home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msyibm.asm < prev    next >
Assembly Source File  |  2020-01-01  |  262KB  |  8,840 lines

  1.     NAME msyibm
  2. ; File MSYIBM.ASM
  3.     include mssdef.h
  4. ;    Copyright (C) 1982, 1997, 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. INT 3
  3727. NOP
  3728. NOP
  3729.     xor    flags.debug,logses    ; toggle debugging
  3730.     xor    yflags,trnctl        ; Debug mode local edition
  3731.     ret
  3732. kdebug    endp
  3733.  
  3734. snull    proc    near            ; send a null byte
  3735.     xor    al,al            ; the null
  3736.     call    fprtbout        ; send without logging and local echo
  3737.     ret
  3738. snull    endp
  3739.  
  3740. khold:    xor    holdscr,1        ; toggle Hold screen byte for msx
  3741.     call    kbhold            ; tell DEC LK250 the hold kbd state
  3742.     clc                ;  kbhold is in file msuibm.asm
  3743.     ret
  3744.  
  3745. tn_AYT:    mov    ah,255            ; 'I' Telnet Are You There
  3746.     call    outchr            ; send IAC (255) AYT (246)
  3747.     mov    ah,246
  3748.     call    outchr
  3749.     clc
  3750.     ret
  3751.  
  3752. tn_IP:    mov    ah,255            ; 'I' Telnet Interrrupt Process
  3753.     call    outchr            ; send IAC (255) IP (244)
  3754.     mov    ah,244
  3755.     call    outchr
  3756.     clc
  3757.     ret
  3758.  
  3759. ; Data General "Fn" function keys
  3760. dgkf1:    mov    al,113            ; F1 sends RS q
  3761.     jmp    dgkeyccom
  3762. dgkf2:    mov    al,114            ; F2 sends RS r
  3763.     jmp    dgkeyccom
  3764. dgkf3:    mov    al,115            ; F3 sends RS s
  3765.     jmp    dgkeyccom
  3766. dgkf4:    mov    al,116            ; F4 sends RS t
  3767.     jmp    short dgkeyccom
  3768. dgkf5:    mov    al,117            ; F5 sends RS u
  3769.     jmp    short dgkeyccom
  3770. dgkf6:    mov    al,118            ; F6 sends RS v
  3771.     jmp    short dgkeyccom
  3772. dgkf7:    mov    al,119            ; F7 sends RS w
  3773.     jmp    short dgkeyccom
  3774. dgkf8:    mov    al,120            ; F8 sends RS x
  3775.     jmp    short dgkeyccom
  3776. dgkf9:    mov    al,121            ; F9 sends RS y
  3777.     jmp    short dgkeyccom
  3778. dgkf10:    mov    al,122            ; F10 sends RS z
  3779.     jmp    short dgkeyccom
  3780. dgkf11:    mov    al,123            ; F11 sends RS {
  3781.     jmp    short dgkeyccom
  3782. dgkf12:    mov    al,124            ; F12 sends RS |
  3783.     jmp    short dgkeyccom
  3784. dgkf13:    mov    al,125            ; F13 sends RS }
  3785.     jmp    short dgkeyccom
  3786. dgkf14:    mov    al,126            ; F14 sends RS ~
  3787.     jmp    short dgkeyccom
  3788. dgkf15:    mov    al,112            ; F15 sends RS p
  3789.     jmp    short dgkeyccom
  3790. dgkSf1:    mov    al,'a'            ; SF1 sends RS a
  3791.     jmp    short dgkeyccom
  3792. dgkSf2:    mov    al,'b'            ; SF2 sends RS b
  3793.     jmp    short dgkeyccom
  3794. dgkSf3:    mov    al,'c'            ; SF3 sends RS c
  3795.     jmp    short dgkeyccom
  3796. dgkSf4:    mov    al,'d'            ; SF4 sends RS d
  3797.     jmp    short dgkeyccom
  3798. dgkSf5:    mov    al,'e'            ; SF5 sends RS e
  3799.     jmp    short dgkeyccom
  3800. dgkSf6:    mov    al,'f'            ; SF6 sends RS f
  3801.     jmp    short dgkeyccom
  3802. dgkSf7:    mov    al,'g'            ; SF7 sends RS g
  3803.     jmp    short dgkeyccom
  3804. dgkSf8:    mov    al,'h'            ; SF8 sends RS h
  3805.     jmp    short dgkeyccom
  3806. dgkSf9:    mov    al,'i'            ; SF9 sends RS i
  3807.     jmp    short dgkeyccom
  3808. dgkSf10:mov    al,'j'            ; SF10 sends RS j
  3809.     jmp    short dgkeyccom
  3810. dgkSf11:mov    al,'k'            ; SF11 sends RS k
  3811.     jmp    short dgkeyccom
  3812. dgkSf12:mov    al,'l'            ; SF12 sends RS l
  3813.     jmp    short dgkeyccom
  3814. dgkSf13:mov    al,'m'            ; SF13 sends RS m
  3815.     jmp    short dgkeyccom
  3816. dgkSf14:mov    al,'n'            ; SF14 sends RS n
  3817.     jmp    short dgkeyccom
  3818. dgkSf15:mov    al,'`'            ; SF15 sends RS `
  3819.     jmp    short dgkeyccom
  3820.  
  3821.  
  3822. ; Data General "C" keys C1..C4
  3823. dgkc1:    mov    al,92            ; C1 sends RS \
  3824.     jmp    short dgkc5
  3825. dgkc2:    mov    al,93            ; C2 sends RS ]
  3826.     jmp    short dgkc5
  3827. dgkc3:    mov    al,95            ; C3 sends RS ^
  3828.     jmp    short dgkc5
  3829. dgkc4:    mov    al,96            ; C4 sends RS _
  3830. dgkc5:    cmp    dgd470mode,0        ; D470 ANSI mode active?
  3831.     je    dgkeyccom        ; e = no
  3832.     add    al,40            ; yes, bias, C1=132 et seq
  3833. dgkeyccom:                ; common code
  3834.     mov    ttyact,0        ; network, group chars for packet
  3835.     push    ax
  3836.     cmp    dgd470mode,0        ; D470 ANSI mode active?
  3837.     je    dgkeyccom1        ; e = no
  3838.     mov    al,ESCAPE        ; send ESC [ 0<high><low> z
  3839.     call    fprtbout
  3840.     mov    al,'['
  3841.     call    fprtbout
  3842.     mov    al,'0'            ; first byte, always "0"
  3843.     call    fprtbout
  3844.     pop    ax
  3845.     sub    al,112            ; remove bias (to 0..23)
  3846.     mov    cl,10            ; split into two bytes
  3847.     xor    ah,ah
  3848.     div    cl            ; al = quotient, ah = remainder
  3849.     push    ax            ; save remainder
  3850.     add    al,'0'            ; send high part (0..2)
  3851.     call    fprtbout
  3852.     pop    ax
  3853.     xchg    ah,al
  3854.     add    al,'0'            ; send low part (0..9)
  3855.     call    fprtbout
  3856.     mov    al,'z'            ; terminator
  3857.     mov    ttyact,1        ; network, restore tty active flag
  3858.     ret
  3859.  
  3860. dgkeyccom1:mov    al,DGescape        ; send DG escape (RS)
  3861.     call    fprtbout        ; with no echo
  3862.     pop    ax
  3863.     mov    ttyact,1        ; network, restore tty active flag
  3864.     call    fprtbout        ; send the second byte
  3865.     ret
  3866.  
  3867. ; Keyboard "Compose" key to compose characters by the three stroke method
  3868. kbdcompose proc    near
  3869.     mov    grab,1            ; say grabbing normal output
  3870.     call    togmod
  3871.     call    togmod            ; update mode line
  3872.     ret
  3873. kbdcompose endp
  3874.  
  3875. ; DG POINT (aka CMD CURSOR-TYPE)
  3876. dgpoint    proc    near
  3877. ifndef    no_graphics
  3878.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  3879.     jne    dgpoint1        ; ne = no, ignore cmd
  3880.     call    dgcrossrpt        ; send crosshair report
  3881. endif    ; no_graphics
  3882. dgpoint1:ret
  3883. dgpoint    endp
  3884.  
  3885. ; DG N/C (normal, compressed font) key
  3886. dgnckey proc    near
  3887.     test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  3888.     jz    dgnckey1        ; z = no, ignore
  3889.     call    dgnctoggle        ; toggle normal/compressed mode
  3890. dgnckey1:clc
  3891.     ret
  3892. dgnckey endp
  3893.  
  3894. ; Compose char lookup and reemitter.
  3895. fgrabber proc    far
  3896.     push    bx
  3897.     mov    bx,grab            ; count chars grabbed (want two)
  3898.     dec    bx            ; first char becomes bx=0
  3899.     mov    grabbox[bx],al        ; stuff char in short buffer
  3900.     cmp    bx,1            ; got both chars?
  3901.     pop    bx
  3902.     jae    fgrab2            ; ae = yes, go produce output
  3903.     inc    grab            ; keep grabbing
  3904.     ret                ; return for the second
  3905.                     ; process the byte pair
  3906. fgrab2:    mov    grab,0            ; say done grabbing output
  3907.     push    dx            ; compose new single char result
  3908.     push    di
  3909.     push    es
  3910.     mov    di,seg data1
  3911.     mov    es,di
  3912.     mov    di,offset grl1lat    ; use Latin1 ptr
  3913.     cmp    vtcpage,852        ; CP852?
  3914.     jne    fgrab2a            ; ne = no
  3915.     mov    di,offset grl1lat2    ; use Latin 2
  3916. fgrab2a:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  3917.     jz    fgrab3            ; z = no
  3918.     cmp    dgkbl,16        ; Latin1?
  3919.     je    fgrab3            ; e = yes
  3920.     mov    di,offset grl1dgi    ; get DG Internat ptr to structure
  3921.     cmp    dgkbl,20        ; DG keyboard language, DG Internat?
  3922.     jne    fgrab15            ; ne = no
  3923. fgrab3:    mov    ax,word ptr grabbox    ; get pair of chars
  3924.     call    toupr            ; convert AX to upper case
  3925.     call    match
  3926.     jnc    fgrab11            ; nc = found
  3927.     xchg    ah,al
  3928.     call    match
  3929.     jnc    fgrab11            ; nc = match
  3930.  
  3931. fgrab5:    mov    di,offset grl2lat    ; use Latin1 ptr
  3932.     cmp    vtcpage,852        ; CP852?
  3933.     jne    fgrab5a            ; ne = no
  3934.     mov    di,offset grl2lat2    ; use Latin 2
  3935. fgrab5a:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  3936.     jz    fgrab6            ; z = no
  3937.     cmp    dgkbl,16        ; Latin1?
  3938.     je    fgrab6            ; e = yes
  3939.     mov    di,offset grl2dgi    ; get DG Internat ptr to structure
  3940.     cmp    dgkbl,20        ; DG keyboard language, DG Internat?
  3941.     jne    fgrab15            ; ne = no
  3942. fgrab6:    mov    ax,word ptr grabbox
  3943.     mov    dx,ax
  3944.     cmp    vtcpage,852        ; CP852?
  3945.     je    fgrab6a            ; e = yes, use as-is
  3946.     call    toupr            ; convert AX to upper case
  3947. fgrab6a:call    match
  3948.     jnc    fgrab7            ; nc = found
  3949.     xchg    ah,al            ; try reversed order
  3950.     xchg    dh,dl
  3951.     call    match
  3952.     jc    fgrab8            ; c = not found
  3953. fgrab7:    cmp    vtcpage,852        ; CP852?
  3954.     je    fgrab11            ; e = yes, output as-is
  3955.     cmp    dl,'a'            ; lower case char?
  3956.     jb    fgrab11            ; b = no, upper case
  3957.     or    al,20h            ; move to lower case output codes
  3958.     jmp    short fgrab11
  3959.  
  3960. fgrab8:    mov    di,offset grl3lat    ; use Latin1 ptr
  3961.     cmp    vtcpage,852        ; CP852?
  3962.     jne    fgrab8a            ; ne = no
  3963.     mov    di,offset grl3lat2    ; use Latin 2
  3964. fgrab8a:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  3965.     jz    fgrab9            ; z = no
  3966.     cmp    dgkbl,16        ; Latin1?
  3967.     je    fgrab9            ; e = yes
  3968.     mov    di,offset grl3dgi    ; get DG Internat ptr to structure
  3969.     cmp    dgkbl,20        ; DG keyboard language, DG Internat?
  3970.     jne    fgrab15            ; ne = no
  3971. fgrab9:    mov    ax,word ptr grabbox
  3972.     xchg    ah,al
  3973.     call    match            ; look for matching combination
  3974.     jc    fgrab16            ; c = failed
  3975. fgrab11:call    foutprt            ; send it to the host
  3976. fgrab15:call    togmod
  3977.     call    togmod            ; update mode line
  3978.     pop    es
  3979.     pop    di
  3980.     pop    dx
  3981.     ret
  3982.  
  3983. fgrab16:call    fvtbell            ; mismatch, beep, cancel
  3984.     jmp    short fgrab15        ;  finish up
  3985. fgrabber endp
  3986.  
  3987.                     ; worker for above
  3988. match    proc    near
  3989.     push    bx
  3990.     push    si
  3991.     push    di
  3992.     mov    cl,es:[di]        ; get count of pairs
  3993.     xor    ch,ch
  3994.     inc    di
  3995.     mov    si,di            ; start of char lists
  3996.     jcxz    match2            ; nothing to look at
  3997.     mov    si,di            ; remember where pairs start
  3998.     mov    bx,di
  3999.     add    bx,cx
  4000.     add    bx,cx            ; output singles start here
  4001.     cld
  4002.     push    cx            ; save counter
  4003.     repne    scasw            ; look for a match
  4004.     pop    cx
  4005.     jne    match2            ; ne = no match
  4006.     sub    di,2            ; backup to match
  4007.     sub    di,si            ; get item count
  4008.     shr    di,1            ; count bytes
  4009.     mov    al,es:[bx+di]        ; get new output char
  4010.     pop    di
  4011.     pop    si
  4012.     pop    bx
  4013.     clc                ; say success
  4014.     ret
  4015. match2:    pop    di
  4016.     pop    si
  4017.     pop    bx
  4018.     stc                ; say no match
  4019.     ret
  4020. match    endp
  4021.  
  4022. ; DEC LK201 keyboard keys and "User Definable Keys" in VT3xx mode
  4023. decfind:mov    al,1            ; Find
  4024.     jmp    dfkout
  4025. decinsert:mov    al,2            ; Insert
  4026.     jmp    dfkout
  4027. decremove:mov    al,3            ; Remove
  4028.     jmp    dfkout
  4029. decselect:mov    al,4            ; Select
  4030.     jmp    dfkout
  4031. decprev:mov    al,5            ; Previous screen
  4032.     jmp    dfkout
  4033. decnext:mov    al,6            ; Next screen
  4034.     jmp    dfkout
  4035. decf6:    mov    al,17            ; key ident for DEC F6
  4036.     jmp    dfkout            ; process it
  4037. decf7:    mov    al,18            ; key ident for DEC F7
  4038.     jmp    dfkout            ; process it
  4039. decf8:    mov    al,19            ; key ident for DEC F8
  4040.     jmp    dfkout            ; process it
  4041. decf9:    mov    al,20            ; key ident for DEC F9
  4042.     jmp    dfkout            ; process it
  4043. decf10:    mov    al,21            ; key ident for DEC F10
  4044.     jmp    dfkout            ; process it
  4045. decf11:    mov    al,23            ; key ident for DEC F11
  4046.     jmp    dfkout            ; process it
  4047. decf12:    mov    al,24            ; key ident for DEC F12
  4048.     jmp    dfkout            ; process it
  4049. decf13:    mov    al,25            ; key ident for DEC F13
  4050.     jmp    dfkout            ; process it
  4051. decf14:    mov    al,26            ; key ident for DEC F14
  4052.     jmp    dfkout            ; process it
  4053. dechelp:mov    al,28            ; key ident for DEC HELP
  4054.     jmp    dfkout            ; process it
  4055. decdo:    mov    al,29            ; key ident for DEC DO
  4056.     jmp    dfkout            ; process it
  4057. decf17:    mov    al,31            ; key ident for DEC F17
  4058.     jmp    dfkout            ; process it
  4059. decf18:    mov    al,32            ; key ident for DEC F18
  4060.     jmp    dfkout            ; process it
  4061. decf19:    mov    al,33            ; key ident for DEC F19
  4062.     jmp    dfkout            ; process it
  4063. decf20:    mov    al,34            ; key ident for DEC F20
  4064.     jmp    dfkout            ; process it
  4065.  
  4066. ; common worker to output contents of User Definable Key definition strings
  4067. ; Enter with al = key ident (17 - 34)
  4068. dfkout    proc    near
  4069.     push    ax
  4070.     push    bx
  4071.     push    cx
  4072.     push    es
  4073.     mov    ttyact,0        ; network, group chars for packet
  4074.     test    flags.vtflg,ttvt320+ttvt220 ; VT320/VT220?
  4075.     jnz    dfkout4            ; nz = yes, else use VT100/VT52 default
  4076.     test    flags.vtflg,tttek    ; Tek?
  4077.     jnz    dfkout4            ; nz = yes, try this
  4078.     mov    ttyact,1        ; network, restore tty active flag
  4079.     cmp    al,23            ; F11 sends ESC
  4080.     jne    dfkou1            ; ne = not F11
  4081.     mov    al,escape
  4082.     call    foutprt
  4083.     jmp    dfkoutx
  4084. dfkou1:    cmp    al,24            ; F12 sends BS
  4085.     jne    dfkou2            ; ne = not F12
  4086.     mov    al,BS
  4087.     call    foutprt
  4088.     jmp    dfkoutx
  4089. dfkou2:    cmp    al,25            ; F13 sends LF
  4090.     jne    dfkoutx            ; ne = not F13, ignore
  4091.     mov    al,LF
  4092.     call    foutprt
  4093. dfkou3:    jmp    dfkoutx
  4094.  
  4095. dfkout4:push    ax            ; VT320, use default definitions
  4096.     mov    al,Escape        ; char to send, CSI
  4097.     call    foutprt
  4098.     mov    al,'['
  4099.     call    foutprt            ; send lead-in char in 7/8-bit form
  4100.     pop    ax
  4101.     call    fprtnout        ; key ident (17-34) as ascii digits
  4102.     mov    al,7eh            ; tilde terminator
  4103.     mov    ttyact,1        ; network, restore tty active flag
  4104.     call    foutprt
  4105. dfkoutx:pop    es
  4106.     pop    cx
  4107.     pop    bx
  4108.     pop    ax
  4109.     clc
  4110.     ret
  4111. dfkout    endp
  4112.  
  4113. ; User Definable Keys
  4114. udkf6:    mov    al,17            ; key ident for DEC F6
  4115.     jmp    udkout            ; process it
  4116. udkf7:    mov    al,18            ; key ident for DEC F7
  4117.     jmp    udkout            ; process it
  4118. udkf8:    mov    al,19            ; key ident for DEC F8
  4119.     jmp    udkout            ; process it
  4120. udkf9:    mov    al,20            ; key ident for DEC F9
  4121.     jmp    udkout            ; process it
  4122. udkf10:    mov    al,21            ; key ident for DEC F10
  4123.     jmp    udkout            ; process it
  4124. udkf11:    mov    al,23            ; key ident for DEC F11
  4125.     jmp    udkout            ; process it
  4126. udkf12:    mov    al,24            ; key ident for DEC F12
  4127.     jmp    udkout            ; process it
  4128. udkf13:    mov    al,25            ; key ident for DEC F13
  4129.     jmp    udkout            ; process it
  4130. udkf14:    mov    al,26            ; key ident for DEC F14
  4131.     jmp    udkout            ; process it
  4132. udkf15:    mov    al,28            ; key ident for DEC HELP
  4133.     jmp    udkout            ; process it
  4134. udkf16:    mov    al,29            ; key ident for DEC DO
  4135.     jmp    udkout            ; process it
  4136. udkf17:    mov    al,31            ; key ident for DEC F17
  4137.     jmp    udkout            ; process it
  4138. udkf18:    mov    al,32            ; key ident for DEC F18
  4139.     jmp    udkout            ; process it
  4140. udkf19:    mov    al,33            ; key ident for DEC F19
  4141.     jmp    udkout            ; process it
  4142. udkf20:    mov    al,34            ; key ident for DEC F20
  4143. ;    jmp    udkout            ; process it
  4144.  
  4145. udkout    proc    near
  4146.     push    es
  4147.     mov    ttyact,0        ; network, group chars for packet
  4148.     mov    bl,al            ; VT3XX key ident, UDK style (17-34)
  4149.     sub    bl,17            ; minus starting offset of 17
  4150.     xor    bh,bh
  4151.     cmp    bl,17            ; out of range?
  4152.     ja    udkoutx            ; a = yes, ignore
  4153.     shl    bx,1            ; index words
  4154.     mov    bx,udkseg[bx]        ; segment of definition
  4155.     or    bx,bx            ; anything there?
  4156.     jz    udkoutx            ; z = no
  4157.     mov    es,bx            ; definition segment
  4158.     xor    bx,bx            ;  and offset
  4159.     mov    cl,es:[bx]        ; get string length byte
  4160.     xor    ch,ch            ; use cx as a counter
  4161.     jcxz    udkoutx            ; z = empty
  4162. udkou1:    inc    bx            ; es:bx is now the string text
  4163.     mov    al,es:[bx]        ; get a char
  4164.     push    bx
  4165.     push    cx
  4166.     push    es
  4167.     cmp    cx,1            ; last byte
  4168.     jne    udkou2            ; ne = not last byte
  4169.     mov    ttyact,1        ; network, restore tty active flag
  4170. udkou2:    call    foutprt            ; output
  4171.     pop    es
  4172.     pop    cx
  4173.     pop    bx
  4174.     loop    udkou1
  4175. udkoutx:pop    es
  4176.     clc
  4177.     ret
  4178. udkout    endp
  4179.                     ; Wyse-50 function keys F1..F16
  4180. wykf1:    mov    al,'@'            ; Wyse F1
  4181.     jmp    short wykfcom
  4182. wykf2:    mov    al,'A'            ; Wyse F2
  4183.     jmp    short wykfcom
  4184. wykf3:    mov    al,'B'
  4185.     jmp    short wykfcom
  4186. wykf4:    mov    al,'C'
  4187.     jmp    short wykfcom
  4188. wykf5:    mov    al,'D'
  4189.     jmp    short wykfcom
  4190. wykf6:    mov    al,'E'
  4191.     jmp    short wykfcom
  4192. wykf7:    mov    al,'F'
  4193.     jmp    short wykfcom
  4194. wykf8:    mov    al,'G'
  4195.     jmp    short wykfcom
  4196. wykf9:    mov    al,'H'
  4197.     jmp    short wykfcom
  4198. wykf10:    mov    al,'I'
  4199.     jmp    short wykfcom
  4200. wykf11:    mov    al,'J'
  4201.     jmp    short wykfcom
  4202. wykf12:    mov    al,'K'
  4203.     jmp    short wykfcom
  4204. wykf13:    mov    al,'L'
  4205.     jmp    short wykfcom
  4206. wykf14:    mov    al,'M'
  4207.     jmp    short wykfcom
  4208. wykf15:    mov    al,'N'
  4209.     jmp    short wykfcom
  4210. wykf16:    mov    al,'O'            ; Wyse F16
  4211.     jmp    short wykfcom
  4212.                     ; Wyse-50 Shift function keys F1..F16
  4213. wykSf1:    mov    al,'`'            ; Wyse Shift F1
  4214.     jmp    short wykfcom
  4215. wykSf2:    mov    al,'a'            ; Wyse Shift F2
  4216.     jmp    short wykfcom
  4217. wykSf3:    mov    al,'b'
  4218.     jmp    short wykfcom
  4219. wykSf4:    mov    al,'c'
  4220.     jmp    short wykfcom
  4221. wykSf5:    mov    al,'d'
  4222.     jmp    short wykfcom
  4223. wykSf6:    mov    al,'e'
  4224.     jmp    short wykfcom
  4225. wykSf7:    mov    al,'f'
  4226.     jmp    short wykfcom
  4227. wykSf8:    mov    al,'g'
  4228.     jmp    short wykfcom
  4229. wykSf9:    mov    al,'h'
  4230.     jmp    short wykfcom
  4231. wykSf10:mov    al,'i'
  4232.     jmp    short wykfcom
  4233. wykSf11:mov    al,'j'
  4234.     jmp    short wykfcom
  4235. wykSf12:mov    al,'k'
  4236.     jmp    short wykfcom
  4237. wykSf13:mov    al,'l'
  4238.     jmp    short wykfcom
  4239. wykSf14:mov    al,'m'
  4240.     jmp    short wykfcom
  4241. wykSf15:mov    al,'n'
  4242.     jmp    short wykfcom
  4243. wykSf16:mov    al,'o'            ; Wyse Shift F16
  4244.  
  4245. wykfcom:mov    ttyact,0        ; network, group chars for packet
  4246.     push    ax            ; save key code
  4247.     mov    al,1            ; send SOH keycode CR
  4248.     call    foutprt
  4249.     pop    ax
  4250.     call    foutprt
  4251.     mov    al,CR
  4252.     mov    ttyact,1        ; network, restore tty active flag
  4253.     call    foutprt
  4254.     ret
  4255.  
  4256. ; Change Telnet sessions
  4257. ifndef    no_tcp
  4258. ses1    proc    near
  4259.     mov    bx,0
  4260.     mov    cx,1
  4261.     jmp    short nextses4
  4262. ses1    endp
  4263. ses2    proc    near
  4264.     mov    bx,1
  4265.     mov    cx,1
  4266.     jmp    short nextses4
  4267. ses2    endp
  4268. ses3    proc    near
  4269.     mov    bx,2
  4270.     mov    cx,1
  4271.     jmp    short nextses4
  4272. ses3    endp
  4273. ses4    proc    near
  4274.     mov    bx,3
  4275.     mov    cx,1
  4276.     jmp    short nextses4
  4277. ses4    endp
  4278. ses5    proc    near
  4279.     mov    bx,4
  4280.     mov    cx,1
  4281.     jmp    short nextses4
  4282. ses5    endp
  4283. ses6    proc    near
  4284.     mov    bx,5
  4285.     mov    cx,1
  4286.     jmp    short nextses4
  4287. ses6    endp
  4288. endif    ; no tcp
  4289.  
  4290. nextses proc    near
  4291. ifndef    no_tcp
  4292.     cmp    flags.comflg,'t'    ; doing Telnet?
  4293.     je    nextses1        ; e = yes
  4294.     clc                ; do not exit Connect mode
  4295.     ret
  4296. nextses1:mov    bx,sescur        ; current session ident
  4297.     mov    cx,6            ; sessions to consider
  4298. nextses3:inc    bx
  4299.     cmp    bx,6            ; over the top yet
  4300.     jb    nextses4        ; b = no
  4301.     xor    bx,bx            ; wrap
  4302. nextses4:cmp    seslist[bx],0        ; is this session active?
  4303.     jge    nextses5        ; ge = yes
  4304.     loop    nextses3
  4305.     clc
  4306.     ret                ; do nothing
  4307.  
  4308. nextses5:push    bx
  4309.     mov    bx,sescur        ; old session
  4310.     call    termswapout        ; save current terminal items
  4311.     pop    bx
  4312.     mov    sescur,bx        ; next session, from above
  4313.     call    tcpstart        ; start session, ident in bl
  4314.     mov    bx,sescur        ; new session
  4315.     call    termswapin        ; get data structures
  4316.     mov    kbdflg,' '        ; return Connect mode
  4317.     stc                ; but exit Connect mode now
  4318. else
  4319.     clc
  4320. endif    ; no_tcp
  4321.     ret
  4322. nextses endp
  4323.  
  4324. vtsesmac  proc    far            ; SESSION macro
  4325.     mov    vtmacname,offset vtsesname
  4326.     mov    al,bl            ; session number
  4327.     add    al,'1'            ; to ascii, from 1
  4328.     mov    vtsesnum,al        ; to name
  4329.     mov    vtmaclen,vtseslen
  4330.     call    dword ptr vtmacroptr    ; FAR pointer
  4331.     ret
  4332. vtsesmac endp
  4333.  
  4334. ; Call from mszibm DG components to put system into DG special graphics mode,
  4335. ; and thus to cause incoming material to be still sent to the text emulator.
  4336. ; This also unshifts the screen (as seen on the status line) before starting
  4337. ; graphics so the column 81 stuff comes out right.
  4338. dgsettek proc    far
  4339. ifndef    no_graphics
  4340.     cmp    tekflg,tek_active+tek_sg ; inited already?
  4341.     je    dgsettek3        ; e = yes
  4342.     push    bx
  4343.     push    cx
  4344.     mov    cl,byte ptr low_rgt+1    ; examine whole screen
  4345.     inc    cl            ; lines in emulation part
  4346.     xor    ch,ch
  4347.     mov    bx,cx            ; for status line
  4348.     xor    al,al
  4349.     xchg    al,linescroll[bx]    ; status line scroll value
  4350.     or    al,al
  4351.     jz    dgsettek2        ; z = no shift in effect
  4352.     xor    bx,bx            ; start of screen
  4353. dgsettek1:sub    linescroll[bx],al    ; unscroll by status line amount
  4354.     inc    bx            ; next line
  4355.     loop    dgsettek1        ; do all emulation lines
  4356. dgsettek2:pop    cx
  4357.     pop    bx
  4358.     or    tekflg,tek_sg        ; set special graphics mode
  4359.     call    TEKINI            ; go to Tektronix Emulator
  4360. endif    ; no_graphics
  4361. dgsettek3:ret
  4362. dgsettek endp
  4363.  
  4364. ;[HF]940206 jpnxltkey
  4365. ;[HF]940207
  4366. ;[HF]940206 Check if leading byte of Japanese double byte code
  4367. ;[HF]940207 Range of Japanese second byte
  4368. ;[HF]940207 ((AL >= 0x40) && (AL <= 0x7e))||((AL >= 0x80) && (AL <= 0xfc))
  4369. ;[HF]940207
  4370. ;[HF]940206 If not Japanese, clear carry and return.
  4371. ;[HF]940207
  4372. jpnxltkey    proc    near        ;[HF]940206
  4373.     cmp    keypend,0        ;[HF]940207 Kanji second byte?
  4374.     jne    jpnxltk3        ;[HF]940207 ne = yes, second byte
  4375.     call    iskanji1        ;[HF]941010 Kanji leading byte ?
  4376.     jc    jpnxltk2        ;[HF]941010 c = yes
  4377.     call    iskana            ;[HF]941010 Katakana ?
  4378.     jnc    jpnxltk1        ;[HF]941010 nc = no
  4379.     cmp    flags.oshift,(128+3)    ;[HF]941012 DEC-Kanji ?
  4380.     je    jpnxltk1c        ;[HF]941012 e = yes, use X208 Katakana
  4381.     cmp    flags.oshift,(128+2)    ;[HF]941012 EUC-Kanji ?
  4382.     jne    jpnxltk1b        ;[HF]941012 ne = no
  4383.     call    outkana            ;[HF]941011 katakana output
  4384.     mov    keypend,0        ;[HF]941011 no pending char
  4385.     stc                ;[HF]941011 say, we have done
  4386.     ret                ;[HF]941011
  4387. jpnxltk1b:                ;[HF]941011
  4388.     cmp    flags.oshift,(128+1)    ;[HF]941012 JIS7-Kanji ?
  4389.     jne    jpnxltk1a        ;[HF]941012 ne = no
  4390. jpnxltk1c:                ;[HF]941012
  4391.     call    dblkana            ;[HF]941012 get double byte code
  4392.     or    ax,8080h        ;[HF]941012 make it GR
  4393.     mov    keypend,ax        ;[HF]941012
  4394.     jmp    jpnxltk5c        ;[HF]941012
  4395. jpnxltk1:                ;[HF]940207
  4396.     cmp    flags.oshift,(128+1)    ;[HF]940211 JIS7?
  4397.     jne    jpnxltk1a        ;[HF]940211 ne = no
  4398.     cmp    keyj7st,0        ;[HF]940211 ASCII state?
  4399.     je    jpnxltk1a        ;[HF]940211 e = yes
  4400.     push    ax            ;[HF]940211
  4401.     mov    al,ESCAPE        ;[HF]940211
  4402.     call    chrout            ;[HF]940211
  4403.     mov    al,'('            ;[HF]940211
  4404.     call    chrout            ;[HF]940211
  4405.     mov    al,byte ptr jis7des+1    ;[HF]940211
  4406.     call    chrout            ;[HF]940211
  4407.     mov    keyj7st,0        ;[HF]940211
  4408.     pop    ax            ;[HF]940211
  4409. jpnxltk1a:                ;[HF]940211
  4410.     mov    keypend,0        ;[HF]940207 Clear second byte flag
  4411.     clc                ;[HF]940206 tell that not Japanese
  4412.     ret                ;[HF]940206
  4413. jpnxltk2:                ;[HF]940206
  4414.     push    ax            ;[HF]940207
  4415.     mov    ah,al            ;[HF]940207
  4416.     xor    al,al            ;[HF]940207
  4417.     mov    keypend,ax        ;[HF]940207 save it for later use
  4418.     pop    ax            ;[HF]940207
  4419.     stc                ;[HF]940206 tell that Japanese
  4420.     ret                ;[HF]940206
  4421. jpnxltk3:                ;[HF]940207
  4422.     cmp    al,40h            ;[HF]940207
  4423.     jb    jpnxltk4        ;[HF]940207 not the second byte
  4424.     cmp    al,7eh            ;[HF]940207
  4425.     jbe    jpnxltk5        ;[HF]940207 Yes second byte
  4426.     cmp    al,80h            ;[HF]940207
  4427.     jb    jpnxltk4        ;[HF]940207 not the second byte
  4428.     cmp    al,0fch            ;[HF]940207
  4429.     jbe    jpnxltk5        ;[HF]940207 Yes second byte
  4430. jpnxltk4:                ;[HF]940207
  4431.     jmp    jpnxltk1        ;[HF]940211 treat as single byte char.
  4432. jpnxltk5:                ;[HF]940207
  4433.     mov    byte ptr keypend,al    ;[HF]940207 make double byte code
  4434.     mov    ax,keypend        ;[HF]940207 Shift-JIS code
  4435.     call    jpnftox            ;[HF]940207 translate to EUC(JIS-GR)
  4436. jpnxltk5c:                ;[HF]941012
  4437.     cmp    flags.oshift,(128+1)    ;[HF]940211 JIS7?
  4438.     je    jpnxltk5a        ;[HF]940211 e = yes
  4439.     cmp    flags.oshift,(128+2)    ;[HF]940214 EUC?
  4440.     je    jpnxltk5b        ;[HF]940214 e = yes
  4441.     cmp    flags.oshift,(128+3)    ;[HF]941012 DEC?
  4442.     je    jpnxltk5b        ;[HF]941012 e = yes
  4443.     mov    ax,keypend        ;[HF]940214 No. use Shift-JIS code
  4444.     jmp    short jpnxltk5b        ;[HF]940211
  4445. jpnxltk5a:                ;[HF]940211
  4446.     and    ax,7f7fh        ;[HF]940211
  4447.     cmp    keyj7st,2        ;[HF]940211 Kanji state?
  4448.     je    jpnxltk5b        ;[HF]940211 e=yes, no shift
  4449.     push    ax            ;[HF]940211
  4450.     mov    al,ESCAPE        ;[HF]940211
  4451.     call    chrout            ;[HF]940211
  4452.     mov    al,'$'            ;[HF]940211
  4453.     call    chrout            ;[HF]940211
  4454.     mov    al,byte ptr jis7des    ;[HF]940211
  4455.     call    chrout            ;[HF]940211
  4456.     mov    keyj7st,2        ;[HF]940211
  4457.     pop    ax            ;[HF]940211
  4458. jpnxltk5b:                ;[HF]940211
  4459.     push    ax            ;[HF]940214 save dble byte code
  4460.     mov    al,ah            ;[HF]940207
  4461.     call    chrout            ;[HF]940207 send leading byte
  4462.     pop    ax            ;[HF]940214 remember dble byte code
  4463.     mov    ah,al            ;[HF]940207
  4464.     call    chrout            ;[HF]940207 send second byte
  4465.     mov    keypend,0        ;[HF]940207 clear double byte flag
  4466.     stc                ;[HF]940207 say no more char
  4467.     ret                ;[HF]940207
  4468. jpnxltkey    endp            ;[HF]940206
  4469.  
  4470. ;[HF]941011 outkana
  4471. ;[HF]941011
  4472. ;[HF]941011 Output Shift-JIS katakana code in AL to com port.
  4473. outkana    proc    near            ;[HF]941011
  4474.     push    ax            ;[HF]941011 save AX
  4475.     push    bx            ;[HF]941011 save BX
  4476.     cmp    flags.oshift,(128+1)    ;[HF]941012 JIS7 ?
  4477.     je    outkan1            ;[HF]941012 e = yes
  4478.     mov    bl,flags.oshift        ;[HF]941011 save output-shift
  4479.     mov    flags.oshift,0        ;[HF]941011 Do our own shift
  4480.     mov    bh,al            ;[HF]941011 save AL
  4481.     mov    al,SS2            ;[HF]941011 SS2
  4482.     call    chrout            ;[HF]941011
  4483.     mov    al,bh            ;[HF]941011 restore AL
  4484.     or    al,80h            ;[HF]941011 8th bit On
  4485.     call    chrout            ;[HF]941011
  4486.     jmp    outkanx            ;[HF]941012
  4487. outkan1:cmp    keyj7st,1        ;[HF]941012 already in katakana mode?
  4488.     je    outkan3            ;[HF]941012 e = yes
  4489.     cmp    keyj7st,2        ;[HF]941012 in kanji mode?
  4490.     jne    outkan2            ;[HF]941012 ne = no
  4491.     mov     bh,al            ;[HF]941012 save AL
  4492.     mov    al,ESCAPE        ;[HF]941012
  4493.     call    chrout            ;[HF]941012
  4494.     mov    al,'('            ;[HF]941012
  4495.     call    chrout            ;[HF]941012
  4496.     mov    al,byte ptr jis7des+1    ;[HF]941012
  4497.     call    chrout            ;[HF]941012
  4498. outkan2:mov    al,SOchar        ;[HF]941012 SO
  4499.     call    chrout            ;[HF]941012
  4500.     mov    keyj7st,1        ;[HF]941012
  4501.     mov    al,bh            ;[HF]941012
  4502. outkan3:and    al,7fh            ;[HF]941012 mask 8th bit
  4503.     call    chrout            ;[HF]941012
  4504. outkanx:mov    flags.oshift,bl        ;[HF]941011 restore output-shift
  4505.     pop    bx            ;[HF]941011 restore BX
  4506.     pop    ax            ;[HF]941011 restore AX
  4507.     ret                ;[HF]941011
  4508. outkana    endp                ;[HF]941011
  4509.  
  4510. ;[HF]941012 dblkana
  4511. ;[HF]941012
  4512. ;[HF]941012 convert single byte katakana code to double byte code
  4513. ;[HF]941012 Input: AL Katakana code in JIS
  4514. ;[HF]941012 Outpt: AX Double byte JIS katakana code (AH first)
  4515. dblkana    proc    near            ;[HF]941012
  4516.     push    es
  4517.     push    bx            ;[HF]941012
  4518.     sub    ax,32            ;[HF]941012
  4519.     and    ax,3fh            ;[HF]941012
  4520.     mov    bx,seg kanatbl
  4521.     mov    es,bx
  4522.     mov    bx,offset kanatbl    ;[HF]941012
  4523.     add    bx,ax            ;[HF]941012
  4524.     add    bx,ax            ;[HF]941012 word address
  4525.     mov    ax,es:[bx]        ;[HF]941012
  4526.     pop    bx            ;[HF]941012
  4527.     pop    es
  4528.     ret                ;[HF]941012
  4529. dblkana    endp                ;[HF]941012
  4530.  
  4531. ;[HF]941010 iskana
  4532. ;[HF]941010
  4533. ;[HF]941010 Check if AL is Shift-JIS Katakana code or not.
  4534. ;[HF]941010 If Katakana, program returns with carry set,
  4535. ;[HF]941010 if not, carry clear.
  4536. ;[HF]941010
  4537. ;[HF]941010 Note: Shift-JIS Katakana is in the range
  4538. ;[HF]941010 ((AL >= 0xa0) && (AL <= 0xdf))
  4539. ;[HF]941010 where AL = 0xa0 is space
  4540. ;[HF]941010
  4541. iskana    proc    near            ;[HF]941010
  4542.     cmp    al,0a0h            ;[HF]941010
  4543.     jb    iskanan            ;[HF]941010 b = no
  4544.     cmp    al,0dfh            ;[HF]941010
  4545.     ja    iskanan            ;[HF]941010 a = no
  4546.     stc                ;[HF]941010 yes, katakana
  4547.     jmp    short iskanax        ;[HF]941010
  4548. iskanan:clc                ;[HF]941010 no, not katakana
  4549. iskanax:ret                ;[HF]941010
  4550. iskana    endp                ;[HF]941010
  4551.  
  4552. ;[HF]940207 Range of Shift-JIS Kanji leading byte
  4553. ;[HF]940207 ((AL >= 0x81) && (AL <= 0x9f))||((AL >= 0xe0) && (AL <= 0xfc))
  4554. iskanji1    proc    near        ;[HF]941010
  4555.     cmp    al,81h            ;[HF]940207
  4556.     jb    iskan1n            ;[HF]940207 b = No, not Kanji leading
  4557.     cmp    al,9fh            ;[HF]940207
  4558.     jbe    iskan1y            ;[HF]940207 Yes, Japanese leading byte
  4559.     cmp    al,0e0h            ;[HF]940207
  4560.     jb    iskan1n            ;[HF]940207 No, not Japanese
  4561.     cmp    al,0fch            ;[HF]940207
  4562.     jbe    iskan1y            ;[HF]940207 Yes, Japanese leading byte
  4563. iskan1n:clc                ;[HF]941010
  4564.     jmp    short iskan1x        ;[HF]941010
  4565. iskan1y:stc                ;[HF]941010
  4566. iskan1x:ret                ;[HF]941010
  4567. iskanji1    endp            ;[HF]941010
  4568.  
  4569. code    ends
  4570.  
  4571. code1    segment
  4572.     assume    cs:code1
  4573.  
  4574. ; Set (define) the DEC "User Definable Keys". Inserts text definitions for
  4575. ; keyboard verbs \KdecF6 ...\KdecF14, \KdecHELP, \KdecDO, \KdecF17...\KdecF20.
  4576. ; Enter with the DCS definition string as key-number/hex-chars. UDK key number
  4577. ; is 17 for \KdecF6, et seq, the definition are pairs of hex digits converted
  4578. ; here to a single byte per pair. The DCS definition string is pointed at by
  4579. ; DS:SI, and the byte count is in CX.
  4580. ; Example:  17/54657374204636   means key \KdecF6 sends string "Test F6"
  4581. setudk    proc    near
  4582.     push    ax
  4583.     push    bx
  4584.     push    cx
  4585.     push    si
  4586.     push    di
  4587.     push    es
  4588.     cld
  4589.     lodsb                ; get key ident first byte
  4590.     sub    al,'0'            ; ascii to binary
  4591.     mul    ten            ; times 10
  4592.     xchg    ah,al            ; to ah
  4593.     lodsb                ; get key ident second byte
  4594.     sub    al,'0'            ; ascii to binary
  4595.     add    al,ah            ; plus high order part
  4596.     xor    ah,ah
  4597.     mov    bx,ax            ; key ident, 17 - 34
  4598.     lodsb                ; skip slash separator
  4599.     sub    cx,3            ; three less bytes in the string
  4600.     jge    setudk0            ; ge = had three or more bytes
  4601.     jmp    setudkx            ; else error
  4602. setudk0:sub    bx,17            ; remove key ident bias of 17
  4603.     cmp    bx,17            ; out of range?
  4604.     ja    setudkx            ; a = yes, ignore
  4605.     shl    bx,1            ; index words
  4606.     cmp    udkseg[bx],0        ; has a segment been allocated for it?
  4607.     je    setudk1            ; e = no
  4608.     mov    ax,udkseg[bx]        ; get segment to es
  4609.     mov    es,ax
  4610.     mov    ah,freemem        ; deallocate old memory block, es:0
  4611.     int    dos
  4612.     mov    udkseg[bx],0        ; clear table entry too
  4613. setudk1:and    cl,not 1        ; force an even number of inputs
  4614.     jcxz    setudkx            ; z = no definition, clear entry
  4615.     push    bx            ; save index BX
  4616.     mov    bx,cx            ; get string length
  4617.     shr    bx,1            ; two hex digits per final byte
  4618.     add    bx,15+1            ; round up plus length byte
  4619.     shr    bx,1            ; convert to paragraphs
  4620.     shr    bx,1
  4621.     shr    bx,1
  4622.     shr    bx,1
  4623.     mov    di,bx            ; remember request
  4624.     mov    ah,alloc        ; allocate BX paragraphs
  4625.     int    dos
  4626.     jc    setudkx            ; c = failure
  4627.     cmp    di,bx            ; requested vs allocated
  4628.     pop    bx            ; recover bx
  4629.     je    setudk2            ; e = enough
  4630.     mov    ah,freemem        ; return the memory, es is ptr
  4631.     int    dos
  4632.     jmp    short setudkx        ; exit failure
  4633.  
  4634. setudk2:mov    es,ax            ; segment of allocated memory
  4635.     mov    udkseg[bx],ax        ; segment:0 of definition string
  4636.     xor    di,di
  4637.     cld
  4638.     mov    al,cl            ; length of string
  4639.     shr    al,1            ; two hex bytes per stored byte
  4640.     xor    ch,ch
  4641.     stosb                ; store length byte
  4642.     jcxz    setudkx            ; z = empty string
  4643. setukd3:lodsb                ; get first hex digit
  4644.     dec    cx            ; adjust count remaining
  4645.     or    al,20h            ; to lower case
  4646.     cmp    al,'9'            ; digit?
  4647.     jbe    setudk4            ; be = yes
  4648.     sub    al,'a'-'9'-1        ; hex letter to column three
  4649. setudk4:sub    al,'0'            ; ascii to binary
  4650.     shl    al,1            ; times 16
  4651.     shl    al,1
  4652.     shl    al,1
  4653.     shl    al,1
  4654.     mov    ah,al            ; save in ah
  4655.     lodsb                ; get second hex digit
  4656.     or    al,20h            ; to lower case
  4657.     cmp    al,'9'            ; digit?
  4658.     jbe    setudk5            ; be = yes
  4659.     sub    al,'a'-'9'-1        ; hex letter to column three
  4660. setudk5:sub    al,'0'            ; ascii to binary
  4661.     add    al,ah            ; join both parts
  4662.     stosb                ; store final byte
  4663.     loop    setukd3
  4664. setudkx:pop    es
  4665.     pop    di
  4666.     pop    si
  4667.     pop    cx
  4668.     pop    bx
  4669.     pop    ax
  4670.     clc
  4671.     ret
  4672. setudk    endp
  4673.  
  4674. ; Clear all User Definable Keys, deallocate memory for their definitions
  4675. udkclear proc    near
  4676.     push    ax
  4677.     push    bx
  4678.     push    cx
  4679.     push    es
  4680.     mov    cx,17            ; 17 entries
  4681.     xor    bx,bx
  4682. udkcle1:mov    ax,udkseg[bx]        ; segment of definition
  4683.     or    ax,ax            ; segment defined?
  4684.     jz    udkcle2            ; z = no, try next key
  4685.     mov    es,ax
  4686.     mov    udkseg[bx],0        ; clear the entry
  4687.     mov    ah,freemem        ; release the memory
  4688.     int    dos
  4689. udkcle2:add    bx,2            ; word index
  4690.     loop    udkcle1            ; do all
  4691.     pop    es
  4692.     pop    cx
  4693.     pop    bx
  4694.     pop    ax
  4695.     clc
  4696.     ret
  4697. udkclear endp
  4698.  
  4699. fsetpos    proc    far
  4700.     call    setpos
  4701.     ret
  4702. fsetpos    endp
  4703.  
  4704. frepaint proc    far
  4705.     call    repaint
  4706.     ret
  4707. frepaint endp
  4708. code1    ends
  4709.  
  4710. code    segment
  4711.     assume    cs:code
  4712.                     ; these commands invoke Quit
  4713. cdos:    mov    al,'P'            ; Push to DOS
  4714.     jmp    short cmdcom
  4715. cstatus:mov    al,'S'            ; Status
  4716.     jmp    short cmdcom
  4717. cquit:    mov    al,'C'            ; Exit Connect mode
  4718.     jmp    short cmdcom
  4719. cquery:    mov    al,'?'            ; Help
  4720.     jmp    short cmdcom
  4721. chang:    mov    al,'H'            ; Hangup, drop DTR & RTS
  4722.     jmp    short cmdcom
  4723. cmdcom:    mov    kbdflg,al        ; pass char to msster.asm via kbdflg
  4724.     stc                ; signal that Quit is needed
  4725.     ret
  4726.                     ; general character out for emulator
  4727. chrout    proc    near
  4728.     cmp    flags.vtflg,0        ; emulating?
  4729.     je    chrou5            ; e = no
  4730.     call    fanskbi            ; say we had keyboard input
  4731.     cmp    al,cr            ; CR?
  4732.     jne    chrou5            ; ne = no, just output it and return
  4733.     test    vtemu.vtflgop,anslnm    ; ANSI new-line mode set?
  4734.     jz    chrou5            ; z = no, just send the cr
  4735.     cmp    dupflg,0        ; full duplex?
  4736.     je    chrou4            ; e = yes
  4737.     cmp    al,trans.seol        ; End of Line char?
  4738.     jne    chrou5            ; ne = no
  4739. chrou4:    mov    ah,trans.seol        ; save eol char
  4740.     push    ax            ; save on stack
  4741.     mov    trans.seol,lf        ; make LF the eol char
  4742.     call    foutprt            ; output a carriage-return
  4743.     mov    al,lf            ; followed by a line feed
  4744.     call    foutprt            ; send the LF
  4745.     pop    ax
  4746.     mov    trans.seol,ah        ; restore eol char
  4747.     ret
  4748. chrou5:    call    foutprt
  4749.     ret
  4750. chrout    endp
  4751.  
  4752.                        ; Screen dump entry from keyboad xlat
  4753. dmpscn    proc    near            ; dump screen to file
  4754. ifndef    no_graphics
  4755.     cmp    flags.vtflg,tttek    ; doing Tektronix emulation?
  4756.     je    dmpscn2            ; e = yes, use Tek emulator
  4757.     cmp    tekflg,tek_active+tek_dec ; emulation a Tektronix?
  4758.     jne    dmpscn1            ; ne = no
  4759. dmpscn2:call    tekdmp            ; near-call Tek screen dump utility
  4760.     clc
  4761.     ret
  4762. endif    ; no_graphics
  4763.  
  4764. dmpscn1:call    dumpscr            ; do buffer to file
  4765.     clc                ; do not exit Connect mode
  4766.     ret
  4767. dmpscn    endp
  4768.  
  4769. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  4770. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  4771. ; is determined by mssset and is passed as pointer dmpname.
  4772. ; Dumpscr reads the screen image saved in vscreen.
  4773.  
  4774. dumpscr proc    near
  4775.     push    ax
  4776.     push    bx
  4777.     push    cx
  4778.     push    dx
  4779.     mov    dmphand,-1        ; preset illegal handle
  4780.     mov    dx,offset dmpname    ; name of disk file, from mssset
  4781.     mov    ax,dx            ; where isfile wants name ptr
  4782.     call    isfile            ; what kind of file is this?
  4783.     jc    dmp5            ; c = no such file, create it
  4784.     test    byte ptr filtst.dta+21,1fh ; file attributes, ok to write?
  4785.     jnz    dmp0            ; nz = no.    
  4786.     mov    al,1            ; writing
  4787.     mov    ah,open2        ; open existing file
  4788.     int    dos
  4789.     jc    dmp0            ; c = failure
  4790.     mov    dmphand,ax        ; save file handle
  4791.     mov    bx,ax            ; need handle here
  4792.     mov    cx,0ffffh        ; setup file pointer
  4793.     mov    dx,-1            ; and offset
  4794.     mov    al,2            ; move to eof minus one byte
  4795.     mov    ah,lseek        ; seek the end
  4796.     int    dos
  4797.     jmp    dmp1
  4798.  
  4799. dmp5:    test    filtst.fstat,80h    ; access problem?
  4800.     jnz    dmp0            ; nz = yes
  4801.     mov    ah,creat2        ; file did not exist
  4802.     mov    cx,20h            ; attributes, archive bit
  4803.     int    dos
  4804.     mov    dmphand,ax        ; save file handle
  4805.     jnc    dmp1            ; nc = ok
  4806.  
  4807. dmp0:    mov    ah,3            ; get cursor position
  4808.     xor    bh,bh            ; page 0
  4809.     int    screen
  4810.     push    dx            ; save it
  4811.     mov    dh,byte ptr low_rgt+1    ; go to status line
  4812.     inc    dh
  4813.     xor    dl,dl            ; left most column
  4814.     mov    ah,2            ; set cursor
  4815.     xor    bh,bh            ; page 0
  4816.     int    screen
  4817.     mov    dx,offset dmperr    ; say no can do
  4818.     mov    ah,prstr
  4819.     int    dos
  4820.     pop    dx            ; get original cursor position
  4821.     mov    ah,2            ; set cursor
  4822.     xor    bh,bh            ; page 0
  4823.     int    screen
  4824.     pop    dx
  4825.     pop    cx
  4826.     pop    bx
  4827.     pop    ax
  4828.     clc
  4829.     ret
  4830.  
  4831. dmp1:    mov    ah,ioctl        ; is destination ready for output?
  4832.     mov    al,7            ; test output status
  4833.     mov    bx,dmphand        ; handle
  4834.     int    dos
  4835.     jc    dmp0            ; c = error
  4836.     cmp    al,0ffh            ; ready?
  4837.     jne    dmp0            ; ne = not ready
  4838.     push    di            ; read screen buffer, write lines
  4839.     push    si
  4840.     push    es
  4841.     mov    cl,byte ptr low_rgt+1    ; number of lines - 2
  4842.     add    cl,2            ; number of line on screen
  4843.     xor    ch,ch
  4844.     les    si,vs_ptr        ; seg and offset of vscreen
  4845.     sub    si,vswidth*2        ; prep for inc below
  4846. dmp2:    add    si,vswidth*2        ; virtual screen width in bytes
  4847.     push    si
  4848.     push    cx            ; save outer loop counter
  4849.     push    di
  4850.     mov    di,offset decbuf    ; data segment memory
  4851.     mov    cl,byte ptr low_rgt    ; number of columns on screen -1
  4852.     inc    cl
  4853.     xor    ch,ch
  4854. dmp3:    mov    ax,word ptr es:[si]    ; read char + attribute
  4855.     or    al,al            ; is it a null?
  4856.     jnz    dmp3c            ; nz = no
  4857.     mov    al,' '            ; replace null with space
  4858. dmp3c:    mov    byte ptr [di],al    ; store just char, don't use es:
  4859.     inc    si            ; update pointers
  4860.     inc    si
  4861.     inc    di
  4862.     loop    dmp3            ; do for each column
  4863.     mov    cl,byte ptr low_rgt    ; number of columns on screen - 1
  4864.     inc    cl
  4865.     xor    ch,ch
  4866.     push    es
  4867.     mov    ax,ds
  4868.     mov    es,ax            ; set es to data segment for es:di
  4869.     mov    di,offset decbuf    ; start of line
  4870.     add    di,cx            ; plus length of line
  4871.     dec    di            ; minus 1 equals end of line
  4872.     mov    al,' '            ; thing to scan over
  4873.     std                ; set scan backward
  4874.     repe    scasb            ; scan until non-space
  4875.     cld                ; set direction forward
  4876.     pop    es
  4877.     je    dmp3a            ; e = all spaces
  4878.     inc    cx
  4879.     inc    di
  4880. dmp3a:    mov    word ptr [di+1],0A0Dh    ; append cr/lf
  4881.     add    cx,2            ; line count + cr/lf
  4882.     mov    dx,offset decbuf    ; array to be written
  4883.     mov    bx,dmphand        ; need file handle
  4884.     mov    ah,write2        ; write the line
  4885.     int    dos
  4886.     pop    di
  4887.     pop    cx            ; get line counter again
  4888.     pop    si            ; screen offset
  4889.     jc    dmp3b            ; c = error
  4890.     loop    dmp2            ; do next line
  4891. dmp3b:    mov    dx,offset dumpsep    ; put in formfeed/cr/lf
  4892.     mov    bx,dmphand        ; need file handle
  4893.     mov    cx,3            ; three bytes overall
  4894.     mov    ah,write2        ; write them
  4895.     mov    bx,dmphand        ; file handle
  4896.     int    dos
  4897.     mov    bx,dmphand        ; need file handle
  4898.     mov    ah,close2        ; close the file now
  4899.     int    dos
  4900.     pop    es
  4901.     pop    si
  4902.     pop    di
  4903.     pop    dx
  4904.     pop    cx
  4905.     pop    bx
  4906.     pop    ax
  4907.     clc
  4908.     ret
  4909. dumpscr endp
  4910.  
  4911. togmod    proc    FAR
  4912.     call    trnmod            ; FAR callable trnmod
  4913.     ret
  4914. togmod    endp
  4915.  
  4916.                     ; Toggle Mode Line
  4917. trnmod    proc    near
  4918.     cmp    inemulator,0        ; in terminal emulator?
  4919.     je    trnm1            ; e = no, no mode line
  4920.     cmp    flags.modflg,1        ; mode line enabled and owned by us?
  4921.     jne    trnm1            ; ne = no, don't touch it
  4922.     cmp    flags.vtflg,tttek    ; Tek mode?
  4923.     je    trnm1            ; e = yes
  4924.     test    tekflg,tek_dec        ; in Tek submode?
  4925.     jnz    trnm1            ; nz = yes, no mode line changes
  4926.     test    yflags,modoff        ; mode line already off?
  4927.     jnz    trnm2            ; nz = yes, go turn on
  4928.     or    yflags,modoff        ; say modeline is toggled off
  4929.     cmp    flags.vtflg,0        ; emulating none?
  4930.     jne    trnm0            ; ne = no
  4931.     mov    lastsec,-1        ; tickle tod clock
  4932.     push    dx
  4933.     call    fgetpcur        ; get physical cursor
  4934.     mov    cursor,dx
  4935.     pop    dx
  4936. trnm0:    call    clrmod            ; clear mode line
  4937. trnm1:    clc                ; clear c bit so don't exit Connect
  4938.     ret
  4939. trnm2:    cmp    flags.vtflg,0        ; emulating a terminal?
  4940.     jne    trnm3            ; ne = yes
  4941.     push    dx            ; scroll screen to save bottom line
  4942.     call    fgetpcur        ; get physical cursor
  4943.     mov    cursor,dx
  4944.     mov    ah,prstr        ; for terminal type none
  4945.     mov    dx,offset crlf
  4946.     int    dos
  4947.     pop    dx
  4948. trnm3:    call    modlin            ; turn on modeline
  4949.     and    yflags,not modoff    ; say modeline is not toggled off
  4950.     clc
  4951.     ret
  4952. trnmod    endp
  4953.  
  4954. modlin    proc    near
  4955.     cmp    isps55,0        ; [HF]940206 Japanese PS/55 ?
  4956.     je    modl21            ; [HF]940206 e = no
  4957.     cmp    ps55mod,0        ; [HF]940206 can we use modeline?
  4958.     jne    modl21            ; [HF]940206 ne = yes
  4959.     mov    ax,1401h        ; [HF]940206 user uses the modeline
  4960.     mov    ps55mod,al        ; [HF]940206 save current status
  4961.     int    16h            ; [HF]940206 OK, now in our hands
  4962. modl21:    push    si
  4963.     push    di
  4964.     push    es
  4965.     mov    ax,ds
  4966.     mov    es,ax
  4967.     mov    si,offset modmaster    ; master template
  4968.     mov    di,offset modbuf    ; working copy
  4969.     mov    lastsec,-1        ; tickle tod clock
  4970.     cld
  4971. modl20:    lodsb
  4972.     stosb
  4973.     cmp    al,'$'            ; at end?
  4974.     jne    modl20            ; ne = no
  4975.     mov    bx,argadr        ; get argument block
  4976.     mov    al,[bx].baudb        ; get baud bits
  4977.     mov    si,offset unkbaud    ; assume unknown baud
  4978.     mov    cx,size m_baud        ; length of baud space
  4979.     cmp    al,baudnsiz        ; beyond end of table?
  4980.     jnb    modl2            ; nb = yes, use default
  4981.     mul    cl
  4982.     xor    ah,ah
  4983.     add    ax,offset baudn
  4984.     mov    si,ax
  4985. modl2:    mov    di,offset modbuf.m_baud
  4986.     cld
  4987.     rep    movsb            ; copy in baud rate
  4988.     mov    bx,portval
  4989.     mov    al,[bx].parflg        ; get parity code
  4990.     and    al,3            ; regular parity uses two bits
  4991.     mov    ah,al
  4992.     shl    al,1            ; each is 3 bytes long
  4993.     add    al,ah
  4994.     xor    ah,ah
  4995.     add    ax,offset parnams    ; names of parity settings
  4996.     mov    si,ax
  4997.     mov    cx,3            ; each is 3 long
  4998.     mov    di,offset modbuf.m_par
  4999.     push    di
  5000.     rep    movsb
  5001.     pop    di
  5002.     test    [bx].parflg,PARHARDWARE    ; using hardware parity?
  5003.     jz    modl2b            ; z = no
  5004.     mov    al,'8'            ; say 8 data bits
  5005.     stosb
  5006.     jmp    short modl2a
  5007.  
  5008. modl2b:    cmp    byte ptr [di],'8'    ; any parity?
  5009.     jne    modl2a            ; ne = yes, use existing '7'
  5010.     test    flags.remflg,d8bit    ; 8 bit display?
  5011.     jnz    modl2a            ; nz = yes
  5012.     mov    al,'7'
  5013.     stosb                ; overwrite '8' with '7'
  5014. modl2a:    mov    si,offset remmsg    ; assume remote echoing
  5015.     test    yflags,lclecho        ; local echo on?
  5016.     jz    modl3            ; z = no
  5017.     mov    si,offset lclmsg    ; say echo is local
  5018. modl3:    mov    cx,3            ; size of value
  5019.     mov    di,offset modbuf.m_echo
  5020.     rep    movsb
  5021.     mov    al,portno        ; communications port
  5022.     cmp    al,' '            ; binary (non-printable)?
  5023.     jae    modl4            ; ae = no, ascii
  5024.     add    al,'0'            ; convert to ascii
  5025. modl4:    mov    modbuf.m_prt,al        ; fill in port number
  5026.     mov    al,portno
  5027.     cmp    repflg,0        ; REPLAY?
  5028.     je    modl5            ; e = no
  5029.     mov    si,offset repmsg    ; say "REPLAY"
  5030.     mov    cx,repmsgl        ; its length
  5031.     mov    di,offset modbuf.m_prt
  5032.     mov    al,' '            ; start with a space
  5033.     stosb
  5034.     mov    dx,24            ; space to be filled
  5035.     sub    dx,cx            ; amount we will use here
  5036.     rep    movsb            ; copy string
  5037.     mov    cx,dx
  5038.     rep    stosb            ; flesh out with spaces
  5039.     jmp    modl10
  5040.  
  5041. modl5:    cmp    al,'4'            ; in networks material?
  5042.     jbe    modl10            ; be = no
  5043. ifndef    no_tcp
  5044.     cmp    flags.comflg,'t'    ; doing TCP/IP Telnet?
  5045.     jne    modl5d            ; ne = no
  5046.     mov    si,offset tcphost    ; name of host
  5047.     mov    di,offset modbuf.m_prt - 5 ; overwrite "port:"
  5048. ifdef    nls_portuguese
  5049.     dec    di            ; "porta:"
  5050. endif    ; nls_portuguese
  5051.  
  5052. modl5c:    mov    ax,sescur        ; ident of session
  5053.     add    al,'1'            ; ascii, show as 1:nodename
  5054.     mov    ah,':'
  5055.     stosw                ; store that much
  5056.     mov    cx,28            ; bytes max
  5057. modl5a:    lodsb
  5058.     or    al,al             ; at null terminator?
  5059.     jz    modl5b            ; z = yes
  5060.     stosb
  5061.     loop    modl5a
  5062. modl5b:    mov    al,' '            ; fill out with spaces
  5063.     rep    stosb            ; noop if cx == 0
  5064.     jmp    short modl5d        ; done with tcp/ip 
  5065. endif    ; no_tcp
  5066.  
  5067. modl5d:    mov    bx,offset comptab    ; table of comms ports
  5068.     mov    cl,[bx]            ; number of entries
  5069.     xor    ch,ch
  5070.     inc    bx
  5071. modl6:    mov    dx,[bx]            ; length of this entry
  5072.     mov    si,bx
  5073.     add    si,2            ; points to entry text string
  5074.     add    si,dx            ; point to qualifier
  5075.     cmp    [si],al            ; our port?
  5076.     je    modl7            ; e = yes
  5077.     add    bx,[bx]            ; add text length
  5078.     add    bx,4            ; plus count and qualifier
  5079.     loop    modl6            ; next entry
  5080.     jmp    short modl10        ; no match, curious
  5081. modl7:    mov    si,bx            ; point at entry
  5082.     add    si,2            ; point at string
  5083.     mov    cx,[bx]            ; length of string
  5084.     mov    di,offset modbuf.m_prt
  5085.     mov    al,' '            ; start with a space
  5086.     stosb
  5087.     mov    dx,17            ; space to be filled
  5088. ifdef    nls_portuguese
  5089.     dec    dx
  5090. endif    ; nls_portuguese
  5091.     sub    dx,cx            ; amount we will use here
  5092.     rep    movsb            ; copy string
  5093.  
  5094.     cmp    flags.comflg,'F'    ; Fossil?
  5095.     jne    modl9            ; ne = no
  5096.     mov    al,'-'            ; punctuation
  5097.     stosb
  5098.     mov    ax,fossil_port        ; port
  5099.     inc    ax            ; count from one to user
  5100.     push    dx            ; preserve reg for below
  5101.     call    dec2di            ; write port
  5102.     pop    dx
  5103.     sub    dx,2            ; dash and digit
  5104.     add    di,2
  5105.     cmp    fossil_port,9        ; two digits?
  5106.     jbe    modl9            ; be = no
  5107.     dec    dx            ; yes, one less slot
  5108.     inc    di
  5109.  
  5110. modl9:    mov    cx,dx
  5111.     mov    al,' '
  5112.     rep    stosb            ; flesh out with spaces
  5113. modl10:    mov    cx,8            ; blank out terminal id field
  5114.     mov    si,offset mtty        ; assume no terminal emulation
  5115.     mov    di,offset modbuf.m_term ; destination
  5116.     rep    movsb            ; copy it in
  5117.     mov    word ptr modbuf.m_prn,'  '; assume not printing the screen
  5118.     mov    modbuf.m_prn+2,' '
  5119.     test    anspflg,prtscr+2    ; print the screen? (msz uses 1 & 2)
  5120.     jz    modl10a            ; z = no
  5121.     mov    word ptr modbuf.m_prn,'RP' ; yes. display PRN at end of line
  5122.     mov    modbuf.m_prn+2,'N'
  5123. modl10a:mov    modbuf.m_comp,' '    ; flag for not-compose
  5124.     cmp    grab,0            ; doing Compose grabbing?
  5125.     je    modl11            ; e = no
  5126.     mov    modbuf.m_comp,'C'    ; flag for compose
  5127. modl11:    cmp    inemulator,0        ; in terminal emulator now?
  5128.     jne    modl11a            ; ne = yes
  5129.     pop    es            ; do nothing
  5130.     pop    di
  5131.     pop    si
  5132.     ret
  5133. modl11a:push    dx
  5134.     cmp    flags.vtflg,0        ; emulating?
  5135.     je    modl12            ; e = no
  5136.     and    yflags,not modoff    ; update local flags (mode line on)
  5137.     call    fansdsl            ; get extras from emulator
  5138. modl12:    mov    dx,offset modbuf    ; mode line image ptr for putmod
  5139.     call    putmod            ; display mode line
  5140.     mov    dx,cursor        ; restore active cursor position
  5141.     call    fsetpos            ; set cursor
  5142.     pop    dx
  5143.     pop    es
  5144.     pop    di
  5145.     pop    si
  5146.     ret
  5147. modlin    endp
  5148.  
  5149. fmodlin    proc    far
  5150.     call    modlin
  5151.     ret
  5152. fmodlin    endp
  5153.  
  5154. ; toggle between text and graphics modes
  5155. vtans52 proc    near
  5156.     cmp    flags.vtflg,0        ; emulating?
  5157.     je    vtans52a        ; e = no
  5158.     call    ans52t            ; call MSZ toggle-it routine
  5159.     cmp    flags.vtflg,tttek    ; Tek now?
  5160.     je    vtans52a        ; e = yes
  5161.     test    tekflg,tek_tek+tek_dec+TEK_SG     ; Tek submode?
  5162.     jnz    vtans52a        ; nz = yes
  5163.     call    scrini            ; check on screen size changes
  5164. vtans52a:clc                ; clear c bit so don't exit Connect
  5165.     ret
  5166. vtans52 endp
  5167.  
  5168. ftrnprs proc    far
  5169.     call    trnprs
  5170.     ret
  5171. ftrnprs    endp
  5172.  
  5173. trnprs    proc    near
  5174.     push    ax            ; toggle ^ PrtSc screen to printer
  5175.     test    anspflg,prtscr        ; are we currently printing?
  5176.     jnz    trnpr2            ; nz = yes, its on and going off
  5177.     push    bx
  5178.     mov    bx,prnhand        ; file handle for system printer
  5179.     mov    ah,ioctl
  5180.     mov    al,7            ; get output status of printer
  5181.     int    dos
  5182.     pop    bx
  5183.     jc    trnpr1            ; c = printer not ready
  5184.     cmp    al,0ffh            ; Ready status?
  5185.     je    trnpr2            ; e = Ready    
  5186. trnpr1:    call    fvtbell            ; Not Ready, complain
  5187. ;    pop    ax
  5188. ;    stc                ; say failure
  5189. ;    ret                ; and ignore request
  5190. trnpr2:    xor    anspflg,prtscr        ; flip the flag
  5191.     test    yflags,modoff        ; mode line off?
  5192.     jnz    trnpr3            ; nz = yes
  5193.     call    fmodlin            ; else rewrite mode line
  5194. trnpr3:    pop    ax
  5195.     clc                ; return carry clear (don't quit)
  5196.     ret
  5197. trnprs    endp
  5198. code    ends
  5199.  
  5200. code1    segment
  5201.     assume    cs:code1
  5202.  
  5203. pntdead    proc    near            ; display printer is inoperative msg
  5204.     push    ax
  5205.     test    yflags,modoff        ; is mode line off?
  5206.     jnz    pntdea1            ; nz = off, skip msg
  5207.     push    bx
  5208.     mov    dx,offset pntmsg    ; say printer not ready
  5209.     call    fputmod            ; write on mode line
  5210.     pop    bx
  5211. pntdea1:pop    ax
  5212.     stc                ; say printer not ready
  5213.     ret
  5214. pntdead    endp
  5215.  
  5216. endif    ; no_terminal
  5217.  
  5218. ;;;;; General screen management routines for IBM PC
  5219.  
  5220. ; computes screen location to ax, given row and col in [dh,dl], resp.
  5221.  
  5222. scrloc    proc    near
  5223.     push    cx
  5224.     mov    cl,crt_cols
  5225.     cmp    inemulator,0        ; emulating?
  5226.     je    scrloc1            ; e = no
  5227.     cmp    flags.vtflg,0        ; emulating anything?
  5228.     je    scrloc1            ; e = no
  5229.     mov    cl,vswidth
  5230. scrloc1:mov    al,dh            ; get row
  5231.     mul    cl            ; multiply by number of columns
  5232.     add    al,dl            ; plus current column number
  5233.     adc    ah,0            ; ripple carry
  5234.     shl    ax,1            ; double for attributes
  5235.     pop    cx
  5236.     ret
  5237. scrloc    endp
  5238.  
  5239. ; Routine to set cursor type.  Pass cursor type in al: 0,4 = No cursor,
  5240. ; 1 = Underline cursor, 2 = Block cursor.   All cursors blink due to hardware.
  5241. ; For EGA boards running in non-25 line mode the cursor emulation is turned
  5242. ; off during cursor shape changing and restored afterward. It's another
  5243. ; ega Feature. [jrd]
  5244. ; Sense crt_mode 18h as Tseng Labs UltraPAK mono board in 132 column mode.
  5245. csrtype proc    near
  5246.     push    cx            ; save the reg
  5247.     mov    cx,0F00H        ; assume no cursor
  5248.     test    al,4            ; no cursor?
  5249.     jz    csrtyp6            ; z = no
  5250.     xor    al,al            ; set type to invisible
  5251. csrtyp6:or    al,al            ; no cursor?
  5252.     jz    csrty2            ; z = yes, no cursor
  5253.     cmp    crt_mode,7        ; B&W card?
  5254.     je    csrty3            ; e = yes, different sizes
  5255.     cmp    crt_mode,18h        ; Tseng UltraPAK mono board?
  5256.      je    csrty3            ; e = yes, use mono cursor
  5257.     mov    cx,0607H        ; use CGA underline cursor
  5258.     cmp    al,2            ; Block?
  5259.     jne    csrty2            ; ne = no, set it now
  5260. csrty1: xor    ch,ch            ; make cursor a block
  5261. csrty2:    cmp    ega_mode,0        ; ega board active?
  5262.     je    csrty4            ; e = no
  5263.     test    tv_mode,10h        ; DV active?
  5264.     jnz    csrty4            ; nz = yes, it messes with the cursor
  5265.     cmp    byte ptr low_rgt+1,23    ; standard screen length?
  5266.     je    csrty4            ; e = yes, use regular cursor setting
  5267.     cmp    byte ptr low_rgt+1,24    ; ANSI, standard screen length?
  5268.     je    csrty4            ; e = yes, use regular cursor setting
  5269.     push    es            ; EGA. turn off cursor emulation
  5270.     mov    ax,40h            ; 40:87h is ega Info byte
  5271.     mov    es,ax
  5272.     push    es:[87h]        ; save Info byte around call
  5273.     or    byte ptr es:[87h],1    ; set emulation off (low bit = 1)
  5274.     mov    ah,1            ; video function for set cursor type
  5275.     int    screen
  5276.     pop    es:[87h]        ; restore Info byte
  5277.     pop    es            ;  and our work register
  5278.     pop    cx
  5279.     ret
  5280.  
  5281. csrty4:    push    ax
  5282.     mov    ah,1            ; video function for set cursor type
  5283.     int    screen            ; regular cursor shape setting
  5284.     pop    ax
  5285. csrty5:    pop    cx
  5286.     ret
  5287.  
  5288. csrty3: mov    cx,0B0CH        ; assume B&W underline cursor
  5289.     cmp    al,2            ; Block?
  5290.     jne    csrty2            ; ne = no, set it now
  5291.     jmp    short csrty1        ; make it a block
  5292. csrtype endp
  5293.  
  5294. fcsrtype proc    far
  5295.     call    csrtype
  5296.     ret
  5297. fcsrtype endp
  5298.  
  5299. ; Get CRT mode - returns mode in variable crt_mode,
  5300. ; updates crt_cols, and low_rgt.
  5301. ; For EGA active it looks in Bios work memory 40:84H for number of rows
  5302. scrmod    proc    near
  5303.     push    ax
  5304.     push    dx
  5305.     mov    ah,0fh            ; get current video state
  5306.     int    screen
  5307.     and    al,not 80h        ; strip "preserve regen" bit 80h
  5308.     mov    crt_mode,al        ; store CRT mode value
  5309.     mov    crt_cols,ah        ; store # of cols
  5310.     mov    dl,ah            ; # of cols again
  5311.     mov    dh,crt_lins        ; and # of rows (constant from msster)
  5312.     cmp    tv_mode,0        ; Topview active?
  5313.     je    scrmod2            ; e = no
  5314.     test    tv_mode,20h        ; Japanese DOS active?
  5315.     jnz    scrmod2            ; nz = yes, do not do Int 15h
  5316.     push    cx
  5317.     push    bx
  5318.     mov    ah,12h            ; TV, Get Object Length
  5319.     mov    bx,0901h        ; object, BL = 01 = chars/line
  5320.     int    15h
  5321.     pop    ax            ; chars/line from stack dword
  5322.     cmp    al,10            ; keep things sane, chars per line
  5323.     ja    scrmod7            ; a = might be sane
  5324.     pop    ax            ; clean stack
  5325.     jmp    scrmod2            ; wacko, ignore DV stuff
  5326.  
  5327. scrmod7:mov    crt_cols,al        ; TV windowed screen columns
  5328.     pop    ax            ; clear rest of dword from stack
  5329.     mov    ah,12h            ; send
  5330.     mov    bx,1            ; handle (0*256) + window (me, 1)
  5331.     int    15h
  5332.     pop    bx            ; handle low word
  5333.     pop    bx            ; handle high word to BX for next call
  5334.     mov    ax,1024h        ; TV Get Virtual Screen Info
  5335.     int    15h            ; can yield 8KB, yikes
  5336. scrmod1:cmp    cx,80*25*2        ; get sanity for DV big DOS window
  5337.     jbe    scrmod1a        ; be = reasonable size
  5338.     shr    cx,1            ; reduce size
  5339.     jmp    short scrmod1        ;  and try again
  5340. scrmod1a:mov    ax,cx            ; CX is virtual screen size, bytes
  5341.     mov    bl,crt_cols        ; divide by columns to get width
  5342.     shl    bl,1            ; get words (char and attribute)
  5343.     div    bl            ; al = lines, ah = fractions of line
  5344.     dec    al            ; count this from zero like the Bios
  5345.     mov    crt_lins,al        ; visible screen lines -1 (24)
  5346.     mov    dh,al
  5347.     mov    dl,crt_cols        ; visible screen columns (80)
  5348.     pop    bx
  5349.     pop    cx
  5350.     jmp    short scrmod4
  5351.  
  5352. scrmod2:cmp    ega_mode,0        ; ega active?
  5353.     je    scrmod4            ; e = no
  5354.     push    es            ; yes, permit different lengths
  5355.     mov    ax,40h            ; refer to 40:84h for # ega rows
  5356.     mov    es,ax
  5357.     mov    ah,es:[84h]        ; get number of rows - 1 (typ 24)
  5358.     cmp    ah,20            ; less than 20 rows?
  5359.     jb    scrmod3            ; b = yes, ignore this length
  5360.     cmp    ah,80            ; more than 80 rows?
  5361.     ja    scrmod3            ; a = yes, ignore this length
  5362.     mov    dh,ah            ; use this length
  5363.     mov    dos_bottom,dh        ; remember for DOS screen pager
  5364. ifndef    no_terminal
  5365.     cmp    flags.vtflg,ttansi    ; ANSI?
  5366.     jne    scrmod2b        ; ne = no
  5367.     inc    dh            ; make mode line a regular text line
  5368.     mov    flags.modflg,2        ; mode line enabled and owned by host
  5369. scrmod2b:cmp    isps55,0        ; [HF]940206 is Japanese PS/55 ?
  5370.     je    scrmo2a            ; [HF]940206 e = no
  5371.     cmp    ps55mod,0        ; [HF]940206 can we use modeline?
  5372.     jne    scrmo2a            ; [HF]940206 ne = yes
  5373.     inc    dh            ; [HF]940206 no, add modeline
  5374. endif    ; no_terminal
  5375. scrmo2a:mov    crt_lins,dh        ; update our working constant
  5376. scrmod3:pop    es
  5377. scrmod4:dec    dl            ; max text column, count from zero
  5378.     dec    dh            ; max text row, count from zero
  5379. ifndef    no_terminal
  5380.     cmp    flags.vtflg,ttgenrc    ; no terminal emulation
  5381.     je    scrmod6            ; e = yes
  5382.     cmp    tekflg,tek_active+tek_sg ; doing special graphics?
  5383.     jne    scrmod4a        ; ne = no
  5384.     mov    crt_cols,128        ; VT style special graphics uses this
  5385. scrmod4a:
  5386.     cmp    crt_cols,80        ; doing wide now?
  5387.     ja    scrmod5            ; a = yes
  5388.     mov    dl,80-1            ; assume 80 column width
  5389.     test    vtemu.vtflgop,deccol    ; 132 column mode set?
  5390.     jz    scrmod6            ; z = no
  5391. scrmod5:mov    dl,132-1        ; set to 132 column mode
  5392.  
  5393. endif    ; no_terminal
  5394.  
  5395. scrmod6:mov    low_rgt,dx        ; save away window address
  5396.     pop    dx
  5397.     pop    ax
  5398.     ret
  5399. scrmod    endp
  5400.  
  5401. ; Get screen segment. Returns screen segment in ax, and full address in es:di
  5402. scrseg    proc    near
  5403.     xor    di,di            ; start at beginning of screen (0,0)
  5404.     mov    ax,0B800H        ; video memory is here on color
  5405.     cmp    crt_mode,7        ; normal color modes?
  5406.     jb    scrse1            ; b = yes
  5407.     mov    ax,0B000H        ; assume B&W card
  5408.     cmp    crt_mode,12        ; 
  5409.     jb    scrse1
  5410.     cmp    crt_mode,18h        ; Tseng UltraPAK mono in 132 col?
  5411.     je    scrse1            ; e = yes, use seg B000H
  5412.     cmp    crt_mode,56h        ; Paradise EGA Mono in 132x43 mode?
  5413.     je     scrse1            ; e = yes, use seg B000H
  5414.     cmp    crt_mode,57h        ; Paradise EGA Mono in 132x25 mode?
  5415.     je    scrse1            ; e = yes, use seg B000H
  5416.     mov    ax,0B800H        ; video memory is here on color
  5417.     cmp    crt_mode,18        ; end of ordinary 640x480 graphics
  5418.     ja    scrse1            ; a = no, assume CGA segment
  5419.     mov    ax,0A000H        ; graphics
  5420. scrse1:    mov    es,ax        ; tell Topview our hardware address needs
  5421.     mov    tv_segs,es        ; save our hardware screen address
  5422.     mov    tv_sego,di        ; segment and offset form
  5423.     or    tv_mode,1        ; assume we're running under Topview
  5424.     mov    ah,tvhere        ; query Topview for its presence
  5425.     int    screen
  5426.     mov    ax,es            ; get its new segment for screen work
  5427.     cmp    ax,tv_segs        ; same as hardware?
  5428.     jne    scrse2            ; ne = no, we are being mapped
  5429.     cmp    di,tv_sego        ; check this too
  5430.     jne    scrse2        ; ne = no too. Use TV's work buf as screen
  5431.     and    tv_mode,not 1        ; else no Topview or no mapping
  5432. scrse2:    mov    tv_segs,es        ; save segment
  5433.     mov    tv_sego,di        ; and offset
  5434.     ret
  5435. scrseg    endp
  5436.  
  5437. ; Synchronize a Topview provided virtual screen buffer with the image
  5438. ; seen by the user. Requires cx = number of words written to screen
  5439. ; (char & attribute bytes) and es:di = ENDING address of screen write.
  5440. ; Changes ax and di. Skip operations for DESQview
  5441. scrsync proc    near
  5442.     cmp    tv_mode,0        ; Topview mode active?
  5443.     je    scrsyn1            ; e = no, skip Bios call below
  5444.     push    ax
  5445.     push    cx
  5446.     push    di
  5447.     sub    di,cx            ; backup to start byte (cx = words)
  5448.     sub    di,cx            ;  after storing words to screen
  5449.     mov    ah,tvsynch        ; tell Topview we have changed screen
  5450.     int    screen            ;  so user sees updated screen
  5451.     pop    di
  5452.     pop    cx
  5453.     pop    ax
  5454. scrsyn1:ret
  5455. scrsync endp
  5456.  
  5457. ; The following two routines are used to turn off the display while we
  5458. ; are reading or writing the screen in one of the color card modes.
  5459. ; Turn screen off for (known) color card modes only. All regs preserved.
  5460. ; Includes code for old procedure scrwait. 16 June 1987 [jrd]
  5461. scroff    proc    near
  5462.     cmp    ega_mode,0        ; Extended Graphics Adapter in use?
  5463.     jne    scrofx            ; ne = yes, no waiting
  5464.     cmp    tv_mode,0        ; Topview mode?
  5465.     jne    scrofx            ; ne = yes, no waiting
  5466.     cmp    crt_mode,7        ; B&W card?
  5467.     jnb    scrofx            ; nb = yes - just return
  5468.     cmp    refresh,0        ; slow refresh?
  5469.     jne    scrofx            ; ne = no wait
  5470.     push    ax            ; save ax and dx
  5471.     push    dx
  5472.     mov    dx,crt_status        ; CGA: Wait for vertical retrace
  5473. scrof1:    in    al,dx
  5474.     test    al,disp_enb        ; display enabled?
  5475.     jnz    scrof1            ; yes, keep waiting
  5476. scrof2:    in    al,dx
  5477.     test    al,disp_enb        ; now wait for it to go off
  5478.     jz    scrof2            ; so can have whole cycle
  5479.     mov    dx,crtmset        ; output to CRT mode set port
  5480.     mov    al,25H            ; this shuts down the display
  5481.     out    dx,al
  5482.     pop    dx            ; restore regs
  5483.     pop    ax
  5484. scrofx: ret
  5485. scroff    endp
  5486.  
  5487.  
  5488. ; Turn screen on for (known) color card modes only
  5489. ; All registers are preserved.
  5490.  
  5491. scron    proc    near
  5492.     cmp    ega_mode,0        ; Extended Graphics Adapter in use?
  5493.     jne    scronx            ; ne = yes, no waiting
  5494.     cmp    tv_mode,0        ; Topview mode?
  5495.     jne    scronx            ; ne = yes, no waiting
  5496.     cmp    crt_mode,7        ; B&W card?
  5497.     jnb    scronx            ; nb = yes - just return
  5498.     cmp    refresh,0        ; slow refresh?
  5499.     jne    scronx            ; ne = no wait
  5500.     push    ax            ; save ax, dx, and si
  5501.     push    dx
  5502.     push    si
  5503.     mov    al,crt_mode        ; convert crt_mode to a word
  5504.     xor    ah,ah
  5505.     mov    si,ax            ; get it in a usable register
  5506.     mov    al,msets[si]        ; fetch the modeset byte
  5507.     mov    dx,crtmset        ; this port
  5508.     out    dx,al            ; flash it back on
  5509.     pop    si
  5510.     pop    dx
  5511.     pop    ax
  5512. scronx: ret
  5513. scron    endp
  5514.  
  5515. ifndef    no_terminal
  5516. ; Determine screen roll back buffer parameters depending on current screen
  5517. ; dimensions and available memory. Each rollback screen line has its own
  5518. ; segment (lines start on segment boundaries for rollback). One full screen
  5519. ; must be allocated to hold the current display, deduct this from lmax.
  5520.  
  5521. bufadj    proc    near
  5522.     push    bx
  5523.     push    cx
  5524.     push    dx
  5525.     mov    bx,rollwidth        ; rollback line width
  5526.     add    bx,7            ; (BDT) round up to paragraph boundary
  5527.     mov    cl,3            ; (BDT) now convert to
  5528.     shr    bx,cl            ; (BDT) paragraphs / line
  5529.     mov    ppl,bx            ; (BDT) save this in buffer area
  5530.     xor    dx,dx            ; high order dividend, clear it
  5531.     cmp    emsrbhandle,0        ; using EMS?
  5532.     jle    bufadj2            ; le = no (-1 means not used)
  5533.     mov    ax,1024            ; 1024 paragraphs per ems 16KB page
  5534.     div    bx            ; divide by paragraphs per line
  5535.     mov    lineems,ax        ; lines per ems page, remember
  5536.     mul    inipara            ; times number of ems pages
  5537.     jmp    short bufadj3        ; ax has number of lines
  5538.                     ; conventional memory
  5539. bufadj2:mov    ax,inipara        ; (BDT) compute the number of lines
  5540.     div    bx            ; (BDT)  in the buffer
  5541.  
  5542. bufadj3:mov    lmax,ax            ; max line capacity of the buffer
  5543.     mov    linee,ax        ; (BDT) save as number of total lines
  5544.     or    ax,ax            ; have any lines?
  5545.     jz    bufadj1            ; z = no, no space at all
  5546.     xor    bh,bh            ; (BDT) get lines / screen
  5547.     mov    bl,byte ptr low_rgt+1    ; (BDT) rows on user/host screen
  5548.     inc    bx            ; (BDT) adjust for counting from 0
  5549.     sub    lmax,bx            ; minus master "current" screen
  5550.     jg    bufadj1            ; g = have some rollback space
  5551.     mov    lmax,0            ; say none
  5552. bufadj1:mov     lcnt,0                  ; (BDT) # of lines filled in buffer
  5553.     mov    linef,0            ; (BDT) first filled in line
  5554.     mov    linec,0            ; (BDT) last  filled in line
  5555.     pop    dx
  5556.     pop    cx
  5557.     pop    bx
  5558.     ret
  5559. bufadj    endp
  5560. endif    ; no_terminal
  5561.  
  5562. ; Test for DESQview in operation, set tv_mode bit 10h to non-zero if so.
  5563. dvtest    proc    near
  5564.     and    tv_mode,not 30h        ; assume no DV and no Japanese DOS
  5565. ifndef    no_terminal
  5566.     cmp    isps55,0        ; [HF] 940130 Japanese PS/55 ?
  5567.     je    dvtest4            ; [HF] 940130 no
  5568.     or    tv_mode,30h        ; [HF] 940205 say Japanese & DV
  5569.     ret                ; [HF]  do not use Int 15h for Japan
  5570. endif    ; no_terminal
  5571. dvtest4:xor    bx,bx            ; for version number
  5572.     mov    cx,'DE'            ; DV signature
  5573.     mov    dx,'SQ'
  5574.     mov    ax,2B01h        ; DOS set date (with illegal value)
  5575.     int    dos
  5576.     cmp    al,0ffh            ; DOS should say invalid if no DV
  5577.     je    dvtest2            ; e = yes, invalid so no DV
  5578.     cmp    bx,2            ; DV version 2.00?
  5579.     jne    dvtest1            ; ne = no
  5580.     xchg    bh,bl            ; get major version into bh
  5581. dvtest1:or    tv_mode,10h        ; say using DV
  5582. dvtest2:ret
  5583. dvtest    endp
  5584.  
  5585. ; Execute DESQview function call provided in BX.
  5586. dvcall    proc    near
  5587.     push    ax
  5588.     mov    ax,101ah        ; switch to DV stack
  5589.     int    15h
  5590.     mov    ax,bx            ; function to do
  5591.     int    15h
  5592.     mov    ax,1025h        ; switch from DV stack
  5593.     int    15h
  5594.     pop    ax
  5595.     ret
  5596. dvcall    endp
  5597.  
  5598. ; Call this to release the cpu during idle times
  5599. dvpause    proc    near
  5600.     cmp    vtcpumode,0        ; timeslice-release enabled?
  5601.     jne    dvpaus2            ; ne = no
  5602.     test    tv_mode,10h        ; in DV?
  5603.     jz    dvpaus1            ; z = no
  5604.     push    bx
  5605.     mov    bx,1000h        ; say release control
  5606.     call    dvcall            ; to DV
  5607.     pop    bx
  5608. dvpaus1:cmp    byte ptr dosnum+1,5    ; DOS verson, major high, minor low
  5609.     jb    dvpaus2            ; b = too old for this operation
  5610.     mov    ax,1680h        ; release current virtual machine
  5611.     int    2fh            ;  time slice (Windows, OS/2, DPMI)
  5612. dvpaus2:ret
  5613. dvpause    endp
  5614.  
  5615. ; Screen clearing routine
  5616. ; Call:    ax = coordinates of first screen location to be cleared.
  5617. ;    bx = coordinates of last location to be cleared.
  5618. ; Coord: ah = row [0-24], al = column [0-206]. Preserves all registers.
  5619.  
  5620. atsclr    proc    near
  5621.     cmp    ax,bx            ; correct order?
  5622.     jbe    atsclr9            ; be = yes
  5623.     xchg    ax,bx            ; larger to bx
  5624. atsclr9:push    ax            ; save regs 
  5625.     push    cx
  5626.     push    dx
  5627.     mov    dx,bx            ; compute last screen offset from bx
  5628.     push    ax
  5629.     call    scrloc            ; get screen start address in ax
  5630.     mov    cx,ax            ; save it in cx for a minute
  5631.     pop    dx            ; compute first screen offset in ax
  5632.     call    scrloc
  5633.     sub    cx,ax            ; compute number of locs to clear
  5634.     add    cx,2            ; +1 for span, +1 for round up
  5635.     sar    cx,1            ; make byte count a word count
  5636.     jle    atscl3            ; le = nothing to clear
  5637.     push    di            ; save regs
  5638.     push    es            ; save es
  5639. ifndef    no_terminal
  5640.     cmp    inemulator,0        ; in terminal emulator now?
  5641.     je    atscl1            ; e = no
  5642.     cmp    flags.vtflg,0        ; emulating anything?
  5643.     je    atscl1            ; e = no, using DOS
  5644.     les    di,vs_ptr        ; es:di is virtual screen
  5645.     jmp    short atscl2
  5646. endif    ; no_terminal
  5647. atscl1:    push    ax            ; save displacement
  5648.     call    scroff            ; turn screen off if color card
  5649.     call    scrseg            ; get address of screen into es:di
  5650.     pop    ax
  5651. atscl2:    add    di,ax            ; location in buffer
  5652.     mov    ah,scbattr        ; use current screen background attr
  5653.     mov    al,' '            ; use space for fill
  5654.     push    cx            ; save word count for Topview
  5655.     cld
  5656.     rep    stosw            ; copy to screen
  5657.     pop    cx            ; recover word count
  5658. ifndef    no_terminal
  5659.     cmp    inemulator,0        ; in terminal emulator now?
  5660.     je    atscl2a            ; e = no
  5661.     cmp    flags.vtflg,0        ; emulating anything?
  5662.     jne    atscl2b            ; ne = yes
  5663. endif    ; no_terminal
  5664. atscl2a:call    scron            ; turn screen back on if color card
  5665.     call    scrsync            ; synch Topview
  5666. atscl2b:pop    es
  5667.     pop    di
  5668. atscl3:    pop    dx
  5669.     pop    cx
  5670.     pop    ax            ; back to regs at call time
  5671. ifndef    no_terminal
  5672.     cmp    inemulator,0        ; in terminal emulator now?
  5673.     je    atscl6            ; e = no
  5674.     cmp    flags.vtflg,0        ; emulating anything?
  5675.     je    atscl6            ; e = no, using DOS
  5676.     push    dx            ; do extended attributes
  5677.     push    ax
  5678.     push    bx
  5679.     push    cx
  5680.     mov    dx,ax            ; starting place
  5681.     mov    al,dh            ; row
  5682.     mov    cl,vswidth        ; row char cells
  5683.     mul    cl
  5684.     add    al,dl            ; plus starting column
  5685.     adc    ah,0            ; char cells to starting place
  5686.     mov    dx,ax            ; save here
  5687.     mov    al,bh            ; ending row
  5688.     mul    cl
  5689.     add    al,bl            ; plus ending column
  5690.     adc    ah,0
  5691.     mov    bx,ax
  5692.     sub    bx,dx            ; number of cells -1 to clear
  5693.     inc    bx
  5694.     mov    cx,bx            ; cx = cells to clear
  5695.     xchg    bx,dx            ; bx = start offset, dx=cells
  5696.     push    es
  5697.     push    di
  5698.     les    di,vsat_ptr        ; where attributes are stored
  5699.     add    di,bx            ; offset plus start byte
  5700.     xor    ax,ax
  5701.     cld
  5702.     shr    cx,1
  5703.     jnc    atscl4
  5704.     stosb
  5705. atscl4:    rep    stosw            ; clear those bytes
  5706. ;;;    mov    extattr,0        ; and the extension byte too
  5707.     pop    di
  5708.     pop    es
  5709.     pop    cx
  5710.     pop    bx
  5711.     pop    ax
  5712.     mov    dl,ah            ; first row
  5713.     mov    dh,bh            ; last row
  5714.     call    touchup            ; repaint this part of the screen
  5715.     pop    dx            ; finish cleaning stack
  5716. endif    ; no_terminal
  5717. atscl6:    ret
  5718. atsclr    endp
  5719.  
  5720. ifndef    no_terminal
  5721. ; Screen-scrolling routines.
  5722.      
  5723. fhomwnd    proc    far            ; "home" to start of the buffer
  5724.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5725.     inc    cl            ; full text screen
  5726.     xor    ch,ch
  5727.     call    putcirc            ; save them
  5728.     mov    linec,0            ; reset the current pointer
  5729.     call    getcirc            ; now get the new screen
  5730.     clc
  5731.     ret
  5732. fhomwnd    endp
  5733.      
  5734. fendwnd    proc    far            ; "end" to end of the buffer
  5735.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5736.     inc    cl            ; full text screen
  5737.     xor    ch,ch
  5738.     call    putcirc            ; save them
  5739.     mov    ax,lcnt            ; reset the current pointer
  5740.     mov    linec,ax        ; save the results
  5741.     call    getcirc            ; now get the new screen
  5742.     clc
  5743.     ret
  5744. fendwnd    endp
  5745.      
  5746. fdnwpg    proc    far            ; scroll down 1 page
  5747.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5748.     inc    cl            ; full text screen
  5749.     xor    ch,ch
  5750.     call    putcirc            ; save them
  5751.     mov    ax,linec        ; reset the current pointer
  5752.     add    ax,cx
  5753.     cmp    ax,lcnt            ; did we go past the end?
  5754.     jbe    dnwpg1            ; be = no, we're OK
  5755.     mov    ax,lcnt            ; yup, back up
  5756. dnwpg1:    mov    linec,ax        ; save the results
  5757.     call    getcirc            ; now get the new screen
  5758.     clc
  5759.     ret
  5760. fdnwpg    endp
  5761.      
  5762. fdnone    proc    far            ; scroll down 1 line
  5763.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5764.     inc    cl            ; full text screen
  5765.     xor    ch,ch
  5766.     call    putcirc            ; save them
  5767.     mov    ax,linec        ; reset the current pointer
  5768.     inc    ax            ;  to the next line
  5769.     cmp    ax,lcnt            ; oops, did we go past the end?
  5770.     jbe    dnone1            ; be = no, we're OK
  5771.     mov    ax,lcnt            ; yup, back up
  5772. dnone1:    mov    linec,ax        ; save the results
  5773.     call    getcirc            ; now get the new screen
  5774.     clc
  5775.     ret
  5776. fdnone    endp
  5777.      
  5778. fupwpg    proc    far            ; scroll up 1 page
  5779.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5780.     inc    cl            ; full text screen
  5781.     xor    ch,ch
  5782.     call    putcirc            ; save a full screen
  5783.     mov    ax,linec        ; reset the current pointer
  5784.     sub    ax,cx            ;  to the previous page
  5785.     jge    upwpg1            ; ge = not past end, we're OK
  5786.     xor    ax,ax            ; stop at the beginning of the buffer
  5787. upwpg1:    mov    linec,ax        ; line counter to use
  5788.     call    getcirc            ; get the new screen
  5789.     clc
  5790.     ret
  5791. fupwpg    endp
  5792.      
  5793. fupone    proc    far            ; scroll up 1 line
  5794.     mov    cl,byte ptr low_rgt+1    ; save this many lines
  5795.     inc    cl            ; full text screen
  5796.     xor    ch,ch
  5797.     call    putcirc            ; save them
  5798.     mov    ax,linec        ; reset the current pointer
  5799.     sub    ax,1            ;  to the previous line
  5800.     jge    upone1            ; ge = not past end, we're OK
  5801.     xor    ax,ax            ; yup, back up
  5802. upone1:    mov    linec,ax        ; save the results
  5803.     call    getcirc            ; now get the new screen
  5804.     clc
  5805.     ret
  5806. fupone    endp
  5807.  
  5808. ; Horizontal scrolling keyboard verbs
  5809. frtpage    proc    far
  5810.     mov    cx,20            ; step size
  5811.     call    rtcommon
  5812.     ret
  5813. frtpage    endp
  5814.  
  5815. frtone    proc    far
  5816.     mov    cx,1
  5817.     call    rtcommon
  5818.     ret
  5819. frtone    endp
  5820.  
  5821. ; Move screen to the right margin by CX columns
  5822. rtcommon proc    near
  5823.     push    bx
  5824.     mov    bl,byte ptr cursor+1    ; current cursor row
  5825.     xor    bh,bh
  5826.     mov    al,linescroll[bx]    ; horz scroll in effect for this line
  5827.     pop    bx
  5828.     add    al,handhsc         ; plus hand scrolling now present
  5829.     add    al,crt_cols        ; right most char on visible screen
  5830.     adc    ah,0
  5831.     cmp    ax,vswidth        ; too far already?
  5832.     ja    rtcomm2            ; a = yes, do nothing
  5833.     sub    ax,vswidth        ; available distance
  5834.     neg    ax
  5835.     cmp    ax,cx            ; space vs desired scroll
  5836.     jbe    rtcomm1            ; be = less than desired, use space
  5837.     mov    ax,cx            ; enough room, use desired scroll
  5838. rtcomm1:add    handhsc,al        ; indicate how much done by hand
  5839.     call    repaint
  5840. rtcomm2:clc
  5841.     ret
  5842. rtcommon endp
  5843.  
  5844. flfpage    proc    far
  5845.     mov    cx,20            ; step size
  5846.     call    lfcommon
  5847.     ret
  5848. flfpage    endp
  5849.  
  5850. flfone    proc    far
  5851.     mov    cx,1            ; step size
  5852.     call    lfcommon
  5853.     ret
  5854. flfone    endp
  5855.  
  5856. ; Move screen toward left margin by CX columns
  5857. lfcommon proc    near
  5858.     push    bx
  5859.     mov    bl,byte ptr cursor+1    ; current cursor row
  5860.     xor    bh,bh
  5861.     mov    al,linescroll[bx]    ; horz scroll in effect for this line
  5862.     pop    bx
  5863.     add    al,handhsc        ; available distance to move
  5864.     jz    lfcomm2            ; z = no space to move
  5865.     sub    al,cl            ; minus our desired jump
  5866.     jge    lfcomm1            ; ge = no overscroll the wrong way
  5867.     add    cl,al            ; reduce cx request by overage
  5868. lfcomm1:sub    handhsc,cl        ; successful, new handhsc
  5869.     call    repaint
  5870. lfcomm2:clc
  5871.     ret
  5872. lfcommon endp
  5873.  
  5874. ; Scrolling routines.  vtscru scrolls up, vtscrd scrolls down 'scroll'
  5875. ; rows. Top lines are saved in the circular buffer before scrolling up.
  5876. ; When running under an Environment control number of line positions moved
  5877. ; to be less than scrolling region.
  5878. ; All registers are preserved.
  5879. ;
  5880. ; Screen scroll up "scroll" lines (text moves up) for terminal emulator use.
  5881.      
  5882. vtscru    proc    near
  5883.     push    ax
  5884.     push    bx
  5885.     push    cx
  5886.     push    dx
  5887.     push    si
  5888.     push    di
  5889.     mov    al,mar_bot        ; compute size of scroll
  5890.     sub    al,mar_top
  5891.     inc    al            ; lines in scrolling region
  5892.     mov    dl,scroll        ; desired scroll
  5893.     xor    dh,dh
  5894.     cmp    dl,al            ; scrolling more than needed?
  5895.     jbe    vtscru1            ; be = no
  5896.     mov    dl,al            ; limit scrolling
  5897.     mov    scroll,al
  5898. vtscru1:or    dl,dl
  5899.     jnz    vtscru2    
  5900.     jmp    vtscru9            ; z = nothing to do
  5901.  
  5902. vtscru2:cmp    mar_top,0        ; scrolling the top screen line?
  5903.     jne    vtscru5            ; ne = no, do not save in roll back
  5904.     mov    cx,dx            ; cx is how many lines
  5905.     call    putcirc            ; put screen lines in circular buffer
  5906.     
  5907.     add    linec,cx        ; (BDT) increment the current line
  5908.     mov    cx,linec        ; new current line number
  5909.     sub    cx,lcnt            ; minus # in buf = qty new lines added
  5910.     jc    vtscru3            ; c = not extending buffer
  5911.     add    lcnt,cx            ; (BDT) increment the line counter
  5912. vtscru3:mov    cx,lcnt            ; (BDT) check: are we
  5913.     cmp    cx,lmax            ; (BDT) beyond the end?
  5914.     jb    vtscru5            ; (BDT) b = no
  5915.     sub    cx,lmax            ; (BDT) compute overflow count
  5916.     add    linef,cx        ; (BDT) adjust the "first" line
  5917.     mov    cx,linef        ; (BDT) check: time to wrap?
  5918.     cmp    cx,linee        ; (BDT) ...
  5919.     jb    vtscru4            ; (BDT) b = no
  5920.     sub    cx,linee        ; (BDT) yup
  5921.     mov    linef,cx        ; (BDT) adjust it
  5922. vtscru4:mov    cx,lmax            ; (BDT) get the maximum line count
  5923.     mov    lcnt,cx            ; (BDT) reset the line counter
  5924.     mov    linec,cx        ; (BDT) reset the current line
  5925.  
  5926. vtscru5:mov    di,word ptr vs_ptr    ; offset of virtual screen
  5927.     mov    cl,vswidth
  5928.     mov    al,mar_top        ; top line number (from 0)
  5929.     mul    cl            ; times chars/line
  5930.     add    ax,ax            ; char + attribute
  5931.     add    di,ax            ; destination (mar_top)
  5932.     mov    al,dl            ; number of lines to scroll
  5933.     mov    cl,vswidth
  5934.     mul    cl            ; vswidth * total lines to scroll
  5935.     mov    bx,ax            ; number of cells to clear
  5936.     add    ax,ax            ; bytes
  5937.     mov    si,di
  5938.     add    si,ax            ; src is that many bytes down screen
  5939.     mov    al,mar_bot        ; lines in scrolling region
  5940.     sub    al,mar_top
  5941.     inc    al
  5942.     sub    al,dl            ; minus scrolled portion
  5943.     mul    cl            ; times words per line
  5944.     mov    cx,ax            ; number of cells to copy
  5945.     mov    dh,scbattr        ; need this for later (in seg data)
  5946.     push    cx            ; save number of words for attribute
  5947.     push    es
  5948.     push    ds
  5949.     mov    ax,word ptr vs_ptr+2    ; segment of vscreen
  5950.     mov    ds,ax
  5951.     mov    es,ax
  5952.     cld
  5953.     rep    movsw            ; copy src to dest
  5954.     mov    cx,bx            ; count of words to clear
  5955.     mov    ah,dh            ; default attriubte
  5956.     mov    al,' '            ; filler for clearing a line
  5957.     rep    stosw            ; store after new src
  5958.     pop    ds
  5959.     pop    es
  5960.                     ; bx is number of words cleared
  5961.     mov    di,word ptr vsat_ptr    ; offset of attributes
  5962.     mov    cl,vswidth        ; char cells per attributes line
  5963.     mov    al,mar_top        ; top line number (from 0)
  5964.     mul    cl            ; times cells per line
  5965.     add    di,ax            ; destination (mar_top)
  5966.     mov    si,di
  5967.  
  5968.     mov    al,dl            ; number of lines to scroll
  5969.     mul    cl            ; vswidth * total lines to scroll
  5970.     mov    bx,ax            ; number of cells to clear
  5971.     add    si,bx            ; src is that many bytes down screen
  5972.     pop    cx            ; number of vscreen cells copied
  5973.     push    es
  5974.     push    ds
  5975.     mov    ax,word ptr vsat_ptr+2    ; segment of vsatt
  5976.     mov    ds,ax
  5977.     mov    es,ax
  5978.     cld
  5979.     rep    movsb            ; copy src to dest
  5980.     mov    cx,bx            ; count of bytes to clear
  5981.     xor    al,al            ; default attributes of none
  5982.     rep    stosb            ; store after new src
  5983.     pop    ds
  5984.     pop    es
  5985.     cmp    writemode,0        ; use direct screen writing?
  5986.     je    vscru5a            ; e = yes
  5987. ifndef    no_graphics
  5988.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  5989.     jne    vscru5b            ; ne = no
  5990. endif    ; no_graphics
  5991.  
  5992. vscru5a:cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  5993.     jne    vtscru8            ; ne = no
  5994. ifndef    no_graphics
  5995.     call    tekremcursor        ; turn off text cursor
  5996. vscru5b:mov    dosetcursor,-1        ; don't turn on automatically
  5997.     mov    al,' '            ; write space
  5998.     mov    ah,scbattr        ; in normal colors
  5999.     xor    dl,dl            ; at mar_top, left margin
  6000.     mov    dh,mar_top        ; to set normal text mode for the
  6001.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6002.     jne    vscru5d            ; ne = no
  6003.     xor    cl,cl            ; no extended attribute
  6004.     call    ttxtchr            ; graphics adapter
  6005. endif    ; no_graphics
  6006.  
  6007. vscru5d:mov    ax,0600h        ; scroll up whole region
  6008.     mov    dh,mar_bot        ; bottom row
  6009.     mov    dl,crt_cols
  6010.     cmp    isps55,0        ; [HF]940216 Japanese PS/55?
  6011.     jne    vscru5e            ; [HF]940216 ne=yes, allowed > 80cols.
  6012.     cmp    dl,80            ; more than physical screen?
  6013.     jbe    vscru5e            ; be = no
  6014.     cmp    dl,131            ; really wide screen
  6015.     jae    vscru5e            ; ae = yes
  6016.     mov    dl,80            ; else 128 col fake text wide screen
  6017. vscru5e:dec    dl            ; right most physical col for scroll
  6018.     mov    ch,mar_top        ; top row of scrolling region
  6019.     xor    cl,cl            ; left most column
  6020.     mov    bh,scbattr        ; attributes
  6021.     mov    bl,dh
  6022.     sub    bl,ch            ; region size - 1 line
  6023.     jz    vscru2b            ; z = region is 1 line, do one scroll
  6024.     mov    al,scroll        ; number of lines to scroll, from msz
  6025. vscru2a:cmp    al,bl            ; want to scroll more that than?
  6026.     jbe    vscru2b            ; be = no
  6027.     push    ax
  6028.     mov    al,bl            ; limit to region - 1 for Windows
  6029.     int    screen            ;  and do in parts
  6030.     pop    ax
  6031.     sub    al,bl            ; al = amount yet to scroll
  6032.     jmp    short vscru2a        ; do next part
  6033. vscru2b:int    screen            ; scroll up that region
  6034.     mov    dx,cursor
  6035.     mov    dosetcursor,dx        ; reminder of where to set cursor
  6036.     jmp    short vtscru9
  6037.  
  6038. vtscru8:mov    dh,mar_bot        ; real text mode
  6039.     mov    dl,mar_top        ; setup touchup, lines changed
  6040.     call    touchup            ; touch up real screen
  6041. vtscru9:pop    di
  6042.     pop    si
  6043.     pop    dx
  6044.     pop    cx
  6045.     pop    bx
  6046.     pop    ax
  6047.     ret
  6048. vtscru    endp
  6049.  
  6050. ; Screen-roll down. Move text down scroll lines, for terminal emulator only.
  6051. vtscrd    proc    near
  6052.     push    ax
  6053.     push    bx
  6054.     push    cx
  6055.     push    dx
  6056.     push    si
  6057.     push    di
  6058.     push    bp
  6059.     push    es
  6060.     les    si,vs_ptr        ; source is top line of virtual screen
  6061.     mov    al,mar_top        ; top margin line (0..)
  6062.     mov    cl,vswidth        ; chars across vscreen
  6063.     mul    cl
  6064.     add    ax,ax            ; words to bytes
  6065.     add    si,ax            ; offset of start of top line
  6066.     mov    bp,si            ; remember top line for later
  6067.     mov    cl,mar_bot        ; compute number of lines to move
  6068.     sub    cl,mar_top
  6069.     inc    cl            ; qty of lines in region
  6070.     mov    ch,scroll
  6071.     cmp    ch,cl            ; want to scroll more than region?
  6072.     jbe    vtscrd1            ; be = no
  6073.     mov    ch,cl            ; set scroll to whole region
  6074.     mov    scroll,ch        ; remember for attributes
  6075. vtscrd1:sub    cl,ch             ; less lines to be skipped
  6076.     mov    bl,ch            ; save effective scroll for below
  6077.     mov    al,vswidth        ; number of character cells
  6078.     mul    cl
  6079.     mov    cx,ax            ; number of words in the movement
  6080.     dec    ax            ; compute to end word
  6081.     add    ax,ax            ; number of bytes
  6082.     add    si,ax            ; go to the end
  6083.     mov    di,si
  6084.     mov    al,vswidth        ; words in a line buffer
  6085.     mul    bl            ; number of chars dest is below src
  6086.     mov    bx,ax            ; save number of chars here for clear
  6087.     add    ax,ax            ; number of bytes (char + attribute)
  6088.     add    di,ax            ; destination offset
  6089.     push    ds
  6090.     mov    ax,es
  6091.     mov    ds,ax
  6092.     std
  6093.     rep    movsw            ; copy down the lines
  6094.     cld
  6095.     pop    ds
  6096.     mov    di,bp            ; fill top line in scrolling region
  6097.     mov    ah,scbattr
  6098.     mov    al,' '
  6099.     mov    cx,bx            ; number of char cells to clear
  6100.     rep    stosw            ; fill top line(s) with spaces
  6101.                     ; do extended attributes the same way
  6102.     les    si,vsat_ptr        ; source of extended attributes
  6103.     mov    al,mar_top        ; top margin line (0..)
  6104.     mov    cl,vswidth        ; attribute cells/line
  6105.     mul    cl
  6106.     add    si,ax            ; offset of start of top line
  6107.     mov    bp,si            ; remember top line for later
  6108.     mov    cl,mar_bot        ; compute number of lines to move
  6109.     sub    cl,mar_top
  6110.     inc    cl            ; qty of lines in region
  6111.     mov    ch,scroll
  6112.     sub    cl,ch             ; less lines to be skipped
  6113.     mov    bl,ch            ; save effective scroll for below
  6114.     mov    al,vswidth        ; number of attribute cells/line
  6115.     mul    cl
  6116.     mov    cx,ax            ; number of bytes in the movement
  6117.     dec    ax            ; compute to end byte
  6118.     add    si,ax            ; go to the end
  6119.     mov    di,si
  6120.     mov    al,vswidth        ; number of attribute cells/line
  6121.     mul    bl            ; number of cells dest is below src
  6122.     mov    bx,ax            ; save number of bytes here for clear
  6123.     add    di,ax            ; destination offset
  6124.     push    ds
  6125.     mov    ax,es
  6126.     mov    ds,ax
  6127.     std
  6128.     rep    movsb            ; copy down the lines
  6129.     cld
  6130.     pop    ds
  6131.     mov    di,bp            ; fill top line in scrolling region
  6132.     xor    al,al            ; null attributes for filler
  6133.     mov    cx,bx            ; number of attributes bytes to clear
  6134.     rep    stosb            ; fill top line(s) with spaces
  6135.     pop    es
  6136.     pop    bp
  6137.     cmp    writemode,0        ; use direct screen writing?
  6138.     je    vscrd1            ; e = yes
  6139.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6140.     jne    vscrd3a            ; ne = no
  6141. vscrd1:
  6142. ifndef    no_graphics
  6143.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6144.     je    vscrd3            ; e = yes
  6145. endif    ; no_graphics
  6146.     mov    dl,mar_top        ; setup touchup, lines changed
  6147.     mov    dh,mar_bot
  6148.     call    touchup            ; touch up real screen
  6149.     jmp    short vscrd8
  6150.  
  6151. ifndef    no_graphics
  6152. vscrd3:    call    tekremcursor        ; turn off text cursor
  6153. endif    ; no_graphics
  6154. vscrd3a:mov    dosetcursor,-1        ; don't turn on automatically
  6155.     mov    al,' '            ; write space
  6156.     mov    ah,scbattr        ; in normal colors
  6157. ifndef    no_graphics
  6158.     xor    dl,dl            ; at mar_bot, left margin
  6159.     mov    dh,mar_bot        ; to set normal text mode for the
  6160.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6161.     jne    vscrd3b            ; ne = no
  6162.     xor    cl,cl            ; no extended attribute
  6163.     call    ttxtchr            ; graphics adapter
  6164. endif    ; no_graphics
  6165. vscrd3b:mov    ax,0700h        ; scroll down whole region
  6166.     mov    ch,mar_top        ; top margin line
  6167.     xor    cl,cl            ; left most column
  6168.     mov    dh,mar_bot        ; bottom margin line
  6169.     mov    dl,crt_cols
  6170.     cmp    isps55,0        ; [HF]940216 Japanese PS/55
  6171.     jne    vscrd3c            ; [HF]940216 ne=yes, allowed > 80 cols
  6172.     cmp    dl,80            ; more than physical screen?
  6173.     jbe    vscrd3c            ; be = no
  6174.     cmp    dl,131            ; really wide screen
  6175.     jae    vscrd3c            ; ae = yes
  6176.     mov    dl,80            ; else 128 col fake text wide screen
  6177. vscrd3c:dec    dl            ; right most physical col for scroll
  6178.     mov    bh,scbattr        ; attributes
  6179.     mov    bl,dh
  6180.     sub    bl,ch            ; region size - 1 line
  6181.     jz    vscrd7             ; z = region is 1 line, do one scroll
  6182.     mov    al,scroll        ; number of lines to scroll, from msz
  6183. vscrd7:    cmp    al,bl            ; want to scroll more that than?
  6184.     jbe    vscrd2            ; be = no
  6185.     push    ax
  6186.     mov    al,bl            ; limit to region-1 for Windows
  6187.     int    screen            ;  and do in parts
  6188.     pop    ax
  6189.     sub    al,bl            ; get remainder
  6190.     jmp    short vscrd7        ; do next part
  6191. vscrd2:    int    screen            ; scroll it down
  6192.     mov    dx,cursor
  6193.     mov    dosetcursor,dx        ; reminder of where to set cursor
  6194. vscrd8:    pop    di
  6195.     pop    si
  6196.     pop    dx
  6197.     pop    cx
  6198.     pop    bx
  6199.     pop    ax
  6200.     ret
  6201. vtscrd    endp
  6202.  
  6203. ; Put the top cx lines from the virtual screen in to the circular buffer
  6204. ; starting at line index linec (counted from zero, modulo linee).
  6205. putcirc    proc    near
  6206.     jcxz    putcir6            ; z = no lines to save
  6207.     cmp    lmax,0            ; any buffer space?
  6208.     jne    putcir7            ; ne = yes, have some
  6209. putcir6:ret
  6210. putcir7:push    ax
  6211.     push    bx
  6212.     push    cx
  6213.     push    dx
  6214.     push    si
  6215.     push    di
  6216.     push    es
  6217.     cld
  6218.     mov    pageready,-1        ; ems page number currently active
  6219.     mov    si,word ptr vs_ptr    ; offset of screen buffer
  6220.     mov    bx,linef        ; index of the first line
  6221.     add    bx,linec        ; add the current line counter
  6222.     dec    bx
  6223. putcir1:inc    bx
  6224.     cmp    bx,linee        ; at the end of the buffer now?
  6225.     jb    putcir2            ; b = no
  6226.     sub    bx,linee        ; backup to start of buffer
  6227. putcir2:mov    ax,bx            ; line index
  6228.     cmp    emsrbhandle,0        ; EMS in use?
  6229.     jg    putcir3            ; g = yes
  6230.     cmp    xmsrhandle,0        ; XMS rollback in use?
  6231.     je    putcir3            ; e = no
  6232.     call    putxms            ; do the put via xms
  6233.     jmp    short putcir4
  6234. putcir3:call    emsfixup        ; do expanded memory conversion work
  6235.     mul    ppl            ; times paragraphs per line
  6236.     add    ax,iniseg        ; plus initial seg of buffer
  6237.     mov    es,ax            ; now we have the segment pointer
  6238.     xor    di,di            ; buffer offset is always 0
  6239.     push    cx            ; save the number of lines
  6240.     mov    cx,rollwidth        ; get the number of characters to move
  6241.     push    si            ; save starting vscreen offset
  6242.     push    ds            ; get the offset of the screen
  6243.     cld
  6244.     mov    ds,word ptr vs_ptr+2    ; seg of vscreen
  6245.     rep    movsw            ; move them
  6246.     pop    ds            ; restore DS
  6247.     pop    si            ; vscreen offset
  6248.     add    si,vswidth*2        ; inc to next vscreen line
  6249.     pop    cx            ; restore the line count
  6250. putcir4:loop    putcir1            ; go back for more
  6251.     pop    es
  6252.     pop    di
  6253.     pop    si
  6254.     pop    dx
  6255.     pop    cx
  6256.     pop    bx
  6257.     pop    ax
  6258.     clc
  6259.     ret
  6260. putcirc    endp
  6261.  
  6262. ; Put CX lines into XMS based rollback buffer
  6263. putxms    proc    near
  6264.     mul    ppl            ; line number times paragraphs/line
  6265.     push    cx
  6266.     mov    cx,4            ; have paragraphs, want bytes
  6267.     xor    dx,dx
  6268. putxms1:shl    al,1
  6269.     rcl    ah,1
  6270.     rcl    dl,1            ; get bytes to dx:ax
  6271.     loop    putxms1            ; times 16
  6272.     pop    cx
  6273.  
  6274.     mov    word ptr xms.offset_dst,ax    ; low order address
  6275.     mov    word ptr xms.offset_dst+2,dx    ; high order
  6276.     mov    ax,rollwidth
  6277.     shl    ax,1                ; times two
  6278.     mov    word ptr xms.xms_count,ax    ; byte count
  6279.     mov    ax,word ptr vs_ptr+2         ; src seg
  6280.     mov    word ptr xms.offset_src+2,ax
  6281.     mov    word ptr xms.offset_src+0,si     ; low order
  6282.     mov    xms.handle_src,0        ; source is local
  6283.     mov    ax,xmsrhandle             ; dest is rollback area
  6284.     mov    xms.handle_dst,ax
  6285.     push    si
  6286.     mov    si,offset xms        ; ds:si is request block
  6287.     mov    ah,xmsmove
  6288.     call    dword ptr xmsep
  6289.     pop    si
  6290.     add    si,vswidth*2        ; inc to next vscreen line
  6291.     ret
  6292. putxms    endp
  6293.  
  6294. ; Get CX lines from the circular buffer, non destructively, starting at
  6295. ; line index linec (counted from zero, modulo linee) and put them at
  6296. ; the top of the virtual screen. Fewer lines are written if the buffer
  6297. ; holds fewer than CX.
  6298. getcirc    proc    near
  6299.     or    cx,cx            ; check on qty
  6300.     jnz    getcir0            ; nz = some
  6301.     ret
  6302. getcir0:cmp    lmax,0            ; any buffer space?
  6303.     jne    getcir5            ; ne = yes, have some
  6304.     ret
  6305. getcir5:push    ax
  6306.     push    bx
  6307.     push    cx
  6308.     push    dx
  6309.     push    si
  6310.     push    di
  6311.     push    es
  6312.     mov    pageready,-1        ; ems page number currently active
  6313.     les    di,vs_ptr        ; seg and offset of vscreen
  6314.     mov    bx,linef        ; get the first line pointer
  6315.     add    bx,linec        ; add the current line counter
  6316.     dec    bx
  6317.     cld
  6318. getcir1:inc    bx
  6319.     cmp    bx,linee        ; at the end of the buffer now?
  6320.     jb    getcir2            ; b = no
  6321.     sub    bx,linee        ; backup to start of buffer
  6322. getcir2:mov    ax,bx            ; line index
  6323.  
  6324.     cmp    emsrbhandle,0        ; EMS in use?
  6325.     jg    getcir3            ; g = yes
  6326.     cmp    xmsrhandle,0        ; XMS rollback in use?
  6327.     je    getcir3            ; e = no
  6328.     call    getxms            ; get from XMS
  6329.     jmp    short getcir4
  6330. getcir3:call    emsfixup        ; do expanded memory conversion work
  6331.     mul    ppl            ; times paragraphs per line
  6332.     add    ax,iniseg        ; plus initial seg of buffer
  6333.     xor    si,si            ; initial offset is always 0
  6334.     push    cx            ; save the number of lines
  6335.     mov    cx,rollwidth        ; get the number of characters to move
  6336.     push    di            ; save vscreen offset
  6337.     push    ds            ; save DS for a tad
  6338.     mov    ds,ax            ; now we have the segment pointer
  6339.     rep    movsw            ; move them
  6340.     pop    ds            ; restore DS
  6341.     pop    di            ; recover vscreen offset
  6342.     add    di,vswidth*2        ; next vscreen line
  6343.     pop    cx            ; restore the line count
  6344. getcir4:
  6345.     loop    getcir1            ; go back for more
  6346.     call    repaint            ; repaint screen
  6347.     pop    es
  6348.     pop    di
  6349.     pop    si
  6350.     pop    dx
  6351.     pop    cx
  6352.     pop    bx
  6353.     pop    ax
  6354.     clc
  6355.     ret
  6356. getcirc    endp
  6357.  
  6358. getxms    proc    near
  6359.     mul    ppl            ; line number times paragraphs/line
  6360.     push    cx
  6361.     mov    cx,4            ; have paragraphs, want bytes
  6362.     xor    dx,dx
  6363. getxms1:shl    al,1
  6364.     rcl    ah,1
  6365.     rcl    dl,1            ; get bytes to dx:ax
  6366.     loop    getxms1            ; times 16
  6367.     pop    cx
  6368.     mov    word ptr xms.offset_src,ax    ; low order address
  6369.     mov    word ptr xms.offset_src+2,dx    ; high order
  6370.     mov    ax,rollwidth
  6371.     shl    ax,1                ; times two for words
  6372.     mov    word ptr xms.xms_count,ax    ; byte count
  6373.     mov    ax,word ptr vs_ptr+2         ; dst seg
  6374.     mov    word ptr xms.offset_dst+2,ax
  6375.     mov    word ptr xms.offset_dst+0,di     ; low order
  6376.     mov    xms.handle_dst,0        ; destination is local
  6377.     mov    ax,xmsrhandle             ; source is rollback area
  6378.     mov    xms.handle_src,ax         ; source is rollback area
  6379.     push    si
  6380.     mov    si,offset xms            ; ds:si is request block
  6381.     mov    ah,xmsmove
  6382.     call    dword ptr xmsep
  6383.     pop    si
  6384.     add    di,vswidth*2            ; next vscreen line
  6385.     ret
  6386. getxms    endp
  6387.  
  6388. ; Convert rollback line number in AX to line number in ems page, and invoke 
  6389. ; that page. Destroys dx, returns ax as line number in page.
  6390. emsfixup proc    near
  6391.     cmp    emsrbhandle,0        ; EMS in use?
  6392.     jg    emsfix1            ; g = yes (-1 is not in use)
  6393.     ret
  6394. emsfix1:xor    dx,dx
  6395.     div    lineems            ; line number / lines per ems page
  6396.     push    bx
  6397.     mov    bx,ax            ; quotient, page number
  6398.     mov    ax,dx            ; remainder, line in page
  6399.     cmp    bx,pageready        ; is this page now present?
  6400.     je    emsfix2            ; e = yes
  6401.     mov    pageready,bx        ; remember
  6402.     push    ax
  6403.     mov    ah,emsmapmem        ; map logical page in bx
  6404.     xor    al,al            ;  to physical page zero
  6405.     mov    dx,emsrbhandle        ; our ems rollback handle
  6406.     int    emsint
  6407.     pop    ax            ; return ax as line in page
  6408. emsfix2:pop    bx
  6409.     ret
  6410. emsfixup endp
  6411.  
  6412. ; Repaint screen from the vscreen buffer
  6413. repaint    proc    near
  6414.     push    dx
  6415.     xor    dl,dl            ; top row
  6416.     mov    dh,crt_lins        ; physical screen rows-1, incl status
  6417.     cmp    isps55,0        ; [HF]940209 Japanese PS/55?
  6418.     je    repain1            ; [HF]940209 e = no
  6419.     cmp    ps55mod,0        ; [HF]940209 system uses modeline?
  6420.     jne    repain1            ; [HF]940209 ne = no
  6421.     dec    dh            ; [HF]940209 yes, don't touch modeline
  6422. repain1:call    touchup
  6423.     pop    dx
  6424.     ret
  6425. repaint    endp
  6426.  
  6427. ; Repaint part of screen from the vscreen buffer, with linescroll offset
  6428. ; dh is bottom line number, dl is top line number (dh >= dl)
  6429. ftouchup proc    far
  6430.     call    touchup
  6431.     ret
  6432. ftouchup endp
  6433.  
  6434. touchup    proc    near            ; get lines from virtual screen
  6435.     cmp    flags.vtflg,ttgenrc    ; terminal type of none?
  6436.     jne    touch1            ; ne = no
  6437.     ret
  6438. touch1:    push    ax
  6439.     push    bx
  6440.     push    cx
  6441.     push    dx
  6442.     push    si
  6443.     push    di
  6444.     push    es
  6445.     mov    cl,dh            ; last row to change
  6446.     sub    cl,dl            ; number of lines -1
  6447.     cmp    cl,crt_lins        ; out of bounds value?
  6448.     jbe    touch1b            ; be = no
  6449.     xor    cl,cl            ; stay sane
  6450. touch1b:inc    cl            ; number of lines to update
  6451.     xor    ch,ch
  6452.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6453.     je    touch1c            ; e = yes, skip text screen update
  6454.     test    tekflg,tek_active    ; other graphics mode?
  6455.     jnz    touch9            ; nz = yes, no touchup
  6456.  
  6457.     call    scroff            ; turn off text screen
  6458.     mov    es,tv_segs        ; get the segment of the screen
  6459.     mov    di,tv_sego        ; initial screen offset
  6460. touch1c:mov    al,crt_cols        ; physical screen width
  6461.     mul    dl            ; chars into physical screen
  6462.     add    ax,ax            ; chars to bytes
  6463.     add    di,ax            ; offset of start of phy update area
  6464.     mov    si,word ptr vs_ptr
  6465.     mov    al,vswidth        ; chars per line
  6466.     mul    dl            ; ax = bytes to first vscreen line
  6467.     add    ax,ax            ; chars to bytes
  6468.     add    si,ax            ; si = starting vscreen line offset
  6469.     mov    bl,dl            ; top line number
  6470.     xor    bh,bh            ; index for linescroll
  6471.     cld
  6472.     push    dx
  6473.     mov    dh,dl            ; set row into dh, temporarily
  6474. touch2:    push    si            ; save the current line pointer
  6475.     push    cx            ; save the number of lines
  6476.     mov    cl,crt_cols        ; get the number of characters to move
  6477.     xor    ch,ch
  6478.     xor    dl,dl
  6479.     mov    al,linescroll[bx]    ; get horiz scroll for this line
  6480.     add    al,handhsc        ; hand done shift, total to AL
  6481.     cbw                ; sign extend
  6482.     or    ax,ax            ; sane?
  6483.     jge    touch2c            ; ge = yes
  6484.     xor    ax,ax            ; remove negative overshifts
  6485. touch2c:add    si,ax            ; offset into vscreen
  6486.     add    si,ax            ; char cells to words
  6487.  
  6488.     mov    ah,dgwindcomp[bx]
  6489.     test    ah,2            ; soft font?
  6490.     jz    touch2g            ; z = no
  6491. ifndef    no_graphics
  6492.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6493.     je    touch2d            ; e = yes
  6494.     push    ax
  6495.     call    dgsettek        ; set special graphics mode now
  6496.     pop    ax
  6497.     jmp    short touch2d
  6498. endif    ; no_graphics
  6499.  
  6500. touch2g:cmp    writemode,0        ; use direct writing?
  6501.     je    touch2a            ; e = yes
  6502.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6503.     je    touch2d            ; e = yes
  6504.     call    tchbios            ; Bios writing
  6505.     jmp    short touch4
  6506. touch2a:cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6507.     jne    touch3            ; ne = no
  6508.  
  6509. touch2d:
  6510. ifndef    no_graphics
  6511.     push    bx
  6512.     mov    bl,al            ; horizontal scroll for this line
  6513.     xor    bh,bh
  6514.     test    ah,1            ; is this line compressed?
  6515.     jz    touch2e            ; z = no
  6516.     mov    cl,128            ; compressed, 5 dot chars, 128/line
  6517. touch2e:mov    al,vswidth
  6518.     mul    dh            ; cells in previous rows
  6519.     add    al,dl            ; cells across to this column
  6520.     adc    ah,0
  6521.     add    bx,ax            ; cells from start of screen
  6522. touch2b:push    bx
  6523.     push    cx
  6524.     push    si
  6525.     push    es
  6526.     shl    bx,1            ; address words
  6527.     les    si,vs_ptr        ; main vscreen
  6528.     mov    ax,es:[si+bx]        ; obtain char and attribute
  6529.     les    si,vsat_ptr        ; extended attributes
  6530.     shr    bx,1            ; count bytes, vs words above
  6531.     mov    cl,es:[bx+si]        ; obtain extended attribute byte
  6532.     pop    es            ; to get font indicator
  6533.     pop    si
  6534.     call    ttxtchr            ; write character
  6535.     pop    cx
  6536.     pop    bx
  6537.     inc    dl            ; next column
  6538.     inc    bx
  6539.     loop    touch2b
  6540.     pop    bx
  6541.     jmp    short touch4
  6542. endif    ; no_graphics
  6543.  
  6544. touch3:    push    ds
  6545.     mov    ds,word ptr vs_ptr+2    ; segment of vscreen
  6546.     rep    movsw            ; from vscreen+hsc to real screen+0
  6547.     pop    ds
  6548.  
  6549. touch4:    pop    cx            ; restore the line count
  6550.     pop    si            ; restore the buffer counter
  6551.     inc    bx            ; for next line
  6552.     add    si,vswidth*2        ; point to next line
  6553.     inc    dh
  6554.     dec    cx
  6555.     jz    touch4a            ; z = have done all lines
  6556.     jmp    touch2            ; do more lines
  6557.  
  6558. touch4a:pop    dx
  6559.     mov    ah,byte ptr cursor+1    ; row of cursor
  6560.     cmp    ah,dl            ; cursor before this line?
  6561.     jb    touch5            ; b = yes, skip cursor
  6562.     cmp    ah,dh            ; cursor after this line?
  6563.     ja    touch5            ; a = yes, skip cursor
  6564. ifndef    no_graphics
  6565.     mov    cursorst,0        ; say cursor has been zapped off
  6566. endif    ; no_graphics
  6567.     push    dx
  6568.     mov    dx,cursor
  6569.     mov    bl,dh            ; get row
  6570.     xor    bh,bh
  6571.     sub    dl,linescroll[bx]    ; deduct horiz scroll for this line
  6572.     sub    dl,handhsc        ; hand done shift
  6573.     call    setpcur            ; reset the cursor
  6574.     pop    dx
  6575.  
  6576. touch5:    cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6577.     je    touch9            ; e = yes
  6578.     cmp    tv_mode,0h        ; TV active?
  6579.     je    touch8            ; e = no
  6580.     mov    cl,dh            ; tell Topview/Desqview
  6581.     sub    cl,dl            ; number of lines -1
  6582.     cmp    cl,crt_lins        ; out of bounds value?
  6583.     jbe    touch7            ; be = no
  6584.     xor    cl,cl            ; stay sane
  6585. touch7:    inc    cl            ; number of lines to update
  6586.     mov    al,crt_cols        ; chars/line
  6587.     mul    cl
  6588.     mov    cx,ax            ; cx = words changed
  6589.     call    scrsync            ; synch Topview
  6590. touch8:    call    scron            ; turn on the screen
  6591. touch9:    pop    es
  6592.     pop    di
  6593.     pop    si
  6594.     pop    dx
  6595.     pop    cx
  6596.     pop    bx
  6597.     pop    ax
  6598.     ret
  6599. touchup    endp
  6600.  
  6601. ; Write screen via Bios. Enter with SI pointing at starting screen buffer
  6602. ; offset, dh is current screen row, cx has chars to write across a line.
  6603.  
  6604. tchbios proc    near
  6605.     push    bx
  6606.     xor    bh,bh            ; video page zero
  6607.     push    dx
  6608.     mov    ah,3
  6609.     int    screen
  6610.     mov    temp,dx            ; save current cursor
  6611.     pop    dx
  6612.     mov    cl,crt_cols
  6613.     xor    ch,ch
  6614.     xor    dl,dl            ; column zero
  6615.     cld
  6616.     push    ds
  6617.     mov    ds,word ptr vs_ptr+2    ; source is virtual screen buffer
  6618.     add    di,cx            ; move DI to match si movemen
  6619.     add    di,di            ; word's worth
  6620.  
  6621. tchbios1:push    cx
  6622.     mov    ah,2            ; set cursor position to dx
  6623.     int    screen
  6624.     lodsw                ; char+attribute
  6625.     mov    bl,ah            ; attribute
  6626.     mov    cx,1            ; one char
  6627.     mov    ah,9            ; write char at cursor position
  6628.     int    screen            ; do the Bios Int 10h call
  6629.     inc    dl            ; next column
  6630.     pop    cx
  6631.     loop    tchbios1
  6632.     pop    ds
  6633.     push    dx
  6634.     mov    dx,temp            ; starting cursor position
  6635.     mov    ah,2            ; set it back there
  6636.     int    screen
  6637.     pop    dx
  6638.     pop    bx
  6639.     ret
  6640. tchbios    endp
  6641.  
  6642. ; Character write/read and cursor manipulation routines for terminal emulator
  6643. ; All registers other than returned values are preserved.
  6644.  
  6645. ; Read char and attributes under virtual cursor (DH = row, DL = column).
  6646. ; Returns AL = character, AH = video attributes, CL = logical attribute bit
  6647. ; pair.
  6648. getatch    proc    near
  6649.     push    bx
  6650.     push    si
  6651.     push    es
  6652.     mov    al,vswidth        ; width of vscreen line
  6653.     mul    dh            ; count down rows (0..)
  6654.     add    al,dl            ; add column
  6655.     adc    ah,0
  6656.     add    ax,ax            ; times two for char and attrib
  6657.     mov    bx,ax            ; address subscript
  6658.     les    si,vs_ptr        ; main vscreen
  6659.     mov    ax,es:[si+bx]        ; obtain char and attribute
  6660.  
  6661.     les    si,vsat_ptr        ; extended attributes
  6662.     shr    bx,1            ; count bytes, vs words above
  6663.     mov    cl,es:[bx+si]        ; obtain extended attribute byte
  6664.     pop    es
  6665.     pop    si
  6666.     pop    bx
  6667.     ret
  6668. getatch    endp
  6669. endif    ; no_terminal
  6670.  
  6671. ; Set virtual cursor postion
  6672. ; DL = column, DH = row, both counted from 0,0 at upper left corner.
  6673. ; If not displaced, handhsc = 0, then scroll left if virtual > crt_cols.
  6674. ; If displaced, handhsc != 0, then scroll right if virtual < handhsc.
  6675. ; For the D463/D470 only, set carry bit (for setatch) if the cursor is off
  6676. ; the visible screen and horizontal scrolling is disabled.
  6677.  
  6678. setpos    proc    near
  6679.     push    ax
  6680.     push    bx
  6681.     push    cx
  6682.     push    dx            ; save outside virtual cursor
  6683.     mov    cl,crt_cols        ; physical screen width
  6684.     push    cx            ; save here
  6685. ifndef    no_terminal
  6686.     cmp    inemulator,0        ; emulating?
  6687.     je    setpos9            ; e = no, no virtual screen
  6688.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6689.     jne    setpos1            ; ne = no
  6690.     mov    bl,dh            ; get row
  6691.     xor    bh,bh
  6692.     test    dgwindcomp[bx],1    ; is this line compressed?
  6693.     jz    setpos1            ; z = no
  6694.     mov    crt_cols,128        ; compressed, 5 dot chars, 128/line
  6695. setpos1:mov    ch,vswidth        ; leftmost legal margin (207)
  6696.     sub    ch,crt_cols        ; minus screen physical width
  6697.     xor    cl,cl        ; cl is flag for repainting needed (if != 0)
  6698.     xchg    handhsc,cl        ; hand-done horiz scroll, clear it
  6699.     or    cl,cl            ; need to undo it?
  6700.     jz    setpos2            ; z = no
  6701.     call    repaint            ; repaint screen without hand scroll
  6702.     xor    cl,cl            ; remove repaint indicator
  6703. setpos2:mov    bl,dh            ; current row
  6704.     xor    bh,bh
  6705.     mov    ah,linescroll[bx]    ; current horz scroll
  6706. setpos3:mov    al,dl            ; virtual column where we ought to be
  6707.     sub    al,ah            ; virtual - already scrolled    
  6708.     jc    setpos4            ; c = cursor off screen to the left
  6709.     cmp    al,crt_cols        ; beyond right physical screen?
  6710.     jb    setpos5            ; b = no, use this
  6711.     mov    cl,1            ; say need repaint
  6712.     inc    ah            ; scroll screen left one column
  6713.     jc    setpos3a        ; c = over did it
  6714.     cmp    ah,ch            ; going beyond largest scroll?
  6715.     jbe    setpos3            ; be = no
  6716. setpos3a:mov    ah,ch            ; yes, stay here
  6717.     jmp    short setpos5        ; done, do real operation
  6718.  
  6719. setpos4:mov    cl,1            ; say repaint needed
  6720.     mov    ah,dl            ; reduce horz scroll
  6721.  
  6722. setpos5:or    cl,cl            ; repaint needed?
  6723.     jnz    setpos5c        ; ne = yes
  6724.     mov    bl,byte ptr low_rgt+1    ; screen bottom
  6725.     inc    bl            ; lines in emulation part
  6726.     xor    bh,bh
  6727.     cmp    linescroll[bx],ah    ; status line, need to scroll?
  6728.     jbe    setpos8            ; be = already scrolled properly
  6729.     mov    linescroll[bx],ah    ; modify status line
  6730.     push    dx
  6731.     mov    dl,bl
  6732.     mov    dh,bl
  6733.     call    touchup            ; redraw status line
  6734.     pop    dx
  6735.     jmp    short setpos8        ; set cursor
  6736.  
  6737. setpos5c:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  6738.     jz    setpos5a        ; z = no
  6739.     cmp    dghscrdis,0        ; D463/D470 horz scroll disabled?
  6740.     je    setpos5a        ; e = no, check auto vs manual
  6741.     stc                ; c = do not show on real screen
  6742.     jmp    short setposx        ; skip screen update
  6743.  
  6744. setpos5a:test    vtemu.vtflgop,vshscroll    ; horizontal scrolling, manual?
  6745.     jnz    setpos9            ; nz = yes manual, else auto
  6746.  
  6747. setpos5b:mov    bl,mar_top        ; auto scrolling, top row
  6748.     xor    bh,bh
  6749.     mov    cl,mar_bot
  6750.     sub    cl,bl
  6751.     xor    ch,ch
  6752.     inc    cx            ; lines in scrolling region
  6753. setpos6:cmp    linescroll[bx],ah    ; any change?
  6754.     je    setpos7            ; e = no
  6755.     mov    linescroll[bx],ah    ; set scroll for this line
  6756.     push    dx
  6757.     mov    dl,bl
  6758.     mov    dh,bl
  6759.     call    touchup            ; repaint this line
  6760.     pop    dx
  6761. setpos7:inc    bx
  6762.     loop    setpos6            ; do all lines in window
  6763.  
  6764. setpos7a:push    ax            ; now do status line
  6765.     push    si
  6766.     mov    cl,byte ptr low_rgt+1    ; examine whole screen
  6767.     inc    cl            ; lines in emulation part
  6768.     xor    ch,ch
  6769.     mov    bx,cx            ; save for status line
  6770.     mov    si,offset linescroll
  6771.     mov    ah,[si]            ; smallest horizontal shift found
  6772.     cld
  6773. setpos10:lodsb                ; current line scroll to al
  6774.     cmp    al,ah            ; smaller than smallest?
  6775.     ja    setpos11        ; a = no
  6776.     mov    ah,al            ; remember smallest
  6777.     or    ah,ah            ; zero?
  6778.     jz    setpos11a        ; can't get any smaller than this
  6779. setpos11:loop    setpos10
  6780.                     ; just status line
  6781. setpos11a:cmp    linescroll[bx],ah    ; status line, need to scroll?
  6782.     je    setpos12        ; e = already scrolled properly
  6783.     mov    linescroll[bx],ah    ; modify status line
  6784.     push    dx
  6785.     mov    dl,bl
  6786.     mov    dh,bl
  6787.     call    touchup            ; redraw status line
  6788.     pop    dx
  6789. setpos12:pop    si
  6790.     pop    ax
  6791. setpos8:sub    dl,ah            ; virtual - horz scrolled column
  6792.  
  6793. endif    ; no_terminal
  6794.  
  6795. setpos9:call    setpcur            ; set physical cursor
  6796.     clc                ; set status for ok to show
  6797. setposx:pop    cx
  6798.     mov    crt_cols,cl
  6799.     pop    dx
  6800.     pop    cx
  6801.     pop    bx
  6802.     pop    ax
  6803.     ret
  6804. setpos    endp
  6805.  
  6806. ; Read physical cursor position
  6807. ; DL = column, DH = row, both counted from 0,0 at upper left corner
  6808. ; CX = cursor lines
  6809. getpcur    proc    near
  6810.     push    ax
  6811.     push    bx
  6812.     mov    ah,3            ; get cursor position
  6813.     xor    bh,bh            ; page 0
  6814.     int    screen
  6815.     pop    bx
  6816.     pop    ax
  6817.     ret
  6818. getpcur    endp
  6819.  
  6820. fgetpcur proc    far
  6821.     call    getpcur
  6822.     ret
  6823. fgetpcur endp
  6824.  
  6825. ; Set physical cursor postion
  6826. ; DL = column, DH = row, both counted from 0,0 at upper left corner
  6827. setpcur    proc    near
  6828.     push    dx
  6829.     cmp    dl,crt_cols        ; out of bounds?
  6830.     jb    setpcur1        ; b = ok
  6831.     cmp    dl,207            ; off screen to left?
  6832.     jbe    setpcur0        ; be = no
  6833.     xor    dl,dl            ; put at column zero
  6834.     jmp    short setpcur1
  6835. setpcur0:mov    dl,crt_cols        ; physical cols on screen
  6836.     dec    dl            ; count from zero
  6837. setpcur1:
  6838. ifndef    no_terminal
  6839.     cmp    inemulator,0        ; emulating?
  6840.     je    setpcur4        ; e = no, no virtual screen
  6841.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6842.     jne    setpcur4        ; ne = no
  6843.     push    ax
  6844.     push    es
  6845.     mov    ax,40h
  6846.     mov    es,ax
  6847.     mov    ax,es:[50h]        ; current position
  6848.     mov    es:[50h],dx        ; text page 0 cursor, keep it tracking
  6849.     cmp    ax,dx            ; same?
  6850.     pop    es
  6851.     pop    ax
  6852. ifndef    no_graphics
  6853.     jne    setpcur2        ; not same, draw cursor
  6854.     cmp    cursorst,0        ; is cursor off now?
  6855.     jne    setpcur3        ; ne = no, skip redrawing
  6856. setpcur2:
  6857.     mov    dosetcursor,dx        ; reminder of where to set cursor
  6858.     call    tekremcursor        ; ensure it's off
  6859. endif    ; no_graphics
  6860. setpcur3:pop    dx
  6861.     ret
  6862. endif    ; no_terminal
  6863.  
  6864. setpcur4:push    ax
  6865.     push    es
  6866.     mov    ax,40h
  6867.     mov    es,ax
  6868.     mov    ax,es:[50h]        ; current position
  6869.     cmp    ax,dx            ; same?
  6870.     pop    es
  6871.     jne    setpcur5        ; ne = no
  6872.     pop    ax
  6873.     pop    dx
  6874.     ret
  6875. setpcur5:push    bx
  6876.     mov    ah,2            ; set cursor
  6877.     xor    bh,bh            ; page 0
  6878.     int    screen
  6879.     pop    bx
  6880.     pop    ax
  6881.     pop    dx
  6882.     ret
  6883. setpcur    endp
  6884.  
  6885. ; Read char and attributes under physical cursor.
  6886. ; Returns AL = character, AH = video attributes
  6887. getpcha    proc    near
  6888.     push    bx
  6889.     mov    ah,8            ; read char and attributes
  6890.     xor    bh,bh            ; page 0
  6891.     int    screen            ; Bios video call
  6892.     pop    bx
  6893.     ret
  6894. getpcha    endp
  6895.  
  6896. ; Write char and attribute to screen at cursor position, do not move cursor.
  6897. ; AL = char, AH = video attribute, DL = column, DH = row, CL = logical 
  6898. ; attribute bits. Does not update physical screen.
  6899. qsetatch proc    near
  6900.     mov    setnoshow,1        ; turn off physical screen update
  6901.     jmp    setatch            ; call with same args
  6902. qsetatch endp
  6903.  
  6904. ; Write char and attribute to screen at cursor position, do not move cursor.
  6905. ; AL = char, AH = video attribute, DL = column, DH = row, CL = logical 
  6906. ; attribute bits. Turns off setnoshow at the end.
  6907.  
  6908. setatch    proc    near
  6909.     push    bx
  6910.     push    es
  6911.     push    cx            ; save logical attribute
  6912.     push    ax            ; save char and attribute
  6913.     cmp    setnoshow,0        ; show on real screen?
  6914.     jne    setatc1            ; ne = no, do just virtual screen
  6915.     push    cx
  6916.     call    setpos            ; set cursor at dx location
  6917.     pop    cx
  6918.     jc    setatc1            ; c = do not show character
  6919.     cmp    inemulator,0        ; emulating a terminal now?
  6920.     je    setatc4            ; e = no
  6921. ifndef    no_graphics
  6922.     cmp    flags.vtflg,tttek    ; full Tek?
  6923.     je    setatc5            ; e = yes
  6924.     cmp    tekflg,tek_active+tek_sg ; special graphics mode?
  6925.     jne    setatc4            ; ne = no, text mode
  6926. setatc5:push    dx
  6927.     push    si
  6928.     push    di
  6929.     mov    bl,dh            ; get row
  6930.     xor    bh,bh
  6931.     sub    dl,linescroll[bx]     ; deduct horizontal scroll
  6932.     call    ttxtchr            ; display char in graphics mode
  6933.     pop    di
  6934.     pop    si
  6935.     pop    dx
  6936.     jmp    short setatc1
  6937. endif    ; no_graphics
  6938. setatc4:
  6939.     mov    cx,1            ; one char
  6940.     mov    bl,ah            ; attribute
  6941.     xor    bh,bh            ; page 0
  6942.     mov    ah,9            ; write char, do not move cursor
  6943.     int    screen
  6944. setatc1:mov    setnoshow,0        ; always reset this automatically
  6945.                     ; write same material to vscreen
  6946.     mov    al,vswidth        ; width of vscreen line
  6947.     mul    dh            ; count across rows (0..)
  6948.     xor    bh,bh
  6949.     mov    bl,dl            ; get position
  6950.     add    bx,ax            ; add column
  6951.     add    bx,bx            ; times two for char and attrib
  6952.     pop    ax            ; recover char and attribute
  6953.     pop    cx            ; recover logical attribute
  6954. ifndef    no_terminal
  6955.     cmp    inemulator,0        ; in terminal emulator?
  6956.     je    setatc2            ; e = no, so no virtual screen
  6957.     push    di
  6958.     les    di,vs_ptr        ; virtual screen
  6959.     mov    es:[di+bx],ax        ; store char and attribute
  6960.     push    ax            ; save ah attributes
  6961.  
  6962.     les    di,vsat_ptr        ; attributes byte array
  6963.     shr    bx,1            ; bytes, vs words above
  6964.     mov    es:[bx+di],cl        ; set extended attributes
  6965.     pop    ax
  6966.     pop    di
  6967. endif    ; no_terminal
  6968. setatc2:pop    es
  6969.     pop    bx
  6970.     ret
  6971. setatch    endp
  6972.  
  6973. ifndef    no_terminal
  6974. ; Get bold video attribute bit
  6975. ; Returns AH = bold attribute bit (0 if not bold)
  6976. getbold    proc    near
  6977.     and    ah,att_bold
  6978.     test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  6979.     jnz    getbold1        ; nz = yes
  6980.     xor    ah,userbold        ; invert with user bold
  6981. getbold1:ret
  6982. getbold endp
  6983.  
  6984. ; Set bold video attribute bit, current video attribute supplied in AH
  6985. setbold proc    near
  6986.     or    ah,att_bold
  6987.     cmp    colunder,0ffh        ; uninited?
  6988.     je    setbold2        ; e = yes, don't change here
  6989.     or    colunder,att_bold
  6990. setbold2:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  6991.     jnz    setbold1        ; nz = yes
  6992.     xor    ah,userbold        ; invert with user bold
  6993.     cmp    colunder,0ffh        ; uninited?
  6994.     je    setbold1        ; e = yes, don't change here
  6995.     push    ax
  6996.     mov    ah,userbold
  6997.     xor    colunder,ah
  6998.     pop    ax
  6999. setbold1:ret
  7000. setbold endp
  7001.  
  7002. ; Clear bold video attribute bit, current video attribute supplied in AH
  7003. clrbold    proc    near
  7004.     and    ah,not att_bold
  7005.     cmp    colunder,0ffh        ; uninited?
  7006.     je    clrbold2        ; e = yes, don't change here
  7007.     and    colunder,not att_bold
  7008. clrbold2:test    flags.vtflg,ttd463+ttd470+ttd217 ; D463/D470/D217?
  7009.     jnz    clrbold1        ; nz = yes
  7010.     xor    ah,userbold        ; invert with user bold
  7011.     cmp    colunder,0ffh        ; uninited?
  7012.     je    clrbold1        ; e = yes, don't change here
  7013.     push    ax
  7014.     mov    ah,userbold
  7015.     or    colunder,ah
  7016.     pop    ax
  7017. clrbold1:ret
  7018. clrbold    endp
  7019.  
  7020. ; Get blink video attribute bit
  7021. ; Returns AH = blink attribute bit
  7022. getblink proc    near
  7023.     and    ah,att_blink
  7024.     ret
  7025. getblink endp
  7026.  
  7027. ; Set blink video attribute bit, current video attribute supplied in AH
  7028. setblink proc    near
  7029.     or    ah,att_blink
  7030.     ret
  7031. setblink endp
  7032.  
  7033. ; Clear blink video attribute bit, current video attribute supplied in AH
  7034. clrblink proc    near
  7035.     and    ah,not att_blink
  7036.     ret
  7037. clrblink endp
  7038.  
  7039. ; Set extended attribute for protection in extattr and in CL.
  7040. setprot    proc    near            ; set protected mode
  7041.     or    extattr,att_protect
  7042.     or    cl,att_protect        ; and in cl
  7043.     ret
  7044. setprot    endp
  7045.  
  7046. ; Clear extended attribute for protection in extattr and in CL.
  7047. clrprot    proc    near            ; clear protected mode
  7048.     and    extattr,not att_protect
  7049.     and    cl,not att_protect
  7050.     ret
  7051. clrprot endp
  7052.  
  7053. ; Get underline video attribute bit from extattr
  7054. ; Returns CL = underline attribute bit
  7055. getunder proc    near
  7056.     mov    cl,extattr        ; get extended attribute
  7057.     and    cl,att_uline        ; return underline status bit
  7058.     ret
  7059. getunder endp
  7060.  
  7061. ; Set underline video attribute bit, current video attribute supplied in AH
  7062. ; and extended attributes in extattr. Returns new AH and extattr in CL.
  7063. setunder proc    near
  7064.     test    extattr,att_uline    ; extended attributes, on already?
  7065.     jz    setund1            ; z = no
  7066.     ret                ; else do nothing
  7067. setund1:or    extattr,att_uline    ; set underline attribute for MSZ
  7068.     or    cl,att_uline
  7069.     cmp    crt_mode,7        ; monochrome display adapter mode?
  7070.     je    setund6            ; e = yes
  7071.     cmp    colunder,0ffh        ; uninited?
  7072.     je    setund10        ; e = yes
  7073.  
  7074.     and    ah,att_blink        ; preserve blink
  7075.     or    ah,colunder        ; user specified underline coloring
  7076.     test    extattr,att_rev        ; are we reversed per char?
  7077.     jz    setund8            ; z = no
  7078.     call    revideo
  7079. setund8:cmp    reversed_screen,0    ; whole screen reversed too?
  7080.     je    setund9            ; e = no
  7081.     call    revideo
  7082. setund9:ret
  7083.  
  7084. setund10:push    bx
  7085.     push    dx
  7086.     mov    bh,al            ; preserve possible char in al
  7087.     mov    dl,scbattr        ; screen fill
  7088.     and    dl,70h            ; background colors
  7089.     mov    bl,extattr        ; extended attributes
  7090.     and    bl,att_rev        ; per char reversed video
  7091.     mov    dh,ah            ; current character attributes
  7092.     and    dh,not 77h        ; blink/bold attributes only
  7093.     and    ah,77h            ; colors only
  7094.     mov    al,ah
  7095.     shr    al,1
  7096.     shr    al,1
  7097.     shr    al,1
  7098.     shr    al,1            ; background to lower nibble
  7099.     and    ah,7            ; foreground only
  7100.     or    bl,bl            ; reversed video attribute?
  7101.     jz    setund3            ; z = no, normal
  7102.     xchg    ah,al            ; real background color to al
  7103. setund3:xor    al,ah            ; modify background
  7104.     or    dl,dl            ; case of black background?
  7105.     jnz    setund4            ; nz = no
  7106.     mov    al,ah
  7107.     dec    al
  7108.     and    al,7            ; background goes to (foreground-1)/8
  7109.     or    al,al            ; still black?
  7110.     jnz    setund4            ; nz = no
  7111.     mov    al,7            ; force non-black (white foreground)
  7112. setund4:shl    al,1            ; background to high nibble
  7113.     shl    al,1
  7114.     shl    al,1
  7115.     shl    al,1
  7116.     or    ah,al            ; or new background
  7117.     or    bl,bl            ; per char reversal?
  7118.     jz    setund5            ; z = no
  7119.     rol    ah,1            ; yes, flip fore/background again
  7120.     rol    ah,1
  7121.     rol    ah,1
  7122.     rol    ah,1
  7123. setund5:or    ah,dh            ; restore blink and bold
  7124.     pop    dx
  7125.     mov    al,bh            ; restore possible char
  7126.     pop    bx
  7127.     ret
  7128. setund6:push    bx
  7129.     mov    bl,al            ; preserve char in AL
  7130.     call    brkatt            ; monochrome, break apart
  7131.     mov    ah,att_underline    ; set mono underline coloring
  7132.     or    ah,al            ; put back blink/bold
  7133.     test    extattr,att_rev        ; are we reversed per char?
  7134.     jz    setund6a        ; z = no
  7135.     call    revideo
  7136. setund6a:cmp    reversed_screen,0    ; whole screen reversed too?
  7137.     je    setund6b        ; e = no
  7138.     call    revideo
  7139. setund6b:mov    al,bl            ; restore char in AL
  7140.     pop    bx
  7141.     ret
  7142. setunder endp
  7143.  
  7144. ; Clear underline video attribute bit, current video attribute supplied in AH
  7145. ; and extended attributes in extattr. Returns new AH and extattr in CL.
  7146. clrunder proc    near
  7147.     test    extattr,att_uline    ; extended attributes, off already?
  7148.     jnz    clrund1            ; nz = no
  7149.     ret                ; else do nothing
  7150. clrund1:and    extattr,not att_uline    ; clear underline attribute for MSZ
  7151.     and    cl,not att_uline
  7152.     cmp    crt_mode,7        ; monochrome display adapter mode?
  7153.     je    clrund6            ; e = yes, otherwise reverse video
  7154.     cmp    colunder,0ffh        ; user spec underline inited?
  7155.     je    clrund10        ; e = no
  7156.     and    ah,att_blink        ; preserve blink
  7157.     or    ah,att_normal        ; current normal coloring
  7158.     test    extattr,att_rev        ; are we reversed per char?
  7159.     jz    clrund1a        ; z = no
  7160.     call    revideo
  7161. clrund1a:cmp    reversed_screen,0    ; whole screen reversed too?
  7162.     je    clrund1b        ; e = no
  7163.     call    revideo
  7164. clrund1b:ret    
  7165.     
  7166. clrund6:push    bx
  7167.     mov    bl,al            ; preserve char in al
  7168.     call    brkatt            ; mono, break apart attributes
  7169.     mov    ah,07h            ; set normal coloring
  7170.     or    ah,al            ; reassemble attributes
  7171.     test    extattr,att_rev        ; are we reversed per char?
  7172.     jz    clrund6a        ; z = no
  7173.     call    revideo
  7174. clrund6a:cmp    reversed_screen,0    ; whole screen reversed too?
  7175.     je    clrund6b        ; e = no
  7176.     call    revideo
  7177. clrund6b:mov    al,bl            ; restore char in AL
  7178.     pop    bx
  7179.     ret
  7180.  
  7181. clrund10:push    bx
  7182.     push    dx
  7183.     mov    bh,al            ; save possible char in al
  7184.     xor    bl,bl
  7185.     mov    dl,scbattr        ; screen fill
  7186.     and    dl,70h            ; background colors
  7187.     mov    bl,extattr        ; extended attributes
  7188.     and    bl,att_rev        ; per char reversed video
  7189.     mov    dh,ah            ; current char attributes
  7190.     and    dh,not 77h        ; blink/bold attributes only
  7191.     and    ah,77h            ; colors only
  7192.     mov    al,ah
  7193.     shr    al,1
  7194.     shr    al,1
  7195.     shr    al,1
  7196.     shr    al,1            ; background to lower nibble
  7197.     and    ah,7            ; foreground only
  7198.     or    bl,bl            ; reversed video attribute?
  7199.     jz    clrund3            ; z = no, normal
  7200.     xchg    ah,al            ; real background color to al
  7201. clrund3:or    dl,dl            ; case of black background?
  7202.     jz    clrund4            ; z = yes, leave it black (empty)
  7203.     xor    al,ah
  7204.     shl    al,1            ; background to high nibble
  7205.     shl    al,1
  7206.     shl    al,1
  7207.     shl    al,1
  7208.     or    ah,al            ; or in new background
  7209. clrund4:or    bl,bl            ; per char reversal?
  7210.     jz    clrund5            ; z = no
  7211.     rol    ah,1            ; yes, reverse nibbles again
  7212.     rol    ah,1
  7213.     rol    ah,1
  7214.     rol    ah,1
  7215. clrund5:or    ah,dh            ; restore blink and bold
  7216.     pop    dx
  7217.     mov    al,bh            ; restore possible char
  7218.     pop    bx
  7219.     ret    
  7220. clrunder endp
  7221. endif    ; no_terminal
  7222.  
  7223. ; Compute reversed video attributes, given displayables in AH and extended
  7224. ; in extattr. Returns new attribute in AH and CL holding new extattr
  7225. setrev    proc    near
  7226.     test    extattr,att_rev        ; reversed now?
  7227.     jnz    setrev2            ; nz = yes
  7228.     call    revideo            ; do reversal
  7229.     or    extattr,att_rev        ; update extended attribute
  7230.     or    cl,att_rev
  7231. setrev2:ret
  7232. setrev    endp
  7233.  
  7234. ; Compute un-reversed video attributes, given displayables in AH and extended
  7235. ; in extattr. Returns new attribute in AH and CL holding new extattr
  7236. clrrev    proc    near
  7237.     test    extattr,att_rev        ; reversed now?
  7238.     jz    clrrev1            ; z = no
  7239.     call    revideo            ; do reversal
  7240.     and    extattr,not att_rev    ; update extended attribute
  7241.     and    cl,not att_rev        ; update extended attribute
  7242. clrrev1:ret
  7243. clrrev    endp
  7244.  
  7245.  
  7246. ; Compute reversed video attribute byte. Normally preserves blink/bold.
  7247. ; Enter with AH = video attribute byte, returns new attribute byte in AH.
  7248. revideo    proc    near
  7249.     push    bx
  7250.     mov    bl,al            ; preserve char in AL
  7251.     call    brkatt            ; separate colors from blink/bold
  7252.     rol    ah,1            ; reverse foreground & background
  7253.     rol    ah,1            ; RGB bits
  7254.     rol    ah,1
  7255.     rol    ah,1
  7256.     cmp    crt_mode,7        ; monochrome?
  7257.     jne    revideo1        ; ne = no
  7258.     test    al,att_bold        ; bold?
  7259.     jz    revideo1        ; z = no
  7260.     test    ah,7            ; black foreground now?
  7261.     jnz    revideo1        ; nz = no, something to brighten
  7262.     and    al,not att_bold        ; remove bolding
  7263. revideo1:or    ah,al            ; reinsert bold/blink bits
  7264.     mov    al,bl            ; restore char in AL
  7265.     pop    bx
  7266.     ret
  7267. revideo    endp
  7268.  
  7269. ; This routine picks an attribute apart into its component "parts" - the
  7270. ; base attribute for the screen and the "extras" - i.e., blink, intensity
  7271. ; and underline.
  7272. ; enter with    ah = a cursor attribute
  7273. ; return    ah = base attribute for screen (07H normal, 70H reverse).
  7274. ;        al = "extra" attributes
  7275. ; Note that there is a complementary routine, addatt, for putting attributes
  7276. ; back together.
  7277.  
  7278. brkatt:    mov    al,ah            ; copy displayables
  7279.     and    al,(att_blink+att_bold)    ; get modifiers
  7280.     and    ah,not (att_bold+att_blink) ; strip blink/bold, leave color
  7281.     ret
  7282.  
  7283. ; This routine builds a cursor attribute given the base attribute for the
  7284. ; screen background and the "extra" attributes we want (blink, etc.).
  7285. ; enter with    ah = base attribute for background (07H or 70H)
  7286. ;        al = "extra" attributes (89H for all three)
  7287. ; return    ah = base combined with "extras".
  7288.  
  7289. addatt: or    ah,al            ; OR the attributes
  7290.     ret
  7291.  
  7292. ifndef    no_terminal
  7293.  
  7294. ; This routine is called when we want to reverse everything on the screen
  7295. ; from normal to reverse video, or vice versa.    It is called only when
  7296. ; the decscnm attribute is changed.
  7297. ; Call:    no arguments.
  7298.  
  7299. revscn    proc    near
  7300.     push    ax
  7301.     push    bx
  7302.     push    cx
  7303.     push    dx
  7304.     xor    reversed_screen,1    ; remember we did this
  7305.     mov    dh,byte ptr low_rgt+1    ; compute last screen offset in ax
  7306.     inc    dh            ; one more row to catch mode line
  7307.     mov    dl,vswidth        ; logical screen buffer
  7308.     dec    dl            ; and we count from 0
  7309.     call    scrloc            ; get screen offset into ax
  7310.     mov    cx,ax            ; save it in cx for a minute
  7311.     add    cx,2
  7312.     sar    cx,1            ; in 16-bit words please
  7313.     push    di            ; Save some more acs
  7314.     push    es
  7315.     les    di,vs_ptr        ; seg and offset of vscreen
  7316.     cld
  7317. revsc1:    mov    ax,es:[di]        ; fetch a word
  7318.     mov    bl,al            ; save the character
  7319.     call    revideo            ; get reversed video attributes (AH)
  7320.     mov    al,bl            ; restore character
  7321.     stosw                ; stuff into screen memory
  7322.     loop    revsc1            ; loop for entire screen
  7323.     pop    es            ; restore segment register
  7324.     pop    di            ; and destination index
  7325.     pop    dx
  7326.     pop    cx
  7327.     pop    bx
  7328.     call    repaint
  7329.     pop    ax
  7330.     ret
  7331. revscn    endp
  7332.  
  7333. ; Set coloring attributes.
  7334. ; Enter with AH holding current video attribute byte,
  7335. ; BL holding ANSI color code (30-37 or 40-47) where 30's are foreground,
  7336. ; 40's are background. ANSI colors are 1 = red, 2 = green, 4 = blue.
  7337. ; Return new attribute byte in AH.
  7338.  
  7339. setcolor proc    near
  7340.     test    extattr,att_rev        ; normal video currently?
  7341.     jz    setcol0            ; z = yes
  7342.     mov    al,ah            ; make a copy
  7343.     and    ax,7788h        ; strip bold,blink, keep both in al
  7344.     rol    ah,1            ; get colors in right parts
  7345.     rol    ah,1            ;  of ah = back, al = foreground
  7346.     rol    ah,1
  7347.     rol    ah,1
  7348.     call    setcol0            ; set fore or background color
  7349.     rol    ah,1            ; reverse coloring again
  7350.     rol    ah,1
  7351.     rol    ah,1
  7352.     rol    ah,1
  7353.     or    ah,al            ; put back blink and bold
  7354.     ret
  7355.  
  7356. setcol0:cmp    bl,30            ; ANSI color series?
  7357.     jb    setcol7            ; b = no
  7358.     cmp    bl,37            ; foreground set (30-37)?
  7359.     ja    setcol4            ; a = no, try background set
  7360.     sub    bl,30            ; take away the bias
  7361.     and    ah,not 07H        ; clear foreground bits
  7362.     test    bl,1            ; ANSI red?
  7363.     jz    setcol1            ; z = no
  7364.     or    ah,4            ; IBM red foreground bit
  7365. setcol1:test    bl,2            ; ANSI & IBM green?
  7366.     jz    setcol2            ; z = no
  7367.     or    ah,2            ; IBM green foreground bit
  7368. setcol2:test    bl,4            ; ANSI blue?
  7369.     jz    setcol3            ; z = no
  7370.     or    ah,1            ; IBM blue foreground bit
  7371. setcol3:ret
  7372.  
  7373. setcol4:cmp    bl,40            ; background color set?
  7374.     jb    setcol7            ; b = no
  7375.     cmp    bl,47            ; background set is 40-47
  7376.     ja    setcol7            ; nb = no, not a color command
  7377.     sub    bl,40            ; take away the bias
  7378.     and    ah,not 70H        ; clear background bits
  7379.     test    bl,1            ; ANSI red?
  7380.     jz    setcol5            ; z = no
  7381.     or    ah,40h            ; IBM red background bit
  7382. setcol5:test    bl,2            ; ANSI & IBM green?
  7383.     jz    setcol6            ; z = no
  7384.     or    ah,20h            ; IBM green background bit
  7385. setcol6:test    bl,4            ; ANSI blue?
  7386.     jz    setcol7            ; z = no
  7387.     or    ah,10h            ; IBM blue background bit
  7388. setcol7:ret
  7389. setcolor endp
  7390.  
  7391. ifndef    no_tcp
  7392. ; Save terminal emulator, session is in BX.
  7393. ; Delete older save buffer for this session, so that compressed vscreen
  7394. ; can be saved properly.
  7395. termswapout proc far
  7396.     cmp    bx,6            ; legal session number?
  7397.     jb    termso0            ; b = yes
  7398.     stc
  7399.     ret
  7400. termso0:push    ax
  7401.     push    bx
  7402.     push    cx
  7403.     push    si
  7404.     push    di
  7405.     shl    bx,1            ; to words
  7406.     mov    temp,bx            ; save session ident
  7407.     cmp    tsave[bx],0        ; have a storage buffer?
  7408.     je    termso9            ; ne = no, create one now
  7409.     shr    bx,1            ; get original BL session indicator
  7410.     call    termswapdel        ; delete old save area
  7411.     shl    bx,1            ; restore word indexing
  7412. termso9:
  7413. ifndef    no_graphics
  7414.     mov    ax,31*2            ; softlist, 31 words
  7415. else
  7416.     xor    ax,ax
  7417. endif    ; no_graphics
  7418.     call    getvssize        ; get size of vscreen, compressed
  7419.     add    ax,bx            ; accumulate new from bx
  7420.     call    getvasize        ; size of attributes
  7421.     add    bx,ax            ; new total to bx
  7422.     add    bx,savexlen        ; plus length of MSX save area
  7423.     add    bx,saveylen        ; plus MSY save area
  7424.     add    bx,savezlen        ; plus MSZ area
  7425.     add    bx,saveplen        ; plus parser in MSSCMD
  7426.     add    bx,saveulen        ; plus MSU area
  7427. ifndef    no_graphics
  7428.     add    bx,saveglen        ; plus MSG area
  7429. endif    ; no_graphics
  7430.     add    bx,15            ; round up
  7431.     mov    cl,4
  7432.     shr    bx,cl            ; convert to paragraphs
  7433.     mov    cx,bx            ; save request in cx
  7434.     mov    ah,alloc        ; please, more space
  7435.     int    dos            ; paragraph to ax, num paras to bx
  7436.     cmp    bx,cx            ; given vs wanted
  7437.     jae    termso1            ; ae = got it
  7438.     pop    di
  7439.     pop    si
  7440.     pop    cx
  7441.     pop    bx
  7442.     pop    ax
  7443.     stc                ; fail
  7444.     ret
  7445. termso1:
  7446. ifndef    no_graphics
  7447.     push    temp
  7448.     push    ax
  7449.     call    tekend            ; exit graphics mode
  7450.     pop    ax
  7451.     pop    temp
  7452. endif    ; no_graphics
  7453.     mov    bx,temp            ; get 2 * session number (sescur)
  7454.     mov    tsave[bx],ax        ; save starting paragraph
  7455.  
  7456.     push    es
  7457.     mov    es,ax            ; save area is destination
  7458.     xor    di,di            ; offset of save area
  7459. ifndef    no_graphics
  7460.     mov    si,seg softlist        ; where softlist lives
  7461.     push    ds
  7462.     mov    ds,si
  7463.     mov    si,offset softlist
  7464.     mov    cx,31            ; number of entries
  7465.     cld
  7466.     rep    movsw            ; save segs of soft font in msgibm
  7467.     pop    ds
  7468. endif    ; no_graphics
  7469.  
  7470.     push    es            ; save tsave seg
  7471.     push    di            ; save current dest ptr
  7472.     mov    cx,ds
  7473.     mov    es,cx
  7474.     mov    cx,size flginfo        ; length of saved flags array
  7475.     mov    di,offset saveflag    ; saved array
  7476.     mov    si,offset flags        ; working array
  7477.     rep    movsb            ; save
  7478.     pop    di            ; tsave dest offset
  7479.     pop    es            ; tsave seg
  7480.  
  7481. ; virtual screen is saved as structure
  7482. ; scr-len    dw    text screen length (typically 24 lines)
  7483. ; with the items below repeated for each line (scr-len total lines)
  7484. ; per-line    dw    saved chars on this line
  7485. ;        dw    per-line dup (char & attribute)
  7486. ; with the last saved char on each line being repeated to endofline on screen
  7487.     push    bx            ; virtual screen saving
  7488.     mov    cl,crt_lins        ; number of screen lines - 1
  7489.     inc    cl            ; add status line to save block
  7490.     xor    ch,ch
  7491.     mov    ax,cx
  7492.     cld
  7493.     stosw                ; store screen length as first word
  7494.     xor    bx,bx            ; line counter
  7495.     mov    si,word ptr vs_ptr    ; offset of vscreen
  7496. termso3:push    cx            ; save line loop counter
  7497.     mov    cx,word ptr rdbuf[bx]    ; get number of saveable chars on line
  7498.     mov    ax,cx            ; store char count as first word
  7499.     stosw
  7500.     mov    ax,word ptr vs_ptr+2    ; get vscreen segment
  7501.     push    si
  7502.     push    ds
  7503.     mov    ds,ax
  7504.     rep    movsw            ; copy saveable chars
  7505.     pop    ds
  7506.     pop    si
  7507.     pop    cx            ; recover line counter
  7508.     add    bx,2            ; next line, get length info
  7509.     add    si,vswidth*2        ; next line, offset of vscreen line
  7510.     loop    termso3
  7511.     pop    bx            ; end of vscreen saving
  7512.                     ;
  7513.     push    bx            ; virtual screen saving
  7514.     mov    cl,crt_lins        ; number of screen lines - 1
  7515.     inc    cl            ; do all lines
  7516. termso3b:xor    ch,ch
  7517.     mov    ax,cx
  7518.     cld
  7519.     stosw                ; store screen length as first word
  7520.     xor    bx,bx            ; line counter
  7521.     mov    si,word ptr vsat_ptr    ; offset of vsattr
  7522. termso7:push    cx            ; save line loop counter
  7523.     mov    cx,word ptr rdbuf[bx+120]; get num of saveable bytes on line
  7524.     mov    ax,cx            ; store char count as first word
  7525.     stosw
  7526.     mov    ax,word ptr vsat_ptr+2    ; get vsattr segment
  7527.     push    si
  7528.     push    ds
  7529.     mov    ds,ax
  7530.     shr    cx,1            ; get odd byte count info
  7531.     jnc    termso7a        ; nc = even count
  7532.     movsb
  7533. termso7a:rep    movsw            ; copy saveable bytes
  7534.     pop    ds
  7535.     pop    si
  7536.     pop    cx            ; recover line counter
  7537.     add    bx,2            ; next line, get length info
  7538.     add    si,vswidth        ; next line, offset of vsattr line
  7539.     loop    termso7
  7540.     pop    bx            ; end of vsattr saving
  7541.                     ;
  7542.     mov    si,offset saveyoff    ; offset of MSY save area
  7543.     mov    cx,saveylen        ; length of MSY save area
  7544.     cld
  7545.     shr    cx,1            ; even/odd?
  7546.     jnc    termso4            ; nc = even
  7547.     movsb                ; the odd byte
  7548. termso4:rep    movsw
  7549.     mov    si,offset savezoff    ; offset of MSZ save area
  7550.     mov    cx,savezlen        ; length of MSZ save area
  7551.     shr    cx,1
  7552.     jnc    termso5
  7553.     movsb
  7554. termso5:rep    movsw
  7555.     mov    si,offset savexoff    ; offset of MSX save area
  7556.     mov    cx,savexlen        ; length of MSX save area
  7557.     cld
  7558.     cli                ; cautious about serial ints
  7559.     shr    cx,1            ; even/odd?
  7560.     jnc    termso6            ; nc = even
  7561.     movsb                ; the odd byte
  7562. termso6:rep    movsw
  7563.     sti
  7564.     mov    si,offset savepoff    ; offset of MSSCMD parser save area
  7565.     mov    cx,saveplen        ; length of the area
  7566.     shr    cx,1
  7567.     jnc    termso6a
  7568.     movsb
  7569. termso6a:rep    movsw
  7570.     mov    si,offset saveuoff    ; offset of MSUIBM kbd save area
  7571.     mov    cx,saveulen        ; length of the area
  7572.     shr    cx,1
  7573.     jnc    termso6b
  7574.     movsb
  7575. termso6b:rep    movsw
  7576.  
  7577. ifndef    no_graphics
  7578.     mov    si,offset savegoff    ; offset of MSG save area
  7579.     mov    cx,saveglen        ; length of MSG save area
  7580.     shr    cx,1            ; graphics mode exited above
  7581.     jnc    termso6c
  7582.     movsb
  7583. termso6c:rep    movsw
  7584. endif    ; no_graphics
  7585.     pop    es
  7586.     mov    ax,100h            ; assume using 80 col screen
  7587.     cmp    dos_cols,80        ; startup screen width
  7588.     jbe    termso8            ; be = assume 80 columns
  7589.     inc    al            ; say do 132 columns
  7590. termso8:push    vtemu.vtflgop
  7591.     or    vtemu.vtflgop,vscompress ; turn off compressed mode
  7592.     call    chgdsp            ; reset display width to startup
  7593.     pop    vtemu.vtflgop
  7594.     pop    di
  7595.     pop    si
  7596.     pop    cx
  7597.     pop    bx
  7598.     pop    ax
  7599.     clc
  7600.     ret
  7601. termswapout endp
  7602.  
  7603. ; Restore terminal emulator, session is BX
  7604. ; Delete save buffer after restoration.
  7605. termswapin proc    far
  7606.     cmp    bx,6            ; valid session?
  7607.     jb    termsi0            ; b = yes
  7608.     stc
  7609.     ret
  7610. termsi0:push    bx
  7611.     shl    bx,1            ; to words
  7612.     cmp    tsave[bx],0        ; have a storage buffer?
  7613.     pop    bx
  7614.     jne    termsi1            ; ne = yes, use it
  7615.     mov    vtinited,0        ; say not inited
  7616.     stc                ; fail
  7617.     ret
  7618.  
  7619. termsi1:push    ax
  7620.     push    bx
  7621.     push    cx
  7622.     push    si
  7623.     push    di
  7624.     push    es            ; virtual screen restore
  7625. ifndef    no_graphics
  7626.     test    tekflg,tek_active    ; current graphics mode status
  7627.     jz    tswapin1a        ; z = not in graphics mode
  7628.     push    bx
  7629.     call    tekend
  7630.     pop    bx
  7631. endif    ; no_graphics
  7632. tswapin1a:
  7633.     shl    bx,1            ; address words
  7634.     mov    ax,tsave[bx]        ; starting paragraph for save area
  7635.     push    ds
  7636.     mov    ds,ax            ; save area is source
  7637.     xor    si,si            ; offset of save area
  7638. ifndef    no_graphics
  7639.     mov    di,seg softlist        ; seg of destination
  7640.     mov    es,di
  7641.     mov    di,offset softlist
  7642.     mov    cx,31            ; number of entries
  7643.     cld
  7644.     rep    movsw            ; restore segs of soft font in msgibm
  7645. endif    ; no_graphics
  7646.     pop    ds
  7647.  
  7648.     les    di,vs_ptr        ; seg and offset of vscreen
  7649.     mov    ax,tsave[bx]        ; starting paragraph of save area
  7650.     push    ds
  7651.     mov    ds,ax            ; source segment is save area
  7652.     lodsw                ; get screen length
  7653.     mov    cx,ax            ; counter of vscreen lines to do
  7654. tswapi2:push    cx            ; save line counter
  7655.     lodsw                ; get count of saved chars of line
  7656.     dec    ax            ; omit repeated char til next step
  7657.     mov    cx,ax            ; count for saved char writes
  7658.     rep    movsw            ; copy saved chars except last one
  7659.     mov    cx,vswidth        ; total line width (chars)
  7660.     sub    cx,ax            ; minus those done
  7661.     lodsw                ; get last char (this repeats to end)
  7662.     rep    stosw            ; repeat last char
  7663.     pop    cx            ; recover line counter
  7664.     loop    tswapi2            ; do all text lines (omit status)
  7665.     pop    ds            ; restore DS, SI is ready for nxt grp
  7666.                     ; end of virtual screen restoration
  7667.                     ; attributes, vsatt, for vscreen
  7668.     les    di,vsat_ptr        ; seg and offset of vsatt
  7669.     mov    ax,tsave[bx]        ; starting paragraph of save area
  7670.     push    ds
  7671.     mov    ds,ax            ; source segment is save area
  7672.     lodsw                ; get screen length
  7673.     mov    cx,ax            ; counter of vsattr lines to do
  7674. tswapi7:push    cx            ; save line counter
  7675.     lodsw                ; get count of saved bytes of line
  7676.     dec    ax            ; omit repeated byte til next step
  7677.     mov    cx,ax            ; count for saved byte writes
  7678.     shr    cx,1            ; do odd byte copy
  7679.     jnc    tswapi7a        ; nc = even count
  7680.     movsb
  7681. tswapi7a:rep    movsw            ; copy saved bytes except last one
  7682.     mov    cx,vswidth        ; total line width (bytes)
  7683.     sub    cx,ax            ; minus those done
  7684.     lodsb                ; get last byte (this repeats to end)
  7685.     rep    stosb            ; repeat last byte
  7686.     pop    cx            ; recover line counter
  7687.     loop    tswapi7            ; do all text lines (omit status)
  7688.     pop    ds            ; restore DS, SI is ready for nxt grp
  7689.                     ; end of virtual screen restoration
  7690.  
  7691.     mov    ax,ds            ; regular data seg "data"
  7692.     mov    es,ax            ; new data seg
  7693.     mov    di,offset saveyoff    ; offset of MSY save area
  7694.     mov    cx,saveylen        ; length of MSY save area
  7695.     mov    ax,tsave[bx]        ; starting paragraph of save area
  7696.     push    ds
  7697.     mov    ds,ax            ; source segment is save area
  7698.     cld
  7699.     shr    cx,1            ; even/odd?
  7700.     jnc    termsi3            ; nc = even
  7701.     movsb                ; the odd byte
  7702. termsi3:rep    movsw
  7703.     mov    di,offset savezoff    ; offset of MSZ save area
  7704.     mov    cx,es:savezlen        ; length of MSZ save area
  7705.     shr    cx,1
  7706.     jnc    termsi4
  7707.     movsb
  7708. termsi4:rep    movsw
  7709.     mov    di,offset savexoff    ; offset of MSX save area
  7710.     mov    cx,es:savexlen        ; length of MSX save area
  7711.     cli                ; cautious about serial ints
  7712.     shr    cx,1
  7713.     jnc    termsi5
  7714.     movsb
  7715. termsi5:rep    movsw
  7716.     sti
  7717.     mov    di,offset savepoff    ; offset of MSSCMD parser area
  7718.     mov    cx,es:saveplen        ; length
  7719.     shr    cx,1
  7720.     jnc    termsi6
  7721.     movsb
  7722. termsi6:rep    movsw
  7723.     mov    di,offset saveuoff    ; offset of MSUIBM kbd area
  7724.     mov    cx,es:saveulen        ; length
  7725.     shr    cx,1
  7726.     jnc    termsi6a
  7727.     movsb
  7728. termsi6a:rep    movsw
  7729.  
  7730. ifndef    no_graphics
  7731.     mov    di,offset savegoff    ; offset of MSGIBM area
  7732.     mov    cx,es:saveglen        ; length
  7733.     shr    cx,1
  7734.     jnc    termsi8
  7735.     movsb
  7736. termsi8:rep    movsw
  7737. endif    ; no_graphics
  7738.     pop    ds
  7739.     mov    cx,ds
  7740.     mov    es,cx
  7741.     mov    cx,size flginfo        ; length of saved flags array
  7742.     mov    si,offset saveflag    ; saved array
  7743.     mov    di,offset flags        ; working array
  7744.     rep    movsb            ; restore
  7745.     mov    ah,savattr        ; get saved coloring
  7746.     mov    scbattr,ah        ; replace what DOS may have used
  7747.     and    tekflg,not tek_active    ; say graphics is not active
  7748.     pop    es
  7749.     pop    di
  7750.     pop    si
  7751.     pop    cx
  7752.     pop    bx
  7753.     pop    ax
  7754.     call    termswapdel        ; delete this saved area, BL=session
  7755.     clc
  7756.     ret
  7757. termswapin endp
  7758.  
  7759. ; Remove saved terminal emulator buffers, BX is sescur (-1 means all)
  7760. termswapdel proc far
  7761.     cmp    bx,-1            ; all?
  7762.     jne    tswapdw            ; ne = no, just one
  7763.     mov    cx,6            ; number of possible sessions
  7764.     push    bx
  7765.     xor    bx,bx            ; session index
  7766. tswapd1:call    tswapdw            ; delete bufs for this session (BX)
  7767.     inc    bx
  7768.     loop    tswapd1            ; and all others
  7769.     pop    bx
  7770.     ret
  7771.  
  7772. tswapdw    proc    far            ; worker within termswapdel
  7773.     push    ax            ; delete session BX
  7774.     push    bx
  7775.     cmp    bx,5            ; largest session
  7776.     ja    tswapd2            ; a = illegal, ignore
  7777.     shl    bx,1            ; to words
  7778.     xor    ax,ax            ; clearing indicator
  7779.     xchg    ax,tsave[bx]        ; paragraph of save area
  7780.     or    ax,ax            ; anything there?
  7781.     jnz    tswapd3            ; nz = yes
  7782. tswapd2:pop    bx
  7783.     pop    ax
  7784.     stc
  7785.     ret
  7786.  
  7787. tswapd3:
  7788. ifndef    no_graphics
  7789.     push    es
  7790.     push    ax            ; save seg of save buffer
  7791.     push    cx
  7792.     mov    es,ax            ; seg of save buffer
  7793.     xor    si,si            ; offset in save area of softlist
  7794.     mov    cx,31            ; number of entries
  7795.     cld
  7796. tswapd4:lodsw                ; saved segs of soft font in msgibm
  7797.     or    ax,ax            ; any seg defined?
  7798.     jz    tswapd5            ; z = no
  7799.     push    es
  7800.     mov    es,ax            ; set paragraph to es for DOS
  7801.     mov    ah,freemem
  7802.     int    dos
  7803.     pop    es
  7804. tswapd5:loop    tswapd4
  7805.     pop    cx
  7806.     pop    es            ; recover seg of save buffer from AX
  7807.     mov    ah,freemem        ; free the memory
  7808.     int    dos
  7809.     pop    es
  7810. endif    ; no_graphics
  7811.  
  7812.     pop    bx
  7813.     pop    ax
  7814.     clc
  7815.     ret
  7816. tswapdw    endp
  7817.  
  7818. termswapdel endp
  7819.  
  7820. ; Examine vscreen line by line. Count number of characters by excluding the
  7821. ; trailing repetitions (keep first example) on each line, sum them. Add to 
  7822. ; the sum a word per line to hold the count of such characters and one more 
  7823. ; word to hold the screen length.
  7824. ; Return the number of bytes in register bx for malloc-ing.
  7825. getvssize proc    near
  7826.     push    ax
  7827.     push    cx
  7828.     push    dx
  7829.     push    di
  7830.     push    es
  7831.     les    di,vs_ptr        ; pointer to vscreen
  7832.     xor    bx,bx            ; line counter
  7833.     mov    cl,crt_lins        ; lines on screen - 1
  7834.     xor    ch,ch
  7835.     inc    cl            ; add status line
  7836.     mov    dx,cx            ; accumulated count <cnt, line>
  7837.     inc    dx            ; count screen size word itself
  7838.     add    di,(vswidth - 1) * 2    ; offset of last char on the line
  7839. getvssi1:push    cx            ; save line counter
  7840.     mov    cx,vswidth-1        ; chars on line - 1
  7841.     mov    ax,es:[di]        ; get last char+attrib on the line
  7842.     push    di
  7843.     sub    di,2
  7844.     std                ; scan backward
  7845.     repe    scasw            ; scan while equal (trim trailing rpt)
  7846.     cld
  7847.     pop    di
  7848.     je    getvssi2        ; e = ended on all same char
  7849.     inc    cx            ; ne case gobbles extra char
  7850. getvssi2:inc    cx            ; count the trailing char
  7851.     mov    word ptr rdbuf[bx],cx    ; store number of words here
  7852.     add    dx,cx            ; accumulate count of chars
  7853.     add    bx,2            ; next line
  7854.     add    di,vswidth*2        ; end of next line
  7855.     pop    cx            ; line counter
  7856.     loop    getvssi1
  7857.  
  7858.     add    dx,dx            ; chars to bytes accumulated
  7859.     mov    bx,dx            ; return it in bx
  7860.     pop    es
  7861.     pop    di
  7862.     pop    dx
  7863.     pop    cx
  7864.     pop    ax
  7865.     ret
  7866. getvssize endp
  7867.  
  7868. ; Examine vsattr line by line. Count number of attributes by excluding the
  7869. ; trailing repetitions (keep first example) on each line, sum them. Add to 
  7870. ; the sum a word per line to hold the count of such characters and one more 
  7871. ; word to hold the screen length. Stores temp length indicator in
  7872. ; words rdbuf+120 et seq (one word per line).
  7873. ; Return the number of bytes in register bx for malloc-ing.
  7874. getvasize proc    near
  7875.     push    ax
  7876.     push    cx
  7877.     push    dx
  7878.     push    di
  7879.     push    es
  7880.     les    di,vsat_ptr        ; pointer to vsattr
  7881.     xor    bx,bx            ; line counter
  7882.     mov    cl,crt_lins        ; lines on normal screen - 1
  7883.     inc    cl            ; include status line
  7884.     xor    ch,ch
  7885.     mov    dx,cx            ; accumulated count <cnt, line>
  7886.     inc    dx            ; count screen size word itself
  7887.     add    dx,dx            ; convert to bytes used
  7888.     add    di,vswidth - 1        ; offset of last attrib on the line
  7889. getvasi1:push    cx            ; save line counter
  7890.     mov    cx,vswidth -1        ; bytes on line - 1
  7891.     mov    ax,es:[di]        ; get last attribute byte on the line
  7892.     push    di
  7893.     dec    di
  7894.     std                ; scan backward
  7895.     repe    scasb            ; scan while equal (trim trailing rpt)
  7896.     cld
  7897.     pop    di
  7898.     je    getvasi2        ; e = ended on all same byte
  7899.     inc    cx            ; ne case gobbles extra byte
  7900. getvasi2:inc    cx            ; count the trailing byte
  7901.     mov    word ptr rdbuf[bx+120],cx; store number of bytes here
  7902.     add    dx,cx            ; accumulate count of bytes
  7903.     add    bx,2            ; next line
  7904.     add    di,vswidth        ; end of next line
  7905.     pop    cx            ; line counter
  7906.     loop    getvasi1
  7907.     mov    bx,dx            ; return bytes needed in bx
  7908.     pop    es
  7909.     pop    di
  7910.     pop    dx
  7911.     pop    cx
  7912.     pop    ax
  7913.     ret
  7914. getvasize endp
  7915. endif    ; no_tcp
  7916.  
  7917. ;
  7918. ; CHKDSP - procedure to check for hardware support of 132 cols
  7919. ;  Supported hardware:
  7920. ;  ATI EGA and VGA Wonder
  7921. ;  AT&T
  7922. ;  Everex Viewpoint EV-659, FVGA-673, EV-678, Micro Enhancer Deluxe
  7923. ;  IBM XGA
  7924. ;  Paradise AutoSwitch EGA Mono, VGA Professional, VGA Plus, VGA Plus 16
  7925. ;  STB VGA/EM (Tseng TVGA)
  7926. ;  STB VGA/EM Plus (Tseng 4000), VGA/EM-16, VGA/EM-16 Plus
  7927. ;  Tseng Labs EVA board w/132-col kit installed
  7928. ;  Tseng Labs UltraPAK mono/Herc board w/132 column modes.
  7929. ;  Tseng Labs ET4000 SVGA.
  7930. ;  VESA compatible Bios'.
  7931. ;  Video 7 Vega Deluxe w/ 132X25.COM driver installed and VGA board.
  7932. ; The routine checks for the presence of a 132-column-capable adapter. If
  7933. ; one is found its handler executes the desired mode setting and returns
  7934. ; carry clear; it returns carry set otherwise.
  7935. ; Adding new boards - place an identification string in the data segment,
  7936. ; construct a mode setting routine and insert it in the call list below
  7937. ; (setting 132 column mode is byte AL non-zero). Byte AH is non-zero to
  7938. ; avoid saving old screen and running scrini; it is used to set the screen
  7939. ; width when starting/exiting Connect mode
  7940. ;
  7941. chgdsp    proc    near
  7942. ifndef    no_graphics
  7943.     or    al,al            ; 80 column mode?
  7944.     jnz    chgdsg1            ; nz = no, want 132 cols
  7945.     test    tekflg,tek_active    ; graphics mode active?
  7946.     jz    chgdsp_start        ; z = no
  7947.     push    ax
  7948.     push    dx
  7949.     call    tekend            ; exit special graphics
  7950.     call    scrmod            ; update video mode info
  7951.     pop    dx
  7952.     pop    ax
  7953.     jmp    short chgdsp_start    ; set 80 col mode
  7954.  
  7955. chgdsg1:test    vtemu.vtflgop,vscompress ; allowed to use graphics for it?
  7956.     jnz    chgdsp_start        ; nz = no, use 132 column text mode
  7957.     cmp    tekflg,tek_active+tek_sg ; special graphics mode active?
  7958.     je    chgdsg3            ; e = yes, no change needed
  7959.     mov    cl,byte ptr low_rgt+1    ; examine whole screen
  7960.     add    cl,2            ; lines in emulation part + status
  7961.     xor    ch,ch
  7962.     xor    bx,bx
  7963. chgdsg2:or    dgwindcomp[bx],1    ; set compressed mode flag non-zero
  7964.     inc    bx
  7965.     loop    chgdsg2
  7966.     call    dgsettek        ; setup special graphics mode
  7967. chgdsg3:mov    byte ptr low_rgt,131    ; 132 columns in special graphics
  7968.     mov    crt_cols,128        ; but 128 physical columns
  7969.     ret
  7970. endif    ; no_graphics
  7971.  
  7972. chgdsp_start:
  7973.     push    es            ; save all we use
  7974.     push    ax
  7975.     push    bx
  7976.     push    cx
  7977.     push    dx
  7978.     push    si
  7979.     push    di
  7980.     mov    temp,ax            ; save set/reset flag from msz
  7981.     mov    ax,sp            ; do push sp test for XT vs AT/386
  7982.     push    sp            ; XT pushes sp-2, AT's push old sp
  7983.     pop    cx            ; recover pushed value, clean stack
  7984.     xor    ax,cx            ; same?
  7985.     jne    chgdspnw        ; ne = no, XT. Don't do Int 2fh
  7986.     test    tv_mode,10h        ; DESQview active?
  7987.     jz    chgdspndv        ; z = no
  7988.     jmp    chgdsx1            ; exit without screen change
  7989. chgdspndv:
  7990.     cmp    vchgmode,1        ; change permissions, disabled?
  7991.     je    chgdspnw        ; e = 1 = disabled
  7992.     mov    ax,1683h        ; Windows 3, get current virt machine
  7993.     int    2fh
  7994.     cmp    ax,1683h        ; virtual machine, if any
  7995.     je    chgdspok        ; e = none
  7996.     cmp    vchgmode,2        ; DOS-only (2)?
  7997.     jne    chgdspok        ; ne = no
  7998. chgdspnw:jmp    chgdsx1            ; exit without screen change
  7999. chgdspok:mov    ax,temp
  8000.     cmp    crt_cols,80        ; are we narrow?
  8001.     jbe    chgds3            ; be = narrow width now
  8002.     or    al,al            ; resetting to narrow width?
  8003.     jz    chgds4            ; z = yes, do it
  8004.     jmp    chgdsx1            ; else we are there now
  8005. chgds3:    or    al,al            ; resetting to narrow width?
  8006.     jnz    chgds4            ; nz = no, setting to wide
  8007.     jmp    chgdsx1            ; narrow width, we are there now
  8008. chgds4:    or    ah,ah            ; are we connected now?
  8009.     jnz    chgds0            ; nz = no, skip flow control etc
  8010.     mov    ah,flowoff        ; get xoff
  8011.     or    ah,ah            ; flow control?
  8012.     jz    chgds4a            ; z = none
  8013.     call    foutchr            ; send it
  8014. chgds4a:cmp    byte ptr temp+1,0    ; exiting Connect mode?
  8015.     jne    chgds0            ; ne = yes
  8016.     mov    ax,200            ; wait 200 millisec before video tests
  8017.     call    pcwait            ; so don't mix screen and port intrpts
  8018.  
  8019. chgds0:    call    ckteva            ; try Tseng Labs EVA
  8020.     jnc    chgds1            ; nc = found
  8021.     call    ckstbv            ; try STB VEGA/EM
  8022.     jnc    chgds1            ; nc = found
  8023.     call    ckv7vd            ; try Video 7 EGA Deluxe and VGA
  8024.     jnc    chgds1            ; nc = found
  8025.     call    ckatiw            ; try ATI EGA Wonder
  8026.     jnc    chgds1            ; nc = found
  8027.     call    ckevrx                  ; try Everex Micro Enhancer Deluxe
  8028.     jnc     chgds1                  ; nc = found
  8029.     call    ckevga            ; try Everex EVGA-673
  8030.     jnc     chgds1                  ; nc = found
  8031.     call    ckatt            ; ATT boards
  8032.     jnc    chgds1            ; nc = found
  8033.     call    chkpa            ; Paradise EGA/VGA boards
  8034.     jnc    chgds1            ; nc = found
  8035.     call    chkvesa            ; VESA compatibles
  8036.     jnc    chgds1            ; nc = found
  8037.     call    ckxga            ; IBM XGA
  8038.     jnc    chgds1            ; nc = found
  8039.     mov    si,offset cols80    ; name of 80 column file
  8040.     cmp    byte ptr temp,0        ; setting 80 cols?
  8041.     je    chgdsx2            ; e = yes
  8042.     mov    si,offset cols132    ; use 132 column file
  8043. chgdsx2:mov    di,offset decbuf    ; a temp buffer for path= usage
  8044.     call    strcpy
  8045.     mov    ax,di            ; spath wants ptr in ax
  8046.     call    fspath
  8047.     jc    chgdsx            ; c = file not found
  8048.     mov    si,ax            ; crun wants ptr in si
  8049.     call    fcrun            ; run the batch file, si = filespec
  8050.     call    fserini            ; reengage serial port, mode changes
  8051.     mov    ax,0c06h        ; clear kbd buffer and do function
  8052.     mov    dl,0ffh            ; console input
  8053.     int    dos            ; discard character(s)
  8054.                     ; Perform mode change
  8055. chgds1:    cmp    byte ptr temp+1,0    ; do without serial port xon/xoff?
  8056.     jne    chgdsx1            ; ne = yes
  8057.     cmp    flags.modflg,1        ; is mode line enabled?
  8058.     jbe    chgdsx            ; be = yes, and off or locally owned
  8059.     mov    flags.modflg,1        ; remove foreign ownership
  8060. chgdsx:    mov    ah,flowon        ; get flow-on byte
  8061.     or    ah,ah            ; using flow control?
  8062.     jz    chgdsx1            ; z = no
  8063.     call    foutchr            ; send it
  8064. chgdsx1:mov    al,crt_lins        ; previous conditions
  8065.     mov    ah,crt_cols
  8066.     push    ax
  8067.     call    scrmod            ; pick up current screen size
  8068.     pop    ax
  8069. ifndef    no_tcp
  8070.     cmp    al,crt_lins        ; screen size change?
  8071.     jne    chgdsx1a        ; ne = yes
  8072.     cmp    ah,crt_cols
  8073.     je    chgdsx1b        ; no
  8074. chgdsx1a:call    winupdate        ; window update req for TCP/IP Telnet
  8075. chgdsx1b:
  8076. endif    ; no_tcp
  8077.     pop    di            ; restore what we saved
  8078.     pop    si
  8079.     pop    dx
  8080.     pop    cx
  8081.     pop    bx
  8082.     pop    ax
  8083.     pop    es
  8084.     ret                ; return to caller
  8085.      
  8086. ; Individual tests for various 132-column boards
  8087.                     ; Tseng LABS EVA, UltraPAK, ET4000
  8088. ckteva: mov    ax,0c000h        ; seg addr for EVA
  8089.     mov    es,ax            ; set into es register
  8090.     mov    di,76h            ; offset of board's string
  8091.     lea    si,tsngid        ; validation string
  8092.     mov    cx,tsnglen        ; length of validiation string
  8093.     cld
  8094.     repe    cmpsb            ; compare strings
  8095.     je    ckteva2            ; e = strings match
  8096.     mov    ax,4d00h        ; check for UltraPAK mono driver
  8097.     int    screen
  8098.     cmp    ax,5aa5h        ; driver signature?
  8099.      jne    ckteva4            ; ne = no
  8100.     mov    ax,7            ; default to mono (7) for this board
  8101.     cmp    byte ptr temp,0        ; setting 132 columns?
  8102.     je    ckteva1            ; e = resetting to normal
  8103.     mov    ax,18h            ; set to 132 cols (Set Mode 18H)
  8104. ckteva1:int    screen
  8105.     clc                ; carry clear means success
  8106.     ret
  8107.                     ; an EVA board - check for 132 col kit
  8108. ckteva2:cmp    byte ptr es:099h,0    ; check 132 col kit installed
  8109.     jne    catfnd            ; ne = installed, do the mode change
  8110. ckteva3:stc                ; indicate adapter not present
  8111.     ret                ; and exit
  8112.  
  8113. ckteva4:mov    dx,03cdh        ; ET4000 test
  8114.     in    al,dx            ; Segment Select Register, get value
  8115.     push    ax
  8116.     xor    al,15h            ; create test condition
  8117.     jmp    $+2
  8118.     jmp    $+2
  8119.     out    dx,al            ; set condition
  8120.     jmp    $+2
  8121.     jmp    $+2
  8122.     mov    ah,al            ; save condition
  8123.     in    al,dx            ; get new condition
  8124.     jmp    $+2
  8125.     jmp    $+2
  8126.     cmp    ah,al            ; did it work (same)?
  8127.     pop    ax
  8128.     out    dx,al            ; restore original condition
  8129.     jne    ckteva3            ; ne = no, ET4000 not present
  8130.     mov    ax,3            ; default to cga 3
  8131.     cmp    byte ptr temp,0        ; setting 132 columns?
  8132.     je    ckteva5            ; e = resetting to normal
  8133.     mov    ax,23h            ; set to 132 cols (Set Mode 23H)
  8134. ckteva5:int    screen
  8135.     clc
  8136.     ret
  8137.                     ;
  8138. ckstbv:    mov    ax,0c000h        ; STB's VGA/EM, VGA/EM-16, EM-16 Plus
  8139.     mov    es,ax            ;
  8140.     mov    di,70h            ; where to look for signature
  8141.     lea    si,stbvid        ; the signature
  8142.     mov    cx,stbvlen        ;
  8143.     cld                ;
  8144.     repe    cmpsb            ; test
  8145.     je    catfnd            ; e = found
  8146.     mov    di,70h            ; where to look for signature
  8147.     lea    si,stavid        ; the signature
  8148.     mov    cx,stavlen
  8149.     cld
  8150.     repe    cmpsb            ; test
  8151.     je    catfnd            ; e = found
  8152.     stc                ; else say not there
  8153.     ret                ;
  8154.                     ; ATI EGA Wonder
  8155. ckatiw:    mov    ax,0c000h        ; seg addr for EGA Wonder
  8156.     mov    es,ax            ; set into es register
  8157.     mov    di,012fh        ; offset of message in ROM
  8158.     lea    si,atiwid        ; offset of message here
  8159.     mov    cx,atilen        ; length of validation string
  8160.     cld
  8161.     repe    cmpsb            ; compare strings
  8162.     je    catfnd            ; e = they match
  8163.     lea    si,atiwid2        ; alternative signature
  8164.     mov    di,30h            ; start at this offset
  8165.     mov    cx,atilen2        ; alternative signature length
  8166.     mov    ax,es:[di]        ; get first two bytes
  8167.     cmp    al,atiwid2        ; string starts here?
  8168.      je    ckatiw1            ; e = yes
  8169.     inc    di            ; try next location, just in case
  8170.     cmp    ah,atiwid2        ; or here?
  8171.     je    ckatiw1            ; e = yes
  8172.     stc                ; strings differ
  8173.     ret
  8174. ckatiw1:repe    cmpsb            ; check the whole string
  8175.     je    catfnd            ; e = matches the whole thing
  8176.     stc                ; fail on mismatch
  8177.     ret
  8178. catfnd:    mov    ax,0003h        ; prepare to reset video mode
  8179.     cmp    byte ptr temp,0        ; are we setting or resetting?
  8180.     je    catfnd1            ; e is reset, exit
  8181.     mov    ax,0023h        ; set to 132 cols (Set Mode 23H)
  8182. catfnd1:int    screen
  8183.     clc                ; carry clear means success
  8184.     ret
  8185.  
  8186. chkpa:    mov    ax,0c000h        ; load Paradise ROM BIOS address
  8187.     mov    es,ax
  8188.     mov    ax,0057h        ; assume 132x25 mono display needed
  8189.     mov    di,0009h        ; load EGA board identifier index
  8190.     lea    si,pmega1        ; Paradise Autoswitch Mono ident
  8191.     mov    cx,pmegal1
  8192.     cld
  8193.     repe    cmpsb            ; do identification strings match?
  8194.     je    chgpa2            ; e = yes, check num of display lines
  8195.     mov    di,007dh        ; no, load VGA board identifier index
  8196.     lea    si,p30id        ; Paradise VGA, other flavors
  8197.     mov    cx,p30ln
  8198.     repe    cmpsb            ; do identification strings match?
  8199.     je    chgpa1            ; e = yes, check for color mode
  8200.     stc                ; fail
  8201.     ret
  8202. chgpa1:    cmp    crt_norm,3        ; is the "normal" screen in color?
  8203.     ja    chgpa2            ; a = no, orig assumption is correct
  8204.     mov    ax,0055h        ; assume 132x25 color required
  8205. chgpa2:    cmp    crt_lins,25        ; is the "normal" screen 25 lines?
  8206.     jna    chgpa3            ; na = yes, check num of cols needed
  8207.     dec    ax            ; change assumption to 132x43
  8208. chgpa3:    cmp    byte ptr temp,0        ; switching to a 132 column mode?
  8209.     jne    chgpa4            ; ne = yes
  8210.     mov    al,crt_norm        ; load "normal" display mode
  8211. chgpa4:    int    screen            ; issue BIOS call to change display
  8212.     clc                ; success
  8213.     ret
  8214.                     ; Video 7 Vega Deluxe
  8215. ckv7vd:    mov    ax,0c000h        ; seg addr for Vega rom bios
  8216.     mov    es,ax            ; set into es register
  8217.     mov    di,002ah        ; offset of message in ROM
  8218.     lea    si,vid7id        ; offset of message here
  8219.     mov    cx,vid7len
  8220.     cld
  8221.     repe    cmpsb            ; compare strings
  8222.     je    cnv7fn1            ; e = same
  8223.     mov    di,002ah        ; offset of ident string
  8224.     mov    si,offset vid7id2    ; Video 7 VGA board
  8225.     mov    cx,vid7len2
  8226.     repe    cmpsb
  8227.     je    cnv7fn2            ; e = found
  8228. cnv7fx:    stc                ; strings are different
  8229.     ret
  8230.                     ;
  8231. cnv7fn1:test    byte ptr es:[03ffeh],1    ; is this a 'Deluxe' Vega?
  8232.     jz    cnv7fx            ; z = nope, can't do it
  8233.     mov    ah,35h            ; DOS Get Vector
  8234.     mov    al,10h            ; Bios video interrupt
  8235.     int    dos            ; get it into es:bx
  8236.     mov    di,bx            ; es:bx is returned int 10h entry pnt
  8237.     sub    di,5ah            ; back offset to msg in 132X25.COM
  8238.     lea    si,vid7id        ; offset of validation message
  8239.     mov    cx,vid7len        ; length of validation string
  8240.     cld
  8241.     repe    cmpsb            ; Look for repeat of msg by 132X25.COM
  8242.     jne    cnv7fn2            ; if different
  8243.     mov    al,crt_mode        ; prepare to reset video mode
  8244.     xor    ah,ah
  8245.     cmp    byte ptr temp,0        ; are we setting or resetting?
  8246.     je    cnv7fn2a        ; e is reset
  8247.     mov    ax,0000h        ; set to 132 cols (old 40x25)
  8248. cnv7fn1a:int    screen
  8249.     clc
  8250.     ret
  8251.  
  8252. cnv7fn2:mov    ax,6f00h        ; check for VegaBios driver
  8253.     int    screen
  8254.     cmp    bx,'V7'            ; Video 7 Bios presence response
  8255.     jne    cnv7fx            ; ne = not there
  8256.     mov    ax,6f01h        ; al gets monitor type (mono,color,ega)
  8257.     int    screen
  8258.     mov    bx,51h            ; presume mono 132x25, page 0
  8259.     cmp    crt_lins,42        ; 43 lines active?
  8260.     jb    cnv7fn2a        ; b = no
  8261.     inc    bx            ; use bx = 52h for 132x43
  8262. cnv7fn2a:
  8263.     cmp    al,10h            ; analogue fixed freq (IBM 85xx)?
  8264.     je    cnv7fx            ; e = yes, no 132 columns
  8265.     cmp    al,2            ; 1 = mono, 2 = color, above = ega
  8266.     jb    cnv7fn3            ; b = mono or unknown
  8267.     mov    bx,4fh            ; presume med res color 132x25
  8268.     je    cnv7fn3            ; e = med res color, al = 2
  8269.     mov    bx,41h            ; ega high res 132x25, enhanced mons
  8270.     cmp    crt_lins,42        ; 43 lines active?
  8271.     jb    cnv7fn3            ; b = no
  8272.     inc    bx            ; use bx = 42h for 132x43
  8273. cnv7fn3:mov    ax,6f05h        ; set special mode found in bl
  8274.     cmp    byte ptr temp,0        ; resetting to 80 column mode?
  8275.     jne    cnv7fn4            ; ne = no, setting 132x25
  8276.     mov    al,crt_norm        ; get normal mode
  8277.     xor    ah,ah            ; set mode
  8278.     cmp    crt_lins,42        ; 43 lines active?
  8279.     jb    cnv7fn4            ; b = no
  8280.     mov    bl,40h            ; use Video 7 mode 40h 80x43 for color
  8281.     mov    ax,6f05h        ; and do special mode set
  8282. cnv7fn4:int    screen            ; special mode is in bl
  8283.     mov    ax,0f00h        ; a nop screen bios command
  8284.     int    screen
  8285.     clc
  8286.     ret
  8287.  
  8288. ckevrx: mov     ax,0c000h               ; seg addr for Everex EV-659
  8289.         mov     es,ax                   ; set into es register
  8290.         mov     di,0047h                ; offset of message in ROM
  8291.         lea     si,evrxid               ; offset of message here
  8292.         mov     cx,evrxlen              ; length of validation string
  8293.         cld
  8294.         repe    cmpsb                   ; compare strings
  8295.         jne     ckfnr2                  ; ne = strings differ
  8296.         mov     ah,crt_lins             ; we recognize either 44 or 25 rows
  8297.         cmp     ah,43                   ; equal to 44-1 rows?
  8298.         jne     ckfnr1                  ; ne = no
  8299.         mov     ax,0070h                ; Everex extended mode ident
  8300.         mov     bl,09h                  ; prepare to reset video mode to 80x44
  8301.         cmp     byte ptr temp,0         ; are we setting or resetting?
  8302.         je      ckfnr4                  ; e is reset, exit
  8303.         mov     bl,0bh                  ; 132x44
  8304.     int    screen
  8305.     clc
  8306.     ret
  8307. ckfnr1: cmp     ah,24                   ; equal to 25-1 rows?
  8308.     je    ckfnr3            ; e = yes
  8309. ckfnr2:    stc                ; return failure
  8310.     ret
  8311. ckfnr3:    mov     ax,0003h                ; prepare to reset video mode
  8312.         cmp     byte ptr temp,0         ; are we setting or resetting?
  8313.         je      ckfnr4                  ; e is reset, exit
  8314.         mov     ax,0070h                ; Everex extended mode ident
  8315.         mov     bl,0ah                  ; 132x25
  8316. ckfnr4:    int    screen
  8317.     clc
  8318.     ret
  8319. ckevga:    mov    ax,0c000h        ; Everex FVGA-673, EV-678 rom segment
  8320.     mov    es,ax
  8321.     mov    di,76h            ; offset in rom for board's id string
  8322.     lea    si,evgid        ; id string
  8323.     mov    cx,evglen        ; length of id string
  8324.     cld
  8325.     repe    cmpsb            ; do they match?
  8326.     je    ckevg0            ; e = yes
  8327.     mov    di,9dh            ; offset in ROM for board's ID string
  8328.     lea    si,evvid        ; ID string
  8329.     mov    cx,evvlen        ; length of ID string
  8330.     cld
  8331.     repe    cmpsb            ; do they match?
  8332.     jne    ckevg2            ; ne = no
  8333. ckevg0:    mov    ax,3            ; prepare to reset video mode
  8334.     cmp    byte ptr temp,0        ; setting or resetting mode?
  8335.     je    ckevg1            ; e = resetting, exit
  8336.     mov    ax,0070h        ; mode for 132x25
  8337.     mov    bl,0ah            ; Everex mode 0ah
  8338. ckevg1:    int    screen
  8339.     clc
  8340.     ret
  8341. ckevg2:    stc                ; say board not found
  8342.     ret
  8343.                     ; AT&T EGA/VGA boards
  8344. ckatt:    mov    ax,0c000h        ; seg of first signature
  8345.     mov    es,ax
  8346.     mov    si,offset attvdc6    ; first pattern
  8347.     mov    di,35h            ; test area
  8348.     cld
  8349.     mov    cx,attvdlen        ; length
  8350.     repe    cmpsb
  8351.     je    ckatt2            ; e = found
  8352.     mov    cx,attvdlen        ; try second signature, same length
  8353.     mov    si,offset attvdc7
  8354.     mov    ax,0e000h        ; seg of second signature
  8355.     mov    es,ax
  8356.     mov    di,10h            ; test area
  8357.     repe    cmpsb
  8358.     je    ckatt2            ; e = found
  8359.     stc                ; not found
  8360.     ret
  8361. ckatt2:    mov    al,crt_norm        ; old mode
  8362.     xor    ah,ah
  8363.     cmp    byte ptr temp,0        ; resetting to 80 col?
  8364.     je    ckatt3            ; e = yes
  8365.     mov    ax,0055h        ; 132 cols, set mode 55h
  8366. ckatt3:    int    screen
  8367.     clc
  8368.     ret
  8369.                     ; VESA compatibles
  8370. chkvesa:mov    di,seg rdbuf        ; es:di is buffer for results
  8371.     mov    es,di
  8372.     mov    di,offset rdbuf
  8373.     mov    ax,4f00h        ; get SVGA information
  8374.     int    screen
  8375.     cmp    ax,4fh            ; success?
  8376.     jne    chkvesax        ; ne = no
  8377.     cmp    word ptr rdbuf,'EV'    ; 'VESA'
  8378.     jne    chkvesax        ; ne = no
  8379.     cmp    word ptr rdbuf+2,'AS'
  8380.     jne    chkvesax        ; ne = no
  8381.     mov    ax,4f01h        ; get mode info to es:di buffer
  8382.     mov    cx,109h            ; 109h is 132x25 text
  8383.     int    screen
  8384.     cmp    ax,4fh            ; success?
  8385.     jne    chkvesax        ; ne = no
  8386.     mov    bx,3            ; assume 80 columns
  8387.     cmp    byte ptr temp,0        ; setting or resetting mode?
  8388.     je    chkvesa2        ; e = resetting
  8389.     mov    bx,109h            ; mode for 132x25
  8390. chkvesa2:mov    ax,4f02h        ; set mode from bx
  8391.     int    screen
  8392.     cmp    ax,4fh            ; success?
  8393.     jne    chkvesax        ; ne = no
  8394.     clc                ; say success
  8395.     ret
  8396. chkvesax:stc                ; say failure
  8397.     ret
  8398.  
  8399.                     ; IBM XGA 132 columns
  8400. ckxga:    push    bp            ; (old BIOSes are still around)
  8401.     push    ds            ; set es to data segment
  8402.     pop    es
  8403.     mov    ax,1b00h        ; get functionality table
  8404.     xor    bx,bx
  8405.     mov    di,offset decbuf    ; es:di is 64 bytes of workspace
  8406.     int    screen
  8407.     cmp    al,1bh            ; is this call supported?
  8408.     jne    ckxgax            ; ne = no, fail
  8409.     les    bx,dword ptr decbuf    ; get the address of the modes info
  8410.     test    byte ptr es:[bx+2],10h    ; is mode 14h supported?
  8411.     jz    ckxman            ; z = no, try manual method for now
  8412.     mov    ax,3            ; assume resetting to mode 3, 80x25
  8413.     cmp    byte ptr temp,0        ; setting 132 columns?
  8414.     je    ckxga1            ; e = no, resetting to 80 columns
  8415.     mov    ax,14h            ; invoke IBM XGA mode 14h, 132x25
  8416. ckxga1:    int    screen
  8417. ckxga2:    pop    bp
  8418.     clc                ; say success
  8419.     ret
  8420. ckxgax:    pop    bp
  8421.     mov    xga_reg_base,-2        ; flag saying no XGA Adapter found
  8422.     stc                ; say failure
  8423.     ret
  8424.  
  8425. ckxman:    call    xgaman            ; do tests/sets manually
  8426.     pop    bp
  8427.     jnc    ckxman1            ; nc = success
  8428.     mov    xga_reg_base,-2        ; flag saying no XGA Adapter found
  8429. ckxman1:ret
  8430. chgdsp    endp
  8431.  
  8432. ; XGA mode setting via going to the hardware manually
  8433. ; Code furnished by Bert Tyler, National Institue of Health
  8434.  
  8435. xgaman    proc    near
  8436.     cmp    xga_reg_base,-2        ; has the XGA detector already failed?
  8437.     je    xgafail            ; e = yes, fail again
  8438.     cmp    xga_reg_base,-1        ; have we already found the XGA?
  8439.     je    xga_loc            ; e = no
  8440.     jmp    xga_do1            ; yes, process it
  8441. xga_loc:push    es
  8442.     mov    ah,35h            ; DOS get interrupt vector
  8443.     mov    al,15h            ; Int 15h
  8444.         int     dos                     ; returns vector in es:bx
  8445.     mov    ax,es            ; segment part
  8446.     pop    es
  8447.     or    ax,ax            ; undefined vector?
  8448.     jz    xgafail            ; z = yes
  8449.     mov    dx,-1            ; start with an invalid POS address
  8450.     mov    ax,0c400h        ; look for POS base address
  8451.     int    15h            ;  (Microchannel machines only)
  8452.     jc    xgafail            ; c = error, not a MC machine
  8453.     mov    xgatmp1,dx        ; save pos_base_address
  8454.     xor    cx,cx            ; check all MCA slots & motherboard
  8455.     cmp    dx,-1            ; do we have a good POS?
  8456.     jne    xga_lp1            ; ne = yes, proceed with MCA checks
  8457. xgafail:stc                ; fail
  8458.     ret
  8459.  
  8460. xga_lp1:cli                ; no interrupts, please
  8461.     cmp    cx,0            ; treat the motherboard differently?
  8462.     jne    xga_sk4            ; ne = yes
  8463.     mov    al,0dfh            ; enable the motherboard for setup
  8464.     mov    dx,94h
  8465.     out    dx,al
  8466.     jmp    short xga_sk5
  8467. xga_sk4:mov    ax,0c401h        ; enable an MCA slot for setup
  8468.     mov    bx,cx            ;  this slot
  8469.     int    15h
  8470. xga_sk5:mov    dx,xgatmp1        ; get pos record for the slot
  8471.     in    ax,dx            ;  ID
  8472.     mov    xgatmp2,ax
  8473.     add    dx,2            ; compute IO Res Base
  8474.     in    al,dx            ;  get POS data byte1
  8475.     and    ax,0eh            ;  muck about with it to get reg base
  8476.     shl    ax,1
  8477.     shl    ax,1
  8478.     shl    ax,1
  8479.     add    ax,2100h
  8480.     mov    xga_reg_base,ax
  8481.     cmp    cx,0            ; treat the motherboard differently?
  8482.     jne    xga_sk6            ; ne = yes
  8483.     mov    al,0ffh            ; enable the motherboard for normal
  8484.     out    094h,al
  8485.     jmp    short xga_sk7
  8486. xga_sk6:mov    ax,0c402h        ; enable the MCA slot for normal
  8487.     mov    bx,cx            ;  this slot
  8488.     int    15h
  8489. xga_sk7:sti                ; interrupts on again
  8490.  
  8491.     mov    ax,xgatmp2        ; is an XGA adapter on this slot?
  8492.     cmp    ax,08fd8h
  8493.     jae    xga_sk8            ; ae = yes
  8494.     jmp    xga_lp2            ; try another slot
  8495. xga_sk8:cmp    ax,08fdbh        ; still within range?
  8496.     jbe    xga_sk9            ; be = yes
  8497.     jmp    xga_lp2            ; no, try another slot
  8498. xga_sk9:mov    dx,xga_reg_base        ; is there a monitor on this slot?
  8499.     add    dx,0ah
  8500.     mov    al,052h
  8501.     out    dx,al
  8502.     mov    dx,xga_reg_base
  8503.     add    dx,0bh
  8504.     in    al,dx
  8505.     and    al,0fh
  8506.     cmp    al,0fh
  8507.     jne    xga_ska            ; ne = yes
  8508.     jmp    xga_lp2            ; no
  8509. xga_ska:mov    dx,xga_reg_base        ; is this XGA in VGA mode?
  8510.     in    al,dx
  8511.     test    al,1
  8512.     jnz    xga_do1            ; nz = yes, found it!
  8513.  
  8514. xga_lp2:inc    cx            ; try another adapter?
  8515.     cmp    cx,9            ; done all slots?
  8516.     ja    xga_no            ; a = yes
  8517.     jmp    xga_lp1            ; no, try another slot
  8518. xga_no:    jmp    xgafail            ; fail
  8519.  
  8520. ;    *finally* put the XGA into 132-column or 80-column mode
  8521.  
  8522. xga_do1:cmp    byte ptr temp,0        ; setting 80-column mode?
  8523.     jne    xga_do2            ; ne = no, 132 columns
  8524.     jmp    xga_do3            ; do 80 column mode
  8525.  
  8526.                     ; 132-column mode routine
  8527. xga_do2:mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8528.     add    dx,0ah
  8529.     mov    ax,1550h
  8530.     out    dx,ax
  8531.     mov    ax,1450h
  8532.     out    dx,ax
  8533.     mov    ax,0454h
  8534.     out    dx,ax
  8535.     mov    ax,1202h        ; select 400 scan lines
  8536.     mov    bl,30h
  8537.     int    screen
  8538.     mov    ax,0+3            ; set video mode 3
  8539.     int    screen
  8540.  
  8541.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8542.     add    dx,0ah
  8543.     mov    al,50h
  8544.     out    dx,al
  8545.     inc    dx
  8546.     in    al,dx
  8547.     or    al,1
  8548.     out    dx,al
  8549.  
  8550.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8551.     add    dx,0ah
  8552.     mov    al,50h
  8553.     out    dx,al
  8554.     inc    dx
  8555.     in    al,dx
  8556.     and    al,0fdh
  8557.     out    dx,al
  8558.  
  8559.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8560.     add    dx,0ah
  8561.     mov    al,50h
  8562.     out    dx,al
  8563.     inc    dx
  8564.     in    al,dx
  8565.     and    al,0fch
  8566.     out    dx,al
  8567.  
  8568.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8569.     mov    al,3
  8570.     out    dx,al
  8571.  
  8572.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8573.     add    dx,0ah
  8574.     mov    ax,0154h
  8575.     out    dx,ax
  8576.     mov    ax,8070h
  8577.     out    dx,ax
  8578.  
  8579.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8580.     add    dx,0ah
  8581.     mov    al,50h
  8582.     out    dx,al
  8583.     inc    dx
  8584.     in    al,dx
  8585.     and    al,0efh
  8586.     out    dx,al
  8587.  
  8588.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8589.     mov    ax,11h
  8590.     out    dx,al
  8591.     inc    dx
  8592.     in    al,dx
  8593.     and    al,7fh
  8594.     out    dx,al
  8595.  
  8596.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8597.     mov    ax,0
  8598.     out    dx,al
  8599.     inc    dx
  8600.     mov    ax,0a4h
  8601.     out    dx,al
  8602.  
  8603.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8604.     mov    ax,1
  8605.     out    dx,al
  8606.     inc    dx
  8607.     mov    ax,83h
  8608.     out    dx,al
  8609.  
  8610.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8611.     mov    ax,2
  8612.     out    dx,al
  8613.     inc    dx
  8614.     mov    ax,84h
  8615.     out    dx,al
  8616.  
  8617.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8618.     mov    ax,3
  8619.     out    dx,al
  8620.     inc    dx
  8621.     mov    ax,83h
  8622.     out    dx,al
  8623.  
  8624.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8625.     mov    ax,4
  8626.     out    dx,al
  8627.     inc    dx
  8628.     mov    ax,90h
  8629.     out    dx,al
  8630.  
  8631.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8632.     mov    ax,5
  8633.     out    dx,al
  8634.     inc    dx
  8635.     mov    ax,80h
  8636.     out    dx,al
  8637.  
  8638.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8639.     add    dx,0ah
  8640.     mov    ax,0a31ah
  8641.     out    dx,ax
  8642.     mov    ax,001bh
  8643.     out    dx,ax
  8644.  
  8645.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8646.     mov    ax,13h
  8647.     out    dx,al
  8648.     inc    dx
  8649.     mov    ax,42h
  8650.     out    dx,al
  8651.  
  8652.     mov    dx,03d4h        ; (the manual doesn't explain...)
  8653.     mov    al,11h
  8654.     out    dx,al
  8655.     inc    dx
  8656.     in    al,dx
  8657.     or    al,80h
  8658.     out    dx,al
  8659.  
  8660.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8661.     add    dx,0ah
  8662.     mov    al,50h
  8663.     out    dx,al
  8664.     inc    dx
  8665.     in    al,dx
  8666.     or    al,3
  8667.     out    dx,al
  8668.  
  8669.     mov    dx,03c4h        ; (the manual doesn't explain...)
  8670.     mov    ax,1
  8671.     out    dx,al
  8672.     inc    dx
  8673.     in    al,dx
  8674.     or    al,1
  8675.     out    dx,al
  8676.  
  8677.     mov    dx,03dah        ; (the manual doesn't explain...)
  8678.     in    al,dx
  8679.  
  8680.     mov    dx,003c0h        ; (the manual doesn't explain...)
  8681.     mov    al,13h
  8682.     out    dx,al
  8683.     xor    al,al
  8684.     out    dx,al
  8685.     mov    al,20h
  8686.     out    dx,al
  8687.  
  8688.     mov    ax,40h            ; tell the BIOS we have 132 columns
  8689.     mov    es,ax
  8690.     mov    byte ptr es:[4ah],132    ; set Bios screen width data area
  8691.     clc                ; return success
  8692.     ret
  8693.                         ; Set 80 column mode
  8694. xga_do3:mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8695.     add    dx,01h
  8696.     xor    al,al
  8697.     out    dx,al
  8698.  
  8699.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8700.     add    dx,4
  8701.     xor    al,al
  8702.     out    dx,al
  8703.  
  8704.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8705.     add    dx,5
  8706.     mov    al,0ffh
  8707.     out    dx,al
  8708.  
  8709.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8710.     add    dx,0ah
  8711.     mov    ax,0ff64h
  8712.     out    dx,ax
  8713.  
  8714.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8715.     add    dx,0ah
  8716.     mov    ax,1550h
  8717.     out    dx,ax
  8718.  
  8719.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8720.     add    dx,0ah
  8721.     mov    ax,1450h
  8722.     out    dx,ax
  8723.  
  8724.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8725.     add    dx,0ah
  8726.     mov    ax,0051h
  8727.     out    dx,ax
  8728.  
  8729.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8730.     add    dx,0ah
  8731.     mov    ax,0454h
  8732.     out    dx,ax
  8733.  
  8734.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8735.     add    dx,0ah
  8736.     mov    ax,7f70h
  8737.     out    dx,ax
  8738.  
  8739.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8740.     add    dx,0ah
  8741.     mov    ax,202ah
  8742.     out    dx,ax
  8743.  
  8744.     mov    dx,xga_reg_base        ; (the manual doesn't explain...)
  8745. ;;    add    dx,00h
  8746.     mov    al,1
  8747.     out    dx,al
  8748.  
  8749.     mov    dx,03c3h        ; (the manual doesn't explain...)
  8750.     mov    al,1
  8751.     out    dx,al
  8752.  
  8753.     mov    ax,1202h        ; select 400 scan lines
  8754.     mov    bl,30h
  8755.     int    screen
  8756.     mov    ax,0+3            ; set video mode 3
  8757.     int    screen
  8758.     clc                ; return success
  8759.     ret
  8760. xgaman    endp
  8761.  
  8762. ; Routine to do keyclick if flag is set, no arguments
  8763. vclick    proc    near
  8764.     test    vtemu.vtflgop,vskeyclick ; is keyclick flag on?
  8765.     jz    vclick1            ; z = no, just return
  8766.     push    bx
  8767.     push    di
  8768.     mov    di,500            ; 500 Hertz
  8769.     mov    bx,1            ; For 1 millisecond
  8770.     call    vtsound            ; Do it
  8771.     pop    di            ; Restore the ACs
  8772.     pop    bx
  8773. vclick1:ret
  8774. vclick    endp
  8775. endif    ; no_terminal
  8776.  
  8777. ; Routine to do VT100-style bell, no arguments
  8778. fvtbell    proc    far
  8779.     call    vtbell
  8780.     ret
  8781. fvtbell    endp
  8782.  
  8783. vtbell    proc    near
  8784.     cmp    belltype,1        ; visual bell?
  8785.     je    vtbell1            ; e = yes
  8786.     ja    vtbell2            ; a = no bell
  8787.     push    di            ; audible bell
  8788.     push    bx
  8789.     mov    di,880            ; 880 Hertz
  8790.     mov    bx,40            ; For 40 ms
  8791.     call    vtsound            ; Do it
  8792.     pop    bx
  8793.     pop    di
  8794.     ret
  8795. vtbell1:
  8796. ifndef    no_terminal
  8797.     call    revscn            ; reverse screen
  8798.     push    ax
  8799.     mov    ax,40            ; for 40 milliseconds
  8800.     call    pcwait
  8801.     pop    ax
  8802.     call    revscn            ; put back
  8803. endif    ; no_terminal
  8804. vtbell2:ret
  8805. vtbell    endp
  8806.  
  8807. ; Routine to make noise of arbitrary frequency for arbitrary duration.
  8808. ; Similar to routine (with typo removed) in "IBM PC Assembly Language:
  8809. ; A Guide for Programmers", Leo J. Scanlon, 1983 Robert J. Brady Co.,
  8810. ; Bowie, MD., page 270. Modified by J R Doupnik to use 0.1 millsec interval.
  8811. ; Call:        di/    frequency in Hertz.
  8812. ;        bx/    duration in 1 millisecond units
  8813. vtsound proc    near
  8814.     push    ax            ; save regs
  8815.     push    cx
  8816.     push    dx
  8817.     mov    al,0B6H            ; write timer mode register
  8818.     out    43H,al
  8819.     mov    dx,14H            ; timer divisor is
  8820.     mov    ax,4F38H        ; 1331000/frequency
  8821.     div    di
  8822.     out    42H,al            ; write timer 2 count low byte
  8823.     mov    al,ah
  8824.     out    42H,al            ; write timer 2 count high byte
  8825.     in    al,61H            ; get current port B setting
  8826.     or    al,3            ; turn speaker on
  8827.     out    61H,al
  8828.     mov    ax,bx            ; number of milliseconds to wait
  8829.     call    pcwait            ; do the calibrated wait
  8830.     in    al,61H            ; get current port B setting
  8831.     and    al,0fch            ; turn off speaker and timer
  8832.     out    61H,al
  8833.     pop    dx            ; restore regs
  8834.     pop    cx
  8835.     pop    ax
  8836.     ret
  8837. vtsound endp
  8838. code1    ends
  8839.     end
  8840.