fat: add fread
This commit is contained in:
parent
9288ad46a4
commit
7143112a5b
53
fat.asm
53
fat.asm
@ -106,6 +106,7 @@ read: push ax
|
||||
mov dx, word [cs:seek.dl]
|
||||
|
||||
int 0x13
|
||||
int 3
|
||||
|
||||
pop dx
|
||||
pop cx
|
||||
@ -196,17 +197,18 @@ scadir:
|
||||
.name: db "HELLO "
|
||||
.ext: db "COM"
|
||||
|
||||
open:
|
||||
fopen:
|
||||
push ax
|
||||
push cx
|
||||
push dx
|
||||
push bx
|
||||
push ds
|
||||
push es
|
||||
cmp word [cclus], 0
|
||||
jne .err
|
||||
xor ax, ax
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov [csec], ax
|
||||
call dirsec
|
||||
call dirlen
|
||||
.loop: xor dx, dx
|
||||
@ -217,10 +219,11 @@ open:
|
||||
jnc .found
|
||||
inc ax
|
||||
loop .loop
|
||||
stc
|
||||
.found:
|
||||
mov [cclus], bx
|
||||
pop es
|
||||
.err: stc
|
||||
jmp .ret
|
||||
.found: mov [cclus], bx
|
||||
mov word [csec], 0
|
||||
.ret: pop es
|
||||
pop ds
|
||||
pop bx
|
||||
pop dx
|
||||
@ -228,11 +231,43 @@ open:
|
||||
pop ax
|
||||
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
|
||||
|
||||
int 3
|
||||
call open
|
||||
int 3
|
||||
call fopen
|
||||
mov bx, 0x1100
|
||||
call fread
|
||||
|
||||
mov ax, 0x0100
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
call 0x100:0x100
|
||||
|
||||
.hlt: hlt
|
||||
jmp .hlt
|
||||
|
Loading…
Reference in New Issue
Block a user