Previous 15994 Revisions Next

r7544 Tuesday 9th March, 2010 at 21:10:47 UTC by Fabio Priuli
[SNES] Refactored joypad inputs to be consistent with other devices
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mess/drivers]snes.c

src/mame/machine/snes.c
r7543r7544
19381938static void nss_io_read( running_machine *machine )
19391939{
19401940   snes_state *state = (snes_state *)machine->driver_data;
1941   int i;
1941   static const char *const portnames[2][4] =
1942         {
1943            { "SERIAL1_DATA1_L", "SERIAL1_DATA1_H", "SERIAL1_DATA2_L", "SERIAL1_DATA2_H" },
1944            { "SERIAL2_DATA1_L", "SERIAL2_DATA1_H", "SERIAL2_DATA2_L", "SERIAL2_DATA2_H" },
1945         };
1946   int port;
19421947
1943   state->joypad[0].low  = input_port_read(machine, "SERIAL1_DATA1_L");
1944   state->joypad[0].high = input_port_read(machine, "SERIAL1_DATA1_H");
1945   state->joypad[1].low  = input_port_read(machine, "SERIAL2_DATA1_L");
1946   state->joypad[1].high = input_port_read(machine, "SERIAL2_DATA1_H");
1947   state->joypad[2].low  = input_port_read(machine, "SERIAL1_DATA2_L");
1948   state->joypad[2].high = input_port_read(machine, "SERIAL1_DATA2_H");
1949   state->joypad[3].low  = input_port_read(machine, "SERIAL2_DATA2_L");
1950   state->joypad[3].high = input_port_read(machine, "SERIAL2_DATA2_H");
1948   for (port = 0; port < 2; port++)
1949   {
1950      state->data1[port] = input_port_read(machine, portnames[port][0]) | (input_port_read(machine, portnames[port][1]) << 8);
1951      state->data2[port] = input_port_read(machine, portnames[port][2]) | (input_port_read(machine, portnames[port][3]) << 8);
19511952
1952   // avoid sending signals that could crash games
1953   for (i = 0; i < 4; i++)
1954   {
1953      // avoid sending signals that could crash games
19551954      // if left, no right
1956      if (state->joypad[i].high & 2)
1957         state->joypad[i].high &= ~1;
1955      if (state->data1[port] & 0x200)
1956         state->data1[port] &= ~0x100;
19581957      // if up, no down
1959      if (state->joypad[i].high & 8)
1960         state->joypad[i].high &= ~4;
1958      if (state->data1[port] & 0x800)
1959         state->data1[port] &= ~0x400;
1960
1961      state->joypad[port].buttons = state->data1[port];
19611962   }
19621963
1963   // is automatic reading on?
1964   // is automatic reading on? if so, copy port data1/data2 to joy1l->joy4h
1965   // this actually works like reading the first 16bits from oldjoy1/2 in reverse order
19641966   if (snes_ram[NMITIMEN] & 1)
19651967   {
1966      state->joy1l = state->joypad[0].low;
1967      state->joy1h = state->joypad[0].high;
1968      state->joy2l = state->joypad[1].low;
1969      state->joy2h = state->joypad[1].high;
1970      state->joy3l = state->joypad[2].low;
1971      state->joy3h = state->joypad[2].high;
1972      state->joy4l = state->joypad[3].low;
1973      state->joy4h = state->joypad[3].high;
1968      state->joy1l = (state->data1[0] & 0x00ff) >> 0;
1969      state->joy1h = (state->data1[0] & 0xff00) >> 8;
1970      state->joy2l = (state->data1[1] & 0x00ff) >> 0;
1971      state->joy2h = (state->data1[1] & 0xff00) >> 8;
1972      state->joy3l = (state->data2[0] & 0x00ff) >> 0;
1973      state->joy3h = (state->data2[0] & 0xff00) >> 8;
1974      state->joy4l = (state->data2[1] & 0x00ff) >> 0;
1975      state->joy4h = (state->data2[1] & 0xff00) >> 8;
19741976
19751977      // make sure read_idx starts returning all 1s because the auto-read reads it :-)
19761978      state->read_idx[0] = 16;
r7543r7544
19841986   snes_state *state = (snes_state *)machine->driver_data;
19851987   UINT8 res;
19861988
1987   // joysticks
19881989   if (state->read_idx[0] >= 16)
19891990      res = 0x01;
19901991   else
1991      res = ((state->joypad[0].low | (state->joypad[0].high << 8)) >> (15 - state->read_idx[0]++)) & 0x01;
1992      res = (state->joypad[0].buttons >> (15 - state->read_idx[0]++)) & 0x01;
19921993
19931994   return res;
19941995}
r7543r7544
20012002   if (state->read_idx[1] >= 16)
20022003      res = 0x01;
20032004   else
2004      res = ((state->joypad[1].low | (state->joypad[1].high << 8)) >> (15 - state->read_idx[1]++)) & 0x01;
2005      res = (state->joypad[1].buttons >> (15 - state->read_idx[1]++)) & 0x01;
20052006
20062007   return res;
20072008}
src/mame/includes/snes.h
r7543r7544
355355#define DSP_FIR_C6      0x6F
356356#define DSP_FIR_C7      0x7F
357357
358struct snes_controller_port
358struct snes_joypad
359359{
360   UINT8 low;
361   UINT8 high;
360   UINT16 buttons;
362361};
363362
364363struct snes_mouse
r7543r7544
389388
390389   /* input-related */
391390   UINT8                 joy1l, joy1h, joy2l, joy2h, joy3l, joy3h, joy4l, joy4h;
391   UINT16                data1[2], data2[2];
392392   UINT8                 read_idx[2];
393   snes_controller_port  joypad[4];
393   snes_joypad           joypad[2];
394394   snes_mouse            mouse[2];
395395   snes_superscope       scope[2];
396396
src/mess/drivers/snes.c
r7543r7544
373373            { "SERIAL2_DATA1_L", "SERIAL2_DATA1_H", "SERIAL2_DATA2_L", "SERIAL2_DATA2_H" },
374374         };
375375
376   state->joypad[port + 0].low  = input_port_read(machine, portnames[port][0]);
377   state->joypad[port + 0].high = input_port_read(machine, portnames[port][1]);
378   state->joypad[port + 2].low  = input_port_read(machine, portnames[port][2]);
379   state->joypad[port + 2].high = input_port_read(machine, portnames[port][3]);
376   state->data1[port] = input_port_read(machine, portnames[port][0]) | (input_port_read(machine, portnames[port][1]) << 8);
377   state->data2[port] = input_port_read(machine, portnames[port][2]) | (input_port_read(machine, portnames[port][3]) << 8);
378
379   // avoid sending signals that could crash games
380   // if left, no right
381   if (state->data1[port] & 0x200)
382      state->data1[port] &= ~0x100;
383   // if up, no down
384   if (state->data1[port] & 0x800)
385      state->data1[port] &= ~0x400;
386
387   state->joypad[port].buttons = state->data1[port];
380388}
381389
382390static void snes_input_read_mouse( running_machine *machine, int port )
r7543r7544
437445      state->mouse[port].deltay = var & 0xff;
438446      state->mouse[port].oldy = state->mouse[port].y;
439447   }
448
449   state->data1[port] = state->mouse[port].buttons | (0x00 << 8);
450   state->data2[port] = 0;
440451}
441452
442453static void snes_input_read_superscope( running_machine *machine, int port )
r7543r7544
496507   words, you can connect SuperScope to Port1, but there is no way SNES could detect its on-screen position */
497508   if ((state->scope[port].buttons & 0xc0) && !(state->scope[port].buttons & 0x02) && port == 1)
498509      snes_gun_latch(machine, state->scope[port].x, state->scope[port].y);
510
511   state->data1[port] = 0xff | (state->scope[port].buttons << 8);
512   state->data2[port] = 0;
499513}
500514
501515static void snes_input_read( running_machine *machine )
r7543r7544
503517   snes_state *state = (snes_state *)machine->driver_data;
504518   UINT8 ctrl1 = input_port_read(machine, "CTRLSEL") & 0x0f;
505519   UINT8 ctrl2 = (input_port_read(machine, "CTRLSEL") & 0xf0) >> 4;
506   int i;
507520
508521   /* Check if lightgun has been chosen as input: if so, enable crosshair */
509522   timer_set(machine, attotime_zero, NULL, 0, lightgun_tick);
r7543r7544
521534      break;
522535   case 0:   /* no controller in port1 */
523536   default:
537      state->data1[0] = 0;
538      state->data2[0] = 0;
524539      break;
525540   }
526541
r7543r7544
537552      break;
538553   case 0:   /* no controller in port2 */
539554   default:
555      state->data1[1] = 0;
556      state->data2[1] = 0;
540557      break;
541558   }
542559
543   // avoid sending signals that could crash games
544   for (i = 0; i < 4; i++)
545   {
546      // if left, no right
547      if (state->joypad[i].high & 2)
548         state->joypad[i].high &= ~1;
549      // if up, no down
550      if (state->joypad[i].high & 8)
551         state->joypad[i].high &= ~4;
552   }
553
554   // is automatic reading on?
560   // is automatic reading on? if so, copy port data1/data2 to joy1l->joy4h
561   // this actually works like reading the first 16bits from oldjoy1/2 in reverse order
555562   if (snes_ram[NMITIMEN] & 1)
556563   {
557      switch (ctrl1)
558      {
559      case 1:   /* SNES joypad */
560         state->joy1l = state->joypad[0].low;
561         state->joy1h = state->joypad[0].high;
562         state->joy3l = state->joypad[2].low;
563         state->joy3h = state->joypad[2].high;
564         break;
565      case 2:   /* SNES Mouse */
566         state->joy1l = state->mouse[0].buttons;
567         state->joy1h = 0;
568         state->joy3l = 0;
569         state->joy3h = 0;
570         break;
571      case 3:   /* SNES Superscope */
572         state->joy1l = 0xff;
573         state->joy1h = state->scope[0].buttons;
574         state->joy3l = 0;
575         state->joy3h = 0;
576         break;
577      case 0:   /* no controller in port2 */
578      default:
579         state->joy1l = 0;
580         state->joy1h = 0;
581         state->joy3l = 0;
582         state->joy3h = 0;
583         break;
584      }
564      state->joy1l = (state->data1[0] & 0x00ff) >> 0;
565      state->joy1h = (state->data1[0] & 0xff00) >> 8;
566      state->joy2l = (state->data1[1] & 0x00ff) >> 0;
567      state->joy2h = (state->data1[1] & 0xff00) >> 8;
568      state->joy3l = (state->data2[0] & 0x00ff) >> 0;
569      state->joy3h = (state->data2[0] & 0xff00) >> 8;
570      state->joy4l = (state->data2[1] & 0x00ff) >> 0;
571      state->joy4h = (state->data2[1] & 0xff00) >> 8;
585572
586      switch (ctrl2)
587      {
588      case 1:   /* SNES joypad */
589         state->joy2l = state->joypad[1].low;
590         state->joy2h = state->joypad[1].high;
591         state->joy4l = state->joypad[3].low;
592         state->joy4h = state->joypad[3].high;
593         break;
594      case 2:   /* SNES Mouse */
595         state->joy2l = state->mouse[1].buttons;
596         state->joy2h = 0;
597         state->joy4l = 0;
598         state->joy4h = 0;
599         break;
600      case 3:   /* SNES Superscope */
601         state->joy2l = 0xff;
602         state->joy2h = state->scope[1].buttons;
603         state->joy4l = 0;
604         state->joy4h = 0;
605         break;
606      case 0:   /* no controller in port2 */
607      default:
608         state->joy2l = 0;
609         state->joy2h = 0;
610         state->joy4l = 0;
611         state->joy4h = 0;
612         break;
613      }
614
615573      // make sure read_idx starts returning all 1s because the auto-read reads it :-)
616574      state->read_idx[0] = 16;
617575      state->read_idx[1] = 16;
r7543r7544
631589      if (state->read_idx[0] >= 16)
632590         res = 0x01;
633591      else
634         res = ((state->joypad[0].low | (state->joypad[0].high << 8)) >> (15 - state->read_idx[0]++)) & 0x01;
592         res = (state->joypad[0].buttons >> (15 - state->read_idx[0]++)) & 0x01;
635593      break;
636594   case 2:   /* SNES Mouse */
637595      if (state->read_idx[0] >= 32)
r7543r7544
671629      if (state->read_idx[1] >= 16)
672630         res = 0x01;
673631      else
674         res = ((state->joypad[1].low | (state->joypad[1].high << 8)) >> (15 - state->read_idx[1]++)) & 0x01;
632         res = (state->joypad[1].buttons >> (15 - state->read_idx[1]++)) & 0x01;
675633      break;
676634   case 2:   /* SNES Mouse */
677635      if (state->read_idx[1] >= 32)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team