Skip to content

Commit

Permalink
Add support for uncompressed CHD version 5 CD images (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
schellingb committed Nov 17, 2023
1 parent 9b1f577 commit 2999708
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 15 deletions.
8 changes: 4 additions & 4 deletions dosbox_pure_libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ typedef void(*dbp_intercept_gfx_func)(DBP_Buffer& buf, void* data);
static dbp_intercept_gfx_func dbp_intercept_gfx;

// DOSBOX DISC MANAGEMENT
struct DBP_Image { std::string path; bool mounted = false, remount = false, image_disk = false; char drive; };
struct DBP_Image { std::string path; bool mounted = false, remount = false, image_disk = false; char drive; bool IsCD() { size_t n = path.size(); const char* ext = (n > 3 ? &*(path.end()-3) : NULL); return (ext && !((ext[1]|0x20) == 'm' || (ext[0]|0x20) == 'v')); } };
static std::vector<DBP_Image> dbp_images;
static std::vector<std::string> dbp_osimages, dbp_shellzips;
static StringToPointerHashMap<void> dbp_vdisk_filter;
Expand Down Expand Up @@ -801,7 +801,7 @@ static DOS_Drive* DBP_Mount(unsigned image_index = 0, bool unmount_existing = fa
if (!letter) letter = (disk->hardDrive ? 'D' : 'A');
media_byte = (disk->hardDrive ? 0xF8 : (disk->active ? disk->GetBiosType() : 0));
}
else if (!strcasecmp(ext, "ISO") || !strcasecmp(ext, "CUE") || !strcasecmp(ext, "INS"))
else if (!strcasecmp(ext, "ISO") || !strcasecmp(ext, "CHD") || !strcasecmp(ext, "CUE") || !strcasecmp(ext, "INS"))
{
MOUNT_ISO:
if (letter < 'D') letter = 'D';
Expand Down Expand Up @@ -2072,7 +2072,7 @@ void retro_get_system_info(struct retro_system_info *info) // #1
info->library_version = "0.9.7";
info->need_fullpath = true;
info->block_extract = true;
info->valid_extensions = "zip|dosz|exe|com|bat|iso|cue|ins|img|ima|vhd|jrc|tc|m3u|m3u8|conf";
info->valid_extensions = "zip|dosz|exe|com|bat|iso|chd|cue|ins|img|ima|vhd|jrc|tc|m3u|m3u8|conf";
}

void retro_set_environment(retro_environment_t cb) //#2
Expand Down Expand Up @@ -2850,7 +2850,7 @@ static void init_dosbox(bool firsttime, bool forcemenu = false, void(*loadcfg)(c
const char* fext = (data == ('C'-'A') ? strrchr(fname, '.') : NULL);
if (fext++)
{
bool isFS = (!strcmp(fext, "ISO") || !strcmp(fext, "CUE") || !strcmp(fext, "INS") || !strcmp(fext, "IMG") || !strcmp(fext, "IMA") || !strcmp(fext, "VHD") || !strcmp(fext, "JRC") || !strcmp(fext, "TC"));
bool isFS = (!strcmp(fext, "ISO") || !strcmp(fext, "CHD") || !strcmp(fext, "CUE") || !strcmp(fext, "INS") || !strcmp(fext, "IMG") || !strcmp(fext, "IMA") || !strcmp(fext, "VHD") || !strcmp(fext, "JRC") || !strcmp(fext, "TC"));
if (isFS && !strncmp(fext, "IM", 2) && (size < 163840 || (size <= 2949120 && (size % 20480) && (size % 20480) != 1024))) isFS = false; //validate floppy images
if (isFS && !strcmp(fext, "INS"))
{
Expand Down
2 changes: 1 addition & 1 deletion dosbox_pure_libretro.info
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Software Information
display_name = "DOS (DOSBox-Pure)"
authors = "DOSBox Team|Psyraven"
supported_extensions = "zip|dosz|exe|com|bat|iso|cue|ins|img|ima|vhd|jrc|tc|m3u|m3u8|conf"
supported_extensions = "zip|dosz|exe|com|bat|iso|chd|cue|ins|img|ima|vhd|jrc|tc|m3u|m3u8|conf"
corename = "DOSBox-pure"
categories = "Emulator"
license = "GPLv2"
Expand Down
6 changes: 3 additions & 3 deletions dosbox_pure_osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,13 @@ struct DBP_PureMenuState : DBP_MenuState
void RefreshFileList(bool initial_scan)
{
list.clear();
exe_count = fs_count = 0; int iso_count = 0, img_count = 0; bool bootimg = false;
exe_count = fs_count = 0; int cd_count = 0, hd_count = 0; bool bootimg = false;

for (DBP_Image& image : dbp_images)
{
list.emplace_back(IT_MOUNT, (Bit16s)(&image - &dbp_images[0]));
DBP_GetImageLabel(image, list.back().str);
((list.back().str[list.back().str.size()-2]|0x25) == 'm' ? img_count : iso_count)++; //0x25 recognizes IMG/IMA/VHD but not ISO/CUE/INS
(image.IsCD() ? cd_count : hd_count)++;
fs_count++;
if (image.image_disk) bootimg = true;
}
Expand All @@ -986,7 +986,7 @@ struct DBP_PureMenuState : DBP_MenuState
list.emplace_back(IT_SHELLLIST, 0, "[ Run System Shell ]");
fs_count++;
}
if (!dbp_strict_mode && ((Drives['D'-'A'] && dynamic_cast<isoDrive*>(Drives['D'-'A']) && ((isoDrive*)(Drives['D'-'A']))->CheckBootDiskImage()) || (img_count == 1 && iso_count == 1)))
if (!dbp_strict_mode && ((Drives['D'-'A'] && dynamic_cast<isoDrive*>(Drives['D'-'A']) && ((isoDrive*)(Drives['D'-'A']))->CheckBootDiskImage()) || (hd_count == 1 && cd_count == 1)))
{
list.emplace_back(IT_INSTALLOSSIZE, 0, "[ Boot and Install New Operating System ]");
fs_count++;
Expand Down
12 changes: 6 additions & 6 deletions dosbox_pure_run.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ struct DBP_Run
return true;
}

static bool HaveISO()
static bool HaveCDImage()
{
for (DBP_Image& i : dbp_images) if ((i.path[i.path.size()-2]|0x25) != 'm') return true; //0x25 recognizes IMG/IMA/VHD but not ISO/CUE/INS
for (DBP_Image& i : dbp_images) if (i.IsCD()) return true;
return false;
}

Expand Down Expand Up @@ -161,7 +161,7 @@ struct DBP_Run

// If there is no mounted hard disk image but a D: drive, setup the CDROM IDE controller
if (!imageDiskList['C'-'A'] && Drives['D'-'A'])
IDE_SetupControllers(BatchFileBoot::HaveISO() ? 'D' : 0);
IDE_SetupControllers(BatchFileBoot::HaveCDImage() ? 'D' : 0);

// Install the NE2000 network card
NET_SetupEthernet();
Expand Down Expand Up @@ -214,11 +214,11 @@ struct DBP_Run
dbp_osimages.emplace_back(filename);
}

const bool have_iso = BatchFileBoot::HaveISO();
const bool have_cd_image = BatchFileBoot::HaveCDImage();
if (!path.empty())
{
// When booting an external disk image as C:, use whatever is C: in DOSBox DOS as the second hard disk in the booted OS (it being E: in Drives[] doesn't matter)
char newC = ((have_iso || DBP_IsMounted('D')) ? 'E' : 'D'); // alternative would be to do DBP_Remount('D', 'E'); and always use 'D'
char newC = ((have_cd_image || DBP_IsMounted('D')) ? 'E' : 'D'); // alternative would be to do DBP_Remount('D', 'E'); and always use 'D'
if (imageDiskList['C'-'A'])
imageDiskList[newC-'A'] = imageDiskList['C'-'A'];
else if (!BatchFileBoot::MountOSIMG(newC, (dbp_content_path + ".img").c_str(), "D: drive image", true, false) && Drives['C'-'A'])
Expand Down Expand Up @@ -256,7 +256,7 @@ struct DBP_Run
}

// Setup IDE controllers for the hard drives and one CDROM drive (if any CDROM image is mounted)
IDE_SetupControllers(have_iso ? 'D' : 0);
IDE_SetupControllers(have_cd_image ? 'D' : 0);

// Install the NE2000 network card
NET_SetupEthernet();
Expand Down
1 change: 1 addition & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#define C_DBP_HAVE_FPATH_NOCASE
#define C_DBP_RELIABLE_MEMORY_ADDRESSES
#define C_DBP_SUPPORT_CDROM_MOUNT_DOSFILE
#define C_DBP_SUPPORT_CDROM_CHD_IMAGE
#define C_DBP_SUPPORT_DISK_MOUNT_DOSFILE
#define C_DBP_SUPPORT_DISK_FAT_EMULATOR
#define C_DBP_SUPPORT_MIDI_TSF
Expand Down
3 changes: 3 additions & 0 deletions src/dos/cdrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ static struct imagePlayer {
bool GetCueFrame(int &frames, std::istream &in);
bool GetCueString(std::string &str, std::istream &in);
bool AddTrack(Track &curr, int &shift, int prestart, int &totalPregap, int currPregap);
#ifdef C_DBP_SUPPORT_CDROM_CHD_IMAGE
bool LoadChdFile(char *filename);
#endif

static int refCount;
std::vector<Track> tracks;
Expand Down
Loading

0 comments on commit 2999708

Please sign in to comment.