-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflashSupport.asm
More file actions
507 lines (482 loc) · 18.9 KB
/
flashSupport.asm
File metadata and controls
507 lines (482 loc) · 18.9 KB
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
; bank 0
;
;
; all flash operations (write, erase, test - must be done, and the RAM buffer to copy the rotuines must be available!)
; RAM buffer at "flashUserRAM" (title RAM definition)
;
;
; **************************************************************************
; read flash options to RAM
; fill current/next block values
; expects bank 0 active
; in "currentFlashROMStart" current relevant block address
; returns currentFlashROMStart = 0 if error occured
; needs flash "RAM" block
;
; on error Z = 1
; **************************************************************************
if VECFEVER = 1
initFlash ;#isfunction
rts
;.
checkFlash
clr flashAvailable
bsr readOptionsOnly ; and highscore
REPLACE_1_2_buildShadowramFever_varFromIRQ1_32
ldx #0 ;buildShadowramFever
jsr jsrBank1_fromBank0_T1
lda flashAvailable
ora #FLASH_AVAILABLE_BIT
sta flashAvailable
REPLACE_1_2_checkForSavedGameFever_varFromIRQ1_1
ldx #0 ;checkForSavedGameFever
jsr jsrBank1_fromBank0_T1
bra readHighscore
;.
;.......................................................................
;.
;
; copies options to RAM
; uses current block
; no flash check, since default options are available
; **************************************************************************
readOptionsOnly ;#isfunction
REPLACE_1_2_optionsToVectrexRAM_varFromIRQ1_1
ldx #0 ;optionsToVectrexRAM
jmp jsrBank1_fromBank0_T1
;.
;.......................................................................
;.
; reads highscore to RAM, highscore RAM must be available
; uses current block
; no flash check, since default HS are available
; **************************************************************************
readHighscore
REPLACE_1_2_highscoreToVectrexRAM_varFromIRQ1_1
ldx #0 ;highscoreToVectrexRAM
jmp jsrBank1_fromBank0_T1
saveBlockOnChange
; fill shadow with "defaults"
REPLACE_1_2_buildShadowramFever_varFromIRQ1_1
ldx #0 ;buildShadowramFever
jsr jsrBank1_fromBank0_T1
REPLACE_1_2_copyOptionsToShadowram_varFromIRQ1_1
ldx #0 ;copyOptionsToShadowram
jsr jsrBank1_fromBank0_T1
REPLACE_1_2_copyHighScoreToShadowram_varFromIRQ1_1
ldx #0 ;copyHighScoreToShadowram
jsr jsrBank1_fromBank0_T1
REPLACE_1_2_romifyShadowRamFever_varFromIRQ1_1
ldx #0 ;romifyShadowRamFever
jmp jsrBank1_fromBank0_T1
else ; if VECFEVER = 1
initFlash ;#isfunction
clr flashAvailable
jsr checkFlash
lda flashAvailable
anda #FLASH_AVAILABLE_BIT
beq flashErrorOut
ldx #flashRAMROM
checkNextBlock
ldd FlashBlock,x
cmpd #$ffff ; empty flash space
beq flashBlockFound
leax FlashBlock,x
cmpx #$c000
blo checkNextBlock
ldx #0
bra flashErrorOut
; in x the address of the current relevant flash block
flashBlockFound
stx currentFlashROMStart
bsr readOptionsOnly
bsr readHighscore
; ensure Z != 1
lda #1
flashErrorOut
rts
;.
;.......................................................................
;.
;
; copies options to RAM
; uses current block
; no flash check, since default options are available
; **************************************************************************
readOptionsOnly ;#isfunction
; copy options data
ldu #Ram_Options_Start
ldx currentFlashROMStart
copyOptionsLoop
lda ,x+
sta ,u+
cmpu #Ram_Options_End
blo copyOptionsLoop
lda additionalFlags
anda #%00001111
sta additionalFlags
rts
;.
;.......................................................................
;.
; reads highscore to RAM, highscore RAM must be available
; uses current block
; no flash check, since default HS are available
; **************************************************************************
readHighscore
ldu #Ram_HighScore_Start
ldx currentFlashROMStart
leax OptionStruct,x
ldb #HighScoreEntry*4 *2
; lda difficulty
; bpl normalHSLoad
; leax HighScoreEntry*4,x ; load Hardcore highscore
;normalHSLoad
copyHSLoop
lda ,x+
sta ,u+
decb
bne copyHSLoop
rts
;.
;.......................................................................
; clears complete sector (from $b000)
; nothing else
; needs flash "RAM" block
;
; Sector-Erase Operation
; The Sector-Erase operation allows the system to erase the device on a sector-by-sector basis. The
; sector architecture is based on uniform sector size of 4 KByte. The Sector-Erase operation is initiated
; by executing a six-byte command load sequence for Software Data Protection with Sector-Erase command
; (30H) and sector address (SA) in the last bus cycle. The sector address is latched on the falling
; edge of the sixth WE# pulse, while the command (30H) is latched on the rising edge of the sixth WE#
; pulse. The internal Erase operation begins after the sixth WE# pulse. The End-of-Erase can be determined
; using either Data# Polling or Toggle Bit methods. See Figure 10 for timing waveforms. Any commands
; written during the Sector-Erase operation will be ignored.
;.
; **************************************************************************
eraseSector ;#isfunction
lda flashAvailable
anda #FLASH_AVAILABLE_BIT
beq flashErrorOutR1
bsr eraseSector_2RAM
jmp flashUserRAM
;.
eraseSector_2RAM
ldx #eraseSector_Start
ldu #flashUserRAM
eraseSector_copyNextWord
ldd ,x++
std ,u++
cmpx #eraseSector_End
blo eraseSector_copyNextWord
rts
;.
eraseSector_Start
; data 1,
lda #$aa
; address 1
sta $5555
; data 2
lda #$55
; address 2
sta $2aaa
; data 3
lda #$80
; address 3
sta $5555
; data 4
lda #$aa
; address 4
sta $5555
; data 5
lda #$55
; address 5
sta $2aaa
; data 6
lda #$30
; address 6
sta $b000 ; earse sector beginning at $b000
eraseToggleWait
ldb $0000 ; load from even address
eorb $0000 ; load again even and eor
bitb #%01000000 ; if not equal go on waiting
bne eraseToggleWait
flashErrorOutR1
rts
eraseSector_End
;.
;.......................................................................
;.
; finds and sets new flash block
; if last flash block was used, than flash sector is
; erased and flash blocks start anew from $b000
;.
; Assumed: currentFlashROMStart was initialized to current block
;.
; **************************************************************************
findNextFlashBlock ;#isfunction
ldx currentFlashROMStart
leax FlashBlock,x ; load next memory address of flashblock
cmpx #$c000 - FlashBlock ; check if next address has enough space left
blo blockAddressOk
; format flash
bsr eraseSector
ldx #$b000
blockAddressOk
stx currentFlashROMStart
; in x now correct adress block of flash that can be written to
rts
;.
;.......................................................................
;.
; saves options and highscores to next block
; Highscores AND options are always taken from RAM
; sets/corrects current next block
;.
; needs flash "RAM" block
;.
; **************************************************************************
saveCurrentBlock ;#isfunction
lda flashAvailable
anda #FLASH_AVAILABLE_BIT
lbeq flashErrorOut
; changes for V1.11
bsr findNextFlashBlock ; also loads to X
jsr writeFlashByte_2RAM
ldx currentFlashROMStart
; first write options
ldu #Ram_Options_Start
writeNextOptionByte
lda ,u+
jsr flashUserRAM
leax 1,x
cmpu #Ram_Options_End
blo writeNextOptionByte
; second write Highscore
ldu #Ram_HighScore_Start
writeNextHSByte
lda ,u+
jsr flashUserRAM
leax 1,x
cmpu #Ram_HardcoreScore_End
blo writeNextHSByte
rts
;.
;.......................................................................
;.
; compares highscore RAM/ROM
; and options RAM/ROM
; if different -> saves to flash
;.
; needs flash "RAM" block
; **************************************************************************
saveBlockOnChange ;#isfunction
lda flashAvailable
anda #FLASH_AVAILABLE_BIT
lbeq flashErrorOut
ldu #Ram_Options_Start
ldx currentFlashROMStart
compareOptionsNextByte
lda ,u+
cmpa ,x+
bne saveCurrentBlock
cmpu #Ram_Options_End
bne compareOptionsNextByte
ldu #Ram_HighScore_Start
compareHSNextByte
lda ,u+
cmpa ,x+
bne saveCurrentBlock
cmpu #Ram_HardcoreScore_End
bne compareHSNextByte
rts
;.
;.......................................................................
;.
; check flash ID byte
; z flag set if ok
; z flag not set, than flash id wrong
;.
; needs flash "RAM" block
; **************************************************************************
checkFlash ;#isfunction
jsr checkForSavedGameFlash
bsr checkFlash_2RAM
jmp flashUserRAM
;.
checkFlash_2RAM
ldx #checkFlash_Start
ldu #flashUserRAM
checkFlash_copyNextWord
ldd ,x++
std ,u++
cmpx #checkFlash_End
blo checkFlash_copyNextWord
rts
;.
checkFlash_Start
; data 1,
lda #$aa
; address 1
sta $5555
; data 2
lda #$55
; address 2
sta $2aaa
; data 3
lda #$90 ; id
; address 3
sta $5555
ldx $0
lda #$f0
sta $0
cmpx #$bfb5 ; for SST39SF010
beq flashOk_out
cmpx #$bfb6 ; for SST39SF020
beq flashOk_out
flashNotOk_out
lda flashAvailable
anda #$ff-FLASH_AVAILABLE_BIT
sta flashAvailable
rts
flashOk_out
lda flashAvailable
ora #FLASH_AVAILABLE_BIT
sta flashAvailable
rts
checkFlash_End
;.
;.......................................................................
;.
; writes one byte to flash memory
; exepcts flash to be properly formated/erased (all bit = 1)
;
; output address = x
; output byte in A
;
; destroys B
;
; needs flash "RAM" block
; **************************************************************************
writeFlashByte_2RAM
ldx #writeFlashByte_Start
ldu #flashUserRAM
writeFlashByte_copyNextWord
ldd ,x++
std ,u++
cmpx #writeFlashByte_End
blo writeFlashByte_copyNextWord
rts
;.
writeFlashByte_Start
ldb #$aa
stb $5555
ldb #$55
stb $2aaa
ldb #$a0
stb $5555
sta 0, x
; wait for write to be done
nop ; force a tiny wait to ensure switching from write
; to read works work with fast logic gates.
writeByteToggleLoop
ldb 0, x ; wait for DQ6 toggle bit to be the same,
eorb 0, x ; which indicates write is complete.
andb #%01000000 ; |
bne writeByteToggleLoop ; |
rts
writeFlashByte_End
;.
;.......................................................................
;.
;. 46 byte!
eraseSector_Startra000
; data 1,
lda #$aa
; address 1
sta $5555
; data 2
lda #$55
; address 2
sta $2aaa
; data 3
lda #$80
; address 3
sta $5555
; data 4
lda #$aa
; address 4
sta $5555
; data 5
lda #$55
; address 5
sta $2aaa
; data 6
lda #$30
; address 6
sta $a000 ; earse sector beginning at $a000
eraseToggleWaitra000
ldb $0000 ; load from even address
eorb $0000 ; load again even and eor
bitb #%01000000 ; if not equal go on waiting
bne eraseToggleWaitra000
flashErrorOutra000
rts
eraseSector_Endra000
;.
;.......................................................................
; clears complete sector (from $a000)
; nothing else
; needs flash "RAM" block
;
; Sector-Erase Operation
; The Sector-Erase operation allows the system to erase the device on a sector-by-sector basis. The
; sector architecture is based on uniform sector size of 4 KByte. The Sector-Erase operation is initiated
; by executing a six-byte command load sequence for Software Data Protection with Sector-Erase command
; (30H) and sector address (SA) in the last bus cycle. The sector address is latched on the falling
; edge of the sixth WE# pulse, while the command (30H) is latched on the rising edge of the sixth WE#
; pulse. The internal Erase operation begins after the sixth WE# pulse. The End-of-Erase can be determined
; using either Data# Polling or Toggle Bit methods. See Figure 10 for timing waveforms. Any commands
; written during the Sector-Erase operation will be ignored.
;.
; **************************************************************************
eraseSectora000 ;#isfunction
lda flashAvailable
anda #FLASH_AVAILABLE_BIT
lbeq flashErrorOutR1
bsr eraseSector_2RAMra000
jmp bank0flashUserRAM ; THIS MUST BE AVAILABLE!
;.
eraseSector_2RAMra000
ldx #eraseSector_Startra000
ldu #bank0flashUserRAM
eraseSector_copyNextWordra000
ldd ,x++
std ,u++
cmpx #eraseSector_Endra000
blo eraseSector_copyNextWordra000
rts
;.
;.......................................................................
;.
; writes one byte to flash memory
; exepcts flash to be properly formated/erased (all bit = 1)
;
; output address = x
; output byte in A
;
; destroys B
;
; needs flash "RAM" block
; **************************************************************************
writeFlashByte_2RAMA000
ldx #writeFlashByte_Start
ldu #bank0flashUserRAM
writeFlashByte_copyNextWordA000
ldd ,x++
std ,u++
cmpx #writeFlashByte_End
blo writeFlashByte_copyNextWordA000
rts
endif ; if VECFEVER = 1