.global DrZ80Run\r
.global DrZ80Ver\r
\r
- .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 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
+.endif\r
\r
.if INTERRUPT_MODE\r
.extern Interrupt\r
.endif\r
\r
-.if DRZ80_FOR_PICODRIVE\r
- .extern PicoRead8\r
- .extern Pico\r
- .extern z80_write\r
- .extern ym2612_read_local_z80\r
-.endif\r
-\r
DrZ80Ver: .long 0x0001\r
\r
;@ --------------------------- Defines ----------------------------\r
;@ Make sure that regs/pointers for z80pc to z80sp match up!\r
\r
- opcodes .req r3\r
- z80_icount .req r4\r
+ z80_icount .req r3\r
+ opcodes .req r4\r
cpucontext .req r5\r
z80pc .req r6\r
z80a .req r7\r
\r
.text\r
\r
-.if DRZ80_FOR_PICODRIVE\r
+.if DRZ80_XMAP\r
\r
-pico_z80_read8: @ addr\r
- cmp r0,#0x2000 @ Z80 RAM\r
- ldrlt r1,[cpucontext,#z80sp_base]\r
- ldrltb r0,[r1,r0]\r
- bxlt lr\r
-\r
- cmp r0,#0x8000 @ 68k bank\r
- blt 1f\r
- ldr r2,=(Pico+0x22212)\r
- ldrh r1,[r2]\r
- bic r0,r0,#0x3f8000\r
- orr r0,r0,r1,lsl #15\r
- ldr r1,[r2,#-0xe] @ ROM size\r
- cmp r0,r1\r
- ldrlt r1,[r2,#-0x12] @ ROM\r
- eorlt r0,r0,#1 @ our ROM is byteswapped\r
- ldrltb r0,[r1,r0]\r
- bxlt lr\r
- stmfd sp!,{r3,r12,lr}\r
- bl PicoRead8\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
- stmfd sp!,{r3,r12,lr}\r
+z80_xmap_read8: @ addr\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
+ ldrccb r0,[r1,r0]\r
+ bxcc lr\r
+\r
+z80_xmap_read8_handler: @ addr, func\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
- bxge lr\r
- ldr r1,[cpucontext,#z80sp_base]\r
- bic r0,r0,#0x0fe000 @ Z80 RAM (mirror)\r
- ldrb r0,[r1,r0]\r
- bx lr\r
+ stmfd sp!,{r12,lr}\r
+ mov lr,pc\r
+ bx r1\r
+ ldr z80_icount,[cpucontext,#cycles_pointer]\r
+ ldmfd sp!,{r12,pc}\r
+\r
+z80_xmap_write8: @ data, addr\r
+ ldr r2,[cpucontext,#z80_write8]\r
+ add r2,r2,r1,lsr #Z80_MEM_SHIFT-2\r
+ bic r2,r2,#3\r
+ ldr r2,[r2]\r
+ movs r2,r2,lsl #1\r
+ strccb r0,[r2,r1]\r
+ bxcc lr\r
+\r
+z80_xmap_write8_handler: @ data, addr, func\r
+ str z80_icount,[cpucontext,#cycles_pointer]\r
+ mov r3,r0\r
+ mov r0,r1\r
+ mov r1,r3\r
+ stmfd sp!,{r12,lr}\r
+ mov lr,pc\r
+ bx r2\r
+ ldr z80_icount,[cpucontext,#cycles_pointer]\r
+ ldmfd sp!,{r12,pc}\r
+\r
+z80_xmap_read16: @ addr\r
+ @ check if we cross bank boundary\r
+ add r1,r0,#1\r
+ eor r1,r0,r0\r
+ tst r1,#1<<Z80_MEM_SHIFT\r
+ bne 0f\r
\r
-pico_z80_read16: @ addr\r
- cmp r0,#0x2000 @ Z80 RAM\r
- bge 2f\r
- ldr r1,[cpucontext,#z80sp_base]\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
+ bcs 0f\r
ldrb r0,[r1,r0]!\r
ldrb r1,[r1,#1]\r
orr r0,r0,r1,lsl #8\r
bx lr\r
\r
-2:\r
- cmp r0,#0x8000 @ 68k bank\r
- blt 1f\r
- ldr r2,=(Pico+0x22212)\r
- ldrh r1,[r2]\r
- bic r0,r0,#0x1f8000\r
- orr r0,r0,r1,lsl #15\r
- ldr r1,[r2,#-0xe] @ ROM size\r
- cmp r0,r1\r
- ldr r1,[r2,#-0x12] @ ROM\r
- tst r0,#1\r
- eor r0,r0,#1\r
- ldrb r0,[r1,r0]!\r
- ldreqb r1,[r1,#-1]\r
- ldrneb r1,[r1,#3] @ this is due to byteswapped ROM\r
- orr r0,r0,r1,lsl #8\r
- bx lr\r
-3:\r
- stmfd sp!,{r3-r5,r12,lr}\r
+0:\r
+ @ z80_xmap_read8 will save r3 and r12 for us\r
+ stmfd sp!,{r4,r5,lr}\r
mov r4,r0\r
- bl PicoRead8\r
+ bl z80_xmap_read8\r
mov r5,r0\r
add r0,r4,#1\r
- bl PicoRead8\r
+ bl z80_xmap_read8\r
orr r0,r5,r0,lsl #8\r
- ldmfd sp!,{r3-r5,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
- 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
- bxge lr\r
- ldr r1,[cpucontext,#z80sp_base]\r
- bic r0,r0,#0x0fe000 @ Z80 RAM (mirror)\r
- ldrb r0,[r1,r0]!\r
- ldrb r1,[r1,#1]\r
- orr r0,r0,r1,lsl #8\r
- bx lr\r
+ ldmfd sp!,{r4,r5,pc}\r
\r
-pico_z80_write8: @ data, addr\r
- cmp r1,#0x4000\r
- bge 1f\r
- ldr r2,[cpucontext,#z80sp_base]\r
- bic r1,r1,#0x0fe000 @ Z80 RAM\r
- strb r0,[r2,r1]\r
- 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
+z80_xmap_write16: @ data, addr\r
+ add r2,r1,#1\r
+ eor r2,r1,r1\r
+ tst r2,#1<<Z80_MEM_SHIFT\r
+ bne 0f\r
\r
-pico_z80_write16: @ data, addr\r
- cmp r1,#0x4000\r
- bge 1f\r
- ldr r2,[cpucontext,#z80sp_base]\r
- bic r1,r1,#0x0fe000 @ Z80 RAM\r
+ ldr r2,[cpucontext,#z80_read8]\r
+ add r2,r2,r1,lsr #Z80_MEM_SHIFT-2\r
+ bic r2,r2,#3\r
+ ldr r2,[r2]\r
+ movs r2,r2,lsl #1\r
+ bcs 0f\r
strb r0,[r2,r1]!\r
mov r0,r0,lsr #8\r
strb r0,[r2,#1]\r
bx lr\r
-1:\r
- stmfd sp!,{r3-r5,r12,lr}\r
- str z80_icount,[cpucontext,#cycles_pointer]\r
+\r
+0:\r
+ stmfd sp!,{r4,r5,lr}\r
mov r4,r0\r
mov r5,r1\r
- bl z80_write\r
+ bl z80_xmap_write8\r
mov r0,r4,lsr #8\r
add r1,r5,#1\r
- bl z80_write\r
- ldmfd sp!,{r3-r5,r12,pc}\r
-\r
- .pool\r
+ bl z80_xmap_write8\r
+ ldmfd sp!,{r4,r5,pc}\r
.endif\r
\r
+\r
.macro fetch cycs\r
subs z80_icount,z80_icount,#\cycs\r
.if UPDATE_CONTEXT\r
.if UPDATE_CONTEXT\r
str z80pc,[cpucontext,#z80pc_pointer]\r
.endif\r
-.if DRZ80_FOR_PICODRIVE\r
- bl pico_z80_read8\r
+.if DRZ80_XMAP\r
+.if !DRZ80_XMAP_MORE_INLINE\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
+ ldrccb r0,[r1,r0]\r
+ blcs z80_xmap_read8_handler\r
.else\r
+ bl z80_xmap_read8\r
+.endif\r
+.else ;@ if !DRZ80_XMAP\r
stmfd sp!,{r3,r12}\r
mov lr,pc\r
ldr pc,[cpucontext,#z80_read8] ;@ r0 = addr - data returned in r0\r
.if UPDATE_CONTEXT\r
str z80pc,[cpucontext,#z80pc_pointer]\r
.endif\r
-.if DRZ80_FOR_PICODRIVE\r
- bl pico_z80_read16\r
+.if DRZ80_XMAP\r
+ bl z80_xmap_read16\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
- bl pico_z80_write8\r
+.if DRZ80_XMAP\r
+.if DRZ80_XMAP_MORE_INLINE\r
+ ldr r2,[cpucontext,#z80_write8]\r
+ mov lr,r1,lsr #Z80_MEM_SHIFT\r
+ ldr r2,[r2,lr,lsl #2]\r
+ movs r2,r2,lsl #1\r
+ strccb r0,[r2,r1]\r
+ blcs z80_xmap_write8_handler\r
.else\r
+ bl z80_xmap_write8\r
+.endif\r
+.else ;@ if !DRZ80_XMAP\r
stmfd sp!,{r3,r12}\r
mov lr,pc\r
ldr pc,[cpucontext,#z80_write8] ;@ r0=data r1=addr\r
.if UPDATE_CONTEXT\r
str z80pc,[cpucontext,#z80pc_pointer]\r
.endif\r
-.if DRZ80_FOR_PICODRIVE\r
- bl pico_z80_write16\r
+.if DRZ80_XMAP\r
+ bl z80_xmap_write16\r
.else\r
stmfd sp!,{r3,r12}\r
mov lr,pc\r
str z80pc,[cpucontext,#z80pc_pointer]\r
.endif\r
mov r0,z80hl, lsr #16\r
-.if DRZ80_FOR_PICODRIVE\r
- bl pico_z80_read8\r
+.if DRZ80_XMAP\r
+ bl z80_xmap_read8\r
.else\r
stmfd sp!,{r3,r12}\r
mov lr,pc\r
ldr pc,[cpucontext,#z80_read8] ;@ r0 = addr - data returned in r0\r
-.endif\r
-.if UPDATE_CONTEXT\r
- str z80pc,[cpucontext,#z80pc_pointer]\r
.endif\r
mov r1,z80de, lsr #16\r
-.if DRZ80_FOR_PICODRIVE\r
- bl pico_z80_write8\r
+.if DRZ80_XMAP\r
+ bl z80_xmap_write8\r
.else\r
mov lr,pc\r
ldr pc,[cpucontext,#z80_write8] ;@ r0=data r1=addr\r
;@---------------------------------------\r
\r
.macro opRESmemHL bit\r
-.if DRZ80_FOR_PICODRIVE\r
mov r0,z80hl, lsr #16\r
- bl pico_z80_read8\r
+.if DRZ80_XMAP\r
+ bl z80_xmap_read8\r
bic r0,r0,#1<<\bit\r
mov r1,z80hl, lsr #16\r
- bl pico_z80_write8\r
+ bl z80_xmap_write8\r
.else\r
- mov r0,z80hl, lsr #16\r
stmfd sp!,{r3,r12}\r
mov lr,pc\r
ldr pc,[cpucontext,#z80_read8] ;@ r0 = addr - data returned in r0\r
;@---------------------------------------\r
\r
.macro opRESmem bit\r
-.if DRZ80_FOR_PICODRIVE\r
+.if DRZ80_XMAP\r
stmfd sp!,{r0} ;@ save addr as well\r
- bl pico_z80_read8\r
+ bl z80_xmap_read8\r
bic r0,r0,#1<<\bit\r
ldmfd sp!,{r1} ;@ restore addr into r1\r
- bl pico_z80_write8\r
+ bl z80_xmap_write8\r
.else\r
stmfd sp!,{r3,r12}\r
stmfd sp!,{r0} ;@ save addr as well\r
;@---------------------------------------\r
\r
.macro opSETmemHL bit\r
-.if DRZ80_FOR_PICODRIVE\r
mov r0,z80hl, lsr #16\r
- bl pico_z80_read8\r
+.if DRZ80_XMAP\r
+ bl z80_xmap_read8\r
orr r0,r0,#1<<\bit\r
mov r1,z80hl, lsr #16\r
- bl pico_z80_write8\r
+ bl z80_xmap_write8\r
.else\r
- mov r0,z80hl, lsr #16\r
stmfd sp!,{r3,r12}\r
mov lr,pc\r
ldr pc,[cpucontext,#z80_read8] ;@ r0 = addr - data returned in r0\r
;@---------------------------------------\r
\r
.macro opSETmem bit\r
-.if DRZ80_FOR_PICODRIVE\r
+.if DRZ80_XMAP\r
stmfd sp!,{r0} ;@ save addr as well\r
- bl pico_z80_read8\r
+ bl z80_xmap_read8\r
orr r0,r0,#1<<\bit\r
ldmfd sp!,{r1} ;@ restore addr into r1\r
- bl pico_z80_write8\r
+ bl z80_xmap_write8\r
.else\r
stmfd sp!,{r3,r12}\r
stmfd sp!,{r0} ;@ save addr as well\r
orr r0,r0,r1,lsr#16\r
\r
;@ read new pc from vector address\r
-.if DRZ80_FOR_PICODRIVE\r
- bl pico_z80_read16\r
- bic r0,r0,#0xfe000\r
- ldr r1,[cpucontext,#z80pc_base]\r
- add z80pc,r1,r0\r
.if UPDATE_CONTEXT\r
str z80pc,[cpucontext,#z80pc_pointer]\r
.endif\r
+.if DRZ80_XMAP\r
+ bl z80_xmap_read16\r
+ rebasepc\r
.else\r
stmfd sp!,{r3,r12}\r
mov lr,pc\r
ldr pc,[cpucontext,#z80_read16]\r
\r
;@ rebase new pc\r
-.if UPDATE_CONTEXT\r
- str z80pc,[cpucontext,#z80pc_pointer]\r
-.endif\r
mov lr,pc\r
ldr pc,[cpucontext,#z80_rebasePC] ;@ r0=new pc - external function sets z80pc_base and returns new z80pc in r0\r
ldmfd sp!,{r3,r12}\r
#endif
#ifdef _USE_DRZ80
-
struct DrZ80 drZ80;
-
-static unsigned int DrZ80_rebasePC(unsigned short a)
-{
- drZ80.Z80PC_BASE = (unsigned int) Pico.zram;
- return drZ80.Z80PC_BASE + a;
-}
-
-static unsigned int DrZ80_rebaseSP(unsigned short a)
-{
- drZ80.Z80SP_BASE = (unsigned int) Pico.zram;
- return drZ80.Z80SP_BASE + a;
-}
#endif
#endif
#ifdef _USE_DRZ80
memset(&drZ80, 0, sizeof(drZ80));
- drZ80.z80_rebasePC=DrZ80_rebasePC;
- drZ80.z80_rebaseSP=DrZ80_rebaseSP;
+ drZ80.z80_rebasePC=NULL; // unused, handled by xmap
+ drZ80.z80_rebaseSP=NULL;
drZ80.z80_read8 =(void *)z80_read_map;
drZ80.z80_read16 =NULL;
drZ80.z80_write8 =(void *)z80_write_map;
drZ80.Z80IY = 0xFFFF << 16;
drZ80.Z80IM = 0; // 1?
drZ80.z80irqvector = 0xff0000; // RST 38h
- drZ80.Z80PC = drZ80.z80_rebasePC(0);
- drZ80.Z80SP = drZ80.z80_rebaseSP(0x2000); // 0xf000 ?
+ drZ80.Z80PC_BASE = drZ80.Z80PC = z80_read_map[0] << 1;
+ drZ80.Z80SP_BASE = z80_read_map[0] << 1;
+// drZ80.Z80SP = drZ80.z80_rebaseSP(0x2000); // 0xf000 ?
#endif
#ifdef _USE_CZ80
Cz80_Reset(&CZ80);
Pico.m.z80_fakeval = 0; // for faking when Z80 is disabled
}
+// XXX TODO: should better use universal z80 save format
PICO_INTERNAL void z80_pack(unsigned char *data)
{
#if defined(_USE_MZ80)
memcpy(data+4, &mz80.z80clockticks, sizeof(mz80)-5*4); // don't save base&memhandlers
#elif defined(_USE_DRZ80)
*(int *)data = 0x015A7244; // "DrZ" v1
- drZ80.Z80PC = drZ80.z80_rebasePC(drZ80.Z80PC-drZ80.Z80PC_BASE);
- drZ80.Z80SP = drZ80.z80_rebaseSP(drZ80.Z80SP-drZ80.Z80SP_BASE);
+// drZ80.Z80PC = drZ80.z80_rebasePC(drZ80.Z80PC-drZ80.Z80PC_BASE);
+// drZ80.Z80SP = drZ80.z80_rebaseSP(drZ80.Z80SP-drZ80.Z80SP_BASE);
memcpy(data+4, &drZ80, 0x54);
#elif defined(_USE_CZ80)
*(int *)data = 0x00007a43; // "Cz"
}
#elif defined(_USE_DRZ80)
if (*(int *)data == 0x015A7244) { // "DrZ" v1 save?
+ int pc, sp;
memcpy(&drZ80, data+4, 0x54);
+ pc = (drZ80.Z80PC - drZ80.Z80PC_BASE) & 0xffff;
+ sp = (drZ80.Z80SP - drZ80.Z80SP_BASE) & 0xffff;
// update bases
- drZ80.Z80PC = drZ80.z80_rebasePC(drZ80.Z80PC-drZ80.Z80PC_BASE);
- drZ80.Z80SP = drZ80.z80_rebaseSP(drZ80.Z80SP-drZ80.Z80SP_BASE);
+ drZ80.Z80PC_BASE = z80_read_map[pc >> 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;