| 1 | ; ***************************** |
| 2 | ; Reads bytes from disk |
| 3 | ; ***************************** |
| 4 | |
| 5 | ; IN: |
| 6 | ; EAX = Start address to load low 32 |
| 7 | ; EBP = Start address to load high 32 |
| 8 | ; DL = Drive number |
| 9 | ; ES = Buffer segment |
| 10 | ; BX = Buffer offset |
| 11 | ; ECX = Byte count |
| 12 | |
| 13 | ; OUT: |
| 14 | ; Carry if error |
| 15 | |
| 16 | read_sectors: |
| 17 | pusha |
| 18 | |
| 19 | mov si, .da_struct |
| 20 | |
| 21 | mov dword [si], 0x00010010 |
| 22 | mov word [si+4], bx |
| 23 | mov word [si+6], es |
| 24 | |
| 25 | push dx |
| 26 | push si |
| 27 | |
| 28 | push eax |
| 29 | push ebp |
| 30 | |
| 31 | ; Get bytes per sector |
| 32 | mov ah, 0x48 |
| 33 | mov si, .drive_params |
| 34 | mov word [si], 30 ; buf_size |
| 35 | int 0x13 |
| 36 | jc .fail |
| 37 | movzx ebp, word [si+24] ; bytes_per_sect |
| 38 | |
| 39 | ; ECX byte count to CX sector count |
| 40 | xchg ax, cx |
| 41 | shr ecx, 16 |
| 42 | mov dx, cx |
| 43 | xor cx, cx |
| 44 | div bp |
| 45 | test dx, dx |
| 46 | setnz cl |
| 47 | add cx, ax |
| 48 | |
| 49 | pop edx |
| 50 | pop eax |
| 51 | |
| 52 | pop si |
| 53 | |
| 54 | ; EDX:EAX byte address to 64-bit LBA sector |
| 55 | push eax |
| 56 | xchg eax, edx |
| 57 | xor edx, edx |
| 58 | div ebp |
| 59 | xchg ebx, eax |
| 60 | pop eax |
| 61 | div ebp |
| 62 | mov dword [si+8], eax |
| 63 | mov dword [si+12], ebx |
| 64 | |
| 65 | pop dx |
| 66 | |
| 67 | .loop: |
| 68 | mov ah, 0x42 |
| 69 | |
| 70 | clc |
| 71 | int 0x13 |
| 72 | jc .done |
| 73 | |
| 74 | add word [si+4], bp |
| 75 | add dword [si+8], 1 |
| 76 | adc dword [si+12], 0 |
| 77 | |
| 78 | loop .loop |
| 79 | |
| 80 | jmp short .done |
| 81 | |
| 82 | .fail: |
| 83 | add sp, 12 |
| 84 | stc |
| 85 | .done: |
| 86 | popa |
| 87 | ret |
| 88 | |
| 89 | .da_struct: equ 0x8000 |
| 90 | .drive_params: equ 0x8010 |