Previous 15994 Revisions Next

r14620 Saturday 25th February, 2012 at 11:51:03 UTC by Wilbert Pol
lr35902.c: Started splitting up the instructions into sub-cycles. (nw)
[src/emu/cpu/lr35902]lr35902.c opc_main.h

src/emu/cpu/lr35902/lr35902.c
r14619r14620
129129/* Memory functions                                                         */
130130/****************************************************************************/
131131
132#define mem_ReadByte(cs,A)      ((UINT8)(cs)->w.program->read_byte(A))
133#define mem_WriteByte(cs,A,V)   ((cs)->w.program->write_byte(A,V))
132#define mem_ReadByte(cs,A)      ((UINT8)(cs)->w.program->read_byte(A)); CYCLES_PASSED(4);
133#define mem_WriteByte(cs,A,V)   ((cs)->w.program->write_byte(A,V)); CYCLES_PASSED(4);
134134
135135INLINE UINT16 mem_ReadWord (lr35902_state *cpustate, UINT32 address)
136136{
137   UINT16 value = (UINT16) mem_ReadByte (cpustate, (address + 1) & 0xffff) << 8;
137   UINT16 value = mem_ReadByte (cpustate, (address + 1) & 0xffff);
138   value <<= 8;
138139   value |= mem_ReadByte (cpustate, address);
139140   return value;
140141}
r14619r14620
145146   mem_WriteByte (cpustate, (address + 1) & 0xffff, value >> 8);
146147}
147148
148static const int Cycles[256] =
149{
150    4,12, 8, 8, 4, 4, 8, 4,20, 8, 8, 8, 4, 4, 8, 4,
151    4,12, 8, 8, 4, 4, 8, 4,12, 8, 8, 8, 4, 4, 8, 4,
152    8,12, 8, 8, 4, 4, 8, 4, 8, 8, 8, 8, 4, 4, 8, 4,
153    8,12, 8, 8,12,12,12, 4, 8, 8, 8, 8, 4, 4, 8, 4,
154    4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4,
155    4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4,
156    4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4,
157    8, 8, 8, 8, 8, 8, 4, 8, 4, 4, 4, 4, 4, 4, 8, 4,
158    4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4,
159    4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4,
160    4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4,
161    4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4,
162    8,12,12,16,12,16, 8,16, 8,16,12, 0,12,24, 8,16,
163    8,12,12, 4,12,16, 8,16, 8,16,12, 4,12, 4, 8,16,
164   12,12, 8, 4, 4,16, 8,16,16, 4,16, 4, 4, 4, 8,16,
165   12,12, 8, 4, 4,16, 8,16,12, 8,16, 4, 4, 4, 8,16
166};
167
168static const int CyclesCB[256] =
169{
170    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8,
171    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8,
172    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8,
173    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8,
174    8, 8, 8, 8, 8, 8,12, 8, 8, 8, 8, 8, 8, 8,12, 8,
175    8, 8, 8, 8, 8, 8,12, 8, 8, 8, 8, 8, 8, 8,12, 8,
176    8, 8, 8, 8, 8, 8,12, 8, 8, 8, 8, 8, 8, 8,12, 8,
177    8, 8, 8, 8, 8, 8,12, 8, 8, 8, 8, 8, 8, 8,12, 8,
178    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8,
179    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8,
180    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8,
181    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8,
182    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8,
183    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8,
184    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8,
185    8, 8, 8, 8, 8, 8,16, 8, 8, 8, 8, 8, 8, 8,16, 8
186};
187
188149static CPU_INIT( lr35902 )
189150{
190151   lr35902_state *cpustate = get_safe_token(device);
r14619r14620
285246                  (*cpustate->w.irq_callback)(cpustate->w.device, irqline);
286247               cpustate->w.enable &= ~IME;
287248               cpustate->w.IF &= ~(1 << irqline);
288               CYCLES_PASSED( 20 );
249               CYCLES_PASSED( 12 );
289250               cpustate->w.SP -= 2;
290251               mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
291252               cpustate->w.PC = 0x40 + irqline * 8;
r14619r14620
318279         lr35902_ProcessInterrupts (cpustate);
319280         debugger_instruction_hook(device, cpustate->w.PC);
320281         if ( cpustate->w.enable & HALTED ) {
321            CYCLES_PASSED( Cycles[0x76] );
282            CYCLES_PASSED( 4 );
322283            cpustate->w.execution_state = 1;
323284         } else {
324285            cpustate->w.op = mem_ReadByte (cpustate, cpustate->w.PC++);
r14619r14620
326287               cpustate->w.PC--;
327288               cpustate->w.doHALTbug = 0;
328289            }
329            CYCLES_PASSED( Cycles[cpustate->w.op] );
330290         }
331291      }
332292      cpustate->w.execution_state ^= 1;
src/emu/cpu/lr35902/opc_main.h
r14619r14620
147147  mem_WriteByte (cpustate, cpustate->w.BC, cpustate->b.A);
148148  break;
149149case 0x03: /*      INC BC */
150
151150#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
152151  if (cpustate->b.B == 0xFE)
153152  {
154153    trash_sprites (state);
155154  }
156155#endif
157  cpustate->w.BC += 1;
158  break;
156   cpustate->w.BC += 1;
157   CYCLES_PASSED( 4 );
158   break;
159159case 0x04: /*      INC B */
160160
161161  INC_8BIT (cpustate->b.B)
r14619r14620
186186  cpustate->w.PC += 2;
187187  break;
188188case 0x09: /*      ADD HL,BC */
189
190  ADD_HL_RR (cpustate->w.BC)
191  break;
189   ADD_HL_RR (cpustate->w.BC)
190   CYCLES_PASSED( 4 );
191   break;
192192case 0x0A: /*      LD A,(BC) */
193193
194194  cpustate->b.A = mem_ReadByte (cpustate, cpustate->w.BC);
r14619r14620
201201    trash_sprites (state);
202202  }
203203#endif
204
205  cpustate->w.BC -= 1;
206  break;
204   cpustate->w.BC -= 1;
205   CYCLES_PASSED( 4 );
206   break;
207207case 0x0C: /*      INC C */
208208
209209  INC_8BIT (cpustate->b.C)
r14619r14620
248248  }
249249#endif
250250
251  cpustate->w.DE += 1;
252  break;
251   cpustate->w.DE += 1;
252   CYCLES_PASSED( 4 );
253   break;
253254case 0x14: /*      INC D */
254255
255256  INC_8BIT (cpustate->b.D)
r14619r14620
275276
276277    offset = mem_ReadByte (cpustate, cpustate->w.PC++);
277278    cpustate->w.PC += offset;
279   CYCLES_PASSED( 4 );
278280  }
279281  break;
280282case 0x19: /*      ADD HL,DE */
281
282  ADD_HL_RR (cpustate->w.DE)
283  break;
283   ADD_HL_RR (cpustate->w.DE)
284   CYCLES_PASSED( 4 );
285   break;
284286case 0x1A: /*      LD A,(DE) */
285287
286288  cpustate->b.A = mem_ReadByte (cpustate, cpustate->w.DE);
r14619r14620
293295    trash_sprites (state);
294296  }
295297#endif
296
297  cpustate->w.DE -= 1;
298  break;
298   cpustate->w.DE -= 1;
299   CYCLES_PASSED( 4 );
300   break;
299301case 0x1C: /*      INC E */
300302
301303  INC_8BIT (cpustate->b.E)
r14619r14620
316318  cpustate->b.F = x;
317319  break;
318320case 0x20: /*      JR NZ,n8 */
319
320  if (cpustate->b.F & FLAG_Z)
321  {
322    cpustate->w.PC++;
323  }
324  else
325  {
326   INT8 offset;
327
328    offset = mem_ReadByte (cpustate, cpustate->w.PC++);
329    cpustate->w.PC += offset;
330    CYCLES_PASSED( 4 );
331  }
332  break;
321   {
322      INT8 offset = mem_ReadByte (cpustate, cpustate->w.PC++);
323      if (! (cpustate->b.F & FLAG_Z) )
324      {
325         cpustate->w.PC += offset;
326         CYCLES_PASSED( 4 );
327      }
328   }
329   break;
333330case 0x21: /*      LD HL,n16 */
334331
335332  cpustate->w.HL = mem_ReadWord (cpustate, cpustate->w.PC);
r14619r14620
356353  }
357354#endif
358355
359  cpustate->w.HL += 1;
360  break;
356   cpustate->w.HL += 1;
357   CYCLES_PASSED( 4 );
358   break;
361359case 0x24: /*      INC H */
362360
363361  INC_8BIT (cpustate->b.H);
r14619r14620
397395   }
398396  break;
399397case 0x28: /*      JR Z,n8 */
398   {
399      INT8 offset = mem_ReadByte (cpustate, cpustate->w.PC++);;
400400
401  if (cpustate->b.F & FLAG_Z)
402  {
403   INT8 offset;
404
405    offset = mem_ReadByte (cpustate, cpustate->w.PC++);
406    cpustate->w.PC += offset;
407
408    CYCLES_PASSED( 4 );
409  }
410  else
411  {
412    cpustate->w.PC += 1;
413  }
414  break;
401      if (cpustate->b.F & FLAG_Z)
402      {
403         cpustate->w.PC += offset;
404         CYCLES_PASSED( 4 );
405      }
406   }
407   break;
415408case 0x29: /*      ADD HL,HL */
416
417  ADD_HL_RR (cpustate->w.HL)
418  break;
409   ADD_HL_RR (cpustate->w.HL)
410   CYCLES_PASSED( 4 );
411   break;
419412case 0x2A: /*      LD A,(HL+) */
420413#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
421414  if (cpustate->b.H == 0xFE)
r14619r14620
435428    trash_sprites (state);
436429  }
437430#endif
438
439  cpustate->w.HL -= 1;
440  break;
431   cpustate->w.HL -= 1;
432   CYCLES_PASSED( 4 );
433   break;
441434case 0x2C: /*      INC L */
442435
443436  INC_8BIT (cpustate->b.L);
r14619r14620
456449  cpustate->b.F |= FLAG_N | FLAG_H;
457450  break;
458451case 0x30: /*      JR NC,n8 */
452   {
453      INT8 offset = mem_ReadByte (cpustate, cpustate->w.PC++);
459454
460  if (cpustate->b.F & FLAG_C)
461  {
462    cpustate->w.PC += 1;
463  }
464  else
465  {
466   INT8 offset;
467
468    offset = mem_ReadByte (cpustate, cpustate->w.PC++);
469    cpustate->w.PC += offset;
470    CYCLES_PASSED( 4 );
471  }
472  break;
455      if ( ! (cpustate->b.F & FLAG_C) )
456      {
457         cpustate->w.PC += offset;
458         CYCLES_PASSED( 4 );
459      }
460   }
461   break;
473462case 0x31: /*      LD SP,n16 */
474463
475464  cpustate->w.SP = mem_ReadWord (cpustate, cpustate->w.PC);
r14619r14620
488477  cpustate->w.HL -= 1;
489478  break;
490479case 0x33: /*      INC SP */
491
492  cpustate->w.SP += 1;
493  break;
480   cpustate->w.SP += 1;
481   CYCLES_PASSED( 4 );
482   break;
494483case 0x34: /*      INC (HL) */
495484
496485  {
497486   register UINT8 r, f;
498487
499488   f = (UINT8) (cpustate->b.F & FLAG_C);
500   r = (UINT8) (mem_ReadByte (cpustate, cpustate->w.HL) + 1);
489   r = mem_ReadByte (cpustate, cpustate->w.HL);
490   r += 1;
501491    mem_WriteByte (cpustate, cpustate->w.HL, r);
502492
503493    if (r == 0)
r14619r14620
515505   register UINT8 r, f;
516506
517507   f = (UINT8) ((cpustate->b.F & FLAG_C) | FLAG_N);
518   r = (UINT8) (mem_ReadByte (cpustate, cpustate->w.HL) - 1);
508   r = mem_ReadByte (cpustate, cpustate->w.HL);
509   r -= 1;
519510    mem_WriteByte (cpustate, cpustate->w.HL, r);
520511
521512    if (r == 0)
r14619r14620
529520  break;
530521case 0x36: /*      LD (HL),n8 */
531522  /* FIXED / broken ? */
532  mem_WriteByte (cpustate, cpustate->w.HL, mem_ReadByte (cpustate, cpustate->w.PC++));
523  {
524   UINT8 v = mem_ReadByte (cpustate, cpustate->w.PC++);
525   mem_WriteByte (cpustate, cpustate->w.HL, v);
526  }
533527  break;
534528case 0x37: /*      SCF */
535529
536530  cpustate->b.F = (UINT8) ((cpustate->b.F & FLAG_Z) | FLAG_C);
537531  break;
538532case 0x38: /*      JR C,n8 */
533   {
534      INT8 offset = mem_ReadByte (cpustate, cpustate->w.PC++);
539535
540  if (cpustate->b.F & FLAG_C)
541  {
542   INT8 offset;
543
544    offset = mem_ReadByte (cpustate, cpustate->w.PC++);
545    cpustate->w.PC += offset;
546
547    CYCLES_PASSED( 4 );
548  }
549  else
550  {
551    cpustate->w.PC += 1;
552  }
553  break;
536      if (cpustate->b.F & FLAG_C)
537      {
538         cpustate->w.PC += offset;
539         CYCLES_PASSED( 4 );
540      }
541   }
542   break;
554543case 0x39: /*      ADD HL,SP */
555  ADD_HL_RR (cpustate->w.SP)
556  break;
544   ADD_HL_RR (cpustate->w.SP)
545   CYCLES_PASSED( 4 );
546   break;
557547case 0x3A: /*      LD A,(HL-) */
558548#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
559549  if (cpustate->b.H == 0xFE)
r14619r14620
566556  cpustate->w.HL -= 1;
567557  break;
568558case 0x3B: /*      DEC SP */
569
570  cpustate->w.SP -= 1;
571  break;
559   cpustate->w.SP -= 1;
560   CYCLES_PASSED( 4 );
561   break;
572562case 0x3C: /*      INC     A */
573563
574564  INC_8BIT (cpustate->b.A);
r14619r14620
11001090  CP_A_X (cpustate->b.A)
11011091  break;
11021092case 0xC0: /*      RET NZ */
1103
1104  if (!(cpustate->b.F & FLAG_Z))
1105  {
1106    cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1107    cpustate->w.SP += 2;
1108    CYCLES_PASSED( 12 );
1109  }
1110  break;
1093   CYCLES_PASSED( 4 );
1094   if (!(cpustate->b.F & FLAG_Z))
1095   {
1096      cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1097      cpustate->w.SP += 2;
1098      CYCLES_PASSED( 4 );
1099   }
1100   break;
11111101case 0xC1: /*      POP BC */
11121102
11131103  cpustate->w.BC = mem_ReadWord (cpustate, cpustate->w.SP);
11141104  cpustate->w.SP += 2;
11151105  break;
11161106case 0xC2: /*      JP NZ,n16 */
1107   {
1108      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1109      cpustate->w.PC += 2;
11171110
1118  if (cpustate->b.F & FLAG_Z)
1119  {
1120    cpustate->w.PC += 2;
1121  }
1122  else
1123  {
1124    cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.PC);
1125    CYCLES_PASSED( 4 );
1126  }
1127  break;
1111      if ( ! (cpustate->b.F & FLAG_Z) )
1112      {
1113         cpustate->w.PC = addr;
1114         CYCLES_PASSED( 4 );
1115      }
1116   }
1117   break;
11281118case 0xC3: /*      JP n16 */
1129
1130  cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.PC);
1131  break;
1119   cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.PC);
1120   CYCLES_PASSED( 4 );
1121   break;
11321122case 0xC4: /*      CALL NZ,n16 */
1123   {
1124      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1125      cpustate->w.PC += 2;
11331126
1134  if (cpustate->b.F & FLAG_Z)
1135  {
1136    cpustate->w.PC += 2;
1137  }
1138  else
1139  {
1140   register UINT16 PC;
1141    PC = mem_ReadWord (cpustate, cpustate->w.PC);
1142    cpustate->w.PC += 2;
1143
1144    cpustate->w.SP -= 2;
1145    mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1146    cpustate->w.PC = PC;
1147    CYCLES_PASSED( 12 );
1148  }
1149  break;
1127      if ( ! (cpustate->b.F & FLAG_Z) )
1128      {
1129         cpustate->w.SP -= 2;
1130         mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1131         cpustate->w.PC = addr;
1132         CYCLES_PASSED( 4 );
1133      }
1134   }
1135   break;
11501136case 0xC5: /*      PUSH BC */
1151
1152  cpustate->w.SP -= 2;
1153  mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.BC);
1154  break;
1137   cpustate->w.SP -= 2;
1138   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.BC);
1139   CYCLES_PASSED( 4 );
1140   break;
11551141case 0xC6: /*      ADD A,n8 */
11561142
11571143  x = mem_ReadByte (cpustate, cpustate->w.PC++);
11581144  ADD_A_X (x)
11591145  break;
11601146case 0xC7: /*      RST 0 */
1161
1162  {
1163   register UINT16 PC;
1164    PC = cpustate->w.PC;
1165    cpustate->w.PC = 0;
1166
1167    cpustate->w.SP -= 2;
1168    mem_WriteWord (cpustate, cpustate->w.SP, PC);
1169  }
1170  break;
1147   cpustate->w.SP -= 2;
1148   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1149   cpustate->w.PC = 0;
1150   CYCLES_PASSED( 4 );
1151   break;
11711152case 0xC8: /*      RET Z */
1172
1173  if (cpustate->b.F & FLAG_Z)
1174  {
1175    cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1176    cpustate->w.SP += 2;
1177    CYCLES_PASSED( 12 );
1178  }
1179  break;
1153   CYCLES_PASSED( 4 );
1154   if (cpustate->b.F & FLAG_Z)
1155   {
1156      cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1157      cpustate->w.SP += 2;
1158      CYCLES_PASSED( 4 );
1159   }
1160   break;
11801161case 0xC9: /*      RET */
1181
1182  cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1183  cpustate->w.SP += 2;
1184  break;
1162   cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1163   cpustate->w.SP += 2;
1164   CYCLES_PASSED( 4 );
1165   break;
11851166case 0xCA: /*      JP Z,n16 */
1167   {
1168      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1169      cpustate->w.PC += 2;
11861170
1187  if (cpustate->b.F & FLAG_Z)
1188  {
1189    cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.PC);
1190    CYCLES_PASSED( 4 );
1191  }
1192  else
1193  {
1194    cpustate->w.PC += 2;
1195  }
1196  break;
1171      if (cpustate->b.F & FLAG_Z)
1172      {
1173         cpustate->w.PC = addr;
1174         CYCLES_PASSED( 4 );
1175      }
1176   }
1177   break;
11971178case 0xCB: /*      PREFIX! */
11981179  x = mem_ReadByte (cpustate, cpustate->w.PC++);
1199  CYCLES_PASSED( CyclesCB[x] );
12001180  switch (x)
12011181  {
12021182    #include "opc_cb.h"
12031183  }
12041184  break;
12051185case 0xCC: /*      CALL Z,n16 */
1186   {
1187      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1188      cpustate->w.PC += 2;
12061189
1207  if (cpustate->b.F & FLAG_Z)
1208  {
1209   register UINT16 PC;
1210    PC = mem_ReadWord (cpustate, cpustate->w.PC);
1211    cpustate->w.PC += 2;
1212
1213    cpustate->w.SP -= 2;
1214    mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1215    cpustate->w.PC = PC;
1216    CYCLES_PASSED( 12 );
1217  }
1218  else
1219  {
1220    cpustate->w.PC += 2;
1221  }
1222  break;
1190      if (cpustate->b.F & FLAG_Z)
1191      {
1192         cpustate->w.SP -= 2;
1193         mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1194         cpustate->w.PC = addr;
1195         CYCLES_PASSED( 4 );
1196      }
1197   }
1198   break;
12231199case 0xCD: /*      CALL n16 */
1224  {
1225   register UINT16 PC;
1226    PC = mem_ReadWord (cpustate, cpustate->w.PC);
1227    cpustate->w.PC += 2;
1200   {
1201      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1202      cpustate->w.PC += 2;
12281203
1229    cpustate->w.SP -= 2;
1230    mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1231    cpustate->w.PC = PC;
1232  }
1233  break;
1204      cpustate->w.SP -= 2;
1205      mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1206      cpustate->w.PC = addr;
1207      CYCLES_PASSED( 4 );
1208   }
1209   break;
12341210case 0xCE: /*      ADC A,n8 */
12351211
12361212  x = mem_ReadByte (cpustate, cpustate->w.PC++);
12371213  ADC_A_X (x)
12381214  break;
12391215case 0xCF: /*      RST 8 */
1240
1241  cpustate->w.SP -= 2;
1242  mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1243  cpustate->w.PC = 8;
1244  break;
1216   cpustate->w.SP -= 2;
1217   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1218   cpustate->w.PC = 8;
1219   CYCLES_PASSED( 4 );
1220   break;
12451221case 0xD0: /*      RET NC */
1246
1247  if (!(cpustate->b.F & FLAG_C))
1248  {
1249    cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1250    cpustate->w.SP += 2;
1251    CYCLES_PASSED( 12 );
1252  }
1253  break;
1222   CYCLES_PASSED( 4 );
1223   if (!(cpustate->b.F & FLAG_C))
1224   {
1225      cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1226      cpustate->w.SP += 2;
1227      CYCLES_PASSED( 4 );
1228   }
1229   break;
12541230case 0xD1: /*      POP DE */
12551231
12561232  cpustate->w.DE = mem_ReadWord (cpustate, cpustate->w.SP);
12571233  cpustate->w.SP += 2;
12581234  break;
12591235case 0xD2: /*      JP NC,n16 */
1236   {
1237      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1238      cpustate->w.PC += 2;
12601239
1261  if (cpustate->b.F & FLAG_C)
1262  {
1263    cpustate->w.PC += 2;
1264  }
1265  else
1266  {
1267    cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.PC);
1268    CYCLES_PASSED( 4 );
1269  }
1270  break;
1240      if ( ! (cpustate->b.F & FLAG_C) )
1241      {
1242         cpustate->w.PC = addr;
1243         CYCLES_PASSED( 4 );
1244      }
1245   }
1246   break;
12711247case 0xD3: /*      EH? */
12721248  break;
12731249case 0xD4: /*      CALL NC,n16 */
1250   {
1251      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1252      cpustate->w.PC += 2;
12741253
1275  if (cpustate->b.F & FLAG_C)
1276  {
1277    cpustate->w.PC += 2;
1278  }
1279  else
1280  {
1281   register UINT16 PC;
1282    PC = mem_ReadWord (cpustate, cpustate->w.PC);
1283    cpustate->w.PC += 2;
1284
1285    cpustate->w.SP -= 2;
1286    mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1287    cpustate->w.PC = PC;
1288    CYCLES_PASSED( 12 );
1289  }
1290  break;
1254      if ( ! (cpustate->b.F & FLAG_C) )
1255      {
1256         cpustate->w.SP -= 2;
1257         mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1258         cpustate->w.PC = addr;
1259         CYCLES_PASSED( 4 );
1260      }
1261   }
1262   break;
12911263case 0xD5: /*      PUSH DE */
1292
1293  cpustate->w.SP -= 2;
1294  mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.DE);
1295  break;
1264   cpustate->w.SP -= 2;
1265   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.DE);
1266   CYCLES_PASSED( 4 );
1267   break;
12961268case 0xD6: /*      SUB A,n8 */
12971269
12981270  x = mem_ReadByte (cpustate, cpustate->w.PC++);
12991271  SUB_A_X (x)
13001272  break;
13011273case 0xD7: /*      RST     $10 */
1302
1303  cpustate->w.SP -= 2;
1304  mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1305  cpustate->w.PC = 0x10;
1306  break;
1274   cpustate->w.SP -= 2;
1275   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1276   cpustate->w.PC = 0x10;
1277   CYCLES_PASSED( 4 );
1278   break;
13071279case 0xD8: /*      RET C */
1308
1309  if (cpustate->b.F & FLAG_C)
1310  {
1311    cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1312    cpustate->w.SP += 2;
1313    CYCLES_PASSED( 12 );
1314  }
1315  break;
1280   CYCLES_PASSED( 4 );
1281   if (cpustate->b.F & FLAG_C)
1282   {
1283      cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1284      cpustate->w.SP += 2;
1285      CYCLES_PASSED( 4 );
1286   }
1287   break;
13161288case 0xD9: /*      RETI */
1317
1318  cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1319  cpustate->w.SP += 2;
1320  cpustate->w.enable |= IME;
1321  break;
1289   cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1290   cpustate->w.SP += 2;
1291   cpustate->w.enable |= IME;
1292   CYCLES_PASSED( 4 );
1293   break;
13221294case 0xDA: /*      JP C,n16 */
1295   {
1296      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1297      cpustate->w.PC += 2;
13231298
1324  if (cpustate->b.F & FLAG_C)
1325  {
1326    cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.PC);
1327    CYCLES_PASSED( 4 );
1328  }
1329  else
1330  {
1331    cpustate->w.PC += 2;
1332  }
1333  break;
1299      if (cpustate->b.F & FLAG_C)
1300      {
1301         cpustate->w.PC = addr;
1302         CYCLES_PASSED( 4 );
1303      }
1304   }
1305   break;
13341306case 0xDB: /*      EH? */
13351307  break;
13361308case 0xDC: /*      CALL C,n16 */
1309   {
1310      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1311      cpustate->w.PC += 2;
13371312
1338  if (cpustate->b.F & FLAG_C)
1339  {
1340   register UINT16 PC;
1341    PC = mem_ReadWord (cpustate, cpustate->w.PC);
1342    cpustate->w.PC += 2;
1343
1344    cpustate->w.SP -= 2;
1345    mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1346    cpustate->w.PC = PC;
1347    CYCLES_PASSED( 12 );
1348  }
1349  else
1350  {
1351    cpustate->w.PC += 2;
1352  }
1353  break;
1313      if (cpustate->b.F & FLAG_C)
1314      {
1315         cpustate->w.SP -= 2;
1316         mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1317         cpustate->w.PC = addr;
1318         CYCLES_PASSED( 4 );
1319      }
1320   }
1321   break;
13541322case 0xDD: /*      EH? */
13551323  break;
13561324case 0xDE: /*      SBC A,n8 */
r14619r14620
13591327  SBC_A_X (x)
13601328  break;
13611329case 0xDF: /*      RST     $18 */
1362
1363  cpustate->w.SP -= 2;
1364  mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1365  cpustate->w.PC = 0x18;
1366  break;
1330   cpustate->w.SP -= 2;
1331   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1332   cpustate->w.PC = 0x18;
1333   CYCLES_PASSED( 4 );
1334   break;
13671335case 0xE0: /*      LD      ($FF00+n8),A */
1368  mem_WriteByte (cpustate, mem_ReadByte (cpustate, cpustate->w.PC++) + 0xFF00, cpustate->b.A);
1336  {
1337   UINT8 v = mem_ReadByte (cpustate, cpustate->w.PC++);
1338   mem_WriteByte (cpustate, 0xFF00 + v, cpustate->b.A);
1339  }
13691340  break;
13701341case 0xE1: /*      POP HL */
13711342
r14619r14620
13811352case 0xE4: /*      EH? */
13821353  break;
13831354case 0xE5: /*      PUSH HL */
1384
1385  cpustate->w.SP -= 2;
1386  mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.HL);
1387  break;
1355   cpustate->w.SP -= 2;
1356   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.HL);
1357   CYCLES_PASSED( 4 );
1358   break;
13881359case 0xE6: /*      AND A,n8 */
13891360
13901361  x = mem_ReadByte (cpustate, cpustate->w.PC++);
13911362  AND_A_X (x)
13921363  break;
13931364case 0xE7: /*      RST $20 */
1394
1395  cpustate->w.SP -= 2;
1396  mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1397  cpustate->w.PC = 0x20;
1398  break;
1365   cpustate->w.SP -= 2;
1366   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1367   cpustate->w.PC = 0x20;
1368   CYCLES_PASSED( 4 );
1369   break;
13991370case 0xE8: /*      ADD SP,n8 */
14001371/*
14011372 *   Z - Reset.
r14619r14620
14071378  {
14081379   register INT32 n;
14091380
1410   n = (INT32) ((INT8) mem_ReadByte (cpustate, cpustate->w.PC++));
1381   n = (INT8) mem_ReadByte (cpustate, cpustate->w.PC++);
14111382
14121383   if ( ( cpustate->w.SP & 0xFF ) + (UINT8)(n & 0xFF) > 0xFF )
14131384    {
r14619r14620
14251396
14261397   cpustate->w.SP = (UINT16) ( cpustate->w.SP + n );
14271398  }
1399  CYCLES_PASSED( 8 );
14281400  break;
14291401case 0xE9: /*      JP (HL) */
14301402
r14619r14620
14471419  XOR_A_X (x)
14481420  break;
14491421case 0xEF: /*      RST $28 */
1450
1451  cpustate->w.SP -= 2;
1452  mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1453  cpustate->w.PC = 0x28;
1454  break;
1422   cpustate->w.SP -= 2;
1423   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1424   cpustate->w.PC = 0x28;
1425   CYCLES_PASSED( 4 );
1426   break;
14551427case 0xF0: /*      LD A,($FF00+n8) */
1456
1457  cpustate->b.A = mem_ReadByte (cpustate, 0xFF00 + mem_ReadByte (cpustate, cpustate->w.PC++));
1428  {
1429   UINT8 v = mem_ReadByte (cpustate, cpustate->w.PC++);
1430   cpustate->b.A = mem_ReadByte (cpustate, 0xFF00 + v);
1431  }
14581432  break;
14591433case 0xF1: /*      POP AF */
14601434
r14619r14620
14721446case 0xF4: /*      EH? */
14731447  break;
14741448case 0xF5: /*      PUSH AF */
1475
1476  cpustate->w.SP -= 2;
1477  mem_WriteWord (cpustate, cpustate->w.SP, (UINT16) (cpustate->w.AF & 0xFFF0));
1478  break;
1449   cpustate->w.SP -= 2;
1450   mem_WriteWord (cpustate, cpustate->w.SP, (UINT16) (cpustate->w.AF & 0xFFF0));
1451   CYCLES_PASSED( 4 );
1452   break;
14791453case 0xF6: /*      OR A,n8 */
14801454
14811455  x = mem_ReadByte (cpustate, cpustate->w.PC++);
14821456  OR_A_X (x)
14831457  break;
14841458case 0xF7: /*      RST $30 */
1485
1486  cpustate->w.SP -= 2;
1487  mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1488  cpustate->w.PC = 0x30;
1489  break;
1459   cpustate->w.SP -= 2;
1460   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1461   cpustate->w.PC = 0x30;
1462   CYCLES_PASSED( 4 );
1463   break;
14901464case 0xF8: /*      LD HL,SP+n8 */
14911465/*
14921466 *   n = one UINT8 signed immediate value.
r14619r14620
15011475  {
15021476   register INT32 n;
15031477
1504   n = (INT32) ((INT8) mem_ReadByte (cpustate, cpustate->w.PC++));
1478   n = (INT8) mem_ReadByte (cpustate, cpustate->w.PC++);
15051479
15061480   if ( ( cpustate->w.SP & 0xFF ) + (UINT8)(n & 0xFF) > 0xFF )
15071481    {
r14619r14620
15191493
15201494   cpustate->w.HL = (UINT16) ( cpustate->w.SP + n );
15211495  }
1496  CYCLES_PASSED( 4 );
15221497  break;
15231498case 0xF9: /*      LD SP,HL */
1524
1525  cpustate->w.SP = cpustate->w.HL;
1526  break;
1499   cpustate->w.SP = cpustate->w.HL;
1500   CYCLES_PASSED( 4 );
1501   break;
15271502case 0xFA: /*      LD A,(n16) */
1528
1529  cpustate->b.A = mem_ReadByte (cpustate, mem_ReadWord (cpustate, cpustate->w.PC));
1530  cpustate->w.PC += 2;
1531  break;
1503   cpustate->b.A = mem_ReadByte (cpustate, mem_ReadWord (cpustate, cpustate->w.PC));
1504   cpustate->w.PC += 2;
1505   break;
15321506case 0xFB: /*      EI */
1533
1534  cpustate->w.enable |= IME;
1535  cpustate->w.ei_delay = 1;
1536  break;
1507   cpustate->w.enable |= IME;
1508   cpustate->w.ei_delay = 1;
1509   break;
15371510case 0xFC: /*      EH? */
1538  break;
1511   break;
15391512case 0xFD: /*      EH? */
1540  break;
1513   break;
15411514case 0xFE: /*      CP A,n8 */
1542
1543  x = mem_ReadByte (cpustate, cpustate->w.PC++);
1544  CP_A_X (x)
1545  break;
1515   x = mem_ReadByte (cpustate, cpustate->w.PC++);
1516   CP_A_X (x)
1517   break;
15461518case 0xFF: /*      RST $38 */
1547
1548  cpustate->w.SP -= 2;
1549  mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1550  cpustate->w.PC = 0x38;
1551  break;
1519   cpustate->w.SP -= 2;
1520   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1521   cpustate->w.PC = 0x38;
1522   CYCLES_PASSED( 4 );
1523   break;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team