X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fz80if.c;h=da2043e4536835dc7f933d21a09d0817878c3cf7;hb=93f9619ed819dee07948416c98ca2f1c70a22666;hp=cb0fa9b11b9f7317022082c64b72ad1367c30446;hpb=cff531af94bd9c9c89ae162e80f48ddc26a4e504;p=picodrive.git diff --git a/pico/z80if.c b/pico/z80if.c index cb0fa9b..da2043e 100644 --- a/pico/z80if.c +++ b/pico/z80if.c @@ -14,9 +14,11 @@ uptr z80_read_map [0x10000 >> Z80_MEM_SHIFT]; uptr z80_write_map[0x10000 >> Z80_MEM_SHIFT]; #ifdef _USE_DRZ80 -struct DrZ80 drZ80; +// this causes trouble in some cases, like doukutsu putting sp in bank area +// no perf difference for most, upto 1-2% for some others +//#define FAST_Z80SP -static u32 drz80_sp_base; +struct DrZ80 drZ80; static void drz80_load_pcsp(u32 pc, u32 sp) { @@ -28,6 +30,8 @@ static void drz80_load_pcsp(u32 pc, u32 sp) drZ80.Z80PC_BASE <<= 1; drZ80.Z80PC = drZ80.Z80PC_BASE + pc; } + drZ80.Z80SP = sp; +#ifdef FAST_Z80SP drZ80.Z80SP_BASE = z80_read_map[sp >> Z80_MEM_SHIFT]; if (drZ80.Z80SP_BASE & (1<<31)) { elprintf(EL_STATUS|EL_ANOMALY, "load_pcsp: bad SP: %04x", sp); @@ -37,6 +41,7 @@ static void drz80_load_pcsp(u32 pc, u32 sp) drZ80.Z80SP_BASE <<= 1; drZ80.Z80SP = drZ80.Z80SP_BASE + sp; } +#endif } // called only if internal xmap rebase fails @@ -47,13 +52,19 @@ static unsigned int dz80_rebase_pc(unsigned short pc) return drZ80.Z80PC_BASE; } +#ifdef FAST_Z80SP +static u32 drz80_sp_base; + static unsigned int dz80_rebase_sp(unsigned short sp) { elprintf(EL_STATUS|EL_ANOMALY, "dz80_rebase_sp: fail on %04x", sp); drZ80.Z80SP_BASE = z80_read_map[drz80_sp_base >> Z80_MEM_SHIFT] << 1; return drZ80.Z80SP_BASE + (1 << Z80_MEM_SHIFT) - 0x100; } +#else +#define dz80_rebase_sp NULL #endif +#endif // _USE_DRZ80 void z80_init(void) @@ -91,44 +102,23 @@ void z80_reset(void) drZ80.Z80IX = 0xFFFF << 16; drZ80.Z80IY = 0xFFFF << 16; */ +#ifdef FAST_Z80SP // drZ80 is locked in single bank - drz80_sp_base = (PicoAHW & PAHW_SMS) ? 0xc000 : 0x0000; + drz80_sp_base = (PicoIn.AHW & PAHW_SMS) ? 0xc000 : 0x0000; drZ80.Z80SP_BASE = z80_read_map[drz80_sp_base >> Z80_MEM_SHIFT] << 1; - if (PicoAHW & PAHW_SMS) +#endif + if (PicoIn.AHW & PAHW_SMS) drZ80.Z80SP = drZ80.Z80SP_BASE + 0xdff0; // simulate BIOS // XXX: since we use direct SP pointer, it might make sense to force it to RAM, // but we'll rely on built-in stack protection for now #endif #ifdef _USE_CZ80 Cz80_Reset(&CZ80); - if (PicoAHW & PAHW_SMS) + if (PicoIn.AHW & PAHW_SMS) Cz80_Set_Reg(&CZ80, CZ80_SP, 0xdff0); #endif } -/* save state stuff */ -static int z80_unpack_legacy(const void *data) -{ -#if defined(_USE_DRZ80) - if (*(int *)data == 0x015A7244) { // "DrZ" v1 save? - u32 pc, sp; - memcpy(&drZ80, data+4, 0x54); - pc = (drZ80.Z80PC - drZ80.Z80PC_BASE) & 0xffff; - sp = (drZ80.Z80SP - drZ80.Z80SP_BASE) & 0xffff; - // update bases - drz80_load_pcsp(pc, sp); - return 0; - } -#elif defined(_USE_CZ80) - if (*(int *)data == 0x00007a43) { // "Cz" save? - memcpy(&CZ80, data+8, offsetof(cz80_struc, BasePC)); - Cz80_Set_Reg(&CZ80, CZ80_PC, *(int *)(data+4)); - return 0; - } -#endif - return -1; -} - struct z80sr_main { u8 a, f; u8 b, c; @@ -164,11 +154,11 @@ void z80_pack(void *data) #define DRR16(n) (drZ80.Z80##n >> 16) #define DRR16H(n) (drZ80.Z80##n >> 24) #define DRR16L(n) ((drZ80.Z80##n >> 16) & 0xff) - s->m.a = DRR8(A); s->m.f = DRR8(F); + s->m.a = DRR8(A); s->m.f = drZ80.Z80F; s->m.b = DRR16H(BC); s->m.c = DRR16L(BC); s->m.d = DRR16H(DE); s->m.e = DRR16L(DE); s->m.h = DRR16H(HL); s->m.l = DRR16L(HL); - s->a.a = DRR8(A2); s->a.f = DRR8(F2); + s->a.a = DRR8(A2); s->a.f = drZ80.Z80F2; s->a.b = DRR16H(BC2); s->a.c = DRR16L(BC2); s->a.d = DRR16H(DE2); s->a.e = DRR16L(DE2); s->a.h = DRR16H(HL2); s->a.l = DRR16L(HL2); @@ -213,9 +203,7 @@ int z80_unpack(const void *data) { const struct z80_state *s = data; if (strcmp(s->magic, "Z80") != 0) { - if (z80_unpack_legacy(data) != 0) - goto fail; - elprintf(EL_STATUS, "legacy z80 state"); + elprintf(EL_STATUS, "legacy z80 state - ignored"); return 0; } @@ -223,11 +211,11 @@ int z80_unpack(const void *data) #define DRW8(n, v) drZ80.Z80##n = (u32)(v) << 24 #define DRW16(n, v) drZ80.Z80##n = (u32)(v) << 16 #define DRW16HL(n, h, l) drZ80.Z80##n = ((u32)(h) << 24) | ((u32)(l) << 16) - DRW8(A, s->m.a); DRW8(F, s->m.f); + DRW8(A, s->m.a); drZ80.Z80F = s->m.f; DRW16HL(BC, s->m.b, s->m.c); DRW16HL(DE, s->m.d, s->m.e); DRW16HL(HL, s->m.h, s->m.l); - DRW8(A2, s->a.a); DRW8(F2, s->a.f); + DRW8(A2, s->a.a); drZ80.Z80F2 = s->a.f; DRW16HL(BC2, s->a.b, s->a.c); DRW16HL(DE2, s->a.d, s->a.e); DRW16HL(HL2, s->a.h, s->a.l); @@ -265,13 +253,9 @@ int z80_unpack(const void *data) Cz80_Set_Reg(&CZ80, CZ80_IRQ, s->irq_pending ? HOLD_LINE : CLEAR_LINE); return 0; } +#else + return 0; #endif - -fail: - elprintf(EL_STATUS|EL_ANOMALY, "z80_unpack failed"); - z80_reset(); - z80_int(); - return -1; } void z80_exit(void) @@ -286,3 +270,5 @@ void z80_debug(char *dstr) sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", (unsigned int)(CZ80.PC - CZ80.BasePC), CZ80.SP.W); #endif } + +// vim:ts=2:sw=2:expandtab