{$m 8000,0,8000}

uses pstuff21;
var
 piece:array[0..10] of graftype;
 CH:CHAR;

procedure drawboard;
var
 lines:array[1..20] of string;
 i,ii:integer;
 XPOS,YPOS:INTEGER;
 CH:CHAR;
 WINDOW:WINDOWSCREEN;
begin
 lines[ 1]:='!------------------------?';
 lines[ 2]:='|........................|';
 lines[ 3]:='|.!---?.!--?.!--?.--=--..|';
 lines[ 4]:='|.|...|.|..|.|..|...|....|';
 lines[ 5]:='|.<---/.|..|.<-=/...|....|';
 lines[ 6]:='|.|.....\--/.|.|....|.S..|';
 lines[ 7]:='|........................|';
 lines[ 8]:='|........................|';
 lines[ 9]:='|......S........S........|';
 lines[10]:='|..........!?............|';
 lines[11]:='|..........\/............|';
 lines[12]:='|......|........|........|';
 lines[13]:='|......\--------/........|';
 lines[14]:='|........................|';
 lines[15]:='\------------------------/';
 lines[16]:='|........................|';
 lines[17]:='\----?!---------?!-------/';
 lines[18]:='|....||.........||.......|';
 lines[19]:='\----/\---------/\-------/';

 for i:=1 to 19 do
  for ii:=1 to length(lines[i]) do
   putscreen(doubleLOGIC,ii*8-8,i*7,piece[pos(lines[i][ii],'!-.?</=S|\')]);
              {PUT EACH PIECE ON THE LOGICAL SCREEN}

 XPOS:=0;YPOS:=0;
 RITE(1,1,'DEMO NO. 2  BY R. QUEZADA',FALSE);
 REPEAT
  SCANCODE:=0;
  IF KEYBUFFER THEN CH:=KEYHIT;  {IF A KEY WAS HIT, THEN READ THAT KEY}
  IF SCANCODE=72 THEN      {IF UP ARROW WAS HIT}
   DEC(YPOS,2)         {SUBTRACT TWO SCREEN LINES}
  ELSE IF SCANCODE=80 THEN {IF DOWN ARROW WAS HIT}
   INC(YPOS,2);        {ADD TWO SCREEN LINES}
  IF SCANCODE=75 THEN  {IF LEFT ARROW WAS HIT}
   DEC(XPOS,2)
  ELSE IF SCANCODE=77 THEN  {IF RIGHT ARROW WAS HIT}
   INC(XPOS,2);
  IF XPOS<0 THEN XPOS:=0
   ELSE IF XPOS>240-80 THEN XPOS:=240-80;
  IF YPOS<0 THEN YPOS:=0
  ELSE IF YPOS>100 THEN YPOS:=100;
  MOVEABLEWIN(XPOS,YPOS,WINDOW); {GET WINDOW FROM DOUBLELOGIC AT 'XPOS,YPOS'}
  WINDOWDISPLAY(48,16,WINDOW);   {SHOW WINDOW AT 48,16}
 UNTIL SCANCODE=1;     {QUIT IF ESC KEY IS HIT}
end;

var i:word;
begin
 LOADLETTERS('ALPHA.DAT');  {LOAD THE LETTERS FOR THE rite COMMAND}
 for i:=0 to screenlength do
  doublebackg[i]:=0;    {CLEAR BACKGROUND SCREEN}
 doubleLOGIC:=doubleBACKG;   {COPY BACKGROUND SCREEN TO LOGICAL SCREEN}
 LOCATELCD(0);               {MOVE SCREEN TO TOP}
 VIDEOMODE(4);               {SET GRAPHICS MODE}

 (*DEFINE SHAPES*)

 PIECE[0]:=NULL_GRAPH;  {ASSIGN A BLANK CHARACTER TO THIS ONE}

 piece[1,1]:=convert('........');
 piece[1,2]:=convert('........');
 piece[1,3]:=convert('.....XXX');
 piece[1,4]:=convert('....X...');
 piece[1,5]:=convert('...X..XX');
 piece[1,6]:=convert('...X.X..');
 piece[1,7]:=convert('...X.X..');

 piece[2,1]:=convert('........');
 piece[2,2]:=convert('........');
 piece[2,3]:=convert('XXXXXXXX');
 piece[2,4]:=convert('........');
 piece[2,5]:=convert('XXXXXXXX');
 piece[2,6]:=convert('........');
 piece[2,7]:=convert('........');

 piece[3,1]:=convert('........');
 piece[3,2]:=convert('........');
 piece[3,3]:=convert('........');
 piece[3,4]:=convert('...XX...');
 piece[3,5]:=convert('........');
 piece[3,6]:=convert('........');
 piece[3,7]:=convert('........');

 piece[4,1]:=convert('........');
 piece[4,2]:=convert('........');
 piece[4,3]:=convert('XXXX....');
 piece[4,4]:=convert('....X...');
 piece[4,5]:=convert('XXX..X..');
 piece[4,6]:=convert('...X.X..');
 piece[4,7]:=convert('...X.X..');

 piece[5,1]:=convert('...X.X..');
 piece[5,2]:=convert('...X.X..');
 piece[5,3]:=convert('...X.XXX');
 piece[5,4]:=convert('...X....');
 piece[5,5]:=convert('...X.XXX');
 piece[5,6]:=convert('...X.X..');
 piece[5,7]:=convert('...X.X..');

 piece[6,1]:=convert('...X.X..');
 piece[6,2]:=convert('...X.X..');
 piece[6,3]:=convert('XXX..X..');
 piece[6,4]:=convert('....X...');
 piece[6,5]:=convert('XXXX....');
 piece[6,6]:=convert('........');
 piece[6,7]:=convert('........');

 piece[7,1]:=convert('........');
 piece[7,2]:=convert('........');
 piece[7,3]:=convert('XXXXXXXX');
 piece[7,4]:=convert('........');
 piece[7,5]:=convert('XXXX.XXX');
 piece[7,6]:=convert('...X.X..');
 piece[7,7]:=convert('...X.X..');

 piece[8,1]:=convert('..XXXX..');
 piece[8,2]:=convert('.X....X.');
 piece[8,3]:=convert('X......X');
 piece[8,4]:=convert('X......X');
 piece[8,5]:=convert('X......X');
 piece[8,6]:=convert('.X....X.');
 piece[8,7]:=convert('..XXXX..');

 piece[9,1]:=convert('...X.X..');
 piece[9,2]:=convert('...X.X..');
 piece[9,3]:=convert('...X.X..');
 piece[9,4]:=convert('...X.X..');
 piece[9,5]:=convert('...X.X..');
 piece[9,6]:=convert('...X.X..');
 piece[9,7]:=convert('...X.X..');

 piece[10,1]:=convert('...X.X..');
 piece[10,2]:=convert('...X.X..');
 piece[10,3]:=convert('...X..XX');
 piece[10,4]:=convert('....X...');
 piece[10,5]:=convert('.....XXX');
 piece[10,6]:=convert('........');
 piece[10,7]:=convert('........');

 DRAWBOARD;
 VIDEOMODE(3);   {SET TO TEXT MODE}
end.