basic psp snd + cz80
authornotaz <notasas@gmail.com>
Fri, 26 Oct 2007 20:08:13 +0000 (20:08 +0000)
committernotaz <notasas@gmail.com>
Fri, 26 Oct 2007 20:08:13 +0000 (20:08 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@280 be3aeb3a-fb24-0410-a615-afba39da0efa

16 files changed:
Pico/Memory.c
Pico/PicoInt.h
Pico/sound/sound.c
cpu/cz80/cz80.c [new file with mode: 0644]
cpu/cz80/cz80.h [new file with mode: 0644]
cpu/cz80/cz80_op.c [new file with mode: 0644]
cpu/cz80/cz80_opCB.c [new file with mode: 0644]
cpu/cz80/cz80_opED.c [new file with mode: 0644]
cpu/cz80/cz80_opXY.c [new file with mode: 0644]
cpu/cz80/cz80_opXYCB.c [new file with mode: 0644]
cpu/cz80/cz80jmp.c [new file with mode: 0644]
cpu/cz80/cz80macro.h [new file with mode: 0644]
platform/psp/Makefile
platform/psp/emu.c
platform/psp/menu.c
platform/psp/psp.c

index 527b80b..3c7b70c 100644 (file)
@@ -684,14 +684,11 @@ end:
   return ret;\r
 }\r
 \r
-PICO_INTERNAL unsigned short z80_read16(unsigned short a)\r
-{\r
-  //dprintf("z80_read16");\r
-\r
-  return (u16) ( (u16)z80_read(a) | ((u16)z80_read((u16)(a+1))<<8) );\r
-}\r
-\r
+#ifndef _USE_CZ80\r
 PICO_INTERNAL_ASM void z80_write(unsigned char data, unsigned short a)\r
+#else\r
+PICO_INTERNAL_ASM void z80_write(unsigned int a, unsigned char data)\r
+#endif\r
 {\r
   //if (a<0x4000)\r
   //  dprintf("z80 w8 : %06x,   %02x @%04x", a, data, mz80GetRegisterValue(NULL, 0));\r
@@ -732,6 +729,14 @@ PICO_INTERNAL_ASM void z80_write(unsigned char data, unsigned short a)
   elprintf(EL_ANOMALY, "z80 invalid w8 [%06x] %02x", a, data);\r
 }\r
 \r
+#ifndef _USE_CZ80\r
+PICO_INTERNAL unsigned short z80_read16(unsigned short a)\r
+{\r
+  //dprintf("z80_read16");\r
+\r
+  return (u16) ( (u16)z80_read(a) | ((u16)z80_read((u16)(a+1))<<8) );\r
+}\r
+\r
 PICO_INTERNAL void z80_write16(unsigned short data, unsigned short a)\r
 {\r
   //dprintf("z80_write16");\r
@@ -739,4 +744,5 @@ PICO_INTERNAL void z80_write16(unsigned short data, unsigned short a)
   z80_write((unsigned char) data,a);\r
   z80_write((unsigned char)(data>>8),(u16)(a+1));\r
 }\r
+#endif\r
 \r
index 7a81ba6..c98ba8b 100644 (file)
@@ -318,9 +318,13 @@ PICO_INTERNAL void PicoMemSetup(void);
 PICO_INTERNAL_ASM void PicoMemReset(void);\r
 PICO_INTERNAL int PadRead(int i);\r
 PICO_INTERNAL unsigned char z80_read(unsigned short a);\r
-PICO_INTERNAL unsigned short z80_read16(unsigned short a);\r
+#ifndef _USE_CZ80\r
 PICO_INTERNAL_ASM void z80_write(unsigned char data, unsigned short a);\r
 PICO_INTERNAL void z80_write16(unsigned short data, unsigned short a);\r
+PICO_INTERNAL unsigned short z80_read16(unsigned short a);\r
+#else\r
+PICO_INTERNAL_ASM void z80_write(unsigned int a, unsigned char data);\r
+#endif\r
 \r
 // cd/Memory.c\r
 PICO_INTERNAL void PicoMemSetupCD(void);\r
index ab56bb9..1b12696 100644 (file)
@@ -15,6 +15,8 @@
 #include "../../cpu/mz80/mz80.h"\r
 #elif defined(_USE_DRZ80)\r
 #include "../../cpu/DrZ80/drz80.h"\r
+#elif defined(_USE_CZ80)\r
+#include "../../cpu/cz80/cz80.h"\r
 #endif\r
 \r
 #include "../PicoInt.h"\r
@@ -329,7 +331,6 @@ static void DrZ80_irq_callback()
 {\r
   drZ80.Z80_IRQ = 0; // lower irq when accepted\r
 }\r
-\r
 #endif\r
 \r
 // z80 functionality wrappers\r
@@ -353,7 +354,6 @@ PICO_INTERNAL void z80_init(void)
   mz80SetContext(&z80);\r
 \r
 #elif defined(_USE_DRZ80)\r
-\r
   memset(&drZ80, 0, sizeof(struct DrZ80));\r
   drZ80.z80_rebasePC=DrZ80_rebasePC;\r
   drZ80.z80_rebaseSP=DrZ80_rebaseSP;\r
@@ -364,6 +364,14 @@ PICO_INTERNAL void z80_init(void)
   drZ80.z80_in      =DrZ80_in;\r
   drZ80.z80_out     =DrZ80_out;\r
   drZ80.z80_irq_callback=DrZ80_irq_callback;\r
+\r
+#elif defined(_USE_CZ80)\r
+  memset(&CZ80, 0, sizeof(CZ80));\r
+  Cz80_Init(&CZ80);\r
+  Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (UINT32)Pico.zram); // main RAM\r
+  Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (UINT32)Pico.zram - 0x2000); // mirror\r
+  Cz80_Set_ReadB(&CZ80, (UINT8 (*)(UINT32 address))z80_read);\r
+  Cz80_Set_WriteB(&CZ80, z80_write);\r
 #endif\r
 }\r
 \r
@@ -380,6 +388,8 @@ PICO_INTERNAL void z80_reset(void)
   drZ80.Z80IM = 0; // 1?\r
   drZ80.Z80PC = drZ80.z80_rebasePC(0);\r
   drZ80.Z80SP = drZ80.z80_rebaseSP(0x2000); // 0xf000 ?\r
+#elif defined(_USE_CZ80)\r
+  Cz80_Reset(&CZ80);\r
 #endif\r
   Pico.m.z80_fakeval = 0; // for faking when Z80 is disabled\r
 }\r
@@ -398,6 +408,8 @@ PICO_INTERNAL void z80_int(void)
 #elif defined(_USE_DRZ80)\r
   drZ80.z80irqvector = 0xFF; // default IRQ vector RST opcode\r
   drZ80.Z80_IRQ = 1;\r
+#elif defined(_USE_CZ80)\r
+  Cz80_Set_IRQ(&CZ80, 0, HOLD_LINE);\r
 #endif\r
 }\r
 \r
@@ -410,6 +422,8 @@ PICO_INTERNAL int z80_run(int cycles)
   return mz80GetElapsedTicks(0) - ticks_pre;\r
 #elif defined(_USE_DRZ80)\r
   return cycles - DrZ80Run(&drZ80, cycles);\r
+#elif defined(_USE_CZ80)\r
+  return Cz80_Exec(&CZ80, cycles);\r
 #else\r
   return cycles;\r
 #endif\r
@@ -427,13 +441,17 @@ PICO_INTERNAL void z80_pack(unsigned char *data)
   drZ80.Z80PC = drZ80.z80_rebasePC(drZ80.Z80PC-drZ80.Z80PC_BASE);\r
   drZ80.Z80SP = drZ80.z80_rebaseSP(drZ80.Z80SP-drZ80.Z80SP_BASE);\r
   memcpy(data+4, &drZ80, 0x54);\r
