A Simple Read Sector Function
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:A Simple Read Sector Function
oops. I obviously misunderstood your point. Sorry ... ::)
Re:A Simple Read Sector Function
Here's the function that seems to work correct:
now i got another problem with FAT12 but I will open a new thread because this thread have a wrong title for the problem.
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 + 1
mov ax, cx ; ax = sector number
mov bl, 18 ; bl = number of sectors per track
div bl ; al = ax / bl
mov cl, ah ; cl = real sector number (cl is used by int 13)
add cl, 1
; 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 bl, 2 ; bl = number of heads
div bl ; 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
Re:A Simple Read Sector Function
That doesn't mean you need to start a new thread.(sorry not meaning to sound rude)ich_will wrote: now i got another problem with FAT12 but I will open a new thread because this thread have a wrong title for the problem.
Only Human
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:A Simple Read Sector Function
not needed, but he's welcome to do so btw as the two subjects are differents. Long threads dealing with several problems are generally useless for other people that face the same problem...Neo wrote: That doesn't mean you need to start a new thread.
Re:A Simple Read Sector Function
<chuckling> well at least i tried to keep things together</chuckling>
Only Human