! Dump packet (hex & ASCII)

%systemroutinespec phex2(%integer i)

%routine dump(%integer bytes, %bytename buffer)
   %integer i, j, k
      newline
      i = 0
      %while i < bytes %cycle
         %for j = 0, 1, 15 %cycle
            %if i + j >= bytes %then space %and space %c
                               %else phex2(byteinteger(addr(buffer) + j))
            space %if j & 3 = 3
         %repeat
         printstring(" [")
         write(i, -3)
         printstring("]  |")
         %for j = 0, 1, 15 %cycle
            %if j + i < bytes %start
               k = byteinteger(addr(buffer) + j) & 127
               %if k = 0 %start
                  k = '.'
               %else %unless ' ' <= k <= '~'
                  k = '_'
               %finish
               printsymbol(k)
            %else
               space
            %finish
         %repeat
         printsymbol('|')
         newline
         i = i + 16;  buffer == buffer [16]
      %repeat
      newline
%end

%routine sdump(%integer bytes, %bytename buffer)
   %integer i, j, k
      newline
      i = 0
      %while i < bytes %cycle
         %for j = 0, 2, 14 %cycle
            %if i + j >= bytes %then spaces(6) %c
                               %else write(shortinteger(addr(buffer) + j), 5)
         %repeat
         printstring("  [")
         write(i // 2, -3)
         printstring("]  |")
         %for j = 0, 1, 15 %cycle
            %if j + i < bytes %start
               k = byteinteger(addr(buffer) + j) & 127
               %if k = 0 %start
                  k = '.'
               %else %unless ' ' <= k <= '~'
                  k = '_'
               %finish
               printsymbol(k)
            %else
               space
            %finish
         %repeat
         printsymbol('|')
         newline
         i = i + 16;  buffer == buffer [16]
      %repeat
      newline
%end

%end %of %file