+#elif defined(_USE_CZ80)\r
+  *(int *)data = 0x00007a43; // "Cz"\r
+  memcpy(data+4, &CZ80, (INT32)&CZ80.BasePC - (INT32)&CZ80);\r
+  printf("size: %i (%x)\n", (INT32)&CZ80.BasePC - (INT32)&CZ80, (INT32)&CZ80.BasePC - (INT32)&CZ80); // FIXME rm\r
 #endif\r
 }\r
 \r
 PICO_INTERNAL void z80_unpack(unsigned char *data)\r
 {\r
 #if defined(_USE_MZ80)\r
-  if(*(int *)data == 0x00005A6D) { // "mZ" save?\r
+  if (*(int *)data == 0x00005A6D) { // "mZ" save?\r
     struct mz80context mz80;\r
     mz80GetContext(&mz80);\r
     memcpy(&mz80.z80clockticks, data+4, sizeof(mz80)-5*4);\r
@@ -443,7 +461,7 @@ PICO_INTERNAL void z80_unpack(unsigned char *data)
     z80_int();\r
   }\r
 #elif defined(_USE_DRZ80)\r
-  if(*(int *)data == 0x015A7244) { // "DrZ" v1 save?\r
+  if (*(int *)data == 0x015A7244) { // "DrZ" v1 save?\r
     memcpy(&drZ80, data+4, 0x54);\r
     // update bases\r
     drZ80.Z80PC = drZ80.z80_rebasePC(drZ80.Z80PC-drZ80.Z80PC_BASE);\r
@@ -453,6 +471,13 @@ PICO_INTERNAL void z80_unpack(unsigned char *data)
     drZ80.Z80IM = 1;\r
     z80_int(); // try to goto int handler, maybe we won't execute trash there?\r
   }\r
+#elif defined(_USE_CZ80)\r
+  if (*(int *)data == 0x00007a43) // "Cz" save?\r
+    memcpy(&CZ80, data+4, (INT32)&CZ80.BasePC - (INT32)&CZ80);\r
+  else {\r
+    z80_reset();\r
+    z80_int();\r
+  }\r
 #endif\r
 }\r
 \r
@@ -468,6 +493,8 @@ PICO_INTERNAL void z80_debug(char *dstr)
 {\r
 #if defined(_USE_DRZ80)\r
   sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", drZ80.Z80PC-drZ80.Z80PC_BASE, drZ80.Z80SP-drZ80.Z80SP_BASE);\r
+#elif defined(_USE_CZ80)\r
+  sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", CZ80.PC - CZ80.BasePC, CZ80.SP.W);\r
 #endif\r
 }\r
 #endif\r
diff --git a/cpu/cz80/cz80.c b/cpu/cz80/cz80.c
new file mode 100644 (file)
index 0000000..bcff740
--- /dev/null
@@ -0,0 +1,460 @@
+/******************************************************************************\r
+ *\r
+ * CZ80 (Z80 CPU emulator) version 0.9\r
+ * Compiled with Dev-C++\r
+ * Copyright 2004-2005 Stéphane Dallongeville\r
+ *\r
+ * (Modified by NJ)\r
+ *\r
+ *****************************************************************************/\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include "cz80.h"\r
+\r
+#ifndef ALIGN_DATA\r
+#define ALIGN_DATA      __attribute__((aligned(4)))\r
+#endif\r
+\r
+#define CF                                     0x01\r
+#define NF                                     0x02\r
+#define PF                                     0x04\r
+#define VF                                     PF\r
+#define XF                                     0x08\r
+#define HF                                     0x10\r
+#define YF                                     0x20\r
+#define ZF                                     0x40\r
+#define SF                                     0x80\r
+\r
+\r
+/******************************************************************************\r
+       \83}\83N\83\8d\r
+******************************************************************************/\r
+\r
+#include "cz80macro.h"\r
+\r
+\r
+/******************************************************************************\r
+       \83O\83\8d\81[\83o\83\8b\8d\\91¢\91Ì\r
+******************************************************************************/\r
+\r
+cz80_struc ALIGN_DATA CZ80;\r
+\r
+\r
+/******************************************************************************\r
+       \83\8d\81[\83J\83\8b\95Ï\90\94\r
+******************************************************************************/\r
+\r
+static UINT8 ALIGN_DATA cz80_bad_address[1 << CZ80_FETCH_SFT];\r
+\r
+static UINT8 ALIGN_DATA SZ[256];\r
+static UINT8 ALIGN_DATA SZP[256];\r
+static UINT8 ALIGN_DATA SZ_BIT[256];\r
+static UINT8 ALIGN_DATA SZHV_inc[256];\r
+static UINT8 ALIGN_DATA SZHV_dec[256];\r
+#if CZ80_BIG_FLAGS_ARRAY\r
+static UINT8 ALIGN_DATA SZHVC_add[2*256*256];\r
+static UINT8 ALIGN_DATA SZHVC_sub[2*256*256];\r
+#endif\r
+\r
+\r
+/******************************************************************************\r
+       \83\8d\81[\83J\83\8b\8aÖ\90\94\r
+******************************************************************************/\r
+\r
+/*--------------------------------------------------------\r
+       \8a\84\82è\8d\9e\82Ý\83R\81[\83\8b\83o\83b\83N\r
+--------------------------------------------------------*/\r
+\r
+static INT32 Cz80_Interrupt_Callback(INT32 line)\r
+{\r
+       return 0xff;\r
+}\r
+\r
+\r
+/******************************************************************************\r
+       CZ80\83C\83\93\83^\83t\83F\81[\83X\8aÖ\90\94\r
+******************************************************************************/\r
+\r
+/*--------------------------------------------------------\r
+       CPU\8f\89\8aú\89»\r
+--------------------------------------------------------*/\r
+\r
+void Cz80_Init(cz80_struc *CPU)\r
+{\r
+       UINT32 i, j, p;\r
+#if CZ80_BIG_FLAGS_ARRAY\r
+       int oldval, newval, val;\r
+       UINT8 *padd, *padc, *psub, *psbc;\r
+#endif\r
+\r
+       memset(CPU, 0, sizeof(cz80_struc));\r
+\r
+       memset(cz80_bad_address, 0xff, sizeof(cz80_bad_address));\r
+\r
+       for (i = 0; i < CZ80_FETCH_BANK; i++)\r
+       {\r
+               CPU->Fetch[i] = (UINT32)cz80_bad_address;\r
+#if CZ80_ENCRYPTED_ROM\r
+               CPU->OPFetch[i] = 0;\r
+#endif\r
+       }\r
+\r
+       // flags tables initialisation\r
+       for (i = 0; i < 256; i++)\r
+       {\r
+               SZ[i] = i & (SF | YF | XF);\r
+               if (!i) SZ[i] |= ZF;\r
+\r
+               SZ_BIT[i] = i & (SF | YF | XF);\r
+               if (!i) SZ_BIT[i] |= ZF | PF;\r
+\r
+               for (j = 0, p = 0; j < 8; j++) if (i & (1 << j)) p++;\r
+               SZP[i] = SZ[i];\r
+               if (!(p & 1)) SZP[i] |= PF;\r
+\r
+               SZHV_inc[i] = SZ[i];\r
+               if(i == 0x80) SZHV_inc[i] |= VF;\r
+               if((i & 0x0f) == 0x00) SZHV_inc[i] |= HF;\r
+\r
+               SZHV_dec[i] = SZ[i] | NF;\r
+               if (i == 0x7f) SZHV_dec[i] |= VF;\r
+               if ((i & 0x0f) == 0x0f) SZHV_dec[i] |= HF;\r
+       }\r
+\r
+#if CZ80_BIG_FLAGS_ARRAY\r
+       padd = &SZHVC_add[  0*256];\r
+       padc = &SZHVC_add[256*256];\r
+       psub = &SZHVC_sub[  0*256];\r
+       psbc = &SZHVC_sub[256*256];\r
+\r
+       for (oldval = 0; oldval < 256; oldval++)\r
+       {\r
+               for (newval = 0; newval < 256; newval++)\r
+               {\r
+                       /* add or adc w/o carry set */\r
+                       val = newval - oldval;\r
+                       *padd = (newval) ? ((newval & 0x80) ? SF : 0) : ZF;\r
+                       *padd |= (newval & (YF | XF));  /* undocumented flag bits 5+3 */\r
+                       if ((newval & 0x0f) < (oldval & 0x0f)) *padd |= HF;\r
+                       if (newval < oldval ) *padd |= CF;\r
+                       if ((val ^ oldval ^ 0x80) & (val ^ newval) & 0x80) *padd |= VF;\r
+                       padd++;\r
+\r
+                       /* adc with carry set */\r
+                       val = newval - oldval - 1;\r
+                       *padc = (newval) ? ((newval & 0x80) ? SF : 0) : ZF;\r
+                       *padc |= (newval & (YF | XF));  /* undocumented flag bits 5+3 */\r
+                       if ((newval & 0x0f) <= (oldval & 0x0f)) *padc |= HF;\r
+                       if (newval <= oldval) *padc |= CF;\r
+                       if ((val ^ oldval ^ 0x80) & (val ^ newval) & 0x80) *padc |= VF;\r
+                       padc++;\r
+\r
+                       /* cp, sub or sbc w/o carry set */\r
+                       val = oldval - newval;\r
+                       *psub = NF | ((newval) ? ((newval & 0x80) ? SF : 0) : ZF);\r
+                       *psub |= (newval & (YF | XF));  /* undocumented flag bits 5+3 */\r
+                       if ((newval & 0x0f) > (oldval & 0x0f)) *psub |= HF;\r
+                       if (newval > oldval) *psub |= CF;\r
+                       if ((val^oldval) & (oldval^newval) & 0x80) *psub |= VF;\r
+                       psub++;\r
+\r
+                       /* sbc with carry set */\r
+                       val = oldval - newval - 1;\r
+                       *psbc = NF | ((newval) ? ((newval & 0x80) ? SF : 0) : ZF);\r
+                       *psbc |= (newval & (YF | XF));  /* undocumented flag bits 5+3 */\r
+                       if ((newval & 0x0f) >= (oldval & 0x0f)) *psbc |= HF;\r
+                       if (newval >= oldval) *psbc |= CF;\r
+                       if ((val ^ oldval) & (oldval^newval) & 0x80) *psbc |= VF;\r
+                       psbc++;\r
+               }\r
+       }\r
+#endif\r
+\r
+       CPU->pzR8[0] = &zB;\r
+       CPU->pzR8[1] = &zC;\r
+       CPU->pzR8[2] = &zD;\r
+       CPU->pzR8[3] = &zE;\r
+       CPU->pzR8[4] = &zH;\r
+       CPU->pzR8[5] = &zL;\r
+       CPU->pzR8[6] = &zF;     // \8f\88\97\9d\82Ì\93s\8d\87\8fã\81AA\82Æ\93ü\82ê\91Ö\82¦\r
+       CPU->pzR8[7] = &zA;     // \8f\88\97\9d\82Ì\93s\8d\87\8fã\81AF\82Æ\93ü\82ê\91Ö\82¦\r
+\r
+       CPU->pzR16[0] = pzBC;\r
+       CPU->pzR16[1] = pzDE;\r
+       CPU->pzR16[2] = pzHL;\r
+       CPU->pzR16[3] = pzAF;\r
+\r
+       zIX = zIY = 0xffff;\r
+       zF = ZF;\r
+\r
+       CPU->Interrupt_Callback = Cz80_Interrupt_Callback;\r
+}\r
+\r
+\r
+/*--------------------------------------------------------\r
+       CPU\83\8a\83Z\83b\83g\r
+--------------------------------------------------------*/\r
+\r
+void Cz80_Reset(cz80_struc *CPU)\r
+{\r
+       memset(CPU, 0, (INT32)&CPU->BasePC - (INT32)CPU);\r
+       Cz80_Set_Reg(CPU, CZ80_PC, 0);\r
+}\r
+\r
+\r
+/*--------------------------------------------------------\r
+       CPU\8eÀ\8ds\r
+--------------------------------------------------------*/\r
+\r
+INT32 Cz80_Exec(cz80_struc *CPU, INT32 cycles)\r
+{\r
+#if CZ80_USE_JUMPTABLE\r
+#include "cz80jmp.c"\r
+#endif\r
+\r
+       UINT32 PC;\r
+#if CZ80_ENCRYPTED_ROM\r
+       INT32 OPBase;\r
+#endif\r
+       UINT32 Opcode;\r
+       UINT32 adr = 0;\r
+       UINT32 res;\r
+       UINT32 val;\r
+       int afterEI = 0;\r
+\r
+       PC = CPU->PC;\r
+#if CZ80_ENCRYPTED_ROM\r
+       OPBase = CPU->OPBase;\r
+#endif\r
+       CPU->ICount = cycles - CPU->ExtraCycles;\r
+       CPU->ExtraCycles = 0;\r
+\r
+       if (!CPU->HaltState)\r
+       {\r
+Cz80_Exec:\r
+               if (CPU->ICount > 0)\r
+               {\r
+                       union16 *data = pzHL;\r
+                       Opcode = READ_OP();\r
+#if CZ80_EMULATE_R_EXACTLY\r
+                       zR++;\r
+#endif\r
+                       #include "cz80_op.c"\r
+               }\r
+\r
+               if (afterEI)\r
+               {\r
+                       afterEI = 0;\r
+Cz80_Check_Interrupt:\r
+                       CHECK_INT\r
+                       goto Cz80_Exec;\r
+               }\r
+       }\r
+       else CPU->ICount = 0;\r
+\r
+Cz80_Exec_End:\r
+       CPU->PC = PC;\r
+#if CZ80_ENCRYPTED_ROM\r
+       CPU->OPBase = OPBase;\r
+#endif\r
+       cycles -= CPU->ICount;\r
+#if !CZ80_EMULATE_R_EXACTLY\r
+       zR = (zR + (cycles >> 2)) & 0x7f;\r
+#endif\r
+\r
+       return cycles;\r
+}\r
+\r
+\r
+/*--------------------------------------------------------\r
+       \8a\84\82è\8d\9e\82Ý\8f\88\97\9d\r
+--------------------------------------------------------*/\r
+\r
+void Cz80_Set_IRQ(cz80_struc *CPU, INT32 line, INT32 state)\r
+{\r
+       if (line == IRQ_LINE_NMI)\r
+       {\r
+               zIFF1 = 0;\r
+               CPU->ExtraCycles += 11;\r
+               CPU->HaltState = 0;\r
+               PUSH_16(CPU->PC - CPU->BasePC)\r
+               Cz80_Set_Reg(CPU, CZ80_PC, 0x66);\r
+       }\r
+       else\r
+       {\r
+               CPU->IRQState = state;\r
+\r
+               if (state != CLEAR_LINE)\r
+               {\r
+                       UINT32 PC = CPU->PC;\r
+#if CZ80_ENCRYPTED_ROM\r
+                       INT32 OPBase = CPU->OPBase;\r
+#endif\r
+\r
+                       CPU->IRQLine = line;\r
+                       CHECK_INT\r
+                       CPU->PC = PC;\r
+#if CZ80_ENCRYPTED_ROM\r
+                       CPU->OPBase = OPBase;\r
+#endif\r
+               }\r
+       }\r
+}\r
+\r
+\r
+/*--------------------------------------------------------\r
+       \83\8c\83W\83X\83^\8eæ\93¾\r
+--------------------------------------------------------*/\r
+\r
+UINT32 Cz80_Get_Reg(cz80_struc *CPU, INT32 regnum)\r
+{\r
+       switch (regnum)\r
+       {\r
+       case CZ80_PC:   return (CPU->PC - CPU->BasePC);\r
+       case CZ80_SP:   return zSP;\r
+       case CZ80_AF:   return zAF;\r
+       case CZ80_BC:   return zBC;\r
+       case CZ80_DE:   return zDE;\r
+       case CZ80_HL:   return zHL;\r
+       case CZ80_IX:   return zIX;\r
+       case CZ80_IY:   return zIY;\r
+       case CZ80_AF2:  return zAF2;\r
+       case CZ80_BC2:  return zBC2;\r
+       case CZ80_DE2:  return zDE2;\r
+       case CZ80_HL2:  return zHL2;\r
+       case CZ80_R:    return zR;\r
+       case CZ80_I:    return zI;\r
+       case CZ80_IM:   return zIM;\r
+       case CZ80_IFF1: return zIFF1;\r
+       case CZ80_IFF2: return zIFF2;\r
+       case CZ80_HALT: return CPU->HaltState;\r
+       case CZ80_IRQ:  return CPU->IRQState;\r
+       default: return 0;\r
+       }\r
+}\r
+\r
+\r
+/*--------------------------------------------------------\r
+       \83\8c\83W\83X\83^\90Ý\92è\r
+--------------------------------------------------------*/\r
+\r
+void Cz80_Set_Reg(cz80_struc *CPU, INT32 regnum, UINT32 val)\r
+{\r
+       switch (regnum)\r
+       {\r
+       case CZ80_PC:\r
+               CPU->BasePC = CPU->Fetch[val >> CZ80_FETCH_SFT];\r
+#if CZ80_ENCRYPTED_ROM\r
+               CPU->OPBase = CPU->OPFetch[val >> CZ80_FETCH_SFT];\r
+#endif\r
+               CPU->PC = val + CPU->BasePC;\r
+               break;\r
+\r
+       case CZ80_SP:   zSP = val; break;\r
+       case CZ80_AF:   zAF = val; break;\r
+       case CZ80_BC:   zBC = val; break;\r
+       case CZ80_DE:   zDE = val; break;\r
+       case CZ80_HL:   zHL = val; break;\r
+       case CZ80_IX:   zIX = val; break;\r
+       case CZ80_IY:   zIY = val; break;\r
+       case CZ80_AF2:  zAF2 = val; break;\r
+       case CZ80_BC2:  zBC2 = val; break;\r
+       case CZ80_DE2:  zDE2 = val; break;\r
+       case CZ80_HL2:  zHL2 = val; break;\r
+       case CZ80_R:    zR = val; break;\r
+       case CZ80_I:    zI = val; break;\r
+       case CZ80_IM:   zIM = val; break;\r
+       case CZ80_IFF1: zIFF1 = val; break;\r
+       case CZ80_IFF2: zIFF2 = val; break;\r
+       case CZ80_HALT: CPU->HaltState = val; break;\r
+       case CZ80_IRQ:  CPU->IRQState = val; break;\r
+       default: break;\r
+       }\r
+}\r
+\r
+\r
+/*--------------------------------------------------------\r
+       \83t\83F\83b\83`\83A\83h\83\8c\83X\90Ý\92è\r
+--------------------------------------------------------*/\r
+\r
+void Cz80_Set_Fetch(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 fetch_adr)\r
+{\r
+       int i, j;\r
+\r
+       i = low_adr >> CZ80_FETCH_SFT;\r
+       j = high_adr >> CZ80_FETCH_SFT;\r
+       fetch_adr -= i << CZ80_FETCH_SFT;\r
+\r
+       while (i <= j)\r
+       {\r
+               CPU->Fetch[i] = fetch_adr;\r
+#if CZ80_ENCRYPTED_ROM\r
+               CPU->OPFetch[i] = 0;\r
+#endif\r
+               i++;\r
+       }\r
+}\r
+\r
+\r
+/*--------------------------------------------------------\r
+       \83t\83F\83b\83`\83A\83h\83\8c\83X\90Ý\92è (\88Ã\8d\86\89»ROM\91Î\89\9e)\r
+--------------------------------------------------------*/\r
+\r
+#if CZ80_ENCRYPTED_ROM\r
+void Cz80_Set_Encrypt_Range(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 decrypted_rom)\r
+{\r
+       int i, j;\r
+\r
+       i = low_adr >> CZ80_FETCH_SFT;\r
+       j = high_adr >> CZ80_FETCH_SFT;\r
+       decrypted_rom -= i << CZ80_FETCH_SFT;\r
+\r
+       while (i <= j)\r
+       {\r
+               CPU->OPFetch[i] = (INT32)decrypted_rom - (INT32)CPU->Fetch[i];\r
+               i++;\r
+       }\r
+}\r
+#endif\r
+\r
+\r
+/*--------------------------------------------------------\r
+       \83\81\83\82\83\8a\83\8a\81[\83h/\83\89\83C\83g\8aÖ\90\94\90Ý\92è\r
+--------------------------------------------------------*/\r
+\r
+void Cz80_Set_ReadB(cz80_struc *CPU, UINT8 (*Func)(UINT32 address))\r
+{\r
+       CPU->Read_Byte = Func;\r
+}\r
+\r
+void Cz80_Set_WriteB(cz80_struc *CPU, void (*Func)(UINT32 address, UINT8 data))\r
+{\r
+       CPU->Write_Byte = Func;\r
+}\r
+\r
+\r
+/*--------------------------------------------------------\r
+       \83|\81[\83g\83\8a\81[\83h/\83\89\83C\83g\8aÖ\90\94\90Ý\92è\r
+--------------------------------------------------------*/\r
+\r
+void Cz80_Set_INPort(cz80_struc *CPU, UINT8 (*Func)(UINT16 port))\r
+{\r
+       CPU->IN_Port = Func;\r
+}\r
+\r
+void Cz80_Set_OUTPort(cz80_struc *CPU, void (*Func)(UINT16 port, UINT8 value))\r
+{\r
+       CPU->OUT_Port = Func;\r
+}\r
+\r
+\r
+/*--------------------------------------------------------\r
+       \83R\81[\83\8b\83o\83b\83N\8aÖ\90\94\90Ý\92è\r
+--------------------------------------------------------*/\r
+\r
+void Cz80_Set_IRQ_Callback(cz80_struc *CPU, INT32 (*Func)(INT32 irqline))\r
+{\r
+       CPU->Interrupt_Callback = Func;\r
+}\r
diff --git a/cpu/cz80/cz80.h b/cpu/cz80/cz80.h
new file mode 100644 (file)
index 0000000..a5da31d
--- /dev/null
@@ -0,0 +1,303 @@
+/******************************************************************************\r
+ *\r
+ * CZ80 (Z80 CPU emulator) version 0.9\r
+ * Compiled with Dev-C++\r
+ * Copyright 2004-2005 Stéphane Dallongeville\r
+ *\r
+ * (Modified by NJ)\r
+ *\r
+ *****************************************************************************/\r
+\r
+#ifndef CZ80_H\r
+#define CZ80_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/******************************/\r
+/* Compiler dependant defines */\r
+/******************************/\r
+\r
+#ifndef UINT8\r
+#define UINT8  unsigned char\r
+#endif\r
+\r
+#ifndef INT8\r
+#define INT8   char\r
+#endif\r
+\r
+#ifndef UINT16\r
+#define UINT16 unsigned short\r
+#endif\r
+\r
+#ifndef INT16\r
+#define INT16  short\r
+#endif\r
+\r
+#ifndef UINT32\r
+#define UINT32 unsigned int\r
+#endif\r
+\r
+#ifndef INT32\r
+#define INT32  int\r
+#endif\r
+\r
+/*************************************/\r
+/* Z80 core Structures & definitions */\r
+/*************************************/\r
+\r
+#define CZ80_FETCH_BITS                        4   // [4-12]   default = 8\r
+\r
+#define CZ80_FETCH_SFT                 (16 - CZ80_FETCH_BITS)\r
+#define CZ80_FETCH_BANK                        (1 << CZ80_FETCH_BITS)\r
+\r
+#define CZ80_LITTLE_ENDIAN             1\r
+#define CZ80_USE_JUMPTABLE             1\r
+#define CZ80_BIG_FLAGS_ARRAY   1\r
+//#ifdef BUILD_CPS1PSP\r
+//#define CZ80_ENCRYPTED_ROM           1\r
+//#else\r
+#define CZ80_ENCRYPTED_ROM             0\r
+//#endif\r
+#define CZ80_EMULATE_R_EXACTLY 0\r
+\r
+#define zR8(A)         (*CPU->pzR8[A])\r
+#define zR16(A)                (CPU->pzR16[A]->W)\r
+\r
+#define pzAF           &(CPU->AF)\r
+#define zAF                    CPU->AF.W\r
+#define zlAF           CPU->AF.B.L\r
+#define zhAF           CPU->AF.B.H\r
+#define zA                     zhAF\r
+#define zF                     zlAF\r
+\r
+#define pzBC           &(CPU->BC)\r
+#define zBC                    CPU->BC.W\r
+#define zlBC           CPU->BC.B.L\r
+#define zhBC           CPU->BC.B.H\r
+#define zB                     zhBC\r
+#define zC                     zlBC\r
+\r
+#define pzDE           &(CPU->DE)\r
+#define zDE                    CPU->DE.W\r
+#define zlDE           CPU->DE.B.L\r
+#define zhDE           CPU->DE.B.H\r
+#define zD                     zhDE\r
+#define zE                     zlDE\r
+\r
+#define pzHL           &(CPU->HL)\r
+#define zHL                    CPU->HL.W\r
+#define zlHL           CPU->HL.B.L\r
+#define zhHL           CPU->HL.B.H\r
+#define zH                     zhHL\r
+#define zL                     zlHL\r
+\r
+#define zAF2           CPU->AF2.W\r
+#define zlAF2          CPU->AF2.B.L\r
+#define zhAF2          CPU->AF2.B.H\r
+#define zA2                    zhAF2\r
+#define zF2                    zlAF2\r
+\r
+#define zBC2           CPU->BC2.W\r
+#define zDE2           CPU->DE2.W\r
+#define zHL2           CPU->HL2.W\r
+\r
+#define pzIX           &(CPU->IX)\r
+#define zIX                    CPU->IX.W\r
+#define zlIX           CPU->IX.B.L\r
+#define zhIX           CPU->IX.B.H\r
+\r
+#define pzIY           &(CPU->IY)\r
+#define zIY                    CPU->IY.W\r
+#define zlIY           CPU->IY.B.L\r
+#define zhIY           CPU->IY.B.H\r
+\r
+#define pzSP           &(CPU->SP)\r
+#define zSP                    CPU->SP.W\r
+#define zlSP           CPU->SP.B.L\r
+#define zhSP           CPU->SP.B.H\r
+\r
+#define zRealPC                (PC - CPU->BasePC)\r
+#define zPC                    PC\r
+\r
+#define zI                     CPU->I\r
+#define zIM                    CPU->IM\r
+\r
+#define zwR                    CPU->R.W\r
+#define zR1                    CPU->R.B.L\r
+#define zR2                    CPU->R.B.H\r
+#define zR                     zR1\r
+\r
+#define zIFF           CPU->IFF.W\r
+#define zIFF1          CPU->IFF.B.L\r
+#define zIFF2          CPU->IFF.B.H\r
+\r
+#define CZ80_SF_SFT     7\r
+#define CZ80_ZF_SFT     6\r
+#define CZ80_YF_SFT     5\r
+#define CZ80_HF_SFT     4\r
+#define CZ80_XF_SFT     3\r
+#define CZ80_PF_SFT     2\r
+#define CZ80_VF_SFT     2\r
+#define CZ80_NF_SFT     1\r
+#define CZ80_CF_SFT     0\r
+\r
+#define CZ80_SF                (1 << CZ80_SF_SFT)\r
+#define CZ80_ZF                (1 << CZ80_ZF_SFT)\r
+#define CZ80_YF                (1 << CZ80_YF_SFT)\r
+#define CZ80_HF                (1 << CZ80_HF_SFT)\r
+#define CZ80_XF                (1 << CZ80_XF_SFT)\r
+#define CZ80_PF                (1 << CZ80_PF_SFT)\r
+#define CZ80_VF                (1 << CZ80_VF_SFT)\r
+#define CZ80_NF                (1 << CZ80_NF_SFT)\r
+#define CZ80_CF                (1 << CZ80_CF_SFT)\r
+\r
+#define CZ80_IFF_SFT   CZ80_PF_SFT\r
+#define CZ80_IFF               CZ80_PF\r
+\r
+#ifndef IRQ_LINE_STATE\r
+#define IRQ_LINE_STATE\r
+#define CLEAR_LINE             0               /* clear (a fired, held or pulsed) line */\r
+#define ASSERT_LINE            1               /* assert an interrupt immediately */\r
+#define HOLD_LINE              2               /* hold interrupt line until acknowledged */\r
+#define PULSE_LINE             3               /* pulse interrupt line for one instruction */\r
+#define IRQ_LINE_NMI   127             /* IRQ line for NMIs */\r
+#endif\r
+\r
+enum\r
+{\r
+       CZ80_PC = 1,\r
+       CZ80_SP,\r
+       CZ80_AF,\r
+       CZ80_BC,\r
+       CZ80_DE,\r
+       CZ80_HL,\r
+       CZ80_IX,\r
+       CZ80_IY,\r
+       CZ80_AF2,\r
+       CZ80_BC2,\r
+       CZ80_DE2,\r
+       CZ80_HL2,\r
+       CZ80_R,\r
+       CZ80_I,\r
+       CZ80_IM,\r
+       CZ80_IFF1,\r
+       CZ80_IFF2,\r
+       CZ80_HALT,\r
+       CZ80_IRQ\r
+};\r
+\r
+typedef union\r
+{\r
+       struct\r
+       {\r
+#if CZ80_LITTLE_ENDIAN\r
+               UINT8 L;\r
+               UINT8 H;\r
+#else\r
+               UINT8 H;\r
+               UINT8 L;\r
+#endif\r
+       } B;\r
+       UINT16 W;\r
+} union16;\r
+\r
+typedef struct cz80_t\r
+{\r
+       union\r
+       {\r
+               UINT8 r8[8];\r
+               union16 r16[4];\r
+               struct\r
+               {\r
+                       union16 BC;\r
+                       union16 DE;\r
+                       union16 HL;\r
+                       union16 AF;\r
+               };\r
+       };\r
+\r
+       union16 IX;\r
+       union16 IY;\r
+       union16 SP;\r
+       UINT32 PC;\r
+\r
+       union16 BC2;\r
+       union16 DE2;\r
+       union16 HL2;\r
+       union16 AF2;\r
+\r
+       union16 R;\r
+       union16 IFF;\r
+\r
+       UINT8 I;\r
+       UINT8 IM;\r
+       UINT8 HaltState;\r
+       UINT8 dummy;\r
+\r
+       INT32 IRQLine;\r
+       INT32 IRQState;\r
+       INT32 ICount;\r
+       INT32 ExtraCycles;\r
+\r
+       UINT32 BasePC;\r
+       UINT32 Fetch[CZ80_FETCH_BANK];\r
+#if CZ80_ENCRYPTED_ROM\r
+       INT32 OPBase;\r
+       INT32 OPFetch[CZ80_FETCH_BANK];\r
+#endif\r
+\r
+       UINT8 *pzR8[8];\r
+       union16 *pzR16[4];\r
+\r
+       UINT8   (*Read_Byte)(UINT32 address);\r
+       void (*Write_Byte)(UINT32 address, UINT8 data);\r
+\r
+       UINT8   (*IN_Port)(UINT16 port);\r
+       void (*OUT_Port)(UINT16 port, UINT8 value);\r
+\r
+       INT32  (*Interrupt_Callback)(INT32 irqline);\r
+\r
+} cz80_struc;\r
+\r
+\r
+/*************************/\r
+/* Publics Z80 variables */\r
+/*************************/\r
+\r
+extern cz80_struc CZ80;\r
+\r
+/*************************/\r
+/* Publics Z80 functions */\r
+/*************************/\r
+\r
+void Cz80_Init(cz80_struc *CPU);\r
+\r
+void Cz80_Reset(cz80_struc *CPU);\r
+\r
+INT32  Cz80_Exec(cz80_struc *CPU, INT32 cycles);\r
+\r
+void Cz80_Set_IRQ(cz80_struc *CPU, INT32 line, INT32 state);\r
+\r
+UINT32  Cz80_Get_Reg(cz80_struc *CPU, INT32 regnum);\r
+void Cz80_Set_Reg(cz80_struc *CPU, INT32 regnum, UINT32 value);\r
+\r
+void Cz80_Set_Fetch(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 fetch_adr);\r
+#if CZ80_ENCRYPTED_ROM\r
+void Cz80_Set_Encrypt_Range(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 decrypted_rom);\r
+#endif\r
+\r
+void Cz80_Set_ReadB(cz80_struc *CPU, UINT8 (*Func)(UINT32 address));\r
+void Cz80_Set_WriteB(cz80_struc *CPU, void (*Func)(UINT32 address, UINT8 data));\r
+\r
+void Cz80_Set_INPort(cz80_struc *CPU, UINT8 (*Func)(UINT16 port));\r
+void Cz80_Set_OUTPort(cz80_struc *CPU, void (*Func)(UINT16 port, UINT8 value));\r
+\r
+void Cz80_Set_IRQ_Callback(cz80_struc *CPU, INT32 (*Func)(INT32 irqline));\r
+\r
+#ifdef __cplusplus\r
+};\r
+#endif\r
+\r
+#endif /* CZ80_H */\r
diff --git a/cpu/cz80/cz80_op.c b/cpu/cz80/cz80_op.c
new file mode 100644 (file)
index 0000000..ed13c9e
--- /dev/null
@@ -0,0 +1,1145 @@
+/******************************************************************************\r
+ *\r
+ * CZ80 opcode include source file\r
+ * CZ80 emulator version 0.9\r
+ * Copyright 2004-2005 Stéphane Dallongeville\r
+ *\r
+ * (Modified by NJ)\r
+ *\r
+ *****************************************************************************/\r
+\r
+#if CZ80_USE_JUMPTABLE\r
+       goto *JumpTable[Opcode];\r
+#else\r
+switch (Opcode)\r
+{\r
+#endif\r
+\r
+/*-----------------------------------------\r
+ NOP\r
+-----------------------------------------*/\r
+\r
+       OP(0x00):   // NOP\r
+\r
+/*-----------------------------------------\r
+ LD r8 (same register)\r
+-----------------------------------------*/\r
+\r
+       OP(0x40):   // LD   B,B\r
+       OP(0x49):   // LD   C,C\r
+       OP(0x52):   // LD   D,D\r
+       OP(0x5b):   // LD   E,E\r
+       OP(0x64):   // LD   H,H\r
+       OP(0x6d):   // LD   L,L\r
+       OP(0x7f):   // LD   A,A\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ LD r8\r
+-----------------------------------------*/\r
+\r
+       OP(0x41):   // LD   B,C\r
+       OP(0x42):   // LD   B,D\r
+       OP(0x43):   // LD   B,E\r
+       OP(0x44):   // LD   B,H\r
+       OP(0x45):   // LD   B,L\r
+       OP(0x47):   // LD   B,A\r
+\r
+       OP(0x48):   // LD   C,B\r
+       OP(0x4a):   // LD   C,D\r
+       OP(0x4b):   // LD   C,E\r
+       OP(0x4c):   // LD   C,H\r
+       OP(0x4d):   // LD   C,L\r
+       OP(0x4f):   // LD   C,A\r
+\r
+       OP(0x50):   // LD   D,B\r
+       OP(0x51):   // LD   D,C\r
+       OP(0x53):   // LD   D,E\r
+       OP(0x54):   // LD   D,H\r
+       OP(0x55):   // LD   D,L\r
+       OP(0x57):   // LD   D,A\r
+\r
+       OP(0x58):   // LD   E,B\r
+       OP(0x59):   // LD   E,C\r
+       OP(0x5a):   // LD   E,D\r
+       OP(0x5c):   // LD   E,H\r
+       OP(0x5d):   // LD   E,L\r
+       OP(0x5f):   // LD   E,A\r
+\r
+       OP(0x60):   // LD   H,B\r
+       OP(0x61):   // LD   H,C\r
+       OP(0x62):   // LD   H,D\r
+       OP(0x63):   // LD   H,E\r
+       OP(0x65):   // LD   H,L\r
+       OP(0x67):   // LD   H,A\r
+\r
+       OP(0x68):   // LD   L,B\r
+       OP(0x69):   // LD   L,C\r
+       OP(0x6a):   // LD   L,D\r
+       OP(0x6b):   // LD   L,E\r
+       OP(0x6c):   // LD   L,H\r
+       OP(0x6f):   // LD   L,A\r
+\r
+       OP(0x78):   // LD   A,B\r
+       OP(0x79):   // LD   A,C\r
+       OP(0x7a):   // LD   A,D\r
+       OP(0x7b):   // LD   A,E\r
+       OP(0x7c):   // LD   A,H\r
+       OP(0x7d):   // LD   A,L\r
+OP_LD_R_R:\r
+               zR8((Opcode >> 3) & 7) = zR8(Opcode & 7);\r
+               RET(4)\r
+\r
+       OP(0x06):   // LD   B,#imm\r
+       OP(0x0e):   // LD   C,#imm\r
+       OP(0x16):   // LD   D,#imm\r
+       OP(0x1e):   // LD   E,#imm\r
+       OP(0x26):   // LD   H,#imm\r
+       OP(0x2e):   // LD   L,#imm\r
+       OP(0x3e):   // LD   A,#imm\r
+OP_LD_R_imm:\r
+               zR8(Opcode >> 3) = READ_ARG();\r
+               RET(7)\r
+\r
+       OP(0x46):   // LD   B,(HL)\r
+       OP(0x4e):   // LD   C,(HL)\r
+       OP(0x56):   // LD   D,(HL)\r
+       OP(0x5e):   // LD   E,(HL)\r
+       OP(0x66):   // LD   H,(HL)\r
+       OP(0x6e):   // LD   L,(HL)\r
+       OP(0x7e):   // LD   A,(HL)\r
+               zR8((Opcode >> 3) & 7) = READ_MEM8(zHL);\r
+               RET(7)\r
+\r
+       OP(0x70):   // LD   (HL),B\r
+       OP(0x71):   // LD   (HL),C\r
+       OP(0x72):   // LD   (HL),D\r
+       OP(0x73):   // LD   (HL),E\r
+       OP(0x74):   // LD   (HL),H\r
+       OP(0x75):   // LD   (HL),L\r
+       OP(0x77):   // LD   (HL),A\r
+               WRITE_MEM8(zHL, zR8(Opcode & 7));\r
+               RET(7)\r
+\r
+       OP(0x36):   // LD (HL), #imm\r
+               WRITE_MEM8(zHL, READ_ARG());\r
+               RET(10)\r
+\r
+       OP(0x0a):   // LD   A,(BC)\r
+OP_LOAD_A_mBC:\r
+               adr = zBC;\r
+               goto OP_LOAD_A_mxx;\r
+\r
+       OP(0x1a):   // LD   A,(DE)\r
+OP_LOAD_A_mDE:\r
+               adr = zDE;\r
+\r
+OP_LOAD_A_mxx:\r
+               zA = READ_MEM8(adr);\r
+               RET(7)\r
+\r
+       OP(0x3a):   // LD   A,(nn)\r
+OP_LOAD_A_mNN:\r
+               adr = READ_ARG16();\r
+               zA = READ_MEM8(adr);\r
+               RET(13)\r
+\r
+       OP(0x02):   // LD   (BC),A\r
+OP_LOAD_mBC_A:\r
+               adr = zBC;\r
+               goto OP_LOAD_mxx_A;\r
+\r
+       OP(0x12):   // LD   (DE),A\r
+OP_LOAD_mDE_A:\r
+               adr = zDE;\r
+\r
+OP_LOAD_mxx_A:\r
+               WRITE_MEM8(adr, zA);\r
+               RET(7)\r
+\r
+       OP(0x32):   // LD   (nn),A\r
+OP_LOAD_mNN_A:\r
+               adr = READ_ARG16();\r
+               WRITE_MEM8(adr, zA);\r
+               RET(13)\r
+\r
+/*-----------------------------------------\r
+ LD r16\r
+-----------------------------------------*/\r
+\r
+       OP(0x01):   // LD   BC,nn\r
+       OP(0x11):   // LD   DE,nn\r
+       OP(0x21):   // LD   HL,nn\r
+OP_LOAD_RR_imm16:\r
+               zR16(Opcode >> 4) = READ_ARG16();\r
+               RET(10)\r
+\r
+       OP(0x31):   // LD   SP,nn\r
+OP_LOAD_SP_imm16:\r
+               zSP = READ_ARG16();\r
+               RET(10)\r
+\r
+       OP(0xf9):   // LD   SP,HL\r
+OP_LD_SP_xx:\r
+               zSP = data->W;\r
+               RET(6)\r
+\r
+       OP(0x2a):   // LD   HL,(nn)\r
+OP_LD_xx_mNN:\r
+               adr = READ_ARG16();\r
+               data->W = READ_MEM16(adr);\r
+               RET(16)\r
+\r
+       OP(0x22):   // LD   (nn),HL\r
+OP_LD_mNN_xx:\r
+               adr = READ_ARG16();\r
+               WRITE_MEM16(adr, data->W);\r
+               RET(16)\r
+\r
+/*-----------------------------------------\r
+ POP\r
+-----------------------------------------*/\r
+\r
+       OP(0xc1):   // POP  BC\r
+       OP(0xd1):   // POP  DE\r
+       OP(0xf1):   // POP  AF\r
+OP_POP_RR:\r
+               data = CPU->pzR16[(Opcode >> 4) & 3];\r
+\r
+       OP(0xe1):   // POP  HL\r
+OP_POP:\r
+               POP_16(data->W)\r
+               RET(10)\r
+\r
+/*-----------------------------------------\r
+ PUSH\r
+-----------------------------------------*/\r
+\r
+       OP(0xc5):   // PUSH BC\r
+       OP(0xd5):   // PUSH DE\r
+       OP(0xf5):   // PUSH AF\r
+OP_PUSH_RR:\r
+               data = CPU->pzR16[(Opcode >> 4) & 3];\r
+\r
+       OP(0xe5):   // PUSH HL\r
+OP_PUSH:\r
+               PUSH_16(data->W);\r
+               RET(11)\r
+\r
+/*-----------------------------------------\r
+ EX\r
+-----------------------------------------*/\r
+\r
+       OP(0x08):   // EX   AF,AF'\r
+OP_EX_AF_AF2:\r
+               res = zAF;\r
+               zAF = zAF2;\r
+               zAF2 = res;\r
+               RET(4)\r
+\r
+       OP(0xeb):   // EX   DE,HL\r
+OP_EX_DE_HL:\r
+               res = zDE;\r
+               zDE = zHL;\r
+               zHL = res;\r
+               RET(4)\r
+\r
+       OP(0xd9):   // EXX\r
+OP_EXX:\r
+               res = zBC;\r
+               zBC = zBC2;\r
+               zBC2 = res;\r
+               res = zDE;\r
+               zDE = zDE2;\r
+               zDE2 = res;\r
+               res = zHL;\r
+               zHL = zHL2;\r
+               zHL2 = res;\r
+               RET(4)\r
+\r
+       OP(0xe3):   // EX   HL,(SP)\r
+OP_EX_xx_mSP:\r
+               adr = zSP;\r
+               res = data->W;\r
+               data->W = READ_MEM16(adr);\r
+               WRITE_MEM16(adr, res);\r
+               RET(19)\r
+\r
+/*-----------------------------------------\r
+ INC r8\r
+-----------------------------------------*/\r
+\r
+       OP(0x04):   // INC  B\r
+       OP(0x0c):   // INC  C\r
+       OP(0x14):   // INC  D\r
+       OP(0x1c):   // INC  E\r
+       OP(0x24):   // INC  H\r
+       OP(0x2c):   // INC  L\r
+       OP(0x3c):   // INC  A\r
+OP_INC_R:\r
+               zR8(Opcode >> 3)++;\r
+               zF = (zF & CF) | SZHV_inc[zR8(Opcode >> 3)];\r
+               RET(4)\r
+\r
+       OP(0x34):   // INC  (HL)\r
+               adr = zHL;\r
+\r
+OP_INC_m:\r
+               res = READ_MEM8(adr);\r
+               res = (res + 1) & 0xff;\r
+               zF = (zF & CF) | SZHV_inc[res];\r
+               WRITE_MEM8(adr, res);\r
+               RET(11)\r
+\r
+/*-----------------------------------------\r
+ DEC r8\r
+-----------------------------------------*/\r
+\r
+       OP(0x05):   // DEC  B\r
+       OP(0x0d):   // DEC  C\r
+       OP(0x15):   // DEC  D\r
+       OP(0x1d):   // DEC  E\r
+       OP(0x25):   // DEC  H\r
+       OP(0x2d):   // DEC  L\r
+       OP(0x3d):   // DEC  A\r
+OP_DEC_R:\r
+               zR8(Opcode >> 3)--;\r
+               zF = (zF & CF) | SZHV_dec[zR8(Opcode >> 3)];\r
+               RET(4)\r
+\r
+       OP(0x35):   // DEC  (HL)\r
+               adr = zHL;\r
+\r
+OP_DEC_m:\r
+               res = READ_MEM8(adr);\r
+               res = (res - 1) & 0xff;\r
+               zF = (zF & CF) | SZHV_dec[res];\r
+               WRITE_MEM8(adr, res);\r
+               RET(11)\r
+\r
+/*-----------------------------------------\r
+ ADD r8\r
+-----------------------------------------*/\r
+\r
+       OP(0x86):   // ADD  A,(HL)\r
+               val = READ_MEM8(zHL);\r
+               USE_CYCLES(3)\r
+               goto OP_ADD;\r
+\r
+       OP(0xc6):   // ADD  A,n\r
+OP_ADD_imm:\r
+               val = READ_ARG();\r
+               USE_CYCLES(3)\r
+               goto OP_ADD;\r
+\r
+       OP(0x80):   // ADD  A,B\r
+       OP(0x81):   // ADD  A,C\r
+       OP(0x82):   // ADD  A,D\r
+       OP(0x83):   // ADD  A,E\r
+       OP(0x84):   // ADD  A,H\r
+       OP(0x85):   // ADD  A,L\r
+       OP(0x87):   // ADD  A,A\r
+OP_ADD_R:\r
+               val = zR8(Opcode & 7);\r
+\r
+OP_ADD:\r
+#if CZ80_BIG_FLAGS_ARRAY\r
+               {\r
+                       UINT16 A = zA;\r
+                       res = (UINT8)(A + val);\r
+                       zF = SZHVC_add[(A << 8) | res];\r
+                       zA = res;\r
+               }\r
+#else\r
+               res = zA + val;\r
+               zF = SZ[(UINT8)res] | ((res >> 8) & CF) |\r
+                       ((zA ^ res ^ val) & HF) |\r
+                       (((val ^ zA ^ 0x80) & (val ^ res) & 0x80) >> 5);\r
+               zA = res;\r
+#endif\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ ADC r8\r
+-----------------------------------------*/\r
+\r
+       OP(0x8e):   // ADC  A,(HL)\r
+               val = READ_MEM8(zHL);\r
+               USE_CYCLES(3)\r
+               goto OP_ADC;\r
+\r
+       OP(0xce):   // ADC  A,n\r
+OP_ADC_imm:\r
+               val = READ_ARG();\r
+               USE_CYCLES(3)\r
+               goto OP_ADC;\r
+\r
+       OP(0x88):   // ADC  A,B\r
+       OP(0x89):   // ADC  A,C\r
+       OP(0x8a):   // ADC  A,D\r
+       OP(0x8b):   // ADC  A,E\r
+       OP(0x8c):   // ADC  A,H\r
+       OP(0x8d):   // ADC  A,L\r
+       OP(0x8f):   // ADC  A,A\r
+OP_ADC_R:\r
+               val = zR8(Opcode & 7);\r
+\r
+OP_ADC:\r
+#if CZ80_BIG_FLAGS_ARRAY\r
+               {\r
+                       UINT8 A = zA;\r
+                       UINT8 c = zF & CF;\r
+                       res = (UINT8)(A + val + c);\r
+                       zF = SZHVC_add[(c << 16) | (A << 8) | res];\r
+                       zA = res;\r
+               }\r
+#else\r
+               res = zA + val + (zF & CF);\r
+               zF = SZ[res & 0xff] | ((res >> 8) & CF) |\r
+                       ((zA ^ res ^ val) & HF) |\r
+                       (((val ^ zA ^ 0x80) & (val ^ res) & 0x80) >> 5);\r
+               zA = res;\r
+#endif\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ SUB r8\r
+-----------------------------------------*/\r
+\r
+       OP(0x96):   // SUB  (HL)\r
+               val = READ_MEM8(zHL);\r
+               USE_CYCLES(3)\r
+               goto OP_SUB;\r
+\r
+       OP(0xd6):   // SUB  A,n\r
+OP_SUB_imm:\r
+               val = READ_ARG();\r
+               USE_CYCLES(3)\r
+               goto OP_SUB;\r
+\r
+       OP(0x90):   // SUB  B\r
+       OP(0x91):   // SUB  C\r
+       OP(0x92):   // SUB  D\r
+       OP(0x93):   // SUB  E\r
+       OP(0x94):   // SUB  H\r
+       OP(0x95):   // SUB  L\r
+       OP(0x97):   // SUB  A\r
+OP_SUB_R:\r
+               val = zR8(Opcode & 7);\r
+\r
+OP_SUB:\r
+#if CZ80_BIG_FLAGS_ARRAY\r
+               {\r
+                       UINT8 A = zA;\r
+                       res = (UINT8)(A - val);\r
+                       zF = SZHVC_sub[(A << 8) | res];\r
+                       zA = res;\r
+               }\r
+#else\r
+               res = zA - val;\r
+               zF = SZ[res & 0xff] | ((res >> 8) & CF) | NF |\r
+                       ((zA ^ res ^ val) & HF) |\r
+                       (((val ^ zA) & (zA ^ res) & 0x80) >> 5);\r
+               zA = res;\r
+#endif\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ SBC r8\r
+-----------------------------------------*/\r
+\r
+       OP(0x9e):   // SBC  A,(HL)\r
+               val = READ_MEM8(zHL);\r
+               USE_CYCLES(3)\r
+               goto OP_SBC;\r
+\r
+       OP(0xde):   // SBC  A,n\r
+OP_SBC_imm:\r
+               val = READ_ARG();\r
+               USE_CYCLES(3)\r
+               goto OP_SBC;\r
+\r
+       OP(0x98):   // SBC  A,B\r
+       OP(0x99):   // SBC  A,C\r
+       OP(0x9a):   // SBC  A,D\r
+       OP(0x9b):   // SBC  A,E\r
+       OP(0x9c):   // SBC  A,H\r
+       OP(0x9d):   // SBC  A,L\r
+       OP(0x9f):   // SBC  A,A\r
+OP_SBC_R:\r
+               val = zR8(Opcode & 7);\r
+\r
+OP_SBC:\r
+#if CZ80_BIG_FLAGS_ARRAY\r
+               {\r
+                       UINT8 A = zA;\r
+                       UINT8 c = zF & CF;\r
+                       res = (UINT8)(A - val - c);\r
+                       zF = SZHVC_sub[(c << 16) | (A << 8) | res];\r
+                       zA = res;\r
+               }\r
+#else\r
+               res = zA - val - (zF & CF);\r
+               zF = SZ[res & 0xff] | ((res >> 8) & CF) | NF |\r
+                       ((zA ^ res ^ val) & HF) |\r
+                       (((val ^ zA) & (zA ^ res) & 0x80) >> 5);\r
+               zA = res;\r
+#endif\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ CP r8\r
+-----------------------------------------*/\r
+\r
+       OP(0xbe):   // CP   (HL)\r
+               val = READ_MEM8(zHL);\r
+               USE_CYCLES(3)\r
+               goto OP_CP;\r
+\r
+       OP(0xfe):   // CP   n\r
+OP_CP_imm:\r
+               val = READ_ARG();\r
+               USE_CYCLES(3)\r
+               goto OP_CP;\r
+\r
+       OP(0xb8):   // CP   B\r
+       OP(0xb9):   // CP   C\r
+       OP(0xba):   // CP   D\r
+       OP(0xbb):   // CP   E\r
+       OP(0xbc):   // CP   H\r
+       OP(0xbd):   // CP   L\r
+       OP(0xbf):   // CP   A\r
+OP_CP_R:\r
+               val = zR8(Opcode & 7);\r
+\r
+OP_CP:\r
+#if CZ80_BIG_FLAGS_ARRAY\r
+               {\r
+                       UINT8 A = zA;\r
+                       res = (UINT8)(A - val);\r
+                       zF = (SZHVC_sub[(A << 8) | res] & ~(YF | XF)) |\r
+                                (val & (YF | XF));\r
+               }\r
+#else\r
+               res = zA - val;\r
+               zF = (SZ[res & 0xff] & (SF | ZF)) |\r
+                       (val & (YF | XF)) | ((res >> 8) & CF) | NF |\r
+                       ((zA ^ res ^ val) & HF) |\r
+                       (((val ^ zA) & (zA ^ res) >> 5) & VF);\r
+#endif\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ AND r8\r
+-----------------------------------------*/\r
+\r
+       OP(0xa6):   // AND  (HL)\r
+               val = READ_MEM8(zHL);\r
+               USE_CYCLES(3)\r
+               goto OP_AND;\r
+\r
+       OP(0xe6):   // AND  A,n\r
+OP_AND_imm:\r
+               val = READ_ARG();\r
+               USE_CYCLES(3)\r
+               goto OP_AND;\r
+\r
+       OP(0xa0):   // AND  B\r
+       OP(0xa1):   // AND  C\r
+       OP(0xa2):   // AND  D\r
+       OP(0xa3):   // AND  E\r
+       OP(0xa4):   // AND  H\r
+       OP(0xa5):   // AND  L\r
+       OP(0xa7):   // AND  A\r
+OP_AND_R:\r
+               val = zR8(Opcode & 7);\r
+\r
+OP_AND:\r
+               zA &= val;\r
+               zF = SZP[zA] | HF;\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ XOR r8\r
+-----------------------------------------*/\r
+\r
+       OP(0xae):   // XOR  (HL)\r
+               val = READ_MEM8(zHL);\r
+               USE_CYCLES(3)\r
+               goto OP_XOR;\r
+\r
+       OP(0xee):   // XOR  A,n\r
+OP_XOR_imm:\r
+               val = READ_ARG();\r
+               USE_CYCLES(3)\r
+               goto OP_XOR;\r
+\r
+       OP(0xa8):   // XOR  B\r
+       OP(0xa9):   // XOR  C\r
+       OP(0xaa):   // XOR  D\r
+       OP(0xab):   // XOR  E\r
+       OP(0xac):   // XOR  H\r
+       OP(0xad):   // XOR  L\r
+       OP(0xaf):   // XOR  A\r
+OP_XOR_R:\r
+               val = zR8(Opcode & 7);\r
+\r
+OP_XOR:\r
+               zA ^= val;\r
+               zF = SZP[zA];\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ OR r8\r
+-----------------------------------------*/\r
+\r
+       OP(0xb6):   // OR   (HL)\r
+               val = READ_MEM8(zHL);\r
+               USE_CYCLES(3)\r
+               goto OP_OR;\r
+\r
+       OP(0xf6):   // OR   A,n\r
+OP_OR_imm:\r
+               val = READ_ARG();\r
+               USE_CYCLES(3)\r
+               goto OP_OR;\r
+\r
+       OP(0xb0):   // OR   B\r
+       OP(0xb1):   // OR   C\r
+       OP(0xb2):   // OR   D\r
+       OP(0xb3):   // OR   E\r
+       OP(0xb4):   // OR   H\r
+       OP(0xb5):   // OR   L\r
+       OP(0xb7):   // OR   A\r
+OP_OR_R:\r
+               val = zR8(Opcode & 7);\r
+\r
+OP_OR:\r
+               zA |= val;\r
+               zF = SZP[zA];\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ MISC ARITHMETIC & CPU CONTROL\r
+-----------------------------------------*/\r
+\r
+       OP(0x27):   // DAA\r
+OP_DAA:\r
+       {\r
+               UINT8 F;\r
+               UINT8 cf, nf, hf, lo, hi, diff;\r
+\r
+               F = zF;\r
+               cf = F & CF;\r
+               nf = F & NF;\r
+               hf = F & HF;\r
+               lo = zA & 0x0f;\r
+               hi = zA >> 4;\r
+\r
+               if (cf)\r
+               {\r
+                       diff = (lo <= 9 && !hf) ? 0x60 : 0x66;\r
+               }\r
+               else\r
+               {\r
+                       if (lo >= 10)\r
+                       {\r
+                               diff = hi <= 8 ? 0x06 : 0x66;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (hi >= 10)\r
+                               {\r
+                                       diff = hf ? 0x66 : 0x60;\r
+                               }\r
+                               else\r
+                               {\r
+                                       diff = hf ? 0x06 : 0x00;\r
+                               }\r
+                       }\r
+               }\r
+               if (nf) zA -= diff;\r
+               else zA += diff;\r
+\r
+               F = SZP[zA] | (F & NF);\r
+               if (cf || (lo <= 9 ? hi >= 10 : hi >= 9)) F |= CF;\r
+               if (nf ? hf && lo <= 5 : lo >= 10) F |= HF;\r
+               zF = F;\r
+               RET(4)\r
+       }\r
+\r
+       OP(0x2f):   // CPL\r
+OP_CPL:\r
+               zA ^= 0xff;\r
+               zF = (zF & (SF | ZF | PF | CF)) | HF | NF | (zA & (YF | XF));\r
+               RET(4)\r
+\r
+       OP(0x37):   // SCF\r
+OP_SCF:\r
+               zF = (zF & (SF | ZF | PF)) | CF | (zA & (YF | XF));\r
+               RET(4)\r
+\r
+       OP(0x3f):   // CCF\r
+OP_CCF:\r
+               zF = ((zF & (SF | ZF | PF | CF)) | ((zF & CF) << 4) | (zA & (YF | XF))) ^ CF;\r
+               RET(4)\r
+\r
+       OP(0x76):   // HALT\r
+OP_HALT:\r
+               CPU->HaltState = 1;\r
+               CPU->ICount = 0;\r
+               goto Cz80_Check_Interrupt;\r
+\r
+       OP(0xf3):   // DI\r
+OP_DI:\r
+               zIFF = 0;\r
+               RET(4)\r
+\r
+       OP(0xfb):   // EI\r
+OP_EI:\r
+               USE_CYCLES(4)\r
+               if (!zIFF1)\r
+               {\r
+                       zIFF1 = zIFF2 = (1 << 2);\r
+                       while (GET_OP() == 0xfb)\r
+                       {\r
+                               USE_CYCLES(4)\r
+                               PC++;\r
+#if CZ80_EMULATE_R_EXACTLY\r
+                               zR++;\r
+#endif\r
+                       }\r
+                       if (CPU->IRQState)\r
+                       {\r
+                               afterEI = 1;\r
+                       }\r
+                       if (CPU->ICount <= 0)\r
+                       {\r
+                               CPU->ICount = 1;\r
+                       }\r
+               }\r
+               else zIFF2 = (1 << 2);\r
+               goto Cz80_Exec;\r
+\r
+/*-----------------------------------------\r
+ INC r16\r
+-----------------------------------------*/\r
+\r
+       OP(0x03):   // INC  BC\r
+OP_INC_BC:\r
+               zBC++;\r
+               RET(6)\r
+\r
+       OP(0x13):   // INC  DE\r
+OP_INC_DE:\r
+               zDE++;\r
+               RET(6)\r
+\r
+       OP(0x23):   // INC  HL\r
+OP_INC_xx:\r
+               data->W++;\r
+               RET(6)\r
+\r
+       OP(0x33):   // INC  SP\r
+OP_INC_SP:\r
+               zSP++;\r
+               RET(6)\r
+\r
+/*-----------------------------------------\r
+ DEC r16\r
+-----------------------------------------*/\r
+\r
+       OP(0x0b):   // DEC  BC\r
+OP_DEC_BC:\r
+               zBC--;\r
+               RET(6)\r
+\r
+       OP(0x1b):   // DEC  DE\r
+OP_DEC_DE:\r
+               zDE--;\r
+               RET(6)\r
+\r
+       OP(0x2b):   // DEC  HL\r
+OP_DEC_xx:\r
+               data->W--;\r
+               RET(6)\r
+\r
+       OP(0x3b):   // DEC  SP\r
+OP_DEC_SP:\r
+               zSP--;\r
+               RET(6)\r
+\r
+/*-----------------------------------------\r
+ ADD r16\r
+-----------------------------------------*/\r
+\r
+       OP(0x39):   // ADD  xx,SP\r
+OP_ADD16_xx_SP:\r
+               val = zSP;\r
+               goto OP_ADD16;\r
+\r
+       OP(0x29):   // ADD  xx,xx\r
+OP_ADD16_xx_xx:\r
+               val = data->W;\r
+               goto OP_ADD16;\r
+\r
+       OP(0x09):   // ADD  xx,BC\r
+OP_ADD16_xx_BC:\r
+               val = zBC;\r
+               goto OP_ADD16;\r
+\r
+       OP(0x19):   // ADD  xx,DE\r
+OP_ADD16_xx_DE:\r
+               val = zDE;\r
+\r
+OP_ADD16:\r
+               res = data->W + val;\r
+               zF = (zF & (SF | ZF | VF)) |\r
+                       (((data->W ^ res ^ val) >> 8) & HF) |\r
+                       ((res >> 16) & CF) | ((res >> 8) & (YF | XF));\r
+               data->W = (UINT16)res;\r
+               RET(11)\r
+\r
+/*-----------------------------------------\r
+ ROTATE\r
+-----------------------------------------*/\r
+\r
+       {\r
+               UINT8 A;\r
+               UINT8 F;\r
+\r
+       OP(0x07):   // RLCA\r
+OP_RLCA:\r
+               A = zA;\r
+               zA = (A << 1) | (A >> 7);\r
+               zF = (zF & (SF | ZF | PF)) | (zA & (YF | XF | CF));\r
+               RET(4)\r
+\r
+       OP(0x0f):   // RRCA\r
+OP_RRCA:\r
+               A = zA;\r
+               F = zF;\r
+               F = (F & (SF | ZF | PF)) | (A & CF);\r
+               zA = (A >> 1) | (A << 7);\r
+               zF = F | (zA & (YF | XF));\r
+               RET(4)\r
+\r
+       OP(0x17):   // RLA\r
+OP_RLA:\r
+               A = zA;\r
+               F = zF;\r
+               zA = (A << 1) | (F & CF);\r
+               zF = (F & (SF | ZF | PF)) | (A >> 7) | (zA & (YF | XF));\r
+               RET(4)\r
+\r
+       OP(0x1f):   // RRA\r
+OP_RRA:\r
+               A = zA;\r
+               F = zF;\r
+               zA = (A >> 1) | (F << 7);\r
+               zF = (F & (SF | ZF | PF)) | (A & CF) | (zA & (YF | XF));\r
+               RET(4)\r
+       }\r
+\r
+/*-----------------------------------------\r
+ JP\r
+-----------------------------------------*/\r
+\r
+       OP(0xc3):   // JP   nn\r
+OP_JP:\r
+               res = READ_ARG16();\r
+               SET_PC(res);\r
+               RET(10)\r
+\r
+       OP(0xc2):   // JP   NZ,nn\r
+OP_JP_NZ:\r
+               if (!(zF & ZF)) goto OP_JP;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xca):   // JP   Z,nn\r
+OP_JP_Z:\r
+               if (zF & ZF) goto OP_JP;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xd2):   // JP   NC,nn\r
+OP_JP_NC:\r
+               if (!(zF & CF)) goto OP_JP;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xda):   // JP   C,nn\r
+OP_JP_C:\r
+               if (zF & CF) goto OP_JP;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xe2):   // JP   PO,nn\r
+OP_JP_PO:\r
+               if (!(zF & VF)) goto OP_JP;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xea):   // JP   PE,nn\r
+OP_JP_PE:\r
+               if (zF & VF) goto OP_JP;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xf2):   // JP   P,nn\r
+OP_JP_P:\r
+               if (!(zF & SF)) goto OP_JP;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xfa):   // JP   M,nn\r
+OP_JP_M:\r
+               if (zF & SF) goto OP_JP;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xe9):   // JP   (xx)\r
+OP_JP_xx:\r
+               res = data->W;\r
+               SET_PC(res);\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ JR\r
+-----------------------------------------*/\r
+\r
+       OP(0x10):   // DJNZ n\r
+OP_DJNZ:\r
+               USE_CYCLES(1)\r
+               if (--zB) goto OP_JR;\r
+               PC++;\r
+               RET(7)\r
+\r
+       OP(0x18):   // JR   n\r
+OP_JR:\r
+               adr = (INT8)READ_ARG();\r
+               PC += adr;\r
+               RET(12)\r
+\r
+       OP(0x20):   // JR   NZ,n\r
+OP_JR_NZ:\r
+               if (!(zF & ZF)) goto OP_JR;\r
+               PC++;\r
+               RET(7)\r
+\r
+       OP(0x28):   // JR   Z,n\r
+OP_JR_Z:\r
+               if (zF & ZF) goto OP_JR;\r
+               PC++;\r
+               RET(7)\r
+\r
+       OP(0x38):   // JR   C,n\r
+OP_JR_C:\r
+               if (zF & CF) goto OP_JR;\r
+               PC++;\r
+               RET(7)\r
+\r
+       OP(0x30):   // JR   NC,n\r
+OP_JR_NC:\r
+               if (!(zF & CF)) goto OP_JR;\r
+               PC++;\r
+               RET(7)\r
+\r
+/*-----------------------------------------\r
+ CALL\r
+-----------------------------------------*/\r
+\r
+       OP(0xcd):   // CALL nn\r
+OP_CALL:\r
+               res = READ_ARG16();\r
+               val = zRealPC;\r
+               PUSH_16(val);\r
+               SET_PC(res);\r
+               RET(17)\r
+\r
+       OP(0xc4):   // CALL NZ,nn\r
+OP_CALL_NZ:\r
+               if (!(zF & ZF)) goto OP_CALL;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xcc):   // CALL Z,nn\r
+OP_CALL_Z:\r
+               if (zF & ZF) goto OP_CALL;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xd4):   // CALL NC,nn\r
+OP_CALL_NC:\r
+               if (!(zF & CF)) goto OP_CALL;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xdc):   // CALL C,nn\r
+OP_CALL_C:\r
+               if (zF & CF) goto OP_CALL;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xe4):   // CALL PO,nn\r
+OP_CALL_PO:\r
+               if (!(zF & VF)) goto OP_CALL;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xec):   // CALL PE,nn\r
+OP_CALL_PE:\r
+               if (zF & VF) goto OP_CALL;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xf4):   // CALL P,nn\r
+OP_CALL_P:\r
+               if (!(zF & SF)) goto OP_CALL;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+       OP(0xfc):   // CALL M,nn\r
+OP_CALL_M:\r
+               if (zF & SF) goto OP_CALL;\r
+               PC += 2;\r
+               RET(10)\r
+\r
+/*-----------------------------------------\r
+ RET\r
+-----------------------------------------*/\r
+\r
+OP_RET_COND:\r
+               USE_CYCLES(1)\r
+\r
+       OP(0xc9):   // RET\r
+OP_RET:\r
+               POP_16(res);\r
+               SET_PC(res);\r
+               RET(10)\r
+\r
+       OP(0xc0):   // RET  NZ\r
+OP_RET_NZ:\r
+               if (!(zF & ZF)) goto OP_RET_COND;\r
+               RET(5)\r
+\r
+       OP(0xc8):   // RET  Z\r
+OP_RET_Z:\r
+               if (zF & ZF) goto OP_RET_COND;\r
+               RET(5)\r
+\r
+       OP(0xd0):   // RET  NC\r
+OP_RET_NC:\r
+               if (!(zF & CF)) goto OP_RET_COND;\r
+               RET(5)\r
+\r
+       OP(0xd8):   // RET  C\r
+OP_RET_C:\r
+               if (zF & CF) goto OP_RET_COND;\r
+               RET(5)\r
+\r
+       OP(0xe0):   // RET  PO\r
+OP_RET_PO:\r
+               if (!(zF & VF)) goto OP_RET_COND;\r
+               RET(5)\r
+\r
+       OP(0xe8):   // RET  PE\r
+OP_RET_PE:\r
+               if (zF & VF) goto OP_RET_COND;\r
+               RET(5)\r
+\r
+       OP(0xf0):   // RET  P\r
+OP_RET_P:\r
+               if (!(zF & SF)) goto OP_RET_COND;\r
+               RET(5)\r
+\r
+       OP(0xf8):   // RET  M\r
+OP_RET_M:\r
+               if (zF & SF) goto OP_RET_COND;\r
+               RET(5)\r
+\r
+/*-----------------------------------------\r
+ RST\r
+-----------------------------------------*/\r
+\r
+       OP(0xc7):   // RST  0\r
+       OP(0xcf):   // RST  1\r
+       OP(0xd7):   // RST  2\r
+       OP(0xdf):   // RST  3\r
+       OP(0xe7):   // RST  4\r
+       OP(0xef):   // RST  5\r
+       OP(0xf7):   // RST  6\r
+       OP(0xff):   // RST  7\r
+OP_RST:\r
+               res = zRealPC;\r
+               PUSH_16(res);\r
+               res = Opcode & 0x38;\r
+               SET_PC(res);\r
+               RET(11)\r
+\r
+/*-----------------------------------------\r
+ OUT\r
+-----------------------------------------*/\r
+\r
+       OP(0xd3):   // OUT  (n),A\r
+OP_OUT_mN_A:\r
+               adr = (zA << 8) | READ_ARG();\r
+               OUT(adr, zA);\r
+               RET(11)\r
+\r
+/*-----------------------------------------\r
+ IN\r
+-----------------------------------------*/\r
+\r
+       OP(0xdb):   // IN   A,(n)\r
+OP_IN_A_mN:\r
+               adr = (zA << 8) | READ_ARG();\r
+               zA = IN(adr);\r
+               RET(11)\r
+\r
+/*-----------------------------------------\r
+ PREFIX\r
+-----------------------------------------*/\r
+\r
+       OP(0xcb):   // CB prefix (BIT & SHIFT INSTRUCTIONS)\r
+       {\r
+               UINT8 src;\r
+               UINT8 res;\r
+\r
+               Opcode = READ_OP();\r
+#if CZ80_EMULATE_R_EXACTLY\r
+               zR++;\r
+#endif\r
+               #include "cz80_opCB.c"\r
+       }\r
+\r
+       OP(0xed):   // ED prefix\r
+ED_PREFIX:\r
+               USE_CYCLES(4)\r
+               Opcode = READ_OP();\r
+#if CZ80_EMULATE_R_EXACTLY\r
+               zR++;\r
+#endif\r
+               #include "cz80_opED.c"\r
+\r
+       OP(0xdd):   // DD prefix (IX)\r
+DD_PREFIX:\r
+               data = pzIX;\r
+               goto XY_PREFIX;\r
+\r
+       OP(0xfd):   // FD prefix (IY)\r
+FD_PREFIX:\r
+               data = pzIY;\r
+\r
+XY_PREFIX:\r
+               USE_CYCLES(4)\r
+               Opcode = READ_OP();\r
+#if CZ80_EMULATE_R_EXACTLY\r
+               zR++;\r
+#endif\r
+               #include "cz80_opXY.c"\r
+\r
+#if !CZ80_USE_JUMPTABLE\r
+}\r
+#endif\r
diff --git a/cpu/cz80/cz80_opCB.c b/cpu/cz80/cz80_opCB.c
new file mode 100644 (file)
index 0000000..58a78c5
--- /dev/null
@@ -0,0 +1,470 @@
+/******************************************************************************\r
+ *\r
+ * CZ80 CB opcode include source file\r
+ * CZ80 emulator version 0.9\r
+ * Copyright 2004-2005 Stéphane Dallongeville\r
+ *\r
+ * (Modified by NJ)\r
+ *\r
+ *****************************************************************************/\r
+\r
+#if CZ80_USE_JUMPTABLE\r
+       goto *JumpTableCB[Opcode];\r
+#else\r
+switch (Opcode)\r
+{\r
+#endif\r
+\r
+/*-----------------------------------------\r
+ RLC\r
+-----------------------------------------*/\r
+\r
+       OPCB(0x00): // RLC  B\r
+       OPCB(0x01): // RLC  C\r
+       OPCB(0x02): // RLC  D\r
+       OPCB(0x03): // RLC  E\r
+       OPCB(0x04): // RLC  H\r
+       OPCB(0x05): // RLC  L\r
+       OPCB(0x07): // RLC  A\r
+               src = zR8(Opcode);\r
+               res = (src << 1) | (src >> 7);\r
+               zF = SZP[res] | (src >> 7);\r
+               zR8(Opcode) = res;\r
+               RET(8)\r
+\r
+       OPCB(0x06): // RLC  (HL)\r
+               adr = zHL;\r
+               src = READ_MEM8(adr);\r
+               res = (src << 1) | (src >> 7);\r
+               zF = SZP[res] | (src >> 7);\r
+               WRITE_MEM8(adr, res);\r
+               RET(15)\r
+\r
+/*-----------------------------------------\r
+ RRC\r
+-----------------------------------------*/\r
+\r
+       OPCB(0x08): // RRC  B\r
+       OPCB(0x09): // RRC  C\r
+       OPCB(0x0a): // RRC  D\r
+       OPCB(0x0b): // RRC  E\r
+       OPCB(0x0c): // RRC  H\r
+       OPCB(0x0d): // RRC  L\r
+       OPCB(0x0f): // RRC  A\r
+               src = zR8(Opcode & 7);\r
+               res = (src >> 1) | (src << 7);\r
+               zF = SZP[res] | (src & CF);\r
+               zR8(Opcode & 7) = res;\r
+               RET(8)\r
+\r
+       OPCB(0x0e): // RRC  (HL)\r
+               adr = zHL;\r
+               src = READ_MEM8(adr);\r
+               res = (src >> 1) | (src << 7);\r
+               zF = SZP[res] | (src & CF);\r
+               WRITE_MEM8(adr, res);\r
+               RET(15)\r
+\r
+/*-----------------------------------------\r
+ RL\r
+-----------------------------------------*/\r
+\r
+       OPCB(0x10): // RL   B\r
+       OPCB(0x11): // RL   C\r
+       OPCB(0x12): // RL   D\r
+       OPCB(0x13): // RL   E\r
+       OPCB(0x14): // RL   H\r
+       OPCB(0x15): // RL   L\r
+       OPCB(0x17): // RL   A\r
+               src = zR8(Opcode & 7);\r
+               res = (src << 1) | (zF & CF);\r
+               zF = SZP[res] | (src >> 7);\r
+               zR8(Opcode & 7) = res;\r
+               RET(8)\r
+\r
+       OPCB(0x16): // RL   (HL)\r
+               adr = zHL;\r
+               src = READ_MEM8(adr);\r
+               res = (src << 1) | (zF & CF);\r
+               zF = SZP[res] | (src >> 7);\r
+               WRITE_MEM8(adr, res);\r
+               RET(15)\r
+\r
+/*-----------------------------------------\r
+ RR\r
+-----------------------------------------*/\r
+\r
+       OPCB(0x18): // RR   B\r
+       OPCB(0x19): // RR   C\r
+       OPCB(0x1a): // RR   D\r
+       OPCB(0x1b): // RR   E\r
+       OPCB(0x1c): // RR   H\r
+       OPCB(0x1d): // RR   L\r
+       OPCB(0x1f): // RR   A\r
+               src = zR8(Opcode & 7);\r
+               res = (src >> 1) | (zF << 7);\r
+               zF = SZP[res] | (src & CF);\r
+               zR8(Opcode & 7) = res;\r
+               RET(8)\r
+\r
+       OPCB(0x1e): // RR   (HL)\r
+               adr = zHL;\r
+               src = READ_MEM8(adr);\r
+               res = (src >> 1) | (zF << 7);\r
+               zF = SZP[res] | (src & CF);\r
+               WRITE_MEM8(adr, res);\r
+               RET(15)\r
+\r
+/*-----------------------------------------\r
+ SLA\r
+-----------------------------------------*/\r
+\r
+       OPCB(0x20): // SLA  B\r
+       OPCB(0x21): // SLA  C\r
+       OPCB(0x22): // SLA  D\r
+       OPCB(0x23): // SLA  E\r
+       OPCB(0x24): // SLA  H\r
+       OPCB(0x25): // SLA  L\r
+       OPCB(0x27): // SLA  A\r
+               src = zR8(Opcode & 7);\r
+               res = src << 1;\r
+               zF = SZP[res] | (src >> 7);\r
+               zR8(Opcode & 7) = res;\r
+               RET(8)\r
+\r
+       OPCB(0x26): // SLA  (HL)\r
+               adr = zHL;\r
+               src = READ_MEM8(adr);\r
+               res = src << 1;\r
+               zF = SZP[res] | (src >> 7);\r
+               WRITE_MEM8(adr, res);\r
+               RET(15)\r
+\r
+/*-----------------------------------------\r
+ SRA\r
+-----------------------------------------*/\r
+\r
+       OPCB(0x28): // SRA  B\r
+       OPCB(0x29): // SRA  C\r
+       OPCB(0x2a): // SRA  D\r
+       OPCB(0x2b): // SRA  E\r
+       OPCB(0x2c): // SRA  H\r
+       OPCB(0x2d): // SRA  L\r
+       OPCB(0x2f): // SRA  A\r
+               src = zR8(Opcode & 7);\r
+               res = (src >> 1) | (src & 0x80);\r
+               zF = SZP[res] | (src & CF);\r
+               zR8(Opcode & 7) = res;\r
+               RET(8)\r
+\r
+       OPCB(0x2e): // SRA  (HL)\r
+               adr = zHL;\r
+               src = READ_MEM8(adr);\r
+               res = (src >> 1) | (src & 0x80);\r
+               zF = SZP[res] | (src & CF);\r
+               WRITE_MEM8(adr, res);\r
+               RET(15)\r
+\r
+/*-----------------------------------------\r
+ SLL\r
+-----------------------------------------*/\r
+\r
+       OPCB(0x30): // SLL  B\r
+       OPCB(0x31): // SLL  C\r
+       OPCB(0x32): // SLL  D\r
+       OPCB(0x33): // SLL  E\r
+       OPCB(0x34): // SLL  H\r
+       OPCB(0x35): // SLL  L\r
+       OPCB(0x37): // SLL  A\r
+               src = zR8(Opcode & 7);\r
+               res = (src << 1) | 0x01;\r
+               zF = SZP[res] | (src >> 7);\r
+               zR8(Opcode & 7) = res;\r
+               RET(8)\r
+\r
+       OPCB(0x36): // SLL  (HL)\r
+               adr = zHL;\r
+               src = READ_MEM8(adr);\r
+               res = (src << 1) | 0x01;\r
+               zF = SZP[res] | (src >> 7);\r
+               WRITE_MEM8(adr, res);\r
+               RET(15)\r
+\r
+/*-----------------------------------------\r
+ SRL\r
+-----------------------------------------*/\r
+\r
+       OPCB(0x38): // SRL  B\r
+       OPCB(0x39): // SRL  C\r
+       OPCB(0x3a): // SRL  D\r
+       OPCB(0x3b): // SRL  E\r
+       OPCB(0x3c): // SRL  H\r
+       OPCB(0x3d): // SRL  L\r
+       OPCB(0x3f): // SRL  A\r
+               src = zR8(Opcode & 7);\r
+               res = src >> 1;\r
+               zF = SZP[res] | (src & CF);\r
+               zR8(Opcode & 7) = res;\r
+               RET(8)\r
+\r
+       OPCB(0x3e): // SRL  (HL)\r
+               adr = zHL;\r
+               src = READ_MEM8(adr);\r
+               res = src >> 1;\r
+               zF = SZP[res] | (src & CF);\r
+               WRITE_MEM8(adr, res);\r
+               RET(15)\r
+\r
+/*-----------------------------------------\r
+ BIT\r
+-----------------------------------------*/\r
+\r
+       OPCB(0x40): // BIT  0,B\r
+       OPCB(0x41): // BIT  0,C\r
+       OPCB(0x42): // BIT  0,D\r
+       OPCB(0x43): // BIT  0,E\r
+       OPCB(0x44): // BIT  0,H\r
+       OPCB(0x45): // BIT  0,L\r
+       OPCB(0x47): // BIT  0,A\r
+\r
+       OPCB(0x48): // BIT  1,B\r
+       OPCB(0x49): // BIT  1,C\r
+       OPCB(0x4a): // BIT  1,D\r
+       OPCB(0x4b): // BIT  1,E\r
+       OPCB(0x4c): // BIT  1,H\r
+       OPCB(0x4d): // BIT  1,L\r
+       OPCB(0x4f): // BIT  1,A\r
+\r
+       OPCB(0x50): // BIT  2,B\r
+       OPCB(0x51): // BIT  2,C\r
+       OPCB(0x52): // BIT  2,D\r
+       OPCB(0x53): // BIT  2,E\r
+       OPCB(0x54): // BIT  2,H\r
+       OPCB(0x55): // BIT  2,L\r
+       OPCB(0x57): // BIT  2,A\r
+\r
+       OPCB(0x58): // BIT  3,B\r
+       OPCB(0x59): // BIT  3,C\r
+       OPCB(0x5a): // BIT  3,D\r
+       OPCB(0x5b): // BIT  3,E\r
+       OPCB(0x5c): // BIT  3,H\r
+       OPCB(0x5d): // BIT  3,L\r
+       OPCB(0x5f): // BIT  3,A\r
+\r
+       OPCB(0x60): // BIT  4,B\r
+       OPCB(0x61): // BIT  4,C\r
+       OPCB(0x62): // BIT  4,D\r
+       OPCB(0x63): // BIT  4,E\r
+       OPCB(0x64): // BIT  4,H\r
+       OPCB(0x65): // BIT  4,L\r
+       OPCB(0x67): // BIT  4,A\r
+\r
+       OPCB(0x68): // BIT  5,B\r
+       OPCB(0x69): // BIT  5,C\r
+       OPCB(0x6a): // BIT  5,D\r
+       OPCB(0x6b): // BIT  5,E\r
+       OPCB(0x6c): // BIT  5,H\r
+       OPCB(0x6d): // BIT  5,L\r
+       OPCB(0x6f): // BIT  5,A\r
+\r
+       OPCB(0x70): // BIT  6,B\r
+       OPCB(0x71): // BIT  6,C\r
+       OPCB(0x72): // BIT  6,D\r
+       OPCB(0x73): // BIT  6,E\r
+       OPCB(0x74): // BIT  6,H\r
+       OPCB(0x75): // BIT  6,L\r
+       OPCB(0x77): // BIT  6,A\r
+\r
+       OPCB(0x78): // BIT  7,B\r
+       OPCB(0x79): // BIT  7,C\r
+       OPCB(0x7a): // BIT  7,D\r
+       OPCB(0x7b): // BIT  7,E\r
+       OPCB(0x7c): // BIT  7,H\r
+       OPCB(0x7d): // BIT  7,L\r
+       OPCB(0x7f): // BIT  7,A\r
+               zF = (zF & CF) | HF | SZ_BIT[zR8(Opcode & 7) & (1 << ((Opcode >> 3) & 7))];\r
+               RET(8)\r
+\r
+       OPCB(0x46): // BIT  0,(HL)\r
+       OPCB(0x4e): // BIT  1,(HL)\r
+       OPCB(0x56): // BIT  2,(HL)\r
+       OPCB(0x5e): // BIT  3,(HL)\r
+       OPCB(0x66): // BIT  4,(HL)\r
+       OPCB(0x6e): // BIT  5,(HL)\r
+       OPCB(0x76): // BIT  6,(HL)\r
+       OPCB(0x7e): // BIT  7,(HL)\r
+               src = READ_MEM8(zHL);\r
+               zF = (zF & CF) | HF | SZ_BIT[src & (1 << ((Opcode >> 3) & 7))];\r
+               RET(12)\r
+\r
+/*-----------------------------------------\r
+ RES\r
+-----------------------------------------*/\r
+\r
+       OPCB(0x80): // RES  0,B\r
+       OPCB(0x81): // RES  0,C\r
+       OPCB(0x82): // RES  0,D\r
+       OPCB(0x83): // RES  0,E\r
+       OPCB(0x84): // RES  0,H\r
+       OPCB(0x85): // RES  0,L\r
+       OPCB(0x87): // RES  0,A\r
+\r
+       OPCB(0x88): // RES  1,B\r
+       OPCB(0x89): // RES  1,C\r
+       OPCB(0x8a): // RES  1,D\r
+       OPCB(0x8b): // RES  1,E\r
+       OPCB(0x8c): // RES  1,H\r
+       OPCB(0x8d): // RES  1,L\r
+       OPCB(0x8f): // RES  1,A\r
+\r
+       OPCB(0x90): // RES  2,B\r
+       OPCB(0x91): // RES  2,C\r
+       OPCB(0x92): // RES  2,D\r
+       OPCB(0x93): // RES  2,E\r
+       OPCB(0x94): // RES  2,H\r
+       OPCB(0x95): // RES  2,L\r
+       OPCB(0x97): // RES  2,A\r
+\r
+       OPCB(0x98): // RES  3,B\r
+       OPCB(0x99): // RES  3,C\r
+       OPCB(0x9a): // RES  3,D\r
+       OPCB(0x9b): // RES  3,E\r
+       OPCB(0x9c): // RES  3,H\r
+       OPCB(0x9d): // RES  3,L\r
+       OPCB(0x9f): // RES  3,A\r
+\r
+       OPCB(0xa0): // RES  4,B\r
+       OPCB(0xa1): // RES  4,C\r
+       OPCB(0xa2): // RES  4,D\r
+       OPCB(0xa3): // RES  4,E\r
+       OPCB(0xa4): // RES  4,H\r
+       OPCB(0xa5): // RES  4,L\r
+       OPCB(0xa7): // RES  4,A\r
+\r
+       OPCB(0xa8): // RES  5,B\r
+       OPCB(0xa9): // RES  5,C\r
+       OPCB(0xaa): // RES  5,D\r
+       OPCB(0xab): // RES  5,E\r
+       OPCB(0xac): // RES  5,H\r
+       OPCB(0xad): // RES  5,L\r
+       OPCB(0xaf): // RES  5,A\r
+\r
+       OPCB(0xb0): // RES  6,B\r
+       OPCB(0xb1): // RES  6,C\r
+       OPCB(0xb2): // RES  6,D\r
+       OPCB(0xb3): // RES  6,E\r
+       OPCB(0xb4): // RES  6,H\r
+       OPCB(0xb5): // RES  6,L\r
+       OPCB(0xb7): // RES  6,A\r
+\r
+       OPCB(0xb8): // RES  7,B\r
+       OPCB(0xb9): // RES  7,C\r
+       OPCB(0xba): // RES  7,D\r
+       OPCB(0xbb): // RES  7,E\r
+       OPCB(0xbc): // RES  7,H\r
+       OPCB(0xbd): // RES  7,L\r
+       OPCB(0xbf): // RES  7,A\r
+               zR8(Opcode & 7) &= ~(1 << ((Opcode >> 3) & 7));\r
+               RET(8)\r
+\r
+       OPCB(0x86): // RES  0,(HL)\r
+       OPCB(0x8e): // RES  1,(HL)\r
+       OPCB(0x96): // RES  2,(HL)\r
+       OPCB(0x9e): // RES  3,(HL)\r
+       OPCB(0xa6): // RES  4,(HL)\r
+       OPCB(0xae): // RES  5,(HL)\r
+       OPCB(0xb6): // RES  6,(HL)\r
+       OPCB(0xbe): // RES  7,(HL)\r
+               adr = zHL;\r
+               res = READ_MEM8(adr);\r
+               res &= ~(1 << ((Opcode >> 3) & 7));\r
+               WRITE_MEM8(adr, res);\r
+               RET(15)\r
+\r
+/*-----------------------------------------\r
+ SET\r
+-----------------------------------------*/\r
+\r
+       OPCB(0xc0): // SET  0,B\r
+       OPCB(0xc1): // SET  0,C\r
+       OPCB(0xc2): // SET  0,D\r
+       OPCB(0xc3): // SET  0,E\r
+       OPCB(0xc4): // SET  0,H\r
+       OPCB(0xc5): // SET  0,L\r
+       OPCB(0xc7): // SET  0,A\r
+\r
+       OPCB(0xc8): // SET  1,B\r
+       OPCB(0xc9): // SET  1,C\r
+       OPCB(0xca): // SET  1,D\r
+       OPCB(0xcb): // SET  1,E\r
+       OPCB(0xcc): // SET  1,H\r
+       OPCB(0xcd): // SET  1,L\r
+       OPCB(0xcf): // SET  1,A\r
+\r
+       OPCB(0xd0): // SET  2,B\r
+       OPCB(0xd1): // SET  2,C\r
+       OPCB(0xd2): // SET  2,D\r
+       OPCB(0xd3): // SET  2,E\r
+       OPCB(0xd4): // SET  2,H\r
+       OPCB(0xd5): // SET  2,L\r
+       OPCB(0xd7): // SET  2,A\r
+\r
+       OPCB(0xd8): // SET  3,B\r
+       OPCB(0xd9): // SET  3,C\r
+       OPCB(0xda): // SET  3,D\r
+       OPCB(0xdb): // SET  3,E\r
+       OPCB(0xdc): // SET  3,H\r
+       OPCB(0xdd): // SET  3,L\r
+       OPCB(0xdf): // SET  3,A\r
+\r
+       OPCB(0xe0): // SET  4,B\r
+       OPCB(0xe1): // SET  4,C\r
+       OPCB(0xe2): // SET  4,D\r
+       OPCB(0xe3): // SET  4,E\r
+       OPCB(0xe4): // SET  4,H\r
+       OPCB(0xe5): // SET  4,L\r
+       OPCB(0xe7): // SET  4,A\r
+\r
+       OPCB(0xe8): // SET  5,B\r
+       OPCB(0xe9): // SET  5,C\r
+       OPCB(0xea): // SET  5,D\r
+       OPCB(0xeb): // SET  5,E\r
+       OPCB(0xec): // SET  5,H\r
+       OPCB(0xed): // SET  5,L\r
+       OPCB(0xef): // SET  5,A\r
+\r
+       OPCB(0xf0): // SET  6,B\r
+       OPCB(0xf1): // SET  6,C\r
+       OPCB(0xf2): // SET  6,D\r
+       OPCB(0xf3): // SET  6,E\r
+       OPCB(0xf4): // SET  6,H\r
+       OPCB(0xf5): // SET  6,L\r
+       OPCB(0xf7): // SET  6,A\r
+\r
+       OPCB(0xf8): // SET  7,B\r
+       OPCB(0xf9): // SET  7,C\r
+       OPCB(0xfa): // SET  7,D\r
+       OPCB(0xfb): // SET  7,E\r
+       OPCB(0xfc): // SET  7,H\r
+       OPCB(0xfd): // SET  7,L\r
+       OPCB(0xff): // SET  7,A\r
+               zR8(Opcode & 7) |= 1 << ((Opcode >> 3) & 7);\r
+               RET(8)\r
+\r
+       OPCB(0xc6): // SET  0,(HL)\r
+       OPCB(0xce): // SET  1,(HL)\r
+       OPCB(0xd6): // SET  2,(HL)\r
+       OPCB(0xde): // SET  3,(HL)\r
+       OPCB(0xe6): // SET  4,(HL)\r
+       OPCB(0xee): // SET  5,(HL)\r
+       OPCB(0xf6): // SET  6,(HL)\r
+       OPCB(0xfe): // SET  7,(HL)\r
+               adr = zHL;\r
+               res = READ_MEM8(adr);\r
+               res |= 1 << ((Opcode >> 3) & 7);\r
+               WRITE_MEM8(adr, res);\r
+               RET(15)\r
+\r
+#if !CZ80_USE_JUMPTABLE\r
+}\r
+#endif\r
diff --git a/cpu/cz80/cz80_opED.c b/cpu/cz80/cz80_opED.c
new file mode 100644 (file)
index 0000000..c3b7ec6
--- /dev/null
@@ -0,0 +1,731 @@
+/******************************************************************************\r
+ *\r
+ * CZ80 ED opcode include source file\r
+ * CZ80 emulator version 0.9\r
+ * Copyright 2004-2005 Stéphane Dallongeville\r
+ *\r
+ * (Modified by NJ)\r
+ *\r
+ *****************************************************************************/\r
+\r
+#if CZ80_USE_JUMPTABLE\r
+       goto *JumpTableED[Opcode];\r
+#else\r
+switch (Opcode)\r
+{\r
+#endif\r
+\r
+/*-----------------------------------------\r
+ ILLEGAL\r
+-----------------------------------------*/\r
+\r
+       OPED(0x00):\r
+       OPED(0x01):\r
+       OPED(0x02):\r
+       OPED(0x03):\r
+       OPED(0x04):\r
+       OPED(0x05):\r
+       OPED(0x06):\r
+       OPED(0x07):\r
+       OPED(0x08):\r
+       OPED(0x09):\r
+       OPED(0x0a):\r
+       OPED(0x0b):\r
+       OPED(0x0c):\r
+       OPED(0x0d):\r
+       OPED(0x0e):\r
+       OPED(0x0f):\r
+\r
+       OPED(0x10):\r
+       OPED(0x11):\r
+       OPED(0x12):\r
+       OPED(0x13):\r
+       OPED(0x14):\r
+       OPED(0x15):\r
+       OPED(0x16):\r
+       OPED(0x17):\r
+       OPED(0x18):\r
+       OPED(0x19):\r
+       OPED(0x1a):\r
+       OPED(0x1b):\r
+       OPED(0x1c):\r
+       OPED(0x1d):\r
+       OPED(0x1e):\r
+       OPED(0x1f):\r
+\r
+       OPED(0x20):\r
+       OPED(0x21):\r
+       OPED(0x22):\r
+       OPED(0x23):\r
+       OPED(0x24):\r
+       OPED(0x25):\r
+       OPED(0x26):\r
+       OPED(0x27):\r
+       OPED(0x28):\r
+       OPED(0x29):\r
+       OPED(0x2a):\r
+       OPED(0x2b):\r
+       OPED(0x2c):\r
+       OPED(0x2d):\r
+       OPED(0x2e):\r
+       OPED(0x2f):\r
+\r
+       OPED(0x30):\r
+       OPED(0x31):\r
+       OPED(0x32):\r
+       OPED(0x33):\r
+       OPED(0x34):\r
+       OPED(0x35):\r
+       OPED(0x36):\r
+       OPED(0x37):\r
+       OPED(0x38):\r
+       OPED(0x39):\r
+       OPED(0x3a):\r
+       OPED(0x3b):\r
+       OPED(0x3c):\r
+       OPED(0x3d):\r
+       OPED(0x3e):\r
+       OPED(0x3f):\r
+\r
+       OPED(0x77):\r
+       OPED(0x7f):\r
+\r
+       OPED(0x80):\r
+       OPED(0x81):\r
+       OPED(0x82):\r
+       OPED(0x83):\r
+       OPED(0x84):\r
+       OPED(0x85):\r
+       OPED(0x86):\r
+       OPED(0x87):\r
+       OPED(0x88):\r
+       OPED(0x89):\r
+       OPED(0x8a):\r
+       OPED(0x8b):\r
+       OPED(0x8c):\r
+       OPED(0x8d):\r
+       OPED(0x8e):\r
+       OPED(0x8f):\r
+\r
+       OPED(0x90):\r
+       OPED(0x91):\r
+       OPED(0x92):\r
+       OPED(0x93):\r
+       OPED(0x94):\r
+       OPED(0x95):\r
+       OPED(0x96):\r
+       OPED(0x97):\r
+       OPED(0x98):\r
+       OPED(0x99):\r
+       OPED(0x9a):\r
+       OPED(0x9b):\r
+       OPED(0x9c):\r
+       OPED(0x9d):\r
+       OPED(0x9e):\r
+       OPED(0x9f):\r
+\r
+       OPED(0xa4):\r
+       OPED(0xa5):\r
+       OPED(0xa6):\r
+       OPED(0xa7):\r
+\r
+       OPED(0xac):\r
+       OPED(0xad):\r
+       OPED(0xae):\r
+       OPED(0xaf):\r
+\r
+       OPED(0xb4):\r
+       OPED(0xb5):\r
+       OPED(0xb6):\r
+       OPED(0xb7):\r
+\r
+       OPED(0xbc):\r
+       OPED(0xbd):\r
+       OPED(0xbe):\r
+       OPED(0xbf):\r
+\r
+       OPED(0xc0):\r
+       OPED(0xc1):\r
+       OPED(0xc2):\r
+       OPED(0xc3):\r
+       OPED(0xc4):\r
+       OPED(0xc5):\r
+       OPED(0xc6):\r
+       OPED(0xc7):\r
+       OPED(0xc8):\r
+       OPED(0xc9):\r
+       OPED(0xca):\r
+       OPED(0xcb):\r
+       OPED(0xcc):\r
+       OPED(0xcd):\r
+       OPED(0xce):\r
+       OPED(0xcf):\r
+\r
+       OPED(0xd0):\r
+       OPED(0xd1):\r
+       OPED(0xd2):\r
+       OPED(0xd3):\r
+       OPED(0xd4):\r
+       OPED(0xd5):\r
+       OPED(0xd6):\r
+       OPED(0xd7):\r
+       OPED(0xd8):\r
+       OPED(0xd9):\r
+       OPED(0xda):\r
+       OPED(0xdb):\r
+       OPED(0xdc):\r
+       OPED(0xdd):\r
+       OPED(0xde):\r
+       OPED(0xdf):\r
+\r
+       OPED(0xe0):\r
+       OPED(0xe1):\r
+       OPED(0xe2):\r
+       OPED(0xe3):\r
+       OPED(0xe4):\r
+       OPED(0xe5):\r
+       OPED(0xe6):\r
+       OPED(0xe7):\r
+       OPED(0xe8):\r
+       OPED(0xe9):\r
+       OPED(0xea):\r
+       OPED(0xeb):\r
+       OPED(0xec):\r
+       OPED(0xed):\r
+       OPED(0xee):\r
+       OPED(0xef):\r
+\r
+       OPED(0xf0):\r
+       OPED(0xf1):\r
+       OPED(0xf2):\r
+       OPED(0xf3):\r
+       OPED(0xf4):\r
+       OPED(0xf5):\r
+       OPED(0xf6):\r
+       OPED(0xf7):\r
+       OPED(0xf8):\r
+       OPED(0xf9):\r
+       OPED(0xfa):\r
+       OPED(0xfb):\r
+       OPED(0xfc):\r
+       OPED(0xfd):\r
+       OPED(0xfe):\r
+       OPED(0xff):\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ LD r8\r
+-----------------------------------------*/\r
+\r
+       OPED(0x47): // LD   I,A\r
+               zI = zA;\r
+               RET(5)\r
+\r
+       OPED(0x4f): // LD   R,A\r
+#if CZ80_EMULATE_R_EXACTLY\r
+               zR = zA;\r
+#else\r
+               zR = zA - ((cycles - CPU->ICount) >> 2);\r
+#endif\r
+               zR2 = zA & 0x80;\r
+               RET(5)\r
+\r
+       OPED(0x57): // LD   A,I\r
+               zA = zI;\r
+               zF = (zF & CF) | SZ[zA] | zIFF2;\r
+               RET(5)\r
+\r
+       OPED(0x5f): // LD   A,R\r
+#if CZ80_EMULATE_R_EXACTLY\r
+               zA = (zR & 0x7f) | zR2;\r
+#else\r
+               zA = ((zR + ((cycles - CPU->ICount) >> 2)) & 0x7f) | zR2;\r
+#endif\r
+               zF = (zF & CF) | SZ[zA] | zIFF2;\r
+               RET(5)\r
+\r
+/*-----------------------------------------\r
+ LD r16\r
+-----------------------------------------*/\r
+\r
+       OPED(0x43): // LD   (w),BC\r
+               data = pzBC;\r
+               goto OP_LD_mNN_xx;\r
+\r
+       OPED(0x53): // LD   (w),DE\r
+               data = pzDE;\r
+               goto OP_LD_mNN_xx;\r
+\r
+       OPED(0x63): // LD   (w),HL\r
+               data = pzHL;\r
+               goto OP_LD_mNN_xx;\r
+\r
+       OPED(0x73): // LD   (w),SP\r
+               data = pzSP;\r
+               goto OP_LD_mNN_xx;\r
+\r
+       OPED(0x4b): // LD   BC,(w)\r
+               data = pzBC;\r
+               goto OP_LD_xx_mNN;\r
+\r
+       OPED(0x5b): // LD   DE,(w)\r
+               data = pzDE;\r
+               goto OP_LD_xx_mNN;\r
+\r
+       OPED(0x6b): // LD   HL,(w)\r
+               data = pzHL;\r
+               goto OP_LD_xx_mNN;\r
+\r
+       OPED(0x7b): // LD   SP,(w)\r
+               data = pzSP;\r
+               goto OP_LD_xx_mNN;\r
+\r
+/*-----------------------------------------\r
+ NEG\r
+-----------------------------------------*/\r
+\r
+       OPED(0x44): // NEG\r
+       OPED(0x4c): // NEG\r
+       OPED(0x54): // NEG\r
+       OPED(0x5c): // NEG\r
+       OPED(0x64): // NEG\r
+       OPED(0x6c): // NEG\r
+       OPED(0x74): // NEG\r
+       OPED(0x7c): // NEG\r
+               val = zA;\r
+               zA = 0;\r
+               goto OP_SUB;\r
+\r
+/*-----------------------------------------\r
+ RRD\r
+-----------------------------------------*/\r
+\r
+       OPED(0x67): // RRD  (HL)\r
+               adr = zHL;\r
+               val = READ_MEM8(adr);\r
+               WRITE_MEM8(adr, (val >> 4) | (zA << 4));\r
+               zA = (zA & 0xf0) | (val & 0x0f);\r
+               zF = (zF & CF) | SZP[zA];\r
+               RET(14)\r
+\r
+/*-----------------------------------------\r
+ RLD\r
+-----------------------------------------*/\r
+\r
+       OPED(0x6f): // RLD  (HL)\r
+               adr = zHL;\r
+               val = READ_MEM8(adr);\r
+               WRITE_MEM8(adr, (val << 4) | (zA & 0x0f));\r
+               zA = (zA & 0xf0) | (val >> 4);\r
+               zF = (zF & CF) | SZP[zA];\r
+               RET(14)\r
+\r
+/*-----------------------------------------\r
+ ADC 16\r
+-----------------------------------------*/\r
+\r
+       OPED(0x7a): // ADC  HL,SP\r
+               val = zSP;\r
+               goto OP_ADC16;\r
+\r
+       OPED(0x4a): // ADC  HL,BC\r
+       OPED(0x5a): // ADC  HL,DE\r
+       OPED(0x6a): // ADC  HL,HL\r
+               val = zR16((Opcode >> 4) & 3);\r
+\r
+OP_ADC16:\r
+               res = zHL + val + (zF & CF);\r
+               zF = (((zHL ^ res ^ val) >> 8) & HF) |\r
+                       ((res >> 16) & CF) |\r
+                       ((res >> 8) & (SF | YF | XF)) |\r
+                       ((res & 0xffff) ? 0 : ZF) |\r
+                       (((val ^ zHL ^ 0x8000) & (val ^ res) & 0x8000) >> 13);\r
+               zHL = (UINT16)res;\r
+               RET(11)\r
+\r
+/*-----------------------------------------\r
+ SBC 16\r
+-----------------------------------------*/\r
+\r
+       OPED(0x72): // SBC  HL,SP\r
+               val = zSP;\r
+               goto OP_SBC16;\r
+\r
+       OPED(0x42): // SBC  HL,BC\r
+       OPED(0x52): // SBC  HL,DE\r
+       OPED(0x62): // SBC  HL,HL\r
+               val = zR16((Opcode >> 4) & 3);\r
+\r
+OP_SBC16:\r
+               res = zHL - val - (zF & CF);\r
+               zF = (((zHL ^ res ^ val) >> 8) & HF) | NF |\r
+                       ((res >> 16) & CF) |\r
+                       ((res >> 8) & (SF | YF | XF)) |\r
+                       ((res & 0xffff) ? 0 : ZF) |\r
+                       (((val ^ zHL) & (zHL ^ res) & 0x8000) >> 13);\r
+               zHL = (UINT16)res;\r
+               RET(11)\r
+\r
+/*-----------------------------------------\r
+ IN\r
+-----------------------------------------*/\r
+\r
+       OPED(0x40): // IN   B,(C)\r
+       OPED(0x48): // IN   C,(C)\r
+       OPED(0x50): // IN   D,(C)\r
+       OPED(0x58): // IN   E,(C)\r
+       OPED(0x60): // IN   H,(C)\r
+       OPED(0x68): // IN   L,(C)\r
+       OPED(0x78): // IN   E,(C)\r
+               res = IN(zBC);\r
+               zR8((Opcode >> 3) & 7) = res;\r
+               zF = (zF & CF) | SZP[res];\r
+               RET(8)\r
+\r
+       OPED(0x70): // IN   0,(C)\r
+               res = IN(zBC);\r
+               zF = (zF & CF) | SZP[res];\r
+               RET(8)\r
+\r
+/*-----------------------------------------\r
+ OUT\r
+-----------------------------------------*/\r
+\r
+       OPED(0x51): // OUT  (C),D\r
+       OPED(0x41): // OUT  (C),B\r
+       OPED(0x49): // OUT  (C),C\r
+       OPED(0x59): // OUT  (C),E\r
+       OPED(0x61): // OUT  (C),H\r
+       OPED(0x69): // OUT  (C),L\r
+       OPED(0x79): // OUT  (C),E\r
+               res = zR8((Opcode >> 3) & 7);\r
+               OUT(zBC, res);\r
+               RET(8)\r
+\r
+       OPED(0x71): // OUT  (C),0\r
+               OUT(zBC, 0);\r
+               RET(8)\r
+\r
+/*-----------------------------------------\r
+ RETN\r
+-----------------------------------------*/\r
+\r
+       OPED(0x45): // RETN;\r
+       OPED(0x55): // RETN;\r
+       OPED(0x65): // RETN;\r
+       OPED(0x75): // RETN;\r
+               POP_16(res);\r
+               SET_PC(res);\r
+               if (!zIFF1 && zIFF2)\r
+               {\r
+                       zIFF1 = (1 << 2);\r
+                       if (CPU->IRQState)\r
+                       {\r
+                               USE_CYCLES(10)\r
+                               goto Cz80_Check_Interrupt;\r
+                       }\r
+               }\r
+               else zIFF1 = zIFF2;\r
+               RET(10)\r
+\r
+/*-----------------------------------------\r
+ RETI\r
+-----------------------------------------*/\r
+\r
+       OPED(0x4d): // RETI\r
+       OPED(0x5d): // RETI\r
+       OPED(0x6d): // RETI\r
+       OPED(0x7d): // RETI\r
+               POP_16(res);\r
+               SET_PC(res);\r
+               RET(10)\r
+\r
+/*-----------------------------------------\r
+ IM\r
+-----------------------------------------*/\r
+\r
+       OPED(0x46): // IM   0\r
+       OPED(0x4e): // IM   0\r
+       OPED(0x66): // IM   0\r
+       OPED(0x6e): // IM   0\r
+               zIM = 0;\r
+               RET(4)\r
+\r
+       OPED(0x56): // IM   1\r
+       OPED(0x76): // IM   1\r
+               zIM = 1;\r
+               RET(4)\r
+\r
+       OPED(0x5e): // IM   2\r
+       OPED(0x7e): // IM   2\r
+               zIM = 2;\r
+               RET(4)\r
+\r
+       {\r
+               UINT8 val;\r
+               UINT8 res;\r
+               UINT8 F;\r
+\r
+/*-----------------------------------------\r
+ LDI/LDD\r
+-----------------------------------------*/\r
+\r
+       OPED(0xa0): // LDI\r
+               val = READ_MEM8(zHL++);\r
+               WRITE_MEM8(zDE++, val);\r
+               goto OP_LDX;\r
+\r
+       OPED(0xa8): // LDD\r
+               val = READ_MEM8(zHL--);\r
+               WRITE_MEM8(zDE--, val);\r
+\r
+OP_LDX:\r
+               F = zF & (SF | ZF | CF);\r
+               if ((zA + val) & 0x02) F |= YF;\r
+               if ((zA + val) & 0x08) F |= XF;\r
+               if (--zBC) F |= VF;\r
+               zF = F;\r
+               RET(12)\r
+\r
+/*-----------------------------------------\r
+ LDIR/LDDR\r
+-----------------------------------------*/\r
+\r
+       OPED(0xb0): // LDIR\r
+               do\r
+               {\r
+                       val = READ_MEM8(zHL++);\r
+                       WRITE_MEM8(zDE++, val);\r
+                       zBC--;\r
+                       USE_CYCLES(17)\r
+               } while (zBC && (CPU->ICount > 0));\r
+               goto OP_LDXR;\r
+\r
+       OPED(0xb8): // LDDR\r
+               do\r
+               {\r
+                       val = READ_MEM8(zHL--);\r
+                       WRITE_MEM8(zDE--, val);\r
+                       zBC--;\r
+                       USE_CYCLES(17)\r
+               } while (zBC && (CPU->ICount > 0));\r
+\r
+OP_LDXR:\r
+               F = zF & (SF | ZF | CF);\r
+               if ((zA + val) & 0x02) F |= YF;\r
+               if ((zA + val) & 0x08) F |= XF;\r
+               if (zBC)\r
+               {\r
+                       zF = F | VF;\r
+                       PC -= 2;\r
+#if CZ80_EMULATE_R_EXACTLY\r
+                       zR--;\r
+#endif\r
+                       goto Cz80_Exec_End;\r
+               }\r
+               zF = F;\r
+               ADD_CYCLES(5)\r
+               goto Cz80_Exec;\r
+\r
+/*-----------------------------------------\r
+ CPI/CPD\r
+-----------------------------------------*/\r
+\r
+       OPED(0xa1): // CPI\r
+               val = READ_MEM8(zHL++);\r
+               goto OP_CPX;\r
+\r
+       OPED(0xa9): // CPD\r
+               val = READ_MEM8(zHL--);\r
+\r
+OP_CPX:\r
+               res = zA - val;\r
+               F = (zF & CF) | (SZ[res] & ~(YF | XF)) | ((zA ^ val ^ res) & HF) | NF;\r
+               if (F & HF) res--;\r
+               if (res & 0x02) F |= YF;\r
+               if (res & 0x08) F |= XF;\r
+               if (--zBC) F |= VF;\r
+               zF = F;\r
+               RET(12)\r
+\r
+/*-----------------------------------------\r
+ CPIR/CPDR\r
+-----------------------------------------*/\r
+\r
+       OPED(0xb1): // CPIR\r
+               do\r
+               {\r
+                       val = READ_MEM8(zHL++);\r
+                       res = zA - val;\r
+                       zBC--;\r
+                       F = (zF & CF) | (SZ[res] & ~(YF | XF)) | ((zA ^ val ^ res) & HF) | NF;\r
+                       if (F & HF) res--;\r
+                       if (res & 0x02) F |= YF;\r
+                       if (res & 0x08) F |= XF;\r
+                       if (zBC) F |= VF;\r
+                       zF = F;\r
+                       USE_CYCLES(17)\r
+               } while (zBC && !(F & ZF) && (CPU->ICount > 0));\r
+               goto OP_CPXR;\r
+\r
+       OPED(0xb9): // CPDR\r
+               do\r
+               {\r
+                       val = READ_MEM8(zHL--);\r
+                       res = zA - val;\r
+                       zBC--;\r
+                       F = (zF & CF) | (SZ[res] & ~(YF | XF)) | ((zA ^ val ^ res) & HF) | NF;\r
+                       if (F & HF) res--;\r
+                       if (res & 0x02) F |= YF;\r
+                       if (res & 0x08) F |= XF;\r
+                       if (zBC) F |= VF;\r
+                       zF = F;\r
+                       USE_CYCLES(17)\r
+               } while (zBC && !(F & ZF) && (CPU->ICount > 0));\r
+\r
+OP_CPXR:\r
+               if (zBC && !(F & ZF))\r
+               {\r
+                       PC -= 2;\r
+#if CZ80_EMULATE_R_EXACTLY\r
+                       zR--;\r
+#endif\r
+                       goto Cz80_Exec_End;\r
+               }\r
+               ADD_CYCLES(5)\r
+               goto Cz80_Exec;\r
+\r
+/*-----------------------------------------\r
+ INI/IND\r
+-----------------------------------------*/\r
+\r
+       OPED(0xa2): // INI\r
+               val = IN(zBC);\r
+               zB--;\r
+               WRITE_MEM8(zHL++, val);\r
+               goto OP_INX;\r
+\r
+       OPED(0xaa): // IND\r
+               val = IN(zBC);\r
+               zB--;\r
+               WRITE_MEM8(zHL--, val);\r
+\r
+OP_INX:\r
+               F = SZ[zB];\r
+               res = ((UINT32)(zC - 1) & 0xff) + (UINT32)val;\r
+               if (val & SF) F |= NF;\r
+               if (res & 0x100) F |= HF | CF;\r
+               F |= SZP[(UINT8)(res & 0x07) ^ zB] & PF;\r
+               zF = F;\r
+               RET(12)\r
+\r
+/*-----------------------------------------\r
+ INIR/INDR\r
+-----------------------------------------*/\r
+\r
+       OPED(0xb2): // INIR\r
+               do\r
+               {\r
+                       val = IN(zBC);\r
+                       zB--;\r
+                       WRITE_MEM8(zHL++, val);\r
+                       USE_CYCLES(17)\r
+               } while (zB && (CPU->ICount > 0));\r
+               goto OP_INXR;\r
+\r
+       OPED(0xba): // INDR\r
+               do\r
+               {\r
+                       val = IN(zBC);\r
+                       zB--;\r
+                       WRITE_MEM8(zHL--, val);\r
+                       USE_CYCLES(17)\r
+               } while (zB && (CPU->ICount > 0));\r
+\r
+OP_INXR:\r
+               F = SZ[zB];\r
+               res = ((UINT32)(zC - 1) & 0xff) + (UINT32)val;\r
+               if (val & SF) F |= NF;\r
+               if (res & 0x100) F |= HF | CF;\r
+               F |= SZP[(UINT8)(res & 0x07) ^ zB] & PF;\r
+               zF = F;\r
+               if (zB)\r
+               {\r
+                       PC -= 2;\r
+#if CZ80_EMULATE_R_EXACTLY\r
+                       zR--;\r
+#endif\r
+                       goto Cz80_Exec_End;\r
+               }\r
+               ADD_CYCLES(5);\r
+               goto Cz80_Exec;\r
+\r
+/*-----------------------------------------\r
+ OUTI/OUTD\r
+-----------------------------------------*/\r
+\r
+       OPED(0xa3): // OUTI\r
+               val = READ_MEM8(zHL++);\r
+               zB--;\r
+               OUT(zBC, val);\r
+               goto OP_OUTX;\r
+\r
+       OPED(0xab): // OUTD\r
+               val = READ_MEM8(zHL--);\r
+               zB--;\r
+               OUT(zBC, val);\r
+\r
+OP_OUTX:\r
+               F = SZ[zB];\r
+               res = (UINT32)zL + (UINT32)val;\r
+               if (val & SF) F |= NF;\r
+               if (res & 0x100) F |= HF | CF;\r
+               F |= SZP[(UINT8)(res & 0x07) - zB] & PF;\r
+               zF = F;\r
+               RET(12)\r
+\r
+/*-----------------------------------------\r
+ OTIR/OTDR\r
+-----------------------------------------*/\r
+\r
+       OPED(0xb3): // OTIR\r
+               do\r
+               {\r
+                       val = READ_MEM8(zHL++);\r
+                       zB--;\r
+                       OUT(zBC, val);\r
+                       USE_CYCLES(17)\r
+               } while (zB && (CPU->ICount > 0));\r
+               goto OP_OTXR;\r
+\r
+       OPED(0xbb): // OTDR\r
+               do\r
+               {\r
+                       val = READ_MEM8(zHL--);\r
+                       zB--;\r
+                       OUT(zBC, val);\r
+                       USE_CYCLES(17)\r
+               } while (zB && (CPU->ICount > 0));\r
+\r
+OP_OTXR:\r
+               F = SZ[zB];\r
+               res = (UINT32)zL + (UINT32)val;\r
+               if (val & SF) F |= NF;\r
+               if (res & 0x100) F |= HF | CF;\r
+               F |= SZP[(UINT8)(res & 0x07) - zB] & PF;\r
+               zF = F;\r
+               if (zB)\r
+               {\r
+                       PC -= 2;\r
+#if CZ80_EMULATE_R_EXACTLY\r
+                       zR--;\r
+#endif\r
+                       goto Cz80_Exec_End;\r
+               }\r
+               ADD_CYCLES(5)\r
+               goto Cz80_Exec;\r
+       }\r
+\r
+#if !CZ80_USE_JUMPTABLE\r
+}\r
+#endif\r
diff --git a/cpu/cz80/cz80_opXY.c b/cpu/cz80/cz80_opXY.c
new file mode 100644 (file)
index 0000000..b02e401
--- /dev/null
@@ -0,0 +1,786 @@
+/******************************************************************************\r
+ *\r
+ * CZ80 XY opcode include source file\r
+ * CZ80 emulator version 0.9\r
+ * Copyright 2004-2005 Stéphane Dallongeville\r
+ *\r
+ * (Modified by NJ)\r
+ *\r
+ *****************************************************************************/\r
+\r
+#if CZ80_USE_JUMPTABLE\r
+       goto *JumpTableXY[Opcode];\r
+#else\r
+switch (Opcode)\r
+{\r
+#endif\r
+\r
+/*-----------------------------------------\r
+ NOP\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x00): // NOP\r
+\r
+/*-----------------------------------------\r
+ LD r8 (same register)\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x40): // LD   B,B\r
+       OPXY(0x49): // LD   C,C\r
+       OPXY(0x52): // LD   D,D\r
+       OPXY(0x5b): // LD   E,E\r
+       OPXY(0x64): // LD   H,H\r
+       OPXY(0x6d): // LD   L,L\r
+       OPXY(0x7f): // LD   A,A\r
+               RET(4)\r
+\r
+/*-----------------------------------------\r
+ LD r8\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x41): // LD   B,C\r
+       OPXY(0x42): // LD   B,D\r
+       OPXY(0x43): // LD   B,E\r
+       OPXY(0x47): // LD   B,A\r
+\r
+       OPXY(0x48): // LD   C,B\r
+       OPXY(0x4a): // LD   C,D\r
+       OPXY(0x4b): // LD   C,E\r
+       OPXY(0x4f): // LD   C,A\r
+\r
+       OPXY(0x50): // LD   D,B\r
+       OPXY(0x51): // LD   D,C\r
+       OPXY(0x53): // LD   D,E\r
+       OPXY(0x57): // LD   D,A\r
+\r
+       OPXY(0x58): // LD   E,B\r
+       OPXY(0x59): // LD   E,C\r
+       OPXY(0x5a): // LD   E,D\r
+       OPXY(0x5f): // LD   E,A\r
+\r
+       OPXY(0x78): // LD   A,B\r
+       OPXY(0x79): // LD   A,C\r
+       OPXY(0x7a): // LD   A,D\r
+       OPXY(0x7b): // LD   A,E\r
+               goto OP_LD_R_R;\r
+\r
+       OPXY(0x44): // LD   B,HX\r
+       OPXY(0x4c): // LD   C,HX\r
+       OPXY(0x54): // LD   D,HX\r
+       OPXY(0x5c): // LD   E,HX\r
+       OPXY(0x7c): // LD   A,HX\r
+               zR8((Opcode >> 3) & 7) = data->B.H;\r
+               RET(5)\r
+\r
+       OPXY(0x45): // LD   B,LX\r
+       OPXY(0x4d): // LD   C,LX\r
+       OPXY(0x55): // LD   D,LX\r
+       OPXY(0x5d): // LD   E,LX\r
+       OPXY(0x7d): // LD   A,LX\r
+               zR8((Opcode >> 3) & 7) = data->B.L;\r
+               RET(5)\r
+\r
+       OPXY(0x60): // LD   HX,B\r
+       OPXY(0x61): // LD   HX,C\r
+       OPXY(0x62): // LD   HX,D\r
+       OPXY(0x63): // LD   HX,E\r
+       OPXY(0x67): // LD   HX,A\r
+               data->B.H = zR8(Opcode & 7);\r
+               RET(5)\r
+\r
+       OPXY(0x68): // LD   LX,B\r
+       OPXY(0x69): // LD   LX,C\r
+       OPXY(0x6a): // LD   LX,D\r
+       OPXY(0x6b): // LD   LX,E\r
+       OPXY(0x6f): // LD   LX,A\r
+               data->B.L = zR8(Opcode & 7);\r
+               RET(5)\r
+\r
+       OPXY(0x65): // LD   HX,LX\r
+               data->B.H = data->B.L;\r
+               RET(5)\r
+\r
+       OPXY(0x6c): // LD   LX,HX\r
+               data->B.L = data->B.H;\r
+               RET(5)\r
+\r
+       OPXY(0x06): // LD   B,#imm\r
+       OPXY(0x0e): // LD   C,#imm\r
+       OPXY(0x16): // LD   D,#imm\r
+       OPXY(0x1e): // LD   E,#imm\r
+       OPXY(0x3e): // LD   A,#imm\r
+               goto OP_LD_R_imm;\r
+\r
+       OPXY(0x26): // LD   HX,#imm\r
+               data->B.H = READ_ARG();\r
+               RET(5)\r
+\r
+       OPXY(0x2e): // LD   LX,#imm\r
+               data->B.L = READ_ARG();\r
+               RET(5)\r
+\r
+       OPXY(0x0a): // LD   A,(BC)\r
+               goto OP_LOAD_A_mBC;\r
+\r
+       OPXY(0x1a): // LD   A,(DE)\r
+               goto OP_LOAD_A_mDE;\r
+\r
+       OPXY(0x3a): // LD   A,(nn)\r
+               goto OP_LOAD_A_mNN;\r
+\r
+       OPXY(0x02): // LD   (BC),A\r
+               goto OP_LOAD_mBC_A;\r
+\r
+       OPXY(0x12): // LD   (DE),A\r
+               goto OP_LOAD_mDE_A;\r
+\r
+       OPXY(0x32): // LD   (nn),A\r
+               goto OP_LOAD_mNN_A;\r
+\r
+       OPXY(0x46): // LD   B,(IX+o)\r
+       OPXY(0x4e): // LD   C,(IX+o)\r
+       OPXY(0x56): // LD   D,(IX+o)\r
+       OPXY(0x5e): // LD   E,(IX+o)\r
+       OPXY(0x66): // LD   H,(IX+o)\r
+       OPXY(0x6e): // LD   L,(IX+o)\r
+       OPXY(0x7e): // LD   A,(IX+o)\r
+               adr = data->W + (INT8)READ_ARG();\r
+               zR8((Opcode >> 3) & 7) = READ_MEM8(adr);\r
+               RET(15)\r
+\r
+       OPXY(0x70): // LD   (IX+o),B\r
+       OPXY(0x71): // LD   (IX+o),C\r
+       OPXY(0x72): // LD   (IX+o),D\r
+       OPXY(0x73): // LD   (IX+o),E\r
+       OPXY(0x74): // LD   (IX+o),H\r
+       OPXY(0x75): // LD   (IX+o),L\r
+       OPXY(0x77): // LD   (IX+o),A\r
+               adr = data->W + (INT8)READ_ARG();\r
+               WRITE_MEM8(adr, zR8(Opcode & 7));\r
+               RET(15)\r
+\r
+       OPXY(0x36): // LD   (IX+o),#imm\r
+               adr = data->W + (INT8)READ_ARG();\r
+               WRITE_MEM8(adr, READ_ARG());\r
+               RET(15)\r
+\r
+/*-----------------------------------------\r
+ LD r16\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x01): // LD   BC,nn\r
+       OPXY(0x11): // LD   DE,nn\r
+               goto OP_LOAD_RR_imm16;\r
+\r
+       OPXY(0x21): // LD   IX,nn\r
+               data->W = READ_ARG16();\r
+               RET(10)\r
+\r
+       OPXY(0x31): // LD   SP,nn\r
+               goto OP_LOAD_SP_imm16;\r
+\r
+       OPXY(0x2a): // LD   IX,(w)\r
+               goto OP_LD_xx_mNN;\r
+\r
+       OPXY(0x22): // LD   (w),IX\r
+               goto OP_LD_mNN_xx;\r
+\r
+       OPXY(0xf9): // LD   SP,IX\r
+               goto OP_LD_SP_xx;\r
+\r
+/*-----------------------------------------\r
+ POP\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xc1): // POP  BC\r
+       OPXY(0xd1): // POP  DE\r
+       OPXY(0xf1): // POP  AF\r
+               goto OP_POP_RR;\r
+\r
+       OPXY(0xe1): // POP  IX\r
+               goto OP_POP;\r
+\r
+/*-----------------------------------------\r
+ PUSH\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xc5): // PUSH BC\r
+       OPXY(0xd5): // PUSH DE\r
+       OPXY(0xf5): // PUSH AF\r
+               goto OP_PUSH_RR;\r
+\r
+       OPXY(0xe5): // PUSH IX\r
+               goto OP_PUSH;\r
+\r
+/*-----------------------------------------\r
+ EX\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x08): // EX   AF,AF'\r
+               goto OP_EX_AF_AF2;\r
+\r
+       OPXY(0xeb): // EX   DE,HL\r
+               goto OP_EX_DE_HL;\r
+\r
+       OPXY(0xd9): // EXX\r
+               goto OP_EXX;\r
+\r
+       OPXY(0xe3): // EX   (SP),IX\r
+               goto OP_EX_xx_mSP;\r
+\r
+/*-----------------------------------------\r
+ INC r8\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x04): // INC  B\r
+       OPXY(0x0c): // INC  C\r
+       OPXY(0x14): // INC  D\r
+       OPXY(0x1c): // INC  E\r
+       OPXY(0x3c): // INC  A\r
+               goto OP_INC_R;\r
+\r
+       OPXY(0x24): // INC  HX\r
+               data->B.H++;\r
+               zF = (zF & CF) | SZHV_inc[data->B.H];\r
+               RET(5)\r
+\r
+       OPXY(0x2c): // INC  LX\r
+               data->B.L++;\r
+               zF = (zF & CF) | SZHV_inc[data->B.L];\r
+               RET(5)\r
+\r
+       OPXY(0x34): // INC  (IX+o)\r
+               adr = data->W + (INT8)READ_ARG();\r
+               USE_CYCLES(8)\r
+               goto OP_INC_m;\r
+\r
+/*-----------------------------------------\r
+ DEC r8\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x05): // DEC  B\r
+       OPXY(0x0d): // DEC  C\r
+       OPXY(0x15): // DEC  D\r
+       OPXY(0x1d): // DEC  E\r
+       OPXY(0x3d): // DEC  A\r
+               goto OP_DEC_R;\r
+\r
+       OPXY(0x25): // DEC  HX\r
+               data->B.H--;\r
+               zF = (zF & CF) | SZHV_dec[data->B.H];\r
+               RET(5)\r
+\r
+       OPXY(0x2d): // DEC  LX\r
+               data->B.L--;\r
+               zF = (zF & CF) | SZHV_dec[data->B.L];\r
+               RET(5)\r
+\r
+       OPXY(0x35): // DEC  (IX+o)\r
+               adr = data->W + (INT8)READ_ARG();\r
+               USE_CYCLES(8)\r
+               goto OP_DEC_m;\r
+\r
+/*-----------------------------------------\r
+ ADD r8\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x80): // ADD  A,B\r
+       OPXY(0x81): // ADD  A,C\r
+       OPXY(0x82): // ADD  A,D\r
+       OPXY(0x83): // ADD  A,E\r
+       OPXY(0x87): // ADD  A,A\r
+               goto OP_ADD_R;\r
+\r
+       OPXY(0xc6): // ADD  A,n\r
+               goto OP_ADD_imm;\r
+\r
+       OPXY(0x84): // ADD  A,HX\r
+               val = data->B.H;\r
+               USE_CYCLES(1)\r
+               goto OP_ADD;\r
+\r
+       OPXY(0x85): // ADD  A,LX\r
+               val = data->B.L;\r
+               USE_CYCLES(1)\r
+               goto OP_ADD;\r
+\r
+       OPXY(0x86): // ADD  A,(IX+o)\r
+               adr = data->W + (INT8)READ_ARG();\r
+               val = READ_MEM8(adr);\r
+               USE_CYCLES(11)\r
+               goto OP_ADD;\r
+\r
+/*-----------------------------------------\r
+ ADC r8\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x88): // ADC  A,B\r
+       OPXY(0x89): // ADC  A,C\r
+       OPXY(0x8a): // ADC  A,D\r
+       OPXY(0x8b): // ADC  A,E\r
+       OPXY(0x8f): // ADC  A,A\r
+               goto OP_ADC_R;\r
+\r
+       OPXY(0xce): // ADC  A,n\r
+               goto OP_ADC_imm;\r
+\r
+       OPXY(0x8c): // ADC  A,HX\r
+               val = data->B.H;\r
+               USE_CYCLES(1)\r
+               goto OP_ADC;\r
+\r
+       OPXY(0x8d): // ADC  A,LX\r
+               val = data->B.L;\r
+               USE_CYCLES(1)\r
+               goto OP_ADC;\r
+\r
+       OPXY(0x8e): // ADC  A,(IX+o)\r
+               adr = data->W + (INT8)READ_ARG();\r
+               val = READ_MEM8(adr);\r
+               USE_CYCLES(11)\r
+               goto OP_ADC;\r
+\r
+/*-----------------------------------------\r
+ SUB r8\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x90): // SUB  B\r
+       OPXY(0x91): // SUB  C\r
+       OPXY(0x92): // SUB  D\r
+       OPXY(0x93): // SUB  E\r
+       OPXY(0x97): // SUB  A\r
+               goto OP_SUB_R;\r
+\r
+       OPXY(0xd6): // SUB  A,n\r
+               goto OP_SUB_imm;\r
+\r
+       OPXY(0x94): // SUB  HX\r
+               val = data->B.H;\r
+               USE_CYCLES(1)\r
+               goto OP_SUB;\r
+\r
+       OPXY(0x95): // SUB  LX\r
+               val = data->B.L;\r
+               USE_CYCLES(1)\r
+               goto OP_SUB;\r
+\r
+       OPXY(0x96): // SUB  (IX+o)\r
+               adr = data->W + (INT8)READ_ARG();\r
+               val = READ_MEM8(adr);\r
+               USE_CYCLES(11)\r
+               goto OP_SUB;\r
+\r
+/*-----------------------------------------\r
+ SBC r8\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x98): // SBC  A,B\r
+       OPXY(0x99): // SBC  A,C\r
+       OPXY(0x9a): // SBC  A,D\r
+       OPXY(0x9b): // SBC  A,E\r
+       OPXY(0x9f): // SBC  A,A\r
+               goto OP_SBC_R;\r
+\r
+       OPXY(0xde): // SBC  A,n\r
+               goto OP_SBC_imm;\r
+\r
+       OPXY(0x9c): // SBC  A,HX\r
+               val = data->B.H;\r
+               USE_CYCLES(1)\r
+               goto OP_SBC;\r
+\r
+       OPXY(0x9d): // SBC  A,LX\r
+               val = data->B.L;\r
+               USE_CYCLES(1)\r
+               goto OP_SBC;\r
+\r
+       OPXY(0x9e): // SBC  A,(IX+o)\r
+               adr = data->W + (INT8)READ_ARG();\r
+               val = READ_MEM8(adr);\r
+               USE_CYCLES(11)\r
+               goto OP_SBC;\r
+\r
+/*-----------------------------------------\r
+ CP r8\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xb8): // CP   B\r
+       OPXY(0xb9): // CP   C\r
+       OPXY(0xba): // CP   D\r
+       OPXY(0xbb): // CP   E\r
+       OPXY(0xbf): // CP   A\r
+               goto OP_CP_R;\r
+\r
+       OPXY(0xfe): // CP   n\r
+               goto OP_CP_imm;\r
+\r
+       OPXY(0xbc): // CP   HX\r
+               val = data->B.H;\r
+               USE_CYCLES(1)\r
+               goto OP_CP;\r
+\r
+       OPXY(0xbd): // CP   LX\r
+               val = data->B.L;\r
+               USE_CYCLES(1)\r
+               goto OP_CP;\r
+\r
+       OPXY(0xbe): // CP   (IX+o)\r
+               adr = data->W + (INT8)READ_ARG();\r
+               val = READ_MEM8(adr);\r
+               USE_CYCLES(11)\r
+               goto OP_CP;\r
+\r
+/*-----------------------------------------\r
+ AND r8\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xa0): // AND  B\r
+       OPXY(0xa1): // AND  C\r
+       OPXY(0xa2): // AND  D\r
+       OPXY(0xa3): // AND  E\r
+       OPXY(0xa7): // AND  A\r
+               goto OP_AND_R;\r
+\r
+       OPXY(0xe6): // AND  A,n\r
+               goto OP_AND_imm;\r
+\r
+       OPXY(0xa4): // AND  HX\r
+               val = data->B.H;\r
+               USE_CYCLES(1)\r
+               goto OP_AND;\r
+\r
+       OPXY(0xa5): // AND  LX\r
+               val = data->B.L;\r
+               USE_CYCLES(1)\r
+               goto OP_AND;\r
+\r
+       OPXY(0xa6): // AND  (IX+o)\r
+               adr = data->W + (INT8)READ_ARG();\r
+               val = READ_MEM8(adr);\r
+               USE_CYCLES(11)\r
+               goto OP_AND;\r
+\r
+/*-----------------------------------------\r
+ XOR r8\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xa8): // XOR  B\r
+       OPXY(0xa9): // XOR  C\r
+       OPXY(0xaa): // XOR  D\r
+       OPXY(0xab): // XOR  E\r
+       OPXY(0xaf): // XOR  A\r
+               goto OP_XOR_R;\r
+\r
+       OPXY(0xee): // XOR  A,n\r
+               goto OP_XOR_imm;\r
+\r
+       OPXY(0xac): // XOR  HX\r
+               val = data->B.H;\r
+               USE_CYCLES(1)\r
+               goto OP_XOR;\r
+\r
+       OPXY(0xad): // XOR  LX\r
+               val = data->B.L;\r
+               USE_CYCLES(1)\r
+               goto OP_XOR;\r
+\r
+       OPXY(0xae): // XOR  (IX+o)\r
+               adr = data->W + (INT8)READ_ARG();\r
+               val = READ_MEM8(adr);\r
+               USE_CYCLES(11)\r
+               goto OP_XOR;\r
+\r
+/*-----------------------------------------\r
+ OR r8\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xb0): // OR   B\r
+       OPXY(0xb1): // OR   C\r
+       OPXY(0xb2): // OR   D\r
+       OPXY(0xb3): // OR   E\r
+       OPXY(0xb7): // OR   A\r
+               goto OP_OR_R;\r
+\r
+       OPXY(0xf6): // OR   A,n\r
+               goto OP_OR_imm;\r
+\r
+       OPXY(0xb4): // OR   HX\r
+               val = data->B.H;\r
+               USE_CYCLES(1)\r
+               goto OP_OR;\r
+\r
+       OPXY(0xb5): // OR   LX\r
+               val = data->B.L;\r
+               USE_CYCLES(1)\r
+               goto OP_OR;\r
+\r
+       OPXY(0xb6): // OR   (IX+o)\r
+               adr = data->W + (INT8)READ_ARG();\r
+               val = READ_MEM8(adr);\r
+               USE_CYCLES(11)\r
+               goto OP_OR;\r
+\r
+/*-----------------------------------------\r
+ MISC ARITHMETIC & CPU CONTROL\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x27): // DAA\r
+               goto OP_DAA;\r
+\r
+       OPXY(0x2f): // CPL\r
+               goto OP_CPL;\r
+\r
+       OPXY(0x37): // SCF\r
+               goto OP_SCF;\r
+\r
+       OPXY(0x3f): // CCF\r
+               goto OP_CCF;\r
+\r
+       OPXY(0x76): // HALT\r
+               goto OP_HALT;\r
+\r
+       OPXY(0xf3): // DI\r
+               goto OP_DI;\r
+\r
+       OPXY(0xfb): // EI\r
+               goto OP_EI;\r
+\r
+/*-----------------------------------------\r
+ INC r16\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x03): // INC  BC\r
+               goto OP_INC_BC;\r
+\r
+       OPXY(0x13): // INC  DE\r
+               goto OP_INC_DE;\r
+\r
+       OPXY(0x23): // INC  IX\r
+               goto OP_INC_xx;\r
+\r
+       OPXY(0x33): // INC  SP\r
+               goto OP_INC_SP;\r
+\r
+/*-----------------------------------------\r
+ DEC r16\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x0b): // DEC  BC\r
+               goto OP_DEC_BC;\r
+\r
+       OPXY(0x1b): // DEC  DE\r
+               goto OP_DEC_DE;\r
+\r
+       OPXY(0x2b): // DEC  IX\r
+               goto OP_DEC_xx;\r
+\r
+       OPXY(0x3b): // DEC  SP\r
+               goto OP_DEC_SP;\r
+\r
+/*-----------------------------------------\r
+ ADD r16\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x09): // ADD  IX,BC\r
+               goto OP_ADD16_xx_BC;\r
+\r
+       OPXY(0x19): // ADD  IX,DE\r
+               goto OP_ADD16_xx_DE;\r
+\r
+       OPXY(0x29): // ADD  IX,IX\r
+               goto OP_ADD16_xx_xx;\r
+\r
+       OPXY(0x39): // ADD  IX,SP\r
+               goto OP_ADD16_xx_SP;\r
+\r
+/*-----------------------------------------\r
+ ROTATE\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x07): // RLCA\r
+               goto OP_RLCA;\r
+\r
+       OPXY(0x0f): // RRCA\r
+               goto OP_RRCA;\r
+\r
+       OPXY(0x17): // RLA\r
+               goto OP_RLA;\r
+\r
+       OPXY(0x1f): // RRA\r
+               goto OP_RRA;\r
+\r
+/*-----------------------------------------\r
+ JP\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xc3): // JP   nn\r
+               goto OP_JP;\r
+\r
+       OPXY(0xe9): // JP   (IX)\r
+               goto OP_JP_xx;\r
+\r
+       OPXY(0xc2): // JP   NZ,nn\r
+               goto OP_JP_NZ;\r
+\r
+       OPXY(0xca): // JP   Z,nn\r
+               goto OP_JP_Z;\r
+\r
+       OPXY(0xd2): // JP   NC,nn\r
+               goto OP_JP_NC;\r
+\r
+       OPXY(0xda): // JP   C,nn\r
+               goto OP_JP_C;\r
+\r
+       OPXY(0xe2): // JP   PO,nn\r
+               goto OP_JP_PO;\r
+\r
+       OPXY(0xea): // JP   PE,nn\r
+               goto OP_JP_PE;\r
+\r
+       OPXY(0xf2): // JP   P,nn\r
+               goto OP_JP_P;\r
+\r
+       OPXY(0xfa): // JP   M,nn\r
+               goto OP_JP_M;\r
+\r
+/*-----------------------------------------\r
+ JR\r
+-----------------------------------------*/\r
+\r
+       OPXY(0x10): // DJNZ n\r
+               goto OP_DJNZ;\r
+\r
+       OPXY(0x18): // JR   n\r
+               goto OP_JR;\r
+\r
+       OPXY(0x20): // JR   NZ,n\r
+               goto OP_JR_NZ;\r
+\r
+       OPXY(0x28): // JR   Z,n\r
+               goto OP_JR_Z;\r
+\r
+       OPXY(0x30): // JR   NC,n\r
+               goto OP_JR_NC;\r
+\r
+       OPXY(0x38): // JR   C,n\r
+               goto OP_JR_C;\r
+\r
+/*-----------------------------------------\r
+ CALL\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xcd): // CALL nn\r
+               goto OP_CALL;\r
+\r
+       OPXY(0xc4): // CALL NZ,nn\r
+               goto OP_CALL_NZ;\r
+\r
+       OPXY(0xcc): // CALL Z,nn\r
+               goto OP_CALL_Z;\r
+\r
+       OPXY(0xd4): // CALL NC,nn\r
+               goto OP_CALL_NC;\r
+\r
+       OPXY(0xdc): // CALL C,nn\r
+               goto OP_CALL_C;\r
+\r
+       OPXY(0xe4): // CALL PO,nn\r
+               goto OP_CALL_PO;\r
+\r
+       OPXY(0xec): // CALL PE,nn\r
+               goto OP_CALL_PE;\r
+\r
+       OPXY(0xf4): // CALL P,nn\r
+               goto OP_CALL_P;\r
+\r
+       OPXY(0xfc): // CALL M,nn\r
+               goto OP_CALL_M;\r
+\r
+/*-----------------------------------------\r
+ RET\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xc9): // RET\r
+               goto OP_RET;\r
+\r
+       OPXY(0xc0): // RET  NZ\r
+               goto OP_RET_NZ;\r
+\r
+       OPXY(0xc8): // RET  Z\r
+               goto OP_RET_Z;\r
+\r
+       OPXY(0xd0): // RET  NC\r
+               goto OP_RET_NC;\r
+\r
+       OPXY(0xd8): // RET  C\r
+               goto OP_RET_C;\r
+\r
+       OPXY(0xe0): // RET  PO\r
+               goto OP_RET_PO;\r
+\r
+       OPXY(0xe8): // RET  PE\r
+               goto OP_RET_PE;\r
+\r
+       OPXY(0xf0): // RET  P\r
+               goto OP_RET_P;\r
+\r
+       OPXY(0xf8): // RET  M\r
+               goto OP_RET_M;\r
+\r
+/*-----------------------------------------\r
+ RST\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xc7): // RST  0\r
+       OPXY(0xcf): // RST  1\r
+       OPXY(0xd7): // RST  2\r
+       OPXY(0xdf): // RST  3\r
+       OPXY(0xe7): // RST  4\r
+       OPXY(0xef): // RST  5\r
+       OPXY(0xf7): // RST  6\r
+       OPXY(0xff): // RST  7\r
+               goto OP_RST;\r
+\r
+/*-----------------------------------------\r
+ OUT\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xd3): // OUT  (n),A\r
+               goto OP_OUT_mN_A;\r
+\r
+/*-----------------------------------------\r
+ IN\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xdb): // IN   A,(n)\r
+               goto OP_IN_A_mN;\r
+\r
+/*-----------------------------------------\r
+ PREFIX\r
+-----------------------------------------*/\r
+\r
+       OPXY(0xcb): // XYCB prefix (BIT & SHIFT INSTRUCTIONS)\r
+       {\r
+               UINT8 src;\r
+               UINT8 res;\r
+\r
+               adr = data->W + (INT8)READ_ARG();\r
+               Opcode = READ_ARG();\r
+#if CZ80_EMULATE_R_EXACTLY\r
+               zR++;\r
+#endif\r
+               #include "cz80_opXYCB.c"\r
+       }\r
+\r
+       OPXY(0xed): // ED prefix\r
+               goto ED_PREFIX;\r
+\r
+       OPXY(0xdd): // DD prefix (IX)\r
+               goto DD_PREFIX;\r
+\r
+       OPXY(0xfd): // FD prefix (IY)\r
+               goto FD_PREFIX;\r
+\r
+#if !CZ80_USE_JUMPTABLE\r
+}\r
+#endif\r
diff --git a/cpu/cz80/cz80_opXYCB.c b/cpu/cz80/cz80_opXYCB.c
new file mode 100644 (file)
index 0000000..b706580
--- /dev/null
@@ -0,0 +1,474 @@
+/******************************************************************************\r
+ *\r
+ * CZ80 XYCB opcode include source file\r
+ * CZ80 emulator version 0.9\r
+ * Copyright 2004-2005 Stéphane Dallongeville\r
+ *\r
+ * (Modified by NJ)\r
+ *\r
+ *****************************************************************************/\r
+\r
+#if CZ80_USE_JUMPTABLE\r
+       goto *JumpTableXYCB[Opcode];\r
+#else\r
+switch (Opcode)\r
+{\r
+#endif\r
+\r
+/*-----------------------------------------\r
+ RLC\r
+-----------------------------------------*/\r
+\r
+       OPXYCB(0x00):   // RLC  (Ix+d), B\r
+       OPXYCB(0x01):   // RLC  (Ix+d), C\r
+       OPXYCB(0x02):   // RLC  (Ix+d), D\r
+       OPXYCB(0x03):   // RLC  (Ix+d), E\r
+       OPXYCB(0x04):   // RLC  (Ix+d), H\r
+       OPXYCB(0x05):   // RLC  (Ix+d), L\r
+       OPXYCB(0x07):   // RLC  (Ix+d), A\r
+               src = READ_MEM8(adr);\r
+               res = ((src << 1) | (src >> 7)) & 0xff;\r
+               zF = SZP[res] | (src >> 7);\r
+               zR8(Opcode) = res;\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+       OPXYCB(0x06):   // RLC  (Ix+d)\r
+               src = READ_MEM8(adr);\r
+               res = ((src << 1) | (src >> 7)) & 0xff;\r
+               zF = SZP[res] | (src >> 7);\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+/*-----------------------------------------\r
+ RRC\r
+-----------------------------------------*/\r
+\r
+       OPXYCB(0x08):   // RRC  (Ix+d), B\r
+       OPXYCB(0x09):   // RRC  (Ix+d), C\r
+       OPXYCB(0x0a):   // RRC  (Ix+d), D\r
+       OPXYCB(0x0b):   // RRC  (Ix+d), E\r
+       OPXYCB(0x0c):   // RRC  (Ix+d), H\r
+       OPXYCB(0x0d):   // RRC  (Ix+d), L\r
+       OPXYCB(0x0f):   // RRC  (Ix+d), A\r
+               src = READ_MEM8(adr);\r
+               res = ((src >> 1) | (src << 7)) & 0xff;\r
+               zF = SZP[res] | (src & CF);\r
+               zR8(Opcode & 7) = res;\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+       OPXYCB(0x0e):   // RRC  (Ix+d)\r
+               src = READ_MEM8(adr);\r
+               res = ((src >> 1) | (src << 7)) & 0xff;\r
+               zF = SZP[res] | (src & CF);\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+/*-----------------------------------------\r
+ RL\r
+-----------------------------------------*/\r
+\r
+       OPXYCB(0x10):   // RL   (Ix+d), B\r
+       OPXYCB(0x11):   // RL   (Ix+d), C\r
+       OPXYCB(0x12):   // RL   (Ix+d), D\r
+       OPXYCB(0x13):   // RL   (Ix+d), E\r
+       OPXYCB(0x14):   // RL   (Ix+d), H\r
+       OPXYCB(0x15):   // RL   (Ix+d), L\r
+       OPXYCB(0x17):   // RL   (Ix+d), A\r
+               src = READ_MEM8(adr);\r
+               res = ((src << 1) | (zF & CF)) & 0xff;\r
+               zF = SZP[res] | (src >> 7);\r
+               zR8(Opcode & 7) = res;\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+       OPXYCB(0x16):   // RL   (Ix+d)\r
+               src = READ_MEM8(adr);\r
+               res = ((src << 1) | (zF & CF)) & 0xff;\r
+               zF = SZP[res] | (src >> 7);\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+/*-----------------------------------------\r
+ RR\r
+-----------------------------------------*/\r
+\r
+       OPXYCB(0x18):   // RR   (Ix+d), B\r
+       OPXYCB(0x19):   // RR   (Ix+d), C\r
+       OPXYCB(0x1a):   // RR   (Ix+d), D\r
+       OPXYCB(0x1b):   // RR   (Ix+d), E\r
+       OPXYCB(0x1c):   // RR   (Ix+d), H\r
+       OPXYCB(0x1d):   // RR   (Ix+d), L\r
+       OPXYCB(0x1f):   // RR   (Ix+d), A\r
+               src = READ_MEM8(adr);\r
+               res = ((src >> 1) | (zF << 7)) & 0xff;\r
+               zF = SZP[res] | (src & CF);\r
+               zR8(Opcode & 7) = res;\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+       OPXYCB(0x1e):   // RR   (Ix+d)\r
+               src = READ_MEM8(adr);\r
+               res = ((src >> 1) | (zF << 7)) & 0xff;\r
+               zF = SZP[res] | (src & CF);\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+/*-----------------------------------------\r
+ SLA\r
+-----------------------------------------*/\r
+\r
+       OPXYCB(0x20):   // SLA  (Ix+d), B\r
+       OPXYCB(0x21):   // SLA  (Ix+d), C\r
+       OPXYCB(0x22):   // SLA  (Ix+d), D\r
+       OPXYCB(0x23):   // SLA  (Ix+d), E\r
+       OPXYCB(0x24):   // SLA  (Ix+d), H\r
+       OPXYCB(0x25):   // SLA  (Ix+d), L\r
+       OPXYCB(0x27):   // SLA  (Ix+d), A\r
+               src = READ_MEM8(adr);\r
+               res = (src << 1) & 0xff;\r
+               zF = SZP[res] | (src >> 7);\r
+               zR8(Opcode & 7) = res;\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+       OPXYCB(0x26):   // SLA  (Ix+d)\r
+               src = READ_MEM8(adr);\r
+               res = (src << 1) & 0xff;\r
+               zF = SZP[res] | (src >> 7);\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+/*-----------------------------------------\r
+ SRA\r
+-----------------------------------------*/\r
+\r
+       OPXYCB(0x28):   // SRA  (Ix+d), B\r
+       OPXYCB(0x29):   // SRA  (Ix+d), C\r
+       OPXYCB(0x2a):   // SRA  (Ix+d), D\r
+       OPXYCB(0x2b):   // SRA  (Ix+d), E\r
+       OPXYCB(0x2c):   // SRA  (Ix+d), H\r
+       OPXYCB(0x2d):   // SRA  (Ix+d), L\r
+       OPXYCB(0x2f):   // SRA  (Ix+d), A\r
+               src = READ_MEM8(adr);\r
+               res = ((src >> 1) | (src & 0x80)) & 0xff;\r
+               zF = SZP[res] | (src & CF);\r
+               zR8(Opcode & 7) = res;\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+       OPXYCB(0x2e):   // SRA  (Ix+d)\r
+               src = READ_MEM8(adr);\r
+               res = ((src >> 1) | (src & 0x80)) & 0xff;\r
+               zF = SZP[res] | (src & CF);\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+/*-----------------------------------------\r
+ SLL\r
+-----------------------------------------*/\r
+\r
+       OPXYCB(0x30):   // SLL  (Ix+d), B\r
+       OPXYCB(0x31):   // SLL  (Ix+d), C\r
+       OPXYCB(0x32):   // SLL  (Ix+d), D\r
+       OPXYCB(0x33):   // SLL  (Ix+d), E\r
+       OPXYCB(0x34):   // SLL  (Ix+d), H\r
+       OPXYCB(0x35):   // SLL  (Ix+d), L\r
+       OPXYCB(0x37):   // SLL  (Ix+d), A\r
+               src = READ_MEM8(adr);\r
+               res = ((src << 1) | 0x01) & 0xff;\r
+               zF = SZP[res] | (src >> 7);\r
+               zR8(Opcode & 7) = res;\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+       OPXYCB(0x36):   // SLL  (Ix+d)\r
+               src = READ_MEM8(adr);\r
+               res = ((src << 1) | 0x01) & 0xff;\r
+               zF = SZP[res] | (src >> 7);\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+/*-----------------------------------------\r
+ SRL\r
+-----------------------------------------*/\r
+\r
+       OPXYCB(0x38):   // SRL  (Ix+d), B\r
+       OPXYCB(0x39):   // SRL  (Ix+d), C\r
+       OPXYCB(0x3a):   // SRL  (Ix+d), D\r
+       OPXYCB(0x3b):   // SRL  (Ix+d), E\r
+       OPXYCB(0x3c):   // SRL  (Ix+d), H\r
+       OPXYCB(0x3d):   // SRL  (Ix+d), L\r
+       OPXYCB(0x3f):   // SRL  (Ix+d), A\r
+               src = READ_MEM8(adr);\r
+               res = (src >> 1) & 0xff;\r
+               zF = SZP[res] | (src & CF);\r
+               zR8(Opcode & 7) = res;\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+       OPXYCB(0x3e):   // SRL  (Ix+d)\r
+               src = READ_MEM8(adr);\r
+               res = (src >> 1) & 0xff;\r
+               zF = SZP[res] | (src & CF);\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+/*-----------------------------------------\r
+ BIT\r
+-----------------------------------------*/\r
+\r
+       OPXYCB(0x40):   // BIT  0,(Ix+d)\r
+       OPXYCB(0x41):   // BIT  0,(Ix+d)\r
+       OPXYCB(0x42):   // BIT  0,(Ix+d)\r
+       OPXYCB(0x43):   // BIT  0,(Ix+d)\r
+       OPXYCB(0x44):   // BIT  0,(Ix+d)\r
+       OPXYCB(0x45):   // BIT  0,(Ix+d)\r
+       OPXYCB(0x47):   // BIT  0,(Ix+d)\r
+\r
+       OPXYCB(0x48):   // BIT  1,(Ix+d)\r
+       OPXYCB(0x49):   // BIT  1,(Ix+d)\r
+       OPXYCB(0x4a):   // BIT  1,(Ix+d)\r
+       OPXYCB(0x4b):   // BIT  1,(Ix+d)\r
+       OPXYCB(0x4c):   // BIT  1,(Ix+d)\r
+       OPXYCB(0x4d):   // BIT  1,(Ix+d)\r
+       OPXYCB(0x4f):   // BIT  1,(Ix+d)\r
+\r
+       OPXYCB(0x50):   // BIT  2,(Ix+d)\r
+       OPXYCB(0x51):   // BIT  2,(Ix+d)\r
+       OPXYCB(0x52):   // BIT  2,(Ix+d)\r
+       OPXYCB(0x53):   // BIT  2,(Ix+d)\r
+       OPXYCB(0x54):   // BIT  2,(Ix+d)\r
+       OPXYCB(0x55):   // BIT  2,(Ix+d)\r
+       OPXYCB(0x57):   // BIT  2,(Ix+d)\r
+\r
+       OPXYCB(0x58):   // BIT  3,(Ix+d)\r
+       OPXYCB(0x59):   // BIT  3,(Ix+d)\r
+       OPXYCB(0x5a):   // BIT  3,(Ix+d)\r
+       OPXYCB(0x5b):   // BIT  3,(Ix+d)\r
+       OPXYCB(0x5c):   // BIT  3,(Ix+d)\r
+       OPXYCB(0x5d):   // BIT  3,(Ix+d)\r
+       OPXYCB(0x5f):   // BIT  3,(Ix+d)\r
+\r
+       OPXYCB(0x60):   // BIT  4,(Ix+d)\r
+       OPXYCB(0x61):   // BIT  4,(Ix+d)\r
+       OPXYCB(0x62):   // BIT  4,(Ix+d)\r
+       OPXYCB(0x63):   // BIT  4,(Ix+d)\r
+       OPXYCB(0x64):   // BIT  4,(Ix+d)\r
+       OPXYCB(0x65):   // BIT  4,(Ix+d)\r
+       OPXYCB(0x67):   // BIT  4,(Ix+d)\r
+\r
+       OPXYCB(0x68):   // BIT  5,(Ix+d)\r
+       OPXYCB(0x69):   // BIT  5,(Ix+d)\r
+       OPXYCB(0x6a):   // BIT  5,(Ix+d)\r
+       OPXYCB(0x6b):   // BIT  5,(Ix+d)\r
+       OPXYCB(0x6c):   // BIT  5,(Ix+d)\r
+       OPXYCB(0x6d):   // BIT  5,(Ix+d)\r
+       OPXYCB(0x6f):   // BIT  5,(Ix+d)\r
+\r
+       OPXYCB(0x70):   // BIT  6,(Ix+d)\r
+       OPXYCB(0x71):   // BIT  6,(Ix+d)\r
+       OPXYCB(0x72):   // BIT  6,(Ix+d)\r
+       OPXYCB(0x73):   // BIT  6,(Ix+d)\r
+       OPXYCB(0x74):   // BIT  6,(Ix+d)\r
+       OPXYCB(0x75):   // BIT  6,(Ix+d)\r
+       OPXYCB(0x77):   // BIT  6,(Ix+d)\r
+\r
+       OPXYCB(0x78):   // BIT  7,(Ix+d)\r
+       OPXYCB(0x79):   // BIT  7,(Ix+d)\r
+       OPXYCB(0x7a):   // BIT  7,(Ix+d)\r
+       OPXYCB(0x7b):   // BIT  7,(Ix+d)\r
+       OPXYCB(0x7c):   // BIT  7,(Ix+d)\r
+       OPXYCB(0x7d):   // BIT  7,(Ix+d)\r
+       OPXYCB(0x7f):   // BIT  7,(Ix+d)\r
+\r
+       OPXYCB(0x46):   // BIT  0,(Ix+d)\r
+       OPXYCB(0x4e):   // BIT  1,(Ix+d)\r
+       OPXYCB(0x56):   // BIT  2,(Ix+d)\r
+       OPXYCB(0x5e):   // BIT  3,(Ix+d)\r
+       OPXYCB(0x66):   // BIT  4,(Ix+d)\r
+       OPXYCB(0x6e):   // BIT  5,(Ix+d)\r
+       OPXYCB(0x76):   // BIT  6,(Ix+d)\r
+       OPXYCB(0x7e):   // BIT  7,(Ix+d)\r
+               src = READ_MEM8(adr);\r
+               zF = (zF & CF) | HF |\r
+                        (SZ_BIT[src & (1 << ((Opcode >> 3) & 7))] & ~(YF | XF)) |\r
+                        ((adr >> 8) & (YF | XF));\r
+               RET(16)\r
+\r
+/*-----------------------------------------\r
+ RES\r
+-----------------------------------------*/\r
+\r
+       OPXYCB(0x80):   // RES  0,(Ix+d),B\r
+       OPXYCB(0x81):   // RES  0,(Ix+d),C\r
+       OPXYCB(0x82):   // RES  0,(Ix+d),D\r
+       OPXYCB(0x83):   // RES  0,(Ix+d),E\r
+       OPXYCB(0x84):   // RES  0,(Ix+d),H\r
+       OPXYCB(0x85):   // RES  0,(Ix+d),L\r
+       OPXYCB(0x87):   // RES  0,(Ix+d),A\r
+\r
+       OPXYCB(0x88):   // RES  1,(Ix+d),B\r
+       OPXYCB(0x89):   // RES  1,(Ix+d),C\r
+       OPXYCB(0x8a):   // RES  1,(Ix+d),D\r
+       OPXYCB(0x8b):   // RES  1,(Ix+d),E\r
+       OPXYCB(0x8c):   // RES  1,(Ix+d),H\r
+       OPXYCB(0x8d):   // RES  1,(Ix+d),L\r
+       OPXYCB(0x8f):   // RES  1,(Ix+d),A\r
+\r
+       OPXYCB(0x90):   // RES  2,(Ix+d),B\r
+       OPXYCB(0x91):   // RES  2,(Ix+d),C\r
+       OPXYCB(0x92):   // RES  2,(Ix+d),D\r
+       OPXYCB(0x93):   // RES  2,(Ix+d),E\r
+       OPXYCB(0x94):   // RES  2,(Ix+d),H\r
+       OPXYCB(0x95):   // RES  2,(Ix+d),L\r
+       OPXYCB(0x97):   // RES  2,(Ix+d),A\r
+\r
+       OPXYCB(0x98):   // RES  3,(Ix+d),B\r
+       OPXYCB(0x99):   // RES  3,(Ix+d),C\r
+       OPXYCB(0x9a):   // RES  3,(Ix+d),D\r
+       OPXYCB(0x9b):   // RES  3,(Ix+d),E\r
+       OPXYCB(0x9c):   // RES  3,(Ix+d),H\r
+       OPXYCB(0x9d):   // RES  3,(Ix+d),L\r
+       OPXYCB(0x9f):   // RES  3,(Ix+d),A\r
+\r
+       OPXYCB(0xa0):   // RES  4,(Ix+d),B\r
+       OPXYCB(0xa1):   // RES  4,(Ix+d),C\r
+       OPXYCB(0xa2):   // RES  4,(Ix+d),D\r
+       OPXYCB(0xa3):   // RES  4,(Ix+d),E\r
+       OPXYCB(0xa4):   // RES  4,(Ix+d),H\r
+       OPXYCB(0xa5):   // RES  4,(Ix+d),L\r
+       OPXYCB(0xa7):   // RES  4,(Ix+d),A\r
+\r
+       OPXYCB(0xa8):   // RES  5,(Ix+d),B\r
+       OPXYCB(0xa9):   // RES  5,(Ix+d),C\r
+       OPXYCB(0xaa):   // RES  5,(Ix+d),D\r
+       OPXYCB(0xab):   // RES  5,(Ix+d),E\r
+       OPXYCB(0xac):   // RES  5,(Ix+d),H\r
+       OPXYCB(0xad):   // RES  5,(Ix+d),L\r
+       OPXYCB(0xaf):   // RES  5,(Ix+d),A\r
+\r
+       OPXYCB(0xb0):   // RES  6,(Ix+d),B\r
+       OPXYCB(0xb1):   // RES  6,(Ix+d),C\r
+       OPXYCB(0xb2):   // RES  6,(Ix+d),D\r
+       OPXYCB(0xb3):   // RES  6,(Ix+d),E\r
+       OPXYCB(0xb4):   // RES  6,(Ix+d),H\r
+       OPXYCB(0xb5):   // RES  6,(Ix+d),L\r
+       OPXYCB(0xb7):   // RES  6,(Ix+d),A\r
+\r
+       OPXYCB(0xb8):   // RES  7,(Ix+d),B\r
+       OPXYCB(0xb9):   // RES  7,(Ix+d),C\r
+       OPXYCB(0xba):   // RES  7,(Ix+d),D\r
+       OPXYCB(0xbb):   // RES  7,(Ix+d),E\r
+       OPXYCB(0xbc):   // RES  7,(Ix+d),H\r
+       OPXYCB(0xbd):   // RES  7,(Ix+d),L\r
+       OPXYCB(0xbf):   // RES  7,(Ix+d),A\r
+               res = READ_MEM8(adr);\r
+               res &= ~(1 << ((Opcode >> 3) & 7));\r
+               zR8(Opcode & 7) = res;\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+       OPXYCB(0x86):   // RES  0,(Ix+d)\r
+       OPXYCB(0x8e):   // RES  1,(Ix+d)\r
+       OPXYCB(0x96):   // RES  2,(Ix+d)\r
+       OPXYCB(0x9e):   // RES  3,(Ix+d)\r
+       OPXYCB(0xa6):   // RES  4,(Ix+d)\r
+       OPXYCB(0xae):   // RES  5,(Ix+d)\r
+       OPXYCB(0xb6):   // RES  6,(Ix+d)\r
+       OPXYCB(0xbe):   // RES  7,(Ix+d)\r
+               res = READ_MEM8(adr);\r
+               res &= ~(1 << ((Opcode >> 3) & 7));\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+/*-----------------------------------------\r
+ SET\r
+-----------------------------------------*/\r
+\r
+       OPXYCB(0xc0):   // SET  0,(Ix+d),B\r
+       OPXYCB(0xc1):   // SET  0,(Ix+d),C\r
+       OPXYCB(0xc2):   // SET  0,(Ix+d),D\r
+       OPXYCB(0xc3):   // SET  0,(Ix+d),E\r
+       OPXYCB(0xc4):   // SET  0,(Ix+d),H\r
+       OPXYCB(0xc5):   // SET  0,(Ix+d),L\r
+       OPXYCB(0xc7):   // SET  0,(Ix+d),A\r
+\r
+       OPXYCB(0xc8):   // SET  1,(Ix+d),B\r
+       OPXYCB(0xc9):   // SET  1,(Ix+d),C\r
+       OPXYCB(0xca):   // SET  1,(Ix+d),D\r
+       OPXYCB(0xcb):   // SET  1,(Ix+d),E\r
+       OPXYCB(0xcc):   // SET  1,(Ix+d),H\r
+       OPXYCB(0xcd):   // SET  1,(Ix+d),L\r
+       OPXYCB(0xcf):   // SET  1,(Ix+d),A\r
+\r
+       OPXYCB(0xd0):   // SET  2,(Ix+d),B\r
+       OPXYCB(0xd1):   // SET  2,(Ix+d),C\r
+       OPXYCB(0xd2):   // SET  2,(Ix+d),D\r
+       OPXYCB(0xd3):   // SET  2,(Ix+d),E\r
+       OPXYCB(0xd4):   // SET  2,(Ix+d),H\r
+       OPXYCB(0xd5):   // SET  2,(Ix+d),L\r
+       OPXYCB(0xd7):   // SET  2,(Ix+d),A\r
+\r
+       OPXYCB(0xd8):   // SET  3,(Ix+d),B\r
+       OPXYCB(0xd9):   // SET  3,(Ix+d),C\r
+       OPXYCB(0xda):   // SET  3,(Ix+d),D\r
+       OPXYCB(0xdb):   // SET  3,(Ix+d),E\r
+       OPXYCB(0xdc):   // SET  3,(Ix+d),H\r
+       OPXYCB(0xdd):   // SET  3,(Ix+d),L\r
+       OPXYCB(0xdf):   // SET  3,(Ix+d),A\r
+\r
+       OPXYCB(0xe0):   // SET  4,(Ix+d),B\r
+       OPXYCB(0xe1):   // SET  4,(Ix+d),C\r
+       OPXYCB(0xe2):   // SET  4,(Ix+d),D\r
+       OPXYCB(0xe3):   // SET  4,(Ix+d),E\r
+       OPXYCB(0xe4):   // SET  4,(Ix+d),H\r
+       OPXYCB(0xe5):   // SET  4,(Ix+d),L\r
+       OPXYCB(0xe7):   // SET  4,(Ix+d),A\r
+\r
+       OPXYCB(0xe8):   // SET  5,(Ix+d),B\r
+       OPXYCB(0xe9):   // SET  5,(Ix+d),C\r
+       OPXYCB(0xea):   // SET  5,(Ix+d),D\r
+       OPXYCB(0xeb):   // SET  5,(Ix+d),E\r
+       OPXYCB(0xec):   // SET  5,(Ix+d),H\r
+       OPXYCB(0xed):   // SET  5,(Ix+d),L\r
+       OPXYCB(0xef):   // SET  5,(Ix+d),A\r
+\r
+       OPXYCB(0xf0):   // SET  6,(Ix+d),B\r
+       OPXYCB(0xf1):   // SET  6,(Ix+d),C\r
+       OPXYCB(0xf2):   // SET  6,(Ix+d),D\r
+       OPXYCB(0xf3):   // SET  6,(Ix+d),E\r
+       OPXYCB(0xf4):   // SET  6,(Ix+d),H\r
+       OPXYCB(0xf5):   // SET  6,(Ix+d),L\r
+       OPXYCB(0xf7):   // SET  6,(Ix+d),A\r
+\r
+       OPXYCB(0xf8):   // SET  7,(Ix+d),B\r
+       OPXYCB(0xf9):   // SET  7,(Ix+d),C\r
+       OPXYCB(0xfa):   // SET  7,(Ix+d),D\r
+       OPXYCB(0xfb):   // SET  7,(Ix+d),E\r
+       OPXYCB(0xfc):   // SET  7,(Ix+d),H\r
+       OPXYCB(0xfd):   // SET  7,(Ix+d),L\r
+       OPXYCB(0xff):   // SET  7,(Ix+d),A\r
+               res = READ_MEM8(adr);\r
+               res |= 1 << ((Opcode >> 3) & 7);\r
+               zR8(Opcode & 7) = res;\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+       OPXYCB(0xc6):   // SET  0,(Ix+d)\r
+       OPXYCB(0xce):   // SET  1,(Ix+d)\r
+       OPXYCB(0xd6):   // SET  2,(Ix+d)\r
+       OPXYCB(0xde):   // SET  3,(Ix+d)\r
+       OPXYCB(0xe6):   // SET  4,(Ix+d)\r
+       OPXYCB(0xee):   // SET  5,(Ix+d)\r
+       OPXYCB(0xf6):   // SET  6,(Ix+d)\r
+       OPXYCB(0xfe):   // SET  7,(Ix+d)\r
+               res = READ_MEM8(adr);\r
+               res |= 1 << ((Opcode >> 3) & 7);\r
+               WRITE_MEM8(adr, res);\r
+               RET(19)\r
+\r
+#if !CZ80_USE_JUMPTABLE\r
+}\r
+#endif\r
diff --git a/cpu/cz80/cz80jmp.c b/cpu/cz80/cz80jmp.c
new file mode 100644 (file)
index 0000000..0100772
--- /dev/null
@@ -0,0 +1,422 @@
+/******************************************************************************\r
+\r
+       cz80jmp.c\r
+\r
+       CZ80 opcode\83W\83\83\83\93\83v\83e\81[\83u\83\8b\r
+\r
+******************************************************************************/\r
+\r
+static const void ALIGN_DATA *JumpTable[0x100] =\r
+{\r
+       &&OP0x00, &&OP0x01, &&OP0x02, &&OP0x03,\r
+       &&OP0x04, &&OP0x05, &&OP0x06, &&OP0x07,\r
+       &&OP0x08, &&OP0x09, &&OP0x0a, &&OP0x0b,\r
+       &&OP0x0c, &&OP0x0d, &&OP0x0e, &&OP0x0f,\r
+\r
+       &&OP0x10, &&OP0x11, &&OP0x12, &&OP0x13,\r
+       &&OP0x14, &&OP0x15, &&OP0x16, &&OP0x17,\r
+       &&OP0x18, &&OP0x19, &&OP0x1a, &&OP0x1b,\r
+       &&OP0x1c, &&OP0x1d, &&OP0x1e, &&OP0x1f,\r
+\r
+       &&OP0x20, &&OP0x21, &&OP0x22, &&OP0x23,\r
+       &&OP0x24, &&OP0x25, &&OP0x26, &&OP0x27,\r
+       &&OP0x28, &&OP0x29, &&OP0x2a, &&OP0x2b,\r
+       &&OP0x2c, &&OP0x2d, &&OP0x2e, &&OP0x2f,\r
+\r
+       &&OP0x30, &&OP0x31, &&OP0x32, &&OP0x33,\r
+       &&OP0x34, &&OP0x35, &&OP0x36, &&OP0x37,\r
+       &&OP0x38, &&OP0x39, &&OP0x3a, &&OP0x3b,\r
+       &&OP0x3c, &&OP0x3d, &&OP0x3e, &&OP0x3f,\r
+\r
+       &&OP0x40, &&OP0x41, &&OP0x42, &&OP0x43,\r
+       &&OP0x44, &&OP0x45, &&OP0x46, &&OP0x47,\r
+       &&OP0x48, &&OP0x49, &&OP0x4a, &&OP0x4b,\r
+       &&OP0x4c, &&OP0x4d, &&OP0x4e, &&OP0x4f,\r
+\r
+       &&OP0x50, &&OP0x51, &&OP0x52, &&OP0x53,\r
+       &&OP0x54, &&OP0x55, &&OP0x56, &&OP0x57,\r
+       &&OP0x58, &&OP0x59, &&OP0x5a, &&OP0x5b,\r
+       &&OP0x5c, &&OP0x5d, &&OP0x5e, &&OP0x5f,\r
+\r
+       &&OP0x60, &&OP0x61, &&OP0x62, &&OP0x63,\r
+       &&OP0x64, &&OP0x65, &&OP0x66, &&OP0x67,\r
+       &&OP0x68, &&OP0x69, &&OP0x6a, &&OP0x6b,\r
+       &&OP0x6c, &&OP0x6d, &&OP0x6e, &&OP0x6f,\r
+\r
+       &&OP0x70, &&OP0x71, &&OP0x72, &&OP0x73,\r
+       &&OP0x74, &&OP0x75, &&OP0x76, &&OP0x77,\r
+       &&OP0x78, &&OP0x79, &&OP0x7a, &&OP0x7b,\r
+       &&OP0x7c, &&OP0x7d, &&OP0x7e, &&OP0x7f,\r
+\r
+       &&OP0x80, &&OP0x81, &&OP0x82, &&OP0x83,\r
+       &&OP0x84, &&OP0x85, &&OP0x86, &&OP0x87,\r
+       &&OP0x88, &&OP0x89, &&OP0x8a, &&OP0x8b,\r
+       &&OP0x8c, &&OP0x8d, &&OP0x8e, &&OP0x8f,\r
+\r
+       &&OP0x90, &&OP0x91, &&OP0x92, &&OP0x93,\r
+       &&OP0x94, &&OP0x95, &&OP0x96, &&OP0x97,\r
+       &&OP0x98, &&OP0x99, &&OP0x9a, &&OP0x9b,\r
+       &&OP0x9c, &&OP0x9d, &&OP0x9e, &&OP0x9f,\r
+\r
+       &&OP0xa0, &&OP0xa1, &&OP0xa2, &&OP0xa3,\r
+       &&OP0xa4, &&OP0xa5, &&OP0xa6, &&OP0xa7,\r
+       &&OP0xa8, &&OP0xa9, &&OP0xaa, &&OP0xab,\r
+       &&OP0xac, &&OP0xad, &&OP0xae, &&OP0xaf,\r
+\r
+       &&OP0xb0, &&OP0xb1, &&OP0xb2, &&OP0xb3,\r
+       &&OP0xb4, &&OP0xb5, &&OP0xb6, &&OP0xb7,\r
+       &&OP0xb8, &&OP0xb9, &&OP0xba, &&OP0xbb,\r
+       &&OP0xbc, &&OP0xbd, &&OP0xbe, &&OP0xbf,\r
+\r
+       &&OP0xc0, &&OP0xc1, &&OP0xc2, &&OP0xc3,\r
+       &&OP0xc4, &&OP0xc5, &&OP0xc6, &&OP0xc7,\r
+       &&OP0xc8, &&OP0xc9, &&OP0xca, &&OP0xcb,\r
+       &&OP0xcc, &&OP0xcd, &&OP0xce, &&OP0xcf,\r
+\r
+       &&OP0xd0, &&OP0xd1, &&OP0xd2, &&OP0xd3,\r
+       &&OP0xd4, &&OP0xd5, &&OP0xd6, &&OP0xd7,\r
+       &&OP0xd8, &&OP0xd9, &&OP0xda, &&OP0xdb,\r
+       &&OP0xdc, &&OP0xdd, &&OP0xde, &&OP0xdf,\r
+\r
+       &&OP0xe0, &&OP0xe1, &&OP0xe2, &&OP0xe3,\r
+       &&OP0xe4, &&OP0xe5, &&OP0xe6, &&OP0xe7,\r
+       &&OP0xe8, &&OP0xe9, &&OP0xea, &&OP0xeb,\r
+       &&OP0xec, &&OP0xed, &&OP0xee, &&OP0xef,\r
+\r
+       &&OP0xf0, &&OP0xf1, &&OP0xf2, &&OP0xf3,\r
+       &&OP0xf4, &&OP0xf5, &&OP0xf6, &&OP0xf7,\r
+       &&OP0xf8, &&OP0xf9, &&OP0xfa, &&OP0xfb,\r
+       &&OP0xfc, &&OP0xfd, &&OP0xfe, &&OP0xff\r
+};\r
+\r
+static const void ALIGN_DATA *JumpTableCB[0x100] =\r
+{\r
+       &&OPCB0x00, &&OPCB0x01, &&OPCB0x02, &&OPCB0x03,\r
+       &&OPCB0x04, &&OPCB0x05, &&OPCB0x06, &&OPCB0x07,\r
+       &&OPCB0x08, &&OPCB0x09, &&OPCB0x0a, &&OPCB0x0b,\r
+       &&OPCB0x0c, &&OPCB0x0d, &&OPCB0x0e, &&OPCB0x0f,\r
+\r
+       &&OPCB0x10, &&OPCB0x11, &&OPCB0x12, &&OPCB0x13,\r
+       &&OPCB0x14, &&OPCB0x15, &&OPCB0x16, &&OPCB0x17,\r
+       &&OPCB0x18, &&OPCB0x19, &&OPCB0x1a, &&OPCB0x1b,\r
+       &&OPCB0x1c, &&OPCB0x1d, &&OPCB0x1e, &&OPCB0x1f,\r
+\r
+       &&OPCB0x20, &&OPCB0x21, &&OPCB0x22, &&OPCB0x23,\r
+       &&OPCB0x24, &&OPCB0x25, &&OPCB0x26, &&OPCB0x27,\r
+       &&OPCB0x28, &&OPCB0x29, &&OPCB0x2a, &&OPCB0x2b,\r
+       &&OPCB0x2c, &&OPCB0x2d, &&OPCB0x2e, &&OPCB0x2f,\r
+\r
+       &&OPCB0x30, &&OPCB0x31, &&OPCB0x32, &&OPCB0x33,\r
+       &&OPCB0x34, &&OPCB0x35, &&OPCB0x36, &&OPCB0x37,\r
+       &&OPCB0x38, &&OPCB0x39, &&OPCB0x3a, &&OPCB0x3b,\r
+       &&OPCB0x3c, &&OPCB0x3d, &&OPCB0x3e, &&OPCB0x3f,\r
+\r
+       &&OPCB0x40, &&OPCB0x41, &&OPCB0x42, &&OPCB0x43,\r
+       &&OPCB0x44, &&OPCB0x45, &&OPCB0x46, &&OPCB0x47,\r
+       &&OPCB0x48, &&OPCB0x49, &&OPCB0x4a, &&OPCB0x4b,\r
+       &&OPCB0x4c, &&OPCB0x4d, &&OPCB0x4e, &&OPCB0x4f,\r
+\r
+       &&OPCB0x50, &&OPCB0x51, &&OPCB0x52, &&OPCB0x53,\r
+       &&OPCB0x54, &&OPCB0x55, &&OPCB0x56, &&OPCB0x57,\r
+       &&OPCB0x58, &&OPCB0x59, &&OPCB0x5a, &&OPCB0x5b,\r
+       &&OPCB0x5c, &&OPCB0x5d, &&OPCB0x5e, &&OPCB0x5f,\r
+\r
+       &&OPCB0x60, &&OPCB0x61, &&OPCB0x62, &&OPCB0x63,\r
+       &&OPCB0x64, &&OPCB0x65, &&OPCB0x66, &&OPCB0x67,\r
+       &&OPCB0x68, &&OPCB0x69, &&OPCB0x6a, &&OPCB0x6b,\r
+       &&OPCB0x6c, &&OPCB0x6d, &&OPCB0x6e, &&OPCB0x6f,\r
+\r
+       &&OPCB0x70, &&OPCB0x71, &&OPCB0x72, &&OPCB0x73,\r
+       &&OPCB0x74, &&OPCB0x75, &&OPCB0x76, &&OPCB0x77,\r
+       &&OPCB0x78, &&OPCB0x79, &&OPCB0x7a, &&OPCB0x7b,\r
+       &&OPCB0x7c, &&OPCB0x7d, &&OPCB0x7e, &&OPCB0x7f,\r
+\r
+       &&OPCB0x80, &&OPCB0x81, &&OPCB0x82, &&OPCB0x83,\r
+       &&OPCB0x84, &&OPCB0x85, &&OPCB0x86, &&OPCB0x87,\r
+       &&OPCB0x88, &&OPCB0x89, &&OPCB0x8a, &&OPCB0x8b,\r
+       &&OPCB0x8c, &&OPCB0x8d, &&OPCB0x8e, &&OPCB0x8f,\r
+\r
+       &&OPCB0x90, &&OPCB0x91, &&OPCB0x92, &&OPCB0x93,\r
+       &&OPCB0x94, &&OPCB0x95, &&OPCB0x96, &&OPCB0x97,\r
+       &&OPCB0x98, &&OPCB0x99, &&OPCB0x9a, &&OPCB0x9b,\r
+       &&OPCB0x9c, &&OPCB0x9d, &&OPCB0x9e, &&OPCB0x9f,\r
+\r
+       &&OPCB0xa0, &&OPCB0xa1, &&OPCB0xa2, &&OPCB0xa3,\r
+       &&OPCB0xa4, &&OPCB0xa5, &&OPCB0xa6, &&OPCB0xa7,\r
+       &&OPCB0xa8, &&OPCB0xa9, &&OPCB0xaa, &&OPCB0xab,\r
+       &&OPCB0xac, &&OPCB0xad, &&OPCB0xae, &&OPCB0xaf,\r
+\r
+       &&OPCB0xb0, &&OPCB0xb1, &&OPCB0xb2, &&OPCB0xb3,\r
+       &&OPCB0xb4, &&OPCB0xb5, &&OPCB0xb6, &&OPCB0xb7,\r
+       &&OPCB0xb8, &&OPCB0xb9, &&OPCB0xba, &&OPCB0xbb,\r
+       &&OPCB0xbc, &&OPCB0xbd, &&OPCB0xbe, &&OPCB0xbf,\r
+\r
+       &&OPCB0xc0, &&OPCB0xc1, &&OPCB0xc2, &&OPCB0xc3,\r
+       &&OPCB0xc4, &&OPCB0xc5, &&OPCB0xc6, &&OPCB0xc7,\r
+       &&OPCB0xc8, &&OPCB0xc9, &&OPCB0xca, &&OPCB0xcb,\r
+       &&OPCB0xcc, &&OPCB0xcd, &&OPCB0xce, &&OPCB0xcf,\r
+\r
+       &&OPCB0xd0, &&OPCB0xd1, &&OPCB0xd2, &&OPCB0xd3,\r
+       &&OPCB0xd4, &&OPCB0xd5, &&OPCB0xd6, &&OPCB0xd7,\r
+       &&OPCB0xd8, &&OPCB0xd9, &&OPCB0xda, &&OPCB0xdb,\r
+       &&OPCB0xdc, &&OPCB0xdd, &&OPCB0xde, &&OPCB0xdf,\r
+\r
+       &&OPCB0xe0, &&OPCB0xe1, &&OPCB0xe2, &&OPCB0xe3,\r
+       &&OPCB0xe4, &&OPCB0xe5, &&OPCB0xe6, &&OPCB0xe7,\r
+       &&OPCB0xe8, &&OPCB0xe9, &&OPCB0xea, &&OPCB0xeb,\r
+       &&OPCB0xec, &&OPCB0xed, &&OPCB0xee, &&OPCB0xef,\r
+\r
+       &&OPCB0xf0, &&OPCB0xf1, &&OPCB0xf2, &&OPCB0xf3,\r
+       &&OPCB0xf4, &&OPCB0xf5, &&OPCB0xf6, &&OPCB0xf7,\r
+       &&OPCB0xf8, &&OPCB0xf9, &&OPCB0xfa, &&OPCB0xfb,\r
+       &&OPCB0xfc, &&OPCB0xfd, &&OPCB0xfe, &&OPCB0xff\r
+};\r
+\r
+static const void ALIGN_DATA *JumpTableED[0x100] =\r
+{\r
+       &&OPED0x00, &&OPED0x01, &&OPED0x02, &&OPED0x03,\r
+       &&OPED0x04, &&OPED0x05, &&OPED0x06, &&OPED0x07,\r
+       &&OPED0x08, &&OPED0x09, &&OPED0x0a, &&OPED0x0b,\r
+       &&OPED0x0c, &&OPED0x0d, &&OPED0x0e, &&OPED0x0f,\r
+\r
+       &&OPED0x10, &&OPED0x11, &&OPED0x12, &&OPED0x13,\r
+       &&OPED0x14, &&OPED0x15, &&OPED0x16, &&OPED0x17,\r
+       &&OPED0x18, &&OPED0x19, &&OPED0x1a, &&OPED0x1b,\r
+       &&OPED0x1c, &&OPED0x1d, &&OPED0x1e, &&OPED0x1f,\r
+\r
+       &&OPED0x20, &&OPED0x21, &&OPED0x22, &&OPED0x23,\r
+       &&OPED0x24, &&OPED0x25, &&OPED0x26, &&OPED0x27,\r
+       &&OPED0x28, &&OPED0x29, &&OPED0x2a, &&OPED0x2b,\r
+       &&OPED0x2c, &&OPED0x2d, &&OPED0x2e, &&OPED0x2f,\r
+\r
+       &&OPED0x30, &&OPED0x31, &&OPED0x32, &&OPED0x33,\r
+       &&OPED0x34, &&OPED0x35, &&OPED0x36, &&OPED0x37,\r
+       &&OPED0x38, &&OPED0x39, &&OPED0x3a, &&OPED0x3b,\r
+       &&OPED0x3c, &&OPED0x3d, &&OPED0x3e, &&OPED0x3f,\r
+\r
+       &&OPED0x40, &&OPED0x41, &&OPED0x42, &&OPED0x43,\r
+       &&OPED0x44, &&OPED0x45, &&OPED0x46, &&OPED0x47,\r
+       &&OPED0x48, &&OPED0x49, &&OPED0x4a, &&OPED0x4b,\r
+       &&OPED0x4c, &&OPED0x4d, &&OPED0x4e, &&OPED0x4f,\r
+\r
+       &&OPED0x50, &&OPED0x51, &&OPED0x52, &&OPED0x53,\r
+       &&OPED0x54, &&OPED0x55, &&OPED0x56, &&OPED0x57,\r
+       &&OPED0x58, &&OPED0x59, &&OPED0x5a, &&OPED0x5b,\r
+       &&OPED0x5c, &&OPED0x5d, &&OPED0x5e, &&OPED0x5f,\r
+\r
+       &&OPED0x60, &&OPED0x61, &&OPED0x62, &&OPED0x63,\r
+       &&OPED0x64, &&OPED0x65, &&OPED0x66, &&OPED0x67,\r
+       &&OPED0x68, &&OPED0x69, &&OPED0x6a, &&OPED0x6b,\r
+       &&OPED0x6c, &&OPED0x6d, &&OPED0x6e, &&OPED0x6f,\r
+\r
+       &&OPED0x70, &&OPED0x71, &&OPED0x72, &&OPED0x73,\r
+       &&OPED0x74, &&OPED0x75, &&OPED0x76, &&OPED0x77,\r
+       &&OPED0x78, &&OPED0x79, &&OPED0x7a, &&OPED0x7b,\r
+       &&OPED0x7c, &&OPED0x7d, &&OPED0x7e, &&OPED0x7f,\r
+\r
+       &&OPED0x80, &&OPED0x81, &&OPED0x82, &&OPED0x83,\r
+       &&OPED0x84, &&OPED0x85, &&OPED0x86, &&OPED0x87,\r
+       &&OPED0x88, &&OPED0x89, &&OPED0x8a, &&OPED0x8b,\r
+       &&OPED0x8c, &&OPED0x8d, &&OPED0x8e, &&OPED0x8f,\r
+\r
+       &&OPED0x90, &&OPED0x91, &&OPED0x92, &&OPED0x93,\r
+       &&OPED0x94, &&OPED0x95, &&OPED0x96, &&OPED0x97,\r
+       &&OPED0x98, &&OPED0x99, &&OPED0x9a, &&OPED0x9b,\r
+       &&OPED0x9c, &&OPED0x9d, &&OPED0x9e, &&OPED0x9f,\r
+\r
+       &&OPED0xa0, &&OPED0xa1, &&OPED0xa2, &&OPED0xa3,\r
+       &&OPED0xa4, &&OPED0xa5, &&OPED0xa6, &&OPED0xa7,\r
+       &&OPED0xa8, &&OPED0xa9, &&OPED0xaa, &&OPED0xab,\r
+       &&OPED0xac, &&OPED0xad, &&OPED0xae, &&OPED0xaf,\r
+\r
+       &&OPED0xb0, &&OPED0xb1, &&OPED0xb2, &&OPED0xb3,\r
+       &&OPED0xb4, &&OPED0xb5, &&OPED0xb6, &&OPED0xb7,\r
+       &&OPED0xb8, &&OPED0xb9, &&OPED0xba, &&OPED0xbb,\r
+       &&OPED0xbc, &&OPED0xbd, &&OPED0xbe, &&OPED0xbf,\r
+\r
+       &&OPED0xc0, &&OPED0xc1, &&OPED0xc2, &&OPED0xc3,\r
+       &&OPED0xc4, &&OPED0xc5, &&OPED0xc6, &&OPED0xc7,\r
+       &&OPED0xc8, &&OPED0xc9, &&OPED0xca, &&OPED0xcb,\r
+       &&OPED0xcc, &&OPED0xcd, &&OPED0xce, &&OPED0xcf,\r
+\r
+       &&OPED0xd0, &&OPED0xd1, &&OPED0xd2, &&OPED0xd3,\r
+       &&OPED0xd4, &&OPED0xd5, &&OPED0xd6, &&OPED0xd7,\r
+       &&OPED0xd8, &&OPED0xd9, &&OPED0xda, &&OPED0xdb,\r
+       &&OPED0xdc, &&OPED0xdd, &&OPED0xde, &&OPED0xdf,\r
+\r
+       &&OPED0xe0, &&OPED0xe1, &&OPED0xe2, &&OPED0xe3,\r
+       &&OPED0xe4, &&OPED0xe5, &&OPED0xe6, &&OPED0xe7,\r
+       &&OPED0xe8, &&OPED0xe9, &&OPED0xea, &&OPED0xeb,\r
+       &&OPED0xec, &&OPED0xed, &&OPED0xee, &&OPED0xef,\r
+\r
+       &&OPED0xf0, &&OPED0xf1, &&OPED0xf2, &&OPED0xf3,\r
+       &&OPED0xf4, &&OPED0xf5, &&OPED0xf6, &&OPED0xf7,\r
+       &&OPED0xf8, &&OPED0xf9, &&OPED0xfa, &&OPED0xfb,\r
+       &&OPED0xfc, &&OPED0xfd, &&OPED0xfe, &&OPED0xff\r
+};\r
+\r
+static const void ALIGN_DATA *JumpTableXY[0x100] =\r
+{\r
+       &&OPXY0x00, &&OPXY0x01, &&OPXY0x02, &&OPXY0x03,\r
+       &&OPXY0x04, &&OPXY0x05, &&OPXY0x06, &&OPXY0x07,\r
+       &&OPXY0x08, &&OPXY0x09, &&OPXY0x0a, &&OPXY0x0b,\r
+       &&OPXY0x0c, &&OPXY0x0d, &&OPXY0x0e, &&OPXY0x0f,\r
+\r
+       &&OPXY0x10, &&OPXY0x11, &&OPXY0x12, &&OPXY0x13,\r
+       &&OPXY0x14, &&OPXY0x15, &&OPXY0x16, &&OPXY0x17,\r
+       &&OPXY0x18, &&OPXY0x19, &&OPXY0x1a, &&OPXY0x1b,\r
+       &&OPXY0x1c, &&OPXY0x1d, &&OPXY0x1e, &&OPXY0x1f,\r
+\r
+       &&OPXY0x20, &&OPXY0x21, &&OPXY0x22, &&OPXY0x23,\r
+       &&OPXY0x24, &&OPXY0x25, &&OPXY0x26, &&OPXY0x27,\r
+       &&OPXY0x28, &&OPXY0x29, &&OPXY0x2a, &&OPXY0x2b,\r
+       &&OPXY0x2c, &&OPXY0x2d, &&OPXY0x2e, &&OPXY0x2f,\r
+\r
+       &&OPXY0x30, &&OPXY0x31, &&OPXY0x32, &&OPXY0x33,\r
+       &&OPXY0x34, &&OPXY0x35, &&OPXY0x36, &&OPXY0x37,\r
+       &&OPXY0x38, &&OPXY0x39, &&OPXY0x3a, &&OPXY0x3b,\r
+       &&OPXY0x3c, &&OPXY0x3d, &&OPXY0x3e, &&OPXY0x3f,\r
+\r
+       &&OPXY0x40, &&OPXY0x41, &&OPXY0x42, &&OPXY0x43,\r
+       &&OPXY0x44, &&OPXY0x45, &&OPXY0x46, &&OPXY0x47,\r
+       &&OPXY0x48, &&OPXY0x49, &&OPXY0x4a, &&OPXY0x4b,\r
+       &&OPXY0x4c, &&OPXY0x4d, &&OPXY0x4e, &&OPXY0x4f,\r
+\r
+       &&OPXY0x50, &&OPXY0x51, &&OPXY0x52, &&OPXY0x53,\r
+       &&OPXY0x54, &&OPXY0x55, &&OPXY0x56, &&OPXY0x57,\r
+       &&OPXY0x58, &&OPXY0x59, &&OPXY0x5a, &&OPXY0x5b,\r
+       &&OPXY0x5c, &&OPXY0x5d, &&OPXY0x5e, &&OPXY0x5f,\r
+\r
+       &&OPXY0x60, &&OPXY0x61, &&OPXY0x62, &&OPXY0x63,\r
+       &&OPXY0x64, &&OPXY0x65, &&OPXY0x66, &&OPXY0x67,\r
+       &&OPXY0x68, &&OPXY0x69, &&OPXY0x6a, &&OPXY0x6b,\r
+       &&OPXY0x6c, &&OPXY0x6d, &&OPXY0x6e, &&OPXY0x6f,\r
+\r
+       &&OPXY0x70, &&OPXY0x71, &&OPXY0x72, &&OPXY0x73,\r
+       &&OPXY0x74, &&OPXY0x75, &&OPXY0x76, &&OPXY0x77,\r
+       &&OPXY0x78, &&OPXY0x79, &&OPXY0x7a, &&OPXY0x7b,\r
+       &&OPXY0x7c, &&OPXY0x7d, &&OPXY0x7e, &&OPXY0x7f,\r
+\r
+       &&OPXY0x80, &&OPXY0x81, &&OPXY0x82, &&OPXY0x83,\r
+       &&OPXY0x84, &&OPXY0x85, &&OPXY0x86, &&OPXY0x87,\r
+       &&OPXY0x88, &&OPXY0x89, &&OPXY0x8a, &&OPXY0x8b,\r
+       &&OPXY0x8c, &&OPXY0x8d, &&OPXY0x8e, &&OPXY0x8f,\r
+\r
+       &&OPXY0x90, &&OPXY0x91, &&OPXY0x92, &&OPXY0x93,\r
+       &&OPXY0x94, &&OPXY0x95, &&OPXY0x96, &&OPXY0x97,\r
+       &&OPXY0x98, &&OPXY0x99, &&OPXY0x9a, &&OPXY0x9b,\r
+       &&OPXY0x9c, &&OPXY0x9d, &&OPXY0x9e, &&OPXY0x9f,\r
+\r
+       &&OPXY0xa0, &&OPXY0xa1, &&OPXY0xa2, &&OPXY0xa3,\r
+       &&OPXY0xa4, &&OPXY0xa5, &&OPXY0xa6, &&OPXY0xa7,\r
+       &&OPXY0xa8, &&OPXY0xa9, &&OPXY0xaa, &&OPXY0xab,\r
+       &&OPXY0xac, &&OPXY0xad, &&OPXY0xae, &&OPXY0xaf,\r
+\r
+       &&OPXY0xb0, &&OPXY0xb1, &&OPXY0xb2, &&OPXY0xb3,\r
+       &&OPXY0xb4, &&OPXY0xb5, &&OPXY0xb6, &&OPXY0xb7,\r
+       &&OPXY0xb8, &&OPXY0xb9, &&OPXY0xba, &&OPXY0xbb,\r
+       &&OPXY0xbc, &&OPXY0xbd, &&OPXY0xbe, &&OPXY0xbf,\r
+\r
+       &&OPXY0xc0, &&OPXY0xc1, &&OPXY0xc2, &&OPXY0xc3,\r
+       &&OPXY0xc4, &&OPXY0xc5, &&OPXY0xc6, &&OPXY0xc7,\r
+       &&OPXY0xc8, &&OPXY0xc9, &&OPXY0xca, &&OPXY0xcb,\r
+       &&OPXY0xcc, &&OPXY0xcd, &&OPXY0xce, &&OPXY0xcf,\r
+\r
+       &&OPXY0xd0, &&OPXY0xd1, &&OPXY0xd2, &&OPXY0xd3,\r
+       &&OPXY0xd4, &&OPXY0xd5, &&OPXY0xd6, &&OPXY0xd7,\r
+       &&OPXY0xd8, &&OPXY0xd9, &&OPXY0xda, &&OPXY0xdb,\r
+       &&OPXY0xdc, &&OPXY0xdd, &&OPXY0xde, &&OPXY0xdf,\r
+\r
+       &&OPXY0xe0, &&OPXY0xe1, &&OPXY0xe2, &&OPXY0xe3,\r
+       &&OPXY0xe4, &&OPXY0xe5, &&OPXY0xe6, &&OPXY0xe7,\r
+       &&OPXY0xe8, &&OPXY0xe9, &&OPXY0xea, &&OPXY0xeb,\r
+       &&OPXY0xec, &&OPXY0xed, &&OPXY0xee, &&OPXY0xef,\r
+\r
+       &&OPXY0xf0, &&OPXY0xf1, &&OPXY0xf2, &&OPXY0xf3,\r
+       &&OPXY0xf4, &&OPXY0xf5, &&OPXY0xf6, &&OPXY0xf7,\r
+       &&OPXY0xf8, &&OPXY0xf9, &&OPXY0xfa, &&OPXY0xfb,\r
+       &&OPXY0xfc, &&OPXY0xfd, &&OPXY0xfe, &&OPXY0xff\r
+};\r
+\r
+static const void ALIGN_DATA *JumpTableXYCB[0x100] =\r
+{\r
+       &&OPXYCB0x00, &&OPXYCB0x01, &&OPXYCB0x02, &&OPXYCB0x03,\r
+       &&OPXYCB0x04, &&OPXYCB0x05, &&OPXYCB0x06, &&OPXYCB0x07,\r
+       &&OPXYCB0x08, &&OPXYCB0x09, &&OPXYCB0x0a, &&OPXYCB0x0b,\r
+       &&OPXYCB0x0c, &&OPXYCB0x0d, &&OPXYCB0x0e, &&OPXYCB0x0f,\r
+\r
+       &&OPXYCB0x10, &&OPXYCB0x11, &&OPXYCB0x12, &&OPXYCB0x13,\r
+       &&OPXYCB0x14, &&OPXYCB0x15, &&OPXYCB0x16, &&OPXYCB0x17,\r
+       &&OPXYCB0x18, &&OPXYCB0x19, &&OPXYCB0x1a, &&OPXYCB0x1b,\r
+       &&OPXYCB0x1c, &&OPXYCB0x1d, &&OPXYCB0x1e, &&OPXYCB0x1f,\r
+\r
+       &&OPXYCB0x20, &&OPXYCB0x21, &&OPXYCB0x22, &&OPXYCB0x23,\r
+       &&OPXYCB0x24, &&OPXYCB0x25, &&OPXYCB0x26, &&OPXYCB0x27,\r
+       &&OPXYCB0x28, &&OPXYCB0x29, &&OPXYCB0x2a, &&OPXYCB0x2b,\r
+       &&OPXYCB0x2c, &&OPXYCB0x2d, &&OPXYCB0x2e, &&OPXYCB0x2f,\r
+\r
+       &&OPXYCB0x30, &&OPXYCB0x31, &&OPXYCB0x32, &&OPXYCB0x33,\r
+       &&OPXYCB0x34, &&OPXYCB0x35, &&OPXYCB0x36, &&OPXYCB0x37,\r
+       &&OPXYCB0x38, &&OPXYCB0x39, &&OPXYCB0x3a, &&OPXYCB0x3b,\r
+       &&OPXYCB0x3c, &&OPXYCB0x3d, &&OPXYCB0x3e, &&OPXYCB0x3f,\r
+\r
+       &&OPXYCB0x40, &&OPXYCB0x41, &&OPXYCB0x42, &&OPXYCB0x43,\r
+       &&OPXYCB0x44, &&OPXYCB0x45, &&OPXYCB0x46, &&OPXYCB0x47,\r
+       &&OPXYCB0x48, &&OPXYCB0x49, &&OPXYCB0x4a, &&OPXYCB0x4b,\r
+       &&OPXYCB0x4c, &&OPXYCB0x4d, &&OPXYCB0x4e, &&OPXYCB0x4f,\r
+\r
+       &&OPXYCB0x50, &&OPXYCB0x51, &&OPXYCB0x52, &&OPXYCB0x53,\r
+       &&OPXYCB0x54, &&OPXYCB0x55, &&OPXYCB0x56, &&OPXYCB0x57,\r
+       &&OPXYCB0x58, &&OPXYCB0x59, &&OPXYCB0x5a, &&OPXYCB0x5b,\r
+       &&OPXYCB0x5c, &&OPXYCB0x5d, &&OPXYCB0x5e, &&OPXYCB0x5f,\r
+\r
+       &&OPXYCB0x60, &&OPXYCB0x61, &&OPXYCB0x62, &&OPXYCB0x63,\r
+       &&OPXYCB0x64, &&OPXYCB0x65, &&OPXYCB0x66, &&OPXYCB0x67,\r
+       &&OPXYCB0x68, &&OPXYCB0x69, &&OPXYCB0x6a, &&OPXYCB0x6b,\r
+       &&OPXYCB0x6c, &&OPXYCB0x6d, &&OPXYCB0x6e, &&OPXYCB0x6f,\r
+\r
+       &&OPXYCB0x70, &&OPXYCB0x71, &&OPXYCB0x72, &&OPXYCB0x73,\r
+       &&OPXYCB0x74, &&OPXYCB0x75, &&OPXYCB0x76, &&OPXYCB0x77,\r
+       &&OPXYCB0x78, &&OPXYCB0x79, &&OPXYCB0x7a, &&OPXYCB0x7b,\r
+       &&OPXYCB0x7c, &&OPXYCB0x7d, &&OPXYCB0x7e, &&OPXYCB0x7f,\r
+\r
+       &&OPXYCB0x80, &&OPXYCB0x81, &&OPXYCB0x82, &&OPXYCB0x83,\r
+       &&OPXYCB0x84, &&OPXYCB0x85, &&OPXYCB0x86, &&OPXYCB0x87,\r
+       &&OPXYCB0x88, &&OPXYCB0x89, &&OPXYCB0x8a, &&OPXYCB0x8b,\r
+       &&OPXYCB0x8c, &&OPXYCB0x8d, &&OPXYCB0x8e, &&OPXYCB0x8f,\r
+\r
+       &&OPXYCB0x90, &&OPXYCB0x91, &&OPXYCB0x92, &&OPXYCB0x93,\r
+       &&OPXYCB0x94, &&OPXYCB0x95, &&OPXYCB0x96, &&OPXYCB0x97,\r
+       &&OPXYCB0x98, &&OPXYCB0x99, &&OPXYCB0x9a, &&OPXYCB0x9b,\r
+       &&OPXYCB0x9c, &&OPXYCB0x9d, &&OPXYCB0x9e, &&OPXYCB0x9f,\r
+\r
+       &&OPXYCB0xa0, &&OPXYCB0xa1, &&OPXYCB0xa2, &&OPXYCB0xa3,\r
+       &&OPXYCB0xa4, &&OPXYCB0xa5, &&OPXYCB0xa6, &&OPXYCB0xa7,\r
+       &&OPXYCB0xa8, &&OPXYCB0xa9, &&OPXYCB0xaa, &&OPXYCB0xab,\r
+       &&OPXYCB0xac, &&OPXYCB0xad, &&OPXYCB0xae, &&OPXYCB0xaf,\r
+\r
+       &&OPXYCB0xb0, &&OPXYCB0xb1, &&OPXYCB0xb2, &&OPXYCB0xb3,\r
+       &&OPXYCB0xb4, &&OPXYCB0xb5, &&OPXYCB0xb6, &&OPXYCB0xb7,\r
+       &&OPXYCB0xb8, &&OPXYCB0xb9, &&OPXYCB0xba, &&OPXYCB0xbb,\r
+       &&OPXYCB0xbc, &&OPXYCB0xbd, &&OPXYCB0xbe, &&OPXYCB0xbf,\r
+\r
+       &&OPXYCB0xc0, &&OPXYCB0xc1, &&OPXYCB0xc2, &&OPXYCB0xc3,\r
+       &&OPXYCB0xc4, &&OPXYCB0xc5, &&OPXYCB0xc6, &&OPXYCB0xc7,\r
+       &&OPXYCB0xc8, &&OPXYCB0xc9, &&OPXYCB0xca, &&OPXYCB0xcb,\r
+       &&OPXYCB0xcc, &&OPXYCB0xcd, &&OPXYCB0xce, &&OPXYCB0xcf,\r
+\r
+       &&OPXYCB0xd0, &&OPXYCB0xd1, &&OPXYCB0xd2, &&OPXYCB0xd3,\r
+       &&OPXYCB0xd4, &&OPXYCB0xd5, &&OPXYCB0xd6, &&OPXYCB0xd7,\r
+       &&OPXYCB0xd8, &&OPXYCB0xd9, &&OPXYCB0xda, &&OPXYCB0xdb,\r
+       &&OPXYCB0xdc, &&OPXYCB0xdd, &&OPXYCB0xde, &&OPXYCB0xdf,\r
+\r
+       &&OPXYCB0xe0, &&OPXYCB0xe1, &&OPXYCB0xe2, &&OPXYCB0xe3,\r
+       &&OPXYCB0xe4, &&OPXYCB0xe5, &&OPXYCB0xe6, &&OPXYCB0xe7,\r
+       &&OPXYCB0xe8, &&OPXYCB0xe9, &&OPXYCB0xea, &&OPXYCB0xeb,\r
+       &&OPXYCB0xec, &&OPXYCB0xed, &&OPXYCB0xee, &&OPXYCB0xef,\r
+\r
+       &&OPXYCB0xf0, &&OPXYCB0xf1, &&OPXYCB0xf2, &&OPXYCB0xf3,\r
+       &&OPXYCB0xf4, &&OPXYCB0xf5, &&OPXYCB0xf6, &&OPXYCB0xf7,\r
+       &&OPXYCB0xf8, &&OPXYCB0xf9, &&OPXYCB0xfa, &&OPXYCB0xfb,\r
+       &&OPXYCB0xfc, &&OPXYCB0xfd, &&OPXYCB0xfe, &&OPXYCB0xff\r
+};\r
diff --git a/cpu/cz80/cz80macro.h b/cpu/cz80/cz80macro.h
new file mode 100644 (file)
index 0000000..91b49ef
--- /dev/null
@@ -0,0 +1,113 @@
+/******************************************************************************\r
+\r
+       cz80macro.h\r
+\r
+       CZ80 \8ae\8eí\83}\83N\83\8d\r
+\r
+******************************************************************************/\r
+\r
+#if CZ80_USE_JUMPTABLE\r
+#define _SSOP(A,B)                     A##B\r
+#define OP(A)                          _SSOP(OP,A)\r
+#define OPCB(A)                                _SSOP(OPCB,A)\r
+#define OPED(A)                                _SSOP(OPED,A)\r
+#define OPXY(A)                                _SSOP(OPXY,A)\r
+#define OPXYCB(A)                      _SSOP(OPXYCB,A)\r
+#else\r
+#define OP(A)                          case A\r
+#define OPCB(A)                                case A\r
+#define OPED(A)                                case A\r
+#define OPXY(A)                                case A\r
+#define OPXYCB(A)                      case A\r
+#endif\r
+\r
+#define USE_CYCLES(A)          CPU->ICount -= (A);\r
+#define ADD_CYCLES(A)          CPU->ICount += (A);\r
+\r
+#define RET(A)                         { USE_CYCLES(A) goto Cz80_Exec; }\r
+\r
+#if CZ80_ENCRYPTED_ROM\r
+\r
+#define SET_PC(A)                                                                                      \\r
+       CPU->BasePC = CPU->Fetch[(A) >> CZ80_FETCH_SFT];                \\r
+       OPBase = CPU->OPFetch[(A) >> CZ80_FETCH_SFT];                   \\r
+       PC = (A) + CPU->BasePC;\r
+\r
+#define GET_OP()                       (*(UINT8 *)(OPBase + PC))\r
+\r
+#else\r
+\r
+#define SET_PC(A)                                                                                      \\r
+       CPU->BasePC = CPU->Fetch[(A) >> CZ80_FETCH_SFT];                \\r
+       PC = (A) + CPU->BasePC;\r
+\r
+#define GET_OP()                       (*(UINT8 *)PC)\r
+\r
+#endif\r
+\r
+#define READ_OP()                      GET_OP(); PC++\r
+\r
+#define READ_ARG()                     (*(UINT8 *)PC++)\r
+#if CZ80_LITTLE_ENDIAN\r
+#define READ_ARG16()           (*(UINT8 *)PC | (*(UINT8 *)(PC + 1) << 8)); PC += 2\r
+#else\r
+#define READ_ARG16()           (*(UINT8 *)(PC + 1) | (*(UINT8 *)PC << 8)); PC += 2\r
+#endif\r
+\r
+//#ifndef BUILD_CPS1PSP\r
+//#define READ_MEM8(A)         memory_region_cpu2[(A)]\r
+//#else\r
+#define READ_MEM8(A)           CPU->Read_Byte(A)\r
+//#endif\r
+#if CZ80_LITTLE_ENDIAN\r
+#define READ_MEM16(A)          (READ_MEM8(A) | (READ_MEM8((A) + 1) << 8))\r
+#else\r
+#define READ_MEM16(A)          ((READ_MEM8(A) << 8) | READ_MEM8((A) + 1))\r
+#endif\r
+\r
+#define WRITE_MEM8(A, D)       CPU->Write_Byte(A, D);\r
+#if CZ80_LITTLE_ENDIAN\r
+#define WRITE_MEM16(A, D)      { WRITE_MEM8(A, D); WRITE_MEM8((A) + 1, (D) >> 8); }\r
+#else\r
+#define WRITE_MEM16(A, D)      { WRITE_MEM8((A) + 1, D); WRITE_MEM8(A, (D) >> 8); }\r
+#endif\r
+\r
+#define PUSH_16(A)                     { UINT32 sp; zSP -= 2; sp = zSP; WRITE_MEM16(sp, A); }\r
+#define POP_16(A)                      { UINT32 sp; sp = zSP; A = READ_MEM16(sp); zSP = sp + 2; }\r
+\r
+#define IN(A)                          CPU->IN_Port(A)\r
+#define OUT(A, D)                      CPU->OUT_Port(A, D)\r
+\r
+#define CHECK_INT                                                                                                      \\r
+       if (zIFF1)                                                                                                              \\r
+       {                                                                                                                               \\r
+               UINT32 IntVect;                                                                                         \\r
+                                                                                                                                       \\r
+               if (CPU->IRQState == HOLD_LINE)                                                         \\r
+                       CPU->IRQState = CLEAR_LINE;                                                             \\r
+                                                                                                                                       \\r
+               CPU->HaltState = 0;                                                                                     \\r
+               zIFF1 = zIFF2 = 0;                                                                                      \\r
+               IntVect = CPU->Interrupt_Callback(CPU->IRQLine);                        \\r
+                                                                                                                                       \\r
+               PUSH_16(zRealPC)                                                                                        \\r
+                                                                                                                                       \\r
+               if (zIM == 2)                                                                                           \\r
+               {                                                                                                                       \\r
+                       IntVect = (IntVect & 0xff) | (zI << 8);                                 \\r
+                       PC = READ_MEM16(IntVect);                                                               \\r
+                       CPU->ExtraCycles += 17;                                                                 \\r
+               }                                                                                                                       \\r
+               else if (zIM == 1)                                                                                      \\r
+               {                                                                                                                       \\r
+                       PC = 0x38;                                                                                              \\r
+                       CPU->ExtraCycles += 13;                                                                 \\r
+               }                                                                                                                       \\r
+               else                                                                                                            \\r
+               {                                                                                                                       \\r
+                       PC = IntVect & 0x38;                                                                    \\r
+                       CPU->ExtraCycles += 13;                                                                 \\r
+               }                                                                                                                       \\r
+                                                                                                                                       \\r
+               SET_PC(PC)                                                                                                      \\r
+       }\r
index db032d8..6aaf51b 100644 (file)
@@ -4,7 +4,7 @@ PSPSDK = $(shell psp-config --pspsdk-path)
 \r
 # settings\r
 #use_musashi = 1\r
