Re: TI-H: empeg player 2
[Prev][Next][Index][Thread]
Re: TI-H: empeg player 2
nxtext bsr fmpaloc ; allocate next extension block
bmi fpcret
move.l d0,(a1) ; save new ext block lba to link field
* bsr print ; !!!!!!!!!!!!!!
move.l ext_lba(a0),-(a7)
jsr slba
move.b #1,hd1+5
pea.l ent_ext(a0)
jsr shdbuf ; save old extension block
adda.l #8,a7
tst.l d0
bmi fpcret
move.l (a1),ext_lba(a0) ; save new extension block lba
pea.l ent_ext(a0)
move.l (a7)+,lba_ptr(a0) ; save reset lba pointer
fpcret move.l (a7)+,a1
movea.l (a7)+,a0
rts
* ------File-Close ( handle -- )
* ------Returns -3 if write error
fclose move.l a0,-(a7)
movea.l 8(a7),a0 ; get handle
tst.l mode(a0)
beq fclrd ; read mode close
move.l ent_lba(a0),-(a7)
jsr slba
move.b #1,hd1+5
move.l #tbuf,-(a7)
jsr fhdbuf ; get header from disk (to preserve links)
adda.l #8,a7
tst.l d0
bmi fcret
move.l tbuf+prv_ent,prv_ent(a0) ; update links before write-back
move.l tbuf+nxt_ent,nxt_ent(a0) ; update links before write-back
move.l ent_lba(a0),-(a7)
jsr slba
move.b #1,hd1+5
move.l a0,-(a7)
jsr shdbuf ; save header
tst.l d0
bmi fcret
move.l ext_lba(a0),-(a7)
jsr slba
move.b #1,hd1+5
pea.l ent_ext(a0)
jsr shdbuf ; save extension block
move.l dat_lba(a0),-(a7)
jsr slba
move.b #1,hd1+5
pea.l dat_buf(a0)
jsr shdbuf ; save data buffer
adda.l #24,a7
clr.b (a0) ; zap first character of name in buffer
bsr fflush ; clean up allocations
fcret movea.l (a7)+,a0
rts
fclrd clr.b (a0) ; zap first character of name in buffer
movea.l (a7)+,a0
clr.l d0
rts
* ------File-Open-Read ( caddr u -- handle/err)
* ------Returns either handle/-1/-2
fopenrd move.l a5,-(a7)
move.l a4,-(a7)
movea.l 12(a7),a5 ; get name pointer
bsr ghandle
bmi fordret
movea.l d0,a4
move.l 16(a7),-(a7) ; get name length and push it
move.l a5,-(a7) ; push addr
bsr fndfile ; get lba of header
adda.l #8,a7
tst.l d0
bmi fordret
move.l d0,ent_lba(a4)
move.l d0,-(a7) ; set header lba
jsr slba
move.b #1,hd1+5
pea.l (a4) ; read it in
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi fordret
pea.l ent_ext(a4)
move.l (a7)+,lba_ptr(a4) ; load lba ptr with start of ext block
move.l linkf(a4),-(a7) ; get first extension block lba
move.l (a7),ext_lba(a4)
jsr slba
move.b #1,hd1+5
pea.l ent_ext(a4) ; read it in
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi fordret
add.l #4,lba_ptr(a4) ; move past block already read
pea.l dat_buf(a4)
move.l (a7)+,dat_ptr(a4) ; load data ptr with start of buffer
move.l ent_ext(a4),-(a7) ; get first data block lba
move.l (a7),dat_lba(a4)
jsr slba
move.b #1,hd1+5
pea.l dat_buf(a4) ; read it in
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi fordret
clr.l mode(a4) ; we're now in read mode
move.l a4,d0 ; return handle
fordret movea.l (a7)+,a4
movea.l (a7)+,a5
rts
* ------File-Get-Character ( handle -- c/-1/-2 )
* ------Returns either c, or -1 if eof, -2 if read error
fgetc move.l a0,-(a7)
move.l a1,-(a7)
movea.l 12(a7),a0 ; get handle
tst.l size(a0) ; read everything?
beq fgdone
movea.l dat_ptr(a0),a1 ; get data pointer
move.b (a1)+,tmp1 ; get character
subq.l #1,size(a0) ; otherwise sub one from current size
move.l a0,d0
add.l #dat_buf+512,d0
cmp.l a1,d0 ; at end of buffer?
beq nxtbuf
move.l a1,dat_ptr(a0) ; save pointer
bra fgret
nxtbuf movea.l lba_ptr(a0),a1 ; get lba pointer
move.l (a1)+,-(a7)
move.l (a7),dat_lba(a0) ; new lba for data buf
jsr slba
move.b #1,hd1+5
pea.l dat_buf(a0) ; read next buffer in
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi fgrete
pea.l dat_buf(a0)
move.l (a7)+,dat_ptr(a0) ; reset data pointer
move.l a0,d0
add.l #ent_ext+508,d0
cmp.l a1,d0 ; end of extension buffer?
beq rnxtext
move.l a1,lba_ptr(a0) ; update lba pointer
clr.l d0
bra fgret
rnxtext move.l ent_ext+linkf(a0),-(a7)
move.l (a7),ext_lba(a0) ; new lba in for extension buffer
jsr slba
pea.l ent_ext(a0) ; read next extension block in
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi fgrete
pea.l ent_ext(a0)
move.l (a7)+,lba_ptr(a0) ; update lba pointer
clr.l d0
bra fgret
fgdone move.l #-1,d0
movea.l (a7)+,a1
movea.l (a7)+,a0
rts
fgret clr.l d0
move.b tmp1,d0
fgrete movea.l (a7)+,a1
movea.l (a7)+,a0
rts
* ------File-Delete ( caddr u -- 0/err)
* ------Returns either 0/-1/-2/-3
fdel move.l a5,-(a7)
move.l a4,-(a7)
move.l d1,-(a7)
movea.l 16(a7),a5 ; get name pointer
movea.l #tbuf,a4
move.l 20(a7),-(a7) ; get name length and push it
move.l a5,-(a7) ; push addr
bsr fndfile ; get lba of header
adda.l #8,a7
tst.l d0
bmi fdelret
move.l d0,d1 ; save d0 (lba of header)
move.l d0,-(a7) ; set lba
jsr slba
move.b #1,hd1+5
pea.l (a4) ; read it in
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi fdelret
tst.l tbuf+type ; is it a file we're trying to delete?
beq notfile ; if not, abort!
move.l d1,-(a7)
bsr freesec ; free header block
adda.l #4,a7
tst.l d0
bmi fdelret
move.l tbuf+size,d1 ; get size of file
lsr.l #8,d1 ; divide by 512
lsr.l #1,d1 ; ""
addq.l #1,d1 ; add one so even 0-sized files get deleted
move.l tbuf+nxt_ent,tmp2 ; get next entry lba
move.l tbuf+linkf,tmp1 ; get extension block lba
move.l tbuf+prv_ent,-(a7) ; read in previous file header
move.l (a7),tmp3 ; save it
jsr slba
move.b #1,hd1+5
move.l #tbuf,-(a7) ; read it in
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi fdelret
move.l tmp3,d0 ; get lba of previous entry (currently loaded)
cmp.l cur_dir,d0 ; is it the current dir?
beq usefstf ; if so, write to fst_fil, instead of prv_ent
move.l tmp2,tbuf+nxt_ent ; point next entry to file past delete file
; This is zero if there is no file after it
ufstfrt move.b #1,hd1+5
move.l #tbuf,-(a7) ; write it back
jsr shdbuf
adda.l #4,a7
tst.l d0
bmi fdelret
tst.l tmp2 ; see if next file exists
beq rdext ; skip it if it doesn't
move.l tmp2,-(a7) ; read in next file header
jsr slba
move.b #1,hd1+5
move.l #tbuf,-(a7) ; read it in
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi fdelret
move.l tmp3,tbuf+prv_ent ; point previous entry to file before
deleted file
move.b #1,hd1+5
move.l #tbuf,-(a7) ; write it back
jsr shdbuf
adda.l #4,a7
tst.l d0
bmi fdelret
rdext move.l tmp1,-(a7) ; read in extension block of file to delete
jsr slba
move.b #1,hd1+5
move.l #tbuf,-(a7) ; read it in
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi fdelret
movea.l #tbuf,a5 ; point to start of loaded ext block
dellp tst.l d1 ; size=0 yet?
beq fdelok ; if so, we're done
move.l (a5)+,-(a7)
bsr freesec ; free up allocated sector
adda.l #4,a7
tst.l d0
bmi fdelret ; abort if it fails
subq.l #1,d1 ; sub one from adjusted size
cmpa.l #tbuf+508,a5
bne dellp
nxtdlsc move.l tmp1,-(a7)
bsr freesec ; free up ext block just read
adda.l #4,a7
tst.l d0
bmi fdelret
move.l tbuf+508,tmp1
bra rdext
notfile move.l #-4,d0 ; fubar code
bra fdelret
fdelok move.l tmp1,-(a7)
bsr freesec ; free up ext block just read
adda.l #4,a7
tst.l d0
bmi fdelret
bsr fsflush
clr.l d0
fdelret move.l (a7)+,d1
movea.l (a7)+,a4
movea.l (a7)+,a5
rts
usefstf move.l tmp2,tbuf+fst_fil ; write to first_file location in dir entry
bra ufstfrt
* ------File-Copy ( caddr1 u1 caddr2 u2 -- 0/err)
* ------Returns either 0/-1/-2/-3
fcpy move.l a5,-(a7)
move.l a4,-(a7)
move.l d1,-(a7)
move.l d2,-(a7)
movea.l 20(a7),a5 ; get name pointer
movea.l #cpbuf,a4
move.l 24(a7),-(a7) ; get name length and push it
move.l a5,-(a7) ; push addr
bsr fndfile ; get lba of header
adda.l #8,a7
tst.l d0
bmi fcpyret
move.l d0,-(a7)
jsr slba
move.b #1,hd1+5
move.l #cpbuf,-(a7) ; read in source header
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi fcpyret
move.l cpbuf+size,d0 ; get size
move.l d0,d1
lsr.l #8,d1 ; divide by 512 so size is in sectors
lsr.l #1,d1 ; ""
andi.l #511,d0
tst.l d0 ; make sure it divides/512 evenly
beq skadju ; skip adding one to size
addq.l #1,d1 ; adjust sector size up by one
skadju move.l cpbuf+linkf,-(a7) ; get link field of source
jsr slba
move.b #1,hd1+5
move.l #tbuf2,-(a7) ; read in source ext block
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi fcpyret
movea.l 28(a7),a5 ; get pointer to dest name
move.l 32(a7),d0 ; get length
movea.l #cpbuf,a4
jsr Strcpyn ; copy string to dest header
bsr fmpaloc ; allocate space for dest header
bmi fcpyret
move.l d0,d2 ; save dest header lba
bsr fmpaloc ; allocate space for dest ext block
bmi fcpyret
move.l d0,cpsec ; save dest ext lba
move.l d0,cpbuf+linkf ; write to dest linkfield
clr.l cpbuf+nxt_ent ; no next file
bsr lstlink ; find last file in chain
bmi fcpyret
move.l d0,cpbuf+prv_ent ; save to prev ent field
move.l d2,-(a7) ; set for dest header lba
jsr slba
move.l #cpbuf,-(a7)
move.b #1,hd1+5
jsr shdbuf ; save dest header
adda.l #8,a7
tst.l d0
bmi fcpyret
bsr lstlink ; get last file in dir
bmi fcpyret
move.l d0,-(a7)
jsr slba
move.l #tbuf3,-(a7)
move.b #1,hd1+5
jsr fhdbuf ; read in file
adda.l #8,a7
tst.l d0
bmi fcpyret
move.l d2,tbuf3+nxt_ent ; put dest file's header lba in nxt_ent
move.l #tbuf3,-(a7)
move.b #1,hd1+5
jsr shdbuf ; write it back
adda.l #4,a7
tst.l d0
bmi fcpyret
movea.l #tbuf2,a5 ; point to start of source ext blk
movea.l #tbuf,a4 ; point to start of dest ext blk
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
fcpylp move.l (a5)+,-(a7) ; source lba
jsr slba
move.l #tbuf3,-(a7) ; data buf
move.b #1,hd1+5
jsr fhdbuf ; get source data block
adda.l #8,a7
tst.l d0
bmi fcpyret
bsr fmpaloc ; allocate space for dest data block
bmi fcpyret
move.l d0,(a4)+ ; save dest data block lba
move.l d0,-(a7) ; dest lba
jsr slba
move.l #tbuf3,-(a7) ; data buf
move.b #1,hd1+5
jsr shdbuf ; save dest data block
adda.l #8,a7
tst.l d0
bmi fcpyret
subq.l #1,d1 ; we've written one more block...
beq fcpdone ; if 0, we're done!
bmi fcpdone ; if -1 (because file size was zero) we're done
cmpa.l #tbuf2+508,a5 ; at end of source ext block?
bne fcpylp
fcpnxex bsr fmpaloc ; get a new sector to link ext block to
bmi fcpyret
move.l d0,tbuf+linkf ; save it
move.l cpsec,-(a7)
move.l d0,cpsec
jsr slba
move.l #tbuf,-(a7) ; dest ext lba buf
move.b #1,hd1+5
jsr shdbuf ; save it
adda.l #8,a7
tst.l d0
bmi fcpyret
move.l (a5)+,-(a7) ; source ext block linkfield lba
jsr slba
move.l #tbuf2,-(a7) ; source ext buf
move.b #1,hd1+5
jsr fhdbuf ; get source ext block
adda.l #8,a7
tst.l d0
bmi fcpyret
movea.l #tbuf2,a5 ; reset pointers
movea.l #tbuf,a4
bra fcpylp
fcpdone move.l cpsec,-(a7)
jsr slba
move.l #tbuf,-(a7) ; dest ext lba buf
move.b #1,hd1+5
jsr shdbuf ; save it
adda.l #8,a7
tst.l d0
bmi fcpyret
clr.l d0
bsr fflush
fcpyret move.l (a7)+,d2
move.l (a7)+,d1
movea.l (a7)+,a4
movea.l (a7)+,a5
rts
* ------Make-Dir
* ------Returns 0 ok, -2/-3/-4 (no space/read error/bad file name)
mkdir move.l a5,-(a7)
move.l a4,-(a7)
movea.l 12(a7),a5 ; get name pointer
move.l 16(a7),tmp1 ; get name length
movea.l #cpbuf,a4 ; point a4 to buffer
move.l tmp1,d0 ; restore length
jsr Strcpyn ; copy name into buffer
bsr fmpaloc ; get some space for header
bmi mkdret
move.l d0,-(a7) ; save lba
bsr lstlink ; lstlink uses tbuf (actually nxtlink does)
bmi mkdret
move.l d0,prv_ent(a4) ; previous entry (dir LBA if none)
cmp.l cur_dir,d0 ; are we writing to the current dir entry?
beq wrtff ; if so, write to fst_fil
move.l (a7),tbuf+nxt_ent ; save lba to nxt_ent of last file
wrtffrt move.b #1,hd1+5 ; set count 1 sector
move.l #tbuf,-(a7)
jsr shdbuf ; save last file's header
adda.l #4,a7 ; note dir's lba still on stack...
tst.l d0
bmi mkdret
clr.l nxt_ent(a4) ; no next entry
clr.l fst_fil(a4) ; no files
move.l cur_dir,prv_dir(a4) ; current dir is previous to it
clr.l size(a4) ; 0 size
clr.l date(a4) ; no date
move.l #-1,fflags(a4) ; wide open permissions
clr.l chksum(a4) ; none
move.l #0,type(a4) ; dir type
jsr slba ; LBA is already on stack...
move.b #1,hd1+5 ; set count 1 sector
move.l #cpbuf,-(a7)
jsr shdbuf ; save it!
adda.l #8,a7
tst.l d0
bmi mkdret
clr.l d0
mkdret movea.l (a7)+,a4
movea.l (a7)+,a5
rts
wrtff move.l (a7),tbuf+fst_fil
bra wrtffrt
* ------Change-Dir
* ------Returns 0 ok, -2 otherwise
chdir move.l 4(a7),tmp1 ; get name pointer
move.l 8(a7),tmp2 ; get name length
move.l tmp2,-(a7)
move.l tmp1,-(a7)
bsr fndfile ; get lba
adda.l #8,a7
bmi cdret ; error...
tst.l tbuf+type ; if type!=0, it's a file!
beq cdok
bra cdret
cdok move.l d0,cur_dir ; otherwise set it
cdret rts
* ------CD-Up
* ------Returns 0 ok, -1 otherwise
cdup cmpi.l #map_spc,cur_dir ; are we already at root?
beq atroot
move.l cur_dir,-(a7)
jsr slba
move.b #1,hd1+5 ; set count 1 sector
move.l #tbuf,-(a7)
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi cdupret
move.l tbuf+prv_dir,cur_dir
clr.l d0
cdupret rts
atroot move.l #-1,d0
rts
* ------Remove-Dir
* ------Dir must be empty (returns -4 if otherwise), -1 if not found
rmdir move.l 4(a7),tmp1 ; get name pointer
move.l 8(a7),tmp2 ; get name length
move.l d1,-(a7)
move.l d2,-(a7)
move.l tmp2,-(a7)
move.l tmp1,-(a7)
bsr fndfile ; get lba and load into tbuf
adda.l #8,a7
tst.l d0
bmi rmdret ; error...
tst.l tbuf+fst_fil
bne filsfnd ; if it has any files, no way!
move.l tbuf+prv_ent,d1 ; save previous chain entry
move.l tbuf+nxt_ent,d2 ; save next chain entry
move.l d0,-(a7)
bsr freesec ; otherwise free sector
adda.l #4,a7
tst.l d0
bmi rmdret
move.l d1,-(a7) ; load previous entry
jsr slba
move.b #1,hd1+5 ; set count 1 sector
move.l #tbuf,-(a7)
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi rmdret
cmp.l cur_dir,d1 ; is the previous entry the dir entry?
beq prvidir
move.l d2,tbuf+nxt_ent ; otherwise write next ent's lba
pidrt move.b #1,hd1+5 ; set count 1 sector
move.l #tbuf,-(a7)
jsr shdbuf ; save it!
adda.l #4,a7
tst.l d0
bmi rmdret
move.l d2,-(a7) ; load in entry after deleted dir
jsr slba
move.b #1,hd1+5 ; set count 1 sector
move.l #tbuf,-(a7)
jsr fhdbuf
adda.l #8,a7
tst.l d0
bmi rmdret
move.l d1,tbuf+prv_ent
move.b #1,hd1+5 ; set count 1 sector
move.l #tbuf,-(a7)
jsr shdbuf ; save it!
adda.l #4,a7
tst.l d0
bmi rmdret
clr.l d0
bra rmdret
filsfnd move.l #-4,d0
rmdret move.l (a7)+,d2
move.l (a7)+,d1
rts
prvidir move.l d2,tbuf+fst_fil ; patch first_file entry
bra pidrt
* ------CD-root
cdroot move.l #map_spc,cur_dir
rts
* -------------------------------------------------------------------------
* ------Init-DOS _MUST_ be called before using any DOS routines to avoid
* ------CERTAIN and COMPLETE DISASTER!!!
initdos move.b #$40,hd1+5 ; set count to 64 sectors/track
move.b #7,hd1+13 ; 8 heads
move.b #$91,hd1+15 ; init values command
clr.l bptr ; 0 find-free/fmapalloc variables
clr.l secptr
clr.l bitptr
clr.b ffchg ; flag used to signify altered ffbuf
clr.b frchg ; flag used to signify altered frebuf
move.l #map_spc,cur_dir ; point to root dir entry
move.l #-1,freptr ; doesn't point to anything
move.l a0,-(a7) ; now clear hdbuf
movea.l #hdbuf,a0
move.l #num_fil,d0
mulu #buf_siz,d0
adda.l d0,a0 ; get addr of 1st byte, last entry+1 in buf
clrbflp move.w #0,-(a0) ; we use word clears instead of lword in case...
cmpa.l #hdbuf,a0 ; the buf size is not evenly divisable by 4
bne clrbflp
movea.l (a7)+,a0
move.l #0,-(a7)
jsr slba ; set LBA to 0
move.b #1,hd1+5 ; set count to 1 sector
move.l #ffbuf,-(a7)
jsr fhdbuf ; load with first sector in alloc map
adda.l #8,a7 ; get rid of prev. stacked values
rts
lba move.l a5,-(a7)
movea.l #lbas,a5
jsr prints
jsr flba
bsr print
movea.l (a7)+,a5
rts
print move.l a5,-(a7)
move.l d0,-(a7)
movea.l #tmps,a5
jsr B2adec
jsr prints
* move.b #13,d0
* jsr putc
jsr crlf
move.l d0,(a7)+
movea.l (a7)+,a5
rts
lbas DC.B 'LBA: ',0
updiv divu d1,d0
swap d0
tst.w d0
bne adj
swap d0
rts
adj clr.w d0
addq.w #01,d0
rts
ltv equ $400
flba EQU ltv+204
slba EQU ltv+208
fhdbuf EQU ltv+196
shdbuf EQU ltv+200
hd1 EQU $0500000
Strcpyn equ 136+ltv
Strcpy EQU $0464
Strncmp EQU $04A8
prints equ 8+ltv
B2adec equ 4+ltv
crlf equ 16+ltv
putc equ 20+ltv
key? equ 104+ltv
* ---------------------- Data Area ------------------------------------
tmp1 DC.L 0
tmp2 DC.L 0
tmp3 DC.L 0
tmp4 DC.L 0
cpsec DC.L 0 ; only for use by copy-file/make-dir!!
bptr DC.L 0 ; These five variables are reserved for use with find-free/
secptr DC.L 0 ; free-sec/fmapalloc ONLY!!!
bitptr DC.L 0 ; ""
ffchg DC.L 0 ; ""
frchg DC.L 0 ; ""
cur_dir DC.L 0
freptr DC.L 0 ; points to current sector in frebuf
*tmps DS.B 80 ; temp string buffer
*ffbuf DS.B 512 ; find-free buffer
*frebuf DS.B 512 ; free-sector buffer
*tbuf DS.B 512 ; temp working buffer for hd
*hdbuf DS.B 12480 ; (1560*num_fil)
tmps EQU freptr+4 ; temp string buffer
ffbuf EQU tmps+80 ; find-free buffer
frebuf EQU ffbuf+512 ; free-sector buffer
tbuf EQU frebuf+512 ; working buffer for hd
tbuf2 EQU tbuf+512 ; second working buffer
tbuf3 EQU tbuf2+512 ; third working buffer
cpbuf EQU tbuf3+512
hdbuf EQU cpbuf+512 ; (1560*num_fil)
END
Follow-Ups: