PROGRAM TST2;
VAR I,J,K:INTEGER;

FUNCTION WAITCHAR:INTEGER;
VAR I:INTEGER;
   FUNCTION INKEY:INTEGER;
   VAR I:BYTE;
   BEGIN INLINE ($B4/$08/$CD/$21/$88/$46/I); INKEY:=I;
   END; {INKEY}
BEGIN
   I:=INKEY;
   IF I=0 THEN WAITCHAR:=INKEY+256
   ELSE WAITCHAR:=I;
END; {WAITCHAR}

PROCEDURE RULE(I:INTEGER);
VAR J,K:INTEGER;
BEGIN
   GOTOXY(1,I);
   FOR J:=1 TO 8 DO WRITE(J:9,'0');
   GOTOXY(1,I+1);
   FOR J:=1 TO 7 DO BEGIN
      FOR K:=1 TO 4 DO WRITE(CHR(196));
      WRITE(CHR(194));
      FOR K:=1 TO 4 DO WRITE(CHR(196));
      WRITE(CHR(197));
   END;
   FOR K:=1 TO 4 DO WRITE(CHR(196));
   WRITE(CHR(194));
   FOR K:=1 TO 4 DO WRITE(CHR(196));
   WRITE(CHR(180));
END {RULE};

BEGIN
   FOR I:=2 TO 17 DO BEGIN
      K:=I*160;
      FOR J:=13 TO 79 DO MEM[$B800:K+J*2]:=J+52;
   END;
   RULE(1);
   I:=0;
   WHILE I<256 DO BEGIN
      GOTOXY(1,(I MOD 16)+3);
      WRITE(I:3);
      WRITE(' ');
      FOR J:=0 TO 7 DO BEGIN
         K:=7-J;
         IF ((($01 SHL K) AND I) <> 0) THEN WRITE('1') ELSE WRITE('0');
      END;
      K:=((I MOD 16)+2)*160+1;
      FOR J:=13 TO 79 DO MEM[$B800:K+J*2]:=I;
      IF (I MOD 16)=15
      THEN BEGIN
         GOTOXY(1,20);
         WRITE('Press ESCAPE to exit:');
         IF WAITCHAR=27 THEN I:=256
      END;
      I:=I+1;
      IF I=256 THEN I:=0;
   END;
END.
----------------------------}

