sys: calculate length of cluster series

This commit is contained in:
Nero 2021-12-14 15:23:49 +00:00
parent cfadc73493
commit 467054def6

View File

@ -15,7 +15,12 @@ main mov di, 0x81
mov cl, [0x80] mov cl, [0x80]
repe scasb repe scasb
repne scasb repne scasb
mov si, di test cx, cx
jnz rddrv
call putsh
db "BIOS drive number not specified", 0x0A, 0x0D, 0
int 0x20
rddrv mov si, di
call lodnum call lodnum
mov dx, ax mov dx, ax
test dx, ~0x83 test dx, ~0x83
@ -37,17 +42,23 @@ floppy mov ax, 0x0201
int 0x13 int 0x13
jc drverr jc drverr
mov ax, [prog+0x016]
cmp ax, 12
jbe .gok
call putsh
db "Unsupported FAT size", 0x0A, 0x0D, 0
int 0x20
.gok nop
; calculate start of cluster area ; calculate start of cluster area
mov ax, [prog+0x011] ; number of dir entries mov ax, [prog+0x011] ; number of dir entries
mov cl, 5 mov cl, 5
shl ax, cl shl ax, cl
mov bx, [prog+0x0B] ; bytes per sector mov bx, [prog+0x0B] ; bytes per sector
div bx div bx
; TODO: abort if dx is not zero
mov cx, ax mov cx, ax
mov ax, [prog+0x016] ; logical sectors per fat mov ax, [prog+0x016] ; logical sectors per fat
; TODO: abort if ax is zero (=large FAT32) mov bl, [prog+0x010] ; number of fats
mov bl, [prog+0x010]
mov bh, 0 mov bh, 0
mul bx mul bx
add ax, cx add ax, cx
@ -55,24 +66,36 @@ floppy mov ax, 0x0201
mov si, ax mov si, ax
; calculate sector offset of target track ; calculate sector offset of target track
mov ax, [prog+0x018] mov ax, [prog+0x018] ; sectors per track
mul word [prog+0x01A] mul word [prog+0x01A] ; number of heads
mul word [track] mul word [track]
; calculate cluster offset of target track ; calculate cluster offset of target track -> SI
sub ax, si sub ax, si
mov bl, [prog+0x00D] ; sectors per cluster mov bl, [prog+0x00D] ; sectors per cluster
mov bh, 0 mov bh, 0
call debug xor dx, dx
div bx div bx
mov si, ax
; calculate cluster length of target track -> DI
mov ax, [prog+0x018] ; sectors per track
add ax, dx ; remainder
; add sectors per cluster minus one
add ax, bx
dec ax
; divide by sectors per cluster and floor
xor dx, dx
div bx
mov di, ax
; load fat table
call debug call debug
ret ret
; TODO: ; TODO:
; calculate cluster offset of target track
; calculate cluster length of target track
; calculate offset into fat table ; calculate offset into fat table
; load part of fat table spanning our track
; check that all relevant clusters are 0 or 0xFFF7 ; check that all relevant clusters are 0 or 0xFFF7
; set all relevant clusters to 0xFFF7 ; set all relevant clusters to 0xFFF7
; track is now available for direct writing ; track is now available for direct writing