src/mess/machine/genesis.c
| r0 | r3295 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | genesis.c |
| 4 | |
| 5 | Machine file to handle emulation of the Sega Mega Drive & Genesis. |
| 6 | |
| 7 | |
| 8 | 2008-09: Moved here cart code and custom mapper handlers. Hopefully, |
| 9 | it will make painless the future merging with HazeMD |
| 10 | |
| 11 | ***************************************************************************/ |
| 12 | |
| 13 | |
| 14 | #include "driver.h" |
| 15 | #include "cpu/m68000/m68000.h" |
| 16 | |
| 17 | #include "devices/cartslot.h" |
| 18 | |
| 19 | static UINT16 squirrel_king_extra = 0; |
| 20 | static UINT16 lion2_prot1_data, lion2_prot2_data; |
| 21 | static UINT16 realtek_bank_addr=0, realtek_bank_size=0, realtek_old_bank_addr; |
| 22 | static UINT16 g_l3alt_pdat; |
| 23 | static UINT16 g_l3alt_pcmd; |
| 24 | |
| 25 | static int genesis_last_loaded_image_length = -1; |
| 26 | |
| 27 | |
| 28 | #define MAX_MD_CART_SIZE 0x500000 |
| 29 | |
| 30 | /* where a fresh copy of rom is stashed for reset and banking setup */ |
| 31 | #define VIRGIN_COPY_GEN 0xd00000 |
| 32 | |
| 33 | static UINT8 *genesis_sram; |
| 34 | static int genesis_sram_start; |
| 35 | static int genesis_sram_len = 0; |
| 36 | static int genesis_sram_active; |
| 37 | static int genesis_sram_readonly; |
| 38 | |
| 39 | |
| 40 | enum |
| 41 | { |
| 42 | STANDARD = 0, |
| 43 | SSF2, /* Super Street Fighter 2 */ |
| 44 | LIONK3, /* Lion King 3 */ |
| 45 | SKINGKONG, /* Super King Kong 99 */ |
| 46 | SDK99, /* Super Donkey Kong 99 */ |
| 47 | REDCLIFF, /* Romance of the Three Kingdoms - Battle of Red Cliffs, already decoded from .mdx format */ |
| 48 | RADICA, /* Radica TV games.. these probably should be a seperate driver since they are a seperate 'console' */ |
| 49 | KOF99, /* King of Fighters '99 */ |
| 50 | SOULBLAD, /* Soul Blade */ |
| 51 | MJLOVER, /* Mahjong Lover */ |
| 52 | SQUIRRELK, /* Squirrel King */ |
| 53 | SMOUSE, /* Smart Mouse */ |
| 54 | SMB, /* Super Mario Bros. */ |
| 55 | SMB2, /* Super Mario Bros. 2 */ |
| 56 | KAIJU, |
| 57 | CHINFIGHT3, /* Chinese Fighters 3 */ |
| 58 | LIONK2, /* Lion King 2 */ |
| 59 | BUGSLIFE, /* A Bug's Life */ |
| 60 | ELFWOR, /* Elf Wor */ |
| 61 | ROCKMANX3, /* Rockman X3 */ |
| 62 | SBUBBOB, /* Super Bubble Bobble */ |
| 63 | KOF98, /* King of Fighters '98 */ |
| 64 | REALTEC, /* Whac a Critter/Mallet legend, Defend the Earth, Funnyworld/Ballonboy */ |
| 65 | SUP19IN1, /* Super 19 in 1 */ |
| 66 | SUP15IN1, /* Super 15 in 1 */ |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | static int cart_type = STANDARD; |
| 71 | |
| 72 | |
| 73 | /************************************* |
| 74 | * |
| 75 | * Handlers for custom mappers |
| 76 | * |
| 77 | *************************************/ |
| 78 | |
| 79 | static WRITE16_HANDLER( genesis_ssf2_bank_w ) |
| 80 | { |
| 81 | static int lastoffset = -1,lastdata = -1; |
| 82 | UINT8 *ROM = memory_region(machine, "main"); |
| 83 | |
| 84 | if ((lastoffset != offset) || (lastdata != data)) { |
| 85 | lastoffset = offset; lastdata = data; |
| 86 | switch (offset<<1) |
| 87 | { |
| 88 | case 0x00: /* write protect register // this is not a write protect, but seems to do nothing useful but reset bank0 after the checksum test (red screen otherwise) */ |
| 89 | if (data == 2) { |
| 90 | memcpy(ROM + 0x000000, ROM + 0x400000+(((data&0xf)-2)*0x080000), 0x080000); |
| 91 | } |
| 92 | break; |
| 93 | case 0x02: /* 0x080000 - 0x0FFFFF */ |
| 94 | memcpy(ROM + 0x080000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 95 | break; |
| 96 | case 0x04: /* 0x100000 - 0x17FFFF */ |
| 97 | memcpy(ROM + 0x100000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 98 | break; |
| 99 | case 0x06: /* 0x180000 - 0x1FFFFF */ |
| 100 | memcpy(ROM + 0x180000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 101 | break; |
| 102 | case 0x08: /* 0x200000 - 0x27FFFF */ |
| 103 | memcpy(ROM + 0x200000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 104 | break; |
| 105 | case 0x0a: /* 0x280000 - 0x2FFFFF */ |
| 106 | memcpy(ROM + 0x280000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 107 | break; |
| 108 | case 0x0c: /* 0x300000 - 0x37FFFF */ |
| 109 | memcpy(ROM + 0x300000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 110 | break; |
| 111 | case 0x0e: /* 0x380000 - 0x3FFFFF */ |
| 112 | memcpy(ROM + 0x380000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 113 | break; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /*static WRITE16_HANDLER( g_l3alt_pdat_w ) |
| 119 | { |
| 120 | g_l3alt_pdat = data; |
| 121 | } |
| 122 | |
| 123 | static WRITE16_HANDLER( g_l3alt_pcmd_w ) |
| 124 | { |
| 125 | g_l3alt_pcmd = data; |
| 126 | } |
| 127 | */ |
| 128 | |
| 129 | static READ16_HANDLER( g_l3alt_prot_r ) |
| 130 | { |
| 131 | int retdata = 0; |
| 132 | |
| 133 | offset &=0x7; |
| 134 | |
| 135 | switch (offset) |
| 136 | { |
| 137 | |
| 138 | case 2: |
| 139 | |
| 140 | switch (g_l3alt_pcmd) |
| 141 | { |
| 142 | case 1: |
| 143 | retdata = g_l3alt_pdat>>1; |
| 144 | break; |
| 145 | |
| 146 | case 2: |
| 147 | retdata = g_l3alt_pdat>>4; |
| 148 | retdata |= (g_l3alt_pdat&0x0f)<<4; |
| 149 | break; |
| 150 | |
| 151 | default: |
| 152 | /* printf("unk prot case %d\n",g_l3alt_pcmd); */ |
| 153 | retdata = (((g_l3alt_pdat>>7)&1)<<0); |
| 154 | retdata |=(((g_l3alt_pdat>>6)&1)<<1); |
| 155 | retdata |=(((g_l3alt_pdat>>5)&1)<<2); |
| 156 | retdata |=(((g_l3alt_pdat>>4)&1)<<3); |
| 157 | retdata |=(((g_l3alt_pdat>>3)&1)<<4); |
| 158 | retdata |=(((g_l3alt_pdat>>2)&1)<<5); |
| 159 | retdata |=(((g_l3alt_pdat>>1)&1)<<6); |
| 160 | retdata |=(((g_l3alt_pdat>>0)&1)<<7); |
| 161 | break; |
| 162 | } |
| 163 | break; |
| 164 | |
| 165 | default: |
| 166 | |
| 167 | printf("protection read, unknown offset\n"); |
| 168 | break; |
| 169 | } |
| 170 | |
| 171 | /* printf("%06x: g_l3alt_pdat_w %04x g_l3alt_pcmd_w %04x return %04x\n",activecpu_get_pc(), g_l3alt_pdat,g_l3alt_pcmd,retdata); */ |
| 172 | |
| 173 | return retdata; |
| 174 | |
| 175 | } |
| 176 | |
| 177 | static WRITE16_HANDLER( g_l3alt_protw ) |
| 178 | { |
| 179 | offset &=0x7; |
| 180 | |
| 181 | switch (offset) |
| 182 | { |
| 183 | case 0x0: |
| 184 | g_l3alt_pdat = data; |
| 185 | break; |
| 186 | case 0x1: |
| 187 | g_l3alt_pcmd = data; |
| 188 | break; |
| 189 | default: |
| 190 | printf("protection write, unknown offst\n"); |
| 191 | break; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | static WRITE16_HANDLER( g_l3alt_bank_w ) |
| 196 | { |
| 197 | offset &=0x7; |
| 198 | |
| 199 | switch (offset) |
| 200 | { |
| 201 | case 0: |
| 202 | { |
| 203 | UINT8 *ROM = memory_region(machine, "main"); |
| 204 | /* printf("%06x data %04x\n",activecpu_get_pc(), data); */ |
| 205 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN + (data&0xffff)*0x8000], 0x8000); |
| 206 | } |
| 207 | break; |
| 208 | |
| 209 | default: |
| 210 | printf("unk bank w\n"); |
| 211 | break; |
| 212 | |
| 213 | } |
| 214 | |
| 215 | } |
| 216 | |
| 217 | |
| 218 | static WRITE16_HANDLER( realtec_402000_w ) |
| 219 | { |
| 220 | realtek_bank_addr = 0; |
| 221 | realtek_bank_size = (data>>8)&0x1f; |
| 222 | } |
| 223 | |
| 224 | static WRITE16_HANDLER( realtec_400000_w ) |
| 225 | { |
| 226 | int bankdata = (data >> 9) & 0x7; |
| 227 | |
| 228 | UINT8 *ROM = memory_region(machine, "main"); |
| 229 | |
| 230 | realtek_old_bank_addr = realtek_bank_addr; |
| 231 | realtek_bank_addr = (realtek_bank_addr & 0x7) | bankdata<<3; |
| 232 | |
| 233 | memcpy(ROM, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 234 | memcpy(ROM+ realtek_bank_size*0x20000, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 235 | } |
| 236 | |
| 237 | static WRITE16_HANDLER( realtec_404000_w ) |
| 238 | { |
| 239 | int bankdata = (data >> 8) & 0x3; |
| 240 | UINT8 *ROM = memory_region(machine, "main"); |
| 241 | |
| 242 | realtek_old_bank_addr = realtek_bank_addr; |
| 243 | realtek_bank_addr = (realtek_bank_addr & 0xf8)|bankdata; |
| 244 | |
| 245 | if (realtek_old_bank_addr != realtek_bank_addr) |
| 246 | { |
| 247 | memcpy(ROM, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 248 | memcpy(ROM+ realtek_bank_size*0x20000, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | static WRITE16_HANDLER( g_chifi3_bank_w ) |
| 253 | { |
| 254 | UINT8 *ROM = memory_region(machine, "main"); |
| 255 | |
| 256 | if (data==0xf100) // *hit player |
| 257 | { |
| 258 | int x; |
| 259 | for (x=0;x<0x100000;x+=0x10000) |
| 260 | { |
| 261 | memcpy(ROM + x, ROM + 0x410000, 0x10000); |
| 262 | } |
| 263 | } |
| 264 | else if (data==0xd700) // title screen.. |
| 265 | { |
| 266 | int x; |
| 267 | for (x=0;x<0x100000;x+=0x10000) |
| 268 | { |
| 269 | memcpy(ROM + x, ROM + 0x470000, 0x10000); |
| 270 | } |
| 271 | } |
| 272 | else if (data==0xd300) // character hits floor |
| 273 | { |
| 274 | int x; |
| 275 | for (x=0;x<0x100000;x+=0x10000) |
| 276 | { |
| 277 | memcpy(ROM + x, ROM + 0x430000, 0x10000); |
| 278 | } |
| 279 | } |
| 280 | else if (data==0x0000) |
| 281 | { |
| 282 | int x; |
| 283 | for (x=0;x<0x100000;x+=0x10000) |
| 284 | { |
| 285 | memcpy(ROM + x, ROM + 0x400000+x, 0x10000); |
| 286 | } |
| 287 | } |
| 288 | else |
| 289 | { |
| 290 | logerror("%06x chifi3, bankw? %04x %04x\n",activecpu_get_pc(), offset,data); |
| 291 | } |
| 292 | |
| 293 | } |
| 294 | |
| 295 | static READ16_HANDLER( g_chifi3_prot_r ) |
| 296 | { |
| 297 | UINT32 retdat; |
| 298 | |
| 299 | /* not 100% correct, there may be some relationship between the reads here |
| 300 | and the writes made at the start of the game.. */ |
| 301 | |
| 302 | /* |
| 303 | 04dc10 chifi3, prot_r? 2800 |
| 304 | 04cefa chifi3, prot_r? 65262 |
| 305 | */ |
| 306 | |
| 307 | if (activecpu_get_pc()==0x01782) // makes 'VS' screen appear |
| 308 | { |
| 309 | retdat = activecpu_get_reg(M68K_D3)&0xff; |
| 310 | retdat<<=8; |
| 311 | return retdat; |
| 312 | } |
| 313 | else if (activecpu_get_pc()==0x1c24) // background gfx etc. |
| 314 | { |
| 315 | retdat = activecpu_get_reg(M68K_D3)&0xff; |
| 316 | retdat<<=8; |
| 317 | return retdat; |
| 318 | } |
| 319 | else if (activecpu_get_pc()==0x10c4a) // unknown |
| 320 | { |
| 321 | return mame_rand(machine); |
| 322 | } |
| 323 | else if (activecpu_get_pc()==0x10c50) // unknown |
| 324 | { |
| 325 | return mame_rand(machine); |
| 326 | } |
| 327 | else if (activecpu_get_pc()==0x10c52) // relates to the game speed.. |
| 328 | { |
| 329 | retdat = activecpu_get_reg(M68K_D4)&0xff; |
| 330 | retdat<<=8; |
| 331 | return retdat; |
| 332 | } |
| 333 | else if (activecpu_get_pc()==0x061ae) |
| 334 | { |
| 335 | retdat = activecpu_get_reg(M68K_D3)&0xff; |
| 336 | retdat<<=8; |
| 337 | return retdat; |
| 338 | } |
| 339 | else if (activecpu_get_pc()==0x061b0) |
| 340 | { |
| 341 | retdat = activecpu_get_reg(M68K_D3)&0xff; |
| 342 | retdat<<=8; |
| 343 | return retdat; |
| 344 | } |
| 345 | else |
| 346 | { |
| 347 | logerror("%06x chifi3, prot_r? %04x\n",activecpu_get_pc(), offset); |
| 348 | } |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static WRITE16_HANDLER( s19in1_bank ) |
| 354 | { |
| 355 | UINT8 *ROM = memory_region(machine, "main"); |
| 356 | memcpy(ROM + 0x000000, ROM + 0x400000+((offset << 1)*0x10000), 0x80000); |
| 357 | } |
| 358 | |
| 359 | // Kaiju? (Pokemon Stadium) handler from HazeMD |
| 360 | static WRITE16_HANDLER( g_kaiju_bank_w ) |
| 361 | { |
| 362 | UINT8 *ROM = memory_region(machine, "main"); |
| 363 | memcpy(ROM + 0x000000, ROM + 0x400000+(data&0x7f)*0x8000, 0x8000); |
| 364 | } |
| 365 | |
| 366 | // Soulblade handler from HazeMD |
| 367 | static READ16_HANDLER( soulb_0x400006_r ) |
| 368 | { |
| 369 | return 0xf000; |
| 370 | } |
| 371 | |
| 372 | static READ16_HANDLER( soulb_0x400002_r ) |
| 373 | { |
| 374 | return 0x9800; |
| 375 | } |
| 376 | |
| 377 | static READ16_HANDLER( soulb_0x400004_r ) |
| 378 | { |
| 379 | return 0xc900; |
| 380 | } |
| 381 | |
| 382 | // Mahjong Lover handler from HazeMD |
| 383 | static READ16_HANDLER( mjlovr_prot_1_r ) |
| 384 | { |
| 385 | return 0x9000; |
| 386 | } |
| 387 | |
| 388 | static READ16_HANDLER( mjlovr_prot_2_r ) |
| 389 | { |
| 390 | return 0xd300; |
| 391 | } |
| 392 | |
| 393 | // Super Mario Bros handler from HazeMD |
| 394 | static READ16_HANDLER( smbro_prot_r ) |
| 395 | { |
| 396 | return 0xc; |
| 397 | } |
| 398 | |
| 399 | |
| 400 | // Smart Mouse handler from HazeMD |
| 401 | static READ16_HANDLER( smous_prot_r ) |
| 402 | { |
| 403 | switch (offset) |
| 404 | { |
| 405 | case 0: return 0x5500; |
| 406 | case 1: return 0x0f00; |
| 407 | case 2: return 0xaa00; |
| 408 | case 3: return 0xf000; |
| 409 | } |
| 410 | |
| 411 | return -1; |
| 412 | } |
| 413 | |
| 414 | // Super Bubble Bobble MD handler from HazeMD |
| 415 | static READ16_HANDLER( sbub_extra1_r ) |
| 416 | { |
| 417 | return 0x5500; |
| 418 | } |
| 419 | |
| 420 | static READ16_HANDLER( sbub_extra2_r ) |
| 421 | { |
| 422 | return 0x0f00; |
| 423 | } |
| 424 | |
| 425 | // KOF99 handler from HazeMD |
| 426 | static READ16_HANDLER( kof99_0xA13002_r ) |
| 427 | { |
| 428 | // write 02 to a13002.. shift right 1? |
| 429 | return 0x01; |
| 430 | } |
| 431 | |
| 432 | static READ16_HANDLER( kof99_00A1303E_r ) |
| 433 | { |
| 434 | // write 3e to a1303e.. shift right 1? |
| 435 | return 0x1f; |
| 436 | } |
| 437 | |
| 438 | static READ16_HANDLER( kof99_0xA13000_r ) |
| 439 | { |
| 440 | // no write, startup check, chinese message if != 0 |
| 441 | return 0x0; |
| 442 | } |
| 443 | |
| 444 | // Radica handler from HazeMD |
| 445 | |
| 446 | static READ16_HANDLER( radica_bank_select ) |
| 447 | { |
| 448 | int bank = offset&0x3f; |
| 449 | UINT8 *ROM = memory_region(machine, "main"); |
| 450 | memcpy(ROM, ROM + (bank*0x10000)+0x400000, 0x400000); |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | // ROTK Red Cliff handler from HazeMD |
| 455 | |
| 456 | static READ16_HANDLER( redclif_prot_r ) |
| 457 | { |
| 458 | return -0x56 << 8; |
| 459 | } |
| 460 | |
| 461 | static READ16_HANDLER( redclif_prot2_r ) |
| 462 | { |
| 463 | return 0x55 << 8; |
| 464 | } |
| 465 | |
| 466 | // Squirrel King handler from HazeMD, this does not give screen garbage like HazeMD compile If you reset it twice |
| 467 | static READ16_HANDLER( squirrel_king_extra_r ) |
| 468 | { |
| 469 | return squirrel_king_extra; |
| 470 | |
| 471 | } |
| 472 | static WRITE16_HANDLER( squirrel_king_extra_w ) |
| 473 | { |
| 474 | squirrel_king_extra = data; |
| 475 | } |
| 476 | |
| 477 | // Lion King 2 handler from HazeMD |
| 478 | static READ16_HANDLER( lion2_prot1_r ) |
| 479 | { |
| 480 | return lion2_prot1_data; |
| 481 | } |
| 482 | |
| 483 | static READ16_HANDLER( lion2_prot2_r ) |
| 484 | { |
| 485 | return lion2_prot2_data; |
| 486 | } |
| 487 | |
| 488 | static WRITE16_HANDLER ( lion2_prot1_w ) |
| 489 | { |
| 490 | lion2_prot1_data = data; |
| 491 | } |
| 492 | |
| 493 | static WRITE16_HANDLER ( lion2_prot2_w ) |
| 494 | { |
| 495 | lion2_prot2_data = data; |
| 496 | } |
| 497 | |
| 498 | // Rockman X3 handler from HazeMD |
| 499 | static READ16_HANDLER( rx3_extra_r ) |
| 500 | { |
| 501 | return 0xc; |
| 502 | } |
| 503 | |
| 504 | // King of Fighters 98 handler from HazeMD |
| 505 | static READ16_HANDLER( g_kof98_aa_r ) |
| 506 | { |
| 507 | return 0xaa00; |
| 508 | } |
| 509 | |
| 510 | static READ16_HANDLER( g_kof98_0a_r ) |
| 511 | { |
| 512 | return 0x0a00; |
| 513 | } |
| 514 | |
| 515 | static READ16_HANDLER( g_kof98_00_r ) |
| 516 | { |
| 517 | return 0x0000; |
| 518 | } |
| 519 | |
| 520 | // Super Mario Bros 2 handler from HazeMD |
| 521 | static READ16_HANDLER( smb2_extra_r ) |
| 522 | { |
| 523 | return 0xa; |
| 524 | } |
| 525 | |
| 526 | // Bug's Life handler from HazeMD |
| 527 | static READ16_HANDLER( bugl_extra_r ) |
| 528 | { |
| 529 | return 0x28; |
| 530 | } |
| 531 | |
| 532 | // Elf Wor handler from HazeMD (DFJustin says the title is 'Linghuan Daoshi Super Magician') |
| 533 | static READ16_HANDLER( elfwor_0x400000_r ) |
| 534 | { |
| 535 | return 0x5500; |
| 536 | } |
| 537 | |
| 538 | static READ16_HANDLER( elfwor_0x400002_r ) |
| 539 | { |
| 540 | return 0x0f00; |
| 541 | } |
| 542 | |
| 543 | static READ16_HANDLER( elfwor_0x400004_r ) |
| 544 | { |
| 545 | return 0xc900; |
| 546 | } |
| 547 | |
| 548 | static READ16_HANDLER( elfwor_0x400006_r ) |
| 549 | { |
| 550 | return 0x1800; |
| 551 | } |
| 552 | |
| 553 | static WRITE16_HANDLER( genesis_TMSS_bank_w ) |
| 554 | { |
| 555 | /* this probably should do more, like make Genesis V2 'die' if the SEGA string is not written promptly */ |
| 556 | } |
| 557 | |
| 558 | |
| 559 | |
| 560 | /************************************* |
| 561 | * |
| 562 | * Handlers for SRAM |
| 563 | * |
| 564 | *************************************/ |
| 565 | |
| 566 | |
| 567 | static READ16_HANDLER( genesis_sram_read ) |
| 568 | { |
| 569 | UINT16 retval = 0; |
| 570 | |
| 571 | offset <<= 1; |
| 572 | |
| 573 | if (genesis_sram_active) |
| 574 | { |
| 575 | retval |= genesis_sram[offset] << 8; |
| 576 | retval |= genesis_sram[offset ^ 1] & 0xff; |
| 577 | } |
| 578 | |
| 579 | return retval; |
| 580 | } |
| 581 | |
| 582 | static WRITE16_HANDLER( genesis_sram_write ) |
| 583 | { |
| 584 | offset <<= 1; |
| 585 | |
| 586 | if (!genesis_sram_readonly) |
| 587 | { |
| 588 | genesis_sram[offset] = data >> 8; |
| 589 | genesis_sram[offset ^ 1] = data & 0xff; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | static WRITE16_HANDLER( genesis_sram_toggle ) |
| 594 | { |
| 595 | /* unsure if this is actually supposed to toggle or just switch on? |
| 596 | * Yet to encounter game that utilizes |
| 597 | */ |
| 598 | genesis_sram_active = (data & 1) ? 1 : 0; |
| 599 | genesis_sram_readonly = (data & 2) ? 1 : 0; |
| 600 | } |
| 601 | |
| 602 | |
| 603 | |
| 604 | /************************************* |
| 605 | * |
| 606 | * Machine driver reset |
| 607 | * |
| 608 | *************************************/ |
| 609 | |
| 610 | |
| 611 | static void setup_megadriv_custom_mappers(running_machine *machine) |
| 612 | { |
| 613 | static int relocate = VIRGIN_COPY_GEN; |
| 614 | unsigned char *ROM; |
| 615 | UINT32 mirroraddr; |
| 616 | |
| 617 | ROM = memory_region(machine, "main"); |
| 618 | |
| 619 | if (cart_type == SSF2) |
| 620 | { |
| 621 | memcpy(&ROM[0x800000], &ROM[VIRGIN_COPY_GEN + 0x400000], 0x100000); |
| 622 | memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x400000); |
| 623 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x400000); |
| 624 | |
| 625 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa130f0, 0xa130ff, 0, 0, genesis_ssf2_bank_w); |
| 626 | } |
| 627 | |
| 628 | if (cart_type == LIONK3 || cart_type == SKINGKONG) |
| 629 | { |
| 630 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */ |
| 631 | memcpy(&ROM[0x200000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */ |
| 632 | |
| 633 | memory_install_readwrite16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw); |
| 634 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w); |
| 635 | } |
| 636 | |
| 637 | if (cart_type == SDK99) |
| 638 | { |
| 639 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x300000); /* default rom */ |
| 640 | memcpy(&ROM[0x300000], &ROM[VIRGIN_COPY_GEN], 0x100000); /* default rom */ |
| 641 | |
| 642 | memory_install_readwrite16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw); |
| 643 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w); |
| 644 | } |
| 645 | |
| 646 | if (cart_type == REDCLIFF) |
| 647 | { |
| 648 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, redclif_prot2_r); |
| 649 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, redclif_prot_r); |
| 650 | } |
| 651 | |
| 652 | if (cart_type == RADICA) |
| 653 | { |
| 654 | memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x400000); // keep a copy for later banking.. making use of huge ROM_REGION allocated to genesis driver |
| 655 | memcpy(&ROM[0x800000], &ROM[VIRGIN_COPY_GEN], 0x400000); // wraparound banking (from hazemd code) |
| 656 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x400000); |
| 657 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa1307f, 0, 0, radica_bank_select); |
| 658 | } |
| 659 | |
| 660 | if (cart_type == KOF99) |
| 661 | { |
| 662 | //memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x300000); |
| 663 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa13001, 0, 0, kof99_0xA13000_r); |
| 664 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13002, 0xa13003, 0, 0, kof99_0xA13002_r); |
| 665 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa1303e, 0xa1303f, 0, 0, kof99_00A1303E_r); |
| 666 | } |
| 667 | |
| 668 | if (cart_type == SOULBLAD) |
| 669 | { |
| 670 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, soulb_0x400002_r); |
| 671 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, soulb_0x400004_r); |
| 672 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400006, 0x400007, 0, 0, soulb_0x400006_r); |
| 673 | } |
| 674 | |
| 675 | if (cart_type == MJLOVER) |
| 676 | { |
| 677 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, mjlovr_prot_1_r); |
| 678 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x401000, 0x401001, 0, 0, mjlovr_prot_2_r); |
| 679 | } |
| 680 | |
| 681 | if (cart_type == SQUIRRELK) |
| 682 | { |
| 683 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, squirrel_king_extra_r); |
| 684 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, squirrel_king_extra_w); |
| 685 | } |
| 686 | |
| 687 | if (cart_type == SMOUSE) |
| 688 | { |
| 689 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, smous_prot_r); |
| 690 | } |
| 691 | |
| 692 | if (cart_type == SMB) |
| 693 | { |
| 694 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa13001, 0, 0, smbro_prot_r); |
| 695 | } |
| 696 | |
| 697 | if (cart_type == SMB2) |
| 698 | { |
| 699 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa13001, 0, 0, smb2_extra_r); |
| 700 | } |
| 701 | |
| 702 | if (cart_type == KAIJU) |
| 703 | { |
| 704 | memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x200000); |
| 705 | memcpy(&ROM[0x600000], &ROM[VIRGIN_COPY_GEN], 0x200000); |
| 706 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000); |
| 707 | |
| 708 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x700000, 0x7fffff, 0, 0, g_kaiju_bank_w); |
| 709 | } |
| 710 | |
| 711 | if (cart_type == CHINFIGHT3) |
| 712 | { |
| 713 | memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x200000); |
| 714 | memcpy(&ROM[0x600000], &ROM[VIRGIN_COPY_GEN], 0x200000); |
| 715 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000); |
| 716 | |
| 717 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x4fffff, 0, 0, g_chifi3_prot_r); |
| 718 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_chifi3_bank_w); |
| 719 | } |
| 720 | |
| 721 | if (cart_type == LIONK2) |
| 722 | { |
| 723 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, lion2_prot1_r); |
| 724 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400006, 0x400007, 0, 0, lion2_prot2_r); |
| 725 | memory_install_write16_handler(machine, 0,ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, lion2_prot1_w); |
| 726 | memory_install_write16_handler(machine, 0,ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, lion2_prot2_w); |
| 727 | } |
| 728 | |
| 729 | if (cart_type == BUGSLIFE) |
| 730 | { |
| 731 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa13001, 0, 0, bugl_extra_r); |
| 732 | } |
| 733 | |
| 734 | if (cart_type == ELFWOR) |
| 735 | { |
| 736 | /* It return (0x55 @ 0x400000 OR 0xc9 @ 0x400004) AND (0x0f @ 0x400002 OR 0x18 @ 0x400006). It is probably best to add handlers for all 4 addresses. */ |
| 737 | |
| 738 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, elfwor_0x400000_r); |
| 739 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, elfwor_0x400002_r); |
| 740 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, elfwor_0x400004_r); |
| 741 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400006, 0x400007, 0, 0, elfwor_0x400006_r); |
| 742 | } |
| 743 | |
| 744 | if (cart_type == ROCKMANX3) |
| 745 | { |
| 746 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa13001, 0, 0, rx3_extra_r); |
| 747 | } |
| 748 | |
| 749 | if (cart_type == SBUBBOB) |
| 750 | { |
| 751 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, sbub_extra1_r); |
| 752 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, sbub_extra2_r); |
| 753 | } |
| 754 | |
| 755 | if (cart_type == KOF98) |
| 756 | { |
| 757 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x480000, 0x480001, 0, 0, g_kof98_aa_r); |
| 758 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4800e0, 0x4800e1, 0, 0, g_kof98_aa_r); |
| 759 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4824a0, 0x4824a1, 0, 0, g_kof98_aa_r); |
| 760 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x488880, 0x488881, 0, 0, g_kof98_aa_r); |
| 761 | |
| 762 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4a8820, 0x4a8821, 0, 0, g_kof98_0a_r); |
| 763 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4f8820, 0x4f8821, 0, 0, g_kof98_00_r); |
| 764 | } |
| 765 | |
| 766 | if (cart_type == REALTEC) |
| 767 | { |
| 768 | realtek_old_bank_addr = -1; |
| 769 | |
| 770 | /* Realtec mapper!*/ |
| 771 | memcpy(&ROM[0x400000], &ROM[relocate], 0x80000); |
| 772 | |
| 773 | for (mirroraddr = 0; mirroraddr < 0x400000; mirroraddr += 0x2000) |
| 774 | { |
| 775 | memcpy(ROM + mirroraddr, ROM + relocate + 0x7e000, 0x002000); /* copy last 8kb across the whole rom region */ |
| 776 | } |
| 777 | |
| 778 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, realtec_400000_w); |
| 779 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x402000, 0x402001, 0, 0, realtec_402000_w); |
| 780 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x404000, 0x404001, 0, 0, realtec_404000_w); |
| 781 | } |
| 782 | |
| 783 | if (cart_type == SUP19IN1) |
| 784 | { |
| 785 | memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x400000); // allow hard reset to menu |
| 786 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa13039, 0, 0, s19in1_bank); |
| 787 | } |
| 788 | |
| 789 | if (cart_type == SUP15IN1) |
| 790 | { |
| 791 | memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x200000); // allow hard reset to menu |
| 792 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa13039, 0, 0, s19in1_bank); |
| 793 | } |
| 794 | |
| 795 | /* check if cart has battery save */ |
| 796 | genesis_sram_len = 0; |
| 797 | genesis_sram = NULL; |
| 798 | if (ROM[0x1b1] == 'R' && ROM[0x1b0] == 'A') |
| 799 | { |
| 800 | genesis_sram_start = (ROM[0x1b5] << 24 | ROM[0x1b4] << 16 | ROM[0x1b7] << 8 | ROM[0x1b6]); |
| 801 | genesis_sram_len = (ROM[0x1b9] << 24 | ROM[0x1b8] << 16 | ROM[0x1bb] << 8 | ROM[0x1ba]); |
| 802 | } |
| 803 | |
| 804 | if (genesis_sram_start != genesis_sram_len) |
| 805 | { |
| 806 | if (genesis_sram_start & 1) |
| 807 | genesis_sram_start -= 1; |
| 808 | |
| 809 | if (!(genesis_sram_len & 1)) |
| 810 | genesis_sram_len += 1; |
| 811 | |
| 812 | genesis_sram_len -= (genesis_sram_start - 1); |
| 813 | genesis_sram = auto_malloc (genesis_sram_len); |
| 814 | memset(genesis_sram, 0, genesis_sram_len); |
| 815 | image_battery_load(image_from_devtype_and_index(IO_CARTSLOT, 0), genesis_sram, genesis_sram_len); |
| 816 | |
| 817 | if (genesis_last_loaded_image_length - 0x200 < genesis_sram_start) |
| 818 | genesis_sram_active = 1; |
| 819 | |
| 820 | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, genesis_sram_start & 0x3fffff, (genesis_sram_start + genesis_sram_len - 1) & 0x3fffff, 0, 0, genesis_sram_read); |
| 821 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, genesis_sram_start & 0x3fffff, (genesis_sram_start + genesis_sram_len - 1) & 0x3fffff, 0, 0, genesis_sram_write); |
| 822 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa130f0, 0xa130f1, 0, 0, genesis_sram_toggle); |
| 823 | } |
| 824 | |
| 825 | |
| 826 | /* install NOP handler for TMSS */ |
| 827 | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa14000, 0xa14003, 0, 0, genesis_TMSS_bank_w); |
| 828 | } |
| 829 | |
| 830 | |
| 831 | MACHINE_RESET( md_mappers ) |
| 832 | { |
| 833 | setup_megadriv_custom_mappers(machine); |
| 834 | } |
| 835 | |
| 836 | |
| 837 | /************************************* |
| 838 | * |
| 839 | * Driver initialization |
| 840 | * |
| 841 | *************************************/ |
| 842 | |
| 843 | |
| 844 | static void genesis_machine_stop(running_machine *machine) |
| 845 | { |
| 846 | } |
| 847 | |
| 848 | DRIVER_INIT( gencommon ) |
| 849 | { |
| 850 | if (genesis_sram) |
| 851 | { |
| 852 | add_exit_callback(machine, genesis_machine_stop); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | |
| 857 | |
| 858 | /************************************* |
| 859 | * |
| 860 | * Cart handling |
| 861 | * |
| 862 | *************************************/ |
| 863 | |
| 864 | |
| 865 | /******* Memcmp for both endianness *******/ |
| 866 | |
| 867 | static int allendianmemcmp(const void *s1, const void *s2, size_t n) |
| 868 | { |
| 869 | const unsigned char *realbuf; |
| 870 | |
| 871 | #ifdef LSB_FIRST |
| 872 | unsigned char flippedbuf[64]; |
| 873 | unsigned int i; |
| 874 | |
| 875 | if ((n & 1) || (n > 63)) return -1 ; // don't want odd sized buffers or too large a compare |
| 876 | for (i = 0; i < n; i++) flippedbuf[i] = *((char *)s2 + (i ^ 1)); |
| 877 | realbuf = flippedbuf; |
| 878 | |
| 879 | #else |
| 880 | |
| 881 | realbuf = s2; |
| 882 | |
| 883 | #endif |
| 884 | return memcmp(s1,realbuf,n); |
| 885 | } |
| 886 | |
| 887 | |
| 888 | /******* SMD files detection *******/ |
| 889 | |
| 890 | /* code taken directly from GoodGEN by Cowering */ |
| 891 | static int genesis_is_funky_SMD(unsigned char *buf,unsigned int len) |
| 892 | { |
| 893 | /* aq quiz */ |
| 894 | if (!strncmp("UZ(-01 ", (const char *) &buf[0xf0], 8)) |
| 895 | return 1; |
| 896 | |
| 897 | /* Phelios USA redump */ |
| 898 | /* target earth */ |
| 899 | /* klax (namcot) */ |
| 900 | if (buf[0x2080] == ' ' && buf[0x0080] == 'S' && buf[0x2081] == 'E' && buf[0x0081] == 'G') |
| 901 | return 1; |
| 902 | |
| 903 | /* jap baseball 94 */ |
| 904 | if (!strncmp("OL R-AEAL", (const char *) &buf[0xf0], 9)) |
| 905 | return 1; |
| 906 | |
| 907 | /* devilish Mahjong Tower */ |
| 908 | if (!strncmp("optrEtranet", (const char *) &buf[0xf3], 11)) |
| 909 | return 1; |
| 910 | |
| 911 | /* golden axe 2 beta */ |
| 912 | if (buf[0x0100] == 0x3c && buf[0x0101] == 0 && buf[0x0102] == 0 && buf[0x0103] == 0x3c) |
| 913 | return 1; |
| 914 | |
| 915 | /* omega race */ |
| 916 | if (!strncmp("OEARC ", (const char *) &buf[0x90], 8)) |
| 917 | return 1; |
| 918 | |
| 919 | /* budokan beta */ |
| 920 | if ((len >= 0x6708+8) && !strncmp(" NTEBDKN", (const char *) &buf[0x6708], 8)) |
| 921 | return 1; |
| 922 | |
| 923 | /* cdx pro 1.8 bios */ |
| 924 | if (!strncmp("so fCXP", (const char *) &buf[0x2c0], 7)) |
| 925 | return 1; |
| 926 | |
| 927 | /* ishido (hacked) */ |
| 928 | if (!strncmp("sio-Wyo ", (const char *) &buf[0x0090], 8)) |
| 929 | return 1; |
| 930 | |
| 931 | /* onslaught */ |
| 932 | if (!strncmp("SS CAL ", (const char *) &buf[0x0088], 8)) |
| 933 | return 1; |
| 934 | |
| 935 | /* tram terror pirate */ |
| 936 | if ((len >= 0x3648 + 8) && !strncmp("SG NEPIE", (const char *) &buf[0x3648], 8)) |
| 937 | return 1; |
| 938 | |
| 939 | /* breath of fire 3 chinese */ |
| 940 | if (buf[0x0007] == 0x1c && buf[0x0008] == 0x0a && buf[0x0009] == 0xb8 && buf[0x000a] == 0x0a) |
| 941 | return 1; |
| 942 | |
| 943 | /*tetris pirate */ |
| 944 | if ((len >= 0x1cbe + 5) && !strncmp("@TTI>", (const char *) &buf[0x1cbe], 5)) |
| 945 | return 1; |
| 946 | |
| 947 | return 0; |
| 948 | } |
| 949 | |
| 950 | |
| 951 | |
| 952 | /* code taken directly from GoodGEN by Cowering */ |
| 953 | static int genesis_is_SMD(unsigned char *buf,unsigned int len) |
| 954 | { |
| 955 | if (buf[0x2080] == 'S' && buf[0x80] == 'E' && buf[0x2081] == 'G' && buf[0x81] == 'A') |
| 956 | return 1; |
| 957 | return genesis_is_funky_SMD(buf,len); |
| 958 | } |
| 959 | |
| 960 | |
| 961 | /******* Image loading *******/ |
| 962 | |
| 963 | static DEVICE_IMAGE_LOAD( genesis_cart ) |
| 964 | { |
| 965 | unsigned char *ROM, *rawROM, *tmpROMnew, *tmpROM, *secondhalf; |
| 966 | int relocate, length, ptr, x; |
| 967 | #ifdef LSB_FIRST |
| 968 | unsigned char fliptemp; |
| 969 | #endif |
| 970 | |
| 971 | genesis_sram = NULL; |
| 972 | genesis_sram_start = genesis_sram_len = genesis_sram_active = genesis_sram_readonly = 0; |
| 973 | |
| 974 | rawROM = memory_region(image->machine, "main"); |
| 975 | ROM = rawROM /*+ 512 */; |
| 976 | |
| 977 | length = image_fread(image, rawROM + 0x2000, 0x600000); |
| 978 | logerror("image length = 0x%x\n", length); |
| 979 | |
| 980 | /* is this a SMD file? */ |
| 981 | if (genesis_is_SMD(&rawROM[0x2200], (unsigned)length)) |
| 982 | { |
| 983 | tmpROMnew = ROM; |
| 984 | tmpROM = ROM + 0x2000 + 512; |
| 985 | |
| 986 | for (ptr = 0; ptr < MAX_MD_CART_SIZE / (8192); ptr += 2) |
| 987 | { |
| 988 | for (x = 0; x < 8192; x++) |
| 989 | { |
| 990 | *tmpROMnew++ = *(tmpROM + ((ptr + 1) * 8192) + x); |
| 991 | *tmpROMnew++ = *(tmpROM + ((ptr + 0) * 8192) + x); |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | #ifdef LSB_FIRST |
| 996 | tmpROMnew = ROM; |
| 997 | for (ptr = 0; ptr < length; ptr += 2) |
| 998 | { |
| 999 | fliptemp = tmpROMnew[ptr]; |
| 1000 | tmpROMnew[ptr] = tmpROMnew[ptr+1]; |
| 1001 | tmpROMnew[ptr+1] = fliptemp; |
| 1002 | } |
| 1003 | #endif |
| 1004 | genesis_last_loaded_image_length = length - 512; |
| 1005 | memcpy(&ROM[VIRGIN_COPY_GEN], &ROM[0x000000], MAX_MD_CART_SIZE); /* store a copy of data for MACHINE_RESET processing */ |
| 1006 | |
| 1007 | relocate = 0; |
| 1008 | |
| 1009 | } |
| 1010 | |
| 1011 | /* is this a MD file? */ |
| 1012 | else if ((rawROM[0x2080] == 'E') && (rawROM[0x2081] == 'A') && |
| 1013 | (rawROM[0x2082] == 'M' || rawROM[0x2082] == 'G')) |
| 1014 | { |
| 1015 | tmpROMnew = malloc(length); |
| 1016 | secondhalf = &tmpROMnew[length >> 1]; |
| 1017 | |
| 1018 | if (!tmpROMnew) |
| 1019 | { |
| 1020 | logerror("Memory allocation failed reading roms!\n"); |
| 1021 | return INIT_FAIL; |
| 1022 | } |
| 1023 | |
| 1024 | memcpy(tmpROMnew, ROM + 0x2000, length); |
| 1025 | for (ptr = 0; ptr < length; ptr += 2) |
| 1026 | { |
| 1027 | |
| 1028 | ROM[ptr] = secondhalf[ptr >> 1]; |
| 1029 | ROM[ptr + 1] = tmpROMnew[ptr >> 1]; |
| 1030 | } |
| 1031 | free(tmpROMnew); |
| 1032 | |
| 1033 | #ifdef LSB_FIRST |
| 1034 | for (ptr = 0; ptr < length; ptr += 2) |
| 1035 | { |
| 1036 | fliptemp = ROM[ptr]; |
| 1037 | ROM[ptr] = ROM[ptr+1]; |
| 1038 | ROM[ptr+1] = fliptemp; |
| 1039 | } |
| 1040 | #endif |
| 1041 | genesis_last_loaded_image_length = length; |
| 1042 | memcpy(&ROM[VIRGIN_COPY_GEN], &ROM[0x000000], MAX_MD_CART_SIZE); /* store a copy of data for MACHINE_RESET processing */ |
| 1043 | relocate = 0; |
| 1044 | |
| 1045 | } |
| 1046 | |
| 1047 | /* BIN it is, then */ |
| 1048 | else |
| 1049 | { |
| 1050 | relocate = 0x2000; |
| 1051 | genesis_last_loaded_image_length = length; |
| 1052 | |
| 1053 | for (ptr = 0; ptr < MAX_MD_CART_SIZE + relocate; ptr += 2) /* mangle bytes for little endian machines */ |
| 1054 | { |
| 1055 | #ifdef LSB_FIRST |
| 1056 | int temp = ROM[relocate + ptr]; |
| 1057 | |
| 1058 | ROM[ptr] = ROM[relocate + ptr + 1]; |
| 1059 | ROM[ptr + 1] = temp; |
| 1060 | #else |
| 1061 | ROM[ptr] = ROM[relocate + ptr]; |
| 1062 | ROM[ptr + 1] = ROM[relocate + ptr + 1]; |
| 1063 | #endif |
| 1064 | } |
| 1065 | |
| 1066 | memcpy(&ROM[VIRGIN_COPY_GEN], &ROM[0x000000], MAX_MD_CART_SIZE); /* store a copy of data for MACHINE_RESET processing */ |
| 1067 | } |
| 1068 | |
| 1069 | |
| 1070 | /* Detect carts which need additional handlers */ |
| 1071 | { |
| 1072 | static unsigned char smouse_sig[] = { 0x4d, 0xf9, 0x00, 0x40, 0x00, 0x02 }, |
| 1073 | mjlover_sig[] = { 0x13, 0xf9, 0x00, 0x40, 0x00, 0x00 }, // move.b ($400000).l,($FFFF0C).l (partial) |
| 1074 | squir_sig[] = { 0x26, 0x79, 0x00, 0xff, 0x00, 0xfa }, |
| 1075 | bugsl_sig[] = { 0x20, 0x12, 0x13, 0xc0, 0x00, 0xff }, |
| 1076 | sbub_sig[] = { 0x0c, 0x39, 0x00, 0x55, 0x00, 0x40 }, // cmpi.b #$55,($400000).l |
| 1077 | lk3_sig[] = { 0x0c, 0x01, 0x00, 0x30, 0x66, 0xe4 }, |
| 1078 | sdk_sig[] = { 0x48, 0xe7, 0xff, 0xfe, 0x52, 0x79 }, |
| 1079 | redcliff_sig[] = { 0x10, 0x39, 0x00, 0x40, 0x00, 0x04 }, // move.b ($400004).l,d0 |
| 1080 | smb_sig[] = { 0x20, 0x4d, 0x41, 0x52, 0x49, 0x4f }, |
| 1081 | smb2_sig[] = { 0x4e, 0xb9, 0x00, 0x0f, 0x25, 0x84 }, |
| 1082 | kaiju_sig[] = { 0x19, 0x7c, 0x00, 0x01, 0x00, 0x00 }, |
| 1083 | chifi3_sig[] = { 0xb6, 0x16, 0x66, 0x00, 0x00, 0x4a }, |
| 1084 | lionk2_sig[] = { 0x26, 0x79, 0x00, 0xff, 0x00, 0xf4 }, |
| 1085 | rx3_sig[] = { 0x66, 0x00, 0x00, 0x0e, 0x30, 0x3c }, |
| 1086 | kof98_sig[] = { 0x9b, 0xfc, 0x00, 0x00, 0x4a, 0x00 }, |
| 1087 | s15in1_sig[] = { 0x22, 0x3c, 0x00, 0xa1, 0x30, 0x00 }, |
| 1088 | kof99_sig[] = { 0x20, 0x3c, 0x30, 0x00, 0x00, 0xa1 }, // move.l #$300000A1,d0 |
| 1089 | radica_sig[] = { 0x4e, 0xd0, 0x30, 0x39, 0x00, 0xa1 }, // jmp (a0) move.w ($a130xx),d0 |
| 1090 | soulb_sig[] = { 0x33, 0xfc, 0x00, 0x0c, 0x00, 0xff }, // move.w #$C,($FF020A).l (what happens if check fails) |
| 1091 | s19in1_sig[] = { 0x13, 0xc0, 0x00, 0xa1, 0x30, 0x38 }; |
| 1092 | |
| 1093 | switch (genesis_last_loaded_image_length) |
| 1094 | { |
| 1095 | case 0x80000: |
| 1096 | if (!allendianmemcmp(&ROM[0x08c8], &smouse_sig[0], sizeof(smouse_sig))) |
| 1097 | cart_type = SMOUSE; |
| 1098 | |
| 1099 | if (!allendianmemcmp((char *)&ROM[0x7e30e], "SEGA", 4) || |
| 1100 | !allendianmemcmp((char *)&ROM[0x7e100], "SEGA", 4) || |
| 1101 | !allendianmemcmp((char *)&ROM[0x7e1e6], "SEGA", 4)) |
| 1102 | cart_type = REALTEC; |
| 1103 | break; |
| 1104 | |
| 1105 | case 0x100000: |
| 1106 | if (!allendianmemcmp(&ROM[0x01b24], &mjlover_sig[0], sizeof(mjlover_sig))) |
| 1107 | cart_type = MJLOVER; |
| 1108 | |
| 1109 | if (!allendianmemcmp(&ROM[0x03b4], &squir_sig[0], sizeof(squir_sig))) |
| 1110 | cart_type = SQUIRRELK; |
| 1111 | |
| 1112 | if (!allendianmemcmp(&ROM[0xee0d0], &bugsl_sig[0], sizeof(bugsl_sig))) |
| 1113 | cart_type = BUGSLIFE; |
| 1114 | |
| 1115 | if (!allendianmemcmp((char *)&ROM[0x0172], "GAME : ELF WOR", 14)) |
| 1116 | cart_type = ELFWOR; |
| 1117 | |
| 1118 | if (!allendianmemcmp(&ROM[0x123e4], &sbub_sig[0], sizeof(sbub_sig))) |
| 1119 | cart_type = SBUBBOB; |
| 1120 | break; |
| 1121 | |
| 1122 | case 0x200000: |
| 1123 | if (!allendianmemcmp(&ROM[0x18c6], &lk3_sig[0], sizeof(lk3_sig))) |
| 1124 | cart_type = LIONK3; |
| 1125 | |
| 1126 | if (!allendianmemcmp(&ROM[0x220], &sdk_sig[0], sizeof(sdk_sig))) |
| 1127 | cart_type = SKINGKONG; |
| 1128 | |
| 1129 | if (!allendianmemcmp(&ROM[0xce560], &redcliff_sig[0], sizeof(redcliff_sig))) |
| 1130 | cart_type = REDCLIFF; |
| 1131 | |
| 1132 | if (!allendianmemcmp(&ROM[0xc8cb0], &smb_sig[0], sizeof(smb_sig))) |
| 1133 | cart_type = SMB; |
| 1134 | |
| 1135 | if (!allendianmemcmp(&ROM[0xf24d6], &smb2_sig[0], sizeof(smb2_sig))) |
| 1136 | cart_type = SMB2; |
| 1137 | |
| 1138 | if (!allendianmemcmp(&ROM[0x674e], &kaiju_sig[0], sizeof(kaiju_sig))) |
| 1139 | cart_type = KAIJU; |
| 1140 | |
| 1141 | if (!allendianmemcmp(&ROM[0x1780], &chifi3_sig[0], sizeof(chifi3_sig))) |
| 1142 | cart_type = CHINFIGHT3; |
| 1143 | |
| 1144 | if (!allendianmemcmp(&ROM[0x03c2], &lionk2_sig[0], sizeof(lionk2_sig))) |
| 1145 | cart_type = LIONK2; |
| 1146 | |
| 1147 | if (!allendianmemcmp(&ROM[0xc8b90], &rx3_sig[0], sizeof(rx3_sig))) |
| 1148 | cart_type = ROCKMANX3; |
| 1149 | |
| 1150 | if (!allendianmemcmp(&ROM[0x56ae2], &kof98_sig[0], sizeof(kof98_sig))) |
| 1151 | cart_type = KOF98; |
| 1152 | |
| 1153 | if (!allendianmemcmp(&ROM[0x17bb2], &s15in1_sig[0], sizeof(s15in1_sig))) |
| 1154 | cart_type = SUP15IN1; |
| 1155 | break; |
| 1156 | |
| 1157 | case 0x300000: |
| 1158 | if (!allendianmemcmp(&ROM[0x220], &sdk_sig[0], sizeof(sdk_sig))) |
| 1159 | cart_type = SDK99; |
| 1160 | |
| 1161 | if (!allendianmemcmp(&ROM[0x1fd0d2], &kof99_sig[0], sizeof(kof99_sig))) |
| 1162 | cart_type = KOF99; |
| 1163 | break; |
| 1164 | |
| 1165 | case 0x400000: |
| 1166 | if (!allendianmemcmp(&ROM[0x3c031c], &radica_sig[0], sizeof(radica_sig)) || |
| 1167 | !allendianmemcmp(&ROM[0x3f031c], &radica_sig[0], sizeof(radica_sig))) // ssf+gng + radica vol1 |
| 1168 | cart_type = RADICA; |
| 1169 | |
| 1170 | if (!allendianmemcmp(&ROM[0x028460], &soulb_sig[0], sizeof(soulb_sig))) |
| 1171 | cart_type = SOULBLAD; |
| 1172 | |
| 1173 | if (!allendianmemcmp(&ROM[0x1e700], &s19in1_sig[0], sizeof(s19in1_sig))) |
| 1174 | cart_type = SUP19IN1; |
| 1175 | break; |
| 1176 | |
| 1177 | case 0x500000: |
| 1178 | if (!allendianmemcmp((char *)&ROM[0x0120], "SUPER STREET FIGHTER2 ", 22)) |
| 1179 | cart_type = SSF2; |
| 1180 | break; |
| 1181 | |
| 1182 | default: |
| 1183 | break; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | logerror("cart type: %d\n", cart_type); |
| 1188 | |
| 1189 | return INIT_PASS; |
| 1190 | } |
| 1191 | |
| 1192 | |
| 1193 | /******* Image unloading (with SRAM saving) *******/ |
| 1194 | |
| 1195 | static DEVICE_IMAGE_UNLOAD( genesis_cart ) |
| 1196 | { |
| 1197 | /* Write out the battery file if necessary */ |
| 1198 | if ((genesis_sram != NULL) && (genesis_sram_len > 0)) |
| 1199 | { |
| 1200 | image_battery_save(image_from_devtype_and_index(IO_CARTSLOT, 0), genesis_sram, genesis_sram_len); |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | |
| 1205 | /******* Cart getinfo *******/ |
| 1206 | |
| 1207 | void genesis_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 1208 | { |
| 1209 | /* cartslot */ |
| 1210 | switch(state) |
| 1211 | { |
| 1212 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1213 | case MESS_DEVINFO_INT_COUNT: info->i = 1; break; |
| 1214 | case MESS_DEVINFO_INT_MUST_BE_LOADED: info->i = 1; break; |
| 1215 | |
| 1216 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1217 | case MESS_DEVINFO_PTR_LOAD: info->load = DEVICE_IMAGE_LOAD_NAME(genesis_cart); break; |
| 1218 | case MESS_DEVINFO_PTR_UNLOAD: info->unload = DEVICE_IMAGE_UNLOAD_NAME(genesis_cart); break; |
| 1219 | |
| 1220 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1221 | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "smd,bin,md,gen"); break; |
| 1222 | |
| 1223 | default: cartslot_device_getinfo(devclass, state, info); break; |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | |
| 1228 | void pico_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 1229 | { |
| 1230 | /* cartslot */ |
| 1231 | switch(state) |
| 1232 | { |
| 1233 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1234 | case MESS_DEVINFO_INT_COUNT: info->i = 1; break; |
| 1235 | case MESS_DEVINFO_INT_MUST_BE_LOADED: info->i = 1; break; |
| 1236 | |
| 1237 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1238 | case MESS_DEVINFO_PTR_LOAD: info->load = DEVICE_IMAGE_LOAD_NAME(genesis_cart); break; |
| 1239 | case MESS_DEVINFO_PTR_UNLOAD: info->unload = DEVICE_IMAGE_UNLOAD_NAME(genesis_cart); break; |
| 1240 | |
| 1241 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1242 | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "bin"); break; |
| 1243 | |
| 1244 | default: cartslot_device_getinfo(devclass, state, info); break; |
| 1245 | } |
| 1246 | } |
src/mess/drivers/genesis.c
| r3294 | r3295 | |
| 50 | 50 | |
| 51 | 51 | #include "driver.h" |
| 52 | 52 | #include "sound/2612intf.h" |
| 53 | | #include "devices/cartslot.h" |
| 54 | 53 | #include "../../mame/drivers/megadriv.h" |
| 55 | | #include "cpu/m68000/m68000.h" |
| 54 | #include "deprecat.h" |
| 56 | 55 | |
| 57 | | static UINT16 squirrel_king_extra = 0; |
| 58 | | static UINT16 lion2_prot1_data, lion2_prot2_data; |
| 59 | | static UINT16 realtek_bank_addr=0, realtek_bank_size=0, realtek_old_bank_addr; |
| 60 | | static UINT16 g_l3alt_pdat; |
| 61 | | static UINT16 g_l3alt_pcmd; |
| 56 | /* cart device, custom mappers & sram init */ |
| 57 | #include "includes/genesis.h" |
| 62 | 58 | |
| 63 | | static int genesis_last_loaded_image_length = -1; |
| 64 | 59 | |
| 65 | 60 | static int megadrive_region_export = 0; |
| 66 | 61 | static int megadrive_region_pal = 0; |
| 67 | 62 | |
| 68 | | /* where a fresh copy of rom is stashed for reset and banking setup */ |
| 69 | | #define VIRGIN_COPY_GEN 0xd00000 |
| 70 | 63 | |
| 71 | | static UINT8 *genesis_sram; |
| 72 | | static int genesis_sram_start; |
| 73 | | static int genesis_sram_len = 0; |
| 74 | | static int genesis_sram_active; |
| 75 | | static int genesis_sram_readonly; |
| 76 | 64 | |
| 65 | /************************************* |
| 66 | * |
| 67 | * Machine driver |
| 68 | * |
| 69 | *************************************/ |
| 77 | 70 | |
| 71 | static MACHINE_RESET( ms_megadriv ) |
| 72 | { |
| 73 | MACHINE_RESET_CALL( megadriv ); |
| 74 | MACHINE_RESET_CALL( md_mappers ); |
| 75 | } |
| 78 | 76 | |
| 77 | static MACHINE_DRIVER_START( ms_megadriv ) |
| 78 | MDRV_IMPORT_FROM(megadriv) |
| 79 | |
| 80 | MDRV_MACHINE_RESET( ms_megadriv ) |
| 81 | MACHINE_DRIVER_END |
| 82 | |
| 83 | static MACHINE_DRIVER_START( ms_megdsvp ) |
| 84 | MDRV_IMPORT_FROM(megdsvp) |
| 85 | |
| 86 | MDRV_MACHINE_RESET( ms_megadriv ) |
| 87 | MACHINE_DRIVER_END |
| 88 | |
| 89 | |
| 90 | |
| 79 | 91 | /************************************* |
| 80 | 92 | * |
| 81 | 93 | * ROM definition(s) |
| r3294 | r3295 | |
| 109 | 121 | |
| 110 | 122 | /************************************* |
| 111 | 123 | * |
| 112 | | * Handlers for custom mappers |
| 113 | | * |
| 114 | | *************************************/ |
| 115 | | |
| 116 | | /******* SRAM handling *******/ |
| 117 | | |
| 118 | | static READ16_HANDLER( genesis_sram_read ) |
| 119 | | { |
| 120 | | UINT16 retval = 0; |
| 121 | | |
| 122 | | offset <<= 1; |
| 123 | | |
| 124 | | if (genesis_sram_active) |
| 125 | | { |
| 126 | | retval |= genesis_sram[offset] << 8; |
| 127 | | retval |= genesis_sram[offset ^ 1] & 0xff; |
| 128 | | } |
| 129 | | |
| 130 | | return retval; |
| 131 | | } |
| 132 | | |
| 133 | | static WRITE16_HANDLER( genesis_sram_write ) |
| 134 | | { |
| 135 | | offset <<= 1; |
| 136 | | |
| 137 | | if (!genesis_sram_readonly) |
| 138 | | { |
| 139 | | genesis_sram[offset] = data >> 8; |
| 140 | | genesis_sram[offset ^ 1] = data & 0xff; |
| 141 | | } |
| 142 | | } |
| 143 | | |
| 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 | | } |
| 152 | | |
| 153 | | /**************************/ |
| 154 | | |
| 155 | | static WRITE16_HANDLER( genesis_ssf2_bank_w ) |
| 156 | | { |
| 157 | | static int lastoffset = -1,lastdata = -1; |
| 158 | | UINT8 *ROM = memory_region(machine, "main"); |
| 159 | | |
| 160 | | if ((lastoffset != offset) || (lastdata != data)) { |
| 161 | | lastoffset = offset; lastdata = data; |
| 162 | | switch (offset<<1) |
| 163 | | { |
| 164 | | case 0x00: /* write protect register // this is not a write protect, but seems to do nothing useful but reset bank0 after the checksum test (red screen otherwise) */ |
| 165 | | if (data == 2) { |
| 166 | | memcpy(ROM + 0x000000, ROM + 0x400000+(((data&0xf)-2)*0x080000), 0x080000); |
| 167 | | } |
| 168 | | break; |
| 169 | | case 0x02: /* 0x080000 - 0x0FFFFF */ |
| 170 | | memcpy(ROM + 0x080000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 171 | | break; |
| 172 | | case 0x04: /* 0x100000 - 0x17FFFF */ |
| 173 | | memcpy(ROM + 0x100000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 174 | | break; |
| 175 | | case 0x06: /* 0x180000 - 0x1FFFFF */ |
| 176 | | memcpy(ROM + 0x180000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 177 | | break; |
| 178 | | case 0x08: /* 0x200000 - 0x27FFFF */ |
| 179 | | memcpy(ROM + 0x200000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 180 | | break; |
| 181 | | case 0x0a: /* 0x280000 - 0x2FFFFF */ |
| 182 | | memcpy(ROM + 0x280000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 183 | | break; |
| 184 | | case 0x0c: /* 0x300000 - 0x37FFFF */ |
| 185 | | memcpy(ROM + 0x300000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 186 | | break; |
| 187 | | case 0x0e: /* 0x380000 - 0x3FFFFF */ |
| 188 | | memcpy(ROM + 0x380000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 189 | | break; |
| 190 | | } |
| 191 | | } |
| 192 | | } |
| 193 | | |
| 194 | | /*static WRITE16_HANDLER( g_l3alt_pdat_w ) |
| 195 | | { |
| 196 | | g_l3alt_pdat = data; |
| 197 | | } |
| 198 | | |
| 199 | | static WRITE16_HANDLER( g_l3alt_pcmd_w ) |
| 200 | | { |
| 201 | | g_l3alt_pcmd = data; |
| 202 | | } |
| 203 | | */ |
| 204 | | |
| 205 | | static READ16_HANDLER( g_l3alt_prot_r ) |
| 206 | | { |
| 207 | | int retdata = 0; |
| 208 | | |
| 209 | | offset &=0x7; |
| 210 | | |
| 211 | | switch (offset) |
| 212 | | { |
| 213 | | |
| 214 | | case 2: |
| 215 | | |
| 216 | | switch (g_l3alt_pcmd) |
| 217 | | { |
| 218 | | case 1: |
| 219 | | retdata = g_l3alt_pdat>>1; |
| 220 | | break; |
| 221 | | |
| 222 | | case 2: |
| 223 | | retdata = g_l3alt_pdat>>4; |
| 224 | | retdata |= (g_l3alt_pdat&0x0f)<<4; |
| 225 | | break; |
| 226 | | |
| 227 | | default: |
| 228 | | /* printf("unk prot case %d\n",g_l3alt_pcmd); */ |
| 229 | | retdata = (((g_l3alt_pdat>>7)&1)<<0); |
| 230 | | retdata |=(((g_l3alt_pdat>>6)&1)<<1); |
| 231 | | retdata |=(((g_l3alt_pdat>>5)&1)<<2); |
| 232 | | retdata |=(((g_l3alt_pdat>>4)&1)<<3); |
| 233 | | retdata |=(((g_l3alt_pdat>>3)&1)<<4); |
| 234 | | retdata |=(((g_l3alt_pdat>>2)&1)<<5); |
| 235 | | retdata |=(((g_l3alt_pdat>>1)&1)<<6); |
| 236 | | retdata |=(((g_l3alt_pdat>>0)&1)<<7); |
| 237 | | break; |
| 238 | | } |
| 239 | | break; |
| 240 | | |
| 241 | | default: |
| 242 | | |
| 243 | | printf("protection read, unknown offset\n"); |
| 244 | | break; |
| 245 | | } |
| 246 | | |
| 247 | | /* printf("%06x: g_l3alt_pdat_w %04x g_l3alt_pcmd_w %04x return %04x\n",activecpu_get_pc(), g_l3alt_pdat,g_l3alt_pcmd,retdata); */ |
| 248 | | |
| 249 | | return retdata; |
| 250 | | |
| 251 | | } |
| 252 | | |
| 253 | | static WRITE16_HANDLER( g_l3alt_protw ) |
| 254 | | { |
| 255 | | offset &=0x7; |
| 256 | | |
| 257 | | switch (offset) |
| 258 | | { |
| 259 | | case 0x0: |
| 260 | | g_l3alt_pdat = data; |
| 261 | | break; |
| 262 | | case 0x1: |
| 263 | | g_l3alt_pcmd = data; |
| 264 | | break; |
| 265 | | default: |
| 266 | | printf("protection write, unknown offst\n"); |
| 267 | | break; |
| 268 | | } |
| 269 | | } |
| 270 | | |
| 271 | | static WRITE16_HANDLER( g_l3alt_bank_w ) |
| 272 | | { |
| 273 | | offset &=0x7; |
| 274 | | |
| 275 | | switch (offset) |
| 276 | | { |
| 277 | | case 0: |
| 278 | | { |
| 279 | | UINT8 *ROM = memory_region(machine, "main"); |
| 280 | | /* printf("%06x data %04x\n",activecpu_get_pc(), data); */ |
| 281 | | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN + (data&0xffff)*0x8000], 0x8000); |
| 282 | | } |
| 283 | | break; |
| 284 | | |
| 285 | | default: |
| 286 | | printf("unk bank w\n"); |
| 287 | | break; |
| 288 | | |
| 289 | | } |
| 290 | | |
| 291 | | } |
| 292 | | |
| 293 | | |
| 294 | | static WRITE16_HANDLER( realtec_402000_w ) |
| 295 | | { |
| 296 | | realtek_bank_addr = 0; |
| 297 | | realtek_bank_size = (data>>8)&0x1f; |
| 298 | | } |
| 299 | | |
| 300 | | static WRITE16_HANDLER( realtec_400000_w ) |
| 301 | | { |
| 302 | | int bankdata = (data >> 9) & 0x7; |
| 303 | | |
| 304 | | UINT8 *ROM = memory_region(machine, "main"); |
| 305 | | |
| 306 | | realtek_old_bank_addr = realtek_bank_addr; |
| 307 | | realtek_bank_addr = (realtek_bank_addr & 0x7) | bankdata<<3; |
| 308 | | |
| 309 | | memcpy(ROM, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 310 | | memcpy(ROM+ realtek_bank_size*0x20000, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 311 | | } |
| 312 | | |
| 313 | | static WRITE16_HANDLER( realtec_404000_w ) |
| 314 | | { |
| 315 | | int bankdata = (data >> 8) & 0x3; |
| 316 | | UINT8 *ROM = memory_region(machine, "main"); |
| 317 | | |
| 318 | | realtek_old_bank_addr = realtek_bank_addr; |
| 319 | | realtek_bank_addr = (realtek_bank_addr & 0xf8)|bankdata; |
| 320 | | |
| 321 | | if (realtek_old_bank_addr != realtek_bank_addr) |
| 322 | | { |
| 323 | | memcpy(ROM, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 324 | | memcpy(ROM+ realtek_bank_size*0x20000, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 325 | | } |
| 326 | | } |
| 327 | | |
| 328 | | static WRITE16_HANDLER( g_chifi3_bank_w ) |
| 329 | | { |
| 330 | | UINT8 *ROM = memory_region(machine, "main"); |
| 331 | | |
| 332 | | if (data==0xf100) // *hit player |
| 333 | | { |
| 334 | | int x; |
| 335 | | for (x=0;x<0x100000;x+=0x10000) |
| 336 | | { |
| 337 | | memcpy(ROM + x, ROM + 0x410000, 0x10000); |
| 338 | | } |
| 339 | | } |
| 340 | | else if (data==0xd700) // title screen.. |
| 341 | | { |
| 342 | | int x; |
| 343 | | for (x=0;x<0x100000;x+=0x10000) |
| 344 | | { |
| 345 | | memcpy(ROM + x, ROM + 0x470000, 0x10000); |
| 346 | | } |
| 347 | | } |
| 348 | | else if (data==0xd300) // character hits floor |
| 349 | | { |
| 350 | | int x; |
| 351 | | for (x=0;x<0x100000;x+=0x10000) |
| 352 | | { |
| 353 | | memcpy(ROM + x, ROM + 0x430000, 0x10000); |
| 354 | | } |
| 355 | | } |
| 356 | | else if (data==0x0000) |
| 357 | | { |
| 358 | | int x; |
| 359 | | for (x=0;x<0x100000;x+=0x10000) |
| 360 | | { |
| 361 | | memcpy(ROM + x, ROM + 0x400000+x, 0x10000); |
| 362 | | } |
| 363 | | } |
| 364 | | else |
| 365 | | { |
| 366 | | logerror("%06x chifi3, bankw? %04x %04x\n",activecpu_get_pc(), offset,data); |
| 367 | | } |
| 368 | | |
| 369 | | } |
| 370 | | |
| 371 | | static READ16_HANDLER( g_chifi3_prot_r ) |
| 372 | | { |
| 373 | | UINT32 retdat; |
| 374 | | |
| 375 | | /* not 100% correct, there may be some relationship between the reads here |
| 376 | | and the writes made at the start of the game.. */ |
| 377 | | |
| 378 | | /* |
| 379 | | 04dc10 chifi3, prot_r? 2800 |
| 380 | | 04cefa chifi3, prot_r? 65262 |
| 381 | | */ |
| 382 | | |
| 383 | | if (activecpu_get_pc()==0x01782) // makes 'VS' screen appear |
| 384 | | { |
| 385 | | retdat = activecpu_get_reg(M68K_D3)&0xff; |
| 386 | | retdat<<=8; |
| 387 | | return retdat; |
| 388 | | } |
| 389 | | else if (activecpu_get_pc()==0x1c24) // background gfx etc. |
| 390 | | { |
| 391 | | retdat = activecpu_get_reg(M68K_D3)&0xff; |
| 392 | | retdat<<=8; |
| 393 | | return retdat; |
| 394 | | } |
| 395 | | else if (activecpu_get_pc()==0x10c4a) // unknown |
| 396 | | { |
| 397 | | return mame_rand(machine); |
| 398 | | } |
| 399 | | else if (activecpu_get_pc()==0x10c50) // unknown |
| 400 | | { |
| 401 | | return mame_rand(machine); |
| 402 | | } |
| 403 | | else if (activecpu_get_pc()==0x10c52) // relates to the game speed.. |
| 404 | | { |
| 405 | | retdat = activecpu_get_reg(M68K_D4)&0xff; |
| 406 | | retdat<<=8; |
| 407 | | return retdat; |
| 408 | | } |
| 409 | | else if (activecpu_get_pc()==0x061ae) |
| 410 | | { |
| 411 | | retdat = activecpu_get_reg(M68K_D3)&0xff; |
| 412 | | retdat<<=8; |
| 413 | | return retdat; |
| 414 | | } |
| 415 | | else if (activecpu_get_pc()==0x061b0) |
| 416 | | { |
| 417 | | retdat = activecpu_get_reg(M68K_D3)&0xff; |
| 418 | | retdat<<=8; |
| 419 | | return retdat; |
| 420 | | } |
| 421 | | else |
| 422 | | { |
| 423 | | logerror("%06x chifi3, prot_r? %04x\n",activecpu_get_pc(), offset); |
| 424 | | } |
| 425 | | |
| 426 | | return 0; |
| 427 | | } |
| 428 | | |
| 429 | | static WRITE16_HANDLER( s19in1_bank ) |
| 430 | | { |
| 431 | | UINT8 *ROM = memory_region(machine, "main"); |
| 432 | | memcpy(ROM + 0x000000, ROM + 0x400000+((offset << 1)*0x10000), 0x80000); |
| 433 | | } |
| 434 | | |
| 435 | | // Kaiju? (Pokemon Stadium) handler from HazeMD |
| 436 | | static WRITE16_HANDLER( g_kaiju_bank_w ) |
| 437 | | { |
| 438 | | UINT8 *ROM = memory_region(machine, "main"); |
| 439 | | memcpy(ROM + 0x000000, ROM + 0x400000+(data&0x7f)*0x8000, 0x8000); |
| 440 | | } |
| 441 | | |
| 442 | | // Soulblade handler from HazeMD |
| 443 | | static READ16_HANDLER( soulb_0x400006_r ) |
| 444 | | { |
| 445 | | return 0xf000; |
| 446 | | } |
| 447 | | |
| 448 | | static READ16_HANDLER( soulb_0x400002_r ) |
| 449 | | { |
| 450 | | return 0x9800; |
| 451 | | } |
| 452 | | |
| 453 | | static READ16_HANDLER( soulb_0x400004_r ) |
| 454 | | { |
| 455 | | return 0xc900; |
| 456 | | } |
| 457 | | |
| 458 | | // Mahjong Lover handler from HazeMD |
| 459 | | static READ16_HANDLER( mjlovr_prot_1_r ) |
| 460 | | { |
| 461 | | return 0x9000; |
| 462 | | } |
| 463 | | |
| 464 | | static READ16_HANDLER( mjlovr_prot_2_r ) |
| 465 | | { |
| 466 | | return 0xd300; |
| 467 | | } |
| 468 | | |
| 469 | | // Super Mario Bros handler from HazeMD |
| 470 | | static READ16_HANDLER( smbro_prot_r ) |
| 471 | | { |
| 472 | | return 0xc; |
| 473 | | } |
| 474 | | |
| 475 | | |
| 476 | | // Smart Mouse handler from HazeMD |
| 477 | | static READ16_HANDLER( smous_prot_r ) |
| 478 | | { |
| 479 | | switch (offset) |
| 480 | | { |
| 481 | | case 0: return 0x5500; |
| 482 | | case 1: return 0x0f00; |
| 483 | | case 2: return 0xaa00; |
| 484 | | case 3: return 0xf000; |
| 485 | | } |
| 486 | | |
| 487 | | return -1; |
| 488 | | } |
| 489 | | |
| 490 | | // Super Bubble Bobble MD handler from HazeMD |
| 491 | | static READ16_HANDLER( sbub_extra1_r ) |
| 492 | | { |
| 493 | | return 0x5500; |
| 494 | | } |
| 495 | | |
| 496 | | static READ16_HANDLER( sbub_extra2_r ) |
| 497 | | { |
| 498 | | return 0x0f00; |
| 499 | | } |
| 500 | | |
| 501 | | // KOF99 handler from HazeMD |
| 502 | | static READ16_HANDLER( kof99_0xA13002_r ) |
| 503 | | { |
| 504 | | // write 02 to a13002.. shift right 1? |
| 505 | | return 0x01; |
| 506 | | } |
| 507 | | |
| 508 | | static READ16_HANDLER( kof99_00A1303E_r ) |
| 509 | | { |
| 510 | | // write 3e to a1303e.. shift right 1? |
| 511 | | return 0x1f; |
| 512 | | } |
| 513 | | |
| 514 | | static READ16_HANDLER( kof99_0xA13000_r ) |
| 515 | | { |
| 516 | | // no write, startup check, chinese message if != 0 |
| 517 | | return 0x0; |
| 518 | | } |
| 519 | | |
| 520 | | // Radica handler from HazeMD |
| 521 | | |
| 522 | | static READ16_HANDLER( radica_bank_select ) |
| 523 | | { |
| 524 | | int bank = offset&0x3f; |
| 525 | | UINT8 *ROM = memory_region(machine, "main"); |
| 526 | | memcpy(ROM, ROM + (bank*0x10000)+0x400000, 0x400000); |
| 527 | | return 0; |
| 528 | | } |
| 529 | | |
| 530 | | // ROTK Red Cliff handler from HazeMD |
| 531 | | |
| 532 | | static READ16_HANDLER( redclif_prot_r ) |
| 533 | | { |
| 534 | | return -0x56 << 8; |
| 535 | | } |
| 536 | | |
| 537 | | static READ16_HANDLER( redclif_prot2_r ) |
| 538 | | { |
| 539 | | return 0x55 << 8; |
| 540 | | } |
| 541 | | |
| 542 | | // Squirrel King handler from HazeMD, this does not give screen garbage like HazeMD compile If you reset it twice |
| 543 | | static READ16_HANDLER( squirrel_king_extra_r ) |
| 544 | | { |
| 545 | | return squirrel_king_extra; |
| 546 | | |
| 547 | | } |
| 548 | | static WRITE16_HANDLER( squirrel_king_extra_w ) |
| 549 | | { |
| 550 | | squirrel_king_extra = data; |
| 551 | | } |
| 552 | | |
| 553 | | // Lion King 2 handler from HazeMD |
| 554 | | static READ16_HANDLER( lion2_prot1_r ) |
| 555 | | { |
| 556 | | return lion2_prot1_data; |
| 557 | | } |
| 558 | | |
| 559 | | static READ16_HANDLER( lion2_prot2_r ) |
| 560 | | { |
| 561 | | return lion2_prot2_data; |
| 562 | | } |
| 563 | | |
| 564 | | static WRITE16_HANDLER ( lion2_prot1_w ) |
| 565 | | { |
| 566 | | lion2_prot1_data = data; |
| 567 | | } |
| 568 | | |
| 569 | | static WRITE16_HANDLER ( lion2_prot2_w ) |
| 570 | | { |
| 571 | | lion2_prot2_data = data; |
| 572 | | } |
| 573 | | |
| 574 | | // Rockman X3 handler from HazeMD |
| 575 | | static READ16_HANDLER( rx3_extra_r ) |
| 576 | | { |
| 577 | | return 0xc; |
| 578 | | } |
| 579 | | |
| 580 | | // King of Fighters 98 handler from HazeMD |
| 581 | | static READ16_HANDLER( g_kof98_aa_r ) |
| 582 | | { |
| 583 | | return 0xaa00; |
| 584 | | } |
| 585 | | |
| 586 | | static READ16_HANDLER( g_kof98_0a_r ) |
| 587 | | { |
| 588 | | return 0x0a00; |
| 589 | | } |
| 590 | | |
| 591 | | static READ16_HANDLER( g_kof98_00_r ) |
| 592 | | { |
| 593 | | return 0x0000; |
| 594 | | } |
| 595 | | |
| 596 | | // Super Mario Bros 2 handler from HazeMD |
| 597 | | static READ16_HANDLER( smb2_extra_r ) |
| 598 | | { |
| 599 | | return 0xa; |
| 600 | | } |
| 601 | | |
| 602 | | // Bug's Life handler from HazeMD |
| 603 | | static READ16_HANDLER( bugl_extra_r ) |
| 604 | | { |
| 605 | | return 0x28; |
| 606 | | } |
| 607 | | |
| 608 | | // Elf Wor handler from HazeMD (DFJustin says the title is 'Linghuan Daoshi Super Magician') |
| 609 | | static READ16_HANDLER( elfwor_0x400000_r ) |
| 610 | | { |
| 611 | | return 0x5500; |
| 612 | | } |
| 613 | | |
| 614 | | static READ16_HANDLER( elfwor_0x400002_r ) |
| 615 | | { |
| 616 | | return 0x0f00; |
| 617 | | } |
| 618 | | |
| 619 | | static READ16_HANDLER( elfwor_0x400004_r ) |
| 620 | | { |
| 621 | | return 0xc900; |
| 622 | | } |
| 623 | | |
| 624 | | static READ16_HANDLER( elfwor_0x400006_r ) |
| 625 | | { |
| 626 | | return 0x1800; |
| 627 | | } |
| 628 | | |
| 629 | | static WRITE16_HANDLER( genesis_TMSS_bank_w ) |
| 630 | | { |
| 631 | | /* this probably should do more, like make Genesis V2 'die' if the SEGA string is not written promptly */ |
| 632 | | } |
| 633 | | |
| 634 | | |
| 635 | | |
| 636 | | // only looks for == in the compare for LSB systems |
| 637 | | static int allendianmemcmp(const void *s1, const void *s2, size_t n) |
| 638 | | { |
| 639 | | const unsigned char *realbuf; |
| 640 | | |
| 641 | | #ifdef LSB_FIRST |
| 642 | | unsigned char flippedbuf[64]; |
| 643 | | unsigned int i; |
| 644 | | |
| 645 | | if ((n & 1) || (n > 63)) return -1 ; // don't want odd sized buffers or too large a compare |
| 646 | | for (i = 0; i < n; i++) flippedbuf[i] = *((char *)s2 + (i ^ 1)); |
| 647 | | realbuf = flippedbuf; |
| 648 | | |
| 649 | | #else |
| 650 | | |
| 651 | | realbuf = s2; |
| 652 | | |
| 653 | | #endif |
| 654 | | return memcmp(s1,realbuf,n); |
| 655 | | } |
| 656 | | |
| 657 | | void setup_megadriv_custom_mappers(running_machine *machine) |
| 658 | | { |
| 659 | | static int relocate = VIRGIN_COPY_GEN; |
| 660 | | unsigned char *ROM; |
| 661 | | UINT32 mirroraddr; |
| 662 | | |
| 663 | | ROM = memory_region(machine, "main"); |
| 664 | | |
| 665 | | if (genesis_last_loaded_image_length == 0x500000 && !allendianmemcmp((char *)&ROM[0x0120+relocate], "SUPER STREET FIGHTER2 ", 22)) |
| 666 | | { |
| 667 | | memcpy(&ROM[0x800000],&ROM[VIRGIN_COPY_GEN+0x400000],0x100000); |
| 668 | | memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x400000); |
| 669 | | memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x400000); |
| 670 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA130F0, 0xA130FF, 0, 0, genesis_ssf2_bank_w); |
| 671 | | } |
| 672 | | /* Lion King 3 */ |
| 673 | | if (genesis_last_loaded_image_length == 0x200000) |
| 674 | | { |
| 675 | | static unsigned char lk3sig[] = { 0x0c, 0x01, 0x00, 0x30, 0x66, 0xe4}; |
| 676 | | if (!allendianmemcmp(&ROM[0x18c6+relocate],&lk3sig[0],sizeof(lk3sig))) |
| 677 | | { |
| 678 | | |
| 679 | | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */ |
| 680 | | memcpy(&ROM[0x200000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */ |
| 681 | | |
| 682 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_l3alt_protw ); |
| 683 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w ); |
| 684 | | memory_install_read16_handler( machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r ); |
| 685 | | } |
| 686 | | } |
| 687 | | |
| 688 | | /* Super King Kong 99 */ |
| 689 | | if (genesis_last_loaded_image_length == 0x200000) |
| 690 | | { |
| 691 | | static unsigned char sdksig[] = { 0x48, 0xe7, 0xff, 0xfe, 0x52, 0x79}; |
| 692 | | if (!allendianmemcmp(&ROM[0x220+relocate],&sdksig[0],sizeof(sdksig))) |
| 693 | | { |
| 694 | | |
| 695 | | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */ |
| 696 | | memcpy(&ROM[0x200000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */ |
| 697 | | |
| 698 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_l3alt_protw ); |
| 699 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w ); |
| 700 | | memory_install_read16_handler( machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r ); |
| 701 | | } |
| 702 | | } |
| 703 | | |
| 704 | | /* Super Donkey Kong 99 */ |
| 705 | | if (genesis_last_loaded_image_length == 0x300000) |
| 706 | | { |
| 707 | | static unsigned char sdksig[] = { 0x48, 0xe7, 0xff, 0xfe, 0x52, 0x79}; |
| 708 | | if (!allendianmemcmp(&ROM[0x220+relocate],&sdksig[0],sizeof(sdksig))) |
| 709 | | { |
| 710 | | |
| 711 | | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x300000); /* default rom */ |
| 712 | | memcpy(&ROM[0x300000], &ROM[VIRGIN_COPY_GEN], 0x100000); /* default rom */ |
| 713 | | |
| 714 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_l3alt_protw ); |
| 715 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w ); |
| 716 | | memory_install_read16_handler( machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r ); |
| 717 | | } |
| 718 | | } |
| 719 | | |
| 720 | | /* detect the 'Romance of the Three Kingdoms - Battle of Red Cliffs' rom, already decoded from .mdx format */ |
| 721 | | if (genesis_last_loaded_image_length == 0x200000) |
| 722 | | { |
| 723 | | static unsigned char redcliffsig[] = { 0x10, 0x39, 0x00, 0x40, 0x00, 0x04}; // move.b ($400004).l,d0 |
| 724 | | if (!allendianmemcmp(&ROM[0xce560+relocate],&redcliffsig[0],sizeof(redcliffsig))) |
| 725 | | { |
| 726 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, redclif_prot2_r ); |
| 727 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, redclif_prot_r ); |
| 728 | | } |
| 729 | | } |
| 730 | | /* detect the Radica TV games.. these probably should be a seperate driver since they are a seperate 'console' */ |
| 731 | | if (genesis_last_loaded_image_length == 0x400000) |
| 732 | | { |
| 733 | | static unsigned char radicasig[] = { 0x4e, 0xd0, 0x30, 0x39, 0x00, 0xa1}; // jmp (a0) move.w ($a130xx),d0 |
| 734 | | |
| 735 | | if (!allendianmemcmp(&ROM[0x3c031c+relocate],&radicasig[0],sizeof(radicasig)) || |
| 736 | | !allendianmemcmp(&ROM[0x3f031c+relocate],&radicasig[0],sizeof(radicasig))) // ssf+gng + radica vol1 |
| 737 | | { |
| 738 | | memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x400000); // keep a copy for later banking.. making use of huge ROM_REGION allocated to genesis driver |
| 739 | | memcpy(&ROM[0x800000],&ROM[VIRGIN_COPY_GEN],0x400000); // wraparound banking (from hazemd code) |
| 740 | | memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x400000); |
| 741 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa13000, 0xa1307f, 0, 0, radica_bank_select ); |
| 742 | | } |
| 743 | | |
| 744 | | } |
| 745 | | |
| 746 | | // detect the King of Fighters '99 unlicensed game |
| 747 | | if (genesis_last_loaded_image_length == 0x300000) |
| 748 | | { |
| 749 | | static unsigned char kof99sig[] = { 0x20, 0x3c, 0x30, 0x00, 0x00, 0xa1}; // move.l #$300000A1,d0 |
| 750 | | |
| 751 | | if (!allendianmemcmp(&ROM[0x1fd0d2+relocate],&kof99sig[0],sizeof(kof99sig))) |
| 752 | | { |
| 753 | | //memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x300000); |
| 754 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, kof99_0xA13000_r ); |
| 755 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13002, 0xA13003, 0, 0, kof99_0xA13002_r ); |
| 756 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA1303e, 0xA1303f, 0, 0, kof99_00A1303E_r ); |
| 757 | | } |
| 758 | | } |
| 759 | | |
| 760 | | // detect the Soul Blade unlicensed game |
| 761 | | if (genesis_last_loaded_image_length == 0x400000) |
| 762 | | { |
| 763 | | static unsigned char soulbsig[] = { 0x33, 0xfc, 0x00, 0x0c, 0x00, 0xff}; // move.w #$C,($FF020A).l (what happens if check fails) |
| 764 | | |
| 765 | | if (!allendianmemcmp(&ROM[0x028460+relocate],&soulbsig[0],sizeof(soulbsig))) |
| 766 | | { |
| 767 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400006, 0x400007, 0, 0, soulb_0x400006_r ); |
| 768 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, soulb_0x400002_r ); |
| 769 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, soulb_0x400004_r ); |
| 770 | | } |
| 771 | | } |
| 772 | | |
| 773 | | // detect Mahjong Lover unlicensed game |
| 774 | | if (genesis_last_loaded_image_length == 0x100000) |
| 775 | | { |
| 776 | | static unsigned char mjlovrsig[] = { 0x13, 0xf9, 0x00, 0x40, 0x00, 0x00}; // move.b ($400000).l,($FFFF0C).l (partial) |
| 777 | | |
| 778 | | if (!allendianmemcmp(&ROM[0x01b24+relocate],&mjlovrsig[0],sizeof(mjlovrsig))) |
| 779 | | { |
| 780 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, mjlovr_prot_1_r ); |
| 781 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x401000, 0x401001, 0, 0, mjlovr_prot_2_r ); |
| 782 | | } |
| 783 | | } |
| 784 | | // detect Squirrel King unlicensed game |
| 785 | | if (genesis_last_loaded_image_length == 0x100000) |
| 786 | | { |
| 787 | | static unsigned char squirsig[] = { 0x26, 0x79, 0x00, 0xff, 0x00, 0xfa}; |
| 788 | | |
| 789 | | if (!allendianmemcmp(&ROM[0x03b4+relocate],&squirsig[0],sizeof(squirsig))) |
| 790 | | { |
| 791 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, squirrel_king_extra_r); |
| 792 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, squirrel_king_extra_w); |
| 793 | | } |
| 794 | | } |
| 795 | | if (genesis_last_loaded_image_length == 0x80000) |
| 796 | | { |
| 797 | | static unsigned char smoussig[] = { 0x4d, 0xf9, 0x00, 0x40, 0x00, 0x02}; |
| 798 | | |
| 799 | | if (!allendianmemcmp(&ROM[0x08c8+relocate],&smoussig[0],sizeof(smoussig))) |
| 800 | | { |
| 801 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400007, 0, 0, smous_prot_r ); |
| 802 | | } |
| 803 | | } |
| 804 | | if (genesis_last_loaded_image_length >= 0x200000) |
| 805 | | { |
| 806 | | static unsigned char smbsig[] = { 0x20, 0x4d, 0x41, 0x52, 0x49, 0x4f}; |
| 807 | | |
| 808 | | if (!allendianmemcmp(&ROM[0xc8cb0+relocate],&smbsig[0],sizeof(smbsig))) |
| 809 | | { |
| 810 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, smbro_prot_r ); |
| 811 | | } |
| 812 | | } |
| 813 | | if (genesis_last_loaded_image_length >= 0x200000) |
| 814 | | { |
| 815 | | static unsigned char smb2sig[] = { 0x4e, 0xb9, 0x00, 0x0f, 0x25, 0x84}; |
| 816 | | |
| 817 | | if (!allendianmemcmp(&ROM[0xf24d6+relocate],&smb2sig[0],sizeof(smb2sig))) |
| 818 | | { |
| 819 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, smb2_extra_r); |
| 820 | | } |
| 821 | | } |
| 822 | | if (genesis_last_loaded_image_length == 0x200000) |
| 823 | | { |
| 824 | | static unsigned char kaijusig[] = { 0x19, 0x7c, 0x00, 0x01, 0x00, 0x00}; |
| 825 | | |
| 826 | | if (!allendianmemcmp(&ROM[0x674e + relocate],&kaijusig[0],sizeof(kaijusig))) |
| 827 | | { |
| 828 | | memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x200000); |
| 829 | | memcpy(&ROM[0x600000],&ROM[VIRGIN_COPY_GEN],0x200000); |
| 830 | | memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x200000); |
| 831 | | |
| 832 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x700000, 0x7fffff, 0, 0, g_kaiju_bank_w ); |
| 833 | | } |
| 834 | | } |
| 835 | | |
| 836 | | if (genesis_last_loaded_image_length == 0x200000) |
| 837 | | { |
| 838 | | static unsigned char chifi3sig[] = { 0xb6, 0x16, 0x66, 0x00, 0x00, 0x4a}; |
| 839 | | |
| 840 | | if (!allendianmemcmp(&ROM[0x1780 + relocate],&chifi3sig[0],sizeof(chifi3sig))) |
| 841 | | { |
| 842 | | memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x200000); |
| 843 | | memcpy(&ROM[0x600000],&ROM[VIRGIN_COPY_GEN],0x200000); |
| 844 | | memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x200000); |
| 845 | | |
| 846 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x4fffff, 0, 0, g_chifi3_prot_r ); |
| 847 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000, 0x6fffff, 0, 0, g_chifi3_bank_w ); |
| 848 | | } |
| 849 | | } |
| 850 | | |
| 851 | | |
| 852 | | if (genesis_last_loaded_image_length == 0x200000) |
| 853 | | { |
| 854 | | static unsigned char lionk2sig[] = { 0x26, 0x79, 0x00, 0xff, 0x00, 0xf4}; |
| 855 | | |
| 856 | | if (!allendianmemcmp(&ROM[0x03c2+relocate],&lionk2sig[0],sizeof(lionk2sig))) |
| 857 | | { |
| 858 | | memory_install_write16_handler(machine, 0,ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, lion2_prot1_w ); |
| 859 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, lion2_prot1_r ); |
| 860 | | memory_install_write16_handler(machine, 0,ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, lion2_prot2_w ); |
| 861 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400006, 0x400007, 0, 0, lion2_prot2_r ); |
| 862 | | } |
| 863 | | } |
| 864 | | |
| 865 | | if (genesis_last_loaded_image_length == 0x100000) |
| 866 | | { |
| 867 | | static unsigned char bugslsig[] = { 0x20, 0x12, 0x13, 0xc0, 0x00, 0xff}; |
| 868 | | |
| 869 | | if (!allendianmemcmp(&ROM[0xee0d0+relocate],&bugslsig[0],sizeof(bugslsig))) |
| 870 | | { |
| 871 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, bugl_extra_r); |
| 872 | | } |
| 873 | | } |
| 874 | | |
| 875 | | if (genesis_last_loaded_image_length == 0x100000 && !allendianmemcmp((char *)&ROM[0x0172+relocate], "GAME : ELF WOR", 14)) |
| 876 | | { |
| 877 | | /* |
| 878 | | Elf Wor (Unl) - return (0x55 @ 0x400000 OR 0xc9 @ 0x400004) AND (0x0f @ 0x400002 OR 0x18 @ 0x400006). It is probably best to add handlers for all 4 addresses. |
| 879 | | */ |
| 880 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, elfwor_0x400000_r ); |
| 881 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400004, 0x400005, 0, 0, elfwor_0x400004_r ); |
| 882 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, elfwor_0x400002_r ); |
| 883 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400006, 0x400007, 0, 0, elfwor_0x400006_r ); |
| 884 | | } |
| 885 | | if (genesis_last_loaded_image_length == 0x200000) |
| 886 | | { |
| 887 | | static unsigned char rx3sig[] = { 0x66, 0x00, 0x00, 0x0e, 0x30, 0x3c}; |
| 888 | | if (!allendianmemcmp(&ROM[0xc8b90+relocate],&rx3sig[0],sizeof(rx3sig))) |
| 889 | | { |
| 890 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13001, 0, 0, rx3_extra_r); |
| 891 | | } |
| 892 | | } |
| 893 | | if (genesis_last_loaded_image_length == 0x100000) |
| 894 | | { |
| 895 | | static unsigned char sbubsig[] = { 0x0c, 0x39, 0x00, 0x55, 0x00, 0x40}; // cmpi.b #$55,($400000).l |
| 896 | | if (!allendianmemcmp(&ROM[0x123e4+relocate],&sbubsig[0],sizeof(sbubsig))) |
| 897 | | { |
| 898 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, sbub_extra1_r); |
| 899 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400002, 0x400003, 0, 0, sbub_extra2_r); |
| 900 | | } |
| 901 | | } |
| 902 | | if (genesis_last_loaded_image_length == 0x200000) |
| 903 | | { |
| 904 | | static unsigned char kof98sig[] = { 0x9b, 0xfc, 0x00, 0x00, 0x4a, 0x00}; |
| 905 | | if (!allendianmemcmp(&ROM[0x56ae2+relocate],&kof98sig[0],sizeof(kof98sig))) |
| 906 | | { |
| 907 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x480000, 0x480001, 0, 0, g_kof98_aa_r ); |
| 908 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4800e0, 0x4800e1, 0, 0, g_kof98_aa_r ); |
| 909 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4824a0, 0x4824a1, 0, 0, g_kof98_aa_r ); |
| 910 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x488880, 0x488881, 0, 0, g_kof98_aa_r ); |
| 911 | | |
| 912 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4a8820, 0x4a8821, 0, 0, g_kof98_0a_r ); |
| 913 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4f8820, 0x4f8821, 0, 0, g_kof98_00_r ); |
| 914 | | } |
| 915 | | } |
| 916 | | if (genesis_last_loaded_image_length == 0x80000) |
| 917 | | { |
| 918 | | if (!allendianmemcmp((char *)&ROM[0x7e30e + relocate],"SEGA",4) || |
| 919 | | !allendianmemcmp((char *)&ROM[0x7e100 + relocate],"SEGA",4) || |
| 920 | | !allendianmemcmp((char *)&ROM[0x7e1e6 + relocate],"SEGA",4)) { // Whac a Critter/mallet legend, Defend the Earth, Funnyworld/ballonboy |
| 921 | | realtek_old_bank_addr = -1; |
| 922 | | /* Realtec mapper!*/ |
| 923 | | memcpy(&ROM[0x400000],&ROM[relocate],0x80000); |
| 924 | | for (mirroraddr = 0; mirroraddr < 0x400000;mirroraddr+=0x2000) { |
| 925 | | memcpy(ROM+mirroraddr, ROM + relocate + 0x7e000, 0x002000); /* copy last 8kb across the whole rom region */ |
| 926 | | } |
| 927 | | |
| 928 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x400000, 0x400001, 0, 0, realtec_400000_w); |
| 929 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x402000, 0x402001, 0, 0, realtec_402000_w); |
| 930 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x404000, 0x404001, 0, 0, realtec_404000_w); |
| 931 | | } |
| 932 | | } |
| 933 | | // detect 'Super 19 in 1' |
| 934 | | if (genesis_last_loaded_image_length == 0x400000) |
| 935 | | { |
| 936 | | static unsigned char s19in1sig[] = { 0x13, 0xc0, 0x00, 0xa1, 0x30, 0x38}; |
| 937 | | |
| 938 | | if (!allendianmemcmp(&ROM[0x1e700+relocate],&s19in1sig[0],sizeof(s19in1sig))) // super19in1 |
| 939 | | { |
| 940 | | memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x400000); // allow hard reset to menu |
| 941 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13039, 0, 0, s19in1_bank); |
| 942 | | } |
| 943 | | |
| 944 | | } |
| 945 | | // detect 'Super 15 in 1' |
| 946 | | if (genesis_last_loaded_image_length == 0x200000) |
| 947 | | { |
| 948 | | static unsigned char s15in1sig[] = { 0x22, 0x3c, 0x00, 0xa1, 0x30, 0x00}; |
| 949 | | |
| 950 | | if (!allendianmemcmp(&ROM[0x17bb2+relocate],&s15in1sig[0],sizeof(s15in1sig))) // super15in1 |
| 951 | | { |
| 952 | | memcpy(&ROM[0x400000],&ROM[VIRGIN_COPY_GEN],0x200000); // allow hard reset to menu |
| 953 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA13000, 0xA13039, 0, 0, s19in1_bank); |
| 954 | | } |
| 955 | | } |
| 956 | | |
| 957 | | /* check if cart has battery save */ |
| 958 | | genesis_sram_len = 0; |
| 959 | | genesis_sram = NULL; |
| 960 | | if (ROM[0x1b1] == 'R' && ROM[0x1b0] == 'A') |
| 961 | | { |
| 962 | | genesis_sram_start = (ROM[0x1b5] << 24 | ROM[0x1b4] << 16 | ROM[0x1b7] << 8 | ROM[0x1b6]); |
| 963 | | genesis_sram_len = (ROM[0x1b9] << 24 | ROM[0x1b8] << 16 | ROM[0x1bb] << 8 | ROM[0x1ba]); |
| 964 | | } |
| 965 | | |
| 966 | | if (genesis_sram_start != genesis_sram_len) |
| 967 | | { |
| 968 | | if (genesis_sram_start & 1) |
| 969 | | genesis_sram_start -= 1; |
| 970 | | if (!(genesis_sram_len & 1)) |
| 971 | | genesis_sram_len += 1; |
| 972 | | genesis_sram_len -= (genesis_sram_start - 1); |
| 973 | | genesis_sram = auto_malloc (genesis_sram_len); |
| 974 | | memset(genesis_sram, 0, genesis_sram_len); |
| 975 | | image_battery_load(image_from_devtype_and_index(IO_CARTSLOT,0), genesis_sram, genesis_sram_len); |
| 976 | | |
| 977 | | if (genesis_last_loaded_image_length - 0x200 < genesis_sram_start) |
| 978 | | { |
| 979 | | genesis_sram_active = 1; |
| 980 | | } |
| 981 | | |
| 982 | | memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, genesis_sram_start & 0x3fffff, (genesis_sram_start + genesis_sram_len - 1) & 0x3fffff, 0, 0, genesis_sram_read); |
| 983 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, genesis_sram_start & 0x3fffff, (genesis_sram_start + genesis_sram_len - 1) & 0x3fffff, 0, 0, genesis_sram_write); |
| 984 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xa130f0, 0xa130f1, 0, 0, genesis_sram_toggle); |
| 985 | | } |
| 986 | | |
| 987 | | |
| 988 | | /* install NOP handler for TMSS */ |
| 989 | | memory_install_write16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xA14000, 0xA14003, 0, 0, genesis_TMSS_bank_w); |
| 990 | | } |
| 991 | | |
| 992 | | |
| 993 | | /************************************* |
| 994 | | * |
| 995 | 124 | * Driver initialization |
| 996 | 125 | * |
| 997 | 126 | *************************************/ |
| 998 | 127 | |
| 999 | | /* We add handlers for custom mappers to basic megadriv reset */ |
| 1000 | | |
| 1001 | | static MACHINE_RESET( ms_megadriv ) |
| 1002 | | { |
| 1003 | | MACHINE_RESET_CALL( megadriv ); |
| 1004 | | |
| 1005 | | setup_megadriv_custom_mappers(machine); |
| 1006 | | } |
| 1007 | | |
| 1008 | | |
| 1009 | | static MACHINE_DRIVER_START( ms_megadriv ) |
| 1010 | | MDRV_IMPORT_FROM(megadriv) |
| 1011 | | |
| 1012 | | MDRV_MACHINE_RESET( ms_megadriv ) |
| 1013 | | MACHINE_DRIVER_END |
| 1014 | | |
| 1015 | | static MACHINE_DRIVER_START( ms_megdsvp ) |
| 1016 | | MDRV_IMPORT_FROM(megdsvp) |
| 1017 | | |
| 1018 | | MDRV_MACHINE_RESET( ms_megadriv ) |
| 1019 | | MACHINE_DRIVER_END |
| 1020 | | |
| 1021 | | |
| 1022 | | |
| 1023 | | /************************************* |
| 1024 | | * |
| 1025 | | * Driver initialization |
| 1026 | | * |
| 1027 | | *************************************/ |
| 1028 | | |
| 1029 | | static void genesis_machine_stop(running_machine *machine) |
| 1030 | | { |
| 1031 | | } |
| 1032 | | |
| 1033 | | static DRIVER_INIT( gencommon ) |
| 1034 | | { |
| 1035 | | if (genesis_sram) |
| 1036 | | { |
| 1037 | | add_exit_callback(machine, genesis_machine_stop); |
| 1038 | | } |
| 1039 | | } |
| 1040 | | |
| 1041 | 128 | static DRIVER_INIT( genesis ) |
| 1042 | 129 | { |
| 1043 | 130 | DRIVER_INIT_CALL(gencommon); |
| r3294 | r3295 | |
| 1059 | 146 | |
| 1060 | 147 | /************************************* |
| 1061 | 148 | * |
| 1062 | | * Cart handling / |
| 1063 | | * System configuration(s) |
| 149 | * System configuration(s) |
| 1064 | 150 | * |
| 1065 | 151 | *************************************/ |
| 1066 | 152 | |
| 1067 | 153 | |
| 1068 | | /******* SMD files detection *******/ |
| 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 | 154 | static SYSTEM_CONFIG_START( genesis ) |
| 1294 | 155 | CONFIG_DEVICE(genesis_cartslot_getinfo) |
| 1295 | 156 | SYSTEM_CONFIG_END |
| r3294 | r3295 | |
| 1530 | 391 | ROM_END |
| 1531 | 392 | |
| 1532 | 393 | |
| 1533 | | |
| 1534 | | static void pico_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 1535 | | { |
| 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; |
| 1542 | | |
| 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; |
| 1546 | | |
| 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 | | } |
| 1552 | | } |
| 1553 | | |
| 1554 | 394 | static SYSTEM_CONFIG_START( pico ) |
| 1555 | 395 | CONFIG_DEVICE(pico_cartslot_getinfo) |
| 1556 | 396 | SYSTEM_CONFIG_END |