-use_mz80 = 1\r
+#use_mz80 = 1\r
 amalgamate = 0\r
 #profile = 1\r
 #up = 1\r
@@ -69,13 +69,14 @@ ifeq "$(use_mz80)" "1"
 CFLAGS += -D_USE_MZ80\r
 OBJS += ../../cpu/mz80/mz80.o\r
 else\r
-$(error nothing here!)\r
+CFLAGS += -D_USE_CZ80\r
+OBJS += ../../cpu/cz80/cz80.o\r
 endif\r
 # bg images\r
 OBJS += data/bg32.o data/bg40.o\r
 \r
 \r
-LIBS += -lpng -lm -lpspgu -lpsppower -Wl,-Map=PicoDrive.map # -lpspaudio -lpsphprm\r
+LIBS += -lpng -lm -lpspgu -lpsppower -Wl,-Map=PicoDrive.map -lpspaudio\r
 \r
 # target\r
 TARGET = PicoDrive\r
index 8542a8f..df4a08e 100644 (file)
@@ -6,6 +6,7 @@
 #include <pspdisplay.h>
 #include <psputils.h>
 #include <pspgu.h>
+#include <pspaudio.h>
 
 #include "psp.h"
 #include "menu.h"
 #define OSD_FPS_X 420
 #endif
 
