        .title  scr
;
; content : SCR-routines
;
; author  : Arne Vajhøj (june 1989)
;
;-
;
;  External routines (primary):
;
;    SCR_APP
;    SCR_ASCIIFONT
;    SCR_BEL
;    SCR_BOX
;    SCR_CANCEL
;    SCR_CLR
;    SCR_CUR_OFF
;    SCR_CUR_ON
;    SCR_DEL_LIN
;    SCR_DEVTYP
;    SCR_EXIT
;    SCR_FLUSH
;    SCR_FLU_TXT
;    SCR_GET_KEY
;    SCR_GET_LIN
;    SCR_GET_MSG
;    SCR_GET_PW
;    SCR_GET_TXT
;    SCR_HIT
;    SCR_HOR_LIN
;    SCR_NOTRAP
;    SCR_PUT_BIGTXT
;    SCR_PUT_LIN
;    SCR_PUT_TXT
;    SCR_RETRAP
;    SCR_SCROLL
;    SCR_SETSCROLL
;    SCR_SOFTFONT1
;    SCR_SOFTFONT2
;    SCR_TRAP
;    SCR_VER_LIN
;    SCR_WHERE
;    SCR_WID_132
;    SCR_WID_80
;
;  Internal routines:
;
;    asg_trm
;    dsg_trm
;    end_lin
;    flu_buf
;    get_1
;    get_1t (added 13/11/92 by AV)
;    get_n
;    get_no
;    get_tah (added 08/11/92 by AV)
;    grf_chr
;    ins_lin
;    nrm_chr
;    pos_abs
;    put_n
;    set_atr
;    ver_loop
;
;-
        $DSCDEF
        $IODEF
        $TTDEF
        $TT2DEF
        $SSDEF
TRUE=-1
FALSE=0
        .macro  fixdesc,l,a
        .word   l
        .byte   DSC$K_DTYPE_T
        .byte   DSC$K_CLASS_S
        .address a
        .endm
        .macro  ascstr,s
        .ascii  "s"
        .align  long
        .endm
        .macro  time8to4,t8,t4,garb
        subl2   #^x4BEB4000,t8
        sbwc    #^x007C9567,t8+4
        ediv    #10000000,t8,t4,garb
        .endm
        .macro  time4to8,t4,t8
        emul    #10000000,t4,#0,t8
        addl2   #^x4BEB4000,t8
        adwc    #^x007C9567,t8+4
        .endm
        .macro  dtime4to8,t4,t8
        emul    #-10000000,t4,#0,t8
        .endm
        .macro  cvt_d2g var,?L1         ; scratcher r2-r5
        movq    var,r2
        beql    L1
        rotl    #16,r2,r5
        rotl    #16,r3,r4
        ashq    #-3,r4,r4
        rotl    #16,r5,r2
        rotl    #16,r4,r3
        bicl2   #^x00007000,r2
        addl2   #14336,r2
L1:     movq    r2,var
        .endm
;
; readonly data section
;
        .psect  $PDATA quad,pic,con,lcl,shr,noexe,nowrt
argl_assign:                            ; argumentlist SYS$ASSIGN
        .long   4
        .address trmdes                 ; device name
        .address ttchan                 ; channel
        .long   0                       ; access-mode
        .long   0                       ; mailbox name
argl_asnwthmbx:                         ; argumentlist LIB$ASN_WTH_MBX
        .long   5
        .address trmdes                 ; device name
        .address messizadr              ; message size
        .address bufquoadr              ; buffer quota
        .address garbchan               ; device channel
        .address mbxchan                ; mailbox channel
trmdes: fixdesc 2,trmadr                ; terminal-descriptor
trmadr: ascstr  <TT>                    ; terminal-name
messizadr:
        .long   512
bufquoadr:
        .long   2048
font1:  .ascii  "???~???/???J???;"
        .ascii  "?@F??F?/???????;"
        .ascii  "G}GGG}G/ANAAANA;"
        .ascii  "Wca~QQc/ACCNCA@;"
        .ascii  "?EEoGE@/GE@?EE?;"
        .ascii  "?eXPhE?/BCGGDAD;"
        .ascii  "???B???/???????;"
        .ascii  "?wE@???/?@EG???;"
        .ascii  "???@Ew?/???GE@?;"
        .ascii  "cgo{ogc/CA@F@AC;"
        .ascii  "?__w__?/???B???;"
        .ascii  "???????/???F???;"
        .ascii  "?_____?/???????;"
        .ascii  "???????/???C???;"
        .ascii  "???oGCB/KA@????;"
        .ascii  "{A@@@A{/BCGGGCB;"
        .ascii  "?CA~???/???N???;"
        .ascii  "A@@`PHE/KIHGGGG;"
        .ascii  "A@@@ppM/CGGGGGF;"
        .ascii  "^OOOOO~/??????N;"
        .ascii  "^PPPPP`/CGGGGGF;"
        .ascii  "?_OWSa@/BCGGGCB;"
        .ascii  "@@@@`PN/GCA@???;"
        .ascii  "CiPPPiC/BCGGGCB;"
        .ascii  "KQ```QK/GCA@???;"
        .ascii  "???G???/???@???;"
        .ascii  "???G???/???F???;"
        .ascii  "_OGGCAA/?@AACGG;"
        .ascii  "GGGGGGG/@@@@@@@;"
        .ascii  "AACGGO_/GGCAA@?;"
        .ascii  "?A@@`QK/???J???;"
        .ascii  "{AAqQQ{/FGGJIIJ;"
        .ascii  "oGCACGo/N@@@@@N;"
        .ascii  "}aaaaa[/NGGGGGF;"
        .ascii  "{AAAAAC/FGGGGGC;"
        .ascii  "}AAAAA{/NGGGGGF;"
        .ascii  "}aaaaAA/NGGGGGG;"
        .ascii  "}aaaaAA/N??????;"
        .ascii  "{AAaaac/FGGGGGF;"
        .ascii  "}_____}/N?????N;"
        .ascii  "??A}A??/??GNG??;"
        .ascii  "AAA}AAA/CGGF???;"
        .ascii  "}__OGCA/N??@ACG;"
        .ascii  "}??????/NGGGGGG;"
        .ascii  "}CGOGC}/N?????N;"
        .ascii  "}CW_??}/N???BCN;"
        .ascii  "{AAAAA{/FGGGGGF;"
        .ascii  "}aaaaa[/N??????;"
        .ascii  "{AAAAA{/FGGIKGF;"
        .ascii  "}aaaaa[/N??@ACG;"
        .ascii  "KQaaaAC/CGGGGHE;"
        .ascii  "AAA}AAA/???N???;"
        .ascii  "}?????}/FGGGGGF;"
        .ascii  "Mo???oM/?@EGE@?;"
        .ascii  "}??w??}/FGGFGGF;"
        .ascii  "AKO_OKA/GE@?@EG;"
        .ascii  "EGO_OGE/???N???;"
        .ascii  "AAAaQIE/KIHGGGG;"
        .ascii  "???~@@?/???NGG?;"
        .ascii  "BCGo???/????@AK;"
        .ascii  "?@@~???/?GGN???;"
        .ascii  "?CA@AC?/???????;"
        .ascii  "???????/GGGGGGG;"
        .ascii  "???B???/???????;"
        .ascii  "oGGGGOw/FGGGGCN;"
        .ascii  "~OGGGGo/NCGGGGF;"
        .ascii  "oGGGGGO/FGGGGGC;"
        .ascii  "oGGGGO~/FGGGGCN;"
        .ascii  "oGGGGGo/FHHHH@?;"
        .ascii  "??G}H@A/???N???;"
        .ascii  "oGGGGGo/CHHHHHF;"
        .ascii  "~OGGGGo/N?????N;"
        .ascii  "???s???/???N???;"
        .ascii  "???s???/CGGF???;"
        .ascii  "~???_OG/N@@@ACG;"
        .ascii  "???~???/???N???;"
        .ascii  "wO?_O?_/N??N??N;"
        .ascii  "w_OOOO_/N?????N;"
        .ascii  "oGGGGGo/FGGGGGF;"
        .ascii  "wGGGGGo/N@@@@@?;"
        .ascii  "oGGGGGw/?@@@@@N;"
        .ascii  "wOGGGGO/N??????;"
        .ascii  "oGGGGGO/CHHHHHE;"
        .ascii  "??OwO??/???FGGC;"
        .ascii  "w?????w/FGGGGCN;"
        .ascii  "W_???_W/?@EGE@?;"
        .ascii  "w??_??w/FGGFGGF;"
        .ascii  "GO_?_OG/GCA@ACG;"
        .ascii  "GO_?_OG/GCA@???;"
        .ascii  "GGGGgWG/GKIHGGG;"
        .ascii  "??_}A??/???NG??;"
        .ascii  "???}???/???N???;"
        .ascii  "??A}_??/??GN???;"
        .ascii  "_OO_??_/????@@?;"
