-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpxdisk.h
209 lines (179 loc) · 7.62 KB
/
pxdisk.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
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
// pxdisk.h
/// Based on pxDisk copyright(c) 2019 William R Cooke
bool console = false;
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define BOARD_MEGA
#define BOARDTEXT "Mega2560"
#define PXPORT Serial2 // pin 16 & 17
//#define DEBUG true // Change to true for debugging
#define DEBUGPORT Serial // pin 0 & 1 and USB port
#define CS_PIN 53 // SD card CS pin
#define D_LED 9
#define E_LED 10
#define F_LED 11
#define G_LED 12
#define DEBUGLED 13
#endif
// The Pro Micro is equal to the Micro or Leonardo but smaller (and cheaper)
#if defined(__AVR_ATmega32U4__)
#define BOARD_MICRO
#define BOARDTEXT "Pro_Micro"
#define PXPORT Serial1 // pin 0 & 1
//#define DEBUG true // Change to true for debugging
#define DEBUGPORT Serial // USB port
#define CS_PIN 10 // SD card CS pin
#define D_LED 2
#define E_LED 3
#define F_LED 4
#define G_LED 5
#define DEBUGLED 6
#endif
#define MAX_TEXT 128
#define DEBUGBAUDRATE 115200
#define PXBAUDRATE 38400
//////////////////////////////////////////////////////////////////////////////
/// Special characters used by the state machine.
//////////////////////////////////////////////////////////////////////////////
enum Characters
{
C_SOH = 0x01, /// < Start of Header
C_STX = 0x02, /// < Start of Text
C_ETX = 0x03, /// < End of Text
C_EOT = 0x04, /// < End of Transmission
C_ENQ = 0x05, /// < Enquiry
C_ACK = 0x06, /// < Acknowledge
C_NAK = 0x15, /// < Negative Acknowledge
C_FMT_MS = 0x00, /// < Format message from Master to Slave
C_FMT_SM = 0x01, /// < Format message from Slave to Master
C_SEL = 0x31, /// < Select command
};
const byte MY_ID_1 = 0x31; /// < Id of first drive unit
const byte MY_ID_2 = 0x32; /// < Id of second drive unit
//////////////////////////////////////////////////////////////////////////////
/// Device IDs that are relevant
//////////////////////////////////////////////////////////////////////////////
enum DeviceID
{
ID_HX20 = 0x20,
ID_PX8 = 0x22,
ID_PX4 = 0x23,
ID_FD1 = 0x31,
ID_FD2 = 0x32,
};
//////////////////////////////////////////////////////////////////////////////
/// States used by the state machine.
//////////////////////////////////////////////////////////////////////////////
enum States
{
ST_BEGIN, /// < Starting State :0
ST_IDLE, /// < Returns to IDLE after all major blocks :1
ST_PS_POL, /// < Received POLL from IDLE (not used) :2
ST_PS_SEL, /// < Received SELECT from IDLE :3
ST_PS_DID, /// < Received Destination ID after SELECT :4
ST_PS_SID, /// < Received Source ID after Destination ID 5
ST_PS_ENQ, /// < Received Enquiry after Source ID 6
ST_HD_SOH, /// < Received SOH from IDLE 7
ST_HD_FMT, /// < Received Format character after SOH 8
ST_HD_DID, /// < Received Destination ID after Format 9
ST_HD_SID, /// < Received Source ID after Destination ID 10
ST_HD_FNC, /// < Received Function code after Source ID 11
ST_HD_SIZ, /// < Received Text Size after Function code 12
ST_HD_CKS, /// < Received header Checksum after Size 13
ST_TX_STX, /// < Received STX from IDLE 14
ST_TX_TXT, /// < Received SIZ bytes of Text after STX 15
ST_TX_ETX, /// < Received ETX after Text 16
ST_TX_CKS, /// < Received Text Checksum after ETX 17
ST_TX_ACK, /// < 18
ST_SENT_HDR, /// < Header was sent to Master 19
ST_SENT_TXT, /// < Text was sent to Master :20
ST_ERR, /// < An error occurred in the state machine :21
ST_UNDEFINED /// < An undefined state -- should never happen :22
};
int oldState = ST_UNDEFINED; // Used to report state before ST_ERR
//////////////////////////////////////////////////////////////////////////////
/// Functions codes used in CP/M disk systems
//////////////////////////////////////////////////////////////////////////////
enum Functions
{
FN_DISK_RESET = 0x0d, /// < RESET?
FN_DISK_SELECT = 0x0e, /// < SELECT?
FN_DISK_READ_SECTOR = 0x77, /// < Read a single 128 byte sector
FN_DISK_WRITE_SECTOR = 0x78, /// < Write a single 128 byte sector
FN_DISK_WRITE_HST = 0x79, /// < CP/M WRITEHST flushes buffers
FN_DISK_COPY = 0x7a, /// < Copy a complete disk -- not used
FN_DISK_FORMAT = 0x7c, /// < Format a blank disk -- not used
FN_IMAGE_CMDS = 0xE0, /// < Commands managing disk images
};
//////////////////////////////////////////////////////////////////////////////
/// BDOS return codes from BIOS disk functions
//////////////////////////////////////////////////////////////////////////////
enum BDOS_ReturnCodes
{
BDOS_RC_SUCCESS = 0, /// < Successful Completion
BDOS_RC_READ_ERROR = 0xfa, /// < Disk Read Error
BDOS_RC_WRITE_ERROR = 0xfb, /// < Disk Write Error
BDOS_RC_SELECT_ERROR = 0xfc, /// < Disk Select Error
BDOS_RC_DISK_WP_ERROR = 0xfd, /// < Disk Write Protect Error
BDOS_RC_FILE_WP_ERROR = 0xfe, /// < Disk Write Protect Error
};
uint32_t count = 0;
int16_t selectedDevice = -1; /// < Latest device selected ( 1 or 2 )
uint8_t latestDID = 0; /// < Latest received Destination ID
uint8_t latestSID = 0; /// < Latest received Source ID
uint8_t latestFNC = 0; /// < Latest received Funcion code
uint8_t latestSIZ = 0; /// < Latest received Text size
uint8_t latestCKS = 0; /// < Latest received calculated checksum
uint8_t textBuffer[MAX_TEXT]; /// < Buffer to hold incoming/outgoing text
///////////////////////////////////////////////////////
//////////////// SD card / file /////////////////////
#define DISK_BYTES_PER_SECTOR 128L
#define DISK_SECTORS_PER_TRACK 64L
#define DISK_BYTES_PER_TRACK (DISK_BYTES_PER_SECTOR * DISK_SECTORS_PER_TRACK)
#define DISK_TRACKS_PER_DISK 40L
#define DISK_SECTORS (DISK_SECTORS_PER_TRACK * DISK_TRACKS_PER_DISK)
//////////////////////////////////////////////////////////////////////////////
/// diskNames
///
/// @brief Holds filenames of current image files
///
//////////////////////////////////////////////////////////////////////////////
#define DRIVECOUNT 4
#define DRIVENAMESIZE 13
char diskNames[DRIVECOUNT][DRIVENAMESIZE] =
{
"d.img",
"e.img",
"f.img",
"g.img"
};
bool writeProtect[DRIVECOUNT] = {0, 0, 0, 0};
bool ledOn;
uint32_t ledTime;
#define LEDTIMEOUT 250
enum PFBDKFuncs
{
PFC_DIR = 'D',
PFC_MOUNT = 'M',
PFC_NEWIMG = 'N',
PFC_PROT = 'P',
PFC_RST = 'R',
};
// Size of the returned block -1
#define DTEXTSIZE 128
#define MTEXTSIZE 64
#define NTEXTSIZE 0
#define PTEXTSIZE 16
#define RTEXTSIZE 0
//////////////////////////////////////////////////////////////////////////////
/// for console/debug command interpreter
#define SERIALBUFSIZE 30
char serialBuffer[SERIALBUFSIZE];
byte setBufPointer = 0;
bool consoleCommand = false;
char latestE0Command;
uint8_t receivedSize;
#define LF 0x0A
// directory text block
#define ENTRIESPERMESSAGE 8
#define ENTRYSIZE 16
#define ENTRYNAMESIZE 12