Permalink
Browse files

Merge pull request #613 from Shane32/shane_bug_fixes

Misc bug fixes
  • Loading branch information...
joncampbell123 committed Mar 13, 2018
2 parents 1954621 + f595f13 commit ff32a761733f562346e4e2c60ddae3c6859e5eed
Showing with 48 additions and 36 deletions.
  1. +31 −17 src/dos/dos_programs.cpp
  2. +1 −1 src/hardware/ide.cpp
  3. +9 −4 src/ints/bios_disk.cpp
  4. +7 −14 src/ints/bios_memdisk.cpp
View
@@ -2425,7 +2425,7 @@ class IMGMOUNT : public Program {
return;
}
drive=temp_line[0];
if ((drive<'0') || (drive>3+'0')) {
if ((drive<'0') || (drive>=MAX_DISK_IMAGES+'0')) {
WriteOut_NoParsing(MSG_Get("PROGRAM_IMGMOUNT_SPECIFY2"));
return;
}
@@ -2485,8 +2485,12 @@ class IMGMOUNT : public Program {
if (newImage == NULL) return;
}
AttachToBiosAndIde(newImage, drive - '0', ide_index, ide_slave);
WriteOut(MSG_Get("PROGRAM_IMGMOUNT_MOUNT_NUMBER"), drive - '0', temp_line.c_str());
if (AttachToBiosAndIde(newImage, drive - '0', ide_index, ide_slave)) {
WriteOut(MSG_Get("PROGRAM_IMGMOUNT_MOUNT_NUMBER"), drive - '0', temp_line.c_str());
}
else {
WriteOut("Invalid mount number");
}
}
else {
WriteOut("Invalid fstype\n");
@@ -2633,7 +2637,7 @@ class IMGMOUNT : public Program {
}
/* drive must not exist (as a hard drive) */
if (imageDiskList[el_torito_cd_drive - 'C'] != NULL) {
if (imageDiskList[el_torito_cd_drive - 'A'] != NULL) {
WriteOut("-el-torito CD-ROM drive specified already exists as a non-CD-ROM device\n");
return false;
}
@@ -2804,6 +2808,8 @@ class IMGMOUNT : public Program {
AddToDriveManager(drive, newDrive, mediaid);
AttachToBios(newImage, driveIndex);
WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_2"), drive, "el torito floppy");
return true;
}
@@ -2879,11 +2885,11 @@ class IMGMOUNT : public Program {
if (imgDisks.size() == 1) {
imageDisk* image = ((fatDrive*)imgDisks[0])->loadedDisk;
if (image->hardDrive) {
if (imageDiskList[2] == NULL) {
AttachToBiosAndIde(image, 2, ide_index, ide_slave);
}
else if (imageDiskList[3] == NULL) {
AttachToBiosAndIde(image, 3, ide_index, ide_slave);
for (int index = 2; index < MAX_DISK_IMAGES; index++) {
if (imageDiskList[index] == NULL) {
AttachToBiosAndIde(image, index, ide_index, ide_slave);
break;
}
}
}
else {
@@ -2894,8 +2900,8 @@ class IMGMOUNT : public Program {
return true;
}
void AttachToBios(imageDisk* image, const unsigned char bios_drive_index) {
if (bios_drive_index >= MAX_DISK_IMAGES) return;
bool AttachToBios(imageDisk* image, const unsigned char bios_drive_index) {
if (bios_drive_index >= MAX_DISK_IMAGES) return false;
if (imageDiskList[bios_drive_index] != NULL) {
/* Notify IDE ATA emulation if a drive is already there */
if (bios_drive_index >= 2) IDE_Hard_Disk_Detach(bios_drive_index);
@@ -2906,15 +2912,18 @@ class IMGMOUNT : public Program {
// let FDC know if we mounted a floppy
if (bios_drive_index <= 1) FDC_AssignINT13Disk(bios_drive_index);
return true;
}
void AttachToBiosAndIde(imageDisk* image, const unsigned char bios_drive_index, const unsigned char ide_index, const bool ide_slave) {
AttachToBios(image, bios_drive_index);
bool AttachToBiosAndIde(imageDisk* image, const unsigned char bios_drive_index, const unsigned char ide_index, const bool ide_slave) {
if (!AttachToBios(image, bios_drive_index)) return false;
//if hard drive image, and if ide controller is specified
if (bios_drive_index == 2 || bios_drive_index == 3) {
if (bios_drive_index >= 2 || bios_drive_index < MAX_DISK_IMAGES) {
if (ide_index >= 0) IDE_Hard_Disk_Attach(ide_index, ide_slave, bios_drive_index);
updateDPT();
}
return true;
}
void DetachFromBios(imageDisk* image) {
@@ -3140,6 +3149,10 @@ class IMGMOUNT : public Program {
if (sizes[0] == 0) sizes[0] = 512;
FILE *newDisk = fopen64(temp_line.c_str(), "rb+");
if (!newDisk) {
WriteOut("Unable to open '%s'\n", temp_line.c_str());
return NULL;
}
QCow2Image::QCow2Header qcow2_header = QCow2Image::read_header(newDisk);
@@ -3722,16 +3735,16 @@ void DOS_SetupPrograms(void) {
MSG_Add("PROGRAM_IMGMOUNT_MULTIPLE_NON_CUEISO_FILES", "Using multiple files is only supported for cue/iso images.\n");
MSG_Add("PROGRAM_IMGMOUNT_HELP",
"Mounts hard drive and optical disc images.\n\n"
"Mounts hard drive and optical disc images.\n"
"IMGMOUNT drive filename [-t floppy] [-fs fat] [-size ss,s,h,c]\n"
"IMGMOUNT drive filename [-t hdd] [-fs fat] [-size ss,s,h,c] [-ide 1m|1s|2m|2s]\n"
"IMGMOUNT driveLocation filename [-t hdd] -fs none [-size ss,s,h,c]\n"
"IMGMOUNT driveLoc filename [-t hdd] -fs none [-size ss,s,h,c] [-reservecyl #]\n"
"IMGMOUNT drive filename [-t iso] [-fs iso]\n"
"IMGMOUNT drive -t floppy -el-torito cdDrive\n"
"IMGMOUNT drive -t ram -size driveSize\n"
"IMGMOUNT -u drive|driveLocation\n"
" drive Drive letter to mount the image at\n"
" driveLocation Location to mount drive, where 2 = Master and 3 = Slave\n"
" driveLoc Location to mount drive, where 2 = Master and 3 = Slave\n"
" filename Filename of the image to mount\n"
" -t iso Image type is optical disc iso or cue / bin image\n"
" -t floppy Image type is floppy\n"
@@ -3740,6 +3753,7 @@ void DOS_SetupPrograms(void) {
" -fs iso File system is ISO 9660\n"
" -fs fat File system is FAT; FAT12 and FAT16 are supported\n"
" -fs none Do not detect file system\n"
" -reservecyl # Report # number of cylinders less than actual in BIOS\n"
" -ide 1m|1s|2m|2s Specifies the controller to mount drive\n"
" -size ss,s,h,c Specify the geometry: Sector size,Sectors,Heads,Cylinders\n"
" -size driveSize Specify the drive size in KB\n"
View
@@ -2119,7 +2119,7 @@ void IDE_Auto(signed char &index,bool &slave) {
slave = false;
for (i=0;i < MAX_IDE_CONTROLLERS;i++) {
if ((c=idecontroller[i]) == NULL) continue;
index = (signed char)(i >> 1);
index = (signed char)i;
if (c->device[0] == NULL) {
slave = false;
View
@@ -731,8 +731,9 @@ static Bitu INT13_DiskHandler(void) {
last_status = 0x00;
if (reg_dl&0x80) { // harddisks
reg_dl = 0;
if(imageDiskList[2] != NULL) reg_dl++;
if(imageDiskList[3] != NULL) reg_dl++;
for (int index = 2; index < MAX_DISK_IMAGES; index++) {
if (imageDiskList[index] != NULL) reg_dl++;
}
} else { // floppy disks
reg_dl = 0;
if(imageDiskList[0] != NULL) reg_dl++;
@@ -909,10 +910,14 @@ void BIOS_SetupDisks(void) {
RealSetVec(0x13,CALLBACK_RealPointer(call_int13));
/* FIXME: I see a potential problem here: We're just zeroing out the array. Didn't I rewrite disk images with refcounting? --J.C. */
for(i=0;i<MAX_DISK_IMAGES;i++)
for (i = 0; i < MAX_DISK_IMAGES; i++) {
if (imageDiskList[i]) imageDiskList[i]->Release();
imageDiskList[i] = NULL;
for(i=0;i<MAX_SWAPPABLE_DISKS;i++)
}
for (i = 0; i < MAX_SWAPPABLE_DISKS; i++) {
if (diskSwap[i]) diskSwap[i]->Release();
diskSwap[i] = NULL;
}
/* FIXME: Um... these aren't callbacks. Why are they allocated as callbacks? We have ROM general allocation now. */
diskparm0 = CALLBACK_Allocate();
View
@@ -211,6 +211,7 @@ void imageDiskMemory::init(diskGeo diskParams, bool isHardDrive, imageDisk* unde
memset((void*)ChunkMap, 0, total_chunks * sizeof(Bit8u*));
//set internal variables
this->diskname = "ram drive";
this->heads = diskParams.headscyl;
this->cylinders = diskParams.cylcount;
this->sectors = diskParams.secttrack;
@@ -407,18 +408,10 @@ Bit8u imageDiskMemory::Format() {
return 0x05;
}
if (this->hardDrive) {
LOG_MSG("Formatting FAT%u hard drive C/H/S %u/%u/%u with %u bytes/sector, %u root entries, %u-byte clusters, media id 0x%X\n",
(unsigned int)(isFat16 ? 16 : 12),
(unsigned int)reported_cylinders, (unsigned int)this->heads, (unsigned int)this->sectors, (unsigned int)this->sector_size,
(unsigned int)root_ent, (unsigned int)(sectors_per_cluster * this->sector_size), (unsigned int)mediaID);
}
else {
LOG_MSG("Formatting FAT%u floppy drive C/H/S %u/%u/%u with %u bytes/sector, %u root entries, %u-byte clusters, media id 0x%X\n",
(unsigned int)(isFat16 ? 16 : 12),
(unsigned int)reported_cylinders, (unsigned int)this->heads, (unsigned int)this->sectors, (unsigned int)this->sector_size,
(unsigned int)root_ent, (unsigned int)(sectors_per_cluster * this->sector_size), (unsigned int)mediaID);
}
LOG_MSG("Formatting FAT%u %s drive C/H/S %u/%u/%u with %u bytes/sector, %u root entries, %u-byte clusters, media id 0x%X\n",
(unsigned int)(isFat16 ? 16 : 12), this->hardDrive ? "hard" : "floppy",
(unsigned int)reported_cylinders, (unsigned int)this->heads, (unsigned int)this->sectors, (unsigned int)this->sector_size,
(unsigned int)root_ent, (unsigned int)(sectors_per_cluster * this->sector_size), (unsigned int)mediaID);
//write MBR if applicable
Bit8u sbuf[512];
@@ -545,8 +538,8 @@ bool imageDiskMemory::CalculateFAT(Bit32u partitionStartingSector, Bit32u partit
//set the number of root sectors
*rootSectors = rootEntries * 32 / 512;
//make sure there is a minimum number of sectors available
// minimum sectors = root sectors + 1 for boot sector + 1 for fat #1 + 1 for fat #2 + 1 for data sector + add 7 for hard drives due to allow for 4k alignment
if (partitionLength < (*rootSectors + 4 + (isHardDrive ? 7 : 0))) {
// minimum sectors = root sectors + 1 for boot sector + 1 for fat #1 + 1 for fat #2 + 1 cluster for data + add 7 for hard drives due to allow for 4k alignment
if (partitionLength < (*rootSectors + 3 + *sectorsPerCluster + (isHardDrive ? 7 : 0))) {
LOG_MSG("Partition too small to format\n");
return false;
}

0 comments on commit ff32a76

Please sign in to comment.