fat.bs: Implement correctly for FAT12
This commit is contained in:
parent
34ef468aa9
commit
035b69db10
69
boot/fat.asm
69
boot/fat.asm
@ -55,8 +55,14 @@ readr: ; add offset to rootdir to DX:AX (FAT12/FAT16 only)
|
|||||||
push cx
|
push cx
|
||||||
xor ch, ch
|
xor ch, ch
|
||||||
mov cl, byte [bp+bpb_fn]
|
mov cl, byte [bp+bpb_fn]
|
||||||
fatlp: add ax, [bp+bpb7_lsf]
|
fatlp:
|
||||||
|
%ifdef FAT32
|
||||||
|
add ax, [bp+bpb7_lsf]
|
||||||
adc dx, [bp+bpb7_lsf+2]
|
adc dx, [bp+bpb7_lsf+2]
|
||||||
|
%else
|
||||||
|
add ax, [bp+bpb_sf]
|
||||||
|
adc dx, 0
|
||||||
|
%endif
|
||||||
loop fatlp
|
loop fatlp
|
||||||
pop cx
|
pop cx
|
||||||
readf: ; add offset to FAT table to DX:AX
|
readf: ; add offset to FAT table to DX:AX
|
||||||
@ -168,30 +174,49 @@ shftl: clc
|
|||||||
|
|
||||||
pop bx
|
pop bx
|
||||||
|
|
||||||
; get lower part of cluster number
|
; get address of cluster within sector
|
||||||
pop si
|
pop si
|
||||||
|
%ifdef FAT12
|
||||||
|
push si
|
||||||
|
; times 1.5
|
||||||
|
mov ax, si
|
||||||
|
shr ax, 1
|
||||||
|
add si, ax
|
||||||
|
add si, buf
|
||||||
|
lodsw
|
||||||
|
pop si
|
||||||
|
test si, 1
|
||||||
|
jz .odd
|
||||||
|
.even: mov cl, 4
|
||||||
|
shr ax, cl
|
||||||
|
jmp .done
|
||||||
|
.odd: and ax, 0x0FFF
|
||||||
|
.done: xor dx, dx
|
||||||
|
%endif
|
||||||
|
|
||||||
%ifdef FAT16
|
%ifdef FAT16
|
||||||
; double
|
; double
|
||||||
sal si, 1
|
sal si, 1
|
||||||
|
; make sure its within sector range
|
||||||
|
and si, 0x1FF
|
||||||
|
add si, buf
|
||||||
|
; load word
|
||||||
|
lodsw
|
||||||
|
xor dx, dx
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
%ifdef FAT32
|
%ifdef FAT32
|
||||||
; multiply with 4
|
; multiply with 4
|
||||||
sal si, 1
|
sal si, 1
|
||||||
sal si, 1
|
sal si, 1
|
||||||
%endif
|
|
||||||
; make sure its within sector range
|
; make sure its within sector range
|
||||||
and si, 0x1FF
|
and si, 0x1FF
|
||||||
add si, buf
|
add si, buf
|
||||||
%ifdef FAT16
|
; load dword
|
||||||
; load word from FAT
|
|
||||||
lodsw
|
|
||||||
xor dx, dx
|
|
||||||
%endif
|
|
||||||
%ifdef FAT32
|
|
||||||
; load dword from FAT
|
|
||||||
lodsw
|
lodsw
|
||||||
mov dx, [si]
|
mov dx, [si]
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; reads current cluster into [dest]
|
; reads current cluster into [dest]
|
||||||
@ -230,9 +255,21 @@ l02e:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
; Load root directory
|
; Load root directory
|
||||||
loadr: mov ax, 2
|
loadr:
|
||||||
|
%ifdef FAT32
|
||||||
|
mov ax, 2
|
||||||
xor dx, dx
|
xor dx, dx
|
||||||
jmp load
|
jmp load
|
||||||
|
%else
|
||||||
|
mov ax, [bp+bpb_rde]
|
||||||
|
mov cl, 4
|
||||||
|
shr ax, cl
|
||||||
|
mov cx, ax
|
||||||
|
xor ax, ax
|
||||||
|
xor dx, dx
|
||||||
|
mov bx, 0x07C0
|
||||||
|
jmp readr
|
||||||
|
%endif
|
||||||
|
|
||||||
; Load file identified by fsattr
|
; Load file identified by fsattr
|
||||||
; Directory data is expected at 0x07C00
|
; Directory data is expected at 0x07C00
|
||||||
@ -259,8 +296,16 @@ sloop: add si, 0x20
|
|||||||
load: mov bx, 0x07C0
|
load: mov bx, 0x07C0
|
||||||
lloop: call readc
|
lloop: call readc
|
||||||
call next
|
call next
|
||||||
|
%ifdef FAT12
|
||||||
|
cmp word ax, 0x0FF8
|
||||||
|
%endif
|
||||||
|
%ifdef FAT16
|
||||||
|
cmp word ax, 0xFFF8
|
||||||
|
%endif
|
||||||
|
%ifdef FAT32
|
||||||
cmp word dx, 0x0FFF
|
cmp word dx, 0x0FFF
|
||||||
jne lloop
|
%endif
|
||||||
|
jc lloop
|
||||||
ret
|
ret
|
||||||
|
|
||||||
main: ; Set up BP to point to BPB
|
main: ; Set up BP to point to BPB
|
||||||
|
Loading…
Reference in New Issue
Block a user