Put rootdir and cluster access into separate files

This commit is contained in:
Nero 2021-03-19 19:01:38 +00:00
parent fbab632616
commit 5e3ae0aa08
5 changed files with 128 additions and 115 deletions

View File

@ -10,6 +10,8 @@ banner: db "RDOS KERNEL ", V, 0x0A, 0x0D, '$', 0x1A
%include "inc/bpb.asm"
%include "kernel/drive.asm"
%include "kernel/fcb.asm"
%include "kernel/rootdir.asm"
%include "kernel/cluster.asm"
section .text
@ -23,7 +25,12 @@ init: call rstseg
mov dx, testdta
call setdta
mov dx, testfcb
call fndfst
call open
int 3
call read
int 3

7
kernel/cluster.asm Normal file
View File

@ -0,0 +1,7 @@
; read/write data from FAT clusters
; requires defines from fcb.asm
read mov bp, sp
call fcbdrv
ret

View File

@ -199,12 +199,12 @@ maprel add ax, [bpb+BPBHS]
; skip doing a read if sector number matches
; IN dx:ax sector number
mapabs cmp ax, [dskseek]
jne read
jne dskread
cmp dx, [dskseek+2]
jne read
jne dskread
ret
read push ax
dskread push ax
push dx
call flush
pop dx

View File

@ -55,114 +55,3 @@ setdta mov [cs:dta], dx
; OUT ES:BX dta ptr
getdta les bx, [cs:dta]
ret
; Load root directory entry
; 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, [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, [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
mov ax, cs
mov ds, ax
mov si, bx
mov cx, 11
rep movsb
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+26]
mov [ds:bx+FCBCLUS], ax
; reset record number
mov byte [ds:bx+FCBRN], 0
.ret ret

110
kernel/rootdir.asm Normal file
View File

@ -0,0 +1,110 @@
; 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, [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, [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
mov ax, cs
mov ds, ax
mov si, bx
mov cx, 11
rep movsb
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+26]
mov [ds:bx+FCBCLUS], ax
; reset record number
mov byte [ds:bx+FCBRN], 0
.ret ret