-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid_disk.aii
408 lines (305 loc) · 4.49 KB
/
id_disk.aii
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
include 'gsos.equ'
include 'minix.equ'
include 'records.equ'
include 'fst.equ'
include 'fst.macros'
include 'M16.Debug'
; id_disk
; identify disk in device.
;
; inputs:
; a = device id
;
; outputs:
; (registers)
; c = 1 for error
; a = error code or 0
; (dp)
; my_vcr
;
entry check_super
entry build_vcr
entry calc_free_blocks
entry bitcount
import device_read
import read_data_block
id_disk procname export
;
; read the superblock
;
;
; note - minix has 1024-k blocks. I'm only reading 512
; since there's nothing of interest in the second half of the
; superblock.
with dev_parms
with v1
sta dev_num
lda #512
;sta dev_blk_size
sta dev_req_cnt
lda #SUPER_BLOCK*2
sta dev_blk_num
jsr device_read
bcs exit
jsr check_super
bcs exit
;
; if my_vcr is set, we only need to verify this is a minix disk,
; not building a new vcr.
lda dp.my_vcr
ora dp.my_vcr+2
bne done
jsr build_vcr
bcs exit
done
; error priority $8000?
lda #0
clc
exit
rts
endp
;
; checks if the super block is valid for minix.
; returns a = error / 0
;
check_super procname
with dev_parms
with v1_super
with dp
check_magic
ldy #magic
lda [dev_buff],y
cmp #v1.MAGIC
beq @ok
cmp #v1L.MAGIC
bne no
@ok
check_log_zone
; should be 0
ldy #log_zone_size
lda [dev_buff],y
bne no
; todo
; if my_vcr is valid, check the volume name...
;
;
yes
clc
rts
no
lda #unknown_vol
sec
rts
endp
build_vcr procname
; for now, volume hard coded as 'minix'.
;
; todo --
; offset 128 $6502 (magic word)
; 130 (minix) volume name, terminated w/ 0
; 14 chars for minix, 30 chars for linux.
;
with v1
with dp
ldx #default_name
ldy #^default_name
lda #0
jsl find_vcr
bcs create_vcr
jsl deref
stx my_vcr
sty my_vcr+2
ldy #vcr.fst_id
lda [my_vcr],y
cmp #fst_id
bne dump_vcr
ldy #vcr.status
lda [my_vcr],y
and #vcr_swapped
beq @exit
and #vcr_swapped_in
sta [my_vcr],y
;lda device
lda dev_parms.dev_num
ldy #vcr.device
sta [my_vcr],y
@exit
lda #0
clc
rts
dump_vcr
; vcr exists for the filename but it's not mine.
; if inactive, kick it out. otherwise, return dup error.
;
; todo -- prodos fst has kludge for change path which
; allows duplicates if using a device name or something...
;
ldy #vcr.open_count
lda [my_vcr],y
beq @dump
lda #dup_volume
sec
rts
@dump
ldy #vcr.id
lda [my_vcr],y
jsl release_vcr
; drop through.
create_vcr
lda #vcr.__sizeof
ldx #default_name
ldy #^default_name
jsl alloc_vcr
lda #out_of_mem
bcs exit
jsl deref
stx my_vcr
sty my_vcr+2
lda #0
ldy #vcr.status
sta [my_vcr],y
ldy #vcr.open_count
sta [my_vcr],y
lda #fst_id
ldy #vcr.fst_id
sta [my_vcr],y
lda dev_parms.dev_num
ldy #vcr.device
sta [my_vcr],y
; copy over the super block...
clc
lda #vcr.super
adc my_vcr
sta ptr
lda #0
adc my_vcr+2
sta ptr+2
ldy #v1_super.__sizeof-2
@loop
lda [dev_parms.dev_buff],y
sta [ptr],y
dey
dey
bpl @loop
;
; boot
; super
; imap blocks
; zmap blocks
; inodes
; zones
; calculate offsets
lda #2 ; hard-coded.
ldy #vcr.first_imap_block
sta [my_vcr],y
clc
ldy #vcr.super.imap_blocks
adc [my_vcr],y
ldy #vcr.first_zmap_block
sta [my_vcr],y
clc
ldy #vcr.super.zmap_blocks
adc [my_vcr],y
ldy #vcr.first_inode_block
sta [my_vcr],y
vname
; also need to copy over the volume name...
;ldy #vcr.vname
lda default_name_colon
;sta [my_vcr],y
inc a
tax
clc
adc #vcr.vname
tay
short m
@loop
lda default_name_colon,x
sta [my_vcr],y
dey
dex
bpl @loop
long m
; store free blocks in the vcr?
jsr calc_free_blocks
bcs exit
; ~DebugHexDump <my_vcr,#vcr.__sizeof
lda #0
clc
exit
rts
default_name_colon
str.w ':minix'
default_name
str.w 'minix'
endp
calc_free_blocks procname
with dp
stz count
ldy #vcr.first_inode_block
lda [my_vcr],y
sta endb
ldy #vcr.first_zmap_block
lda [my_vcr],y
sta block
loop
jsr read_data_block
bcs error
jsr bitcount
clc
adc count
sta count
lda block
inc a
cmp endb
bcc loop
; done!
ldy #vcr.free_blocks
lda count
sta [my_vcr],y
lda #0
clc
error
rts
block ds.w 1
endb ds.w 1
count ds.w 1
endp
bitcount procname
; count up a page of bitmaps...
; count the 0s, not the 1s.
with dp
ldy #1024-2
ldx #0
loop
lda [io_buffer],y
beq add16
eor #$ffff
beq next
; now inverted, so count the 1s.
; kernighan / wegner
; 1 pass per bit.
pha
bloop
dec a
and 1,s
beq bdone
inx
sta 1,s
bra bloop
bdone
pla
bra next
add16
txa
clc
adc #16
tax
next
dey
dey
bpl loop
txa
rts
endp
end