; BAUD.LIT - display or change baud rates
; replaces AM's version
; Irv Bromberg, Medic/OS Consultants
; see AMUS Newsletter, Vol. 8, No. 3 (March 1985) pp 35+ for documentation
;
; Modified by Brad Horine, Hytek Amplifier (TDF/AM) 25-Jun-1986, to
;   require that user be logged into OPR: to change baud rate of another
;   terminal (other than his own) -- Version 1.4(100)
;
       OBJNAM  BAUD.LIT
;
; Under AMOS/L Version 1.3, hash = 244-176-423-405, size = 414. bytes
;
       VMAJOR  = 1                     ; Version 1.4(100)
       VMINOR  = 4
       VSUB    = 0
       VEDIT   = 100.
       VWHO    = 0

       SEARCH  SYS
       SEARCH  SYSSYM
       SEARCH  TRM

       PHDR    -1,0,PH$REE!PH$REU

       JCB     =A0
       RAD50   =A1
       BUFFER  =A2
       TCB     =A5
       ATEMP   =A6
       NUMBER  =D1

       MOV     JOBCUR,JCB              ; get user's TCB
       MOV     JOBTRM(JCB),TCB
       BYP
       LIN                             ; if line empty, then show current
       JEQ     SHRATE                  ;   baud rate
       NUM                             ; is there a number here?
       JEQ     GETRAT                  ;   yes, read it in
       CALL    FNDTRM                  ; search for specified terminal
       BEQ     FOUND
       TYPECR  <?Terminal does not exist>
       EXIT

FOUND:  BYP
       LIN
       JEQ     SHRATE
;
; User wants to change another terminal's rate -- be sure he is
; logged into OPR: first!
;
       CMMW    JOBUSR(JCB),#402        ; is PPN [1,2]?                 ;1.4
       BNE     NOTOPR                  ;  no - sorry                   ;1.4
       CMMW    JOBDEV(JCB),#[DSK]      ; is device DSK ?               ;1.4
       BNE     NOTOPR                  ;  no - sorry again             ;1.4
       TSTW    JOBDRV(JCB)             ; are we logged into unit 0 ?   ;1.4
       JEQ     GETRAT                  ;  yep - carry on               ;1.4
NOTOPR: TYPESP  <?You must be logged into OPR: to change another>       ;1.4
       TYPECR  <terminal's baud rate>                                  ;1.4
       EXIT                                                            ;1.4
;
; OK, we ARE logged into DSK0:[1,2], so we can try to change the rate
;
GETRAT: GTDEC                           ; get specified rate
       LEA     A0,RATES                ; lookup rate to see if valid
LOOK:   CMPW    NUMBER,(A0)+
       BEQ     OK
       TSTW    @A0                     ; end of table?
       BNE     LOOK                    ;  no - look some more
       TYPE    <?Baud rate>
       DCVT    0,OT$TRM!OT$LSP!OT$TSP
       TYPECR  <is not a valid baud rate>
       EXIT

OK:     SUBW    #2,A0                   ; compensate for post-increment
       LEA     A6,RATES                ; calculate rate code
       SUB     A6,A0
       MOV     A0,D0
       ASR     D0                      ; divide by 2 (table was words)
WAIT:   TSTB    T.STS(TCB)              ; wait for echoing to finish
       BMI     WAIT
       SLEEP   #500                    ; last pause for final CRLF (if any)
       MOVW    D0,T.BAU(TCB)           ; set baud rate in TCB
       MOV     T.IDV(TCB),A6
       CALL    2(A6)                   ; call interface driver to set rate
       EXIT

SHRATE: CLR     NUMBER                  ; pre-clear
       MOVW    T.BAU(TCB),NUMBER       ; get current rate
       ASL     NUMBER                  ; x2 to index baud table
       LEA     A1,RATES
       MOVW    0(A1)[NUMBER],NUMBER
       TYPESP  <Current baud rate is>
       DCVT    0,OT$TRM
       CRLF
       EXIT

FNDTRM: PUSH                            ; get some workspace
       MOV     SP,RAD50                ; pack terminal name
       PACK
       PACK
       POP     D6                      ; into D6
       MOV     TRMDFC,TCB
NXTTRM: MOV     TCB,D7                  ; test if end of defined terminals
       BEQ     TNOTFD                  ; 0=end of list
       ADD     #8.,TCB
       MOV     -4(TCB),D7
       CMP     D7,D6                   ; is this the terminal specified?
       BEQ     TFOUND                  ;   yes - return
       MOV     -8.(TCB),TCB            ;   no - try again
       BR      NXTTRM

TNOTFD: LCC     #0                      ; set "not found" flag
TFOUND: RTN

RATES:  RADIX   10                      ; table of valid baud rates
       WORD    50,75,110,134,150,200,300,600,1200,1800
       WORD    2000,2400,3600,4800,7200,9600,19200,38400,57600
       WORD    0                       ; end of table

       END