home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / directry / dos2bi.asm
Assembly Source File  |  1994-06-17  |  3KB  |  62 lines

  1.                ;Translates logical sector number in DX:AX to
  2.                ;BIOSsec, HeadNum and CylNum
  3.                ;---------------------------------------------
  4. DOS2BIOSsec    PROC      USES ax bx dx
  5.                ;DX:AX contains LogSec, which we'll need later
  6.                push      dx
  7.                push      ax
  8.                ;
  9.                ;Get BIOSsec: 
  10.                ;Sector =  1 + LogSector MOD SectorsPerTrack
  11.                ;--------------------------------------------
  12.                mov       bl,SecsPerTrac
  13.                xor       bh,bh          ;zero extend SecsPerTrac
  14.                div       bx             ;LogSec \ SecsPerTrac
  15.                mov       BIOSsec,dl     ;Remainder in DX.  We need only low 
  16.                                         ;byte because SecsPerTrac < 256.
  17.                inc       BIOSsec        ;Add 1
  18.                ;
  19.                ;Get HeadNum
  20.                ;Head = (LogSector \ SectorsPerTrack) MOD NumHeads
  21.                ;-------------------------------------------------
  22.                ;AX now contains (LogSec \ SecsPerTrac) from previous div
  23.                mov       bl,NumHeads    ;Divide by NumHeads
  24.                div       bl             ;Returns remainder in AH
  25.                mov       HeadNum,ah
  26.                ;
  27.                ;Get Cylinder
  28.                ;Cylinder = LogSector \ (SectorsPerTrack * NumHeads)
  29.                ;---------------------------------------------------
  30.                ;Multiply SecsPerTrac * NumHeads
  31.                mov       al,SecsPerTrac ;BL already contains NumHeads
  32.                mul       bl             ;Returns (SecsPerTrac*NumHeads) in AX
  33.                mov       bx,ax          ;Save it in BX
  34.                ;Restore LogSec to DX:AX
  35.                pop       ax
  36.                pop       dx
  37.                ;Divide LogSec by (SecsPerTrac*NumHeads)
  38.                div       bx             ;Returns quotient in AX
  39.                mov       CylNum,ax
  40.                ret
  41. DOS2BIOSsec    ENDP
  42. ;
  43. ReadSector     PROC NEAR
  44.           mov       ah,02h    ;BIOS Read Sector function
  45.           mov       al,1      ;Read one sector
  46.           mov       cx,CylNum
  47.           xchg      ch,cl     ;Put low byte of CylNum in ch
  48.           shl       cl,6      ;Move bits 0 & 1 to bits 6 & 7
  49.           add       cl,BIOSsec     ;(BIOSsec will not be more than 6 bits)
  50.           mov       dh,HeadNum
  51.           mov       dl,drive
  52.           cmp       dl,2           ;Is it a hard drive?
  53.           jb        ReadSector1
  54.           add       dl,7Eh         ;80h=C:, 81h=D:, etc.
  55. ReadSector1:
  56.           lea       bx,text        ;ES:BX points to text buffer
  57.           int       13h       ;BIOS Direct Disk Services
  58.           jc        goDOS
  59.           ret
  60. ReadSector     ENDP
  61. ;
  62.