src/mess/machine/cgenie.c
| r3669 | r3670 | |
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | #define AYWriteReg(chip,port,value) \ |
| 22 | | ay8910_control_port_0_w(machine, 0,port); \ |
| 23 | | ay8910_write_port_0_w(machine, 0,value) |
| 22 | ay8910_control_port_0_w(space, 0,port); \ |
| 23 | ay8910_write_port_0_w(space, 0,value) |
| 24 | 24 | |
| 25 | 25 | #define TAPE_HEADER "Colour Genie - Virtual Tape File" |
| 26 | 26 | |
| r3669 | r3670 | |
| 97 | 97 | |
| 98 | 98 | MACHINE_RESET( cgenie ) |
| 99 | 99 | { |
| 100 | const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ); |
| 100 | 101 | UINT8 *ROM = memory_region(machine, "main"); |
| 101 | 102 | |
| 102 | 103 | /* reset the AY8910 to be quiet, since the cgenie BIOS doesn't */ |
| r3669 | r3670 | |
| 132 | 133 | { |
| 133 | 134 | if ( input_port_read(machine, "DSW0") & 0x80 ) |
| 134 | 135 | { |
| 135 | | memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc000, 0xdfff, 0, 0, SMH_BANK10); |
| 136 | | memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc000, 0xdfff, 0, 0, SMH_NOP); |
| 136 | memory_install_read8_handler(space, 0xc000, 0xdfff, 0, 0, SMH_BANK10); |
| 137 | memory_install_write8_handler(space, 0xc000, 0xdfff, 0, 0, SMH_NOP); |
| 137 | 138 | memory_set_bankptr(machine, 10, &ROM[0x0c000]); |
| 138 | 139 | logerror("cgenie DOS enabled\n"); |
| 139 | 140 | memcpy(&ROM[0x0c000],&ROM[0x10000], 0x2000); |
| 140 | 141 | } |
| 141 | 142 | else |
| 142 | 143 | { |
| 143 | | memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc000, 0xdfff, 0, 0, SMH_NOP); |
| 144 | | memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc000, 0xdfff, 0, 0, SMH_NOP); |
| 144 | memory_install_read8_handler(space, 0xc000, 0xdfff, 0, 0, SMH_NOP); |
| 145 | memory_install_write8_handler(space, 0xc000, 0xdfff, 0, 0, SMH_NOP); |
| 145 | 146 | logerror("cgenie DOS disabled (no floppy image given)\n"); |
| 146 | 147 | } |
| 147 | 148 | } |
| 148 | 149 | else |
| 149 | 150 | { |
| 150 | | memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc000, 0xdfff, 0, 0, SMH_NOP); |
| 151 | | memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc000, 0xdfff, 0, 0, SMH_NOP); |
| 151 | memory_install_read8_handler(space, 0xc000, 0xdfff, 0, 0, SMH_NOP); |
| 152 | memory_install_write8_handler(space, 0xc000, 0xdfff, 0, 0, SMH_NOP); |
| 152 | 153 | logerror("cgenie DOS disabled\n"); |
| 153 | 154 | memset(&memory_region(machine, "main")[0x0c000], 0x00, 0x2000); |
| 154 | 155 | } |
| r3669 | r3670 | |
| 156 | 157 | /* copy EXT ROM, if enabled or wipe out that memory area */ |
| 157 | 158 | if( input_port_read(machine, "DSW0") & 0x20 ) |
| 158 | 159 | { |
| 159 | | memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xe000, 0xefff, 0, 0, SMH_ROM); |
| 160 | | memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xe000, 0xefff, 0, 0, SMH_ROM); |
| 160 | memory_install_read8_handler(space, 0xe000, 0xefff, 0, 0, SMH_ROM); |
| 161 | memory_install_write8_handler(space, 0xe000, 0xefff, 0, 0, SMH_ROM); |
| 161 | 162 | logerror("cgenie EXT enabled\n"); |
| 162 | 163 | memcpy(&memory_region(machine, "main")[0x0e000], |
| 163 | 164 | &memory_region(machine, "main")[0x12000], 0x1000); |
| 164 | 165 | } |
| 165 | 166 | else |
| 166 | 167 | { |
| 167 | | memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xe000, 0xefff, 0, 0, SMH_NOP); |
| 168 | | memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xe000, 0xefff, 0, 0, SMH_NOP); |
| 168 | memory_install_read8_handler(space, 0xe000, 0xefff, 0, 0, SMH_NOP); |
| 169 | memory_install_write8_handler(space, 0xe000, 0xefff, 0, 0, SMH_NOP); |
| 169 | 170 | logerror("cgenie EXT disabled\n"); |
| 170 | 171 | memset(&memory_region(machine, "main")[0x0e000], 0x00, 0x1000); |
| 171 | 172 | } |
| r3669 | r3670 | |
| 177 | 178 | |
| 178 | 179 | MACHINE_START( cgenie ) |
| 179 | 180 | { |
| 181 | const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ); |
| 180 | 182 | UINT8 *gfx = memory_region(machine, "gfx2"); |
| 181 | 183 | int i; |
| 182 | 184 | |
| r3669 | r3670 | |
| 197 | 199 | memset(gfx + i * 8, i, 8); |
| 198 | 200 | |
| 199 | 201 | /* set up RAM */ |
| 200 | | memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x4000 + mess_ram_size - 1, 0, 0, SMH_BANK1); |
| 201 | | memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x4000 + mess_ram_size - 1, 0, 0, cgenie_videoram_w); |
| 202 | memory_install_read8_handler(space, 0x4000, 0x4000 + mess_ram_size - 1, 0, 0, SMH_BANK1); |
| 203 | memory_install_write8_handler(space, 0x4000, 0x4000 + mess_ram_size - 1, 0, 0, cgenie_videoram_w); |
| 202 | 204 | videoram = mess_ram; |
| 203 | 205 | memory_set_bankptr(machine, 1, mess_ram); |
| 204 | 206 | |
| r3669 | r3670 | |
| 324 | 326 | { |
| 325 | 327 | int port_ff_changed = port_ff ^ data; |
| 326 | 328 | |
| 327 | | cassette_output ( device_list_find_by_tag( machine->config->devicelist, CASSETTE, "cassette" ), data & 0x01 ? -1.0 : 1.0 ); |
| 329 | cassette_output ( device_list_find_by_tag( space->machine->config->devicelist, CASSETTE, "cassette" ), data & 0x01 ? -1.0 : 1.0 ); |
| 328 | 330 | |
| 329 | 331 | /* background bits changed ? */ |
| 330 | 332 | if( port_ff_changed & FF_BGD ) |
| r3669 | r3670 | |
| 372 | 374 | b = 15; |
| 373 | 375 | } |
| 374 | 376 | } |
| 375 | | palette_set_color_rgb(machine, 0, r, g, b); |
| 377 | palette_set_color_rgb(space->machine, 0, r, g, b); |
| 376 | 378 | } |
| 377 | 379 | |
| 378 | 380 | /* character mode changed ? */ |
| r3669 | r3670 | |
| 429 | 431 | /* comparator value */ |
| 430 | 432 | psg_b_inp = 0x00; |
| 431 | 433 | |
| 432 | | if( input_port_read(machine, "JOY0") > psg_a_out ) |
| 434 | if( input_port_read(space->machine, "JOY0") > psg_a_out ) |
| 433 | 435 | psg_b_inp |= 0x80; |
| 434 | 436 | |
| 435 | | if( input_port_read(machine, "JOY1") > psg_a_out ) |
| 437 | if( input_port_read(space->machine, "JOY1") > psg_a_out ) |
| 436 | 438 | psg_b_inp |= 0x40; |
| 437 | 439 | |
| 438 | | if( input_port_read(machine, "JOY2") > psg_a_out ) |
| 440 | if( input_port_read(space->machine, "JOY2") > psg_a_out ) |
| 439 | 441 | psg_b_inp |= 0x20; |
| 440 | 442 | |
| 441 | | if( input_port_read(machine, "JOY3") > psg_a_out ) |
| 443 | if( input_port_read(space->machine, "JOY3") > psg_a_out ) |
| 442 | 444 | psg_b_inp |= 0x10; |
| 443 | 445 | } |
| 444 | 446 | else |
| r3669 | r3670 | |
| 447 | 449 | psg_b_inp = 0xFF; |
| 448 | 450 | |
| 449 | 451 | if( !(psg_a_out & 0x01) ) |
| 450 | | psg_b_inp &= ~input_port_read(machine, "KP0"); |
| 452 | psg_b_inp &= ~input_port_read(space->machine, "KP0"); |
| 451 | 453 | |
| 452 | 454 | if( !(psg_a_out & 0x02) ) |
| 453 | | psg_b_inp &= ~input_port_read(machine, "KP1"); |
| 455 | psg_b_inp &= ~input_port_read(space->machine, "KP1"); |
| 454 | 456 | |
| 455 | 457 | if( !(psg_a_out & 0x04) ) |
| 456 | | psg_b_inp &= ~input_port_read(machine, "KP2"); |
| 458 | psg_b_inp &= ~input_port_read(space->machine, "KP2"); |
| 457 | 459 | |
| 458 | 460 | if( !(psg_a_out & 0x08) ) |
| 459 | | psg_b_inp &= ~input_port_read(machine, "KP3"); |
| 461 | psg_b_inp &= ~input_port_read(space->machine, "KP3"); |
| 460 | 462 | |
| 461 | 463 | if( !(psg_a_out & 0x10) ) |
| 462 | | psg_b_inp &= ~input_port_read(machine, "KP4"); |
| 464 | psg_b_inp &= ~input_port_read(space->machine, "KP4"); |
| 463 | 465 | |
| 464 | 466 | if( !(psg_a_out & 0x20) ) |
| 465 | | psg_b_inp &= ~input_port_read(machine, "KP5"); |
| 467 | psg_b_inp &= ~input_port_read(space->machine, "KP5"); |
| 466 | 468 | } |
| 467 | 469 | return psg_b_inp; |
| 468 | 470 | } |
| r3669 | r3670 | |
| 480 | 482 | READ8_HANDLER( cgenie_status_r ) |
| 481 | 483 | { |
| 482 | 484 | /* If the floppy isn't emulated, return 0 */ |
| 483 | | if( (input_port_read(machine, "DSW0") & 0x80) == 0 ) |
| 485 | if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 ) |
| 484 | 486 | return 0; |
| 485 | | return wd17xx_status_r(machine, offset); |
| 487 | return wd17xx_status_r(space, offset); |
| 486 | 488 | } |
| 487 | 489 | |
| 488 | 490 | READ8_HANDLER( cgenie_track_r ) |
| 489 | 491 | { |
| 490 | 492 | /* If the floppy isn't emulated, return 0xff */ |
| 491 | | if( (input_port_read(machine, "DSW0") & 0x80) == 0 ) |
| 493 | if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 ) |
| 492 | 494 | return 0xff; |
| 493 | | return wd17xx_track_r(machine, offset); |
| 495 | return wd17xx_track_r(space, offset); |
| 494 | 496 | } |
| 495 | 497 | |
| 496 | 498 | READ8_HANDLER( cgenie_sector_r ) |
| 497 | 499 | { |
| 498 | 500 | /* If the floppy isn't emulated, return 0xff */ |
| 499 | | if( (input_port_read(machine, "DSW0") & 0x80) == 0 ) |
| 501 | if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 ) |
| 500 | 502 | return 0xff; |
| 501 | | return wd17xx_sector_r(machine, offset); |
| 503 | return wd17xx_sector_r(space, offset); |
| 502 | 504 | } |
| 503 | 505 | |
| 504 | 506 | READ8_HANDLER(cgenie_data_r ) |
| 505 | 507 | { |
| 506 | 508 | /* If the floppy isn't emulated, return 0xff */ |
| 507 | | if( (input_port_read(machine, "DSW0") & 0x80) == 0 ) |
| 509 | if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 ) |
| 508 | 510 | return 0xff; |
| 509 | | return wd17xx_data_r(machine, offset); |
| 511 | return wd17xx_data_r(space, offset); |
| 510 | 512 | } |
| 511 | 513 | |
| 512 | 514 | WRITE8_HANDLER( cgenie_command_w ) |
| 513 | 515 | { |
| 514 | 516 | /* If the floppy isn't emulated, return immediately */ |
| 515 | | if( (input_port_read(machine, "DSW0") & 0x80) == 0 ) |
| 517 | if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 ) |
| 516 | 518 | return; |
| 517 | | wd17xx_command_w(machine, offset, data); |
| 519 | wd17xx_command_w(space, offset, data); |
| 518 | 520 | } |
| 519 | 521 | |
| 520 | 522 | WRITE8_HANDLER( cgenie_track_w ) |
| 521 | 523 | { |
| 522 | 524 | /* If the floppy isn't emulated, ignore the write */ |
| 523 | | if( (input_port_read(machine, "DSW0") & 0x80) == 0 ) |
| 525 | if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 ) |
| 524 | 526 | return; |
| 525 | | wd17xx_track_w(machine, offset, data); |
| 527 | wd17xx_track_w(space, offset, data); |
| 526 | 528 | } |
| 527 | 529 | |
| 528 | 530 | WRITE8_HANDLER( cgenie_sector_w ) |
| 529 | 531 | { |
| 530 | 532 | /* If the floppy isn't emulated, ignore the write */ |
| 531 | | if( (input_port_read(machine, "DSW0") & 0x80) == 0 ) |
| 533 | if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 ) |
| 532 | 534 | return; |
| 533 | | wd17xx_sector_w(machine, offset, data); |
| 535 | wd17xx_sector_w(space, offset, data); |
| 534 | 536 | } |
| 535 | 537 | |
| 536 | 538 | WRITE8_HANDLER( cgenie_data_w ) |
| 537 | 539 | { |
| 538 | 540 | /* If the floppy isn't emulated, ignore the write */ |
| 539 | | if( (input_port_read(machine, "DSW0") & 0x80) == 0 ) |
| 541 | if( (input_port_read(space->machine, "DSW0") & 0x80) == 0 ) |
| 540 | 542 | return; |
| 541 | | wd17xx_data_w(machine, offset, data); |
| 543 | wd17xx_data_w(space, offset, data); |
| 542 | 544 | } |
| 543 | 545 | |
| 544 | 546 | READ8_HANDLER( cgenie_irq_status_r ) |
| r3669 | r3670 | |
| 554 | 556 | if( (irq_status & IRQ_TIMER) == 0 ) |
| 555 | 557 | { |
| 556 | 558 | irq_status |= IRQ_TIMER; |
| 557 | | cpu_set_input_line(machine->cpu[0], 0, HOLD_LINE); |
| 559 | cpu_set_input_line(device->machine->cpu[0], 0, HOLD_LINE); |
| 558 | 560 | } |
| 559 | 561 | } |
| 560 | 562 | |
| 561 | | static INTERRUPT_GEN( cgenie_fdc_interrupt ) |
| 562 | | { |
| 563 | | if( (irq_status & IRQ_FDC) == 0 ) |
| 564 | | { |
| 565 | | irq_status |= IRQ_FDC; |
| 566 | | cpu_set_input_line(machine->cpu[0], 0, HOLD_LINE); |
| 567 | | } |
| 568 | | } |
| 569 | | |
| 570 | 563 | void cgenie_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param) |
| 571 | 564 | { |
| 572 | 565 | /* if disc hardware is not enabled, do not cause an int */ |
| r3669 | r3670 | |
| 579 | 572 | irq_status &= ~IRQ_FDC; |
| 580 | 573 | break; |
| 581 | 574 | case WD17XX_IRQ_SET: |
| 582 | | cgenie_fdc_interrupt(machine, 0); |
| 575 | if( (irq_status & IRQ_FDC) == 0 ) |
| 576 | { |
| 577 | irq_status |= IRQ_FDC; |
| 578 | cpu_set_input_line(machine->cpu[0], 0, HOLD_LINE); |
| 579 | } |
| 583 | 580 | break; |
| 584 | 581 | case WD17XX_DRQ_CLR: |
| 585 | 582 | case WD17XX_DRQ_SET: |
| r3669 | r3670 | |
| 624 | 621 | int result = 0; |
| 625 | 622 | |
| 626 | 623 | if( offset & 0x01 ) |
| 627 | | result |= input_port_read(machine, "ROW0"); |
| 624 | result |= input_port_read(space->machine, "ROW0"); |
| 628 | 625 | |
| 629 | 626 | if( offset & 0x02 ) |
| 630 | | result |= input_port_read(machine, "ROW1"); |
| 627 | result |= input_port_read(space->machine, "ROW1"); |
| 631 | 628 | |
| 632 | 629 | if( offset & 0x04 ) |
| 633 | | result |= input_port_read(machine, "ROW2"); |
| 630 | result |= input_port_read(space->machine, "ROW2"); |
| 634 | 631 | |
| 635 | 632 | if( offset & 0x08 ) |
| 636 | | result |= input_port_read(machine, "ROW3"); |
| 633 | result |= input_port_read(space->machine, "ROW3"); |
| 637 | 634 | |
| 638 | 635 | if( offset & 0x10 ) |
| 639 | | result |= input_port_read(machine, "ROW4"); |
| 636 | result |= input_port_read(space->machine, "ROW4"); |
| 640 | 637 | |
| 641 | 638 | if( offset & 0x20 ) |
| 642 | | result |= input_port_read(machine, "ROW5"); |
| 639 | result |= input_port_read(space->machine, "ROW5"); |
| 643 | 640 | |
| 644 | 641 | if( offset & 0x40 ) |
| 645 | | result |= input_port_read(machine, "ROW6"); |
| 642 | result |= input_port_read(space->machine, "ROW6"); |
| 646 | 643 | |
| 647 | 644 | if( offset & 0x80 ) |
| 648 | | result |= input_port_read(machine, "ROW7"); |
| 645 | result |= input_port_read(space->machine, "ROW7"); |
| 649 | 646 | |
| 650 | 647 | return result; |
| 651 | 648 | } |
| r3669 | r3670 | |
| 702 | 699 | cgenie_fontram[offset] = data; |
| 703 | 700 | |
| 704 | 701 | /* convert eight pixels */ |
| 705 | | dp = &machine->gfx[0]->gfxdata[(256 * 8 + offset) * machine->gfx[0]->width]; |
| 702 | dp = &space->machine->gfx[0]->gfxdata[(256 * 8 + offset) * space->machine->gfx[0]->width]; |
| 706 | 703 | dp[0] = (data & 0x80) ? 1 : 0; |
| 707 | 704 | dp[1] = (data & 0x40) ? 1 : 0; |
| 708 | 705 | dp[2] = (data & 0x20) ? 1 : 0; |
| r3669 | r3670 | |
| 721 | 718 | |
| 722 | 719 | INTERRUPT_GEN( cgenie_frame_interrupt ) |
| 723 | 720 | { |
| 724 | | if( cgenie_tv_mode != (input_port_read(machine, "DSW0") & 0x10) ) |
| 721 | if( cgenie_tv_mode != (input_port_read(device->machine, "DSW0") & 0x10) ) |
| 725 | 722 | { |
| 726 | | cgenie_tv_mode = input_port_read(machine, "DSW0") & 0x10; |
| 723 | cgenie_tv_mode = input_port_read(device->machine, "DSW0") & 0x10; |
| 727 | 724 | /* force setting of background color */ |
| 728 | 725 | port_ff ^= FF_BGD0; |
| 729 | | cgenie_port_ff_w(machine, 0, port_ff ^ FF_BGD0); |
| 726 | cgenie_port_ff_w(cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0, port_ff ^ FF_BGD0); |
| 730 | 727 | } |
| 731 | 728 | } |