{$R-}    {Range checking off}
{$B+}    {Boolean complete evaluation on}
{$S+}    {Stack checking on}
{$I+}    {I/O checking on}
{$N-}    {No numeric coprocessor}
{$M 65500,16384,655360} {Turbo 3 default stack and heap}

PROGRAM SLIDSHOW;


Uses
  Crt, {Unit found in TURBO.TPL}
  Graph3; {Unit found in GRAPH3.TPU}

CONST
PICTURESIZE=15924;

TYPE
PICTURETYPE = ARRAY[1..PICTURESIZE]OF INTEGER;
PICTUREPOINT = ^PICTURETYPE;
NAMETYPE=STRING[14];

VAR
PICTURE:PICTUREPOINT;
PICTUREFILE:FILE OF PICTURETYPE;
PICNAME:NAMETYPE;
SWITCH,FIRST:BOOLEAN;
UTILCHAR:CHAR;
NEWMODE,OLDMODE:INTEGER;
IPOS:INTEGER;
ITSTHERE,OVERRIDE:BOOLEAN;

{============================================================================}
PROCEDURE MODESELECT;
BEGIN

IF NEWMODE=1 THEN GRAPHCOLORMODE
ELSE IF NEWMODE=2 THEN
BEGIN
  HIRES;
  HIRESCOLOR(YELLOW);
END
ELSE GRAPHMODE;

OLDMODE:=NEWMODE;

END;
{============================================================================}
FUNCTION EXIST(FILNAME:NAMETYPE):BOOLEAN;
VAR
FIL:FILE;
SWITCH:BOOLEAN;

BEGIN
ASSIGN(FIL,FILNAME);
{$I-}
RESET(FIL);
{$I+}
SWITCH:=(IORESULT=0);
{! 1. IOR^esult now returns different values corresponding to DOS error codes.}
IF SWITCH THEN CLOSE(FIL);
EXIST:=SWITCH;
END;
{============================================================================}
BEGIN

OLDMODE:=99;{** NO SUCH MODE **}
NEW(PICTURE);{** BIG ARRAY IS ALLOCATED TO HEAP **}
OVERRIDE:=FALSE;

REPEAT

REPEAT

 CLRSCR;

  WRITELN;
  WRITE('ENTER PICTURE FILE NAME  ');

  READLN(PICNAME);
  IPOS:=POS('.',PICNAME);

  IF IPOS=0 THEN
  BEGIN
    PICNAME:=PICNAME+'.PIC';
    IPOS:=POS('.',PICNAME);
  END;

  IF((IPOS>9)AND(PICNAME[2]<>':')) THEN
             PICNAME:=COPY(PICNAME,1,8)+'.PIC'

  ELSE IF((IPOS>11)AND(PICNAME[2]=':')) THEN
             PICNAME:=COPY(PICNAME,1,8)+'.PIC'

  ELSE IF IPOS=LENGTH(PICNAME)THEN
            PICNAME:=COPY(PICNAME,1,LENGTH(PICNAME)-1);

  ITSTHERE:=EXIST(PICNAME);

  IF NOT(ITSTHERE)THEN
  BEGIN

    WRITELN;
    WRITELN(PICNAME,' DOES NOT EXIST. HIT <SPACE> TO CONTINUE');

    REPEAT
      UTILCHAR:=READKEY;
{! 2. USE T^URBO3 unit for access to KBD, or instead USE CRT and ReadKey.}
    UNTIL(UTILCHAR=' ');

  END;

UNTIL(ITSTHERE);

ASSIGN(PICTUREFILE,PICNAME);
RESET(PICTUREFILE);

SWITCH:=TRUE;
FIRST:=TRUE;

WHILE (SWITCH)DO
BEGIN

  READ(PICTUREFILE,PICTURE^);

  NEWMODE:=PICTURE^[PICTURESIZE];

  IF OVERRIDE THEN NEWMODE:=OLDMODE;

  IF((NEWMODE<>OLDMODE)OR(FIRST)) THEN MODESELECT;

  PUTPIC(PICTURE^,0,199);
  IF EOF(PICTUREFILE) THEN RESET(PICTUREFILE);
  FIRST:=FALSE;
  REPEAT

    UTILCHAR:=' ';
    UTILCHAR:=READKEY;
{! 3. USE^ TURBO3 unit for access to KBD, or instead USE CRT and ReadKey.}

    IF UPCASE(UTILCHAR)='C' THEN
    BEGIN
      GRAPHCOLORMODE;
      PUTPIC(PICTURE^,0,199);
      OVERRIDE:=TRUE;
      OLDMODE:=1;
    END
    ELSE IF UPCASE(UTILCHAR)='M' THEN
    BEGIN
      GRAPHMODE;
      PUTPIC(PICTURE^,0,199);
      OVERRIDE:=TRUE;
      OLDMODE:=3;
    END
    ELSE IF UPCASE(UTILCHAR)='T' THEN
    BEGIN
      TEXTMODE(CO80);
{! 4. The Text^mode procedure requires a parameter (Mode:Word) in Turbo 5.0.}
      PUTPIC(PICTURE^,0,199);
      OVERRIDE:=TRUE;
      OLDMODE:=99;
    END
    ELSE IF UPCASE(UTILCHAR)='H' THEN
    BEGIN
      HIRES;
      PUTPIC(PICTURE^,0,199);
      OVERRIDE:=TRUE;
      OLDMODE:=2;
    END
    ELSE IF UPCASE(UTILCHAR)='R' THEN
    BEGIN
      NEWMODE:=PICTURE^[PICTURESIZE];
      OVERRIDE:=FALSE;
      MODESELECT;
      PUTPIC(PICTURE^,0,199);
    END;


  UNTIL NOT (UPCASE(UTILCHAR) IN ['C','M','R','T','H']);

  IF(UPCASE(UTILCHAR)='Q')THEN SWITCH:=FALSE;

END;

CLOSE(PICTUREFILE);
TEXTMODE(CO80);
{! 5. Th^e Textmode procedure requires a parameter (Mode:Word) in Turbo 5.0.}
WRITELN;
WRITE('ANOTHER PICTURE FILE ? ''Y''=YES, ''N''=NO ');

REPEAT
  UTILCHAR:=READKEY;
{! 6. U^SE TURBO3 unit for access to KBD, or instead USE CRT and ReadKey.}
UNTIL UPCASE(UTILCHAR) IN ['Y','N'];

UNTIL(UPCASE(UTILCHAR)<>'Y');

CLRSCR;

END.
