From f4ab2647f2c0b6eeb4fd3c391fb6274d038b7bbd Mon Sep 17 00:00:00 2001 From: kub Date: Sat, 28 Sep 2024 09:19:40 +0200 Subject: [PATCH] mcd, fix regression when reloading --- README.md | 6 ++++++ pico/cd/mcd.c | 7 ++++++- pico/media.c | 28 +++++++++++++++------------- platform/base_readme.txt | 7 ++++--- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 527aa29b..d188ab24 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,12 @@ At present, most development activity occurs in [irixxxx's fork](https://github.com/irixxxx/picodrive); [notaz's repo](https://github.com/notaz/picodrive) is updated less frequently. +### Using MSU, MD+/32X+, and Mode 1 on Sega/Mega CD + +PicoDrive supports using CD audio enhanced cartridge games in all 3 formats. +To start an enhanced cartridge, the "cue" or "chd" file of the audio CD must be +selected. Further instructions can be found in `platform/base_readme.txt`. + ### Sega Pico and Storyware Pages PicoDrive can use Storyware pages and pad overlays in png format in the same diff --git a/pico/cd/mcd.c b/pico/cd/mcd.c index 178bac3d..c0d9192d 100644 --- a/pico/cd/mcd.c +++ b/pico/cd/mcd.c @@ -24,8 +24,13 @@ PICO_INTERNAL void PicoCreateMCD(unsigned char *bios_data, int bios_size) { if (!Pico_mcd) { Pico_mcd = plat_mmap(0x05000000, sizeof(mcd_state), 0, 0); - memset(Pico_mcd, 0, sizeof(mcd_state)); + if (Pico_mcd == NULL) { + elprintf(EL_STATUS, "OOM"); + return; + } } + memset(Pico_mcd, 0, sizeof(mcd_state)); + if (bios_data && bios_size > 0) { if (bios_size > sizeof(Pico_mcd->bios)) bios_size = sizeof(Pico_mcd->bios); diff --git a/pico/media.c b/pico/media.c index c02cea1f..ccad09af 100644 --- a/pico/media.c +++ b/pico/media.c @@ -303,21 +303,23 @@ enum media_type_e PicoLoadMedia(const char *filename, goto out; } - ret = PicoCartLoad(rom_file, NULL, 0, &rom_data, &rom_size, 0); - if (ret != 0) { - lprintf("reading BIOS failed\n"); - media_type = PM_ERROR; - goto out; + if (rom_file != NULL) { + ret = PicoCartLoad(rom_file, NULL, 0, &rom_data, &rom_size, 0); + if (ret != 0) { + lprintf("reading BIOS failed\n"); + media_type = PM_ERROR; + goto out; + } + + // copy BIOS and close file + PicoCreateMCD(rom_data, rom_size); + + PicoCartUnload(); + pm_close(rom_file); + rom_file = NULL; + rom_size = 0; } - // copy BIOS and close file - PicoCreateMCD(rom_data, rom_size); - - PicoCartUnload(); - pm_close(rom_file); - rom_file = NULL; - rom_size = 0; - // if there is an MSU ROM, it's name is now in rom_fname for loading PicoIn.AHW |= PAHW_MCD; } diff --git a/platform/base_readme.txt b/platform/base_readme.txt index 51dcb98a..dce94724 100644 --- a/platform/base_readme.txt +++ b/platform/base_readme.txt @@ -34,8 +34,9 @@ Just copy the .pnd to /pandora/menu or /pandora/desktop. Then load a ROM and enjoy! Cartridge ROMs can be in various common formats and can be zipped, one ROM file per zip. Certain extensions are used to detect the console the ROM is for (.sg, .sc, .sms, .gg, .smd, .md, .gen, .32x, .pco). -For MSU games, load the .cue file and make sure the cartridge ROM has the same -name and is in the same directory. +For MSU or MD+ games, load the .cue file and make sure the cartridge ROM has the +same name and is in the same directory. MD+ use extensions in the .cue file, +hence don't try to convert it to any other format. Sega/Mega CD images can be in CHD, CUE+BIN/ISO or ISO/CSO+MP3/WAV format (read below for more details). @@ -48,7 +49,7 @@ option. How to run Sega/Mega CD games ----------------------------- -To play any non-MSU CD game you need BIOS files. These files must be copied to +To play any non-MSU/MD+ CD game you need BIOS files. These must be copied to #ifdef PANDORA /pandora/appdata/picodrive/ directory (if you run PicoDrive once it will create that directory for you). -- 2.39.5