From 02ff025479b6c78bcfcd78dc80581287a226a2b9 Mon Sep 17 00:00:00 2001 From: kub Date: Fri, 26 May 2023 19:09:37 +0000 Subject: [PATCH] mcd, preparations for msu support --- pico/cart.c | 5 -- pico/cd/cd_image.c | 15 ++++-- pico/cd/cd_parse.c | 29 +++++------ pico/cd/cdc.c | 7 +-- pico/cd/cdd.c | 37 +++++++------- pico/cd/cdd.h | 1 + pico/cd/mcd.c | 8 ++- pico/cd/memory.c | 113 +++++++++++++++++-------------------------- pico/cd/memory_arm.S | 58 +++++++++++----------- pico/memory.c | 19 ++------ pico/pico.c | 4 +- pico/pico.h | 8 +-- pico/pico_int.h | 7 +-- pico/state.c | 2 +- pico/videoport.c | 10 ++-- 15 files changed, 153 insertions(+), 170 deletions(-) diff --git a/pico/cart.c b/pico/cart.c index 526ea442..dee5485b 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -726,11 +726,6 @@ static unsigned char *PicoCartAlloc(int filesize, int is_sms) rom_alloc_size = 0x10000; } else { - // make alloc size at least sizeof(mcd_state), - // in case we want to switch to CD mode - if (filesize < sizeof(mcd_state)) - filesize = sizeof(mcd_state); - // align to 512K for memhandlers rom_alloc_size = (filesize + 0x7ffff) & ~0x7ffff; } diff --git a/pico/cd/cd_image.c b/pico/cd/cd_image.c index 65d22ebd..9bd29ce0 100644 --- a/pico/cd/cd_image.c +++ b/pico/cd/cd_image.c @@ -49,6 +49,7 @@ static int handle_mp3(const char *fname, int index) return -1; } + track->type = CT_AUDIO; track->fd = tmp_file; track->offset = 0; @@ -114,10 +115,11 @@ int load_cd_image(const char *cd_img_name, int *type) } tracks[0].fd = pmf; tracks[0].fname = strdup(cd_img_name); + tracks[0].type = *type & CT_AUDIO; if (*type == CT_ISO) - cd_img_sectors = pmf->size >>= 11; // size in sectors - else cd_img_sectors = pmf->size /= 2352; + cd_img_sectors = pmf->size >> 11; // size in sectors + else cd_img_sectors = pmf->size / 2352; // cdd.c operates with lba - 150 tracks[0].start = 0; @@ -125,8 +127,8 @@ int load_cd_image(const char *cd_img_name, int *type) tracks[0].offset = 0; sprintf_lba(tmp_ext, sizeof(tmp_ext), 0); - elprintf(EL_STATUS, "Track 1: %s %9i DATA %s", - tmp_ext, tracks[0].end, cd_img_name); + elprintf(EL_STATUS, "Track 1: %s %9i %s %s", + tmp_ext, tracks[0].end, tracks[0].type ? "AUDIO" : "DATA ", cd_img_name); lba = cd_img_sectors; @@ -185,13 +187,15 @@ int load_cd_image(const char *cd_img_name, int *type) length = cue_data->tracks[n].sector_xlength; Pico_mcd->cdda_type = cue_data->tracks[n].type; + tracks[index].type = cue_data->tracks[n].type & CT_AUDIO; tracks[index].start = lba; lba += length; tracks[index].end = lba; sprintf_lba(tmp_ext, sizeof(tmp_ext), tracks[index].start); - elprintf(EL_STATUS, "Track %2i: %s %9i AUDIO %s", n, tmp_ext, length, + elprintf(EL_STATUS, "Track %2i: %s %9i %s %s", n, tmp_ext, length, + tracks[index].type ? "AUDIO" : "DATA ", cue_data->tracks[n].fname ? cue_data->tracks[n].fname : ""); } goto finish; @@ -246,6 +250,7 @@ int load_cd_image(const char *cd_img_name, int *type) tracks[index].end = lba; Pico_mcd->cdda_type = CT_MP3; + tracks[index].type = CT_AUDIO; sprintf_lba(tmp_ext, sizeof(tmp_ext), tracks[index].start); elprintf(EL_STATUS, "Track %2i: %s %9i AUDIO - %s", diff --git a/pico/cd/cd_parse.c b/pico/cd/cd_parse.c index 574070dd..53c15d20 100644 --- a/pico/cd/cd_parse.c +++ b/pico/cd/cd_parse.c @@ -172,19 +172,15 @@ cd_data_t *chd_parse(const char *fname) } memset(&data->tracks[count], 0, sizeof(data->tracks[0])); - if (count == 1) { // binary code - data->tracks[count].fname = strdup(fname); - if (!strcmp(type, "MODE1_RAW") || !strcmp(type, "MODE2_RAW")) { - data->tracks[count].type = CT_BIN; - } else if (!strcmp(type, "MODE1") || !strcmp(type, "MODE2_FORM1")) { - data->tracks[count].type = CT_ISO; - } else - break; - } else { // audio - if (strcmp(type, "AUDIO")) - break; + data->tracks[count].fname = strdup(fname); + if (!strcmp(type, "MODE1_RAW") || !strcmp(type, "MODE2_RAW")) { + data->tracks[count].type = CT_BIN; + } else if (!strcmp(type, "MODE1") || !strcmp(type, "MODE2_FORM1")) { + data->tracks[count].type = CT_ISO; + } else if (!strcmp(type, "AUDIO")) { data->tracks[count].type = CT_CHD; - } + } else + break; data->tracks[count].pregap = pregap; if (pgtype[0] != 'V') // VAUDIO includes pregap in file @@ -344,17 +340,22 @@ file_ok: else if (strcasecmp(ext, "wav") == 0) data->tracks[count].type = CT_WAV; else if (strcasecmp(ext, "bin") == 0) - data->tracks[count].type = CT_BIN; + data->tracks[count].type = CT_RAW; else { elprintf(EL_STATUS, "unhandled audio format: \"%s\"", data->tracks[count].fname); } } - else + else if (data->tracks[count-1].type & CT_AUDIO) { // propagate previous data->tracks[count].type = data->tracks[count-1].type; } + else + { + // assume raw binary data + data->tracks[count].type = CT_RAW; + } } else { elprintf(EL_STATUS, "unhandled track type: \"%s\"", buff2); diff --git a/pico/cd/cdc.c b/pico/cd/cdc.c index f7ae04c2..de16acbc 100644 --- a/pico/cd/cdc.c +++ b/pico/cd/cdc.c @@ -704,7 +704,6 @@ void cdc_reg_w(unsigned char data) case 0x0f: /* RESET */ cdc_reset(); - Pico_mcd->s68k_regs[0x04+1] = 0x10; break; default: /* by default, SBOUT is not used */ @@ -715,7 +714,7 @@ void cdc_reg_w(unsigned char data) unsigned char cdc_reg_r(void) { - switch (Pico_mcd->s68k_regs[0x04+1] & 0x01F) + switch (Pico_mcd->s68k_regs[0x04+1] & 0x1F) { case 0x00: return 0xff; @@ -835,7 +834,9 @@ unsigned short cdc_host_r(void) /* clear DSR bit & set EDT bit (SCD register $04) */ Pico_mcd->s68k_regs[0x04+0] = (Pico_mcd->s68k_regs[0x04+0] & 0x07) | 0x80; - } else if ((int16)cdc.dbc <= 2) { + + } else if ((int16)cdc.dbc <= 2) + { if (cdc.ifstat & BIT_DTEI) { /* pending Data Transfer End interrupt */ cdc.ifstat &= ~BIT_DTEI; diff --git a/pico/cd/cdd.c b/pico/cd/cdd.c index 571c5a77..6e510c2c 100644 --- a/pico/cd/cdd.c +++ b/pico/cd/cdd.c @@ -49,6 +49,9 @@ cdd_t cdd; +#define is_audio(index) \ + (cdd.toc.tracks[index].type & CT_AUDIO) + /* BCD conversion lookup tables */ static const uint8 lut_BCD_8[100] = { @@ -239,12 +242,12 @@ int cdd_context_load(uint8 *state) } /* seek to current track position */ - if (!cdd.index) + if (!is_audio(cdd.index)) { /* DATA track */ - if (cdd.toc.tracks[0].fd) + if (cdd.toc.tracks[cdd.index].fd) { - pm_seek(cdd.toc.tracks[0].fd, lba * cdd.sectorSize, SEEK_SET); + pm_seek(cdd.toc.tracks[cdd.index].fd, lba * cdd.sectorSize, SEEK_SET); } } #ifdef USE_LIBTREMOR @@ -318,7 +321,7 @@ int cdd_load(const char *filename, int type) cdd.sectorSize = 2048; } - ret = (type == CT_BIN) ? 2352 : 2048; + ret = (type == CT_ISO ? 2048 : 2352); if (ret != cdd.sectorSize) elprintf(EL_STATUS|EL_ANOMALY, "cd: type detection mismatch"); pm_sectorsize(cdd.sectorSize, cdd.toc.tracks[0].fd); @@ -507,17 +510,17 @@ int cdd_unload(void) void cdd_read_data(uint8 *dst) { /* only read DATA track sectors */ - if ((cdd.lba >= 0) && (cdd.lba < cdd.toc.tracks[0].end)) + if ((cdd.lba >= 0) && (cdd.lba < cdd.toc.tracks[cdd.index].end)) { /* BIN format ? */ if (cdd.sectorSize == 2352) { /* skip 16-byte header */ - pm_seek(cdd.toc.tracks[0].fd, cdd.lba * 2352 + 16, SEEK_SET); + pm_seek(cdd.toc.tracks[cdd.index].fd, cdd.lba * 2352 + 16, SEEK_SET); } /* read sector data (Mode 1 = 2048 bytes) */ - pm_read(dst, 2048, cdd.toc.tracks[0].fd); + pm_read(dst, 2048, cdd.toc.tracks[cdd.index].fd); } } @@ -698,7 +701,7 @@ void cdd_update(void) if (cdd.status == CD_PLAY) { /* track type */ - if (!cdd.index) + if (!is_audio(cdd.index)) { /* DATA sector header (CD-ROM Mode 1) */ uint8 header[4]; @@ -846,13 +849,13 @@ void cdd_update(void) } /* seek to current block */ - if (!cdd.index) + if (!is_audio(cdd.index)) { /* no AUDIO track playing */ Pico_mcd->s68k_regs[0x36+0] = 0x01; /* DATA track */ - pm_seek(cdd.toc.tracks[0].fd, cdd.lba * cdd.sectorSize, SEEK_SET); + pm_seek(cdd.toc.tracks[cdd.index].fd, cdd.lba * cdd.sectorSize, SEEK_SET); } #ifdef USE_LIBTREMOR else if (cdd.toc.tracks[cdd.index].vf.seekable) @@ -914,7 +917,7 @@ void cdd_process(void) set_reg16(0x3a, lut_BCD_16[(lba/75)/60]); set_reg16(0x3c, lut_BCD_16[(lba/75)%60]); set_reg16(0x3e, lut_BCD_16[(lba%75)]); - Pico_mcd->s68k_regs[0x40+0] = cdd.index ? 0x00 : 0x04; + Pico_mcd->s68k_regs[0x40+0] = is_audio(cdd.index) ? 0x00 : 0x04; } else if (Pico_mcd->s68k_regs[0x38+1] == 0x02) { /* then return valid track infos, e.g current track number in RS2-RS3 (fixes Lunar - The Silver Star) */ Pico_mcd->s68k_regs[0x38+1] = 0x02; @@ -957,7 +960,7 @@ void cdd_process(void) set_reg16(0x3a, lut_BCD_16[(lba/75)/60]); set_reg16(0x3c, lut_BCD_16[(lba/75)%60]); set_reg16(0x3e, lut_BCD_16[(lba%75)]); - Pico_mcd->s68k_regs[0x40+0] = cdd.index ? 0x00 : 0x04; /* Current block flags in RS8 (bit0 = mute status, bit1: pre-emphasis status, bit2: track type) */ + Pico_mcd->s68k_regs[0x40+0] = is_audio(cdd.index) ? 0x00 : 0x04; /* Current block flags in RS8 (bit0 = mute status, bit1: pre-emphasis status, bit2: track type) */ break; } @@ -969,7 +972,7 @@ void cdd_process(void) set_reg16(0x3a, lut_BCD_16[(lba/75)/60]); set_reg16(0x3c, lut_BCD_16[(lba/75)%60]); set_reg16(0x3e, lut_BCD_16[(lba%75)]); - Pico_mcd->s68k_regs[0x40+0] = cdd.index ? 0x00 : 0x04; /* Current block flags in RS8 (bit0 = mute status, bit1: pre-emphasis status, bit2: track type) */ + Pico_mcd->s68k_regs[0x40+0] = is_audio(cdd.index) ? 0x00 : 0x04; /* Current block flags in RS8 (bit0 = mute status, bit1: pre-emphasis status, bit2: track type) */ break; } @@ -1113,10 +1116,10 @@ void cdd_process(void) } /* seek to current block */ - if (!index) + if (!is_audio(cdd.index)) { /* DATA track */ - pm_seek(cdd.toc.tracks[0].fd, lba * cdd.sectorSize, SEEK_SET); + pm_seek(cdd.toc.tracks[cdd.index].fd, lba * cdd.sectorSize, SEEK_SET); } #ifdef USE_LIBTREMOR else if (cdd.toc.tracks[index].vf.seekable) @@ -1212,10 +1215,10 @@ void cdd_process(void) } /* seek to current block */ - if (!index) + if (!is_audio(cdd.index)) { /* DATA track */ - pm_seek(cdd.toc.tracks[0].fd, lba * cdd.sectorSize, SEEK_SET); + pm_seek(cdd.toc.tracks[cdd.index].fd, lba * cdd.sectorSize, SEEK_SET); } #ifdef USE_LIBTREMOR else if (cdd.toc.tracks[index].vf.seekable) diff --git a/pico/cd/cdd.h b/pico/cd/cdd.h index da5b5108..d896e256 100644 --- a/pico/cd/cdd.h +++ b/pico/cd/cdd.h @@ -60,6 +60,7 @@ /* CD track */ typedef struct { + int type; char *fname; void *fd; #ifdef USE_LIBTREMOR diff --git a/pico/cd/mcd.c b/pico/cd/mcd.c index 50c85ac1..2943f431 100644 --- a/pico/cd/mcd.c +++ b/pico/cd/mcd.c @@ -16,6 +16,7 @@ static unsigned int mcd_s68k_cycle_mult; static unsigned int mcd_m68k_cycle_base; static unsigned int mcd_s68k_cycle_base; +mcd_state *Pico_mcd; PICO_INTERNAL void PicoInitMCD(void) { @@ -25,6 +26,10 @@ PICO_INTERNAL void PicoInitMCD(void) PICO_INTERNAL void PicoExitMCD(void) { cdd_unload(); + if (Pico_mcd) { + plat_munmap(Pico_mcd, sizeof(mcd_state)); + Pico_mcd = NULL; + } } PICO_INTERNAL void PicoPowerMCD(void) @@ -52,7 +57,8 @@ PICO_INTERNAL void PicoPowerMCD(void) Pico_mcd->m.state_flags = PCD_ST_S68K_RST; Pico_mcd->m.busreq = 2; // busreq on, s68k in reset Pico_mcd->s68k_regs[3] = 1; // 2M word RAM mode, m68k access - memset(Pico_mcd->bios + 0x70, 0xff, 4); + if (Pico.romsize <= 0x20000) + memset(Pico.rom + 0x70, 0xff, 4); } void pcd_soft_reset(void) diff --git a/pico/cd/memory.c b/pico/cd/memory.c index b26b6295..ba3ee398 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -23,6 +23,9 @@ MAKE_68K_WRITE16(s68k_write16, s68k_write16_map) MAKE_68K_WRITE32(s68k_write32, s68k_write16_map) #endif +u32 pcd_base_address; +#define BASE pcd_base_address + // ----------------------------------------------------------------- // provided by ASM code: @@ -113,7 +116,7 @@ static u32 m68k_reg_read16(u32 a) d = Pico_mcd->s68k_regs[4]<<8; goto end; case 6: - d = *(u16 *)(Pico_mcd->bios + 0x72); + d = *(u16 *)(Pico.rom + 0x72); goto end; case 8: d = cdc_host_r(); @@ -169,8 +172,8 @@ void m68k_reg_write8(u32 a, u32 d) case 1: d &= 3; dold = Pico_mcd->m.busreq; - if (!(d & 1)) - d |= 2; // verified: can't release bus on reset +// if (!(d & 1)) +// d |= 2; // verified: can't release bus on reset if (dold == d) return; @@ -185,7 +188,7 @@ void m68k_reg_write8(u32 a, u32 d) elprintf(EL_CDREGS, "m68k: resetting s68k"); SekResetS68k(); } - if ((dold ^ d) & 2) { + if (((dold & 3) == 1) != ((d & 3) == 1)) { elprintf(EL_INTSW, "m68k: s68k brq %i", d >> 1); remap_prg_window(d, Pico_mcd->s68k_regs[3]); } @@ -218,12 +221,12 @@ void m68k_reg_write8(u32 a, u32 d) remap_word_ram(d); goto write_comm; case 6: - Pico_mcd->bios[MEM_BE2(0x72)] = d; // simple hint vector changer + Pico.rom[MEM_BE2(0x72)] = d; // simple hint vector changer return; case 7: - Pico_mcd->bios[MEM_BE2(0x73)] = d; + Pico.rom[MEM_BE2(0x73)] = d; elprintf(EL_CDREGS, "hint vector set to %04x%04x", - ((u16 *)Pico_mcd->bios)[0x70/2], ((u16 *)Pico_mcd->bios)[0x72/2]); + ((u16 *)Pico.rom)[0x70/2], ((u16 *)Pico.rom)[0x72/2]); return; case 8: (void) cdc_host_r(); // acts same as reading @@ -659,7 +662,7 @@ static void PicoWriteM68k16_cell1(u32 a, u32 d) } #endif -// RAM cart (40000 - 7fffff, optional) +// RAM cart (400000 - 7fffff, optional) static u32 PicoReadM68k8_ramc(u32 a) { u32 d = 0; @@ -685,6 +688,8 @@ static u32 PicoReadM68k8_ramc(u32 a) static u32 PicoReadM68k16_ramc(u32 a) { elprintf(EL_ANOMALY, "ramcart r16: [%06x] @%06x", a, SekPcS68k); + if ((a & 0xfffffc) == BASE+0x100) // CD detection by MSU + return (~a & 2) ? 0x5345 : 0x4741; // "SEGA" return PicoReadM68k8_ramc(a + 1); } @@ -1093,13 +1098,12 @@ static const void *s68k_dec_write16[2][4] = { static void remap_prg_window(u32 r1, u32 r3) { - // PRG RAM - if (r1 & 2) { + // PRG RAM, mapped to main CPU if sub is not running + if ((r1 & 3) != 1) { void *bank = Pico_mcd->prg_ram_b[(r3 >> 6) & 3]; - cpu68k_map_all_ram(0x020000, 0x03ffff, bank, 0); - } - else { - m68k_map_unmap(0x020000, 0x03ffff); + cpu68k_map_all_ram(BASE+0x020000, BASE+0x03ffff, bank, 0); + } else { + m68k_map_unmap(BASE+0x020000, BASE+0x03ffff); } } @@ -1145,14 +1149,14 @@ static void remap_word_ram(u32 r3) // 2M mode. bank = Pico_mcd->word_ram2M; if (r3 & 1) { - cpu68k_map_all_ram(0x200000, 0x23ffff, bank, 0); + cpu68k_map_all_ram(BASE+0x200000, BASE+0x23ffff, bank, 0); cpu68k_map_all_funcs(0x80000, 0xbffff, s68k_wordram_main_read8, s68k_wordram_main_read16, s68k_wordram_main_write8, s68k_wordram_main_write16, 1); } else { Pico_mcd->m.state_flags &= ~PCD_ST_S68K_SLEEP; cpu68k_map_all_ram(0x080000, 0x0bffff, bank, 1); - m68k_map_unmap(0x200000, 0x23ffff); + m68k_map_unmap(BASE+0x200000, BASE+0x23ffff); } // TODO: handle 0x0c0000 } @@ -1161,11 +1165,11 @@ static void remap_word_ram(u32 r3) int m = (r3 & 0x18) >> 3; Pico_mcd->m.state_flags &= ~PCD_ST_S68K_SLEEP; bank = Pico_mcd->word_ram1M[b0]; - cpu68k_map_all_ram(0x200000, 0x21ffff, bank, 0); + cpu68k_map_all_ram(BASE+0x200000, BASE+0x21ffff, bank, 0); bank = Pico_mcd->word_ram1M[b0 ^ 1]; cpu68k_map_all_ram(0x0c0000, 0x0effff, bank, 1); // "cell arrange" on m68k - cpu68k_map_all_funcs(0x220000, 0x23ffff, + cpu68k_map_all_funcs(BASE+0x220000, BASE+0x23ffff, m68k_cell_read8[b0], m68k_cell_read16[b0], m68k_cell_write8[b0], m68k_cell_write16[b0], 0); // "decode format" on s68k @@ -1187,7 +1191,7 @@ void pcd_state_loaded_mem(void) Pico_mcd->m.dmna_ret_2m &= 3; // restore hint vector - *(u16 *)(Pico_mcd->bios + 0x72) = Pico_mcd->m.hint_vector; + *(u16 *)(Pico.rom + 0x72) = Pico_mcd->m.hint_vector; } #ifdef EMU_M68K @@ -1196,6 +1200,10 @@ static void m68k_mem_setup_cd(void); PICO_INTERNAL void PicoMemSetupCD(void) { + if (!Pico_mcd) + Pico_mcd = plat_mmap(0x05000000, sizeof(mcd_state), 0, 0); + pcd_base_address = (Pico.romsize > 0x20000 ? 0x400000 : 0x000000); + // setup default main68k map PicoMemSetup(); @@ -1215,30 +1223,30 @@ PICO_INTERNAL void PicoMemSetupCD(void) 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); - cpu68k_map_set(s68k_read16_map, 0x000000, 0xffffff, s68k_unmapped_read16, 1); - cpu68k_map_set(s68k_write8_map, 0x000000, 0xffffff, s68k_unmapped_write8, 1); - cpu68k_map_set(s68k_write16_map, 0x000000, 0xffffff, s68k_unmapped_write16, 1); + cpu68k_map_set(s68k_read8_map, 0x000000, 0xffffff, s68k_unmapped_read8, 3); + cpu68k_map_set(s68k_read16_map, 0x000000, 0xffffff, s68k_unmapped_read16, 3); + cpu68k_map_set(s68k_write8_map, 0x000000, 0xffffff, s68k_unmapped_write8, 3); + cpu68k_map_set(s68k_write16_map, 0x000000, 0xffffff, s68k_unmapped_write16, 3); // PRG RAM - cpu68k_map_set(s68k_read8_map, 0x000000, 0x07ffff, Pico_mcd->prg_ram, 0); - 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, 0x01ffff, PicoWriteS68k8_prgwp, 1); - cpu68k_map_set(s68k_write16_map, 0x000000, 0x01ffff, PicoWriteS68k16_prgwp, 1); + cpu68k_map_set(s68k_read8_map, 0x000000, 0x07ffff, Pico_mcd->prg_ram, 2); + cpu68k_map_set(s68k_read16_map, 0x000000, 0x07ffff, Pico_mcd->prg_ram, 2); + cpu68k_map_set(s68k_write8_map, 0x000000, 0x07ffff, Pico_mcd->prg_ram, 2); + cpu68k_map_set(s68k_write16_map, 0x000000, 0x07ffff, Pico_mcd->prg_ram, 2); + cpu68k_map_set(s68k_write8_map, 0x000000, 0x01ffff, PicoWriteS68k8_prgwp, 3); + cpu68k_map_set(s68k_write16_map, 0x000000, 0x01ffff, PicoWriteS68k16_prgwp, 3); // BRAM - cpu68k_map_set(s68k_read8_map, 0xfe0000, 0xfeffff, PicoReadS68k8_bram, 1); - cpu68k_map_set(s68k_read16_map, 0xfe0000, 0xfeffff, PicoReadS68k16_bram, 1); - cpu68k_map_set(s68k_write8_map, 0xfe0000, 0xfeffff, PicoWriteS68k8_bram, 1); - cpu68k_map_set(s68k_write16_map, 0xfe0000, 0xfeffff, PicoWriteS68k16_bram, 1); + cpu68k_map_set(s68k_read8_map, 0xfe0000, 0xfeffff, PicoReadS68k8_bram, 3); + cpu68k_map_set(s68k_read16_map, 0xfe0000, 0xfeffff, PicoReadS68k16_bram, 3); + cpu68k_map_set(s68k_write8_map, 0xfe0000, 0xfeffff, PicoWriteS68k8_bram, 3); + cpu68k_map_set(s68k_write16_map, 0xfe0000, 0xfeffff, PicoWriteS68k16_bram, 3); // PCM, regs - cpu68k_map_set(s68k_read8_map, 0xff0000, 0xffffff, PicoReadS68k8_pr, 1); - cpu68k_map_set(s68k_read16_map, 0xff0000, 0xffffff, PicoReadS68k16_pr, 1); - cpu68k_map_set(s68k_write8_map, 0xff0000, 0xffffff, PicoWriteS68k8_pr, 1); - cpu68k_map_set(s68k_write16_map, 0xff0000, 0xffffff, PicoWriteS68k16_pr, 1); + cpu68k_map_set(s68k_read8_map, 0xff0000, 0xffffff, PicoReadS68k8_pr, 3); + cpu68k_map_set(s68k_read16_map, 0xff0000, 0xffffff, PicoReadS68k16_pr, 3); + cpu68k_map_set(s68k_write8_map, 0xff0000, 0xffffff, PicoWriteS68k8_pr, 3); + cpu68k_map_set(s68k_write16_map, 0xff0000, 0xffffff, PicoWriteS68k16_pr, 3); // RAMs remap_prg_window(2,1); @@ -1265,37 +1273,6 @@ PICO_INTERNAL void PicoMemSetupCD(void) PicoCpuFS68k.write_byte = (void *)s68k_write8; PicoCpuFS68k.write_word = (void *)s68k_write16; PicoCpuFS68k.write_long = (void *)s68k_write32; - - // setup FAME fetchmap - { -#if defined __clang__ || defined HW_WUP - volatile // prevent strange relocs from clang -#endif - uptr ptr_ram = (uptr)PicoMem.ram; - int i; - - // M68k - // by default, point everything to fitst 64k of ROM (BIOS) - for (i = 0; i < M68K_FETCHBANK1; i++) - PicoCpuFM68k.Fetch[i] = (uptr)Pico.rom - (i<<(24-FAMEC_FETCHBITS)); - // now real ROM (BIOS) - for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < Pico.romsize; i++) - PicoCpuFM68k.Fetch[i] = (uptr)Pico.rom; - // .. and RAM - for (i = M68K_FETCHBANK1*14/16; i < M68K_FETCHBANK1; i++) - PicoCpuFM68k.Fetch[i] = ptr_ram - (i<<(24-FAMEC_FETCHBITS)); - // S68k - // PRG RAM is default - for (i = 0; i < M68K_FETCHBANK1; i++) - PicoCpuFS68k.Fetch[i] = (uptr)Pico_mcd->prg_ram - (i<<(24-FAMEC_FETCHBITS)); - // real PRG RAM - for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < 0x80000; i++) - PicoCpuFS68k.Fetch[i] = (uptr)Pico_mcd->prg_ram; - // WORD RAM 2M area - for (i = M68K_FETCHBANK1*0x08/0x100; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < 0xc0000; i++) - PicoCpuFS68k.Fetch[i] = (uptr)Pico_mcd->word_ram2M - 0x80000; - // remap_word_ram() will setup word ram for both - } #endif #ifdef EMU_M68K m68k_mem_setup_cd(); diff --git a/pico/cd/memory_arm.S b/pico/cd/memory_arm.S index e4c314ba..f601d47c 100644 --- a/pico/cd/memory_arm.S +++ b/pico/cd/memory_arm.S @@ -51,7 +51,7 @@ .global PicoWriteS68k16_dec_m2b1 @ externs, just for reference -.extern Pico +.extern Pico_mcd .extern cdc_host_r .extern m68k_reg_write8 .extern s68k_reg_read16 @@ -130,9 +130,9 @@ PicoReadM68k8_cell1: @ 0x220000 - 0x23ffff, cell arranged mov r3, #0x0e0000 0: cell_map - PIC_LDR(r1, r2, Pico) + PIC_LDR(r1, r2, Pico_mcd) add r0, r0, r3 - ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd (used everywhere) + ldr r1, [r1] @ Pico.mcd (used everywhere) eor r0, r0, #1 ldrb r0, [r1, r0] bx lr @@ -143,9 +143,9 @@ PicoRead8_mcd_io: cmp r1, #0x2000 @ a120xx? bne PicoRead8_io - PIC_LDR(r1, r2, Pico) + PIC_LDR(r1, r2, Pico_mcd) and r0, r0, #0x3f - ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd + ldr r1, [r1] @ Pico.mcd cmp r0, #0x0e PIC_XB(lt ,r0, lsl #2) b m_m68k_read8_hi @@ -242,9 +242,9 @@ PicoReadM68k16_cell1: @ 0x220000 - 0x23ffff, cell arranged mov r3, #0x0e0000 0: cell_map - PIC_LDR(r1, r2, Pico) + PIC_LDR(r1, r2, Pico_mcd) add r0, r0, r3 - ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd + ldr r1, [r1] @ Pico.mcd bic r0, r0, #1 ldrh r0, [r1, r0] bx lr @@ -256,9 +256,9 @@ PicoRead16_mcd_io: bne PicoRead16_io m_m68k_read16_m68k_regs: - PIC_LDR(r1, r2, Pico) + PIC_LDR(r1, r2, Pico_mcd) and r0, r0, #0x3e - ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd + ldr r1, [r1, @ Pico.mcd cmp r0, #0x0e PIC_XB(lt ,r0, lsl #1) b m_m68k_read16_hi @@ -333,9 +333,9 @@ PicoWriteM68k8_cell1: @ 0x220000 - 0x23ffff, cell arranged 0: mov r3, r1 cell_map - PIC_LDR(r2, r1, Pico) + PIC_LDR(r2, r1, Pico_mcd) add r0, r0, r12 - ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd + ldr r2, [r2] @ Pico.mcd ldr r2, [r2] eor r0, r0, #1 strb r3, [r2, r0] @@ -361,9 +361,9 @@ PicoWriteM68k16_cell1: @ 0x220000 - 0x23ffff, cell arranged 0: mov r3, r1 cell_map - PIC_LDR(r1, r2, Pico) + PIC_LDR(r1, r2, Pico_mcd) add r0, r0, r12 - ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd + ldr r1, [r1] @ Pico.mcd bic r0, r0, #1 strh r3, [r1, r0] bx lr @@ -403,9 +403,9 @@ PicoReadS68k8_dec0: @ 0x080000 - 0x0bffff PicoReadS68k8_dec1: mov r3, #0x0a0000 @ + ^ / 2 0: - PIC_LDR(r2, r1, Pico) + PIC_LDR(r2, r1, Pico_mcd) eor r0, r0, #2 - ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd + ldr r2, [r2] @ Pico.mcd movs r0, r0, lsr #1 @ +4-6 <<16 add r2, r2, r3 @ map to our address ldrb r0, [r2, r0] @@ -435,8 +435,8 @@ m_s68k_read8_regs: bx lr m_s68k_read8_comm: - PIC_LDR(r1, r2, Pico) - ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd + PIC_LDR(r1, r2, Pico_mcd) + ldr r1, [r1] @ Pico.mcd add r1, r1, #0x110000 ldrb r1, [r1, r0] bic r0, r0, #1 @@ -448,9 +448,9 @@ m_s68k_read8_pcm: bne m_read_null @ must not trash r3 and r12 - PIC_LDR(r1, r2, Pico) + PIC_LDR(r1, r2, Pico_mcd) bic r0, r0, #0xff0000 - ldr r1, [r1, #OFS_Pico_rom] @ Pico.mcd + ldr r1, [r1] @ Pico.mcd mov r2, #0x110000 orr r2, r2, #0x002200 cmp r0, #0x2000 @@ -483,9 +483,9 @@ PicoReadS68k16_dec0: @ 0x080000 - 0x0bffff PicoReadS68k16_dec1: mov r3, #0x0a0000 @ + ^ / 2 0: - PIC_LDR(r2, r1, Pico) + PIC_LDR(r2, r1, Pico_mcd) eor r0, r0, #2 - ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd + ldr r2, [r2] @ Pico.mcd mov r0, r0, lsr #1 @ +4-6 <<16 add r2, r2, r3 @ map to our address ldrb r0, [r2, r0] @@ -513,9 +513,9 @@ m_s68k_read16_regs: .macro m_s68k_write8_2M_decode - PIC_LDR(r2, ip, Pico) + PIC_LDR(r2, ip, Pico_mcd) eor r0, r0, #2 - ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd + ldr r2, [r2] @ Pico.mcd movs r0, r0, lsr #1 @ +4-6 <<16 add r2, r2, r3 @ map to our address .endm @@ -597,9 +597,9 @@ m_s68k_write8_pcm: bxlt lr m_s68k_write8_pcm_ram: - PIC_LDR(r3, r2, Pico) + PIC_LDR(r3, r2, Pico_mcd) bic r0, r0, #0x00e000 - ldr r3, [r3, #OFS_Pico_rom] @ Pico.mcd + ldr r3, [r3] @ Pico.mcd mov r0, r0, lsr #1 add r2, r3, #0x110000 add r2, r2, #0x002200 @@ -615,9 +615,9 @@ m_s68k_write8_pcm_ram: .macro m_s68k_write16_2M_decode - PIC_LDR(r2, ip, Pico) + PIC_LDR(r2, ip, Pico_mcd) eor r0, r0, #2 - ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd + ldr r2, [r2] @ Pico.mcd mov r0, r0, lsr #1 @ +4-6 <<16 add r2, r2, r3 @ map to our address .endm @@ -696,9 +696,9 @@ m_s68k_write16_regs: bne s68k_reg_write16 m_s68k_write16_regs_spec: @ special case - PIC_LDR(r2, r0, Pico) + PIC_LDR(r2, r0, Pico_mcd) mov r0, #0x110000 - ldr r2, [r2, #OFS_Pico_rom] @ Pico.mcd + ldr r2, [r2] @ Pico.mcd add r0, r0, #0x00000f strb r1, [r2, r0] @ if (a == 0xe) s68k_regs[0xf] = d; bx lr diff --git a/pico/memory.c b/pico/memory.c index ebadaf1f..33e2aa5d 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -66,16 +66,17 @@ void z80_map_set(uptr *map, u16 start_addr, u16 end_addr, void cpu68k_map_set(uptr *map, u32 start_addr, u32 end_addr, const void *func_or_mh, int is_func) { - xmap_set(map, M68K_MEM_SHIFT, start_addr, end_addr, func_or_mh, is_func); + xmap_set(map, M68K_MEM_SHIFT, start_addr, end_addr, func_or_mh, is_func & 1); #ifdef EMU_F68K // setup FAME fetchmap - if (!is_func) + if (!(is_func & 1)) { + M68K_CONTEXT *ctx = is_func & 2 ? &PicoCpuFS68k : &PicoCpuFM68k; int shiftout = 24 - FAMEC_FETCHBITS; int i = start_addr >> shiftout; uptr base = (uptr)func_or_mh - (i << shiftout); for (; i <= (end_addr >> shiftout); i++) - PicoCpuFM68k.Fetch[i] = base; + ctx->Fetch[i] = base; } #endif } @@ -997,18 +998,6 @@ PICO_INTERNAL void PicoMemSetup(void) PicoCpuFM68k.write_byte = (void *)m68k_write8; PicoCpuFM68k.write_word = (void *)m68k_write16; PicoCpuFM68k.write_long = (void *)m68k_write32; - - // setup FAME fetchmap - { - int i; - // by default, point everything to first 64k of ROM - for (i = 0; i < M68K_FETCHBANK1 * 0xe0 / 0x100; i++) - PicoCpuFM68k.Fetch[i] = (uptr)Pico.rom - (i<<(24-FAMEC_FETCHBITS)); - // now real ROM - for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < Pico.romsize; i++) - PicoCpuFM68k.Fetch[i] = (uptr)Pico.rom; - // RAM already set - } #endif #ifdef EMU_M68K m68k_mem_setup(); diff --git a/pico/pico.c b/pico/pico.c index 8be65a0b..f0128dae 100644 --- a/pico/pico.c +++ b/pico/pico.c @@ -146,7 +146,9 @@ PICO_INTERNAL void PicoDetectRegion(void) else if (support&1) hw=0x00; // Japan NTSC else hw=0x80; // USA - Pico.m.hardware=(unsigned char)(hw|0x20); // No disk attached + if (!(PicoIn.AHW & PAHW_MCD)) hw |= 0x20; // No disk attached + + Pico.m.hardware=(unsigned char)hw; Pico.m.pal=pal; } diff --git a/pico/pico.h b/pico/pico.h index e73c3456..40a1c665 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -289,9 +289,11 @@ enum cd_track_type CT_ISO = 1, /* 2048 B/sector */ CT_BIN = 2, /* 2352 B/sector */ // audio tracks - CT_MP3 = 3, - CT_WAV = 4, - CT_CHD = 5, + CT_AUDIO = 8, + CT_RAW = CT_AUDIO | 1, + CT_CHD = CT_AUDIO | 2, + CT_MP3 = CT_AUDIO | 3, + CT_WAV = CT_AUDIO | 4, }; typedef struct diff --git a/pico/pico_int.h b/pico/pico_int.h index 578fcb65..8c891c60 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -566,9 +566,6 @@ typedef struct char pcm_regs_dirty; } mcd_state; -// XXX: this will need to be reworked for cart+cd support. -#define Pico_mcd ((mcd_state *)Pico.rom) - // 32X #define P32XS_FM (1<<15) #define P32XS_nCART (1<< 8) @@ -773,6 +770,7 @@ int gfx_context_load(const unsigned char *state); void DmaSlowCell(u32 source, u32 a, int len, unsigned char inc); // cd/memory.c +extern unsigned int pcd_base_address; PICO_INTERNAL void PicoMemSetupCD(void); u32 PicoRead8_mcd_io(u32 a); u32 PicoRead16_mcd_io(u32 a); @@ -797,6 +795,8 @@ PICO_INTERNAL void PicoSyncZ80(unsigned int m68k_cycles_done); #define PCDS_IEN5 (1<<5) #define PCDS_IEN6 (1<<6) +extern mcd_state *Pico_mcd; + PICO_INTERNAL void PicoInitMCD(void); PICO_INTERNAL void PicoExitMCD(void); PICO_INTERNAL void PicoPowerMCD(void); @@ -811,6 +811,7 @@ enum pcd_event { PCD_EVENT_COUNT, }; extern unsigned int pcd_event_times[PCD_EVENT_COUNT]; + void pcd_event_schedule(unsigned int now, enum pcd_event event, int after); void pcd_event_schedule_s68k(enum pcd_event event, int after); void pcd_prepare_frame(void); diff --git a/pico/state.c b/pico/state.c index 07c4ff4a..9f91cd15 100644 --- a/pico/state.c +++ b/pico/state.c @@ -278,7 +278,7 @@ static int state_save(void *file) SekPackCpu(buff, 1); if (Pico_mcd->s68k_regs[3] & 4) // 1M mode? wram_1M_to_2M(Pico_mcd->word_ram2M); - memcpy(&Pico_mcd->m.hint_vector, Pico_mcd->bios + 0x72, + memcpy(&Pico_mcd->m.hint_vector, Pico.rom + 0x72, sizeof(Pico_mcd->m.hint_vector)); CHECKED_WRITE_BUFF(CHUNK_S68K, buff); diff --git a/pico/videoport.c b/pico/videoport.c index fa8a3329..c39a5605 100644 --- a/pico/videoport.c +++ b/pico/videoport.c @@ -533,13 +533,13 @@ static void DmaSlow(int len, u32 source) { u8 r3 = Pico_mcd->s68k_regs[3]; elprintf(EL_VDPDMA, "DmaSlow CD, r3=%02x", r3); - if (source < 0x20000) { // Bios area - base = (u16 *)Pico_mcd->bios; - } else if ((source & 0xfc0000) == 0x200000) { // Word Ram + if (source < Pico.romsize /*0x20000*/) { // Bios area + base = (u16 *)(Pico.rom + (source & 0xfe0000)); + } else if ((source & 0xfc0000) == pcd_base_address+0x200000) { // Word Ram if (!(r3 & 4)) { // 2M mode base = (u16 *)(Pico_mcd->word_ram2M + (source & 0x20000)); } else { - if (source < 0x220000) { // 1M mode + if ((source & 0xfe0000) < pcd_base_address+0x220000) { // 1M mode int bank = r3 & 1; base = (u16 *)(Pico_mcd->word_ram1M[bank]); } else { @@ -548,7 +548,7 @@ static void DmaSlow(int len, u32 source) } } source -= 2; - } else if ((source & 0xfe0000) == 0x020000) { // Prg Ram + } else if ((source & 0xfe0000) == pcd_base_address+0x020000) { // Prg Ram base = (u16 *)Pico_mcd->prg_ram_b[r3 >> 6]; source -= 2; // XXX: test } -- 2.39.5