forked from RetroPinUpgrade/ExampleMachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleMachine.ino
2624 lines (2192 loc) · 88.1 KB
/
ExampleMachine.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
/**************************************************************************
This pinball Example Machine code is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
See <https://www.gnu.org/licenses/>.
*/
#include "RPU_Config.h"
#include "RPU.h"
#include "DropTargets.h"
#include "ExampleMachine.h"
#include "SelfTestAndAudit.h"
#include "AudioHandler.h"
#include "LampAnimations.h"
#include <EEPROM.h>
#define GAME_MAJOR_VERSION 2023
#define GAME_MINOR_VERSION 1
#define DEBUG_MESSAGES 1
/*********************************************************************
Game specific code
*********************************************************************/
// MachineState
// 0 - Attract Mode
// negative - self-test modes
// positive - game play
char MachineState = 0;
boolean MachineStateChanged = true;
#define MACHINE_STATE_ATTRACT 0
#define MACHINE_STATE_INIT_GAMEPLAY 1
#define MACHINE_STATE_INIT_NEW_BALL 2
#define MACHINE_STATE_NORMAL_GAMEPLAY 4
#define MACHINE_STATE_COUNTDOWN_BONUS 99
#define MACHINE_STATE_BALL_OVER 100
#define MACHINE_STATE_MATCH_MODE 110
#define MACHINE_STATE_DIAGNOSTICS 120
#define MACHINE_STATE_ADJUST_FREEPLAY (MACHINE_STATE_TEST_DONE-1)
#define MACHINE_STATE_ADJUST_BALL_SAVE (MACHINE_STATE_TEST_DONE-2)
#define MACHINE_STATE_ADJUST_SOUND_SELECTOR (MACHINE_STATE_TEST_DONE-3)
#define MACHINE_STATE_ADJUST_MUSIC_VOLUME (MACHINE_STATE_TEST_DONE-4)
#define MACHINE_STATE_ADJUST_SFX_VOLUME (MACHINE_STATE_TEST_DONE-5)
#define MACHINE_STATE_ADJUST_CALLOUTS_VOLUME (MACHINE_STATE_TEST_DONE-6)
#define MACHINE_STATE_ADJUST_TOURNAMENT_SCORING (MACHINE_STATE_TEST_DONE-7)
#define MACHINE_STATE_ADJUST_TILT_WARNING (MACHINE_STATE_TEST_DONE-8)
#define MACHINE_STATE_ADJUST_AWARD_OVERRIDE (MACHINE_STATE_TEST_DONE-9)
#define MACHINE_STATE_ADJUST_BALLS_OVERRIDE (MACHINE_STATE_TEST_DONE-10)
#define MACHINE_STATE_ADJUST_SCROLLING_SCORES (MACHINE_STATE_TEST_DONE-11)
#define MACHINE_STATE_ADJUST_EXTRA_BALL_AWARD (MACHINE_STATE_TEST_DONE-12)
#define MACHINE_STATE_ADJUST_SPECIAL_AWARD (MACHINE_STATE_TEST_DONE-13)
#define MACHINE_STATE_ADJUST_CREDIT_RESET_HOLD_TIME (MACHINE_STATE_TEST_DONE-14)
#define MACHINE_STATE_ADJUST_DONE (MACHINE_STATE_TEST_DONE-15)
#define GAME_MODE_SKILL_SHOT 1
#define GAME_MODE_UNSTRUCTURED_PLAY 2
// Add more game modes as necessary
// Examples:
//#define GAME_MODE_DROP_TARGET_FRENZY_START 3
//#define GAME_MODE_DROP_TARGET_FRENZY 4
//#define GAME_MODE_DROP_TARGET_FRENZY_FINISH 5
// Indices of EEPROM save locations
#define EEPROM_BALL_SAVE_BYTE 100
#define EEPROM_FREE_PLAY_BYTE 101
#define EEPROM_SOUND_SELECTOR_BYTE 102
#define EEPROM_SKILL_SHOT_BYTE 103
#define EEPROM_TILT_WARNING_BYTE 104
#define EEPROM_AWARD_OVERRIDE_BYTE 105
#define EEPROM_BALLS_OVERRIDE_BYTE 106
#define EEPROM_TOURNAMENT_SCORING_BYTE 107
#define EEPROM_SFX_VOLUME_BYTE 108
#define EEPROM_MUSIC_VOLUME_BYTE 109
#define EEPROM_SCROLLING_SCORES_BYTE 110
#define EEPROM_CALLOUTS_VOLUME_BYTE 111
#define EEPROM_CRB_HOLD_TIME 118
#define EEPROM_EXTRA_BALL_SCORE_UL 140
#define EEPROM_SPECIAL_SCORE_UL 144
#define SOUND_EFFECT_NONE 0
#define SOUND_EFFECT_BONUS_COUNT 1
#define SOUND_EFFECT_BALL_OVER 19
#define SOUND_EFFECT_GAME_OVER 20
#define SOUND_EFFECT_TILT_WARNING 28
#define SOUND_EFFECT_MATCH_SPIN 30
#define SOUND_EFFECT_TILT 61
#define SOUND_EFFECT_SCORE_TICK 67
#define SOUND_EFFECT_COIN_DROP_1 100
#define SOUND_EFFECT_COIN_DROP_2 101
#define SOUND_EFFECT_COIN_DROP_3 102
#define SOUND_EFFECT_MACHINE_START 120
#if (RPU_MPU_ARCHITECTURE<10) && !defined(RPU_OS_DISABLE_CPC_FOR_SPACE)
// This array maps the self-test modes to audio callouts
unsigned short SelfTestStateToCalloutMap[34] = { 136, 137, 135, 134, 133, 140, 141, 142, 139, 143, 144, 145, 146, 147, 148, 149, 138, 150, 151, 152,
153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166 };
#elif (RPU_MPU_ARCHITECTURE<10) && defined(RPU_OS_DISABLE_CPC_FOR_SPACE)
unsigned short SelfTestStateToCalloutMap[31] = { 136, 137, 135, 134, 133, 140, 141, 142, 139, 143, 144, 145, 146, 147, 148, 149, 138,
153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166 };
#elif (RPU_MPU_ARCHITECTURE>=10) && !defined(RPU_OS_DISABLE_CPC_FOR_SPACE)
// This array maps the self-test modes to audio callouts
unsigned short SelfTestStateToCalloutMap[34] = { 134, 135, 133, 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 };
#elif (RPU_MPU_ARCHITECTURE>=10) && defined(RPU_OS_DISABLE_CPC_FOR_SPACE)
unsigned short SelfTestStateToCalloutMap[34] = { 134, 135, 133, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166 };
#endif
#define SOUND_EFFECT_SELF_TEST_MODE_START 132
#define SOUND_EFFECT_SELF_TEST_CPC_START 180
#define SOUND_EFFECT_SELF_TEST_AUDIO_OPTIONS_START 190
#define SOUND_EFFECT_BACKGROUND_SONG_1 500
#define NUM_BACKGROUND_SONGS 10
#define SOUND_EFFECT_BATTLE_SONG_1 525
#define NUM_BATTLE_SONGS 3
// Game play status callouts
#define NUM_VOICE_NOTIFICATIONS 24
#define SOUND_EFFECT_VP_VOICE_NOTIFICATIONS_START 300
#define SOUND_EFFECT_VP_PLAYER 300
#define SOUND_EFFECT_VP_ONE 301
#define SOUND_EFFECT_VP_TWO 302
#define SOUND_EFFECT_VP_THREE 303
#define SOUND_EFFECT_VP_FOUR 304
#define SOUND_EFFECT_VP_EXTRA_BALL 305
#define SOUND_EFFECT_VP_ADD_PLAYER_1 306
#define SOUND_EFFECT_VP_ADD_PLAYER_2 (SOUND_EFFECT_VP_ADD_PLAYER_1+1)
#define SOUND_EFFECT_VP_ADD_PLAYER_3 (SOUND_EFFECT_VP_ADD_PLAYER_1+2)
#define SOUND_EFFECT_VP_ADD_PLAYER_4 (SOUND_EFFECT_VP_ADD_PLAYER_1+3)
#define SOUND_EFFECT_VP_SHOOT_AGAIN 310
#define SOUND_EFFECT_DIAG_START 1900
#define SOUND_EFFECT_DIAG_CREDIT_RESET_BUTTON 1900
#define SOUND_EFFECT_DIAG_SELECTOR_SWITCH_ON 1901
#define SOUND_EFFECT_DIAG_SELECTOR_SWITCH_OFF 1902
#define SOUND_EFFECT_DIAG_STARTING_ORIGINAL_CODE 1903
#define SOUND_EFFECT_DIAG_STARTING_NEW_CODE 1904
#define SOUND_EFFECT_DIAG_ORIGINAL_CPU_DETECTED 1905
#define SOUND_EFFECT_DIAG_ORIGINAL_CPU_RUNNING 1906
#define SOUND_EFFECT_DIAG_PROBLEM_PIA_U10 1907
#define SOUND_EFFECT_DIAG_PROBLEM_PIA_U11 1908
#define SOUND_EFFECT_DIAG_PROBLEM_PIA_1 1909
#define SOUND_EFFECT_DIAG_PROBLEM_PIA_2 1910
#define SOUND_EFFECT_DIAG_PROBLEM_PIA_3 1911
#define SOUND_EFFECT_DIAG_PROBLEM_PIA_4 1912
#define SOUND_EFFECT_DIAG_PROBLEM_PIA_5 1913
#define SOUND_EFFECT_DIAG_STARTING_DIAGNOSTICS 1914
#define MAX_DISPLAY_BONUS 10
#define TILT_WARNING_DEBOUNCE_TIME 1000
/*********************************************************************
Machine state and options
*********************************************************************/
byte Credits = 0;
byte SoundSelector = 3;
byte BallSaveNumSeconds = 0;
byte MaximumCredits = 40;
byte BallsPerGame = 3;
byte ScoreAwardReplay = 0;
byte MusicVolume = 6;
byte SoundEffectsVolume = 8;
byte CalloutsVolume = 10;
byte ChuteCoinsInProgress[3];
byte TotalBallsLoaded = 1;
byte TimeRequiredToResetGame = 1;
byte NumberOfBallsInPlay = 0;
byte NumberOfBallsLocked = 0;
byte LampType = 0;
boolean FreePlayMode = false;
boolean HighScoreReplay = true;
boolean MatchFeature = true;
boolean TournamentScoring = false;
boolean ScrollingScores = true;
unsigned long ExtraBallValue = 0;
unsigned long SpecialValue = 0;
unsigned long CurrentTime = 0;
unsigned long HighScore = 0;
unsigned long AwardScores[3];
unsigned long CreditResetPressStarted = 0;
AudioHandler Audio;
/*********************************************************************
Game State
*********************************************************************/
byte CurrentPlayer = 0;
byte CurrentBallInPlay = 1;
byte CurrentNumPlayers = 0;
byte Bonus[4];
byte BonusX[4];
byte GameMode = GAME_MODE_SKILL_SHOT;
byte MaxTiltWarnings = 2;
byte NumTiltWarnings = 0;
byte CurrentAchievements[4];
boolean SamePlayerShootsAgain = false;
boolean BallSaveUsed = false;
boolean ExtraBallCollected = false;
boolean SpecialCollected = false;
boolean TimersPaused = true;
boolean AllowResetAfterBallOne = true;
unsigned long CurrentScores[4];
unsigned long BallFirstSwitchHitTime = 0;
unsigned long BallTimeInTrough = 0;
unsigned long GameModeStartTime = 0;
unsigned long GameModeEndTime = 0;
unsigned long LastTiltWarningTime = 0;
unsigned long ScoreAdditionAnimation;
unsigned long ScoreAdditionAnimationStartTime;
unsigned long LastRemainingAnimatedScoreShown;
unsigned long PlayfieldMultiplier;
unsigned long LastTimeThroughLoop;
unsigned long LastSwitchHitTime;
unsigned long BallSaveEndTime;
#define BALL_SAVE_GRACE_PERIOD 2000
/*********************************************************************
Game Specific State Variables
*********************************************************************/
unsigned long PlayfieldMultiplierExpiration;
unsigned long BonusChanged;
unsigned long BonusXAnimationStart;
DropTargetBank DropTargets(3, 1, DROP_TARGET_TYPE_BLY_1, 50);
/******************************************************
*
* Adjustments Serialization
*
*/
void ReadStoredParameters() {
for (byte count=0; count<3; count++) {
ChuteCoinsInProgress[count] = 0;
}
HighScore = RPU_ReadULFromEEProm(RPU_HIGHSCORE_EEPROM_START_BYTE, 10000);
Credits = RPU_ReadByteFromEEProm(RPU_CREDITS_EEPROM_BYTE);
if (Credits > MaximumCredits) Credits = MaximumCredits;
ReadSetting(EEPROM_FREE_PLAY_BYTE, 0);
FreePlayMode = (EEPROM.read(EEPROM_FREE_PLAY_BYTE)) ? true : false;
BallSaveNumSeconds = ReadSetting(EEPROM_BALL_SAVE_BYTE, 15);
if (BallSaveNumSeconds > 20) BallSaveNumSeconds = 20;
SoundSelector = ReadSetting(EEPROM_SOUND_SELECTOR_BYTE, 3);
if (SoundSelector > 8) SoundSelector = 3;
MusicVolume = ReadSetting(EEPROM_MUSIC_VOLUME_BYTE, 10);
if (MusicVolume>10) MusicVolume = 10;
SoundEffectsVolume = ReadSetting(EEPROM_SFX_VOLUME_BYTE, 10);
if (SoundEffectsVolume>10) SoundEffectsVolume = 10;
CalloutsVolume = ReadSetting(EEPROM_CALLOUTS_VOLUME_BYTE, 10);
if (CalloutsVolume>10) CalloutsVolume = 10;
Audio.SetMusicVolume(MusicVolume);
Audio.SetSoundFXVolume(SoundEffectsVolume);
Audio.SetNotificationsVolume(CalloutsVolume);
TournamentScoring = (ReadSetting(EEPROM_TOURNAMENT_SCORING_BYTE, 0)) ? true : false;
MaxTiltWarnings = ReadSetting(EEPROM_TILT_WARNING_BYTE, 2);
if (MaxTiltWarnings > 2) MaxTiltWarnings = 2;
byte awardOverride = ReadSetting(EEPROM_AWARD_OVERRIDE_BYTE, 99);
if (awardOverride != 99) {
ScoreAwardReplay = awardOverride;
}
byte ballsOverride = ReadSetting(EEPROM_BALLS_OVERRIDE_BYTE, 99);
if (ballsOverride == 3 || ballsOverride == 5) {
BallsPerGame = ballsOverride;
} else {
if (ballsOverride != 99) EEPROM.write(EEPROM_BALLS_OVERRIDE_BYTE, 99);
}
ScrollingScores = (ReadSetting(EEPROM_SCROLLING_SCORES_BYTE, 1)) ? true : false;
ExtraBallValue = RPU_ReadULFromEEProm(EEPROM_EXTRA_BALL_SCORE_UL);
if (ExtraBallValue % 1000 || ExtraBallValue > 100000) ExtraBallValue = 20000;
SpecialValue = RPU_ReadULFromEEProm(EEPROM_SPECIAL_SCORE_UL);
if (SpecialValue % 1000 || SpecialValue > 100000) SpecialValue = 40000;
TimeRequiredToResetGame = ReadSetting(EEPROM_CRB_HOLD_TIME, 1);
if (TimeRequiredToResetGame>3 && TimeRequiredToResetGame!=99) TimeRequiredToResetGame = 1;
AwardScores[0] = RPU_ReadULFromEEProm(RPU_AWARD_SCORE_1_EEPROM_START_BYTE);
AwardScores[1] = RPU_ReadULFromEEProm(RPU_AWARD_SCORE_2_EEPROM_START_BYTE);
AwardScores[2] = RPU_ReadULFromEEProm(RPU_AWARD_SCORE_3_EEPROM_START_BYTE);
}
void QueueDIAGNotification(unsigned short notificationNum) {
// This is optional, but the machine can play an audio message at boot
// time to indicate any errors and whether it's going to boot to original
// or new code.
Audio.QueuePrioritizedNotification(notificationNum, 0, 10, CurrentTime);
}
void setup() {
if (DEBUG_MESSAGES) {
// If debug is on, set up the Serial port for communication
Serial.begin(115200);
Serial.write("Starting\n");
}
// Set up the Audio handler in order to play boot messages
CurrentTime = millis();
Audio.InitDevices(AUDIO_PLAY_TYPE_WAV_TRIGGER | AUDIO_PLAY_TYPE_ORIGINAL_SOUNDS);
Audio.StopAllAudio();
// Tell the OS about game-specific switches
// (this is for software-controlled pop bumpers and slings)
#if (RPU_MPU_ARCHITECTURE<10)
// Machines with a -17, -35, 100, and 200 architecture
// almost always have software based switch-triggered solenoids.
// For those, you can define an array of solenoids and the switches
// that will trigger them:
RPU_SetupGameSwitches(NUM_SWITCHES_WITH_TRIGGERS, NUM_PRIORITY_SWITCHES_WITH_TRIGGERS, SolenoidAssociatedSwitches);
#endif
// Set up the chips and interrupts
unsigned long initResult = 0;
if (DEBUG_MESSAGES) Serial.write("Initializing MPU\n");
// If the hardware has the ability to switch on the Credit/Reset button (requires Rev 4 or greater)
// then that can be used to choose Original or New code. Otherwise, the hardware switch
// will choose Original if open, and New if closed
initResult = RPU_InitializeMPU( RPU_CMD_BOOT_ORIGINAL_IF_CREDIT_RESET | RPU_CMD_BOOT_ORIGINAL_IF_NOT_SWITCH_CLOSED |
RPU_CMD_INIT_AND_RETURN_EVEN_IF_ORIGINAL_CHOSEN | RPU_CMD_PERFORM_MPU_TEST, SW_CREDIT_RESET);
if (DEBUG_MESSAGES) {
char buf[128];
sprintf(buf, "Return from init = 0x%04lX\n", initResult);
Serial.write(buf);
if (initResult&RPU_RET_6800_DETECTED) Serial.write("Detected 6800 clock\n");
else if (initResult&RPU_RET_6802_OR_8_DETECTED) Serial.write("Detected 6802/8 clock\n");
Serial.write("Back from init\n");
}
if (initResult & RPU_RET_SELECTOR_SWITCH_ON) QueueDIAGNotification(SOUND_EFFECT_DIAG_SELECTOR_SWITCH_ON);
else QueueDIAGNotification(SOUND_EFFECT_DIAG_SELECTOR_SWITCH_OFF);
if (initResult & RPU_RET_CREDIT_RESET_BUTTON_HIT) QueueDIAGNotification(SOUND_EFFECT_DIAG_CREDIT_RESET_BUTTON);
if (initResult & RPU_RET_DIAGNOSTIC_REQUESTED) {
QueueDIAGNotification(SOUND_EFFECT_DIAG_STARTING_DIAGNOSTICS);
// Run diagnostics here:
}
if (initResult & RPU_RET_ORIGINAL_CODE_REQUESTED) {
if (DEBUG_MESSAGES) Serial.write("Asked to run original code\n");
delay(100);
QueueDIAGNotification(SOUND_EFFECT_DIAG_STARTING_ORIGINAL_CODE);
delay(100);
while (Audio.Update(millis()));
// Arduino should hang if original code is running
while (1);
}
QueueDIAGNotification(SOUND_EFFECT_DIAG_STARTING_NEW_CODE);
RPU_DisableSolenoidStack();
RPU_SetDisableFlippers(true);
// Read parameters from EEProm
ReadStoredParameters();
RPU_SetCoinLockout((Credits >= MaximumCredits) ? true : false);
CurrentScores[0] = GAME_MAJOR_VERSION;
CurrentScores[1] = GAME_MINOR_VERSION;
CurrentScores[2] = RPU_OS_MAJOR_VERSION;
CurrentScores[3] = RPU_OS_MINOR_VERSION;
CurrentAchievements[0] = 0;
CurrentAchievements[1] = 0;
CurrentAchievements[2] = 0;
CurrentAchievements[3] = 0;
// Initialize any drop target variables here
DropTargets.DefineSwitch(0, SW_DROP_1);
DropTargets.DefineSwitch(1, SW_DROP_2);
DropTargets.DefineSwitch(2, SW_DROP_3);
DropTargets.DefineResetSolenoid(0, SOL_DROP_TARGET_RESET);
Audio.SetMusicDuckingGain(12);
Audio.QueueSound(SOUND_EFFECT_MACHINE_START, AUDIO_PLAY_TYPE_WAV_TRIGGER, CurrentTime+1200);
}
byte ReadSetting(byte setting, byte defaultValue) {
byte value = EEPROM.read(setting);
if (value == 0xFF) {
EEPROM.write(setting, defaultValue);
return defaultValue;
}
return value;
}
// This function is useful for checking the status of drop target switches
byte CheckSequentialSwitches(byte startingSwitch, byte numSwitches) {
byte returnSwitches = 0;
for (byte count = 0; count < numSwitches; count++) {
returnSwitches |= (RPU_ReadSingleSwitchState(startingSwitch + count) << count);
}
return returnSwitches;
}
////////////////////////////////////////////////////////////////////////////
//
// Lamp Management functions
//
////////////////////////////////////////////////////////////////////////////
void SetGeneralIlluminationOn(boolean setGIOn = true) {
// some machines have solenoids attached to relays
// to control the GI
// WOS_SetContinuousSolenoid(!generalIlluminationOn, SOL_GI_RELAY);
// Since this basic shell doesn't have GI,
// this line prevents compiler warnings.
(void)setGIOn;
}
void ShowLockLamps() {
}
void ShowBonusLamps() {
}
void ShowBonusXLamps() {
}
void ShowStandupLamps() {
}
void ShowDropTargetLamps() {
}
void ShowShootAgainLamps() {
if ( (BallFirstSwitchHitTime==0 && BallSaveNumSeconds) || (BallSaveEndTime && CurrentTime<BallSaveEndTime) ) {
unsigned long msRemaining = 5000;
if (BallSaveEndTime!=0) msRemaining = BallSaveEndTime - CurrentTime;
RPU_SetLampState(LAMP_SHOOT_AGAIN, 1, 0, (msRemaining < 5000) ? 100 : 500);
RPU_SetLampState(LAMP_HEAD_SAME_PLAYER_SHOOTS_AGAIN, 1, 0, (msRemaining < 5000) ? 100 : 500);
} else {
RPU_SetLampState(LAMP_SHOOT_AGAIN, SamePlayerShootsAgain);
RPU_SetLampState(LAMP_HEAD_SAME_PLAYER_SHOOTS_AGAIN, SamePlayerShootsAgain);
}
}
/*
boolean RequestedGIState;
unsigned long GIOverrideEndTime;
void SetGeneralIlluminationOn(boolean generalIlluminationOn = true) {
RequestedGIState = generalIlluminationOn;
if (GIOverrideEndTime) return;
RPU_SetContinuousSolenoid(!generalIlluminationOn, SOL_GI_RELAY);
}
void OverrideGeneralIllumination(boolean generalIlluminationOn, unsigned long endTime) {
GIOverrideEndTime = endTime;
RPU_SetContinuousSolenoid(!generalIlluminationOn, SOL_GI_RELAY);
}
*/
////////////////////////////////////////////////////////////////////////////
//
// Display Management functions
//
////////////////////////////////////////////////////////////////////////////
unsigned long LastTimeScoreChanged = 0;
unsigned long LastFlashOrDash = 0;
unsigned long ScoreOverrideValue[4] = {0, 0, 0, 0};
byte LastAnimationSeed[4] = {0, 0, 0, 0};
byte AnimationStartSeed[4] = {0, 0, 0, 0};
byte ScoreOverrideStatus = 0;
byte ScoreAnimation[4] = {0, 0, 0, 0};
byte AnimationDisplayOrder[4] = {0, 1, 2, 3};
#define DISPLAY_OVERRIDE_BLANK_SCORE 0xFFFFFFFF
#define DISPLAY_OVERRIDE_ANIMATION_NONE 0
#define DISPLAY_OVERRIDE_ANIMATION_BOUNCE 1
#define DISPLAY_OVERRIDE_ANIMATION_FLUTTER 2
#define DISPLAY_OVERRIDE_ANIMATION_FLYBY 3
#define DISPLAY_OVERRIDE_ANIMATION_CENTER 4
byte LastScrollPhase = 0;
byte MagnitudeOfScore(unsigned long score) {
if (score == 0) return 0;
byte retval = 0;
while (score > 0) {
score = score / 10;
retval += 1;
}
return retval;
}
void OverrideScoreDisplay(byte displayNum, unsigned long value, byte animationType) {
if (displayNum > 3) return;
ScoreOverrideStatus |= (0x01 << displayNum);
ScoreAnimation[displayNum] = animationType;
ScoreOverrideValue[displayNum] = value;
LastAnimationSeed[displayNum] = 255;
}
byte GetDisplayMask(byte numDigits) {
byte displayMask = 0;
for (byte digitCount = 0; digitCount < numDigits; digitCount++) {
#ifdef RPU_USE_7_DIGIT_DISPLAYS
displayMask |= (0x40 >> digitCount);
#else
displayMask |= (0x20 >> digitCount);
#endif
}
return displayMask;
}
void SetAnimationDisplayOrder(byte disp0, byte disp1, byte disp2, byte disp3) {
AnimationDisplayOrder[0] = disp0;
AnimationDisplayOrder[1] = disp1;
AnimationDisplayOrder[2] = disp2;
AnimationDisplayOrder[3] = disp3;
}
void ShowAnimatedValue(byte displayNum, unsigned long displayScore, byte animationType) {
byte overrideAnimationSeed;
byte displayMask = RPU_OS_ALL_DIGITS_MASK;
byte numDigits = MagnitudeOfScore(displayScore);
if (numDigits == 0) numDigits = 1;
if (numDigits < (RPU_OS_NUM_DIGITS - 1) && animationType == DISPLAY_OVERRIDE_ANIMATION_BOUNCE) {
// This score is going to be animated (back and forth)
overrideAnimationSeed = (CurrentTime / 250) % (2 * RPU_OS_NUM_DIGITS - 2 * numDigits);
if (overrideAnimationSeed != LastAnimationSeed[displayNum]) {
LastAnimationSeed[displayNum] = overrideAnimationSeed;
byte shiftDigits = (overrideAnimationSeed);
if (shiftDigits >= ((RPU_OS_NUM_DIGITS + 1) - numDigits)) shiftDigits = (RPU_OS_NUM_DIGITS - numDigits) * 2 - shiftDigits;
byte digitCount;
displayMask = GetDisplayMask(numDigits);
for (digitCount = 0; digitCount < shiftDigits; digitCount++) {
displayScore *= 10;
displayMask = displayMask >> 1;
}
//RPU_SetDisplayBlank(displayNum, 0x00);
RPU_SetDisplay(displayNum, displayScore, false);
RPU_SetDisplayBlank(displayNum, displayMask);
}
} else if (animationType == DISPLAY_OVERRIDE_ANIMATION_FLUTTER) {
overrideAnimationSeed = CurrentTime / 50;
if (overrideAnimationSeed != LastAnimationSeed[displayNum]) {
LastAnimationSeed[displayNum] = overrideAnimationSeed;
displayMask = GetDisplayMask(numDigits);
if (overrideAnimationSeed % 2) {
displayMask &= 0x55;
} else {
displayMask &= 0xAA;
}
RPU_SetDisplay(displayNum, displayScore, false);
RPU_SetDisplayBlank(displayNum, displayMask);
}
} else if (animationType == DISPLAY_OVERRIDE_ANIMATION_FLYBY) {
overrideAnimationSeed = (CurrentTime / 75) % 256;
if (overrideAnimationSeed != LastAnimationSeed[displayNum]) {
if (LastAnimationSeed[displayNum] == 255) {
AnimationStartSeed[displayNum] = overrideAnimationSeed;
}
LastAnimationSeed[displayNum] = overrideAnimationSeed;
byte realAnimationSeed = overrideAnimationSeed - AnimationStartSeed[displayNum];
if (overrideAnimationSeed < AnimationStartSeed[displayNum]) realAnimationSeed = (255 - AnimationStartSeed[displayNum]) + overrideAnimationSeed;
if (realAnimationSeed > 34) {
RPU_SetDisplayBlank(displayNum, 0x00);
ScoreOverrideStatus &= ~(0x01 << displayNum);
} else {
int shiftDigits = (-6 * ((int)AnimationDisplayOrder[displayNum] + 1)) + realAnimationSeed;
displayMask = GetDisplayMask(numDigits);
if (shiftDigits < 0) {
shiftDigits = 0 - shiftDigits;
byte digitCount;
for (digitCount = 0; digitCount < shiftDigits; digitCount++) {
displayScore /= 10;
displayMask = displayMask << 1;
}
} else if (shiftDigits > 0) {
byte digitCount;
for (digitCount = 0; digitCount < shiftDigits; digitCount++) {
displayScore *= 10;
displayMask = displayMask >> 1;
}
}
RPU_SetDisplay(displayNum, displayScore, false);
RPU_SetDisplayBlank(displayNum, displayMask);
}
}
} else if (animationType == DISPLAY_OVERRIDE_ANIMATION_CENTER) {
overrideAnimationSeed = CurrentTime / 250;
if (overrideAnimationSeed != LastAnimationSeed[displayNum]) {
LastAnimationSeed[displayNum] = overrideAnimationSeed;
byte shiftDigits = (RPU_OS_NUM_DIGITS - numDigits) / 2;
byte digitCount;
displayMask = GetDisplayMask(numDigits);
for (digitCount = 0; digitCount < shiftDigits; digitCount++) {
displayScore *= 10;
displayMask = displayMask >> 1;
}
//RPU_SetDisplayBlank(displayNum, 0x00);
RPU_SetDisplay(displayNum, displayScore, false);
RPU_SetDisplayBlank(displayNum, displayMask);
}
} else {
RPU_SetDisplay(displayNum, displayScore, true, 1);
}
}
void ShowPlayerScores(byte displayToUpdate, boolean flashCurrent, boolean dashCurrent, unsigned long allScoresShowValue = 0) {
if (displayToUpdate == 0xFF) ScoreOverrideStatus = 0;
byte displayMask = RPU_OS_ALL_DIGITS_MASK;
unsigned long displayScore = 0;
byte scrollPhaseChanged = false;
byte scrollPhase = ((CurrentTime - LastTimeScoreChanged) / 125) % 16;
if (scrollPhase != LastScrollPhase) {
LastScrollPhase = scrollPhase;
scrollPhaseChanged = true;
}
for (byte scoreCount = 0; scoreCount < 4; scoreCount++) {
// If this display is currently being overriden, then we should update it
if (allScoresShowValue == 0 && (ScoreOverrideStatus & (0x01 << scoreCount))) {
displayScore = ScoreOverrideValue[scoreCount];
if (displayScore != DISPLAY_OVERRIDE_BLANK_SCORE) {
ShowAnimatedValue(scoreCount, displayScore, ScoreAnimation[scoreCount]);
} else {
RPU_SetDisplayBlank(scoreCount, 0);
}
} else {
boolean showingCurrentAchievement = false;
// No override, update scores designated by displayToUpdate
if (allScoresShowValue == 0) {
displayScore = CurrentScores[scoreCount];
displayScore += (CurrentAchievements[scoreCount] % 10);
if (CurrentAchievements[scoreCount]) showingCurrentAchievement = true;
}
else displayScore = allScoresShowValue;
// If we're updating all displays, or the one currently matching the loop, or if we have to scroll
if (displayToUpdate == 0xFF || displayToUpdate == scoreCount || displayScore > RPU_OS_MAX_DISPLAY_SCORE || showingCurrentAchievement) {
// Don't show this score if it's not a current player score (even if it's scrollable)
if (displayToUpdate == 0xFF && (scoreCount >= CurrentNumPlayers && CurrentNumPlayers != 0) && allScoresShowValue == 0) {
RPU_SetDisplayBlank(scoreCount, 0x00);
continue;
}
if (displayScore > RPU_OS_MAX_DISPLAY_SCORE) {
// Score needs to be scrolled
if ((CurrentTime - LastTimeScoreChanged) < 2000) {
// show score for four seconds after change
RPU_SetDisplay(scoreCount, displayScore % (RPU_OS_MAX_DISPLAY_SCORE + 1), false);
byte blank = RPU_OS_ALL_DIGITS_MASK;
if (showingCurrentAchievement && (CurrentTime / 200) % 2) {
blank &= ~(0x01 << (RPU_OS_NUM_DIGITS - 1));
}
RPU_SetDisplayBlank(scoreCount, blank);
} else {
// Scores are scrolled 10 digits and then we wait for 6
if (scrollPhase < 11 && scrollPhaseChanged) {
byte numDigits = MagnitudeOfScore(displayScore);
// Figure out top part of score
unsigned long tempScore = displayScore;
if (scrollPhase < RPU_OS_NUM_DIGITS) {
displayMask = RPU_OS_ALL_DIGITS_MASK;
for (byte scrollCount = 0; scrollCount < scrollPhase; scrollCount++) {
displayScore = (displayScore % (RPU_OS_MAX_DISPLAY_SCORE + 1)) * 10;
displayMask = displayMask >> 1;
}
} else {
displayScore = 0;
displayMask = 0x00;
}
// Add in lower part of score
if ((numDigits + scrollPhase) > 10) {
byte numDigitsNeeded = (numDigits + scrollPhase) - 10;
for (byte scrollCount = 0; scrollCount < (numDigits - numDigitsNeeded); scrollCount++) {
tempScore /= 10;
}
displayMask |= GetDisplayMask(MagnitudeOfScore(tempScore));
displayScore += tempScore;
}
RPU_SetDisplayBlank(scoreCount, displayMask);
RPU_SetDisplay(scoreCount, displayScore);
}
}
} else {
if (flashCurrent && displayToUpdate == scoreCount) {
unsigned long flashSeed = CurrentTime / 250;
if (flashSeed != LastFlashOrDash) {
LastFlashOrDash = flashSeed;
if (((CurrentTime / 250) % 2) == 0) RPU_SetDisplayBlank(scoreCount, 0x00);
else RPU_SetDisplay(scoreCount, displayScore, true, 2);
}
} else if (dashCurrent && displayToUpdate == scoreCount) {
unsigned long dashSeed = CurrentTime / 50;
if (dashSeed != LastFlashOrDash) {
LastFlashOrDash = dashSeed;
byte dashPhase = (CurrentTime / 60) % (2 * RPU_OS_NUM_DIGITS * 3);
byte numDigits = MagnitudeOfScore(displayScore);
if (dashPhase < (2 * RPU_OS_NUM_DIGITS)) {
displayMask = GetDisplayMask((numDigits == 0) ? 2 : numDigits);
if (dashPhase < (RPU_OS_NUM_DIGITS + 1)) {
for (byte maskCount = 0; maskCount < dashPhase; maskCount++) {
displayMask &= ~(0x01 << maskCount);
}
} else {
for (byte maskCount = (2 * RPU_OS_NUM_DIGITS); maskCount > dashPhase; maskCount--) {
byte firstDigit;
firstDigit = (0x20) << (RPU_OS_NUM_DIGITS - 6);
displayMask &= ~(firstDigit >> (maskCount - dashPhase - 1));
}
}
RPU_SetDisplay(scoreCount, displayScore);
RPU_SetDisplayBlank(scoreCount, displayMask);
} else {
RPU_SetDisplay(scoreCount, displayScore, true, 2);
}
}
} else {
byte blank;
blank = RPU_SetDisplay(scoreCount, displayScore, false, 2);
if (showingCurrentAchievement && (CurrentTime / 200) % 2) {
blank &= ~(0x01 << (RPU_OS_NUM_DIGITS - 1));
}
RPU_SetDisplayBlank(scoreCount, blank);
}
}
} // End if this display should be updated
} // End on non-overridden
} // End loop on scores
}
void ShowFlybyValue(byte numToShow, unsigned long timeBase) {
byte shiftDigits = (CurrentTime - timeBase) / 120;
byte rightSideBlank = 0;
unsigned long bigVersionOfNum = (unsigned long)numToShow;
for (byte count = 0; count < shiftDigits; count++) {
bigVersionOfNum *= 10;
rightSideBlank /= 2;
if (count > 2) rightSideBlank |= 0x20;
}
bigVersionOfNum /= 1000;
byte curMask = RPU_SetDisplay(CurrentPlayer, bigVersionOfNum, false, 0);
if (bigVersionOfNum == 0) curMask = 0;
RPU_SetDisplayBlank(CurrentPlayer, ~(~curMask | rightSideBlank));
}
void StartScoreAnimation(unsigned long scoreToAnimate) {
if (ScoreAdditionAnimation != 0) {
//CurrentScores[CurrentPlayer] += ScoreAdditionAnimation;
}
ScoreAdditionAnimation += scoreToAnimate;
ScoreAdditionAnimationStartTime = CurrentTime;
LastRemainingAnimatedScoreShown = 0;
}
////////////////////////////////////////////////////////////////////////////
//
// Machine State Helper functions
//
////////////////////////////////////////////////////////////////////////////
boolean AddPlayer(boolean resetNumPlayers = false) {
if (Credits < 1 && !FreePlayMode) return false;
if (resetNumPlayers) CurrentNumPlayers = 0;
if (CurrentNumPlayers >= 4) return false;
CurrentNumPlayers += 1;
RPU_SetDisplay(CurrentNumPlayers - 1, 0, true, 2);
// RPU_SetDisplayBlank(CurrentNumPlayers - 1, 0x30);
// RPU_SetLampState(LAMP_HEAD_1_PLAYER, CurrentNumPlayers==1, 0, 500);
// RPU_SetLampState(LAMP_HEAD_2_PLAYERS, CurrentNumPlayers==2, 0, 500);
// RPU_SetLampState(LAMP_HEAD_3_PLAYERS, CurrentNumPlayers==3, 0, 500);
// RPU_SetLampState(LAMP_HEAD_4_PLAYERS, CurrentNumPlayers==4, 0, 500);
if (!FreePlayMode) {
Credits -= 1;
RPU_WriteByteToEEProm(RPU_CREDITS_EEPROM_BYTE, Credits);
RPU_SetDisplayCredits(Credits, !FreePlayMode);
RPU_SetCoinLockout(false);
}
if (CurrentNumPlayers==1) Audio.StopAllAudio();
QueueNotification(SOUND_EFFECT_VP_ADD_PLAYER_1 + (CurrentNumPlayers - 1), 10);
RPU_WriteULToEEProm(RPU_TOTAL_PLAYS_EEPROM_START_BYTE, RPU_ReadULFromEEProm(RPU_TOTAL_PLAYS_EEPROM_START_BYTE) + 1);
return true;
}
unsigned short ChuteAuditByte[] = {RPU_CHUTE_1_COINS_START_BYTE, RPU_CHUTE_2_COINS_START_BYTE, RPU_CHUTE_3_COINS_START_BYTE};
void AddCoinToAudit(byte chuteNum) {
if (chuteNum>2) return;
unsigned short coinAuditStartByte = ChuteAuditByte[chuteNum];
RPU_WriteULToEEProm(coinAuditStartByte, RPU_ReadULFromEEProm(coinAuditStartByte) + 1);
}
void AddCredit(boolean playSound = false, byte numToAdd = 1) {
if (Credits < MaximumCredits) {
Credits += numToAdd;
if (Credits > MaximumCredits) Credits = MaximumCredits;
RPU_WriteByteToEEProm(RPU_CREDITS_EEPROM_BYTE, Credits);
if (playSound) {
//PlaySoundEffect(SOUND_EFFECT_ADD_CREDIT);
RPU_PushToSolenoidStack(SOL_KNOCKER, 20, true);
}
RPU_SetDisplayCredits(Credits, !FreePlayMode);
RPU_SetCoinLockout(false);
} else {
RPU_SetDisplayCredits(Credits, !FreePlayMode);
RPU_SetCoinLockout(true);
}
}
byte SwitchToChuteNum(byte switchHit) {
byte chuteNum = 0;
if (switchHit==SW_COIN_2) chuteNum = 1;
else if (switchHit==SW_COIN_3) chuteNum = 2;
return chuteNum;
}
boolean AddCoin(byte chuteNum) {
boolean creditAdded = false;
if (chuteNum>2) return false;
byte cpcSelection = GetCPCSelection(chuteNum);
// Find the lowest chute num with the same ratio selection
// and use that ChuteCoinsInProgress counter
byte chuteNumToUse;
for (chuteNumToUse=0; chuteNumToUse<=chuteNum; chuteNumToUse++) {
if (GetCPCSelection(chuteNumToUse)==cpcSelection) break;
}
PlaySoundEffect(SOUND_EFFECT_COIN_DROP_1+(CurrentTime%3));
byte cpcCoins = GetCPCCoins(cpcSelection);
byte cpcCredits = GetCPCCredits(cpcSelection);
byte coinProgressBefore = ChuteCoinsInProgress[chuteNumToUse];
ChuteCoinsInProgress[chuteNumToUse] += 1;
if (ChuteCoinsInProgress[chuteNumToUse]==cpcCoins) {
if (cpcCredits>cpcCoins) AddCredit(cpcCredits - (coinProgressBefore));
else AddCredit(cpcCredits);
ChuteCoinsInProgress[chuteNumToUse] = 0;
creditAdded = true;
} else {
if (cpcCredits>cpcCoins) {
AddCredit(1);
creditAdded = true;
} else {
}
}
return creditAdded;
}
void AddSpecialCredit() {
AddCredit(false, 1);
RPU_PushToTimedSolenoidStack(SOL_KNOCKER, 20, CurrentTime, true);
RPU_WriteULToEEProm(RPU_TOTAL_REPLAYS_EEPROM_START_BYTE, RPU_ReadULFromEEProm(RPU_TOTAL_REPLAYS_EEPROM_START_BYTE) + 1);
}
void AwardSpecial() {
if (SpecialCollected) return;
SpecialCollected = true;
if (TournamentScoring) {
CurrentScores[CurrentPlayer] += SpecialValue * PlayfieldMultiplier;
} else {
AddSpecialCredit();
}
}
boolean AwardExtraBall() {
if (ExtraBallCollected) return false;
ExtraBallCollected = true;
if (TournamentScoring) {
CurrentScores[CurrentPlayer] += ExtraBallValue * PlayfieldMultiplier;
} else {
SamePlayerShootsAgain = true;
RPU_SetLampState(LAMP_SHOOT_AGAIN, SamePlayerShootsAgain);
RPU_SetLampState(LAMP_HEAD_SAME_PLAYER_SHOOTS_AGAIN, SamePlayerShootsAgain);
QueueNotification(SOUND_EFFECT_VP_EXTRA_BALL, 8);
}
return true;
}
void IncreasePlayfieldMultiplier(unsigned long duration) {
if (PlayfieldMultiplierExpiration) PlayfieldMultiplierExpiration += duration;
else PlayfieldMultiplierExpiration = CurrentTime + duration;
PlayfieldMultiplier += 1;
if (PlayfieldMultiplier > 5) {
PlayfieldMultiplier = 5;
} else {
// QueueNotification(SOUND_EFFECT_VP_RETURN_TO_1X + (PlayfieldMultiplier - 1), 1);
}
}
/*
// Some example lock functionality
unsigned long UpperLockSwitchDownTime[3] = {0, 0, 0};
unsigned long UpperLockSwitchUpTime[3] = {0, 0, 0};
boolean UpperLockSwitchState[3] = {false, false, false};
void UpdateLockStatus() {
boolean lockSwitchDownTransition;
boolean lockSwitchUpTransition;
for (byte count=0; count<3; count++) {
lockSwitchDownTransition = false;
lockSwitchUpTransition = false;
if (RPU_ReadSingleSwitchState(SW_LOCK_1+count)) {
UpperLockSwitchUpTime[count] = 0;
if (UpperLockSwitchDownTime[count]==0) {
UpperLockSwitchDownTime[count] = CurrentTime;
} else if (CurrentTime > (UpperLockSwitchDownTime[count] + 250)) {
lockSwitchDownTransition = true;
}
} else {
UpperLockSwitchDownTime[count] = 0;
if (UpperLockSwitchUpTime[count]==0) {
UpperLockSwitchUpTime[count] = CurrentTime;
} else if (CurrentTime > (UpperLockSwitchUpTime[count] + 250)) {
lockSwitchUpTransition = true;
}
}
if (lockSwitchUpTransition && UpperLockSwitchState[count]) {