Previous 15994 Revisions Next

r3337 Saturday 27th September, 2008 at 12:09:50 UTC by Fabio Priuli
[SNES] Moved bank mode detection to MESS and improved the routine (thanks to byuu). MAME part submitted to MAMEDevs.
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mess/machine]snescart.c

src/mame/machine/snes.c
r3336r3337
14811481   snes_ram[offset] = data;
14821482}
14831483
1484/* This function checks everything is in a valid range and returns how
1485 * 'valid' this section is as an information block. */
1486int snes_validate_infoblock( UINT8 *infoblock, UINT16 offset )
1487{
1488   INT8 valid = 6;
1489
1490   /* Check the CRC and inverse CRC */
1491   if( ((infoblock[offset + 0x1c] + (infoblock[offset + 0x1d] << 8)) |
1492      (infoblock[offset + 0x1e] + (infoblock[offset + 0x1f] << 8))) != 0xffff )
1493   {
1494      valid -= 3;
1495   }
1496   /* Check the ROM Size is in a valid range */
1497   if( infoblock[offset + 0x17] > 13 )
1498   {
1499      valid--;
1500   }
1501   /* Check the SRAM size */
1502   if( infoblock[offset + 0x18] > 8 )
1503   {
1504      valid--;
1505   }
1506   /* Check the Country is in a valid range */
1507   if( infoblock[offset + 0x19] > 13 )
1508   {
1509      valid--;
1510   }
1511   /* Check the game version */
1512   if( infoblock[offset + 0x1b] >= 128 )
1513   {
1514      valid--;
1515   }
1516
1517   if( valid < 0 )
1518   {
1519      valid = 0;
1520   }
1521
1522   return valid;
1523}
1524
1525#ifndef MESS
15261484/* for mame we use an init, maybe we will need more for the different games */
15271485DRIVER_INIT( snes )
15281486{
r3336r3337
16141572         snes_cart.sram = snes_cart.sram_max;
16151573   }
16161574}
1617#endif   /* MESS */
16181575
16191576void snes_hdma_init()
16201577{
src/mame/includes/snes.h
r3336r3337
3838#define SNES_SCR_HEIGHT_PAL   274      /* ??? */
3939#define SNES_VTOTAL_NTSC   262      /* Maximum number of lines for NTSC systems */
4040#define SNES_VTOTAL_PAL      312      /* Maximum number of lines for PAL systems */
41#define SNES_HTOTAL      341      /* Maximum number pixels per line (incl. hblank) */
41#define SNES_HTOTAL         341      /* Maximum number pixels per line (incl. hblank) */
4242#define SNES_DMA_BASE      0x4300   /* Base DMA register address */
4343#define SNES_MODE_20      0x1      /* Lo-ROM cart */
4444#define SNES_MODE_21      0x2      /* Hi-ROM cart */
45#define SNES_MODE_22      0x4      /* Extended Lo-ROM cart - SDD-1 */
46#define SNES_MODE_25      0x8      /* Extended Hi-ROM cart */
4547#define SNES_NTSC         0x00
4648#define SNES_PAL         0x10
4749#define SNES_VRAM_SIZE      0x20000   /* 128kb of video ram */
r3336r3337
371373extern WRITE8_HANDLER( snes_w_io );
372374extern WRITE8_HANDLER( snes_w_sram );
373375
374extern int snes_validate_infoblock( UINT8 *infoblock, UINT16 offset );
375
376376extern void snes_gdma( UINT8 channels );
377377extern void snes_hdma_init(void);
378378extern void snes_hdma(void);
src/mess/machine/snescart.c
r3336r3337
1010#include "includes/snes.h"
1111#include "devices/cartslot.h"
1212
13
14/****** Cart types ******/
15
1316static int cart_type;
1417
18enum
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 */
53static 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 */
83static 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) */
92static 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[] */
130static 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
15155/***************************************************************************
16156
17157  SRAM handling
r3336r3337
99239
100240***************************************************************************/
101241
242/* This function assign a 'score' to data immediately after 'offset' to measure how valid they are
243as information block (to decide if the image is HiRom, LoRom, ExLoRom or ExHiRom) */
244/* Code from bsnes, courtesy of byuu - http://byuu.cinnamonpirate.com/ */
245static 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
102352static DEVICE_IMAGE_LOAD( snes_cart )
103353{
104354   int i, supported_type = 0;
105355   running_machine *machine = image->machine;
106356   UINT16 totalblocks, readblocks;
107357   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;
110361
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
191362   memory_region_alloc(machine, "main", 0x1000000,0);
192363
193364   snes_ram = memory_region( machine, "main" );
r3336r3337
221392      image_fseek( image, offset, SEEK_SET );
222393   }
223394
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 );
226398   image_fseek( image, offset, SEEK_SET );   /* Rewind */
227399
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))
232410   {
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
234416      snes_cart.sram_max = 0x40000;
235417   }
236   else if( valid_mode21 > valid_mode20 )
418   else if( valid_mode21 >= valid_mode25 )
237419   {
238      snes_cart.mode = SNES_MODE_21;
420      snes_cart.mode = SNES_MODE_21;   // HiRom
239421      snes_cart.sram_max = 0x20000;
240422   }
423   else
424   {
425      snes_cart.mode = SNES_MODE_25;   // ExHiRom
426      snes_cart.sram_max = 0x20000;
427   }
241428
242   /* Find the number of blocks in this ROM */
243   totalblocks = ((image_length(image) - offset) >> (snes_cart.mode == SNES_MODE_20 ? 15 : 16));
244
245429   /* FIXME: Insert crc check here */
246430
247   readblocks = 0;
248   if( snes_cart.mode == SNES_MODE_20 )
431   readblocks = 1;
432   switch (snes_cart.mode)
249433   {
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;
274461
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;
289488   }
290489
291490
r3336r3337
424623   /* Log snes_cart information */
425624   {
426625      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 */
431629      for( i = 0; i < 2; i++ )
432630         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 */
434636      for( i = 0; i < 4; i++ )
435637         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 */
438640      for( i = 0; i < 21; i++ )
439641         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 );
441655      logerror( "\tSpeed:         %s [%d]\n", ((snes_r_bank1(machine, 0x00ffd5) & 0xf0)) ? "FastROM" : "SlowROM", (snes_r_bank1(machine, 0x00ffd5) & 0xf0) >> 4 );
442656      logerror( "\tBank size:     %s [%d]\n", (snes_r_bank1(machine, 0x00ffd5) & 0xf) ? "HiROM" : "LoROM", snes_r_bank1(machine, 0x00ffd5) & 0xf );
443657      logerror( "\tType:          %s [%d]\n", types[cart_type], snes_r_bank1(machine, 0x00ffd6) );
444658      logerror( "\tSize:          %d megabits [%d]\n", 1 << (snes_r_bank1(machine, 0x00ffd7) - 7), snes_r_bank1(machine, 0x00ffd7) );
445659      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) );
451662      logerror( "\tVersion:       1.%d\n", snes_r_bank1(machine, 0x00ffdb) );
452663      logerror( "\tInv Checksum:  %X %X\n", snes_r_bank1(machine, 0x00ffdd), snes_r_bank1(machine, 0x00ffdc) );
453664      logerror( "\tChecksum:      %X %X\n", snes_r_bank1(machine, 0x00ffdf), snes_r_bank1(machine, 0x00ffde) );
454665      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) );
456667
457668      if (!supported_type)
458669         logerror("WARNING: This cart type \"%s\" is not supported yet!\n", types[cart_type]);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team