src/mess/machine/c64.c
| r5521 | r5522 | |
| 46 | 46 | #define log_cart 0 |
| 47 | 47 | |
| 48 | 48 | /* expansion port lines input */ |
| 49 | | int c64_pal = 0; |
| 49 | int c64_pal; |
| 50 | 50 | UINT8 c64_game = 1, c64_exrom = 1; |
| 51 | 51 | |
| 52 | 52 | /* cpu port */ |
| r5521 | r5522 | |
| 68 | 68 | static int c64_cia1_on; |
| 69 | 69 | static int c64_io_enabled = 0; |
| 70 | 70 | static int is_sx64; // temporary workaround until we implement full vc1541 emulation for every c64 set |
| 71 | | static UINT8 c64_cart_loaded = 0; |
| 71 | static UINT8 c64_cart_n_banks = 0; |
| 72 | 72 | |
| 73 | 73 | static UINT8 serial_clock, serial_data, serial_atn; |
| 74 | 74 | static UINT8 vicirq = 0; |
| r5521 | r5522 | |
| 1028 | 1028 | |
| 1029 | 1029 | /* Hardware Types for C64 carts */ |
| 1030 | 1030 | enum { |
| 1031 | | GENERIC_CRT = 0, /* 00 - Normal cartridge */ |
| 1031 | GENERIC_CRT = 0, /* 00 - Normal cartridge */ |
| 1032 | 1032 | ACTION_REPLAY, /* 01 - Action Replay */ |
| 1033 | | KCS_PC, /* 02 - KCS Power Cartridge */ |
| 1033 | KCS_PC, /* 02 - KCS Power Cartridge */ |
| 1034 | 1034 | FINAL_CART_III, /* 03 - Final Cartridge III */ |
| 1035 | 1035 | SIMONS_BASIC, /* 04 - Simons Basic */ |
| 1036 | 1036 | OCEAN_1, /* 05 - Ocean type 1 (1) */ |
| 1037 | | EXPERT, /* 06 - Expert Cartridge */ |
| 1038 | | FUN_PLAY, /* 07 - Fun Play, Power Play */ |
| 1039 | | SUPER_GAMES, /* 08 - Super Games */ |
| 1037 | EXPERT, /* 06 - Expert Cartridge */ |
| 1038 | FUN_PLAY, /* 07 - Fun Play, Power Play */ |
| 1039 | SUPER_GAMES, /* 08 - Super Games */ |
| 1040 | 1040 | ATOMIC_POWER, /* 09 - Atomic Power */ |
| 1041 | 1041 | EPYX_FASTLOAD, /* 10 - Epyx Fastload */ |
| 1042 | 1042 | WESTERMANN, /* 11 - Westermann Learning */ |
| 1043 | | REX, /* 12 - Rex Utility */ |
| 1043 | REX, /* 12 - Rex Utility */ |
| 1044 | 1044 | FINAL_CART_I, /* 13 - Final Cartridge I */ |
| 1045 | 1045 | MAGIC_FORMEL, /* 14 - Magic Formel */ |
| 1046 | | C64GS, /* 15 - C64 Game System, System 3 */ |
| 1046 | C64GS, /* 15 - C64 Game System, System 3 */ |
| 1047 | 1047 | WARPSPEED, /* 16 - WarpSpeed */ |
| 1048 | | DINAMIC, /* 17 - Dinamic (2) */ |
| 1049 | | ZAXXON, /* 18 - Zaxxon, Super Zaxxon (SEGA) */ |
| 1050 | | DOMARK, /* 19 - Magic Desk, Domark, HES Australia */ |
| 1048 | DINAMIC, /* 17 - Dinamic (2) */ |
| 1049 | ZAXXON, /* 18 - Zaxxon, Super Zaxxon (SEGA) */ |
| 1050 | DOMARK, /* 19 - Magic Desk, Domark, HES Australia */ |
| 1051 | 1051 | SUPER_SNAP_5, /* 20 - Super Snapshot 5 */ |
| 1052 | 1052 | COMAL_80, /* 21 - Comal-80 */ |
| 1053 | 1053 | STRUCT_BASIC, /* 22 - Structured Basic */ |
| 1054 | | ROSS, /* 23 - Ross */ |
| 1054 | ROSS, /* 23 - Ross */ |
| 1055 | 1055 | DELA_EP64, /* 24 - Dela EP64 */ |
| 1056 | | DELA_EP7X8, /* 25 - Dela EP7x8 */ |
| 1057 | | DELA_EP256, /* 26 - Dela EP256 */ |
| 1056 | DELA_EP7X8, /* 25 - Dela EP7x8 */ |
| 1057 | DELA_EP256, /* 26 - Dela EP256 */ |
| 1058 | 1058 | REX_EP256, /* 27 - Rex EP256 */ |
| 1059 | 1059 | MIKRO_ASSMBLR, /* 28 - Mikro Assembler */ |
| 1060 | | REAL_FC_I, /* 29 - (3) */ |
| 1061 | | ACTION_REPLAY_4, /* 30 - Action Replay 4 */ |
| 1062 | | STARDOS, /* 31 - StarDOS */ |
| 1060 | REAL_FC_I, /* 29 - (3) */ |
| 1061 | ACTION_REPLAY_4, /* 30 - Action Replay 4 */ |
| 1062 | STARDOS, /* 31 - StarDOS */ |
| 1063 | 1063 | /* |
| 1064 | 1064 | (1) Ocean type 1 includes Navy Seals, Robocop 2 & 3, Shadow of |
| 1065 | 1065 | the Beast, Toki, Terminator 2 and more. Both 256 and 128 Kb images. |
| r5521 | r5522 | |
| 1082 | 1082 | |
| 1083 | 1083 | static DEVICE_IMAGE_LOAD(c64_cart) |
| 1084 | 1084 | { |
| 1085 | | int size = image_length(image), test, i = 0; |
| 1085 | int size = image_length(image), test, i = 0, n_banks; |
| 1086 | 1086 | const char *filetype; |
| 1087 | | int address = 0, lbank_end_addr = 0, hbank_end_addr = 0, new_start = 0; |
| 1087 | int address = 0, new_start = 0; |
| 1088 | // int lbank_end_addr = 0, hbank_end_addr = 0; |
| 1088 | 1089 | UINT8 *cart = memory_region(image->machine, "cart"); |
| 1089 | 1090 | |
| 1090 | 1091 | filetype = image_filetype(image); |
| r5521 | r5522 | |
| 1112 | 1113 | switch (c64_cart_type) |
| 1113 | 1114 | { |
| 1114 | 1115 | case GENERIC_CRT: |
| 1116 | printf("Currently supported cart type (Type %d)\n", c64_cart_type); |
| 1115 | 1117 | break; |
| 1116 | 1118 | |
| 1117 | 1119 | default: |
| 1118 | | logerror("Currently unsupported cart type (Type %d)\n", c64_cart_type); |
| 1120 | printf("Currently unsupported cart type (Type %d)\n", c64_cart_type); |
| 1119 | 1121 | break; |
| 1120 | 1122 | } |
| 1121 | 1123 | |
| r5521 | r5522 | |
| 1197 | 1199 | j += chip_size; |
| 1198 | 1200 | } |
| 1199 | 1201 | } |
| 1200 | | |
| 1201 | | /* We also support .80 files for c64 & .e0/.f0 for max */ |
| 1202 | | else |
| 1202 | else /* We also support .80 files for c64 & .e0/.f0 for max */ |
| 1203 | 1203 | { |
| 1204 | 1204 | /* Assign loading address according to extension */ |
| 1205 | 1205 | if (!mame_stricmp (filetype, "80")) |
| r5521 | r5522 | |
| 1232 | 1232 | return INIT_FAIL; |
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | n_banks = i; |
| 1236 | |
| 1235 | 1237 | /* If we load a .crt file, use EXROM & GAME from the header! */ |
| 1236 | 1238 | if ((cbm_c64_exrom != -1) && (cbm_c64_game != -1)) |
| 1237 | 1239 | { |
| r5521 | r5522 | |
| 1244 | 1246 | roml = c64_roml; |
| 1245 | 1247 | romh = c64_romh; |
| 1246 | 1248 | |
| 1247 | | memset(roml, 0, 0x4000); |
| 1249 | memset(roml, 0, 0x2000); |
| 1248 | 1250 | memset(romh, 0, 0x2000); |
| 1249 | 1251 | |
| 1250 | 1252 | /* a bit hacky, until we have fixed the bankswitch part... it will be improved afterwards! */ |
| r5521 | r5522 | |
| 1252 | 1254 | /* now we have bankswitch handlers for some cart types, but we keep loading first 1 or 2 banks here, for carts without bankswitch */ |
| 1253 | 1255 | /* to be sure we only load the first pieces, we check that cart.addr is larger than the previous and that no more than 2 CHIPs are loaded */ |
| 1254 | 1256 | for (i = 0; (i < sizeof(c64_cbm_cart) / sizeof(c64_cbm_cart[0])) && (c64_cbm_cart[i].size != 0); i++) |
| 1257 | /* |
| 1255 | 1258 | { |
| 1256 | | /* load the bank only if the space is free */ |
| 1259 | // load the bank only if the space is free |
| 1257 | 1260 | if ((c64_cbm_cart[i].addr < 0xc000) && (c64_cbm_cart[i].addr >= lbank_end_addr + 0x8000) && (i < 2)) |
| 1258 | 1261 | { |
| 1259 | 1262 | memcpy(roml + c64_cbm_cart[i].addr - 0x8000, cart + c64_cbm_cart[i].start, c64_cbm_cart[i].size); |
| r5521 | r5522 | |
| 1265 | 1268 | hbank_end_addr += c64_cbm_cart[i].addr - 0xe000 + c64_cbm_cart[i].size; |
| 1266 | 1269 | } |
| 1267 | 1270 | } |
| 1271 | */ |
| 1272 | memcpy(roml, cart + 0 * 0x2000, 0x2000); |
| 1273 | if (n_banks > 1) memcpy(romh, cart + 1 * 0x2000, 0x2000); |
| 1268 | 1274 | |
| 1269 | | c64_cart_loaded = 1; // this is needed so that we only set mappers if a cart is present! |
| 1275 | c64_cart_n_banks = n_banks; // this is needed so that we only set mappers if a cart is present! |
| 1270 | 1276 | return INIT_PASS; |
| 1271 | 1277 | } |
| 1272 | 1278 | |
| r5521 | r5522 | |
| 1292 | 1298 | |
| 1293 | 1299 | static WRITE8_HANDLER( ocean1_bank_w ) |
| 1294 | 1300 | { |
| 1301 | // Type # 5 |
| 1302 | // working: Ghostbusters, Terminator 2 |
| 1303 | // not working: Pang, Robocop 2, Toki |
| 1304 | |
| 1295 | 1305 | UINT8 bank = data & 0x3f; |
| 1296 | 1306 | UINT8 *cart = memory_region(space->machine, "cart"); |
| 1297 | 1307 | |
| 1298 | | if (bank < 32) |
| 1308 | if (c64_cart_n_banks != 64) // all carts except Terminator II |
| 1309 | { |
| 1310 | if (bank < 16) |
| 1311 | memcpy(roml, cart + bank * 0x2000, 0x2000); |
| 1312 | else |
| 1313 | memcpy(romh, cart + (bank - 16) * 0x2000, 0x2000); |
| 1314 | } |
| 1315 | else // Terminator II |
| 1316 | { |
| 1299 | 1317 | memcpy(roml, cart + bank * 0x2000, 0x2000); |
| 1300 | | else |
| 1301 | | memcpy(romh, cart + (bank - 32) * 0x2000, 0x2000); |
| 1318 | } |
| 1302 | 1319 | /* |
| 1303 | 1320 | if (log_cart) |
| 1304 | 1321 | { |
| r5521 | r5522 | |
| 1311 | 1328 | |
| 1312 | 1329 | static WRITE8_HANDLER( funplay_bank_w ) |
| 1313 | 1330 | { |
| 1331 | // Type # 7 |
| 1332 | // working: |
| 1333 | // not working: |
| 1334 | |
| 1314 | 1335 | UINT8 bank = data & 0x39, real_bank = 0; |
| 1315 | | UINT8 *mem = memory_region(space->machine, "maincpu"); |
| 1316 | 1336 | UINT8 *cart = memory_region(space->machine, "cart"); |
| 1317 | 1337 | |
| 1318 | 1338 | /* This should be written after the bankswitch has happened. We log it to see if it is really working */ |
| r5521 | r5522 | |
| 1323 | 1343 | /* bank number is not the value written, but c64_cbm_cart[bank].index IS the value written! */ |
| 1324 | 1344 | real_bank = ((bank & 0x01) << 3) + ((bank & 0x38) >> 3); |
| 1325 | 1345 | |
| 1326 | | memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size); |
| 1346 | // memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size); |
| 1327 | 1347 | |
| 1348 | memcpy(roml, cart + real_bank * 0x2000, 0x2000); |
| 1349 | |
| 1328 | 1350 | if (log_cart) |
| 1329 | 1351 | { |
| 1330 | 1352 | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr); |
| r5521 | r5522 | |
| 1336 | 1358 | |
| 1337 | 1359 | static WRITE8_HANDLER( c64gs_bank_w ) |
| 1338 | 1360 | { |
| 1361 | // Type # 15 |
| 1362 | // working: |
| 1363 | // not working: The Last Ninja Remix |
| 1364 | |
| 1339 | 1365 | UINT8 bank = offset & 0xff; |
| 1340 | | UINT8 *mem = memory_region(space->machine, "maincpu"); |
| 1341 | 1366 | UINT8 *cart = memory_region(space->machine, "cart"); |
| 1342 | 1367 | |
| 1343 | 1368 | if (bank > 0x3f) |
| 1344 | 1369 | logerror("Warning: This cart type should have at most 64 banks and the cart looked for bank %d... Something strange is going on!\n", bank); |
| 1345 | 1370 | |
| 1346 | | memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size); |
| 1371 | // memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size); |
| 1347 | 1372 | |
| 1373 | memcpy(roml, cart + bank * 0x2000, 0x2000); |
| 1374 | |
| 1348 | 1375 | if (log_cart) |
| 1349 | 1376 | { |
| 1350 | 1377 | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr); |
| r5521 | r5522 | |
| 1355 | 1382 | |
| 1356 | 1383 | static READ8_HANDLER( dinamic_bank_r ) |
| 1357 | 1384 | { |
| 1385 | // Type # 17 |
| 1386 | // working: Satan |
| 1387 | // not working: |
| 1388 | |
| 1358 | 1389 | UINT8 bank = offset & 0xff; |
| 1359 | | UINT8 *mem = memory_region(space->machine, "maincpu"); |
| 1360 | 1390 | UINT8 *cart = memory_region(space->machine, "cart"); |
| 1361 | 1391 | |
| 1362 | 1392 | if (bank > 0xf) |
| 1363 | 1393 | logerror("Warning: This cart type should have 16 banks and the cart looked for bank %d... Something strange is going on!\n", bank); |
| 1364 | 1394 | |
| 1365 | | memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size); |
| 1395 | memcpy(roml, cart + bank * 0x2000, 0x2000); |
| 1366 | 1396 | |
| 1397 | // memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size); |
| 1398 | |
| 1367 | 1399 | if (log_cart) |
| 1368 | 1400 | { |
| 1369 | 1401 | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr); |
| r5521 | r5522 | |
| 1376 | 1408 | |
| 1377 | 1409 | static WRITE8_HANDLER( comal80_bank_w ) |
| 1378 | 1410 | { |
| 1411 | // Type # 21 |
| 1412 | // working: Comal 80 |
| 1413 | // not working: |
| 1414 | |
| 1379 | 1415 | UINT8 bank = data & 0x83; |
| 1380 | 1416 | UINT8 *cart = memory_region(space->machine, "cart"); |
| 1381 | 1417 | |
| r5521 | r5522 | |
| 1404 | 1440 | |
| 1405 | 1441 | switch( c64_mapper ) |
| 1406 | 1442 | { |
| 1407 | | case FINAL_CART_III: /* 4 16k banks, loaded at 0x8000, banks chosen by writing to 0xdfff */ |
| 1443 | case KCS_PC: /* Type # 2 not working*/ |
| 1444 | break; |
| 1445 | case FINAL_CART_III: /* Type # 3 - 4 16k banks, loaded at 0x8000, banks chosen by writing to 0xdfff */ |
| 1408 | 1446 | memory_install_write8_handler( space, 0xdfff, 0xdfff, 0, 0, fc3_bank_w ); |
| 1409 | 1447 | break; |
| 1410 | | case OCEAN_1: /* up to 64 8k banks, loaded at 0x8000 or 0xa000, banks chosen by writing to 0xde00 */ |
| 1448 | case SIMONS_BASIC: /* Type # 4 not working*/ |
| 1449 | break; |
| 1450 | case OCEAN_1: /* Type # 5 - up to 64 8k banks, loaded at 0x8000 or 0xa000, banks chosen by writing to 0xde00 */ |
| 1411 | 1451 | memory_install_write8_handler( space, 0xde00, 0xde00, 0, 0, ocean1_bank_w ); |
| 1412 | 1452 | break; |
| 1413 | | case FUN_PLAY: /* 16 8k banks, loaded at 0x8000, banks chosen by writing to 0xde00 */ |
| 1453 | case FUN_PLAY: /* Type # 7 - 16 8k banks, loaded at 0x8000, banks chosen by writing to 0xde00 */ |
| 1414 | 1454 | memory_install_write8_handler( space, 0xde00, 0xde00, 0, 0, funplay_bank_w ); |
| 1415 | 1455 | break; |
| 1416 | | case C64GS: /* up to 64 8k banks, loaded at 0x8000, banks chosen by writing to 0xde00+bank# */ |
| 1456 | case EPYX_FASTLOAD: /* Type # 10 not working*/ |
| 1457 | break; |
| 1458 | case WESTERMANN: /* Type # 11 not working*/ |
| 1459 | break; |
| 1460 | case FINAL_CART_I: /* Type # 13 not working*/ |
| 1461 | break; |
| 1462 | case C64GS: /* Type # 15 - up to 64 8k banks, loaded at 0x8000, banks chosen by writing to 0xde00 + bank */ |
| 1417 | 1463 | memory_install_write8_handler( space, 0xde00, 0xdeff, 0, 0, c64gs_bank_w ); |
| 1418 | 1464 | break; |
| 1419 | | case DINAMIC: /* 16 8k banks, loaded at 0x8000, banks chosen by reading to 0xde00+bank# */ |
| 1465 | case DINAMIC: /* Type # 17 - 16 8k banks, loaded at 0x8000, banks chosen by reading to 0xde00 + bank# */ |
| 1420 | 1466 | memory_install_read8_handler( space, 0xde00, 0xdeff, 0, 0, dinamic_bank_r ); |
| 1421 | 1467 | break; |
| 1422 | | case COMAL_80: /* 4 16k banks, loaded at 0x8000, banks chosen by writing(?) to 0xde00 */ |
| 1468 | case COMAL_80: /* Type # 21 - 4 16k banks, loaded at 0x8000, banks chosen by writing the value 0x80 + bank to 0xde00 */ |
| 1423 | 1469 | memory_install_write8_handler( space, 0xde00, 0xde00, 0, 0, comal80_bank_w ); |
| 1424 | 1470 | break; |
| 1425 | | case GENERIC_CRT: /* single bank, no bankswitch, loaded at start with correct size and place */ |
| 1471 | case GENERIC_CRT: /* Type # 0 - single bank, no bankswitch, loaded at start with correct size and place */ |
| 1426 | 1472 | default: |
| 1427 | 1473 | break; |
| 1428 | 1474 | } |
| r5521 | r5522 | |
| 1431 | 1477 | |
| 1432 | 1478 | MACHINE_RESET( c64 ) |
| 1433 | 1479 | { |
| 1434 | | if(c64_cart_loaded) |
| 1480 | if(c64_cart_n_banks) |
| 1435 | 1481 | setup_c64_custom_mappers(machine); |
| 1436 | 1482 | } |
| 1437 | 1483 | |