src/mess/machine/c2040.c
| r7237 | r7238 | |
| 11 | 11 | |
| 12 | 12 | TODO: |
| 13 | 13 | |
| 14 | | - 8050 clock generator |
| 14 | - 8050 e27 |
| 15 | - save state |
| 16 | - remove via_pb_r |
| 15 | 17 | - write to disk |
| 16 | | - save state |
| 18 | - alloca buffers |
| 19 | - activity/error LEDs |
| 17 | 20 | |
| 18 | 21 | */ |
| 19 | 22 | |
| r7237 | r7238 | |
| 47 | 50 | #define C8050_REGION "c8050" |
| 48 | 51 | #define SFD1001_REGION "sfd1001" |
| 49 | 52 | |
| 50 | | static const double C2040_BITRATE[4] = |
| 51 | | { |
| 52 | | XTAL_16MHz/13.0, /* tracks 1-17 */ |
| 53 | | XTAL_16MHz/14.0, /* tracks 18-24 */ |
| 54 | | XTAL_16MHz/15.0, /* tracks 25-30 */ |
| 55 | | XTAL_16MHz/16.0 /* tracks 31-42 */ |
| 56 | | }; |
| 53 | #define SYNC \ |
| 54 | (!(((c2040->sr & G64_SYNC_MARK) == G64_SYNC_MARK) & c2040->rw)) |
| 57 | 55 | |
| 58 | | #define SYNC_MARK 0x3ff /* 10 consecutive 1-bits */ |
| 56 | #define ERROR \ |
| 57 | (!(c2040->ready | BIT(c2040->e, 3))) |
| 59 | 58 | |
| 60 | | #define TRACK_BUFFER_SIZE 8194 /* 2 bytes track length + maximum of 8192 bytes of GCR encoded data */ |
| 61 | | #define TRACK_DATA_START 2 |
| 62 | | |
| 63 | | #define SYNC (!(((c2040->sr & SYNC_MARK) == SYNC_MARK) & c2040->rw)) |
| 64 | | #define ERROR (!(c2040->ready | BIT(c2040->e, 3))) |
| 65 | | |
| 66 | 59 | /*************************************************************************** |
| 67 | 60 | TYPE DEFINITIONS |
| 68 | 61 | ***************************************************************************/ |
| r7237 | r7238 | |
| 73 | 66 | int stp; /* stepper motor phase */ |
| 74 | 67 | |
| 75 | 68 | /* track */ |
| 76 | | UINT8 track_buffer[TRACK_BUFFER_SIZE]; /* track data buffer */ |
| 69 | UINT8 track_buffer[G64_BUFFER_SIZE]; /* track data buffer */ |
| 77 | 70 | int track_len; /* track length */ |
| 78 | 71 | int buffer_pos; /* byte position within track buffer */ |
| 79 | 72 | int bit_pos; /* bit position within track buffer byte */ |
| r7237 | r7238 | |
| 218 | 211 | int ready = !(c2040->bit_count==9); |
| 219 | 212 | int error = !(ready | BIT(c2040->e, 3)); |
| 220 | 213 | |
| 221 | | logerror("offs %04x/%04x G64 %02x READY %u PA %02x DATA %03x GCR %02x SYNC %u ERROR %u I %04x\n", c2040->unit[c2040->drive].buffer_pos-1, c2040->unit[c2040->drive].track_len, |
| 214 | logerror("d %u offs %04x/%04x G64 %02x READY %u PA %02x DATA %03x GCR %02x SYNC %u ERROR %u I %04x\n", c2040->drive, c2040->unit[c2040->drive].buffer_pos-1, c2040->unit[c2040->drive].track_len, |
| 222 | 215 | c2040->unit[c2040->drive].track_buffer[c2040->unit[c2040->drive].buffer_pos], |
| 223 | 216 | ready, pa, c2040->sr & 0x3ff, c2040->e, SYNC, error, c2040->i); |
| 224 | 217 | } |
| r7237 | r7238 | |
| 257 | 250 | if (c2040->unit[c2040->drive].buffer_pos == c2040->unit[c2040->drive].track_len + 2) |
| 258 | 251 | { |
| 259 | 252 | /* loop to the start of the track */ |
| 260 | | c2040->unit[c2040->drive].buffer_pos = TRACK_DATA_START; |
| 253 | c2040->unit[c2040->drive].buffer_pos = G64_DATA_START; |
| 261 | 254 | } |
| 262 | 255 | } |
| 263 | 256 | |
| r7237 | r7238 | |
| 280 | 273 | c2040->ready = ready; |
| 281 | 274 | } |
| 282 | 275 | |
| 276 | if ((device->type == C8050) || (device->type == C8250) || (device->type == SFD1001)) |
| 277 | { |
| 278 | cpu_set_input_line(c2040->cpu_fdc, M6502_SET_OVERFLOW, ready); |
| 279 | } |
| 280 | |
| 283 | 281 | via_ca1_w(c2040->via, ready); |
| 284 | 282 | via_cb1_w(c2040->via, ERROR); |
| 285 | 283 | } |
| r7237 | r7238 | |
| 335 | 333 | ADDRESS_MAP_GLOBAL_MASK(0x1fff) |
| 336 | 334 | AM_RANGE(0x0000, 0x003f) AM_MIRROR(0x0300) AM_RAM // 6530 |
| 337 | 335 | AM_RANGE(0x0040, 0x004f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6522_TAG, via_r, via_w) |
| 338 | | AM_RANGE(0x0080, 0x009f) AM_MIRROR(0x0320) AM_DEVREADWRITE(M6530_TAG, miot6530_r, miot6530_w) |
| 336 | AM_RANGE(0x0080, 0x008f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6530_TAG, miot6530_r, miot6530_w) |
| 339 | 337 | AM_RANGE(0x0400, 0x07ff) AM_RAM AM_SHARE("share1") |
| 340 | 338 | AM_RANGE(0x0800, 0x0bff) AM_RAM AM_SHARE("share2") |
| 341 | 339 | AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_SHARE("share3") |
| r7237 | r7238 | |
| 368 | 366 | ADDRESS_MAP_GLOBAL_MASK(0x1fff) |
| 369 | 367 | AM_RANGE(0x0000, 0x003f) AM_MIRROR(0x0300) AM_RAM // 6530 |
| 370 | 368 | AM_RANGE(0x0040, 0x004f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6522_TAG, via_r, via_w) |
| 371 | | AM_RANGE(0x0080, 0x009f) AM_MIRROR(0x0320) AM_DEVREADWRITE(M6530_TAG, miot6530_r, miot6530_w) |
| 369 | AM_RANGE(0x0080, 0x008f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6530_TAG, miot6530_r, miot6530_w) |
| 372 | 370 | AM_RANGE(0x0400, 0x07ff) AM_RAM AM_SHARE("share1") |
| 373 | 371 | AM_RANGE(0x0800, 0x0bff) AM_RAM AM_SHARE("share2") |
| 374 | 372 | AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_SHARE("share3") |
| r7237 | r7238 | |
| 710 | 708 | |
| 711 | 709 | if (tracks != 0) |
| 712 | 710 | { |
| 713 | | c2040->unit[unit].track_len = TRACK_BUFFER_SIZE; |
| 714 | | c2040->unit[unit].buffer_pos = TRACK_DATA_START; |
| 711 | c2040->unit[unit].track_len = G64_BUFFER_SIZE; |
| 712 | c2040->unit[unit].buffer_pos = G64_DATA_START; |
| 715 | 713 | c2040->unit[unit].bit_pos = 7; |
| 716 | 714 | c2040->bit_count = 0; |
| 717 | 715 | |
| r7237 | r7238 | |
| 722 | 720 | floppy_drive_read_track_data_info_buffer(c2040->unit[unit].image, c2040->side, c2040->unit[unit].track_buffer, &c2040->unit[unit].track_len); |
| 723 | 721 | |
| 724 | 722 | /* extract track length */ |
| 725 | | c2040->unit[unit].track_len = 2 + ((c2040->unit[unit].track_buffer[1] << 8) | c2040->unit[unit].track_buffer[0]); |
| 723 | c2040->unit[unit].track_len = G64_DATA_START + ((c2040->unit[unit].track_buffer[1] << 8) | c2040->unit[unit].track_buffer[0]); |
| 726 | 724 | } |
| 727 | 725 | |
| 728 | 726 | c2040->unit[unit].stp = stp; |
| r7237 | r7238 | |
| 1072 | 1070 | |
| 1073 | 1071 | c2040_t *c2040 = get_safe_token(device->owner); |
| 1074 | 1072 | |
| 1075 | | miot_pb_w(device, 0, newdata); |
| 1073 | /* drive select */ |
| 1074 | if ((device->type == C8050) || (device->type == C8250)) |
| 1075 | { |
| 1076 | //TODO c2040->drive = BIT(newdata, 0); |
| 1077 | } |
| 1076 | 1078 | |
| 1079 | /* density select */ |
| 1080 | int ds = (newdata >> 1) & 0x03; |
| 1081 | |
| 1082 | if (c2040->ds != ds) |
| 1083 | { |
| 1084 | timer_adjust_periodic(c2040->bit_timer, attotime_zero, 0, ATTOTIME_IN_HZ(C8050_BITRATE[ds])); |
| 1085 | c2040->ds = ds; |
| 1086 | } |
| 1087 | |
| 1077 | 1088 | /* side select */ |
| 1078 | | c2040->side = !BIT(newdata, 4); |
| 1089 | if ((device->type == C8250) || (device->type == SFD1001)) |
| 1090 | { |
| 1091 | c2040->side = !BIT(newdata, 4); |
| 1092 | } |
| 1079 | 1093 | |
| 1080 | 1094 | /* interrupt */ |
| 1081 | | cpu_set_input_line(c2040->cpu_fdc, M6502_IRQ_LINE, BIT(newdata, 7) ? CLEAR_LINE : ASSERT_LINE); |
| 1095 | if (c2040->miot_irq != BIT(newdata, 7)) |
| 1096 | { |
| 1097 | cpu_set_input_line(c2040->cpu_fdc, M6502_IRQ_LINE, BIT(newdata, 7) ? CLEAR_LINE : ASSERT_LINE); |
| 1098 | c2040->miot_irq = BIT(newdata, 7); |
| 1099 | } |
| 1082 | 1100 | } |
| 1083 | 1101 | |
| 1084 | 1102 | static const miot6530_interface c8050_miot_intf = |
| r7237 | r7238 | |
| 1301 | 1319 | ROM( c2040 ) |
| 1302 | 1320 | -------------------------------------------------*/ |
| 1303 | 1321 | |
| 1304 | | ROM_START( c2040 ) |
| 1322 | ROM_START( c2040 ) // schematic 320806 |
| 1305 | 1323 | ROM_REGION( 0x2c00, C2040_REGION, ROMREGION_LOADBYNAME ) |
| 1306 | 1324 | /* DOS 1.0 */ |
| 1307 | 1325 | ROM_LOAD( "901468-06.ul1", 0x0000, 0x1000, CRC(25b5eed5) SHA1(4d9658f2e6ff3276e5c6e224611a66ce44b16fc7) ) |
| r7237 | r7238 | |
| 1311 | 1329 | ROM_LOAD( "901466-02.uk3", 0x2000, 0x0400, NO_DUMP ) |
| 1312 | 1330 | |
| 1313 | 1331 | /* ROM GCR */ |
| 1314 | | ROM_LOAD( "901467.uk6", 0x2400, 0x0800, CRC(a23337eb) SHA1(97df576397608455616331f8e837cb3404363fa2) ) |
| 1332 | ROM_LOAD( "901467.uk6", 0x2400, 0x0800, CRC(a23337eb) SHA1(97df576397608455616331f8e837cb3404363fa2) ) |
| 1315 | 1333 | ROM_END |
| 1316 | 1334 | |
| 1317 | 1335 | /*------------------------------------------------- |
| 1318 | 1336 | ROM( c4040 ) |
| 1319 | 1337 | -------------------------------------------------*/ |
| 1320 | 1338 | |
| 1321 | | ROM_START( c4040 ) |
| 1339 | ROM_START( c4040 ) // schematic ? |
| 1322 | 1340 | ROM_REGION( 0x3c00, C4040_REGION, ROMREGION_LOADBYNAME ) |
| 1323 | 1341 | /* DOS 2.1 */ |
| 1324 | 1342 | ROM_LOAD( "901468-11.uj1", 0x0000, 0x1000, CRC(b7157458) SHA1(8415f3159dea73161e0cef7960afa6c76953b6f8) ) |
| r7237 | r7238 | |
| 1333 | 1351 | ROM_LOAD( "901466-04.uk3", 0x3000, 0x0400, CRC(0ab338dc) SHA1(6645fa40b81be1ff7d1384e9b52df06a26ab0bfb) ) |
| 1334 | 1352 | |
| 1335 | 1353 | /* ROM GCR */ |
| 1336 | | ROM_LOAD( "901467.uk6", 0x3400, 0x800, CRC(a23337eb) SHA1(97df576397608455616331f8e837cb3404363fa2) ) |
| 1354 | ROM_LOAD( "901467.uk6", 0x3400, 0x0800, CRC(a23337eb) SHA1(97df576397608455616331f8e837cb3404363fa2) ) |
| 1337 | 1355 | ROM_END |
| 1338 | 1356 | |
| 1339 | 1357 | /*------------------------------------------------- |
| r7237 | r7238 | |
| 1368 | 1386 | ROM_LOAD( "901888-01.uh1", 0x2000, 0x2000, CRC(de9b6132) SHA1(2e6c2d7ca934e5c550ad14bd5e9e7749686b7af4) ) |
| 1369 | 1387 | |
| 1370 | 1388 | /* controller */ |
| 1371 | | ROM_LOAD( "901483-03.uk3", 0x4000, 0x400, CRC(9e83fa70) SHA1(e367ea8a5ddbd47f13570088427293138a10784b) ) |
| 1372 | | ROM_LOAD( "901483-04.uk3", 0x4000, 0x400, NO_DUMP ) |
| 1373 | | ROM_LOAD( "901884-01.uk3", 0x4000, 0x400, NO_DUMP ) |
| 1374 | | ROM_LOAD( "901885-04.uk3", 0x4000, 0x400, CRC(bab998c9) SHA1(0dc9a3b60f1b866c63eebd882403532fc59fe57f) ) |
| 1375 | | ROM_LOAD( "901869-01.uk3", 0x4000, 0x400, CRC(2915327a) SHA1(3a9a80f72ce76e5f5c72513f8ef7553212912ae3) ) |
| 1389 | ROM_LOAD( "901483-03.uk3", 0x4000, 0x0400, CRC(9e83fa70) SHA1(e367ea8a5ddbd47f13570088427293138a10784b) ) |
| 1390 | ROM_LOAD( "901483-04.uk3", 0x4000, 0x0400, NO_DUMP ) |
| 1391 | ROM_LOAD( "901884-01.uk3", 0x4000, 0x0400, NO_DUMP ) |
| 1392 | ROM_LOAD( "901885-04.uk3", 0x4000, 0x0400, CRC(bab998c9) SHA1(0dc9a3b60f1b866c63eebd882403532fc59fe57f) ) |
| 1393 | ROM_LOAD( "901869-01.uk3", 0x4000, 0x0400, CRC(2915327a) SHA1(3a9a80f72ce76e5f5c72513f8ef7553212912ae3) ) |
| 1376 | 1394 | |
| 1377 | 1395 | /* GCR decoder */ |
| 1378 | | ROM_LOAD( "901467.uk6", 0x4400, 0x800, CRC(a23337eb) SHA1(97df576397608455616331f8e837cb3404363fa2) ) |
| 1396 | ROM_LOAD( "901467.uk6", 0x4400, 0x0800, CRC(a23337eb) SHA1(97df576397608455616331f8e837cb3404363fa2) ) |
| 1379 | 1397 | ROM_END |
| 1380 | 1398 | |
| 1381 | 1399 | /*------------------------------------------------- |
| 1382 | 1400 | ROM( sfd1001 ) |
| 1383 | 1401 | -------------------------------------------------*/ |
| 1384 | 1402 | |
| 1385 | | ROM_START( sfd1001 ) // schematic |
| 1403 | ROM_START( sfd1001 ) // schematic 251406 |
| 1386 | 1404 | ROM_REGION( 0x5000, SFD1001_REGION, ROMREGION_LOADBYNAME ) |
| 1387 | | ROM_LOAD( "901887-01.1j", 0x0000, 0x2000, CRC(0073b8b2) SHA1(b10603195f240118fe5fb6c6dfe5c5097463d890) ) |
| 1388 | | ROM_LOAD( "901888-01.3j", 0x2000, 0x2000, CRC(de9b6132) SHA1(2e6c2d7ca934e5c550ad14bd5e9e7749686b7af4) ) |
| 1405 | ROM_LOAD( "901887-01.1j", 0x0000, 0x2000, CRC(0073b8b2) SHA1(b10603195f240118fe5fb6c6dfe5c5097463d890) ) |
| 1406 | ROM_LOAD( "901888-01.3j", 0x2000, 0x2000, CRC(de9b6132) SHA1(2e6c2d7ca934e5c550ad14bd5e9e7749686b7af4) ) |
| 1389 | 1407 | |
| 1390 | 1408 | /* controller */ |
| 1391 | 1409 | ROM_LOAD( "251257-02a.u2", 0x4000, 0x0800, CRC(b51150de) SHA1(3b954eb34f7ea088eed1d33ebc6d6e83a3e9be15) ) |
| 1392 | 1410 | |
| 1393 | 1411 | /* GCR decoder */ |
| 1394 | | ROM_LOAD( "901467.5c", 0x4800, 0x800, CRC(a23337eb) SHA1(97df576397608455616331f8e837cb3404363fa2) ) |
| 1412 | ROM_LOAD( "901467.5c", 0x4800, 0x0800, CRC(a23337eb) SHA1(97df576397608455616331f8e837cb3404363fa2) ) |
| 1395 | 1413 | ROM_END |
| 1396 | 1414 | |
| 1397 | 1415 | /*------------------------------------------------- |
| r7237 | r7238 | |
| 1465 | 1483 | c2040->miot->reset(); |
| 1466 | 1484 | c2040->via->reset(); |
| 1467 | 1485 | |
| 1468 | | /* toggle SO */ |
| 1486 | /* toggle M6502 SO */ |
| 1469 | 1487 | cpu_set_input_line(c2040->cpu_dos, M6502_SET_OVERFLOW, ASSERT_LINE); |
| 1470 | 1488 | cpu_set_input_line(c2040->cpu_dos, M6502_SET_OVERFLOW, CLEAR_LINE); |
| 1471 | 1489 | } |
src/mess/machine/c1541.c
| r7237 | r7238 | |
| 158 | 158 | #define M6522_1_TAG "ucd4" |
| 159 | 159 | #define TIMER_BIT_TAG "ue7" |
| 160 | 160 | |
| 161 | | static const double C1541_BITRATE[4] = |
| 162 | | { |
| 163 | | XTAL_16MHz/13.0, /* tracks 1-17 */ |
| 164 | | XTAL_16MHz/14.0, /* tracks 18-24 */ |
| 165 | | XTAL_16MHz/15.0, /* tracks 25-30 */ |
| 166 | | XTAL_16MHz/16.0 /* tracks 31-42 */ |
| 167 | | }; |
| 168 | | |
| 169 | | #define SYNC_MARK 0x3ff /* 10 consecutive 1-bits */ |
| 170 | | |
| 171 | | #define TRACK_BUFFER_SIZE 8194 /* 2 bytes track length + maximum of 8192 bytes of GCR encoded data */ |
| 172 | | #define TRACK_DATA_START 2 |
| 173 | | |
| 174 | 161 | /*************************************************************************** |
| 175 | 162 | TYPE DEFINITIONS |
| 176 | 163 | ***************************************************************************/ |
| r7237 | r7238 | |
| 180 | 167 | { |
| 181 | 168 | /* abstractions */ |
| 182 | 169 | int address; /* serial bus address - 8 */ |
| 183 | | UINT8 track_buffer[TRACK_BUFFER_SIZE]; /* track data buffer */ |
| 170 | UINT8 track_buffer[G64_BUFFER_SIZE]; /* track data buffer */ |
| 184 | 171 | int track_len; /* track length */ |
| 185 | 172 | int buffer_pos; /* current byte position within track buffer */ |
| 186 | 173 | int bit_pos; /* current bit position within track buffer byte */ |
| r7237 | r7238 | |
| 263 | 250 | if (c1541->buffer_pos > c1541->track_len + 1) |
| 264 | 251 | { |
| 265 | 252 | /* loop to the start of the track */ |
| 266 | | c1541->buffer_pos = TRACK_DATA_START; |
| 253 | c1541->buffer_pos = G64_DATA_START; |
| 267 | 254 | } |
| 268 | 255 | } |
| 269 | 256 | |
| 270 | | if ((c1541->data & SYNC_MARK) == SYNC_MARK) |
| 257 | if ((c1541->data & G64_SYNC_MARK) == G64_SYNC_MARK) |
| 271 | 258 | { |
| 272 | 259 | /* SYNC detected */ |
| 273 | 260 | c1541->bit_count = 0; |
| r7237 | r7238 | |
| 822 | 809 | data |= !floppy_wpt_r(c1541->image) << 4; |
| 823 | 810 | |
| 824 | 811 | /* SYNC detect line */ |
| 825 | | data |= !(c1541->mode && ((c1541->data & SYNC_MARK) == SYNC_MARK)) << 7; |
| 812 | data |= !(c1541->mode && ((c1541->data & G64_SYNC_MARK) == G64_SYNC_MARK)) << 7; |
| 826 | 813 | |
| 827 | 814 | return data; |
| 828 | 815 | } |
| r7237 | r7238 | |
| 865 | 852 | |
| 866 | 853 | if (tracks != 0) |
| 867 | 854 | { |
| 868 | | c1541->track_len = TRACK_BUFFER_SIZE; |
| 869 | | c1541->buffer_pos = TRACK_DATA_START; |
| 855 | c1541->track_len = G64_BUFFER_SIZE; |
| 856 | c1541->buffer_pos = G64_DATA_START; |
| 870 | 857 | c1541->bit_pos = 7; |
| 871 | 858 | c1541->bit_count = 0; |
| 872 | 859 | |
| r7237 | r7238 | |
| 877 | 864 | floppy_drive_read_track_data_info_buffer(c1541->image, 0, c1541->track_buffer, &c1541->track_len); |
| 878 | 865 | |
| 879 | 866 | /* extract track length */ |
| 880 | | c1541->track_len = (c1541->track_buffer[1] << 8) | c1541->track_buffer[0]; |
| 867 | c1541->track_len = G64_DATA_START + ((c1541->track_buffer[1] << 8) | c1541->track_buffer[0]); |
| 881 | 868 | } |
| 882 | 869 | |
| 883 | 870 | c1541->stp = stp; |
| r7237 | r7238 | |
| 892 | 879 | /* density select */ |
| 893 | 880 | if (c1541->ds != ds) |
| 894 | 881 | { |
| 895 | | timer_adjust_periodic(c1541->bit_timer, attotime_zero, 0, ATTOTIME_IN_HZ(C1541_BITRATE[ds]/4)); |
| 882 | timer_adjust_periodic(c1541->bit_timer, attotime_zero, 0, ATTOTIME_IN_HZ(C2040_BITRATE[ds]/4)); |
| 896 | 883 | c1541->ds = ds; |
| 897 | 884 | } |
| 898 | 885 | } |
| r7237 | r7238 | |
| 1108 | 1095 | c1541->image = device->subdevice(FLOPPY_0); |
| 1109 | 1096 | |
| 1110 | 1097 | /* allocate track buffer */ |
| 1111 | | // c1541->track_buffer = auto_alloc_array(device->machine, UINT8, TRACK_BUFFER_SIZE); |
| 1098 | // c1541->track_buffer = auto_alloc_array(device->machine, UINT8, G64_BUFFER_SIZE); |
| 1112 | 1099 | |
| 1113 | 1100 | /* allocate data timer */ |
| 1114 | 1101 | c1541->bit_timer = timer_alloc(device->machine, bit_tick, (void *)device); |
| 1115 | 1102 | |
| 1116 | 1103 | /* register for state saving */ |
| 1117 | | // state_save_register_device_item_pointer(device, 0, c1541->track_buffer, TRACK_BUFFER_SIZE); |
| 1104 | // state_save_register_device_item_pointer(device, 0, c1541->track_buffer, G64_BUFFER_SIZE); |
| 1118 | 1105 | state_save_register_device_item(device, 0, c1541->address); |
| 1119 | 1106 | state_save_register_device_item(device, 0, c1541->track_len); |
| 1120 | 1107 | state_save_register_device_item(device, 0, c1541->buffer_pos); |
src/mess/machine/c1551.c
| r7237 | r7238 | |
| 37 | 37 | |
| 38 | 38 | #define FLOPPY_TAG "c1551_floppy" |
| 39 | 39 | |
| 40 | | static const double C1551_BITRATE[4] = |
| 41 | | { |
| 42 | | XTAL_16MHz/13.0, /* tracks 1-17 */ |
| 43 | | XTAL_16MHz/14.0, /* tracks 18-24 */ |
| 44 | | XTAL_16MHz/15.0, /* tracks 25-30 */ |
| 45 | | XTAL_16MHz/16.0 /* tracks 31-42 */ |
| 46 | | }; |
| 47 | | |
| 48 | | #define SYNC_MARK 0x3ff /* 10 consecutive 1-bits */ |
| 49 | | |
| 50 | | #define TRACK_BUFFER_SIZE 8194 /* 2 bytes track length + maximum of 8192 bytes of GCR encoded data */ |
| 51 | | #define TRACK_DATA_START 2 |
| 52 | | |
| 53 | 40 | /*************************************************************************** |
| 54 | 41 | TYPE DEFINITIONS |
| 55 | 42 | ***************************************************************************/ |
| r7237 | r7238 | |
| 57 | 44 | typedef struct _c1551_t c1551_t; |
| 58 | 45 | struct _c1551_t |
| 59 | 46 | { |
| 60 | | UINT8 track_buffer[TRACK_BUFFER_SIZE]; /* track data buffer */ |
| 47 | UINT8 track_buffer[G64_BUFFER_SIZE]; /* track data buffer */ |
| 61 | 48 | int track_len; /* track length */ |
| 62 | 49 | int buffer_pos; /* current byte position within track buffer */ |
| 63 | 50 | int bit_pos; /* current bit position within track buffer byte */ |
| r7237 | r7238 | |
| 123 | 110 | if (c1551->buffer_pos > c1551->track_len + 1) |
| 124 | 111 | { |
| 125 | 112 | /* loop to the start of the track */ |
| 126 | | c1551->buffer_pos = TRACK_DATA_START; |
| 113 | c1551->buffer_pos = G64_DATA_START; |
| 127 | 114 | } |
| 128 | 115 | } |
| 129 | 116 | |
| 130 | | if ((c1551->data & SYNC_MARK) == SYNC_MARK) |
| 117 | if ((c1551->data & G64_SYNC_MARK) == G64_SYNC_MARK) |
| 131 | 118 | { |
| 132 | 119 | /* SYNC detected */ |
| 133 | 120 | c1551->bit_count = 0; |
| r7237 | r7238 | |
| 224 | 211 | |
| 225 | 212 | if (tracks != 0) |
| 226 | 213 | { |
| 227 | | c1551->track_len = TRACK_BUFFER_SIZE; |
| 228 | | c1551->buffer_pos = TRACK_DATA_START; |
| 214 | c1551->track_len = G64_BUFFER_SIZE; |
| 215 | c1551->buffer_pos = G64_DATA_START; |
| 229 | 216 | c1551->bit_pos = 7; |
| 230 | 217 | c1551->bit_count = 0; |
| 231 | 218 | |
| r7237 | r7238 | |
| 236 | 223 | floppy_drive_read_track_data_info_buffer(c1551->image, 0, c1551->track_buffer, &c1551->track_len); |
| 237 | 224 | |
| 238 | 225 | /* extract track length */ |
| 239 | | c1551->track_len = (c1551->track_buffer[1] << 8) | c1551->track_buffer[0]; |
| 226 | c1551->track_len = G64_DATA_START + ((c1551->track_buffer[1] << 8) | c1551->track_buffer[0]); |
| 240 | 227 | } |
| 241 | 228 | |
| 242 | 229 | c1551->stp = stp; |
| r7237 | r7238 | |
| 251 | 238 | /* density select */ |
| 252 | 239 | if (c1551->ds != ds) |
| 253 | 240 | { |
| 254 | | timer_adjust_periodic(c1551->bit_timer, attotime_zero, 0, ATTOTIME_IN_HZ(C1551_BITRATE[ds]/4)); |
| 241 | timer_adjust_periodic(c1551->bit_timer, attotime_zero, 0, ATTOTIME_IN_HZ(C2040_BITRATE[ds]/4)); |
| 255 | 242 | c1551->ds = ds; |
| 256 | 243 | } |
| 257 | 244 | } |
| r7237 | r7238 | |
| 374 | 361 | UINT8 data = 0; |
| 375 | 362 | |
| 376 | 363 | /* SYNC detect line */ |
| 377 | | data |= !(c1551->mode && ((c1551->data & SYNC_MARK) == SYNC_MARK)) << 6; |
| 364 | data |= !(c1551->mode && ((c1551->data & G64_SYNC_MARK) == G64_SYNC_MARK)) << 6; |
| 378 | 365 | |
| 379 | 366 | return data; |
| 380 | 367 | } |
| r7237 | r7238 | |
| 480 | 467 | c1551->image = device->subdevice(FLOPPY_0); |
| 481 | 468 | |
| 482 | 469 | /* allocate track buffer */ |
| 483 | | // c1551->track_buffer = auto_alloc_array(device->machine, UINT8, TRACK_BUFFER_SIZE); |
| 470 | // c1551->track_buffer = auto_alloc_array(device->machine, UINT8, G64_BUFFER_SIZE); |
| 484 | 471 | |
| 485 | 472 | /* allocate data timer */ |
| 486 | 473 | c1551->bit_timer = timer_alloc(device->machine, bit_tick, (void *)device); |
| 487 | 474 | |
| 488 | 475 | /* register for state saving */ |
| 489 | | // state_save_register_device_item_pointer(device, 0, c1551->track_buffer, TRACK_BUFFER_SIZE); |
| 476 | // state_save_register_device_item_pointer(device, 0, c1551->track_buffer, G64_BUFFER_SIZE); |
| 490 | 477 | state_save_register_device_item(device, 0, c1551->track_len); |
| 491 | 478 | state_save_register_device_item(device, 0, c1551->buffer_pos); |
| 492 | 479 | state_save_register_device_item(device, 0, c1551->bit_pos); |
src/mess/formats/d64_dsk.c
| r7237 | r7238 | |
| 1 | | /* |
| 1 | /********************************************************************* |
| 2 | 2 | |
| 3 | | Commodore sector format |
| 3 | formats/d64_dsk.c |
| 4 | 4 | |
| 5 | | SYNC FF * 5 |
| 6 | | 08 |
| 7 | | CHECKSUM sector ^ track ^ id2 ^ id1 |
| 8 | | SECTOR 0..20 (2040), 0..28 (8050) |
| 9 | | TRACK 1..35 (2040), 1..77 (8050), 1..70 (1571) |
| 10 | | ID2 |
| 11 | | ID1 |
| 12 | | GAP 1 55 * 9 (2040), 55 * 8 (1541) |
| 5 | Floppy format code for Commodore 2040/8050 type disk images |
| 13 | 6 | |
| 14 | | SYNC FF * 5 |
| 15 | | 07 |
| 16 | | NEXT TRACK |
| 17 | | NEXT SECTOR |
| 18 | | 254 BYTES OF DATA |
| 19 | | CHECKSUM |
| 20 | | GAP 2 55 * 8..19 |
| 7 | *********************************************************************/ |
| 21 | 8 | |
| 22 | | */ |
| 23 | | |
| 24 | 9 | /* |
| 25 | 10 | |
| 26 | | Commodore GCR format |
| 27 | | |
| 28 | | Original Encoded |
| 29 | | 4 bits 5 bits |
| 30 | | |
| 31 | | 0000 -> 01010 = 0x0a |
| 32 | | 0001 -> 01011 = 0x0b |
| 33 | | 0010 -> 10010 = 0x12 |
| 34 | | 0011 -> 10011 = 0x13 |
| 35 | | 0100 -> 01110 = 0x0e |
| 36 | | 0101 -> 01111 = 0x0f |
| 37 | | 0110 -> 10110 = 0x16 |
| 38 | | 0111 -> 10111 = 0x17 |
| 39 | | 1000 -> 01001 = 0x09 |
| 40 | | 1001 -> 11001 = 0x19 |
| 41 | | 1010 -> 11010 = 0x1a |
| 42 | | 1011 -> 11011 = 0x1b |
| 43 | | 1100 -> 01101 = 0x0d |
| 44 | | 1101 -> 11101 = 0x1d |
| 45 | | 1110 -> 11110 = 0x1e |
| 46 | | 1111 -> 10101 = 0x15 |
| 47 | | |
| 48 | | We use the encoded values in bytes because we use them to encode |
| 49 | | groups of 4 bytes into groups of 5 bytes, below. |
| 50 | | |
| 51 | | */ |
| 52 | | |
| 53 | | /* |
| 54 | | |
| 55 | 11 | TODO: |
| 56 | 12 | |
| 13 | - D81 geometry translation |
| 57 | 14 | - disk errors |
| 58 | 15 | - variable gaps |
| 59 | 16 | |
| r7237 | r7238 | |
| 64 | 21 | #include "formats/d64_dsk.h" |
| 65 | 22 | #include "devices/flopdrv.h" |
| 66 | 23 | |
| 24 | /*************************************************************************** |
| 25 | PARAMETERS |
| 26 | ***************************************************************************/ |
| 27 | |
| 67 | 28 | #define LOG 0 |
| 68 | 29 | |
| 69 | 30 | #define MAX_HEADS 2 |
| r7237 | r7238 | |
| 74 | 35 | |
| 75 | 36 | #define INVALID_OFFSET 0xbadbad |
| 76 | 37 | |
| 38 | #define D64_SIZE_35_TRACKS 174848 |
| 39 | #define D64_SIZE_35_TRACKS_WITH_ERRORS 175531 |
| 40 | #define D64_SIZE_40_TRACKS 196608 |
| 41 | #define D64_SIZE_40_TRACKS_WITH_ERRORS 197376 |
| 42 | #define D64_SIZE_42_TRACKS 205312 |
| 43 | #define D64_SIZE_42_TRACKS_WITH_ERRORS 206114 |
| 44 | #define D67_SIZE_35_TRACKS 176640 |
| 45 | #define D71_SIZE_70_TRACKS 349696 |
| 46 | #define D71_SIZE_70_TRACKS_WITH_ERRORS 351062 |
| 47 | #define D80_SIZE_77_TRACKS 533248 |
| 48 | #define D82_SIZE_154_TRACKS 1066496 |
| 49 | |
| 77 | 50 | enum |
| 78 | 51 | { |
| 79 | 52 | DOS1, |
| 80 | 53 | DOS2, |
| 81 | | DOS27 |
| 54 | DOS25 |
| 82 | 55 | }; |
| 83 | 56 | |
| 57 | static const char *const DOS_VERSION[] = { "1.0", "2.0", "2.5" }; |
| 58 | |
| 84 | 59 | enum |
| 85 | 60 | { |
| 86 | 61 | ERROR_00 = 1, |
| r7237 | r7238 | |
| 97 | 72 | ERROR_74, /* disk not ready (no device 1) */ |
| 98 | 73 | }; |
| 99 | 74 | |
| 100 | | #define D64_SIZE_35_TRACKS 174848 |
| 101 | | #define D64_SIZE_35_TRACKS_WITH_ERRORS 175531 |
| 102 | | #define D64_SIZE_40_TRACKS 196608 |
| 103 | | #define D64_SIZE_40_TRACKS_WITH_ERRORS 197376 |
| 104 | | #define D64_SIZE_42_TRACKS 205312 |
| 105 | | #define D64_SIZE_42_TRACKS_WITH_ERRORS 206114 |
| 106 | | #define D67_SIZE_35_TRACKS 176640 |
| 107 | | #define D71_SIZE_70_TRACKS 349696 |
| 108 | | #define D71_SIZE_70_TRACKS_WITH_ERRORS 351062 |
| 109 | | #define D80_SIZE_77_TRACKS 533248 |
| 110 | | #define D82_SIZE_154_TRACKS 1066496 |
| 75 | static const UINT8 bin_2_gcr[] = |
| 76 | { |
| 77 | 0x0a, 0x0b, 0x12, 0x13, 0x0e, 0x0f, 0x16, 0x17, |
| 78 | 0x09, 0x19, 0x1a, 0x1b, 0x0d, 0x1d, 0x1e, 0x15 |
| 79 | }; |
| 111 | 80 | |
| 81 | /* This could be of use if we ever implement saving in .d64 format, to convert back GCR -> d64 */ |
| 82 | /* |
| 83 | static const int gcr_2_bin[] = |
| 84 | { |
| 85 | -1, -1, -1, -1, |
| 86 | -1, -1, -1, -1, |
| 87 | -1, 0x08, 0x00, 0x01, |
| 88 | -1, 0x0c, 0x04, 0x05, |
| 89 | -1, -1, 0x02, 0x03, |
| 90 | -1, 0x0f, 0x06, 0x07, |
| 91 | -1, 0x09, 0x0a, 0x0b, |
| 92 | -1, 0x0d, 0x0e, -1 |
| 93 | }; |
| 94 | */ |
| 95 | |
| 112 | 96 | static const int DOS1_SECTORS_PER_TRACK[] = |
| 113 | 97 | { |
| 114 | 98 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, |
| r7237 | r7238 | |
| 139 | 123 | 17, 17 |
| 140 | 124 | }; |
| 141 | 125 | |
| 142 | | static const int DOS27_SECTORS_PER_TRACK[] = |
| 126 | static const int DOS25_SECTORS_PER_TRACK[] = |
| 143 | 127 | { |
| 144 | 128 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, |
| 145 | 129 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, /* 1-39 */ |
| r7237 | r7238 | |
| 149 | 133 | 23, 23, 23, 23, 23, 23, 23 /* 78-84 */ |
| 150 | 134 | }; |
| 151 | 135 | |
| 152 | | static const int DOS27_SPEED_ZONE[] = |
| 136 | static const int DOS25_SPEED_ZONE[] = |
| 153 | 137 | { |
| 154 | 138 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
| 155 | 139 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 1-39 */ |
| r7237 | r7238 | |
| 159 | 143 | 0, 0, 0, 0, 0, 0, 0 /* 78-84 */ |
| 160 | 144 | }; |
| 161 | 145 | |
| 146 | /*************************************************************************** |
| 147 | TYPE DEFINITIONS |
| 148 | ***************************************************************************/ |
| 149 | |
| 162 | 150 | struct d64dsk_tag |
| 163 | 151 | { |
| 164 | 152 | int dos; /* CBM DOS version */ |
| r7237 | r7238 | |
| 172 | 160 | UINT8 id1, id2; /* DOS disk format ID */ |
| 173 | 161 | }; |
| 174 | 162 | |
| 175 | | INLINE float get_dos_track(int track) |
| 163 | /*************************************************************************** |
| 164 | INLINE FUNCTIONS |
| 165 | ***************************************************************************/ |
| 166 | |
| 167 | INLINE struct d64dsk_tag *get_tag(floppy_image *floppy) |
| 176 | 168 | { |
| 177 | | return ((float)track / 2) + 1; |
| 169 | return (d64dsk_tag *)floppy_tag(floppy); |
| 178 | 170 | } |
| 179 | 171 | |
| 180 | | static struct d64dsk_tag *get_tag(floppy_image *floppy) |
| 172 | INLINE float get_dos_track(int track) |
| 181 | 173 | { |
| 182 | | struct d64dsk_tag *tag; |
| 183 | | tag = (d64dsk_tag *)floppy_tag(floppy); |
| 184 | | return tag; |
| 174 | return ((float)track / 2) + 1; |
| 185 | 175 | } |
| 186 | 176 | |
| 177 | /*************************************************************************** |
| 178 | IMPLEMENTATION |
| 179 | ***************************************************************************/ |
| 180 | |
| 181 | /*------------------------------------------------- |
| 182 | d64_get_heads_per_disk - returns the number |
| 183 | of heads in the disk image |
| 184 | -------------------------------------------------*/ |
| 185 | |
| 187 | 186 | static int d64_get_heads_per_disk(floppy_image *floppy) |
| 188 | 187 | { |
| 189 | 188 | return get_tag(floppy)->heads; |
| 190 | 189 | } |
| 191 | 190 | |
| 191 | /*------------------------------------------------- |
| 192 | d64_get_tracks_per_disk - returns the number |
| 193 | of DOS tracks in the disk image |
| 194 | -------------------------------------------------*/ |
| 195 | |
| 192 | 196 | static int d64_get_tracks_per_disk(floppy_image *floppy) |
| 193 | 197 | { |
| 194 | 198 | return get_tag(floppy)->tracks; |
| 195 | 199 | } |
| 196 | 200 | |
| 201 | /*------------------------------------------------- |
| 202 | d64_get_sectors_per_track - returns the number |
| 203 | of sectors per given track |
| 204 | -------------------------------------------------*/ |
| 205 | |
| 197 | 206 | static int d64_get_sectors_per_track(floppy_image *floppy, int head, int track) |
| 198 | 207 | { |
| 199 | 208 | int sectors_per_track = 0; |
| r7237 | r7238 | |
| 202 | 211 | { |
| 203 | 212 | case DOS1: sectors_per_track = DOS1_SECTORS_PER_TRACK[track / 2]; break; |
| 204 | 213 | case DOS2: sectors_per_track = DOS2_SECTORS_PER_TRACK[track / 2]; break; |
| 205 | | case DOS27: sectors_per_track = DOS27_SECTORS_PER_TRACK[track]; break; |
| 214 | case DOS25: sectors_per_track = DOS25_SECTORS_PER_TRACK[track]; break; |
| 206 | 215 | } |
| 207 | 216 | |
| 208 | 217 | return sectors_per_track; |
| 209 | 218 | } |
| 210 | 219 | |
| 220 | /*------------------------------------------------- |
| 221 | get_track_offset - returns the offset within |
| 222 | the disk image for a given track |
| 223 | -------------------------------------------------*/ |
| 224 | |
| 211 | 225 | static floperr_t get_track_offset(floppy_image *floppy, int head, int track, UINT64 *offset) |
| 212 | 226 | { |
| 213 | 227 | struct d64dsk_tag *tag = get_tag(floppy); |
| r7237 | r7238 | |
| 224 | 238 | return FLOPPY_ERROR_SUCCESS; |
| 225 | 239 | } |
| 226 | 240 | |
| 227 | | static const int bin_2_gcr[] = |
| 228 | | { |
| 229 | | 0x0a, 0x0b, 0x12, 0x13, 0x0e, 0x0f, 0x16, 0x17, |
| 230 | | 0x09, 0x19, 0x1a, 0x1b, 0x0d, 0x1d, 0x1e, 0x15 |
| 231 | | }; |
| 241 | /*------------------------------------------------- |
| 242 | gcr_double_2_gcr - GCR decodes given data |
| 243 | -------------------------------------------------*/ |
| 232 | 244 | |
| 233 | | /* This could be of use if we ever implement saving in .d64 format, to convert back GCR -> d64 */ |
| 234 | | /* |
| 235 | | static const int gcr_2_bin[] = |
| 236 | | { |
| 237 | | -1, -1, -1, -1, |
| 238 | | -1, -1, -1, -1, |
| 239 | | -1, 0x08, 0x00, 0x01, |
| 240 | | -1, 0x0c, 0x04, 0x05, |
| 241 | | -1, -1, 0x02, 0x03, |
| 242 | | -1, 0x0f, 0x06, 0x07, |
| 243 | | -1, 0x09, 0x0a, 0x0b, |
| 244 | | -1, 0x0d, 0x0e, -1 |
| 245 | | }; |
| 246 | | */ |
| 247 | | |
| 248 | 245 | /* gcr_double_2_gcr takes 4 bytes (a, b, c, d) and shuffles their nibbles to obtain 5 bytes in dest */ |
| 249 | 246 | /* The result is basically res = (enc(a) << 15) | (enc(b) << 10) | (enc(c) << 5) | enc(d) |
| 250 | 247 | * with res being 5 bytes long and enc(x) being the GCR encode of x. |
| 251 | 248 | * In fact, we store the result as five separate bytes in the dest argument |
| 252 | 249 | */ |
| 250 | |
| 251 | /* |
| 252 | |
| 253 | Commodore GCR format |
| 254 | |
| 255 | Original Encoded |
| 256 | 4 bits 5 bits |
| 257 | |
| 258 | 0000 -> 01010 = 0x0a |
| 259 | 0001 -> 01011 = 0x0b |
| 260 | 0010 -> 10010 = 0x12 |
| 261 | 0011 -> 10011 = 0x13 |
| 262 | 0100 -> 01110 = 0x0e |
| 263 | 0101 -> 01111 = 0x0f |
| 264 | 0110 -> 10110 = 0x16 |
| 265 | 0111 -> 10111 = 0x17 |
| 266 | 1000 -> 01001 = 0x09 |
| 267 | 1001 -> 11001 = 0x19 |
| 268 | 1010 -> 11010 = 0x1a |
| 269 | 1011 -> 11011 = 0x1b |
| 270 | 1100 -> 01101 = 0x0d |
| 271 | 1101 -> 11101 = 0x1d |
| 272 | 1110 -> 11110 = 0x1e |
| 273 | 1111 -> 10101 = 0x15 |
| 274 | |
| 275 | We use the encoded values in bytes because we use them to encode |
| 276 | groups of 4 bytes into groups of 5 bytes, below. |
| 277 | |
| 278 | */ |
| 279 | |
| 253 | 280 | static void gcr_double_2_gcr(UINT8 a, UINT8 b, UINT8 c, UINT8 d, UINT8 *dest) |
| 254 | 281 | { |
| 255 | 282 | UINT8 gcr[8]; |
| r7237 | r7238 | |
| 272 | 299 | dest[4] = (gcr[6] << 5) | gcr[7]; |
| 273 | 300 | } |
| 274 | 301 | |
| 302 | /*------------------------------------------------- |
| 303 | d64_read_track - reads a full track from the |
| 304 | disk image |
| 305 | -------------------------------------------------*/ |
| 306 | |
| 307 | /* |
| 308 | |
| 309 | Commodore sector format |
| 310 | |
| 311 | SYNC FF * 5 |
| 312 | 08 |
| 313 | CHECKSUM sector ^ track ^ id2 ^ id1 |
| 314 | SECTOR 0..20 (2040), 0..28 (8050) |
| 315 | TRACK 1..35 (2040), 1..77 (8050), 1..70 (1571) |
| 316 | ID2 |
| 317 | ID1 |
| 318 | GAP 1 55 * 9 (2040), 55 * 8 (1541) |
| 319 | |
| 320 | SYNC FF * 5 |
| 321 | 07 |
| 322 | NEXT TRACK |
| 323 | NEXT SECTOR |
| 324 | 254 BYTES OF DATA |
| 325 | CHECKSUM |
| 326 | GAP 2 55 * 8..19 |
| 327 | |
| 328 | */ |
| 329 | |
| 275 | 330 | static floperr_t d64_read_track(floppy_image *floppy, int head, int track, UINT64 offset, void *buffer, size_t buflen) |
| 276 | 331 | { |
| 277 | 332 | struct d64dsk_tag *tag = get_tag(floppy); |
| r7237 | r7238 | |
| 298 | 353 | /* determine logical track number */ |
| 299 | 354 | int dos_track = get_dos_track(track); |
| 300 | 355 | |
| 301 | | if (tag->dos == DOS27) |
| 356 | if (tag->dos == DOS25) |
| 302 | 357 | { |
| 303 | 358 | dos_track = track + 1; |
| 304 | 359 | } |
| r7237 | r7238 | |
| 422 | 477 | return FLOPPY_ERROR_SUCCESS; |
| 423 | 478 | } |
| 424 | 479 | |
| 480 | /*------------------------------------------------- |
| 481 | d64_write_track - writes a full track to the |
| 482 | disk image |
| 483 | -------------------------------------------------*/ |
| 484 | |
| 425 | 485 | static floperr_t d64_write_track(floppy_image *floppy, int head, int track, UINT64 offset, const void *buffer, size_t buflen) |
| 426 | 486 | { |
| 427 | 487 | return FLOPPY_ERROR_UNSUPPORTED; |
| 428 | 488 | } |
| 429 | 489 | |
| 490 | /*------------------------------------------------- |
| 491 | d64_identify - identifies the disk image |
| 492 | -------------------------------------------------*/ |
| 493 | |
| 430 | 494 | static void d64_identify(floppy_image *floppy, int *dos, int *heads, int *tracks, bool *has_errors) |
| 431 | 495 | { |
| 432 | 496 | switch (floppy_image_size(floppy)) |
| r7237 | r7238 | |
| 447 | 511 | case D71_SIZE_70_TRACKS_WITH_ERRORS: *dos = DOS2; *heads = 2; *tracks = 35; *has_errors = true; break; |
| 448 | 512 | |
| 449 | 513 | /* 8050 */ |
| 450 | | case D80_SIZE_77_TRACKS: *dos = DOS27; *heads = 1; *tracks = 77; *has_errors = false; break; |
| 514 | case D80_SIZE_77_TRACKS: *dos = DOS25; *heads = 1; *tracks = 77; *has_errors = false; break; |
| 451 | 515 | |
| 452 | 516 | /* 8250/SFD1001 */ |
| 453 | | case D82_SIZE_154_TRACKS: *dos = DOS27; *heads = 2; *tracks = 77; *has_errors = false; break; |
| 517 | case D82_SIZE_154_TRACKS: *dos = DOS25; *heads = 2; *tracks = 77; *has_errors = false; break; |
| 454 | 518 | } |
| 455 | 519 | } |
| 456 | 520 | |
| 521 | /*------------------------------------------------- |
| 522 | FLOPPY_IDENTIFY( d64_dsk_identify ) |
| 523 | -------------------------------------------------*/ |
| 524 | |
| 457 | 525 | FLOPPY_IDENTIFY( d64_dsk_identify ) |
| 458 | 526 | { |
| 459 | 527 | int dos = 0, heads, tracks; |
| r7237 | r7238 | |
| 471 | 539 | return FLOPPY_ERROR_SUCCESS; |
| 472 | 540 | } |
| 473 | 541 | |
| 542 | /*------------------------------------------------- |
| 543 | FLOPPY_IDENTIFY( d67_dsk_identify ) |
| 544 | -------------------------------------------------*/ |
| 545 | |
| 474 | 546 | FLOPPY_IDENTIFY( d67_dsk_identify ) |
| 475 | 547 | { |
| 476 | 548 | *vote = 0; |
| r7237 | r7238 | |
| 483 | 555 | return FLOPPY_ERROR_SUCCESS; |
| 484 | 556 | } |
| 485 | 557 | |
| 558 | /*------------------------------------------------- |
| 559 | FLOPPY_IDENTIFY( d71_dsk_identify ) |
| 560 | -------------------------------------------------*/ |
| 561 | |
| 486 | 562 | FLOPPY_IDENTIFY( d71_dsk_identify ) |
| 487 | 563 | { |
| 488 | 564 | int heads = 0, tracks = 0, dos; |
| r7237 | r7238 | |
| 500 | 576 | return FLOPPY_ERROR_SUCCESS; |
| 501 | 577 | } |
| 502 | 578 | |
| 579 | /*------------------------------------------------- |
| 580 | FLOPPY_IDENTIFY( d80_dsk_identify ) |
| 581 | -------------------------------------------------*/ |
| 582 | |
| 503 | 583 | FLOPPY_IDENTIFY( d80_dsk_identify ) |
| 504 | 584 | { |
| 505 | 585 | *vote = 0; |
| r7237 | r7238 | |
| 512 | 592 | return FLOPPY_ERROR_SUCCESS; |
| 513 | 593 | } |
| 514 | 594 | |
| 595 | /*------------------------------------------------- |
| 596 | FLOPPY_IDENTIFY( d82_dsk_identify ) |
| 597 | -------------------------------------------------*/ |
| 598 | |
| 515 | 599 | FLOPPY_IDENTIFY( d82_dsk_identify ) |
| 516 | 600 | { |
| 517 | 601 | *vote = 0; |
| r7237 | r7238 | |
| 524 | 608 | return FLOPPY_ERROR_SUCCESS; |
| 525 | 609 | } |
| 526 | 610 | |
| 611 | /*------------------------------------------------- |
| 612 | FLOPPY_CONSTRUCT( d64_dsk_construct ) |
| 613 | -------------------------------------------------*/ |
| 614 | |
| 527 | 615 | FLOPPY_CONSTRUCT( d64_dsk_construct ) |
| 528 | 616 | { |
| 529 | 617 | struct FloppyCallbacks *callbacks; |
| r7237 | r7238 | |
| 559 | 647 | logerror("D64 size: %04x\n", (UINT32)floppy_image_size(floppy)); |
| 560 | 648 | logerror("D64 heads: %u\n", heads); |
| 561 | 649 | logerror("D64 tracks: %u\n", dos_tracks); |
| 650 | logerror("D64 DOS version: %s\n", DOS_VERSION[dos]); |
| 562 | 651 | } |
| 563 | 652 | |
| 564 | 653 | /* determine track data offsets */ |
| r7237 | r7238 | |
| 566 | 655 | { |
| 567 | 656 | for (track = 0; track < tag->tracks; track++) |
| 568 | 657 | { |
| 569 | | if (dos == DOS27) |
| 658 | if (dos == DOS25) |
| 570 | 659 | { |
| 571 | 660 | if (track >= dos_tracks) |
| 572 | 661 | { |
| r7237 | r7238 | |
| 576 | 665 | else |
| 577 | 666 | { |
| 578 | 667 | tag->track_offset[head][track] = track_offset; |
| 579 | | track_offset += DOS27_SECTORS_PER_TRACK[track] * SECTOR_SIZE; |
| 668 | track_offset += DOS25_SECTORS_PER_TRACK[track] * SECTOR_SIZE; |
| 580 | 669 | |
| 581 | | if (LOG) logerror("D64 head %u track %u data offset: %04x\n", head, track, tag->track_offset[head][track]); |
| 670 | if (LOG) logerror("D64 head %u track %u data offset: %04x\n", head, track + 1, tag->track_offset[head][track]); |
| 582 | 671 | } |
| 583 | 672 | } |
| 584 | 673 | else |
| r7237 | r7238 | |
| 607 | 696 | /* determine speed zones */ |
| 608 | 697 | for (track = 0; track < tag->tracks; track++) |
| 609 | 698 | { |
| 610 | | if (dos == DOS27) |
| 699 | if (dos == DOS25) |
| 611 | 700 | { |
| 612 | | tag->speed_zone[track] = DOS27_SPEED_ZONE[track]; |
| 701 | tag->speed_zone[track] = DOS25_SPEED_ZONE[track]; |
| 613 | 702 | |
| 614 | | if (LOG) logerror("D64 track %u speed zone: %u\n", track, tag->speed_zone[track]); |
| 703 | if (LOG) logerror("D64 track %u speed zone: %u\n", track + 1, tag->speed_zone[track]); |
| 615 | 704 | } |
| 616 | 705 | else |
| 617 | 706 | { |
| r7237 | r7238 | |
| 622 | 711 | } |
| 623 | 712 | |
| 624 | 713 | /* read format ID from directory */ |
| 625 | | if (dos == DOS27) |
| 714 | /* |
| 715 | id1, id2 are the same for extended d64 (i.e. with error tables), for d67 and for d71 |
| 716 | |
| 717 | for d81 they are at track 40 bytes 0x17 & 0x18 |
| 718 | for d80 & d82 they are at track 39 bytes 0x18 & 0x19 |
| 719 | */ |
| 720 | if (dos == DOS25) |
| 626 | 721 | floppy_image_read(floppy, id, tag->track_offset[0][39] + 0x18, 2); |
| 627 | 722 | else |
| 628 | 723 | floppy_image_read(floppy, id, tag->track_offset[0][34] + 0xa2, 2); |
| r7237 | r7238 | |
| 642 | 737 | |
| 643 | 738 | return FLOPPY_ERROR_SUCCESS; |
| 644 | 739 | } |
| 645 | | |
| 646 | | /* |
| 647 | | id1, id2 are the same for extended d64 (i.e. with error tables), for d67 and for d71 |
| 648 | | |
| 649 | | for d81 they are at track 40 bytes 0x17 & 0x18 |
| 650 | | for d80 & d82 they are at track 39 bytes 0x18 & 0x19 |
| 651 | | */ |
src/mess/formats/g64_dsk.c
| r7237 | r7238 | |
| 1 | | /* |
| 1 | /********************************************************************* |
| 2 | 2 | |
| 3 | | Bytes: $0000-0007: File signature "GCR-1541" |
| 4 | | 0008: G64 version (presently only $00 defined) |
| 5 | | 0009: Number of tracks in image (usually $54, decimal 84) |
| 6 | | 000A-000B: Size of each stored track in bytes (usually 7928, or |
| 7 | | $1EF8 in LO/HI format. |
| 3 | formats/g64_dsk.c |
| 8 | 4 | |
| 9 | | Bytes: $000C-000F: Offset to stored track 1.0 ($000002AC, in LO/HI |
| 10 | | format, see below for more) |
| 11 | | 0010-0013: Offset to stored track 1.5 ($00000000) |
| 12 | | 0014-0017: Offset to stored track 2.0 ($000021A6) |
| 13 | | ... |
| 14 | | 0154-0157: Offset to stored track 42.0 ($0004F8B6) |
| 15 | | 0158-015B: Offset to stored track 42.5 ($00000000) |
| 5 | Floppy format code for Commodore 1541 GCR disk images |
| 16 | 6 | |
| 17 | | Bytes: $015C-015F: Speed zone entry for track 1 ($03, in LO/HI format, |
| 18 | | see below for more) |
| 19 | | 0160-0163: Speed zone entry for track 1.5 ($03) |
| 20 | | ... |
| 21 | | 02A4-02A7: Speed zone entry for track 42 ($00) |
| 22 | | 02A8-02AB: Speed zone entry for track 42.5 ($00) |
| 7 | *********************************************************************/ |
| 23 | 8 | |
| 24 | | Bytes: $02AC-02AD: Actual size of stored track (7692 or $1E0C, in LO/HI |
| 25 | | format) |
| 26 | | 02AE-02AE+$1E0C: Track data |
| 27 | | |
| 28 | | */ |
| 29 | | |
| 30 | 9 | /* |
| 31 | 10 | |
| 32 | 11 | TODO: |
| r7237 | r7238 | |
| 40 | 19 | #include "formats/flopimg.h" |
| 41 | 20 | #include "devices/flopdrv.h" |
| 42 | 21 | |
| 22 | /*************************************************************************** |
| 23 | PARAMETERS |
| 24 | ***************************************************************************/ |
| 25 | |
| 43 | 26 | #define LOG 0 |
| 44 | 27 | |
| 45 | 28 | #define HEADER_LENGTH 0x2ac /* standard length for 84 half tracks */ |
| 46 | 29 | #define MAX_TRACKS 84 |
| 47 | 30 | |
| 31 | /*************************************************************************** |
| 32 | TYPE DEFINITIONS |
| 33 | ***************************************************************************/ |
| 34 | |
| 48 | 35 | struct g64dsk_tag |
| 49 | 36 | { |
| 50 | 37 | int version; |
| 38 | int heads; /* number of physical heads */ |
| 51 | 39 | int tracks; /* number of physical tracks */ |
| 52 | 40 | UINT16 track_size; /* size of each track */ |
| 53 | 41 | UINT32 track_offset[MAX_TRACKS]; /* offset within data for each track */ |
| 54 | 42 | UINT32 speed_zone_offset[MAX_TRACKS]; /* offset within data for each track */ |
| 55 | 43 | }; |
| 56 | 44 | |
| 57 | | INLINE float get_dos_track(int track) |
| 45 | /*************************************************************************** |
| 46 | INLINE FUNCTIONS |
| 47 | ***************************************************************************/ |
| 48 | |
| 49 | INLINE struct g64dsk_tag *get_tag(floppy_image *floppy) |
| 58 | 50 | { |
| 59 | | return ((float)track / 2) + 1; |
| 51 | return (g64dsk_tag *)floppy_tag(floppy); |
| 60 | 52 | } |
| 61 | 53 | |
| 62 | | static struct g64dsk_tag *get_tag(floppy_image *floppy) |
| 54 | INLINE float get_dos_track(int track) |
| 63 | 55 | { |
| 64 | | struct g64dsk_tag *tag = (g64dsk_tag *)floppy_tag(floppy); |
| 65 | | return tag; |
| 56 | return ((float)track / 2) + 1; |
| 66 | 57 | } |
| 67 | 58 | |
| 59 | /*************************************************************************** |
| 60 | IMPLEMENTATION |
| 61 | ***************************************************************************/ |
| 62 | |
| 63 | /*------------------------------------------------- |
| 64 | g64_get_heads_per_disk - returns the number |
| 65 | of heads in the disk image |
| 66 | -------------------------------------------------*/ |
| 67 | |
| 68 | 68 | static int g64_get_heads_per_disk(floppy_image *floppy) |
| 69 | 69 | { |
| 70 | | return 1; |
| 70 | return get_tag(floppy)->heads; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | /*------------------------------------------------- |
| 74 | g64_get_tracks_per_disk - returns the number |
| 75 | of DOS tracks in the disk image |
| 76 | -------------------------------------------------*/ |
| 77 | |
| 73 | 78 | static int g64_get_tracks_per_disk(floppy_image *floppy) |
| 74 | 79 | { |
| 75 | 80 | return get_tag(floppy)->tracks; |
| 76 | 81 | } |
| 77 | 82 | |
| 83 | /*------------------------------------------------- |
| 84 | get_track_offset - returns the offset within |
| 85 | the disk image for a given track |
| 86 | -------------------------------------------------*/ |
| 87 | |
| 78 | 88 | static floperr_t get_track_offset(floppy_image *floppy, int track, UINT64 *offset) |
| 79 | 89 | { |
| 80 | 90 | struct g64dsk_tag *tag = get_tag(floppy); |
| r7237 | r7238 | |
| 91 | 101 | return FLOPPY_ERROR_SUCCESS; |
| 92 | 102 | } |
| 93 | 103 | |
| 104 | /*------------------------------------------------- |
| 105 | g64_read_track - reads a full track from the |
| 106 | disk image |
| 107 | -------------------------------------------------*/ |
| 108 | |
| 94 | 109 | static floperr_t g64_read_track(floppy_image *floppy, int head, int track, UINT64 offset, void *buffer, size_t buflen) |
| 95 | 110 | { |
| 96 | 111 | struct g64dsk_tag *tag = get_tag(floppy); |
| r7237 | r7238 | |
| 122 | 137 | return FLOPPY_ERROR_SUCCESS; |
| 123 | 138 | } |
| 124 | 139 | |
| 140 | /*------------------------------------------------- |
| 141 | g64_write_track - writes a full track to the |
| 142 | disk image |
| 143 | -------------------------------------------------*/ |
| 144 | |
| 125 | 145 | static floperr_t g64_write_track(floppy_image *floppy, int head, int track, UINT64 offset, const void *buffer, size_t buflen) |
| 126 | 146 | { |
| 127 | 147 | return FLOPPY_ERROR_UNSUPPORTED; |
| 128 | 148 | } |
| 129 | 149 | |
| 150 | /*------------------------------------------------- |
| 151 | FLOPPY_IDENTIFY( g64_dsk_identify ) |
| 152 | -------------------------------------------------*/ |
| 153 | |
| 130 | 154 | FLOPPY_IDENTIFY( g64_dsk_identify ) |
| 131 | 155 | { |
| 132 | 156 | UINT8 header[8]; |
| r7237 | r7238 | |
| 145 | 169 | return FLOPPY_ERROR_SUCCESS; |
| 146 | 170 | } |
| 147 | 171 | |
| 172 | /*------------------------------------------------- |
| 173 | FLOPPY_CONSTRUCT( g64_dsk_construct ) |
| 174 | -------------------------------------------------*/ |
| 175 | |
| 176 | /* |
| 177 | |
| 178 | G64 File Header Format |
| 179 | |
| 180 | Bytes: $0000-0007: File signature "GCR-1541" |
| 181 | 0008: G64 version (presently only $00 defined) |
| 182 | 0009: Number of tracks in image (usually $54, decimal 84) |
| 183 | 000A-000B: Size of each stored track in bytes (usually 7928, or |
| 184 | $1EF8 in LO/HI format. |
| 185 | |
| 186 | Bytes: $000C-000F: Offset to stored track 1.0 ($000002AC, in LO/HI |
| 187 | format, see below for more) |
| 188 | 0010-0013: Offset to stored track 1.5 ($00000000) |
| 189 | 0014-0017: Offset to stored track 2.0 ($000021A6) |
| 190 | ... |
| 191 | 0154-0157: Offset to stored track 42.0 ($0004F8B6) |
| 192 | 0158-015B: Offset to stored track 42.5 ($00000000) |
| 193 | |
| 194 | Bytes: $015C-015F: Speed zone entry for track 1 ($03, in LO/HI format, |
| 195 | see below for more) |
| 196 | 0160-0163: Speed zone entry for track 1.5 ($03) |
| 197 | ... |
| 198 | 02A4-02A7: Speed zone entry for track 42 ($00) |
| 199 | 02A8-02AB: Speed zone entry for track 42.5 ($00) |
| 200 | |
| 201 | Bytes: $02AC-02AD: Actual size of stored track (7692 or $1E0C, in LO/HI |
| 202 | format) |
| 203 | 02AE-02AE+$1E0C: Track data |
| 204 | |
| 205 | */ |
| 206 | |
| 148 | 207 | FLOPPY_CONSTRUCT( g64_dsk_construct ) |
| 149 | 208 | { |
| 150 | 209 | struct FloppyCallbacks *callbacks; |
| r7237 | r7238 | |
| 169 | 228 | if (LOG) logerror("G64 version: %u\n", tag->version); |
| 170 | 229 | |
| 171 | 230 | /* number of half tracks */ |
| 231 | tag->heads = 1; |
| 172 | 232 | tag->tracks = header[9]; |
| 173 | 233 | if (LOG) logerror("G64 tracks: %u\n", tag->tracks); |
| 174 | 234 | |