forked from snes9xgit/snes9x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controls.cpp
3693 lines (3043 loc) · 84.1 KB
/
controls.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************************************
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
(c) Copyright 1996 - 2002 Gary Henderson ([email protected]),
Jerremy Koot ([email protected])
(c) Copyright 2002 - 2004 Matthew Kendora
(c) Copyright 2002 - 2005 Peter Bortas ([email protected])
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
(c) Copyright 2001 - 2006 John Weidman ([email protected])
(c) Copyright 2002 - 2006 funkyass ([email protected]),
Kris Bleakley ([email protected])
(c) Copyright 2002 - 2010 Brad Jorsch ([email protected]),
Nach ([email protected]),
(c) Copyright 2002 - 2011 zones ([email protected])
(c) Copyright 2006 - 2007 nitsuja
(c) Copyright 2009 - 2011 BearOso,
OV2
BS-X C emulator code
(c) Copyright 2005 - 2006 Dreamer Nom,
zones
C4 x86 assembler and some C emulation code
(c) Copyright 2000 - 2003 _Demo_ ([email protected]),
Nach,
zsKnight ([email protected])
C4 C++ code
(c) Copyright 2003 - 2006 Brad Jorsch,
Nach
DSP-1 emulator code
(c) Copyright 1998 - 2006 _Demo_,
Andreas Naive ([email protected]),
Gary Henderson,
Ivar ([email protected]),
John Weidman,
Kris Bleakley,
Matthew Kendora,
Nach,
neviksti ([email protected])
DSP-2 emulator code
(c) Copyright 2003 John Weidman,
Kris Bleakley,
Lord Nightmare ([email protected]),
Matthew Kendora,
neviksti
DSP-3 emulator code
(c) Copyright 2003 - 2006 John Weidman,
Kris Bleakley,
Lancer,
z80 gaiden
DSP-4 emulator code
(c) Copyright 2004 - 2006 Dreamer Nom,
John Weidman,
Kris Bleakley,
Nach,
z80 gaiden
OBC1 emulator code
(c) Copyright 2001 - 2004 zsKnight,
pagefault ([email protected]),
Kris Bleakley
Ported from x86 assembler to C by sanmaiwashi
SPC7110 and RTC C++ emulator code used in 1.39-1.51
(c) Copyright 2002 Matthew Kendora with research by
zsKnight,
John Weidman,
Dark Force
SPC7110 and RTC C++ emulator code used in 1.52+
(c) Copyright 2009 byuu,
neviksti
S-DD1 C emulator code
(c) Copyright 2003 Brad Jorsch with research by
Andreas Naive,
John Weidman
S-RTC C emulator code
(c) Copyright 2001 - 2006 byuu,
John Weidman
ST010 C++ emulator code
(c) Copyright 2003 Feather,
John Weidman,
Kris Bleakley,
Matthew Kendora
Super FX x86 assembler emulator code
(c) Copyright 1998 - 2003 _Demo_,
pagefault,
zsKnight
Super FX C emulator code
(c) Copyright 1997 - 1999 Ivar,
Gary Henderson,
John Weidman
Sound emulator code used in 1.5-1.51
(c) Copyright 1998 - 2003 Brad Martin
(c) Copyright 1998 - 2006 Charles Bilyue'
Sound emulator code used in 1.52+
(c) Copyright 2004 - 2007 Shay Green ([email protected])
SH assembler code partly based on x86 assembler code
(c) Copyright 2002 - 2004 Marcus Comstedt ([email protected])
2xSaI filter
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
HQ2x, HQ3x, HQ4x filters
(c) Copyright 2003 Maxim Stepin ([email protected])
NTSC filter
(c) Copyright 2006 - 2007 Shay Green
GTK+ GUI code
(c) Copyright 2004 - 2011 BearOso
Win32 GUI code
(c) Copyright 2003 - 2006 blip,
funkyass,
Matthew Kendora,
Nach,
nitsuja
(c) Copyright 2009 - 2011 OV2
Mac OS GUI code
(c) Copyright 1998 - 2001 John Stiles
(c) Copyright 2001 - 2011 zones
Specific ports contains the works of other authors. See headers in
individual files.
Snes9x homepage: http://www.snes9x.com/
Permission to use, copy, modify and/or distribute Snes9x in both binary
and source form, for non-commercial purposes, is hereby granted without
fee, providing that this license information and copyright notice appear
with all copies and any derived work.
This software is provided 'as-is', without any express or implied
warranty. In no event shall the authors be held liable for any damages
arising from the use of this software or it's derivatives.
Snes9x is freeware for PERSONAL USE only. Commercial users should
seek permission of the copyright holders first. Commercial use includes,
but is not limited to, charging money for Snes9x or software derived from
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
using Snes9x as a promotion for your commercial product.
The copyright holders request that bug fixes and improvements to the code
should be forwarded to them so everyone can benefit from the modifications
in future versions.
Super NES and Super Nintendo Entertainment System are trademarks of
Nintendo Co., Limited and its subsidiary companies.
***********************************************************************************/
#include <map>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <ctype.h>
#include "snes9x.h"
#include "memmap.h"
#include "apu/apu.h"
#include "snapshot.h"
#include "controls.h"
#include "crosshairs.h"
#include "movie.h"
#include "display.h"
#ifdef NETPLAY_SUPPORT
#include "netplay.h"
#endif
using namespace std;
#define NONE (-2)
#define MP5 (-1)
#define JOYPAD0 0
#define JOYPAD1 1
#define JOYPAD2 2
#define JOYPAD3 3
#define JOYPAD4 4
#define JOYPAD5 5
#define JOYPAD6 6
#define JOYPAD7 7
#define MOUSE0 8
#define MOUSE1 9
#define SUPERSCOPE 10
#define ONE_JUSTIFIER 11
#define TWO_JUSTIFIERS 12
#define NUMCTLS 13 // This must be LAST
#define POLL_ALL NUMCTLS
#define SUPERSCOPE_FIRE 0x80
#define SUPERSCOPE_CURSOR 0x40
#define SUPERSCOPE_TURBO 0x20
#define SUPERSCOPE_PAUSE 0x10
#define SUPERSCOPE_OFFSCREEN 0x02
#define JUSTIFIER_TRIGGER 0x80
#define JUSTIFIER_START 0x20
#define JUSTIFIER_SELECT 0x08
#define MAP_UNKNOWN (-1)
#define MAP_NONE 0
#define MAP_BUTTON 1
#define MAP_AXIS 2
#define MAP_POINTER 3
#define FLAG_IOBIT0 (Memory.FillRAM[0x4213] & 0x40)
#define FLAG_IOBIT1 (Memory.FillRAM[0x4213] & 0x80)
#define FLAG_IOBIT(n) ((n) ? (FLAG_IOBIT1) : (FLAG_IOBIT0))
bool8 pad_read = 0, pad_read_last = 0;
uint8 read_idx[2 /* ports */][2 /* per port */];
struct exemulti
{
int32 pos;
bool8 data1;
s9xcommand_t *script;
};
struct crosshair
{
uint8 set;
uint8 img;
uint8 fg, bg;
};
static struct
{
int16 x, y;
int16 V_adj;
bool8 V_var;
int16 H_adj;
bool8 H_var;
bool8 mapped;
} pseudopointer[8];
static struct
{
uint16 buttons;
uint16 turbos;
uint16 toggleturbo;
uint16 togglestick;
uint8 turbo_ct;
} joypad[8];
static struct
{
uint8 delta_x, delta_y;
int16 old_x, old_y;
int16 cur_x, cur_y;
uint8 buttons;
uint32 ID;
struct crosshair crosshair;
} mouse[2];
static struct
{
int16 x, y;
uint8 phys_buttons;
uint8 next_buttons;
uint8 read_buttons;
uint32 ID;
struct crosshair crosshair;
} superscope;
static struct
{
int16 x[2], y[2];
uint8 buttons;
bool8 offscreen[2];
uint32 ID[2];
struct crosshair crosshair[2];
} justifier;
static struct
{
int8 pads[4];
} mp5[2];
static set<struct exemulti *> exemultis;
static set<uint32> pollmap[NUMCTLS + 1];
static map<uint32, s9xcommand_t> keymap;
static vector<s9xcommand_t *> multis;
static uint8 turbo_time;
static uint8 pseudobuttons[256];
static bool8 FLAG_LATCH = FALSE;
static int32 curcontrollers[2] = { NONE, NONE };
static int32 newcontrollers[2] = { JOYPAD0, NONE };
static char buf[256];
static const char *color_names[32] =
{
"Trans",
"Black",
"25Grey",
"50Grey",
"75Grey",
"White",
"Red",
"Orange",
"Yellow",
"Green",
"Cyan",
"Sky",
"Blue",
"Violet",
"MagicPink",
"Purple",
NULL,
"tBlack",
"t25Grey",
"t50Grey",
"t75Grey",
"tWhite",
"tRed",
"tOrange",
"tYellow",
"tGreen",
"tCyan",
"tSky",
"tBlue",
"tViolet",
"tMagicPink",
"tPurple"
};
static const char *speed_names[4] =
{
"Var",
"Slow",
"Med",
"Fast"
};
static const int ptrspeeds[4] = { 1, 1, 4, 8 };
// Note: these should be in asciibetical order!
#define THE_COMMANDS \
S(BeginRecordingMovie), \
S(ClipWindows), \
S(Debugger), \
S(DecEmuTurbo), \
S(DecFrameRate), \
S(DecFrameTime), \
S(DecTurboSpeed), \
S(EmuTurbo), \
S(EndRecordingMovie), \
S(ExitEmu), \
S(IncEmuTurbo), \
S(IncFrameRate), \
S(IncFrameTime), \
S(IncTurboSpeed), \
S(LoadFreezeFile), \
S(LoadMovie), \
S(LoadOopsFile), \
S(Pause), \
S(QuickLoad000), \
S(QuickLoad001), \
S(QuickLoad002), \
S(QuickLoad003), \
S(QuickLoad004), \
S(QuickLoad005), \
S(QuickLoad006), \
S(QuickLoad007), \
S(QuickLoad008), \
S(QuickLoad009), \
S(QuickLoad010), \
S(QuickSave000), \
S(QuickSave001), \
S(QuickSave002), \
S(QuickSave003), \
S(QuickSave004), \
S(QuickSave005), \
S(QuickSave006), \
S(QuickSave007), \
S(QuickSave008), \
S(QuickSave009), \
S(QuickSave010), \
S(Reset), \
S(SaveFreezeFile), \
S(SaveSPC), \
S(Screenshot), \
S(SeekToFrame), \
S(SoftReset), \
S(SoundChannel0), \
S(SoundChannel1), \
S(SoundChannel2), \
S(SoundChannel3), \
S(SoundChannel4), \
S(SoundChannel5), \
S(SoundChannel6), \
S(SoundChannel7), \
S(SoundChannelsOn), \
S(SwapJoypads), \
S(ToggleBG0), \
S(ToggleBG1), \
S(ToggleBG2), \
S(ToggleBG3), \
S(ToggleEmuTurbo), \
S(ToggleSprites), \
S(ToggleTransparency) \
#define S(x) x
enum command_numbers
{
THE_COMMANDS,
LAST_COMMAND
};
#undef S
#define S(x) #x
static const char *command_names[LAST_COMMAND + 1] =
{
THE_COMMANDS,
NULL
};
#undef S
#undef THE_COMMANDS
static void DisplayStateChange (const char *, bool8);
static void DoGunLatch (int, int);
static int maptype (int);
static bool strless (const char *, const char *);
static int findstr (const char *, const char **, int);
static int get_threshold (const char **);
static const char * maptypename (int);
static int32 ApplyMulti (s9xcommand_t *, int32, int16);
static void do_polling (int);
static void UpdatePolledMouse (int);
static string& operator += (string &s, int i)
{
snprintf(buf, sizeof(buf), "%d", i);
s.append(buf);
return (s);
}
static string& operator += (string &s, double d)
{
snprintf(buf, sizeof(buf), "%g", d);
s.append(buf);
return (s);
}
static void DisplayStateChange (const char *str, bool8 on)
{
snprintf(buf, sizeof(buf), "%s: %s", str, on ? "on":"off");
S9xSetInfoString(buf);
}
static void DoGunLatch (int x, int y)
{
x += 40;
if (x > 295)
x = 295;
else
if (x < 40)
x = 40;
if (y > PPU.ScreenHeight - 1)
y = PPU.ScreenHeight - 1;
else
if (y < 0)
y = 0;
PPU.GunVLatch = (uint16) (y + 1);
PPU.GunHLatch = (uint16) x;
}
static int maptype (int t)
{
switch (t)
{
case S9xNoMapping:
return (MAP_NONE);
case S9xButtonJoypad:
case S9xButtonMouse:
case S9xButtonSuperscope:
case S9xButtonJustifier:
case S9xButtonCommand:
case S9xButtonPseudopointer:
case S9xButtonPort:
case S9xButtonMulti:
return (MAP_BUTTON);
case S9xAxisJoypad:
case S9xAxisPseudopointer:
case S9xAxisPseudobuttons:
case S9xAxisPort:
return (MAP_AXIS);
case S9xPointer:
case S9xPointerPort:
return (MAP_POINTER);
default:
return (MAP_UNKNOWN);
}
}
void S9xControlsReset (void)
{
S9xControlsSoftReset();
mouse[0].buttons &= ~0x30;
mouse[1].buttons &= ~0x30;
justifier.buttons &= ~JUSTIFIER_SELECT;
}
void S9xControlsSoftReset (void)
{
for (set<struct exemulti *>::iterator it = exemultis.begin(); it != exemultis.end(); it++)
delete *it;
exemultis.clear();
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
read_idx[i][j]=0;
FLAG_LATCH = FALSE;
}
void S9xUnmapAllControls (void)
{
S9xControlsReset();
keymap.clear();
for (int i = 0; i < (int) multis.size(); i++)
free(multis[i]);
multis.clear();
for (int i = 0; i < NUMCTLS + 1; i++)
pollmap[i].clear();
for (int i = 0; i < 8; i++)
{
pseudopointer[i].x = 0;
pseudopointer[i].y = 0;
pseudopointer[i].H_adj = 0;
pseudopointer[i].V_adj = 0;
pseudopointer[i].H_var = 0;
pseudopointer[i].V_var = 0;
pseudopointer[i].mapped = false;
joypad[i].buttons = 0;
joypad[i].turbos = 0;
joypad[i].turbo_ct = 0;
}
for (int i = 0; i < 2; i++)
{
mouse[i].old_x = mouse[i].old_y = 0;
mouse[i].cur_x = mouse[i].cur_y = 0;
mouse[i].buttons = 1;
mouse[i].ID = InvalidControlID;
if (!(mouse[i].crosshair.set & 1))
mouse[i].crosshair.img = 0; // no image for mouse because its only logical position is game-specific, not known by the emulator
if (!(mouse[i].crosshair.set & 2))
mouse[i].crosshair.fg = 5;
if (!(mouse[i].crosshair.set & 4))
mouse[i].crosshair.bg = 1;
justifier.x[i] = justifier.y[i] = 0;
justifier.offscreen[i] = 0;
justifier.ID[i] = InvalidControlID;
if (!(justifier.crosshair[i].set & 1))
justifier.crosshair[i].img = 4;
if (!(justifier.crosshair[i].set & 2))
justifier.crosshair[i].fg = i ? 14 : 12;
if (!(justifier.crosshair[i].set & 4))
justifier.crosshair[i].bg = 1;
}
justifier.buttons = 0;
superscope.x = superscope.y = 0;
superscope.phys_buttons = 0;
superscope.next_buttons = 0;
superscope.read_buttons = 0;
superscope.ID = InvalidControlID;
if (!(superscope.crosshair.set & 1))
superscope.crosshair.img = 2;
if (!(superscope.crosshair.set & 2))
superscope.crosshair.fg = 5;
if (!(superscope.crosshair.set & 4))
superscope.crosshair.bg = 1;
memset(pseudobuttons, 0, sizeof(pseudobuttons));
turbo_time = 1;
}
void S9xSetController (int port, enum controllers controller, int8 id1, int8 id2, int8 id3, int8 id4)
{
if (port < 0 || port > 1)
return;
switch (controller)
{
case CTL_NONE:
break;
case CTL_JOYPAD:
if (id1 < 0 || id1 > 7)
break;
newcontrollers[port] = JOYPAD0 + id1;
return;
case CTL_MOUSE:
if (id1 < 0 || id1 > 1)
break;
if (!Settings.MouseMaster)
{
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, "Cannot select SNES Mouse: MouseMaster disabled");
break;
}
newcontrollers[port] = MOUSE0 + id1;
return;
case CTL_SUPERSCOPE:
if (!Settings.SuperScopeMaster)
{
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, "Cannot select SNES Superscope: SuperScopeMaster disabled");
break;
}
newcontrollers[port] = SUPERSCOPE;
return;
case CTL_JUSTIFIER:
if (id1 < 0 || id1 > 1)
break;
if (!Settings.JustifierMaster)
{
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, "Cannot select Konami Justifier: JustifierMaster disabled");
break;
}
newcontrollers[port] = ONE_JUSTIFIER + id1;
return;
case CTL_MP5:
if (id1 < -1 || id1 > 7)
break;
if (id2 < -1 || id2 > 7)
break;
if (id3 < -1 || id3 > 7)
break;
if (id4 < -1 || id4 > 7)
break;
if (!Settings.MultiPlayer5Master)
{
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, "Cannot select MP5: MultiPlayer5Master disabled");
break;
}
newcontrollers[port] = MP5;
mp5[port].pads[0] = (id1 < 0) ? NONE : JOYPAD0 + id1;
mp5[port].pads[1] = (id2 < 0) ? NONE : JOYPAD0 + id2;
mp5[port].pads[2] = (id3 < 0) ? NONE : JOYPAD0 + id3;
mp5[port].pads[3] = (id4 < 0) ? NONE : JOYPAD0 + id4;
return;
default:
fprintf(stderr, "Unknown controller type %d\n", controller);
break;
}
newcontrollers[port] = NONE;
}
bool S9xVerifyControllers (void)
{
bool ret = false;
int port, i, used[NUMCTLS];
for (i = 0; i < NUMCTLS; used[i++] = 0) ;
for (port = 0; port < 2; port++)
{
switch (i = newcontrollers[port])
{
case MOUSE0:
case MOUSE1:
if (!Settings.MouseMaster)
{
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, "Cannot select SNES Mouse: MouseMaster disabled");
newcontrollers[port] = NONE;
ret = true;
break;
}
if (used[i]++ > 0)
{
snprintf(buf, sizeof(buf), "Mouse%d used more than once! Disabling extra instances", i - MOUSE0 + 1);
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, buf);
newcontrollers[port] = NONE;
ret = true;
break;
}
break;
case SUPERSCOPE:
if (!Settings.SuperScopeMaster)
{
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, "Cannot select SNES Superscope: SuperScopeMaster disabled");
newcontrollers[port] = NONE;
ret = true;
break;
}
if (used[i]++ > 0)
{
snprintf(buf, sizeof(buf), "Superscope used more than once! Disabling extra instances");
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, buf);
newcontrollers[port] = NONE;
ret = true;
break;
}
break;
case ONE_JUSTIFIER:
case TWO_JUSTIFIERS:
if (!Settings.JustifierMaster)
{
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, "Cannot select Konami Justifier: JustifierMaster disabled");
newcontrollers[port] = NONE;
ret = true;
break;
}
if (used[ONE_JUSTIFIER]++ > 0)
{
snprintf(buf, sizeof(buf), "Justifier used more than once! Disabling extra instances");
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, buf);
newcontrollers[port] = NONE;
ret = true;
break;
}
break;
case MP5:
if (!Settings.MultiPlayer5Master)
{
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, "Cannot select MP5: MultiPlayer5Master disabled");
newcontrollers[port] = NONE;
ret = true;
break;
}
for (i = 0; i < 4; i++)
{
if (mp5[port].pads[i] != NONE)
{
if (used[mp5[port].pads[i] - JOYPAD0]++ > 0)
{
snprintf(buf, sizeof(buf), "Joypad%d used more than once! Disabling extra instances", mp5[port].pads[i] - JOYPAD0 + 1);
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, buf);
mp5[port].pads[i] = NONE;
ret = true;
break;
}
}
}
break;
case JOYPAD0:
case JOYPAD1:
case JOYPAD2:
case JOYPAD3:
case JOYPAD4:
case JOYPAD5:
case JOYPAD6:
case JOYPAD7:
if (used[i - JOYPAD0]++ > 0)
{
snprintf(buf, sizeof(buf), "Joypad%d used more than once! Disabling extra instances", i - JOYPAD0 + 1);
S9xMessage(S9X_CONFIG_INFO, S9X_ERROR, buf);
newcontrollers[port] = NONE;
ret = true;
break;
}
break;
default:
break;
}
}
return (ret);
}
void S9xGetController (int port, enum controllers *controller, int8 *id1, int8 *id2, int8 *id3, int8 *id4)
{
int i;
*controller = CTL_NONE;
*id1 = *id2 = *id3 = *id4 = -1;
if (port < 0 || port > 1)
return;
switch (i = newcontrollers[port])
{
case MP5:
*controller = CTL_MP5;
*id1 = (mp5[port].pads[0] == NONE) ? -1 : mp5[port].pads[0] - JOYPAD0;
*id2 = (mp5[port].pads[1] == NONE) ? -1 : mp5[port].pads[1] - JOYPAD0;
*id3 = (mp5[port].pads[2] == NONE) ? -1 : mp5[port].pads[2] - JOYPAD0;
*id4 = (mp5[port].pads[3] == NONE) ? -1 : mp5[port].pads[3] - JOYPAD0;
return;
case JOYPAD0:
case JOYPAD1:
case JOYPAD2:
case JOYPAD3:
case JOYPAD4:
case JOYPAD5:
case JOYPAD6:
case JOYPAD7:
*controller = CTL_JOYPAD;
*id1 = i - JOYPAD0;
return;
case MOUSE0:
case MOUSE1:
*controller = CTL_MOUSE;
*id1 = i - MOUSE0;
return;
case SUPERSCOPE:
*controller = CTL_SUPERSCOPE;
*id1 = 1;
return;
case ONE_JUSTIFIER:
case TWO_JUSTIFIERS:
*controller = CTL_JUSTIFIER;
*id1 = i - ONE_JUSTIFIER;
return;
}
}
void S9xReportControllers (void)
{
static char mes[128];
char *c = mes;
S9xVerifyControllers();
for (int port = 0; port < 2; port++)
{
c += sprintf(c, "Port %d: ", port + 1);
switch (newcontrollers[port])
{
case NONE:
c += sprintf(c, "<none>. ");
break;
case MP5:
c += sprintf(c, "MP5 with pads");
for (int i = 0; i < 4; i++)
{
if (mp5[port].pads[i] == NONE)
c += sprintf(c, " <none>. ");
else
c += sprintf(c, " #%d. ", mp5[port].pads[i] + 1 - JOYPAD0);
}
break;
case JOYPAD0:
case JOYPAD1:
case JOYPAD2:
case JOYPAD3:
case JOYPAD4:
case JOYPAD5:
case JOYPAD6:
case JOYPAD7:
c += sprintf(c, "Pad #%d. ", (int) (newcontrollers[port] - JOYPAD0 + 1));
break;
case MOUSE0:
case MOUSE1:
c += sprintf(c, "Mouse #%d. ", (int) (newcontrollers[port] - MOUSE0 + 1));
break;
case SUPERSCOPE:
if (port == 0)
c += sprintf(c, "Superscope (cannot fire). ");
else
c += sprintf(c, "Superscope. ");
break;
case ONE_JUSTIFIER:
if (port == 0)
c += sprintf(c, "Blue Justifier (cannot fire). ");
else
c += sprintf(c, "Blue Justifier. ");
break;
case TWO_JUSTIFIERS:
if (port == 0)
c += sprintf(c, "Blue and Pink Justifiers (cannot fire). ");
else
c += sprintf(c, "Blue and Pink Justifiers. ");
break;
}
}
S9xMessage(S9X_INFO, S9X_CONFIG_INFO, mes);
}
char * S9xGetCommandName (s9xcommand_t command)
{
string s;
char c;
switch (command.type)
{
case S9xButtonJoypad:
if (command.button.joypad.buttons == 0)
return (strdup("None"));
if (command.button.joypad.buttons & 0x000f)
return (strdup("None"));
s = "Joypad";
s += command.button.joypad.idx + 1;
c = ' ';
if (command.button.joypad.toggle) { if (c) s += c; s += "Toggle"; c = 0; }
if (command.button.joypad.sticky) { if (c) s += c; s += "Sticky"; c = 0; }
if (command.button.joypad.turbo ) { if (c) s += c; s += "Turbo"; c = 0; }
c = ' ';
if (command.button.joypad.buttons & SNES_UP_MASK ) { s += c; s += "Up"; c = '+'; }
if (command.button.joypad.buttons & SNES_DOWN_MASK ) { s += c; s += "Down"; c = '+'; }
if (command.button.joypad.buttons & SNES_LEFT_MASK ) { s += c; s += "Left"; c = '+'; }
if (command.button.joypad.buttons & SNES_RIGHT_MASK ) { s += c; s += "Right"; c = '+'; }
if (command.button.joypad.buttons & SNES_A_MASK ) { s += c; s += "A"; c = '+'; }
if (command.button.joypad.buttons & SNES_B_MASK ) { s += c; s += "B"; c = '+'; }
if (command.button.joypad.buttons & SNES_X_MASK ) { s += c; s += "X"; c = '+'; }
if (command.button.joypad.buttons & SNES_Y_MASK ) { s += c; s += "Y"; c = '+'; }
if (command.button.joypad.buttons & SNES_TL_MASK ) { s += c; s += "L"; c = '+'; }
if (command.button.joypad.buttons & SNES_TR_MASK ) { s += c; s += "R"; c = '+'; }
if (command.button.joypad.buttons & SNES_START_MASK ) { s += c; s += "Start"; c = '+'; }
if (command.button.joypad.buttons & SNES_SELECT_MASK) { s += c; s += "Select"; c = '+'; }
break;
case S9xButtonMouse:
if (!command.button.mouse.left && !command.button.mouse.right)
return (strdup("None"));