-
Notifications
You must be signed in to change notification settings - Fork 3
/
DiskBase.h
133 lines (111 loc) · 3.18 KB
/
DiskBase.h
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
//Virtual base class for disk device/image
#ifndef _DISK_BASE_
#define _DISK_BASE_
#include "types.h"
#include <malloc.h>
#include <math.h>
#include <string.h>
#define DEF_RETRY_CNT 5
class CDiskBase
{
public:
static const byte MAX_SECT_PER_TRACK = 32; //Maximum sector count on a track
typedef bool (ProgressCallbackType)(word item, word totalItems, bool haveError);
typedef enum
{
ERR_OK,
ERR_NOT_SUPPORTED,
ERR_OPEN,
ERR_READ,
ERR_WRITE,
ERR_SEEK,
ERR_PARAM,
ERR_ITEM_CNT
} ErrorType;
typedef enum
{
DISK_DATARATE_HD, //high
DISK_DATARATE_DD_5_25,//double for 5.25
DISK_DATARATE_DD_3_5, //double for 3.5
DISK_DATARATE_ED //extra density
} DiskDensType;
typedef enum
{
SECT_SZ_128 = 128,
SECT_SZ_256 = 256,
SECT_SZ_512 = 512,
SECT_SZ_1024 = 1024,
SECT_SZ_2048 = 2048,
SECT_SZ_4096 = 4096,
} DiskSectType;
typedef enum
{
OPEN_MODE_EXISTING,
OPEN_MODE_CREATE
} DiskOpenMode;
typedef struct
{
byte track;
byte head;
byte sectID;
byte sectSizeCode;
} SectDescType;
struct DiskDescType
{
byte TrackCnt;
byte SideCnt;
byte SPT;
DiskSectType SectSize;
byte Filler;
byte GapFmt;
DiskDensType Density;
byte HWInterleave;
};
CDiskBase();
CDiskBase(byte tracks, byte spt, byte sides = 2, DiskSectType st = SECT_SZ_512, DiskDensType dens = DISK_DATARATE_DD_3_5,
byte filler = 0xE5, byte gap = 0x16);
CDiskBase(DiskDescType dd);
CDiskBase(const CDiskBase& src);
virtual ~CDiskBase();
//128 = 0; 256 = 1; 512 = 2; 1024 = 3, etc.
static DiskSectType SectCode2SectSize(byte sectCode) { return (DiskSectType)(128 * (1 << sectCode)); }
static byte SectSize2SectCode(DiskSectType sectSize)
{
word lg2 = 0, x = sectSize/128;
while ((x = x >> 1) > 0)
lg2++;
return (byte)lg2;
}
virtual bool ReadSectors(byte * buff, byte track, byte side, byte sector, byte sectCnt)=0;
virtual bool WriteSectors(byte track, byte side, byte sector, byte sectCnt, byte * buff)=0;
virtual bool FormatTrack(byte track, byte side)=0;
virtual bool FormatDisk();
virtual bool Seek(byte trackNo)=0;
virtual bool GetTrackInfo(byte track, byte side, byte& sectorCnt, SectDescType sectors[])=0;
virtual bool Open(char* src, DiskOpenMode)=0;
virtual bool ReadTrack(byte* buff, byte track, byte head);
virtual bool WriteTrack(byte track, byte head, byte* buff);
bool CopyTo(CDiskBase* dest, bool formatDst = false);
virtual bool GetDiskInfo(byte& trkCnt, byte& sideCnt, char* comment = NULL);
bool DetectDiskGeometry(DiskDescType& dd);
bool CreateInterleaveTable();
byte CalculateInterleaveFactor();
void SetContinueOnError(bool doIgnore) { continueOnError = doIgnore; }
void SetProgressCallback(ProgressCallbackType* callback) { progCallback = callback; }
ErrorType GetLastError(char* errMsg)
{
if (errMsg != NULL)
strcpy(errMsg, ERROR_TYPE_MSG[LastError]);
return LastError;
}
DiskDescType DiskDefinition;
char* diskCmnt;
protected:
byte m_Skew; //Sector IDs for hardware interleave
byte InterlaveTbl[MAX_SECT_PER_TRACK];
static char* ERROR_TYPE_MSG[];
ErrorType LastError;
bool continueOnError = true;
ProgressCallbackType* progCallback = nullptr;
};
#endif//_DISK_BASE_