rdos/kernel/rootdir.asm

114 lines
1.8 KiB
NASM

; Load root directory entry into buffer
; IN ax number of directory entry
; OUT cs:di ptr to directory entry
lddir push ax
push ax
call rstseg
pop ax
mov cl, 4
shr ax, cl
xor dx, dx
; dx:ax = sector number in rootdir
; add sizes of FAT tables
xor ch, ch
mov cl, byte [bpb+BPBFN]
.loop: add ax, [bpb+BPBFS]
adc dx, 0
loop .loop
; add reserved sector count
add ax, [bpb+BPBRSC]
adc dx, 0
; fetch sector (relative to partition)
call maprel
; get di to point to entry
pop di
mov cl, 5
shl di, cl
and di, 0x1FF
add di, dskbuf
ret
; find first matching file
; IN DS:DX input fcb
fndfst mov bp, sp
call fcbdrv
; set search state to zero
les di, [cs:dta]
xor ax, ax
mov [es:di+FCBSIZ], ax
; find next matching file
; state is kept in DTA
fndnxt mov bp, sp
call fcbdrv
; get next direntry to fetch
; get number of current entry from DTA
.loop les di, [cs:dta]
mov ax, [es:di+FCBSIZ]
inc word [es:di+FCBSIZ]
; bail out if we are at end of dir
cmp ax, [cs:bpb+BPBRDE]
jnc .err
; load entry and first byte
push ds
push dx
call lddir
pop dx
pop ds
; next if hidden, dir or vol label
test byte [cs:di+0x0B], 0xDA
jnz .loop
; bail out if end of dir
mov al, [cs:di]
cmp al, 0
je .err
; next if deleted entry
cmp al, 0xE5
je .loop
; DS:SI := FCB+1
; ES:DI := CS:dirent
mov si, dx
push si
inc si
mov ax, cs
mov es, ax
; compare and ; try next if mismatch
mov cx, 11
push di
rep cmpsb
pop di
pop si
jne .loop
; create FCB in DTA
call getdta
xchg bx, di
; copy over drive byte
movsb
; copy filename
push ds
push si
mov ax, cs
mov ds, ax
mov si, bx
mov cx, 11
rep movsb
pop si
pop ds
; done!
xor ax, ax
ret
.err: stc
.ret: sbb al, al
ret
open call fndfst
test al, al
jnz .ret
; read start cluster
mov ax, [cs:bx+0x1A]
mov bx, dx
mov [ds:bx+FCBCLUS], ax
; reset record number
mov byte [ds:bx+FCBRN], 0
.ret ret