From: notaz Date: Sat, 15 Aug 2009 18:54:59 +0000 (+0000) Subject: drZ80 separation finished, related bugs fixed X-Git-Tag: v1.85~294 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8f51995c466282c7c93f3666b1bc54b827ec19e;p=picodrive.git drZ80 separation finished, related bugs fixed git-svn-id: file:///home/notaz/opt/svn/PicoDrive@755 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/cpu/DrZ80/drz80.s b/cpu/DrZ80/drz80.s index 5445ffd0..a623451b 100644 --- a/cpu/DrZ80/drz80.s +++ b/cpu/DrZ80/drz80.s @@ -14,12 +14,12 @@ .equiv INTERRUPT_MODE, 0 ;@0 = Use internal int handler, 1 = Use Mames int handler .equiv FAST_Z80SP, 1 ;@0 = Use mem functions for stack pointer, 1 = Use direct mem pointer .equiv UPDATE_CONTEXT, 0 - .equiv DRZ80_FOR_PICODRIVE, 1 .equiv DRZ80_XMAP, 1 .equiv DRZ80_XMAP_MORE_INLINE, 1 .if DRZ80_XMAP .equ Z80_MEM_SHIFT, 13 + ;@ note: stack is locked in single bank that z80sp_base points to .endif .if INTERRUPT_MODE @@ -160,14 +160,14 @@ z80_xmap_read16: @ addr 0: @ z80_xmap_read8 will save r3 and r12 for us - stmfd sp!,{r4,r5,lr} - mov r4,r0 + stmfd sp!,{r8,r9,lr} + mov r8,r0 bl z80_xmap_read8 - mov r5,r0 - add r0,r4,#1 + mov r9,r0 + add r0,r8,#1 bl z80_xmap_read8 - orr r0,r5,r0,lsl #8 - ldmfd sp!,{r4,r5,pc} + orr r0,r9,r0,lsl #8 + ldmfd sp!,{r8,r9,pc} z80_xmap_write16: @ data, addr add r2,r1,#1 @@ -187,14 +187,30 @@ z80_xmap_write16: @ data, addr bx lr 0: - stmfd sp!,{r4,r5,lr} - mov r4,r0 - mov r5,r1 + stmfd sp!,{r8,r9,lr} + mov r8,r0 + mov r9,r1 bl z80_xmap_write8 - mov r0,r4,lsr #8 - add r1,r5,#1 + mov r0,r8,lsr #8 + add r1,r9,#1 bl z80_xmap_write8 - ldmfd sp!,{r4,r5,pc} + ldmfd sp!,{r8,r9,pc} + +z80_xmap_rebase_pc: + ldr r1,[cpucontext,#z80_read8] + mov r2,r0,lsr #Z80_MEM_SHIFT + ldr r1,[r1,r2,lsl #2] + movs r1,r1,lsl #1 + strcc r1,[cpucontext,#z80pc_base] + addcc z80pc,r1,r0 + bxcc lr + +z80_bad_jump: + ldr r0,[cpucontext,#z80_read8] + ldr r0,[r0] + str r0,[cpucontext,#z80pc_base] + mov z80pc,r0 + bx lr .endif @@ -335,10 +351,8 @@ z80_xmap_write16: @ data, addr .if UPDATE_CONTEXT str z80pc,[cpucontext,#z80pc_pointer] .endif -.if DRZ80_FOR_PICODRIVE - ldr r1,[cpucontext,#z80pc_base] - bic r0,r0,#0xfe000 - add z80pc,r1,r0 +.if DRZ80_XMAP + bl z80_xmap_rebase_pc .else stmfd sp!,{r3,r12} mov lr,pc @@ -352,9 +366,10 @@ z80_xmap_write16: @ data, addr .if UPDATE_CONTEXT str z80pc,[cpucontext,#z80pc_pointer] .endif -.if DRZ80_FOR_PICODRIVE - bic r0,r0,#0xfe000 +.if DRZ80_XMAP + ;@ XXX: SP is locked to single back z80sp_base points to. ldr r1,[cpucontext,#z80sp_base] + bic r0,r0,#0x7f< r1 .if FAST_Z80SP -.if DRZ80_FOR_PICODRIVE - @ notaz: try to protect against stack overflows, which tend to happen in Picodrive because of poor timing - ldr r0,[cpucontext,#z80sp_base] - cmp z80sp,r0 - addle z80sp,z80sp,#0x2000 - mov r1,\reg, lsr #8 - strb r1,[z80sp,#-1]! - cmp z80sp,r0 - addle z80sp,z80sp,#0x2000 - strb \reg,[z80sp,#-1]! -.else +.if DRZ80_XMAP + stack_check +.endif mov r1,\reg, lsr #8 strb r1,[z80sp,#-1]! strb \reg,[z80sp,#-1]! -.endif .else mov r0,\reg sub z80sp,z80sp,#2 @@ -779,22 +780,13 @@ z80_xmap_write16: @ data, addr .macro opPUSHreg reg .if FAST_Z80SP -.if DRZ80_FOR_PICODRIVE - ldr r0,[cpucontext,#z80sp_base] - cmp z80sp,r0 - addle z80sp,z80sp,#0x2000 - mov r1,\reg, lsr #24 - strb r1,[z80sp,#-1]! - cmp z80sp,r0 - addle z80sp,z80sp,#0x2000 - mov r1,\reg, lsr #16 - strb r1,[z80sp,#-1]! -.else +.if DRZ80_XMAP + stack_check +.endif mov r1,\reg, lsr #24 strb r1,[z80sp,#-1]! mov r1,\reg, lsr #16 strb r1,[z80sp,#-1]! -.endif .else mov r0,\reg,lsr #16 sub z80sp,z80sp,#2 diff --git a/pico/cd/memory.c b/pico/cd/memory.c index 4e56bf7a..8110a2e1 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -1711,6 +1711,7 @@ PICO_INTERNAL void PicoMemSetupCD(void) #ifdef EMU_M68K m68k_mem_setup_cd(); #endif + z80_mem_setup(); // m68k_poll_addr = m68k_poll_cnt = 0; s68k_poll_adclk = s68k_poll_cnt = 0; diff --git a/pico/memory.c b/pico/memory.c index e8b65e48..819ead8e 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -514,7 +514,6 @@ PICO_INTERNAL void PicoMemResetHooks(void) PicoWrite16Hook = OtherWrite16End; } -static void z80_mem_setup(void); #ifdef EMU_M68K static void m68k_mem_setup(void); #endif @@ -1066,7 +1065,7 @@ static void z80_md_out(unsigned short p, unsigned char d) elprintf(EL_ANOMALY, "Z80 port %04x write %02x", p, d); } -static void z80_mem_setup(void) +void z80_mem_setup(void) { z80_map_set(z80_read_map, 0x0000, 0x1fff, Pico.zram, 0); z80_map_set(z80_read_map, 0x2000, 0x3fff, Pico.zram, 0); diff --git a/pico/pico_int.h b/pico/pico_int.h index 1339c264..d3b64a82 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -427,6 +427,7 @@ PICO_INTERNAL_ASM void PicoMemReset(void); PICO_INTERNAL void PicoMemResetHooks(void); PICO_INTERNAL int PadRead(int i); PICO_INTERNAL int ym2612_write_local(unsigned int a, unsigned int d, int is_from_z80); +void z80_mem_setup(void); extern unsigned int (*PicoRead16Hook)(unsigned int a, int realsize); extern void (*PicoWrite8Hook) (unsigned int a,unsigned int d,int realsize); extern void (*PicoWrite16Hook)(unsigned int a,unsigned int d,int realsize); diff --git a/pico/z80if.c b/pico/z80if.c index dd65e1ad..815e0030 100644 --- a/pico/z80if.c +++ b/pico/z80if.c @@ -118,6 +118,7 @@ PICO_INTERNAL void z80_reset(void) drZ80.Z80IM = 0; // 1? drZ80.z80irqvector = 0xff0000; // RST 38h drZ80.Z80PC_BASE = drZ80.Z80PC = z80_read_map[0] << 1; + // drZ80 is locked in single bank drZ80.Z80SP_BASE = z80_read_map[0] << 1; // drZ80.Z80SP = drZ80.z80_rebaseSP(0x2000); // 0xf000 ? #endif