+// additional pspaudio imports, credits to crazyc
+int sceAudio_38553111(unsigned short samples, unsigned short freq, char unknown);  // play with conversion?
+int sceAudio_5C37C0AE(void);                           // end play?
+int sceAudio_E0727056(int volume, void *buffer);       // blocking output
+int sceAudioOutput2GetRestSample();
+
+
 char romFileName[PATH_MAX];
 unsigned char *PicoDraw2FB = (unsigned char *)VRAM_CACHED_STUFF + 8; // +8 to be able to skip border with 1 quadword..
 int engineState;
@@ -29,6 +37,8 @@ static unsigned int noticeMsgTime = 0;
 int reset_timing = 0; // do we need this?
 
 
+static void sound_init(void);
+static void sound_deinit(void);
 static void blit2(const char *fps, const char *notice);
 static void clearArea(int full);
 
@@ -82,6 +92,8 @@ void emu_Init(void)
        mkdir("brm", 0777);
        mkdir("cfg", 0777);
 
+       sound_init();
+
        PicoInit();
        PicoMessage = emu_msg_cb;
        PicoMCDopenTray = emu_msg_tray_open;
@@ -111,6 +123,7 @@ void emu_Deinit(void)
        }
 
        PicoExit();
+       sound_deinit();
 }
 
 void emu_setDefaultConfig(void)
