22 #ifdef CONFIG_EXDOS_SUPPORT
27 #include <sys/types.h>
32 #define DEBUGEXDOS DEBUG
34 static FILE *disk_fp = NULL;
35 static int disk_fd = -1;
36 static Uint8 disk_buffer[512];
42 static Uint8 wd_status, wd_data, wd_command, wd_interrupt, wd_DRQ;
43 static int driveSel, diskSide, diskInserted, readOnly;
44 static int diskChanged = 0x40;
45 static int buffer_pos = 0, buffer_size = 1;
48 #define WDINT_OFF 0x3C
51 #define SEEK_ERROR (32 | 16 | 8)
56 static const int disk_formats[][2] = {
70 static int doCRC (
Uint8 *
buf,
int nBytes,
int n)
72 int nBits = nBytes << 3;
81 if ((bitBuf ^ (n >> 8)) & 0x80)
82 n = (n << 1) ^ 0x1021;
86 bitBuf = (bitBuf << 1) & 0xFF;
93 static int guess_geometry (
void )
96 off_t disk_size = lseek(disk_fd, 0, SEEK_END);
97 for (a = 0; disk_formats[a][0] != -1; a++) {
128 if (!strcasecmp(
fn,
"none")) {
148 disk_fd = fileno(disk_fp);
149 if (guess_geometry()) {
150 ERROR_WINDOW(
"Cannot figure the EXDOS disk image geometry out, invalid/not supported image size?");
172 driveSel = (disk_fp != NULL);
174 diskInserted = (disk_fp == NULL) ? 1 : 0;
179 static int read_sector (
void )
188 memset(disk_buffer, 0, 512);
201 if (lseek(disk_fd,
ofs, SEEK_SET) !=
ofs) {
205 ret = read(disk_fd, disk_buffer, 512);
206 DEBUGEXDOS(
"WD: read() for 512 bytes data to read, retval=%d" NL, ret);
209 ERROR_WINDOW(
"WD/EXDOS disk image read error: NO DATA READ");
225 return 128 | wd_status | wd_DRQ;
233 wd_data = disk_buffer[buffer_pos++];
234 if (buffer_pos >= buffer_size)
244 return wd_interrupt | (wd_DRQ << 6) | diskInserted | diskChanged;
254 DEBUGEXDOS(
"WD: command received: 0x%02X driveSel=%d distInserted=%d hasImage=%d" NL,
value, driveSel, diskInserted, disk_fp != NULL);
255 switch (
value >> 4) {
287 disk_buffer[1] = diskSide;
290 i = doCRC(disk_buffer, 4, 0xB230);
291 disk_buffer[4] = i >> 8;
292 disk_buffer[5] = i & 0xFF;
303 wd_status = (
wd_track == 0) ? 4 : 0;
307 wd_status = 4 | 8 | 16 | 64;
324 driveSel = (disk_fp != NULL) && ((
value & 15) == 1);
325 diskSide = (
value >> 4) & 1;
326 diskInserted = driveSel ? 0 : 1;
331 #warning "EXDOS/WD support is not compiled in / not ready"