2020-12-06 18:43:38 +03:00
|
|
|
; *****************************
|
|
|
|
; Reads bytes from disk
|
|
|
|
; *****************************
|
2019-05-30 16:59:25 +03:00
|
|
|
|
|
|
|
; IN:
|
2020-12-06 18:43:38 +03:00
|
|
|
; EAX = Start address to load low 32
|
|
|
|
; EBP = Start address to load high 32
|
2019-05-30 16:59:25 +03:00
|
|
|
; DL = Drive number
|
|
|
|
; ES = Buffer segment
|
|
|
|
; BX = Buffer offset
|
2020-11-05 19:00:15 +03:00
|
|
|
; ECX = Byte count
|
2019-05-30 16:59:25 +03:00
|
|
|
|
|
|
|
; OUT:
|
|
|
|
; Carry if error
|
|
|
|
|
2020-09-06 06:15:55 +03:00
|
|
|
read_sectors:
|
|
|
|
pusha
|
2020-01-22 06:12:55 +03:00
|
|
|
|
2020-12-06 18:43:38 +03:00
|
|
|
mov si, .da_struct
|
2020-01-22 06:12:55 +03:00
|
|
|
|
2020-11-05 19:00:15 +03:00
|
|
|
mov word [si], 16
|
|
|
|
mov word [si+2], 1
|
|
|
|
mov word [si+4], bx
|
|
|
|
mov word [si+6], es
|
|
|
|
|
|
|
|
push dx
|
|
|
|
push si
|
2020-12-06 18:43:38 +03:00
|
|
|
|
|
|
|
push eax
|
|
|
|
push ebp
|
|
|
|
|
|
|
|
; Get bytes per sector
|
2020-11-05 19:00:15 +03:00
|
|
|
mov ah, 0x48
|
|
|
|
mov si, .drive_params
|
|
|
|
mov word [si], 30 ; buf_size
|
|
|
|
int 0x13
|
|
|
|
jc .done
|
|
|
|
mov bp, word [si+24] ; bytes_per_sect
|
2020-12-06 18:43:38 +03:00
|
|
|
|
|
|
|
; ECX byte count to CX sector count
|
2020-11-05 19:00:15 +03:00
|
|
|
mov ax, cx
|
|
|
|
shr ecx, 16
|
|
|
|
mov dx, cx
|
|
|
|
xor cx, cx
|
|
|
|
div bp
|
|
|
|
test dx, dx
|
2020-12-06 18:43:38 +03:00
|
|
|
setnz cl
|
|
|
|
add cx, ax
|
|
|
|
|
|
|
|
pop edx
|
|
|
|
pop eax
|
|
|
|
|
2020-11-05 19:00:15 +03:00
|
|
|
pop si
|
2020-12-06 18:43:38 +03:00
|
|
|
|
|
|
|
; EBP:EAX address to EAX LBA sector
|
|
|
|
div ebp
|
|
|
|
mov dword [si+8], eax
|
2021-03-04 14:29:59 +03:00
|
|
|
mov dword [si+12], 0
|
2020-12-06 18:43:38 +03:00
|
|
|
|
2020-11-05 19:00:15 +03:00
|
|
|
pop dx
|
2020-09-06 06:15:55 +03:00
|
|
|
|
|
|
|
.loop:
|
2020-01-22 06:12:55 +03:00
|
|
|
mov ah, 0x42
|
|
|
|
|
2020-01-22 07:02:12 +03:00
|
|
|
clc
|
|
|
|
int 0x13
|
2020-09-06 06:15:55 +03:00
|
|
|
jc .done
|
|
|
|
|
2020-11-05 19:00:15 +03:00
|
|
|
add word [si+4], bp
|
|
|
|
inc dword [si+8]
|
2020-12-06 18:43:38 +03:00
|
|
|
adc dword [si+12], 0
|
2020-09-06 06:15:55 +03:00
|
|
|
|
2020-11-05 19:00:15 +03:00
|
|
|
loop .loop
|
2020-01-22 06:12:55 +03:00
|
|
|
|
|
|
|
.done:
|
2020-09-06 06:15:55 +03:00
|
|
|
popa
|
2020-01-22 07:02:12 +03:00
|
|
|
ret
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-11-05 19:00:15 +03:00
|
|
|
.da_struct: equ 0x8000
|
|
|
|
.drive_params: equ 0x8010
|