sys: calculate length of cluster series

This commit is contained in:
Nero 2021-12-14 15:23:49 +00:00
parent cfadc73493
commit 467054def6
1 changed files with 34 additions and 11 deletions

View File

@ -15,7 +15,12 @@ main mov di, 0x81
mov cl, [0x80]
repe 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
mov dx, ax
test dx, ~0x83
@ -37,17 +42,23 @@ floppy mov ax, 0x0201
int 0x13
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
mov ax, [prog+0x011] ; number of dir entries
mov cl, 5
shl ax, cl
mov bx, [prog+0x0B] ; bytes per sector
div bx
; TODO: abort if dx is not zero
mov cx, ax
mov ax, [prog+0x016] ; logical sectors per fat
; TODO: abort if ax is zero (=large FAT32)
mov bl, [prog+0x010]
mov bl, [prog+0x010] ; number of fats
mov bh, 0
mul bx
add ax, cx
@ -55,24 +66,36 @@ floppy mov ax, 0x0201
mov si, ax
; calculate sector offset of target track
mov ax, [prog+0x018]
mul word [prog+0x01A]
mov ax, [prog+0x018] ; sectors per track
mul word [prog+0x01A] ; number of heads
mul word [track]
; calculate cluster offset of target track
; calculate cluster offset of target track -> SI
sub ax, si
mov bl, [prog+0x00D] ; sectors per cluster
mov bh, 0
call debug
xor dx, dx
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
ret
; TODO:
; calculate cluster offset of target track
; calculate cluster length of target track
; calculate offset into fat table
; load part of fat table spanning our track
; check that all relevant clusters are 0 or 0xFFF7
; set all relevant clusters to 0xFFF7
; track is now available for direct writing