;       TVI950.TDV - driver for Televideo 950
;
;       Copyright [c] Noel Alaska Systems Technology, 1983.

; 07/10/83 -  revised for AMOSL release 1.0b - new TCRT order for many
;             of the fancy things - also pick up new SV and AB defined
;             calls.  Add input translation for certain keys.  Install
;             function-code bitmap per new SuperVue specs.

; 08/08/83 -  correct function-code bitmap per Jim Rea.

;       T$AB is a bit I define in terminal status word that tells VTAM
;       'func' keys will be used for alt escape, tchar, and pchar.  So
;       it will 'passthru' ^G, ^[,  and ^_ to the controlled job, only
;       recognizing them when the parity bit is set -  which the input
;       routine of this driver does when it translates the func keys.

T$AB    =       ^O02000

       SEARCH  SYS
       SEARCH  SYSSYM
       SEARCH  TRM

       OBJNAM  0,0,[TDV]

; Bitmap of defined functions (for new tdv format)
 FN.1  =^B1111111111111111     ;   0 -  15
 FN.2  =^B1111000111111111     ;  16 -  31
 FN.3  =^B1111111111111111     ;  32 -  47
 FN.4  =^B1000000000111111     ;  48 -  63
 FN.5  =^B0111111111111111     ;  64 -  79
 FN.6  =^B0000000000000000     ;  80 -  95
 FN.7  =^B0000000000000000     ;  96 - 111
 FN.8  =^B0000000000000000     ; 112 - 127
 FN.9  =^B1111111110011111     ; 128 - 143
 FN.A  =^B0000001111111111     ; 144 - 159

;************************
;*      TVI             * TDV communications area
;************************
TVI:    WORD    TD$NEW          ; TERMINAL ATTRIBUTES
       BR      INPUT           ; INPUT ROUTINE
       BR      OUTP            ; OUTPUT ROUTINE
       BR      ECHO            ; ECHO ROUTINE
       BR      TCRT            ; CRT CONTROL
       RTN                     ; TDV INIT ROUTINE (none)
       WORD    0               ; IPA SIZE (bytes)
       BYTE    24.             ; number of rows
       BYTE    80.             ; number of columns
       LWORD   -1              ; Alpha's  function word

       WORD    FN.2            ; Vendor's function bitmap
       WORD    FN.1
       WORD    FN.4
       WORD    FN.3
       WORD    FN.6
       WORD    FN.5
       WORD    FN.8
       WORD    FN.7
       WORD    FN.A
       WORD    FN.9
       BLKW    6.
       WORD    [SUP],[ER],[VUE]
       WORD    0,0,0

OUTP:   JMP     OUTPUT          ; "the long branch"
ECHO:   JMP     ECHO2           ; "the long branch"
TCRT:   JMP     CRT             ; "the long branch"

       PAGE
;************************
;*      INPUT           * Input routine for Televideo 950
;************************
INPUT:  BMI     INMLT           ; skip if multi-byte processing
       ANDB    #177,D1         ; remove parity
       CMPB    D1,#^H16        ; replace ^V with LF
       BNE     1$
       MOVB    #^H0A,D1
       BR      INX
1$:     CMPB    D1,#^H0A        ; replace LF with ^V
       BNE     CKLESC
       MOVB    #^H16,D1
       BR      INX

CKLESC: CMPB    D1,#1           ; function code?
       BEQ     INPM            ;   yes - could be multi-byte sequence
       CMPB    D1,#33          ; escape?
       BEQ     INPM            ;   yes - could be multi-byte sequence
INX:    LCC     #0              ;   no - normal processing
       RTN
INPM:   LCC     #PS.N           ; possible multi-byte - return N flag
       RTN

; --- get here for multi-byte sequence ---
INMLT:  MOVB    (A0)+,D1        ; get the first character
       ANDB    #177,D1
       DECB    D0              ; no translation if single character
       BEQ     INMX
       CMPB    D1,#1           ; function sequences start with SOH
       BNE     INMNOT          ;   - escape sequence -

;Function codes translation
INMF:   MOVB    (A0)+,D1        ; get the second character
       ANDB    #177,D1         ; remove parity
       LEA     A6,XLAT1        ; index the translation table
10$:    MOVB    (A6)+,D7        ; get character
       BEQ     30$             ;   end of table - take char as is
       CMPB    D1,D7           ; this one it?
       BEQ     20$             ;   yes -
       INC     A6              ;   no  - keep looken
       BR      10$
20$:    MOVB    @A6,D1          ; translate the sequence
       ORW     #T$AB,@A5       ; force T$AB bit
       BR      INMX
30$:    MOV     T.IBF(A5),A6
       ADD     T.ICC(A5),A6
       MOVB    #07,@A6         ; force ^G ahead of this char
       INC     T.ICC(A5)
       INC     T.BCC(A5)
INMX:   LCC     #0              ; reset the flags
INMX2:  RTN

;Escape code translation
INMNOT: MOVB    (A0)+,D1        ; get the second character
       ANDB    #177,D1         ; remove parity
       LEA     A6,XLAT2        ; index the translation table
10$:    MOVB    (A6)+,D7        ; get character
       BEQ     30$             ;   end of table - take char(s) as is
       CMPB    D1,D7           ; this one it?
       BEQ     20$             ;   yes -
       INC     A6              ;   no  - keep looken
       BR      10$
20$:    MOVB    @A6,D1          ; translate the sequence
       BR      INMX
30$:    CALL    40$             ; accept sequence 'as is'
       MOVB    #33,@A6
35$:    CALL    40$
       MOVB    D1,@A6
       DEC     D0
       BEQ     INMX2
       MOVB    (A2)+,D1
       BR      35$
40$:    MOV     T.IBF(A5),A6    ; subroutine inserts char
       ADD     T.ICC(A5),A6
       INC     T.ICC(A5)
       INC     T.BCC(A5)
       RTN

XLAT1:  BYTE    'E,207          ; func E is alternate escape    [vtam]
       BYTE    'e,207          ;
       BYTE    'P,237          ; func P is picture request     [vtam]
       BYTE    'p,237          ;
       BYTE    'T,235          ; func T is toggle request      [vtam]
       BYTE    't,235          ;
       BYTE    0,0             ; end of table
       EVEN

XLAT2:  BYTE    'Q,^H06         ; ins chr
       BYTE    'R,^H1A         ; delete line
       BYTE    'W,^H04         ; del chr
       BYTE    'E,^H02         ; ins line
       BYTE    'I,^H01         ; bs (backtab) ^A
       BYTE    'j,^H0B         ; shifted up arrow
       BYTE    0,0             ; end of table
       EVEN

       PAGE
;************************
;*      OUTPUT          * Output routine for Televideo 950
;************************
OUTPUT: SAVE    A3
       CMPB    D1,#12          ; is this a linefeed?
       BNE     0$              ;   NO
       LEA     A3,T.OQX(A5)    ;   YES - point at output queue
       QINS    A3              ; get another queue block
       MOV     #4,0(A3)        ; we use image-mode output
       MOV     #3,4(A3)        ; we send 3 bytes
       PEA     1$              ; point to data to send
       POP     10(A3)          ; put data addr into queue block
       CLR     D1              ; tell TRMSER to ignore this LF
0$:     LCC     #10             ; normal positioning
       REST    A3
       RTN

1$:     BYTE    14,10,12        ; send right, left, LF
       EVEN

       PAGE
;************************
;*      ECHO            * standard crt echo routine
;************************
ECHO2:  CMPB    D1,#25          ; ^U ?
       BEQ     CTRLU
       CMPB    D1,#177         ; Rubout ?
       BNE     ECHX

RUBOUT: CMPB    D6,#11          ; was it tab?
       BEQ     RBTB            ;  YES
KRTG:   MOV     #3,D3           ; set char count
       PEA     ERUB            ; set buf addr
       POP     D1
       TRMBFQ                  ; queue up space/bs/space
       RTN

ERUB:   BYTE    10,40,10,0

RBTB:   CLR     D3
       MOVW    T.POB(A5),D3    ; get begin position
       MOV     T.ICC(A5),D2    ; get input char count
       MOV     T.IBF(A5),A6    ; get input base
KRTS:   DEC     D2              ; dec # chars
       BMI     KRTQ            ;  YES
       MOVB    (A6)+,D1        ; fwd scan
       CMPB    D1,#11          ;  TAB
       BEQ     KRTT
       CMPB    D1,#15          ;  CR
       BEQ     KRTC
       CMPB    D1,#33          ;  ESCAPE
       BEQ     KRTI
       CMPB    D1,#40          ;  CTL CHAR
       BLO     KRTS
       CMPB    D1,#176         ;  RUBOUT
       BHI     KRTS
KRTI:   INC     D3              ; bump position
       BR      KRTS
KRTT:   ADD     #10,D3          ; tab adjust
       AND     #^C7,D3
       BR      KRTS
KRTC:   CLR     D3              ; zero for CR
       BR      KRTS
KRTQ:   COM     D3              ; compute # BS's
       AND     #7,D3
       INC     D3
       MOV     #10,D1
       TRMBFQ                  ; queue BS's
ECHX:   RTN

CTRLU:  TST     D6              ; anything to clear?
       BEQ     CTUX            ;  NO
       CLR     D3
       MOVW    T.POO(A5),D3    ; compute # spaces
       SUBW    T.POB(A5),D3
       BEQ     ECHX
       CMP     D3,T.ILS(A5)    ; make sure <= terminal width
       BLOS    CLUA
       MOV     T.ILS(A5),D3
CLUA:   MOV     #10,D1          ; queue BS's
       TRMBFQ
       ASL     D1,#2           ; queue spaces
       TRMBFQ
       MOV     #10,D1          ; queue BS's
       TRMBFQ
CTUX:   RTN

       PAGE
;************************
;*      CRT             * crt routine for televideo 950
;************************
CRT:    TSTW    D1              ; is it cursor position?
       BMI     CRTS            ;  NO
       TTYI                    ; send position command
       BYTE    233,75,0,0
       ADD     #^H1F1F,D1      ; add position offsets
       ROR     D1,#8.          ; send row
       TTY
       ROL     D1,#8.          ; send col
       TTY
       ORW     #T$AB,@A5       ; force T$AB bit
       RTN

CRTS:   AND     #377,D1         ; strip the high byte
       ASL     D1              ;  times 2 (word offset).
       SAVE    A2,D1           ; save A2 and command code
       CMP     D1,#CRCB-CRCA   ; check for valid code
       BHI     CRTX            ;   and bypass if bad
       LEA     A2,CRCA         ; index the table
       ADD     D1,A2           ; add command code
       MOVW    @A2,D1          ; pick up data field offset
       ADD     D1,A2           ; make absolute data address
       TTYL    @A2             ; print the data field

CRTX:   REST    A2,D1           ; restore A2 and command code
;       TSTB    D1              ; pause if clear screen
;       BEQ     0$
;       CMPB    D1,#10.         ; pause if erase to end of screen
;       BEQ     0$
       RTN

; ----- televideo 950 doesn't seem to need waits, even @ 19200 -----
; 0$:   SSTS    -(SP)           ; stack status
; 1$:   SVLOK                   ; lock so things can't change
;       MOVW    @A5,D7
;       ANDW    #T$OIP,D7       ; is output in progress?
;       BNE     2$              ;   YES - wait
;       TST     T.OQX(A5)       ; is output queued?
;       BNE     2$              ;   YES - wait
;       LSTS    (SP)+           ; restore status
;       RTN                     ; return to user
; 2$:   JWAIT   J.TOW           ; let TRMSER wake us (UNLOCK's)
;       BR      1$              ; re-test

; offset and data tables follow for all commands
CRCA:   WORD    C0-.,C1-.,C2-.,C3-.,C4-.,C5-.,C6-.,C7-.,C8-.
       WORD    C9-.,C10-.,C11-.,C12-.,C13-.,C14-.
       WORD    C15-.,C16-.,C17-.,C18-.,C19-.,C20-.,C21-.,C22-.
       WORD    C23-.,C24-.,C25-.,C26-.,C27-.,C28-.,C29-.
       WORD    C30-.,C31-.,C32-.,C33-.,C34-.,C35-.,C36-.,C37-.,C38-.,C39-.
       WORD    C40-.,C41-.,C42-.,C43-.,C44-.,C45-.,C46-.,C47-.,C48-.,C49-.
       WORD    C50-.,C51-.,C52-.,C53-.,C54-.,C55-.,C56-.,C57-.,C58-.,C59-.
       WORD    C60-.,C61-.,C62-.,C63-.,C64-.,C65-.,C66-.,C67-.,C68-.,C69-.
       WORD    C70-.,C71-.,C72-.,C73-.,C74-.,C75-.,C76-.,C77-.,C78-.,C79-.
       WORD    C80-.,C81-.,C82-.,C83-.,C84-.,C85-.,C86-.,C87-.,C88-.,C89-.
       WORD    C90-.,C91-.,C92-.,C93-.,C94-.,C95-.,C96-.,C97-.,C98-.,C99-.
       WORD    C100-.,C101-.,C102-.,C103-.,C104-.,C105-.,C106-.,C107-.,C108-.,C109-.
       WORD    C110-.,C111-.,C112-.,C113-.,C114-.,C115-.,C116-.,C117-.,C118-.,C119-.
       WORD    C120-.,C121-.,C122-.,C123-.,C124-.,C125-.,C126-.,C127-.,C128-.,C129-.
       WORD    C130-.,C131-.,C132-.,C133-.,C134-.,C135-.,C136-.,C137-.,C138-.,C139-.
       WORD    C140-.,C141-.,C142-.,C143-.,C144-.,C145-.,C146-.,C147-.,C148-.,C149-.
       WORD    C150-.,C151-.,C152-.,C153-.,C154-.,C155-.,C156-.
CRCB:

       PAGE
C0:     BYTE    233,'*,0                ; clear screen
C1:     BYTE    30.,0                   ; cursor home (move to column 1,1)
C2:     BYTE    215,0                   ; cursor return (move to column 1)
C3:     BYTE    11.,0                   ; cursor up
C4:     BYTE    10.,0                   ; cursor down
C5:     BYTE    8.,0                    ; cursor left
C6:     BYTE    12.,0                   ; cursor right
C7:     BYTE    233,43,0                ; lock keyboard
C8:     BYTE    233,42,0                ; unlock keyboard
C9:     BYTE    233,'T,0                ; erase to end of line
C10:    BYTE    233,'Y,0                ; erase to end of screen
C11:    BYTE    233,'),0                ; enter backgroud display mode (reduced intensity).
C12:    BYTE    233,'(,0                ; enter foreground display mode (normal intensity)
C13:    BYTE    233,'&,0                ; enable protected  fields
C14:    BYTE    233,'',0                ; disable protected fields
C15:    BYTE    233,'R,0                ; delete line
C16:    BYTE    233,'E,0                ; insert line
C17:    BYTE    233,'W,0                ; delete character
C18:    BYTE    233,'Q,0                ; insert character
C19:    BYTE    233,'?,0                ; read cursor address
C20:    BYTE    233,'1,0                ; read character at current cursor position
C21:    BYTE    233,'G,'2,0             ; start blink field
C22:    BYTE    233,'G,'0,0             ; end blink field
C23:    BYTE    233,'$,0                ; start line drawing mode (enable alternate character set)
C24:    BYTE    233,'%,0                ; end line drawing mode (disable alternate character set)
C25:                                    ; set horizontal position
C26:                                    ; set vertical   position
C27:    BYTE    0                       ; set terminal   attributes
C28:    BYTE    233,'.,'1,0             ; cursor on
C29:    BYTE    233,'.,'0,0             ; cursor off
C30:    BYTE    233,'G,'8,0             ; start underscore                      [102]
C31:    BYTE    233,'G,'0,0             ; end underscore                        [102
C32:    BYTE    233,'G,'4,0             ; start reverse video                   [102]
C33:    BYTE    233,'G,'0,0             ; end reverse video                     [102]
C34:    BYTE    233,'G,'6,0             ; start reverse blink                   [102]
C35:    BYTE    233,'G,'0,0             ; end reverse blink                     [102]
C36:    BYTE    233,'o,0                ; turn off screen display               [102]
C37:    BYTE    233,'n,0                ; turn on screen display                [102]
C38:    BYTE    30.,0                   ; top left corner
C39:    BYTE    233,75,40,156,0         ; top right corner
C40:    BYTE    233,75,67,40,0          ; bottom left corner
C41:    BYTE    233,75,67,156,0         ; bottom right corner
C42:    BYTE    '-,0                    ; top intersect
C43:    BYTE    '|,0                    ; right intersect
C44:    BYTE    '|,0                    ; left intersect
C45:    BYTE    '-,0                    ; bottom intersect
C46:    BYTE    '-,0                    ; horizontal line
C47:    BYTE    '|,0                    ; vertical line
C48:    BYTE    '+,0                    ; intersection
C49:                                    ; solid block
C50:                                    ; slant block
C51:    BYTE    '#,0                    ; cross-hatch block
C52:    BYTE    '=,0                    ; double line horizontal
C53:    BYTE    '|,0                    ; double line vertical
C54:                                    ; send message to function key line
C55:                                    ; send message to shifted function key line
C56:                                    ; set normal display format
C57:                                    ; set horizontal split (follow with row code)
C58:                                    ; set vertical split (39 char columns)
C59:                                    ; set vertical split (40 char columns)
C60:                                    ; set vertical split column to next char
C61:                                    ; activate split segment 0
C62:    BYTE    0                       ; activate split segment 1
C63:    BYTE    233,'f,0                ; send message to host message field
C64:    BYTE    '^,0                    ; up-arrow
C65:    BYTE    '|,0                    ; down-arrow
C66:    BYTE    '`,0                    ; raised dot
C67:    BYTE    '~,0                    ; end of line marker
C68:    BYTE    '[,0                    ; horizontal tab symbol
C69:                                    ; paragraph
C70:                                    ; dagger
C71:                                    ; section
C72:                                    ; cent sign
C73:                                    ; one-quarter
C74:                                    ; one-half
C75:                                    ; degree
C76:                                    ; trademark
C77:                                    ; copyright
C78:    BYTE    ' ,0                    ; registered
C79:                                    ; undefined
C80:                                    ; undefined
C81:                                    ; undefined
C82:                                    ; undefined
C83:                                    ; undefined
C84:                                    ; undefined
C85:                                    ; undefined
C86:                                    ; undefined
C87:                                    ; undefined
C88:                                    ; undefined
C89:                                    ; undefined
C90:                                    ; undefined
C91:                                    ; undefined
C92:                                    ; undefined
C93:                                    ; undefined
C94:                                    ; undefined
C95:                                    ; undefined
C96:                                    ; undefined
C97:                                    ; undefined
C98:                                    ; undefined
C99:                                    ; undefined
C100:                                   ; undefined
C101:                                   ; undefined
C102:                                   ; undefined
C103:                                   ; undefined
C104:                                   ; undefined
C105:                                   ; undefined
C106:                                   ; undefined
C107:                                   ; undefined
C108:                                   ; undefined
C109:                                   ; undefined
C110:                                   ; undefined
C111:                                   ; undefined
C112:                                   ; undefined
C113:                                   ; undefined
C114:                                   ; undefined
C115:                                   ; undefined
C116:                                   ; undefined
C117:                                   ; undefined
C118:                                   ; undefined
C119:                                   ; undefined
C120:                                   ; undefined
C121:                                   ; undefined
C122:                                   ; undefined
C123:                                   ; undefined
C124:                                   ; undefined
C125:                                   ; undefined
C126:                                   ; undefined
C127:   BYTE    0                       ; undefined

; ----- begin SuperVue defined calls ------
C128:   BYTE    233,'f,0                ; start line 25 (line 0 on some terms)
C129:   BYTE    215,0                   ; end   line 25   "
C130:   BYTE    33,'!,1,0               ; line lock on
C131:   BYTE    33,'!,2,0               ; line lock off
C132:   BYTE    233,'f,40,215,0         ; clear line 25
C133:                                   ; start underline (per char type)
C134:   BYTE    0                       ; end   underline   "

; ----- begin Alpha-Base defined calls -----
C135:   BYTE    233,'d,0                ; set SCREEN DARK
C136:   BYTE    233,'b,0                ; set SCREEN BRIGHT
C137:   BYTE    233,'>,0                ; key click on
C138:   BYTE    233,'<,0                ; key click off
C139:   BYTE    233,'G,'1,0             ; blank on
C140:   BYTE    233,'G,'0,0             ; blank off
C141:   BYTE    233,'G,'>,0             ; reverse/blink/underline on
C142:   BYTE    233,'G,'0,0             ; reverse/blink/underline off
C143:   BYTE    233,'G,'<,0             ; reverse/underline on
C144:   BYTE    233,'G,'0,0             ; reverse/underline off
C145:   BYTE    233,'G,':,0             ; blink/underline on
C146:   BYTE    233,'G,'0,0             ; blink/underline off
C147:   BYTE    233,'.,'1,0             ; cursor blink  block
C148:   BYTE    233,'.,'2,0             ; cursor steady block
C149:   BYTE    233,'.,'3,0             ; cursor blink  underline
C150:   BYTE    233,'.,'4,0             ; cursor steady underline
C151:   BYTE    233,'f                  ; send msg to host msg fld (centered)
       ASCII   /                    /
       BYTE    0
C152:   BYTE    215,0                   ; end line 25
C153:   BYTE    233,'g,0                ; Turn L25 Msg ON
C154:                                   ; undefined
C155:                                   ; undefined
C156:   BYTE    0                       ; undefined

       EVEN
       END