Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Andrea Odetti 2018-03-03 17:59:09 +00:00
commit 5efc8ca461
12 changed files with 278 additions and 294 deletions

View file

@ -252,7 +252,7 @@ static void ContinueExecution(void)
const bool bWasFullSpeed = g_bFullSpeed;
g_bFullSpeed = (g_dwSpeed == SPEED_MAX) ||
bScrollLock_FullSpeed ||
(DiskIsSpinning() && enhancedisk && !Spkr_IsActive() && !MB_IsActive()) ||
(Disk_IsConditionForFullSpeed() && !Spkr_IsActive() && !MB_IsActive()) ||
IsDebugSteppingAtFullSpeed();
if (g_bFullSpeed)
@ -606,7 +606,10 @@ void LoadConfiguration(void)
}
REGLOAD(TEXT(REGVALUE_EMULATION_SPEED) ,&g_dwSpeed);
REGLOAD(TEXT(REGVALUE_ENHANCE_DISK_SPEED),(DWORD *)&enhancedisk);
DWORD dwEnhanceDisk;
REGLOAD(TEXT(REGVALUE_ENHANCE_DISK_SPEED), &dwEnhanceDisk);
Disk_SetEnhanceDisk(dwEnhanceDisk ? true : false);
Config_Load_Video();
@ -821,32 +824,45 @@ void RegisterExtensions(void)
//===========================================================================
void AppleWin_RegisterHotKeys(void)
{
BOOL bStatus = true;
BOOL bStatus[3] = {0,0,0};
bStatus &= RegisterHotKey(
bStatus[0] = RegisterHotKey(
g_hFrameWindow , // HWND hWnd
VK_SNAPSHOT_560, // int id (user/custom id)
0 , // UINT fsModifiers
VK_SNAPSHOT // UINT vk = PrintScreen
);
bStatus &= RegisterHotKey(
bStatus[1] = RegisterHotKey(
g_hFrameWindow , // HWND hWnd
VK_SNAPSHOT_280, // int id (user/custom id)
MOD_SHIFT , // UINT fsModifiers
VK_SNAPSHOT // UINT vk = PrintScreen
);
bStatus &= RegisterHotKey(
bStatus[2] = RegisterHotKey(
g_hFrameWindow , // HWND hWnd
VK_SNAPSHOT_TEXT, // int id (user/custom id)
MOD_CONTROL , // UINT fsModifiers
VK_SNAPSHOT // UINT vk = PrintScreen
);
if (!bStatus && g_bShowPrintScreenWarningDialog)
if ((!bStatus[0] || !bStatus[1] || !bStatus[2]))
{
MessageBox( g_hFrameWindow, "Unable to capture PrintScreen key", "Warning", MB_OK );
std::string msg("Unable to register for PrintScreen key(s):\n");
if (!bStatus[0])
msg += "\n. PrintScreen";
if (!bStatus[1])
msg += "\n. Shift+PrintScreen";
if (!bStatus[2])
msg += "\n. Ctrl+PrintScreen";
if (g_bShowPrintScreenWarningDialog)
MessageBox( g_hFrameWindow, msg.c_str(), "Warning", MB_ICONASTERISK | MB_OK );
msg += "\n";
LogFileOutput(msg.c_str());
}
}

View file

@ -502,29 +502,6 @@ ULONG CpuGetCyclesThisVideoFrame(const ULONG nExecutedCycles)
}
#endif
//---------------------------------------------------------------------------
static DWORD g_dwEmulationTime_ms = 0;
static void UpdateEmulationTime(const DWORD dwExecutedCycles)
{
static DWORD dwEmulationTimeFrac_clks = 0;
const DWORD CLKS_PER_MS = (DWORD)g_fCurrentCLK6502 / 1000;
dwEmulationTimeFrac_clks += dwExecutedCycles;
if (dwEmulationTimeFrac_clks > CLKS_PER_MS)
{
g_dwEmulationTime_ms += dwEmulationTimeFrac_clks / CLKS_PER_MS;
dwEmulationTimeFrac_clks %= CLKS_PER_MS;
}
}
DWORD CpuGetEmulationTime_ms(void)
{
return g_dwEmulationTime_ms;
}
//===========================================================================
DWORD CpuExecute(const DWORD uCycles, const bool bVideoUpdate)
@ -540,7 +517,6 @@ DWORD CpuExecute(const DWORD uCycles, const bool bVideoUpdate)
MB_UpdateCycles(uExecutedCycles); // Update 6522s (NB. Do this before updating g_nCumulativeCycles below)
// NB. Ensures that 6522 regs are up-to-date for any potential save-state
UpdateEmulationTime(uExecutedCycles);
//

View file

@ -34,8 +34,6 @@ void CpuLoadSnapshot(class YamlLoadHelper& yamlLoadHelper);
BYTE CpuRead(USHORT addr, ULONG uExecutedCycles);
void CpuWrite(USHORT addr, BYTE a, ULONG uExecutedCycles);
DWORD CpuGetEmulationTime_ms(void);
enum eCpuType {CPU_UNKNOWN=0, CPU_6502=1, CPU_65C02, CPU_Z80}; // Don't change! Persisted to Registry
eCpuType GetMainCpu(void);

View file

@ -2,7 +2,7 @@
#include "../Applewin.h"
#include "../CPU.h"
#include "../Disk.h" // BOOL enhancedisk
#include "../DiskImage.h" // Disk_Status_e
#include "../Harddisk.h" // HD_CardIsEnabled()
class CConfigNeedingRestart
@ -11,7 +11,6 @@ public:
CConfigNeedingRestart(UINT bEnableTheFreezesF8Rom = false) :
m_Apple2Type( GetApple2Type() ),
m_CpuType( GetMainCpu() ),
m_bEnhanceDisk(enhancedisk),
m_uSaveLoadStateMsg(0)
{
m_bEnableHDD = HD_CardIsEnabled();
@ -27,7 +26,6 @@ public:
m_Apple2Type = other.m_Apple2Type;
m_CpuType = other.m_CpuType;
memcpy(m_Slot, other.m_Slot, sizeof(m_Slot));
m_bEnhanceDisk = other.m_bEnhanceDisk;
m_bEnableHDD = other.m_bEnableHDD;
m_bEnableTheFreezesF8Rom = other.m_bEnableTheFreezesF8Rom;
m_uSaveLoadStateMsg = other.m_uSaveLoadStateMsg;
@ -39,7 +37,6 @@ public:
return m_Apple2Type == other.m_Apple2Type &&
m_CpuType == other.m_CpuType &&
memcmp(m_Slot, other.m_Slot, sizeof(m_Slot)) == 0 &&
m_bEnhanceDisk == other.m_bEnhanceDisk &&
m_bEnableHDD == other.m_bEnableHDD &&
m_bEnableTheFreezesF8Rom == other.m_bEnableTheFreezesF8Rom &&
m_uSaveLoadStateMsg == other.m_uSaveLoadStateMsg;
@ -54,7 +51,6 @@ public:
eCpuType m_CpuType;
SS_CARDTYPE m_Slot[NUM_SLOTS]; // 0..7
SS_CARDTYPE m_SlotAux;
BOOL m_bEnhanceDisk;
bool m_bEnableHDD;
UINT m_bEnableTheFreezesF8Rom;
UINT m_uSaveLoadStateMsg;

View file

@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "StdAfx.h"
#include "../Applewin.h"
#include "../Disk.h" // Drive_e, Disk_Status_e
#include "../Frame.h"
#include "../Registry.h"
#include "../resource/resource.h"
@ -127,7 +128,7 @@ BOOL CPageDisk::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM l
case WM_INITDIALOG:
{
m_PropertySheetHelper.FillComboBox(hWnd, IDC_DISKTYPE, m_discchoices, enhancedisk);
m_PropertySheetHelper.FillComboBox(hWnd, IDC_DISKTYPE, m_discchoices, Disk_GetEnhanceDisk() ? 1 : 0);
m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_DISK1, m_defaultDiskOptions, -1);
m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_DISK2, m_defaultDiskOptions, -1);
m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_HDD1, m_defaultHDDOptions, -1);
@ -177,10 +178,11 @@ BOOL CPageDisk::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM l
void CPageDisk::DlgOK(HWND hWnd)
{
const BOOL bNewEnhanceDisk = (BOOL) SendDlgItemMessage(hWnd, IDC_DISKTYPE,CB_GETCURSEL, 0, 0);
if (bNewEnhanceDisk != enhancedisk)
const bool bNewEnhanceDisk = SendDlgItemMessage(hWnd, IDC_DISKTYPE,CB_GETCURSEL, 0, 0) ? true : false;
if (bNewEnhanceDisk != Disk_GetEnhanceDisk())
{
m_PropertySheetHelper.GetConfigNew().m_bEnhanceDisk = bNewEnhanceDisk;
Disk_SetEnhanceDisk(bNewEnhanceDisk);
REGSAVE(TEXT(REGVALUE_ENHANCE_DISK_SPEED), (DWORD)bNewEnhanceDisk);
}
const bool bNewHDDIsEnabled = IsDlgButtonChecked(hWnd, IDC_HDD_ENABLE) ? true : false;

View file

@ -47,7 +47,6 @@ Input
Sound
. MB/Phasor/SAM/None WM_USER_RESTART
Disk
. Enhanced disk speed WM_USER_RESTART Why? (used to patch Disk][ f/w - but not anymore)
. HDD enable WM_USER_RESTART
Advanced
. Save State WM_USER_SAVESTATE
@ -399,9 +398,6 @@ void CPropertySheetHelper::ApplyNewConfig(const CConfigNeedingRestart& ConfigNew
if (CONFIG_CHANGED_LOCAL(m_Slot[5]))
SetSlot5(ConfigNew.m_Slot[5]);
if (CONFIG_CHANGED_LOCAL(m_bEnhanceDisk))
REGSAVE(TEXT(REGVALUE_ENHANCE_DISK_SPEED), ConfigNew.m_bEnhanceDisk);
if (CONFIG_CHANGED_LOCAL(m_bEnableHDD))
{
REGSAVE(TEXT(REGVALUE_HDD_ENABLED), ConfigNew.m_bEnableHDD ? 1 : 0);
@ -425,7 +421,6 @@ void CPropertySheetHelper::SaveCurrentConfig(void)
m_ConfigOld.m_CpuType = GetMainCpu();
m_ConfigOld.m_Slot[4] = g_Slot4;
m_ConfigOld.m_Slot[5] = g_Slot5;
m_ConfigOld.m_bEnhanceDisk = enhancedisk;
m_ConfigOld.m_bEnableHDD = HD_CardIsEnabled();
m_ConfigOld.m_bEnableTheFreezesF8Rom = sg_PropertySheet.GetTheFreezesF8Rom();
@ -444,7 +439,6 @@ void CPropertySheetHelper::RestoreCurrentConfig(void)
SetMainCpu(m_ConfigOld.m_CpuType);
g_Slot4 = m_ConfigOld.m_Slot[4];
g_Slot5 = m_ConfigOld.m_Slot[5];
enhancedisk = m_ConfigOld.m_bEnhanceDisk;
HD_SetEnabled(m_ConfigOld.m_bEnableHDD);
sg_PropertySheet.SetTheFreezesF8Rom(m_ConfigOld.m_bEnableTheFreezesF8Rom);
}
@ -503,9 +497,6 @@ bool CPropertySheetHelper::HardwareConfigChanged(HWND hWnd)
if (CONFIG_CHANGED(m_Slot[5]))
strMsgMain += GetSlot(5);
if (CONFIG_CHANGED(m_bEnhanceDisk))
strMsgMain += ". Floppy disk speed setting has changed\n";
if (CONFIG_CHANGED(m_bEnableHDD))
strMsgMain += ". Harddisk(s) have been plugged/unplugged\n";

View file

@ -51,14 +51,33 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
static bool g_bLogDisk_NibblesRW = false; // From VS Debugger, change this to true/false during runtime for precise nibble logging
#endif
// Public _________________________________________________________________________________________
BOOL enhancedisk = 1; // TODO: Make static & add accessor funcs
// Private ________________________________________________________________________________________
struct Drive_t
{
int phase;
int track;
DWORD spinning;
DWORD writelight;
Disk_t disk;
Drive_t()
{
clear();
}
void clear()
{
phase = 0;
track = 0;
spinning = 0;
writelight = 0;
disk.clear();
}
};
static WORD currdrive = 0;
static Disk_t g_aFloppyDisk[NUM_DRIVES];
static Drive_t g_aFloppyDrive[NUM_DRIVES];
static BYTE floppylatch = 0;
static BOOL floppymotoron = 0;
static BOOL floppyloadmode = 0; // for efficiency this is not used; it's extremely unlikely to affect emulation (nickw)
@ -79,34 +98,39 @@ static LPCTSTR DiskGetFullPathName(const int iDrive);
#define SPINNING_CYCLES (20000*64) // 1280000 cycles = 1.25s
#define WRITELIGHT_CYCLES (20000*64) // 1280000 cycles = 1.25s
static bool enhancedisk = true;
//===========================================================================
bool Disk_GetEnhanceDisk(void) { return enhancedisk; }
void Disk_SetEnhanceDisk(bool bEnhanceDisk) { enhancedisk = bEnhanceDisk; }
int DiskGetCurrentDrive(void) { return currdrive; }
int DiskGetCurrentTrack(void) { return g_aFloppyDisk[currdrive].track; }
int DiskGetCurrentPhase(void) { return g_aFloppyDisk[currdrive].phase; }
int DiskGetCurrentOffset(void) { return g_aFloppyDisk[currdrive].byte; }
int DiskGetTrack( int drive ) { return g_aFloppyDisk[ drive ].track; }
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; }
const char* DiskGetDiskPathFilename(const int iDrive)
{
return g_aFloppyDisk[iDrive].fullname;
return g_aFloppyDrive[iDrive].disk.fullname;
}
const char* DiskGetCurrentState(void)
{
if (g_aFloppyDisk[currdrive].imagehandle == NULL)
if (g_aFloppyDrive[currdrive].disk.imagehandle == NULL)
return "Empty";
if (!floppymotoron)
{
if (g_aFloppyDisk[currdrive].spinning > 0)
if (g_aFloppyDrive[currdrive].spinning > 0)
return "Off (spinning)";
else
return "Off";
}
else if (floppywritemode)
{
if (g_aFloppyDisk[currdrive].bWriteProtected)
if (g_aFloppyDrive[currdrive].disk.bWriteProtected)
return "Writing (write protected)";
else
return "Writing";
@ -115,7 +139,7 @@ const char* DiskGetCurrentState(void)
{
/*if (floppyloadmode)
{
if (g_aFloppyDisk[currdrive].bWriteProtected)
if (g_aFloppyDrive[currdrive].disk.bWriteProtected)
return "Reading write protect state (write protected)";
else
return "Reading write protect state (not write protected)";
@ -158,7 +182,7 @@ void Disk_SaveLastDiskImage(const int iDrive)
if (!g_bSaveDiskImage)
return;
const char *pFileName = g_aFloppyDisk[iDrive].fullname;
const char *pFileName = g_aFloppyDrive[iDrive].disk.fullname;
if (iDrive == DRIVE_1)
RegSaveString(TEXT(REG_PREFS), REGVALUE_PREF_LAST_DISK_1, TRUE, pFileName);
@ -182,10 +206,10 @@ void Disk_SaveLastDiskImage(const int iDrive)
// Called by DiskControlMotor() & DiskEnable()
static void CheckSpinning(const ULONG nCyclesLeft)
{
DWORD modechange = (floppymotoron && !g_aFloppyDisk[currdrive].spinning);
DWORD modechange = (floppymotoron && !g_aFloppyDrive[currdrive].spinning);
if (floppymotoron)
g_aFloppyDisk[currdrive].spinning = SPINNING_CYCLES;
g_aFloppyDrive[currdrive].spinning = SPINNING_CYCLES;
if (modechange)
FrameDrawDiskLEDS( (HDC)0 );
@ -204,21 +228,23 @@ static Disk_Status_e GetDriveLightStatus(const int iDrive)
{
if (IsDriveValid( iDrive ))
{
Disk_t *pFloppy = & g_aFloppyDisk[ iDrive ];
Drive_t* pDrive = &g_aFloppyDrive[ iDrive ];
if (pFloppy->spinning)
if (pDrive->spinning)
{
if (pFloppy->bWriteProtected)
if (pDrive->disk.bWriteProtected)
return DISK_STATUS_PROT;
if (pFloppy->writelight)
if (pDrive->writelight)
return DISK_STATUS_WRITE;
else
return DISK_STATUS_READ;
}
else
{
return DISK_STATUS_OFF;
}
}
return DISK_STATUS_OFF;
}
@ -234,8 +260,8 @@ static bool IsDriveValid(const int iDrive)
static void AllocTrack(const int iDrive)
{
Disk_t * fptr = &g_aFloppyDisk[iDrive];
fptr->trackimage = (LPBYTE)VirtualAlloc(NULL, NIBBLES_PER_TRACK, MEM_COMMIT, PAGE_READWRITE);
Disk_t* pFloppy = &g_aFloppyDrive[iDrive].disk;
pFloppy->trackimage = (LPBYTE)VirtualAlloc(NULL, NIBBLES_PER_TRACK, MEM_COMMIT, PAGE_READWRITE);
}
//===========================================================================
@ -245,9 +271,10 @@ static void ReadTrack(const int iDrive)
if (! IsDriveValid( iDrive ))
return;
Disk_t *pFloppy = &g_aFloppyDisk[ iDrive ];
Drive_t* pDrive = &g_aFloppyDrive[ iDrive ];
Disk_t* pFloppy = &pDrive->disk;
if (pFloppy->track >= ImageGetNumTracks(pFloppy->imagehandle))
if (pDrive->track >= ImageGetNumTracks(pFloppy->imagehandle))
{
pFloppy->trackimagedata = 0;
return;
@ -259,12 +286,12 @@ static void ReadTrack(const int iDrive)
if (pFloppy->trackimage && pFloppy->imagehandle)
{
#if LOG_DISK_TRACKS
LOG_DISK("track $%02X%s read\r\n", pFloppy->track, (pFloppy->phase & 1) ? ".5" : " ");
LOG_DISK("track $%02X%s read\r\n", pDrive->track, (pDrive->phase & 1) ? ".5" : " ");
#endif
ImageReadTrack(
pFloppy->imagehandle,
pFloppy->track,
pFloppy->phase,
pDrive->track,
pDrive->phase,
pFloppy->trackimage,
&pFloppy->nibbles);
@ -277,7 +304,7 @@ static void ReadTrack(const int iDrive)
void DiskFlushCurrentTrack(const int iDrive)
{
Disk_t *pFloppy = &g_aFloppyDisk[iDrive];
Disk_t* pFloppy = &g_aFloppyDrive[iDrive].disk;
if (pFloppy->trackimage && pFloppy->trackimagedirty)
WriteTrack(iDrive);
@ -287,7 +314,7 @@ void DiskFlushCurrentTrack(const int iDrive)
static void RemoveDisk(const int iDrive)
{
Disk_t *pFloppy = &g_aFloppyDisk[iDrive];
Disk_t* pFloppy = &g_aFloppyDrive[iDrive].disk;
if (pFloppy->imagehandle)
{
@ -316,9 +343,10 @@ static void RemoveDisk(const int iDrive)
static void WriteTrack(const int iDrive)
{
Disk_t *pFloppy = &g_aFloppyDisk[ iDrive ];
Drive_t* pDrive = &g_aFloppyDrive[ iDrive ];
Disk_t* pFloppy = &pDrive->disk;
if (pFloppy->track >= ImageGetNumTracks(pFloppy->imagehandle))
if (pDrive->track >= ImageGetNumTracks(pFloppy->imagehandle))
return;
if (pFloppy->bWriteProtected)
@ -327,12 +355,12 @@ static void WriteTrack(const int iDrive)
if (pFloppy->trackimage && pFloppy->imagehandle)
{
#if LOG_DISK_TRACKS
LOG_DISK("track $%02X%s write\r\n", pFloppy->track, (pFloppy->phase & 0) ? ".5" : " "); // TODO: hard-coded to whole tracks - see below (nickw)
LOG_DISK("track $%02X%s write\r\n", pDrive->track, (pDrive->phase & 0) ? ".5" : " "); // TODO: hard-coded to whole tracks - see below (nickw)
#endif
ImageWriteTrack(
pFloppy->imagehandle,
pFloppy->track,
pFloppy->phase, // TODO: this should never be used; it's the current phase (half-track), not that of the track to be written (nickw)
pDrive->track,
pDrive->phase, // TODO: this should never be used; it's the current phase (half-track), not that of the track to be written (nickw)
pFloppy->trackimage,
pFloppy->nibbles);
}
@ -350,7 +378,7 @@ void 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.
if (g_aFloppyDisk[0].imagehandle && ImageBoot(g_aFloppyDisk[0].imagehandle))
if (g_aFloppyDrive[0].disk.imagehandle && ImageBoot(g_aFloppyDrive[0].disk.imagehandle))
floppymotoron = 0;
}
@ -376,11 +404,12 @@ static void __stdcall DiskControlMotor(WORD, WORD address, BYTE, BYTE, ULONG uEx
static void __stdcall DiskControlStepper(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles)
{
Disk_t * fptr = &g_aFloppyDisk[currdrive];
Drive_t* pDrive = &g_aFloppyDrive[currdrive];
Disk_t* pFloppy = &pDrive->disk;
if (!floppymotoron) // GH#525
{
if (!fptr->spinning)
if (!pDrive->spinning)
{
#if LOG_DISK_PHASES
LOG_DISK("stepper accessed whilst motor is off and not spinning\r\n");
@ -415,23 +444,23 @@ static void __stdcall DiskControlStepper(WORD, WORD address, BYTE, BYTE, ULONG u
// - do not move if both adjacent magnets are on
// momentum and timing are not accounted for ... maybe one day!
int direction = 0;
if (phases & (1 << ((fptr->phase + 1) & 3)))
if (phases & (1 << ((pDrive->phase + 1) & 3)))
direction += 1;
if (phases & (1 << ((fptr->phase + 3) & 3)))
if (phases & (1 << ((pDrive->phase + 3) & 3)))
direction -= 1;
// apply magnet step, if any
if (direction)
{
fptr->phase = MAX(0, MIN(79, fptr->phase + direction));
const int nNumTracksInImage = ImageGetNumTracks(fptr->imagehandle);
pDrive->phase = MAX(0, MIN(79, pDrive->phase + direction));
const int nNumTracksInImage = ImageGetNumTracks(pFloppy->imagehandle);
const int newtrack = (nNumTracksInImage == 0) ? 0
: MIN(nNumTracksInImage-1, fptr->phase >> 1); // (round half tracks down)
if (newtrack != fptr->track)
: MIN(nNumTracksInImage-1, pDrive->phase >> 1); // (round half tracks down)
if (newtrack != pDrive->track)
{
DiskFlushCurrentTrack(currdrive);
fptr->track = newtrack;
fptr->trackimagedata = 0;
pDrive->track = newtrack;
pFloppy->trackimagedata = 0;
g_formatTrack.DriveNotWritingTrack();
}
@ -446,8 +475,8 @@ static void __stdcall DiskControlStepper(WORD, WORD address, BYTE, BYTE, ULONG u
#if LOG_DISK_PHASES
LOG_DISK("track $%02X%s phases %d%d%d%d phase %d %s address $%4X\r\n",
fptr->phase >> 1,
(fptr->phase & 1) ? ".5" : " ",
pDrive->phase >> 1,
(pDrive->phase & 1) ? ".5" : " ",
(phases >> 3) & 1,
(phases >> 2) & 1,
(phases >> 1) & 1,
@ -479,8 +508,8 @@ static void __stdcall DiskEnable(WORD, WORD address, BYTE, BYTE, ULONG uExecuted
#if LOG_DISK_ENABLE_DRIVE
LOG_DISK("enable drive: %d\r\n", currdrive);
#endif
g_aFloppyDisk[!currdrive].spinning = 0;
g_aFloppyDisk[!currdrive].writelight = 0;
g_aFloppyDrive[!currdrive].spinning = 0;
g_aFloppyDrive[!currdrive].writelight = 0;
CheckSpinning(uExecutedCycles);
}
@ -500,39 +529,39 @@ void DiskEject(const int iDrive)
// . Used by Property Sheet Page (Disk)
LPCTSTR DiskGetFullName(const int iDrive)
{
return g_aFloppyDisk[iDrive].fullname;
return g_aFloppyDrive[iDrive].disk.fullname;
}
// Return the filename
// . Used by Drive Buttons' tooltips
LPCTSTR DiskGetFullDiskFilename(const int iDrive)
{
if (!g_aFloppyDisk[iDrive].strFilenameInZip.empty())
return g_aFloppyDisk[iDrive].strFilenameInZip.c_str();
if (!g_aFloppyDrive[iDrive].disk.strFilenameInZip.empty())
return g_aFloppyDrive[iDrive].disk.strFilenameInZip.c_str();
return DiskGetFullName(iDrive);
}
static LPCTSTR DiskGetFullPathName(const int iDrive)
{
return ImageGetPathname(g_aFloppyDisk[iDrive].imagehandle);
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)
{
return g_aFloppyDisk[iDrive].imagename;
return g_aFloppyDrive[iDrive].disk.imagename;
}
//===========================================================================
void DiskGetLightStatus(Disk_Status_e *pDisk1Status_, Disk_Status_e *pDisk2Status_)
void DiskGetLightStatus(Disk_Status_e *pDisk1Status, Disk_Status_e *pDisk2Status)
{
if (pDisk1Status_)
*pDisk1Status_ = GetDriveLightStatus( 0 );
if (pDisk1Status)
*pDisk1Status = GetDriveLightStatus(DRIVE_1);
if (pDisk2Status_)
*pDisk2Status_ = GetDriveLightStatus( 1 );
if (pDisk2Status)
*pDisk2Status = GetDriveLightStatus(DRIVE_2);
}
//===========================================================================
@ -541,32 +570,34 @@ void DiskInitialize(void)
{
int loop = NUM_DRIVES;
while (loop--)
g_aFloppyDisk[loop].clear();
g_aFloppyDrive[loop].clear();
}
//===========================================================================
ImageError_e DiskInsert(const int iDrive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary)
{
Disk_t * fptr = &g_aFloppyDisk[iDrive];
if (fptr->imagehandle)
Drive_t* pDrive = &g_aFloppyDrive[iDrive];
Disk_t* pFloppy = &pDrive->disk;
if (pFloppy->imagehandle)
RemoveDisk(iDrive);
// Reset the drive's struct, but preserve the physical attributes (bug#18242: Platoon)
// . Changing the disk (in the drive) doesn't affect the drive's head etc.
{
int track = fptr->track;
int phase = fptr->phase;
fptr->clear();
fptr->track = track;
fptr->phase = phase;
int track = pDrive->track;
int phase = pDrive->phase;
pDrive->clear();
pDrive->track = track;
pDrive->phase = phase;
}
const DWORD dwAttributes = GetFileAttributes(pszImageFilename);
if(dwAttributes == INVALID_FILE_ATTRIBUTES)
fptr->bWriteProtected = false; // Assume this is a new file to create
pFloppy->bWriteProtected = false; // Assume this is a new file to create
else
fptr->bWriteProtected = bForceWriteProtected ? true : (dwAttributes & FILE_ATTRIBUTE_READONLY);
pFloppy->bWriteProtected = bForceWriteProtected ? true : (dwAttributes & FILE_ATTRIBUTE_READONLY);
// Check if image is being used by the other drive, and if so remove it in order so it can be swapped
{
@ -585,16 +616,16 @@ ImageError_e DiskInsert(const int iDrive, LPCTSTR pszImageFilename, const bool b
}
ImageError_e Error = ImageOpen(pszImageFilename,
&fptr->imagehandle,
&fptr->bWriteProtected,
&pFloppy->imagehandle,
&pFloppy->bWriteProtected,
bCreateIfNecessary,
fptr->strFilenameInZip);
pFloppy->strFilenameInZip);
if (Error == eIMAGE_ERROR_NONE && ImageIsMultiFileZip(fptr->imagehandle))
if (Error == eIMAGE_ERROR_NONE && ImageIsMultiFileZip(pFloppy->imagehandle))
{
TCHAR szText[100+MAX_PATH];
szText[sizeof(szText)-1] = 0;
_snprintf(szText, sizeof(szText)-1, "Only the first file in a multi-file zip is supported\nUse disk image '%s' ?", fptr->strFilenameInZip.c_str());
_snprintf(szText, sizeof(szText)-1, "Only the first file in a multi-file zip is supported\nUse disk image '%s' ?", pFloppy->strFilenameInZip.c_str());
int nRes = MessageBox(g_hFrameWindow, szText, TEXT("Multi-Zip Warning"), MB_ICONWARNING | MB_YESNO | MB_SETFOREGROUND);
if (nRes == IDNO)
{
@ -605,8 +636,8 @@ ImageError_e DiskInsert(const int iDrive, LPCTSTR pszImageFilename, const bool b
if (Error == eIMAGE_ERROR_NONE)
{
GetImageTitle(pszImageFilename, fptr->imagename, fptr->fullname);
Video_ResetScreenshotCounter(fptr->imagename);
GetImageTitle(pszImageFilename, pFloppy->imagename, pFloppy->fullname);
Video_ResetScreenshotCounter(pFloppy->imagename);
}
else
{
@ -620,6 +651,11 @@ ImageError_e DiskInsert(const int iDrive, LPCTSTR pszImageFilename, const bool b
//===========================================================================
bool Disk_IsConditionForFullSpeed(void)
{
return floppymotoron && enhancedisk;
}
BOOL DiskIsSpinning(void)
{
return floppymotoron;
@ -689,7 +725,7 @@ void DiskNotifyInvalidImage(const int iDrive, LPCTSTR pszImageFilename, const Im
TEXT("first file (%s) in this multi-zip archive is not recognized.\n")
TEXT("Try unzipping and using the disk images directly.\n"),
pszImageFilename,
g_aFloppyDisk[iDrive].strFilenameInZip.c_str());
g_aFloppyDrive[iDrive].disk.strFilenameInZip.c_str());
break;
case eIMAGE_ERROR_GZ:
@ -745,10 +781,10 @@ bool DiskGetProtect(const int iDrive)
{
if (IsDriveValid(iDrive))
{
Disk_t *pFloppy = &g_aFloppyDisk[ iDrive ];
if (pFloppy->bWriteProtected)
if (g_aFloppyDrive[iDrive].disk.bWriteProtected)
return true;
}
return false;
}
@ -759,8 +795,7 @@ void DiskSetProtect(const int iDrive, const bool bWriteProtect)
{
if (IsDriveValid( iDrive ))
{
Disk_t *pFloppy = &g_aFloppyDisk[ iDrive ];
pFloppy->bWriteProtected = bWriteProtect;
g_aFloppyDrive[iDrive].disk.bWriteProtected = bWriteProtect;
}
}
@ -772,8 +807,7 @@ bool Disk_ImageIsWriteProtected(const int iDrive)
if (!IsDriveValid(iDrive))
return true;
Disk_t *pFloppy = &g_aFloppyDisk[iDrive];
return ImageIsWriteProtected(pFloppy->imagehandle);
return ImageIsWriteProtected(g_aFloppyDrive[iDrive].disk.imagehandle);
}
//===========================================================================
@ -783,8 +817,7 @@ bool Disk_IsDriveEmpty(const int iDrive)
if (!IsDriveValid(iDrive))
return true;
Disk_t *pFloppy = &g_aFloppyDisk[iDrive];
return pFloppy->imagehandle == NULL;
return g_aFloppyDrive[iDrive].disk.imagehandle == NULL;
}
//===========================================================================
@ -826,12 +859,13 @@ static bool LogWriteCheckSyncFF(ULONG& uCycleDelta)
static void __stdcall DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft)
{
/* floppyloadmode = 0; */
Disk_t * fptr = &g_aFloppyDisk[currdrive];
Drive_t* pDrive = &g_aFloppyDrive[currdrive];
Disk_t* pFloppy = &pDrive->disk;
if (!fptr->trackimagedata && fptr->imagehandle)
if (!pFloppy->trackimagedata && pFloppy->imagehandle)
ReadTrack(currdrive);
if (!fptr->trackimagedata)
if (!pFloppy->trackimagedata)
{
floppylatch = 0xFF;
return;
@ -841,7 +875,7 @@ static void __stdcall DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULO
UINT uSpinNibbleCount = 0;
CpuCalcCycles(nCyclesLeft); // g_nCumulativeCycles required for uSpinNibbleCount & LogWriteCheckSyncFF()
if (!enhancedisk && fptr->spinning)
if (!enhancedisk && pDrive->spinning)
{
const ULONG nCycleDiff = (ULONG) (g_nCumulativeCycles - g_uDiskLastCycle);
g_uDiskLastCycle = g_nCumulativeCycles;
@ -851,13 +885,13 @@ static void __stdcall DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULO
// 40 cycles for a write of a 10-bit 0xFF sync byte
uSpinNibbleCount = nCycleDiff >> 5; // ...but divide by 32 (not 40)
ULONG uWrapOffset = uSpinNibbleCount % fptr->nibbles;
fptr->byte += uWrapOffset;
if (fptr->byte >= fptr->nibbles)
fptr->byte -= fptr->nibbles;
ULONG uWrapOffset = uSpinNibbleCount % pFloppy->nibbles;
pFloppy->byte += uWrapOffset;
if (pFloppy->byte >= pFloppy->nibbles)
pFloppy->byte -= pFloppy->nibbles;
#if LOG_DISK_NIBBLES_SPIN
UINT uCompleteRevolutions = uSpinNibbleCount / fptr->nibbles;
UINT uCompleteRevolutions = uSpinNibbleCount / pFloppy->nibbles;
LOG_DISK("spin: revs=%d, nibbles=%d\r\n", uCompleteRevolutions, uWrapOffset);
#endif
}
@ -867,23 +901,23 @@ static void __stdcall DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULO
// but Sherwood Forest sets shift mode and reads with the drive off, so don't check for now
if (!floppywritemode)
{
floppylatch = *(fptr->trackimage + fptr->byte);
floppylatch = *(pFloppy->trackimage + pFloppy->byte);
#if LOG_DISK_NIBBLES_READ
#if LOG_DISK_NIBBLES_USE_RUNTIME_VAR
if (g_bLogDisk_NibblesRW)
#endif
{
LOG_DISK("read %04X = %02X\r\n", fptr->byte, floppylatch);
LOG_DISK("read %04X = %02X\r\n", pFloppy->byte, floppylatch);
}
g_formatTrack.DecodeLatchNibbleRead(floppylatch);
#endif
}
else if (!fptr->bWriteProtected) // && floppywritemode
else if (!pFloppy->bWriteProtected) // && floppywritemode
{
*(fptr->trackimage + fptr->byte) = floppylatch;
fptr->trackimagedirty = 1;
*(pFloppy->trackimage + pFloppy->byte) = floppylatch;
pFloppy->trackimagedirty = 1;
bool bIsSyncFF = false;
#if LOG_DISK_NIBBLES_WRITE
@ -891,7 +925,7 @@ static void __stdcall DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULO
bIsSyncFF = LogWriteCheckSyncFF(uCycleDelta);
#endif
g_formatTrack.DecodeLatchNibbleWrite(floppylatch, uSpinNibbleCount, fptr, bIsSyncFF); // GH#125
g_formatTrack.DecodeLatchNibbleWrite(floppylatch, uSpinNibbleCount, pFloppy, bIsSyncFF); // GH#125
#if LOG_DISK_NIBBLES_WRITE
#if LOG_DISK_NIBBLES_USE_RUNTIME_VAR
@ -899,20 +933,20 @@ static void __stdcall DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULO
#endif
{
if (!bIsSyncFF)
LOG_DISK("write %04X = %02X (cy=+%d)\r\n", fptr->byte, floppylatch, uCycleDelta);
LOG_DISK("write %04X = %02X (cy=+%d)\r\n", pFloppy->byte, floppylatch, uCycleDelta);
else
LOG_DISK("write %04X = %02X (cy=+%d) sync #%d\r\n", fptr->byte, floppylatch, uCycleDelta, g_uSyncFFCount);
LOG_DISK("write %04X = %02X (cy=+%d) sync #%d\r\n", pFloppy->byte, floppylatch, uCycleDelta, g_uSyncFFCount);
}
#endif
}
if (++fptr->byte >= fptr->nibbles)
fptr->byte = 0;
if (++pFloppy->byte >= pFloppy->nibbles)
pFloppy->byte = 0;
// Feature Request #201 Show track status
// https://github.com/AppleWin/AppleWin/issues/201
// NB. Prevent flooding of forcing UI to redraw!!!
if( ((fptr->byte) & 0xFF) == 0 )
if( ((pFloppy->byte) & 0xFF) == 0 )
FrameDrawDiskStatus( (HDC)0 );
}
@ -931,10 +965,10 @@ void DiskReset(const bool bIsPowerCycle/*=false*/)
if (bIsPowerCycle) // GH#460
{
g_aFloppyDisk[DRIVE_1].spinning = 0;
g_aFloppyDisk[DRIVE_1].writelight = 0;
g_aFloppyDisk[DRIVE_2].spinning = 0;
g_aFloppyDisk[DRIVE_2].writelight = 0;
g_aFloppyDrive[DRIVE_1].spinning = 0;
g_aFloppyDrive[DRIVE_1].writelight = 0;
g_aFloppyDrive[DRIVE_2].spinning = 0;
g_aFloppyDrive[DRIVE_2].writelight = 0;
FrameRefreshStatus(DRAW_LEDS, false);
}
@ -1012,7 +1046,7 @@ static void __stdcall DiskLoadWriteProtect(WORD, WORD, BYTE write, BYTE value, U
// . write mode doesn't prevent reading write protect (GH#537):
// "If for some reason the above write protect check were entered with the READ/WRITE switch in WRITE,
// the write protect switch would still be read correctly" (UTAIIe page 9-21)
if (g_aFloppyDisk[currdrive].bWriteProtected)
if (g_aFloppyDrive[currdrive].disk.bWriteProtected)
floppylatch |= 0x80;
else
floppylatch &= 0x7F;
@ -1025,7 +1059,7 @@ static void __stdcall DiskSetReadMode(WORD, WORD, BYTE, BYTE, ULONG)
{
floppywritemode = 0;
g_formatTrack.DriveSwitchedToReadMode(&g_aFloppyDisk[currdrive]);
g_formatTrack.DriveSwitchedToReadMode(&g_aFloppyDrive[currdrive].disk);
#if LOG_DISK_RW_MODE
LOG_DISK("rw mode: read\r\n");
@ -1038,9 +1072,9 @@ static void __stdcall DiskSetWriteMode(WORD, WORD, BYTE, BYTE, ULONG uExecutedCy
{
floppywritemode = 1;
g_formatTrack.DriveSwitchedToWriteMode(g_aFloppyDisk[currdrive].byte);
g_formatTrack.DriveSwitchedToWriteMode(g_aFloppyDrive[currdrive].disk.byte);
BOOL modechange = !g_aFloppyDisk[currdrive].writelight;
BOOL modechange = !g_aFloppyDrive[currdrive].writelight;
#if LOG_DISK_RW_MODE
LOG_DISK("rw mode: write (mode changed=%d)\r\n", modechange ? 1 : 0);
#endif
@ -1048,7 +1082,7 @@ static void __stdcall DiskSetWriteMode(WORD, WORD, BYTE, BYTE, ULONG uExecutedCy
g_uWriteLastCycle = 0;
#endif
g_aFloppyDisk[currdrive].writelight = WRITELIGHT_CYCLES;
g_aFloppyDrive[currdrive].writelight = WRITELIGHT_CYCLES;
if (modechange)
FrameDrawDiskLEDS( (HDC)0 );
@ -1061,24 +1095,24 @@ void DiskUpdateDriveState(DWORD cycles)
int loop = NUM_DRIVES;
while (loop--)
{
Disk_t * fptr = &g_aFloppyDisk[loop];
Drive_t* pDrive = &g_aFloppyDrive[loop];
if (fptr->spinning && !floppymotoron)
if (pDrive->spinning && !floppymotoron)
{
if (!(fptr->spinning -= MIN(fptr->spinning, cycles)))
if (!(pDrive->spinning -= MIN(pDrive->spinning, cycles)))
{
FrameDrawDiskLEDS( (HDC)0 );
FrameDrawDiskStatus( (HDC)0 );
}
}
if (floppywritemode && (currdrive == loop) && fptr->spinning)
if (floppywritemode && (currdrive == loop) && pDrive->spinning)
{
fptr->writelight = WRITELIGHT_CYCLES;
pDrive->writelight = WRITELIGHT_CYCLES;
}
else if (fptr->writelight)
else if (pDrive->writelight)
{
if (!(fptr->writelight -= MIN(fptr->writelight, cycles)))
if (!(pDrive->writelight -= MIN(pDrive->writelight, cycles)))
{
FrameDrawDiskLEDS( (HDC)0 );
FrameDrawDiskStatus( (HDC)0 );
@ -1093,7 +1127,7 @@ bool DiskDriveSwap(void)
{
// Refuse to swap if either Disk][ is active
// TODO: if Shift-Click then FORCE drive swap to bypass message
if(g_aFloppyDisk[0].spinning || g_aFloppyDisk[1].spinning)
if (g_aFloppyDrive[0].spinning || g_aFloppyDrive[1].spinning)
{
// 1.26.2.4 Prompt when trying to swap disks while drive is on instead of silently failing
int status = MessageBox(
@ -1125,8 +1159,7 @@ bool DiskDriveSwap(void)
// Swap disks between drives
// . NB. We swap trackimage ptrs (so don't need to swap the buffers' data)
// . TODO: Consider array of Pointers: Disk_t* g_aDrive[]
std::swap(g_aFloppyDisk[0], g_aFloppyDisk[1]);
std::swap(g_aFloppyDrive[0].disk, g_aFloppyDrive[1].disk);
Disk_SaveLastDiskImage(DRIVE_1);
Disk_SaveLastDiskImage(DRIVE_2);
@ -1247,7 +1280,7 @@ int DiskSetSnapshot_v1(const SS_CARD_DISK2* const pSS)
phases = pSS->phases;
currdrive = pSS->currdrive;
//diskaccessed = pSS->diskaccessed; // deprecated
enhancedisk = pSS->enhancedisk;
enhancedisk = pSS->enhancedisk ? true : false;
floppylatch = pSS->floppylatch;
floppymotoron = pSS->floppymotoron;
floppywritemode = pSS->floppywritemode;
@ -1256,7 +1289,7 @@ int DiskSetSnapshot_v1(const SS_CARD_DISK2* const pSS)
for(UINT i=0; i<NUM_DRIVES; i++)
{
DiskEject(i); // Remove any disk & update Registry to reflect empty drive
g_aFloppyDisk[i].clear();
g_aFloppyDrive[i].clear();
}
for(UINT i=0; i<NUM_DRIVES; i++)
@ -1287,35 +1320,36 @@ int DiskSetSnapshot_v1(const SS_CARD_DISK2* const pSS)
//
// strcpy(g_aFloppyDisk[i].fullname, pSS->Unit[i].szFileName);
g_aFloppyDisk[i].track = pSS->Unit[i].track;
g_aFloppyDisk[i].phase = pSS->Unit[i].phase;
g_aFloppyDisk[i].byte = pSS->Unit[i].byte;
// g_aFloppyDisk[i].writeprotected = pSS->Unit[i].writeprotected;
g_aFloppyDisk[i].trackimagedata = pSS->Unit[i].trackimagedata;
g_aFloppyDisk[i].trackimagedirty = pSS->Unit[i].trackimagedirty;
g_aFloppyDisk[i].spinning = pSS->Unit[i].spinning;
g_aFloppyDisk[i].writelight = pSS->Unit[i].writelight;
g_aFloppyDisk[i].nibbles = pSS->Unit[i].nibbles;
// strcpy(g_aFloppyDrive[i].fullname, pSS->Unit[i].szFileName);
g_aFloppyDrive[i].track = pSS->Unit[i].track;
g_aFloppyDrive[i].phase = pSS->Unit[i].phase;
g_aFloppyDrive[i].spinning = pSS->Unit[i].spinning;
g_aFloppyDrive[i].writelight = pSS->Unit[i].writelight;
g_aFloppyDrive[i].disk.byte = pSS->Unit[i].byte;
// g_aFloppyDrive[i].disk.writeprotected = pSS->Unit[i].writeprotected;
g_aFloppyDrive[i].disk.trackimagedata = pSS->Unit[i].trackimagedata ? true : false;
g_aFloppyDrive[i].disk.trackimagedirty = pSS->Unit[i].trackimagedirty ? true : false;
g_aFloppyDrive[i].disk.nibbles = pSS->Unit[i].nibbles;
//
if(!bImageError)
{
if((g_aFloppyDisk[i].trackimage == NULL) && g_aFloppyDisk[i].nibbles)
if((g_aFloppyDrive[i].disk.trackimage == NULL) && g_aFloppyDrive[i].disk.nibbles)
AllocTrack(i);
if(g_aFloppyDisk[i].trackimage == NULL)
if(g_aFloppyDrive[i].disk.trackimage == NULL)
bImageError = true;
else
memcpy(g_aFloppyDisk[i].trackimage, pSS->Unit[i].nTrack, NIBBLES_PER_TRACK);
memcpy(g_aFloppyDrive[i].disk.trackimage, pSS->Unit[i].nTrack, NIBBLES_PER_TRACK);
}
if(bImageError)
{
g_aFloppyDisk[i].trackimagedata = 0;
g_aFloppyDisk[i].trackimagedirty = 0;
g_aFloppyDisk[i].nibbles = 0;
g_aFloppyDrive[i].disk.trackimagedata = 0;
g_aFloppyDrive[i].disk.trackimagedirty = 0;
g_aFloppyDrive[i].disk.nibbles = 0;
}
}
@ -1363,21 +1397,21 @@ std::string DiskGetSnapshotCardName(void)
static void DiskSaveSnapshotDisk2Unit(YamlSaveHelper& yamlSaveHelper, UINT unit)
{
YamlSaveHelper::Label label(yamlSaveHelper, "%s%d:\n", SS_YAML_KEY_DISK2UNIT, unit);
yamlSaveHelper.SaveString(SS_YAML_KEY_FILENAME, g_aFloppyDisk[unit].fullname);
yamlSaveHelper.SaveUint(SS_YAML_KEY_TRACK, g_aFloppyDisk[unit].track);
yamlSaveHelper.SaveUint(SS_YAML_KEY_PHASE, g_aFloppyDisk[unit].phase);
yamlSaveHelper.SaveHexUint16(SS_YAML_KEY_BYTE, g_aFloppyDisk[unit].byte);
yamlSaveHelper.SaveBool(SS_YAML_KEY_WRITE_PROTECTED, g_aFloppyDisk[unit].bWriteProtected);
yamlSaveHelper.SaveUint(SS_YAML_KEY_SPINNING, g_aFloppyDisk[unit].spinning);
yamlSaveHelper.SaveUint(SS_YAML_KEY_WRITE_LIGHT, g_aFloppyDisk[unit].writelight);
yamlSaveHelper.SaveHexUint16(SS_YAML_KEY_NIBBLES, g_aFloppyDisk[unit].nibbles);
yamlSaveHelper.SaveUint(SS_YAML_KEY_TRACK_IMAGE_DATA, g_aFloppyDisk[unit].trackimagedata);
yamlSaveHelper.SaveUint(SS_YAML_KEY_TRACK_IMAGE_DIRTY, g_aFloppyDisk[unit].trackimagedirty);
yamlSaveHelper.SaveString(SS_YAML_KEY_FILENAME, g_aFloppyDrive[unit].disk.fullname);
yamlSaveHelper.SaveUint(SS_YAML_KEY_TRACK, g_aFloppyDrive[unit].track);
yamlSaveHelper.SaveUint(SS_YAML_KEY_PHASE, g_aFloppyDrive[unit].phase);
yamlSaveHelper.SaveHexUint16(SS_YAML_KEY_BYTE, g_aFloppyDrive[unit].disk.byte);
yamlSaveHelper.SaveBool(SS_YAML_KEY_WRITE_PROTECTED, g_aFloppyDrive[unit].disk.bWriteProtected);
yamlSaveHelper.SaveUint(SS_YAML_KEY_SPINNING, g_aFloppyDrive[unit].spinning);
yamlSaveHelper.SaveUint(SS_YAML_KEY_WRITE_LIGHT, g_aFloppyDrive[unit].writelight);
yamlSaveHelper.SaveHexUint16(SS_YAML_KEY_NIBBLES, g_aFloppyDrive[unit].disk.nibbles);
yamlSaveHelper.SaveUint(SS_YAML_KEY_TRACK_IMAGE_DATA, g_aFloppyDrive[unit].disk.trackimagedata);
yamlSaveHelper.SaveUint(SS_YAML_KEY_TRACK_IMAGE_DIRTY, g_aFloppyDrive[unit].disk.trackimagedirty);
if (g_aFloppyDisk[unit].trackimage)
if (g_aFloppyDrive[unit].disk.trackimage)
{
YamlSaveHelper::Label image(yamlSaveHelper, "%s:\n", SS_YAML_KEY_TRACK_IMAGE);
yamlSaveHelper.SaveMemory(g_aFloppyDisk[unit].trackimage, NIBBLES_PER_TRACK);
yamlSaveHelper.SaveMemory(g_aFloppyDrive[unit].disk.trackimage, NIBBLES_PER_TRACK);
}
}
@ -1389,7 +1423,7 @@ void DiskSaveSnapshot(class YamlSaveHelper& yamlSaveHelper)
yamlSaveHelper.SaveHexUint4(SS_YAML_KEY_PHASES, phases);
yamlSaveHelper.SaveUint(SS_YAML_KEY_CURRENT_DRIVE, currdrive);
yamlSaveHelper.SaveBool(SS_YAML_KEY_DISK_ACCESSED, false); // deprecated
yamlSaveHelper.SaveBool(SS_YAML_KEY_ENHANCE_DISK, enhancedisk == TRUE);
yamlSaveHelper.SaveBool(SS_YAML_KEY_ENHANCE_DISK, enhancedisk);
yamlSaveHelper.SaveHexUint8(SS_YAML_KEY_FLOPPY_LATCH, floppylatch);
yamlSaveHelper.SaveBool(SS_YAML_KEY_FLOPPY_MOTOR_ON, floppymotoron == TRUE);
yamlSaveHelper.SaveBool(SS_YAML_KEY_FLOPPY_WRITE_MODE, floppywritemode == TRUE);
@ -1408,9 +1442,9 @@ static void DiskLoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, UINT unit)
bool bImageError = false;
g_aFloppyDisk[unit].fullname[0] = 0;
g_aFloppyDisk[unit].imagename[0] = 0;
g_aFloppyDisk[unit].bWriteProtected = false; // Default to false (until image is successfully loaded below)
g_aFloppyDrive[unit].disk.fullname[0] = 0;
g_aFloppyDrive[unit].disk.imagename[0] = 0;
g_aFloppyDrive[unit].disk.bWriteProtected = false; // Default to false (until image is successfully loaded below)
std::string filename = yamlLoadHelper.LoadString(SS_YAML_KEY_FILENAME);
if (!filename.empty())
@ -1430,22 +1464,22 @@ static void DiskLoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, UINT unit)
if(DiskInsert(unit, filename.c_str(), dwAttributes & FILE_ATTRIBUTE_READONLY, IMAGE_DONT_CREATE) != eIMAGE_ERROR_NONE)
bImageError = true;
// DiskInsert() zeros g_aFloppyDisk[unit], then sets up:
// DiskInsert() zeros g_aFloppyDrive[unit], then sets up:
// . imagename
// . fullname
// . writeprotected
}
}
g_aFloppyDisk[unit].track = yamlLoadHelper.LoadUint(SS_YAML_KEY_TRACK);
g_aFloppyDisk[unit].phase = yamlLoadHelper.LoadUint(SS_YAML_KEY_PHASE);
g_aFloppyDisk[unit].byte = yamlLoadHelper.LoadUint(SS_YAML_KEY_BYTE);
g_aFloppyDrive[unit].track = yamlLoadHelper.LoadUint(SS_YAML_KEY_TRACK);
g_aFloppyDrive[unit].phase = yamlLoadHelper.LoadUint(SS_YAML_KEY_PHASE);
g_aFloppyDrive[unit].disk.byte = yamlLoadHelper.LoadUint(SS_YAML_KEY_BYTE);
yamlLoadHelper.LoadBool(SS_YAML_KEY_WRITE_PROTECTED); // Consume
g_aFloppyDisk[unit].spinning = yamlLoadHelper.LoadUint(SS_YAML_KEY_SPINNING);
g_aFloppyDisk[unit].writelight = yamlLoadHelper.LoadUint(SS_YAML_KEY_WRITE_LIGHT);
g_aFloppyDisk[unit].nibbles = yamlLoadHelper.LoadUint(SS_YAML_KEY_NIBBLES);
g_aFloppyDisk[unit].trackimagedata = yamlLoadHelper.LoadUint(SS_YAML_KEY_TRACK_IMAGE_DATA);
g_aFloppyDisk[unit].trackimagedirty = yamlLoadHelper.LoadUint(SS_YAML_KEY_TRACK_IMAGE_DIRTY);
g_aFloppyDrive[unit].spinning = yamlLoadHelper.LoadUint(SS_YAML_KEY_SPINNING);
g_aFloppyDrive[unit].writelight = yamlLoadHelper.LoadUint(SS_YAML_KEY_WRITE_LIGHT);
g_aFloppyDrive[unit].disk.nibbles = yamlLoadHelper.LoadUint(SS_YAML_KEY_NIBBLES);
g_aFloppyDrive[unit].disk.trackimagedata = yamlLoadHelper.LoadUint(SS_YAML_KEY_TRACK_IMAGE_DATA) ? true : false;
g_aFloppyDrive[unit].disk.trackimagedirty = yamlLoadHelper.LoadUint(SS_YAML_KEY_TRACK_IMAGE_DIRTY) ? true : false;
std::vector<BYTE> track(NIBBLES_PER_TRACK);
if (yamlLoadHelper.GetSubMap(SS_YAML_KEY_TRACK_IMAGE))
@ -1460,20 +1494,20 @@ static void DiskLoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, UINT unit)
if (!filename.empty() && !bImageError)
{
if ((g_aFloppyDisk[unit].trackimage == NULL) && g_aFloppyDisk[unit].nibbles)
if ((g_aFloppyDrive[unit].disk.trackimage == NULL) && g_aFloppyDrive[unit].disk.nibbles)
AllocTrack(unit);
if (g_aFloppyDisk[unit].trackimage == NULL)
if (g_aFloppyDrive[unit].disk.trackimage == NULL)
bImageError = true;
else
memcpy(g_aFloppyDisk[unit].trackimage, &track[0], NIBBLES_PER_TRACK);
memcpy(g_aFloppyDrive[unit].disk.trackimage, &track[0], NIBBLES_PER_TRACK);
}
if (bImageError)
{
g_aFloppyDisk[unit].trackimagedata = 0;
g_aFloppyDisk[unit].trackimagedirty = 0;
g_aFloppyDisk[unit].nibbles = 0;
g_aFloppyDrive[unit].disk.trackimagedata = 0;
g_aFloppyDrive[unit].disk.trackimagedirty = 0;
g_aFloppyDrive[unit].disk.nibbles = 0;
}
}
@ -1503,7 +1537,7 @@ bool DiskLoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT vers
for(UINT i=0; i<NUM_DRIVES; i++)
{
DiskEject(i); // Remove any disk & update Registry to reflect empty drive
g_aFloppyDisk[i].clear();
g_aFloppyDrive[i].clear();
}
DiskLoadSnapshotDriveUnit(yamlLoadHelper, DRIVE_1);

View file

@ -39,7 +39,6 @@ const bool IMAGE_FORCE_WRITE_PROTECTED = true;
const bool IMAGE_DONT_CREATE = false;
const bool IMAGE_CREATE = true;
extern BOOL enhancedisk;
const char* DiskGetDiskPathFilename(const int iDrive);
void DiskInitialize(void); // DiskIIManagerStartup()
@ -53,9 +52,10 @@ LPCTSTR DiskGetFullName(const int iDrive);
LPCTSTR DiskGetFullDiskFilename(const int iDrive);
LPCTSTR DiskGetBaseName(const int iDrive);
void DiskGetLightStatus (Disk_Status_e *pDisk1Status_, Disk_Status_e *pDisk2Status_);
void DiskGetLightStatus (Disk_Status_e* pDisk1Status, Disk_Status_e* pDisk2Status);
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);
@ -83,6 +83,9 @@ void Disk_SaveLastDiskImage(const int iDrive);
bool Disk_ImageIsWriteProtected(const int iDrive);
bool Disk_IsDriveEmpty(const int iDrive);
bool Disk_GetEnhanceDisk(void);
void Disk_SetEnhanceDisk(bool bEnhanceDisk);
//
// For sharing with class FormatTrack
@ -94,15 +97,11 @@ struct Disk_t
ImageInfo* imagehandle; // Init'd by DiskInsert() -> ImageOpen()
bool bWriteProtected;
//
int track;
LPBYTE trackimage;
int phase;
int byte;
BOOL trackimagedata;
BOOL trackimagedirty;
DWORD spinning;
DWORD writelight;
int nibbles; // Init'd by ReadTrack() -> ImageReadTrack()
LPBYTE trackimage;
bool trackimagedata;
bool trackimagedirty;
Disk_t()
{
@ -116,14 +115,11 @@ struct Disk_t
strFilenameInZip.clear();
imagehandle = NULL;
bWriteProtected = false;
track = 0;
trackimage = NULL;
phase = 0;
//
byte = 0;
trackimagedata = FALSE;
trackimagedirty = FALSE;
spinning = 0;
writelight = 0;
nibbles = 0;
trackimage = NULL;
trackimagedata = false;
trackimagedirty = false;
}
};

View file

@ -84,15 +84,15 @@ void FormatTrack::DriveNotWritingTrack(void)
#endif
}
void FormatTrack::UpdateOnWriteLatch(UINT uSpinNibbleCount, const Disk_t* const fptr)
void FormatTrack::UpdateOnWriteLatch(UINT uSpinNibbleCount, const Disk_t* const pFloppy)
{
if (fptr->bWriteProtected)
if (pFloppy->bWriteProtected)
return;
if (m_bmWrittenSectorAddrFields == 0x0000)
{
if (m_WriteTrackStartIndex == (UINT)-1) // waiting for 1st write?
m_WriteTrackStartIndex = fptr->byte;
m_WriteTrackStartIndex = pFloppy->byte;
return;
}
@ -108,8 +108,8 @@ void FormatTrack::UpdateOnWriteLatch(UINT uSpinNibbleCount, const Disk_t* const
return;
}
UINT uTrackIndex = fptr->byte;
const UINT& kTrackMaxNibbles = fptr->nibbles;
UINT uTrackIndex = pFloppy->byte;
const UINT& kTrackMaxNibbles = pFloppy->nibbles;
// NB. spin in write mode is only max 1-2 bytes
do
@ -128,7 +128,7 @@ void FormatTrack::UpdateOnWriteLatch(UINT uSpinNibbleCount, const Disk_t* const
while (uSpinNibbleCount--);
}
void FormatTrack::DriveSwitchedToReadMode(Disk_t* const fptr)
void FormatTrack::DriveSwitchedToReadMode(Disk_t* const pFloppy)
{
if (m_bAddressPrologueIsDOS3_2)
{
@ -154,10 +154,10 @@ void FormatTrack::DriveSwitchedToReadMode(Disk_t* const fptr)
// So need a track size between 0x18B0 (rounding down) and 0x182F
const UINT kShortTrackLen = 0x18B0;
LPBYTE TrackBuffer = fptr->trackimage;
const UINT kLongTrackLen = fptr->nibbles;
LPBYTE TrackBuffer = pFloppy->trackimage;
const UINT kLongTrackLen = pFloppy->nibbles;
UINT uWriteTrackEndIndex = fptr->byte;
UINT uWriteTrackEndIndex = pFloppy->byte;
UINT uWrittenTrackSize = m_WriteTrackHasWrapped ? kLongTrackLen : 0;
if (m_WriteTrackStartIndex <= uWriteTrackEndIndex)
@ -216,10 +216,10 @@ void FormatTrack::DecodeLatchNibbleRead(BYTE floppylatch)
DecodeLatchNibble(floppylatch, false, false);
}
void FormatTrack::DecodeLatchNibbleWrite(BYTE floppylatch, UINT uSpinNibbleCount, const Disk_t* const fptr, bool bIsSyncFF)
void FormatTrack::DecodeLatchNibbleWrite(BYTE floppylatch, UINT uSpinNibbleCount, const Disk_t* const pFloppy, bool bIsSyncFF)
{
DecodeLatchNibble(floppylatch, true, bIsSyncFF);
UpdateOnWriteLatch(uSpinNibbleCount, fptr);
UpdateOnWriteLatch(uSpinNibbleCount, pFloppy);
}
void FormatTrack::DecodeLatchNibble(BYTE floppylatch, bool bIsWrite, bool bIsSyncFF)

View file

@ -35,15 +35,15 @@ public:
void Reset(void);
void DriveNotWritingTrack(void);
void DriveSwitchedToReadMode(Disk_t* const fptr);
void DriveSwitchedToReadMode(Disk_t* const pFloppy);
void DriveSwitchedToWriteMode(UINT uTrackIndex);
void DecodeLatchNibbleRead(BYTE floppylatch);
void DecodeLatchNibbleWrite(BYTE floppylatch, UINT uSpinNibbleCount, const Disk_t* const fptr, bool bIsSyncFF);
void DecodeLatchNibbleWrite(BYTE floppylatch, UINT uSpinNibbleCount, const Disk_t* const pFloppy, bool bIsSyncFF);
void SaveSnapshot(class YamlSaveHelper& yamlSaveHelper);
void LoadSnapshot(class YamlLoadHelper& yamlLoadHelper);
private:
void UpdateOnWriteLatch(UINT uSpinNibbleCount, const Disk_t* const fptr);
void UpdateOnWriteLatch(UINT uSpinNibbleCount, const Disk_t* const pFloppy);
void DecodeLatchNibble(BYTE floppylatch, bool bIsWrite, bool bIsSyncFF);
BYTE m_VolTrkSecChk[4];

View file

@ -635,7 +635,7 @@ public:
{
ReadTrack(pImageInfo, nTrack, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE);
*pNibbles = NibblizeTrack(pTrackImageBuffer, eDOSOrder, nTrack);
if (!enhancedisk)
if (!Disk_GetEnhanceDisk())
SkewTrack(nTrack, *pNibbles, pTrackImageBuffer);
}
@ -701,7 +701,7 @@ public:
{
ReadTrack(pImageInfo, nTrack, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE);
*pNibbles = NibblizeTrack(pTrackImageBuffer, eProDOSOrder, nTrack);
if (!enhancedisk)
if (!Disk_GetEnhanceDisk())
SkewTrack(nTrack, *pNibbles, pTrackImageBuffer);
}

View file

@ -30,6 +30,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "Applewin.h"
#include "CPU.h"
#include "Disk.h" // DiskUpdateDriveState()
#include "Frame.h"
#include "Keyboard.h"
#include "Memory.h"
@ -591,28 +592,6 @@ void VideoRedrawScreen (void)
//===========================================================================
// NB. Can get "big" 1000+ms times: these occur during disk loading when the emulator is at full-speed.
//#define DEBUG_REFRESH_TIMINGS
#if defined(_DEBUG) && defined(DEBUG_REFRESH_TIMINGS)
static void DebugRefresh(char uDebugFlag)
{
static DWORD uLastRefreshTime = 0;
const DWORD dwEmuTime_ms = CpuGetEmulationTime_ms();
const DWORD uTimeBetweenRefreshes = uLastRefreshTime ? dwEmuTime_ms - uLastRefreshTime : 0;
uLastRefreshTime = dwEmuTime_ms;
if (!uTimeBetweenRefreshes)
return; // 1st time in func
char szStr[100];
sprintf(szStr, "Time between refreshes = %d ms %c\n", uTimeBetweenRefreshes, (uDebugFlag==0)?' ':uDebugFlag);
OutputDebugString(szStr);
}
#endif
// TC: Hacky-fix for GH#341 - better to draw to the correct position in the framebuffer to start with! (in NTSC.cpp)
static void VideoFrameBufferAdjust(int& xSrc, int& ySrc, bool bInvertY=false)
{
@ -640,10 +619,6 @@ static void VideoFrameBufferAdjust(int& xSrc, int& ySrc, bool bInvertY=false)
void VideoRefreshScreen ( uint32_t uRedrawWholeScreenVideoMode /* =0*/, bool bRedrawWholeScreen /* =false*/ )
{
#if defined(_DEBUG) && defined(DEBUG_REFRESH_TIMINGS)
DebugRefresh(0);
#endif
if (bRedrawWholeScreen || g_nAppMode == MODE_PAUSED)
{
// uVideoModeForWholeScreen set if: