-
Notifications
You must be signed in to change notification settings - Fork 53
/
save.asm
182 lines (180 loc) · 4.89 KB
/
save.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
;--------------------------------------------------------------------------------
WriteSaveChecksumAndBackup:
TDC
CLC
LDX.w #$004FC
-
ADC.l CartridgeSRAM, X
DEX #2
BPL -
LDX.w #$0FFE
-
ADC.l ExtendedFileNameSRAM, X
DEX #2
BPL -
STA.b Scrap00
LDA.w #$5A5A
SEC : SBC.b Scrap00
STA.l InverseChecksumSRAM
.backup_save
PHB
LDA.w #$14FF
LDX.w #CartridgeSRAM
LDY.w #SaveBackupSRAM
MVN CartridgeSRAM>>16, CartridgeSRAM>>16
PLB
TDC
TAX
RTL
;--------------------------------------------------------------------------------
ValidateSRAM:
REP #$30
TDC
CLC
LDX.w #$04FC
-
ADC.l CartridgeSRAM, X
DEX #2
BPL -
LDX.w #$0FFE
-
ADC.l ExtendedFileNameSRAM, X
DEX #2
BPL -
STA.b Scrap00
LDA.w #$5A5A
SEC : SBC.b Scrap00
CMP.l InverseChecksumSRAM : BEQ .goodchecksum
TDC
LDX.w #$04FC
-
ADC.l SaveBackupSRAM, X
DEX #2
BPL -
LDX.w #$0FFE
-
ADC.l SaveBackupSRAM+$500, X
DEX #2
BPL -
STA.b Scrap00
LDA.w #$5A5A
SEC : SBC.b Scrap00
CMP.l SaveBackupSRAM+$4FE : BEQ +
TDC : STA.l FileValiditySRAM ; Delete save
BRA .goodchecksum
+
PHB
LDA.w #$14FF
LDX.w #SaveBackupSRAM
LDY.w #CartridgeSRAM
MVN CartridgeSRAM>>16, CartridgeSRAM>>16
PLB
.goodchecksum
LDX.w #$00FE : - ; includes prize pack reset after save and quit
STZ.w $0D00, X
STZ.w $0E00, X
STZ.w $0F00, X
DEX #2
BPL -
SEP #$30
RTL
;--------------------------------------------------------------------------------
WriteNewFileChecksum:
LDX.w #$0000 : TXA : - ; Checksum first $04FE bytes
CLC : ADC.l CartridgeSRAM, X
INX #2
CPX.w #$04FE : BNE -
LDX.w #$0000 : - ; Checksum extended save data
CLC : ADC.l ExtendedFileNameSRAM, X
INX #2
CPX.w #$0FFE : BNE -
STA.b Scrap00
LDA.w #$5A5A
SEC : SBC.b Scrap00
STA.l InverseChecksumSRAM
RTL
;--------------------------------------------------------------------------------
ClearExtendedSaveFile:
STA.l $700400, X ; what we wrote over
STA.l $700500, X
STA.l $700600, X
STA.l $700700, X
STA.l $700800, X
STA.l $700900, X
STA.l $700A00, X
STA.l $700B00, X
STA.l $700C00, X
STA.l $700D00, X
STA.l $700E00, X
STA.l $700F00, X
STA.l $701000, X
STA.l $701100, X
STA.l $701200, X
STA.l $701300, X
STA.l $701400, X
; Clear backup save
STA.l $704000, X
STA.l $704100, X
STA.l $704200, X
STA.l $704300, X
STA.l $704400, X
STA.l $704500, X
STA.l $704600, X
STA.l $704700, X
STA.l $704800, X
STA.l $704900, X
STA.l $704A00, X
STA.l $704B00, X
STA.l $704C00, X
STA.l $704D00, X
STA.l $704E00, X
STA.l $704F00, X
STA.l $705000, X
STA.l $705100, X
STA.l $705200, X
STA.l $705300, X
STA.l $705400, X
RTL
;--------------------------------------------------------------------------------
ClearExtendedWRAMSaveFile:
STA.l $7EF400, X ; what we wrote over
STA.l $7F6000, X
STA.l $7F6100, X
STA.l $7F6200, X
STA.l $7F6300, X
STA.l $7F6400, X
STA.l $7F6500, X
STA.l $7F6600, X
STA.l $7F6700, X
STA.l $7F6800, X
STA.l $7F6900, X
STA.l $7F6A00, X
STA.l $7F6B00, X
STA.l $7F6C00, X
STA.l $7F6D00, X
STA.l $7F6E00, X
STA.l $7F6F00, X
RTL
;--------------------------------------------------------------------------------
CopyExtendedSaveFileToWRAM:
PHA
PHB
LDA.w #$0FFF
LDX.w #ExtendedSaveDataSRAM
LDY.w #ExtendedSaveDataWRAM
MVN ExtendedSaveDataWRAM>>16, CartridgeSRAM>>16
PLB
PLA
STA.l $7EC00D ; What we wrote over. Keep this write last.
RTL
;--------------------------------------------------------------------------------
CopyExtendedWRAMSaveFileToSRAM:
PHB
LDA.w #$0FFF
LDX.w #ExtendedSaveDataWRAM
LDY.w #ExtendedSaveDataSRAM
MVN CartridgeSRAM>>16, ExtendedSaveDataWRAM>>16
PLB
TDC
TAX
RTL