src/mess/machine/c64.c
| r8857 | r8858 | |
| 64 | 64 | static int c64_cia1_on; |
| 65 | 65 | static int c64_io_enabled; |
| 66 | 66 | static int is_sx64; // temporary workaround until we implement full vc1541 emulation for every c64 set |
| 67 | | static UINT8 c64_cart_n_banks = 0; |
| 68 | 67 | |
| 69 | 68 | static UINT8 vicirq; |
| 70 | 69 | |
| r8857 | r8858 | |
| 939 | 938 | */ |
| 940 | 939 | |
| 941 | 940 | |
| 942 | | #define C64_MAX_ROMBANK 64 //? |
| 943 | | |
| 944 | | static CBM_ROM c64_cbm_cart[C64_MAX_ROMBANK] = { {0} }; |
| 945 | | static INT8 cbm_c64_game; |
| 946 | | static INT8 cbm_c64_exrom; |
| 947 | | |
| 948 | | static DEVICE_IMAGE_UNLOAD( c64_cart ) |
| 949 | | { |
| 950 | | int i; |
| 951 | | |
| 952 | | for (i = 0; i < C64_MAX_ROMBANK; i++) |
| 953 | | { |
| 954 | | c64_cbm_cart[i].size = 0; |
| 955 | | c64_cbm_cart[i].addr = 0; |
| 956 | | c64_cbm_cart[i].chip = 0; |
| 957 | | } |
| 958 | | } |
| 959 | | |
| 960 | | |
| 961 | | static DEVICE_START( c64_cart ) |
| 962 | | { |
| 963 | | int index = 0; |
| 964 | | |
| 965 | | if (strcmp(device->tag(), "cart1") == 0) |
| 966 | | index = 0; |
| 967 | | |
| 968 | | if (strcmp(device->tag(), "cart2") == 0) |
| 969 | | index = 1; |
| 970 | | |
| 971 | | |
| 972 | | /* In the first slot we can load a .crt file. In this case we want |
| 973 | | to use game & exrom values from the header, not the default ones. */ |
| 974 | | if (index == 0) |
| 975 | | { |
| 976 | | cbm_c64_game = -1; |
| 977 | | cbm_c64_exrom = -1; |
| 978 | | } |
| 979 | | } |
| 980 | | |
| 981 | 941 | /* Hardware Types for C64 carts */ |
| 982 | 942 | enum { |
| 983 | 943 | GENERIC_CRT = 0, /* 00 - Normal cartridge */ |
| r8857 | r8858 | |
| 987 | 947 | SIMONS_BASIC, /* 04 - Simons Basic */ |
| 988 | 948 | OCEAN_1, /* 05 - Ocean type 1 (1) */ |
| 989 | 949 | EXPERT, /* 06 - Expert Cartridge */ |
| 990 | | FUN_PLAY, /* 07 - Fun Play, Power Play */ |
| 991 | | SUPER_GAMES, /* 08 - Super Games */ |
| 950 | FUN_PLAY, /* 07 - Fun Play, Power Play */ |
| 951 | SUPER_GAMES, /* 08 - Super Games */ |
| 992 | 952 | ATOMIC_POWER, /* 09 - Atomic Power */ |
| 993 | 953 | EPYX_FASTLOAD, /* 10 - Epyx Fastload */ |
| 994 | 954 | WESTERMANN, /* 11 - Westermann Learning */ |
| 995 | | REX, /* 12 - Rex Utility */ |
| 955 | REX, /* 12 - Rex Utility */ |
| 996 | 956 | FINAL_CART_I, /* 13 - Final Cartridge I */ |
| 997 | 957 | MAGIC_FORMEL, /* 14 - Magic Formel */ |
| 998 | | C64GS, /* 15 - C64 Game System, System 3 */ |
| 958 | C64GS, /* 15 - C64 Game System, System 3 */ |
| 999 | 959 | WARPSPEED, /* 16 - WarpSpeed */ |
| 1000 | | DINAMIC, /* 17 - Dinamic (2) */ |
| 1001 | | ZAXXON, /* 18 - Zaxxon, Super Zaxxon (SEGA) */ |
| 1002 | | DOMARK, /* 19 - Magic Desk, Domark, HES Australia */ |
| 960 | DINAMIC, /* 17 - Dinamic (2) */ |
| 961 | ZAXXON, /* 18 - Zaxxon, Super Zaxxon (SEGA) */ |
| 962 | DOMARK, /* 19 - Magic Desk, Domark, HES Australia */ |
| 1003 | 963 | SUPER_SNAP_5, /* 20 - Super Snapshot 5 */ |
| 1004 | 964 | COMAL_80, /* 21 - Comal-80 */ |
| 1005 | 965 | STRUCT_BASIC, /* 22 - Structured Basic */ |
| 1006 | | ROSS, /* 23 - Ross */ |
| 966 | ROSS, /* 23 - Ross */ |
| 1007 | 967 | DELA_EP64, /* 24 - Dela EP64 */ |
| 1008 | | DELA_EP7X8, /* 25 - Dela EP7x8 */ |
| 1009 | | DELA_EP256, /* 26 - Dela EP256 */ |
| 968 | DELA_EP7X8, /* 25 - Dela EP7x8 */ |
| 969 | DELA_EP256, /* 26 - Dela EP256 */ |
| 1010 | 970 | REX_EP256, /* 27 - Rex EP256 */ |
| 1011 | 971 | MIKRO_ASSMBLR, /* 28 - Mikro Assembler */ |
| 1012 | | REAL_FC_I, /* 29 - (3) */ |
| 972 | REAL_FC_I, /* 29 - (3) */ |
| 1013 | 973 | ACTION_REPLAY_4, /* 30 - Action Replay 4 */ |
| 1014 | | STARDOS, /* 31 - StarDOS */ |
| 974 | STARDOS, /* 31 - StarDOS */ |
| 1015 | 975 | /* |
| 1016 | 976 | (1) Ocean type 1 includes Navy Seals, Robocop 2 & 3, Shadow of |
| 1017 | 977 | the Beast, Toki, Terminator 2 and more. Both 256 and 128 Kb images. |
| r8857 | r8858 | |
| 1030 | 990 | *****************************************/ |
| 1031 | 991 | }; |
| 1032 | 992 | |
| 1033 | | static UINT8 c64_mapper = GENERIC_CRT; |
| 993 | #define C64_MAX_ROMBANK 64 // .crt files contain multiple 'CHIPs', i.e. rom banks (of variable size) with headers. Known carts have at most 64 'CHIPs'. |
| 1034 | 994 | |
| 1035 | | static int c64_common_cart_load( device_image_interface &image ) |
| 995 | typedef struct { |
| 996 | int addr, size, index, start; |
| 997 | } C64_ROM; |
| 998 | |
| 999 | typedef struct _c64_cart_t c64_cart_t; |
| 1000 | struct _c64_cart_t { |
| 1001 | C64_ROM bank[C64_MAX_ROMBANK]; |
| 1002 | INT8 game; |
| 1003 | INT8 exrom; |
| 1004 | UINT8 mapper; |
| 1005 | UINT8 n_banks; |
| 1006 | }; |
| 1007 | |
| 1008 | static c64_cart_t c64_cart; |
| 1009 | |
| 1010 | static DEVICE_IMAGE_UNLOAD( c64_cart ) |
| 1036 | 1011 | { |
| 1037 | | int size = image.length(), test, i = 0, n_banks; |
| 1038 | | const char *filetype; |
| 1012 | int i; |
| 1013 | |
| 1014 | for (i = 0; i < C64_MAX_ROMBANK; i++) |
| 1015 | { |
| 1016 | c64_cart.bank[i].size = 0; |
| 1017 | c64_cart.bank[i].addr = 0; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | static DEVICE_START( c64_cart ) |
| 1023 | { |
| 1024 | /* In the first slot we can load a .crt file. In this case we want |
| 1025 | to use game & exrom values from the header, not the default ones. */ |
| 1026 | c64_cart.game = -1; |
| 1027 | c64_cart.exrom = -1; |
| 1028 | c64_cart.mapper = GENERIC_CRT; |
| 1029 | c64_cart.n_banks = 0; |
| 1030 | } |
| 1031 | |
| 1032 | static int c64_crt_load( device_image_interface &image ) |
| 1033 | { |
| 1034 | int size = image.length(), test, i = 0, ii; |
| 1035 | int _80_loaded = 0, _90_loaded = 0, a0_loaded = 0, b0_loaded = 0, e0_loaded = 0, f0_loaded = 0; |
| 1036 | const char *filetype = image.filetype(); |
| 1039 | 1037 | int address = 0, new_start = 0; |
| 1040 | 1038 | // int lbank_end_addr = 0, hbank_end_addr = 0; |
| 1041 | | UINT8 *temp_cart = auto_alloc_array(image.device().machine, UINT8, size); |
| 1039 | UINT8 *cart_cpy = memory_region(image.device().machine, "user1"); |
| 1042 | 1040 | |
| 1043 | | filetype = image.filetype(); |
| 1044 | | |
| 1045 | 1041 | /* We support .crt files */ |
| 1046 | 1042 | if (!mame_stricmp(filetype, "crt")) |
| 1047 | 1043 | { |
| 1048 | 1044 | int j; |
| 1049 | 1045 | unsigned short c64_cart_type; |
| 1050 | 1046 | |
| 1051 | | for (i = 0; (i < ARRAY_LENGTH(c64_cbm_cart)) && (c64_cbm_cart[i].size != 0); i++) |
| 1047 | for (i = 0; (i < C64_MAX_ROMBANK) && (c64_cart.bank[i].size != 0); i++) |
| 1052 | 1048 | ; |
| 1053 | 1049 | |
| 1054 | | if (i >= ARRAY_LENGTH(c64_cbm_cart)) |
| 1055 | | { |
| 1056 | | auto_free(image.device().machine, temp_cart); |
| 1050 | if (i >= C64_MAX_ROMBANK) |
| 1057 | 1051 | return IMAGE_INIT_FAIL; |
| 1058 | | } |
| 1059 | 1052 | |
| 1060 | 1053 | /* Start to parse the .crt header */ |
| 1061 | 1054 | /* 0x16-0x17 is Hardware type */ |
| 1062 | 1055 | image.fseek(0x16, SEEK_SET); |
| 1063 | 1056 | image.fread(&c64_cart_type, 2); |
| 1064 | 1057 | c64_cart_type = BIG_ENDIANIZE_INT16(c64_cart_type); |
| 1065 | | c64_mapper = c64_cart_type; |
| 1058 | c64_cart.mapper = c64_cart_type; |
| 1066 | 1059 | |
| 1067 | 1060 | /* If it is unsupported cart type, warn the user */ |
| 1068 | 1061 | switch (c64_cart_type) |
| 1069 | 1062 | { |
| 1070 | | case ACTION_REPLAY: /* Type # 1 */ |
| 1071 | | case KCS_PC: /* Type # 2 */ |
| 1072 | | case FINAL_CART_III: /* Type # 3 */ |
| 1073 | 1063 | case SIMONS_BASIC: /* Type # 4 */ |
| 1074 | 1064 | case OCEAN_1: /* Type # 5 */ |
| 1075 | | case EXPERT: /* Type # 6 */ |
| 1076 | 1065 | case FUN_PLAY: /* Type # 7 */ |
| 1077 | 1066 | case SUPER_GAMES: /* Type # 8 */ |
| 1078 | | case ATOMIC_POWER: /* Type # 9 */ |
| 1079 | 1067 | case EPYX_FASTLOAD: /* Type # 10 */ |
| 1080 | | case WESTERMANN: /* Type # 11 */ |
| 1081 | 1068 | case REX: /* Type # 12 */ |
| 1082 | | case FINAL_CART_I: /* Type # 13 */ |
| 1083 | | case MAGIC_FORMEL: /* Type # 14 */ |
| 1084 | 1069 | case C64GS: /* Type # 15 */ |
| 1085 | 1070 | case DINAMIC: /* Type # 17 */ |
| 1086 | 1071 | case ZAXXON: /* Type # 18 */ |
| 1087 | 1072 | case DOMARK: /* Type # 19 */ |
| 1088 | | case SUPER_SNAP_5: /* Type # 20 */ |
| 1089 | 1073 | case COMAL_80: /* Type # 21 */ |
| 1090 | 1074 | case GENERIC_CRT: /* Type # 0 */ |
| 1091 | 1075 | printf("Currently supported cart type (Type %d)\n", c64_cart_type); |
| 1092 | 1076 | break; |
| 1093 | 1077 | |
| 1094 | 1078 | default: |
| 1079 | case ACTION_REPLAY: /* Type # 1 */ |
| 1080 | case KCS_PC: /* Type # 2 */ |
| 1081 | case FINAL_CART_III: /* Type # 3 */ |
| 1082 | case EXPERT: /* Type # 6 */ |
| 1083 | case ATOMIC_POWER: /* Type # 9 */ |
| 1084 | case WESTERMANN: /* Type # 11 */ |
| 1085 | case FINAL_CART_I: /* Type # 13 */ |
| 1086 | case MAGIC_FORMEL: /* Type # 14 */ |
| 1087 | case SUPER_SNAP_5: /* Type # 20 */ |
| 1095 | 1088 | printf("Currently unsupported cart type (Type %d)\n", c64_cart_type); |
| 1096 | 1089 | break; |
| 1097 | 1090 | } |
| 1098 | 1091 | |
| 1099 | 1092 | /* 0x18 is EXROM */ |
| 1100 | 1093 | image.fseek(0x18, SEEK_SET); |
| 1101 | | image.fread(&cbm_c64_exrom, 1); |
| 1094 | image.fread(&c64_cart.exrom, 1); |
| 1102 | 1095 | |
| 1103 | 1096 | /* 0x19 is GAME */ |
| 1104 | | image.fread(&cbm_c64_game, 1); |
| 1097 | image.fread(&c64_cart.game, 1); |
| 1105 | 1098 | |
| 1106 | 1099 | /* We can pass to the data: it starts from 0x40 */ |
| 1107 | 1100 | image.fseek(0x40, SEEK_SET); |
| 1108 | 1101 | j = 0x40; |
| 1109 | 1102 | |
| 1110 | 1103 | logerror("Loading cart %s size:%.4x\n", image.filename(), size); |
| 1111 | | logerror("Header info: EXROM %d, GAME %d, Cart Type %d \n", cbm_c64_exrom, cbm_c64_game, c64_cart_type); |
| 1104 | logerror("Header info: EXROM %d, GAME %d, Cart Type %d \n", c64_cart.exrom, c64_cart.game, c64_cart_type); |
| 1112 | 1105 | |
| 1113 | 1106 | |
| 1114 | 1107 | /* Data in a .crt image are organized in blocks called 'CHIP': |
| r8857 | r8858 | |
| 1150 | 1143 | address, chip_data_size); |
| 1151 | 1144 | logerror("Loading CHIP data at %.4x size:%.4x\n", address, chip_data_size); |
| 1152 | 1145 | |
| 1153 | | /* Does CHIP contain any data? */ |
| 1154 | | c64_cbm_cart[i].chip = (UINT8*) image.image_malloc(chip_data_size); |
| 1155 | | if (!c64_cbm_cart[i].chip) |
| 1156 | | { |
| 1157 | | auto_free(image.device().machine, temp_cart); |
| 1158 | | return IMAGE_INIT_FAIL; |
| 1159 | | } |
| 1160 | | |
| 1161 | 1146 | /* Store data, address & size of the CHIP block */ |
| 1162 | | c64_cbm_cart[i].addr = address; |
| 1163 | | c64_cbm_cart[i].index = chip_bank_index; |
| 1164 | | c64_cbm_cart[i].size = chip_data_size; |
| 1165 | | c64_cbm_cart[i].start = new_start; |
| 1147 | c64_cart.bank[i].addr = address; |
| 1148 | c64_cart.bank[i].index = chip_bank_index; |
| 1149 | c64_cart.bank[i].size = chip_data_size; |
| 1150 | c64_cart.bank[i].start = new_start; |
| 1166 | 1151 | |
| 1167 | | test = image.fread(c64_cbm_cart[i].chip, chip_data_size); |
| 1152 | test = image.fread(cart_cpy + new_start, c64_cart.bank[i].size); |
| 1153 | new_start += c64_cart.bank[i].size; |
| 1168 | 1154 | |
| 1169 | | memcpy(&temp_cart[new_start], c64_cbm_cart[i].chip, c64_cbm_cart[i].size); |
| 1170 | | new_start += c64_cbm_cart[i].size; |
| 1171 | | |
| 1172 | | if (test != chip_data_size) |
| 1173 | | { |
| 1174 | | auto_free(image.device().machine, temp_cart); |
| 1155 | /* Does CHIP contain any data? */ |
| 1156 | if (test != c64_cart.bank[i].size) |
| 1175 | 1157 | return IMAGE_INIT_FAIL; |
| 1176 | | } |
| 1177 | 1158 | |
| 1178 | 1159 | /* Advance to the next CHIP block */ |
| 1179 | 1160 | i++; |
| r8857 | r8858 | |
| 1183 | 1164 | else /* We also support .80 files for c64 & .e0/.f0 for max */ |
| 1184 | 1165 | { |
| 1185 | 1166 | /* Assign loading address according to extension */ |
| 1186 | | if (!mame_stricmp (filetype, "80")) |
| 1167 | if (!mame_stricmp(filetype, "80")) |
| 1187 | 1168 | address = 0x8000; |
| 1188 | 1169 | |
| 1189 | | if (!mame_stricmp (filetype, "e0")) |
| 1170 | if (!mame_stricmp(filetype, "e0")) |
| 1190 | 1171 | address = 0xe000; |
| 1191 | 1172 | |
| 1192 | | if (!mame_stricmp (filetype, "f0")) |
| 1173 | if (!mame_stricmp(filetype, "f0")) |
| 1193 | 1174 | address = 0xf000; |
| 1194 | 1175 | |
| 1195 | 1176 | logerror("loading %s rom at %.4x size:%.4x\n", image.filename(), address, size); |
| 1196 | 1177 | |
| 1197 | | /* Does cart contain any data? */ |
| 1198 | | c64_cbm_cart[0].chip = (UINT8*) image.image_malloc(size); |
| 1199 | | if (!c64_cbm_cart[0].chip) |
| 1200 | | { |
| 1201 | | auto_free(image.device().machine, temp_cart); |
| 1202 | | return IMAGE_INIT_FAIL; |
| 1203 | | } |
| 1204 | | |
| 1205 | 1178 | /* Store data, address & size */ |
| 1206 | | c64_cbm_cart[0].addr = address; |
| 1207 | | c64_cbm_cart[0].size = size; |
| 1208 | | c64_cbm_cart[0].start = new_start; |
| 1179 | c64_cart.bank[0].addr = address; |
| 1180 | c64_cart.bank[0].size = size; |
| 1181 | c64_cart.bank[0].start = new_start; |
| 1209 | 1182 | |
| 1210 | | test = image.fread(c64_cbm_cart[0].chip, size); |
| 1183 | test = image.fread(cart_cpy + new_start, c64_cart.bank[0].size); |
| 1184 | new_start += c64_cart.bank[0].size; |
| 1211 | 1185 | |
| 1212 | | memcpy(&temp_cart[new_start], c64_cbm_cart[0].chip, c64_cbm_cart[0].size); |
| 1213 | | new_start += c64_cbm_cart[0].size; |
| 1214 | | |
| 1215 | | if (test != c64_cbm_cart[0].size) |
| 1216 | | { |
| 1217 | | auto_free(image.device().machine, temp_cart); |
| 1186 | /* Does cart contain any data? */ |
| 1187 | if (test != c64_cart.bank[0].size) |
| 1218 | 1188 | return IMAGE_INIT_FAIL; |
| 1219 | | } |
| 1220 | 1189 | } |
| 1221 | 1190 | |
| 1222 | | n_banks = i; |
| 1191 | c64_cart.n_banks = i; // this is also needed so that we only set mappers if a cart is present! |
| 1223 | 1192 | |
| 1224 | 1193 | /* If we load a .crt file, use EXROM & GAME from the header! */ |
| 1225 | | if ((cbm_c64_exrom != -1) && (cbm_c64_game != -1)) |
| 1194 | if ((c64_cart.exrom != -1) && (c64_cart.game != -1)) |
| 1226 | 1195 | { |
| 1227 | | c64_exrom = cbm_c64_exrom; |
| 1228 | | c64_game = cbm_c64_game; |
| 1196 | c64_exrom = c64_cart.exrom; |
| 1197 | c64_game = c64_cart.game; |
| 1229 | 1198 | } |
| 1230 | 1199 | |
| 1231 | 1200 | /* Finally load the cart */ |
| r8857 | r8858 | |
| 1235 | 1204 | memset(roml, 0, 0x2000); |
| 1236 | 1205 | memset(romh, 0, 0x2000); |
| 1237 | 1206 | |
| 1238 | | switch (c64_mapper) |
| 1207 | switch (c64_cart.mapper) |
| 1239 | 1208 | { |
| 1240 | | case ZAXXON: |
| 1241 | | memcpy(romh, temp_cart + 0x1000, 0x2000); |
| 1242 | | break; |
| 1243 | 1209 | default: |
| 1244 | | if (!c64_game && c64_exrom && (n_banks == 1)) |
| 1245 | | memcpy(romh, temp_cart, 0x2000); |
| 1210 | if (!c64_game && c64_exrom && (c64_cart.n_banks == 1)) |
| 1211 | { |
| 1212 | memcpy(romh, cart_cpy, 0x2000); |
| 1213 | } |
| 1246 | 1214 | else |
| 1247 | 1215 | { |
| 1248 | | memcpy(roml, temp_cart + 0 * 0x2000, 0x2000); |
| 1249 | | memcpy(romh, temp_cart + 1 * 0x2000, 0x2000); |
| 1216 | // we first attempt to load the first 'CHIPs' with address 0x8000-0xb000 and 0xe000-0xf000, otherwise we load the first (or first two) 'CHIPs' of the image |
| 1217 | for (ii = 0; ii < c64_cart.n_banks; ii++) |
| 1218 | { |
| 1219 | if (c64_cart.bank[ii].addr == 0x8000 && !_80_loaded) |
| 1220 | { |
| 1221 | memcpy(roml, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size); |
| 1222 | _80_loaded = 1; |
| 1223 | if (c64_cart.bank[ii].size > 0x1000) |
| 1224 | _90_loaded = 1; |
| 1225 | if (c64_cart.bank[ii].size > 0x2000) |
| 1226 | a0_loaded = 1; |
| 1227 | if (c64_cart.bank[ii].size > 0x3000) |
| 1228 | b0_loaded = 1; |
| 1229 | // printf("addr 0x8000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded); |
| 1230 | } |
| 1231 | |
| 1232 | if (c64_cart.bank[ii].addr == 0x9000 && !_90_loaded) |
| 1233 | { |
| 1234 | memcpy(roml + 0x1000, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size); |
| 1235 | _90_loaded = 1; |
| 1236 | if (c64_cart.bank[ii].size > 0x1000) |
| 1237 | a0_loaded = 1; |
| 1238 | if (c64_cart.bank[ii].size > 0x2000) |
| 1239 | b0_loaded = 1; |
| 1240 | // printf("addr 0x9000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded); |
| 1241 | } |
| 1242 | |
| 1243 | if (c64_cart.bank[ii].addr == 0xa000 && !a0_loaded) |
| 1244 | { |
| 1245 | memcpy(roml + 0x2000, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size); |
| 1246 | a0_loaded = 1; |
| 1247 | if (c64_cart.bank[ii].size > 0x1000) |
| 1248 | b0_loaded = 1; |
| 1249 | // printf("addr 0xa000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded); |
| 1250 | } |
| 1251 | |
| 1252 | if (c64_cart.bank[ii].addr == 0xb000 && !b0_loaded) |
| 1253 | { |
| 1254 | memcpy(roml + 0x3000, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size); |
| 1255 | b0_loaded = 1; |
| 1256 | // printf("addr 0xb000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded); |
| 1257 | } |
| 1258 | |
| 1259 | if (c64_cart.bank[ii].addr == 0xe000 && !e0_loaded) |
| 1260 | { |
| 1261 | memcpy(romh, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size); |
| 1262 | e0_loaded = 1; |
| 1263 | if (c64_cart.bank[ii].size > 0x1000) |
| 1264 | f0_loaded = 1; |
| 1265 | // printf("addr 0xe000: e0 %d, f0 %d\n", e0_loaded, f0_loaded); |
| 1266 | } |
| 1267 | |
| 1268 | if (c64_cart.bank[ii].addr == 0xf000 && !f0_loaded) |
| 1269 | { |
| 1270 | memcpy(romh + 0x1000, cart_cpy + c64_cart.bank[ii].start, c64_cart.bank[ii].size); |
| 1271 | f0_loaded = 1; |
| 1272 | // printf("addr 0xe000: e0 %d, f0 %d\n", e0_loaded, f0_loaded); |
| 1273 | } |
| 1274 | } |
| 1250 | 1275 | } |
| 1251 | 1276 | } |
| 1252 | 1277 | |
| 1253 | | c64_cart_n_banks = n_banks; // this is needed so that we only set mappers if a cart is present! |
| 1254 | | |
| 1255 | | memcpy(memory_region(image.device().machine, "user1"), temp_cart, size); |
| 1256 | | auto_free(image.device().machine, temp_cart); |
| 1257 | 1278 | return IMAGE_INIT_PASS; |
| 1258 | 1279 | } |
| 1259 | 1280 | |
| 1260 | 1281 | static DEVICE_IMAGE_LOAD( c64_cart ) |
| 1261 | 1282 | { |
| 1262 | | return c64_common_cart_load(image); |
| 1283 | return c64_crt_load(image); |
| 1263 | 1284 | } |
| 1264 | 1285 | |
| 1265 | 1286 | static DEVICE_IMAGE_LOAD( max_cart ) |
| r8857 | r8858 | |
| 1268 | 1289 | |
| 1269 | 1290 | if (image.software_entry() == NULL) |
| 1270 | 1291 | { |
| 1271 | | result = c64_common_cart_load(image); |
| 1272 | | } |
| 1273 | | else |
| 1274 | | { |
| 1275 | 1292 | UINT32 size; |
| 1276 | 1293 | |
| 1277 | 1294 | // setup Ultimax mode |
| r8857 | r8858 | |
| 1294 | 1311 | if (size) |
| 1295 | 1312 | memcpy(romh, image.get_software_region("romh"), size); |
| 1296 | 1313 | } |
| 1314 | else |
| 1315 | result = c64_crt_load(image); |
| 1297 | 1316 | |
| 1298 | 1317 | return result; |
| 1299 | 1318 | } |
| r8857 | r8858 | |
| 1319 | 1338 | /* |
| 1320 | 1339 | if (log_cart) |
| 1321 | 1340 | { |
| 1322 | | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr); |
| 1323 | | if (c64_cbm_cart[bank].index != bank) |
| 1324 | | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank); |
| 1341 | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr); |
| 1342 | if (c64_cart.bank[bank].index != bank) |
| 1343 | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank); |
| 1325 | 1344 | } |
| 1326 | 1345 | */ |
| 1327 | 1346 | } |
| r8857 | r8858 | |
| 1334 | 1353 | // working: Double Dragon, Ghostbusters, Terminator 2 |
| 1335 | 1354 | // not working: Pang, Robocop 2, Toki |
| 1336 | 1355 | |
| 1337 | | UINT8 bank = data & 0x3f; |
| 1356 | UINT8 bank = data & c64_cart.n_banks; |
| 1338 | 1357 | UINT8 *cart = memory_region(space->machine, "user1"); |
| 1339 | 1358 | |
| 1340 | | if (c64_cart_n_banks != 64) // all carts except Terminator II |
| 1359 | switch (c64_cart.bank[bank].addr) |
| 1341 | 1360 | { |
| 1342 | | if (bank < 16) |
| 1343 | | memcpy(roml, cart + bank * 0x2000, 0x2000); |
| 1344 | | else |
| 1345 | | memcpy(romh, cart + (bank - 16) * 0x2000, 0x2000); |
| 1361 | case 0x8000: |
| 1362 | memcpy(roml, cart + bank * 0x2000, c64_cart.bank[bank].size); |
| 1363 | break; |
| 1364 | case 0xa000: |
| 1365 | memcpy(roml + 0x2000, cart + bank * 0x2000, c64_cart.bank[bank].size); |
| 1366 | break; |
| 1367 | case 0xe000: |
| 1368 | memcpy(romh, cart + bank * 0x2000, c64_cart.bank[bank].size); |
| 1369 | break; |
| 1370 | default: |
| 1371 | logerror("Unexpected loading address (%x) for bank %x", c64_cart.bank[bank].addr, bank); |
| 1372 | break; |
| 1346 | 1373 | } |
| 1347 | | else // Terminator II |
| 1348 | | { |
| 1349 | | memcpy(roml, cart + bank * 0x2000, 0x2000); |
| 1350 | | } |
| 1351 | 1374 | /* |
| 1352 | 1375 | if (log_cart) |
| 1353 | 1376 | { |
| 1354 | | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr); |
| 1355 | | if (c64_cbm_cart[bank].index != bank) |
| 1356 | | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank); |
| 1377 | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr); |
| 1378 | if (c64_cart.bank[bank].index != bank) |
| 1379 | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank); |
| 1357 | 1380 | } |
| 1358 | 1381 | */ |
| 1359 | 1382 | } |
| r8857 | r8858 | |
| 1372 | 1395 | logerror("Reserved value written\n"); |
| 1373 | 1396 | else |
| 1374 | 1397 | { |
| 1375 | | /* bank number is not the value written, but c64_cbm_cart[bank].index IS the value written! */ |
| 1398 | /* bank number is not the value written, but c64_cart.bank[bank].index IS the value written! */ |
| 1376 | 1399 | real_bank = ((bank & 0x01) << 3) + ((bank & 0x38) >> 3); |
| 1377 | 1400 | |
| 1378 | 1401 | memcpy(roml, cart + real_bank * 0x2000, 0x2000); |
| 1379 | 1402 | /* |
| 1380 | 1403 | if (log_cart) |
| 1381 | 1404 | { |
| 1382 | | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr); |
| 1383 | | if (c64_cbm_cart[bank].index != bank) |
| 1384 | | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank); |
| 1405 | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr); |
| 1406 | if (c64_cart.bank[bank].index != bank) |
| 1407 | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank); |
| 1385 | 1408 | } |
| 1386 | 1409 | */ |
| 1387 | 1410 | } |
| r8857 | r8858 | |
| 1441 | 1464 | /* |
| 1442 | 1465 | if (log_cart) |
| 1443 | 1466 | { |
| 1444 | | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr); |
| 1445 | | if (c64_cbm_cart[bank].index != bank) |
| 1446 | | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank); |
| 1467 | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr); |
| 1468 | if (c64_cart.bank[bank].index != bank) |
| 1469 | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank); |
| 1447 | 1470 | } |
| 1448 | 1471 | */ |
| 1449 | 1472 | } |
| r8857 | r8858 | |
| 1464 | 1487 | /* |
| 1465 | 1488 | if (log_cart) |
| 1466 | 1489 | { |
| 1467 | | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr); |
| 1468 | | if (c64_cbm_cart[bank].index != bank) |
| 1469 | | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank); |
| 1490 | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr); |
| 1491 | if (c64_cart.bank[bank].index != bank) |
| 1492 | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank); |
| 1470 | 1493 | } |
| 1471 | 1494 | */ |
| 1472 | 1495 | return 0; |
| r8857 | r8858 | |
| 1536 | 1559 | /* |
| 1537 | 1560 | if (log_cart) |
| 1538 | 1561 | { |
| 1539 | | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr); |
| 1540 | | if (c64_cbm_cart[bank].index != bank) |
| 1541 | | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank); |
| 1562 | logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cart.bank[bank].size, c64_cart.bank[bank].addr); |
| 1563 | if (c64_cart.bank[bank].index != bank) |
| 1564 | logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cart.bank[bank].index, bank); |
| 1542 | 1565 | } |
| 1543 | 1566 | */ |
| 1544 | 1567 | } |
| r8857 | r8858 | |
| 1548 | 1571 | { |
| 1549 | 1572 | address_space *space = cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ); |
| 1550 | 1573 | |
| 1551 | | switch (c64_mapper) |
| 1574 | switch (c64_cart.mapper) |
| 1552 | 1575 | { |
| 1553 | 1576 | case ACTION_REPLAY: /* Type # 1 not working */ |
| 1554 | 1577 | break; |
| r8857 | r8858 | |
| 1608 | 1631 | |
| 1609 | 1632 | MACHINE_RESET( c64 ) |
| 1610 | 1633 | { |
| 1611 | | if (c64_cart_n_banks) |
| 1634 | if (c64_cart.n_banks) |
| 1612 | 1635 | setup_c64_custom_mappers(machine); |
| 1613 | 1636 | } |
| 1614 | 1637 | |