; AMOS.M68 - AlphaFIX/L overlay to allow temporary exit to AMOS
;          Written at Castle Computer Group, Inc.
;               By David Greene, Winter 1985
;      Copyright (C) 1985  Castle Computer Group, Inc.
;

; This is an AlphaFIX/L overlay.  When in an FIX overlay all registers
; should be preseved, along with all JCB items that are used by FIX.
; (e.g.  JOBBRK,JOBERC,JOBEXI,JOBTRC  etc...)

; This overlay creates the AMOS command.  Usage is as follows
;
;  >AMOS command<CR>            ; Executes the 'command' and returns
;
;  >AMOS<CR>                    ; This mode pretends that it is at monitor
;                               ; level by typing the normal prompt '.'
;                               ; and executing commands via the AMOS
;                               ; monitor call.  This mode is terminated
;                               ; when you hit CTRL-C at the dot.


;  Edit History  ******************************************
;
;  100 - Created /DJG
;  101 - Made it work, by clearing DAT mode on entry /Cary Fitch
;       (Maybe it worked before, but it wouldn't work under 1.3 for me. )
;       Also changed object to AMOS.FXO to correspond to common "AMOS" use.
;  102 - Made it recognize both lower and upper case "fix" as command to
;               return to FIX program.
;  103 - Put "FIX   " in JOBPRG when returning from overlay
;  104 - Make monitor simulator much better.  Make command files work nice.
;        Ajust CHKFIX routine.  /Dave Greene

;Define version equates
VMAJOR  =       1
VMINOR  =       0
VSUB    =       0
VEDIT   =       104. ;[101]
VWHO    =       0


       SEARCH  SYS                     ; Search system libraries
       SEARCH  SYSSYM
       SEARCH  TRM

       OBJNAM  AMOS.FXO                ; designate FIX overlay


       PHDR    -1,0,PH$REU             ; Program header (reusable)

;Start of overlay

       SAVE    A0,D1,D5                ; Save work registers
       JOBIDX  A0                      ; Index my JCB
       MOV     JOBTRM(A0),A6           ; index my terminal status
;was    ANDW    #^C<T$IMI!T$ECS!T$ILC>,@A6; clear image and noecho modes
       ANDW    #^C<T$IMI!T$ECS!T$DAT>,@A6; [101] clear image and noecho modes

       CLR     D5                      ; clear work register
       PUSH    JOBEXI(A0)              ; push amos exit SP onto stack
       MOV     #<-1_8.+10.>,D1         ; erase to end of screen
       TCRT
       LIN                             ; is there a command already there ?
       BNE     20$                     ; yes - then execute what is on
                                       ;     command line and return to FIX
       SET     D5                      ; no - set AMOS imitation mode


; This routine pretends its the monitor.  It types a dot;
; accepts a command; and executes just like AMOS.

10$:
       TSTW    JOBCMZ(A0)              ; did we invoke a command file?
       BEQ     15$                     ;  no - ok
       ORW     #C.MON,JOBCMS(A0)       ; yes - KBD needs to think we are
                                       ;  at the monitor to handle ':' cmds
       MOV     JOBCMS(A0),D1           ; get command file status word
       ANDW    #C.SIL,D1               ; are we in :S
       BNE     17$                     ;  yes - don't display prompt
15$:
       TTYL    JOBPRM(A0)              ; pretend we're AMOS
17$:
       ANDW    #^C<J.CCA>,JOBSTS(A0)   ; clear any pending control-c's
       KBD     40$                     ; get AMOS command
       CALL    CHKFIX                  ; check to see if he wants to return
       JEQ     40$                     ;  yes - end routine
       BYP                             ; bypass spaces
       LIN                             ; anything there ?
       BEQ     10$                     ;  no - continue
20$:
       SAVE    A0-A5,D0-D5             ; yes - save all registers
       AMOS                            ; execute command
       REST    A0-A5,D0-D5             ; restore all registers

       ANDW    #^C<C.MON>,JOBCMS(A0)   ; tell KBD back in program
       TSTW    JOBCMZ(A0)              ; any command file active ?
       BEQ     25$                     ;  no - ok
       ANDW    #^C<C.SIL>,JOBCMS(A0)   ;  yes - make sure C.SIL is clear
25$:
       TST     D5                      ; are we in 'AMOS pretend' mode ?
       BNE     10$                     ;  yes - go back and get more commands

; This routine is executed when mode 1 is used.
; It prevents return to AlphaFIX before the user
; can appreciate the results

       MOV     JOBTRM(A0),A6           ; not index terminal attribute word
       ORW     #<T$IMI!T$ECS>,@A6      ; and reset image and noecho mode
       CRLF                            ; a little asthetics
       CRLF
       MOV     #<-1_8.+11.>,D1         ; lower intensity
       TCRT
       TYPE    <Press >
       MOV     #<-1_8.+12.>,D1         ; higher intensity
       TCRT
       TYPE    <Any Key >
       MOV     #<-1_8.+11.>,D1         ; back to lower
       TCRT
       TYPE    <to Return to >         ; back to higher
       MOV     #<-1_8.+12.>,D1
       TCRT
       TYPE    <AlphaFIX: >
30$:
       ANDW    #^C<J.CCA>,JOBSTS(A0)   ; clear any pending ctrlcs
       TIN                             ; get a character
       CMPB    D1,#3.                  ; is this a CTRLC
       BEQ     30$                     ; yes clear it and get a real
                                       ;   character
;This routine is either fallen through to or, when in 'AMOS pretend'
;mode a Ctrl-C is hit.
40$:
       MOV     JOBTRM(A0),A6           ; index terminal attribute word
       ORW     #<T$IMI!T$ECS>,@A6      ; set image and noecho mode
                                       ; in order to redisplay the
                                       ; AlphaFIX menu, we need to
       ORW     #J.CCA,JOBSTS(A0)       ; simulate a CTRLC
       JOBIDX                          ; [103 cf]
       MOVW    #[FIX],JOBPRG(A6)       ; [103 cf]
       MOVW    #[   ],JOBPRG+2(A6)     ; [103 cf]
       POP     JOBEXI(A0)              ; restore exit trap SP
       REST    A0,D1,D5                ; restore work registers
       RTN                             ; and return to AlphaFIX/L

;  This routine checks to see if you want back into FIX.  A valid request
;  is 'FIX<CR>'.  FIX610 will not cut it.
CHKFIX:
       PUSH    A2
       BYP                             ; skip spaces
       MOVB    (A2),D1                 ; get first byte of string
       UCS                             ; upper case
       CMPB    D1,#'F                  ; 'f' ?
       BNE     10$                     ;  no - not 'Fix'
2$:     INC     A2                      ; get next bye
       MOVB    @A2,D1                  ;
       UCS                             ; fold
       CMPB    D1,#'I                  ; is it 'I' ?
       BNE     10$                     ;   no - can't be 'fIx'
4$:     INC     A2                      ; get next byte
       MOVB    @A2,D1                  ;
       UCS                             ; fold
       CMPB    D1,#'X                  ; is it 'X'
       BNE     10$                     ;   no - not 'fiX'
       INC     A2                      ;  yes - check to see if FIX is part
       BYP                             ;        of something; like 'FIXCRC'
       LIN
       BNE     10$
       POP     A2                      ; restore A2 for posterity
       LCC     #4                      ; set success flag
       RTN                             ; and return
10$:
       POP     A2                      ; A2 back to real command
       LCC     #0                      ; no this is not a request for FIX
       RTN                             ; return

       END                             ; End Of Source