IDENTIFICATION DIVISION.
PROGRAM-ID. TAPE-READER.
AUTHOR. Kevin Roper.
INSTALLATION. KEYHOLE HQ.
DATE-WRITTEN. 05/25/2020.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT CALCULATOR-TAPE ASSIGN TO "CALCULATOR-TAPE.DAT"
		ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD CALCULATOR-TAPE.
01 CALCULATION-RECORD.
   88 END-OF-CALC-FILE     VALUE HIGH-VALUES.
   02 F-OPERAND-A            PIC 9(8).
   02 F-OPERAND-B            PIC 9(8).
   02 F-OPERATOR             PIC A.
   02 F-ANSWER               PIC 9(16).
   02 F-ERROR-MESSAGE        PIC X(30).
   02 F-META-DATA.
       05 DATE-OF-CALCULATION.
           10 CALCULATION-YEAR     PIC 9(2).
           10 CALCULATION-MONTH    PIC 9(2).
           10 CALCULATION-DAY      PIC 9(2).

WORKING-STORAGE SECTION.
01 COMMAND         PIC A.
01 ERROR-MESSAGE   PIC X(30).
01 OPERAND-A       PIC 9(8).
01 OPERAND-B       PIC 9(8).
01 OPERATOR        PIC A.
01 ANSWER          PIC 9(16).

01 ERROR-MESSAGES.
       05 CLEARED-MESSAGE  PIC A(30) VALUE IS "                             ".
       05 OVERFLOW-MESSAGE PIC A(30) VALUE IS "ERROR: OVERFLOW              ".
       05 SIGN-MESSAGE     PIC A(30) VALUE IS "ERROR: LESS THAN ZERO        ".
       05 MISC-MESSAGE     PIC A(30) VALUE IS "ERROR: OTHER ERROR           ".

SCREEN SECTION.
01 MATH-SCREEN.
       05 BACKGROUND-COLOR 1 FOREGROUND-COLOR 7.
       05 LINE 1 COLUMN 30 VALUE "TAPE READER v0.1".
       05 LINE 10 COLUMN 5 VALUE "N=NEXT Q=QUIT".
       05 LINE 3 COLUMN 5 VALUE "OPERAND 1".
       05 LINE 4 COLUMN 5 VALUE "OPERAND 2".
       05 LINE 5 COLUMN 5 VALUE "OPERATOR".
       05 LINE 7 COLUMN 5 VALUE "ANSWER".
       05 LINE 9 COLUMN 5 VALUE "COMMAND".

       05 SCR-OPERAND-A LINE 3 COLUMN 20 PIC 9(8) FROM F-OPERAND-A.
       05 SCR-OPERAND-B LINE 4 COLUMN 20 PIC 9(8) FROM F-OPERAND-B.
       05 SCR-OPERATOR  LINE 5 COLUMN 20 PIC A FROM F-OPERATOR.
       05 SCR-ANSWER    LINE 7 COLUMN 20 PIC 9(16) FROM F-ANSWER.
       05 SCR-ERROR     LINE 8 COLUMN 20 PIC X(30) FROM F-ERROR-MESSAGE.
       05 SCR-COMMAND   LINE 9 COLUMN 20 PIC A TO COMMAND.

PROCEDURE DIVISION.
OPEN INPUT CALCULATOR-TAPE.
    READ CALCULATOR-TAPE
         AT END SET END-OF-CALC-FILE TO TRUE
    END-READ
    PERFORM UNTIL END-OF-CALC-FILE
       *>DISPLAY F-OPERAND-A SPACE F-OPERATOR SPACE F-OPERAND-B SPACE "=" F-ANSWER
       PERFORM SHOW-SCREEN UNTIL COMMAND="N"
       READ CALCULATOR-TAPE
            AT END SET END-OF-CALC-FILE TO TRUE
       END-READ
    END-PERFORM
    CLOSE CALCULATOR-TAPE
STOP RUN.

SHOW-SCREEN.
DISPLAY MATH-SCREEN.
ACCEPT MATH-SCREEN.