src/mess/machine/c64.c
| r4345 | r4346 | |
| 12 | 12 | (program write some short test code into the vic sprite register) |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | | /* |
| 15 | /* |
| 16 | 16 | 2008-09-06: Tape status for C64 & C128 [FP & RZ] |
| 17 | 17 | - tape loading works |
| 18 | 18 | - tap files are supported |
| r4345 | r4346 | |
| 126 | 126 | cpu_set_input_line(machine->cpu[1], INPUT_LINE_NMI, (input_port_read(machine, "SPECIAL") & 0x80) || cia1irq); |
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | | |
| 129 | |
| 130 | 130 | else |
| 131 | 131 | { |
| 132 | 132 | cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, (input_port_read(machine, "SPECIAL") & 0x80) || cia1irq); |
| 133 | 133 | } |
| 134 | | |
| 134 | |
| 135 | 135 | nmilevel = (input_port_read(machine, "SPECIAL") & 0x80) || cia1irq; |
| 136 | 136 | } |
| 137 | 137 | } |
| r4345 | r4346 | |
| 294 | 294 | |
| 295 | 295 | if ( input_port_read(device->machine, "CTRLSEL") & 0x80 ) |
| 296 | 296 | value &= c64_keyline[9]; |
| 297 | | else |
| 297 | else |
| 298 | 298 | value &= c64_keyline[8]; |
| 299 | 299 | |
| 300 | 300 | if (is_c128(device->machine)) |
| r4345 | r4346 | |
| 421 | 421 | const cia6526_interface c64_ntsc_cia0 = |
| 422 | 422 | { |
| 423 | 423 | DEVCB_LINE(c64_cia0_interrupt), |
| 424 | DEVCB_NULL, /* pc_func */ |
| 424 | 425 | 60, |
| 425 | 426 | |
| 426 | 427 | { |
| r4345 | r4346 | |
| 432 | 433 | const cia6526_interface c64_pal_cia0 = |
| 433 | 434 | { |
| 434 | 435 | DEVCB_LINE(c64_cia0_interrupt), |
| 436 | DEVCB_NULL, /* pc_func */ |
| 435 | 437 | 50, |
| 436 | 438 | |
| 437 | 439 | { |
| r4345 | r4346 | |
| 443 | 445 | const cia6526_interface c64_ntsc_cia1 = |
| 444 | 446 | { |
| 445 | 447 | DEVCB_LINE(c64_cia1_interrupt), |
| 448 | DEVCB_NULL, /* pc_func */ |
| 446 | 449 | 60, |
| 447 | 450 | |
| 448 | 451 | { |
| r4345 | r4346 | |
| 454 | 457 | const cia6526_interface c64_pal_cia1 = |
| 455 | 458 | { |
| 456 | 459 | DEVCB_LINE(c64_cia1_interrupt), |
| 460 | DEVCB_NULL, /* pc_func */ |
| 457 | 461 | 50, |
| 458 | 462 | |
| 459 | 463 | { |
| r4345 | r4346 | |
| 502 | 506 | |
| 503 | 507 | WRITE8_HANDLER(c64_ioarea_w) |
| 504 | 508 | { |
| 505 | | if (c64_io_enabled) |
| 509 | if (c64_io_enabled) |
| 506 | 510 | { |
| 507 | 511 | c64_write_io(space, offset, data); |
| 508 | | } |
| 509 | | else |
| 512 | } |
| 513 | else |
| 510 | 514 | { |
| 511 | 515 | c64_io_ram_w_ptr[offset] = data; |
| 512 | 516 | } |
| r4345 | r4346 | |
| 584 | 588 | ---------------------------------------------------------------------- |
| 585 | 589 | C000 RAM RAM RAM RAM RAM RAM RAM RAM - |
| 586 | 590 | ---------------------------------------------------------------------- |
| 587 | | B000 |
| 591 | B000 |
| 588 | 592 | BASIC RAM RAM RAM RAM BASIC ROMH ROMH - |
| 589 | | A000 |
| 593 | A000 |
| 590 | 594 | ---------------------------------------------------------------------- |
| 591 | | 9000 |
| 595 | 9000 |
| 592 | 596 | RAM RAM RAM RAM RAM ROML RAM ROML ROML(* |
| 593 | | 8000 |
| 597 | 8000 |
| 594 | 598 | ---------------------------------------------------------------------- |
| 595 | | 7000 |
| 596 | | |
| 597 | | 6000 |
| 599 | 7000 |
| 600 | |
| 601 | 6000 |
| 598 | 602 | RAM RAM RAM RAM RAM RAM RAM RAM - |
| 599 | | 5000 |
| 600 | | |
| 601 | | 4000 |
| 603 | 5000 |
| 604 | |
| 605 | 4000 |
| 602 | 606 | ---------------------------------------------------------------------- |
| 603 | | 3000 |
| 604 | | |
| 607 | 3000 |
| 608 | |
| 605 | 609 | 2000 RAM RAM RAM RAM RAM RAM RAM RAM - |
| 606 | | |
| 607 | | 1000 |
| 610 | |
| 611 | 1000 |
| 608 | 612 | ---------------------------------------------------------------------- |
| 609 | 613 | 0000 RAM RAM RAM RAM RAM RAM RAM RAM RAM |
| 610 | 614 | ---------------------------------------------------------------------- |
| r4345 | r4346 | |
| 643 | 647 | |
| 644 | 648 | RAM various ranges Commodore 64's internal RAM. |
| 645 | 649 | |
| 646 | | - 1000-7FFF and Open address space. |
| 650 | - 1000-7FFF and Open address space. |
| 647 | 651 | A000-CFFF The Commodore 64's memory chips |
| 648 | 652 | do not detect any memory accesses |
| 649 | 653 | to this area except the VIC-II's |
| r4345 | r4346 | |
| 678 | 682 | int data = (UINT8) device_get_info_int(machine->cpu[0], CPUINFO_INT_M6510_PORT) & 0x07; |
| 679 | 683 | |
| 680 | 684 | /* If nothing has changed or reset = 0, don't do anything */ |
| 681 | | if ((data == old) && (exrom == c64_exrom) && (game == c64_game) && !reset) |
| 685 | if ((data == old) && (exrom == c64_exrom) && (game == c64_game) && !reset) |
| 682 | 686 | return; |
| 683 | 687 | |
| 684 | 688 | /* Are we in Ultimax mode? */ |
| r4345 | r4346 | |
| 788 | 792 | data = (c64_port_data & ~direction) | (data & direction); |
| 789 | 793 | |
| 790 | 794 | /* resistors make P0,P1,P2 go high when respective line is changed to input */ |
| 791 | | if (!(direction & 0x04)) |
| 795 | if (!(direction & 0x04)) |
| 792 | 796 | data |= 0x04; |
| 793 | 797 | |
| 794 | 798 | if (!(direction & 0x02)) |
| r4345 | r4346 | |
| 801 | 805 | |
| 802 | 806 | if (c64_tape_on) |
| 803 | 807 | { |
| 804 | | if (direction & 0x08) |
| 808 | if (direction & 0x08) |
| 805 | 809 | { |
| 806 | 810 | cassette_output(devtag_get_device(device->machine, CASSETTE, "cassette"), (data & 0x08) ? -(0x5a9e >> 1) : +(0x5a9e >> 1)); |
| 807 | 811 | } |
| r4345 | r4346 | |
| 846 | 850 | data |= 0x10; |
| 847 | 851 | } |
| 848 | 852 | |
| 849 | | if (is_c65(device->machine)) |
| 853 | if (is_c65(device->machine)) |
| 850 | 854 | { |
| 851 | 855 | if (input_port_read(device->machine, "SPECIAL") & 0x20) /* Check Caps Lock */ |
| 852 | 856 | data &= ~0x40; |
| 853 | 857 | |
| 854 | | else |
| 858 | else |
| 855 | 859 | data |= 0x40; |
| 856 | 860 | } |
| 857 | 861 | |
| r4345 | r4346 | |
| 948 | 952 | temp = pot3; pot3 = pot4; pot4 = temp; |
| 949 | 953 | } |
| 950 | 954 | |
| 951 | | switch (cia0porta & 0xc0) |
| 955 | switch (cia0porta & 0xc0) |
| 952 | 956 | { |
| 953 | 957 | case 0x40: |
| 954 | 958 | return which ? pot2 : pot1; |
| r4345 | r4346 | |
| 1024 | 1028 | device_set_info_fct(machine->cpu[0], CPUINFO_FCT_M6510_PORTREAD, (genf *) c64_m6510_port_read); |
| 1025 | 1029 | device_set_info_fct(machine->cpu[0], CPUINFO_FCT_M6510_PORTWRITE, (genf *) c64_m6510_port_write); |
| 1026 | 1030 | |
| 1027 | | if (!ultimax) |
| 1031 | if (!ultimax) |
| 1028 | 1032 | { |
| 1029 | 1033 | UINT8 *mem = memory_region(machine, "main"); |
| 1030 | 1034 | c64_basic = mem + 0x10000; |
| r4345 | r4346 | |
| 1171 | 1175 | |
| 1172 | 1176 | /* Shift Lock is mapped on Left Shift */ |
| 1173 | 1177 | if ((i == 1) && (input_port_read(device->machine, "SPECIAL") & 0x40) && !is_c128(device->machine)) // Fix Me! Currently, neither left Shift nor Shift Lock works in c128, but reading this in c128 produces a bug! |
| 1174 | | value &= ~0x80; |
| 1178 | value &= ~0x80; |
| 1175 | 1179 | |
| 1176 | 1180 | c64_keyline[i] = value; |
| 1177 | 1181 | } |
| r4345 | r4346 | |
| 1183 | 1187 | case 0x00: |
| 1184 | 1188 | value &= ~input_port_read(device->machine, "JOY1_1B"); /* Joy1 Directions + Button 1 */ |
| 1185 | 1189 | break; |
| 1186 | | |
| 1190 | |
| 1187 | 1191 | case 0x01: |
| 1188 | 1192 | if (input_port_read(device->machine, "OTHER") & 0x40) /* Paddle2 Button */ |
| 1189 | 1193 | value &= ~0x08; |
| r4345 | r4346 | |
| 1197 | 1201 | if (input_port_read(device->machine, "OTHER") & 0x01) /* Mouse Button Right */ |
| 1198 | 1202 | value &= ~0x01; |
| 1199 | 1203 | break; |
| 1200 | | |
| 1204 | |
| 1201 | 1205 | case 0x03: |
| 1202 | 1206 | value &= ~(input_port_read(device->machine, "JOY1_2B") & 0x1f); /* Joy1 Directions + Button 1 */ |
| 1203 | 1207 | break; |
| 1204 | | |
| 1208 | |
| 1205 | 1209 | case 0x04: |
| 1206 | 1210 | /* was there any input on the lightpen? where is it mapped? */ |
| 1207 | 1211 | // if (input_port_read(device->machine, "OTHER") & 0x04) /* Lightpen Signal */ |
| r4345 | r4346 | |
| 1225 | 1229 | case 0x00: |
| 1226 | 1230 | value &= ~input_port_read(device->machine, "JOY2_1B"); /* Joy2 Directions + Button 1 */ |
| 1227 | 1231 | break; |
| 1228 | | |
| 1232 | |
| 1229 | 1233 | case 0x10: |
| 1230 | 1234 | if (input_port_read(device->machine, "OTHER") & 0x10) /* Paddle4 Button */ |
| 1231 | 1235 | value &= ~0x08; |
| r4345 | r4346 | |
| 1239 | 1243 | if (input_port_read(device->machine, "OTHER") & 0x01) /* Mouse Button Right */ |
| 1240 | 1244 | value &= ~0x01; |
| 1241 | 1245 | break; |
| 1242 | | |
| 1246 | |
| 1243 | 1247 | case 0x30: |
| 1244 | 1248 | value &= ~(input_port_read(device->machine, "JOY2_2B") & 0x1f); /* Joy2 Directions + Button 1 */ |
| 1245 | 1249 | break; |
| r4345 | r4346 | |
| 1261 | 1265 | c64_keyline[9] = value; |
| 1262 | 1266 | |
| 1263 | 1267 | /* C128 only : keypad input ports */ |
| 1264 | | if (is_c128(device->machine)) |
| 1268 | if (is_c128(device->machine)) |
| 1265 | 1269 | { |
| 1266 | 1270 | for (i = 0; i < 3; i++) |
| 1267 | 1271 | { |
| r4345 | r4346 | |
| 1272 | 1276 | } |
| 1273 | 1277 | |
| 1274 | 1278 | /* C65 only : function keys input ports */ |
| 1275 | | if (is_c65(device->machine)) |
| 1279 | if (is_c65(device->machine)) |
| 1276 | 1280 | { |
| 1277 | 1281 | value = 0xff; |
| 1278 | 1282 | |
| r4345 | r4346 | |
| 1287 | 1291 | timer_set(device->machine, attotime_zero, NULL, 0, lightpen_tick); |
| 1288 | 1292 | |
| 1289 | 1293 | set_led_status (1, input_port_read(device->machine, "SPECIAL") & 0x40 ? 1 : 0); /* Shift Lock */ |
| 1290 | | set_led_status (0, input_port_read(device->machine, "CTRLSEL") & 0x80 ? 1 : 0); /* Joystick Swap */ |
| 1294 | set_led_status (0, input_port_read(device->machine, "CTRLSEL") & 0x80 ? 1 : 0); /* Joystick Swap */ |
| 1291 | 1295 | } |
| 1292 | 1296 | |
| 1293 | 1297 | |
| r4345 | r4346 | |
| 1298 | 1302 | ***********************************************/ |
| 1299 | 1303 | |
| 1300 | 1304 | /* Info based on http://ist.uwaterloo.ca/~schepers/formats/CRT.TXT */ |
| 1301 | | /* Please refer to the webpage for the latest version and for a very |
| 1305 | /* Please refer to the webpage for the latest version and for a very |
| 1302 | 1306 | complete listing of various cart types and their bankswitch tricks */ |
| 1303 | 1307 | /* |
| 1304 | 1308 | Cartridge files were introduced in the CCS64 emulator, written by Per |
| r4345 | r4346 | |
| 1323 | 1327 | $0040-EOF : Blocks of data |
| 1324 | 1328 | |
| 1325 | 1329 | Each block of data, called 'CHIP', can be of variable size. The first |
| 1326 | | 0x10 bytes of each CHIP block is the block header, and it contains various |
| 1327 | | informations on the block itself, as its size (both with and without the |
| 1330 | 0x10 bytes of each CHIP block is the block header, and it contains various |
| 1331 | informations on the block itself, as its size (both with and without the |
| 1328 | 1332 | header), the loading address and an index to identify which memory bank |
| 1329 | 1333 | the data must be loaded to. FP ] |
| 1330 | 1334 | |
| r4345 | r4346 | |
| 1441 | 1445 | REAL_FC_I, /* 29 - (3) */ |
| 1442 | 1446 | ACTION_REPLAY_4, /* 30 - Action Replay 4 */ |
| 1443 | 1447 | STARDOS, /* 31 - StarDOS */ |
| 1444 | | /* |
| 1445 | | (1) Ocean type 1 includes Navy Seals, Robocop 2 & 3, Shadow of |
| 1448 | /* |
| 1449 | (1) Ocean type 1 includes Navy Seals, Robocop 2 & 3, Shadow of |
| 1446 | 1450 | the Beast, Toki, Terminator 2 and more. Both 256 and 128 Kb images. |
| 1447 | 1451 | (2) Dinamic includes Narco Police and more. |
| 1448 | | (3) Type 29 is reserved for the real Final Cartridge I, the one |
| 1452 | (3) Type 29 is reserved for the real Final Cartridge I, the one |
| 1449 | 1453 | above (Type 13) will become Final Cartridge II. */ |
| 1450 | 1454 | /**************************************** |
| 1451 | | Vice also defines the following types: |
| 1455 | Vice also defines the following types: |
| 1452 | 1456 | #define CARTRIDGE_ACTION_REPLAY3 -29 |
| 1453 | 1457 | #define CARTRIDGE_IEEE488 -11 |
| 1454 | 1458 | #define CARTRIDGE_IDE64 -7 |
| 1455 | 1459 | #define CARTRIDGE_RETRO_REPLAY -5 |
| 1456 | 1460 | #define CARTRIDGE_SUPER_SNAPSHOT -4 |
| 1457 | 1461 | |
| 1458 | | Can we support these as well? |
| 1462 | Can we support these as well? |
| 1459 | 1463 | *****************************************/ |
| 1460 | 1464 | }; |
| 1461 | 1465 | |
| r4345 | r4346 | |
| 1512 | 1516 | |
| 1513 | 1517 | |
| 1514 | 1518 | /* Data in a .crt image are organized in blocks called 'CHIP': |
| 1515 | | each 'CHIP' consists of a 0x10 header, which contains the |
| 1516 | | actual size of the block, the loading address and info on |
| 1519 | each 'CHIP' consists of a 0x10 header, which contains the |
| 1520 | actual size of the block, the loading address and info on |
| 1517 | 1521 | the bankswitch, followed by the actual data */ |
| 1518 | 1522 | while (j < size) |
| 1519 | 1523 | { |
| 1520 | 1524 | unsigned short chip_size, chip_bank_index, chip_data_size; |
| 1521 | 1525 | unsigned char buffer[10]; |
| 1522 | | |
| 1526 | |
| 1523 | 1527 | /* Start to parse the CHIP header */ |
| 1524 | 1528 | /* First 4 bytes are the string 'CHIP' */ |
| 1525 | 1529 | image_fread(image, buffer, 6); |
| r4345 | r4346 | |
| 1531 | 1535 | /* 0x08-0x09 chip type (ROM, RAM + no ROM, Flash ROM) */ |
| 1532 | 1536 | image_fread(image, buffer + 6, 2); |
| 1533 | 1537 | |
| 1534 | | /* 0x0a-0x0b is the bank number of the CHIP block */ |
| 1538 | /* 0x0a-0x0b is the bank number of the CHIP block */ |
| 1535 | 1539 | /* We currently don't use this, but it is needed to support more cart types. */ |
| 1536 | 1540 | image_fread(image, &chip_bank_index, 2); |
| 1537 | 1541 | chip_bank_index = BIG_ENDIANIZE_INT16(chip_bank_index); |
| 1538 | 1542 | |
| 1539 | | /* 0x0c-0x0d is the loading address of the CHIP block */ |
| 1543 | /* 0x0c-0x0d is the loading address of the CHIP block */ |
| 1540 | 1544 | image_fread(image, &address, 2); |
| 1541 | 1545 | address = BIG_ENDIANIZE_INT16(address); |
| 1542 | 1546 | |
| 1543 | | /* 0x0e-0x0f is the data size of the CHIP block (without header) */ |
| 1547 | /* 0x0e-0x0f is the data size of the CHIP block (without header) */ |
| 1544 | 1548 | image_fread(image, &chip_data_size, 2); |
| 1545 | 1549 | chip_data_size = BIG_ENDIANIZE_INT16(chip_data_size); |
| 1546 | 1550 | |
| r4345 | r4346 | |
| 1571 | 1575 | } |
| 1572 | 1576 | |
| 1573 | 1577 | /* We also support .80 files for c64 & .e0/.f0 for max */ |
| 1574 | | else |
| 1578 | else |
| 1575 | 1579 | { |
| 1576 | 1580 | /* Assign loading address according to extension */ |
| 1577 | 1581 | if (!mame_stricmp (filetype, "80")) |
| r4345 | r4346 | |
| 1600 | 1604 | } |
| 1601 | 1605 | |
| 1602 | 1606 | /* If we load a .crt file, use EXROM & GAME from the header! */ |
| 1603 | | if ((cbm_c64_exrom != -1) && (cbm_c64_game != -1)) |
| 1607 | if ((cbm_c64_exrom != -1) && (cbm_c64_game != -1)) |
| 1604 | 1608 | { |
| 1605 | 1609 | c64_exrom = cbm_c64_exrom; |
| 1606 | 1610 | c64_game = cbm_c64_game; |
| r4345 | r4346 | |
| 1613 | 1617 | memset(roml, 0, 0x2000); |
| 1614 | 1618 | memset(romh, 0, 0x2000); |
| 1615 | 1619 | |
| 1616 | | for (i=0; (i < sizeof(c64_cbm_cart) / sizeof(c64_cbm_cart[0])) && (c64_cbm_cart[i].size != 0); i++) |
| 1620 | for (i=0; (i < sizeof(c64_cbm_cart) / sizeof(c64_cbm_cart[0])) && (c64_cbm_cart[i].size != 0); i++) |
| 1617 | 1621 | { |
| 1618 | | if (c64_cbm_cart[i].addr < 0xc000) |
| 1622 | if (c64_cbm_cart[i].addr < 0xc000) |
| 1619 | 1623 | memcpy(roml + c64_cbm_cart[i].addr - 0x8000, c64_cbm_cart[i].chip, c64_cbm_cart[i].size); |
| 1620 | 1624 | |
| 1621 | | else |
| 1625 | else |
| 1622 | 1626 | memcpy(romh + c64_cbm_cart[i].addr - 0xe000, c64_cbm_cart[i].chip, c64_cbm_cart[i].size); |
| 1623 | 1627 | } |
| 1624 | 1628 | |