~ubuntu-branches/debian/experimental/mednafen/experimental

« back to all changes in this revision

Viewing changes to src/psx/frontio.cpp

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2012-11-19 07:00:37 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20121119070037-jvknrm13zvim88oc
Tags: 0.9.26-1
* New upstream WIP version.
* Change priority to "extra" to match libvorbisidec1's.
* Drop "DM-Upload-Allowed" since it is no longer appropriate.
* Refresh patches, replacing MPC_STATUS_FAIL constant from older mpcdec
  versions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include "input/gamepad.h"
23
23
#include "input/dualanalog.h"
 
24
#include "input/dualshock.h"
24
25
#include "input/mouse.h"
 
26
#include "input/negcon.h"
 
27
#include "input/guncon.h"
 
28
#include "input/justifier.h"
 
29
 
25
30
#include "input/memcard.h"
26
31
 
27
32
#include "input/multitap.h"
53
58
 
54
59
}
55
60
 
 
61
void InputDevice::SetAMCT(bool)
 
62
{
 
63
 
 
64
}
 
65
 
 
66
void InputDevice::SetCrosshairsColor(uint32 color)
 
67
{
 
68
 
 
69
}
 
70
 
 
71
bool InputDevice::RequireNoFrameskip(void)
 
72
{
 
73
 return(false);
 
74
}
 
75
 
 
76
pscpu_timestamp_t InputDevice::GPULineHook(const pscpu_timestamp_t timestamp, bool vsync, uint32 *pixels, const MDFN_PixelFormat* const format, const unsigned width, const unsigned pix_clock_offset, const unsigned pix_clock)
 
77
{
 
78
 return(PSX_EVENT_MAXTS);
 
79
}
 
80
 
56
81
 
57
82
void InputDevice::UpdateInput(const void *data)
58
83
{
158
183
 
159
184
 DummyDevice = new InputDevice();
160
185
 
161
 
 for(int i = 0; i < 8; i++)
 
186
 for(unsigned i = 0; i < 8; i++)
162
187
 {
163
188
  DeviceData[i] = NULL;
164
189
  Devices[i] = new InputDevice();
165
190
  DevicesMC[i] = Device_Memcard_Create();
 
191
  chair_colors[i] = 1 << 24;
 
192
  Devices[i]->SetCrosshairsColor(chair_colors[i]);
166
193
 }
167
194
 
168
195
 for(unsigned i = 0; i < 2; i++)
173
200
 MapDevicesToPorts();
174
201
}
175
202
 
 
203
void FrontIO::SetAMCT(bool enabled)
 
204
{
 
205
 for(unsigned i = 0; i < 8; i++)
 
206
 {
 
207
  Devices[i]->SetAMCT(enabled);
 
208
 }
 
209
 amct_enabled = enabled;
 
210
}
 
211
 
 
212
void FrontIO::SetCrosshairsColor(unsigned port, uint32 color)
 
213
{
 
214
 assert(port >= 0 && port < 8);
 
215
 
 
216
 chair_colors[port] = color;
 
217
 Devices[port]->SetCrosshairsColor(color);
 
218
}
 
219
 
176
220
FrontIO::~FrontIO()
177
221
{
178
222
 for(int i = 0; i < 8; i++)
205
249
 }
206
250
}
207
251
 
208
 
int32 FrontIO::CalcNextEvent(int32 next_event)
 
252
pscpu_timestamp_t FrontIO::CalcNextEventTS(pscpu_timestamp_t timestamp, int32 next_event)
209
253
{
 
254
 pscpu_timestamp_t ret;
 
255
 
210
256
 if(ClockDivider > 0 && ClockDivider < next_event)
211
257
  next_event = ClockDivider;
212
258
 
214
260
  if(dsr_pulse_delay[i] > 0 && next_event > dsr_pulse_delay[i])
215
261
   next_event = dsr_pulse_delay[i];
216
262
 
217
 
 return(next_event);
 
263
 ret = timestamp + next_event;
 
264
 
 
265
 if(irq10_pulse_ts[0] < ret)
 
266
  ret = irq10_pulse_ts[0];
 
267
 
 
268
 if(irq10_pulse_ts[1] < ret)
 
269
  ret = irq10_pulse_ts[1];
 
270
 
 
271
 return(ret);
218
272
}
219
273
 
