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

View File

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

View File

@ -9,36 +9,87 @@ FCBSIZ: equ 30
section .text section .text
; auto-complete drive field in fcb ; auto-complete drive field in fcb
; IN es:bx far ptr FCB ; also returns the drive number
; OUT si copy of bx ; IN es:bx far ptr FCB
fixfcb: cmp byte [es:bx], 0 ; OUT dl dl (0=A:, 1=B:, 2=C:, ...)
jne .ret fcbdrv: mov dl, [es:bx]
call getdd test dl, dl
inc dl jnz .ret
mov byte [es:bx], dl call getdd
.ret: ret mov dl, al
inc dl
mov [es:bx], dl
.ret: dec dl
ret
; Load root directory entry ; Load root directory entry
; IN ax number of directory entry ; IN ax number of directory entry
; OUT cs:si ptr to directory entry ; OUT cs:si ptr to directory entry
lddir: push ax lddir: push ax
mov cl, 4 mov cl, 4
shr ax, cl shr ax, cl
xor dx, dx xor dx, dx
call maprd call maprd
; get si to point to entry ; get si to point to entry
pop si pop si
mov cl, 5 mov cl, 5
shl si, cl shl si, cl
and si, 0x1FF and si, 0x1FF
add si, dskbuf add si, dskbuf
ret ret
; find first matching file
; IN ES:BX input fcb
fndfst:
; 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: open:
ret ret