@@ -462,14 +475,147 @@ static void vidResetMode(void)
        sceGuSync(0,0);
 }
 
-/*
-static void updateSound(int len)
+
+/* sound stuff */
+#define SOUND_DEF_BLOCK_SIZE 1024 // 1152 // 1024
+#define SOUND_BLOCK_COUNT    4
+
+static short __attribute__((aligned(4))) sndBuffer[SOUND_DEF_BLOCK_SIZE*SOUND_BLOCK_COUNT*2 + 44100/50*2];
+static short *snd_playptr = NULL;
+static int samples_made = 0, samples_done = 0, samples_block = SOUND_DEF_BLOCK_SIZE;
+static int sound_thread_exit = 0;
+static SceUID sound_sem = -1;
+
+static void writeSound(int len);
+
+static int sound_thread(SceSize args, void *argp)
 {
+       short *endptr = &sndBuffer[SOUND_DEF_BLOCK_SIZE*SOUND_BLOCK_COUNT*2];
+       int ret;
+
+       lprintf("sound_thread: started, priority %i\n", sceKernelGetThreadCurrentPriority());
+
+       while (!sound_thread_exit)
+       {
+               if (samples_made - samples_done < samples_block) {
+                       // wait for data...
+                       //lprintf("sthr: wait... (%i/%i)\n", samples_done, samples_made);
+                       ret = sceKernelWaitSema(sound_sem, 1, 0);
+                       //lprintf("sthr: sceKernelWaitSema: %i\n", ret);
+                       continue;
+               }
+
+               //lprintf("sthr: got data: %i\n", samples_made - samples_done);
+
+               ret = sceAudio_E0727056(PSP_AUDIO_VOLUME_MAX, snd_playptr);
+
+               samples_done += samples_block;
+               snd_playptr  += samples_block;
+               if (snd_playptr >= endptr)
+                       snd_playptr = sndBuffer;
+               if (ret)
+                       lprintf("sthr: outf: %i; pos %i/%i\n", ret, samples_done, samples_made);
+       }
+
+       lprintf("sthr: exit\n");
+       sceKernelExitDeleteThread(0);
+       return 0;
+}
+
+static void sound_init(void)
+{
+       SceUID thid;
+
+       sound_sem = sceKernelCreateSema("sndsem", 0, 0, 1, NULL);
+       if (sound_sem < 0) lprintf("sceKernelCreateSema() failed: %i\n", sound_sem);
+
+       sound_thread_exit = 0;
+       thid = sceKernelCreateThread("sndthread", sound_thread, 0x12, 0x10000, 0, NULL);
+       if (thid >= 0)
+       {
+               sceKernelStartThread(thid, 0, 0);
+       }
+       else
+               lprintf("sceKernelCreateThread failed: %i\n", thid);
+}
+
+static void sound_prepare(void)
+{
+       static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;
+       int ret, stereo;
+
+       samples_made = samples_done = 0;
+
+       if (PsndRate != PsndRate_old || (PicoOpt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
+               sound_rerate(Pico.m.frame_count ? 1 : 0);
+       }
+       stereo=(PicoOpt&8)>>3;
+       samples_block = SOUND_DEF_BLOCK_SIZE;
+       if (PsndRate < 44100) samples_block = SOUND_DEF_BLOCK_SIZE / 2;
+       if (PsndRate < 22050) samples_block = SOUND_DEF_BLOCK_SIZE / 4;
+
+       lprintf("starting audio: %i, len: %i, stereo: %i, pal: %i, block samples: %i\n",
+                       PsndRate, PsndLen, stereo, Pico.m.pal, samples_block);
+
+       while (sceAudioOutput2GetRestSample() > 0) psp_msleep(100);
+       sceAudio_5C37C0AE();
+       ret = sceAudio_38553111(samples_block/2, PsndRate, 2/*stereo ? 2 : 1*/);
+               lprintf("sceAudio_38553111() ret: %i\n", ret);
+       if (ret < 0) {
+               lprintf("sceAudio_38553111() failed: %i\n", ret);
+               sprintf(noticeMsg, "sound init failed (%i), snd disabled", ret);
+               noticeMsgTime = sceKernelGetSystemTimeLow();
+               currentConfig.EmuOpt &= ~4;
+       } else {
+//             int ret = sceAudioSetChannelDataLen(ret, PsndLen); // a try..
+//             lprintf("sceAudioSetChannelDataLen: %i\n", ret);
+               PicoWriteSound = writeSound;
+               memset32((int *)(void *)sndBuffer, 0, sizeof(sndBuffer)/4);
+               snd_playptr = sndBuffer;
+               PsndOut = sndBuffer;
+               PsndRate_old = PsndRate;
+               PicoOpt_old  = PicoOpt;
+               pal_old = Pico.m.pal;
+       }
+}
+
+static void sound_end(void)
+{
+       int ret;
+       while (sceAudioOutput2GetRestSample() > 0) psp_msleep(100);
+       ret = sceAudio_5C37C0AE();
+       lprintf("sound_end: sceAudio_5C37C0AE ret %i\n", ret);
+}
+
+static void sound_deinit(void)
+{
+       sound_thread_exit = 1;
+       sceKernelSignalSema(sound_sem, 1);
+}
+
+static void writeSound(int len)
+{
+       int ret;
+       short *endptr = &sndBuffer[SOUND_DEF_BLOCK_SIZE*SOUND_BLOCK_COUNT*2];
        if (PicoOpt&8) len<<=1;
 
-       // TODO..
+       PsndOut += len;
+       if (PsndOut > endptr) {
+               memcpy32((int *)(void *)sndBuffer, (int *)endptr, (PsndOut - endptr + 1) / 2);
+               PsndOut = &sndBuffer[PsndOut - endptr];
+       }
+       else if (PsndOut == endptr)
+               PsndOut = sndBuffer; // happy case
+
+       // signal the snd thread
+       samples_made += len;
+       if (samples_made - samples_done >= samples_block) {
+               if (!Pico.m.scanline) lprintf("signal, %i/%i\n", samples_done, samples_made);
+               ret = sceKernelSignalSema(sound_sem, 1);
+               if (!Pico.m.scanline) lprintf("signal ret %i\n", ret);
+       }
 }
-*/
+
 
 static void SkipFrame(void)
 {
@@ -490,6 +636,7 @@ void emu_forcedFrame(void)
        vidResetMode();
        memset32(VRAM_CACHED_STUFF, 0xe0e0e0e0, 512*8/4); // borders
        memset32((int *)VRAM_CACHED_STUFF + 512*232/4, 0xe0e0e0e0, 512*8/4);
+       memset32((int *)psp_screen + 512*264*2/4, 0, 512*8*2/4);
 
        PicoDrawSetColorFormat(-1);
        PicoScan = EmuScanSlow;
@@ -676,7 +823,6 @@ static void simpleWait(unsigned int until)
 
 void emu_Loop(void)
 {
-       //static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;
        char fpsbuff[24]; // fps count c string
        unsigned int tval, tval_prev = 0, tval_thissec = 0; // timing
        int frames_done = 0, frames_shown = 0, oldmodes = 0;
@@ -711,36 +857,10 @@ void emu_Loop(void)
 
        // prepare sound stuff
        PsndOut = NULL;
-#if 0 // TODO
        if (currentConfig.EmuOpt & 4)
        {
-               int ret, snd_excess_add, stereo;
-               if (PsndRate != PsndRate_old || (PicoOpt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
-                       sound_rerate(Pico.m.frame_count ? 1 : 0);
-               }
-               stereo=(PicoOpt&8)>>3;
-               snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;
-               snd_cbuf_samples = (PsndRate<<stereo) * 16 / target_fps;
-               lprintf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",
-                       PsndRate, PsndLen, snd_excess_add, stereo, Pico.m.pal);
-               ret = FrameworkAudio_Init(PsndRate, snd_cbuf_samples, stereo);
-               if (ret != 0) {
-                       lprintf("FrameworkAudio_Init() failed: %i\n", ret);
-                       sprintf(noticeMsg, "sound init failed (%i), snd disabled", ret);
-                       noticeMsgTime = sceKernelGetSystemTimeLow();
-                       currentConfig.EmuOpt &= ~4;
-               } else {
-                       FrameworkAudio_SetVolume(currentConfig.volume, currentConfig.volume);
-                       PicoWriteSound = updateSound;
-                       snd_cbuff = FrameworkAudio_56448Buffer();
-                       PsndOut = snd_cbuff + snd_cbuf_samples / 2; // start writing at the middle
-                       snd_all_samples = 0;
-                       PsndRate_old = PsndRate;
-                       PicoOpt_old  = PicoOpt;
-                       pal_old = Pico.m.pal;
-               }
+               sound_prepare();
        }
-#endif
 
        // loop?
        while (engineState == PGS_Running)
@@ -875,18 +995,21 @@ void emu_Loop(void)
 
 
        if (PicoMCD & 1) PicoCDBufferFree();
-/*
+
        if (PsndOut != NULL) {
-               PsndOut = snd_cbuff = NULL;
-               FrameworkAudio_Close();
+               PsndOut = NULL;
+               sound_end();
        }
-*/
+
        // save SRAM
        if ((currentConfig.EmuOpt & 1) && SRam.changed) {
                emu_msg_cb("Writing SRAM/BRAM..");
                emu_SaveLoadGame(0, 1);
                SRam.changed = 0;
        }
+
+       // draw a frame for bg..
+       emu_forcedFrame();
 }
 
 
index 27cb28a..356597f 100644 (file)
@@ -43,7 +43,7 @@ static unsigned short bg_buffer[480*272] __attribute__((aligned(16)));
 #define menu_screen psp_screen
 
 static void menu_darken_bg(void *dst, const void *src, int pixels, int darker);
-static void menu_prepare_bg(int use_game_bg, int use_back_buff);
+static void menu_prepare_bg(int use_game_bg);
 
 
 static unsigned int inp_prev = 0;
@@ -552,7 +552,7 @@ static void draw_savestate_bg(int slot)
        }
 
        emu_forcedFrame();
-       menu_prepare_bg(1, 1);
+       menu_prepare_bg(1);
 
        restore_oldstate(oldstate);
 }
