fat: add fread

This commit is contained in:
Nero 2020-03-02 20:45:06 +00:00
parent 9288ad46a4
commit 7143112a5b

53
fat.asm
View File

@ -106,6 +106,7 @@ read: push ax
mov dx, word [cs:seek.dl] mov dx, word [cs:seek.dl]
int 0x13 int 0x13
int 3
pop dx pop dx
pop cx pop cx
@ -196,17 +197,18 @@ scadir:
.name: db "HELLO " .name: db "HELLO "
.ext: db "COM" .ext: db "COM"
open: fopen:
push ax push ax
push cx push cx
push dx push dx
push bx push bx
push ds push ds
push es push es
cmp word [cclus], 0
jne .err
xor ax, ax xor ax, ax
mov ds, ax mov ds, ax
mov es, ax mov es, ax
mov [csec], ax
call dirsec call dirsec
call dirlen call dirlen
.loop: xor dx, dx .loop: xor dx, dx
@ -217,10 +219,11 @@ open:
jnc .found jnc .found
inc ax inc ax
loop .loop loop .loop
stc .err: stc
.found: jmp .ret
mov [cclus], bx .found: mov [cclus], bx
pop es mov word [csec], 0
.ret: pop es
pop ds pop ds
pop bx pop bx
pop dx pop dx
@ -228,11 +231,43 @@ open:
pop ax pop ax
ret ret
fread: push ax
push cx
push dx
cmp word [cs:cclus], 0
je .err
call clusec
push ax
mov ax, [cs:cclus]
sub ax, 2
mov cl, [cs:fdc.sc]
xor ch, ch
mul word cx
; add current cluster offset, cluster start and current sector
pop cx
add cx, [cs:csec]
add ax, cx
adc dx, 0
; dx:ax now point to the sector that should be read next
call seek
call read
jmp .ret
.err: stc
.ret: pop dx
pop cx
pop ax
ret
main: mov [seek.dl], dl ; save drive number main: mov [seek.dl], dl ; save drive number
int 3 call fopen
call open mov bx, 0x1100
int 3 call fread
mov ax, 0x0100
mov ds, ax
mov es, ax
call 0x100:0x100
.hlt: hlt .hlt: hlt
jmp .hlt jmp .hlt