vbr: read root directory into memory

This commit is contained in:
Nero 2019-03-27 23:06:13 +00:00
parent 7492e99c3f
commit 6bfb0dd21e

View File

@ -16,8 +16,8 @@ fdc: ; FDC Descriptor as per ECMA-107
db 0 ; number of file allocation tables db 0 ; number of file allocation tables
.rde: .rde:
dw 0 ; number of root directory entries dw 0 ; number of root directory entries
.ts_old: .ts:
dw 0 ; legacy: total number of sectors dw 720 ; total number of sectors
.mi: ; medium identifier .mi: ; medium identifier
db 0xFD ; 5.25-inch Double sided, 40 tracks per side, 9 sectors per track (360 KB) db 0xFD ; 5.25-inch Double sided, 40 tracks per side, 9 sectors per track (360 KB)
.sf: ; sectors per fat .sf: ; sectors per fat
@ -28,8 +28,8 @@ fdc: ; FDC Descriptor as per ECMA-107
dw 2 ; number of sides (heads) dw 2 ; number of sides (heads)
.po: .po:
dd 0 ; partition offset (in LBA blocks) dd 0 ; partition offset (in LBA blocks)
.ts: .lrgts:
dw 720 dw 0
.drv: .drv:
db 0 ; drive number db 0 ; drive number
db 0 db 0
@ -76,29 +76,60 @@ _startup:
mul word [fdc.spt] ; number of sectors = number of tracks * sectors per track mul word [fdc.spt] ; number of sectors = number of tracks * sectors per track
mov [fdc.ts], ax mov [fdc.ts], ax
.noadjust: .noadjust:
mov ax, 0x0500 mov ax, 0x0070
mov es, ax mov es, ax
mov bx, 0x0000 xor bx, bx
mov ax, 1 call loadrootdir
call loadblk
call dump call dump
mov al, [fdc.sc]
call print8
.end: .end:
hlt hlt
jmp .end jmp .end
; Load a cluster from cluster offset ; Load root directory into memory
loadcluster: ; 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 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 ; in ax sector number
; es:bx buffer ; es:bx buffer
; out al error code, ; out al error code,
; carry set if error ; carry set if error
loadblk: loadblk:
push ax
push cx
push dx
xor dx, dx xor dx, dx
div word [fdc.spt] ; ax:temp = (lba / spt) div word [fdc.spt] ; ax:temp = (lba / spt)
inc dx ; dx:sector = (lba % spt) + 1 inc dx ; dx:sector = (lba % spt) + 1
@ -111,10 +142,15 @@ loadblk:
mov dl, [fdc.drv] ; driver number mov dl, [fdc.drv] ; driver number
mov ax, 0x0201 ; ah=0x02 al=0x01 mov ax, 0x0201 ; ah=0x02 al=0x01
int 0x13 int 0x13
pop dx
pop cx
pop ax
inc ax
add bx, 0x0200
ret ret
dump: dump:
mov si, 0x0000 mov si, bx
mov cx, 0x10 mov cx, 0x10
.nextline: .nextline:
mov ax, si mov ax, si