A Simple Read Sector Function

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Pype.Clicker
Member
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

Post by Pype.Clicker »

oops. I obviously misunderstood your point. Sorry ... ::)
ich_will

Re:A Simple Read Sector Function

Post 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.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:A Simple Read Sector Function

Post 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)
Only Human
User avatar
Pype.Clicker
Member
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

Post 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...
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:A Simple Read Sector Function

Post by Neo »

<chuckling> well at least i tried to keep things together</chuckling>
Only Human
Post Reply