X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fcd%2Fmemory.c;h=b15e9c8a04e323539849e04679380ce28b09311e;hb=e71fae1f13fa9cb16b435c18edb5e1505b18e592;hp=f8ffaeb0de76fbd70a3e1a4570fe713aab4edd38;hpb=ba6e8bfd4b707aab042e47bc3e2a14f70be01075;p=picodrive.git diff --git a/pico/cd/memory.c b/pico/cd/memory.c index f8ffaeb..b15e9c8 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -65,39 +65,41 @@ void PicoWriteS68k16_dec_m1b1(u32 a, u32 d); void PicoWriteS68k16_dec_m2b1(u32 a, u32 d); #endif -static void remap_prg_window(int r3); -static void remap_word_ram(int r3); +static void remap_prg_window(u32 r1, u32 r3); +static void remap_word_ram(u32 r3); // poller detection #define POLL_LIMIT 16 -#define POLL_CYCLES 124 +#define POLL_CYCLES 64 -u32 m68k_comm_check(u32 a, u32 d) +void m68k_comm_check(u32 a) { pcd_sync_s68k(SekCyclesDone(), 0); if (a != Pico_mcd->m.m68k_poll_a) { Pico_mcd->m.m68k_poll_a = a; Pico_mcd->m.m68k_poll_cnt = 0; - return d; + return; } Pico_mcd->m.m68k_poll_cnt++; - return d; } #ifndef _ASM_CD_MEMORY_C static u32 m68k_reg_read16(u32 a) { - u32 d=0; + u32 d = 0; a &= 0x3e; switch (a) { case 0: - d = ((Pico_mcd->s68k_regs[0x33]<<13)&0x8000) | Pico_mcd->m.busreq; // here IFL2 is always 0, just like in Gens + // here IFL2 is always 0, just like in Gens + d = ((Pico_mcd->s68k_regs[0x33] << 13) & 0x8000) + | Pico_mcd->m.busreq; goto end; case 2: + m68k_comm_check(a); d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0xc7); elprintf(EL_CDREG3, "m68k_regs r3: %02x @%06x", (u8)d, SekPc); - goto end_comm; + goto end; case 4: d = Pico_mcd->s68k_regs[4]<<8; goto end; @@ -121,17 +123,15 @@ static u32 m68k_reg_read16(u32 a) if (a < 0x30) { // comm flag/cmd/status (0xE-0x2F) + m68k_comm_check(a); d = (Pico_mcd->s68k_regs[a]<<8) | Pico_mcd->s68k_regs[a+1]; - goto end_comm; + goto end; } elprintf(EL_UIO, "m68k_regs FIXME invalid read @ %02x", a); end: return d; - -end_comm: - return m68k_comm_check(a, d); } #endif @@ -143,9 +143,6 @@ void m68k_reg_write8(u32 a, u32 d) u32 dold; a &= 0x3f; - Pico_mcd->m.m68k_poll_a = - Pico_mcd->m.m68k_poll_cnt = 0; - switch (a) { case 0: d &= 1; @@ -157,23 +154,26 @@ void m68k_reg_write8(u32 a, u32 d) return; case 1: d &= 3; - elprintf(EL_CDREGS, "d m.busreq %u %u", d, Pico_mcd->m.busreq); - if (d == Pico_mcd->m.busreq) + dold = Pico_mcd->m.busreq; + if (!(d & 1)) + d |= 2; // verified: can't release bus on reset + if (dold == d) return; + pcd_sync_s68k(SekCyclesDone(), 0); - if ((Pico_mcd->m.busreq ^ d) & 1) { + if ((dold ^ d) & 1) elprintf(EL_INTSW, "m68k: s68k reset %i", !(d&1)); - if (!(d & 1)) - d |= 2; // verified: reset also gives bus - else { - elprintf(EL_CDREGS, "m68k: resetting s68k"); - SekResetS68k(); - } + if (!(d & 1)) + Pico_mcd->m.state_flags |= PCD_ST_S68K_RST; + else if (d == 1 && (Pico_mcd->m.state_flags & PCD_ST_S68K_RST)) { + Pico_mcd->m.state_flags &= ~PCD_ST_S68K_RST; + elprintf(EL_CDREGS, "m68k: resetting s68k"); + SekResetS68k(); } - if ((Pico_mcd->m.busreq ^ d) & 2) { + if ((dold ^ d) & 2) { elprintf(EL_INTSW, "m68k: s68k brq %i", d >> 1); - remap_prg_window(Pico_mcd->s68k_regs[3]); + remap_prg_window(d, Pico_mcd->s68k_regs[3]); } Pico_mcd->m.busreq = d; return; @@ -187,7 +187,7 @@ void m68k_reg_write8(u32 a, u32 d) if ((d ^ dold) & 0xc0) { elprintf(EL_CDREGS, "m68k: prg bank: %i -> %i", (Pico_mcd->s68k_regs[a]>>6), ((d>>6)&3)); - remap_prg_window(d); + remap_prg_window(Pico_mcd->m.busreq, d); } // 2M mode state is tracked regardless of current mode @@ -212,7 +212,6 @@ void m68k_reg_write8(u32 a, u32 d) ((u16 *)Pico_mcd->bios)[0x70/2], ((u16 *)Pico_mcd->bios)[0x72/2]); return; case 0x0f: - d = (d << 1) | ((d >> 7) & 1); // rol8 1 (special case) a = 0x0e; case 0x0e: goto write_comm; @@ -228,18 +227,17 @@ write_comm: if (d == Pico_mcd->s68k_regs[a]) return; - Pico_mcd->s68k_regs[a] = d; pcd_sync_s68k(SekCyclesDone(), 0); - if (Pico_mcd->m.s68k_poll_a == a && Pico_mcd->m.s68k_poll_cnt > POLL_LIMIT) { + Pico_mcd->s68k_regs[a] = d; + if (Pico_mcd->m.s68k_poll_a == (a & ~1) + && Pico_mcd->m.s68k_poll_cnt > POLL_LIMIT) + { SekSetStopS68k(0); Pico_mcd->m.s68k_poll_a = 0; elprintf(EL_CDPOLL, "s68k poll release, a=%02x", a); } } -#ifndef _ASM_CD_MEMORY_C -static -#endif u32 s68k_poll_detect(u32 a, u32 d) { #ifdef USE_POLL_DETECT @@ -255,7 +253,7 @@ u32 s68k_poll_detect(u32 a, u32 d) //printf("-- diff: %u, cnt = %i\n", clkdiff, cnt); if (Pico_mcd->m.s68k_poll_cnt > POLL_LIMIT) { SekSetStopS68k(1); - elprintf(EL_CDPOLL, "s68k poll detected @ %06x, a=%02x", + elprintf(EL_CDPOLL, "s68k poll detected @%06x, a=%02x", SekPcS68k, a); } } @@ -394,8 +392,6 @@ void s68k_reg_write8(u32 a, u32 d) Pico_mcd->m.stopwatch_base_c = SekCyclesDoneS68k(); return; case 0x0e: - d &= 0xff; - d = (d>>1) | (d<<7); // ror8 1, Gens note: Dragons lair a = 0x0f; case 0x0f: goto write_comm; @@ -555,12 +551,14 @@ static void PicoWriteM68k8_ramc(u32 a, u32 d) return; } - elprintf(EL_UIO, "m68k unmapped w8 [%06x] %02x @%06x", a, d & 0xff, SekPc); + elprintf(EL_UIO, "m68k unmapped w8 [%06x] %02x @%06x", + a, d & 0xff, SekPc); } static void PicoWriteM68k16_ramc(u32 a, u32 d) { - elprintf(EL_ANOMALY, "ramcart w16: [%06x] %04x @%06x", a, d, SekPcS68k); + elprintf(EL_ANOMALY, "ramcart w16: [%06x] %04x @%06x", + a, d, SekPcS68k); PicoWriteM68k8_ramc(a + 1, d); } @@ -574,7 +572,8 @@ static u32 PicoReadM68k8_io(u32 a) if (!(a & 1)) d >>= 8; d &= 0xff; - elprintf(EL_CDREGS, "m68k_regs r8: [%02x] %02x @%06x", a & 0x3f, d, SekPc); + elprintf(EL_CDREGS, "m68k_regs r8: [%02x] %02x @%06x", + a & 0x3f, d, SekPc); return d; } @@ -587,7 +586,8 @@ static u32 PicoReadM68k16_io(u32 a) u32 d; if ((a & 0xff00) == 0x2000) { d = m68k_reg_read16(a); - elprintf(EL_CDREGS, "m68k_regs r16: [%02x] %04x @%06x", a & 0x3f, d, SekPc); + elprintf(EL_CDREGS, "m68k_regs r16: [%02x] %04x @%06x", + a & 0x3f, d, SekPc); return d; } @@ -597,7 +597,8 @@ static u32 PicoReadM68k16_io(u32 a) static void PicoWriteM68k8_io(u32 a, u32 d) { if ((a & 0xff00) == 0x2000) { // a12000 - a120ff - elprintf(EL_CDREGS, "m68k_regs w8: [%02x] %02x @%06x", a&0x3f, d, SekPc); + elprintf(EL_CDREGS, "m68k_regs w8: [%02x] %02x @%06x", + a & 0x3f, d, SekPc); m68k_reg_write8(a, d); return; } @@ -608,7 +609,8 @@ static void PicoWriteM68k8_io(u32 a, u32 d) static void PicoWriteM68k16_io(u32 a, u32 d) { if ((a & 0xff00) == 0x2000) { // a12000 - a120ff - elprintf(EL_CDREGS, "m68k_regs w16: [%02x] %04x @%06x", a&0x3f, d, SekPc); + elprintf(EL_CDREGS, "m68k_regs w16: [%02x] %04x @%06x", + a & 0x3f, d, SekPc); m68k_reg_write8(a, d >> 8); if ((a & 0x3e) != 0x0e) // special case @@ -638,25 +640,27 @@ static u32 s68k_unmapped_read16(u32 a) static void s68k_unmapped_write8(u32 a, u32 d) { - elprintf(EL_UIO, "s68k unmapped w8 [%06x] %02x @%06x", a, d & 0xff, SekPc); + elprintf(EL_UIO, "s68k unmapped w8 [%06x] %02x @%06x", + a, d & 0xff, SekPc); } static void s68k_unmapped_write16(u32 a, u32 d) { - elprintf(EL_UIO, "s68k unmapped w16 [%06x] %04x @%06x", a, d & 0xffff, SekPc); + elprintf(EL_UIO, "s68k unmapped w16 [%06x] %04x @%06x", + a, d & 0xffff, SekPc); } -// PRG RAM protected range (000000 - 00ff00)? +// PRG RAM protected range (000000 - 01fdff)? // XXX verify: ff00 or 1fe00 max? static void PicoWriteS68k8_prgwp(u32 a, u32 d) { - if (a >= (Pico_mcd->s68k_regs[2] << 8)) + if (a >= (Pico_mcd->s68k_regs[2] << 9)) Pico_mcd->prg_ram[a ^ 1] = d; } static void PicoWriteS68k16_prgwp(u32 a, u32 d) { - if (a >= (Pico_mcd->s68k_regs[2] << 8)) + if (a >= (Pico_mcd->s68k_regs[2] << 9)) *(u16 *)(Pico_mcd->prg_ram + a) = d; } @@ -807,7 +811,7 @@ static u32 PicoReadS68k8_pr(u32 a) a &= 0x1ff; if (a >= 0x0e && a < 0x30) { d = Pico_mcd->s68k_regs[a]; - s68k_poll_detect(a, d); + s68k_poll_detect(a & ~1, d); goto regs_done; } else if (a >= 0x58 && a < 0x68) @@ -818,7 +822,7 @@ static u32 PicoReadS68k8_pr(u32 a) regs_done: d &= 0xff; - elprintf(EL_CDREGS, "s68k_regs r8: [%02x] %02x @ %06x", + elprintf(EL_CDREGS, "s68k_regs r8: [%02x] %02x @%06x", a, d, SekPcS68k); return d; } @@ -852,7 +856,7 @@ static u32 PicoReadS68k16_pr(u32 a) d = gfx_cd_read(a); else d = s68k_reg_read16(a); - elprintf(EL_CDREGS, "s68k_regs r16: [%02x] %04x @ %06x", + elprintf(EL_CDREGS, "s68k_regs r16: [%02x] %04x @%06x", a, d, SekPcS68k); return d; } @@ -880,7 +884,7 @@ static void PicoWriteS68k8_pr(u32 a, u32 d) // regs if ((a & 0xfe00) == 0x8000) { a &= 0x1ff; - elprintf(EL_CDREGS, "s68k_regs w8: [%02x] %02x @ %06x", a, d, SekPcS68k); + elprintf(EL_CDREGS, "s68k_regs w8: [%02x] %02x @%06x", a, d, SekPcS68k); if (0x58 <= a && a < 0x68) gfx_cd_write16(a&~1, (d<<8)|d); else s68k_reg_write8(a,d); @@ -905,7 +909,7 @@ static void PicoWriteS68k16_pr(u32 a, u32 d) // regs if ((a & 0xfe00) == 0x8000) { a &= 0x1fe; - elprintf(EL_CDREGS, "s68k_regs w16: [%02x] %04x @ %06x", a, d, SekPcS68k); + elprintf(EL_CDREGS, "s68k_regs w16: [%02x] %04x @%06x", a, d, SekPcS68k); if (a >= 0x58 && a < 0x68) gfx_cd_write16(a, d); else { @@ -956,11 +960,11 @@ static const void *s68k_dec_write16[2][4] = { // ----------------------------------------------------------------- -static void remap_prg_window(int r3) +static void remap_prg_window(u32 r1, u32 r3) { // PRG RAM - if (Pico_mcd->m.busreq & 2) { - void *bank = Pico_mcd->prg_ram_b[r3 >> 6]; + if (r1 & 2) { + void *bank = Pico_mcd->prg_ram_b[(r3 >> 6) & 3]; cpu68k_map_all_ram(0x020000, 0x03ffff, bank, 0); } else { @@ -968,7 +972,7 @@ static void remap_prg_window(int r3) } } -static void remap_word_ram(int r3) +static void remap_word_ram(u32 r3) { void *bank; @@ -1019,13 +1023,13 @@ static void remap_word_ram(int r3) void pcd_state_loaded_mem(void) { - int r3 = Pico_mcd->s68k_regs[3]; + u32 r3 = Pico_mcd->s68k_regs[3]; /* after load events */ if (r3 & 4) // 1M mode? wram_2M_to_1M(Pico_mcd->word_ram2M); remap_word_ram(r3); - remap_prg_window(r3); + remap_prg_window(Pico_mcd->m.busreq, r3); Pico_mcd->m.dmna_ret_2m &= 3; // restore hint vector @@ -1067,8 +1071,8 @@ PICO_INTERNAL void PicoMemSetupCD(void) cpu68k_map_set(s68k_read16_map, 0x000000, 0x07ffff, Pico_mcd->prg_ram, 0); cpu68k_map_set(s68k_write8_map, 0x000000, 0x07ffff, Pico_mcd->prg_ram, 0); cpu68k_map_set(s68k_write16_map, 0x000000, 0x07ffff, Pico_mcd->prg_ram, 0); - cpu68k_map_set(s68k_write8_map, 0x000000, 0x00ffff, PicoWriteS68k8_prgwp, 1); - cpu68k_map_set(s68k_write16_map, 0x000000, 0x00ffff, PicoWriteS68k16_prgwp, 1); + cpu68k_map_set(s68k_write8_map, 0x000000, 0x01ffff, PicoWriteS68k8_prgwp, 1); + cpu68k_map_set(s68k_write16_map, 0x000000, 0x01ffff, PicoWriteS68k16_prgwp, 1); // BRAM cpu68k_map_set(s68k_read8_map, 0xfe0000, 0xfeffff, PicoReadS68k8_bram, 1);