Previous 15994 Revisions Next

r3406 Tuesday 7th October, 2008 at 22:04:14 UTC by Fabio Priuli
[SNES] Added support for DSP-2 and OBC-1 special chips (ported from BSNES, courtesy of byuu). MAME changes submitted to MAMEDev as well.
[src/mame/includes]snes.h
[src/mame/machine]snes.c snesdsp2.c* snesobc1.c*
[src/mess/machine]snescart.c

src/mame/machine/snesdsp2.c
r0r3406
1/***************************************************************************
2
3  snesdsp2.c
4
5  File to handle emulation of the SNES "DSP-2" add-on chip.
6
7  Original C++ code by byuu, based on research by Overload
8
9  MAME/MESS C conversion by etabeta
10
11***************************************************************************/
12
13int DSP2_waiting_for_command = 0;
14int DSP2_command = 0;
15int DSP2_in_count = 0,  DSP2_in_index = 0;
16int DSP2_out_count = 0, DSP2_out_index = 0;
17
18UINT8 DSP2_parameters[512] = {0};
19UINT8 DSP2_output[512] = {0};
20
21UINT8 DSP2_op05transparent = 0;
22int DSP2_op05haslen = 0;
23int DSP2_op05len = 0;
24int DSP2_op06haslen = 0;
25int DSP2_op06len = 0;
26UINT16 DSP2_op09word1 = 0;
27UINT16 DSP2_op09word2 = 0;
28int DSP2_op0dhaslen = 0;
29int DSP2_op0doutlen = 0;
30int DSP2_op0dinlen = 0;
31
32
33//convert bitmap to bitplane tile
34void DSP2_op01( void )
35{
36//op01 size is always 32 bytes input and output
37//the hardware does strange things if you vary the size
38
39   unsigned char c0, c1, c2, c3;
40   unsigned char *p1  = DSP2_parameters;
41   unsigned char *p2a = DSP2_output;
42   unsigned char *p2b = DSP2_output + 16; //halfway
43   int j;
44
45//process 8 blocks of 4 bytes each
46   for (j = 0; j < 8; j++)
47   {
48      c0 = *p1++;
49      c1 = *p1++;
50      c2 = *p1++;
51      c3 = *p1++;
52
53      *p2a++ = (c0 & 0x10) << 3 |
54            (c0 & 0x01) << 6 |
55            (c1 & 0x10) << 1 |
56            (c1 & 0x01) << 4 |
57            (c2 & 0x10) >> 1 |
58            (c2 & 0x01) << 2 |
59            (c3 & 0x10) >> 3 |
60            (c3 & 0x01);
61
62      *p2a++ = (c0 & 0x20) << 2 |
63            (c0 & 0x02) << 5 |
64            (c1 & 0x20)      |
65            (c1 & 0x02) << 3 |
66            (c2 & 0x20) >> 2 |
67            (c2 & 0x02) << 1 |
68            (c3 & 0x20) >> 4 |
69            (c3 & 0x02) >> 1;
70
71      *p2b++ = (c0 & 0x40) << 1 |
72            (c0 & 0x04) << 4 |
73            (c1 & 0x40) >> 1 |
74            (c1 & 0x04) << 2 |
75            (c2 & 0x40) >> 3 |
76            (c2 & 0x04)      |
77            (c3 & 0x40) >> 5 |
78            (c3 & 0x04) >> 2;
79
80      *p2b++ = (c0 & 0x80)      |
81            (c0 & 0x08) << 3 |
82            (c1 & 0x80) >> 2 |
83            (c1 & 0x08) << 1 |
84            (c2 & 0x80) >> 4 |
85            (c2 & 0x08) >> 1 |
86            (c3 & 0x80) >> 6 |
87            (c3 & 0x08) >> 3;
88   }
89}
90
91//set transparent color
92void DSP2_op03( void )
93{
94   DSP2_op05transparent = DSP2_parameters[0];
95}
96
97//replace bitmap using transparent color
98void DSP2_op05( void )
99{
100   UINT8 color;
101// Overlay bitmap with transparency.
102// Input:
103//
104//   Bitmap 1:  i[0] <=> i[size-1]
105//   Bitmap 2:  i[size] <=> i[2*size-1]
106//
107// Output:
108//
109//   Bitmap 3:  o[0] <=> o[size-1]
110//
111// Processing:
112//
113//   Process all 4-bit pixels (nibbles) in the bitmap
114//
115//   if ( BM2_pixel == transparent_color )
116//      pixelout = BM1_pixel
117//   else
118//      pixelout = BM2_pixel
119
120// The max size bitmap is limited to 255 because the size parameter is a byte
121// I think size=0 is an error.  The behavior of the chip on size=0 is to
122// return the last value written to DR if you read DR on Op05 with
123// size = 0.  I don't think it's worth implementing this quirk unless it's
124// proven necessary.
125
126   unsigned char c1, c2;
127   unsigned char *p1 = DSP2_parameters;
128   unsigned char *p2 = DSP2_parameters + DSP2_op05len;
129   unsigned char *p3 = DSP2_output;
130   int n;
131
132   color = DSP2_op05transparent & 0x0f;
133
134   for (n = 0; n < DSP2_op05len; n++)
135   {
136      c1 = *p1++;
137      c2 = *p2++;
138      *p3++ = ( ((c2 >> 4)   == color ) ? c1 & 0xf0 : c2 & 0xf0 ) |
139            ( ((c2 & 0x0f) == color ) ? c1 & 0x0f : c2 & 0x0f );
140   }
141}
142
143//reverse bitmap
144void DSP2_op06( void )
145{
146// Input:
147//    size
148//    bitmap
149   int i, j;
150   for (i = 0, j = DSP2_op06len - 1; i < DSP2_op06len; i++, j--)
151   {
152      DSP2_output[j] = (DSP2_parameters[i] << 4) | (DSP2_parameters[i] >> 4);
153   }
154}
155
156//multiply
157void DSP2_op09( void )
158{
159   UINT32 r = 0;
160   DSP2_out_count = 4;
161
162   DSP2_op09word1 = DSP2_parameters[0] | (DSP2_parameters[1] << 8);
163   DSP2_op09word2 = DSP2_parameters[2] | (DSP2_parameters[3] << 8);
164
165   r = DSP2_op09word1 * DSP2_op09word2;
166   DSP2_output[0] = r;
167   DSP2_output[1] = r >> 8;
168   DSP2_output[2] = r >> 16;
169   DSP2_output[3] = r >> 24;
170}
171
172//scale bitmap
173void DSP2_op0d( void )
174{
175// Bit accurate hardware algorithm - uses fixed point math
176// This should match the DSP2 Op0D output exactly
177// I wouldn't recommend using this unless you're doing hardware debug.
178// In some situations it has small visual artifacts that
179// are not readily apparent on a TV screen but show up clearly
180// on a monitor.  Use Overload's scaling instead.
181// This is for hardware verification testing.
182//
183// One note:  the HW can do odd byte scaling but since we divide
184// by two to get the count of bytes this won't work well for
185// odd byte scaling (in any of the current algorithm implementations).
186// So far I haven't seen Dungeon Master use it.
187// If it does we can adjust the parameters and code to work with it
188
189   UINT32 multiplier; // Any size int >= 32-bits
190   UINT32 pixloc;     // match size of multiplier
191   int    i, j;
192   UINT8  pixelarray[512];
193   if (DSP2_op0dinlen <= DSP2_op0doutlen)
194   {
195      multiplier = 0x10000; // In our self defined fixed point 0x10000 == 1
196   }
197   else
198   {
199      multiplier = (DSP2_op0dinlen << 17) / ((DSP2_op0doutlen << 1) + 1);
200   }
201
202   pixloc = 0;
203   for (i = 0; i < DSP2_op0doutlen * 2; i++)
204   {
205      j = pixloc >> 16;
206
207      if (j & 1)
208         pixelarray[i] = (DSP2_parameters[j >> 1] & 0x0f);
209      else
210         pixelarray[i] = (DSP2_parameters[j >> 1] & 0xf0) >> 4;
211
212      pixloc += multiplier;
213   }
214
215   for (i = 0; i < DSP2_op0doutlen; i++)
216   {
217      DSP2_output[i] = (pixelarray[i << 1] << 4) | pixelarray[(i << 1) + 1];
218   }
219}
220
221
222void DSP2_reset( void )
223{
224   DSP2_waiting_for_command = 1;
225   DSP2_in_count  = 0;
226   DSP2_in_index  = 0;
227   DSP2_out_count = 0;
228   DSP2_out_index = 0;
229
230   DSP2_op05transparent = 0;
231   DSP2_op05haslen      = 0;
232   DSP2_op05len         = 0;
233   DSP2_op06haslen      = 0;
234   DSP2_op06len         = 0;
235   DSP2_op09word1       = 0;
236   DSP2_op09word2       = 0;
237   DSP2_op0dhaslen      = 0;
238   DSP2_op0doutlen      = 0;
239   DSP2_op0dinlen       = 0;
240}
241
242UINT8 DSP2_read( void )
243{
244   UINT8 r = 0xff;
245   if (DSP2_out_count)
246   {
247      r = DSP2_output[DSP2_out_index++];
248      DSP2_out_index &= 511;
249      if (DSP2_out_count == DSP2_out_index)
250         DSP2_out_count = 0;
251   }
252   return r;
253}
254
255void DSP2_write(UINT8 data)
256{
257   if(DSP2_waiting_for_command)
258   {
259      DSP2_command  = data;
260      DSP2_in_index = 0;
261      DSP2_waiting_for_command = 0;
262
263      switch (data)
264      {
265         case 0x01: DSP2_in_count = 32; break;
266         case 0x03: DSP2_in_count =  1; break;
267         case 0x05: DSP2_in_count =  1; break;
268         case 0x06: DSP2_in_count =  1; break;
269         case 0x07: break;
270         case 0x08: break;
271         case 0x09: DSP2_in_count =  4; break;
272         case 0x0d: DSP2_in_count =  2; break;
273         case 0x0f: DSP2_in_count =  0; break;
274      }
275   }
276   else
277   {
278      DSP2_parameters[DSP2_in_index++] = data;
279      DSP2_in_index &= 511;
280   }
281
282   if (DSP2_in_count == DSP2_in_index)
283   {
284      DSP2_waiting_for_command = 1;
285      DSP2_out_index = 0;
286      switch (DSP2_command)
287      {
288         case 0x01:
289            DSP2_out_count = 32;
290            DSP2_op01();
291            break;
292
293         case 0x03:
294            DSP2_op03();
295            break;
296
297         case 0x05:
298            if (DSP2_op05haslen)
299            {
300               DSP2_op05haslen = 0;
301               DSP2_out_count  = DSP2_op05len;
302               DSP2_op05();
303            }
304            else
305            {
306               DSP2_op05len    = DSP2_parameters[0];
307               DSP2_in_index   = 0;
308               DSP2_in_count   = DSP2_op05len * 2;
309               DSP2_op05haslen = 1;
310               if (data)
311                  DSP2_waiting_for_command = 0;
312            }
313            break;
314
315         case 0x06:
316            if (DSP2_op06haslen)
317            {
318               DSP2_op06haslen = 0;
319               DSP2_out_count  = DSP2_op06len;
320               DSP2_op06();
321            }
322            else
323            {
324               DSP2_op06len    = DSP2_parameters[0];
325               DSP2_in_index   = 0;
326               DSP2_in_count   = DSP2_op06len;
327               DSP2_op06haslen = 1;
328               if (data)
329                  DSP2_waiting_for_command = 0;
330            }
331            break;
332
333         case 0x07: break;
334         case 0x08: break;
335
336         case 0x09:
337            DSP2_op09();
338            break;
339
340         case 0x0d:
341            if (DSP2_op0dhaslen)
342            {
343               DSP2_op0dhaslen = 0;
344               DSP2_out_count  = DSP2_op0doutlen;
345               DSP2_op0d();
346            }
347            else
348            {
349               DSP2_op0dinlen  = DSP2_parameters[0];
350               DSP2_op0doutlen = DSP2_parameters[1];
351               DSP2_in_index   = 0;
352               DSP2_in_count   = (DSP2_op0dinlen + 1) >> 1;
353               DSP2_op0dhaslen = 1;
354               if(data)
355                  DSP2_waiting_for_command = 0;
356            }
357            break;
358
359         case 0x0f:
360            break;
361      }
362   }
363}
src/mame/machine/snesobc1.c
r0r3406
1/***************************************************************************
2
3  snesobc1.c
4
5  File to handle emulation of the SNES "OBC-1" add-on chip.
6
7  Original C++ code by byuu
8
9  MAME/MESS C conversion by etabeta
10
11***************************************************************************/
12
13int obc1_address;
14int obc1_offset;
15int obc1_shift;
16
17READ8_HANDLER( obc1_read )
18{
19   UINT16 address = offset & 0x1fff;
20   UINT8 value;
21
22   switch (address)
23   {
24      case 0x1ff0:
25         value = snes_ram[obc1_offset + (obc1_address << 2) + 0];
26         break;
27
28      case 0x1ff1:
29         value = snes_ram[obc1_offset + (obc1_address << 2) + 1];
30         break;
31
32      case 0x1ff2:
33         value = snes_ram[obc1_offset + (obc1_address << 2) + 2];
34         break;
35
36      case 0x1ff3:
37         value = snes_ram[obc1_offset + (obc1_address << 2) + 3];
38         break;
39
40      case 0x1ff4:
41         value = snes_ram[obc1_offset + (obc1_address >> 2) + 0x200];
42         break;
43
44      default:
45         value = snes_ram[address];
46         break;
47   }
48
49   return value;
50}
51
52
53WRITE8_HANDLER( obc1_write )
54{
55   UINT16 address = offset & 0x1fff;
56   UINT8 temp;
57
58   switch(address)
59   {
60      case 0x1ff0:
61         snes_ram[obc1_offset + (obc1_address << 2) + 0] = data;
62         break;
63
64      case 0x1ff1:
65         snes_ram[obc1_offset + (obc1_address << 2) + 1] = data;
66         break;
67
68      case 0x1ff2:
69         snes_ram[obc1_offset + (obc1_address << 2) + 2] = data;
70         break;
71
72      case 0x1ff3:
73         snes_ram[obc1_offset + (obc1_address << 2) + 3] = data;
74         break;
75
76      case 0x1ff4:
77         temp = snes_ram[obc1_offset + (obc1_address >> 2) + 0x200];
78         temp = (temp & ~(3 << obc1_shift)) | ((data & 0x03) << obc1_shift);
79         snes_ram[obc1_offset + (obc1_address >> 2) + 0x200] = temp;
80         break;
81
82      case 0x1ff5:
83         obc1_offset = (data & 0x01) ? 0x1800 : 0x1c00;
84         snes_ram[address & 0x1fff] = data;
85         break;
86
87      case 0x1ff6:
88         obc1_address = data & 0x7f;
89         obc1_shift = (data & 0x03) << 1;
90         snes_ram[address & 0x1fff] = data;
91         break;
92
93      default:
94         snes_ram[address & 0x1fff] = data;
95         break;
96   }
97}
98
99void obc1_init( void )
100{
101   obc1_offset  = (snes_ram[0x1ff5] & 0x01) ? 0x1800 : 0x1c00;
102   obc1_address = (snes_ram[0x1ff6] & 0x7f);
103   obc1_shift   = (snes_ram[0x1ff6] & 0x03) << 1;
104}
src/mame/machine/snes.c
r3405r3406
1818
1919// add-on chip emulators
2020#include "machine/snesdsp1.c"
21#include "machine/snesdsp2.c"
22#include "machine/snesobc1.c"
2123
2224/* -- Globals -- */
2325UINT8  *snes_ram = NULL;      /* 65816 ram */
r3405r3406
3941static emu_timer *snes_hirq_timer;
4042static UINT16 hblank_offset;
4143static UINT16 snes_htmult;   /* in 512 wide, we run HTOTAL double and halve it on latching */
42static UINT8 has_dsp1;
44UINT8 has_addon_chip;
4345
4446// full graphic variables
4547static UINT16 vram_fgr_high, vram_fgr_increment, vram_fgr_count, vram_fgr_mask, vram_fgr_shift, vram_read_buffer;
r3405r3406
275277}
276278
277279
278
279280/*************************************
280281
281282    Input Handlers
r3405r3406
10971098/*
10981099There are at least 4 different kind of boards for SNES carts, which we denote with
10991100mode_20, mode_21, mode_22 and mode_25. Below is a layout of the memory for each of
1100them, as described on the SNES dev manual. Notice we mirror ROM at loading time
1101where necessary (e.g. banks 0x80 to 0xff at address 0x8000 for mode_20).
1101them. Notice we mirror ROM at loading time where necessary (e.g. banks 0x80 to 0xff
1102at address 0x8000 for mode_20).
11021103
11031104MODE_20
11041105     banks 0x00      0x20          0x40      0x60       0x70     0x7e  0x80   0xc0   0xff
r3405r3406
111711180x0000  -------------------------------------------------------------------------------
11181119
11191120MODE_22 is the same, but banks 0x40 to 0x7e at address 0x000 to 0x7fff contain ROM (of
1120course mirrored also at 0xc0 to 0xff). Mode 22 is quite similar to the board SHVC-2P3B
1121shown on SNES Dev manual. It is used also in SDD-1 games (only for the first blocks of
1122data). DSP data & status can be either at banks 0x20 to 0x40 at address 0x8000 or at
1123banks 0x60 to 0x6f at address 0x0000.
1121course mirrored also at 0xc0 to 0xff). Mode 22 is quite similar to the board SHVC-2P3B.
1122It is used also in SDD-1 games (only for the first blocks of data). DSP data & status
1123can be either at banks 0x20 to 0x40 at address 0x8000 or at banks 0x60 to 0x6f at address
11240x0000.
11241125
11251126
11261127MODE_21
r3405r3406
11631164
11641165*/
11651166
1166
11671167/* 0x000000 - 0x2fffff */
11681168READ8_HANDLER( snes_r_bank1 )
11691169{
r3405r3406
11761176      value = snes_r_io(machine, address);
11771177   else if (address < 0x8000)
11781178   {
1179      if ((snes_cart.mode == SNES_MODE_21) && has_dsp1 && (offset < 0x100000))
1179      if (has_addon_chip == HAS_OBC1)
1180         value = obc1_read(machine, offset);
1181      else if ((has_addon_chip == HAS_DSP2) && (offset >= 0x200000))
1182         value = (address < 0x7000) ? DSP2_read() : 0x00;
1183      else if ((snes_cart.mode == SNES_MODE_21) && (has_addon_chip == HAS_DSP1) && (offset < 0x100000))
11801184         value = (address < 0x7000) ? DSP1_getDr() : DSP1_getSr();
11811185      else
11821186         value = 0xff;                                 /* Reserved */
11831187   }
1184   else if ((snes_cart.mode == SNES_MODE_20) && has_dsp1 && (offset >= 0x200000))
1185      value = (address < 0xc000) ? DSP1_getDr() : DSP1_getSr();   /* This is not mentioned in the SNES dev manual, fwiw */
1188   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP1) && (offset >= 0x200000))
1189      value = (address < 0xc000) ? DSP1_getDr() : DSP1_getSr();
1190   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP2) && (offset >= 0x200000))
1191      value = (address < 0xc000) ? DSP2_read() : 0x00;
11861192   else
11871193      value = snes_ram[offset];
11881194
r3405r3406
12011207      value = snes_r_io(machine, address);
12021208   else if (address < 0x8000)                              /* SRAM for mode_21, Reserved othewise */
12031209   {
1204      if ((snes_cart.mode == SNES_MODE_21) && (snes_cart.sram > 0))
1210      if (has_addon_chip == HAS_OBC1)
1211         value = obc1_read (machine, offset);
1212      else if (has_addon_chip == HAS_DSP2)
1213         value = (address < 0x7000) ? DSP2_read() : 0x00;
1214      else if ((snes_cart.mode == SNES_MODE_21) && (snes_cart.sram > 0))
12051215      {
12061216         int mask = ((snes_cart.sram * 1024) - 1);            /* Limit SRAM size to what's actually present */
12071217         offset -= 0x6000;
r3405r3406
12111221         value = 0xff;
12121222   }
12131223   /* some dsp1 games use these banks 0x30 to 0x3f at address 0x8000 */
1214   else if ((snes_cart.mode == SNES_MODE_20) && has_dsp1)
1224   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP1))
12151225      value = (address < 0xc000) ? DSP1_getDr() : DSP1_getSr();
1226   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP2))
1227      value = (address < 0xc000) ? DSP2_read() : 0x00;
12161228   else
12171229      value = snes_ram[0x300000 + offset];
12181230
r3405r3406
12411253/* 0x600000 - 0x6fffff */
12421254READ8_HANDLER( snes_r_bank4 )
12431255{
1244   UINT8 value = 0;
1256   UINT8 value = 0xff;
12451257   UINT16 address = offset & 0xffff;
12461258
12471259   if (snes_cart.mode & 5)                     /* Mode 20 & 22 */
r3405r3406
12491261      if (address >= 0x8000)
12501262         value = snes_ram[0x600000 + offset];
12511263      /* some other dsp1 games use these banks 0x60 to 0x6f at address 0x0000 */
1252      else if (has_dsp1)
1264      else if (has_addon_chip == HAS_DSP1)
12531265         value = (address >= 0x4000) ? DSP1_getSr() : DSP1_getDr();
12541266      else
12551267         value = 0xff;                     /* Reserved */
r3405r3406
13061318            value = 0xff;
13071319      }
13081320   }
1321   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP1) && (offset >= 0x200000))
1322      value = (address < 0xc000) ? DSP1_getDr() : DSP1_getSr();
1323   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP2) && (offset >= 0x200000))
1324      value = (address < 0xc000) ? DSP2_read() : 0x00;
13091325   else
13101326      value = snes_ram[0x800000 + offset];
13111327
r3405r3406
13431359      snes_w_io(machine, address, data);
13441360   else if (address < 0x8000)
13451361   {
1346      if ((snes_cart.mode == SNES_MODE_21) && has_dsp1 && (offset < 0x100000))
1362      if (has_addon_chip == HAS_OBC1)
1363         obc1_write(machine, offset, data);
1364      else if ((has_addon_chip == HAS_DSP2) && (offset >= 0x200000))
1365         DSP2_write(data);
1366      else if ((snes_cart.mode == SNES_MODE_21) && (has_addon_chip == HAS_DSP1) && (offset < 0x100000))
13471367         DSP1_setDr(data);
13481368      else
13491369         logerror( "Attempt to write to reserved address: %X\n", offset );
13501370   }
1351   else if ((snes_cart.mode == SNES_MODE_20) && has_dsp1 && (offset >= 0x200000))
1352      DSP1_setDr(data);         /* This is not mentioned in the SNES dev manual, fwiw */
1371   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP1) && (offset >= 0x200000))
1372      DSP1_setDr(data);
1373   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP2) && (offset >= 0x200000) && (address < 0xc000))
1374      DSP2_write(data);
13531375   else
13541376      logerror( "Attempt to write to ROM address: %X\n", offset );
13551377}
r3405r3406
13651387      snes_w_io(machine, address, data);
13661388   else if (address < 0x8000)                  /* SRAM for mode_21, Reserved othewise */
13671389   {
1368      if ((snes_cart.mode == SNES_MODE_21) && (snes_cart.sram > 0))
1390      if (has_addon_chip == HAS_OBC1)
1391         obc1_write(machine, offset, data);
1392      else if (has_addon_chip == HAS_DSP2)
1393         DSP2_write(data);
1394      else if ((snes_cart.mode == SNES_MODE_21) && (snes_cart.sram > 0))
13691395      {
13701396         int mask = ((snes_cart.sram * 1024) - 1);         /* Limit SRAM size to what's actually present */
13711397         offset -= 0x6000;
r3405r3406
13731399      }
13741400      else
13751401         logerror("Attempt to write to reserved address: %X\n", offset + 0x300000);
1376   }
1402   }   
13771403   /* some dsp1 games use these banks 0x30 to 0x3f at address 0x8000 */
1378   else if ((snes_cart.mode == SNES_MODE_20) && has_dsp1)
1404   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP1))
13791405      DSP1_setDr(data);
1406   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP2) && (address < 0xc000))
1407      DSP2_write(data);
13801408   else
13811409      logerror("Attempt to write to ROM address: %X\n", offset + 0x300000);
13821410}
r3405r3406
13901418   {
13911419      if (address >= 0x8000)
13921420         logerror("Attempt to write to ROM address: %X\n", offset + 0x600000);
1393      else if (has_dsp1)
1421      else if (has_addon_chip == HAS_DSP1)
13941422         DSP1_setDr(data);
13951423      else
13961424         logerror("Attempt to write to reserved address: %X\n", offset + 0x600000);
r3405r3406
14301458      {
14311459         if (offset < 0x300000)
14321460            snes_w_bank1(machine, offset, data);
1433         else
1461         else
14341462            snes_w_bank2(machine, offset - 0x300000, data);
14351463      }
14361464      else   /* Mode 25 has SRAM not mirrored from lower banks */
r3405r3406
14391467         {
14401468            if (offset < 0x300000)
14411469               snes_w_bank1(machine, offset, data);
1442            else
1470            else
14431471               snes_w_bank2(machine, offset - 0x300000, data);
14441472         }
14451473         else if ((offset >= 0x300000) && (snes_cart.sram > 0))
r3405r3406
14491477            snes_ram[0xb06000 + (offset & mask)] = data;
14501478         }
14511479         else   /* Area in 0x6000-0x8000 && offset < 0x300000 is Reserved! */
1452            logerror("Attempt to write to reserved address: %X\n", offset + 0x800000);
1480            logerror("Attempt to write to reserved address: %X\n", offset + 0x800000);     
14531481      }
14541482   }
1483   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP1) && (offset >= 0x200000))
1484      DSP1_setDr(data);
1485   else if ((snes_cart.mode == SNES_MODE_20) && (has_addon_chip == HAS_DSP2) && (offset >= 0x200000) && (address < 0xc000))
1486      DSP2_write(data);
14551487   else
14561488      logerror("Attempt to write to ROM address: %X\n", offset + 0x800000);
14571489}
r3405r3406
14831515
14841516/*************************************
14851517
1486    Driver Init
1518   Driver Init
14871519
14881520*************************************/
14891521
r3405r3406
15431575   hblank_offset = 268;
15441576   timer_adjust_oneshot(snes_hblank_timer, video_screen_get_time_until_pos(machine->primary_screen, ((snes_ram[STAT78] & 0x10) == SNES_NTSC) ? SNES_VTOTAL_NTSC-1 : SNES_VTOTAL_PAL-1, hblank_offset), 0);
15451577
1546   // check if DSP1 is present (maybe not 100%?)
1547   has_dsp1 = ((snes_r_bank1(machine,0xffd6) >= 3) && (snes_r_bank1(machine,0xffd6) <= 5)) ? 1 : 0;
1578   switch (has_addon_chip)
1579   {
1580      case HAS_DSP2:
1581         DSP2_reset();
1582         break;
1583         
1584      case HAS_OBC1:
1585         obc1_init();
1586         break;
15481587
1588      default:
1589         break;
1590   }
1591
15491592   // init frame counter so first line is 0
15501593   if( ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds) >= 59 )
15511594   {
r3405r3406
16381681   /* all NSS games seem to use MODE 20 */
16391682   snes_cart.mode = SNES_MODE_20;
16401683   snes_cart.sram_max = 0x40000;
1684   has_addon_chip = HAS_NONE;
16411685
16421686   /* Find the number of blocks in this ROM */
16431687   total_blocks = (memory_region_length(machine, "user3") / 0x8000);
r3405r3406
17011745
17021746   snes_cart.mode = SNES_MODE_21;
17031747   snes_cart.sram_max = 0x40000;
1748   has_addon_chip = HAS_NONE;
17041749
17051750   /* Find the number of blocks in this ROM */
17061751   total_blocks = (memory_region_length(machine, "user3") / 0x10000);
src/mame/includes/snes.h
r3405r3406
351351#define DSP_FIR_C6      0x6F
352352#define DSP_FIR_C7      0x7F
353353
354/* Special chips, checked at init and used in memory handlers */
355enum
356{
357HAS_NONE = 0,
358HAS_DSP1,
359HAS_DSP2,
360HAS_DSP3,
361HAS_DSP4,
362HAS_SUPERFX,
363HAS_SA1,
364HAS_SDD1,
365HAS_OBC1,
366HAS_RTC,
367HAS_Z80GB,
368HAS_C4,
369HAS_ST010,
370HAS_ST011,
371HAS_ST018,
372HAS_SPC7110,
373HAS_SPC7110_RTC,
374HAS_UNK
375};
376
354377/*----------- defined in machine/snes.c -----------*/
355378
356379extern DRIVER_INIT( snes );
r3405r3406
377400extern WRITE8_HANDLER( snes_w_bank6 );
378401extern WRITE8_HANDLER( snes_w_bank7 );
379402
403extern UINT8 has_addon_chip;
380404
381
382405extern void snes_gdma( UINT8 channels );
383406extern void snes_hdma_init(void);
384407extern void snes_hdma(void);
src/mess/machine/snescart.c
r3405r3406
1111#include "devices/cartslot.h"
1212
1313
14/****** Cart types ******/
15
16static int cart_type;
17
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
4814/****** Strings for Cart Header Logging ******/
4915
5016#define UNK "Unknown"
r3405r3406
5319static const char *types[] =
5420{
5521   "ROM",
56   "ROM, RAM",
57   "ROM, SRAM",
5822   "ROM, DSP-1",
59   "ROM, RAM, DSP-1",
60   "ROM, SRAM, DSP-1",
61   "ROM, SRAM, DSP-2",
62   "ROM, SRAM, DSP-3",
23   "ROM, DSP-2",
24   "ROM, DSP-3",
6325   "ROM, DSP-4",
6426   "ROM, Super FX / FX2",
65   "ROM, SRAM, Super FX / FX2",
6627   "ROM, SA-1",
67   "ROM, SRAM, SA-1",
6828   "ROM, S-DD1",
69   "ROM, SRAM, S-DD1",
70   "ROM, SRAM, OBC-1",
71   "ROM, SRAM, S-RTC",
29   "ROM, OBC-1",
30   "ROM, S-RTC",
7231   "ROM, Z80GB (Super Game Boy)",
7332   "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",
33   "ROM, Seta ST-010",
34   "ROM, Seta ST-011",
35   "ROM, Seta ST-018",
36   "ROM, SPC7110",
37   "ROM, SPC7110, RTC",
7938   UNK,                     // to add: Satellaview BS-X detection
8039};
8140
r3405r3406
413372      /* No header found so go back to the start of the file */
414373      logerror("No header found.\n");
415374      offset = 0;
416      image_fseek( image, offset, SEEK_SET );
375      image_fseek(image, offset, SEEK_SET);
417376   }
418377
419378   /* We need to take a sample to test what mode we need to be in (the
r3405r3406
628587   switch (snes_r_bank1(machine, 0x00ffd6))
629588   {
630589         case 0x00:
631            cart_type = STANDARD;
632            supported_type = 1;
633            break;
634
635590         case 0x01:
636            cart_type = STANDARD_RAM;
637            supported_type = 1;
638            break;
639
640591         case 0x02:
641            cart_type = STANDARD_SRAM;
592            has_addon_chip = HAS_NONE;
642593            supported_type = 1;
643594            break;
644595
645596         case 0x03:
646597            if (snes_r_bank1(machine, 0x00ffd5) == 0x30)
647               cart_type = DSP4;
598               has_addon_chip = HAS_DSP4;
648599            else
649600            {
650               cart_type = DSP1;
601               has_addon_chip = HAS_DSP1;
651602               supported_type = 1;
652603            }
653604            break;
654605
655606         case 0x04:
656            cart_type = DSP1_RAM;
607            has_addon_chip = HAS_DSP1;
657608            supported_type = 1;
658609            break;
659610
660611         case 0x05:
661612            if (snes_r_bank1(machine, 0x00ffd5) == 0x20)
662               cart_type = DSP2;
613            {
614               has_addon_chip = HAS_DSP2;
615               supported_type = 1;
616            }
663617            /* DSP-3 is hard to detect. We exploit the fact that the only game has been manufactured by Bandai */
664618            else if ((snes_r_bank1(machine, 0x00ffd5) == 0x30) && (snes_r_bank1(machine, 0x00ffda) == 0xb2))
665               cart_type = DSP3;
619               has_addon_chip = HAS_DSP3;
666620            else
667621            {
668               cart_type = DSP1_SRAM;
622               has_addon_chip = HAS_DSP1;
669623               supported_type = 1;
670624            }
671625            break;
672626
673627         case 0x13:   // Mario Chip 1
674628         case 0x14:   // GSU-x
675            if (snes_r_bank1(machine, 0x00ffd5) == 0x20)
676               cart_type = SUPERFX;
677            break;
678
679629         case 0x15:   // GSU-x
680630         case 0x1a:   // GSU-1 (21 Mhz at start)
681631            if (snes_r_bank1(machine, 0x00ffd5) == 0x20)
682               cart_type = SUPERFX_SRAM;
632               has_addon_chip = HAS_SUPERFX;
683633            break;
684634
685635         case 0x25:
686            cart_type = OBC1;
636            has_addon_chip = HAS_OBC1;
637            supported_type = 1;
687638            break;
688639
689         case 0x34:
690            if (snes_r_bank1(machine, 0x00ffd5) == 0x23)
691               cart_type = SA1;
692            break;
693
694640         case 0x32:   // needed by a Sample game (according to ZSNES)
641         case 0x34:
695642         case 0x35:
696643            if (snes_r_bank1(machine, 0x00ffd5) == 0x23)
697               cart_type = SA1_SRAM;
644               has_addon_chip = HAS_SA1;
698645            break;
699646
700647         case 0x43:
701            if (snes_r_bank1(machine, 0x00ffd5) == 0x32)
702               cart_type = SDD1;
703            break;
704
705648         case 0x45:
706649            if (snes_r_bank1(machine, 0x00ffd5) == 0x32)
707               cart_type = SDD1_SRAM;
650               has_addon_chip = HAS_SDD1;
708651            break;
709652
710653         case 0x55:
711654            if (snes_r_bank1(machine, 0x00ffd5) == 0x35)
712               cart_type = RTC;
655               has_addon_chip = HAS_RTC;
713656            break;
714657
715658         case 0xe3:
716            cart_type = SGB;
659            has_addon_chip = HAS_Z80GB;
717660            break;
718661
719662         case 0xf3:
720            cart_type = C4;
663            has_addon_chip = HAS_C4;
721664            break;
722665         
723666         case 0xf5:
724667            if (snes_r_bank1(machine, 0x00ffd5) == 0x30)
725               cart_type = ST018;
668               has_addon_chip = HAS_ST018;
726669            else if (snes_r_bank1(machine, 0x00ffd5) == 0x3a)
727               cart_type = SPC7110;
670               has_addon_chip = HAS_SPC7110;
728671            break;
729672
730673         case 0xf6:
731674            /* These Seta ST-01X chips have both 0x30 at 0x00ffd5,
732675            they only differ for the 'size' at 0x00ffd7 */
733676            if (snes_r_bank1(machine, 0x00ffd7) < 0x0a)
734               cart_type = ST011;
677               has_addon_chip = HAS_ST011;
735678            else
736               cart_type = ST010;
679               has_addon_chip = HAS_ST010;
737680            break;
738681
739682         case 0xf9:
740683            if (snes_r_bank1(machine, 0x00ffd5) == 0x3a)
741               cart_type = SPC7110_RTC;
684               has_addon_chip = HAS_SPC7110_RTC;
742685            break;
743686         
744687         default:
745            cart_type = UNKNOWN;
688            has_addon_chip = HAS_UNK;
746689            break;
747690   }
748691
749692   /* Log snes_cart information */
750693   {
751694      char title[21], rom_id[4], company_id[2];
752      int company;
695      int company, has_ram = 0, has_sram = 0;
753696
754697      /* Company */
755698      for( i = 0; i < 2; i++ )
r3405r3406
766709      for( i = 0; i < 21; i++ )
767710         title[i] = snes_r_bank1(machine, 0x00ffc0 + i);
768711
712      /* RAM */
713      if (((snes_r_bank1(machine, 0x00ffd6) & 0xf) == 1) ||
714            ((snes_r_bank1(machine, 0x00ffd6) & 0xf) == 2) ||
715            ((snes_r_bank1(machine, 0x00ffd6) & 0xf) == 4) ||
716            ((snes_r_bank1(machine, 0x00ffd6) & 0xf) == 5))
717         has_ram = 1;
718
719      /* SRAM */
720      if (((snes_r_bank1(machine, 0x00ffd6) & 0xf) == 2) ||
721            ((snes_r_bank1(machine, 0x00ffd6) & 0xf) == 5) ||
722            ((snes_r_bank1(machine, 0x00ffd6) & 0xf) == 6))
723         has_sram = 1;
724
769725      logerror( "ROM DETAILS\n" );
770726      logerror( "===========\n\n" );
771727      logerror( "\tTotal blocks:  %d (%dmb)\n", total_blocks, total_blocks / (snes_cart.mode & 5 ? 32 : 16) );
r3405r3406
780736      logerror( "\tName:          %.21s\n", title );
781737      logerror( "\tSpeed:         %s [%d]\n", ((snes_r_bank1(machine, 0x00ffd5) & 0xf0)) ? "FastROM" : "SlowROM", (snes_r_bank1(machine, 0x00ffd5) & 0xf0) >> 4 );
782738      logerror( "\tBank size:     %s [%d]\n", (snes_r_bank1(machine, 0x00ffd5) & 0xf) ? "HiROM" : "LoROM", snes_r_bank1(machine, 0x00ffd5) & 0xf );
783      logerror( "\tType:          %s [%d]\n", types[cart_type], snes_r_bank1(machine, 0x00ffd6) );
739
740      logerror( "\tType:          %s", types[has_addon_chip]);
741      if (has_ram)
742         logerror( ", RAM");
743      if (has_sram)
744         logerror( ", SRAM");
745      logerror( " [%d]\n", snes_r_bank1(machine, 0x00ffd6) );
746
784747      logerror( "\tSize:          %d megabits [%d]\n", 1 << (snes_r_bank1(machine, 0x00ffd7) - 7), snes_r_bank1(machine, 0x00ffd7) );
785748      logerror( "\tSRAM:          %d kilobits [%d]\n", snes_cart.sram * 8, snes_ram[0xffd8] );
786749      logerror( "\tCountry:       %s [%d]\n", countries[snes_r_bank1(machine, 0x00ffd9)], snes_r_bank1(machine, 0x00ffd9) );
r3405r3406
792755      logerror( "\tStart Address: %2X%2Xh\n\n", snes_r_bank1(machine, 0x00fffd), snes_r_bank1(machine, 0x00fffc) );
793756
794757      if (!supported_type)
795         logerror("WARNING: This cart type \"%s\" is not supported yet!\n", types[cart_type]);
758         logerror("WARNING: This cart type \"%s\" is not supported yet!\n", types[has_addon_chip]);
796759   }
797760
798761   /* Load SRAM */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team