-
Notifications
You must be signed in to change notification settings - Fork 10
/
USBcontrol.ino
1224 lines (1205 loc) · 69 KB
/
USBcontrol.ino
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
// USB interface for APC based pinball machines
const byte USB_CommandLength[110] = {0,0,0,0,0,0,0,1,0,0, // Length of USB commands from 0 - 9
1,1,1,0,0,0,0,0,0,0, // Length of USB commands from 10 - 19
1,1,1,1,2,2,0,0,0,0, // Length of USB commands from 20 - 29
250,250,250,250,250,0,0,2,0,0, // Length of USB commands from 30 - 39
1,0,0,0,0,0,0,0,0,0, // Length of USB commands from 40 - 49
2,1,251,0,2,0,0,0,0,0, // Length of USB commands from 50 - 59
10,0,0,0,2,3,0,0,0,0, // Length of USB commands from 60 - 69
0,0,0,0,0,0,0,0,0,0, // Length of USB commands from 70 - 79
2,1,2,0,0,0,0,0,0,0, // Length of USB commands from 80 - 89
0,0,0,0,0,0,0,0,0,0, // Length of USB commands from 90 - 99
0,0,0,0,0,0,0,0,0,0}; // Length of USB commands from 100 - 109
const byte USB_DisplayDigitNum[9][6] = {{4,7,7,7,7,0},{4,7,7,7,7,0},{0,7,7,7,7,0},{0,16,16,0,0,0},{0,16,16,0,0,0},{0,16,16,7,0,0},{0,16,16,7,4,0},{4,6,6,6,6,0},{4,7,7,7,7,0}};
const byte USB_DisplayTypes[9][6] = {{3,4,4,4,4,0},{3,4,4,3,3,0},{0,4,4,3,3,0},{0,4,4,0,0,0},{0,4,4,0,0,0},{0,4,3,3,0,0},{0,4,3,3,3,0},{1,1,1,1,1,0},{1,2,2,2,2,0}};
// offsets of settings in the settings array
#define USB_Watchdog 0 // watchdog enable setting
#define USB_Debug 1 // USB debug mode
#define USB_PinMameSound 2 // use APC sound HW or old sound board?
#define USB_PinMameGame 3 // number of the game to be run in PinMame
#define USB_LisyDebug 4 // selected debug mode
const byte USB_defaults[64] = {0,0,0,255,0,0,0,0, // game default settings
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0};
byte USB_ChangedSwitches[64];
byte USB_HWrule_ActSw[16][3]; // hardware rules for activated switches
byte USB_HWrule_RelSw[16][3]; // hardware rules for released switches
byte USB_DisplayProtocol[5]; // stores the selected display protocol
char USB_RepeatMusic[13]; // name of the music file to be repeated
byte USB_WaitingSoundFiles[2][14]; // names of the waiting sound files first byte is for channel and commands
byte USB_WaitSoundTimer; // number of the timer for the sound sequencing
byte USB_Enter_TestmodeTimer; // number of the timer to determine whether the Advance button has been held down
unsigned int USB_SolTimes[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Activation times for solenoids
const char TxTUSB_debug[3][17] = {{" OFF "},{" USB "},{" AUDIO "}};
const char TxTUSB_PinMameSound[2][17] = {{" APC "},{" BOARD "}};
const struct SettingTopic USB_setList[67] = {{"USB WATCHDOG ",HandleBoolSetting,0,0,0}, // defines the game specific settings
{" DEBUG MODE ",HandleTextSetting,&TxTUSB_debug[0][0],0,2},
{"PINMAME SOUND ",HandleTextSetting,&TxTUSB_PinMameSound[0][0],0,1},
{"PINMAME GAME ",HandleNumSetting,0,0,72},
{" LISY DEBUG ",HandleNumSetting,0,1,31},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SETTING UNUSED ",HandleBoolSetting,0,0,0},
{"SYSTEM3 SET 1 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 2 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 3 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 4 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 5 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 6 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 7 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 8 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 9 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 10 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 11 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 12 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 13 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 14 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 15 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 16 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 17 ",HandleNumSetting,0,0,72},
{"SYSTEM3 SET 18 ",HandleNumSetting,0,0,72},
{"RESTOREDEFAULT",RestoreDefaults,0,0,0},
{" EXIT SETTNGS",ExitSettings,0,0,0},
{"",NULL,0,0,0}};
struct GameDef USB_GameDefinition = {
USB_setList, // GameSettingsList
(byte*)USB_defaults, // GameDefaultsPointer
"USB_SET.BIN", // GameSettingsFileName
"USBSCORE.BIN", // HighScoresFileName
USB_AttractMode, // AttractMode
USB_SolTimes}; // Default activation times of solenoids
void USB_init() {
Switch_Pressed = DummyProcess;
GameDefinition = USB_GameDefinition; // read the game specific settings and highscores
if (APC_settings[ConnType]) {
if (APC_settings[ConnType] == 1) {
OnBoardCom = false;}
else {
Serial.begin(115200); // needed for USB and serial communication
return;}}
if (APC_settings[DebugMode]) { // activate serial interface in debug mode
Serial.begin(115200);}}
void USB_AttractMode() { // Attract Mode
DispRow1 = DisplayUpper;
DispRow2 = DisplayLower;
if (APC_settings[Volume]) { // system set to digital volume control?
analogWrite(VolumePin,255-APC_settings[Volume]);} // adjust PWM to volume setting
else {
digitalWrite(VolumePin,HIGH);} // turn off the digital volume control
for (i=0; i<8; i++) { // turn off all lamps
LampColumns[i] = 0;}
LampPattern = LampColumns;
Switch_Pressed = USB_SwitchHandler;
Switch_Released = USB_ReleasedSwitches;
EX_Init(game_settings[USB_PinMameGame]); // set exceptions for selected game
USB_ReleasedSwitches(72); // tell Lisy to start PinMame
for (byte i=0; i<5; i++) {
USB_DisplayProtocol[i] = USB_DisplayTypes[APC_settings[DisplayType]][i];} // use default protocol for displays
if (game_settings[USB_Watchdog]) { // watchdog enabled?
USB_WatchdogHandler(1);} // initiate reset and start watchdog
if (APC_settings[ConnType]) {
if (APC_settings[ConnType] == 1) {
WriteUpper("BOOTING LISY ");}
else {
WriteUpper(" USB CONTROL ");}}
else {
WriteUpper("NO CONNSELECTED ");}
WriteLower(" ");}
void USB_WatchdogHandler(byte Event) { // Arg = 0->Reset WD / 1-> Reset & start WD / 2-> WD has run out / 3-> stop WD
static byte USB_WatchdogTimer;
byte i=0;
if (!Event) { // reset watchdog
USB_WriteByte((byte) 0); // send OK
if (USB_WatchdogTimer) {
KillTimer(USB_WatchdogTimer);} // restart timer
if (game_settings[USB_Watchdog]) { // watchdog enabled?
USB_WatchdogTimer = ActivateTimer(1000, 2, USB_WatchdogHandler);} // start the timer
else { // watchdog disabled?
USB_WatchdogTimer = 0;}} // mark timer as inactive
else {
if (Event == 3) { // stop watchdog
if (USB_WatchdogTimer) {
KillTimer(USB_WatchdogTimer);
USB_WatchdogTimer = 0;}}
else {
if (Event == 1) { // initiate reset and start watchdog
if (USB_WatchdogTimer) {
KillTimer(USB_WatchdogTimer);
USB_WatchdogTimer = 0;}
for (i=0; i<16; i++) { // delete all HW rules
USB_HWrule_ActSw[i][0] = 0;
USB_HWrule_RelSw[i][0] = 0;}
USB_WriteByte((byte) 0);} // send OK
else { // timer has run out
if (!game_settings[USB_Watchdog]) { // watchdog disabled?
USB_WatchdogTimer = 0;
return;} // then leave
WriteUpper2(" USB WATCHDOG ");
WriteLower2(" ");
ShowMessage(3);}
ReleaseAllSolenoids(); // switch off all coils
for (i=0; i<63; i++) { // clear switch buffer
USB_ChangedSwitches[i] = 0;}
for (i=0; i<8; i++) { // turn off all lamps
LampColumns[i] = 0;}
USB_WatchdogTimer = ActivateTimer(1000, 2, USB_WatchdogHandler);}}} // restart watchdog
void USB_SwitchHandler(byte Switch) {
byte i = 0;
if (!PinMameException(SwitchActCommand, Switch)){ // check for machine specific exceptions
switch (Switch) {
case 8: // high score reset
digitalWrite(Blanking, LOW); // invoke the blanking
StopPlayingMusic();
StopPlayingSound();
break;
case 72: // advance button
while (USB_ChangedSwitches[i] && (i<63)) {
i++;}
USB_ChangedSwitches[i] = Switch | 128; // send switch code to USB
if (QuerySwitch(73)) { // Up/Down switch pressed?
USB_Enter_TestmodeTimer = ActivateTimer(1000, 0, USB_Testmode);} // look again in 1s
break;
default:
while (USB_HWrule_ActSw[i][0]) { // check for HW rules for this switch
if (USB_HWrule_ActSw[i][0] == Switch) {
if (USB_HWrule_ActSw[i][2]) { // duration != 0 ?
ActivateSolenoid((byte) USB_HWrule_ActSw[i][2], USB_HWrule_ActSw[i][1]);}
else {
ReleaseSolenoid(USB_HWrule_ActSw[i][1]);}
break;}
i++;}
i = 0; // add switch number to list of changed switches
while (USB_ChangedSwitches[i] && (i<63)) {
i++;}
USB_ChangedSwitches[i] = Switch | 128;}}}
void USB_ReleasedSwitches(byte Switch) {
if (!PinMameException(SwitchRelCommand, Switch)){ // check for machine specific exceptions
switch (Switch) {
case 8: // high score reset
break;
case 72:
if (USB_Enter_TestmodeTimer) {
KillTimer(USB_Enter_TestmodeTimer);
USB_Enter_TestmodeTimer = 0;} // @suppress("No break at end of case")
default:
byte i = 0;
while (USB_HWrule_RelSw[i][0]) { // check for HW rules for this switch
if (USB_HWrule_RelSw[i][0] == Switch) {
if (USB_HWrule_RelSw[i][2]) { // duration != 0 ?
ActivateSolenoid((byte) USB_HWrule_RelSw[i][2], USB_HWrule_RelSw[i][1]);}
else {
ReleaseSolenoid(USB_HWrule_RelSw[i][1]);}
break;}
i++;}
i = 0; // add switch number to list of changed switches
while (USB_ChangedSwitches[i] && (i<63)) {
i++;}
USB_ChangedSwitches[i] = Switch;}}}
void USB_Testmode(byte Dummy) { // enter system settings if advance button still pressed
UNUSED(Dummy);
USB_Enter_TestmodeTimer = 0;
USB_WatchdogHandler(3); // stop USB watchdog
for (byte i=0; i<5; i++) {
USB_DisplayProtocol[i] = 6;} // use ASCII protocol for displays
if (APC_settings[ConnType] == 2) { // USB mode selected?
Serial.end();}
else if ((APC_settings[ConnType] == 1) && OnBoardCom) { // onboard Pi selected and detected?
Serial3.end();}
Settings_Enter();}
byte USB_ReadByte() { // read a byte from the selected interface
if (APC_settings[ConnType] == 1) { // onboard PI selected?
return Serial3.read();}
else { // USB selected
return Serial.read();}}
void USB_WriteByte(byte Data) { // write a byte to the selected interface
if (APC_settings[ConnType] == 1) { // onboard PI selected?
Serial3.write(Data);}
else { // USB selected
Serial.write(Data);}}
byte USB_Available() {
if (APC_settings[ConnType] == 1) { // onboard PI selected?
if (OnBoardCom) { // onboard Pi detected?
return Serial3.available();}
else {
return 0;}}
else { // USB selected
return Serial.available();}}
void USB_SerialCommand() {
static byte Command;
static byte USB_BufferPointer; // pointer for the SerialBuffer
static bool CommandPending;
byte c = 0;
byte i = 0;
if (!CommandPending) { // any unfinished business?
Command = USB_ReadByte();} // if not read new command
if (USB_CommandLength[Command] > 249) { // command doesn't have a constant length
switch (USB_CommandLength[Command]) {
case 250: // argument length is stored in the first byte
if (USB_BufferPointer) { // length byte already stored?
c = USB_SerialBuffer[0];} // read previously stored argument length
else {
if (USB_Available()) { // length byte available?
USB_BufferPointer = 1; // indicated that the length is read
c = USB_ReadByte();} // read argument length
else {
USB_BufferPointer = 0;
CommandPending = true; // command not finished
return;}}
if (USB_Available() >= c) { // enough bytes in the serial buffer?
for (i=0; i<c; i++) { // read the required amount of bytes
USB_SerialBuffer[i] = USB_ReadByte();}}
else { // not enough bytes in the buffer
CommandPending = true; // command not finished
USB_SerialBuffer[0] = c; // store argument length for next round
return;}
break;
case 251:
c = USB_Available();
i = USB_BufferPointer;
if (!USB_BufferPointer) { // first run?
if (c < 3) { // 3 bytes needed at least
CommandPending = true;
return;}
USB_SerialBuffer[0] = USB_ReadByte(); // store track number
i++;
USB_SerialBuffer[1] = USB_ReadByte(); // store options byte
i++;}
do { // receive bytes
USB_SerialBuffer[i] = USB_ReadByte(); // and store them
i++;}
while ((USB_SerialBuffer[i-1]) && ((i - USB_BufferPointer) < c)); // until a 0 is read or serial buffer is empty
if (USB_SerialBuffer[i-1]) { // last byte not zero
CommandPending = true; // command not finished
USB_BufferPointer = i;
return;}
break;
case 255: // argument is terminated by a zero byte
c = USB_Available();
i = USB_BufferPointer;
if (!c) { // no further received bytes
CommandPending = true;
return;}
do { // receive bytes
USB_SerialBuffer[i] = USB_ReadByte(); // and store them
i++;}
while ((USB_SerialBuffer[i-1]) && ((i - USB_BufferPointer) < c)); // until a 0 is read or serial buffer is empty
if (USB_SerialBuffer[i-1]) { // last byte not zero
CommandPending = true; // command not finished
USB_BufferPointer = i;
return;}
break;}}
else { // argument has a specific length
if (USB_Available() >= USB_CommandLength[Command]) { // enough bytes in the serial buffer?
for (i=0; i<USB_CommandLength[Command]; i++) { // read the required amount of bytes
USB_SerialBuffer[i] = USB_ReadByte();}}
else { // not enough bytes in the buffer
CommandPending = true; // command not finished
return;}}
CommandPending = false;
USB_BufferPointer = 0;
if (game_settings[USB_Debug] == 1) {
for (i=1; i<24; i++) { // move all characters in the lower display row 4 chars to the left
DisplayLower[i] = DisplayLower[i+8];}
*(DisplayLower+30) = DispPattern2[32 + 2 * (Command % 10)]; // and insert the command number to the right of the row
*(DisplayLower+31) = DispPattern2[33 + 2 * (Command % 10)];
*(DisplayLower+28) = DispPattern2[32 + 2 * (Command / 10)];
*(DisplayLower+29) = DispPattern2[33 + 2 * (Command / 10)];
*(DisplayLower+26) = DispPattern2[32 + 2 * (Command / 100)];
*(DisplayLower+27) = DispPattern2[33 + 2 * (Command / 100)];}
switch (Command) { // execute command if complete
case 0: // get connected hardware
USB_WriteByte('A');
USB_WriteByte('P');
USB_WriteByte('C');
USB_WriteByte((byte) 0);
break;
case 1: // get firmware version
if (APC_settings[ConnType] == 1) {
Serial3.print(APC_Version);}
else {
Serial.print(APC_Version);}
USB_WriteByte((byte) 0);
break;
case 2: // get API version
USB_WriteByte('0');
USB_WriteByte('.');
USB_WriteByte('1');
USB_WriteByte('0');
USB_WriteByte((byte) 0);
break;
case 3: // get number of lamps
USB_WriteByte((byte) 65);
break;
case 4: // get number of solenoids
USB_WriteByte((byte) 25);
break;
case 6: // get number of displays
switch (APC_settings[DisplayType]) {
case 0: // 4 ALPHA+CREDIT
case 1: // Sys11 Pinbot
case 2: // Sys11 F-14
case 5: // Sys11 Riverboat Gambler
case 7: // Sys3 - 6
case 8: // Sys7 + 9
USB_WriteByte((byte) 5);
break;
case 3: // Sys11 BK2K
case 6: // DE 2x16
USB_WriteByte((byte) 3);
break;
case 4: // Sys11 Taxi
USB_WriteByte((byte) 4);
break;
default: // unknown display type
USB_WriteByte((byte) 0);
break;}
break;
case 7: // Display details
USB_WriteByte((byte) USB_DisplayTypes[APC_settings[DisplayType]][USB_SerialBuffer[0]]);
USB_WriteByte((byte) USB_DisplayDigitNum[APC_settings[DisplayType]][USB_SerialBuffer[0]]);
break;
case 9: // get number of switches
USB_WriteByte((byte) 73);
break;
case 10: // get status of lamp
USB_WriteByte((byte) QueryLamp(USB_SerialBuffer[0]));
break;
case 11: // turn on lamp
if (!PinMameException(LampOnCommand, USB_SerialBuffer[0])){ // check for machine specific exceptions
TurnOnLamp(USB_SerialBuffer[0]);}
break;
case 12: // turn off lamp
if (!PinMameException(LampOffCommand, USB_SerialBuffer[0])){ // check for machine specific exceptions
TurnOffLamp(USB_SerialBuffer[0]);}
break;
case 19: // get number of modern lights
USB_WriteByte((byte) 0);
break;
case 20: // get status of solenoid
if (USB_SerialBuffer[0] < 26) { // max 24 solenoids
USB_WriteByte((byte) QuerySolenoid(USB_SerialBuffer[0]));}
break;
case 21: // set solenoid # to on
if (game_settings[USB_PinMameGame] > 18 || USB_SerialBuffer[0] < 9 || USB_SerialBuffer[0] > 13) { // block solenoid commands for Sys 3 - 6 sound control lines
if (!PinMameException(SolenoidActCommand, USB_SerialBuffer[0])){ // check for machine specific exceptions
if (USB_SerialBuffer[0] < 23) { // max 24 solenoids
if (!SolRecycleTimers[USB_SerialBuffer[0]-1]) { // recycling time over for this coil?
SolChange = false; // block IRQ solenoid handling
if (USB_SerialBuffer[0] > 8) { // does the solenoid not belong to the first latch?
if (USB_SerialBuffer[0] < 17) { // does it belong to the second latch?
SolBuffer[1] |= 1<<(USB_SerialBuffer[0]-9);} // latch counts from 0
else {
SolBuffer[2] |= 1<<(USB_SerialBuffer[0]-17);}}
else {
SolBuffer[0] |= 1<<(USB_SerialBuffer[0]-1);}
SolChange = true;}}
else if (USB_SerialBuffer[0] == 23) { // right flipper
ActivateSolenoid(0, 23);}
else if (USB_SerialBuffer[0] == 24) { // left flipper
ActivateSolenoid(0, 24);}
else if (USB_SerialBuffer[0] == 25) { // 25 is a shortcut for both flipper fingers
ActivateSolenoid(0, 23); // enable both flipper fingers
ActivateSolenoid(0, 24);}
else if ((USB_SerialBuffer[0] <= SolMax) && APC_settings[SolenoidExp]) { // sol exp board selected
WriteToHwExt(SolBuffer[3] |= 1<<(USB_SerialBuffer[0]-26), 128+4);
WriteToHwExt(SolBuffer[3] |= 1<<(USB_SerialBuffer[0]-26), 4);}}}
break;
case 22: // set solenoid # to off
if (game_settings[USB_PinMameGame] > 18 || USB_SerialBuffer[0] < 9 || USB_SerialBuffer[0] > 13) { // block solenoid commands for Sys 3 - 6 sound control lines
if (!PinMameException(SolenoidRelCommand, USB_SerialBuffer[0])){ // check for machine specific exceptions
if (USB_SerialBuffer[0] < 25) { // max 24 solenoids
ReleaseSolenoid(USB_SerialBuffer[0]);}
else if (USB_SerialBuffer[0] == 25) { // 25 is a shortcut for both flipper fingers
ReleaseSolenoid(23); // disable both flipper fingers
ReleaseSolenoid(24);}
else if ((USB_SerialBuffer[0] <= SolMax) && APC_settings[SolenoidExp]) { // sol exp board selected
WriteToHwExt(SolBuffer[3] &= 255-(1<<(USB_SerialBuffer[0]-26)), 128+4);
WriteToHwExt(SolBuffer[3] &= 255-(1<<(USB_SerialBuffer[0]-26)), 4);}}}
break;
case 23: // pulse solenoid
if (USB_SolTimes[USB_SerialBuffer[0]-1]) { // pulse length set?
ActivateSolenoid((byte) USB_SolTimes[USB_SerialBuffer[0]-1], USB_SerialBuffer[0]);}
break;
case 24: // set solenoid pulse time
if (USB_SerialBuffer[0] < 25) { // max 24 solenoids
USB_SolTimes[USB_SerialBuffer[0]-1] = USB_SerialBuffer[1];}
break;
case 25: // set solenoid recycle time
SolRecycleTime[USB_SerialBuffer[0]-1] = USB_SerialBuffer[1];
break;
case 30: // set display 0 to (credit display)
if (!PinMameException(WriteToDisplay0, 0)){ // check for machine specific exceptions
switch (APC_settings[DisplayType]) { // which display is used?
case 0: // 4 ALPHA+CREDIT
case 1: // Sys11 Pinbot
switch (USB_DisplayProtocol[0]) { // which protocol shall be used?
case 1: // BCD
case 2: // BCD with comma (not possible as credit has no comma)
*(DisplayUpper) = LeftCredit[(USB_SerialBuffer[0]+16)*2];
*(DisplayUpper+16) = LeftCredit[(USB_SerialBuffer[1]+16)*2];
*(DisplayLower) = RightCredit[(USB_SerialBuffer[2]+16)*2];
*(DisplayLower+16) = RightCredit[(USB_SerialBuffer[3]+16)*2];
break;
case 3: // 7 segment pattern (1 byte)
*(DisplayUpper) = USB_SerialBuffer[0];
*(DisplayUpper+16) = USB_SerialBuffer[1];
*(DisplayLower) = ConvertPattern(0, USB_SerialBuffer[2]);
*(DisplayLower+16) = ConvertPattern(0, USB_SerialBuffer[3]);
break;
case 4: // 14 segment pattern (2 bytes)
*(DisplayUpper) = USB_SerialBuffer[0];
*(DisplayUpper+16) = USB_SerialBuffer[2];
*(DisplayLower) = ConvertPattern(0, USB_SerialBuffer[4]);
*(DisplayLower+16) = ConvertPattern(0, USB_SerialBuffer[6]);
break;
case 5: // ASCII
case 6: // ASCII with comma (not possible as credit has no comma)
WritePlayerDisplay((char*)USB_SerialBuffer, 0);
break;}
break;
case 7: // Sys3 - 6 display
case 8: // Sys7 + 9 display
switch (USB_DisplayProtocol[0]) { // which protocol shall be used?
case 1: // BCD
case 2: // BCD with comma
DisplayBCD(0, USB_SerialBuffer);
break;
case 5:
case 6:
WritePlayerDisplay((char*)USB_SerialBuffer, 0);
break;}
break;}}
break;
case 31: // set display 1 to
if (!PinMameException(WriteToDisplay1, 0)){ // check for machine specific exceptions
switch (APC_settings[DisplayType]) { // which display is used?
case 0: // 4 ALPHA+CREDIT
case 1: // Sys11 Pinbot
case 2: // Sys11 F-14
switch (USB_DisplayProtocol[1]) { // which protocol shall be used?
case 1: // BCD
for (i=0; i<7; i++) {
*(DisplayUpper+2*i+2) = DispPattern1[32+2*USB_SerialBuffer[i]];
*(DisplayUpper+2*i+3) = DispPattern1[33+2*USB_SerialBuffer[i]];}
break;
case 2: // BCD with comma
for (i=0; i<7; i++) {
if (USB_SerialBuffer[i] & 128) { // comma set?
*(DisplayUpper+2*i+2) = 128 | DispPattern1[32+2*(USB_SerialBuffer[i] & 15)];
*(DisplayUpper+2*i+3) = 64 | DispPattern1[33+2*(USB_SerialBuffer[i] & 15)];}
else {
*(DisplayUpper+2*i+2) = DispPattern1[32+2*USB_SerialBuffer[i]];
*(DisplayUpper+2*i+3) = DispPattern1[33+2*USB_SerialBuffer[i]];}}
break;
case 3: // 7 segment pattern (1 byte)
for (i=0; i<7; i++) {
*(DisplayUpper+2*i+2) = USB_SerialBuffer[i];
if (USB_SerialBuffer[i] & 64) { // g segment set?
*(DisplayUpper+2*i+3) = 4;} // turn on m segment of alpha display
else {
*(DisplayUpper+2*i+1) = 0;}}
break;
case 4: // 14 segment pattern (2 bytes)
for (i=0; i<14; i++) {
*(DisplayUpper+i+2) = USB_SerialBuffer[i];}
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 1);
break;}
break;
case 3: // Sys11 BK2K
case 4: // Sys11 Taxi
case 5: // Sys11 Riverboat Gambler
case 6: // DE 2x16
switch (USB_DisplayProtocol[1]) { // which protocol shall be used?
case 1: // BCD
for (i=0; i<16; i++) {
*(DisplayUpper+2*i) = DispPattern1[32+2*USB_SerialBuffer[i]];
*(DisplayUpper+2*i+1) = DispPattern1[33+2*USB_SerialBuffer[i]];}
break;
case 2: // BCD with comma
for (i=0; i<16; i++) {
if (USB_SerialBuffer[i] & 128) { // comma set?
*(DisplayUpper+2*i) = 128 | DispPattern1[32+2*(USB_SerialBuffer[i] & 15)];
*(DisplayUpper+2*i+1) = 64 | DispPattern1[33+2*(USB_SerialBuffer[i] & 15)];}
else {
*(DisplayUpper+2*i) = DispPattern1[32+2*USB_SerialBuffer[i]];
*(DisplayUpper+2*i+1) = DispPattern1[33+2*USB_SerialBuffer[i]];}}
break;
case 3: // 7 segment pattern (1 byte)
for (i=0; i<16; i++) {
*(DisplayUpper+2*i) = USB_SerialBuffer[i];
if (USB_SerialBuffer[i] & 64) { // g segment set?
*(DisplayUpper+2*i+1) = 4;} // turn on m segment of alpha display
else {
*(DisplayUpper+2*i+1) = 0;}}
break;
case 4: // 14 segment pattern (2 bytes)
for (i=0; i<32; i++) {
*(DisplayUpper+i) = USB_SerialBuffer[i];}
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 1);
break;}
break;
case 7: // Sys3 - 6 display
case 8: // Sys7 + 9 display
switch (USB_DisplayProtocol[1]) { // which protocol shall be used?
case 1: // BCD
case 2: // BCD with comma
DisplayBCD(1, USB_SerialBuffer);
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 1);
break;}
break;}}
break;
case 32: // set display 2 to
if (!PinMameException(WriteToDisplay2, 0)){ // check for machine specific exceptions
switch (APC_settings[DisplayType]) { // which display is used?
case 0: // 4 ALPHA+CREDIT
case 1: // Sys11 Pinbot
case 2: // Sys11 F-14
switch (USB_DisplayProtocol[2]) { // which protocol shall be used?
case 1: // BCD
for (i=0; i<7; i++) {
*(DisplayUpper+2*i+18) = DispPattern1[32+2*USB_SerialBuffer[i]];
*(DisplayUpper+2*i+19) = DispPattern1[33+2*USB_SerialBuffer[i]];}
break;
case 2: // BCD with comma
for (i=0; i<7; i++) {
if (USB_SerialBuffer[i] & 128) { // comma set?
*(DisplayUpper+2*i+18) = 128 | DispPattern1[32+2*(USB_SerialBuffer[i] & 15)];
*(DisplayUpper+2*i+19) = 64 | DispPattern1[33+2*(USB_SerialBuffer[i] & 15)];}
else {
*(DisplayUpper+2*i+18) = DispPattern1[32+2*USB_SerialBuffer[i]];
*(DisplayUpper+2*i+19) = DispPattern1[33+2*USB_SerialBuffer[i]];}}
break;
case 3: // 7 segment pattern (1 byte)
for (i=0; i<7; i++) {
*(DisplayUpper+2*i+18) = USB_SerialBuffer[i];
if (USB_SerialBuffer[i] & 64) { // g segment set?
*(DisplayUpper+2*i+19) = 4;} // turn on m segment of alpha display
else {
*(DisplayUpper+2*i+19) = 0;}}
break;
case 4: // 14 segment pattern (2 bytes)
for (i=0; i<14; i++) {
*(DisplayUpper+i+18) = USB_SerialBuffer[i];}
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 2);
break;}
break;
case 3: // Sys11 BK2K
if (!game_settings[USB_Debug]) { // display can be used for debug information
switch (USB_DisplayProtocol[2]) { // which protocol shall be used?
case 1: // BCD
for (i=0; i<16; i++) {
*(DisplayLower+2*i) = DispPattern2[32+2*USB_SerialBuffer[i]];
*(DisplayLower+2*i+1) = DispPattern2[33+2*USB_SerialBuffer[i]];}
break;
case 2: // BCD with comma
for (i=0; i<16; i++) {
if (USB_SerialBuffer[i] & 128) { // comma set?
*(DisplayLower+2*i) = 1 | DispPattern2[32+2*(USB_SerialBuffer[i] & 15)];
*(DisplayLower+2*i+1) = 8 | DispPattern2[33+2*(USB_SerialBuffer[i] & 15)];}
else {
*(DisplayLower+2*i) = DispPattern2[32+2*USB_SerialBuffer[i]];
*(DisplayLower+2*i+1) = DispPattern2[33+2*USB_SerialBuffer[i]];}}
break;
case 3: // 7 segment pattern (1 byte)
for (i=0; i<16; i++) {
*(DisplayLower+2*i) = ConvertPattern(0, USB_SerialBuffer[i]);}
break;
case 4: // 14 segment pattern (2 bytes)
for (i=0; i<16; i++) {
*(DisplayLower+2*i) = ConvertPattern(0, USB_SerialBuffer[2*i]);
*(DisplayLower+2*i+1) = ConvertPattern(1, USB_SerialBuffer[2*i+1]);}
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 2);
break;}}
break;
case 4: // Sys11 Taxi
case 5: // Sys11 Riverboat Gambler
case 6: // DE 2x16
if (!game_settings[USB_Debug]) { // display can be used for debug information
switch (USB_DisplayProtocol[2]) { // which protocol shall be used?
case 1: // BCD
for (i=0; i<16; i++) {
*(DisplayLower+2*i) = DispPattern2[32+2*USB_SerialBuffer[i]];}
break;
case 2: // BCD with comma
for (i=0; i<16; i++) {
if (USB_SerialBuffer[i] & 128) { // comma set?
*(DisplayLower+2*i) = 1 | DispPattern2[32+2*(USB_SerialBuffer[i] & 15)];}
else {
*(DisplayLower+2*i) = DispPattern2[32+2*USB_SerialBuffer[i]];}}
break;
case 3: // 7 segment pattern (1 byte)
for (i=0; i<16; i++) {
*(DisplayLower+2*i) = ConvertPattern(0, USB_SerialBuffer[i]);}
break;
case 4: // 14 segment pattern (2 bytes)
for (i=0; i<16; i++) {
*(DisplayLower+2*i) = ConvertPattern(0, USB_SerialBuffer[2*i]);
*(DisplayLower+2*i+1) = ConvertPattern(1, USB_SerialBuffer[2*i+1]);}
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 2);
break;}}
break;
case 7: // Sys3 - 6 display
case 8: // Sys7 + 9 display
switch (USB_DisplayProtocol[2]) { // which protocol shall be used?
case 1: // BCD
case 2: // BCD with comma
DisplayBCD(2, USB_SerialBuffer);
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 2);
break;}
break;}}
break;
case 33: // set display 3 to
if (!game_settings[USB_Debug] && !PinMameException(WriteToDisplay3, 0)) { // display can be used for debug information
switch (APC_settings[DisplayType]) { // which display is used?
case 0: // 4 ALPHA+CREDIT
switch (USB_DisplayProtocol[3]) { // which protocol shall be used?
case 1: // BCD
for (i=0; i<7; i++) {
*(DisplayLower+2*i+2) = DispPattern2[32+2*USB_SerialBuffer[i]];
*(DisplayLower+2*i+3) = DispPattern2[33+2*USB_SerialBuffer[i]];}
break;
case 2: // BCD with comma
for (i=0; i<7; i++) {
if (USB_SerialBuffer[i] & 128) { // comma set?
*(DisplayLower+2*i+2) = 1 | DispPattern2[32+2*(USB_SerialBuffer[i] & 15)];
*(DisplayLower+2*i+3) = 8 | DispPattern2[33+2*(USB_SerialBuffer[i] & 15)];}
else {
*(DisplayLower+2*i+2) = DispPattern2[32+2*USB_SerialBuffer[i]];
*(DisplayLower+2*i+3) = DispPattern2[33+2*USB_SerialBuffer[i]];}}
break;
case 3: // 7 segment pattern (1 byte)
for (i=0; i<7; i++) {
*(DisplayUpper+2*i+2) = ConvertPattern(0, USB_SerialBuffer[i]);
if (USB_SerialBuffer[i] & 64) { // g segment set?
*(DisplayLower+2*i+3) = 2;} // turn on m segment of alpha display
else {
*(DisplayLower+2*i+3) = 0;}}
break;
case 4: // 14 segment pattern (2 bytes)
for (i=0; i<14; i++) {
*(DisplayLower+2*i+2) = ConvertPattern(0, USB_SerialBuffer[2*i]);
*(DisplayLower+2*i+3) = ConvertPattern(1, USB_SerialBuffer[2*i+1]);}
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 3);
break;}
break;
case 1: // Sys11 Pinbot
case 2: // Sys11 F-14
switch (USB_DisplayProtocol[3]) { // which protocol shall be used?
case 1: // BCD
for (i=0; i<7; i++) {
*(DisplayLower+2*i+2) = DispPattern2[32+2*USB_SerialBuffer[i]];}
break;
case 2: // BCD with comma
for (i=0; i<7; i++) {
if (USB_SerialBuffer[i] & 128) { // comma set?
*(DisplayLower+2*i+2) = 1 | DispPattern2[32+2*(USB_SerialBuffer[i] & 15)];}
else {
*(DisplayLower+2*i+2) = DispPattern2[32+2*USB_SerialBuffer[i]];}}
break;
case 3: // 7 segment pattern (1 byte)
for (i=0; i<7; i++) {
*(DisplayLower+2*i+2) = ConvertPattern(0, USB_SerialBuffer[i]);}
break;
// case 4: // 14 segment pattern (2 bytes)
// for (i=0; i<14; i++) {
// *(DisplayLower+2*i+2) = ConvertPattern(0, USB_SerialBuffer[i]);}
// break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 3);
break;}
break;
case 4: // Sys11 Taxi
case 5: // Sys11 Riverboat Gambler
for (i=0; i<7; i++) { // 7 segment pattern assumed (1 byte)
*(DisplayLower+2*i+1) = ConvertPattern(1, USB_SerialBuffer[i]);}
break;
case 7: // Sys3 - 6 display
case 8: // Sys7 + 9 display
switch (USB_DisplayProtocol[3]) { // which protocol shall be used?
case 1: // BCD
case 2: // BCD with comma
DisplayBCD(3, USB_SerialBuffer);
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 3);
break;}
break;}}
break;
case 34: // set display 4 to
if (!game_settings[USB_Debug] && !PinMameException(WriteToDisplay4, 0)) { // display can be used for debug information
switch (APC_settings[DisplayType]) { // which display is used?
case 0: // 4 ALPHA+CREDIT
switch (USB_DisplayProtocol[4]) { // which protocol shall be used?
case 1: // BCD
for (i=0; i<7; i++) {
*(DisplayLower+2*i+18) = DispPattern2[32+2*USB_SerialBuffer[i]];
*(DisplayLower+2*i+19) = DispPattern2[33+2*USB_SerialBuffer[i]];}
break;
case 2: // BCD with comma
for (i=0; i<7; i++) {
if (USB_SerialBuffer[i] & 128) { // comma set?
*(DisplayLower+2*i+18) = 1 | DispPattern2[32+2*(USB_SerialBuffer[i] & 15)];
*(DisplayLower+2*i+19) = 8 | DispPattern2[33+2*(USB_SerialBuffer[i] & 15)];}
else {
*(DisplayLower+2*i+18) = DispPattern2[32+2*USB_SerialBuffer[i]];
*(DisplayLower+2*i+19) = DispPattern2[33+2*USB_SerialBuffer[i]];}}
break;
case 3: // 7 segment pattern (1 byte)
for (i=0; i<7; i++) {
*(DisplayUpper+2*i+18) = ConvertPattern(0, USB_SerialBuffer[i]);
if (USB_SerialBuffer[i] & 64) { // g segment set?
*(DisplayLower+2*i+19) = 2;} // turn on m segment of alpha display
else {
*(DisplayLower+2*i+19) = 0;}}
break;
case 4: // 14 segment pattern (2 bytes)
for (i=0; i<14; i++) {
*(DisplayLower+2*i+2) = ConvertPattern(0, USB_SerialBuffer[2*i]);
*(DisplayLower+2*i+3) = ConvertPattern(1, USB_SerialBuffer[2*i+1]);}
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 4);
break;}
break;
case 1: // Sys11 Pinbot
case 2: // Sys11 F-14
switch (USB_DisplayProtocol[4]) { // which protocol shall be used?
case 1: // BCD
for (i=0; i<7; i++) {
*(DisplayLower+2*i+18) = DispPattern2[32+2*USB_SerialBuffer[i]];}
break;
case 2: // BCD with comma
for (i=0; i<7; i++) {
if (USB_SerialBuffer[i] & 128) { // comma set?
*(DisplayLower+2*i+18) = 16 | DispPattern2[32+2*(USB_SerialBuffer[i] & 15)];}
else {
*(DisplayLower+2*i+18) = DispPattern2[32+2*USB_SerialBuffer[i]];}}
break;
case 3: // 7 segment pattern (1 byte)
for (i=0; i<7; i++) {
*(DisplayLower+2*i+18) = ConvertPattern(0, USB_SerialBuffer[i]);}
break;
case 4: // 14 segment pattern (2 bytes)
for (i=0; i<14; i++) {
*(DisplayLower+2*i+18) = ConvertPattern(0, USB_SerialBuffer[i]);}
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 4);
break;}
break;
case 4: // Sys11 Taxi
case 5: // Sys11 Riverboat Gambler
for (i=0; i<7; i++) { // 7 segment pattern assumed (1 byte)
*(DisplayLower+2*i+17) = ConvertPattern(1, USB_SerialBuffer[i]);}
break;
case 7: // Sys3 - 6 display
case 8: // Sys7 + 9 display
switch (USB_DisplayProtocol[4]) { // which protocol shall be used?
case 1: // BCD
case 2: // BCD with comma
DisplayBCD(4, USB_SerialBuffer);
break;
case 5: // ASCII
case 6: // ASCII with comma
WritePlayerDisplay((char*)USB_SerialBuffer, 4);
break;}
break;}}
break;
case 37: // select display protocol
if (USB_SerialBuffer[0] < 5) {
USB_DisplayProtocol[USB_SerialBuffer[0]] = USB_SerialBuffer[1];}
break;
case 40: // get status of switch #
if (USB_SerialBuffer[0] < 74) { // max 73 switches
if (QuerySwitch(USB_SerialBuffer[0])) { // query state
USB_WriteByte((byte) 1);}
else {
USB_WriteByte((byte) 0);}}
else {
USB_WriteByte((byte) 2);}
break;
case 41: // get changed switches
if (USB_ChangedSwitches[0]) { // any changed switches?
i = 0;
USB_WriteByte((byte) USB_ChangedSwitches[0]); // send it
do {
USB_ChangedSwitches[i] = USB_ChangedSwitches[i+1];
i++;}
while (USB_ChangedSwitches[i]);} // still more changed switches?
else {
USB_WriteByte((byte) 127);} // no changed switches at all
break;
case 50: // play sound #
if (game_settings[USB_PinMameSound]) { // use old audio board
if (game_settings[USB_PinMameGame] < 19) { // Sys 3 - 6 game
SolBuffer[1] = SolBuffer[1] & 224; // turn off sound related solenoids
SolBuffer[1] = SolBuffer[1] | (~USB_SerialBuffer[1] & 31);} // write sound number to solenoids 9 - 13
else if (game_settings[USB_PinMameGame] < 40) { // Sys 7 - 9 game
WriteToHwExt(USB_SerialBuffer[1], 128+16); // turn on Sel14
WriteToHwExt(USB_SerialBuffer[1], 16);} // turn off Sel14
else { // Sys 11 game
WriteToHwExt(USB_SerialBuffer[1], 4); // turn off Sel7
WriteToHwExt(USB_SerialBuffer[1], 128+4+16);}} // turn on Sel7 + Sel14
else { // use APC sound HW
if (USB_SerialBuffer[0] == 1) { // channel 1?
PinMameException(SoundCommandCh1, USB_SerialBuffer[1]);}
else { // channel 2
PinMameException(SoundCommandCh2, USB_SerialBuffer[1]);}}
break;
case 51: // stop sound
if (USB_SerialBuffer[0] == 1) { // channel 1?
AfterMusic = 0;
StopPlayingMusic();}
else {
AfterSound = 0;
StopPlayingSound();}
break;
case 52: // play soundfile
if (USB_SerialBuffer[0] == 1) { // channel 1?
if (!USB_WaitSoundTimer) { // no sound wait timer active?
PlayMusic(50, (char*) USB_SerialBuffer+2); // play the sound
USB_WaitSoundTimer = ActivateTimer(15, 0, USB_ResetWaitSoundTimers); // start a timer
if (USB_SerialBuffer[1] & 1) { // looping active?
for (i=0; i<12; i++) {
USB_RepeatMusic[i] = USB_SerialBuffer[2+i];}
QueueNextMusic(USB_RepeatMusic);}
else {
AfterMusic = 0;}}
else { // sound wait timer active
if (!USB_WaitingSoundFiles[0][1]) { // any waiting sounds?
if (USB_SerialBuffer[1] & 1) { // if not check for looping
USB_WaitingSoundFiles[0][0] = 2;} // set the looping flag
for (i=0; i<12; i++) { // copy the filename to the waiting stack
USB_WaitingSoundFiles[0][i+1] = USB_SerialBuffer[2+i];}}
else { // waiting stack not empty
if (USB_WaitingSoundFiles[0][0] & 1) { // is the waiting sound for channel 2?
if (USB_SerialBuffer[1] & 1) { // then copy the sound data to stack position 2
USB_WaitingSoundFiles[1][0] = 2;}
for (i=0; i<12; i++) { // copy the filename to the waiting stack
USB_WaitingSoundFiles[1][1+i] = USB_SerialBuffer[2+i];}}
else { // waiting sound is also for channel 1
if (USB_WaitingSoundFiles[1][1]) { // is there a sound in waiting position 2?
for (i=1; i<13; i++) { // if yes move it to position 1 and copy the new sound to position 2
USB_WaitingSoundFiles[0][i] = USB_WaitingSoundFiles[1][i];
USB_WaitingSoundFiles[1][i] = USB_SerialBuffer[1+i];}
USB_WaitingSoundFiles[0][0] = USB_WaitingSoundFiles[1][0]; // copy command byte
if (USB_SerialBuffer[1] & 1) { // handle looping flag
USB_WaitingSoundFiles[1][0] = 2;}
else {
USB_WaitingSoundFiles[1][0] = 0;}}
else { // no sound at stack position 2
if (USB_SerialBuffer[1] & 1) { // overwrite stack position 1
USB_WaitingSoundFiles[0][0] = 2;}
else {
USB_WaitingSoundFiles[0][0] = 0;}
for (i=0; i<12; i++) { // copy the filename to the waiting stack
USB_WaitingSoundFiles[0][i+1] = USB_SerialBuffer[2+i];}}}}}}
else { // channel 2
if (!USB_WaitSoundTimer) {
PlaySound(50, (char*) USB_SerialBuffer+2);
USB_WaitSoundTimer = ActivateTimer(15, 0, USB_ResetWaitSoundTimers);
if (USB_SerialBuffer[1] & 1) { // looping active?
for (i=0; i<12; i++) {
USB_RepeatSound[i] = USB_SerialBuffer[2+i];}
QueueNextSound(USB_RepeatSound);}
else {
AfterSound = 0;}}
else {
if (!USB_WaitingSoundFiles[0][1]) { // any waiting sounds?
if (USB_SerialBuffer[1] & 1) { // is not check for looping
USB_WaitingSoundFiles[0][0] = 3;} // set the looping flag
else {
USB_WaitingSoundFiles[0][0] = 1;} // or just set the channel 2 flag