home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MISC / TNH_PC.ZIP / LAVIGNE.NL < prev    next >
Encoding:
Text File  |  1987-01-14  |  5.9 KB  |  188 lines

  1. Cleaning Disk Drive Heads
  2.  
  3.              Bruce LaVigne
  4.       Madison IBM PC Users Group
  5.  
  6. The disk cleaning program given below
  7. resulted from frustration with the
  8. "ring around the collar" syndrome.
  9. When cleaning our diskette drives, we
  10. went through the routine of inserting
  11. a cleaning disk in drive A and typing
  12. a command instructing DOS to access a
  13. file on the disk, thereby spinning
  14. the disk.  After about thirty seconds
  15. of (R)etries, according to cleaning
  16. kit instructions, we (A)borted this,
  17. and pulled out the cleaning disk out
  18. to find a nice dirty ring on track 0
  19. (where DOS searched in vain for the
  20. diskette directory), with the rest of
  21. the cleaning diskette as clean as
  22. when the package was opened.
  23.  
  24. In order to use more of the cleaning
  25. diskette (and to avoid retyping the
  26. "R(etry)" key for 30 seconds), I
  27. developed the following program. It
  28. uses the BIOS diskette interrupt to
  29. verify alternatively on tracks 0 and
  30. 39.  This is self-modifying code,
  31. where the program changes the
  32. instruction loading the track number.
  33. In this way, only immediate data
  34. types are used.  Initially the
  35. program was written in assembly code
  36. using DEBUG 2.0, then recoded into
  37. BASIC, since many people don't have
  38. the Macro Assembler.  The assembly
  39. code routine is stored in a string
  40. variable. The call is made indirectly
  41. through the string's VARPTR.  This
  42. has two advantages: the program can
  43. be easily modified at run time, as
  44. seen by the choice of drive to clean;
  45. and the the assembly routine does not
  46. have to be loaded from disk or
  47. specific memory space reserved for
  48. it.
  49.  
  50. The first listing is the BASIC
  51. program in RUNable form, followed by
  52. the assembly code for those who wish
  53. to see how it works.  It uses the DOS
  54. verify command, so even if you leave
  55. a regular diskette in the drive you
  56. won't trash any files.
  57.  
  58. 10 REM Disk Head Cleaning Program
  59. 20 REM Author: Bruce LaVigne
  60. 30 REM Written: 1/11/84 for the
  61.    Madison IBM PC User's Group
  62. 40 REM Consult your drive manufact-
  63.    urer for cleaning recommendations
  64. 50 DEF SEG : SCREEN 0,0,0,0 :
  65.    COLOR 7,0,0 : KEY OFF : CLS
  66. 60 LOCATE 1,26,0 : PRINT "*** DISK 
  67.    Head Cleaner ***"
  68. 70 CLEAN$ = "" : CHSUM = 0 : REM
  69.    initialize variables for reading
  70.    assembly
  71. 80 FOR I=0 TO 63 : REM read assembly
  72.    program into string
  73. 90 READ BYTE : CLEAN$ = CLEAN$ +
  74.    CHR$(BYTE) : CHSUM = CHSUM + BYTE
  75.    : NEXT I
  76. 100 READ CHECK : IF CHSUM <> CHECK
  77.     THEN PRINT "Bad checksum-retype
  78.     data" : END
  79. 110 LOCATE 4,1,1,0,13 : INPUT "Drive
  80.     to clean (A or B): ",DR$
  81. 120 DR$ = LEFT$(DR$,1) : DRV =
  82.     (ASC(DR$) AND &H5F) - 65 :
  83.     REM Compute Drive #
  84. 130 IF DRV < 0 OR DRV > 1 THEN BEEP
  85.     : GOTO 110
  86. 140 POINTER = VARPTR(CLEAN$) + 1 :
  87.     ASSEM = PEEK(POINTER) + 256*
  88.     PEEK(POINTER+1)
  89. 150 POKE ASSEM+13,DRV : REM set drive
  90.     number to clean
  91. 160 TADR = ASSEM + 11 : TADRH =
  92.     INT(TADR/256) : REM compute
  93.     relocation address
  94. 170 IF TADR > 32767 THEN TADR =
  95.     TADR - 65536!
  96. 180 TADRL = TADR AND &HFF
  97. 190 POKE ASSEM+44,TADRL : POKE
  98.     ASSEM+45,TADRH : REM put new
  99.     address pointer in
  100. 200 LOCATE 10,13,0 : COLOR 16,7
  101. 210 PRINT ">> Put cleaning disk in
  102.     drive ";DR$;": and press any key
  103.     <<"
  104. 220 A$ = INKEY$ : IF A$ = "" THEN 220
  105. 230 LOCATE 10,1 : COLOR 7,0 : PRINT
  106.     SPC(78)
  107. 240 LOCATE 10,30 : COLOR 31,0 : PRINT
  108.     "*** CLEANING ***" : COLOR 7,0
  109. 250 CALL ASSEM : REM call actual disk
  110.     routine
  111. 260 LOCATE 10,1 : PRINT SPC(78)
  112. 270 LOCATE 6,1 : INPUT "Clean another
  113.     disk (Y/N)";A$
  114. 280 A$ = LEFT$(A$,1) : IF A$ <> "Y"
  115.     AND A$ <> "y" THEN CLS : END
  116. 290 LOCATE 6,1 : PRINT SPC(78) :
  117.     GOTO 110
  118. 300 DATA 49,192,205,26,81,82,184,1,4,
  119.     185,1,0,186,0,0,205,19,49,192,205
  120.     ,26,60,0
  121. 310 DATA 91,88,80,83,116,7,129,195,
  122.     176,0,21,24,0,129,195,34,2,21,0,0
  123.     ,190,11,1
  124. 320 DATA 128,52,39,57,200,119,209,57,
  125. 211,119,205,88,88,49,192,205,19,203
  126. 330 DATA 5785 : REM checksum
  127. ******** ASSEMBLY LISTING *********
  128. 0930:0100 31C0     XOR    AX,AX
  129.        ; Use BIOS function call to
  130. 0930:0102 CD1A     INT    1A
  131.        ;  get the initial system time
  132. 0930:0104 51     PUSH   CX
  133.        ; Save high part of count
  134. 0930:0105 52     PUSH   DX
  135.        ; Save low part of count
  136. 0930:0106 B80104     MOV    AX,0401
  137.        ; Verify one sector
  138. 0930:0109 B90100     MOV    CX,0001
  139.        ; Track & sector (self-modify)
  140. 0930:010C BA0000     MOV    DX,0000
  141.        ; Head 0, Drive (BASIC modify)
  142. 0930:010F CD13     INT    13
  143.        ; Verify a track (0 or 39)
  144. 0930:0111 31C0     XOR    AX,AX
  145.        ; Get the time again
  146. 0930:0113 CD1A     INT    1A
  147.        ;  from the BIOS
  148. 0930:0115 3C00     CMP    AL,00
  149.        ; Check for day wraparound
  150. 0930:0117 5B     POP    BX
  151.        ; Recover initial time low
  152. 0930:0118 58     POP    AX
  153.        ; Recover initial time high
  154. 0930:0119 50     PUSH   AX
  155.        ; Save initial time high again
  156. 0930:011A 53     PUSH   BX
  157.        ; Save initial time low again
  158. 0930:011B 7407     JZ     0124
  159.        ; If not day wrap (from above)
  160. 0930:011D 81C3B000   ADD    BX,00B0
  161.        ; Adjust count for day wrap
  162. 0930:0121 151800     ADC    AX,0018
  163.        ; Carry the adjustment into AX
  164. 0930:0124 81C32202   ADD    BX,0222
  165.        ; Add the 30 second count
  166. 0930:0128 150000     ADC    AX,000x0
  167.        ; Carry the adjustment into AX
  168. 0930:012B BE0B01     MOV    SI,010B
  169.        ; Address of track in code
  170. 0930:012E 803427     XOR    BYTE PTR
  171. [SI],27; Flip between track 0 and 39
  172. 0930:0131 39C8     CMP    AX,CX
  173.        ; Time to go home?
  174. 0930:0133 77D1     JA     0106
  175.        ; Nope!
  176. 0930:0135 39D3     CMP    BX,DX
  177.        ; High ok, what about low?
  178. 0930:0137 77CD     JA     0106
  179.        ; Let's go back and try again
  180. 0930:0139 58     POP    AX
  181.        ; Toss time low
  182. 0930:013A 58     POP    AX
  183.        ; Toss time high
  184. 0930:013B 31C0     XOR    AX,AX
  185.        ; Reset the disk drive so
  186. 0930:013D CD13     INT    13
  187.        ; Next seek will be ok
  188.