rdos/kernel/drive.asm

88 lines
1.3 KiB
NASM

section .bss
; drive actually selected for I/O
dsknum: resb 1
; current sector number
dskseek: resd 1
; disk buffer for I/O operations
dskbuf: resb 512
dpt: resb DPTSIZE
bpb: resb BPBSIZ4
section .text
ret: ret
; Convert drive number into DL for int 13h
; A=0, B=1, C=0x80
; IN dl dos drive number
; OUT dl bios drive number
getdl: cmp dl, 2
jc ret
mov dl, 0x80
ret
; Ask BIOS for drive parameters
; IN dl dos drive number
; OUT CX,DH chs data
; ES:DI DPT if floppy
qrychs: mov ah, 8
les di, [0x1E*4]
int 0x13
jc .defs
test cl, cl
jz .defs
ret
.defs: mov cx, 0x2709 ; max track = 39, max sec = 9
mov dh, 1 ; 2 heads
ret
; select drive
; IN dl drive number
dsksel: cmp dl, byte [dsknum]
je ret
call dskrst
call getdl
push dx
call qrychs
; store CHS data in BPB
xor ax, ax
mov al, cl
mov [bpb+BPBSPT], ax
mov al, dh
inc ax
mov [bpb+BPBNOS], ax
; get dpt from bios if not hdd
pop dx
test dl, 0x80
jnz .nodpt
push dx
mov dx, dpt
mov bx, di
mov cx, DPTSIZE
call lod
mov ax, [bpb+BPBSPT]
mov [dpt+DPTSPT], al
pop dx
.nodpt:
ret
dskrst: call flush
mov ax, 0xFFFF
mov [dsknum], al
mov [dskseek], ax
mov [dskseek+2], ax
ret
; flush buffer if dirty
flush: ret