From e7d6eac04d4d1fd05c68ada95b791ba95e358dc6 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sun, 7 Apr 2019 14:22:05 +0100 Subject: [PATCH] Class-ify disk.cpp into DiskIIInterfaceCard --- source/Applewin.cpp | 17 +- source/Configuration/PageDisk.cpp | 22 +-- source/Configuration/PropertySheetHelper.cpp | 2 +- source/Debugger/Debug.cpp | 18 +- source/Disk.cpp | 196 +++++++++---------- source/Disk.h | 108 ++++++---- source/DiskImage.cpp | 5 +- source/DiskImage.h | 2 +- source/DiskImageHelper.cpp | 15 +- source/DiskImageHelper.h | 2 +- source/Frame.cpp | 50 ++--- source/Memory.cpp | 2 +- source/SaveState.cpp | 8 +- source/Video.cpp | 2 +- 14 files changed, 243 insertions(+), 206 deletions(-) diff --git a/source/Applewin.cpp b/source/Applewin.cpp index 4cf53765..402b44de 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -105,6 +105,7 @@ int g_nMemoryClearType = MIP_FF_FF_00_00; // Note: -1 = random MIP in Memory.c IPropertySheet& sg_PropertySheet = * new CPropertySheet; CSuperSerialCard sg_SSC; CMouseInterface sg_Mouse; +DiskIIInterfaceCard sg_DiskIICard; SS_CARDTYPE g_Slot0 = CT_LanguageCard; // Just for Apple II or II+ or similar clones SS_CARDTYPE g_Slot4 = CT_Empty; @@ -269,7 +270,7 @@ static void ContinueExecution(void) const bool bWasFullSpeed = g_bFullSpeed; g_bFullSpeed = (g_dwSpeed == SPEED_MAX) || bScrollLock_FullSpeed || - (Disk_IsConditionForFullSpeed() && !Spkr_IsActive() && !MB_IsActive()) || + (sg_DiskIICard.Disk_IsConditionForFullSpeed() && !Spkr_IsActive() && !MB_IsActive()) || IsDebugSteppingAtFullSpeed(); if (g_bFullSpeed) @@ -316,7 +317,7 @@ static void ContinueExecution(void) const DWORD uActualCyclesExecuted = CpuExecute(uCyclesToExecute, bVideoUpdate); g_dwCyclesThisFrame += uActualCyclesExecuted; - DiskUpdateDriveState(uActualCyclesExecuted); + sg_DiskIICard.DiskUpdateDriveState(uActualCyclesExecuted); JoyUpdateButtonLatch(nExecutionPeriodUsec); // Button latch time is independent of CPU clock frequency PrintUpdate(uActualCyclesExecuted); @@ -624,7 +625,7 @@ void LoadConfiguration(void) DWORD dwEnhanceDisk; REGLOAD(TEXT(REGVALUE_ENHANCE_DISK_SPEED), &dwEnhanceDisk); - Disk_SetEnhanceDisk(dwEnhanceDisk ? true : false); + sg_DiskIICard.Disk_SetEnhanceDisk(dwEnhanceDisk ? true : false); Config_Load_Video(); @@ -713,8 +714,8 @@ void LoadConfiguration(void) GetCurrentDirectory(sizeof(szFilename), szFilename); SetCurrentImageDir(szFilename); - Disk_LoadLastDiskImage(DRIVE_1); - Disk_LoadLastDiskImage(DRIVE_2); + sg_DiskIICard.Disk_LoadLastDiskImage(DRIVE_1); + sg_DiskIICard.Disk_LoadLastDiskImage(DRIVE_2); // @@ -1061,7 +1062,7 @@ static bool DoDiskInsert(const int nDrive, LPCSTR szFileName) std::string strPathName = GetFullPath(szFileName); if (strPathName.empty()) return false; - ImageError_e Error = DiskInsert(nDrive, strPathName.c_str(), IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); + ImageError_e Error = sg_DiskIICard.DiskInsert(nDrive, strPathName.c_str(), IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); return Error == eIMAGE_ERROR_NONE; } @@ -1521,7 +1522,7 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) ImageInitialize(); LogFileOutput("Init: ImageInitialize()\n"); - DiskInitialize(); + sg_DiskIICard.DiskInitialize(); LogFileOutput("Init: DiskInitialize()\n"); // @@ -1615,7 +1616,7 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) } // Need to test if it's safe to call ResetMachineState(). In the meantime, just call DiskReset(): - DiskReset(); // Switch from a booting A][+ to a non-autostart A][, so need to turn off floppy motor + sg_DiskIICard.DiskReset(); // Switch from a booting A][+ to a non-autostart A][, so need to turn off floppy motor LogFileOutput("Main: DiskReset()\n"); HD_Reset(); // GH#515 LogFileOutput("Main: HDDReset()\n"); diff --git a/source/Configuration/PageDisk.cpp b/source/Configuration/PageDisk.cpp index 68b6cd8f..f871ade5 100644 --- a/source/Configuration/PageDisk.cpp +++ b/source/Configuration/PageDisk.cpp @@ -130,19 +130,19 @@ BOOL CPageDisk::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM l case WM_INITDIALOG: { - m_PropertySheetHelper.FillComboBox(hWnd, IDC_DISKTYPE, m_discchoices, Disk_GetEnhanceDisk() ? 1 : 0); + m_PropertySheetHelper.FillComboBox(hWnd, IDC_DISKTYPE, m_discchoices, sg_DiskIICard.Disk_GetEnhanceDisk() ? 1 : 0); m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_DISK1, m_defaultDiskOptions, -1); m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_DISK2, m_defaultDiskOptions, -1); - if (strlen(DiskGetFullName(DRIVE_1)) > 0) + if (strlen(sg_DiskIICard.DiskGetFullName(DRIVE_1)) > 0) { - SendDlgItemMessage(hWnd, IDC_COMBO_DISK1, CB_INSERTSTRING, 0, (LPARAM)DiskGetFullName(DRIVE_1)); + SendDlgItemMessage(hWnd, IDC_COMBO_DISK1, CB_INSERTSTRING, 0, (LPARAM)sg_DiskIICard.DiskGetFullName(DRIVE_1)); SendDlgItemMessage(hWnd, IDC_COMBO_DISK1, CB_SETCURSEL, 0, 0); } - if (strlen(DiskGetFullName(DRIVE_2)) > 0) + if (strlen(sg_DiskIICard.DiskGetFullName(DRIVE_2)) > 0) { - SendDlgItemMessage(hWnd, IDC_COMBO_DISK2, CB_INSERTSTRING, 0, (LPARAM)DiskGetFullName(DRIVE_2)); + SendDlgItemMessage(hWnd, IDC_COMBO_DISK2, CB_INSERTSTRING, 0, (LPARAM)sg_DiskIICard.DiskGetFullName(DRIVE_2)); SendDlgItemMessage(hWnd, IDC_COMBO_DISK2, CB_SETCURSEL, 0, 0); } @@ -187,9 +187,9 @@ void CPageDisk::InitComboHDD(HWND hWnd) void CPageDisk::DlgOK(HWND hWnd) { const bool bNewEnhanceDisk = SendDlgItemMessage(hWnd, IDC_DISKTYPE,CB_GETCURSEL, 0, 0) ? true : false; - if (bNewEnhanceDisk != Disk_GetEnhanceDisk()) + if (bNewEnhanceDisk != sg_DiskIICard.Disk_GetEnhanceDisk()) { - Disk_SetEnhanceDisk(bNewEnhanceDisk); + sg_DiskIICard.Disk_SetEnhanceDisk(bNewEnhanceDisk); REGSAVE(TEXT(REGVALUE_ENHANCE_DISK_SPEED), (DWORD)bNewEnhanceDisk); } @@ -299,7 +299,7 @@ void CPageDisk::HandleDiskCombo(HWND hWnd, UINT driveSelected, UINT comboSelecte if (dwComboSelection == dwOpenDialogIndex) { EnableDisk(hWnd, FALSE); // Prevent multiple Selection dialogs to be triggered - bool bRes = DiskSelect(driveSelected); + bool bRes = sg_DiskIICard.DiskSelect(driveSelected); EnableDisk(hWnd, TRUE); if (!bRes) @@ -316,13 +316,13 @@ void CPageDisk::HandleDiskCombo(HWND hWnd, UINT driveSelected, UINT comboSelecte SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); } - SendDlgItemMessage(hWnd, comboSelected, CB_INSERTSTRING, 0, (LPARAM)DiskGetFullName(driveSelected)); + SendDlgItemMessage(hWnd, comboSelected, CB_INSERTSTRING, 0, (LPARAM)sg_DiskIICard.DiskGetFullName(driveSelected)); SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); // If the FD was in the other combo, remove now DWORD comboOther = (comboSelected == IDC_COMBO_DISK1) ? IDC_COMBO_DISK2 : IDC_COMBO_DISK1; - DWORD duplicated = (DWORD)SendDlgItemMessage(hWnd, comboOther, CB_FINDSTRINGEXACT, -1, (LPARAM)DiskGetFullName(driveSelected)); + DWORD duplicated = (DWORD)SendDlgItemMessage(hWnd, comboOther, CB_FINDSTRINGEXACT, -1, (LPARAM)sg_DiskIICard.DiskGetFullName(driveSelected)); if (duplicated != CB_ERR) { SendDlgItemMessage(hWnd, comboOther, CB_DELETESTRING, duplicated, 0); @@ -337,7 +337,7 @@ void CPageDisk::HandleDiskCombo(HWND hWnd, UINT driveSelected, UINT comboSelecte if (RemovalConfirmation(uCommand)) { // Eject selected disk - DiskEject(driveSelected); + sg_DiskIICard.DiskEject(driveSelected); // Remove drive from list SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); } diff --git a/source/Configuration/PropertySheetHelper.cpp b/source/Configuration/PropertySheetHelper.cpp index 903013f0..5f26e5d6 100644 --- a/source/Configuration/PropertySheetHelper.cpp +++ b/source/Configuration/PropertySheetHelper.cpp @@ -198,7 +198,7 @@ void CPropertySheetHelper::SaveStateUpdate() void CPropertySheetHelper::GetDiskBaseNameWithAWS(TCHAR* pszFilename) { - LPCTSTR pDiskName = DiskGetBaseName(DRIVE_1); + LPCTSTR pDiskName = sg_DiskIICard.DiskGetBaseName(DRIVE_1); if (pDiskName && pDiskName[0]) { strcpy(pszFilename, pDiskName); diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index 33ef6e60..cb37c579 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -3727,15 +3727,15 @@ Update_t CmdDisk ( int nArgs) if (nArgs > 2) goto _Help; - int drive = DiskGetCurrentDrive() + 1; + int drive = sg_DiskIICard.DiskGetCurrentDrive() + 1; char buffer[200] = ""; ConsoleBufferPushFormat(buffer, "D%d at T$%X (%d), phase $%X, offset $%X, %s", drive, - DiskGetCurrentTrack(), - DiskGetCurrentTrack(), - DiskGetCurrentPhase(), - DiskGetCurrentOffset(), - DiskGetCurrentState()); + sg_DiskIICard.DiskGetCurrentTrack(), + sg_DiskIICard.DiskGetCurrentTrack(), + sg_DiskIICard.DiskGetCurrentPhase(), + sg_DiskIICard.DiskGetCurrentOffset(), + sg_DiskIICard.DiskGetCurrentState()); return ConsoleUpdate(); } @@ -3762,7 +3762,7 @@ Update_t CmdDisk ( int nArgs) if (nArgs > 2) goto _Help; - DiskEject( iDrive ); + sg_DiskIICard.DiskEject( iDrive ); FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES); } else @@ -3776,7 +3776,7 @@ Update_t CmdDisk ( int nArgs) if (nArgs == 3) bProtect = g_aArgs[ 3 ].nValue ? true : false; - DiskSetProtect( iDrive, bProtect ); + sg_DiskIICard.DiskSetProtect( iDrive, bProtect ); FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES); } else @@ -3787,7 +3787,7 @@ Update_t CmdDisk ( int nArgs) LPCTSTR pDiskName = g_aArgs[ 3 ].sArg; // DISK # "Diskname" - DiskInsert( iDrive, pDiskName, IMAGE_FORCE_WRITE_PROTECTED, IMAGE_DONT_CREATE ); + sg_DiskIICard.DiskInsert( iDrive, pDiskName, IMAGE_FORCE_WRITE_PROTECTED, IMAGE_DONT_CREATE ); FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES); } diff --git a/source/Disk.cpp b/source/Disk.cpp index a7ef7c4b..7ab9ac58 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -99,21 +99,21 @@ static bool enhancedisk = true; //=========================================================================== -bool Disk_GetEnhanceDisk(void) { return enhancedisk; } -void Disk_SetEnhanceDisk(bool bEnhanceDisk) { enhancedisk = bEnhanceDisk; } +bool DiskIIInterfaceCard::Disk_GetEnhanceDisk(void) { return enhancedisk; } +void DiskIIInterfaceCard::Disk_SetEnhanceDisk(bool bEnhanceDisk) { enhancedisk = bEnhanceDisk; } -int DiskGetCurrentDrive(void) { return currdrive; } -int DiskGetCurrentTrack(void) { return g_aFloppyDrive[currdrive].track; } -int DiskGetCurrentPhase(void) { return g_aFloppyDrive[currdrive].phase; } -int DiskGetCurrentOffset(void) { return g_aFloppyDrive[currdrive].disk.byte; } -int DiskGetTrack( int drive ) { return g_aFloppyDrive[ drive ].track; } +int DiskIIInterfaceCard::DiskGetCurrentDrive(void) { return currdrive; } +int DiskIIInterfaceCard::DiskGetCurrentTrack(void) { return g_aFloppyDrive[currdrive].track; } +int DiskIIInterfaceCard::DiskGetCurrentPhase(void) { return g_aFloppyDrive[currdrive].phase; } +int DiskIIInterfaceCard::DiskGetCurrentOffset(void) { return g_aFloppyDrive[currdrive].disk.byte; } +int DiskIIInterfaceCard::DiskGetTrack( int drive ) { return g_aFloppyDrive[ drive ].track; } -const char* DiskGetDiskPathFilename(const int iDrive) +const char* DiskIIInterfaceCard::DiskGetDiskPathFilename(const int iDrive) { return g_aFloppyDrive[iDrive].disk.fullname; } -const char* DiskGetCurrentState(void) +const char* DiskIIInterfaceCard::DiskGetCurrentState(void) { if (g_aFloppyDrive[currdrive].disk.imagehandle == NULL) return "Empty"; @@ -148,7 +148,7 @@ const char* DiskGetCurrentState(void) //=========================================================================== -void Disk_LoadLastDiskImage(const int iDrive) +void DiskIIInterfaceCard::Disk_LoadLastDiskImage(const int iDrive) { _ASSERT(iDrive == DRIVE_1 || iDrive == DRIVE_2); @@ -172,7 +172,7 @@ void Disk_LoadLastDiskImage(const int iDrive) //=========================================================================== -void Disk_SaveLastDiskImage(const int iDrive) +void DiskIIInterfaceCard::Disk_SaveLastDiskImage(const int iDrive) { _ASSERT(iDrive == DRIVE_1 || iDrive == DRIVE_2); @@ -201,7 +201,7 @@ void Disk_SaveLastDiskImage(const int iDrive) //=========================================================================== // Called by DiskControlMotor() & DiskEnable() -static void CheckSpinning(const ULONG nExecutedCycles) +void DiskIIInterfaceCard::CheckSpinning(const ULONG nExecutedCycles) { DWORD modechange = (floppymotoron && !g_aFloppyDrive[currdrive].spinning); @@ -221,7 +221,7 @@ static void CheckSpinning(const ULONG nExecutedCycles) //=========================================================================== -static Disk_Status_e GetDriveLightStatus(const int iDrive) +Disk_Status_e DiskIIInterfaceCard::GetDriveLightStatus(const int iDrive) { if (IsDriveValid( iDrive )) { @@ -248,14 +248,14 @@ static Disk_Status_e GetDriveLightStatus(const int iDrive) //=========================================================================== -static bool IsDriveValid(const int iDrive) +bool DiskIIInterfaceCard::IsDriveValid(const int iDrive) { return (iDrive >= 0 && iDrive < NUM_DRIVES); } //=========================================================================== -static void AllocTrack(const int iDrive) +void DiskIIInterfaceCard::AllocTrack(const int iDrive) { Disk_t* pFloppy = &g_aFloppyDrive[iDrive].disk; pFloppy->trackimage = (LPBYTE)VirtualAlloc(NULL, NIBBLES_PER_TRACK, MEM_COMMIT, PAGE_READWRITE); @@ -263,7 +263,7 @@ static void AllocTrack(const int iDrive) //=========================================================================== -static void ReadTrack(const int iDrive) +void DiskIIInterfaceCard::ReadTrack(const int iDrive) { if (! IsDriveValid( iDrive )) return; @@ -290,7 +290,8 @@ static void ReadTrack(const int iDrive) pDrive->track, pDrive->phase, pFloppy->trackimage, - &pFloppy->nibbles); + &pFloppy->nibbles, + enhancedisk); pFloppy->byte = 0; pFloppy->trackimagedata = (pFloppy->nibbles != 0); @@ -299,7 +300,7 @@ static void ReadTrack(const int iDrive) //=========================================================================== -static void RemoveDisk(const int iDrive) +void DiskIIInterfaceCard::RemoveDisk(const int iDrive) { Disk_t* pFloppy = &g_aFloppyDrive[iDrive].disk; @@ -328,7 +329,7 @@ static void RemoveDisk(const int iDrive) //=========================================================================== -static void WriteTrack(const int iDrive) +void DiskIIInterfaceCard::WriteTrack(const int iDrive) { Drive_t* pDrive = &g_aFloppyDrive[ iDrive ]; Disk_t* pFloppy = &pDrive->disk; @@ -355,7 +356,7 @@ static void WriteTrack(const int iDrive) pFloppy->trackimagedirty = false; } -void DiskFlushCurrentTrack(const int iDrive) +void DiskIIInterfaceCard::DiskFlushCurrentTrack(const int iDrive) { Disk_t* pFloppy = &g_aFloppyDrive[iDrive].disk; @@ -363,13 +364,9 @@ void DiskFlushCurrentTrack(const int iDrive) WriteTrack(iDrive); } -// -// ----- ALL GLOBALLY ACCESSIBLE FUNCTIONS ARE BELOW THIS LINE ----- -// - //=========================================================================== -void DiskBoot(void) +void DiskIIInterfaceCard::DiskBoot(void) { // THIS FUNCTION RELOADS A PROGRAM IMAGE IF ONE IS LOADED IN DRIVE ONE. // IF A DISK IMAGE OR NO IMAGE IS LOADED IN DRIVE ONE, IT DOES NOTHING. @@ -379,7 +376,7 @@ void DiskBoot(void) //=========================================================================== -static void __stdcall DiskControlMotor(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles) +void __stdcall DiskIIInterfaceCard::DiskControlMotor(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles) { BOOL newState = address & 1; @@ -397,7 +394,7 @@ static void __stdcall DiskControlMotor(WORD, WORD address, BYTE, BYTE, ULONG uEx //=========================================================================== -static void __stdcall DiskControlStepper(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles) +void __stdcall DiskIIInterfaceCard::DiskControlStepper(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles) { Drive_t* pDrive = &g_aFloppyDrive[currdrive]; Disk_t* pFloppy = &pDrive->disk; @@ -484,7 +481,7 @@ static void __stdcall DiskControlStepper(WORD, WORD address, BYTE, BYTE, ULONG u //=========================================================================== -void DiskDestroy(void) +void DiskIIInterfaceCard::DiskDestroy(void) { g_bSaveDiskImage = false; RemoveDisk(DRIVE_1); @@ -497,7 +494,7 @@ void DiskDestroy(void) //=========================================================================== -static void __stdcall DiskEnable(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles) +void __stdcall DiskIIInterfaceCard::DiskEnable(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles) { currdrive = address & 1; #if LOG_DISK_ENABLE_DRIVE @@ -510,7 +507,7 @@ static void __stdcall DiskEnable(WORD, WORD address, BYTE, BYTE, ULONG uExecuted //=========================================================================== -void DiskEject(const int iDrive) +void DiskIIInterfaceCard::DiskEject(const int iDrive) { if (IsDriveValid(iDrive)) { @@ -522,14 +519,14 @@ void DiskEject(const int iDrive) // Return the file or zip name // . Used by Property Sheet Page (Disk) -LPCTSTR DiskGetFullName(const int iDrive) +LPCTSTR DiskIIInterfaceCard::DiskGetFullName(const int iDrive) { return g_aFloppyDrive[iDrive].disk.fullname; } // Return the filename // . Used by Drive Buttons' tooltips -LPCTSTR DiskGetFullDiskFilename(const int iDrive) +LPCTSTR DiskIIInterfaceCard::DiskGetFullDiskFilename(const int iDrive) { if (!g_aFloppyDrive[iDrive].disk.strFilenameInZip.empty()) return g_aFloppyDrive[iDrive].disk.strFilenameInZip.c_str(); @@ -537,20 +534,20 @@ LPCTSTR DiskGetFullDiskFilename(const int iDrive) return DiskGetFullName(iDrive); } -static LPCTSTR DiskGetFullPathName(const int iDrive) +LPCTSTR DiskIIInterfaceCard::DiskGetFullPathName(const int iDrive) { return ImageGetPathname(g_aFloppyDrive[iDrive].disk.imagehandle); } // Return the imagename // . Used by Drive Button's icons & Property Sheet Page (Save snapshot) -LPCTSTR DiskGetBaseName(const int iDrive) +LPCTSTR DiskIIInterfaceCard::DiskGetBaseName(const int iDrive) { return g_aFloppyDrive[iDrive].disk.imagename; } //=========================================================================== -void DiskGetLightStatus(Disk_Status_e *pDisk1Status, Disk_Status_e *pDisk2Status) +void DiskIIInterfaceCard::DiskGetLightStatus(Disk_Status_e *pDisk1Status, Disk_Status_e *pDisk2Status) { if (pDisk1Status) *pDisk1Status = GetDriveLightStatus(DRIVE_1); @@ -561,7 +558,7 @@ void DiskGetLightStatus(Disk_Status_e *pDisk1Status, Disk_Status_e *pDisk2Status //=========================================================================== -void DiskInitialize(void) +void DiskIIInterfaceCard::DiskInitialize(void) { int loop = NUM_DRIVES; while (loop--) @@ -570,7 +567,7 @@ void DiskInitialize(void) //=========================================================================== -ImageError_e DiskInsert(const int iDrive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary) +ImageError_e DiskIIInterfaceCard::DiskInsert(const int iDrive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary) { Drive_t* pDrive = &g_aFloppyDrive[iDrive]; Disk_t* pFloppy = &pDrive->disk; @@ -646,19 +643,19 @@ ImageError_e DiskInsert(const int iDrive, LPCTSTR pszImageFilename, const bool b //=========================================================================== -bool Disk_IsConditionForFullSpeed(void) +bool DiskIIInterfaceCard::Disk_IsConditionForFullSpeed(void) { return floppymotoron && enhancedisk; } -BOOL DiskIsSpinning(void) +BOOL DiskIIInterfaceCard::DiskIsSpinning(void) { return floppymotoron; } //=========================================================================== -void DiskNotifyInvalidImage(const int iDrive, LPCTSTR pszImageFilename, const ImageError_e Error) +void DiskIIInterfaceCard::DiskNotifyInvalidImage(const int iDrive, LPCTSTR pszImageFilename, const ImageError_e Error) { TCHAR szBuffer[MAX_PATH+128]; szBuffer[sizeof(szBuffer)-1] = 0; @@ -772,7 +769,7 @@ void DiskNotifyInvalidImage(const int iDrive, LPCTSTR pszImageFilename, const Im //=========================================================================== -bool DiskGetProtect(const int iDrive) +bool DiskIIInterfaceCard::DiskGetProtect(const int iDrive) { if (IsDriveValid(iDrive)) { @@ -786,7 +783,7 @@ bool DiskGetProtect(const int iDrive) //=========================================================================== -void DiskSetProtect(const int iDrive, const bool bWriteProtect) +void DiskIIInterfaceCard::DiskSetProtect(const int iDrive, const bool bWriteProtect) { if (IsDriveValid( iDrive )) { @@ -797,7 +794,7 @@ void DiskSetProtect(const int iDrive, const bool bWriteProtect) //=========================================================================== -bool Disk_ImageIsWriteProtected(const int iDrive) +bool DiskIIInterfaceCard::Disk_ImageIsWriteProtected(const int iDrive) { if (!IsDriveValid(iDrive)) return true; @@ -807,7 +804,7 @@ bool Disk_ImageIsWriteProtected(const int iDrive) //=========================================================================== -bool Disk_IsDriveEmpty(const int iDrive) +bool DiskIIInterfaceCard::Disk_IsDriveEmpty(const int iDrive) { if (!IsDriveValid(iDrive)) return true; @@ -821,7 +818,7 @@ bool Disk_IsDriveEmpty(const int iDrive) static UINT64 g_uWriteLastCycle = 0; static UINT g_uSyncFFCount = 0; -static bool LogWriteCheckSyncFF(ULONG& uCycleDelta) +bool DiskIIInterfaceCard::LogWriteCheckSyncFF(ULONG& uCycleDelta) { bool bIsSyncFF = false; @@ -851,7 +848,7 @@ static bool LogWriteCheckSyncFF(ULONG& uCycleDelta) //=========================================================================== -static void __stdcall DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles) +void __stdcall DiskIIInterfaceCard::DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles) { /* floppyloadmode = 0; */ Drive_t* pDrive = &g_aFloppyDrive[currdrive]; @@ -965,7 +962,7 @@ static void __stdcall DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULO //=========================================================================== -void DiskReset(const bool bIsPowerCycle/*=false*/) +void DiskIIInterfaceCard::DiskReset(const bool bIsPowerCycle/*=false*/) { // RESET forces all switches off (UTAIIe Table 9.1) currdrive = 0; @@ -993,7 +990,7 @@ void DiskReset(const bool bIsPowerCycle/*=false*/) //=========================================================================== -static bool DiskSelectImage(const int iDrive, LPCSTR pszFilename) +bool DiskIIInterfaceCard::DiskSelectImage(const int iDrive, LPCSTR pszFilename) { TCHAR directory[MAX_PATH] = TEXT(""); TCHAR filename[MAX_PATH] = TEXT(""); @@ -1044,14 +1041,14 @@ static bool DiskSelectImage(const int iDrive, LPCSTR pszFilename) //=========================================================================== -bool DiskSelect(const int iDrive) +bool DiskIIInterfaceCard::DiskSelect(const int iDrive) { return DiskSelectImage(iDrive, TEXT("")); } //=========================================================================== -static void __stdcall DiskLoadWriteProtect(WORD, WORD, BYTE write, BYTE value, ULONG) +void __stdcall DiskIIInterfaceCard::DiskLoadWriteProtect(WORD, WORD, BYTE write, BYTE value, ULONG) { /* floppyloadmode = 1; */ @@ -1077,7 +1074,7 @@ static void __stdcall DiskLoadWriteProtect(WORD, WORD, BYTE write, BYTE value, U //=========================================================================== -static void __stdcall DiskSetReadMode(WORD, WORD, BYTE, BYTE, ULONG) +void __stdcall DiskIIInterfaceCard::DiskSetReadMode(WORD, WORD, BYTE, BYTE, ULONG) { floppywritemode = 0; @@ -1090,7 +1087,7 @@ static void __stdcall DiskSetReadMode(WORD, WORD, BYTE, BYTE, ULONG) //=========================================================================== -static void __stdcall DiskSetWriteMode(WORD, WORD, BYTE, BYTE, ULONG uExecutedCycles) +void __stdcall DiskIIInterfaceCard::DiskSetWriteMode(WORD, WORD, BYTE, BYTE, ULONG uExecutedCycles) { floppywritemode = 1; @@ -1112,7 +1109,7 @@ static void __stdcall DiskSetWriteMode(WORD, WORD, BYTE, BYTE, ULONG uExecutedCy //=========================================================================== -void DiskUpdateDriveState(DWORD cycles) +void DiskIIInterfaceCard::DiskUpdateDriveState(DWORD cycles) { int loop = NUM_DRIVES; while (loop--) @@ -1145,7 +1142,7 @@ void DiskUpdateDriveState(DWORD cycles) //=========================================================================== -bool DiskDriveSwap(void) +bool DiskIIInterfaceCard::DiskDriveSwap(void) { // Refuse to swap if either Disk][ is active // TODO: if Shift-Click then FORCE drive swap to bypass message @@ -1200,11 +1197,8 @@ bool DiskDriveSwap(void) //=========================================================================== -static BYTE __stdcall Disk_IORead(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles); -static BYTE __stdcall Disk_IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles); - // TODO: LoadRom_Disk_Floppy() -void DiskLoadRom(LPBYTE pCxRomPeripheral, UINT uSlot) +void DiskIIInterfaceCard::Initialize(LPBYTE pCxRomPeripheral, UINT uSlot) { const UINT DISK2_FW_SIZE = APPLE_SLOT_SIZE; @@ -1233,33 +1227,36 @@ void DiskLoadRom(LPBYTE pCxRomPeripheral, UINT uSlot) // . Patching the firmware breaks the ADC checksum used by "The CIA Files" (Tricky Dick) // . In this case we can patch to compensate for an ADC or EOR checksum but not both (nickw) - RegisterIoHandler(uSlot, Disk_IORead, Disk_IOWrite, NULL, NULL, NULL, NULL); + RegisterIoHandler(uSlot, &DiskIIInterfaceCard::Disk_IORead, &DiskIIInterfaceCard::Disk_IOWrite, NULL, NULL, this, NULL); g_uSlot = uSlot; } //=========================================================================== -static BYTE __stdcall Disk_IORead(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles) +BYTE __stdcall DiskIIInterfaceCard::Disk_IORead(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles) { + UINT uSlot = ((addr & 0xff) >> 4) - 8; + DiskIIInterfaceCard* pCard = (DiskIIInterfaceCard*) MemGetSlotParameters(uSlot); + switch (addr & 0xF) { - case 0x0: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x1: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x2: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x3: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x4: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x5: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x6: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x7: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x8: DiskControlMotor(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x9: DiskControlMotor(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xA: DiskEnable(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xB: DiskEnable(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xC: DiskReadWrite(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xD: DiskLoadWriteProtect(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xE: DiskSetReadMode(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xF: DiskSetWriteMode(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x0: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x1: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x2: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x3: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x4: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x5: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x6: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x7: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x8: pCard->DiskControlMotor(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x9: pCard->DiskControlMotor(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xA: pCard->DiskEnable(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xB: pCard->DiskEnable(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xC: pCard->DiskReadWrite(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xD: pCard->DiskLoadWriteProtect(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xE: pCard->DiskSetReadMode(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xF: pCard->DiskSetWriteMode(pc, addr, bWrite, d, nExecutedCycles); break; } // only even addresses return the latch (UTAIIe Table 9.1) @@ -1269,26 +1266,29 @@ static BYTE __stdcall Disk_IORead(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG return MemReadFloatingBus(nExecutedCycles); } -static BYTE __stdcall Disk_IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles) +BYTE __stdcall DiskIIInterfaceCard::Disk_IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles) { + UINT uSlot = ((addr & 0xff) >> 4) - 8; + DiskIIInterfaceCard* pCard = (DiskIIInterfaceCard*) MemGetSlotParameters(uSlot); + switch (addr & 0xF) { - case 0x0: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x1: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x2: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x3: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x4: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x5: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x6: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x7: DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x8: DiskControlMotor(pc, addr, bWrite, d, nExecutedCycles); break; - case 0x9: DiskControlMotor(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xA: DiskEnable(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xB: DiskEnable(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xC: DiskReadWrite(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xD: DiskLoadWriteProtect(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xE: DiskSetReadMode(pc, addr, bWrite, d, nExecutedCycles); break; - case 0xF: DiskSetWriteMode(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x0: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x1: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x2: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x3: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x4: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x5: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x6: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x7: pCard->DiskControlStepper(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x8: pCard->DiskControlMotor(pc, addr, bWrite, d, nExecutedCycles); break; + case 0x9: pCard->DiskControlMotor(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xA: pCard->DiskEnable(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xB: pCard->DiskEnable(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xC: pCard->DiskReadWrite(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xD: pCard->DiskLoadWriteProtect(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xE: pCard->DiskSetReadMode(pc, addr, bWrite, d, nExecutedCycles); break; + case 0xF: pCard->DiskSetWriteMode(pc, addr, bWrite, d, nExecutedCycles); break; } // any address writes the latch via sequencer LD command (74LS323 datasheet) @@ -1331,13 +1331,13 @@ static const UINT kUNIT_VERSION = 3; #define SS_YAML_KEY_TRACK_IMAGE_DIRTY "Track Image Dirty" #define SS_YAML_KEY_TRACK_IMAGE "Track Image" -std::string DiskGetSnapshotCardName(void) +std::string DiskIIInterfaceCard::DiskGetSnapshotCardName(void) { static const std::string name(SS_YAML_VALUE_CARD_DISK2); return name; } -static void DiskSaveSnapshotDisk2Unit(YamlSaveHelper& yamlSaveHelper, UINT unit) +void DiskIIInterfaceCard::DiskSaveSnapshotDisk2Unit(YamlSaveHelper& yamlSaveHelper, UINT unit) { YamlSaveHelper::Label label(yamlSaveHelper, "%s%d:\n", SS_YAML_KEY_DISK2UNIT, unit); yamlSaveHelper.SaveString(SS_YAML_KEY_FILENAME, g_aFloppyDrive[unit].disk.fullname); @@ -1358,7 +1358,7 @@ static void DiskSaveSnapshotDisk2Unit(YamlSaveHelper& yamlSaveHelper, UINT unit) } } -void DiskSaveSnapshot(class YamlSaveHelper& yamlSaveHelper) +void DiskIIInterfaceCard::DiskSaveSnapshot(class YamlSaveHelper& yamlSaveHelper) { YamlSaveHelper::Slot slot(yamlSaveHelper, DiskGetSnapshotCardName(), g_uSlot, kUNIT_VERSION); @@ -1378,7 +1378,7 @@ void DiskSaveSnapshot(class YamlSaveHelper& yamlSaveHelper) DiskSaveSnapshotDisk2Unit(yamlSaveHelper, DRIVE_2); } -static void DiskLoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, UINT unit) +void DiskIIInterfaceCard::DiskLoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, UINT unit) { std::string disk2UnitName = std::string(SS_YAML_KEY_DISK2UNIT) + (unit == DRIVE_1 ? std::string("0") : std::string("1")); if (!yamlLoadHelper.GetSubMap(disk2UnitName)) @@ -1455,7 +1455,7 @@ static void DiskLoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, UINT unit) } } -bool DiskLoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version) +bool DiskIIInterfaceCard::DiskLoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version) { if (slot != 6) // fixme throw std::string("Card: wrong slot"); diff --git a/source/Disk.h b/source/Disk.h index e4dc460b..e39631e0 100644 --- a/source/Disk.h +++ b/source/Disk.h @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "DiskImage.h" +extern class DiskIIInterfaceCard sg_DiskIICard; + // Floppy Disk Drives enum Drive_e @@ -39,51 +41,85 @@ const bool IMAGE_FORCE_WRITE_PROTECTED = true; const bool IMAGE_DONT_CREATE = false; const bool IMAGE_CREATE = true; -const char* DiskGetDiskPathFilename(const int iDrive); +class DiskIIInterfaceCard +{ +public: + DiskIIInterfaceCard(void){}; + virtual ~DiskIIInterfaceCard(void){}; -void DiskInitialize(void); // DiskIIManagerStartup() -void DiskDestroy(void); // no, doesn't "destroy" the disk image. DiskIIManagerShutdown() + const char* DiskGetDiskPathFilename(const int iDrive); -void DiskBoot(void); -void DiskEject(const int iDrive); -void DiskFlushCurrentTrack(const int iDrive); + void DiskInitialize(void); // DiskIIManagerStartup() + void DiskDestroy(void); // no, doesn't "destroy" the disk image. DiskIIManagerShutdown() -LPCTSTR DiskGetFullName(const int iDrive); -LPCTSTR DiskGetFullDiskFilename(const int iDrive); -LPCTSTR DiskGetBaseName(const int iDrive); + void DiskBoot(void); + void DiskEject(const int iDrive); + void DiskFlushCurrentTrack(const int iDrive); -void DiskGetLightStatus (Disk_Status_e* pDisk1Status, Disk_Status_e* pDisk2Status); + LPCTSTR DiskGetFullName(const int iDrive); + LPCTSTR DiskGetFullDiskFilename(const int iDrive); + LPCTSTR DiskGetBaseName(const int iDrive); -ImageError_e DiskInsert(const int iDrive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary); -bool Disk_IsConditionForFullSpeed(void); -BOOL DiskIsSpinning(void); -void DiskNotifyInvalidImage(const int iDrive, LPCTSTR pszImageFilename, const ImageError_e Error); -void DiskReset(const bool bIsPowerCycle=false); -bool DiskGetProtect(const int iDrive); -void DiskSetProtect(const int iDrive, const bool bWriteProtect); -int DiskGetCurrentDrive(); -int DiskGetCurrentTrack(); -int DiskGetTrack( int drive ); -int DiskGetCurrentPhase(); -int DiskGetCurrentOffset(); -const char* DiskGetCurrentState(); -bool DiskSelect(const int iDrive); -void DiskUpdateDriveState(DWORD); -bool DiskDriveSwap(void); -void DiskLoadRom(LPBYTE pCxRomPeripheral, UINT uSlot); + void DiskGetLightStatus (Disk_Status_e* pDisk1Status, Disk_Status_e* pDisk2Status); -std::string DiskGetSnapshotCardName(void); -void DiskSaveSnapshot(class YamlSaveHelper& yamlSaveHelper); -bool DiskLoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version); + ImageError_e DiskInsert(const int iDrive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary); + bool Disk_IsConditionForFullSpeed(void); + BOOL DiskIsSpinning(void); + void DiskNotifyInvalidImage(const int iDrive, LPCTSTR pszImageFilename, const ImageError_e Error); + void DiskReset(const bool bIsPowerCycle=false); + bool DiskGetProtect(const int iDrive); + void DiskSetProtect(const int iDrive, const bool bWriteProtect); + int DiskGetCurrentDrive(); + int DiskGetCurrentTrack(); + int DiskGetTrack( int drive ); + int DiskGetCurrentPhase(); + int DiskGetCurrentOffset(); + const char* DiskGetCurrentState(); + bool DiskSelect(const int iDrive); + void DiskUpdateDriveState(DWORD); + bool DiskDriveSwap(void); + void Initialize(LPBYTE pCxRomPeripheral, UINT uSlot); -void Disk_LoadLastDiskImage(const int iDrive); -void Disk_SaveLastDiskImage(const int iDrive); + std::string DiskGetSnapshotCardName(void); + void DiskSaveSnapshot(class YamlSaveHelper& yamlSaveHelper); + bool DiskLoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version); -bool Disk_ImageIsWriteProtected(const int iDrive); -bool Disk_IsDriveEmpty(const int iDrive); + void Disk_LoadLastDiskImage(const int iDrive); + void Disk_SaveLastDiskImage(const int iDrive); -bool Disk_GetEnhanceDisk(void); -void Disk_SetEnhanceDisk(bool bEnhanceDisk); + bool Disk_ImageIsWriteProtected(const int iDrive); + bool Disk_IsDriveEmpty(const int iDrive); + + bool Disk_GetEnhanceDisk(void); + void Disk_SetEnhanceDisk(bool bEnhanceDisk); + + static BYTE __stdcall DiskIIInterfaceCard::Disk_IORead(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles); + static BYTE __stdcall DiskIIInterfaceCard::Disk_IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles); + +private: + void DiskIIInterfaceCard::CheckSpinning(const ULONG nExecutedCycles); + Disk_Status_e DiskIIInterfaceCard::GetDriveLightStatus(const int iDrive); + bool DiskIIInterfaceCard::IsDriveValid(const int iDrive); + void DiskIIInterfaceCard::AllocTrack(const int iDrive); + void DiskIIInterfaceCard::ReadTrack(const int iDrive); + void DiskIIInterfaceCard::RemoveDisk(const int iDrive); + void DiskIIInterfaceCard::WriteTrack(const int iDrive); + LPCTSTR DiskIIInterfaceCard::DiskGetFullPathName(const int iDrive); + bool DiskIIInterfaceCard::DiskSelectImage(const int iDrive, LPCSTR pszFilename); + void DiskIIInterfaceCard::DiskSaveSnapshotDisk2Unit(YamlSaveHelper& yamlSaveHelper, UINT unit); + void DiskIIInterfaceCard::DiskLoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, UINT unit); + + void __stdcall DiskIIInterfaceCard::DiskControlStepper(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles); + void __stdcall DiskIIInterfaceCard::DiskControlMotor(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles); + void __stdcall DiskIIInterfaceCard::DiskEnable(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles); + void __stdcall DiskIIInterfaceCard::DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles); + void __stdcall DiskIIInterfaceCard::DiskLoadWriteProtect(WORD, WORD, BYTE write, BYTE value, ULONG); + void __stdcall DiskIIInterfaceCard::DiskSetReadMode(WORD, WORD, BYTE, BYTE, ULONG); + void __stdcall DiskIIInterfaceCard::DiskSetWriteMode(WORD, WORD, BYTE, BYTE, ULONG uExecutedCycles); + + //#if LOG_DISK_NIBBLES_WRITE + bool DiskIIInterfaceCard::LogWriteCheckSyncFF(ULONG& uCycleDelta); +}; // diff --git a/source/DiskImage.cpp b/source/DiskImage.cpp index 6640124c..be1c1a2c 100644 --- a/source/DiskImage.cpp +++ b/source/DiskImage.cpp @@ -155,7 +155,8 @@ void ImageReadTrack( ImageInfo* const pImageInfo, const int nTrack, const int nQuarterTrack, LPBYTE pTrackImageBuffer, - int* pNibbles) + int* pNibbles, + bool enhancedisk) { _ASSERT(nTrack >= 0); if (nTrack < 0) @@ -163,7 +164,7 @@ void ImageReadTrack( ImageInfo* const pImageInfo, if (pImageInfo->pImageType->AllowRW() && pImageInfo->ValidTrack[nTrack]) { - pImageInfo->pImageType->Read(pImageInfo, nTrack, nQuarterTrack, pTrackImageBuffer, pNibbles); + pImageInfo->pImageType->Read(pImageInfo, nTrack, nQuarterTrack, pTrackImageBuffer, pNibbles, enhancedisk); } else { diff --git a/source/DiskImage.h b/source/DiskImage.h index 76c105ae..ebb6d55f 100644 --- a/source/DiskImage.h +++ b/source/DiskImage.h @@ -71,7 +71,7 @@ BOOL ImageBoot(ImageInfo* const pImageInfo); void ImageDestroy(void); void ImageInitialize(void); -void ImageReadTrack(ImageInfo* const pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles); +void ImageReadTrack(ImageInfo* const pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles, bool enhancedisk); void ImageWriteTrack(ImageInfo* const pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImage, int nNibbles); bool ImageReadBlock(ImageInfo* const pImageInfo, UINT nBlock, LPBYTE pBlockBuffer); bool ImageWriteBlock(ImageInfo* const pImageInfo, UINT nBlock, LPBYTE pBlockBuffer); diff --git a/source/DiskImageHelper.cpp b/source/DiskImageHelper.cpp index 1cd01e24..f26649a7 100644 --- a/source/DiskImageHelper.cpp +++ b/source/DiskImageHelper.cpp @@ -34,7 +34,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "unzip.h" #include "CPU.h" -#include "Disk.h" #include "DiskImage.h" #include "DiskImageHelper.h" #include "Memory.h" @@ -631,11 +630,11 @@ public: return ePossibleMatch; } - virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles) + virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles, bool enhancedisk) { ReadTrack(pImageInfo, nTrack, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); *pNibbles = NibblizeTrack(pTrackImageBuffer, eDOSOrder, nTrack); - if (!Disk_GetEnhanceDisk()) + if (!enhancedisk) SkewTrack(nTrack, *pNibbles, pTrackImageBuffer); } @@ -697,11 +696,11 @@ public: return ePossibleMatch; } - virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles) + virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles, bool enhancedisk) { ReadTrack(pImageInfo, nTrack, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); *pNibbles = NibblizeTrack(pTrackImageBuffer, eProDOSOrder, nTrack); - if (!Disk_GetEnhanceDisk()) + if (!enhancedisk) SkewTrack(nTrack, *pNibbles, pTrackImageBuffer); } @@ -736,7 +735,7 @@ public: return eMatch; } - virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles) + virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles, bool enhancedisk) { ReadTrack(pImageInfo, nTrack, pTrackImageBuffer, NIB1_TRACK_SIZE); *pNibbles = NIB1_TRACK_SIZE; @@ -776,7 +775,7 @@ public: return eMatch; } - virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles) + virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles, bool enhancedisk) { ReadTrack(pImageInfo, nTrack, pTrackImageBuffer, NIB2_TRACK_SIZE); *pNibbles = NIB2_TRACK_SIZE; @@ -852,7 +851,7 @@ public: return eMatch; } - virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles) + virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles, bool enhancedisk) { // IF WE HAVEN'T ALREADY DONE SO, READ THE IMAGE FILE HEADER if (!m_pHeader) diff --git a/source/DiskImageHelper.h b/source/DiskImageHelper.h index 3eaafe23..f79c020f 100644 --- a/source/DiskImageHelper.h +++ b/source/DiskImageHelper.h @@ -54,7 +54,7 @@ public: virtual bool Boot(ImageInfo* pImageInfo) { return false; } virtual eDetectResult Detect(const LPBYTE pImage, const DWORD dwImageSize, const TCHAR* pszExt) = 0; - virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles) { } + virtual void Read(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles, bool enhancedisk) { } virtual bool Read(ImageInfo* pImageInfo, UINT nBlock, LPBYTE pBlockBuffer) { return false; } virtual void Write(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImage, int nNibbles) { } virtual bool Write(ImageInfo* pImageInfo, UINT nBlock, LPBYTE pBlockBuffer) { return false; } diff --git a/source/Frame.cpp b/source/Frame.cpp index b3328c28..4bf58ed0 100644 --- a/source/Frame.cpp +++ b/source/Frame.cpp @@ -512,7 +512,7 @@ static void DrawButton (HDC passdc, int number) { SetTextColor(dc,RGB(0,0,0)); SetTextAlign(dc,TA_CENTER | TA_TOP); SetBkMode(dc,TRANSPARENT); - LPCTSTR pszBaseName = DiskGetBaseName(number-BTN_DRIVE1); + LPCTSTR pszBaseName = sg_DiskIICard.DiskGetBaseName(number-BTN_DRIVE1); ExtTextOut(dc,x+offset+22,rect.top,ETO_CLIPPED,&rect, pszBaseName, MIN(8,_tcslen(pszBaseName)), @@ -702,7 +702,7 @@ void FrameDrawDiskLEDS( HDC passdc ) { Disk_Status_e eDrive1Status; Disk_Status_e eDrive2Status; - DiskGetLightStatus(&eDrive1Status, &eDrive2Status); + sg_DiskIICard.DiskGetLightStatus(&eDrive1Status, &eDrive2Status); g_eStatusDrive1 = eDrive1Status; g_eStatusDrive2 = eDrive2Status; @@ -755,10 +755,10 @@ void FrameDrawDiskStatus( HDC passdc ) // Track $B7EC LC1 $D356 // Sector $B7ED LC1 $D357 // RWTS LC1 $D300 - int nActiveFloppy = DiskGetCurrentDrive(); + int nActiveFloppy = sg_DiskIICard.DiskGetCurrentDrive(); - int nDisk1Track = DiskGetTrack(0); - int nDisk2Track = DiskGetTrack(1); + int nDisk1Track = sg_DiskIICard.DiskGetTrack(DRIVE_1); + int nDisk2Track = sg_DiskIICard.DiskGetTrack(DRIVE_2); // Probe known OS's for Track/Sector int isProDOS = mem[ 0xBF00 ] == 0x4C; @@ -1103,7 +1103,7 @@ LRESULT CALLBACK FrameWndProc ( Snapshot_Shutdown(); DebugDestroy(); if (!g_bRestart) { - DiskDestroy(); + sg_DiskIICard.DiskDestroy(); ImageDestroy(); HD_Destroy(); } @@ -1161,7 +1161,7 @@ LRESULT CALLBACK FrameWndProc ( LogFileOutput("WM_DDE_EXECUTE\n"); LPTSTR filename = (LPTSTR)GlobalLock((HGLOBAL)lparam); //MessageBox( g_hFrameWindow, filename, "DDE Exec", MB_OK ); - ImageError_e Error = DiskInsert(DRIVE_1, filename, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); + ImageError_e Error = sg_DiskIICard.DiskInsert(DRIVE_1, filename, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); if (Error == eIMAGE_ERROR_NONE) { if (!g_bIsFullScreen) @@ -1171,7 +1171,7 @@ LRESULT CALLBACK FrameWndProc ( } else { - DiskNotifyInvalidImage(DRIVE_1, filename, Error); + sg_DiskIICard.DiskNotifyInvalidImage(DRIVE_1, filename, Error); } GlobalUnlock((HGLOBAL)lparam); LogFileOutput("WM_DDE_EXECUTE (done)\n"); @@ -1193,7 +1193,7 @@ LRESULT CALLBACK FrameWndProc ( rect.top = buttony+BTN_DRIVE2*BUTTONCY+1; rect.bottom = rect.top+BUTTONCY; const int iDrive = PtInRect(&rect,point) ? DRIVE_2 : DRIVE_1; - ImageError_e Error = DiskInsert(iDrive, filename, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); + ImageError_e Error = sg_DiskIICard.DiskInsert(iDrive, filename, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); if (Error == eIMAGE_ERROR_NONE) { if (!g_bIsFullScreen) @@ -1207,7 +1207,7 @@ LRESULT CALLBACK FrameWndProc ( } else { - DiskNotifyInvalidImage(iDrive, filename, Error); + sg_DiskIICard.DiskNotifyInvalidImage(iDrive, filename, Error); } DragFinish((HDROP)wparam); break; @@ -1653,7 +1653,7 @@ LRESULT CALLBACK FrameWndProc ( if(((LPNMTTDISPINFO)lparam)->hdr.hwndFrom == tooltipwindow && ((LPNMTTDISPINFO)lparam)->hdr.code == TTN_GETDISPINFO) ((LPNMTTDISPINFO)lparam)->lpszText = - (LPTSTR)DiskGetFullDiskFilename(((LPNMTTDISPINFO)lparam)->hdr.idFrom); + (LPTSTR)sg_DiskIICard.DiskGetFullDiskFilename(((LPNMTTDISPINFO)lparam)->hdr.idFrom); break; case WM_PAINT: @@ -1967,7 +1967,7 @@ static void ProcessButtonClick(int button, bool bFromButtonUI /*=false*/) if (g_nAppMode == MODE_LOGO) { - DiskBoot(); + sg_DiskIICard.DiskBoot(); LogFileTimeUntilFirstKeyReadReset(); g_nAppMode = MODE_RUNNING; } @@ -1990,13 +1990,13 @@ static void ProcessButtonClick(int button, bool bFromButtonUI /*=false*/) case BTN_DRIVE1: case BTN_DRIVE2: - DiskSelect(button-BTN_DRIVE1); + sg_DiskIICard.DiskSelect(button-BTN_DRIVE1); if (!g_bIsFullScreen) DrawButton((HDC)0,button); break; case BTN_DRIVESWAP: - DiskDriveSwap(); + sg_DiskIICard.DiskDriveSwap(); break; case BTN_FULLSCR: @@ -2057,7 +2057,7 @@ void ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) //TODO: A directory is open if an empty path to CiderPress is set. This has to be fixed. std::string filename1= "\""; - filename1.append( DiskGetDiskPathFilename(iDrive) ); + filename1.append( sg_DiskIICard.DiskGetDiskPathFilename(iDrive) ); filename1.append("\""); std::string sFileNameEmpty = "\""; sFileNameEmpty.append("\""); @@ -2079,16 +2079,16 @@ void ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) // Check menu depending on current floppy protection { int iMenuItem = ID_DISKMENU_WRITEPROTECTION_OFF; - if (DiskGetProtect( iDrive )) + if (sg_DiskIICard.DiskGetProtect( iDrive )) iMenuItem = ID_DISKMENU_WRITEPROTECTION_ON; CheckMenuItem(hmenu, iMenuItem, MF_CHECKED); } - if (Disk_IsDriveEmpty(iDrive)) + if (sg_DiskIICard.Disk_IsDriveEmpty(iDrive)) EnableMenuItem(hmenu, ID_DISKMENU_EJECT, MF_GRAYED); - if (Disk_ImageIsWriteProtected(iDrive)) + if (sg_DiskIICard.Disk_ImageIsWriteProtected(iDrive)) { // If image-file is read-only (or a gzip) then disable these menu items EnableMenuItem(hmenu, ID_DISKMENU_WRITEPROTECTION_ON, MF_GRAYED); @@ -2104,13 +2104,13 @@ void ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) , hwnd, NULL ); if (iCommand == ID_DISKMENU_EJECT) - DiskEject( iDrive ); + sg_DiskIICard.DiskEject( iDrive ); else if (iCommand == ID_DISKMENU_WRITEPROTECTION_ON) - DiskSetProtect( iDrive, true ); + sg_DiskIICard.DiskSetProtect( iDrive, true ); else if (iCommand == ID_DISKMENU_WRITEPROTECTION_OFF) - DiskSetProtect( iDrive, false ); + sg_DiskIICard.DiskSetProtect( iDrive, false ); else if (iCommand == ID_DISKMENU_SENDTO_CIDERPRESS) { @@ -2119,7 +2119,7 @@ void ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) "Please install CiderPress.\n" "Otherwise set the path to CiderPress from Configuration->Disk."; - DiskFlushCurrentTrack(iDrive); + sg_DiskIICard.DiskFlushCurrentTrack(iDrive); //if(!filename1.compare("\"\"") == false) //Do not use this, for some reason it does not work!!! if(!filename1.compare(sFileNameEmpty) ) @@ -2181,13 +2181,13 @@ void RelayEvent (UINT message, WPARAM wparam, LPARAM lparam) { // todo: consolidate CtrlReset() and ResetMachineState() void ResetMachineState () { - DiskReset(true); + sg_DiskIICard.DiskReset(true); HD_Reset(); g_bFullSpeed = 0; // Might've hit reset in middle of InternalCpuExecute() - so beep may get (partially) muted MemReset(); // calls CpuInitialize() PravetsReset(); - DiskBoot(); + sg_DiskIICard.DiskBoot(); VideoResetState(); sg_SSC.CommReset(); PrintReset(); @@ -2225,7 +2225,7 @@ void CtrlReset() } PravetsReset(); - DiskReset(); + sg_DiskIICard.DiskReset(); HD_Reset(); KeybReset(); sg_SSC.CommReset(); diff --git a/source/Memory.cpp b/source/Memory.cpp index b91a7c58..406fadfd 100644 --- a/source/Memory.cpp +++ b/source/Memory.cpp @@ -1692,7 +1692,7 @@ void MemInitializeIO(void) ConfigureSAM(pCxRomPeripheral, 5); // $C500 : Z80 card } - DiskLoadRom(pCxRomPeripheral, 6); // $C600 : Disk][ f/w + sg_DiskIICard.Initialize(pCxRomPeripheral, 6); // $C600 : Disk][ card HD_Load_Rom(pCxRomPeripheral, 7); // $C700 : HDD f/w // diff --git a/source/SaveState.cpp b/source/SaveState.cpp index 11537916..447423f8 100644 --- a/source/SaveState.cpp +++ b/source/SaveState.cpp @@ -286,9 +286,9 @@ static void ParseSlots(YamlLoadHelper& yamlLoadHelper, UINT unitVersion) bRes = Phasor_LoadSnapshot(yamlLoadHelper, slot, cardVersion); type = CT_Phasor; } - else if (card == DiskGetSnapshotCardName()) + else if (card == sg_DiskIICard.DiskGetSnapshotCardName()) { - bRes = DiskLoadSnapshot(yamlLoadHelper, slot, cardVersion); + bRes = sg_DiskIICard.DiskLoadSnapshot(yamlLoadHelper, slot, cardVersion); type = CT_Disk2; } else if (card == HD_GetSnapshotCardName()) @@ -391,7 +391,7 @@ static void Snapshot_LoadState_v2(void) MemReset(); PravetsReset(); - DiskReset(); + sg_DiskIICard.DiskReset(); HD_Reset(); KeybReset(); VideoResetState(); @@ -519,7 +519,7 @@ void Snapshot_SaveState(void) if (g_Slot4 == CT_Phasor) Phasor_SaveSnapshot(yamlSaveHelper, 4); - DiskSaveSnapshot(yamlSaveHelper); + sg_DiskIICard.DiskSaveSnapshot(yamlSaveHelper); HD_SaveSnapshot(yamlSaveHelper); } diff --git a/source/Video.cpp b/source/Video.cpp index f65d2168..147ce350 100644 --- a/source/Video.cpp +++ b/source/Video.cpp @@ -304,7 +304,7 @@ void VideoBenchmark () { while (cycles > 0) { DWORD executedcycles = CpuExecute(103, true); cycles -= executedcycles; - DiskUpdateDriveState(executedcycles); + sg_DiskIICard.DiskUpdateDriveState(executedcycles); JoyUpdateButtonLatch(executedcycles); } }