font2:  .ascii  "???~???/???J???;"
        .ascii  "?@F??F?/???????;"
        .ascii  "G}GGG}G/ANAAANA;"
        .ascii  "Wca~QQc/ACCNCA@;"
        .ascii  "?EEoGE@/GE@?EE?;"
        .ascii  "?eXPhE?/BCGGDAD;"
        .ascii  "???B???/???????;"
        .ascii  "?wE@???/?@EG???;"
        .ascii  "???@Ew?/???GE@?;"
        .ascii  "cgo{ogc/CA@F@AC;"
        .ascii  "?__w__?/???B???;"
        .ascii  "???????/???F???;"
        .ascii  "?_____?/???????;"
        .ascii  "???????/???C???;"
        .ascii  "???oGCB/KA@????;"
        .ascii  "{A@@@A{/BCGGGCB;"
        .ascii  "?CA~???/???N???;"
        .ascii  "A@@`PHE/KIHGGGG;"
        .ascii  "A@@@ppM/CGGGGGF;"
        .ascii  "^OOOOO~/??????N;"
        .ascii  "^PPPPP`/CGGGGGF;"
        .ascii  "?_OWSa@/BCGGGCB;"
        .ascii  "@@@@`PN/GCA@???;"
        .ascii  "CiPPPiC/BCGGGCB;"
        .ascii  "KQ```QK/GCA@???;"
        .ascii  "???G???/???@???;"
        .ascii  "???G???/???F???;"
        .ascii  "_OGGCAA/?@AACGG;"
        .ascii  "GGGGGGG/@@@@@@@;"
        .ascii  "AACGGO_/GGCAA@?;"
        .ascii  "?A@@`QK/???J???;"
        .ascii  "{AAqQQ{/FGGJIIJ;"
        .ascii  "???{A@}/CGCB?@N;"
        .ascii  "@~PPPiC/GNGGGGF;"
        .ascii  "_OHEEB@/FGGGGGC;"
        .ascii  "@~DX`@}/GNGGJCJ;"
        .ascii  "_oheEB@/FGGGGGC;"
        .ascii  "B@`~`@@/CGGF???;"
        .ascii  "_oheeb`/CGGGGGF;"
        .ascii  "@~?{A~@/GNA@?NC;"
        .ascii  "A@A`~_?/CGGGF??;"
        .ascii  "A@A@~_O/??MHN??;"
        .ascii  "@~___~@/GN???NC;"
        .ascii  "??xEEB@/CIFGCA@;"
        .ascii  "??}@}?~/CGF?FGF;"
        .ascii  "??~A{?~/CGF?FGF;"
        .ascii  "{AF@@@}/FGGGGCB;"
        .ascii  "?@~PPPM/CGF????;"
        .ascii  "{AF@@@}/FGGGICJ;"
        .ascii  "?@~PpPM/CGF?@AK;"
        .ascii  "??@yCBB/CIIDGGC;"
        .ascii  "A@@~@@@/CGGF???;"
        .ascii  "A@}???~/??FGGCN;"
        .ascii  "A@}???~/??BCGCB;"
        .ascii  "A@}?w?~/??FGFGF;"
        .ascii  "A`}_}`A/CGF?FGC;"
        .ascii  "A@]__O~/????CIF;"
        .ascii  "A@A|AB@/CIIFGCA;"
        .ascii  "???~@@?/???NGG?;"
        .ascii  "BCGo???/????@AK;"
        .ascii  "?@@~???/?GGN???;"
        .ascii  "?CA@AC?/???????;"
        .ascii  "???????/GGGGGGG;"
        .ascii  "???B???/???????;"
        .ascii  "?_OwGGw/N??FGGF;"
        .ascii  "]`]??__/N?@EGF?;"
        .ascii  "?_OwGGG/N??FGGC;"
        .ascii  "?_OwGG~/N??FGGN;"
        .ascii  "?OgGgO?/GCA@ACG;"
        .ascii  "?_}`}_?/GCA@ACG;"
        .ascii  "?_OWgGw/@???MHN;"
        .ascii  "]`}___?/GF????N;"
        .ascii  "???s???/GCA@ACG;"
        .ascii  "?_OyOOO/@?FGF??;"
        .ascii  "?Mpm__?/GCB?AAN;"
        .ascii  "??MpM??/GCA@ACG;"
        .ascii  "oGGoGGo/N??N??N;"
        .ascii  "oGGGo??/N???FGE;"
        .ascii  "?_OwGGw/N??FGGF;"
        .ascii  "?_OGo_O/@??EHE?;"
        .ascii  "?_OGw_O/@??CNC?;"
        .ascii  "?_OOoOg/N???N??;"
        .ascii  "????o??/GCA@CHE;"
        .ascii  "??oKBKo/KB??@@N;"
        .ascii  "?_o???o/N?FGGCN;"
        .ascii  "_OO_??o/N??FGGF;"
        .ascii  "_O_?o?o/N?FGFGF;"
        .ascii  "OGw?wGO/CHN@NHC;"
        .ascii  "?_Ow??w/@??@DJN;"
        .ascii  "OGOGoWG/CIEDGCA;"
        .ascii  "??_}A??/???NG??;"
        .ascii  "???}???/???N???;"
        .ascii  "??A}_??/??GN???;"
        .ascii  "_OO_??_/????@@?;"
