-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdarktower.asm
5458 lines (5114 loc) · 143 KB
/
darktower.asm
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
; *** Chapter 0 page 0
S000 ldx 0
tma
a9aac
br S03E
S00F tcmiy 8
tcy 0
br S01B
S03E tcmiy 0
;
; Rotate the drum to the position targeted in 4/0
; Current position is in 0/0
;
S03D ldx 0
tcy 0
tma
ldx 4
mnea
br S033
retn
S033 ldp 1
call L040
ldx 5
tcy 0
tma
ldx 1
alem
br S018
br S000
S018 mnea
br S01C
ldx 6
tma
ldx 2
alem
br S01C
br S000
S01C ldx 0
tma
a9aac
br S00F
imac
tam
S01B ldx 6
tma
amaac
br S011
ldx 2
tam
ldx 5
tma
br S026
S011 ldx 2
tam
ldx 5
imac
br S00A
S026 amaac
br S00A
ldx 1
tam
br S03D
S00A ldx 2
tcmiy 14
ldx 1
tcy 0
tcmiy 15
br S03D
mnea
; *** Chapter 0 page 1
L040 tcy 8 ; Select the Rotation Sensor
setr
tcy 9 ; Select the Motor
setr
ldx 6
tcy 0
tcmiy 0
ldx 5
tcy 0
tcmiy 0
S077 tka
dan
br S04E
br S077
S079 ldx 6
tcmiy 15
br S071
S04E tcy 5
tya
tcy 8
S075 dyn
br S075
dan
br S075
ldx 6
tcy 0
imac
br S04B
br S078
S04B tam
ldx 5
imac
br S079
S078 tam
S071 tka
dan
br S04E
tcy 8
rstr
tcy 9
rstr
retn
;
; RANDOM routine continues
;
S074 tma ; Pick up value at 3/0, 3/1, 3/2
ldx 4
amaac ; Add 4/0, 4/1, 4/2 to it
call S055 ; Increment 6/0, 6/1, 6/2 if carry
ldx 5
amaac ; Add 5/0, 5/1, 5/2 to it
call S055 ; Increment 6/0, 6/1, 6/2 if carry
ldx 6
amaac ; Add 6/0, 6/1, 6/2 to it
call S055 ; Increment 6/0, 6/1, 6/2 if carry
ldx 3
tamiyc ; Store it at 3/0, 3/1, 3/2 then increment Y
ynec 3 ; We done doing 0-2?
br S074 ; Nope, do the next column
tcy 2
retn
S055 iyc
ldx 6
xma
iac
ldp 7
br L1D4 ; xma, dyn, retn
; *** Chapter 0 page 2
;
; Using the R output in A, scan the K inputs to find a key pressed
;
; For some reason the R output we're looking at is stored in 6/13 with the high-order bit set.
;
S080 tcy 13
tam ; Save the R output we're using at 6/13
a8aac ; Toggle high-order bit
br S09F ; There should have been a carry due to the way it's stored
a8aac ; Nope, add 8 again to get it back (?)
S09F tay
setr ; Set R output addressed by Y
tka ; Pick up K inputs from keyboard
rstr ; Reset R output addressed by Y
tcy 14
xma ; Exchange 6/14 and results of TKA - Look at the last read?
tbit1 0 ; Keyboard row 1 - Dark Tower/Frontier/Inventory - set? (3/7/11)
br S0AE ; Add 3 to accumulator
tbit1 3 ; Keyboard row 2 - Tomb-Ruin/Move/Sanctuary-Citadel - set? (2/6/10)
br S09C ; Add 2 to accumulator
tbit1 2 ; Keyboard row 3 - Haggle/Bazaar/Clear - set? (1/5/9)
br S0B8 ; Add 1 to accumulator
tbit1 1 ; Keyboard row 4 - Yes-Buy/Repeat/No-End - set? (0/4/8)
br S0B1 ; Add nothing to accumulator
;
; No keys were detected, fall through
;
a4aac ; Nothing was read? - A = 4
tam ; Save results at 6/14
;
; Entry point for keyboard read routine. Loop through the R output and scan the K inputs at S080
;
READKBD tcy 13
dman ; Pick up the last R output we looked at and subtract one
br S0B0 ; We're not done scanning
br S085
S0B0 tay
ynec 7
br S080 ; Go back and scan the next R output
S085 tcy 14
tma ; Load 6/14
br S0B1
S0AE iac
S09C iac
S0B8 iac
S0B1 tcy 15
xma ; Swap 6/15 with results
mnea ; Compare this result to the last result
br S08A ; Go back to prompt routine if they're different
tay
ynec 12
br S091
tcy 13
sbit 3 ; Set 6/13 bit 3
tcy 12
tbit1 0 ; 6/12 bit 0 set?
br S08A ; Go back to prompt routine
br S089 ; Success, return?
S091 tcy 12
tbit1 0 ; 6/12 bit 0 set?
br S099
S089 cla
dan
ldp 10
br L2A2 ; TDO, pick up value in 6/15 to Y and return
S099 tcy 13
tbit1 3 ; 6/13 bit 3 set?
br S0AA
S08A ldp 7
br L1C6 ; Jump back into prompt routine and refresh the LEDs some more
S0AA ldp 3
tpc
ldp 1
call PLYTICK
br S089
; *** Chapter 0 page 3
;********************************************************************************
; RANDOM
;
; Generate a random number based on the seed at 3/0-2 and 4/0-2
; 5/0-2 and 6/0-2 are overwritten.
;
; Return value in A (0-F); Y=2
;
; The formula is:
;
; 3/0 * 2 -> 4/0 * 2 -> 5/1
; 3/1 * 2 -> 4/1 * 2 -> 5/2
; 3/2 * 2 -> 4/2
; 3/0 + 4/0 + 5/0 + 6/0 -> 3/0 using 6/0 as carry
; 3/1 + 4/1 + 5/1 + 6/1 -> 3/1 using 6/1 as carry
; 3/2 + 4/2 + 5/2 + 6/2 -> 3/2 using 6/2 as carry
;
; Example: 3/0 = 0; 3/1 = 1; 3/2 = 2
; 4/0 = 0; 4/1 = 0
;
; Results: 0 1 2 Y=2; A=A
; -----
; 3|0 3 A
; 4|0 2 4
; 5|0 0 4
; 6|0 0 0
;********************************************************************************
RANDOM ldx 5
call S0D5 ; Clear 5/0-2
ldx 6
call S0D5 ; Clear 6/0-2
ldx 3
tcy 0
tma ; Pick up value at 3/0 (Starting value)
amaac ; Double it
br S0C9 ; Branch if it overflowed
ldx 4
tam ; Save it at 4/0
S0EF amaac ; Double it
br S0E9 ; Branch if it overflowed
ldx 5
tcy 1
tam ; Save doubled value at 5/1
S0E7 ldx 3
tma ; Pick up value at 3/1 (Starting value)
amaac ; Double it
br S0E3 ; Branch if it overflowed
ldx 4
tam ; Save doubled value at 4/1
S0D6 amaac ; Double it
ldx 5
tcy 2
tam ; Save it at 5/2
ldx 3
tma ; Pick up value at 3/2 (Starting value)
amaac ; Double it
ldx 4
tam ; Save it at 4/2
ldx 3
tcy 0
ldp 1
br S074 ; Out of room here...
S0E3 ldx 4 ; 3/1 doubling caused an overflow...
tamiyc ; Save doubled value at 4/1
ldx 6
imac
tamdyn ; Add one to 6/2
ldx 4
tma ; Pick up 4/1
br S0D6 ; Go back and deal with the next digit
S0E9 ldx 5
tcy 1
tamiyc
ldx 6
imac
tamdyn
br S0E7
S0C9 ldx 4 ; 3/0 doubling caused an overflow
tamiyc ; Save doubled value at 4/0
ldx 6
tcmiy 1 ; Store a 1 at 6/1
tcmiy 2 ; Store a 2 at 6/2
ldx 4
tcy 0
br S0EF ; Go back and deal with the next digit
S0D5 tcy 0
tcmiy 0
tcmiy 0
tcmiy 0
retn
mnea
; *** Chapter 0 page 4
;********************************************************************************
; AD2B10
;
; Perform Base 10 arithmetic on values in scratchpad RAM 4/1-2 and 5/1-2
;
; Add the two-digit base 10 number encoded in 4/1 and 4/2 to the two-digit
; base 10 number encoded in 5/1 and 5/2 giving a three-digit base-10 number
; encoded in 5/0-2.
;
; For example: 0 1 2 (x means doesn't matter--overwritten)
; 4 x 1 9
; 5 x 2 2
;
; Returns: 0 1 2
; 4 0 1 9
; 5 0 4 1
;********************************************************************************
AD2B10 ldx 5
tcy 0
tcmiy 0 ; 5/0 = 0
L107 ldx 4
tcy 0
tcmiy 0 ; 4/0 = 0
SUMB10 cla ; SUMB10 - don't initialize 100s digit
tcy 2 ; Start at 4/2 with A=0
;
; Perform (4/Y + 5/Y) mod 10
;
S13D ldx 4
amaac
ldx 5
amaac ; A = 4/Y + 5/Y (Y = 2-0)
br S11D ; Overflow?
a6aac ; Add 6 to Accumulator - (do a MOD 10 operation; is the result >= 10?)
br S13A ; Yes
a10aac ; Add 10 to Accumulator - (effectively back out the A6AAC operation)
tamza ; Save to 5/Y (Y = 2-0)
br S12B
S11D a6aac
S13A tamza
iac
S12B dyn
br S13D
tcy 0
retn
;
; Generate a random number between 17 and 32 - used to give a base Brigand count
;
L130 ldp 3
call RANDOM ; Get a random number in ACC
ldx 4
tcy 1
tcmiy 0 ; 4/1 = 0
ldx 4
tamdyn ; 4/2 = ACC
ldx 5
tcmiy 0 ; 5/1 = 0
tcmiy 0 ; 5/2 = 0
ldp 4
call AD2B10 ; Copy random number to 5/2 via addition (?!)
ldx 4
tcy 1
tcmiy 1 ; 4/1 = 1
tcmiy 7 ; 4/2 = 7
ldp 4
br AD2B10 ; Add 17 and return
;
; Generate a random number between 9 and 16. Used by Santuary to calculate
; how much food or gold to provide the player.
;
L129 ldp 3
call RANDOM
ldx 4
tamdyn ; 4/2 = ACC
tcmiy 0 ; 4/1 = 0
rbit 3 ; Limit 4/2 to 0-7
ldx 5
tcy 1
tcmiy 0 ; 5/1 = 0
tcmiy 9 ; 5/2 = 9
call AD2B10
ldp 1
tpc
ldp 12
br CPY5TO4 ; Be neat about it and copy the amount up to the top of the formula
;
; Add 16 to 5/1-2
;
ADD16 ldx 4
tcy 1
tcmiy 1 ; 4/1 = 16
tcmiy 6
ldp 4
br AD2B10
; *** Chapter 0 page 5
;********************************************************************************
; DSPRSLT
;
; Display the results of an encounter or inventory
; Called after encounter as well as when Repeat button is hit
;
; Note about status flags. The tests assume the bit being set means
; the inventory doesn't need to be shown. Cleared means display the
; current status.
;********************************************************************************
DSPRSLT ldx 4
tcy 13
tbit1 0 ; Warrior count change during encounter
br S173
;
; Display Warrior count
;
tcy 1 ; Switch drum to Warrior/Food/Beast position
ldp 8
call ROTDRUM
ldp 1
tpc
ldp 6
call CPY2TO5 ; Copy the warrior count for current player to 5/1 and 5/2
ldp 8
call BUF2DSP ; Update display buffer with contents of 5/1 and 5/2
ldp 9
call L241 ; Light top window and update display from display buffer???
S173 ldx 4
tcy 13
tbit1 1 ; Food change during encounter
br S157
;
; Display Food
;
tcy 1 ; Switch drum to Warrior/Food/Beast position
ldp 8
call ROTDRUM
ldp 1
tpc
ldp 12
call CPY1TO5 ; Copy the gold amount for current player to 5/1 and 5/2
ldp 8
call BUF2DSP ; Update display buffer with contents of 5/1 and 5/2
ldp 9
call L25F
S157 ldx 4
tcy 13
tbit1 3 ; Beast found during encounter
br S152
;
; Display Beast
;
ldx 1
tcy 3
tbit1 0 ; Check inventory for Beast
br S176
br S152
S176 tcy 1 ; Switch drum to Warrior/Food/Beast position
ldp 8
call ROTDRUM
ldp 9
call LTLWRCL ; Light lower window
S152 ldx 4
tcy 14
tbit1 0 ; Scout found during encounter
br S155
;
; Display Scout
;
ldx 1
tcy 3
tbit1 3 ; Check inventory for Scout
br S14C
br S155
S14C tcy 2 ; Switch drum to Scout/Healer/Gold position
ldp 8
call ROTDRUM
ldp 9
call LTTOPCL ; Light Scout and clear display
S155 ldx 4
tcy 14
ldp 6
tbit1 1 ; Healer found during encounter?
br L1B7
br S180
; *** Chapter 0 page 6
;
; Display Healer
;
S180 ldx 1
tcy 3
tbit1 1 ; Check inventory for Healer
br S19F
br L1B7
S19F tcy 2 ; Switch drum to Scout/Healer/Gold position
ldp 8
call ROTDRUM
ldp 9
call LTMIDCL ; Light Healer and clear display
L1B7 ldx 4
tcy 13
tbit1 2 ; Gold found during encounter?
br S1B0
;
; Display Gold
;
tcy 2 ; Switch drum to Scout/Healer/Gold position
ldp 8
call ROTDRUM
ldp 1
tpc
ldp 12
call CPY0TO5
ldp 8
call BUF2DSP ; Update display buffer with contents of 5/1 and 5/2
ldp 9
call L27B ; Light bottom window and update display from display buffer???
S1B0 ldx 4
tcy 15
tbit1 0 ; Gold Key found during encounter?
br S1B6
;
; Display Gold Key
;
ldx 2
tcy 3
tbit1 3 ; Check inventory for Gold Key
br S1B1
br S1B6
S1B1 tcy 3 ; Switch drum to Gold Key/Silver Key/Brass Key
ldp 8
call ROTDRUM
ldp 9
call LTTOPCL ; Light Gold Key and clear display
S1B6 ldx 4
tcy 14
tbit1 3 ; Silver Key found during encounter?
br S18C
;
; Display Silver Key
;
ldx 2
tcy 3
tbit1 2 ; Check inventory for Silver Key
br S1A2
br S18C
S1A2 tcy 3 ; Switch drum to Gold Key/Silver Key/Brass Key
ldp 8
call ROTDRUM
ldp 9
call LTMIDCL ; Light Silver Key and clear display
S18C ldx 4
tcy 14
ldp 7
tbit1 2 ; Brass Key found during encounter?
br L1DF
;
; Display Brass Key
;
ldx 2
tcy 3
tbit1 1 ; Check inventory for Brass Key
br L1C0
br L1DF
mnea
; *** Chapter 0 page 7
L1C0 tcy 3 ; Switch drum to Gold Key/Silver Key/Brass Key
ldp 8
call ROTDRUM
ldp 9
call LTLWRCL ; Light lower window
L1DF ldx 4
tcy 15
tbit1 1 ; Sword resulting from encounter?
br S1FA
;
; Display Sword if in inventory
;
ldx 1
tcy 3
tbit1 2 ; Check inventory for Sword
br S1F9
br S1FA
S1F9 tcy 4 ; Switch drum to Dragon/Sword/Pegasus
ldp 8
call ROTDRUM
ldp 9
call LTMIDCL ; Light Sword and clear display
;
; Display Pegasus?
;
; Note, Pegasus isn't an inventory item so there is no check for it
;
S1FA ldx 4
tcy 15
tbit1 2 ; Pegasus resulting from encounter?
br S1C5
tcy 4 ; Switch drum to Dragon/Sword/Pegasus
ldp 8
call ROTDRUM
ldp 9
call LTLWRCL ; Light lower window
S1C5 retn
;********************************************************************************
; PROMPT - Prompt user for input
;
; Update display with contents of 7/14 and 7/15, flash and wait for keypress
;
; Return key pressed in Y:
; 0 = Yes/Buy 6 = Move
; 1 = Haggle 7 = Frontier
; 2 = Tomb/Ruin 8 = No/End
; 3 = Dark Tower 9 = Clear
; 4 = Repeat 10 = Sanctuary/Citadel
; 5 = Bazaar 11 = Inventory
;********************************************************************************
PROMPT ldx 6
tcy 12
sbit 0
rbit 2 ; Don't update LEDs immediately (?)
L1F8 ldx 6
tcy 13
rbit 3
L1C6 ldp 10
call REFRLED
ldp 10
call REFRLED
ldp 10
call REFRLED
ldx 3
tcy 2
tma
a7aac
call S1CA
tam
;
; Set things up before reading the keyboard
;
ldx 6
tcy 13
rbit 2
sbit 1
sbit 0
tcy 14
tcmiy 0
ldp 2
br READKBD
S1CA tamdyn
imac
retn
L1D4 xma
dyn
retn
mnea
; *** Chapter 0 page 8
;
; Rotate the player RAM buffer so the next player is in the first
; position
;
L200 ldx 0 ; Rotate 0/1-12 left three times
call S230
call S230
call S230
ldx 1 ; Rotate 1/1-12 left three times
call S230
call S230
call S230
ldx 2 ; Rotate 2/1-12 left three times
call S230
call S230
call S230
ldx 3
tcy 11
tma ; Pick up the current player from 3/11
a12aac ; Add 12 to generate an overflow if we're on player 4
br S21D ; Overflow, it's P0 right now
a4aac ; Add 4 to get us back to where we should be
S21D iac ; Next player...
tam ; Update current player at 3/11
tcy 9
alem ; Check that we're not exceeding the total number of players playing
br S218 ; We're done
br L200 ; Oops. Do another rotation
S218 retn
;
; Rotate the current register file words 1-12 left one word
;
S230 tcy 12 ; Start at 12
tma ; Get a copy of what's at the current position
dyn ; Move pointer left
S205 xma ; Swap
dyn ; Move pointer left
ynec 0 ; Are we pointing at zero?
br S205 ; Nope, do it again
tcy 12 ; Final step, copy what was at 1
tam ; To 12
retn
;********************************************************************************
; RND0TO2 - Return a random value from 0 to 2 in A
;
; 11 - 15 - A = 2
; 6 - 10 - A = 1
; 0 - 5 - A = 0
;********************************************************************************
RND0TO2 ldp 3
call RANDOM
L20D tcy 1
S21B a5aac
br S234
dyn
br S21B
S234 tya
iac
retn
;********************************************************************************
; BUF2DSP - Load 5/1 and 5/2 into the display buffer 7/14 and 7/15 respectively
;********************************************************************************
BUF2DSP ldx 5
tcy 1
tma
ldx 7
tcy 14
tam
ldx 5
tcy 2
tma
ldx 7
tcy 15
tam
retn
;********************************************************************************
; ROTDRUM - Rotate the drum to the position specified in Y
;********************************************************************************
ROTDRUM tya
ldx 4
tcy 0
tam
ldp 0
br S03D
; *** Chapter 0 page 9
;********************************************************************************
; LTTOPCL - Clear display and light top lamp
;********************************************************************************
LTTOPCL call S25A ; Load blanks into 7/14-15
L241 call S248 ; Set for immediate update of LEDS (6/12 bit 2 set)
tcy 7 ; Select upper lamp
br S26F
;********************************************************************************
; LTMIDCL - Clear display and light middle lamp
;********************************************************************************
LTMIDCL call S25A ; Load blanks into 7/14-15
L25F call S248 ; Set for immediate update of LEDS (6/12 bit 2 set)
tcy 6 ; Select middle lamp
br S26F
;********************************************************************************
; LTLWRCL - Clear display and light lower lamp
;********************************************************************************
LTLWRCL call S25A ; Load blanks into 7/14-15
L27B call S248 ; Set for immediate update of LEDS (6/12 bit 2 set)
tcy 5 ; Select lower lamp
;
; Light the lamp referenced in Y, beep, update the LEDs and loop over REFRLED
;
S26F setr ; Light the selected lamp
ldp 3
tpc
ldp 13
call PLYBEEP
L267 ldx 6
tcy 12
sbit 2 ; 6/12 bit 2 set - Immediate update of LEDs
;
; Call REFRLED $BF (191) times
;
ldx 6
tcy 0
tcmiy 15 ; 6/0 = 15
tcmiy 11 ; 6/1 = 11
S26C tam ; 6/2 = A
ldp 10
call REFRLED
ldx 6
tcy 0
dman ; Acc = 6/0 - 1
br S26C ; Update 6/0 and loop
tamiyc ; Acc has overflowed; update 6/0 and focus on 6/1
dman ; Decrement 6/1
br S26C ; Update 6/1 and loop
;
; We've called REFRLED enough times; turn off the lamps
;
tdo
tcy 7 ; Select Upper lamp
rstr ; Turn it off
tcy 6 ; Select Middle lamp
rstr ; Turn it off
tcy 5 ; Select Lower lamp
rstr ; Turn it off
retn
;
; Load blanks into display buffer (7/14-15)
;
S25A ldx 7
tcy 14
tcmiy 15 ; 7/14 = 15 (" ")
tcmiy 15 ; 7/15 = 15 (" ")
retn
;
; Set for immediate update of LEDs on call to REFRLED (6/12 bit 2 set)
;
S248 ldx 6
tcy 12
sbit 2
retn
;********************************************************************************
; CPYBRIG - Copy the current brigand count (3/12-13) to 5/1-2 for base 10 math
;********************************************************************************
CPYBRIG ldx 3
tcy 12
tma
ldx 5
tcy 1
tam
ldx 3
tcy 13
tma
ldx 5
tcy 2
tam
retn
mnea
; *** Chapter 0 page 10
;********************************************************************************
; REFRLED
;
; Refresh the contents of the LEDs either with new data or handle flashing
;
;********************************************************************************
REFRLED ldx 6
tcy 12
tbit1 2 ; 6/12 Bit 2 - Immediate update of LEDs. Bypass flashing.
br S2A1
;
; Decrement countdown timer in 7/12-13. When it expires, it checks what's currently displayed
; in the LED segments (6/12 Bit 1). If it's reset, it does a TDO and clears the display. It then
; toggles the bit.
;
ldx 7
tcy 13
dman
br S2AB
tamdyn ; 7/13 = 7/13 - 1
dman ; A = 7/12 - 1
br S2AB
;
; Countdown has expired. Acc has 15 (" ") in it due to underflow. If 6/12 bit 1 is reset, the
; display has data in it. Blank the display with a TDO. In either case, toggle 6/12 bit 1.
;
tcmiy 1 ; Reset 7/12 - $1F
ldx 6
tcy 12
tbit1 1 ; 6/12 Bit 1 - Display currently blank
br S2BA
sbit 1 ; Set 6/12 Bit 1 - Display now blank
tdo ; Transfer Accumulator to O outputs - Clear display (Load 15 [" "] into LED)
br S29A
S2BA rbit 1 ; Clear 6/12 Bit 1 - Display now not blank
br S2A1
S2AB tam
ldx 6
tcy 12
tbit1 1 ; Is display currently blank (6/12 Bit 1 set)?
br S29A ; Bit 1 is set. Skip update and just delay
;
; Update the LED segments with the contents of 7/14-15
;
S2A1 tma ; Load 6/12
tay ; Save it...
a8aac ; Toggle 6/12 bit 3
br S2AE ; It's now clear; we want the Status Latch set to 1
tay ; It's now set; we want the Status Latch set to 0
S2AE ynea ; Update Status Latch to select correct LED segment based on prior steps
tcy 12
tam ; Update 6/12 with the new state of 6/12 Bit 3
ldx 7
tcy 14 ; Select 7/14
a8aac ; Flip bit 3 of Accumulator BACK to test it (from the earlier work on 6/12)
br S2B6 ; There was a carry, we have the right segment (Bit 3 was set)
tcy 15 ; Switch to 7/15 (Bit 3 was clear)
S2B6 tma ; Pick up value in the referenced LED display buffer
tdo ; Transfer Accumulator to O outputs - Update the LED display
;
; Display has been updated; delay for 255 loops and return
;
S29A tcy 15
tya
S2A9 dyn
br S2A9
dan
br S2A9
retn
;
; Used by read keyboard routine
;
L2A2 tdo
ldx 6
tcy 15
tmy
retn
;
; Copy 5/2-0 to 7/2-0
;
L28C tcy 2
S299 ldx 5
tma
ldx 7
tamdyn
br S299
retn
;
; This code looks to be unused... Odd. There's also a chunk of code