CPU->pzR16[3] = pzAF;\r
\r
zIX = zIY = 0xffff;\r
- zF = ZF;\r
\r
CPU->Interrupt_Callback = Cz80_Interrupt_Callback;\r
}\r
UINT32 adr = 0;\r
UINT32 res;\r
UINT32 val;\r
- int afterEI = 0;\r
union16 *data;\r
\r
PC = CPU->PC;\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
+ if (CPU->Status)\r
+ {\r
+ if (CPU->Status & CZ80_HAS_NMI)\r
{\r
+ zIFF1 = 0;\r
+ CPU->Status &= ~(CZ80_HALTED | CZ80_HAS_NMI);\r
+ CPU->ExtraCycles += 11;\r
+ PUSH_16(zRealPC);\r
+ SET_PC(0x66);\r
+ } else if (CPU->Status & CZ80_HAS_INT)\r
+ {\r
+ CHECK_INT\r
+ } else if (CPU->Status & CZ80_HALTED)\r
+ {\r
+ goto Cz80_Exec_End;\r
+ }\r
+ CPU->ICount -= CPU->ExtraCycles;\r
+ CPU->ExtraCycles = 0;\r
+ }\r
+\r
+ if (CPU->ICount > 0)\r
+ {\r
Cz80_Exec_nocheck:\r
- data = pzHL;\r
- Opcode = READ_OP();\r
+ data = pzHL;\r
+ Opcode = READ_OP();\r
#if CZ80_EMULATE_R_EXACTLY\r
- zR++;\r
+ zR++;\r
#endif\r
- #include "cz80_op.c"\r
- }\r
-\r
- if (afterEI)\r
- {\r
- afterEI = 0;\r
-Cz80_Check_Interrupt:\r
- if (CPU->IRQState != CLEAR_LINE)\r
- {\r
- CHECK_INT\r
- }\r
- CPU->ICount -= CPU->ExtraCycles;\r
- CPU->ExtraCycles = 0;\r
- if (!CPU->HaltState)\r
- goto Cz80_Exec;\r
- }\r
+ #include "cz80_op.c"\r
}\r
\r
Cz80_Exec_End:\r
#if CZ80_ENCRYPTED_ROM\r
CPU->OPBase = OPBase;\r
#endif\r
- if (!(CPU->HaltState && CPU->ICount > 0))\r
+ if (!((CPU->Status & CZ80_HALTED) && CPU->ICount > 0))\r
cycles -= CPU->ICount;\r
CPU->ICount = 0;\r
#if !CZ80_EMULATE_R_EXACTLY\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
+ if (state)\r
+ CPU->Status |= CZ80_HAS_NMI;\r
+ else\r
+ CPU->Status &= ~CZ80_HAS_NMI;\r
+ } else\r
{\r
+ CPU->IRQLine = line;\r
CPU->IRQState = state;\r
-\r
- if (state != CLEAR_LINE)\r
+ if (state)\r
{\r
- FPTR PC = CPU->PC;\r
-#if CZ80_ENCRYPTED_ROM\r
- FPTR 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
+ if (zIFF1)\r
+ CPU->Status |= CZ80_HAS_INT;\r
+ } else\r
+ {\r
+ CPU->Status &= ~CZ80_HAS_INT;\r
}\r
}\r
- if (CPU->ICount > 0)\r
- {\r
- CPU->ICount -= CPU->ExtraCycles;\r
- CPU->ExtraCycles = 0;\r
- }\r
}\r
\r
\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_HALT: return CPU->Status & CZ80_HALTED;\r
case CZ80_IRQ: return CPU->IRQState;\r
default: return 0;\r
}\r
case CZ80_IM: zIM = val; break;\r
case CZ80_IFF1: zIFF1 = val ? (1 << 2) : 0; break;\r
case CZ80_IFF2: zIFF2 = val ? (1 << 2) : 0; break;\r
- case CZ80_HALT: CPU->HaltState = val; break;\r
+ case CZ80_HALT: CPU->Status = !!val * CZ80_HALTED; break;\r
case CZ80_IRQ: CPU->IRQState = val; break;\r
default: break;\r
}\r
zIFF1 = (1 << 2);\r
if (CPU->IRQState)\r
{\r
- USE_CYCLES(10)\r
- goto Cz80_Check_Interrupt;\r
+ CPU->Status |= CZ80_HAS_INT;\r
}\r
}\r
else zIFF1 = zIFF2;\r
-----------------------------------------*/\r
\r
OPED(0xb0): // LDIR\r
+ if (zBC != 1)\r
+ PC -= 2;\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
+ USE_CYCLES(21)\r
+ } while (zBC > 1 && (CPU->ICount > 0) && !CPU->Status);\r
goto OP_LDXR;\r
\r
OPED(0xb8): // LDDR\r
+ if (zBC != 1)\r
+ PC -= 2;\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
+ USE_CYCLES(21)\r
+ } while (zBC > 1 && (CPU->ICount > 0) && !CPU->Status);\r
\r
OP_LDXR:\r
F = zF & (SF | ZF | CF);\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
+ ADD_CYCLES(4)\r
+ goto Cz80_Exec;\r
}\r
zF = F;\r
- ADD_CYCLES(5)\r
+ ADD_CYCLES(4+5)\r
goto Cz80_Exec;\r
\r
/*-----------------------------------------\r
-----------------------------------------*/\r
\r
OPED(0xb1): // CPIR\r
+ if (zBC != 1)\r
+ PC -= 2;\r
do\r
{\r
val = READ_MEM8(zHL++);\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
+ USE_CYCLES(21)\r
+ } while (zBC > 1 && !(F & ZF) && (CPU->ICount > 0) && !CPU->Status);\r
goto OP_CPXR;\r
\r
OPED(0xb9): // CPDR\r
+ if (zBC != 1)\r
+ PC -= 2;\r
do\r
{\r
val = READ_MEM8(zHL--);\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
+ USE_CYCLES(21)\r
+ } while (zBC > 1 && !(F & ZF) && (CPU->ICount > 0) && !CPU->Status);\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
+ ADD_CYCLES(4)\r
+ goto Cz80_Exec;\r
}\r
- ADD_CYCLES(5)\r
+ ADD_CYCLES(4+5)\r
goto Cz80_Exec;\r
\r
/*-----------------------------------------\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
+ if (res < val) F |= HF | CF;\r
F |= SZP[(UINT8)(res & 0x07) ^ zB] & PF;\r
zF = F;\r
RET(12)\r
-----------------------------------------*/\r
\r
OPED(0xb2): // INIR\r
+ if (zB != 1)\r
+ PC -= 2;\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
+ USE_CYCLES(21)\r
+ } while (zB > 1 && (CPU->ICount > 0) && !CPU->Status);\r
goto OP_INXR;\r
\r
OPED(0xba): // INDR\r
+ if (zB != 1)\r
+ PC -= 2;\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
+ USE_CYCLES(21)\r
+ } while (zB > 1 && (CPU->ICount > 0) && !CPU->Status);\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
+ if (res < val) 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
+ ADD_CYCLES(4)\r
+ goto Cz80_Exec;\r
}\r
- ADD_CYCLES(5);\r
+ ADD_CYCLES(4+5);\r
goto Cz80_Exec;\r
\r
/*-----------------------------------------\r
F = SZ[zB];\r
res = (UINT32)zL + (UINT32)val;\r
if (val & SF) F |= NF;\r
- if (res & 0x100) F |= HF | CF;\r
+ if (res < val) F |= HF | CF;\r
F |= SZP[(UINT8)(res & 0x07) ^ zB] & PF;\r
zF = F;\r
RET(12)\r
-----------------------------------------*/\r
\r
OPED(0xb3): // OTIR\r
+ if (zB != 1)\r
+ PC -= 2;\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
+ USE_CYCLES(21)\r
+ } while (zB > 1 && (CPU->ICount > 0) && !CPU->Status);\r
goto OP_OTXR;\r
\r
OPED(0xbb): // OTDR\r
+ if (zB != 1)\r
+ PC -= 2;\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
+ USE_CYCLES(21)\r
+ } while (zB > 1 && (CPU->ICount > 0) && !CPU->Status);\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
+ if (res < val) 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
+ ADD_CYCLES(4)\r
+ goto Cz80_Exec;\r
}\r
- ADD_CYCLES(5)\r
+ ADD_CYCLES(4+5)\r
goto Cz80_Exec;\r
}\r
\r