Improve error handling in fat bs

This commit is contained in:
Nero 2020-03-02 22:15:46 +00:00
parent 59dd979feb
commit 5eedddd0c9
1 changed files with 15 additions and 1 deletions

16
fat.asm
View File

@ -234,12 +234,17 @@ fopen:
fread: push ax
push cx
push dx
; abort if there is no file opened
cmp word [cs:cclus], 0
je .err
; get start sector for data area
call clusec
push ax
; get current cluster number
mov ax, [cs:cclus]
; clusters are 2-indexed
sub ax, 2
; multiply that with sectors per cluster
mov cl, [cs:fdc.sc]
xor ch, ch
mul word cx
@ -251,13 +256,22 @@ fread: push ax
; dx:ax now point to the sector that should be read next
call seek
call read
jc .err
inc word [cs:csec]
jmp .ret
.err: stc
.err: ; in case of error, trash current state
call fclose
stc
.ret: pop dx
pop cx
pop ax
ret
; Reset open file info
fclose: mov [cclus], bx
mov word [csec], 0
ret
main: mov [seek.dl], dl ; save drive number
call fopen