From c81269eebe7528ca50d9a9d9175ddf99d7e871cb Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Wed, 18 Dec 2019 21:34:38 +0100 Subject: [PATCH] Remove extern global variable from bios_disk.h This way interface of swapInDisks function is cleaner and we avoid a warning when comparing (previously) signed swap position with an unsigned array size or index. Also, add some documentation to swapInDisks function. --- include/bios_disk.h | 14 ++++++++++++-- src/dos/dos_programs.cpp | 4 +--- src/ints/bios_disk.cpp | 15 ++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/include/bios_disk.h b/include/bios_disk.h index a13aa344..562b0dc6 100644 --- a/include/bios_disk.h +++ b/include/bios_disk.h @@ -84,12 +84,22 @@ void incrementFDD(void); extern std::array, MAX_DISK_IMAGES> imageDiskList; extern std::array, MAX_SWAPPABLE_DISKS> diskSwap; -extern Bit32s swapPosition; extern Bit16u imgDTASeg; /* Real memory location of temporary DTA pointer for fat image disk access */ extern RealPt imgDTAPtr; /* Real memory location of temporary DTA pointer for fat image disk access */ extern DOS_DTA *imgDTA; -void swapInDisks(void); +/** + * Insert 2 boot disks starting at swap_position into the drives A and B. + * + * Selected disks are wrapped around, so swapping in the last boot disk + * will place the first disk into drive B. + * + * When there's only 1 disk, it will be placed into both A and B drives. + * + * When there's no boot disks loaded, this function has no effect. + */ +void swapInDisks(unsigned int swap_position); + void swapInNextDisk(void); bool getSwapRequest(void); diff --git a/src/dos/dos_programs.cpp b/src/dos/dos_programs.cpp index 27e0c6b0..00399cea 100644 --- a/src/dos/dos_programs.cpp +++ b/src/dos/dos_programs.cpp @@ -676,9 +676,7 @@ public: i++; } - swapPosition = 0; - - swapInDisks(); + swapInDisks(0); if (!imageDiskList[drive - 'A']) { WriteOut(MSG_Get("PROGRAM_BOOT_UNABLE"), drive); diff --git a/src/ints/bios_disk.cpp b/src/ints/bios_disk.cpp index 4fb5c6aa..0c434e0e 100644 --- a/src/ints/bios_disk.cpp +++ b/src/ints/bios_disk.cpp @@ -59,7 +59,8 @@ void CMOS_SetRegister(Bitu regNr, Bit8u val); //For setting equipment word /* 2 floppys and 2 harddrives, max */ std::array, MAX_DISK_IMAGES> imageDiskList; std::array, MAX_SWAPPABLE_DISKS> diskSwap; -Bit32s swapPosition; + +unsigned int swapPosition; void updateDPT(void) { Bit32u tmpheads, tmpcyl, tmpsect, tmpsize; @@ -111,14 +112,14 @@ static size_t disk_array_prefix_size(const std::array &images) { return num; } -void swapInDisks(void) { +void swapInDisks(unsigned int swap_position) { const size_t boot_disks_num = disk_array_prefix_size(diskSwap); if (boot_disks_num == 0) return; - assert(swapPosition < boot_disks_num); - const unsigned int pos_1 = swapPosition; - const unsigned int pos_2 = (swapPosition + 1) % boot_disks_num; + assert(swap_position < boot_disks_num); + const unsigned int pos_1 = swap_position; + const unsigned int pos_2 = (swap_position + 1) % boot_disks_num; imageDiskList[0] = diskSwap[pos_1]; LOG_MSG("Loaded disk A from swaplist position %u - \"%s\"", @@ -145,10 +146,10 @@ void swapInNextDisk(bool pressed) { if (Drives[i]) Drives[i]->EmptyCache(); } swapPosition++; - if(!diskSwap[swapPosition]) { + if (!diskSwap[swapPosition]) { swapPosition = 0; } - swapInDisks(); + swapInDisks(swapPosition); swapping_requested = true; }