-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfilefuncs.s
270 lines (201 loc) · 6.11 KB
/
filefuncs.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
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
; ***************************************************************************
; ***************************************************************************
;
; filefuncs.s
;
; File loading and saving.
;
; Copyright John Brandwood 2019.
;
; Distributed under the Boost Software License, Version 1.0.
; (See accompanying file LICENSE_1_0.txt or copy at
; http://www.boost.org/LICENSE_1_0.txt)
;
; ***************************************************************************
; ***************************************************************************
; ***************************************************************************
; ***************************************************************************
;
; tos_chdir_tbed - Change to the "/TBED/" directory.
;
; Uses: __bp = Pointer to directory entry in cache.
;
; Returns: X = F32_OK (and Z flag) or an error code.
;
tos_chdir_tbed: jsr f32_select_root ; Start back at the root.
bne .exit
lda #<.filename ; Locate the 'TBED' folder.
ldy #>.filename
sta <__ax + 0
sty <__ax + 1
jsr f32_find_name
bne .exit
jmp f32_change_dir
.exit: rts
.filename: db "TBED",0
; ***************************************************************************
; ***************************************************************************
;
; tos_slot_file -
;
; Args: tos_bram_slot = Slot #.
; Uses: __bp = Pointer to directory entry in cache.
;
; Returns: X = F32_OK (and Z flag) or an error code.
;
tos_slot_file: jsr tos_chdir_tbed ; Select "/TBED/" directory.
bne .exit
lda tos_bram_slot ; Divide slot # by 10.
inc a
sta <__ax + 0
stz <__ax + 1
lda #10
sta <__cl
jsr tos_div16_7u
lda <__al ; Dividend.
clc
adc #'0'
sta .filename + 5
lda <__dl ; Remainder.
clc
adc #'0'
sta .filename + 6
lda #<.filename
ldy #>.filename
sta <__ax + 0
sty <__ax + 1
jsr f32_find_name ; Locate the named file in
bne .exit ; the current directory.
jsr f32_open_file ; Open the file.
bne .exit
ldx #TOS_WRONG_SIZE
lda f32_file_length + 1 ; Check that the file is 2KB.
cmp #$08
bne .close
lda f32_file_length + 3
ora f32_file_length + 2
ora f32_file_length + 0
bne .close
lda #2048 / 512
sta <__ax + 0 ; Lo-byte of # blocks in file.
stz <__ax + 1 ; Hi-byte of # blocks in file.
stz <sdc_data_addr + 0 ; Xfer into $6000-$67FF.
lda #$60
sta <sdc_data_addr + 1
lda #SLOT_BANK
tam3
ldx #TOS_OK
.exit: rts
.close: jmp f32_close_file ; Close the file & set N & Z.
.filename: db "BRAM-01.BIN",0
; ***************************************************************************
; ***************************************************************************
;
; tos_load_slot - Load a BRAM slot file into memory.
;
tos_load_slot: jsr tos_slot_file ; Select and open the
bne .exit ; slot file.
jsr f32_file_read ; Read the file into memory.
jsr f32_close_file ; Close the file & set N & Z.
.exit: rts
; ***************************************************************************
; ***************************************************************************
;
; tos_save_slot - Load a BRAM slot file into memory.
;
tos_save_slot: jsr tos_slot_file ; Select and open the
bne .exit ; slot file.
jsr f32_file_write ; Write the file from memory.
jsr f32_close_file ; Close the file & set N & Z.
.exit: rts
; ***************************************************************************
; ***************************************************************************
;
; tos_m128_file -
;
; Args: A = bank # of image (uses 16 contiguous banks)
; Args: tos_m128_slot = Slot #.
; Uses: __bp = Pointer to directory entry in cache.
;
; Returns: X = F32_OK (and Z flag) or an error code.
;
tos_m128_file: sta mb1_base_bank ; Set the image base bank.
jsr tos_chdir_tbed ; Select "/TBED/" directory.
bne .exit
lda tos_m128_slot ; Divide slot # by 10.
inc a
sta <__ax + 0
stz <__ax + 1
lda #10
sta <__cl
jsr tos_div16_7u
lda <__al ; Dividend.
clc
adc #'0'
sta .filename + 6
lda <__dl ; Remainder.
clc
adc #'0'
sta .filename + 7
lda #<.filename
ldy #>.filename
sta <__ax + 0
sty <__ax + 1
jsr f32_find_name ; Locate the named file in
bne .exit ; the current directory.
jsr f32_open_file ; Open the file.
bne .exit
ldx #TOS_WRONG_SIZE
lda f32_file_length + 2 ; Check that the file is 128KB.
cmp #$02
bne .close
lda f32_file_length + 3
ora f32_file_length + 1
ora f32_file_length + 0
bne .close
stz <__ax + 0 ; Lo-byte of # blocks in file.
lda #>(131072 / 512)
sta <__ax + 1 ; Hi-byte of # blocks in file.
lda #$4F ; Map in TED2 512KB bank 4.
sta sdc_data_bank
stz <sdc_data_addr + 0 ; Xfer into $6000-$67FF.
lda #$60
sta <sdc_data_addr + 1
lda mb1_base_bank ; Select the starting bank.
tam3
ldx #TOS_OK
.exit: rts
.close: jmp f32_close_file ; Close the file & set N & Z.
.filename: db "MB128-01.BIN",0
; ***************************************************************************
; ***************************************************************************
;
; tos_load_m128 - Load an MB128 slot file into memory.
;
; Args: A = bank # of image (uses 16 contiguous banks)
; Args: tos_m128_slot = Slot #.
; Uses: __bp = Pointer to directory entry in cache.
;
; Returns: X = F32_OK (and Z flag) or an error code.
;
tos_load_m128: jsr tos_m128_file ; Select the and open the
bne .exit ; slot file.
jsr f32_file_read ; Read the file into memory.
jsr f32_close_file ; Close the file & set N & Z.
.exit: rts
; ***************************************************************************
; ***************************************************************************
;
; tos_save_m128 - Load an MB128 slot file into memory.
;
; Args: A = bank # of image (uses 16 contiguous banks)
; Args: tos_m128_slot = Slot #.
; Uses: __bp = Pointer to directory entry in cache.
;
; Returns: X = F32_OK (and Z flag) or an error code.
;
tos_save_m128: jsr tos_m128_file ; Select the and open the
bne .exit ; slot file.
jsr f32_file_write ; Write the file from memory.
jsr f32_close_file ; Close the file & set N & Z.
.exit: rts