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

@ -35,13 +35,9 @@ relinit: ; print banner
push word [version+2]
call printf
db "RDOS ",2,2, 0x0A, 0x0D, 0
push dx
push ds
; initialize the disk i/o
call dinit
pop ds
pop dx
; init 21h vector
mov word [0x21*4], int21
mov word [0x21*4+2], cs
; set current PSP, directly after us
@ -49,15 +45,19 @@ relinit: ; print banner
mov cl, 4
shr ax, cl
mov word [curpsp], ax
; also the DTA
mov bx, dta
call setdta
; set current drive to boot drive
mov al, dl
rol al, 1
rol al, 1
or dl, al
and dl, 3
call setdd
cmp dl, 0x80
jc .k
sub dl, (0x80-2)
.k: call setdd
mov dx, testfcb
mov ah, 0xF
int 0x21
mov bx, testfcb
call fndfst
restart:
hlt: hlt
@ -70,6 +70,10 @@ hlt: hlt
%include "kernel/drive.asm"
%include "kernel/printf.asm"
section .bss
dta: resb 128
section .data
testfcb: db 0

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

@ -10,14 +10,18 @@ FCBSIZ: equ 30
section .text
; auto-complete drive field in fcb
; also returns the drive number
; IN es:bx far ptr FCB
; OUT si copy of bx
fixfcb: cmp byte [es:bx], 0
jne .ret
; 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 byte [es:bx], dl
.ret: ret
mov [es:bx], dl
.ret: dec dl
ret
; Load root directory entry
; IN ax number of directory entry
@ -37,8 +41,55 @@ lddir: push ax
; find first matching file
; IN ES:BX input fcb
fndfst:
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