X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fcd%2Fmemory.c;h=22694389af370bae67bb14b125ea9a4c26880727;hb=93f9619ed819dee07948416c98ca2f1c70a22666;hp=47553f57277f7c3a19f8881e1a420beace345ece;hpb=ecc8036ee27ec57454c3fe736a71dd9c0cbcf3de;p=picodrive.git diff --git a/pico/cd/memory.c b/pico/cd/memory.c index 47553f5..2269438 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,6 +67,12 @@ static void remap_word_ram(u32 r3); void m68k_comm_check(u32 a) { pcd_sync_s68k(SekCyclesDone(), 0); + 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; @@ -108,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"); @@ -230,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); } } @@ -293,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; @@ -336,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: { @@ -382,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 & 0xff); return; case 0xa: elprintf(EL_CDREGS, "s68k set CDC dma addr"); @@ -410,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 @@ -421,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; } @@ -452,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 // ----------------------------------------------------------------- @@ -514,14 +602,14 @@ static u32 PicoReadM68k8_ramc(u32 a) { u32 d = 0; if (a == 0x400001) { - if (SRam.data != NULL) + if (Pico.sv.data != NULL) d = 3; // 64k cart return d; } if ((a & 0xfe0000) == 0x600000) { - if (SRam.data != NULL) - d = SRam.data[((a >> 1) & 0xffff) + 0x2000]; + if (Pico.sv.data != NULL) + d = Pico.sv.data[((a >> 1) & 0xffff) + 0x2000]; return d; } @@ -541,9 +629,9 @@ static u32 PicoReadM68k16_ramc(u32 a) static void PicoWriteM68k8_ramc(u32 a, u32 d) { if ((a & 0xfe0000) == 0x600000) { - if (SRam.data != NULL && (Pico_mcd->m.bcram_reg & 1)) { - SRam.data[((a>>1) & 0xffff) + 0x2000] = d; - SRam.changed = 1; + if (Pico.sv.data != NULL && (Pico_mcd->m.bcram_reg & 1)) { + Pico.sv.data[((a>>1) & 0xffff) + 0x2000] = d; + Pico.sv.changed = 1; } return; } @@ -566,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 @@ -583,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) { @@ -596,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", @@ -605,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; @@ -789,7 +877,7 @@ static u32 PicoReadS68k16_bram(u32 a) static void PicoWriteS68k8_bram(u32 a, u32 d) { Pico_mcd->bram[(a >> 1) & 0x1fff] = d; - SRam.changed = 1; + Pico.sv.changed = 1; } static void PicoWriteS68k16_bram(u32 a, u32 d) @@ -798,7 +886,7 @@ static void PicoWriteS68k16_bram(u32 a, u32 d) a = (a >> 1) & 0x1fff; Pico_mcd->bram[a++] = d; Pico_mcd->bram[a++] = d >> 8; // TODO: verify.. - SRam.changed = 1; + Pico.sv.changed = 1; } #ifndef _ASM_CD_MEMORY_C @@ -816,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; @@ -835,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); @@ -854,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); @@ -865,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; } @@ -887,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; } @@ -899,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; } @@ -912,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; } @@ -933,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; } @@ -1004,23 +1071,6 @@ static void remap_word_ram(u32 r3) cpu68k_map_set(s68k_write8_map, 0x080000, 0x0bffff, s68k_dec_write8[b0 ^ 1][m], 1); cpu68k_map_set(s68k_write16_map, 0x080000, 0x0bffff, s68k_dec_write16[b0 ^ 1][m], 1); } - -#ifdef EMU_F68K - // update fetchmap.. - int i; - if (!(r3 & 4)) - { - for (i = M68K_FETCHBANK1*2/16; (i<<(24-FAMEC_FETCHBITS)) < 0x240000; i++) - PicoCpuFM68k.Fetch[i] = (unsigned long)Pico_mcd->word_ram2M - 0x200000; - } - else - { - for (i = M68K_FETCHBANK1*2/16; (i<<(24-FAMEC_FETCHBITS)) < 0x220000; i++) - PicoCpuFM68k.Fetch[i] = (unsigned long)Pico_mcd->word_ram1M[r3 & 1] - 0x200000; - for (i = M68K_FETCHBANK1*0x0c/0x100; (i<<(24-FAMEC_FETCHBITS)) < 0x0e0000; i++) - PicoCpuFS68k.Fetch[i] = (unsigned long)Pico_mcd->word_ram1M[(r3&1)^1] - 0x0c0000; - } -#endif } void pcd_state_loaded_mem(void) @@ -1049,7 +1099,7 @@ PICO_INTERNAL void PicoMemSetupCD(void) // main68k map (BIOS mapped by PicoMemSetup()): // RAM cart - if (PicoOpt & POPT_EN_MCD_RAMCART) { + if (PicoIn.opt & POPT_EN_MCD_RAMCART) { cpu68k_map_set(m68k_read8_map, 0x400000, 0x7fffff, PicoReadM68k8_ramc, 1); cpu68k_map_set(m68k_read16_map, 0x400000, 0x7fffff, PicoReadM68k16_ramc, 1); cpu68k_map_set(m68k_write8_map, 0x400000, 0x7fffff, PicoWriteM68k8_ramc, 1); @@ -1057,10 +1107,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); @@ -1115,7 +1165,12 @@ PICO_INTERNAL void PicoMemSetupCD(void) // setup FAME fetchmap { +#ifdef __clang__ + volatile // prevent strange relocs from clang +#endif + unsigned long ptr_ram = (unsigned long)PicoMem.ram; int i; + // M68k // by default, point everything to fitst 64k of ROM (BIOS) for (i = 0; i < M68K_FETCHBANK1; i++) @@ -1125,7 +1180,7 @@ PICO_INTERNAL void PicoMemSetupCD(void) PicoCpuFM68k.Fetch[i] = (unsigned long)Pico.rom; // .. and RAM for (i = M68K_FETCHBANK1*14/16; i < M68K_FETCHBANK1; i++) - PicoCpuFM68k.Fetch[i] = (unsigned long)Pico.ram - (i<<(24-FAMEC_FETCHBITS)); + PicoCpuFM68k.Fetch[i] = ptr_ram - (i<<(24-FAMEC_FETCHBITS)); // S68k // PRG RAM is default for (i = 0; i < M68K_FETCHBANK1; i++)