src/mess/drivers/genesis.c
| r3283 | r3284 | |
| 50 | 50 | |
| 51 | 51 | #include "driver.h" |
| 52 | 52 | #include "sound/2612intf.h" |
| 53 | | /*#include "includes/genesis.h"*/ |
| 54 | 53 | #include "devices/cartslot.h" |
| 55 | 54 | #include "../../mame/drivers/megadriv.h" |
| 56 | 55 | #include "cpu/m68000/m68000.h" |
| r3283 | r3284 | |
| 75 | 74 | static int genesis_sram_active; |
| 76 | 75 | static int genesis_sram_readonly; |
| 77 | 76 | |
| 78 | | static READ16_HANDLER( genesis_sram_read ) |
| 79 | | { |
| 80 | | UINT16 retval = 0; |
| 81 | 77 | |
| 82 | | offset <<= 1; |
| 83 | 78 | |
| 84 | | if (genesis_sram_active) |
| 85 | | { |
| 86 | | retval |= genesis_sram[offset] << 8; |
| 87 | | retval |= genesis_sram[offset ^ 1] & 0xff; |
| 88 | | } |
| 79 | /************************************* |
| 80 | * |
| 81 | * ROM definition(s) |
| 82 | * |
| 83 | *************************************/ |
| 89 | 84 | |
| 90 | | return retval; |
| 91 | | } |
| 92 | 85 | |
| 86 | /* we don't use the bios rom (it's not needed and only provides security on early models) */ |
| 93 | 87 | |
| 94 | | static WRITE16_HANDLER( genesis_sram_write ) |
| 95 | | { |
| 96 | | offset <<= 1; |
| 97 | | |
| 98 | | if (!genesis_sram_readonly) |
| 99 | | { |
| 100 | | genesis_sram[offset] = data >> 8; |
| 101 | | genesis_sram[offset ^ 1] = data & 0xff; |
| 102 | | } |
| 103 | | } |
| 104 | | |
| 105 | | |
| 106 | | static WRITE16_HANDLER( genesis_sram_toggle ) |
| 107 | | { |
| 108 | | /* unsure if this is actually supposed to toggle or just switch on? |
| 109 | | * Yet to encounter game that utilizes |
| 110 | | */ |
| 111 | | genesis_sram_active = (data & 1) ? 1 : 0; |
| 112 | | genesis_sram_readonly = (data & 2) ? 1 : 0; |
| 113 | | } |
| 114 | | |
| 115 | | |
| 116 | | /* code taken directly from GoodGEN by Cowering */ |
| 117 | | static int genesis_isfunkySMD(unsigned char *buf,unsigned int len) |
| 118 | | { |
| 119 | | /* aq quiz */ |
| 120 | | if (!strncmp("UZ(-01 ", (const char *) &buf[0xf0], 8)) |
| 121 | | return 1; |
| 122 | | |
| 123 | | /* Phelios USA redump */ |
| 124 | | /* target earth */ |
| 125 | | /* klax (namcot) */ |
| 126 | | if (buf[0x2080] == ' ' && buf[0x0080] == 'S' && buf[0x2081] == 'E' && buf[0x0081] == 'G') |
| 127 | | return 1; |
| 128 | | |
| 129 | | /* jap baseball 94 */ |
| 130 | | if (!strncmp("OL R-AEAL", (const char *) &buf[0xf0], 9)) |
| 131 | | return 1; |
| 132 | | |
| 133 | | /* devilish Mahjong Tower */ |
| 134 | | if (!strncmp("optrEtranet", (const char *) &buf[0xf3], 11)) |
| 135 | | return 1; |
| 136 | | |
| 137 | | /* golden axe 2 beta */ |
| 138 | | if (buf[0x0100] == 0x3c && buf[0x0101] == 0 && buf[0x0102] == 0 && buf[0x0103] == 0x3c) |
| 139 | | return 1; |
| 140 | | |
| 141 | | /* omega race */ |
| 142 | | if (!strncmp("OEARC ", (const char *) &buf[0x90], 8)) |
| 143 | | return 1; |
| 144 | | |
| 145 | | /* budokan beta */ |
| 146 | | if ((len >= 0x6708+8) && !strncmp(" NTEBDKN", (const char *) &buf[0x6708], 8)) |
| 147 | | return 1; |
| 148 | | |
| 149 | | /* cdx pro 1.8 bios */ |
| 150 | | if (!strncmp("so fCXP", (const char *) &buf[0x2c0], 7)) |
| 151 | | return 1; |
| 152 | | |
| 153 | | /* ishido (hacked) */ |
| 154 | | if (!strncmp("sio-Wyo ", (const char *) &buf[0x0090], 8)) |
| 155 | | return 1; |
| 156 | | |
| 157 | | /* onslaught */ |
| 158 | | if (!strncmp("SS CAL ", (const char *) &buf[0x0088], 8)) |
| 159 | | return 1; |
| 160 | | |
| 161 | | /* tram terror pirate */ |
| 162 | | if ((len >= 0x3648 + 8) && !strncmp("SG NEPIE", (const char *) &buf[0x3648], 8)) |
| 163 | | return 1; |
| 164 | | |
| 165 | | /* breath of fire 3 chinese */ |
| 166 | | if (buf[0x0007] == 0x1c && buf[0x0008] == 0x0a && buf[0x0009] == 0xb8 && buf[0x000a] == 0x0a) |
| 167 | | return 1; |
| 168 | | |
| 169 | | /*tetris pirate */ |
| 170 | | if ((len >= 0x1cbe + 5) && !strncmp("@TTI>", (const char *) &buf[0x1cbe], 5)) |
| 171 | | return 1; |
| 172 | | |
| 173 | | return 0; |
| 174 | | } |
| 175 | | |
| 176 | | |
| 177 | | |
| 178 | | /* code taken directly from GoodGEN by Cowering */ |
| 179 | | static int genesis_isSMD(unsigned char *buf,unsigned int len) |
| 180 | | { |
| 181 | | if (buf[0x2080] == 'S' && buf[0x80] == 'E' && buf[0x2081] == 'G' && buf[0x81] == 'A') |
| 182 | | return 1; |
| 183 | | return genesis_isfunkySMD(buf,len); |
| 184 | | } |
| 185 | | |
| 186 | | |
| 187 | | static DEVICE_IMAGE_LOAD( genesis_cart ) |
| 188 | | { |
| 189 | | unsigned char *ROM, *rawROM, *tmpROMnew, *tmpROM, *secondhalf; |
| 190 | | int relocate, length, ptr, x; |
| 191 | | #ifdef LSB_FIRST |
| 192 | | unsigned char fliptemp; |
| 193 | | #endif |
| 194 | | |
| 195 | | genesis_sram = NULL; |
| 196 | | genesis_sram_start = genesis_sram_len = genesis_sram_active = genesis_sram_readonly = 0; |
| 197 | | |
| 198 | | rawROM = memory_region(image->machine, "main"); |
| 199 | | ROM = rawROM /*+ 512 */; |
| 200 | | |
| 201 | | length = image_fread(image, rawROM + 0x2000, 0x600000); |
| 202 | | logerror("image length = 0x%x\n", length); |
| 203 | | |
| 204 | | if (genesis_isSMD(&rawROM[0x2200],(unsigned)length)) /* is this a SMD file..? */ |
| 205 | | { |
| 206 | | tmpROMnew = ROM; |
| 207 | | tmpROM = ROM + 0x2000 + 512; |
| 208 | | |
| 209 | | for (ptr = 0; ptr < (0x500000) / (8192); ptr += 2) |
| 210 | | { |
| 211 | | for (x = 0; x < 8192; x++) |
| 212 | | { |
| 213 | | *tmpROMnew++ = *(tmpROM + ((ptr + 1) * 8192) + x); |
| 214 | | *tmpROMnew++ = *(tmpROM + ((ptr + 0) * 8192) + x); |
| 215 | | } |
| 216 | | } |
| 217 | | |
| 218 | | #ifdef LSB_FIRST |
| 219 | | tmpROMnew = ROM; |
| 220 | | for (ptr = 0; ptr < length; ptr += 2) |
| 221 | | { |
| 222 | | fliptemp = tmpROMnew[ptr]; |
| 223 | | tmpROMnew[ptr] = tmpROMnew[ptr+1]; |
| 224 | | tmpROMnew[ptr+1] = fliptemp; |
| 225 | | } |
| 226 | | #endif |
| 227 | | genesis_last_loaded_image_length = length - 512; |
| 228 | | memcpy(&ROM[VIRGIN_COPY_GEN],&ROM[0x000000],0x500000); /* store a copy of data for MACHINE_RESET processing */ |
| 229 | | |
| 230 | | relocate = 0; |
| 231 | | |
| 232 | | } |
| 233 | | else |
| 234 | | /* check if it's a MD file */ |
| 235 | | if ((rawROM[0x2080] == 'E') && |
| 236 | | (rawROM[0x2081] == 'A') && |
| 237 | | (rawROM[0x2082] == 'M' || rawROM[0x2082] == 'G')) /* is this a MD file..? */ |
| 238 | | { |
| 239 | | tmpROMnew = malloc(length); |
| 240 | | secondhalf = &tmpROMnew[length >> 1]; |
| 241 | | |
| 242 | | if (!tmpROMnew) |
| 243 | | { |
| 244 | | logerror("Memory allocation failed reading roms!\n"); |
| 245 | | goto bad; |
| 246 | | } |
| 247 | | |
| 248 | | memcpy(tmpROMnew, ROM + 0x2000, length); |
| 249 | | for (ptr = 0; ptr < length; ptr += 2) |
| 250 | | { |
| 251 | | |
| 252 | | ROM[ptr] = secondhalf[ptr >> 1]; |
| 253 | | ROM[ptr + 1] = tmpROMnew[ptr >> 1]; |
| 254 | | } |
| 255 | | free(tmpROMnew); |
| 256 | | |
| 257 | | #ifdef LSB_FIRST |
| 258 | | for (ptr = 0; ptr < length; ptr += 2) |
| 259 | | { |
| 260 | | fliptemp = ROM[ptr]; |
| 261 | | ROM[ptr] = ROM[ptr+1]; |
| 262 | | ROM[ptr+1] = fliptemp; |
| 263 | | } |
| 264 | | #endif |
| 265 | | genesis_last_loaded_image_length = length; |
| 266 | | memcpy(&ROM[VIRGIN_COPY_GEN],&ROM[0x000000],0x500000); /* store a copy of data for MACHINE_RESET processing */ |
| 267 | | relocate = 0; |
| 268 | | |
| 269 | | } |
| 270 | | else |
| 271 | | /* BIN it is, then */ |
| 272 | | { |
| 273 | | relocate = 0x2000; |
| 274 | | genesis_last_loaded_image_length = length; |
| 275 | | |
| 276 | | |
| 277 | | ROM = memory_region(image->machine, "main"); /* 68000 ROM region */ |
| 278 | | |
| 279 | | for (ptr = 0; ptr < 0x502000; ptr += 2) /* mangle bytes for littleendian machines */ |
| 280 | | { |
| 281 | | #ifdef LSB_FIRST |
| 282 | | int temp = ROM[relocate + ptr]; |
| 283 | | |
| 284 | | ROM[ptr] = ROM[relocate + ptr + 1]; |
| 285 | | ROM[ptr + 1] = temp; |
| 286 | | #else |
| 287 | | ROM[ptr] = ROM[relocate + ptr]; |
| 288 | | ROM[ptr + 1] = ROM[relocate + ptr + 1]; |
| 289 | | #endif |
| 290 | | } |
| 291 | | memcpy(&ROM[VIRGIN_COPY_GEN],&ROM[0x000000],0x500000); /* store a copy of data for MACHINE_RESET processing */ |
| 292 | | } |
| 293 | | return INIT_PASS; |
| 294 | | |
| 295 | | bad: |
| 296 | | return INIT_FAIL; |
| 297 | | } |
| 298 | | /* we don't use the bios rom (its not needed and only provides security on early models) */ |
| 299 | | |
| 300 | 88 | ROM_START(genesis) |
| 301 | 89 | ROM_REGION(0x1415000, "main", ROMREGION_ERASEFF) |
| 302 | 90 | ROM_REGION( 0x10000, "sound", ROMREGION_ERASEFF) |
| r3283 | r3284 | |
| 317 | 105 | ROM_REGION( 0x10000, "sound", ROMREGION_ERASEFF) |
| 318 | 106 | ROM_END |
| 319 | 107 | |
| 320 | | static DEVICE_IMAGE_UNLOAD( genesis_cart ) |
| 108 | |
| 109 | |
| 110 | /************************************* |
| 111 | * |
| 112 | * Handlers for custom mappers |
| 113 | * |
| 114 | *************************************/ |
| 115 | |
| 116 | /******* SRAM handling *******/ |
| 117 | |
| 118 | static READ16_HANDLER( genesis_sram_read ) |
| 321 | 119 | { |
| 322 | | /* Write out the battery file if necessary */ |
| 323 | | if ((genesis_sram != NULL) && (genesis_sram_len > 0)) |
| 120 | UINT16 retval = 0; |
| 121 | |
| 122 | offset <<= 1; |
| 123 | |
| 124 | if (genesis_sram_active) |
| 324 | 125 | { |
| 325 | | image_battery_save(image_from_devtype_and_index(IO_CARTSLOT, 0), genesis_sram, genesis_sram_len); |
| 126 | retval |= genesis_sram[offset] << 8; |
| 127 | retval |= genesis_sram[offset ^ 1] & 0xff; |
| 326 | 128 | } |
| 129 | |
| 130 | return retval; |
| 327 | 131 | } |
| 328 | 132 | |
| 329 | | static void genesis_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 133 | static WRITE16_HANDLER( genesis_sram_write ) |
| 330 | 134 | { |
| 331 | | /* cartslot */ |
| 332 | | switch(state) |
| 135 | offset <<= 1; |
| 136 | |
| 137 | if (!genesis_sram_readonly) |
| 333 | 138 | { |
| 334 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 335 | | case MESS_DEVINFO_INT_COUNT: info->i = 1; break; |
| 336 | | case MESS_DEVINFO_INT_MUST_BE_LOADED: info->i = 1; break; |
| 337 | | |
| 338 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 339 | | case MESS_DEVINFO_PTR_LOAD: info->load = DEVICE_IMAGE_LOAD_NAME(genesis_cart); break; |
| 340 | | case MESS_DEVINFO_PTR_UNLOAD: info->unload = DEVICE_IMAGE_UNLOAD_NAME(genesis_cart); break; |
| 341 | | |
| 342 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 343 | | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "smd,bin,md,gen"); break; |
| 344 | | |
| 345 | | default: cartslot_device_getinfo(devclass, state, info); break; |
| 139 | genesis_sram[offset] = data >> 8; |
| 140 | genesis_sram[offset ^ 1] = data & 0xff; |
| 346 | 141 | } |
| 347 | 142 | } |
| 348 | 143 | |
| 349 | | static SYSTEM_CONFIG_START(genesis) |
| 350 | | CONFIG_DEVICE(genesis_cartslot_getinfo) |
| 351 | | SYSTEM_CONFIG_END |
| 144 | static WRITE16_HANDLER( genesis_sram_toggle ) |
| 145 | { |
| 146 | /* unsure if this is actually supposed to toggle or just switch on? |
| 147 | * Yet to encounter game that utilizes |
| 148 | */ |
| 149 | genesis_sram_active = (data & 1) ? 1 : 0; |
| 150 | genesis_sram_readonly = (data & 2) ? 1 : 0; |
| 151 | } |
| 352 | 152 | |
| 153 | /**************************/ |
| 154 | |
| 353 | 155 | static WRITE16_HANDLER( genesis_ssf2_bank_w ) |
| 354 | 156 | { |
| 355 | 157 | static int lastoffset = -1,lastdata = -1; |
| r3283 | r3284 | |
| 829 | 631 | /* this probably should do more, like make Genesis V2 'die' if the SEGA string is not written promptly */ |
| 830 | 632 | } |
| 831 | 633 | |
| 832 | | static void genesis_machine_stop(running_machine *machine) |
| 833 | | { |
| 834 | | } |
| 835 | 634 | |
| 836 | | static DRIVER_INIT( gencommon ) |
| 837 | | { |
| 838 | | if (genesis_sram) |
| 839 | | { |
| 840 | | add_exit_callback(machine, genesis_machine_stop); |
| 841 | | } |
| 842 | | } |
| 843 | 635 | |
| 844 | | static DRIVER_INIT( genusa ) |
| 845 | | { |
| 846 | | DRIVER_INIT_CALL(gencommon); |
| 847 | | DRIVER_INIT_CALL(megadriv); |
| 848 | | } |
| 849 | | |
| 850 | | static DRIVER_INIT( geneur ) |
| 851 | | { |
| 852 | | DRIVER_INIT_CALL(gencommon); |
| 853 | | DRIVER_INIT_CALL(megadrie); |
| 854 | | } |
| 855 | | |
| 856 | | static DRIVER_INIT( genjpn ) |
| 857 | | { |
| 858 | | DRIVER_INIT_CALL(gencommon); |
| 859 | | DRIVER_INIT_CALL(megadrij); |
| 860 | | } |
| 861 | | |
| 862 | 636 | // only looks for == in the compare for LSB systems |
| 863 | 637 | static int allendianmemcmp(const void *s1, const void *s2, size_t n) |
| 864 | 638 | { |
| r3283 | r3284 | |
| 1216 | 990 | } |
| 1217 | 991 | |
| 1218 | 992 | |
| 993 | /************************************* |
| 994 | * |
| 995 | * Driver initialization |
| 996 | * |
| 997 | *************************************/ |
| 998 | |
| 999 | /* We add handlers for custom mappers to basic megadriv reset */ |
| 1000 | |
| 1219 | 1001 | static MACHINE_RESET( ms_megadriv ) |
| 1220 | 1002 | { |
| 1221 | 1003 | MACHINE_RESET_CALL( megadriv ); |
| r3283 | r3284 | |
| 1236 | 1018 | MDRV_MACHINE_RESET( ms_megadriv ) |
| 1237 | 1019 | MACHINE_DRIVER_END |
| 1238 | 1020 | |
| 1239 | | /*************************************************************************** |
| 1240 | | Pico Related |
| 1241 | 1021 | |
| 1242 | | ***************************************************************************/ |
| 1243 | 1022 | |
| 1244 | | ROM_START(picoe) |
| 1245 | | ROM_REGION(0x1415000, "main", ROMREGION_ERASEFF) |
| 1246 | | ROM_REGION( 0x10000, "sound", ROMREGION_ERASEFF) |
| 1247 | | ROM_END |
| 1023 | /************************************* |
| 1024 | * |
| 1025 | * Driver initialization |
| 1026 | * |
| 1027 | *************************************/ |
| 1248 | 1028 | |
| 1249 | | ROM_START(picou) |
| 1250 | | ROM_REGION(0x1415000, "main", ROMREGION_ERASEFF) |
| 1251 | | ROM_REGION( 0x10000, "sound", ROMREGION_ERASEFF) |
| 1252 | | ROM_END |
| 1029 | static void genesis_machine_stop(running_machine *machine) |
| 1030 | { |
| 1031 | } |
| 1253 | 1032 | |
| 1254 | | ROM_START(picoj) |
| 1255 | | ROM_REGION(0x1415000, "main", ROMREGION_ERASEFF) |
| 1256 | | ROM_REGION( 0x10000, "sound", ROMREGION_ERASEFF) |
| 1257 | | ROM_END |
| 1033 | static DRIVER_INIT( gencommon ) |
| 1034 | { |
| 1035 | if (genesis_sram) |
| 1036 | { |
| 1037 | add_exit_callback(machine, genesis_machine_stop); |
| 1038 | } |
| 1039 | } |
| 1258 | 1040 | |
| 1259 | | /* static DRIVER_INIT( picoeur ) */ |
| 1260 | | /* { */ |
| 1261 | | /* DRIVER_INIT_CALL(picoe); */ |
| 1262 | | /* } */ |
| 1041 | static DRIVER_INIT( genesis ) |
| 1042 | { |
| 1043 | DRIVER_INIT_CALL(gencommon); |
| 1044 | DRIVER_INIT_CALL(megadriv); |
| 1045 | } |
| 1263 | 1046 | |
| 1264 | | /* static DRIVER_INIT( picousa ) */ |
| 1265 | | /* { */ |
| 1266 | | /* DRIVER_INIT_CALL(picou); */ |
| 1267 | | /* } */ |
| 1047 | static DRIVER_INIT( md_eur ) |
| 1048 | { |
| 1049 | DRIVER_INIT_CALL(gencommon); |
| 1050 | DRIVER_INIT_CALL(megadrie); |
| 1051 | } |
| 1268 | 1052 | |
| 1269 | | /* static DRIVER_INIT( picojpn ) */ |
| 1270 | | /* { */ |
| 1271 | | /* DRIVER_INIT_CALL(picoj); */ |
| 1272 | | /* } */ |
| 1053 | static DRIVER_INIT( md_jpn ) |
| 1054 | { |
| 1055 | DRIVER_INIT_CALL(gencommon); |
| 1056 | DRIVER_INIT_CALL(megadrij); |
| 1057 | } |
| 1273 | 1058 | |
| 1274 | | /* static MACHINE_DRIVER_START( ms_pico ) */ |
| 1275 | | /* MDRV_IMPORT_FROM(pico) */ |
| 1276 | 1059 | |
| 1277 | | /* MDRV_MACHINE_RESET( ms_megadriv ) */ |
| 1278 | | /* MACHINE_DRIVER_END */ |
| 1060 | /************************************* |
| 1061 | * |
| 1062 | * Cart handling / |
| 1063 | * System configuration(s) |
| 1064 | * |
| 1065 | *************************************/ |
| 1279 | 1066 | |
| 1280 | 1067 | |
| 1281 | | /****************************************** PICO related ****************************************/ |
| 1068 | /******* SMD files detection *******/ |
| 1282 | 1069 | |
| 1070 | |
| 1071 | /* code taken directly from GoodGEN by Cowering */ |
| 1072 | static int genesis_isfunkySMD(unsigned char *buf,unsigned int len) |
| 1073 | { |
| 1074 | /* aq quiz */ |
| 1075 | if (!strncmp("UZ(-01 ", (const char *) &buf[0xf0], 8)) |
| 1076 | return 1; |
| 1077 | |
| 1078 | /* Phelios USA redump */ |
| 1079 | /* target earth */ |
| 1080 | /* klax (namcot) */ |
| 1081 | if (buf[0x2080] == ' ' && buf[0x0080] == 'S' && buf[0x2081] == 'E' && buf[0x0081] == 'G') |
| 1082 | return 1; |
| 1083 | |
| 1084 | /* jap baseball 94 */ |
| 1085 | if (!strncmp("OL R-AEAL", (const char *) &buf[0xf0], 9)) |
| 1086 | return 1; |
| 1087 | |
| 1088 | /* devilish Mahjong Tower */ |
| 1089 | if (!strncmp("optrEtranet", (const char *) &buf[0xf3], 11)) |
| 1090 | return 1; |
| 1091 | |
| 1092 | /* golden axe 2 beta */ |
| 1093 | if (buf[0x0100] == 0x3c && buf[0x0101] == 0 && buf[0x0102] == 0 && buf[0x0103] == 0x3c) |
| 1094 | return 1; |
| 1095 | |
| 1096 | /* omega race */ |
| 1097 | if (!strncmp("OEARC ", (const char *) &buf[0x90], 8)) |
| 1098 | return 1; |
| 1099 | |
| 1100 | /* budokan beta */ |
| 1101 | if ((len >= 0x6708+8) && !strncmp(" NTEBDKN", (const char *) &buf[0x6708], 8)) |
| 1102 | return 1; |
| 1103 | |
| 1104 | /* cdx pro 1.8 bios */ |
| 1105 | if (!strncmp("so fCXP", (const char *) &buf[0x2c0], 7)) |
| 1106 | return 1; |
| 1107 | |
| 1108 | /* ishido (hacked) */ |
| 1109 | if (!strncmp("sio-Wyo ", (const char *) &buf[0x0090], 8)) |
| 1110 | return 1; |
| 1111 | |
| 1112 | /* onslaught */ |
| 1113 | if (!strncmp("SS CAL ", (const char *) &buf[0x0088], 8)) |
| 1114 | return 1; |
| 1115 | |
| 1116 | /* tram terror pirate */ |
| 1117 | if ((len >= 0x3648 + 8) && !strncmp("SG NEPIE", (const char *) &buf[0x3648], 8)) |
| 1118 | return 1; |
| 1119 | |
| 1120 | /* breath of fire 3 chinese */ |
| 1121 | if (buf[0x0007] == 0x1c && buf[0x0008] == 0x0a && buf[0x0009] == 0xb8 && buf[0x000a] == 0x0a) |
| 1122 | return 1; |
| 1123 | |
| 1124 | /*tetris pirate */ |
| 1125 | if ((len >= 0x1cbe + 5) && !strncmp("@TTI>", (const char *) &buf[0x1cbe], 5)) |
| 1126 | return 1; |
| 1127 | |
| 1128 | return 0; |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | /* code taken directly from GoodGEN by Cowering */ |
| 1134 | static int genesis_isSMD(unsigned char *buf,unsigned int len) |
| 1135 | { |
| 1136 | if (buf[0x2080] == 'S' && buf[0x80] == 'E' && buf[0x2081] == 'G' && buf[0x81] == 'A') |
| 1137 | return 1; |
| 1138 | return genesis_isfunkySMD(buf,len); |
| 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | /******* Image loading *******/ |
| 1143 | |
| 1144 | static DEVICE_IMAGE_LOAD( genesis_cart ) |
| 1145 | { |
| 1146 | unsigned char *ROM, *rawROM, *tmpROMnew, *tmpROM, *secondhalf; |
| 1147 | int relocate, length, ptr, x; |
| 1148 | #ifdef LSB_FIRST |
| 1149 | unsigned char fliptemp; |
| 1150 | #endif |
| 1151 | |
| 1152 | genesis_sram = NULL; |
| 1153 | genesis_sram_start = genesis_sram_len = genesis_sram_active = genesis_sram_readonly = 0; |
| 1154 | |
| 1155 | rawROM = memory_region(image->machine, "main"); |
| 1156 | ROM = rawROM /*+ 512 */; |
| 1157 | |
| 1158 | length = image_fread(image, rawROM + 0x2000, 0x600000); |
| 1159 | logerror("image length = 0x%x\n", length); |
| 1160 | |
| 1161 | if (genesis_isSMD(&rawROM[0x2200],(unsigned)length)) /* is this a SMD file..? */ |
| 1162 | { |
| 1163 | tmpROMnew = ROM; |
| 1164 | tmpROM = ROM + 0x2000 + 512; |
| 1165 | |
| 1166 | for (ptr = 0; ptr < (0x500000) / (8192); ptr += 2) |
| 1167 | { |
| 1168 | for (x = 0; x < 8192; x++) |
| 1169 | { |
| 1170 | *tmpROMnew++ = *(tmpROM + ((ptr + 1) * 8192) + x); |
| 1171 | *tmpROMnew++ = *(tmpROM + ((ptr + 0) * 8192) + x); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | #ifdef LSB_FIRST |
| 1176 | tmpROMnew = ROM; |
| 1177 | for (ptr = 0; ptr < length; ptr += 2) |
| 1178 | { |
| 1179 | fliptemp = tmpROMnew[ptr]; |
| 1180 | tmpROMnew[ptr] = tmpROMnew[ptr+1]; |
| 1181 | tmpROMnew[ptr+1] = fliptemp; |
| 1182 | } |
| 1183 | #endif |
| 1184 | genesis_last_loaded_image_length = length - 512; |
| 1185 | memcpy(&ROM[VIRGIN_COPY_GEN],&ROM[0x000000],0x500000); /* store a copy of data for MACHINE_RESET processing */ |
| 1186 | |
| 1187 | relocate = 0; |
| 1188 | |
| 1189 | } |
| 1190 | else |
| 1191 | /* check if it's a MD file */ |
| 1192 | if ((rawROM[0x2080] == 'E') && |
| 1193 | (rawROM[0x2081] == 'A') && |
| 1194 | (rawROM[0x2082] == 'M' || rawROM[0x2082] == 'G')) /* is this a MD file..? */ |
| 1195 | { |
| 1196 | tmpROMnew = malloc(length); |
| 1197 | secondhalf = &tmpROMnew[length >> 1]; |
| 1198 | |
| 1199 | if (!tmpROMnew) |
| 1200 | { |
| 1201 | logerror("Memory allocation failed reading roms!\n"); |
| 1202 | goto bad; |
| 1203 | } |
| 1204 | |
| 1205 | memcpy(tmpROMnew, ROM + 0x2000, length); |
| 1206 | for (ptr = 0; ptr < length; ptr += 2) |
| 1207 | { |
| 1208 | |
| 1209 | ROM[ptr] = secondhalf[ptr >> 1]; |
| 1210 | ROM[ptr + 1] = tmpROMnew[ptr >> 1]; |
| 1211 | } |
| 1212 | free(tmpROMnew); |
| 1213 | |
| 1214 | #ifdef LSB_FIRST |
| 1215 | for (ptr = 0; ptr < length; ptr += 2) |
| 1216 | { |
| 1217 | fliptemp = ROM[ptr]; |
| 1218 | ROM[ptr] = ROM[ptr+1]; |
| 1219 | ROM[ptr+1] = fliptemp; |
| 1220 | } |
| 1221 | #endif |
| 1222 | genesis_last_loaded_image_length = length; |
| 1223 | memcpy(&ROM[VIRGIN_COPY_GEN],&ROM[0x000000],0x500000); /* store a copy of data for MACHINE_RESET processing */ |
| 1224 | relocate = 0; |
| 1225 | |
| 1226 | } |
| 1227 | else |
| 1228 | /* BIN it is, then */ |
| 1229 | { |
| 1230 | relocate = 0x2000; |
| 1231 | genesis_last_loaded_image_length = length; |
| 1232 | |
| 1233 | |
| 1234 | ROM = memory_region(image->machine, "main"); /* 68000 ROM region */ |
| 1235 | |
| 1236 | for (ptr = 0; ptr < 0x502000; ptr += 2) /* mangle bytes for littleendian machines */ |
| 1237 | { |
| 1238 | #ifdef LSB_FIRST |
| 1239 | int temp = ROM[relocate + ptr]; |
| 1240 | |
| 1241 | ROM[ptr] = ROM[relocate + ptr + 1]; |
| 1242 | ROM[ptr + 1] = temp; |
| 1243 | #else |
| 1244 | ROM[ptr] = ROM[relocate + ptr]; |
| 1245 | ROM[ptr + 1] = ROM[relocate + ptr + 1]; |
| 1246 | #endif |
| 1247 | } |
| 1248 | memcpy(&ROM[VIRGIN_COPY_GEN],&ROM[0x000000],0x500000); /* store a copy of data for MACHINE_RESET processing */ |
| 1249 | } |
| 1250 | return INIT_PASS; |
| 1251 | |
| 1252 | bad: |
| 1253 | return INIT_FAIL; |
| 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | /******* Image unloading (with SRAM saving) *******/ |
| 1258 | |
| 1259 | static DEVICE_IMAGE_UNLOAD( genesis_cart ) |
| 1260 | { |
| 1261 | /* Write out the battery file if necessary */ |
| 1262 | if ((genesis_sram != NULL) && (genesis_sram_len > 0)) |
| 1263 | { |
| 1264 | image_battery_save(image_from_devtype_and_index(IO_CARTSLOT, 0), genesis_sram, genesis_sram_len); |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | |
| 1269 | /******* Cart getinfo *******/ |
| 1270 | |
| 1271 | static void genesis_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 1272 | { |
| 1273 | /* cartslot */ |
| 1274 | switch(state) |
| 1275 | { |
| 1276 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1277 | case MESS_DEVINFO_INT_COUNT: info->i = 1; break; |
| 1278 | case MESS_DEVINFO_INT_MUST_BE_LOADED: info->i = 1; break; |
| 1279 | |
| 1280 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1281 | case MESS_DEVINFO_PTR_LOAD: info->load = DEVICE_IMAGE_LOAD_NAME(genesis_cart); break; |
| 1282 | case MESS_DEVINFO_PTR_UNLOAD: info->unload = DEVICE_IMAGE_UNLOAD_NAME(genesis_cart); break; |
| 1283 | |
| 1284 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1285 | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "smd,bin,md,gen"); break; |
| 1286 | |
| 1287 | default: cartslot_device_getinfo(devclass, state, info); break; |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | /******* System configuration *******/ |
| 1292 | |
| 1293 | static SYSTEM_CONFIG_START( genesis ) |
| 1294 | CONFIG_DEVICE(genesis_cartslot_getinfo) |
| 1295 | SYSTEM_CONFIG_END |
| 1296 | |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | /****************************************** PICO emulation ****************************************/ |
| 1301 | |
| 1283 | 1302 | /* |
| 1284 | 1303 | Pico Implementation By ElBarto (Emmanuel Vadot, elbarto@megadrive.org) |
| 1285 | 1304 | Still missing the PCM custom chip |
| r3283 | r3284 | |
| 1455 | 1474 | AM_RANGE(0xe00000 , 0xe0ffff) AM_WRITE(SMH_RAM) AM_MIRROR(0x1f0000) AM_BASE(&megadrive_ram) |
| 1456 | 1475 | ADDRESS_MAP_END |
| 1457 | 1476 | |
| 1477 | |
| 1458 | 1478 | INPUT_PORTS_START( pico ) |
| 1459 | 1479 | PORT_START("PAD") |
| 1460 | 1480 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1) |
| 1461 | 1481 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1) |
| 1462 | 1482 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1) |
| 1463 | 1483 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1) |
| 1464 | | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("RED BUTTON") |
| 1465 | | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("PEN BUTTON") |
| 1484 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("Red Button") |
| 1485 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("Pen Button") |
| 1466 | 1486 | |
| 1467 | 1487 | PORT_START("PAGE") |
| 1468 | 1488 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("Increment Page") |
| 1469 | 1489 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("Decrement Page") |
| 1470 | 1490 | |
| 1471 | 1491 | PORT_START("PENX") |
| 1472 | | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(70) PORT_KEYDELTA(30) PORT_MINMAX(0, 255) PORT_CATEGORY(5) PORT_PLAYER(1) PORT_NAME("PEN X") |
| 1492 | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(10) PORT_MINMAX(0, 255) PORT_CATEGORY(5) PORT_PLAYER(1) PORT_NAME("PEN X") |
| 1473 | 1493 | |
| 1474 | 1494 | PORT_START("PENY") |
| 1475 | | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(50) PORT_KEYDELTA(30) PORT_MINMAX(0,255 ) PORT_CATEGORY(5) PORT_PLAYER(1) PORT_NAME("PEN Y") |
| 1495 | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(30) PORT_KEYDELTA(10) PORT_MINMAX(0,255 ) PORT_CATEGORY(5) PORT_PLAYER(1) PORT_NAME("PEN Y") |
| 1476 | 1496 | |
| 1477 | | PORT_START("REGION") /* Buttons on Genesis Console */ |
| 1497 | PORT_START("REGION") |
| 1478 | 1498 | /* Region setting for Console */ |
| 1479 | 1499 | PORT_DIPNAME( 0x000f, 0x0000, DEF_STR( Region ) ) |
| 1480 | 1500 | PORT_DIPSETTING( 0x0000, "Use HazeMD Default Choice" ) |
| r3283 | r3284 | |
| 1483 | 1503 | PORT_DIPSETTING( 0x0003, "EUROPE (PAL, 50fps)" ) |
| 1484 | 1504 | INPUT_PORTS_END |
| 1485 | 1505 | |
| 1506 | |
| 1486 | 1507 | MACHINE_DRIVER_START( pico ) |
| 1487 | | /* MDRV_CPU_ADD_TAG("main", M68000, MASTER_CLOCK / 7) /\* 7.67 MHz *\/ */ |
| 1488 | | /* MDRV_CPU_PROGRAM_MAP(_pico_readmem,_pico_writemem) */ |
| 1489 | | /* /\* IRQs are handled via the timers *\/ */ |
| 1508 | MDRV_IMPORT_FROM(megadriv) |
| 1509 | MDRV_CPU_MODIFY("main") |
| 1510 | MDRV_CPU_PROGRAM_MAP(_pico_readmem,_pico_writemem) |
| 1490 | 1511 | |
| 1491 | | /* MDRV_CPU_ADD_TAG("sound", Z80, MASTER_CLOCK / 15) /\* 3.58 MHz *\/ */ |
| 1492 | | /* MDRV_CPU_PROGRAM_MAP(z80_readmem,z80_writemem) */ |
| 1493 | | /* MDRV_CPU_IO_MAP(z80_portmap,0) */ |
| 1494 | | /* /\* IRQ handled via the timers *\/ */ |
| 1512 | MDRV_MACHINE_RESET( ms_megadriv ) |
| 1513 | MACHINE_DRIVER_END |
| 1495 | 1514 | |
| 1496 | | /* MDRV_MACHINE_RESET(megadriv) */ |
| 1497 | 1515 | |
| 1498 | | /* MDRV_SCREEN_ADD("pico", RASTER) */ |
| 1499 | | /* MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB15) */ |
| 1500 | | /* MDRV_SCREEN_REFRESH_RATE(60) */ |
| 1501 | | /* MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) // Vblank handled manually. */ |
| 1502 | | /* MDRV_SCREEN_SIZE(64*8, 64*8) */ |
| 1503 | | /* MDRV_SCREEN_VISIBLE_AREA(0, 32*8-1, 0, 28*8-1) */ |
| 1504 | 1516 | |
| 1505 | | /* #ifndef MESS */ |
| 1506 | | /* MDRV_NVRAM_HANDLER(megadriv) */ |
| 1507 | | /* #endif */ |
| 1517 | ROM_START( pico ) |
| 1518 | ROM_REGION(0x1415000, "main", ROMREGION_ERASEFF) |
| 1519 | ROM_REGION( 0x10000, "sound", ROMREGION_ERASEFF) |
| 1520 | ROM_END |
| 1508 | 1521 | |
| 1509 | | /* MDRV_PALETTE_LENGTH(0x200) */ |
| 1522 | ROM_START( picou ) |
| 1523 | ROM_REGION(0x1415000, "main", ROMREGION_ERASEFF) |
| 1524 | ROM_REGION( 0x10000, "sound", ROMREGION_ERASEFF) |
| 1525 | ROM_END |
| 1510 | 1526 | |
| 1511 | | /* MDRV_VIDEO_START(megadriv) */ |
| 1512 | | /* MDRV_VIDEO_UPDATE(megadriv) /\* Copies a bitmap *\/ */ |
| 1513 | | /* MDRV_VIDEO_EOF(megadriv) /\* Used to Sync the timing *\/ */ |
| 1527 | ROM_START( picoj ) |
| 1528 | ROM_REGION(0x1415000, "main", ROMREGION_ERASEFF) |
| 1529 | ROM_REGION( 0x10000, "sound", ROMREGION_ERASEFF) |
| 1530 | ROM_END |
| 1514 | 1531 | |
| 1515 | | /* MDRV_SPEAKER_STANDARD_STEREO("left", "right") */ |
| 1516 | 1532 | |
| 1517 | | /* /\* sound hardware *\/ */ |
| 1518 | | /* MDRV_SOUND_ADD(SN76496, MASTER_CLOCK/15) */ |
| 1519 | | /* MDRV_SOUND_ROUTE(ALL_OUTPUTS, "left", 0.25) /\* 3.58 MHz *\/ */ |
| 1520 | | /* MDRV_SOUND_ROUTE(ALL_OUTPUTS, "right",0.25) /\* 3.58 MHz *\/ */ |
| 1521 | | MDRV_IMPORT_FROM(megadriv) |
| 1522 | | MDRV_CPU_MODIFY("main") |
| 1523 | | MDRV_CPU_PROGRAM_MAP(_pico_readmem,_pico_writemem) |
| 1524 | 1533 | |
| 1525 | | MDRV_MACHINE_RESET( ms_megadriv ) |
| 1526 | | MACHINE_DRIVER_END |
| 1527 | | |
| 1528 | | DRIVER_INIT( picoe ) |
| 1534 | static void pico_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 1529 | 1535 | { |
| 1530 | | DRIVER_INIT_CALL(gencommon); |
| 1531 | | DRIVER_INIT_CALL(megadrie); |
| 1532 | | } |
| 1536 | /* cartslot */ |
| 1537 | switch(state) |
| 1538 | { |
| 1539 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1540 | case MESS_DEVINFO_INT_COUNT: info->i = 1; break; |
| 1541 | case MESS_DEVINFO_INT_MUST_BE_LOADED: info->i = 1; break; |
| 1533 | 1542 | |
| 1534 | | DRIVER_INIT( picou ) |
| 1535 | | { |
| 1536 | | DRIVER_INIT_CALL(gencommon); |
| 1537 | | DRIVER_INIT_CALL(megadriv); |
| 1538 | | } |
| 1543 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1544 | case MESS_DEVINFO_PTR_LOAD: info->load = DEVICE_IMAGE_LOAD_NAME(genesis_cart); break; |
| 1545 | case MESS_DEVINFO_PTR_UNLOAD: info->unload = DEVICE_IMAGE_UNLOAD_NAME(genesis_cart); break; |
| 1539 | 1546 | |
| 1540 | | DRIVER_INIT( picoj ) |
| 1541 | | { |
| 1542 | | DRIVER_INIT_CALL(gencommon); |
| 1543 | | DRIVER_INIT_CALL(megadrij); |
| 1547 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1548 | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "bin"); break; |
| 1549 | |
| 1550 | default: cartslot_device_getinfo(devclass, state, info); break; |
| 1551 | } |
| 1544 | 1552 | } |
| 1545 | 1553 | |
| 1546 | | /****************************************** END PICO related ************************************/ |
| 1554 | static SYSTEM_CONFIG_START( pico ) |
| 1555 | CONFIG_DEVICE(pico_cartslot_getinfo) |
| 1556 | SYSTEM_CONFIG_END |
| 1547 | 1557 | |
| 1548 | 1558 | |
| 1559 | |
| 1549 | 1560 | /*************************************************************************** |
| 1550 | 1561 | |
| 1551 | 1562 | Game driver(s) |
| 1552 | 1563 | |
| 1553 | 1564 | ***************************************************************************/ |
| 1554 | 1565 | |
| 1555 | | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ |
| 1556 | | CONS( 1989, genesis, 0, 0, ms_megadriv, megadri6, genusa, genesis, "Sega", "Genesis (USA, NTSC)", 0) |
| 1557 | | CONS( 1993, gensvp, genesis, 0, ms_megdsvp, megdsvp, megadsvp, genesis, "Sega", "Genesis (USA, NTSC, w/SVP)", 0) |
| 1558 | | CONS( 1990, megadriv, genesis, 0, ms_megadriv, megadri6, geneur, genesis, "Sega", "Mega Drive (Europe, PAL)", 0) |
| 1559 | | CONS( 1988, megadrij, genesis, 0, ms_megadriv, megadri6, genjpn, genesis, "Sega", "Mega Drive (Japan, NTSC)", 0) |
| 1560 | | CONS( 1994, picoe, genesis, 0, pico, pico, picoe, genesis, "Sega", "Pico (Europe, PAL)", 0) |
| 1561 | | CONS( 1994, picou, genesis, 0, pico, pico, picou, genesis, "Sega", "Pico (USA, NTSC)", 0) |
| 1562 | | CONS( 1993, picoj, genesis, 0, pico, pico, picoj, genesis, "Sega", "Pico (Japan, NTSC)", 0) |
| 1566 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ |
| 1567 | CONS( 1989, genesis, 0, 0, ms_megadriv, megadri6, genesis, genesis, "Sega", "Genesis (USA, NTSC)", 0) |
| 1568 | CONS( 1993, gensvp, genesis, 0, ms_megdsvp, megdsvp, megadsvp, genesis, "Sega", "Genesis (USA, NTSC, w/SVP)", 0) |
| 1569 | CONS( 1990, megadriv, genesis, 0, ms_megadriv, megadri6, md_eur, genesis, "Sega", "Mega Drive (Europe, PAL)", 0) |
| 1570 | CONS( 1988, megadrij, genesis, 0, ms_megadriv, megadri6, md_jpn, genesis, "Sega", "Mega Drive (Japan, NTSC)", 0) |
| 1571 | CONS( 1994, pico, 0, 0, pico, pico, md_eur, pico, "Sega", "Pico (Europe, PAL)", 0) |
| 1572 | CONS( 1994, picou, pico, 0, pico, pico, genesis, pico, "Sega", "Pico (USA, NTSC)", 0) |
| 1573 | CONS( 1993, picoj, pico, 0, pico, pico, md_jpn, pico, "Sega", "Pico (Japan, NTSC)", 0) |