rdos/boot/vbr.asm

93 lines
1.8 KiB
NASM

org 0x7C00
bpb:
jmp _startup ; 2 bytes
nop ; 1 byte
.oem:
db "OEM " ; OEM
.bps:
dw 0x200 ; bytes per sector
.spc:
db 1 ; sectors per cluster
.rsectors:
dw 2 ; number of reserved sectors
.fats:
db 2 ; number of file allocation tables
.dirents:
dw 2 ; Number of directory entries
.sectors:
dw 720 ; total number of sectors
.mtd: ; media descriptor type
db 0xFD ; 5.25-inch Double sided, 40 tracks per side, 9 sectors per track (360 KB)
.spfat: ; sectors per fat
dw 0
.spt:
dw 9 ; sectors per track
.heads:
dw 2 ; number of heads
.hidsecs:
dd 0 ; number of hidden sectors
.lrgsectors:
dd 0 ; large sector count
times (0x3E - ($-$$)) nop
_startup:
call printgeo
mov ah, 0x08
mov dl, 0x00
int 0x13 ; required, QEMU detects 360kB as 1200kB with CHS 80 2 15
jc .noadjust
inc dh
mov [bpb.heads], dh
mov ax, cx
and ax, 0x003F
mov [bpb.spt], ax ; no adjustment because sectors are 1-indexed
mov ax, cx
xchg al, ah
mov cl,6
shr ah,cl
inc ax ; convert from maximum number (0-based) to total number (1-based) of cylinders
mul word [bpb.heads] ; number of tracks = number of cylinders * heads
mul word [bpb.spt] ; number of sectors = number of tracks * sectors per track
mov [bpb.sectors], ax
.noadjust:
call printgeo
.end:
hlt
jmp .end
printgeo:
mov ax, [bpb.heads]
call print16
mov ax, [bpb.spt]
call print16
mov ax, [bpb.sectors]
call print16
mov al, 0x0A
call printc
mov al, 0x0D
call printc
ret
; in bx sector number,
; dl drive number
; ds:di buffer
; out al error code,
; carry set if error
loadblk:
mov ax, bx
div byte [bpb.spt]
call print16
; Temp = LBA / (Sectors per Track)
; Sector = (LBA % (Sectors per Track)) + 1
; Head = Temp % (Number of Heads)
; Cylinder = Temp / (Number of Heads)
ret
%include "print.asm"
times (0x1FE - ($-$$)) nop
dw 0xAA55