;
; readwrite data section
;
        .psect  $LOCAL quad,pic,con,lcl,noshr,noexe,wrt
argl_qio:                               ; argumentlist SYS$QIOW
        .long   12
        .long   0                       ; efn
        .blkl   1                       ; channel
        .blkl   1                       ; function
        .address stat                   ; IOSB
        .long   0                       ; AST address
        .long   0                       ; AST parameter
        .blkl   1                       ; P1
        .blkl   1                       ; P2
        .blkl   1                       ; P3
        .long   0                       ; P4
        .blkl   1                       ; P5
        .blkl   1                       ; P6
argl_dassgn:                            ; argumentlist SYS$DASSGN
        .long   1
        .blkl   1                       ; channel
argl_cancel:                            ; argumentlist SYS$CANCEL
        .long   1
        .blkl   1                       ; channel
stat:   .blkq   1                       ; IO status block
char1:  .blkq   1                       ; terminal characteristics (old)
char2:  .blkq   1                       ; terminal characteristics (new)
char3:  .blkl   3                       ; terminal characteristics (old)
char4:  .blkl   3                       ; terminal characteristics (new)
typah:  .blkl   2                       ; type-ahead buffer
keybuf: .blkb   1                       ; keystroke buffer
ttchan: .blkw   1                       ; terminal channel
mbxchan:                                ; mailbox channel
        .blkw   1
garbchan:                               ; garbage channel
        .blkw   1
fstrow: .blkl   1
lstrow: .blkl   1
wrtbuf_siz=2048
wrtbuf_lim=1532
wrtpnt: .long   0                       ; writebuffer pointer
wrtbuf: .blkb   wrtbuf_siz              ; writebuffer
;
; code section
;
        .psect  $CODE quad,pic,con,lcl,shr,exe,nowrt
;***************************************
;
;  SCR_APP ( )
;
;  set application keypad and VT220/VT320/VT420 7 bit mode
;
;***************************************
        .entry  scr_app,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
;        movq    #^x007022313B32369B,(r0); write "<CSI>62;1"p"
        movl    #^x3B32369B,(r0)
        movw    #^x2231,B^4(r0)
        movb    #^x70,B^6(r0)
        addl2   #7,wrtpnt
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movw    #^x3D1B,(r0)         ; write "<ESC>="
        addl2   #2,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    100$
        jsb     flu_buf
100$:   ret
;***************************************
;
;  SCR_ASCIIFONT ( )
;
;  load ASCII font
;
;***************************************
        .entry  scr_asciifont,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x0F42281B,(r0)
        addl2   #4,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    200$
        jsb     flu_buf
200$:   ret
;***************************************
;
;  SCR_BEL ( )
;
;  ring bell
;
;***************************************
        .entry  scr_bel,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movb    #^x07,(r0)              ; write "<BEL>"
        addl2   #1,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    100$
        jsb     flu_buf
100$:   ret
;***************************************
;
;  SCR_BOX ( ROW , COL , HEIGTH , WIDTH )
;
;  draw box
;
;***************************************
        .entry  scr_box,^m<r2,r3,r4,r5,r7,r8,r9,r10>
        movl    @B^4(ap),r9
        movl    @B^8(ap),r10
        movl    @B^12(ap),r7
        movl    @B^16(ap),r8
        jsb     grf_chr                 ; change characterset to graphic
        pushl   r9
        pushl   r10
        jsb     pos_abs                 ; position to upper left corner
        popl    r10
        popl    r9
        subl2   #2,r8
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movb    #108,(r0)
        addl2   #1,wrtpnt
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movc5   #0,#0,#113,r8,(r0)
        addl2   r8,wrtpnt
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movb    #107,(r0)
        addl2   #1,wrtpnt
        addl2   #2,r8
        addl2   r7,r9
        decl    r9
        pushl   r9
        pushl   r10
        jsb     pos_abs                 ; position to lower left corner
        popl    r10
        popl    r9
        subl2   #2,r8
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movb    #109,(r0)
        addl2   #1,wrtpnt
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movc5   #0,#0,#113,r8,(r0)
        addl2   r8,wrtpnt
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movb    #106,(r0)
        addl2   #1,wrtpnt
        addl2   #2,r8
        subl2   #2,r7
        subl2   r7,r9
        movl    r7,r1
        pushl   r9
        jsb     ver_lop                 ; draw left vertical line
        popl    r9
        addl2   r8,r10
        subl2   #1,r10
        movl    r7,r1
        pushl   r9
        jsb     ver_lop                 ; draw rigth vertical line
        popl    r9
        jsb     nrm_chr                 ; change characterset to normal
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    700$
        jsb     flu_buf
700$:   ret
;***************************************
;
;  SCR_CANCEL
;
;  cancel
;
;***************************************
        .entry  scr_cancel,^m<>
        movw    ttchan,argl_cancel+4
        callg   argl_cancel,G^SYS$CANCEL; cancel outstanding IO
        ret
;***************************************
;
;  SCR_CLR ( )
;
;  clear screen
;
;***************************************
        .entry  scr_clr,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x004A329B,(r0)        ; write "<CSI>2J"
        addl2   #3,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    100$
        jsb     flu_buf
100$:   movl    #1,r9
        movl    #1,r10
        jsb     pos_abs                 ; position
        ret
;***************************************
;
;  SCR_CUR_OFF ( )
;
;  cursor off
;
;***************************************
        .entry  scr_cur_off,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
