Code: Select all
loadLoop:
;; Save the current cluster
push ax
;; Find the LBA of the cluster
dec ax
dec ax
mul byte [Boot.SPC]
;; These were calculated earlier
add ax, [ROOTSTART]
add ax, [ROOTLENGTH]
;; Load all of the sectors in the cluster
movzx cx, byte [Boot.SPC]
.clusterLoop:
push cx
push ax
;; Convert the cluster's LBA to CHS
call getCHS
;; only want one sector (in case a cluster crosses a track boundary)
mov al, 1
;; Get the destination
mov bx, di
call readDiskCHS
;; Automatically advance destination pointer
add di, [Boot.BPS]
;; get the LBA and move to the next cluster
pop ax
inc ax
;; Get the loop counter and loop
pop cx
loop .clusterLoop
;; Get the current cluster's number back
pop ax
;; Save it, we'll need it for even/odd checking
push ax
;; Get the byte index into the FAT of the cluster (* by 1.5)
mov bx, ax
shr bx, 1
add ax, bx
;; From that we can figure the sector index of the cluster in the FAT
;; and the byte index into this sector of the cluster
xor dx, dx
div ax, word [Boot.BPS]
inc dx
mov si, dx
add ax, [Boot.RSC]
;; SI = cluster's index, AX = cluster's FAT sector
;; Save the destination segment so we don't interfere
;; and use DS for smaller instructions
push es
;; A.K.A. mov es, ds
push ds
pop es
;; Save the sector LBA (we want this one and the next one)
push ax
;; Load it
call getCHS
mov bx, freeSpace
add si, bx
mov al, 1
call readDiskCHS
;; Get the next sector in case the cluster index spans two
;; of them
pop ax
inc ax
push bx
call getCHS
pop bx
add bx, [Boot.BPS]
mov al, 1
call readDiskCHS
;; Get the real destination back now due to stack layout
pop es
;; Get the last cluster (the one we just loaded) for even/odd checking
pop bx
mov ax, [si]
test bx, 1
jnz .odd
;; if even, lop off top 4 bits
shl ax, 4
.odd:
;; Shift down to get the actual number
shr ax, 4
cmp ax, 0x0FF0
jb loadLoop
Thank you for taking the time to fix my stupid mistakes .