rdos/boot/vbr.asm

93 lines
1.8 KiB
NASM
Raw Normal View History

2019-03-25 09:51:37 +01:00
org 0x7C00
bpb:
jmp _startup ; 2 bytes
nop ; 1 byte
.oem:
db "OEM " ; OEM
2019-03-25 09:51:37 +01:00
.bps:
dw 0x200 ; bytes per sector
.spc:
db 1 ; sectors per cluster
.rsectors:
dw 2 ; number of reserved sectors
.fats:
2019-03-25 09:51:37 +01:00
db 2 ; number of file allocation tables
.dirents:
dw 2 ; Number of directory entries
.sectors:
2019-03-25 09:51:37 +01:00
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:
2019-03-25 09:51:37 +01:00
dw 2 ; number of heads
.hidsecs:
2019-03-25 09:51:37 +01:00
dd 0 ; number of hidden sectors
.lrgsectors:
2019-03-25 09:51:37 +01:00
dd 0 ; large sector count
times (0x3E - ($-$$)) nop
_startup:
call printgeo
2019-03-25 09:51:37 +01:00
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
2019-03-25 09:51:37 +01:00
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
2019-03-25 09:51:37 +01:00
.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
2019-03-25 09:51:37 +01:00
%include "print.asm"
times (0x1FE - ($-$$)) nop
dw 0xAA55