diff --git a/boot/vbr.asm b/boot/vbr.asm index 41daeef..c9628c0 100644 --- a/boot/vbr.asm +++ b/boot/vbr.asm @@ -16,8 +16,8 @@ fdc: ; FDC Descriptor as per ECMA-107 db 0 ; number of file allocation tables .rde: dw 0 ; number of root directory entries -.ts_old: - dw 0 ; legacy: total number of sectors +.ts: + dw 720 ; total number of sectors .mi: ; medium identifier db 0xFD ; 5.25-inch Double sided, 40 tracks per side, 9 sectors per track (360 KB) .sf: ; sectors per fat @@ -28,8 +28,8 @@ fdc: ; FDC Descriptor as per ECMA-107 dw 2 ; number of sides (heads) .po: dd 0 ; partition offset (in LBA blocks) -.ts: - dw 720 +.lrgts: + dw 0 .drv: db 0 ; drive number db 0 @@ -76,29 +76,60 @@ _startup: mul word [fdc.spt] ; number of sectors = number of tracks * sectors per track mov [fdc.ts], ax .noadjust: - mov ax, 0x0500 + mov ax, 0x0070 mov es, ax - mov bx, 0x0000 - mov ax, 1 - call loadblk + xor bx, bx + call loadrootdir call dump - - mov al, [fdc.sc] - call print8 .end: hlt jmp .end -; Load a cluster from cluster offset -loadcluster: +; Load root directory into memory +; in es data segment +loadrootdir: + push bx + push cx + mov bx, [fdc.ss] ; bytes per sector + mov cl, 5 + shr bx, cl ; div by 2^5, 32 bytes per directory entity + mov ax, [fdc.rde] ; number of root directory entities + xor dx, dx + div bx + mov cx, ax + + mov ax, [fdc.sf] + mul byte [fdc.fn] + add ax, [fdc.rsc] + + xor bx, bx ; load at beginning of es +.loop: + call loadblk + loop .loop + + pop cx + pop bx ret -; Load a single cluster into memory +; Load a cluster from cluster offset +; in ax cluster number +; es:bx buffer +loadcl: + mov ax, [fdc.sf] + mul byte [fdc.fn] + add ax, [fdc.rsc] + call print16 + ret + +; Load a single block into memory ; in ax sector number ; es:bx buffer ; out al error code, ; carry set if error loadblk: + push ax + push cx + push dx xor dx, dx div word [fdc.spt] ; ax:temp = (lba / spt) inc dx ; dx:sector = (lba % spt) + 1 @@ -111,10 +142,15 @@ loadblk: mov dl, [fdc.drv] ; driver number mov ax, 0x0201 ; ah=0x02 al=0x01 int 0x13 + pop dx + pop cx + pop ax + inc ax + add bx, 0x0200 ret dump: - mov si, 0x0000 + mov si, bx mov cx, 0x10 .nextline: mov ax, si