-
Notifications
You must be signed in to change notification settings - Fork 3
/
save-highscores.s
94 lines (75 loc) · 2.12 KB
/
save-highscores.s
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
;
; Enable SRAM and save highscores
;
.include "build/tetris.inc"
.include "ips.inc"
SRAM := $6000
sramMagic := SRAM
sramHighScoreTable := SRAM+5
; header patch to enable SRAM
.fileopt comment, "ips: 0 INES_HEADER_MOD"
.segment "INES_HEADER_MOD_HDR"
.byte 0
.dbyt 6 ; header offset
.dbyt 1 ; byte sized
.segment "INES_HEADER_MOD"
INES_MAPPER = 1 ; 0 = NROM
INES_MIRROR = 0 ; 0 = horizontal mirroring, 1 = vertical mirroring
INES_SRAM = 1 ; 1 = battery backed SRAM at $6000-7FFF
.byte INES_MIRROR | (INES_SRAM << 1) | ((INES_MAPPER & $f) << 4)
.segment "saveHighscoreStartPressed_patch"
ips_segment "saveHighscoreStartPressed_patch",highScoreEntryScreen+$94 ; $A295
; Save high scores after player presses start after entering name
; saveHighscoreStartPressed_patch:
jmp saveHighScores
.segment "initAndSave"
ips_segment "initAndSave",initRamContinued+$13,$4F ; $806D
continueWarmBootInit := initRamContinued+$62 ; $80BC
; Redefine cold boot to mean uninitialized SRAM
checkInit:
ldx #$05
@checkColdBoot:
dex
bmi @warmInit
lda magicValue,x
cmp sramMagic,x
beq @checkColdBoot
; Copy default high scores and magic to SRAM
@coldInit:
; Init all of SRAM, in case we use more in the future
lda #$00
ldx #>SRAM
ldy #$7F
jsr memset_page
ldx #$50-1
@initSramHighScore:
lda defaultHighScoresTable,x
sta sramHighScoreTable,x
dex
bpl @initSramHighScore
ldx #$05-1
@initSramMagic:
lda magicValue,x
sta sramMagic,x
dex
bpl @initSramMagic
; Copy scores from SRAM every boot; initMagic unused
@warmInit:
ldx #$50-1
@loadHighScore:
lda sramHighScoreTable,x
sta highScoreNames,x
dex
bpl @loadHighScore
jmp continueWarmBootInit
magicValue:
.byte $12,$34,$56,$78,$9A
; Copy updated scores to SRAM
saveHighScores:
ldx #$50-1
@loop:
lda highScoreNames,x
sta sramHighScoreTable,x
dex
bpl @loop
jmp highScorePosToY-4 ; @ret := $A337