home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / latrobe / b / biodif.arc / FORMAT.DIF < prev    next >
Text File  |  1987-07-18  |  13KB  |  428 lines

  1.  
  2. ----------dsformat.asm
  3.     TITLE    DSFORMAT
  4. ;++
  5.  
  6. ----------format.asm
  7.     TITLE    FORMAT
  8. ;++
  9.  
  10. -----------------------------------------------
  11.  
  12. ----------dsformat.asm
  13. ;        If the /2 option is chosen, then the program
  14. ;        formats a double-sided disk.  
  15. ;
  16. ;        It automatically sets the /V option to request a volume label.
  17.  
  18. ----------format.asm
  19. ;        It automatically sets the /V option to request a volume label.
  20.  
  21. -----------------------------------------------
  22.  
  23. ----------dsformat.asm
  24. ;    RGT    17 Jan 1987    Modified to use hard disk information,
  25. ;                and to format double/sided disks.
  26. ;                Also split the program into smaller files.
  27. ;
  28.  
  29. ----------format.asm
  30. ;    RGT    17 Jan 1987    Modified to split the program into smaller files.
  31. ;
  32.  
  33. -----------------------------------------------
  34.  
  35. ----------dsformat.asm
  36. ;   Define some public symbols to aid in debugging
  37. ;
  38.     PUBLIC    START_DISK_FORMAT, INITIALIZE_FAT, WRITE_VOL_LABEL
  39.     PUBLIC    READY_DISKS, FORMAT_DISK, VERIFY_DISK_SECTORS
  40.     PUBLIC    WRITE_FAT_SECTORS_TO_DISK, COPY_RESERVED_SECTORS
  41.     PUBLIC    READ_SECTORS, WRITE_SECTORS, CHECK_SECTOR
  42.     PUBLIC    DISP_ERROR_AND_RET, WRITE_DISK_SECTORS, PROCESS_DISK_SECTORS
  43.     PUBLIC    READ_DISK_SECTORS, SETUP_CMD_BUF
  44.     PUBLIC    READ_HARD_DISK_CTL, READ_HARD_DISK_BLOCK
  45.     PUBLIC    PHYS_FMT_FLOPPY
  46. ;
  47. ;   Define the files to be included
  48.  
  49. ----------format.asm
  50. ;   Define the files to be included
  51.  
  52. -----------------------------------------------
  53.  
  54. ----------dsformat.asm
  55.     INCLUDE    DISKPAR.INC        ;Disk parameter information
  56.     INCLUDE    MSCALLS.INC        ;Define MS-DOS calls
  57.  
  58. ----------format.asm
  59.     INCLUDE    MSCALLS.INC        ;Define MS-DOS calls
  60.  
  61. -----------------------------------------------
  62.  
  63. ----------dsformat.asm
  64.     EXTRN    FAT_BUFFER:BYTE, PROG_END:ABS
  65.     EXTRN    READ_FILE:NEAR, WRITE_FILE:NEAR
  66.     EXTRN    BAT_BUFFER:BYTE, BAT_BUFFER_2:BYTE
  67.     EXTRN    BAT_BUFFER_3:BYTE, BAT_BUFFER_4:BYTE
  68. ;
  69. ;   Define the starting location for the program
  70.  
  71. ----------format.asm
  72.     EXTRN    READ_FILE:NEAR, WRITE_FILE:NEAR
  73. ;
  74. ;   Define some sizes for the floppy disks
  75. ;
  76. F_MAX_FAT_SECTORS    EQU    3        ;Assume 3 sectors per FAT
  77. F_MAX_NUM_FATS        EQU    2        ;2 FATs on disk
  78. F_SECTOR_SIZE        EQU    512        ;Sector size
  79. F_CLUSTER_SIZE        EQU    1        ;Cluster size
  80. F_MAX_SECT_PER_TRACK    EQU    10        ;Normal sectors
  81. F_MAX_SURFACES        EQU    1        ;Number of surfaces
  82. ;
  83. ;   Define some sizes for the hard disks
  84. ;
  85. H_MAX_FAT_SECTORS    EQU    6        ;Assume 3 sectors per FAT
  86. H_MAX_NUM_FATS        EQU    2        ;2 FATs on disk
  87. H_SECTOR_SIZE        EQU    512        ;Sector size
  88. H_CLUSTER_SIZE        EQU    4        ;Cluster size
  89. H_MAX_SECT_PER_TRACK    EQU    16        ;Normal sectors
  90. H_MAX_SURFACES        EQU    4        ;Number of surfaces
  91. ;
  92. ;   Define the starting location for the program
  93.  
  94. -----------------------------------------------
  95.  
  96. ----------dsformat.asm
  97.         DB    'Rainbow Double-Sided Disk Formatter Version 1.0.',CR,LF
  98.         DB    'Copyright 1987  Flame-Point Computer Products, Inc.',CR,LF
  99.         DB    CR,LF
  100.  
  101. ----------format.asm
  102.         DB    'Rainbow Disk Formatter Version 2.7.',CR,LF
  103.         DB    CR,LF
  104.  
  105. -----------------------------------------------
  106.  
  107. ----------dsformat.asm
  108. ;
  109. ;   Define the number of valid options
  110. ;
  111. NUM_VALID_OPTIONS    DB    6    ;Number of valid options
  112. ;
  113. ;   Define the symbols for the valid options
  114.  
  115. ----------format.asm
  116. ;   Start of buffer for reading in hard disk BAT information
  117. ;
  118. BAT_BUFFER    DB    0        ;First byte of BAT buffer
  119. BAT_BUFFER_2    DB    0        ;Second byte of BAT buffer
  120. BAT_BUFFER_3    DB    0        ;Third byte of BAT buffer
  121. BAT_BUFFER_4    DB    0        ;Fourth byte of BAT buffer
  122.         DB    7164 DUP(0)    ;Rest of BAT buffer
  123. ;
  124. ;   Define the number of valid options
  125. ;
  126. NUM_VALID_OPTIONS    DB    5    ;Number of valid options
  127. ;
  128. ;   Define the symbols for the valid options
  129.  
  130. -----------------------------------------------
  131.  
  132. ----------dsformat.asm
  133. FOPT_DOUBLE    EQU    020H        ;Option is /2 (double-sided)
  134. ;
  135.  
  136. ----------format.asm
  137. ;
  138.  
  139. -----------------------------------------------
  140.  
  141. ----------dsformat.asm
  142. VALID_OPTIONS        DB    '2CIOVS' ;Valid options for format
  143. ;
  144.  
  145. ----------format.asm
  146. VALID_OPTIONS        DB    'CIOVS'    ;Valid options for format
  147. ;
  148.  
  149. -----------------------------------------------
  150.  
  151. ----------dsformat.asm
  152. ;   Disk parameter buffer for single-sided floppy disk drive
  153. ;
  154. F1_DISK_PARAM    DW    F_SECTOR_SIZE        ;Sector size of disk
  155.         DB    F_CLUSTER_SIZE        ;Cluster size of disk
  156.         DW    F_NUM_RESERVED_SECT    ;Number of reserved sectors
  157.         DB    F_MAX_NUM_FATS        ;Number of FATs on disk
  158.         DW    F_NUM_DIR_ENTRIES    ;Number of directory entries
  159.         DW    F_NUM_SECTORS_TOTAL    ;Number of sectors on disk
  160.         DB    F_DISK_MEDIA_TYPE    ;Disk media type code
  161.         DW    F_MAX_FAT_SECTORS    ;Number of FAT sectors
  162.         DW    F_MAX_SECT_PER_TRACK    ;Number of sectors per track
  163.         DW    F_MAX_SURFACES        ;Number of surfaces
  164.         DW    0            ;Unknown
  165. ;
  166. ;   Disk parameter buffer for double-sided floppy disk drive
  167. ;
  168. F2_DISK_PARAM    DW    F2_SECTOR_SIZE        ;Sector size of disk
  169.         DB    F2_CLUSTER_SIZE        ;Cluster size of disk
  170.         DW    F2_NUM_RESERVED_SECT    ;Number of reserved sectors
  171.         DB    F2_MAX_NUM_FATS        ;Number of FATs on disk
  172.         DW    F2_NUM_DIR_ENTRIES    ;Number of directory entries
  173.         DW    F2_NUM_SECTORS_TOTAL    ;Number of sectors on disk
  174.         DB    F2_DISK_MEDIA_TYPE    ;Disk media type code
  175.         DW    F2_MAX_FAT_SECTORS    ;Number of FAT sectors
  176.         DW    F2_MAX_SECT_PER_TRACK    ;Number of sectors per track
  177.         DW    F2_MAX_SURFACES        ;Number of surfaces
  178.         DW    0            ;Unknown
  179. ;
  180. ;   Disk parameter buffer for source disk drive, if hard disk
  181.  
  182. ----------format.asm
  183. ;   Disk parameter buffer for floppy disk drive
  184. ;
  185. FLOPPY_DISK_PARAM    DW    F_SECTOR_SIZE    ;Sector size of disk
  186.             DB    F_CLUSTER_SIZE    ;Cluster size of disk
  187.             DW    20        ;Number of reserved sectors
  188.             DB    F_MAX_NUM_FATS    ;Number of FATs on disk
  189.             DW    96        ;Number of directory entries
  190.             DW    800        ;Number of sectors on disk
  191.             DB    0FAH        ;Disk media type code
  192.             DW    F_MAX_FAT_SECTORS
  193.                         ;Number of FAT sectors
  194.             DW    F_MAX_SECT_PER_TRACK
  195.                         ;Number of sectors per track
  196.             DW    F_MAX_SURFACES    ;Number of surfaces
  197.             DW    0        ;Unknown
  198. ;
  199. ;   Disk parameter buffer for source disk drive, if hard disk
  200.  
  201. -----------------------------------------------
  202.  
  203. ----------dsformat.asm
  204.     MOV    SI,OFFSET F1_DISK_PARAM    ;Get the address of the disk
  205.                     ;parameter block for floppies
  206.     CMP    AL,3            ;See if floppy disk
  207.  
  208. ----------format.asm
  209.     MOV    SI,OFFSET FLOPPY_DISK_PARAM    ;Get the address of the disk
  210.                         ;parameter block for floppies
  211.     CMP    AL,3            ;See if floppy disk
  212.  
  213. -----------------------------------------------
  214.  
  215. ----------dsformat.asm
  216.     MOV    SI,OFFSET F1_DISK_PARAM    ;Get the address of the disk
  217.                     ;parameter block for floppies
  218.     CMP    DISK_TO_FORMAT,3    ;Check disk to be formatted
  219.  
  220. ----------format.asm
  221.     MOV    SI,OFFSET FLOPPY_DISK_PARAM    ;Get the address of the disk
  222.                         ;parameter block for floppies
  223.     CMP    DISK_TO_FORMAT,3    ;Check disk to be formatted
  224.  
  225. -----------------------------------------------
  226.  
  227. ----------dsformat.asm
  228. ;   Formatting a floppy disk  --  see if double-sided
  229. ;
  230.     TEST    WORD PTR OPTION_MASK,FOPT_DOUBLE
  231.                     ;See if double-sided disk
  232.     JZ    FMT_FLOPPY_DISK        ;If not, get address of buffer area
  233.     MOV    SI,OFFSET F2_DISK_PARAM    ;Otherwise, get the address of the disk
  234.                     ;parameter block for double-sided
  235.                     ;floppy disks
  236. FMT_FLOPPY_DISK:
  237.  
  238. ----------format.asm
  239. ;   Formatting a floppy disk
  240. ;
  241. FMT_FLOPPY_DISK:
  242.  
  243. -----------------------------------------------
  244.  
  245. ----------dsformat.asm
  246. ;   Now get the disk control information and store it in parameter block
  247. ;
  248.     PUSH    SI            ;Save reg DI
  249.     MOV    SI,TARGET_PARAM_ADR    ;Get address of disk parameter buffer
  250.     MOV    AX,HOM_SECPERTRK[BX]    ;Get number of sectors per track
  251.     MOV    DP_SECT_PER_TRACK_OFF[SI],AX    ;And store this information
  252.     MOV    AX,HOM_SECSIZE[BX]    ;Get sector size
  253.     MOV    DP_SECTOR_SIZE_OFF[SI],AX    ;And store this information
  254.     MOV    AL,HOM_NOSURFACE[BX]    ;Get number of surfaces
  255.     CBW                ;Convert to word
  256.     MOV    DP_NUM_SURFACES_OFF[SI],AX    ;And store this information
  257.     POP    SI            ;Restore reg DI
  258. ;
  259. ;   Now read in the DPD blocks
  260.  
  261. ----------format.asm
  262. ;   Now read in the DPD blocks
  263.  
  264. -----------------------------------------------
  265.  
  266. ----------dsformat.asm
  267.     MOV    CX,(BAT_NUM_BYTES/2)    ;Set count to number of words
  268.                     ;in rest of block
  269.  
  270. ----------format.asm
  271.     MOV    CX,250            ;Set count to number of words
  272.                     ;in rest of block
  273.  
  274. -----------------------------------------------
  275.  
  276. ----------dsformat.asm
  277.     ADD    BAT_BUFFER_ADR,BAT_NUM_BYTES
  278.                     ;Increment address to end of block read
  279.     MOV    BX,BAT_BUFFER_ADR    ;Get new address of block
  280.     INC    AL            ;Increment sector number
  281.     MOV    SI,TARGET_PARAM_ADR    ;Get address of target disk parameters
  282.     CMP    AL,DP_SECT_PER_TRACK_OFF[SI]    ;Compare sector number to
  283.                         ;number of sectors per track
  284.     JLE    READ_BAT_BLOCK_CONTINUE    ;If less, then go on to next sector
  285.     INC    DX            ;Otherwise, increment track number
  286.     MOV    AL,1            ;And set to sector 1 of track
  287. READ_BAT_BLOCK_CONTINUE:
  288.     DEC    NUM_BAT_SECTORS        ;Decrement count of sectors to read
  289.  
  290. ----------format.asm
  291.     ADD    BAT_BUFFER_ADR,001F4H    ;Increment address to end of block read
  292.     MOV    BX,BAT_BUFFER_ADR    ;Get new address of block
  293.     INC    AL            ;Increment sector number
  294.     DEC    NUM_BAT_SECTORS        ;Decrement count of sectors to read
  295.  
  296. -----------------------------------------------
  297.  
  298. ----------dsformat.asm
  299. ;
  300. ;   Now convert track number into cylinder and track number
  301. ;
  302.     MOV    BX,TARGET_PARAM_ADR    ;Get address of disk parameter buffer
  303.     MOV    AX,DX            ;Move track number into reg AX
  304.     XOR    DX,DX            ;Clear upper word
  305.     DIV    WORD PTR DP_NUM_SURFACES_OFF[BX]
  306.                     ;Divide by number of surfaces
  307.     MOV    DIRECT_CMD_TRACK,AX    ;Store track to be read
  308. ;
  309. ;   Combine the surface number with the drive number
  310. ;
  311.     MOV    AX,DX            ;Get surface to be read
  312.     OR    AL,40H            ;Set to physical disk
  313.     MOV    DIRECT_CMD_PHYS_UNIT,AL    ;Store physical unit number
  314. ;
  315. ;   Now set up the call to MS-DOS to format the track
  316.  
  317. ----------format.asm
  318.     MOV    AX,DX            ;Get disk to be formatted
  319.     AND    AL,3            ;Mask out all but lower 2 bytes
  320.     OR    AL,40H            ;Set to physical disk
  321.     MOV    DIRECT_CMD_PHYS_UNIT,AL    ;Store physical unit number
  322.     SHR    DX,1            ;Shift out head from track number
  323.     SHR    DX,1
  324.     MOV    DIRECT_CMD_TRACK,DX    ;Store track to be formatted
  325.     MOV    CX,14            ;Set number of bytes
  326. ;
  327. ;   Now set up the call to MS-DOS to format the track
  328.  
  329. -----------------------------------------------
  330.  
  331. ----------dsformat.asm
  332.     MOV    SI,TARGET_PARAM_ADR    ;Otherwise, Get address of
  333.                     ;target disk parameters
  334.     MOV    CX,DP_SECTOR_SIZE_OFF[SI]    ;Get sector size of target disk
  335.     SHR    CX,1            ;Divide by 2 to get no. of words
  336.     MOV    SI,BX            ;Get address of buffer
  337.     XOR    BX,BX            ;Clear checksum
  338.  
  339. ----------format.asm
  340.     MOV    SI,BX            ;Otherwise, get address of buffer
  341.     MOV    CX,H_SECTOR_SIZE / 2    ;Get number of words in block
  342.     XOR    BX,BX            ;Clear checksum
  343.  
  344. -----------------------------------------------
  345.  
  346. ----------dsformat.asm
  347.     MOV    DIRECT_CMD_DRIVE,0FFH    ;Set physical drive
  348.     SHL    AX,1            ;Shift drive to upper limit
  349.     SHL    AX,1
  350.     SHL    AX,1
  351.     SHL    AX,1
  352.     MOV    DIRECT_CMD_PHYS_UNIT,AL    ;Store drive to be formatted
  353.     MOV    AX,BORROWED_MEM_START    ;Get offset to format buffer
  354.  
  355. ----------format.asm
  356.     MOV    DIRECT_CMD_DRIVE,AL    ;Store drive to be formatted
  357.     MOV    AX,BORROWED_MEM_START    ;Get offset to format buffer
  358.  
  359. -----------------------------------------------
  360.  
  361. ----------dsformat.asm
  362. ;
  363. ;   Formatted side zero of disk  --  if error, then just return
  364. ;
  365.     JC    PHYS_FMT_FLOPPY_RET    ;If error, return it
  366. ;
  367. ;   Formatted size zero of disk  --  see if double-sided disk
  368. ;
  369.     MOV    SI,TARGET_PARAM_ADR    ;Get address of disk parameter buffer
  370.     CMP    WORD PTR DP_NUM_SURFACES_OFF[SI],F2_MAX_SURFACES
  371.                     ;See if double-sided
  372.     JNZ    PHYS_FMT_FLOPPY_RET    ;If not, just return
  373. ;
  374. ;   Double-sided disk  --  format second side
  375. ;
  376.     MOV    DIRECT_CMD_CMD,3    ;Set command to format track
  377.     MOV    AL,DISK_TO_FORMAT    ;Get drive to be formatted
  378.     AND    AL,3            ;Mask out all but lower 2 bits
  379.     MOV    DIRECT_CMD_DRIVE,0FFH    ;Set physical drive
  380.     SHL    AX,1            ;Shift drive to upper limit
  381.     SHL    AX,1
  382.     SHL    AX,1
  383.     SHL    AX,1
  384.     OR    AX,1            ;OR in second side
  385.     MOV    DIRECT_CMD_PHYS_UNIT,AL    ;Store drive to be formatted
  386.     MOV    AX,BORROWED_MEM_START    ;Get offset to format buffer
  387.     MOV    DIRECT_CMD_BUF_OFFSET,AX    ;Store it in format command buffer
  388.     MOV    DIRECT_CMD_BUF_SEGMENT,0    ;Set segment of format buffer to zero
  389.     MOV    DIRECT_CMD_TRACK,0FFH    ;Set track number (all tracks)
  390.     MOV    DIRECT_CMD_SECTOR,0    ;Set sector number to zero
  391.     MOV    DIRECT_CMD_COUNT,0    ;Set sector count to zero
  392.     MOV    BX,OFFSET DIRECT_CMD_BUF    ;Get address of format command buffer
  393.     FLOPPY_DIRECT            ;Call direct floppy interrupt
  394.                     ;to perform the call
  395. ;
  396. ;   Done with format  --  return to caller
  397. ;
  398. PHYS_FMT_FLOPPY_RET:
  399.     RET                ;And return to caller
  400. ;
  401. SCODE    ENDS                ;End of segment
  402.  
  403. ----------format.asm
  404.     RET                ;And return to caller
  405. ;
  406.  
  407. ;
  408. ;   Define the end of the program as a large buffer for formatting
  409. ;    Make it long enough to hold all sectors of the maximum number
  410. ;    of FATs.
  411. ;
  412. FAT_BUFFER_SIZE    EQU    H_MAX_NUM_FATS * H_MAX_FAT_SECTORS * H_SECTOR_SIZE
  413. FAT_BUFFER    DB    FAT_BUFFER_SIZE DUP (0)    ;Buffer for FAT sectors
  414. ;
  415. ;   Define a symbol for the end of the program
  416. ;
  417. PROG_END    EQU    $        ;End of program
  418. ;
  419. SCODE    ENDS                ;End of segment
  420.  
  421. -----------------------------------------------
  422.  
  423. ----------dsformat.asm
  424.  
  425. ----------format.asm
  426.     END    PROG_START
  427.     RET                ;And return to caller
  428.