-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRPU_PinballPoolGameV82.ino
More file actions
3858 lines (3431 loc) · 153 KB
/
RPU_PinballPoolGameV82.ino
File metadata and controls
3858 lines (3431 loc) · 153 KB
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
/**************************************************************************
Pinball Pool Game 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 "PinballPoolGame.h"
#include "SelfTestAndAudit.h"
#include <EEPROM.h>
#define VERSION_NUMBER 82
#define DEBUG_MESSAGES 1
#define COIN_DOOR_TELEMETRY // If uncommented, coin door settings are sent to monitor on boot
#define IN_GAME_TELEMETRY // If uncommented, sends game status to monitor
#define EXECUTION_MESSAGES // If uncommented, sends game logic telemetry to monitor
#define USE_SCORE_OVERRIDES
#define USE_SCORE_ACHIEVEMENTS
// MachineState
// 0 - Attract Mode
// negative - self-test modes
// positive - game play
int 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_UNVALIDATED 3
#define MACHINE_STATE_NORMAL_GAMEPLAY 4
#define MACHINE_STATE_COUNTDOWN_BONUS 90
#define MACHINE_STATE_MATCH_MODE 95
#define MACHINE_STATE_BALL_OVER 100
#define MACHINE_STATE_GAME_OVER 110
//
// Adjustment machine states
//
// Display value
#define MACHINE_STATE_ADJUST_FREEPLAY -17 // 12
#define MACHINE_STATE_ADJUST_BALL_SAVE -18 // 13
#define MACHINE_STATE_ADJUST_CHASEBALL_DURATION -19 // 14
#define MACHINE_STATE_ADJUST_SPINNER_COMBO_DURATION -20 // 15
#define MACHINE_STATE_ADJUST_SPINNER_THRESHOLD -21 // 16
#define MACHINE_STATE_ADJUST_POP_THRESHOLD -22 // 17
#define MACHINE_STATE_ADJUST_NEXT_BALL_DURATION -23 // 18
#define MACHINE_STATE_ADJUST_TILT_WARNING -24 // 19
#define MACHINE_STATE_ADJUST_BALLS_OVERRIDE -25 // 20
#define MACHINE_STATE_ADJUST_DONE -26 // 21
//
// EEPROM Save Locations
//
#define EEPROM_FREE_PLAY_BYTE 100
#define EEPROM_BALL_SAVE_BYTE 101
#define EEPROM_CHASEBALL_DURATION_BYTE 102
#define EEPROM_SPINNER_COMBO_DURATION_BYTE 103
#define EEPROM_SPINNER_THRESHOLD_BYTE 104
#define EEPROM_POP_THRESHOLD_BYTE 105
#define EEPROM_NEXT_BALL_DURATION_BYTE 106
#define EEPROM_TILT_WARNING_BYTE 107
#define EEPROM_BALLS_OVERRIDE_BYTE 108
#define TIME_TO_WAIT_FOR_BALL 100
#define TILT_WARNING_DEBOUNCE_TIME 1500
//
// Sound Effects
//
#define SOUND_EFFECT_NONE 0
#define SOUND_EFFECT_ADD_PLAYER 1
#define SOUND_EFFECT_BALL_OVER 2
#define SOUND_EFFECT_GAME_OVER 3
#define SOUND_EFFECT_MACHINE_START 4
#define SOUND_EFFECT_ADD_CREDIT 5
#define SOUND_EFFECT_PLAYER_UP 6
#define SOUND_EFFECT_GAME_START 7
#define SOUND_EFFECT_EXTRA_BALL 8
#define SOUND_EFFECT_5K_CHIME 9
#define SOUND_EFFECT_BALL_CAPTURE 10
#define SOUND_EFFECT_POP_MODE 11
#define SOUND_EFFECT_POP_100 12
#define SOUND_EFFECT_POP_1000 13
#define SOUND_EFFECT_POP_1000b 14
#define SOUND_EFFECT_POP_1000c 15
#define SOUND_EFFECT_TILT_WARNING 16
#define SOUND_EFFECT_TILTED 17
#define SOUND_EFFECT_10_PTS 18
#define SOUND_EFFECT_100_PTS 19
#define SOUND_EFFECT_1000_PTS 20
#define SOUND_EFFECT_EXTRA 21
#define SOUND_EFFECT_SPINNER_COMBO 22
#define SOUND_EFFECT_KICKER_OUTLANE 23
#define SOUND_EFFECT_8_BALL_CAPTURE 24
#define SOUND_EFFECT_BALL_LOSS 25
//
// Game/machine global variables
//
unsigned long HighScore = 0;
unsigned long AwardScores[3]; // Score thresholds for awards
int Credits = 0;
int MaximumCredits = 20;
boolean FreePlayMode = false;
boolean MatchFeature = true; // Allows Match Feature to run
#define MAX_TILT_WARNINGS_MAX 2
#define MAX_TILT_WARNINGS_DEF 1 // Length of each segment
byte MaxTiltWarnings = MAX_TILT_WARNINGS_DEF;
byte NumTiltWarnings = 0;
unsigned long LastTiltWarningTime = 0;
boolean Tilted = false;
byte CurrentPlayer = 0;
byte CurrentBallInPlay = 1;
byte CurrentNumPlayers = 0;
unsigned long CurrentScores[4];
boolean SamePlayerShootsAgain = false;
byte CurrentAchievements[4]; // Score achievments
unsigned long CurrentTime = 0;
unsigned long BallTimeInTrough = 0;
unsigned long BallFirstSwitchHitTime = 0;
boolean BallSaveUsed = false;
#define BALLSAVENUMSECONDS_MAX 20
#define BALLSAVENUMSECONDS_DEF 0
byte BallSaveNumSeconds = BALLSAVENUMSECONDS_DEF;
#define BALLSPERGAME_MAX 5
#define BALLSPERGAME_DEF 3
#define BALLSPERGAME_MIN 3
byte BallsPerGame = BALLSPERGAME_DEF;
boolean HighScoreReplay = true;
byte Ten_Pts_Stack = 0;
byte Hundred_Pts_Stack = 0;
byte Thousand_Pts_Stack = 0;
int Silent_Thousand_Pts_Stack = 0;
byte Silent_Hundred_Pts_Stack = 0;
unsigned long ChimeScoringDelay = 0;
// Animation variables
boolean MarqueeDisabled = false;
// Attract mode variables
// byte AttractHeadMode = 255;
byte AttractPlayfieldMode = 255;
unsigned long AttractSweepTime = 0;
byte AttractSweepLights = 1;
int SpiralIncrement = 0;
unsigned long RackDelayLength = 850;
unsigned long AttractStepTime = 0;
byte AttractStepLights = 0;
// Display variables
int CreditsDispValue = 0; // Value to be displayed in Credit window
byte CreditsFlashing = false; // Allow credits display to flash if true
int BIPDispValue = 0; // Value to be displayed in Ball In Play window
byte BIPFlashing = false; // Allow BIP display to flash if true
#define OVERRIDE_PRIORITY_NEXTBALL 10
#define OVERRIDE_PRIORITY_SPINNERCOMBO 20
#define OVERRIDE_PRIORITY_CHASEBALLMODE3 30
byte OverrideScorePriority = 0; // Priority of score overrides
//
// Global game logic variables
//
byte GameMode[4] = {1,1,1,1}; // GameMode=1 normal play, GameMode=2 15 ball mode
byte FifteenBallCounter[4] = {0,0,0,0}; // Track how long in 15-Ball mode
unsigned long CheckBallTime = 0; // Debug timing variable
boolean FifteenBallQualified[4]; // Set to true when all goals are met
byte ChaseBall = 0; // Game Mode 3 target ball
byte ChaseBallStage = 0; // Counter of Ball captured in Game Mode 3
unsigned long ChaseBallTimeStart = 0; // Timer for ChaseBall
#define CHASEBALL_DURATION_MAX 31
#define CHASEBALL_DURATION_DEF 25 // Length of each segment
#define CHASEBALL_DURATION_MIN 19
byte ChaseBallDuration = CHASEBALL_DURATION_DEF; // Length of each segment (seconds)
byte BankShotProgress = 0; // Track what Bank Shot step we are on
boolean SuperBonusLit = false; // True if we have achieved rack of 8 balls
boolean EightBallTest[4] = {true,true,true,true}; // One time check per player.
unsigned long BankShotOffTime = 0;
unsigned long MarqueeOffTime = 0;
byte MarqueeMultiple = 0;
boolean SpinnerKickerLit = false; // Triggers spinner light and scoring, sets kicker on
unsigned long KickerOffTime = 0; // Delayed off time for Kicker
boolean KickerReady = false;
boolean KickerUsed = true;
unsigned int SpinnerCount[4] = {0,0,0,0}; // Spinner counter
byte SpinnerMode[4] = {0,0,0,0}; // Spinner mode threshold
unsigned long SuperSpinnerTime = 0; // Start of SuperSpinner mode
unsigned long SuperSpinnerDuration = 0; // Length of SuperSpinner mode once triggered
#define SPINNER_COMBO_DURATION_MAX 16
#define SPINNER_COMBO_DURATION_DEF 12 // Default for EEPROM settings - sec
#define SPINNER_COMBO_DURATION_MIN 8
byte Spinner_Combo_Duration = SPINNER_COMBO_DURATION_DEF; // Duration in seconds
boolean SuperSpinnerAllowed[4] = {false, false, false, false}; // Locks out SuperSpinner mode
boolean SpinnerComboHalf = false; // True if BankShot half of combo is hit
unsigned int SpinnerDelta = 0;
#define SPINNER_THRESHOLD_MAX 70
#define SPINNER_THRESHOLD_DEF 50 // Default for EEPROM settings - spins
#define SPINNER_THRESHOLD_MIN 30
byte Spinner_Threshold = SPINNER_THRESHOLD_DEF; // Spinner hits to achieve mode - 50
unsigned int PopCount[4] = {0,0,0,0}; // Pop bumper counter
byte PopMode[4] = {0,0,0,0}; // Pop bumper scoring threshold
unsigned int PopDelta = 0;
#define POP_THRESHOLD_MAX 50
#define POP_THRESHOLD_DEF 40 // Default for EEPROM settings - hits
#define POP_THRESHOLD_MIN 30
byte Pop_Threshold = POP_THRESHOLD_DEF; // Pop bumper hits to achieve mode - 40
boolean ArrowsLit[4] = {false,false,false,false}; // True when lanes 1-4 are collected
boolean ArrowTest = true; // One time check flag
boolean RightArrow = false; // Always start with Right arrow
unsigned int Balls[4]={0,0,0,0}; // Ball status
byte Goals[4]={0,0,0,0};
boolean GoalsDisplayToggle; // Display achieved goals if true
boolean OutlaneSpecial[4] = {false,false,false,false}; // True when Balls 1 thru 7 are collected, then 8 ball collected
byte BonusMult = 1; // Bonus multiplier, defaults to 1X
boolean BonusMultTenX = false; // Set when 10X achieved
#define NEXT_BALL_DURATION_MAX 19
#define NEXT_BALL_DURATION_DEF 15 // Default for EEPROM settings - sec
#define NEXT_BALL_DURATION_MIN 11
byte NextBallDuration = NEXT_BALL_DURATION_DEF; // Length in msec next ball award is available
unsigned long NextBallTime = 0;
byte NextBall=0; // Keeps track of ball after current one being captured
byte MatchDigit = 0; // Relocated to make global
//
// Function prototypes
//
// Default is Speed=100, CW=true
void MarqueeAttract(byte Segment, int Speed=100, boolean CW=true);
void BankShotScoring(byte Sound=1);
void FlashingArrows(int lamparray[], int rate, int numlamps=6);
void setup() {
if (DEBUG_MESSAGES) {
Serial.begin(115200);
}
// Tell the OS about game-specific lights and switches
RPU_SetupGameSwitches(NUM_SWITCHES_WITH_TRIGGERS, NUM_PRIORITY_SWITCHES_WITH_TRIGGERS, TriggeredSwitches);
if (DEBUG_MESSAGES) {
Serial.write("Attempting to initialize the MPU\n");
}
// Set up the chips and interrupts
RPU_InitializeMPU();
RPU_DisableSolenoidStack();
RPU_SetDisableFlippers(true);
// Read parameters from EEProm
ReadStoredParameters();
RPU_SetCoinLockout((Credits >= MaximumCredits) ? true : false);
byte dipBank = RPU_GetDipSwitches(0);
// Use dip switches to set up game variables
if (DEBUG_MESSAGES) {
char buf[32];
sprintf(buf, "DipBank 0 = 0x%02X\n", dipBank);
Serial.write(buf);
}
/*
HighScore = RPU_ReadULFromEEProm(RPU_HIGHSCORE_EEPROM_START_BYTE, 10000);
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);
*/
Credits = RPU_ReadByteFromEEProm(RPU_CREDITS_EEPROM_BYTE);
if (Credits>MaximumCredits) Credits = MaximumCredits;
//BallsPerGame = 3;
// Play Machine start tune - Have to set CurrentTime as we are not yet in the loop structure
CurrentTime = millis();
PlaySoundEffect(SOUND_EFFECT_MACHINE_START);
// Display SW Version
CurrentNumPlayers = 1;
CurrentScores[0] = VERSION_NUMBER;
//CurrentScores[0] = 1234567;
if (DEBUG_MESSAGES) {
Serial.write("Done with setup\n");
}
}
void ReadStoredParameters() {
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, BALLSAVENUMSECONDS_DEF);
if (BallSaveNumSeconds == 99) { // If set to 99
BallSaveNumSeconds = BALLSAVENUMSECONDS_DEF; // Set to default
EEPROM.write(EEPROM_BALL_SAVE_BYTE, BALLSAVENUMSECONDS_DEF); // Write to EEPROM
}
if (BallSaveNumSeconds > BALLSAVENUMSECONDS_MAX) BallSaveNumSeconds = BALLSAVENUMSECONDS_MAX;
MaxTiltWarnings = ReadSetting(EEPROM_TILT_WARNING_BYTE, MAX_TILT_WARNINGS_DEF);
if (MaxTiltWarnings == 99) { // If set to 99
MaxTiltWarnings = MAX_TILT_WARNINGS_DEF; // Set to default
EEPROM.write(EEPROM_TILT_WARNING_BYTE, MAX_TILT_WARNINGS_DEF); // Write to EEPROM
}
if (MaxTiltWarnings > MAX_TILT_WARNINGS_MAX) MaxTiltWarnings = MAX_TILT_WARNINGS_MAX;
BallsPerGame = ReadSetting(EEPROM_BALLS_OVERRIDE_BYTE, BALLSPERGAME_DEF);
if (BallsPerGame == 99) { // If set to 99
BallsPerGame = BALLSPERGAME_DEF; // Set to default
EEPROM.write(EEPROM_BALLS_OVERRIDE_BYTE, BALLSPERGAME_DEF); // Write to EEPROM
}
if (BallsPerGame > BALLSPERGAME_MAX) BallsPerGame = BALLSPERGAME_MAX;
if (BallsPerGame < BALLSPERGAME_MIN) BallsPerGame = BALLSPERGAME_MIN;
ChaseBallDuration = ReadSetting(EEPROM_CHASEBALL_DURATION_BYTE, CHASEBALL_DURATION_DEF);
if (ChaseBallDuration == 99) { // If set to 99
ChaseBallDuration = CHASEBALL_DURATION_DEF; // Set to default
EEPROM.write(EEPROM_CHASEBALL_DURATION_BYTE, CHASEBALL_DURATION_DEF); // Write to EEPROM
}
if (ChaseBallDuration > CHASEBALL_DURATION_MAX) ChaseBallDuration = CHASEBALL_DURATION_MAX;
if (ChaseBallDuration < CHASEBALL_DURATION_MIN) ChaseBallDuration = CHASEBALL_DURATION_MIN;
Spinner_Combo_Duration = ReadSetting(EEPROM_SPINNER_COMBO_DURATION_BYTE, SPINNER_COMBO_DURATION_DEF);
if (Spinner_Combo_Duration == 99) { // If set to 99
Spinner_Combo_Duration = SPINNER_COMBO_DURATION_DEF; // Set to default
EEPROM.write(EEPROM_SPINNER_COMBO_DURATION_BYTE, SPINNER_COMBO_DURATION_DEF); // Write to EEPROM
}
if (Spinner_Combo_Duration > SPINNER_COMBO_DURATION_MAX) Spinner_Combo_Duration = SPINNER_COMBO_DURATION_MAX;
if (Spinner_Combo_Duration < SPINNER_COMBO_DURATION_MIN) Spinner_Combo_Duration = SPINNER_COMBO_DURATION_MIN;
Spinner_Threshold = ReadSetting(EEPROM_SPINNER_THRESHOLD_BYTE, SPINNER_THRESHOLD_DEF);
if (Spinner_Threshold == 99) { // If set to 99
Spinner_Threshold = SPINNER_THRESHOLD_DEF; // Set to default
EEPROM.write(EEPROM_SPINNER_THRESHOLD_BYTE, SPINNER_THRESHOLD_DEF); // Write to EEPROM
}
if (Spinner_Threshold > SPINNER_THRESHOLD_MAX) Spinner_Threshold = SPINNER_THRESHOLD_MAX;
if (Spinner_Threshold < SPINNER_THRESHOLD_MIN) Spinner_Threshold = SPINNER_THRESHOLD_MIN;
Pop_Threshold = ReadSetting(EEPROM_POP_THRESHOLD_BYTE, POP_THRESHOLD_DEF);
if (Pop_Threshold == 99) { // If set to 99
Pop_Threshold = POP_THRESHOLD_DEF; // Set to default
EEPROM.write(EEPROM_POP_THRESHOLD_BYTE, POP_THRESHOLD_DEF); // Write to EEPROM
}
if (Pop_Threshold > POP_THRESHOLD_MAX) Pop_Threshold = POP_THRESHOLD_MAX;
if (Pop_Threshold < POP_THRESHOLD_MIN) Pop_Threshold = POP_THRESHOLD_MIN;
NextBallDuration = ReadSetting(EEPROM_NEXT_BALL_DURATION_BYTE, NEXT_BALL_DURATION_DEF);
if (NextBallDuration == 99) { // If set to 99
NextBallDuration = NEXT_BALL_DURATION_DEF; // Set to default
EEPROM.write(EEPROM_NEXT_BALL_DURATION_BYTE, NEXT_BALL_DURATION_DEF); // Write to EEPROM
}
if (NextBallDuration > NEXT_BALL_DURATION_MAX) NextBallDuration = NEXT_BALL_DURATION_MAX;
if (NextBallDuration < NEXT_BALL_DURATION_MIN) NextBallDuration = NEXT_BALL_DURATION_MIN;
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);
}
byte ReadSetting(byte setting, byte defaultValue) {
byte value = EEPROM.read(setting);
if (value == 0xFF) {
EEPROM.write(setting, defaultValue);
return defaultValue;
}
return value;
}
//
// ShowLampAnimation - Ver 2
// Ver 1 - Modified from version in Meteor
// Ver 2 - Altered to enable use of Aux board lamps
//
void ShowLampAnimation(byte animationNum[][8], byte frames, unsigned long divisor,
unsigned long baseTime, byte subOffset, boolean dim, boolean reverse = false,
byte keepLampOn = 99, boolean AuxLamps = false) {
byte currentStep = (baseTime / divisor) % frames;
if (reverse) currentStep = (frames - 1) - currentStep;
byte lampNum = 0;
for (int byteNum = 0; byteNum < ((AuxLamps)?2:8); byteNum++) {
// for (int byteNum = 0; byteNum < 8; byteNum++) {
for (byte bitNum = 0; bitNum < 8; bitNum++) {
// if there's a subOffset, turn off lights at that offset
if (subOffset) {
byte lampOff = true;
lampOff = animationNum[(currentStep + subOffset) % frames][byteNum] & (1 << bitNum);
if (lampOff && lampNum != keepLampOn) RPU_SetLampState((lampNum + ((AuxLamps)?60:0) ), 0);
// if (lampOff && lampNum != keepLampOn) RPU_SetLampState(lampNum, 0);
}
byte lampOn = false;
lampOn = animationNum[currentStep][byteNum] & (1 << bitNum);
if (lampOn) RPU_SetLampState((lampNum + ((AuxLamps)?60:0)), 1, dim);
// if (lampOn) RPU_SetLampState(lampNum, 1, dim);
lampNum += 1;
}
#if not defined (BALLY_STERN_OS_SOFTWARE_DISPLAY_INTERRUPT)
if (byteNum % 2) RPU_DataRead(0);
#endif
}
}
// Mata Hari version - includes setting of game player lamps on backglass
//
// PLAYER_x_UP are the lamps adjacent to each display
// PLAYER_X are the lamps at bottom left of backglass indicating how many player game is running
//
void SetPlayerLamps(byte numPlayers, byte playerOffset = 0, int flashPeriod = 0) {
// For Mata Hari, the "Player Up" lights are all +4 of the "Player" lights
// so this function covers both sets of lights. Putting a 4 in playerOffset
// will turn on/off the player up lights.
// Offset of 0 means lower backglass lamps, offset of 4 mean player lamps next to the score displays
for (int count = 0; count < 4; count++) {
RPU_SetLampState(LA_1_PLAYER + playerOffset + count, (numPlayers == (count + 1)) ? 1 : 0, 0, flashPeriod);
}
}
//Meteor version - updates audit EEPROM memory locations
void AddCoinToAudit(byte switchHit) {
unsigned short coinAuditStartByte = 0;
switch (switchHit) {
case SW_COIN_3: coinAuditStartByte = RPU_CHUTE_3_COINS_START_BYTE; break;
case SW_COIN_2: coinAuditStartByte = RPU_CHUTE_2_COINS_START_BYTE; break;
case SW_COIN_1: coinAuditStartByte = RPU_CHUTE_1_COINS_START_BYTE; break;
}
if (coinAuditStartByte) {
RPU_WriteULToEEProm(coinAuditStartByte, RPU_ReadULFromEEProm(coinAuditStartByte) + 1);
}
}
// Mata Hari version (and Meteor)
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);
CreditsDispValue = Credits;
//RPU_SetDisplayCredits(Credits);
RPU_SetCoinLockout(false);
} else {
CreditsDispValue = Credits;
//RPU_SetDisplayCredits(Credits);
RPU_SetCoinLockout(true);
}
}
void AddSpecialCredit() {
AddCredit(false, 1);
RPU_PushToTimedSolenoidStack(SOL_KNOCKER, 3, CurrentTime, true);
RPU_WriteULToEEProm(RPU_TOTAL_REPLAYS_EEPROM_START_BYTE, RPU_ReadULFromEEProm(RPU_TOTAL_REPLAYS_EEPROM_START_BYTE) + 1);
}
// Meteor version - uses updated function call in Attract Mode to allow game start following a
// a 4 player game
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);
RPU_SetDisplayBlank(CurrentNumPlayers - 1, 0x30);
if (!FreePlayMode) {
Credits -= 1;
RPU_WriteByteToEEProm(RPU_CREDITS_EEPROM_BYTE, Credits);
CreditsDispValue = Credits;
//RPU_SetDisplayCredits(Credits);
RPU_SetCoinLockout(false);
}
if (CurrentNumPlayers > 1){
PlaySoundEffect(SOUND_EFFECT_ADD_PLAYER);
}
//Serial.println(F("AddPlayer - SetPlayerLamps(CurrentNumPlayers)"));
SetPlayerLamps(CurrentNumPlayers);
RPU_WriteULToEEProm(RPU_TOTAL_PLAYS_EEPROM_START_BYTE, RPU_ReadULFromEEProm(RPU_TOTAL_PLAYS_EEPROM_START_BYTE) + 1);
return true;
}
int InitNewBall(bool curStateChanged, byte playerNum, int ballNum) {
if (curStateChanged) {
//
// Set pre-ball conditions & variables
//
Serial.println(F("----------InitNewBall----------"));
CheckBallTime = CurrentTime;
BallFirstSwitchHitTime = 0;
MarqueeOffTime = 0;
CreditsDispValue = Credits;
SetPlayerLamps(playerNum+1, 4, 500);
NumTiltWarnings = 0;
LastTiltWarningTime = 0;
Tilted = false;
BallSaveUsed = false;
if (BallSaveNumSeconds>0) {
RPU_SetLampState(SAME_PLAYER, 1, 0, 500);
}
ArrowTest = true;
RPU_SetLampState(LA_LEFT_ARROW, 0); // Reset arrows
RPU_SetLampState(LA_RIGHT_ARROW, 0); // Reset arrows
SpinnerKickerLit = false;
KickerUsed = true;
KickerReady = false;
SuperSpinnerTime = 0;
SuperSpinnerDuration = Spinner_Combo_Duration;
SpinnerComboHalf = false;
SpinnerDelta = 0;
PopDelta = 0;
NextBallTime = 0;
NextBall = 0;
RPU_SetLampState(LA_SPINNER, 0); // Spinner and Kicker are off at beginning of a new ball
BankShotProgress = 0; // Reset Bank shot for each ball
BankShotLighting(); // Set Lights for ball start
BonusMultiplier(1); // Reset bonus multiplier and lights
BonusMultTenX = false; // Reset flag
Ten_Pts_Stack = 0; // Reset Scoring variables
Hundred_Pts_Stack = 0;
Thousand_Pts_Stack = 0;
Silent_Thousand_Pts_Stack = 0;
Silent_Hundred_Pts_Stack = 0;
ChimeScoringDelay = 0;
//
// Chase Ball - Mode 3
//
ChaseBall = 0; // Game Mode 3 target ball
ChaseBallStage = 0; // Counter of Ball captured in Game Mode 3
ChaseBallTimeStart = 0; // Timer for ChaseBall
//
// SuperBonus
//
if (OutlaneSpecial[CurrentPlayer] == false) {
RPU_SetLampState(LA_OUTLANE_SPECIAL, 0); // Turn off lamp
} else {
RPU_SetLampState(LA_OUTLANE_SPECIAL, 1); // If current player is true, turn on lamp
}
if (GameMode[CurrentPlayer] == 1) {
RPU_SetLampState(LA_SUPER_BONUS, 0); // Turn off SuperBonus lamp
if (Balls[CurrentPlayer] & (0b1<<15)) { // If player already has SuperBonus
RPU_SetLampState(LA_SUPER_BONUS, 1); // Turn on SuperBonus lamp
}
if ((Balls[CurrentPlayer] & (0b1<<7)) == 128) { // If 8 ball collected, we have achieved SuperBonus
RPU_SetLampState(LA_SUPER_BONUS, 1); // Turn on SuperBonus lamp
Balls[CurrentPlayer] = 0x8000; // Wipe out all collected balls, set SuperBonus
SetGoals(1); // Duplicate of above
EightBallTest[CurrentPlayer] = true; // Reset to enable getting 8 ball again
if (!OutlaneSpecial[CurrentPlayer]) { // Achieving SuperBonus turns on Outlane Special
OutlaneSpecial[CurrentPlayer] = true;
RPU_SetLampState(LA_OUTLANE_SPECIAL, 1); // Turn lamp on, signifying mode is active
}
ArrowsLit[CurrentPlayer] = false;
}
}
//
// 15 Ball Mode
//
if (GameMode[CurrentPlayer] == 2) { // if 15 Ball mode already active
FifteenBallCounter[CurrentPlayer] += 1;
RPU_SetLampState(LA_SUPER_BONUS, 1, 0, 750); // Turn on slow blink for Mode 2
}
if (FifteenBallCounter[CurrentPlayer] > 2) { // Maximum balls in Mode 2
GameMode[CurrentPlayer] = 1; // Reset to Mode 1
FifteenBallCounter[CurrentPlayer] = 0; // Reset counter
Balls[CurrentPlayer] = 0; // Reset all balls plus SuperBonus
Goals[CurrentPlayer] = 0; // Reset all goals
PopMode[CurrentPlayer] = 0; // Reset
PopCount[CurrentPlayer] = 0; // Reset
SpinnerMode[CurrentPlayer] = 0; // Reset
SpinnerCount[CurrentPlayer] = 0; // Reset
CurrentScores[CurrentPlayer] = CurrentScores[CurrentPlayer]/10*10; // Remove goals
RPU_SetLampState(LA_SUPER_BONUS, 0); // Turn off
}
if (FifteenBallQualified[CurrentPlayer]) {
FifteenBallQualified[CurrentPlayer] = false; // Turn off
GameMode[CurrentPlayer] = 2; // Set Game Mode to 15 Ball
Balls[CurrentPlayer] = 0; // Reset all balls plus SuperBonus
RPU_SetLampState(LA_SUPER_BONUS, 1, 0, 750); // Turn on slow blink for Mode 2
EightBallTest[CurrentPlayer] = false; // Turn off for Mode 2
ArrowsLit[CurrentPlayer] = false; // Turn off
FifteenBallCounter[CurrentPlayer] = 1; // Set to 1
}
SamePlayerShootsAgain = false;
RPU_SetLampState(SAME_PLAYER, 0);
RPU_SetLampState(LA_SPSA_BACK, 0);
RPU_SetDisableFlippers(false);
RPU_EnableSolenoidStack();
MarqueeDisabled = false; // In case SetGoals turned this off.
//Serial.println("InitNewBall - BallLighting");
BallLighting(); // Relight rack balls already collected
if (RPU_ReadSingleSwitchState(SW_OUTHOLE)) {
RPU_PushToTimedSolenoidStack(SOL_OUTHOLE, 4, CurrentTime + 100);
}
//ShowPlayerScores(0xFF, false, false); // Show player scores
for (int count=0; count<CurrentNumPlayers; count++) {
RPU_SetDisplay(count, CurrentScores[count], true, 2);
}
BIPDispValue = ballNum;
RPU_SetLampState(BALL_IN_PLAY, 1);
RPU_SetLampState(TILT, 0);
CreditsFlashing = false; // credits display on steady
BIPFlashing = false; // BIP display on steady
OverrideScorePriority = 0; // Set to default
}
// We should only consider the ball initialized when
// the ball is no longer triggering the SW_OUTHOLE
if (RPU_ReadSingleSwitchState(SW_OUTHOLE)) {
//Serial.println(F("--InitNewBall, ball still in outhole--"));
return MACHINE_STATE_INIT_NEW_BALL;
} else {
return MACHINE_STATE_NORMAL_GAMEPLAY;
}
}
////////////////////////////////////////////////////////////////////////////
//
// Self test, audit, adjustments mode
//
////////////////////////////////////////////////////////////////////////////
#define ADJ_TYPE_LIST 1
#define ADJ_TYPE_MIN_MAX 2
#define ADJ_TYPE_MIN_MAX_DEFAULT 3
#define ADJ_TYPE_SCORE 4
#define ADJ_TYPE_SCORE_WITH_DEFAULT 5
#define ADJ_TYPE_SCORE_NO_DEFAULT 6
byte AdjustmentType = 0;
byte NumAdjustmentValues = 0;
byte AdjustmentValues[8];
unsigned long AdjustmentScore;
byte *CurrentAdjustmentByte = NULL;
unsigned long *CurrentAdjustmentUL = NULL;
byte CurrentAdjustmentStorageByte = 0;
byte TempValue = 0;
int RunSelfTest(int curState, boolean curStateChanged) {
int returnState = curState;
CurrentNumPlayers = 0;
#if 0
if (curStateChanged) {
// Send a stop-all command and reset the sample-rate offset, in case we have
// reset while the WAV Trigger was already playing.
StopAudio();
PlaySoundEffect(SOUND_EFFECT_SELF_TEST_MODE_START-curState, 0);
} else {
if (SoundSettingTimeout && CurrentTime>SoundSettingTimeout) {
SoundSettingTimeout = 0;
StopAudio();
}
}
#endif
// Any state that's greater than CHUTE_3 is handled by the Base Self-test code
// Any that's less, is machine specific, so we handle it here.
if (curState >= MACHINE_STATE_TEST_CHUTE_3_COINS) {
returnState = RunBaseSelfTest(returnState, curStateChanged, CurrentTime, SW_CREDIT_RESET, SW_SLAM);
} else {
byte curSwitch = RPU_PullFirstFromSwitchStack();
if (curSwitch == SW_SELF_TEST_SWITCH && (CurrentTime - GetLastSelfTestChangedTime()) > 250) {
SetLastSelfTestChangedTime(CurrentTime);
returnState -= 1;
}
if (curSwitch == SW_SLAM) {
returnState = MACHINE_STATE_ATTRACT;
}
if (curStateChanged) {
for (int count = 0; count < 4; count++) {
RPU_SetDisplay(count, 0);
RPU_SetDisplayBlank(count, 0x00);
}
Serial.print(F("Current Machine State is: "));
Serial.println(curState, DEC);
RPU_SetDisplayCredits(MACHINE_STATE_TEST_SOUNDS - curState);
RPU_SetDisplayBallInPlay(0, false);
CurrentAdjustmentByte = NULL;
CurrentAdjustmentUL = NULL;
CurrentAdjustmentStorageByte = 0;
AdjustmentType = ADJ_TYPE_MIN_MAX;
AdjustmentValues[0] = 0;
AdjustmentValues[1] = 1;
TempValue = 0;
switch (curState) {
case MACHINE_STATE_ADJUST_FREEPLAY:
CurrentAdjustmentByte = (byte *)&FreePlayMode;
CurrentAdjustmentStorageByte = EEPROM_FREE_PLAY_BYTE;
break;
case MACHINE_STATE_ADJUST_BALL_SAVE:
AdjustmentType = ADJ_TYPE_LIST;
NumAdjustmentValues = 6;
AdjustmentValues[1] = 5;
AdjustmentValues[2] = 10;
AdjustmentValues[3] = 15;
AdjustmentValues[4] = 20;
AdjustmentValues[5] = 99;
CurrentAdjustmentByte = &BallSaveNumSeconds;
CurrentAdjustmentStorageByte = EEPROM_BALL_SAVE_BYTE;
break;
case MACHINE_STATE_ADJUST_CHASEBALL_DURATION:
AdjustmentType = ADJ_TYPE_LIST;
NumAdjustmentValues = 6;
AdjustmentValues[0] = 19;
AdjustmentValues[1] = 22;
AdjustmentValues[2] = 25;
AdjustmentValues[3] = 28;
AdjustmentValues[4] = 31;
AdjustmentValues[5] = 99;
CurrentAdjustmentByte = &ChaseBallDuration;
CurrentAdjustmentStorageByte = EEPROM_CHASEBALL_DURATION_BYTE;
break;
case MACHINE_STATE_ADJUST_SPINNER_COMBO_DURATION:
AdjustmentType = ADJ_TYPE_LIST;
NumAdjustmentValues = 6;
AdjustmentValues[0] = 8;
AdjustmentValues[1] = 10;
AdjustmentValues[2] = 12;
AdjustmentValues[3] = 14;
AdjustmentValues[4] = 16;
AdjustmentValues[5] = 99;
CurrentAdjustmentByte = &Spinner_Combo_Duration;
CurrentAdjustmentStorageByte = EEPROM_SPINNER_COMBO_DURATION_BYTE;
break;
case MACHINE_STATE_ADJUST_SPINNER_THRESHOLD:
AdjustmentType = ADJ_TYPE_LIST;
NumAdjustmentValues = 6;
AdjustmentValues[0] = 30;
AdjustmentValues[1] = 40;
AdjustmentValues[2] = 50;
AdjustmentValues[3] = 60;
AdjustmentValues[4] = 70;
AdjustmentValues[5] = 99;
CurrentAdjustmentByte = &Spinner_Threshold;
CurrentAdjustmentStorageByte = EEPROM_SPINNER_THRESHOLD_BYTE;
break;
case MACHINE_STATE_ADJUST_POP_THRESHOLD:
AdjustmentType = ADJ_TYPE_LIST;
NumAdjustmentValues = 6;
AdjustmentValues[0] = 30;
AdjustmentValues[1] = 35;
AdjustmentValues[2] = 40;
AdjustmentValues[3] = 45;
AdjustmentValues[4] = 50;
AdjustmentValues[5] = 99;
CurrentAdjustmentByte = &Pop_Threshold;
CurrentAdjustmentStorageByte = EEPROM_POP_THRESHOLD_BYTE;
break;
case MACHINE_STATE_ADJUST_NEXT_BALL_DURATION:
AdjustmentType = ADJ_TYPE_LIST;
NumAdjustmentValues = 6;
AdjustmentValues[0] = 11;
AdjustmentValues[1] = 13;
AdjustmentValues[2] = 15;
AdjustmentValues[3] = 17;
AdjustmentValues[4] = 19;
AdjustmentValues[5] = 99;
CurrentAdjustmentByte = &NextBallDuration;
CurrentAdjustmentStorageByte = EEPROM_NEXT_BALL_DURATION_BYTE;
break;
case MACHINE_STATE_ADJUST_TILT_WARNING:
AdjustmentType = ADJ_TYPE_LIST;
NumAdjustmentValues = 4;
AdjustmentValues[0] = 0;
AdjustmentValues[1] = 1;
AdjustmentValues[2] = 2;
AdjustmentValues[3] = 99;
CurrentAdjustmentByte = &MaxTiltWarnings;
CurrentAdjustmentStorageByte = EEPROM_TILT_WARNING_BYTE;
break;
case MACHINE_STATE_ADJUST_BALLS_OVERRIDE:
AdjustmentType = ADJ_TYPE_LIST;
NumAdjustmentValues = 3;
AdjustmentValues[0] = 3;
AdjustmentValues[1] = 5;
AdjustmentValues[2] = 99;
CurrentAdjustmentByte = &BallsPerGame;
CurrentAdjustmentStorageByte = EEPROM_BALLS_OVERRIDE_BYTE;
break;
case MACHINE_STATE_ADJUST_DONE:
returnState = MACHINE_STATE_ATTRACT;
break;
}
}
// Change value, if the switch is hit
if (curSwitch == SW_CREDIT_RESET) {
if (CurrentAdjustmentByte && (AdjustmentType == ADJ_TYPE_MIN_MAX || AdjustmentType == ADJ_TYPE_MIN_MAX_DEFAULT)) {
byte curVal = *CurrentAdjustmentByte;
curVal += 1;
if (curVal > AdjustmentValues[1]) {
if (AdjustmentType == ADJ_TYPE_MIN_MAX) curVal = AdjustmentValues[0];
else {
if (curVal > 99) curVal = AdjustmentValues[0];
else curVal = 99;
}
}
*CurrentAdjustmentByte = curVal;
if (CurrentAdjustmentStorageByte) EEPROM.write(CurrentAdjustmentStorageByte, curVal);
/*
if (curState==MACHINE_STATE_ADJUST_SFX_AND_SOUNDTRACK) {
StopAudio();
PlaySoundEffect(SOUND_EFFECT_SELF_TEST_AUDIO_OPTIONS_START+curVal, 0);
if (curVal>=3) SoundtrackSelection = curVal-3;
} else if (curState==MACHINE_STATE_ADJUST_MUSIC_VOLUME) {
if (SoundSettingTimeout) StopAudio();
PlayBackgroundSong(MusicIndices[SoundtrackSelection][4] + RALLY_MUSIC_WAITING_FOR_SKILLSHOT);
SoundSettingTimeout = CurrentTime+5000;
} else if (curState==MACHINE_STATE_ADJUST_SFX_VOLUME) {
if (SoundSettingTimeout) StopAudio();
PlaySoundEffect(SOUND_EFFECT_GALAXY_LETTER_AWARD, ConvertVolumeSettingToGain(SoundEffectsVolume));
SoundSettingTimeout = CurrentTime+5000;
} else if (curState==MACHINE_STATE_ADJUST_CALLOUTS_VOLUME) {
if (SoundSettingTimeout) StopAudio();
PlaySoundEffect(SOUND_EFFECT_VP_SKILL_SHOT_1, ConvertVolumeSettingToGain(CalloutsVolume));
SoundSettingTimeout = CurrentTime+3000;
}*/
} else if (CurrentAdjustmentByte && AdjustmentType == ADJ_TYPE_LIST) {
byte valCount = 0;
byte curVal = *CurrentAdjustmentByte;
byte newIndex = 0;
for (valCount = 0; valCount < (NumAdjustmentValues - 1); valCount++) {
if (curVal == AdjustmentValues[valCount]) newIndex = valCount + 1;
}
*CurrentAdjustmentByte = AdjustmentValues[newIndex];
if (CurrentAdjustmentStorageByte) EEPROM.write(CurrentAdjustmentStorageByte, AdjustmentValues[newIndex]);
} else if (CurrentAdjustmentUL && (AdjustmentType == ADJ_TYPE_SCORE_WITH_DEFAULT || AdjustmentType == ADJ_TYPE_SCORE_NO_DEFAULT)) {
unsigned long curVal = *CurrentAdjustmentUL;
curVal += 5000;
if (curVal > 100000) curVal = 0;
if (AdjustmentType == ADJ_TYPE_SCORE_NO_DEFAULT && curVal == 0) curVal = 5000;
*CurrentAdjustmentUL = curVal;
if (CurrentAdjustmentStorageByte) RPU_WriteULToEEProm(CurrentAdjustmentStorageByte, curVal);
}
/*
if (curState == MACHINE_STATE_ADJUST_DIM_LEVEL) {
RPU_SetDimDivisor(1, DimLevel);
}*/
}
// Show current value
if (CurrentAdjustmentByte != NULL) {
RPU_SetDisplay(0, (unsigned long)(*CurrentAdjustmentByte), true);
} else if (CurrentAdjustmentUL != NULL) {
RPU_SetDisplay(0, (*CurrentAdjustmentUL), true);
}
}
/*
if (curState == MACHINE_STATE_ADJUST_DIM_LEVEL) {
// for (int count = 0; count < 7; count++) RPU_SetLampState(MIDDLE_ROCKET_7K + count, 1, (CurrentTime / 1000) % 2);
}*/
if (returnState == MACHINE_STATE_ATTRACT) {
// If any variables have been set to non-override (99), return
// them to dip switch settings
// Balls Per Game, Player Loses On Ties, Novelty Scoring, Award Score
// DecodeDIPSwitchParameters();
RPU_SetDisplayCredits(Credits, !FreePlayMode);
ReadStoredParameters();
}
return returnState;
}
////////////////////////////////////////////////////////////////////////////
//
// Display Management functions
//
////////////////////////////////////////////////////////////////////////////
unsigned long LastTimeScoreChanged = 0;
unsigned long LastTimeOverrideAnimated = 0;
unsigned long LastFlashOrDash = 0;
#ifdef USE_SCORE_OVERRIDES
unsigned long ScoreOverrideValue[4] = {0, 0, 0, 0};
byte ScoreOverrideStatus = 0;
#define DISPLAY_OVERRIDE_BLANK_SCORE 0xFFFFFFFF
#endif
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;
}
#ifdef USE_SCORE_OVERRIDES
void OverrideScoreDisplay(byte displayNum, unsigned long value, boolean animate) {
if (displayNum > 3) return;
ScoreOverrideStatus |= (0x10 << displayNum);
if (animate) ScoreOverrideStatus |= (0x01 << displayNum);
else ScoreOverrideStatus &= ~(0x01 << displayNum);
ScoreOverrideValue[displayNum] = value;