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