-
Notifications
You must be signed in to change notification settings - Fork 10
/
BlackKnight.ino
executable file
·2361 lines (2278 loc) · 116 KB
/
BlackKnight.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
// Rules for the Black Knight pinball machine
byte BK_LeftMagna[5]; // left magna save available? (for every player)
bool BK_LeftAfterMagna = false; // number of the timer for the after magna save time
byte BK_RightMagna[5]; // right magna save available? (for every player)
bool BK_RightAfterMagna = false; // number of the timer for the after magna save time
bool BK_LastChance = false; // last chance active?
bool BK_LastChanceActive = false; // give a last chance ball
bool BK_LastChanceOver = false; // did the player already have a last chance?
byte BK_RightMysteryTimer = 0; // number of the timer for the right mystery (if active)
byte BK_LeftMysteryTimer = 0; // number of the timer for the left mystery (if active)
byte BK_TimedRightMagnaTimer = 0; // number of the timer for the right timed magna save
byte BK_TimedLeftMagnaTimer = 0; // number of the timer for the left timed magna save
byte BK_BonusToAdd = 0; // bonus points to be added by AddBonus()
byte BK_BonusCountTime = 0; // counter to reduce the waiting time between the bonus counts
const byte BK_BonusLamp = 48; // first lamp of the bonus ladder
bool BK_LowerExBall[5]; // extra ball in turnaround pending?
bool BK_UpperExBall[5]; // extra ball in left ramp pending?
bool BK_PlayersExBalls[5]; // did the player already get an extra ball?
byte BK_DropTimer[4]; // timer for all drop target banks
byte BK_DropHits[16]; // counts how often the target banks have been cleared
bool BK_DropWait[5]; // indicates that a waiting time for this drop target bank is active before it it being processed
const byte BK_BallSearchCoils[12] = {1,8,10,9,2,3,4,5,7,19,15,0}; // coils to fire when the ball watchdog timer runs out
const unsigned int BK_SolTimes[24] = {30,50,50,50,50,40,50,50,1999,1999,0,5,5,5,999,999,50,50,50,5,5,5,0,0}; // Activation times for solenoids
const char BK_TestSounds[16][15] = {{"0_2f.snd"},{"0_30.snd"},{"0_31.snd"},{"0_32.snd"},{"0_33.snd"},{"0_15.snd"},{"0_36.snd"},{"0_37.snd"},
{"0_38.snd"},{"0_39.snd"},{"0_3a.snd"},{"0_3b.snd"},{"0_3c.snd"},{"BK_E14.snd"},{"0_3e.snd"},0};
// offsets of settings in the settings array
#define BK_TimedMagna 0 // Timed Magna saves?
#define BK_ReplayScore 1 // without credits being implemented just show some respect
#define BK_MultiballJackpot 2 // optional multiball jackpot
#define BK_MultiballVolume 3 // increase volume during multiball when digital volume control is used
#define BK_HighScoreVolume 4 // increase volume during high score entry when digital volume control is used
#define BK_BallEjectStrength 5 // activation time of the ball ramp thrower (solenoid 6) in ms
const byte BK_defaults[64] = {0,0,0,0,0,30,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};
const char BK_TxTJackpot[4][17] = {{" OFF "},{" 500000 "},{" 750000 "},{" 1000000 "}};
const char BK_TxTReplayScore[4][17] = {{" 1000000 "},{" 1500000 "},{" 2000000 "},{" 2500000 "}};
const struct SettingTopic BK_setList[10] = {{" TIMED MAGNA ",HandleBoolSetting,0,0,0},
{" REPLAY SCORE ",HandleTextSetting,&BK_TxTReplayScore[0][0],0,3},
{" MBALL JACKPOT",HandleTextSetting,&BK_TxTJackpot[0][0],0,3},
{"MULTBALVOLUME ",BK_HandleVolumeSetting,0,0,30},
{" HSCOREVOLUME ",BK_HandleVolumeSetting,0,0,30},
{" EJECT STRNGTH",HandleNumSetting,0,10,50},
{" RESET HIGH ",BK_ResetHighScores,0,0,0},
{"RESTOREDEFAULT",RestoreDefaults,0,0,0},
{" EXIT SETTNGS",ExitSettings,0,0,0},
{"",NULL,0,0,0}};
// Duration..11111110...22222111...33322222...43333333...44444444...55555554...66666555
// Duration..65432109...43210987...21098765...09876543...87654321...65432109...43210987
const struct LampPat BK_ExBallPat[13] = {{50,0,0b10000000,0b00000000,0b00000000,0b00000000,0b01000000,0b00000000,0b00000000},
{50,0,0b01000000,0b00000000,0b00000000,0b00000000,0b01000000,0b00000000,0b00000000},
{50,0,0b01001000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000},
{50,0,0b00101000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000},
{50,0,0b00100000,0b00000000,0b00010000,0b00000000,0b00000000,0b00000000,0b00000000},
{50,0,0b00000000,0b00000000,0b00110000,0b00000000,0b00000000,0b00000000,0b00000000},
{50,0,0b00000000,0b00000000,0b01100000,0b00000000,0b00000000,0b00000000,0b00000000},
{50,0,0b00000000,0b00000000,0b01000100,0b00000000,0b00000000,0b00000000,0b00000000},
{50,0,0b00000000,0b00000000,0b00000110,0b00000000,0b00000000,0b00000000,0b00000000},
{50,0,0b00000000,0b00000000,0b00000011,0b00000000,0b00000000,0b00000000,0b00000000},
{50,0,0b00000100,0b00000000,0b00000001,0b00000000,0b00000000,0b00000000,0b00000000},
{50,0,0b10000100,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000},
{0,0,0,0,0,0,0,0,0}};
const struct LampPat BK_AttractPat1[52] = {{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b01000000,0b00000000,0b00000000},
{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00000000,0b00000000},
{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00000001,0b00000000},
{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00000011,0b00000000},
{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00000111,0b11110000},
{30,0,0b11000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00001111,0b11110000},
{30,0,0b11000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00011111,0b11110000},
{30,0,0b11000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00111111,0b11110000},
{30,0,0b11000000,0b00000000,0b00000000,0b00000000,0b11000000,0b01111111,0b11110000},
{30,0,0b11000000,0b00000000,0b00000000,0b00000000,0b11000000,0b11111111,0b11110000},
{30,0,0b11001100,0b00000000,0b10001000,0b00000000,0b11000000,0b11111111,0b11110001},
{30,0,0b11001111,0b00000000,0b10001000,0b00000000,0b11000000,0b11111111,0b11110011},
{30,0,0b11001111,0b00000000,0b10001001,0b00000000,0b11000000,0b11111111,0b11110111},
{30,0,0b11101111,0b00000000,0b10001011,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11101111,0b00000000,0b10001111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11101111,0b00000001,0b10011111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11101111,0b00000001,0b10111111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11101111,0b00000001,0b11111111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11101111,0b10000011,0b11111111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11111111,0b10100011,0b11111111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11111111,0b11100011,0b11111111,0b00010001,0b11000000,0b11111111,0b11111111},
{30,0,0b11111111,0b11100011,0b11111111,0b00110011,0b11000000,0b11111111,0b11111111},
{30,0,0b11111111,0b11100011,0b11111111,0b11110111,0b11000000,0b11111111,0b11111111},
{30,0,0b11111111,0b11101111,0b11111111,0b11110111,0b11000000,0b11111111,0b11111111},
{30,0,0b11111111,0b11101111,0b11111111,0b11111111,0b11000001,0b11111111,0b11111111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b11000011,0b11111111,0b11111111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b10000011,0b11111111,0b11111111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11111111,0b11111111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11111110,0b11111111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11111100,0b11111111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11111000,0b00001111},
{30,0,0b00111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11110000,0b00001111},
{30,0,0b00111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11100000,0b00001111},
{30,0,0b00111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11000000,0b00001111},
{30,0,0b00111111,0b11111111,0b11111111,0b11111111,0b00000011,0b10000000,0b00001111},
{30,0,0b00111111,0b11111111,0b11111111,0b11111111,0b00000011,0b00000000,0b00001111},
{30,0,0b00110011,0b11111111,0b01110111,0b11111111,0b00000011,0b00000000,0b00001110},
{30,0,0b00110000,0b11111111,0b01110111,0b11111111,0b00000011,0b00000000,0b00001100},
{30,0,0b00110000,0b11111111,0b01110110,0b11111111,0b00000011,0b00000000,0b00001000},
{30,0,0b00010000,0b11111111,0b01110100,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00010000,0b11111111,0b01110000,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00010000,0b11111110,0b01100000,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00010000,0b11111110,0b01000000,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00010000,0b11111110,0b00000000,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00000000,0b01111100,0b00000000,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00000000,0b00011100,0b00000000,0b11101110,0b00000011,0b00000000,0b00000000},
{30,0,0b00000000,0b00011100,0b00000000,0b11001100,0b00000011,0b00000000,0b00000000},
{30,0,0b00000000,0b00011100,0b00000000,0b00001000,0b00000011,0b00000000,0b00000000},
{30,0,0b00000000,0b00010000,0b00000000,0b00001000,0b00000011,0b00000000,0b00000000},
{30,0,0b00000000,0b00010000,0b00000000,0b00000000,0b00000010,0b00000000,0b00000000},
{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000},
{0,0,0,0,0,0,0,0,0}};
const struct LampPat BK_AttractPat2[4] = {{250,0,0b11111100,0b10000100,0b00100100,0b11000001,0b01000000,0b10010010,0b00000100},
{250,0,0b00000000,0b00111001,0b11001010,0b00100010,0b10000000,0b00100100,0b01101001},
{250,0,0b00000011,0b01000010,0b00010001,0b00011100,0b00000011,0b01001001,0b10010010},
{0,0,0,0,0,0,0,0,0}};
const struct LampPat BK_AttractPat3[6] = {{90,0,0b00000000,0b00000001,0b00100001,0b00100010,0b01000000,0b00001000,0b00000001},
{90,0,0b00100000,0b10000000,0b01000010,0b11000100,0b10000000,0b00010000,0b00000010},
{90,0,0b00011100,0b00001110,0b00000100,0b00000000,0b00000001,0b00100001,0b00000100},
{90,0,0b11000000,0b00100000,0b00000000,0b00001000,0b00000000,0b01000010,0b10011000},
{90,0,0b00000011,0b01010000,0b10011000,0b00010001,0b00000010,0b10000100,0b01100000},
{0,0,0,0,0,0,0,0,0}};
const struct LampPat BK_AttractPat4[52] = {{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000},
{30,0,0b00000000,0b00010000,0b00000000,0b00000000,0b00000010,0b00000000,0b00000000},
{30,0,0b00000000,0b00010000,0b00000000,0b00001000,0b00000011,0b00000000,0b00000000},
{30,0,0b00000000,0b00011100,0b00000000,0b00001000,0b00000011,0b00000000,0b00000000},
{30,0,0b00000000,0b00011100,0b00000000,0b11001100,0b00000011,0b00000000,0b00000000},
{30,0,0b00000000,0b00011100,0b00000000,0b11101110,0b00000011,0b00000000,0b00000000},
{30,0,0b00000000,0b01111100,0b00000000,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00010000,0b11111110,0b00000000,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00010000,0b11111110,0b01000000,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00010000,0b11111110,0b01100000,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00010000,0b11111111,0b01110000,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00010000,0b11111111,0b01110100,0b11111111,0b00000011,0b00000000,0b00000000},
{30,0,0b00110000,0b11111111,0b01110110,0b11111111,0b00000011,0b00000000,0b00001000},
{30,0,0b00110000,0b11111111,0b01110111,0b11111111,0b00000011,0b00000000,0b00001100},
{30,0,0b00110011,0b11111111,0b01110111,0b11111111,0b00000011,0b00000000,0b00001110},
{30,0,0b00111111,0b11111111,0b11111111,0b11111111,0b00000011,0b00000000,0b00001111},
{30,0,0b00111111,0b11111111,0b11111111,0b11111111,0b00000011,0b10000000,0b00001111},
{30,0,0b00111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11000000,0b00001111},
{30,0,0b00111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11100000,0b00001111},
{30,0,0b00111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11110000,0b00001111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11111000,0b00001111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11111100,0b11111111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11111110,0b11111111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b00000011,0b11111111,0b11111111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b10000011,0b11111111,0b11111111},
{30,0,0b11111111,0b11111111,0b11111111,0b11111111,0b11000011,0b11111111,0b11111111},
{30,0,0b11111111,0b11101111,0b11111111,0b11111111,0b11000001,0b11111111,0b11111111},
{30,0,0b11111111,0b11101111,0b11111111,0b11110111,0b11000000,0b11111111,0b11111111},
{30,0,0b11111111,0b11100011,0b11111111,0b11110111,0b11000000,0b11111111,0b11111111},
{30,0,0b11111111,0b11100011,0b11111111,0b11001100,0b11000000,0b11111111,0b11111111},
{30,0,0b11111111,0b11100011,0b11111111,0b00010001,0b11000000,0b11111111,0b11111111},
{30,0,0b11111111,0b10100011,0b11111111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11101111,0b10000011,0b11111111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11101111,0b00000001,0b11111111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11101111,0b00000001,0b10111111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11101111,0b00000001,0b10011111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11101111,0b00000000,0b10001111,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11101111,0b00000000,0b10001011,0b00000000,0b11000000,0b11111111,0b11111111},
{30,0,0b11001111,0b00000000,0b10001001,0b00000000,0b11000000,0b11111111,0b11110111},
{30,0,0b11001111,0b00000000,0b10001000,0b00000000,0b11000000,0b11111111,0b11110011},
{30,0,0b11001100,0b00000000,0b10001000,0b00000000,0b11000000,0b11111111,0b11110001},
{30,0,0b11000000,0b00000000,0b00000000,0b00000000,0b11000000,0b11111111,0b11110000},
{30,0,0b11000000,0b00000000,0b00000000,0b00000000,0b11000000,0b01111111,0b11110000},
{30,0,0b11000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00111111,0b11110000},
{30,0,0b11000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00011111,0b11110000},
{30,0,0b11000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00001111,0b11110000},
{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00000111,0b11110000},
{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00000011,0b00000000},
{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00000001,0b00000000},
{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b11000000,0b00000000,0b00000000},
{30,0,0b00000000,0b00000000,0b00000000,0b00000000,0b01000000,0b00000000,0b00000000},
{0,0,0,0,0,0,0,0,0}};
// Duration..11111110...22222111...33322222...43333333...44444444...55555554...66666555
// Duration..65432109...43210987...21098765...09876543...87654321...65432109...43210987
const struct LampPat BK_AttractPat5[17] = {{50,0,0b11000110,0b00000000,0b00001000,0b00000000,0b00000000,0b00000111,0b11110000},
{50,0,0b01000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00001100,0b11000000},
{50,0,0b01001001,0b00000000,0b10000000,0b00000000,0b00000000,0b00011000,0b11000000},
{50,0,0b00001001,0b00000000,0b10000000,0b00000000,0b00000000,0b00110000,0b00000000},
{50,0,0b00101001,0b10000000,0b10010000,0b10000000,0b00000000,0b01100000,0b00000000},
{50,0,0b00100000,0b10000000,0b00010000,0b10000000,0b00000000,0b11000000,0b00000000},
{50,0,0b00100000,0b10011000,0b00010000,0b11110000,0b00000000,0b10000000,0b00000001},
{50,0,0b00000000,0b00011000,0b00000000,0b01110000,0b00000000,0b00000000,0b00000011},
{50,0,0b00000000,0b00011100,0b00000000,0b01110110,0b00000010,0b00000000,0b00000110},
{50,0,0b00000000,0b00000100,0b00000000,0b00000110,0b00000010,0b00000000,0b00001100},
{50,0,0b00010000,0b01100110,0b00100000,0b00000111,0b00000011,0b00000000,0b00001000},
{50,0,0b00010000,0b01100010,0b01100000,0b00001001,0b00000001,0b00000000,0b00000000},
{50,0,0b00010000,0b01100011,0b01000111,0b00001000,0b01000001,0b00000000,0b00000000},
{50,0,0b00000000,0b00000001,0b00000111,0b00000000,0b11000000,0b00000000,0b00000000},
{50,0,0b10000110,0b00000001,0b00001111,0b00000000,0b10000000,0b00000001,0b00110000},
{50,0,0b10000110,0b00000000,0b00001000,0b00000000,0b00000000,0b00000011,0b00110000},
{0,0,0,0,0,0,0,0,0}};
const struct LampFlow BK_AttractFlow[6] = {{3,BK_AttractPat1},{10,BK_AttractPat2},{3,BK_AttractPat4},{10,BK_AttractPat3},{10,BK_AttractPat5},{0,0}};
const char BK_NewGameSounds[5][13] = {{"0_2b_001.snd"},{"0_2b_002.snd"},{"0_2b_003.snd"},{"0_2b_004.snd"},{"0_2b_005.snd"}};
const byte BK_BonusLamps[13] = {60,59,58,57,56,55,54,53,52,51,50,49,48}; // numbers of the bonus lamps
const byte BK_BonusValues[13] = {40,30,20,10,9,8,7,6,5,4,3,2,1}; // values of the bonus lamps
const byte BK_ResetAllDropTargets[9] = {2,15,3,15,4,15,5,15,0};
const byte BK_FirstMultLamp = 61;
const byte BK_DropTargets[4] = {25, 29, 33, 37};
const byte BK_DropSolenoid = 2;
const byte BK_DropLamp = 17;
struct GameDef BK_GameDefinition = {
BK_setList, // GameSettingsList
(byte*)BK_defaults, // GameDefaultsPointer
"BK_SET.BIN", // GameSettingsFileName
"BKSCORES.BIN", // HighScoresFileName
BK_AttractMode, // AttractMode
BK_SolTimes}; // Default activation times of solenoids
void BK_init() {
digitalWrite(VolumePin,HIGH); // mute sound
if (APC_settings[DebugMode]) { // activate serial interface in debug mode
Serial.begin(115200);}
SolRecycleTime[17-1] = 200; // set recycle time for both slingshots
SolRecycleTime[18-1] = 200;
ACselectRelay = 0; // no A/C select relay
GameDefinition = BK_GameDefinition;} // read the game specific settings and highscores
void BK_AttractMode() { // Attract Mode
DispRow1 = DisplayUpper;
DispRow2 = DisplayLower;
LampPattern = NoLamps;
Switch_Pressed = BK_AttractModeSW;
Switch_Released = DummyProcess;
AppByte2 = 0;
LampReturn = BK_AttractLampCycle;
AddBlinkLamp(4, 150); // blink Game Over lamp
ActivateTimer(1000, 0, BK_AttractLampCycle);
if (APC_settings[DisplayType]) { // check display setting
BK_AttractNumCycle(1);} // use Sys7 standard animation
else { // it's the 4Alpha + Credit display
BK_AttractDisplayCycle(1);}} // use alphanumeric animation
void BK_CheckForLockedBalls(byte Event) { // check if balls are locked and release them
UNUSED(Event);
if (QuerySwitch(20)) { // for the outhole
ActivateSolenoid(0, 1);}
else if (QuerySwitch(24)) { // for the lower eject hole
ActivateSolenoid(0, 8);}
else if (QuerySwitch(41)) { // for the multiball lock
ActivateSolenoid(0, 7);}}
void BK_AttractLampCycle(byte Event) { // play multiple lamp pattern series
UNUSED(Event);
PatPointer = BK_AttractFlow[AppByte2].FlowPat; // set the pointer to the current series
FlowRepeat = BK_AttractFlow[AppByte2].Repeat; // set the repetitions
if (AppByte2 == 2) {
StrobeLights(3);}
else {
StrobeLights(0);}
AppByte2++; // increase counter
if (!BK_AttractFlow[AppByte2].Repeat) { // repetitions of next series = 0?
AppByte2 = 0;} // reset counter
ShowLampPatterns(1);} // call the player
void BK_AddScrollUpper(byte Step) { // shifts Step times and adds the text being in DisplayUpper2
static byte Position = 0; // stores the position in DisplayUpper2
byte Buffer1 = DisplayUpper[18]; // get the leftmost character of the right display
byte Buffer2 = DisplayUpper[19];
for (byte i=1; i<8; i++) { // left display
DisplayUpper[2*i] = DisplayUpper[2*i+2];
DisplayUpper[2*i+1] = DisplayUpper[2*i+3];
DisplayUpper[2*i+16] = DisplayUpper[2*i+18];
DisplayUpper[2*i+17] = DisplayUpper[2*i+19];}
DisplayUpper[14] = Buffer1;
DisplayUpper[15] = Buffer2;
DisplayUpper[30] = DisplayUpper2[2*Position]; // fill the rightmost character of the right display
DisplayUpper[31] = DisplayUpper2[2*Position+1];
Step--;
if (Step) {
Position++;
if (Position == 8) {
Position++;}
ActivateTimer(50, Step, BK_AddScrollUpper);}
else {
Position = 0;}}
void BK_AttractNumCycle(byte Step) {
static byte Timer0 = 0;
switch (Step) {
case 0: // stop command
RemoveBlinkLamp(4); // stop blinking of game over lamp
if (Timer0) {
KillTimer(Timer0);
Timer0 = 0;}
return;
case 1: // start command
AddBlinkLamp(4, 150); // blink game over lamp
Step = 2;
break;
case 2: // show high score
AddBlinkLamp(6, 150); // blink highest Score lamp
DisplayScore(1, HallOfFame.Scores[0]);
DisplayScore(2, HallOfFame.Scores[0]);
DisplayScore(3, HallOfFame.Scores[0]);
DisplayScore(4, HallOfFame.Scores[0]);
Step = 3;
break;
case 3: // show scores of previous game
RemoveBlinkLamp(6); // stop blinking of high score lamp
for (byte i=0; i<16; i++) { // clear displays
*(DisplayUpper+2*i) = 255;
*(DisplayUpper+2*i+1) = 0;
*(DisplayLower+2*i) = 255;
*(DisplayLower+2*i+1) = 0;}
DisplayScore(1, Points[1]);
if (Points[2]) {
DisplayScore(2, Points[2]);
if (Points[3]) {
DisplayScore(3, Points[3]);
if (Points[4]) {
DisplayScore(4, Points[4]);}}}
Step = 1;
break;}
BK_CheckForLockedBalls(0); // check for a ball in the outhole
Timer0 = ActivateTimer(3000, Step, BK_AttractNumCycle);} // come back for the next 'page'
void BK_AttractDisplayCycle(byte Step) {
static byte Count = 0;
static byte Timer0 = 0;
static byte Timer1 = 0;
static byte Timer2 = 0;
static byte Timer3 = 0;
switch (Step) {
case 0: // stop command
if (Timer0) {
KillTimer(Timer0);
Timer0 = 0;}
if (Timer1) {
KillTimer(Timer1);
Timer1 = 0;}
if (Timer2) {
KillTimer(Timer2);
Timer2 = 0;}
if (Timer3) {
KillTimer(Timer3);
Timer3 = 0;}
ScrollUpper(100); // stop scrolling
ScrollLower(100);
AddScrollUpper(100);
RemoveBlinkLamp(6);
return;
case 1: // attract mode title 'page'
if (Count == 40 && !APC_settings[DisplayType]) { // only for alphanumeriscal displays
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
Count++;
Step = 0;
Timer0 = 0;
ShowLampPatterns(0); // stop lamp animations
BK_AttractDisplayCycle(0); // stop display animations
for (byte i=0; i< 8; i++) {
LampColumns[i] = 0;}
LampPattern = LampColumns;
BK_RulesDisplay(1);
Count = 0;
return;}
else {
Count++;
WriteUpper2(" THE ");
Timer1 = ActivateTimer(50, 5, BK_AttractDisplayCycle);
Timer3 = ActivateTimer(900, 7, BK_AttractDisplayCycle);
WriteLower2(" BLACK KNIGHT ");
Timer2 = ActivateTimer(1400, 6, BK_AttractDisplayCycle);
if (NoPlayers) { // if there were no games before skip the next step
Step++;}
else {
Step = 3;}}
break;
case 2: // show scores of previous game
WriteUpper2(" "); // erase display
WriteLower2(" ");
for (i=1; i<=NoPlayers; i++) { // display the points of all active players
ShowNumber(8*i-1, Points[i]);}
Timer1 = ActivateTimer(50, 5, BK_AttractDisplayCycle);
Timer2 = ActivateTimer(900, 6, BK_AttractDisplayCycle);
Step++;
break;
case 3: // Show highscores
AddBlinkLamp(6, 150); // blink Highest Score lamp
WriteUpper2("1> ");
WriteLower2("2> ");
for (i=0; i<3; i++) {
*(DisplayUpper2+8+2*i) = DispPattern1[(HallOfFame.Initials[i]-32)*2];
*(DisplayUpper2+8+2*i+1) = DispPattern1[(HallOfFame.Initials[i]-32)*2+1];
*(DisplayLower2+8+2*i) = DispPattern2[(HallOfFame.Initials[3+i]-32)*2];
*(DisplayLower2+8+2*i+1) = DispPattern2[(HallOfFame.Initials[3+i]-32)*2+1];}
ShowNumber(15, HallOfFame.Scores[0]);
ShowNumber(31, HallOfFame.Scores[1]);
Timer1 = ActivateTimer(50, 5, BK_AttractDisplayCycle);
Timer2 = ActivateTimer(900, 6, BK_AttractDisplayCycle);
Step++;
break;
case 4:
RemoveBlinkLamp(6); // stop blinking of Highest Score lamp
WriteUpper2("3> ");
WriteLower2("4> ");
for (i=0; i<3; i++) {
*(DisplayUpper2+8+2*i) = DispPattern1[(HallOfFame.Initials[6+i]-32)*2];
*(DisplayUpper2+8+2*i+1) = DispPattern1[(HallOfFame.Initials[6+i]-32)*2+1];
*(DisplayLower2+8+2*i) = DispPattern2[(HallOfFame.Initials[9+i]-32)*2];
*(DisplayLower2+8+2*i+1) = DispPattern2[(HallOfFame.Initials[9+i]-32)*2+1];}
ShowNumber(15, HallOfFame.Scores[2]);
ShowNumber(31, HallOfFame.Scores[3]);
Timer1 = ActivateTimer(50, 5, BK_AttractDisplayCycle);
Timer2 = ActivateTimer(900, 6, BK_AttractDisplayCycle);
Step = 1;
break;
case 5: // scrolling routine called here to keep track of the timer
Timer1 = 0;
ScrollUpper(0);
return;
case 6:
Timer2 = 0;
ScrollLower(0);
return;
case 7:
Timer3 = 0;
WriteUpper2(" APC ");
AddScrollUpper(0);
return;}
BK_CheckForLockedBalls(0); // check for a ball in the outhole
Timer0 = ActivateTimer(4000, Step, BK_AttractDisplayCycle);} // come back for the next 'page'
void BK_AttractModeSW(byte Event) { // Attract Mode switch behaviour
switch (Event) {
case 8: // high score reset
digitalWrite(Blanking, LOW); // invoke the blanking
break;
case 20: // outhole
ActivateTimer(200, 0, BK_CheckForLockedBalls); // check again in 200ms
break;
case 72: // Service Mode
StrobeLights(0);
BK_RightMysteryTimer = 0;
BK_LeftMysteryTimer = 0;
BK_LockChaseLight(0);
ShowLampPatterns(0);
BlinkScore(0);
BallWatchdogTimer = 0;
BK_TimedRightMagnaTimer = 0;
BK_TimedLeftMagnaTimer = 0;
CheckReleaseTimer = 0;
RemoveBlinkLamp(4); // stop blinking of Game Over lamp
RemoveBlinkLamp(6); // stop blinking of Highest Score lamp
StrobeLights(0);
ShowLampPatterns(0); // stop lamp animations
if (APC_settings[0]) { // check display setting
BK_AttractNumCycle(0);} // stop Sys7 standard animation
else { // it's the 4Alpha + Credit display
BK_AttractDisplayCycle(0);} // stop animation
BK_RulesDisplay(0);
BK_TestMode_Enter();
break;
case 3: // start game
if (BK_CountBallsInTrunk() == 3 || (BK_CountBallsInTrunk() == 2 && QuerySwitch(45))) { // Ball missing?
StrobeLights(0);
randomSeed(TC_ReadCV(TC2, 1));
AfterSound = BK_StartBgMusic;
PlayRandomSound(61, 5, (char *)BK_NewGameSounds);
ShowLampPatterns(0); // stop lamp animations
RemoveBlinkLamp(4);
RemoveBlinkLamp(6);
Switch_Pressed = DummyProcess; // Switches do nothing
if (APC_settings[0]) { // check display setting
BK_AttractNumCycle(0);} // stop Sys7 standard animation
else { // it's the 4Alpha + Credit display
BK_AttractDisplayCycle(0);} // stop animation
BK_RulesDisplay(0);
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++) {
LampColumns[i] = 0;}
LampPattern = LampColumns;
TurnOnLamp(2); // turn on Ball in Play lamp
NoPlayers = 0;
if (APC_settings[DisplayType]) { // check display setting
for (byte i=0; i<16; i++) { // clear displays
*(DisplayUpper+2*i) = 255;
*(DisplayUpper+2*i+1) = 0;
*(DisplayLower+2*i) = 255;
*(DisplayLower+2*i+1) = 0;}}
else { // alphanumeric displays
WriteUpper(" ");
WriteLower(" ");}
Ball = 1;
BK_ResetAllDTargets(0);
BK_AddPlayer();
Player = 1;
ExBalls = 0;
Bonus = 1;
BonusMultiplier = 1;
for (i=0; i<16; i++) {
BK_DropHits[i] = 0;} // clear drop target hits
InLock = 0;
Multiballs = 1;
for (i=1; i < 5; i++) {
BK_LowerExBall[i] = false;
BK_UpperExBall[i] = false;
BK_PlayersExBalls[i] = false;
BK_RightMagna[i] = 0;
BK_LeftMagna[i] = 0;
LockedBalls[i] = 0;
Points[i] = 0;}
BK_NewBall(3); // release a new ball (3 expected balls in the trunk)
ActivateSolenoid(0, 23); // enable flipper fingers
ActivateSolenoid(0, 24);}}}
void BK_ResetAllDTargets(byte Dummy) {
for (Dummy=0; Dummy <4; Dummy++) { // Dummy counts through the drop target banks
for (i=0; i<3;i++) { // for each target
if (QuerySwitch(BK_DropTargets[Dummy]+i)) { // target down?
ActivateSolenoid(0, BK_DropSolenoid+Dummy); // reset
break;}}}} // quit for next bank
void BK_AddPlayer() {
if ((NoPlayers < 4) && (Ball == 1)) { // if actual number of players < 4
NoPlayers++; // add a player
Points[NoPlayers] = 0; // delete the points of the new player
ShowPoints(NoPlayers);}} // and show them
void BK_NewBall(byte Balls) { // release ball (Balls = expected balls on ramp)
ShowAllPoints(0);
BK_ShowBonus();
if (!((Player == 1) && (Ball == 1) && !InLock)) { // skip for the first ball of the game to wait for speech sequence
BK_StartBgMusic(0);}
if (APC_settings[DisplayType]) {
*(DisplayLower+16) = ConvertNumUpper(Ball,(byte) *(DisplayLower+16));}
else {
*(DisplayUpper+16) = LeftCredit[32 + 2 * Ball];} // show current ball in left credit
BK_LockChaseLight(1);
BlinkScore(1); // start score blinking
TurnOnLamp(36); // bumper light on
for (byte i=0; i<4; i++) { // restore the drop target lamps of the current player
for (byte c=0; c < 3; c++) { // for all drop target banks
if (BK_DropHits[(4*(Player-1))+i] > c) {
TurnOnLamp(BK_DropTargets[i]+c);}
else {
TurnOffLamp(BK_DropTargets[i]+c);}}}
if (BK_LowerExBall[Player]) { // restore extra ball lamps
TurnOnLamp(23);}
else {
TurnOffLamp(23);}
if (BK_UpperExBall[Player]) {
TurnOnLamp(41);}
else {
TurnOffLamp(41);}
if (game_settings[BK_TimedMagna]) { // if timed magna save mode
if (BK_LeftMagna[Player]) {
if (BK_LeftMagna[Player] == 5) { // 5 seconds reached?
RemoveBlinkLamp(10); // turn off blinking lamp
TurnOnLamp(10);} // and switch it on permanently
else {
AddBlinkLamp(10, 150*BK_LeftMagna[Player]);}}
else {
RemoveBlinkLamp(10); // turn off blinking lamp
TurnOffLamp(10);} // and switch it off permanently
if (BK_RightMagna[Player]) {
if (BK_RightMagna[Player] == 5) { // 5 seconds reached?
RemoveBlinkLamp(9); // turn off blinking lamp
TurnOnLamp(9);} // and switch it on permanently
else {
AddBlinkLamp(9, 150*BK_RightMagna[Player]);}}
else {
RemoveBlinkLamp(9); // turn off blinking lamp
TurnOffLamp(9);}} // and switch it off permanently
else {
if (BK_LeftMagna[Player]) {
TurnOnLamp(10);}
else {
TurnOffLamp(10);}
if (BK_RightMagna[Player]) {
TurnOnLamp(9);}
else {
TurnOffLamp(9);}}
Switch_Released = BK_CheckShooterLaneSwitch;
if (!QuerySwitch(45)) {
ActivateSolenoid(game_settings[BK_BallEjectStrength], 6); // release ball
Switch_Pressed = BK_BallReleaseCheck; // set switch check to enter game
CheckReleaseTimer = ActivateTimer(5000, Balls-1, BK_CheckReleasedBall);} // start release watchdog
else {
Switch_Pressed = BK_ResetBallWatchdog;}}
void BK_CheckShooterLaneSwitch(byte Switch) {
if (Switch == 45) { // shooter lane switch released?
Switch_Released = DummyProcess;
StopPlayingMusic();
PlaySound(50, "0_33.snd");
if (!BallWatchdogTimer) {
BallWatchdogTimer = ActivateTimer(30000, 0, BK_SearchBall);}}}
void BK_BallReleaseCheck(byte Switch) { // handle switches during ball release
if ((Switch > 10)&&(Switch != 17)&&(Switch != 18)&&(Switch != 19)&&(Switch != 46)) { // playfield switch activated?
if (CheckReleaseTimer) {
KillTimer(CheckReleaseTimer);
CheckReleaseTimer = 0;} // stop watchdog
Switch_Pressed = BK_ResetBallWatchdog;
if (Switch == 45) { // ball is in the shooter lane
Switch_Released = BK_CheckShooterLaneSwitch;} // set mode to register when ball is shot
else {
if (!BallWatchdogTimer) {
BallWatchdogTimer = ActivateTimer(30000, 0, BK_SearchBall);}}} // set switch mode to game
BK_GameMain(Switch);} // process current switch
void BK_ResetBallWatchdog(byte Event) { // handle switches during ball release
if ((Event > 10)&&(Event != 17)&&(Event != 18)&&(Event != 19)&&(Event != 46)) { // playfield switch activated?
if (BallWatchdogTimer) {
KillTimer(BallWatchdogTimer);} // stop watchdog
BallWatchdogTimer = ActivateTimer(30000, 0, BK_SearchBall);}
BK_GameMain(Event);} // process current switch
void BK_SearchBall(byte Counter) { // ball watchdog timer has run out
BallWatchdogTimer = 0;
if (QuerySwitch(20)) {
BlockOuthole = false;
ActivateTimer(1000, 0, BK_ClearOuthole);}
else {
if (QuerySwitch(45)) { // if ball is waiting to be launched
BallWatchdogTimer = ActivateTimer(30000, 0, BK_SearchBall);} // restart watchdog
else { // if ball is really missing
byte c = BK_CountBallsInTrunk(); // recount all balls
if (c == 3) { // found 3 balls in trunk?
BK_BallEnd(0);} // ball has probably jumped over the outhole switch
else {
byte c2 = 0;
for (i=0; i<3; i++) { // count balls in lock
if (QuerySwitch(41+i)) {
if (c2 < i) {
c = 5;} // set warning flag
c2++;}}
if (c == 5) { // balls have not settled yet
WriteUpper(" BALL STUCK ");
BallWatchdogTimer = ActivateTimer(1000, 0, BK_SearchBall);} // and try again in 1s
else {
if (c2 > InLock) { // more locked balls found than expected?
BK_HandleLock(0); // lock them
BallWatchdogTimer = ActivateTimer(30000, 0, BK_SearchBall);}
else {
if (c + c2 == 3) { // all balls found
BK_BallEnd(0);} // ball has probably jumped over the outhole switch
WriteUpper(" BALL SEARCH");
ActivateSolenoid(0, BK_BallSearchCoils[Counter]); // fire coil to get ball free
Counter++;
if (Counter == 10) { // all coils fired?
Counter = 0;} // start again
BallWatchdogTimer = ActivateTimer(1000, Counter, BK_SearchBall);}}}}}} // come again in 1s if no switch is activated
byte BK_CountBallsInTrunk() {
byte Balls = 0;
for (i=0; i<3; i++) { // check how many balls are on the ball ramp
if (QuerySwitch(17+i)) {
if (Balls < i) {
return 5;} // send warning
Balls++;}}
return Balls;}
void BK_CheckReleasedBall(byte Balls) { // ball release watchdog
CheckReleaseTimer = 0;
BlinkScore(0); // stop blinking to show messages
WriteUpper("WAITINGFORBALL"); // indicate a problem
WriteLower(" ");
if (Balls == 10) { // indicating a previous trunk error
WriteUpper(" ");
WriteLower(" ");
ShowAllPoints(0);
BlinkScore(1);
ActivateSolenoid(game_settings[BK_BallEjectStrength], 6);}
byte c = BK_CountBallsInTrunk();
if (c == Balls) { // expected number of balls in trunk
if (APC_settings[DebugMode]) {
WriteUpper(" BALL MISSING");}
if (QuerySwitch(20)) { // outhole switch still active?
ActivateSolenoid(0, 1);}} // shove the ball into the trunk
else {
if (c == 5) { // balls not settled
if (APC_settings[DebugMode]) {
WriteLower(" TRUNK ERROR ");}
Balls = 10;}
else {
if ((c > Balls) || !c) { // more balls in trunk than expected or none at all
WriteUpper(" ");
WriteLower(" ");
ShowAllPoints(0);
BlinkScore(1);
ActivateSolenoid(game_settings[BK_BallEjectStrength], 6);}}} // release again
CheckReleaseTimer = ActivateTimer(5000, Balls, BK_CheckReleasedBall);}
void BK_PlaySpinnerSound(byte Event) { // play the sounds of the lit spinner - start with Event = 0
static byte TimerNo;
static byte Step = 0;
char Filename[13] = "0_2d_001.snd";
if (Event) { // called from timer (spinner not lit any more)
TimerNo = 0;
Step = 0;}
else { // called from spinner switch
if (TimerNo) { // not the first time
KillTimer(TimerNo); // kill old timer
Filename[7] = ((Step+1) % 10) + 48; // determine new filename
Filename[6] = ((Step+1) / 10) + 48;}
PlaySound(51, Filename); // play sound
if (Step < 31) { // still sound files left?
Step++;} // increase file number
TimerNo = ActivateTimer(2000, 1, BK_PlaySpinnerSound);}} // set timer to stop sound cycling
void BK_StopExballParty(byte dummy){
UNUSED(dummy);
LampReturn = 0;
LampPattern = LampColumns;}
void BK_StopExballParty2(byte dummy){
UNUSED(dummy);
LampReturn = 0;
LampPattern = LampColumns;
ReleaseSolenoid(15);
if (!game_settings[BK_MultiballJackpot] || Multiballs == 1) {
StopPlayingMusic();}
PlaySound(61, "0_22.snd");}
void BK_TimedRightMagna(byte dummy) { // runs every second as long as button is pressed
UNUSED(dummy);
if (QuerySwitch(9) && BK_RightMagna[Player]) { // button still pressed and magna seconds left?
BK_RightMagna[Player]--; // reduce magna save seconds
AddBlinkLamp(9, 150*BK_RightMagna[Player]); // adjust blinking rhythm of lamp
BK_TimedRightMagnaTimer = ActivateTimer(1000, 0, BK_TimedRightMagna);}// and come back in 1s
else { // magna save not to be continued
ReleaseSolenoid(9); // turn off magnet
if (!BK_TimedLeftMagnaTimer) {
Switch_Released = DummyProcess;}
BK_EndRightMagna(0);
BK_TimedRightMagnaTimer = 0;}}
void BK_TimedLeftMagna(byte dummy) { // runs every second as long as button is pressed
UNUSED(dummy);
if (QuerySwitch(10) && BK_LeftMagna[Player]) { // button still pressed and magna seconds left?
BK_LeftMagna[Player]--; // reduce magna save seconds
AddBlinkLamp(10, 150*BK_LeftMagna[Player]); // adjust blinking rhythm of lamp
BK_TimedLeftMagnaTimer = ActivateTimer(1000, 0, BK_TimedLeftMagna);}// and come back in 1s
else { // magna save not to be continued
ReleaseSolenoid(10); // turn off magnet
if (!BK_TimedRightMagnaTimer) {
Switch_Released = DummyProcess;}
BK_EndLeftMagna(0);
BK_TimedLeftMagnaTimer = 0;}}
void BK_TimedMagnaSW(byte Switch) { // magna save button released
if (Switch==9 && BK_TimedRightMagnaTimer) { // was it the right switch and is the magna save active?
KillTimer(BK_TimedRightMagnaTimer);
BK_TimedRightMagnaTimer = 0;
ReleaseSolenoid(9); // turn off magnet
BK_EndRightMagna(0);}
if (Switch==10 && BK_TimedLeftMagnaTimer) { // was it the left switch and is the magna save active?
KillTimer(BK_TimedLeftMagnaTimer);
BK_TimedLeftMagnaTimer = 0;
ReleaseSolenoid(10); // turn off magnet
BK_EndLeftMagna(0);}
if (!BK_TimedRightMagnaTimer && !BK_TimedLeftMagnaTimer) { // no magna save active
Switch_Released = DummyProcess;}} // ignore released switches
void BK_GameMain(byte Event) { // game switch events
switch (Event) {
case 1: // plumb bolt tilt
case 2: // ball roll tilt
case 7: // slam tilt
case 46: // playfield tilt
WriteUpper(" TILT WARNING");
ActivateTimer(3000, 0, ShowAllPoints);
break;
case 3: // credit button
BK_AddPlayer();
break;
case 4: // right coin switch
case 5: // center coin switch
case 6: // left coin switch
WriteUpper(" FREE GAME ");
ActivateTimer(3000, 0, ShowAllPoints);
break;
case 8:
digitalWrite(Blanking, LOW); // invoke the blanking
break;
case 9: // right magna save button
if (BK_RightMagna[Player]) { // right magna save available?
if (!game_settings[BK_TimedMagna]) { // no timed magna save
AddBlinkLamp(9, 150);
BK_RightMagna[Player] = 0; // not any more
ActivateTimer(4990, 0, BK_EndRightMagna);
ActivateSolenoid(5000, 9);} // use it for 5 seconds
else { // timed magna active
Switch_Released = BK_TimedMagnaSW;
BK_RightMagna[Player]--; // reduce magna save seconds
AddBlinkLamp(9, 150*BK_RightMagna[Player]);
ActivateSolenoid(6000, 9); // switch on magnet
BK_TimedRightMagnaTimer = ActivateTimer(1000, 0, BK_TimedRightMagna);}} // check again in 1s
break;
case 10: // left magna save button
if (BK_LeftMagna[Player]) { // left magna save available?
if (!game_settings[BK_TimedMagna]) { // no timed magna save
AddBlinkLamp(10, 150);
BK_LeftMagna[Player] = 0; // not any more
ActivateTimer(4990, 0, BK_EndLeftMagna);
ActivateSolenoid(5000, 10);} // use it for 5 seconds
else { // timed magna active
Switch_Released = BK_TimedMagnaSW;
BK_LeftMagna[Player]--; // reduce magna save seconds
AddBlinkLamp(10, 150*BK_LeftMagna[Player]);
ActivateSolenoid(6000, 10); // switch on magnet
BK_TimedLeftMagnaTimer = ActivateTimer(1000, 0, BK_TimedLeftMagna);}} // check again in 1s
break;
case 11: // left outlane
case 12: // right outlane
Points[Player] += Multiballs * 5000; // add 5000 points
ShowPoints(Player); // and show the score
BK_AddBonus(2);
if (BK_LastChance) {
BK_LastChance = false;
BK_LastChanceOver = true; // don't give a last chance again
BK_LastChanceActive = true; // give a last chance ball
AddBlinkLamp(11, 150); // let the last chance lamps blink
AddBlinkLamp(12, 150);}
else {
if (Multiballs == 1) { // not during multiball
StopPlayingMusic();
PlaySound(61, "0_29.snd");}} // BK laughing
break;
case 13: // spinner
//StopPlayingMusic();
if (BK_RightMysteryTimer) {
BK_PlaySpinnerSound(0);
Points[Player] += Multiballs * 2500;} // add 2500 points
else {
PlaySound(51, "0_39.snd");
Points[Player] += Multiballs * 100;} // add 100 points
ShowPoints(Player); // and show the score
break;
case 14: // right ramp
if (BK_LeftMysteryTimer) { // left mystery active?
//StopPlayingMusic();
PlaySound(52, "BK_E19.snd");
ByteBuffer = ((byte)(TimerValue[BK_LeftMysteryTimer])/2.56);
if (ByteBuffer < 20) {
Points[Player] += Multiballs * 20000;} // at least 20000 points
else {
Points[Player] += Multiballs * ByteBuffer * 1000;} // or more
KillTimer(BK_LeftMysteryTimer); // turn off left mystery
BK_LeftMysteryTimer = 0;
RemoveBlinkLamp(14);} // stop the blinking of the mystery lamp
else {
PlaySound(51, "0_39.snd");
Points[Player] += Multiballs * 500;} // add 500 points
ShowPoints(Player); // and show the score
break;
case 15: // right inlane
if (BK_RightMysteryTimer) { // right mystery timer already running?
KillTimer(BK_RightMysteryTimer);} // stop it
else {
AddBlinkLamp(13, 250);} // let the mystery lamp blink
if (BK_RightAfterMagna) { // if it's right after using the right magna save
if (!game_settings[BK_MultiballJackpot] || Multiballs == 1) {
StopPlayingMusic();}
PlaySound(51, "BK_E20.snd");
BK_AddBonus(5);
Points[Player] += Multiballs * 10000;} // add 10000 points
else {
if (!game_settings[BK_MultiballJackpot] || Multiballs == 1) {
StopPlayingMusic();}
PlaySound(50, "0_33.snd");
BK_AddBonus(2);
Points[Player] += Multiballs * 2000;} // add 2000 points
ShowPoints(Player); // and show the score
BK_RightMysteryTimer = ActivateTimer(5000, 0, BK_ResetRightMystery); // and start a timer to reset the mystery
break;
case 16: // left inlane
if (BK_LeftMysteryTimer) { // left mystery timer already running?
KillTimer(BK_LeftMysteryTimer);} // stop it
else {
AddBlinkLamp(14, 250);} // let the mystery lamp blink
if (BK_LeftAfterMagna) { // if it's right after using the right magna save
if (!game_settings[BK_MultiballJackpot] || Multiballs == 1) {
StopPlayingMusic();}
PlaySound(51, "BK_E20.snd");
BK_AddBonus(5);
Points[Player] += Multiballs * 10000;} // add 10000 points
else {
if (!game_settings[BK_MultiballJackpot] || Multiballs == 1) {
StopPlayingMusic();}
PlaySound(50, "0_33.snd");
BK_AddBonus(2);
Points[Player] += Multiballs * 2000;} // add 2000 points
ShowPoints(Player); // and show the score
BK_LeftMysteryTimer = ActivateTimer(5000, 0, BK_ResetLeftMystery); // and start a timer to reset the mystery
break;
case 20: // outhole
ActivateTimer(200, 0, BK_ClearOuthole); // check again in 200ms
break;
case 21: // left slingshot
case 22: // right slingshot
Points[Player] += Multiballs * 10;
ShowPoints(Player);
break;
case 23: // turnaround
Points[Player] += Multiballs * 5000;
ShowPoints(Player);
if (BonusMultiplier < 5) {
BonusMultiplier++;
if ((BonusMultiplier == 5) && (Bonus == 49)) { // full bonus and multiplier?
BK_CycleSwordLights(1);}
else {
AddBlinkLamp(BK_FirstMultLamp+BonusMultiplier-2, 250);
ActivateTimer(2000, BK_FirstMultLamp+BonusMultiplier-2, BK_SetBonusMultiplier);}}
if (BK_LowerExBall[Player]) {
ActivateSolenoid(8000, 15); // ring the bell
PatPointer = BK_ExBallPat;
FlowRepeat = 10;
LampReturn = BK_StopExballParty2;
ShowLampPatterns(1); // show lamp animation
TurnOffLamp(23);
TurnOnLamp(47);
TurnOnLamp(1);
BK_LowerExBall[Player] = false;
ExBalls++;}
else {
PlaySound(50, "0_38.snd");}
break;
case 24: // lower eject hole
if (!BK_DropWait[4]) { // locks are not blocked?
Points[Player] += Multiballs * 5000;
ShowPoints(Player);
if (QueryLamp(24) && Multiballs == 1) { // lower lock lit and no multiball running?
LockedBalls[Player]++;
BK_DropWait[4] = true; // block locks
BK_StartMultiball();}
else {
if (Multiballs > 1) { // multiball running?
if (game_settings[BK_MultiballJackpot]) {
BK_Jackpot(2);
ActivateTimer(2000, 8, DelaySolenoid);
break;}
else {
BK_GiveMultiballs(1);}} // eject ball with some ado
else {
StopPlayingMusic();}
PlaySound(50, "0_31.snd");
ActivateTimer(1000, 8, DelaySolenoid);}} // eject ball
break;
case 25:
case 26: // lower left drop targets
case 27:
if (!BK_DropWait[0]) {
PlaySound(50, "0_38.snd");
BK_DropWait[0] = true;
Points[Player] += Multiballs * 1000;
ShowPoints(Player);
ActivateTimer(200, 0, BK_HandleDropTargets);}
break;
case 29:
case 30: // lower right drop targets
case 31:
if (!BK_DropWait[1]) {
PlaySound(50, "0_38.snd");
BK_DropWait[1] = true;
Points[Player] += Multiballs * 1000;
ShowPoints(Player);
ActivateTimer(200, 1, BK_HandleDropTargets);}
break;
case 33:
case 34: // upper left drop targets
case 35:
if (!BK_DropWait[2]) {
PlaySound(50, "0_38.snd");
BK_DropWait[2] = true;
Points[Player] += Multiballs * 1000;
ShowPoints(Player);
ActivateTimer(200, 2, BK_HandleDropTargets);}
break;
case 36: // jet bumper
Points[Player] += Multiballs * 500;
ShowPoints(Player);