forked from the-atari-team/tat.night-knight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HIGHSCORE.INC
467 lines (390 loc) · 9.2 KB
/
HIGHSCORE.INC
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
; Current score and high score for Night Knight
.local
; Wir arbeiten hier mit BCD Zahlen, dann haben wir es bei der Ausgabe einfacher
; einfach als Hex-Zahlen (3x1 Byte) rueckwaerts ausgeben
; Das heisst aber:
; in Interrupts ist unbedingt CLD zu verwenden, sollte ADC/SBC zum Einsatz kommen
;
; Da @printff('%x%x%x%x', a,b,c,d) zu teuer ist (sehr viele Bildschirmzeilen),
; implementieren wir das Setzen der (High-)Scores hier einfach nochmal.
; Das setzen geht damit recht flott, Y:=@current_cursor_row) X:=colcrs
; Der Wert @current_cursor_row kommt aus FAST_SCREEN_OUTPUT
;
;
; WICHTIG: Da wir hier BCD nutzen, den Wert hier als hex uebergeben,
; aber nur die Zahlen 0-9 sind zulaessig. Max $9999 ist moeglich!
; erhoehe Highscore um Wert aus Parameter
; Wenn
@ADD_CURRENT_SCORE
@ADD_CURRENT_SCORE_I
LDY #1
LDA (@HEAP_PTR),Y ; wert holen
sta @reg
iny
lda (@heap_ptr),y
sta @reg+1
; lda @pacman_multiply_score_10
; beq ?no_mult
;
; asl @reg ; um 4 bit verschieben, entspricht in BCD * 10
; rol @reg+1
; asl @reg
; rol @reg+1
; asl @reg
; rol @reg+1
; asl @reg
; rol @reg+1
;
;?no_mult
SED
CLC
lda @reg
ADC @BCD_CURRENT_SCORE
STA @BCD_CURRENT_SCORE
lda @reg+1
ADC @BCD_CURRENT_SCORE+1
STA @BCD_CURRENT_SCORE+1
bcc ?no_upper_score ; no need to add something to next values
LDA @BCD_CURRENT_SCORE+2
ADC #$00
STA @BCD_CURRENT_SCORE+2
bcc ?no_upper_score ; no need to add something to next values
LDA @BCD_CURRENT_SCORE+3
ADC #$00
STA @BCD_CURRENT_SCORE+3
; check for extra live every 10000 points
; inc @lives
; inc @live_update
; TODO: flash wenn wir die 10000 ueberschreiten
?no_upper_score
CLC
lda @reg
ADC bcd_check_score
STA bcd_check_score
lda @reg+1
ADC bcd_check_score+1
STA bcd_check_score+1
bcc ?no_upper_check_score ; no need to add something to next values
lda bcd_check_score+2
ADC #0
STA bcd_check_score+2
?no_upper_check_score
; CLD
; RTS
; check if score greater or equal (parameter)
; return 1 if greater than given parameter
;@CHECK_SCORE_GE_I
; SED
; LDY #2
; LDA (@HEAP_PTR),Y ; wert holen
; tax
; dey
; lda (@heap_ptr),y
; tay
; bcd_check_score == (x*256+y)
; cmp bcd_check_score
; bne ?false_ge
; cpy bcd_check_score+1
; beq ?false_ge
; cpx bcd_check_score+2
; beq ?true
; bcd_check_score >= (x*256+y)
;?false_ge
lda bcd_check_score
CMP bcd_new_live
LDA bcd_check_score+1
SBC bcd_new_live+1
LDA bcd_check_score+2
SBC bcd_new_live+2
BCC ?false
?true
inc @lives
inc @live_update
; TODO: flash wenn wir die 10000 ueberschreiten
; ?SUB_CHECK_SCORE
; SED
; LDY #1
; LDA (@HEAP_PTR),Y ; wert holen
; sta @reg
; iny
; lda (@heap_ptr),y
; sta @reg+1
SEC
LDA bcd_check_score
SBC bcd_new_live
STA bcd_check_score
LDA bcd_check_score+1
SBC bcd_new_live+1
STA bcd_check_score+1
LDA bcd_check_score+2
SBC #$00
STA bcd_check_score+2
LDA bcd_check_score+3
SBC #$00
STA bcd_check_score+3
CLD
ldy #1
ldx #0
RTS
?false
CLD
ldy #0
ldx #0
rts
; ueberprueft current score mit Highscore und kopiert wenn current > high
@CHECK_FOR_NEW_HIGHSCORE
LDA @BCD_CURRENT_SCORE+3
CMP @BCD_HIGHSCORE+3
BMI ?DO_NOT_COPY_CURRENT_TO_HIGH
BEQ ?CHECK_NO_3
LDA @BCD_CURRENT_SCORE+3
STA @BCD_HIGHSCORE+3
?COPY_3
LDA @BCD_CURRENT_SCORE+2
STA @BCD_HIGHSCORE+2
?COPY_2
LDA @BCD_CURRENT_SCORE+1
STA @BCD_HIGHSCORE+1
?COPY_1
LDA @BCD_CURRENT_SCORE
STA @BCD_HIGHSCORE
ldy #1 ; es gibt einen neues Highscore
sty @new_highscore
ldx #0
RTS
?CHECK_NO_3
LDA @BCD_CURRENT_SCORE+2
CMP @BCD_HIGHSCORE+2
BMI ?DO_NOT_COPY_CURRENT_TO_HIGH
BEQ ?CHECK_NO_2
JMP ?COPY_3
?CHECK_NO_2
LDA @BCD_CURRENT_SCORE+1
CMP @BCD_HIGHSCORE+1
BMI ?DO_NOT_COPY_CURRENT_TO_HIGH
BEQ ?CHECK_NO_1
JMP ?COPY_2
?CHECK_NO_1
LDA @BCD_CURRENT_SCORE
CMP @BCD_HIGHSCORE
BMI ?DO_NOT_COPY_CURRENT_TO_HIGH
JMP ?COPY_1
?DO_NOT_COPY_CURRENT_TO_HIGH
ldy #0
ldx #0
RTS
; setzt den aktuellen Score auf 0 zurueck
; und ab welchem Wert ein neues Leben
@init_score_and_new_live
@init_score_and_new_live_i
LDY #1
LDA (@HEAP_PTR),Y ; wert holen
sta bcd_new_live
iny
lda (@heap_ptr),y
sta bcd_new_live+1
LDA #0
STA @BCD_CURRENT_SCORE
STA @BCD_CURRENT_SCORE+1
STA @BCD_CURRENT_SCORE+2
STA @BCD_CURRENT_SCORE+3
STA bcd_check_score
STA bcd_check_score+1
sta bcd_check_score+2
sta bcd_new_live+2
sta @new_highscore ; ist nur 1, wenn es einen neuen Highscore gibt
RTS
@remember_current_score
lda @bcd_current_score
sta @bcd_remember_score
lda @bcd_current_score+1
sta @bcd_remember_score+1
rts
; @return 1, if first two bytes of current_score has changed to remember_score
@has_current_score_changed
lda @bcd_current_score
cmp @bcd_remember_score
bne ?score_has_changed ; --> bytes unterscheiden sich
lda @bcd_current_score+1
cmp @bcd_remember_score+1
bne ?score_has_changed ; --> obere bytes unterscheiden sich
ldy #0
ldx #0
rts
?score_has_changed
ldy #1
ldx #0
rts
@bcd_remember_score
.byte 0,0
BCD_NEW_LIVE
.byte 0,0,0,0
@BCD_CURRENT_SCORE ; big endian!
.byte 0,0,0,0
BCD_CHECK_SCORE
.byte 0,0,0,0
@new_highscore
.byte 0
@BCD_HIGHSCORE
.byte $00,$00,$01,$00
; Kopiert den aktuellen Highscore an die gewuenschte Cursor-Position
; Die Cursor-Position kann mit @fast_gotoxy(x,y) gesetzt werden
; @parameter void
@print_highscore_in_title
ldy #0
@print_highscore
jsr ?load_current_cursor_row_and_set_Y_from_colcrs
; lda @BCD_HIGHSCORE+3
; jsr ?print_bcd
lda @BCD_HIGHSCORE+2
jsr ?print_bcd
lda @BCD_HIGHSCORE+1
jsr ?print_bcd
lda @BCD_HIGHSCORE
jmp ?print_bcd
; Initialisiert die internen Register zum setzen der Zahlen an die richtige Position
?load_current_cursor_row_and_set_Y_from_colcrs
lda @current_cursor_row
sta @reg
lda @current_cursor_row+1
sta @reg+1
ldy COLCRS
rts
; Kopiert den aktuellen Score an die gewuenschte Cursor-Position
; Die Cursor-Position kann mit @fast_gotoxy(x,y) gesetzt werden
; @parameter void
@print_score_in_title
ldy #6
@print_score
jsr ?load_current_cursor_row_and_set_Y_from_colcrs
; lda @bcd_current_score+3
; jsr ?print_bcd
lda @bcd_current_score+2
jsr ?print_bcd
lda @bcd_current_score+1
jsr ?print_bcd
lda @bcd_current_score
jmp ?print_bcd
; Interne Funktion, um den Akku als 2 BCD-Zahlen in den Screen zu setzen
; (@reg),y zeigt in den Screen
; goody: @score_color wird zur Zahl hinzuge"oder"t damit koennen unterschiedliche
; Farben gesetzt werden.
?print_bcd
pha
lsr
lsr
lsr
lsr
tax
lda @screen_digit,x
; ora @score_color,y
sta (@reg),y
iny
pla
and #$0F
tax
lda @screen_digit,x
; ora @score_color,y
sta (@reg),y
iny
rts
@screen_digit
.sbyte '0,'1,'2,'3,'4,'5,'6,'7,'8,'9
;@score_color
; .byte $c0,$c0,$c0,$c0,$c0,$c0,$c0,$c0,$c0,$c0
; .byte $c0,$c0,$c0,$c0,$c0,$c0,$c0,$c0,$c0,$c0
; .byte $c0,$c0,$c0,$c0,$c0,$c0,$c0,$c0,0,0
; .byte 0,0,$40,$40,$40,$40,$40,$40,$40,$40
?hextobcd_in = @REG+2
?hextobcd_out = @REG+3 ; low byte first
?TABLE_LOW
.byte <$01, <$02, <$04, <$08, <$16, <$32, <$64, <$128
;?TABLE_HIGH
; .byte >$01, >$02, >$04, >$08, >$16, >$32, >$64, >$128
; (Word directive puts low byte first.)
; Print number from 00 to 99 at fast_gotoxy() position
@printSmallDecimalWith0
@printSmallDecimalWith0_I
ldy #1
lda (@heap_ptr),y
jsr @hextobcd_i
tya
pha
jsr ?load_current_cursor_row_and_set_Y_from_colcrs
pla
jmp ?print_bcd
@HexToBcd
@HexToBcd_I
sta ?hextobcd_in
SED ; Output gets added up in decimal.
LDA #0
STA ?hextobcd_out ; Inititalize output word as 0.
STA ?hextobcd_out+1 ; (NMOS 6502 will need LDA#0, STA ...)
LDX #7 ; $E is 14 for 2x7 bits. (0-7 is 8 positions.)
?loop
ASL ?hextobcd_in ; Look at next high bit. If it's 0,
BCC ?no_add ; don't add anything to the output for this bit.
LDA ?hextobcd_out ; Otherwise get the running output sum
CLC
ADC ?TABLE_LOW,X ; and add the appropriate value for this bit
STA ?hextobcd_out ; from the table, and store the new sum.
LDA ?hextobcd_out+1 ; After low byte, do high byte.
ADC #0 ; as log as we are <99 this byte will not need
STA ?hextobcd_out+1
?no_add
DEX ; Go down to next bit value to loop again.
BPL ?loop ; If still not done, go back for another loop.
CLD
ldy ?hextobcd_out
ldx ?hextobcd_out+1
RTS
; Show Password
; @printPassword(adr:hashResult)
@printPassword
@printPassword_i
ldy #1
lda (@heap_ptr),y
sta @REG
iny
lda (@heap_ptr),y
sta @REG+1
ldy #1
lda (@REG),y
sta ?password
iny
lda (@REG),y
sta ?password+1
iny
lda (@REG),y
sta ?password+2
jsr ?load_current_cursor_row_and_set_Y_from_colcrs
lda ?password
jsr ?print_password_byte
lda ?password+1
jsr ?print_password_byte
lda ?password+2
jmp ?print_password_byte
?password
.byte 0,0,0
?print_password_byte
pha
lsr
lsr
lsr
lsr
tax
lda @password_digit,x
; ora @score_color,y
sta (@reg),y
iny
pla
and #$0F
tax
lda @password_digit,x
; ora @score_color,y
sta (@reg),y
iny
rts
@password_digit
; .sbyte 'K,'L,'M,'N,'O,'P,'Q,'R,'S,'T,'U,'V,'W,'X,'Y,'Z
.sbyte 'D,'E,'F,'G,'H,'I,'J,'K,'L,'M,'N,'O,'P,'Q,'R,'S