220
274
void FrontIO::CheckStartStopPending(pscpu_timestamp_t timestamp, bool skip_event_set)
256
310
  ClockDivider = 0;
257
311
 
258
312
 if(!(skip_event_set))
259
 
  PSX_SetEventNT(PSX_EVENT_FIO, timestamp + CalcNextEvent(0x10000000));
 
313
  PSX_SetEventNT(PSX_EVENT_FIO, CalcNextEventTS(timestamp, 0x10000000));
260
314
}
261
315
 
262
316
// DSR IRQ bit setting appears(from indirect tests on real PS1) to be level-sensitive, not edge-sensitive
295
349
        if(ClockDivider > 0 && ((V & 0x2000) != (Control & 0x2000)) && ((Control & 0x2) == (V & 0x2))  )
296
350
         fprintf(stderr, "FIO device selection changed during comm %04x->%04x", Control, V);
297
351
 
 
352
        //printf("Control: %d, %04x\n", timestamp, V);
298
353
        Control = V & 0x3F2F;
299
354
 
300
355
        if(V & 0x10)
439
494
   }
440
495
  }
441
496
 
 
497
 for(int i = 0; i < 2; i++)
 
498
 {
 
499
  if(timestamp >= irq10_pulse_ts[i])
 
500
  {
 
501
   //printf("Yay: %d %u\n", i, timestamp);
 
502
   irq10_pulse_ts[i] = PSX_EVENT_MAXTS;
 
503
   IRQ_Assert(IRQ_PIO, true);
 
504
   IRQ_Assert(IRQ_PIO, false);
 
505
  }
 
506
 }
442
507
 
443
508
 if(ClockDivider > 0)
444
509
 {
510
575
  CheckStartStopPending(timestamp, true);
511
576
 }
512
577
 
513
 
 return(timestamp + CalcNextEvent(0x10000000));
 
578
 return(CalcNextEventTS(timestamp, 0x10000000));
514
579
}
515
580
 
516
581
void FrontIO::ResetTS(void)
530
595
  DevicesTap[i]->ResetTS();
531
596
 }
532
597
 
 
598
 for(int i = 0; i < 2; i++)
 
599
 {
 
600
  if(irq10_pulse_ts[i] != PSX_EVENT_MAXTS)
 
601
   irq10_pulse_ts[i] -= lastts;
 
602
 }
 
603
 
533
604
 for(int i = 0; i < 4; i++)
534
605
 {
535
606
  if(dsr_active_until_ts[i] >= 0)
550
621
  dsr_active_until_ts[i] = -1;
551
622
 }
552
623
 
 
624
 for(int i = 0; i < 2; i++)
 
625
 {
 
626
  irq10_pulse_ts[i] = PSX_EVENT_MAXTS;
 
627
 }
 
628
 
553
629
 lastts = 0;
554
630
 
555
631
 //
595
671
 delete Devices[port];
596
672
 Devices[port] = NULL;
597
673
 
598
 
 if(!strcmp(type, "gamepad"))
 
674
 if(port < 2)
 
675
  irq10_pulse_ts[port] = PSX_EVENT_MAXTS;
 
676
 
 
677
 if(!strcmp(type, "gamepad") || !strcmp(type, "dancepad"))
599
678
  Devices[port] = Device_Gamepad_Create();
600
679
 else if(!strcmp(type, "dualanalog"))
601
680
  Devices[port] = Device_DualAnalog_Create(false);
602
681
 else if(!strcmp(type, "analogjoy"))
603
682
  Devices[port] = Device_DualAnalog_Create(true);
 
683
 else if(!strcmp(type, "dualshock"))
 
