fat32 bs: use BPB include header and base off BP
We now set BP once at the start to point to the beginning of the BPB. Encoding an direct address access can then be done relative to BP, which saves an immediate byte per access.
This commit is contained in:
parent
9044e3948c
commit
1981a8efba
@ -4,29 +4,12 @@
|
|||||||
jmp short init
|
jmp short init
|
||||||
nop
|
nop
|
||||||
|
|
||||||
; WORD reserved sector count
|
%include "inc/bpb.asm"
|
||||||
rsc: equ ( $$ + 0x00E )
|
|
||||||
|
|
||||||
; BYTE number of sectors per cluster
|
bpb: equ 0x080B
|
||||||
sc: equ ( $$ + 0x00D )
|
|
||||||
|
|
||||||
; BYTE number of FATs
|
|
||||||
fn: equ ( $$ + 0x010 )
|
|
||||||
|
|
||||||
; WORD number of root directory entries
|
|
||||||
rde: equ ( $$ + 0x011 )
|
|
||||||
|
|
||||||
; DWORD hidden sector count (partition offset)
|
|
||||||
po: equ ( $$ + 0x01C )
|
|
||||||
|
|
||||||
; DWORD sectors per FAT
|
|
||||||
sf: equ ( $$ + 0x024 )
|
|
||||||
|
|
||||||
; BYTE drive number (we set it from dl)
|
|
||||||
dn: equ ( $$ + 0x040 )
|
|
||||||
|
|
||||||
; Area for BPB
|
; Area for BPB
|
||||||
times (0x5A - ($-$$)) db 0
|
times ( 0x5A - ($-$$) ) db 0
|
||||||
|
|
||||||
init: xor ax, ax
|
init: xor ax, ax
|
||||||
mov ss, ax
|
mov ss, ax
|
||||||
@ -66,7 +49,7 @@ hlt: hlt
|
|||||||
; offsets relative to FS
|
; offsets relative to FS
|
||||||
readd: ; add offset of cluster data area to DX:AX
|
readd: ; add offset of cluster data area to DX:AX
|
||||||
push cx
|
push cx
|
||||||
mov di, [rde]
|
mov di, [bp+bpb_rde]
|
||||||
mov cl, 4
|
mov cl, 4
|
||||||
shr di, cl ; 32 bytes per entry
|
shr di, cl ; 32 bytes per entry
|
||||||
add ax, di
|
add ax, di
|
||||||
@ -75,17 +58,17 @@ readd: ; add offset of cluster data area to DX:AX
|
|||||||
readr: ; add offset to rootdir to DX:AX (FAT12/FAT16 only)
|
readr: ; add offset to rootdir to DX:AX (FAT12/FAT16 only)
|
||||||
push cx
|
push cx
|
||||||
xor ch, ch
|
xor ch, ch
|
||||||
mov cl, byte [fn]
|
mov cl, byte [bp+bpb_fn]
|
||||||
fatlp: add ax, [sf]
|
fatlp: add ax, [bp+bpb7_lsf]
|
||||||
adc dx, [sf+2]
|
adc dx, [bp+bpb7_lsf+2]
|
||||||
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
|
||||||
add ax, word [rsc]
|
add ax, word [bp+bpb_rsc]
|
||||||
adc dx, 0
|
adc dx, 0
|
||||||
readp: ; read sector DX:AX from partition
|
readp: ; read sector DX:AX from partition
|
||||||
add ax, word [po]
|
add ax, word [bp+bpb_po]
|
||||||
adc dx, word [po+2]
|
adc dx, word [bp+bpb_po+2]
|
||||||
jc err
|
jc err
|
||||||
read_: ; read sector DX:AX from disk
|
read_: ; read sector DX:AX from disk
|
||||||
; qword sector number DX:AX
|
; qword sector number DX:AX
|
||||||
@ -102,17 +85,17 @@ read_: ; read sector DX:AX from disk
|
|||||||
push cx
|
push cx
|
||||||
|
|
||||||
; size & passing
|
; size & passing
|
||||||
mov bp, 0x10
|
mov di, 0x10
|
||||||
push bp
|
push di
|
||||||
|
|
||||||
mov si, sp
|
mov si, sp
|
||||||
mov ah, 0x42
|
mov ah, 0x42
|
||||||
mov dl, [dn]
|
mov dl, [bp+bpb7_dn]
|
||||||
stc
|
stc
|
||||||
int 0x13
|
int 0x13
|
||||||
jc dskerr
|
jc dskerr
|
||||||
|
|
||||||
add sp, bp
|
add sp, di
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -159,7 +142,7 @@ readc: ; load cluster number
|
|||||||
|
|
||||||
; convert cluster number to sector number
|
; convert cluster number to sector number
|
||||||
; this is some cheapo multiplication with 2^n
|
; this is some cheapo multiplication with 2^n
|
||||||
mov cl, [sc]
|
mov cl, [bp+bpb_sc]
|
||||||
l02: shr cl, 1
|
l02: shr cl, 1
|
||||||
jz l02e
|
jz l02e
|
||||||
clc
|
clc
|
||||||
@ -168,15 +151,15 @@ l02: shr cl, 1
|
|||||||
jmp l02
|
jmp l02
|
||||||
l02e:
|
l02e:
|
||||||
; dx:ax is now sector num in data area
|
; dx:ax is now sector num in data area
|
||||||
mov cx, [sc]
|
mov cx, [bp+bpb_sc]
|
||||||
xor ch, ch
|
xor ch, ch
|
||||||
|
|
||||||
call readd
|
call readd
|
||||||
|
|
||||||
xchg bp, cx
|
xchg di, cx
|
||||||
mov cl, 5
|
mov cl, 5
|
||||||
sal bp, cl
|
sal di, cl
|
||||||
add bx, bp
|
add bx, di
|
||||||
|
|
||||||
pop dx
|
pop dx
|
||||||
pop ax
|
pop ax
|
||||||
@ -219,7 +202,8 @@ loadf: call search
|
|||||||
mov dx, [si+0x14]
|
mov dx, [si+0x14]
|
||||||
jmp load
|
jmp load
|
||||||
|
|
||||||
main: mov [dn], dl
|
main: mov bp, bpb
|
||||||
|
mov [bp+bpb7_dn], dl
|
||||||
; load root directory
|
; load root directory
|
||||||
call loadr
|
call loadr
|
||||||
; search for first system directory
|
; search for first system directory
|
||||||
@ -234,10 +218,9 @@ main: mov [dn], dl
|
|||||||
xor dx, dx
|
xor dx, dx
|
||||||
xor bx, bx
|
xor bx, bx
|
||||||
xor di, di
|
xor di, di
|
||||||
xor bp, bp
|
|
||||||
|
|
||||||
; restore drive number
|
; restore drive number
|
||||||
mov dl, [dn]
|
mov dl, [bp+bpb7_dn]
|
||||||
|
|
||||||
; restore potential partition table
|
; restore potential partition table
|
||||||
pop si
|
pop si
|
||||||
|
Loading…
Reference in New Issue
Block a user