home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / msk316src.zip / MSYIBM.ASM < prev    next >
Assembly Source File  |  1999-04-24  |  262KB  |  8,837 lines

  1.     NAME msyibm
  2. ; File MSYIBM.ASM
  3.     include mssdef.h
  4. ;    Copyright (C) 1982, 1999, Trustees of Columbia University in the 
  5. ;    City of New York.  The MS-DOS Kermit software may not be, in whole 
  6. ;    or in part, licensed or sold for profit as a software product itself,
  7. ;    nor may it be included in or distributed with commercial products
  8. ;    or otherwise distributed by commercial concerns to their clients 
  9. ;    or customers without written permission of the Office of Kermit 
  10. ;    Development and Distribution, Columbia University.  This copyright 
  11. ;    notice must not be removed, altered, or obscured.
  12. ; Edit history
  13. ; 12 Jan 1995 version 3.14
  14. ; Last edit
  15. ; 12 Jan 1995
  16.  
  17.     public    lclyini, csrtype, fcsrtype, scrseg
  18.     public    atsclr, trnmod, vtbell, vtroll, crt_lins, crt_cols
  19.     public    vtemu, crt_mode, scbattr, refresh, low_rgt    ; data
  20.     public    setchtab, extattr, vtcpage, tv_mode, dos_bottom
  21.     public    setpos, setatch, yflags, vtinited, useexp
  22.     public    vts, vtstat, termtb, modbuf, qsetatch    ; terminal emulation
  23.     public    tv_segs, tv_sego
  24.  
  25. ifndef    no_terminal
  26.     public    term, enqbuf
  27.     public    chgdsp, vtclear, ftogmod, getatch, nextses,  setprot, clrprot
  28.     public    prtbout, prtnout, vtscru, vtscrd, vclick, reset_color
  29.     public    getbold, setbold, clrbold, getblink, setblink, clrblink
  30.     public    getunder, setunder, clrunder, revideo, revscn, setcolor
  31.     public    setrev, clrrev, frepaint, touchup, reversed_screen
  32.             ; action verb procedures for keyboard translator
  33.     public    uparrw, dnarrw, rtarr, lfarr, pf1, pf2, pf3, pf4
  34.     public    kp0, kp1, kp2, kp3, kp4, kp5, kp6, kp7, kp8, kp9
  35.     public    kpminus, kpcoma, kpenter, kpdot, chrout, cstatus, cquit
  36.     public    cquery, dmpscn,    vtans52, vtinit, dnwpg, upwpg, endwnd, homwnd
  37.     public    upone, dnone, trnprs, dumpscr, modlin, snull, ignore_key
  38.     public    klogon, klogof, cdos, chang, khold, product, termesc_flag
  39.     public    vtksmac, vtkrmac, apcmacro, apcenable, vtenqenable
  40.     public    decf6,decf7,decf8,decf9,decf10,decf11,decf12,decf13,decf14
  41.     public    dechelp,decdo,decf17,decf18,decf19,decf20, udkclear
  42.     public    decfind, decinsert, decremove, decselect, decprev
  43.     public    decnext, setudk, extmacro, vtmacname, vtmaclen
  44.     public    rtone, lfone, rtpage, lfpage, kbdcompose, kdebug
  45.     public    dgkc1,dgkc2,dgkc3,dgkc4,dgkf1,dgkf2,dgkf3,dgkf4,dgkf5
  46.     public    dgkf6,dgkf7,dgkf8,dgkf9,dgkf10,dgkf11,dgkf12,dgkf13
  47.     public    dgkf14,dgkf15, dgpoint, dgnckey
  48.     public    dgkSf1,dgkSf2,dgkSf3,dgkSf4,dgkSf5,dgkSf6,dgkSf7,dgkSf8
  49.     public    dgkSf9,dgkSf10,dgkSf11,dgkSf12,dgkSf13,dgkSf14,dgkSf15
  50.     public    udkf6, udkf7, udkf8, udkf9, udkf10, udkf11, udkf12, udkf13
  51.     public    udkf14, udkf15, udkf16, udkf17, udkf18, udkf19, udkf20
  52.     public    wykf1,wykf2,wykf3,wykf4,wykf5,wykf6,wykf7,wykf8
  53.     public    wykf9,wykf10,wykf11,wykf12,wykf13,wykf14,wykf15,wykf16
  54.     public    wykSf1,wykSf2,wykSf3,wykSf4,wykSf5,wykSf6,wykSf7,wykSf8
  55.     public    wykSf9,wykSf10,wykSf11,wykSf12,wykSf13,wykSf14,wykSf15,wykSf16
  56.     public    dgsettek, vtclrflg, tn_AYT, tn_IP, jpnxltkey, rcvmacro
  57.     public    srvmacro, crdisp_mode
  58. ifndef    no_tcp
  59.     public    termswapout, termswapin, termswapdel, commbyte
  60.     public    ses1, ses2, ses3, ses4, ses5, ses6
  61. endif    ; no_tcp
  62. endif    ; no_terminal
  63.  
  64. ; some definitions
  65. SIchar    equ    0fh
  66. SOchar    equ    0eh
  67. DGescape equ    1eh
  68. CSI    equ    9bh
  69. SS2    equ    8eh
  70. SS3    equ    8fh
  71. bapito_3270 equ 0b3h            ; KERMIT BAPI extension, byte to 3270
  72.  
  73. ; hardware
  74. crt_status equ    3dah            ; CGA crt status port
  75. disp_enb equ    8            ; CGA display enable bit
  76. crtmset    equ    3D8H            ; CGA CRT mode set port
  77. screen    equ    10h            ; Bios screen interrupt
  78.  
  79. att_protect    equ    01h        ; protected    in vsatt
  80. att_uline    equ    02h        ; underscored    in vsatt
  81. att_rev        equ    04h        ; reversed video  in vsatt
  82. att_bold    equ    08h        ; bold        in main video word
  83. att_blink    equ    80h        ; blinking    in main video word
  84.  
  85. att_low_mask    equ    06H        ; Various attribute-related equates
  86. ;;;att_normal    equ    07h
  87. att_underline    equ    01H        ; for mono monitors, in video word
  88. ifndef    nls_portuguese
  89.  
  90. modfrm    struc                ; format of mode (status) line
  91.     db    'Esc:Alt-x help:Alt-h port:'
  92. m_prt    db    20 dup (' ')
  93. m_baud    db    6 dup (' ')
  94. m_par    db    3 dup (' ')
  95.     db    ' echo:'
  96. m_echo    db    3 dup (' ')
  97. m_term    db    12 dup (' ')        ; 12 bytes for term type
  98. m_prn    db    3 dup (' ')        ; show PRN when printer is on
  99. m_comp    db    ' '            ; Compose indicator
  100.     db    '$'            ; terminator
  101. modfrm    ends
  102.  
  103. else
  104.  
  105. modfrm    struc                ; format of mode (status) line
  106.     db    'Esc:Alt-X help:Alt-H porta:'
  107. ;    db    'Carac-Esc:   ajuda:   ? porta:'
  108. ;    db    'Carac-Esc:'        ; do not write in last column
  109. m_prt    db    19 dup (' ')
  110. m_baud    db    6 dup (' ')
  111. m_par    db    3 dup (' ')
  112.     db    '  eco:'
  113. m_echo    db    3 dup (' ')
  114. m_term    db    12 dup (' ')        ; 12 bytes for term type
  115. m_prn    db    3 dup (' ')        ; show PRN when printer is on
  116. m_comp    db    ' '            ; Compose indicator
  117.     db    '$'            ; terminator
  118. modfrm    ends
  119. endif    ; nls_portuguese
  120.  
  121. ; structure for status information table sttab.
  122. stent    struc
  123. sttyp    dw    ?        ; type (actually routine to call)
  124. msg    dw    ?        ; message to print
  125. val2    dw    ?        ; needed value: another message, or tbl addr
  126. tstcel    dw    ?        ; address of cell to test, in data segment
  127. basval    dw    0        ; base value, if non-zero
  128. stent    ends
  129.  
  130.  
  131. data    segment
  132.     extrn    flags:byte, decbuf:byte, rdbuf:byte, xms:dword
  133.     extrn    filtst:byte, dmpname:byte, kbdflg:byte, rxtable:byte
  134.     extrn    trans:byte, comand:byte, kstatus:word, prnhand:word
  135.     extrn    comptab:byte, dosnum:word, fossil_port:word, termserver:byte
  136. ifndef    no_terminal
  137.     extrn    anspflg:byte, scroll:byte, ttyact:byte
  138.     extrn    mar_top:byte, mar_bot:byte, npages:word
  139.     extrn    holdscr:byte, portval:word
  140.     extrn    taklev:byte, takadr:word, mcctab:byte, dupflg:byte
  141.     extrn    apctrap:byte, denyflg:word
  142.     extrn    kbcodes:byte, repflg:byte
  143.     extrn    param:word, nparam:word
  144.     extrn    upss:byte, GRptr:word, G1set:byte, G2set:byte
  145.     extrn    G3set:byte, cursor:word, linescroll:byte
  146.     extrn    savezlen:word, savezoff:word
  147.     extrn    savexoff:word, savexlen:word, savepoff:word
  148.     extrn    saveplen:word, rollwidth:word, dgkbl:byte, apcstring:word
  149.     extrn    blinkdis:byte, protectena:byte, dghscrdis:byte
  150.     extrn    dgwindcomp:byte, att_normal:byte
  151.     extrn    emsrbhandle:word, curattr:byte, saveuoff:word, saveulen:word
  152.     extrn    dgd470mode:byte, tekflg:byte, xmsrhandle:word
  153.     extrn    xmsghandle:word, xmsep:dword
  154.     extrn    parmsk:byte, flowon:byte, flowoff:byte, flowcnt:byte
  155.     extrn    isps55:byte        ; [HF]940130 in MSXIBM.ASM
  156.     extrn    ps55mod:byte        ; [HF]940206 in MSXIBM.ASM
  157.     extrn domath_ptr:word, domath_cnt:word, domath_msg:word
  158. ifndef    no_graphics
  159.     extrn    chcontrol:byte, softlist:word
  160.     extrn    tekgraf:byte, tekcursor:byte, dgcross:byte, cursorst:byte
  161.     extrn    savegoff:word, saveglen:word
  162.  
  163. endif    ; no_graphics
  164. ifndef    no_network
  165. ifndef    no_tcp
  166.     extrn    tcpnewline:byte
  167.     extrn    seslist:byte, sescur:word, tcphost:byte, tcpmode:byte
  168.     extrn    sestime:byte
  169. endif    ; no_tcp
  170. endif    ; no_network
  171. endif    ; no_terminal
  172.  
  173. inited    equ    08h            ; been here before
  174. prtscr    equ    1            ; print screen pressed
  175.  
  176. ; stuff for screen routines
  177. ;;;;;;;;;;;;;; start session save area
  178.     even
  179. saveyoff label    word
  180. yflags    db    0            ; status flags
  181. vtemu    emulst    <>            ; emulator flags
  182. vtsave    db    7 dup (0)        ; inuse/color/charset save around ANSI
  183. belltype db    0            ; 0 = aural bell, 1 = visual
  184. scbattr db    ?            ; screen background attribute
  185. savattr    db    ?            ; current emulator attributes
  186. extattr    db    0            ; extended scbattr
  187. colunder db    0ffh            ; underline color (0ffh = uninited)
  188. vtclrflg db    0            ; erase with scbattr(0) or curattr(1)
  189. vtclkflg db    1            ; status line clock (0=off)
  190. reversed_screen db 0            ; if whole screen has been reversed
  191. crt_mode db    3            ; video mode (typ 3, must be text)
  192.                     ; keep crt_cols & crt_lins in order
  193. crt_cols db    80            ; number of screen columns (typ 80)
  194. crt_lins db    24            ; number of screen rows - 1 (typ 24)
  195. dos_bottom db    24            ; num of rows-1 at DOS level (typ 24)
  196. low_rgt    dw    174fh            ; lower right corner of text window
  197.                     ; high = row address (typ 23)
  198.                     ; low = column address (typ 79)
  199. handhsc    db    0            ; hand horizontal scroll
  200. dosetcursor dw    -1            ; place to set tekcursor, -1 = don't
  201. vtinited db    0            ; flag for emulator having been inited
  202. vtclear    db    0            ; nonzero to redo emulator screen
  203. reset_color db    0            ; reset color on CSI m
  204. writemode db    0            ; screen writing mode
  205. vchgmode db    2            ; video-change mode (0=enabled)
  206. vtcpage    dw    437            ; terminal code page
  207. apcenable db    0            ; enable APC macro (default is off)
  208. vtenqenable db    0            ; enable Answerback
  209. saveflag    flginfo <>        ; copy of flags array
  210. ytermtype dw    0
  211. ymodetype db    0
  212. keypend dw    0            ;[HF]940207 buffer for double byte code
  213. keyj7st    dw    0            ;[HF]940211 keyoutput status for JIS7
  214. enqbuf    db    40 dup (0),0        ; local enquiry string, asciiz
  215. crdisp_mode db    0            ; CR display mode
  216. saveylen dw    ($ - saveyoff)
  217. ;;;;;;;;;;;;;;;;; end of session save area
  218.  
  219.  
  220. modbuf    modfrm    <>            ; mode line buffer
  221. argadr    dw    0            ; address of arg blk
  222. skip    dw    0
  223. inemulator db    0            ; non-zero if term emlator active
  224. inwindows db    0            ; non-zero if Windows is active
  225. crlf    db    cr,lf,'$'
  226.     even
  227.  
  228.  
  229. ifndef    no_terminal
  230.  
  231. vid7id    db    'VEGA BIOS Code, '    ; Video 7 Vega version string subset
  232. vid7len    equ    $-vid7id        ; length of string
  233. vid7id2    db    'Video Seven BIOS Code, ' ; Video 7 VGA board
  234. vid7len2 equ    $-vid7id2
  235. atiwid    db    'ATI EGA Wonder Bios,'    ; ATI EGA wonder version string subset
  236. atilen    equ    $-atiwid        ; length of string, inc terminator
  237. atiwid2    db    '761295520'        ; ATI signature #2
  238. atilen2    equ    $-atiwid2
  239. tsngid    db    'Tseng'            ; Tseng Labs EVA (& Orchid Designer)
  240. tsnglen    equ    $-tsngid
  241. stbvid    db    'TVGA'            ; STB VGA/EM (also Tseng TVGA)
  242. stbvlen    equ    $-stbvid
  243. stavid    db    '4000'            ; STB VGA/EM Plus (Tesng 4000)
  244. stavlen equ    $-stavid
  245. evrxid  db      'Everex'                ; Everex Micro Enhancer Deluxe EGA
  246. evrxlen equ     $-evrxid
  247. evgid    db    'VGA EV673'        ; Everex EVGA EV-673
  248. evglen    equ    $-evgid
  249. evvid    db    'EV-678'        ; Everex Viewpoint EV-678
  250. evvlen    equ    $-evvid
  251. attvdc6    db    '003116'        ; AT&T video board, at c000:35h
  252. attvdlen equ    $-attvdc6
  253. attvdc7    db    'C02000'        ; AT&T video board, at e000:10h
  254. pmega1    db    '28190-A1001'        ; Paradise AutoSwitch EGA Mono String1
  255. pmegal1 equ    $-pmega1        
  256. p30id    db    'VGA'            ; VGA Plus, Plus 16, Professional
  257. p30ln    equ    $-p30id            ;  and VGA1024 by Paradise
  258. emsrollname db    'KERMIT  ',0        ; 8 byte EMS region name, + safety
  259. pageready dw    -1            ; ems page currently active
  260. cols80    db    'COLS80.BAT',0        ; to 80 column mode batch file
  261. cols132    db    'COLS132.BAT',0        ; to 132 column mode batch file
  262. xga_reg_base dw    -1            ; PS/2 MCA I/O register base
  263. emsname    db    'EMMXXXX0',0        ; expanded memory manager dev name
  264. jis7des    db    'B','B'        ; [HF] 941016 JIS7 designators (Kanji/ASCII)
  265. cpwarn    db    cr,lf
  266.     db    '?Warning: Code Page CP866 is required but it is not active.$'
  267. endif    ; no_terminal
  268.  
  269. ega_mode db    0            ; non-zero if IBM EGA is in use
  270. tvhere    equ    0feh            ; Topview active query
  271. tvsynch    equ    0ffh            ; Topview resynch request
  272. tv_segs    dw    0            ; Topview virtual screen, segment
  273. tv_sego    dw    0            ; and offset
  274. tv_mode    db    0            ; flag, 0 = no Topview or DESQview
  275. vtcpumode db    0            ; timeslice-release (0 = enabled)
  276. vs_ptr    dd    0            ; offset, segment of vscreen (dynamic)
  277. vsat_ptr dd    0            ; offset, segment of vs's attributes
  278. ; Note: (vswidth+1)/2 bytes of attributes/line, at two attributes/byte
  279. vswidth    equ    207            ; columns across DG virtual screen
  280.  
  281. ; The following are used to turn the display back on (after scrolling etc.)
  282. msets    db    2CH,28H,2DH,29H,2AH,2EH,1EH,29H
  283. wysecurtab db    0bh,0ah,0ch,08h        ; VT to Wyse-50 cursor converter
  284. dgcurtab db    23,26,24,25        ; ANSI to DG cursor converter
  285. dgcrostab db    72,80,77,75        ; DG cursor to PC scan for croshair
  286.  
  287. mtty    db    '  TTY   '        ; no terminal type (mode line)
  288. fairness dw    0
  289. fairprn    dw    0
  290. lincur    dw    ?            ; cursor type save area
  291. dosattr    db    ?            ; screen attributes at init time
  292. userbold db    0            ; screen bold attribute at start up
  293. dos_cols db    0            ; screen width (crt_cols) at DOS
  294.  
  295. ifndef    no_terminal
  296.  
  297. oldsp    dw    0            ; offset to longjmp to for i/o failure
  298. ten    db    10            ; byte constant for key defines
  299. temp    dw    0            ; scratch storage
  300. temp2    dw    0            ; scratch storage
  301. endif    ; no_terminal
  302.  
  303. ifndef    no_terminal
  304.  
  305. dmphand    dw    -1            ; screen dump file handle
  306. dumpsep    db    0ch,cr,lf        ; screen image separators
  307. dmperr    db    ' Cannot open file to save screen to disk $'
  308. memerr    db    cr,lf,'Not enough memory for terminal emulator$'
  309. pntmsg    db    'Printer not ready, printing request skipped$'
  310. ; some static data for mode line
  311. modmaster modfrm <>            ; master template
  312. unkbaud    db    'unkwn '        ; must be 6 chars
  313. baudn    db    ' 45.5 ',' 50   ',' 75   ',' 110  ','134.5 ',' 150  ',' 300  '
  314.     db    ' 600  ',' 1200 ',' 1800 ',' 2000 ',' 2400 ',' 4800 ',' 9600 '
  315.     db    '14400 ', '19200 ','28800 ', '38400 ','57.6K ','115 K '
  316.     db    '75/12 '
  317. baudnsiz  equ    21            ; # of baud rates known (tbl size / 6)
  318. repmsg    db    'REPLAY'        ; REPLAY message for speed field
  319. repmsgl    equ    $-repmsg
  320. parnams    db    '7e1','7m1','8n1','7o1','7s1'
  321. lclmsg    db    'loc'
  322. remmsg    db    'rem'
  323. portno    db    0
  324. termesc_flag db 0            ; SET TERM ESCAPE flag
  325. endif    ; no_terminal
  326.  
  327. ; storage for multi-window stuff
  328. slen    equ    24            ; and length of text
  329. crt_norm db    3            ; video mode for normal screen
  330.                     
  331. inipara    dw    0            ; initial paragraphs of scroll memory
  332.                     ;  also is number ems pages for same
  333. refresh    db    0            ; screen refresh (0=wait for retrace)
  334. vtroll    db    0            ; auto roll back allowed (0 = no)
  335. useexp    db    0            ; non-zero to use exp mem for rollback
  336. vsbuff_inited db 0            ; non-zero if inited screen buffers
  337. setnoshow db    0            ; quiet setatch flag
  338. lastsec    db    -1            ; seconds of last gettim call
  339.  
  340. ifndef    no_terminal
  341. vtkrname db    'KEYBOARDR'        ; a macro name, must be Upper Case
  342. vtkrlen    equ    $-vtkrname
  343. vtksname db    'KEYBOARDS'        ; a macro name, must be Upper Case
  344. vtkslen    equ    $-vtksname
  345. prodname db    'PRODUCT'
  346. vtplen    equ    $-prodname
  347. vtsesname db    'SESSION'
  348. vtsesnum db    '1'
  349. vtseslen equ    $-vtsesname
  350.  
  351. vtmacname dw    vtkrname        ; pointer to selected macro name
  352. vtmaclen dw    vtkrlen
  353. udkseg    dw    18 dup (0)        ; segment of user definable key defs
  354.     even                ; screen rollback material
  355. iniseg    dw    ?            ; (BDT) initial seg of scroll memory
  356. ppl    dw    0            ; (BDT) paragraphs per line
  357. lcnt    dw    0            ; (BDT) number of "filled" buffer lines
  358. linef    dw    0            ; (BDT) "first" filled line is here
  359. linec    dw    0            ; (BDT) "current" screen line number
  360. linee    dw    0            ; (BDT) total # of lines in the buffer
  361. lmax    dw    0            ; (BDT) max lines in buff (less 1 scrn)
  362. lineems    dw    0            ; lines per EMS 16KB page frame
  363. xgatmp1    dw    0            ; XGA display adapter work word pair
  364. xgatmp2    dw    0
  365.  
  366. tsave    dw    6 dup (0)        ; list of term swap paragraphs
  367.  
  368.                     ; DG SPCL three stroke Compose key
  369. grab    dw    0            ; zero if not grabbing output
  370. grabbox    db    0,0            ; store incoming pair of bytes
  371. endif    ; no_terminal
  372.  
  373. setchtab db    10            ; Set File Character-Set table
  374.     mkeyw    'CP437',437        ; hardware default Code Page
  375.     mkeyw    'CP850',850        ; Multilingual CP
  376.     mkeyw    'CP852',852        ; Latin2 CP
  377.     mkeyw    'CP860',860        ; Portuguese CP
  378.     mkeyw    'CP861',861        ; Icelandic CP
  379.     mkeyw    'CP862',862        ; Hebrew CP
  380.     mkeyw    'CP863',863        ; French Canadian CP
  381.     mkeyw    'CP865',865        ; Norwegian CP
  382.     mkeyw    'CP866',866        ; Latin5/Cryillic CP
  383.     mkeyw    'Shift-JIS',932        ; Japanese Shift-JIS
  384.  
  385. ifdef    no_terminal
  386.                     ; begin Terminal emulator data set
  387. termtb    db    1            ; entries for Status, not Set
  388.     mkeyw    'none',ttgenrc
  389.  
  390. vttbl    db    0            ; number of entries
  391.  
  392. endif    ; no_terminal
  393. ifndef    no_terminal
  394.                     ; begin Terminal emulator data set
  395. ifndef    no_graphics
  396. termtb    db    tttypes            ; entries for Status, not Set
  397. else
  398. termtb    db    tttypes - 1
  399. endif
  400.     mkeyw    'VT320',ttvt320
  401.     mkeyw    'VT220',ttvt220
  402.     mkeyw    'VT102',ttvt102
  403.     mkeyw    'VT100',ttvt100
  404.     mkeyw    'VT52',ttvt52
  405.     mkeyw    'Honeywell VIP7809',tthoney
  406.     mkeyw    'Heath-19',ttheath
  407. ifndef    no_graphics
  408.     mkeyw    'Tek4010',tttek
  409. endif
  410.     mkeyw    'PT200',ttpt200
  411.     mkeyw    'D217',ttd217
  412.     mkeyw    'D463',ttd463
  413.     mkeyw    'D470',ttd470
  414.     mkeyw    'Wyse50',ttwyse
  415.     mkeyw    'Ansi-BBS',ttansi
  416.     mkeyw    'none',ttgenrc
  417.  
  418. ifndef    no_graphics
  419. vttbl    db    55            ; number of entries
  420. else
  421. vttbl    db    55 - 2
  422. endif    ; no_graphics
  423.     mkeyw    'Answerback',vtenqctl
  424.     mkeyw    'APC-macro',apcctl
  425.     mkeyw    'Arrow-keys',flg11
  426.     mkeyw    'Autodownload',vtdownld
  427.     mkeyw    'Character-set',vtchar
  428.     mkeyw    'Clock',vtclock
  429.     mkeyw    'Code-Page',vtcodepage
  430.     mkeyw    'Compressed-text',flg14
  431.     mkeyw    'Controls',flg9
  432.     mkeyw    'CR-display',vtcrdisp
  433.     mkeyw    'Cursor-style',flg7
  434.     mkeyw    'Direction',flg4
  435.     mkeyw    'Escape-character',termesc
  436.     mkeyw    'Expanded-memory',expmemory
  437.     mkeyw    'Horizontal-scroll',flg13
  438.     mkeyw    'Keyclick',flg5
  439.     mkeyw    'Keypad',flg10
  440.     mkeyw    'Margin-bell',flg6
  441.     mkeyw    'Newline',flg1
  442.     mkeyw    'Reset',termreset
  443.     mkeyw    'Screen-background',flg8
  444.     mkeyw    'Video-writing',scrwrite
  445.     mkeyw    'Video-change',scrchange
  446.     mkeyw    'Tabstops',tabmod
  447.     mkeyw    'Timeslice-release',vtcpu
  448.     mkeyw    'Width',flg12
  449.     mkeyw    'Wrap-lines',flg2
  450.  
  451.     mkeyw    'Bell',vtbeep
  452.     mkeyw    'Bytesize',vtbyte
  453.     mkeyw    'Clear-screen',vtcls
  454.     mkeyw    'Color',vtcolor
  455.     mkeyw    'Display',vtbyte    ; syn for set display 7/8
  456.     mkeyw    'Erase',vterase
  457. ifndef    no_graphics
  458.     mkeyw    'Graphics',vtgraph
  459.     mkeyw    'Tek4010',vttyp40
  460. endif    ; no_graphics
  461.     mkeyw    'Replay',replay
  462.     mkeyw    'Rollback',vtrollbk
  463.     mkeyw    'output-shift',vtshift
  464.     mkeyw    'Underscore',vtucolor
  465.     mkeyw    'UPSS',vtupss
  466.     mkeyw    'Type',vttype        ; SET TERM TYPE
  467.     mkeyw    'None',vttyp0
  468.     mkeyw    'Heath-19',vttyp1
  469.     mkeyw    'VT52',vttyp2
  470.     mkeyw    'VT100',vttyp4
  471.     mkeyw    'VT102',vttyp8
  472.     mkeyw    'VT220',vttyp10
  473.     mkeyw    'VT320',vttyp20
  474.     mkeyw    'Honeywell',vttyp80
  475.     mkeyw    'PT200',vttyp100
  476.     mkeyw    'D217',vttyp1000
  477.     mkeyw    'D463',vttyp200
  478.     mkeyw    'D470',vttyp400
  479.     mkeyw    'Wyse50',vttyp800
  480.     mkeyw    'ANSI',vttyp2000
  481.  
  482. ontab    db    2            ; two entries
  483.     mkeyw    'off',0
  484.     mkeyw    'on',1
  485.  
  486. beltab    db    3            ; bell type
  487.     mkeyw    'audible',0
  488.     mkeyw    'visual',1
  489.     mkeyw    'none',2
  490.  
  491. clktab    db    3
  492.     mkeyw    'Off',0
  493.     mkeyw    'On',1
  494.     mkeyw    'Elapsed-time',2
  495.  
  496. distab    db    2            ; display
  497.     mkeyw    '7-bit',0
  498.     mkeyw    '8-bit',d8bit
  499.  
  500. erasetb    db    2            ; erase
  501.     mkeyw    'normal-background',0
  502.     mkeyw    'current-color',1
  503.  
  504. scrtab    db    2            ; screen attributes
  505.     mkeyw    'normal',0
  506.     mkeyw    'reverse',1
  507.  
  508. dirtab    db    2            ; writing direction
  509.     mkeyw    'left-to-right',0
  510.     mkeyw    'right-to-left',1
  511.  
  512. writetab db    2            ; writing
  513.     mkeyw    'direct',0
  514.     mkeyw    'Bios',1
  515.  
  516. curtab    db    2            ; cursor attributes
  517.     mkeyw    'block',0
  518.     mkeyw    'underline',1
  519.  
  520. apctab    db    3            ; three entries
  521.     mkeyw    'off',0
  522.     mkeyw    'on',1
  523.     mkeyw    'unchecked',2
  524.      
  525. chatab    db    32            ; National Replacement Character sets
  526.     mkeyw    'ASCII',C_ASCII        ; ASCII is default (0, no NRC)
  527.     mkeyw    'British',C_UKNRC    ; start NRC set (1-12)
  528.     mkeyw    'Dutch',C_DUNRC
  529.     mkeyw    'Finnish',C_FINRC
  530.     mkeyw    'French',C_FRNRC
  531.     mkeyw    'Fr-Canadian',C_FCNRC
  532.     mkeyw    'German',C_DENRC
  533.     mkeyw    'Hebrew-7',C_DHEBNRC
  534.     mkeyw    'Italian',C_ITNRC
  535.     mkeyw    'Norwegian/Danish',C_NONRC
  536.     mkeyw    'Portuguese',C_PONRC
  537.     mkeyw    'Spanish',C_SPNRC
  538.     mkeyw    'Swedish',C_SENRC
  539.     mkeyw    'Swiss',C_CHNRC        ; end of NRC proper
  540.  
  541.     mkeyw    'Alternate-ROM',C_ALTROM ; Alternate-ROM character set
  542.     mkeyw    'Transparent',C_XPARENT    ; use native display adapter hardware
  543.     mkeyw    'Latin1',C_LATIN1    ; Latin-1 in GR
  544.     mkeyw    'Latin2',C_LATIN2    ; Latin-2 (will presume CP852)
  545.     mkeyw    'Hebrew-ISO',C_HEBREWISO ; Hebrew-ISO (presumes CP862)
  546.     mkeyw    'HP-Roman8',C_HPROMAN8    ; HP-Roman8
  547.     mkeyw    'DEC-MCS',C_DMULTINAT    ; DEC Supplemental Graphics in GR
  548.     mkeyw    'DEC-Technical',C_DECTECH
  549.     mkeyw    'DEC-Special',C_DECSPEC
  550.     mkeyw    'DG-International',C_DGINT
  551.     mkeyw    'DG-Line-Drawing',C_DGLINE
  552.     mkeyw    'DG-Word-Processing',C_DGWP
  553.     mkeyw    'JIS-Kanji',C_JISKANJI    ; [HF] JIS X 208, ISO(ECMA)#87
  554.     mkeyw    'JIS-Katakana',C_JISKAT    ; [HF] JIS X 201, ISO(ECMA)#13
  555.     mkeyw    'JIS-Roman',C_JISROM    ; [HF] JIS X 201, ISO(ECMA)#14
  556.     mkeyw    'Cyrillic-ISO',C_CYRILLIC_ISO
  557.     mkeyw    'KOI8',C_KOI8
  558.     mkeyw    'Short-KOI',C_SHORT_KOI
  559.  
  560. upsstab    db    4
  561.     mkeyw    'DEC-MCS','5%'            ; DEC Supplemental Graphics
  562.     mkeyw    'Latin1','A'            ; Latin-1
  563.     mkeyw    'Hebrew-7','4"'            ; DEC Hebrew-7
  564.     mkeyw    'Hebrew-ISO','H'        ; Hebrew-ISO
  565.  
  566. sidetab    db    4            ; SET TERM CHAR <char set> Gn
  567.     mkeyw    'G0','0'
  568.     mkeyw    'G1','1'
  569.     mkeyw    'G2','2'
  570.     mkeyw    'G3','3'
  571.  
  572. shifttab db    8            ; SET TERM OUTPUT-SHIFT
  573.     mkeyw    'none',0
  574.     mkeyw    'automatic',8
  575.     mkeyw    'SI/SO',1
  576.     mkeyw    'SS2',2
  577.     mkeyw    'SS3',4
  578.     mkeyw    'JIS7-Kanji',(128+1)        ; [HF]940211
  579.     mkeyw    'EUC-Kanji',(128+2)        ; [HF]940211
  580.     mkeyw    'DEC-Kanji',(128+3)        ; [HF]941012
  581.  
  582. jis7tab    db    6            ;[HF]941014
  583.     mkeyw    'JIS83-US','BB'        ;[HF]941014
  584.     mkeyw    'JIS83-Roman','JB'    ;[HF]941014
  585.     mkeyw    'JIS83-75Roman','HB'    ;[HF]941014
  586.     mkeyw    'JIS78-US','B@'        ;[HF]941014
  587.     mkeyw    'JIS78-Roman','J@'    ;[HF]941014
  588.     mkeyw    'JIS78-75Roman','H@'    ;[HF]941014
  589.  
  590. enqtab    db    5            ; set term enquire table
  591.     mkeyw    'off',0
  592.     mkeyw    'on',1
  593.     mkeyw    'message',2
  594.     mkeyw    'UNSAFE-MESSAGE',3
  595.     mkeyw    'UNSAFE-MESSAGE ',4    ; invisible to force spelled out
  596.  
  597. graftab    db    13
  598.     mkeyw    'auto-sensing',0    ; autosensing
  599.     mkeyw    'CGA',1
  600.     mkeyw    'EGA',2
  601.     mkeyw    'VGA',3
  602.     mkeyw    'VESA(800x600)',9
  603.     mkeyw    'Hercules',4
  604.     mkeyw    'ATT',5
  605.     mkeyw    'WyseA(1280x800)',6    ; Wyse-700 1280 x 800 mode
  606.     mkeyw    'WyseH(1280x780)',7    ; Wyse-700 1280 x 780 mode
  607.     mkeyw    'WyseT(1024x780)',8    ; Wyse-700 1024 x 780 mode
  608.     mkeyw    'character-writing',101h
  609.     mkeyw    'color',103h
  610.     mkeyw    'cursor',102h
  611.  
  612. gchrtab    db    2            ; set term graphics char-writing
  613.     mkeyw    'opaque',1
  614.     mkeyw    'transparent',0
  615.  
  616. disatab    db    2            ; Tek disable/enable table
  617.     mkeyw    'disabled',1        ; video-change table
  618.     mkeyw    'enabled',0
  619.  
  620. tabtab    db    2            ; label says it all!
  621.     mkeyw    'at',0FFH        ; For setting tab stops
  622.     mkeyw    'Clear',0        ; For clearing tab stops
  623.      
  624. alltab    db    2            ; more tab command decoding
  625.     mkeyw    'all',0
  626.     mkeyw    'at',1
  627.  
  628. cntltab    db    2            ; 8-bit controls
  629.     mkeyw    '7-bit',0
  630.     mkeyw    '8-bit',1
  631.  
  632. kpamtab    db    2            ; keypad, application
  633.     mkeyw    'numeric',0
  634.     mkeyw    'application',1
  635.  
  636. arrtab    db    2            ; cursor keys, application
  637.     mkeyw    'cursor',0
  638.     mkeyw    'application',1
  639.  
  640. widtab    db    2
  641.     mkeyw    '80-columns',0
  642.     mkeyw    '132-columns',1
  643.  
  644. vchgtab db    3            ; video-change
  645.     mkeyw    'enabled',0
  646.     mkeyw    'disabled',1
  647.     mkeyw    'DOS-only',2
  648.  
  649. hstab    db    2            ; horizontal scrolling
  650.     mkeyw    'auto',0
  651.     mkeyw    'manual',1
  652.  
  653. cmptab    db    2
  654.     mkeyw    'graphics',0
  655.     mkeyw    'text-132',1
  656.  
  657. emmtab    db    4
  658.     mkeyw    'off',0
  659.     mkeyw    'expanded',1
  660.     mkeyw    'extended',2
  661.     mkeyw    'on',3
  662.  
  663. termesctab db    2            ; SET TERM ESCAPE
  664.     mkeyw    'Enabled',0
  665.     mkeyw    'Disabled',1
  666.  
  667. crdisptab db    2
  668.     mkeyw    'normal',0
  669.     mkeyw    'CRLF',1
  670.  
  671. colortb    db    0,4,2,6,1,5,3,7        ; color reversed-bit setting bytes
  672. clrset    db    0            ; Temp for SET Term Tabstops xxx
  673.  
  674. erms41    db    cr,lf,'?More parameters are needed$'
  675. tbserr    db    cr,lf,'?Column number is not in range 1 to screen width-1$'
  676. colerr    db    cr,lf,'?Value not in range of 0, 1, 10, 30-37, or 40-47$'
  677. vtwrap    db    'Term wrap-lines: $'
  678. vtbellm    db    'Term margin-bell: $'
  679. vtnewln db    'Term newline: $'
  680. vtcur    db    'Term cursor-style: $'
  681. vtcset    db    'Term character-set: $'
  682. vtclik    db    'Term key-click: $'
  683. vtscrn    db    'Term screen-background: $'
  684. txtcolst1    db    'Term color (normal) f:3$'
  685. colst2    db    ' b:4$'
  686. colst3    db    ' rst:$'
  687. undcolst1    db    'Term underscore color f:3$'
  688. grcolst1    db    'Term graphics color   f:3$'
  689. vtgraf    db    'Term graphics: $'
  690. vtrolst    db    'Term rollback: $'
  691. vtdir    db    'Term direction: $'
  692. vtcntst    db    'Term controls: $'
  693. vtkpst    db    'Term keypad: $'
  694. vtarst    db    'Term arrow-keys: $'
  695. vtbset    db    'Term bell: $'
  696. vtgchst    db    'Term graph char: $'
  697. vtwdst    db    'Term width: $'
  698. vtupsst    db    'Term UPSS: $'
  699. vtshftst db    'Term output-shift: $'
  700. vthscst    db    'Term horizontal-scroll: $'
  701. vtapcst    db    'Term APC-macro: $'
  702. vtenqst db    'Term Answerback: $'
  703. vtenqst2 db    'ab msg: '
  704. vtenqst2_len equ $-vtenqst2
  705. vtwrtst    db    'Term video-writing: $'
  706. vtexpmst db    'Term expanded-memory: $'    
  707. vtcpagest db    'Term Code-Page: $'
  708. vtcmptst db    'Term compressed-text: $'
  709. vtchgst    db    'Term video-change: $'
  710. vtcpust    db    'Term timeslice-release: $'
  711. vtclrst    db    'Term erase: $'
  712. vtdnldst db    'Term autodownload: $'
  713. vtcrdispst db    'Term CR-display: $'
  714.                             ; terminal emulator
  715. vtstbl    stent    <srchkw,vtenqst,ontab,vtenqenable>        ; Answerback
  716.     stent    <ansbkstat>
  717.     stent    <srchkw,vtcset,chatab,vtemu.vtchset>        ; char set
  718.     stent    <srchkw,vtapcst,apctab,apcenable>        ; APC-macro
  719.     stent    <txtcolstat>                    ; colors
  720.     stent    <srchkb,vtclik,ontab,vskeyclick,vtemu.vtflgop>    ; keyclick
  721.     stent    <undcolstat>                    ; colors
  722.     stent    <srchkb,vtwrap,ontab,vswrap,vtemu.vtflgop>    ; line wrap
  723. ifndef    no_graphics
  724.     stent    <grcolstat>                    ; colors
  725. endif    ; no_graphics
  726.     stent    <srchkb,vtcntst,cntltab,vscntl,vtemu.vtflgop>    ; controls
  727.     stent    <srchkw,vtclrst,erasetb,vtclrflg>        ; erase
  728.     stent    <srchkb,vtbellm,ontab,vsmarginbell,vtemu.vtflgop>;margin bell
  729.     stent    <srchkb,vtcur,curtab,vscursor,vtemu.vtflgop>    ; cursor type
  730.     stent    <srchkw,vtbset,beltab,belltype>            ; bell
  731.     stent    <srchkb,vtdir,dirtab,vswdir,vtemu.vtflgop>    ; write direct
  732.     stent    <srchkb,vtnewln,ontab,vsnewline,vtemu.vtflgop>    ; newline
  733. ifndef    no_graphics
  734.     stent    <srchkw,vtgraf,graftab,tekgraf>            ; graphics
  735. endif    ; no_graphics
  736.     stent    <srchkw,vtrolst,ontab,vtroll>            ; rollback
  737. ifndef    no_graphics
  738.     stent    <srchkw,vtgchst,gchrtab,chcontrol>        ; chr cntrl
  739. endif    ; no_graphics
  740.     stent    <srchkb,vtarst,arrtab,decckm,vtemu.vtflgop>    ; arrow-keys
  741.     stent    <srchkb,vtscrn,scrtab,vsscreen,vtemu.vtflgop>    ; screen 
  742.     stent    <srchkb,vtkpst,kpamtab,deckpam,vtemu.vtflgop>    ; keypad
  743.     stent    <srchkb,vtwdst,widtab,deccol,vtemu.vtflgop>    ; width
  744.     stent    <srchkww,vtupsst,upsstab,upss+1>        ; UPSS
  745.     stent    <srchkw,vtshftst,shifttab,flags.oshift>        ; output-shift
  746.     stent    <srchkb,vthscst,hstab,vshscroll,vtemu.vtflgop>    ; Horz scroll
  747.     stent    <srchkw,vtchgst,vchgtab,vchgmode>        ; V change
  748.     stent    <srchkw,vtexpmst,emmtab,useexp>            ; exp mem
  749.     stent    <srchkw,vtwrtst,writetab,writemode>        ; Writing
  750.     stent    <srchkww,vtcpagest,setchtab,vtcpage>        ; Code-Page
  751.     stent    <srchkb,vtcmptst,cmptab,vscompress,vtemu.vtflgop> ; compress
  752.     stent    <srchkw,vtcpust,disatab,vtcpumode>        ; timeslice
  753.     stent    <srchkw,vtcrdispst,crdisptab,crdisp_mode>    ; CR-display
  754.     stent    <srchkw,vtdnldst,ontab,vtemu.vtdnld>        ; autodownload
  755.     stent    <tabstat>    ; VT320 tab status - needs one whole line
  756.     dw    0        ; end of table
  757.  
  758. vtmacroptr    dd    vtmacro            ; FAR pointer
  759. ftogmod        dd    togmod            ; FAR pointer
  760. termlatch    db    0        ; reentry block for session macros
  761. rcvstring    db    9,0,'RECEIVE',CR,'C'
  762. rcvstring_len    equ    $-rcvstring-2
  763. srvstring    db    5,0,'SER',CR,'C'
  764. srvstring_len    equ    $-srvstring-2
  765. endif    ; no_terminal
  766. data    ends
  767.  
  768. ifndef    no_terminal
  769. data1    segment
  770. vthlp    db    ' one of the following:',cr,lf
  771.     db    '  TYPE of: None, ANSI, Heath-19, Honeywell VIP7809, Wyse50,'
  772.     db    ' VT52, VT100, VT102'
  773.     db    cr,lf
  774.     db    '   VT220, VT320 (default), Tek4010,'
  775.     db     ' PT200 (Prime), D217, D463, D470 (Data Gen)'
  776.     db    cr,lf
  777.     db    '  Newline-mode    Cursor-style        Character-set'
  778.     db     cr,lf
  779.     db    '  Keyclick        Margin-bell         Screen-background'
  780.     db    ' (normal, reverse)',cr,lf
  781.     db '  Tabstops        Wrap (long lines)   Color (fore & background)'
  782.     db    cr,lf,'  Answerback response (on or off, default is off)'
  783.     db    cr,lf,'  APC-macro  (APC cmd from host invokes local cmds)' 
  784.     db    cr,lf,'  Autodownload (on, off=default) kermit file xfers'
  785.     db    cr,lf,'  Arrow-keys  cursor (normal) or application mode'
  786.     db    cr,lf,'  Bell  audible or visual or none'
  787.     db    cr,lf,'  Clear-screen  (clears old startup screen)'
  788.     db    cr,lf,'  Clock (status line HH:MM) on or off, default is off'
  789.     db    cr,lf,'  Code-Page (overrides default)'
  790.     db    cr,lf,'  Compressed-text  Graphics or Text-132 (for D463/D470)'
  791.     db    cr,lf,'  Controls 7-bit or 8-bit  (permits VT320 to send'
  792.     db    ' 8-bit control sequences (C1))'
  793.     db    cr,lf,'  CR-display  normal or CR-LF'
  794.     db    cr,lf,'  Direction Left-to-right or Right-to-left'
  795.     db    ' (screen writing direction)'
  796.     db    cr,lf,'  Display or Bytesize 7-bit or 8-bit'
  797.     db    cr,lf,'  Erase in normal bkground or in current char color'
  798.     db    cr,lf,'  Expanded/extended-memory (rollback), default on'
  799.     db    cr,lf,'  Graphics  (type of display adapter when in Tek4010'
  800.     db    ' mode, and char writing)'
  801.     db    cr,lf,'  Horizontal scrolling, auto (default) or manual'
  802.     db    cr,lf,'  Keypad numeric (normal) or application mode'
  803.     db    cr,lf,'  Output-shift (prefix 8-bit data for 7-bit channel)'
  804.     db    cr,lf,'  Reset, resets terminal emulation to startup defaults'
  805.     db    cr,lf,'  Rollback  (undo screen roll back before writing new'
  806.     db    ' chars, default=off)'
  807.     db    cr,lf,'  TEK ENABLE or DISABLE (activation by host command)'
  808.     db    cr,lf,'  Timeslice-release (OS/2, DV, Windows, def: enabled)'
  809.     db    cr,lf,'  Underscore Color (same syntax as SET TERM COLOR)'
  810.     db    cr,lf,'  Width 80 or 132 columns, if the adapter can do it'
  811.     db    cr,lf,'  Video-change, enable or disable 132 column switching'
  812.     db    ' or restrict to DOS-only'
  813.     db    cr,lf,'  Video-writing, Direct or via Bios$'
  814. clrhlp    db    ' one of the following:'
  815.     db    cr,lf,'  AT #s  (to set tabs at column #s)    or'
  816.     db    ' AT start-column:spacing'
  817.     db    cr,lf,'  Clear AT #s (clears individual tabs) or'
  818.     db    ' AT start-column:spacing'
  819.     db    cr,lf,'  Clear ALL  (to clear all tabstops)'
  820. clrhlp2    db    cr,lf,'  Ex: Set term tab at 10, 20, 34        sets tabs'
  821.     db    cr,lf,'  Ex: Set term tab at 1:8        sets tabs at 1, 9,'
  822.     db    cr,lf,'  Ex: Set term tab clear at 9, 17, 65   clears tabs'
  823.     db    cr,lf,'  Ex: Set term tab clear at 1:8  clears tabs at 1, 9,'
  824.     db    ' 17,...$'
  825. colhlp    db    cr,lf,'  Set Term Color  value, value, value, ...'
  826.     db    cr,lf,'   0 no-snow mode on an IBM CGA and white on black'
  827.     db    cr,lf,'   1 for high intensity foreground'
  828.     db    cr,lf,'  10 for fast CGA screen updating (may cause snow)'
  829.     db    cr,lf,'  20 to restore normal colors after ESC [ 0 m'
  830.     db    cr,lf,'  Foreground color (30-37) = 30 + sum of colors'
  831.     db    cr,lf,'  Background color (40-47) = 40 + sum of colors'
  832.     db    cr,lf,'    where colors are  1 = red, 2 = green, 4 = blue'
  833.     db    cr,lf,'  Ex: 0, 1, 37, 44   IBM CGA(0), bright(1) white(37)'
  834.     db    ' chars on a blue(44) field'
  835.     db    cr,lf,'  Attributes are applied in order of appearance.$'
  836. upsshlp    db    ' User Preferred Supplemental Set:'
  837.     db    cr,lf, 'DEC-MCS, Latin-1, Hebrew-7, Hebrew-ISO$'
  838. apchlp    db    cr,lf,'ON to allow APC cmd from host to invoke commands'
  839.     db    cr,lf,'OFF to prevent all use of APC from the host'
  840.     db    ' (default)'
  841.     db    cr,lf,'UNCHECKED to allow any command to be executed$'
  842. dnldhlp db    cr,lf,'ON to act upon incoming Kermit file transfer packets'
  843.     db    cr,lf,'OFF to prevent that action. Default is off$'
  844. enqhlp    db    cr,lf,' ON to permit Answerback to Control-E Enquire request'
  845.     db    ' (default is OFF),'
  846.     db    cr,lf,' MESSAGE text  to append local message to safe'
  847.     db    ' response prefix'
  848.     db    cr,lf,' UNSAFE-MESSAGE text  to send message as-is, without'
  849.     db    ' prefix$'
  850. enqhlp2    db    ' string to send$'
  851. expmhlp    db    cr,lf,' Use expanded or extended memory for screen rollback'
  852.     db    ' buffer,'
  853.     db    cr,lf,' OFF, EXPANDED, EXTENDED, or ON (try expanded first)$'
  854.  
  855. ; structures below: byte cnt of combos, dw input combo list, db output list
  856. ; using DG International or Latin1 codes for output.
  857. grl1dgi db    48            ; case and order insensitive
  858.     dw    '++','AA','((','//','/<','^ ','(-','/^',')-','<<'
  859.     dw    '0^','* ','+-','>>','SS','/U','2^','3^','C/','C|'
  860.     dw    'L-','L=','Y-','Y=','SO','S!','S0','XO','X0','A-'
  861.     dw    'CO','C0','PP','P!','.^','O-','12','!!','??','T-'
  862.     dw    'TM','FF','<=','>=',',-','""',2727h,'RO'
  863. grc1dgi db    '#', '@', '[', '\', '\', '^', '{', '|', '}', 0b1h
  864.     db    0bch,0bch,0b6h,0b0h,0fch,0a3h,0a4h,0a5h,0a7h,0a7h
  865.     db    0a8h,0a8h,0b5h,0b5h,0bbh,0bbh,0bbh,0a6h,0a6h,0a9h
  866.     db    0adh,0adh,0b2h,0b2h,0b9h,0aah,0a2h,0abh,0ach,0afh
  867.     db    0b3h,0b4h,0b7h,0b8h,0a1h,0bdh,0beh, 0aeh
  868.  
  869. grl1lat db    44            ; case and order insensitive
  870.     dw    '<<','0^','* ','+-','>>','SS','/U','2^','3^','C/'
  871.     dw    'C|','L-','L=','Y-','Y=','SO','S!','S0','XO','X0'
  872.     dw    'A-','CO','C0','PP','P!','.^','O-','12','!!','??'
  873.     dw    'TM',',-','""',2727h,'RO','||','--','-^',',,','34'
  874.     dw    'XX','-:','1^','14'
  875. grc1lat db    0abh,0b0h,0b0h,0b1h,0bbh,0dfh,0b5h,0b2h,0b3h,0a2h
  876.     db    0a2h,0a3h,0a3h,0a5h,0a5h,0a7h,0a7h,0a7h,0a4h,0a4h
  877.     db    0aah,0a9h,0a9h,0b6h,0b6h,0b7h,0bah,0bdh,0a1h,0bfh
  878.     db    0aeh,0ach,0a8h,0b4h, 0aeh,0a6h,0adh,0afh,0b8h,0beh
  879.     db    0d7h,0f7h,0b9h,0bch
  880.  
  881. grl2dgi    db    25            ; case sensitive, order insensitive
  882.     dw    '''A','`A','^A','"A','~A','*A','''E','`E','^E','"E'
  883.     dw    '''I','`I','^I','"I','~N','''O','`O','^O','"O','~O'
  884.     dw    '''U','`U','^U','"U','"Y'
  885. grc2dgi    db    0c0h, 0c1h,0c2h,0c3h,0c4h,0c5h,0c8h, 0c9h,0cah,0cbh
  886.     db    0cch, 0cdh,0ceh,0cfh,0d0h, 0d1h,0d2h,0d4h,0d6h,0d5h
  887.     db    0dah, 0d9h,0dbh,0dch,0ddh
  888.  
  889. grl2lat    db    25            ; case sensitive, order insensitive
  890.     dw    '''A','`A','^A','"A','~A','*A','''E','`E','^E','"E'
  891.     dw    '''I','`I','^I','"I','~N','''O','`O','^O','"O','~O'
  892.     dw    '''U','`U','^U','"U','''Y'
  893. grc2lat    db    0c1h, 0c0h,0c2h,0c4h,0c3h,0c5h,0c9h, 0c8h,0cah,0cbh
  894.     db    0cdh, 0cch,0ceh,0cfh,0d1h, 0d3h,0d2h,0d4h,0d6h,0d5h
  895.     db    0dah, 0d9h,0dbh,0dch,0ddh
  896.  
  897. grl3dgi db    7            ; case and order sensitive
  898.     dw    'EO','AE',',C','/O','ae',',c','/o'
  899. grc3dgi db    0d7h,0c6h,0c7h,0d6h,0e6h,0e7h,0f6h
  900.  
  901. grl3lat db    10+2            ; case and order sensitive
  902. ; The last two, OE/oe dipthong, are for DEC MCS but added here for user help
  903.     dw    'AE',',C','/O','HT','-D','ae',',c','/o','ht','-d'
  904.     dw    'OE','oe'
  905. grc3lat db    0c6h,0c7h,0d8h,0deh,0d0h,0e6h,0e7h,0f8h,0feh,0f0h
  906.     db    0d7h,0f7h
  907.  
  908.             ; CP852 Latin 2 codes in gr<l/c><1/2/3>lat2
  909. grl1lat2 db    24            ; case and order insensitive
  910.     db    '%%','::','--','==',"''",'&&',',,','##','xx','..'
  911.     db    '++','AA','aa','((','//','/<','))','(-','/^',')-'
  912.     db    '^^','``','~~','""'
  913. grc1lat2 db    0a2h,0a8h,0adh,0b2h,0b4h,0b7h,0b8h,0bdh,0d7h,0ffh
  914.     db    '#','@','@','[','\','\',']','{','|','}'
  915.     db    '^','`','~','"'
  916.  
  917. grl2lat2 db    83            ; case sensitive, order insensitive
  918.     db    'A=','L/','L&',"S'",'S&','S,','T&',"Z'",'Z&','Z.'
  919.     db    'a=','l/','l&',"s'",'s&','s,','t&',"z'",'z&','z.'
  920.     db       "R'","A'",'A^','A%','A"',"L'","C'",'C,','C&',"E'"
  921.     db    'E=','E"','E&',"I'",'I^','D&','D-',"N'",'N&',"O'"
  922.     db    'O^','O#','O"','R&','U*',"U'",'U#','U"',"Y'",'T,'
  923.     db    'ss',"r'","a'",'a^','a%','a"',"I'","c'",'c,','c&'
  924.     db    "e'",'e=','e"','e&',"i'",'i^','d&','d-',"n'",'n&'
  925.     db    "o'",'o^','o#','o"','r&','u*',"u'",'u#','u"',"y'"
  926.     db    't,',".'",',.'
  927. grc2lat2 db    0a1h,0a3h,0a5h,0a6h,0a9h,0aah,0abh,0ach,0aeh,0afh
  928.     db    0b1h,0b3h,0b5h,0b6h,0b9h,0bah,0bbh,0bbh,0beh,0bfh
  929.     db    0c0h,0c1h,0c2h,0c3h,0c4h,0c5h,0c6h,0c7h,0c8h,0c9h
  930.     db    0cah,0cah,0cch,0d8h,0d9h,0dah,0dbh,0dch,0ddh,0deh
  931.     db    0d4h,0d5h,0d6h,0fch,0deh,0e9h,0ebh,09ah,0edh,0ddh
  932.     db    0dfh,0e0h,0e1h,0e2h,0e3h,0e4h,0e5h,0e6h,0e7h,0e8h
  933.     db    0e9h,09ah,0ebh,0ech,0edh,0eeh,0efh,0f0h,0f1h,0f2h
  934.     db    0f3h,0f4h,0f5h,0f6h,0f8h,0f9h,0fah,0fbh,0fch,0fdh
  935.     db    0feh,"'", ','
  936.  
  937. grl3lat2 db    12            ; case and order sensitive
  938.     db    'XO','X0','xo','x0','SO','S!','S0','so','s!','s0'
  939.     db    '0^','-:'
  940. grc3lat2 db    0a4h,0a4h,0a4h,0a4h,0a7h,0a7h,0a7h,0a7h,0a7h,0a7h
  941.     db    0b0h,0f7h
  942.  
  943.  
  944. ;[HF] 941012 Double-byte katakana code table
  945. kanatbl    dw    2121h, 2123h, 2156h, 2157h, 2122h, 2126h, 2572h, 2521h    ;[HF]
  946.     dw    2523h, 2525h, 2527h, 2529h, 2563h, 2565h, 2567h, 2543h    ;[HF]
  947.     dw    213ch, 2522h, 2524h, 2526h, 2528h, 252ah, 252bh, 252dh    ;[HF]
  948.     dw    252fh, 2531h, 2533h, 2535h, 2537h, 2539h, 253bh, 253dh    ;[HF]
  949.     dw    253fh, 2541h, 2544h, 2546h, 2548h, 254ah, 254bh, 254ch    ;[HF]
  950.     dw    254dh, 254eh, 254fh, 2552h, 2555h, 2558h, 255bh, 255eh    ;[HF]
  951.     dw    255fh, 2560h, 2561h, 2562h, 2564h, 2566h, 2568h, 2569h    ;[HF]
  952.     dw    256ah, 256bh, 256ch, 256dh, 256fh, 2573h, 212bh, 212ch    ;[HF]
  953.  
  954. data1    ends
  955.                         ; end of Terminal data set
  956. code1    segment
  957.     extrn    ans52t:far, vsinit:near        ; in mszibm
  958.     extrn    anstty:near, ansini:near, ansrei:near    ; in mszibm
  959.     extrn    anskbi:near, ansdsl:near, chrdef:near    ; in mszibm
  960.     extrn    tabset:near, tabclr:near, dgnctoggle:far
  961.     extrn    toupr:far, domath:far, cboff:far, cbrestore:far
  962.  
  963.     assume    cs:code1
  964. fanskbi    proc    far
  965.     call    anskbi                ; in mszibm
  966.     ret
  967. fanskbi    endp
  968. ftabset    proc    far
  969.     call    tabset                ; in mszibm
  970.     ret
  971. ftabset    endp
  972. ftabclr    proc    far
  973.     call    tabclr                ; in mszibm
  974.     ret
  975. ftabclr    endp
  976. fchrdef    proc    far
  977.     call    chrdef
  978.     ret
  979. fchrdef    endp
  980. code1    ends
  981. endif    ; no_terminal
  982.  
  983. ifndef    no_graphics
  984. code2    segment
  985.     extrn   tekini:far, tekemu:far, tekend:far, tekrint:far ;in msgibm
  986.     extrn    ttxtchr:far, teksetcursor:far, tekremcursor:far
  987.     extrn    croshair:far, dgcrossrpt:far
  988. code2    ends
  989. endif    ; no_graphics
  990.  
  991. ifndef    no_tcp
  992. _TEXT    segment
  993.     extrn    ktcpcom:far
  994. _TEXT    ends
  995.  
  996. _DATA    segment
  997. commbyte db    0            ; byte from msyibm to 3270 emulator
  998. _DATA    ends
  999. endif    ; no_tcp
  1000.  
  1001. code1    segment
  1002.     extrn    strlen:far, strcpy:far, strcat:far, isfile:far
  1003.     extrn    dec2di:far
  1004.     assume    cs:code1
  1005. code1    ends
  1006.  
  1007. code    segment
  1008.     extrn    prtchr:near, outchr:near, pcwait:far
  1009.     extrn    clrmod:near, putmod:near, cmblnk:near, cptchr:near
  1010.     extrn    telnet:near, srchkww:near, jpnftox:near
  1011.     extrn    srchkb:near, srchkw:near, pasz:near
  1012.     extrn    prompt:near, comnd:near, statc:near, replay:near
  1013.     extrn    crun:near, serini:near, spath:near
  1014.     extrn    prttab:near, ctlu:near
  1015.     extrn    pntchr:near, pntflsh:near, serrst:near
  1016. ifndef    no_graphics
  1017.     extrn    tekgcptr:near, tekdmp:near
  1018. endif    ; no_graphics
  1019. ifndef    no_network
  1020.     extrn    ubclose:near
  1021. endif    ; no_network
  1022. ifndef    no_tcp
  1023.     extrn    tcpstart:near, winupdate:far
  1024. endif    ; no_tcp
  1025. ifndef    no_terminal
  1026.     extrn    takopen_macro:far
  1027.     extrn    msuinit:near, keybd:near, kbhold:near    ; in msuibm
  1028. endif    ; no_terminal
  1029.  
  1030.     assume    cs:code, ds:data, es:nothing
  1031.  
  1032. ifdef    no_terminal
  1033. ; do initialization local to this module
  1034. ; Dynamically allocates 4000 bytes for screen save/restore buffer plus
  1035. ;  320 to 38400 bytes for screen scroll back buffers. Tries to leave space
  1036. ;  for Command.com before enlarging buffers.
  1037. lclyini    proc    near
  1038.     call    far ptr flclyini    ; far call specifics
  1039.     ret
  1040. lclyini    endp
  1041.                     ; begin Terminal set & status code
  1042. ; SET Term parameters, especially for use with VT100 emulator.
  1043. ; VTS is called only by mssset to set terminal type and characteristics.
  1044. ; Exit carry set for failure.
  1045. VTS    proc    near            ; SET TERM whatever
  1046.     mov    ah,cmeol        ; Clear-screen
  1047.     call    comnd
  1048.     ret
  1049. VTS    endp                ; end of Set Term things
  1050.  
  1051.           ; Terminal Status display, called within STAT0: in MSSSET
  1052. VTSTAT    proc    near            ; enter with di within sttbuf, save bx
  1053.     jmp    statc            ; status common code, in mssset
  1054. vtstat    endp
  1055.  
  1056. trnmod    proc    near
  1057.     ret
  1058. trnmod    endp
  1059.                        ; Screen dump entry from keyboad xlat
  1060. dmpscn    proc    near            ; dump screen to file
  1061.     stc
  1062.     ret
  1063. dmpscn    endp
  1064.  
  1065. endif    ; no_terminal
  1066.  
  1067. ifndef    no_terminal
  1068.  
  1069. ; do initialization local to this module
  1070. ; Dynamically allocates 4000 bytes for screen save/restore buffer plus
  1071. ;  320 to 38400 bytes for screen scroll back buffers. Tries to leave space
  1072. ;  for Command.com before enlarging buffers.
  1073. lclyini    proc    near
  1074.     call    msuinit            ; initialize keyboard module msuxxx
  1075.     call    far ptr flclyini    ; far call specifics
  1076.     ret
  1077. lclyini    endp
  1078.  
  1079.                     ; begin Terminal set & status code
  1080. ; SET Term parameters, especially for use with VT100 emulator.
  1081. ; VTS is called only by mssset to set terminal type and characteristics.
  1082. ; Exit carry set for failure.
  1083. VTS    proc    near            ; SET TERM whatever
  1084.     mov    kstatus,kssuc        ; success
  1085.     mov    ah,cmkey        ; Parse another keyword
  1086.     mov    bx,offset vthlp        ; Use this help
  1087.     mov    dx,offset vttbl        ; Use this table
  1088.     call    comnd
  1089.     jnc    vset1            ; nc = success
  1090.     ret                ; failure
  1091. vset1:    call    bx            ; dispatch to processing routine
  1092.     ret
  1093.  
  1094. vtcls:    mov    ah,cmeol        ; Clear-screen
  1095.     call    comnd
  1096.     jc    vtclsx            ; c = failure
  1097.     mov    vtclear,2        ; set trigger for emulator clear scn
  1098.     clc                ; success
  1099. vtclsx:    ret
  1100.  
  1101. vtclock:mov    ah,cmkey        ; SET TERM CLOCK {ON | OFF | ELAPSED}
  1102.     xor    bx,bx
  1103.     mov    dx,offset clktab
  1104.     call    comnd
  1105.     jnc    vtclo1
  1106.     ret
  1107. vtclo1:    mov    vtclkflg,bl        ; status line clock flag
  1108.     ret
  1109.  
  1110. vterase:mov    ah,cmkey        ; SET TERM ERASE
  1111.     xor    bx,bx            ; table is help
  1112.     mov    dx,offset erasetb    ; use this table
  1113.     call    comnd
  1114.     jc    vterasex        ; c = failure
  1115.     mov    vtclrflg,bl
  1116. vterasex:ret
  1117.                     ; SET TERM kind
  1118. vttyp0:    mov    bx,ttgenrc        ; NONE
  1119.     jmp    vsett1
  1120. vttyp1:    mov    bx,ttheath        ; Heath-19
  1121.     jmp    vsett1
  1122. vttyp2:    mov    bx,ttvt52        ; VT52
  1123.     jmp    vsett1
  1124. vttyp4:    mov    bx,ttvt100        ; VT100
  1125.     jmp    vsett1
  1126. vttyp8:    mov    bx,ttvt102        ; VT102
  1127.     jmp    vsett1
  1128. vttyp10:mov    bx,ttvt220        ; VT220
  1129.     jmp    vsett1
  1130. vttyp20:mov    bx,ttvt320        ; VT320
  1131.     jmp    vsett1
  1132. vttyp40:mov    bx,tttek        ; Tek
  1133.     jmp    vsett1
  1134. vttyp80:mov    bx,tthoney        ; Honeywell VIP7809
  1135.     jmp    vsett1
  1136. vttyp100:mov    bx,ttpt200        ; Prime PT200
  1137.     jmp    short vsett1
  1138. vttyp200:mov    bx,ttd463        ; Data General D463
  1139.     jmp    short vsett1
  1140. vttyp400:mov    bx,ttd470        ; Data General D470
  1141.     jmp    short vsett1
  1142. vttyp800:mov    bx,ttwyse        ; Wyse-50
  1143.     jmp    short vsett1
  1144. vttyp1000:mov    bx,ttd217        ; Data General D217
  1145.     jmp    short vsett1
  1146. vttyp2000:mov    bx,ttansi        ; Ansi-BBS
  1147.     call    ansi_save        ; save settings
  1148.     jmp    short vsett1
  1149.     
  1150. vttype:    mov    ah,cmkey        ; SET TERM TYPE
  1151.     xor    bx,bx            ; table is help
  1152.     mov    dx,offset termtb    ; use this table
  1153.     call    comnd
  1154.     jnc    vsett1            ; nc = success
  1155.     ret                ; failure
  1156.  
  1157. vsett1:    mov    temp,bx            ; save terminal type
  1158.     mov    vtemu.vtchop,-1        ; say reinit char tables
  1159.     mov    temp2,-1        ; assume no enable/disable Tek
  1160.     cmp    bx,ttansi        ; going to be ANSI?
  1161.     je    vsett1a            ; e = yes
  1162.     cmp    vtsave,0        ; VT save area in use?
  1163.     je    vsett1a            ; e = no
  1164.     mov    ax,word ptr vtsave+1    ; get saved video and char set
  1165.     mov    vtemu.vtchset,al    ; restore current char set
  1166.     mov    si,vtemu.att_ptr    ; pointer to attributes
  1167.     mov    [si],ah            ; restore current screen coloring
  1168.     mov    ax,word ptr vtsave+3
  1169.     mov    reset_color,al        ; this too
  1170.     mov    savattr,ah
  1171.     mov    ax,word ptr vtsave+5
  1172.     mov    vtcpage,ax        ; restore terminal Code Page
  1173.     mov    vtclear,1        ; signal color change
  1174.     mov    vtsave,0        ; save area is free
  1175. vsett1a:cmp    bx,tttek        ; set term tek?
  1176.     jne    vsett2            ; ne = no
  1177.     mov    dx,offset disatab    ; disable/enable keyword table
  1178.     xor    bx,bx            ; help is the table
  1179.     mov    comand.cmcr,1        ; allow bare CR's
  1180.         mov    ah,cmkey        ; get enable/disable keyword
  1181.     call    comnd
  1182.     mov    comand.cmcr,0        ; no more bare CR's
  1183.     jc    vsett2            ; c = no such keyword
  1184. ifndef    no_graphics
  1185.     mov    temp2,bx        ; save enable/disable keyword value
  1186.     mov    bx,flags.vtflg        ; get current terminal type
  1187.     mov    temp,bx            ; and force it here
  1188. endif    ; no_graphics
  1189.  
  1190. vsett2:    mov    ah,cmeol
  1191.     call    comnd            ; get a confirm
  1192.     jc    vsettx            ; c = failure
  1193. vsett3:    mov    bx,temp
  1194.     mov    flags.vtflg,bx        ; Set the terminal emulation type
  1195.     call    ansi_save        ; save if going to ANSI
  1196.     mov    tekflg,0        ; clear graphics mode
  1197.     or    vtemu.vtflgst,vscompress+vshscroll ; set compress to text-132
  1198.     or    vtemu.vtflgop,vscompress+vshscroll
  1199.                     ; and horz scroll to manual
  1200.     cmp    bx,tttek        ; adjusting Tek?
  1201.     je    vsett4            ; e = yes
  1202.     test    bx,ttd463+ttd470+ttd217    ; DG D463/470/217?
  1203.     jz    vsett6            ; z = no
  1204.     and    vtemu.vtflgst,not (vshscroll) ; comp = graphics,
  1205.     and    vtemu.vtflgop,not (vshscroll) ; horz scroll = auto
  1206. vsett6:    cmp    temp2,-1        ; just enable/disable tek?
  1207.     je    vsett5            ; e = no
  1208. vsett4:
  1209. ifndef    no_graphics
  1210.     and    denyflg,not tekxflg    ; enable Tek
  1211.     cmp    temp2,1            ; ought we disable?
  1212.     jne    vsett5            ; ne = no
  1213. endif    ; no_graphics
  1214.     or    denyflg,tekxflg        ; disable Tek
  1215. vsett5:    call    fchrdef            ; make tables in mszibm.asm
  1216.     clc                ; success
  1217. vsettx:    ret
  1218.  
  1219. ; save coloring and character set around ANSI terminal type, worker
  1220. ansi_save proc    near
  1221.     cmp    flags.vtflg,ttansi    ; are we ANSI now?
  1222.     jne    ansi_savex        ; ne = no
  1223.     cmp    vtsave,0        ; save area in use?
  1224.     jne    ansi_savex        ; ne = yes
  1225.     mov    vtsave,1        ; state that save area is in use
  1226.     mov    al,vtemu.vtchset    ; get current char set
  1227.     mov    si,vtemu.att_ptr    ; pointer to attributes
  1228.     mov    ah,[si]            ; get current screen coloring
  1229.     mov    word ptr vtsave+1,ax    ; save them
  1230.     mov    al,reset_color        ; this too
  1231.     mov    ah,savattr
  1232.     mov    word ptr vtsave+3,ax
  1233.     mov    ax,437            ; forced codepage is 437
  1234.     xchg    ax,vtcpage        ; get old CP
  1235.     mov    word ptr vtsave+5,ax    ; save old CP
  1236.     mov    reset_color,1        ; reset colors with CSI m
  1237.     mov    byte ptr [si],07h    ; dim white on black
  1238.     mov    savattr,07h
  1239.     mov    vtclear,1        ; signal color change
  1240.     mov    vtemu.vtchset,15    ; Transparent char set
  1241.     or    flags.remflg,d8bit    ; set 8-bit display
  1242. ansi_savex:
  1243.     ret
  1244. ansi_save endp
  1245.  
  1246. vtchar: mov    ah,cmkey        ; Set Term character set
  1247.     xor    bx,bx            ; character set table for help 
  1248.     mov    temp,bx            ; counter of trailing items
  1249.     mov    dx,offset chatab    ; character set table
  1250.     call    comnd
  1251.     jc    vtcharx            ; c = failure
  1252.     call    chkcp866        ; check on CP866 requirements
  1253.     mov    decbuf,bl        ; save here
  1254.     mov    ax,word ptr vtemu.vttable ; table of 4 overrides now
  1255.     mov    word ptr decbuf+1,ax    ; copy them to temporary table
  1256.     mov    ax,word ptr vtemu.vttable+2
  1257.     mov    word ptr decbuf+3,ax
  1258. vtchar1:mov    comand.cmcr,1        ; allow bare CR's
  1259.     mov    ah,cmkey
  1260.     xor    bx,bx
  1261.     mov    dx,offset sidetab    ; read Gnumber item, if any
  1262.     call    comnd
  1263.     mov    comand.cmcr,0        ; no bare CR's
  1264.     jc    vtchar2            ; c = no match, get confirm
  1265.     inc    temp            ; say have a trailing table number
  1266.     and    bx,3            ; remove ASCII value encoding
  1267.     add    bx,offset decbuf+1    ; address of slot to store info
  1268.     mov    al,decbuf        ; set ident
  1269.     mov    [bx],al            ; store table ident in G0..G3 slot
  1270.     jmp    short vtchar1        ; repeat
  1271.  
  1272. ; vtemu.vtchset:    changed to new set if no table trailers, else intact
  1273. ; vtemu.vttable    db 4 dup(0ffh)     char set numbers for G0..G3 as overrides,
  1274. ;                use 0ffh to mean no override for table Gn
  1275. vtchar2:mov    ah,cmeol        ; get EOL confirmation
  1276.     call    comnd
  1277.     jc    vtcharx            ; c = failure, quit
  1278.     mov    vtemu.vtchop,-1        ; say reinit char tables
  1279.     cmp    temp,0            ; trailers (skip regular setup)?
  1280.     jne    vtchar3            ; ne = yes
  1281.     mov    al,decbuf        ; get character set
  1282.     mov    vtemu.vtchset,al    ; set default character set
  1283.     clc
  1284.     ret
  1285.                     ; just overrides
  1286. vtchar3:mov    ax,word ptr decbuf+1    ; first pair of char set idents
  1287.     mov    word ptr vtemu.vttable,ax
  1288.     mov    ax,word ptr decbuf+3    ; second pair
  1289.     mov    word ptr vtemu.vttable+2,ax
  1290.     clc
  1291. vtcharx:ret
  1292.  
  1293. vtshift:mov    ah,cmkey        ; Set Term Output-shift auto, none
  1294.     xor    bx,bx
  1295.     mov    dx,offset shifttab
  1296.     call    comnd
  1297.     jc    vtshifx            ;[HF] c = failed
  1298.     cmp    bl,(128+1)        ;[HF] JIS7-Kanji ?
  1299.     jne    vtshif3            ;[HF] ne = no
  1300.     mov    temp2,bx        ; save shift from above
  1301.     mov    temp,'BB'        ;[HF] set default
  1302.     mov    comand.cmcr,1        ;[HF] allow bare CR
  1303.     mov    ah,cmkey        ;[HF] get Roman/ASCII set
  1304.     xor    bx,bx            ;[HF]
  1305.     mov    dx,offset jis7tab    ;[HF]
  1306.     call    comnd            ;[HF]
  1307.     jc    vtshif2            ;[HF] get confirm
  1308.     mov    temp,bx            ;[HF] set value
  1309. vtshif2:mov    ah,cmeol        ;[HF] get confirm
  1310.     call    comnd            ;[HF]
  1311.     jc    vtshifx            ;[HF]
  1312.     mov    bx,temp            ;[HF] restore value
  1313.     mov    word ptr jis7des,bx    ;[HF] set it
  1314.     mov    bx,temp2        ; initial shift
  1315.     mov    flags.oshift,bl        ; shift
  1316.     clc                ;[HF]
  1317.     ret
  1318. vtshif3:push    bx
  1319.     mov    ah,cmeol
  1320.     call    comnd
  1321.     pop    bx
  1322.     jc    vtshifx
  1323.     mov    flags.oshift,bl        ; shift
  1324.     clc
  1325. vtshifx:ret
  1326.  
  1327. vtrollbk:mov    ah,cmkey        ; Set Term Roll On/Off, auto roll back
  1328.     xor    bx,bx            ; Use on/off table as help
  1329.     mov    dx,offset ontab        ; Use on/off table
  1330.     call    comnd
  1331.     jc    vtrollx            ; c = failure
  1332.     push    bx
  1333.     mov    ah,cmeol        ; get a confirm
  1334.     call    comnd
  1335.     pop    bx
  1336.     jc    vtrollx            ; c = failure
  1337.     mov    vtroll,bl        ; set roll state (0=no auto rollback)
  1338.     clc
  1339. vtrollx:ret
  1340.  
  1341.                      ; Set Term Color foreground, background
  1342. vtcolor:mov    bx,vtemu.att_ptr    ; get address of attributes byte
  1343.     mov    bl,[bx]            ; get attributes
  1344.     mov    decbuf,bl        ; save in work temp
  1345.     mov    al,vtclear        ; screen clear state
  1346.     mov    ah,refresh        ; refresh state
  1347.     mov    word ptr decbuf+1,ax    ; save here
  1348.     mov    al,reset_color        ; reset color state
  1349.     mov    decbuf+3,al
  1350.     call    vsetcol            ; get and analyze colors
  1351.     jc    vtcolo1            ; c = failure
  1352.     mov    al,decbuf        ; get current attributes
  1353.     mov    bx,vtemu.att_ptr    ; get address of attributes byte
  1354.     mov    [bx],al            ; store attributes
  1355.     mov    savattr,al        ; saved emulator attributes
  1356.  
  1357.     and    al,att_bold        ; pick up userbold preference
  1358.     mov    userbold,al
  1359.  
  1360.     mov    ax,word ptr decbuf+1
  1361.     mov    vtclear,al        ; update these items
  1362.     mov    refresh,ah
  1363.     mov    al,decbuf+3
  1364.     mov    reset_color,al        ; reset color state
  1365.     clc
  1366. vtcolo1:ret
  1367.                     ; setup color information
  1368. vsetcol:mov    ah,cmword        ; get number(s) after set term color
  1369.     mov    dx,offset colhlp    ; use this help
  1370.     mov    bx,offset rdbuf        ; temp buffer
  1371.     mov    comand.cmcr,1        ; allow bare c/r's
  1372.     mov    comand.cmcomma,1    ; commas are equivalent to spaces
  1373.     call    comnd
  1374.     jc    vsetco2            ; c = failure
  1375.     or    ax,ax            ; text given?
  1376.     jz    vsetco1            ; z = no
  1377.     mov    si,offset rdbuf        ; si = string
  1378.     call    vsetco3            ; analyze
  1379.     jmp    short vsetcol        ; get more data
  1380. vsetco1:mov    ah,cmeol        ; get end of line confirm
  1381.     call    comnd
  1382. vsetco2:ret                ; c set if failure
  1383.  
  1384. vsetco3:mov    dx,si
  1385.     call    strlen            ; get string count
  1386.     mov    domath_ptr,si
  1387.     mov    domath_cnt,cx
  1388.     call    domath
  1389.     mov    si,domath_ptr        ; where to read next string byte
  1390.     cmp    domath_cnt,0
  1391.     jne    vsetco1            ; ne = did not convert whole string
  1392.     or    ax,ax            ; reset all? regular IBM CGA refresh
  1393.     jnz    vsetco4            ; nz = no
  1394.     mov    word ptr decbuf+2,0    ; slow screen refresh, no reset color
  1395.     mov    decbuf,07h        ; clear all, set white on black
  1396.     mov    decbuf+1,2        ; set trigger for emulator clear scrn
  1397.     jmp    short vsetcol
  1398.  
  1399. vsetco4:cmp    ax,1            ; high intensity?
  1400.     jne    vsetco5            ; e = no
  1401.     or    decbuf,08h        ; set high intensity
  1402.     mov    decbuf+1,1        ; set trigger for emulator keep screen
  1403.     jmp    short vsetcol
  1404.  
  1405. vsetco5:cmp    ax,10            ; fast refresh?
  1406.     jne    vsetco5a        ; ne = no
  1407.     mov    decbuf+2,1        ; Fast screen refresh
  1408.     jmp    short vsetcol
  1409.  
  1410. vsetco5a:cmp    ax,20            ; reset color upon CSI m?
  1411.     jne    vsetco6            ; ne = no
  1412.     mov    decbuf+3,1        ; reset color state is yes
  1413.     jmp    vsetcol
  1414.  
  1415. vsetco6:cmp    ax,30            ; check range
  1416.     jb    vsetco8            ; b = too small, complain
  1417.     cmp    ax,37
  1418.     ja    vsetco7            ; 30-37 is foreground color
  1419.     sub    al,30            ; remove foreground bias
  1420.     and    decbuf,not 07H        ; clear foreground bits
  1421.     mov    bx,ax
  1422.     mov    al,colortb[bx]        ; get reversed bit pattern
  1423.     or    decbuf,al        ; load new bits
  1424.     mov    decbuf+1,2        ; set trigger for emulator clear scn
  1425.     jmp    vsetcol
  1426.  
  1427. vsetco7:cmp    ax,40
  1428.     jb    vsetco8            ; b = bad value
  1429.     cmp    ax,47            ; compare as unsigned
  1430.     ja    vsetco8            ; 40-47 is background
  1431.     sub    al,40            ; remove background bias
  1432.     and    decbuf,not 70H        ; clear background bits
  1433.     mov    bx,ax
  1434.     mov    al,colortb[bx]        ; get reversed bit pattern
  1435.     mov    cl,4            ; rotate 4 positions
  1436.     rol    al,cl
  1437.     or    decbuf,al        ; load new bits
  1438.     mov    decbuf+1,2        ; set trigger for emulator clear scn
  1439.     jmp    vsetcol
  1440.  
  1441. vsetco8:mov    ah,prstr        ; not in range - complain and exit
  1442.     mov    dx,offset colerr
  1443.     int    dos
  1444.     mov    kstatus,ksgen        ; general failure
  1445.     stc                ; error
  1446.     ret
  1447.          
  1448. vtucolor:mov    al,vtclear        ; screen clear state
  1449.     mov    ah,refresh        ; refresh state
  1450.     mov    word ptr decbuf+1,ax    ; save here
  1451.     mov    al,scbattr
  1452.     mov    decbuf,al
  1453.     call    vsetcol            ; get and analyze colors
  1454.     jc    vtucol1            ; c = failure
  1455.     mov    al,decbuf        ; get current attributes
  1456.     mov    colunder,al        ; saved underlined color
  1457.     mov    ax,word ptr decbuf+1
  1458.     mov    vtclear,al        ; update these items
  1459.     mov    refresh,ah
  1460.     clc
  1461. vtucol1:ret
  1462.  
  1463. ifndef    no_graphics
  1464. vtgraph:mov    ah,cmkey        ; Set Term graphics
  1465.     xor    bx,bx            ; Use graphics table as help
  1466.     mov    dx,offset graftab    ; Use graphics table
  1467.     call    comnd
  1468.     jc    vtgrapx            ; c = failure
  1469.     cmp    bx,100h            ; in the special options area?
  1470.     ja    vtgrap1            ; a = yes
  1471.     push    bx
  1472.     mov    ah,cmeol        ; get a confirm
  1473.     call    comnd
  1474.     pop    bx
  1475.     jc    vtgrapx            ; c = failure
  1476.     mov    tekgraf,bl        ; set Tek graphics board type
  1477.     clc
  1478. vtgrapx:ret
  1479. vtgrap1:cmp    bx,101h            ; character writing?
  1480.     jne    vtgrap2            ; ne = no
  1481.     mov    ah,cmkey        ; Set Term graphics char-writing
  1482.     xor    bx,bx            ; no help
  1483.     mov    dx,offset gchrtab    ; opaque/transparent table
  1484.     call    comnd
  1485.     jc    vtgrapx            ; c = failure
  1486.     push    bx
  1487.     mov    ah,cmeol        ; get a confirm
  1488.     call    comnd
  1489.     pop    bx
  1490.     jc    vtgrapx
  1491.     mov    chcontrol,bl        ; set/reset opaque char control
  1492.     clc
  1493.     ret
  1494. vtgrap2:cmp    bx,102h            ; cursor on/off?
  1495.     jne    vtgrap4            ; ne = no
  1496.     mov    ah,cmkey        ; Set Term graphics cursor on/off
  1497.     xor    bx,bx            ; no help
  1498.     mov    dx,offset ontab        ; on/off table
  1499.     call    comnd
  1500.     jc    vtgrapx            ; c = failure
  1501.     push    bx
  1502.     mov    ah,cmeol        ; get a confirm
  1503.     call    comnd
  1504.     pop    bx
  1505.     jc    vtgrapx
  1506.     mov    tekcursor,bl        ; set Tek text cursor on/off
  1507.     clc
  1508.     ret
  1509.  
  1510. vtgrap4:cmp    bx,103h            ; Color?
  1511.     jne    vtgrap6            ; ne = no
  1512.     call    tekgcptr        ; get pointer to active Tek color pal
  1513.     mov    al,[bx]            ; get background attributes
  1514.     and    al,7            ; discard intensity bit
  1515.     mov    cl,4
  1516.     shl    al,cl
  1517.     mov    ah,[bx+7]        ; get foreground attributes
  1518.     or    al,ah
  1519.     mov    decbuf,al        ; setup work temp for vsetcol
  1520.     push    bx            ; save index
  1521.     call    vsetcol            ; get and analyze colors
  1522.     pop    bx
  1523.     jnc    vtgrap5            ; nc = ok
  1524.     ret
  1525. vtgrap5:mov    al,decbuf        ; get current attributes
  1526.     mov    ah,al            ; get background bits
  1527.     mov    cl,4
  1528.     shr    ah,cl            ; just background here
  1529.     and    al,0fh            ; just foreground here
  1530.     mov    [bx],ah            ; store colpal[0] as background
  1531.     mov    [bx+7],al        ; store colpal[7] as foreground
  1532.     clc                ; success
  1533. vtgrap6:ret
  1534. endif    ; no_graphics
  1535.     
  1536. vtbeep:    mov    ah,cmkey        ; SET TERM BELL
  1537.     xor    bx,bx            ; use table as help
  1538.     mov    dx,offset beltab    ; use Bell table
  1539.     call    comnd
  1540.     jc    vtbeepx            ; c = failure
  1541.     push    bx
  1542.     mov    ah,cmeol        ; get a confirm
  1543.     call    comnd
  1544.     pop    bx
  1545.     jc    vtbeepx            ; c = failure
  1546.     mov    belltype,bl        ; set bell type
  1547. vtbeepx:ret                ; return carry clear or set
  1548.  
  1549.                     ; SET TERM BYTESIZE {7-bit | 8-bit}
  1550. vtbyte:    mov    ah,cmkey        ; SET TERM DISPLAY {7-bit | 8-bit}
  1551.     mov    dx,offset distab    ; table
  1552.     xor    bx,bx            ; help is table
  1553.     call    comnd
  1554.     jc    vtbytex            ; c = failure
  1555.     push    bx
  1556.     mov    ah,cmeol        ; get a confirm
  1557.     call    comnd
  1558.     pop    bx
  1559.     jc    vtbytex            ; c = failure
  1560.     and    flags.remflg,not d8bit    ; clear display 8-bit bit
  1561.     or    flags.remflg,bl        ; set or clear the bit
  1562. vtbytex:ret
  1563.  
  1564. vtupss:    mov    ah,cmkey        ; SET TERM UPSS
  1565.     mov    bx,offset upsshlp    ; help
  1566.     mov    dx,offset upsstab    ; UPSS table
  1567.     call    comnd            ; get UPSS char set
  1568.     jc    vtupssx            ; failure
  1569.     push    bx
  1570.     mov    ah,cmeol
  1571.     call    comnd
  1572.     pop    bx
  1573.     jc    vtupssx            ; c = fail
  1574.     mov    al,96            ; assume 96 byte set
  1575.     or    bh,bh            ; one byte set identifier?
  1576.     jz    vtupss1            ; z = yes
  1577.     mov    al,94            ; a 94 byte set
  1578. vtupss1:mov    upss,al            ; set length
  1579.     mov    word ptr upss+1,bx    ; store set ident
  1580.     mov    vtemu.vtchop,-1        ; clear operational char set to reinit
  1581.     clc
  1582. vtupssx:ret
  1583.                       ; SET TERM RESET
  1584. termreset:mov    vtinited,0        ; say uninitialized
  1585.     clc
  1586.     ret
  1587.  
  1588. apcctl:    cmp    apctrap,0        ; doing within an APC-macro?
  1589.     jne    apcctl1            ; ne = yes, don't do it
  1590.     mov    ah,cmkey        ; SET TERM APC-macro enable, disable
  1591.     mov    bx,offset apchlp    ; help
  1592.     mov    dx,offset apctab    ; APC table
  1593.     call    comnd
  1594.     jc    apcctl1            ; failure
  1595.     push    bx
  1596.     mov    ah,cmeol
  1597.     call    comnd
  1598.     pop    bx
  1599.     jc    apcctl1            ; c = fail
  1600.     mov    apcenable,bl        ; enable flag
  1601.     clc
  1602. apcctl1:ret
  1603.  
  1604. vtdownld:mov    ah,cmkey        ; AUTODOWNLOAD {ON, OFF}
  1605.     mov    bx,offset dnldhlp
  1606.     mov    dx,offset ontab
  1607.     call    comnd
  1608.     jc    vtdownldx
  1609.     mov    vtemu.vtdnld,bl        ; status
  1610.     clc
  1611. vtdownldx:ret
  1612.  
  1613. vtenqctl:mov    ah,cmkey        ; SET TERM Answerback {ON, OFF}
  1614.     mov    bx,offset enqhlp    ; help
  1615.     mov    dx,offset enqtab    ; on/off/message table
  1616.     call    comnd
  1617.     jc    vtenqctl1        ; failure
  1618.     cmp    bl,2            ; message?
  1619.     je    vtenqctl1        ; e = yes
  1620.     cmp    bl,3            ; unsafe-message?
  1621.     je    vtenqctl1        ; e = yes
  1622.     push    bx            ; else 0=off, 1=on
  1623.     mov    ah,cmeol
  1624.     call    comnd
  1625.     pop    bx
  1626.     jc    vtenqctlx        ; c = fail
  1627.     mov    vtenqenable,bl        ; enable (1) flag
  1628.     clc
  1629.     ret
  1630. vtenqctl1:
  1631.     mov    enqbuf,0        ; presume save message
  1632.     cmp    bl,3            ; unsafe?
  1633.     jne    vtenqctl2        ; ne = no
  1634.     mov    enqbuf,1        ; say unsafe
  1635. vtenqctl2:
  1636.     mov    dx,offset enqhlp2    ; help
  1637.     mov    comand.cmdonum,1    ; \number conversion allowed
  1638.     mov    comand.cmblen,length enqbuf-1 ; length of analysis buffer
  1639.     mov    bx,offset rdbuf        ; temp response buffer
  1640.     mov    ah,cmline
  1641.     call    comnd
  1642.     jc    vtenqctlx        ; c = failure
  1643.     mov    si,offset rdbuf        ; temp response buffer
  1644.     mov    di,offset enqbuf+1    ; enquire response buffer
  1645.     call    strcpy            ; copy string, asciiz
  1646.     clc
  1647. vtenqctlx:ret
  1648.  
  1649. scrwrite:mov    ah,cmkey        ; SET TERM SCREEN-WRITING
  1650.     xor    bx,bx            ; help
  1651.     mov    dx,offset writetab    ; screen table
  1652.     call    comnd
  1653.     jc    scrwritx        ; failure
  1654.     push    bx
  1655.     mov    ah,cmeol
  1656.     call    comnd
  1657.     pop    bx
  1658.     jc    vtupssx            ; c = fail
  1659.     mov    writemode,bl        ; store writing mode
  1660.     clc
  1661. scrwritx:ret
  1662.  
  1663. scrchange:mov    ah,cmkey        ; SET TERM VIDEO-CHANGE
  1664.     xor    bx,bx            ; help
  1665.     mov    dx,offset vchgtab    ; enable/disable/dos-only
  1666.     call    comnd
  1667.     jc    scrchangex        ; failure
  1668.     push    bx
  1669.     mov    ah,cmeol
  1670.     call    comnd
  1671.     pop    bx
  1672.     jc    scrchangex        ; c = fail
  1673.     mov    vchgmode,bl        ; store video-change mode
  1674.     clc
  1675. scrchangex:ret
  1676.  
  1677.  
  1678. expmemory:mov    ah,cmkey        ; EXPANDED-MEMORY {OFF, EXTENDED, EXP}
  1679.     mov    bx,offset expmhlp    ; help
  1680.     mov    dx,offset emmtab    ; emm choice table
  1681.     call    comnd
  1682.     jc    expmem2            ; failure
  1683.     push    bx
  1684.     mov    ah,cmeol
  1685.     call    comnd
  1686.     pop    bx
  1687.     jc    expmem2            ; c = fail
  1688.     cmp    useexp,bl        ; changing kinds?
  1689.     je    expmem1            ; e = no
  1690.     mov    vsbuff_inited,0        ; say reinitialize buffer memory
  1691.     mov    useexp,bl        ; enable (1) flag
  1692. expmem1:clc
  1693. expmem2:ret
  1694.  
  1695. vtcodepage:mov    ah,cmkey        ; SET TERM CODE-PAGE
  1696.     xor    bx,bx            ; help
  1697.     mov    dx,offset setchtab    ; Code Page table
  1698.     call    comnd
  1699.     jc    vtcode1            ; failure
  1700.     push    bx
  1701.     mov    ah,cmeol
  1702.     call    comnd
  1703.     pop    bx
  1704.     jc    vtcode1            ; c = fail
  1705.     mov    vtcpage,bx        ; new terminal Code Page
  1706.     mov    vtemu.vtchop,-1        ; force change of working set
  1707.     clc
  1708. vtcode1:ret
  1709.  
  1710. vtcpu:    mov    ah,cmkey        ; SET TERM Timeslice-release
  1711.     xor    bx,bx            ; help
  1712.     mov    dx,offset disatab    ; enable/disable
  1713.     call    comnd
  1714.     jc    vtcpux            ; failure
  1715.     push    bx
  1716.     mov    ah,cmeol
  1717.     call    comnd
  1718.     pop    bx
  1719.     jc    vtcpux            ; c = fail
  1720.     mov    vtcpumode,bl        ; store timeslice release mode
  1721.     clc
  1722. vtcpux:    ret
  1723.  
  1724. vtcrdisp:mov    ah,cmkey
  1725.     xor    bx,bx
  1726.     mov    dx,offset crdisptab    ; table
  1727.     call    comnd
  1728.     jc    vtcrdispx
  1729.     push    bx
  1730.     mov    ah,cmeol
  1731.     call    comnd
  1732.     pop    bx
  1733.     jc    vtcrdispx
  1734.     mov    crdisp_mode,bl
  1735.     clc
  1736. vtcrdispx:ret
  1737.  
  1738. termesc:mov    ah,cmkey        ; SET TERM ESCAPE
  1739.     xor    bx,bx
  1740.     mov    dx,offset termesctab    ; table
  1741.     call    comnd
  1742.     jc    termescx
  1743.     push    bx
  1744.     mov    ah,cmeol
  1745.     pop    bx
  1746.     jc    termescx
  1747.     mov    termesc_flag,bl
  1748.     clc
  1749. termescx:ret
  1750.  
  1751. ; SET Term flags. These are the (near) equivalent of VT100 Setup mode values.
  1752. flg1:    mov    ax,vsnewline        ; NEWLINE
  1753.     mov    dx,offset ontab
  1754.     jmp    short flgset
  1755. flg2:    mov    ax,vswrap        ; WRAP
  1756.     mov    dx,offset ontab
  1757.     jmp    short flgset
  1758. flg4:    mov    ax,vswdir        ; DIRECTION
  1759.     mov    dx,offset dirtab
  1760.     jmp    short flgset
  1761. flg5:    mov    ax,vskeyclick        ; KEYCLICK
  1762.     mov    dx,offset ontab
  1763.     jmp    short flgset
  1764. flg6:    mov    ax,vsmarginbell        ; MARGIN BELL
  1765.     mov    dx,offset ontab
  1766.     jmp    short flgset
  1767. flg7:    mov    ax,vscursor        ; CURSOR
  1768.     mov    dx,offset curtab
  1769.     jmp    short flgset
  1770. flg8:    mov    ax,vsscreen        ; SCREEN
  1771.     mov    dx,offset scrtab
  1772.     jmp    short flgset
  1773. flg9:    mov    ax,vscntl        ; CONTROLS
  1774.     mov    dx,offset cntltab
  1775.     jmp    short flgset
  1776. flg10:    mov    ax,deckpam        ; KEYPAD
  1777.     mov    dx,offset kpamtab
  1778.     jmp    short flgset
  1779. flg11:    mov    ax,decckm        ; ARROW
  1780.     mov    dx,offset arrtab
  1781.     jmp    short flgset
  1782. flg12:    mov    ax,deccol        ; WIDTH
  1783.     mov    dx,offset widtab
  1784.     jmp    short flgset
  1785. flg13:    mov    ax,vshscroll        ; Horizontal scrolling
  1786.     mov    dx,offset hstab
  1787.     jmp    short flgset
  1788. flg14:    mov    ax,vscompress        ; compressed text display
  1789.     mov    dx,offset cmptab
  1790. ;;    jmp    short flgset
  1791.  
  1792. flgset:    push    ax            ; save flag
  1793.     mov    ah,cmkey        ; another keyword
  1794.     xor    bx,bx            ; use default help, dx has table ptr
  1795.     call    comnd
  1796.     pop    ax            ; recover index
  1797.     jc    flgse0            ; c = failure
  1798.     push    ax
  1799.     push    bx            ; save result of keyword
  1800.     mov    ah,cmeol        ; get confirm
  1801.     call    comnd
  1802.     pop    bx
  1803.     pop    ax            ; recover flag
  1804.     jc    flgse0            ; c = failure
  1805.     or    bx,bx            ; set or clear?
  1806.     jz    flgse1            ; z = clear it
  1807.     or    vtemu.vtflgst,ax    ; set the flag
  1808.     or    vtemu.vtflgop,ax    ; in runtime flags too
  1809. flgse3:    test    ax,deccol        ; modifying screen width?
  1810.     jz    flgse2            ; z = no
  1811.     mov    al,crt_cols        ; current width
  1812.     mov    dos_cols,al        ; width to remember, for changes
  1813. flgse2:    clc                ; success
  1814. flgse0:    ret     
  1815. flgse1: not    ax            ; Complement
  1816.     and    vtemu.vtflgst,ax    ; clear the indicated setup flag
  1817.     and    vtemu.vtflgop,ax    ; clear the indicated runtime flag
  1818.     not    ax
  1819.     jmp    short flgse3        ; test for screen change
  1820.      
  1821. ;    SET Term Tabstops Clear ALL
  1822. ;    SET Term Tabstops Clear AT n1, n2, ..., nx
  1823. ;    SET Term Tabstops At n1, n2, ..., nx
  1824.      
  1825. tabmod:    mov    ah,cmkey        ; parse keyword
  1826.     mov    bx,offset clrhlp    ; help text
  1827.     mov    dx,offset tabtab    ; table
  1828.     call    comnd
  1829.     jc    tabmo2            ; c = failure
  1830.     mov    clrset,2        ; 2 = code for set a tab
  1831.     or    bl,bl            ; clear?
  1832.     jnz    tabmo4            ; nz = no, SET. parse column number(s)
  1833.     mov    clrset,1        ; code for clear at/all tab(s)
  1834.     mov    ah,cmkey        ; CLEAR, parse ALL or AT
  1835.     mov    bx,offset clrhlp    ; help text
  1836.     mov    dx,offset alltab    ; parse ALL or AT
  1837.     call    comnd
  1838.     jc    tabmo2            ; c = failure
  1839.     or    bx,bx            ; ALL?
  1840.     jnz    tabmo4            ; nz = AT, clear at specific places
  1841.     mov    ah,cmeol        ; confirm the ALL
  1842.     call    comnd
  1843.     jc    tabmo2            ; c = failure
  1844.     mov    cx,vswidth        ; ALL, means clear all tab stops
  1845. tabmo1:    mov    dx,cx
  1846.     dec    dl            ; column number, starting with 0
  1847.     mov    si,vtemu.vttbs        ; the cold-start buffer
  1848.     call    ftabclr            ; clear the tab
  1849.     loop    tabmo1            ; do all columns
  1850.     mov    si,vtemu.vttbs
  1851.     mov    di,vtemu.vttbst        ; and active buffer
  1852.     call    tabcpy            ; update active tabs
  1853.     clc                ; success
  1854. tabmo2:    ret                ; a success/fail return point
  1855.  
  1856. tabmo4:    mov    si,vtemu.vttbs        ; from the cold-start buffer
  1857.     mov    di,offset decbuf    ; temp work buffer
  1858.     call    tabcpy            ; make a working copy of the tabs
  1859.     mov    skip,0            ; clear spacing-active flag
  1860.     mov    temp,0            ; place where last tab was written
  1861. tabmo6:    mov    dx,offset clrhlp2    ; tell them we want a column number
  1862.     mov    ah,cmword        ; get line of text
  1863.     mov    bx,offset rdbuf        ; temp buffer
  1864.     mov    comand.cmcomma,1    ; commas are equivalent to spaces
  1865.     call    comnd
  1866.     jc    tabmo2            ; c = failure
  1867.     or    ax,ax            ; anything given?
  1868.     jnz    tabmo7            ; nz = yes
  1869.     mov    ah,cmeol        ; confirm end of line
  1870.     call    comnd
  1871.     jc    tabmo2            ; failure
  1872.     mov    si,offset decbuf    ; copy tabs from temp work buffer
  1873.     mov    di,vtemu.vttbs        ; to the cold-start buffer
  1874.     call    tabcpy            ; copy work to cold start
  1875.     mov    di,vtemu.vttbst        ; and terminal emulator's active buf
  1876.     call    tabcpy
  1877.     clc
  1878.     ret
  1879.  
  1880. tbsbad:    mov    ah,prstr        ; not in range - complain
  1881.     mov    dx,offset tbserr
  1882.     int    dos
  1883.     stc
  1884.     ret
  1885.      
  1886. tabmo7:    mov    si,offset rdbuf        ; si = string
  1887. tabmo8:    mov    dx,si
  1888.     call    strlen            ; get length of this word
  1889.     jcxz    tabmo6            ; empty, get more user input
  1890.     mov    domath_ptr,si        ; try for expression
  1891.     mov    domath_cnt,cx
  1892.     mov    domath_msg,1        ; do not complain
  1893.     call    domath
  1894.     mov    si,domath_ptr        ; where to read next string byte
  1895.     jnc    tabmo9            ; got a value
  1896.     cmp    byte ptr [si],','    ; comma syntax?
  1897.     jne    tabmo8a            ; ne = no
  1898.     inc    si            ; skip the comma and try next field
  1899.     jmp    short tabmo8
  1900. tabmo8a:cmp    byte ptr [si],':'    ; spacing separator?
  1901.     jne    tbsbad            ; ne = no, no number available
  1902.     inc    si            ; skip colon, do start:space analysis
  1903.     inc    skip            ; set spacing-active flag
  1904.     jmp    short tabmo8        ; get another token
  1905.  
  1906. tabmo9:    cmp    skip,0            ; want spacing value now?
  1907.     jne    tabmo11            ; ne = yes, go do it
  1908.     mov    dx,ax            ; column (1-vswidth style)
  1909.     dec    dx            ; put column in range 0-131
  1910.     or    dx,dx            ; check range (1-vswidth-->0-...)
  1911.     js    tbsbad            ; s = too small. complain
  1912.     cmp    dl,vswidth-1        ; more than the right most column?
  1913.     ja    tbsbad            ; a = yes, quit
  1914.     mov    temp,dx            ; remember last written position
  1915.     jmp    tabmo15            ; and write this member
  1916.  
  1917. tabmo11:mov    dx,temp            ; continue spacing analysis
  1918.     mov    skip,0            ; clear spacing-active flag
  1919.     mov    cx,ax            ; "space" value
  1920.     or    cx,cx            ; zero spacing?
  1921.     jnz    tabmo12            ; nz = no
  1922.     inc    cx            ; don't get caught with zero spacing
  1923. tabmo12:cmp    dx,vswidth-1        ; largest tab stop
  1924.     ja    tabmo8            ; a = done largest tab stop
  1925.     mov    temp,dx            ; remember last written tabstop
  1926.     push    si
  1927.     mov    si,offset decbuf    ; the work buffer
  1928.     cmp    clrset,2        ; set?
  1929.     jne    tabmo13            ; ne = no, clear
  1930.     call    ftabset            ; set tabstop in column DL
  1931.     jmp    short tabmo14
  1932. tabmo13:call    ftabclr            ; clear tabstop in column DL
  1933. tabmo14:add    dx,cx            ; new column value
  1934.     pop    si
  1935.     jmp    short tabmo12        ; finish spacing loop
  1936.  
  1937. tabmo15:push    si            ; individual tabstop
  1938.     mov    si,offset decbuf    ; the work buffer
  1939.     cmp    clrset,2        ; set?
  1940.     jne    tabmo16            ; ne = no, clear
  1941.     call    ftabset            ; set tabstop in column DL
  1942.     jmp    short tabmo17        ; get next command value
  1943. tabmo16:call    ftabclr            ; clear tabstop in column DL
  1944. tabmo17:pop    si
  1945.     jmp    tabmo8            ; get next command value
  1946.  
  1947. VTS    endp                ; end of Set Term things
  1948.  
  1949.           ; Terminal Status display, called within STAT0: in MSSSET
  1950. VTSTAT    proc    near            ; enter with di within sttbuf, save bx
  1951.     mov    bx,offset vtstbl    ; table of things to show
  1952.     jmp    statc            ; status common code, in mssset
  1953. vtstat    endp
  1954.  
  1955. txtcolstat proc    near            ; text color status report
  1956.     push    si
  1957.     mov    si,offset txtcolst1
  1958.     mov    bx,vtemu.att_ptr    ; pointer to attributes byte
  1959.     call    colstd            ; report worker
  1960.     mov    si,offset colst3
  1961. txtcols1:lodsb
  1962.     cmp    al,'$'
  1963.     je    txtcols2
  1964.     stosb
  1965.     jmp    short txtcols1
  1966. txtcols2:mov    al,reset_color
  1967.     or    al,al            ; resetting color after CSI [ m?
  1968.     jz    txtcols3        ; z = no
  1969.     mov    al,'2'            ; show as "20"
  1970.     stosb
  1971. txtcols3:mov    al,'0'
  1972.     stosb
  1973.     pop    si
  1974.     ret
  1975. txtcolstat endp
  1976.  
  1977. undcolstat proc    near            ; underline color status report
  1978.     push    si
  1979.     mov    si,offset undcolst1
  1980.     mov    bx,offset colunder    ; pointer to attributes byte
  1981.     call    colstd            ; report worker
  1982.     pop    si
  1983.     ret
  1984. undcolstat endp
  1985.  
  1986. ifndef    no_graphics
  1987. grcolstat proc    near            ; graphics color status report
  1988.     push    si
  1989.     mov    si,offset grcolst1
  1990.     call    tekgcptr        ; get pointer to active Tek color pal
  1991.     call    colstd            ; report worker
  1992.     pop    si
  1993.     ret
  1994. grcolstat endp
  1995. endif    ; no_graphics
  1996.  
  1997. ; enter with offset of initial msg in si and ptr to color codes in bx
  1998. colstd    proc    near            ; worker for color status reports
  1999.     cld
  2000. colstd1:lodsb
  2001.     cmp    al,'$'            ; end of string?
  2002.     je    colstd2            ; e = yes
  2003.     stosb
  2004.     jmp    short colstd1
  2005. colstd2:mov    bl,byte ptr[bx]        ; attributes
  2006.     xor    bh,bh
  2007.     push    bx
  2008.     and    bx,7            ; get foreground set
  2009.     mov    al,colortb[bx]        ; get reversed bit pattern
  2010.     add    al,'0'            ; add ascii bias
  2011.     stosb
  2012.     pop    bx
  2013.     mov    si,offset colst2
  2014. colstd3:lodsb
  2015.     cmp    al,'$'
  2016.     je    colstd4
  2017.     stosb
  2018.     jmp    short colstd3
  2019. colstd4:mov    cl,4            ; rotate 4 positions
  2020.     shr    bl,cl
  2021.     and    bx,7            ; get background set
  2022.     mov    al,colortb[bx]        ; get reversed bit pattern
  2023.     add    al,'0'            ; add ascii bias
  2024.     stosb
  2025.     ret
  2026. colstd endp
  2027.  
  2028. tabstat proc    near            ; worker,display tabs ruler for Status
  2029.     push    dx
  2030.     cld
  2031.     mov    al,cr
  2032.     stosb
  2033.     cmp    cl,10            ; are we on a new line?
  2034.     jb    tabsta0            ; b = no, do a lf now
  2035.     mov    al,lf
  2036.     stosb
  2037. tabsta0:xor    cl,cl            ; column index
  2038.     xor    ax,ax            ; ah = tens, al = units counter
  2039. tabsta1:mov    dl,'.'            ; default position symbol
  2040.     inc    al
  2041.     cmp    al,10            ; time to roll over?
  2042.     jb    tabsta2            ; b = not yet
  2043.     xor    al,al            ; modulo 10
  2044.     inc    ah
  2045.     mov    dl,ah            ; display a tens-digit
  2046.     add    dl,'0'
  2047.     cmp    dl,'9'            ; larger than 90?
  2048.     jbe    tabsta2            ; be = no
  2049.     sub    dl,10            ; roll over to 0, 1, etc
  2050. tabsta2:push    dx
  2051.     push    si
  2052.     mov    dl,cl            ; column number, counted from 0
  2053.     mov    si,vtemu.vttbst        ; the active buffer
  2054.     call    istabs            ; is tab set here?
  2055.     pop    si
  2056.     pop    dx
  2057.     jnc    tabsta3            ; nc = no
  2058.     mov    dl,'T'            ; yes, display a 'T'
  2059. tabsta3:push    ax
  2060.     mov    al,dl
  2061.     stosb
  2062.     pop    ax
  2063.     inc    cl
  2064.     cmp    cl,byte ptr low_rgt    ; done yet?
  2065.     jb    tabsta1            ; b = not yet
  2066.     pop    dx
  2067.     ret
  2068. tabstat endp
  2069.  
  2070. ; Returns carry set if column in DL is a tab stop, else carry clear.
  2071. ; Enter with column number in DL (starts at column 0, max of vswidth-1)
  2072. ; and tabstop buffer offset in SI.
  2073. istabs    proc    near
  2074.     push    bx
  2075.     push    cx
  2076.     mov    cl,dl            ; column number (0 to swidth-1)
  2077.     and    cl,00000111b        ; keep bit in byte (0-7)
  2078.     inc    cl            ; map to 1-8
  2079.     mov    bl,dl            ; column
  2080.     shr    bl,1            ; bl / 8 to get byte
  2081.     shr    bl,1
  2082.     shr    bl,1
  2083.     xor    bh,bh            ; clear high byte
  2084.     mov    bl,[si+bx]        ; get a byte of tab bits
  2085.     ror    bl,cl            ; rotate to put tab-set bit into carry
  2086.     pop    cx
  2087.     pop    bx
  2088.     ret
  2089. istabs    endp
  2090.  
  2091. ansbkstat proc    near
  2092.     mov    ax,di            ; starting place
  2093.     push    ax
  2094.     mov    si,offset vtenqst2
  2095.     mov    cx,vtenqst2_len
  2096.     cld
  2097.     rep    movsb
  2098.     mov    si,offset enqbuf+1    ; skip safe/unsafe byte
  2099.     mov    dx,si
  2100.     call    strlen            ; append local string
  2101.     rep    movsb
  2102.     pop    ax
  2103.     mov    cx,di
  2104.     sub    cx,ax            ; return space used
  2105.     ret
  2106. ansbkstat endp
  2107.  
  2108. filler    proc    near            ; use space
  2109.     mov    cx,20
  2110.     mov    al,' '
  2111.     cld
  2112.     rep    stosb
  2113.     ret
  2114. filler    endp
  2115.  
  2116. ; Jump here to exit Connect mode and execute macros 'KEYBOARDR' (vtkrmac) or
  2117. ; 'KEYBOARDS' (vtksmac). Does nothing if macro does not exist.
  2118. ; Preserves registers except ax. Returns to TELNET caller with 'C' in kbdflg.
  2119. vtkrmac    proc    near            ; RESET macro
  2120.     mov    vtmacname,offset vtkrname ; select macro name
  2121.     mov    vtmaclen,vtkrlen    ; and its length
  2122.     call    dword ptr vtmacroptr    ; FAR pointer, finish in common code
  2123.     jc    vtkrmac1        ; c = failure
  2124.     jmp    far ptr endcon        ; end connect mode, do macro
  2125. vtkrmac1:ret
  2126. vtkrmac    endp
  2127.  
  2128. vtksmac    proc    near            ; SET macro
  2129.     mov    vtmacname,offset vtksname
  2130.     mov    vtmaclen,vtkslen
  2131.     call    dword ptr vtmacroptr    ; FAR pointer
  2132.     jc    vtksmac1        ; c = failure
  2133.     jmp    far ptr endcon        ; end connect mode, do macro
  2134. vtksmac1:ret
  2135. vtksmac    endp
  2136.  
  2137. ; Invoked by keyboard translator when an unknown keyboard verb is used as
  2138. ; a string definition, such as {\ktest}. Enter with vtmacname pointing to
  2139. ; uppercased verb name, asciiz, and vtmaclen set to its length.
  2140. extmacro proc    near
  2141.     call    dword ptr vtmacroptr    ; FAR pointer
  2142.     jc    extmac1            ; c = failure
  2143.     jmp    far ptr endcon        ; end connect mode, do macro
  2144. extmac1:mov    kbdflg,' '        ; report ' ' to TERM's caller
  2145.     ret                ; to resume Connect mode
  2146. extmacro endp
  2147.  
  2148. ; Invokes macro PRODUCT with variables \%1..\%9
  2149. ; defined as the ascii renditions of the control sequence numeric paramters
  2150. ; param[0]..param[8], and sets script ARGC item to one greater than this.
  2151.  
  2152. product    proc    near
  2153.     call    far ptr prodwork    ; FAR pointer
  2154.     jc    prodmac1        ; c = failure
  2155.     jmp    far ptr endcon        ; end connect mode, do macro
  2156. prodmac1:ret
  2157. product    endp
  2158.  
  2159. term    proc    near
  2160.     call    far ptr fterm
  2161.     ret
  2162. term    endp
  2163.  
  2164. fclrmod    proc    far
  2165.     call    clrmod
  2166.     ret
  2167. fclrmod    endp
  2168.  
  2169. fputmod    proc    far
  2170.     call    putmod
  2171.     ret
  2172. fputmod    endp
  2173.  
  2174. fcmblnk    proc    far
  2175.     call    cmblnk
  2176.     ret
  2177. fcmblnk    endp
  2178. fkbhold    proc    far
  2179.     call    kbhold
  2180.     ret
  2181. fkbhold    endp
  2182. fprtchr    proc    far
  2183.     call    prtchr
  2184.     ret
  2185. fprtchr    endp
  2186. fkeybd    proc    far
  2187.     call    keybd
  2188.     ret
  2189. fkeybd    endp
  2190. fpntflsh proc    far
  2191.     call    pntflsh
  2192.     ret
  2193. fpntflsh endp
  2194. fpntchr    proc    far
  2195.     call    pntchr
  2196.     ret
  2197. fpntchr    endp
  2198. foutchr    proc    far
  2199.     call    outchr
  2200.     ret
  2201. foutchr    endp
  2202. fspath    proc    far
  2203.     call    spath
  2204.     ret
  2205. fspath    endp
  2206. fcrun    proc    far
  2207.     call    crun
  2208.     ret
  2209. fcrun    endp
  2210. fserini    proc    far
  2211.     call    serini
  2212.     ret
  2213. fserini    endp
  2214. fctlu    proc    far                ; [HF]940211
  2215.     call    ctlu                ; [HF]940211
  2216.     ret                    ; [HF]940211
  2217. fctlu    endp                    ; [HF]940211
  2218. vtinit    proc    near
  2219.     call    fvtinit
  2220.     ret
  2221. vtinit    endp
  2222.  
  2223. rtone    proc    near
  2224.     call    frtone
  2225.     ret
  2226. rtone    endp
  2227.  
  2228. rtpage    proc    near
  2229.     call    frtpage
  2230.     ret
  2231. rtpage    endp
  2232.  
  2233. lfone    proc    near
  2234.     call    flfone
  2235.     ret
  2236. lfone    endp
  2237.  
  2238. lfpage    proc    near
  2239.     call    flfpage
  2240.     ret
  2241. lfpage    endp
  2242.  
  2243. homwnd    proc    near
  2244.     call    fhomwnd
  2245.     ret
  2246. homwnd    endp
  2247. endwnd    proc    near
  2248.     call    fendwnd
  2249.     ret
  2250. endwnd    endp
  2251. dnwpg    proc    near
  2252.     call    fdnwpg
  2253.     ret
  2254. dnwpg    endp
  2255. dnone    proc    near
  2256.     call    fdnone
  2257.     ret
  2258. dnone    endp
  2259. upwpg    proc    near
  2260.     call    fupwpg
  2261.     ret
  2262. upwpg    endp
  2263. upone    proc    near
  2264.     call    fupone
  2265.     ret
  2266. upone    endp
  2267. fcptchr    proc    far
  2268.     call    cptchr
  2269.     ret
  2270. fcptchr    endp
  2271. fserrst    proc    far
  2272.     call    serrst
  2273.     ret
  2274. fserrst    endp
  2275. ifndef    no_network
  2276. fubclose proc    far
  2277.     call    ubclose
  2278.     ret
  2279. fubclose endp
  2280. endif    ; no_network
  2281. endif    ; no_terminal
  2282. code    ends
  2283.  
  2284. code1    segment
  2285.     assume    cs:code1
  2286.                     ; Kermit startup time initialization
  2287. flclyini proc    far
  2288.     mov    ah,conout        ; write a space to determine
  2289.     mov    dl,' '            ; DOS's default cursor coloring
  2290.     int    dos
  2291.     call    getpcur            ; get current cursor position into dx
  2292.     mov    lincur,cx        ; save cursor type (scan line #'s)
  2293.     dec    dl            ; backup to last char
  2294.     or    dl,dl
  2295.     jns    lclyin5            ; ns = no problem
  2296.     xor    dl,dl            ; else set cursor back to left margin
  2297. lclyin5:call    setpcur            ; set the cursor
  2298.     call    getpcha            ; read current attributes into AH
  2299.     mov    scbattr,ah        ; save video attributes
  2300.     mov    savattr,ah        ; and saved attributes
  2301.     mov    dosattr,ah        ; and here too
  2302.     and    ah,att_bold        ; select intensity bit
  2303.     mov    userbold,ah        ; save bit for user Bold control
  2304.     mov    ega_mode,0        ; assume no EGA
  2305.     mov    ax,1200H        ; EGA: Bios alternate select
  2306.     mov    bl,10H            ; Ask for EGA info
  2307.     mov    bh,0ffH            ; Bad info, for testing
  2308.     mov    cl,0fH            ; Reserved switch settings
  2309.     int    screen            ; EGA, are you there?
  2310.     cmp    cl,0cH            ; Test reserved switch settings
  2311.     jge    lclyin1            ; ge = no EGA in use
  2312.     push    es
  2313.     mov    ax,40h            ; check Bios 40:87h for ega being
  2314.     mov    es,ax            ;  the active display adapter
  2315.     test    byte ptr es:[87h],8    ; is ega active?
  2316.     pop    es
  2317.     jnz    lclyin1            ; nz = no
  2318.     mov    ega_mode,1        ; yes, set flag to say ega is active
  2319.     mov    crt_norm,3        ; assume color monitor is attached
  2320.     or    bh,bh            ; is color mode in effect?
  2321.     jz    lclyin1            ; z = yes
  2322.     mov    crt_norm,7        ; else use mode 7 for mono
  2323. lclyin1:call    scrseg            ; test running in an Environment
  2324.     call    dvtest            ; test for running under DESQview
  2325.     call    scrmod            ; read video state, get crt_mode
  2326.     mov    dosetcursor,-1        ; cursor position reminder, none
  2327.     mov    ax,low_rgt        ; lower right corner of screen
  2328.     mov    al,crt_mode
  2329.     mov    crt_norm,al        ; save as normal mode
  2330.     mov    ah,crt_cols
  2331.     mov    dos_cols,ah        ; remember for exiting Connect mode
  2332. ifndef    no_terminal
  2333.     mov    keypend,0        ; [HF]940207 clear double byte flag
  2334.     mov    keyj7st,0        ; [HF]940211 clear keyoutput status
  2335.     mov    cursor,0        ; initial cursor
  2336.     call    vsalloc            ; allocate memory for virtual screen
  2337.     jnc    lclyin4            ; nc = success
  2338.     mov    ah,prstr
  2339.     mov    dx,offset memerr    ; say not enough memory to operate
  2340.     int    dos
  2341.     mov    flags.extflg,1        ; set Kermit exit flag
  2342.     ret
  2343.  
  2344. lclyin4:call    vsinit            ; init terminal emulator module MSZ
  2345.     mov    bx,vtemu.att_ptr    ; attributes pointer
  2346.     mov    ah,dosattr        ; startup video attributes
  2347.     and    ah,not att_bold        ; emulation intensity to normal
  2348.     or    ah,userbold
  2349.     mov    [bx],ah            ; set initial emulation attributes
  2350.     and    vtemu.vtflgst,not deccol ; assume 80 column screen
  2351.     and    vtemu.vtflgop,not deccol
  2352.     cmp    crt_cols,80        ; screen cols now, wide screen?
  2353.     jbe    lclyin6            ; be = no
  2354.     or    vtemu.vtflgst,deccol    ; say using 132 columns screen
  2355.     or    vtemu.vtflgop,deccol
  2356. endif    ; no_terminal
  2357. lclyin6:ret
  2358. flclyini endp
  2359.  
  2360. ifndef    no_terminal
  2361.  
  2362. ; Allocate memory for virtual screen buffers vscreen and vsat.
  2363. ; Return carry clear if success, else carry set. Removes older allocations.
  2364. vsalloc    proc    near
  2365.     call    vsalloc4        ; free alloc'd memory, if any
  2366.     mov    al,crt_lins        ; one minus number of screen rows
  2367.     inc    al
  2368.     mov    cl,vswidth        ; virtual screen vscreen
  2369.     mul    cl            ; lines time width, words for vscreen
  2370.     add    ax,ax            ; need words
  2371.     add    ax,15            ; round up
  2372.     mov    cl,4            ; convert to paragraphs
  2373.     shr    ax,cl            ; need words rather than bytes
  2374.     mov    cx,ax            ; save total wanted paragraphs in cx
  2375.     mov    bx,ax            ; ask for the memory
  2376.     mov    ah,alloc        ; allocate memory
  2377.     int    dos            ; bx has # free paragraphs
  2378.     mov    word ptr vs_ptr+2,ax    ; seg of vsscreen (offset is zero)
  2379.     cmp    cx,bx            ; got what we wanted
  2380.     jb    vsalloc5        ; b = no
  2381.     push    es
  2382.     mov    es,ax
  2383.     xor    di,di
  2384.     shl    cx,1
  2385.     shl    cx,1
  2386.     shl    cx,1            ; paragraphs to words
  2387.     mov    ah,scbattr
  2388.     mov    al,' '
  2389.     cld
  2390.     rep    stosw             ; clear the memory with def colors
  2391.     pop    es
  2392.     mov    al,crt_lins
  2393.     inc    al            ; attributes (nibbles)
  2394.     mov    cl,vswidth        ; lines time width, bytes for vsattr
  2395.     mul    cl
  2396.     add    ax,15            ; round up
  2397.     mov    cl,4            ; convert to paragraphs
  2398.     shr    ax,cl
  2399.     mov    cx,ax            ; save total wanted paragraphs in cx
  2400.     mov    bx,ax            ; ask for the memory
  2401.     mov    ah,alloc        ; allocate the memory
  2402.     int    dos            ; bx has # free paragraphs
  2403.     mov    word ptr vsat_ptr+2,ax    ; seg of vsattr (offset is zero)
  2404.     cmp    cx,bx            ; got what we wanted
  2405.     jb    vsalloc4        ; b = no
  2406.     push    es
  2407.     mov    es,ax
  2408.     xor    di,di
  2409.     shl    cx,1
  2410.     shl    cx,1
  2411.     shl    cx,1
  2412.     shl    cx,1            ; paragraphs to bytes
  2413.     xor    al,al
  2414.     rep    stosb             ; clear the memory with def extattr
  2415.     pop    es
  2416.     clc                ; report success
  2417.     ret
  2418.  
  2419. vsalloc4:mov    ax,word ptr vsat_ptr+2    ; seg of vsattr (offset is zero)
  2420.     or    ax,ax            ; unused?
  2421.     jz    vsalloc5        ; z = yes
  2422.     push    es
  2423.     mov    es,ax            ; allocated segment
  2424.     mov    ah,freemem        ; free it
  2425.     int    dos
  2426.     mov    word ptr vsat_ptr+2,0    ; clear pointer too
  2427.     pop    es
  2428. vsalloc5:mov    ax,word ptr vs_ptr+2    ; seg of vsscreen
  2429.     or    ax,ax            ; unused?
  2430.     jz    vsalloc6        ; z = yes
  2431.     push    es
  2432.     mov    es,ax            ; allocated segment
  2433.     mov    ah,freemem        ; free it
  2434.     int    dos
  2435.     mov    word ptr vs_ptr+2,0    ; clear pointer too
  2436.     pop    es
  2437. vsalloc6:stc                ; return failure
  2438.     ret
  2439. vsalloc    endp
  2440.  
  2441. ; Allocate memory for screen rollback buffers.
  2442. ; Return carry clear if success, else carry set to exit.
  2443. vsbuff    proc    near            ; screen roll back buffers
  2444.     cmp    vsbuff_inited,0        ; inited yet?
  2445.     je    vsbuff0            ; e = no
  2446.     clc                ; say success
  2447.     ret
  2448. vsbuff0:mov    vsbuff_inited,1        ; say we are initializing
  2449.     cmp    emsrbhandle,-1        ; valid EMS rollback handle?
  2450.     je    vsbuff20        ; e = no
  2451.     mov    ah,emsrelease        ; release pages
  2452.     mov    dx,emsrbhandle        ; handle
  2453.     int    emsint
  2454.     mov    emsrbhandle,-1        ; invalidate EMS rollback handle
  2455.     mov    iniseg,0        ; and no segment for page frame
  2456.     jmp    short vsbuff21
  2457. vsbuff20:cmp    xmsrhandle,0        ; using XMS?
  2458.     je    vsbuff20a        ; e = no
  2459.     mov    dx,xmsrhandle        ; handle for memory block
  2460.     mov    ah,xmsrelease        ; release the memory block
  2461.     call    dword ptr xmsep        ; xms handler entry point
  2462.     mov    xmsrhandle,0
  2463.     mov    dx,xmsghandle        ; and the graphics area too
  2464.     mov    ah,xmsrelease        ; release the memory block
  2465.     call    dword ptr xmsep        ; xms handler entry point
  2466.     mov    xmsghandle,0
  2467. vsbuff20a:
  2468.     mov    ax,iniseg        ; memory segment, window area
  2469.     or    ax,ax            ; anything allocated?
  2470.     jz    vsbuff21        ; z = no
  2471.     mov    es,ax
  2472.     mov    ah,freemem        ; free regular memory segment
  2473.     int    dos
  2474.     mov    iniseg,0
  2475. vsbuff21:
  2476.     mov    bx,rollwidth        ; columns to roll back
  2477.     or    bx,bx            ; user override given?
  2478.     jnz    vsbuff1            ; nz = yes, else physical screen
  2479.     mov    bl,crt_cols        ; physical screen
  2480.     xor    bh,bh
  2481.     mov    rollwidth,bx        ; set final roll width
  2482. vsbuff1:add    bx,7            ; round up (cancel common times twos)
  2483.     mov    cl,3
  2484.     shr    bx,cl            ; bytes/line to paragraphs/line
  2485.     mov    ppl,bx            ; paragraphs/line
  2486.  
  2487.  
  2488. vsbuff11:                ; expanded memory
  2489.     test    useexp,1        ; use expanded memory?
  2490.     jz    vsbuff10        ; z = no, try XMS
  2491.     mov    ah,open2        ; file open
  2492.     xor    al,al            ; 0 = open readonly
  2493.     mov    dx,offset emsname    ; device name EMMXXXX0
  2494.     int    dos
  2495.     jc    vsbuff10        ; can't open, no expanded memory
  2496.     push    ax            ; save handle
  2497.     mov    bx,ax            ; handle ax
  2498.     xor    al,al            ; get device info
  2499.     mov    ah,ioctl
  2500.     int    dos
  2501.     pop    ax
  2502.     push    dx            ; save status report in dx
  2503.     mov    dx,ax            ; handle
  2504.     mov    ah,close2        ; close device
  2505.     int    dos
  2506.     pop    dx            ; recover status report
  2507.     rcl    dl,1            ; put ISDEV bit into the carry bit
  2508.     jnc    vsbuff10        ; nc = not a device
  2509.     mov    ax,sp            ; do push sp test for XT vs AT/386
  2510.     push    sp            ; XT pushes sp-2, AT's push old sp
  2511.     pop    cx            ; recover pushed value, clean stack
  2512.     xor    ax,cx            ; same?
  2513.     jne    vsbuff5            ; ne = no, XT. Don't do Int 2fh
  2514.     mov    ax,xmspresent        ; XMS presence test
  2515.     int    2fh
  2516.     cmp    al,80h            ; present?
  2517.     jne    vsbuff10        ; ne = no
  2518.     mov    ah,getintv        ; get interrupt vector
  2519.     mov    al,emsint        ; EMS interrupt 67h
  2520.     int    dos            ; to es:bx
  2521.     mov    ax,es
  2522.     or    ax,bx            ; check for null
  2523.     jz    vsbuff10        ; z = interrupt not activated
  2524.     mov    ah,emsmgrstat        ; LIM 3.2 manager status
  2525.     int    emsint
  2526.     or    ah,ah            ; ok?
  2527.     jnz    vsbuff10        ; nz = not ok
  2528.     mov    ax,1024            ; 1024 paragraphs per ems 16KB page
  2529.     xor    dx,dx
  2530.     div    ppl            ; divide by paragraphs per line
  2531.     mov    lineems,ax        ; lines per ems page, remember
  2532.     mov    al,crt_lins        ; lines-1 per physical screen
  2533.     xor    ah,ah
  2534.     mov    cx,npages        ; number of roll back screens wanted
  2535.     inc    cx            ; include current screen
  2536.     mul    cx            ; times number screens
  2537.     div    lineems            ; lines total / (lines/emspage)
  2538.     or    dx,dx            ; remainder?
  2539.     jz    vsbuff2            ; z = no
  2540.     inc    ax            ; add page for fraction
  2541. vsbuff2:push    ax            ;  ax is number of emspages
  2542.     mov    ah,emsgetnpgs        ; get number pages free
  2543.     int    emsint            ; to bx
  2544.     pop    ax
  2545.     or    bx,bx            ; any pages free?
  2546.     jz    vsbuff10        ; z = no, try XMS
  2547.     cmp    bx,ax            ; enough?
  2548.     jb    vsbuff3            ; b = less, use what we can get
  2549.     mov    bx,ax            ; number of pages wanted
  2550. vsbuff3:mov    ah,emsalloc        ; allocate bx pages
  2551.     int    emsint
  2552.     or    ah,ah            ; successful?
  2553.     jnz    vsbuff10        ; nz = no, failure
  2554.     mov    emsrbhandle,dx        ; returned handle
  2555.     mov    ax,bx            ; pages allocated
  2556.     mov    inipara,ax        ; save for later resizing of buffers
  2557.     mov    ah,emsgetseg        ; get segment of page frame
  2558.     int    emsint            ;  to bx
  2559.     or    ah,ah            ; status, success?
  2560.     jnz    vsbuff10        ; nz = no, no expanded memory today
  2561.     mov    iniseg,bx        ; save here
  2562.     mov    ah,emsgetver        ; get EMS version number
  2563.     int    emsint            ; to al (high=major, low=minor)
  2564.     cmp    al,40h            ; at least LIM 4.0?
  2565.     jb    vsbuff4            ; b = no, so no name for our area
  2566.     mov    si,offset emsrollname    ; point to name for rollback area
  2567.     mov    di,offset emsrollname+6    ; add digits
  2568.     mov    dx,emsrbhandle
  2569.     mov    ax,dx
  2570.     call    dec2di            ; write to handle name
  2571.     mov    ax,emssetname        ; set name for handle from ds:si
  2572.     int    emsint
  2573.     mov    useexp,1        ; say using expanded
  2574. vsbuff4:jmp    vsbuff9
  2575.  
  2576. vsbuff10:                ; XMS, try this first
  2577.     test    useexp,2        ; use extended memory?
  2578.     jz    vsbuff5            ; z = no, try conventional
  2579.     cmp    xmsrhandle,0        ; have already allocated xms?
  2580.     je    vsbuff10a        ; e = no
  2581.     mov    ah,xmsrelease        ; release memory block
  2582.     mov    dx,xmsrhandle
  2583.     call    dword ptr xmsep        ; release the memory
  2584.     jmp    short vsbuff10b
  2585. vsbuff10a:xor    bx,bx            ; clear entry point response
  2586.     mov    es,bx
  2587.     mov    ax,xmsmanager        ; get XMS manager entry point
  2588.     int    2fh            ; to es:bx
  2589.     mov    word ptr xmsep,bx    ; save entry point in xmsep
  2590.     mov    ax,es
  2591.     or    bx,ax            ; is there an entry point returned?
  2592.     jz    vsbuff5            ; z = no, use regular memory
  2593.     mov    word ptr xmsep+2,ax
  2594. vsbuff10b:mov    ax,ppl            ; paragraphs / line
  2595.     mul    crt_lins        ; times lines-1 on physical screen
  2596.     mov    cx,npages        ; number of roll back screens wanted
  2597.     inc    cx            ; include current screen
  2598.     mul    cx            ; total number of paragraphs wanted
  2599.     mov    cx,6
  2600. vsbuff10c:shr    dl,1
  2601.     rcr    ah,1
  2602.     rcr    al,1            ; get kilobytes to ax
  2603.     loop    vsbuff10c        ; divide by 2^6
  2604.     mov    dx,ax            ; KB wanted to dx
  2605.     push    dx
  2606.     mov    ah,xmsquery
  2607.     call    dword ptr xmsep        ; get largest block KB into ax
  2608.     pop    dx
  2609.     cmp    dx,ax            ; wanted KB vs available KB
  2610.     jbe    vsbuff10d        ; be = have space
  2611.     mov    dx,ax            ; else use space available
  2612. vsbuff10d:push    dx            ; save KB request amount
  2613.     mov    ah,xmsalloc        ; allocate block of dx KB
  2614.     call    dword ptr xmsep
  2615.     mov    xmsrhandle,dx        ; returned XMS handle of block
  2616.     pop    dx            ; recover KB request amount
  2617.     mov    cx,6            ; convert dx KB to paragraphs in AX
  2618.     mov    ax,dx            ; KB allocated to AX
  2619.     xor    dx,dx
  2620. vsbuff10e:shl    al,1            ; convert KB to paragraphs
  2621.     rcl    ah,1
  2622.     loop    vsbuff10e        ; times 2^6, yield paragarphs in ax
  2623.     mov    inipara,ax        ; initial number of paragraphs
  2624.     mov    useexp,2        ; say using extended
  2625.     jmp    vsbuff9            ; end XMS
  2626.  
  2627.                     ; no ems, so use regular memory
  2628. vsbuff5:mov    useexp,0        ; say no ems
  2629.     mov    bx,0ffffh        ; ask for all of memory, to get size
  2630.     mov    ah,alloc        ; allocate all of memory (must fail)
  2631.     int    dos            ; bx has # free paragraphs
  2632.     mov    ax,bx            ; ax has copy of number free paragraphs
  2633.     sub    bx,26000D/16        ; space for Command.com copy #2
  2634.     jc    vsbuff7            ; c = not enough for it
  2635.     mov    ax,ppl            ; paragraphs / line
  2636.     mul    crt_lins        ; times lines-1 on physical screen
  2637.     cmp    bx,ax            ; minimum roll back space left over?
  2638.     jbe    vsbuff7            ; be = not even that much
  2639.     mov    cx,npages        ; number of roll back screens wanted
  2640.     inc    cx            ; include current screen
  2641.     mul    cx            ; total number of paragraphs wanted
  2642.     mov    cx,ax            ; save in cx
  2643.     or    dx,dx            ; want more than 1 MB of real memory?
  2644.     jz    vsbuff6            ; e = no
  2645.     mov    cx,0ffffh        ; set all of real memory
  2646. vsbuff6:cmp    bx,cx            ; got vs wanted paras for roll back
  2647.     jbe    vsbuff8            ; be = enough but not more than needed
  2648.     mov    bx,cx            ; limit to our actual needs
  2649.     jmp    short vsbuff8        ; ask for all we really want
  2650. vsbuff7:xor    bx,bx            ; use no space at all
  2651.     mov    cx,bx            ; remember this new request
  2652. vsbuff8:mov    ah,alloc
  2653.     int    dos
  2654.     mov    iniseg,ax        ; (BDT) memory segment, window area
  2655.     mov    inipara,bx        ; save for later resizing of buffers
  2656.     cmp    cx,bx            ; paragraphs wanted vs delivered
  2657.     jae    vsbuff9            ; ae = enough
  2658.     mov    ah,prstr
  2659.     mov    dx,offset memerr    ; say not enough memory to operate
  2660.     int    dos
  2661.     stc                ; carry set = fail
  2662.     ret
  2663. vsbuff9:call    bufadj             ; set roll back buffer parameters
  2664.     clc                ; carry clear for success
  2665.     ret
  2666. vsbuff    endp
  2667.  
  2668. scrini    proc    far            ; init screen stuff
  2669.     call    chkwindows        ; check for Windows being active
  2670.     mov    al,crt_lins        ; screen lines - 1 
  2671.     mov    ah,crt_mode        ; preserve this too
  2672.     push    ax            ; save
  2673.     call    scrmod            ; get screen mode now
  2674.     mov    ax,100h            ; assume 80 column mode, no-renter
  2675.     test    vtemu.vtflgop,deccol    ; supposed to be in 80 col?
  2676.     jz    scrin5            ; z = yes
  2677.     inc    al            ; say want 132 cols
  2678. scrin5:    call    chgdsp            ; set to 80/132 columns
  2679.     call    scrmod            ; get crt_lins again
  2680.     pop    ax
  2681.     mov    crt_mode,ah        ; restore in case in graphics now
  2682.     cmp    al,crt_lins        ; changed?
  2683.     je    scrin2            ; e = no
  2684.     mov    vtinited,0        ; say must reinit emulator
  2685.     mov    cursor,0
  2686.     call    vsalloc            ; reallocate virtual screen
  2687.     jnc    scrin2            ; nc = success
  2688.     mov    ah,prstr
  2689.     mov    dx,offset memerr    ; say not enough memory to operate
  2690.     int    dos
  2691.     mov    sp,oldsp
  2692.     ret                ; must be Far return
  2693.     
  2694. scrin2:
  2695. scrin1:    mov    ah,savattr        ; saved emulator attributes
  2696.     mov    scbattr,ah        ; restore active value
  2697.     call    scrseg            ; update screen segment tv_seg(s/o)
  2698.     call    getpcur            ; get cursor position DX and type CX
  2699.     cmp    flags.vtflg,0        ; emulating anything?
  2700.     jne    scrin4            ; ne = yes
  2701.     mov    cursor,dx        ; use physical cursor
  2702. scrin4:    mov    dx,cursor        ; use old cursor, if any
  2703.     call    setpos            ; set cursor position
  2704.     cmp    vtinited,inited        ; inited emulator yet?
  2705.     je    scrin11            ; e = yes, do reinit
  2706.     call    fvtinit            ; init it now
  2707.     call    repaint            ; repaint screen
  2708.     ret
  2709.  
  2710. scrin11:
  2711. ifndef    no_graphics
  2712.     cmp    flags.vtflg,tttek    ; Tek mode?
  2713.     je    scrin12            ; e = yes
  2714.     test    tekflg,tek_tek+tek_dec     ; Tek submode?
  2715.     jz    scrin14            ; z = no
  2716. scrin12:call    tekini            ; init graphics mode
  2717.     ret
  2718. endif    ; no_graphics
  2719.  
  2720. scrin14:call    ansrei            ; reinit the emulator
  2721.     call    repaint            ; restore screen from vscreen
  2722. scrin15:ret
  2723. scrini    endp
  2724.  
  2725. chkwindows proc    near
  2726.     mov    inwindows,0        ; presume not in Windows
  2727.     mov    ax,sp            ; do push sp test for XT vs AT/386
  2728.     push    sp            ; XT pushes sp-2, AT's push old sp
  2729.     pop    cx            ; recover pushed value, clean stack
  2730.     xor    ax,cx            ; same?
  2731.     jne    chkwin2            ; ne = no, XT. Don't do Int 2fh
  2732.     mov    ax,1683h        ; Windows 3, get current virt machine
  2733.     int    2fh
  2734.     cmp    ax,1683h        ; virtual machine, if any
  2735.     je    chkwin2            ; e = none
  2736.     mov    inwindows,1        ; say in Windows
  2737. chkwin2:ret
  2738. chkwindows endp
  2739.  
  2740. ; Initialize terminal emulators
  2741. fvtinit    proc    far
  2742.     mov    ax,apcstring        ; seg of apcmacro memory area
  2743.     or    ax,ax            ; empty?
  2744.     jz    vtini4            ; z = yes
  2745.     mov    es,ax
  2746.     mov    ah,freemem
  2747.     int    dos            ; free that memory
  2748.     mov    apcstring,0
  2749. vtini4:    mov    holdscr,0        ; clear holdscreen
  2750.     mov    vtclear,0        ; clear clear-screen indicator
  2751.     mov    keypend,0        ; [HF]940207 clear double byte flag
  2752.     mov    keyj7st,0        ; [HF]940211 clear keyoutput status
  2753.     call    fkbhold            ; tell DEC LK250 the state, in msuibm
  2754.     or    vtinited,inited
  2755.     mov    dosetcursor,0        ; cursor position reminder, none
  2756.     mov    bx,portval
  2757.     mov    dl,[bx].ecoflg        ; local echo flag
  2758.     and    yflags,not lclecho
  2759.     or    yflags,dl
  2760.     mov    bx,argadr        ; address of argument block
  2761.     mov    dl,[bx].baudb        ; baud rate code in dl
  2762.     mov    dh,[bx].parity        ; parity code in bits
  2763.     mov    cl,4            ; 0-3 of dh
  2764.     shl    dh,cl
  2765.     or    dh,07H            ; just say 7 data bits
  2766.     test    flags.remflg,d8bit    ; eight bit display?
  2767.     jz    vtini1            ; z = no
  2768.     inc    dh            ; set low four bits to value 8
  2769. vtini1:    cmp    flags.vtflg,0        ; doing emulation?
  2770.     je    vtini3            ; e = no
  2771.     cmp    tekflg,tek_active+tek_tek ; Tek graphics mode?
  2772.     je    vtini2            ; e = yes, do it's reinit
  2773.     cmp    tekflg,tek_active+tek_dec ; Tek graphics submode?
  2774.     je    vtini2            ; e = yes, do it's reinit
  2775.     xor    ax,ax            ; assume 80 col mode (al=0)
  2776.     test    vtemu.vtflgst,deccol    ; want wide display?
  2777.     jz    vtini1a            ; z = no
  2778.     inc    al            ; set AL to 1 for set 132 col mode
  2779. vtini1a:call    chgdsp            ; set screen width
  2780.     call    ansini            ; call startup routine in mszibm
  2781.     cmp    flags.vtflg,tttek    ; full Tek mode?
  2782.     jne    vtinix            ; ne = no
  2783.     or    tekflg,tek_tek        ; say tek mode
  2784.     jmp    short vtini2        ; e = yes
  2785. vtinix:    clc
  2786.     ret
  2787. vtini2:
  2788. ifndef    no_graphics
  2789.     call    tekrint            ; reinitialize Tek emulator
  2790. endif    ; no_graphics
  2791.     clc
  2792.     ret
  2793. vtini3:    call    fcmblnk            ; clear the screen
  2794.     clc
  2795.     ret
  2796. fvtinit    endp
  2797.  
  2798. argini    proc    near            ; read passed arguments
  2799.     mov    bx,argadr        ; base of argument block
  2800.     mov    al,[bx].flgs        ; get flags
  2801.     and    al,capt+emheath+trnctl+lclecho+modoff
  2802.     mov    yflags,al        ; mask for allowable and save
  2803.     mov    al,[bx].prt
  2804.     mov    portno,al        ; update port number
  2805.     ret
  2806. argini    endp
  2807.  
  2808. fterm    proc    FAR            ; terminal mode entry point
  2809.     mov    argadr,ax        ; save argument ptr
  2810.     mov    oldsp,sp        ; remember stack for i/o failure,
  2811.     mov    apctrap,0        ; un-trap certain commands
  2812. ifndef    no_tcp
  2813.     cmp    flags.comflg,'t'    ; doing internal Telnet?
  2814.     jne    fterm2            ; ne = not Telnet
  2815.     cmp    termlatch,0        ; have we been here for macro?
  2816.     jne    fterm2            ; ne = yes, reset it and skip macro
  2817.     mov    termlatch,1        ; arm reentry bypass
  2818.     mov    bx,sescur        ; get session to bl
  2819.     call    vtsesmac        ; this returns us to the Kermit prompt
  2820.     jc    fterm2            ; c = no such macro
  2821. else
  2822.     jmp    short fterm2
  2823. endif    ; no_tcp
  2824. fterm1:    call    fserrst            ; shut down serial port now
  2825.     mov    kbdflg,'C'         ; say exit Connect mode
  2826.     ret                ; return, to process macro
  2827.  
  2828. fterm2:    mov    termlatch,0        ; disable bypass, enable macro again
  2829.     mov    handhsc,0        ; cancel hand scrolling
  2830.     call    vsbuff            ; allocate screen buffer memory
  2831.     jc    fterm1            ; c = failure, quit now
  2832.     mov    grab,0            ; clear Compose/Spcl output grabber
  2833.     call    argini            ; init options from arg address
  2834.     mov    inemulator,1        ; say in terminal emulator (local)
  2835.     call    scrini            ; call screen setup
  2836.     or    kbcodes,80h        ; set need-to-init flg for kbd xtlator
  2837.     mov    fairprn,0        ; set printer buffer flush counter
  2838. lp:    call    fprtchr            ; char at port?
  2839.     jnc    short lpinp        ; nc = yes, go handle
  2840. ifndef    no_graphics
  2841.     cmp    tekflg,tek_active+tek_sg ; special graphics active?
  2842.     jne    lpcross            ; ne = no, stay in idle loop
  2843.     mov    dx,dosetcursor        ; preserved cursor position
  2844.     cmp    dx,-1            ; should we set the cursor?
  2845.     je    lpcursor        ; e = no
  2846.     call    teksetcursor        ; set the cursor at dx
  2847.     mov    dosetcursor,-1        ; turn off reminder
  2848.  
  2849. lpcursor:test    flags.vtflg,ttd463+ttd470+ttd217 ; doing DG emulation?
  2850.     jz    lpcross            ; z = not DG
  2851.     cmp    dgcross,0        ; is DG crosshair active?
  2852.     je    lpcross            ; e = no
  2853.     xor    al,al            ; feed it a null command, to do mouse
  2854.     call    croshair        ; call Tek crosshair to read mouse
  2855. endif    ; no_graphics
  2856.  
  2857. lpcross:cmp    repflg,0        ; REPLAY?
  2858.     jne    lpkbd            ; ne = yes
  2859.     push    bx
  2860.     mov    bx,portval        ; port structure address
  2861.     cmp    [bx].portrdy,0        ; is port ready for business?
  2862.     pop    bx
  2863.     jne    lpkbd            ; ne = ready
  2864.     jmp    quit            ; end the communications now
  2865. lpkbd:    mov    fairness,0        ; say kbd was examined
  2866.     call    dvpause            ; tell DESQview we are not busy
  2867.     inc    fairprn            ; inc printer dump counter
  2868.     cmp    fairprn,100        ; been here enough times now?
  2869.     jb    lpkbd1            ; b = no
  2870.     call    fpntflsh        ; flush printer buffer
  2871.     jnc    lpkbd0            ; nc = success
  2872.     call    pntdead            ; call bad printer notifier
  2873. lpkbd0:    mov    fairprn,0        ; reset for next time
  2874. lpkbd1:    call    fkeybd            ; call keyboard translator in msu
  2875.     jc    quit            ; carry set = quit connect mode
  2876.     call    clkdsp            ; display clock
  2877.     jmp    short lp        ; and repeat idle loop
  2878.  
  2879. lpinp:    and    al,parmsk        ; apply 8/7 bit parity mask
  2880.     call    outtty            ; print on terminal
  2881.     inc    fairness        ; say read port but not kbd, again
  2882.     cmp    fairness,100        ; this many port reads before kbd?
  2883.     jb    lp            ; b = no, read port again
  2884.     jmp    short lpkbd        ; yes, let user have a chance too
  2885.  
  2886. quit:    mov    sp,oldsp        ; recover startup stack pointer
  2887.                     ; TERM caller's return address is now
  2888.                     ; on the top of stack. A longjmp.
  2889.     mov    ah,scbattr        ; current emulator attributes
  2890.     mov    savattr,ah        ; save them here
  2891.     call    fpntflsh        ; flush printer buffer
  2892. ifndef    no_graphics
  2893.     call    tekend            ; cleanup Tektronix mode
  2894. endif    ; no_graphics
  2895.     mov    inemulator,0        ; say not in terminal emulator (local)
  2896.     mov    al,1
  2897.     call    csrtype            ; turn on underline cursor
  2898.     mov    ah,dosattr        ; attributes at init time
  2899.     mov    scbattr,ah        ; background = original state
  2900.     call    fclrmod            ; clear mode line with DOS attributes
  2901.     mov    ax,100h            ; assume using 80 col screen
  2902.     cmp    dos_cols,80        ; startup screen width
  2903.     jbe    quit1            ; be = assume 80 columns
  2904.     inc    al            ; say do 132 columns
  2905. quit1:
  2906.     push    vtemu.vtflgop
  2907.     or    vtemu.vtflgop,vscompress ; turn off compressed mode
  2908.     call    chgdsp            ; reset display width to startup
  2909.     pop    vtemu.vtflgop
  2910.     call    scrmod            ; update size info
  2911.                     ; for ega in non-standard # lines
  2912.     test    tv_mode,10h        ; DV active?
  2913.     jnz    quit2            ; nz = yes, it messes with the cursor
  2914.     cmp    ega_mode,0        ; ega board active?
  2915.     je    quit2            ; e = no
  2916.     cmp    byte ptr low_rgt+1,23    ; is screen standard length?
  2917.     je    quit2            ; e = yes, so regular cursor set is ok
  2918.     cmp    byte ptr low_rgt+1,24    ; ANSI, is screen standard length?
  2919.     je    quit2            ; e = yes, so regular cursor set is ok
  2920.     push    es            ; turn off ega cursor emulation
  2921.     mov    ax,40h            ; byte 40:87H is ega Info byte
  2922.     mov    es,ax
  2923.     push    es:[87h]        ; save info byte around call
  2924.     or    byte ptr es:[87h],1    ; set emulation off (low bit = 1)
  2925.     mov    cx,lincur        ; cursor shape to set
  2926.     mov    ah,1            ; set the shape
  2927.     int    screen            ;   back to starting value
  2928.     pop    es:[87h]        ; recover original Info byte
  2929.     pop    es            ; and our work reg
  2930.     jmp    short quit3        ; skip regular mode cursor setting
  2931. quit2:                    ; for regular sized screen
  2932.     mov    cx,lincur        ; cursor type at startup
  2933.     mov    ah,1
  2934.     int    screen            ; restore cursor type
  2935. quit3:     mov    dh,byte ptr low_rgt+1    ; bottom line -1
  2936.     xor    dl,dl            ; left most column
  2937.     call    setpcur            ; set cursor physical position
  2938.     mov    al,yflags
  2939.     mov    bx,argadr
  2940.     mov    [bx].flgs,al        ; update flags in arg block
  2941.     call    dvpause            ; tell DESQview we are not busy
  2942.     cmp    isps55,0        ; [HF]940214 Japanese PS/55?
  2943.     je    quit4            ; [HF]940214 e = no
  2944.     cmp    ps55mod,0        ; [HF]940214 system modeline ?
  2945.     jne    quit4            ; [HF]940214 ne = no
  2946.     push    ax            ; [HF]940211
  2947.     push    dx            ; [HF]940211
  2948.     mov    ah,prstr        ; [HF]940211 we need newline for DOS
  2949.     mov    dx,offset crlf        ; [HF]940211
  2950.     int    dos            ; [HF]940211
  2951.     call    fctlu            ; [HF]940211 clear new line
  2952.     pop    dx            ; [HF]940211
  2953.     pop    ax            ; [HF]940211
  2954. quit4:    ret
  2955. fterm    endp
  2956.  
  2957. ; put the character in al to the screen
  2958. outtty    proc    near
  2959.     test    flags.remflg,d8bit    ; keep 8 bits for displays?
  2960.     jnz    outtt1            ; nz = yes, 8 bits if possible
  2961.     and    al,7fh            ; remove high bit
  2962. outtt1:    cmp    flags.vtflg,0        ; emulating a terminal?
  2963.     je    outnp10            ; e = no
  2964.     cmp    vtroll,0        ; auto roll back allowed?
  2965.     je    outem1            ; e = no, leave screen as is
  2966.     test    tekflg,tek_active    ; Tek mode active?
  2967.     jnz    outem1            ; nz = yes, skip screen rolling
  2968.     push    ax            ; (BDT) save this for a tad
  2969.     mov    ax,linec        ; (BDT) are we at the buffer end?
  2970.     cmp    ax,lcnt
  2971.     pop    ax            ; (BDT) restore the register
  2972.         je      outem1            ; (BDT) e = yes
  2973.     push    ax            ; (BDT) save AX again
  2974.     call    fendwnd            ; do END to roll screen to end of buf
  2975.     pop    ax            ; (BDT) restore the register
  2976. outem1:    test    tekflg,tek_active    ; graphics mode active?
  2977.     jz    outem2            ; z = no
  2978.     test    tekflg,tek_tek+tek_dec    ; Tek submode active for input?
  2979.     jnz    outem3            ; nz = yes, use Tek emulator
  2980. outem2:    call    anstty            ; call terminal emulator, char in AL
  2981.     ret
  2982. outem3:
  2983. ifndef    no_graphics
  2984.     call    tekemu            ; use Tek emulator and return
  2985. endif    ; no_graphics
  2986.     ret
  2987.                          ; use DOS for screen output
  2988. outnp10:test    flags.remflg,d8bit    ; keep 8 bits for displays?
  2989.     jnz    outnp9            ; nz = yes, 8 bits if possible
  2990.     and    al,7fh            ; remove high bit
  2991. outnp9:    cmp    rxtable+256,0        ; translation turned off?
  2992.     je    outnp7            ; e = yes, no translation
  2993.     push    bx
  2994.     mov    bx,offset rxtable    ; address of translate table
  2995.     xlatb                ; new char is in al
  2996.     pop    bx
  2997. outnp7:    test    anspflg,prtscr        ; should we be printing?
  2998.     jz    outnp8            ; no, keep going
  2999.     call    fpntchr            ; queue char for printer
  3000.     jnc    outnp8            ; nc = successful print
  3001.     push    ax
  3002.     call    vtbell            ; else make a noise and
  3003.     call    ftrnprs            ;  turn off printing
  3004.     pop    ax
  3005. outnp8:    test    yflags,capt        ; capturing output?
  3006.     jz    outnp6            ; no, forget this part
  3007.     call    fcptchr            ; give it captured character
  3008. outnp6:    test    yflags,trnctl        ; debug? if so use Bios tty mode
  3009.     jz    outnp4            ; z = no
  3010.     mov    ah,conout        ; DOS screen write
  3011.     cmp    al,7fh            ; Ascii Del char or greater?
  3012.     jb    outnp1            ; b = no
  3013.     je    outnp0            ; e = Del char
  3014.     push    ax            ; save the char
  3015.     mov    dl,7eh            ; output a tilde for 8th bit
  3016.     int    dos
  3017.     pop    ax            ; restore char
  3018.     and    al,7fh            ; strip high bit
  3019. outnp0:    cmp    al,7fh            ; is char now a DEL?
  3020.     jne    outnp1            ; ne = no
  3021.     and    al,3fH            ; strip next highest bit (Del --> '?')
  3022.     jmp    outnp2            ; send, preceded by caret
  3023. outnp1:    cmp    al,' '            ; control char?
  3024.     jae    outnp3            ; ae = no
  3025.     add    al,'A'-1        ; make visible
  3026. outnp2:    push    ax            ; save char
  3027.     mov    dl,5eh            ; caret
  3028.     int    dos            ; display it
  3029.     pop    ax            ; recover the non-printable char
  3030. outnp3:    push    ax
  3031.     mov    dl,al
  3032.     int    dos
  3033.     pop    ax
  3034.     ret
  3035. outnp4:    cmp    al,bell            ; bell (Control G)?
  3036.     jne    outnp5            ; ne = no
  3037.     jmp    vtbell            ; use short beep, avoid char loss
  3038. outnp5:    mov    dl,al            ; write without intervention
  3039.     mov    ah,conout
  3040.     int    dos            ; else let dos display char
  3041.     ret
  3042. outtty    endp
  3043.      
  3044. ;[IU2] Here to output an unsigned 8-bit number (in al) to the port
  3045. ; Used by terminal emulator escape sequence output.
  3046.      
  3047. prtnout proc    near
  3048.     jmp    short prtno2        ; ensure at least a zero
  3049.      
  3050. prtno1: or    al,al
  3051.     jnz    prtno2            ; nz = yes, do more digits
  3052.     ret                ; no, return from recursive call
  3053. prtno2: xor    ah,ah            ; clear previous remainder
  3054.     mov    bl,10            ; output in base 10
  3055.     div    bl            ; divide off a digit
  3056.     push    ax            ; push remainder (in ah) on stack
  3057.     call    prtno1            ; recurse
  3058.     pop    ax            ; pop off a digit
  3059.     add    ah,'0'            ; make it ASCII
  3060.     mov    al,ah            ; send to port, in ah
  3061.     call    outprt
  3062.     jc    prtno3            ; failure, end connection
  3063.     ret
  3064. prtno3:    jmp    far ptr endcon
  3065. prtnout endp
  3066.  
  3067. ; Send the character in al out to the serial port; handle echoing.
  3068. ; Can send an 8 bit char while displaying only 7 bits locally.
  3069. outprt    proc    near
  3070.     mov    ah,1            ; say local echo is permitted
  3071.     jmp    short outprt0
  3072.  
  3073. prtbout:xor    ah,ah            ; no local echo
  3074.  
  3075. outprt0:cmp    grab,0            ; grabbing output?
  3076.     je    outprt0a        ; e = no
  3077.     call    fgrabber        ; yes, give it to the guy
  3078.     ret
  3079. outprt0a:test    al,80h            ; high bit set?
  3080.     jz    outpr2            ; z = no
  3081.     test    flags.vtflg,ttd463+ttd470+ttd217 ; Data General?
  3082.     jz    outprt4            ; z = no
  3083.     test    flags.remflg,d8bit    ; chop DG high bit?
  3084.     jnz    outpr2            ; nz = no, send as-is
  3085.     and    al,7fh            ; chop high bit
  3086.     jmp    short outpr1        ; send with possible DG SI/SO brackets
  3087.  
  3088. outprt4:cmp    al,0a0h            ; C1 area?
  3089.     jae    outpr1            ; ae = no
  3090.     cmp    vtemu.vtchset,C_XPARENT    ; TRANSPARENT?
  3091.     je    outpr2            ; e = yes, pass as-is
  3092.     test    vtemu.vtflgop,vscntl    ; sending 8-bit controls?
  3093.     jz    outprt5            ; z = no, force use of 7-bit controls
  3094.     cmp    parmsk,7fh        ; using parity?
  3095.     jne    outpr2            ; ne = no, no need to force on that
  3096. outprt5:push    ax            ; save char
  3097.     mov    al,Escape        ; C1 as ESCAPE <char-40h>
  3098.     call    outpr2            ; send ESCAPE
  3099.     pop    ax            ; recover char
  3100.     sub    al,40h            ; relocate the code
  3101.     jmp    short outpr2        ; send the char
  3102.                     ; GRight printable characters
  3103. outpr1:    cmp    flags.vtflg,ttgenrc    ; doing term type of NONE?
  3104.     je    outpr2            ; e = yes, no tables (maybe SO/SI?)
  3105.     cmp    parmsk,7fh        ; using parity?
  3106.     jne    outpr2            ; ne = no, no shifts needed
  3107.     cmp    flags.oshift,0        ; allowing shifts on output?
  3108.     je    outpr2            ; e = no
  3109.     and    al,not 80h        ; strip high bit
  3110.     test    flags.oshift,8        ; Auto?
  3111.     jnz    outpr1a            ; nz = yes
  3112.     test    flags.oshift,1        ; force SI/SO?
  3113.     jnz    outpr8            ; nz = yes
  3114.     jmp    short outpr1b        ; else SS2/SS3
  3115. outpr1a:cmp    GRptr,offset G1set    ; GR points to G1 char set?
  3116.     je    outpr8            ; e = yes, use SO/char/SI
  3117. outpr1b:push    ax            ; save char
  3118.     mov    al,Escape        ; send SS2 as ESC N
  3119.     call    outpr2            ; ESC N is Single Shift 2
  3120.     mov    al,'N'
  3121.     cmp    flags.oshift,4        ; force SS3?
  3122.     jb    outpr7            ; b = force SS2
  3123.     je    outpr1c            ; e = force SS3
  3124.     cmp    GRptr,offset G2set    ; GR points to G2 char set?
  3125.     je    outpr7            ; e = yes, else use SS3 (ESC P)
  3126. outpr1c:inc    al            ; use ESC P for Single Shift 3
  3127. outpr7:    call    outpr2
  3128.     pop    ax            ; recover char
  3129.     jmp    short outpr2
  3130.  
  3131. outpr8:    push    ax            ; save char
  3132.     mov    al,SOchar        ; SO locking shift 1 for G1 to GL
  3133.     cmp    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  3134.     jz    outpr8a            ; z = no
  3135.     mov    al,DGescape        ; send SO as DG's  RS N
  3136.     call    outpr2
  3137.     mov    al,'N'
  3138. outpr8a:call    outpr2            ; send it
  3139.     pop    ax
  3140.     push    ax            ; preserve ah around call
  3141.     call    outpr2            ; send real character (7 bit'd)
  3142.     pop    ax
  3143.     mov    al,SIchar        ; shift back to normal
  3144.     test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  3145.     jz    outpr2            ; z = no
  3146.     mov    al,DGescape        ; send SI as DG's  RS O
  3147.     call    outpr2
  3148.     mov    al,'O'
  3149.  
  3150. outpr2:    or    ah,ah            ; local echo permitted?
  3151.     jz    outpr3            ; z = no
  3152.     test    yflags,lclecho        ; echoing ourselves?
  3153.     jz    outpr3            ; z = no, forget it
  3154.     push    ax            ; save char
  3155.     call    outtty            ; display it
  3156.     pop    ax            ; restore
  3157. ifndef    no_network
  3158.     cmp    al,CR            ; sending CR?
  3159.     jne    outpr3            ; ne = no
  3160.     cmp    flags.comflg,'t'    ; doing Telnet?
  3161.     jne    outpr3            ; ne = no
  3162. ifndef    no_tcp
  3163.     cmp    tcpnewline,1        ; newline mode is on?
  3164.     ja    outpr3            ; a = RAW, no extra LF
  3165.     je    outpr2a            ; e = yes, send CR/LF (else NVT/Bin)
  3166.     cmp    tcpmode,0        ; NVT-ASCII?
  3167.     jne    outpr3            ; ne = no, Binary so no extra LF
  3168. endif    ; no_tcp
  3169. outpr2a:push    ax
  3170.     mov    al,LF            ; locally show LF which we will send
  3171.     call    outtty
  3172.     pop    ax
  3173. endif    ; no_network
  3174. outpr3:    mov    ah,al            ; this is where outchr expects it
  3175.     call    foutchr            ; output to the port
  3176.     jc    outpr4            ; c = failure
  3177.     ret
  3178. outpr4:    jmp    far ptr endcon        ; failure, end connection
  3179. outprt    endp
  3180.  
  3181. fansdsl    proc    far
  3182.     call    ansdsl
  3183.     ret
  3184. fansdsl    endp
  3185.  
  3186. foutprt    proc    far
  3187.     call    outprt
  3188.     ret
  3189. foutprt    endp
  3190.  
  3191. ; keyboard handler verbs come here to sidestep transparent mode ALT-nnn
  3192. outprt_key proc far
  3193.     test    al,80h            ; high bit set?
  3194.     jz    outprt_key1        ; z = no, send as-is
  3195.     cmp    al,0a0h            ; C1 area?
  3196.     jae    outprt_key1        ; ae = no, send as-is
  3197.     cmp    vtemu.vtchset,C_XPARENT    ; TRANSPARENT?
  3198.     jne    outprt_key1        ; ne = no
  3199.     push    ax            ; 
  3200.     mov    al,Escape        ; C1 as ESCAPE <char-40h>
  3201.     call    outprt            ; send escape
  3202.     pop    ax
  3203.     sub    al,40h            ; relocate the code
  3204. outprt_key1:
  3205.     call    outprt
  3206.     ret
  3207. outprt_key endp
  3208.  
  3209. fprtbout proc    far
  3210.     call    prtbout
  3211.     ret
  3212. fprtbout endp
  3213.  
  3214. fprtnout proc    far
  3215.     call    prtnout
  3216.     ret
  3217. fprtnout endp
  3218.  
  3219. ; Product macro worker
  3220. prodwork proc    far
  3221.     push    si
  3222.     push    di
  3223.     push    es
  3224.     mov    ax,ds
  3225.     mov    es,ax
  3226.     mov    di,offset decbuf+2    ; macro def buffer starts here
  3227.     mov    si,offset prodname    ; pointer to macro name
  3228.     mov    cx,vtplen        ; length of macro name
  3229.     cld
  3230.     rep    movsb            ; copy to rdbuf+2
  3231.     mov    byte ptr [di],0        ; null terminator
  3232.     mov    cx,nparam        ; number of parameters
  3233.     cmp    cx,9            ; more than 9?
  3234.     jle    produc1            ; le = no
  3235.     mov    cx,9            ; limit to 9
  3236. produc1:jcxz    produc3            ; z = none
  3237.     xor    bx,bx            ; parameter subscript
  3238. produc2:push    bx
  3239.     push    cx
  3240.     mov    al,' '            ; and a space separator
  3241.     stosb
  3242.     shl    bx,1            ; address words
  3243.     mov    ax,param[bx]        ; get parameter to use as definition
  3244.     call    dec2di            ; convert numerics to ascii string
  3245.     pop    cx
  3246.     pop    bx
  3247.     inc    bx
  3248.     loop    produc2
  3249. produc3:xor    al,al            ; safety terminator
  3250.     mov    [di],al            ; don't count in length
  3251.     mov    ax,di
  3252.     sub    ax,offset decbuf + 2    ; compute length
  3253.     mov    vtmaclen,ax        ; pass along to vtmacro
  3254.     mov    vtmacname,offset decbuf+2 ; say this is our macro text ptr
  3255.     pop    si
  3256.     pop    di
  3257.     pop    es
  3258.     jmp    short vtmacro
  3259. prodwork endp
  3260.  
  3261. ;
  3262. ; Reference    Macro structure for    db    number of entries (mac names)
  3263. ;  is file     table mcctab       |->    dw    length of macroname
  3264. ;  mssset.asm        each entry |->     db    'macroname'
  3265. ;  where these               |->    dw    segment:0 of definition string
  3266. ;  are stored.                      (offset part is always 0)    
  3267. ;        Definition string in     db    length of <string with null>
  3268. ;         buffer macbuf          db    'string with trailing null'
  3269. ;
  3270. vtmacro    proc    far            ; common code for macros vtsmac,vtrmac
  3271.     push    bx            ; and Product
  3272.     push    cx
  3273.     push    si
  3274.     push    di
  3275.     push    es
  3276.     mov    ax,ds
  3277.     mov    es,ax
  3278.     mov    di,offset decbuf+2    ; macro def buffer starts here
  3279.     mov    si,vtmacname        ; pointer to macro name
  3280.     mov    cx,vtmaclen        ; length of macro name<sp/null>text
  3281.     mov    [di-2],cx        ; counted string field
  3282.     cld
  3283.     rep    movsb            ; copy to rdbuf
  3284.     mov    byte ptr [di],0        ; null terminator
  3285.     mov    si,offset decbuf+2    ; look for name-text separator
  3286.     mov    cx,vtmaclen
  3287. vtmac1:    lodsb
  3288.     cmp    al,' '            ; space separator?
  3289.     je    vtmac1a            ; e = yes, stop here
  3290.     or    al,al            ; null terminator?
  3291.     jz    vtmac1a            ; e = yes, stop here
  3292.     loop    vtmac1
  3293.     inc    si            ; to do null length correctly
  3294. vtmac1a:sub    si,offset decbuf+2+1    ; compute length of macro name
  3295.     mov    cx,si
  3296.     mov    vtmaclen,cx        ; save a macro name length
  3297.                     ; check for existence of macro
  3298.     mov    bx,offset mcctab    ; table of macro names
  3299.     mov    cl,[bx]            ; number of names in table
  3300.     xor    ch,ch
  3301.     jcxz    vtmacx            ; z = empty table, do nothing
  3302.     inc    bx            ; point to length of first name
  3303. vtmac2:    mov    ax,[bx]            ; length of this name
  3304.     cmp    ax,vtmaclen        ; length same as desired keyword?
  3305.     jne    vtmac3            ; ne = no, search again
  3306.     mov    si,bx
  3307.     add    si,2            ; point at first char of name
  3308.     push    cx            ; save name counter
  3309.     push    di            ; save reg
  3310.     mov    cx,vtmaclen        ; length of name
  3311.     mov    di,vtmacname        ; point at desired macro name
  3312.     push    es            ; save reg
  3313.     push    ds
  3314.     pop    es            ; make es use data segment
  3315.     cld
  3316.     repe    cmpsb            ; match strings
  3317.     pop    es            ; need current si below
  3318.     pop    di            ; recover saved regs
  3319.     pop    cx
  3320.     je    vtmac4            ; e = matched
  3321. vtmac3:    add    bx,ax            ; step to next name, add name length
  3322.     add    bx,4            ; + count and def word ptr
  3323.     loop    vtmac2            ; try next name
  3324. vtmacx:    pop    es
  3325.     pop    di
  3326.     pop    si            ; no macro, return to Connect mode
  3327.     pop    cx
  3328.     pop    bx
  3329.     stc                ; say failure
  3330.     ret
  3331.  
  3332. vtmac4:    call    takopen_macro        ; open a macro
  3333.     mov    bx,takadr        ; point to current macro structure
  3334.     mov    ax,ds            ; segment of rdbuf
  3335.     mov    [bx].takbuf,ax        ; segment of definition string struc
  3336.     mov    cx,word ptr decbuf    ; length of count + string
  3337.     mov    [bx].takcnt,cx        ; number of chars in definition
  3338.     mov    [bx].takargc,0        ; our argument count
  3339.     mov    [bx].takptr,offset decbuf+2 ; where to read next command char
  3340.     pop    es
  3341.     pop    di
  3342.     pop    si
  3343.     pop    cx
  3344.     pop    bx
  3345.     clc                ; say success, can exit connect mode
  3346.     ret
  3347. vtmacro    endp
  3348.  
  3349. ; APC macro. Macro string (word count, string text) preset by mszibm.asm
  3350. ; into seg apcstring offset 0.
  3351. apcmacro proc    near
  3352.     cmp    taklev,maxtak        ; room in take level?
  3353.     jb    apcmac1            ; b = yes
  3354.     stc                ; fail
  3355.     ret
  3356. apcmac1:call    takopen_macro        ; open macro
  3357.     mov    bx,takadr        ; point to current macro structure
  3358.     mov    ax,apcstring        ; segment of buffer
  3359.     mov    [bx].takbuf,ax        ; segment of definition string struc
  3360.     mov    [bx].takcnt,cx        ; number of chars in definition
  3361.     or    [bx].takattr,take_malloc; say have buffer to be removed
  3362.     cmp    apcenable,2        ; enable all commands?
  3363.     je    apcmac2            ; e = yes
  3364.     mov    apctrap,1        ; trap certain commands
  3365. apcmac2:mov    apcstring,0        ; takclos will delete the buffer
  3366.     jmp    far ptr endcon        ; exit Connect mode cleanly
  3367. apcmacro endp
  3368.  
  3369. rcvmacro proc near
  3370.     call    takopen_macro        ; open macro
  3371.     mov    bx,takadr        ; point to current macro structure
  3372.     mov    ax,seg rcvstring    ; segment of buffer
  3373.     mov    [bx].takbuf,ax        ; segment of definition string struc
  3374.     mov    [bx].takptr,offset rcvstring+2
  3375.     mov    [bx].takcnt,rcvstring_len ; number of chars in definition
  3376.     mov    termserver,1        ; say Connect mode started receive
  3377.     jmp    far ptr endcon        ; exit Connect mode cleanly
  3378. rcvmacro endp
  3379.  
  3380. srvmacro proc near
  3381.     call    takopen_macro        ; open macro
  3382.     mov    bx,takadr        ; point to current macro structure
  3383.     mov    ax,seg srvstring    ; segment of buffer
  3384.     mov    [bx].takbuf,ax        ; segment of definition string struc
  3385.     mov    [bx].takptr,offset srvstring+2
  3386.     mov    [bx].takcnt,srvstring_len ; number of chars in definition
  3387.     mov    termserver,1        ; say Connect mode started server
  3388.     jmp    far ptr endcon        ; exit Connect mode cleanly
  3389. srvmacro endp
  3390.  
  3391. ; Error recovery routine used when outchr reports unable to send character
  3392. ;  or when vtmacro requests exiting Connect mode.
  3393. ; Exit Connect mode cleanly, despite layers of intermediate calls.
  3394. endcon    proc    FAR
  3395.     mov    kbdflg,'C'        ; report 'C' to TERM's caller
  3396.     mov    sp,oldsp        ; recover startup stack pointer
  3397.                     ; TERM caller's return address is now
  3398.                     ; on the top of stack. A longjmp.
  3399.     jmp    quit            ; exit Connect mode cleanly
  3400. endcon    endp
  3401.  
  3402. tabcpy    proc    far
  3403.     push    es            ; worker copy routine
  3404.     push    si
  3405.     push    di
  3406.     mov    cx,ds
  3407.     mov    es,cx
  3408.     mov    cx,(vswidth+7)/8    ; update all active tab stops
  3409.     cld
  3410.     rep    movsb
  3411.     pop    di
  3412.     pop    si
  3413.     pop    es
  3414.     clc                ; success
  3415.     ret
  3416. tabcpy    endp
  3417.  
  3418. ifndef    no_terminal
  3419.  
  3420. ; Issue warning that CP866 is needed but not loaded for Cyrillic char sets
  3421. chkcp866 proc    far
  3422.     cmp    bl,C_CYRILLIC_ISO    ; these Cyrillic character sets?
  3423.     je    chkcp1            ; e = yes
  3424.     cmp    bl,C_KOI8
  3425.     je    chkcp1
  3426.     cmp    bl,C_SHORT_KOI
  3427.     je    chkcp1
  3428.     ret
  3429. chkcp1:    cmp    vtcpage,866            ; Code Page is CP866?
  3430.     je    chkcp2                ; e = yes, no warning
  3431.     push    ax
  3432.     push    dx
  3433.     mov    ah,prstr
  3434.     mov    dx,offset cpwarn        ; issue warning
  3435.     int    dos
  3436.     pop    dx
  3437.     pop    ax
  3438. chkcp2:    ret
  3439. chkcp866 endp
  3440. endif    ; no_terminal
  3441.  
  3442. ; Display HHMM on status line over the led dots
  3443. clkdsp    proc    far
  3444.     cmp    inemulator,0        ; in terminal emulator?
  3445.     je    clkdsp1            ; e = no, no mode line
  3446.     cmp    vtclkflg,0        ; do not use clock
  3447.     je    clkdsp1            ; e = correct, no clock
  3448.     cmp    inwindows,0        ; in Windows?
  3449. ;;;    jne    clkdsp1            ; ne = yes, no clock
  3450.     cmp    flags.modflg,1        ; mode line enabled and owned by us?
  3451.     jne    clkdsp1            ; ne = no, don't touch it
  3452.     test    flags.vtflg,tttek    ; Tek mode?
  3453.     jnz    clkdsp1            ; nz = yes
  3454.     test    tekflg,tek_dec        ; in Tek submode?
  3455.     jnz    clkdsp1            ; nz = yes, no mode line changes
  3456.     test    yflags,modoff        ; mode line off?
  3457.     jnz    clkdsp1            ; nz = yes
  3458.     cmp    flags.vtflg,0        ; emulating none?
  3459.     jne    clkdsp2            ; ne = no
  3460. clkdsp1:ret
  3461. clkdsp2:push    ax
  3462.     push    bx
  3463.     push    cx
  3464.     push    dx
  3465.     push    es
  3466.     call    cboff            ; turn off Control-Break sensing
  3467.     mov    ah,gettim        ; read DOS tod clock
  3468.     int    dos            ; ch=hours, cl=minutes, dh=seconds
  3469.     cmp    dh,lastsec        ; compare with previous call
  3470.     mov    lastsec,dh        ; remember last sec
  3471.     je    clkdsp9            ; e = same, do nothing
  3472.     cmp    vtclkflg,1        ; do regular time of day?
  3473.     je    clkdsp6            ; e = yes
  3474.     mov    al,60
  3475.     mul    ch            ; hours to minutes in ax
  3476.     add    al,cl            ; plus minutes
  3477.     adc    ah,0
  3478.     mov    bl,dh            ; save seconds in bx
  3479.     xor    bh,bh
  3480.     mov    cx,60
  3481.     mul    cx            ; hh+mm to seconds in dx:ax
  3482.     add    ax,bx            ; plus seconds
  3483.     adc    dx,0            ; total seconds in dx:ax
  3484.  
  3485.     mov    bx,portval
  3486. ifndef    no_tcp
  3487.     cmp    flags.comflg,'t'    ; doing TCP/IP Telnet?
  3488.     je    clkdsp4            ; e = yes
  3489. endif    ; no_tcp
  3490.     sub    ax,word ptr starttime[bx]
  3491.     sbb    dx,word ptr starttime[bx+2]
  3492.     jns    clkdsp5            ; ns = not wrapped
  3493.     add    ax,20864        ; add one day
  3494.     adc    dx,1            ; of 86400 seconds
  3495.     jmp    short clkdsp5
  3496. clkdsp4:
  3497. ifndef no_tcp
  3498.     mov    bx,sescur        ; current session ident
  3499.     shl    bx,1
  3500.     shl    bx,1            ; quad bytes
  3501.     sub    ax,word ptr sestime[bx]
  3502.     sbb    dx,word ptr sestime[bx+2]
  3503.     jns    clkdsp5            ; ns = not wrapped
  3504.     add    ax,20864        ; add one day
  3505.     adc    dx,1            ; of 86400 seconds
  3506. endif    ; no_tcp
  3507. clkdsp5:mov    cx,60*60        ; convert seconds back to ch,cl,dh
  3508.     div    cx            ; ax = quo = hours, dx = rem = secs
  3509.     mov    ch,al            ; ch has hours
  3510.     mov    ax,dx            ; remaining seconds to ax
  3511.     mov    cl,60
  3512.     div    cl            ; al = quo = minutes, ah = secs
  3513.     mov    cl,al            ; minutes
  3514.     xchg    dh,ah            ; seconds to dh
  3515.  
  3516. clkdsp6:mov    ax,tv_segs        ; screen segment
  3517.     mov    es,ax
  3518.     mov    al,crt_cols        ; typically 80
  3519.     mul    crt_lins        ; typically 24
  3520.     mov    bx,65+6            ; led_col from mszibm.asm, dots
  3521.     sub    bl,handhsc        ; minus hand scrolling left
  3522.     sbb    bh,0
  3523.     jc    clkdsp4            ; c = off screen
  3524.     add    ax,bx
  3525.     shl    ax,1            ; char cells
  3526.     mov    bx,ax
  3527.  
  3528.     mov    al,ch            ; hours
  3529.     xor    ah,ah
  3530.     div    ten            ; al = quo, ah=rem
  3531.     add    ax,'00'
  3532.     mov    es:[bx],al
  3533.     mov    es:[bx+2],ah
  3534.     mov    es:[bx+4],al
  3535.     mov    al,' '
  3536.     test    dh,1            ; odd seconds?
  3537.     jnz    clkdsp8            ; nz = yes, show blank
  3538.     mov    al,':'            ; show colon
  3539. clkdsp8:mov    es:[bx+4],al
  3540.     mov    al,cl
  3541.     xor    ah,ah
  3542.     div    ten            ; quo = al, rem = ah
  3543.     add    ax,'00'
  3544.     mov    es:[bx+6],al
  3545.     mov    es:[bx+8],ah
  3546.     push    di
  3547.     mov    di,bx            ; es:di is start address
  3548.     add    di,9            ; is now ending address
  3549.     mov    cx,5            ; bytes changed
  3550.     call    scrsync            ; sync virtual screen
  3551.     pop    di
  3552. clkdsp9:call    cbrestore        ; restore Control-Break sensing
  3553.     pop    es
  3554.     pop    dx
  3555.     pop    cx
  3556.     pop    bx
  3557.     pop    ax
  3558.     ret
  3559. clkdsp    endp
  3560. code1    ends
  3561.  
  3562. code    segment
  3563.     assume    cs:code
  3564. ;;; Action routines (verbs) for keyboard translator KEYBD in msuibm.
  3565. ; These are invoked by a jump instruction. Return carry clear for normal
  3566. ; processing, return carry set for invoking Quit (kbdflg has transfer char).
  3567. uparrw:    mov    al,'A'            ; cursor keys
  3568.     jmp    short comarr
  3569. dnarrw:    mov    al,'B'
  3570.     jmp    short comarr
  3571. rtarr:    mov    al,'C'
  3572.     test    vtemu.vtflgop,vswdir    ; writing left to right?
  3573.     jz    comarr            ; z = yes
  3574.     mov    al,'D'            ; reverse sense of keys
  3575.     jmp    short comarr
  3576. lfarr:    mov    al,'D'
  3577.     test    vtemu.vtflgop,vswdir    ; writing left to right?
  3578.     jz    comarr            ; z = yes
  3579.     mov    al,'C'            ; reverse sense of keys
  3580.  
  3581. comarr:    test    flags.vtflg,ttwyse    ; Wyse-50?
  3582.     jnz    comar7            ; nz = yes
  3583.     test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  3584.     jz    comar4            ; z = no
  3585.     cmp    dgd470mode,0        ; in D470 ANSI mode?
  3586.     je    comar6            ; e = no
  3587.     push    ax            ; these send ESC [ <letter>
  3588.     mov    al,escape
  3589.     call    foutprt
  3590.     mov    al,'['
  3591.     call     foutprt            ; pop ax is done by comar3
  3592.     jmp    short comar3        ; send the letter
  3593. comar6:    sub    al,'A'            ; translate to DG 463/470/217 form
  3594. ifndef    no_graphics
  3595.     cmp    tekflg,tek_active+tek_sg ; in special graphics mode?
  3596.     jne    comar5            ; ne = no
  3597.     test    dgcross,1        ; DG crosshair active?
  3598.     jz    comar5            ; z = no
  3599.     test    dgcross,2        ; DG crosshair active for keypad?
  3600.     jz    comar5            ; z = no
  3601.     mov    bx,offset dgcrostab    ; use scan code table instead
  3602.     xlatb
  3603.     call    croshair        ; send AL to graphics to move cursor
  3604.     ret
  3605. endif    ; no_graphics
  3606.  
  3607. comar5:    mov    bx,offset dgcurtab    ; VT to DG cursor code table
  3608.     xlatb
  3609.     push    ax            ; setup for comar3
  3610.     jmp    short comar3
  3611.  
  3612. comar7:    mov    bx,offset wysecurtab    ; VT to Wyse-50 code table
  3613.     sub    al,'A'            ; remove bias
  3614.     xlatb
  3615.     push    ax
  3616.     jmp    short comar3
  3617.  
  3618. comar4:    push    ax            ; save final char
  3619.     mov    ttyact,0        ; network, group chars for packet
  3620.     mov    al,Escape        ; send the ESC
  3621.     test    vtemu.vtflgop,decanm    ; ANSI mode?
  3622.     jz    comar1            ; z = no
  3623.     mov    al,CSI            ; CSI character
  3624.     test    vtemu.vtflgop,decckm    ; cursor keys in application mode?
  3625.     jz    comar1            ; z = no, in cursor mode
  3626.     mov    al,SS3            ; SS3 character
  3627. comar1:    call    outprt_key        ; send in 7 or 8 bit form, with echo
  3628. comar3: pop    ax            ; recover final char
  3629.     mov    ttyact,1        ; network, restore tty active flag
  3630.     call    foutprt
  3631.     ret
  3632.  
  3633. pf1:    mov    al,'P'            ; keypad function keys PF1-4
  3634.     jmp    short compf
  3635. pf2:    mov    al,'Q'
  3636.     jmp    short compf
  3637. pf3:    mov    al,'R'
  3638.     jmp    short compf
  3639. pf4:    mov    al,'S'
  3640. compf:    push    ax            ; save final char
  3641.     mov    ttyact,0        ; network, group chars for packet
  3642.     mov    al,Escape        ; send the ESC
  3643.     test    vtemu.vtflgop,decanm    ; ansi mode?
  3644.     jz    short compf2        ; z = no
  3645.     mov    al,SS3             ; SS3, ESC O
  3646. compf2:    call    outprt_key        ; send 7 or 8 bit version
  3647. compf1: pop    ax            ; get the saved char
  3648.     mov    ttyact,1        ; network, restore tty active flag
  3649.     call    foutprt
  3650.     ret
  3651.  
  3652. ignore_key:                ; key is to be ignored
  3653.     ret
  3654.  
  3655. kp0:    mov    al,'p'            ; keypad numeric keys
  3656.     jmp    short comkp
  3657. kp1:    mov    al,'q'
  3658.     jmp    short comkp
  3659. kp2:    mov    al,'r'
  3660.     jmp    short comkp
  3661. kp3:    mov    al,'s'
  3662.     jmp    short comkp
  3663. kp4:    mov    al,'t'
  3664.     jmp    short comkp
  3665. kp5:    mov    al,'u'
  3666.     jmp    short comkp
  3667. kp6:    mov    al,'v'
  3668.     jmp    short comkp
  3669. kp7:    mov    al,'w'
  3670.     jmp    short comkp
  3671. kp8:    mov    al,'x'
  3672.     jmp    short comkp
  3673. kp9:    mov    al,'y'
  3674.     jmp    short comkp
  3675. kpminus:mov    al,'m'
  3676.     jmp    short comkp
  3677. kpcoma:    mov    al,'l'
  3678.     jmp    short comkp
  3679. kpenter:mov    al,'M'
  3680.     jmp    short comkp
  3681. kpdot:    mov    al,'n'
  3682. comkp:    test    vtemu.vtflgop,deckpam    ; keypad application mode active?
  3683.     jnz    comkp1            ; nz = yes, use escape sequences
  3684.     sub    al,40h            ; deduct offset to numeric symbols
  3685.     push    ax            ; save final char
  3686.     jmp    short comkp3        ; and send that single char
  3687. comkp1:    push    ax
  3688.     mov    ttyact,0        ; network, group chars for packet
  3689.     test    vtemu.vtflgop,decanm    ; ANSI mode?
  3690.     jz    comkp2            ; z = no
  3691.     mov    al,SS3            ; SS3 character
  3692.     call    outprt_key        ; send 7 or 8 bit version
  3693.     jmp    short comkp3
  3694. comkp2:    mov    al,escape        ; output "ESC ?"
  3695.     call    foutprt
  3696.     mov    al,'?'
  3697.     call    foutprt
  3698. comkp3:    pop    ax            ; recover final char
  3699.     mov    ttyact,1        ; network, restore tty active flag
  3700.     call    foutprt            ; send it
  3701.     ret
  3702.  
  3703. klogon    proc    near            ; resume logging (if any)
  3704.     test    flags.capflg,logses    ; session logging enabled?
  3705.     jz    klogn            ; z = no, forget it
  3706.     push    bx
  3707.     mov    bx,argadr
  3708.     or    [bx].flgs,capt        ; turn on capture flag
  3709.     pop    bx
  3710.     or    yflags,capt        ; set local msy flag as well
  3711. klogn:    clc
  3712.     ret
  3713. klogon    endp
  3714.  
  3715. klogof    proc    near            ; suspend logging (if any)
  3716.     push    bx
  3717.     mov    bx,argadr
  3718.     and    [bx].flgs,not capt    ; stop capturing
  3719.     pop    bx
  3720.     and    yflags,not capt        ; reset local msy flag as well
  3721.     clc
  3722.     ret
  3723. klogof    endp
  3724.  
  3725. kdebug    proc    near
  3726.     xor    flags.debug,logses    ; toggle debugging
  3727.     xor    yflags,trnctl        ; Debug mode local edition
  3728.     ret
  3729. kdebug    endp
  3730.  
  3731. snull    proc    near            ; send a null byte
  3732.     xor    al,al            ; the null
  3733.     call    fprtbout        ; send without logging and local echo
  3734.     ret
  3735. snull    endp
  3736.  
  3737. khold:    xor    holdscr,1        ; toggle Hold screen byte for msx
  3738.     call    kbhold            ; tell DEC LK250 the hold kbd state
  3739.     clc                ;  kbhold is in file msuibm.asm
  3740.     ret
  3741.  
  3742. tn_AYT:    mov    ah,255            ; 'I' Telnet Are You There
  3743.     call    outchr            ; send IAC (255) AYT (246)
  3744.     mov    ah,246
  3745.     call    outchr
  3746.     clc
  3747.     ret
  3748.  
  3749. tn_IP:    mov    ah,255            ; 'I' Telnet Interrrupt Process
  3750.     call    outchr            ; send IAC (255) IP (244)
  3751.     mov    ah,244
  3752.     call    outchr
  3753.     clc
  3754.     ret
  3755.  
  3756. ; Data General "Fn" function keys
  3757. dgkf1:    mov    al,113            ; F1 sends RS q
  3758.     jmp    dgkeyccom
  3759. dgkf2:    mov    al,114            ; F2 sends RS r
  3760.     jmp    dgkeyccom
  3761. dgkf3:    mov    al,115            ; F3 sends RS s
  3762.     jmp    dgkeyccom
  3763. dgkf4:    mov    al,116            ; F4 sends RS t
  3764.     jmp    short dgkeyccom
  3765. dgkf5:    mov    al,117            ; F5 sends RS u
  3766.     jmp    short dgkeyccom
  3767. dgkf6:    mov    al,118            ; F6 sends RS v
  3768.     jmp    short dgkeyccom
  3769. dgkf7:    mov    al,119            ; F7 sends RS w
  3770.     jmp    short dgkeyccom
  3771. dgkf8:    mov    al,120            ; F8 sends RS x
  3772.     jmp    short dgkeyccom
  3773. dgkf9:    mov    al,121            ; F9 sends RS y
  3774.     jmp    short dgkeyccom
  3775. dgkf10:    mov    al,122            ; F10 sends RS z
  3776.     jmp    short dgkeyccom
  3777. dgkf11:    mov    al,123            ; F11 sends RS {
  3778.     jmp    short dgkeyccom
  3779. dgkf12:    mov    al,124            ; F12 sends RS |
  3780.     jmp    short dgkeyccom
  3781. dgkf13:    mov    al,125            ; F13 sends RS }
  3782.     jmp    short dgkeyccom
  3783. dgkf14:    mov    al,126            ; F14 sends RS ~
  3784.     jmp    short dgkeyccom
  3785. dgkf15:    mov    al,112            ; F15 sends RS p
  3786.     jmp    short dgkeyccom
  3787. dgkSf1:    mov    al,'a'            ; SF1 sends RS a
  3788.     jmp    short dgkeyccom
  3789. dgkSf2:    mov    al,'b'            ; SF2 sends RS b
  3790.     jmp    short dgkeyccom
  3791. dgkSf3:    mov    al,'c'            ; SF3 sends RS c
  3792.     jmp    short dgkeyccom
  3793. dgkSf4:    mov    al,'d'            ; SF4 sends RS d
  3794.     jmp    short dgkeyccom
  3795. dgkSf5:    mov    al,'e'            ; SF5 sends RS e
  3796.     jmp    short dgkeyccom
  3797. dgkSf6:    mov    al,'f'            ; SF6 sends RS f
  3798.     jmp    short dgkeyccom
  3799. dgkSf7:    mov    al,'g'            ; SF7 sends RS g
  3800.     jmp    short dgkeyccom
  3801. dgkSf8:    mov    al,'h'            ; SF8 sends RS h
  3802.     jmp    short dgkeyccom
  3803. dgkSf9:    mov    al,'i'            ; SF9 sends RS i
  3804.     jmp    short dgkeyccom
  3805. dgkSf10:mov    al,'j'            ; SF10 sends RS j
  3806.     jmp    short dgkeyccom
  3807. dgkSf11:mov    al,'k'            ; SF11 sends RS k
  3808.     jmp    short dgkeyccom
  3809. dgkSf12:mov    al,'l'            ; SF12 sends RS l
  3810.     jmp    short dgkeyccom
  3811. dgkSf13:mov    al,'m'            ; SF13 sends RS m
  3812.     jmp    short dgkeyccom
  3813. dgkSf14:mov    al,'n'            ; SF14 sends RS n
  3814.     jmp    short dgkeyccom
  3815. dgkSf15:mov    al,'`'            ; SF15 sends RS `
  3816.     jmp    short dgkeyccom
  3817.  
  3818.  
  3819. ; Data General "C" keys C1..C4
  3820. dgkc1:    mov    al,92            ; C1 sends RS \
  3821.     jmp    short dgkc5
  3822. dgkc2:    mov    al,93            ; C2 sends RS ]
  3823.     jmp    short dgkc5
  3824. dgkc3:    mov    al,95            ; C3 sends RS ^
  3825.     jmp    short dgkc5
  3826. dgkc4:    mov    al,96            ; C4 sends RS _
  3827. dgkc5:    cmp    dgd470mode,0        ; D470 ANSI mode active?
  3828.     je    dgkeyccom        ; e = no
  3829.     add    al,40            ; yes, bias, C1=132 et seq
  3830. dgkeyccom:                ; common code
  3831.     mov    ttyact,0        ; network, group chars for packet
  3832.     push    ax
  3833.     cmp    dgd470mode,0        ; D470 ANSI mode active?
  3834.     je    dgkeyccom1        ; e = no
  3835.     mov    al,ESCAPE        ; send ESC [ 0<high><low> z
  3836.     call    fprtbout
  3837.     mov    al,'['
  3838.     call    fprtbout
  3839.     mov    al,'0'            ; first byte, always "0"
  3840.     call    fprtbout
  3841.     pop    ax
  3842.     sub    al,112            ; remove bias (to 0..23)
  3843.     mov    cl,10            ; split into two bytes
  3844.     xor    ah,ah
  3845.     div    cl            ; al = quotient, ah = remainder
  3846.     push    ax            ; save remainder
  3847.     add    al,'0'            ; send high part (0..2)
  3848.     call    fprtbout
  3849.     pop    ax
  3850.     xchg    ah,al
  3851.     add    al,'0'            ; send low part (0..9)
  3852.     call    fprtbout
  3853.     mov    al,'z'            ; terminator
  3854.     mov    ttyact,1        ; network, restore tty active flag
  3855.     ret
  3856.  
  3857. dgkeyccom1:mov    al,DGescape        ; send DG escape (RS)
  3858.     call    fprtbout        ; with no echo
  3859.     pop    ax
  3860.     mov    ttyact,1        ; network, restore tty active flag
  3861.     call    fprtbout        ; send the second byte
  3862.     ret
  3863.  
  3864. ; Keyboard "Compose" key to compose characters by the three stroke method
  3865. kbdcompose proc    near
  3866.     mov    grab,1            ; say grabbing normal output
  3867.     call    togmod
  3868.     call    togmod            ; update mode line
  3869.     ret
  3870. kbdcompose endp
  3871.  
  3872. ; DG POINT (aka CMD CURSOR-TYPE)
  3873. dgpoint    proc    near
  3874. ifndef    no_graphics
  3875.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  3876.     jne    dgpoint1        ; ne = no, ignore cmd
  3877.     call    dgcrossrpt        ; send crosshair report
  3878. endif    ; no_graphics
  3879. dgpoint1:ret
  3880. dgpoint    endp
  3881.  
  3882. ; DG N/C (normal, compressed font) key
  3883. dgnckey proc    near
  3884.     test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  3885.     jz    dgnckey1        ; z = no, ignore
  3886.     call    dgnctoggle        ; toggle normal/compressed mode
  3887. dgnckey1:clc
  3888.     ret
  3889. dgnckey endp
  3890.  
  3891. ; Compose char lookup and reemitter.
  3892. fgrabber proc    far
  3893.     push    bx
  3894.     mov    bx,grab            ; count chars grabbed (want two)
  3895.     dec    bx            ; first char becomes bx=0
  3896.     mov    grabbox[bx],al        ; stuff char in short buffer
  3897.     cmp    bx,1            ; got both chars?
  3898.     pop    bx
  3899.     jae    fgrab2            ; ae = yes, go produce output
  3900.     inc    grab            ; keep grabbing
  3901.     ret                ; return for the second
  3902.                     ; process the byte pair
  3903. fgrab2:    mov    grab,0            ; say done grabbing output
  3904.     push    dx            ; compose new single char result
  3905.     push    di
  3906.     push    es
  3907.     mov    di,seg data1
  3908.     mov    es,di
  3909.     mov    di,offset grl1lat    ; use Latin1 ptr
  3910.     cmp    vtcpage,852        ; CP852?
  3911.     jne    fgrab2a            ; ne = no
  3912.     mov    di,offset grl1lat2    ; use Latin 2
  3913. fgrab2a:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  3914.     jz    fgrab3            ; z = no
  3915.     cmp    dgkbl,16        ; Latin1?
  3916.     je    fgrab3            ; e = yes
  3917.     mov    di,offset grl1dgi    ; get DG Internat ptr to structure
  3918.     cmp    dgkbl,20        ; DG keyboard language, DG Internat?
  3919.     jne    fgrab15            ; ne = no
  3920. fgrab3:    mov    ax,word ptr grabbox    ; get pair of chars
  3921.     call    toupr            ; convert AX to upper case
  3922.     call    match
  3923.     jnc    fgrab11            ; nc = found
  3924.     xchg    ah,al
  3925.     call    match
  3926.     jnc    fgrab11            ; nc = match
  3927.  
  3928. fgrab5:    mov    di,offset grl2lat    ; use Latin1 ptr
  3929.     cmp    vtcpage,852        ; CP852?
  3930.     jne    fgrab5a            ; ne = no
  3931.     mov    di,offset grl2lat2    ; use Latin 2
  3932. fgrab5a:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  3933.     jz    fgrab6            ; z = no
  3934.     cmp    dgkbl,16        ; Latin1?
  3935.     je    fgrab6            ; e = yes
  3936.     mov    di,offset grl2dgi    ; get DG Internat ptr to structure
  3937.     cmp    dgkbl,20        ; DG keyboard language, DG Internat?
  3938.     jne    fgrab15            ; ne = no
  3939. fgrab6:    mov    ax,word ptr grabbox
  3940.     mov    dx,ax
  3941.     cmp    vtcpage,852        ; CP852?
  3942.     je    fgrab6a            ; e = yes, use as-is
  3943.     call    toupr            ; convert AX to upper case
  3944. fgrab6a:call    match
  3945.     jnc    fgrab7            ; nc = found
  3946.     xchg    ah,al            ; try reversed order
  3947.     xchg    dh,dl
  3948.     call    match
  3949.     jc    fgrab8            ; c = not found
  3950. fgrab7:    cmp    vtcpage,852        ; CP852?
  3951.     je    fgrab11            ; e = yes, output as-is
  3952.     cmp    dl,'a'            ; lower case char?
  3953.     jb    fgrab11            ; b = no, upper case
  3954.     or    al,20h            ; move to lower case output codes
  3955.     jmp    short fgrab11
  3956.  
  3957. fgrab8:    mov    di,offset grl3lat    ; use Latin1 ptr
  3958.     cmp    vtcpage,852        ; CP852?
  3959.     jne    fgrab8a            ; ne = no
  3960.     mov    di,offset grl3lat2    ; use Latin 2
  3961. fgrab8a:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  3962.     jz    fgrab9            ; z = no
  3963.     cmp    dgkbl,16        ; Latin1?
  3964.     je    fgrab9            ; e = yes
  3965.     mov    di,offset grl3dgi    ; get DG Internat ptr to structure
  3966.     cmp    dgkbl,20        ; DG keyboard language, DG Internat?
  3967.     jne    fgrab15            ; ne = no
  3968. fgrab9:    mov    ax,word ptr grabbox
  3969.     xchg    ah,al
  3970.     call    match            ; look for matching combination
  3971.     jc    fgrab16            ; c = failed
  3972. fgrab11:call    foutprt            ; send it to the host
  3973. fgrab15:call    togmod
  3974.     call    togmod            ; update mode line
  3975.     pop    es
  3976.     pop    di
  3977.     pop    dx
  3978.     ret
  3979.  
  3980. fgrab16:call    fvtbell            ; mismatch, beep, cancel
  3981.     jmp    short fgrab15        ;  finish up
  3982. fgrabber endp
  3983.  
  3984.                     ; worker for above
  3985. match    proc    near
  3986.     push    bx
  3987.     push    si
  3988.     push    di
  3989.     mov    cl,es:[di]        ; get count of pairs
  3990.     xor    ch,ch
  3991.     inc    di
  3992.     mov    si,di            ; start of char lists
  3993.     jcxz    match2            ; nothing to look at
  3994.     mov    si,di            ; remember where pairs start
  3995.     mov    bx,di
  3996.     add    bx,cx
  3997.     add    bx,cx            ; output singles start here
  3998.     cld
  3999.     push    cx            ; save counter
  4000.     repne    scasw            ; look for a match
  4001.     pop    cx
  4002.     jne    match2            ; ne = no match
  4003.     sub    di,2            ; backup to match
  4004.     sub    di,si            ; get item count
  4005.     shr    di,1            ; count bytes
  4006.     mov    al,es:[bx+di]        ; get new output char
  4007.     pop    di
  4008.     pop    si
  4009.     pop    bx
  4010.     clc                ; say success
  4011.     ret
  4012. match2:    pop    di
  4013.     pop    si
  4014.     pop    bx
  4015.     stc                ; say no match
  4016.     ret
  4017. match    endp
  4018.  
  4019. ; DEC LK201 keyboard keys and "User Definable Keys" in VT3xx mode
  4020. decfind:mov    al,1            ; Find
  4021.     jmp    dfkout
  4022. decinsert:mov    al,2            ; Insert
  4023.     jmp    dfkout
  4024. decremove:mov    al,3            ; Remove
  4025.     jmp    dfkout
  4026. decselect:mov    al,4            ; Select
  4027.     jmp    dfkout
  4028. decprev:mov    al,5            ; Previous screen
  4029.     jmp    dfkout
  4030. decnext:mov    al,6            ; Next screen
  4031.     jmp    dfkout
  4032. decf6:    mov    al,17            ; key ident for DEC F6
  4033.     jmp    dfkout            ; process it
  4034. decf7:    mov    al,18            ; key ident for DEC F7
  4035.     jmp    dfkout            ; process it
  4036. decf8:    mov    al,19            ; key ident for DEC F8
  4037.     jmp    dfkout            ; process it
  4038. decf9:    mov    al,20            ; key ident for DEC F9
  4039.     jmp    dfkout            ; process it
  4040. decf10:    mov    al,21            ; key ident for DEC F10
  4041.     jmp    dfkout            ; process it
  4042. decf11:    mov    al,23            ; key ident for DEC F11
  4043.     jmp    dfkout            ; process it
  4044. decf12:    mov    al,24            ; key ident for DEC F12
  4045.     jmp    dfkout            ; process it
  4046. decf13:    mov    al,25            ; key ident for DEC F13
  4047.     jmp    dfkout            ; process it
  4048. decf14:    mov    al,26            ; key ident for DEC F14
  4049.     jmp    dfkout            ; process it
  4050. dechelp:mov    al,28            ; key ident for DEC HELP
  4051.     jmp    dfkout            ; process it
  4052. decdo:    mov    al,29            ; key ident for DEC DO
  4053.     jmp    dfkout            ; process it
  4054. decf17:    mov    al,31            ; key ident for DEC F17
  4055.     jmp    dfkout            ; process it
  4056. decf18:    mov    al,32            ; key ident for DEC F18
  4057.     jmp    dfkout            ; process it
  4058. decf19:    mov    al,33            ; key ident for DEC F19
  4059.     jmp    dfkout            ; process it
  4060. decf20:    mov    al,34            ; key ident for DEC F20
  4061.     jmp    dfkout            ; process it
  4062.  
  4063. ; common worker to output contents of User Definable Key definition strings
  4064. ; Enter with al = key ident (17 - 34)
  4065. dfkout    proc    near
  4066.     push    ax
  4067.     push    bx
  4068.     push    cx
  4069.     push    es
  4070.     mov    ttyact,0        ; network, group chars for packet
  4071.     test    flags.vtflg,ttvt320+ttvt220 ; VT320/VT220?
  4072.     jnz    dfkout4            ; nz = yes, else use VT100/VT52 default
  4073.     test    flags.vtflg,tttek    ; Tek?
  4074.     jnz    dfkout4            ; nz = yes, try this
  4075.     mov    ttyact,1        ; network, restore tty active flag
  4076.     cmp    al,23            ; F11 sends ESC
  4077.     jne    dfkou1            ; ne = not F11
  4078.     mov    al,escape
  4079.     call    foutprt
  4080.     jmp    dfkoutx
  4081. dfkou1:    cmp    al,24            ; F12 sends BS
  4082.     jne    dfkou2            ; ne = not F12
  4083.     mov    al,BS
  4084.     call    foutprt
  4085.     jmp    dfkoutx
  4086. dfkou2:    cmp    al,25            ; F13 sends LF
  4087.     jne    dfkoutx            ; ne = not F13, ignore
  4088.     mov    al,LF
  4089.     call    foutprt
  4090. dfkou3:    jmp    dfkoutx
  4091.  
  4092. dfkout4:push    ax            ; VT320, use default definitions
  4093.     mov    al,Escape        ; char to send, CSI
  4094.     call    foutprt
  4095.     mov    al,'['
  4096.     call    foutprt            ; send lead-in char in 7/8-bit form
  4097.     pop    ax
  4098.     call    fprtnout        ; key ident (17-34) as ascii digits
  4099.     mov    al,7eh            ; tilde terminator
  4100.     mov    ttyact,1        ; network, restore tty active flag
  4101.     call    foutprt
  4102. dfkoutx:pop    es
  4103.     pop    cx
  4104.     pop    bx
  4105.     pop    ax
  4106.     clc
  4107.     ret
  4108. dfkout    endp
  4109.  
  4110. ; User Definable Keys
  4111. udkf6:    mov    al,17            ; key ident for DEC F6
  4112.     jmp    udkout            ; process it
  4113. udkf7:    mov    al,18            ; key ident for DEC F7
  4114.     jmp    udkout            ; process it
  4115. udkf8:    mov    al,19            ; key ident for DEC F8
  4116.     jmp    udkout            ; process it
  4117. udkf9:    mov    al,20            ; key ident for DEC F9
  4118.     jmp    udkout            ; process it
  4119. udkf10:    mov    al,21            ; key ident for DEC F10
  4120.     jmp    udkout            ; process it
  4121. udkf11:    mov    al,23            ; key ident for DEC F11
  4122.     jmp    udkout            ; process it
  4123. udkf12:    mov    al,24            ; key ident for DEC F12
  4124.     jmp    udkout            ; process it
  4125. udkf13:    mov    al,25            ; key ident for DEC F13
  4126.     jmp    udkout            ; process it
  4127. udkf14:    mov    al,26            ; key ident for DEC F14
  4128.     jmp    udkout            ; process it
  4129. udkf15:    mov    al,28            ; key ident for DEC HELP
  4130.     jmp    udkout            ; process it
  4131. udkf16:    mov    al,29            ; key ident for DEC DO
  4132.     jmp    udkout            ; process it
  4133. udkf17:    mov    al,31            ; key ident for DEC F17
  4134.     jmp    udkout            ; process it
  4135. udkf18:    mov    al,32            ; key ident for DEC F18
  4136.     jmp    udkout            ; process it
  4137. udkf19:    mov    al,33            ; key ident for DEC F19
  4138.     jmp    udkout            ; process it
  4139. udkf20:    mov    al,34            ; key ident for DEC F20
  4140. ;    jmp    udkout            ; process it
  4141.  
  4142. udkout    proc    near
  4143.     push    es
  4144.     mov    ttyact,0        ; network, group chars for packet
  4145.     mov    bl,al            ; VT3XX key ident, UDK style (17-34)
  4146.     sub    bl,17            ; minus starting offset of 17
  4147.     xor    bh,bh
  4148.     cmp    bl,17            ; out of range?
  4149.     ja    udkoutx            ; a = yes, ignore
  4150.     shl    bx,1            ; index words
  4151.     mov    bx,udkseg[bx]        ; segment of definition
  4152.     or    bx,bx            ; anything there?
  4153.     jz    udkoutx            ; z = no
  4154.     mov    es,bx            ; definition segment
  4155.     xor    bx,bx            ;  and offset
  4156.     mov    cl,es:[bx]        ; get string length byte
  4157.     xor    ch,ch            ; use cx as a counter
  4158.     jcxz    udkoutx            ; z = empty
  4159. udkou1:    inc    bx            ; es:bx is now the string text
  4160.     mov    al,es:[bx]        ; get a char
  4161.     push    bx
  4162.     push    cx
  4163.     push    es
  4164.     cmp    cx,1            ; last byte
  4165.     jne    udkou2            ; ne = not last byte
  4166.     mov    ttyact,1        ; network, restore tty active flag
  4167. udkou2:    call    foutprt            ; output
  4168.     pop    es
  4169.     pop    cx
  4170.     pop    bx
  4171.     loop    udkou1
  4172. udkoutx:pop    es
  4173.     clc
  4174.     ret
  4175. udkout    endp
  4176.                     ; Wyse-50 function keys F1..F16
  4177. wykf1:    mov    al,'@'            ; Wyse F1
  4178.     jmp    short wykfcom
  4179. wykf2:    mov    al,'A'            ; Wyse F2
  4180.     jmp    short wykfcom
  4181. wykf3:    mov    al,'B'
  4182.     jmp    short wykfcom
  4183. wykf4:    mov    al,'C'
  4184.     jmp    short wykfcom
  4185. wykf5:    mov    al,'D'
  4186.     jmp    short wykfcom
  4187. wykf6:    mov    al,'E'
  4188.     jmp    short wykfcom
  4189. wykf7:    mov    al,'F'
  4190.     jmp    short wykfcom
  4191. wykf8:    mov    al,'G'
  4192.     jmp    short wykfcom
  4193. wykf9:    mov    al,'H'
  4194.     jmp    short wykfcom
  4195. wykf10:    mov    al,'I'
  4196.     jmp    short wykfcom
  4197. wykf11:    mov    al,'J'
  4198.     jmp    short wykfcom
  4199. wykf12:    mov    al,'K'
  4200.     jmp    short wykfcom
  4201. wykf13:    mov    al,'L'
  4202.     jmp    short wykfcom
  4203. wykf14:    mov    al,'M'
  4204.     jmp    short wykfcom
  4205. wykf15:    mov    al,'N'
  4206.     jmp    short wykfcom
  4207. wykf16:    mov    al,'O'            ; Wyse F16
  4208.     jmp    short wykfcom
  4209.                     ; Wyse-50 Shift function keys F1..F16
  4210. wykSf1:    mov    al,'`'            ; Wyse Shift F1
  4211.     jmp    short wykfcom
  4212. wykSf2:    mov    al,'a'            ; Wyse Shift F2
  4213.     jmp    short wykfcom
  4214. wykSf3:    mov    al,'b'
  4215.     jmp    short wykfcom
  4216. wykSf4:    mov    al,'c'
  4217.     jmp    short wykfcom
  4218. wykSf5:    mov    al,'d'
  4219.     jmp    short wykfcom
  4220. wykSf6:    mov    al,'e'
  4221.     jmp    short wykfcom
  4222. wykSf7:    mov    al,'f'
  4223.     jmp    short wykfcom
  4224. wykSf8:    mov    al,'g'
  4225.     jmp    short wykfcom
  4226. wykSf9:    mov    al,'h'
  4227.     jmp    short wykfcom
  4228. wykSf10:mov    al,'i'
  4229.     jmp    short wykfcom
  4230. wykSf11:mov    al,'j'
  4231.     jmp    short wykfcom
  4232. wykSf12:mov    al,'k'
  4233.     jmp    short wykfcom
  4234. wykSf13:mov    al,'l'
  4235.     jmp    short wykfcom
  4236. wykSf14:mov    al,'m'
  4237.     jmp    short wykfcom
  4238. wykSf15:mov    al,'n'
  4239.     jmp    short wykfcom
  4240. wykSf16:mov    al,'o'            ; Wyse Shift F16
  4241.  
  4242. wykfcom:mov    ttyact,0        ; network, group chars for packet
  4243.     push    ax            ; save key code
  4244.     mov    al,1            ; send SOH keycode CR
  4245.     call    foutprt
  4246.     pop    ax
  4247.     call    foutprt
  4248.     mov    al,CR
  4249.     mov    ttyact,1        ; network, restore tty active flag
  4250.     call    foutprt
  4251.     ret
  4252.  
  4253. ; Change Telnet sessions
  4254. ifndef    no_tcp
  4255. ses1    proc    near
  4256.     mov    bx,0
  4257.     mov    cx,1
  4258.     jmp    short nextses4
  4259. ses1    endp
  4260. ses2    proc    near
  4261.     mov    bx,1
  4262.     mov    cx,1
  4263.     jmp    short nextses4
  4264. ses2    endp
  4265. ses3    proc    near
  4266.     mov    bx,2
  4267.     mov    cx,1
  4268.     jmp    short nextses4
  4269. ses3    endp
  4270. ses4    proc    near
  4271.     mov    bx,3
  4272.     mov    cx,1
  4273.     jmp    short nextses4
  4274. ses4    endp
  4275. ses5    proc    near
  4276.     mov    bx,4
  4277.     mov    cx,1
  4278.     jmp    short nextses4
  4279. ses5    endp
  4280. ses6    proc    near
  4281.     mov    bx,5
  4282.     mov    cx,1
  4283.     jmp    short nextses4
  4284. ses6    endp
  4285. endif    ; no tcp
  4286.  
  4287. nextses proc    near
  4288. ifndef    no_tcp
  4289.     cmp    flags.comflg,'t'    ; doing Telnet?
  4290.     je    nextses1        ; e = yes
  4291.     clc                ; do not exit Connect mode
  4292.     ret
  4293. nextses1:mov    bx,sescur        ; current session ident
  4294.     mov    cx,6            ; sessions to consider
  4295. nextses3:inc    bx
  4296.     cmp    bx,6            ; over the top yet
  4297.     jb    nextses4        ; b = no
  4298.     xor    bx,bx            ; wrap
  4299. nextses4:cmp    seslist[bx],0        ; is this session active?
  4300.     jge    nextses5        ; ge = yes
  4301.     loop    nextses3
  4302.     clc
  4303.     ret                ; do nothing
  4304.  
  4305. nextses5:push    bx
  4306.     mov    bx,sescur        ; old session
  4307.     call    termswapout        ; save current terminal items
  4308.     pop    bx
  4309.     mov    sescur,bx        ; next session, from above
  4310.     call    tcpstart        ; start session, ident in bl
  4311.     mov    bx,sescur        ; new session
  4312.     call    termswapin        ; get data structures
  4313.     mov    kbdflg,' '        ; return Connect mode
  4314.     stc                ; but exit Connect mode now
  4315. else
  4316.     clc
  4317. endif    ; no_tcp
  4318.     ret
  4319. nextses endp
  4320.  
  4321. vtsesmac  proc    far            ; SESSION macro
  4322.     mov    vtmacname,offset vtsesname
  4323.     mov    al,bl            ; session number
  4324.     add    al,'1'            ; to ascii, from 1
  4325.     mov    vtsesnum,al        ; to name
  4326.     mov    vtmaclen,vtseslen
  4327.     call    dword ptr vtmacroptr    ; FAR pointer
  4328.     ret
  4329. vtsesmac endp
  4330.  
  4331. ; Call from mszibm DG components to put system into DG special graphics mode,
  4332. ; and thus to cause incoming material to be still sent to the text emulator.
  4333. ; This also unshifts the screen (as seen on the status line) before starting
  4334. ; graphics so the column 81 stuff comes out right.
  4335. dgsettek proc    far
  4336. ifndef    no_graphics
  4337.     cmp    tekflg,tek_active+tek_sg ; inited already?
  4338.     je    dgsettek3        ; e = yes
  4339.     push    bx
  4340.     push    cx
  4341.     mov    cl,byte ptr low_rgt+1    ; examine whole screen
  4342.     inc    cl            ; lines in emulation part
  4343.     xor    ch,ch
  4344.     mov    bx,cx            ; for status line
  4345.     xor    al,al
  4346.     xchg    al,linescroll[bx]    ; status line scroll value
  4347.     or    al,al
  4348.     jz    dgsettek2        ; z = no shift in effect
  4349.     xor    bx,bx            ; start of screen
  4350. dgsettek1:sub    linescroll[bx],al    ; unscroll by status line amount
  4351.     inc    bx            ; next line
  4352.     loop    dgsettek1        ; do all emulation lines
  4353. dgsettek2:pop    cx
  4354.     pop    bx
  4355.     or    tekflg,tek_sg        ; set special graphics mode
  4356.     call    TEKINI            ; go to Tektronix Emulator
  4357. endif    ; no_graphics
  4358. dgsettek3:ret
  4359. dgsettek endp
  4360.  
  4361. ;[HF]940206 jpnxltkey
  4362. ;[HF]940207
  4363. ;[HF]940206 Check if leading byte of Japanese double byte code
  4364. ;[HF]940207 Range of Japanese second byte
  4365. ;[HF]940207 ((AL >= 0x40) && (AL <= 0x7e))||((AL >= 0x80) && (AL <= 0xfc))
  4366. ;[HF]940207
  4367. ;[HF]940206 If not Japanese, clear carry and return.
  4368. ;[HF]940207
  4369. jpnxltkey    proc    near        ;[HF]940206
  4370.     cmp    keypend,0        ;[HF]940207 Kanji second byte?
  4371.     jne    jpnxltk3        ;[HF]940207 ne = yes, second byte
  4372.     call    iskanji1        ;[HF]941010 Kanji leading byte ?
  4373.     jc    jpnxltk2        ;[HF]941010 c = yes
  4374.     call    iskana            ;[HF]941010 Katakana ?
  4375.     jnc    jpnxltk1        ;[HF]941010 nc = no
  4376.     cmp    flags.oshift,(128+3)    ;[HF]941012 DEC-Kanji ?
  4377.     je    jpnxltk1c        ;[HF]941012 e = yes, use X208 Katakana
  4378.     cmp    flags.oshift,(128+2)    ;[HF]941012 EUC-Kanji ?
  4379.     jne    jpnxltk1b        ;[HF]941012 ne = no
  4380.     call    outkana            ;[HF]941011 katakana output
  4381.     mov    keypend,0        ;[HF]941011 no pending char
  4382.     stc                ;[HF]941011 say, we have done
  4383.     ret                ;[HF]941011
  4384. jpnxltk1b:                ;[HF]941011
  4385.     cmp    flags.oshift,(128+1)    ;[HF]941012 JIS7-Kanji ?
  4386.     jne    jpnxltk1a        ;[HF]941012 ne = no
  4387. jpnxltk1c:                ;[HF]941012
  4388.     call    dblkana            ;[HF]941012 get double byte code
  4389.     or    ax,8080h        ;[HF]941012 make it GR
  4390.     mov    keypend,ax        ;[HF]941012
  4391.     jmp    jpnxltk5c        ;[HF]941012
  4392. jpnxltk1:                ;[HF]940207
  4393.     cmp    flags.oshift,(128+1)    ;[HF]940211 JIS7?
  4394.     jne    jpnxltk1a        ;[HF]940211 ne = no
  4395.     cmp    keyj7st,0        ;[HF]940211 ASCII state?
  4396.     je    jpnxltk1a        ;[HF]940211 e = yes
  4397.     push    ax            ;[HF]940211
  4398.     mov    al,ESCAPE        ;[HF]940211
  4399.     call    chrout            ;[HF]940211
  4400.     mov    al,'('            ;[HF]940211
  4401.     call    chrout            ;[HF]940211
  4402.     mov    al,byte ptr jis7des+1    ;[HF]940211
  4403.     call    chrout            ;[HF]940211
  4404.     mov    keyj7st,0        ;[HF]940211
  4405.     pop    ax            ;[HF]940211
  4406. jpnxltk1a:                ;[HF]940211
  4407.     mov    keypend,0        ;[HF]940207 Clear second byte flag
  4408.     clc                ;[HF]940206 tell that not Japanese
  4409.     ret                ;[HF]940206
  4410. jpnxltk2:                ;[HF]940206
  4411.     push    ax            ;[HF]940207
  4412.     mov    ah,al            ;[HF]940207
  4413.     xor    al,al            ;[HF]940207
  4414.     mov    keypend,ax        ;[HF]940207 save it for later use
  4415.     pop    ax            ;[HF]940207
  4416.     stc                ;[HF]940206 tell that Japanese
  4417.     ret                ;[HF]940206
  4418. jpnxltk3:                ;[HF]940207
  4419.     cmp    al,40h            ;[HF]940207
  4420.     jb    jpnxltk4        ;[HF]940207 not the second byte
  4421.     cmp    al,7eh            ;[HF]940207
  4422.     jbe    jpnxltk5        ;[HF]940207 Yes second byte
  4423.     cmp    al,80h            ;[HF]940207
  4424.     jb    jpnxltk4        ;[HF]940207 not the second byte
  4425.     cmp    al,0fch            ;[HF]940207
  4426.     jbe    jpnxltk5        ;[HF]940207 Yes second byte
  4427. jpnxltk4:                ;[HF]940207
  4428.     jmp    jpnxltk1        ;[HF]940211 treat as single byte char.
  4429. jpnxltk5:                ;[HF]940207
  4430.     mov    byte ptr keypend,al    ;[HF]940207 make double byte code
  4431.     mov    ax,keypend        ;[HF]940207 Shift-JIS code
  4432.     call    jpnftox            ;[HF]940207 translate to EUC(JIS-GR)
  4433. jpnxltk5c:                ;[HF]941012
  4434.     cmp    flags.oshift,(128+1)    ;[HF]940211 JIS7?
  4435.     je    jpnxltk5a        ;[HF]940211 e = yes
  4436.     cmp    flags.oshift,(128+2)    ;[HF]940214 EUC?
  4437.     je    jpnxltk5b        ;[HF]940214 e = yes
  4438.     cmp    flags.oshift,(128+3)    ;[HF]941012 DEC?
  4439.     je    jpnxltk5b        ;[HF]941012 e = yes
  4440.     mov    ax,keypend        ;[HF]940214 No. use Shift-JIS code
  4441.     jmp    short jpnxltk5b        ;[HF]940211
  4442. jpnxltk5a:                ;[HF]940211
  4443.     and    ax,7f7fh        ;[HF]940211
  4444.     cmp    keyj7st,2        ;[HF]940211 Kanji state?
  4445.     je    jpnxltk5b        ;[HF]940211 e=yes, no shift
  4446.     push    ax            ;[HF]940211
  4447.     mov    al,ESCAPE        ;[HF]940211
  4448.     call    chrout            ;[HF]940211
  4449.     mov    al,'$'            ;[HF]940211
  4450.     call    chrout            ;[HF]940211
  4451.     mov    al,byte ptr jis7des    ;[HF]940211
  4452.     call    chrout            ;[HF]940211
  4453.     mov    keyj7st,2        ;[HF]940211
  4454.     pop    ax            ;[HF]940211
  4455. jpnxltk5b:                ;[HF]940211
  4456.     push    ax            ;[HF]940214 save dble byte code
  4457.     mov    al,ah            ;[HF]940207
  4458.     call    chrout            ;[HF]940207 send leading byte
  4459.     pop    ax            ;[HF]940214 remember dble byte code
  4460.     mov    ah,al            ;[HF]940207
  4461.     call    chrout            ;[HF]940207 send second byte
  4462.     mov    keypend,0        ;[HF]940207 clear double byte flag
  4463.     stc                ;[HF]940207 say no more char
  4464.     ret                ;[HF]940207
  4465. jpnxltkey    endp            ;[HF]940206
  4466.  
  4467. ;[HF]941011 outkana
  4468. ;[HF]941011
  4469. ;[HF]941011 Output Shift-JIS katakana code in AL to com port.
  4470. outkana    proc    near            ;[HF]941011
  4471.     push    ax            ;[HF]941011 save AX
  4472.     push    bx            ;[HF]941011 save BX
  4473.     cmp    flags.oshift,(128+1)    ;[HF]941012 JIS7 ?
  4474.     je    outkan1            ;[HF]941012 e = yes
  4475.     mov    bl,flags.oshift        ;[HF]941011 save output-shift
  4476.     mov    flags.oshift,0        ;[HF]941011 Do our own shift
  4477.     mov    bh,al            ;[HF]941011 save AL
  4478.     mov    al,SS2            ;[HF]941011 SS2
  4479.     call    chrout            ;[HF]941011
  4480.     mov    al,bh            ;[HF]941011 restore AL
  4481.     or    al,80h            ;[HF]941011 8th bit On
  4482.     call    chrout            ;[HF]941011
  4483.     jmp    outkanx            ;[HF]941012
  4484. outkan1:cmp    keyj7st,1        ;[HF]941012 already in katakana mode?
  4485.     je    outkan3            ;[HF]941012 e = yes
  4486.     cmp    keyj7st,2        ;[HF]941012 in kanji mode?
  4487.     jne    outkan2            ;[HF]941012 ne = no
  4488.     mov     bh,al            ;[HF]941012 save AL
  4489.     mov    al,ESCAPE        ;[HF]941012
  4490.     call    chrout            ;[HF]941012
  4491.     mov    al,'('            ;[HF]941012
  4492.     call    chrout            ;[HF]941012
  4493.     mov    al,byte ptr jis7des+1    ;[HF]941012
  4494.     call    chrout            ;[HF]941012
  4495. outkan2:mov    al,SOchar        ;[HF]941012 SO
  4496.     call    chrout            ;[HF]941012
  4497.     mov    keyj7st,1        ;[HF]941012
  4498.     mov    al,bh            ;[HF]941012
  4499. outkan3:and    al,7fh            ;[HF]941012 mask 8th bit
  4500.     call    chrout            ;[HF]941012
  4501. outkanx:mov    flags.oshift,bl        ;[HF]941011 restore output-shift
  4502.     pop    bx            ;[HF]941011 restore BX
  4503.     pop    ax            ;[HF]941011 restore AX
  4504.     ret                ;[HF]941011
  4505. outkana    endp                ;[HF]941011
  4506.  
  4507. ;[HF]941012 dblkana
  4508. ;[HF]941012
  4509. ;[HF]941012 convert single byte katakana code to double byte code
  4510. ;[HF]941012 Input: AL Katakana code in JIS
  4511. ;[HF]941012 Outpt: AX Double byte JIS katakana code (AH first)
  4512. dblkana    proc    near            ;[HF]941012
  4513.     push    es
  4514.     push    bx            ;[HF]941012
  4515.     sub    ax,32            ;[HF]941012
  4516.     and    ax,3fh            ;[HF]941012
  4517.     mov    bx,seg kanatbl
  4518.     mov    es,bx
  4519.     mov    bx,offset kanatbl    ;[HF]941012
  4520.     add    bx,ax            ;[HF]941012
  4521.     add    bx,ax            ;[HF]941012 word address
  4522.     mov    ax,es:[bx]        ;[HF]941012
  4523.     pop    bx            ;[HF]941012
  4524.     pop    es
  4525.     ret                ;[HF]941012
  4526. dblkana    endp                ;[HF]941012
  4527.  
  4528. ;[HF]941010 iskana
  4529. ;[HF]941010
  4530. ;[HF]941010 Check if AL is Shift-JIS Katakana code or not.
  4531. ;[HF]941010 If Katakana, program returns with carry set,
  4532. ;[HF]941010 if not, carry clear.
  4533. ;[HF]941010
  4534. ;[HF]941010 Note: Shift-JIS Katakana is in the range
  4535. ;[HF]941010 ((AL >= 0xa0) && (AL <= 0xdf))
  4536. ;[HF]941010 where AL = 0xa0 is space
  4537. ;[HF]941010
  4538. iskana    proc    near            ;[HF]941010
  4539.     cmp    al,0a0h            ;[HF]941010
  4540.     jb    iskanan            ;[HF]941010 b = no
  4541.     cmp    al,0dfh            ;[HF]941010
  4542.     ja    iskanan            ;[HF]941010 a = no
  4543.     stc                ;[HF]941010 yes, katakana
  4544.     jmp    short iskanax        ;[HF]941010
  4545. iskanan:clc                ;[HF]941010 no, not katakana
  4546. iskanax:ret                ;[HF]941010
  4547. iskana    endp                ;[HF]941010
  4548.  
  4549. ;[HF]940207 Range of Shift-JIS Kanji leading byte
  4550. ;[HF]940207 ((AL >= 0x81) && (AL <= 0x9f))||((AL >= 0xe0) && (AL <= 0xfc))
  4551. iskanji1    proc    near        ;[HF]941010
  4552.     cmp    al,81h            ;[HF]940207
  4553.     jb    iskan1n            ;[HF]940207 b = No, not Kanji leading
  4554.     cmp    al,9fh            ;[HF]940207
  4555.     jbe    iskan1y            ;[HF]940207 Yes, Japanese leading byte
  4556.     cmp    al,0e0h            ;[HF]940207
  4557.     jb    iskan1n            ;[HF]940207 No, not Japanese
  4558.     cmp    al,0fch            ;[HF]940207
  4559.     jbe    iskan1y            ;[HF]940207 Yes, Japanese leading byte
  4560. iskan1n:clc                ;[HF]941010
  4561.     jmp    short iskan1x        ;[HF]941010
  4562. iskan1y:stc                ;[HF]941010
  4563. iskan1x:ret                ;[HF]941010
  4564. iskanji1    endp            ;[HF]941010
  4565.  
  4566. code    ends
  4567.  
  4568. code1    segment
  4569.     assume    cs:code1
  4570.  
  4571. ; Set (define) the DEC "User Definable Keys". Inserts text definitions for
  4572. ; keyboard verbs \KdecF6 ...\KdecF14, \KdecHELP, \KdecDO, \KdecF17...\KdecF20.
  4573. ; Enter with the DCS definition string as key-number/hex-chars. UDK key number
  4574. ; is 17 for \KdecF6, et seq, the definition are pairs of hex digits converted
  4575. ; here to a single byte per pair. The DCS definition string is pointed at by
  4576. ; DS:SI, and the byte count is in CX.
  4577. ; Example:  17/54657374204636   means key \KdecF6 sends string "Test F6"
  4578. setudk    proc    near
  4579.     push    ax
  4580.     push    bx
  4581.     push    cx
  4582.     push    si
  4583.     push    di
  4584.     push    es
  4585.     cld
  4586.     lodsb                ; get key ident first byte
  4587.     sub    al,'0'            ; ascii to binary
  4588.     mul    ten            ; times 10
  4589.     xchg    ah,al            ; to ah
  4590.     lodsb                ; get key ident second byte
  4591.     sub    al,'0'            ; ascii to binary
  4592.     add    al,ah            ; plus high order part
  4593.     xor    ah,ah
  4594.     mov    bx,ax            ; key ident, 17 - 34
  4595.     lodsb                ; skip slash separator
  4596.     sub    cx,3            ; three less bytes in the string
  4597.     jge    setudk0            ; ge = had three or more bytes
  4598.     jmp    setudkx            ; else error
  4599. setudk0:sub    bx,17            ; remove key ident bias of 17
  4600.     cmp    bx,17            ; out of range?
  4601.     ja    setudkx            ; a = yes, ignore
  4602.     shl    bx,1            ; index words
  4603.     cmp    udkseg[bx],0        ; has a segment been allocated for it?
  4604.     je    setudk1            ; e = no
  4605.     mov    ax,udkseg[bx]        ; get segment to es
  4606.     mov    es,ax
  4607.     mov    ah,freemem        ; deallocate old memory block, es:0
  4608.     int    dos
  4609.     mov    udkseg[bx],0        ; clear table entry too
  4610. setudk1:and    cl,not 1        ; force an even number of inputs
  4611.     jcxz    setudkx            ; z = no definition, clear entry
  4612.     push    bx            ; save index BX
  4613.     mov    bx,cx            ; get string length
  4614.     shr    bx,1            ; two hex digits per final byte
  4615.     add    bx,15+1            ; round up plus length byte
  4616.     shr    bx,1            ; convert to paragraphs
  4617.     shr    bx,1
  4618.     shr    bx,1
  4619.     shr    bx,1
  4620.     mov    di,bx            ; remember request
  4621.     mov    ah,alloc        ; allocate BX paragraphs
  4622.     int    dos
  4623.     jc    setudkx            ; c = failure
  4624.     cmp    di,bx            ; requested vs allocated
  4625.     pop    bx            ; recover bx
  4626.     je    setudk2            ; e = enough
  4627.     mov    ah,freemem        ; return the memory, es is ptr
  4628.     int    dos
  4629.     jmp    short setudkx        ; exit failure
  4630.  
  4631. setudk2:mov    es,ax            ; segment of allocated memory
  4632.     mov    udkseg[bx],ax        ; segment:0 of definition string
  4633.     xor    di,di
  4634.     cld
  4635.     mov    al,cl            ; length of string
  4636.     shr    al,1            ; two hex bytes per stored byte
  4637.     xor    ch,ch
  4638.     stosb                ; store length byte
  4639.     jcxz    setudkx            ; z = empty string
  4640. setukd3:lodsb                ; get first hex digit
  4641.     dec    cx            ; adjust count remaining
  4642.     or    al,20h            ; to lower case
  4643.     cmp    al,'9'            ; digit?
  4644.     jbe    setudk4            ; be = yes
  4645.     sub    al,'a'-'9'-1        ; hex letter to column three
  4646. setudk4:sub    al,'0'            ; ascii to binary
  4647.     shl    al,1            ; times 16
  4648.     shl    al,1
  4649.     shl    al,1
  4650.     shl    al,1
  4651.     mov    ah,al            ; save in ah
  4652.     lodsb                ; get second hex digit
  4653.     or    al,20h            ; to lower case
  4654.     cmp    al,'9'            ; digit?
  4655.     jbe    setudk5            ; be = yes
  4656.     sub    al,'a'-'9'-1        ; hex letter to column three
  4657. setudk5:sub    al,'0'            ; ascii to binary
  4658.     add    al,ah            ; join both parts
  4659.     stosb                ; store final byte
  4660.     loop    setukd3
  4661. setudkx:pop    es
  4662.     pop    di
  4663.     pop    si
  4664.     pop    cx
  4665.     pop    bx
  4666.     pop    ax
  4667.     clc
  4668.     ret
  4669. setudk    endp
  4670.  
  4671. ; Clear all User Definable Keys, deallocate memory for their definitions
  4672. udkclear proc    near
  4673.     push    ax
  4674.     push    bx
  4675.     push    cx
  4676.     push    es
  4677.     mov    cx,17            ; 17 entries
  4678.     xor    bx,bx
  4679. udkcle1:mov    ax,udkseg[bx]        ; segment of definition
  4680.     or    ax,ax            ; segment defined?
  4681.     jz    udkcle2            ; z = no, try next key
  4682.     mov    es,ax
  4683.     mov    udkseg[bx],0        ; clear the entry
  4684.     mov    ah,freemem        ; release the memory
  4685.     int    dos
  4686. udkcle2:add    bx,2            ; word index
  4687.     loop    udkcle1            ; do all
  4688.     pop    es
  4689.     pop    cx
  4690.     pop    bx
  4691.     pop    ax
  4692.     clc
  4693.     ret
  4694. udkclear endp
  4695.  
  4696. fsetpos    proc    far
  4697.     call    setpos
  4698.     ret
  4699. fsetpos    endp
  4700.  
  4701. frepaint proc    far
  4702.     call    repaint
  4703.     ret
  4704. frepaint endp
  4705. code1    ends
  4706.  
  4707. code    segment
  4708.     assume    cs:code
  4709.                     ; these commands invoke Quit
  4710. cdos:    mov    al,'P'            ; Push to DOS
  4711.     jmp    short cmdcom
  4712. cstatus:mov    al,'S'            ; Status
  4713.     jmp    short cmdcom
  4714. cquit:    mov    al,'C'            ; Exit Connect mode
  4715.     jmp    short cmdcom
  4716. cquery:    mov    al,'?'            ; Help
  4717.     jmp    short cmdcom
  4718. chang:    mov    al,'H'            ; Hangup, drop DTR & RTS
  4719.     jmp    short cmdcom
  4720. cmdcom:    mov    kbdflg,al        ; pass char to msster.asm via kbdflg
  4721.     stc                ; signal that Quit is needed
  4722.     ret
  4723.                     ; general character out for emulator
  4724. chrout    proc    near
  4725.     cmp    flags.vtflg,0        ; emulating?
  4726.     je    chrou5            ; e = no
  4727.     call    fanskbi            ; say we had keyboard input
  4728.     cmp    al,cr            ; CR?
  4729.     jne    chrou5            ; ne = no, just output it and return
  4730.     test    vtemu.vtflgop,anslnm    ; ANSI new-line mode set?
  4731.     jz    chrou5            ; z = no, just send the cr
  4732.     cmp    dupflg,0        ; full duplex?
  4733.     je    chrou4            ; e = yes
  4734.     cmp    al,trans.seol        ; End of Line char?
  4735.     jne    chrou5            ; ne = no
  4736. chrou4:    mov    ah,trans.seol        ; save eol char
  4737.     push    ax            ; save on stack
  4738.     mov    trans.seol,lf        ; make LF the eol char
  4739.     call    foutprt            ; output a carriage-return
  4740.     mov    al,lf            ; followed by a line feed
  4741.     call    foutprt            ; send the LF
  4742.     pop    ax
  4743.     mov    trans.seol,ah        ; restore eol char
  4744.     ret
  4745. chrou5:    call    foutprt
  4746.     ret
  4747. chrout    endp
  4748.  
  4749.                        ; Screen dump entry from keyboad xlat
  4750. dmpscn    proc    near            ; dump screen to file
  4751. ifndef    no_graphics
  4752.     cmp    flags.vtflg,tttek    ; doing Tektronix emulation?
  4753.     je    dmpscn2            ; e = yes, use Tek emulator
  4754.     cmp    tekflg,tek_active+tek_dec ; emulation a Tektronix?
  4755.     jne    dmpscn1            ; ne = no
  4756. dmpscn2:call    tekdmp            ; near-call Tek screen dump utility
  4757.     clc
  4758.     ret
  4759. endif    ; no_graphics
  4760.  
  4761. dmpscn1:call    dumpscr            ; do buffer to file
  4762.     clc                ; do not exit Connect mode
  4763.     ret
  4764. dmpscn    endp
  4765.  
  4766. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  4767. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  4768. ; is determined by mssset and is passed as pointer dmpname.
  4769. ; Dumpscr reads the screen image saved in vscreen.
  4770.  
  4771. dumpscr proc    near
  4772.     push    ax
  4773.     push    bx
  4774.     push    cx
  4775.     push    dx
  4776.     mov    dmphand,-1        ; preset illegal handle
  4777.     mov    dx,offset dmpname    ; name of disk file, from mssset
  4778.     mov    ax,dx            ; where isfile wants name ptr
  4779.     call    isfile            ; what kind of file is this?
  4780.     jc    dmp5            ; c = no such file, create it
  4781.     test    byte ptr filtst.dta+21,1fh ; file attributes, ok to write?
  4782.     jnz    dmp0            ; nz = no.    
  4783.     mov    al,1            ; writing
  4784.     mov    ah,open2        ; open existing file
  4785.     int    dos
  4786.     jc    dmp0            ; c = failure
  4787.     mov    dmphand,ax        ; save file handle
  4788.     mov    bx,ax            ; need handle here
  4789.     mov    cx,0ffffh        ; setup file pointer
  4790.     mov    dx,-1            ; and offset
  4791.     mov    al,2            ; move to eof minus one byte
  4792.     mov    ah,lseek        ; seek the end
  4793.     int    dos
  4794.     jmp    dmp1
  4795.  
  4796. dmp5:    test    filtst.fstat,80h    ; access problem?
  4797.     jnz    dmp0            ; nz = yes
  4798.     mov    ah,creat2        ; file did not exist
  4799.     mov    cx,20h            ; attributes, archive bit
  4800.     int    dos
  4801.     mov    dmphand,ax        ; save file handle
  4802.     jnc    dmp1            ; nc = ok
  4803.  
  4804. dmp0:    mov    ah,3            ; get cursor position
  4805.     xor    bh,bh            ; page 0
  4806.     int    screen
  4807.     push    dx            ; save it
  4808.     mov    dh,byte ptr low_rgt+1    ; go to status line
  4809.     inc    dh
  4810.     xor    dl,dl            ; left most column
  4811.     mov    ah,2            ; set cursor
  4812.     xor    bh,bh            ; page 0
  4813.     int    screen
  4814.     mov    dx,offset dmperr    ; say no can do
  4815.     mov    ah,prstr
  4816.     int    dos
  4817.     pop    dx            ; get original cursor position
  4818.     mov    ah,2            ; set cursor
  4819.     xor    bh,bh            ; page 0
  4820.     int    screen
  4821.     pop    dx
  4822.     pop    cx
  4823.     pop    bx
  4824.     pop    ax
  4825.     clc
  4826.     ret
  4827.  
  4828. dmp1:    mov    ah,ioctl        ; is destination ready for output?
  4829.     mov    al,7            ; test output status
  4830.     mov    bx,dmphand        ; handle
  4831.     int    dos
  4832.     jc    dmp0            ; c = error
  4833.     cmp    al,0ffh            ; ready?
  4834.     jne    dmp0            ; ne = not ready
  4835.     push    di            ; read screen buffer, write lines
  4836.     push    si
  4837.     push    es
  4838.     mov    cl,byte ptr low_rgt+1    ; number of lines - 2
  4839.     add    cl,2            ; number of line on screen
  4840.     xor    ch,ch
  4841.     les    si,vs_ptr        ; seg and offset of vscreen
  4842.     sub    si,vswidth*2        ; prep for inc below
  4843. dmp2:    add    si,vswidth*2        ; virtual screen width in bytes
  4844.     push    si
  4845.     push    cx            ; save outer loop counter
  4846.     push    di
  4847.     mov    di,offset decbuf    ; data segment memory
  4848.     mov    cl,byte ptr low_rgt    ; number of columns on screen -1
  4849.     inc    cl
  4850.     xor    ch,ch
  4851. dmp3:    mov    ax,word ptr es:[si]    ; read char + attribute
  4852.     or    al,al            ; is it a null?
  4853.     jnz    dmp3c            ; nz = no
  4854.     mov    al,' '            ; replace null with space
  4855. dmp3c:    mov    byte ptr [di],al    ; store just char, don't use es:
  4856.     inc    si            ; update pointers
  4857.     inc    si
  4858.     inc    di
  4859.     loop    dmp3            ; do for each column
  4860.     mov    cl,byte ptr low_rgt    ; number of columns on screen - 1
  4861.     inc    cl
  4862.     xor    ch,ch
  4863.     push    es
  4864.     mov    ax,ds
  4865.     mov    es,ax            ; set es to data segment for es:di
  4866.     mov    di,offset decbuf    ; start of line
  4867.     add    di,cx            ; plus length of line
  4868.     dec    di            ; minus 1 equals end of line
  4869.     mov    al,' '            ; thing to scan over
  4870.     std                ; set scan backward
  4871.     repe    scasb            ; scan until non-space
  4872.     cld                ; set direction forward
  4873.     pop    es
  4874.     je    dmp3a            ; e = all spaces
  4875.     inc    cx
  4876.     inc    di
  4877. dmp3a:    mov    word ptr [di+1],0A0Dh    ; append cr/lf
  4878.     add    cx,2            ; line count + cr/lf
  4879.     mov    dx,offset decbuf    ; array to be written
  4880.     mov    bx,dmphand        ; need file handle
  4881.     mov    ah,write2        ; write the line
  4882.     int    dos
  4883.     pop    di
  4884.     pop    cx            ; get line counter again
  4885.     pop    si            ; screen offset
  4886.     jc    dmp3b            ; c = error
  4887.     loop    dmp2            ; do next line
  4888. dmp3b:    mov    dx,offset dumpsep    ; put in formfeed/cr/lf
  4889.     mov    bx,dmphand        ; need file handle
  4890.     mov    cx,3            ; three bytes overall
  4891.     mov    ah,write2        ; write them
  4892.     mov    bx,dmphand        ; file handle
  4893.     int    dos
  4894.     mov    bx,dmphand        ; need file handle
  4895.     mov    ah,close2        ; close the file now
  4896.     int    dos
  4897.     pop    es
  4898.     pop    si
  4899.     pop    di
  4900.     pop    dx
  4901.     pop    cx
  4902.     pop    bx
  4903.     pop    ax
  4904.     clc
  4905.     ret
  4906. dumpscr endp
  4907.  
  4908. togmod    proc    FAR
  4909.     call    trnmod            ; FAR callable trnmod
  4910.     ret
  4911. togmod    endp
  4912.  
  4913.                     ; Toggle Mode Line
  4914. trnmod    proc    near
  4915.     cmp    inemulator,0        ; in terminal emulator?
  4916.     je    trnm1            ; e = no, no mode line
  4917.     cmp    flags.modflg,1        ; mode line enabled and owned by us?
  4918.     jne    trnm1            ; ne = no, don't touch it
  4919.     cmp    flags.vtflg,tttek    ; Tek mode?
  4920.     je    trnm1            ; e = yes
  4921.     test    tekflg,tek_dec        ; in Tek submode?
  4922.     jnz    trnm1            ; nz = yes, no mode line changes
  4923.     test    yflags,modoff        ; mode line already off?
  4924.     jnz    trnm2            ; nz = yes, go turn on
  4925.     or    yflags,modoff        ; say modeline is toggled off
  4926.     cmp    flags.vtflg,0        ; emulating none?
  4927.     jne    trnm0            ; ne = no
  4928.     mov    lastsec,-1        ; tickle tod clock
  4929.     push    dx
  4930.     call    fgetpcur        ; get physical cursor
  4931.     mov    cursor,dx
  4932.     pop    dx
  4933. trnm0:    call    clrmod            ; clear mode line
  4934. trnm1:    clc                ; clear c bit so don't exit Connect
  4935.     ret
  4936. trnm2:    cmp    flags.vtflg,0        ; emulating a terminal?
  4937.     jne    trnm3            ; ne = yes
  4938.     push    dx            ; scroll screen to save bottom line
  4939.     call    fgetpcur        ; get physical cursor
  4940.     mov    cursor,dx
  4941.     mov    ah,prstr        ; for terminal type none
  4942.     mov    dx,offset crlf
  4943.     int    dos
  4944.     pop    dx
  4945. trnm3:    call    modlin            ; turn on modeline
  4946.     and    yflags,not modoff    ; say modeline is not toggled off
  4947.     clc
  4948.     ret
  4949. trnmod    endp
  4950.  
  4951. modlin    proc    near
  4952.     cmp    isps55,0        ; [HF]940206 Japanese PS/55 ?
  4953.     je    modl21            ; [HF]940206 e = no
  4954.     cmp    ps55mod,0        ; [HF]940206 can we use modeline?
  4955.     jne    modl21            ; [HF]940206 ne = yes
  4956.     mov    ax,1401h        ; [HF]940206 user uses the modeline
  4957.     mov    ps55mod,al        ; [HF]940206 save current status
  4958.     int    16h            ; [HF]940206 OK, now in our hands
  4959. modl21:    push    si
  4960.     push    di
  4961.     push    es
  4962.     mov    ax,ds
  4963.     mov    es,ax
  4964.     mov    si,offset modmaster    ; master template
  4965.     mov    di,offset modbuf    ; working copy
  4966.     mov    lastsec,-1        ; tickle tod clock
  4967.     cld
  4968. modl20:    lodsb
  4969.     stosb
  4970.     cmp    al,'$'            ; at end?
  4971.     jne    modl20            ; ne = no
  4972.     mov    bx,argadr        ; get argument block
  4973.     mov    al,[bx].baudb        ; get baud bits
  4974.     mov    si,offset unkbaud    ; assume unknown baud
  4975.     mov    cx,size m_baud        ; length of baud space
  4976.     cmp    al,baudnsiz        ; beyond end of table?
  4977.     jnb    modl2            ; nb = yes, use default
  4978.     mul    cl
  4979.     xor    ah,ah
  4980.     add    ax,offset baudn
  4981.     mov    si,ax
  4982. modl2:    mov    di,offset modbuf.m_baud
  4983.     cld
  4984.     rep    movsb            ; copy in baud rate
  4985.     mov    bx,portval
  4986.     mov    al,[bx].parflg        ; get parity code
  4987.     and    al,3            ; regular parity uses two bits
  4988.     mov    ah,al
  4989.     shl    al,1            ; each is 3 bytes long
  4990.     add    al,ah
  4991.     xor    ah,ah
  4992.     add    ax,offset parnams    ; names of parity settings
  4993.     mov    si,ax
  4994.     mov    cx,3            ; each is 3 long
  4995.     mov    di,offset modbuf.m_par
  4996.     push    di
  4997.     rep    movsb
  4998.     pop    di
  4999.     test    [bx].parflg,PARHARDWARE    ; using hardware parity?
  5000.     jz    modl2b            ; z = no
  5001.     mov    al,'8'            ; say 8 data bits
  5002.     stosb
  5003.     jmp    short modl2a
  5004.  
  5005. modl2b:    cmp    byte ptr [di],'8'    ; any parity?
  5006.     jne    modl2a            ; ne = yes, use existing '7'
  5007.     test    flags.remflg,d8bit    ; 8 bit display?
  5008.     jnz    modl2a            ; nz = yes
  5009.     mov    al,'7'
  5010.     stosb                ; overwrite '8' with '7'
  5011. modl2a:    mov    si,offset remmsg    ; assume remote echoing
  5012.     test    yflags,lclecho        ; local echo on?
  5013.     jz    modl3            ; z = no
  5014.     mov    si,offset lclmsg    ; say echo is local
  5015. modl3:    mov    cx,3            ; size of value
  5016.     mov    di,offset modbuf.m_echo
  5017.     rep    movsb
  5018.     mov    al,portno        ; communications port
  5019.     cmp    al,' '            ; binary (non-printable)?
  5020.     jae    modl4            ; ae = no, ascii
  5021.     add    al,'0'            ; convert to ascii
  5022. modl4:    mov    modbuf.m_prt,al        ; fill in port number
  5023.     mov    al,portno
  5024.     cmp    repflg,0        ; REPLAY?
  5025.     je    modl5            ; e = no
  5026.     mov    si,offset repmsg    ; say "REPLAY"
  5027.     mov    cx,repmsgl        ; its length
  5028.     mov    di,offset modbuf.m_prt
  5029.     mov    al,' '            ; start with a space
  5030.     stosb
  5031.     mov    dx,24            ; space to be filled
  5032.     sub    dx,cx            ; amount we will use here
  5033.     rep    movsb            ; copy string
  5034.     mov    cx,dx
  5035.     rep    stosb            ; flesh out with spaces
  5036.     jmp    modl10
  5037.  
  5038. modl5:    cmp    al,'4'            ; in networks material?
  5039.     jbe    modl10            ; be = no
  5040. ifndef    no_tcp
  5041.     cmp    flags.comflg,'t'    ; doing TCP/IP Telnet?
  5042.     jne    modl5d            ; ne = no
  5043.     mov    si,offset tcphost    ; name of host
  5044.     mov    di,offset modbuf.m_prt - 5 ; overwrite "port:"
  5045. ifdef    nls_portuguese
  5046.     dec    di            ; "porta:"
  5047. endif    ; nls_portuguese
  5048.  
  5049. modl5c:    mov    ax,sescur        ; ident of session
  5050.     add    al,'1'            ; ascii, show as 1:nodename
  5051.     mov    ah,':'
  5052.     stosw                ; store that much
  5053.     mov    cx,28            ; bytes max
  5054. modl5a:    lodsb
  5055.     or    al,al             ; at null terminator?
  5056.     jz    modl5b            ; z = yes
  5057.     stosb
  5058.     loop    modl5a
  5059. modl5b:    mov    al,' '            ; fill out with spaces
  5060.     rep    stosb            ; noop if cx == 0
  5061.     jmp    short modl5d        ; done with tcp/ip 
  5062. endif    ; no_tcp
  5063.  
  5064. modl5d:    mov    bx,offset comptab    ; table of comms ports
  5065.     mov    cl,[bx]            ; number of entries
  5066.     xor    ch,ch
  5067.     inc    bx
  5068. modl6:    mov    dx,[bx]            ; length of this entry
  5069.     mov    si,bx
  5070.     add    si,2            ; points to entry text string
  5071.     add    si,dx            ; point to qualifier
  5072.     cmp    [si],al            ; our port?
  5073.     je    modl7            ; e = yes
  5074.     add    bx,[bx]            ; add text length
  5075.     add    bx,4            ; plus count and qualifier
  5076.     loop    modl6            ; next entry
  5077.     jmp    short modl10        ; no match, curious
  5078. modl7:    mov    si,bx            ; point at entry
  5079.     add    si,2            ; point at string
  5080.     mov    cx,[bx]            ; length of string
  5081.     mov    di,offset modbuf.m_prt
  5082.     mov    al,' '            ; start with a space
  5083.     stosb
  5084.     mov    dx,17            ; space to be filled
  5085. ifdef    nls_portuguese
  5086.     dec    dx
  5087. endif    ; nls_portuguese
  5088.     sub    dx,cx            ; amount we will use here
  5089.     rep    movsb            ; copy string
  5090.  
  5091.     cmp    flags.comflg,'F'    ; Fossil?
  5092.     jne    modl9            ; ne = no
  5093.     mov    al,'-'            ; punctuation
  5094.     stosb
  5095.     mov    ax,fossil_port        ; port
  5096.     inc    ax            ; count from one to user
  5097.     push    dx            ; preserve reg for below
  5098.     call    dec2di            ; write port
  5099.     pop    dx
  5100.     sub    dx,2            ; dash and digit
  5101.     add    di,2
  5102.     cmp    fossil_port,9        ; two digits?
  5103.     jbe    modl9            ; be = no
  5104.     dec    dx            ; yes, one less slot
  5105.     inc    di
  5106.  
  5107. modl9:    mov    cx,dx
  5108.     mov    al,' '
  5109.     rep    stosb            ; flesh out with spaces
  5110. modl10:    mov    cx,8            ; blank out terminal id field
  5111.     mov    si,offset mtty        ; assume no terminal emulation
  5112.     mov    di,offset modbuf.m_term ; destination
  5113.     rep    movsb            ; copy it in
  5114.     mov    word ptr modbuf.m_prn,'  '; assume not printing the screen
  5115.     mov    modbuf.m_prn+2,' '
  5116.     test    anspflg,prtscr+2    ; print the screen? (msz uses 1 & 2)
  5117.     jz    modl10a            ; z = no
  5118.     mov    word ptr modbuf.m_prn,'RP' ; yes. display PRN at end of line
  5119.     mov    modbuf.m_prn+2,'N'
  5120. modl10a:mov    modbuf.m_comp,' '    ; flag for not-compose
  5121.     cmp    grab,0            ; doing Compose grabbing?
  5122.     je    modl11            ; e = no
  5123.     mov    modbuf.m_comp,'C'    ; flag for compose
  5124. modl11:    cmp    inemulator,0        ; in terminal emulator now?
  5125.     jne    modl11a            ; ne = yes
  5126.     pop    es            ; do nothing
  5127.     pop    di
  5128.     pop    si
  5129.     ret
  5130. modl11a:push    dx
  5131.     cmp    flags.vtflg,0        ; emulating?
  5132.     je    modl12            ; e = no
  5133.     and    yflags,not modoff    ; update local flags (mode line on)
  5134.     call    fansdsl            ; get extras from emulator
  5135. modl12:    mov    dx,offset modbuf    ; mode line image ptr for putmod
  5136.     call    putmod            ; display mode line
  5137.     mov    dx,cursor        ; restore active cursor position
  5138.     call    fsetpos            ; set cursor
  5139.     pop    dx
  5140.     pop    es
  5141.     pop    di
  5142.     pop    si
  5143.     ret
  5144. modlin    endp
  5145.  
  5146. fmodlin    proc    far
  5147.     call    modlin
  5148.     ret
  5149. fmodlin    endp
  5150.  
  5151. ; toggle between text and graphics modes
  5152. vtans52 proc    near
  5153.     cmp    flags.vtflg,0        ; emulating?
  5154.     je    vtans52a        ; e = no
  5155.     call    ans52t            ; call MSZ toggle-it routine
  5156.     cmp    flags.vtflg,tttek    ; Tek now?
  5157.     je    vtans52a        ; e = yes
  5158.     test    tekflg,tek_tek+tek_dec+TEK_SG     ; Tek submode?
  5159.     jnz    vtans52a        ; nz = yes
  5160.     call    scrini            ; check on screen size changes
  5161. vtans52a:clc                ; clear c bit so don't exit Connect
  5162.     ret
  5163. vtans52 endp
  5164.  
  5165. ftrnprs proc    far
  5166.     call    trnprs
  5167.     ret
  5168. ftrnprs    endp
  5169.  
  5170. trnprs    proc    near
  5171.     push    ax            ; toggle ^ PrtSc screen to printer
  5172.     test    anspflg,prtscr        ; are we currently printing?
  5173.     jnz    trnpr2            ; nz = yes, its on and going off
  5174.     push    bx
  5175.     mov    bx,prnhand        ; file handle for system printer
  5176.     mov    ah,ioctl
  5177.     mov    al,7            ; get output status of printer
  5178.     int    dos
  5179.     pop    bx
  5180.     jc    trnpr1            ; c = printer not ready
  5181.     cmp    al,0ffh            ; Ready status?
  5182.     je    trnpr2            ; e = Ready    
  5183. trnpr1:    call    fvtbell            ; Not Ready, complain
  5184. ;    pop    ax
  5185. ;    stc                ; say failure
  5186. ;    ret                ; and ignore request
  5187. trnpr2:    xor    anspflg,prtscr        ; flip the flag
  5188.     test    yflags,modoff        ; mode line off?
  5189.     jnz    trnpr3            ; nz = yes
  5190.     call    fmodlin            ; else rewrite mode line
  5191. trnpr3:    pop    ax
  5192.     clc                ; return carry clear (don't quit)
  5193.     ret
  5194. trnprs    endp
  5195. code    ends
  5196.  
  5197. code1    segment
  5198.     assume    cs:code1
  5199.  
  5200. pntdead    proc    near            ; display printer is inoperative msg
  5201.     push    ax
  5202.     test    yflags,modoff        ; is mode line off?
  5203.     jnz    pntdea1            ; nz = off, skip msg
  5204.     push    bx
  5205.     mov    dx,offset pntmsg    ; say printer not ready
  5206.     call    fputmod            ; write on mode line
  5207.     pop    bx
  5208. pntdea1:pop    ax
  5209.     stc                ; say printer not ready
  5210.     ret
  5211. pntdead    endp
  5212.  
  5213. endif    ; no_terminal
  5214.  
  5215. ;;;;; General screen management routines for IBM PC
  5216.  
  5217. ; computes screen location to ax, given row and col in [dh,dl], resp.
  5218.  
  5219. scrloc    proc    near
  5220.     push    cx
  5221.     mov    cl,crt_cols
  5222.     cmp    inemulator,0        ; emulating?
  5223.     je    scrloc1            ; e = no
  5224.     cmp    flags.vtflg,0        ; emulating anything?
  5225.     je    scrloc1            ; e = no
  5226.     mov    cl,vswidth
  5227. scrloc1:mov    al,dh            ; get row
  5228.     mul    cl            ; multiply by number of columns
  5229.     add    al,dl            ; plus current column number
  5230.     adc    ah,0            ; ripple carry
  5231.     shl    ax,1            ; double for attributes
  5232.     pop    cx
  5233.     ret
  5234. scrloc    endp
  5235.  
  5236. ; Routine to set cursor type.  Pass cursor type in al: 0,4 = No cursor,
  5237. ; 1 = Underline cursor, 2 = Block cursor.   All cursors blink due to hardware.
  5238. ; For EGA boards running in non-25 line mode the cursor emulation is turned
  5239. ; off during cursor shape changing and restored afterward. It's another
  5240. ; ega Feature. [jrd]
  5241. ; Sense crt_mode 18h as Tseng Labs UltraPAK mono board in 132 column mode.
  5242. csrtype proc    near
  5243.     push    cx            ; save the reg
  5244.     mov    cx,0F00H        ; assume no cursor
  5245.     test    al,4            ; no cursor?
  5246.     jz    csrtyp6            ; z = no
  5247.     xor    al,al            ; set type to invisible
  5248. csrtyp6:or    al,al            ; no cursor?
  5249.     jz    csrty2            ; z = yes, no cursor
  5250.     cmp    crt_mode,7        ; B&W card?
  5251.     je    csrty3            ; e = yes, different sizes
  5252.     cmp    crt_mode,18h        ; Tseng UltraPAK mono board?
  5253.      je    csrty3            ; e = yes, use mono cursor
  5254.     mov    cx,0607H        ; use CGA underline cursor
  5255.     cmp    al,2            ; Block?
  5256.     jne    csrty2            ; ne = no, set it now
  5257. csrty1: xor    ch,ch            ; make cursor a block
  5258. csrty2:    cmp    ega_mode,0        ; ega board active?
  5259.     je    csrty4            ; e = no
  5260.     test    tv_mode,10h        ; DV active?
  5261.     jnz    csrty4            ; nz = yes, it messes with the cursor
  5262.     cmp    byte ptr low_rgt+1,23    ; standard screen length?
  5263.     je    csrty4            ; e = yes, use regular cursor setting
  5264.     cmp    byte ptr low_rgt+1,24    ; ANSI, standard screen length?
  5265.     je    csrty4            ; e = yes, use regular cursor setting
  5266.     push    es            ; EGA. turn off cursor emulation
  5267.     mov    ax,40h            ; 40:87h is ega Info byte
  5268.     mov    es,ax
  5269.     push    es:[87h]        ; save Info byte around call
  5270.     or    byte ptr es:[87h],1    ; set emulation off (low bit = 1)
  5271.     mov    ah,1            ; video function for set cursor type
  5272.     int    screen
  5273.     pop    es:[87h]        ; restore Info byte
  5274.     pop    es            ;  and our work register
  5275.     pop    cx
  5276.     ret
  5277.  
  5278. csrty4:    push    ax
  5279.     mov    ah,1            ; video function for set cursor type
  5280.     int    screen            ; regular cursor shape setting
  5281.     pop    ax
  5282. csrty5:    pop    cx
  5283.     ret
  5284.  
  5285. csrty3: mov    cx,0B0CH        ; assume B&W underline cursor
  5286.     cmp    al,2            ; Block?
  5287.     jne    csrty2            ; ne = no, set it now
  5288.     jmp    short csrty1        ; make it a block
  5289. csrtype endp
  5290.  
  5291. fcsrtype proc    far
  5292.     call    csrtype
  5293.     ret
  5294. fcsrtype endp
  5295.  
  5296. ; Get CRT mode - returns mode in variable crt_mode,
  5297. ; updates crt_cols, and low_rgt.
  5298. ; For EGA active it looks in Bios work memory 40:84H for number of rows
  5299. scrmod    proc    near
  5300.     push    ax
  5301.     push    dx
  5302.     mov    ah,0fh            ; get current video state
  5303.     int    screen
  5304.     and    al,not 80h        ; strip "preserve regen" bit 80h
  5305.     mov    crt_mode,al        ; store CRT mode value
  5306.     mov    crt_cols,ah        ; store # of cols
  5307.     mov    dl,ah            ; # of cols again
  5308.     mov    dh,crt_lins        ; and # of rows (constant from msster)
  5309.     cmp    tv_mode,0        ; Topview active?
  5310.     je    scrmod2            ; e = no
  5311.     test    tv_mode,20h        ; Japanese DOS active?
  5312.     jnz    scrmod2            ; nz = yes, do not do Int 15h
  5313.     push    cx
  5314.     push    bx
  5315.     mov    ah,12h            ; TV, Get Object Length
  5316.     mov    bx,0901h        ; object, BL = 01 = chars/line
  5317.     int    15h
  5318.     pop    ax            ; chars/line from stack dword
  5319.     cmp    al,10            ; keep things sane, chars per line
  5320.     ja    scrmod7            ; a = might be sane
  5321.     pop    ax            ; clean stack
  5322.     jmp    scrmod2            ; wacko, ignore DV stuff
  5323.  
  5324. scrmod7:mov    crt_cols,al        ; TV windowed screen columns
  5325.     pop    ax            ; clear rest of dword from stack
  5326.     mov    ah,12h            ; send
  5327.     mov    bx,1            ; handle (0*256) + window (me, 1)
  5328.     int    15h
  5329.     pop    bx            ; handle low word
  5330.     pop    bx            ; handle high word to BX for next call
  5331.     mov    ax,1024h        ; TV Get Virtual Screen Info
  5332.     int    15h            ; can yield 8KB, yikes
  5333. scrmod1:cmp    cx,80*25*2        ; get sanity for DV big DOS window
  5334.     jbe    scrmod1a        ; be = reasonable size
  5335.     shr    cx,1            ; reduce size
  5336.     jmp    short scrmod1        ;  and try again
  5337. scrmod1a:mov    ax,cx            ; CX is virtual screen size, bytes
  5338.     mov    bl,crt_cols        ; divide by columns to get width
  5339.     shl    bl,1            ; get words (char and attribute)
  5340.     div    bl            ; al = lines, ah = fractions of line
  5341.     dec    al            ; count this from zero like the Bios
  5342.     mov    crt_lins,al        ; visible screen lines -1 (24)
  5343.     mov    dh,al
  5344.     mov    dl,crt_cols        ; visible screen columns (80)
  5345.     pop    bx
  5346.     pop    cx
  5347.     jmp    short scrmod4
  5348.  
  5349. scrmod2:cmp    ega_mode,0        ; ega active?
  5350.     je    scrmod4            ; e = no
  5351.     push    es            ; yes, permit different lengths
  5352.     mov    ax,40h            ; refer to 40:84h for # ega rows
  5353.     mov    es,ax
  5354.     mov    ah,es:[84h]        ; get number of rows - 1 (typ 24)
  5355.     cmp    ah,20            ; less than 20 rows?
  5356.     jb    scrmod3            ; b = yes, ignore this length
  5357.     cmp    ah,80            ; more than 80 rows?
  5358.     ja    scrmod3            ; a = yes, ignore this length
  5359.     mov    dh,ah            ; use this length
  5360.     mov    dos_bottom,dh        ; remember for DOS screen pager
  5361. ifndef    no_terminal
  5362.     cmp    flags.vtflg,ttansi    ; ANSI?
  5363.     jne    scrmod2b        ; ne = no
  5364.     inc    dh            ; make mode line a regular text line
  5365.     mov    flags.modflg,2        ; mode line enabled and owned by host
  5366. scrmod2b:cmp    isps55,0        ; [HF]940206 is Japanese PS/55 ?
  5367.     je    scrmo2a            ; [HF]940206 e = no
  5368.     cmp    ps55mod,0        ; [HF]940206 can we use modeline?
  5369.     jne    scrmo2a            ; [HF]940206 ne = yes
  5370.     inc    dh            ; [HF]940206 no, add modeline
  5371. endif    ; no_terminal
  5372. scrmo2a:mov    crt_lins,dh        ; update our working constant
  5373. scrmod3:pop    es
  5374. scrmod4:dec    dl            ; max text column, count from zero
  5375.     dec    dh            ; max text row, count from zero
  5376. ifndef    no_terminal
  5377.     cmp    flags.vtflg,ttgenrc    ; no terminal emulation
  5378.     je    scrmod6            ; e = yes
  5379.     cmp    tekflg,tek_active+tek_sg ; doing special graphics?
  5380.     jne    scrmod4a        ; ne = no
  5381.     mov    crt_cols,128        ; VT style special graphics uses this
  5382. scrmod4a:
  5383.     cmp    crt_cols,80        ; doing wide now?
  5384.     ja    scrmod5            ; a = yes
  5385.     mov    dl,80-1            ; assume 80 column width
  5386.     test    vtemu.vtflgop,deccol    ; 132 column mode set?
  5387.     jz    scrmod6            ; z = no
  5388. scrmod5:mov    dl,132-1        ; set to 132 column mode
  5389.  
  5390. endif    ; no_terminal
  5391.  
  5392. scrmod6:mov    low_rgt,dx        ; save away window address
  5393.     pop    dx
  5394.     pop    ax
  5395.     ret
  5396. scrmod    endp
  5397.  
  5398. ; Get screen segment. Returns screen segment in ax, and full address in es:di
  5399. scrseg    proc    near
  5400.     xor    di,di            ; start at beginning of screen (0,0)
  5401.     mov    ax,0B800H        ; video memory is here on color
  5402.     cmp    crt_mode,7        ; normal color modes?
  5403.     jb    scrse1            ; b = yes
  5404.     mov    ax,0B000H        ; assume B&W card
  5405.     cmp    crt_mode,12        ; 
  5406.     jb    scrse1
  5407.     cmp    crt_mode,18h        ; Tseng UltraPAK mono in 132 col?
  5408.     je    scrse1            ; e = yes, use seg B000H
  5409.     cmp    crt_mode,56h        ; Paradise EGA Mono in 132x43 mode?
  5410.     je     scrse1            ; e = yes, use seg B000H
  5411.     cmp    crt_mode,57h        ; Paradise EGA Mono in 132x25 mode?
  5412.     je    scrse1            ; e = yes, use seg B000H
  5413.     mov    ax,0B800H        ; video memory is here on color
  5414.     cmp    crt_mode,18        ; end of ordinary 640x480 graphics
  5415.     ja    scrse1            ; a = no, assume CGA segment
  5416.     mov    ax,0A000H        ; graphics
  5417. scrse1:    mov    es,ax        ; tell Topview our hardware address needs
  5418.     mov    tv_segs,es        ; save our hardware screen address
  5419.     mov    tv_sego,di        ; segment and offset form
  5420.     or    tv_mode,1        ; assume we're running under Topview
  5421.     mov    ah,tvhere        ; query Topview for its presence
  5422.     int    screen
  5423.     mov    ax,es            ; get its new segment for screen work
  5424.     cmp    ax,tv_segs        ; same as hardware?
  5425.     jne    scrse2            ; ne = no, we are being mapped
  5426.     cmp    di,tv_sego        ; check this too
  5427.     jne    scrse2        ; ne = no too. Use TV's work buf as screen
  5428.     and    tv_mode,not 1        ; else no Topview or no mapping
  5429. scrse2:    mov    tv_segs,es        ; save segment
  5430.     mov    tv_sego,di        ; and offset
  5431.     ret
  5432. scrseg    endp
  5433.  
  5434. ; Synchronize a Topview provided virtual screen buffer with the image
  5435. ; seen by the user. Requires cx = number of words written to screen
  5436. ; (char & attribute bytes) and es:di = ENDING address of screen write.
  5437. ; Changes ax and di. Skip operations for DESQview
  5438. scrsync proc    near
  5439.     cmp    tv_mode,0        ; Topview mode active?
  5440.     je    scrsyn1            ; e = no, skip Bios call below
  5441.     push    ax
  5442.     push    cx
  5443.     push    di
  5444.     sub    di,cx            ; backup to start byte (cx = words)
  5445.     sub    di,cx            ;  after storing words to screen
  5446.     mov    ah,tvsynch        ; tell Topview we have changed screen
  5447.     int    screen            ;  so user sees updated screen
  5448.     pop    di
  5449.     pop    cx
  5450.     pop    ax
  5451. scrsyn1:ret
  5452. scrsync endp
  5453.  
  5454. ; The following two routines are used to turn off the display while we
  5455. ; are reading or writing the screen in one of the color card modes.
  5456. ; Turn screen off for (known) color card modes only. All regs preserved.
  5457. ; Includes code for old procedure scrwait. 16 June 1987 [jrd]
  5458. scroff    proc    near
  5459.     cmp    ega_mode,0        ; Extended Graphics Adapter in use?
  5460.     jne    scrofx            ; ne = yes, no waiting
  5461.     cmp    tv_mode,0        ; Topview mode?
  5462.     jne    scrofx            ; ne = yes, no waiting
  5463.     cmp    crt_mode,7        ; B&W card?
  5464.     jnb    scrofx            ; nb = yes - just return
  5465.     cmp    refresh,0        ; slow refresh?
  5466.     jne    scrofx            ; ne = no wait
  5467.     push    ax            ; save ax and dx
  5468.     push    dx
  5469.     mov    dx,crt_status        ; CGA: Wait for vertical retrace
  5470. scrof1:    in    al,dx
  5471.     test    al,disp_enb        ; display enabled?
  5472.     jnz    scrof1            ; yes, keep waiting
  5473. scrof2:    in    al,dx
  5474.     test    al,disp_enb        ; now wait for it to go off
  5475.     jz    scrof2            ; so can have whole cycle
  5476.     mov    dx,crtmset        ; output to CRT mode set port
  5477.     mov    al,25H            ; this shuts down the display
  5478.     out    dx,al
  5479.     pop    dx            ; restore regs
  5480.     pop    ax
  5481. scrofx: ret
  5482. scroff    endp
  5483.  
  5484.  
  5485. ; Turn screen on for (known) color card modes only
  5486. ; All registers are preserved.
  5487.  
  5488. scron    proc    near
  5489.     cmp    ega_mode,0        ; Extended Graphics Adapter in use?
  5490.     jne    scronx            ; ne = yes, no waiting
  5491.     cmp    tv_mode,0        ; Topview mode?
  5492.     jne    scronx            ; ne = yes, no waiting
  5493.     cmp    crt_mode,7        ; B&W card?
  5494.     jnb    scronx            ; nb = yes - just return
  5495.     cmp    refresh,0        ; slow refresh?
  5496.     jne    scronx            ; ne = no wait
  5497.     push    ax            ; save ax, dx, and si
  5498.     push    dx
  5499.     push    si
  5500.     mov    al,crt_mode        ; convert crt_mode to a word
  5501.     xor    ah,ah
  5502.     mov    si,ax            ; get it in a usable register
  5503.     mov    al,msets[si]        ; fetch the modeset byte
  5504.     mov    dx,crtmset        ; this port
  5505.     out    dx,al            ; flash it back on
  5506.     pop    si
  5507.     pop    dx
  5508.     pop    ax
  5509. scronx: ret
  5510. scron    endp
  5511.  
  5512. ifndef    no_terminal
  5513. ; Determine screen roll back buffer parameters depending on current screen
  5514. ; dimensions and available memory. Each rollback screen line has its own
  5515. ; segment (lines start on segment boundaries for rollback). One full screen
  5516. ; must be allocated to hold the current display, deduct this from lmax.
  5517.  
  5518. bufadj    proc    near
  5519.     push    bx
  5520.     push    cx
  5521.     push    dx
  5522.     mov    bx,rollwidth        ; rollback line width
  5523.     add    bx,7            ; (BDT) round up to paragraph boundary
  5524.     mov    cl,3            ; (BDT) now convert to
  5525.     shr    bx,cl            ; (BDT) paragraphs / line
  5526.     mov    ppl,bx            ; (BDT) save this in buffer area
  5527.     xor    dx,dx            ; high order dividend, clear it
  5528.     cmp    emsrbhandle,0        ; using EMS?
  5529.     jle    bufadj2            ; le = no (-1 means not used)
  5530.     mov    ax,1024            ; 1024 paragraphs per ems 16KB page
  5531.     div    bx            ; divide by paragraphs per line
  5532.     mov    lineems,ax        ; lines per ems page, remember
  5533.     mul    inipara            ; times number of ems pages
  5534.     jmp    short bufadj3        ; ax has number of lines
  5535.                     ; conventional memory
  5536. bufadj2:mov    ax,inipara        ; (BDT) compute the number of lines
  5537.     div    bx            ; (BDT)  in the buffer
  5538.  
  5539. bufadj3:mov    lmax,ax            ; max line capacity of the buffer
  5540.     mov    linee,ax        ; (BDT) save as number of total lines
  5541.     or    ax,ax            ; have any lines?
  5542.     jz    bufadj1            ; z = no, no space at all
  5543.     xor    bh,bh            ; (BDT) get lines / screen
  5544.     mov    bl,byte ptr low_rgt+1    ; (BDT) rows on user/host screen
  5545.     inc    bx            ; (BDT) adjust for counting from 0
  5546.     sub    lmax,bx            ; minus master "current" screen
  5547.     jg    bufadj1            ; g = have some rollback space
  5548.     mov    lmax,0            ; say none
  5549. bufadj1:mov     lcnt,0                  ; (BDT) # of lines filled in buffer
  5550.     mov    linef,0            ; (BDT) first filled in line
  5551.     mov    linec,0            ; (BDT) last  filled in line
  5552.     pop    dx
  5553.     pop    cx
  5554.     pop    bx
  5555.     ret
  5556. bufadj    endp
  5557. endif    ; no_terminal
  5558.  
  5559. ; Test for DESQview in operation, set tv_mode bit 10h to non-zero if so.
  5560. dvtest    proc    near
  5561.     and    tv_mode,not 30h        ; assume no DV and no Japanese DOS
  5562. ifndef    no_terminal
  5563.     cmp    isps55,0        ; [HF] 940130 Japanese PS/55 ?
  5564.     je    dvtest4            ; [HF] 940130 no
  5565.     or    tv_mode,30h        ; [HF] 940205 say Japanese & DV
  5566.     ret                ; [HF]  do not use Int 15h for Japan
  5567. endif    ; no_terminal
  5568. dvtest4:xor    bx,bx            ; for version number
  5569.     mov    cx,'DE'            ; DV signature
  5570.     mov    dx,'SQ'
  5571.     mov    ax,2B01h        ; DOS set date (with illegal value)
  5572.     int    dos
  5573.     cmp    al,0ffh            ; DOS should say invalid if no DV
  5574.     je    dvtest2            ; e = yes, invalid so no DV
  5575.     cmp    bx,2            ; DV version 2.00?
  5576.     jne    dvtest1            ; ne = no
  5577.     xchg    bh,bl            ; get major version into bh
  5578. dvtest1:or    tv_mode,10h        ; say using DV
  5579. dvtest2:ret
  5580. dvtest    endp
  5581.  
  5582. ; Execute DESQview function call provided in BX.
  5583. dvcall    proc    near
  5584.     push    ax
  5585.     mov    ax,101ah        ; switch to DV stack
  5586.     int    15h
  5587.     mov    ax,bx            ; function to do
  5588.     int    15h
  5589.     mov    ax,1025h        ; switch from DV stack
  5590.     int    15h
  5591.     pop    ax
  5592.     ret
  5593. dvcall    endp
  5594.  
  5595. ; Call this to release the cpu during idle times
  5596. dvpause    proc    near
  5597.     cmp    vtcpumode,0        ; timeslice-release enabled?
  5598.     jne    dvpaus2            ; ne = no
  5599.     test    tv_mode,10h        ; in DV?
  5600.     jz    dvpaus1            ; z = no
  5601.     push    bx
  5602.     mov    bx,1000h        ; say release control
  5603.     call    dvcall            ; to DV
  5604.     pop    bx
  5605. dvpaus1:cmp    byte ptr dosnum+1,5    ; DOS verson, major high, minor low
  5606.     jb    dvpaus2            ; b = too old for this operation
  5607.     mov    ax,1680h        ; release current virtual machine
  5608.     int    2fh            ;  time slice (Windows, OS/2, DPMI)
  5609. dvpaus2:ret
  5610. dvpause    endp
  5611.  
  5612. ; Screen clearing routine
  5613. ; Call:    ax = coordinates of first screen location to be cleared.
  5614. ;    bx = coordinates of last location to be cleared.
  5615. ; Coord: ah = row [0-24], al = column [0-206]. Preserves all registers.
  5616.  
  5617. atsclr    proc    near
  5618.     cmp    ax,bx            ; correct order?
  5619.     jbe    atsclr9            ; be = yes
  5620.     xchg    ax,bx            ; larger to bx
  5621. atsclr9:push    ax            ; save regs 
  5622.     push    cx
  5623.     push    dx
  5624.     mov    dx,bx            ; compute last screen offset from bx
  5625.     push    ax
  5626.     call    scrloc            ; get screen start address in ax
  5627.     mov    cx,ax            ; save it in cx for a minute
  5628.     pop    dx            ; compute first screen offset in ax
  5629.     call    scrloc
  5630.     sub    cx,ax            ; compute number of locs to clear
  5631.     add    cx,2            ; +1 for span, +1 for round up
  5632.     sar    cx,1            ; make byte count a word count
  5633.     jle    atscl3            ; le = nothing to clear
  5634.     push    di            ; save regs
  5635.     push    es            ; save es
  5636. ifndef    no_terminal
  5637.     cmp    inemulator,0        ; in terminal emulator now?
  5638.     je    atscl1            ; e = no
  5639.     cmp    flags.vtflg,0        ; emulating anything?
  5640.     je    atscl1            ; e = no, using DOS
  5641.     les    di,vs_ptr        ; es:di is virtual screen
  5642.     jmp    short atscl2
  5643. endif    ; no_terminal
  5644. atscl1:    push    ax            ; save displacement
  5645.     call    scroff            ; turn screen off if color card
  5646.     call    scrseg            ; get address of screen into es:di
  5647.     pop    ax
  5648. atscl2:    add    di,ax            ; location in buffer
  5649.     mov    ah,scbattr        ; use current screen background attr
  5650.     mov    al,' '            ; use space for fill
  5651.     push    cx            ; save word count for Topview
  5652.     cld
  5653.     rep    stosw            ; copy to screen
  5654.     pop    cx            ; recover word count
  5655. ifndef    no_terminal
  5656.     cmp    inemulator,0        ; in terminal emulator now?
  5657.     je    atscl2a            ; e = no
  5658.     cmp    flags.vtflg,0        ; emulating anything?
  5659.     jne    atscl2b            ; ne = yes
  5660. endif    ; no_terminal
  5661. atscl2a:call    scron            ; turn screen back on if color card
  5662.     call    scrsync            ; synch Topview
  5663. atscl2b:pop    es
  5664.     pop    di
  5665. atscl3:    pop    dx
  5666.     pop    cx
  5667.     pop    ax            ; back to regs at call time
  5668. ifndef    no_terminal
  5669.     cmp    inemulator,0        ; in terminal emulator now?
  5670.     je    atscl6            ; e = no
  5671.     cmp    flags.vtflg,0        ; emulating anything?
  5672.     je    atscl6            ; e = no, using DOS
  5673.     push    dx            ; do extended attributes
  5674.     push    ax
  5675.     push    bx
  5676.     push    cx
  5677.     mov    dx,ax            ; starting place
  5678.     mov    al,dh            ; row
  5679.     mov    cl,vswidth        ; row char cells
  5680.     mul    cl
  5681.     add    al,dl            ; plus starting column
  5682.     adc    ah,0            ; char cells to starting place
  5683.     mov    dx,ax            ; save here
  5684.     mov    al,bh            ; ending row
  5685.     mul    cl
  5686.     add    al,bl            ; plus ending column
  5687.     adc    ah,0
  5688.     mov    bx,ax
  5689.     sub    bx,dx            ; number of cells -1 to clear
  5690.     inc    bx
  5691.     mov    cx,bx            ; cx = cells to clear
  5692.     xchg    bx,dx            ; bx = start offset, dx=cells
  5693.     push    es
  5694.     push    di
  5695.     les    di,vsat_ptr        ; where attributes are stored
  5696.     add    di,bx            ; offset plus start byte
  5697.     xor    ax,ax
  5698.     cld
  5699.     shr    cx,1
  5700.     jnc    atscl4
  5701.     stosb
  5702. atscl4:    rep    stosw            ; clear those bytes
  5703. ;;;    mov    extattr,0        ; and the extension byte too
  5704.     pop    di
  5705.     pop    es
  5706.     pop    cx
  5707.     pop    bx
  5708.     pop    ax
  5709.     mov    dl,ah            ; first row
  5710.     mov    dh,bh            ; last row
  5711.     call    touchup            ; repaint this part of the screen
  5712.     pop    dx            ; finish cleaning stack
  5713. endif    ; no_terminal
  5714. atscl6:    ret
  5715. atsclr    endp
  5716.  
  5717. ifndef    no_terminal
  5718. ; Screen-scrolling routines.
  5719.      
  5720. fhomwnd    proc    far            ; "home" to start of the buffer
  5721.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5722.     inc    cl            ; full text screen
  5723.     xor    ch,ch
  5724.     call    putcirc            ; save them
  5725.     mov    linec,0            ; reset the current pointer
  5726.     call    getcirc            ; now get the new screen
  5727.     clc
  5728.     ret
  5729. fhomwnd    endp
  5730.      
  5731. fendwnd    proc    far            ; "end" to end of the buffer
  5732.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5733.     inc    cl            ; full text screen
  5734.     xor    ch,ch
  5735.     call    putcirc            ; save them
  5736.     mov    ax,lcnt            ; reset the current pointer
  5737.     mov    linec,ax        ; save the results
  5738.     call    getcirc            ; now get the new screen
  5739.     clc
  5740.     ret
  5741. fendwnd    endp
  5742.      
  5743. fdnwpg    proc    far            ; scroll down 1 page
  5744.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5745.     inc    cl            ; full text screen
  5746.     xor    ch,ch
  5747.     call    putcirc            ; save them
  5748.     mov    ax,linec        ; reset the current pointer
  5749.     add    ax,cx
  5750.     cmp    ax,lcnt            ; did we go past the end?
  5751.     jbe    dnwpg1            ; be = no, we're OK
  5752.     mov    ax,lcnt            ; yup, back up
  5753. dnwpg1:    mov    linec,ax        ; save the results
  5754.     call    getcirc            ; now get the new screen
  5755.     clc
  5756.     ret
  5757. fdnwpg    endp
  5758.      
  5759. fdnone    proc    far            ; scroll down 1 line
  5760.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5761.     inc    cl            ; full text screen
  5762.     xor    ch,ch
  5763.     call    putcirc            ; save them
  5764.     mov    ax,linec        ; reset the current pointer
  5765.     inc    ax            ;  to the next line
  5766.     cmp    ax,lcnt            ; oops, did we go past the end?
  5767.     jbe    dnone1            ; be = no, we're OK
  5768.     mov    ax,lcnt            ; yup, back up
  5769. dnone1:    mov    linec,ax        ; save the results
  5770.     call    getcirc            ; now get the new screen
  5771.     clc
  5772.     ret
  5773. fdnone    endp
  5774.      
  5775. fupwpg    proc    far            ; scroll up 1 page
  5776.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5777.     inc    cl            ; full text screen
  5778.     xor    ch,ch
  5779.     call    putcirc            ; save a full screen
  5780.     mov    ax,linec        ; reset the current pointer
  5781.     sub    ax,cx            ;  to the previous page
  5782.     jge    upwpg1            ; ge = not past end, we're OK
  5783.     xor    ax,ax            ; stop at the beginning of the buffer
  5784. upwpg1:    mov    linec,ax        ; line counter to use
  5785.     call    getcirc            ; get the new screen
  5786.     clc
  5787.     ret
  5788. fupwpg    endp
  5789.      
  5790. fupone    proc    far            ; scroll up 1 line
  5791.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5792.     inc    cl            ; full text screen
  5793.     xor    ch,ch
  5794.     call    putcirc            ; save them
  5795.     mov    ax,linec        ; reset the current pointer
  5796.     sub    ax,1            ;  to the previous line
  5797.     jge    upone1            ; ge = not past end, we're OK
  5798.     xor    ax,ax            ; yup, back up
  5799. upone1:    mov    linec,ax        ; save the results
  5800.     call    getcirc            ; now get the new screen
  5801.     clc
  5802.     ret
  5803. fupone    endp
  5804.  
  5805. ; Horizontal scrolling keyboard verbs
  5806. frtpage    proc    far
  5807.     mov    cx,20            ; step size
  5808.     call    rtcommon
  5809.     ret
  5810. frtpage    endp
  5811.  
  5812. frtone    proc    far
  5813.     mov    cx,1
  5814.     call    rtcommon
  5815.     ret
  5816. frtone    endp
  5817.  
  5818. ; Move screen to the right margin by CX columns
  5819. rtcommon proc    near
  5820.     push    bx
  5821.     mov    bl,byte ptr cursor+1    ; current cursor row
  5822.     xor    bh,bh
  5823.     mov    al,linescroll[bx]    ; horz scroll in effect for this line
  5824.     pop    bx
  5825.     add    al,handhsc         ; plus hand scrolling now present
  5826.     add    al,crt_cols        ; right most char on visible screen
  5827.     adc    ah,0
  5828.     cmp    ax,vswidth        ; too far already?
  5829.     ja    rtcomm2            ; a = yes, do nothing
  5830.     sub    ax,vswidth        ; available distance
  5831.     neg    ax
  5832.     cmp    ax,cx            ; space vs desired scroll
  5833.     jbe    rtcomm1            ; be = less than desired, use space
  5834.     mov    ax,cx            ; enough room, use desired scroll
  5835. rtcomm1:add    handhsc,al        ; indicate how much done by hand
  5836.     call    repaint
  5837. rtcomm2:clc
  5838.     ret
  5839. rtcommon endp
  5840.  
  5841. flfpage    proc    far
  5842.     mov    cx,20            ; step size
  5843.     call    lfcommon
  5844.     ret
  5845. flfpage    endp
  5846.  
  5847. flfone    proc    far
  5848.     mov    cx,1            ; step size
  5849.     call    lfcommon
  5850.     ret
  5851. flfone    endp
  5852.  
  5853. ; Move screen toward left margin by CX columns
  5854. lfcommon proc    near
  5855.     push    bx
  5856.     mov    bl,byte ptr cursor+1    ; current cursor row
  5857.     xor    bh,bh
  5858.     mov    al,linescroll[bx]    ; horz scroll in effect for this line
  5859.     pop    bx
  5860.     add    al,handhsc        ; available distance to move
  5861.     jz    lfcomm2            ; z = no space to move
  5862.     sub    al,cl            ; minus our desired jump
  5863.     jge    lfcomm1            ; ge = no overscroll the wrong way
  5864.     add    cl,al            ; reduce cx request by overage
  5865. lfcomm1:sub    handhsc,cl        ; successful, new handhsc
  5866.     call    repaint
  5867. lfcomm2:clc
  5868.     ret
  5869. lfcommon endp
  5870.  
  5871. ; Scrolling routines.  vtscru scrolls up, vtscrd scrolls down 'scroll'
  5872. ; rows. Top lines are saved in the circular buffer before scrolling up.
  5873. ; When running under an Environment control number of line positions moved
  5874. ; to be less than scrolling region.
  5875. ; All registers are preserved.
  5876. ;
  5877. ; Screen scroll up "scroll" lines (text moves up) for terminal emulator use.
  5878.      
  5879. vtscru    proc    near
  5880.     push    ax
  5881.     push    bx
  5882.     push    cx
  5883.     push    dx
  5884.     push    si
  5885.     push    di
  5886.     mov    al,mar_bot        ; compute size of scroll
  5887.     sub    al,mar_top
  5888.     inc    al            ; lines in scrolling region
  5889.     mov    dl,scroll        ; desired scroll
  5890.     xor    dh,dh
  5891.     cmp    dl,al            ; scrolling more than needed?
  5892.     jbe    vtscru1            ; be = no
  5893.     mov    dl,al            ; limit scrolling
  5894.     mov    scroll,al
  5895. vtscru1:or    dl,dl
  5896.     jnz    vtscru2    
  5897.     jmp    vtscru9            ; z = nothing to do
  5898.  
  5899. vtscru2:cmp    mar_top,0        ; scrolling the top screen line?
  5900.     jne    vtscru5            ; ne = no, do not save in roll back
  5901.     mov    cx,dx            ; cx is how many lines
  5902.     call    putcirc            ; put screen lines in circular buffer
  5903.     
  5904.     add    linec,cx        ; (BDT) increment the current line
  5905.     mov    cx,linec        ; new current line number
  5906.     sub    cx,lcnt            ; minus # in buf = qty new lines added
  5907.     jc    vtscru3            ; c = not extending buffer
  5908.     add    lcnt,cx            ; (BDT) increment the line counter
  5909. vtscru3:mov    cx,lcnt            ; (BDT) check: are we
  5910.     cmp    cx,lmax            ; (BDT) beyond the end?
  5911.     jb    vtscru5            ; (BDT) b = no
  5912.     sub    cx,lmax            ; (BDT) compute overflow count
  5913.     add    linef,cx        ; (BDT) adjust the "first" line
  5914.     mov    cx,linef        ; (BDT) check: time to wrap?
  5915.     cmp    cx,linee        ; (BDT) ...
  5916.     jb    vtscru4            ; (BDT) b = no
  5917.     sub    cx,linee        ; (BDT) yup
  5918.     mov    linef,cx        ; (BDT) adjust it
  5919. vtscru4:mov    cx,lmax            ; (BDT) get the maximum line count
  5920.     mov    lcnt,cx            ; (BDT) reset the line counter
  5921.     mov    linec,cx        ; (BDT) reset the current line
  5922.  
  5923. vtscru5:mov    di,word ptr vs_ptr    ; offset of virtual screen
  5924.     mov    cl,vswidth
  5925.     mov    al,mar_top        ; top line number (from 0)
  5926.     mul    cl            ; times chars/line
  5927.     add    ax,ax            ; char + attribute
  5928.     add    di,ax            ; destination (mar_top)
  5929.     mov    al,dl            ; number of lines to scroll
  5930.     mov    cl,vswidth
  5931.     mul    cl            ; vswidth * total lines to scroll
  5932.     mov    bx,ax            ; number of cells to clear
  5933.     add    ax,ax            ; bytes
  5934.     mov    si,di
  5935.     add    si,ax            ; src is that many bytes down screen
  5936.     mov    al,mar_bot        ; lines in scrolling region
  5937.     sub    al,mar_top
  5938.     inc    al
  5939.     sub    al,dl            ; minus scrolled portion
  5940.     mul    cl            ; times words per line
  5941.     mov    cx,ax            ; number of cells to copy
  5942.     mov    dh,scbattr        ; need this for later (in seg data)
  5943.     push    cx            ; save number of words for attribute
  5944.     push    es
  5945.     push    ds
  5946.     mov    ax,word ptr vs_ptr+2    ; segment of vscreen
  5947.     mov    ds,ax
  5948.     mov    es,ax
  5949.     cld
  5950.     rep    movsw            ; copy src to dest
  5951.     mov    cx,bx            ; count of words to clear
  5952.     mov    ah,dh            ; default attriubte
  5953.     mov    al,' '            ; filler for clearing a line
  5954.     rep    stosw            ; store after new src
  5955.     pop    ds
  5956.     pop    es
  5957.                     ; bx is number of words cleared
  5958.     mov    di,word ptr vsat_ptr    ; offset of attributes
  5959.     mov    cl,vswidth        ; char cells per attributes line
  5960.     mov    al,mar_top        ; top line number (from 0)
  5961.     mul    cl            ; times cells per line
  5962.     add    di,ax            ; destination (mar_top)
  5963.     mov    si,di
  5964.  
  5965.     mov    al,dl            ; number of lines to scroll
  5966.     mul    cl            ; vswidth * total lines to scroll
  5967.     mov    bx,ax            ; number of cells to clear
  5968.     add    si,bx            ; src is that many bytes down screen
  5969.     pop    cx            ; number of vscreen cells copied
  5970.     push    es
  5971.     push    ds
  5972.     mov    ax,word ptr vsat_ptr+2    ; segment of vsatt
  5973.     mov    ds,ax
  5974.     mov    es,ax
  5975.     cld
  5976.     rep    movsb            ; copy src to dest
  5977.     mov    cx,bx            ; count of bytes to clear
  5978.     xor    al,al            ; default attributes of none
  5979.     rep    stosb            ; store after new src
  5980.     pop    ds
  5981.     pop    es
  5982.     cmp    writemode,0        ; use direct screen writing?
  5983.     je    vscru5a            ; e = yes
  5984. ifndef    no_graphics
  5985.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  5986.     jne    vscru5b            ; ne = no
  5987. endif    ; no_graphics
  5988.  
  5989. vscru5a:cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  5990.     jne    vtscru8            ; ne = no
  5991. ifndef    no_graphics
  5992.     call    tekremcursor        ; turn off text cursor
  5993. vscru5b:mov    dosetcursor,-1        ; don't turn on automatically
  5994.     mov    al,' '            ; write space
  5995.     mov    ah,scbattr        ; in normal colors
  5996.     xor    dl,dl            ; at mar_top, left margin
  5997.     mov    dh,mar_top        ; to set normal text mode for the
  5998.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  5999.     jne    vscru5d            ; ne = no
  6000.     xor    cl,cl            ; no extended attribute
  6001.     call    ttxtchr            ; graphics adapter
  6002. endif    ; no_graphics
  6003.  
  6004. vscru5d:mov    ax,0600h        ; scroll up whole region
  6005.     mov    dh,mar_bot        ; bottom row
  6006.     mov    dl,crt_cols
  6007.     cmp    isps55,0        ; [HF]940216 Japanese PS/55?
  6008.     jne    vscru5e            ; [HF]940216 ne=yes, allowed > 80cols.
  6009.     cmp    dl,80            ; more than physical screen?
  6010.     jbe    vscru5e            ; be = no
  6011.     cmp    dl,131            ; really wide screen
  6012.     jae    vscru5e            ; ae = yes
  6013.     mov    dl,80            ; else 128 col fake text wide screen
  6014. vscru5e:dec    dl            ; right most physical col for scroll
  6015.     mov    ch,mar_top        ; top row of scrolling region
  6016.     xor    cl,cl            ; left most column
  6017.     mov    bh,scbattr        ; attributes
  6018.     mov    bl,dh
  6019.     sub    bl,ch            ; region size - 1 line
  6020.     jz    vscru2b            ; z = region is 1 line, do one scroll
  6021.     mov    al,scroll        ; number of lines to scroll, from msz
  6022. vscru2a:cmp    al,bl            ; want to scroll more that than?
  6023.     jbe    vscru2b            ; be = no
  6024.     push    ax
  6025.     mov    al,bl            ; limit to region - 1 for Windows
  6026.     int    screen            ;  and do in parts
  6027.     pop    ax
  6028.     sub    al,bl            ; al = amount yet to scroll
  6029.     jmp    short vscru2a        ; do next part
  6030. vscru2b:int    screen            ; scroll up that region
  6031.     mov    dx,cursor
  6032.     mov    dosetcursor,dx        ; reminder of where to set cursor
  6033.     jmp    short vtscru9
  6034.  
  6035. vtscru8:mov    dh,mar_bot        ; real text mode
  6036.     mov    dl,mar_top        ; setup touchup, lines changed
  6037.     call    touchup            ; touch up real screen
  6038. vtscru9:pop    di
  6039.     pop    si
  6040.     pop    dx
  6041.     pop    cx
  6042.     pop    bx
  6043.     pop    ax
  6044.     ret
  6045. vtscru    endp
  6046.  
  6047. ; Screen-roll down. Move text down scroll lines, for terminal emulator only.
  6048. vtscrd    proc    near
  6049.     push    ax
  6050.     push    bx
  6051.     push    cx
  6052.     push    dx
  6053.     push    si
  6054.     push    di
  6055.     push    bp
  6056.     push    es
  6057.     les    si,vs_ptr        ; source is top line of virtual screen
  6058.     mov    al,mar_top        ; top margin line (0..)
  6059.     mov    cl,vswidth        ; chars across vscreen
  6060.     mul    cl
  6061.     add    ax,ax            ; words to bytes
  6062.     add    si,ax            ; offset of start of top line
  6063.     mov    bp,si            ; remember top line for later
  6064.     mov    cl,mar_bot        ; compute number of lines to move
  6065.     sub    cl,mar_top
  6066.     inc    cl            ; qty of lines in region
  6067.     mov    ch,scroll
  6068.     cmp    ch,cl            ; want to scroll more than region?
  6069.     jbe    vtscrd1            ; be = no
  6070.     mov    ch,cl            ; set scroll to whole region
  6071.     mov    scroll,ch        ; remember for attributes
  6072. vtscrd1:sub    cl,ch             ; less lines to be skipped
  6073.     mov    bl,ch            ; save effective scroll for below
  6074.     mov    al,vswidth        ; number of character cells
  6075.     mul    cl
  6076.     mov    cx,ax            ; number of words in the movement
  6077.     dec    ax            ; compute to end word
  6078.     add    ax,ax            ; number of bytes
  6079.     add    si,ax            ; go to the end
  6080.     mov    di,si
  6081.     mov    al,vswidth        ; words in a line buffer
  6082.     mul    bl            ; number of chars dest is below src
  6083.     mov    bx,ax            ; save number of chars here for clear
  6084.     add    ax,ax            ; number of bytes (char + attribute)
  6085.     add    di,ax            ; destination offset
  6086.     push    ds
  6087.     mov    ax,es
  6088.     mov    ds,ax
  6089.     std
  6090.     rep    movsw            ; copy down the lines
  6091.     cld
  6092.     pop    ds
  6093.     mov    di,bp            ; fill top line in scrolling region
  6094.     mov    ah,scbattr
  6095.     mov    al,' '
  6096.     mov    cx,bx            ; number of char cells to clear
  6097.     rep    stosw            ; fill top line(s) with spaces
  6098.                     ; do extended attributes the same way
  6099.     les    si,vsat_ptr        ; source of extended attributes
  6100.     mov    al,mar_top        ; top margin line (0..)
  6101.     mov    cl,vswidth        ; attribute cells/line
  6102.     mul    cl
  6103.     add    si,ax            ; offset of start of top line
  6104.     mov    bp,si            ; remember top line for later
  6105.     mov    cl,mar_bot        ; compute number of lines to move
  6106.     sub    cl,mar_top
  6107.     inc    cl            ; qty of lines in region
  6108.     mov    ch,scroll
  6109.     sub    cl,ch             ; less lines to be skipped
  6110.     mov    bl,ch            ; save effective scroll for below
  6111.     mov    al,vswidth        ; number of attribute cells/line
  6112.     mul    cl
  6113.     mov    cx,ax            ; number of bytes in the movement
  6114.     dec    ax            ; compute to end byte
  6115.     add    si,ax            ; go to the end
  6116.     mov    di,si
  6117.     mov    al,vswidth        ; number of attribute cells/line
  6118.     mul    bl            ; number of cells dest is below src
  6119.     mov    bx,ax            ; save number of bytes here for clear
  6120.     add    di,ax            ; destination offset
  6121.     push    ds
  6122.     mov    ax,es
  6123.     mov    ds,ax
  6124.     std
  6125.     rep    movsb            ; copy down the lines
  6126.     cld
  6127.     pop    ds
  6128.     mov    di,bp            ; fill top line in scrolling region
  6129.     xor    al,al            ; null attributes for filler
  6130.     mov    cx,bx            ; number of attributes bytes to clear
  6131.     rep    stosb            ; fill top line(s) with spaces
  6132.     pop    es
  6133.     pop    bp
  6134.     cmp    writemode,0        ; use direct screen writing?
  6135.     je    vscrd1            ; e = yes
  6136.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6137.     jne    vscrd3a            ; ne = no
  6138. vscrd1:
  6139. ifndef    no_graphics
  6140.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6141.     je    vscrd3            ; e = yes
  6142. endif    ; no_graphics
  6143.     mov    dl,mar_top        ; setup touchup, lines changed
  6144.     mov    dh,mar_bot
  6145.     call    touchup            ; touch up real screen
  6146.     jmp    short vscrd8
  6147.  
  6148. ifndef    no_graphics
  6149. vscrd3:    call    tekremcursor        ; turn off text cursor
  6150. endif    ; no_graphics
  6151. vscrd3a:mov    dosetcursor,-1        ; don't turn on automatically
  6152.     mov    al,' '            ; write space
  6153.     mov    ah,scbattr        ; in normal colors
  6154. ifndef    no_graphics
  6155.     xor    dl,dl            ; at mar_bot, left margin
  6156.     mov    dh,mar_bot        ; to set normal text mode for the
  6157.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6158.     jne    vscrd3b            ; ne = no
  6159.     xor    cl,cl            ; no extended attribute
  6160.     call    ttxtchr            ; graphics adapter
  6161. endif    ; no_graphics
  6162. vscrd3b:mov    ax,0700h        ; scroll down whole region
  6163.     mov    ch,mar_top        ; top margin line
  6164.     xor    cl,cl            ; left most column
  6165.     mov    dh,mar_bot        ; bottom margin line
  6166.     mov    dl,crt_cols
  6167.     cmp    isps55,0        ; [HF]940216 Japanese PS/55
  6168.     jne    vscrd3c            ; [HF]940216 ne=yes, allowed > 80 cols
  6169.     cmp    dl,80            ; more than physical screen?
  6170.     jbe    vscrd3c            ; be = no
  6171.     cmp    dl,131            ; really wide screen
  6172.     jae    vscrd3c            ; ae = yes
  6173.     mov    dl,80            ; else 128 col fake text wide screen
  6174. vscrd3c:dec    dl            ; right most physical col for scroll
  6175.     mov    bh,scbattr        ; attributes
  6176.     mov    bl,dh
  6177.     sub    bl,ch            ; region size - 1 line
  6178.     jz    vscrd7             ; z = region is 1 line, do one scroll
  6179.     mov    al,scroll        ; number of lines to scroll, from msz
  6180. vscrd7:    cmp    al,bl            ; want to scroll more that than?
  6181.     jbe    vscrd2            ; be = no
  6182.     push    ax
  6183.     mov    al,bl            ; limit to region-1 for Windows
  6184.     int    screen            ;  and do in parts
  6185.     pop    ax
  6186.     sub    al,bl            ; get remainder
  6187.     jmp    short vscrd7        ; do next part
  6188. vscrd2:    int    screen            ; scroll it down
  6189.     mov    dx,cursor
  6190.     mov    dosetcursor,dx        ; reminder of where to set cursor
  6191. vscrd8:    pop    di
  6192.     pop    si
  6193.     pop    dx
  6194.     pop    cx
  6195.     pop    bx
  6196.     pop    ax
  6197.     ret
  6198. vtscrd    endp
  6199.  
  6200. ; Put the top cx lines from the virtual screen in to the circular buffer
  6201. ; starting at line index linec (counted from zero, modulo linee).
  6202. putcirc    proc    near
  6203.     jcxz    putcir6            ; z = no lines to save
  6204.     cmp    lmax,0            ; any buffer space?
  6205.     jne    putcir7            ; ne = yes, have some
  6206. putcir6:ret
  6207. putcir7:push    ax
  6208.     push    bx
  6209.     push    cx
  6210.     push    dx
  6211.     push    si
  6212.     push    di
  6213.     push    es
  6214.     cld
  6215.     mov    pageready,-1        ; ems page number currently active
  6216.     mov    si,word ptr vs_ptr    ; offset of screen buffer
  6217.     mov    bx,linef        ; index of the first line
  6218.     add    bx,linec        ; add the current line counter
  6219.     dec    bx
  6220. putcir1:inc    bx
  6221.     cmp    bx,linee        ; at the end of the buffer now?
  6222.     jb    putcir2            ; b = no
  6223.     sub    bx,linee        ; backup to start of buffer
  6224. putcir2:mov    ax,bx            ; line index
  6225.     cmp    emsrbhandle,0        ; EMS in use?
  6226.     jg    putcir3            ; g = yes
  6227.     cmp    xmsrhandle,0        ; XMS rollback in use?
  6228.     je    putcir3            ; e = no
  6229.     call    putxms            ; do the put via xms
  6230.     jmp    short putcir4
  6231. putcir3:call    emsfixup        ; do expanded memory conversion work
  6232.     mul    ppl            ; times paragraphs per line
  6233.     add    ax,iniseg        ; plus initial seg of buffer
  6234.     mov    es,ax            ; now we have the segment pointer
  6235.     xor    di,di            ; buffer offset is always 0
  6236.     push    cx            ; save the number of lines
  6237.     mov    cx,rollwidth        ; get the number of characters to move
  6238.     push    si            ; save starting vscreen offset
  6239.     push    ds            ; get the offset of the screen
  6240.     cld
  6241.     mov    ds,word ptr vs_ptr+2    ; seg of vscreen
  6242.     rep    movsw            ; move them
  6243.     pop    ds            ; restore DS
  6244.     pop    si            ; vscreen offset
  6245.     add    si,vswidth*2        ; inc to next vscreen line
  6246.     pop    cx            ; restore the line count
  6247. putcir4:loop    putcir1            ; go back for more
  6248.     pop    es
  6249.     pop    di
  6250.     pop    si
  6251.     pop    dx
  6252.     pop    cx
  6253.     pop    bx
  6254.     pop    ax
  6255.     clc
  6256.     ret
  6257. putcirc    endp
  6258.  
  6259. ; Put CX lines into XMS based rollback buffer
  6260. putxms    proc    near
  6261.     mul    ppl            ; line number times paragraphs/line
  6262.     push    cx
  6263.     mov    cx,4            ; have paragraphs, want bytes
  6264.     xor    dx,dx
  6265. putxms1:shl    al,1
  6266.     rcl    ah,1
  6267.     rcl    dl,1            ; get bytes to dx:ax
  6268.     loop    putxms1            ; times 16
  6269.     pop    cx
  6270.  
  6271.     mov    word ptr xms.offset_dst,ax    ; low order address
  6272.     mov    word ptr xms.offset_dst+2,dx    ; high order
  6273.     mov    ax,rollwidth
  6274.     shl    ax,1                ; times two
  6275.     mov    word ptr xms.xms_count,ax    ; byte count
  6276.     mov    ax,word ptr vs_ptr+2         ; src seg
  6277.     mov    word ptr xms.offset_src+2,ax
  6278.     mov    word ptr xms.offset_src+0,si     ; low order
  6279.     mov    xms.handle_src,0        ; source is local
  6280.     mov    ax,xmsrhandle             ; dest is rollback area
  6281.     mov    xms.handle_dst,ax
  6282.     push    si
  6283.     mov    si,offset xms        ; ds:si is request block
  6284.     mov    ah,xmsmove
  6285.     call    dword ptr xmsep
  6286.     pop    si
  6287.     add    si,vswidth*2        ; inc to next vscreen line
  6288.     ret
  6289. putxms    endp
  6290.  
  6291. ; Get CX lines from the circular buffer, non destructively, starting at
  6292. ; line index linec (counted from zero, modulo linee) and put them at
  6293. ; the top of the virtual screen. Fewer lines are written if the buffer
  6294. ; holds fewer than CX.
  6295. getcirc    proc    near
  6296.     or    cx,cx            ; check on qty
  6297.     jnz    getcir0            ; nz = some
  6298.     ret
  6299. getcir0:cmp    lmax,0            ; any buffer space?
  6300.     jne    getcir5            ; ne = yes, have some
  6301.     ret
  6302. getcir5:push    ax
  6303.     push    bx
  6304.     push    cx
  6305.     push    dx
  6306.     push    si
  6307.     push    di
  6308.     push    es
  6309.     mov    pageready,-1        ; ems page number currently active
  6310.     les    di,vs_ptr        ; seg and offset of vscreen
  6311.     mov    bx,linef        ; get the first line pointer
  6312.     add    bx,linec        ; add the current line counter
  6313.     dec    bx
  6314.     cld
  6315. getcir1:inc    bx
  6316.     cmp    bx,linee        ; at the end of the buffer now?
  6317.     jb    getcir2            ; b = no
  6318.     sub    bx,linee        ; backup to start of buffer
  6319. getcir2:mov    ax,bx            ; line index
  6320.  
  6321.     cmp    emsrbhandle,0        ; EMS in use?
  6322.     jg    getcir3            ; g = yes
  6323.     cmp    xmsrhandle,0        ; XMS rollback in use?
  6324.     je    getcir3            ; e = no
  6325.     call    getxms            ; get from XMS
  6326.     jmp    short getcir4
  6327. getcir3:call    emsfixup        ; do expanded memory conversion work
  6328.     mul    ppl            ; times paragraphs per line
  6329.     add    ax,iniseg        ; plus initial seg of buffer
  6330.     xor    si,si            ; initial offset is always 0
  6331.     push    cx            ; save the number of lines
  6332.     mov    cx,rollwidth        ; get the number of characters to move
  6333.     push    di            ; save vscreen offset
  6334.     push    ds            ; save DS for a tad
  6335.     mov    ds,ax            ; now we have the segment pointer
  6336.     rep    movsw            ; move them
  6337.     pop    ds            ; restore DS
  6338.     pop    di            ; recover vscreen offset
  6339.     add    di,vswidth*2        ; next vscreen line
  6340.     pop    cx            ; restore the line count
  6341. getcir4:
  6342.     loop    getcir1            ; go back for more
  6343.     call    repaint            ; repaint screen
  6344.     pop    es
  6345.     pop    di
  6346.     pop    si
  6347.     pop    dx
  6348.     pop    cx
  6349.     pop    bx
  6350.     pop    ax
  6351.     clc
  6352.     ret
  6353. getcirc    endp
  6354.  
  6355. getxms    proc    near
  6356.     mul    ppl            ; line number times paragraphs/line
  6357.     push    cx
  6358.     mov    cx,4            ; have paragraphs, want bytes
  6359.     xor    dx,dx
  6360. getxms1:shl    al,1
  6361.     rcl    ah,1
  6362.     rcl    dl,1            ; get bytes to dx:ax
  6363.     loop    getxms1            ; times 16
  6364.     pop    cx
  6365.     mov    word ptr xms.offset_src,ax    ; low order address
  6366.     mov    word ptr xms.offset_src+2,dx    ; high order
  6367.     mov    ax,rollwidth
  6368.     shl    ax,1                ; times two for words
  6369.     mov    word ptr xms.xms_count,ax    ; byte count
  6370.     mov    ax,word ptr vs_ptr+2         ; dst seg
  6371.     mov    word ptr xms.offset_dst+2,ax
  6372.     mov    word ptr xms.offset_dst+0,di     ; low order
  6373.     mov    xms.handle_dst,0        ; destination is local
  6374.     mov    ax,xmsrhandle             ; source is rollback area
  6375.     mov    xms.handle_src,ax         ; source is rollback area
  6376.     push    si
  6377.     mov    si,offset xms            ; ds:si is request block
  6378.     mov    ah,xmsmove
  6379.     call    dword ptr xmsep
  6380.     pop    si
  6381.     add    di,vswidth*2            ; next vscreen line
  6382.     ret
  6383. getxms    endp
  6384.  
  6385. ; Convert rollback line number in AX to line number in ems page, and invoke 
  6386. ; that page. Destroys dx, returns ax as line number in page.
  6387. emsfixup proc    near
  6388.     cmp    emsrbhandle,0        ; EMS in use?
  6389.     jg    emsfix1            ; g = yes (-1 is not in use)
  6390.     ret
  6391. emsfix1:xor    dx,dx
  6392.     div    lineems            ; line number / lines per ems page
  6393.     push    bx
  6394.     mov    bx,ax            ; quotient, page number
  6395.     mov    ax,dx            ; remainder, line in page
  6396.     cmp    bx,pageready        ; is this page now present?
  6397.     je    emsfix2            ; e = yes
  6398.     mov    pageready,bx        ; remember
  6399.     push    ax
  6400.     mov    ah,emsmapmem        ; map logical page in bx
  6401.     xor    al,al            ;  to physical page zero
  6402.     mov    dx,emsrbhandle        ; our ems rollback handle
  6403.     int    emsint
  6404.     pop    ax            ; return ax as line in page
  6405. emsfix2:pop    bx
  6406.     ret
  6407. emsfixup endp
  6408.  
  6409. ; Repaint screen from the vscreen buffer
  6410. repaint    proc    near
  6411.     push    dx
  6412.     xor    dl,dl            ; top row
  6413.     mov    dh,crt_lins        ; physical screen rows-1, incl status
  6414.     cmp    isps55,0        ; [HF]940209 Japanese PS/55?
  6415.     je    repain1            ; [HF]940209 e = no
  6416.     cmp    ps55mod,0        ; [HF]940209 system uses modeline?
  6417.     jne    repain1            ; [HF]940209 ne = no
  6418.     dec    dh            ; [HF]940209 yes, don't touch modeline
  6419. repain1:call    touchup
  6420.     pop    dx
  6421.     ret
  6422. repaint    endp
  6423.  
  6424. ; Repaint part of screen from the vscreen buffer, with linescroll offset
  6425. ; dh is bottom line number, dl is top line number (dh >= dl)
  6426. ftouchup proc    far
  6427.     call    touchup
  6428.     ret
  6429. ftouchup endp
  6430.  
  6431. touchup    proc    near            ; get lines from virtual screen
  6432.     cmp    flags.vtflg,ttgenrc    ; terminal type of none?
  6433.     jne    touch1            ; ne = no
  6434.     ret
  6435. touch1:    push    ax
  6436.     push    bx
  6437.     push    cx
  6438.     push    dx
  6439.     push    si
  6440.     push    di
  6441.     push    es
  6442.     mov    cl,dh            ; last row to change
  6443.     sub    cl,dl            ; number of lines -1
  6444.     cmp    cl,crt_lins        ; out of bounds value?
  6445.     jbe    touch1b            ; be = no
  6446.     xor    cl,cl            ; stay sane
  6447. touch1b:inc    cl            ; number of lines to update
  6448.     xor    ch,ch
  6449.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6450.     je    touch1c            ; e = yes, skip text screen update
  6451.     test    tekflg,tek_active    ; other graphics mode?
  6452.     jnz    touch9            ; nz = yes, no touchup
  6453.  
  6454.     call    scroff            ; turn off text screen
  6455.     mov    es,tv_segs        ; get the segment of the screen
  6456.     mov    di,tv_sego        ; initial screen offset
  6457. touch1c:mov    al,crt_cols        ; physical screen width
  6458.     mul    dl            ; chars into physical screen
  6459.     add    ax,ax            ; chars to bytes
  6460.     add    di,ax            ; offset of start of phy update area
  6461.     mov    si,word ptr vs_ptr
  6462.     mov    al,vswidth        ; chars per line
  6463.     mul    dl            ; ax = bytes to first vscreen line
  6464.     add    ax,ax            ; chars to bytes
  6465.     add    si,ax            ; si = starting vscreen line offset
  6466.     mov    bl,dl            ; top line number
  6467.     xor    bh,bh            ; index for linescroll
  6468.     cld
  6469.     push    dx
  6470.     mov    dh,dl            ; set row into dh, temporarily
  6471. touch2:    push    si            ; save the current line pointer
  6472.     push    cx            ; save the number of lines
  6473.     mov    cl,crt_cols        ; get the number of characters to move
  6474.     xor    ch,ch
  6475.     xor    dl,dl
  6476.     mov    al,linescroll[bx]    ; get horiz scroll for this line
  6477.     add    al,handhsc        ; hand done shift, total to AL
  6478.     cbw                ; sign extend
  6479.     or    ax,ax            ; sane?
  6480.     jge    touch2c            ; ge = yes
  6481.     xor    ax,ax            ; remove negative overshifts
  6482. touch2c:add    si,ax            ; offset into vscreen
  6483.     add    si,ax            ; char cells to words
  6484.  
  6485.     mov    ah,dgwindcomp[bx]
  6486.     test    ah,2            ; soft font?
  6487.     jz    touch2g            ; z = no
  6488. ifndef    no_graphics
  6489.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6490.     je    touch2d            ; e = yes
  6491.     push    ax
  6492.     call    dgsettek        ; set special graphics mode now
  6493.     pop    ax
  6494.     jmp    short touch2d
  6495. endif    ; no_graphics
  6496.  
  6497. touch2g:cmp    writemode,0        ; use direct writing?
  6498.     je    touch2a            ; e = yes
  6499.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6500.     je    touch2d            ; e = yes
  6501.     call    tchbios            ; Bios writing
  6502.     jmp    short touch4
  6503. touch2a:cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6504.     jne    touch3            ; ne = no
  6505.  
  6506. touch2d:
  6507. ifndef    no_graphics
  6508.     push    bx
  6509.     mov    bl,al            ; horizontal scroll for this line
  6510.     xor    bh,bh
  6511.     test    ah,1            ; is this line compressed?
  6512.     jz    touch2e            ; z = no
  6513.     mov    cl,128            ; compressed, 5 dot chars, 128/line
  6514. touch2e:mov    al,vswidth
  6515.     mul    dh            ; cells in previous rows
  6516.     add    al,dl            ; cells across to this column
  6517.     adc    ah,0
  6518.     add    bx,ax            ; cells from start of screen
  6519. touch2b:push    bx
  6520.     push    cx
  6521.     push    si
  6522.     push    es
  6523.     shl    bx,1            ; address words
  6524.     les    si,vs_ptr        ; main vscreen
  6525.     mov    ax,es:[si+bx]        ; obtain char and attribute
  6526.     les    si,vsat_ptr        ; extended attributes
  6527.     shr    bx,1            ; count bytes, vs words above
  6528.     mov    cl,es:[bx+si]        ; obtain extended attribute byte
  6529.     pop    es            ; to get font indicator
  6530.     pop    si
  6531.     call    ttxtchr            ; write character
  6532.     pop    cx
  6533.     pop    bx
  6534.     inc    dl            ; next column
  6535.     inc    bx
  6536.     loop    touch2b
  6537.     pop    bx
  6538.     jmp    short touch4
  6539. endif    ; no_graphics
  6540.  
  6541. touch3:    push    ds
  6542.     mov    ds,word ptr vs_ptr+2    ; segment of vscreen
  6543.     rep    movsw            ; from vscreen+hsc to real screen+0
  6544.     pop    ds
  6545.  
  6546. touch4:    pop    cx            ; restore the line count
  6547.     pop    si            ; restore the buffer counter
  6548.     inc    bx            ; for next line
  6549.     add    si,vswidth*2        ; point to next line
  6550.     inc    dh
  6551.     dec    cx
  6552.     jz    touch4a            ; z = have done all lines
  6553.     jmp    touch2            ; do more lines
  6554.  
  6555. touch4a:pop    dx
  6556.     mov    ah,byte ptr cursor+1    ; row of cursor
  6557.     cmp    ah,dl            ; cursor before this line?
  6558.     jb    touch5            ; b = yes, skip cursor
  6559.     cmp    ah,dh            ; cursor after this line?
  6560.     ja    touch5            ; a = yes, skip cursor
  6561. ifndef    no_graphics
  6562.     mov    cursorst,0        ; say cursor has been zapped off
  6563. endif    ; no_graphics
  6564.     push    dx
  6565.     mov    dx,cursor
  6566.     mov    bl,dh            ; get row
  6567.     xor    bh,bh
  6568.     sub    dl,linescroll[bx]    ; deduct horiz scroll for this line
  6569.     sub    dl,handhsc        ; hand done shift
  6570.     call    setpcur            ; reset the cursor
  6571.     pop    dx
  6572.  
  6573. touch5:    cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6574.     je    touch9            ; e = yes
  6575.     cmp    tv_mode,0h        ; TV active?
  6576.     je    touch8            ; e = no
  6577.     mov    cl,dh            ; tell Topview/Desqview
  6578.     sub    cl,dl            ; number of lines -1
  6579.     cmp    cl,crt_lins        ; out of bounds value?
  6580.     jbe    touch7            ; be = no
  6581.     xor    cl,cl            ; stay sane
  6582. touch7:    inc    cl            ; number of lines to update
  6583.     mov    al,crt_cols        ; chars/line
  6584.     mul    cl
  6585.     mov    cx,ax            ; cx = words changed
  6586.     call    scrsync            ; synch Topview
  6587. touch8:    call    scron            ; turn on the screen
  6588. touch9:    pop    es
  6589.     pop    di
  6590.     pop    si
  6591.     pop    dx
  6592.     pop    cx
  6593.     pop    bx
  6594.     pop    ax
  6595.     ret
  6596. touchup    endp
  6597.  
  6598. ; Write screen via Bios. Enter with SI pointing at starting screen buffer
  6599. ; offset, dh is current screen row, cx has chars to write across a line.
  6600.  
  6601. tchbios proc    near
  6602.     push    bx
  6603.     xor    bh,bh            ; video page zero
  6604.     push    dx
  6605.     mov    ah,3
  6606.     int    screen
  6607.     mov    temp,dx            ; save current cursor
  6608.     pop    dx
  6609.     mov    cl,crt_cols
  6610.     xor    ch,ch
  6611.     xor    dl,dl            ; column zero
  6612.     cld
  6613.     push    ds
  6614.     mov    ds,word ptr vs_ptr+2    ; source is virtual screen buffer
  6615.     add    di,cx            ; move DI to match si movemen
  6616.     add    di,di            ; word's worth
  6617.  
  6618. tchbios1:push    cx
  6619.     mov    ah,2            ; set cursor position to dx
  6620.     int    screen
  6621.     lodsw                ; char+attribute
  6622.     mov    bl,ah            ; attribute
  6623.     mov    cx,1            ; one char
  6624.     mov    ah,9            ; write char at cursor position
  6625.     int    screen            ; do the Bios Int 10h call
  6626.     inc    dl            ; next column
  6627.     pop    cx
  6628.     loop    tchbios1
  6629.     pop    ds
  6630.     push    dx
  6631.     mov    dx,temp            ; starting cursor position
  6632.     mov    ah,2            ; set it back there
  6633.     int    screen
  6634.     pop    dx
  6635.     pop    bx
  6636.     ret
  6637. tchbios    endp
  6638.  
  6639. ; Character write/read and cursor manipulation routines for terminal emulator
  6640. ; All registers other than returned values are preserved.
  6641.  
  6642. ; Read char and attributes under virtual cursor (DH = row, DL = column).
  6643. ; Returns AL = character, AH = video attributes, CL = logical attribute bit
  6644. ; pair.
  6645. getatch    proc    near
  6646.     push    bx
  6647.     push    si
  6648.     push    es
  6649.     mov    al,vswidth        ; width of vscreen line
  6650.     mul    dh            ; count down rows (0..)
  6651.     add    al,dl            ; add column
  6652.     adc    ah,0
  6653.     add    ax,ax            ; times two for char and attrib
  6654.     mov    bx,ax            ; address subscript
  6655.     les    si,vs_ptr        ; main vscreen
  6656.     mov    ax,es:[si+bx]        ; obtain char and attribute
  6657.  
  6658.     les    si,vsat_ptr        ; extended attributes
  6659.     shr    bx,1            ; count bytes, vs words above
  6660.     mov    cl,es:[bx+si]        ; obtain extended attribute byte
  6661.     pop    es
  6662.     pop    si
  6663.     pop    bx
  6664.     ret
  6665. getatch    endp
  6666. endif    ; no_terminal
  6667.  
  6668. ; Set virtual cursor postion
  6669. ; DL = column, DH = row, both counted from 0,0 at upper left corner.
  6670. ; If not displaced, handhsc = 0, then scroll left if virtual > crt_cols.
  6671. ; If displaced, handhsc != 0, then scroll right if virtual < handhsc.
  6672. ; For the D463/D470 only, set carry bit (for setatch) if the cursor is off
  6673. ; the visible screen and horizontal scrolling is disabled.
  6674.  
  6675. setpos    proc    near
  6676.     push    ax
  6677.     push    bx
  6678.     push    cx
  6679.     push    dx            ; save outside virtual cursor
  6680.     mov    cl,crt_cols        ; physical screen width
  6681.     push    cx            ; save here
  6682. ifndef    no_terminal
  6683.     cmp    inemulator,0        ; emulating?
  6684.     je    setpos9            ; e = no, no virtual screen
  6685.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6686.     jne    setpos1            ; ne = no
  6687.     mov    bl,dh            ; get row
  6688.     xor    bh,bh
  6689.     test    dgwindcomp[bx],1    ; is this line compressed?
  6690.     jz    setpos1            ; z = no
  6691.     mov    crt_cols,128        ; compressed, 5 dot chars, 128/line
  6692. setpos1:mov    ch,vswidth        ; leftmost legal margin (207)
  6693.     sub    ch,crt_cols        ; minus screen physical width
  6694.     xor    cl,cl        ; cl is flag for repainting needed (if != 0)
  6695.     xchg    handhsc,cl        ; hand-done horiz scroll, clear it
  6696.     or    cl,cl            ; need to undo it?
  6697.     jz    setpos2            ; z = no
  6698.     call    repaint            ; repaint screen without hand scroll
  6699.     xor    cl,cl            ; remove repaint indicator
  6700. setpos2:mov    bl,dh            ; current row
  6701.     xor    bh,bh
  6702.     mov    ah,linescroll[bx]    ; current horz scroll
  6703. setpos3:mov    al,dl            ; virtual column where we ought to be
  6704.     sub    al,ah            ; virtual - already scrolled    
  6705.     jc    setpos4            ; c = cursor off screen to the left
  6706.     cmp    al,crt_cols        ; beyond right physical screen?
  6707.     jb    setpos5            ; b = no, use this
  6708.     mov    cl,1            ; say need repaint
  6709.     inc    ah            ; scroll screen left one column
  6710.     jc    setpos3a        ; c = over did it
  6711.     cmp    ah,ch            ; going beyond largest scroll?
  6712.     jbe    setpos3            ; be = no
  6713. setpos3a:mov    ah,ch            ; yes, stay here
  6714.     jmp    short setpos5        ; done, do real operation
  6715.  
  6716. setpos4:mov    cl,1            ; say repaint needed
  6717.     mov    ah,dl            ; reduce horz scroll
  6718.  
  6719. setpos5:or    cl,cl            ; repaint needed?
  6720.     jnz    setpos5c        ; ne = yes
  6721.     mov    bl,byte ptr low_rgt+1    ; screen bottom
  6722.     inc    bl            ; lines in emulation part
  6723.     xor    bh,bh
  6724.     cmp    linescroll[bx],ah    ; status line, need to scroll?
  6725.     jbe    setpos8            ; be = already scrolled properly
  6726.     mov    linescroll[bx],ah    ; modify status line
  6727.     push    dx
  6728.     mov    dl,bl
  6729.     mov    dh,bl
  6730.     call    touchup            ; redraw status line
  6731.     pop    dx
  6732.     jmp    short setpos8        ; set cursor
  6733.  
  6734. setpos5c:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  6735.     jz    setpos5a        ; z = no
  6736.     cmp    dghscrdis,0        ; D463/D470 horz scroll disabled?
  6737.     je    setpos5a        ; e = no, check auto vs manual
  6738.     stc                ; c = do not show on real screen
  6739.     jmp    short setposx        ; skip screen update
  6740.  
  6741. setpos5a:test    vtemu.vtflgop,vshscroll    ; horizontal scrolling, manual?
  6742.     jnz    setpos9            ; nz = yes manual, else auto
  6743.  
  6744. setpos5b:mov    bl,mar_top        ; auto scrolling, top row
  6745.     xor    bh,bh
  6746.     mov    cl,mar_bot
  6747.     sub    cl,bl
  6748.     xor    ch,ch
  6749.     inc    cx            ; lines in scrolling region
  6750. setpos6:cmp    linescroll[bx],ah    ; any change?
  6751.     je    setpos7            ; e = no
  6752.     mov    linescroll[bx],ah    ; set scroll for this line
  6753.     push    dx
  6754.     mov    dl,bl
  6755.     mov    dh,bl
  6756.     call    touchup            ; repaint this line
  6757.     pop    dx
  6758. setpos7:inc    bx
  6759.     loop    setpos6            ; do all lines in window
  6760.  
  6761. setpos7a:push    ax            ; now do status line
  6762.     push    si
  6763.     mov    cl,byte ptr low_rgt+1    ; examine whole screen
  6764.     inc    cl            ; lines in emulation part
  6765.     xor    ch,ch
  6766.     mov    bx,cx            ; save for status line
  6767.     mov    si,offset linescroll
  6768.     mov    ah,[si]            ; smallest horizontal shift found
  6769.     cld
  6770. setpos10:lodsb                ; current line scroll to al
  6771.     cmp    al,ah            ; smaller than smallest?
  6772.     ja    setpos11        ; a = no
  6773.     mov    ah,al            ; remember smallest
  6774.     or    ah,ah            ; zero?
  6775.     jz    setpos11a        ; can't get any smaller than this
  6776. setpos11:loop    setpos10
  6777.                     ; just status line
  6778. setpos11a:cmp    linescroll[bx],ah    ; status line, need to scroll?
  6779.     je    setpos12        ; e = already scrolled properly
  6780.     mov    linescroll[bx],ah    ; modify status line
  6781.     push    dx
  6782.     mov    dl,bl
  6783.     mov    dh,bl
  6784.     call    touchup            ; redraw status line
  6785.     pop    dx
  6786. setpos12:pop    si
  6787.     pop    ax
  6788. setpos8:sub    dl,ah            ; virtual - horz scrolled column
  6789.  
  6790. endif    ; no_terminal
  6791.  
  6792. setpos9:call    setpcur            ; set physical cursor
  6793.     clc                ; set status for ok to show
  6794. setposx:pop    cx
  6795.     mov    crt_cols,cl
  6796.     pop    dx
  6797.     pop    cx
  6798.     pop    bx
  6799.     pop    ax
  6800.     ret
  6801. setpos    endp
  6802.  
  6803. ; Read physical cursor position
  6804. ; DL = column, DH = row, both counted from 0,0 at upper left corner
  6805. ; CX = cursor lines
  6806. getpcur    proc    near
  6807.     push    ax
  6808.     push    bx
  6809.     mov    ah,3            ; get cursor position
  6810.     xor    bh,bh            ; page 0
  6811.     int    screen
  6812.     pop    bx
  6813.     pop    ax
  6814.     ret
  6815. getpcur    endp
  6816.  
  6817. fgetpcur proc    far
  6818.     call    getpcur
  6819.     ret
  6820. fgetpcur endp
  6821.  
  6822. ; Set physical cursor postion
  6823. ; DL = column, DH = row, both counted from 0,0 at upper left corner
  6824. setpcur    proc    near
  6825.     push    dx
  6826.     cmp    dl,crt_cols        ; out of bounds?
  6827.     jb    setpcur1        ; b = ok
  6828.     cmp    dl,207            ; off screen to left?
  6829.     jbe    setpcur0        ; be = no
  6830.     xor    dl,dl            ; put at column zero
  6831.     jmp    short setpcur1
  6832. setpcur0:mov    dl,crt_cols        ; physical cols on screen
  6833.     dec    dl            ; count from zero
  6834. setpcur1:
  6835. ifndef    no_terminal
  6836.     cmp    inemulator,0        ; emulating?
  6837.     je    setpcur4        ; e = no, no virtual screen
  6838.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6839.     jne    setpcur4        ; ne = no
  6840.     push    ax
  6841.     push    es
  6842.     mov    ax,40h
  6843.     mov    es,ax
  6844.     mov    ax,es:[50h]        ; current position
  6845.     mov    es:[50h],dx        ; text page 0 cursor, keep it tracking
  6846.     cmp    ax,dx            ; same?
  6847.     pop    es
  6848.     pop    ax
  6849. ifndef    no_graphics
  6850.     jne    setpcur2        ; not same, draw cursor
  6851.     cmp    cursorst,0        ; is cursor off now?
  6852.     jne    setpcur3        ; ne = no, skip redrawing
  6853. setpcur2:
  6854.     mov    dosetcursor,dx        ; reminder of where to set cursor
  6855.     call    tekremcursor        ; ensure it's off
  6856. endif    ; no_graphics
  6857. setpcur3:pop    dx
  6858.     ret
  6859. endif    ; no_terminal
  6860.  
  6861. setpcur4:push    ax
  6862.     push    es
  6863.     mov    ax,40h
  6864.     mov    es,ax
  6865.     mov    ax,es:[50h]        ; current position
  6866.     cmp    ax,dx            ; same?
  6867.     pop    es
  6868.     jne    setpcur5        ; ne = no
  6869.     pop    ax
  6870.     pop    dx
  6871.     ret
  6872. setpcur5:push    bx
  6873.     mov    ah,2            ; set cursor
  6874.     xor    bh,bh            ; page 0
  6875.     int    screen
  6876.     pop    bx
  6877.     pop    ax
  6878.     pop    dx
  6879.     ret
  6880. setpcur    endp
  6881.  
  6882. ; Read char and attributes under physical cursor.
  6883. ; Returns AL = character, AH = video attributes
  6884. getpcha    proc    near
  6885.     push    bx
  6886.     mov    ah,8            ; read char and attributes
  6887.     xor    bh,bh            ; page 0
  6888.     int    screen            ; Bios video call
  6889.     pop    bx
  6890.     ret
  6891. getpcha    endp
  6892.  
  6893. ; Write char and attribute to screen at cursor position, do not move cursor.
  6894. ; AL = char, AH = video attribute, DL = column, DH = row, CL = logical 
  6895. ; attribute bits. Does not update physical screen.
  6896. qsetatch proc    near
  6897.     mov    setnoshow,1        ; turn off physical screen update
  6898.     jmp    setatch            ; call with same args
  6899. qsetatch endp
  6900.  
  6901. ; Write char and attribute to screen at cursor position, do not move cursor.
  6902. ; AL = char, AH = video attribute, DL = column, DH = row, CL = logical 
  6903. ; attribute bits. Turns off setnoshow at the end.
  6904.  
  6905. setatch    proc    near
  6906.     push    bx
  6907.     push    es
  6908.     push    cx            ; save logical attribute
  6909.     push    ax            ; save char and attribute
  6910.     cmp    setnoshow,0        ; show on real screen?
  6911.     jne    setatc1            ; ne = no, do just virtual screen
  6912.     push    cx
  6913.     call    setpos            ; set cursor at dx location
  6914.     pop    cx
  6915.     jc    setatc1            ; c = do not show character
  6916.     cmp    inemulator,0        ; emulating a terminal now?
  6917.     je    setatc4            ; e = no
  6918. ifndef    no_graphics
  6919.     cmp    flags.vtflg,tttek    ; full Tek?
  6920.     je    setatc5            ; e = yes
  6921.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6922.     jne    setatc4            ; ne = no, text mode
  6923. setatc5:push    dx
  6924.     push    si
  6925.     push    di
  6926.     mov    bl,dh            ; get row
  6927.     xor    bh,bh
  6928.     sub    dl,linescroll[bx]     ; deduct horizontal scroll
  6929.     call    ttxtchr            ; display char in graphics mode
  6930.     pop    di
  6931.     pop    si
  6932.     pop    dx
  6933.     jmp    short setatc1
  6934. endif    ; no_graphics
  6935. setatc4:
  6936.     mov    cx,1            ; one char
  6937.     mov    bl,ah            ; attribute
  6938.     xor    bh,bh            ; page 0
  6939.     mov    ah,9            ; write char, do not move cursor
  6940.     int    screen
  6941. setatc1:mov    setnoshow,0        ; always reset this automatically
  6942.                     ; write same material to vscreen
  6943.     mov    al,vswidth        ; width of vscreen line
  6944.     mul    dh            ; count across rows (0..)
  6945.     xor    bh,bh
  6946.     mov    bl,dl            ; get position
  6947.     add    bx,ax            ; add column
  6948.     add    bx,bx            ; times two for char and attrib
  6949.     pop    ax            ; recover char and attribute
  6950.     pop    cx            ; recover logical attribute
  6951. ifndef    no_terminal
  6952.     cmp    inemulator,0        ; in terminal emulator?
  6953.     je    setatc2            ; e = no, so no virtual screen
  6954.     push    di
  6955.     les    di,vs_ptr        ; virtual screen
  6956.     mov    es:[di+bx],ax        ; store char and attribute
  6957.     push    ax            ; save ah attributes
  6958.  
  6959.     les    di,vsat_ptr        ; attributes byte array
  6960.     shr    bx,1            ; bytes, vs words above
  6961.     mov    es:[bx+di],cl        ; set extended attributes
  6962.     pop    ax
  6963.     pop    di
  6964. endif    ; no_terminal
  6965. setatc2:pop    es
  6966.     pop    bx
  6967.     ret
  6968. setatch    endp
  6969.  
  6970. ifndef    no_terminal
  6971. ; Get bold video attribute bit
  6972. ; Returns AH = bold attribute bit (0 if not bold)
  6973. getbold    proc    near
  6974.     and    ah,att_bold
  6975.     test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  6976.     jnz    getbold1        ; nz = yes
  6977.     xor    ah,userbold        ; invert with user bold
  6978. getbold1:ret
  6979. getbold endp
  6980.  
  6981. ; Set bold video attribute bit, current video attribute supplied in AH
  6982. setbold proc    near
  6983.     or    ah,att_bold
  6984.     cmp    colunder,0ffh        ; uninited?
  6985.     je    setbold2        ; e = yes, don't change here
  6986.     or    colunder,att_bold
  6987. setbold2:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  6988.     jnz    setbold1        ; nz = yes
  6989.     xor    ah,userbold        ; invert with user bold
  6990.     cmp    colunder,0ffh        ; uninited?
  6991.     je    setbold1        ; e = yes, don't change here
  6992.     push    ax
  6993.     mov    ah,userbold
  6994.     xor    colunder,ah
  6995.     pop    ax
  6996. setbold1:ret
  6997. setbold endp
  6998.  
  6999. ; Clear bold video attribute bit, current video attribute supplied in AH
  7000. clrbold    proc    near
  7001.     and    ah,not att_bold
  7002.     cmp    colunder,0ffh        ; uninited?
  7003.     je    clrbold2        ; e = yes, don't change here
  7004.     and    colunder,not att_bold
  7005. clrbold2:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  7006.     jnz    clrbold1        ; nz = yes
  7007.     xor    ah,userbold        ; invert with user bold
  7008.     cmp    colunder,0ffh        ; uninited?
  7009.     je    clrbold1        ; e = yes, don't change here
  7010.     push    ax
  7011.     mov    ah,userbold
  7012.     or    colunder,ah
  7013.     pop    ax
  7014. clrbold1:ret
  7015. clrbold    endp
  7016.  
  7017. ; Get blink video attribute bit
  7018. ; Returns AH = blink attribute bit
  7019. getblink proc    near
  7020.     and    ah,att_blink
  7021.     ret
  7022. getblink endp
  7023.  
  7024. ; Set blink video attribute bit, current video attribute supplied in AH
  7025. setblink proc    near
  7026.     or    ah,att_blink
  7027.     ret
  7028. setblink endp
  7029.  
  7030. ; Clear blink video attribute bit, current video attribute supplied in AH
  7031. clrblink proc    near
  7032.     and    ah,not att_blink
  7033.     ret
  7034. clrblink endp
  7035.  
  7036. ; Set extended attribute for protection in extattr and in CL.
  7037. setprot    proc    near            ; set protected mode
  7038.     or    extattr,att_protect
  7039.     or    cl,att_protect        ; and in cl
  7040.     ret
  7041. setprot    endp
  7042.  
  7043. ; Clear extended attribute for protection in extattr and in CL.
  7044. clrprot    proc    near            ; clear protected mode
  7045.     and    extattr,not att_protect
  7046.     and    cl,not att_protect
  7047.     ret
  7048. clrprot endp
  7049.  
  7050. ; Get underline video attribute bit from extattr
  7051. ; Returns CL = underline attribute bit
  7052. getunder proc    near
  7053.     mov    cl,extattr        ; get extended attribute
  7054.     and    cl,att_uline        ; return underline status bit
  7055.     ret
  7056. getunder endp
  7057.  
  7058. ; Set underline video attribute bit, current video attribute supplied in AH
  7059. ; and extended attributes in extattr. Returns new AH and extattr in CL.
  7060. setunder proc    near
  7061.     test    extattr,att_uline    ; extended attributes, on already?
  7062.     jz    setund1            ; z = no
  7063.     ret                ; else do nothing
  7064. setund1:or    extattr,att_uline    ; set underline attribute for MSZ
  7065.     or    cl,att_uline
  7066.     cmp    crt_mode,7        ; monochrome display adapter mode?
  7067.     je    setund6            ; e = yes
  7068.     cmp    colunder,0ffh        ; uninited?
  7069.     je    setund10        ; e = yes
  7070.  
  7071.     and    ah,att_blink        ; preserve blink
  7072.     or    ah,colunder        ; user specified underline coloring
  7073.     test    extattr,att_rev        ; are we reversed per char?
  7074.     jz    setund8            ; z = no
  7075.     call    revideo
  7076. setund8:cmp    reversed_screen,0    ; whole screen reversed too?
  7077.     je    setund9            ; e = no
  7078.     call    revideo
  7079. setund9:ret
  7080.  
  7081. setund10:push    bx
  7082.     push    dx
  7083.     mov    bh,al            ; preserve possible char in al
  7084.     mov    dl,scbattr        ; screen fill
  7085.     and    dl,70h            ; background colors
  7086.     mov    bl,extattr        ; extended attributes
  7087.     and    bl,att_rev        ; per char reversed video
  7088.     mov    dh,ah            ; current character attributes
  7089.     and    dh,not 77h        ; blink/bold attributes only
  7090.     and    ah,77h            ; colors only
  7091.     mov    al,ah
  7092.     shr    al,1
  7093.     shr    al,1
  7094.     shr    al,1
  7095.     shr    al,1            ; background to lower nibble
  7096.     and    ah,7            ; foreground only
  7097.     or    bl,bl            ; reversed video attribute?
  7098.     jz    setund3            ; z = no, normal
  7099.     xchg    ah,al            ; real background color to al
  7100. setund3:xor    al,ah            ; modify background
  7101.     or    dl,dl            ; case of black background?
  7102.     jnz    setund4            ; nz = no
  7103.     mov    al,ah
  7104.     dec    al
  7105.     and    al,7            ; background goes to (foreground-1)/8
  7106.     or    al,al            ; still black?
  7107.     jnz    setund4            ; nz = no
  7108.     mov    al,7            ; force non-black (white foreground)
  7109. setund4:shl    al,1            ; background to high nibble
  7110.     shl    al,1
  7111.     shl    al,1
  7112.     shl    al,1
  7113.     or    ah,al            ; or new background
  7114.     or    bl,bl            ; per char reversal?
  7115.     jz    setund5            ; z = no
  7116.     rol    ah,1            ; yes, flip fore/background again
  7117.     rol    ah,1
  7118.     rol    ah,1
  7119.     rol    ah,1
  7120. setund5:or    ah,dh            ; restore blink and bold
  7121.     pop    dx
  7122.     mov    al,bh            ; restore possible char
  7123.     pop    bx
  7124.     ret
  7125. setund6:push    bx
  7126.     mov    bl,al            ; preserve char in AL
  7127.     call    brkatt            ; monochrome, break apart
  7128.     mov    ah,att_underline    ; set mono underline coloring
  7129.     or    ah,al            ; put back blink/bold
  7130.     test    extattr,att_rev        ; are we reversed per char?
  7131.     jz    setund6a        ; z = no
  7132.     call    revideo
  7133. setund6a:cmp    reversed_screen,0    ; whole screen reversed too?
  7134.     je    setund6b        ; e = no
  7135.     call    revideo
  7136. setund6b:mov    al,bl            ; restore char in AL
  7137.     pop    bx
  7138.     ret
  7139. setunder endp
  7140.  
  7141. ; Clear underline video attribute bit, current video attribute supplied in AH
  7142. ; and extended attributes in extattr. Returns new AH and extattr in CL.
  7143. clrunder proc    near
  7144.     test    extattr,att_uline    ; extended attributes, off already?
  7145.     jnz    clrund1            ; nz = no
  7146.     ret                ; else do nothing
  7147. clrund1:and    extattr,not att_uline    ; clear underline attribute for MSZ
  7148.     and    cl,not att_uline
  7149.     cmp    crt_mode,7        ; monochrome display adapter mode?
  7150.     je    clrund6            ; e = yes, otherwise reverse video
  7151.     cmp    colunder,0ffh        ; user spec underline inited?
  7152.     je    clrund10        ; e = no
  7153.     and    ah,att_blink        ; preserve blink
  7154.     or    ah,att_normal        ; current normal coloring
  7155.     test    extattr,att_rev        ; are we reversed per char?
  7156.     jz    clrund1a        ; z = no
  7157.     call    revideo
  7158. clrund1a:cmp    reversed_screen,0    ; whole screen reversed too?
  7159.     je    clrund1b        ; e = no
  7160.     call    revideo
  7161. clrund1b:ret    
  7162.     
  7163. clrund6:push    bx
  7164.     mov    bl,al            ; preserve char in al
  7165.     call    brkatt            ; mono, break apart attributes
  7166.     mov    ah,07h            ; set normal coloring
  7167.     or    ah,al            ; reassemble attributes
  7168.     test    extattr,att_rev        ; are we reversed per char?
  7169.     jz    clrund6a        ; z = no
  7170.     call    revideo
  7171. clrund6a:cmp    reversed_screen,0    ; whole screen reversed too?
  7172.     je    clrund6b        ; e = no
  7173.     call    revideo
  7174. clrund6b:mov    al,bl            ; restore char in AL
  7175.     pop    bx
  7176.     ret
  7177.  
  7178. clrund10:push    bx
  7179.     push    dx
  7180.     mov    bh,al            ; save possible char in al
  7181.     xor    bl,bl
  7182.     mov    dl,scbattr        ; screen fill
  7183.     and    dl,70h            ; background colors
  7184.     mov    bl,extattr        ; extended attributes
  7185.     and    bl,att_rev        ; per char reversed video
  7186.     mov    dh,ah            ; current char attributes
  7187.     and    dh,not 77h        ; blink/bold attributes only
  7188.     and    ah,77h            ; colors only
  7189.     mov    al,ah
  7190.     shr    al,1
  7191.     shr    al,1
  7192.     shr    al,1
  7193.     shr    al,1            ; background to lower nibble
  7194.     and    ah,7            ; foreground only
  7195.     or    bl,bl            ; reversed video attribute?
  7196.     jz    clrund3            ; z = no, normal
  7197.     xchg    ah,al            ; real background color to al
  7198. clrund3:or    dl,dl            ; case of black background?
  7199.     jz    clrund4            ; z = yes, leave it black (empty)
  7200.     xor    al,ah
  7201.     shl    al,1            ; background to high nibble
  7202.     shl    al,1
  7203.     shl    al,1
  7204.     shl    al,1
  7205.     or    ah,al            ; or in new background
  7206. clrund4:or    bl,bl            ; per char reversal?
  7207.     jz    clrund5            ; z = no
  7208.     rol    ah,1            ; yes, reverse nibbles again
  7209.     rol    ah,1
  7210.     rol    ah,1
  7211.     rol    ah,1
  7212. clrund5:or    ah,dh            ; restore blink and bold
  7213.     pop    dx
  7214.     mov    al,bh            ; restore possible char
  7215.     pop    bx
  7216.     ret    
  7217. clrunder endp
  7218. endif    ; no_terminal
  7219.  
  7220. ; Compute reversed video attributes, given displayables in AH and extended
  7221. ; in extattr. Returns new attribute in AH and CL holding new extattr
  7222. setrev    proc    near
  7223.     test    extattr,att_rev        ; reversed now?
  7224.     jnz    setrev2            ; nz = yes
  7225.     call    revideo            ; do reversal
  7226.     or    extattr,att_rev        ; update extended attribute
  7227.     or    cl,att_rev
  7228. setrev2:ret
  7229. setrev    endp
  7230.  
  7231. ; Compute un-reversed video attributes, given displayables in AH and extended
  7232. ; in extattr. Returns new attribute in AH and CL holding new extattr
  7233. clrrev    proc    near
  7234.     test    extattr,att_rev        ; reversed now?
  7235.     jz    clrrev1            ; z = no
  7236.     call    revideo            ; do reversal
  7237.     and    extattr,not att_rev    ; update extended attribute
  7238.     and    cl,not att_rev        ; update extended attribute
  7239. clrrev1:ret
  7240. clrrev    endp
  7241.  
  7242.  
  7243. ; Compute reversed video attribute byte. Normally preserves blink/bold.
  7244. ; Enter with AH = video attribute byte, returns new attribute byte in AH.
  7245. revideo    proc    near
  7246.     push    bx
  7247.     mov    bl,al            ; preserve char in AL
  7248.     call    brkatt            ; separate colors from blink/bold
  7249.     rol    ah,1            ; reverse foreground & background
  7250.     rol    ah,1            ; RGB bits
  7251.     rol    ah,1
  7252.     rol    ah,1
  7253.     cmp    crt_mode,7        ; monochrome?
  7254.     jne    revideo1        ; ne = no
  7255.     test    al,att_bold        ; bold?
  7256.     jz    revideo1        ; z = no
  7257.     test    ah,7            ; black foreground now?
  7258.     jnz    revideo1        ; nz = no, something to brighten
  7259.     and    al,not att_bold        ; remove bolding
  7260. revideo1:or    ah,al            ; reinsert bold/blink bits
  7261.     mov    al,bl            ; restore char in AL
  7262.     pop    bx
  7263.     ret
  7264. revideo    endp
  7265.  
  7266. ; This routine picks an attribute apart into its component "parts" - the
  7267. ; base attribute for the screen and the "extras" - i.e., blink, intensity
  7268. ; and underline.
  7269. ; enter with    ah = a cursor attribute
  7270. ; return    ah = base attribute for screen (07H normal, 70H reverse).
  7271. ;        al = "extra" attributes
  7272. ; Note that there is a complementary routine, addatt, for putting attributes
  7273. ; back together.
  7274.  
  7275. brkatt:    mov    al,ah            ; copy displayables
  7276.     and    al,(att_blink+att_bold)    ; get modifiers
  7277.     and    ah,not (att_bold+att_blink) ; strip blink/bold, leave color
  7278.     ret
  7279.  
  7280. ; This routine builds a cursor attribute given the base attribute for the
  7281. ; screen background and the "extra" attributes we want (blink, etc.).
  7282. ; enter with    ah = base attribute for background (07H or 70H)
  7283. ;        al = "extra" attributes (89H for all three)
  7284. ; return    ah = base combined with "extras".
  7285.  
  7286. addatt: or    ah,al            ; OR the attributes
  7287.     ret
  7288.  
  7289. ifndef    no_terminal
  7290.  
  7291. ; This routine is called when we want to reverse everything on the screen
  7292. ; from normal to reverse video, or vice versa.    It is called only when
  7293. ; the decscnm attribute is changed.
  7294. ; Call:    no arguments.
  7295.  
  7296. revscn    proc    near
  7297.     push    ax
  7298.     push    bx
  7299.     push    cx
  7300.     push    dx
  7301.     xor    reversed_screen,1    ; remember we did this
  7302.     mov    dh,byte ptr low_rgt+1    ; compute last screen offset in ax
  7303.     inc    dh            ; one more row to catch mode line
  7304.     mov    dl,vswidth        ; logical screen buffer
  7305.     dec    dl            ; and we count from 0
  7306.     call    scrloc            ; get screen offset into ax
  7307.     mov    cx,ax            ; save it in cx for a minute
  7308.     add    cx,2
  7309.     sar    cx,1            ; in 16-bit words please
  7310.     push    di            ; Save some more acs
  7311.     push    es
  7312.     les    di,vs_ptr        ; seg and offset of vscreen
  7313.     cld
  7314. revsc1:    mov    ax,es:[di]        ; fetch a word
  7315.     mov    bl,al            ; save the character
  7316.     call    revideo            ; get reversed video attributes (AH)
  7317.     mov    al,bl            ; restore character
  7318.     stosw                ; stuff into screen memory
  7319.     loop    revsc1            ; loop for entire screen
  7320.     pop    es            ; restore segment register
  7321.     pop    di            ; and destination index
  7322.     pop    dx
  7323.     pop    cx
  7324.     pop    bx
  7325.     call    repaint
  7326.     pop    ax
  7327.     ret
  7328. revscn    endp
  7329.  
  7330. ; Set coloring attributes.
  7331. ; Enter with AH holding current video attribute byte,
  7332. ; BL holding ANSI color code (30-37 or 40-47) where 30's are foreground,
  7333. ; 40's are background. ANSI colors are 1 = red, 2 = green, 4 = blue.
  7334. ; Return new attribute byte in AH.
  7335.  
  7336. setcolor proc    near
  7337.     test    extattr,att_rev        ; normal video currently?
  7338.     jz    setcol0            ; z = yes
  7339.     mov    al,ah            ; make a copy
  7340.     and    ax,7788h        ; strip bold,blink, keep both in al
  7341.     rol    ah,1            ; get colors in right parts
  7342.     rol    ah,1            ;  of ah = back, al = foreground
  7343.     rol    ah,1
  7344.     rol    ah,1
  7345.     call    setcol0            ; set fore or background color
  7346.     rol    ah,1            ; reverse coloring again
  7347.     rol    ah,1
  7348.     rol    ah,1
  7349.     rol    ah,1
  7350.     or    ah,al            ; put back blink and bold
  7351.     ret
  7352.  
  7353. setcol0:cmp    bl,30            ; ANSI color series?
  7354.     jb    setcol7            ; b = no
  7355.     cmp    bl,37            ; foreground set (30-37)?
  7356.     ja    setcol4            ; a = no, try background set
  7357.     sub    bl,30            ; take away the bias
  7358.     and    ah,not 07H        ; clear foreground bits
  7359.     test    bl,1            ; ANSI red?
  7360.     jz    setcol1            ; z = no
  7361.     or    ah,4            ; IBM red foreground bit
  7362. setcol1:test    bl,2            ; ANSI & IBM green?
  7363.     jz    setcol2            ; z = no
  7364.     or    ah,2            ; IBM green foreground bit
  7365. setcol2:test    bl,4            ; ANSI blue?
  7366.     jz    setcol3            ; z = no
  7367.     or    ah,1            ; IBM blue foreground bit
  7368. setcol3:ret
  7369.  
  7370. setcol4:cmp    bl,40            ; background color set?
  7371.     jb    setcol7            ; b = no
  7372.     cmp    bl,47            ; background set is 40-47
  7373.     ja    setcol7            ; nb = no, not a color command
  7374.     sub    bl,40            ; take away the bias
  7375.     and    ah,not 70H        ; clear background bits
  7376.     test    bl,1            ; ANSI red?
  7377.     jz    setcol5            ; z = no
  7378.     or    ah,40h            ; IBM red background bit
  7379. setcol5:test    bl,2            ; ANSI & IBM green?
  7380.     jz    setcol6            ; z = no
  7381.     or    ah,20h            ; IBM green background bit
  7382. setcol6:test    bl,4            ; ANSI blue?
  7383.     jz    setcol7            ; z = no
  7384.     or    ah,10h            ; IBM blue background bit
  7385. setcol7:ret
  7386. setcolor endp
  7387.  
  7388. ifndef    no_tcp
  7389. ; Save terminal emulator, session is in BX.
  7390. ; Delete older save buffer for this session, so that compressed vscreen
  7391. ; can be saved properly.
  7392. termswapout proc far
  7393.     cmp    bx,6            ; legal session number?
  7394.     jb    termso0            ; b = yes
  7395.     stc
  7396.     ret
  7397. termso0:push    ax
  7398.     push    bx
  7399.     push    cx
  7400.     push    si
  7401.     push    di
  7402.     shl    bx,1            ; to words
  7403.     mov    temp,bx            ; save session ident
  7404.     cmp    tsave[bx],0        ; have a storage buffer?
  7405.     je    termso9            ; ne = no, create one now
  7406.     shr    bx,1            ; get original BL session indicator
  7407.     call    termswapdel        ; delete old save area
  7408.     shl    bx,1            ; restore word indexing
  7409. termso9:
  7410. ifndef    no_graphics
  7411.     mov    ax,31*2            ; softlist, 31 words
  7412. else
  7413.     xor    ax,ax
  7414. endif    ; no_graphics
  7415.     call    getvssize        ; get size of vscreen, compressed
  7416.     add    ax,bx            ; accumulate new from bx
  7417.     call    getvasize        ; size of attributes
  7418.     add    bx,ax            ; new total to bx
  7419.     add    bx,savexlen        ; plus length of MSX save area
  7420.     add    bx,saveylen        ; plus MSY save area
  7421.     add    bx,savezlen        ; plus MSZ area
  7422.     add    bx,saveplen        ; plus parser in MSSCMD
  7423.     add    bx,saveulen        ; plus MSU area
  7424. ifndef    no_graphics
  7425.     add    bx,saveglen        ; plus MSG area
  7426. endif    ; no_graphics
  7427.     add    bx,15            ; round up
  7428.     mov    cl,4
  7429.     shr    bx,cl            ; convert to paragraphs
  7430.     mov    cx,bx            ; save request in cx
  7431.     mov    ah,alloc        ; please, more space
  7432.     int    dos            ; paragraph to ax, num paras to bx
  7433.     cmp    bx,cx            ; given vs wanted
  7434.     jae    termso1            ; ae = got it
  7435.     pop    di
  7436.     pop    si
  7437.     pop    cx
  7438.     pop    bx
  7439.     pop    ax
  7440.     stc                ; fail
  7441.     ret
  7442. termso1:
  7443. ifndef    no_graphics
  7444.     push    temp
  7445.     push    ax
  7446.     call    tekend            ; exit graphics mode
  7447.     pop    ax
  7448.     pop    temp
  7449. endif    ; no_graphics
  7450.     mov    bx,temp            ; get 2 * session number (sescur)
  7451.     mov    tsave[bx],ax        ; save starting paragraph
  7452.  
  7453.     push    es
  7454.     mov    es,ax            ; save area is destination
  7455.     xor    di,di            ; offset of save area
  7456. ifndef    no_graphics
  7457.     mov    si,seg softlist        ; where softlist lives
  7458.     push    ds
  7459.     mov    ds,si
  7460.     mov    si,offset softlist
  7461.     mov    cx,31            ; number of entries
  7462.     cld
  7463.     rep    movsw            ; save segs of soft font in msgibm
  7464.     pop    ds
  7465. endif    ; no_graphics
  7466.  
  7467.     push    es            ; save tsave seg
  7468.     push    di            ; save current dest ptr
  7469.     mov    cx,ds
  7470.     mov    es,cx
  7471.     mov    cx,size flginfo        ; length of saved flags array
  7472.     mov    di,offset saveflag    ; saved array
  7473.     mov    si,offset flags        ; working array
  7474.     rep    movsb            ; save
  7475.     pop    di            ; tsave dest offset
  7476.     pop    es            ; tsave seg
  7477.  
  7478. ; virtual screen is saved as structure
  7479. ; scr-len    dw    text screen length (typically 24 lines)
  7480. ; with the items below repeated for each line (scr-len total lines)
  7481. ; per-line    dw    saved chars on this line
  7482. ;        dw    per-line dup (char & attribute)
  7483. ; with the last saved char on each line being repeated to endofline on screen
  7484.     push    bx            ; virtual screen saving
  7485.     mov    cl,crt_lins        ; number of screen lines - 1
  7486.     inc    cl            ; add status line to save block
  7487.     xor    ch,ch
  7488.     mov    ax,cx
  7489.     cld
  7490.     stosw                ; store screen length as first word
  7491.     xor    bx,bx            ; line counter
  7492.     mov    si,word ptr vs_ptr    ; offset of vscreen
  7493. termso3:push    cx            ; save line loop counter
  7494.     mov    cx,word ptr rdbuf[bx]    ; get number of saveable chars on line
  7495.     mov    ax,cx            ; store char count as first word
  7496.     stosw
  7497.     mov    ax,word ptr vs_ptr+2    ; get vscreen segment
  7498.     push    si
  7499.     push    ds
  7500.     mov    ds,ax
  7501.     rep    movsw            ; copy saveable chars
  7502.     pop    ds
  7503.     pop    si
  7504.     pop    cx            ; recover line counter
  7505.     add    bx,2            ; next line, get length info
  7506.     add    si,vswidth*2        ; next line, offset of vscreen line
  7507.     loop    termso3
  7508.     pop    bx            ; end of vscreen saving
  7509.                     ;
  7510.     push    bx            ; virtual screen saving
  7511.     mov    cl,crt_lins        ; number of screen lines - 1
  7512.     inc    cl            ; do all lines
  7513. termso3b:xor    ch,ch
  7514.     mov    ax,cx
  7515.     cld
  7516.     stosw                ; store screen length as first word
  7517.     xor    bx,bx            ; line counter
  7518.     mov    si,word ptr vsat_ptr    ; offset of vsattr
  7519. termso7:push    cx            ; save line loop counter
  7520.     mov    cx,word ptr rdbuf[bx+120]; get num of saveable bytes on line
  7521.     mov    ax,cx            ; store char count as first word
  7522.     stosw
  7523.     mov    ax,word ptr vsat_ptr+2    ; get vsattr segment
  7524.     push    si
  7525.     push    ds
  7526.     mov    ds,ax
  7527.     shr    cx,1            ; get odd byte count info
  7528.     jnc    termso7a        ; nc = even count
  7529.     movsb
  7530. termso7a:rep    movsw            ; copy saveable bytes
  7531.     pop    ds
  7532.     pop    si
  7533.     pop    cx            ; recover line counter
  7534.     add    bx,2            ; next line, get length info
  7535.     add    si,vswidth        ; next line, offset of vsattr line
  7536.     loop    termso7
  7537.     pop    bx            ; end of vsattr saving
  7538.                     ;
  7539.     mov    si,offset saveyoff    ; offset of MSY save area
  7540.     mov    cx,saveylen        ; length of MSY save area
  7541.     cld
  7542.     shr    cx,1            ; even/odd?
  7543.     jnc    termso4            ; nc = even
  7544.     movsb                ; the odd byte
  7545. termso4:rep    movsw
  7546.     mov    si,offset savezoff    ; offset of MSZ save area
  7547.     mov    cx,savezlen        ; length of MSZ save area
  7548.     shr    cx,1
  7549.     jnc    termso5
  7550.     movsb
  7551. termso5:rep    movsw
  7552.     mov    si,offset savexoff    ; offset of MSX save area
  7553.     mov    cx,savexlen        ; length of MSX save area
  7554.     cld
  7555.     cli                ; cautious about serial ints
  7556.     shr    cx,1            ; even/odd?
  7557.     jnc    termso6            ; nc = even
  7558.     movsb                ; the odd byte
  7559. termso6:rep    movsw
  7560.     sti
  7561.     mov    si,offset savepoff    ; offset of MSSCMD parser save area
  7562.     mov    cx,saveplen        ; length of the area
  7563.     shr    cx,1
  7564.     jnc    termso6a
  7565.     movsb
  7566. termso6a:rep    movsw
  7567.     mov    si,offset saveuoff    ; offset of MSUIBM kbd save area
  7568.     mov    cx,saveulen        ; length of the area
  7569.     shr    cx,1
  7570.     jnc    termso6b
  7571.     movsb
  7572. termso6b:rep    movsw
  7573.  
  7574. ifndef    no_graphics
  7575.     mov    si,offset savegoff    ; offset of MSG save area
  7576.     mov    cx,saveglen        ; length of MSG save area
  7577.     shr    cx,1            ; graphics mode exited above
  7578.     jnc    termso6c
  7579.     movsb
  7580. termso6c:rep    movsw
  7581. endif    ; no_graphics
  7582.     pop    es
  7583.     mov    ax,100h            ; assume using 80 col screen
  7584.     cmp    dos_cols,80        ; startup screen width
  7585.     jbe    termso8            ; be = assume 80 columns
  7586.     inc    al            ; say do 132 columns
  7587. termso8:push    vtemu.vtflgop
  7588.     or    vtemu.vtflgop,vscompress ; turn off compressed mode
  7589.     call    chgdsp            ; reset display width to startup
  7590.     pop    vtemu.vtflgop
  7591.     pop    di
  7592.     pop    si
  7593.     pop    cx
  7594.     pop    bx
  7595.     pop    ax
  7596.     clc
  7597.     ret
  7598. termswapout endp
  7599.  
  7600. ; Restore terminal emulator, session is BX
  7601. ; Delete save buffer after restoration.
  7602. termswapin proc    far
  7603.     cmp    bx,6            ; valid session?
  7604.     jb    termsi0            ; b = yes
  7605.     stc
  7606.     ret
  7607. termsi0:push    bx
  7608.     shl    bx,1            ; to words
  7609.     cmp    tsave[bx],0        ; have a storage buffer?
  7610.     pop    bx
  7611.     jne    termsi1            ; ne = yes, use it
  7612.     mov    vtinited,0        ; say not inited
  7613.     stc                ; fail
  7614.     ret
  7615.  
  7616. termsi1:push    ax
  7617.     push    bx
  7618.     push    cx
  7619.     push    si
  7620.     push    di
  7621.     push    es            ; virtual screen restore
  7622. ifndef    no_graphics
  7623.     test    tekflg,tek_active    ; current graphics mode status
  7624.     jz    tswapin1a        ; z = not in graphics mode
  7625.     push    bx
  7626.     call    tekend
  7627.     pop    bx
  7628. endif    ; no_graphics
  7629. tswapin1a:
  7630.     shl    bx,1            ; address words
  7631.     mov    ax,tsave[bx]        ; starting paragraph for save area
  7632.     push    ds
  7633.     mov    ds,ax            ; save area is source
  7634.     xor    si,si            ; offset of save area
  7635. ifndef    no_graphics
  7636.     mov    di,seg softlist        ; seg of destination
  7637.     mov    es,di
  7638.     mov    di,offset softlist
  7639.     mov    cx,31            ; number of entries
  7640.     cld
  7641.     rep    movsw            ; restore segs of soft font in msgibm
  7642. endif    ; no_graphics
  7643.     pop    ds
  7644.  
  7645.     les    di,vs_ptr        ; seg and offset of vscreen
  7646.     mov    ax,tsave[bx]        ; starting paragraph of save area
  7647.     push    ds
  7648.     mov    ds,ax            ; source segment is save area
  7649.     lodsw                ; get screen length
  7650.     mov    cx,ax            ; counter of vscreen lines to do
  7651. tswapi2:push    cx            ; save line counter
  7652.     lodsw                ; get count of saved chars of line
  7653.     dec    ax            ; omit repeated char til next step
  7654.     mov    cx,ax            ; count for saved char writes
  7655.     rep    movsw            ; copy saved chars except last one
  7656.     mov    cx,vswidth        ; total line width (chars)
  7657.     sub    cx,ax            ; minus those done
  7658.     lodsw                ; get last char (this repeats to end)
  7659.     rep    stosw            ; repeat last char
  7660.     pop    cx            ; recover line counter
  7661.     loop    tswapi2            ; do all text lines (omit status)
  7662.     pop    ds            ; restore DS, SI is ready for nxt grp
  7663.                     ; end of virtual screen restoration
  7664.                     ; attributes, vsatt, for vscreen
  7665.     les    di,vsat_ptr        ; seg and offset of vsatt
  7666.     mov    ax,tsave[bx]        ; starting paragraph of save area
  7667.     push    ds
  7668.     mov    ds,ax            ; source segment is save area
  7669.     lodsw                ; get screen length
  7670.     mov    cx,ax            ; counter of vsattr lines to do
  7671. tswapi7:push    cx            ; save line counter
  7672.     lodsw                ; get count of saved bytes of line
  7673.     dec    ax            ; omit repeated byte til next step
  7674.     mov    cx,ax            ; count for saved byte writes
  7675.     shr    cx,1            ; do odd byte copy
  7676.     jnc    tswapi7a        ; nc = even count
  7677.     movsb
  7678. tswapi7a:rep    movsw            ; copy saved bytes except last one
  7679.     mov    cx,vswidth        ; total line width (bytes)
  7680.     sub    cx,ax            ; minus those done
  7681.     lodsb                ; get last byte (this repeats to end)
  7682.     rep    stosb            ; repeat last byte
  7683.     pop    cx            ; recover line counter
  7684.     loop    tswapi7            ; do all text lines (omit status)
  7685.     pop    ds            ; restore DS, SI is ready for nxt grp
  7686.                     ; end of virtual screen restoration
  7687.  
  7688.     mov    ax,ds            ; regular data seg "data"
  7689.     mov    es,ax            ; new data seg
  7690.     mov    di,offset saveyoff    ; offset of MSY save area
  7691.     mov    cx,saveylen        ; length of MSY save area
  7692.     mov    ax,tsave[bx]        ; starting paragraph of save area
  7693.     push    ds
  7694.     mov    ds,ax            ; source segment is save area
  7695.     cld
  7696.     shr    cx,1            ; even/odd?
  7697.     jnc    termsi3            ; nc = even
  7698.     movsb                ; the odd byte
  7699. termsi3:rep    movsw
  7700.     mov    di,offset savezoff    ; offset of MSZ save area
  7701.     mov    cx,es:savezlen        ; length of MSZ save area
  7702.     shr    cx,1
  7703.     jnc    termsi4
  7704.     movsb
  7705. termsi4:rep    movsw
  7706.     mov    di,offset savexoff    ; offset of MSX save area
  7707.     mov    cx,es:savexlen        ; length of MSX save area
  7708.     cli                ; cautious about serial ints
  7709.     shr    cx,1
  7710.     jnc    termsi5
  7711.     movsb
  7712. termsi5:rep    movsw
  7713.     sti
  7714.     mov    di,offset savepoff    ; offset of MSSCMD parser area
  7715.     mov    cx,es:saveplen        ; length
  7716.     shr    cx,1
  7717.     jnc    termsi6
  7718.     movsb
  7719. termsi6:rep    movsw
  7720.     mov    di,offset saveuoff    ; offset of MSUIBM kbd area
  7721.     mov    cx,es:saveulen        ; length
  7722.     shr    cx,1
  7723.     jnc    termsi6a
  7724.     movsb
  7725. termsi6a:rep    movsw
  7726.  
  7727. ifndef    no_graphics
  7728.     mov    di,offset savegoff    ; offset of MSGIBM area
  7729.     mov    cx,es:saveglen        ; length
  7730.     shr    cx,1
  7731.     jnc    termsi8
  7732.     movsb
  7733. termsi8:rep    movsw
  7734. endif    ; no_graphics
  7735.     pop    ds
  7736.     mov    cx,ds
  7737.     mov    es,cx
  7738.     mov    cx,size flginfo        ; length of saved flags array
  7739.     mov    si,offset saveflag    ; saved array
  7740.     mov    di,offset flags        ; working array
  7741.     rep    movsb            ; restore
  7742.     mov    ah,savattr        ; get saved coloring
  7743.     mov    scbattr,ah        ; replace what DOS may have used
  7744.     and    tekflg,not tek_active    ; say graphics is not active
  7745.     pop    es
  7746.     pop    di
  7747.     pop    si
  7748.     pop    cx
  7749.     pop    bx
  7750.     pop    ax
  7751.     call    termswapdel        ; delete this saved area, BL=session
  7752.     clc
  7753.     ret
  7754. termswapin endp
  7755.  
  7756. ; Remove saved terminal emulator buffers, BX is sescur (-1 means all)
  7757. termswapdel proc far
  7758.     cmp    bx,-1            ; all?
  7759.     jne    tswapdw            ; ne = no, just one
  7760.     mov    cx,6            ; number of possible sessions
  7761.     push    bx
  7762.     xor    bx,bx            ; session index
  7763. tswapd1:call    tswapdw            ; delete bufs for this session (BX)
  7764.     inc    bx
  7765.     loop    tswapd1            ; and all others
  7766.     pop    bx
  7767.     ret
  7768.  
  7769. tswapdw    proc    far            ; worker within termswapdel
  7770.     push    ax            ; delete session BX
  7771.     push    bx
  7772.     cmp    bx,5            ; largest session
  7773.     ja    tswapd2            ; a = illegal, ignore
  7774.     shl    bx,1            ; to words
  7775.     xor    ax,ax            ; clearing indicator
  7776.     xchg    ax,tsave[bx]        ; paragraph of save area
  7777.     or    ax,ax            ; anything there?
  7778.     jnz    tswapd3            ; nz = yes
  7779. tswapd2:pop    bx
  7780.     pop    ax
  7781.     stc
  7782.     ret
  7783.  
  7784. tswapd3:
  7785. ifndef    no_graphics
  7786.     push    es
  7787.     push    ax            ; save seg of save buffer
  7788.     push    cx
  7789.     mov    es,ax            ; seg of save buffer
  7790.     xor    si,si            ; offset in save area of softlist
  7791.     mov    cx,31            ; number of entries
  7792.     cld
  7793. tswapd4:lodsw                ; saved segs of soft font in msgibm
  7794.     or    ax,ax            ; any seg defined?
  7795.     jz    tswapd5            ; z = no
  7796.     push    es
  7797.     mov    es,ax            ; set paragraph to es for DOS
  7798.     mov    ah,freemem
  7799.     int    dos
  7800.     pop    es
  7801. tswapd5:loop    tswapd4
  7802.     pop    cx
  7803.     pop    es            ; recover seg of save buffer from AX
  7804.     mov    ah,freemem        ; free the memory
  7805.     int    dos
  7806.     pop    es
  7807. endif    ; no_graphics
  7808.  
  7809.     pop    bx
  7810.     pop    ax
  7811.     clc
  7812.     ret
  7813. tswapdw    endp
  7814.  
  7815. termswapdel endp
  7816.  
  7817. ; Examine vscreen line by line. Count number of characters by excluding the
  7818. ; trailing repetitions (keep first example) on each line, sum them. Add to 
  7819. ; the sum a word per line to hold the count of such characters and one more 
  7820. ; word to hold the screen length.
  7821. ; Return the number of bytes in register bx for malloc-ing.
  7822. getvssize proc    near
  7823.     push    ax
  7824.     push    cx
  7825.     push    dx
  7826.     push    di
  7827.     push    es
  7828.     les    di,vs_ptr        ; pointer to vscreen
  7829.     xor    bx,bx            ; line counter
  7830.     mov    cl,crt_lins        ; lines on screen - 1
  7831.     xor    ch,ch
  7832.     inc    cl            ; add status line
  7833.     mov    dx,cx            ; accumulated count <cnt, line>
  7834.     inc    dx            ; count screen size word itself
  7835.     add    di,(vswidth - 1) * 2    ; offset of last char on the line
  7836. getvssi1:push    cx            ; save line counter
  7837.     mov    cx,vswidth-1        ; chars on line - 1
  7838.     mov    ax,es:[di]        ; get last char+attrib on the line
  7839.     push    di
  7840.     sub    di,2
  7841.     std                ; scan backward
  7842.     repe    scasw            ; scan while equal (trim trailing rpt)
  7843.     cld
  7844.     pop    di
  7845.     je    getvssi2        ; e = ended on all same char
  7846.     inc    cx            ; ne case gobbles extra char
  7847. getvssi2:inc    cx            ; count the trailing char
  7848.     mov    word ptr rdbuf[bx],cx    ; store number of words here
  7849.     add    dx,cx            ; accumulate count of chars
  7850.     add    bx,2            ; next line
  7851.     add    di,vswidth*2        ; end of next line
  7852.     pop    cx            ; line counter
  7853.     loop    getvssi1
  7854.  
  7855.     add    dx,dx            ; chars to bytes accumulated
  7856.     mov    bx,dx            ; return it in bx
  7857.     pop    es
  7858.     pop    di
  7859.     pop    dx
  7860.     pop    cx
  7861.     pop    ax
  7862.     ret
  7863. getvssize endp
  7864.  
  7865. ; Examine vsattr line by line. Count number of attributes by excluding the
  7866. ; trailing repetitions (keep first example) on each line, sum them. Add to 
  7867. ; the sum a word per line to hold the count of such characters and one more 
  7868. ; word to hold the screen length. Stores temp length indicator in
  7869. ; words rdbuf+120 et seq (one word per line).
  7870. ; Return the number of bytes in register bx for malloc-ing.
  7871. getvasize proc    near
  7872.     push    ax
  7873.     push    cx
  7874.     push    dx
  7875.     push    di
  7876.     push    es
  7877.     les    di,vsat_ptr        ; pointer to vsattr
  7878.     xor    bx,bx            ; line counter
  7879.     mov    cl,crt_lins        ; lines on normal screen - 1
  7880.     inc    cl            ; include status line
  7881.     xor    ch,ch
  7882.     mov    dx,cx            ; accumulated count <cnt, line>
  7883.     inc    dx            ; count screen size word itself
  7884.     add    dx,dx            ; convert to bytes used
  7885.     add    di,vswidth - 1        ; offset of last attrib on the line
  7886. getvasi1:push    cx            ; save line counter
  7887.     mov    cx,vswidth -1        ; bytes on line - 1
  7888.     mov    ax,es:[di]        ; get last attribute byte on the line
  7889.     push    di
  7890.     dec    di
  7891.     std                ; scan backward
  7892.     repe    scasb            ; scan while equal (trim trailing rpt)
  7893.     cld
  7894.     pop    di
  7895.     je    getvasi2        ; e = ended on all same byte
  7896.     inc    cx            ; ne case gobbles extra byte
  7897. getvasi2:inc    cx            ; count the trailing byte
  7898.     mov    word ptr rdbuf[bx+120],cx; store number of bytes here
  7899.     add    dx,cx            ; accumulate count of bytes
  7900.     add    bx,2            ; next line
  7901.     add    di,vswidth        ; end of next line
  7902.     pop    cx            ; line counter
  7903.     loop    getvasi1
  7904.     mov    bx,dx            ; return bytes needed in bx
  7905.     pop    es
  7906.     pop    di
  7907.     pop    dx
  7908.     pop    cx
  7909.     pop    ax
  7910.     ret
  7911. getvasize endp
  7912. endif    ; no_tcp
  7913.  
  7914. ;
  7915. ; CHKDSP - procedure to check for hardware support of 132 cols
  7916. ;  Supported hardware:
  7917. ;  ATI EGA and VGA Wonder
  7918. ;  AT&T
  7919. ;  Everex Viewpoint EV-659, FVGA-673, EV-678, Micro Enhancer Deluxe
  7920. ;  IBM XGA
  7921. ;  Paradise AutoSwitch EGA Mono, VGA Professional, VGA Plus, VGA Plus 16
  7922. ;  STB VGA/EM (Tseng TVGA)
  7923. ;  STB VGA/EM Plus (Tseng 4000), VGA/EM-16, VGA/EM-16 Plus
  7924. ;  Tseng Labs EVA board w/132-col kit installed
  7925. ;  Tseng Labs UltraPAK mono/Herc board w/132 column modes.
  7926. ;  Tseng Labs ET4000 SVGA.
  7927. ;  VESA compatible Bios'.
  7928. ;  Video 7 Vega Deluxe w/ 132X25.COM driver installed and VGA board.
  7929. ; The routine checks for the presence of a 132-column-capable adapter. If
  7930. ; one is found its handler executes the desired mode setting and returns
  7931. ; carry clear; it returns carry set otherwise.
  7932. ; Adding new boards - place an identification string in the data segment,
  7933. ; construct a mode setting routine and insert it in the call list below
  7934. ; (setting 132 column mode is byte AL non-zero). Byte AH is non-zero to
  7935. ; avoid saving old screen and running scrini; it is used to set the screen
  7936. ; width when starting/exiting Connect mode
  7937. ;
  7938. chgdsp    proc    near
  7939. ifndef    no_graphics
  7940.     or    al,al            ; 80 column mode?
  7941.     jnz    chgdsg1            ; nz = no, want 132 cols
  7942.     test    tekflg,tek_active    ; graphics mode active?
  7943.     jz    chgdsp_start        ; z = no
  7944.     push    ax
  7945.     push    dx
  7946.     call    tekend            ; exit special graphics
  7947.     call    scrmod            ; update video mode info
  7948.     pop    dx
  7949.     pop    ax
  7950.     jmp    short chgdsp_start    ; set 80 col mode
  7951.  
  7952. chgdsg1:test    vtemu.vtflgop,vscompress ; allowed to use graphics for it?
  7953.     jnz    chgdsp_start        ; nz = no, use 132 column text mode
  7954.     cmp    tekflg,tek_active+tek_sg ; special graphics mode active?
  7955.     je    chgdsg3            ; e = yes, no change needed
  7956.     mov    cl,byte ptr low_rgt+1    ; examine whole screen
  7957.     add    cl,2            ; lines in emulation part + status
  7958.     xor    ch,ch
  7959.     xor    bx,bx
  7960. chgdsg2:or    dgwindcomp[bx],1    ; set compressed mode flag non-zero
  7961.     inc    bx
  7962.     loop    chgdsg2
  7963.     call    dgsettek        ; setup special graphics mode
  7964. chgdsg3:mov    byte ptr low_rgt,131    ; 132 columns in special graphics
  7965.     mov    crt_cols,128        ; but 128 physical columns
  7966.     ret
  7967. endif    ; no_graphics
  7968.  
  7969. chgdsp_start:
  7970.     push    es            ; save all we use
  7971.     push    ax
  7972.     push    bx
  7973.     push    cx
  7974.     push    dx
  7975.     push    si
  7976.     push    di
  7977.     mov    temp,ax            ; save set/reset flag from msz
  7978.     mov    ax,sp            ; do push sp test for XT vs AT/386
  7979.     push    sp            ; XT pushes sp-2, AT's push old sp
  7980.     pop    cx            ; recover pushed value, clean stack
  7981.     xor    ax,cx            ; same?
  7982.     jne    chgdspnw        ; ne = no, XT. Don't do Int 2fh
  7983.     test    tv_mode,10h        ; DESQview active?
  7984.     jz    chgdspndv        ; z = no
  7985.     jmp    chgdsx1            ; exit without screen change
  7986. chgdspndv:
  7987.     cmp    vchgmode,1        ; change permissions, disabled?
  7988.     je    chgdspnw        ; e = 1 = disabled
  7989.     mov    ax,1683h        ; Windows 3, get current virt machine
  7990.     int    2fh
  7991.     cmp    ax,1683h        ; virtual machine, if any
  7992.     je    chgdspok        ; e = none
  7993.     cmp    vchgmode,2        ; DOS-only (2)?
  7994.     jne    chgdspok        ; ne = no
  7995. chgdspnw:jmp    chgdsx1            ; exit without screen change
  7996. chgdspok:mov    ax,temp
  7997.     cmp    crt_cols,80        ; are we narrow?
  7998.     jbe    chgds3            ; be = narrow width now
  7999.     or    al,al            ; resetting to narrow width?
  8000.     jz    chgds4            ; z = yes, do it
  8001.     jmp    chgdsx1            ; else we are there now
  8002. chgds3:    or    al,al            ; resetting to narrow width?
  8003.     jnz    chgds4            ; nz = no, setting to wide
  8004.     jmp    chgdsx1            ; narrow width, we are there now
  8005. chgds4:    or    ah,ah            ; are we connected now?
  8006.     jnz    chgds0            ; nz = no, skip flow control etc
  8007.     mov    ah,flowoff        ; get xoff
  8008.     or    ah,ah            ; flow control?
  8009.     jz    chgds4a            ; z = none
  8010.     call    foutchr            ; send it
  8011. chgds4a:cmp    byte ptr temp+1,0    ; exiting Connect mode?
  8012.     jne    chgds0            ; ne = yes
  8013.     mov    ax,200            ; wait 200 millisec before video tests
  8014.     call    pcwait            ; so don't mix screen and port intrpts
  8015.  
  8016. chgds0:    call    ckteva            ; try Tseng Labs EVA
  8017.     jnc    chgds1            ; nc = found
  8018.     call    ckstbv            ; try STB VEGA/EM
  8019.     jnc    chgds1            ; nc = found
  8020.     call    ckv7vd            ; try Video 7 EGA Deluxe and VGA
  8021.     jnc    chgds1            ; nc = found
  8022.     call    ckatiw            ; try ATI EGA Wonder
  8023.     jnc    chgds1            ; nc = found
  8024.     call    ckevrx                  ; try Everex Micro Enhancer Deluxe
  8025.     jnc     chgds1                  ; nc = found
  8026.     call    ckevga            ; try Everex EVGA-673
  8027.     jnc     chgds1                  ; nc = found
  8028.     call    ckatt            ; ATT boards
  8029.     jnc    chgds1            ; nc = found
  8030.     call    chkpa            ; Paradise EGA/VGA boards
  8031.     jnc    chgds1            ; nc = found
  8032.     call    chkvesa            ; VESA compatibles
  8033.     jnc    chgds1            ; nc = found
  8034.     call    ckxga            ; IBM XGA
  8035.     jnc    chgds1            ; nc = found
  8036.     mov    si,offset cols80    ; name of 80 column file
  8037.     cmp    byte ptr temp,0        ; setting 80 cols?
  8038.     je    chgdsx2            ; e = yes
  8039.     mov    si,offset cols132    ; use 132 column file
  8040. chgdsx2:mov    di,offset decbuf    ; a temp buffer for path= usage
  8041.     call    strcpy
  8042.     mov    ax,di            ; spath wants ptr in ax
  8043.     call    fspath
  8044.     jc    chgdsx            ; c = file not found
  8045.     mov    si,ax            ; crun wants ptr in si
  8046.     call    fcrun            ; run the batch file, si = filespec
  8047.     call    fserini            ; reengage serial port, mode changes
  8048.     mov    ax,0c06h        ; clear kbd buffer and do function
  8049.     mov    dl,0ffh            ; console input
  8050.     int    dos            ; discard character(s)
  8051.                     ; Perform mode change
  8052. chgds1:    cmp    byte ptr temp+1,0    ; do without serial port xon/xoff?
  8053.     jne    chgdsx1            ; ne = yes
  8054.     cmp    flags.modflg,1        ; is mode line enabled?
  8055.     jbe    chgdsx            ; be = yes, and off or locally owned
  8056.     mov    flags.modflg,1        ; remove foreign ownership
  8057. chgdsx:    mov    ah,flowon        ; get flow-on byte
  8058.     or    ah,ah            ; using flow control?
  8059.     jz    chgdsx1            ; z = no
  8060.     call    foutchr            ; send it
  8061. chgdsx1:mov    al,crt_lins        ; previous conditions
  8062.     mov    ah,crt_cols
  8063.     push    ax
  8064.     call    scrmod            ; pick up current screen size
  8065.     pop    ax
  8066. ifndef    no_tcp
  8067.     cmp    al,crt_lins        ; screen size change?
  8068.     jne    chgdsx1a        ; ne = yes
  8069.     cmp    ah,crt_cols
  8070.     je    chgdsx1b        ; no
  8071. chgdsx1a:call    winupdate        ; window update req for TCP/IP Telnet
  8072. chgdsx1b:
  8073. endif    ; no_tcp
  8074.     pop    di            ; restore what we saved
  8075.     pop    si
  8076.     pop    dx
  8077.     pop    cx
  8078.     pop    bx
  8079.     pop    ax
  8080.     pop    es
  8081.     ret                ; return to caller
  8082.      
  8083. ; Individual tests for various 132-column boards
  8084.                     ; Tseng LABS EVA, UltraPAK, ET4000
  8085. ckteva: mov    ax,0c000h        ; seg addr for EVA
  8086.     mov    es,ax            ; set into es register
  8087.     mov    di,76h            ; offset of board's string
  8088.     lea    si,tsngid        ; validation string
  8089.     mov    cx,tsnglen        ; length of validiation string
  8090.     cld
  8091.     repe    cmpsb            ; compare strings
  8092.     je    ckteva2            ; e = strings match
  8093.     mov    ax,4d00h        ; check for UltraPAK mono driver
  8094.     int    screen
  8095.     cmp    ax,5aa5h        ; driver signature?
  8096.      jne    ckteva4            ; ne = no
  8097.     mov    ax,7            ; default to mono (7) for this board
  8098.     cmp    byte ptr temp,0        ; setting 132 columns?
  8099.     je    ckteva1            ; e = resetting to normal
  8100.     mov    ax,18h            ; set to 132 cols (Set Mode 18H)
  8101. ckteva1:int    screen
  8102.     clc                ; carry clear means success
  8103.     ret
  8104.                     ; an EVA board - check for 132 col kit
  8105. ckteva2:cmp    byte ptr es:099h,0    ; check 132 col kit installed
  8106.     jne    catfnd            ; ne = installed, do the mode change
  8107. ckteva3:stc                ; indicate adapter not present
  8108.     ret                ; and exit
  8109.  
  8110. ckteva4:mov    dx,03cdh        ; ET4000 test
  8111.     in    al,dx            ; Segment Select Register, get value
  8112.     push    ax
  8113.     xor    al,15h            ; create test condition
  8114.     jmp    $+2
  8115.     jmp    $+2
  8116.     out    dx,al            ; set condition
  8117.     jmp    $+2
  8118.     jmp    $+2
  8119.     mov    ah,al            ; save condition
  8120.     in    al,dx            ; get new condition
  8121.     jmp    $+2
  8122.     jmp    $+2
  8123.     cmp    ah,al            ; did it work (same)?
  8124.     pop    ax
  8125.     out    dx,al            ; restore original condition
  8126.     jne    ckteva3            ; ne = no, ET4000 not present
  8127.     mov    ax,3            ; default to cga 3
  8128.     cmp    byte ptr temp,0        ; setting 132 columns?
  8129.     je    ckteva5            ; e = resetting to normal
  8130.     mov    ax,23h            ; set to 132 cols (Set Mode 23H)
  8131. ckteva5:int    screen
  8132.     clc
  8133.     ret
  8134.                     ;
  8135. ckstbv:    mov    ax,0c000h        ; STB's VGA/EM, VGA/EM-16, EM-16 Plus
  8136.     mov    es,ax            ;
  8137.     mov    di,70h            ; where to look for signature
  8138.     lea    si,stbvid        ; the signature
  8139.     mov    cx,stbvlen        ;
  8140.     cld                ;
  8141.     repe    cmpsb            ; test
  8142.     je    catfnd            ; e = found
  8143.     mov    di,70h            ; where to look for signature
  8144.     lea    si,stavid        ; the signature
  8145.     mov    cx,stavlen
  8146.     cld
  8147.     repe    cmpsb            ; test
  8148.     je    catfnd            ; e = found
  8149.     stc                ; else say not there
  8150.     ret                ;
  8151.                     ; ATI EGA Wonder
  8152. ckatiw:    mov    ax,0c000h        ; seg addr for EGA Wonder
  8153.     mov    es,ax            ; set into es register
  8154.     mov    di,012fh        ; offset of message in ROM
  8155.     lea    si,atiwid        ; offset of message here
  8156.     mov    cx,atilen        ; length of validation string
  8157.     cld
  8158.     repe    cmpsb            ; compare strings
  8159.     je    catfnd            ; e = they match
  8160.     lea    si,atiwid2        ; alternative signature
  8161.     mov    di,30h            ; start at this offset
  8162.     mov    cx,atilen2        ; alternative signature length
  8163.     mov    ax,es:[di]        ; get first two bytes
  8164.     cmp    al,atiwid2        ; string starts here?
  8165.      je    ckatiw1            ; e = yes
  8166.     inc    di            ; try next location, just in case
  8167.     cmp    ah,atiwid2        ; or here?
  8168.     je    ckatiw1            ; e = yes
  8169.     stc                ; strings differ
  8170.     ret
  8171. ckatiw1:repe    cmpsb            ; check the whole string
  8172.     je    catfnd            ; e = matches the whole thing
  8173.     stc                ; fail on mismatch
  8174.     ret
  8175. catfnd:    mov    ax,0003h        ; prepare to reset video mode
  8176.     cmp    byte ptr temp,0        ; are we setting or resetting?
  8177.     je    catfnd1            ; e is reset, exit
  8178.     mov    ax,0023h        ; set to 132 cols (Set Mode 23H)
  8179. catfnd1:int    screen
  8180.     clc                ; carry clear means success
  8181.     ret
  8182.  
  8183. chkpa:    mov    ax,0c000h        ; load Paradise ROM BIOS address
  8184.     mov    es,ax
  8185.     mov    ax,0057h        ; assume 132x25 mono display needed
  8186.     mov    di,0009h        ; load EGA board identifier index
  8187.     lea    si,pmega1        ; Paradise Autoswitch Mono ident
  8188.     mov    cx,pmegal1
  8189.     cld
  8190.     repe    cmpsb            ; do identification strings match?
  8191.     je    chgpa2            ; e = yes, check num of display lines
  8192.     mov    di,007dh        ; no, load VGA board identifier index
  8193.     lea    si,p30id        ; Paradise VGA, other flavors
  8194.     mov    cx,p30ln
  8195.     repe    cmpsb            ; do identification strings match?
  8196.     je    chgpa1            ; e = yes, check for color mode
  8197.     stc                ; fail
  8198.     ret
  8199. chgpa1:    cmp    crt_norm,3        ; is the "normal" screen in color?
  8200.     ja    chgpa2            ; a = no, orig assumption is correct
  8201.     mov    ax,0055h        ; assume 132x25 color required
  8202. chgpa2:    cmp    crt_lins,25        ; is the "normal" screen 25 lines?
  8203.     jna    chgpa3            ; na = yes, check num of cols needed
  8204.     dec    ax            ; change assumption to 132x43
  8205. chgpa3:    cmp    byte ptr temp,0        ; switching to a 132 column mode?
  8206.     jne    chgpa4            ; ne = yes
  8207.     mov    al,crt_norm        ; load "normal" display mode
  8208. chgpa4:    int    screen            ; issue BIOS call to change display
  8209.     clc                ; success
  8210.     ret
  8211.                     ; Video 7 Vega Deluxe
  8212. ckv7vd:    mov    ax,0c000h        ; seg addr for Vega rom bios
  8213.     mov    es,ax            ; set into es register
  8214.     mov    di,002ah        ; offset of message in ROM
  8215.     lea    si,vid7id        ; offset of message here
  8216.     mov    cx,vid7len
  8217.     cld
  8218.     repe    cmpsb            ; compare strings
  8219.     je    cnv7fn1            ; e = same
  8220.     mov    di,002ah        ; offset of ident string
  8221.     mov    si,offset vid7id2    ; Video 7 VGA board
  8222.     mov    cx,vid7len2
  8223.     repe    cmpsb
  8224.     je    cnv7fn2            ; e = found
  8225. cnv7fx:    stc                ; strings are different
  8226.     ret
  8227.                     ;
  8228. cnv7fn1:test    byte ptr es:[03ffeh],1    ; is this a 'Deluxe' Vega?
  8229.     jz    cnv7fx            ; z = nope, can't do it
  8230.     mov    ah,35h            ; DOS Get Vector
  8231.     mov    al,10h            ; Bios video interrupt
  8232.     int    dos            ; get it into es:bx
  8233.     mov    di,bx            ; es:bx is returned int 10h entry pnt
  8234.     sub    di,5ah            ; back offset to msg in 132X25.COM
  8235.     lea    si,vid7id        ; offset of validation message
  8236.     mov    cx,vid7len        ; length of validation string
  8237.     cld
  8238.     repe    cmpsb            ; Look for repeat of msg by 132X25.COM
  8239.     jne    cnv7fn2            ; if different
  8240.     mov    al,crt_mode        ; prepare to reset video mode
  8241.     xor    ah,ah
  8242.     cmp    byte ptr temp,0        ; are we setting or resetting?
  8243.     je    cnv7fn2a        ; e is reset
  8244.     mov    ax,0000h        ; set to 132 cols (old 40x25)
  8245. cnv7fn1a:int    screen
  8246.     clc
  8247.     ret
  8248.  
  8249. cnv7fn2:mov    ax,6f00h        ; check for VegaBios driver
  8250.     int    screen
  8251.     cmp    bx,'V7'            ; Video 7 Bios presence response
  8252.     jne    cnv7fx            ; ne = not there
  8253.     mov    ax,6f01h        ; al gets monitor type (mono,color,ega)
  8254.     int    screen
  8255.     mov    bx,51h            ; presume mono 132x25, page 0
  8256.     cmp    crt_lins,42        ; 43 lines active?
  8257.     jb    cnv7fn2a        ; b = no
  8258.     inc    bx            ; use bx = 52h for 132x43
  8259. cnv7fn2a:
  8260.     cmp    al,10h            ; analogue fixed freq (IBM 85xx)?
  8261.     je    cnv7fx            ; e = yes, no 132 columns
  8262.     cmp    al,2            ; 1 = mono, 2 = color, above = ega
  8263.     jb    cnv7fn3            ; b = mono or unknown
  8264.     mov    bx,4fh            ; presume med res color 132x25
  8265.     je    cnv7fn3            ; e = med res color, al = 2
  8266.     mov    bx,41h            ; ega high res 132x25, enhanced mons
  8267.     cmp    crt_lins,42        ; 43 lines active?
  8268.     jb    cnv7fn3            ; b = no
  8269.     inc    bx            ; use bx = 42h for 132x43
  8270. cnv7fn3:mov    ax,6f05h        ; set special mode found in bl
  8271.     cmp    byte ptr temp,0        ; resetting to 80 column mode?
  8272.     jne    cnv7fn4            ; ne = no, setting 132x25
  8273.     mov    al,crt_norm        ; get normal mode
  8274.     xor    ah,ah            ; set mode
  8275.     cmp    crt_lins,42        ; 43 lines active?
  8276.     jb    cnv7fn4            ; b = no
  8277.     mov    bl,40h            ; use Video 7 mode 40h 80x43 for color
  8278.     mov    ax,6f05h        ; and do special mode set
  8279. cnv7fn4:int    screen            ; special mode is in bl
  8280.     mov    ax,0f00h        ; a nop screen bios command
  8281.     int    screen
  8282.     clc
  8283.     ret
  8284.  
  8285. ckevrx: mov     ax,0c000h               ; seg addr for Everex EV-659
  8286.         mov     es,ax                   ; set into es register
  8287.         mov     di,0047h                ; offset of message in ROM
  8288.         lea     si,evrxid               ; offset of message here
  8289.         mov     cx,evrxlen              ; length of validation string
  8290.         cld
  8291.         repe    cmpsb                   ; compare strings
  8292.         jne     ckfnr2                  ; ne = strings differ
  8293.         mov     ah,crt_lins             ; we recognize either 44 or 25 rows
  8294.         cmp     ah,43                   ; equal to 44-1 rows?
  8295.         jne     ckfnr1                  ; ne = no
  8296.         mov     ax,0070h                ; Everex extended mode ident
  8297.         mov     bl,09h                  ; prepare to reset video mode to 80x44
  8298.         cmp     byte ptr temp,0         ; are we setting or resetting?
  8299.         je      ckfnr4                  ; e is reset, exit
  8300.         mov     bl,0bh                  ; 132x44
  8301.     int    screen
  8302.     clc
  8303.     ret
  8304. ckfnr1: cmp     ah,24                   ; equal to 25-1 rows?
  8305.     je    ckfnr3            ; e = yes
  8306. ckfnr2:    stc                ; return failure
  8307.     ret
  8308. ckfnr3:    mov     ax,0003h                ; prepare to reset video mode
  8309.         cmp     byte ptr temp,0         ; are we setting or resetting?
  8310.         je      ckfnr4                  ; e is reset, exit
  8311.         mov     ax,0070h                ; Everex extended mode ident
  8312.         mov     bl,0ah                  ; 132x25
  8313. ckfnr4:    int    screen
  8314.     clc
  8315.     ret
  8316. ckevga:    mov    ax,0c000h        ; Everex FVGA-673, EV-678 rom segment
  8317.     mov    es,ax
  8318.     mov    di,76h            ; offset in rom for board's id string
  8319.     lea    si,evgid        ; id string
  8320.     mov    cx,evglen        ; length of id string
  8321.     cld
  8322.     repe    cmpsb            ; do they match?
  8323.     je    ckevg0            ; e = yes
  8324.     mov    di,9dh            ; offset in ROM for board's ID string
  8325.     lea    si,evvid        ; ID string
  8326.     mov    cx,evvlen        ; length of ID string
  8327.     cld
  8328.     repe    cmpsb            ; do they match?
  8329.     jne    ckevg2            ; ne = no
  8330. ckevg0:    mov    ax,3            ; prepare to reset video mode
  8331.     cmp    byte ptr temp,0        ; setting or resetting mode?
  8332.     je    ckevg1            ; e = resetting, exit
  8333.     mov    ax,0070h        ; mode for 132x25
  8334.     mov    bl,0ah            ; Everex mode 0ah
  8335. ckevg1:    int    screen
  8336.     clc
  8337.     ret
  8338. ckevg2:    stc                ; say board not found
  8339.     ret
  8340.                     ; AT&T EGA/VGA boards
  8341. ckatt:    mov    ax,0c000h        ; seg of first signature
  8342.     mov    es,ax
  8343.     mov    si,offset attvdc6    ; first pattern
  8344.     mov    di,35h            ; test area
  8345.     cld
  8346.     mov    cx,attvdlen        ; length
  8347.     repe    cmpsb
  8348.     je    ckatt2            ; e = found
  8349.     mov    cx,attvdlen        ; try second signature, same length
  8350.     mov    si,offset attvdc7
  8351.     mov    ax,0e000h        ; seg of second signature
  8352.     mov    es,ax
  8353.     mov    di,10h            ; test area
  8354.     repe    cmpsb
  8355.     je    ckatt2            ; e = found
  8356.     stc                ; not found
  8357.     ret
  8358. ckatt2:    mov    al,crt_norm        ; old mode
  8359.     xor    ah,ah
  8360.     cmp    byte ptr temp,0        ; resetting to 80 col?
  8361.     je    ckatt3            ; e = yes
  8362.     mov    ax,0055h        ; 132 cols, set mode 55h
  8363. ckatt3:    int    screen
  8364.     clc
  8365.     ret
  8366.                     ; VESA compatibles
  8367. chkvesa:mov    di,seg rdbuf        ; es:di is buffer for results
  8368.     mov    es,di
  8369.     mov    di,offset rdbuf
  8370.     mov    ax,4f00h        ; get SVGA information
  8371.     int    screen
  8372.     cmp    ax,4fh            ; success?
  8373.     jne    chkvesax        ; ne = no
  8374.     cmp    word ptr rdbuf,'EV'    ; 'VESA'
  8375.     jne    chkvesax        ; ne = no
  8376.     cmp    word ptr rdbuf+2,'AS'
  8377.     jne    chkvesax        ; ne = no
  8378.     mov    ax,4f01h        ; get mode info to es:di buffer
  8379.     mov    cx,109h            ; 109h is 132x25 text
  8380.     int    screen
  8381.     cmp    ax,4fh            ; success?
  8382.     jne    chkvesax        ; ne = no
  8383.     mov    bx,3            ; assume 80 columns
  8384.     cmp    byte ptr temp,0        ; setting or resetting mode?
  8385.     je    chkvesa2        ; e = resetting
  8386.     mov    bx,109h            ; mode for 132x25
  8387. chkvesa2:mov    ax,4f02h        ; set mode from bx
  8388.     int    screen
  8389.     cmp    ax,4fh            ; success?
  8390.     jne    chkvesax        ; ne = no
  8391.     clc                ; say success
  8392.     ret
  8393. chkvesax:stc                ; say failure
  8394.     ret
  8395.  
  8396.                     ; IBM XGA 132 columns
  8397. ckxga:    push    bp            ; (old BIOSes are still around)
  8398.     push    ds            ; set es to data segment
  8399.     pop    es
  8400.     mov    ax,1b00h        ; get functionality table
  8401.     xor    bx,bx
  8402.     mov    di,offset decbuf    ; es:di is 64 bytes of workspace
  8403.     int    screen
  8404.     cmp    al,1bh            ; is this call supported?
  8405.     jne    ckxgax            ; ne = no, fail
  8406.     les    bx,dword ptr decbuf    ; get the address of the modes info
  8407.     test    byte ptr es:[bx+2],10h    ; is mode 14h supported?
  8408.     jz    ckxman            ; z = no, try manual method for now
  8409.     mov    ax,3            ; assume resetting to mode 3, 80x25
  8410.     cmp    byte ptr temp,0        ; setting 132 columns?
  8411.     je    ckxga1            ; e = no, resetting to 80 columns
  8412.     mov    ax,14h            ; invoke IBM XGA mode 14h, 132x25
  8413. ckxga1:    int    screen
  8414. ckxga2:    pop    bp
  8415.     clc                ; say success
  8416.     ret
  8417. ckxgax:    pop    bp
  8418.     mov    xga_reg_base,-2        ; flag saying no XGA Adapter found
  8419.     stc                ; say failure
  8420.     ret
  8421.  
  8422. ckxman:    call    xgaman            ; do tests/sets manually
  8423.     pop    bp
  8424.     jnc    ckxman1            ; nc = success
  8425.     mov    xga_reg_base,-2        ; flag saying no XGA Adapter found
  8426. ckxman1:ret
  8427. chgdsp    endp
  8428.  
  8429. ; XGA mode setting via going to the hardware manually
  8430. ; Code furnished by Bert Tyler, National Institue of Health
  8431.  
  8432. xgaman    proc    near
  8433.     cmp    xga_reg_base,-2        ; has the XGA detector already failed?
  8434.     je    xgafail            ; e = yes, fail again
  8435.     cmp    xga_reg_base,-1        ; have we already found the XGA?
  8436.     je    xga_loc            ; e = no
  8437.     jmp    xga_do1            ; yes, process it
  8438. xga_loc:push    es
  8439.     mov    ah,35h            ; DOS get interrupt vector
  8440.     mov    al,15h            ; Int 15h
  8441.         int     dos                     ; returns vector in es:bx
  8442.     mov    ax,es            ; segment part
  8443.     pop    es
  8444.     or    ax,ax            ; undefined vector?
  8445.     jz    xgafail            ; z = yes
  8446.     mov    dx,-1            ; start with an invalid POS address
  8447.     mov    ax,0c400h        ; look for POS base address
  8448.     int    15h            ;  (Microchannel machines only)
  8449.     jc    xgafail            ; c = error, not a MC machine
  8450.     mov    xgatmp1,dx        ; save pos_base_address
  8451.     xor    cx,cx            ; check all MCA slots & motherboard
  8452.     cmp    dx,-1            ; do we have a good POS?
  8453.     jne    xga_lp1            ; ne = yes, proceed with MCA checks
  8454. xgafail:stc                ; fail
  8455.     ret
  8456.  
  8457. xga_lp1:cli                ; no interrupts, please
  8458.     cmp    cx,0            ; treat the motherboard differently?
  8459.     jne    xga_sk4            ; ne = yes
  8460.     mov    al,0dfh            ; enable the motherboard for setup
  8461.     mov    dx,94h
  8462.     out    dx,al
  8463.     jmp    short xga_sk5
  8464. xga_sk4:mov    ax,0c401h        ; enable an MCA slot for setup
  8465.     mov    bx,cx            ;  this slot
  8466.     int    15h
  8467. xga_sk5:mov    dx,xgatmp1        ; get pos record for the slot
  8468.     in    ax,dx            ;  ID
  8469.     mov    xgatmp2,ax
  8470.     add    dx,2            ; compute IO Res Base
  8471.     in    al,dx            ;  get POS data byte1
  8472.     and    ax,0eh            ;  muck about with it to get reg base
  8473.     shl    ax,1
  8474.     shl    ax,1
  8475.     shl    ax,1
  8476.     add    ax,2100h
  8477.     mov    xga_reg_base,ax
  8478.     cmp    cx,0            ; treat the motherboard differently?
  8479.     jne    xga_sk6            ; ne = yes
  8480.     mov    al,0ffh            ; enable the motherboard for normal
  8481.     out    094h,al
  8482.     jmp    short xga_sk7
  8483. xga_sk6:mov    ax,0c402h        ; enable the MCA slot for normal
  8484.     mov    bx,cx            ;  this slot
  8485.     int    15h
  8486. xga_sk7:sti                ; interrupts on again
  8487.  
  8488.     mov    ax,xgatmp2        ; is an XGA adapter on this slot?
  8489.     cmp    ax,08fd8h
  8490.     jae    xga_sk8            ; ae = yes
  8491.     jmp    xga_lp2            ; try another slot
  8492. xga_sk8:cmp    ax,08fdbh        ; still within range?
  8493.     jbe    xga_sk9            ; be = yes
  8494.     jmp    xga_lp2            ; no, try another slot
  8495. xga_sk9:mov    dx,xga_reg_base        ; is there a monitor on this slot?
  8496.     add    dx,0ah
  8497.     mov    al,052h
  8498.     out    dx,al
  8499.     mov    dx,xga_reg_base
  8500.     add    dx,0bh
  8501.     in    al,dx
  8502.     and    al,0fh
  8503.     cmp    al,0fh
  8504.     jne    xga_ska            ; ne = yes
  8505.     jmp    xga_lp2            ; no
  8506. xga_ska:mov    dx,xga_reg_base        ; is this XGA in VGA mode?
  8507.     in    al,dx
  8508.     test    al,1
  8509.     jnz    xga_do1            ; nz = yes, found it!
  8510.  
  8511. xga_lp2:inc    cx            ; try another adapter?
  8512.     cmp    cx,9            ; done all slots?
  8513.     ja    xga_no            ; a = yes
  8514.     jmp    xga_lp1            ; no, try another slot
  8515. xga_no:    jmp    xgafail            ; fail
  8516.  
  8517. ;    *finally* put the XGA into 132-column or 80-column mode
  8518.  
  8519. xga_do1:cmp    byte ptr temp,0        ; setting 80-column mode?
  8520.     jne    xga_do2            ; ne = no, 132 columns
  8521.     jmp    xga_do3            ; do 80 column mode
  8522.  
  8523.                     ; 132-column mode routine
  8524. xga_do2:mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8525.     add    dx,0ah
  8526.     mov    ax,1550h
  8527.     out    dx,ax
  8528.     mov    ax,1450h
  8529.     out    dx,ax
  8530.     mov    ax,0454h
  8531.     out    dx,ax
  8532.     mov    ax,1202h        ; select 400 scan lines
  8533.     mov    bl,30h
  8534.     int    screen
  8535.     mov    ax,0+3            ; set video mode 3
  8536.     int    screen
  8537.  
  8538.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8539.     add    dx,0ah
  8540.     mov    al,50h
  8541.     out    dx,al
  8542.     inc    dx
  8543.     in    al,dx
  8544.     or    al,1
  8545.     out    dx,al
  8546.  
  8547.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8548.     add    dx,0ah
  8549.     mov    al,50h
  8550.     out    dx,al
  8551.     inc    dx
  8552.     in    al,dx
  8553.     and    al,0fdh
  8554.     out    dx,al
  8555.  
  8556.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8557.     add    dx,0ah
  8558.     mov    al,50h
  8559.     out    dx,al
  8560.     inc    dx
  8561.     in    al,dx
  8562.     and    al,0fch
  8563.     out    dx,al
  8564.  
  8565.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8566.     mov    al,3
  8567.     out    dx,al
  8568.  
  8569.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8570.     add    dx,0ah
  8571.     mov    ax,0154h
  8572.     out    dx,ax
  8573.     mov    ax,8070h
  8574.     out    dx,ax
  8575.  
  8576.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8577.     add    dx,0ah
  8578.     mov    al,50h
  8579.     out    dx,al
  8580.     inc    dx
  8581.     in    al,dx
  8582.     and    al,0efh
  8583.     out    dx,al
  8584.  
  8585.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8586.     mov    ax,11h
  8587.     out    dx,al
  8588.     inc    dx
  8589.     in    al,dx
  8590.     and    al,7fh
  8591.     out    dx,al
  8592.  
  8593.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8594.     mov    ax,0
  8595.     out    dx,al
  8596.     inc    dx
  8597.     mov    ax,0a4h
  8598.     out    dx,al
  8599.  
  8600.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8601.     mov    ax,1
  8602.     out    dx,al
  8603.     inc    dx
  8604.     mov    ax,83h
  8605.     out    dx,al
  8606.  
  8607.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8608.     mov    ax,2
  8609.     out    dx,al
  8610.     inc    dx
  8611.     mov    ax,84h
  8612.     out    dx,al
  8613.  
  8614.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8615.     mov    ax,3
  8616.     out    dx,al
  8617.     inc    dx
  8618.     mov    ax,83h
  8619.     out    dx,al
  8620.  
  8621.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8622.     mov    ax,4
  8623.     out    dx,al
  8624.     inc    dx
  8625.     mov    ax,90h
  8626.     out    dx,al
  8627.  
  8628.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8629.     mov    ax,5
  8630.     out    dx,al
  8631.     inc    dx
  8632.     mov    ax,80h
  8633.     out    dx,al
  8634.  
  8635.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8636.     add    dx,0ah
  8637.     mov    ax,0a31ah
  8638.     out    dx,ax
  8639.     mov    ax,001bh
  8640.     out    dx,ax
  8641.  
  8642.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8643.     mov    ax,13h
  8644.     out    dx,al
  8645.     inc    dx
  8646.     mov    ax,42h
  8647.     out    dx,al
  8648.  
  8649.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8650.     mov    al,11h
  8651.     out    dx,al
  8652.     inc    dx
  8653.     in    al,dx
  8654.     or    al,80h
  8655.     out    dx,al
  8656.  
  8657.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8658.     add    dx,0ah
  8659.     mov    al,50h
  8660.     out    dx,al
  8661.     inc    dx
  8662.     in    al,dx
  8663.     or    al,3
  8664.     out    dx,al
  8665.  
  8666.     mov    dx,03c4h        ; (the manual doesn't explain...)
  8667.     mov    ax,1
  8668.     out    dx,al
  8669.     inc    dx
  8670.     in    al,dx
  8671.     or    al,1
  8672.     out    dx,al
  8673.  
  8674.     mov    dx,03dah        ; (the manual doesn't explain...)
  8675.     in    al,dx
  8676.  
  8677.     mov    dx,003c0h        ; (the manual doesn't explain...)
  8678.     mov    al,13h
  8679.     out    dx,al
  8680.     xor    al,al
  8681.     out    dx,al
  8682.     mov    al,20h
  8683.     out    dx,al
  8684.  
  8685.     mov    ax,40h            ; tell the BIOS we have 132 columns
  8686.     mov    es,ax
  8687.     mov    byte ptr es:[4ah],132    ; set Bios screen width data area
  8688.     clc                ; return success
  8689.     ret
  8690.                         ; Set 80 column mode
  8691. xga_do3:mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8692.     add    dx,01h
  8693.     xor    al,al
  8694.     out    dx,al
  8695.  
  8696.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8697.     add    dx,4
  8698.     xor    al,al
  8699.     out    dx,al
  8700.  
  8701.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8702.     add    dx,5
  8703.     mov    al,0ffh
  8704.     out    dx,al
  8705.  
  8706.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8707.     add    dx,0ah
  8708.     mov    ax,0ff64h
  8709.     out    dx,ax
  8710.  
  8711.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8712.     add    dx,0ah
  8713.     mov    ax,1550h
  8714.     out    dx,ax
  8715.  
  8716.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8717.     add    dx,0ah
  8718.     mov    ax,1450h
  8719.     out    dx,ax
  8720.  
  8721.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8722.     add    dx,0ah
  8723.     mov    ax,0051h
  8724.     out    dx,ax
  8725.  
  8726.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8727.     add    dx,0ah
  8728.     mov    ax,0454h
  8729.     out    dx,ax
  8730.  
  8731.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8732.     add    dx,0ah
  8733.     mov    ax,7f70h
  8734.     out    dx,ax
  8735.  
  8736.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8737.     add    dx,0ah
  8738.     mov    ax,202ah
  8739.     out    dx,ax
  8740.  
  8741.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8742. ;;    add    dx,00h
  8743.     mov    al,1
  8744.     out    dx,al
  8745.  
  8746.     mov    dx,03c3h        ; (the manual doesn't explain...)
  8747.     mov    al,1
  8748.     out    dx,al
  8749.  
  8750.     mov    ax,1202h        ; select 400 scan lines
  8751.     mov    bl,30h
  8752.     int    screen
  8753.     mov    ax,0+3            ; set video mode 3
  8754.     int    screen
  8755.     clc                ; return success
  8756.     ret
  8757. xgaman    endp
  8758.  
  8759. ; Routine to do keyclick if flag is set, no arguments
  8760. vclick    proc    near
  8761.     test    vtemu.vtflgop,vskeyclick ; is keyclick flag on?
  8762.     jz    vclick1            ; z = no, just return
  8763.     push    bx
  8764.     push    di
  8765.     mov    di,500            ; 500 Hertz
  8766.     mov    bx,1            ; For 1 millisecond
  8767.     call    vtsound            ; Do it
  8768.     pop    di            ; Restore the ACs
  8769.     pop    bx
  8770. vclick1:ret
  8771. vclick    endp
  8772. endif    ; no_terminal
  8773.  
  8774. ; Routine to do VT100-style bell, no arguments
  8775. fvtbell    proc    far
  8776.     call    vtbell
  8777.     ret
  8778. fvtbell    endp
  8779.  
  8780. vtbell    proc    near
  8781.     cmp    belltype,1        ; visual bell?
  8782.     je    vtbell1            ; e = yes
  8783.     ja    vtbell2            ; a = no bell
  8784.     push    di            ; audible bell
  8785.     push    bx
  8786.     mov    di,880            ; 880 Hertz
  8787.     mov    bx,40            ; For 40 ms
  8788.     call    vtsound            ; Do it
  8789.     pop    bx
  8790.     pop    di
  8791.     ret
  8792. vtbell1:
  8793. ifndef    no_terminal
  8794.     call    revscn            ; reverse screen
  8795.     push    ax
  8796.     mov    ax,40            ; for 40 milliseconds
  8797.     call    pcwait
  8798.     pop    ax
  8799.     call    revscn            ; put back
  8800. endif    ; no_terminal
  8801. vtbell2:ret
  8802. vtbell    endp
  8803.  
  8804. ; Routine to make noise of arbitrary frequency for arbitrary duration.
  8805. ; Similar to routine (with typo removed) in "IBM PC Assembly Language:
  8806. ; A Guide for Programmers", Leo J. Scanlon, 1983 Robert J. Brady Co.,
  8807. ; Bowie, MD., page 270. Modified by J R Doupnik to use 0.1 millsec interval.
  8808. ; Call:        di/    frequency in Hertz.
  8809. ;        bx/    duration in 1 millisecond units
  8810. vtsound proc    near
  8811.     push    ax            ; save regs
  8812.     push    cx
  8813.     push    dx
  8814.     mov    al,0B6H            ; write timer mode register
  8815.     out    43H,al
  8816.     mov    dx,14H            ; timer divisor is
  8817.     mov    ax,4F38H        ; 1331000/frequency
  8818.     div    di
  8819.     out    42H,al            ; write timer 2 count low byte
  8820.     mov    al,ah
  8821.     out    42H,al            ; write timer 2 count high byte
  8822.     in    al,61H            ; get current port B setting
  8823.     or    al,3            ; turn speaker on
  8824.     out    61H,al
  8825.     mov    ax,bx            ; number of milliseconds to wait
  8826.     call    pcwait            ; do the calibrated wait
  8827.     in    al,61H            ; get current port B setting
  8828.     and    al,0fch            ; turn off speaker and timer
  8829.     out    61H,al
  8830.     pop    dx            ; restore regs
  8831.     pop    cx
  8832.     pop    ax
  8833.     ret
  8834. vtsound endp
  8835. code1    ends
  8836.     end
  8837.