Implement calculation of number of clusters

This commit is contained in:
Nero 2020-05-11 21:19:51 +00:00
parent efb5ad146c
commit 5129a5499e

View File

@ -21,6 +21,15 @@ clusters_num:
section .text section .text
load_ts: ; load total number of sectors into DX:AX
xor dx, dx
mov ax, [disk_buffer+0x013]
test ax, ax
jnz .ret
mov ax, [disk_buffer+0x020]
mov dx, [disk_buffer+0x022]
.ret: ret
; invoked after disk select ; invoked after disk select
load_bpb: load_bpb:
; read word for "sectors per fat" ; read word for "sectors per fat"
@ -47,22 +56,57 @@ load_bpb:
mov al, [disk_buffer+0x010] mov al, [disk_buffer+0x010]
mov [fat_num], ax mov [fat_num], ax
; copy number of root directory entries
mov ax, [disk_buffer+0x011]
mov cl, 4
shr ax, cl
mov [rootdir_size], ax
; calculate offsets for everything
mov ax, [part_offset] mov ax, [part_offset]
mov dx, [part_offset+2] mov dx, [part_offset+2]
; add reserved sectors
add ax, [disk_buffer+0x0B+bpb_rsc] add ax, [disk_buffer+0x0B+bpb_rsc]
adc ax, 0 adc ax, 0
; save begin of FAT tables
mov [fat_offset], ax mov [fat_offset], ax
mov [fat_offset+2], dx mov [fat_offset+2], dx
int 3
; add FAT size * FAT number ; add FAT size * FAT number
mov cx, [fat_num] mov cx, [fat_num]
.floop: add ax, [fat_size] .floop: add ax, [fat_size]
adc dx, [fat_size+2] adc dx, [fat_size+2]
loop .floop loop .floop
; save begin of root directories
mov [rootdir_offset], ax
mov [rootdir_offset+2], dx
; add root directory size (might be zero)
add ax, [rootdir_size]
adc dx, 0
; save start of data area
mov [clusters_offset], ax
mov [clusters_offset+2], dx
call load_ts
add ax, [part_offset]
adc dx, [part_offset+2]
sub ax, [clusters_offset]
sbb dx, [clusters_offset+2]
; get "sectors per cluster"
mov cl, [disk_buffer+0x00D]
; this turns dx:ax from data sectors to number of clus
.sloop: shr cl, 1
test cl, cl
jz .send
clc
rcr dx, 1
rcr ax, 1
jmp .sloop
.send: mov [clusters_num], ax
mov [clusters_num+2], dx
int 3 int 3
ret ret
.err: stc .err: stc
ret ret