%include "Inc:UTIL.IMP"

%constinteger first partition = 1, last partition = 3

%routine do map (%integer first part, last part)
   %bytename bm
   %integer s, l, i, j, total, bitmap size, which
   %string(127) command = "", output
   %byte x
   %for which = first part, 1, last part %cycle
      newlines (2)
      connect file("$:BITMAP." . to string(which + '0'), 0, s, bitmap size)
      printstring("Partition ");  write(which, 0)
      printstring(" (size ");  write(bitmap size * 8, 0)
      printstring("):")
      bm == byteinteger(s)
      total = 0
      %for i = 0, 1, bitmap size - 1 %cycle
         x = bm [i]
         %for j = 0, 1, 7 %cycle
            total = total + 1 %if x & 1 # 0
            x = x >> 1
         %repeat
      %repeat
      print(100 * total / (bitmap size << 3), 3, 3)
      printstring("% used")
      newline
      %for i = 0, 1, bitmap size - 1 %cycle
         %if i & 7 = 0 %start
            phex4(i << 3)
            printstring(":  ")
         %finish
         x = bm [i]
         %for j = 0, 1, 7 %cycle
            %if x & 1 = 0 %then space %c
                          %else print symbol('*') %and total = total + 1
            x = x >> 1
         %repeat
         newline %if i & 7 = 7
      %repeat
      newline %if i & 7 # 7
   %repeat
%end

%begin
   %integer p
      %on 9 %start;  %stop;  %finish
      prompt("Partition: ")
      read(p) %until first partition <= p <= last partition
      do map(p, p)
%end %of %program
