forked from AppleWin/AppleWin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisk.h
More file actions
211 lines (176 loc) · 6.23 KB
/
Copy pathDisk.h
File metadata and controls
211 lines (176 loc) · 6.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#pragma once
/*
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-2019, Tom Charlesworth, Michael Pohoreski, Nick Westgate
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"
extern class Disk2InterfaceCard sg_Disk2Card;
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;
class FloppyDisk
{
public:
FloppyDisk()
{
clear();
}
~FloppyDisk(){}
void clear()
{
ZeroMemory(m_imagename, sizeof(m_imagename));
ZeroMemory(m_fullname, sizeof(m_fullname));
m_strFilenameInZip.clear();
m_imagehandle = NULL;
m_bWriteProtected = false;
//
m_byte = 0;
m_nibbles = 0;
m_trackimage = NULL;
m_trackimagedata = false;
m_trackimagedirty = false;
}
public:
TCHAR m_imagename[ MAX_DISK_IMAGE_NAME + 1 ]; // <FILENAME> (ie. no extension)
TCHAR m_fullname [ MAX_DISK_FULL_NAME + 1 ]; // <FILENAME.EXT> or <FILENAME.zip> : This is persisted to the snapshot file
std::string m_strFilenameInZip; // "" or <FILENAME.EXT>
ImageInfo* m_imagehandle; // Init'd by InsertDisk() -> ImageOpen()
bool m_bWriteProtected;
int m_byte;
int m_nibbles; // Init'd by ReadTrack() -> ImageReadTrack()
LPBYTE m_trackimage;
bool m_trackimagedata;
bool m_trackimagedirty;
};
class FloppyDrive
{
public:
FloppyDrive()
{
clear();
}
~FloppyDrive(){}
void clear()
{
m_phase = 0;
m_track = 0;
m_spinning = 0;
m_writelight = 0;
m_disk.clear();
}
public:
int m_phase;
int m_track;
DWORD m_spinning;
DWORD m_writelight;
FloppyDisk m_disk;
};
class Disk2InterfaceCard
{
public:
Disk2InterfaceCard(void);
virtual ~Disk2InterfaceCard(void){}
void Initialize(LPBYTE pCxRomPeripheral, UINT uSlot);
void Destroy(void); // no, doesn't "destroy" the disk image. DiskIIManagerShutdown()
void Boot(void);
void FlushCurrentTrack(const int drive);
LPCTSTR GetFullDiskFilename(const int drive);
LPCTSTR GetFullName(const int drive);
LPCTSTR GetBaseName(const int drive);
void GetLightStatus (Disk_Status_e* pDisk1Status, Disk_Status_e* pDisk2Status);
ImageError_e InsertDisk(const int drive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary);
void EjectDisk(const int drive);
bool IsConditionForFullSpeed(void);
void NotifyInvalidImage(const int drive, LPCTSTR pszImageFilename, const ImageError_e Error);
void Reset(const bool bIsPowerCycle=false);
bool GetProtect(const int drive);
void SetProtect(const int drive, const bool bWriteProtect);
int GetCurrentDrive(void);
int GetCurrentTrack();
int GetTrack(const int drive);
int GetCurrentPhase(void);
int GetCurrentOffset(void);
LPCTSTR GetCurrentState(void);
bool UserSelectNewDiskImage(const int drive, LPCSTR pszFilename="");
void UpdateDriveState(DWORD cycles);
bool DriveSwap(void);
std::string GetSnapshotCardName(void);
void SaveSnapshot(class YamlSaveHelper& yamlSaveHelper);
bool LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version);
void LoadLastDiskImage(const int drive);
void SaveLastDiskImage(const int drive);
bool IsDiskImageWriteProtected(const int drive);
bool IsDriveEmpty(const int drive);
bool GetEnhanceDisk(void);
void SetEnhanceDisk(bool bEnhanceDisk);
static BYTE __stdcall IORead(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles);
static BYTE __stdcall IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles);
private:
void CheckSpinning(const ULONG nExecutedCycles);
Disk_Status_e GetDriveLightStatus(const int drive);
bool IsDriveValid(const int drive);
void AllocTrack(const int drive);
void ReadTrack(const int drive);
void RemoveDisk(const int drive);
void WriteTrack(const int drive);
LPCTSTR DiskGetFullPathName(const int drive);
void SaveSnapshotDisk2Unit(YamlSaveHelper& yamlSaveHelper, UINT unit);
void LoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, UINT unit);
void __stdcall ControlStepper(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles);
void __stdcall ControlMotor(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles);
void __stdcall Enable(WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles);
void __stdcall ReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles);
void __stdcall LoadWriteProtect(WORD, WORD, BYTE write, BYTE value, ULONG);
void __stdcall SetReadMode(WORD, WORD, BYTE, BYTE, ULONG);
void __stdcall SetWriteMode(WORD, WORD, BYTE, BYTE, ULONG uExecutedCycles);
#if LOG_DISK_NIBBLES_WRITE
bool LogWriteCheckSyncFF(ULONG& uCycleDelta);
#endif
//
WORD m_currDrive;
FloppyDrive m_floppyDrive[NUM_DRIVES];
BYTE m_floppyLatch;
BOOL m_floppyMotorOn;
BOOL m_floppyLoadMode; // for efficiency this is not used; it's extremely unlikely to affect emulation (nickw)
BOOL m_floppyWriteMode;
WORD m_phases; // state bits for stepper magnet phases 0 - 3
bool m_saveDiskImage;
UINT m_slot;
unsigned __int64 m_diskLastCycle;
unsigned __int64 m_diskLastReadLatchCycle;
FormatTrack m_formatTrack;
bool m_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 m_bLogDisk_NibblesRW; // From VS Debugger, change this to true/false during runtime for precise nibble logging
#endif
#if LOG_DISK_NIBBLES_WRITE
UINT64 m_uWriteLastCycle;
UINT m_uSyncFFCount;
#endif
};