@@ -1001,7 +1001,6 @@ static void menu_opt3_preview(int is_32col)
                void *bgdata = is_32col ? bgdatac32_start : bgdatac40_start;
                unsigned long insize = is_32col ? bgdatac32_size : bgdatac40_size, outsize = 65856;
                int ret;
-               lprintf("%p %p %i %i (n %p)\n", bgdatac32_start, bgdatac40_start, bgdatac32_size, bgdatac40_size, &engineState);
                ret = uncompress((Bytef *)bg_buffer, &outsize, bgdata, insize);
                if (ret == 0)
                {
@@ -1017,7 +1016,7 @@ static void menu_opt3_preview(int is_32col)
 
        memset32(psp_screen, 0, 512*272*2/4);
        emu_forcedFrame();
-       menu_prepare_bg(1, 1);
+       menu_prepare_bg(1);
 
        if (oldstate) restore_oldstate(oldstate);
 }
@@ -1165,7 +1164,6 @@ static void amenu_loop_options(void)
 menu_entry opt_entries[] =
 {
        { NULL,                        MB_NONE,  MA_OPT_RENDERER,      NULL, 0, 0, 0, 1 },
-       { "Scale low res mode",        MB_ONOFF, MA_OPT_SCALING,       &currentConfig.scaling, 0x0001, 0, 3, 1 },
        { "Accurate timing (slower)",  MB_ONOFF, MA_OPT_ACC_TIMING,    &currentConfig.PicoOpt, 0x0040, 0, 0, 1 },
        { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES,   &currentConfig.PicoOpt, 0x0080, 0, 0, 1 },
        { "Show FPS",                  MB_ONOFF, MA_OPT_SHOW_FPS,      &currentConfig.EmuOpt,  0x0002, 0, 0, 1 },
@@ -1672,13 +1670,13 @@ static void menu_darken_bg(void *dst, const void *src, int pixels, int darker)
        }
 }
 
