Code: Select all
;----------------------------------------------;
;------------- read_sector --------------------;
;----------------------------------------------;
;------ es = buffer address -------------------;
;------ bx = buffer offset -------------------;
;------ cx = sector to read -------------------;
;------ dl = drive -------------------;
;----------------------------------------------;
;------ for 1.44MB Floppys 80 Sectors ---------;
;----------------------------------------------;
read_sector:
pusha
push bx ; save buffer offset
; compute the sector number: sector_number/sectors_per_track
mov ax, cx ; ax = sector number
mov bx, 18 ; bx = number of sectors per track
div bx ; al = ax / bx
mov cl, al ; cl = real sector number (cl is used by int 13)
; compute the head number: (sector_number/sector_per_track) just in ax mod number_of_heads
; and the track number: (sector_number/sector_per_track) / number_of_heads
xor ah, ah ; del the rest of the div before
mov bx, 2 ; bx = number of heads
div bx ; ah = rest of ( ax / bx ), al = ax / bx
mov ch, al ; ch = number of track
mov dh, ah ; dh = the head number (dh is used by int 13)
pop bx ; restore the buffer offset
mov ax, cx ; save cx in ax
mov cx, 5 ; try to read the sector 5 times ;!!! overwrite the num of track and num of sec
read_sector_next_try:
pusha
mov cx, ax ; restore cx
mov ah, 0x02 ; function number 2 (read from disk)
mov al, 0x01 ; number of sectors to read
int 0x13
jnc load_ok ; if all is ok return
popa
loop read_sector_next_try; else try once again if there is an error
jmp error ; if cx = 0 and the read operation always failed, halt
load_ok:
popa
popa
ret