684
 {
 
685
  char name[256];
 
686
  trio_snprintf(name, 256, _("DualShock on port %u"), port + 1);
 
687
  Devices[port] = Device_DualShock_Create(std::string(name));
 
688
 }
604
689
 else if(!strcmp(type, "mouse"))
605
690
  Devices[port] = Device_Mouse_Create();
 
691
 else if(!strcmp(type, "negcon"))
 
692
  Devices[port] = Device_neGcon_Create();
 
693
 else if(!strcmp(type, "guncon"))
 
694
  Devices[port] = Device_GunCon_Create();
 
695
 else if(!strcmp(type, "justifier"))
 
696
  Devices[port] = Device_Justifier_Create();
606
697
 else
607
698
  Devices[port] = new InputDevice();
608
699
 
 
700
 Devices[port]->SetAMCT(amct_enabled);
 
701
 Devices[port]->SetCrosshairsColor(chair_colors[port]);
609
702
 DeviceData[port] = ptr;
610
703
 
611
704
 MapDevicesToPorts();
667
760
 }
668
761
}
669
762
 
670
 
 
 
763
bool FrontIO::RequireNoFrameskip(void)
 
764
{
 
765
 for(unsigned i = 0; i < 8; i++)
 
766
  if(Devices[i]->RequireNoFrameskip())
 
767
   return(true);
 
768
 
 
769
 return(false);
 
770
}
 
771
 
 
772
void FrontIO::GPULineHook(const pscpu_timestamp_t timestamp, const pscpu_timestamp_t line_timestamp, bool vsync, uint32 *pixels, const MDFN_PixelFormat* const format, const unsigned width, const unsigned pix_clock_offset, const unsigned pix_clock)
 
773
{
 
774
 Update(timestamp);
 
775
 
 
776
 for(unsigned i = 0; i < 8; i++)
 
777
 {
 
778
  pscpu_timestamp_t plts = Devices[i]->GPULineHook(line_timestamp, vsync, pixels, format, width, pix_clock_offset, pix_clock);
 
779
 
 
780
  if(i < 2)
 
781
  {
 
782
   irq10_pulse_ts[i] = plts;
 
783
 
 
784
   if(irq10_pulse_ts[i] <= timestamp)
 
785
   {
 
786
    irq10_pulse_ts[i] = PSX_EVENT_MAXTS;
 
787
    IRQ_Assert(IRQ_PIO, true);
 
788
    IRQ_Assert(IRQ_PIO, false);
 
789
   }
 
790
  }
 
791
 }
 
792
 
 
793
 PSX_SetEventNT(PSX_EVENT_FIO, CalcNextEventTS(timestamp, 0x10000000));
 
794
}
671
795
 
672
796
static InputDeviceInfoStruct InputDeviceInfoPSXPort[] =
673
797
{
676
800
  "none",
677
801
  "none",
678
802
  NULL,
 
803
  NULL,
679
804
  0,
680
805
  NULL 
681
806
 },
684
809
 {
685
810
  "gamepad",
686
811
  "Digital Gamepad",
 
812
  "PlayStation digital gamepad; SCPH-1080.",
687
813
  NULL,
688
814
  sizeof(Device_Gamepad_IDII) / sizeof(InputDeviceInputInfoStruct),
689
815
  Device_Gamepad_IDII,
690
816
 },
691
817
 
 
818
 // Dual Shock Gamepad(SCPH-1200)
 
819
 {
 
820
  "dualshock",
 
821
  "DualShock",
 
822
  "DualShock gamepad; SCPH-1200.  Emulation in Mednafen includes the analog mode toggle button.",
 
823
  NULL,
 
824
  sizeof(Device_DualShock_IDII) / sizeof(InputDeviceInputInfoStruct),
 
825
  Device_DualShock_IDII,
 
826
 },
 
827
 
692
828
 // Dual Analog Gamepad(SCPH-1180), forced to analog mode.