;        movq    #^x0000006C35323F9B,(r0); write "<CSI>?25l"
        movl    #^x35323F9B,(r0)
        movb    #^x6C,B^4(r0)
        addl2   #5,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    100$
        jsb     flu_buf
100$:   ret
;***************************************
;
;  SCR_CUR_ON ( )
;
;  cursor on
;
;***************************************
        .entry  scr_cur_on,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
;        movq    #^x0000006835323F9B,(r0); write "<CSI>?25h"
        movl    #^x35323F9B,(r0)
        movb    #^x68,B^4(r0)
        addl2   #5,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    100$
        jsb     flu_buf
100$:   ret
;***************************************
;
;  SCR_DEL_LIN ( ROW )
;
;  delete line
;
;***************************************
        .entry  scr_del_lin,^m<r9,r10>
        movl    @B^4(ap),r9
        movl    #1,r10
        jsb     pos_abs                 ; position
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movw    #^x4B9B,(r0)            ; write "<CSI>K"
        addl2   #2,wrtpnt
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x0035231B,(r0)        ; write "<ESC>#5"
        addl2   #3,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    200$
        jsb     flu_buf
200$:   ret
;***************************************
;
;  SCR_DEVTYP ( TYP )
;
;  which devicetype is terminal
;
;***************************************
        .entry  scr_devtyp,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movw    #^x639B,(r0)            ; write "<CSI>c"
        addl2   #2,wrtpnt
        jsb     flu_buf                 ; flush buffer
100$:   clrl    r10
        jsb     get_1                   ; try to read "<ESC>"
        cmpb    r10,#^x1B
        bneq    100$
200$:   clrl    r10
        jsb     get_1                   ; try to read "["
        cmpb    r10,#^x5B
        bneq    200$
300$:   clrl    r10
        jsb     get_1                   ; try to read "?"
        cmpb    r10,#63
        bneq    300$
500$:   clrl    r10
        jsb     get_1                   ; try to read "6"
        cmpb    r10,#54
        bneq    500$
900$:   clrl    r10
        jsb     get_1                   ; try to read "1/2/3"
        cmpb    r10,#49                 ; VT100
        bneq    1010$
        movl    #1,@B^4(ap)
        brb     1100$
1010$:  cmpb    r10,#50                 ; VT200
        bneq    1020$
        movl    #2,@B^4(ap)
        brb     1100$
1020$:  cmpb    r10,#51                 ; VT300
        bneq    1030$
        movl    #3,@B^4(ap)
        brb     1100$
1030$:  cmpb    r10,#52                 ; VT400
        bneq    1040$
        movl    #4,@B^4(ap)
        brb     1100$
1040$:  movl    #0,@B^4(ap)
1100$:  clrl    r10
        jsb     get_1                   ; try to read "c"
        cmpb    r10,#99
        bneq    1100$
        ret
;***************************************
;
;  SCR_EXIT
;
;  exit
;
;***************************************
        .entry  scr_exit,^m<r9,r10>
        tstl    wrtpnt                  ; test if flush buffer
        bleq    100$
        jsb     flu_buf
100$:   jsb     dsg_trm                 ; deassign terminal
        ret
;***************************************
;
;  SCR_FLUSH
;
;  flush
;
;***************************************
        .entry  scr_flush,^m<r9,r10>
        jsb     flu_buf
100$:   ret
;***************************************
;
;  SCR_FLU_TXT ( ROW , COL , TXT_STR , ATTR )
;
;  flush text to screen
;
;***************************************
        .entry  scr_flu_txt,^m<r2,r3,r4,r5,r9,r10>
        movl    #0,r10
        cmpl    (ap),#4                 ; test if attributes specified
        blss    100$
        movl    @B^16(ap),r10
100$:   jsb     set_atr                 ; change attributes
        movl    @B^4(ap),r9
        movl    @B^8(ap),r10
        jsb     pos_abs                 ; position
        movl    B^12(ap),r0
        movl    B^4(r0),r1
        cvtwl   (r0),r3
        moval   wrtbuf,r2
        addl2   wrtpnt,r2
        addl2   r3,wrtpnt
        movc3   r3,(r1),(r2)            ; write text
        movl    #0,r10
        jsb     set_atr                 ; change attributes
        jsb     flu_buf
500$:   ret
;***************************************
;
;  SCR_GET_KEY ( ROW , COL , KEY )
;
;  get key from screen
;
;***************************************
        .entry  scr_get_key,^m<r9,r10>
        movl    @B^4(ap),r9
        movl    @B^8(ap),r10
        jsb     pos_abs                 ; position
        jsb     flu_buf                 ; flush buffer
        clrl    r10
        jsb     get_1
        cmpb    #27,r10                 ; test if "<ESC> read
        bneq    200$
        jsb     get_tah                 ; read type-ahead-buffer
        tstw    typah                   ; test if empty
        bneq    50$
        movl    #3,r9
        jsb     get_1t
        cmpl    #-1,r10                 ; test if timeout
        beql    150$
        cmpb    #91,r10                 ; test if "[" read
        bneq    25$
        brb     300$
25$:    cmpb    #79,r10                 ; test if "O" read
        bneq    150$
        brb     400$
50$:    cmpb    #91,typah+2             ; test if "[" in type-ahead-buffer
        bneq    100$
        jsb     get_1
        brb     300$
100$:   cmpb    #79,typah+2             ; test if "O" in type-ahead-buffer
        bneq    150$
        jsb     get_1
        brb     400$
150$:   movl    #27,r10                 ; return "<ESC>"
        brw     2100$
200$:   cmpb    #155,r10                ; test if "<CSI>" read
        beql    300$
        cmpb    #143,r10                ; test if "<SS3>" read
        beql    400$
        brw     2100$                   ; return ASCII code
300$:   brw     500$
400$:   brw     1300$
500$:   jsb     get_1
        cmpb    #65,r10                 ; test if "A"-"D" read
        bgtr    700$                    ;
        cmpb    #68,r10                 ;
        blss    700$                    ;
        addl2   #236,r10
        brw     2100$                   ; return 301-304 (arrows)
700$:   cmpb    #49,r10                 ; test if "1"-"6" read
        bgtr    1200$                   ;
        cmpb    #54,r10                 ;
        blss    1200$                   ;
        movl    r10,r9
        jsb     get_1
        cmpb    #126,r10                ; "~" read
        bneq    900$
        addl3   #352,r9,r10
        brw     2100$                   ; return 401-406 (E1-E6)
900$:   subb2   #48,r9                  ; assume "0"-"9" read
        subb2   #48,r10
        mulb2   #10,r9
        addl2   r9,r10
        cmpl    #22,r10
        bgtr    1000$
        decl    r10
        cmpl    #26,r10
        bgtr    1000$
        decl    r10
        cmpl    #28,r10
        bgtr    1000$
        decl    r10
