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
|
2020-08-27 22:52:16 +02:00
|
|
|
|
|
|
|
; disk buffer for I/O operations
|
2020-10-11 23:33:01 +02:00
|
|
|
dskbuf: resb 512
|
2020-08-27 22:52:16 +02:00
|
|
|
|
2020-10-25 00:50:23 +02:00
|
|
|
dpt: resb DPTSIZE
|
2020-10-30 10:29:22 +01:00
|
|
|
bpb: resb BPBSIZ4
|
2020-10-25 00:50:23 +02:00
|
|
|
|
2020-08-15 23:15:31 +02:00
|
|
|
section .text
|
|
|
|
|
2020-10-11 23:33:01 +02:00
|
|
|
ret: ret
|
2020-08-27 22:52:16 +02:00
|
|
|
|
2020-10-25 00:50:23 +02:00
|
|
|
; Convert drive number into DL for int 13h
|
2020-10-30 10:29:22 +01:00
|
|
|
; A=0, B=1, C=0x80
|
2020-10-25 00:50:23 +02:00
|
|
|
; 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
|
|
|
|
|
2020-08-27 22:52:16 +02:00
|
|
|
; select drive
|
|
|
|
; IN dl drive number
|
2020-10-25 00:50:23 +02:00
|
|
|
dsksel: cmp dl, byte [dsknum]
|
2020-10-11 23:33:01 +02:00
|
|
|
je ret
|
2020-08-27 22:52:16 +02:00
|
|
|
|
2020-10-11 23:33:01 +02:00
|
|
|
call dskrst
|
2020-08-27 22:52:16 +02:00
|
|
|
|
2020-10-25 00:50:23 +02:00
|
|
|
call getdl
|
2020-10-30 10:29:22 +01:00
|
|
|
push dx
|
|
|
|
call qrychs
|
2020-10-25 00:50:23 +02:00
|
|
|
|
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
|
2020-10-25 00:50:23 +02:00
|
|
|
mov dx, dpt
|
2020-10-30 10:29:22 +01:00
|
|
|
mov bx, di
|
2020-10-25 00:50:23 +02:00
|
|
|
mov cx, DPTSIZE
|
|
|
|
call lod
|
2020-10-30 10:29:22 +01:00
|
|
|
mov ax, [bpb+BPBSPT]
|
|
|
|
mov [dpt+DPTSPT], al
|
|
|
|
pop dx
|
|
|
|
.nodpt:
|
|
|
|
|
2020-08-27 22:52:16 +02:00
|
|
|
|
|
|
|
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
|
2020-08-27 22:52:16 +02:00
|
|
|
ret
|
|
|
|
|
2020-10-11 23:33:01 +02:00
|
|
|
; flush buffer if dirty
|
|
|
|
flush: ret
|