home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / at / atfmt.asm < prev    next >
Assembly Source File  |  1994-03-04  |  5KB  |  154 lines

  1. ; ATFMT.ASM - low level hard disk format for PC-AT.
  2. ; Create DOSFM.COM as follows:
  3. ;    masm atfmt;
  4. ;    link atfmt;
  5. ;    exe2bin atfmt.exe atfmt.com
  6. ;    del atfmt.exe
  7.  
  8. cgroup    group    code
  9. code    segment
  10.     assume    cs:cgroup,ds:cgroup,es:cgroup
  11.  
  12.     org    100h
  13.  
  14. start:
  15.     jmp    init
  16.  
  17. ; Data
  18.  
  19. maxhead    db    ?
  20. maxcyl    dw    ?
  21.  
  22. head    db    0
  23. cyl    dw    0
  24.  
  25. warn    db    'Low-level hard disk format for AT.',13,10
  26.     db    'Are you sure you want to destroy your disk (y/n)? $'
  27. crlf    db    13,10,'$'
  28. diskerr    db    13,10,'Disk error, format aborted',13,10,'$'
  29.  
  30. init:
  31.     mov    dx,offset warn        ; print warning message
  32.     mov    ah,9
  33.     int    21h
  34.     mov    ah,1            ; wait for key to be hit
  35.     int    21h
  36.     push    ax            ; save the key
  37.     mov    dx,offset crlf        ; print new line
  38.     mov    ah,9
  39.     int    21h
  40.     pop    ax            ; get back the key
  41.     cmp    al,'y'            ; if Y or y, continue
  42.     je    continue
  43.     cmp    al,'Y'
  44.     jne    done
  45. continue:
  46.     mov    ah,8            ; get drive parameters
  47.     mov    dl,80h            ;  for drive c:
  48.     int    13h
  49.     jc    error
  50.     and    cl,0c0h            ; mask off max sector
  51.     mov    maxcyl,cx
  52.     mov    maxhead,dh
  53.  
  54. dotrack:
  55.     mov    dh,head            ; get head number
  56.     mov    cx,cyl            ; get cylinder number
  57.     mov    bx,offset buff        ; track interleave table address
  58.     mov    dl,80h            ; drive C
  59.     mov    ah,5            ; format track
  60.     int    13h            ; call bios
  61.     jc    error
  62.     
  63. ; Check for head overrun
  64.  
  65.     mov    dh,head
  66.     cmp    dh,maxhead        ; done all heads on one cylinder?
  67.     je    nextcyl            ; yes - go to next cylinder
  68.     inc    dh            ; no - go to next head
  69.     mov    head,dh
  70.     jmp    dotrack            ; and format next track
  71.  
  72. ; Check for cylinder overrun.  This is tricky since ch contains
  73. ; the low eight bits, and bits <7:6> of cl contain the high two bits.
  74.  
  75. nextcyl:
  76.     mov    head,dh
  77.     mov    head,0
  78.     mov    cx,cyl
  79.     cmp    cx,maxcyl        ; done all cylinders?
  80.     je    done            ; yes - we're done
  81.     inc    ch            ; low byte wrapped around?
  82.     jnz    nowrap            ; no, skip incrementing high byte
  83.     add    cl,40h            ; increment high two bits
  84. nowrap:
  85.     mov    cyl,cx            ; save new cylinder number
  86.     mov    dl,'.'            ; write a dot to screen
  87.     mov    ah,2            ;  to let them know we're
  88.     int    21h            ;  doing something
  89.     jmp    dotrack            ; go do next cylinder
  90.     
  91. error:
  92.     mov    dx,offset diskerr    ; print error message
  93.     mov    ah,9
  94.     int    21h
  95.     mov    ax,4c01h        ; error return
  96.     int    21h
  97.  
  98. done:    mov    ax,4c00h        ; normal return
  99.     int    21h
  100.     
  101.  
  102. ; Track interleave table.  Quoting from the COMPAQ 386 Technical
  103. ; Reference, page 9-14:
  104. ;    "The table contains 2 bytes per sector on the track.
  105. ;    The first byte is 0 if the sector is to be formatted
  106. ;    normally, or 80h if the sector is to be formatted bad.
  107. ;    The second byte is the logical sector number of the
  108. ;    sector..."dd" is a "don't care" byte used to make up a
  109. ;    total of 512 bytes."
  110. ; The table shown here is for an interleave factor of 2.
  111. ; Tables for other interleaves are left as an exercise for the reader.
  112.  
  113. buff    db    0,1,0,0ah,0,2,0,0bh,0,3,0,0ch
  114.     db    0,4,0,0dh,0,5,0,0eh,0,6,0,0fh
  115.     db    0,7,0,10h,0,8,0,11h,0,9
  116.     
  117.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  118.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  119.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  120.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  121.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  122.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  123.  
  124.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  125.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  126.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  127.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  128.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  129.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  130.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  131.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  132.  
  133.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  134.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  135.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  136.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  137.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  138.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  139.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  140.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  141.  
  142.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  143.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  144.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  145.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  146.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  147.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  148.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  149.     dw    0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh,0ddddh
  150.  
  151. code    ends
  152.  
  153.     end    start
  154.