! Dump packet (hex & ASCII)

%systemroutinespec phexx2 %alias "phex2" (%integer i)

%routine dump(%bytename buffer, %integer bytes)
   %integer i, j, k
      %return %if bytes <= 0
      newline
      i = 0
      %while i < bytes %cycle
         print symbol('[')
         write(i, -4)
         printstring("]  ")
         %for j = 0, 1, 15 %cycle
            %if i + j >= bytes %then space %and space %c
                               %else phexx2(byteinteger(addr(buffer) + j))
            space %if j & 3 = 3
         %repeat
         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
