Previous 15994 Revisions Next

r7524 Saturday 6th March, 2010 at 23:18:25 UTC by Fabio Priuli
[SNES] Added basic infrastructure to support multiple controller types. Currently, you can use the Category menu to plug/unplug emulated SNES controllers in port 1 and 2.
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mess/drivers]snes.c

src/mame/machine/snes.c
r7523r7524
12651265      case OLDJOY1:   /* Old NES joystick support */
12661266         if (((!(data & 0x1)) && (snes_ram[offset] & 0x1)))
12671267         {
1268            state->joypad[0].oldrol = 0;
1269            state->joypad[1].oldrol = 0;
1270            state->joypad[2].oldrol = 0;
1271            state->joypad[3].oldrol = 0;
1268            state->read_idx[0] = 0;
1269            state->read_idx[1] = 0;
12721270         }
12731271         break;
12741272      case NMITIMEN:   /* Flag for v-blank, timer int. and joy read */
r7523r7524
20112009      state->joy4l = state->joypad[3].low;
20122010      state->joy4h = state->joypad[3].high;
20132011
2014      // make sure oldrol starts returning all 1s because the auto-read reads it :-)
2015      state->joypad[0].oldrol = 16;
2016      state->joypad[1].oldrol = 16;
2012      // make sure read_idx starts returning all 1s because the auto-read reads it :-)
2013      state->read_idx[0] = 16;
2014      state->read_idx[1] = 16;
20172015   }
20182016
20192017}
r7523r7524
20242022   UINT8 res;
20252023
20262024   // joysticks
2027   if (state->joypad[0].oldrol >= 16)
2025   if (state->read_idx[0] >= 16)
20282026      res = 0x01;
20292027   else
2030      res = ((state->joypad[0].low | (state->joypad[0].high << 8)) >> (15 - state->joypad[0].oldrol++)) & 0x01;
2028      res = ((state->joypad[0].low | (state->joypad[0].high << 8)) >> (15 - state->read_idx[0]++)) & 0x01;
20312029
20322030   return res;
20332031}
r7523r7524
20372035   snes_state *state = (snes_state *)machine->driver_data;
20382036   UINT8 res;
20392037
2040   if (state->joypad[1].oldrol >= 16)
2038   if (state->read_idx[1] >= 16)
20412039      res = 0x01;
20422040   else
2043      res = ((state->joypad[1].low | (state->joypad[1].high << 8)) >> (15 - state->joypad[1].oldrol++)) & 0x01;
2041      res = ((state->joypad[1].low | (state->joypad[1].high << 8)) >> (15 - state->read_idx[1]++)) & 0x01;
20442042
20452043   return res;
20462044}
src/mame/includes/snes.h
r7523r7524
359359{
360360   UINT8 low;
361361   UINT8 high;
362   UINT8 oldrol;
363362};
364363
365364typedef void (*snes_io_read)(running_machine *machine);
r7523r7524
374373
375374   /* input-related */
376375   UINT8                 joy1l, joy1h, joy2l, joy2h, joy3l, joy3h, joy4l, joy4h;
376   UINT8                 read_idx[2];
377377   snes_controller_port  joypad[4];
378378
379379   /* input callbacks (to allow MESS to have its own input handlers) */
src/mess/drivers/snes.c
r7523r7524
3838
3939/*************************************
4040 *
41 *  Main CPU memory handlers
41 *  Memory handlers
4242 *
4343 *************************************/
4444
45static READ8_HANDLER( spc_ram_100_r )
46{
47   return spc_ram_r(space, offset + 0x100);
48}
49
50static WRITE8_HANDLER( spc_ram_100_w )
51{
52   spc_ram_w(space, offset + 0x100, data);
53}
54
55/*************************************
56 *
57 *  Address maps
58 *
59 *************************************/
60
4561static ADDRESS_MAP_START( snes_map, ADDRESS_SPACE_PROGRAM, 8)
4662   AM_RANGE(0x000000, 0x2fffff) AM_READWRITE(snes_r_bank1, snes_w_bank1)   /* I/O and ROM (repeats for each bank) */
4763   AM_RANGE(0x300000, 0x3fffff) AM_READWRITE(snes_r_bank2, snes_w_bank2)   /* I/O and ROM (repeats for each bank) */
r7523r7524
6278   AM_RANGE(0xe00000, 0xffffff) AM_READWRITE(superfx_r_bank3, superfx_w_bank3)
6379ADDRESS_MAP_END
6480
65static READ8_HANDLER( spc_ram_100_r )
66{
67   return spc_ram_r(space, offset + 0x100);
68}
69
70static WRITE8_HANDLER( spc_ram_100_w )
71{
72   spc_ram_w(space, offset + 0x100, data);
73}
74
7581static ADDRESS_MAP_START( spc_map, ADDRESS_SPACE_PROGRAM, 8)
7682   AM_RANGE(0x0000, 0x00ef) AM_READWRITE(spc_ram_r, spc_ram_w) AM_BASE(&spc_ram)      /* lower 32k ram */
7783   AM_RANGE(0x00f0, 0x00ff) AM_READWRITE(spc_io_r, spc_io_w)      /* spc io */
r7523r7524
8288
8389
8490
85/***************************************************************************
91/*************************************
92 *
93 *  Input ports
94 *
95 *************************************/
8696
87  Input ports
97static INPUT_PORTS_START( snes )
98   PORT_START("CTRLSEL")  /* Select Controller Type */
99   PORT_CATEGORY_CLASS( 0x0f, 0x01, "P1 Controller")
100   PORT_CATEGORY_ITEM(  0x00, "Unconnected",      10 )
101   PORT_CATEGORY_ITEM(  0x01, "Gamepad",      11 )
102//   PORT_CATEGORY_ITEM(  0x02, "Mouse",         12 )
103//   PORT_CATEGORY_ITEM(  0x03, "Superscope",      13 )
104//   PORT_CATEGORY_ITEM(  0x04, "Justfier",      14 )
105//   PORT_CATEGORY_ITEM(  0x05, "Multitap",      15 )
106   PORT_CATEGORY_CLASS( 0xf0, 0x10, "P2 Controller")
107   PORT_CATEGORY_ITEM(  0x00, "Unconnected",      20 )
108   PORT_CATEGORY_ITEM(  0x10, "Gamepad",      21 )
109//   PORT_CATEGORY_ITEM(  0x20, "Mouse",         22 )
110//   PORT_CATEGORY_ITEM(  0x30, "Superscope",      23 )
111//   PORT_CATEGORY_ITEM(  0x40, "Justfier",      24 )
112//   PORT_CATEGORY_ITEM(  0x50, "Multitap",      25 )
88113
89***************************************************************************/
90
91static INPUT_PORTS_START( snes )
92114   PORT_START("SERIAL1_DATA1_L")
93   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P1 Button A") PORT_PLAYER(1)
94   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P1 Button X") PORT_PLAYER(1)
95   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P1 Button L") PORT_PLAYER(1)
96   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P1 Button R") PORT_PLAYER(1)
115   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P1 Button A") PORT_PLAYER(1) PORT_CATEGORY(11)
116   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P1 Button X") PORT_PLAYER(1) PORT_CATEGORY(11)
117   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P1 Button L") PORT_PLAYER(1) PORT_CATEGORY(11)
118   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P1 Button R") PORT_PLAYER(1) PORT_CATEGORY(11)
97119   PORT_START("SERIAL1_DATA1_H")
98   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P1 Button B") PORT_PLAYER(1)
99   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P1 Button Y") PORT_PLAYER(1)
100   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_NAME("P1 Select")
101   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START1 ) PORT_NAME("P1 Start")
102   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
103   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
104   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
105   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
120   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P1 Button B") PORT_PLAYER(1) PORT_CATEGORY(11)
121   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P1 Button Y") PORT_PLAYER(1) PORT_CATEGORY(11)
122   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_NAME("P1 Select") PORT_CATEGORY(11)
123   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START1 ) PORT_NAME("P1 Start") PORT_CATEGORY(11)
124   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_CATEGORY(11)
125   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_CATEGORY(11)
126   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_CATEGORY(11)
127   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_CATEGORY(11)
106128
107129   PORT_START("SERIAL2_DATA1_L")
108   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P2 Button A") PORT_PLAYER(2)
109   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P2 Button X") PORT_PLAYER(2)
110   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P2 Button L") PORT_PLAYER(2)
111   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P2 Button R") PORT_PLAYER(2)
130   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P2 Button A") PORT_PLAYER(2) PORT_CATEGORY(21)
131   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P2 Button X") PORT_PLAYER(2) PORT_CATEGORY(21)
132   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P2 Button L") PORT_PLAYER(2) PORT_CATEGORY(21)
133   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P2 Button R") PORT_PLAYER(2) PORT_CATEGORY(21)
112134   PORT_START("SERIAL2_DATA1_H")
113   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P2 Button B") PORT_PLAYER(2)
114   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P2 Button Y") PORT_PLAYER(2)
115   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SERVICE2 ) PORT_NAME("P2 Select")
116   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START2 ) PORT_NAME("P2 Start")
117   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
118   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
119   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
120   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
135   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P2 Button B") PORT_PLAYER(2) PORT_CATEGORY(21)
136   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P2 Button Y") PORT_PLAYER(2) PORT_CATEGORY(21)
137   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SERVICE2 ) PORT_NAME("P2 Select") PORT_CATEGORY(21)
138   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START2 ) PORT_NAME("P2 Start") PORT_CATEGORY(21)
139   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_CATEGORY(21)
140   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_CATEGORY(21)
141   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CATEGORY(21)
142   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_CATEGORY(21)
121143
122144   PORT_START("SERIAL1_DATA2_L")
123145   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
r7523r7524
136158   PORT_CONFSETTING(   0x1, DEF_STR( Yes ) )
137159
138160   PORT_START("DEBUG1")
139   PORT_DIPNAME( 0x3, 0x0, "Browse tiles" )
140   PORT_DIPSETTING(   0x0, DEF_STR( Off ) )
141   PORT_DIPSETTING(   0x1, "2bpl" )
142   PORT_DIPSETTING(   0x2, "4bpl" )
143   PORT_DIPSETTING(   0x3, "8bpl" )
144   PORT_DIPNAME( 0xc, 0x0, "Browse maps" )
145   PORT_DIPSETTING(   0x0, DEF_STR( Off ) )
146   PORT_DIPSETTING(   0x4, "2bpl" )
147   PORT_DIPSETTING(   0x8, "4bpl" )
148   PORT_DIPSETTING(   0xc, "8bpl" )
161   PORT_CONFNAME( 0x3, 0x0, "Browse tiles" )
162   PORT_CONFSETTING(   0x0, DEF_STR( Off ) )
163   PORT_CONFSETTING(   0x1, "2bpl" )
164   PORT_CONFSETTING(   0x2, "4bpl" )
165   PORT_CONFSETTING(   0x3, "8bpl" )
166   PORT_CONFNAME( 0xc, 0x0, "Browse maps" )
167   PORT_CONFSETTING(   0x0, DEF_STR( Off ) )
168   PORT_CONFSETTING(   0x4, "2bpl" )
169   PORT_CONFSETTING(   0x8, "4bpl" )
170   PORT_CONFSETTING(   0xc, "8bpl" )
149171
150172   PORT_START("DEBUG2")
151173   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 1") PORT_CODE(KEYCODE_1_PAD)
r7523r7524
175197INPUT_PORTS_END
176198
177199
178/***************************************************************************
200/*************************************
201 *
202 *  Input callbacks
203 *
204 *************************************/
179205
180  Machine driver
206static void snes_input_read( running_machine *machine )
207{
208   snes_state *state = (snes_state *)machine->driver_data;
209   UINT8 ctrl1 = input_port_read(machine, "CTRLSEL") & 0x0f;
210   UINT8 ctrl2 = input_port_read(machine, "CTRLSEL") & 0xf0;
211   int i;
181212
182***************************************************************************/
213   switch (ctrl1)
214   {
215   case 1:   /* joystick */
216      state->joypad[0].low  = input_port_read(machine, "SERIAL1_DATA1_L");
217      state->joypad[0].high = input_port_read(machine, "SERIAL1_DATA1_H");
218      state->joypad[2].low  = input_port_read(machine, "SERIAL1_DATA2_L");
219      state->joypad[2].high = input_port_read(machine, "SERIAL1_DATA2_H");
220      break;
221   case 0:   /* no controller in port1 */
222   default:
223      break;
224   }
183225
226   switch (ctrl2)
227   {
228   case 1:   /* joystick */
229      state->joypad[1].low  = input_port_read(machine, "SERIAL2_DATA1_L");
230      state->joypad[1].high = input_port_read(machine, "SERIAL2_DATA1_H");
231      state->joypad[3].low  = input_port_read(machine, "SERIAL2_DATA2_L");
232      state->joypad[3].high = input_port_read(machine, "SERIAL2_DATA2_H");
233      break;
234   case 0:   /* no controller in port2 */
235   default:
236      break;
237   }
184238
239   // avoid sending signals that could crash games
240   for (i = 0; i < 4; i++)
241   {
242      // if left, no right
243      if (state->joypad[i].high & 2)
244         state->joypad[i].high &= ~1;
245      // if up, no down
246      if (state->joypad[i].high & 8)
247         state->joypad[i].high &= ~4;
248   }
249
250   // is automatic reading on?
251   if (snes_ram[NMITIMEN] & 1)
252   {
253      state->joy1l = state->joypad[0].low;
254      state->joy1h = state->joypad[0].high;
255      state->joy2l = state->joypad[1].low;
256      state->joy2h = state->joypad[1].high;
257      state->joy3l = state->joypad[2].low;
258      state->joy3h = state->joypad[2].high;
259      state->joy4l = state->joypad[3].low;
260      state->joy4h = state->joypad[3].high;
261
262      // make sure oldrol starts returning all 1s because the auto-read reads it :-)
263      state->read_idx[0] = 16;
264      state->read_idx[1] = 16;
265   }
266
267}
268
269static UINT8 snes_oldjoy1_read( running_machine *machine )
270{
271   snes_state *state = (snes_state *)machine->driver_data;
272   UINT8 res = 0;
273
274   // joysticks
275   if (state->read_idx[0] >= 16)
276      res = 0x01;
277   else
278      res = ((state->joypad[0].low | (state->joypad[0].high << 8)) >> (15 - state->read_idx[0]++)) & 0x01;
279
280   return res;
281}
282
283static UINT8 snes_oldjoy2_read( running_machine *machine )
284{
285   snes_state *state = (snes_state *)machine->driver_data;
286   UINT8 res = 0;
287
288   // joysticks
289   if (state->read_idx[1] >= 16)
290      res = 0x01;
291   else
292      res = ((state->joypad[1].low | (state->joypad[1].high << 8)) >> (15 - state->read_idx[1]++)) & 0x01;
293
294   return res;
295}
296
297/*************************************
298 *
299 *  Machine driver
300 *
301 *************************************/
302
303static MACHINE_RESET( snes_mess )
304{
305   snes_state *state = (snes_state *)machine->driver_data;
306
307   MACHINE_RESET_CALL(snes);
308
309   state->io_read = snes_input_read;
310   state->oldjoy1_read = snes_oldjoy1_read;
311   state->oldjoy2_read = snes_oldjoy2_read;
312}
313
185314static MACHINE_DRIVER_START( snes )
186315
187316   /* driver data */
r7523r7524
197326   //MDRV_QUANTUM_TIME(HZ(48000))
198327   MDRV_QUANTUM_PERFECT_CPU("maincpu")
199328
200   MDRV_MACHINE_START( snes_mess )
201   MDRV_MACHINE_RESET( snes )
329   MDRV_MACHINE_START(snes_mess)
330   MDRV_MACHINE_RESET(snes_mess)
202331
203332   /* video hardware */
204   MDRV_VIDEO_START( generic_bitmapped )
205   MDRV_VIDEO_UPDATE( snes )
333   MDRV_VIDEO_START(generic_bitmapped)
334   MDRV_VIDEO_UPDATE(snes)
206335
207336   MDRV_SCREEN_ADD("screen", RASTER)
208337   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team