shadeos/learning/old_src/16bit/disk.asm

40 lines
1.2 KiB
NASM

; load 'dh' sectors from drive 'dl' into ES:BX
disk_load:
pusha
push dx ; save dx to stack for later use, as it needs to be overwritten
mov ah, 0x02 ; ah: int 0x13 function. 0x02 = 'read'
mov al, dh ; al: number of sectors to read (0x01 .. 0x80)
mov cl, 0x02 ; cl: sector (0x01 .. 0x11). 0x01 is boot sector, 0x02 is first 'avaliable' sector
mov ch, 0x00 ; ch: cylinder (0x0 .. 0x3FF, upper 2 bits in 'cl')
; dl: drive number. caller sets it as param and gets it from bios
; 0 = floppy, 1 = floppy2, 0x80 = hdd, 0x81 = hdd2
mov dh, 0x00 ; dh: head number (0x0 .. 0xF)
; [es:bx] pointer to buf where data is stored
; caller sets it up, and is standard location for int 13h
int 13h
jc disk_error ; if error (in carry)
pop dx
cmp al, dh ; al is # of sectors read. compare it
jne sectors_error
popa
ret
disk_error:
mov bx, DISK_ERROR
call print
call print_nl
mov dh, ah ; ah = error code, dl = disk drive that caused error
call print_hex
sectors_error:
mov bx, SECTORS_ERROR
call print
disk_loop:
jmp $
DISK_ERROR: db "Disk read error", 0
SECTORS_ERROR: db "Incorrect number of sectors read", 0