AppleWin/source/Disk.h

212 lines
6.9 KiB
C
Raw Normal View History

2006-02-25 20:50:29 +00:00
#pragma once
2010-12-18 20:58:29 +00:00
/*
AppleWin : An Apple //e emulator for Windows
Copyright (C) 1994-1996, Michael O'Brien
Copyright (C) 1999-2001, Oliver Schmidt
Copyright (C) 2002-2005, Tom Charlesworth
Copyright (C) 2006-2010, Tom Charlesworth, Michael Pohoreski
AppleWin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
AppleWin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with AppleWin; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "DiskLog.h"
#include "DiskFormatTrack.h"
#include "DiskImage.h"
2006-02-25 20:50:29 +00:00
extern class DiskIIInterfaceCard sg_DiskIICard;
2010-12-18 20:58:29 +00:00
// Floppy Disk Drives
enum Drive_e
{
DRIVE_1 = 0,
DRIVE_2,
NUM_DRIVES
};
const bool IMAGE_USE_FILES_WRITE_PROTECT_STATUS = false;
const bool IMAGE_FORCE_WRITE_PROTECTED = true;
const bool IMAGE_DONT_CREATE = false;
const bool IMAGE_CREATE = true;
2006-02-25 20:50:29 +00:00
struct Disk_t
{
TCHAR imagename[ MAX_DISK_IMAGE_NAME + 1 ]; // <FILENAME> (ie. no extension)
TCHAR fullname [ MAX_DISK_FULL_NAME + 1 ]; // <FILENAME.EXT> or <FILENAME.zip> : This is persisted to the snapshot file
std::string strFilenameInZip; // "" or <FILENAME.EXT>
ImageInfo* imagehandle; // Init'd by DiskInsert() -> ImageOpen()
bool bWriteProtected;
//
int byte;
int nibbles; // Init'd by ReadTrack() -> ImageReadTrack()
LPBYTE trackimage;
bool trackimagedata;
bool trackimagedirty;
Disk_t()
{
clear();
}
void clear()
{
ZeroMemory(imagename, sizeof(imagename));
ZeroMemory(fullname, sizeof(fullname));
strFilenameInZip.clear();
imagehandle = NULL;
bWriteProtected = false;
//
byte = 0;
nibbles = 0;
trackimage = NULL;
trackimagedata = false;
trackimagedirty = false;
}
};
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();
}
};
class DiskIIInterfaceCard
{
public:
DiskIIInterfaceCard(void);
virtual ~DiskIIInterfaceCard(void){};
const char* DiskGetDiskPathFilename(const int iDrive);
void DiskInitialize(void); // DiskIIManagerStartup()
void DiskDestroy(void); // no, doesn't "destroy" the disk image. DiskIIManagerShutdown()
void DiskBoot(void);
void DiskEject(const int iDrive);
void DiskFlushCurrentTrack(const int iDrive);
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);
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);
std::string DiskGetSnapshotCardName(void);
void DiskSaveSnapshot(class YamlSaveHelper& yamlSaveHelper);
bool DiskLoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version);
void Disk_LoadLastDiskImage(const int iDrive);
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);
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);
#endif
//
WORD currdrive;
Drive_t g_aFloppyDrive[NUM_DRIVES];
BYTE floppylatch;
BOOL floppymotoron;
BOOL floppyloadmode; // for efficiency this is not used; it's extremely unlikely to affect emulation (nickw)
BOOL floppywritemode;
WORD phases; // state bits for stepper magnet phases 0 - 3
bool g_bSaveDiskImage;
UINT g_uSlot;
unsigned __int64 g_uDiskLastCycle;
unsigned __int64 g_uDiskLastReadLatchCycle;
FormatTrack g_formatTrack;
bool enhancedisk;
static const UINT SPINNING_CYCLES = 20000*64; // 1280000 cycles = 1.25s
static const UINT WRITELIGHT_CYCLES = 20000*64; // 1280000 cycles = 1.25s
// Debug:
#if LOG_DISK_NIBBLES_USE_RUNTIME_VAR
bool g_bLogDisk_NibblesRW; // From VS Debugger, change this to true/false during runtime for precise nibble logging
#endif
#if LOG_DISK_NIBBLES_WRITE
UINT64 g_uWriteLastCycle;
UINT g_uSyncFFCount;
#endif
};