1000$:  addl2   #484,r10
        movl    r10,r9
        jsb     get_1                   ; skip "~"
        movl    r9,r10
        brw     2100$                   ; return 501-515 (F6-F20)
1200$:  movb    #155,r10                ; return CSI code
        brw     2100$
1300$:  jsb     get_1
        cmpb    #112,r10                ; test if "p"-"y" read
        bgtr    1500$                   ;
        cmpb    #121,r10                ;
        blss    1500$                   ;
        addl2   #489,r10
        brw     2100$                   ; return 601-610 (KP0-KP9)
1500$:  cmpb    #80,r10                 ; test if "P"-"S" read   
        bgtr    1600$                   ;
        cmpb    #83,r10                 ;
        blss    1600$                   ;
        addl2   #621,r10                ; return 701-704 (PF1-PF4)
        brw     2100$
1600$:  cmpb    #77,r10                 ; test if "M" read
        bneq    1700$
        movl    #705,r10
        brw     2100$                   ; return 705 (enter)
1700$:  cmpb    #109,r10                ; test if "m" read
        bneq    1800$
        movl    #706,r10
        brw     2100$                   ; return 706 (minus)
1800$:  cmpb    #108,r10                ; test if "l" read
        bneq    1900$
        movl    #707,r10
        brw     2100$                   ; return 707 (comma)
1900$:  cmpb    #110,r10                ; test if "n" read
        bneq    2000$
        movl    #708,r10
        brw     2100$                   ; return 708 (period)
2000$:  movl    #143,r10                ; return "<SS3>"
2100$:  movl    r10,@B^12(ap)
        ret
;***************************************
;
;  SCR_GET_LIN ( LIN_STR , ACTLEN , PMT_STR )
;
;  get line from keyboard
;
;***************************************
        .entry  scr_get_lin,^m<r6,r7,r8,r9,r10>
        tstl    wrtpnt                  ; test if flush buffer
        bleq    200$
        jsb     end_lin                 ; set end of line
        jsb     flu_buf                 ; flush buffer
200$:   movl    #0,r6
        movl    #0,r7
        cmpl    (ap),#3                 ; test if prompt specified
        blss    300$
        movl    B^12(ap),r0
        movl    B^4(r0),r7
        cvtwl   (r0),r6
300$:   clrl    r8
        movl    B^4(ap),r0
        movl    B^4(r0),r10
        cvtwl   (r0),r9
        jsb     get_n                   ; read line
        movl    r8,@B^8(ap)             ; return actual length
        ret
;***************************************
;
;  SCR_GET_MSG ( MSG , MSGLEN , OK )
;
;  get message
;
;***************************************
        .entry  scr_get_msg,^m<>
        movw    mbxchan,argl_qio+8
        movw    #IO$_READVBLK!IO$M_NOW,argl_qio+12
        movl    B^4(ap),r0
        movl    B^4(r0),argl_qio+28
        cvtwl   (r0),argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; read trapped message
        cmpl    #SS$_NORMAL,r0
        bneq    100$
        cmpw    #SS$_NORMAL,stat
        bneq    100$
        cvtwl   stat+2,@B^8(ap)
        movl    #TRUE,@B^12(ap)
        ret
100$:   movl    #FALSE,@B^12(ap)
        ret
;***************************************
;
;  SCR_GET_PW ( LIN_STR , ACTLEN , PMT_STR )
;
;  get password from keyboard
;
;***************************************
        .entry  scr_get_pw,^m<r6,r7,r8,r9,r10>
        tstl    wrtpnt                  ; test if flush buffer
        bleq    200$
        jsb     end_lin                 ; set end of line
        jsb     flu_buf                 ; flush buffer
200$:   movl    #0,r6
        movl    #0,r7
        cmpl    (ap),#3                 ; test if prompt specified
        blss    300$
        movl    B^12(ap),r0
        movl    B^4(r0),r7
        cvtwl   (r0),r6
300$:   clrl    r8
        movl    B^4(ap),r0
        movl    B^4(r0),r10
        cvtwl   (r0),r9
        jsb     get_no                  ; read line
        movl    r8,@B^8(ap)             ; return actual length
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movb    #^x0D,(r0)              ; write "<CR>" to wrap line
        addl2   #1,wrtpnt
        ret
;***************************************
;
;  SCR_GET_TXT ( ROW , COL , LIN_STR , ACTLEN , PMT_STR )
;
;  get text from screen
;
;***************************************
        .entry  scr_get_txt,^m<r6,r7,r8,r9,r10>
        movl    @B^4(ap),r9
        movl    @B^8(ap),r10
        jsb     pos_abs                 ; position
        tstl    wrtpnt                  ; test if flush buffer
        bleq    200$
        jsb     flu_buf
200$:   movl    #0,r6
        movl    #0,r7
        cmpl    (ap),#5                 ; test if prompt specified
        blss    300$
        movl    20(ap),r0
        movl    B^4(r0),r7
        cvtwl   (r0),r6
300$:   clrl    r8
        movl    B^12(ap),r0
        movl    B^4(r0),r10
        cvtwl   (r0),r9
        jsb     get_n                   ; read text
        movl    r8,@B^16(ap)            ; return actual length
        ret
;***************************************
;
;  SCR_HIT ( )
;
;  test if hit
;
;***************************************
        .entry  scr_hit,^m<>
        jsb     get_tah                 ; read type-ahead-buffer
        tstw    typah                   ; test if empty
        beql    200$
        movl    #TRUE,r0
        ret
200$:   movl    #FALSE,r0
        ret
;***************************************
;
;  SCR_HOR_LIN ( ROW , COL , LENGTH )
;
;  draw horizontal line
;
;***************************************
        .entry  scr_hor_lin,^m<r2,r3,r4,r5,r9,r10>
        movl    @B^4(ap),r9
        movl    @B^8(ap),r10
        jsb     pos_abs                 ; position
        jsb     grf_chr                 ; change characterset to graphic
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movc5   #0,#0,#113,@B^12(ap),(r0)
        addl2   @B^12(ap),wrtpnt
        jsb     nrm_chr                 ; change characterset to normal
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush
        blss    400$
        jsb     flu_buf
400$:   ret
;***************************************
;
;  SCR_NOTRAP ( )
;
;  notrap broadcasts
;
;***************************************
        .entry  scr_notrap,^m<>
        movw    ttchan,argl_qio+8
        movw    #IO$_SETMODE,argl_qio+12
        moval   char3,argl_qio+28
        movl    #12,argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; write old characteristics
        movw    garbchan,argl_dassgn+4
        callg   argl_dassgn,G^SYS$DASSGN; deassign terminal
        ret
