A2osX/ProDOS.203/ProDOS.S.XDOS.C.txt

729 lines
24 KiB
Plaintext
Raw Normal View History

2019-09-10 20:53:18 +00:00
NEW
AUTO 3,1
2019-09-11 15:53:33 +00:00
* deallocate a block's entry in bitmap
* on entry, x,a = address of block
2019-09-16 20:50:08 +00:00
dealloc stx bmcnt high address of block.
2019-09-11 15:53:33 +00:00
pha save low address.
ldx vcbptr check that bitmap block address is
lda vcbbuf+19,x valid given the total # of blocks
cmp bmcnt on the volume.
pla
2019-09-14 19:13:22 +00:00
bcc L3C8C branch if invalid
2019-09-11 15:53:33 +00:00
tax
2019-09-14 19:13:22 +00:00
and #$07 bit to be or'd in
2019-09-11 15:53:33 +00:00
tay
2019-09-14 19:13:22 +00:00
lda whichbit,y (shifting takes 7 bytes, but is slower)
sta nofree save bit pattern.
txa low block address.
2019-09-11 15:53:33 +00:00
lsr bmcnt
2019-09-14 19:13:22 +00:00
ror get pointer to byte in block that
lsr bmcnt represents the block address.
2019-09-11 15:53:33 +00:00
ror
lsr bmcnt
ror
2019-09-14 19:13:22 +00:00
sta bmptr save pointer.
lsr bmcnt transfer bit which is page of bitmap
2019-09-11 15:53:33 +00:00
rol half
2019-09-14 19:13:22 +00:00
jsr fndbmap make sure device is correct one.
bcs L3C8B error.
lda bmacmap current map.
cmp bmcnt is in-core bitmap the correct one ?
beq L3C64 branch if yes.
jsr upbmap put current map away.
bcs L3C8B error.
lda bmcnt get map #
2019-09-11 15:53:33 +00:00
ldx vcbptr
2019-09-14 19:13:22 +00:00
sta vcbbuf+28,x and make it current.
2019-09-11 15:53:33 +00:00
lda bmadev
2019-09-14 19:13:22 +00:00
jsr gtbmap read it into buffer
2019-09-11 15:53:33 +00:00
bcs L3C8B
2019-09-14 19:13:22 +00:00
L3C64 ldy bmptr index to byte
2019-09-11 15:53:33 +00:00
lsr half
2019-09-14 19:13:22 +00:00
lda nofree (get indiviual bit)
2019-09-16 20:50:08 +00:00
bcc bmbufhi branch if on page 1 of bitmap
2019-09-11 15:53:33 +00:00
ora bmbuf+$100,y
sta bmbuf+$100,y
2019-09-14 19:13:22 +00:00
bcs L3C7D always.
2019-09-16 20:50:08 +00:00
bmbufhi ora bmbuf,y this address + 2 is used as an absolute reference to bmbuf high byte.
2019-09-11 15:53:33 +00:00
sta bmbuf,y
2019-09-14 19:13:22 +00:00
L3C7D lda #$80 mark bitmap as modified
2019-09-11 15:53:33 +00:00
tsb bmastat
2019-09-14 19:13:22 +00:00
inc deblock inc count of blocks deallocated
2019-09-11 15:53:33 +00:00
bne L3C8A
inc deblock+1
2019-09-14 19:13:22 +00:00
L3C8A clc
L3C8B rts
L3C8C lda #$5A bitmap block # impossible.
sec bitmap disk address wrong
rts (maybe data masquerading as indx block)
2019-09-16 20:50:08 +00:00
alc1blk jsr fndbmap get address of bitmap.
2019-09-14 19:13:22 +00:00
bcs L3CB8 error.
L3C95 ldy #$00 begin search at start of bitmap block.
sty half which half (page) to search
L3C9A lda bmbuf,y
bne L3CB9 free blocks indicated by 'on' bits
2019-09-11 15:53:33 +00:00
iny
2019-09-14 19:13:22 +00:00
bne L3C9A check all in 1st page.
inc half now search page 2.
inc basval base value = base address / 2048.
L3CA8 lda bmbuf+$100,y search 2nd half for free block
2019-09-11 15:53:33 +00:00
bne L3CB9
iny
bne L3CA8
2019-09-14 19:13:22 +00:00
inc basval add 2048 offset for next page.
jsr nxtbmap get next bitmap (if exists) and
bcc L3C95 update vcb. branch if no error.
L3CB8 rts return error.
L3CB9 sty bmptr save index pointer to valid bit group.
lda basval prep for block address calculation
2019-09-11 15:53:33 +00:00
sta scrtch+1
2019-09-14 19:13:22 +00:00
tya address of bit pattern.
asl multiply this and basval by 8
2019-09-11 15:53:33 +00:00
rol scrtch+1
asl
rol scrtch+1
asl
rol scrtch+1
2019-09-14 19:13:22 +00:00
tax low address within 7 of actual address
2019-09-11 15:53:33 +00:00
sec
lda half
2019-09-14 19:13:22 +00:00
beq L3CDB branch if allocating from 1st half.
lda bmbuf+$100,y get pattern from 2nd page.
bcs L3CDE always.
L3CDB lda bmbuf,y get bit pattern from 1st page.
L3CDE rol find left most 'on' bit
bcs L3CE4 if found.
inx adjust low address.
bne L3CDE always.
L3CE4 lsr restore pos'n of all but left most bit.
bcc L3CE4 loop until mark moves into carry.
stx scrtch save low address.
ldx half which half of bitmap ?
bne L3CF4 if page 2.
2019-09-11 15:53:33 +00:00
sta bmbuf,y
2019-09-14 19:13:22 +00:00
beq L3CF7 always.
L3CF4 sta bmbuf+$100,y update to show allocated block in use.
L3CF7 lda #$80 indicate map is modified.
2019-09-11 15:53:33 +00:00
tsb bmastat
2019-09-14 19:13:22 +00:00
ldy vcbptr subtract 1 from total free vcb blocks
lda vcbbuf+20,y to account for newly allocated block.
sbc #$01 (carry is set)
2019-09-11 15:53:33 +00:00
sta vcbbuf+20,y
2019-09-14 19:13:22 +00:00
bcs L3D10 if high free count doesn't need adj.
lda vcbbuf+21,y adjust high count
2019-09-12 06:39:47 +00:00
dec
2019-09-11 15:53:33 +00:00
sta vcbbuf+21,y
2019-09-14 19:13:22 +00:00
L3D10 clc no errors.
lda scrtch return address in y,a of newly
ldy scrtch+1 allocated block.
2019-09-11 15:53:33 +00:00
rts
2019-09-16 20:50:08 +00:00
nxtbmap ldy vcbptr inc to next bitmap, but 1st make sure there is another one.
2019-09-11 15:53:33 +00:00
lda vcbbuf+19,y
lsr
lsr
lsr
lsr
2019-09-14 19:13:22 +00:00
cmp vcbbuf+28,y are there more maps ?
beq L3D60 if no more to look at.
lda vcbbuf+28,y add 1 to current map
2019-09-11 15:53:33 +00:00
inc
sta vcbbuf+28,y
jsr upbmap
2019-09-16 20:50:08 +00:00
fndbmap ldy vcbptr
2019-09-14 19:13:22 +00:00
lda vcbbuf+16,y get device #.
cmp bmadev does this map match this device ?
beq L3D4A yes.
jsr upbmap otherwise, save other volume's bitmap
2019-09-11 15:53:33 +00:00
bcs L3D5F
ldy vcbptr
lda vcbbuf+16,y
2019-09-14 19:13:22 +00:00
sta bmadev and read in fresh bitmap for this dev.
L3D4A ldy bmastat is it already modified ?
bmi L3D54 yes, return pointer
jsr gtbmap otherwise read in fresh bitmap.
bcs L3D5F if error.
L3D54 ldy vcbptr get relative block # of bitmap.
2019-09-11 15:53:33 +00:00
lda vcbbuf+28,y
2019-09-14 19:13:22 +00:00
asl 2 pages per block
2019-09-11 15:53:33 +00:00
sta basval
2019-09-14 19:13:22 +00:00
clc no errors.
L3D5F rts
L3D60 lda #$48 request can't be filled
sec error
2019-09-11 15:53:33 +00:00
rts
2019-09-16 20:50:08 +00:00
upbmap clc
2019-09-14 19:13:22 +00:00
lda bmastat is current map modified ?
bpl L3D5F no.
jsr wrtbmap update device.
bcs L3D5F if error on writing.
2019-09-11 15:53:33 +00:00
lda #$00
2019-09-14 19:13:22 +00:00
sta bmastat mark bitmap buffer as free
2019-09-11 15:53:33 +00:00
rts
2019-09-16 20:50:08 +00:00
gtbmap sta bmadev read bitmap specified by dev and vcb.
2019-09-14 19:13:22 +00:00
ldy vcbptr get lowest map # with free blocks in it
2019-09-11 15:53:33 +00:00
lda vcbbuf+28,y
2019-09-14 19:13:22 +00:00
sta bmacmap associate offset with bitmap ctrl block.
clc add this # to the base address of
adc vcbbuf+26,y 1st bitmap and save in bmadadr which
sta bmadadr is address of bitmap to be used.
2019-09-11 15:53:33 +00:00
lda vcbbuf+27,y
adc #$00
sta bmadadr+1
2019-09-14 19:13:22 +00:00
lda #$01 read device command
L3D92 sta A4L
lda devnum save current dev #
2019-09-11 15:53:33 +00:00
pha
2019-09-14 19:13:22 +00:00
lda bmadev get bitmap's dev #
2019-09-11 15:53:33 +00:00
sta devnum
2019-09-14 19:13:22 +00:00
lda bmadadr and disk address
2019-09-11 15:53:33 +00:00
sta bloknml
lda bmadadr+1
sta bloknml+1
2019-09-14 19:13:22 +00:00
lda bmbufhi+2 address of the buffer (low = 0)
2019-09-11 15:53:33 +00:00
jsr dobitmap
2019-09-14 19:13:22 +00:00
tax error code (if any).
pla restore current dev #
2019-09-11 15:53:33 +00:00
sta devnum
2019-09-14 19:13:22 +00:00
bcc L3DB6 and return it if no error.
txa error code
L3DB6 rts
2019-09-16 20:50:08 +00:00
rdblk sta bloknml
2019-09-11 15:53:33 +00:00
stx bloknml+1
jsr rdgbuf
rts
2019-09-16 20:50:08 +00:00
wrtbmap lda #$02 write command.
2019-09-14 19:13:22 +00:00
bne L3D92 always.
2019-09-16 20:50:08 +00:00
wrtgbuf lda #$02 write command
2019-09-14 19:13:22 +00:00
bne L3DC9 always.
2019-09-16 20:50:08 +00:00
rdgbuf lda #$01 read command.
2019-09-14 19:13:22 +00:00
L3DC9 sta A4L pass to device handler.
lda /gbuf general buffer.
2019-09-16 20:50:08 +00:00
dobitmap php no interrupts
2019-09-11 15:53:33 +00:00
sei
2019-09-14 19:13:22 +00:00
sta buf+1 buffer high.
stz buf buffer low (always on page boundary)
stz p8error clear global error code.
lda #$FF indicates reg call made to dev handler
2019-09-11 15:53:33 +00:00
sta ioaccess
2019-09-14 19:13:22 +00:00
lda devnum transfer dev # for dispatcher to
sta unitnum convert to unit #.
jsr dmgr call the driver.
bcs L3DE8 if error.
plp restore interrupts.
2019-09-11 15:53:33 +00:00
clc
rts
2019-09-14 19:13:22 +00:00
L3DE8 plp file i/o error. restore interrupts.
2019-09-11 15:53:33 +00:00
sec
rts
2019-09-10 20:53:18 +00:00
* get mark command
2019-09-16 20:50:08 +00:00
getmark ldx fcbptr index to open fcb.
2019-09-14 19:13:22 +00:00
ldy #$02 index to user's mark parmeter.
.1 lda fcbbuf+18,x transfer current position
sta (A3L),y to user's parameter list
2019-09-10 20:53:18 +00:00
inx
iny
2019-09-14 19:13:22 +00:00
cpy #$05 transfer 3 bytes
2019-09-11 15:53:33 +00:00
bne .1
2019-09-10 20:53:18 +00:00
clc
rts
2019-09-14 19:13:22 +00:00
L3DFD lda #$4D invalid position
2019-09-10 20:53:18 +00:00
sec
rts
* set mark command
2019-09-16 20:50:08 +00:00
setmark ldy #$04 index to user's desired position.
2019-09-14 19:13:22 +00:00
ldx fcbptr file's control block index.
inx inc by 2 for index to hi eof
2019-09-10 20:53:18 +00:00
inx
2019-09-14 19:13:22 +00:00
sec indicate comparisons are necessary.
.1 lda (A3L),y move it to 'tpos'
2019-09-10 20:53:18 +00:00
sta tposll-2,y
2019-09-14 19:13:22 +00:00
bcc .2 branch if mark < eof
2019-09-10 20:53:18 +00:00
cmp fcbbuf+21,x
2019-09-14 19:13:22 +00:00
bcc .2 branch if mark qualifies.
bne L3DFD branch if mark > eof (invalid position)
2019-09-10 20:53:18 +00:00
dex
2019-09-14 19:13:22 +00:00
.2 dey move/compare next lower byte of mark.
tya test for all bytes moved/tested.
eor #$01 preserves carry status.
bne .1 branch if more.
2019-09-16 20:50:08 +00:00
rdposn ldy fcbptr test to see if new position is
2019-09-14 19:13:22 +00:00
lda fcbbuf+19,y within the same (current) data block.
2019-09-10 20:53:18 +00:00
and #$FE
sta scrtch
2019-09-14 19:13:22 +00:00
lda tposlh middle byte of new position
2019-09-10 20:53:18 +00:00
sec
sbc scrtch
sta scrtch
2019-09-14 19:13:22 +00:00
bcc L3E44 branch if < current position.
cmp #$02 must be within 512 bytes of beginning
bcs L3E44 of current position.
lda tposhi make sure within the same 64k.
2019-09-10 20:53:18 +00:00
cmp fcbbuf+20,y
2019-09-14 19:13:22 +00:00
bne L3E44 branch if not.
jmp svmark if so, adj fcb, position ptr and return.
L3E44 lda fcbbuf+7,y determine file type for positioning.
beq L3E50 0 = invalid file type.
cmp #$04 tree class file?
bcc L3E59 yes, go position.
jmp dirmark no, test for dir type.
L3E50 ldy #$A4 clear illegal filetype entry in fcb
2019-09-10 20:53:18 +00:00
sta fcbbuf,y
2019-09-14 19:13:22 +00:00
lda #$43 and report error
2019-09-10 20:53:18 +00:00
sec
rts
2019-09-14 19:13:22 +00:00
L3E59 lda fcbbuf+7,y use storage type as # of index levels
sta levels since 1=seed, 2=sapling, 3=tree.
2019-09-10 20:53:18 +00:00
lda fcbbuf+8,y
2019-09-14 19:13:22 +00:00
and #$40 if previous data was modified then
beq L3E6B disk must be updated.
2019-09-10 20:53:18 +00:00
jsr wfcbdat
2019-09-14 19:13:22 +00:00
bcs L3ED4 if error.
L3E6B ldy fcbptr test to see if current index block
2019-09-11 15:53:33 +00:00
lda fcbbuf+20,y is usable by checking if new
2019-09-14 19:13:22 +00:00
and #$FE position is within 128k of the
sta scrtch beginning of current sapling level
lda tposhi chunk.
2019-09-10 20:53:18 +00:00
sec
sbc scrtch
2019-09-11 15:53:33 +00:00
bcc L3E9D branch if a new index block is needed.
cmp #$02 is new position within 128k of old ?
bcs L3E9D branch if not.
ldx levels is it a seed file ?
2019-09-10 20:53:18 +00:00
dex
2019-09-11 15:53:33 +00:00
bne datlevel no, use current indexes.
2019-09-14 19:13:22 +00:00
L3E89 lda tposlh is new position < 512 ?
2019-09-11 15:53:33 +00:00
lsr
2019-09-10 20:53:18 +00:00
ora tposhi
2019-09-11 15:53:33 +00:00
bne L3EEF no, mark both data and index block as
lda fcbbuf+12,y unallocated. 1st block is only block
sta bloknml and it's data.
lda fcbbuf+13,y high block address.
jmp rnewpos go read in block and set statuses.
2019-09-14 19:13:22 +00:00
L3E9D lda fcbbuf+8,y check to see if previous index block
2019-09-11 15:53:33 +00:00
and #$80 was modified.
beq L3EA9 read in over it if current up to date.
jsr wfcbidx go update index on disk (fcb block addr)
2019-09-10 20:53:18 +00:00
bcs L3ED4
2019-09-14 19:13:22 +00:00
L3EA9 ldx levels be sure there is a top index
cpx #$03 before reading it...
2019-09-11 15:53:33 +00:00
beq posindex branch if file is a tree.
2019-09-14 19:13:22 +00:00
lda tposhi is new position within range of a
lsr sapling file (less than 128k) ?
php save results
lda #$07 (no level is allocated for new pos'n)
plp restore z-flag.
bne L3F18 go mark all as dummy.
2019-09-10 20:53:18 +00:00
jsr clrstats clr status bits 0,1,2 (index/data/alloc)
2019-09-14 19:13:22 +00:00
dex check for seed
beq L3E89 if seed, check for position < 512.
jsr rfcbfst go get only index block.
bcs L3ED4 if error.
ldy fcbptr save newly loaded index block's address.
2019-09-10 20:53:18 +00:00
lda bloknml
sta fcbbuf+14,y
lda bloknml+1
sta fcbbuf+15,y
bcc datlevel branch always
2019-09-14 19:13:22 +00:00
L3ED4 rts
posindex jsr clrstats clr all alloc requirements for previous
jsr rfcbfst position. get highest level index block
2019-09-10 20:53:18 +00:00
bcs L3ED4
2019-09-14 19:13:22 +00:00
lda tposhi then test for a sap level index block
2019-09-11 15:53:33 +00:00
lsr
2019-09-10 20:53:18 +00:00
tay
lda (zpt),y
inc zpt+1
2019-09-14 19:13:22 +00:00
cmp (zpt),y (both high and low = 0 if no index exists)
2019-09-10 20:53:18 +00:00
bne saplevel
2019-09-14 19:13:22 +00:00
tax are both bytes 0 ?
2019-09-10 20:53:18 +00:00
bne saplevel
dec zpt+1
2019-09-14 19:13:22 +00:00
L3EEF lda #$03 show neither index or data block alloc'd
2019-09-10 20:53:18 +00:00
bra L3F18
2019-09-14 19:13:22 +00:00
saplevel sta bloknml read in next lower index block.
lda (zpt),y (high address)
2019-09-10 20:53:18 +00:00
sta bloknml+1
dec zpt+1
2019-09-14 19:13:22 +00:00
jsr rfcbidx read in sapling level
2019-09-10 20:53:18 +00:00
bcs L3ED4
2019-09-14 19:13:22 +00:00
datlevel lda tposhi get block address of data block
2019-09-11 15:53:33 +00:00
lsr
2019-09-14 19:13:22 +00:00
lda tposlh ( if there is one )
2019-09-11 15:53:33 +00:00
ror
2019-09-10 20:53:18 +00:00
tay
2019-09-14 19:13:22 +00:00
lda (zpt),y data block address low
2019-09-10 20:53:18 +00:00
inc zpt+1
cmp (zpt),y
bne L3F51
tax
bne L3F51
2019-09-14 19:13:22 +00:00
lda #$01 show data block as never been allocated
2019-09-10 20:53:18 +00:00
dec zpt+1
2019-09-14 19:13:22 +00:00
L3F18 ldy fcbptr set status to show what's missing
2019-09-10 20:53:18 +00:00
ora fcbbuf+8,y
sta fcbbuf+8,y
2019-09-14 19:13:22 +00:00
lsr discard bit that says data block
lsr unallocated because carry indicates if
jsr zipdata index block is invalid and needs to be
2019-09-16 20:50:08 +00:00
bcc svmark zeroed. branch if it doesn't need zeroed
2019-09-14 19:13:22 +00:00
jsr zeroindex zero index block in user's i/o buffer
2019-09-16 20:50:08 +00:00
bra svmark
zeroindex lda #$00
2019-09-10 20:53:18 +00:00
tay
2019-09-14 19:13:22 +00:00
L3F30 sta (zpt),y zero out the index half of the user's
iny i/o buffer
2019-09-10 20:53:18 +00:00
bne L3F30
inc zpt+1
2019-09-14 19:13:22 +00:00
L3F37 sta (zpt),y
2019-09-10 20:53:18 +00:00
iny
bne L3F37
2019-09-14 19:13:22 +00:00
dec zpt+1 restore proper address
2019-09-10 20:53:18 +00:00
rts
2019-09-16 20:50:08 +00:00
zipdata lda #$00
2019-09-10 20:53:18 +00:00
tay
2019-09-14 19:13:22 +00:00
L3F42 sta (datptr),y zero out data area
2019-09-10 20:53:18 +00:00
iny
bne L3F42
inc datptr+1
2019-09-14 19:13:22 +00:00
L3F49 sta (datptr),y
2019-09-10 20:53:18 +00:00
iny
bne L3F49
dec datptr+1
rts
2019-09-14 19:13:22 +00:00
L3F51 sta bloknml get data block of new position
lda (zpt),y (high address)
2019-09-10 20:53:18 +00:00
dec zpt+1
2019-09-16 20:50:08 +00:00
rnewpos sta bloknml+1
2019-09-10 20:53:18 +00:00
jsr rfcbdat
2019-09-14 19:13:22 +00:00
bcs L3F86 if error.
jsr clrstats show whole chain is allocated.
2019-09-16 20:50:08 +00:00
svmark ldy fcbptr update position in fcb
2019-09-10 20:53:18 +00:00
iny
iny
ldx #$02
2019-09-14 19:13:22 +00:00
L3F68 lda fcbbuf+18,y save old mark in case calling routine
sta oldmark,x fails later.
2019-09-10 20:53:18 +00:00
lda tposll,x
sta fcbbuf+18,y
dey
2019-09-14 19:13:22 +00:00
dex move 3 byte position marker
2019-09-10 20:53:18 +00:00
bpl L3F68
2019-09-14 19:13:22 +00:00
clc set up indirect address to buffer
lda datptr page pointed to by the current
sta sos position marker.
2019-09-10 20:53:18 +00:00
lda tposlh
and #$01
adc datptr+1
sta sos+1
2019-09-14 19:13:22 +00:00
L3F86 rts carry set if error
2019-09-16 20:50:08 +00:00
clrstats ldy fcbptr clear allocation states for data block
2019-09-14 19:13:22 +00:00
lda fcbbuf+8,y and both levels of indexes/
2019-09-10 20:53:18 +00:00
and #$F8
2019-09-14 19:13:22 +00:00
sta fcbbuf+8,y indicates that either they exist now
rts or unnecessary for current position.
2019-09-16 20:50:08 +00:00
dirmark cmp #$0D is it a directory ?
2019-09-14 19:13:22 +00:00
beq L3F9C yes...
lda #$4A no, so compatability problem.
jsr p8errv should not have been opened !!!
L3F9C lda scrtch recover results of previous subtraction.
lsr use difference as counter for how many
sta cntent blocks must be read to get to new pos'n.
lda fcbbuf+19,y test for positive direction
cmp tposlh indicated by carry.
bcc L3FB9 if set, position forward. otherwise,
L3FAB ldy #$00 read directory file in reverse order.
jsr dirpos1 read previous block.
bcs L3FD6 if error.
inc cntent count up to 128.
bpl L3FAB loop if more blocks to pass over.
2019-09-16 20:50:08 +00:00
bmi svmark always.
2019-09-14 19:13:22 +00:00
L3FB9 ldy #$02 position is forward from current.
jsr dirpos1 read next directory block
bcs L3FD6 if error.
2019-09-10 20:53:18 +00:00
dec cntent
2019-09-14 19:13:22 +00:00
bne L3FB9 loop if position not found in this block
2019-09-16 20:50:08 +00:00
beq svmark branch always.
dirpos1 lda (datptr),y get link address of previous or next
2019-09-14 19:13:22 +00:00
sta bloknml directory block.
cmp #$01 test for null byte into carry
iny but first be sure there is a link.
lda (datptr),y get the rest of the link.
bne L3FD8 branch if certain link exists.
bcs L3FD8 was the low part null as well ?
lda #$4C something is wrong with directory file!
L3FD6 sec error.
2019-09-10 20:53:18 +00:00
rts
2019-09-14 19:13:22 +00:00
L3FD8 sta bloknml+1
2019-09-10 20:53:18 +00:00
* read file's data block
2019-09-16 20:50:08 +00:00
rfcbdat lda #$01 read command
2019-09-10 20:53:18 +00:00
sta A4L
2019-09-14 19:13:22 +00:00
ldx #datptr points at address of data buffer.
jsr fileio1 go do file input.
bcs L3FF2 error.
2019-09-10 20:53:18 +00:00
ldy fcbptr
lda bloknml
2019-09-14 19:13:22 +00:00
sta fcbbuf+16,y save block # just read in fcb.
2019-09-10 20:53:18 +00:00
lda bloknml+1
sta fcbbuf+17,y
2019-09-14 19:13:22 +00:00
L3FF2 rts
2019-09-16 20:50:08 +00:00
rfcbidx lda #$01 prepare to read index block : read command
2019-09-10 20:53:18 +00:00
sta A4L
2019-09-14 19:13:22 +00:00
ldx #$48 address of current index buffer.
jsr fileio1 go read index block.
bcs L400C error
2019-09-10 20:53:18 +00:00
ldy fcbptr
lda bloknml
2019-09-14 19:13:22 +00:00
sta fcbbuf+14,y save block address of this index in fcb
2019-09-10 20:53:18 +00:00
lda bloknml+1
sta fcbbuf+15,y
clc
2019-09-14 19:13:22 +00:00
L400C rts
L400D lda #$02 write command
.HS 2C skip next instruction
2019-09-16 20:50:08 +00:00
rfcbfst lda #$01 read command.
2019-09-14 19:13:22 +00:00
pha save the command
2019-09-10 20:53:18 +00:00
lda #$0C
2019-09-14 19:13:22 +00:00
ora fcbptr add offset to fcbptr
2019-09-10 20:53:18 +00:00
tay
pla
2019-09-14 19:13:22 +00:00
ldx #$48 rd block into index portion of file buf
2019-09-16 20:50:08 +00:00
dofileio sta A4L command
2019-09-14 19:13:22 +00:00
lda fcbbuf,y get disk block address from fcb.
sta bloknml block 0 not legal
2019-09-10 20:53:18 +00:00
cmp fcbbuf+1,y
bne L4031
2019-09-14 19:13:22 +00:00
cmp #$00 are both bytes 0 ?
bne L4031 no, continue request
lda #$0C otherwise, allocation error.
2019-09-10 20:53:18 +00:00
jsr sysdeath doesn't return...
2019-09-14 19:13:22 +00:00
L4031 lda fcbbuf+1,y high address of disk block
2019-09-10 20:53:18 +00:00
sta bloknml+1
2019-09-16 20:50:08 +00:00
fileio1 php no interrupts
2019-09-10 20:53:18 +00:00
sei
2019-09-14 19:13:22 +00:00
lda $00,x get memory address of buffer from
sta buf page zero pointed to by x register
2019-09-10 20:53:18 +00:00
lda $01,x
2019-09-14 19:13:22 +00:00
sta buf+1 and pass address to device handler
2019-09-10 20:53:18 +00:00
ldy fcbptr
lda fcbbuf+1,y
2019-09-14 19:13:22 +00:00
sta devnum along with device #.
lda #$FF also, set to indicate reg call made to
sta ioaccess device handler.
lda devnum transfer device # for dispatcher
sta unitnum to convert to unit #.
stz p8error clear global error code.
jsr dmgr call the driver.
bcs L405E if error.
plp restore interrupts
2019-09-10 20:53:18 +00:00
clc
rts
2019-09-14 19:13:22 +00:00
L405E plp restore interrupts
2019-09-10 20:53:18 +00:00
sec
rts
2019-09-16 20:50:08 +00:00
wfcbfst jsr upbmap update the bitmap
2019-09-14 19:13:22 +00:00
bra L400D and write file's 1st block.
2019-09-16 20:50:08 +00:00
wfcbdat ldx #datptr point at memory address with x and
2019-09-14 19:13:22 +00:00
lda #$10 disk address with y.
ora fcbptr add offset to fcbptr
tay and put in y.
lda #$02 write data block.
2019-09-10 20:53:18 +00:00
jsr dofileio
2019-09-14 19:13:22 +00:00
bcs L4096 if errors.
lda #$BF mark data status as current.
2019-09-10 20:53:18 +00:00
bra L408D
2019-09-16 20:50:08 +00:00
wfcbidx jsr upbmap update bitmap.
2019-09-14 19:13:22 +00:00
ldx #$48 point to address of index buffer
lda #$0E and block address of that index block.
2019-09-10 20:53:18 +00:00
ora fcbptr
tay
lda #$02
2019-09-14 19:13:22 +00:00
jsr dofileio go write out index block.
bcs L4096 if errors.
lda #$7F mark index status as current.
L408D ldy fcbptr change status byte to reflect
and fcbbuf+8,y successful disk file update.
sta fcbbuf+8,y (carry is unaffected)
L4096 rts
2019-09-10 20:53:18 +00:00
2019-09-16 20:50:08 +00:00
openf jsr findfile look up the file.
2019-09-14 19:13:22 +00:00
bcc L40A0 if ok.
cmp #$40 is this opening a root directory ?
bne L40A7 if not, then error.
L40A0 jsr tstopen are any other files writing to this
bcc L40AD same file ? branch if not.
L40A5 lda #$50 file is busy, shared access not allowed.
L40A7 sec
2019-09-10 20:53:18 +00:00
rts
2019-09-14 19:13:22 +00:00
L40A9 lda #$4B file is wrong storage type.
2019-09-10 20:53:18 +00:00
sec
rts
2019-09-14 19:13:22 +00:00
L40AD ldy fcbptr get address of 1st free fcb found.
lda fcbflg if this byte <> 0 then free fcb found
bne L40B9 and available for use.
lda #$42 fcb full error.
2019-09-10 20:53:18 +00:00
sec
rts
2019-09-14 19:13:22 +00:00
L40B9 ldx #$1F assign fcb,
lda #$00 but clean it first.
L40BD sta fcbbuf,y
2019-09-10 20:53:18 +00:00
iny
dex
bpl L40BD
2019-09-14 19:13:22 +00:00
lda #$06 start claiming it by moving in file info
tax using x as source index
ora fcbptr and y as destination (fcb).
2019-09-10 20:53:18 +00:00
tay
2019-09-14 19:13:22 +00:00
L40CB lda d_dev-1,x move ownership info.
sta fcbbuf,y note: this code depends upon the defined
dey order of both the fcb and directory
dex entry buffer.
2019-09-10 20:53:18 +00:00
bne L40CB
2019-09-14 19:13:22 +00:00
lda d_stor get storage type and
lsr strip off file name length
lsr by dividing by 16.
2019-09-11 15:53:33 +00:00
lsr
lsr
2019-09-14 19:13:22 +00:00
tax save in x for later comparison
sta fcbbuf+7,y and in fcb for future access.
lda d_attr get file's attributes and use it
and #$03 as a default access request.
cpx #$0D if directory, don't allow write enable.
2019-09-10 20:53:18 +00:00
bne L40EB
2019-09-14 19:13:22 +00:00
and #$01 read enabled bit
L40EB sta fcbbuf+9,y
and #$02 check for write enabled request.
beq L40F7 branch for open as read-only
lda totent otherwise, be sure no one else is
bne L40A5 reading the same file. branch if busy.
L40F7 cpx #$04 is it a tree file type ?
bcc L40FF yes.
cpx #$0D is it a directory type ?
bne L40A9 if not, wrong storage type.
L40FF ldx #$06 move address of 1st block of file, end
L4101 sta bloknml+1 of file and current usage count.
2019-09-10 20:53:18 +00:00
lda fcbptr
2019-09-14 19:13:22 +00:00
ora ofcbtbl,x this is done via a translation table
tay between directory info and fcb.
2019-09-10 20:53:18 +00:00
lda d_frst,x
sta fcbbuf,y
dex
2019-09-14 19:13:22 +00:00
bpl L4101 last loop stores hi address of 1st block
sta bloknml and this is the low one.
2019-09-10 20:53:18 +00:00
ldy fcbptr
2019-09-14 19:13:22 +00:00
lda cntent this was set up by 'tstopen'.
sta fcbbuf,y claim fcb for this file.
2019-09-10 20:53:18 +00:00
jsr alcbuffr go allocate buffer in memory tables.
2019-09-14 19:13:22 +00:00
bcs L4147 if errors.
jsr fndfcbuf rtn addr of bufs in data & index ptrs.
lda flevel mark level at which
sta fcbbuf+27,y file was opened.
lda fcbbuf+7,y file must be positioned at beginning.
cmp #$04 is it a tree file ?
bcs L415E no, assume a directory.
lda #$FF fool the position routine into giving
sta fcbbuf+20,y a valid position with preloaded data,
ldy #$02 etc. set desired position to 0.
2019-09-10 20:53:18 +00:00
lda #$00
2019-09-14 19:13:22 +00:00
L413C sta tposll,y
2019-09-10 20:53:18 +00:00
dey
bpl L413C
2019-09-14 19:13:22 +00:00
jsr rdposn let tree position routine do the rest.
bcc L4163 if successful.
L4147 pha save error code.
ldy fcbptr free buffer space.
2019-09-10 20:53:18 +00:00
lda fcbbuf+11,y
2019-09-14 19:13:22 +00:00
beq L4156 if no bufnum, ok because never alloc'd.
jsr relbuffr go release buffer.
ldy fcbptr since error was before file was
L4156 lda #$00 successfully opened, then it is
sta fcbbuf,y necessary to release fcb also.
pla error code.
2019-09-10 20:53:18 +00:00
sec
rts
2019-09-14 19:13:22 +00:00
L415E jsr rfcbdat read in 1st block of directory file.
bcs L4147 return error after freeing buffer & fcb.
L4163 ldx vcbptr index to vcb.
inc vcbbuf+30,x add 1 to # of files currently open
lda vcbbuf+17,x and indicate that this volume has at
ora #$80 least 1 file active.
2019-09-10 20:53:18 +00:00
sta vcbbuf+17,x
2019-09-14 19:13:22 +00:00
ldy fcbptr index to fcb.
lda fcbbuf,y return ref # to user.
2019-09-10 20:53:18 +00:00
ldy #$05
sta (A3L),y
2019-09-14 19:13:22 +00:00
clc open is successful
2019-09-10 20:53:18 +00:00
rts
* test open
* is there an open file?
2019-09-16 20:50:08 +00:00
tstopen lda #$00
2019-09-14 19:13:22 +00:00
sta cntent returns the ref # of a free fcb.
sta totent flag to indicate file already open.
sta fcbflg flag indicates a free fcb is available.
L4188 tay index to next fcb.
ldx fcbflg test for free fcb found.
bne L4191 if already found.
2019-09-10 20:53:18 +00:00
inc cntent
2019-09-14 19:13:22 +00:00
L4191 lda fcbbuf,y is this fcb in use ?
bne L41A3 yes.
txa if not, should we claim it ?
bne L41C1 branch if free fcb already found.
sty fcbptr save index to new free fcb.
lda #$FF set fcb flag to indicate
sta fcbflg free fcb found.
bne L41C1 branch always to test next fcb.
L41A3 tya add offset to index to ownership info
2019-09-10 20:53:18 +00:00
ora #$06
2019-09-14 19:13:22 +00:00
tay and put it back in y.
ldx #$06 index to directory entry owner info.
L41A9 lda fcbbuf,y all bytes must match to say that it's
cmp d_dev-1,x the same file again.
bne L41C1 if not, then next fcb.
dey index to next lower bytes.
2019-09-10 20:53:18 +00:00
dex
2019-09-14 19:13:22 +00:00
bne L41A9 loop to check all owner info.
inc totent file is already open, now see
lda fcbbuf+9,y if it's already opened for write. and #$02 if so report file busy (with carry set).
and #$02 if so report file busy (with carry set).
beq L41C1 branch if this file is read access only.
2019-09-10 20:53:18 +00:00
sec
rts
2019-09-14 19:13:22 +00:00
L41C1 tya calc position of next fcb.
and #$E0 first strip any possible index offsets.
2019-09-10 20:53:18 +00:00
clc
2019-09-14 19:13:22 +00:00
adc #$20 inc to next fcb.
bne L4188 branch if more to compare.
clc report no conflicts.
2019-09-10 20:53:18 +00:00
rts
MAN
SAVE USR/SRC/PRODOS.203/PRODOS.S.XDOS.C
LOAD USR/SRC/PRODOS.203/PRODOS.S
ASM