X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fcd%2Fmemory.c;h=acf29c64a978a6e9b1e5cb259c3d5fa8a4505573;hb=6901d0e45dbf77671d86cb9bf9af98c486db97c8;hp=b15e9c8a04e323539849e04679380ce28b09311e;hpb=c7fd7bb8b7bc6342026a42e5316bd275a2f815c7;p=picodrive.git diff --git a/pico/cd/memory.c b/pico/cd/memory.c index b15e9c8..acf29c6 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -9,9 +9,6 @@ #include "../pico_int.h" #include "../memory.h" -#include "gfx_cd.h" -#include "pcm.h" - uptr s68k_read8_map [0x1000000 >> M68K_MEM_SHIFT]; uptr s68k_read16_map [0x1000000 >> M68K_MEM_SHIFT]; uptr s68k_write8_map [0x1000000 >> M68K_MEM_SHIFT]; @@ -28,11 +25,6 @@ MAKE_68K_WRITE32(s68k_write32, s68k_write16_map) // provided by ASM code: #ifdef _ASM_CD_MEMORY_C -u32 PicoReadM68k8_io(u32 a); -u32 PicoReadM68k16_io(u32 a); -void PicoWriteM68k8_io(u32 a, u32 d); -void PicoWriteM68k16_io(u32 a, u32 d); - u32 PicoReadS68k8_pr(u32 a); u32 PicoReadS68k16_pr(u32 a); void PicoWriteS68k8_pr(u32 a, u32 d); @@ -75,9 +67,16 @@ static void remap_word_ram(u32 r3); void m68k_comm_check(u32 a) { pcd_sync_s68k(SekCyclesDone(), 0); - if (a != Pico_mcd->m.m68k_poll_a) { + if (a >= 0x0e && !Pico_mcd->m.need_sync) { + // there are cases when slave updates comm and only switches RAM + // over after that (mcd1b), so there must be a resync.. + SekEndRun(64); + Pico_mcd->m.need_sync = 1; + } + if (SekNotPolling || a != Pico_mcd->m.m68k_poll_a) { Pico_mcd->m.m68k_poll_a = a; Pico_mcd->m.m68k_poll_cnt = 0; + SekNotPolling = 0; return; } Pico_mcd->m.m68k_poll_cnt++; @@ -107,7 +106,7 @@ static u32 m68k_reg_read16(u32 a) d = *(u16 *)(Pico_mcd->bios + 0x72); goto end; case 8: - d = Read_CDC_Host(0); + d = cdc_host_r(); goto end; case 0xA: elprintf(EL_UIO, "m68k FIXME: reserved read"); @@ -229,12 +228,13 @@ write_comm: pcd_sync_s68k(SekCyclesDone(), 0); Pico_mcd->s68k_regs[a] = d; - if (Pico_mcd->m.s68k_poll_a == (a & ~1) - && Pico_mcd->m.s68k_poll_cnt > POLL_LIMIT) + if (Pico_mcd->m.s68k_poll_a == (a & ~1)) { - SekSetStopS68k(0); + if (Pico_mcd->m.s68k_poll_cnt > POLL_LIMIT) { + elprintf(EL_CDPOLL, "s68k poll release, a=%02x", a); + SekSetStopS68k(0); + } Pico_mcd->m.s68k_poll_a = 0; - elprintf(EL_CDPOLL, "s68k poll release, a=%02x", a); } } @@ -246,7 +246,7 @@ u32 s68k_poll_detect(u32 a, u32 d) return d; cycles = SekCyclesDoneS68k(); - if (a == Pico_mcd->m.s68k_poll_a) { + if (!SekNotPolling && a == Pico_mcd->m.s68k_poll_a) { u32 clkdiff = cycles - Pico_mcd->m.s68k_poll_clk; if (clkdiff <= POLL_CYCLES) { cnt = Pico_mcd->m.s68k_poll_cnt + 1; @@ -261,6 +261,7 @@ u32 s68k_poll_detect(u32 a, u32 d) Pico_mcd->m.s68k_poll_a = a; Pico_mcd->m.s68k_poll_clk = cycles; Pico_mcd->m.s68k_poll_cnt = cnt; + SekNotPollingS68k = 0; #endif return d; } @@ -291,9 +292,9 @@ u32 s68k_reg_read16(u32 a) elprintf(EL_CDREG3, "s68k_regs r3: %02x @%06x", (u8)d, SekPcS68k); return s68k_poll_detect(a, d); case 6: - return CDC_Read_Reg(); + return cdc_reg_r(); case 8: - return Read_CDC_Host(1); // Gens returns 0 here on byte reads + return cdc_host_r(); case 0xC: d = SekCyclesDoneS68k() - Pico_mcd->m.stopwatch_base_c; d /= 384; @@ -334,6 +335,10 @@ void s68k_reg_write8(u32 a, u32 d) { // Warning: d might have upper bits set switch (a) { + case 1: + if (!(d & 1)) + pcd_soft_reset(); + return; case 2: return; // only m68k can change WP case 3: { @@ -380,7 +385,7 @@ void s68k_reg_write8(u32 a, u32 d) //dprintf("s68k CDC reg addr: %x", d&0xf); break; case 7: - CDC_Write_Reg(d); + cdc_reg_w(d); return; case 0xa: elprintf(EL_CDREGS, "s68k set CDC dma addr"); @@ -408,8 +413,11 @@ void s68k_reg_write8(u32 a, u32 d) elprintf(EL_CDREGS|EL_CD, "s68k irq mask: %02x", d); d &= 0x7e; if ((d ^ Pico_mcd->s68k_regs[0x33]) & d & PCDS_IEN4) { - if (Pico_mcd->s68k_regs[0x37] & 4) - CDD_Export_Status(); + // XXX: emulate pending irq instead? + if (Pico_mcd->s68k_regs[0x37] & 4) { + elprintf(EL_INTS, "cdd export irq 4 (unmask)"); + SekInterruptS68k(4); + } } break; case 0x34: // fader @@ -419,15 +427,38 @@ void s68k_reg_write8(u32 a, u32 d) return; // d/m bit is unsetable case 0x37: { u32 d_old = Pico_mcd->s68k_regs[0x37]; - Pico_mcd->s68k_regs[0x37] = d&7; + Pico_mcd->s68k_regs[0x37] = d & 7; if ((d&4) && !(d_old&4)) { - CDD_Export_Status(); + // ?? + pcd_event_schedule_s68k(PCD_EVENT_CDC, 12500000/75); + + if (Pico_mcd->s68k_regs[0x33] & PCDS_IEN4) { + elprintf(EL_INTS, "cdd export irq 4"); + SekInterruptS68k(4); + } } return; } case 0x4b: - Pico_mcd->s68k_regs[a] = (u8) d; - CDD_Import_Command(); + Pico_mcd->s68k_regs[a] = 0; // (u8) d; ? + cdd_process(); + { + static const char *nm[] = + { "stat", "stop", "read_toc", "play", + "seek", "???", "pause", "resume", + "ff", "fr", "tjump", "???", + "close","open", "???", "???" }; + u8 *c = &Pico_mcd->s68k_regs[0x42]; + u8 *s = &Pico_mcd->s68k_regs[0x38]; + elprintf(EL_CD, + "CDD command: %02x %02x %02x %02x %02x %02x %02x %02x %12s", + c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], nm[c[0] & 0x0f]); + elprintf(EL_CD, + "CDD status: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", + s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9]); + } + return; + case 0x58: return; } @@ -450,6 +481,65 @@ write_comm: Pico_mcd->m.m68k_poll_cnt = 0; } +void s68k_reg_write16(u32 a, u32 d) +{ + u8 *r = Pico_mcd->s68k_regs; + + if ((a & 0x1f0) == 0x20) + goto write_comm; + + switch (a) { + case 0x0e: + // special case, 2 byte writes would be handled differently + // TODO: verify + r[0xf] = d; + return; + case 0x58: // stamp data size + r[0x59] = d & 7; + return; + case 0x5a: // stamp map base address + r[0x5a] = d >> 8; + r[0x5b] = d & 0xe0; + return; + case 0x5c: // V cell size + r[0x5d] = d & 0x1f; + return; + case 0x5e: // image buffer start address + r[0x5e] = d >> 8; + r[0x5f] = d & 0xf8; + return; + case 0x60: // image buffer offset + r[0x61] = d & 0x3f; + return; + case 0x62: // h dot size + r[0x62] = (d >> 8) & 1; + r[0x63] = d; + return; + case 0x64: // v dot size + r[0x65] = d; + return; + case 0x66: // trace vector base address + d &= 0xfffe; + r[0x66] = d >> 8; + r[0x67] = d; + gfx_start(d); + return; + default: + break; + } + + s68k_reg_write8(a, d >> 8); + s68k_reg_write8(a + 1, d & 0xff); + return; + +write_comm: + r[a] = d >> 8; + r[a + 1] = d; + if (Pico_mcd->m.m68k_poll_cnt) + SekEndRunS68k(0); + Pico_mcd->m.m68k_poll_cnt = 0; +} + // ----------------------------------------------------------------- // Main 68k // ----------------------------------------------------------------- @@ -564,7 +654,7 @@ static void PicoWriteM68k16_ramc(u32 a, u32 d) // IO/control/cd registers (a10000 - ...) #ifndef _ASM_CD_MEMORY_C -static u32 PicoReadM68k8_io(u32 a) +u32 PicoRead8_mcd_io(u32 a) { u32 d; if ((a & 0xff00) == 0x2000) { // a12000 - a120ff @@ -581,7 +671,7 @@ static u32 PicoReadM68k8_io(u32 a) return PicoRead8_io(a); } -static u32 PicoReadM68k16_io(u32 a) +u32 PicoRead16_mcd_io(u32 a) { u32 d; if ((a & 0xff00) == 0x2000) { @@ -594,7 +684,7 @@ static u32 PicoReadM68k16_io(u32 a) return PicoRead16_io(a); } -static void PicoWriteM68k8_io(u32 a, u32 d) +void PicoWrite8_mcd_io(u32 a, u32 d) { if ((a & 0xff00) == 0x2000) { // a12000 - a120ff elprintf(EL_CDREGS, "m68k_regs w8: [%02x] %02x @%06x", @@ -603,16 +693,16 @@ static void PicoWriteM68k8_io(u32 a, u32 d) return; } - PicoWrite16_io(a, d); + PicoWrite8_io(a, d); } -static void PicoWriteM68k16_io(u32 a, u32 d) +void PicoWrite16_mcd_io(u32 a, u32 d) { if ((a & 0xff00) == 0x2000) { // a12000 - a120ff elprintf(EL_CDREGS, "m68k_regs w16: [%02x] %04x @%06x", a & 0x3f, d, SekPc); - m68k_reg_write8(a, d >> 8); + m68k_reg_write8(a, d >> 8); if ((a & 0x3e) != 0x0e) // special case m68k_reg_write8(a + 1, d & 0xff); return; @@ -814,9 +904,7 @@ static u32 PicoReadS68k8_pr(u32 a) s68k_poll_detect(a & ~1, d); goto regs_done; } - else if (a >= 0x58 && a < 0x68) - d = gfx_cd_read(a & ~1); - else d = s68k_reg_read16(a & ~1); + d = s68k_reg_read16(a & ~1); if (!(a & 1)) d >>= 8; @@ -833,13 +921,10 @@ regs_done: a &= 0x7fff; if (a >= 0x2000) d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a >> 1) & 0xfff]; - else if (a >= 0x20) { - a &= 0x1e; - d = Pico_mcd->pcm.ch[a>>2].addr >> PCM_STEP_SHIFT; - if (a & 2) - d >>= 8; - } - return d & 0xff; + else if (a >= 0x20) + d = pcd_pcm_read(a >> 1); + + return d; } return s68k_unmapped_read8(a); @@ -852,9 +937,7 @@ static u32 PicoReadS68k16_pr(u32 a) // regs if ((a & 0xfe00) == 0x8000) { a &= 0x1fe; - if (0x58 <= a && a < 0x68) - d = gfx_cd_read(a); - else d = s68k_reg_read16(a); + d = s68k_reg_read16(a); elprintf(EL_CDREGS, "s68k_regs r16: [%02x] %04x @%06x", a, d, SekPcS68k); @@ -863,16 +946,12 @@ static u32 PicoReadS68k16_pr(u32 a) // PCM if ((a & 0x8000) == 0x0000) { - //elprintf(EL_ANOMALY, "FIXME: s68k_pcm r16: [%06x] @%06x", a, SekPcS68k); a &= 0x7fff; if (a >= 0x2000) - d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff]; - else if (a >= 0x20) { - a &= 0x1e; - d = Pico_mcd->pcm.ch[a>>2].addr >> PCM_STEP_SHIFT; - if (a & 2) d >>= 8; - } - elprintf(EL_CDREGS, "ret = %04x", d); + d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a >> 1) & 0xfff]; + else if (a >= 0x20) + d = pcd_pcm_read(a >> 1); + return d; } @@ -885,9 +964,10 @@ static void PicoWriteS68k8_pr(u32 a, u32 d) if ((a & 0xfe00) == 0x8000) { a &= 0x1ff; 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); + if (0x59 <= a && a < 0x68) // word regs + s68k_reg_write16(a & ~1, (d << 8) | d); + else + s68k_reg_write8(a, d); return; } @@ -897,7 +977,7 @@ static void PicoWriteS68k8_pr(u32 a, u32 d) if (a >= 0x2000) Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff] = d; else if (a < 0x12) - pcm_write(a>>1, d); + pcd_pcm_write(a>>1, d); return; } @@ -910,18 +990,7 @@ static void PicoWriteS68k16_pr(u32 a, u32 d) if ((a & 0xfe00) == 0x8000) { a &= 0x1fe; elprintf(EL_CDREGS, "s68k_regs w16: [%02x] %04x @%06x", a, d, SekPcS68k); - if (a >= 0x58 && a < 0x68) - gfx_cd_write16(a, d); - else { - if (a == 0xe) { - // special case, 2 byte writes would be handled differently - // TODO: verify - Pico_mcd->s68k_regs[0xf] = d; - return; - } - s68k_reg_write8(a, d >> 8); - s68k_reg_write8(a + 1, d & 0xff); - } + s68k_reg_write16(a, d); return; } @@ -931,7 +1000,7 @@ static void PicoWriteS68k16_pr(u32 a, u32 d) if (a >= 0x2000) Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff] = d; else if (a < 0x12) - pcm_write(a>>1, d & 0xff); + pcd_pcm_write(a>>1, d & 0xff); return; } @@ -1055,10 +1124,10 @@ PICO_INTERNAL void PicoMemSetupCD(void) } // registers/IO: - cpu68k_map_set(m68k_read8_map, 0xa10000, 0xa1ffff, PicoReadM68k8_io, 1); - cpu68k_map_set(m68k_read16_map, 0xa10000, 0xa1ffff, PicoReadM68k16_io, 1); - cpu68k_map_set(m68k_write8_map, 0xa10000, 0xa1ffff, PicoWriteM68k8_io, 1); - cpu68k_map_set(m68k_write16_map, 0xa10000, 0xa1ffff, PicoWriteM68k16_io, 1); + cpu68k_map_set(m68k_read8_map, 0xa10000, 0xa1ffff, PicoRead8_mcd_io, 1); + cpu68k_map_set(m68k_read16_map, 0xa10000, 0xa1ffff, PicoRead16_mcd_io, 1); + cpu68k_map_set(m68k_write8_map, 0xa10000, 0xa1ffff, PicoWrite8_mcd_io, 1); + cpu68k_map_set(m68k_write16_map, 0xa10000, 0xa1ffff, PicoWrite16_mcd_io, 1); // sub68k map cpu68k_map_set(s68k_read8_map, 0x000000, 0xffffff, s68k_unmapped_read8, 1);