693
829
 {
694
830
  "dualanalog",
695
831
  "Dual Analog",
 
832
  "Dual Analog gamepad; SCPH-1180.  It is the predecessor/prototype to the more advanced DualShock.  Emulated in Mednafen as forced to analog mode, and without rumble.",
696
833
  NULL,
697
834
  sizeof(Device_DualAnalog_IDII) / sizeof(InputDeviceInputInfoStruct),
698
835
  Device_DualAnalog_IDII,
703
840
 {
704
841
  "analogjoy",
705
842
  "Analog Joystick",
 
843
  "Flight-game-oriented dual-joystick controller; SCPH-1110.   Emulated in Mednafen as forced to analog mode.",
706
844
  NULL,
707
845
  sizeof(Device_AnalogJoy_IDII) / sizeof(InputDeviceInputInfoStruct),
708
846
  Device_AnalogJoy_IDII,
712
850
  "mouse",
713
851
  "Mouse",
714
852
  NULL,
 
853
  NULL,
715
854
  sizeof(Device_Mouse_IDII) / sizeof(InputDeviceInputInfoStruct),
716
855
  Device_Mouse_IDII,
717
856
 },
718
857
 
 
858
 {
 
859
  "negcon",
 
860
  "neGcon",
 
861
  "Namco's unconventional twisty racing-game-oriented gamepad; NPC-101.",
 
862
  NULL,
 
863
  sizeof(Device_neGcon_IDII) / sizeof(InputDeviceInputInfoStruct),
 
864
  Device_neGcon_IDII,
 
865
 },
 
866
 
 
867
 {
 
868
  "guncon",
 
869
  "GunCon",
 
870
  "Namco's light gun; NPC-103.",
 
871
  NULL,
 
872
  sizeof(Device_GunCon_IDII) / sizeof(InputDeviceInputInfoStruct),
 
873
  Device_GunCon_IDII,
 
874
 },
 
875
 
 
876
 {
 
877
  "justifier",
 
878
  "Konami Justifier",
 
879
  "Konami's light gun; SLUH-00017.  Rumored to be wrought of the coagulated rage of all who tried to shoot The Dog.  If the game you want to play supports the \"GunCon\", you should use that instead. NOTE: Currently does not work properly when on any of ports 1B-1D and 2B-2D.",
 
880
  NULL,
 
881
  sizeof(Device_Justifier_IDII) / sizeof(InputDeviceInputInfoStruct),
 
882
  Device_Justifier_IDII,
 
883
 },
 
884
 
 
885
 {
 
886
  "dancepad",
 
887
  "Dance Pad",
 
888
  "Dingo Dingo Rodeo!",
 
889
  NULL,
 
890
  sizeof(Device_Dancepad_IDII) / sizeof(InputDeviceInputInfoStruct),
 
891
  Device_Dancepad_IDII,
 
892
 },
 
893
 
719
894
};
720
895
 
721
896
static const InputPortInfoStruct PortInfo[] =
722
897
{
723
 
 { 0, "port1", "Port 1/1A", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
724
 
 { 0, "port2", "Port 2/2A", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
725
 
 { 0, "port3", "Port 1B", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
726
 
 { 0, "port4", "Port 1C", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
727
 
 { 0, "port5", "Port 1D", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
728
 
 { 0, "port6", "Port 2B", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
729
 
 { 0, "port7", "Port 2C", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
730
 
 { 0, "port8", "Port 2D", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
 
898
 { "port1", "Port 1/1A", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
 
899
 { "port2", "Port 2/2A", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
 
900
 { "port3", "Port 1B", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
 
901
 { "port4", "Port 1C", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
 
902
 { "port5", "Port 1D", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
 
903
 { "port6", "Port 2B", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
 
904
 { "port7", "Port 2C", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
 
905
 { "port8", "Port 2D", sizeof(InputDeviceInfoPSXPort) / sizeof(InputDeviceInfoStruct), InputDeviceInfoPSXPort, "gamepad" },
731
906
};
732
907
 
733
908
InputInfoStruct FIO_InputInfo =