Page 2 of 2

Re:A Simple Read Sector Function

Posted: Mon Mar 15, 2004 12:37 pm
by Pype.Clicker
oops. I obviously misunderstood your point. Sorry ... ::)

Re:A Simple Read Sector Function

Posted: Wed Mar 17, 2004 6:30 am
by ich_will
Here's the function that seems to work correct:

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
now i got another problem with FAT12 but I will open a new thread because this thread have a wrong title for the problem.

Re:A Simple Read Sector Function

Posted: Wed Mar 17, 2004 1:30 pm
by Neo
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.
That doesn't mean you need to start a new thread.(sorry not meaning to sound rude)

Re:A Simple Read Sector Function

Posted: Wed Mar 17, 2004 3:47 pm
by Pype.Clicker
Neo wrote: That doesn't mean you need to start a new thread.
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...

Re:A Simple Read Sector Function

Posted: Wed Mar 17, 2004 10:22 pm
by Neo
<chuckling> well at least i tried to keep things together</chuckling>