Skip to content

Commit

Permalink
Empty CD-ROM drive support for IMGMOUNT
Browse files Browse the repository at this point in the history
  • Loading branch information
joncampbell123 committed Feb 29, 2024
1 parent 1a53d75 commit 9f88c26
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Next:
- Add "empty drive" CD-RIM image type "IMGMOUNT e: -t iso -empty" as a way
to emulate an empty CD-ROM drive with no disc in the drive. (joncampbell123).
- Add "empty drive" floppy image type "IMGMOUNT 0 -t floppy -fs none -empty"
as a way to emulate a floppy drive with no disk in the drive. (joncampbell123).
- Video debug overlay: Fix mouse integration misalignment when the video
Expand Down
10 changes: 7 additions & 3 deletions src/dos/dos_mscdex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,13 @@ int CMscdex::AddDrive(uint16_t _drive, char* physicalPath, uint8_t& subUnit)
break;
case 0x02: // fake cdrom interface (directories)
cdrom[numDrives] = new CDROM_Interface_Fake;
LOG(LOG_MISC,LOG_NORMAL)("MSCDEX: Mounting directory as cdrom: %s",physicalPath);
LOG(LOG_MISC,LOG_NORMAL)("MSCDEX: You won't have full MSCDEX support !");
result = 5;
if (!strcmp(physicalPath,"empty")) {
}
else {
LOG(LOG_MISC,LOG_NORMAL)("MSCDEX: Mounting directory as cdrom: %s",physicalPath);
LOG(LOG_MISC,LOG_NORMAL)("MSCDEX: You won't have full MSCDEX support !");
result = 5;
}
break;
default : // weird result
return 6;
Expand Down
34 changes: 24 additions & 10 deletions src/dos/dos_programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5197,11 +5197,14 @@ class IMGMOUNT : public Program {
}
else if (empty_drive) {
if (paths.size() != 0) {
WriteOut("Image list cannot be specified with -empty");
WriteOut("Image list cannot be specified with -empty\n");
return;
}
if (fstype != "none") {
WriteOut("-empty must be combined with -fs none");
if (type == "iso" && fstype == "iso") {
/* OK */
}
else if (fstype != "none") {
WriteOut("-empty must be combined with -fs none\n");
return;
}
}
Expand Down Expand Up @@ -5260,7 +5263,7 @@ class IMGMOUNT : public Program {
return;
}
//supports multiple files
if (!MountIso(drive, paths, ide_index, ide_slave)) return;
if (!MountIso(drive, paths, ide_index, ide_slave, empty_drive)) return;
if (removed && !exist && i_drive < DOS_DRIVES && i_drive >= 0 && Drives[i_drive]) DOS_SetDefaultDrive(i_drive);
} else if (fstype=="none") {
unsigned char driveIndex = drive - '0';
Expand Down Expand Up @@ -6408,7 +6411,7 @@ class IMGMOUNT : public Program {
return false;
}

bool MountIso(const char drive, const std::vector<std::string> &paths, const signed char ide_index, const bool ide_slave) {
bool MountIso(const char drive, const std::vector<std::string> &paths, const signed char ide_index, const bool ide_slave, const bool empty_drive) {
//mount cdrom
if (Drives[drive - 'A']) {
WriteOut(MSG_Get("PROGRAM_IMGMOUNT_ALREADY_MOUNTED"));
Expand Down Expand Up @@ -6443,6 +6446,12 @@ class IMGMOUNT : public Program {
return false;
}
}
if (empty_drive) {
std::vector<std::string> options2 = options;
int error = -1;
options2.push_back("empty");
isoDisks.push_back(new isoDrive(drive, "empty", mediaid, error, options2));
}
// Update DriveManager
for (ct = 0; ct < isoDisks.size(); ct++) {
DriveManager::AppendDisk(drive - 'A', isoDisks[ct]);
Expand All @@ -6458,12 +6467,17 @@ class IMGMOUNT : public Program {

// Print status message (success)
if (!qmount) WriteOut(MSG_Get("MSCDEX_SUCCESS"));
std::string tmp(wpcolon&&paths[0].length()>1&&paths[0].c_str()[0]==':'?paths[0].substr(1):paths[0]);
for (i = 1; i < paths.size(); i++) {
tmp += "; " + (wpcolon&&paths[i].length()>1&&paths[i].c_str()[0]==':'?paths[i].substr(1):paths[i]);
if (!paths.empty()) {
std::string tmp(wpcolon&&paths[0].length()>1&&paths[0].c_str()[0]==':'?paths[0].substr(1):paths[0]);
for (i = 1; i < paths.size(); i++) {
tmp += "; " + (wpcolon&&paths[i].length()>1&&paths[i].c_str()[0]==':'?paths[i].substr(1):paths[i]);
}
lastmount = drive;
if (!qmount) WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_2"), drive, tmp.c_str());
}
else {
lastmount = drive;
}
lastmount = drive;
if (!qmount) WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_2"), drive, tmp.c_str());
return true;
}

Expand Down
49 changes: 38 additions & 11 deletions src/dos/drive_iso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,10 @@ isoDrive::isoDrive(char driveLetter, const char* fileName, uint8_t mediaid, int&
if (value == "1" || value == "") enable_udf = true; // "-o udf" or "-o udf=1"
else if (value == "0") enable_udf = false;
}
else if (name == "empty") {
empty_drive = true;
fileName = "empty";
}
}

if (!CDROM_Interface_Image::images_init) {
Expand All @@ -1015,18 +1019,27 @@ isoDrive::isoDrive(char driveLetter, const char* fileName, uint8_t mediaid, int&
memset(&rootEntry, 0, sizeof(isoDirEntry));

safe_strncpy(this->fileName, fileName, CROSS_LEN);
LOG_MSG("UPD");
error = UpdateMscdex(driveLetter, fileName, subUnit);
LOG_MSG("Error %u",error);

if (!error) {
if (loadImage()) {
if (empty_drive) {
LOG_MSG("Empty ISO");
strcpy(info, "isoDrive ");
strcat(info, "empty");
this->driveLetter = driveLetter;
this->mediaid = mediaid;
char buffer[32] = { 0 };
Set_Label(buffer,discLabel,true);
} else if (loadImage()) {
strcpy(info, "isoDrive ");
strcat(info, fileName);
this->driveLetter = driveLetter;
this->mediaid = mediaid;
char buffer[32] = { 0 };
if (!MSCDEX_GetVolumeName(subUnit, buffer)) strcpy(buffer, "");
Set_Label(buffer,discLabel,true);

} else if (CDROM_Interface_Image::images[subUnit]->HasDataTrack() == false && CDROM_Interface_Image::images[subUnit]->HasAudioTrack() == true) { //Audio only cdrom
strcpy(info, "isoDrive ");
strcat(info, fileName);
Expand All @@ -1050,16 +1063,30 @@ void isoDrive::setFileName(const char* fileName) {
int isoDrive::UpdateMscdex(char driveLetter, const char* path, uint8_t& subUnit) {
if (MSCDEX_HasDrive(driveLetter)) {
subUnit = MSCDEX_GetSubUnit(driveLetter);
CDROM_Interface_Image* oldCdrom = CDROM_Interface_Image::images[subUnit];
CDROM_Interface* cdrom = new CDROM_Interface_Image(subUnit);
char pathCopy[CROSS_LEN];
safe_strncpy(pathCopy, path, CROSS_LEN);
if (!cdrom->SetDevice(pathCopy, 0)) {
CDROM_Interface_Image::images[subUnit] = oldCdrom;
delete cdrom;
return 3;
if (empty_drive) {
CDROM_Interface_Image* oldCdrom = CDROM_Interface_Image::images[subUnit];
CDROM_Interface* cdrom = new CDROM_Interface_Fake();
char pathCopy[CROSS_LEN];
safe_strncpy(pathCopy, path, CROSS_LEN);
if (!cdrom->SetDevice(pathCopy, 0)) {
CDROM_Interface_Image::images[subUnit] = oldCdrom;
delete cdrom;
return 3;
}
MSCDEX_ReplaceDrive(cdrom, subUnit);
}
else {
CDROM_Interface_Image* oldCdrom = CDROM_Interface_Image::images[subUnit];
CDROM_Interface* cdrom = new CDROM_Interface_Image(subUnit);
char pathCopy[CROSS_LEN];
safe_strncpy(pathCopy, path, CROSS_LEN);
if (!cdrom->SetDevice(pathCopy, 0)) {
CDROM_Interface_Image::images[subUnit] = oldCdrom;
delete cdrom;
return 3;
}
MSCDEX_ReplaceDrive(cdrom, subUnit);
}
MSCDEX_ReplaceDrive(cdrom, subUnit);
return 0;
} else {
return MSCDEX_AddDrive(driveLetter, path, subUnit);
Expand Down
1 change: 1 addition & 0 deletions src/dos/drives.h
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ class isoDrive : public DOS_Drive {
bool dataCD = false;
bool is_udf = false;
bool is_joliet = false;
bool empty_drive = false;
bool is_rock_ridge = false; // NTS: Rock Ridge and System Use Sharing Protocol was detected in the root directory
bool enable_joliet = false; // NTS: "Joliet" is just ISO 9660 with filenames encoded as UTF-16 Unicode. One of the few times Microsoft extended something yet kept it simple --J.C.
bool enable_rock_ridge = false; // NTS: Windows 95/98 are unlikely to support Rock Ridge, therefore this is off by default. If they do support RR, let me know --J.C.
Expand Down

0 comments on commit 9f88c26

Please sign in to comment.