improved irq handling Cz80_Exec() calls with lots of cycles
authornotaz <notasas@gmail.com>
Sun, 25 May 2008 21:01:55 +0000 (21:01 +0000)
committernotaz <notasas@gmail.com>
Sun, 25 May 2008 21:01:55 +0000 (21:01 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@458 be3aeb3a-fb24-0410-a615-afba39da0efa

cpu/DrZ80/drz80.s
cpu/cz80/cz80.c
cpu/cz80/cz80.h
cpu/cz80/cz80_op.c

index ee14013..9b07a13 100644 (file)
@@ -106,21 +106,6 @@ DrZ80Ver: .long 0x0001
 \r
 .if DRZ80_FOR_PICODRIVE\r
 \r
-.macro YM2612Read_and_ret8\r
-    ldr r0, =ym2612_st\r
-    ldr r0, [r0]\r
-    ldrb r0, [r0, #0x11]   ;@ ym2612_st->status\r
-    bx lr\r
-.endm\r
-\r
-.macro YM2612Read_and_ret16\r
-    ldr r0, =ym2612_st\r
-    ldr r0, [r0]\r
-    ldrb r0, [r0, #0x11]   ;@ ym2612_st->status\r
-    orr r0,r0,r0,lsl #8\r
-    bx lr\r
-.endm\r
-\r
 pico_z80_read8: @ addr\r
     cmp r0,#0x2000         @ Z80 RAM\r
     ldrlt r1,[cpucontext,#z80sp_base]\r
@@ -139,15 +124,18 @@ pico_z80_read8: @ addr
     eorlt r0,r0,#1         @ our ROM is byteswapped\r
     ldrltb r0,[r1,r0]\r
     bxlt lr\r
-       stmfd sp!,{r3,r12,lr}\r
+    stmfd sp!,{r3,r12,lr}\r
     bl PicoRead8\r
-       ldmfd sp!,{r3,r12,pc}\r
+    ldmfd sp!,{r3,r12,pc}\r
 1:\r
     mov r1,r0,lsr #13\r
     cmp r1,#2              @ YM2612 (0x4000-0x5fff)\r
     bne 0f\r
     and r0,r0,#3\r
-    YM2612Read_and_ret8\r
+    stmfd sp!,{r3,r12,lr}\r
+    str z80_icount,[cpucontext,#cycles_pointer]\r
+    bl ym2612_read_local_z80\r
+    ldmfd sp!,{r3,r12,pc}\r
 0:\r
     cmp r0,#0x4000\r
     movge r0,#0xff\r
@@ -197,7 +185,11 @@ pico_z80_read16: @ addr
     cmp r1,#2              @ YM2612 (0x4000-0x5fff)\r
     bne 0f\r
     and r0,r0,#3\r
-    YM2612Read_and_ret16\r
+    stmfd sp!,{r3,r12,lr}\r
+    str z80_icount,[cpucontext,#cycles_pointer]\r
+    bl ym2612_read_local_z80\r
+    orr r0,r0,r0,lsl #8\r
+    ldmfd sp!,{r3,r12,pc}\r
 0:\r
     cmp r0,#0x4000\r
     movge r0,#0xff\r
@@ -218,6 +210,7 @@ pico_z80_write8: @ data, addr
     bx lr\r
 1:\r
     stmfd sp!,{r3,r12,lr}\r
+    str z80_icount,[cpucontext,#cycles_pointer]\r
     bl z80_write\r
     ldmfd sp!,{r3,r12,pc}\r
 \r
@@ -231,14 +224,15 @@ pico_z80_write16: @ data, addr
     strb r0,[r2,#1]\r
     bx lr\r
 1:\r
-       stmfd sp!,{r3-r5,r12,lr}\r
+    stmfd sp!,{r3-r5,r12,lr}\r
+    str z80_icount,[cpucontext,#cycles_pointer]\r
     mov r4,r0\r
     mov r5,r1\r
-       bl z80_write\r
+    bl z80_write\r
     mov r0,r4,lsr #8\r
     add r1,r5,#1\r
-       bl z80_write\r
-       ldmfd sp!,{r3-r5,r12,pc}\r
+    bl z80_write\r
+    ldmfd sp!,{r3-r5,r12,pc}\r
 \r
     .pool\r
 .endif\r
index d7bdba3..18fd620 100644 (file)
@@ -270,6 +270,8 @@ Cz80_Check_Interrupt:
                        if (CPU->IRQState != CLEAR_LINE)\r
                        {\r
                                CHECK_INT\r
+                               CPU->ICount -= CPU->ExtraCycles;\r
+                               CPU->ExtraCycles = 0;\r
                        }\r
                        goto Cz80_Exec;\r
                }\r
index e097460..d23d793 100644 (file)
@@ -61,7 +61,7 @@ extern "C" {
 //#else\r
 #define CZ80_ENCRYPTED_ROM             0\r
 //#endif\r
-#define CZ80_EMULATE_R_EXACTLY 0\r
+#define CZ80_EMULATE_R_EXACTLY 1\r
 \r
 #define zR8(A)         (*CPU->pzR8[A])\r
 #define zR16(A)                (CPU->pzR16[A]->W)\r
index ed13c9e..a4a5ef9 100644 (file)
@@ -712,8 +712,10 @@ OP_EI:
                        if (CPU->IRQState)\r
                        {\r
                                afterEI = 1;\r
+                               CPU->ExtraCycles += 1 - CPU->ICount;\r
+                               CPU->ICount = 1;\r
                        }\r
-                       if (CPU->ICount <= 0)\r
+                       else if (CPU->ICount <= 0)\r
                        {\r
                                CPU->ICount = 1;\r
                        }\r