src/mess/machine/c64.c
| r3130 | r3131 | |
| 12 | 12 | (program write some short test code into the vic sprite register) |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | /* |
| 16 | 2008-08-31: Tape status [FP & RZ] |
| 17 | - tape loading works |
| 18 | |
| 19 | TODO: |
| 20 | * write to tape |
| 21 | * FFW & REW |
| 22 | * support for .tap files |
| 23 | * fix implementation for other CBM machines |
| 24 | */ |
| 25 | |
| 15 | 26 | #include "driver.h" |
| 16 | 27 | |
| 17 | 28 | #include "cpu/m6502/m6502.h" |
| r3130 | r3131 | |
| 28 | 39 | #include "video/vic6567.h" |
| 29 | 40 | #include "video/vdc8563.h" |
| 30 | 41 | |
| 31 | | #include "includes/c128.h" /* we need c128_bankswitch_64 in c64_m6510_port_write */ |
| 32 | 42 | #include "includes/c64.h" |
| 43 | #include "includes/c128.h" /* we need c128_bankswitch_64 in MACHINE_START */ |
| 33 | 44 | |
| 34 | | static void c64_driver_shutdown (running_machine *machine); |
| 45 | #include "devices/cassette.h" |
| 35 | 46 | |
| 36 | 47 | unsigned char c65_keyline = { 0xff }; |
| 37 | 48 | UINT8 c65_6511_port=0xff; |
| r3130 | r3131 | |
| 47 | 58 | |
| 48 | 59 | /* expansion port lines input */ |
| 49 | 60 | int c64_pal = 0; |
| 50 | | UINT8 c64_game=1, c64_exrom=1; |
| 61 | UINT8 c64_game = 1, c64_exrom = 1; |
| 51 | 62 | |
| 52 | 63 | /* cpu port */ |
| 53 | 64 | int c128_va1617; |
| r3130 | r3131 | |
| 323 | 334 | } |
| 324 | 335 | } |
| 325 | 336 | |
| 326 | | WRITE8_HANDLER(c64_tape_read) |
| 327 | | { |
| 328 | | cia_issue_index(machine, 0); |
| 329 | | } |
| 330 | | |
| 331 | 337 | static void c64_cia0_interrupt (running_machine *machine, int level) |
| 332 | 338 | { |
| 333 | 339 | c64_irq (machine, level || vicirq); |
| r3130 | r3131 | |
| 421 | 427 | } |
| 422 | 428 | }; |
| 423 | 429 | |
| 430 | |
| 431 | static UINT8 *c64_io_ram_w_ptr; |
| 432 | static UINT8 *c64_io_ram_r_ptr; |
| 433 | |
| 424 | 434 | WRITE8_HANDLER( c64_write_io ) |
| 425 | 435 | { |
| 426 | 436 | c64_io_mirror[ offset ] = data; |
| r3130 | r3131 | |
| 451 | 461 | } |
| 452 | 462 | } |
| 453 | 463 | |
| 454 | | static UINT8 *c64_io_ram_w_ptr; |
| 455 | | static UINT8 *c64_io_ram_r_ptr; |
| 456 | | |
| 457 | 464 | WRITE8_HANDLER(c64_ioarea_w) |
| 458 | 465 | { |
| 459 | | if ( c64_io_enabled ) { |
| 460 | | c64_write_io( machine, offset, data ); |
| 461 | | } else { |
| 462 | | c64_io_ram_w_ptr[ offset ] = data; |
| 466 | if (c64_io_enabled) |
| 467 | { |
| 468 | c64_write_io(machine, offset, data); |
| 469 | } |
| 470 | else |
| 471 | { |
| 472 | c64_io_ram_w_ptr[offset] = data; |
| 463 | 473 | } |
| 464 | 474 | } |
| 465 | 475 | |
| r3130 | r3131 | |
| 491 | 501 | |
| 492 | 502 | READ8_HANDLER(c64_ioarea_r) |
| 493 | 503 | { |
| 494 | | if ( c64_io_enabled ) { |
| 495 | | return c64_read_io( machine, offset ); |
| 496 | | } |
| 497 | | return c64_io_ram_r_ptr[ offset ]; |
| 504 | return c64_io_enabled ? c64_read_io(machine, offset) : c64_io_ram_r_ptr[offset]; |
| 498 | 505 | } |
| 499 | 506 | |
| 507 | |
| 508 | /* Info from http://unusedino.de/ec64/technical/misc/c64/64doc.html */ |
| 500 | 509 | /* |
| 501 | | * two devices access bus, cpu and vic |
| 502 | | * |
| 503 | | * romh, roml chip select lines on expansion bus |
| 504 | | * loram, hiram, charen bankswitching select by cpu |
| 505 | | * exrom, game bankswitching select by cartridge |
| 506 | | * va15, va14 bank select by cpu for vic |
| 507 | | * |
| 508 | | * exrom, game: normal c64 mode |
| 509 | | * exrom, !game: ultimax mode |
| 510 | | * |
| 511 | | * romh: 8k rom at 0xa000 (hiram && !game && exrom) |
| 512 | | * or 8k ram at 0xe000 (!game exrom) |
| 513 | | * roml: 8k rom at 0x8000 (loram hiram !exrom) |
| 514 | | * or 8k ram at 0x8000 (!game exrom) |
| 515 | | * roml vic: upper 4k rom at 0x3000, 0x7000, 0xb000, 0xd000 (!game exrom) |
| 516 | | * |
| 517 | | * basic rom: 8k rom at 0xa000 (loram hiram game) |
| 518 | | * kernal rom: 8k rom at 0xe000 (hiram !exrom, hiram game) |
| 519 | | * char rom: 4k rom at 0xd000 (!exrom charen hiram |
| 520 | | * game charen !hiram loram |
| 521 | | * game charen hiram) |
| 522 | | * cpu |
| 523 | | * |
| 524 | | * (write colorram) |
| 525 | | * gr_w = !read&&!cas&&((address&0xf000)==0xd000) |
| 526 | | * |
| 527 | | * i_o = !game exrom !read ((address&0xf000)==0xd000) |
| 528 | | * !game exrom ((address&0xf000)==0xd000) |
| 529 | | * charen !hiram loram !read ((address&0xf000)==0xd000) |
| 530 | | * charen !hiram loram ((address&0xf000)==0xd000) |
| 531 | | * charen hiram !read ((address&0xf000)==0xd000) |
| 532 | | * charen hiram ((address&0xf000)==0xd000) |
| 533 | | * |
| 534 | | * vic |
| 535 | | * char rom: x101 (game, !exrom) |
| 536 | | * romh: 0011 (!game, exrom) |
| 537 | | * |
| 538 | | * exrom !game (ultimax mode) |
| 539 | | * addr CPU VIC-II |
| 540 | | * ---- --- ------ |
| 541 | | * 0000 RAM RAM |
| 542 | | * 1000 - RAM |
| 543 | | * 2000 - RAM |
| 544 | | * 3000 - ROMH (upper half) |
| 545 | | * 4000 - RAM |
| 546 | | * 5000 - RAM |
| 547 | | * 6000 - RAM |
| 548 | | * 7000 - ROMH |
| 549 | | * 8000 ROML RAM |
| 550 | | * 9000 ROML RAM |
| 551 | | * A000 - RAM |
| 552 | | * B000 - ROMH |
| 553 | | * C000 - RAM |
| 554 | | * D000 I/O RAM |
| 555 | | * E000 ROMH RAM |
| 556 | | * F000 ROMH ROMH |
| 557 | | */ |
| 510 | |
| 511 | The leftmost column of the table contains addresses in hexadecimal |
| 512 | notation. The columns aside it introduce all possible memory |
| 513 | configurations. The default mode is on the left, and the absolutely |
| 514 | most rarely used Ultimax game console configuration is on the right. |
| 515 | (Has anybody ever seen any Ultimax games?) Each memory configuration |
| 516 | column has one or more four-digit binary numbers as a title. The bits, |
| 517 | from left to right, represent the state of the -LORAM, -HIRAM, -GAME |
| 518 | and -EXROM lines, respectively. The bits whose state does not matter |
| 519 | are marked with "x". For instance, when the Ultimax video game |
| 520 | configuration is active (the -GAME line is shorted to ground), the |
| 521 | -LORAM and -HIRAM lines have no effect. |
| 522 | |
| 523 | default 001x Ultimax |
| 524 | 1111 101x 1000 011x 00x0 1110 0100 1100 xx01 |
| 525 | 10000 |
| 526 | ---------------------------------------------------------------------- |
| 527 | F000 |
| 528 | Kernal RAM RAM Kernal RAM Kernal Kernal Kernal ROMH(* |
| 529 | E000 |
| 530 | ---------------------------------------------------------------------- |
| 531 | D000 IO/C IO/C IO/RAM IO/C RAM IO/C IO/C IO/C I/O |
| 532 | ---------------------------------------------------------------------- |
| 533 | C000 RAM RAM RAM RAM RAM RAM RAM RAM - |
| 534 | ---------------------------------------------------------------------- |
| 535 | B000 |
| 536 | BASIC RAM RAM RAM RAM BASIC ROMH ROMH - |
| 537 | A000 |
| 538 | ---------------------------------------------------------------------- |
| 539 | 9000 |
| 540 | RAM RAM RAM RAM RAM ROML RAM ROML ROML(* |
| 541 | 8000 |
| 542 | ---------------------------------------------------------------------- |
| 543 | 7000 |
| 544 | |
| 545 | 6000 |
| 546 | RAM RAM RAM RAM RAM RAM RAM RAM - |
| 547 | 5000 |
| 548 | |
| 549 | 4000 |
| 550 | ---------------------------------------------------------------------- |
| 551 | 3000 |
| 552 | |
| 553 | 2000 RAM RAM RAM RAM RAM RAM RAM RAM - |
| 554 | |
| 555 | 1000 |
| 556 | ---------------------------------------------------------------------- |
| 557 | 0000 RAM RAM RAM RAM RAM RAM RAM RAM RAM |
| 558 | ---------------------------------------------------------------------- |
| 559 | |
| 560 | *) Internal memory does not respond to write accesses to these |
| 561 | areas. |
| 562 | |
| 563 | |
| 564 | Legend: Kernal E000-FFFF Kernal ROM. |
| 565 | |
| 566 | IO/C D000-DFFF I/O address space or Character |
| 567 | generator ROM, selected by |
| 568 | -CHAREN. If the CHAREN bit is |
| 569 | clear, the character generator |
| 570 | ROM will be selected. If it is |
| 571 | set, the I/O chips are |
| 572 | accessible. |
| 573 | |
| 574 | IO/RAM D000-DFFF I/O address space or RAM, |
| 575 | selected by -CHAREN. If the |
| 576 | CHAREN bit is clear, the |
| 577 | character generator ROM will |
| 578 | be selected. If it is set, the |
| 579 | internal RAM is accessible. |
| 580 | |
| 581 | I/O D000-DFFF I/O address space. |
| 582 | The -CHAREN line has no effect. |
| 583 | |
| 584 | BASIC A000-BFFF BASIC ROM. |
| 585 | |
| 586 | ROMH A000-BFFF or External ROM with the -ROMH line |
| 587 | E000-FFFF connected to its -CS line. |
| 588 | |
| 589 | ROML 8000-9FFF External ROM with the -ROML line |
| 590 | connected to its -CS line. |
| 591 | |
| 592 | RAM various ranges Commodore 64's internal RAM. |
| 593 | |
| 594 | - 1000-7FFF and Open address space. |
| 595 | A000-CFFF The Commodore 64's memory chips |
| 596 | do not detect any memory accesses |
| 597 | to this area except the VIC-II's |
| 598 | DMA and memory refreshes. |
| 599 | |
| 600 | NOTE: Whenever the processor tries to write to any ROM area |
| 601 | (Kernal, BASIC, CHAROM, ROML, ROMH), the data will get |
| 602 | "through the ROM" to the C64's internal RAM. |
| 603 | |
| 604 | For this reason, you can easily copy data from ROM to RAM, |
| 605 | without any bank switching. But implementing external |
| 606 | memory expansions without DMA is very hard, as you have to |
| 607 | use a 256 byte window on the I/O1 or I/O2 area, like |
| 608 | GEORAM, or the Ultimax memory configuration, if you do not |
| 609 | want the data to be written both to internal and external |
| 610 | RAM. |
| 611 | |
| 612 | However, this is not true for the Ultimax video game |
| 613 | configuration. In that mode, the internal RAM ignores all |
| 614 | memory accesses outside the area $0000-$0FFF, unless they |
| 615 | are performed by the VIC, and you can write to external |
| 616 | memory at $1000-$CFFF and $E000-$FFFF, if any, without |
| 617 | changing the contents of the internal RAM. |
| 618 | |
| 619 | */ |
| 620 | |
| 558 | 621 | static void c64_bankswitch(running_machine *machine, int reset) |
| 559 | 622 | { |
| 560 | 623 | static int old = -1, exrom, game; |
| 561 | | int data, loram, hiram, charen; |
| 624 | int loram, hiram, charen; |
| 625 | int ultimax_mode = 0; |
| 626 | int data = (UINT8) cpunum_get_info_int(0, CPUINFO_INT_M6510_PORT) & 0x07; |
| 562 | 627 | |
| 563 | | data = (UINT8) cpunum_get_info_int(0, CPUINFO_INT_M6510_PORT) & 7; |
| 564 | | if ((data == old)&&(exrom==c64_exrom)&&(game==c64_game)&&!reset) return; |
| 628 | /* If nothing has changed or reset = 0, don't do anything */ |
| 629 | if ((data == old) && (exrom == c64_exrom) && (game == c64_game) && !reset) |
| 630 | return; |
| 565 | 631 | |
| 632 | /* Are we in Ultimax mode? */ |
| 633 | if (!c64_game && c64_exrom) |
| 634 | ultimax_mode = 1; |
| 635 | |
| 566 | 636 | DBG_LOG (1, "bankswitch", ("%d\n", data & 7)); |
| 567 | | loram = (data & 1) ? 1 : 0; |
| 568 | | hiram = (data & 2) ? 1 : 0; |
| 637 | loram = (data & 1) ? 1 : 0; |
| 638 | hiram = (data & 2) ? 1 : 0; |
| 569 | 639 | charen = (data & 4) ? 1 : 0; |
| 570 | 640 | |
| 571 | | if ((!c64_game && c64_exrom) |
| 572 | | || (loram && !c64_exrom)) // for omega race cartridge |
| 573 | | // || (loram && hiram && !c64_exrom)) |
| 641 | if (ultimax_mode) |
| 574 | 642 | { |
| 575 | | memory_set_bankptr (1, roml); |
| 576 | | memory_set_bankptr (2, c64_memory + 0x8000); |
| 577 | | } |
| 578 | | else |
| 579 | | { |
| 580 | | memory_set_bankptr (1, c64_memory + 0x8000); |
| 581 | | memory_set_bankptr (2, c64_memory + 0x8000); |
| 582 | | } |
| 643 | c64_io_enabled = 1; // charen has no effect in ultimax_mode |
| 583 | 644 | |
| 584 | | #if 1 |
| 585 | | if ((!c64_game && !c64_exrom && hiram) |
| 586 | | /*|| (!c64_exrom)*/) // must be disabled for 8kb c64 cartridges! like space action, super expander, ... |
| 587 | | #else |
| 588 | | if ((!c64_game && c64_exrom && hiram) |
| 589 | | || (!c64_exrom) ) |
| 590 | | #endif |
| 591 | | { |
| 592 | | memory_set_bankptr (3, romh); |
| 645 | memory_set_bankptr (1, roml); |
| 646 | memory_set_bankptr (2, c64_memory + 0x8000); |
| 647 | memory_set_bankptr (3, c64_memory + 0xa000); |
| 648 | memory_set_bankptr (4, romh); |
| 649 | memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xe000, 0xffff, 0, 0, SMH_NOP); |
| 593 | 650 | } |
| 594 | | else if (loram && hiram &&c64_game) |
| 595 | | { |
| 596 | | memory_set_bankptr (3, c64_basic); |
| 597 | | } |
| 598 | 651 | else |
| 599 | 652 | { |
| 600 | | memory_set_bankptr (3, c64_memory + 0xa000); |
| 601 | | } |
| 653 | /* 0x8000-0x9000 */ |
| 654 | if (loram && hiram && !c64_exrom) |
| 655 | { |
| 656 | memory_set_bankptr (1, roml); |
| 657 | memory_set_bankptr (2, c64_memory + 0x8000); |
| 658 | } |
| 659 | else |
| 660 | { |
| 661 | memory_set_bankptr (1, c64_memory + 0x8000); |
| 662 | memory_set_bankptr (2, c64_memory + 0x8000); |
| 663 | } |
| 602 | 664 | |
| 603 | | if ((!c64_game && c64_exrom) |
| 604 | | || (charen && (loram || hiram))) |
| 605 | | { |
| 606 | | c64_io_enabled = 1; |
| 607 | | // memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xd000, 0xdfff, 0, 0, c64_read_io); |
| 608 | | // memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xd000, 0xdfff, 0, 0, c64_write_io); |
| 609 | | // if ( cpu_getactivecpu() >= 0 ) |
| 610 | | // memory_set_opbase(activecpu_get_physical_pc_byte()); |
| 611 | | } |
| 612 | | else |
| 613 | | { |
| 614 | | c64_io_enabled = 0; |
| 615 | | c64_io_ram_w_ptr = c64_memory + 0xd000; |
| 616 | | if ( !charen && (loram || hiram)) { |
| 617 | | c64_io_ram_r_ptr = c64_chargen; |
| 618 | | } else { |
| 665 | /* 0xa000 */ |
| 666 | if (hiram && !c64_game && !c64_exrom) |
| 667 | memory_set_bankptr (3, romh); |
| 668 | |
| 669 | else if (loram && hiram && c64_game) |
| 670 | memory_set_bankptr (3, c64_basic); |
| 671 | |
| 672 | else |
| 673 | memory_set_bankptr (3, c64_memory + 0xa000); |
| 674 | |
| 675 | /* 0xd000 */ |
| 676 | // RAM |
| 677 | if (!loram && !hiram && (c64_game || !c64_exrom)) |
| 678 | { |
| 679 | c64_io_enabled = 0; |
| 619 | 680 | c64_io_ram_r_ptr = c64_memory + 0xd000; |
| 681 | c64_io_ram_w_ptr = c64_memory + 0xd000; |
| 620 | 682 | } |
| 621 | | // memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xd000, 0xdfff, 0, 0, SMH_BANK5); |
| 622 | | // memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xd000, 0xdfff, 0, 0, SMH_BANK6); |
| 623 | | // memory_set_bankptr (6, c64_memory + 0xd000); |
| 624 | | // if (!charen && (loram || hiram)) |
| 625 | | // { |
| 626 | | // memory_set_bankptr (5, c64_chargen); |
| 627 | | // } |
| 628 | | // else |
| 629 | | // { |
| 630 | | // memory_set_bankptr (5, c64_memory + 0xd000); |
| 631 | | // } |
| 683 | // IO/RAM |
| 684 | else if (loram && !hiram && !c64_game) // remember we cannot be in ultimax_mode, no need of !c64_exrom |
| 685 | { |
| 686 | c64_io_enabled = 0; |
| 687 | c64_io_ram_w_ptr = c64_memory + 0xd000; |
| 688 | c64_io_ram_r_ptr = (!charen) ? c64_chargen : c64_memory + 0xd000; |
| 689 | } |
| 690 | // IO/C |
| 691 | else |
| 692 | { |
| 693 | c64_io_enabled = charen ? 1 : 0; |
| 694 | |
| 695 | if (!charen) |
| 696 | { |
| 697 | c64_io_ram_w_ptr = c64_memory + 0xd000; |
| 698 | c64_io_ram_r_ptr = c64_chargen; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | /* 0xe000-0xf000 */ |
| 703 | memory_set_bankptr (4, hiram ? c64_kernal : c64_memory + 0xe000); |
| 704 | memory_set_bankptr (5, c64_memory + 0xe000); |
| 632 | 705 | } |
| 633 | 706 | |
| 634 | | if (!c64_game && c64_exrom) |
| 635 | | { |
| 636 | | memory_set_bankptr (7, romh); |
| 637 | | memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xe000, 0xffff, 0, 0, SMH_NOP); |
| 638 | | } |
| 639 | | else |
| 640 | | { |
| 641 | | if (hiram) |
| 642 | | memory_set_bankptr (7, c64_kernal); |
| 643 | | else |
| 644 | | memory_set_bankptr (7, c64_memory + 0xe000); |
| 645 | | memory_set_bankptr (8, c64_memory + 0xe000); |
| 646 | | } |
| 647 | 707 | /* make sure the opbase function gets called each time */ |
| 648 | 708 | /* NPW 15-May-2008 - Another hack in the C64 drivers broken! */ |
| 649 | 709 | /* opbase->mem_max = 0xcfff; */ |
| 710 | |
| 650 | 711 | game = c64_game; |
| 651 | 712 | exrom = c64_exrom; |
| 652 | 713 | old = data; |
| r3130 | r3131 | |
| 664 | 725 | p5 output cassette motor |
| 665 | 726 | p6,7 not available on M6510 |
| 666 | 727 | */ |
| 728 | |
| 729 | static emu_timer *datasette_timer; |
| 730 | |
| 667 | 731 | void c64_m6510_port_write(UINT8 direction, UINT8 data) |
| 668 | 732 | { |
| 669 | 733 | /* if line is marked as input then keep current value */ |
| 670 | | data = ( c64_port_data & ~direction ) | ( data & direction ); |
| 734 | data = (c64_port_data & ~direction) | (data & direction); |
| 671 | 735 | |
| 672 | | /* resistor makes cassette sense go high when P4 changes to input */ |
| 673 | | if ( ! ( direction & 0x10 ) ) { |
| 674 | | data |= 0x10; |
| 675 | | } |
| 676 | 736 | /* resistors make P0,P1,P2 go high when respective line is changed to input */ |
| 677 | | if ( ! ( direction & 0x04 ) ) { |
| 737 | if (!(direction & 0x04)) |
| 678 | 738 | data |= 0x04; |
| 679 | | } |
| 680 | | if ( ! ( direction & 0x02 ) ) { |
| 739 | |
| 740 | if (!(direction & 0x02)) |
| 681 | 741 | data |= 0x02; |
| 682 | | } |
| 683 | | if ( ! ( direction & 0x01 ) ) { |
| 742 | |
| 743 | if (!(direction & 0x01)) |
| 684 | 744 | data |= 0x01; |
| 685 | | } |
| 745 | |
| 686 | 746 | c64_port_data = data; |
| 687 | 747 | |
| 688 | 748 | if (c64_tape_on) |
| 689 | 749 | { |
| 690 | | if ( direction & 0x08 ) { |
| 691 | | vc20_tape_write (!(data & 8)); |
| 750 | if (direction & 0x08) |
| 751 | { |
| 752 | /* CASSETTE_RECORD is not implemented yet */ |
| 692 | 753 | } |
| 693 | | if ( direction & 0x20 ) { |
| 694 | | vc20_tape_motor (data & 0x20); |
| 754 | |
| 755 | if (direction & 0x20) |
| 756 | { |
| 757 | if(!(data & 0x20)) |
| 758 | { |
| 759 | cassette_change_state(image_from_devtype_and_index(IO_CASSETTE, 0),CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR); |
| 760 | timer_adjust_periodic(datasette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(44100)); |
| 761 | } |
| 762 | else |
| 763 | { |
| 764 | cassette_change_state(image_from_devtype_and_index(IO_CASSETTE, 0),CASSETTE_MOTOR_DISABLED ,CASSETTE_MASK_MOTOR); |
| 765 | timer_reset(datasette_timer, attotime_never); |
| 766 | } |
| 695 | 767 | } |
| 696 | 768 | } |
| 697 | | if (is_c128(Machine)) |
| 698 | | c128_bankswitch_64 (Machine, 0); |
| 699 | | else if (is_c65(Machine)) |
| 769 | |
| 770 | if (is_c65(Machine)) |
| 700 | 771 | { |
| 701 | 772 | // NPW 8-Feb-2004 - Don't know why I have to do this |
| 702 | 773 | //c65_bankswitch(Machine); |
| 703 | 774 | } |
| 775 | |
| 704 | 776 | else if (!ultimax) |
| 705 | 777 | c64_bankswitch(Machine, 0); |
| 778 | |
| 706 | 779 | c64_memory[0x000] = program_read_byte( 0 ); |
| 707 | 780 | c64_memory[0x001] = program_read_byte( 1 ); |
| 708 | 781 | } |
| r3130 | r3131 | |
| 712 | 785 | running_machine *machine = Machine; |
| 713 | 786 | UINT8 data = c64_port_data; |
| 714 | 787 | |
| 715 | | if (c64_tape_on && !vc20_tape_switch()) |
| 788 | if ((cassette_get_state(image_from_devtype_and_index(IO_CASSETTE, 0)) & CASSETTE_MASK_UISTATE) == CASSETTE_PLAY) |
| 716 | 789 | data &= ~0x10; |
| 717 | | /* WP: motor is always marked as on??? */ |
| 718 | | data &= ~0x20; |
| 719 | | if (is_c128(machine)) { |
| 790 | else |
| 791 | data |= 0x10; |
| 792 | |
| 793 | if (is_c65(machine)) |
| 794 | { |
| 720 | 795 | if (input_port_read(machine, "SPECIAL") & 0x20) /* Check Caps Lock */ |
| 721 | | { |
| 722 | 796 | data &= ~0x40; |
| 723 | | } else { |
| 797 | |
| 798 | else |
| 724 | 799 | data |= 0x40; |
| 725 | | } |
| 726 | 800 | } |
| 727 | | if (is_c65(machine)) { |
| 728 | | if (input_port_read(machine, "SPECIAL") & 0x20) /* Check Caps Lock */ |
| 729 | | { |
| 730 | | data &= ~0x40; |
| 731 | | } else { |
| 732 | | data |= 0x40; |
| 733 | | } |
| 734 | | } |
| 801 | |
| 735 | 802 | return data; |
| 736 | 803 | } |
| 737 | 804 | |
| 805 | |
| 738 | 806 | int c64_paddle_read (int which) |
| 739 | 807 | { |
| 740 | 808 | int pot1=0xff, pot2=0xff, pot3=0xff, pot4=0xff, temp; |
| r3130 | r3131 | |
| 835 | 903 | return c64_colorram[offset & 0x3ff] & 0xf; |
| 836 | 904 | } |
| 837 | 905 | |
| 906 | double last = 0; |
| 907 | |
| 908 | static TIMER_CALLBACK( c64_tape_timer ) |
| 909 | { |
| 910 | double tmp = cassette_input(image_from_devtype_and_index(IO_CASSETTE, 0)); |
| 911 | |
| 912 | if((last > +0.0) && (tmp < +0.0)) |
| 913 | cia_issue_index(machine, 0); |
| 914 | |
| 915 | last = tmp; |
| 916 | } |
| 917 | |
| 838 | 918 | static void c64_common_driver_init (running_machine *machine) |
| 839 | 919 | { |
| 920 | cia6526_interface cia_intf[2]; |
| 921 | |
| 840 | 922 | /* configure the M6510 port */ |
| 841 | 923 | cpunum_set_info_fct(0, CPUINFO_PTR_M6510_PORTREAD, (genf *) c64_m6510_port_read); |
| 842 | 924 | cpunum_set_info_fct(0, CPUINFO_PTR_M6510_PORTWRITE, (genf *) c64_m6510_port_write); |
| 843 | 925 | |
| 844 | | /* memset(c64_memory, 0, 0xfd00); */ |
| 845 | | if (!ultimax) { |
| 926 | if (!ultimax) |
| 927 | { |
| 846 | 928 | UINT8 *mem = memory_region(machine, "main"); |
| 847 | | c64_basic=mem+0x10000; |
| 848 | | c64_kernal=mem+0x12000; |
| 849 | | c64_chargen=mem+0x14000; |
| 850 | | c64_colorram=mem+0x15000; |
| 851 | | c64_roml=mem+0x15400; |
| 852 | | c64_romh=mem+0x17400; |
| 853 | | #if 0 |
| 854 | | {0x10000, 0x11fff, SMH_ROM, &c64_basic}, /* basic at 0xa000 */ |
| 855 | | {0x12000, 0x13fff, SMH_ROM, &c64_kernal}, /* kernal at 0xe000 */ |
| 856 | | {0x14000, 0x14fff, SMH_ROM, &c64_chargen}, /* charrom at 0xd000 */ |
| 857 | | {0x15000, 0x153ff, SMH_RAM, &c64_colorram}, /* colorram at 0xd800 */ |
| 858 | | {0x15400, 0x173ff, SMH_ROM, &c64_roml}, /* basic at 0xa000 */ |
| 859 | | {0x17400, 0x193ff, SMH_ROM, &c64_romh}, /* kernal at 0xe000 */ |
| 860 | | #endif |
| 929 | c64_basic = mem + 0x10000; |
| 930 | c64_kernal = mem + 0x12000; |
| 931 | c64_chargen = mem + 0x14000; |
| 932 | c64_colorram = mem + 0x15000; |
| 933 | c64_roml = mem + 0x15400; |
| 934 | c64_romh = mem + 0x17400; |
| 861 | 935 | } |
| 936 | |
| 862 | 937 | if (c64_tape_on) |
| 863 | | vc20_tape_open (c64_tape_read); |
| 938 | datasette_timer = timer_alloc(c64_tape_timer, NULL); |
| 864 | 939 | |
| 940 | /* CIA initialization */ |
| 941 | cia_intf[0] = c64_cia0; |
| 942 | cia_intf[0].tod_clock = c64_pal ? 50 : 60; |
| 943 | cia_config(machine, 0, &cia_intf[0]); |
| 944 | |
| 945 | if (c64_cia1_on) |
| 865 | 946 | { |
| 866 | | cia6526_interface cia_intf[2]; |
| 867 | | |
| 868 | | cia_intf[0] = c64_cia0; |
| 869 | | cia_intf[0].tod_clock = c64_pal ? 50 : 60; |
| 870 | | cia_config(machine, 0, &cia_intf[0]); |
| 871 | | |
| 872 | | if (c64_cia1_on) |
| 873 | | { |
| 874 | | cia_intf[1] = c64_cia1; |
| 875 | | cia_intf[1].tod_clock = c64_pal ? 50 : 60; |
| 876 | | cia_config(machine, 1, &cia_intf[1]); |
| 877 | | } |
| 947 | cia_intf[1] = c64_cia1; |
| 948 | cia_intf[1].tod_clock = c64_pal ? 50 : 60; |
| 949 | cia_config(machine, 1, &cia_intf[1]); |
| 878 | 950 | } |
| 879 | | |
| 951 | |
| 952 | |
| 880 | 953 | if (ultimax) |
| 881 | | { |
| 882 | | vic6567_init (0, c64_pal, c64_dma_read_ultimax, c64_dma_read_color, |
| 883 | | c64_vic_interrupt); |
| 884 | | } |
| 954 | vic6567_init (0, c64_pal, c64_dma_read_ultimax, c64_dma_read_color, c64_vic_interrupt); |
| 885 | 955 | else |
| 886 | | { |
| 887 | | vic6567_init (0, c64_pal, c64_dma_read, c64_dma_read_color, |
| 888 | | c64_vic_interrupt); |
| 889 | | } |
| 956 | vic6567_init (0, c64_pal, c64_dma_read, c64_dma_read_color, c64_vic_interrupt); |
| 957 | |
| 890 | 958 | cia_reset(); |
| 891 | | add_exit_callback(machine, c64_driver_shutdown); |
| 892 | 959 | } |
| 893 | 960 | |
| 894 | 961 | DRIVER_INIT( c64 ) |
| r3130 | r3131 | |
| 926 | 993 | vc1541_config (0, 0, &vc1541); |
| 927 | 994 | } |
| 928 | 995 | |
| 929 | | static void c64_driver_shutdown (running_machine *machine) |
| 930 | | { |
| 931 | | if (c64_tape_on) |
| 932 | | vc20_tape_close (); |
| 933 | | } |
| 934 | | |
| 935 | 996 | void c64_common_init_machine (running_machine *machine) |
| 936 | 997 | { |
| 937 | 998 | #ifdef VC1541 |
| r3130 | r3131 | |
| 949 | 1010 | vicirq = 0; |
| 950 | 1011 | } |
| 951 | 1012 | |
| 952 | | static OPBASE_HANDLER( c64_opbase ) { |
| 953 | | if ( ( address & 0xf000 ) == 0xd000 ) { |
| 954 | | if ( c64_io_enabled ) { |
| 1013 | static OPBASE_HANDLER( c64_opbase ) |
| 1014 | { |
| 1015 | if ((address & 0xf000) == 0xd000) |
| 1016 | { |
| 1017 | if (c64_io_enabled) |
| 1018 | { |
| 955 | 1019 | opbase->mask = 0x0fff; |
| 956 | 1020 | opbase->ram = c64_io_mirror; |
| 957 | 1021 | opbase->rom = c64_io_mirror; |
| 958 | 1022 | opbase->mem_min = 0x0000; |
| 959 | 1023 | opbase->mem_max = 0xcfff; |
| 960 | 1024 | c64_io_mirror[address & 0x0fff] = c64_read_io( machine, address & 0x0fff ); |
| 961 | | } else { |
| 1025 | } |
| 1026 | else |
| 1027 | { |
| 962 | 1028 | opbase->mask = 0x0fff; |
| 963 | 1029 | opbase->ram = c64_io_ram_r_ptr; |
| 964 | 1030 | opbase->rom = c64_io_ram_r_ptr; |
| r3130 | r3131 | |
| 1210 | 1276 | c65_keyline = value; |
| 1211 | 1277 | } |
| 1212 | 1278 | |
| 1213 | | |
| 1214 | 1279 | vic2_frame_interrupt (machine, cpunum); |
| 1215 | 1280 | |
| 1216 | | if (c64_tape_on) |
| 1217 | | { |
| 1218 | | vc20_tape_config (input_port_read(machine, "CFG") & 0x4000, input_port_read(machine, "DSW0") & 0x2000); /* DATASSETTE, DATASSETTE_TONE */ |
| 1219 | | vc20_tape_buttons (input_port_read(machine, "CFG") & 0x1000, input_port_read(machine, "DSW0") & 0x0800, input_port_read(machine, "DSW0") & 0x0400); /* DATASETTE_PLAY, DATASETTE_RECORD, DATASETTE_STOP */ |
| 1220 | | } |
| 1221 | | |
| 1222 | 1281 | set_led_status (1, input_port_read(machine, "SPECIAL") & 0x40 ? 1 : 0); /*KB_CAPSLOCK_FLAG */ |
| 1223 | 1282 | set_led_status (0, input_port_read(machine, "DSW0") & 0x0100 ? 1 : 0); /*KB_NUMLOCK_FLAG */ |
| 1224 | 1283 | } |
src/mess/drivers/c64.c
| r3130 | r3131 | |
| 193 | 193 | #include "driver.h" |
| 194 | 194 | #include "sound/sid6581.h" |
| 195 | 195 | #include "machine/6526cia.h" |
| 196 | #include "devices/cassette.h" |
| 196 | 197 | |
| 197 | 198 | #define VERBOSE_DBG 0 |
| 198 | 199 | #include "includes/cbm.h" |
| r3130 | r3131 | |
| 200 | 201 | #include "video/vic6567.h" |
| 201 | 202 | #include "includes/cbmserb.h" |
| 202 | 203 | #include "includes/vc1541.h" |
| 203 | | #include "includes/vc20tape.h" |
| 204 | 204 | |
| 205 | 205 | #include "includes/c64.h" |
| 206 | 206 | |
| 207 | |
| 207 | 208 | static ADDRESS_MAP_START(ultimax_mem , ADDRESS_SPACE_PROGRAM, 8) |
| 208 | 209 | AM_RANGE(0x0000, 0x0fff) AM_RAM AM_BASE(&c64_memory) |
| 209 | 210 | AM_RANGE(0x8000, 0x9fff) AM_ROM AM_BASE(&c64_roml) |
| r3130 | r3131 | |
| 211 | 212 | AM_RANGE(0xd400, 0xd7ff) AM_READWRITE(sid6581_0_port_r, sid6581_0_port_w) |
| 212 | 213 | AM_RANGE(0xd800, 0xdbff) AM_READWRITE(SMH_RAM, c64_colorram_write) AM_BASE(&c64_colorram) /* colorram */ |
| 213 | 214 | AM_RANGE(0xdc00, 0xdcff) AM_READWRITE(cia_0_r, cia_0_w) |
| 214 | | AM_RANGE(0xe000, 0xffff) AM_ROM AM_BASE( &c64_romh) /* ram or kernel rom */ |
| 215 | AM_RANGE(0xe000, 0xffff) AM_ROM AM_BASE(&c64_romh) /* ram or kernel rom */ |
| 215 | 216 | ADDRESS_MAP_END |
| 216 | 217 | |
| 217 | 218 | static ADDRESS_MAP_START(c64_mem, ADDRESS_SPACE_PROGRAM, 8) |
| 218 | 219 | AM_RANGE(0x0000, 0x7fff) AM_RAM AM_BASE(&c64_memory) |
| 219 | | AM_RANGE(0x8000, 0x9fff) AM_READWRITE(SMH_BANK1, SMH_BANK2) /* ram or external roml */ |
| 220 | | AM_RANGE(0xa000, 0xbfff) AM_READWRITE(SMH_BANK3, SMH_RAM) /* ram or basic rom or external romh */ |
| 220 | AM_RANGE(0x8000, 0x9fff) AM_READWRITE(SMH_BANK1, SMH_BANK2) /* ram or external roml */ |
| 221 | AM_RANGE(0xa000, 0xbfff) AM_ROMBANK(3) AM_WRITEONLY /* ram or basic rom or external romh */ |
| 221 | 222 | AM_RANGE(0xc000, 0xcfff) AM_RAM |
| 222 | 223 | AM_RANGE(0xd000, 0xdfff) AM_READWRITE(c64_ioarea_r, c64_ioarea_w) |
| 223 | | //#if 1 |
| 224 | | // AM_RANGE(0xd000, 0xdfff) AM_READWRITE(SMH_BANK5, SMH_BANK6) |
| 225 | | //#else |
| 226 | | ///* dram */ |
| 227 | | ///* or character rom */ |
| 228 | | // AM_RANGE(0xd000, 0xd3ff) AM_READWRITE(SMH_BANK9, vic2_port_w) |
| 229 | | // AM_RANGE(0xd400, 0xd7ff) AM_READWRITE(SMH_BANK10, sid6581_0_port_w) |
| 230 | | // AM_RANGE(0xd800, 0xdbff) AM_READWRITE(SMH_BANK11, c64_colorram_write) /* colorram */ |
| 231 | | // AM_RANGE(0xdc00, 0xdcff) AM_READWRITE(SMH_BANK12, cia_0_w) |
| 232 | | // AM_RANGE(0xdd00, 0xddff) AM_READWRITE(SMH_BANK13, cia_1_w) |
| 233 | | // AM_RANGE(0xde00, 0xdeff) AM_READ(SMH_BANK14) /* csline expansion port */ |
| 234 | | // AM_RANGE(0xdf00, 0xdfff) AM_READ(SMH_BANK15) /* csline expansion port */ |
| 235 | | //#endif |
| 236 | | AM_RANGE(0xe000, 0xffff) AM_READWRITE(SMH_BANK7, SMH_BANK8) /* ram or kernel rom or external romh */ |
| 224 | AM_RANGE(0xe000, 0xffff) AM_READWRITE(SMH_BANK4, SMH_BANK5) /* ram or kernel rom or external romh */ |
| 237 | 225 | ADDRESS_MAP_END |
| 238 | 226 | |
| 239 | 227 | |
| r3130 | r3131 | |
| 593 | 581 | } |
| 594 | 582 | } |
| 595 | 583 | |
| 596 | | static SYSTEM_CONFIG_START(c64) |
| 597 | | CONFIG_DEVICE(c64_cbmcartslot_getinfo) |
| 598 | | CONFIG_DEVICE(cbmfloppy_device_getinfo) |
| 599 | | CONFIG_DEVICE(vc20tape_device_getinfo) |
| 600 | | SYSTEM_CONFIG_END |
| 601 | | |
| 602 | | static SYSTEM_CONFIG_START(sx64) |
| 603 | | CONFIG_DEVICE(c64_cbmcartslot_getinfo) |
| 604 | | CONFIG_DEVICE(vc1541_device_getinfo) |
| 605 | | SYSTEM_CONFIG_END |
| 606 | | |
| 607 | 584 | static void ultimax_cbmcartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 608 | 585 | { |
| 609 | 586 | switch(state) |
| r3130 | r3131 | |
| 618 | 595 | } |
| 619 | 596 | } |
| 620 | 597 | |
| 598 | static void datasette_device_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 599 | { |
| 600 | /* cassette */ |
| 601 | switch(state) |
| 602 | { |
| 603 | case MESS_DEVINFO_INT_COUNT: info->i = 1; break; |
| 604 | |
| 605 | case MESS_DEVINFO_INT_CASSETTE_DEFAULT_STATE: info->i = CASSETTE_STOPPED | CASSETTE_MOTOR_DISABLED | CASSETTE_SPEAKER_ENABLED; break; |
| 606 | |
| 607 | default: cassette_device_getinfo( devclass, state, info ); break; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | static SYSTEM_CONFIG_START(c64) |
| 612 | CONFIG_DEVICE(c64_cbmcartslot_getinfo) |
| 613 | CONFIG_DEVICE(cbmfloppy_device_getinfo) |
| 614 | CONFIG_DEVICE(datasette_device_getinfo) |
| 615 | SYSTEM_CONFIG_END |
| 616 | |
| 617 | static SYSTEM_CONFIG_START(sx64) |
| 618 | CONFIG_DEVICE(c64_cbmcartslot_getinfo) |
| 619 | CONFIG_DEVICE(vc1541_device_getinfo) |
| 620 | SYSTEM_CONFIG_END |
| 621 | |
| 621 | 622 | static SYSTEM_CONFIG_START(ultimax) |
| 622 | 623 | CONFIG_DEVICE(ultimax_cbmcartslot_getinfo) |
| 623 | | CONFIG_DEVICE(vc20tape_device_getinfo) |
| 624 | CONFIG_DEVICE(datasette_device_getinfo) |
| 624 | 625 | SYSTEM_CONFIG_END |
| 625 | 626 | |
| 626 | 627 | static SYSTEM_CONFIG_START(c64gs) |
| r3130 | r3131 | |
| 634 | 635 | ***************************************************************************/ |
| 635 | 636 | |
| 636 | 637 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ |
| 637 | | COMP(1982, max, 0, 0, ultimax, ultimax,ultimax,ultimax, "Commodore Business Machines Co.", "Commodore Max (Ultimax/VC10)", 0) |
| 638 | 638 | COMP(1982, c64, 0, 0, c64, c64, c64, c64, "Commodore Business Machines Co.", "Commodore 64 (NTSC)", 0) |
| 639 | COMP(1982, c64pal, c64, 0, c64pal, c64, c64pal, c64, "Commodore Business Machines Co.", "Commodore 64/VC64/VIC64 (PAL)", 0) |
| 639 | 640 | COMP(1982, cbm4064, c64, 0, pet64, c64, c64, c64, "Commodore Business Machines Co.", "CBM4064/PET64/Educator64 (NTSC)", 0) |
| 640 | | COMP(1982, c64pal, c64, 0, c64pal, c64, c64pal, c64, "Commodore Business Machines Co.", "Commodore 64/VC64/VIC64 (PAL)", 0) |
| 641 | 641 | COMP(1982, vic64s, c64, 0, c64pal, vic64s, c64pal, c64, "Commodore Business Machines Co.", "Commodore 64 Swedish (PAL)", 0) |
| 642 | COMP(1982, max, 0, 0, ultimax, ultimax,ultimax,ultimax, "Commodore Business Machines Co.", "Commodore Max (Ultimax/VC10)", 0) |
| 642 | 643 | CONS(1987, c64gs, c64, 0, c64gs, c64gs, c64gs, c64gs, "Commodore Business Machines Co.", "C64GS (PAL)", 0) |
| 643 | 644 | |
| 644 | 645 | /* testdrivers */ |