;*; Updated on 13-Jan-92 at 1:00 PM by Michele Tonti; edit time: 0:00:07
;************************************
; SETUP - SetUp some JOB attributes
;
; by Dave Heyliger - AMUS Staff
;    for AAA December '86
;************************************

       SEARCH  SYS                     ;search AM universals
       SEARCH  SYSSYM
       SEARCH  TRM

       SEARCH  STSWRD                  ;and our own universal

;Define a PRINT TAB(#,#) MACRO - we've seen this before...
DEFINE  PRTTAB  AA,BB                   ;PRINT TAB(#,#)
       MOVB    #'AA,D1                 ;get first #
       LSLW    D1,#10                  ;shift left 8. bits
       MOVB    #'BB,D1                 ;get second #
       TCRT                            ;PRINT TAB(#,#)
ENDM

;MAIN LOOP - rest of program contains Subroutines
;------------------------------------------------
TOP:    CALL    MENU                    ;type out the menu, wait for input
       CALL    ANALIZ                  ;analyse user input
       CRLF                            ;simulate a return
       EXIT                            ;then quit

;MENU Subroutine - types out user interface
;------------------------------------------
MENU:   PRTTAB  -1,0                    ;clear the screen
       PRTTAB  4,20.                   ;tab to row 4, column 20 (20 decimal!)
       TYPE    <SETUP - Set up your terminal without using SET!>

       PRTTAB  6,12.                   ;tab to row 6, column 12 (decimal)
       TYPE    <Choose: 1) set hex  2) set octal  3) no ^C  4) ^C  5) Exit>

       PRTTAB  8.,30.                  ;tab to row 8, column 30 (decimal)
       TYPE    <User's Choice: >       ;prompt for responce

       ONEKEY                          ;expect only 1 keystroke, no return
       KBD                             ;get the key into D1
       RTN                             ;return from subroutine

;ANALYSE Subroutine - gets user input, acts accordingly
;------------------------------------------------------
ANALIZ: CTRLC   FOOLEM                  ;fool'em on control C

       SUBB    #60,D1                  ;adjust ASCII to "decimal 1...5"

       CMPB    D1,#1                   ;set hex?
       BNE     MO                      ;nope, maybe OCTAL
       HEX                             ;yup, set hex
       RTN                             ;and return

MO:     CMPB    D1,#2                   ;set octal?
       BNE     MNC                     ;nope, maybe NO ^C
       OCTAL                           ;yup, set octal
       RTN                             ;and return

MNC:    CMPB    D1,#3                   ;set NO ^C?
       BNE     MSC                     ;nope, maybe SET ^C
       NOCTC                           ;no ^C
       RTN                             ;and return

MSC:    CMPB    D1,#4                   ;set ^C?
       BNE     MQ                      ;nope, maybe Quit
       CTC                             ;set ^C
       RTN                             ;and return

MQ:     CMPB    D1,#5                   ;quit?
       BNE     ERROR                   ;nope, error!
       RTN                             ;return (program then quits)

ERROR:  MOV     #7,D1                   ;ASCII for a bell
       TTY                             ;BEEP!
       CRLF                            ;blank line
       TYPECR  <?not a valid number>   ;error message
       RTN                             ;and return (only to quit)

;FOOL'EM routine - makes user think they are at the dot, but they aren't
;-----------------------------------------------------------------------
FOOLEM: CLRCTC                          ;clear out the ^C
       MLTKEY                          ;just wait for input.....
       TYPE    <.>                     ;give em a "."
       KBD                             ;like so (expects a [CR])
       TYPECR  <HA-HA   - fooled you! ^C will not set you free!>
       ONEKEY                          ;adjust keyboard input
       TYPE    <Any key to continue.....>      ;prompt
       KBD                             ;get key (don't care what it is
       CLRCTC                          ;clear out ^C
       JMP     TOP                     ;upon keystroke, re-run program

END