2019-10-08 19:54:39 +02:00
|
|
|
; Load a sector from drive.
|
|
|
|
; IN DX:AX sector number (lba)
|
|
|
|
; BX ptr to FCB
|
|
|
|
; OUT CL Sector number
|
|
|
|
; CH Cylinder number
|
|
|
|
; DH Head number
|
|
|
|
drive_chs_calc:
|
|
|
|
push bx ; backup fcb ptr
|
|
|
|
mov bx, [bx+fcb_spt] ; nos is in BH now
|
|
|
|
push bx ; backup nos
|
|
|
|
xor bh, bh ; zero out nos so spt is left
|
|
|
|
div word bx ; ax:temp = (lba / spt)
|
|
|
|
inc dx ; dx:sector = (lba % spt) + 1
|
|
|
|
mov cl, dl ; sector number
|
|
|
|
|
|
|
|
pop bx ; restore nos
|
|
|
|
xchg bl, bh ; put nos into bl
|
|
|
|
xor bh, bh ; zero out spt
|
|
|
|
div word bx ; ax:cylinder = (temp / nos)
|
|
|
|
; dx:head = (temp % nos)
|
|
|
|
mov ch, al ; cylinder number
|
|
|
|
mov dh, dl ; head number
|
|
|
|
|
|
|
|
pop bx ; restore fcb ptr
|
|
|
|
ret
|
|
|
|
|
2019-09-29 23:25:29 +02:00
|
|
|
; Load a sector from drive.
|
|
|
|
; IN DX:AX sector number
|
2019-10-08 19:54:39 +02:00
|
|
|
; BX ptr to FCB
|
2019-09-29 23:25:29 +02:00
|
|
|
drive_read:
|
|
|
|
push ax
|
|
|
|
push cx
|
|
|
|
push dx
|
|
|
|
push bx
|
|
|
|
push si
|
|
|
|
|
|
|
|
mov cx, dx
|
|
|
|
or cx, ax
|
|
|
|
jz .fast
|
|
|
|
|
2019-10-08 19:54:39 +02:00
|
|
|
call drive_chs_calc
|
2019-09-29 23:25:29 +02:00
|
|
|
|
|
|
|
mov si, 5 ; retry count
|
|
|
|
.try:
|
2019-10-08 19:54:39 +02:00
|
|
|
mov dl, [bx+fcb_drv] ; drive number
|
|
|
|
dec dl
|
2019-09-29 23:25:29 +02:00
|
|
|
mov ax, 0x0201
|
2019-10-08 19:54:39 +02:00
|
|
|
mov bx, diskbuf
|
2019-10-14 19:59:48 +02:00
|
|
|
; try read
|
2019-09-29 23:25:29 +02:00
|
|
|
int 0x13
|
2019-10-14 19:59:48 +02:00
|
|
|
jnc .end
|
2019-09-29 23:25:29 +02:00
|
|
|
; reset disk
|
|
|
|
mov ah, 0x00
|
|
|
|
int 0x13
|
|
|
|
; loop with si
|
|
|
|
dec si
|
|
|
|
test si, si
|
|
|
|
jnz .try
|
|
|
|
stc
|
2019-10-14 19:59:48 +02:00
|
|
|
.end:
|
|
|
|
pop si
|
|
|
|
pop bx
|
|
|
|
pop dx
|
2019-10-12 20:33:26 +02:00
|
|
|
pop cx
|
|
|
|
pop ax
|
|
|
|
ret
|
2019-10-14 19:59:48 +02:00
|
|
|
.fast: ; fast lane for boot sector
|
|
|
|
inc cl
|
|
|
|
jmp .try
|