49 lines
838 B
NASM
49 lines
838 B
NASM
|
; Load a sector from drive.
|
||
|
; IN DX:AX sector number
|
||
|
; BP ptr to BPB
|
||
|
drive_read:
|
||
|
push ax
|
||
|
push cx
|
||
|
push dx
|
||
|
push bx
|
||
|
push si
|
||
|
|
||
|
mov cx, dx
|
||
|
or cx, ax
|
||
|
jz .fast
|
||
|
|
||
|
div word [bp+13] ; ax:temp = (lba / spt)
|
||
|
inc dx ; dx:sector = (lba % spt) + 1
|
||
|
mov cl, dl ; sector number
|
||
|
|
||
|
div word [bp+15] ; ax:cylinder = (tmp / heads)
|
||
|
; dx:head = (tmp % heads)
|
||
|
mov ch, al ; cylinder number
|
||
|
mov dh, dl ; head number
|
||
|
mov si, 5 ; retry count
|
||
|
.try:
|
||
|
mov dl, [bp+(bpb_size-1)] ; drive number
|
||
|
mov bx, diskbuf
|
||
|
mov ax, 0x0201
|
||
|
int 0x13
|
||
|
.giveup:
|
||
|
pop si
|
||
|
pop bx
|
||
|
pop dx
|
||
|
pop cx
|
||
|
pop ax
|
||
|
ret
|
||
|
.fast: ; fast lane for boot sector
|
||
|
inc cl
|
||
|
jmp .try
|
||
|
.fail:
|
||
|
; reset disk
|
||
|
mov ah, 0x00
|
||
|
int 0x13
|
||
|
; loop with si
|
||
|
dec si
|
||
|
test si, si
|
||
|
jnz .try
|
||
|
stc
|
||
|
jmp .giveup
|