;***************************************
;
;  SCR_PUT_BIGTXT ( ROW , COL , TXT_STR , ATTR )
;
;  put bigtext to screen
;
;***************************************
        .entry  scr_put_bigtxt,^m<r2,r3,r4,r5,r9,r10>
        movl    #0,r10
        cmpl    (ap),#4                 ; test if attributes specified
        blss    100$
        movl    @B^16(ap),r10
100$:   jsb     set_atr                 ; change attributes
        movl    @B^4(ap),r9
        movl    @B^8(ap),r10
        jsb     pos_abs                 ; position
        movl    B^12(ap),r0
        movl    B^4(r0),r1
        cvtwl   (r0),r3
        moval   wrtbuf,r2
        addl2   wrtpnt,r2
        movl    #^x0033231B,(r2)
        addl2   #3,wrtpnt
        addl2   #3,r2
        addl2   r3,wrtpnt
        movc3   r3,(r1),(r2)            ; write text upperpart
        movl    @B^4(ap),r9
        incl    r9
        movl    @B^8(ap),r10
        jsb     pos_abs                 ; position
        movl    B^12(ap),r0
        movl    B^4(r0),r1
        cvtwl   (r0),r3
        moval   wrtbuf,r2
        addl2   wrtpnt,r2
        movl    #^x0034231B,(r2)
        addl2   #3,wrtpnt
        addl2   #3,r2
        addl2   r3,wrtpnt
        movc3   r3,(r1),(r2)            ; write text lowerpart
        movl    #0,r10
        jsb     set_atr                 ; change attributes
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    600$
        jsb     flu_buf
600$:   ret
;***************************************
;  
;  SCR_PUT_LIN ( LIN_STR )
;
;  put line to screen
;
;***************************************
        .entry  scr_put_lin,^m<r2,r3,r4,r5,r9,r10>
        movl    B^4(ap),r0
        movl    B^4(r0),r1
        cvtwl   (r0),r3
        jsb     end_lin                 ; set end of line
        moval   wrtbuf,r2
        addl2   wrtpnt,r2
        addl2   r3,wrtpnt
        movc3   r3,(r1),(r2)            ; write line
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    200$
        jsb     flu_buf
200$:   ret
;***************************************
;
;  SCR_PUT_TXT ( ROW , COL , TXT_STR , ATTR )
;
;  put text to screen
;
;***************************************
        .entry  scr_put_txt,^m<r2,r3,r4,r5,r9,r10>
        movl    #0,r10
        cmpl    (ap),#4                 ; test if attributes specified
        blss    100$
        movl    @B^16(ap),r10
100$:   jsb     set_atr                 ; change attributes
        movl    @B^4(ap),r9
        movl    @B^8(ap),r10
        jsb     pos_abs                 ; position
        movl    B^12(ap),r0
        movl    B^4(r0),r1
        cvtwl   (r0),r3
        moval   wrtbuf,r2
        addl2   wrtpnt,r2
        addl2   r3,wrtpnt
        movc3   r3,(r1),(r2)            ; write text
        movl    #0,r10
        jsb     set_atr                 ; change attributes
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    500$
        jsb     flu_buf
500$:   ret
;***************************************
;
;  SCR_RETRAP ( HANDL )
;
;  retrap broadcasts
;
;***************************************
        .entry  scr_retrap,^m<>
        movw    mbxchan,argl_qio+8
        movw    #IO$_SETMODE!IO$M_WRTATTN,argl_qio+12
        movl    B^4(ap),argl_qio+28
        movl    #0,argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; setup broadcast handler
        ret
;***************************************
;
;  SCR_SCROLL ( NLIN )
;
;  scroll
;
;***************************************
        .entry  scr_scroll,^m<r2,r3,r9,r10>
        movl    @B^4(ap),r2
        tstl    r2
        blss    100$
        movl    lstrow,r9
        movl    #80,r10
        moval   end_lin,r3
        brb     200$
100$:   movl    fstrow,r9
        movl    #1,r10
        moval   ins_lin,r3
        mnegl   r2,r2
200$:   jsb     pos_abs
300$:   tstl    r2
        bleq    400$
        jsb     (r3)
        decl    r2
        brb     300$
400$:   cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    500$
        jsb     flu_buf
500$:   ret
;***************************************
;
;  SCR_SETSCROLL ( FIRST , LAST )
;
;  set scrolling region
;
;***************************************
        .entry  scr_setscroll,^m<r9,r10>
        movl    @B^4(ap),r9
        movl    @B^8(ap),r10
        movl    r9,fstrow
        movl    r10,lstrow
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movb    #^x9B,(r0)              ; write "<CSI>"
        divl3   #10,r9,r1
        addb3   #48,r1,B^1(r0)
        mull2   #10,r1
        subl2   r1,r9
        addb3   #48,r9,B^2(r0)
        movb    #^x3B,B^3(r0)           ; write ";"
        divl3   #10,r10,r1
        addb3   #48,r1,B^4(r0)
        mull2   #10,r1
        subl2   r1,r10
        addb3   #48,r10,B^5(r0)
        movb    #^x72,B^6(r0)           ; write "r"
        addl2   #7,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    100$
        jsb     flu_buf
100$:   ret
;***************************************
;
;  SCR_SOFTFONT1 ( )
;
;  load softfont 1
;
;***************************************
        .entry  scr_softfont1,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
;        movq    #^x303B303B313B3090,(r0)
;        movq    #^x40207B3B303B303B,B^8(r0)
        movl    #^x313B3090,(r0)
        movl    #^x303B303B,B^4(r0)
        movl    #^x303B303B,B^8(r0)
        movl    #^x40207B3B,B^12(r0)
        addl2   #16,wrtpnt
        jsb     flu_buf                 ; flush buffer unconditionally
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movc3   #1503,font1,(r0)
        addl2   #1503,wrtpnt
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
;        movq    #^x00000F4020281B9C,(r0)
        movl    #^x20281B9C,(r0)
        movw    #^x0F40,B^4(r0)
        addl2   #6,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    200$
        jsb     flu_buf
200$:   ret
;***************************************
;
;  SCR_SOFTFONT2 ( )
;
;  load softfont 2
;
;***************************************
        .entry  scr_softfont2,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
