Fix CD mount crash when drive is "empty"

This commit is contained in:
maron2000 2024-11-23 00:09:25 +09:00
parent 98f374ee09
commit e2617f390c
3 changed files with 23 additions and 7 deletions

View File

@ -430,7 +430,7 @@ void CMscdex::ReplaceDrive(CDROM_Interface* newCdrom, uint8_t subUnit) {
}
PhysPt CMscdex::GetDefaultBuffer(void) {
if (defaultBufSeg==0) {
if (defaultBufSeg==0 && !dos_kernel_disabled) {
uint16_t size = (2352*2+15)/16;
defaultBufSeg = DOS_GetMemory(size,"MSCDEX default buffer");
}
@ -1504,6 +1504,7 @@ uint8_t MSCDEX_GetSubUnit(char driveLetter)
bool MSCDEX_GetVolumeName(uint8_t subUnit, char* name)
{
if(dos_kernel_disabled) return false;
return mscdex->GetVolumeName(subUnit,name);
}

View File

@ -557,24 +557,38 @@ void MenuBrowseCDImage(char drive, int num) {
const char *lFilterPatterns[] = {"*.iso","*.cue","*.bin","*.chd","*.mdf","*.gog","*.ins","*.inst","*.ISO","*.CUE","*.BIN","*.CHD","*.MDF","*.GOG","*.INS","*.INST" };
const char *lFilterDescription = "CD image files (*.iso, *.cue, *.bin, *.chd, *.mdf, *.gog, *.ins, *.inst)";
lTheOpenFileName = tinyfd_openFileDialog("Select a CD image file","", sizeof(lFilterPatterns) / sizeof(lFilterPatterns[0]),lFilterPatterns,lFilterDescription,0);
bool isempty = std::string(Drives[drive - 'A']->GetInfo() + 9) == "empty";
if (lTheOpenFileName) {
isoDrive *cdrom = dynamic_cast<isoDrive*>(Drives[drive-'A']);
DOS_Drive *newDrive = NULL;
int error = -1;
uint8_t mediaid = 0xF8;
if (cdrom && dos_kernel_disabled) {
cdrom->setFileName(lTheOpenFileName);
if(isempty) {
newDrive = new isoDrive(drive, lTheOpenFileName, mediaid, error, options);
if(error) {
delete newDrive;
systemmessagebox("Error", "Could not mount the selected CD image.", "ok", "error", 1);
chdir(Temp_CurrentDir);
return;
}
delete cdrom;
cdrom = dynamic_cast<isoDrive*>(newDrive);
Drives[drive - 'A'] = cdrom;
}
} else {
uint8_t mediaid = 0xF8;
int error = -1;
newDrive = new isoDrive(drive, lTheOpenFileName, mediaid, error, options);
if (error) {
delete newDrive;
systemmessagebox("Error","Could not mount the selected CD image.","ok","error", 1);
chdir( Temp_CurrentDir );
return;
}
cdrom = dynamic_cast<isoDrive*>(newDrive);
Drives[drive - 'A'] = cdrom;
}
if (cdrom) DriveManager::ChangeDisk(drive-'A', cdrom);
if ((!isempty || !dos_kernel_disabled) && cdrom) DriveManager::ChangeDisk(drive-'A', cdrom);
}
chdir( Temp_CurrentDir );
#endif

View File

@ -1737,6 +1737,7 @@ bool isoDrive::ReadCachedSector(uint8_t** buffer, const uint32_t sector) {
}
inline bool isoDrive :: readSector(uint8_t *buffer, uint32_t sector) const {
if(CDROM_Interface_Image::images[subUnit] == nullptr) return false;
return CDROM_Interface_Image::images[subUnit]->ReadSector(buffer, false, sector);
}