From 170435846c8e2309dc4011f954287f9ea861a6b6 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 25 May 2008 21:01:55 +0000 Subject: [PATCH] improved irq handling Cz80_Exec() calls with lots of cycles git-svn-id: file:///home/notaz/opt/svn/PicoDrive@458 be3aeb3a-fb24-0410-a615-afba39da0efa --- cpu/DrZ80/drz80.s | 40 +++++++++++++++++----------------------- cpu/cz80/cz80.c | 2 ++ cpu/cz80/cz80.h | 2 +- cpu/cz80/cz80_op.c | 4 +++- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/cpu/DrZ80/drz80.s b/cpu/DrZ80/drz80.s index ee140130..9b07a133 100644 --- a/cpu/DrZ80/drz80.s +++ b/cpu/DrZ80/drz80.s @@ -106,21 +106,6 @@ DrZ80Ver: .long 0x0001 .if DRZ80_FOR_PICODRIVE -.macro YM2612Read_and_ret8 - ldr r0, =ym2612_st - ldr r0, [r0] - ldrb r0, [r0, #0x11] ;@ ym2612_st->status - bx lr -.endm - -.macro YM2612Read_and_ret16 - ldr r0, =ym2612_st - ldr r0, [r0] - ldrb r0, [r0, #0x11] ;@ ym2612_st->status - orr r0,r0,r0,lsl #8 - bx lr -.endm - pico_z80_read8: @ addr cmp r0,#0x2000 @ Z80 RAM ldrlt r1,[cpucontext,#z80sp_base] @@ -139,15 +124,18 @@ pico_z80_read8: @ addr eorlt r0,r0,#1 @ our ROM is byteswapped ldrltb r0,[r1,r0] bxlt lr - stmfd sp!,{r3,r12,lr} + stmfd sp!,{r3,r12,lr} bl PicoRead8 - ldmfd sp!,{r3,r12,pc} + ldmfd sp!,{r3,r12,pc} 1: mov r1,r0,lsr #13 cmp r1,#2 @ YM2612 (0x4000-0x5fff) bne 0f and r0,r0,#3 - YM2612Read_and_ret8 + stmfd sp!,{r3,r12,lr} + str z80_icount,[cpucontext,#cycles_pointer] + bl ym2612_read_local_z80 + ldmfd sp!,{r3,r12,pc} 0: cmp r0,#0x4000 movge r0,#0xff @@ -197,7 +185,11 @@ pico_z80_read16: @ addr cmp r1,#2 @ YM2612 (0x4000-0x5fff) bne 0f and r0,r0,#3 - YM2612Read_and_ret16 + stmfd sp!,{r3,r12,lr} + str z80_icount,[cpucontext,#cycles_pointer] + bl ym2612_read_local_z80 + orr r0,r0,r0,lsl #8 + ldmfd sp!,{r3,r12,pc} 0: cmp r0,#0x4000 movge r0,#0xff @@ -218,6 +210,7 @@ pico_z80_write8: @ data, addr bx lr 1: stmfd sp!,{r3,r12,lr} + str z80_icount,[cpucontext,#cycles_pointer] bl z80_write ldmfd sp!,{r3,r12,pc} @@ -231,14 +224,15 @@ pico_z80_write16: @ data, addr strb r0,[r2,#1] bx lr 1: - stmfd sp!,{r3-r5,r12,lr} + stmfd sp!,{r3-r5,r12,lr} + str z80_icount,[cpucontext,#cycles_pointer] mov r4,r0 mov r5,r1 - bl z80_write + bl z80_write mov r0,r4,lsr #8 add r1,r5,#1 - bl z80_write - ldmfd sp!,{r3-r5,r12,pc} + bl z80_write + ldmfd sp!,{r3-r5,r12,pc} .pool .endif diff --git a/cpu/cz80/cz80.c b/cpu/cz80/cz80.c index d7bdba3b..18fd620e 100644 --- a/cpu/cz80/cz80.c +++ b/cpu/cz80/cz80.c @@ -270,6 +270,8 @@ Cz80_Check_Interrupt: if (CPU->IRQState != CLEAR_LINE) { CHECK_INT + CPU->ICount -= CPU->ExtraCycles; + CPU->ExtraCycles = 0; } goto Cz80_Exec; } diff --git a/cpu/cz80/cz80.h b/cpu/cz80/cz80.h index e097460b..d23d7936 100644 --- a/cpu/cz80/cz80.h +++ b/cpu/cz80/cz80.h @@ -61,7 +61,7 @@ extern "C" { //#else #define CZ80_ENCRYPTED_ROM 0 //#endif -#define CZ80_EMULATE_R_EXACTLY 0 +#define CZ80_EMULATE_R_EXACTLY 1 #define zR8(A) (*CPU->pzR8[A]) #define zR16(A) (CPU->pzR16[A]->W) diff --git a/cpu/cz80/cz80_op.c b/cpu/cz80/cz80_op.c index ed13c9e7..a4a5ef9b 100644 --- a/cpu/cz80/cz80_op.c +++ b/cpu/cz80/cz80_op.c @@ -712,8 +712,10 @@ OP_EI: if (CPU->IRQState) { afterEI = 1; + CPU->ExtraCycles += 1 - CPU->ICount; + CPU->ICount = 1; } - if (CPU->ICount <= 0) + else if (CPU->ICount <= 0) { CPU->ICount = 1; } -- 2.39.5