-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTCEROM.MAC
1716 lines (1589 loc) · 34 KB
/
TCEROM.MAC
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
.TITLE TCEROM
.INCLUDE WSCOMN ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;INTERNAL ROUTINES
.GLOBL EEACC,EEACCU,EEACCT,EECKSM,EEINIT,EEOPT,EEOPT1,EEOPT3,EEUTIM,CHKEE,EEINI0
.GLOBL EETEMP,EETMP2,EETMP3,SUMMIT,TEMPEE,TMPEE2,TMPEE3
;EXTERNAL ROUTINES
.GLOBL VWBYTE,VWNIBL,MESSON,DOMESS,DOMES2,SETINT,BINBCD,WAITFRAME
;EXTERNAL GLOBAL OFFSETS
;RHEOSTAT
;*** IRQ/MAINLINE INTERACTIONS !!!!
RH$LO ==0 ;LO VALUE-MINIMUM
RH$LT ==1 ;LO VALUE ON TRIAL
RH$SP ==2 ;SPREAD MULTIPLIER
RH$ST ==3 ;SPREAD CHANGE TIMER
RH$NML ==4 ;NORMALZIED POT VALUE
RH$POS ==5 ;SITE POSITION
RH$RAT ==7 ;RATE OF TURN
RH$RSD ==8 ;MAGIC TIC RESIDUE
RH$IZ ==9 ;SIZE OF BLOCK
;EXTERNAL LOCATIONS
.GLOBL EEROM,EEROMZ,EEBUF,NVRRCL,NSTORE
.GLOBL DUPOPT,EECK0
.GLOBL SAVSCR,SAVINT,EECK1
.GLOBL POTSAV,AMECH,LMECH,RMECH,GAMES,TIMEON,TTIME
.GLOBL HISTOG,ZHISTOG,ENDGAM,EECK2
.GLOBL OPTS0,EECK3,RESETS
.GLOBL BCD
.GLOBL GM.DWAV
.GLOBL INTINT,INTSCR
.GLOBL ITEMP
.GLOBL NVTSTR,NVADDR
.GLOBL RHEOP,RHEOY
.GLOBL SI.RSY
.GLOBL TIMER
.GLOBL VGCNTR,VGMSGA,VJCOLN,VGCOLR,VGCGRN,VGCRED
.GLOBL WTCHDG
.GLOBB BT.SUP,FRAME,R.OPT1,R.OPT2
.GLOBB MS.ACC,MS.XIT,MS.TST,MS.RES
.GLOBB MS.OPT,MS.VLC,MS.LMV,MS.RMV,MS.BAV,MS.SLV,MS.DIF,MS.RHS
.GLOBB MS.RAC,MS.ROP,MS.BSV,MS.MUV,MS.TER,MS.GNV,MS.BNV
.GLOBL NAREA,TEMP,TEMP2,TMPCNT,EEVAL,EEINDX,EECOIN,$CCTIM,GTIME
.GLOBB GN.SWE,LFIRBT,RFIRBT
.CSECT TCEROM
; ***************************************
DEVSYS ==0 ;10101010101 IF DEVSYS IS 1, WILL GET BRKS AT STRATEGIC POINTS
RESONLY ==0 ;IF RESONLY IS 1, ONLY ALLOW CHANGES TO RESET OPTIONS IN OPTION MODE
; ***************************************
.PAGE
.SBTTL DISPLAY ACCOUNTING INFO
.REPT 0
**********************************
*
* EEACC
*
**********************************
DESCRIPTION: DISPLAYS THE ACCOUNTING INFO FROM THE EEROM
IN:
OUT:
USE: EEROM,TEMP(8),TEMP2(8)
.ENDR
EEACC:
LDA #MS.ACC
BEGIN
JSR MESSON
INCA
CMPA #MS.OPT
HSEND
LDA #MS.XIT ;EXIT MESSAGE
JSR MESSON
;---
LDD #VGCOLR+<VGCRED*100>;SETUP COLOR FOR DATA MESSAGES
STD (Y)++
LDX #AMECH ;START WITH AUX COIN DATA
LDU #T.ACCP ;TABLE OF POSITIONS
BEGIN
LDD (U)++ ;SET POSITION
STD (Y)++
LDD #1FFF&048.
STD (Y)++
STU TEMP ;SAVE U--- VWNIBL ALTERS U
LDB #5
STB BT.SUP
LDB #05 ;VIEW 6 NIBBLES
BEGIN
LDA (X)+
JSR VWNIBL
DECB
MIEND
LDD #VGCNTR
STD (Y)++
LDU TEMP ;GET POINTER TO POS TABLE BACK
CMPX #TTIME
HSEND
;---
;DISPLAY HIGHEST LEVEL ATTAINED
LDD T.ACCP+6.
STD (Y)++
LDD #1FFF&316.
STD (Y)++
LDA #01
STA BT.SUP ;SUPRESS 1 DIGIT
LDA ENDGAM ;BCD VALUE OF HIGHEST WAVE ATTAINED ( HI NIBL )
JSR VWNIBL
LDA ENDGAM+1 ;LO NIBL
JSR VWNIBL
LDD #VGCNTR
STD (Y)++
;---
;GET TOTAL COINS PAID
LDX #RMECH ;GET RIGHT MECH DATA INTO TEMP
JSR EETEMP
LDU #TEMP2 ;GET LEFT MECH DATA INTO TEMP2
LDX #LMECH
JSR EETMP2
LDA TEMP+2 ;3 BYTE ADD, RESULT IN TEMP
ADDA TEMP2+2
DAA
STA TEMP+2
LDA TEMP+1
ADCA TEMP2+1
DAA
STA TEMP+1
LDA TEMP ;NOW THE MSB
ADCA TEMP2
DAA
STA TEMP
;DISPLAY TOTAL COINS
LDD T.ACCP+8 ;POSITION
STD (Y)++
LDD #1FFF&048.
STD (Y)++
LDB #5
STB BT.SUP
LDA TEMP ;DATA
JSR VWBYTE
LDA TEMP+1
JSR VWBYTE
LDA TEMP+2
JSR VWBYTE
LDD #VGCNTR ;CENTER
STD (Y)++
;---
LDX #TTIME ;DISPLAY TOTAL GAME TIME
JSR EETEMP ;MOVE IT TO TEMP
JSR TMPMUL ;GOT TO MULTIPLY BY 4 FOR SECONDS
LDD T.ACCP+14. ;POSITION IT
STD (Y)++
LDD #1FFF&048.
STD (Y)++
LDB #7
STB BT.SUP
LDA TEMP
JSR VWBYTE
LDA TEMP+1
JSR VWBYTE
LDA TEMP+2
JSR VWBYTE
LDA TEMP+3
JSR VWBYTE
LDD #VGCNTR
STD (Y)++
;---
LDX #TIMEON ;DISPLAY TOTAL TIME ON
JSR EETEMP ;MOVE IT TO TEMP
JSR TMPMUL ;GOT TO MULTIPLY BY 4 FOR SECONDS
LDD T.ACCP+16. ;POSITION IT
STD (Y)++
LDD #1FFF&048.
STD (Y)++
LDB #7
STB BT.SUP
LDA TEMP
JSR VWBYTE
LDA TEMP+1
JSR VWBYTE
LDA TEMP+2
JSR VWBYTE
LDA TEMP+3
JSR VWBYTE
LDD #VGCNTR
STD (Y)++
;---
;CALCULATE AND SHOW AVERAGE GAME TIME
LDX #GAMES-2 ;MOVE NUMBER OF GAMES PLAYED TO TEMP+1
JSR EETEMP
CLR TEMP ;LEADING 0
LDA TEMP+1 ;NUMBER OF GAMES = 00?
ORA TEMP+2
ORA TEMP+3
IFNE ;NO, THEN I GUESS I WON'T DIVIDE BY 0
LDX #TTIME ;GET TOTAL GAME TIME TO TEMP2
LDU #TEMP2
JSR EETMP2
JSR DIVIDE ;TEMP2/TEMP RESULT IN TEMP ( GAME TIME/# OF GAMES)
;ADJUST ANSWER FOR M:S FORMAT
LDA TEMP
ANDA #0F
CMPA #0F ;E MEANS 56 SECONDS ( 14*4) F IS 60 SECONDS
LDA TEMP
IFHS ;60 SECONDS GETS ADDED IN AS A MINUTE (HI NIBBLE)
INC TEMP
ENDIF
LSRA ;HI NIBBLE REALLY 64 SECONDS NOT 60 SECONDS
LSRA ;SO ADD 64 SECOND NIBBLE TO 4 SECOND NIBBLE
LSRA
LSRA
ADDA TEMP
STA TEMP ;ADJUSTED MINUTES+SECONDS/4 IE. M:S
ANDA #0F
CMPA #0F
IFHS ;IF 60 SECONDS ADD 1 TO MINUTES
INC TEMP ;0F+1=10
ENDIF
ENDIF
LDD T.ACCP+10. ;SHOW IT
STD (Y)++
LDD #1FFF&048.
STD (Y)++
LDA TEMP
JSR TIME
LDD #VGCNTR
STD (Y)++
;---
;CALCULATE AND SHOW PERCENTAGE OF PLAY/TIMEON
LDX #TIMEON ;GET TOTAL TIME ON TO TEMP
JSR EETEMP
LDA TEMP ;NO PLAY TIME?
ORA TEMP+1
ORA TEMP+2
ORA TEMP+3
IFNE ;WON'T DIVIDE BY ZERO
LDX #TTIME+2 ;GET PLAY TIME ON TO TEMP2 ( 2 LSD IGNORED )
LDU #TEMP2
JSR EETMP2
CLR TEMP2+3 ; * 100.
JSR DIVIDE
ENDIF
LDD T.ACCP+12. ;SHOW IT
STD (Y)++
LDD #1FFF&048.
STD (Y)++
CLRA ;CONVERT FROM HEX
LDB TEMP
LDX #10
JSR BINBCD
LDB #1
STB BT.SUP
LDA BCD+2
JSR VWBYTE
LDD #VGCNTR
STD (Y)++
;---
;DISPLAY HISTOGRAM OF GAME TIMES
LDB #<ZHISTOG-HISTOG-2>/2 ;START AT LARGEST TIME ( 6:00 )
STB TEMP
LDU #T.HISP
STU TEMP+2
BEGIN
LDU TEMP+2
LDD (U)++ ;Y POSITION
STD (Y)++
CMPU #T.HISP+20. ;PAST HALF WAY POINT + 2 ( U++ ABOVE )
IFHS ;YES, PUT DATA ON LEFT HALF OF SCREEN
LDD #1FFF&-300.
ELSE ;RIGHT SIDE OF SCREEN
LDD #1FFF&100.
ENDIF
STD (Y)++
STU TEMP+2
LDX #T.HIST-1 ;TIME SLOT TIME
LDB TEMP
LDA B(X)
JSR TIME ;DISPLAY TIME IN M:S FORMAT
LDD VGMSGA ;2 BLANKS
STD (Y)++
STD (Y)++
LDB #0
STB BT.SUP
LDX #HISTOG ;HISTOGRAM DATA
LDB TEMP
ASLB
LDA B(X) ;HIGH NIBBLE
JSR VWNIBL ;SHOW IT
INCB
LDA B(X)
JSR VWNIBL
LDD #VGCNTR ;CENTER INSTRUCTION
STD (Y)++
DEC TEMP
MIEND
RTS
.PAGE
.SBTTL DIVIDE
.REPT 0
**********************************
*
* DIVIDE
*
**********************************
DESCRIPTION: DECIMAL DIVIDE TEMP2/TEMP.
USES ITERATIVE ADD OF -TEMP UNTIL WRAP.
IN: TEMP2 =NUMERATOR
TEMP =DENOMINATOR ( NON-ZERO )
OUT: TEMP =ANSWER
USE: TEMP(4),TEMP2(4)
.ENDR
DIVIDE:
LDX #TEMP+4 ;PERFORM DECIMAL NEGATE OF DENOMINATOR
LDA #01
STA TMPCNT ;SETUP FOR NEGATE
LDB #03 ;4 BYTES WORTH
BEGIN
LDA #99
SUBA -(X)
ADDA TMPCNT
DAA
STA (X)
IFCC ;PROPAGATE THE CARRY
CLR TMPCNT
ELSE
LDA #01
STA TMPCNT
ENDIF
DECB
MIEND
LDB #0FF
BEGIN ;START DIVIDE
INCB
CMPB #0EF
BEQ 40$ ;OVERFLOW---LEAVE AT MAX
LDA TEMP2+3 ;START WITH LSB
ADDA TEMP+3 ;SUBTRACT DENOMINATOR ( ADD NEGATIVE IN DECIMAL)
DAA
STA TEMP2+3
LDA TEMP2+2
ADCA TEMP+2
DAA
STA TEMP2+2
LDA TEMP2+1
ADCA TEMP+1
DAA
STA TEMP2+1
LDA TEMP2+0
ADCA TEMP+0
DAA
STA TEMP2+0
CCEND ;DONE WHEN STAYS NEGATIVE ( DECIMAL ) NO CARRY
40$:
STB TEMP
RTS
.PAGE
.SBTTL TMPMUL
.REPT 0
**********************************
*
* TMPMUL
*
**********************************
DESCRIPTION: PERFORM DECIMAL MULTIPLY TEMP(4) * 4
USE SUCCESIVE ADDS
IN: TEMP(4) IS BCD NUMBER TO MULT
OUT: TEMP(4) IS RESULT
USE: TEMP(4)
.ENDR
TMPMUL:
BSR TMPML2 ;DO IT TWICE
TMPML2: ;ADD TEMP TO TEMP IN DECIMAL
CLC ;START WITH CARRY CLEAR
LDB #03 ;4 BYTES WORTH
LDX #TEMP+3 ;START WITH LSD
BEGIN
LDA (X)
ADCA (X)
DAA
STA (X)
LEAX -1(X)
DECB
MIEND
RTS
.PAGE
.SBTTL COIN ACOUNTING UPDATE
.REPT 0
**********************************
*
* EEACCU
*
**********************************
DESCRIPTION: UPDATE COIN COUNTERS IN EEROM.
( CALLED EVERY 16MS. )
IN: NONE
OUT: A,B,X,U ALTERED
USE: AMECH(6),RMECH(6),LMECH(6),TEMP(4),EECOIN
.ENDR
EEACCU:
LDA #2 ;VERIFY AREA 2
JSR SUMMIT ;CALCULATES CHECKSUM WITHOUT STORING
IFEQ ;CHECKSUM OK, THEN CONTINUE-- ELSE BAD DATA
CLRA ;START WITH 0
LDB $CCTIM ;GET COIN COUNTER DATA-ALL 3
ASLD ;GET COUNTER DATA INTO A
LDB $CCTIM+1
ASLD
LDB $CCTIM+2
ASLD
TFR A,B ;NEW DATA IN B
EORB EECOIN ;1=CHANGE IN STATE
ANDB EECOIN ;1=COIN COUNTER JUST TURNED ON
STA EECOIN ;NEW STATE
LDX #RMECH
BEGIN
LSRB
IFCS
LDU #ITEMP
JSR EETMP2 ;MOVE EE TO TEMP
LDA ITEMP+2 ;LSB
ADDA #01
DAA
STA ITEMP+2
LDA ITEMP+1
ADCA #00
DAA
STA ITEMP+1
LDA ITEMP+0
ADCA #00
DAA
STA ITEMP+0
LDU #ITEMP
JSR TMPEE2 ;PUT BACK IN EE ROM
LDA #2 ;CALCULATE CHECKSUM FOR AREA 2
STB ITEMP+3 ;SAVE IT
JSR EECKSM
LDB ITEMP+3 ;GET B BACK
ENDIF
LEAX -6(X) ;NEXT MECH
CMPX #AMECH ;DONE?
LOEND
ENDIF
RTS
.PAGE
.SBTTL UPDATE TOTAL GAME TIME
.REPT 0
**********************************
*
* EEACCT
*
**********************************
DESCRIPTION: ADD GAME TIME TO TOTAL TIME.
CALLED ONCE AT END OF GAME.
ALSO UPDATE TOTAL TIME ON.
IN: TTIME=TOTAL ACCRUED TIME (EEROM)
GTIME=TIME FOR LAST GAME
TIME =RAM BASED TOTAL TIME ON
OUT: A,B,X,U ALTERED
USE: TEMP(4),TTIME(8),HISTOG(36.)
.ENDR
EEACCT: ;UPDATE TOTAL GAME TIME
LDA #2
JSR CHKEE ;MAKE SURE AREA 2 IS VALID
LDX #TTIME ;TOTAL GAME TIMES
JSR EETEMP ;GET TOTALS INTO TEMPS
LDA TEMP+3 ;ADD GAME TIME TO TOTAL
ADDA GTIME+1
DAA
STA TEMP+3
LDA TEMP+2
ADCA GTIME+0
DAA
STA TEMP+2
LDA TEMP+1
ADCA #00
DAA
STA TEMP+1
LDA TEMP+0
ADCA #00
DAA
IFCC ;DO NOT OVERFLOW THE MSB
STA TEMP+0
ENDIF
LDA #3 ;DO FOUR BYTES
STB TMPCNT
LDU #TEMP
JSR TMPEE3 ;PUT DATA BACK TO EEROM
;---
;UPDATE NUMBER OF GAMES PLAYED
LDX #GAMES ;NUMBER OF GAMES
JSR EETEMP ;PUT IT IN TEMPS
LDA TEMP+2
ADDA #01
DAA
STA TEMP+2
LDA TEMP+1
ADCA #00
DAA
STA TEMP+1
LDA TEMP+0
ADCA #00
DAA
STA TEMP+0
JSR TEMPEE ;PUT IT BACK IN EEROM
;---
;RECORD HIGHEST LEVEL EVER ATTAINED
LDX #ENDGAM
JSR EETEMP ;GET CURRENT HIGHEST TO TEMP
LDA GM.DWAV ;END OF GAME LEVEL ( IN BCD OR DECIMAL )
CMPA TEMP ;COMPARE TO RECORDED LEVEL
IFHI ;THIS ONE IS HIGHER, USE IT INSTEAD
STA TEMP
CLR TEMP+1 ;CLEAR UNUSED NIBBLES
CLR TEMP+2
JSR TEMPEE ;PUT IT BACK INTO EEROM
ENDIF
;---
;UPDATE HISTOGRAM INFO
LDX #ZHISTOG-2 ;LAST ENTRY POINTER
LDA GTIME ;MSB-IF NOT 0 THEN OVER 6:00, SO PUT IN LAST ENTRY
IFEQ ;FIND OUT WHERE TO PUT DATA
LDA GTIME+1
LDX #HISTOG ;BEGINNING OF HISTOGRAM DATA
LDB #9A ;GET NEGATIVE OF T.HIST ( THIS WON'T WORK FOR ALL)
SUBB T.HIST
STB TEMP
BEGIN
ADDA TEMP
DAA
BCC 20$ ;FOUND ITS NICHE
LEAX 2(X)
CMPX #ZHISTOG-2
HSEND ;IF NOT FOUND, PUT IN LAST ONE ANYWAY
ENDIF
20$: LDA 1(X) ;ADD 1
ANDA #0F
ADDA #01
DAA
STA 1(X)
ANDA #0F0
IFNE ;UPDATE HI NIBBLE
LDA (X)
ANDA #0F
ADDA #01
DAA
STA (X)
ANDA #0F0
IFNE ;OVERFLOW-BAD NEWS DIVIDE ALL HISTOGRAM VALUES BY 2
LDX #HISTOG
BEGIN
LDA (X)
ASLA
ASLA
ASLA
ASLA
STA TEMP
LDA 1(X)
ANDA #0F
ADDA TEMP
BITA #10 ;WILL DIVIDE BY 2 WORK?
IFNE ;NO
SUBA #06 ;THIS CORRECTS IT
ENDIF
LSRA
STA 1(X)
LSRA
LSRA
LSRA
LSRA
STA (X)
LEAX 2(X)
CMPX #ZHISTOG
HSEND
LDA #5 ;1/2 OF 100 IS 50
STA (U)
LDA #0
STA 1(U)
ENDIF
ENDIF
;---
;SAVE POT VALUES
LDA RHEOP+RH$LO
STA TEMP
LDA RHEOP+RH$SP
STA TEMP+1
LDA RHEOY+RH$LO
STA TEMP+2
LDA RHEOY+RH$SP
STA TEMP+3
LDX #POTSAV ;MOVE THEM FROM TEMP TO POTSAV IN EEROM
LDU #TEMP
LDA #3 ;4 BYTES WORTH
JSR TMPEE3
;---
EEUTIM: ;UPDATE TOTAL TIME ON
LDX #TIMEON ;MOVE TIMEON FROM EEROM
JSR EETEMP
SEI ;STOPS INTERRUPT INTERACTION
LDU TIMER+2 ;RAM BASED TIME
LDD TIMER
CLI
CMPD TEMP ;NEW TIME SHOULD BE LARGER THAN OLD
BHI 40$ ;OK USE THIS AS NEW TIME
BLO 50$ ;LESS, DON'T USE IT AND SET IT TO OLD
CMPU TEMP+2 ;CHECK THE LOWER BYTES
BLS 50$
40$:
STD TEMP ;SAVE NEW TIME
STU TEMP+2
LDX #TIMEON
LDU #TEMP
LDA #03
JSR TMPEE3 ;PUT IT BACK INTO EEROM
BRA 60$
50$:
LDD TEMP ;RESTORE TIME FROM TIMEON
STD TIMER
LDD TEMP+2
STD TIMER+2
60$:
;---
LDA #2 ;SET NEW CHECKSUM
JMP EECKSM ;AND RETURN
.PAGE
.SBTTL SET EEROM AREA TO DEFAULT VALUES
.REPT 0
**********************************
*
* EECPY
*
**********************************
DESCRIPTION: COPY DEFAULT VALUES TO EEROM AREA(A)
IN: A=EEROM AREA NUMBER
OUT: B,X,U ALTERED
USE: EEROM
.ENDR
EECPY:
CMPA #NAREA ;LEGAL?
IFLO ;YES, GO AHEAD PLEASE
CMPA #02 ;AREAS 0 AND 1 GET DEFAULTS DIFFERENTLY
IFHS ;GET DEFAULTS FROM T.DFLT
LDX #T.AREA+1 ;GET END OF AREA
LDB A(X) ;POINTS TO SOMEWHERE IN EEROM PAGE
SUBB #02 ;LIMIT IS FIRST NIBBLE OF CHECKSUM
STB TEMP+1
LDB #EEROM/100 ;WHAT PAGE IS NON-VOLATILE RAM
STB TEMP ;(TEMP,TEMP+1) IS LIMIT
LDX #T.AREA
LDB A(X) ;GET START OF AREA
LDX #T.DFLT-<EECK1-EEROM+2> ;DEFAULT TABLE STARTS WITH AREA 2
ABX
TFR X,U
LDX #EEROM
ABX
BEGIN
LDB (U)+
STB (X)+
CMPX TEMP
HSEND
ELSE ;ELSE GET DEFAULTS FROM ELSEWHERE
TFR A,B ;SAVE IT
TSTA
IFEQ ;OPTION SWITCHES----USE PHYSICAL SWITCHES FOR DEFAULT
LDA R.OPT1 ;COINS
STA TEMP
LDA R.OPT2 ;STARTING LIVES,DIFFICULTY,BONUS SHIELDS,ATTRACTIVE MUSIC
STA TEMP+1
LDA #00 ;SET FOR MISC. OPTIONS
STA TEMP+2
LDX #DUPOPT ;START OF AREA 0
JSR TEMPEE
ELSE ;MUST BE HIGH SCORE INIT
LDX #SAVSCR ;DO SCORES FIRST
LDU #INTSCR ;INITIAL SCORE TABLE (SEE TCHSCR)
LDA #11.
JSR TMPEE3
LDX #SAVINT ;NOW FOR THE INITIALS
LDU #INTINT ;INITIAL INITIALS TABLE (SEE TCHSCR)
LDA #08
JSR TMPEE3
ENDIF
TFR B,A ;GET AREA NUMBER BACK INTO A
ENDIF
ENDIF
;FALL THROUGH TO CHECKSUM IT
.PAGE
.SBTTL CHECKSUM EEROM AREA
.REPT 0
**********************************
*
* EECKSM
*
**********************************
DESCRIPTION: CALCULATE CHECKSUM FOR EEROM AREA.
CONDITION CODE HAS Z SET IF CHECKSUM WAS ALREADY CORRECT (TEST).
IN: A=AREA NUMBER
OUT: A=AREA NUMBER (NOT CHANGED)
B=CHECKSUM
CC=ZERO IF CHECKSUM WAS CORRECT
X ALTERED
USE: EEROM
3 BYTES OF STACK USED TO MAKE ROUTINE RE-ENTRANT
.ENDR
CNT =0
NEWSUM =1
OLDSUM =2
EECKSM:
JSR SUMMIT ;GET CHECKSUM, Z=1 IF CHECKSUM SAME, SUM IN B
IFNE ;STORE IT
STB 1(X) ;LO NIBBLE
LSRB
LSRB
LSRB
LSRB
STB (X) ;HI NIBBLE
LDB #0FF ;CLEAR ZERO FLAG
ENDIF
;---
RTS
;===
SUMMIT:
LEAS -3(S) ;ALLOCATE 3 BYTES
LDX #T.AREA+1 ;GET LENGHT OF AREA
LDB A(X)
LDX #T.AREA
SUBB A(X)
SUBB #02 ;DON'T CHECKSUM THE CHECKSUM
STB CNT(S)
LDB A(X) ;GET START OF AREA
LDX #EEROM
ABX ;POINTS TO START OF AREA TO CHECKSUM
LDB #00 ;SEED
STB NEWSUM(S)
SEC ;PREVENT A ZERO CHECKSUM
BEGIN
LDB (X)+ ;GET DATA
ANDB #0F ;ONLY LOWER NIBBLE IS DATA
ADCB NEWSUM(S) ;SUM
STB NEWSUM(S)
DEC CNT(S)
EQEND
ADCB #0 ;GET ALL THE CARRIES IN
STB NEWSUM(S)
;COMPARE WITH OLD CHECKSUM
LDB (X) ;HI NIBBLE
ASLB
ASLB
ASLB
ASLB
STB OLDSUM(S)
LDB 1(X) ;LO NIBBLE
ANDB #0F
ADDB OLDSUM(S) ;OLD CHECKSUM
STB OLDSUM(S)
LDB NEWSUM(S)
CMPB OLDSUM(S) ;SET CONDITION CODE
LEAS 3(S) ;RESTORE STACK POINTER
RTS
;===
.PAGE
.SBTTL TEST/REINIT EEROM
.REPT 0
**********************************
*
* EEINIT
*
**********************************
DESCRIPTION: CALL EEINIT AFTER RESET. (IE. POWERON,SELFTEST,WATCHDOG,ETC.)
MAKE SURE EEROM IS VALID, USE FOLLOWING STEPS:
1. IF THE EEROM RAM IS VALID THEN USE IT.
2. IF AN AREA OF THE RAM IS BAD THEN USE THE DATA
FROM THE EEROM (RECALLED DATA) FOR THAT AREA.
3. IF THE ABOVE FAILS THEN THE AREAS IN ERROR ARE REWRITTEN
WITH THE DEFAULT VALUES.
IN:
OUT: A,B,X,U ALTERED
USE: EEROM
.ENDR
EEINIT:
LDX #EEROM ;COPY EEROM TO BUFFER
LDU #EEBUF
BEGIN
LDD (X)++
STD (U)++
CMPX #EEROMZ
HSEND
;---
LDA #0FF ;PERFORM A RECALL OF THE NON-VOLATILE MEMORY
STA NVRRCL
LDX #0100 ;WAIT FOR THE CAP TO DISCHARGE
BEGIN
STA WTCHDG
LEAX -1(X)
EQEND
LDA #00 ;TURN OFF RECALL LINE
STA NVRRCL
LDX #0A000 ;NOW WAIT FOR THE CAP TO CHARGE BACK UP
BEGIN
STA WTCHDG
LEAX -1(X)
EQEND
;---
LDX #EEROM ;SWAP EEROM AND BUFFER
LDY #EEBUF
BEGIN
LDU (X)
LDD (Y)
STU (Y)++
STD (X)++
CMPX #EEROMZ
HSEND ;EEBUF HAS RECALLED DATA AND EEROM HAS ITS ORIGINAL
.IF NE,RESONLY
; THIS MAKES SURE THAT WE ALWAYS USE PHYSICAL SWITCHES
LDA #00 ;OPTION SWITCH BACKUP AREA NUMBER
BRA EEINI0 ;WILL RESET BOTH BACKUP AND PRIMARY OPTION AREAS
.ENDC
;---
;START CHECKING VALIDITY
LDA #NAREA ;OPTION SWITCH AREA IS SPECIAL, 2 AREAS
JSR SUMMIT
BEQ 20$ ;PRIMARY OK, MAKE SURE BACKUP IS OK
LDA #00 ;PRIMARY WAS BAD, CHECK BACKUP AREA
JSR SUMMIT
BEQ 15$ ;BACKUP OK, GO REWRITE MAIN AREA FROM BACKUP
;BOTH RAM AREAS BAD, CHECK RECALLED DATA
JSR EEINI2 ;RESTORE PRIMARY AND BACKUP FROM EEBUFF COPY
LDA #NAREA
JSR EEINI2
JSR SUMMIT ;CHECKSUM RECALLED PRIMARY
BEQ 20$ ;'TWAS OK, CHECK NEW BACKUP
LDA #00 ;NEW PRIMARY BAD, CHECK NEW BACKUP
JSR SUMMIT
BEQ 15$
.IIF EQ,DEVSYS-1,SWI ;OH SHIT! NONE OF THEM WAS GOOD
EEINI0 =. ; SPECIAL ENTRY FOR ALWAYS SETTING UP OPTION SWITCH INFO **************
JSR EECPY ;RESTORE FROM ROM TABLE
15$: ;PRIMARY BAD, BUT BACKUP OK
LDX #T.AREA ;MOVE BACKUP TO PRIMARY
LDB NAREA(X)
LDX #EEROM
ABX ;POINTER TO BAD AREA
LDU #EEROM ;POINTER TO GOOD AREA (BACKUP)
BRA 40$ ;FIX IT FROM BACKUP
20$: ;PRIMARY GOOD
LDA #00 ;CHECK THE BACKUP AREA
JSR SUMMIT
BNE EEINI1 ;FIX IT FROM PRIMARY
;---
;BOTH AREAS HAVE GOOD CHECKSUMS, MAKE AREAS THE SAME
LDA EECK3 ;PRIMARY OPTION SWITCH CHECKSUM
ANDA #0F
STA TEMP
LDA EECK0 ;BACKUP
ANDA #0F
CMPA TEMP
IFEQ
LDA EECK3+1
ANDA #0F
STA TEMP
LDA EECK0+1
ANDA #0F
CMPA TEMP
ENDIF
BEQ 55$ ;OPTION SWITCH CHECKSUM ARE THE SAME, CHECK OTHER AREAS
EEINI1 =.
LDX #T.AREA ;REPLACE BACKUP AREA WITH PRIMARY
LDB NAREA(X)
LDX #EEROM
ABX
TFR X,U ;POINTS TO PRIMARY OPTION SWITCH AREA
LDX #EEROM ;POINTS TO BACKUP OPTION SWITCH AREA
40$:
LDB T.AREA+1 ;LENGTH OF OPTION SWITCH AREAS
STB TMPCNT
BEGIN
LDB (U)+ ;TRANSFER GOOD TO BAD
STB (X)+
DEC TMPCNT
EQEND
55$:
LDA #NAREA-1 ;NEXT AREA
BEGIN
JSR SUMMIT
IFNE ;NO GOOD
JSR EEINI2 ;REPLACE FROM BUFFER
JSR SUMMIT
IFNE ;REALLY BAD, USE DEFAULTS
.IIF EQ,DEVSYS-1,SWI
JSR EECPY
ENDIF
ENDIF
DECA
EQEND
;---
LDX #TIMEON ;SETUP RAM BASED TIME ON
JSR EETEMP
LDD TEMP
STD TIMER
LDD TEMP+2
STD TIMER+2
RTS
EEINI2: ;MOVE AREA A FROM EEBUF TO EEROM
LDX #T.AREA+1
LDB A(X)
LDX #EEROM
ABX
STX TEMP ;START OF NEXT AREA
LDX #T.AREA
LDB A(X)
LDX #EEBUF
ABX
TFR X,U ;START OF AREA IN EEBUF
LDX #EEROM
ABX ;START OF AREA IN EEROM
BEGIN
LDB (U)+
STB (X)+
CMPX TEMP
HSEND
RTS
;===
CHKEE: ;CHECK AND RESTORE IF NECESSARY THE VALIDITY OF AREA (A)
JSR SUMMIT
IFNE ;ERROR
STA TEMP ;SAVE AREA NUMBER
LDX #EEROM ;COPY EEROM TO BUFFER
LDU #EEBUF
BEGIN
LDD (X)++
STD (U)++
CMPX #EEROMZ
HSEND
JSR NOVRCL ;PERFORM A RECALL OF THE NON-VOLATILE RAM
LDX #EEROM ;SWAP EEROM AND BUFFER
LDY #EEBUF
BEGIN
LDU (X)
LDD (Y)
STU (Y)++