Previous 15994 Revisions Next

r14631 Saturday 25th February, 2012 at 21:24:19 UTC by Wilbert Pol
lr35902.c: Refactored a bit and got rid of the union magic. (nw)
[src/emu/cpu/lr35902]lr35902.c opc_cb.h opc_main.h

src/emu/cpu/lr35902/lr35902.c
r14630r14631
4646#define FLAG_H  0x20
4747#define FLAG_C  0x10
4848
49#define CYCLES_PASSED(X)      cpustate->w.icount -= ((X) / (cpustate->w.gb_speed));   \
50               if ( cpustate->w.timer_expired_func ) {         \
51                  cpustate->w.timer_expired_func( cpustate->w.device, X );      \
49#define CYCLES_PASSED(X)      cpustate->icount -= ((X) / (cpustate->gb_speed));   \
50               if ( cpustate->timer_expired_func ) {         \
51                  cpustate->timer_expired_func( cpustate->device, X );      \
5252               }
5353
54typedef struct {
55   UINT16 AF;
56   UINT16 BC;
57   UINT16 DE;
58   UINT16 HL;
54typedef struct _lr35902_state {
55   UINT8 A;
56   UINT8 F;
57   UINT8 B;
58   UINT8 C;
59   UINT8 D;
60   UINT8 E;
61   UINT8 H;
62   UINT8 L;
5963
6064   UINT16 SP;
6165   UINT16 PC;
r14630r14631
8084   int doHALTbug;
8185   UINT8   features;
8286   const lr35902_cpu_core *config;
83} lr35902_16BitRegs;
87} lr35902_state;
8488
85#ifdef LSB_FIRST
86typedef struct {
87   UINT8 F;
88   UINT8 A;
89   UINT8 C;
90   UINT8 B;
91   UINT8 E;
92   UINT8 D;
93   UINT8 L;
94   UINT8 H;
95} lr35902_8BitRegs;
96#else
97typedef struct {
98   UINT8 A;
99   UINT8 F;
100   UINT8 B;
101   UINT8 C;
102   UINT8 D;
103   UINT8 E;
104   UINT8 H;
105   UINT8 L;
106} lr35902_8BitRegs;
107#endif
108
109
110typedef union _lr35902_state lr35902_state;
111union _lr35902_state {
112   lr35902_16BitRegs w;
113   lr35902_8BitRegs b;
114};
115
11689INLINE lr35902_state *get_safe_token(device_t *device)
11790{
11891   assert(device != NULL);
r14630r14631
129102/* Memory functions                                                         */
130103/****************************************************************************/
131104
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);
105#define mem_ReadByte(cs,A)      ((UINT8)(cs)->program->read_byte(A)); CYCLES_PASSED(4);
106#define mem_WriteByte(cs,A,V)   ((cs)->program->write_byte(A,V)); CYCLES_PASSED(4);
134107
108INLINE UINT8 mem_ReadOp(lr35902_state *cpustate)
109{
110   UINT8 r = mem_ReadByte (cpustate, cpustate->PC++);
111   return r;
112}
113
135114INLINE UINT16 mem_ReadWord (lr35902_state *cpustate, UINT32 address)
136115{
137116   UINT16 value = mem_ReadByte (cpustate, (address + 1) & 0xffff);
r14630r14631
150129{
151130   lr35902_state *cpustate = get_safe_token(device);
152131
153   cpustate->w.config = (const lr35902_cpu_core *) device->static_config();
154   cpustate->w.irq_callback = irqcallback;
155   cpustate->w.device = device;
156   cpustate->w.program = device->space(AS_PROGRAM);
132   cpustate->config = (const lr35902_cpu_core *) device->static_config();
133   cpustate->irq_callback = irqcallback;
134   cpustate->device = device;
135   cpustate->program = device->space(AS_PROGRAM);
157136}
158137
159138/*** Reset lr353902 registers: ******************************/
r14630r14631
165144{
166145   lr35902_state *cpustate = get_safe_token(device);
167146
168   cpustate->w.AF = 0x0000;
169   cpustate->w.BC = 0x0000;
170   cpustate->w.DE = 0x0000;
171   cpustate->w.HL = 0x0000;
172   cpustate->w.SP = 0x0000;
173   cpustate->w.PC = 0x0000;
174   cpustate->w.timer_expired_func = NULL;
175   cpustate->w.features = LR35902_FEATURE_HALT_BUG;
176   if (cpustate->w.config)
147   cpustate->A = 0x00;
148   cpustate->F = 0x00;
149   cpustate->B = 0x00;
150   cpustate->C = 0x00;
151   cpustate->D = 0x00;
152   cpustate->E = 0x00;
153   cpustate->H = 0x00;
154   cpustate->L = 0x00;
155   cpustate->SP = 0x0000;
156   cpustate->PC = 0x0000;
157   cpustate->timer_expired_func = NULL;
158   cpustate->features = LR35902_FEATURE_HALT_BUG;
159   if (cpustate->config)
177160   {
178      if ( cpustate->w.config->regs ) {
179         cpustate->w.AF = cpustate->w.config->regs[0];
180         cpustate->w.BC = cpustate->w.config->regs[1];
181         cpustate->w.DE = cpustate->w.config->regs[2];
182         cpustate->w.HL = cpustate->w.config->regs[3];
183         cpustate->w.SP = cpustate->w.config->regs[4];
184         cpustate->w.PC = cpustate->w.config->regs[5];
161      if ( cpustate->config->regs ) {
162         cpustate->A = cpustate->config->regs[0] >> 8;
163         cpustate->F = cpustate->config->regs[0] & 0xFF;
164         cpustate->B = cpustate->config->regs[1] >> 8;
165         cpustate->C = cpustate->config->regs[1] & 0xFF;
166         cpustate->D = cpustate->config->regs[2] >> 8;
167         cpustate->E = cpustate->config->regs[2] & 0xFF;
168         cpustate->H = cpustate->config->regs[3] >> 8;
169         cpustate->L = cpustate->config->regs[3] & 0xFF;
170         cpustate->SP = cpustate->config->regs[4];
171         cpustate->PC = cpustate->config->regs[5];
185172      }
186      cpustate->w.timer_expired_func = cpustate->w.config->timer_expired_func;
187      cpustate->w.features = cpustate->w.config->features;
173      cpustate->timer_expired_func = cpustate->config->timer_expired_func;
174      cpustate->features = cpustate->config->features;
188175   }
189   cpustate->w.enable = 0;
190   cpustate->w.IE = 0;
191   cpustate->w.IF = 0;
176   cpustate->enable = 0;
177   cpustate->IE = 0;
178   cpustate->IF = 0;
192179
193   cpustate->w.execution_state = 0;
194   cpustate->w.doHALTbug = 0;
195   cpustate->w.ei_delay = 0;
196   cpustate->w.gb_speed_change_pending = 0;
197   cpustate->w.gb_speed = 1;
180   cpustate->execution_state = 0;
181   cpustate->doHALTbug = 0;
182   cpustate->ei_delay = 0;
183   cpustate->gb_speed_change_pending = 0;
184   cpustate->gb_speed = 1;
198185}
199186
200187INLINE void lr35902_ProcessInterrupts (lr35902_state *cpustate)
201188{
202   UINT8 irq = cpustate->w.IE & cpustate->w.IF;
189   UINT8 irq = cpustate->IE & cpustate->IF;
203190
204191   /* Interrupts should be taken after the first instruction after an EI instruction */
205   if (cpustate->w.ei_delay) {
206      cpustate->w.ei_delay = 0;
192   if (cpustate->ei_delay) {
193      cpustate->ei_delay = 0;
207194      return;
208195   }
209196
210197   /*
211198       logerror("Attempting to process LR35902 Interrupt IRQ $%02X\n", irq);
212       logerror("Attempting to process LR35902 Interrupt IE $%02X\n", cpustate->w.IE);
213       logerror("Attempting to process LR35902 Interrupt IF $%02X\n", cpustate->w.IF);
199       logerror("Attempting to process LR35902 Interrupt IE $%02X\n", cpustate->IE);
200       logerror("Attempting to process LR35902 Interrupt IF $%02X\n", cpustate->IF);
214201    */
215202   if (irq)
216203   {
r14630r14631
223210      {
224211         if( irq & (1<<irqline) )
225212         {
226            if (cpustate->w.enable & HALTED)
213            if (cpustate->enable & HALTED)
227214            {
228               cpustate->w.enable &= ~HALTED;
229               cpustate->w.PC++;
230               if ( cpustate->w.features & LR35902_FEATURE_HALT_BUG ) {
231                  if ( ! ( cpustate->w.enable & IME ) ) {
215               cpustate->enable &= ~HALTED;
216               cpustate->PC++;
217               if ( cpustate->features & LR35902_FEATURE_HALT_BUG ) {
218                  if ( ! ( cpustate->enable & IME ) ) {
232219                     /* Old cpu core (dmg/mgb/sgb) */
233                     cpustate->w.doHALTbug = 1;
220                     cpustate->doHALTbug = 1;
234221                  }
235222               } else {
236223                  /* New cpu core (cgb/agb/ags) */
r14630r14631
241228                  }
242229               }
243230            }
244            if ( cpustate->w.enable & IME ) {
245               if ( cpustate->w.irq_callback )
246                  (*cpustate->w.irq_callback)(cpustate->w.device, irqline);
247               cpustate->w.enable &= ~IME;
248               cpustate->w.IF &= ~(1 << irqline);
231            if ( cpustate->enable & IME ) {
232               if ( cpustate->irq_callback )
233                  (*cpustate->irq_callback)(cpustate->device, irqline);
234               cpustate->enable &= ~IME;
235               cpustate->IF &= ~(1 << irqline);
249236               CYCLES_PASSED( 12 );
250               cpustate->w.SP -= 2;
251               mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
252               cpustate->w.PC = 0x40 + irqline * 8;
253               /*logerror("LR35902 Interrupt PC $%04X\n", cpustate->w.PC );*/
237               cpustate->SP -= 2;
238               mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
239               cpustate->PC = 0x40 + irqline * 8;
240               /*logerror("LR35902 Interrupt PC $%04X\n", cpustate->PC );*/
254241               return;
255242            }
256243         }
r14630r14631
268255
269256   do
270257   {
271      if ( cpustate->w.execution_state ) {
258      if ( cpustate->execution_state ) {
272259         UINT8   x;
273260         /* Execute instruction */
274         switch( cpustate->w.op ) {
261         switch( cpustate->op ) {
275262#include "opc_main.h"
276263         }
277264      } else {
278265         /* Fetch and count cycles */
279266         lr35902_ProcessInterrupts (cpustate);
280         debugger_instruction_hook(device, cpustate->w.PC);
281         if ( cpustate->w.enable & HALTED ) {
267         debugger_instruction_hook(device, cpustate->PC);
268         if ( cpustate->enable & HALTED ) {
282269            CYCLES_PASSED( 4 );
283            cpustate->w.execution_state = 1;
270            cpustate->execution_state = 1;
284271         } else {
285            cpustate->w.op = mem_ReadByte (cpustate, cpustate->w.PC++);
286            if ( cpustate->w.doHALTbug ) {
287               cpustate->w.PC--;
288               cpustate->w.doHALTbug = 0;
272            cpustate->op = mem_ReadOp (cpustate);
273            if ( cpustate->doHALTbug ) {
274               cpustate->PC--;
275               cpustate->doHALTbug = 0;
289276            }
290277         }
291278      }
292      cpustate->w.execution_state ^= 1;
293   } while (cpustate->w.icount > 0);
279      cpustate->execution_state ^= 1;
280   } while (cpustate->icount > 0);
294281}
295282
296283static CPU_BURN( lr35902 )
r14630r14631
301288    {
302289        /* NOP takes 4 cycles per instruction */
303290        int n = (cycles + 3) / 4;
304        cpustate->w.icount -= 4 * n;
291        cpustate->icount -= 4 * n;
305292    }
306293}
307294
308295static void lr35902_set_irq_line (lr35902_state *cpustate, int irqline, int state)
309296{
310297   /*logerror("setting irq line 0x%02x state 0x%08x\n", irqline, state);*/
311   //if( cpustate->w.irq_state == state )
298   //if( cpustate->irq_state == state )
312299   //  return;
313300
314   cpustate->w.irq_state = state;
301   cpustate->irq_state = state;
315302   if( state == ASSERT_LINE )
316303   {
317304
318      cpustate->w.IF |= (0x01 << irqline);
319      /*logerror("LR35902 assert irq line %d ($%02X)\n", irqline, cpustate->w.IF);*/
305      cpustate->IF |= (0x01 << irqline);
306      /*logerror("LR35902 assert irq line %d ($%02X)\n", irqline, cpustate->IF);*/
320307
321308   }
322309   else
323310   {
324311
325      cpustate->w.IF &= ~(0x01 << irqline);
326      /*logerror("LR35902 clear irq line %d ($%02X)\n", irqline, cpustate->w.IF);*/
312      cpustate->IF &= ~(0x01 << irqline);
313      /*logerror("LR35902 clear irq line %d ($%02X)\n", irqline, cpustate->IF);*/
327314
328315   }
329316}
r14630r14631
331318#ifdef UNUSED_FUNCTION
332319static void lr35902_clear_pending_interrupts (lr35902_state *cpustate)
333320{
334    cpustate->w.IF = 0;
321    cpustate->IF = 0;
335322}
336323#endif
337324
r14630r14631
348335   case CPUINFO_INT_INPUT_STATE + 3:
349336   case CPUINFO_INT_INPUT_STATE + 4:         lr35902_set_irq_line(cpustate, state-CPUINFO_INT_INPUT_STATE, info->i); break;
350337
351   case CPUINFO_INT_SP:                  cpustate->w.SP = info->i;                  break;
352   case CPUINFO_INT_PC:                  cpustate->w.PC = info->i;                  break;
338   case CPUINFO_INT_SP:                  cpustate->SP = info->i;                  break;
339   case CPUINFO_INT_PC:                  cpustate->PC = info->i;                  break;
353340
354   case CPUINFO_INT_REGISTER + LR35902_PC:      cpustate->w.PC = info->i;                  break;
355   case CPUINFO_INT_REGISTER + LR35902_SP:      cpustate->w.SP = info->i;                  break;
356   case CPUINFO_INT_REGISTER + LR35902_AF:      cpustate->w.AF = info->i;                  break;
357   case CPUINFO_INT_REGISTER + LR35902_BC:      cpustate->w.BC = info->i;                  break;
358   case CPUINFO_INT_REGISTER + LR35902_DE:      cpustate->w.DE = info->i;                  break;
359   case CPUINFO_INT_REGISTER + LR35902_HL:      cpustate->w.HL = info->i;                  break;
360   case CPUINFO_INT_REGISTER + LR35902_IE:      cpustate->w.IE = info->i; break;
361   case CPUINFO_INT_REGISTER + LR35902_IF:      cpustate->w.IF = info->i; break;
362   case CPUINFO_INT_REGISTER + LR35902_SPEED:   cpustate->w.gb_speed_change_pending = info->i & 0x01; break;
341   case CPUINFO_INT_REGISTER + LR35902_PC:      cpustate->PC = info->i;                  break;
342   case CPUINFO_INT_REGISTER + LR35902_SP:      cpustate->SP = info->i;                  break;
343   case CPUINFO_INT_REGISTER + LR35902_AF:      cpustate->A = info->i >> 8; cpustate->F = info->i & 0xFF;      break;
344   case CPUINFO_INT_REGISTER + LR35902_BC:      cpustate->B = info->i >> 8; cpustate->C = info->i & 0xFF;      break;
345   case CPUINFO_INT_REGISTER + LR35902_DE:      cpustate->D = info->i >> 8; cpustate->E = info->i & 0xFF;      break;
346   case CPUINFO_INT_REGISTER + LR35902_HL:      cpustate->H = info->i >> 8; cpustate->L = info->i & 0xFF;      break;
347   case CPUINFO_INT_REGISTER + LR35902_IE:      cpustate->IE = info->i; break;
348   case CPUINFO_INT_REGISTER + LR35902_IF:      cpustate->IF = info->i; break;
349   case CPUINFO_INT_REGISTER + LR35902_SPEED:   cpustate->gb_speed_change_pending = info->i & 0x01; break;
363350   }
364351}
365352
r14630r14631
391378   case DEVINFO_INT_ADDRBUS_WIDTH + AS_IO:      info->i = 16;               break;
392379   case DEVINFO_INT_ADDRBUS_SHIFT + AS_IO:      info->i = 0;               break;
393380
394   case CPUINFO_INT_SP:                     info->i = cpustate->w.SP;               break;
395   case CPUINFO_INT_PC:                     info->i = cpustate->w.PC;               break;
381   case CPUINFO_INT_SP:                     info->i = cpustate->SP;               break;
382   case CPUINFO_INT_PC:                     info->i = cpustate->PC;               break;
396383   case CPUINFO_INT_PREVIOUSPC:               info->i = 0;   /* TODO??? */         break;
397384
398385   case CPUINFO_INT_INPUT_STATE + 0:
399386   case CPUINFO_INT_INPUT_STATE + 1:
400387   case CPUINFO_INT_INPUT_STATE + 2:
401388   case CPUINFO_INT_INPUT_STATE + 3:
402   case CPUINFO_INT_INPUT_STATE + 4:               info->i = cpustate->w.IF & (1 << (state-CPUINFO_INT_INPUT_STATE)); break;
389   case CPUINFO_INT_INPUT_STATE + 4:               info->i = cpustate->IF & (1 << (state-CPUINFO_INT_INPUT_STATE)); break;
403390
404   case CPUINFO_INT_REGISTER + LR35902_PC:         info->i = cpustate->w.PC;               break;
405   case CPUINFO_INT_REGISTER + LR35902_SP:         info->i = cpustate->w.SP;               break;
406   case CPUINFO_INT_REGISTER + LR35902_AF:         info->i = cpustate->w.AF;               break;
407   case CPUINFO_INT_REGISTER + LR35902_BC:         info->i = cpustate->w.BC;               break;
408   case CPUINFO_INT_REGISTER + LR35902_DE:         info->i = cpustate->w.DE;               break;
409   case CPUINFO_INT_REGISTER + LR35902_HL:         info->i = cpustate->w.HL;               break;
410   case CPUINFO_INT_REGISTER + LR35902_IE:         info->i = cpustate->w.IE;               break;
411   case CPUINFO_INT_REGISTER + LR35902_IF:         info->i = cpustate->w.IF;               break;
412   case CPUINFO_INT_REGISTER + LR35902_SPEED:      info->i = 0x7E | ( ( cpustate->w.gb_speed - 1 ) << 7 ) | cpustate->w.gb_speed_change_pending; break;
391   case CPUINFO_INT_REGISTER + LR35902_PC:         info->i = cpustate->PC;               break;
392   case CPUINFO_INT_REGISTER + LR35902_SP:         info->i = cpustate->SP;               break;
393   case CPUINFO_INT_REGISTER + LR35902_AF:         info->i = ( cpustate->A << 8 ) | cpustate->F;               break;
394   case CPUINFO_INT_REGISTER + LR35902_BC:         info->i = ( cpustate->B << 8 ) | cpustate->C;               break;
395   case CPUINFO_INT_REGISTER + LR35902_DE:         info->i = ( cpustate->D << 8 ) | cpustate->E;               break;
396   case CPUINFO_INT_REGISTER + LR35902_HL:         info->i = ( cpustate->H << 8 ) | cpustate->L;               break;
397   case CPUINFO_INT_REGISTER + LR35902_IE:         info->i = cpustate->IE;               break;
398   case CPUINFO_INT_REGISTER + LR35902_IF:         info->i = cpustate->IF;               break;
399   case CPUINFO_INT_REGISTER + LR35902_SPEED:      info->i = 0x7E | ( ( cpustate->gb_speed - 1 ) << 7 ) | cpustate->gb_speed_change_pending; break;
413400
414401   /* --- the following bits of info are returned as pointers to data or functions --- */
415402   case CPUINFO_FCT_SET_INFO:                  info->setinfo = CPU_SET_INFO_NAME(lr35902);      break;
r14630r14631
418405   case CPUINFO_FCT_EXECUTE:                  info->execute = CPU_EXECUTE_NAME(lr35902);      break;
419406   case CPUINFO_FCT_BURN:                     info->burn = CPU_BURN_NAME(lr35902);            break;
420407   case CPUINFO_FCT_DISASSEMBLE:               info->disassemble = CPU_DISASSEMBLE_NAME(lr35902);      break;
421   case CPUINFO_PTR_INSTRUCTION_COUNTER:         info->icount = &cpustate->w.icount;         break;
408   case CPUINFO_PTR_INSTRUCTION_COUNTER:         info->icount = &cpustate->icount;         break;
422409
423410   /* --- the following bits of info are returned as NULL-terminated strings --- */
424411   case DEVINFO_STR_NAME:                     strcpy(info->s, "LR35902"); break;
r14630r14631
429416
430417   case CPUINFO_STR_FLAGS:
431418      sprintf(info->s, "%c%c%c%c%c%c%c%c",
432         cpustate->b.F & 0x80 ? 'Z':'.',
433         cpustate->b.F & 0x40 ? 'N':'.',
434         cpustate->b.F & 0x20 ? 'H':'.',
435         cpustate->b.F & 0x10 ? 'C':'.',
436         cpustate->b.F & 0x08 ? '3':'.',
437         cpustate->b.F & 0x04 ? '2':'.',
438         cpustate->b.F & 0x02 ? '1':'.',
439         cpustate->b.F & 0x01 ? '0':'.');
419         cpustate->F & 0x80 ? 'Z':'.',
420         cpustate->F & 0x40 ? 'N':'.',
421         cpustate->F & 0x20 ? 'H':'.',
422         cpustate->F & 0x10 ? 'C':'.',
423         cpustate->F & 0x08 ? '3':'.',
424         cpustate->F & 0x04 ? '2':'.',
425         cpustate->F & 0x02 ? '1':'.',
426         cpustate->F & 0x01 ? '0':'.');
440427      break;
441428
442   case CPUINFO_STR_REGISTER + LR35902_PC: sprintf(info->s, "PC:%04X", cpustate->w.PC); break;
443   case CPUINFO_STR_REGISTER + LR35902_SP: sprintf(info->s, "SP:%04X", cpustate->w.SP); break;
444   case CPUINFO_STR_REGISTER + LR35902_AF: sprintf(info->s, "AF:%04X", cpustate->w.AF); break;
445   case CPUINFO_STR_REGISTER + LR35902_BC: sprintf(info->s, "BC:%04X", cpustate->w.BC); break;
446   case CPUINFO_STR_REGISTER + LR35902_DE: sprintf(info->s, "DE:%04X", cpustate->w.DE); break;
447   case CPUINFO_STR_REGISTER + LR35902_HL: sprintf(info->s, "HL:%04X", cpustate->w.HL); break;
448   case CPUINFO_STR_REGISTER + LR35902_IRQ_STATE: sprintf(info->s, "IRQ:%X", cpustate->w.enable & IME ); break;
449   case CPUINFO_STR_REGISTER + LR35902_IE: sprintf(info->s, "IE:%02X", cpustate->w.IE); break;
450   case CPUINFO_STR_REGISTER + LR35902_IF: sprintf(info->s, "IF:%02X", cpustate->w.IF); break;
451   case CPUINFO_STR_REGISTER + LR35902_SPEED: sprintf(info->s, "SPD:%02x", 0x7E | ( ( cpustate->w.gb_speed - 1 ) << 7 ) | cpustate->w.gb_speed_change_pending ); break;
429   case CPUINFO_STR_REGISTER + LR35902_PC: sprintf(info->s, "PC:%04X", cpustate->PC); break;
430   case CPUINFO_STR_REGISTER + LR35902_SP: sprintf(info->s, "SP:%04X", cpustate->SP); break;
431   case CPUINFO_STR_REGISTER + LR35902_AF: sprintf(info->s, "AF:%02X%02X", cpustate->A, cpustate->F); break;
432   case CPUINFO_STR_REGISTER + LR35902_BC: sprintf(info->s, "BC:%02X%02X", cpustate->B, cpustate->C); break;
433   case CPUINFO_STR_REGISTER + LR35902_DE: sprintf(info->s, "DE:%02X%02X", cpustate->D, cpustate->E); break;
434   case CPUINFO_STR_REGISTER + LR35902_HL: sprintf(info->s, "HL:%02X%02X", cpustate->H, cpustate->L); break;
435   case CPUINFO_STR_REGISTER + LR35902_IRQ_STATE: sprintf(info->s, "IRQ:%X", cpustate->enable & IME ); break;
436   case CPUINFO_STR_REGISTER + LR35902_IE: sprintf(info->s, "IE:%02X", cpustate->IE); break;
437   case CPUINFO_STR_REGISTER + LR35902_IF: sprintf(info->s, "IF:%02X", cpustate->IF); break;
438   case CPUINFO_STR_REGISTER + LR35902_SPEED: sprintf(info->s, "SPD:%02x", 0x7E | ( ( cpustate->gb_speed - 1 ) << 7 ) | cpustate->gb_speed_change_pending ); break;
452439   }
453440}
454441
src/emu/cpu/lr35902/opc_cb.h
r14630r14631
88      f=0;               \
99   if( (x)==0 )            \
1010      f|=FLAG_Z;            \
11   cpustate->b.F=f;         \
11   cpustate->F=f;         \
1212}
1313
1414#define   RL_8BIT(x)            \
1515{                        \
1616   register UINT8 r;         \
1717   r=((x)&0x80)?FLAG_C:0;      \
18   (x)=(UINT8)(((x)<<1)|((cpustate->b.F&FLAG_C)?1:0));    \
18   (x)=(UINT8)(((x)<<1)|((cpustate->F&FLAG_C)?1:0));    \
1919   if( (x)==0 )            \
2020      r|=FLAG_Z;            \
21   cpustate->b.F=r;         \
21   cpustate->F=r;         \
2222}
2323
2424#define   RRC_8BIT(x)            \
r14630r14631
3131      f=0;               \
3232   if( (x)==0 )            \
3333      f|=FLAG_Z;            \
34   cpustate->b.F=f;         \
34   cpustate->F=f;         \
3535}
3636
3737#define   RR_8BIT(x)            \
3838{                        \
3939   register UINT8 r;         \
4040   r=((x)&1)?FLAG_C:0;         \
41   (x)=(UINT8)(((x)>>1)|((cpustate->b.F&FLAG_C)?0x80:0));    \
41   (x)=(UINT8)(((x)>>1)|((cpustate->F&FLAG_C)?0x80:0));    \
4242   if( (x)==0 )            \
4343      r|=FLAG_Z;            \
44   cpustate->b.F=r;         \
44   cpustate->F=r;         \
4545}
4646
4747#define   SLA_8BIT(x)            \
r14630r14631
5454   (x)<<=1;               \
5555   if( (x)==0 )            \
5656      f|=FLAG_Z;            \
57   cpustate->b.F=f;         \
57   cpustate->F=f;         \
5858}
5959
6060#define   SRA_8BIT(x)            \
r14630r14631
6767   (x)=(UINT8)(((char)(x))>>1);    \
6868   if( (x)==0 )            \
6969      f|=FLAG_Z;            \
70   cpustate->b.F=f;         \
70   cpustate->F=f;         \
7171}
7272
7373#define   SWAP_8BIT(x)         \
7474   (x)=(UINT8)(((x)>>4)|((x)<<4));     \
7575   if( (x)==0 )            \
76      cpustate->b.F=FLAG_Z;   \
76      cpustate->F=FLAG_Z;   \
7777   else                  \
78      cpustate->b.F=0;
78      cpustate->F=0;
7979
8080
8181#define   SRL_8BIT(x)            \
r14630r14631
8888   (x)>>=1;               \
8989   if( (x)==0 )            \
9090      f|=FLAG_Z;            \
91   cpustate->b.F=f;         \
91   cpustate->F=f;         \
9292}
9393
9494#define   BIT_8BIT(n,x)         \
9595   if( (x)&(1<<(n)) )         \
96      cpustate->b.F=(UINT8)(FLAG_H|(cpustate->b.F&FLAG_C));  \
96      cpustate->F=(UINT8)(FLAG_H|(cpustate->F&FLAG_C));  \
9797   else                  \
98      cpustate->b.F=(UINT8)(FLAG_Z|FLAG_H|(cpustate->b.F&FLAG_C));
98      cpustate->F=(UINT8)(FLAG_Z|FLAG_H|(cpustate->F&FLAG_C));
9999
100100#define   RES_8BIT(n,x)   (x)&=~(1<<(n));
101101
r14630r14631
105105case 0x00:
106106  /*      RLC B */
107107
108  RLC_8BIT (cpustate->b.B)
108  RLC_8BIT (cpustate->B)
109109  break;
110110case 0x01:
111111  /*      RLC C */
112112
113  RLC_8BIT (cpustate->b.C)
113  RLC_8BIT (cpustate->C)
114114  break;
115115case 0x02:
116116  /*      RLC D */
117117
118  RLC_8BIT (cpustate->b.D)
118  RLC_8BIT (cpustate->D)
119119  break;
120120case 0x03:
121121  /*      RLC E */
122122
123  RLC_8BIT (cpustate->b.E)
123  RLC_8BIT (cpustate->E)
124124  break;
125125case 0x04:
126126  /*      RLC H */
127127
128  RLC_8BIT (cpustate->b.H)
128  RLC_8BIT (cpustate->H)
129129  break;
130130case 0x05:
131131  /*      RLC L */
132132
133  RLC_8BIT (cpustate->b.L)
133  RLC_8BIT (cpustate->L)
134134  break;
135135case 0x06:
136  /*      RLC (HL) */
136   /*      RLC (HL) */
137   {
138      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
137139
138  x = mem_ReadByte (cpustate, cpustate->w.HL);
139  RLC_8BIT (x)
140  mem_WriteByte (cpustate, cpustate->w.HL, x);
141  break;
140      x = mem_ReadByte (cpustate, addr);
141      RLC_8BIT (x)
142      mem_WriteByte (cpustate, addr, x);
143   }
144   break;
142145case 0x07:
143146  /*      RLC A */
144147
145  RLC_8BIT (cpustate->b.A)
148  RLC_8BIT (cpustate->A)
146149  break;
147150case 0x08:
148151  /*      RRC B */
149152
150  RRC_8BIT (cpustate->b.B)
153  RRC_8BIT (cpustate->B)
151154  break;
152155case 0x09:
153156  /*      RRC C */
154157
155  RRC_8BIT (cpustate->b.C)
158  RRC_8BIT (cpustate->C)
156159  break;
157160case 0x0A:
158161  /*      RRC D */
159162
160  RRC_8BIT (cpustate->b.D)
163  RRC_8BIT (cpustate->D)
161164  break;
162165case 0x0B:
163166  /*      RRC E */
164167
165  RRC_8BIT (cpustate->b.E)
168  RRC_8BIT (cpustate->E)
166169  break;
167170case 0x0C:
168171  /*      RRC H */
169172
170  RRC_8BIT (cpustate->b.H)
173  RRC_8BIT (cpustate->H)
171174  break;
172175case 0x0D:
173176  /*      RRC L */
174177
175  RRC_8BIT (cpustate->b.L)
178  RRC_8BIT (cpustate->L)
176179  break;
177180case 0x0E:
178  /*      RRC (HL) */
181   /*      RRC (HL) */
182   {
183      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
179184
180  x = mem_ReadByte (cpustate, cpustate->w.HL);
181  RRC_8BIT (x)
182  mem_WriteByte (cpustate, cpustate->w.HL, x);
183  break;
185      x = mem_ReadByte (cpustate, addr);
186      RRC_8BIT (x)
187      mem_WriteByte (cpustate, addr, x);
188   }
189   break;
184190case 0x0F:
185191  /*      RRC A */
186192
187  RRC_8BIT (cpustate->b.A)
193  RRC_8BIT (cpustate->A)
188194  break;
189195case 0x10:
190196  /*      RL B */
191197
192  RL_8BIT (cpustate->b.B)
198  RL_8BIT (cpustate->B)
193199  break;
194200case 0x11:
195201  /*      RL C */
196202
197  RL_8BIT (cpustate->b.C)
203  RL_8BIT (cpustate->C)
198204  break;
199205case 0x12:
200206  /*      RL D */
201207
202  RL_8BIT (cpustate->b.D)
208  RL_8BIT (cpustate->D)
203209  break;
204210case 0x13:
205211  /*      RL E */
206212
207  RL_8BIT (cpustate->b.E)
213  RL_8BIT (cpustate->E)
208214  break;
209215case 0x14:
210216  /*      RL H */
211217
212  RL_8BIT (cpustate->b.H)
218  RL_8BIT (cpustate->H)
213219  break;
214220case 0x15:
215221  /*      RL L */
216222
217  RL_8BIT (cpustate->b.L)
223  RL_8BIT (cpustate->L)
218224  break;
219225case 0x16:
220  /*      RL (HL) */
226   /*      RL (HL) */
227   {
228      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
221229
222  x = mem_ReadByte (cpustate, cpustate->w.HL);
223  RL_8BIT (x)
224  mem_WriteByte (cpustate, cpustate->w.HL, x);
225  break;
230      x = mem_ReadByte (cpustate, addr);
231      RL_8BIT (x)
232      mem_WriteByte (cpustate, addr, x);
233   }
234   break;
226235case 0x17:
227236  /*      RL A */
228237
229  RL_8BIT (cpustate->b.A)
238  RL_8BIT (cpustate->A)
230239  break;
231240case 0x18:
232241  /*      RR B */
233242
234  RR_8BIT (cpustate->b.B)
243  RR_8BIT (cpustate->B)
235244  break;
236245case 0x19:
237246  /*      RR C */
238247
239  RR_8BIT (cpustate->b.C)
248  RR_8BIT (cpustate->C)
240249  break;
241250case 0x1A:
242251  /*      RR D */
243252
244  RR_8BIT (cpustate->b.D)
253  RR_8BIT (cpustate->D)
245254  break;
246255case 0x1B:
247256  /*      RR E */
248257
249  RR_8BIT (cpustate->b.E)
258  RR_8BIT (cpustate->E)
250259  break;
251260case 0x1C:
252261  /*      RR H */
253262
254  RR_8BIT (cpustate->b.H)
263  RR_8BIT (cpustate->H)
255264  break;
256265case 0x1D:
257266  /*      RR L */
258267
259  RR_8BIT (cpustate->b.L)
268  RR_8BIT (cpustate->L)
260269  break;
261270case 0x1E:
262  /*      RR (HL) */
271   /*      RR (HL) */
272   {
273      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
263274
264  x = mem_ReadByte (cpustate, cpustate->w.HL);
265  RR_8BIT (x)
266  mem_WriteByte (cpustate, cpustate->w.HL, x);
267  break;
275      x = mem_ReadByte (cpustate, addr);
276      RR_8BIT (x)
277      mem_WriteByte (cpustate, addr, x);
278   }
279   break;
268280case 0x1F:
269281  /*      RR A */
270282
271  RR_8BIT (cpustate->b.A)
283  RR_8BIT (cpustate->A)
272284  break;
273285case 0x20:
274286  /*      SLA B */
275287
276  SLA_8BIT (cpustate->b.B)
288  SLA_8BIT (cpustate->B)
277289  break;
278290case 0x21:
279291  /*      SLA C */
280292
281  SLA_8BIT (cpustate->b.C)
293  SLA_8BIT (cpustate->C)
282294  break;
283295case 0x22:
284296  /*      SLA D */
285297
286  SLA_8BIT (cpustate->b.D)
298  SLA_8BIT (cpustate->D)
287299  break;
288300case 0x23:
289301  /*      SLA E */
290302
291  SLA_8BIT (cpustate->b.E)
303  SLA_8BIT (cpustate->E)
292304  break;
293305case 0x24:
294306  /*      SLA H */
295307
296  SLA_8BIT (cpustate->b.H)
308  SLA_8BIT (cpustate->H)
297309  break;
298310case 0x25:
299311  /*      SLA L */
300312
301  SLA_8BIT (cpustate->b.L)
313  SLA_8BIT (cpustate->L)
302314  break;
303315case 0x26:
304  /*      SLA (HL) */
316   /*      SLA (HL) */
317   {
318      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
305319
306  x = mem_ReadByte (cpustate, cpustate->w.HL);
307  SLA_8BIT (x)
308  mem_WriteByte (cpustate, cpustate->w.HL, x);
309  break;
320      x = mem_ReadByte (cpustate, addr);
321      SLA_8BIT (x)
322      mem_WriteByte (cpustate, addr, x);
323   }
324   break;
310325case 0x27:
311326  /*      SLA A */
312327
313  SLA_8BIT (cpustate->b.A)
328  SLA_8BIT (cpustate->A)
314329  break;
315330case 0x28:
316331  /*      SRA B */
317332
318  SRA_8BIT (cpustate->b.B)
333  SRA_8BIT (cpustate->B)
319334  break;
320335case 0x29:
321336  /*      SRA C */
322337
323  SRA_8BIT (cpustate->b.C)
338  SRA_8BIT (cpustate->C)
324339  break;
325340case 0x2A:
326341  /*      SRA D */
327342
328  SRA_8BIT (cpustate->b.D)
343  SRA_8BIT (cpustate->D)
329344  break;
330345case 0x2B:
331346  /*      SRA E */
332347
333  SRA_8BIT (cpustate->b.E)
348  SRA_8BIT (cpustate->E)
334349  break;
335350case 0x2C:
336351  /*      SRA H */
337352
338  SRA_8BIT (cpustate->b.H)
353  SRA_8BIT (cpustate->H)
339354  break;
340355case 0x2D:
341356  /*      SRA L */
342357
343  SRA_8BIT (cpustate->b.L)
358  SRA_8BIT (cpustate->L)
344359  break;
345360case 0x2E:
346  /*      SRA (HL) */
361   /*      SRA (HL) */
362   {
363      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
347364
348  x = mem_ReadByte (cpustate, cpustate->w.HL);
349  SRA_8BIT (x)
350  mem_WriteByte (cpustate, cpustate->w.HL, x);
351  break;
365      x = mem_ReadByte (cpustate, addr);
366      SRA_8BIT (x)
367      mem_WriteByte (cpustate, addr, x);
368   }
369   break;
352370case 0x2F:
353371  /*      SRA A */
354372
355  SRA_8BIT (cpustate->b.A)
373  SRA_8BIT (cpustate->A)
356374  break;
357375case 0x30:
358376  /*      SWAP B */
359377
360  SWAP_8BIT (cpustate->b.B)
378  SWAP_8BIT (cpustate->B)
361379  break;
362380case 0x31:
363381  /*      SWAP C */
364382
365  SWAP_8BIT (cpustate->b.C)
383  SWAP_8BIT (cpustate->C)
366384  break;
367385case 0x32:
368386  /*      SWAP D */
369387
370  SWAP_8BIT (cpustate->b.D)
388  SWAP_8BIT (cpustate->D)
371389  break;
372390case 0x33:
373391  /*      SWAP E */
374392
375  SWAP_8BIT (cpustate->b.E)
393  SWAP_8BIT (cpustate->E)
376394  break;
377395case 0x34:
378396  /*      SWAP H */
379397
380  SWAP_8BIT (cpustate->b.H)
398  SWAP_8BIT (cpustate->H)
381399  break;
382400case 0x35:
383401  /*      SWAP L */
384402
385  SWAP_8BIT (cpustate->b.L)
403  SWAP_8BIT (cpustate->L)
386404  break;
387405case 0x36:
388  /*      SWAP (HL) */
406   /*      SWAP (HL) */
407   {
408      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
389409
390  x = mem_ReadByte (cpustate, cpustate->w.HL);
391  SWAP_8BIT (x)
392  mem_WriteByte (cpustate, cpustate->w.HL, x);
393  break;
410      x = mem_ReadByte (cpustate, addr);
411      SWAP_8BIT (x)
412      mem_WriteByte (cpustate, addr, x);
413   }
414   break;
394415case 0x37:
395416  /*      SWAP A */
396417
397  SWAP_8BIT (cpustate->b.A)
418  SWAP_8BIT (cpustate->A)
398419  break;
399420case 0x38:
400421  /*      SRL B */
401422
402  SRL_8BIT (cpustate->b.B)
423  SRL_8BIT (cpustate->B)
403424  break;
404425case 0x39:
405426  /*      SRL C */
406427
407  SRL_8BIT (cpustate->b.C)
428  SRL_8BIT (cpustate->C)
408429  break;
409430case 0x3A:
410431  /*      SRL D */
411432
412  SRL_8BIT (cpustate->b.D)
433  SRL_8BIT (cpustate->D)
413434  break;
414435case 0x3B:
415436  /*      SRL E */
416437
417  SRL_8BIT (cpustate->b.E)
438  SRL_8BIT (cpustate->E)
418439  break;
419440case 0x3C:
420441  /*      SRL H */
421442
422  SRL_8BIT (cpustate->b.H)
443  SRL_8BIT (cpustate->H)
423444  break;
424445case 0x3D:
425446  /*      SRL L */
426447
427  SRL_8BIT (cpustate->b.L)
448  SRL_8BIT (cpustate->L)
428449  break;
429450case 0x3E:
430  /*      SRL (HL) */
451   /*      SRL (HL) */
452   {
453      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
431454
432  x = mem_ReadByte (cpustate, cpustate->w.HL);
433  SRL_8BIT (x)
434  mem_WriteByte (cpustate, cpustate->w.HL, x);
435  break;
455      x = mem_ReadByte (cpustate, addr);
456      SRL_8BIT (x)
457      mem_WriteByte (cpustate, addr, x);
458   }
459   break;
436460case 0x3F:
437461  /*      SRL A */
438462
439  SRL_8BIT (cpustate->b.A)
463  SRL_8BIT (cpustate->A)
440464  break;
441465case 0x40:
442466  /*      BIT 0,B */
443467
444  BIT_8BIT (0, cpustate->b.B)
468  BIT_8BIT (0, cpustate->B)
445469  break;
446470case 0x41:
447471  /*      BIT 0,C */
448472
449  BIT_8BIT (0, cpustate->b.C)
473  BIT_8BIT (0, cpustate->C)
450474  break;
451475case 0x42:
452476  /*      BIT 0,D */
453477
454  BIT_8BIT (0, cpustate->b.D)
478  BIT_8BIT (0, cpustate->D)
455479  break;
456480case 0x43:
457481  /*      BIT 0,E */
458482
459  BIT_8BIT (0, cpustate->b.E)
483  BIT_8BIT (0, cpustate->E)
460484  break;
461485case 0x44:
462486  /*      BIT 0,H */
463487
464  BIT_8BIT (0, cpustate->b.H)
488  BIT_8BIT (0, cpustate->H)
465489  break;
466490case 0x45:
467491  /*      BIT 0,L */
468492
469  BIT_8BIT (0, cpustate->b.L)
493  BIT_8BIT (0, cpustate->L)
470494  break;
471495case 0x46:
472  /*      BIT 0,(HL) */
496   /*      BIT 0,(HL) */
497   {
498      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
473499
474  x = mem_ReadByte (cpustate, cpustate->w.HL);
475  BIT_8BIT (0, x)
476  break;
500      x = mem_ReadByte (cpustate, addr);
501      BIT_8BIT (0, x)
502   }
503   break;
477504case 0x47:
478505  /*      BIT 0,A */
479506
480  BIT_8BIT (0, cpustate->b.A)
507  BIT_8BIT (0, cpustate->A)
481508  break;
482509case 0x48:
483510  /*      BIT 1,B */
484511
485  BIT_8BIT (1, cpustate->b.B)
512  BIT_8BIT (1, cpustate->B)
486513  break;
487514case 0x49:
488515  /*      BIT 1,C */
489516
490  BIT_8BIT (1, cpustate->b.C)
517  BIT_8BIT (1, cpustate->C)
491518  break;
492519case 0x4A:
493520  /*      BIT 1,D */
494521
495  BIT_8BIT (1, cpustate->b.D)
522  BIT_8BIT (1, cpustate->D)
496523  break;
497524case 0x4B:
498525  /*      BIT 1,E */
499526
500  BIT_8BIT (1, cpustate->b.E)
527  BIT_8BIT (1, cpustate->E)
501528  break;
502529case 0x4C:
503530  /*      BIT 1,H */
504531
505  BIT_8BIT (1, cpustate->b.H)
532  BIT_8BIT (1, cpustate->H)
506533  break;
507534case 0x4D:
508535  /*      BIT 1,L */
509536
510  BIT_8BIT (1, cpustate->b.L)
537  BIT_8BIT (1, cpustate->L)
511538  break;
512539case 0x4E:
513  /*      BIT 1,(HL) */
540   /*      BIT 1,(HL) */
541   {
542      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
514543
515  x = mem_ReadByte (cpustate, cpustate->w.HL);
516  BIT_8BIT (1, x)
517  break;
544      x = mem_ReadByte (cpustate, addr);
545      BIT_8BIT (1, x)
546   }
547   break;
518548case 0x4F:
519549  /*      BIT 1,A */
520550
521  BIT_8BIT (1, cpustate->b.A)
551  BIT_8BIT (1, cpustate->A)
522552  break;
523553case 0x50:
524554  /*      BIT 2,B */
525555
526  BIT_8BIT (2, cpustate->b.B)
556  BIT_8BIT (2, cpustate->B)
527557  break;
528558case 0x51:
529559  /*      BIT 2,C */
530560
531  BIT_8BIT (2, cpustate->b.C)
561  BIT_8BIT (2, cpustate->C)
532562  break;
533563case 0x52:
534564  /*      BIT 2,D */
535565
536  BIT_8BIT (2, cpustate->b.D)
566  BIT_8BIT (2, cpustate->D)
537567  break;
538568case 0x53:
539569  /*      BIT 2,E */
540570
541  BIT_8BIT (2, cpustate->b.E)
571  BIT_8BIT (2, cpustate->E)
542572  break;
543573case 0x54:
544574  /*      BIT 2,H */
545575
546  BIT_8BIT (2, cpustate->b.H)
576  BIT_8BIT (2, cpustate->H)
547577  break;
548578case 0x55:
549579  /*      BIT 2,L */
550580
551  BIT_8BIT (2, cpustate->b.L)
581  BIT_8BIT (2, cpustate->L)
552582  break;
553583case 0x56:
554  /*      BIT 2,(HL) */
584   /*      BIT 2,(HL) */
585   {
586      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
555587
556  x = mem_ReadByte (cpustate, cpustate->w.HL);
557  BIT_8BIT (2, x)
558  break;
588      x = mem_ReadByte (cpustate, addr);
589      BIT_8BIT (2, x)
590   }
591   break;
559592case 0x57:
560593  /*      BIT 2,A */
561594
562  BIT_8BIT (2, cpustate->b.A)
595  BIT_8BIT (2, cpustate->A)
563596  break;
564597case 0x58:
565598  /*      BIT 3,B */
566599
567  BIT_8BIT (3, cpustate->b.B)
600  BIT_8BIT (3, cpustate->B)
568601  break;
569602case 0x59:
570603  /*      BIT 3,C */
571604
572  BIT_8BIT (3, cpustate->b.C)
605  BIT_8BIT (3, cpustate->C)
573606  break;
574607case 0x5A:
575608  /*      BIT 3,D */
576609
577  BIT_8BIT (3, cpustate->b.D)
610  BIT_8BIT (3, cpustate->D)
578611  break;
579612case 0x5B:
580613  /*      BIT 3,E */
581614
582  BIT_8BIT (3, cpustate->b.E)
615  BIT_8BIT (3, cpustate->E)
583616  break;
584617case 0x5C:
585618  /*      BIT 3,H */
586619
587  BIT_8BIT (3, cpustate->b.H)
620  BIT_8BIT (3, cpustate->H)
588621  break;
589622case 0x5D:
590623  /*      BIT 3,L */
591624
592  BIT_8BIT (3, cpustate->b.L)
625  BIT_8BIT (3, cpustate->L)
593626  break;
594627case 0x5E:
595  /*      BIT 3,(HL) */
628   /*      BIT 3,(HL) */
629   {
630      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
596631
597  x = mem_ReadByte (cpustate, cpustate->w.HL);
598  BIT_8BIT (3, x)
599  break;
632      x = mem_ReadByte (cpustate, addr);
633      BIT_8BIT (3, x)
634   }
635   break;
600636case 0x5F:
601637  /*      BIT 3,A */
602638
603  BIT_8BIT (3, cpustate->b.A)
639  BIT_8BIT (3, cpustate->A)
604640  break;
605641case 0x60:
606642  /*      BIT 4,B */
607643
608  BIT_8BIT (4, cpustate->b.B)
644  BIT_8BIT (4, cpustate->B)
609645  break;
610646case 0x61:
611647  /*      BIT 4,C */
612648
613  BIT_8BIT (4, cpustate->b.C)
649  BIT_8BIT (4, cpustate->C)
614650  break;
615651case 0x62:
616652  /*      BIT 4,D */
617653
618  BIT_8BIT (4, cpustate->b.D)
654  BIT_8BIT (4, cpustate->D)
619655  break;
620656case 0x63:
621657  /*      BIT 4,E */
622658
623  BIT_8BIT (4, cpustate->b.E)
659  BIT_8BIT (4, cpustate->E)
624660  break;
625661case 0x64:
626662  /*      BIT 4,H */
627663
628  BIT_8BIT (4, cpustate->b.H)
664  BIT_8BIT (4, cpustate->H)
629665  break;
630666case 0x65:
631667  /*      BIT 4,L */
632668
633  BIT_8BIT (4, cpustate->b.L)
669  BIT_8BIT (4, cpustate->L)
634670  break;
635671case 0x66:
636  /*      BIT 4,(HL) */
672   /*      BIT 4,(HL) */
673   {
674      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
637675
638  x = mem_ReadByte (cpustate, cpustate->w.HL);
639  BIT_8BIT (4, x)
640  break;
676      x = mem_ReadByte (cpustate, addr);
677      BIT_8BIT (4, x)
678   }
679   break;
641680case 0x67:
642681  /*      BIT 4,A */
643682
644  BIT_8BIT (4, cpustate->b.A)
683  BIT_8BIT (4, cpustate->A)
645684  break;
646685case 0x68:
647686  /*      BIT 5,B */
648687
649  BIT_8BIT (5, cpustate->b.B)
688  BIT_8BIT (5, cpustate->B)
650689  break;
651690case 0x69:
652691  /*      BIT 5,C */
653692
654  BIT_8BIT (5, cpustate->b.C)
693  BIT_8BIT (5, cpustate->C)
655694  break;
656695case 0x6A:
657696  /*      BIT 5,D */
658697
659  BIT_8BIT (5, cpustate->b.D)
698  BIT_8BIT (5, cpustate->D)
660699  break;
661700case 0x6B:
662701  /*      BIT 5,E */
663702
664  BIT_8BIT (5, cpustate->b.E)
703  BIT_8BIT (5, cpustate->E)
665704  break;
666705case 0x6C:
667706  /*      BIT 5,H */
668707
669  BIT_8BIT (5, cpustate->b.H)
708  BIT_8BIT (5, cpustate->H)
670709  break;
671710case 0x6D:
672711  /*      BIT 5,L */
673712
674  BIT_8BIT (5, cpustate->b.L)
713  BIT_8BIT (5, cpustate->L)
675714  break;
676715case 0x6E:
677  /*      BIT 5,(HL) */
716   /*      BIT 5,(HL) */
717   {
718      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
678719
679  x = mem_ReadByte (cpustate, cpustate->w.HL);
680  BIT_8BIT (5, x)
681  break;
720      x = mem_ReadByte (cpustate, addr);
721      BIT_8BIT (5, x)
722   }
723   break;
682724case 0x6F:
683725  /*      BIT 5,A */
684726
685  BIT_8BIT (5, cpustate->b.A)
727  BIT_8BIT (5, cpustate->A)
686728  break;
687729case 0x70:
688730  /*      BIT 6,B */
689731
690  BIT_8BIT (6, cpustate->b.B)
732  BIT_8BIT (6, cpustate->B)
691733  break;
692734case 0x71:
693735  /*      BIT 6,C */
694736
695  BIT_8BIT (6, cpustate->b.C)
737  BIT_8BIT (6, cpustate->C)
696738  break;
697739case 0x72:
698740  /*      BIT 6,D */
699741
700  BIT_8BIT (6, cpustate->b.D)
742  BIT_8BIT (6, cpustate->D)
701743  break;
702744case 0x73:
703745  /*      BIT 6,E */
704746
705  BIT_8BIT (6, cpustate->b.E)
747  BIT_8BIT (6, cpustate->E)
706748  break;
707749case 0x74:
708750  /*      BIT 6,H */
709751
710  BIT_8BIT (6, cpustate->b.H)
752  BIT_8BIT (6, cpustate->H)
711753  break;
712754case 0x75:
713755  /*      BIT 6,L */
714756
715  BIT_8BIT (6, cpustate->b.L)
757  BIT_8BIT (6, cpustate->L)
716758  break;
717759case 0x76:
718  /*      BIT 6,(HL) */
760   /*      BIT 6,(HL) */
761   {
762      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
719763
720  x = mem_ReadByte (cpustate, cpustate->w.HL);
721  BIT_8BIT (6, x)
722  break;
764      x = mem_ReadByte (cpustate, addr);
765      BIT_8BIT (6, x)
766   }
767   break;
723768case 0x77:
724769  /*      BIT 6,A */
725770
726  BIT_8BIT (6, cpustate->b.A)
771  BIT_8BIT (6, cpustate->A)
727772  break;
728773case 0x78:
729774  /*      BIT 7,B */
730775
731  BIT_8BIT (7, cpustate->b.B)
776  BIT_8BIT (7, cpustate->B)
732777  break;
733778case 0x79:
734779  /*      BIT 7,C */
735780
736  BIT_8BIT (7, cpustate->b.C)
781  BIT_8BIT (7, cpustate->C)
737782  break;
738783case 0x7A:
739784  /*      BIT 7,D */
740785
741  BIT_8BIT (7, cpustate->b.D)
786  BIT_8BIT (7, cpustate->D)
742787  break;
743788case 0x7B:
744789  /*      BIT 7,E */
745790
746  BIT_8BIT (7, cpustate->b.E)
791  BIT_8BIT (7, cpustate->E)
747792  break;
748793case 0x7C:
749794  /*      BIT 7,H */
750795
751  BIT_8BIT (7, cpustate->b.H)
796  BIT_8BIT (7, cpustate->H)
752797  break;
753798case 0x7D:
754799  /*      BIT 7,L */
755800
756  BIT_8BIT (7, cpustate->b.L)
801  BIT_8BIT (7, cpustate->L)
757802  break;
758803case 0x7E:
759  /*      BIT 7,(HL) */
804   /*      BIT 7,(HL) */
805   {
806      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
760807
761  x = mem_ReadByte (cpustate, cpustate->w.HL);
762  BIT_8BIT (7, x)
763  break;
808      x = mem_ReadByte (cpustate, addr);
809      BIT_8BIT (7, x)
810   }
811   break;
764812case 0x7F:
765813  /*      BIT 7,A */
766814
767  BIT_8BIT (7, cpustate->b.A)
815  BIT_8BIT (7, cpustate->A)
768816  break;
769817case 0x80:
770818  /*      RES 0,B */
771819
772  RES_8BIT (0, cpustate->b.B)
820  RES_8BIT (0, cpustate->B)
773821  break;
774822case 0x81:
775823  /*      RES 0,C */
776824
777  RES_8BIT (0, cpustate->b.C)
825  RES_8BIT (0, cpustate->C)
778826  break;
779827case 0x82:
780828  /*      RES 0,D */
781829
782  RES_8BIT (0, cpustate->b.D)
830  RES_8BIT (0, cpustate->D)
783831  break;
784832case 0x83:
785833  /*      RES 0,E */
786834
787  RES_8BIT (0, cpustate->b.E)
835  RES_8BIT (0, cpustate->E)
788836  break;
789837case 0x84:
790838  /*      RES 0,H */
791839
792  RES_8BIT (0, cpustate->b.H)
840  RES_8BIT (0, cpustate->H)
793841  break;
794842case 0x85:
795843  /*      RES 0,L */
796844
797  RES_8BIT (0, cpustate->b.L)
845  RES_8BIT (0, cpustate->L)
798846  break;
799847case 0x86:
800  /*      RES 0,(HL) */
848   /*      RES 0,(HL) */
849   {
850      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
801851
802  x = mem_ReadByte (cpustate, cpustate->w.HL);
803  RES_8BIT (0, x)
804  mem_WriteByte (cpustate, cpustate->w.HL, x);
805  break;
852      x = mem_ReadByte (cpustate, addr);
853      RES_8BIT (0, x)
854      mem_WriteByte (cpustate, addr, x);
855   }
856   break;
806857case 0x87:
807858  /*      RES 0,A */
808859
809  RES_8BIT (0, cpustate->b.A)
860  RES_8BIT (0, cpustate->A)
810861  break;
811862case 0x88:
812863  /*      RES 1,B */
813864
814  RES_8BIT (1, cpustate->b.B)
865  RES_8BIT (1, cpustate->B)
815866  break;
816867case 0x89:
817868  /*      RES 1,C */
818869
819  RES_8BIT (1, cpustate->b.C)
870  RES_8BIT (1, cpustate->C)
820871  break;
821872case 0x8A:
822873  /*      RES 1,D */
823874
824  RES_8BIT (1, cpustate->b.D)
875  RES_8BIT (1, cpustate->D)
825876  break;
826877case 0x8B:
827878  /*      RES 1,E */
828879
829  RES_8BIT (1, cpustate->b.E)
880  RES_8BIT (1, cpustate->E)
830881  break;
831882case 0x8C:
832883  /*      RES 1,H */
833884
834  RES_8BIT (1, cpustate->b.H)
885  RES_8BIT (1, cpustate->H)
835886  break;
836887case 0x8D:
837888  /*      RES 1,L */
838889
839  RES_8BIT (1, cpustate->b.L)
890  RES_8BIT (1, cpustate->L)
840891  break;
841892case 0x8E:
842  /*      RES 1,(HL) */
893   /*      RES 1,(HL) */
894   {
895      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
843896
844  x = mem_ReadByte (cpustate, cpustate->w.HL);
845  RES_8BIT (1, x)
846  mem_WriteByte (cpustate, cpustate->w.HL, x);
847  break;
897      x = mem_ReadByte (cpustate, addr);
898      RES_8BIT (1, x)
899      mem_WriteByte (cpustate, addr, x);
900   }
901   break;
848902case 0x8F:
849903  /*      RES 1,A */
850904
851  RES_8BIT (1, cpustate->b.A)
905  RES_8BIT (1, cpustate->A)
852906  break;
853907case 0x90:
854908  /*      RES 2,B */
855909
856  RES_8BIT (2, cpustate->b.B)
910  RES_8BIT (2, cpustate->B)
857911  break;
858912case 0x91:
859913  /*      RES 2,C */
860914
861  RES_8BIT (2, cpustate->b.C)
915  RES_8BIT (2, cpustate->C)
862916  break;
863917case 0x92:
864918  /*      RES 2,D */
865919
866  RES_8BIT (2, cpustate->b.D)
920  RES_8BIT (2, cpustate->D)
867921  break;
868922case 0x93:
869923  /*      RES 2,E */
870924
871  RES_8BIT (2, cpustate->b.E)
925  RES_8BIT (2, cpustate->E)
872926  break;
873927case 0x94:
874928  /*      RES 2,H */
875929
876  RES_8BIT (2, cpustate->b.H)
930  RES_8BIT (2, cpustate->H)
877931  break;
878932case 0x95:
879933  /*      RES 2,L */
880934
881  RES_8BIT (2, cpustate->b.L)
935  RES_8BIT (2, cpustate->L)
882936  break;
883937case 0x96:
884  /*      RES 2,(HL) */
938   /*      RES 2,(HL) */
939   {
940      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
885941
886  x = mem_ReadByte (cpustate, cpustate->w.HL);
887  RES_8BIT (2, x)
888  mem_WriteByte (cpustate, cpustate->w.HL, x);
889  break;
942      x = mem_ReadByte (cpustate, addr);
943      RES_8BIT (2, x)
944      mem_WriteByte (cpustate, addr, x);
945   }
946   break;
890947case 0x97:
891948  /*      RES 2,A */
892949
893  RES_8BIT (2, cpustate->b.A)
950  RES_8BIT (2, cpustate->A)
894951  break;
895952case 0x98:
896953  /*      RES 3,B */
897954
898  RES_8BIT (3, cpustate->b.B)
955  RES_8BIT (3, cpustate->B)
899956  break;
900957case 0x99:
901958  /*      RES 3,C */
902959
903  RES_8BIT (3, cpustate->b.C)
960  RES_8BIT (3, cpustate->C)
904961  break;
905962case 0x9A:
906963  /*      RES 3,D */
907964
908  RES_8BIT (3, cpustate->b.D)
965  RES_8BIT (3, cpustate->D)
909966  break;
910967case 0x9B:
911968  /*      RES 3,E */
912969
913  RES_8BIT (3, cpustate->b.E)
970  RES_8BIT (3, cpustate->E)
914971  break;
915972case 0x9C:
916973  /*      RES 3,H */
917974
918  RES_8BIT (3, cpustate->b.H)
975  RES_8BIT (3, cpustate->H)
919976  break;
920977case 0x9D:
921978  /*      RES 3,L */
922979
923  RES_8BIT (3, cpustate->b.L)
980  RES_8BIT (3, cpustate->L)
924981  break;
925982case 0x9E:
926  /*      RES 3,(HL) */
983   /*      RES 3,(HL) */
984   {
985      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
927986
928  x = mem_ReadByte (cpustate, cpustate->w.HL);
929  RES_8BIT (3, x)
930  mem_WriteByte (cpustate, cpustate->w.HL, x);
931  break;
987      x = mem_ReadByte (cpustate, addr);
988      RES_8BIT (3, x)
989      mem_WriteByte (cpustate, addr, x);
990   }
991   break;
932992case 0x9F:
933993  /*      RES 3,A */
934994
935  RES_8BIT (3, cpustate->b.A)
995  RES_8BIT (3, cpustate->A)
936996  break;
937997case 0xA0:
938998  /*      RES 4,B */
939999
940  RES_8BIT (4, cpustate->b.B)
1000  RES_8BIT (4, cpustate->B)
9411001  break;
9421002case 0xA1:
9431003  /*      RES 4,C */
9441004
945  RES_8BIT (4, cpustate->b.C)
1005  RES_8BIT (4, cpustate->C)
9461006  break;
9471007case 0xA2:
9481008  /*      RES 4,D */
9491009
950  RES_8BIT (4, cpustate->b.D)
1010  RES_8BIT (4, cpustate->D)
9511011  break;
9521012case 0xA3:
9531013  /*      RES 4,E */
9541014
955  RES_8BIT (4, cpustate->b.E)
1015  RES_8BIT (4, cpustate->E)
9561016  break;
9571017case 0xA4:
9581018  /*      RES 4,H */
9591019
960  RES_8BIT (4, cpustate->b.H)
1020  RES_8BIT (4, cpustate->H)
9611021  break;
9621022case 0xA5:
9631023  /*      RES 4,L */
9641024
965  RES_8BIT (4, cpustate->b.L)
1025  RES_8BIT (4, cpustate->L)
9661026  break;
9671027case 0xA6:
968  /*      RES 4,(HL) */
1028   /*      RES 4,(HL) */
1029   {
1030      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
9691031
970  x = mem_ReadByte (cpustate, cpustate->w.HL);
971  RES_8BIT (4, x)
972  mem_WriteByte (cpustate, cpustate->w.HL, x);
973  break;
1032      x = mem_ReadByte (cpustate, addr);
1033      RES_8BIT (4, x)
1034      mem_WriteByte (cpustate, addr, x);
1035   }
1036   break;
9741037case 0xA7:
9751038  /*      RES 4,A */
9761039
977  RES_8BIT (4, cpustate->b.A)
1040  RES_8BIT (4, cpustate->A)
9781041  break;
9791042case 0xA8:
9801043  /*      RES 5,B */
9811044
982  RES_8BIT (5, cpustate->b.B)
1045  RES_8BIT (5, cpustate->B)
9831046  break;
9841047case 0xA9:
9851048  /*      RES 5,C */
9861049
987  RES_8BIT (5, cpustate->b.C)
1050  RES_8BIT (5, cpustate->C)
9881051  break;
9891052case 0xAA:
9901053  /*      RES 5,D */
9911054
992  RES_8BIT (5, cpustate->b.D)
1055  RES_8BIT (5, cpustate->D)
9931056  break;
9941057case 0xAB:
9951058  /*      RES 5,E */
9961059
997  RES_8BIT (5, cpustate->b.E)
1060  RES_8BIT (5, cpustate->E)
9981061  break;
9991062case 0xAC:
10001063  /*      RES 5,H */
10011064
1002  RES_8BIT (5, cpustate->b.H)
1065  RES_8BIT (5, cpustate->H)
10031066  break;
10041067case 0xAD:
10051068  /*      RES 5,L */
10061069
1007  RES_8BIT (5, cpustate->b.L)
1070  RES_8BIT (5, cpustate->L)
10081071  break;
10091072case 0xAE:
1010  /*      RES 5,(HL) */
1073   /*      RES 5,(HL) */
1074   {
1075      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
10111076
1012  x = mem_ReadByte (cpustate, cpustate->w.HL);
1013  RES_8BIT (5, x)
1014  mem_WriteByte (cpustate, cpustate->w.HL, x);
1015  break;
1077      x = mem_ReadByte (cpustate, addr);
1078      RES_8BIT (5, x)
1079      mem_WriteByte (cpustate, addr, x);
1080   }
1081   break;
10161082case 0xAF:
10171083  /*      RES 5,A */
10181084
1019  RES_8BIT (5, cpustate->b.A)
1085  RES_8BIT (5, cpustate->A)
10201086  break;
10211087case 0xB0:
10221088  /*      RES 6,B */
10231089
1024  RES_8BIT (6, cpustate->b.B)
1090  RES_8BIT (6, cpustate->B)
10251091  break;
10261092case 0xB1:
10271093  /*      RES 6,C */
10281094
1029  RES_8BIT (6, cpustate->b.C)
1095  RES_8BIT (6, cpustate->C)
10301096  break;
10311097case 0xB2:
10321098  /*      RES 6,D */
10331099
1034  RES_8BIT (6, cpustate->b.D)
1100  RES_8BIT (6, cpustate->D)
10351101  break;
10361102case 0xB3:
10371103  /*      RES 6,E */
10381104
1039  RES_8BIT (6, cpustate->b.E)
1105  RES_8BIT (6, cpustate->E)
10401106  break;
10411107case 0xB4:
10421108  /*      RES 6,H */
10431109
1044  RES_8BIT (6, cpustate->b.H)
1110  RES_8BIT (6, cpustate->H)
10451111  break;
10461112case 0xB5:
10471113  /*      RES 6,L */
10481114
1049  RES_8BIT (6, cpustate->b.L)
1115  RES_8BIT (6, cpustate->L)
10501116  break;
10511117case 0xB6:
1052  /*      RES 6,(HL) */
1118   /*      RES 6,(HL) */
1119   {
1120      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
10531121
1054  x = mem_ReadByte (cpustate, cpustate->w.HL);
1055  RES_8BIT (6, x)
1056  mem_WriteByte (cpustate, cpustate->w.HL, x);
1057  break;
1122      x = mem_ReadByte (cpustate, addr);
1123      RES_8BIT (6, x)
1124      mem_WriteByte (cpustate, addr, x);
1125   }
1126   break;
10581127case 0xB7:
10591128  /*      RES 6,A */
10601129
1061  RES_8BIT (6, cpustate->b.A)
1130  RES_8BIT (6, cpustate->A)
10621131  break;
10631132case 0xB8:
10641133  /*      RES 7,B */
10651134
1066  RES_8BIT (7, cpustate->b.B)
1135  RES_8BIT (7, cpustate->B)
10671136  break;
10681137case 0xB9:
10691138  /*      RES 7,C */
10701139
1071  RES_8BIT (7, cpustate->b.C)
1140  RES_8BIT (7, cpustate->C)
10721141  break;
10731142case 0xBA:
10741143  /*      RES 7,D */
10751144
1076  RES_8BIT (7, cpustate->b.D)
1145  RES_8BIT (7, cpustate->D)
10771146  break;
10781147case 0xBB:
10791148  /*      RES 7,E */
10801149
1081  RES_8BIT (7, cpustate->b.E)
1150  RES_8BIT (7, cpustate->E)
10821151  break;
10831152case 0xBC:
10841153  /*      RES 7,H */
10851154
1086  RES_8BIT (7, cpustate->b.H)
1155  RES_8BIT (7, cpustate->H)
10871156  break;
10881157case 0xBD:
10891158  /*      RES 7,L */
10901159
1091  RES_8BIT (7, cpustate->b.L)
1160  RES_8BIT (7, cpustate->L)
10921161  break;
10931162case 0xBE:
1094  /*      RES 7,(HL) */
1163   /*      RES 7,(HL) */
1164   {
1165      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
10951166
1096  x = mem_ReadByte (cpustate, cpustate->w.HL);
1097  RES_8BIT (7, x)
1098  mem_WriteByte (cpustate, cpustate->w.HL, x);
1099  break;
1167      x = mem_ReadByte (cpustate, addr);
1168      RES_8BIT (7, x)
1169      mem_WriteByte (cpustate, addr, x);
1170   }
1171   break;
11001172case 0xBF:
11011173  /*      RES 7,A */
11021174
1103  RES_8BIT (7, cpustate->b.A)
1175  RES_8BIT (7, cpustate->A)
11041176  break;
11051177case 0xC0:
11061178  /*      SET 0,B */
11071179
1108  SET_8BIT (0, cpustate->b.B)
1180  SET_8BIT (0, cpustate->B)
11091181  break;
11101182case 0xC1:
11111183  /*      SET 0,C */
11121184
1113  SET_8BIT (0, cpustate->b.C)
1185  SET_8BIT (0, cpustate->C)
11141186  break;
11151187case 0xC2:
11161188  /*      SET 0,D */
11171189
1118  SET_8BIT (0, cpustate->b.D)
1190  SET_8BIT (0, cpustate->D)
11191191  break;
11201192case 0xC3:
11211193  /*      SET 0,E */
11221194
1123  SET_8BIT (0, cpustate->b.E)
1195  SET_8BIT (0, cpustate->E)
11241196  break;
11251197case 0xC4:
11261198  /*      SET 0,H */
11271199
1128  SET_8BIT (0, cpustate->b.H)
1200  SET_8BIT (0, cpustate->H)
11291201  break;
11301202case 0xC5:
11311203  /*      SET 0,L */
11321204
1133  SET_8BIT (0, cpustate->b.L)
1205  SET_8BIT (0, cpustate->L)
11341206  break;
11351207case 0xC6:
1136  /*      SET 0,(HL) */
1208   /*      SET 0,(HL) */
1209   {
1210      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
11371211
1138  x = mem_ReadByte (cpustate, cpustate->w.HL);
1139  SET_8BIT (0, x)
1140  mem_WriteByte (cpustate, cpustate->w.HL, x);
1141  break;
1212      x = mem_ReadByte (cpustate, addr);
1213      SET_8BIT (0, x)
1214      mem_WriteByte (cpustate, addr, x);
1215   }
1216   break;
11421217case 0xC7:
11431218  /*      SET 0,A */
11441219
1145  SET_8BIT (0, cpustate->b.A)
1220  SET_8BIT (0, cpustate->A)
11461221  break;
11471222case 0xC8:
11481223  /*      SET 1,B */
11491224
1150  SET_8BIT (1, cpustate->b.B)
1225  SET_8BIT (1, cpustate->B)
11511226  break;
11521227case 0xC9:
11531228  /*      SET 1,C */
11541229
1155  SET_8BIT (1, cpustate->b.C)
1230  SET_8BIT (1, cpustate->C)
11561231  break;
11571232case 0xCA:
11581233  /*      SET 1,D */
11591234
1160  SET_8BIT (1, cpustate->b.D)
1235  SET_8BIT (1, cpustate->D)
11611236  break;
11621237case 0xCB:
11631238  /*      SET 1,E */
11641239
1165  SET_8BIT (1, cpustate->b.E)
1240  SET_8BIT (1, cpustate->E)
11661241  break;
11671242case 0xCC:
11681243  /*      SET 1,H */
11691244
1170  SET_8BIT (1, cpustate->b.H)
1245  SET_8BIT (1, cpustate->H)
11711246  break;
11721247case 0xCD:
11731248  /*      SET 1,L */
11741249
1175  SET_8BIT (1, cpustate->b.L)
1250  SET_8BIT (1, cpustate->L)
11761251  break;
11771252case 0xCE:
1178  /*      SET 1,(HL) */
1253   /*      SET 1,(HL) */
1254   {
1255      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
11791256
1180  x = mem_ReadByte (cpustate, cpustate->w.HL);
1181  SET_8BIT (1, x)
1182  mem_WriteByte (cpustate, cpustate->w.HL, x);
1183  break;
1257      x = mem_ReadByte (cpustate, addr);
1258      SET_8BIT (1, x)
1259      mem_WriteByte (cpustate, addr, x);
1260   }
1261   break;
11841262case 0xCF:
11851263  /*      SET 1,A */
11861264
1187  SET_8BIT (1, cpustate->b.A)
1265  SET_8BIT (1, cpustate->A)
11881266  break;
11891267case 0xD0:
11901268  /*      SET 2,B */
11911269
1192  SET_8BIT (2, cpustate->b.B)
1270  SET_8BIT (2, cpustate->B)
11931271  break;
11941272case 0xD1:
11951273  /*      SET 2,C */
11961274
1197  SET_8BIT (2, cpustate->b.C)
1275  SET_8BIT (2, cpustate->C)
11981276  break;
11991277case 0xD2:
12001278  /*      SET 2,D */
12011279
1202  SET_8BIT (2, cpustate->b.D)
1280  SET_8BIT (2, cpustate->D)
12031281  break;
12041282case 0xD3:
12051283  /*      SET 2,E */
12061284
1207  SET_8BIT (2, cpustate->b.E)
1285  SET_8BIT (2, cpustate->E)
12081286  break;
12091287case 0xD4:
12101288  /*      SET 2,H */
12111289
1212  SET_8BIT (2, cpustate->b.H)
1290  SET_8BIT (2, cpustate->H)
12131291  break;
12141292case 0xD5:
12151293  /*      SET 2,L */
12161294
1217  SET_8BIT (2, cpustate->b.L)
1295  SET_8BIT (2, cpustate->L)
12181296  break;
12191297case 0xD6:
1220  /*      SET 2,(HL) */
1298   /*      SET 2,(HL) */
1299   {
1300      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
12211301
1222  x = mem_ReadByte (cpustate, cpustate->w.HL);
1223  SET_8BIT (2, x)
1224  mem_WriteByte (cpustate, cpustate->w.HL, x);
1225  break;
1302      x = mem_ReadByte (cpustate, addr);
1303      SET_8BIT (2, x)
1304      mem_WriteByte (cpustate, addr, x);
1305   }
1306   break;
12261307case 0xD7:
12271308  /*      SET 2,A */
12281309
1229  SET_8BIT (2, cpustate->b.A)
1310  SET_8BIT (2, cpustate->A)
12301311  break;
12311312case 0xD8:
12321313  /*      SET 3,B */
12331314
1234  SET_8BIT (3, cpustate->b.B)
1315  SET_8BIT (3, cpustate->B)
12351316  break;
12361317case 0xD9:
12371318  /*      SET 3,C */
12381319
1239  SET_8BIT (3, cpustate->b.C)
1320  SET_8BIT (3, cpustate->C)
12401321  break;
12411322case 0xDA:
12421323  /*      SET 3,D */
12431324
1244  SET_8BIT (3, cpustate->b.D)
1325  SET_8BIT (3, cpustate->D)
12451326  break;
12461327case 0xDB:
12471328  /*      SET 3,E */
12481329
1249  SET_8BIT (3, cpustate->b.E)
1330  SET_8BIT (3, cpustate->E)
12501331  break;
12511332case 0xDC:
12521333  /*      SET 3,H */
12531334
1254  SET_8BIT (3, cpustate->b.H)
1335  SET_8BIT (3, cpustate->H)
12551336  break;
12561337case 0xDD:
12571338  /*      SET 3,L */
12581339
1259  SET_8BIT (3, cpustate->b.L)
1340  SET_8BIT (3, cpustate->L)
12601341  break;
12611342case 0xDE:
1262  /*      SET 3,(HL) */
1343   /*      SET 3,(HL) */
1344   {
1345      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
12631346
1264  x = mem_ReadByte (cpustate, cpustate->w.HL);
1265  SET_8BIT (3, x)
1266  mem_WriteByte (cpustate, cpustate->w.HL, x);
1267  break;
1347      x = mem_ReadByte (cpustate, addr);
1348      SET_8BIT (3, x)
1349      mem_WriteByte (cpustate, addr, x);
1350   }
1351   break;
12681352case 0xDF:
12691353  /*      SET 3,A */
12701354
1271  SET_8BIT (3, cpustate->b.A)
1355  SET_8BIT (3, cpustate->A)
12721356  break;
12731357case 0xE0:
12741358  /*      SET 4,B */
12751359
1276  SET_8BIT (4, cpustate->b.B)
1360  SET_8BIT (4, cpustate->B)
12771361  break;
12781362case 0xE1:
12791363  /*      SET 4,C */
12801364
1281  SET_8BIT (4, cpustate->b.C)
1365  SET_8BIT (4, cpustate->C)
12821366  break;
12831367case 0xE2:
12841368  /*      SET 4,D */
12851369
1286  SET_8BIT (4, cpustate->b.D)
1370  SET_8BIT (4, cpustate->D)
12871371  break;
12881372case 0xE3:
12891373  /*      SET 4,E */
12901374
1291  SET_8BIT (4, cpustate->b.E)
1375  SET_8BIT (4, cpustate->E)
12921376  break;
12931377case 0xE4:
12941378  /*      SET 4,H */
12951379
1296  SET_8BIT (4, cpustate->b.H)
1380  SET_8BIT (4, cpustate->H)
12971381  break;
12981382case 0xE5:
12991383  /*      SET 4,L */
13001384
1301  SET_8BIT (4, cpustate->b.L)
1385  SET_8BIT (4, cpustate->L)
13021386  break;
13031387case 0xE6:
1304  /*      SET 4,(HL) */
1388   /*      SET 4,(HL) */
1389   {
1390      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
13051391
1306  x = mem_ReadByte (cpustate, cpustate->w.HL);
1307  SET_8BIT (4, x)
1308  mem_WriteByte (cpustate, cpustate->w.HL, x);
1309  break;
1392      x = mem_ReadByte (cpustate, addr);
1393      SET_8BIT (4, x)
1394      mem_WriteByte (cpustate, addr, x);
1395   }
1396   break;
13101397case 0xE7:
13111398  /*      SET 4,A */
13121399
1313  SET_8BIT (4, cpustate->b.A)
1400  SET_8BIT (4, cpustate->A)
13141401  break;
13151402case 0xE8:
13161403  /*      SET 5,B */
13171404
1318  SET_8BIT (5, cpustate->b.B)
1405  SET_8BIT (5, cpustate->B)
13191406  break;
13201407case 0xE9:
13211408  /*      SET 5,C */
13221409
1323  SET_8BIT (5, cpustate->b.C)
1410  SET_8BIT (5, cpustate->C)
13241411  break;
13251412case 0xEA:
13261413  /*      SET 5,D */
13271414
1328  SET_8BIT (5, cpustate->b.D)
1415  SET_8BIT (5, cpustate->D)
13291416  break;
13301417case 0xEB:
13311418  /*      SET 5,E */
13321419
1333  SET_8BIT (5, cpustate->b.E)
1420  SET_8BIT (5, cpustate->E)
13341421  break;
13351422case 0xEC:
13361423  /*      SET 5,H */
13371424
1338  SET_8BIT (5, cpustate->b.H)
1425  SET_8BIT (5, cpustate->H)
13391426  break;
13401427case 0xED:
13411428  /*      SET 5,L */
13421429
1343  SET_8BIT (5, cpustate->b.L)
1430  SET_8BIT (5, cpustate->L)
13441431  break;
13451432case 0xEE:
1346  /*      SET 5,(HL) */
1433   /*      SET 5,(HL) */
1434   {
1435      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
13471436
1348  x = mem_ReadByte (cpustate, cpustate->w.HL);
1349  SET_8BIT (5, x)
1350  mem_WriteByte (cpustate, cpustate->w.HL, x);
1351  break;
1437      x = mem_ReadByte (cpustate, addr);
1438      SET_8BIT (5, x)
1439      mem_WriteByte (cpustate, addr, x);
1440   }
1441   break;
13521442case 0xEF:
13531443  /*      SET 5,A */
13541444
1355  SET_8BIT (5, cpustate->b.A)
1445  SET_8BIT (5, cpustate->A)
13561446  break;
13571447case 0xF0:
13581448  /*      SET 6,B */
13591449
1360  SET_8BIT (6, cpustate->b.B)
1450  SET_8BIT (6, cpustate->B)
13611451  break;
13621452case 0xF1:
13631453  /*      SET 6,C */
13641454
1365  SET_8BIT (6, cpustate->b.C)
1455  SET_8BIT (6, cpustate->C)
13661456  break;
13671457case 0xF2:
13681458  /*      SET 6,D */
13691459
1370  SET_8BIT (6, cpustate->b.D)
1460  SET_8BIT (6, cpustate->D)
13711461  break;
13721462case 0xF3:
13731463  /*      SET 6,E */
13741464
1375  SET_8BIT (6, cpustate->b.E)
1465  SET_8BIT (6, cpustate->E)
13761466  break;
13771467case 0xF4:
13781468  /*      SET 6,H */
13791469
1380  SET_8BIT (6, cpustate->b.H)
1470  SET_8BIT (6, cpustate->H)
13811471  break;
13821472case 0xF5:
13831473  /*      SET 6,L */
13841474
1385  SET_8BIT (6, cpustate->b.L)
1475  SET_8BIT (6, cpustate->L)
13861476  break;
13871477case 0xF6:
1388  /*      SET 6,(HL) */
1478   /*      SET 6,(HL) */
1479   {
1480      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
13891481
1390  x = mem_ReadByte (cpustate, cpustate->w.HL);
1391  SET_8BIT (6, x)
1392  mem_WriteByte (cpustate, cpustate->w.HL, x);
1393  break;
1482      x = mem_ReadByte (cpustate, addr);
1483      SET_8BIT (6, x)
1484      mem_WriteByte (cpustate, addr, x);
1485   }
1486   break;
13941487case 0xF7:
13951488  /*      SET 6,A */
13961489
1397  SET_8BIT (6, cpustate->b.A)
1490  SET_8BIT (6, cpustate->A)
13981491  break;
13991492case 0xF8:
14001493  /*      SET 7,B */
14011494
1402  SET_8BIT (7, cpustate->b.B)
1495  SET_8BIT (7, cpustate->B)
14031496  break;
14041497case 0xF9:
14051498  /*      SET 7,C */
14061499
1407  SET_8BIT (7, cpustate->b.C)
1500  SET_8BIT (7, cpustate->C)
14081501  break;
14091502case 0xFA:
14101503  /*      SET 7,D */
14111504
1412  SET_8BIT (7, cpustate->b.D)
1505  SET_8BIT (7, cpustate->D)
14131506  break;
14141507case 0xFB:
14151508  /*      SET 7,E */
14161509
1417  SET_8BIT (7, cpustate->b.E)
1510  SET_8BIT (7, cpustate->E)
14181511  break;
14191512case 0xFC:
14201513  /*      SET 7,H */
14211514
1422  SET_8BIT (7, cpustate->b.H)
1515  SET_8BIT (7, cpustate->H)
14231516  break;
14241517case 0xFD:
14251518  /*      SET 7,L */
14261519
1427  SET_8BIT (7, cpustate->b.L)
1520  SET_8BIT (7, cpustate->L)
14281521  break;
14291522case 0xFE:
1430  /*      SET 7,(HL) */
1523   /*      SET 7,(HL) */
1524   {
1525      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
14311526
1432  x = mem_ReadByte (cpustate, cpustate->w.HL);
1433  SET_8BIT (7, x)
1434  mem_WriteByte (cpustate, cpustate->w.HL, x);
1435  break;
1527      x = mem_ReadByte (cpustate, addr);
1528      SET_8BIT (7, x)
1529      mem_WriteByte (cpustate, addr, x);
1530   }
1531   break;
14361532case 0xFF:
14371533  /*      SET 7,A */
14381534
1439  SET_8BIT (7, cpustate->b.A)
1535  SET_8BIT (7, cpustate->A)
14401536  break;
src/emu/cpu/lr35902/opc_main.h
r14630r14631
33  register UINT8 r,f; \
44  x++; \
55  r=(x);  \
6  f=(UINT8)(cpustate->b.F&FLAG_C); \
6  f=(UINT8)(cpustate->F&FLAG_C); \
77  if( r==0 )       f|=FLAG_Z; \
88  if( (r&0xF)==0 ) f|=FLAG_H; \
9  cpustate->b.F=f; \
9  cpustate->F=f; \
1010}
1111
1212#define   DEC_8BIT(x) \
r14630r14631
1414  register UINT8 r,f; \
1515  x--; \
1616  r=(x);  \
17  f=(UINT8)((cpustate->b.F&FLAG_C)|FLAG_N); \
17  f=(UINT8)((cpustate->F&FLAG_C)|FLAG_N); \
1818  if( r==0 )       f|=FLAG_Z; \
1919  if( (r&0xF)==0xF ) f|=FLAG_H; \
20  cpustate->b.F=f; \
20  cpustate->F=f; \
2121}
2222
2323#define   ADD_HL_RR(x) \
2424{ \
2525  register UINT32 r1,r2; \
2626  register UINT8 f; \
27  r1=cpustate->w.HL+(x); \
28  r2=(cpustate->w.HL&0xFFF)+((x)&0xFFF); \
29  f=(UINT8)(cpustate->b.F&FLAG_Z); \
27  r1=((cpustate->H<<8)|cpustate->L)+(x); \
28  r2=(((cpustate->H<<8)|cpustate->L)&0xFFF)+((x)&0xFFF); \
29  f=(UINT8)(cpustate->F&FLAG_Z); \
3030  if( r1>0xFFFF ) f|=FLAG_C; \
3131  if( r2>0x0FFF ) f|=FLAG_H; \
32  cpustate->w.HL=(UINT16)r1; \
33  cpustate->b.F=f; \
32  cpustate->L = r1; \
33  cpustate->H = r1 >> 8; \
34  cpustate->F=f; \
3435}
3536
3637#define   ADD_A_X(x) \
3738{ \
3839  register UINT16 r1,r2; \
3940  register UINT8 f; \
40  r1=(UINT16)((cpustate->b.A&0xF)+((x)&0xF)); \
41  r2=(UINT16)(cpustate->b.A+(x)); \
42  cpustate->b.A=(UINT8)r2; \
41  r1=(UINT16)((cpustate->A&0xF)+((x)&0xF)); \
42  r2=(UINT16)(cpustate->A+(x)); \
43  cpustate->A=(UINT8)r2; \
4344  if( ((UINT8)r2)==0 ) f=FLAG_Z; \
4445    else f=0; \
4546  if( r2>0xFF ) f|=FLAG_C; \
4647  if( r1>0xF )  f|=FLAG_H; \
47  cpustate->b.F=f; \
48  cpustate->F=f; \
4849}
4950
5051#define   SUB_A_X(x) \
5152{ \
5253  register UINT16 r1,r2; \
5354  register UINT8 f; \
54  r1=(UINT16)((cpustate->b.A&0xF)-((x)&0xF)); \
55  r2=(UINT16)(cpustate->b.A-(x)); \
56  cpustate->b.A=(UINT8)r2; \
55  r1=(UINT16)((cpustate->A&0xF)-((x)&0xF)); \
56  r2=(UINT16)(cpustate->A-(x)); \
57  cpustate->A=(UINT8)r2; \
5758  if( ((UINT8)r2)==0 ) f=FLAG_N|FLAG_Z; \
5859    else f=FLAG_N; \
5960  if( r2>0xFF ) f|=FLAG_C; \
6061  if( r1>0xF )  f|=FLAG_H; \
61  cpustate->b.F=f; \
62  cpustate->F=f; \
6263}
6364
6465/*
r14630r14631
6667   { \
6768   register UINT16 r; \
6869   register UINT8 f; \
69   r=(UINT16)(cpustate->b.A-(x)); \
70   r=(UINT16)(cpustate->A-(x)); \
7071   if( ((UINT8)r)==0 ) \
7172   f=FLAG_N|FLAG_Z; \
7273   else \
7374   f=FLAG_N; \
7475   f|=(UINT8)((r>>8)&FLAG_C); \
75   if( (r^cpustate->b.A^(x))&0x10 ) \
76   if( (r^cpustate->A^(x))&0x10 ) \
7677   f|=FLAG_H; \
77   cpustate->b.F=f; \
78   cpustate->F=f; \
7879   }
7980 */
8081
r14630r14631
8283{ \
8384  register UINT16 r1,r2; \
8485  register UINT8 f; \
85  r1=(UINT16)((cpustate->b.A&0xF)-((x)&0xF)); \
86  r2=(UINT16)(cpustate->b.A-(x)); \
86  r1=(UINT16)((cpustate->A&0xF)-((x)&0xF)); \
87  r2=(UINT16)(cpustate->A-(x)); \
8788  if( ((UINT8)r2)==0 ) f=FLAG_N|FLAG_Z; \
8889    else f=FLAG_N; \
8990  if( r2>0xFF ) f|=FLAG_C; \
9091  if( r1>0xF )  f|=FLAG_H; \
91  cpustate->b.F=f; \
92  cpustate->F=f; \
9293}
9394
9495#define   SBC_A_X(x) \
9596{ \
9697  register UINT16 r1,r2; \
9798  register UINT8 f; \
98  r1=(UINT16)((cpustate->b.A&0xF)-((x)&0xF)-((cpustate->b.F&FLAG_C)?1:0)); \
99  r2=(UINT16)(cpustate->b.A-(x)-((cpustate->b.F&FLAG_C)?1:0)); \
100  cpustate->b.A=(UINT8)r2; \
99  r1=(UINT16)((cpustate->A&0xF)-((x)&0xF)-((cpustate->F&FLAG_C)?1:0)); \
100  r2=(UINT16)(cpustate->A-(x)-((cpustate->F&FLAG_C)?1:0)); \
101  cpustate->A=(UINT8)r2; \
101102  if( ((UINT8)r2)==0 ) f=FLAG_N|FLAG_Z; \
102103    else f=FLAG_N; \
103104  if( r2>0xFF ) f|=FLAG_C; \
104105  if( r1>0xF )  f|=FLAG_H; \
105  cpustate->b.F=f; \
106  cpustate->F=f; \
106107}
107108
108109#define   ADC_A_X(x) \
109110{ \
110111  register UINT16 r1,r2;  \
111112  register UINT8 f; \
112  r1=(UINT16)((cpustate->b.A&0xF)+((x)&0xF)+((cpustate->b.F&FLAG_C)?1:0));  \
113  r2=(UINT16)(cpustate->b.A+(x)+((cpustate->b.F&FLAG_C)?1:0)); \
114  if( (cpustate->b.A=(UINT8)r2)==0 ) f=FLAG_Z; \
113  r1=(UINT16)((cpustate->A&0xF)+((x)&0xF)+((cpustate->F&FLAG_C)?1:0));  \
114  r2=(UINT16)(cpustate->A+(x)+((cpustate->F&FLAG_C)?1:0)); \
115  if( (cpustate->A=(UINT8)r2)==0 ) f=FLAG_Z; \
115116    else f=0; \
116117  if( r2>0xFF )   f|=FLAG_C; \
117118  if( r1>0xF )   f|=FLAG_H; \
118  cpustate->b.F=f; \
119  cpustate->F=f; \
119120}
120121
121122#define   AND_A_X(x) \
122  if( (cpustate->b.A&=(x))==0 ) \
123    cpustate->b.F=FLAG_H|FLAG_Z; \
123  if( (cpustate->A&=(x))==0 ) \
124    cpustate->F=FLAG_H|FLAG_Z; \
124125  else \
125    cpustate->b.F=FLAG_H;
126    cpustate->F=FLAG_H;
126127
127128#define XOR_A_X(x) \
128  if( (cpustate->b.A^=(x))==0 ) \
129    cpustate->b.F=FLAG_Z; \
129  if( (cpustate->A^=(x))==0 ) \
130    cpustate->F=FLAG_Z; \
130131  else \
131    cpustate->b.F=0;
132    cpustate->F=0;
132133
133134#define   OR_A_X(x) \
134  if( (cpustate->b.A|=(x))==0 ) \
135    cpustate->b.F=FLAG_Z; \
135  if( (cpustate->A|=(x))==0 ) \
136    cpustate->F=FLAG_Z; \
136137  else \
137    cpustate->b.F=0;
138    cpustate->F=0;
138139
140#define POP(x,y) \
141   y = mem_ReadByte( cpustate, cpustate->SP++ ); \
142   x = mem_ReadByte( cpustate, cpustate->SP++ );
139143
144#define PUSH(x,y) \
145   cpustate->SP--; \
146   mem_WriteByte( cpustate, cpustate->SP, x ); \
147   cpustate->SP--; \
148   mem_WriteByte( cpustate, cpustate->SP, y );
149
140150case 0x00: /*      NOP */
141151  break;
142152case 0x01: /*      LD BC,n16 */
143  cpustate->w.BC = mem_ReadWord (cpustate, cpustate->w.PC);
144  cpustate->w.PC += 2;
145  break;
153   cpustate->C = mem_ReadOp (cpustate);
154   cpustate->B = mem_ReadOp (cpustate);
155   break;
146156case 0x02: /*      LD (BC),A */
147  mem_WriteByte (cpustate, cpustate->w.BC, cpustate->b.A);
157  mem_WriteByte (cpustate, ( cpustate->B << 8 ) | cpustate->C, cpustate->A);
148158  break;
149159case 0x03: /*      INC BC */
150160#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
151  if (cpustate->b.B == 0xFE)
161  if (cpustate->B == 0xFE)
152162  {
153163    trash_sprites (state);
154164  }
155165#endif
156   cpustate->w.BC += 1;
166   cpustate->C++;
167   if ( cpustate->C == 0 )
168   {
169      cpustate->B++;
170   }
157171   CYCLES_PASSED( 4 );
158172   break;
159173case 0x04: /*      INC B */
160
161  INC_8BIT (cpustate->b.B)
162  break;
174   INC_8BIT (cpustate->B)
175   break;
163176case 0x05: /*      DEC B */
164177
165  DEC_8BIT (cpustate->b.B)
178  DEC_8BIT (cpustate->B)
166179  break;
167180case 0x06: /*      LD B,n8 */
168181
169  cpustate->b.B = mem_ReadByte (cpustate, cpustate->w.PC++);
182  cpustate->B = mem_ReadByte (cpustate, cpustate->PC++);
170183  break;
171184case 0x07: /*      RLCA */
172185
173  cpustate->b.A = (UINT8) ((cpustate->b.A << 1) | (cpustate->b.A >> 7));
174  if (cpustate->b.A & 1)
186  cpustate->A = (UINT8) ((cpustate->A << 1) | (cpustate->A >> 7));
187  if (cpustate->A & 1)
175188  {
176    cpustate->b.F = FLAG_C;
189    cpustate->F = FLAG_C;
177190  }
178191  else
179192  {
180    cpustate->b.F = 0;
193    cpustate->F = 0;
181194  }
182195  break;
183196case 0x08: /*      LD (n16),SP */
184197
185  mem_WriteWord (cpustate, mem_ReadWord (cpustate, cpustate->w.PC), cpustate->w.SP);
186  cpustate->w.PC += 2;
198  mem_WriteWord (cpustate, mem_ReadWord (cpustate, cpustate->PC), cpustate->SP);
199  cpustate->PC += 2;
187200  break;
188201case 0x09: /*      ADD HL,BC */
189   ADD_HL_RR (cpustate->w.BC)
202   ADD_HL_RR ((cpustate->B<<8)|cpustate->C)
190203   CYCLES_PASSED( 4 );
191204   break;
192205case 0x0A: /*      LD A,(BC) */
193206
194  cpustate->b.A = mem_ReadByte (cpustate, cpustate->w.BC);
207  cpustate->A = mem_ReadByte (cpustate, (cpustate->B<<8)|cpustate->C);
195208  break;
196209case 0x0B: /*      DEC BC */
197210
198211#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
199  if (cpustate->b.B == 0xFE)
212  if (cpustate->B == 0xFE)
200213  {
201214    trash_sprites (state);
202215  }
203216#endif
204   cpustate->w.BC -= 1;
217   cpustate->C--;
218   if ( cpustate->C == 0xFF )
219   {
220      cpustate->B--;
221   }
205222   CYCLES_PASSED( 4 );
206223   break;
207224case 0x0C: /*      INC C */
208225
209  INC_8BIT (cpustate->b.C)
226  INC_8BIT (cpustate->C)
210227  break;
211228case 0x0D: /*      DEC C */
212229
213  DEC_8BIT (cpustate->b.C)
230  DEC_8BIT (cpustate->C)
214231  break;
215232case 0x0E: /*      LD C,n8 */
216233
217  cpustate->b.C = mem_ReadByte (cpustate, cpustate->w.PC++);
234  cpustate->C = mem_ReadByte (cpustate, cpustate->PC++);
218235  break;
219236case 0x0F: /*      RRCA */
220237
221  cpustate->b.A = (UINT8) ((cpustate->b.A >> 1) | (cpustate->b.A << 7));
222  cpustate->b.F = 0;
223  if (cpustate->b.A & 0x80)
238  cpustate->A = (UINT8) ((cpustate->A >> 1) | (cpustate->A << 7));
239  cpustate->F = 0;
240  if (cpustate->A & 0x80)
224241  {
225    cpustate->b.F |= FLAG_C;
242    cpustate->F |= FLAG_C;
226243  }
227244  break;
228245case 0x10: /*      STOP */
229  if ( cpustate->w.gb_speed_change_pending ) {
230    cpustate->w.gb_speed = ( cpustate->w.gb_speed == 1 ) ? 2 : 1;
246  if ( cpustate->gb_speed_change_pending ) {
247    cpustate->gb_speed = ( cpustate->gb_speed == 1 ) ? 2 : 1;
231248  }
232  cpustate->w.gb_speed_change_pending = 0;
249  cpustate->gb_speed_change_pending = 0;
233250  break;
234251case 0x11: /*      LD DE,n16 */
235
236  cpustate->w.DE = mem_ReadWord (cpustate, cpustate->w.PC);
237  cpustate->w.PC += 2;
238  break;
252   cpustate->E = mem_ReadOp (cpustate);
253   cpustate->D = mem_ReadOp (cpustate);
254   break;
239255case 0x12: /*      LD (DE),A */
240  mem_WriteByte (cpustate, cpustate->w.DE, cpustate->b.A);
256  mem_WriteByte (cpustate, ( cpustate->D << 8 ) | cpustate->E, cpustate->A);
241257  break;
242258case 0x13: /*      INC DE */
243259
244260#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
245  if (cpustate->b.D == 0xFE)
261  if (cpustate->D == 0xFE)
246262  {
247263    trash_sprites (state);
248264  }
249265#endif
250
251   cpustate->w.DE += 1;
266   cpustate->E++;
267   if ( cpustate->E == 0 )
268   {
269      cpustate->D++;
270   }
252271   CYCLES_PASSED( 4 );
253272   break;
254273case 0x14: /*      INC D */
255274
256  INC_8BIT (cpustate->b.D)
275  INC_8BIT (cpustate->D)
257276  break;
258277case 0x15: /*      DEC D */
259278
260  DEC_8BIT (cpustate->b.D)
279  DEC_8BIT (cpustate->D)
261280  break;
262281case 0x16: /*      LD D,n8 */
263282
264  cpustate->b.D = mem_ReadByte (cpustate, cpustate->w.PC++);
283  cpustate->D = mem_ReadByte (cpustate, cpustate->PC++);
265284  break;
266285case 0x17: /*      RLA */
267286
268  x = (cpustate->b.A & 0x80) ? FLAG_C : 0;
287  x = (cpustate->A & 0x80) ? FLAG_C : 0;
269288
270  cpustate->b.A = (UINT8) ((cpustate->b.A << 1) | ((cpustate->b.F & FLAG_C) ? 1 : 0));
271  cpustate->b.F = x;
289  cpustate->A = (UINT8) ((cpustate->A << 1) | ((cpustate->F & FLAG_C) ? 1 : 0));
290  cpustate->F = x;
272291  break;
273292case 0x18: /*      JR      n8 */
274293  {
275294   INT8 offset;
276295
277    offset = mem_ReadByte (cpustate, cpustate->w.PC++);
278    cpustate->w.PC += offset;
296    offset = mem_ReadByte (cpustate, cpustate->PC++);
297    cpustate->PC += offset;
279298   CYCLES_PASSED( 4 );
280299  }
281300  break;
282301case 0x19: /*      ADD HL,DE */
283   ADD_HL_RR (cpustate->w.DE)
302   ADD_HL_RR (( cpustate->D << 8 ) | cpustate->E)
284303   CYCLES_PASSED( 4 );
285304   break;
286305case 0x1A: /*      LD A,(DE) */
287306
288  cpustate->b.A = mem_ReadByte (cpustate, cpustate->w.DE);
307  cpustate->A = mem_ReadByte (cpustate, ( cpustate->D << 8 ) | cpustate->E);
289308  break;
290309case 0x1B: /*      DEC DE */
291310
292311#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
293  if (cpustate->b.D == 0xFE)
312  if (cpustate->D == 0xFE)
294313  {
295314    trash_sprites (state);
296315  }
297316#endif
298   cpustate->w.DE -= 1;
317   cpustate->E--;
318   if ( cpustate->E == 0xFF )
319   {
320      cpustate->D--;
321   }
299322   CYCLES_PASSED( 4 );
300323   break;
301324case 0x1C: /*      INC E */
302325
303  INC_8BIT (cpustate->b.E)
326  INC_8BIT (cpustate->E)
304327  break;
305328case 0x1D: /*      DEC E */
306329
307  DEC_8BIT (cpustate->b.E)
330  DEC_8BIT (cpustate->E)
308331  break;
309332case 0x1E: /*      LD E,n8 */
310333
311  cpustate->b.E = mem_ReadByte (cpustate, cpustate->w.PC++);
334  cpustate->E = mem_ReadByte (cpustate, cpustate->PC++);
312335  break;
313336case 0x1F: /*      RRA */
314337
315  x = (cpustate->b.A & 1) ? FLAG_C : 0;
338  x = (cpustate->A & 1) ? FLAG_C : 0;
316339
317  cpustate->b.A = (UINT8) ((cpustate->b.A >> 1) | ((cpustate->b.F & FLAG_C) ? 0x80 : 0));
318  cpustate->b.F = x;
340  cpustate->A = (UINT8) ((cpustate->A >> 1) | ((cpustate->F & FLAG_C) ? 0x80 : 0));
341  cpustate->F = x;
319342  break;
320343case 0x20: /*      JR NZ,n8 */
321344   {
322      INT8 offset = mem_ReadByte (cpustate, cpustate->w.PC++);
323      if (! (cpustate->b.F & FLAG_Z) )
345      INT8 offset = mem_ReadByte (cpustate, cpustate->PC++);
346      if (! (cpustate->F & FLAG_Z) )
324347      {
325         cpustate->w.PC += offset;
348         cpustate->PC += offset;
326349         CYCLES_PASSED( 4 );
327350      }
328351   }
329352   break;
330353case 0x21: /*      LD HL,n16 */
331
332  cpustate->w.HL = mem_ReadWord (cpustate, cpustate->w.PC);
333  cpustate->w.PC += 2;
334  break;
354   cpustate->L = mem_ReadOp (cpustate);
355   cpustate->H = mem_ReadOp (cpustate);
356   break;
335357case 0x22: /*      LD (HL+),A */
336358
337359#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
338  if (cpustate->b.H == 0xFE)
360  if (cpustate->H == 0xFE)
339361  {
340362    trash_sprites (state);
341363  }
342364#endif
343
344  mem_WriteByte (cpustate, cpustate->w.HL, cpustate->b.A);
345  cpustate->w.HL += 1;
346  break;
365   mem_WriteByte (cpustate, (cpustate->H << 8 ) | cpustate->L, cpustate->A);
366   cpustate->L++;
367   if ( cpustate->L == 0 )
368   {
369      cpustate->H++;
370   }
371   break;
347372case 0x23: /*      INC HL */
348373
349374#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
350  if (cpustate->b.H == 0xFE)
375  if (cpustate->H == 0xFE)
351376  {
352377    trash_sprites (state);
353378  }
354379#endif
355
356   cpustate->w.HL += 1;
380   cpustate->L++;
381   if ( cpustate->L == 0 )
382   {
383      cpustate->H++;
384   }
357385   CYCLES_PASSED( 4 );
358386   break;
359387case 0x24: /*      INC H */
360388
361  INC_8BIT (cpustate->b.H);
389  INC_8BIT (cpustate->H);
362390  break;
363391case 0x25: /*      DEC H */
364392
365  DEC_8BIT (cpustate->b.H);
393  DEC_8BIT (cpustate->H);
366394  break;
367395case 0x26: /*      LD H,n8 */
368396
369  cpustate->b.H = mem_ReadByte (cpustate, cpustate->w.PC++);
397  cpustate->H = mem_ReadByte (cpustate, cpustate->PC++);
370398  break;
371399case 0x27: /*      DAA */
372400   {
373      int tmp = cpustate->b.A;
401      int tmp = cpustate->A;
374402
375      if ( ! ( cpustate->b.F & FLAG_N ) ) {
376         if ( ( cpustate->b.F & FLAG_H ) || ( tmp & 0x0F ) > 9 )
403      if ( ! ( cpustate->F & FLAG_N ) ) {
404         if ( ( cpustate->F & FLAG_H ) || ( tmp & 0x0F ) > 9 )
377405            tmp += 6;
378         if ( ( cpustate->b.F & FLAG_C ) || tmp > 0x9F )
406         if ( ( cpustate->F & FLAG_C ) || tmp > 0x9F )
379407            tmp += 0x60;
380408      } else {
381         if ( cpustate->b.F & FLAG_H ) {
409         if ( cpustate->F & FLAG_H ) {
382410            tmp -= 6;
383            if ( ! ( cpustate->b.F & FLAG_C ) )
411            if ( ! ( cpustate->F & FLAG_C ) )
384412               tmp &= 0xFF;
385413         }
386         if ( cpustate->b.F & FLAG_C )
414         if ( cpustate->F & FLAG_C )
387415               tmp -= 0x60;
388416      }
389      cpustate->b.F &= ~ ( FLAG_H | FLAG_Z );
417      cpustate->F &= ~ ( FLAG_H | FLAG_Z );
390418      if ( tmp & 0x100 )
391         cpustate->b.F |= FLAG_C;
392      cpustate->b.A = tmp & 0xFF;
393      if ( ! cpustate->b.A )
394         cpustate->b.F |= FLAG_Z;
419         cpustate->F |= FLAG_C;
420      cpustate->A = tmp & 0xFF;
421      if ( ! cpustate->A )
422         cpustate->F |= FLAG_Z;
395423   }
396424  break;
397425case 0x28: /*      JR Z,n8 */
398426   {
399      INT8 offset = mem_ReadByte (cpustate, cpustate->w.PC++);;
427      INT8 offset = mem_ReadByte (cpustate, cpustate->PC++);;
400428
401      if (cpustate->b.F & FLAG_Z)
429      if (cpustate->F & FLAG_Z)
402430      {
403         cpustate->w.PC += offset;
431         cpustate->PC += offset;
404432         CYCLES_PASSED( 4 );
405433      }
406434   }
407435   break;
408436case 0x29: /*      ADD HL,HL */
409   ADD_HL_RR (cpustate->w.HL)
437   ADD_HL_RR ((cpustate->H << 8 ) | cpustate->L)
410438   CYCLES_PASSED( 4 );
411439   break;
412440case 0x2A: /*      LD A,(HL+) */
413441#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
414  if (cpustate->b.H == 0xFE)
442  if (cpustate->H == 0xFE)
415443  {
416444    trash_sprites (state);
417445  }
418446#endif
419
420  cpustate->b.A = mem_ReadByte (cpustate, cpustate->w.HL);
421  cpustate->w.HL += 1;
422  break;
447   cpustate->A = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
448   cpustate->L++;
449   if ( cpustate->L == 0 )
450   {
451      cpustate->H++;
452   }
453   break;
423454case 0x2B: /*      DEC HL */
424455
425456#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
426  if (cpustate->b.H == 0xFE)
457  if (cpustate->H == 0xFE)
427458  {
428459    trash_sprites (state);
429460  }
430461#endif
431   cpustate->w.HL -= 1;
462   cpustate->L--;
463   if ( cpustate->L == 0xFF )
464   {
465      cpustate->H--;
466   }
432467   CYCLES_PASSED( 4 );
433468   break;
434469case 0x2C: /*      INC L */
435470
436  INC_8BIT (cpustate->b.L);
471  INC_8BIT (cpustate->L);
437472  break;
438473case 0x2D: /*      DEC L */
439474
440  DEC_8BIT (cpustate->b.L);
475  DEC_8BIT (cpustate->L);
441476  break;
442477case 0x2E: /*      LD L,n8 */
443478
444  cpustate->b.L = mem_ReadByte (cpustate, cpustate->w.PC++);
479  cpustate->L = mem_ReadByte (cpustate, cpustate->PC++);
445480  break;
446481case 0x2F: /*      CPL */
447482
448  cpustate->b.A = ~cpustate->b.A;
449  cpustate->b.F |= FLAG_N | FLAG_H;
483  cpustate->A = ~cpustate->A;
484  cpustate->F |= FLAG_N | FLAG_H;
450485  break;
451486case 0x30: /*      JR NC,n8 */
452487   {
453      INT8 offset = mem_ReadByte (cpustate, cpustate->w.PC++);
488      INT8 offset = mem_ReadByte (cpustate, cpustate->PC++);
454489
455      if ( ! (cpustate->b.F & FLAG_C) )
490      if ( ! (cpustate->F & FLAG_C) )
456491      {
457         cpustate->w.PC += offset;
492         cpustate->PC += offset;
458493         CYCLES_PASSED( 4 );
459494      }
460495   }
461496   break;
462497case 0x31: /*      LD SP,n16 */
463498
464  cpustate->w.SP = mem_ReadWord (cpustate, cpustate->w.PC);
465  cpustate->w.PC += 2;
499  cpustate->SP = mem_ReadWord (cpustate, cpustate->PC);
500  cpustate->PC += 2;
466501  break;
467502case 0x32: /*      LD (HL-),A */
468503
469504#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
470  if (cpustate->b.H == 0xFE)
505  if (cpustate->H == 0xFE)
471506  {
472507    trash_sprites (state);
473508  }
474509#endif
475
476  mem_WriteByte (cpustate, cpustate->w.HL, cpustate->b.A);
477  cpustate->w.HL -= 1;
478  break;
510   mem_WriteByte (cpustate, ( cpustate->H << 8 ) | cpustate->L, cpustate->A);
511   cpustate->L--;
512   if ( cpustate->L == 0xFF )
513   {
514      cpustate->H--;
515   }
516   break;
479517case 0x33: /*      INC SP */
480   cpustate->w.SP += 1;
518   cpustate->SP += 1;
481519   CYCLES_PASSED( 4 );
482520   break;
483521case 0x34: /*      INC (HL) */
522   {
523      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
524      register UINT8 r, f;
484525
485  {
486   register UINT8 r, f;
526      f = (UINT8) (cpustate->F & FLAG_C);
527      r = mem_ReadByte (cpustate, addr);
528      r += 1;
529      mem_WriteByte (cpustate, addr, r);
487530
488   f = (UINT8) (cpustate->b.F & FLAG_C);
489   r = mem_ReadByte (cpustate, cpustate->w.HL);
490   r += 1;
491    mem_WriteByte (cpustate, cpustate->w.HL, r);
531      if (r == 0)
532         f |= FLAG_Z;
492533
493    if (r == 0)
494      f |= FLAG_Z;
534      if ((r & 0xF) == 0)
535         f |= FLAG_H;
495536
496    if ((r & 0xF) == 0)
497      f |= FLAG_H;
498
499    cpustate->b.F = f;
500  }
501  break;
537      cpustate->F = f;
538   }
539   break;
502540case 0x35: /*      DEC (HL) */
541   {
542      UINT16 addr = ( cpustate->H << 8 ) | cpustate->L;
543      register UINT8 r, f;
503544
504  {
505   register UINT8 r, f;
545      f = (UINT8) ((cpustate->F & FLAG_C) | FLAG_N);
546      r = mem_ReadByte (cpustate, addr);
547      r -= 1;
548      mem_WriteByte (cpustate, addr, r);
506549
507   f = (UINT8) ((cpustate->b.F & FLAG_C) | FLAG_N);
508   r = mem_ReadByte (cpustate, cpustate->w.HL);
509   r -= 1;
510    mem_WriteByte (cpustate, cpustate->w.HL, r);
550      if (r == 0)
551         f |= FLAG_Z;
511552
512    if (r == 0)
513      f |= FLAG_Z;
553      if ((r & 0xF) == 0xF)
554         f |= FLAG_H;
514555
515    if ((r & 0xF) == 0xF)
516      f |= FLAG_H;
517
518    cpustate->b.F = f;
519  }
520  break;
556      cpustate->F = f;
557   }
558   break;
521559case 0x36: /*      LD (HL),n8 */
522  /* FIXED / broken ? */
523  {
524   UINT8 v = mem_ReadByte (cpustate, cpustate->w.PC++);
525   mem_WriteByte (cpustate, cpustate->w.HL, v);
526  }
527  break;
560   {
561      UINT8 v = mem_ReadByte (cpustate, cpustate->PC++);
562      mem_WriteByte (cpustate, ( cpustate->H << 8 ) | cpustate->L, v);
563   }
564   break;
528565case 0x37: /*      SCF */
529566
530  cpustate->b.F = (UINT8) ((cpustate->b.F & FLAG_Z) | FLAG_C);
567  cpustate->F = (UINT8) ((cpustate->F & FLAG_Z) | FLAG_C);
531568  break;
532569case 0x38: /*      JR C,n8 */
533570   {
534      INT8 offset = mem_ReadByte (cpustate, cpustate->w.PC++);
571      INT8 offset = mem_ReadByte (cpustate, cpustate->PC++);
535572
536      if (cpustate->b.F & FLAG_C)
573      if (cpustate->F & FLAG_C)
537574      {
538         cpustate->w.PC += offset;
575         cpustate->PC += offset;
539576         CYCLES_PASSED( 4 );
540577      }
541578   }
542579   break;
543580case 0x39: /*      ADD HL,SP */
544   ADD_HL_RR (cpustate->w.SP)
581   ADD_HL_RR (cpustate->SP)
545582   CYCLES_PASSED( 4 );
546583   break;
547584case 0x3A: /*      LD A,(HL-) */
548585#if 0            /* FIXME ?? do we want to support this? (bug emulation) */
549  if (cpustate->b.H == 0xFE)
586  if (cpustate->H == 0xFE)
550587  {
551588    trash_sprites (state);
552589  }
553590#endif
554
555  cpustate->b.A = mem_ReadByte (cpustate, cpustate->w.HL);
556  cpustate->w.HL -= 1;
557  break;
591   cpustate->A = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
592   cpustate->L--;
593   if ( cpustate->L == 0xFF )
594   {
595      cpustate->H--;
596   }
597   break;
558598case 0x3B: /*      DEC SP */
559   cpustate->w.SP -= 1;
599   cpustate->SP -= 1;
560600   CYCLES_PASSED( 4 );
561601   break;
562602case 0x3C: /*      INC     A */
563603
564  INC_8BIT (cpustate->b.A);
604  INC_8BIT (cpustate->A);
565605  break;
566606case 0x3D: /*      DEC     A */
567607
568  DEC_8BIT (cpustate->b.A);
608  DEC_8BIT (cpustate->A);
569609  break;
570610case 0x3E: /*      LD A,n8 */
571611
572  cpustate->b.A = mem_ReadByte (cpustate, cpustate->w.PC++);
612  cpustate->A = mem_ReadByte (cpustate, cpustate->PC++);
573613  break;
574614case 0x3F: /*      CCF */
575615
576  cpustate->b.F = (UINT8) ((cpustate->b.F & FLAG_Z) | ((cpustate->b.F & FLAG_C) ? 0 : FLAG_C));
616  cpustate->F = (UINT8) ((cpustate->F & FLAG_Z) | ((cpustate->F & FLAG_C) ? 0 : FLAG_C));
577617  break;
578618case 0x40: /*      LD B,B */
579619  break;
580620case 0x41: /*      LD B,C */
581621
582  cpustate->b.B = cpustate->b.C;
622  cpustate->B = cpustate->C;
583623  break;
584624case 0x42: /*      LD B,D */
585625
586  cpustate->b.B = cpustate->b.D;
626  cpustate->B = cpustate->D;
587627  break;
588628case 0x43: /*      LD B,E */
589629
590  cpustate->b.B = cpustate->b.E;
630  cpustate->B = cpustate->E;
591631  break;
592632case 0x44: /*      LD B,H */
593633
594  cpustate->b.B = cpustate->b.H;
634  cpustate->B = cpustate->H;
595635  break;
596636case 0x45: /*      LD B,L */
597637
598  cpustate->b.B = cpustate->b.L;
638  cpustate->B = cpustate->L;
599639  break;
600640case 0x46: /*      LD B,(HL) */
601641
602  cpustate->b.B = mem_ReadByte (cpustate, cpustate->w.HL);
642  cpustate->B = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
603643  break;
604644case 0x47: /*      LD B,A */
605645
606  cpustate->b.B = cpustate->b.A;
646  cpustate->B = cpustate->A;
607647  break;
608648case 0x48: /*      LD C,B */
609649
610  cpustate->b.C = cpustate->b.B;
650  cpustate->C = cpustate->B;
611651  break;
612652case 0x49: /*      LD C,C */
613653  break;
614654case 0x4A: /*      LD C,D */
615655
616  cpustate->b.C = cpustate->b.D;
656  cpustate->C = cpustate->D;
617657  break;
618658case 0x4B: /*      LD C,E */
619659
620  cpustate->b.C = cpustate->b.E;
660  cpustate->C = cpustate->E;
621661  break;
622662case 0x4C: /*      LD C,H */
623663
624  cpustate->b.C = cpustate->b.H;
664  cpustate->C = cpustate->H;
625665  break;
626666case 0x4D: /*      LD C,L */
627667
628  cpustate->b.C = cpustate->b.L;
668  cpustate->C = cpustate->L;
629669  break;
630670case 0x4E: /*      LD C,(HL) */
631671
632  cpustate->b.C = mem_ReadByte (cpustate, cpustate->w.HL);
672  cpustate->C = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
633673  break;
634674case 0x4F: /*      LD C,A */
635675
636  cpustate->b.C = cpustate->b.A;
676  cpustate->C = cpustate->A;
637677  break;
638678case 0x50: /*      LD D,B */
639679
640  cpustate->b.D = cpustate->b.B;
680  cpustate->D = cpustate->B;
641681  break;
642682case 0x51: /*      LD D,C */
643683
644  cpustate->b.D = cpustate->b.C;
684  cpustate->D = cpustate->C;
645685  break;
646686case 0x52: /*      LD D,D */
647687  break;
648688case 0x53: /*      LD D,E */
649689
650  cpustate->b.D = cpustate->b.E;
690  cpustate->D = cpustate->E;
651691  break;
652692case 0x54: /*      LD D,H */
653693
654  cpustate->b.D = cpustate->b.H;
694  cpustate->D = cpustate->H;
655695  break;
656696case 0x55: /*      LD D,L */
657697
658  cpustate->b.D = cpustate->b.L;
698  cpustate->D = cpustate->L;
659699  break;
660700case 0x56: /*      LD D,(HL) */
661701
662  cpustate->b.D = mem_ReadByte (cpustate, cpustate->w.HL);
702  cpustate->D = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
663703  break;
664704case 0x57: /*      LD D,A */
665705
666  cpustate->b.D = cpustate->b.A;
706  cpustate->D = cpustate->A;
667707  break;
668708case 0x58: /*      LD E,B */
669709
670  cpustate->b.E = cpustate->b.B;
710  cpustate->E = cpustate->B;
671711  break;
672712case 0x59: /*      LD E,C */
673713
674  cpustate->b.E = cpustate->b.C;
714  cpustate->E = cpustate->C;
675715  break;
676716case 0x5A: /*      LD E,D */
677717
678  cpustate->b.E = cpustate->b.D;
718  cpustate->E = cpustate->D;
679719  break;
680720case 0x5B: /*      LD E,E */
681721  break;
682722case 0x5C: /*      LD E,H */
683723
684  cpustate->b.E = cpustate->b.H;
724  cpustate->E = cpustate->H;
685725  break;
686726case 0x5D: /*      LD E,L */
687727
688  cpustate->b.E = cpustate->b.L;
728  cpustate->E = cpustate->L;
689729  break;
690730case 0x5E: /*      LD E,(HL) */
691731
692  cpustate->b.E = mem_ReadByte (cpustate, cpustate->w.HL);
732  cpustate->E = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
693733  break;
694734case 0x5F: /*      LD E,A */
695735
696  cpustate->b.E = cpustate->b.A;
736  cpustate->E = cpustate->A;
697737  break;
698738case 0x60: /*      LD H,B */
699739
700  cpustate->b.H = cpustate->b.B;
740  cpustate->H = cpustate->B;
701741  break;
702742case 0x61: /*      LD H,C */
703743
704  cpustate->b.H = cpustate->b.C;
744  cpustate->H = cpustate->C;
705745  break;
706746case 0x62: /*      LD H,D */
707747
708  cpustate->b.H = cpustate->b.D;
748  cpustate->H = cpustate->D;
709749  break;
710750case 0x63: /*      LD H,E */
711751
712  cpustate->b.H = cpustate->b.E;
752  cpustate->H = cpustate->E;
713753  break;
714754case 0x64: /*      LD H,H */
715755  break;
716756case 0x65: /*      LD H,L */
717757
718  cpustate->b.H = cpustate->b.L;
758  cpustate->H = cpustate->L;
719759  break;
720760case 0x66: /*      LD H,(HL) */
721761
722  cpustate->b.H = mem_ReadByte (cpustate, cpustate->w.HL);
762  cpustate->H = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
723763  break;
724764case 0x67: /*      LD H,A */
725765
726  cpustate->b.H = cpustate->b.A;
766  cpustate->H = cpustate->A;
727767  break;
728768case 0x68: /*      LD L,B */
729769
730  cpustate->b.L = cpustate->b.B;
770  cpustate->L = cpustate->B;
731771  break;
732772case 0x69: /*      LD L,C */
733773
734  cpustate->b.L = cpustate->b.C;
774  cpustate->L = cpustate->C;
735775  break;
736776case 0x6A: /*      LD L,D */
737  cpustate->b.L = cpustate->b.D;
777  cpustate->L = cpustate->D;
738778  break;
739779case 0x6B: /*      LD L,E */
740780
741  cpustate->b.L = cpustate->b.E;
781  cpustate->L = cpustate->E;
742782  break;
743783case 0x6C: /*      LD L,H */
744784
745  cpustate->b.L = cpustate->b.H;
785  cpustate->L = cpustate->H;
746786  break;
747787case 0x6D: /*      LD L,L */
748788  break;
749789case 0x6E: /*      LD L,(HL) */
750790
751  cpustate->b.L = mem_ReadByte (cpustate, cpustate->w.HL);
791  cpustate->L = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
752792  break;
753793case 0x6F: /*      LD L,A */
754794
755  cpustate->b.L = cpustate->b.A;
795  cpustate->L = cpustate->A;
756796  break;
757797case 0x70: /*      LD (HL),B */
758798
759  mem_WriteByte (cpustate, cpustate->w.HL, cpustate->b.B);
799  mem_WriteByte (cpustate, ( cpustate->H << 8 ) | cpustate->L, cpustate->B);
760800  break;
761801case 0x71: /*      LD (HL),C */
762802
763  mem_WriteByte (cpustate, cpustate->w.HL, cpustate->b.C);
803  mem_WriteByte (cpustate, ( cpustate->H << 8 ) | cpustate->L, cpustate->C);
764804  break;
765805case 0x72: /*      LD (HL),D */
766806
767  mem_WriteByte (cpustate, cpustate->w.HL, cpustate->b.D);
807  mem_WriteByte (cpustate, ( cpustate->H << 8 ) | cpustate->L, cpustate->D);
768808  break;
769809case 0x73: /*      LD (HL),E */
770810
771  mem_WriteByte (cpustate, cpustate->w.HL, cpustate->b.E);
811  mem_WriteByte (cpustate, ( cpustate->H << 8 ) | cpustate->L, cpustate->E);
772812  break;
773813case 0x74: /*      LD (HL),H */
774814
775  mem_WriteByte (cpustate, cpustate->w.HL, cpustate->b.H);
815  mem_WriteByte (cpustate, ( cpustate->H << 8 ) | cpustate->L, cpustate->H);
776816  break;
777817case 0x75: /*      LD (HL),L */
778818
779  mem_WriteByte (cpustate, cpustate->w.HL, cpustate->b.L);
819  mem_WriteByte (cpustate, ( cpustate->H << 8 ) | cpustate->L, cpustate->L);
780820  break;
781821case 0x76: /*      HALT */
782   cpustate->w.enable |= HALTED;
783   cpustate->w.PC--;
822   cpustate->enable |= HALTED;
823   cpustate->PC--;
784824  break;
785825case 0x77: /*      LD (HL),A */
786826
787  mem_WriteByte (cpustate, cpustate->w.HL, cpustate->b.A);
827  mem_WriteByte (cpustate, ( cpustate->H << 8 ) | cpustate->L, cpustate->A);
788828  break;
789829case 0x78: /*      LD A,B */
790830
791  cpustate->b.A = cpustate->b.B;
831  cpustate->A = cpustate->B;
792832  break;
793833case 0x79: /*      LD A,C */
794834
795  cpustate->b.A = cpustate->b.C;
835  cpustate->A = cpustate->C;
796836  break;
797837case 0x7A: /*      LD A,D */
798838
799  cpustate->b.A = cpustate->b.D;
839  cpustate->A = cpustate->D;
800840  break;
801841case 0x7B: /*      LD A,E */
802842
803  cpustate->b.A = cpustate->b.E;
843  cpustate->A = cpustate->E;
804844  break;
805845case 0x7C: /*      LD A,H */
806846
807  cpustate->b.A = cpustate->b.H;
847  cpustate->A = cpustate->H;
808848  break;
809849case 0x7D: /*      LD A,L */
810850
811  cpustate->b.A = cpustate->b.L;
851  cpustate->A = cpustate->L;
812852  break;
813853case 0x7E: /*      LD A,(HL) */
814854
815  cpustate->b.A = mem_ReadByte (cpustate, cpustate->w.HL);
855  cpustate->A = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
816856  break;
817857case 0x7F: /*      LD A,A */
818858  break;
819859case 0x80: /*      ADD A,B */
820860
821  ADD_A_X (cpustate->b.B)
861  ADD_A_X (cpustate->B)
822862  break;
823863case 0x81: /*      ADD A,C */
824864
825  ADD_A_X (cpustate->b.C)
865  ADD_A_X (cpustate->C)
826866  break;
827867case 0x82: /*      ADD A,D */
828868
829  ADD_A_X (cpustate->b.D)
869  ADD_A_X (cpustate->D)
830870  break;
831871case 0x83: /*      ADD A,E */
832872
833  ADD_A_X (cpustate->b.E)
873  ADD_A_X (cpustate->E)
834874  break;
835875case 0x84: /*      ADD A,H */
836876
837  ADD_A_X (cpustate->b.H)
877  ADD_A_X (cpustate->H)
838878  break;
839879case 0x85: /*      ADD A,L */
840880
841  ADD_A_X (cpustate->b.L)
881  ADD_A_X (cpustate->L)
842882  break;
843883case 0x86: /*      ADD A,(HL) */
844884
845  x = mem_ReadByte (cpustate, cpustate->w.HL);
885  x = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
846886
847887  ADD_A_X (x)
848888  break;
849889case 0x87: /*      ADD A,A */
850890
851  ADD_A_X (cpustate->b.A)
891  ADD_A_X (cpustate->A)
852892  break;
853893case 0x88: /*      ADC A,B */
854894
855  ADC_A_X (cpustate->b.B)
895  ADC_A_X (cpustate->B)
856896  break;
857897case 0x89: /*      ADC A,C */
858898
859  ADC_A_X (cpustate->b.C)
899  ADC_A_X (cpustate->C)
860900  break;
861901case 0x8A: /*      ADC A,D */
862902
863  ADC_A_X (cpustate->b.D)
903  ADC_A_X (cpustate->D)
864904  break;
865905case 0x8B: /*      ADC A,E */
866906
867  ADC_A_X (cpustate->b.E)
907  ADC_A_X (cpustate->E)
868908  break;
869909case 0x8C: /*      ADC A,H */
870910
871  ADC_A_X (cpustate->b.H)
911  ADC_A_X (cpustate->H)
872912  break;
873913case 0x8D: /*      ADC A,L */
874914
875  ADC_A_X (cpustate->b.L)
915  ADC_A_X (cpustate->L)
876916  break;
877917case 0x8E: /*      ADC A,(HL) */
878918
879  x = mem_ReadByte (cpustate, cpustate->w.HL);
919  x = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
880920
881921  ADC_A_X (x)
882922  break;
883923case 0x8F: /*      ADC A,A */
884924
885  ADC_A_X (cpustate->b.A)
925  ADC_A_X (cpustate->A)
886926  break;
887927case 0x90: /*      SUB A,B */
888928
889  SUB_A_X (cpustate->b.B)
929  SUB_A_X (cpustate->B)
890930  break;
891931case 0x91: /*      SUB A,C */
892932
893  SUB_A_X (cpustate->b.C)
933  SUB_A_X (cpustate->C)
894934  break;
895935case 0x92: /*      SUB A,D */
896936
897  SUB_A_X (cpustate->b.D)
937  SUB_A_X (cpustate->D)
898938  break;
899939case 0x93: /*      SUB A,E */
900940
901  SUB_A_X (cpustate->b.E)
941  SUB_A_X (cpustate->E)
902942  break;
903943case 0x94: /*      SUB A,H */
904944
905  SUB_A_X (cpustate->b.H)
945  SUB_A_X (cpustate->H)
906946  break;
907947case 0x95: /*      SUB A,L */
908948
909  SUB_A_X (cpustate->b.L)
949  SUB_A_X (cpustate->L)
910950  break;
911951case 0x96: /*      SUB A,(HL) */
912952
913953
914  x = mem_ReadByte (cpustate, cpustate->w.HL);
954  x = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
915955
916956  SUB_A_X (x)
917957  break;
918958case 0x97: /*      SUB A,A */
919959
920  SUB_A_X (cpustate->b.A)
960  SUB_A_X (cpustate->A)
921961  break;
922962case 0x98: /*      SBC A,B */
923963
924  SBC_A_X (cpustate->b.B)
964  SBC_A_X (cpustate->B)
925965  break;
926966case 0x99: /*      SBC A,C */
927967
928  SBC_A_X (cpustate->b.C)
968  SBC_A_X (cpustate->C)
929969  break;
930970case 0x9A: /*      SBC A,D */
931971
932  SBC_A_X (cpustate->b.D)
972  SBC_A_X (cpustate->D)
933973  break;
934974case 0x9B: /*      SBC A,E */
935975
936  SBC_A_X (cpustate->b.E)
976  SBC_A_X (cpustate->E)
937977  break;
938978case 0x9C: /*      SBC A,H */
939979
940  SBC_A_X (cpustate->b.H)
980  SBC_A_X (cpustate->H)
941981  break;
942982case 0x9D: /*      SBC A,L */
943983
944  SBC_A_X (cpustate->b.L)
984  SBC_A_X (cpustate->L)
945985  break;
946986case 0x9E: /*      SBC A,(HL) */
947987
948  x = mem_ReadByte (cpustate, cpustate->w.HL);
988  x = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
949989
950990  SBC_A_X (x)
951991  break;
952992case 0x9F: /*      SBC A,A */
953993
954  SBC_A_X (cpustate->b.A)
994  SBC_A_X (cpustate->A)
955995  break;
956996case 0xA0: /*      AND A,B */
957997
958  AND_A_X (cpustate->b.B)
998  AND_A_X (cpustate->B)
959999  break;
9601000case 0xA1: /*      AND A,C */
9611001
962  AND_A_X (cpustate->b.C)
1002  AND_A_X (cpustate->C)
9631003  break;
9641004case 0xA2: /*      AND A,D */
9651005
966  AND_A_X (cpustate->b.D)
1006  AND_A_X (cpustate->D)
9671007  break;
9681008case 0xA3: /*      AND A,E */
9691009
970  AND_A_X (cpustate->b.E)
1010  AND_A_X (cpustate->E)
9711011  break;
9721012case 0xA4: /*      AND A,H */
9731013
974  AND_A_X (cpustate->b.H)
1014  AND_A_X (cpustate->H)
9751015  break;
9761016case 0xA5: /*      AND A,L */
9771017
978  AND_A_X (cpustate->b.L)
1018  AND_A_X (cpustate->L)
9791019  break;
9801020case 0xA6: /*      AND A,(HL) */
9811021
982  x = mem_ReadByte (cpustate, cpustate->w.HL);
1022  x = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
9831023
9841024  AND_A_X (x)
9851025  break;
9861026case 0xA7: /*      AND A,A */
9871027
988  cpustate->b.F = (cpustate->b.A == 0) ? (FLAG_H | FLAG_Z) : FLAG_H;
1028  cpustate->F = (cpustate->A == 0) ? (FLAG_H | FLAG_Z) : FLAG_H;
9891029  break;
9901030case 0xA8: /*      XOR A,B */
9911031
992  XOR_A_X (cpustate->b.B)
1032  XOR_A_X (cpustate->B)
9931033  break;
9941034case 0xA9: /*      XOR A,C */
9951035
996  XOR_A_X (cpustate->b.C)
1036  XOR_A_X (cpustate->C)
9971037  break;
9981038case 0xAA: /*      XOR A,D */
9991039
1000  XOR_A_X (cpustate->b.D)
1040  XOR_A_X (cpustate->D)
10011041  break;
10021042case 0xAB: /*      XOR A,E */
10031043
1004  XOR_A_X (cpustate->b.E)
1044  XOR_A_X (cpustate->E)
10051045  break;
10061046case 0xAC: /*      XOR A,H */
10071047
1008  XOR_A_X (cpustate->b.H)
1048  XOR_A_X (cpustate->H)
10091049  break;
10101050case 0xAD: /*      XOR A,L */
10111051
1012  XOR_A_X (cpustate->b.L)
1052  XOR_A_X (cpustate->L)
10131053  break;
10141054case 0xAE: /*      XOR A,(HL) */
10151055
1016  x = mem_ReadByte (cpustate, cpustate->w.HL);
1056  x = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
10171057
10181058  XOR_A_X (x)
10191059  break;
10201060case 0xAF: /*      XOR A,A */
10211061
1022  XOR_A_X (cpustate->b.A)
1062  XOR_A_X (cpustate->A)
10231063  break;
10241064case 0xB0: /*      OR A,B */
10251065
1026  OR_A_X (cpustate->b.B)
1066  OR_A_X (cpustate->B)
10271067  break;
10281068case 0xB1: /*      OR A,C */
10291069
1030  OR_A_X (cpustate->b.C)
1070  OR_A_X (cpustate->C)
10311071  break;
10321072case 0xB2: /*      OR A,D */
10331073
1034  OR_A_X (cpustate->b.D)
1074  OR_A_X (cpustate->D)
10351075  break;
10361076case 0xB3: /*      OR A,E */
10371077
1038  OR_A_X (cpustate->b.E)
1078  OR_A_X (cpustate->E)
10391079  break;
10401080case 0xB4: /*      OR A,H */
10411081
1042  OR_A_X (cpustate->b.H)
1082  OR_A_X (cpustate->H)
10431083  break;
10441084case 0xB5: /*      OR A,L */
10451085
1046  OR_A_X (cpustate->b.L)
1086  OR_A_X (cpustate->L)
10471087  break;
10481088case 0xB6: /*      OR A,(HL) */
10491089
1050  x = mem_ReadByte (cpustate, cpustate->w.HL);
1090  x = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
10511091
10521092  OR_A_X (x)
10531093  break;
10541094case 0xB7: /*      OR A,A */
10551095
1056  OR_A_X (cpustate->b.A)
1096  OR_A_X (cpustate->A)
10571097  break;
10581098case 0xB8: /*      CP A,B */
10591099
1060  CP_A_X (cpustate->b.B)
1100  CP_A_X (cpustate->B)
10611101  break;
10621102case 0xB9: /*      CP A,C */
10631103
1064  CP_A_X (cpustate->b.C)
1104  CP_A_X (cpustate->C)
10651105  break;
10661106case 0xBA: /*      CP A,D */
10671107
1068  CP_A_X (cpustate->b.D)
1108  CP_A_X (cpustate->D)
10691109  break;
10701110case 0xBB: /*      CP A,E */
10711111
1072  CP_A_X (cpustate->b.E)
1112  CP_A_X (cpustate->E)
10731113  break;
10741114case 0xBC: /*      CP A,H */
10751115
1076  CP_A_X (cpustate->b.H)
1116  CP_A_X (cpustate->H)
10771117  break;
10781118case 0xBD: /*      CP A,L */
10791119
1080  CP_A_X (cpustate->b.L)
1120  CP_A_X (cpustate->L)
10811121  break;
10821122case 0xBE: /*      CP A,(HL) */
10831123
1084  x = mem_ReadByte (cpustate, cpustate->w.HL);
1124  x = mem_ReadByte (cpustate, ( cpustate->H << 8 ) | cpustate->L);
10851125
10861126  CP_A_X (x)
10871127  break;
10881128case 0xBF: /*      CP A,A */
10891129
1090  CP_A_X (cpustate->b.A)
1130  CP_A_X (cpustate->A)
10911131  break;
10921132case 0xC0: /*      RET NZ */
10931133   CYCLES_PASSED( 4 );
1094   if (!(cpustate->b.F & FLAG_Z))
1134   if (!(cpustate->F & FLAG_Z))
10951135   {
1096      cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1097      cpustate->w.SP += 2;
1136      cpustate->PC = mem_ReadWord (cpustate, cpustate->SP);
1137      cpustate->SP += 2;
10981138      CYCLES_PASSED( 4 );
10991139   }
11001140   break;
11011141case 0xC1: /*      POP BC */
1102
1103  cpustate->w.BC = mem_ReadWord (cpustate, cpustate->w.SP);
1104  cpustate->w.SP += 2;
1105  break;
1142   POP( cpustate->B, cpustate->C );
1143   break;
11061144case 0xC2: /*      JP NZ,n16 */
11071145   {
1108      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1109      cpustate->w.PC += 2;
1146      UINT16 addr = mem_ReadWord (cpustate, cpustate->PC);
1147      cpustate->PC += 2;
11101148
1111      if ( ! (cpustate->b.F & FLAG_Z) )
1149      if ( ! (cpustate->F & FLAG_Z) )
11121150      {
1113         cpustate->w.PC = addr;
1151         cpustate->PC = addr;
11141152         CYCLES_PASSED( 4 );
11151153      }
11161154   }
11171155   break;
11181156case 0xC3: /*      JP n16 */
1119   cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.PC);
1157   cpustate->PC = mem_ReadWord (cpustate, cpustate->PC);
11201158   CYCLES_PASSED( 4 );
11211159   break;
11221160case 0xC4: /*      CALL NZ,n16 */
11231161   {
1124      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1125      cpustate->w.PC += 2;
1162      UINT16 addr = mem_ReadWord (cpustate, cpustate->PC);
1163      cpustate->PC += 2;
11261164
1127      if ( ! (cpustate->b.F & FLAG_Z) )
1165      if ( ! (cpustate->F & FLAG_Z) )
11281166      {
1129         cpustate->w.SP -= 2;
1130         mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1131         cpustate->w.PC = addr;
1167         cpustate->SP -= 2;
1168         mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1169         cpustate->PC = addr;
11321170         CYCLES_PASSED( 4 );
11331171      }
11341172   }
11351173   break;
11361174case 0xC5: /*      PUSH BC */
1137   cpustate->w.SP -= 2;
1138   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.BC);
1175   PUSH( cpustate->B, cpustate->C );
11391176   CYCLES_PASSED( 4 );
11401177   break;
11411178case 0xC6: /*      ADD A,n8 */
11421179
1143  x = mem_ReadByte (cpustate, cpustate->w.PC++);
1180  x = mem_ReadByte (cpustate, cpustate->PC++);
11441181  ADD_A_X (x)
11451182  break;
11461183case 0xC7: /*      RST 0 */
1147   cpustate->w.SP -= 2;
1148   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1149   cpustate->w.PC = 0;
1184   cpustate->SP -= 2;
1185   mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1186   cpustate->PC = 0;
11501187   CYCLES_PASSED( 4 );
11511188   break;
11521189case 0xC8: /*      RET Z */
11531190   CYCLES_PASSED( 4 );
1154   if (cpustate->b.F & FLAG_Z)
1191   if (cpustate->F & FLAG_Z)
11551192   {
1156      cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1157      cpustate->w.SP += 2;
1193      cpustate->PC = mem_ReadWord (cpustate, cpustate->SP);
1194      cpustate->SP += 2;
11581195      CYCLES_PASSED( 4 );
11591196   }
11601197   break;
11611198case 0xC9: /*      RET */
1162   cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1163   cpustate->w.SP += 2;
1199   cpustate->PC = mem_ReadWord (cpustate, cpustate->SP);
1200   cpustate->SP += 2;
11641201   CYCLES_PASSED( 4 );
11651202   break;
11661203case 0xCA: /*      JP Z,n16 */
11671204   {
1168      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1169      cpustate->w.PC += 2;
1205      UINT16 addr = mem_ReadWord (cpustate, cpustate->PC);
1206      cpustate->PC += 2;
11701207
1171      if (cpustate->b.F & FLAG_Z)
1208      if (cpustate->F & FLAG_Z)
11721209      {
1173         cpustate->w.PC = addr;
1210         cpustate->PC = addr;
11741211         CYCLES_PASSED( 4 );
11751212      }
11761213   }
11771214   break;
11781215case 0xCB: /*      PREFIX! */
1179  x = mem_ReadByte (cpustate, cpustate->w.PC++);
1216  x = mem_ReadByte (cpustate, cpustate->PC++);
11801217  switch (x)
11811218  {
11821219    #include "opc_cb.h"
r14630r14631
11841221  break;
11851222case 0xCC: /*      CALL Z,n16 */
11861223   {
1187      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1188      cpustate->w.PC += 2;
1224      UINT16 addr = mem_ReadWord (cpustate, cpustate->PC);
1225      cpustate->PC += 2;
11891226
1190      if (cpustate->b.F & FLAG_Z)
1227      if (cpustate->F & FLAG_Z)
11911228      {
1192         cpustate->w.SP -= 2;
1193         mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1194         cpustate->w.PC = addr;
1229         cpustate->SP -= 2;
1230         mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1231         cpustate->PC = addr;
11951232         CYCLES_PASSED( 4 );
11961233      }
11971234   }
11981235   break;
11991236case 0xCD: /*      CALL n16 */
12001237   {
1201      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1202      cpustate->w.PC += 2;
1238      UINT16 addr = mem_ReadWord (cpustate, cpustate->PC);
1239      cpustate->PC += 2;
12031240
1204      cpustate->w.SP -= 2;
1205      mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1206      cpustate->w.PC = addr;
1241      cpustate->SP -= 2;
1242      mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1243      cpustate->PC = addr;
12071244      CYCLES_PASSED( 4 );
12081245   }
12091246   break;
12101247case 0xCE: /*      ADC A,n8 */
12111248
1212  x = mem_ReadByte (cpustate, cpustate->w.PC++);
1249  x = mem_ReadByte (cpustate, cpustate->PC++);
12131250  ADC_A_X (x)
12141251  break;
12151252case 0xCF: /*      RST 8 */
1216   cpustate->w.SP -= 2;
1217   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1218   cpustate->w.PC = 8;
1253   cpustate->SP -= 2;
1254   mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1255   cpustate->PC = 8;
12191256   CYCLES_PASSED( 4 );
12201257   break;
12211258case 0xD0: /*      RET NC */
12221259   CYCLES_PASSED( 4 );
1223   if (!(cpustate->b.F & FLAG_C))
1260   if (!(cpustate->F & FLAG_C))
12241261   {
1225      cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1226      cpustate->w.SP += 2;
1262      cpustate->PC = mem_ReadWord (cpustate, cpustate->SP);
1263      cpustate->SP += 2;
12271264      CYCLES_PASSED( 4 );
12281265   }
12291266   break;
12301267case 0xD1: /*      POP DE */
1231
1232  cpustate->w.DE = mem_ReadWord (cpustate, cpustate->w.SP);
1233  cpustate->w.SP += 2;
1234  break;
1268   POP( cpustate->D, cpustate->E );
1269   break;
12351270case 0xD2: /*      JP NC,n16 */
12361271   {
1237      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1238      cpustate->w.PC += 2;
1272      UINT16 addr = mem_ReadWord (cpustate, cpustate->PC);
1273      cpustate->PC += 2;
12391274
1240      if ( ! (cpustate->b.F & FLAG_C) )
1275      if ( ! (cpustate->F & FLAG_C) )
12411276      {
1242         cpustate->w.PC = addr;
1277         cpustate->PC = addr;
12431278         CYCLES_PASSED( 4 );
12441279      }
12451280   }
r14630r14631
12481283  break;
12491284case 0xD4: /*      CALL NC,n16 */
12501285   {
1251      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1252      cpustate->w.PC += 2;
1286      UINT16 addr = mem_ReadWord (cpustate, cpustate->PC);
1287      cpustate->PC += 2;
12531288
1254      if ( ! (cpustate->b.F & FLAG_C) )
1289      if ( ! (cpustate->F & FLAG_C) )
12551290      {
1256         cpustate->w.SP -= 2;
1257         mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1258         cpustate->w.PC = addr;
1291         cpustate->SP -= 2;
1292         mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1293         cpustate->PC = addr;
12591294         CYCLES_PASSED( 4 );
12601295      }
12611296   }
12621297   break;
12631298case 0xD5: /*      PUSH DE */
1264   cpustate->w.SP -= 2;
1265   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.DE);
1299   PUSH( cpustate->D, cpustate->E );
12661300   CYCLES_PASSED( 4 );
12671301   break;
12681302case 0xD6: /*      SUB A,n8 */
12691303
1270  x = mem_ReadByte (cpustate, cpustate->w.PC++);
1304  x = mem_ReadByte (cpustate, cpustate->PC++);
12711305  SUB_A_X (x)
12721306  break;
12731307case 0xD7: /*      RST     $10 */
1274   cpustate->w.SP -= 2;
1275   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1276   cpustate->w.PC = 0x10;
1308   cpustate->SP -= 2;
1309   mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1310   cpustate->PC = 0x10;
12771311   CYCLES_PASSED( 4 );
12781312   break;
12791313case 0xD8: /*      RET C */
12801314   CYCLES_PASSED( 4 );
1281   if (cpustate->b.F & FLAG_C)
1315   if (cpustate->F & FLAG_C)
12821316   {
1283      cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1284      cpustate->w.SP += 2;
1317      cpustate->PC = mem_ReadWord (cpustate, cpustate->SP);
1318      cpustate->SP += 2;
12851319      CYCLES_PASSED( 4 );
12861320   }
12871321   break;
12881322case 0xD9: /*      RETI */
1289   cpustate->w.PC = mem_ReadWord (cpustate, cpustate->w.SP);
1290   cpustate->w.SP += 2;
1291   cpustate->w.enable |= IME;
1323   cpustate->PC = mem_ReadWord (cpustate, cpustate->SP);
1324   cpustate->SP += 2;
1325   cpustate->enable |= IME;
12921326   CYCLES_PASSED( 4 );
12931327   break;
12941328case 0xDA: /*      JP C,n16 */
12951329   {
1296      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1297      cpustate->w.PC += 2;
1330      UINT16 addr = mem_ReadWord (cpustate, cpustate->PC);
1331      cpustate->PC += 2;
12981332
1299      if (cpustate->b.F & FLAG_C)
1333      if (cpustate->F & FLAG_C)
13001334      {
1301         cpustate->w.PC = addr;
1335         cpustate->PC = addr;
13021336         CYCLES_PASSED( 4 );
13031337      }
13041338   }
r14630r14631
13071341  break;
13081342case 0xDC: /*      CALL C,n16 */
13091343   {
1310      UINT16 addr = mem_ReadWord (cpustate, cpustate->w.PC);
1311      cpustate->w.PC += 2;
1344      UINT16 addr = mem_ReadWord (cpustate, cpustate->PC);
1345      cpustate->PC += 2;
13121346
1313      if (cpustate->b.F & FLAG_C)
1347      if (cpustate->F & FLAG_C)
13141348      {
1315         cpustate->w.SP -= 2;
1316         mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1317         cpustate->w.PC = addr;
1349         cpustate->SP -= 2;
1350         mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1351         cpustate->PC = addr;
13181352         CYCLES_PASSED( 4 );
13191353      }
13201354   }
r14630r14631
13231357  break;
13241358case 0xDE: /*      SBC A,n8 */
13251359
1326  x = mem_ReadByte (cpustate, cpustate->w.PC++);
1360  x = mem_ReadByte (cpustate, cpustate->PC++);
13271361  SBC_A_X (x)
13281362  break;
13291363case 0xDF: /*      RST     $18 */
1330   cpustate->w.SP -= 2;
1331   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1332   cpustate->w.PC = 0x18;
1364   cpustate->SP -= 2;
1365   mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1366   cpustate->PC = 0x18;
13331367   CYCLES_PASSED( 4 );
13341368   break;
13351369case 0xE0: /*      LD      ($FF00+n8),A */
13361370  {
1337   UINT8 v = mem_ReadByte (cpustate, cpustate->w.PC++);
1338   mem_WriteByte (cpustate, 0xFF00 + v, cpustate->b.A);
1371   UINT8 v = mem_ReadByte (cpustate, cpustate->PC++);
1372   mem_WriteByte (cpustate, 0xFF00 + v, cpustate->A);
13391373  }
13401374  break;
13411375case 0xE1: /*      POP HL */
1342
1343  cpustate->w.HL = mem_ReadWord (cpustate, cpustate->w.SP);
1344  cpustate->w.SP += 2;
1345  break;
1376   POP( cpustate->H, cpustate->L );
1377   break;
13461378case 0xE2: /*      LD ($FF00+C),A */
13471379
1348  mem_WriteByte (cpustate, (UINT16) (0xFF00 + cpustate->b.C), cpustate->b.A);
1380  mem_WriteByte (cpustate, (UINT16) (0xFF00 + cpustate->C), cpustate->A);
13491381  break;
13501382case 0xE3: /*      EH? */
13511383  break;
13521384case 0xE4: /*      EH? */
13531385  break;
13541386case 0xE5: /*      PUSH HL */
1355   cpustate->w.SP -= 2;
1356   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.HL);
1387   PUSH( cpustate->H, cpustate->L );
13571388   CYCLES_PASSED( 4 );
13581389   break;
13591390case 0xE6: /*      AND A,n8 */
13601391
1361  x = mem_ReadByte (cpustate, cpustate->w.PC++);
1392  x = mem_ReadByte (cpustate, cpustate->PC++);
13621393  AND_A_X (x)
13631394  break;
13641395case 0xE7: /*      RST $20 */
1365   cpustate->w.SP -= 2;
1366   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1367   cpustate->w.PC = 0x20;
1396   cpustate->SP -= 2;
1397   mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1398   cpustate->PC = 0x20;
13681399   CYCLES_PASSED( 4 );
13691400   break;
13701401case 0xE8: /*      ADD SP,n8 */
r14630r14631
13781409  {
13791410   register INT32 n;
13801411
1381   n = (INT8) mem_ReadByte (cpustate, cpustate->w.PC++);
1412   n = (INT8) mem_ReadByte (cpustate, cpustate->PC++);
13821413
1383   if ( ( cpustate->w.SP & 0xFF ) + (UINT8)(n & 0xFF) > 0xFF )
1414   if ( ( cpustate->SP & 0xFF ) + (UINT8)(n & 0xFF) > 0xFF )
13841415    {
1385      cpustate->b.F = FLAG_C;
1416      cpustate->F = FLAG_C;
13861417    }
13871418    else
13881419    {
1389      cpustate->b.F = 0;
1420      cpustate->F = 0;
13901421    }
13911422
1392    if ( ( cpustate->w.SP & 0x0F ) + ( n & 0x0F ) > 0x0F )
1423    if ( ( cpustate->SP & 0x0F ) + ( n & 0x0F ) > 0x0F )
13931424    {
1394      cpustate->b.F |= FLAG_H;
1425      cpustate->F |= FLAG_H;
13951426    }
13961427
1397   cpustate->w.SP = (UINT16) ( cpustate->w.SP + n );
1428   cpustate->SP = (UINT16) ( cpustate->SP + n );
13981429  }
13991430  CYCLES_PASSED( 8 );
14001431  break;
14011432case 0xE9: /*      JP (HL) */
1402
1403  cpustate->w.PC = cpustate->w.HL;
1404  break;
1433   cpustate->PC = ( cpustate->H << 8 ) | cpustate->L;
1434   break;
14051435case 0xEA: /*      LD (n16),A */
14061436
1407  mem_WriteByte (cpustate, mem_ReadWord (cpustate, cpustate->w.PC), cpustate->b.A);
1408  cpustate->w.PC += 2;
1437  mem_WriteByte (cpustate, mem_ReadWord (cpustate, cpustate->PC), cpustate->A);
1438  cpustate->PC += 2;
14091439  break;
14101440case 0xEB: /*      EH? */
14111441  break;
r14630r14631
14151445  break;
14161446case 0xEE: /*      XOR A,n8 */
14171447
1418  x = mem_ReadByte (cpustate, cpustate->w.PC++);
1448  x = mem_ReadByte (cpustate, cpustate->PC++);
14191449  XOR_A_X (x)
14201450  break;
14211451case 0xEF: /*      RST $28 */
1422   cpustate->w.SP -= 2;
1423   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1424   cpustate->w.PC = 0x28;
1452   cpustate->SP -= 2;
1453   mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1454   cpustate->PC = 0x28;
14251455   CYCLES_PASSED( 4 );
14261456   break;
14271457case 0xF0: /*      LD A,($FF00+n8) */
14281458  {
1429   UINT8 v = mem_ReadByte (cpustate, cpustate->w.PC++);
1430   cpustate->b.A = mem_ReadByte (cpustate, 0xFF00 + v);
1459   UINT8 v = mem_ReadByte (cpustate, cpustate->PC++);
1460   cpustate->A = mem_ReadByte (cpustate, 0xFF00 + v);
14311461  }
14321462  break;
14331463case 0xF1: /*      POP AF */
1434
1435  cpustate->w.AF = (UINT16) (mem_ReadWord (cpustate, cpustate->w.SP) & 0xFFF0);
1436  cpustate->w.SP += 2;
1437  break;
1464   POP( cpustate->A, cpustate->F );
1465   cpustate->F &= 0xF0;
1466   break;
14381467case 0xF2: /*      LD A,($FF00+C) */
14391468
1440  cpustate->b.A = mem_ReadByte (cpustate, (UINT16) (0xFF00 + cpustate->b.C));
1469  cpustate->A = mem_ReadByte (cpustate, (UINT16) (0xFF00 + cpustate->C));
14411470  break;
14421471case 0xF3: /*      DI */
1443  cpustate->w.ei_delay = 0;
1444  cpustate->w.enable &= ~IME;
1472  cpustate->ei_delay = 0;
1473  cpustate->enable &= ~IME;
14451474  break;
14461475case 0xF4: /*      EH? */
14471476  break;
14481477case 0xF5: /*      PUSH AF */
1449   cpustate->w.SP -= 2;
1450   mem_WriteWord (cpustate, cpustate->w.SP, (UINT16) (cpustate->w.AF & 0xFFF0));
1478   cpustate->F &= 0xF0;
1479   PUSH( cpustate->A, cpustate->F );
14511480   CYCLES_PASSED( 4 );
14521481   break;
14531482case 0xF6: /*      OR A,n8 */
14541483
1455  x = mem_ReadByte (cpustate, cpustate->w.PC++);
1484  x = mem_ReadByte (cpustate, cpustate->PC++);
14561485  OR_A_X (x)
14571486  break;
14581487case 0xF7: /*      RST $30 */
1459   cpustate->w.SP -= 2;
1460   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1461   cpustate->w.PC = 0x30;
1488   cpustate->SP -= 2;
1489   mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1490   cpustate->PC = 0x30;
14621491   CYCLES_PASSED( 4 );
14631492   break;
14641493case 0xF8: /*      LD HL,SP+n8 */
r14630r14631
14751504  {
14761505   register INT32 n;
14771506
1478   n = (INT8) mem_ReadByte (cpustate, cpustate->w.PC++);
1507   n = (INT8) mem_ReadByte (cpustate, cpustate->PC++);
14791508
1480   if ( ( cpustate->w.SP & 0xFF ) + (UINT8)(n & 0xFF) > 0xFF )
1509   if ( ( cpustate->SP & 0xFF ) + (UINT8)(n & 0xFF) > 0xFF )
14811510    {
1482      cpustate->b.F = FLAG_C;
1511      cpustate->F = FLAG_C;
14831512    }
14841513    else
14851514    {
1486      cpustate->b.F = 0;
1515      cpustate->F = 0;
14871516    }
14881517
1489   if ( ( cpustate->w.SP & 0x0F ) + ( n & 0x0F ) > 0x0F )
1518   if ( ( cpustate->SP & 0x0F ) + ( n & 0x0F ) > 0x0F )
14901519    {
1491      cpustate->b.F |= FLAG_H;
1520      cpustate->F |= FLAG_H;
14921521    }
14931522
1494   cpustate->w.HL = (UINT16) ( cpustate->w.SP + n );
1523   UINT16 res = cpustate->SP + n;
1524
1525   cpustate->L = res & 0xFF;
1526   cpustate->H = res >> 8;
14951527  }
14961528  CYCLES_PASSED( 4 );
14971529  break;
14981530case 0xF9: /*      LD SP,HL */
1499   cpustate->w.SP = cpustate->w.HL;
1531   cpustate->SP = ( cpustate->H << 8 ) | cpustate->L;
15001532   CYCLES_PASSED( 4 );
15011533   break;
15021534case 0xFA: /*      LD A,(n16) */
1503   cpustate->b.A = mem_ReadByte (cpustate, mem_ReadWord (cpustate, cpustate->w.PC));
1504   cpustate->w.PC += 2;
1535   cpustate->A = mem_ReadByte (cpustate, mem_ReadWord (cpustate, cpustate->PC));
1536   cpustate->PC += 2;
15051537   break;
15061538case 0xFB: /*      EI */
1507   cpustate->w.enable |= IME;
1508   cpustate->w.ei_delay = 1;
1539   cpustate->enable |= IME;
1540   cpustate->ei_delay = 1;
15091541   break;
15101542case 0xFC: /*      EH? */
15111543   break;
15121544case 0xFD: /*      EH? */
15131545   break;
15141546case 0xFE: /*      CP A,n8 */
1515   x = mem_ReadByte (cpustate, cpustate->w.PC++);
1547   x = mem_ReadByte (cpustate, cpustate->PC++);
15161548   CP_A_X (x)
15171549   break;
15181550case 0xFF: /*      RST $38 */
1519   cpustate->w.SP -= 2;
1520   mem_WriteWord (cpustate, cpustate->w.SP, cpustate->w.PC);
1521   cpustate->w.PC = 0x38;
1551   cpustate->SP -= 2;
1552   mem_WriteWord (cpustate, cpustate->SP, cpustate->PC);
1553   cpustate->PC = 0x38;
15221554   CYCLES_PASSED( 4 );
15231555   break;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team