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

  1.          name    msxp98
  2. ; File MSXP98.ASM
  3. ; NEC PC-9801 MS DOS Kermit module.
  4. ;
  5. ; Last edit: 17 Apr 1991
  6. ; 17 Apr 1991 Joe Doupnik's modifications are added. -> KEK v1.22
  7. ; 05 Apr 1991 KEK v1.21 for MS-Kermit v3.10
  8. ;             correct flow control mismatch.
  9. ;             added pcwtst for correct pcwait.
  10. ; 25 Jul 1990 KEK v1.20 for MS-Kermit v3.02
  11. ; 24 Sep 1989 KEK v1.16 (added VT52 mode).
  12. ; 04 Aug 1989 Fixed wrong ESC M (Reverse index) behavior (in MSYP98.ASM).
  13. ; 30 May 1989 ESC [ 0 m resets to color to default (color in command mode).
  14. ; 25 Apr 1989 KEK v1.15 .
  15. ; 24 Apr 1989 Fixed bug of cooked log for dumb terminal emulator.
  16. ; 21 Apr 1989 Raw mode logging is moved to outside the terminal emulator.
  17. ; 16 Apr 1989 Cooked log in VT100 mode is installed.
  18. ; 01 Mar 1989 Bug on JIS-7 input when local echo is on.
  19. ; 24 Feb 1989 start test of the device port. v1.15 alpha
  20. ; 13 Feb 1989 domode is called when really necessary.
  21. ;             graphic display on when exit.
  22. ; 08 Feb 1989 Call getbaud in lclini.
  23. ; 04 Feb 1989 Bug report from Yoro@Kyoto.Univ. SHOW MODEM becomes mad
  24. ;             when modem is not ready.  This was bug in getmodem.
  25. ; 28 Jan 1989 KEK v1.14, + MS-Kermit 2.23/A
  26. ; 17 Dec 1988 AUTOTEK feature is completely removed. Use eneble/disable Tek.
  27. ; 08 Sep 1988 JIS-7 code for 'Kanji-send' is installed.
  28. ;             The original idea and its code is due to Ogawa, NTT software-lab.
  29. ;             Thanx for cooperation !
  30. ; 16 Jul 1988 Keyboard kanji translation comes into chrout to work with
  31. ;             SET KEY command.
  32. ; 14 Jul 1988 V2.31
  33. ;             old global variable PCNET is now local variable
  34. ;             local termination pointer NETDONE is renamed LCLEXIT
  35. ;             GETMODEM is added as a dummy routine (from MSXGEN.ASM)
  36. ;             Ungermann-Bass port name is UB-NETCI
  37. ; 25 Jun 1988 Ungermann-Bass PC-NIU N98 support in NETCI mode
  38. ; 15 Jun 1988 V1.00
  39. ; 06 Jun 1988 show modem is installed
  40. ; 23 May 1988 added KEYCLICK, AUTOTEK features
  41. ; 19 May 1988 become v2.27(A) level (TEK4014, VT100)
  42. ; 18 May 1988 Keyboard routine for VT100 is installed.
  43. ; 16 May 1988 Works with v2.27(A) VT100 output routine.
  44. ; 15 May 1988 Fixed bug in SERINI.
  45. ; 14 May 1988 Works with dumb terminal emulator !
  46. ; 12 May 1988 start coding based on MSXGEN.ASM by H.Fujii
  47.  
  48.         public  serini, serrst, clrbuf, outchr, coms, vtstat
  49.         public  ctlu, cmblnk, locate, lclini, prtchr, clearl
  50.         public  baudst, getbaud, beep, trnprs, termtb
  51.         public    setchtab
  52.         public  count, xofsnt, puthlp, putmod, clrmod, poscur
  53.         public  sendbr, sendbl, term, machnam, setktab, setkhlp, showkey
  54.         public  ihosts, ihostr, dtrlow, serhng, dumpscr
  55.         public    bdtab, comptab, portval
  56.         public  chrout, cstatus, cquit, cquery, chang   ; kbd action verbs
  57.         public  snull, kdos, klogof, klogon
  58.     public    trnmod
  59.         public    shomodem, getmodem, mdmhand
  60.     public    pf1, pf2, pf3, pf4
  61.     public    kp0, kp1, kp2, kp3, kp4, kp5, kp6, kp7, kp8, kp9
  62.     public    decf6, decf7, decf8, decf9, decf10, decf11, decf12, decf13
  63.     public    decf14, dechelp, decdo, decf17, decf18, decf19, decf20
  64.     public    decfind, decinsert, decremove, decselect
  65.     public    decprev, decnext
  66.     public    kpmins, kpcoma, kpentr, kpdot
  67.     public    uparrw, dnarrw, lfarrw, rtarrw
  68.         public    keyinchg
  69.     public    vtchg, vtreset, vtrmac, vtsmac
  70.         public    upone, dnone, upscn, dnscn
  71.         public    gupone, gdnone
  72.         public    prtscn
  73.         public    outcapt
  74.         public    set_cur_color
  75.  
  76.     public    cpu_clock, vtgrph_flg, vttest_flg
  77.     public    curkey_mode, keypad_mode, display_mode
  78.     public    kanji_rmode, kanji_smode
  79.     public    kanji_rcode, kanji_scode
  80.     public    keyin_dos, vt100_cursr
  81.     public  vt100_flags, vt100_pflag, vt100_lflag, vt100_gflag
  82.     public    vt_ourarg
  83.     public    scn_color, def_color
  84.     public    extmacro, vtmacname, vtmaclen
  85.         include mssdef.h
  86.         include    msxp98.h
  87.  
  88. CHR_GS    equ    1Dh
  89. CHR_CAN    equ    18h
  90.  
  91. false   equ     0
  92. true    equ     1
  93. instat  equ     6
  94. prtscr  equ     80h                     ; print screen pressed
  95.  
  96. ;
  97. ; Ungermann-Bass PC-NIU N98 command interpreter interface
  98. ; CALL    AH -- Function number
  99. ;         AL -- Port number relative to 0
  100. ;         CX -- may be a counter, CL is used as a subfunction for control
  101. ;      ES:BX -- may be a buffer address
  102.  
  103. NETCI_PORT    equ    0        ; NETCI port number
  104.  
  105. NETCI_INT    equ    06Bh        ; Software interrupt vector# for NETCI
  106. NETCI_OPEN    equ    2        ; NETCI open function
  107. NETCI_CLOSE    equ    3        ; NETCI close function
  108. NETCI_READ    equ    1        ; NETCI read function
  109. NETCI_WRITE    equ    0        ; NETCI write function
  110. NETCI_CNTL    equ    6        ; NETCI control function
  111. NETCI_STATUS    equ    7        ; NETCI status function
  112. NETCI_RBRK    equ    8        ; NETCI read break function
  113.  
  114. NETCI_BRK    equ    2        ; NETCI control function, BREAK
  115. NETCI_DIS    equ    4        ; NETCI control function, DISCONNECT
  116. NETCI_HLD    equ    6        ; NETCI control function, HOLD
  117.  
  118. ; Buffer size for Network transfer
  119.  
  120. NETBUFLEN    equ    256
  121.  
  122. ; port assignments for 8251 serial controllers
  123. ;
  124. ;== PORT 1 ==
  125.  
  126. mndata    equ    30h
  127. mnst1a    equ    32h
  128. mncmda    equ    32h
  129.  
  130. mnmska    equ    35h    ; mask set
  131. mnrdsa    equ    33h    ; read signal
  132.  
  133. ;== PORT 2 ==
  134.  
  135. mndatb    equ    0B1h
  136. mnst1b    equ    0B3h
  137. mncmdb    equ    0B3h
  138.  
  139. mnmskb    equ    0B0h
  140. mnrdsb    equ    0B0h    ; read signal
  141.  
  142. ;== PORT 3 ==
  143.  
  144. mndatc    equ    0B9h
  145. mnst1c    equ    0BBh
  146. mncmdc    equ    0BBh
  147.  
  148. mnmskc    equ    0B2h    ; mask set
  149. mnrdsc    equ    0B2h    ; read signal
  150.  
  151. ; Status bits from austt
  152.  
  153. txrdy    equ    01h
  154. rxrdy    equ    02h
  155.  
  156. ; Command values for mncmd
  157.  
  158. ccmd    equ    37H        ; RTS & DTR high, RX & TX enabled, reset ERR
  159. cbrk    equ    08H        ; break enabled
  160. chng    equ    10H        ; RTS & DTR low, RX & TX disabled, reset ERR
  161. cmode    equ    40H        ; enable mode reset
  162. mmode    equ    4EH        ; 16x rate, 8 data, no parity, 1 stop
  163.  
  164. ; Mask values for mnmsk
  165.  
  166.  
  167. txmsk    equ    04H        ; disables transmit ready interrupt
  168. rxmsk    equ    01H        ; disables receive ready interrupt
  169. tbemsk    equ    02H        ; disables transmit buffer empty interrupt
  170.  
  171.  
  172. ; port assignments for 8253 timers
  173.  
  174. ;        Standard interface
  175.  
  176. tmdata    equ    75H        ; data port
  177. tmcmda    equ    77H        ; command port  (Was 27H Ian 10/27/84)
  178.  
  179.  
  180. ; values for tmcmd which select timer channel and mode
  181.  
  182. tmsela    equ    0B6H        ; Channel 2, mode 3 (standard port)
  183.  
  184. ; Baudrate
  185.  
  186. B9600    equ    13
  187.  
  188. ; Modem information
  189.  
  190. mdminfo struc
  191. mddat   dw      0
  192. mdstat  dw      0
  193. mdcom   dw      0
  194. mden    db      0
  195. mddis   db      0
  196. mdmeoi  db      0
  197. mdintv  dw      0
  198. mdminfo ends
  199.  
  200. ; Timer information for current port selection
  201.  
  202. tmrinfo    struc
  203. tmdat    dw    0        ; data port
  204. tmcmd    dw    0        ; command port
  205. tmsel    db    0        ; byte which selects channel and mode
  206. tmrinfo    ends
  207.  
  208. ; Modem information for current port selection
  209.  
  210. ; port assignments for 8259 interrupt controllers
  211.  
  212. ;        Standard interface
  213.  
  214. intcmda    equ    00H        ; Command port (master controller)
  215. intmska    equ    02H        ; Mask port
  216. ictmsk    equ    01H        ; Timer interrupt mask (to master)
  217. icsmska    equ    10H    ; Standard serial interrupt mask (to master)
  218. icsvcta equ    0CH    ;Interrupt vector for standard interface
  219.  
  220. icEOI    equ    20H        ; generic end of interrupt for intcmd
  221.  
  222. ; miscellaneous constants
  223.  
  224. mntrgh    equ    bufsiz*3/4    ; High XON/XOFF trigger = 3/4 of buffer full.
  225.  
  226. ; external variables used:
  227. ; flags - global flags as per flginfo structure defined in pcdefs
  228. ; trans - global transmission parameters, trinfo struct defined in pcdefs
  229. ; portval - pointer to current portinfo structure (currently either port1
  230. ;    or port2)
  231. ; port1, port2 - portinfo structures for the corresponding ports
  232.  
  233. ; global variables defined in this module:
  234. ; xofsnt, xofrcv - tell whether we saw or sent an xoff.
  235.  
  236. data    segment public 'data'
  237.     extrn    denyflg:word, rdbuf:byte
  238.         extrn   flags:byte, trans:byte, ttyact:byte
  239.         extrn    repflg:byte, diskio:byte, filtst:byte
  240.         extrn    lclexit:word, taklev:byte, takadr:word
  241.         extrn   comand:byte, dmpname:byte, prnhand:word
  242.         extrn   kbdflg:byte, rxtable:byte, mcctab:byte
  243.  
  244. ;------------------------
  245. cpu_clock    db    0
  246. curkey_mode    db    0
  247. keypad_mode    db    0
  248. display_mode    db    0
  249. kanji_7smode    db    0
  250. kanji_7rmode    db    0
  251. kanji_smode    db    0    ; Kanji 1st/2nd byte indicator
  252. kanji_rmode    db    0
  253. kanji_scode    db    0
  254. kanji_rcode    db    0
  255. keyin_dos    db    0
  256. vt100_cursr    db    0    ; cursor attributes
  257. vt100_flags    db    0
  258. vt100_lflag     db      0
  259. vt100_pflag    db    0    ; printer control
  260. vt100_gflag    db    0
  261. ;------------------------
  262. vtgrph_flg    db    0
  263. vttest_flg    db    0
  264. replay_hold    db    0
  265.         db    0    ; adjustment for word boundary
  266. ;------------------------
  267. ;
  268. portval        dw    1
  269. ;
  270. ; previous baud rate for serial port 1
  271. pbaud_1        dw    0FFFFh    ; set unknown baud rate
  272. ;
  273. ; color for Foreground, Background, Highlight and Modeline
  274. ;
  275. def_color    db    07h, 00h, 06h, 07h
  276. scn_color    db    07h, 00h, 06h, 07h
  277. ;------------------------
  278.  
  279. fairness    dw    0
  280.  
  281. KI_len        dw    0
  282. KI_ofs        dw    0
  283.  
  284. KO_len        dw    0
  285. KO_ofs        dw    0
  286.  
  287. pcnet        db    0    ; 2.30 global --> 2.31 local
  288.  
  289. kanjis1        db    0    ; storage for Kanji 1st byte (Keyboard)
  290. kanjis2        db    0
  291. kanjir1        db    0    ; storage for Shift-JIS kanji code
  292. kanjir2        db    0
  293. kanjio1        db    0    ; storage for DEC Kanji code
  294. kanjio2        db    0
  295.  
  296. mdstreg    db    ?        ; modem status register
  297.  
  298. machnam db      'NEC PC-9801 (KEK v1.22  17-APR-1991)$'
  299. erms20  db      cr,lf,'?Warning: System has no disk drives$'
  300. erms40  db      cr,lf,'?Warning: Unrecognized baud rate$'
  301. erms41  db      cr,lf,'?Warning: Cannot open com port$'
  302. erms50  db      cr,lf,'Error reading from device$'
  303. hnd1    db      cr,lf,'Enter a file handle.  Check your DOS manual if you are '
  304.         db      cr,lf,'not certain what value to supply (generally 3).$'
  305. hnd2    db      cr,lf,'Handle: $'
  306. hnderr  db      cr,lf,'Warning: Handle not known.'
  307. deverr  db      cr,lf,'Any routine using the communications port will'
  308.         db      cr,lf,'probably not work.$'
  309. pntmsg    db    'Printer not ready, printing request skipped$'
  310. hndhlp  db      cr,lf,'A one to four digit file handle $'
  311. dev1    db      cr,lf,'Device: $'
  312. devhlp  db      cr,lf,'Name for your systems auxiliary port $'
  313. badbd   db      cr,lf,'Unimplemented baud rate$'
  314. noimp   db      cr,lf,'Command not implemented.$'
  315. hngmsg  db      cr,lf,' The phone should have hungup.',cr,lf,'$'
  316. hnghlp  db      cr,lf,' The modem control lines DTR and RTS for the current'
  317.         db      ' port are forced low (off)'
  318.         db      cr,lf,' to hangup the phone. Normally, Kermit leaves them'
  319.         db      ' high (on) when it exits.'
  320.         db      cr,lf,'$'
  321.  
  322. msmsg1  db      cr,lf,'  Modem is not ready: DSR is off$'
  323. msmsg2  db      cr,lf,'  Modem is ready:     DSR is on$'
  324. msmsg3  db      cr,lf,'  no Carrier Detect:  CD  is off$'
  325. msmsg4  db      cr,lf,'  Carrier Detect:     CD  is on$'
  326. msmsg5  db      cr,lf,'  no Clear To Send:   CTS is off$'
  327. msmsg6  db      cr,lf,'  Clear To Send:      CTS is on$'
  328. vtrname    db    'TERMINALR'        ; a macro name, must be Upper Case
  329. vtrlen    equ    $-vtrname
  330. vtsname    db    'TERMINALS'        ; a macro name, must be Upper Case
  331. vtslen    equ    $-vtsname
  332. prodname db    'PRODUCT'
  333. vtplen    equ    $-prodname
  334. vtmacname dw    vtrname            ; pointer to selected macro name
  335. vtmaclen db    vtrlen
  336. oldsp    dw    0 
  337.  
  338. tmpbuf        db    80 DUP (?)
  339.  
  340. ;playback_hndl    dw    ?
  341. ;playback_fnam    db    80 dup (?)
  342. ;playback_defnam    db    'KERMIT.LOG',0
  343. ;playback_hlp    db    cr,lf,'Filename to playback$'
  344.  
  345. prthnd  dw      0               ; Port handle.
  346. prtnam  db      80 dup (0)    ; Name of auxiliary device
  347. prtdef    db    'AUX',0        ; default device name
  348. prtdev    db    ?        ; device flag (device=1,file=0)
  349. prthld    db    ?        ; hold port
  350. prthlp    db    cr,lf,'specify device/file name (default AUX)$'
  351.  
  352. shkmsg  db      'Not implemented.'
  353. shklen  equ     $-shkmsg
  354. setktab db      0
  355. setkhlp db      0
  356. crlf    db      cr,lf,'$'
  357. delstr  db      BS,BS,'  ',BS,BS,'$'    ; Delete string
  358. fulscr    db    ESCAPE,'[>1h$'
  359. nrmscr    db    ESCAPE,'[>1l$'
  360. delscr    db    ESCAPE,'[2J$'        ; Delete screen
  361. retscr    db    ESCAPE,'[>1h'
  362.     db    ESCAPE,'[25;1H',ESCAPE,'[0J'
  363.     db    cr,'$'
  364.  
  365. ; If delete code moves cursor then BS over code, BS over bad char, space
  366. ; over both to erase from screen, BS twice to restore cursor position.
  367. clrlin  db      cr,'$'                  ; Clear line (just the cr part).
  368. clreol  db      ESCAPE,'[K$'    ; Clear to end of line.
  369. telflg  db      0               ; non-zero if we're a terminal.
  370. argadr  dw      ?               ; address of arg blk from msster.asm
  371. parmsk  db      ?               ; 8/7 bit parity mask, for reception
  372. flowoff db      ?               ; flow-off char, Xoff or null (if no flow)
  373. flowon  db      ?               ; flow-on char, Xon or null
  374. captrtn dw      ?               ; routine to call for captured output
  375. xofsnt  db      0               ; Say if we sent an XOFF.
  376. xofrcv  db      0               ; Say if we received an XOFF.
  377.  
  378. temp    dw      0
  379. temp1   dw      ?               ; Temporary storage.
  380. temp2   dw      ?               ; Temporary storage.
  381.  
  382. ; Entries for choosing communications port
  383. comptab db      9               ; Number of options
  384.         mkeyw   '1',1
  385.         mkeyw   '2',2
  386.     mkeyw    '3',3
  387.         mkeyw   'COM1',1
  388.         mkeyw   'COM2',2
  389.         mkeyw    'COM3',3
  390.     mkeyw    'Device','D'
  391.     mkeyw    'File','D'
  392.         mkeyw   'UB-NETCI','N'
  393.         mkeyw    '   ',0        ; port is not present, for Status
  394.  
  395. vt_ourarg  termarg <>
  396. modem    mdminfo    <mndata,mnst1a,mncmda,0,0,0,0>
  397. timer    tmrinfo    <tmdata,tmcmda,tmsela>
  398.  
  399. ;++ The following structure must be initialized as in MSSKER
  400. ;
  401. port1    prtinfo    <0FFFFh,0,defpar,1,0,defhand,floxon>
  402. port2    prtinfo    <0FFFFh,0,defpar,1,0,defhand,floxon>
  403. portd    prtinfo    <0FFFFh,0,defpar,1,0,defhand,floxon>
  404. portf    prtinfo    <0FFFFh,0,defpar,1,0,defhand,floxon>
  405. portn    prtinfo    <0FFFFh,0,defpar,1,0,defhand,floxon>
  406.  
  407. termtb  db      tttypes                 ; entries for Status, not Set
  408.         mkeyw   'Heath-19',ttheath
  409.         mkeyw   'none',ttgenrc
  410.         mkeyw   'Tek4014',tttek
  411.         mkeyw   'VT102',ttvt100
  412.         mkeyw   'VT52',ttvt52
  413.  
  414. setchtab    db    3
  415.     mkeyw    'EUC',1
  416.     mkeyw    'JIS7',2
  417.     mkeyw    'MS-Kanji',0
  418.  
  419. ; this table is indexed by the baud rate definitions given in
  420. ; pcdefs.  Unsupported baud rates should contain FF.
  421.  
  422. bdtab    db    17
  423.     mkeyw    '45.5',0
  424.     mkeyw    '50',1
  425.     mkeyw    '75',2
  426.     mkeyw    '110',3
  427.     mkeyw    '134.5',4
  428.     mkeyw    '150',5
  429.     mkeyw    '300',6
  430.     mkeyw    '600',7
  431.     mkeyw    '1200',8
  432.     mkeyw    '1800',9
  433.     mkeyw    '2000',10
  434.     mkeyw    '2400',11
  435.     mkeyw    '4800',12
  436.     mkeyw    '9600',13
  437.     mkeyw    '19200',14
  438.     mkeyw    '38400',15
  439.     mkeyw    'Unknown',-1
  440.  
  441. ; Baudrate clock count table for 5/10 MHz CPU
  442.     even
  443. bddat5    label    word            ; AHS 29-MAY-86
  444.     dw    00D30H        ; 45.5 baud
  445.     dw    00C00H        ; 50 baud
  446.     dw    00800H        ; 75 baud
  447.     dw    00574H        ; 110 baud
  448.     dw    00476H        ; 134.5 baud
  449.     dw    00400H        ; 150 baud
  450.     dw    00200H        ; 300 baud
  451.     dw    00100H        ; 600 baud
  452.     dw    00080H        ; 1200 baud
  453.     dw    00055H        ; 1800 baud
  454.     dw    0004DH        ; 2000 baud
  455.     dw    00040H        ; 2400 baud
  456.     dw    00020H        ; 4800 baud
  457.     dw    00010H        ; 9600 baud
  458.     dw    00008H        ; 19200 baud
  459.     dw    00004H        ; 38400 baud (not tested - may not work)
  460.     dw    0FFFFH
  461.     dw    0FFFFH
  462.     dw    0FFFFH
  463.  
  464. ; Baud rate clock count table for 8 MHz CPU
  465.  
  466. bddat8    label    word            ; AHS 29-MAY-86
  467.     dw    0FFFFH        ; 45.5 baud
  468.     dw    0FFFFH        ; 50 baud
  469.     dw    00680H        ; 75 baud
  470.     dw    0FFFFH        ; 110 baud
  471.     dw    0FFFFH        ; 134.5 baud
  472.     dw    00340H        ; 150 baud
  473.     dw    001A0H        ; 300 baud
  474.     dw    000D0H        ; 600 baud
  475.     dw    00068H        ; 1200 baud
  476.     dw    0004EH        ; 1800 baud
  477.     dw    0FFFFH        ; 2000 baud
  478.     dw    00034H        ; 2400 baud
  479.     dw    0001AH        ; 4800 baud
  480.     dw    0000DH        ; 9600 baud
  481.     dw    0FFFFH        ; 19200 baud
  482.     dw    0FFFFH        ; 38400 baud (not tested - may not work)
  483.     dw    0FFFFH
  484.     dw    0FFFFH
  485.     dw    0FFFFH
  486.  
  487. baudlen equ     ($-bddat8)/2     ; number of entries above
  488.  
  489.  
  490. axsave        dw    ?
  491. portinia    dw    0
  492.  
  493. dmphand        dw    ?        ; file handle for dump file
  494.  
  495. oldsera_ofs    dw    ?
  496. oldsera_sgm    dw    ?
  497. oldmska        db    ?
  498. oldmsdat    db    ?
  499.  
  500. ; variables for serial interrupt handler
  501.     even
  502. source    db    bufsiz DUP (?)    ; Buffer for data from port.
  503.     db    2 DUP (?)    ; guard for source.
  504. srcpnt    dw    0        ; Pointer in buffer (DI).
  505. count    dw    0        ; Number of chars in int buffer.
  506. rcvpnt    dw    0        ; Save SI register here.
  507. mdmhand    db    0        ; modem status register, current
  508.  
  509. ; buffer for network
  510.  
  511. xmtbuf    db    NETBUFLEN DUP (0)    ; Buffer for Network xfer.
  512.     db    2 DUP (0)        ; guard
  513. xmtpnt    dw    0
  514. xmtcnt    dw    0
  515. ;
  516.     even
  517.     dw    80 DUP (?)    ; local stack for interrupt processing
  518. mnstk    dw    ?
  519. mnsp    dw    ?        ; remote stack info
  520. mnsseg    dw    ?
  521.  
  522. baud_set    db    0
  523.  
  524. onmsg        db    'off'
  525.         db    'on '
  526. applmsg        db    'normal     '
  527.         db    'application'
  528. colmsg        db    'black  '
  529.         db    'blue   '
  530.         db    'red    '
  531.         db    'magenta'
  532.         db    'green  '
  533.         db    'cyan   '
  534.         db    'yellow '
  535.         db    'white  '
  536. knjmsg        db    'none     '
  537.         db    'DEC-code '
  538.         db    'Shift-JIS'
  539.         db    'JIS-7    '
  540. keyinmsg    db    'BIOS  '
  541.         db    'CON   '
  542.         db    'DOS   '
  543. insrepmsg    db    'Replace'
  544.         db    'Insert '
  545. originmsg    db    'Absolute'
  546.         db    'Relative'
  547. lfnlmsg        db    'Line-feed'
  548.         db    'New-line '
  549. clkmsg        db    '5/10 MHz'
  550.         db    '8 MHz   '
  551. dspmsg        db    'Digital '
  552.         db    'Analogue'
  553.  
  554. vstmsg        db    '<Terminal status>  clock '
  555. vstmsg_clk    db    '        '
  556.         db    '  Diaplay: '
  557. vstmsg_dsp    db    '        '
  558.         db    cr,lf,'  Keyclick: '
  559. vstmsg_key    db    '    '
  560.         db    '  Keyinput: '
  561. vstmsg_keyin    db    '      '
  562.         db    '  Cursorkey: '
  563. vstmsg_curmod    db    '           '
  564.         db    '  Keypad: '
  565. vstmsg_kpdmod    db    '           '
  566.         db    cr,lf,'  Color:  Fore:'
  567. vstmsg_colf    db    '        '
  568.                 db      '  Back:'
  569. vstmsg_colb     db      '        '
  570.         db    '  Highlight:'
  571. vstmsg_colh    db    '        '
  572.                 db      '  Modeline:'
  573. vstmsg_colm     db      '        '
  574.         db    cr,lf,'  Kanji-send: '
  575. vstmsg_sknj    db    '          '
  576.         db    '  Kanji-receive: '
  577. vstmsg_rknj    db    '          '
  578.         db    cr,lf,'  Ins/Rep: '
  579. vstmsg_insrep    db    '       '
  580.         db    '  LF/NL: '
  581. vstmsg_lfnl    db    '         '
  582.         db    '  Orgin: '
  583. vstmsg_origin    db    '        '
  584.         db    '  Wrap: '
  585. vstmsg_autow    db    '    '
  586.         db    cr,lf,'  Cooked-log: '
  587. vstmsg_logcook    db    '    '
  588.         db    '$'
  589.  
  590. data    ends
  591.  
  592. code    segment public 'code'
  593.         extrn   comnd:near, dopar:near, atoi:near, prompt:near
  594.         extrn    isfile:near, strlen:near, strcpy:near
  595.         extrn   sleep:near, msuinit:near, keybd:near
  596.         extrn    kbdlini:near, kbdlend:near
  597.         extrn    ans_keystr:near
  598.     extrn    pntchr:near, pntflsh:near
  599.  
  600.     extrn    vt100:near, vt100_ini:near, vt100_reset:near
  601.     extrn    vt100_save:near, vt100_restore:near, vt100_modlin:near
  602.     extrn    vt100_dump:near, vt100_color:near
  603.     extrn    vt100_rupn:near, vt100_rdnn:near
  604.     extrn    vt100_prnl:near, vt100_prns:near
  605.  
  606.     extrn    tekstat:near
  607.  
  608.      extrn    prn_chk:near        ; in MSYP98.ASM
  609.      extrn    set_modlin:near        ; in MSYP98.ASM
  610.      extrn    gdisp_on:near        ; in MSGP98.ASM
  611.      extrn    set_gcolor:near        ; in MSGP98.ASM
  612.  
  613.      extrn    text_scrn:near        ; in MSZP98.ASM
  614.      extrn    pc98_bell:near        ; in MSZP98.ASM
  615.      extrn    pcwait:near        ; in MSZP98.ASM
  616.      extrn    pcwtst:near        ; in MSZP98.ASM
  617.  
  618.     extrn    tek4014:near, tek4014_ini:near, tek4014_reset:near
  619.     extrn    tek4014_save:near, tek4014_restore:near, tek4014_modlin:near
  620.     extrn    tek4014_color:near
  621.     extrn    sixel_rollup:near, sixel_rolldown:near
  622.  
  623.     extrn    sense_sftkey:near
  624.     extrn    set_keydef:near, reset_keydef:near
  625.     extrn    is_kanji1:near, s2jis:near, jis2s:near
  626.  
  627.         assume  cs:code,ds:data,es:nothing
  628.  
  629. ;-----------------
  630. ; Utility Package
  631. ;-----------------
  632.  
  633. NOUT    PROC    NEAR
  634. ; Copy numeric value from AX to ASCII buffer indicated by DI.
  635. ; DI is updated.
  636.  
  637.     mov    dx,0
  638.     mov    bx,10
  639.     div    bx
  640.     push    dx        ; save remainder digit
  641.     or    ax,ax        ; anything left?
  642.     jz    nout1        ; no, start output phase
  643.     call    nout
  644. nout1:    pop    ax        ; retrieve a digit
  645.     add    al,'0'        ; make it ASCII
  646.     stosb            ; put it in buffer
  647.     ret
  648. NOUT    ENDP
  649.  
  650. ENT_VT    PROC    NEAR
  651. ;@@    call    vt100_restore
  652.     and    vt100_gflag,7Fh        ; mask text screen control
  653.     call    set_gcolor
  654.     call    set_modlin
  655.     call    vt100_modlin
  656.     mov    kanji_rmode,0        ; clear all kanji pending flags
  657.     mov    kanji_smode,0
  658.     ret
  659. ENT_VT    ENDP
  660.  
  661. ENT_TK    PROC    NEAR
  662. ;@@    call    cmblnk
  663. ;@@    call    tek4014_restore
  664.     and    vt100_gflag,7Fh
  665.     cmp    vt100_gflag,4        ; TeK screen ?
  666.     jge    ent_tk_1        ; ge = yes
  667.     mov    vt100_gflag,4
  668. ent_tk_1:
  669.     or    vt100_gflag,80h        ; set text screen cotrol bit
  670.     call    set_gcolor
  671.     call    set_modlin
  672.     call    tek4014_modlin
  673.     mov    kanji_rmode,0
  674.     mov    kanji_smode,0
  675.     ret
  676. ENT_TK    ENDP
  677.  
  678. SET_CUR_COLOR    PROC    NEAR
  679. ;
  680. ; Set the current color.  The color table is given in [si] - [si+3]
  681. ;
  682.     push    ax
  683.     push    di
  684.     mov    di,offset scn_color    ; copy color to current buffer
  685.     mov    ax,[si]            ; fore & back
  686.     mov    [di],ax
  687.     mov    ax,[si+2]        ; highlight & modeline
  688.     mov    [di+2],ax
  689.     pop    di
  690.     pop    ax
  691.     ret
  692. SET_CUR_COLOR    ENDP
  693.  
  694. ;---------------------------------------------------------------------------
  695. ; Clear the input buffer. This throws away all the characters in the
  696. ; serial interrupt buffer.  This is particularly important when
  697. ; talking to servers, since NAKs can accumulate in the buffer.
  698.  
  699. CLRBUF  PROC    NEAR
  700.     cli
  701.     mov    srcpnt,offset source    ; receive circular buffer
  702.     mov    count,0
  703.     sti
  704.     cmp    repflg,0        ; in replay mode ?
  705.     jne    clrbf2            ; ne=yes. do not read any character.
  706. clrbf1:
  707.     call    prtchr            ; empty any intermediate buffers
  708.     jnc    clrbf1            ; got a char, clear again
  709. clrbf2:
  710.     cli
  711.     push    ax
  712.     mov    ax,offset source    ; reset pointers
  713.     mov    rcvpnt,ax
  714.     mov    srcpnt,ax
  715.     mov    count,0
  716.     pop    ax
  717.     sti
  718.         ret
  719. CLRBUF  ENDP
  720.  
  721. ; Clear to the end of the current line.  Returns normally.
  722.  
  723. CLEARL  PROC    NEAR
  724.         push ax
  725.         push dx
  726.         mov ah,prstr
  727.         mov dx,offset clreol
  728.         int dos
  729.         pop dx
  730.         pop ax
  731.         ret
  732. CLEARL  ENDP
  733.  
  734. shomodem    proc    near
  735.     mov     ah,cmeol            ; get a confirm
  736.         call    comnd
  737.         jnc    shomd0
  738.         ret                           ; no confirm
  739. shomd0:
  740. ;
  741.     call    serini            ; activate port to get status
  742.     call    serrst            ; turn off port again
  743. ;
  744.     call    getmodem    ; get modem status in al
  745.     mov    mdstreg,al
  746. ;
  747.     mov    ah,prstr
  748.     mov    dx,offset msmsg1    ; modem not ready msg
  749.     test    mdstreg,moddsr        ; is DSR asserted?
  750.     jz    shomd1            ; z = no
  751.     mov    dx,offset msmsg2    ; say asserted
  752. shomd1:    int    dos
  753.     mov    dx,offset msmsg3    ; CD not asserted msg
  754.     test    mdstreg,modcd        ; CD asserted?
  755.     jz    shomd2            ; z = no
  756.     mov    dx,offset msmsg4    ; say asserted
  757. shomd2:    int    dos
  758.     mov    dx,offset msmsg5    ; CTS asserted msg
  759.     test    mdstreg,modcts        ; CTS asserted?
  760.     jz    shomd3            ; z = no
  761.     mov    dx,offset msmsg6    ; say asserted
  762. shomd3:    int    dos
  763.     clc
  764.     ret
  765. shomodem    endp
  766.  
  767. ;
  768. ; returns modem status in AL. Needs more work.  Current version
  769. ; returns only valid for PORT 1.
  770. ;
  771. getmodem    proc    near
  772.     push    bx
  773.     push    dx
  774.     mov    dx,mnst1a    ; read status of port 1A
  775.     in    al,dx
  776.     and    al,80h        ; set only DR bit
  777.     mov    bl,al        ; save it
  778.     mov    dx,mnrdsa    ; read signal
  779.     in    al,dx
  780.     and    al,60h        ; set CS and CD only
  781.     or    bl,al
  782. ;
  783.     mov    al,0
  784.     test    bl,80h        ; is DSR asserted?
  785.     jz    getmd1        ; z = no
  786.     or    al,moddsr    ; set DSR bit
  787. getmd1:
  788.     test    bl,20h        ; CD asserted?
  789.     jnz    getmd2        ; nz = no
  790.     or    al,modcd    ; set CD bit
  791. getmd2:
  792.     test    bl,40h        ; CTS asserted?
  793. ;@@    jnz    shomd3
  794.     jnz    getmd3        ; @@ [04-Feb-89]
  795.     or    al,modcts    ; set CTS bit
  796. getmd3:
  797.     pop    dx
  798.     pop    bx
  799.     ret
  800. getmodem    endp
  801.  
  802. ; Put the char in AH to the serial port, assumimg the port is active.
  803. ; Returns carry clear if success, else carry set.
  804.  
  805. OUTCHR  PROC    NEAR
  806.     cmp    repflg,0        ; in REPLAY mode?
  807.     je    outch0            ; e=no
  808.     cmp    ah,03h            ; CTRL-C ?
  809.     je    outch0_1        ; e=yes
  810.     xor    replay_hold,1        ; toggle replay_hold flag
  811.     clc
  812.     jmp    outch0_2
  813. outch0_1:
  814.     stc
  815. outch0_2:
  816.     ret
  817. outch0:
  818.     push    cx            ; save regs
  819.     cmp    flowoff,0        ; Are we doing flow control.
  820.     je    outch2
  821.     mov    cx,1500h    ; about 15 sec in 4 millisec interval
  822.         cmp     ah,flowoff      ; sending xoff?
  823.         jne     outch1          ; ne = no
  824.         mov     xofsnt,false    ; supress xon from chkxon buffer routine
  825. outch1: cmp     xofrcv,true     ; Are we being held?
  826.         jne     outch2          ; No - it's OK to go on.
  827.         push    ax
  828.         mov    ax,4        ; 4 millisec wait loop
  829.         call    pcwait
  830.         pop    ax
  831.         loop    outch1          ; held, try for a while
  832.         mov     xofrcv,false    ; timed out, force it off and fall thru.
  833. outch2: push    dx              ; Save register.
  834.     xor    cx,cx
  835.         mov     al,ah           ; Parity routine works on AL.
  836.         call    dopar           ; Set parity appropriately.
  837.                                 ; Begin revised output routine
  838.     mov    ah,al
  839.         mov     temp,ax        ; put data there
  840.     cmp    vt_ourarg.prt,'N'        ; Network port ?
  841.     jne    outch6            ; ne = No.
  842.     pop    dx
  843.     pop    cx
  844.     jmp    outchn
  845. outch6:
  846.     cmp    vt_ourarg.prt,'D'    ; DOS device ?
  847.     jne    outch7        ; ne = no
  848.     jmp    outchd
  849. outch7:
  850.     mov    dx,modem.mdstat
  851. outch3:    in    al,dx
  852.     test    al,txrdy
  853.     jnz    outch4
  854.     loop    outch3
  855.     stc            ; fail to send
  856.     jmp    outch5
  857. outch4:    mov    al,ah
  858.     mov    dx,modem.mddat
  859.     out    dx,al
  860.     clc            ; we have sent it.
  861. outch5:    pop     dx
  862.         pop     cx
  863.     clc
  864.     ret
  865. ;
  866. outchn:
  867.     push    bx
  868.     mov    bx,offset xmtbuf    ; set xfer address
  869.     add    bx,xmtcnt        ; count of chars in buffer
  870.     mov    [bx],ah            ; put char in buffer
  871.     pop    bx
  872.     inc    xmtcnt            ; count of items in this buffer
  873.     cmp    xmtcnt,NETBUFLEN    ; is buffer full now?
  874.     jae    outchn1            ; ae = buffer is full, send it now.
  875.     cmp    ah,trans.seol        ; end of packet?
  876.     je    outchn1            ; e = yes, send buffer.
  877.     cmp    ah,flowon        ; flow control?
  878.     je    outchn1            ; e = yes, always expedite
  879.     cmp    ah,flowoff        ; ditto for flow off
  880.     je    outchn1
  881.     cmp    ttyact,0        ; are we in Connect mode?
  882.     je    outchn2            ; e = no, wait for more before sending
  883. outchn1:
  884.     call    send            ; network send routine
  885.     jc    outchn3            ; c = error
  886. outchn2:
  887.     clc                ; good exit
  888. outchn3:
  889.     ret                ; bad  exit
  890.  
  891. outchd:
  892.         cmp     prthnd,0        ; Got a handle yet?
  893.         jne     outchd3         ; Yup just go on
  894.         call    opnprt          ; Else 'open' the port
  895. outchd3:
  896.     cmp    prtdev,1    ; device ?
  897.     je    outchd5        ; e = yes.
  898.     xor    prthld,1    ; flip-flop
  899.     jmp    outch5
  900. outchd5:
  901.         push    bx
  902.         mov     bx,prthnd       ; port handle
  903.         mov     cx,1            ; one byte to write
  904.         mov     dx,offset temp  ; place where data will be found
  905.         mov     ah,write2       ; dos 2 write to file/device
  906.         int     dos
  907.         pop     bx              ; end of revised routine
  908.         jmp    outch5
  909.  
  910. OUTCHR  ENDP
  911.  
  912. SEND    PROC    NEAR
  913.     push    ax
  914.     push    bx
  915.     push    cx
  916.     push    es
  917. ;
  918.     push    ds
  919.     pop    es            ; ES = DS
  920.     mov    bx,offset xmtbuf    ; xfer start address
  921.     mov    ah,NETCI_WRITE        ; set function
  922.     mov    al,NETCI_PORT        ; set port
  923. ;
  924. send0:
  925.     mov    cx,xmtcnt        ; packet length
  926.     jcxz    send1
  927.     int    NETCI_INT        ; send packet
  928.     cmp    cx,xmtcnt        ; all done ?
  929.     jae    send1            ; e = yes.
  930.     pop    ax
  931.     mov    bx,offset xmtbuf
  932.     add    bx,cx            ; update xfer address
  933.     sub    xmtcnt,cx
  934.     jmp    send0
  935. ;
  936. send1:
  937.     mov    xmtcnt,0
  938.     pop    es
  939.     pop    cx
  940.     pop    bx
  941.     pop    ax
  942.     clc
  943.     ret
  944.  
  945. SEND    ENDP
  946.  
  947. ; This routine blanks the screen.  Returns normally.
  948.  
  949. CMBLNK  PROC    NEAR
  950.         push    ax                 ; save some registers
  951.         push    dx
  952.         mov    ah,prstr
  953.         mov    dx,offset delscr    ; delete screen.
  954.     int    dos
  955.         pop    dx
  956.         pop    ax
  957.         ret
  958. CMBLNK  ENDP
  959.  
  960. ; Homes the cursor.  Returns normally.
  961.  
  962. LOCATE  PROC    NEAR
  963.         mov    dx,0                ; Go to top left corner of screen.
  964.         jmp    poscur
  965. LOCATE  ENDP
  966.  
  967. ; Write a line at the bottom of the screen...
  968. ; the line is passed in dx, terminated by a $.  Returns normally.
  969. putmod  proc    near
  970.         push    dx              ; preserve message
  971.         mov     dx,1800h        ; now address line 24
  972.         call    poscur
  973.         pop     dx              ; get message back
  974.         mov     ah,prstr
  975.         int     dos             ; write it out
  976.         ret                     ; and return
  977. putmod  endp
  978.  
  979. ; clear the mode line written by putmod.  Returns normally.
  980. clrmod  proc    near
  981.         mov     dx,1800h
  982.         call    poscur          ; Go to bottom row.
  983.         call    clearl          ; Clear to end of line.
  984.         ret
  985. clrmod  endp
  986.  
  987. ; Put a help message on the screen.
  988. ; Pass the message in ax, terminated by a null.  Returns normally.
  989. puthlp  proc    near
  990.         push    dx              ; save regs
  991.         push    si
  992.         push    ax              ; preserve this
  993. ;@@    call    cmblnk
  994. ;@@    call    locate
  995.     mov    ah,prstr        ;@@
  996.     mov    dx,offset retscr    ;@@
  997.     int    dos            ;@@
  998.         mov     ah,prstr
  999.         mov     dx,offset crlf
  1000.         int     dos
  1001.         pop     si              ; point to string again
  1002.         cld
  1003. puthl3: lodsb                   ; get a byte
  1004.         cmp     al,0            ; end of string?
  1005.         je      puthl4          ; yes, stop
  1006.         mov     dl,al
  1007.         mov     ah,dconio
  1008.         int     dos             ; else write to screen
  1009.         jmp     puthl3          ; and keep going
  1010. puthl4: mov     ah,prstr
  1011.         mov     dx,offset crlf
  1012.         int     dos
  1013.         pop     si
  1014.         pop     dx
  1015.         ret
  1016. puthlp  endp
  1017.  
  1018. ; Set the baud rate for the current port, based on the value
  1019. ; in the portinfo structure.  Returns normally.
  1020.  
  1021. BAUDST    PROC    NEAR
  1022.     mov    dx,offset bdtab        ; baud rate table, ascii
  1023.     xor    bx,bx            ; help is the table itself
  1024.     mov    ah,cmkey        ; get keyword
  1025.     call    comnd
  1026.     jc    baudst1            ; c = failure
  1027.     push    bx            ; save result
  1028.     mov    ah,cmeol        ; get confirmation
  1029.     call    comnd
  1030.     pop    bx
  1031.     jc    baudst1            ; c = failure
  1032.     mov    si,portval
  1033.     mov    ax,[si].baud        ; remember original value
  1034.     mov    [si].baud,bx        ; set the baud rate
  1035.     call    dobaud            ; use common code
  1036.     clc
  1037. baudst1:ret
  1038. BAUDST    ENDP
  1039. ;
  1040. DOBAUD  PROC    NEAR
  1041.     push    ax
  1042.     push    bx
  1043.     push    dx
  1044. ;
  1045.     mov    axsave,ax
  1046.     mov    bx,portval
  1047.     mov    ax,[bx].baud
  1048.     shl    ax,1
  1049. ;
  1050.     cmp    cpu_clock,CPU_5M_CLOCK
  1051.     je    c5mhz
  1052. c8mhz:
  1053.     mov    bx,offset bddat8
  1054.     jmp    dobd0
  1055. c5mhz:
  1056.     mov    bx,offset bddat5
  1057. dobd0:
  1058.     add    bx,ax
  1059.     cmp    word ptr [bx],0FFFFh
  1060.     jne    dobd1
  1061.     mov    ah,prstr
  1062.     mov    dx,offset badbd
  1063.     int    dos
  1064.     jmp    dobd_ex
  1065. dobd1:
  1066.     mov    ax,[bx]
  1067.     cmp    pbaud_1,ax        ; same as previous baud rate ?
  1068.     jne    dobd2
  1069.     jmp    dobd_ex
  1070. dobd2:
  1071.     call    domode            ; reset RS-232C chip
  1072.     mov    dx,timer.tmcmd
  1073.     mov    al,timer.tmsel
  1074.     out    dx,al
  1075.     mov    ax,[bx]
  1076.     mov    pbaud_1,ax        ; store baud rate
  1077.     mov    dx,timer.tmdat
  1078.     out    dx,al
  1079.     mov    al,ah
  1080.     out    dx,al
  1081.     mov    baud_set,1
  1082. dobd_ex:
  1083.     pop    dx
  1084.         pop    bx
  1085.     pop    ax
  1086.     clc
  1087.         ret                     ; Must be set before starting Kermit.
  1088. DOBAUD  ENDP
  1089.  
  1090. ; Get the current baud rate from the serial card and set it
  1091. ; in the portinfo structure for the current port.  Returns normally.
  1092. ; This is used during initialization.
  1093.  
  1094. GETBAUD PROC    NEAR
  1095.     cmp    flags.comflg,'A'    ; controlable ?
  1096.     jae    gbaud1            ; ae = No. do nothing here.
  1097.     push    bx
  1098.     cmp    baud_set,1    ; Did we already set baud rate?
  1099.     je    gbaud0        ; yes, so just leave
  1100.     mov    bx,portval
  1101.     mov    [bx].baud,B9600
  1102.     mov    baud_set,1
  1103. gbaud0:
  1104.     pop    bx
  1105. gbaud1:
  1106.         ret
  1107. GETBAUD ENDP
  1108.  
  1109. ; Set the mode for the current port.  This is part of the serial
  1110. ; initialization routine.
  1111.  
  1112. DOMODE    PROC    NEAR
  1113.     push    ax
  1114.     push    cx
  1115.     push    dx
  1116. ;
  1117.     mov dx,modem.mdcom    ;send 3 zeros to command port to reset chip
  1118.     mov al,0
  1119.     out dx,al
  1120.     mov al,0
  1121.     out dx,al
  1122.     mov al,0
  1123.     out dx,al
  1124.     mov al,cmode        ;enable mode setting
  1125.     out dx,al
  1126.     mov cx,100        ;allow chip time to reset
  1127. mode1:    loop mode1
  1128.     mov al,mmode        ;mode: 16x rate, 8 data, no parity, 1 stop
  1129.     out dx,al
  1130.     mov cx,100
  1131. mode2:    loop mode2
  1132.     mov al,ccmd        ;RTS & DTR high, RX & TX enabled, reset errors
  1133.     out dx,al
  1134. ;
  1135.     pop    dx
  1136.     pop    cx
  1137.     pop    ax
  1138.     ret
  1139. DOMODE    ENDP
  1140.  
  1141. ; Get Char from    serial port buffer.
  1142. ; returns carry set if no character available at port, otherwise
  1143. ; returns carry clear with char in al, # of chars in buffer in dx.
  1144.  
  1145. PRTCHR  PROC    NEAR
  1146.     cmp    repflg,0        ; in replay mode ?
  1147.     je    prtch0            ; e=no.
  1148.     jmp    prtchf
  1149. prtch0:
  1150.     cmp    vt_ourarg.prt,'D'
  1151.     jne    prtch4
  1152.     jmp    prtchd
  1153. prtch4:
  1154.     call    chkxon
  1155.     cmp    vt_ourarg.prt,'N'
  1156.     jne    prtch3
  1157.     jmp    prtchn
  1158. prtch3:
  1159.     cmp    count,0
  1160.     jnz    prtch2
  1161.     xor    dx,dx        ; No data in buffer
  1162.     xor    al,al
  1163.     stc            ; No data in AL.
  1164.     ret
  1165. prtch2:
  1166.     pushf
  1167.     cli            ; disable interrupts while manipulating pointers
  1168.     push    si        ; save SI (uses in rpack)
  1169.     mov    si,rcvpnt
  1170.     lodsb            ; get a byte
  1171.     cmp    si,offset source + bufsiz    ; bigger than buffer?
  1172.     jb    prtch1        ; no, keep going
  1173.     mov    si,offset source    ; yes wrap around
  1174. prtch1:
  1175.     dec    count
  1176.     mov    rcvpnt,si
  1177.     mov    dx,count
  1178.     pop    si        ; restore SI
  1179.     popf
  1180.     clc            ; we have data in AL
  1181.     ret
  1182. ;
  1183. ;  Read from replay file
  1184. ;
  1185. prtchf:
  1186.     cmp    repflg,1    ; nomral state ?
  1187.     jne    prtchf0        ; ne=no
  1188.     cmp    replay_hold,0    ; holding?
  1189.     je    prtchf1        ; e=no
  1190. prtchf0:
  1191.     xor    dx,dx        ; no char at all.
  1192.     xor    al,al        ; with NUL
  1193.     stc            ; no char is available
  1194.     ret
  1195. prtchf1:
  1196.     push    bx
  1197.     push    cx
  1198.     mov    ah,readf2
  1199.     mov    bx,diskio.handle    ; file handle
  1200.     mov    cx,1            ; read one char
  1201.     mov    dx,offset rdbuf        ; to this buffer
  1202.     int    dos
  1203.     jc    prtchf2            ; c=read failure
  1204.     cmp    ax,cx            ; read the byte?
  1205.     jne    prtchf2            ; ne=no
  1206.     mov    al,rdbuf
  1207.     mov    dx,1
  1208.     clc
  1209.     jmp    prtchf3
  1210. prtchf2:
  1211.     call    pc98_bell        ; notify that we cannot read.
  1212.     mov    repflg,2
  1213.     xor    dx,dx
  1214.     xor    al,al
  1215.     stc
  1216. prtchf3:
  1217.     pop    cx
  1218.     pop    bx
  1219.     ret
  1220. ;
  1221. ;  Read from file/device
  1222. ;
  1223. prtchd:
  1224.     cmp    prthld,0    ; hold ?
  1225.     je    prtchd2        ; e = no
  1226.     stc
  1227.     ret
  1228. prtchd2:
  1229.         push    bx
  1230.         push    cx
  1231.         cmp     prthnd,0        ; Got a handle yet?
  1232.         jne     prtchd0         ; Yup just go on
  1233.         call    opnprt          ; Else 'open' the port
  1234. prtchd0:
  1235.         call    chkxon
  1236.         mov     bx,prthnd
  1237.         mov     al,instat       ; input status command
  1238.         mov     ah,ioctl        ; see note above
  1239.         int     dos
  1240.         jc      prtchd4         ; c = call failed, device not ready
  1241.         or      al,al
  1242.         jz      prtchd4         ; not ready
  1243.         mov     bx,prthnd       ; the file handle
  1244.         mov     ah,readf2       ; read file/device
  1245.         mov     cx,1            ; want just one character
  1246.         mov     dx,offset rdbuf ; where to store it
  1247.         int     dos
  1248.         jnc     prtchd1         ; nc = no error
  1249.         cmp     al,5            ; Error condition
  1250.         je      prt3dx
  1251.         cmp     al,6            ; Error condition
  1252.         je      prt3dx
  1253.         jmp     prtchd4         ; else report no char present
  1254. prtchd1:;;;mov   count,0         ; update count (always 0 for one char reads)
  1255.         mov     dx,0        ; needed to obey rules
  1256.         or      ax,ax           ; reading from end of file?
  1257.         jz      prtchd4         ; z = yes
  1258.         mov     al,rdbuf        ; recover char
  1259. prtchd3:
  1260.         pop     cx
  1261.         pop     bx
  1262.         ret                     ; return success (char is in al)
  1263. prt3dx: mov     ah,prstr
  1264.         mov     dx,offset erms50
  1265.         int     dos
  1266. prtchd4:
  1267.         pop     cx
  1268.         pop     bx
  1269.     xor    dx,dx
  1270.     xor    al,al
  1271.     stc
  1272.     ret
  1273.  
  1274. prtchn:
  1275.     cmp    count,0            ; Data in buffer?
  1276.     je    prtchn0            ; e = No. Get them from port.
  1277.     jmp    prtchn2
  1278. prtchn0:
  1279.     push    ax
  1280.     push    bx
  1281.     push    cx
  1282.     push    es
  1283.     mov    ax,offset source
  1284.     mov    rcvpnt,ax
  1285.     mov    srcpnt,ax
  1286.  ;
  1287.     mov    ah,NETCI_READ
  1288.     mov    al,NETCI_PORT
  1289.     mov    bx,offset source
  1290.     mov    cx,bufsiz
  1291.     push    ds
  1292.     pop    es
  1293.     int    NETCI_INT
  1294.     mov    count,cx
  1295.     add    srcpnt,cx
  1296.     pop    es
  1297.     pop    cx
  1298.     pop    bx
  1299.     pop    ax
  1300.     cmp    count,0
  1301.     jnz    prtchn2
  1302.     xor    dx,dx            ; no data in buffer
  1303.     xor    al,al
  1304.     stc                ; no data in AL.
  1305.     ret
  1306. prtchn2:
  1307.     pushf
  1308.     cli            ; disable interrupts while manipulating pointers
  1309.     push    si        ; save SI
  1310.     mov    si,rcvpnt
  1311.     lodsb            ; get a byte
  1312.     dec    count
  1313.     mov    rcvpnt,si
  1314. ;
  1315. ;    I'm not sure the floowings are necesary or not.
  1316. ;    The handshake should be done at network level.
  1317. ;
  1318. ;    check the data
  1319. ;
  1320. ;@@    push    bx
  1321. ;@@    or    al,al
  1322. ;@@    jz    prtchn5        ; Ignore nulls.
  1323. ;@@    mov    ah,al        ; copy the character in AH
  1324. ;@@    and    ah,parmsk    ; apply parity mask
  1325. ;@@    mov    bx,portval
  1326. ;@@    cmp    [bx].floflg,0    ; Doing flow control?
  1327. ;@@    je    prtchn4        ; Nope.
  1328. ;@@    mov    bx,[bx].flowc    ; Flow control character (BH=XON, BL=XOFF).
  1329. ;@@    cmp    ah,bl        ; Is it an XOFF?
  1330. ;@@    jne    prtchn3        ; Nope, go on.
  1331. ;@@    mov    xofrcv,true    ; Set the flag.
  1332. ;@@    jmp    short prtchn5
  1333. prtchn3:
  1334. ;@@    cmp    ah,bh        ; Get an XON?
  1335. ;@@    jne    prtchn4        ; No, go on.
  1336. ;@@    mov    xofrcv,false    ; Clear our flag.
  1337. ;@@    jmp    short prtchn5
  1338. ;
  1339. prtchn4:
  1340. ;@@    pop    bx
  1341.     mov    dx,count    ; number of characters in buffer
  1342.     pop    si        ; restore SI
  1343.     popf
  1344.     clc            ; we have data in AL.
  1345.     ret
  1346.     
  1347. prtchn5:
  1348. ;@@    pop    bx
  1349. ;@@    popf
  1350. ;@@    jmp    prtchn
  1351.  
  1352. PRTCHR  ENDP
  1353.  
  1354. ; Local routine to see if we have to transmit an xon
  1355. chkxon  proc    near
  1356.         push    bx
  1357.         mov     bx,portval
  1358.         cmp     [bx].floflg,0   ; doing flow control?
  1359.         je      chkxo1          ; no, skip all this
  1360.         cmp     xofsnt,false    ; have we sent an xoff?
  1361.         je      chkxo1          ; no, forget it
  1362.     cmp    count,mntrgh    ; below trigger?
  1363.     jae    chkxo1        ; no, forget it
  1364.         mov     ax,[bx].flowc   ; ah gets xon
  1365.         call    outchr          ; send it
  1366.       nop
  1367.       nop
  1368.       nop                     ; in case it skips
  1369.         mov     xofsnt,false    ; remember we've sent the xon.
  1370. chkxo1: pop     bx              ; restore register
  1371.         ret                     ; and return
  1372. chkxon  endp
  1373.  
  1374. ; IHOSTS - Initialize the host by sending XON, or equivalent, and enter the
  1375. ; cycle of clear input buffer, wait 1 second, test if buffer empty then exit
  1376. ; else repeat cycle. Requires that the port be initialized before hand.
  1377. ; Ihosts is used by the local send-file routine just after initializing
  1378. ; the serial port.
  1379. ; 22 March 1986 [jrd]
  1380.  
  1381. IHOSTS  PROC    NEAR
  1382.         push    ax              ; save the registers
  1383.         push    bx
  1384.         push    cx
  1385.         push    dx
  1386.         mov     bx,portval      ; port indicator
  1387.         mov     ax,[bx].flowc   ; put Go-ahead flow control char in ah
  1388.         or      ah,ah           ; don't send null if flow = none
  1389.         jz      ihosts1         ; z = null
  1390.         call    outchr          ; send it (release Host's output queue)
  1391.          nop                    ; outchr can do skip return
  1392.          nop
  1393.          nop
  1394. ihosts1:call    clrbuf          ; clear out interrupt buffer
  1395.         mov     ax,1            ; sleep for 1 second
  1396. ; NOTE: for systems with a time-of-day clock uncomment the line below
  1397. ; (call sleep) to provide an interval for the host to respond.
  1398.  
  1399.         call    sleep           ; procedure sleep is in msscom.asm
  1400.     cmp    repflg,0    ; in replay mode ?
  1401.     jne    ihosts2        ; ne=yes.
  1402.         call    prtchr          ; check for char at port
  1403.         jnc    ihosts1        ; have a char in al, repeat wait/read cycle
  1404. ihosts2:
  1405.         pop     dx              ; empty buffer. we are done here.
  1406.         pop     cx
  1407.         pop     bx
  1408.         pop     ax
  1409.         ret
  1410. IHOSTS  ENDP
  1411.  
  1412. ; IHOSTR - initialize the remote host for our reception of a file by
  1413. ; sending the flow-on character (XON typically) to release any held
  1414. ; data. Called by receive-file code just after initializing the serial
  1415. ; port.         22 March 1986 [jrd]
  1416. IHOSTR  PROC    NEAR
  1417. ;@@    call    pc98_bell
  1418.         push    ax              ; save regs
  1419.         push    bx
  1420.         push    cx
  1421.         mov     bx,portval      ; port indicator
  1422.         mov     ax,[bx].flowc   ; put Go-ahead flow control char in ah
  1423.         or      ah,ah           ; don't send null if flow = null
  1424.         jz      ihostr1         ; z = null
  1425.         call    outchr          ; send it (release Host's output queue)
  1426. ihostr1:pop     cx
  1427.         pop     bx
  1428.         pop     ax
  1429.         clc
  1430.         ret
  1431. IHOSTR  ENDP
  1432.  
  1433. DTRLOW  PROC    NEAR            ; Global proc to Hangup the Phone by making
  1434.                                 ; DTR and RTS low.
  1435.         mov ah,cmline           ; allow text to be able to display help
  1436.         mov bx,offset rdbuf     ; dummy buffer
  1437.         mov dx,offset hnghlp    ; help message
  1438.         call comnd              ; get a confirm
  1439.         jnc dtrlow1
  1440.         ret
  1441. dtrlow1:
  1442.     call serhng             ; drop DTR and RTS
  1443.         mov ah,prstr            ; give a nice message
  1444.     mov dx,offset hngmsg
  1445.         int dos
  1446.     ret
  1447. DTRLOW  ENDP
  1448.  
  1449. ; Test version for NEC PC-9801 (03-Sep-1988)
  1450. ; Hang up the Phone. Similar to SERRST except it just forces DTR and RTS low
  1451. ; to terminate the connection. 29 March 1986 [jrd]
  1452. ; Calling this twice without intervening calls to serini should be harmless.
  1453. ; Returns normally.
  1454.  
  1455. SERHNG  PROC NEAR
  1456.     mov    dx,modem.mdcom    ; set command port
  1457.     mov    al,chng        ; hangup command
  1458.     out    dx,al
  1459.     xor    cx,cx        ; counts for waiting loop
  1460. serhng1:
  1461.     loop    serhng1
  1462.     mov    pbaud_1,0FFFFh    ; reset previous baud rate
  1463.         ret
  1464. SERHNG  ENDP
  1465.  
  1466. ; Send a break out the current serial port.  Returns normally.
  1467. SENDBR  PROC    NEAR            ; Normal Break
  1468.     cmp    flags.comflg,'N'
  1469.     je    ub_sendbr
  1470.     mov    dx,modem.mdcom    ; set command port
  1471.     mov    al,cbrk+ccmd    ; add break to normal command
  1472.     out    dx,al
  1473.     mov    ax,275        ; wait for 275 milliseconds
  1474.     call    pcwait
  1475.     mov    al,ccmd        ; restore normal command
  1476.     out    dx,al
  1477.         ret
  1478. ub_sendbr:
  1479.         push    ax
  1480.         push    cx
  1481.         mov    ah,NETCI_CNTL    ; control function
  1482.         mov    al,NETCI_PORT
  1483.         mov     cl,NETCI_BRK    ; request break                          [ohl]
  1484.         int     NETCI_INT       ; Net/One command interface int. (6Bh)   [ohl]
  1485.         pop     cx
  1486.         pop     ax
  1487.         ret                     ;  [ohl] ---
  1488.  
  1489. SENDBR  ENDP
  1490.  
  1491. SENDBL  PROC    NEAR            ; Long Break
  1492.     cmp    flags.comflg,'N'
  1493.     je    ub_sendbl
  1494.     mov    dx,modem.mdcom    ; set command port
  1495.     mov    al,cbrk+ccmd    ; add break to normal command
  1496.     out    dx,al
  1497.     mov    ax,1800        ; 1.8 second long break
  1498.     call    pcwait
  1499.     mov    al,ccmd
  1500.     out    dx,al        ; restore normal command
  1501.         ret
  1502. ub_sendbl:
  1503.         push    ax
  1504.         push    cx
  1505.         mov    ah,NETCI_CNTL    ; control function
  1506.         mov    al,NETCI_PORT
  1507.         mov     cl,NETCI_HLD    ; request hold
  1508.         int     NETCI_INT       ; Net/One command interface int. (6Bh)   [ohl]
  1509.         pop     cx
  1510.         pop     ax
  1511.         ret                     ;  [ohl] ---
  1512. SENDBL  ENDP
  1513.  
  1514. ; Position the cursor according to contents of DX:
  1515. ; DH contains row, DL contains column.  Returns normally.
  1516. POSCUR  PROC    NEAR
  1517.     push    di
  1518.     mov    di,offset tmpbuf
  1519.     mov    byte ptr [di],ESCAPE
  1520.     mov    byte ptr [di+1],'['
  1521.     add    di,2
  1522.     mov    al,dh
  1523.     xor    ah,ah
  1524.     inc    ax
  1525.     push    dx
  1526.     call    nout
  1527.     mov    byte ptr [di],';'
  1528.     inc    di
  1529.     pop    dx
  1530.     mov    al,dl
  1531.     xor    ah,ah
  1532.     inc    ax
  1533.     call    nout
  1534.     mov    byte ptr [di],'H'
  1535.     mov    byte ptr [di+1],'$'
  1536.     mov    dx,offset tmpbuf
  1537.     mov    ah,prstr
  1538.     int    dos
  1539.     pop    di
  1540.         ret
  1541. POSCUR  ENDP
  1542.  
  1543. ; Move the cursor to the left margin, then clear to end of line.
  1544. ; Returns normally.
  1545.  
  1546. CTLU    PROC    NEAR
  1547.         mov ah,prstr
  1548.         mov dx,offset clrlin
  1549.         int dos
  1550.         call clearl
  1551.         ret
  1552. CTLU    ENDP
  1553.  
  1554. ; Called only when Kermit exits. Program pointer passed to mssker
  1555. ; in word 'lclexit'.
  1556. ; This is used as a local end routine.
  1557.  
  1558. LCLCLOSE    PROC    NEAR
  1559.     push    ax
  1560.     call    clsprt            ; close device if opened.
  1561.     cmp    pcnet,0            ; network closed ?
  1562.     je    lclclo1            ; e = yes
  1563.     mov    ah,NETCI_CLOSE        ; UB-NETCI close command
  1564.     mov    al,NETCI_PORT
  1565.     int    NETCI_INT
  1566.     mov    pcnet,0
  1567. lclclo1:
  1568.     test    vtgrph_flg,EXITG_BIT
  1569.     jz    lclclo2
  1570.     call    gdisp_on        ; graphic display on
  1571. lclclo2:
  1572.     call    reset_keydef        ; reset key definition table
  1573.     call    kbdlend            ; local reset keyboard routine
  1574.     mov    ah,prstr        ;@@
  1575.     mov    dx,offset nrmscr    ;@@
  1576.     int    dos            ;@@
  1577.     pop    ax
  1578.     ret
  1579. LCLCLOSE    ENDP
  1580.  
  1581. ; Open NETCI port
  1582.  
  1583. chknet    proc    near
  1584.     cmp    pcnet,0            ; netport is closed ?
  1585.     jne    chknetx
  1586.     push    ax
  1587.     push    bx
  1588.     push    cx
  1589.     push    es
  1590. ;
  1591.     push    cs
  1592.     pop    es
  1593.     mov    temp,0
  1594.     mov    bx,offset temp
  1595.     mov    cx,0
  1596.     mov    ah,NETCI_OPEN
  1597.     mov    al,NETCI_PORT
  1598.     int    NETCI_INT
  1599.     mov    lclexit,offset lclclose
  1600.     call    clrbuf
  1601.     mov    xmtcnt,0
  1602.     mov    pcnet,2
  1603. ;
  1604.     pop    es
  1605.     pop    cx
  1606.     pop    bx
  1607.     pop    ax
  1608. chknetx:
  1609.     clc
  1610.     ret
  1611. chknet    endp
  1612.  
  1613. ; Get a file handle for the communications port.  Use DOS call to get the
  1614. ; next available handle.  If it fails, ask user what value to use (there
  1615. ; should be a predefined handle for the port, generally 3).  The open
  1616. ; will fail if the system uses names other than "COM1" or "COM2".
  1617.  
  1618. opnprt    proc    near
  1619.         mov     dx,offset prtnam        ; port name
  1620.         mov     ah,open2                ; open file/device
  1621.         mov     al,2                    ; for reading/writing
  1622.         int     dos
  1623.         jnc     opnpr2                  ; nc = no error so far
  1624.         stc                             ; set carry for failure
  1625.         ret
  1626. opnpr2: mov     prthnd,ax               ; Call succeeded
  1627.     mov    prtdev,1        ; device is assumed
  1628.         mov     ah,ioctl
  1629.         mov     al,00h                  ; get device info
  1630.         xor     dx,dx
  1631.         mov     bx,prthnd               ; port's handle
  1632.         int     dos
  1633.         test    dl,80h            ; is device ?
  1634.         jnz    opnpr3            ; nz = yes.
  1635.     mov    prtdev,0        ; say this is a file
  1636.         ret
  1637. opnpr3:
  1638.         or      dl,20h                  ; set raw mode in device info
  1639.         mov     dh,0
  1640.         mov     ah,ioctl
  1641.         mov     al,01h                  ; set device info
  1642.         int     dos
  1643.         ret                             ; carry clear for success
  1644. opnprt    endp
  1645.  
  1646. clsprt    proc    near
  1647.     cmp    prthnd,0        ; already closed ?
  1648.     je    clsprt1            ; e = yes. Do nothing.
  1649.     push    ax
  1650.     push    bx
  1651.     mov    ah,close2
  1652.     mov    bx,prthnd
  1653.     int    dos
  1654.     mov    prthnd,0
  1655.     pop    bx
  1656.     pop    ax
  1657. clsprt1:
  1658.     ret
  1659. clsprt    endp
  1660.  
  1661. ;
  1662. ; Set the current port.
  1663. COMS    PROC    NEAR
  1664.         mov dx,offset comptab   ; the table to examine
  1665.         mov bx,0                ; use keywords as help
  1666.         mov ah,cmkey            ; parse keyword from comptab
  1667.         call comnd
  1668.         jnc  coms0
  1669.         ret            ; no match
  1670. coms0:
  1671.     cmp    bl,'N'        ; Network ?
  1672.     jne    coms1        ; ne = no
  1673.     jmp    comsn        ; Yes, setup for networks
  1674. coms1:
  1675.     cmp    bl,'D'        ; Device ?
  1676.     jne    coms2
  1677.     jmp    comsd        ; Yes, setup for device
  1678. coms2:
  1679.     mov    temp,bx
  1680.         mov    ah,cmeol
  1681.         call    comnd            ; Get a confirm.
  1682.         jnc    coms2_1
  1683.         ret                ;  Didn't get a confirm.
  1684. coms2_1:
  1685.     mov    bx,temp            ; get port number/letter
  1686.     mov    flags.comflg,bl        ; remember port number
  1687.     xor    bh,bh            ; clear high byte
  1688.     mov    bl,flags.comflg        ; get COMx number (1-3)
  1689.     push    bx
  1690.         pop    bx
  1691.     mov    ax,offset port1
  1692.     mov    portval,ax
  1693.     call    inita
  1694.     clc
  1695.     ret
  1696. comsn:
  1697.     mov    temp,bx
  1698.     mov    ah,cmeol
  1699.     call    comnd            ; Get a confirm
  1700.     jnc    comsn0
  1701.     ret                ;  Didn't get a confirm
  1702. comsn0:
  1703.     call    serrst            ; reset serial port
  1704.     call    chknet            ; start network usage
  1705.     cmp    pcnet,0            ; is network alive (non-zero)?
  1706.     jne    comsn4            ; ne = yes
  1707.     stc
  1708.     ret                ; return failure
  1709. comsn4:
  1710.     mov    portval,offset portn    ; set netowrk port data
  1711.     mov    flags.comflg,'N'    ; set the comm port flag.
  1712.     clc                ; return sucess
  1713.     ret
  1714. ;
  1715. comsd:
  1716.  
  1717. ; Set device name. Taken from 'setdmp' in MSSSET.ASM
  1718. ; Puts device name in global string prtnam.
  1719.  
  1720.         mov     dx,offset rdbuf         ; work area
  1721.         mov     rdbuf,0                 ; clear it
  1722.         mov     bx,offset prthlp    ; help message
  1723.         mov     ah,cmword               ; allow paths
  1724.         call    comnd
  1725.         jnc    comsd0
  1726.         ret
  1727. comsd0:
  1728.         mov     ah,cmeol
  1729.         call    comnd
  1730.         jnc    comsd1
  1731.         ret
  1732. comsd1:
  1733.         mov     dx,offset rdbuf         ; assume we will use this text
  1734.         call    strlen                  ; filename given?
  1735.     push    si
  1736.     push    di
  1737.         mov     si,dx                   ; for strcpy
  1738.         cmp     cx,0                    ; length of user's filename
  1739.         jg      comsd2            ; g = filename is given
  1740.         mov     si,offset prtdef    ; no name, use default instead
  1741. comsd2:
  1742.         mov     di,offset prtnam    ; copy to globally available loc
  1743.         call    strcpy
  1744.     pop    di
  1745.     pop    si
  1746.  
  1747.     call    serrst            ; reset serial port
  1748.     call    clsprt            ; close previous device if exists.
  1749.     call    opnprt            ; open device
  1750.     jnc    comsd3
  1751.     stc
  1752.     ret
  1753. comsd3:
  1754.     mov    portval,offset portd    ; set device port data
  1755.     mov    flags.comflg,'D'
  1756.     clc
  1757.     ret
  1758. ;
  1759. COMS    ENDP
  1760.  
  1761. ; Set heath emulation on/off.
  1762.  
  1763.  
  1764. VTSTAT  PROC    NEAR    ; For Status display [jrd]
  1765.     push    ax
  1766.     push    bx
  1767.     push    cx
  1768.     push    dx
  1769.     push    si
  1770.     push    di
  1771.     push    es
  1772. ;
  1773.     push    ds
  1774.     pop    es
  1775.     cld
  1776. ;  CPU clock
  1777.     mov    si,offset clkmsg
  1778.     mov    cx,8
  1779.     cmp    cpu_clock,CPU_5M_CLOCK
  1780.     je    vtstat0
  1781.     add    si,cx
  1782. vtstat0:
  1783.     mov    di,offset vstmsg_clk
  1784.     rep    movsb
  1785. ;  Display
  1786.     mov    si,offset dspmsg
  1787.     mov    cx,8
  1788.     cmp    display_mode,0
  1789.     je    vtstat0_1
  1790.     add    si,cx
  1791. vtstat0_1:
  1792.     mov    di,offset vstmsg_dsp
  1793.     rep    movsb
  1794. ;  Keyclick
  1795.     mov    si,offset onmsg
  1796.     mov    cx,3
  1797.     test    vt100_flags,KEYCLICK_BIT
  1798.     jz    vtstat1
  1799.     add    si,cx
  1800. vtstat1:
  1801.     mov    di,offset vstmsg_key
  1802.     rep    movsb
  1803. ;  Log-cooked
  1804.     mov    si,offset onmsg
  1805.     mov    cx,3
  1806.     test    vt100_lflag,LOGCOOK_BIT
  1807.     jz    vtstat2
  1808.     add    si,cx
  1809. vtstat2:
  1810.     mov    di,offset vstmsg_logcook
  1811.     rep    movsb
  1812. ;  Autowrap
  1813.     mov    si,offset onmsg
  1814.     mov    cx,3
  1815.     test    vt100_flags,AUTOWRAP_BIT
  1816.     jz    vtstat3
  1817.     add    si,cx
  1818. vtstat3:
  1819.     mov    di,offset vstmsg_autow
  1820.     rep    movsb
  1821. ;  Cursor key mode
  1822.     mov    si,offset applmsg
  1823.     mov    cx,11
  1824.     mov    di,offset vstmsg_curmod
  1825.     cmp    curkey_mode,0
  1826.     je    vtstat5
  1827.     add    si,cx
  1828. vtstat5:
  1829.     rep    movsb
  1830. ;  Keypad mode
  1831.     mov    si,offset applmsg
  1832.     mov    cx,11
  1833.     mov    di,offset vstmsg_kpdmod
  1834.     cmp    keypad_mode,0
  1835.     je    vtstat7
  1836.     add    si,cx
  1837. vtstat7:
  1838.     rep    movsb
  1839. ;  Foreground
  1840.     mov    si,offset colmsg
  1841.     mov    di,offset def_color
  1842.     mov    al,[di]
  1843.     mov    ah,0
  1844.     mov    cx,7
  1845.     imul    cl
  1846.     add    si,ax
  1847.     mov    di,offset vstmsg_colf
  1848.     rep    movsb
  1849. ;  Background
  1850.     mov    si,offset colmsg
  1851.     mov    di,offset def_color
  1852.     mov    al,[di+1]
  1853.     mov    ah,0
  1854.     mov    cx,7
  1855.     imul    cl
  1856.     add    si,ax
  1857.     mov    di,offset vstmsg_colb
  1858.     rep    movsb
  1859. ;  Highlight
  1860.     mov    si,offset colmsg
  1861.     mov    di,offset def_color
  1862.     mov    al,[di+2]
  1863.     mov    ah,0
  1864.     mov    cx,7
  1865.     imul    cl
  1866.     add    si,ax
  1867.     mov    di,offset vstmsg_colh
  1868.     rep    movsb
  1869. ;  Modeline
  1870.     mov    si,offset colmsg
  1871.     mov    di,offset def_color
  1872.     mov    al,[di+3]
  1873.     mov    ah,0
  1874.     mov    cx,7
  1875.     imul    cl
  1876.     add    si,ax
  1877.     mov    di,offset vstmsg_colm
  1878.     rep    movsb
  1879. ;  Kanji-code send
  1880.     mov    si,offset knjmsg
  1881.     mov    ah,0
  1882.     mov    al,kanji_scode
  1883.     mov    cx,9
  1884.     imul    cl
  1885.     add    si,ax
  1886.     mov    di,offset vstmsg_sknj
  1887.     rep    movsb
  1888. ;  Kanji-code receive
  1889.     mov    si,offset knjmsg
  1890.     mov    ah,0
  1891.     mov    al,kanji_rcode
  1892.     mov    cx,9
  1893.     imul    cl
  1894.     add    si,ax
  1895.     mov    di,offset vstmsg_rknj
  1896.     rep    movsb
  1897. ;  Keyinput
  1898.     mov    si,offset keyinmsg
  1899.     mov    ah,0
  1900.     mov    al,keyin_dos
  1901.     mov    cx,6
  1902.     imul    cl
  1903.     add    si,ax
  1904.     mov    di,offset vstmsg_keyin
  1905.     rep    movsb
  1906. ;  Insert/Replace
  1907.     mov    si,offset insrepmsg
  1908.     mov    cx,7            ; message length
  1909.     test    vt100_flags,INSERT_BIT
  1910.     jz    vtstat10
  1911.     add    si,cx
  1912. vtstat10:
  1913.     mov    di,offset vstmsg_insrep
  1914.     rep    movsb
  1915. ;  Origin-mode
  1916.     mov    si,offset originmsg
  1917.     mov    cx,8
  1918.     test    vt100_flags,ORIGIN_BIT
  1919.     jz    vtstat11
  1920.     add    si,cx
  1921. vtstat11:
  1922.     mov    di,offset vstmsg_origin
  1923.     rep    movsb
  1924. ;  Line-feed/New-line
  1925.     mov    si,offset lfnlmsg
  1926.     mov    cx,9
  1927.     test    vt100_flags,NEWLINE_BIT
  1928.     jz    vtstat12
  1929.     add    si,cx
  1930. vtstat12:
  1931.     mov    di,offset vstmsg_lfnl
  1932.     rep    movsb
  1933. ;
  1934.     mov    ah,prstr
  1935.     mov    dx,offset vstmsg
  1936.     int    dos
  1937. ;
  1938.     call    tekstat
  1939.     mov    dx,si
  1940.     mov    ah,prstr
  1941.     int    dos
  1942. ;
  1943.     pop    es
  1944.     pop    di
  1945.     pop    si
  1946.     pop    dx
  1947.     pop    cx
  1948.     pop    bx
  1949.     pop    ax
  1950.         ret             ; no emulator status to display
  1951. VTSTAT  ENDP
  1952.  
  1953. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  1954. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  1955. ; is determined by mssset and is passed as pointer dmpname.
  1956.  
  1957. DUMPSCR PROC    NEAR    ; Dumps screen contents to a file. Just Beeps here
  1958.  
  1959.     push    ax
  1960.     push    bx
  1961.     push    cx
  1962.     push    dx
  1963.  
  1964.     mov     dmphand,-1              ; preset illegal handle
  1965.     mov     dx,offset dmpname       ; name of disk file, from mssset
  1966.     mov     ax,dx                   ; where isfile wants name ptr
  1967.     call    isfile                  ; what kind of file is this?
  1968.     jc      dmp5                    ; c = no such file, create it
  1969.     test    byte ptr filtst.dta+21,1fh ; file attributes, ok to write?
  1970.     jnz     dmp0                    ; nz = no.
  1971.     mov     al,1                    ; writing
  1972.     mov     ah,open2                ; open existing file
  1973.     int     dos
  1974.     jc      dmp0                    ; c = failure
  1975.     mov     dmphand,ax              ; save file handle
  1976.     mov     bx,ax                   ; need handle here
  1977.     mov     cx,0ffffh               ; setup file pointer
  1978.     mov     dx,-1                   ; and offset
  1979.     mov     al,2                    ; move to eof minus one byte
  1980.     mov     ah,lseek                ; seek the end
  1981.     int     dos
  1982.     jmp     dmp1
  1983.  
  1984. dmp5:    test    filtst.fstat,80h        ; access problem?
  1985.     jnz     dmp0                    ; nz = yes
  1986.     mov     ah,creat2               ; file did not exist
  1987.     mov     cx,20h                  ; attributes, archive bit
  1988.     int     dos
  1989.     mov     dmphand,ax              ; save file handle
  1990.     jnc     dmp1                    ; nc = ok
  1991.  
  1992. dmp0:    call    beep
  1993.     pop     dx
  1994.     pop     cx
  1995.     pop     bx
  1996.     pop     ax
  1997.     clc
  1998.     ret
  1999.  
  2000. dmp1:    mov     ah,ioctl                ; is destination ready for output?
  2001.     mov     al,7                    ; test output status
  2002.     mov     bx,dmphand              ; handle
  2003.     int     dos
  2004.     jc      dmp0                    ; c = error
  2005.     cmp     al,0ffh                 ; ready?
  2006.     jne     dmp0                    ; ne = not ready.
  2007. ;
  2008.     cmp    flags.vtflg,ttvt100
  2009.     je    dmp_v1
  2010.     cmp    flags.vtflg,ttvt52
  2011.     je    dmp_v1
  2012.     call    ent_vt
  2013. dmp_v1:
  2014.     mov     bx,dmphand              ; need file handle
  2015.     call    vt100_dump
  2016. ;
  2017.     mov    bx,offset tmpbuf
  2018.     mov    byte ptr [bx],CTLZ    ; put EOF mark
  2019.     mov    dx,bx
  2020.     mov    bx,dmphand
  2021.     mov    cx,1
  2022.     mov    ah,write2
  2023.     int    dos            ; write EOF
  2024. ;
  2025.     mov     ah,close2               ; close the file now
  2026.     int     dos
  2027. ;
  2028.     pop     dx
  2029.     pop     cx
  2030.     pop     bx
  2031.     pop     ax
  2032.     clc
  2033.     ret
  2034.  
  2035. DUMPSCR ENDP
  2036.  
  2037. ; Initialize variables to values used by this routine.
  2038.  
  2039. lclini:
  2040.     call    detclck        ; determine CPU clock
  2041.     call    pcwtst        ; adjust wait counter
  2042.     mov    prthnd,0    ; No handle yet
  2043.     mov    portval,offset port1    ; default portval
  2044.     mov    pbaud_1,0FFFFh    ; previous baud rate is unknown
  2045.     mov    flags.comflg,1    ; Communication port 1
  2046.     mov    flags.vtflg,ttvt100    ; override default terminal type
  2047.     call    getbaud        ; Put the baud rate in portval [08-Feb-89]
  2048.     mov    curkey_mode,0    ; cursor key is ANSI normal
  2049.     mov    keypad_mode,0    ; keypad is normal
  2050.     mov    vt100_flags,AUTOTEK_BIT    ; set flags
  2051.     mov    vt100_lflag,LOGCOOK_BIT ; log mode is cooked
  2052.     mov    vt100_gflag,0
  2053.     mov    kanji_scode,KNJCODE_DEC    ; DEC kanji code
  2054.     mov    kanji_rcode,KNJCODE_DEC
  2055.     mov    kanji_smode,0    ; 1st character must be Kanji 1st byte.
  2056.     mov    kanji_rmode,0
  2057.     mov    xmtcnt,0        ; clear counter for xfer
  2058.     or    flags.remflg,d8bit    ; display 8-bit
  2059.     call    set_keydef
  2060.     mov    lclexit,offset lclclose    ; set local close routine
  2061.         call    msuinit        ; declare keyboard translator present
  2062.         call    kbdlini        ; keyboard local initialize
  2063.     call    vt100_ini    ; initialize VT100 terminal emulator
  2064.     call    tek4014_ini    ; initialize TEK4014 terminal emulator
  2065.         push    si
  2066.         mov    si,offset def_color
  2067.         call    set_cur_color
  2068.         call    vt100_color    ; setup color index table
  2069.         call    tek4014_color    ; same for Tek4014
  2070.     pop    si
  2071.     mov    ah,prstr        ;@@
  2072.     mov    dx,offset fulscr    ;@@
  2073.     int    dos            ;@@
  2074.     clc
  2075.         ret
  2076.  
  2077. showkey:
  2078.         mov ax,offset shkmsg
  2079.         mov cx,shklen
  2080.         ret
  2081.  
  2082. detclck    proc    near
  2083. ;
  2084. ;  determine CPU clock
  2085. ;
  2086.     mov    cpu_clock,CPU_5M_CLOCK
  2087.     push    ax
  2088.     in    al,042h
  2089.     test    al,0C0h
  2090.     jz    detclck1
  2091.     test    al,020h
  2092.     jz    detclck1
  2093.     mov    cpu_clock,CPU_8M_CLOCK
  2094. detclck1:
  2095.     pop    ax
  2096.     ret
  2097. detclck    endp
  2098.  
  2099. ; serial port interrupt routine.  This is not accessible outside this
  2100. ; module, handles serial port receiver interrupts.
  2101.  
  2102. SERINT    PROC  NEAR
  2103.     push ds            ; save these on remote stack
  2104.     push ax
  2105.     mov ax,seg data        ; get our own data segment
  2106.     mov ds,ax
  2107.     mov mnsp,sp        ; save remote stack information
  2108.     mov mnsseg,ss
  2109.     mov sp,offset mnstk    ; switch to local stack
  2110.     mov ss,ax
  2111.     push es            ; and save remaining registers
  2112.     push bp
  2113.     push di
  2114.     push si
  2115.     push dx
  2116.     push cx
  2117.     push bx
  2118.     mov es,ax
  2119.     call mnproc        ; process the interrupt
  2120.     mov al,icEOI
  2121.           mov dx,intcmda
  2122.     out dx,al
  2123.     pop bx            ; restore registers from stack
  2124.     pop cx
  2125.     pop dx
  2126.     pop si
  2127.     pop di
  2128.     pop bp
  2129.     pop es
  2130.     mov ax,mnsseg        ; switch back to remote stack
  2131.     mov ss,ax
  2132.     mov ax,mnsp
  2133.     mov sp,ax
  2134.     pop ax
  2135.     pop ds
  2136.     iret
  2137.  
  2138. ; handler for serial input
  2139.  
  2140. mnproc:    cld
  2141.     mov di,srcpnt        ; get buffer pointer
  2142.     mov dx,modem.mdstat    ; is data available?
  2143.     in al,dx
  2144.     test al,rxrdy
  2145.     jz mnpro7
  2146.     mov dx,modem.mddat    ; read data
  2147.     in al,dx
  2148.     or al,al
  2149.     jz mnpro7        ; Ignore nulls.
  2150.  
  2151. ; do NOT ignore rubouts, because TEK LOY code use this.
  2152. ;    cmp al,7FH        ; Ignore rubouts, too.
  2153. ;    jz mnpro7
  2154.  
  2155.     mov ah,al
  2156. ;
  2157. ; originally the following was
  2158. ;
  2159. ;    and ah,7fH        ; only consider low-order 7 bits for flow ctl.
  2160. ; do NOT mask 8-th bit for flow control when parity is none.
  2161.     and ah,parmsk        ; apply parity mask for flow ctl.
  2162.     mov bp,portval
  2163.     cmp ds:[bp].floflg,0    ; Doing flow control?
  2164.     je mnpro4        ; Nope.
  2165.     mov bx,ds:[bp].flowc    ; Flow control char (BH = XON, BL = XOFF).
  2166.     cmp ah,bl        ; Is it an XOFF?
  2167.     jne mnpro3        ; Nope, go on.
  2168.     mov xofrcv,true        ; Set the flag.
  2169.     jmp short mnpro7
  2170. mnpro3:    cmp ah,bh        ; Get an XON?
  2171.     jne mnpro4        ; No, go on.
  2172.     mov xofrcv,false    ; Clear our flag.
  2173.     jmp mnpro7
  2174. mnpro4:    stosb
  2175.     cmp di,offset source + bufsiz
  2176.     jb mnpro5        ; not past end...
  2177.     mov di,offset source    ; wrap buffer around
  2178. mnpro5:    mov srcpnt,di        ; update ptr
  2179.     inc count
  2180.     cmp ds:[bp].floflg,0    ; Doing flow control?
  2181.     je mnpro7        ; No, just leave.
  2182.     cmp xofsnt,true        ; Have we sent an XOFF?
  2183.     je mnpro7        ; Yes.
  2184.     cmp count,mntrgh    ; Past the high trigger point?
  2185.     jbe mnpro7        ; No, we're within our limit.
  2186.     mov ah,bl        ; Get the XOFF.
  2187.     call outchr        ; Send it.
  2188.      nop            ;   ignore failure.
  2189.      nop
  2190.      nop
  2191.     mov xofsnt,true        ; Remember we sent it.
  2192. mnpro7:    ret
  2193.  
  2194. SERINT    ENDP
  2195.  
  2196. ; Initialization for using serial port.  Returns normally.
  2197.  
  2198. SERINI  PROC    NEAR
  2199.     cmp    flags.comflg,'A'    ;@@@@@
  2200.     jae    serin1            ;@@@@@
  2201.     call    inita
  2202.  
  2203. serin0:;;;;     call clrbuf     ; Clear input buffer.
  2204. ;;        push    bx
  2205. ;;        mov     bx,portval      ; get port
  2206. ;;        mov     parmsk,0ffh     ; parity mask, assume parity is None
  2207. ;;        cmp     [bx].parflg,parnon ; is it None?
  2208. ;;        je      serin1          ; e = yes
  2209. ;;        mov     parmsk,07fh     ; no, pass lower 7 bits as data
  2210. ;;serin1: mov     bx,[bx].flowc   ; get flow control chars
  2211. ;;        mov     flowoff,bl      ; xoff or null
  2212. ;;        mov     flowon,bh       ; xon or null
  2213. ;;        pop     bx
  2214. serin1:
  2215.     clc            ; always success ! true ?!
  2216.         ret                     ; We're done.
  2217. SERINI  ENDP
  2218.  
  2219. ; Reset the serial port.  This is the opposite of serini.  Calling
  2220. ; this twice without intervening calls to serini should be harmless.
  2221. ; Returns normally.
  2222.  
  2223. SERRST  PROC    NEAR
  2224.     cmp portinia,0        ; Did we reset port already?
  2225.     je rsta0        ; Yes, so just leave.
  2226.     push es
  2227.     cli            ; Disable interrupts
  2228.     xor ax,ax        ; Address low memory
  2229.     mov es,ax
  2230.     mov ax,oldsera_ofs    ; Restore interrupt vector
  2231.     mov es:[4*icsvcta],ax
  2232.     mov ax,oldsera_sgm
  2233.     mov es:[4*icsvcta+2],ax
  2234.     mov dx,intmska        ; restore old master controller mask
  2235.     mov al,oldmska
  2236.     out dx,al
  2237.     mov dx,mnmska        ; disable serial interrupts at port
  2238. ;    mov al,txmsk+rxmsk+tbemsk
  2239.     mov al,oldmsdat
  2240.     out dx,al
  2241.     mov portinia,0        ; Remember port has been reset
  2242.     sti            ; Allow interrupts
  2243.     pop es
  2244. rsta0:
  2245.     clc
  2246.     ret
  2247. SERRST  ENDP
  2248.  
  2249. ; Local routine to initialize the standard serial port
  2250.  
  2251. INITA    PROC    NEAR
  2252.     cmp    portinia,1    ; Did we initialize port already ?
  2253.     je    inita0        ; Yes, so just leave.
  2254. ;
  2255.     cli            ; Disable interrupts
  2256.     push    ax
  2257.     push    dx
  2258.     push    es
  2259. ;
  2260.     mov    ax,offset port1
  2261.     mov    portval,ax
  2262.     xor    ax,ax
  2263.     mov    es,ax
  2264.     mov    ax,es:[4*icsvcta]    ; save interrupt vector for port1
  2265.     mov    oldsera_ofs,ax
  2266.     mov    ax,es:[4*icsvcta+2]
  2267.     mov    oldsera_sgm,ax
  2268.     mov    ax,offset serint    ; pointer to our routine
  2269.     mov    es:[4*icsvcta],ax    ; set interrupt routine offset
  2270.     mov    es:[4*icsvcta+2],cs    ;  and segment
  2271.     mov    dx,intmska
  2272.     in    al,dx
  2273.     mov    oldmska,al        ; save old master controller mask
  2274. ;
  2275.     and    al,not icsmska        ; enable serial interrupt at master
  2276.     out    dx,al
  2277.     mov    dx,mnmska
  2278.     in    al,dx
  2279.     mov    oldmsdat,al
  2280.     and    al,0f8h
  2281.     or    al,rxmsk
  2282.     out    dx,al
  2283.     mov    modem.mddat,mndata
  2284.     mov    modem.mdstat,mnst1a
  2285.     mov    modem.mdcom,mncmda
  2286.     mov    timer.tmdat,tmdata
  2287.     mov    timer.tmcmd,tmcmda
  2288.     mov    timer.tmsel,tmsela
  2289.     call    dobaud
  2290.     mov    portinia,1
  2291.     call    clrbuf
  2292. ;
  2293.     pop    es
  2294.     pop    dx
  2295.     pop    ax
  2296.     sti
  2297. inita0:    ret
  2298. INITA    ENDP
  2299.  
  2300. ;
  2301. ; Produce a short beep.  The PC DOS bell is long enough to cause a loss
  2302. ; of data at the port.  Returns normally.
  2303.  
  2304. BEEP    PROC    NEAR
  2305.         mov dl,bell
  2306.         mov ah,dconio
  2307.         int dos
  2308.         ret
  2309. BEEP    ENDP
  2310. ;
  2311.  
  2312.  
  2313. ; Terminal emulator.
  2314. ;
  2315. term    proc    near
  2316.     mov    oldsp,sp        ; remember stack for i/o failure,
  2317.     mov    prthld,0        ; clear port hold flag at the beginning
  2318.     mov    replay_hold,0
  2319.     mov    bx,portval
  2320.     mov    bx,[bx].flowc        ; get flow control character
  2321.     mov    flowoff,bl
  2322.     mov    flowon,bh
  2323.     or    vt100_flags,AUTOTEK_BIT
  2324.     test    denyflg,tekxflg
  2325.     jz    term_01
  2326.     and    vt100_flags,(not AUTOTEK_BIT)
  2327. term_01:
  2328.     and    vt100_lflag,(not LOGENAB_BIT)
  2329.     test    flags.capflg,logses    ; session logging enabled?
  2330.     jz    term_02            ; z = no.
  2331.     or    vt100_lflag,LOGENAB_BIT
  2332. term_02:
  2333.     call    vt100_restore
  2334.     call    tek4014_restore
  2335.     mov    fairness,0
  2336.     mov    kanji_smode,0        ; clear Kanji pending flag
  2337.     mov    kanji_rmode,0
  2338.     mov    kanji_7smode,0
  2339.     mov    kanji_7rmode,0
  2340.         mov     argadr,ax               ; save argument ptr
  2341.         mov     si,ax                   ; this is source
  2342.         mov     di,offset vt_ourarg        ; place to store arguments
  2343.         mov     ax,ds
  2344.         mov     es,ax                   ; address destination segment
  2345.         mov     cx,size termarg
  2346.         cld
  2347.         rep     movsb                   ; copy into our arg blk
  2348. ;@@    and    vt_ourarg.flgs,not (prtscr) ; no screen printing at startup
  2349. ;@@    mov    vt100_pflag,0
  2350.         mov     ax,vt_ourarg.captr
  2351.         mov     captrtn,ax              ; buffer capture routine
  2352.     test    vt_ourarg.flgs,modoff    ; mode line off?
  2353.     jnz    term_1
  2354.     call    set_modlin        ; setup mode line
  2355. term_1:
  2356.         mov     parmsk,0ffh             ; parity mask, assume parity = None
  2357.         cmp     vt_ourarg.parity,parnon    ; is parity None?
  2358.         je      term_2            ; e = yes, keep all 8 bits
  2359.         mov     parmsk,07fh             ; else keep lower 7 bits
  2360. term_2:
  2361.     mov    ax,KI_code
  2362.     call    ans_keystr
  2363.     mov    KI_len,cx
  2364.     mov    KI_ofs,bx
  2365.     mov    ax,KO_code
  2366.     call    ans_keystr
  2367.     mov    KO_len,cx
  2368.     mov    KO_ofs,bx
  2369. ;
  2370.     cmp    flags.vtflg,ttvt100    ; vt100 emulation ?
  2371.     je    term_vt            ; e = yes.
  2372.     cmp    flags.vtflg,ttvt52    ; vt52 emulation ?
  2373.     je    term_vt            ; e = yes.
  2374.     cmp    flags.vtflg,tttek    ; Tek4014 emulation ?
  2375.     je    term_tk            ; e = yes.
  2376.     jmp    term0            ; non supported terminal
  2377. ;
  2378. ;  vt100/vt52 emulation
  2379. term_vt:
  2380.     call    ent_vt
  2381.     jmp    term0
  2382. ;
  2383. ;  tek4014 emulation
  2384. term_tk:
  2385.     call    ent_tk
  2386. ;
  2387. term0:
  2388. ;    test    vt100_flags,LOOPTEST_BIT
  2389. ;    je    term1
  2390. ;    jmp    term_tst1
  2391.  
  2392. term1:  call    portchr         ; get char from port, apply parity mask
  2393.         jc    short term2    ; c = no char, go on
  2394.         call    outtty          ; display and capture char
  2395.     inc    fairness
  2396.     cmp    fairness,100
  2397.     jb    term1        ; do quick loop back for more
  2398. term2:    mov    fairness,0
  2399.     call    pntflsh        ; flush printer buffer
  2400.     jnc    term2a        ; nc = success
  2401.     call    pntdead        ; call bad printer notifier
  2402. term2a:    call    keybd           ; keyboard translator to read and send text
  2403.         jnc     term1           ; nc = do not exit Connect mode
  2404.  
  2405. quit:    call    pntflsh        ; flush printer buffer
  2406.     cmp    flags.vtflg,ttgenrc    ; no emulation ?
  2407.     je    term3
  2408.     call    vt100_save
  2409.     call    tek4014_save
  2410. term3:    mov    al,1
  2411.     call    text_scrn    ; ON the text screen
  2412.     xor    al,al
  2413.     mov    ah,prstr
  2414.         mov    dx,offset retscr
  2415.         int    dos
  2416.     ret
  2417.  
  2418. ;term_tst1:
  2419. ;    mov    ax,3D00h    ; open file (read only)
  2420. ;    mov    dx,offset playback_fnam
  2421. ;    int    dos
  2422. ;    jc    term_tstz    ; if error, then normal operation
  2423. ;    mov    playback_hndl,ax
  2424. ;term_tst2:
  2425. ;@@    call    portchr
  2426. ;@@    jnc    short term_tst3
  2427. ;@@    call    outtty
  2428. ;@@    jmp    term_tst2
  2429. ;term_tst3:
  2430. ;    mov    ah,3Fh        ; read file/device
  2431. ;    mov    dx,offset tmpbuf
  2432. ;    mov    bx,playback_hndl
  2433. ;@@    mov    cx,8
  2434. ;    mov    cx,72        ;@@
  2435. ;    int    dos
  2436. ;    jc    term_tstx
  2437. ;    mov    cx,ax
  2438. ;    jcxz    term_tstx
  2439. ;    mov    si,offset tmpbuf
  2440. ;term_tst4:
  2441. ;    push    cx
  2442. ;    push    si
  2443. ;@@    mov    ah,[si]
  2444. ;@@    call    outchr
  2445. ;@@     nop
  2446. ;@@     nop
  2447. ;@@     nop
  2448. ;    mov    al,[si]        ;@@
  2449. ;    call    outtty        ;@@
  2450. ;    pop    si
  2451. ;    pop    cx
  2452. ;    inc    si
  2453. ;
  2454. ;  check the keyboard by using direct console i/o
  2455. ;  Any key can be used for toggle of screen output.
  2456. ;
  2457. ;    push    dx
  2458. ;    mov    ah,dconio    ; direct console i/o
  2459. ;    mov    dl,0ffh        ; read
  2460. ;    int    dos
  2461. ;    jz    term_tst5
  2462. ;term_tst6:
  2463. ;    mov    ah,dconio
  2464. ;    mov    dl,0ffh
  2465. ;    int    dos
  2466. ;    jz    term_tst6
  2467. ;    cmp    al,CR
  2468. ;    jne    term_tst5
  2469. ;    pop    dx
  2470. ;    jmp    term_tstx
  2471. ;term_tst5:
  2472. ;    pop    dx
  2473. ;
  2474. ;    loop    term_tst4
  2475. ;    jmp    term_tst2
  2476. ;term_tstx:
  2477. ;    mov    ah,3Eh
  2478. ;    mov    bx,playback_hndl
  2479. ;    int    dos
  2480. ;term_tstz:
  2481. ;    and    vt100_flags,NOT LOOPTEST_BIT
  2482. ;    clc
  2483. ;    jmp    term1
  2484.  
  2485. term    endp
  2486.  
  2487. ;; keyboard translator action routines, system dependent, called from msugen.
  2488. ; These are invoked by a jump instruction. Return carry clear for normal
  2489. ; processing, return carry set exit Connect mode (kbdflg has transfer char).
  2490.  
  2491. ; kanji_shiftin sends designation codes for G0 to JIS-C6226.
  2492. ; kanji_shiftout sends designation codes for G0 to JIS-roman.
  2493. ; These routines are called in chrout when JIS-7 is specified.
  2494.  
  2495. kanji_shiftin    proc    near
  2496.     push    ax        ; save ax
  2497.     push    cx
  2498.     push    si
  2499.     mov    cx,KI_len
  2500.     jcxz    kanji_shiftin2
  2501.     mov    si,KI_ofs
  2502. kanji_shiftin1:
  2503.     mov    al,[si]
  2504.     push    si        ; save si and cx.
  2505.     push    cx        ;   these are broken when local echo is on
  2506.     call    outprt
  2507.     pop    cx
  2508.     pop    si
  2509.     inc    si
  2510.     loop    kanji_shiftin1
  2511. kanji_shiftin2:
  2512.     mov    kanji_7smode,1
  2513.     pop    si
  2514.     pop    cx
  2515.     pop    ax
  2516.     ret
  2517. kanji_shiftin    endp
  2518.  
  2519. kanji_shiftout    proc    near
  2520.     push    ax        ; save ax
  2521.     push    cx
  2522.     push    si
  2523.     mov    cx,KO_len
  2524.     jcxz    kanji_shiftout2
  2525.     mov    si,KO_ofs
  2526. kanji_shiftout1:
  2527.     mov    al,[si]
  2528.     push    si        ; save si and cx.
  2529.     push    cx        ;   these are broken when local echo is on
  2530.     call    outprt
  2531.     pop    cx
  2532.     pop    si
  2533.     inc    si
  2534.     loop    kanji_shiftout1
  2535. kanji_shiftout2:
  2536.     mov    kanji_7smode,0
  2537.     pop    si
  2538.     pop    cx
  2539.     pop    ax
  2540.     ret
  2541. kanji_shiftout    endp
  2542.  
  2543. ; chrout is called from KEYBD after key definition translation.
  2544. ; the character is in AL.
  2545.  
  2546. chrout:
  2547.     cmp    kanji_scode,KNJCODE_NONE    ; if kanji is not used,
  2548.     je    chroutx2            ;   no translation
  2549.     cmp    kanji_scode,KNJCODE_SJIS    ; if shift-JIS is used,
  2550.     je    chroutx2            ;   no translation
  2551.     cmp    kanji_smode,0        ; 1st byte ?
  2552.     je    chrout_1        ; e = yes,
  2553.     jmp    chrout_knj2
  2554. chrout_1:
  2555.     call    is_kanji1        ; Kanji code 1st byte ?
  2556.     jnc    chroutx            ; nc = no. ASCII character
  2557.     mov    kanjis1,al
  2558.     mov    kanji_smode,1
  2559.     jmp    chroutxx
  2560. chroutx:
  2561.     cmp    kanji_scode,KNJCODE_JIS7    ; JIS-7 used ?
  2562.     jne    chroutx2        ; ne = no
  2563.     cmp    kanji_7smode,0        ; roman-mode ?
  2564.     je    chroutx2        ; e = yes.
  2565.     cmp    al,DEL            ; BS and DEL can be used in Kanji mode
  2566.     je    chroutx2
  2567.     cmp    al,BS
  2568.     je    chroutx2
  2569.     call    kanji_shiftout
  2570. chroutx2:
  2571.     test    vt100_flags,NEWLINE_BIT    ; newline mode ?
  2572.     jz    chroutx1        ; z = no
  2573.     cmp    al,0Dh            ; CR ?
  2574.     jne    chroutx1        ; ne = no
  2575.     call    outprt            ; send it
  2576.     mov    al,0Ah            ; send LF
  2577. chroutx1:
  2578.     call    outprt                  ; put char in al to serial port
  2579.     mov    kanji_smode,0
  2580. chroutxx:
  2581.         clc                             ; stay in Connect mode
  2582.         ret
  2583.  
  2584. chrout_knj2:
  2585.     mov    ah,al
  2586.     mov    al,kanjis1
  2587.     call    s2jis
  2588.     cmp    kanji_scode,KNJCODE_JIS7    ; JIS-7 used ?
  2589.     je    chrout_knj21            ; e = yes.
  2590.     or    ax,8080h        ; convert to DEC code
  2591.     jmp    chrout_knj22
  2592. chrout_knj21:
  2593.     cmp    kanji_7smode,0        ; roman-mode ?
  2594.     jne    chrout_knj22        ; ne = no.
  2595.     call    kanji_shiftin
  2596. chrout_knj22:
  2597.     mov    kanjis1,ah
  2598.     mov    ah,0
  2599.     call    outprt
  2600.     mov    al,kanjis1
  2601.     jmp    chroutx1
  2602.  
  2603. trnprs:    push    ax            ; toggle Copy screen to printer
  2604.     test    vt100_pflag,(AUTOPRINT_BIT+PRINTCTRL_BIT)
  2605.                     ; are we currently printing?
  2606.     jz    trnpr0            ; z = no, check the printer status
  2607.     and    vt100_pflag,(not (AUTOPRINT_BIT+PRINTCTRL_BIT))
  2608.                     ; clear printer flag
  2609.     jmp    trnpr1            ; and going off
  2610. trnpr0:
  2611.     push    bx
  2612.     mov    bx,prnhand        ; file handle for system printer
  2613.     mov    ah,ioctl
  2614.     mov    al,7            ; get output status of printer
  2615.     int    dos
  2616.     pop    bx
  2617.     jc    trnpr1            ; c = printer not ready
  2618.     cmp    al,0ffh            ; Ready status
  2619.     jne    trnpr3            ; ne = not-Ready    
  2620.     or    vt100_pflag,AUTOPRINT_BIT    ; set the autoprint flag
  2621. trnpr1:    call    set_modlin
  2622.     call    vt100_modlin
  2623. trnpr3:    pop    ax
  2624.     clc                ; return carry clear (don't quit)
  2625.     ret
  2626.  
  2627. prtscn:    call    vt100_prns
  2628.     clc
  2629.     ret
  2630.  
  2631. klogon    proc    near            ; resume logging (if any)
  2632.     test    flags.capflg,logses    ; session logging enabled?
  2633.     jz    klogn            ; z = no, forget it
  2634.         or      vt_ourarg.flgs,capt        ; turn on capture flag
  2635. klogn:  clc
  2636.         ret
  2637. klogon  endp
  2638.  
  2639. klogof  proc    near                    ; suspend logging (if any)
  2640.         and     argadr.flgs,not capt    ; stop capturing
  2641. klogo:  clc
  2642.         ret
  2643. klogof  endp
  2644.  
  2645. uparrw:    mov    al,'A'
  2646.     jmp    short comarr
  2647. dnarrw:    mov    al,'B'
  2648.     jmp    short comarr
  2649. rtarrw:    mov    al,'C'
  2650.     jmp    short comarr
  2651. lfarrw:    mov    al,'D'
  2652. comarr:    push    ax
  2653.     mov    al,ESCAPE        ; [06-July-1990]
  2654.     call    outprt            ; [06-July-1990]
  2655.     cmp    flags.vtflg,ttvt52
  2656.     je    comar2
  2657.     mov    al,'['            ; [06-July-1990]
  2658.     cmp    curkey_mode,0
  2659.     je    comar1
  2660.     mov    al,'O'            ; [06-July-1990]
  2661. comar1:    call    outprt            ; [06-July-1990]
  2662. comar2:
  2663.     pop    ax
  2664.     call    outprt            ; [06-July-1990]
  2665.     clc
  2666.     ret
  2667.  
  2668. pf1:    mov    al,'P'
  2669.     jmp    short compf
  2670. pf2:    mov    al,'Q'
  2671.     jmp    short compf
  2672. pf3:    mov    al,'R'
  2673.     jmp    short compf
  2674. pf4:    mov    al,'S'
  2675. compf:    push    ax
  2676.     mov    al,ESCAPE        ; [06-July-1990]
  2677.     call    outprt            ; [06-July-1990]
  2678.     cmp    flags.vtflg,ttvt52
  2679.     je    compf1
  2680.     mov    al,'O'
  2681.     call    outprt            ; [06-July-1990]
  2682. compf1:
  2683.     pop    ax
  2684.     call    outprt            ; [06-July-1990]
  2685.     clc
  2686.     ret
  2687.  
  2688. kp0:    mov    al,'p'
  2689.     jmp    short comkp
  2690. kp1:    mov    al,'q'
  2691.     jmp    short comkp
  2692. kp2:    mov    al,'r'
  2693.     jmp    short comkp
  2694. kp3:    mov    al,'s'
  2695.     jmp    short comkp
  2696. kp4:    mov    al,'t'
  2697.     jmp    short comkp
  2698. kp5:    mov    al,'u'
  2699.     jmp    short comkp
  2700. kp6:    mov    al,'v'
  2701.     jmp    short comkp
  2702. kp7:    mov    al,'w'
  2703.     jmp    short comkp
  2704. kp8:    mov    al,'x'
  2705.     jmp    short comkp
  2706. kp9:    mov    al,'y'
  2707.     jmp    short comkp
  2708. kpmins:    mov    al,'m'
  2709.     jmp    short comkp
  2710. kpcoma:    mov    al,'l'
  2711.     jmp    short comkp
  2712. kpentr:    mov    al,'M'
  2713.     jmp    short comkp
  2714. kpdot:    mov    al,'n'
  2715.     jmp    short comkp
  2716. comkp:    cmp    keypad_mode,0
  2717.     je    comkp1
  2718.     push    ax
  2719.     mov    al,ESCAPE        ; [06-July-1990]
  2720.     call    outprt            ; [06-July-1990]
  2721.     mov    al,'O'            ; [06-July-1990]
  2722.     cmp    flags.vtflg,ttvt52
  2723.     jne    comkp0
  2724.     mov    al,'?'            ; [06-July-1990]
  2725. comkp0:
  2726.     call    outprt            ; [06-July-1990]
  2727.     pop    ax
  2728.     jmp    short comkp2
  2729. comkp1:    sub    al,40h
  2730. comkp2:
  2731.     call    outprt            ; [06-July-1990]
  2732.     clc
  2733.     ret
  2734.  
  2735. decf6:
  2736. decf7:
  2737. decf8:
  2738. decf9:
  2739. decf10:
  2740. decf11:
  2741. decf12:
  2742. decf13:
  2743. decf14:
  2744. dechelp:
  2745. decdo:
  2746. decf17:
  2747. decf18:
  2748. decf19:
  2749. decf20:
  2750.     jmp    comdec1
  2751. decfind:
  2752.     mov    ah,'1'
  2753.     jmp    comdec
  2754. decinsert:
  2755.     mov    ah,'2'
  2756.     jmp    comdec
  2757. decremove:
  2758.     mov    ah,'3'
  2759.     jmp    comdec
  2760. decselect:
  2761.     mov    ah,'4'
  2762.     jmp    comdec
  2763. decprev:
  2764.     mov    ah,'5'
  2765.     jmp    comdec
  2766. decnext:
  2767.     mov    ah,'6'
  2768. comdec:
  2769.     push    ax
  2770.     mov    ah,ESCAPE
  2771.     call    outchr
  2772.     mov    ah,'['
  2773.     call    outchr
  2774.     pop    ax
  2775.     call    outchr
  2776.     mov    ah,'~'
  2777.     call    outchr
  2778. comdec1:
  2779.     clc
  2780.     ret
  2781.  
  2782. snull:  mov     ah,0                    ; send a null
  2783.         call    outchr                  ; send without echo or logging
  2784.          nop
  2785.          nop
  2786.          nop
  2787.         clc
  2788.         ret
  2789.  
  2790. keyinchg:
  2791.     xor    keyin_dos,1
  2792.     clc
  2793.     ret
  2794.  
  2795. ; change terminal emulator
  2796. ;
  2797. vtchg:
  2798.     cmp    flags.vtflg,ttvt100    ; vt100 emulation mode?
  2799.     jne    vtchg_nvt100
  2800.     call    vt100_save
  2801.     jmp    vtchg1
  2802. vtchg_nvt100:
  2803.     cmp    flags.vtflg,tttek    ; tek emulation mode?
  2804.     jne    vtchg_ntek
  2805.     call    tek4014_save
  2806.     jmp    vtchg1
  2807. vtchg_ntek:
  2808. vtchg1:
  2809.     inc    flags.vtflg
  2810.     cmp    flags.vtflg,TTTYPES
  2811.     jb    vtchg2
  2812.     mov    flags.vtflg,ttgenrc
  2813.     jmp    vtchg3
  2814. vtchg2:
  2815.     cmp    flags.vtflg,ttgenrc
  2816.     jne    vtchg21
  2817.     jmp    vtchg3
  2818. vtchg21:
  2819.     cmp    flags.vtflg,ttvt100
  2820.     jne    vtchg22
  2821.     call    ent_vt
  2822.     jmp    vtchg3
  2823. vtchg22:
  2824.     cmp    flags.vtflg,tttek
  2825.     jne    vtchg23
  2826.     call    ent_tk
  2827.     jmp    vtchg3
  2828. vtchg23:
  2829.     call    set_modlin
  2830.     call    vt100_modlin
  2831.     jmp    vtchg1
  2832. vtchg3:
  2833.     clc            ; stay in connect mode
  2834.     ret
  2835. ;
  2836. ; reset terminal
  2837. vtreset:
  2838.     cmp    flags.vtflg,ttvt100
  2839.     jne    vtreset1
  2840.     call    vt100_reset
  2841.     jmp    vtresetx
  2842. vtreset1:
  2843.     cmp    flags.vtflg,tttek
  2844.     jne    vtreset2
  2845.     call    tek4014_reset
  2846.     jmp    vtresetx
  2847. vtreset2:
  2848. vtresetx:
  2849.     clc
  2850.     ret
  2851.  
  2852. upone:
  2853.     push    ax
  2854.     push    cx
  2855.     call    sense_sftkey
  2856.     test    al,08h        ; GRPH is pressed ?
  2857.     jz    upone_1        ; z=no
  2858.     mov    cx,6
  2859.     call    sixel_rollup
  2860.     jmp    upone_2
  2861. upone_1:
  2862.     mov    cx,1
  2863.     call    vt100_rupn
  2864. upone_2:
  2865.     pop    cx
  2866.     pop    ax
  2867.     clc
  2868.     ret
  2869.  
  2870. dnone:
  2871.     push    ax
  2872.     push    cx
  2873.     call    sense_sftkey
  2874.     test    al,08h        ; GRPH is pressed ?
  2875.     jz    dnone_1
  2876.     mov    cx,6
  2877.     call    sixel_rolldown
  2878.     jmp    dnone_2
  2879. dnone_1:
  2880.     mov    cx,1
  2881.     call    vt100_rdnn
  2882. dnone_2:
  2883.     pop    cx
  2884.     pop    ax
  2885.     clc
  2886.     ret
  2887.  
  2888. upscn:
  2889.     push    cx
  2890.     mov    cx,24
  2891.     call    vt100_rupn
  2892.     pop    cx
  2893.     clc
  2894.     ret
  2895.  
  2896. dnscn:
  2897.     push    cx
  2898.     mov    cx,24
  2899.     call    vt100_rdnn
  2900.     pop    cx
  2901.     clc
  2902.     ret
  2903.  
  2904. gupone:
  2905.     push    cx
  2906.     mov    cx,6
  2907.     call    sixel_rollup
  2908.     pop    cx
  2909.     clc
  2910.     ret
  2911.  
  2912. gdnone:
  2913.     push    cx
  2914.     mov    cx,6
  2915.     call    sixel_rolldown
  2916.     pop    cx
  2917.     clc
  2918.     ret
  2919.  
  2920. kdos:   mov     al,'P'                  ; Push to DOS
  2921.         jmp     short cmdcom
  2922. cstatus:mov     al,'S'                  ; these commands exit Connect mode
  2923.         jmp     short cmdcom
  2924. cquit:  mov     al,'C'
  2925.         jmp     short cmdcom
  2926. cquery: mov     al,'?'
  2927.         jmp     short cmdcom
  2928. chang:  mov     al,'H'                  ; Hangup, drop DTR & RTS
  2929.         jmp     short cmdcom
  2930. trnmod:    mov    al,'M'
  2931.     jmp    short cmdcom
  2932. cmdcom: mov     kbdflg,al               ; pass char to msster.asm via kbdflg
  2933.         stc                             ; say exit Connect mode
  2934.         ret
  2935.                                         ;; end of action routines
  2936. ;
  2937. ; capture routine.
  2938. ; If capture flag is ON, put the character in AL to the file.
  2939. ;
  2940. outcapt    proc    near
  2941.         push    bx
  2942.         mov     bx,argadr               ; args from msster directly
  2943.         test    [bx].flgs,capt          ; capturing output? Can be shut off
  2944.         pop     bx                      ;  if out dev becomes not ready
  2945.         jz      outcapt1        ; no, forget this part
  2946.         push    ax                      ; save char
  2947.         call    captrtn                 ; give it captured character
  2948.         pop     ax                      ; restore character and keep going
  2949. outcapt1:
  2950.     ret
  2951. outcapt    endp
  2952.  
  2953. ;
  2954. ; Dumb terminal emulator. AL is the character to be displayed.
  2955. ; Taken from MSXGEN.ASM .
  2956. ;
  2957. dumbterm    proc    near
  2958.     cmp    vt100_lflag,(LOGCOOK_BIT+LOGENAB_BIT)    ; is cooked logging ?
  2959.     jne    dumbterm1        ; ne = no.
  2960.     call    outcapt
  2961. dumbterm1:
  2962.     test    vt100_pflag,AUTOPRINT_BIT    ; should we be printing?
  2963.     jz    dumbterm2        ; no, keep going
  2964.         push    ax
  2965.         mov     ah,LSTOUT        ; write to system printer device
  2966.         mov     dl,al
  2967.         int     dos
  2968.         pop     ax
  2969.         jnc     dumbterm2        ; nc = successful print
  2970.         push    ax
  2971.         call    beep                    ; else make a noise and
  2972.         call    trnprs                  ;  turn off printing
  2973.         pop     ax
  2974. dumbterm2:
  2975.     test    vt_ourarg.flgs,trnctl      ; debug? if so use dos tty mode
  2976.         jz      dumbterm8        ; z = no
  2977.         mov     ah,conout
  2978.         cmp     al,7fh                  ; Ascii Del char or greater?
  2979.         jb    dumbterm4        ; b = no
  2980.         je    dumbterm3        ; e = Del char
  2981.         push    ax                      ; save the char
  2982.         mov     dl,7eh                  ; output a tilde for 8th bit
  2983.         int     dos
  2984.         pop     ax                      ; restore char
  2985.         and     al,7fh                  ; strip high bit
  2986. dumbterm3:
  2987.     cmp     al,7fh                  ; is char now a DEL?
  2988.         jne    dumbterm4        ; ne = no
  2989.         and     al,3fH            ; strip next highest bit (Del --> '?')
  2990.         jmp    dumbterm5        ; send, preceded by caret
  2991. dumbterm4:
  2992.     cmp     al,' '                  ; control char?
  2993.         jae    dumbterm6        ; ae = no
  2994.         add     al,'A'-1                ; make visible
  2995. dumbterm5:
  2996.     push    ax                      ; save char
  2997.         mov     dl,5eh                  ; caret
  2998.         int     dos                     ; display it
  2999.         pop     ax                      ; recover the non-printable char
  3000. dumbterm6:
  3001.     mov     dl,al
  3002.         int     dos
  3003.         ret
  3004. dumbterm7:
  3005.     test    flags.remflg,d8bit      ; keep 8 bits for displays?
  3006.         jnz     dumbterm8        ; nz = yes, 8 bits if possible
  3007.         and     al,7fh                  ; remove high bit
  3008. dumbterm8:
  3009.     mov     ah,conout               ; dostty screen mode
  3010.         mov     dl,al                   ; write without intervention
  3011.         int     dos                     ; else let dos display char
  3012.         ret                             ; and return
  3013. dumbterm    endp
  3014.  
  3015.  
  3016. ; put the character in al to the screen, do capture and printing,
  3017. ; does translation for Set Input command.
  3018. ; Adapted from msyibm.asm [jrd]
  3019.  
  3020. outtty  proc    near
  3021.         test    flags.remflg,d8bit      ; keep 8 bits for displays?
  3022.         jnz     outnp8                  ; nz = yes, 8 bits if possible
  3023.         and     al,7fh                  ; remove high bit
  3024. outnp8:
  3025.     cmp    vt100_lflag,LOGENAB_BIT    ; raw mode logging ?
  3026.     jne    outtty_lg1        ; ne = no.
  3027.     call    outcapt            ; log it
  3028. outtty_lg1:
  3029.         cmp     rxtable+256,0           ; is translation off?
  3030.         je      outtty_knj0        ; e = yes, off
  3031.         push    bx                      ; Translate incoming char
  3032.         mov     bx,offset rxtable       ; address of translate table
  3033.         xlatb                           ; new char is in al
  3034.         pop     bx
  3035. ;
  3036. ; Kanji test. If kanji is used for receiving characters,
  3037. ; do translation for capture file, printer and display.
  3038. ; The capture file and printer use shift-JIS. On the other hand,
  3039. ; VT100 emulator ueses DEC (extended UNIX - JIS-8) code.
  3040. ;
  3041. outtty_knj0:
  3042.     cmp    kanji_rcode,KNJCODE_NONE    ; Kanji code used ?
  3043.     je    outtty_knj2        ; e = no, no translation
  3044.     cmp    kanji_rcode,KNJCODE_DEC        ; DEC (EUC) code ?
  3045.     jne    outtty_knj1        ; ne = no
  3046.     jmp    outtty_dknj0        ; jump to DEC kanji processor
  3047. outtty_knj1:
  3048.     cmp    kanji_rcode,KNJCODE_SJIS    ; Shift-JIS code ?
  3049.     jne    outtty_knj2        ; ne = no
  3050.     jmp    outtty_sknj0        ; jump to Shift-JIS process
  3051. outtty_knj2:
  3052.     jmp    outtty_trm
  3053. ;
  3054. outtty_dknj0:
  3055.     cmp    flags.vtflg,0        ; dumb terminal ?
  3056.     je    outtty_dknj1        ; e = Yes. Needs code conversion.
  3057.     jmp    outtty_trm1
  3058. outtty_dknj1:
  3059.         cmp    kanji_rmode,0        ; 2-byte code in progress ?
  3060.     je    outtty_dknj2        ; e = No, not in progress.
  3061.     mov    kanjir2,al        ; put 2nd byte
  3062.     mov    ah,al            ; prepare to conversion
  3063.     mov    al,kanjir1        ; put 1st byte
  3064.     cmp    al,08Eh            ; SS2 ?
  3065.     jne    outtty_dknj5        ; ne = No.
  3066.     mov    al,kanjir2        ; get 2nd byte
  3067.     jmp    outtty_dknj3
  3068. outtty_dknj5:
  3069.     and    ax,7f7fh        ; mask 8-th bits
  3070.     call    jis2s            ; convert to Shift-JIS
  3071.     xchg    kanjir1,al        ; save the 2byte code
  3072.     xchg    kanjir2,ah
  3073.     mov    kanjio1,ah
  3074.     mov    al,kanjir1
  3075.     call    dumbterm
  3076.     mov    al,kanjir2
  3077.     jmp    outtty_dknj3
  3078. outtty_dknj2:
  3079.     cmp    al,08Eh            ; SS2 ?
  3080.     je    outtty_dknj4        ; e = Yes.
  3081.     cmp    al,0A0h            ; is Kanji ?
  3082.     jbe    outtty_dknj3        ; z = No.
  3083. outtty_dknj4:
  3084.     mov    kanji_rmode,1        ; set multi-byte flag
  3085.     mov    kanjio1,al        ; save 1st byte
  3086.     mov    kanjir1,al
  3087.     ret
  3088. outtty_dknj3:
  3089.     call    dumbterm
  3090.     mov    kanji_rmode,0
  3091.     ret
  3092. ;
  3093. outtty_sknj0:
  3094. outtty_sknj2:
  3095.     cmp     flags.vtflg,0           ; emulating a terminal?
  3096.         jnz    outtty_sknj3        ; nz = yup, go do something smart
  3097.     call    dumbterm        ; dumb terminal emulation
  3098.     ret
  3099. outtty_sknj3:
  3100.     cmp    kanji_rmode,0        ; is it 1st byte character?
  3101.     je    outtty_sknj4        ; e = yes.
  3102.     mov    kanjio2,al        ; put 2nd byte
  3103.     mov    ah,al            ; prepare to conversion
  3104.     mov    al,kanjio1        ; put 1st byte
  3105.     call    s2jis            ; convert to JIS
  3106.     or    ax,8080h        ; use GR set
  3107.     xchg    kanjio1,al        ; save the 2byte code
  3108.     xchg    kanjio2,ah
  3109.     mov    kanjir1,ah
  3110.     jmp    outtty_trm1
  3111. outtty_sknj4:
  3112.     call    is_kanji1        ; check if kanji
  3113.     jc    outtty_sknj6        ; c = Yes.
  3114.     test    al,80h            ; katakana ?
  3115.     jz    outtty_sknj5        ; z = No.
  3116.     mov    kanji_rmode,1        ; set multi-byte flag
  3117.     mov    kanjio1,08Eh        ; SS2 code
  3118.     mov    kanjio2,al        ; extended UNIX convention
  3119. outtty_sknj5:
  3120.     jmp    outtty_trm1
  3121. outtty_sknj6:
  3122.     mov    kanji_rmode,1
  3123.     mov    kanjir1,al
  3124.     mov    kanjio1,al
  3125.     ret
  3126. ;
  3127. outtty_trm:
  3128.     cmp    flags.vtflg,0
  3129.     jne    outtty_trm1
  3130.     call    dumbterm
  3131.     ret
  3132. outtty_trm1:
  3133.     cmp    flags.vtflg,tttek
  3134.     je    outtty_tk
  3135. ;
  3136. outtty_vt:
  3137. outtty_vt1:
  3138.     cmp    kanji_rmode,0
  3139.     je    outtty_vt3
  3140. outtty_vt2:
  3141.     mov    al,kanjio1
  3142.     call    vt100
  3143.     mov    al,kanjio2
  3144. outtty_vt3:
  3145.     call    vt100
  3146. ;
  3147.     cmp    ah,0
  3148.     jne    outtty_vt4
  3149.     jmp    outtty_snd
  3150. outtty_vt4:
  3151.     push    ax
  3152.     push    dx
  3153. ;;@@    call    vt100_save
  3154.     mov    flags.vtflg,tttek
  3155.     call    ent_tk
  3156.     pop    dx
  3157.     pop    ax
  3158.     cmp    ah,2
  3159.     je    outtty_tk3
  3160.     cmp    ah,3
  3161.     jne    outtty_vt5
  3162.     mov    kanjio1,dh
  3163.     mov    kanjio2,dl
  3164.     jmp    outtty_tk2
  3165. outtty_vt5:
  3166.     jmp    outtty_snd_ex
  3167.  
  3168. outtty_tk:
  3169. outtty_tk1:
  3170.     cmp    kanji_rmode,0
  3171.     je    outtty_tk3
  3172. outtty_tk2:
  3173.     mov    al,kanjio1
  3174.     call    tek4014
  3175.     jnc    outtty_tk2_2
  3176.     jcxz    outtty_tk2_2
  3177. outtty_tk2_1:
  3178.     lodsb
  3179.     push    cx
  3180.     push    si
  3181.     call    vt100
  3182.     pop    si
  3183.     pop    cx
  3184.     loop    outtty_tk2_1
  3185. outtty_tk2_2:
  3186.     mov    al,kanjio2
  3187. outtty_tk3:
  3188.     call    tek4014
  3189.     jnc    outtty_tk3_2
  3190.     jcxz    outtty_tk3_2
  3191. outtty_tk3_1:
  3192.     lodsb
  3193.     push    cx
  3194.     push    si
  3195.     call    vt100
  3196.     pop    si
  3197.     pop    cx
  3198.     loop    outtty_tk3_1
  3199. outtty_tk3_2:
  3200. ;
  3201.     cmp    ah,0
  3202.     jne    outtty_tk4
  3203.     jmp    outtty_snd
  3204. outtty_tk4:
  3205.     push    ax
  3206.     push    dx
  3207. ;;@@    call    tek4014_save
  3208.     mov    flags.vtflg,ttvt100
  3209.     call    ent_vt
  3210.     pop    dx
  3211.     pop    ax
  3212.     cmp    ah,2
  3213.     je    outtty_vt3
  3214.     cmp    ah,3
  3215.     jne    outtty_tk5
  3216.     mov    kanjio1,dh
  3217.     mov    kanjio2,dl
  3218.     jmp    outtty_vt2
  3219. outtty_tk5:
  3220.     jmp    outtty_snd_ex
  3221. ;
  3222. outtty_snd:
  3223.     mov    kanji_rmode,0
  3224.     jcxz    outtty_snd_ex        ; If there is no answer-back, return
  3225. outtty_snd1:
  3226.     mov    ah,[si]
  3227.     call    outchr            ; send character without echo
  3228.      nop
  3229.      nop
  3230.      nop
  3231.     inc    si
  3232.     loop    outtty_snd1
  3233. outtty_snd_ex:
  3234.     ret
  3235.  
  3236. outtty  endp
  3237.  
  3238. ; send the character in al out to the serial port; handle echoing.
  3239. ; Can send an 8 bit char while displaying only 7 bits locally.
  3240. outprt  proc    near
  3241.         test    vt_ourarg.flgs,lclecho     ; echoing?
  3242.         jz      outpr1                  ; z = no, forget it
  3243.         push    ax                      ; save char
  3244.         call    outtty                  ; print it
  3245.         pop     ax                      ; restore
  3246. outpr1: mov     ah,al                   ; this is where outchr expects it
  3247.         call    outchr                  ; output to the port
  3248.         ret
  3249. outprt  endp
  3250.  
  3251. pntdead    proc    near            ; display printer is inoperative msg
  3252.     push    ax
  3253.     test    vt_ourarg.flgs,modoff    ; mode line off?
  3254.     jnz    pntdea1            ; nz = off, skip msg
  3255.     push    bx
  3256.     mov    dx,offset pntmsg    ; say printer not ready
  3257.     call    putmod            ; write on mode line
  3258.     pop    bx
  3259. pntdea1:pop    ax
  3260.     stc                ; say printer not ready
  3261.     ret
  3262. pntdead    endp
  3263.  
  3264.  
  3265. ; Get a char from the serial port manager
  3266. ; returns with carry clear if a character is available
  3267. portchr proc    near
  3268.         call    prtchr                  ; character at port?
  3269.         jc    portc2            ; no character
  3270.     and     al,parmsk               ; apply 8/7 bit parity mask
  3271.         or      al,al                   ; catch nulls
  3272.         jnz    portc2            ; nz = non null
  3273.         stc                ; ignore null
  3274. portc2: ret
  3275. portchr endp
  3276.  
  3277. ; Jump here to exit Connect mode and execute macros 'TERMINALR' (vtrmac) or
  3278. ; 'TERMINALS' (vtsmac). Does nothing if macro does not exist.
  3279. ; Preserves registers except ax. Returns to TELNET caller with 'C' in kbdflg.
  3280. vtrmac    proc    near            ; RESET macro
  3281.     mov    vtmacname,offset vtrname ; select macro name
  3282.     mov    vtmaclen,vtrlen        ; and its length
  3283.     jmp    vtmacro
  3284. vtrmac    endp
  3285.  
  3286. vtsmac    proc    near            ; SET macro
  3287.     mov    vtmacname,offset vtsname
  3288.     mov    vtmaclen,vtslen
  3289.     jmp    vtmacro
  3290. vtsmac    endp
  3291.  
  3292. ; Invoked by keyboard translator when an unknown keyboard verb is used as
  3293. ; a string definition, such as {\ktest}. Enter with vtmacname pointing to
  3294. ; uppercased verb name, asciiz, and vtmaclen set to its length.
  3295. extmacro proc    near
  3296.     jmp    vtmacro
  3297. extmacro endp
  3298.  
  3299. ;
  3300. ; Reference    Macro structure for    db    number of entries (mac names)
  3301. ;  is file     table mcctab       |->    db    length of macroname, excl '$'
  3302. ;  mssset.asm        each entry |->     db    'macroname','$'
  3303. ;  where these               |->    dw    segment:0 of definition string
  3304. ;  are stored.                      (offset part is always 0)    
  3305. ;        Definition string in     db    length of <string with null>
  3306. ;         buffer macbuf          db    'string with trailing null'
  3307. ;
  3308. vtmacro    proc    far            ; common code for macros vtsmac,vtrmac
  3309.     push    bx            ; and Product
  3310.     push    cx
  3311.     push    si
  3312.     push    di
  3313.     push    es
  3314.     mov    ax,ds
  3315.     mov    es,ax
  3316.     mov    di,offset rdbuf+1    ; macro def buffer starts here
  3317.     mov    si,vtmacname        ; pointer to macro name
  3318.     mov    cl,vtmaclen        ; length of macro name<sp/null>text
  3319.     xor    ch,ch
  3320.     mov    [di-1],cl        ; counted string field
  3321.     cld
  3322.     rep    movsb            ; copy to rdbuf
  3323.     mov    byte ptr [di],0        ; null terminator
  3324.     mov    si,offset rdbuf+1    ; look for name-text separator
  3325.     mov    cl,vtmaclen
  3326.     xor    ch,ch
  3327. vtmac1:    lodsb
  3328.     cmp    al,' '            ; space separator?
  3329.     je    vtmac1a            ; e = yes, stop here
  3330.     or    al,al            ; null terminator?
  3331.     jz    vtmac1a            ; e = yes, stop here
  3332.     loop    vtmac1
  3333.     inc    si            ; to do null lenght correctly
  3334. vtmac1a:sub    si,offset rdbuf+1+1    ; compute length of macro name
  3335.     mov    cx,si
  3336.     mov    vtmaclen,cl        ; save a macro name length
  3337.                     ; check for existence of macro
  3338.     mov    bx,offset mcctab    ; table of macro names
  3339.     mov    cl,[bx]            ; number of names in table
  3340.     xor    ch,ch
  3341.     jcxz    vtmacx            ; z = empty table, do nothing
  3342.     inc    bx            ; point to length of first name
  3343. vtmac2:    mov    al,[bx]            ; length of this name
  3344.     xor    ah,ah
  3345.     cmp    al,vtmaclen        ; length same as desired keyword?
  3346.     jne    vtmac3            ; ne = no, search again
  3347.     mov    si,bx
  3348.     inc    si            ; point at first char of name
  3349.     push    cx            ; save name counter
  3350.     push    di            ; save reg
  3351.     mov    cl,vtmaclen        ; length of name, excluding '$'
  3352.     xor    ch,ch
  3353.     mov    di,vtmacname        ; point at desired macro name
  3354.     push    es            ; save reg
  3355.     push    ds
  3356.     pop    es            ; make es use data segment
  3357.     cld
  3358.     repe    cmpsb            ; match strings
  3359.     pop    es            ; need current si below
  3360.     pop    cx
  3361.     pop    di            ; recover saved regs
  3362.     je    vtmac4            ; e = matched
  3363. vtmac3:    add    bx,ax            ; step to next name, add name length
  3364.     add    bx,4            ; + count, dollar sign, def word ptr
  3365.     loop    vtmac2            ; try next name
  3366. vtmacx:    pop    es
  3367.     pop    di
  3368.     pop    si            ; no macro, return to Connect mode
  3369.     pop    cx
  3370.     pop    bx
  3371.     ret
  3372.  
  3373. vtmac4:    cmp    taklev,maxtak        ; room in Take level?
  3374.     jge    vtmacx            ; ge = no, exit with no action
  3375.     inc    taklev            ; increment take level
  3376.     add    takadr,size takinfo    ; make a new Take entry/macro
  3377.     mov    bx,takadr        ; point to current macro structure
  3378.     mov    ax,ds            ; segment of rdbuf
  3379.     mov    [bx].takbuf,ax        ; segment of definition string struc
  3380.     mov    cl,rdbuf        ; length of whole string
  3381.     xor    ch,ch
  3382.     mov    [bx].takcnt,cx        ; number of chars in definition
  3383.     mov    [bx].takargc,0        ; our argument count
  3384.     mov    [bx].takptr,offset rdbuf+1 ; where to read next command char
  3385.     mov    [bx].taktyp,0ffh    ; flag as a macro
  3386.     pop    es
  3387.     pop    di
  3388.     pop    si
  3389.     pop    cx
  3390.     pop    bx
  3391.     jmp    endcon            ; exit Connect mode
  3392. vtmacro    endp
  3393.  
  3394. ; Error recovery routine used when outchr reports unable to send character
  3395. ;  or when vtmacro requests exiting Connect mode.
  3396. ; Exit Connect mode cleanly, despite layers of intermediate calls.
  3397. endcon    proc    near
  3398.     mov    kbdflg,'C'        ; report 'C' to TERM's caller
  3399.     mov    sp,oldsp        ; recover startup stack pointer
  3400.                     ; TERM caller's return address is now
  3401.                     ; on the top of stack. A longjmp.
  3402.     jmp    quit            ; exit Connect mode cleanly
  3403. endcon    endp
  3404. code    ends
  3405.         end
  3406.