;        movq    #^x303B303B313B3090,(r0)
;        movq    #^x40207B3B303B303B,B^8(r0)
        movl    #^x313B3090,(r0)
        movl    #^x303B303B,B^4(r0)
        movl    #^x303B303B,B^8(r0)
        movl    #^x40207B3B,B^12(r0)
        addl2   #16,wrtpnt
        jsb     flu_buf                 ; flush buffer unconditionally
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movc3   #1503,font2,(r0)
        addl2   #1503,wrtpnt
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
;        movq    #^x00000F4020281B9C,(r0)
        movl    #^x20281B9C,(r0)
        movw    #^x0F40,B^4(r0)
        addl2   #6,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    200$
        jsb     flu_buf
200$:   ret
;***************************************
;
;  SCR_TRAP ( HANDL )
;
;  trap broadcasts
;
;***************************************
        .entry  scr_trap,^m<>
        tstw    ttchan                  ; test if channel assigned
        bneq    100$
        jsb     asg_trm
100$:   movw    ttchan,argl_qio+8
        movw    #IO$_SENSEMODE,argl_qio+12
        moval   char3,argl_qio+28
        movl    #12,argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; read old characteristics
        movl    char3,char4
        movl    char3+4,char4+4
        movl    char3+8,char4+8
        bisl2   #TT$M_NOBRDCST!TT$M_MBXDSABL,char4+4
        bisl2   #TT2$M_BRDCSTMBX,char4+8
        movw    #511,char4+2
        movw    ttchan,argl_qio+8
        movw    #IO$_SETMODE,argl_qio+12
        moval   char4,argl_qio+28
        movl    #12,argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; write new characteristics
        callg   argl_asnwthmbx,G^LIB$ASN_WTH_MBX; assign mailbox
        movw    mbxchan,argl_qio+8
        movw    #IO$_SETMODE!IO$M_WRTATTN,argl_qio+12
        movl    B^4(ap),argl_qio+28
        movl    #0,argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; setup broadcast handler
        ret
;***************************************
;
;  SCR_VER_LIN ( ROW , COL , LENGTH )
;
;  draw vertical line
;
;***************************************
        .entry  scr_ver_lin,^m<r9,r10>
        movl    @B^4(ap),r9
        movl    @B^8(ap),r10
        movl    @B^12(ap),r1
        tstl    r1                      ; test if LENGTH=0
        bleq    300$
        jsb     grf_chr                 ; change character set to graphic
        jsb     ver_lop                 ; make vertical loop
        jsb     nrm_chr                 ; change character set to normal
300$:   cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    400$
        jsb     flu_buf
400$:   ret
;***************************************
;
;  SCR_WHERE ( ROW , COL )
;
;  where on screen are we
;
;***************************************
        .entry  scr_where,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x006E369B,(r0)        ; write "<CSI>6n"
        addl2   #3,wrtpnt
        jsb     flu_buf                 ; flush buffer
100$:   clrl    r10
        jsb     get_1                   ; try to read "<ESC>"
        cmpb    r10,#^x1B
        bneq    100$
200$:   clrl    r10
        jsb     get_1                   ; try to read "["
        cmpb    r10,#^x5B
        bneq    200$
300$:   clrl    r10
        jsb     get_1                   ; try to read "row"
        cmpb    r10,#48
        blss    300$
        cmpb    r10,#57
        bgtr    300$
        subl2   #48,r10
        movl    r10,@B^4(ap)
500$:   clrl    r10
        jsb     get_1                   ; try to read "row"
        cmpb    r10,#^x3B
        beql    900$
        cmpb    r10,#48
        blss    500$
        cmpb    r10,#57
        bgtr    500$
        mull2   #10,@B^4(ap)
        subl2   #48,r10
        addl2   r10,@B^4(ap)
700$:   clrl    r10
        jsb     get_1                   ; try to read ";"
        cmpb    r10,#^x3B
        bneq    700$
900$:   clrl    r10
        jsb     get_1                   ; try to read "col"
        cmpb    r10,#48
        blss    900$
        cmpb    r10,#57
        bgtr    900$
        subl2   #48,r10
        movl    r10,@B^8(ap)
1100$:  clrl    r10
        jsb     get_1                   ; try to read "col"
        cmpb    r10,#^x52
        beql    1500$
        cmpb    r10,#48
        blss    1100$
        cmpb    r10,#57
        bgtr    1100$
        mull2   #10,@B^8(ap)
        subl2   #48,r10
        addl2   r10,@B^8(ap)
1300$:  clrl    r10
        jsb     get_1                   ; try to read "R"
        cmpb    r10,#^x52
        bneq    1300$
1500$:  ret
;***************************************
;
;  SCR_WID_132 ( )
;
;  width 132 columns
;
;***************************************
        .entry  scr_wid_132,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x68333F9B,(r0)        ; write "<CSI>?3h"
        addl2   #4,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    100$
        jsb     flu_buf
100$:   ret
;***************************************
;
;  SCR_WID_80 ( )
;
;  width 80 columns
;
;***************************************
        .entry  scr_wid_80,^m<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x6C333F9B,(r0)        ; write "<CSI>?3l"
        addl2   #4,wrtpnt
        cmpl    wrtpnt,#wrtbuf_lim      ; test if flush buffer
        blss    100$
        jsb     flu_buf
100$:   ret
;***************************************
;
;  asg_trm
;
;***************************************
asg_trm: .jsb_entry
        callg   argl_assign,G^SYS$ASSIGN; assign terminal
        movw    ttchan,argl_qio+8
        movw    #IO$_SENSEMODE,argl_qio+12
        moval   char1,argl_qio+28
        movl    #8,argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; read old characteristics
        movl    char1,char2
        movl    char1+4,char2+4
        movw    #511,char2+2
        movw    ttchan,argl_qio+8
        movw    #IO$_SETMODE,argl_qio+12
        moval   char2,argl_qio+28
        movl    #8,argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; write new characteristics
        rsb
;***************************************
;
;  dsg_trm
;
;***************************************
dsg_trm: .jsb_entry
        movw    ttchan,argl_qio+8
        movw    #IO$_SETMODE,argl_qio+12
        moval   char1,argl_qio+28
        movl    #8,argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; write old characteristics
        movw    ttchan,argl_dassgn+4
        callg   argl_dassgn,G^SYS$DASSGN; deassign terminal
        clrw    ttchan
        rsb
;***************************************
;
;  end_lin
;
;***************************************
end_lin: .jsb_entry
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movw    #^x0A0D,(r0)            ; write "<CR><LF>"
        addl2   #2,wrtpnt
        rsb
;***************************************
;
;  flu_buf
;
;***************************************
flu_buf: .jsb_entry
        movl    wrtpnt,r9
        moval   wrtbuf,r10
        jsb     put_n                   ; write buffer
        movl    #0,wrtpnt
        rsb
