calculate free blocks

This commit is contained in:
Kelvin Sherlock 2015-09-15 14:18:14 -04:00
parent 9b18dd8aa4
commit f7bdc1df9b
3 changed files with 117 additions and 3 deletions

View File

@ -20,7 +20,7 @@ parent_inode ds.w 1
;disk_inode ds v1_inode ;disk_inode ds v1_inode
;super ds v1_super ;super ds v1_super
__end equ * __end equ *
IF *>=$d4 THEN IF *>=$d4 THEN
AERROR 'dp -- too large.' AERROR 'dp -- too large.'
ENDIF ENDIF
@ -78,6 +78,7 @@ super ds v1_super
first_inode_block ds.w 1 first_inode_block ds.w 1
first_imap_block ds.w 1 first_imap_block ds.w 1
first_zmap_block ds.w 1 first_zmap_block ds.w 1
free_blocks ds.w 1
; case-sensitive volume name. ; case-sensitive volume name.
vname ds GSString32 vname ds GSString32

View File

@ -28,8 +28,11 @@
entry check_super entry check_super
entry build_vcr entry build_vcr
import device_read entry calc_free_blocks
entry bitcount
import device_read
import read_data_block
id_disk procname export id_disk procname export
@ -262,6 +265,10 @@ create_vcr
ldy #vcr.first_inode_block ldy #vcr.first_inode_block
sta [my_vcr],y sta [my_vcr],y
vname vname
; also need to copy over the volume name... ; also need to copy over the volume name...
@ -284,6 +291,11 @@ vname
long m long m
; store free blocks in the vcr?
jsr calc_free_blocks
bcs exit
; ~DebugHexDump <my_vcr,#vcr.__sizeof ; ~DebugHexDump <my_vcr,#vcr.__sizeof
lda #0 lda #0
@ -299,6 +311,98 @@ default_name
endp 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 end

View File

@ -184,10 +184,19 @@ do_total_blocks proc
do_free_blocks proc do_free_blocks proc
; load the zmaps and count them up... ; load the zmaps and count them up...
; someday. ; someday.
with fst_parms with fst_parms, dp
phy
ldy #vcr.free_blocks
lda [my_vcr],y
ply
sta [param_blk_ptr],y
iny
iny
lda #0 lda #0
sta [param_blk_ptr],y sta [param_blk_ptr],y
rts rts
endp endp