      DIM X%: REM use for loops
      DIM FLAG%(90): REM flag array to check for characters used
      DIM CHOICE$(4): REM use to hold computer's choices
      DIM MYCHOICE$(4): REM use to hold user's choices
      DIM HT%(4): REM use to hold four htab locations
      DIM VT%(16): REM use to hold 16 vtab locations

      GT$ = "LETTER FIND by Charlie Hartley"
      HOME
      INVERSE
      PRINT SPC (80);: REM print inverse spaces across screen
      VTAB 2: HTAB 1
      CALL CENTERLINE(GT$): REM center text
      PRINT GT$
      VTAB 3: HTAB 1
      PRINT SPC (80);
      NORMAL

      ! HTABs for responses
      FOR X% = 1 TO 4
        READ HT%(X%)
      NEXT
      DATA 29,31,33,35
      ! Routine placed here to sneak it in while opening screen is drawn.

      VTAB 5: HTAB 3
      PRINT "The object of this game is to determine which four alphabet letters that the"
      PRINT "computer has selected and put them in the same order as the computer has them."
      PRINT "You will have up to 16 chances to try and figure them out."

      VTAB 9: HTAB 3
      PRINT "If you select a letter that the computer has chosen, but it is not in the"
      PRINT "correct position, then a # will be displayed. If it is correct and in the"
      PRINT "correct position, then a * will be displayed. For example, if the computer has"
      PRINT "selected the letters A B C D and you select E A F D then the display will look"
      PRINT "like this --> E A F D # *"
      ! VTABS for responses
      FOR X% = 1 TO 16
        READ VT%(X%)
      NEXT
      DATA 1,3,5,7,9,11,13,15
      DATA 1,3,5,7,9,11,13,15

      VTAB 15: HTAB 3
      PRINT "The # tells you that one letter is correct, but in the wrong position"
      PRINT "(the A), and the * tells you that one letter is both correct and in the"
      PRINT "correct position (the D)."

      VTAB 19: HTAB 3
      PRINT "Only the letters A-Z may be used, and they may only appear once in a line."
      PRINT "If you attempt to enter a line like this: A B C A, the computer will sound an"
      PRINT "alarm and refuse to accept the second A."

      VTAB 23: HTAB 1
      GT$ = "Press a key to continue ..."
      CALL CENTERLINE(GT$)
      PRINT GT$

      CALL GETKEY(GT%)

      REPEAT% = 0: REM flag to determine if another game is requested.
      WHILE NOT REPEAT%

        HOME

        ! clear flags
        FOR X% = 65 TO 90
          FLAG%(X%) = 0
        NEXT

        ! get 4 random letters
        FOR X% = 1 TO 4
          GT% = 0
          WHILE NOT GT%
            R% = ( RND (1) * 90) + 1
            IF R% > 64 AND FLAG%(R%) = 0 THEN
              FLAG%(R%) = 1
              CHOICE$(X%) = CHR$ (R%)
              GT% = 1
            END IF
          WEND
        NEXT


        COUNT% = 1: REM begin getting input
        INVERSE
        VTAB 20: HTAB 1
        PRINT SPC (80);
        VTAB 21: HTAB 1
        GT$ = "# means a correct letter.   * means a correctly placed letter."
        CALL CENTERLINE(GT$)
        PRINT GT$
        VTAB 22: HTAB 1
        PRINT SPC (80);
        NORMAL

        DONE% = 0
        WHILE NOT DONE%
          VTAB 18: HTAB 3
          PRINT "Enter your four letters:  . . . ."
          ! clear flags
          FOR X% = 65 TO 90
            FLAG%(X%) = 0
          NEXT

          FOR X% = 1 TO 4
            OK% = 0
            WHILE OK% = 0

              CALL GETKEY(GT%)

              ! Check for ESCape key
              !  and exit if found
              IF GT% = 27 THEN
                HOME
                PRINT "Bye."
                END

              END IF

              ! Check for lowercase letters and
              !  replace with uppercase if needed.
              IF GT% > 90 THEN
                GT% = GT% - 32
              END IF

              ! Check to see if keypress is between A-Z
              IF GT% < 65 OR GT% > 90 THEN
                OK% = 0
              ELSE IF FLAG%(GT%) = 0 THEN
                FLAG%(GT%) = 1
                OK% = 1
                MYCHOICE$(X%) = CHR$ (GT%)
              END IF
            WEND

            VTAB 18: HTAB HT%(X%)
            PRINT MYCHOICE$(X%);
          NEXT

          ! Determine correct htab for this round

          IF COUNT% < 9 THEN
            HT% = 1
          ELSE IF COUNT% = 9 THEN
            HT% = 25
          ELSE IF COUNT% > 9 THEN
            HT% = 24
          END IF

          ! Print user's choices

          VTAB VT%(COUNT%)
          HTAB HT%
          PRINT COUNT%;". ";
          FOR X% = 1 TO 4
            PRINT MYCHOICE$(X%);" ";
          NEXT

          ! Check to see if user choices are correct.

          FOR X% = 1 TO 4
            FLAG%(X%) = 0
            IF MYCHOICE$(X%) = CHOICE$(X%) THEN
              FLAG%(X%) = 2: REM Correct and in correct place.
            ELSE
              FOR Y% = 1 TO 4
                IF MYCHOICE$(X%) = CHOICE$(Y%) THEN
                  FLAG%(X%) = 1: REM Correct, but in wrong place.
                END IF
              NEXT
            END IF
          NEXT

          YES% = 0
          FOR X% = 1 TO 4
            IF FLAG%(X%) = 1 THEN
              PRINT "# ";
            END IF
          NEXT

          FOR X% = 1 TO 4
            IF FLAG%(X%) = 2 THEN
              PRINT "* ";
              YES% = YES% + 1: REM Add one to correct count.
            END IF
          NEXT
          COUNT% = COUNT% + 1: REM Add one to round count.

          IF YES% = 4 THEN
            VTAB 18: HTAB 1
            PRINT CHR$ (29);: REM clear line
            PRINT "Congratuations! You did it!
            DONE% = 1
          ELSE IF COUNT% = 17 THEN
            VTAB 18: HTAB 1
            PRINT CHR$ (29);: REM clear line
            PRINT "Sorry, the correct letters are ";
            FOR X% = 1 TO 4
              PRINT " ";CHOICE$(X%);
            NEXT
            PRINT "."
            DONE% = 1
          END IF
        WEND
        FLAG% = 0
        WHILE NOT FLAG%
          VTAB 20: HTAB 1
          PRINT CHR$ (11);: REM clear to end of screen
          PRINT "Want to play again? (Y/N) ";
          PRINT CHR$ (6);: GET GT$
          IF GT$ = "Y" OR GT$ = "y" THEN
            REPEAT% = 0:FLAG% = 1
          ELSE IF GT$ = "N" OR GT$ = "n" THEN
            REPEAT% = 1:FLAG% = 1
          ELSE
            PRINT CHR$ (7);
            FLAG% = 0
          END IF
        WEND
      WEND
      HOME
      PRINT "Bye!"
      END

      SUB CENTERLINE(GT$)
      GT% = LEN (GT$)
      IF GT% > 80 THEN
        GT$ = "Line too long - contains " + STR$ (GT%) + " keystrokes.
        LIMITIS80."
      ELSE IF GT% < 80 THEN
        HOLD% = GT% / 2
        IF GT% <> (HOLD% * 2) THEN
          GT% = GT% + 1
        END IF
        HOLD% = (80 - GT%) / 2
        HOLD$ = "                                        ": REM 40 spaces
        GT$ = LEFT$ (HOLD$, HOLD%) + GT$ + LEFT$ (HOLD$, HOLD%)
      END IF
      END SUB

      ! If gt% = 80 then GT$ is returned unchanged.

      SUB GETKEY(GT%)
      PRINT CHR$ (6);
      WAIT $00C000, $80
      GT% = PEEK ($00C000) - $80
      POKE $00C010, 0
      END SUB
