src/mess/machine/cgenie.c
| r5631 | r5632 | |
| 11 | 11 | #include "cpu/z80/z80.h" |
| 12 | 12 | #include "includes/cgenie.h" |
| 13 | 13 | #include "machine/wd17xx.h" |
| 14 | | #include "devices/basicdsk.h" |
| 15 | 14 | #include "devices/cartslot.h" |
| 16 | 15 | #include "devices/cassette.h" |
| 17 | 16 | #include "sound/ay8910.h" |
| r5631 | r5632 | |
| 30 | 29 | int cgenie_tv_mode = -1; |
| 31 | 30 | static int port_ff = 0xff; |
| 32 | 31 | |
| 33 | | #define CGENIE_DRIVE_INFO |
| 34 | | |
| 35 | | |
| 36 | | |
| 37 | | /******************************************************** |
| 38 | | abbreviations used: |
| 39 | | GPL Granules Per Lump |
| 40 | | GAT Granule Allocation Table |
| 41 | | GATL GAT Length |
| 42 | | GATM GAT Mask |
| 43 | | DDGA Disk Directory Granule Allocation |
| 44 | | *********************************************************/ |
| 45 | | typedef struct |
| 46 | | { |
| 47 | | UINT8 DDSL; /* Disk Directory Start Lump (lump number of GAT) */ |
| 48 | | UINT8 GATL; /* # of bytes used in the Granule Allocation Table sector */ |
| 49 | | UINT8 STEPRATE; /* step rate and somet SD/DD flag ... */ |
| 50 | | UINT8 TRK; /* number of tracks */ |
| 51 | | UINT8 SPT; /* sectors per track (both heads counted!) */ |
| 52 | | UINT8 GATM; /* number of used bits per byte in the GAT sector (GAT mask) */ |
| 53 | | UINT8 P7; /* ???? always zero */ |
| 54 | | UINT8 FLAGS; /* ???? some flags (SS/DS bit 6) */ |
| 55 | | UINT8 GPL; /* Sectors per granule (always 5 for the Colour Genie) */ |
| 56 | | UINT8 DDGA; /* Disk Directory Granule allocation (number of driectory granules) */ |
| 57 | | } PDRIVE; |
| 58 | | |
| 59 | | static const PDRIVE pd_list[12] = { |
| 60 | | {0x14, 0x28, 0x07, 0x28, 0x0A, 0x02, 0x00, 0x00, 0x05, 0x02}, /* CMD"<0=A" 40 tracks, SS, SD */ |
| 61 | | {0x14, 0x28, 0x07, 0x28, 0x14, 0x04, 0x00, 0x40, 0x05, 0x04}, /* CMD"<0=B" 40 tracks, DS, SD */ |
| 62 | | {0x18, 0x30, 0x53, 0x28, 0x12, 0x03, 0x00, 0x03, 0x05, 0x03}, /* CMD"<0=C" 40 tracks, SS, DD */ |
| 63 | | {0x18, 0x30, 0x53, 0x28, 0x24, 0x06, 0x00, 0x43, 0x05, 0x06}, /* CMD"<0=D" 40 tracks, DS, DD */ |
| 64 | | {0x14, 0x28, 0x07, 0x28, 0x0A, 0x02, 0x00, 0x04, 0x05, 0x02}, /* CMD"<0=E" 40 tracks, SS, SD */ |
| 65 | | {0x14, 0x28, 0x07, 0x28, 0x14, 0x04, 0x00, 0x44, 0x05, 0x04}, /* CMD"<0=F" 40 tracks, DS, SD */ |
| 66 | | {0x18, 0x30, 0x53, 0x28, 0x12, 0x03, 0x00, 0x07, 0x05, 0x03}, /* CMD"<0=G" 40 tracks, SS, DD */ |
| 67 | | {0x18, 0x30, 0x53, 0x28, 0x24, 0x06, 0x00, 0x47, 0x05, 0x06}, /* CMD"<0=H" 40 tracks, DS, DD */ |
| 68 | | {0x28, 0x50, 0x07, 0x50, 0x0A, 0x02, 0x00, 0x00, 0x05, 0x02}, /* CMD"<0=I" 80 tracks, SS, SD */ |
| 69 | | {0x28, 0x50, 0x07, 0x50, 0x14, 0x04, 0x00, 0x40, 0x05, 0x04}, /* CMD"<0=J" 80 tracks, DS, SD */ |
| 70 | | {0x30, 0x60, 0x53, 0x50, 0x12, 0x03, 0x00, 0x03, 0x05, 0x03}, /* CMD"<0=K" 80 tracks, SS, DD */ |
| 71 | | {0x30, 0x60, 0x53, 0x50, 0x24, 0x06, 0x00, 0x43, 0x05, 0x06}, /* CMD"<0=L" 80 tracks, DS, DD */ |
| 72 | | }; |
| 73 | | |
| 74 | 32 | #define IRQ_TIMER 0x80 |
| 75 | 33 | #define IRQ_FDC 0x40 |
| 76 | 34 | static UINT8 irq_status; |
| r5631 | r5632 | |
| 204 | 162 | memory_set_bankptr(machine, 1, mess_ram); |
| 205 | 163 | } |
| 206 | 164 | |
| 207 | | |
| 208 | | /* basic-dsk is a disk image format which has the tracks and sectors |
| 209 | | * stored in order, no information is stored which details the number |
| 210 | | * of tracks, number of sides, number of sectors etc, so we need to |
| 211 | | * set that up here |
| 212 | | */ |
| 213 | | DEVICE_IMAGE_LOAD( cgenie_floppy ) |
| 214 | | { |
| 215 | | int i, j, dir_offset; |
| 216 | | UINT8 buff[16]; |
| 217 | | UINT8 tracks = 0; |
| 218 | | UINT8 heads = 0; |
| 219 | | UINT8 spt = 0; |
| 220 | | short dir_sector = 0; |
| 221 | | short dir_length = 0; |
| 222 | | |
| 223 | | /* A Floppy Isnt manditory, so return if none */ |
| 224 | | if (device_load_basicdsk_floppy(image) != INIT_PASS) |
| 225 | | return INIT_FAIL; |
| 226 | | |
| 227 | | /* determine image geometry */ |
| 228 | | image_fseek(image, 0, SEEK_SET); |
| 229 | | |
| 230 | | /* determine geometry from disk contents */ |
| 231 | | for( i = 0; i < 12; i++ ) |
| 232 | | { |
| 233 | | image_fseek(image, pd_list[i].SPT * 256, SEEK_SET); |
| 234 | | image_fread(image, buff, 16); |
| 235 | | /* find an entry with matching DDSL */ |
| 236 | | if (buff[0] != 0x00 || buff[1] != 0xfe || buff[2] != pd_list[i].DDSL) |
| 237 | | continue; |
| 238 | | logerror("cgenie: checking format #%d\n", i); |
| 239 | | |
| 240 | | dir_sector = pd_list[i].DDSL * pd_list[i].GATM * pd_list[i].GPL + pd_list[i].SPT; |
| 241 | | dir_length = pd_list[i].DDGA * pd_list[i].GPL; |
| 242 | | |
| 243 | | /* scan directory for DIR/SYS or NCW1983/JHL files */ |
| 244 | | /* look into sector 2 and 3 first entry relative to DDSL */ |
| 245 | | for( j = 16; j < 32; j += 8 ) |
| 246 | | { |
| 247 | | dir_offset = dir_sector * 256 + j * 32; |
| 248 | | if( image_fseek(image, dir_offset, SEEK_SET) < 0 ) |
| 249 | | break; |
| 250 | | if( image_fread(image, buff, 16) != 16 ) |
| 251 | | break; |
| 252 | | if( !strncmp((char*)buff + 5, "DIR SYS", 11) || |
| 253 | | !strncmp((char*)buff + 5, "NCW1983 JHL", 11) ) |
| 254 | | { |
| 255 | | tracks = pd_list[i].TRK; |
| 256 | | heads = (pd_list[i].SPT > 18) ? 2 : 1; |
| 257 | | spt = pd_list[i].SPT / heads; |
| 258 | | dir_sector = pd_list[i].DDSL * pd_list[i].GATM * pd_list[i].GPL + pd_list[i].SPT; |
| 259 | | dir_length = pd_list[i].DDGA * pd_list[i].GPL; |
| 260 | | memcpy(memory_region(image->machine, "maincpu") + 0x5A71 + image_index_in_device(image) * sizeof(PDRIVE), &pd_list[i], sizeof(PDRIVE)); |
| 261 | | break; |
| 262 | | } |
| 263 | | } |
| 264 | | |
| 265 | | logerror("cgenie: geometry %d tracks, %d heads, %d sec/track\n", tracks, heads, spt); |
| 266 | | /* set geometry so disk image can be read */ |
| 267 | | basicdsk_set_geometry(image, tracks, heads, spt, 256, 0, 0, FALSE); |
| 268 | | |
| 269 | | logerror("cgenie: directory sectors %d - %d (%d sectors)\n", dir_sector, dir_sector + dir_length - 1, dir_length); |
| 270 | | /* mark directory sectors with deleted data address mark */ |
| 271 | | /* assumption dir_sector is a sector offset */ |
| 272 | | for (j = 0; j < dir_length; j++) |
| 273 | | { |
| 274 | | UINT8 track; |
| 275 | | UINT8 side; |
| 276 | | UINT8 sector_id; |
| 277 | | UINT16 track_offset; |
| 278 | | UINT16 sector_offset; |
| 279 | | |
| 280 | | /* calc sector offset */ |
| 281 | | sector_offset = dir_sector + j; |
| 282 | | |
| 283 | | /* get track offset */ |
| 284 | | track_offset = sector_offset / spt; |
| 285 | | |
| 286 | | /* calc track */ |
| 287 | | track = track_offset / heads; |
| 288 | | |
| 289 | | /* calc side */ |
| 290 | | side = track_offset % heads; |
| 291 | | |
| 292 | | /* calc sector id - first sector id is 0! */ |
| 293 | | sector_id = sector_offset % spt; |
| 294 | | |
| 295 | | /* set deleted data address mark for sector specified */ |
| 296 | | basicdsk_set_ddam(image, track, side, sector_id, 1); |
| 297 | | } |
| 298 | | |
| 299 | | } |
| 300 | | return INIT_PASS; |
| 301 | | } |
| 302 | | |
| 303 | | |
| 304 | 165 | /************************************* |
| 305 | 166 | * |
| 306 | 167 | * Port handlers. |
src/mess/drivers/cgenie.c
| r5631 | r5632 | |
| 29 | 29 | #include "driver.h" |
| 30 | 30 | #include "cpu/z80/z80.h" |
| 31 | 31 | #include "includes/cgenie.h" |
| 32 | | #include "devices/basicdsk.h" |
| 32 | #include "devices/mflopimg.h" |
| 33 | #include "formats/basicdsk.h" |
| 33 | 34 | #include "devices/cartslot.h" |
| 34 | 35 | #include "devices/cassette.h" |
| 35 | 36 | #include "sound/ay8910.h" |
| r5631 | r5632 | |
| 462 | 463 | |
| 463 | 464 | ROM_END |
| 464 | 465 | |
| 466 | // Code below is previous non-working implementation , just for reference |
| 467 | /* |
| 468 | |
| 469 | #define CGENIE_DRIVE_INFO |
| 470 | |
| 471 | |
| 472 | |
| 473 | // |
| 474 | // abbreviations used: |
| 475 | // GPL Granules Per Lump |
| 476 | // GAT Granule Allocation Table |
| 477 | // GATL GAT Length |
| 478 | // GATM GAT Mask |
| 479 | // DDGA Disk Directory Granule Allocation |
| 480 | typedef struct |
| 481 | { |
| 482 | UINT8 DDSL; // Disk Directory Start Lump (lump number of GAT) |
| 483 | UINT8 GATL; // # of bytes used in the Granule Allocation Table sector |
| 484 | UINT8 STEPRATE; // step rate and somet SD/DD flag ... |
| 485 | UINT8 TRK; // number of tracks |
| 486 | UINT8 SPT; // sectors per track (both heads counted!) |
| 487 | UINT8 GATM; // number of used bits per byte in the GAT sector (GAT mask) |
| 488 | UINT8 P7; // ???? always zero |
| 489 | UINT8 FLAGS; // ???? some flags (SS/DS bit 6) |
| 490 | UINT8 GPL; // Sectors per granule (always 5 for the Colour Genie) |
| 491 | UINT8 DDGA; // Disk Directory Granule allocation (number of driectory granules) |
| 492 | } PDRIVE; |
| 493 | |
| 494 | static const PDRIVE pd_list[12] = { |
| 495 | {0x14, 0x28, 0x07, 0x28, 0x0A, 0x02, 0x00, 0x00, 0x05, 0x02}, // CMD"<0=A" 40 tracks, SS, SD |
| 496 | {0x14, 0x28, 0x07, 0x28, 0x14, 0x04, 0x00, 0x40, 0x05, 0x04}, // CMD"<0=B" 40 tracks, DS, SD |
| 497 | {0x18, 0x30, 0x53, 0x28, 0x12, 0x03, 0x00, 0x03, 0x05, 0x03}, // CMD"<0=C" 40 tracks, SS, DD |
| 498 | {0x18, 0x30, 0x53, 0x28, 0x24, 0x06, 0x00, 0x43, 0x05, 0x06}, // CMD"<0=D" 40 tracks, DS, DD |
| 499 | {0x14, 0x28, 0x07, 0x28, 0x0A, 0x02, 0x00, 0x04, 0x05, 0x02}, // CMD"<0=E" 40 tracks, SS, SD |
| 500 | {0x14, 0x28, 0x07, 0x28, 0x14, 0x04, 0x00, 0x44, 0x05, 0x04}, // CMD"<0=F" 40 tracks, DS, SD |
| 501 | {0x18, 0x30, 0x53, 0x28, 0x12, 0x03, 0x00, 0x07, 0x05, 0x03}, // CMD"<0=G" 40 tracks, SS, DD |
| 502 | {0x18, 0x30, 0x53, 0x28, 0x24, 0x06, 0x00, 0x47, 0x05, 0x06}, // CMD"<0=H" 40 tracks, DS, DD |
| 503 | {0x28, 0x50, 0x07, 0x50, 0x0A, 0x02, 0x00, 0x00, 0x05, 0x02}, // CMD"<0=I" 80 tracks, SS, SD |
| 504 | {0x28, 0x50, 0x07, 0x50, 0x14, 0x04, 0x00, 0x40, 0x05, 0x04}, // CMD"<0=J" 80 tracks, DS, SD |
| 505 | {0x30, 0x60, 0x53, 0x50, 0x12, 0x03, 0x00, 0x03, 0x05, 0x03}, // CMD"<0=K" 80 tracks, SS, DD |
| 506 | {0x30, 0x60, 0x53, 0x50, 0x24, 0x06, 0x00, 0x43, 0x05, 0x06}, // CMD"<0=L" 80 tracks, DS, DD |
| 507 | }; |
| 508 | |
| 509 | // basic-dsk is a disk image format which has the tracks and sectors |
| 510 | // stored in order, no information is stored which details the number |
| 511 | // of tracks, number of sides, number of sectors etc, so we need to |
| 512 | // set that up here |
| 513 | // |
| 514 | DEVICE_IMAGE_LOAD( cgenie_floppy ) |
| 515 | { |
| 516 | int i, j, dir_offset; |
| 517 | UINT8 buff[16]; |
| 518 | UINT8 tracks = 0; |
| 519 | UINT8 heads = 0; |
| 520 | UINT8 spt = 0; |
| 521 | short dir_sector = 0; |
| 522 | short dir_length = 0; |
| 523 | |
| 524 | // A Floppy Isnt manditory, so return if none |
| 525 | if (device_load_basicdsk_floppy(image) != INIT_PASS) |
| 526 | return INIT_FAIL; |
| 527 | |
| 528 | // determine image geometry |
| 529 | image_fseek(image, 0, SEEK_SET); |
| 530 | |
| 531 | // determine geometry from disk contents |
| 532 | for( i = 0; i < 12; i++ ) |
| 533 | { |
| 534 | image_fseek(image, pd_list[i].SPT * 256, SEEK_SET); |
| 535 | image_fread(image, buff, 16); |
| 536 | // find an entry with matching DDSL |
| 537 | if (buff[0] != 0x00 || buff[1] != 0xfe || buff[2] != pd_list[i].DDSL) |
| 538 | continue; |
| 539 | logerror("cgenie: checking format #%d\n", i); |
| 540 | |
| 541 | dir_sector = pd_list[i].DDSL * pd_list[i].GATM * pd_list[i].GPL + pd_list[i].SPT; |
| 542 | dir_length = pd_list[i].DDGA * pd_list[i].GPL; |
| 543 | |
| 544 | // scan directory for DIR/SYS or NCW1983/JHL files |
| 545 | // look into sector 2 and 3 first entry relative to DDSL |
| 546 | for( j = 16; j < 32; j += 8 ) |
| 547 | { |
| 548 | dir_offset = dir_sector * 256 + j * 32; |
| 549 | if( image_fseek(image, dir_offset, SEEK_SET) < 0 ) |
| 550 | break; |
| 551 | if( image_fread(image, buff, 16) != 16 ) |
| 552 | break; |
| 553 | if( !strncmp((char*)buff + 5, "DIR SYS", 11) || |
| 554 | !strncmp((char*)buff + 5, "NCW1983 JHL", 11) ) |
| 555 | { |
| 556 | tracks = pd_list[i].TRK; |
| 557 | heads = (pd_list[i].SPT > 18) ? 2 : 1; |
| 558 | spt = pd_list[i].SPT / heads; |
| 559 | dir_sector = pd_list[i].DDSL * pd_list[i].GATM * pd_list[i].GPL + pd_list[i].SPT; |
| 560 | dir_length = pd_list[i].DDGA * pd_list[i].GPL; |
| 561 | memcpy(memory_region(image->machine, "maincpu") + 0x5A71 + image_index_in_device(image) * sizeof(PDRIVE), &pd_list[i], sizeof(PDRIVE)); |
| 562 | break; |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | logerror("cgenie: geometry %d tracks, %d heads, %d sec/track\n", tracks, heads, spt); |
| 567 | // set geometry so disk image can be read |
| 568 | basicdsk_set_geometry(image, tracks, heads, spt, 256, 0, 0, FALSE); |
| 569 | |
| 570 | logerror("cgenie: directory sectors %d - %d (%d sectors)\n", dir_sector, dir_sector + dir_length - 1, dir_length); |
| 571 | // mark directory sectors with deleted data address mark |
| 572 | // assumption dir_sector is a sector offset |
| 573 | for (j = 0; j < dir_length; j++) |
| 574 | { |
| 575 | UINT8 track; |
| 576 | UINT8 side; |
| 577 | UINT8 sector_id; |
| 578 | UINT16 track_offset; |
| 579 | UINT16 sector_offset; |
| 580 | |
| 581 | // calc sector offset |
| 582 | sector_offset = dir_sector + j; |
| 583 | |
| 584 | // get track offset |
| 585 | track_offset = sector_offset / spt; |
| 586 | |
| 587 | // calc track |
| 588 | track = track_offset / heads; |
| 589 | |
| 590 | // calc side |
| 591 | side = track_offset % heads; |
| 592 | |
| 593 | // calc sector id - first sector id is 0! |
| 594 | sector_id = sector_offset % spt; |
| 595 | |
| 596 | // set deleted data address mark for sector specified |
| 597 | basicdsk_set_ddam(image, track, side, sector_id, 1); |
| 598 | } |
| 599 | |
| 600 | } |
| 601 | return INIT_PASS; |
| 602 | } |
| 603 | */ |
| 604 | // This is currently broken |
| 605 | FLOPPY_OPTIONS_START(cgenie ) |
| 606 | FLOPPY_OPTION( cgd, "cgd", "Colour Genie disk image", basicdsk_identify_default, basicdsk_construct_default, |
| 607 | HEADS([2]) |
| 608 | TRACKS([40]) |
| 609 | SECTORS([10]) |
| 610 | SECTOR_LENGTH([256]) |
| 611 | FIRST_SECTOR_ID([1])) |
| 612 | FLOPPY_OPTIONS_END |
| 613 | |
| 465 | 614 | static void cgenie_floppy_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 466 | 615 | { |
| 467 | 616 | /* floppy */ |
| r5631 | r5632 | |
| 471 | 620 | case MESS_DEVINFO_INT_COUNT: info->i = 4; break; |
| 472 | 621 | |
| 473 | 622 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 474 | | case MESS_DEVINFO_PTR_LOAD: info->load = DEVICE_IMAGE_LOAD_NAME(cgenie_floppy); break; |
| 623 | case MESS_DEVINFO_PTR_FLOPPY_OPTIONS: info->p = (void *) floppyoptions_cgenie; break; |
| 475 | 624 | |
| 476 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 477 | | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "dsk"); break; |
| 478 | | |
| 479 | | default: legacybasicdsk_device_getinfo(devclass, state, info); break; |
| 625 | default: floppy_device_getinfo(devclass, state, info); break; |
| 480 | 626 | } |
| 481 | 627 | } |
| 482 | 628 | |
| 483 | | |
| 484 | 629 | static SYSTEM_CONFIG_START(cgenie) |
| 485 | 630 | CONFIG_DEVICE(cgenie_floppy_getinfo) |
| 486 | 631 | CONFIG_RAM_DEFAULT (16 * 1024) |