-static void menu_prepare_bg(int use_game_bg, int use_back_buff)
+static void menu_prepare_bg(int use_game_bg)
 {
        if (use_game_bg)
        {
                // darken the active framebuffer
                unsigned short *dst = bg_buffer;
-               unsigned short *src = use_back_buff ? psp_screen : psp_video_get_active_fb();
+               unsigned short *src = psp_screen;
                int i;
                for (i = 272; i > 0; i--, dst += 480, src += 512)
                        menu_darken_bg(dst, src, 480, 1);
@@ -1695,7 +1693,7 @@ static void menu_prepare_bg(int use_game_bg, int use_back_buff)
 
 static void menu_gfx_prepare(void)
 {
-       menu_prepare_bg(rom_data != NULL, 0);
+       menu_prepare_bg(rom_data != NULL);
 
        menu_draw_begin();
        menu_draw_end();
index 84ab5c8..b2d0d72 100644 (file)
@@ -32,7 +32,8 @@ static int callback_thread(SceSize args, void *argp)
 {
        int cbid;
 
-       lprintf("callback_thread started with id %i\n", sceKernelGetThreadId());
+       lprintf("callback_thread started with id %i, priority %i\n",
+               sceKernelGetThreadId(), sceKernelGetThreadCurrentPriority());
 
        cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
        sceKernelRegisterExitCallback(cbid);
@@ -44,9 +45,10 @@ static int callback_thread(SceSize args, void *argp)
 
 void psp_init(void)
 {
-       int thid;
+       SceUID thid;
 
-       lprintf("entered psp_init, threadId %i\n", sceKernelGetThreadId());
+       lprintf("entered psp_init, threadId %i, priority %i\n", sceKernelGetThreadId(),
+               sceKernelGetThreadCurrentPriority());
 
        thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, 0);
        if (thid >= 0)