From ee05564fc7644a035ceeedba61975e46ce84af48 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 15 Aug 2009 14:24:55 +0000 Subject: [PATCH] converting drZ80 to use xmap (new mem handling) git-svn-id: file:///home/notaz/opt/svn/PicoDrive@754 be3aeb3a-fb24-0410-a615-afba39da0efa --- cpu/DrZ80/drz80.s | 287 +++++++++++++++++++++------------------------- pico/z80if.c | 49 ++++---- 2 files changed, 156 insertions(+), 180 deletions(-) diff --git a/cpu/DrZ80/drz80.s b/cpu/DrZ80/drz80.s index 846c6362..5445ffd0 100644 --- a/cpu/DrZ80/drz80.s +++ b/cpu/DrZ80/drz80.s @@ -11,29 +11,28 @@ .global DrZ80Run .global DrZ80Ver - .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 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 +.endif .if INTERRUPT_MODE .extern Interrupt .endif -.if DRZ80_FOR_PICODRIVE - .extern PicoRead8 - .extern Pico - .extern z80_write - .extern ym2612_read_local_z80 -.endif - DrZ80Ver: .long 0x0001 ;@ --------------------------- Defines ---------------------------- ;@ Make sure that regs/pointers for z80pc to z80sp match up! - opcodes .req r3 - z80_icount .req r4 + z80_icount .req r3 + opcodes .req r4 cpucontext .req r5 z80pc .req r6 z80a .req r7 @@ -104,139 +103,101 @@ DrZ80Ver: .long 0x0001 .text -.if DRZ80_FOR_PICODRIVE +.if DRZ80_XMAP -pico_z80_read8: @ addr - cmp r0,#0x2000 @ Z80 RAM - ldrlt r1,[cpucontext,#z80sp_base] - ldrltb r0,[r1,r0] - bxlt lr - - cmp r0,#0x8000 @ 68k bank - blt 1f - ldr r2,=(Pico+0x22212) - ldrh r1,[r2] - bic r0,r0,#0x3f8000 - orr r0,r0,r1,lsl #15 - ldr r1,[r2,#-0xe] @ ROM size - cmp r0,r1 - ldrlt r1,[r2,#-0x12] @ ROM - eorlt r0,r0,#1 @ our ROM is byteswapped - ldrltb r0,[r1,r0] - bxlt lr - stmfd sp!,{r3,r12,lr} - bl PicoRead8 - ldmfd sp!,{r3,r12,pc} -1: - mov r1,r0,lsr #13 - cmp r1,#2 @ YM2612 (0x4000-0x5fff) - bne 0f - and r0,r0,#3 - stmfd sp!,{r3,r12,lr} +z80_xmap_read8: @ addr + ldr r1,[cpucontext,#z80_read8] + mov r2,r0,lsr #Z80_MEM_SHIFT + ldr r1,[r1,r2,lsl #2] + movs r1,r1,lsl #1 + ldrccb r0,[r1,r0] + bxcc lr + +z80_xmap_read8_handler: @ addr, func str z80_icount,[cpucontext,#cycles_pointer] - bl ym2612_read_local_z80 - ldmfd sp!,{r3,r12,pc} -0: - cmp r0,#0x4000 - movge r0,#0xff - bxge lr - ldr r1,[cpucontext,#z80sp_base] - bic r0,r0,#0x0fe000 @ Z80 RAM (mirror) - ldrb r0,[r1,r0] - bx lr + stmfd sp!,{r12,lr} + mov lr,pc + bx r1 + ldr z80_icount,[cpucontext,#cycles_pointer] + ldmfd sp!,{r12,pc} + +z80_xmap_write8: @ data, addr + ldr r2,[cpucontext,#z80_write8] + add r2,r2,r1,lsr #Z80_MEM_SHIFT-2 + bic r2,r2,#3 + ldr r2,[r2] + movs r2,r2,lsl #1 + strccb r0,[r2,r1] + bxcc lr + +z80_xmap_write8_handler: @ data, addr, func + str z80_icount,[cpucontext,#cycles_pointer] + mov r3,r0 + mov r0,r1 + mov r1,r3 + stmfd sp!,{r12,lr} + mov lr,pc + bx r2 + ldr z80_icount,[cpucontext,#cycles_pointer] + ldmfd sp!,{r12,pc} + +z80_xmap_read16: @ addr + @ check if we cross bank boundary + add r1,r0,#1 + eor r1,r0,r0 + tst r1,#1<> Z80_MEM_SHIFT]; + if (drZ80.Z80PC & (1<<31)) { + elprintf(EL_STATUS|EL_ANOMALY, "bad PC in z80 save: %04x", pc); + drZ80.Z80PC_BASE = drZ80.Z80PC = z80_read_map[0]; + } else { + drZ80.Z80PC_BASE <<= 1; + drZ80.Z80PC = drZ80.Z80PC_BASE + pc; + } + drZ80.Z80SP_BASE = z80_read_map[sp >> Z80_MEM_SHIFT]; + if (drZ80.Z80SP & (1<<31)) { + elprintf(EL_STATUS|EL_ANOMALY, "bad SP in z80 save: %04x", sp); + drZ80.Z80SP_BASE = z80_read_map[0]; + drZ80.Z80SP = drZ80.Z80SP_BASE + (1 << Z80_MEM_SHIFT); + } else { + drZ80.Z80SP_BASE <<= 1; + drZ80.Z80SP = drZ80.Z80SP_BASE + sp; + } } else { z80_reset(); drZ80.Z80IM = 1; -- 2.39.5