rdos/kernel/drive.asm

88 lines
1.3 KiB
NASM
Raw Normal View History

2020-08-15 23:15:31 +02:00
section .bss
2020-10-13 22:10:23 +02:00
; drive actually selected for I/O
2020-10-11 23:33:01 +02:00
dsknum: resb 1
; current sector number
dskseek: resd 1
; disk buffer for I/O operations
2020-10-11 23:33:01 +02:00
dskbuf: resb 512
dpt: resb DPTSIZE
2020-10-30 10:29:22 +01:00
bpb: resb BPBSIZ4
2020-08-15 23:15:31 +02:00
section .text
2020-10-11 23:33:01 +02:00
ret: ret
; Convert drive number into DL for int 13h
2020-10-30 10:29:22 +01:00
; 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
2020-10-30 10:29:22 +01:00
; 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]
2020-10-11 23:33:01 +02:00
je ret
2020-10-11 23:33:01 +02:00
call dskrst
call getdl
2020-10-30 10:29:22 +01:00
push dx
call qrychs
2020-10-30 10:29:22 +01:00
; 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
2020-10-30 10:29:22 +01:00
mov bx, di
mov cx, DPTSIZE
call lod
2020-10-30 10:29:22 +01:00
mov ax, [bpb+BPBSPT]
mov [dpt+DPTSPT], al
pop dx
.nodpt:
ret
2020-10-11 23:33:01 +02:00
dskrst: call flush
mov ax, 0xFFFF
mov [dsknum], al
mov [dskseek], ax
mov [dskseek+2], ax
ret
2020-10-11 23:33:01 +02:00
; flush buffer if dirty
flush: ret