home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / turbods / disk12.lbr / DISK.BAS next >
BASIC Source File  |  1986-09-27  |  5KB  |  158 lines

  1.  
  2. rem disk.bas    all system info on specified disk drive
  3. integer i,directory.entries
  4. real total.space,available.space
  5. string disk.free.space,percent.used
  6.  
  7. %include cbc
  8.  
  9. i= match(";",command$,1)
  10. if i>0 then operation$=ucase$(right$(command$,len(command$)-i))
  11. if i<1 then print.options%=-1
  12.  
  13. disk$=ucase$(left$(command$,1))
  14. if disk$<"A" or disk$>"P" then disk$=seldsk("")
  15. disk%=asc(disk$)-65
  16.        
  17. rem main code
  18. if match("L",operation$,1) then lprinter
  19.  
  20. print "DISK v1.1    "
  21. print tab(10);
  22. print using "Drive &: Characteristics";disk$:print
  23. print tab(10);
  24. print "Drive Status:      ";        
  25.  
  26.     call asm(050h,0,21,(-1*256)+disk%,0)    rem T21 get/set drive status
  27.     l%=mod(gethl,256)
  28.     if l%=0 then\
  29.         print "Not ready.":stop
  30.     
  31.     h%=gethl/256
  32.         if h%=-1 then print " :Read Only";
  33.         if h%= 0 then print " :Read/Write";
  34.  
  35.     call asm(050h,0,19,disk%,0)                 rem allocation info
  36.     s%=mod(getpsw,256)
  37.     fixed%=s%>=80h
  38.     s%=mod(s%,80h)
  39.     directory.blocks%=mod(getbc,256)
  40.     blocks.unused%=getde
  41.     total.blocks%=gethl
  42.     blocks.used%=total.blocks%-blocks.unused%
  43.     
  44.     block.size%=4                               rem default
  45.     if s%=3 then block.size%=1
  46.     if s%=4 then block.size%=2
  47.     if s%=5 then block.size%=4
  48.     if s%=6 then block.size%=8
  49.     if s%=7 then block.size%=16
  50.  
  51.     total.space=float(total.blocks%)*float(block.size%)
  52.     directory.entries=directory.blocks%*block.size%
  53.     directory.entries=directory.entries*32
  54.     
  55.     DISK.FREE.SPACE=STR$(float(blocks.unused%)*float(block.size%))
  56.  
  57.     call asm(050h,0,20,(-1*256)+disk%,0)    rem sector size call
  58.  
  59.     sx%=mod(getpsw,256)
  60.     if sx%=0 then sector.size%=128
  61.     if sx%=1 then sector.size%=256
  62.     if sx%=2 then sector.size%=512
  63.     if sx%=3 then sector.size%=1024
  64.     if sx%=4 then sector.size%=2048
  65.     if sx%=5 then sector.size%=4096
  66.     if sx%=6 then sector.size%=8192
  67.     if sx%=7 then sector.size%=16384
  68.     reserved.tracks%=getbc
  69.     num.tracks%=getde
  70.     num.sectors%=gethl
  71.      percent.used = str$(int(100-(blocks.used%/total.space*100)))
  72.      available.space=total.space-(block.size%*directory.blocks%)
  73.     
  74. print tab(55);
  75.     if fixed% then print "(Fixed media)" else print "(Removable media)"
  76.  
  77. print tab(10);
  78.     print "Total space         :";str$(total.space)+"k"
  79. print tab(10);
  80.      print "Useable file space  :";str$(available.space)+"k" 
  81. print tab(10);
  82.     print "Free space          :";disk.free.space+"k"
  83.     print
  84. print tab(10);
  85.     print "Sector size         :";str$(sector.size%)
  86. print tab(10);
  87.     print "Reserved tracks     :";str$(reserved.tracks%)
  88. print tab(10);
  89.     print "Tracks on disk      :";str$(num.tracks%)
  90. print tab(10);
  91.     print "Sectors/track       :";str$(num.sectors%)
  92. print tab(10);
  93.     print "Block size          :";str$(block.size%)+"k"
  94. print tab(10);
  95.     print "Directory blocks    :";str$(directory.blocks%)
  96. print tab(10);
  97.     print "Directory entries   :";str$(directory.entries)
  98. print tab(10);
  99.     print "Allocation Blocks   :";str$(total.blocks%)
  100. print tab(10);
  101.     print "Allocation blks used:";str$(blocks.used%)+"  ("+percent.used+"%)"
  102. print tab(10);
  103.     print "Allocation blks left:";str$(total.blocks%-blocks.used%)
  104. print
  105.     
  106. console
  107. if match("L",operation$,1) then \
  108.     print "Disk characteristics sent to printer."
  109. if match("M",operation$,1) then gosub fixmap
  110. if match("F",operation$,1) then gosub fixdir
  111.  
  112. if print.options% then\
  113.     print "Options      ;L      (send to printer)":\
  114.     print "             ;M      (rebuild disk map)":\
  115.     print "             ;F      (fix directory)"   
  116. stop    rem end prog
  117.  
  118. fixmap:
  119.     print
  120.     print "OK to regenerate disk map on drive ";disk$;":?  (Y/N) ";
  121.     input "";line answer$: answer$=ucase$(answer$)
  122.     if left$(answer$,1)<>"Y" then return
  123.     print "Regenerating map on drive ";disk$;":"
  124.     call asm(050h,0,11,(-1*256)+disk%,0)    rem regenerate map
  125.     a%=mod(getpsw,256)
  126.     if a%<>0 then print "Unable to regenerate disk map.": return
  127.  
  128.     if a%=0 then print "Disk map regenerated."
  129.  
  130.     call asm(050h,0,19,disk%,0)                 rem allocation info
  131.     new.blocks.unused%=getde
  132.     new.blocks.used%=total.blocks%-new.blocks.unused%
  133.     if new.blocks.used%=blocks.used% then return
  134.     if new.blocks.used%>blocks.used% then a$="gained" else a$="lost"
  135.     print abs(blocks.used%-new.blocks.used%);" allocation blocks ";a$
  136.     return
  137.  
  138.  
  139. fixdir:
  140.     print
  141.      print "It would be good to BACK UP drive ";+disk$+": before starting."
  142.     print "OK to reorganize directory on drive ";disk$;" (Y/N) ";
  143.     input "";line answer$:answer$=ucase$(answer$)
  144.     if left$(answer$,1)<>"Y" then return
  145.     print "Reorganizing directory on drive ";disk$;"- DO NOT INTERRUPT!";
  146.     call asm(050h,0,42,(-1*256)+disk%,0)    rem regenerate map
  147.     a%=mod(getpsw,256)
  148.     if a%<>0 then print "Unable to reorganize directory.": return
  149.  
  150.     if a%=0 then print "Directory reorganized."
  151.  
  152.     return
  153.     
  154.     
  155.  
  156.     
  157. rem ******************************
  158.