PROGRAM SetEpsonPrinterModes;

(* This program was written in Turbo Pascal *)

(* Placed in the public domain on 30 March 1985 by Steve Calwas *)

VAR
  Choice           : BYTE;
  ExitProgram      : BOOLEAN;

(************************************************************************)

PROCEDURE MainMenu;

BEGIN
  CLRSCR;
  GOTOXY ( 29, 3 ); WRITELN ( 'Set-Print-Mode Utility' );
  GOTOXY ( 38, 4 ); WRITELN ( 'For' );
  GOTOXY ( 29, 5 ); WRITELN ( 'Epson MX/RX/FX Printers' );
  GOTOXY ( 10, 6 ); WRITELN ( '________________________________________________________________' );
  GOTOXY ( 15, 8 ); WRITELN ( 'PITCHES                      WEIGHTS' );
  WRITELN ( '            1 Elite                      7 Emphasized' );
  WRITELN ( '            2 Compressed                 8 Double-Strike' );
  WRITELN ( '            3 Pica                       9 Single-Strike *' );
  WRITELN ( '            4 Expanded (continuous)      A Near Letter-Quality (7 & 8)' );
  GOTOXY ( 15, 14 ); WRITELN ( 'MODES                        MISCELLANEOUS' );
  WRITELN ( '            5 Roman *                    B Master Reset (Also Sets TOF)' );
  WRITELN ( '            6 Italics                    C Quit; Return To CP/M' );
  GOTOXY ( 10, 18 ); WRITELN ( ' * Denotes Defaults on Power-Up and Master Reset' );
  GOTOXY ( 1, 21 ); WRITELN ( 'Your Choice:' );
END;  (* PROCEDURE MainMenu *)

(************************************************************************)

FUNCTION UserInput : BYTE;

CONST
  Bell             =  7 ;

VAR
  KeyStroke        : CHAR;
  ValidInput       : BOOLEAN;

BEGIN
  REPEAT
    ValidInput := TRUE;
    GOTOXY ( 14, 21 );
    CLREOL;
    READ( KBD, KeyStroke );
    KeyStroke := UPCASE( KeyStroke );
    IF ( KeyStroke >= '1' ) AND ( KeyStroke <= '9' ) THEN BEGIN
      UserInput := ORD( KeyStroke ) - ORD( '0' );
    END ELSE BEGIN
      IF ( KeyStroke >= 'A' ) AND ( KeyStroke <= 'C' ) THEN BEGIN
        (* Convert To Number Between 10..12 *)
        UserInput := ORD( KeyStroke ) - 55;
      END ELSE BEGIN
        ValidInput := FALSE;
        WRITELN ( CHR( Bell ) );
      END;
    END;
  UNTIL ValidInput;
END;  (* FUNCTION UserInput *)
(************************************************************************)

FUNCTION TurnExpandedOn : BOOLEAN;

CONST
  Bell             =  7 ;

VAR
  Response         : CHAR;
  ValidInput       : BOOLEAN;

BEGIN
  GOTOXY ( 1, 23 ); CLREOL;
  WRITELN ( 'Turn Expanded Mode ON? (Y/N)   (''N'' will turn Expanded Mode OFF)' );
  REPEAT
    ValidInput := TRUE;
    GOTOXY ( 30, 23 );
    READ ( KBD, Response );
    Response := UPCASE( Response );
    IF Response = 'Y' THEN BEGIN
      TurnExpandedOn := TRUE;
    END ELSE BEGIN
      IF Response = 'N' THEN BEGIN
        TurnExpandedOn := FALSE;
      END ELSE BEGIN
        ValidInput := False;
        WRITELN ( CHR( Bell ) );
      END;
    END;
  UNTIL ValidInput;
  GOTOXY ( 1, 23 ); CLREOL;
END;  (* FUNCTION TurnExpandedOn *)

(************************************************************************)

BEGIN
  MainMenu;
  ExitProgram := FALSE;
  REPEAT
    Choice := UserInput;
    GOTOXY ( 1, 23 );
    CASE Choice OF
      1 : BEGIN
            (* Elite *)
            WRITELN ( LST, CHR( 27 ), 'M' );
            WRITE ( 'ELITE' );
          END;
      2 : BEGIN
            (* Compressed *)
            (* Turn Off Elite And Emphasized *)
            WRITELN ( LST, CHR( 27 ), 'P', CHR( 27 ), 'F', CHR( 15 ) );
            WRITE ( 'COMPRESSED' );
          END;
      3 : BEGIN
            (* Pica *)
            (* Turn Off Elite, Emphasized, And Compressed *)
            WRITELN ( LST, CHR( 27 ), 'P', CHR( 27 ), 'F', CHR( 18 ) );
            WRITE ( 'PICA' );
          END;
      4 : BEGIN
            (* Continuous Expanded *)
            IF TurnExpandedOn THEN BEGIN
              WRITELN ( LST, CHR( 27 ), 'W1' );
              WRITE ( 'CONTINUOUS EXPANDED' );
            END ELSE BEGIN
              (* Turn Expanded Off *)
              WRITELN ( LST, CHR( 27 ), 'W0' );
              WRITE ( 'EXPANDED/OFF' );
            END;
          END;
      5 : BEGIN
            (* Roman *)
            (* Turn Italics Off *)
            WRITELN ( LST, CHR( 27 ), '5' );
            WRITE ( 'ROMAN CHARACTER' );
          END;
      6 : BEGIN
            (* Italics *)
            WRITELN ( LST, CHR( 27 ), '4' );
            WRITE ( 'ITALICS' );
          END;
      7 : BEGIN
            (* Emphasized *)
            (* Turn Elite Off *)
            WRITELN ( LST, CHR( 27 ), 'P', CHR( 27 ), 'E' );
            WRITE ( 'EMPHASIZED' );
          END;
      8 : BEGIN
            (* Double-Strike *)
            WRITELN ( LST, CHR( 27 ), 'G' );
            WRITE ( 'DOUBLE-STRIKE' );
          END;
      9 : BEGIN
            (* Single-Strike *)
            (* Turn Emphasized And Double-Strike Off *)
            WRITELN ( LST, CHR( 27 ), 'F', CHR( 27 ), 'H' );
            WRITE ( 'SINGLE-STRIKE' );
          END;
     10 : BEGIN
            (* Near Letter-Quality *)
            (* Turn Off Elite And Set Double-Strike And Emphasized *)
            WRITELN ( LST, CHR( 27 ), 'P', CHR( 27 ), 'G', CHR( 27 ), 'E' );
            WRITE ( 'LETTER-QUALITY' );
          END;
     11 : BEGIN
            (* Master Reset; Return Printer To Power Up Configuration *)
            WRITELN ( LST, CHR( 27 ), '@' );
            WRITE ( 'PRINTER RESET' );
          END;
     12 : BEGIN
            (* Quit; Return To CP/M *)
            ExitProgram := TRUE;
          END;
    END;  (* CASE *)
    IF NOT ExitProgram THEN BEGIN
      WRITE ( ' Mode Is Set...' ); CLREOL; WRITELN;
    END ELSE BEGIN
      CLREOL;
      WRITELN ( 'Leaving Printer Setup Utility...' );
    END;
  UNTIL ExitProgram;
END.  (* PROGRAM SetRX80PrinterModes *)
