src/mess/machine/snescart.c
| r0 | r3332 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | snes.c |
| 4 | |
| 5 | Machine file to handle cart loading in the Nintendo Super NES emulation. |
| 6 | |
| 7 | ***************************************************************************/ |
| 8 | |
| 9 | #include "driver.h" |
| 10 | #include "includes/snes.h" |
| 11 | #include "devices/cartslot.h" |
| 12 | |
| 13 | static int cart_type; |
| 14 | |
| 15 | /*************************************************************************** |
| 16 | |
| 17 | SRAM handling |
| 18 | |
| 19 | ***************************************************************************/ |
| 20 | |
| 21 | /* Loads the battery backed RAM into the appropriate memory area */ |
| 22 | static void snes_load_sram(void) |
| 23 | { |
| 24 | UINT8 ii; |
| 25 | UINT8 *battery_ram, *ptr; |
| 26 | |
| 27 | battery_ram = malloc_or_die( snes_cart.sram_max ); |
| 28 | ptr = battery_ram; |
| 29 | image_battery_load( image_from_devtype_and_index(IO_CARTSLOT,0), battery_ram, snes_cart.sram_max ); |
| 30 | |
| 31 | if( snes_cart.mode == SNES_MODE_20 ) |
| 32 | { |
| 33 | for( ii = 0; ii < 8; ii++ ) |
| 34 | { |
| 35 | memmove( &snes_ram[0x700000 + (ii * 0x010000)], ptr, 0x7fff ); |
| 36 | ptr += 0x7fff; |
| 37 | } |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | for( ii = 0; ii < 16; ii++ ) |
| 42 | { |
| 43 | memmove( &snes_ram[0x306000 + (ii * 0x010000)], ptr, 0x1fff ); |
| 44 | ptr += 0x1fff; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | free( battery_ram ); |
| 49 | } |
| 50 | |
| 51 | /* Saves the battery backed RAM from the appropriate memory area */ |
| 52 | static void snes_save_sram(void) |
| 53 | { |
| 54 | UINT8 ii; |
| 55 | UINT8 *battery_ram, *ptr; |
| 56 | |
| 57 | battery_ram = malloc_or_die( snes_cart.sram_max ); |
| 58 | ptr = battery_ram; |
| 59 | |
| 60 | if( snes_cart.mode == SNES_MODE_20 ) |
| 61 | { |
| 62 | for( ii = 0; ii < 8; ii++ ) |
| 63 | { |
| 64 | memmove( ptr, &snes_ram[0x700000 + (ii * 0x010000)], 0x8000 ); |
| 65 | ptr += 0x8000; |
| 66 | } |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | for( ii = 0; ii < 16; ii++ ) |
| 71 | { |
| 72 | memmove( ptr, &snes_ram[0x306000 + (ii * 0x010000)], 0x2000 ); |
| 73 | ptr += 0x2000; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | image_battery_save( image_from_devtype_and_index(IO_CARTSLOT,0), battery_ram, snes_cart.sram_max ); |
| 78 | |
| 79 | free( battery_ram ); |
| 80 | } |
| 81 | |
| 82 | static void snes_machine_stop(running_machine *machine) |
| 83 | { |
| 84 | /* Save SRAM */ |
| 85 | if( snes_cart.sram > 0 ) |
| 86 | snes_save_sram(); |
| 87 | } |
| 88 | |
| 89 | MACHINE_START( snes_mess ) |
| 90 | { |
| 91 | add_exit_callback(machine, snes_machine_stop); |
| 92 | MACHINE_START_CALL(snes); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | /*************************************************************************** |
| 97 | |
| 98 | Cart handling |
| 99 | |
| 100 | ***************************************************************************/ |
| 101 | |
| 102 | static DEVICE_IMAGE_LOAD( snes_cart ) |
| 103 | { |
| 104 | int i, supported_type = 0; |
| 105 | running_machine *machine = image->machine; |
| 106 | UINT16 totalblocks, readblocks; |
| 107 | UINT32 offset; |
| 108 | UINT8 header[512], sample[0xffff]; |
| 109 | UINT8 valid_mode20, valid_mode21; |
| 110 | |
| 111 | enum |
| 112 | { |
| 113 | STANDARD = 0, |
| 114 | STANDARD_RAM, |
| 115 | STANDARD_SRAM, |
| 116 | DSP1, |
| 117 | DSP1_RAM, |
| 118 | DSP1_SRAM, |
| 119 | DSP2, |
| 120 | DSP3, |
| 121 | DSP4, |
| 122 | SUPERFX, |
| 123 | SUPERFX_SRAM, |
| 124 | SA1, |
| 125 | SA1_SRAM, |
| 126 | SDD1, |
| 127 | SDD1_SRAM, |
| 128 | OBC1, |
| 129 | RTC, |
| 130 | SGB, |
| 131 | C4, |
| 132 | ST010, |
| 133 | ST011, |
| 134 | ST018, |
| 135 | SPC7110, |
| 136 | SPC7110_RTC, |
| 137 | UNKNOWN, |
| 138 | }; |
| 139 | |
| 140 | |
| 141 | /* Some known type of cart */ |
| 142 | const char *types[] = |
| 143 | { |
| 144 | "ROM", |
| 145 | "ROM, RAM", |
| 146 | "ROM, SRAM", |
| 147 | "ROM, DSP-1", |
| 148 | "ROM, RAM, DSP-1", |
| 149 | "ROM, SRAM, DSP-1", |
| 150 | "ROM, SRAM, DSP-2", |
| 151 | "ROM, SRAM, DSP-3", |
| 152 | "ROM, DSP-4", |
| 153 | "ROM, Super FX / FX2", |
| 154 | "ROM, SRAM, Super FX / FX2", |
| 155 | "ROM, SA-1", |
| 156 | "ROM, SRAM, SA-1", |
| 157 | "ROM, S-DD1", |
| 158 | "ROM, SRAM, S-DD1", |
| 159 | "ROM, SRAM, OBC-1", |
| 160 | "ROM, SRAM, S-RTC", |
| 161 | "ROM, Z80GB (Super Game Boy)", |
| 162 | "ROM, C4", |
| 163 | "ROM, SRAM, Seta ST-010", |
| 164 | "ROM, SRAM, Seta ST-011", |
| 165 | "ROM, SRAM, Seta ST-018", |
| 166 | "ROM, SRAM, SPC7110", |
| 167 | "ROM, SRAM, SPC7110, RTC", |
| 168 | "Unknown", // to add: Satellaview BS-X detection |
| 169 | }; |
| 170 | |
| 171 | /* Some known countries */ |
| 172 | const char *countries[] = |
| 173 | { |
| 174 | "Japan (NTSC)", |
| 175 | "USA (NTSC)", |
| 176 | "Australia, Europe, Oceania & Asia (PAL)", |
| 177 | "Sweden (PAL)", |
| 178 | "Finland (PAL)", |
| 179 | "Denmark (PAL)", |
| 180 | "France (PAL)", |
| 181 | "Holland (PAL)", |
| 182 | "Spain (PAL)", |
| 183 | "Germany, Austria & Switzerland (PAL)", |
| 184 | "Italy (PAL)", |
| 185 | "Hong Kong & China (PAL)", |
| 186 | "Indonesia (PAL)", |
| 187 | "South Korea (NTSC)", |
| 188 | "UNKNOWN" |
| 189 | }; |
| 190 | |
| 191 | memory_region_alloc(machine, "main", 0x1000000,0); |
| 192 | |
| 193 | snes_ram = memory_region( machine, "main" ); |
| 194 | memset( snes_ram, 0, 0x1000000 ); |
| 195 | |
| 196 | /* Check for a header (512 bytes) */ |
| 197 | offset = 512; |
| 198 | image_fread( image, header, 512 ); |
| 199 | if( (header[8] == 0xaa) && (header[9] == 0xbb) && (header[10] == 0x04) ) |
| 200 | { |
| 201 | /* Found an SWC identifier */ |
| 202 | logerror( "Found header(SWC) - Skipped\n" ); |
| 203 | } |
| 204 | else if( (header[0] | (header[1] << 8)) == (((image_length(image) - 512) / 1024) / 8) ) |
| 205 | { |
| 206 | /* Some headers have the rom size at the start, if this matches with the |
| 207 | * actual rom size, we probably have a header */ |
| 208 | logerror( "Found header(size) - Skipped\n" ); |
| 209 | } |
| 210 | else if( (image_length(image) % 0x8000) == 512 ) |
| 211 | { |
| 212 | /* As a last check we'll see if there's exactly 512 bytes extra to this |
| 213 | * image. */ |
| 214 | logerror( "Found header(extra) - Skipped\n" ); |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | /* No header found so go back to the start of the file */ |
| 219 | logerror( "No header found.\n" ); |
| 220 | offset = 0; |
| 221 | image_fseek( image, offset, SEEK_SET ); |
| 222 | } |
| 223 | |
| 224 | /* We need to take a sample of 128kb to test what mode we need to be in */ |
| 225 | image_fread( image, sample, 0xffff ); |
| 226 | image_fseek( image, offset, SEEK_SET ); /* Rewind */ |
| 227 | |
| 228 | /* Now to determine if this is a lo-ROM or a hi-ROM */ |
| 229 | valid_mode20 = snes_validate_infoblock( sample, 0x7fc0 ); |
| 230 | valid_mode21 = snes_validate_infoblock( sample, 0xffc0 ); |
| 231 | if( valid_mode20 >= valid_mode21 ) |
| 232 | { |
| 233 | snes_cart.mode = SNES_MODE_20; |
| 234 | snes_cart.sram_max = 0x40000; |
| 235 | } |
| 236 | else if( valid_mode21 > valid_mode20 ) |
| 237 | { |
| 238 | snes_cart.mode = SNES_MODE_21; |
| 239 | snes_cart.sram_max = 0x20000; |
| 240 | } |
| 241 | |
| 242 | /* Find the number of blocks in this ROM */ |
| 243 | totalblocks = ((image_length(image) - offset) >> (snes_cart.mode == SNES_MODE_20 ? 15 : 16)); |
| 244 | |
| 245 | /* FIXME: Insert crc check here */ |
| 246 | |
| 247 | readblocks = 0; |
| 248 | if( snes_cart.mode == SNES_MODE_20 ) |
| 249 | { |
| 250 | /* In mode 20, all blocks are 32kb. There are upto 96 blocks, giving a |
| 251 | * total of 24mbit(3mb) of ROM. |
| 252 | * The first 48 blocks are located in banks 0x00 to 0x2f at address |
| 253 | * 0x8000. They are mirrored in banks 0x80 to 0xaf. |
| 254 | * The next 16 blocks are located in banks 0x30 to 0x3f at address |
| 255 | * 0x8000. They are mirrored in banks 0xb0 to 0xbf. |
| 256 | * The final 32 blocks are located in banks 0x40 - 0x5f at address |
| 257 | * 0x8000. They are mirrored in banks 0xc0 to 0xdf. |
| 258 | */ |
| 259 | i = 0; |
| 260 | while( i < 96 && readblocks <= totalblocks ) |
| 261 | { |
| 262 | image_fread( image, &snes_ram[(i++ * 0x10000) + 0x8000], 0x8000); |
| 263 | readblocks++; |
| 264 | } |
| 265 | } |
| 266 | else /* Mode 21 */ |
| 267 | { |
| 268 | /* In mode 21, all blocks are 64kb. There are upto 96 blocks, giving a |
| 269 | * total of 48mbit(6mb) of ROM. |
| 270 | * The first 64 blocks are located in banks 0xc0 to 0xff. The top 32k of |
| 271 | * each bank is mirrored in banks 0x00 to 0x3f. |
| 272 | * The final 32 blocks are located in banks 0x40 to 0x5f. |
| 273 | */ |
| 274 | |
| 275 | /* read first 64 blocks */ |
| 276 | i = 0; |
| 277 | while( i < 64 && readblocks <= totalblocks ) |
| 278 | { |
| 279 | image_fread( image, &snes_ram[0xc00000 + (i++ * 0x10000)], 0x10000); |
| 280 | readblocks++; |
| 281 | } |
| 282 | /* read the next 32 blocks */ |
| 283 | i = 0; |
| 284 | while( i < 32 && readblocks <= totalblocks ) |
| 285 | { |
| 286 | image_fread( image, &snes_ram[0x400000 + (i++ * 0x10000)], 0x10000); |
| 287 | readblocks++; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | |
| 292 | /* Find the amount of sram */ |
| 293 | snes_cart.sram = snes_r_bank1(machine, 0x00ffd8); |
| 294 | if( snes_cart.sram > 0 ) |
| 295 | { |
| 296 | snes_cart.sram = ((1 << (snes_cart.sram + 3)) / 8); |
| 297 | if( snes_cart.sram > snes_cart.sram_max ) |
| 298 | snes_cart.sram = snes_cart.sram_max; |
| 299 | } |
| 300 | |
| 301 | /* Find the type of cart and detect special chips */ |
| 302 | /* Info mostly taken from http://snesemu.black-ship.net/misc/-from%20nsrt.edgeemu.com-chipinfo.htm */ |
| 303 | switch (snes_r_bank1(machine, 0x00ffd6)) |
| 304 | { |
| 305 | case 0x00: |
| 306 | cart_type = STANDARD; |
| 307 | supported_type = 1; |
| 308 | break; |
| 309 | |
| 310 | case 0x01: |
| 311 | cart_type = STANDARD_RAM; |
| 312 | supported_type = 1; |
| 313 | break; |
| 314 | |
| 315 | case 0x02: |
| 316 | cart_type = STANDARD_SRAM; |
| 317 | supported_type = 1; |
| 318 | break; |
| 319 | |
| 320 | case 0x03: |
| 321 | if (snes_r_bank1(machine, 0x00ffd5) == 0x30) |
| 322 | cart_type = DSP4; |
| 323 | else |
| 324 | { |
| 325 | cart_type = DSP1; |
| 326 | supported_type = 1; |
| 327 | } |
| 328 | break; |
| 329 | |
| 330 | case 0x04: |
| 331 | cart_type = DSP1_RAM; |
| 332 | supported_type = 1; |
| 333 | break; |
| 334 | |
| 335 | case 0x05: |
| 336 | if (snes_r_bank1(machine, 0x00ffd5) == 0x20) |
| 337 | cart_type = DSP2; |
| 338 | /* DSP-3 is hard to detect. We exploit the fact that the only game has been manufactured by Bandai */ |
| 339 | else if ((snes_r_bank1(machine, 0x00ffd5) == 0x30) && (snes_r_bank1(machine, 0x00ffda) == 0xb2)) |
| 340 | cart_type = DSP3; |
| 341 | else |
| 342 | { |
| 343 | cart_type = DSP1_SRAM; |
| 344 | supported_type = 1; |
| 345 | } |
| 346 | break; |
| 347 | |
| 348 | case 0x13: // Mario Chip 1 |
| 349 | case 0x14: // GSU-x |
| 350 | if (snes_r_bank1(machine, 0x00ffd5) == 0x20) |
| 351 | cart_type = SUPERFX; |
| 352 | break; |
| 353 | |
| 354 | case 0x15: // GSU-x |
| 355 | case 0x1a: // GSU-1 (21 Mhz at start) |
| 356 | if (snes_r_bank1(machine, 0x00ffd5) == 0x20) |
| 357 | cart_type = SUPERFX_SRAM; |
| 358 | break; |
| 359 | |
| 360 | case 0x25: |
| 361 | cart_type = OBC1; |
| 362 | break; |
| 363 | |
| 364 | case 0x34: |
| 365 | if (snes_r_bank1(machine, 0x00ffd5) == 0x23) |
| 366 | cart_type = SA1; |
| 367 | break; |
| 368 | |
| 369 | case 0x32: // needed by a Sample game (according to ZSNES) |
| 370 | case 0x35: |
| 371 | if (snes_r_bank1(machine, 0x00ffd5) == 0x23) |
| 372 | cart_type = SA1_SRAM; |
| 373 | break; |
| 374 | |
| 375 | case 0x43: |
| 376 | if (snes_r_bank1(machine, 0x00ffd5) == 0x32) |
| 377 | cart_type = SDD1; |
| 378 | break; |
| 379 | |
| 380 | case 0x45: |
| 381 | if (snes_r_bank1(machine, 0x00ffd5) == 0x32) |
| 382 | cart_type = SDD1_SRAM; |
| 383 | break; |
| 384 | |
| 385 | case 0x55: |
| 386 | if (snes_r_bank1(machine, 0x00ffd5) == 0x35) |
| 387 | cart_type = RTC; |
| 388 | break; |
| 389 | |
| 390 | case 0xe3: |
| 391 | cart_type = SGB; |
| 392 | break; |
| 393 | |
| 394 | case 0xf3: |
| 395 | cart_type = C4; |
| 396 | break; |
| 397 | |
| 398 | case 0xf5: |
| 399 | if (snes_r_bank1(machine, 0x00ffd5) == 0x30) |
| 400 | cart_type = ST018; |
| 401 | else if (snes_r_bank1(machine, 0x00ffd5) == 0x3a) |
| 402 | cart_type = SPC7110; |
| 403 | break; |
| 404 | |
| 405 | case 0xf6: |
| 406 | /* These Seta ST-01X chips have both 0x30 at 0x00ffd5, |
| 407 | they only differ for the 'size' at 0x00ffd7 */ |
| 408 | if (snes_r_bank1(machine, 0x00ffd7) < 0x0a) |
| 409 | cart_type = ST011; |
| 410 | else |
| 411 | cart_type = ST010; |
| 412 | break; |
| 413 | |
| 414 | case 0xf9: |
| 415 | if (snes_r_bank1(machine, 0x00ffd5) == 0x3a) |
| 416 | cart_type = SPC7110_RTC; |
| 417 | break; |
| 418 | |
| 419 | default: |
| 420 | cart_type = UNKNOWN; |
| 421 | break; |
| 422 | } |
| 423 | |
| 424 | /* Log snes_cart information */ |
| 425 | { |
| 426 | char title[21], rom_id[4], company_id[2]; |
| 427 | UINT8 country; |
| 428 | logerror( "ROM DETAILS\n" ); |
| 429 | logerror( "\tTotal blocks: %d (%dmb)\n", totalblocks, totalblocks / (snes_cart.mode == SNES_MODE_20 ? 32 : 16) ); |
| 430 | logerror( "\tROM bank size: %s (LoROM: %d , HiROM: %d)\n", (snes_cart.mode == SNES_MODE_20) ? "LoROM" : "HiROM", valid_mode20, valid_mode21 ); |
| 431 | for( i = 0; i < 2; i++ ) |
| 432 | company_id[i] = snes_r_bank1(machine, 0x00ffb0 + i); |
| 433 | logerror( "\tCompany ID: %s\n", company_id ); |
| 434 | for( i = 0; i < 4; i++ ) |
| 435 | rom_id[i] = snes_r_bank1(machine, 0x00ffb2 + i); |
| 436 | logerror( "\tROM ID: %s\n", rom_id ); |
| 437 | logerror( "HEADER DETAILS\n" ); |
| 438 | for( i = 0; i < 21; i++ ) |
| 439 | title[i] = snes_r_bank1(machine, 0x00ffc0 + i); |
| 440 | logerror( "\tName: %s\n", title ); |
| 441 | logerror( "\tSpeed: %s [%d]\n", ((snes_r_bank1(machine, 0x00ffd5) & 0xf0)) ? "FastROM" : "SlowROM", (snes_r_bank1(machine, 0x00ffd5) & 0xf0) >> 4 ); |
| 442 | logerror( "\tBank size: %s [%d]\n", (snes_r_bank1(machine, 0x00ffd5) & 0xf) ? "HiROM" : "LoROM", snes_r_bank1(machine, 0x00ffd5) & 0xf ); |
| 443 | logerror( "\tType: %s [%d]\n", types[cart_type], snes_r_bank1(machine, 0x00ffd6) ); |
| 444 | logerror( "\tSize: %d megabits [%d]\n", 1 << (snes_r_bank1(machine, 0x00ffd7) - 7), snes_r_bank1(machine, 0x00ffd7) ); |
| 445 | logerror( "\tSRAM: %d kilobits [%d]\n", snes_cart.sram * 8, snes_ram[0xffd8] ); |
| 446 | country = snes_r_bank1(machine, 0x00ffd9); |
| 447 | if( country > 14 ) |
| 448 | country = 14; |
| 449 | logerror( "\tCountry: %s [%d]\n", countries[country], snes_r_bank1(machine, 0x00ffd9) ); |
| 450 | logerror( "\tLicense: %s [%X]\n", "", snes_r_bank1(machine, 0x00ffda) ); |
| 451 | logerror( "\tVersion: 1.%d\n", snes_r_bank1(machine, 0x00ffdb) ); |
| 452 | logerror( "\tInv Checksum: %X %X\n", snes_r_bank1(machine, 0x00ffdd), snes_r_bank1(machine, 0x00ffdc) ); |
| 453 | logerror( "\tChecksum: %X %X\n", snes_r_bank1(machine, 0x00ffdf), snes_r_bank1(machine, 0x00ffde) ); |
| 454 | logerror( "\tNMI Address: %2X%2Xh\n", snes_r_bank1(machine, 0x00fffb), snes_r_bank1(machine, 0x00fffa) ); |
| 455 | logerror( "\tStart Address: %2X%2Xh\n", snes_r_bank1(machine, 0x00fffd), snes_r_bank1(machine, 0x00fffc) ); |
| 456 | |
| 457 | if (!supported_type) |
| 458 | logerror("WARNING: This cart type \"%s\" is not supported yet!\n", types[cart_type]); |
| 459 | } |
| 460 | |
| 461 | /* Load SRAM */ |
| 462 | snes_load_sram(); |
| 463 | |
| 464 | /* All done */ |
| 465 | return INIT_PASS; |
| 466 | } |
| 467 | |
| 468 | |
| 469 | void snes_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 470 | { |
| 471 | /* cartslot */ |
| 472 | switch(state) |
| 473 | { |
| 474 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 475 | case MESS_DEVINFO_INT_COUNT: info->i = 1; break; |
| 476 | case MESS_DEVINFO_INT_MUST_BE_LOADED: info->i = 1; break; |
| 477 | |
| 478 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 479 | case MESS_DEVINFO_PTR_LOAD: info->load = DEVICE_IMAGE_LOAD_NAME(snes_cart); break; |
| 480 | |
| 481 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 482 | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "smc,sfc,fig,swc"); break; |
| 483 | |
| 484 | default: cartslot_device_getinfo(devclass, state, info); break; |
| 485 | } |
| 486 | } |
src/mess/drivers/snes.c
| r3331 | r3332 | |
| 23 | 23 | - I'm sure there's lots more ... |
| 24 | 24 | |
| 25 | 25 | ***************************************************************************/ |
| 26 | |
| 26 | 27 | #include "driver.h" |
| 27 | 28 | #include "deprecat.h" |
| 28 | 29 | #include "includes/snes.h" |
| 29 | | #include "devices/cartslot.h" |
| 30 | #include "machine/snescart.h" |
| 30 | 31 | |
| 32 | |
| 33 | /************************************* |
| 34 | * |
| 35 | * Main CPU memory handlers |
| 36 | * |
| 37 | *************************************/ |
| 38 | |
| 31 | 39 | static ADDRESS_MAP_START( snes_map, ADDRESS_SPACE_PROGRAM, 8) |
| 32 | 40 | AM_RANGE(0x000000, 0x2fffff) AM_READWRITE(snes_r_bank1, snes_w_bank1) /* I/O and ROM (repeats for each bank) */ |
| 33 | 41 | AM_RANGE(0x300000, 0x3fffff) AM_READWRITE(snes_r_bank2, snes_w_bank2) /* I/O and ROM (repeats for each bank) */ |
| r3331 | r3332 | |
| 59 | 67 | |
| 60 | 68 | |
| 61 | 69 | |
| 70 | /*************************************************************************** |
| 71 | |
| 72 | Input ports |
| 73 | |
| 74 | ***************************************************************************/ |
| 75 | |
| 62 | 76 | static INPUT_PORTS_START( snes ) |
| 63 | | PORT_START("PAD1L") /* IN 0 : Joypad 1 - L */ |
| 64 | | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("P1 Button A") PORT_PLAYER(1) |
| 65 | | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4) PORT_NAME("P1 Button X") PORT_PLAYER(1) |
| 66 | | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5) PORT_NAME("P1 Button L") PORT_PLAYER(1) |
| 67 | | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6) PORT_NAME("P1 Button R") PORT_PLAYER(1) |
| 68 | | PORT_START("PAD1H") /* IN 1 : Joypad 1 - H */ |
| 69 | | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("P1 Button B") PORT_PLAYER(1) |
| 70 | | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("P1 Button Y") PORT_PLAYER(1) |
| 71 | | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT) PORT_PLAYER(1) |
| 72 | | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START) PORT_PLAYER(1) |
| 73 | | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP) PORT_PLAYER(1) |
| 74 | | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN) PORT_PLAYER(1) |
| 75 | | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT) PORT_PLAYER(1) |
| 76 | | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(1) |
| 77 | PORT_START("PAD1L") /* Joypad 1 - L */ |
| 78 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P1 Button A") PORT_PLAYER(1) |
| 79 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P1 Button X") PORT_PLAYER(1) |
| 80 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P1 Button L") PORT_PLAYER(1) |
| 81 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P1 Button R") PORT_PLAYER(1) |
| 77 | 82 | |
| 78 | | PORT_START("PAD2L") /* IN 2 : Joypad 2 - L */ |
| 79 | | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("P2 Button A") PORT_PLAYER(2) |
| 80 | | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4) PORT_NAME("P2 Button X") PORT_PLAYER(2) |
| 81 | | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5) PORT_NAME("P2 Button L") PORT_PLAYER(2) |
| 82 | | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6) PORT_NAME("P2 Button R") PORT_PLAYER(2) |
| 83 | | PORT_START("PAD2H") /* IN 3 : Joypad 2 - H */ |
| 84 | | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("P2 Button B") PORT_PLAYER(2) |
| 85 | | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("P2 Button Y") PORT_PLAYER(2) |
| 86 | | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT) PORT_PLAYER(2) |
| 87 | | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START) PORT_PLAYER(2) |
| 88 | | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP) PORT_PLAYER(2) |
| 89 | | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN) PORT_PLAYER(2) |
| 90 | | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT) PORT_PLAYER(2) |
| 91 | | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(2) |
| 83 | PORT_START("PAD1H") /* Joypad 1 - H */ |
| 84 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P1 Button B") PORT_PLAYER(1) |
| 85 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P1 Button Y") PORT_PLAYER(1) |
| 86 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_PLAYER(1) |
| 87 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START ) PORT_PLAYER(1) |
| 88 | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(1) |
| 89 | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) |
| 90 | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) |
| 91 | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) |
| 92 | 92 | |
| 93 | | PORT_START("PAD3L") /* IN 4 : Joypad 3 - L */ |
| 94 | | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("P3 Button A") PORT_PLAYER(3) |
| 95 | | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4) PORT_NAME("P3 Button X") PORT_PLAYER(3) |
| 96 | | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5) PORT_NAME("P3 Button L") PORT_PLAYER(3) |
| 97 | | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6) PORT_NAME("P3 Button R") PORT_PLAYER(3) |
| 98 | | PORT_START("PAD3H") /* IN 5 : Joypad 3 - H */ |
| 99 | | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("P3 Button B") PORT_PLAYER(3) |
| 100 | | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("P3 Button Y") PORT_PLAYER(3) |
| 101 | | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT) PORT_PLAYER(3) |
| 102 | | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START) PORT_PLAYER(3) |
| 103 | | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP) PORT_PLAYER(3) |
| 104 | | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN) PORT_PLAYER(3) |
| 105 | | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT) PORT_PLAYER(3) |
| 106 | | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(3) |
| 93 | PORT_START("PAD2L") /* Joypad 2 - L */ |
| 94 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P2 Button A") PORT_PLAYER(2) |
| 95 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P2 Button X") PORT_PLAYER(2) |
| 96 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P2 Button L") PORT_PLAYER(2) |
| 97 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P2 Button R") PORT_PLAYER(2) |
| 107 | 98 | |
| 108 | | PORT_START("PAD4L") /* IN 6 : Joypad 4 - L */ |
| 109 | | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("P4 Button A") PORT_PLAYER(4) |
| 110 | | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4) PORT_NAME("P4 Button X") PORT_PLAYER(4) |
| 111 | | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5) PORT_NAME("P4 Button L") PORT_PLAYER(4) |
| 112 | | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6) PORT_NAME("P4 Button R") PORT_PLAYER(4) |
| 113 | | PORT_START("PAD4H") /* IN 7 : Joypad 4 - H */ |
| 114 | | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("P4 Button B") PORT_PLAYER(4) |
| 115 | | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("P4 Button Y") PORT_PLAYER(4) |
| 116 | | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT) PORT_PLAYER(4) |
| 117 | | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START) PORT_PLAYER(4) |
| 118 | | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP) PORT_PLAYER(4) |
| 119 | | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN) PORT_PLAYER(4) |
| 120 | | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT) PORT_PLAYER(4) |
| 121 | | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(4) |
| 99 | PORT_START("PAD2H") /* Joypad 2 - H */ |
| 100 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P2 Button B") PORT_PLAYER(2) |
| 101 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P2 Button Y") PORT_PLAYER(2) |
| 102 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_PLAYER(2) |
| 103 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START ) PORT_PLAYER(2) |
| 104 | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(2) |
| 105 | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) |
| 106 | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) |
| 107 | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) |
| 122 | 108 | |
| 123 | | PORT_START("INTERNAL") /* IN 8 : Configuration */ |
| 109 | PORT_START("PAD3L") /* Joypad 3 - L */ |
| 110 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P3 Button A") PORT_PLAYER(3) |
| 111 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P3 Button X") PORT_PLAYER(3) |
| 112 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P3 Button L") PORT_PLAYER(3) |
| 113 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P3 Button R") PORT_PLAYER(3) |
| 114 | |
| 115 | PORT_START("PAD3H") /* Joypad 3 - H */ |
| 116 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P3 Button B") PORT_PLAYER(3) |
| 117 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P3 Button Y") PORT_PLAYER(3) |
| 118 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_PLAYER(3) |
| 119 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START ) PORT_PLAYER(3) |
| 120 | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(3) |
| 121 | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(3) |
| 122 | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(3) |
| 123 | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(3) |
| 124 | |
| 125 | PORT_START("PAD4L") /* Joypad 4 - L */ |
| 126 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P4 Button A") PORT_PLAYER(4) |
| 127 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P4 Button X") PORT_PLAYER(4) |
| 128 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P4 Button L") PORT_PLAYER(4) |
| 129 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P4 Button R") PORT_PLAYER(4) |
| 130 | |
| 131 | PORT_START("PAD4H") /* Joypad 4 - H */ |
| 132 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P4 Button B") PORT_PLAYER(4) |
| 133 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P4 Button Y") PORT_PLAYER(4) |
| 134 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_PLAYER(4) |
| 135 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START ) PORT_PLAYER(4) |
| 136 | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(4) |
| 137 | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(4) |
| 138 | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(4) |
| 139 | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(4) |
| 140 | |
| 141 | PORT_START("INTERNAL") /* Configuration */ |
| 124 | 142 | PORT_CONFNAME( 0x1, 0x1, "Enforce 32 sprites/line" ) |
| 125 | | PORT_CONFSETTING( 0x0, DEF_STR( No ) ) |
| 143 | PORT_CONFSETTING( 0x0, DEF_STR( No ) ) |
| 126 | 144 | PORT_CONFSETTING( 0x1, DEF_STR( Yes ) ) |
| 127 | 145 | |
| 128 | 146 | #ifdef MAME_DEBUG |
| 129 | | PORT_START("DEBUG1") /* IN 9 : debug switches */ |
| 147 | PORT_START("DEBUG1") /* debug switches */ |
| 130 | 148 | PORT_DIPNAME( 0x3, 0x0, "Browse tiles" ) |
| 131 | 149 | PORT_DIPSETTING( 0x0, DEF_STR( Off ) ) |
| 132 | | PORT_DIPSETTING( 0x1, "2bpl" ) |
| 133 | | PORT_DIPSETTING( 0x2, "4bpl" ) |
| 134 | | PORT_DIPSETTING( 0x3, "8bpl" ) |
| 150 | PORT_DIPSETTING( 0x1, "2bpl" ) |
| 151 | PORT_DIPSETTING( 0x2, "4bpl" ) |
| 152 | PORT_DIPSETTING( 0x3, "8bpl" ) |
| 135 | 153 | PORT_DIPNAME( 0xc, 0x0, "Browse maps" ) |
| 136 | 154 | PORT_DIPSETTING( 0x0, DEF_STR( Off ) ) |
| 137 | | PORT_DIPSETTING( 0x4, "2bpl" ) |
| 138 | | PORT_DIPSETTING( 0x8, "4bpl" ) |
| 139 | | PORT_DIPSETTING( 0xc, "8bpl" ) |
| 155 | PORT_DIPSETTING( 0x4, "2bpl" ) |
| 156 | PORT_DIPSETTING( 0x8, "4bpl" ) |
| 157 | PORT_DIPSETTING( 0xc, "8bpl" ) |
| 140 | 158 | |
| 141 | | PORT_START("DEBUG2") /* IN 10 : debug switches */ |
| 142 | | PORT_BIT( 0x1, IP_ACTIVE_HIGH, IPT_BUTTON7) PORT_NAME("Toggle BG 1") PORT_PLAYER(2) |
| 143 | | PORT_BIT( 0x2, IP_ACTIVE_HIGH, IPT_BUTTON8) PORT_NAME("Toggle BG 2") PORT_PLAYER(2) |
| 144 | | PORT_BIT( 0x4, IP_ACTIVE_HIGH, IPT_BUTTON9) PORT_NAME("Toggle BG 3") PORT_PLAYER(2) |
| 145 | | PORT_BIT( 0x8, IP_ACTIVE_HIGH, IPT_BUTTON10) PORT_NAME("Toggle BG 4") PORT_PLAYER(2) |
| 146 | | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON7) PORT_NAME("Toggle Objects") PORT_PLAYER(3) |
| 147 | | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON8) PORT_NAME("Toggle Main/Sub") PORT_PLAYER(3) |
| 148 | | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON9) PORT_NAME("Toggle Back col") PORT_PLAYER(3) |
| 149 | | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON10) PORT_NAME("Toggle Windows") PORT_PLAYER(3) |
| 159 | PORT_START("DEBUG2") /* debug switches */ |
| 160 | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON7 ) PORT_NAME("Toggle BG 1") PORT_PLAYER(2) |
| 161 | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON8 ) PORT_NAME("Toggle BG 2") PORT_PLAYER(2) |
| 162 | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON9 ) PORT_NAME("Toggle BG 3") PORT_PLAYER(2) |
| 163 | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON10 ) PORT_NAME("Toggle BG 4") PORT_PLAYER(2) |
| 164 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON7 ) PORT_NAME("Toggle Objects") PORT_PLAYER(3) |
| 165 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON8 ) PORT_NAME("Toggle Main/Sub") PORT_PLAYER(3) |
| 166 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON9 ) PORT_NAME("Toggle Back col") PORT_PLAYER(3) |
| 167 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON10 ) PORT_NAME("Toggle Windows") PORT_PLAYER(3) |
| 150 | 168 | |
| 151 | 169 | PORT_START("DEBUG3") /* IN 11 : debug input */ |
| 152 | | PORT_BIT( 0x1, IP_ACTIVE_HIGH, IPT_BUTTON9) PORT_NAME("Pal prev") |
| 153 | | PORT_BIT( 0x2, IP_ACTIVE_HIGH, IPT_BUTTON10) PORT_NAME("Pal next") |
| 154 | | PORT_BIT( 0x4, IP_ACTIVE_HIGH, IPT_BUTTON7) PORT_NAME("Toggle Transparency") PORT_PLAYER(4) |
| 170 | PORT_BIT( 0x1, IP_ACTIVE_HIGH, IPT_BUTTON9 ) PORT_NAME("Pal prev") |
| 171 | PORT_BIT( 0x2, IP_ACTIVE_HIGH, IPT_BUTTON10 ) PORT_NAME("Pal next") |
| 172 | PORT_BIT( 0x4, IP_ACTIVE_HIGH, IPT_BUTTON7 ) PORT_NAME("Toggle Transparency") PORT_PLAYER(4) |
| 155 | 173 | #endif |
| 156 | 174 | INPUT_PORTS_END |
| 157 | 175 | |
| 158 | | static const custom_sound_interface snes_sound_interface = |
| 159 | | { snes_sh_start, 0, 0 }; |
| 160 | 176 | |
| 161 | | /* Loads the battery backed RAM into the appropriate memory area */ |
| 162 | | static void snes_load_sram(void) |
| 163 | | { |
| 164 | | UINT8 ii; |
| 165 | | UINT8 *battery_ram, *ptr; |
| 177 | /*************************************************************************** |
| 166 | 178 | |
| 167 | | battery_ram = malloc_or_die( snes_cart.sram_max ); |
| 168 | | ptr = battery_ram; |
| 169 | | image_battery_load( image_from_devtype_and_index(IO_CARTSLOT,0), battery_ram, snes_cart.sram_max ); |
| 179 | Sound interface |
| 170 | 180 | |
| 171 | | if( snes_cart.mode == SNES_MODE_20 ) |
| 172 | | { |
| 173 | | for( ii = 0; ii < 8; ii++ ) |
| 174 | | { |
| 175 | | memmove( &snes_ram[0x700000 + (ii * 0x010000)], ptr, 0x7fff ); |
| 176 | | ptr += 0x7fff; |
| 177 | | } |
| 178 | | } |
| 179 | | else |
| 180 | | { |
| 181 | | for( ii = 0; ii < 16; ii++ ) |
| 182 | | { |
| 183 | | memmove( &snes_ram[0x306000 + (ii * 0x010000)], ptr, 0x1fff ); |
| 184 | | ptr += 0x1fff; |
| 185 | | } |
| 186 | | } |
| 181 | ***************************************************************************/ |
| 187 | 182 | |
| 188 | | free( battery_ram ); |
| 189 | | } |
| 183 | static const custom_sound_interface snes_sound_interface = |
| 184 | { snes_sh_start, 0, 0 }; |
| 190 | 185 | |
| 191 | | /* Saves the battery backed RAM from the appropriate memory area */ |
| 192 | | static void snes_save_sram(void) |
| 193 | | { |
| 194 | | UINT8 ii; |
| 195 | | UINT8 *battery_ram, *ptr; |
| 196 | 186 | |
| 197 | | battery_ram = malloc_or_die( snes_cart.sram_max ); |
| 198 | | ptr = battery_ram; |
| 199 | 187 | |
| 200 | | if( snes_cart.mode == SNES_MODE_20 ) |
| 201 | | { |
| 202 | | for( ii = 0; ii < 8; ii++ ) |
| 203 | | { |
| 204 | | memmove( ptr, &snes_ram[0x700000 + (ii * 0x010000)], 0x8000 ); |
| 205 | | ptr += 0x8000; |
| 206 | | } |
| 207 | | } |
| 208 | | else |
| 209 | | { |
| 210 | | for( ii = 0; ii < 16; ii++ ) |
| 211 | | { |
| 212 | | memmove( ptr, &snes_ram[0x306000 + (ii * 0x010000)], 0x2000 ); |
| 213 | | ptr += 0x2000; |
| 214 | | } |
| 215 | | } |
| 188 | /*************************************************************************** |
| 216 | 189 | |
| 217 | | image_battery_save( image_from_devtype_and_index(IO_CARTSLOT,0), battery_ram, snes_cart.sram_max ); |
| 190 | Machine driver |
| 218 | 191 | |
| 219 | | free( battery_ram ); |
| 220 | | } |
| 192 | ***************************************************************************/ |
| 221 | 193 | |
| 222 | | |
| 223 | | |
| 224 | | static void snes_machine_stop(running_machine *machine) |
| 225 | | { |
| 226 | | /* Save SRAM */ |
| 227 | | if( snes_cart.sram > 0 ) |
| 228 | | snes_save_sram(); |
| 229 | | } |
| 230 | | |
| 231 | | static MACHINE_START( snes_mess ) |
| 232 | | { |
| 233 | | add_exit_callback(machine, snes_machine_stop); |
| 234 | | MACHINE_START_CALL(snes); |
| 235 | | } |
| 236 | | |
| 237 | | static DEVICE_IMAGE_LOAD( snes_cart ) |
| 238 | | { |
| 239 | | int i; |
| 240 | | running_machine *machine = image->machine; |
| 241 | | UINT16 totalblocks, readblocks; |
| 242 | | UINT32 offset; |
| 243 | | UINT8 header[512], sample[0xffff]; |
| 244 | | UINT8 valid_mode20, valid_mode21; |
| 245 | | |
| 246 | | /* Cart types */ |
| 247 | | static const struct |
| 248 | | { |
| 249 | | INT16 Code; |
| 250 | | const char *Name; |
| 251 | | } CartTypes[] = |
| 252 | | { |
| 253 | | { 0, "ROM" }, |
| 254 | | { 1, "ROM,RAM" }, |
| 255 | | { 2, "ROM,SRAM" }, |
| 256 | | { 3, "ROM,DSP1" }, |
| 257 | | { 4, "ROM,RAM,DSP1" }, |
| 258 | | { 5, "ROM,SRAM,DSP1" }, |
| 259 | | { 19, "ROM,SuperFX" }, |
| 260 | | { 21, "ROM,SRAM,SuperFX"}, |
| 261 | | { 69, "ROM,SRAM,S-DD1" }, |
| 262 | | {227, "ROM,Z80GB" }, |
| 263 | | {243, "ROM,?(1)" }, |
| 264 | | {246, "ROM,DSP2" }, |
| 265 | | { -1, "UNKNOWN" } |
| 266 | | }; |
| 267 | | |
| 268 | | /* Some known countries */ |
| 269 | | const char *countries[] = |
| 270 | | { |
| 271 | | "Japan (NTSC)", |
| 272 | | "USA (NTSC)", |
| 273 | | "Australia, Europe, Oceania & Asia (PAL)", |
| 274 | | "Sweden (PAL)", |
| 275 | | "Finland (PAL)", |
| 276 | | "Denmark (PAL)", |
| 277 | | "France (PAL)", |
| 278 | | "Holland (PAL)", |
| 279 | | "Spain (PAL)", |
| 280 | | "Germany, Austria & Switzerland (PAL)", |
| 281 | | "Italy (PAL)", |
| 282 | | "Hong Kong & China (PAL)", |
| 283 | | "Indonesia (PAL)", |
| 284 | | "South Korea (NTSC)", |
| 285 | | "UNKNOWN" |
| 286 | | }; |
| 287 | | |
| 288 | | memory_region_alloc(machine, "main", 0x1000000,0); |
| 289 | | |
| 290 | | snes_ram = memory_region( machine, "main" ); |
| 291 | | memset( snes_ram, 0, 0x1000000 ); |
| 292 | | |
| 293 | | /* Check for a header (512 bytes) */ |
| 294 | | offset = 512; |
| 295 | | image_fread( image, header, 512 ); |
| 296 | | if( (header[8] == 0xaa) && (header[9] == 0xbb) && (header[10] == 0x04) ) |
| 297 | | { |
| 298 | | /* Found an SWC identifier */ |
| 299 | | logerror( "Found header(SWC) - Skipped\n" ); |
| 300 | | } |
| 301 | | else if( (header[0] | (header[1] << 8)) == (((image_length(image) - 512) / 1024) / 8) ) |
| 302 | | { |
| 303 | | /* Some headers have the rom size at the start, if this matches with the |
| 304 | | * actual rom size, we probably have a header */ |
| 305 | | logerror( "Found header(size) - Skipped\n" ); |
| 306 | | } |
| 307 | | else if( (image_length(image) % 0x8000) == 512 ) |
| 308 | | { |
| 309 | | /* As a last check we'll see if there's exactly 512 bytes extra to this |
| 310 | | * image. */ |
| 311 | | logerror( "Found header(extra) - Skipped\n" ); |
| 312 | | } |
| 313 | | else |
| 314 | | { |
| 315 | | /* No header found so go back to the start of the file */ |
| 316 | | logerror( "No header found.\n" ); |
| 317 | | offset = 0; |
| 318 | | image_fseek( image, offset, SEEK_SET ); |
| 319 | | } |
| 320 | | |
| 321 | | /* We need to take a sample of 128kb to test what mode we need to be in */ |
| 322 | | image_fread( image, sample, 0xffff ); |
| 323 | | image_fseek( image, offset, SEEK_SET ); /* Rewind */ |
| 324 | | /* Now to determine if this is a lo-ROM or a hi-ROM */ |
| 325 | | valid_mode20 = snes_validate_infoblock( sample, 0x7fc0 ); |
| 326 | | valid_mode21 = snes_validate_infoblock( sample, 0xffc0 ); |
| 327 | | if( valid_mode20 >= valid_mode21 ) |
| 328 | | { |
| 329 | | snes_cart.mode = SNES_MODE_20; |
| 330 | | snes_cart.sram_max = 0x40000; |
| 331 | | } |
| 332 | | else if( valid_mode21 > valid_mode20 ) |
| 333 | | { |
| 334 | | snes_cart.mode = SNES_MODE_21; |
| 335 | | snes_cart.sram_max = 0x20000; |
| 336 | | } |
| 337 | | |
| 338 | | /* Find the number of blocks in this ROM */ |
| 339 | | totalblocks = ((image_length(image) - offset) >> (snes_cart.mode == SNES_MODE_20 ? 15 : 16)); |
| 340 | | |
| 341 | | /* FIXME: Insert crc check here */ |
| 342 | | |
| 343 | | readblocks = 0; |
| 344 | | if( snes_cart.mode == SNES_MODE_20 ) |
| 345 | | { |
| 346 | | /* In mode 20, all blocks are 32kb. There are upto 96 blocks, giving a |
| 347 | | * total of 24mbit(3mb) of ROM. |
| 348 | | * The first 48 blocks are located in banks 0x00 to 0x2f at address |
| 349 | | * 0x8000. They are mirrored in banks 0x80 to 0xaf. |
| 350 | | * The next 16 blocks are located in banks 0x30 to 0x3f at address |
| 351 | | * 0x8000. They are mirrored in banks 0xb0 to 0xbf. |
| 352 | | * The final 32 blocks are located in banks 0x40 - 0x5f at address |
| 353 | | * 0x8000. They are mirrored in banks 0xc0 to 0xdf. |
| 354 | | */ |
| 355 | | i = 0; |
| 356 | | while( i < 96 && readblocks <= totalblocks ) |
| 357 | | { |
| 358 | | image_fread( image, &snes_ram[(i++ * 0x10000) + 0x8000], 0x8000); |
| 359 | | readblocks++; |
| 360 | | } |
| 361 | | } |
| 362 | | else /* Mode 21 */ |
| 363 | | { |
| 364 | | /* In mode 21, all blocks are 64kb. There are upto 96 blocks, giving a |
| 365 | | * total of 48mbit(6mb) of ROM. |
| 366 | | * The first 64 blocks are located in banks 0xc0 to 0xff. The top 32k of |
| 367 | | * each bank is mirrored in banks 0x00 to 0x3f. |
| 368 | | * The final 32 blocks are located in banks 0x40 to 0x5f. |
| 369 | | */ |
| 370 | | |
| 371 | | /* read first 64 blocks */ |
| 372 | | i = 0; |
| 373 | | while( i < 64 && readblocks <= totalblocks ) |
| 374 | | { |
| 375 | | image_fread( image, &snes_ram[0xc00000 + (i++ * 0x10000)], 0x10000); |
| 376 | | readblocks++; |
| 377 | | } |
| 378 | | /* read the next 32 blocks */ |
| 379 | | i = 0; |
| 380 | | while( i < 32 && readblocks <= totalblocks ) |
| 381 | | { |
| 382 | | image_fread( image, &snes_ram[0x400000 + (i++ * 0x10000)], 0x10000); |
| 383 | | readblocks++; |
| 384 | | } |
| 385 | | } |
| 386 | | |
| 387 | | /* Find the amount of sram */ |
| 388 | | snes_cart.sram = snes_r_bank1(machine, 0x00ffd8); |
| 389 | | if( snes_cart.sram > 0 ) |
| 390 | | { |
| 391 | | snes_cart.sram = ((1 << (snes_cart.sram + 3)) / 8); |
| 392 | | if( snes_cart.sram > snes_cart.sram_max ) |
| 393 | | snes_cart.sram = snes_cart.sram_max; |
| 394 | | } |
| 395 | | |
| 396 | | /* Log snes_cart information */ |
| 397 | | { |
| 398 | | char title[21], romid[4], companyid[2]; |
| 399 | | UINT8 country; |
| 400 | | logerror( "ROM DETAILS\n" ); |
| 401 | | logerror( "\tTotal blocks: %d (%dmb)\n", totalblocks, totalblocks / (snes_cart.mode == SNES_MODE_20 ? 32 : 16) ); |
| 402 | | logerror( "\tROM bank size: %s (LoROM: %d , HiROM: %d)\n", (snes_cart.mode == SNES_MODE_20) ? "LoROM" : "HiROM", valid_mode20, valid_mode21 ); |
| 403 | | for( i = 0; i < 2; i++ ) |
| 404 | | companyid[i] = snes_r_bank1(machine, 0x00ffb0 + i); |
| 405 | | logerror( "\tCompany ID: %s\n", companyid ); |
| 406 | | for( i = 0; i < 4; i++ ) |
| 407 | | romid[i] = snes_r_bank1(machine, 0x00ffb2 + i); |
| 408 | | logerror( "\tROM ID: %s\n", romid ); |
| 409 | | logerror( "HEADER DETAILS\n" ); |
| 410 | | for( i = 0; i < 21; i++ ) |
| 411 | | title[i] = snes_r_bank1(machine, 0x00ffc0 + i); |
| 412 | | logerror( "\tName: %s\n", title ); |
| 413 | | logerror( "\tSpeed: %s [%d]\n", ((snes_r_bank1(machine, 0x00ffd5) & 0xf0)) ? "FastROM" : "SlowROM", (snes_r_bank1(machine, 0x00ffd5) & 0xf0) >> 4 ); |
| 414 | | logerror( "\tBank size: %s [%d]\n", (snes_r_bank1(machine, 0x00ffd5) & 0xf) ? "HiROM" : "LoROM", snes_r_bank1(machine, 0x00ffd5) & 0xf ); |
| 415 | | for( i = 0; i < 12; i++ ) |
| 416 | | { |
| 417 | | if( CartTypes[i].Code == snes_r_bank1(machine, 0x00ffd6) ) |
| 418 | | break; |
| 419 | | } |
| 420 | | logerror( "\tType: %s [%d]\n", CartTypes[i].Name, snes_r_bank1(machine, 0x00ffd6) ); |
| 421 | | logerror( "\tSize: %d megabits [%d]\n", 1 << (snes_r_bank1(machine, 0x00ffd7) - 7), snes_r_bank1(machine, 0x00ffd7) ); |
| 422 | | logerror( "\tSRAM: %d kilobits [%d]\n", snes_cart.sram * 8, snes_ram[0xffd8] ); |
| 423 | | country = snes_r_bank1(machine, 0x00ffd9); |
| 424 | | if( country > 14 ) |
| 425 | | country = 14; |
| 426 | | logerror( "\tCountry: %s [%d]\n", countries[country], snes_r_bank1(machine, 0x00ffd9) ); |
| 427 | | logerror( "\tLicense: %s [%X]\n", "", snes_r_bank1(machine, 0x00ffda) ); |
| 428 | | logerror( "\tVersion: 1.%d\n", snes_r_bank1(machine, 0x00ffdb) ); |
| 429 | | logerror( "\tInv Checksum: %X %X\n", snes_r_bank1(machine, 0x00ffdd), snes_r_bank1(machine, 0x00ffdc) ); |
| 430 | | logerror( "\tChecksum: %X %X\n", snes_r_bank1(machine, 0x00ffdf), snes_r_bank1(machine, 0x00ffde) ); |
| 431 | | logerror( "\tNMI Address: %2X%2Xh\n", snes_r_bank1(machine, 0x00fffb), snes_r_bank1(machine, 0x00fffa) ); |
| 432 | | logerror( "\tStart Address: %2X%2Xh\n", snes_r_bank1(machine, 0x00fffd), snes_r_bank1(machine, 0x00fffc) ); |
| 433 | | } |
| 434 | | |
| 435 | | /* Load SRAM */ |
| 436 | | snes_load_sram(); |
| 437 | | |
| 438 | | /* All done */ |
| 439 | | return INIT_PASS; |
| 440 | | } |
| 441 | | |
| 442 | | |
| 443 | 194 | static MACHINE_DRIVER_START( snes ) |
| 444 | 195 | /* basic machine hardware */ |
| 445 | 196 | MDRV_CPU_ADD("main", G65816, MCLK_NTSC/6) /* 2.68Mhz, also 3.58Mhz */ |
| r3331 | r3332 | |
| 479 | 230 | MDRV_SCREEN_RAW_PARAMS(DOTCLK_PAL, SNES_HTOTAL, 0, SNES_SCR_WIDTH, SNES_VTOTAL_PAL, 0, SNES_SCR_HEIGHT_PAL) |
| 480 | 231 | MACHINE_DRIVER_END |
| 481 | 232 | |
| 482 | | static void snes_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 483 | | { |
| 484 | | /* cartslot */ |
| 485 | | switch(state) |
| 486 | | { |
| 487 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 488 | | case MESS_DEVINFO_INT_COUNT: info->i = 1; break; |
| 489 | | case MESS_DEVINFO_INT_MUST_BE_LOADED: info->i = 1; break; |
| 490 | 233 | |
| 491 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 492 | | case MESS_DEVINFO_PTR_LOAD: info->load = DEVICE_IMAGE_LOAD_NAME(snes_cart); break; |
| 493 | | |
| 494 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 495 | | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "smc,sfc,fig,swc"); break; |
| 496 | | |
| 497 | | default: cartslot_device_getinfo(devclass, state, info); break; |
| 498 | | } |
| 499 | | } |
| 500 | | |
| 501 | | static SYSTEM_CONFIG_START(snes) |
| 502 | | CONFIG_DEVICE(snes_cartslot_getinfo) |
| 503 | | SYSTEM_CONFIG_END |
| 504 | | |
| 505 | 234 | /*************************************************************************** |
| 506 | 235 | |
| 507 | | Game driver(s) |
| 236 | ROM definition(s) |
| 508 | 237 | |
| 509 | 238 | ***************************************************************************/ |
| 510 | 239 | |
| r3331 | r3332 | |
| 522 | 251 | ROM_LOAD("dsp1data.bin", 0x000000, 0x000800, CRC(4b02d66d) SHA1(1534f4403d2a0f68ba6e35186fe7595d33de34b1)) |
| 523 | 252 | ROM_END |
| 524 | 253 | |
| 254 | |
| 255 | |
| 256 | /*************************************************************************** |
| 257 | |
| 258 | System configuration(s) |
| 259 | |
| 260 | ***************************************************************************/ |
| 261 | |
| 262 | static SYSTEM_CONFIG_START(snes) |
| 263 | CONFIG_DEVICE(snes_cartslot_getinfo) |
| 264 | SYSTEM_CONFIG_END |
| 265 | |
| 266 | |
| 267 | |
| 268 | /*************************************************************************** |
| 269 | |
| 270 | Game driver(s) |
| 271 | |
| 272 | ***************************************************************************/ |
| 273 | |
| 525 | 274 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME FLAGS */ |
| 526 | 275 | CONS( 1989, snes, 0, 0, snes, snes, 0, snes, "Nintendo", "Super Nintendo Entertainment System (NTSC)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 527 | 276 | CONS( 1991, snespal, snes, 0, snespal, snes, 0, snes, "Nintendo", "Super Nintendo Entertainment System (PAL)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |