-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.a
374 lines (316 loc) · 8.52 KB
/
memory.a
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
!macro setBank .bankNumAddr {
lda .bankNumAddr
sta $0
}
!macro setBankImmediate .bankNum {
lda #.bankNum
sta $0
}
BLOCK_CTR
!byte 0
NUM_BLOCKS
!byte 0
!macro readBlocks .numBlocks {
lda #.numBlocks
sta NUM_BLOCKS
jsr readBlocksCall
}
; --------------------------------------------------
; This routine copies a number of 256 byte block from video RAM to banked RAM.
; The number of blocks to copy is given in NUM_BLOCKS. As one RAM bank has 32 blocks
; a bigger value than 32 for NUM_BLOCKS makes no sense.
;
; This routine has no return value.
; --------------------------------------------------
readBlocksCall
stz BLOCK_CTR
+load16BitImmediate $A000, MEM_CPY_PTR
ldy #0
.blockLoopRead
lda VERA_DATA_0
sta (MEM_CPY_PTR), y
iny
bne .blockLoopRead
inc MEM_CPY_PTR + 1
inc BLOCK_CTR
lda BLOCK_CTR
cmp NUM_BLOCKS
bne .blockLoopRead
rts
!macro writeBlocks .numBlocks {
lda #.numBlocks
sta NUM_BLOCKS
jsr writeBlocksCall
}
; --------------------------------------------------
; This routine copies a number of 256 byte block from banked RAM to video RAM.
; The number of blocks to copy is given in NUM_BLOCKS. As one RAM bank has 32 blocks
; a bigger value than 32 for NUM_BLOCKS makes no sense.
;
; This routine has no return value.
; --------------------------------------------------
writeBlocksCall
stz BLOCK_CTR
+load16BitImmediate $A000, MEM_CPY_PTR
ldy #0
.blockLoopWrite
lda (MEM_CPY_PTR), y
sta VERA_DATA_0
iny
bne .blockLoopWrite
inc MEM_CPY_PTR + 1
inc BLOCK_CTR
lda BLOCK_CTR
cmp NUM_BLOCKS
bne .blockLoopWrite
rts
SAVED_VERA_STATE
!byte 0,0,0
.TARGET_BANK_NUM
!byte 0
.CONST_NUM_FULL_BANKS
!byte 9
.CONST_BLOCKS_IN_LAST_BANK
!byte 12
.FULL_BANK_COUNT
!byte 0
; 8K = 32 * 256
; 320 * 240 = 76800 = 9 * 8K + 3072
; 3072 = 12 * 256
; --------------------------------------------------
; This routine copies the first 76800 bytes of video RAM into banked RAM
; and thereby save the current state of the hires screen. The banks 32-42 are
; used for this purpose.
;
; This routine has no return value.
; --------------------------------------------------
saveHiresData
+saveVeraRegisters SAVED_VERA_STATE
lda #32
sta .TARGET_BANK_NUM
stz .FULL_BANK_COUNT
+selectDataPort0
+setVRAMStart
+autoIncOn
.saveLoopRead
+setBank .TARGET_BANK_NUM
+readBlocks 32
inc .TARGET_BANK_NUM
inc .FULL_BANK_COUNT
lda .FULL_BANK_COUNT
cmp .CONST_NUM_FULL_BANKS
beq .lastBlockRead
bra .saveLoopRead
.lastBlockRead
+setBank .TARGET_BANK_NUM
+readBlocks 12
rts
; --------------------------------------------------
; This routine copies video RAM data saved with saveHiresData from
; banked RAM back to video RAM and thereby restores the contents of the
; hires screen. The banks 32-42 are used for this purpose.
;
; This routine has no return value.
; --------------------------------------------------
restoreHiresData
lda #32
sta .TARGET_BANK_NUM
stz .FULL_BANK_COUNT
+selectDataPort0
+setVRAMStart
+autoIncOn
.saveLoopWrite
+setBank .TARGET_BANK_NUM
+writeBlocks 32
inc .TARGET_BANK_NUM
inc .FULL_BANK_COUNT
lda .FULL_BANK_COUNT
cmp .CONST_NUM_FULL_BANKS
beq .lastBlockWrite
bra .saveLoopWrite
.lastBlockWrite
+setBank .TARGET_BANK_NUM
+writeBlocks 12
+loadVeraRegisters SAVED_VERA_STATE
rts
.IO_FILE_NUM = 1
.CONST_BANK_SIZE
!byte 00, $20
.CONST_LAST_BANK_SIZE
!byte 00, $0C
.CONST_PARAM_SIZE
!byte 22, 0
MAX_FILE_NAME_LENGTH = 16
FILE_NAME_SAVE_LOAD
!byte MAX_FILE_NAME_LENGTH
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.PREFIX_OVERWRITE
!byte 3
!tx "@0:"
.POSTFIX_SEQ
!byte 4
!tx ",S,W"
.POSTFIX_SEQ_READ
!byte 4
!tx ",S,R"
.WRITE_FILE_NAME
!byte 30
!byte 0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0
; --------------------------------------------------
; This routine saves the cached video RAM data and the calculation parameters
; to a file on disk. The file name has to be specified as a string at address
; FILE_NAME_SAVE_LOAD.
;
;
; This routine returns DISK_IO_OK in accu if no error occurred.
; --------------------------------------------------
saveHiresDataToDisk
+strCpy .PREFIX_OVERWRITE, .WRITE_FILE_NAME
+strCat FILE_NAME_SAVE_LOAD, .WRITE_FILE_NAME
+strCat .POSTFIX_SEQ, .WRITE_FILE_NAME
+openChannel .IO_FILE_NUM, DEVICE_NUM, 5, .WRITE_FILE_NAME
bcc .openOK
jmp .showErrorOpen
.openOK
lda #32
sta .TARGET_BANK_NUM
stz .FULL_BANK_COUNT
.saveDiskLoopWrite
+setBank .TARGET_BANK_NUM
+writeBufferAddr .IO_FILE_NUM, $A000, .CONST_BANK_SIZE
cmp #DISK_IO_OK
bne .showErrorWriteAndClose
inc .TARGET_BANK_NUM
inc .FULL_BANK_COUNT
lda .FULL_BANK_COUNT
cmp .CONST_NUM_FULL_BANKS
beq .lastBlockDiskWrite
bra .saveDiskLoopWrite
.lastBlockDiskWrite
+setBank .TARGET_BANK_NUM
+writeBufferAddr .IO_FILE_NUM, $A000, .CONST_LAST_BANK_SIZE
cmp #DISK_IO_OK
bne .showErrorWriteAndClose
+writeBufferAddr .IO_FILE_NUM, STEP_X, .CONST_PARAM_SIZE
cmp #DISK_IO_OK
bne .showErrorWriteAndClose
lda #.IO_FILE_NUM
jsr CLOSE
lda #DISK_IO_OK
rts
.showErrorWriteAndClose
lda #.IO_FILE_NUM
jsr CLOSE
lda #DISK_IO_ERR
rts
.showErrorOpen
lda #DISK_IO_ERR
rts
.READ_FILE_NAME
!byte 30
!byte 0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0
; --------------------------------------------------
; This routine loads data from disk into the cached video RAM data and the
; calculation parameters. The file name has to be specified as a string at
; address FILE_NAME_SAVE_LOAD.
;
; This routine returns DISK_IO_OK in accu if no error occurred.
; --------------------------------------------------
loadHiresDataFromDisk
+strCpy FILE_NAME_SAVE_LOAD, .READ_FILE_NAME
+strCat .POSTFIX_SEQ_READ, .READ_FILE_NAME
+openChannel .IO_FILE_NUM, DEVICE_NUM, 5, .READ_FILE_NAME
bcc .openLoadOK
lda #DISK_IO_ERR
rts
.openLoadOK
lda #32
sta .TARGET_BANK_NUM
stz .FULL_BANK_COUNT
.loadDiskLoopWrite
+setBank .TARGET_BANK_NUM
+readBufferAddr .IO_FILE_NUM, $A000, .CONST_BANK_SIZE
cmp #DISK_IO_OK
bne .showErrorLoadAndClose
inc .TARGET_BANK_NUM
inc .FULL_BANK_COUNT
lda .FULL_BANK_COUNT
cmp .CONST_NUM_FULL_BANKS
beq .lastBlockDiskLoad
bra .loadDiskLoopWrite
.lastBlockDiskLoad
+setBank .TARGET_BANK_NUM
+readBufferAddr .IO_FILE_NUM, $A000, .CONST_LAST_BANK_SIZE
cmp #DISK_IO_OK
bne .showErrorLoadAndClose
+readBufferAddr .IO_FILE_NUM, STEP_X, .CONST_PARAM_SIZE
cmp #DISK_IO_OK
bne .showErrorLoadAndClose
lda #.IO_FILE_NUM
jsr CLOSE
lda #DISK_IO_OK
rts
.showErrorLoadAndClose
lda #.IO_FILE_NUM
jsr CLOSE
lda #DISK_IO_ERR
rts
; --------------------------------------------------
; This routine saves the the calculation parameters to a file on disk.
; The file name has to be specified as a string at address FILE_NAME_SAVE_LOAD.
;
; This routine returns DISK_IO_OK in accu if no error occurred.
; --------------------------------------------------
saveParametersToDisk
+strCpy .PREFIX_OVERWRITE, .WRITE_FILE_NAME
+strCat FILE_NAME_SAVE_LOAD, .WRITE_FILE_NAME
+strCat .POSTFIX_SEQ, .WRITE_FILE_NAME
+openChannel .IO_FILE_NUM, DEVICE_NUM, 5, .WRITE_FILE_NAME
bcc .openOKParam
jmp .showErrorOpenParam
.openOKParam
+writeBufferAddr .IO_FILE_NUM, STEP_X, .CONST_PARAM_SIZE
cmp #DISK_IO_OK
bne .showErrorWriteAndCloseParam
lda #.IO_FILE_NUM
jsr CLOSE
lda #DISK_IO_OK
rts
.showErrorWriteAndCloseParam
lda #.IO_FILE_NUM
jsr CLOSE
lda #DISK_IO_ERR
rts
.showErrorOpenParam
lda #DISK_IO_ERR
rts
; --------------------------------------------------
; This routine loads calculation parameters. The file name has to be specified
; as a string at address FILE_NAME_SAVE_LOAD.
;
; This routine returns DISK_IO_OK in accu if no error occurred.
; --------------------------------------------------
loadParametersFromDisk
+strCpy FILE_NAME_SAVE_LOAD, .READ_FILE_NAME
+strCat .POSTFIX_SEQ_READ, .READ_FILE_NAME
+openChannel .IO_FILE_NUM, DEVICE_NUM, 5, .READ_FILE_NAME
bcc .openLoadOKParam
lda #DISK_IO_ERR
rts
.openLoadOKParam
+readBufferAddr .IO_FILE_NUM, STEP_X, .CONST_PARAM_SIZE
cmp #DISK_IO_OK
bne .showErrorLoadAndCloseParam
lda #.IO_FILE_NUM
jsr CLOSE
lda #DISK_IO_OK
rts
.showErrorLoadAndCloseParam
lda #.IO_FILE_NUM
jsr CLOSE
lda #DISK_IO_ERR
rts