.equiv INTERRUPT_MODE, 0 ;@0 = Use internal int handler, 1 = Use Mames int handler\r
.equiv FAST_Z80SP, 1 ;@0 = Use mem functions for stack pointer, 1 = Use direct mem pointer\r
.equiv UPDATE_CONTEXT, 0\r
- .equiv DRZ80_FOR_PICODRIVE, 1\r
.equiv DRZ80_XMAP, 1\r
.equiv DRZ80_XMAP_MORE_INLINE, 1\r
\r
.if DRZ80_XMAP\r
.equ Z80_MEM_SHIFT, 13\r
+ ;@ note: stack is locked in single bank that z80sp_base points to\r
.endif\r
\r
.if INTERRUPT_MODE\r
\r
0:\r
@ z80_xmap_read8 will save r3 and r12 for us\r
- stmfd sp!,{r4,r5,lr}\r
- mov r4,r0\r
+ stmfd sp!,{r8,r9,lr}\r
+ mov r8,r0\r
bl z80_xmap_read8\r
- mov r5,r0\r
- add r0,r4,#1\r
+ mov r9,r0\r
+ add r0,r8,#1\r
bl z80_xmap_read8\r
- orr r0,r5,r0,lsl #8\r
- ldmfd sp!,{r4,r5,pc}\r
+ orr r0,r9,r0,lsl #8\r
+ ldmfd sp!,{r8,r9,pc}\r
\r
z80_xmap_write16: @ data, addr\r
add r2,r1,#1\r
bx lr\r
\r
0:\r
- stmfd sp!,{r4,r5,lr}\r
- mov r4,r0\r
- mov r5,r1\r
+ stmfd sp!,{r8,r9,lr}\r
+ mov r8,r0\r
+ mov r9,r1\r
bl z80_xmap_write8\r
- mov r0,r4,lsr #8\r
- add r1,r5,#1\r
+ mov r0,r8,lsr #8\r
+ add r1,r9,#1\r
bl z80_xmap_write8\r
- ldmfd sp!,{r4,r5,pc}\r
+ ldmfd sp!,{r8,r9,pc}\r
+\r
+z80_xmap_rebase_pc:\r
+ ldr r1,[cpucontext,#z80_read8]\r
+ mov r2,r0,lsr #Z80_MEM_SHIFT\r
+ ldr r1,[r1,r2,lsl #2]\r
+ movs r1,r1,lsl #1\r
+ strcc r1,[cpucontext,#z80pc_base]\r
+ addcc z80pc,r1,r0\r
+ bxcc lr\r
+\r
+z80_bad_jump:\r
+ ldr r0,[cpucontext,#z80_read8]\r
+ ldr r0,[r0]\r
+ str r0,[cpucontext,#z80pc_base]\r
+ mov z80pc,r0\r
+ bx lr\r
.endif\r
\r
\r
.if UPDATE_CONTEXT\r
str z80pc,[cpucontext,#z80pc_pointer]\r
.endif\r
-.if DRZ80_FOR_PICODRIVE\r
- ldr r1,[cpucontext,#z80pc_base]\r
- bic r0,r0,#0xfe000\r
- add z80pc,r1,r0\r
+.if DRZ80_XMAP\r
+ bl z80_xmap_rebase_pc\r
.else\r
stmfd sp!,{r3,r12}\r
mov lr,pc\r
.if UPDATE_CONTEXT\r
str z80pc,[cpucontext,#z80pc_pointer]\r
.endif\r
-.if DRZ80_FOR_PICODRIVE\r
- bic r0,r0,#0xfe000\r
+.if DRZ80_XMAP\r
+ ;@ XXX: SP is locked to single back z80sp_base points to.\r
ldr r1,[cpucontext,#z80sp_base]\r
+ bic r0,r0,#0x7f<<Z80_MEM_SHIFT\r
add r0,r1,r0\r
.else\r
stmfd sp!,{r3,r12}\r
\r
.macro opPOP\r
.if FAST_Z80SP\r
-.if DRZ80_FOR_PICODRIVE\r
- @ notaz: try to protect against stack overflows, which tend to happen in Picodrive because of poor timing\r
- ldr r2,[cpucontext,#z80sp_base]\r
- ldrb r0,[z80sp],#1\r
- add r2,r2,#0x2000\r
- cmp z80sp,r2\r
-@ subge z80sp,z80sp,#0x2000 @ unstable?\r
- ldrb r1,[z80sp],#1\r
- cmp z80sp,r2\r
-@ subge z80sp,z80sp,#0x2000\r
- orr r0,r0,r1, lsl #8\r
-.else\r
ldrb r0,[z80sp],#1\r
ldrb r1,[z80sp],#1\r
orr r0,r0,r1, lsl #8\r
-.endif\r
.else\r
mov r0,z80sp\r
readmem16\r
.endm\r
;@---------------------------------------\r
\r
+.macro stack_check\r
+ @ try to protect against stack overflows, lock into current bank\r
+ ldr r1,[cpucontext,#z80sp_base]\r
+ sub r1,z80sp,r1\r
+ cmp r1,#2\r
+ addlt z80sp,z80sp,#1<<Z80_MEM_SHIFT\r
+.endm\r
+\r
.macro opPUSHareg reg @ reg > r1\r
.if FAST_Z80SP\r
-.if DRZ80_FOR_PICODRIVE\r
- @ notaz: try to protect against stack overflows, which tend to happen in Picodrive because of poor timing\r
- ldr r0,[cpucontext,#z80sp_base]\r
- cmp z80sp,r0\r
- addle z80sp,z80sp,#0x2000\r
- mov r1,\reg, lsr #8\r
- strb r1,[z80sp,#-1]!\r
- cmp z80sp,r0\r
- addle z80sp,z80sp,#0x2000\r
- strb \reg,[z80sp,#-1]!\r
-.else\r
+.if DRZ80_XMAP\r
+ stack_check\r
+.endif\r
mov r1,\reg, lsr #8\r
strb r1,[z80sp,#-1]!\r
strb \reg,[z80sp,#-1]!\r
-.endif\r
.else\r
mov r0,\reg\r
sub z80sp,z80sp,#2\r
\r
.macro opPUSHreg reg\r
.if FAST_Z80SP\r
-.if DRZ80_FOR_PICODRIVE\r
- ldr r0,[cpucontext,#z80sp_base]\r
- cmp z80sp,r0\r
- addle z80sp,z80sp,#0x2000\r
- mov r1,\reg, lsr #24\r
- strb r1,[z80sp,#-1]!\r
- cmp z80sp,r0\r
- addle z80sp,z80sp,#0x2000\r
- mov r1,\reg, lsr #16\r
- strb r1,[z80sp,#-1]!\r
-.else\r
+.if DRZ80_XMAP\r
+ stack_check\r
+.endif\r
mov r1,\reg, lsr #24\r
strb r1,[z80sp,#-1]!\r
mov r1,\reg, lsr #16\r
strb r1,[z80sp,#-1]!\r
-.endif\r
.else\r
mov r0,\reg,lsr #16\r
sub z80sp,z80sp,#2\r
PicoWrite16Hook = OtherWrite16End;\r
}\r
\r
-static void z80_mem_setup(void);\r
#ifdef EMU_M68K\r
static void m68k_mem_setup(void);\r
#endif\r
elprintf(EL_ANOMALY, "Z80 port %04x write %02x", p, d);\r
}\r
\r
-static void z80_mem_setup(void)\r
+void z80_mem_setup(void)\r
{\r
z80_map_set(z80_read_map, 0x0000, 0x1fff, Pico.zram, 0);\r
z80_map_set(z80_read_map, 0x2000, 0x3fff, Pico.zram, 0);\r