src/mess/machine/snescart.c
| r3336 | r3337 | |
| 10 | 10 | #include "includes/snes.h" |
| 11 | 11 | #include "devices/cartslot.h" |
| 12 | 12 | |
| 13 | |
| 14 | /****** Cart types ******/ |
| 15 | |
| 13 | 16 | static int cart_type; |
| 14 | 17 | |
| 18 | enum |
| 19 | { |
| 20 | STANDARD = 0, |
| 21 | STANDARD_RAM, |
| 22 | STANDARD_SRAM, |
| 23 | DSP1, |
| 24 | DSP1_RAM, |
| 25 | DSP1_SRAM, |
| 26 | DSP2, |
| 27 | DSP3, |
| 28 | DSP4, |
| 29 | SUPERFX, |
| 30 | SUPERFX_SRAM, |
| 31 | SA1, |
| 32 | SA1_SRAM, |
| 33 | SDD1, |
| 34 | SDD1_SRAM, |
| 35 | OBC1, |
| 36 | RTC, |
| 37 | SGB, |
| 38 | C4, |
| 39 | ST010, |
| 40 | ST011, |
| 41 | ST018, |
| 42 | SPC7110, |
| 43 | SPC7110_RTC, |
| 44 | UNKNOWN, |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | /****** Strings for Cart Header Logging ******/ |
| 49 | |
| 50 | #define UNK "Unknown" |
| 51 | |
| 52 | /* Some known type of cart */ |
| 53 | static const char *types[] = |
| 54 | { |
| 55 | "ROM", |
| 56 | "ROM, RAM", |
| 57 | "ROM, SRAM", |
| 58 | "ROM, DSP-1", |
| 59 | "ROM, RAM, DSP-1", |
| 60 | "ROM, SRAM, DSP-1", |
| 61 | "ROM, SRAM, DSP-2", |
| 62 | "ROM, SRAM, DSP-3", |
| 63 | "ROM, DSP-4", |
| 64 | "ROM, Super FX / FX2", |
| 65 | "ROM, SRAM, Super FX / FX2", |
| 66 | "ROM, SA-1", |
| 67 | "ROM, SRAM, SA-1", |
| 68 | "ROM, S-DD1", |
| 69 | "ROM, SRAM, S-DD1", |
| 70 | "ROM, SRAM, OBC-1", |
| 71 | "ROM, SRAM, S-RTC", |
| 72 | "ROM, Z80GB (Super Game Boy)", |
| 73 | "ROM, C4", |
| 74 | "ROM, SRAM, Seta ST-010", |
| 75 | "ROM, SRAM, Seta ST-011", |
| 76 | "ROM, SRAM, Seta ST-018", |
| 77 | "ROM, SRAM, SPC7110", |
| 78 | "ROM, SRAM, SPC7110, RTC", |
| 79 | UNK, // to add: Satellaview BS-X detection |
| 80 | }; |
| 81 | |
| 82 | /* Some known countries */ |
| 83 | static const char *countries[] = |
| 84 | { |
| 85 | /* 0*/ "Japan (NTSC)", "USA & Canada (NTSC)", "Europe, Oceania & Asia (PAL)", "Sweden (PAL)", |
| 86 | /* 4*/ "Finland (PAL)", "Denmark (PAL)", "France (PAL)", "Holland (PAL)", |
| 87 | /* 8*/ "Spain (PAL)", "Germany, Austria & Switzerland (PAL)", "Italy (PAL)", "Hong Kong & China (PAL)", |
| 88 | /* c*/ "Indonesia (PAL)", "South Korea (NTSC)", UNK, UNK, |
| 89 | }; |
| 90 | |
| 91 | /* Some known companies (integrations to the list from Snes9x) */ |
| 92 | static const char *companies[] = |
| 93 | { |
| 94 | /* 0*/ "Invalid", "Nintendo", "Ajinomoto", "Imagineer-Zoom", "Chris Gray Enterprises Inc.", "Zamuse", "Falcom", UNK, |
| 95 | /* 8*/ "Capcom", "HOT-B", "Jaleco", "Coconuts", "Rage Software", "Micronet", "Technos", "Mebio Software", |
| 96 | /*10*/ "SHOUEi System", "Starfish", "Gremlin Graphics", "Electronic Arts", "NCS / Masaya", "COBRA Team", "Human/Field", "KOEI", |
| 97 | /*18*/ "Hudson Soft", "Game Village", "Yanoman", UNK, "Tecmo", UNK, "Open System", "Virgin Games", |
| 98 | /*20*/ "KSS", "Sunsoft", "POW", "Micro World", UNK, UNK, "Enix", "Loriciel/Electro Brain", |
| 99 | /*28*/ "Kemco", "Seta Co.,Ltd.", "Culture Brain", "Irem Japan", "Pal Soft", "Visit Co.,Ltd.", "INTEC Inc.", "System Sacom Corp.", |
| 100 | /*30*/ "Viacom New Media", "Carrozzeria", "Dynamic", "Nintendo", "Magifact", "Hect", UNK, UNK, |
| 101 | /*38*/ "Capcom Europe", "Accolade Europe", UNK, "Arcade Zone", "Empire Software", "Loriciel", "Gremlin Graphics", UNK, |
| 102 | /*40*/ "Seika Corp.", "UBI Soft", UNK, UNK, "LifeFitness Exertainment", UNK, "System 3", "Spectrum Holobyte", |
| 103 | /*48*/ UNK, "Irem", UNK, "Raya Systems/Sculptured Software", "Renovation Products", "Malibu Games/Black Pearl", UNK, "U.S. Gold", |
| 104 | /*50*/ "Absolute Entertainment", "Acclaim", "Activision", "American Sammy", "GameTek", "Hi Tech Expressions", "LJN Toys", UNK, |
| 105 | /*58*/ UNK, UNK, "Mindscape", "Romstar, Inc.", UNK, "Tradewest", UNK, "American Softworks Corp.", |
| 106 | /*60*/ "Titus", "Virgin Interactive Entertainment", "Maxis", "Origin/FCI/Pony Canyon", UNK, UNK, UNK, "Ocean", |
| 107 | /*68*/ UNK, "Electronic Arts", UNK, "Laser Beam", UNK, UNK, "Elite", "Electro Brain", |
| 108 | /*70*/ "Infogrames", "Interplay", "LucasArts", "Parker Brothers", "Konami", "STORM", UNK, UNK, |
| 109 | /*78*/ "THQ Software", "Accolade Inc.", "Triffix Entertainment", UNK, "Microprose", UNK, UNK, "Kemco", |
| 110 | /*80*/ "Misawa", "Teichio", "Namco Ltd.", "Lozc", "Koei", UNK, "Tokuma Shoten Intermedia", "Tsukuda Original", |
| 111 | /*88*/ "DATAM-Polystar", UNK, UNK, "Bullet-Proof Software", "Vic Tokai", UNK, "Character Soft", "I\'\'Max", |
| 112 | /*90*/ "Takara", "CHUN Soft", "Video System Co., Ltd.", "BEC", UNK, "Varie", "Yonezawa / S'Pal Corp.", "Kaneco", |
| 113 | /*98*/ UNK, "Pack in Video", "Nichibutsu", "TECMO", "Imagineer Co.", UNK, UNK, UNK, |
| 114 | /*a0*/ "Telenet", "Hori", UNK, UNK, "Konami", "K.Amusement Leasing Co.", UNK, "Takara", |
| 115 | /*a8*/ UNK, "Technos Jap.", "JVC", UNK, "Toei Animation", "Toho", UNK, "Namco Ltd.", |
| 116 | /*b0*/ "Media Rings Corp.", "ASCII Co. Activison", "Bandai", UNK, "Enix America", UNK, "Halken", UNK, |
| 117 | /*b8*/ UNK, UNK, "Culture Brain", "Sunsoft", "Toshiba EMI", "Sony Imagesoft", UNK, "Sammy", |
| 118 | /*c0*/ "Taito", UNK, "Kemco", "Square", "Tokuma Soft", "Data East", "Tonkin House", UNK, |
| 119 | /*c8*/ "KOEI", UNK, "Konami USA", "NTVIC", UNK, "Meldac", "Pony Canyon", "Sotsu Agency/Sunrise", |
| 120 | /*d0*/ "Disco/Taito", "Sofel", "Quest Corp.", "Sigma", "Ask Kodansha Co., Ltd.", UNK, "Naxat", UNK, |
| 121 | /*d8*/ "Capcom Co., Ltd.", "Banpresto", "Tomy", "Acclaim", UNK, "NCS", "Human Entertainment", "Altron", |
| 122 | /*e0*/ "Jaleco", UNK, "Yutaka", UNK, "T&ESoft", "EPOCH Co.,Ltd.", UNK, "Athena", |
| 123 | /*e8*/ "Asmik", "Natsume", "King Records", "Atlus", "Sony Music Entertainment", UNK, "IGS", UNK, |
| 124 | /*f0*/ UNK, "Motown Software", "Left Field Entertainment", "Beam Software", "Tec Magik", UNK, UNK, UNK, |
| 125 | /*f8*/ UNK, "Cybersoft", UNK, "Psygnosis", UNK, UNK, "Davidson", UNK, |
| 126 | }; |
| 127 | |
| 128 | |
| 129 | /* We use this to convert the company_id in the header to int value to be passed in companies[] */ |
| 130 | static int char_to_int_conv( char id ) |
| 131 | { |
| 132 | int value; |
| 133 | |
| 134 | if (id == '1') value = 0x01; |
| 135 | else if (id == '2') value = 0x02; |
| 136 | else if (id == '3') value = 0x03; |
| 137 | else if (id == '4') value = 0x04; |
| 138 | else if (id == '5') value = 0x05; |
| 139 | else if (id == '6') value = 0x06; |
| 140 | else if (id == '7') value = 0x07; |
| 141 | else if (id == '8') value = 0x08; |
| 142 | else if (id == '9') value = 0x09; |
| 143 | else if (id == 'A') value = 0x0a; |
| 144 | else if (id == 'B') value = 0x0b; |
| 145 | else if (id == 'C') value = 0x0c; |
| 146 | else if (id == 'D') value = 0x0d; |
| 147 | else if (id == 'E') value = 0x0e; |
| 148 | else if (id == 'F') value = 0x0f; |
| 149 | else value = 0x00; |
| 150 | |
| 151 | return value; |
| 152 | } |
| 153 | |
| 154 | |
| 15 | 155 | /*************************************************************************** |
| 16 | 156 | |
| 17 | 157 | SRAM handling |
| r3336 | r3337 | |
| 99 | 239 | |
| 100 | 240 | ***************************************************************************/ |
| 101 | 241 | |
| 242 | /* This function assign a 'score' to data immediately after 'offset' to measure how valid they are |
| 243 | as information block (to decide if the image is HiRom, LoRom, ExLoRom or ExHiRom) */ |
| 244 | /* Code from bsnes, courtesy of byuu - http://byuu.cinnamonpirate.com/ */ |
| 245 | static int snes_validate_infoblock( UINT8 *infoblock, UINT32 offset ) |
| 246 | { |
| 247 | int score = 0; |
| 248 | UINT16 reset_vector = infoblock[offset + 0x3c] | (infoblock[offset + 0x3d] << 8); |
| 249 | UINT16 checksum = infoblock[offset + 0x1e] | (infoblock[offset + 0x1f] << 8); |
| 250 | UINT16 ichecksum = infoblock[offset + 0x1c] | (infoblock[offset + 0x1d] << 8); |
| 251 | UINT8 reset_opcode = infoblock[(offset & ~0x7fff) | (reset_vector & 0x7fff)]; //first opcode executed upon reset |
| 252 | UINT8 mapper = infoblock[offset + 0x15] & ~0x10; //mask off irrelevent FastROM-capable bit |
| 253 | |
| 254 | /* $00:[000-7fff] contains uninitialized RAM and MMIO. |
| 255 | reset vector must point to ROM at $00:[8000-ffff] to be considered valid. */ |
| 256 | if (reset_vector < 0x8000) |
| 257 | return 0; |
| 258 | |
| 259 | /* some images duplicate the header in multiple locations, and others have completely |
| 260 | invalid header information that cannot be relied upon. The code below will analyze |
| 261 | the first opcode executed at the specified reset vector to determine the probability |
| 262 | that this is the correct header. Score is assigned accordingly. */ |
| 263 | |
| 264 | /* most likely opcodes */ |
| 265 | if (reset_opcode == 0x78 //sei |
| 266 | || reset_opcode == 0x18 //clc (clc; xce) |
| 267 | || reset_opcode == 0x38 //sec (sec; xce) |
| 268 | || reset_opcode == 0x9c //stz $nnnn (stz $4200) |
| 269 | || reset_opcode == 0x4c //jmp $nnnn |
| 270 | || reset_opcode == 0x5c //jml $nnnnnn |
| 271 | ) |
| 272 | score += 8; |
| 273 | |
| 274 | /* plausible opcodes */ |
| 275 | if (reset_opcode == 0xc2 //rep #$nn |
| 276 | || reset_opcode == 0xe2 //sep #$nn |
| 277 | || reset_opcode == 0xad //lda $nnnn |
| 278 | || reset_opcode == 0xae //ldx $nnnn |
| 279 | || reset_opcode == 0xac //ldy $nnnn |
| 280 | || reset_opcode == 0xaf //lda $nnnnnn |
| 281 | || reset_opcode == 0xa9 //lda #$nn |
| 282 | || reset_opcode == 0xa2 //ldx #$nn |
| 283 | || reset_opcode == 0xa0 //ldy #$nn |
| 284 | || reset_opcode == 0x20 //jsr $nnnn |
| 285 | || reset_opcode == 0x22 //jsl $nnnnnn |
| 286 | ) |
| 287 | score += 4; |
| 288 | |
| 289 | /* implausible opcodes */ |
| 290 | if (reset_opcode == 0x40 //rti |
| 291 | || reset_opcode == 0x60 //rts |
| 292 | || reset_opcode == 0x6b //rtl |
| 293 | || reset_opcode == 0xcd //cmp $nnnn |
| 294 | || reset_opcode == 0xec //cpx $nnnn |
| 295 | || reset_opcode == 0xcc //cpy $nnnn |
| 296 | ) |
| 297 | score -= 4; |
| 298 | |
| 299 | /* least likely opcodes */ |
| 300 | if (reset_opcode == 0x00 //brk #$nn |
| 301 | || reset_opcode == 0x02 //cop #$nn |
| 302 | || reset_opcode == 0xdb //stp |
| 303 | || reset_opcode == 0x42 //wdm |
| 304 | || reset_opcode == 0xff //sbc $nnnnnn,x |
| 305 | ) |
| 306 | score -= 8; |
| 307 | |
| 308 | /* Sometimes, both the header and reset vector's first opcode will match ... |
| 309 | fallback and rely on info validity in these cases to determine more likely header. */ |
| 310 | |
| 311 | /* a valid checksum is the biggest indicator of a valid header. */ |
| 312 | if ((checksum + ichecksum) == 0xffff && (checksum != 0) && (ichecksum != 0)) |
| 313 | score += 4; |
| 314 | |
| 315 | /* then there are the expected mapper values */ |
| 316 | if (offset == 0x007fc0 && mapper == 0x20) // 0x20 is usually LoROM |
| 317 | score += 2; |
| 318 | |
| 319 | if (offset == 0x00ffc0 && mapper == 0x21) // 0x21 is usually HiROM |
| 320 | score += 2; |
| 321 | |
| 322 | if (offset == 0x007fc0 && mapper == 0x22) // 0x22 is usually ExLoROM |
| 323 | score += 2; |
| 324 | |
| 325 | if (offset == 0x40ffc0 && mapper == 0x25) // 0x25 is usually ExHiROM |
| 326 | score += 2; |
| 327 | |
| 328 | /* finally, there are valid values in the Company, Region etc. fields */ |
| 329 | if (infoblock[offset + 0x1a] == 0x33) // Company field: 0x33 indicates extended header |
| 330 | score += 2; |
| 331 | |
| 332 | if (infoblock[offset + 0x16] < 0x08) // ROM Type field |
| 333 | score++; |
| 334 | |
| 335 | if (infoblock[offset + 0x17] < 0x10) // ROM Size field |
| 336 | score++; |
| 337 | |
| 338 | if (infoblock[offset + 0x18] < 0x08) // SRAM Size field |
| 339 | score++; |
| 340 | |
| 341 | if (infoblock[offset + 0x19] < 14) // Region field |
| 342 | score++; |
| 343 | |
| 344 | /* do we still have a positive score? */ |
| 345 | if (score < 0) |
| 346 | score = 0; |
| 347 | |
| 348 | return score; |
| 349 | } |
| 350 | |
| 351 | |
| 102 | 352 | static DEVICE_IMAGE_LOAD( snes_cart ) |
| 103 | 353 | { |
| 104 | 354 | int i, supported_type = 0; |
| 105 | 355 | running_machine *machine = image->machine; |
| 106 | 356 | UINT16 totalblocks, readblocks; |
| 107 | 357 | UINT32 offset; |
| 108 | | UINT8 header[512], sample[0xffff]; |
| 109 | | UINT8 valid_mode20, valid_mode21; |
| 358 | UINT8 header[512]; |
| 359 | UINT8 *temp_buffer = auto_malloc(0x410000); |
| 360 | UINT8 valid_mode20, valid_mode21, valid_mode25; |
| 110 | 361 | |
| 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 | 362 | memory_region_alloc(machine, "main", 0x1000000,0); |
| 192 | 363 | |
| 193 | 364 | snes_ram = memory_region( machine, "main" ); |
| r3336 | r3337 | |
| 221 | 392 | image_fseek( image, offset, SEEK_SET ); |
| 222 | 393 | } |
| 223 | 394 | |
| 224 | | /* We need to take a sample of 128kb to test what mode we need to be in */ |
| 225 | | image_fread( image, sample, 0xffff ); |
| 395 | /* We need to take a sample to test what mode we need to be in (the |
| 396 | sample has to be quite large to cope with large carts in ExHiRom) */ |
| 397 | image_fread( image, temp_buffer, 0x40ffff ); |
| 226 | 398 | image_fseek( image, offset, SEEK_SET ); /* Rewind */ |
| 227 | 399 | |
| 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 ) |
| 400 | /* Now to determine if this is a lo-ROM, a hi-ROM or an extended lo/hi-ROM */ |
| 401 | valid_mode20 = snes_validate_infoblock( temp_buffer, 0x007fc0 ); |
| 402 | valid_mode21 = snes_validate_infoblock( temp_buffer, 0x00ffc0 ); |
| 403 | valid_mode25 = snes_validate_infoblock( temp_buffer, 0x40ffc0 ); |
| 404 | |
| 405 | /* Images larger than 32mbits are likely ExHiRom */ |
| 406 | if (valid_mode25) |
| 407 | valid_mode25 += 4; |
| 408 | |
| 409 | if ((valid_mode20 >= valid_mode21) && (valid_mode20 >= valid_mode25)) |
| 232 | 410 | { |
| 233 | | snes_cart.mode = SNES_MODE_20; |
| 411 | if ((temp_buffer[0x007fd5] == 0x32) || ((image_length(image) - offset) > 0x401000)) |
| 412 | snes_cart.mode = SNES_MODE_22; // ExLoRom |
| 413 | else |
| 414 | snes_cart.mode = SNES_MODE_20; // LoRom |
| 415 | |
| 234 | 416 | snes_cart.sram_max = 0x40000; |
| 235 | 417 | } |
| 236 | | else if( valid_mode21 > valid_mode20 ) |
| 418 | else if( valid_mode21 >= valid_mode25 ) |
| 237 | 419 | { |
| 238 | | snes_cart.mode = SNES_MODE_21; |
| 420 | snes_cart.mode = SNES_MODE_21; // HiRom |
| 239 | 421 | snes_cart.sram_max = 0x20000; |
| 240 | 422 | } |
| 423 | else |
| 424 | { |
| 425 | snes_cart.mode = SNES_MODE_25; // ExHiRom |
| 426 | snes_cart.sram_max = 0x20000; |
| 427 | } |
| 241 | 428 | |
| 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 | 429 | /* FIXME: Insert crc check here */ |
| 246 | 430 | |
| 247 | | readblocks = 0; |
| 248 | | if( snes_cart.mode == SNES_MODE_20 ) |
| 431 | readblocks = 1; |
| 432 | switch (snes_cart.mode) |
| 249 | 433 | { |
| 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 | | */ |
| 434 | case SNES_MODE_21: |
| 435 | case SNES_MODE_25: |
| 436 | /* In mode 21, all blocks are 64kb. There are upto 96 blocks, giving a |
| 437 | * total of 48mbit(6mb) of ROM. |
| 438 | * The first 64 blocks are located in banks 0xc0 to 0xff. The top 32k of |
| 439 | * each bank is mirrored in banks 0x00 to 0x3f. |
| 440 | * The final 32 blocks are located in banks 0x40 to 0x5f. |
| 441 | * Extended HiROM has a different mirroring, with the first 64 blocks |
| 442 | * having top half mirrored in banks 0x08 to 0xbf and the final 32 blocks |
| 443 | * having top half mirrored in banks 0x00 to 0x1f |
| 444 | */ |
| 445 | /* read first 64 blocks */ |
| 446 | totalblocks = ((image_length(image) - offset) / 0x10000); |
| 447 | i = 0; |
| 448 | while( i < 64 && readblocks <= totalblocks ) |
| 449 | { |
| 450 | image_fread( image, &snes_ram[0xc00000 + (i++ * 0x10000)], 0x10000); |
| 451 | readblocks++; |
| 452 | } |
| 453 | /* read the next 32 blocks */ |
| 454 | i = 0; |
| 455 | while( i < 32 && readblocks <= totalblocks ) |
| 456 | { |
| 457 | image_fread( image, &snes_ram[0x400000 + (i++ * 0x10000)], 0x10000); |
| 458 | readblocks++; |
| 459 | } |
| 460 | break; |
| 274 | 461 | |
| 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 | | } |
| 462 | case SNES_MODE_22: |
| 463 | /* This is used by SDD-1 games (and others?). It requires to switch the |
| 464 | * content of banks at 0xc0-0xff according to MMC registers $4804-$4807 */ |
| 465 | logerror( "This type of carts (ExLoROM) is still unsupported in M.E.S.S.\n" ); |
| 466 | return INIT_FAIL; |
| 467 | break; |
| 468 | |
| 469 | default: |
| 470 | case SNES_MODE_20: |
| 471 | /* In mode 20, all blocks are 32kb. There are upto 96 blocks, giving a |
| 472 | * total of 24mbit(3mb) of ROM. |
| 473 | * The first 48 blocks are located in banks 0x00 to 0x2f at address |
| 474 | * 0x8000. They are mirrored in banks 0x80 to 0xaf. |
| 475 | * The next 16 blocks are located in banks 0x30 to 0x3f at address |
| 476 | * 0x8000. They are mirrored in banks 0xb0 to 0xbf. |
| 477 | * The final 32 blocks are located in banks 0x40 to 0x5f at address |
| 478 | * 0x8000. They are mirrored in banks 0xc0 to 0xdf. |
| 479 | */ |
| 480 | totalblocks = ((image_length(image) - offset) / 0x8000); |
| 481 | i = 0; |
| 482 | while( i < 96 && readblocks <= totalblocks ) |
| 483 | { |
| 484 | image_fread( image, &snes_ram[(i++ * 0x10000) + 0x8000], 0x8000); |
| 485 | readblocks++; |
| 486 | } |
| 487 | break; |
| 289 | 488 | } |
| 290 | 489 | |
| 291 | 490 | |
| r3336 | r3337 | |
| 424 | 623 | /* Log snes_cart information */ |
| 425 | 624 | { |
| 426 | 625 | 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 ); |
| 626 | int company; |
| 627 | |
| 628 | /* Company */ |
| 431 | 629 | for( i = 0; i < 2; i++ ) |
| 432 | 630 | company_id[i] = snes_r_bank1(machine, 0x00ffb0 + i); |
| 433 | | logerror( "\tCompany ID: %s\n", company_id ); |
| 631 | company = (char_to_int_conv(company_id[0]) << 4) + char_to_int_conv(company_id[1]); |
| 632 | if (company == 0) |
| 633 | company = snes_r_bank1(machine, 0x00ffda); |
| 634 | |
| 635 | /* ROM ID */ |
| 434 | 636 | for( i = 0; i < 4; i++ ) |
| 435 | 637 | rom_id[i] = snes_r_bank1(machine, 0x00ffb2 + i); |
| 436 | | logerror( "\tROM ID: %s\n", rom_id ); |
| 437 | | logerror( "HEADER DETAILS\n" ); |
| 638 | |
| 639 | /* Title */ |
| 438 | 640 | for( i = 0; i < 21; i++ ) |
| 439 | 641 | title[i] = snes_r_bank1(machine, 0x00ffc0 + i); |
| 440 | | logerror( "\tName: %s\n", title ); |
| 642 | |
| 643 | logerror( "ROM DETAILS\n" ); |
| 644 | logerror( "===========\n\n" ); |
| 645 | logerror( "\tTotal blocks: %d (%dmb)\n", totalblocks, totalblocks / (snes_cart.mode == SNES_MODE_20 ? 32 : 16) ); |
| 646 | logerror( "\tROM bank size: %s (LoROM: %d , HiROM: %d, ExHiROM: %d)\n", |
| 647 | (snes_cart.mode == SNES_MODE_20) ? "LoROM" : ((snes_cart.mode == SNES_MODE_21) ? "HiROM" : "ExHiROM"), |
| 648 | valid_mode20, valid_mode21, valid_mode25); |
| 649 | logerror( "\tCompany: %s [%.2s]\n", companies[company], company_id ); |
| 650 | logerror( "\tROM ID: %.4s\n\n", rom_id ); |
| 651 | |
| 652 | logerror( "HEADER DETAILS\n" ); |
| 653 | logerror( "==============\n\n" ); |
| 654 | logerror( "\tName: %.21s\n", title ); |
| 441 | 655 | logerror( "\tSpeed: %s [%d]\n", ((snes_r_bank1(machine, 0x00ffd5) & 0xf0)) ? "FastROM" : "SlowROM", (snes_r_bank1(machine, 0x00ffd5) & 0xf0) >> 4 ); |
| 442 | 656 | logerror( "\tBank size: %s [%d]\n", (snes_r_bank1(machine, 0x00ffd5) & 0xf) ? "HiROM" : "LoROM", snes_r_bank1(machine, 0x00ffd5) & 0xf ); |
| 443 | 657 | logerror( "\tType: %s [%d]\n", types[cart_type], snes_r_bank1(machine, 0x00ffd6) ); |
| 444 | 658 | logerror( "\tSize: %d megabits [%d]\n", 1 << (snes_r_bank1(machine, 0x00ffd7) - 7), snes_r_bank1(machine, 0x00ffd7) ); |
| 445 | 659 | 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) ); |
| 660 | logerror( "\tCountry: %s [%d]\n", countries[snes_r_bank1(machine, 0x00ffd9)], snes_r_bank1(machine, 0x00ffd9) ); |
| 661 | logerror( "\tLicense: %s [%X]\n", companies[snes_r_bank1(machine, 0x00ffda)], snes_r_bank1(machine, 0x00ffda) ); |
| 451 | 662 | logerror( "\tVersion: 1.%d\n", snes_r_bank1(machine, 0x00ffdb) ); |
| 452 | 663 | logerror( "\tInv Checksum: %X %X\n", snes_r_bank1(machine, 0x00ffdd), snes_r_bank1(machine, 0x00ffdc) ); |
| 453 | 664 | logerror( "\tChecksum: %X %X\n", snes_r_bank1(machine, 0x00ffdf), snes_r_bank1(machine, 0x00ffde) ); |
| 454 | 665 | 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) ); |
| 666 | logerror( "\tStart Address: %2X%2Xh\n\n", snes_r_bank1(machine, 0x00fffd), snes_r_bank1(machine, 0x00fffc) ); |
| 456 | 667 | |
| 457 | 668 | if (!supported_type) |
| 458 | 669 | logerror("WARNING: This cart type \"%s\" is not supported yet!\n", types[cart_type]); |