From d86cd7a6714cff2f18b2c51ce2dcb8c94d42dcb4 Mon Sep 17 00:00:00 2001 From: michaelangel007 Date: Tue, 25 Apr 2023 21:18:41 -0700 Subject: [PATCH] Disk: Remove memory probing and cache last track/sector directly from the Prologue Address Fields for non .WOZ disks --- source/Disk.cpp | 19 ++++++++++ source/Disk.h | 9 +++++ source/DiskFormatTrack.h | 1 + source/Windows/WinFrame.cpp | 73 +++---------------------------------- 4 files changed, 34 insertions(+), 68 deletions(-) diff --git a/source/Disk.cpp b/source/Disk.cpp index 5deb99a3..95d3cda0 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -100,6 +100,24 @@ Disk2InterfaceCard::~Disk2InterfaceCard(void) bool Disk2InterfaceCard::GetEnhanceDisk(void) { return m_enhanceDisk; } void Disk2InterfaceCard::SetEnhanceDisk(bool bEnhanceDisk) { m_enhanceDisk = bEnhanceDisk; } +// Returns true if Track, Sector is valid +bool Disk2InterfaceCard::GetLastReadTrackSector(const int drive, int& track, int& sector) +{ + Disk_Status_e status = GetDriveLightStatus(drive); + bool bValid = DISK_STATUS_OFF ? false : true; + if (bValid) + { + track = m_floppyDrive[drive].m_LastReadTrackSector[0]; + sector = m_floppyDrive[drive].m_LastReadTrackSector[1]; + } + else + { + track = -1; + sector = -1; + } + return bValid; +} + int Disk2InterfaceCard::GetCurrentDrive(void) { return m_currDrive; } int Disk2InterfaceCard::GetCurrentTrack(void) { return ImagePhaseToTrack(m_floppyDrive[m_currDrive].m_disk.m_imagehandle, m_floppyDrive[m_currDrive].m_phasePrecise, false); } float Disk2InterfaceCard::GetCurrentPhase(void) { return m_floppyDrive[m_currDrive].m_phasePrecise; } @@ -1092,6 +1110,7 @@ void __stdcall Disk2InterfaceCard::ReadWrite(WORD pc, WORD addr, BYTE bWrite, BY } m_formatTrack.DecodeLatchNibbleRead(m_floppyLatch); + pDrive->SetLastReadTrackSector(m_formatTrack.GetLastReadVolumeTrackSectorChecksum()); #endif } else if (!pFloppy->m_bWriteProtected) // && m_seqFunc.writeMode diff --git a/source/Disk.h b/source/Disk.h index 5f7cb164..6877ef6d 100644 --- a/source/Disk.h +++ b/source/Disk.h @@ -118,6 +118,13 @@ public: m_disk.clear(); } + // NOTE: Managed by Disk2InterfaceCard::ReadWrite() + void SetLastReadTrackSector(BYTE* pVolumeTrackSectorChecksum) + { + m_LastReadTrackSector[0] = pVolumeTrackSectorChecksum[1]; + m_LastReadTrackSector[1] = pVolumeTrackSectorChecksum[2]; + } + public: bool m_isConnected; float m_phasePrecise; // Phase precise to half a phase (aka quarter track) @@ -128,6 +135,7 @@ public: DWORD m_spinning; DWORD m_writelight; FloppyDisk m_disk; + BYTE m_LastReadTrackSector[2]; }; class Disk2InterfaceCard : public Card @@ -160,6 +168,7 @@ public: bool IsConditionForFullSpeed(void); void NotifyInvalidImage(const int drive, LPCTSTR pszImageFilename, const ImageError_e Error); UINT GetCurrentFirmware(void) { return m_is13SectorFirmware ? 13 : 16; } + bool GetLastReadTrackSector(const int drive, int& track, int& sector); int GetCurrentDrive(void); int GetCurrentTrack(void); float GetCurrentPhase(void); diff --git a/source/DiskFormatTrack.h b/source/DiskFormatTrack.h index a2dd2734..e97e75e3 100644 --- a/source/DiskFormatTrack.h +++ b/source/DiskFormatTrack.h @@ -45,6 +45,7 @@ public: std::string GetReadD5AAxxDetectedString(void) { std::string tmp = m_strReadD5AAxxDetected; m_strReadD5AAxxDetected = ""; return tmp; } void SaveSnapshot(class YamlSaveHelper& yamlSaveHelper); void LoadSnapshot(class YamlLoadHelper& yamlLoadHelper); + BYTE* GetLastReadVolumeTrackSectorChecksum() { return m_VolTrkSecChk; } private: void UpdateOnWriteLatch(UINT uSpinNibbleCount, const class FloppyDisk* const pFloppy); diff --git a/source/Windows/WinFrame.cpp b/source/Windows/WinFrame.cpp index a379087b..6a2b388c 100644 --- a/source/Windows/WinFrame.cpp +++ b/source/Windows/WinFrame.cpp @@ -609,81 +609,18 @@ void Win32Frame::FrameDrawDiskStatus() void Win32Frame::GetTrackSector(UINT slot, int& drive1Track, int& drive2Track, int& activeFloppy) { - // DOS3.3 ProDOS - // Slot $B7E9 $BE3C(DEFSLT=Default Slot) ; ref: Beneath Apple ProDOS 8-3 - // Drive $B7EA $BE3D(DEFDRV=Default Drive) ; ref: Beneath Apple ProDOS 8-3 - // Track $B7EC LC1 $D356 - // Sector $B7ED LC1 $D357 - // RWTS LC1 $D300 - drive1Track = drive2Track = activeFloppy = 0; + g_nSector[slot][0] = -1; + g_nSector[slot][1] = -1; + if (GetCardMgr().QuerySlot(slot) != CT_Disk2) return; Disk2InterfaceCard& disk2Card = dynamic_cast(GetCardMgr().GetRef(slot)); activeFloppy = disk2Card.GetCurrentDrive(); - drive1Track = disk2Card.GetTrack(DRIVE_1); - drive2Track = disk2Card.GetTrack(DRIVE_2); - // Probe known OS's for default Slot/Track/Sector - const bool isProDOS = mem[0xBF00] == 0x4C; - bool isSectorValid = false; - int drive1Sector = -1, drive2Sector = -1; - - // Try DOS3.3 Sector - if (!isProDOS) - { - const int nDOS33slot = mem[0xB7E9] / 16; - const int nDOS33track = mem[0xB7EC]; - const int nDOS33sector = mem[0xB7ED]; - - if ((nDOS33slot == slot) - && (nDOS33track >= 0 && nDOS33track < 40) - && (nDOS33sector >= 0 && nDOS33sector < 16)) - { -#if _DEBUG && 0 - if (nDOS33track != nDisk1Track) - { - LogOutput("\n\n\nWARNING: DOS33Track: %d (%02X) != nDisk1Track: %d (%02X)\n\n\n", nDOS33track, nDOS33track, nDisk1Track, nDisk1Track); - } -#endif // _DEBUG - - /**/ if (activeFloppy == 0) drive1Sector = nDOS33sector; - else if (activeFloppy == 1) drive2Sector = nDOS33sector; - - isSectorValid = true; - } - } - else // isProDOS - { - // we can't just read from mem[ 0xD357 ] since it might be bank-switched from ROM - // and we need the Language Card RAM - const int nProDOSslot = mem[0xBE3C]; - const int nProDOStrack = *MemGetMainPtr(0xC356); // LC1 $D356 - const int nProDOSsector = *MemGetMainPtr(0xC357); // LC1 $D357 - - if ((nProDOSslot == slot) - && (nProDOStrack >= 0 && nProDOStrack < 40) - && (nProDOSsector >= 0 && nProDOSsector < 16)) - { - /**/ if (activeFloppy == 0) drive1Sector = nProDOSsector; - else if (activeFloppy == 1) drive2Sector = nProDOSsector; - - isSectorValid = true; - } - } - - // Preserve sector so don't get "??" when switching drives, eg. if using COPYA to copy from drive-1 to drive-2 - if (isSectorValid) - { - if (activeFloppy == 0) g_nSector[slot][0] = drive1Sector; - else g_nSector[slot][1] = drive2Sector; - } - else - { - if (activeFloppy == 0) g_nSector[slot][0] = -1; - else g_nSector[slot][1] = -1; - } + disk2Card.GetLastReadTrackSector(0, drive1Track, g_nSector[slot][0]); + disk2Card.GetLastReadTrackSector(1, drive2Track, g_nSector[slot][1]); } void Win32Frame::CreateTrackSectorStrings(int track, int sector, std::string& strTrack, std::string& strSector)