Implement searching directory for exact matches

This commit is contained in:
Nero 2021-01-02 02:07:40 +00:00
parent 7754312609
commit 9a1c4139a6
5 changed files with 82 additions and 85 deletions

View File

@ -31,24 +31,21 @@ init: cli
call logdrv
xor ax, ax
xor dx, dx
call maprd
inc word [dskbuf+0x82]
push word [dskbuf+0x82]
call dirty
call flush
call printf
db "Current run: ",2,0x0A,0x0D,0
mov bx, testfcb
call fndfst
jc huh
call putfn
hlt: hlt
jmp hlt
huh: call printf
db "huh", 0
jmp hlt
%include "kernel/far.asm"
%include "kernel/fcb.asm"
%include "kernel/find.asm"
%include "kernel/drive.asm"
%include "kernel/printf.asm"

View File

@ -1,10 +1,2 @@
struc fcb
.drive resb 1
.filename resb 8
.type resb 3
.fn2 resb 8
.tp2 resb 3
.dirpos resw 1
.cluster resw 1
.recordnum resb 1
endstruc
FCBDEN: equ 23 ; directory entry
FCBSIZ: equ 30

View File

@ -51,21 +51,21 @@ dinit: ; copy previously set DPT to our data area
; int 13 stub
; place reserved for stack switches
int13: ; debug output
push bx
push dx
push cx
push ax
call printf
db "int13 CALL AX=",2," CX=",2," DX=",2," BX=",2,0x0A,0x0D,0
;push bx
;push dx
;push cx
;push ax
;call printf
;db "int13 CALL AX=",2," CX=",2," DX=",2," BX=",2,0x0A,0x0D,0
; do the call
int 0x13
jc .err
ret
.err: push ax
call printf
db "int13 ERR AX=",2,0x0A,0x0D,0
stc
;jc .err
ret
.err: ;push ax
;call printf
;db "DISK ERR AX=",2,0x0A,0x0D,0
;stc
;ret
; get drive parameters
; read BIOS int13h/AH=8 values

View File

@ -9,61 +9,12 @@ section .text
; Helper function: read the drive number from FCB,
; apply default if necessary,
; and make it current I/O drive
setdrv: mov dl, [es:bx+fcb.drive] ; A=1
setdrv: mov dl, [es:bx] ; A=1
test dl, dl
jnz .nofix
mov dl, [defdrv] ; A=0
inc dl
mov [es:bx+fcb.drive], dl ; A=1
mov [es:bx], dl ; A=1
; now set as current i/o drive
.nofix: dec dl ; A=0 for dsksel
jmp logdrv
; FCB open
fcbopn: ; call fcbfst
; copy match
; store cluster number in fcb
; record = 0
ret
; FCB close
fcbcls: ; flush disk buffer
ret
; FCB find first
fcbfst: mov word [es:bx+fcb.dirpos], 0
; FCB find next
fcbnxt: call setdrv
; load rootdir sector from state
; search until next match
; next sec & loop if mismatch
; err exit if no further matches
ret
; FCB delete file
fcbdel: ; call fcbfst
; get search state, load root dir from there
; mark file as deleted
; mark buffer dirty
ret
; FCB read
; read sector from cluster into diskbuf
fcbrd: ; read record from sector
; advance record num, carry over to cluster
ret
; FCB write
fcbwr: ; read sector from cluster into diskbuf
; write record into sector
; mark buffer dirty
; advance record num, carry over to cluster
ret
; FCB create
fcbcre:
ret
; FCB rename
fcbren:
ret

57
kernel/find.asm Normal file
View File

@ -0,0 +1,57 @@
; Load root directory entry
; IN ax number of directory entry
lddir: push ax
mov cl, 4
shr ax, cl
xor dx, dx
call maprd
; get si to point to entry
pop si
mov cl, 5
shl si, cl
and si, 0x1FF
add si, dskbuf
ret
; find next file
fnfile: mov ax, [es:bx+FCBDEN]
inc word [es:bx+FCBDEN]
; bail out if we are at end of dir
cmp ax, [bpb+BPBRDE]
jnc .err
; load entry and first byte
push bx
call lddir
pop bx
; next if hidden, dir or vol label
test byte [si+0x0B], 0xDA
jnz fnfile
; bail out if end of dir
mov al, [si]
cmp al, 0
je .err
; next if deleted entry
cmp al, 0xE5
je fnfile
clc
ret
.err: stc
ret
; initialize a FCB for directory scanning
fndfst: mov word [es:bx+FCBDEN], 0
fndnxt: call fnfile
jc .ret
push si
lea di, [bx+1]
mov cx, 11
rep cmpsb
pop si
jne fndnxt
.ret: ret
putfn: mov cx, 11
.loop: lodsb
call pputc
loop .loop
ret