Previous 15994 Revisions Next

r7528 Sunday 7th March, 2010 at 09:47:43 UTC by Fabio Priuli
[SNES] Added SNES Mouse support
[src/mame/includes]snes.h
[src/mess/drivers]snes.c

src/mame/includes/snes.h
r7527r7528
361361   UINT8 high;
362362};
363363
364struct snes_mouse
365{
366   INT16 x, y, oldx, oldy;
367   UINT8 buttons;
368   UINT8 deltax, deltay;
369   int speed;
370};
371
364372typedef void (*snes_io_read)(running_machine *machine);
365373typedef UINT8 (*snes_oldjoy_read)(running_machine *machine);
366374
r7527r7528
375383   UINT8                 joy1l, joy1h, joy2l, joy2h, joy3l, joy3h, joy4l, joy4h;
376384   UINT8                 read_idx[2];
377385   snes_controller_port  joypad[4];
386   snes_mouse            mouse[2];
378387
379388   /* input callbacks (to allow MESS to have its own input handlers) */
380389   snes_io_read          io_read;
src/mess/drivers/snes.c
r7527r7528
9494 *
9595 *************************************/
9696
97static CUSTOM_INPUT( snes_mouse_speed_input )
98{
99   snes_state *state = (snes_state *)field->port->machine->driver_data;
100   int port = (FPTR)param;
101
102   if (snes_ram[OLDJOY1] & 0x1)
103   {
104      state->mouse[port].speed++;
105      if ((state->mouse[port].speed & 0x03) == 0x03)
106         state->mouse[port].speed = 0;
107   }
108
109   return state->mouse[port].speed;
110}
111
97112static INPUT_PORTS_START( snes )
98113   PORT_START("CTRLSEL")  /* Select Controller Type */
99114   PORT_CATEGORY_CLASS( 0x0f, 0x01, "P1 Controller")
100115   PORT_CATEGORY_ITEM(  0x00, "Unconnected",      10 )
101116   PORT_CATEGORY_ITEM(  0x01, "Gamepad",      11 )
102//   PORT_CATEGORY_ITEM(  0x02, "Mouse",         12 )
117   PORT_CATEGORY_ITEM(  0x02, "Mouse",         12 )
103118//   PORT_CATEGORY_ITEM(  0x03, "Superscope",      13 )
104119//   PORT_CATEGORY_ITEM(  0x04, "Justfier",      14 )
105120//   PORT_CATEGORY_ITEM(  0x05, "Multitap",      15 )
106121   PORT_CATEGORY_CLASS( 0xf0, 0x10, "P2 Controller")
107122   PORT_CATEGORY_ITEM(  0x00, "Unconnected",      20 )
108123   PORT_CATEGORY_ITEM(  0x10, "Gamepad",      21 )
109//   PORT_CATEGORY_ITEM(  0x20, "Mouse",         22 )
124   PORT_CATEGORY_ITEM(  0x20, "Mouse",         22 )
110125//   PORT_CATEGORY_ITEM(  0x30, "Superscope",      23 )
111126//   PORT_CATEGORY_ITEM(  0x40, "Justfier",      24 )
112127//   PORT_CATEGORY_ITEM(  0x50, "Multitap",      25 )
r7527r7528
151166   PORT_START("SERIAL2_DATA2_H")
152167   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
153168
169   PORT_START("MOUSE1")
170   /* bits 0,3 = mouse signature (must be 1) */
171   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
172   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED )
173   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
174   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
175   /* bits 4,5 = mouse speed: 0 = slow, 1 = normal, 2 = fast, 3 = unused */
176   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_mouse_speed_input, (void *)0)
177   /* bits 6,7 = mouse buttons */
178   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P1 Mouse Button Left") PORT_PLAYER(1) PORT_CATEGORY(12)
179   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P1 Mouse Button Right") PORT_PLAYER(1) PORT_CATEGORY(12)
180
181   PORT_START("MOUSE1_X")
182   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12)
183
184   PORT_START("MOUSE1_Y")
185   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12)
186
187   PORT_START("MOUSE2")
188   /* bits 0,3 = mouse signature (must be 1) */
189   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
190   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED )
191   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
192   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
193   /* bits 4,5 = mouse speed: 0 = slow, 1 = normal, 2 = fast, 3 = unused */
194   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_mouse_speed_input, (void *)1)
195   /* bits 6,7 = mouse buttons */
196   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P2 Mouse Button Left") PORT_PLAYER(2) PORT_CATEGORY(22)
197   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P2 Mouse Button Right") PORT_PLAYER(2) PORT_CATEGORY(22)
198
199   PORT_START("MOUSE2_X")
200   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2) PORT_CATEGORY(22)
201
202   PORT_START("MOUSE2_Y")
203   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2) PORT_CATEGORY(22)
204
154205#ifdef SNES_LAYER_DEBUG
155206   PORT_START("INTERNAL")
156207   PORT_CONFNAME( 0x1, 0x1, "Enforce 32 sprites/line" )
r7527r7528
203254 *
204255 *************************************/
205256
257static void snes_input_read_joy( running_machine *machine, int port )
258{
259   snes_state *state = (snes_state *)machine->driver_data;
260   static const char *const portnames[2][4] =
261         {
262            { "SERIAL1_DATA1_L", "SERIAL1_DATA1_H", "SERIAL1_DATA2_L", "SERIAL1_DATA2_H" },
263            { "SERIAL2_DATA1_L", "SERIAL2_DATA1_H", "SERIAL2_DATA2_L", "SERIAL2_DATA2_H" },
264         };
265
266   state->joypad[port + 0].low  = input_port_read(machine, portnames[port][0]);
267   state->joypad[port + 0].high = input_port_read(machine, portnames[port][1]);
268   state->joypad[port + 2].low  = input_port_read(machine, portnames[port][2]);
269   state->joypad[port + 2].high = input_port_read(machine, portnames[port][3]);
270}
271
272static void snes_input_read_mouse( running_machine *machine, int port )
273{
274   snes_state *state = (snes_state *)machine->driver_data;
275   INT16 var;
276   static const char *const portnames[2][3] =
277         {
278            { "MOUSE1", "MOUSE1_X", "MOUSE1_Y" },
279            { "MOUSE2", "MOUSE2_X", "MOUSE2_Y" },
280         };
281
282   state->mouse[port].buttons = input_port_read(machine, portnames[port][0]);
283   state->mouse[port].x = input_port_read(machine, portnames[port][1]);
284   state->mouse[port].y = input_port_read(machine, portnames[port][2]);
285   var = state->mouse[port].x - state->mouse[port].oldx;
286
287   if (var < -127)
288   {
289      state->mouse[port].deltax = 0xff;
290      state->mouse[port].oldx -= 127;
291   }
292   else if (var < 0)
293   {
294      state->mouse[port].deltax = 0x80 | (-var);
295      state->mouse[port].oldx = state->mouse[port].x;
296   }
297   else if (var > 127)
298   {
299      state->mouse[port].deltax = 0x7f;
300      state->mouse[port].oldx += 127;
301   }
302   else
303   {
304      state->mouse[port].deltax = var & 0xff;
305      state->mouse[port].oldx = state->mouse[port].x;
306   }
307
308   var = state->mouse[port].y - state->mouse[port].oldy;
309
310   if (var < -127)
311   {
312      state->mouse[port].deltay = 0xff;
313      state->mouse[port].oldy -= 127;
314   }
315   else if (var < 0)
316   {
317      state->mouse[port].deltay = 0x80 | (-var);
318      state->mouse[port].oldy = state->mouse[port].y;
319   }
320   else if (var > 127)
321   {
322      state->mouse[port].deltay = 0x7f;
323      state->mouse[port].oldy += 127;
324   }
325   else
326   {
327      state->mouse[port].deltay = var & 0xff;
328      state->mouse[port].oldy = state->mouse[port].y;
329   }
330}
331
206332static void snes_input_read( running_machine *machine )
207333{
208334   snes_state *state = (snes_state *)machine->driver_data;
209335   UINT8 ctrl1 = input_port_read(machine, "CTRLSEL") & 0x0f;
210   UINT8 ctrl2 = input_port_read(machine, "CTRLSEL") & 0xf0;
336   UINT8 ctrl2 = (input_port_read(machine, "CTRLSEL") & 0xf0) >> 4;
211337   int i;
212338
213339   switch (ctrl1)
214340   {
215341   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");
342      snes_input_read_joy(machine, 0);
220343      break;
344   case 2:   /* SNES Mouse */
345      snes_input_read_mouse(machine, 0);
346      break;
221347   case 0:   /* no controller in port1 */
222348   default:
223349      break;
r7527r7528
226352   switch (ctrl2)
227353   {
228354   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");
355      snes_input_read_joy(machine, 1);
233356      break;
357   case 2:   /* SNES Mouse */
358      snes_input_read_mouse(machine, 1);
359      break;
234360   case 0:   /* no controller in port2 */
235361   default:
236362      break;
r7527r7528
250376   // is automatic reading on?
251377   if (snes_ram[NMITIMEN] & 1)
252378   {
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;
379      switch (ctrl1)
380      {
381      case 1:   /* joystick */
382         state->joy1l = state->joypad[0].low;
383         state->joy1h = state->joypad[0].high;
384         state->joy3l = state->joypad[2].low;
385         state->joy3h = state->joypad[2].high;
386         break;
387      case 2:   /* SNES Mouse */
388         state->joy1l = state->mouse[0].buttons;
389         state->joy1h = 0;
390         state->joy3l = 0;
391         state->joy3h = 0;
392         break;
393      case 0:   /* no controller in port2 */
394      default:
395         state->joy1l = 0;
396         state->joy1h = 0;
397         state->joy3l = 0;
398         state->joy3h = 0;
399         break;
400      }
261401
402      switch (ctrl2)
403      {
404      case 1:   /* joystick */
405         state->joy2l = state->joypad[1].low;
406         state->joy2h = state->joypad[1].high;
407         state->joy4l = state->joypad[3].low;
408         state->joy4h = state->joypad[3].high;
409         break;
410      case 2:   /* SNES Mouse */
411         state->joy2l = state->mouse[1].buttons;
412         state->joy2h = 0;
413         state->joy4l = 0;
414         state->joy4h = 0;
415         break;
416      case 0:   /* no controller in port2 */
417      default:
418         state->joy2l = 0;
419         state->joy2h = 0;
420         state->joy4l = 0;
421         state->joy4h = 0;
422         break;
423      }
424
262425      // make sure oldrol starts returning all 1s because the auto-read reads it :-)
263426      state->read_idx[0] = 16;
264427      state->read_idx[1] = 16;
r7527r7528
269432static UINT8 snes_oldjoy1_read( running_machine *machine )
270433{
271434   snes_state *state = (snes_state *)machine->driver_data;
435   UINT8 ctrl1 = input_port_read(machine, "CTRLSEL") & 0x0f;
272436   UINT8 res = 0;
273437
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;
438   switch (ctrl1)
439   {
440   case 1:   /* joystick */
441      if (state->read_idx[0] >= 16)
442         res = 0x01;
443      else
444         res = ((state->joypad[0].low | (state->joypad[0].high << 8)) >> (15 - state->read_idx[0]++)) & 0x01;
445      break;
446   case 2:   /* SNES Mouse */
447      if (state->read_idx[0] >= 32)
448         res = 0x01;
449      else if (state->read_idx[0] >= 24)
450         res = (state->mouse[0].deltax >> (31 - state->read_idx[0]++)) & 0x01;
451      else if (state->read_idx[0] >= 16)
452         res = (state->mouse[0].deltay >> (23 - state->read_idx[0]++)) & 0x01;
453      else if (state->read_idx[0] >= 8)
454         res = (state->mouse[0].buttons >> (15 - state->read_idx[0]++)) & 0x01;
455      else
456         res = 0;
457      break;
458   case 0:   /* no controller in port2 */
459   default:
460      break;
461   }
279462
280463   return res;
281464}
r7527r7528
283466static UINT8 snes_oldjoy2_read( running_machine *machine )
284467{
285468   snes_state *state = (snes_state *)machine->driver_data;
469   UINT8 ctrl2 = (input_port_read(machine, "CTRLSEL") & 0xf0) >> 4;
286470   UINT8 res = 0;
287471
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;
472   switch (ctrl2)
473   {
474   case 1:   /* joystick */
475      if (state->read_idx[1] >= 16)
476         res = 0x01;
477      else
478         res = ((state->joypad[1].low | (state->joypad[1].high << 8)) >> (15 - state->read_idx[1]++)) & 0x01;
479      break;
480   case 2:   /* SNES Mouse */
481      if (state->read_idx[1] >= 32)
482         res = 0x01;
483      else if (state->read_idx[1] >= 24)
484         res = (state->mouse[1].deltax >> (31 - state->read_idx[1]++)) & 0x01;
485      else if (state->read_idx[1] >= 16)
486         res = (state->mouse[1].deltay >> (23 - state->read_idx[1]++)) & 0x01;
487      else if (state->read_idx[1] >= 8)
488         res = (state->mouse[1].buttons >> (15 - state->read_idx[1]++)) & 0x01;
489      else
490         res = 0;
491      break;
492   case 0:   /* no controller in port2 */
493   default:
494      break;
495   }
293496
294497   return res;
295498}
r7527r7528
382585 *
383586 *************************************/
384587
385ROM_START(snes)
588ROM_START( snes )
386589   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
590
387591   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
388592   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
593
389594   ROM_REGION( 0x1000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
390595   ROM_LOAD( "dsp1data.bin", 0x000000, 0x000800, CRC(4b02d66d) SHA1(1534f4403d2a0f68ba6e35186fe7595d33de34b1) )
391596   ROM_LOAD( "dsp3data.bin", 0x000800, 0x000800, CRC(4a1c5453) SHA1(2f69c652109938cde21df5eb89890bf090256dbb) )
597
392598   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
393599ROM_END
394600
395ROM_START(snessfx)
601ROM_START( snessfx )
396602   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
603
397604   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
398605   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
606
399607   ROM_REGION( 0x1000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
400608   ROM_LOAD( "dsp1data.bin", 0x000000, 0x000800, CRC(4b02d66d) SHA1(1534f4403d2a0f68ba6e35186fe7595d33de34b1) )
609
401610   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
402611ROM_END
403612
404ROM_START(snespal)
613ROM_START( snespal )
405614   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
615
406616   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
407617   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
618
408619   ROM_REGION( 0x1000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
409620   ROM_LOAD( "dsp1data.bin", 0x000000, 0x000800, CRC(4b02d66d) SHA1(1534f4403d2a0f68ba6e35186fe7595d33de34b1) )
410621   ROM_LOAD( "dsp3data.bin", 0x000800, 0x000800, CRC(4a1c5453) SHA1(2f69c652109938cde21df5eb89890bf090256dbb) )
622
411623   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
412624ROM_END
413625
414ROM_START(snespsfx)
626ROM_START( snespsfx )
415627   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
628
416629   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
417630   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
631
418632   ROM_REGION( 0x1000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
419633   ROM_LOAD( "dsp1data.bin", 0x000000, 0x000800, CRC(4b02d66d) SHA1(1534f4403d2a0f68ba6e35186fe7595d33de34b1) )
634
420635   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
421636ROM_END
422637
423ROM_START(sfcbox)
638ROM_START( sfcbox )
424639   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
640
425641   /* atm, we only load these here, but we don't really emulate anything */
426642   ROM_REGION( 0x10000, "grom", 0 )
427643   ROM_LOAD( "grom1-1.bin", 0x0000, 0x8000, CRC(333bf9a7) SHA1(5d0cd9ca29e5580c3eebe9f136839987c879f979) )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team