Reorder code and remove unused farptr components

This commit is contained in:
Nero 2021-01-04 23:19:14 +00:00
parent 0256d6ab36
commit 7e2e91b2b7
4 changed files with 62 additions and 111 deletions

View File

@ -45,12 +45,10 @@ hlt: hlt
jmp hlt jmp hlt
%include "kernel/syscall.asm" %include "kernel/syscall.asm"
%include "kernel/far.asm" %include "kernel/char.asm"
%include "kernel/fcb.asm" %include "kernel/fcb.asm"
%include "kernel/find.asm"
%include "kernel/drive.asm" %include "kernel/drive.asm"
%include "kernel/printf.asm" %include "kernel/printf.asm"
%include "kernel/char.asm"
section .data section .data

View File

@ -1,47 +0,0 @@
; Utilities to help with far pointers
; exchange DS:SI with ES:DI
xchgs: push ds
push es
pop ds
pop es
xchg si, di
ret
; far pointer load
; IN ES:BX far pointer to data
; CX number of bytes to copy
; 0:DX destination buffer
lod: push es
; ES:DI := DS:DX
mov ax, ds
mov es, ax
mov di, dx
; DS:SI := 0:BX
xor ax, ax
mov ds, ax
mov si, bx
; copy
pushf
cld
rep movsb
popf
; reset DS to kernel data
mov ds, cx
pop es
ret
; far pointer store
; IN ES:BX far ptr
; CX number of bytes
; 0:DX source buffer
; only CX is trashed
sto: mov si, dx
mov di, bx
cld
rep movsb
ret

View File

@ -4,12 +4,11 @@ section .bss
defdrv: resb 1 defdrv: resb 1
section .text section .text
; Functions here generally expect the FCB to be at ES:BX
; Helper function: read the drive number from FCB, ; Helper function: read the drive number from FCB,
; apply default if necessary, ; apply default if necessary,
; and make it current I/O drive ; and make it current I/O drive
setdrv: mov dl, [es:bx] ; A=1 _setdrv: mov dl, [es:bx] ; A=1
test dl, dl test dl, dl
jnz .nofix jnz .nofix
mov dl, [defdrv] ; A=0 mov dl, [defdrv] ; A=0
@ -18,3 +17,63 @@ setdrv: mov dl, [es:bx] ; A=1
; now set as current i/o drive ; now set as current i/o drive
.nofix: dec dl ; A=0 for dsksel .nofix: dec dl ; A=0 for dsksel
jmp logdrv jmp logdrv
; 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
open: mov word [es:bx+FCBDEN], 0
.search: call fnfile
mov al, 0xFF
jc .ret
push si
lea di, [bx+1]
mov cx, 11
rep cmpsb
pop si
jne .search
mov al, 0
.ret: ret
putfn: mov cx, 11
.loop: lodsb
call pputc
loop .loop
ret

View File

@ -1,59 +0,0 @@
; 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
open: mov word [es:bx+FCBDEN], 0
.search: call fnfile
mov al, 0xFF
jc .ret
push si
lea di, [bx+1]
mov cx, 11
rep cmpsb
pop si
jne .search
mov al, 0
.ret: ret
putfn: mov cx, 11
.loop: lodsb
call pputc
loop .loop
ret