Implement file search in directory

This commit is contained in:
Nero 2021-01-23 17:32:53 +00:00
parent 4530866130
commit ebd356ed8e
3 changed files with 100 additions and 43 deletions

View file

@ -34,6 +34,7 @@ section .text
; initial setup for disk i/o
dinit: ; copy previously set DPT to our data area
push ds
push cs
pop es
lds si, [es:4*0x1E]
@ -45,6 +46,7 @@ dinit: ; copy previously set DPT to our data area
mov word [cs:4*0x1E+2], ds
; set to invalid drive
mov byte [cs:dsknum], 0xFF
pop ds
ret
; int 13 stub

View file

@ -9,36 +9,87 @@ FCBSIZ: equ 30
section .text
; auto-complete drive field in fcb
; IN es:bx far ptr FCB
; OUT si copy of bx
fixfcb: cmp byte [es:bx], 0
jne .ret
call getdd
inc dl
mov byte [es:bx], dl
.ret: ret
; auto-complete drive field in fcb
; also returns the drive number
; IN es:bx far ptr FCB
; OUT dl dl (0=A:, 1=B:, 2=C:, ...)
fcbdrv: mov dl, [es:bx]
test dl, dl
jnz .ret
call getdd
mov dl, al
inc dl
mov [es:bx], dl
.ret: dec dl
ret
; Load root directory entry
; IN ax number of directory entry
; OUT cs:si ptr to 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 first matching file
; IN ES:BX input fcb
fndfst:
; Load root directory entry
; IN ax number of directory entry
; OUT cs:si ptr to 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 first matching file
; IN ES:BX input fcb
fndfst: ; get and log in drive
call fcbdrv
call logdrv
; set search state to zero
push es
push bx
call getdta
xor ax, ax
mov [es:bx+0x20+1], ax
pop bx
pop es
; find next matching file
; state is kept in DTA
fndnxt: ; get net direntry to fetch
; get number of current entry from DTA
push es
push bx
call getdta
mov ax, [es:bx+0x20+1]
inc word [es:bx+0x20+1]
pop bx
pop es
; 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 fndnxt
; bail out if end of dir
mov al, [si]
cmp al, 0
je .err
; next if deleted entry
cmp al, 0xE5
je fndnxt
; compate DS:SI with ES:BX+1
lea di, [bx+1]
mov cx, 11
rep cmpsb
; try next if mismatch
jne fndnxt
clc
ret
.err: stc
ret
open:
ret
ret