vbr: Parse CHS from BIOS to optionally overwrite hardcoded CHS data

This commit is contained in:
Nero 2019-03-25 22:00:07 +00:00
parent 2229c319b6
commit 96234c2a40

View File

@ -4,18 +4,18 @@ bpb:
jmp _startup ; 2 bytes jmp _startup ; 2 bytes
nop ; 1 byte nop ; 1 byte
.oem: .oem:
db "2A " ; OEM db "OEM " ; OEM
.bps: .bps:
dw 0x200 ; bytes per sector dw 0x200 ; bytes per sector
.spc: .spc:
db 1 ; sectors per cluster db 1 ; sectors per cluster
.rsectors: .rsectors:
dw 2 ; number of reserved sectors dw 2 ; number of reserved sectors
.fatcnt: .fats:
db 2 ; number of file allocation tables db 2 ; number of file allocation tables
.dirents: .dirents:
dw 2 ; Number of directory entries dw 2 ; Number of directory entries
.seccnt: .sectors:
dw 720 ; total number of sectors dw 720 ; total number of sectors
.mtd: ; media descriptor type .mtd: ; media descriptor type
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)
@ -23,26 +23,69 @@ bpb:
dw 0 dw 0
.spt: .spt:
dw 9 ; sectors per track dw 9 ; sectors per track
.headcnt: .heads:
dw 2 ; number of heads dw 2 ; number of heads
.hidseccnt: .hidsecs:
dd 0 ; number of hidden sectors dd 0 ; number of hidden sectors
.lrgseccnt: .lrgsectors:
dd 0 ; large sector count dd 0 ; large sector count
times (0x3E - ($-$$)) nop times (0x3E - ($-$$)) nop
_startup: _startup:
call printgeo
mov ah, 0x08 mov ah, 0x08
mov dl, 0x00 mov dl, 0x00
int 0x13 int 0x13 ; required, QEMU detects 360kB as 1200kB with CHS 80 2 15
jc .noadjust
inc dh
mov [bpb.heads], dh
mov ax, cx mov ax, cx
and ax, 0x003F and ax, 0x003F
call print16 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: .end:
hlt hlt
jmp .end 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" %include "print.asm"
times (0x1FE - ($-$$)) nop times (0x1FE - ($-$$)) nop