{--------------------------------------------------------------}
{                         OverlayTest                          }
{                                                              }
{          Turbo Pascal overlay system demo program            }
{                                                              }
{                             by Jeff Duntemann                }
{                             Turbo Pascal V3.0                }
{                             Last update 2/1/86               }
{                                                              }
{    From the book, COMPLETE TURBO PASCAL, by Jeff Duntemann   }
{    Scott, Foresman & Co. (c) 1986,1987  ISBN 0-673-18600-8   }
{--------------------------------------------------------------}

PROGRAM OverlayTest;

VAR
  Quit   : Boolean;
  Number : Integer;


OVERLAY PROCEDURE One;

BEGIN
  Writeln('>>Hi!  Overlay procedure #1 at your service!')
END;


OVERLAY PROCEDURE Two;

BEGIN
  Writeln('>>Number Two here.  May I help you?')
END;


FUNCTION GetNumber : Integer;

VAR
  I  : Integer;
  OK : Boolean;

BEGIN
  REPEAT
    GotoXY(43,18);
    ClrEOL;
    Read(I);
    IF (I >= 0) AND (I <= 4) THEN OK := True ELSE
      BEGIN
        GotoXY(1,24);
        Writeln('Valid numbers are 0-4 only!');
        OK := False;
      END
  UNTIL OK;
  GetNumber := I
END;


OVERLAY PROCEDURE Three;

BEGIN
  Writeln('>>Numbah Three.  Whaddaya want?')
END;


OVERLAY PROCEDURE Four;

BEGIN
  Writeln('>>Four''s on line--lay some work on me!')
END;


BEGIN  { MAIN }
  CLRSCR;
  REPEAT
    GotoXY(1,18);
    WRITE('>>>Enter a Number from 1-4 or 0 to Quit: ');
    Number := GetNumber;
    IF Number = 0 THEN Quit := True ELSE
      BEGIN
        Quit := False;
        GotoXY(1,5); ClrEOL;
        CASE Number OF
          1 : One;
          2 : Two;
          3 : Three;
          4 : Four
        END
      END
  UNTIL Quit;
END.