;***************************************
;
;  get_1, r10=code
;
;***************************************
get_1: .jsb_entry output=<r10>
        tstw    ttchan                  ; test if channel assigned
        bneq    100$
        jsb     asg_trm
100$:   movw    ttchan,argl_qio+8
        movw    #IO$_READVBLK!IO$M_NOECHO!IO$M_NOFILTR,argl_qio+12
        moval   keybuf,argl_qio+28
        movl    #1,argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; perform IO read operation
        movb    keybuf,r10
        rsb
;***************************************
;
;  get_1t, r10=code, r9=timeout
;
;***************************************
get_1t: .jsb_entry input=<r9>,output=<r10>
        tstw    ttchan                  ; test if channel assigned
        bneq    100$
        jsb     asg_trm
100$:   movw    ttchan,argl_qio+8
        movw    #IO$_READVBLK!IO$M_NOECHO!IO$M_NOFILTR!IO$M_TIMED,argl_qio+12
        moval   keybuf,argl_qio+28
        movl    #1,argl_qio+32
        movl    r9,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; perform IO read operation
        cmpw    #SS$_TIMEOUT,stat
        beql    200$
        movb    keybuf,r10
        rsb
200$:   movl    #-1,r10
        rsb
;***************************************
;
;  get_n, r10=stradr, r9=maxlen, r8=actlen, r7=pmtadr, r6=pmtlen
;
;***************************************
get_n: .jsb_entry input=<r6,r7,r9,r10>,output=<r8>
        tstw    ttchan                  ; test if terminal assigned
        bneq    200$
        jsb     asg_trm
200$:   movw    ttchan,argl_qio+8
        movw    #IO$_READPROMPT,argl_qio+12
        movl    r10,argl_qio+28
        movl    r9,argl_qio+32
        movl    #0,argl_qio+36
        movl    r7,argl_qio+44
        movl    r6,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; perform IO read operation
        movw    stat+2,r8
        rsb
;***************************************
;
;  get_no, r10=stradr, r9=maxlen, r8=actlen, r7=pmtadr, r6=pmtlen
;
;***************************************
get_no: .jsb_entry input=<r6,r7,r9,r10>,output=<r8>
        tstw    ttchan                  ; test if terminal assigned
        bneq    200$
        jsb     asg_trm
200$:   movw    ttchan,argl_qio+8
        movw    #IO$_READPROMPT!IO$M_NOECHO,argl_qio+12
        movl    r10,argl_qio+28
        movl    r9,argl_qio+32
        movl    #0,argl_qio+36
        movl    r7,argl_qio+44
        movl    r6,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; perform IO read operation
        movw    stat+2,r8
        rsb
;***************************************
;
;  get_tah
;
;***************************************
get_tah: .jsb_entry
        tstw    ttchan                  ; test if terminal assigned
        bneq    200$
        jsb     asg_trm
200$:   movw    ttchan,argl_qio+8
        movw    #IO$_SENSEMODE!IO$M_TYPEAHDCNT,argl_qio+12
        moval   typah,argl_qio+28
        movl    #8,argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; read type-ahead buffer
        rsb
;***************************************
;
;  grf_chr
;
;***************************************
grf_chr: .jsb_entry
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x0030281B,(r0)        ; write "<ESC>(0"
        addl2   #3,wrtpnt
        rsb
;***************************************
;
;  ins_lin
;
;***************************************
ins_lin: .jsb_entry
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x004C319B,(r0)        ; write "<CSI>1L"
        addl2   #3,wrtpnt
        rsb
;***************************************
;
;  nrm_chr
;
;***************************************
nrm_chr: .jsb_entry
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x0042281B,(r0)        ; write "<ESC>(B"
        addl2   #3,wrtpnt
        rsb
;***************************************
;
;  pos_abs, r10 = col, r9 = row
;
;***************************************
pos_abs: .jsb_entry input=<r9,r10>
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movb    #^x9B,(r0)              ; write "<CSI>"
        divl3   #10,r9,r1
        addb3   #48,r1,B^1(r0)
        mull2   #10,r1
        subl2   r1,r9
        addb3   #48,r9,B^2(r0)
        movb    #^x3B,B^3(r0)           ; write ";"
        divl3   #10,r10,r1
        addb3   #48,r1,B^4(r0)
        mull2   #10,r1
        subl2   r1,r10
        addb3   #48,r10,B^5(r0)
        movb    #^x48,B^6(r0)           ; write "H"
        addl2   #7,wrtpnt
        rsb
;***************************************
;
;  put_n, r10=stradr, r9=strlen
;
;***************************************
put_n: .jsb_entry input=<r9,r10>
        tstw    ttchan                  ; test if terminal assigned
        bneq    200$
        jsb     asg_trm
200$:   movw    ttchan,argl_qio+8
        movw    #IO$_WRITEVBLK,argl_qio+12
        movl    r10,argl_qio+28
        movl    r9,argl_qio+32
        movl    #0,argl_qio+36
        movl    #0,argl_qio+44
        movl    #0,argl_qio+48
        callg   argl_qio,G^SYS$QIOW     ; perform IO write operation
        rsb
;***************************************
;
;  set_atr, r10=attr
;
;***************************************
set_atr: .jsb_entry input=<r10>
        tstl    r10
        bgtr    100$
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x6D305B1B,(r0)        ; normal
        addl2   #4,wrtpnt
        brw     400$
100$:   cmpl    r10,#4
        blss    200$
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x6D375B1B,(r0)        ; revers
        addl2   #4,wrtpnt
        bicl2   #^x00000004,r10
200$:   cmpl    r10,#2
        blss    300$
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x6D355B1B,(r0)        ; blinking
        addl2   #4,wrtpnt               
        bicl2   #^x00000002,r10
300$:   cmpl    r10,#1
        blss    400$
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movl    #^x6D315B1B,(r0)        ; bold
        addl2   #4,wrtpnt
        bicl2   #^x00000001,r10
400$:   rsb
;***************************************
;
;  ver_lop, r10=col, r9=row, r1=n
;
;***************************************
ver_lop: .jsb_entry input=<r1,r9,r10>
100$:   pushl   r1
        pushl   r9
        pushl   r10
        jsb     pos_abs                 ; position
        popl    r10
        popl    r9
        popl    r1
        moval   wrtbuf,r0
        addl2   wrtpnt,r0
        movb    #120,(r0)
        addl2   #1,wrtpnt
        incl    r9
        decl    r1
        tstl    r1
        bgtr    100$
        rsb
        .end
