home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msyv90.asm < prev    next >
Assembly Source File  |  2020-01-01  |  91KB  |  3,723 lines

  1.     name msyv90
  2. ; File MSYV90.ASM
  3. ;       Copyright (C) 1982,1991, Trustees of Columbia University in the
  4. ;       City of New York.  Permission is granted to any individual or
  5. ;       institution to use, copy, or redistribute this software as long as
  6. ;       it is not sold for profit and this copyright notice is retained.
  7. ; Kermit system dependent module for VICTOR 9000/SIRIUS
  8. ;  Use with msuv90.asm and msxv90.asm.
  9. ; SPECIAL VERSION WITH NEAR COMPLETE SUPPORT OF TEKTRONIX 4010 EMULATION
  10. ; as of MS-DOS KERMIT version 3.02. Victor 9000 Kermit without
  11. ; Tektronix emulation will no longer be supported.
  12. ;
  13. ; Edit history:
  14. ; 2 March 1991 version 3.10
  15. ; Last modification: 2 March 1991
  16. ; 6 Dec 1988 Replace dynamic screen space with static segment aagraph (see
  17. ;  NOTE WELL msg below), add control of 7/8 bit displays, add TRANSLATE INPUT
  18. ;  table workings. [jrd]
  19. ; 1 Mar 1988 add TERMTB terminal status display table and correct use
  20. ;  of tektronix mode set to match that implemented in MSYIBM as of version
  21. ;  2.30.  Also add use of CAN (control-X) to exit tektronix temporary
  22. ;  mode. [bgp]
  23. ; 20 Sept 1987 clarify sequence of translation and 8 bit display. [jrd]
  24. ; 11 Sept 1987 Modify page_full routine for Tektronix emulation so that
  25. ;  the indicator box put in the lower left corner of the screen on page
  26. ;  full condition is put in with exclusive or instead of simple or.  Then
  27. ;  modified the homescr routine to remove that indicator box using an
  28. ;  exclusive or operation if the page full condition exists and to be sure
  29. ;  that the old text cursor is removed before moving the current cursor
  30. ;  location to the upper left corner. [bgp]
  31. ; 7 Sept 1987 Remove keep_delete, filter null in portch, filter DEL in
  32. ; terminal read section for VT100 (pass through for Tek), add parmsk. [jrd]
  33. ; 29 August 1987 add temporary Tektronix mode so that the receipt of an
  34. ;  ESCAPE FF (Tektronix clear screen sequence) will go to Tektronix mode with
  35. ;  a clear screen.  It will go back to the previous mode on the receipt of
  36. ;  an ESCAPE US sequence or by entering the escape character.
  37. ; 29 August 1987 add support for keyboard translation.    This uses a
  38. ;  modified version of the translator for the GENERIC MS-DOS version.
  39. ;  This modification required the addition of the following routines:
  40. ;    CQUERY - help on connect
  41. ;    CSTATUS - show status of connect
  42. ;    CQUIT - exit from connect
  43. ;    CHANG - hangup the phone (drop dtr)
  44. ;    DMPSCN - dump the screen
  45. ;    TRNPRS - toggle printer dump status
  46. ;    SNULL - send a null
  47. ;    KDOS - push to DOS
  48. ;    KLOGOFF - suspend session logging
  49. ;    KLOGON - resume session logging
  50. ;    CPAGE - clear tektronix screen
  51. ;    CHOME - move to home on tektronix screen
  52. ; 9 February 1987 Added set of keep_delete (byte) = 0 if delete to be
  53. ;  ignored by serial port routines [bgp]
  54. ; 7 August 1986 fill out procedure DUMPSCR - it was borrowed from MSYIBM
  55. ;  modified to fit the Victor format.  It required a modification of
  56. ;  LCLYINI to get the character set base [bgp]
  57. ;      7-DEC-85 ORIGINAL    BGP
  58. ;     20-FEB-86 CORRECTED FOR ERROR IN PUTMOD IN MSXV9000    (BGP)
  59. ;     22-FEB-86 CLEANED UP CHARACTER SET FOR TEK EMULATION    (BGP)
  60. ;     22-FEB-86 ADDED CODE TO SWALLOW ANSI ESCAPE SEQUENCES IN
  61. ;        HEATH EMULATION MODE                (BGP)
  62. ; ************************************************************
  63. ; Remove segment Graph and replace it with memory dynamically allocated
  64. ; from DOS via procedure sbrk in mssker.  Do allocation, verify that it
  65. ; is in the correct chunk of memory (and fix if necessary), initialize
  66. ; scrseg, and clear the area, all done in lclyini.    17 March 86
  67. ; Joe R. Doupnik
  68. ; Add global procedure Dumpscr, called by Ter in file msster, to dump screen
  69. ;   to a file. Just does a beep for now. 13 April 1986 [jrd]
  70. ;
  71. ; Added 'full' VT100 emulation using code by Andreas Stumpf
  72. ; (ZRZS@DS0RUS1I).    The significant parts that are not emulated are
  73. ;   esc c  - reset terminal
  74. ;   esc N  - ??
  75. ;   esc O  - ??
  76. ;   esc n  - ??
  77. ;   esc l  - ??
  78. ;   esc o  - ??
  79. ;   esc <  - go to ANSI mode (from VT52)
  80. ;   esc [ q    - fiddle with the LED's
  81. ;   esc [ h    - some modes not supported
  82. ;   esc [ l    - some modes not supported
  83. ;   esc [ i    - ??
  84. ;   esc [ p    - ??
  85. ;   esc [ y    - confidence tests
  86. ; and some codes that are not VT100 'standard' are supported
  87. ;   esc [ E    - ??
  88. ;   esc [ F    - ??
  89. ;   esc [ G    - ??
  90. ;   esc [ L    - ??
  91. ;   esc [ M    - ??
  92. ;   esc [ @    - ??
  93. ;   esc [ P    - ??
  94. ;   esc [ X    - ??
  95. ;   esc [ d    - ??
  96. ;   esc [ e    - ??
  97. ; 22 April 86 Bryan G. Peterson
  98.  
  99.     public    term, lclyini, vts, vtstat ; entry points
  100.     public    dumpscr, extmacro, vtmacname, vtmaclen, setchtab
  101.     public    cquery, cstatus, cquit, snull, kdos ; [bgp]
  102.     public    klogof, klogon, cpage, chome    ; [bgp]
  103.     public    chang, trnprs, dmpscn, chrout    ; [bgp]
  104.     public    termtb, trnmod
  105.     public    sescur, sesdisp, setnbios, fcsrtype
  106.  
  107. ; NOTE WELL - The Victor 9000 machine requires high resolution (graphics)
  108. ; memory to be located in the first 128KB of system memory, even though
  109. ; programs are loaded into the same area(!). Here we define a special graphics
  110. ; segment, aagraph, and request the assembler to located segments
  111. ; as shown below, with _STACK last!
  112. ; Further we MUST place MSYV90.OBJ first in the Link list of .objs.
  113. ; [jrd 8 Dec 1988].
  114. ;
  115. ; Start  Stop   Length Name                   Class
  116. ; 00000H 09C5FH 09C60H AAGRAPH                KCODE
  117. ; 09C60H 14FB0H 0B351H CODE                   KCODE
  118. ; 14FC0H 1768FH 026D0H CODE1                  KCODE
  119. ; 17690H 17690H 00000H CODE2                  KCODE
  120. ; 17690H 24E9BH 0D80CH DATA                   KDATA
  121. ; 24EA0H 2627FH 013E0H DATA1                  KDATA
  122. ; 26280H 26280H 00000H _TEXT                  CODE
  123. ; 26280H 26280H 00000H _DATA                  DATA
  124. ; 26280H 26280H 00000H CONST                  CONST
  125. ; 26280H 26280H 00000H _BSS                   BSS
  126. ; 26280H 26FC7H 00D48H _STACK                 STACK
  127. ;
  128. AAGRAPH    SEGMENT PUBLIC 'kcode'
  129.     DB    40032 DUP (?)        ; graphics memory
  130. AAGRAPH    ENDS
  131.  
  132. ; Do the "include mssdef.h" file after the aagraph declaration.
  133.     include mssdef.h
  134.  
  135. ;   Some extra ASCII definitions
  136. ENQ    EQU    5
  137. VTAB    EQU    0BH
  138. ETB    EQU    17H
  139. CAN    EQU    18H
  140. GS    EQU    1DH
  141. US    EQU    1FH
  142.  
  143. CURSOR_CHR EQU    '_'                     ; The cursor character
  144. CURSOR_TIME EQU 100            ; cursor on countdown period
  145. ;    this is the number of unsuccessful tries on getting a charcter
  146. ;    from the input port before turning on the cursor.
  147.  
  148. X_MAX    EQU    799
  149. Y_MAX    EQU    399
  150. TEK_X_MAX EQU    1023
  151. TEK_Y_MAX EQU    780
  152. TEXT_X_MAX EQU    789
  153. TEXT_Y_MAX EQU    389
  154. RPLINE    EQU    11            ; rows per text line
  155. CPCHAR    EQU    11            ; columns per text character
  156. R_MARG    EQU    781            ; right margin position
  157. CUR_LEN EQU    10            ; length of arms on graphics cursor
  158.  
  159. FALSE    EQU    0
  160. TRUE    EQU    1
  161.  
  162. SEG_CRTC EQU    0E800H            ; segment for crt controller
  163. OFF_CRTC EQU    0            ; offset for crt controller
  164.  
  165. modfrm    struc                ; format of mode line
  166.     db    ' Esc-chr:'
  167. m_echr    db    2 dup (?)
  168.     db    ' Help:'
  169. m_hlp    db    2 dup (?)
  170.     db    '? Port:'
  171. m_prt    db    1 dup (?)
  172.     db    ' Speed:'
  173. m_baud    db    5 dup (?)
  174.     db    ' Parity:'
  175. m_par    db    4 dup (?)
  176.     db    ' Echo:'
  177. m_echo    db    3 dup (?)
  178. m_term    db    13 dup (' ')            ; 13 bytes for terminal type
  179. m_prn    db    3 dup (' ')             ; show PRN when printer is on
  180.     db    ' $'                   ; must be dollar terminated
  181. modfrm    ends
  182.  
  183. data    segment
  184.     extrn    rdbuf:byte, flags:byte        ; to get access to emulation
  185.     extrn    dmpname:byte, filtst:byte, trans:byte, prnhand:word
  186.     extrn    kbdflg:byte,rxtable:byte,taklev:byte,takadr:word,mcctab:byte
  187.  
  188. termhlp db    CR,LF,'Terminal type of Heath-19, VT102, VT52, none,'
  189.     db    ' or Tek4010$'
  190.  
  191. termtb    db    5
  192.     mkeyw    'Heath-19',ttheath
  193.     mkeyw    'none',ttgenrc
  194.     mkeyw    'Tek4010',tttek
  195.     mkeyw    'VT102',ttvt100
  196.     mkeyw    'VT52',ttvt52
  197.  
  198. setchtab db    1            ; Set File Character-Set table
  199.     mkeyw    'CP437',437        ; hardware default Code Page
  200.  
  201. tty_generic db    ' None        '
  202. tty_tek4010 db    ' Tektronix   '
  203. tty_heath db    ' Heath-19    '
  204. tty_vt102 db    ' VT-102      '
  205. tty_vt52 db    ' VT-52       '
  206. tty_unkn  db    ' Unknown     '
  207. ; stuff for screen routines
  208. wflags    label    word        ; so we can push yflags
  209. yflags    db    ?        ; status flags...
  210.     db    0        ; extra byte for flags
  211. flags1    db    0        ; internal flags.
  212. prtscr    equ    80h            ; print screen pressed
  213. inited    equ    08h            ; been here before...
  214. wrapped equ    04h            ; on if wrapped on last char...
  215. argadr    dw    ?            ; address of arg blk
  216. crt_cols db    80            ; number of screen columns (typ 80)
  217. crt_lins db    24            ; number of screen rows - 1 (typ 24)
  218. oldsp    dw    0            ; offset to longjmp to for i/o failure
  219.  
  220. vtmacname dw    0            ; pointer to selected macro name
  221. vtmaclen db    0
  222. sescur    dw    0
  223.  
  224. modbuf    modfrm    <>            ; mode line buffer
  225. ; routine to call for captured output
  226. captrtn dw    ?
  227. ; some static data for mode line
  228. unkbaud db    'Unkwn'                 ; must be 5 chars...
  229. baudn    db    ' 45.5'
  230.     db    '   50'
  231.     db    '   75'
  232.     db    '  110'
  233.     db    '  135'
  234.     db    '  150'
  235.     db    '  300'
  236.     db    '  600'
  237.     db    ' 1200'
  238.     db    ' 1800'
  239.     db    ' 2000'
  240.     db    ' 2400'
  241.     db    ' 4800'
  242.     db    ' 9600'
  243.     db    '19200'
  244.     db    '38400'
  245. baudnsiz  equ    16            ; # of baud rates known (tbl size / 4)
  246. parnams db    'Even'
  247.     db    'Mark'
  248.     db    'None'
  249.     db    'Odd '                  ; must be 4 chars
  250.     db    'Spc '
  251. offmsg    db    'Off'
  252. onmsg    db    'On '
  253. lclmsg    db    'Lcl'
  254. remmsg    db    'Rem'
  255.  
  256. portno    db    ?
  257.  
  258. tscreen dw    1920 dup (?)        ; place to save text screen
  259. tcurloc db    2 dup (?)        ; column,row
  260. tscrseg dw    0F000H
  261. rptcur    db    27,'n$'                 ; request cursor location
  262. escseq    db    0            ; ANSI escape sequence indicator
  263.                     ; 0=none, 1=escape, 2=[, <0 eat chars
  264.                     ; until =0
  265.  
  266. ; stuff for the Tektronix emulation
  267.                     ; Order is essential:scrloc then scrseg
  268. scrloc    dw    0            ; offset of screen memory [jrd]
  269. scrseg    dw    0            ; segment of screen memory [jrd]
  270. parmsk    db    ?            ; 8/7 bit parity mask, for reception
  271. temp_tek db    FALSE            ; for temporary tektronix mode [bgp]
  272. temp_mode dw    0            ; previous mode for temp tek mode [bgp]
  273. tek_allowed db    TRUE            ; flag for screen memory ok
  274. no_tek_msg db    CR,LF,'SCREEN MEMORY ALLOCATION FAILED'
  275.     db    ' - TEKTRONIX EMULATION NOT ALLOWED',BELL,CR,LF,'$'
  276. first_in db    TRUE            ; this is the first time emulating
  277. intens    db    14            ; CRT intensity setting
  278. status_line dw    80 dup (?)        ; for CRT status line
  279.  
  280. bit_mask db    1,2,4,8,16,32,64,128
  281. combine dw    pixel_or
  282. t_combine dw    word_or
  283. start    dw    0,0            ; vector start point
  284. endpt    dw    0,0            ; end point (victor coords)
  285. cur_x    dw    0            ; tek coordinates of current point
  286. cur_y    dw    780
  287. text_x    dw    0            ; text cursor location (victor coords)
  288. text_y    dw    0            ; upper left corner
  289. cursor_cnt dw    0            ; cursor countdown
  290. cursor    db    FALSE            ; cursor state flag
  291. full_flag db    FALSE            ; flags page full condition
  292. x_inc    dw    1
  293. y_inc    dw    1
  294. delta_x dw    0
  295. delta_y dw    0
  296. part_accum dw    0            ; accumulator for line
  297. temp    dw    0            ; temporary storage
  298. c_mask    dw    0            ; mask for character work
  299. cur_stp dw    1            ; graphics cursor step
  300. crs_hor dw    0,0,0            ; cursor horizontal line (x1,x2,y)
  301. crs_ver dw    0,0,0            ; cursor vertical line (y1,y2,x)
  302. prtesc    db    FALSE            ; escape from port in GIN mode
  303. trmesc    db    FALSE            ; escape from terminal in GIN mode
  304.  
  305.  
  306. graph_mode db    FALSE            ; graphics mode flag
  307. echo_supp db    FALSE            ; echoplex suppression flag
  308. visible db    0            ; 0 to move, 1 to draw
  309. hiy    dw    0
  310. loy    db    0
  311. hix    dw    0
  312. lox    db    0
  313. lsb    db    0
  314. escflag db    0
  315. tekjump dw    TEKTXT,TEKESC,TEKHIY,TEKHIX
  316.  
  317. ; The next variable defines the bit masks for the text font
  318. font    dw    0,20H,70H,20H,20H,0,20H,20H,0,0,0 ; !
  319.     dw    0,88H,88H,88H,0,0,0,0,0,0,0 ; "
  320.     dw    0,88H,88H,3FEH,88H,3FEH,88H,88H,0,0,0 ; #
  321.     dw    0,1FCH,222H,22H,1FCH,220H,222H,1FCH,0,0,0 ; $
  322.     dw    0,10CH,8CH,40H,20H,10H,188H,184H,0,0,0 ; %
  323.     dw    0,10H,28H,10H,28H,144H,84H,178H,0,0,0 ; &
  324.     dw    0,30H,30H,20H,10H,0,0,0,0,0,0 ; '
  325.     dw    0,40H,20H,10H,10H,10H,20H,40H,0,0,0 ; (
  326.     dw    0,10H,20H,40H,40H,40H,20H,10H,0,0,0 ; )
  327.     dw    0,104H,88H,50H,3FEH,50H,88H,104H,0,0,0 ; *
  328.     dw    0,20H,20H,20H,3FEH,20H,20H,20H,0,0,0 ; +
  329.     dw    0,0,0,0,0,0,30H,30H,20H,10H,0 ; ,
  330.     dw    0,0,0,0,3FEH,0,0,0,0,0,0 ; -
  331.     dw    0,0,0,0,0,0,30H,30H,0,0,0 ; .
  332.     dw    0,100H,80H,40H,20H,10H,8,4,0,0,0 ; /
  333.     dw    0,0F8H,184H,242H,222H,212H,10CH,0F8H,0,0,0 ; 0
  334.     dw    0,20H,30H,20H,20H,20H,20H,70H,0,0,0 ; 1
  335.     dw    0,1FCH,202H,200H,1FCH,2,2,3FEH,0,0,0 ; 2
  336.     dw    0,3FEH,100H,80H,1C0H,200H,202H,1FCH,0,0,0 ; 3
  337.     dw    0,102H,102H,102H,3FEH,100H,100H,100H,0,0,0 ; 4
  338.     dw    0,3FEH,2,2,1FEH,200H,200H,1FEH,0,0,0 ; 5
  339.     dw    0,1FCH,2,2,1FEH,202H,202H,1FCH,0,0,0 ; 6
  340.     dw    0,3FEH,100H,80H,40H,20H,20H,20H,0,0,0 ; 7
  341.     dw    0,0F8H,104H,88H,1FCH,202H,202H,1FCH,0,0,0 ; 8
  342.     dw    0,1FCH,202H,202H,3FCH,200H,200H,1FCH,0,0,0 ; 9
  343.     dw    0,0,30H,30H,0,0,30H,30H,0,0,0 ; :
  344.     dw    0,0,30H,30H,0,0,30H,30H,20H,10H,0 ; ;
  345.     dw    0,80H,40H,20H,10H,20H,40H,80H,0,0,0 ; <
  346.     dw    0,0,0,3FEH,0,3FEH,0,0,0,0,0 ; =
  347.     dw    0,8,10H,20H,40H,20H,10H,8,0,0,0 ; >
  348.     dw    0,1FCH,202H,200H,1E0H,20H,0,20H,0,0,0 ; ?
  349.     dw    0,1FCH,202H,3E2H,212H,1E2H,2,1FCH,0,0,0 ; @
  350.     dw    0,70H,88H,104H,3FEH,202H,202H,202H,0,0,0 ; A
  351.     dw    0,0FEH,102H,102H,1FEH,202H,202H,1FEH,0,0,0 ; B
  352.     dw    0,1FCH,202H,2,2,2,202H,1FCH,0,0,0 ; C
  353.     dw    0,1FEH,202H,202H,202H,202H,202H,1FEH,0,0,0 ; D
  354.     dw    0,3FEH,2,2,7EH,2,2,3FEH,0,0,0 ; E
  355.     dw    0,3FEH,2,2,7EH,2,2,2,0,0,0 ; F
  356.     dw    0,1FCH,202H,2,382H,202H,202H,3FCH,0,0,0 ; G
  357.     dw    0,202H,202H,202H,3FEH,202H,202H,202H,0,0,0 ; H
  358.     dw    0,0F8H,20H,20H,20H,20H,20H,0F8H,0,0,0 ; I
  359.     dw    0,3E0H,80H,80H,80H,80H,84H,78H,0,0,0 ; J
  360.     dw    0,202H,102H,82H,7EH,82H,102H,202H,0,0,0 ; K
  361.     dw    0,2,2,2,2,2,2,3FEH,0,0,0 ; L
  362.     dw    0,306H,28AH,252H,222H,202H,202H,202H,0,0,0 ; M
  363.     dw    0,206H,20AH,212H,222H,242H,282H,302H,0,0,0 ; N
  364.     dw    0,1FCH,202H,202H,202H,202H,202H,1FCH,0,0,0 ; O
  365.     dw    0,1FEH,202H,202H,1FEH,2,2,2,0,0,0 ; P
  366.     dw    0,1FCH,202H,202H,202H,282H,102H,2FCH,0,0,0 ; Q
  367.     dw    0,1FEH,202H,202H,1FEH,82H,102H,202H,0,0,0 ; R
  368.     dw    0,1FCH,202H,2,1FCH,200H,202H,1FCH,0,0,0 ; S
  369.     dw    0,3FEH,20H,20H,20H,20H,20H,20H,0,0,0 ; T
  370.     dw    0,202H,202H,202H,202H,202H,302H,2FCH,0,0,0 ; U
  371.     dw    0,202H,202H,202H,104H,88H,50H,20H,0,0,0 ; V
  372.     dw    0,202H,202H,202H,222H,222H,154H,88H,0,0,0 ; W
  373.     dw    0,104H,88H,50H,20H,50H,88H,104H,0,0,0 ; X
  374.     dw    0,202H,104H,88H,50H,20H,20H,20H,0,0,0 ; Y
  375.     dw    0,3FEH,80H,40H,20H,10H,8,3FEH,0,0,0 ; Z
  376.     dw    0,70H,10H,10H,10H,10H,10H,70H,0,0,0 ; [
  377.     dw    0,4,8,10H,20H,40H,80H,100H,0,0,0 ; \
  378.     dw    0,70H,40H,40H,40H,40H,40H,70H,0,0,0 ; ]
  379.     dw    0,20H,70H,0A8H,124H,20H,20H,20H,0,0,0 ; ^
  380.     dw    0,0,0,0,0,0,0,0,0,0,7FFH ; _
  381.     dw    0,10H,20H,40H,0,0,0,0,0,0,0 ; `
  382.     dw    0,0,0,0F8H,100H,1F8H,104H,2F8H,0,0,0 ; a
  383.     dw    0,4,4,0FCH,104H,104H,104H,0FCH,0,0,0 ; b
  384.     dw    0,0,0,0F8H,104H,4,4,1F8H,0,0,0 ; c
  385.     dw    0,100H,100H,1F8H,104H,104H,104H,1F8H,0,0,0 ; d
  386.     dw    0,0,0,0F8H,104H,1FCH,4,1F8H,0,0,0 ; e
  387.     dw    0,20H,50H,10H,38H,10H,10H,10H,0,0,0 ; f
  388.     dw    0,0,0,1F8H,104H,104H,104H,1F8H,100H,100H,0F8H ; g
  389.     dw    0,4,4,0FCH,104H,104H,104H,104H,0,0,0 ; h
  390.     dw    0,0,20H,0,20H,20H,20H,20H,0,0,0 ; i
  391.     dw    0,0,40H,0,40H,40H,40H,40H,40H,50H,20H ; j
  392.     dw    0,4,4,44H,24H,3CH,44H,84H,0,0,0 ; k
  393.     dw    0,30H,20H,20H,20H,20H,20H,0F8H,0,0,0 ; l
  394.     dw    0,0,0,1DEH,222H,222H,222H,222H,0,0,0 ; m
  395.     dw    0,0,0,0FCH,104H,104H,104H,104H,0,0,0 ; n
  396.     dw    0,0,0,0F8H,104H,104H,104H,0F8H,0,0,0 ; o
  397.     dw    0,0,0,0FCH,104H,104H,104H,0FCH,4,4,4 ; p
  398.     dw    0,0,0,1F8H,104H,104H,104H,1F8H,100H,300H,100H ; q
  399.     dw    0,0,0,0FCH,104H,4,4,4,0,0,0 ; r
  400.     dw    0,0,0,0F8H,4,0F8H,100H,0FCH,0,0,0 ; s
  401.     dw    0,10H,10H,78H,10H,10H,50H,20H,0,0,0 ; t
  402.     dw    0,0,0,84H,84H,84H,84H,178H,0,0,0 ; u
  403.     dw    0,0,0,104H,104H,88H,50H,20H,0,0,0 ; v
  404.     dw    0,0,0,222H,222H,222H,222H,1DCH,0,0,0 ; w
  405.     dw    0,0,0,88H,50H,20H,50H,88H,0,0,0 ; x
  406.     dw    0,0,0,104H,104H,104H,104H,1F8H,100H,100H,0F8H ; y
  407.     dw    0,0,0,0F8H,40H,20H,10H,0F8H,0,0,0 ; z
  408.     dw    0,0C0H,20H,20H,10H,20H,20H,0C0H,0,0,0 ; {
  409.     dw    0,20H,20H,20H,20H,20H,20H,20H,0,0,0 ; |
  410.     dw    0,18H,20H,20H,40H,20H,20H,18H,0,0,0 ; }
  411.     dw    0,0,1CH,222H,1C0H,0,0,0,0,0,0 ; ~
  412.  
  413. ; stuff for ANSI emulation [as]
  414. SUPERBIOS equ    0dfh        ; SuperBios-Interrupt
  415.  
  416. tt    struc            ; structure of keyboardtable
  417. head    dw    2 dup (?)
  418. kd0    db    104*3 dup (?)
  419. kd12    dw    104*3 dup (?)
  420. extrtabl db    256 dup (?)
  421. tt    ends
  422.  
  423. afirst    db    0
  424. ; Parameterblock for setting/getting of keyboard-table
  425. parmblock db    3
  426. laenge    dw    1196        ; length of table
  427. offs    dw    offset oldtable
  428. segm    dw    seg oldtable
  429. ; block for call to get Console-driver-address
  430. condev    dw    1
  431. drivadr dd    0        ; address of consoledriver
  432. ;
  433. oldtable tt    <,,,>        ; saved old keytable
  434. numtbl    tt    <,,,>        ; Table with Num-Keypad
  435. apptbl    tt    <,,,>        ; Table with Appl-Keypad
  436. ; In order to avoid smashing stuff that may already be in the multi-char
  437. ; sequence table for the keyboard (or as little as possible) put it near the
  438. ; end of the table - the following parameters tells how deep into the table
  439. ; to start putting stuff
  440. START_EXTRTBL EQU 160
  441. ; Cursorsequences ANSI
  442. appcur    db    0        ; flag for cursor key modes
  443. curseq    db    3,ESCAPE,'[A',3,ESCAPE,'[B',3,ESCAPE,'[D',3,ESCAPE,'[C'
  444. curapp    db    3,ESCAPE,'OA',3,ESCAPE,'OB',3,ESCAPE,'OD',3,ESCAPE,'OC'
  445. ; Applikationkeypad
  446. appkeys db    0        ; flag for keypad modes
  447. applik    db    3,ESCAPE,'[A',3,ESCAPE,'[B',3,ESCAPE,'[D',3,ESCAPE,'[C'
  448.     db    3,ESCAPE,'OP',3,ESCAPE,'OQ',3,ESCAPE,'OR',3,ESCAPE,'OS'
  449.     db    3,ESCAPE,'Ow',3,ESCAPE,'Ox',3,ESCAPE,'Oy',3,ESCAPE,'Om'
  450.     db    3,ESCAPE,'Ot',3,ESCAPE,'Ou',3,ESCAPE,'Ov',3,ESCAPE,'Ol'
  451.     db    3,ESCAPE,'Oq',3,ESCAPE,'Or',3,ESCAPE,'Os',3,ESCAPE,'OM'
  452.     db    3,ESCAPE,'Op',3,ESCAPE,'On'
  453. sesctbl db    'DEHMNOZn|o[>=78c<)(#' ; table for char following single ESCAPE
  454.     db    FF        ; ESCAPE FF goes temporary tektronix [bgp]
  455. sesclen equ    $-sesctbl
  456. ; now the table for routines to process those characters
  457. sescsub dw    processD
  458.     dw    processE
  459.     dw    processH
  460.     dw    processM
  461.     dw    ignore
  462.     dw    ignore
  463.     dw    procc0        ; same as ESCAPE [0c
  464.     dw    ignore
  465.     dw    ignore
  466.     dw    ignore
  467.     dw    processbra
  468.     dw    processgt
  469.     dw    processeq
  470.     dw    process7
  471.     dw    process8
  472.     dw    ignore
  473.     dw    ignore
  474.     dw    processrp
  475.     dw    processlp
  476.     dw    processlb
  477.     dw    process_ff    ; temporary tektronix mode [bgp]
  478. ; table for the last characters in a ESCAPE'[' sequence
  479. mesctbl db    '`EFGABCDHLM@PXKJfghilmrcnpyqde'
  480. mesclen equ    $-mesctbl
  481. ; processing routine table for ESCAPE'[' sequences
  482. mescsub dw    proce
  483.     dw    proce
  484.     dw    procuf
  485.     dw    procug
  486.     dw    curmov
  487.     dw    curmov
  488.     dw    curmov
  489.     dw    curmov
  490.     dw    procH
  491.     dw    procL
  492.     dw    procM
  493.     dw    procAt
  494.     dw    procP
  495.     dw    procX
  496.     dw    procK
  497.     dw    procJ
  498.     dw    procH
  499.     dw    procg
  500.     dw    prochl
  501.     dw    ignore
  502.     dw    prochl
  503.     dw    proclm
  504.     dw    procr
  505.     dw    procc
  506.     dw    procn
  507.     dw    ignore
  508.     dw    ignore
  509.     dw    ignore
  510.     dw    procld
  511.     dw    procle
  512. ;
  513. top    db    1        ; scrolling region margins
  514. bottom    db    24
  515. escpnt    dw    offset escstring
  516. escstring db    80 dup (?)    ; save area for Escape sequence
  517. tabstops db    0,0,0,0,0,0,0,0 ; tabulator stops
  518.     db    1,0,0,0,0,0,0,0
  519.     db    1,0,0,0,0,0,0,0
  520.     db    1,0,0,0,0,0,0,0
  521.     db    1,0,0,0,0,0,0,0
  522.     db    1,0,0,0,0,0,0,0
  523.     db    1,0,0,0,0,0,0,0
  524.     db    1,0,0,0,0,0,0,0
  525.     db    1,0,0,0,0,0,0,0
  526.     db    1,0,0,0,0,0,0,0
  527. chrset_mask db    0        ; mask for selecting character set
  528.  
  529. char_base dw    0        ; screen character base
  530. crlf    db    cr,lf
  531. dmphand dw    0        ; handle for screen dump [bgp]
  532. dumpbuf db    80 dup (?),CR,LF ; line buffer for screen dump
  533. dumpsep db    FF,CR,LF    ; put in file between screen dumps
  534. dmperr    db    ' WARNING: cannot open the screen dump file$'
  535. data    ends
  536.  
  537. code1    segment
  538.  
  539. ; Control text cursor. AL = 0 for off, 1 for on (nominally underline)
  540. fcsrtype proc    far
  541.     call    csrtype
  542.     ret
  543. fcsrtype endp
  544. code1    ends
  545.  
  546. code    segment
  547.     extrn    prtchr:near,outchr:near,cmblnk:near,poscur:near
  548.     extrn    putmod:near,clrmod:near,beep:near,sbrk:near    ; [jrd]
  549.     extrn    comnd:near,isfile:near                ; [bgp]
  550.     extrn    msuinit:near, keybd:near            ; [bgp]
  551.     extrn    pntchr:near, pntflsh:near
  552.  
  553.     assume    cs:code,ds:data,es:nothing
  554.  
  555. ; do initialization local to this module...
  556. ; mainly get console driver address to speed up screen access [as]
  557. ; Memory for screen must lie either entirely within the first 64K of memory,
  558. ; or within the second 64K of memory due to architecture of the CRT controller
  559. ; connections. It must also be aligned on an exact multiple of 32 bytes
  560. ; (rather than just on paragraph alignment).
  561. ; 7 August 1986 added code to get character set base for dump [bgp]
  562.  
  563. LCLYINI proc    near
  564.     mov    flags.vtflg,ttvt102 ; start as a VT102
  565.     call    msuinit     ; init keyboard module msuv90 [bgp]
  566.     mov    ah,DCONIO
  567.     mov    dl,ESCAPE    ; to set nowrap
  568.     int    DOS
  569.     mov    dl,'w'
  570.     int    DOS
  571.     mov    ax,ds
  572.     mov    es,ax
  573.     mov    ax,14        ; function 'get driveraddress'
  574.     mov    bx,offset condev
  575.     int    SUPERBIOS    ; address is now in drivadr
  576.                 ; setup screen
  577.     mov    ax,aagraph    ; segment of graphics memory (See Note above)
  578.     cmp    ax,1000H    ; start in lower half? [bgp sub-mod]
  579.     jae    lclyini1    ; ae = no
  580.     cmp    ax,63BH     ; maximum segment in lower half
  581.     jb    lclyini3    ; b = low enough to work, go on
  582. lclyini1:
  583.     cmp    ax,163BH    ; maximum segment in top half
  584.     jb    lclyini3    ; b = ok - go on
  585. lclyini2:            ; Tektronix emulation screen won't work...
  586.     mov    dx,offset no_tek_msg ; tell the user we can't do it
  587.     mov    ah,PRSTR
  588.     int    DOS
  589.     mov    tek_allowed,FALSE ; and flag it
  590.     jmp    lclyini4
  591.  
  592. lclyini3:            ; Tektronix will work fine
  593.     inc    ax        ; force round-up
  594.     shr    ax,1        ; divide by two
  595.     shl    ax,1        ; multiply by two - now multiple of 32
  596.     mov    scrseg,ax    ; save it [end bgp sub-mod]
  597.     push    es
  598.     call    clrscr        ; make sure it is clear
  599.     pop    es        ; end of mod [jrd]
  600.     mov    tek_allowed,TRUE ; flag that tektronix is ok
  601.  
  602. lclyini4:
  603.     push    es
  604.     mov    ax,0F000H    ; point at base of screen memory
  605.     mov    es,ax
  606.     mov    ax,word ptr es:3838 ; note:  this should be the last character
  607.                 ; of the last line on the screen - if it was
  608.                 ; cleared as Kermit usually does when it starts
  609.                 ; up, this will be a space - it must be a space!
  610.     and    ax,7FFH     ; strip off mode bits
  611.     sub    ax,' '          ; minus which char it is
  612.     mov    char_base,ax    ; and save it
  613.     pop    es
  614.     ret
  615. LCLYINI endp
  616.  
  617. ; We need to save the arguments to TERM where they are a little more
  618. ; accessible than in the way they were passed
  619.  
  620. ARGINI    proc    near            ; read passed arguments
  621.     mov    bx,argadr        ; base of argument block
  622.     mov    al,[bx].flgs        ; get flags
  623.     and    al,CAPT+EMHEATH+TRNCTL+LCLECHO+MODOFF
  624.     mov    yflags,al        ; mask for allowable and save
  625.     and    flags1,not (PRTSCR)    ; these are allowable
  626.                     ; (others remain).
  627.     mov    al,[bx].prt
  628.     cmp    al,portno        ; using same port?
  629.     je    argin1            ; yes, go on
  630.     and    flags1,not inited    ; else re-init stuff
  631.     mov    first_in,TRUE        ; graphics too...
  632. argin1:
  633.     mov    portno,al        ; update port number
  634.     mov    ax,[bx].captr
  635.     mov    captrtn,ax        ; buffer capture routine
  636.     mov    parmsk,0ffh        ; parity mask, assume parity = None
  637.     cmp    [bx].parity,parnon    ; is parity None?
  638.     je    argini1         ; e = yes, keep all 8 bits
  639.     mov    parmsk,07fh        ; else keep lower 7 bits
  640. argini1:ret                ; that's it
  641. ARGINI    endp
  642.  
  643.                     ; Toggle Mode Line
  644. trnmod    proc    near
  645.     cmp    flags.modflg,1        ; mode line enabled and owned by us?
  646.     jne    trnm1            ; ne = no, don't touch it
  647.     test    yflags,modoff        ; mode line already off?
  648.     jnz    trnm2            ; nz = yes, go turn on
  649.     or    yflags,modoff        ; say modeline is toggled off
  650.     call    clrmod            ; clear mode line
  651. trnm1:    clc                ; clear c bit so don't exit Connect
  652.     ret
  653. trnm2:    cmp    flags.vtflg,0        ; emulating a terminal?
  654.     jne    trnm3            ; ne = yes
  655.     push    dx            ; scroll screen to save bottom line
  656.     mov    ah,prstr        ; for terminal type none
  657.     mov    dx,offset crlf
  658.     int    dos
  659.     pop    dx
  660. trnm3:    call    modlin            ; turn on modeline
  661.     and    yflags,not modoff    ; say modeline is not toggled off
  662.     clc
  663.     ret
  664. trnmod    endp
  665.  
  666. ; We need to generate the mode line and output it
  667.  
  668. MODLIN    proc    near            ; turn on mode line
  669.     push    es
  670.     push    ds
  671.     pop    es            ; make sure es is correct
  672.     mov    al,trans.escchr        ; Connect mode escape character
  673.     mov    modbuf.m_echr,' '       ; first char is initial space
  674.     mov    modbuf.m_hlp,' '        ; goes here too.
  675.     cmp    al,32            ; printable?
  676.     jnb    modl1            ; yes, keep going
  677.     add    al,40h            ; made printable
  678.     mov    modbuf.m_echr,'^'       ; note control char
  679.     mov    modbuf.m_hlp,'^'
  680. modl1:
  681.     mov    modbuf.m_echr+1,al    ; fill in character
  682.     mov    modbuf.m_hlp+1,al
  683.     mov    bx,argadr        ; get argument block
  684.     mov    al,[bx].baudb        ; get baud bits
  685.     mov    si,offset unkbaud    ; assume unknown baud
  686.     cmp    al,baudnsiz        ; too big?
  687.     jnb    modl2            ; yes, use default
  688.     mov    cl,5            ; each is 5 bytes long
  689.     mul    cl
  690.     mov    ah,0
  691.     add    ax,offset baudn
  692.     mov    si,ax
  693. modl2:
  694.     mov    cx,size m_baud        ; length of baud space
  695.     mov    di,offset modbuf.m_baud
  696.     cld
  697.     rep    movsb            ; copy in baud rate
  698.     mov    al,[bx].parity        ; get parity code
  699.     mov    cl,2            ; each is 4 bytes long...
  700.     shl    al,cl
  701.     mov    ah,0
  702.     add    ax,offset parnams    ; names of parity settings
  703.     mov    si,ax
  704.     mov    cx,4            ; each is 4 long
  705.     mov    di,offset modbuf.m_par
  706.     rep    movsb
  707.     mov    si,offset remmsg    ; Assume remote echoing.
  708.     test    yflags,lclecho        ; Is remote side echoing?
  709.     jz    modl4            ; Yes, keep going
  710.     mov    si,offset lclmsg    ; Else it's local echoing.
  711. modl4:
  712.     mov    cx,3            ; size of on/off
  713.     mov    di,offset modbuf.m_echo
  714.     rep    movsb
  715.     mov    al,'1'
  716.     cmp    portno,1        ; 1=1
  717.     je    modl5
  718.     mov    al,'2'                  ; 0=2
  719. modl5:
  720.     mov    modbuf.m_prt,al     ; fill in port number
  721.     mov    cl,13
  722.     mov    di,offset modbuf.m_term ; fill in terminal type
  723.     mov    si,offset tty_generic    ; assume generic first
  724.     cmp    flags.vtflg,TTGENRC
  725.     je    modl6
  726.     mov    si,offset tty_heath    ; try heath
  727.     cmp    flags.vtflg,TTHEATH
  728.     je    modl6
  729.     mov    si,offset tty_vt102    ; try vt100
  730.     cmp    flags.vtflg,TTVT100
  731.     je    modl6
  732.     mov    si,offset tty_vt52    ; try vt52
  733.     cmp    flags.vtflg,TTVT52
  734.     je    modl6
  735.     mov    si,offset tty_tek4010    ; try tektronix
  736.     cmp    flags.vtflg,TTTEK
  737.     je    modl6
  738.     mov    si,offset tty_unkn
  739. modl6:
  740.     rep    movsb
  741.     mov    modbuf.m_prn,' '        ; assume not printing
  742.     mov    modbuf.m_prn+1,' '
  743.     mov    modbuf.m_prn+2,' '
  744.     test    yflags,PRTSCR
  745.     jz    modl7            ; not
  746.     mov    modbuf.m_prn,'P'
  747.     mov    modbuf.m_prn+1,'R'
  748.     mov    modbuf.m_prn+2,'N'
  749. modl7:
  750.     mov    dx,offset modbuf    ; where it is
  751.     call    putmod
  752.     pop    es
  753.     ret
  754. MODLIN    endp
  755.  
  756. ; This is the entry point for terminal emulation
  757. ; Added option of VT100 emulation
  758.  
  759. TERM    proc    near        ; terminal emulator entry point
  760.     mov    oldsp,sp    ; remember stack for i/o failure,
  761.     mov    argadr,ax    ; save argument ptr
  762.     push    es        ; save caller's extra segment address
  763.     mov    ax,seg data
  764.     mov    es,ax
  765.     call    argini        ; init options from arg address
  766.     call    save_mode    ; [bgp]
  767.     cmp    flags.vtflg,TTTEK ; emulating TEKTRONIX?
  768.     jne    term0        ; no
  769.     call    tek4010     ; go look like a TEKTRONIX
  770.     jmp    quit1
  771. term0:
  772.     test    flags1,inited    ; have we run yet?
  773.     jz    term1        ; no, forget this part
  774.     call    restscr     ; restore screen
  775.     jmp    term2
  776. term1:
  777.     call    cmblnk        ; clear it off
  778. term2:
  779.     or    flags1,inited    ; remember we've run already.
  780.     call    clrmod        ; empty mode line
  781.     test    yflags,modoff    ; is mode line disabled?
  782.     jnz    term3        ; yes, skip it
  783.     call    modlin        ; turn on mode line
  784. term3:
  785.     cmp    flags.vtflg,TTVT100 ; emulating VT100?
  786.     jne    lp
  787.     call    ansie
  788.     jmp    quit
  789. lp:
  790.     call    portchr     ; char at port?
  791.     jnc    lp1        ; nc = yes
  792.     jmp    chkinp        ; no, keep going
  793. ; we want to swallow any ANSI escapes that come for now
  794. ; they are all of the form ESCAPE [ nn ; nn ; nn ; nn a
  795. ; where n is a numeric character, and a is a non-numeric character
  796. lp1:    test    flags.remflg,d8bit ; keep 8 bits for displays?
  797.     jnz    lp2        ; nz = yes
  798.     and    al,7fh        ; strip 8th bit
  799. lp2:    cmp    escseq,0    ; escape sequence in progress?
  800.     jne    eat_esc_seq    ; yes
  801.     cmp    al,ESCAPE    ; got an escape?
  802.     jne    no_esc        ; no
  803.     mov    escseq,1    ; yes, flag it
  804.     jmp    chkinp
  805. eat_esc_seq:
  806.     cmp    escseq,1    ; got [?
  807.     jne    eat_esc_seq2    ; yes
  808.     cmp    al,FF        ; ESCAPE FF is go temp tek mode [bgp]
  809.     jne    eat_esc_seq0    ; no [bgp]
  810.     cmp    tek_allowed,FALSE ; is tek mode allowed? [bgp]
  811.     jne    eat_esc_seq00    ; yes, do it [bgp]
  812.     mov    dx,offset no_tek_msg ; tell them about it [bgp]
  813.     mov    ah,PRSTR    ; [bgp]
  814.     int    DOS        ; [bgp]
  815.     jmp    end_esc     ; all through [bgp]
  816. eat_esc_seq00:
  817.     mov    escseq,0    ; not doing escape now [bgp]
  818.     call    savescr     ; save current screen [bgp]
  819.     call    tektemp     ; do it for a while [bgp]
  820.     jnc    eat_esc_seq000    ; carry=exit like esc char [bgp]
  821.     call    clrmod        ; clear mode line [bgp]
  822.     jmp    quit1        ; screen already saved [bgp]
  823. eat_esc_seq000:
  824.     call    restscr     ; restore the screen [bgp]
  825.     jmp    end_esc     ; all through [bgp]
  826. eat_esc_seq0:
  827.     cmp    al,'['
  828.     je    eat_esc_seq1
  829.     push    ax        ; not [, print esc and char
  830.     mov    al,ESCAPE
  831.     call    outtty        ; send the escape
  832.     pop    ax        ; and the following character
  833.     mov    escseq,0    ; no escape sequence
  834.     jmp    no_esc
  835. eat_esc_seq1:
  836.     mov    escseq,2    ; flag [
  837.     jmp    chkinp
  838. eat_esc_seq2:
  839.     cmp    al,';'          ; check for terminator
  840.     je    chkinp
  841.     cmp    al,'0'
  842.     jl    end_esc
  843.     cmp    al,'9'
  844.     jg    end_esc
  845.     jmp    chkinp        ; no terminator, keep eating
  846. end_esc:mov    escseq,0    ; end of sequence
  847.     jmp    chkinp
  848. no_esc:    cmp    rxtable+256,0        ; translation turned off?
  849.     je    no_esc1            ; e = yes, no translation
  850.     push    bx
  851.     mov    bx,offset rxtable    ; address of translate table
  852.     xlatb                ; new char is in al
  853.     pop    bx
  854. no_esc1:call    outtty        ; print on terminal
  855.  
  856. chkinp:    call    keybd        ; get and translate a key [bgp]
  857.     jc    quit        ; carry=esc character entered - quit [bgp]
  858.     jmp    lp        ; keep looping [bgp]
  859. quit:      call    clrmod        ; erase mode line
  860.     call    savescr     ; save screen
  861. quit1:     call    rest_mode    ; [bgp]
  862.     mov    al,yflags
  863.     mov    bx,argadr
  864.     mov    [bx].flgs,al    ; update flags in arg block
  865.     pop    es        ; restore segment register
  866.     ret            ; and return to caller
  867. TERM    endp
  868.  
  869. ; ANSI, VT100 emulation by Andreas Stumpf
  870.  
  871. ANSIE    proc    near
  872.     cmp    afirst,1    ; have we run yet?
  873.     jnz    ansi2        ; no, forget this part
  874.     mov    bx,ds        ; now restore keyboard too
  875.     mov    es,bx
  876.     mov    bx,offset parmblock
  877.     mov    ax,18
  878.     int    SUPERBIOS
  879.     jmp    ansi3
  880. ansi2:    call    initansi
  881. ansi3:    mov    afirst,1    ; remember we've run already.
  882. portc:    call    portchr     ; char at port?
  883.     jc    achkinp     ; c = no, get char from keyboard
  884.     call    doansi        ; handle it somehow
  885. achkinp:
  886.     call    keybd        ; get and translate a key stroke [bgp]
  887.     jnc    portc        ; carry=esc char entered - quit [bgp]
  888. aquit:    call    finiansi    ; fix keyboard up
  889.     ret
  890. ANSIE    endp
  891.  
  892. ; DOANSI actually takes care of emulating the ANSI screen control stuff
  893. ; code by Andreas Stumpf - it expects the character to be in al
  894.  
  895. DOANSI    proc    near
  896.     test    flags.remflg,d8bit     ; keep 8 bits for displays?
  897.     jnz    w00a            ; nz = yes
  898.     and    al,7fh            ; strip 8th bit
  899. w00a:    cmp    al,ESCAPE        ; got an escape?
  900.     jne    w00            ; ne = no
  901.     jmp    procesc0        ; escape terminates Escape-sequence,
  902. w00:                    ; so it has to be tested first
  903.     cmp    escseq,0        ; escape sequence in progress?
  904.     jne    w0a            ; ne = yes, no translation
  905.     cmp    rxtable+256,0        ; translation turned off?
  906.     je    w0a            ; e = yes, no translation
  907.     push    bx
  908.     mov    bx,offset rxtable    ; address of translate table
  909.     xlatb                ; new char is in al
  910.     pop    bx
  911. w0a:    cmp    al,'X'-40h      ; Control-X ?
  912.     jne    w0
  913.     jmp    ignore
  914. w0:
  915.     cmp    al,'Z'-40h      ; Control-Z
  916.     jne    w01
  917.     jmp    ignore
  918. w01:
  919.     cmp    escseq,0    ; escape sequence in progress?
  920.     je    w02
  921.     jmp    procesc     ; yes
  922. w02:
  923.     cmp    al,' '
  924.     jb    controls
  925.     or    al,chrset_mask    ; [bgp]
  926.     jmp    noesc
  927. controls:
  928.     cmp    al,LF        ; Linefeed,Formfeed and Vertical tab are
  929.                 ; processed as 'Scroll down, if at
  930.                 ; bottom margin, same function as ESCAPE'D'
  931.     jne    w1
  932.     jmp    processD    ; perform scrolling if necessary
  933. w1:    cmp    al,FF
  934.     jne    w2
  935.     jmp    processD
  936. w2:    cmp    al,11        ; vertical tab
  937.     jne    w3
  938.     jmp    processD
  939. w3:    cmp    al,TAB        ; horizontal tab
  940.     jne    w4
  941.     call    get_cur_pos    ; get cursor position
  942.     mov    al,dh        ; work on it here
  943.     mov    cx,80
  944.     sub    cl,al        ; # of cols to search for tab
  945.     cmp    cl,0        ; already off the end?
  946.     jg    t0        ; no
  947.     mov    cl,0
  948.     jmp    t1        ; go to right margin
  949. t0:
  950.     xor    ah,ah
  951.     mov    di,offset tabstops
  952.     add    di,ax        ; address of first tabstop to look for
  953.     cld
  954.     mov    ax,1        ; compare table with 1
  955.     repnz    scasb        ; cl=0 is right margin
  956. t1:
  957.     sub    cl,80
  958.     neg    cl
  959.     mov    dh,cl        ; set new col pos
  960.     call    set_cur_pos    ; done...
  961.     jmp    ignore
  962. w4:    cmp    al,14        ; shift to extra set?
  963.     jne    w5
  964.     mov    chrset_mask,80H ; set top bit on these
  965.     jmp    ignore
  966. w5:    cmp    al,15        ; shift to normal set?
  967.     jne    w6
  968.     mov    chrset_mask,0    ; clear top bit
  969.     jmp    ignore
  970.  
  971. w6:    cmp    al,DEL        ; DEL char? [jrd]
  972.     jne    w7        ; ne = no
  973.     jmp    ignore        ; ignore DEL
  974. w7:    jmp    noesc        ; else echo char to screen.
  975.  
  976. procesc0:            ; start of escape sequence processing
  977.     mov    escpnt,offset escstring
  978.     mov    escseq,1    ; flag it
  979.     jmp    doansi_d    ; done with it
  980.  
  981. procesc:            ; have just got an escape
  982.     cmp    escseq,1    ; single char ESCape ?
  983.     je    procesc1    ; yes process it
  984.     inc    escseq
  985.     inc    escpnt        ; store escape sequence for
  986.     mov    bx,escpnt    ; further processing
  987.     mov    [bx],al
  988.     cmp    escseq,3
  989.     jg    proccont1
  990.     cmp    escseq,0    ; [bgp]
  991.     jle    proccont1a    ; [bgp]
  992.     cmp    al,'?'          ; 1st char after ESCAPE'[' may be a '?'
  993.     jne    proccont1
  994. proccont1a:
  995.     jmp    doansi_d    ; done with it
  996. proccont1:
  997.     cmp    al,';'
  998.     jne    proccont2
  999.     jmp    doansi_d
  1000. proccont2:
  1001.     cmp    al,'-'          ; may be first char of a number
  1002.     jne    proccont3    ; continue checking
  1003.     mov    bx,escpnt
  1004.     cmp    byte ptr [bx-1],'0' ; preceding char in [0..9] ?
  1005.     jl    procmin1    ; if yes, then syntax error =>
  1006.     jmp    ignore        ; ignore Escapesequence
  1007. procmin1:
  1008.     cmp    byte ptr [bx-1],'9'
  1009.     jg    procmin2
  1010.     jmp    ignore
  1011. procmin2:
  1012.     jmp    doansi_d
  1013. proccont3:
  1014.     cmp    al,'0'
  1015.     jl    proccont
  1016.     cmp    al,'9'
  1017.     jg    proccont
  1018.     jmp    doansi_d    ; ESCAPE-seq hasn't finished yet
  1019. proccont:
  1020.     jmp    procmulti    ; other char than 0..9 ';' => process them
  1021. procesc1:    ; function dispatcher for single char Escapesequences
  1022.     mov    di,offset sesctbl
  1023.     mov    cx,sesclen
  1024.     cld
  1025.     repnz    scasb        ; search for legal char following ESCAPE
  1026.     cmp    al,[di-1]
  1027.     jnz    notrecognized
  1028.     mov    bx,sesclen
  1029.     sub    bx,cx        ; get offset in table
  1030.     dec    bx
  1031.     shl    bx,1
  1032.     add    bx,offset sescsub
  1033.     mov    escseq,0    ; Escape sequence has finished
  1034.     jmp    [bx]
  1035. notrecognized:
  1036.     jmp    noesc
  1037.  
  1038. processbra:            ; introduction of multi-char Escapesequence
  1039.     mov    escseq,2
  1040.     inc    escpnt
  1041.     mov    bx,escpnt
  1042.     mov    [bx],al     ; save that char
  1043.     jmp    doansi_d    ; and get next one
  1044.  
  1045. processH:
  1046.     call    get_cur_pos    ; get cursor position
  1047.     mov    al,dh        ; get column here
  1048.     dec    al        ; range 0 to 79
  1049.     mov    bx,offset tabstops
  1050.     xor    ah,ah
  1051.     add    bx,ax
  1052.     mov    byte ptr [bx],1
  1053.     jmp    ignore
  1054.  
  1055. processD:
  1056.     call    get_cur_pos    ; get cursor position
  1057.     cmp    dl,bottom    ; is it last line?
  1058.     je    delline     ; yes, need to insert
  1059.     inc    dl        ; move down one line
  1060.     call    set_cur_pos
  1061.     jmp    ignore        ; done
  1062. delline:            ; perform a scroll-up
  1063.     push    dx        ; save where we were
  1064.     mov    dl,top
  1065.     mov    dh,1        ; goto (top,1)
  1066.     call    set_cur_pos
  1067.     mov    al,ESCAPE
  1068.     call    outtty
  1069.     mov    al,'M'          ; delete line
  1070.     call    outtty
  1071.     pop    dx        ; get back where we were
  1072.     push    dx
  1073.     mov    dh,1        ; column 1
  1074.     call    set_cur_pos
  1075.     mov    al,ESCAPE
  1076.     call    outtty
  1077.     mov    al,'L'          ; insert line
  1078.     call    outtty
  1079.     pop    dx        ; get it back again
  1080.     cmp    dh,1
  1081.     je    processD1    ; done
  1082.     call    set_cur_pos    ; move to final position
  1083. processD1:
  1084.     jmp    ignore
  1085.  
  1086. processE:
  1087.     mov    al,CR        ; same as ESCAPE'D', but in col 1
  1088.     call    outtty        ; so write out Carriage return
  1089.     jmp    processD
  1090.  
  1091. processM:
  1092.     call    get_cur_pos    ; get cursor position
  1093.     cmp    dl,top
  1094.     je    insline     ; yes, jump to insert
  1095.     dec    dl        ; move up one
  1096.     call    set_cur_pos
  1097.     jmp    ignore
  1098. insline:            ; perform a scroll-down
  1099.     push    dx        ; save current position
  1100.     mov    dl,bottom
  1101.     mov    dh,1        ; 1. position to bottom margin
  1102.     call    set_cur_pos
  1103.     mov    al,ESCAPE    ; 2. delete line
  1104.     call    outtty
  1105.     mov    al,'M'
  1106.     call    outtty
  1107.     mov    dl,top
  1108.     mov    dh,1        ; 3. position to top margin
  1109.     call    set_cur_pos
  1110.     mov    al,ESCAPE
  1111.     call    outtty
  1112.     mov    al,'L'          ; 4. insert line with ESCAPE 'L'
  1113.     call    outtty
  1114.     pop    dx        ; get back my position
  1115.     cmp    dh,1        ; first col?
  1116.     je    processM1    ; yes
  1117.     call    set_cur_pos
  1118. processM1:
  1119.     jmp    ignore        ; all done
  1120.  
  1121. processeq:            ; set applikation keypad
  1122.     mov    ax,ds
  1123.     mov    es,ax
  1124.     mov    cx,8
  1125.     mov    di, offset apptbl.extrtabl
  1126.     add    di,START_EXTRTBL ; don't want to start at the top
  1127.     cmp    appcur,0    ; cursor keys application ?
  1128.     je    peq1
  1129.     mov    si,offset curapp
  1130.     jmp    peq2
  1131. peq1:    mov    si,offset curseq
  1132. peq2:    rep    movsw        ; move cursor keys to key-table
  1133.     mov    appkeys,1
  1134.     mov    bx,offset parmblock
  1135.     mov    byte ptr [bx],2
  1136.     mov    offs,offset apptbl
  1137.     mov    ax,18
  1138.     int    SUPERBIOS    ; set new keytable
  1139.     jmp    ignore
  1140.  
  1141. processgt:            ; set numeric keypad
  1142.     mov    ax,ds
  1143.     mov    es,ax
  1144.     mov    cx,8
  1145.     mov    di, offset numtbl.extrtabl
  1146.     add    di,START_EXTRTBL ; don't want to start at the top
  1147.     cmp    appcur,0
  1148.     je    pgt1
  1149.     mov    si,offset curapp
  1150.     jmp    pgt2
  1151. pgt1:    mov    si,offset curseq
  1152. pgt2:    rep    movsw
  1153.     mov    appkeys,0
  1154.     mov    bx,offset parmblock
  1155.     mov    byte ptr [bx],2
  1156.     mov    offs,offset numtbl
  1157.     mov    ax,18
  1158.     int    SUPERBIOS
  1159.     jmp    ignore
  1160.  
  1161. process7:            ; save cursor position
  1162.     mov    al,ESCAPE
  1163.     call    outtty
  1164.     mov    al,'j'
  1165.     jmp    noesc
  1166.  
  1167. process8:            ; restore cursor position
  1168.     mov    al,ESCAPE
  1169.     call    outtty
  1170.     mov    al,'k'
  1171.     jmp    noesc
  1172.  
  1173. process_ff:    ; temporary tektronix mode if allowed [bgp]
  1174.     cmp    tek_allowed,FALSE ; ok? [bgp]
  1175.     jne    process_ff1    ; yes [bgp]
  1176.     mov    dx,offset no_tek_msg ; tell them [bgp]
  1177.     mov    ah,PRSTR    ; [bgp]
  1178.     int    DOS        ; [bgp]
  1179.     jmp    ignore        ; end of sequence [bgp]
  1180. process_ff1:
  1181.     call    savescr     ; save the screen [bgp]
  1182.     mov    escseq,0    ; [bgp]
  1183.     call    tektemp     ; [bgp]
  1184.     jc    process_ff2    ; carry=esc char entered [bgp]
  1185.     call    restscr     ; restore the screen [bgp]
  1186.     jmp    ignore        ; end of sequence [bgp]
  1187. process_ff2:
  1188.     pop    ax        ; return address from call to DOANSI [bgp]
  1189.                 ; this is kludgey but it is necessary to
  1190.                 ; make this look like we are actually at
  1191.                 ; the point right after calling keybd and
  1192.                 ; receiving an esc char.
  1193.     call    finiansi    ; restore old keyboard [bgp]
  1194.     pop    ax        ; imagine that we have returned from ANSI [bgp]
  1195.     call    clrmod        ; clear off the mode line [bgp]
  1196.     jmp    quit1        ; normal exit but no save screen! [bgp]
  1197.  
  1198. procmulti:    ; function dispatcher for multi-character escape-sequences
  1199.         ; AL has terminating character
  1200.     mov    cx,ds
  1201.     mov    es,cx
  1202.     mov    di,offset mesctbl
  1203.     mov    cx,mesclen
  1204.     cld
  1205.     repnz    scasb
  1206.     cmp    al,[di-1]
  1207.     jnz    notrec        ; didn't find it in table
  1208.     mov    bx,mesclen
  1209.     sub    bx,cx        ; get offset in table
  1210.     dec    bx
  1211.     shl    bx,1
  1212.     add    bx,offset mescsub
  1213.     jmp    [bx]
  1214. notrec: jmp    noesc
  1215.  
  1216. curmov: ; process Cursor movements
  1217.     cmp    escseq,3    ; has no mumeric argument
  1218.     jne    pars
  1219. curmov0:
  1220.     mov    al,ESCAPE
  1221.     call    outtty
  1222.     mov    bx,escpnt
  1223.     mov    al,[bx]
  1224.     jmp    noesc        ; print it without '['
  1225. pars:                ; parse numeric argument
  1226.     mov    bx,offset escstring+2 ; skip ESCAPE'['
  1227.     call    getnum        ; getnum returns the number in DL
  1228.     xor    dh,dh
  1229.     cmp    dl,80
  1230.     jg    curmovend
  1231.     cmp    dl,0
  1232.     jl    curmovend
  1233.     je    curmov0
  1234.     mov    cx,dx        ; becomes loop counter
  1235.     mov    bx,escpnt
  1236.     mov    bl,[bx]     ; put last char of sequence in bl
  1237. parsl2:
  1238.     mov    al,ESCAPE
  1239.     call    outtty
  1240.     mov    al,bl
  1241.     call    outtty
  1242.     loop    parsl2
  1243. curmovend:
  1244.     jmp    ignore        ; ignore invalid positioning
  1245.  
  1246. procg:
  1247.     mov    bx,offset escstring+2
  1248.     call    getnum
  1249.     cmp    dl,0
  1250.     jne    procg1
  1251.     call    get_cur_pos
  1252.     mov    al,dh        ; current col here
  1253.     dec    al        ; range 0 to 79
  1254.     mov    bx,offset tabstops
  1255.     xor    ah,ah
  1256.     add    bx,ax
  1257.     mov    byte ptr [bx],0
  1258.     jmp    ignore
  1259. procg1:
  1260.     cmp    dl,3
  1261.     jne    procg3
  1262.     mov    cx,80
  1263.     push    es
  1264.     push    ds
  1265.     pop    es        ; make sure in right segment
  1266.     mov    di,offset tabstops
  1267.     xor    ax,ax
  1268.     rep    stosb
  1269.     pop    es        ; get old es back
  1270. procg3:
  1271.     jmp    ignore
  1272.  
  1273. procE:
  1274.     mov    al,CR        ; go to col 1
  1275.     call    outtty
  1276. procle:
  1277.     mov    bx,escpnt
  1278.     mov    byte ptr [bx],'B' ; process cursor down
  1279.     jmp    curmov
  1280.  
  1281. procuF:
  1282.     mov    al,CR        ; go to col 1
  1283.     call    outtty
  1284.     mov    bx, escpnt
  1285.     mov    byte ptr [bx],'A' ; cursor up
  1286.     jmp    curmov
  1287.  
  1288. procuG:
  1289.     mov    bx,offset escstring+2
  1290.     call    getnum
  1291.     cmp    dl,0
  1292.     jg    procug1
  1293.     mov    dl,1
  1294. procug1:
  1295.     cmp    dl,80
  1296.     jle    procug2
  1297.     mov    dl,80
  1298. procug2:
  1299.     mov    cl,dl
  1300.     call    get_cur_pos
  1301.     mov    dh,cl        ; set new column
  1302.     call    set_cur_pos
  1303.     jmp    ignore
  1304.  
  1305. procld:
  1306.     mov    bx,offset escstring+2
  1307.     call    getnum
  1308.     cmp    dl,0
  1309.     jg    procld1
  1310.     mov    dl,1
  1311. procld1:
  1312.     cmp    dl,24
  1313.     jle    procld2
  1314.     mov    dl,24
  1315. procld2:
  1316.     mov    cl,dl
  1317.     call    get_cur_pos
  1318.     mov    dl,cl
  1319.     call    set_cur_pos
  1320.     jmp    ignore
  1321.  
  1322. procH:                ; position cursor
  1323.     mov    bx,offset escstring+2
  1324.     call    getnum
  1325.     cmp    dl,1
  1326.     jge    procH0
  1327.     mov    dl,1        ; provide default for invalid address
  1328. procH0:
  1329.     cmp    dl,24
  1330.     jg    badH
  1331.     cmp    byte ptr [bx],';'
  1332.     jne    procH01
  1333.     inc    bx
  1334. procH01:
  1335.     push    dx        ; save row value
  1336.     call    getnum
  1337.     pop    ax        ; get it back here
  1338.     cmp    dl,1
  1339.     jge    procH1
  1340.     mov    dl,1
  1341. procH1:
  1342.     cmp    dl,80
  1343.     jg    badH
  1344.     mov    dh,dl        ; get in right places
  1345.     mov    dl,al
  1346.     call    set_cur_pos
  1347. badH:
  1348.     jmp    ignore
  1349.  
  1350. procL:
  1351.     mov    bx,offset escstring+2
  1352.     call    getnum
  1353.     mov    cx,dx
  1354.     cmp    cx,0
  1355.     jg    procL0
  1356.     mov    cx,1
  1357.     jmp    procL1
  1358. procL0:
  1359.     cmp    cx,24
  1360.     jle    procL1
  1361.     mov    cx,1
  1362. procL1:
  1363.     call    get_cur_pos
  1364.     mov    bh,dl
  1365.     mov    bl,dh        ; save these
  1366. procL2:             ; perform a insert line
  1367.     mov    dl,bottom
  1368.     mov    dh,1
  1369.     call    set_cur_pos
  1370.     mov    al,ESCAPE
  1371.     call    outtty
  1372.     mov    al,'M'
  1373.     call    outtty
  1374.     mov    dl,bh        ; get in right place
  1375.     mov    dh,bl
  1376.     call    set_cur_pos
  1377.     mov    al,ESCAPE
  1378.     call    outtty
  1379.     mov    al,'L'
  1380.     call    outtty
  1381.     loop    procL2
  1382.     jmp    ignore
  1383.  
  1384. procM:
  1385.     mov    bx,offset escstring+2
  1386.     call    getnum
  1387.     mov    cx,dx
  1388.     cmp    cx,0
  1389.     jg    procM0
  1390.     mov    cx,1
  1391.     jmp    procM1
  1392. procM0:
  1393.     cmp    cx,24
  1394.     jle    procM1
  1395.     mov    cx,1
  1396. procM1:
  1397.     call    get_cur_pos
  1398.     mov    bh,dl
  1399.     mov    bl,dh
  1400. procM2:             ; perform a delete line
  1401.     mov    al,ESCAPE
  1402.     call    outtty
  1403.     mov    al,'M'
  1404.     call    outtty
  1405.     mov    dl,bottom
  1406.     mov    dh,1
  1407.     call    set_cur_pos
  1408.     mov    al,ESCAPE
  1409.     call    outtty
  1410.     mov    al,'L'
  1411.     call    outtty
  1412.     mov    dl,bh        ; get in right places
  1413.     mov    dh,bl
  1414.     call    set_cur_pos
  1415.     loop    procM2
  1416.     jmp    ignore
  1417.  
  1418. procAt:             ; insert blank characters
  1419.     mov    bx,offset escstring+2
  1420.     call    getnum
  1421.     mov    cx,dx
  1422.     sub    cx,1
  1423.     mov    al,ESCAPE
  1424.     call    outtty
  1425.     mov    al,'@'
  1426.     call    outtty
  1427.     mov    al,' '
  1428.     call    outtty
  1429.     mov    al,BS
  1430.     call    outtty
  1431.     cmp    cx,0
  1432.     jle    procat1
  1433. procat2:
  1434.     mov    al,' '
  1435.     call    outtty
  1436.     mov    al,BS
  1437.     call    outtty
  1438.     loop    procat2
  1439. procat1:
  1440.     mov    al,ESCAPE
  1441.     call    outtty
  1442.     mov    al,'O'
  1443.     call    outtty
  1444.     jmp    ignore
  1445.  
  1446. procP:
  1447. procX:
  1448.     mov    bx,offset escstring+2
  1449.     call    getnum
  1450.     mov    cx,dx
  1451.     cmp    cx,0
  1452.     jg    procX1
  1453.     mov    cx,1
  1454. procX1:
  1455.     mov    al,ESCAPE
  1456.     call    outtty
  1457.     mov    al,'N'
  1458.     call    outtty
  1459.     loop    procX1
  1460.     jmp    ignore
  1461.  
  1462. procr:                ; set margins
  1463.     mov    top,1
  1464.     mov    bottom,24
  1465.     mov    bx,offset escstring+2
  1466.     call    getnum
  1467.     cmp    dl,1
  1468.     jl    procr1
  1469.     cmp    dl,23
  1470.     jg    procr1
  1471.     mov    top,dl
  1472. procr1:
  1473.     inc    bx
  1474.     call    getnum
  1475.     cmp    dl,top
  1476.     jl    procr2
  1477.     cmp    dl,24
  1478.     jg    procr2
  1479.     mov    bottom,dl
  1480. procr2:
  1481.     mov    dh,1        ; After inspecting what the VAX EDT editor does,
  1482.     mov    dl,1        ; it appears that ESCAPE [ Pn r should leave
  1483.     call    set_cur_pos    ; the cursor in the upper left corner [bgp]
  1484.     jmp    ignore
  1485.  
  1486. procc:                ; Terminal status request
  1487.     mov    bx,offset escstring+2
  1488.     cmp    byte ptr [bx],'>'
  1489.     je    procc2
  1490.     cmp    byte ptr [bx],'0'
  1491.     je    procc0
  1492.     cmp    byte ptr [bx],'c'
  1493.     je    procc0
  1494.     jmp    ignore
  1495. procc0:
  1496.     push    wflags        ; need to save these
  1497.     and    yflags,not lclecho ; force no echo for these
  1498.     mov    al,ESCAPE
  1499.     call    outprt
  1500.     mov    al,'['
  1501.     call    outprt
  1502.     mov    al,'?'
  1503.     call    outprt
  1504.     mov    al,'1'
  1505.     call    outprt
  1506.     mov    al,';'          ; signal AVO option - we sort of have it
  1507.     call    outprt
  1508.     mov    al,'2'
  1509.     call    outprt
  1510.     mov    al,'c'
  1511.     call    outprt
  1512.     pop    wflags        ; get back old flags
  1513. procc2:
  1514.     jmp    ignore
  1515.  
  1516. procn:                ; device status report
  1517.     mov    bx,offset escstring+2
  1518.     cmp    byte ptr [bx],'5'
  1519.     je    procn5
  1520.     cmp    byte ptr [bx],'6'
  1521.     je    procn6
  1522.     jmp    ignore
  1523. procn5:             ; return operating status 'no malfunction'
  1524.     push    wflags        ; force no echo
  1525.     and    yflags,not lclecho
  1526.     mov    al,ESCAPE
  1527.     call    outprt
  1528.     mov    al,'['
  1529.     call    outprt
  1530.     mov    al,'0'
  1531.     call    outprt
  1532.     mov    al,'n'
  1533.     call    outprt
  1534.     pop    wflags
  1535.     jmp    ignore
  1536. procn6:             ; report cursor position
  1537.     push    wflags        ; force no echo
  1538.     and    yflags,not lclecho
  1539.     call    get_cur_pos
  1540.     mov    al,dh        ; get column here
  1541.     sub    al,1fh        ; get binary column
  1542.     aam
  1543.     add    ax,3030h    ; change to ASCII
  1544.     push    ax
  1545.     mov    al,dl        ; get line here now
  1546.     sub    al,1fh        ; convert to binary
  1547.     aam            ; and to ...
  1548.     add    ax,3030h    ; ASCII
  1549.     mov    bx,ax
  1550.     mov    al,ESCAPE     ; put string out in form : ESCAPE'['line';'col'R'
  1551.     call    outprt
  1552.     mov    al,'['
  1553.     call    outprt
  1554.     cmp    bh,30h        ; don't need leading zero
  1555.     je    procc61
  1556.     mov    al,bh
  1557.     call    outprt
  1558. procc61:
  1559.     mov    al,bl
  1560.     call    outprt
  1561.     mov    al,';'
  1562.     call    outprt
  1563.     pop    bx
  1564.     cmp    bh,30h
  1565.     je    procc62
  1566.     mov    al,bh
  1567.     call    outprt
  1568. procc62:
  1569.     mov    al,bl
  1570.     call    outprt
  1571.     mov    al,'R'
  1572.     call    outprt
  1573.     pop    wflags        ; get these back
  1574.     jmp    ignore
  1575.  
  1576. proclm:             ; do screen attributes
  1577.     mov    bx,offset escstring+2
  1578. proclm1:
  1579.     call    getnum
  1580.     cmp    dl,0
  1581.     jne    proclm2
  1582.     mov    al,ESCAPE
  1583.     call    outtty
  1584.     mov    al,')'
  1585.     call    outtty
  1586.     mov    al,ESCAPE
  1587.     call    outtty
  1588.     mov    al,'q'
  1589.     call    outtty
  1590.     mov    al,ESCAPE
  1591.     call    outtty
  1592.     mov    al,'1'
  1593.     call    outtty
  1594.     jmp    proclm5
  1595. proclm2:
  1596.     cmp    dl,1
  1597.     jne    proclm3
  1598.     mov    al,ESCAPE
  1599.     call    outtty
  1600.     mov    al,'('
  1601.     call    outtty
  1602.     jmp    proclm5
  1603. proclm3:
  1604.     cmp    dl,4
  1605.     jne    proclm4
  1606.     mov    al,ESCAPE
  1607.     call    outtty
  1608.     mov    al,'0'
  1609.     call    outtty
  1610.     jmp    proclm5
  1611. proclm4:
  1612.     cmp    dl,7
  1613.     jne    proclm5
  1614.     mov    al,ESCAPE
  1615.     call    outtty
  1616.     mov    al,'p'
  1617.     call    outtty
  1618. proclm5:
  1619.     cmp    byte ptr [bx],'m'
  1620.     je    proclm6
  1621.     inc    bx
  1622.     jmp    proclm1
  1623. proclm6:
  1624.     jmp    ignore
  1625.  
  1626. procJ:
  1627.     cmp    escseq,3
  1628.     je    procJ0
  1629.     mov    bx,offset escstring+2 ; skip ESCAPE'['
  1630.     call    getnum
  1631.     cmp    dl,0
  1632.     je    procJ0
  1633.     cmp    dl,1
  1634.     je    procJ1
  1635.     cmp    dl,2
  1636.     je    procJ2
  1637.     jmp    ignore        ; ignore others
  1638. procJ0:
  1639.     mov    al,ESCAPE
  1640.     call    outtty
  1641.     mov    al,'J'
  1642.     jmp    noesc
  1643. procJ1:
  1644.     mov    al,ESCAPE
  1645.     call    outtty
  1646.     mov    al,'b'
  1647.     jmp    noesc
  1648. procJ2:
  1649.     mov    al,ESCAPE
  1650.     call    outtty
  1651.     mov    al,'E'
  1652.     jmp    noesc
  1653.  
  1654. prochl:
  1655.     mov    bx,offset escstring+2 ; skip ESCAPE'['
  1656.     call    getnum
  1657.     cmp    [escstring+2],'?'
  1658.     je    quest
  1659.     mov    bx,escpnt
  1660.     mov    bl,[bx]     ; contains 'h' or 'l'
  1661.     cmp    dl,4
  1662.     jne    not4
  1663.     mov    al,ESCAPE
  1664.     call    outtty
  1665.     mov    al,'@'
  1666.     cmp    bl,'l'
  1667.     jne    enterins
  1668.     mov    al,'O'
  1669. enterins:
  1670.     jmp    noesc
  1671. not4:                ; ignore the others
  1672.     jmp    ignore
  1673. quest:                ; sequence like ESCAPE'[?'nn'h'
  1674.     mov    bx,escpnt
  1675.     mov    bl,[bx]
  1676.     cmp    dl,1
  1677.     jne    not1
  1678.     mov    cx,8
  1679.     cmp    appkeys,0
  1680.     je    q1
  1681.     mov    offs,offset apptbl
  1682.     mov    di, offset apptbl.extrtabl
  1683.     jmp    q2
  1684. q1:    mov    offs,offset numtbl
  1685.     mov    di, offset numtbl.extrtabl
  1686. q2:    add    di,START_EXTRTBL ; don't want to start at the top
  1687.     cmp    bl,'l'
  1688.     je    q3
  1689.     mov    si,offset curapp
  1690.     mov    appcur,1
  1691.     jmp    q4
  1692. q3:    mov    si,offset curseq
  1693.     mov    appcur,0
  1694. q4:    rep    movsw
  1695.     mov    bx,offset parmblock
  1696.     mov    byte ptr [bx],2
  1697.     mov    ax,18
  1698.     int    SUPERBIOS
  1699.     jmp    ignore
  1700. not1:
  1701.     cmp    dl,5
  1702.     jne    not5
  1703.     mov    al,ESCAPE
  1704.     call    outtty
  1705.     mov    al,'p'
  1706.     cmp    bl,'h'
  1707.     je    isreverse
  1708.     mov    al,'q'
  1709. isreverse:
  1710.     jmp    noesc
  1711. not5:
  1712.     cmp    dl,7
  1713.     jne    not7
  1714.     mov    al,ESCAPE
  1715.     call    outtty
  1716.     mov    al,'v'
  1717.     cmp    bl,'h'
  1718.     je    autowrap
  1719.     mov    al,'w'
  1720. autowrap:
  1721.     jmp    noesc
  1722. not7:                ; ignore the others
  1723.     jmp    ignore
  1724.  
  1725. procK:
  1726.     cmp    escseq,3
  1727.     je    procK0
  1728.     mov    bx,offset escstring+2 ; skip ESCAPE'['
  1729.     call    getnum
  1730.     cmp    dl,0
  1731.     je    procK0
  1732.     cmp    dl,1
  1733.     je    procK1
  1734.     cmp    dl,2
  1735.     je    procK2
  1736.     jmp    ignore        ; ignore others
  1737. procK0:
  1738.     mov    al,ESCAPE
  1739.     call    outtty
  1740.     mov    al,'K'
  1741.     jmp    noesc
  1742. procK1:
  1743.     mov    al,ESCAPE
  1744.     call    outtty
  1745.     mov    al,'o'
  1746.     jmp    noesc
  1747. procK2:
  1748.     mov    al,ESCAPE
  1749.     call    outtty
  1750.     mov    al,'l'
  1751.     jmp    noesc
  1752.  
  1753. processrp:
  1754. processlp:
  1755. processlb:
  1756.     mov    escseq,-1    ; have to eat one char
  1757.     jmp    doansi_d    ;
  1758. noesc:                ; That wasn't valid! (or print last char)
  1759.     call    outtty        ; print it out...
  1760. ignore:             ; Here to flag end of escape or ignore
  1761.     mov    escseq,0    ; one that we don't like
  1762. doansi_d:
  1763.     ret            ; Here when we have no more to do
  1764. DOANSI    endp
  1765.  
  1766. ; GETNUM gets a number from escapestring, returns it in DL.
  1767. ;   Input: pointer in BX.  Destroys BX, CX, DH. Finishes on first
  1768. ;   encounteder non-numeric char except '-'.     Assumes correct syntax
  1769. ;   ('-' only as first char - checked in procmulti)
  1770.  
  1771. GETNUM    proc    near
  1772.     xor    dx,dx
  1773.     cmp    bx,escpnt    ; is it to end of string already?
  1774.     jge    getn4        ; yes - just exit with zero
  1775.     xor    ch,ch        ; assume positive number
  1776.     cmp    byte ptr [bx],'?' ; first char may be a questionmark
  1777.     jne    getn1
  1778.     inc    bx
  1779. getn1:
  1780.     mov    cl,[bx]
  1781.     cmp    cl,';'
  1782.     je    getn3
  1783.     cmp    cl,'-'
  1784.     jne    getn2
  1785.     mov    ch,-1
  1786. getn2:
  1787.     cmp    cl,'0'
  1788.     jl    getn3
  1789.     cmp    cl,'9'
  1790.     jg    getn3
  1791.     sub    cl,'0'
  1792.     shl    dl,1        ; multiply by 10 (=1010b)
  1793.     mov    dh,dl
  1794.     shl    dl,1
  1795.     shl    dl,1
  1796.     add    dl,dh
  1797.     add    dl,cl
  1798.     inc    bx
  1799.     cmp    bx,escpnt
  1800.     jl    getn1
  1801. getn3:
  1802.     cmp    ch,-1
  1803.     jne    getn4
  1804.     neg    dx
  1805. getn4:
  1806.     ret
  1807. GETNUM    endp
  1808.  
  1809. ; initialize keyboard and tables to build it [as]
  1810.  
  1811. INITANSI proc    near
  1812.     cld
  1813.     mov    bx,ds
  1814.     mov    es,bx
  1815.     mov    bx,offset parmblock
  1816.     mov    ax,18
  1817.     int    SUPERBIOS    ; get old keyboard
  1818.     or    ax,ax
  1819.     jz    ansi01
  1820.     jmp    aend
  1821. ansi01: mov    cx,598        ; copy it
  1822.     mov    si,offset oldtable
  1823.     mov    di,offset numtbl
  1824.     cld
  1825.     rep    movsw
  1826.     mov    si,offset numtbl ; Index in Table
  1827.     mov    byte ptr [si].kd0+25,7fh ; DEL to Backspace-key
  1828.  
  1829. ; set cursorkeys
  1830.     mov    word ptr [si].kd12+2*88,0A000h    ;
  1831.     mov    word ptr [si].kd12+2*89,0A000h    ; with auto-repeat
  1832.     mov    word ptr [si].kd12+2*98,0A000h
  1833.     mov    word ptr [si].kd12+2*99,0A000h
  1834.     mov    byte ptr [si].kd0+88,START_EXTRTBL ; offset in EXTRtabl
  1835.     mov    byte ptr [si].kd0+89,START_EXTRTBL+4
  1836.     mov    byte ptr [si].kd0+98,START_EXTRTBL+8
  1837.     mov    byte ptr [si].kd0+99,START_EXTRTBL+12
  1838.     mov    di,offset numtbl.extrtabl
  1839.     add    di,START_EXTRTBL ; Don't want to overwrite stuff
  1840.     mov    si,offset curseq
  1841.     mov    cx,8
  1842.     rep    movsw        ; move the new sequences to keytable
  1843.  
  1844. ; copy complete table to build Applikation-keypad-table
  1845.     mov    cx,598
  1846.     mov    si,offset numtbl
  1847.     mov    di,offset apptbl
  1848.     rep    movsw
  1849.  
  1850. ; now build keypad
  1851.     mov    si,offset apptbl
  1852.     mov    word ptr [si].kd12+2*28,8000h
  1853.     mov    word ptr [si].kd12+2*29,8000h
  1854.     mov    word ptr [si].kd12+2*30,8000h
  1855.     mov    word ptr [si].kd12+2*31,8000h
  1856.     mov    word ptr [si].kd12+2*49,8000h
  1857.     mov    word ptr [si].kd12+2*50,8000h
  1858.     mov    word ptr [si].kd12+2*51,8000h
  1859.     mov    word ptr [si].kd12+2*52,8000h
  1860.     mov    word ptr [si].kd12+2*69,8000h
  1861.     mov    word ptr [si].kd12+2*70,8000h
  1862.     mov    word ptr [si].kd12+2*71,8000h
  1863.     mov    word ptr [si].kd12+2*72,8000h
  1864.     mov    word ptr [si].kd12+2*90,8000h
  1865.     mov    word ptr [si].kd12+2*91,8000h
  1866.     mov    word ptr [si].kd12+2*92,8000h
  1867.     mov    word ptr [si].kd12+2*93,8000h
  1868.     mov    word ptr [si].kd12+2*100,8000h
  1869.     mov    word ptr [si].kd12+2*101,8000h    ; [bgp]
  1870.     mov    word ptr [si].kd12+2*102,8000h
  1871.     mov    byte ptr [si].kd0+28,START_EXTRTBL+16 ; offset in EXTRtabl
  1872.     mov    byte ptr [si].kd0+29,START_EXTRTBL+20
  1873.     mov    byte ptr [si].kd0+30,START_EXTRTBL+24
  1874.     mov    byte ptr [si].kd0+31,START_EXTRTBL+28
  1875.     mov    byte ptr [si].kd0+49,START_EXTRTBL+32
  1876.     mov    byte ptr [si].kd0+50,START_EXTRTBL+36
  1877.     mov    byte ptr [si].kd0+51,START_EXTRTBL+40
  1878.     mov    byte ptr [si].kd0+52,START_EXTRTBL+44
  1879.     mov    byte ptr [si].kd0+69,START_EXTRTBL+48
  1880.     mov    byte ptr [si].kd0+70,START_EXTRTBL+52
  1881.     mov    byte ptr [si].kd0+71,START_EXTRTBL+56
  1882.     mov    byte ptr [si].kd0+72,START_EXTRTBL+60
  1883.     mov    byte ptr [si].kd0+90,START_EXTRTBL+64
  1884.     mov    byte ptr [si].kd0+91,START_EXTRTBL+68
  1885.     mov    byte ptr [si].kd0+92,START_EXTRTBL+72
  1886.     mov    byte ptr [si].kd0+93,START_EXTRTBL+76
  1887.     mov    byte ptr [si].kd0+100,START_EXTRTBL+80
  1888.     mov    byte ptr [si].kd0+101,START_EXTRTBL+80
  1889.     mov    byte ptr [si].kd0+102,START_EXTRTBL+84
  1890.     mov    di,offset apptbl.extrtabl
  1891.     add    di,START_EXTRTBL ; avoid overwriting stuff...
  1892.     mov    si,offset applik
  1893.     mov    cx,44
  1894.     cld
  1895.     rep    movsw        ; move new keycodes to table
  1896.     mov    bx,offset parmblock
  1897.     mov    byte ptr [bx],2
  1898.     mov    offs,offset numtbl ; set numeric keypad
  1899.     mov    ax,18
  1900.     int    SUPERBIOS
  1901. aend:
  1902.     ret
  1903. INITANSI endp
  1904.  
  1905. ; Save old keyboard stuff when exiting [as]
  1906.  
  1907. FINIANSI proc    near
  1908.     mov    bx,offset parmblock
  1909.     mov    byte ptr [bx],2
  1910.     mov    dx,offset oldtable
  1911.     xchg    dx,offs     ; save old keyboard-type in dx
  1912.     mov    ax,18
  1913.     int    SUPERBIOS
  1914.     xchg    dx,offs     ; restore old keyboard-type
  1915.     ret
  1916. FINIANSI endp
  1917.  
  1918. ; Get the current cursor location - row in dl, col in dh
  1919. ; (1,1) is upper left corner
  1920.  
  1921. GET_CUR_POS proc near
  1922.     mov    al,ESCAPE    ; request cursor location
  1923.     call    outtty
  1924.     mov    al,'n'
  1925.     call    outtty
  1926.     mov    ah,CONINQ    ; input no check
  1927.     int    DOS        ; gets the ESCAPE
  1928.     int    DOS        ; gets the Y
  1929.     int    DOS
  1930.     sub    al,31
  1931.     mov    dl,al
  1932.     int    DOS
  1933.     sub    al,31
  1934.     mov    dh,al
  1935.     ret
  1936. GET_CUR_POS endp
  1937.  
  1938. ; Set the cursor location - row in dl, col in dh
  1939. ; (1,1) is upper left corner
  1940.  
  1941. SET_CUR_POS proc near
  1942.     push    dx        ; save it to be sure
  1943.     mov    al,ESCAPE
  1944.     call    outtty
  1945.     mov    al,'Y'
  1946.     call    outtty
  1947.     pop    dx
  1948.     push    dx
  1949.     mov    al,dl        ; row
  1950.     add    al,31
  1951.     call    outtty
  1952.     pop    dx
  1953.     push    dx
  1954.     mov    al,dh        ; column
  1955.     add    al,31
  1956.     call    outtty
  1957.     pop    dx
  1958.     ret
  1959. SET_CUR_POS endp
  1960.  
  1961. ; Save the screen so we can restore it
  1962.  
  1963. SAVESCR proc    near
  1964.     push    es        ; [bgp]
  1965.     call    get_cur_pos    ; get cursor location
  1966.     mov    tcurloc,dl    ; this is line number
  1967.     mov    tcurloc+1,dh    ; this is column number
  1968.     mov    bx,SEG_CRTC    ; where crt controller is
  1969.     mov    es,bx
  1970.     mov    bx,OFF_CRTC
  1971.     mov    byte ptr es:[bx],12
  1972.     mov    ah,es:1[bx]
  1973.     and    ah,7        ; only want bottom 3 bits
  1974.     mov    byte ptr es:[bx],13
  1975.     mov    al,es:1[bx]
  1976.     shl    ax,1        ; multiply by 2 (was word address)
  1977.     mov    si,ax
  1978.     push    ds
  1979.     pop    es
  1980.     mov    ds,tscrseg
  1981.     mov    di,offset tscreen
  1982.     mov    cx,1920
  1983.     cld
  1984.     rep    movsw
  1985.     push    es
  1986.     pop    ds
  1987.     call    cmblnk        ; let them start with a blank one
  1988.     pop    es        ; [bgp]
  1989.     ret            ; and return
  1990. SAVESCR endp
  1991.  
  1992. ; Restore screen from scrsav buffer
  1993.  
  1994. RESTSCR proc    near
  1995.     push    es        ; [bgp]
  1996.     call    cmblnk        ; start with a clear screen
  1997.     mov    si,offset tscreen
  1998.     mov    es,tscrseg
  1999.     xor    di,di        ; start at start
  2000.     mov    cx,1920     ; 1920 words to go
  2001.     rep    movsw
  2002.     mov    dx,word ptr tcurloc ; get cursor location
  2003.     call    set_cur_pos
  2004.     pop    es        ; [bgp]
  2005.     ret
  2006. RESTSCR endp
  2007.  
  2008. ; Save the mode line so it can be restored when we are through [bgp]
  2009.  
  2010. SAVE_MODE proc    near
  2011.     push es         ; to be sure
  2012.     mov    bx,SEG_CRTC    ; where crt controller is
  2013.     mov    es,bx
  2014.     mov    bx,OFF_CRTC
  2015.     mov    byte ptr es:[bx],12 ; high screen origin register
  2016.     mov    ah,es:1[bx]
  2017.     and    ah,7        ; need bottom 3 bits
  2018.     mov    byte ptr es:[bx],13 ; low screen origin register
  2019.     mov    al,es:1[bx]
  2020.     shl    ax,1        ; multiply by 2 (was word address)
  2021.     add    ax,3840     ; where status line is
  2022.     mov    si,ax
  2023.     mov    di,offset status_line ; where to put it
  2024.     mov    cx,80        ; 80 words long
  2025.     push    ds
  2026.     pop    es
  2027.     mov    ds,tscrseg    ; setment of screen
  2028.     cld
  2029.     rep    movsw
  2030.     push    es
  2031.     pop    ds        ; restore ds
  2032.     pop    es        ; and this too
  2033.     ret
  2034. SAVE_MODE endp
  2035.  
  2036. ; Restore mode line in case someone has something on it [bgp]
  2037.  
  2038. REST_MODE proc near
  2039.     push    es        ; to be sure...
  2040.     mov    bx,SEG_CRTC    ; where crt controller is
  2041.     mov    es,bx
  2042.     mov    bx,OFF_CRTC
  2043.     mov    byte ptr es:[bx],12 ; high screen origin register
  2044.     mov    ah,es:1[bx]
  2045.     and    ah,7        ; need bottom 3 bits
  2046.     mov    byte ptr es:[bx],13 ; low screen origin register
  2047.     mov    al,es:1[bx]
  2048.     shl    ax,1        ; multiply by 2 (was word address)
  2049.     add    ax,3840     ; where status line is
  2050.     mov    di,ax
  2051.     mov    si,offset status_line ; where to get it
  2052.     mov    cx,80        ; 80 words long
  2053.     mov    es,tscrseg    ; segment of screen
  2054.     cld
  2055.     rep    movsw
  2056.     pop    es        ; restore this
  2057.     ret
  2058. REST_MODE endp
  2059.  
  2060. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  2061. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  2062. ; is determined by mssset and is passed as pointer dmpname.
  2063. ; This reads the screen that was last saved by savescr - it is expected
  2064. ; that savescr will be called just before this one.
  2065. ; 7 August 1986 Add this routine - it is pirated from the file MSYIBM and
  2066. ; modified to match the Victor's needs.  Note that a screen dump is not
  2067. ; possible in Tektronix mode (unfortunately) since I'm not sure how to dump
  2068. ; it in a way that would make sense.  [bgp]
  2069.  
  2070. DUMPSCR PROC    NEAR
  2071.     cmp    flags.vtflg,TTTEK ; emulating Tektronix?
  2072.     jne    dumpxx        ; no, save screen
  2073.     jmp    dumptek     ; this won't do anything but beep
  2074. dumpxx:
  2075.     push    ax
  2076.     push    bx
  2077.     push    cx
  2078.     push    dx
  2079.     mov    dmphand,-1    ; preset illegal handle
  2080.     mov    dx,offset dmpname ; name of disk file, from mssset
  2081.     mov    ax,dx        ; where isfile wants name ptr
  2082.     call    isfile        ; what kind of file is this?
  2083.     jc    dmp5        ; c = no such file, create it
  2084.     test    byte ptr filtst.dta+21,1FH ; file attributes, ok to write?
  2085.     jnz    dmp0        ; nz=no.
  2086.     mov    al,1        ; writing
  2087.     mov    ah,OPEN2    ; open existing file
  2088.     int    DOS
  2089.     jc    dmp0        ; c=failure
  2090.     mov    dmphand,ax    ; save file handle
  2091.     mov    bx,ax        ; need handle here
  2092.     mov    cx,0FFFFH    ; set up file pointer
  2093.     mov    dx,-1        ; and offset
  2094.     mov    al,2        ; move to eof minus one byte
  2095.     mov    ah,LSEEK    ; and seek the end
  2096.     int    DOS
  2097.     jmp    dmp1
  2098.  
  2099. dmp5:    mov    ah,CREAT2    ; file did not exist
  2100.     mov    cx,20H        ; attributes, archive bit
  2101.     int    DOS
  2102.     mov    dmphand,ax    ; save file handle
  2103.     jnc    dmp1        ; nc=ok
  2104.  
  2105. dmp0:    call    clrmod        ; clear place for mode line
  2106.     mov    dx,offset dmperr ; get string to put there
  2107.     call    putmod        ; on mode line...
  2108.     pop    dx
  2109.     pop    cx
  2110.     pop    bx
  2111.     pop    ax
  2112.     ret
  2113.  
  2114. dmp1:    push    di        ; read screen buffer, write lines
  2115.     push    si
  2116.     push    es
  2117.     push    ds
  2118.     pop    es        ; make sure this is right
  2119.     mov    cx,24        ; 24 lines in buffer
  2120.     mov    si,offset tscreen ; where screen is saved
  2121. dmp2:    push    cx        ; save outer loop counter
  2122.     mov    di,offset dumpbuf ; data segment memory
  2123.     mov    cx,80        ; 80 columns
  2124. dmp3:    mov    ax,word ptr es:[si] ; read char + attribute
  2125.     and    ax,7FFH     ; take off attributes
  2126.     sub    ax,char_base    ; minus base
  2127.     mov    byte ptr [di],al ; store the char
  2128.     inc    si
  2129.     inc    si
  2130.     inc    di
  2131.     loop    dmp3        ; do for each column
  2132.     std            ; set scan backward
  2133.     mov    cx,80        ; 80 columns
  2134.     mov    di,offset dumpbuf+79 ; end of line
  2135.     mov    al,' '          ; thing to scan over
  2136.     repe    scasb        ; scan until non-space
  2137.     cld            ; set direction forward
  2138.     jz    dmp3a        ; z=all spaces
  2139.     inc    cx
  2140.     inc    di
  2141. dmp3a:    mov    word ptr [di+1],0A0DH ; append cr/lf
  2142.     add    cx,2        ; line count + cr/lf
  2143.     mov    dx,offset dumpbuf ; array to be written
  2144.     mov    bx,dmphand    ; need file handle
  2145.     mov    ah,WRITE2    ; write the line
  2146.     int    DOS
  2147.     pop    cx        ; get line counter again
  2148.     loop    dmp2        ; do next line
  2149.     mov    dx,offset dumpsep ; put in ff/cr/lf
  2150.     mov    cx,3        ; three bytes overall
  2151.     mov    ah,WRITE2    ; write them
  2152.     mov    bx,dmphand    ; file handle
  2153.     int    DOS
  2154.     mov    ah,CLOSE2    ; close the file now
  2155.     int    DOS
  2156. dmp6:    pop    es
  2157.     pop    si
  2158.     pop    di
  2159.     pop    dx
  2160.     pop    cx
  2161.     pop    bx
  2162.     pop    ax
  2163.     ret
  2164. dumptek:call    beep        ; what else should we do?
  2165.     ret
  2166. DUMPSCR ENDP
  2167.  
  2168. ; Come to here to act somewhat like a Tektronix 4010 terminal...
  2169. TEK4010 proc    near
  2170.     push    es            ; this will be used repeatedly
  2171.     mov    es,scrseg
  2172.     mov    cursor_cnt,CURSOR_TIME    ; init cursor countdown timer
  2173.     cmp    first_in,FALSE        ; been here before?
  2174.     je    tek0            ; yes
  2175.     call    clrscr            ; be sure screen is clear
  2176.     mov    first_in,FALSE        ; flag it
  2177. tek0:
  2178.     call    set_hires        ; set to hires screen
  2179. teklp:
  2180.     cmp    full_flag,FALSE     ; page full condition
  2181.     jne    tekcki1         ; yes, I can't accept anything
  2182.     call    portchr         ; char at port?
  2183.     jc    tekcki            ; c = no, keep going
  2184.     call    tekhandle        ; go handle the character
  2185. tekcki:
  2186.     dec    cursor_cnt        ; decrement cursor countdown
  2187.     jnz    tekcki1         ; not ready
  2188.     call    cursor_on        ; turn on cursor
  2189. tekcki1:
  2190.     call    keybd            ; get and translate a key [bgp]
  2191.     jnc    teklp            ; carry=esc char entered - quit [bgp]
  2192. tekquit:
  2193.     call    reset_hires        ; reset to normal screen
  2194.     pop    es
  2195.     ret
  2196. TEK4010 endp
  2197.  
  2198. ; Come to here to temporarily act somewhat like a Tektronix 4010 terminal...
  2199. ; Added 29 August 1987 to allow ANSI or VT52 to go directly to Tektronix
  2200. ; mode.  This is entered at a point where conditions should be like a
  2201. ; clear screen was just received (ESCAPE FF).  We should exit on the receipt
  2202. ; of an ESCAPE US sequence or if the esc char is entered from the keyboard.
  2203. ; If the esc char is entered then return with carry set. [bgp]
  2204. ; For compatibility we will also exit if a CAN (ctrl-X) is received (to be
  2205. ; like the IBM-PC version).
  2206. TEKTEMP proc    near
  2207.     push    es            ; this will be used repeatedly
  2208.     mov    es,scrseg
  2209.     mov    ax,flags.vtflg
  2210.     mov    temp_mode,ax        ; save current emulation
  2211.     mov    flags.vtflg,TTTEK    ; set to tek emulation
  2212.     mov    temp_tek,TRUE        ; this is temporary mode...
  2213.     mov    echo_supp,FALSE     ; clear echo suppression
  2214.     mov    cursor_cnt,CURSOR_TIME    ; init cursor countdown timer
  2215.     mov    escflag,0        ; not in escape sequence
  2216.     mov    graph_mode,FALSE    ; in full text mode
  2217.     call    clrscr            ; be sure screen is clear
  2218.     mov    first_in,FALSE        ; flag it
  2219.     call    set_hires        ; set to hires screen
  2220. tektlp:
  2221.     cmp    full_flag,FALSE     ; page full condition
  2222.     jne    tektcki1        ; yes, I can't accept anything
  2223.     call    portchr         ; char at port?
  2224.     jc    tektcki         ; c = no, keep going
  2225.     and    al,7fh            ; Tek gets only 7 bit characters
  2226.     call    tekhandle        ; go handle the character
  2227. tektcki:
  2228.     dec    cursor_cnt        ; decrement cursor countdown
  2229.     jnz    tektcki1        ; not ready
  2230.     call    cursor_on        ; turn on cursor
  2231. tektcki1:
  2232.     call    keybd            ; get and translate a key
  2233.     jnc    tektlp            ; carry=esc char entered - quit
  2234.     call    reset_hires        ; reset to normal screen
  2235.     mov    ax,temp_mode
  2236.     mov    flags.vtflg,ax        ; reset to previous emulation
  2237.     mov    temp_tek,FALSE        ; clear temp tektronix emulation
  2238.     pop    es
  2239.     stc                ; set carry - this is full quit
  2240.     ret
  2241. TEKTEMP endp
  2242.  
  2243. ; Take care of an incoming character
  2244.  
  2245. TEKHANDLE proc    near
  2246.     cmp    escseq,0        ; escape sequence in progress?
  2247.     jne    tekhand1        ; ne = yes, no translation
  2248.     cmp    rxtable+256,0        ; translation turned off?
  2249.     je    tekhand1        ; e = yes, no translation
  2250.     push    bx
  2251.     mov    bx,offset rxtable    ; address of translate table
  2252.     xlatb                ; new char is in al
  2253.     pop    bx
  2254. tekhand1:call    capture         ; in case we should
  2255.     cmp    al,GS            ; Group Separator?
  2256.     je    tek2graf        ; ->graphics with pen up
  2257.     cmp    al,ESCAPE        ; Escape?
  2258.     je    tek2esc         ; ->handle special commands
  2259.     mov    bl,escflag
  2260.     xor    bh,bh
  2261.     call    tekjump[bx]        ; Go to right routine
  2262.     mov    cursor_cnt,CURSOR_TIME    ; init cursor countdown
  2263.     ret
  2264. tek2graf:
  2265.     mov    visible,0        ; Pen up
  2266.     mov    escflag,4        ; Get HIY next
  2267.     mov    graph_mode,TRUE
  2268.     ret
  2269. tek2esc:
  2270.     mov    escflag,2        ; ESCAPE handler next
  2271.     ret
  2272. TEKHANDLE endp
  2273.  
  2274. ; TEXT mode - just put text on screen
  2275.  
  2276. TEKTXT    proc    near
  2277.     call    cursor_off        ; be sure this is off
  2278.     cmp    text_x,TEXT_X_MAX    ; off screen?
  2279.     jle    tektxta
  2280.     mov    text_x,0        ; to left margin
  2281.     add    text_y,RPLINE
  2282. tektxta:
  2283.     cmp    text_y,TEXT_Y_MAX
  2284.     jle    tektxtb
  2285.     call    page_full        ; page is full!
  2286.     ret                ; lost that character, oh well...
  2287. tektxtb:
  2288.     cmp    al,DEL            ; Is it delete?
  2289.     jne    tektxt1
  2290.     ret
  2291. tektxt1:
  2292.     cmp    al,' '                  ; Is it control?
  2293.     jl    tektxt3
  2294.     cmp    echo_supp,FALSE     ; In echoplex suppression?
  2295.     jne    tektxt2         ; Yes, don't print it
  2296.     call    character        ; Output it
  2297.     call    inc_char
  2298. tektxt2:
  2299.     ret
  2300. tektxt3:
  2301.     cmp    al,BELL
  2302.     jne    tektxt4
  2303.     call    beep
  2304.     mov    echo_supp,FALSE     ; Clear suppression
  2305.     ret
  2306. tektxt4:
  2307.     cmp    al,BS
  2308.     jne    tektxt6
  2309.     sub    text_x,CPCHAR        ; back up one
  2310.     cmp    text_x,0
  2311.     jge    tektxt5         ; ok
  2312.     mov    text_x,R_MARG        ; right margin
  2313.     sub    text_y,RPLINE        ; back one line
  2314.     cmp    text_y,0        ; top?
  2315.     jge    tektxt5
  2316.     mov    text_y,0        ; top of screen
  2317. tektxt5:
  2318.     mov    echo_supp,FALSE     ; Clear suppression
  2319.     ret
  2320. tektxt6:
  2321.     cmp    al,TAB
  2322.     jne    tektxt7
  2323.     call    inc_char
  2324.     mov    echo_supp,FALSE     ; Clear suppression
  2325.     ret
  2326. tektxt7:
  2327.     cmp    al,LF            ; Line feed?
  2328.     jne    tektxt9
  2329.     add    text_y,RPLINE        ; Down one line
  2330.     cmp    text_y,TEXT_Y_MAX    ; Past end?
  2331.     jle    tektxt8
  2332.     call    page_full        ; can't go any further!
  2333.     ret
  2334. tektxt8:
  2335.     mov    echo_supp,FALSE     ; Clear suppression
  2336.     ret
  2337. tektxt9:
  2338.     cmp    al,VTAB
  2339.     jne    tektxt11
  2340.     sub    text_y,RPLINE        ; Up one line
  2341.     cmp    text_y,0        ; Past top?
  2342.     jge    tektxt10
  2343.     mov    text_y,0
  2344. tektxt10:
  2345.     mov    echo_supp,FALSE     ; Clear suppression
  2346.     ret
  2347. tektxt11:
  2348.     cmp    al,CR            ; It is return?
  2349.     jne    tektxt12
  2350.     mov    text_x,0        ; to left margin
  2351.     mov    echo_supp,FALSE     ; Clear suppression
  2352.     ret
  2353. tektxt12:
  2354.     cmp    al,CAN            ; Is it CAN (control-X)?
  2355.     jne    tektxt13
  2356.     cmp    temp_tek,FALSE        ; in temporary mode?
  2357.     je    tektxt13        ; no, just continue!
  2358.     mov    echo_supp,FALSE     ; clear suppression
  2359.     mov    escflag,0        ; place in full text mode
  2360.     mov    graph_mode,FALSE
  2361.     mov    ax,temp_mode
  2362.     mov    flags.vtflg,ax        ; reset emulation mode
  2363.     mov    temp_tek,FALSE        ; clear temporary mode
  2364.     pop    ax            ; this is return to tekhandle
  2365.     pop    ax            ; this is return to tektemp
  2366.     call    reset_hires        ; have to make it look like a tektquit
  2367.     pop    es            ; with a carry clear state
  2368.     clc
  2369.     ret
  2370. tektxt13:
  2371.     ret
  2372. TEKTXT    endp
  2373.  
  2374. ; Move the text position by one char, perform auto wrap, and
  2375. ; check for page full
  2376.  
  2377. INC_CHAR proc    near
  2378.     add    text_x,CPCHAR        ; Move to next column
  2379.     cmp    text_x,TEXT_X_MAX    ; Past end?
  2380.     jle    inc_char0
  2381.     mov    text_x,0        ; Left margin
  2382.     add    text_y,RPLINE
  2383.     cmp    text_y,TEXT_Y_MAX    ; Past end?
  2384.     jle    inc_char0
  2385.     call    page_full        ; Take no more!
  2386. inc_char0:
  2387.     ret
  2388. INC_CHAR endp
  2389.  
  2390. ; ESCAPE mode - check what to do
  2391.  
  2392. TEKESC    proc    near
  2393.     cmp    al,FF            ; Form feed?
  2394.     jne    tekesc1
  2395.     call    clrscr
  2396.     mov    echo_supp,FALSE     ; Clear suppression
  2397.     jmp    tekescq
  2398. tekesc1:
  2399.     cmp    al,CTLZ         ; Control-Z?
  2400.     jne    tekesc2
  2401.     mov    escflag,0        ; Just in case
  2402.     mov    echo_supp,TRUE        ; echoplex suppression
  2403.     call    tekcrs            ; Go to cross hairs
  2404.     ret                ; Last char does its thing
  2405. tekesc2:
  2406.     cmp    al,ETB            ; Make copy?
  2407.     jne    tekesc2a
  2408.     mov    echo_supp,FALSE     ; Clear suppression
  2409.     jmp    tekescq
  2410. tekesc2a:
  2411.     cmp    al,ENQ            ; enquire?
  2412.     jne    tekesc3
  2413.     mov    echo_supp,TRUE        ; echoplex suppression
  2414.     call    send_stat
  2415.     jmp    tekescq         ; do nothing for now ***
  2416. tekesc3:
  2417.     cmp    al,US            ; return from temp tek mode [bgp]
  2418.     jne    tekesc4
  2419.     cmp    temp_tek,FALSE        ; in temporary mode?
  2420.     je    tekescq         ; no, just continue!
  2421.     mov    echo_supp,FALSE     ; clear suppression
  2422.     mov    escflag,0        ; place in full text mode
  2423.     mov    graph_mode,FALSE
  2424.     mov    ax,temp_mode
  2425.     mov    flags.vtflg,ax        ; reset emulation mode
  2426.     mov    temp_tek,FALSE        ; clear temporary mode
  2427.     pop    ax            ; this is return to tekhandle
  2428.     pop    ax            ; this is return to tektemp
  2429.     call    reset_hires        ; have to make it look like a tektquit
  2430.     pop    es            ; with a carry clear state
  2431.     clc
  2432.     ret
  2433. tekesc4:
  2434.     call    tektxt            ; It's just text...
  2435. tekescq:
  2436.     mov    escflag,0        ; Now in full text mode
  2437.     mov    graph_mode,FALSE
  2438.     ret
  2439. TEKESC    endp
  2440.  
  2441. ; Get coordinates   escflag=4->expect hiy, escflag=6->expect hix
  2442.  
  2443. TEKHIY    proc    near
  2444. tekhix:
  2445.     call    cursor_off        ; make sure it is off
  2446.     cmp    al,CR            ; should we exit?
  2447.     jne    tekhi1
  2448.     mov    cur_x,0         ; go to left margin
  2449.     mov    echo_supp,FALSE     ; Clear suppression
  2450.     jmp    go2text
  2451. tekhi1:
  2452.     cmp    al,US            ; another exit?
  2453.     jne    tekhi2
  2454.     mov    echo_supp,FALSE     ; Clear suppression
  2455.     jmp    go2text
  2456. tekhi2:
  2457.     cmp    al,FF
  2458.     jne    tekhi3
  2459.     call    clrscr
  2460.     mov    echo_supp,FALSE     ; Clear suppression
  2461.     jmp    go2text
  2462. tekhi3:
  2463.     cmp    echo_supp,FALSE     ; In suppression
  2464.     jne    tekhi4            ; Yes, ignore this...
  2465.     cmp    al,20H            ; control character?
  2466.     jl    tekhi4
  2467.     cmp    al,40H
  2468.     jl    tekhi5            ; 20-3F are HIX or HIY
  2469.     cmp    al,60H
  2470.     jl    tekhi7            ; 40-5F are LOX
  2471. ;   Get to here must be 60-7F -> LOY
  2472.     mov    ah,loy            ; copy old loy
  2473.     mov    lsb,ah            ; to lsb (in case 4014)
  2474.     and    al,1FH            ; low 5 bits
  2475.     mov    loy,al
  2476.     cmp    escflag,6        ; 2nd in a row?
  2477.     je    tekhi4            ; then previous was lsb anyway
  2478.     mov    lsb,0            ; clear lsb
  2479.     mov    escflag,6        ; expect HIX next
  2480. tekhi4:
  2481.     ret
  2482. ; Get either HIX or HIY depending on escflag
  2483. tekhi5:
  2484.     and    ax,1FH
  2485.     mov    cl,5
  2486.     shl    ax,cl            ; multiply by 32
  2487.     cmp    escflag,4        ; looking for HIY?
  2488.     jne    tekhi6            ; no, HIX
  2489.     mov    hiy,ax
  2490.     ret                ; leave escflag=4
  2491. tekhi6:
  2492.     mov    hix,ax
  2493.     mov    escflag,4        ; look for HIY next
  2494.     ret
  2495. ; Get LOX and do the movement
  2496. tekhi7:
  2497.     and    al,1FH
  2498.     mov    lox,al
  2499.     mov    ax,hix
  2500.     or    al,lox
  2501.     mov    cur_x,ax
  2502.     mov    dx,hiy
  2503.     or    dl,loy
  2504.     mov    cur_y,dx
  2505.     call    tek2victor        ; convert the coords
  2506.     mov    endpt,ax
  2507.     mov    endpt+2,dx        ; save them
  2508.     cmp    visible,0
  2509.     je    tekhi8
  2510.     call    line            ; draw the line
  2511. tekhi8:
  2512.     mov    visible,1
  2513.     mov    ax,endpt
  2514.     mov    start,ax
  2515.     mov    ax,endpt+2
  2516.     mov    start+2,ax        ; end is now start
  2517.     mov    escflag,4        ; want HIY next
  2518.     ret
  2519. ;
  2520. go2text:
  2521.     mov    escflag,0
  2522.     mov    graph_mode,FALSE
  2523.     mov    ax,cur_x
  2524.     mov    dx,cur_y
  2525.     call    tek2victor
  2526.     mov    text_x,ax
  2527.     sub    dx,10            ; mov to upper left corner
  2528.     cmp    dx,0
  2529.     jge    go2text1
  2530.     xor    dx,dx
  2531. go2text1:
  2532.     mov    text_y,dx
  2533.     ret
  2534. TEKHIY    endp
  2535.  
  2536. ; Go to CURSOR mode
  2537.  
  2538. TEKCRS    proc    near
  2539.     call    cursor_off
  2540.     mov    combine,offset pixel_xor
  2541.     mov    trmesc,FALSE
  2542.     mov    prtesc,FALSE
  2543. tekcrs_dr:
  2544.     mov    ax,cur_x        ; get x
  2545.     sub    ax,CUR_LEN        ; minus a little
  2546.     cmp    ax,0
  2547.     jge    tekcrs_dr1
  2548.     mov    ax,0
  2549. tekcrs_dr1:
  2550.     mov    dx,cur_y
  2551.     call    tek2victor
  2552.     mov    crs_hor,ax
  2553.     mov    crs_hor+4,dx
  2554.     mov    ax,cur_x
  2555.     add    ax,CUR_LEN        ; add a little
  2556.     cmp    ax,TEK_X_MAX
  2557.     jle    tekcrs_dr2
  2558.     mov    ax,TEK_X_MAX
  2559. tekcrs_dr2:
  2560.     mov    dx,cur_y
  2561.     call    tek2victor
  2562.     mov    crs_hor+2,ax
  2563.     mov    dx,cur_y        ; now y's
  2564.     sub    dx,CUR_LEN        ; minus a little
  2565.     cmp    dx,0
  2566.     jge    tekcrs_dr3
  2567.     mov    dx,0
  2568. tekcrs_dr3:
  2569.     mov    ax,cur_x
  2570.     call    tek2victor
  2571.     mov    crs_ver,dx
  2572.     mov    crs_ver+4,ax
  2573.     mov    dx,cur_y
  2574.     add    dx,CUR_LEN        ; plus a little
  2575.     cmp    dx,TEK_Y_MAX
  2576.     jle    tekcrs_dr4
  2577.     mov    dx,TEK_Y_MAX
  2578. tekcrs_dr4:
  2579.     mov    ax,cur_x
  2580.     call    tek2victor
  2581.     mov    crs_ver+2,dx
  2582.     call    draw_cursor        ; put it on
  2583. tekcrs_lp:
  2584.     mov    dl,0FFH
  2585.     mov    ah,DCONIO        ; get character
  2586.     int    DOS
  2587.     cmp    al,0            ; anything?
  2588.     jne    tekcrs_hnd        ; take care of it
  2589.     call    portchr         ; check port character
  2590.     jc    tekcrs_lp        ; c = nothing there
  2591.     cmp    prtesc,FALSE        ; received escape?
  2592.     je    tekcrs_lp1        ; no
  2593.     mov    prtesc,FALSE
  2594.     cmp    al,FF
  2595.     je    tekcrs_abt
  2596.     cmp    al,ETB
  2597.     je    tekcrs_abt
  2598.     cmp    al,ENQ
  2599.     jne    tekcrs_lp
  2600.     call    send_stat        ; send status
  2601.     jmp    tekcrs_lp
  2602. tekcrs_lp1:
  2603.     cmp    al,BELL         ; check for control and clear...
  2604.     je    tekcrs_abt
  2605.     cmp    al,BS
  2606.     je    tekcrs_abt
  2607.     cmp    al,CR
  2608.     je    tekcrs_abt
  2609.     cmp    al,TAB
  2610.     je    tekcrs_abt
  2611.     cmp    al,LF
  2612.     je    tekcrs_abt
  2613.     cmp    al,US
  2614.     je    tekcrs_abt
  2615.     cmp    al,ESCAPE
  2616.     jne    tekcrs_lp        ; try for more
  2617.     mov    prtesc,TRUE
  2618.     jmp    tekcrs_lp
  2619. tekcrs_abt:
  2620.     mov    echo_supp,FALSE     ; clear echo suppression
  2621.     mov    escflag,0        ; and text mode
  2622.     jmp    tekcrs_xt        ; and leave
  2623. ;
  2624. tekcrs_hnd:
  2625.     cmp    trmesc,FALSE        ; received escapes yet?
  2626.     jne    tekcrs_hnd2
  2627.     cmp    al,ESCAPE        ; escape character?
  2628.     je    tekcrs_hnd1
  2629.     jmp    tekcrs_done        ; finished
  2630. tekcrs_hnd1:
  2631.     mov    trmesc,TRUE        ; flag it
  2632.     jmp    tekcrs_lp
  2633. tekcrs_hnd2:
  2634.     cmp    al,'1'                  ; change step?
  2635.     jge    tekcrs_hnd2z
  2636.     jmp    tekcrs_done
  2637. tekcrs_hnd2z:
  2638.     cmp    al,'9'
  2639.     jle    tekcrs_hnd3
  2640.     cmp    al,'A'
  2641.     jne    tekcrs_hnd2a
  2642.     mov    ax,cur_stp
  2643.     add    cur_y,ax
  2644.     jmp    tekcrs_und        ; remove old and redraw
  2645. tekcrs_hnd2a:
  2646.     cmp    al,'B'
  2647.     jne    tekcrs_hnd2b
  2648.     mov    ax,cur_stp
  2649.     sub    cur_y,ax
  2650.     jmp    tekcrs_und        ; remove old and redraw
  2651. tekcrs_hnd2b:
  2652.     cmp    al,'C'
  2653.     jne    tekcrs_hnd2c
  2654.     mov    ax,cur_stp
  2655.     add    cur_x,ax
  2656.     jmp    tekcrs_und
  2657. tekcrs_hnd2c:
  2658.     cmp    al,'D'
  2659.     jne    tekcrs_hnd2d
  2660.     mov    ax,cur_stp
  2661.     sub    cur_x,ax
  2662.     jmp    tekcrs_und
  2663. tekcrs_hnd2d:
  2664.     jmp    tekcrs_done        ; its the one to send
  2665. tekcrs_hnd3:
  2666.     sub    al,'0'                  ; convert to number
  2667.     xor    ah,ah
  2668.     mov    cur_stp,ax        ; new step value
  2669.     mov    trmesc,FALSE
  2670.     jmp    tekcrs_lp
  2671. tekcrs_und:
  2672.     cmp    cur_x,0         ; check for validity
  2673.     jge    tekcrs_und1
  2674.     mov    cur_x,0
  2675.     jmp    tekcrs_und2
  2676. tekcrs_und1:
  2677.     cmp    cur_x,TEK_X_MAX
  2678.     jle    tekcrs_und2
  2679.     mov    cur_x,TEK_X_MAX
  2680. tekcrs_und2:
  2681.     cmp    cur_y,0
  2682.     jge    tekcrs_und3
  2683.     mov    cur_y,0
  2684.     jmp    tekcrs_und4
  2685. tekcrs_und3:
  2686.     cmp    cur_y,TEK_Y_MAX
  2687.     jle    tekcrs_und4
  2688.     mov    cur_y,TEK_Y_MAX
  2689. tekcrs_und4:
  2690.     call    draw_cursor        ; remove the cursor
  2691.     mov    trmesc,FALSE
  2692.     jmp    tekcrs_dr        ; and draw new one
  2693. tekcrs_done:
  2694.     push    cur_y            ; want current coords
  2695.     push    cur_x            ; for sending
  2696.     call    send_coord        ; send character and coords
  2697. tekcrs_xt:
  2698.     call    draw_cursor        ; remove the cursor
  2699.     mov    ax,cur_x
  2700.     mov    dx,cur_y        ; need to set start point
  2701.     call    tek2victor
  2702.     mov    start,ax
  2703.     mov    start+2,dx
  2704.     mov    text_x,ax        ; set text point also
  2705.     sub    dx,10            ; move to upper left corner
  2706.     cmp    dx,0
  2707.     jge    tekcrs_xt1
  2708.     xor    dx,dx
  2709. tekcrs_xt1:
  2710.     mov    text_y,dx
  2711.     mov    combine,offset pixel_or
  2712.     ret
  2713. TEKCRS    endp
  2714.  
  2715. ; DRAW CURSOR expects to have the appropriate endpoints in CRS_HOR for
  2716. ; the horizontal line (x1,x2,y) and CRS_VER for the vertical line (y1,y2,x)
  2717.  
  2718. DRAW_CURSOR proc near
  2719.     mov    ax,crs_hor
  2720.     mov    start,ax
  2721.     mov    ax,crs_hor+4
  2722.     mov    start+2,ax
  2723.     mov    endpt+2,ax
  2724.     mov    ax,crs_hor+2
  2725.     mov    endpt,ax
  2726.     call    line            ; draw horizontal line
  2727.     mov    ax,crs_ver
  2728.     mov    start+2,ax
  2729.     mov    ax,crs_ver+4
  2730.     mov    start,ax
  2731.     mov    endpt,ax
  2732.     mov    ax,crs_ver+2
  2733.     mov    endpt+2,ax
  2734.     call    line            ; draw vertical line
  2735.     ret
  2736. DRAW_CURSOR endp
  2737.  
  2738. ; Convert TEK coords to VICTOR coords
  2739. ;   entry:   ax=x, dx=y (tek)
  2740. ;   exit:   ax=x, dx=y (victor)
  2741.  
  2742. TEK2VICTOR proc near
  2743.     push    dx            ; save y for now
  2744.     mov    bx,X_MAX
  2745.     mul    bx
  2746.     mov    bx,TEK_X_MAX
  2747.     div    bx
  2748.     cmp    dx,TEK_X_MAX/2        ; need to round up?
  2749.     jl    tek2vic1
  2750.     inc    ax
  2751. tek2vic1:
  2752.     pop    dx
  2753.     push    ax            ; save x now
  2754.     mov    ax,dx
  2755.     mov    bx,Y_MAX
  2756.     mul    bx
  2757.     mov    bx,TEK_Y_MAX
  2758.     div    bx
  2759.     cmp    dx,TEK_Y_MAX/2        ; need to round up?
  2760.     jl    tek2vic2
  2761.     inc    ax
  2762. tek2vic2:
  2763.     sub    ax,Y_MAX        ; need to swap it
  2764.     neg    ax
  2765.     mov    dx,ax
  2766.     pop    ax
  2767.     ret
  2768. TEK2VICTOR endp
  2769.  
  2770. ; Set the CRT to hires mode
  2771.  
  2772. SET_HIRES proc    near
  2773.     push    es
  2774.     call    crt_lo_inten        ; so you don't see so much jump
  2775.     mov    ah,DCONIO
  2776.     mov    dl,27
  2777.     int    DOS
  2778.     mov    dl,'E'
  2779.     int    DOS            ; let's start with a clear screen
  2780.     mov    bx,0E800H        ; CRT controller segment
  2781.     mov    es,bx
  2782. ; fix the write to work on the VICKI - it has an 8086 [bgp and as]
  2783.     mov    byte ptr es:0,0     ; reg 0
  2784.     mov    byte ptr es:1,3AH
  2785.     mov    byte ptr es:0,1
  2786.     mov    byte ptr es:1,32H
  2787.     mov    byte ptr es:0,2
  2788.     mov    byte ptr es:1,34H
  2789.     mov    byte ptr es:0,3
  2790.     mov    byte ptr es:1,0C9H
  2791.     mov    byte ptr es:0,0AH    ; no cursor
  2792.     mov    byte ptr es:1,20H
  2793. ; end VICKI fix
  2794.     xor    ah,ah            ; assume using lower bank of memory
  2795.     test    scrseg,1000H        ; really?
  2796.     jz    set_hires1
  2797.     mov    ah,10H
  2798. set_hires1:
  2799.     or    ah,20H
  2800. ; VICKI fix again...
  2801.     mov    byte ptr es:0,0CH    ; reg 12
  2802.     mov    byte ptr es:1,ah
  2803.     mov    byte ptr es:0,0DH
  2804.     mov    byte ptr es:1,0
  2805.     mov    byte ptr es:0,0EH
  2806.     mov    byte ptr es:1,0
  2807.     mov    byte ptr es:0,0FH
  2808.     mov    byte ptr es:1,0
  2809. ; end VICKI fix
  2810.     mov    cx,4e2H         ; 1250 locations to set
  2811.     mov    ax,scrseg        ; where screen is
  2812.     shr    ax,1            ; /2
  2813.     mov    di,0F000H        ; in screen ram
  2814.     mov    es,di
  2815.     xor    di,di
  2816. set_hires2:
  2817.     stosw                ; set one
  2818.     inc    ax            ; next one
  2819.     loop    set_hires2
  2820.     call    crt_hi_inten
  2821.     pop    es
  2822.     ret
  2823. SET_HIRES endp
  2824.  
  2825. ; Reset the CRT to lo res mode
  2826.  
  2827. RESET_HIRES proc near
  2828.     push    es
  2829.     call    crt_lo_inten        ; to minimize jump
  2830.     mov    bx,0E800H        ; segment for CRT controller
  2831.     mov    es,bx
  2832. ; VICKI fix
  2833.     mov    byte ptr es:0,0     ; reg 0
  2834.     mov    byte ptr es:1,5CH
  2835.     mov    byte ptr es:0,1
  2836.     mov    byte ptr es:1,50H
  2837.     mov    byte ptr es:0,2
  2838.     mov    byte ptr es:1,51H
  2839.     mov    byte ptr es:0,3
  2840.     mov    byte ptr es:1,0CFH
  2841.     mov    byte ptr es:0,0AH
  2842.     mov    byte ptr es:1,0     ; steady block cursor
  2843.     mov    byte ptr es:0,0CH
  2844.     mov    byte ptr es:1,0
  2845.     mov    byte ptr es:0,0DH
  2846.     mov    byte ptr es:1,0
  2847.     mov    byte ptr es:0,0EH
  2848.     mov    byte ptr es:1,0
  2849.     mov    byte ptr es:0,0FH
  2850.     mov    byte ptr es:1,0
  2851. ; end VICKI fix
  2852.     mov    ah,DCONIO
  2853.     mov    dl,27
  2854.     int    DOS
  2855.     mov    dl,'E'
  2856.     int    DOS            ; insure screen is clear
  2857.     call    crt_hi_inten
  2858.     pop    es
  2859.     ret
  2860. RESET_HIRES endp
  2861.  
  2862. ; Set to lo intensity
  2863.  
  2864. CRT_LO_INTEN proc near
  2865.     mov    bx,0E804H        ; CRT controller segment
  2866.     mov    es,bx
  2867.     mov    al,es:0         ; get current setting
  2868.     mov    ah,al            ; save it
  2869.     and    al,1CH
  2870.     mov    intens,al        ; store it
  2871.     mov    al,ah
  2872.     and    al,0E3H         ; zero intensity
  2873.     mov    es:0,al
  2874.     ret
  2875. CRT_LO_INTEN endp
  2876.  
  2877. ; Set to hi intensity
  2878.  
  2879. CRT_HI_INTEN proc near
  2880.     mov    bx,0E804H        ; Crt controller segment
  2881.     mov    es,bx
  2882.     mov    al,es:0         ; Get current setting
  2883.     and    al,0E3H         ; Clear intensity
  2884.     or    al,intens        ; Set to correct value
  2885.     mov    es:0,al
  2886.     ret
  2887. CRT_HI_INTEN endp
  2888.  
  2889. ; Clear the hires screen area
  2890.  
  2891. CLRSCR    proc    near
  2892.     les    di,dword ptr scrloc    ; get right location
  2893.     cld                ; increment
  2894.     mov    cx,20000        ; 40000 bytes
  2895.     mov    ax,0
  2896.     rep    stosw            ; doing it
  2897.     jmp    clrscr1
  2898. homescr:                ; keyboard translator verb entry [bgp]
  2899.     call    cursor_off        ; make sure it is off
  2900.     cmp    full_flag,TRUE        ; in page full condition?
  2901.     jne    clrscr1         ; no, just go home the cursor
  2902.     les    di,dword ptr scrloc    ; get screen location
  2903.     add    di,38424        ; get to lower left corner
  2904.     mov    ax,0FFFFH        ; want to clear them all
  2905.     xor    es:[di],ax        ; need to clear page full indicator
  2906.     inc    di            ; box in the lower left corner which
  2907.     inc    di            ; was put there when the page filled
  2908.     xor    es:[di],ax        ; up earlier
  2909.     inc    di
  2910.     inc    di
  2911.     xor    es:[di],ax
  2912.     inc    di
  2913.     inc    di
  2914.     xor    es:[di],ax
  2915. clrscr1:
  2916.     mov    cur_x,0         ; set to home position
  2917.     mov    cur_y,780
  2918.     mov    hix,0
  2919.     mov    hiy,0
  2920.     mov    lox,0
  2921.     mov    loy,0
  2922.     mov    lsb,0
  2923.     mov    start,0
  2924.     mov    start+2,0
  2925.     mov    text_x,0
  2926.     mov    text_y,0
  2927.     mov    full_flag,FALSE     ; page isn't full
  2928.     mov    cursor,FALSE        ; cursor isn't on
  2929.     mov    cursor_cnt,CURSOR_TIME    ; set up cursor countdown
  2930.     ret
  2931. CLRSCR    endp
  2932.  
  2933. ; Put the character in al on the screen at location pointed at by
  2934. ; text_x,text_y.  Use combination routine pointed at by t_combine
  2935.  
  2936. CHARACTER proc    near
  2937.     cmp    al,' '                  ; is it a space?
  2938.     jne    character1        ; no
  2939.     ret                ; just return...
  2940. character1:
  2941.     and    al,07FH         ; Be sure it is in range...
  2942.     cmp    al,07FH         ; Is it delete?
  2943.     jl    character1a
  2944.     ret                ; Don't do it...
  2945. character1a:
  2946.     push    ax            ; save the character
  2947.     mov    ax,text_y
  2948.     mov    dx,text_x
  2949.     call    convert_loc        ; get to where we are going
  2950.     les    di,dword ptr scrloc    ; get screen location
  2951.     add    si,di            ; now we are in the right place
  2952.     mov    cx,text_y
  2953.     and    cx,0FH            ; need mod(y,16)
  2954.     sub    cx,16
  2955.     neg    cx            ; how many to do in this section
  2956.     cmp    cx,RPLINE        ; more than one line?
  2957.     jle    character1b
  2958.     mov    cx,RPLINE        ; make it just one line
  2959. character1b:
  2960.     mov    temp,cx         ; need to remember this
  2961.     pop    ax            ; get back the character
  2962.     sub    ax,'!'                  ; start with exclamation mark
  2963.     xor    ah,ah
  2964.     mov    dl,RPLINE        ; number of entries per character
  2965.     shl    dl,1            ; they are word entries
  2966.     mul    dl
  2967.     mov    di,ax            ; where to get bit patterns
  2968.     mov    dx,cx            ; how many to do
  2969.     mov    cx,bx            ; this is the number to shift
  2970.     or    cx,cx            ; look at it
  2971.     jnz    character1c
  2972.     jmp    character8        ; no shifts necessary
  2973. character1c:
  2974.     cmp    cx,5            ; this goes within one word
  2975.     jg    character4        ; spans word boundaries
  2976. character2:
  2977.     mov    bx,font[di]
  2978.     or    bx,bx            ; is it zero?
  2979.     jz    character3
  2980.     cmp    si,0            ; too low? (start at 0 offset) [jrd]
  2981.     jb    character3
  2982.     cmp    si,39999        ; too high? [jrd]
  2983.     jae    character3
  2984.     shl    bx,cl            ; shift to right place
  2985.     call    t_combine
  2986. character3:
  2987.     inc    di
  2988.     inc    di
  2989.     inc    si
  2990.     inc    si
  2991.     dec    dx            ; done one row
  2992.     jnz    character2
  2993.     add    si,1568         ; go to top of next major row
  2994.     mov    dx,RPLINE        ; how many we needed to do
  2995.     sub    dx,temp         ; minus how many done
  2996.     mov    temp,RPLINE        ; claim we have done them all
  2997.     jg    character2        ; do the rest
  2998.     jmp    character10
  2999. character4:
  3000.     sub    cx,16            ; convert to right shift
  3001.     neg    cx
  3002.     mov    ax,0FFFFH        ; need to build mask
  3003.     shl    ax,cl
  3004.     not    ax
  3005.     mov    c_mask,ax
  3006. character5:
  3007.     mov    bx,font[di]
  3008.     or    bx,bx            ; zero?
  3009.     jz    character5a
  3010.     cmp    si,0            ; too low? (starts at 0 offset) [jrd]
  3011.     jb    character5a
  3012.     cmp    si,39999        ; too high? [jrd]
  3013.     jae    character5a
  3014.     jmp    character6
  3015. character5a:
  3016.     inc    si
  3017.     inc    si
  3018.     jmp    character7
  3019. character6:
  3020.     and    bx,c_mask        ; mask upper bits
  3021.     ror    bx,cl            ; get first batch
  3022.     call    t_combine
  3023.     add    si,32            ; next word column
  3024.     mov    bx,font[di]
  3025.     shr    bx,cl
  3026.     call    t_combine
  3027.     sub    si,30            ; back to right column, plus 2
  3028. character7:
  3029.     inc    di
  3030.     inc    di
  3031.     dec    dx            ; done one row
  3032.     jnz    character5
  3033.     add    si,1568         ; go to top of next major row
  3034.     mov    dx,RPLINE        ; how many we needed to do
  3035.     sub    dx,temp         ; minus how many done
  3036.     mov    temp,RPLINE        ; claim we have done them all
  3037.     jg    character5        ; do the rest
  3038.     jmp    character10
  3039. character8:
  3040.     mov    bx,font[di]
  3041.     or    bx,bx            ; is it zero?
  3042.     jz    character9
  3043.     cmp    si,0            ; too low? (starts at 0 offset) [jrd]
  3044.     jb    character9
  3045.     cmp    si,39999        ; too high? [jrd]
  3046.     jae    character9
  3047.     call    t_combine
  3048. character9:
  3049.     inc    di
  3050.     inc    di
  3051.     inc    si
  3052.     inc    si
  3053.     dec    dx            ; done one row
  3054.     jnz    character8
  3055.     add    si,1568         ; go to top of next major row
  3056.     mov    dx,RPLINE        ; how many we needed to do
  3057.     sub    dx,temp         ; minus how many done
  3058.     mov    temp,RPLINE        ; claim we have done them all
  3059.     jg    character8        ; do the rest
  3060.     jmp    character10
  3061. character10:
  3062.     ret
  3063. CHARACTER endp
  3064.  
  3065. ; Cursor on - turn on the cursor if it isn't already on
  3066.  
  3067. CURSOR_ON proc    near
  3068.     cmp    cursor,FALSE
  3069.     jne    c_on_end        ; already on
  3070.     push    ax            ; save this just in case
  3071.     mov    t_combine,offset word_xor ; set combine rule
  3072.     mov    ax,CURSOR_CHR
  3073.     call    character        ; print without advancing
  3074.     mov    t_combine,offset word_or ; set combine rule
  3075.     mov    cursor,TRUE        ; flag it
  3076.     pop    ax
  3077. c_on_end:
  3078.     ret
  3079. CURSOR_ON endp
  3080.  
  3081. ; Cursor off - erase the cursor if it is there
  3082.  
  3083. CURSOR_OFF proc near
  3084.     cmp    cursor,FALSE
  3085.     je    c_off_end        ; already off
  3086.     push    ax
  3087.     mov    t_combine,offset word_xor ; set combine rule
  3088.     mov    ax,CURSOR_CHR
  3089.     call    character        ; print without advancing
  3090.     mov    t_combine,offset word_or ; set combine rule
  3091.     mov    cursor,FALSE        ; flag it
  3092.     pop    ax
  3093. c_off_end:
  3094.     ret
  3095. CURSOR_OFF endp
  3096.  
  3097. ; Notify the user that the page is full, and set flag to wait for
  3098. ; him to clear it.
  3099.  
  3100. PAGE_FULL proc    near
  3101.     mov    full_flag,TRUE        ; page is full!
  3102.     call    beep            ; make some noise about it
  3103.     les    di,dword ptr scrloc    ; get screen location
  3104.     add    di,38424        ; lower left corner
  3105.     mov    ax,0FFFFH        ; set them all!
  3106.     xor    es:[di],ax
  3107.     inc    di
  3108.     inc    di
  3109.     xor    es:[di],ax
  3110.     inc    di
  3111.     inc    di
  3112.     xor    es:[di],ax
  3113.     inc    di
  3114.     inc    di
  3115.     xor    es:[di],ax
  3116.     ret
  3117. PAGE_FULL endp
  3118.  
  3119. ; Connect points: start=startx, start+2=starty, endpt=endx, endpt+2=endy
  3120. ;   Uses combination routine pointed at by combine
  3121.  
  3122. LINE    proc    near
  3123.     mov    dx,start        ; start x
  3124.     mov    ax,endpt        ; end x
  3125.     mov    x_inc,1         ; assume incrementing
  3126.     sub    ax,dx
  3127.     jnb    line1            ; correct
  3128.     neg    x_inc
  3129.     neg    ax
  3130. line1:
  3131.     mov    delta_x,ax        ; save delta
  3132.     mov    dx,start+2        ; start y
  3133.     mov    ax,endpt+2        ; end y
  3134.     mov    y_inc,1         ; assume incrementing
  3135.     sub    ax,dx
  3136.     jnb    line2            ; correct
  3137.     neg    y_inc
  3138.     neg    ax
  3139. line2:
  3140.     mov    delta_y,ax        ; save delta
  3141.     les    di,dword ptr scrloc    ; point at bit map region
  3142.     mov    dx,start
  3143.     mov    ax,start+2
  3144.     call    set_pixel        ; set start point
  3145.     mov    ax,delta_y
  3146.     cmp    ax,delta_x        ; which should we step on
  3147.     ja    line_y
  3148. ;
  3149. line_x:
  3150.     mov    cx,delta_x        ; number of steps
  3151.     jcxz    line_x_done        ; nothing to do
  3152.     mov    ax,cx
  3153.     shr    ax,1            ; delta_x/2
  3154.     mov    part_accum,ax
  3155. line_x_loop:
  3156.     mov    ax,x_inc
  3157.     add    start,ax
  3158.     mov    ax,delta_y
  3159.     sub    part_accum,ax
  3160.     jge    line_x_ok
  3161.     mov    ax,y_inc
  3162.     add    start+2,ax
  3163.     mov    ax,delta_x
  3164.     add    part_accum,ax
  3165. line_x_ok:
  3166.     mov    dx,start
  3167.     mov    ax,start+2
  3168.     call    set_pixel
  3169.     loop    line_x_loop
  3170. line_x_done:
  3171.     ret
  3172. ;
  3173. line_y:
  3174.     mov    cx,delta_y        ; number of steps
  3175.     jcxz    line_y_done        ; nothing to do
  3176.     mov    ax,cx
  3177.     shr    ax,1            ; delta_y/2
  3178.     mov    part_accum,ax
  3179. line_y_loop:
  3180.     mov    ax,y_inc
  3181.     add    start+2,ax
  3182.     mov    ax,delta_x
  3183.     sub    part_accum,ax
  3184.     jge    line_y_ok
  3185.     mov    ax,x_inc
  3186.     add    start,ax
  3187.     mov    ax,delta_y
  3188.     add    part_accum,ax
  3189. line_y_ok:
  3190.     mov    dx,start
  3191.     mov    ax,start+2
  3192.     call    set_pixel
  3193.     loop    line_y_loop
  3194. line_y_done:
  3195.     ret
  3196. LINE    endp
  3197.  
  3198. ; Set pixel at location dx,ax
  3199.  
  3200. SET_PIXEL proc    near
  3201.     cmp    dx,X_MAX
  3202.     ja    set_range
  3203.     cmp    ax,Y_MAX
  3204.     ja    set_range
  3205.     call    convert_loc
  3206.     cmp    bx,8            ; top byte?
  3207.     jb    set_noinc        ; no
  3208.     inc    si
  3209.     sub    bx,8
  3210. set_noinc:
  3211.     add    si,di            ; correct offset to segment
  3212.     mov    bl,bit_mask[bx]
  3213.     call    combine
  3214.     ret
  3215. set_range:
  3216.     pop    bx            ; pop one return address
  3217.     ret                ; do nothing if off the screen
  3218. SET_PIXEL endp
  3219.  
  3220. ; Convert x and y to word location and word bit number
  3221. ;   entry: dx=x, ax=y, exit: si=byte number, bx=bit number
  3222.  
  3223. CONVERT_LOC proc near
  3224.     mov    si,ax
  3225.     and    si,0FH            ; mod(y,16)
  3226.     mov    bx,ax
  3227.     and    bx,0FFF0H        ; 16*int(y/16)
  3228.     shl    bx,1            ; *2 (need 50 times)
  3229.     add    si,bx            ; that's 2
  3230.     shl    bx,1            ; *4
  3231.     shl    bx,1            ; *8
  3232.     shl    bx,1            ; *16
  3233.     add    si,bx            ; that's 18
  3234.     shl    bx,1            ; *32
  3235.     add    si,bx            ; that's 50
  3236.     mov    bx,dx
  3237.     and    bx,0FFF0H        ; 16*int(x/16)
  3238.     add    si,bx
  3239.     shl    si,1            ; byte address
  3240.     mov    bx,dx
  3241.     and    bx,0FH            ; mod(x,16)
  3242.     ret
  3243. CONVERT_LOC endp
  3244.  
  3245. ; Or the mask in bl into byte at es:[si]
  3246.  
  3247. PIXEL_OR proc    near
  3248.     or    es:[si],bl
  3249.     ret
  3250. PIXEL_OR endp
  3251.  
  3252. ; Exclusive-or mask in bl into byte at es:[si]
  3253.  
  3254. PIXEL_XOR proc    near
  3255.     xor    es:[si],bl
  3256.     ret
  3257. PIXEL_XOR endp
  3258.  
  3259. ; Or the word in bx into word at es:[si]
  3260.  
  3261. WORD_OR proc    near
  3262.     or    es:[si],bx
  3263.     ret
  3264. WORD_OR endp
  3265.  
  3266. ; Exclusive-or the word in bx into word at es:[si]
  3267.  
  3268. WORD_XOR proc    near
  3269.     xor    es:[si],bx
  3270.     ret
  3271. WORD_XOR endp
  3272.  
  3273. ; Send the status out the back
  3274.  
  3275. SEND_STAT proc    near
  3276.     cmp    graph_mode,FALSE    ; in graph mode?
  3277.     je    send_stat1        ; No
  3278.     push    cur_y            ; push current point, y first
  3279.     push    cur_x            ; then x
  3280.     mov    al,39H            ; bit 7=0, bit 6=1, bit 5=1 (no hcopy)
  3281.                     ; bit 4=1 (ready for vector)
  3282.                     ; bit 3=0 (graph mode)
  3283.                     ; bit 2=0 (margin 0), bit 1=1
  3284.     call    send_coord        ; send it out
  3285.     ret
  3286. ;
  3287. send_stat1:
  3288.     mov    ax,text_y        ; get current point
  3289.     add    ax,10            ; move to lower left corner
  3290.     sub    ax,Y_MAX        ; need to swap it
  3291.     neg    ax
  3292.     mov    bx,TEK_Y_MAX        ; convert to tek coords
  3293.     mul    bx
  3294.     mov    bx,Y_MAX
  3295.     div    bx
  3296.     cmp    dx,Y_MAX/2        ; need to round up?
  3297.     jl    send_stat2
  3298.     inc    ax
  3299. send_stat2:
  3300.     cmp    ax,TEK_Y_MAX        ; up too far?
  3301.     jbe    send_stat3        ; okay
  3302.     mov    ax,TEK_Y_MAX
  3303. send_stat3:
  3304.     push    ax            ; save y
  3305.     mov    ax,text_x
  3306.     mov    bx,TEK_X_MAX        ; convert to tek coords
  3307.     mul    bx
  3308.     mov    bx,X_MAX
  3309.     div    bx
  3310.     cmp    dx,X_MAX/2        ; need to round up?
  3311.     jl    send_stat4
  3312.     inc    ax
  3313. send_stat4:
  3314.     cmp    ax,TEK_X_MAX        ; up too far?
  3315.     jbe    send_stat5        ; okay
  3316.     mov    ax,TEK_X_MAX
  3317. send_stat5:
  3318.     push    ax            ; save x
  3319.     mov    al,3DH            ; bit 7=0, bit 6=1, bit 5=1 (no hcopy)
  3320.                     ; bit 4=1 (ready for vector)
  3321.                     ; bit 3=1 (not graph mode)
  3322.                     ; bit 2=0 (margin 0), bit 1=1
  3323.     call    send_coord        ; send it out
  3324.     ret
  3325. SEND_STAT endp
  3326.  
  3327. ; Send the byte currently in the al register out the port, then follow
  3328. ; it by the coordinates - x is the first on the stack, y is the second
  3329. ; on the stack (i.e., x was pushed last, and popped first)
  3330.  
  3331. SEND_COORD proc near
  3332.     call    outprt            ; send byte in al
  3333.     pop    cx            ; this is the return address
  3334.     pop    ax            ; this is x coord
  3335.     pop    bx            ; this is y coord
  3336.     push    cx            ; return back on
  3337.     push    bx            ; y back on
  3338.     push    ax            ; x back on
  3339.     mov    cl,5            ; shift to hix
  3340.     shr    ax,cl
  3341.     and    al,31            ; keep 5 bits
  3342.     or    al,32            ; this is hix now
  3343.     call    outprt
  3344.     pop    ax            ; x again
  3345.     and    al,31
  3346.     or    al,64            ; this is lox now
  3347.     call    outprt
  3348.     pop    ax            ; get y coordinate
  3349.     push    ax            ; save it again for a flash
  3350.     mov    cl,5            ; shift to hiy
  3351.     shr    ax,cl
  3352.     and    al,31            ; keep 5 bits
  3353.     or    al,32            ; this is hiy now
  3354.     call    outprt
  3355.     pop    ax            ; y again
  3356.     and    al,31
  3357.     or    al,96            ; this is loy now
  3358.     call    outprt
  3359. ;   Now for the termination string - use CR,EOT - this is the default for
  3360. ;   the 4051 microcomputer which is supposed to look like a 4012 - I hope
  3361. ;   they know what they are doing...
  3362.     mov    al,13
  3363.     call    outprt
  3364.     mov    al,4
  3365.     call    outprt
  3366.     ret
  3367. SEND_COORD endp
  3368.  
  3369. OUTPRT    proc    near
  3370.     test    yflags,lclecho    ; echoing?
  3371.     jz    outpr1        ; z = no, forget it
  3372.     cmp    flags.vtflg,TTTEK ; doing TEKTRONIX?
  3373.     je    outpr00     ; e = yes, echo it nicely
  3374.     cmp    flags.vtflg,TTVT100 ; doing VT100?
  3375.     je    outpr0        ; e = yes, echo it nicely
  3376.     push    ax        ; save char
  3377.     call    outtty        ; print it
  3378.     pop    ax        ; restore
  3379.     jmp    outpr1
  3380. outpr00:cmp    full_flag,FALSE     ; page full?
  3381.     jne    outpr1            ; forget this
  3382.     push    ax
  3383.     call    tekhandle        ; do the job in a smart way
  3384.     pop    ax
  3385.     jmp    outpr1
  3386. outpr0:    push    ax            ; save char
  3387.     call    doansi
  3388.     pop    ax            ; restore
  3389. outpr1:    mov    ah,al            ; this is where outchr expects it
  3390.     call    outchr            ; output to the port
  3391.     jc    outpr4            ; c = failure
  3392.     ret
  3393. outpr4:    jmp    endcon            ; failure, end connection
  3394. OUTPRT    endp
  3395.  
  3396. ; Get a character from the serial port in al
  3397. ; returns with carry clear if a character is available
  3398.  
  3399. PORTCHR proc    near
  3400.     call    prtchr        ; character at port?
  3401.     jnc    portc1        ; nc = yes
  3402. portc0: ret
  3403. portc1:    and    al,parmsk    ; apply 8/7 bit parity mask
  3404.     or    al,al        ; is it a null char?
  3405.     jz    portc0        ; z = yes, ignore it
  3406. portc2: clc            ; have a character
  3407.     ret            ; and return
  3408. PORTCHR endp
  3409.  
  3410. ; Put the character in al to the screen
  3411. ; Directly call the console-driver to get better speed (4 times, ~19200
  3412. ; baud)  [as]
  3413.  
  3414. OUTTTY    proc    near
  3415.     call    capture
  3416.     push    ax        ; these are modified by the driver
  3417.     push    bx
  3418.     push    cx
  3419.     push    dx
  3420.     push    si
  3421.     push    es
  3422.     mov    cl,al
  3423.     mov    ax,1
  3424.     call    dword ptr drivadr
  3425.     pop    es
  3426.     pop    si
  3427.     pop    dx
  3428.     pop    cx
  3429.     pop    bx
  3430.     pop    ax
  3431.     ret            ; through
  3432. OUTTTY    endp
  3433.  
  3434. ; Capture char in al to a file if we are supposed to
  3435. ; Translation taken from msyibm with minimal modification
  3436.  
  3437. CAPTURE proc    near
  3438.     test    yflags,CAPT    ; capturing output?
  3439.     jz    nocap        ; no forget this part
  3440.     push    ax        ; save it
  3441.     call    captrtn
  3442.     pop    ax        ; get char back
  3443. nocap:    test    flags1,PRTSCR    ; should we be printing?
  3444.     jz    noprt        ; no, go on
  3445.     call    pntchr        ; printer routine
  3446.     jnc    noprt        ; nc = successful print
  3447.     push    ax
  3448.     call    beep        ; else make a noise and
  3449.     call    trnprs        ;  turn off printing
  3450.     pop    ax
  3451. noprt:    ret
  3452. CAPTURE endp
  3453.  
  3454. ; Set heath emulation on/off.
  3455. ; Added VT100 emulation switch and TEKTRONIX switch - notifies of
  3456. ; idiosyncracies if TEKTRONIX selected (also checks for allowability)
  3457. ; [bgp].  With the addition of the official TEKTRONIX terminal type
  3458. ; we no longer have to warn about weird results.
  3459.  
  3460. VTS    proc    near
  3461.     mov    dx,offset termtb
  3462.     mov    bx,offset termhlp
  3463.     mov    ah,CMKEY
  3464.     call    comnd
  3465.     jc    vtx        ; c = failure
  3466.     push    bx
  3467.     mov    ah,cmeol
  3468.     call    comnd        ; Get a confirm
  3469.     pop    bx
  3470.     jc    vtx
  3471.     cmp    bx,TTTEK    ; doing TEKTRONIX?
  3472.     jne    vt1        ; no
  3473.     cmp    tek_allowed,FALSE ; can we do TEKTRONIX?
  3474.     jne    vt1        ; yes
  3475.     mov    dx,offset no_tek_msg ; tell him we can't
  3476.     mov    ah,PRSTR
  3477.     int    DOS
  3478.     ret            ; don't do anything
  3479. vt1:    mov    flags.vtflg,bx    ; Set the emulation flag.
  3480. vtx:    ret
  3481. VTS    endp
  3482.  
  3483. VTSTAT    PROC    NEAR        ; For Status display [jrd]
  3484.     ret            ; no emulator status to display
  3485. VTSTAT    ENDP
  3486.  
  3487. ; Control text cursor. AL = 0 for off, 1 for on (nominally underline)
  3488. csrtype proc    far
  3489.     push    dx
  3490.     mov    escstring,ESCAPE
  3491.     mov    escstring+1,'y'
  3492.     mov    escstring+2,'5'
  3493.     mov    escstring+3,'$'
  3494.     or    al,al        ; set mode?
  3495.     jnz    csrty1        ; nz = yes
  3496.     dec    escstring+1    ; 'x' is reset mode ESC x 5
  3497. csrty1:    mov    dx,offset escstring ; pass string to screen console
  3498.     mov    ah,PRSTR
  3499.     int    DOS
  3500.     pop    dx
  3501.     ret
  3502. csrtype endp
  3503.  
  3504. ; The following are keyboard translator access routines added 29 August 1987.
  3505. ; They are invoked by a jump instruction.  They must return carry clear to
  3506. ; continue processing or carry set to exit from Connect mode, in which case
  3507. ; kbdflg will have the transfer character in it. [bgp]
  3508.  
  3509. chrout:    call    outprt        ; send a character out the port
  3510.     clc
  3511.     ret
  3512.  
  3513. cpage:    cmp    flags.vtflg,TTTEK   ; only works on tektronix emulation
  3514.     jne    cpage1
  3515.     call    clrscr        ; clear the tektronix screen
  3516.     clc
  3517.     ret
  3518. cpage1:    call    beep
  3519.     clc
  3520.     ret
  3521.  
  3522. chome:     cmp    flags.vtflg,TTTEK   ; only works on tektronix emulation
  3523.     jne    chome1
  3524.     call    homescr     ; home the tektronix screen
  3525.     clc
  3526.     ret
  3527. chome1:    call    beep
  3528.     clc
  3529.     ret
  3530.  
  3531. cquery:    mov    al,'?'
  3532.     jmp    cmdcom
  3533. cstatus:mov    al,'S'
  3534.     jmp    cmdcom
  3535. cquit:    mov    al,'C'
  3536.     jmp    cmdcom
  3537. chang:    mov    al,'H'
  3538.     jmp    cmdcom
  3539. kdos:    mov    al,'P'
  3540.     jmp    cmdcom
  3541. cmdcom:    mov    kbdflg,al    ; pass to msster.asm via kbdflg
  3542.     stc            ; need to exit connect mode
  3543.     ret
  3544.  
  3545. dmpscn:    cmp    flags.vtflg,TTTEK   ; emulating tektronix?
  3546.     jne    dmpscn1     ; no, do it
  3547.     jmp    dmpscn2     ; can't on tektronix...
  3548. dmpscn1:call    savescr     ; have to save screen to dump it
  3549.     call    dumpscr
  3550.     call    restscr     ; need to put it back again too
  3551.     clc
  3552.     ret
  3553. dmpscn2:call    beep        ; nothing else to do I guess
  3554.     clc
  3555.     ret
  3556.  
  3557. snull:    xor    ah,ah        ; send a null
  3558.     call    outchr        ; send without echo or logging
  3559.     clc
  3560.     ret
  3561.  
  3562. klogof:    mov    bx,argadr    ; need to fix args
  3563.     and    [bx].flags,not CAPT ; clear capture flag
  3564.     and    yflags,not CAPT ; also local copy
  3565.     clc
  3566.     ret
  3567.  
  3568. klogon:    test    flags.capflg,LOGSES ; logging enabled?
  3569.     jz    klogon1
  3570.     mov    bx,argadr    ; need to fix args
  3571.     or    [bx].flags,CAPT ; set capture flag
  3572.     or    yflags,CAPT    ; also local copy
  3573. klogon1:clc
  3574.     ret
  3575.  
  3576. trnprs:    push    ax            ; toggle ^ PrtSc screen to printer
  3577.     test    yflags,prtscr        ; are we currently printing?
  3578.     jnz    trnpr2            ; nz = yes, its on and going off
  3579.     push    bx
  3580.     mov    bx,prnhand        ; file handle for system printer
  3581.     mov    ah,ioctl
  3582.     mov    al,7            ; get output status of printer
  3583.     int    dos
  3584.     pop    bx
  3585.     jc    trnpr1            ; c = printer not ready
  3586.     cmp    al,0ffh            ; Ready status?
  3587.     je    trnpr2            ; e = Ready    
  3588. trnpr1:    call    beep            ; Not Ready, complain
  3589.     jmp    trnpr3            ; and ignore request
  3590. trnpr2:    xor    yflags,prtscr        ; flip the flag
  3591.     test    yflags,modoff        ; mode line off?
  3592.     jnz    trnpr3            ; nz = yes
  3593.     call    modlin            ; else rewrite mode line
  3594. trnpr3:    pop    ax
  3595.     clc                ; return carry clear (don't quit)
  3596.     ret
  3597.  
  3598. ; Error recovery routine used when outchr reports unable to send character
  3599. ;  or when vtmacro requests exiting Connect mode.
  3600. ; Exit Connect mode cleanly, despite layers of intermediate calls.
  3601. endcon    proc    near
  3602.     call    pntflsh            ; flush printer buffer
  3603.     mov    kbdflg,'C'        ; report 'C' to TERM's caller
  3604.     mov    sp,oldsp        ; recover startup stack pointer
  3605.                     ; TERM caller's return address is now
  3606.                     ; on the top of stack. A longjmp.
  3607.     jmp    quit            ; exit Connect mode cleanly
  3608. endcon    endp
  3609.  
  3610.  
  3611. ; Invoked by keyboard translator when an unknown keyboard verb is used as
  3612. ; a string definition, such as {\ktest}. Enter with vtmacname pointing to
  3613. ; uppercased verb name, asciiz, and vtmaclen set to its length.
  3614. extmacro proc    near
  3615.     jmp    vtmacro            ; finish in common code
  3616. extmacro endp
  3617.  
  3618. ;
  3619. ; Reference    Macro structure for    db    number of entries (mac names)
  3620. ;  is file     table mcctab       |->    db    length of macroname, excl '$'
  3621. ;  mssset.asm        each entry |->     db    'macroname','$'
  3622. ;  where these               |->    dw    segment:0 of definition string
  3623. ;  are stored.                      (offset part is always 0)    
  3624. ;        Definition string in     db    length of <string with null>
  3625. ;         buffer macbuf          db    'string with trailing null'
  3626. ;
  3627. vtmacro    proc    near            ; common code for macros vtsmac,vtrmac
  3628.     push    bx            ; and Product
  3629.     push    cx
  3630.     push    si
  3631.     push    di
  3632.     push    es
  3633.     mov    ax,ds
  3634.     mov    es,ax
  3635.     mov    di,offset rdbuf+1    ; macro def buffer starts here
  3636.     mov    si,vtmacname        ; pointer to macro name
  3637.     mov    cl,vtmaclen        ; length of macro name<sp/null>text
  3638.     xor    ch,ch
  3639.     mov    [di-1],cl        ; counted string field
  3640.     cld
  3641.     rep    movsb            ; copy to rdbuf
  3642.     mov    byte ptr [di],0        ; null terminator
  3643.     mov    si,offset rdbuf+1    ; look for name-text separator
  3644.     mov    cl,vtmaclen
  3645.     xor    ch,ch
  3646. vtmac1:    lodsb
  3647.     cmp    al,' '            ; space separator?
  3648.     je    vtmac1a            ; e = yes, stop here
  3649.     or    al,al            ; null terminator?
  3650.     jz    vtmac1a            ; e = yes, stop here
  3651.     loop    vtmac1
  3652.     inc    si            ; to do null lenght correctly
  3653. vtmac1a:sub    si,offset rdbuf+1+1    ; compute length of macro name
  3654.     mov    cx,si
  3655.     mov    vtmaclen,cl        ; save a macro name length
  3656.                     ; check for existence of macro
  3657.     mov    bx,offset mcctab    ; table of macro names
  3658.     mov    cl,[bx]            ; number of names in table
  3659.     xor    ch,ch
  3660.     jcxz    vtmacx            ; z = empty table, do nothing
  3661.     inc    bx            ; point to length of first name
  3662. vtmac2:    mov    al,[bx]            ; length of this name
  3663.     xor    ah,ah
  3664.     cmp    al,vtmaclen        ; length same as desired keyword?
  3665.     jne    vtmac3            ; ne = no, search again
  3666.     mov    si,bx
  3667.     inc    si            ; point at first char of name
  3668.     push    cx            ; save name counter
  3669.     push    di            ; save reg
  3670.     mov    cl,vtmaclen        ; length of name, excluding '$'
  3671.     xor    ch,ch
  3672.     mov    di,vtmacname        ; point at desired macro name
  3673.     push    es            ; save reg
  3674.     push    ds
  3675.     pop    es            ; make es use data segment
  3676.     cld
  3677.     repe    cmpsb            ; match strings
  3678.     pop    es            ; need current si below
  3679.     pop    cx
  3680.     pop    di            ; recover saved regs
  3681.     je    vtmac4            ; e = matched
  3682. vtmac3:    add    bx,ax            ; step to next name, add name length
  3683.     add    bx,4            ; + count, dollar sign, def word ptr
  3684.     loop    vtmac2            ; try next name
  3685. vtmacx:    pop    es
  3686.     pop    di
  3687.     pop    si            ; no macro, return to Connect mode
  3688.     pop    cx
  3689.     pop    bx
  3690.     ret
  3691.  
  3692. vtmac4:    cmp    taklev,maxtak        ; room in Take level?
  3693.     jge    vtmacx            ; ge = no, exit with no action
  3694.     inc    taklev            ; increment take level
  3695.     add    takadr,size takinfo    ; make a new Take entry/macro
  3696.     mov    bx,takadr        ; point to current macro structure
  3697.     mov    ax,ds            ; segment of rdbuf
  3698.     mov    [bx].takbuf,ax        ; segment of definition string struc
  3699.     mov    cl,rdbuf        ; length of whole string
  3700.     xor    ch,ch
  3701.     mov    [bx].takcnt,cx        ; number of chars in definition
  3702.     mov    [bx].takargc,0        ; our argument count
  3703.     mov    [bx].takptr,offset rdbuf+1 ; where to read next command char
  3704.     mov    [bx].taktyp,0ffh    ; flag as a macro
  3705.     pop    es
  3706.     pop    di
  3707.     pop    si
  3708.     pop    cx
  3709.     pop    bx
  3710.     jmp    endcon            ; exit Connect mode
  3711. vtmacro    endp
  3712.  
  3713. ; Service SET NETBIOS-NAME name   command at Kermit prompt level
  3714. setnbios proc    near
  3715.     ret
  3716. setnbios endp
  3717. sesdisp    proc    near
  3718.     ret
  3719. sesdisp    endp
  3720.  
  3721. CODE    ends
  3722.     end
  3723.