home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / msvp98b1.lzh / MSXP98.ASM < prev    next >
Assembly Source File  |  1993-05-18  |  113KB  |  4,456 lines

  1.          name    msxp98
  2. ; File MSXP98.ASM
  3. ; NEC PC-9801 MS DOS Kermit module.
  4. ;
  5. ; Last edit: 01 Dec 1991
  6. ; 18 May 1993 KEK v2.00/Beta added TCP/IP port (from MSXIBM.ASM)
  7. ; 01 Dec 1991 KEK v1.29
  8. ;             support 20 line mode
  9. ;             RTS/CTS handshake
  10. ; 02 Jul 1991 Test version for Color sixel mode -> KEK v1.26
  11. ; 24 May 1991 Bug fixed for CSI (in MSYP98.ASM) -> KEK v1.25
  12. ; 13 May 1991 Bug fixed for serhng (in MSXP98.ASM) -> KEK v1.24
  13. ; 10 May 1991 Bug fixed for script file (in MSXP98.ASM)
  14. ;             vt_ourarg.prt is replaced by flags.comflg . -> KEK v1.23
  15. ; 17 Apr 1991 Joe Doupnik's modifications are added. -> KEK v1.22
  16. ; 05 Apr 1991 KEK v1.21 for MS-Kermit v3.10
  17. ;             correct flow control mismatch.
  18. ;             added pcwtst for correct pcwait.
  19. ; 25 Jul 1990 KEK v1.20 for MS-Kermit v3.02
  20. ; 24 Sep 1989 KEK v1.16 (added VT52 mode).
  21. ; 04 Aug 1989 Fixed wrong ESC M (Reverse index) behavior (in MSYP98.ASM).
  22. ; 30 May 1989 ESC [ 0 m resets to color to default (color in command mode).
  23. ; 25 Apr 1989 KEK v1.15 .
  24. ; 24 Apr 1989 Fixed bug of cooked log for dumb terminal emulator.
  25. ; 21 Apr 1989 Raw mode logging is moved to outside the terminal emulator.
  26. ; 16 Apr 1989 Cooked log in VT100 mode is installed.
  27. ; 01 Mar 1989 Bug on JIS-7 input when local echo is on.
  28. ; 24 Feb 1989 start test of the device port. v1.15 alpha
  29. ; 13 Feb 1989 domode is called when really necessary.
  30. ;             graphic display on when exit.
  31. ; 08 Feb 1989 Call getbaud in lclini.
  32. ; 04 Feb 1989 Bug report from Yoro@Kyoto.Univ. SHOW MODEM becomes mad
  33. ;             when modem is not ready.  This was bug in getmodem.
  34. ; 28 Jan 1989 KEK v1.14, + MS-Kermit 2.23/A
  35. ; 17 Dec 1988 AUTOTEK feature is completely removed. Use eneble/disable Tek.
  36. ; 08 Sep 1988 JIS-7 code for 'Kanji-send' is installed.
  37. ;             The original idea and its code is due to Ogawa, NTT software-lab.
  38. ;             Thanx for cooperation !
  39. ; 16 Jul 1988 Keyboard kanji translation comes into chrout to work with
  40. ;             SET KEY command.
  41. ; 14 Jul 1988 V2.31
  42. ;             old global variable PCNET is now local variable
  43. ;             local termination pointer NETDONE is renamed LCLEXIT
  44. ;             GETMODEM is added as a dummy routine (from MSXGEN.ASM)
  45. ;             Ungermann-Bass port name is UB-NETCI
  46. ; 25 Jun 1988 Ungermann-Bass PC-NIU N98 support in NETCI mode
  47. ; 15 Jun 1988 V1.00
  48. ; 06 Jun 1988 show modem is installed
  49. ; 23 May 1988 added KEYCLICK, AUTOTEK features
  50. ; 19 May 1988 become v2.27(A) level (TEK4014, VT100)
  51. ; 18 May 1988 Keyboard routine for VT100 is installed.
  52. ; 16 May 1988 Works with v2.27(A) VT100 output routine.
  53. ; 15 May 1988 Fixed bug in SERINI.
  54. ; 14 May 1988 Works with dumb terminal emulator !
  55. ; 12 May 1988 start coding based on MSXGEN.ASM by H.Fujii
  56.  
  57.         public  serini, serrst, clrbuf, outchr, coms, vtstat
  58.         public  ctlu, cmblnk, locate, lclini, prtchr, clearl
  59.         public  baudst, getbaud, beep, trnprs
  60.         public    setchtab
  61.         public  count, xofsnt, puthlp, putmod, clrmod, poscur
  62.         public  sendbr, sendbl, term, machnam, setktab, setkhlp, showkey
  63.         public  ihosts, ihostr, dtrlow, serhng, dumpscr
  64.         public    bdtab, comptab, portval
  65.         public  chrout, cstatus, cquit, cquery, chang   ; kbd action verbs
  66.         public  snull, kdos, klogof, klogon
  67.     public    trnmod
  68.         public    shomodem, getmodem, mdmhand
  69.     public    pf1, pf2, pf3, pf4
  70.     public    kp0, kp1, kp2, kp3, kp4, kp5, kp6, kp7, kp8, kp9
  71.     public    decf6, decf7, decf8, decf9, decf10, decf11, decf12, decf13
  72.     public    decf14, dechelp, decdo, decf17, decf18, decf19, decf20
  73.     public    decfind, decinsert, decremove, decselect
  74.     public    decprev, decnext
  75.     public    kpmins, kpcoma, kpentr, kpdot
  76.     public    uparrw, dnarrw, lfarrw, rtarrw
  77.         public    keyinchg
  78.     public    vtchg, vtreset, vtrmac, vtsmac
  79.         public    upone, dnone, upscn, dnscn
  80.         public    gupone, gdnone
  81.         public    prtscn
  82.         public    outcapt
  83.         public    set_cur_color
  84.  
  85.     public    cpu_clock, vtgrph_flg, vttest_flg
  86.     public    curkey_mode, keypad_mode, display_mode
  87.     public    kanji_rmode, kanji_smode
  88.     public    kanji_rcode, kanji_scode
  89.     public    keyin_dos, vt100_cursr
  90.     public  vt100_flags, vt100_pflag, vt100_lflag, vt100_gflag
  91.     public    yflags, vt_ourarg
  92.     public    scn_color, def_color, scrn_lines
  93.     public    extmacro, vtmacname, vtmaclen
  94.         include mssdef.h
  95.         include    msxp98.h
  96.  
  97. CHR_GS    equ    1Dh
  98. CHR_CAN    equ    18h
  99.  
  100. false   equ     0
  101. true    equ     1
  102.  
  103. off    equ    0
  104. bufon    equ    1        ; buffer level xon/xoff on-state control flag
  105. usron    equ    2        ; user level xon/xoff on-state contrl flag
  106.  
  107. instat  equ     6
  108. prtscr  equ     80h                     ; print screen pressed
  109.  
  110. ;
  111. ; SIAM Interface Section (by Kenji Rikitake 30-DEC-1991)
  112. ; from SIAM.INC in SIAM distribution kit
  113. ; modified for MS-Kermit to avoid conflict of symbols
  114.  
  115. ;   -----   INT 2FH entry check  -----
  116. MAGIC        equ    08347h
  117. MAGIC2        equ    04783h
  118. AP_NO_SIAM    equ    0
  119. MAX_PORT    equ    8
  120. FN_NO_SIAM    equ    0
  121.  
  122. ;   -----   Function definition  -----
  123. _siam_getVerSI    equ    1
  124. _siam_releaseSI    equ    2
  125. _siam_initSI    equ    3
  126. _siam_restoreSI    equ    4
  127. _siam_getBaud    equ    5
  128. _siam_setBaud    equ    6
  129. _siam_getParam    equ    7
  130. _siam_setParam    equ    8
  131. _siam_rQClear    equ    9
  132. _siam_sQClear    equ    10
  133. _siam_rQcnt    equ    11
  134. _siam_sQcnt    equ    12
  135. _siam_getSI    equ    13
  136. _siam_putSI    equ    14
  137. _siam_getCH    equ    15
  138. _siam_putCH    equ    16
  139. _siam_getDR    equ    17
  140. _siam_getCS    equ    18
  141. _siam_getCD    equ    19
  142. _siam_getCI    equ    20
  143. _siam_lockRS    equ    21
  144. _siam_unlockRS    equ    22
  145. _siam_setRS    equ    23
  146. _siam_setER    equ    24
  147. _siam_sndBRK    equ    25
  148. _siam_errReset    equ    26
  149. _siam_openSI    equ    27
  150. _siam_closeSI    equ    28
  151.  
  152. def_func    macro    func_name, param
  153. func_name    macro    param
  154.         push    es
  155.         mov    es, data:siam_seg
  156.         ifnb    <param>
  157.             ifdifi    <param>, <ax>
  158.                 mov    ax, param
  159.             endif
  160.             push    ax
  161.         endif
  162.         call    dword ptr es:[_&func_name*4]
  163.         ifnb    <param>
  164.             add    sp, 2
  165.         endif
  166.         pop    es
  167.         endm
  168.         endm
  169.  
  170. def_func    siam_getVerSI
  171. def_func    siam_releaseSI
  172. def_func    siam_initSI
  173. def_func    siam_restoreSI
  174. def_func    siam_getBaud
  175. def_func    siam_setBaud    baud
  176. def_func    siam_getParam
  177. def_func    siam_setParam    param
  178. def_func    siam_rQClear
  179. def_func    siam_sQClear
  180. def_func    siam_rQcnt
  181. def_func    siam_sQcnt
  182. def_func    siam_getSI
  183. def_func    siam_putSI    word
  184. def_func    siam_getCH
  185. def_func    siam_putCH    word
  186. def_func    siam_getDR
  187. def_func    siam_getCS
  188. def_func    siam_getCD
  189. def_func    siam_getCI
  190. def_func    siam_lockRS
  191. def_func    siam_unlockRS
  192. def_func    siam_setRS    on_off
  193. def_func    siam_setER    on_off
  194. def_func    siam_sndBRK    on_off
  195. def_func    siam_errReset
  196. def_func    siam_openSI    id
  197. def_func    siam_closeSI    id
  198.  
  199. ;   -----   DOS Function definition  -----
  200. GETPSP    equ    51h
  201.  
  202. ;   ------------------------------
  203. ; End of SIAM Interface Section
  204.  
  205. ;
  206. ; Ungermann-Bass PC-NIU N98 command interpreter interface
  207. ; CALL    AH -- Function number
  208. ;         AL -- Port number relative to 0
  209. ;         CX -- may be a counter, CL is used as a subfunction for control
  210. ;      ES:BX -- may be a buffer address
  211.  
  212. NETCI_PORT    equ    0        ; NETCI port number
  213.  
  214. NETCI_INT    equ    06Bh        ; Software interrupt vector# for NETCI
  215. NETCI_OPEN    equ    2        ; NETCI open function
  216. NETCI_CLOSE    equ    3        ; NETCI close function
  217. NETCI_READ    equ    1        ; NETCI read function
  218. NETCI_WRITE    equ    0        ; NETCI write function
  219. NETCI_CNTL    equ    6        ; NETCI control function
  220. NETCI_STATUS    equ    7        ; NETCI status function
  221. NETCI_RBRK    equ    8        ; NETCI read break function
  222.  
  223. NETCI_BRK    equ    2        ; NETCI control function, BREAK
  224. NETCI_DIS    equ    4        ; NETCI control function, DISCONNECT
  225. NETCI_HLD    equ    6        ; NETCI control function, HOLD
  226.  
  227. TCPIP_READ    equ    0A5h
  228. TCPIP_WRITE    equ    0A4h
  229.  
  230. NASI_READ    equ    019h        ; Novell NASI read function
  231. NASI_WRITE    equ    018h        ; Novell NASI write function
  232.  
  233. ; Buffer size for Network transfer
  234.  
  235. NETBUFLEN    equ    256
  236.  
  237. ; port assignments for 8251 serial controllers
  238. ;
  239. ;== PORT 1 ==
  240.  
  241. mndata    equ    30h
  242. mnst1a    equ    32h
  243. mncmda    equ    32h
  244.  
  245. mnmska    equ    35h    ; mask set
  246. mnrdsa    equ    33h    ; read signal
  247.  
  248. ;== PORT 2 ==
  249.  
  250. mndatb    equ    0B1h
  251. mnst1b    equ    0B3h
  252. mncmdb    equ    0B3h
  253.  
  254. mnmskb    equ    0B0h
  255. mnrdsb    equ    0B0h    ; read signal
  256.  
  257. ;== PORT 3 ==
  258.  
  259. mndatc    equ    0B9h
  260. mnst1c    equ    0BBh
  261. mncmdc    equ    0BBh
  262.  
  263. mnmskc    equ    0B2h    ; mask set
  264. mnrdsc    equ    0B2h    ; read signal
  265.  
  266. ; Status bits from austt
  267.  
  268. txrdy    equ    01h
  269. rxrdy    equ    02h
  270.  
  271. ; Command values for mncmd
  272. ;   Command
  273. ;          7     6     5     4     3     2     1     0
  274. ;       +-----+-----+-----+-----+-----+-----+-----+-----+
  275. ;       | HUNT|RESET| RTS | ERR | SBRK| RxE | DTR | TxE |
  276. ;       +-----+-----+-----+-----+-----+-----+-----+-----+
  277.  
  278. ccmd        equ    37H    ; RTS & DTR high, RX & TX enabled, ERR reset
  279. cmdrtslow    equ    17H    ; RTS low, DTR high,
  280. cbrk        equ    08H    ; break enabled
  281. chng        equ    10H    ; RTS & DTR low, RX & TX disabled, ERR reset
  282. cmode        equ    40H    ; enable mode reset
  283. mmode        equ    4EH    ; 16x rate, 8 data, no parity, 1 stop
  284.  
  285. ; Mask values for mnmsk
  286.  
  287. txmsk    equ    04H        ; disables transmit ready interrupt
  288. rxmsk    equ    01H        ; disables receive ready interrupt
  289. tbemsk    equ    02H        ; disables transmit buffer empty interrupt
  290.  
  291. ; port assignments for 8253 timers
  292.  
  293. ;        Standard interface
  294.  
  295. tmdata    equ    75H        ; data port
  296. tmcmda    equ    77H        ; command port  (Was 27H Ian 10/27/84)
  297.  
  298.  
  299. ; values for tmcmd which select timer channel and mode
  300.  
  301. tmsela    equ    0B6H        ; Channel 2, mode 3 (standard port)
  302.  
  303. ; Baudrate
  304.  
  305. B9600    equ    13
  306.  
  307. ; Modem information
  308.  
  309. mdminfo struc
  310. mddat   dw      0        ; data port
  311. mdstat  dw      0        ; status port
  312. mdcom   dw      0        ; command port
  313. mdmsk    dw    0        ; interrupt mask port
  314. mdsig    dw    0        ; signal read port
  315. mdminfo ends
  316.  
  317. ; Timer information for current port selection
  318.  
  319. tmrinfo    struc
  320. tmdat    dw    0        ; data port
  321. tmcmd    dw    0        ; command port
  322. tmsel    db    0        ; byte which selects channel and mode
  323. tmrinfo    ends
  324.  
  325. ; Modem information for current port selection
  326.  
  327. ; port assignments for 8259 interrupt controllers
  328.  
  329. ;        Standard interface
  330.  
  331. intcmda    equ    00H        ; Command port (master controller)
  332. intmska    equ    02H        ; Mask port
  333. ictmsk    equ    01H        ; Timer interrupt mask (to master)
  334. icsmska    equ    10H    ; Standard serial interrupt mask (to master)
  335. icsvcta equ    0CH    ;Interrupt vector for standard interface
  336.  
  337. icEOI    equ    20H        ; generic end of interrupt for intcmd
  338.  
  339. ; miscellaneous constants
  340.  
  341. mntrgh    equ    bufsiz*3/4    ; High XON/XOFF trigger = 3/4 of buffer full.
  342. mntrgl    equ    bufsiz/4    ; Low point = 1/4 buffer full
  343.  
  344. _TEXT    segment
  345.     extrn    ktcpstart:far, ktcpstop:far, ktcpcom:far
  346. _TEXT    ends
  347.  
  348. ; external variables used:
  349. ; flags - global flags as per flginfo structure defined in pcdefs
  350. ; trans - global transmission parameters, trinfo struct defined in pcdefs
  351. ; portval - pointer to current portinfo structure (currently either port1
  352. ;    or port2)
  353. ; port1, port2 - portinfo structures for the corresponding ports
  354.  
  355. ; global variables defined in this module:
  356. ; xofsnt, xofrcv - tell whether we saw or sent an xoff.
  357.  
  358. data    segment
  359.     extrn    denyflg:word, rdbuf:byte
  360.         extrn   flags:byte, trans:byte, ttyact:byte
  361.         extrn    repflg:byte, diskio:byte, filtst:byte
  362.         extrn    lclsusp:word, lclrest:word, lclexit:word
  363.         extrn    taklev:byte, takadr:word
  364.         extrn   comand:byte, dmpname:byte, prnhand:word
  365.         extrn   kbdflg:byte, rxtable:byte, mcctab:byte
  366.         extrn    decbuf:byte
  367.         extrn    tcpdata:word, tcphost:byte
  368.  
  369. ;------------------------
  370. cpu_clock    db    0
  371. curkey_mode    db    0
  372. keypad_mode    db    0
  373. display_mode    db    0
  374. ;
  375. kanji_7smode    db    0
  376. kanji_7rmode    db    0
  377. kanji_smode    db    0    ; Kanji 1st/2nd byte indicator
  378. kanji_rmode    db    0
  379. kanji_scode    db    0
  380. kanji_rcode    db    0
  381. ;
  382. keyin_dos    db    0
  383. yflags        db    0    ; flags for lclecho, capt, modoff, ...
  384. vt100_cursr    dw    0    ; cursor lines and attributes
  385. vt100_flags    db    0
  386. vt100_lflag     db      0
  387. vt100_pflag    db    0    ; printer control
  388. vt100_gflag    db    0
  389. ;------------------------
  390. vtgrph_flg    db    0
  391. vttest_flg    db    0
  392. replay_hold    db    0
  393.         db    0    ; adjustment for word boundary
  394. ;------------------------
  395. net_wbuflen    dw    0
  396. net_rbuflen    dw    0
  397. net_port    db    0
  398. net_write    db    0
  399. net_read    db    0
  400.         db    0
  401. ;------------------------
  402. scrn_lines    dw    25    ; number of lines of the screen (25 or 20)
  403. ;
  404. portval        dw    1
  405. ;
  406. ; previous baud rate for serial port 1
  407. pbaud_1        dw    0FFFFh    ; set unknown baud rate
  408. ;
  409. ; color for Foreground, Background, Highlight and Modeline
  410. ;
  411. def_color    db    07h, 00h, 06h, 07h
  412. scn_color    db    07h, 00h, 06h, 07h
  413. ;------------------------
  414.  
  415. fairness    dw    0
  416.  
  417. KI_len        dw    0
  418. KI_ofs        dw    0
  419.  
  420. KO_len        dw    0
  421. KO_ofs        dw    0
  422.  
  423. pcnet        db    0    ; 2.30 global --> 2.31 local
  424.  
  425. kanjis1        db    0    ; storage for Kanji 1st byte (Keyboard)
  426. kanjis2        db    0
  427. kanjir1        db    0    ; storage for Shift-JIS kanji code
  428. kanjir2        db    0
  429. kanjio1        db    0    ; storage for DEC Kanji code
  430. kanjio2        db    0
  431.  
  432. mdstreg    db    ?        ; modem status register
  433.  
  434. machnam db      'NEC PC-9801(KEK v2.00/Beta(01))$'
  435. erms20  db      cr,lf,'?Warning: System has no disk drives$'
  436. erms40  db      cr,lf,'?Warning: Unrecognized baud rate$'
  437. erms41  db      cr,lf,'?Warning: Cannot open com port$'
  438. erms50  db      cr,lf,'Error reading from device$'
  439. hnd1    db      cr,lf,'Enter a file handle.  Check your DOS manual if you are '
  440.         db      cr,lf,'not certain what value to supply (generally 3).$'
  441. hnd2    db      cr,lf,'Handle: $'
  442. hnderr  db      cr,lf,'Warning: Handle not known.'
  443. deverr  db      cr,lf,'Any routine using the communications port will'
  444.         db      cr,lf,'probably not work.$'
  445. nasier1    db    cr,lf,'NASI: Cannot initialize NASI port.$'
  446. nasier2    db    cr,lf,'NASI: Query Name fail.$'
  447. nasier3    db    cr,lf,'NASI: Cannot initialize NASI circuit.$'
  448. pntmsg    db    'Printer not ready, printing request skipped$'
  449. hndhlp  db      cr,lf,'A one to four digit file handle $'
  450. dev1    db      cr,lf,'Device: $'
  451. devhlp  db      cr,lf,'Name for your systems auxiliary port $'
  452. badbd   db      cr,lf,'Unimplemented baud rate$'
  453. noimp   db      cr,lf,'Command not implemented.$'
  454. hngmsg  db      cr,lf,' The phone should have hungup.',cr,lf,'$'
  455. hnghlp  db      cr,lf,' The modem control lines DTR and RTS for the current'
  456.         db      ' port are forced low (off)'
  457.         db      cr,lf,' to hangup the phone. Normally, Kermit leaves them'
  458.         db      ' high (on) when it exits.'
  459.         db      cr,lf,'$'
  460.  
  461. msmsg1  db      cr,lf,'  Modem is not ready: DSR is off$'
  462. msmsg2  db      cr,lf,'  Modem is ready:     DSR is on$'
  463. msmsg3  db      cr,lf,'  no Carrier Detect:  CD  is off$'
  464. msmsg4  db      cr,lf,'  Carrier Detect:     CD  is on$'
  465. msmsg5  db      cr,lf,'  no Clear To Send:   CTS is off$'
  466. msmsg6  db      cr,lf,'  Clear To Send:      CTS is on$'
  467. msmsg7    db    cr,lf,'  Modem is not used by the Network$'
  468. vtrname    db    'TERMINALR'        ; a macro name, must be Upper Case
  469. vtrlen    equ    $-vtrname
  470. vtsname    db    'TERMINALS'        ; a macro name, must be Upper Case
  471. vtslen    equ    $-vtsname
  472. prodname db    'PRODUCT'
  473. vtplen    equ    $-prodname
  474. vtmacname dw    vtrname            ; pointer to selected macro name
  475. vtmaclen db    vtrlen
  476. oldsp    dw    0 
  477.  
  478. tmpbuf        db    80 DUP (?)
  479.  
  480. ;playback_hndl    dw    ?
  481. ;playback_fnam    db    80 dup (?)
  482. ;playback_defnam    db    'KERMIT.LOG',0
  483. ;playback_hlp    db    cr,lf,'Filename to playback$'
  484.  
  485. prthnd  dw      0               ; Port handle.
  486. prtnam  db      80 dup (0)    ; Name of auxiliary device
  487. prtdef    db    'AUX',0        ; default device name
  488. prtdev    db    ?        ; device flag (device=1,file=0)
  489. prthld    db    ?        ; hold port
  490. prthlp    db    cr,lf,'specify device/file name (default AUX)$'
  491.  
  492. shkmsg  db      'Not implemented.'
  493. shklen  equ     $-shkmsg
  494. setktab db      0
  495. setkhlp db      0
  496. crlf    db      cr,lf,'$'
  497. delstr  db      BS,BS,'  ',BS,BS,'$'    ; Delete string
  498. fulscr    db    ESCAPE,'[>1h$'
  499. nrmscr    db    ESCAPE,'[>1l$'
  500. delscr    db    ESCAPE,'[2J$'        ; Delete screen
  501. retscr    db    ESCAPE,'[>1h'
  502.     db    ESCAPE,'[25;1H',ESCAPE,'[0J'
  503.     db    cr,'$'
  504.  
  505. ; If delete code moves cursor then BS over code, BS over bad char, space
  506. ; over both to erase from screen, BS twice to restore cursor position.
  507. clrlin  db      cr,'$'                  ; Clear line (just the cr part).
  508. clreol  db      ESCAPE,'[K$'    ; Clear to end of line.
  509. telflg  db      0               ; non-zero if we're a terminal.
  510. argadr  dw      ?               ; address of arg blk from msster.asm
  511. captrtn dw      ?               ; routine to call for captured output
  512.  
  513. dupflg    db    0        ; 0 = full duplex, 1 = half
  514.  
  515. portin    db    -1        ; Has comm port been initialized, -1=not used
  516. xofsnt    db    0        ; Say if we sent an XOFF
  517. xofrcv    db    0        ; Say if we received an XOFF
  518. parmsk    db    0ffh        ; parity mask, 0ffh for no parity, 07fh with
  519. flowoff    db    0        ; flow-off char, Xoff or null (if no flow)
  520. flowon    db    0        ; flow-on char, Xon or null
  521. flowcnt    db    0        ; holds flowc (!= 0 using any flow control)
  522.  
  523. temp    dw      0
  524. temp1   dw      ?               ; Temporary storage.
  525. temp2   dw      ?               ; Temporary storage.
  526.  
  527. ; Entries for choosing communications port
  528. comptab db    12        ; Number of options
  529.         mkeyw   '1',1
  530.         mkeyw   '2',2
  531.     mkeyw    '3',3
  532.         mkeyw   'COM1',1
  533.         mkeyw   'COM2',2
  534.         mkeyw    'COM3',3
  535.     mkeyw    'Device','D'
  536.     mkeyw    'File','D'
  537.     mkeyw    'NASI(Novell)','W'
  538.     mkeyw    'SIAM','S'    ; SIAM driver
  539.     mkeyw    'TCP/IP','t'    ; Telnet, internal
  540.         mkeyw   'UB-NETCI','N'
  541.         mkeyw    '   ',0        ; port is not present, for Status
  542.  
  543. vt_ourarg  termarg <>
  544. modem    mdminfo    <mndata,mnst1a,mncmda,mnmska,mnrdsa>
  545. timer    tmrinfo    <tmdata,tmcmda,tmsela>
  546.  
  547. ;++ The following structure must be initialized as in MSSKER
  548. ;
  549. port1    prtinfo    <0FFFFh,0,defpar,1,0,defhand,floxon,0>
  550. port2    prtinfo    <0FFFFh,0,defpar,1,0,defhand,floxon,0>
  551. portd    prtinfo    <0FFFFh,0,defpar,1,0,defhand,floxon,0>
  552. portf    prtinfo    <0FFFFh,0,defpar,1,0,defhand,floxon,0>
  553. portn    prtinfo    <0FFFFh,0,defpar,1,0,defhand,floxon,0>
  554. ports    prtinfo    <0FFFFh,0,defpar,1,0,defhand,floxon,0>
  555.  
  556.  
  557. setchtab    db    1
  558.     mkeyw    'CP932 Shift-JIS',932
  559.  
  560. ; this table is indexed by the baud rate definitions given in
  561. ; pcdefs.  Unsupported baud rates should contain FF.
  562.  
  563. bdtab    db    17
  564.     mkeyw    '45.5',0
  565.     mkeyw    '50',1
  566.     mkeyw    '75',2
  567.     mkeyw    '110',3
  568.     mkeyw    '134.5',4
  569.     mkeyw    '150',5
  570.     mkeyw    '300',6
  571.     mkeyw    '600',7
  572.     mkeyw    '1200',8
  573.     mkeyw    '1800',9
  574.     mkeyw    '2000',10
  575.     mkeyw    '2400',11
  576.     mkeyw    '4800',12
  577.     mkeyw    '9600',13
  578.     mkeyw    '19200',14
  579.     mkeyw    '38400',15
  580.     mkeyw    'Unknown',-1
  581.  
  582. ; Baudrate clock count table for 5/10 MHz CPU
  583.     even
  584. bddat5    label    word            ; AHS 29-MAY-86
  585.     dw    00D30H        ; 45.5 baud
  586.     dw    00C00H        ; 50 baud
  587.     dw    00800H        ; 75 baud
  588.     dw    00574H        ; 110 baud
  589.     dw    00476H        ; 134.5 baud
  590.     dw    00400H        ; 150 baud
  591.     dw    00200H        ; 300 baud
  592.     dw    00100H        ; 600 baud
  593.     dw    00080H        ; 1200 baud
  594.     dw    00055H        ; 1800 baud
  595.     dw    0004DH        ; 2000 baud
  596.     dw    00040H        ; 2400 baud
  597.     dw    00020H        ; 4800 baud
  598.     dw    00010H        ; 9600 baud
  599.     dw    00008H        ; 19200 baud
  600.     dw    00004H        ; 38400 baud
  601.     dw    0FFFFH
  602.     dw    0FFFFH
  603.     dw    0FFFFH
  604.  
  605. ; Baud rate clock count table for 8 MHz CPU
  606.  
  607. bddat8    label    word            ; AHS 29-MAY-86
  608.     dw    0FFFFH        ; 45.5 baud
  609.     dw    0FFFFH        ; 50 baud
  610.     dw    00680H        ; 75 baud
  611.     dw    0FFFFH        ; 110 baud
  612.     dw    0FFFFH        ; 134.5 baud
  613.     dw    00340H        ; 150 baud
  614.     dw    001A0H        ; 300 baud
  615.     dw    000D0H        ; 600 baud
  616.     dw    00068H        ; 1200 baud
  617.     dw    0004EH        ; 1800 baud
  618.     dw    0FFFFH        ; 2000 baud
  619.     dw    00034H        ; 2400 baud
  620.     dw    0001AH        ; 4800 baud
  621.     dw    0000DH        ; 9600 baud
  622.     dw    00006H        ; 19200 baud (not acculate - may not work)
  623.     dw    00003H        ; 38400 baud (not acculate - may not work)
  624.     dw    0FFFFH
  625.     dw    0FFFFH
  626.     dw    0FFFFH
  627.  
  628. baudlen equ     ($-bddat8)/2     ; number of entries above
  629.  
  630. ; SIAM Interface Section (by Kenji Rikitake -- 30/Dec/1991)
  631.  
  632. siam_seg    dw    0    ; SIAM routine address table
  633. processID    dw    0    ; PSP segment value (for openSI)
  634.  
  635. siammsg_nosiam    db      cr,lf,'Error: SIAM does not exist$'
  636. siammsg_in_use    db      cr,lf,'Error: SIAM is used by another application$'
  637.  
  638. ; Baud rate table for
  639. ; internal baud table index -> siam_getBaud/setBaud value
  640.  
  641.     even
  642. siam_bauddat    label    word        ; KR 29-DEC-1991
  643.     dw    0FFFFH        ; 45.5 baud
  644.     dw    0FFFFH        ; 50 baud
  645.     dw    1        ; 75 baud
  646.     dw    0FFFFH        ; 110 baud
  647.     dw    0FFFFH        ; 134.5 baud
  648.     dw    2        ; 150 baud
  649.     dw    3        ; 300 baud
  650.     dw    4        ; 600 baud
  651.     dw    5        ; 1200 baud
  652.     dw    0FFFFH        ; 1800 baud
  653.     dw    0FFFFH        ; 2000 baud
  654.     dw    6        ; 2400 baud
  655.     dw    7        ; 4800 baud
  656.     dw    8        ; 9600 baud
  657.     dw    9        ; 19200 baud (not acculate - may not work)
  658.     dw    10        ; 38400 baud (not acculate - may not work)
  659.     dw    0FFFFH
  660.     dw    0FFFFH
  661.     dw    0FFFFH
  662.  
  663. siam_bauddat_len    equ     ($-siam_bauddat)/2     ; number of entries above
  664. ; Baud rate table for
  665. ; siam_getBaud/setBaud value -> internal baud table index
  666.  
  667. siam_datbaud    label    word
  668.     dw    0FFFFH        ; unknown
  669.     dw    2        ; 75bps
  670.     dw    5        ; 150bps
  671.     dw    6        ; 300bps
  672.     dw    7        ; 600bps
  673.     dw    8        ; 1200bps
  674.     dw    11        ; 2400bps
  675.     dw    12        ; 4800bps
  676.     dw    13        ; 9600bps
  677.     dw    14        ; 19200bps
  678.     dw    15        ; 38400bps
  679.  
  680. siam_datbaud_len    equ     ($-siam_datbaud)/2     ; number of entries above
  681. SIAM_B9600    equ    8
  682. ; End of SIAM section
  683.  
  684. axsave        dw    ?
  685. portinia    dw    0
  686.  
  687. dmphand        dw    ?        ; file handle for dump file
  688.  
  689. oldsera_ofs    dw    ?
  690. oldsera_sgm    dw    ?
  691. oldmska        db    ?
  692. oldmsdat    db    ?
  693.  
  694. ; variables for serial interrupt handler
  695.     even
  696. source    db    bufsiz DUP (?)    ; Buffer for data from port.
  697.     db    2 DUP (?)    ; guard for source.
  698. srcpnt    dw    0        ; Pointer in buffer (DI).
  699. count    dw    0        ; Number of chars in int buffer.
  700. rcvpnt    dw    0        ; Save SI register here.
  701. mdmhand    db    0        ; modem status register, current
  702.  
  703. ; buffer for network
  704.  
  705. xmtbuf    db    NETBUFLEN DUP (0)    ; Buffer for Network xfer.
  706.     db    2 DUP (0)        ; guard
  707. xmtpnt    dw    0
  708. xmtcnt    dw    0
  709. ;
  710.     even
  711.     dw    80 DUP (?)    ; local stack for interrupt processing
  712. mnstk    dw    ?
  713. mnsp    dw    ?        ; remote stack info
  714. mnsseg    dw    ?
  715.  
  716. baud_set    db    0
  717.  
  718. onmsg        db    'off'
  719.         db    'on '
  720. applmsg        db    'normal     '
  721.         db    'application'
  722. colmsg        db    'black  '
  723.         db    'blue   '
  724.         db    'red    '
  725.         db    'magenta'
  726.         db    'green  '
  727.         db    'cyan   '
  728.         db    'yellow '
  729.         db    'white  '
  730. knjmsg        db    'none     '
  731.         db    'DEC-code '
  732.         db    'Shift-JIS'
  733.         db    'JIS-7    '
  734. keyinmsg    db    'BIOS  '
  735.         db    'CON   '
  736.         db    'DOS   '
  737. insrepmsg    db    'Replace'
  738.         db    'Insert '
  739. originmsg    db    'Absolute'
  740.         db    'Relative'
  741. lfnlmsg        db    'Line-feed'
  742.         db    'New-line '
  743. clkmsg        db    '5/10 MHz'
  744.         db    '8 MHz   '
  745. dspmsg        db    'Digital '
  746.         db    'Analogue'
  747.  
  748. vstmsg        db    '<Terminal status>  clock '
  749. vstmsg_clk    db    '        '
  750.         db    '  Diaplay: '
  751. vstmsg_dsp    db    '        '
  752.         db    cr,lf,'  Keyclick: '
  753. vstmsg_key    db    '    '
  754.         db    '  Keyinput: '
  755. vstmsg_keyin    db    '      '
  756.         db    '  Cursorkey: '
  757. vstmsg_curmod    db    '           '
  758.         db    '  Keypad: '
  759. vstmsg_kpdmod    db    '           '
  760.         db    cr,lf,'  Color:  Fore:'
  761. vstmsg_colf    db    '        '
  762.                 db      '  Back:'
  763. vstmsg_colb     db      '        '
  764.         db    '  Highlight:'
  765. vstmsg_colh    db    '        '
  766.                 db      '  Modeline:'
  767. vstmsg_colm     db      '        '
  768.         db    cr,lf,'  Kanji-send: '
  769. vstmsg_sknj    db    '          '
  770.         db    '  Kanji-receive: '
  771. vstmsg_rknj    db    '          '
  772.         db    cr,lf,'  Ins/Rep: '
  773. vstmsg_insrep    db    '       '
  774.         db    '  LF/NL: '
  775. vstmsg_lfnl    db    '         '
  776.         db    '  Orgin: '
  777. vstmsg_origin    db    '        '
  778.         db    '  Wrap: '
  779. vstmsg_autow    db    '    '
  780.         db    cr,lf,'  Cooked-log: '
  781. vstmsg_logcook    db    '    '
  782.         db    '$'
  783.  
  784. tcpnet    equ    0100h        ; TCP/IP
  785.  
  786. nettype        dw    0    ; kind of local area net (vendor bit field)
  787. nsbrk        dw    0    ; net can send Break
  788.  
  789. naskpmt    db    cr,lf,' A network session is active.',cr,lf
  790.     db    ' Enter RESUME to resume it or NEW to start a new session:',0
  791. nettab    db    2
  792.     mkeyw    'New',0
  793.     mkeyw    'Resume',1
  794.  
  795. tcpadrst db    cr,lf,'  tcp/ip address: $'    ; TCP/IP status msgs
  796. tcpsubst db    cr,lf,'  tcp/ip subnetmask: $'
  797. tcpdomst db    cr,lf,'  tcp/ip domain: $'
  798. tcpgatest db    cr,lf,'  tcp/ip gateway: $'
  799. tcppnsst db    cr,lf,'  tcp/ip primary-nameserver: $'
  800. tcpsnsst db    cr,lf,'  tcp/ip secondary-nameserver: $'
  801. tcpbcstst db    cr,lf,'  tcp/ip broadcast: $'
  802. tcphostst db    cr,lf,'  tcp/ip host: $'
  803. tcpportst db    cr,lf,'  tcp/ip port: $'
  804. tcppdintst db    ',  Packet-Driver-interrupt: \x$'
  805. tcppdnul db    ' (search for it)$'
  806. tcpttyst db    cr,lf,'  tcp/ip telnet-term-type: $'
  807. tcpttynul db    '(report real terminal type)',0    ; ASCIIZ
  808. tcphlp    db    cr,lf,' Host Internet name  machine.domain  or'
  809.     db    ' Internet address  nnn.nnn.nnn.nnn'
  810.     db    cr,lf,'  or  *  to become a Telnet server.'
  811.     db    cr,lf,' Optional TCP port number may follow the host name.$'
  812. tcpporthlp db    cr,lf,' TCP port on host, 23 is Telnet.$'
  813. badport    db    cr,lf,'?Port 25 is forbidden, sorry. Use 23 for Telnet.$'
  814. lastchar db    0            ; previous char sent, for NVT
  815.  
  816. tcponptr    dw    ktcpstart,seg _TEXT    ; far pointers to TCP start
  817. tcpoffptr    dw    ktcpstop,seg _TEXT    ; and stop procedures
  818. data    ends
  819.  
  820. code2    segment
  821.     extrn    tekstat:far
  822. code2    ends
  823.  
  824. code    segment
  825.         extrn   comnd:near, dopar:near, atoi:near, prompt:near
  826.         extrn    isfile:near, strlen:near, strcpy:near
  827.         extrn    prtasz:near
  828.         extrn   sleep:near, msuinit:near, keybd:near
  829.         extrn    kbdlini:near, kbdlend:near
  830.         extrn    ans_keystr:near
  831.     extrn    pntchr:near, pntflsh:near
  832.     extrn    decout:near, valout:near
  833.     extrn    katoi:near
  834.  
  835.     extrn    vt100:near, vt100_ini:near, vt100_reset:near
  836.     extrn    vt100_save:near, vt100_restore:near, vt100_modlin:near
  837.     extrn    vt100_dump:near, vt100_color:near
  838.     extrn    vt100_rupn:near, vt100_rdnn:near
  839.     extrn    vt100_prnl:near, vt100_prns:near
  840.  
  841.      extrn    prn_chk:near        ; in MSYP98.ASM
  842.      extrn    set_modlin:near        ; in MSYP98.ASM
  843.      extrn    gdisp_on:near        ; in MSGP98.ASM
  844.      extrn    set_gcolor:near        ; in MSGP98.ASM
  845.  
  846.      extrn    text_scrn:near        ; in MSZP98.ASM
  847.      extrn    pc98_bell:near        ; in MSZP98.ASM
  848.      extrn    pc98_tstrt:near        ; in MSZP98.ASM
  849.      extrn    pc98_tend:near        ; in MSZP98.ASM
  850.      extrn    pcwait:near        ; in MSZP98.ASM
  851.      extrn    pcwtst:near        ; in MSZP98.ASM
  852.  
  853.     extrn    tek4014:near, tek4014_ini:near, tek4014_reset:near
  854.     extrn    tek4014_save:near, tek4014_restore:near, tek4014_modlin:near
  855.     extrn    tek4014_color:near
  856.     extrn    sixel_rollup:near, sixel_rolldown:near
  857.  
  858.     extrn    sense_sftkey:near
  859.     extrn    set_keydef:near, reset_keydef:near
  860.     extrn    is_kanji1:near, s2jis:near, jis2s:near
  861.  
  862.         assume  cs:code,ds:data,es:nothing
  863.  
  864. ;-----------------
  865. ; Utility Package
  866. ;-----------------
  867. fprtasz    proc    far
  868.     call    prtasz
  869.     ret
  870. fprtasz    endp
  871. fdecout    proc    far
  872.     call    decout
  873.     ret
  874. fdecout    endp
  875. fvalout    proc    far
  876.     call    valout
  877.     ret
  878. fvalout    endp
  879.  
  880.  
  881. NOUT    PROC    NEAR
  882. ; Copy numeric value from AX to ASCII buffer indicated by DI.
  883. ; DI is updated.
  884.  
  885.     mov    dx,0
  886.     mov    bx,10
  887.     div    bx
  888.     push    dx        ; save remainder digit
  889.     or    ax,ax        ; anything left?
  890.     jz    nout1        ; no, start output phase
  891.     call    nout
  892. nout1:    pop    ax        ; retrieve a digit
  893.     add    al,'0'        ; make it ASCII
  894.     stosb            ; put it in buffer
  895.     ret
  896. NOUT    ENDP
  897.  
  898. ENT_VT    PROC    NEAR
  899. ;@@    call    vt100_restore
  900.     and    vt100_gflag,7Fh        ; mask text screen control
  901.     call    set_gcolor
  902.     call    set_modlin
  903.     call    vt100_modlin
  904.     mov    kanji_rmode,0        ; clear all kanji pending flags
  905.     mov    kanji_smode,0
  906.     ret
  907. ENT_VT    ENDP
  908.  
  909. ENT_TK    PROC    NEAR
  910. ;@@    call    cmblnk
  911. ;@@    call    tek4014_restore
  912.     and    vt100_gflag,7Fh
  913.     cmp    vt100_gflag,4        ; TeK screen ?
  914.     jge    ent_tk_1        ; ge = yes
  915.     mov    vt100_gflag,4
  916. ent_tk_1:
  917.     or    vt100_gflag,80h        ; set text screen cotrol bit
  918.     call    set_gcolor
  919.     call    set_modlin
  920.     call    tek4014_modlin
  921.     mov    kanji_rmode,0
  922.     mov    kanji_smode,0
  923.     ret
  924. ENT_TK    ENDP
  925.  
  926. SET_CUR_COLOR    PROC    NEAR
  927. ;
  928. ; Set the current color.  The color table is given in [si] - [si+3]
  929. ;
  930.     push    ax
  931.     push    di
  932.     mov    di,offset scn_color    ; copy color to current buffer
  933.     mov    ax,[si]            ; fore & back
  934.     mov    [di],ax
  935.     mov    ax,[si+2]        ; highlight & modeline
  936.     mov    [di+2],ax
  937.     pop    di
  938.     pop    ax
  939.     ret
  940. SET_CUR_COLOR    ENDP
  941.  
  942. ;---------------------------------------------------------------------------
  943. ; Clear the input buffer. This throws away all the characters in the
  944. ; serial interrupt buffer.  This is particularly important when
  945. ; talking to servers, since NAKs can accumulate in the buffer.
  946.  
  947. CLRBUF  PROC    NEAR
  948.     cli
  949.     mov    srcpnt,offset source    ; receive circular buffer
  950.     mov    count,0
  951.     sti
  952.     cmp    repflg,0        ; in replay mode ?
  953.     jne    clrbf2            ; ne=yes. do not read any character.
  954. clrbf1:
  955.     call    prtchr            ; empty any intermediate buffers
  956.     jnc    clrbf1            ; got a char, clear again
  957. clrbf2:
  958.     cli
  959.     push    ax
  960.     mov    ax,offset source    ; reset pointers
  961.     mov    rcvpnt,ax
  962.     mov    srcpnt,ax
  963.     mov    count,0
  964.     pop    ax
  965.     sti
  966.         ret
  967. CLRBUF  ENDP
  968.  
  969. ; Clear to the end of the current line.  Returns normally.
  970.  
  971. CLEARL  PROC    NEAR
  972.         push ax
  973.         push dx
  974.         mov ah,prstr
  975.         mov dx,offset clreol
  976.         int dos
  977.         pop dx
  978.         pop ax
  979.         ret
  980. CLEARL  ENDP
  981. code    ends
  982.  
  983. code1    segment
  984.     assume    cs:code1
  985.  
  986. ftcpstats proc    far            ; TCP/IP status display
  987.     mov    ah,prstr
  988.     mov    dx,offset tcpadrst
  989.     int    dos
  990.     mov    dx,tcpdata[0]        ; offset of tcpaddress string
  991.     call    fprtasz
  992.     mov    dx,offset tcpsubst
  993.     int    dos
  994.     mov    dx,tcpdata[2]        ; offset of tcp subnetmask string
  995.     call    fprtasz
  996.     mov    dx,offset tcpdomst
  997.     int    dos
  998.     mov    dx,tcpdata[4]        ; offset of tcp domain string
  999.     call    fprtasz
  1000.     mov    dx,offset tcpgatest
  1001.     int    dos
  1002.     mov    dx,tcpdata[6]        ; offset of tcp gateway string
  1003.     call    fprtasz
  1004.     mov    dx,offset tcppnsst
  1005.     int    dos
  1006.     mov    dx,tcpdata[8]        ; offset of tcp primary nameserver 
  1007.     call    fprtasz
  1008.     mov    dx,offset tcpsnsst
  1009.     int    dos
  1010.     mov    dx,tcpdata[10]        ; offset of tcp secondary nameserver
  1011.     call    fprtasz
  1012.     mov    dx,offset tcpbcstst
  1013.     int    dos
  1014.     mov    dx,tcpdata[14]        ; offset of tcp broadcast address
  1015.     call    fprtasz
  1016.     mov    dx,offset tcpportst
  1017.     int    dos
  1018.     push    ax
  1019.     push    bx
  1020.     push    cx
  1021.     mov    bx,tcpdata[16]        ; offset of tcp port
  1022.     mov    ax,[bx]
  1023.     call    fdecout
  1024.     mov    ah,prstr
  1025.     mov    dx,offset tcppdintst
  1026.     int    dos
  1027.     mov    bx,tcpdata[18]        ; offset of Packet Driver interrupt
  1028.     mov    ax,[bx]
  1029.     mov    cx,16
  1030.     push    ax
  1031.     call    fvalout            ; show value as hex
  1032.     pop    ax
  1033.     or    ax,ax            ; null?
  1034.     jnz    ftcpst1            ; nz = no, just show value
  1035.     mov    ah,prstr
  1036.     mov    dx,offset tcppdnul    ; show search msg
  1037.     int    dos
  1038. ftcpst1:pop    cx
  1039.     pop    bx
  1040.     pop    ax
  1041.     mov    dx,offset tcpttyst
  1042.     int    dos
  1043.     mov    dx,tcpdata[20]        ; offset of tcp term-type override
  1044.     push    bx
  1045.     mov    bx,dx
  1046.     cmp    byte ptr [bx],0
  1047.     jne    ftcpst2
  1048.     mov    dx,offset tcpttynul    ; alternate msg
  1049. ftcpst2:pop    bx
  1050.     call    fprtasz
  1051.     mov    dx,offset tcphostst
  1052.     int    dos
  1053.     mov    dx,tcpdata[12]        ; offset of tcp host ident string
  1054.     call    fprtasz
  1055.     ret
  1056. ftcpstats endp
  1057. code1    ends
  1058.  
  1059. code    segment
  1060.     assume    cs:code
  1061.  
  1062. ; SHOW MODEM, displays current status of lines DSR, CD, and CTS.
  1063. ; Uses byte mdmhand, the modem line status register.
  1064. shomodem    proc    near
  1065.     mov     ah,cmeol            ; get a confirm
  1066.         call    comnd
  1067.         jnc    shomd1a            ; nc = success
  1068.         ret                           ; no confirm
  1069. shomd1a:mov    dx,offset msmsg7    ; no modem status for network
  1070.     call    getmodem        ; get modem status
  1071.     mov    mdmhand,al
  1072.     mov    ah,prstr
  1073.     mov    dx,offset msmsg1    ; modem not ready msg
  1074.     test    mdmhand,moddsr        ; is DSR asserted?
  1075.     jz    shomd1            ; z = no
  1076.     mov    dx,offset msmsg2    ; say asserted
  1077. shomd1:    int    dos
  1078.     mov    dx,offset msmsg3    ; CD not asserted msg
  1079.     test    mdmhand,modcd        ; CD asserted?
  1080.     jz    shomd2            ; z = no
  1081.     mov    dx,offset msmsg4    ; say asserted
  1082. shomd2:    int    dos
  1083.     mov    dx,offset msmsg5    ; CTS asserted msg
  1084.     test    mdmhand,modcts        ; CTS asserted?
  1085.     jz    shomd3            ; z = no
  1086.     mov    dx,offset msmsg6    ; say asserted
  1087. shomd3:    mov    ah,prstr
  1088.     int    dos
  1089.  
  1090. shomd3c:call    ftcpstats        ; call TCP/IP FAR worker
  1091.     clc
  1092.     ret
  1093. shomodem    endp
  1094.  
  1095. ;
  1096. ; returns modem status in AL.
  1097. ;
  1098. getmodem    proc    near
  1099.     push    bx
  1100.     push    dx
  1101.     mov    dx,modem.mdstat    ; read status of port
  1102.     in    al,dx
  1103.     and    al,80h        ; set only DR bit
  1104.     mov    bl,al        ; save it
  1105.     mov    dx,modem.mdsig    ; read signal
  1106.     in    al,dx
  1107.     and    al,60h        ; set CS and CD only
  1108.     or    bl,al
  1109. ;
  1110.     mov    al,0
  1111.     test    bl,80h        ; is DSR asserted?
  1112.     jz    getmd1        ; z = no
  1113.     or    al,moddsr    ; set DSR bit
  1114. getmd1:
  1115.     test    bl,20h        ; CD asserted?
  1116.     jnz    getmd2        ; nz = no
  1117.     or    al,modcd    ; set CD bit
  1118. getmd2:
  1119.     test    bl,40h        ; CTS asserted?
  1120.     jnz    getmd3        ; nz = no
  1121.     or    al,modcts    ; set CTS bit
  1122. getmd3:
  1123.     pop    dx
  1124.     pop    bx
  1125.     ret
  1126. getmodem    endp
  1127.  
  1128. ; Put the char in AH to the serial port, assumimg the port is active.
  1129. ; Returns carry clear if success, else carry set.
  1130.  
  1131. OUTCHR  PROC    NEAR
  1132.     cmp    repflg,0        ; in REPLAY mode?
  1133.     je    outch0            ; e=no
  1134.     cmp    ah,03h            ; CTRL-C ?
  1135.     je    outch0_1        ; e=yes
  1136.     xor    replay_hold,1        ; toggle replay_hold flag
  1137.     clc
  1138.     jmp    outch0_2
  1139. outch0_1:
  1140.     stc
  1141. outch0_2:
  1142.     ret
  1143. outch0:
  1144.     test    flowcnt,1        ; doing XON/XOFF flow control?
  1145.     jz    outch2            ; z = no, just continue
  1146.     cmp    ah,flowoff        ; sending xoff?
  1147.     jne    outch1            ; ne = no
  1148.     mov    xofsnt,usron        ; indicate user level xoff being sent
  1149.     jmp    short outch1b
  1150. outch1:    and    xofsnt,not usron    ; cancel user level xoff
  1151.     cmp    ah,flowon        ; user sending xon?
  1152.     jne    outch1b            ; ne = no
  1153.     mov    xofsnt,off    ; say an xon has been sent (cancels xoff)
  1154. outch1b:cmp    xofrcv,off        ; Are we being held (xoff received)?
  1155.     je    outch2            ; e = no - it's OK to go on
  1156.     push    cx            ; save reg
  1157.     mov    ch,15            ; 15 sec timeout interval
  1158.     xor    cl,cl            ;  convert to 4 millsec increments
  1159.  
  1160. outch1a:cmp    xofrcv,off        ; are we being held (xoff received)?
  1161.     je    outch1c            ; e = no - it's OK to go on
  1162.     push    ax
  1163.     mov    ax,4            ; 4 millisec wait loop
  1164.     call    pcwait
  1165.     pop    ax
  1166.     loop    outch1a            ; and try it again
  1167.     mov    xofrcv,off        ; timed out, force it off
  1168. outch1c:pop    cx            ; end of XON/XOFF control section
  1169.  
  1170. OUTCH2:    mov    al,ah            ; Parity routine works on AL.
  1171.     call    dopar            ; Set parity appropriately
  1172.     mov    ah,al            ; Don't overwrite character with status
  1173. outch3eb:cmp    flags.comflg,'S'    ; SIAM? (speed is critical)
  1174.     jne    outch3            ; ne = no.
  1175.     jmp    outchs
  1176. outch3:    cmp    flags.comflg,'N'    ; Network port ?
  1177.     jne    outch3e            ; ne = no.
  1178.     jmp    outchn            ; yes
  1179. outch3e:cmp    flags.comflg,'t'    ; TCP/IP Telnet?
  1180.     jne    outch3ea
  1181.     jmp    outchn
  1182. outch3ea:cmp    flags.comflg,'W'    ; Novell NASI ?
  1183.     jne    outch3ec
  1184.     jmp    outchn
  1185. outch3ec:cmp    flags.comflg,'D'    ; DOS device ?
  1186.     jne    outch3a            ; ne = no.
  1187.     jmp    outchd
  1188.  
  1189. outch3a:push    cx
  1190.     push    dx            ; Save register.
  1191.     cmp    dupflg,0        ; full duplex?
  1192.     jne    outch3b            ; ne = no, half
  1193.     test    flowcnt,2        ; using RTS tp cpmtrp; omcoming chars ?
  1194.     jz    outch3d            ; z = no
  1195.     mov    cx,8000            ; ~10 seconds worth of wating on CTS
  1196.     jmp    short outch3c        ; do CTS test/waiting
  1197.  
  1198. outch3b:mov    dx,modem.mdcom        ; modem command reg.
  1199.     mov    al,ccmd            ; assert RTS for for hardware transmit
  1200.     out    dx,al
  1201.     jmp    $+2
  1202.     jmp    $+2
  1203.     mov    dx,modem.mdstat        ; modem status reg.
  1204.     in    al,dx
  1205.     test    al,80h            ; ignore CTS if DSR is not asserted
  1206.     jz    outch3d            ; z = DSR not asserted
  1207.     mov    cx,8000            ; ~10 seconds worth of wating on CTS
  1208.                     ; wait on CTS (ah has output char)
  1209. outch3c:mov    dx,modem.mdsig        ; modem signal reg.
  1210.     in    al,dx            ; wait on CTS (ah has output char)
  1211.     test    al,40h            ; is CTS asseerted?
  1212.     jz    outch3d            ; z = yes
  1213.     push    ax            ; preserve char in ah
  1214.     mov    ax,1            ; wait one millisec
  1215.     call    pcwait
  1216.     pop    ax
  1217.     loop    outch3c
  1218.                     ; timeout, make non-fatal
  1219. outch3d:
  1220. outch3f:xor    cx,cx
  1221.     mov    dx,modem.mdstat        ; get port status
  1222. outch3g:in    al,dx
  1223.     test    al,txrdy        ; Transmitter ready ?
  1224.     jnz    outch4            ; nz = yes
  1225.     jmp    $+2            ; use time, prevent overdriving UART
  1226.     jmp    $+2
  1227.     loop    outch3g
  1228.     jmp    short outch5        ; Timeout
  1229. outch4:    mov    al,ah            ; Now send it out
  1230.     mov    dx,modem.mddat
  1231.     out    dx,al
  1232.     cmp    dupflg,0        ; full duplex?
  1233.     je    outch4a            ; e = yes
  1234.     cmp    al,trans.seol        ; End of line char?
  1235.     jne    outch4a            ; ne = no
  1236.     xor    cx,cx
  1237. outch4b:
  1238. outch4a:pop    dx            ; exit success
  1239.     pop    cx
  1240.     clc
  1241.     ret
  1242. outch5:    pop     dx            ; exit failure
  1243.         pop     cx
  1244.     stc
  1245.     ret
  1246. ;
  1247. outchn:
  1248.     push    bx
  1249.     mov    bx,offset xmtbuf    ; set xfer address
  1250.     add    bx,xmtcnt        ; count of chars in buffer
  1251.     mov    [bx],ah            ; put char in buffer
  1252.     pop    bx
  1253.     inc    xmtcnt            ; count of items in this buffer
  1254.     cmp    xmtcnt,NETBUFLEN    ; is buffer full now?
  1255.     jae    outchn1            ; ae = buffer is full, send it now.
  1256.     cmp    ah,trans.seol        ; end of packet?
  1257.     je    outchn1            ; e = yes, send buffer.
  1258.     cmp    ah,flowon        ; flow control?
  1259.     je    outchn1            ; e = yes, always expedite
  1260.     cmp    ah,flowoff        ; ditto for flow off
  1261.     je    outchn1
  1262.     cmp    ttyact,0        ; are we in Connect mode?
  1263.     je    outchn2            ; e = no, wait for more before sending
  1264. outchn1:
  1265.     call    send            ; network send routine
  1266.     jc    outchn3            ; c = error
  1267. outchn2:
  1268.     clc                ; good exit
  1269. outchn3:
  1270.     ret                ; bad  exit
  1271.  
  1272. outchd:
  1273.         cmp     prthnd,0        ; Got a handle yet?
  1274.         jne     outchd3         ; Yup just go on
  1275.         call    opnprt          ; Else 'open' the port
  1276. outchd3:
  1277.     cmp    prtdev,1    ; device ?
  1278.     je    outchd5        ; e = yes.
  1279.     xor    prthld,1    ; flip-flop
  1280.     jmp    outch5
  1281. outchd5:
  1282.     push    bx
  1283.     push    cx
  1284.     push    dx
  1285.     mov    temp,ax        ; store the character in the buffer
  1286.         mov     bx,prthnd       ; port handle
  1287.         mov     cx,1            ; one byte to write
  1288.         mov     dx,offset temp  ; place where data will be found
  1289.         mov     ah,write2       ; dos 2 write to file/device
  1290.         int     dos
  1291.         pop    dx
  1292.         pop    cx
  1293.         pop     bx              ; end of revised routine
  1294.         ret
  1295.  
  1296. ; SIAM section by Kenji Rikitake (30/Dec/1991)
  1297. outchs:
  1298.     push    dx
  1299.     mov    al,ah        ; set char to AX
  1300.     xor    ah,ah        ; clear AH
  1301.     siam_PUTSI    ax    ; send it out
  1302.     shl    ah,1        ; if AH == 0FFH then failed
  1303.     pop    dx        ; else AH == 0 and succeeded
  1304.     ret
  1305.  
  1306. OUTCHR  ENDP
  1307.  
  1308. SEND    PROC    NEAR
  1309.     push    ax
  1310.     push    bx
  1311.     push    cx
  1312.     push    es
  1313. ;
  1314.     push    ds
  1315.     pop    es            ; ES = DS
  1316.     mov    bx,offset xmtbuf    ; xfer start address
  1317.     mov    ah,net_write        ; set function
  1318.     mov    al,net_port        ; set port
  1319. ;
  1320. send0:
  1321.     mov    cx,xmtcnt        ; packet length
  1322.     jcxz    send1
  1323.     test    nettype,tcpnet        ; TCP/IP Telnet?
  1324.     jz    send0a            ; z = no
  1325.     call    ktcpcom
  1326.     jmp    short send0b
  1327. send0a:    int    NETCI_INT        ; send packet
  1328. send0b:    cmp    cx,xmtcnt        ; all done ?
  1329.     jae    send1            ; e = yes.
  1330.     pop    ax
  1331.     mov    bx,offset xmtbuf
  1332.     add    bx,cx            ; update xfer address
  1333.     sub    xmtcnt,cx
  1334.     jmp    send0
  1335. ;
  1336. send1:
  1337.     mov    xmtcnt,0
  1338.     pop    es
  1339.     pop    cx
  1340.     pop    bx
  1341.     pop    ax
  1342.     clc
  1343.     ret
  1344.  
  1345. SEND    ENDP
  1346.  
  1347. ; This routine blanks the screen.  Returns normally.
  1348.  
  1349. CMBLNK  PROC    NEAR
  1350.         push    ax                 ; save some registers
  1351.         push    dx
  1352.         mov    ah,prstr
  1353.         mov    dx,offset delscr    ; delete screen.
  1354.     int    dos
  1355.         pop    dx
  1356.         pop    ax
  1357.         ret
  1358. CMBLNK  ENDP
  1359.  
  1360. ; Homes the cursor.  Returns normally.
  1361.  
  1362. LOCATE  PROC    NEAR
  1363.         mov    dx,0                ; Go to top left corner of screen.
  1364.         jmp    poscur
  1365. LOCATE  ENDP
  1366.  
  1367. ; Write a line at the bottom of the screen...
  1368. ; the line is passed in dx, terminated by a $.  Returns normally.
  1369. putmod  proc    near
  1370.         push    dx              ; preserve message
  1371.         mov     dx,1800h        ; now address line 24
  1372.         call    poscur
  1373.         pop     dx              ; get message back
  1374.         mov     ah,prstr
  1375.         int     dos             ; write it out
  1376.         ret                     ; and return
  1377. putmod  endp
  1378.  
  1379. ; clear the mode line written by putmod.  Returns normally.
  1380. clrmod  proc    near
  1381.         mov     dx,1800h
  1382.         call    poscur          ; Go to bottom row.
  1383.         call    clearl          ; Clear to end of line.
  1384.         ret
  1385. clrmod  endp
  1386.  
  1387. ; Put a help message on the screen.
  1388. ; Pass the message in ax, terminated by a null.  Returns normally.
  1389. puthlp  proc    near
  1390.         push    dx              ; save regs
  1391.         push    si
  1392.         push    ax              ; preserve this
  1393. ;@@    call    cmblnk
  1394. ;@@    call    locate
  1395.     mov    ah,prstr        ;@@
  1396.     mov    dx,offset retscr    ;@@
  1397.     int    dos            ;@@
  1398.         mov     ah,prstr
  1399.         mov     dx,offset crlf
  1400.         int     dos
  1401.         pop     si              ; point to string again
  1402.         cld
  1403. puthl3: lodsb                   ; get a byte
  1404.         cmp     al,0            ; end of string?
  1405.         je      puthl4          ; yes, stop
  1406.         mov     dl,al
  1407.         mov     ah,dconio
  1408.         int     dos             ; else write to screen
  1409.         jmp     puthl3          ; and keep going
  1410. puthl4: mov     ah,prstr
  1411.         mov     dx,offset crlf
  1412.         int     dos
  1413.         pop     si
  1414.         pop     dx
  1415.         ret
  1416. puthlp  endp
  1417.  
  1418. ; Set the baud rate for the current port, based on the value
  1419. ; in the portinfo structure.  Returns normally.
  1420.  
  1421. BAUDST    PROC    NEAR
  1422.     mov    dx,offset bdtab        ; baud rate table, ascii
  1423.     xor    bx,bx            ; help is the table itself
  1424.     mov    ah,cmkey        ; get keyword
  1425.     call    comnd
  1426.     jc    baudst1            ; c = failure
  1427.     push    bx            ; save result
  1428.     mov    ah,cmeol        ; get confirmation
  1429.     call    comnd
  1430.     pop    bx
  1431.     jc    baudst1            ; c = failure
  1432.     mov    si,portval
  1433.     mov    ax,[si].baud        ; remember original value
  1434.     mov    [si].baud,bx        ; set the baud rate
  1435.     call    dobaud            ; use common code
  1436.     clc
  1437. baudst1:ret
  1438. BAUDST    ENDP
  1439. ;
  1440. DOBAUD  PROC    NEAR
  1441.     cmp    flags.comflg,'S'    ; SIAM?
  1442.     je    dobauds            ; e = SIAM, do SIAM things
  1443.     push    ax
  1444.     push    bx
  1445.     push    dx
  1446. ;
  1447.     mov    axsave,ax
  1448.     mov    bx,portval
  1449.     mov    ax,[bx].baud
  1450.     shl    ax,1
  1451. ;
  1452.     cmp    cpu_clock,CPU_5M_CLOCK
  1453.     je    c5mhz
  1454. c8mhz:
  1455.     mov    bx,offset bddat8
  1456.     jmp    dobd0
  1457. c5mhz:
  1458.     mov    bx,offset bddat5
  1459. dobd0:
  1460.     add    bx,ax
  1461.     cmp    word ptr [bx],0FFFFh
  1462.     jne    dobd1
  1463.     mov    ah,prstr
  1464.     mov    dx,offset badbd
  1465.     int    dos
  1466.     jmp    dobd_ex
  1467. dobd1:
  1468.     mov    ax,[bx]
  1469.     cmp    pbaud_1,ax        ; same as previous baud rate ?
  1470.     jne    dobd2
  1471.     jmp    dobd_ex
  1472. dobd2:
  1473.     call    domode            ; reset RS-232C chip
  1474.     mov    dx,timer.tmcmd
  1475.     mov    al,timer.tmsel
  1476.     out    dx,al
  1477.     mov    ax,[bx]
  1478.     mov    pbaud_1,ax        ; store baud rate
  1479.     mov    dx,timer.tmdat
  1480.     out    dx,al
  1481.     mov    al,ah
  1482.     out    dx,al
  1483.     mov    baud_set,1
  1484. dobd_ex:
  1485.     pop    dx
  1486.         pop    bx
  1487.     pop    ax
  1488.     clc
  1489.         ret                     ; Must be set before starting Kermit.
  1490.  
  1491. ; for SIAM
  1492.  
  1493. dobauds:
  1494.     push    ax
  1495.     push    bx
  1496.     push    cx
  1497.     push    dx
  1498. ;
  1499.     mov    axsave,ax
  1500.     mov    bx,portval
  1501.     mov    ax,[bx].baud
  1502.     shl    ax,1
  1503.     mov    bx,offset siam_bauddat
  1504.     add    bx,ax
  1505.     cmp    word ptr [bx],0FFFFh
  1506.     jne    dobauds1
  1507.     mov    ah,prstr
  1508.     mov    dx,offset badbd
  1509.     int    dos
  1510.     jmp    dobauds_ex
  1511. dobauds1:
  1512.     mov    ax,[bx]            ; ax = value for siam_setBaud
  1513.     cmp    pbaud_1,ax        ; same as previous baud rate ?
  1514.     jne    dobauds2
  1515.     jmp    dobauds_ex
  1516. dobauds2:
  1517.     mov    pbaud_1,ax        ; store baud rate
  1518.     siam_setBaud    ax        ; set SIAM baudrate
  1519.     siam_setParam    00011000b    ; 8-bit, no-parity, 1-stopbit
  1520.     siam_initSI            ; init SIAM
  1521.     mov    baud_set,1
  1522. dobauds_ex:
  1523.     pop    dx
  1524.         pop    cx
  1525.         pop    bx
  1526.     pop    ax
  1527.     clc
  1528.         ret                     ; Must be set before starting Kermit.
  1529.  
  1530. DOBAUD  ENDP
  1531.  
  1532. ; Get the current baud rate from the serial card and set it
  1533. ; in the portinfo structure for the current port.  Returns normally.
  1534. ; This is used during initialization.
  1535.  
  1536. GETBAUD PROC    NEAR
  1537.     cmp    flags.comflg,'A'    ; controlable ?
  1538.     jae    gbaud1            ; ae = No.
  1539.     push    bx
  1540.     cmp    baud_set,1    ; Did we already set baud rate?
  1541.     je    gbaud0        ; yes, so just leave
  1542.     mov    bx,portval
  1543.     mov    [bx].baud,B9600
  1544.     mov    baud_set,1
  1545. gbaud0:
  1546.     pop    bx
  1547. gbaud2:
  1548.         ret
  1549. gbaud1:
  1550.     cmp    flags.comflg, 'S'    ; SIAM?
  1551.     jne    gbaud2            ; ne = No, do nothing
  1552.     push    bx
  1553.     push    cx
  1554.     push    dx
  1555.     cmp    baud_set, 1    ; Did we already set baud rate?
  1556.     je    gbaud3        ; yes, so just leave
  1557.     siam_getBaud        ; get current SIAM baudrate
  1558.     mov    cx, ax        ; cx = SIAM baudrate value
  1559.     shl    ax, 1
  1560.     mov    bx, offset siam_datbaud
  1561.     add    bx, ax
  1562.     mov    ax, [bx]    ; ax = internal table index
  1563.     cmp    ax, 0FFFFH    ; unknown?
  1564.     jne    gbaud4        ; ne = SIAM baudrate already set
  1565.     mov    ax, B9600    ; default = 9600bps
  1566.     mov    cx, SIAM_B9600
  1567. gbaud4:
  1568.     mov    bx,portval
  1569.     mov    [bx].baud, ax    ; set portval baudrate data
  1570.     siam_setBaud    cx    ; set SIAM baudrate
  1571.     mov    baud_set,1
  1572.     siam_setParam    00011000b    ; 8-bit, no-parity, 1-stopbit
  1573. gbaud3:
  1574.     pop    dx
  1575.     pop    cx
  1576.     pop    bx
  1577.         ret
  1578.  
  1579. GETBAUD ENDP
  1580.  
  1581. ; Set the mode for the current port.  This is part of the serial
  1582. ; initialization routine.
  1583.  
  1584. DOMODE    PROC    NEAR
  1585.     push    ax
  1586.     push    cx
  1587.     push    dx
  1588. ;
  1589.     mov dx,modem.mdcom    ;send 3 zeros to command port to reset chip
  1590.     mov al,0
  1591.     out dx,al
  1592.     mov al,0
  1593.     out dx,al
  1594.     mov al,0
  1595.     out dx,al
  1596.     mov al,cmode        ;enable mode setting
  1597.     out dx,al
  1598.     mov cx,100        ;allow chip time to reset
  1599. mode1:    loop mode1
  1600.     mov al,mmode        ;mode: 16x rate, 8 data, no parity, 1 stop
  1601.     out dx,al
  1602.     mov cx,100
  1603. mode2:    loop mode2
  1604.     mov al,ccmd        ;RTS & DTR high, RX & TX enabled, reset errors
  1605.     out dx,al
  1606. ;
  1607.     pop    dx
  1608.     pop    cx
  1609.     pop    ax
  1610.     ret
  1611. DOMODE    ENDP
  1612.  
  1613. ; Get Char from    serial port buffer.
  1614. ; returns carry set if no character available at port, otherwise
  1615. ; returns carry clear with char in al, # of chars in buffer in dx.
  1616.  
  1617. PRTCHR  PROC    NEAR
  1618.     cmp    repflg,0        ; in replay mode ?
  1619.     je    prtch3a            ; e=no.
  1620.     jmp    prtchf
  1621. prtch3a:
  1622.     cmp    flags.comflg,'S'    ; SIAM? (speed is critical)
  1623.     jne    prtch0
  1624.     jmp    prtchs
  1625. prtch0:
  1626.     cmp    flags.comflg,'D'
  1627.     jne    prtch4
  1628.     jmp    prtchd
  1629. prtch4:
  1630. ;@@    call    chkxon
  1631.     cmp    flags.comflg,'N'
  1632.     jne    prtch3
  1633.     mov    net_rbuflen,bufsiz
  1634.     jmp    prtchn
  1635. prtch3:
  1636.     cmp    flags.comflg,'t'
  1637.     jne    prtch3b
  1638.     mov    net_rbuflen,bufsiz
  1639.     jmp    prtchn
  1640. prtch3b:
  1641.     cmp    flags.comflg,'W'
  1642.     jne    prtch3c
  1643.     mov    net_rbuflen,128
  1644.     jmp    prtchn
  1645. prtch3c:
  1646.     cmp    count,0
  1647.     jnz    prtch2
  1648.     xor    dx,dx        ; No data in buffer
  1649.     xor    al,al
  1650.     stc            ; No data in AL.
  1651.     ret
  1652. prtch2:
  1653.     pushf
  1654.     cli            ; disable interrupts while manipulating pointers
  1655.     push    si        ; save SI (uses in rpack)
  1656.     mov    si,rcvpnt
  1657.     lodsb            ; get a byte
  1658.     cmp    si,offset source + bufsiz    ; bigger than buffer?
  1659.     jb    prtch1        ; no, keep going
  1660.     mov    si,offset source    ; yes wrap around
  1661. prtch1:
  1662.     dec    count
  1663.     mov    rcvpnt,si
  1664.     mov    dx,count
  1665.     pop    si        ; restore SI
  1666.     popf
  1667.     clc            ; we have data in AL
  1668.     ret
  1669. ;
  1670. ;  Read from replay file
  1671. ;
  1672. prtchf:
  1673.     cmp    repflg,1    ; nomral state ?
  1674.     jne    prtchf0        ; ne=no
  1675.     cmp    replay_hold,0    ; holding?
  1676.     je    prtchf1        ; e=no
  1677. prtchf0:
  1678.     xor    dx,dx        ; no char at all.
  1679.     xor    al,al        ; with NUL
  1680.     stc            ; no char is available
  1681.     ret
  1682. prtchf1:
  1683.     push    bx
  1684.     push    cx
  1685.     mov    ah,readf2
  1686.     mov    bx,diskio.handle    ; file handle
  1687.     mov    cx,1            ; read one char
  1688.     mov    dx,offset rdbuf        ; to this buffer
  1689.     int    dos
  1690.     jc    prtchf2            ; c=read failure
  1691.     cmp    ax,cx            ; read the byte?
  1692.     jne    prtchf2            ; ne=no
  1693.     mov    al,rdbuf
  1694.     mov    dx,1
  1695.     clc
  1696.     jmp    prtchf3
  1697. prtchf2:
  1698.     call    pc98_bell        ; notify that we cannot read.
  1699.     mov    repflg,2
  1700.     xor    dx,dx
  1701.     xor    al,al
  1702.     stc
  1703. prtchf3:
  1704.     pop    cx
  1705.     pop    bx
  1706.     ret
  1707. ;
  1708. ;  Read from file/device
  1709. ;
  1710. prtchd:
  1711.     cmp    prthld,0    ; hold ?
  1712.     je    prtchd2        ; e = no
  1713.     stc
  1714.     ret
  1715. prtchd2:
  1716.         push    bx
  1717.         push    cx
  1718.         cmp     prthnd,0        ; Got a handle yet?
  1719.         jne     prtchd0         ; Yup just go on
  1720.         call    opnprt          ; Else 'open' the port
  1721. prtchd0:
  1722.         call    chkxon
  1723.         mov     bx,prthnd
  1724.         mov     al,instat       ; input status command
  1725.         mov     ah,ioctl        ; see note above
  1726.         int     dos
  1727.         jc      prtchd4         ; c = call failed, device not ready
  1728.         or      al,al
  1729.         jz      prtchd4         ; not ready
  1730.         mov     bx,prthnd       ; the file handle
  1731.         mov     ah,readf2       ; read file/device
  1732.         mov     cx,1            ; want just one character
  1733.         mov     dx,offset rdbuf ; where to store it
  1734.         int     dos
  1735.         jnc     prtchd1         ; nc = no error
  1736.         cmp     al,5            ; Error condition
  1737.         je      prt3dx
  1738.         cmp     al,6            ; Error condition
  1739.         je      prt3dx
  1740.         jmp     prtchd4         ; else report no char present
  1741. prtchd1:;;;mov   count,0         ; update count (always 0 for one char reads)
  1742.         mov     dx,0        ; needed to obey rules
  1743.         or      ax,ax           ; reading from end of file?
  1744.         jz      prtchd4         ; z = yes
  1745.         mov     al,rdbuf        ; recover char
  1746. prtchd3:
  1747.         pop     cx
  1748.         pop     bx
  1749.         ret                     ; return success (char is in al)
  1750. prt3dx: mov     ah,prstr
  1751.         mov     dx,offset erms50
  1752.         int     dos
  1753. prtchd4:
  1754.         pop     cx
  1755.         pop     bx
  1756.     xor    dx,dx
  1757.     xor    al,al
  1758.     stc
  1759.     ret
  1760.  
  1761. prtchn:
  1762.     cmp    count,0            ; Data in buffer?
  1763.     je    prtchn0            ; e = No. Get them from port.
  1764.     jmp    prtchn2
  1765. prtchn0:
  1766.     cmp    pcnet,1            ; session active?
  1767.     jbe    prtchn0b        ; be = no, not active
  1768.     push    ax
  1769.     push    bx
  1770.     push    cx
  1771.     push    es
  1772.     mov    ax,offset source
  1773.     mov    rcvpnt,ax
  1774.     mov    srcpnt,ax
  1775. ;
  1776.     mov    ah,net_read
  1777.     mov    al,net_port
  1778.     mov    bx,offset source
  1779.     mov    cx,net_rbuflen
  1780.     push    ds
  1781.     pop    es
  1782.     xor    dh,dh            ;@@ for tcp/ip
  1783.     test    nettype,tcpnet        ; TCP/IP Telnet?
  1784.     jz    prtchn0c        ; z = no
  1785.     call    ktcpcom
  1786.     cmp    ah,3            ;@@ for tcp/ip
  1787.     jb    prtchn0a        ;@@ for tcp/ip
  1788.     call    nethangup        ;@@ for tcp/ip
  1789.     xor    cx,cx            ;@@ for tcp/ip
  1790.     jmp    short prtchn0a
  1791. prtchn0c:int    NETCI_INT
  1792. prtchn0a:
  1793.     mov    count,cx
  1794.     add    srcpnt,cx
  1795.     pop    es
  1796.     pop    cx
  1797.     pop    bx
  1798.     pop    ax
  1799.     cmp    count,0
  1800.     jnz    prtchn2
  1801. prtchn0b:
  1802.     xor    dx,dx            ; no data in buffer
  1803.     xor    al,al
  1804.     stc                ; no data in AL.
  1805.     ret
  1806. prtchn2:
  1807.     pushf
  1808.     cli            ; disable interrupts while manipulating pointers
  1809.     push    si        ; save SI
  1810.     mov    si,rcvpnt
  1811.     lodsb            ; get a byte
  1812.     dec    count
  1813.     mov    rcvpnt,si
  1814. ;
  1815. ;    I'm not sure the floowings are necesary or not.
  1816. ;    The handshake should be done at network level.
  1817. ;
  1818. ;    check the data
  1819. ;
  1820. ;@@    push    bx
  1821. ;@@    or    al,al
  1822. ;@@    jz    prtchn5        ; Ignore nulls.
  1823. ;@@    mov    ah,al        ; copy the character in AH
  1824. ;@@    and    ah,parmsk    ; apply parity mask
  1825. ;@@    mov    bx,portval
  1826. ;@@    cmp    [bx].floflg,0    ; Doing flow control?
  1827. ;@@    je    prtchn4        ; Nope.
  1828. ;@@    mov    bx,[bx].flowc    ; Flow control character (BH=XON, BL=XOFF).
  1829. ;@@    cmp    ah,bl        ; Is it an XOFF?
  1830. ;@@    jne    prtchn3        ; Nope, go on.
  1831. ;@@    mov    xofrcv,true    ; Set the flag.
  1832. ;@@    jmp    short prtchn5
  1833. prtchn3:
  1834. ;@@    cmp    ah,bh        ; Get an XON?
  1835. ;@@    jne    prtchn4        ; No, go on.
  1836. ;@@    mov    xofrcv,false    ; Clear our flag.
  1837. ;@@    jmp    short prtchn5
  1838. ;
  1839. prtchn4:
  1840. ;@@    pop    bx
  1841.     mov    dx,count    ; number of characters in buffer
  1842.     pop    si        ; restore SI
  1843.     popf
  1844.     clc            ; we have data in AL.
  1845.     ret
  1846.     
  1847. prtchn5:
  1848. ;@@    pop    bx
  1849. ;@@    popf
  1850. ;@@    jmp    prtchn
  1851.  
  1852. ;
  1853. ; Read from SIAM
  1854. ;
  1855.  
  1856. prtchs:
  1857.     call    chkxon
  1858.     siam_getSI        ; get a char from SIAM
  1859.     xor    dx,dx        ; no data in buffer anyway
  1860.     shl    ah,1        ; if AX == 0FFFFH then AL is invalid
  1861.     ret            ; else AX should be < 7FFFH and AL is valid
  1862.  
  1863. PRTCHR  ENDP
  1864.  
  1865. ; local routine to see if we have to transmit an xon
  1866. chkxon    proc    near
  1867.     cmp    flowcnt,0        ; doing flow control?
  1868.     je    chkxo1            ; no, skip all this
  1869.     test    xofsnt,usron        ; did user send an xoff?
  1870.     jnz    chkxo1            ; nz = yes, don't contradict it here
  1871.     test    xofsnt,bufon        ; have we sent a buffer level xoff?
  1872.     jz    chkxo1            ; z = no, forget it
  1873.     cmp    count,mntrgl        ; below (low water mark) trigger?
  1874.     jae    chkxo1            ; no, forget it
  1875.     test    flowcnt,2        ; using RTS/CTS kind?
  1876.     jz    chkxo2            ; z = no
  1877.     cmp    flags.comflg,4        ; using uart?
  1878.     ja    chkxo1            ; a = no, ignore situation
  1879.     push    ax
  1880.     push    dx
  1881.     mov    al,ccmd            ; assert RTS for flow-on
  1882.     mov    dx,modem.mdcom        ; serial port command port
  1883.     out    dx,al
  1884.     and    xofsnt,off        ; remember we've sent the "xon"
  1885.     pop    dx
  1886.     pop    ax
  1887.                     ; do software flow control too
  1888. chkxo2:    test    flowcnt,1        ; using XON/XOFF kind?
  1889.     jz    chkxo1            ; z = no
  1890.     mov    ah,flowon        ; ah gets xon
  1891.     and    xofsnt,off        ; remember we've sent the xon
  1892.     call    outch2            ; send via non-flow controlled entry point
  1893. chkxo1:    ret
  1894. chkxon    endp
  1895.  
  1896. ; IHOSTS - Initialize the host by sending XOFF, or equivalent.
  1897. ; Requires that the port be initialized before hand.
  1898. ; Do not send flow control if doing half duplex.
  1899.  
  1900. IHOSTS    PROC    NEAR
  1901.     push    ax        ; save the registers
  1902.     push    bx
  1903.     push    cx
  1904.     push    dx
  1905.     mov    xofrcv,off    ; clear old xoff received flag
  1906.     mov    xofsnt,off    ; and old xoff sent flag
  1907.     cmp    portin,0    ; is a comms port active?
  1908.     jle    ihosts1        ; le = no
  1909.      mov    bx,portval    ; port indicator
  1910.      mov    ah,byte ptr [bx].flowc    ; put wait flow control char in ah
  1911.         or      ah,ah           ; check for null char
  1912.         jz      ihosts1         ; z = null, don't send it
  1913.         cmp    dupflg,0    ; full duplex?
  1914.         jne    ihosts1        ; ne = no, half
  1915.         call    outchr        ; send it
  1916. ihosts1:call    clrbuf        ; clear out interrupt buffer
  1917.     pop    dx        ; empty buffer. we are done here.
  1918.     pop    cx
  1919.     pop    bx
  1920.     pop    ax
  1921.     ret
  1922. IHOSTS  ENDP
  1923.  
  1924. ; IHOSTR - initialize the remote host for our reception of a file by
  1925. ; sending the flow-on character (XON typically) to release any held
  1926. ; data. Do not send flow control if doing half duplex.
  1927. IHOSTR    PROC    NEAR
  1928.     push    ax        ; save regs
  1929.     push    bx
  1930.     push    cx
  1931.     mov    xofrcv,off    ; clear old xoff received flag
  1932.     mov    xofsnt,off    ; and old xoff sent flag
  1933.     cmp    portin,0    ; is a comms port active?
  1934.     jle    ihostr1        ; le = no
  1935.     mov    bx,portval    ; port indicator
  1936.     mov    ah,byte ptr [bx].flowc+1; put Go-ahead flow control char in ah
  1937.     or    ah,ah        ; check for null char
  1938.      jz    ihostr1        ; z = null
  1939.      cmp    dupflg,0    ; full duplex?
  1940.      jne    ihostr1        ; ne = no, half
  1941.     call    outchr        ; send it (release Host's output queue)
  1942. ihostr1:pop    cx
  1943.     pop    bx
  1944.     pop    ax
  1945.         ret
  1946. IHOSTR  ENDP
  1947.  
  1948. DTRLOW  PROC    NEAR            ; Global proc to Hangup the Phone by making
  1949.                                 ; DTR and RTS low.
  1950.         mov ah,cmline           ; allow text to be able to display help
  1951.         mov bx,offset rdbuf     ; dummy buffer
  1952.         mov dx,offset hnghlp    ; help message
  1953.         call comnd              ; get a confirm
  1954.         jnc dtrlow1
  1955.         ret
  1956. dtrlow1:
  1957.     call serhng             ; drop DTR and RTS
  1958.         mov ah,prstr            ; give a nice message
  1959.     mov dx,offset hngmsg
  1960.         int dos
  1961.     ret
  1962. DTRLOW  ENDP
  1963.  
  1964. ; Test version for NEC PC-9801 (03-Sep-1988)
  1965. ; Hang up the Phone. Similar to SERRST except it just forces DTR and RTS low
  1966. ; to terminate the connection. 29 March 1986 [jrd]
  1967. ; Calling this twice without intervening calls to serini should be harmless.
  1968. ; Returns normally.
  1969.  
  1970. SERHNG  PROC NEAR
  1971.     call    serini        ; init port, if not done already
  1972.     mov    al,flags.comflg    ; get kind of port
  1973.     cmp    al,'A'
  1974.     jb    serhng3
  1975.     cmp    al,'S'
  1976.     je    serhngs
  1977.     cmp    al,'W'
  1978.     jne    serhng1
  1979.     jmp    serhngw
  1980. serhng1:
  1981.     clc            ; no hangup
  1982.     ret
  1983. serhng3:
  1984.     call    serrst        ; reset port so can be opened again
  1985.     cli            ; disable interrupt
  1986.     push    ax
  1987.     push    dx
  1988.     mov    dx,modem.mdcom    ; set command port
  1989.     mov    al,chng        ; hangup command
  1990.     out    dx,al
  1991.     sti
  1992.     mov    ax,500        ; 500 millisec, for pcwait
  1993.     call    pcwait
  1994.     mov    pbaud_1,0FFFFh    ; reset previous baud rate
  1995.     pop    dx
  1996.     pop    ax
  1997.     clc
  1998.         ret
  1999.  
  2000. ; when using SIAM, only DTR turns low,
  2001. ; since SIAM assumes RTS is dedicated for
  2002. ; flow control.
  2003.  
  2004. serhngs:
  2005.     call    serrst        ; reset port so can be opened again
  2006.     push    ax
  2007.     push    dx
  2008.     siam_setER    0    ; turn DTR low
  2009.     mov    ax,500        ; 500 millisec, for pcwait
  2010.     call    pcwait
  2011.     mov    pbaud_1,0FFFFh    ; reset previous baud rate
  2012.     pop    dx
  2013.     pop    ax
  2014.     clc
  2015.         ret
  2016.  
  2017. serhngw:
  2018.     call    serrst
  2019.     push    ax
  2020.     push    cx
  2021.     mov    ah,NETCI_CNTL
  2022.     mov    al,0
  2023.     mov    cx,NETCI_DIS
  2024.     int    NETCI_INT
  2025.     pop    cx
  2026.     pop    ax
  2027.     clc
  2028.     ret
  2029.  
  2030. SERHNG  ENDP
  2031.  
  2032. ; Send a break out the current serial port.  Returns normally.
  2033. SENDBR  PROC    NEAR            ; Normal Break
  2034.     cmp    flags.comflg,'N'
  2035.     je    ub_sendbr
  2036.     cmp    flags.comflg,'S'
  2037.     je    siam_sendbr
  2038.     mov    dx,modem.mdcom    ; set command port
  2039.     mov    al,cbrk+ccmd    ; add break to normal command
  2040.     out    dx,al
  2041.     mov    ax,275        ; wait for 275 milliseconds
  2042.     call    pcwait
  2043.     mov    al,ccmd        ; restore normal command
  2044.     out    dx,al
  2045.         ret
  2046. ub_sendbr:
  2047.         push    ax
  2048.         push    cx
  2049.         mov    ah,NETCI_CNTL    ; control function
  2050.         mov    al,NETCI_PORT
  2051.         mov     cl,NETCI_BRK    ; request break                          [ohl]
  2052.         int     NETCI_INT       ; Net/One command interface int. (6Bh)   [ohl]
  2053.         pop     cx
  2054.         pop     ax
  2055.         ret                     ;  [ohl] ---
  2056. siam_sendbr:
  2057.     siam_sndBRK    1    ; break on
  2058.     mov    ax,275        ; wait for 275 milliseconds
  2059.     call    pcwait
  2060.     siam_sndBRK    0    ; break off
  2061.     ret
  2062.  
  2063. SENDBR  ENDP
  2064.  
  2065. SENDBL  PROC    NEAR            ; Long Break
  2066.     cmp    flags.comflg,'N'
  2067.     je    ub_sendbl
  2068.     cmp    flags.comflg,'S'
  2069.     je    siam_sendbl
  2070.     mov    dx,modem.mdcom    ; set command port
  2071.     mov    al,cbrk+ccmd    ; add break to normal command
  2072.     out    dx,al
  2073.     mov    ax,1800        ; 1.8 second long break
  2074.     call    pcwait
  2075.     mov    al,ccmd
  2076.     out    dx,al        ; restore normal command
  2077.         ret
  2078. ub_sendbl:
  2079.         push    ax
  2080.         push    cx
  2081.         mov    ah,NETCI_CNTL    ; control function
  2082.         mov    al,NETCI_PORT
  2083.         mov     cl,NETCI_HLD    ; request hold
  2084.         int     NETCI_INT       ; Net/One command interface int. (6Bh)   [ohl]
  2085.         pop     cx
  2086.         pop     ax
  2087.         ret                     ;  [ohl] ---
  2088. siam_sendbl:
  2089.     siam_sndBRK    1    ; break on
  2090.     mov    ax,1800        ; 1.8 second long break
  2091.     call    pcwait
  2092.     siam_sndBRK    0    ; break off
  2093.     ret
  2094.  
  2095. SENDBL  ENDP
  2096.  
  2097. ; Position the cursor according to contents of DX:
  2098. ; DH contains row, DL contains column.  Returns normally.
  2099. POSCUR  PROC    NEAR
  2100.     push    di
  2101.     mov    di,offset tmpbuf
  2102.     mov    byte ptr [di],ESCAPE
  2103.     mov    byte ptr [di+1],'['
  2104.     add    di,2
  2105.     mov    al,dh
  2106.     xor    ah,ah
  2107.     inc    ax
  2108.     push    dx
  2109.     call    nout
  2110.     mov    byte ptr [di],';'
  2111.     inc    di
  2112.     pop    dx
  2113.     mov    al,dl
  2114.     xor    ah,ah
  2115.     inc    ax
  2116.     call    nout
  2117.     mov    byte ptr [di],'H'
  2118.     mov    byte ptr [di+1],'$'
  2119.     mov    dx,offset tmpbuf
  2120.     mov    ah,prstr
  2121.     int    dos
  2122.     pop    di
  2123.         ret
  2124. POSCUR  ENDP
  2125.  
  2126. ; Move the cursor to the left margin, then clear to end of line.
  2127. ; Returns normally.
  2128.  
  2129. CTLU    PROC    NEAR
  2130.         mov ah,prstr
  2131.         mov dx,offset clrlin
  2132.         int dos
  2133.         call clearl
  2134.         ret
  2135. CTLU    ENDP
  2136.  
  2137. NETHANGUP    PROC    NEAR
  2138.     mov    al,flags.comflg        ; get type of port
  2139.     cmp    al,'N'
  2140.     jne    nethang5
  2141.     mov    ah,NETCI_CLOSE        ; UB-NETCI close command
  2142.     mov    al,net_port
  2143.     int    NETCI_INT
  2144.     jmp    nethang7
  2145. nethang5:
  2146.     cmp    al,'W'            ; Novell NASI ?
  2147.     jne    nethang6        ; ne = no
  2148.     mov    ah,NETCI_CNTL
  2149.     mov    al,NETCI_DIS
  2150.     int    NETCI_INT
  2151.     clc
  2152.     ret
  2153. nethang6:test    nettype,tcpnet        ; TCP Telnet?
  2154.     jz    nethang7        ; z = no
  2155.     call    tcpclose        ; close the system
  2156. nethang7:
  2157.     mov    portn.portrdy,0        ; say the comms port is not ready
  2158.     mov    pcnet,1            ; say network but no session
  2159.     call    serrst            ; reset the serial port for reiniting
  2160.     clc
  2161.     ret
  2162. NETHANGUP    ENDP
  2163.  
  2164. NETCLOSE    PROC    NEAR
  2165.     call    nethangup
  2166.     mov    pcnet,0            ; say no network
  2167.     mov    portn.portrdy,0        ; say comms port is not ready
  2168.     clc
  2169.     ret
  2170. NETCLOSE    ENDP
  2171.  
  2172. ; Called only when Kermit exits. Program pointer passed to mssker
  2173. ; in word 'lclexit'.
  2174. ; This is used as a local end routine.
  2175.  
  2176. finexit    proc    near
  2177.     push    ax
  2178.     call    netclose
  2179.     call    clsprt            ; close device if opened.
  2180.     test    vtgrph_flg,EXITG_BIT
  2181.     jz    finexit2
  2182.     call    gdisp_on        ; graphic display on
  2183. finexit2:
  2184.     call    reset_keydef        ; reset key definition table
  2185.     call    kbdlend            ; local reset keyboard routine
  2186.     call    pc98_tend        ; reset tick-timer
  2187.     mov    ah,prstr        ;@@
  2188.     mov    dx,offset nrmscr    ;@@
  2189.     int    dos            ;@@
  2190.     pop    ax
  2191.     ret
  2192. finexit    endp
  2193.  
  2194. ; Call these routines when suspending Kermit to go to DOS
  2195. suspend    proc    near
  2196.                     ; set keyboard to DOS
  2197.     cmp    flags.comflg,'t'    ; doing TCP?
  2198.     je    suspen1            ; e = yes, don't touch port
  2199.     cmp    flags.comflg,'W'
  2200.     je    suspen1
  2201.     call    ihosts            ; suspend the host
  2202.     mov    ax,20            ; wait 20 millisec for port to finish
  2203.     call    pcwait
  2204.     call    serrst
  2205. suspen1:ret
  2206. suspend    endp
  2207.  
  2208. ; Call these routines when returning to Kermit from DOS
  2209. restore    proc    near
  2210.                     ; restore keyboard setting
  2211.     cmp    flags.comflg,'t'    ; doing TCP?
  2212.     je    restor1            ; e = yes, don't touch port
  2213.     cmp    flags.comflg,'W'
  2214.     je    restor1
  2215.     call    serini            ; reinit serial port
  2216.     call    ihostr            ; resume the host
  2217. restor1:ret
  2218. restore    endp
  2219.  
  2220. ; Start a TCP/IP Telnet session. Set nettype if successful.
  2221. tcpstart    proc    near
  2222.     mov    net_port,0
  2223.     mov    net_read,TCPIP_READ
  2224.     mov    net_write,TCPIP_WRITE
  2225.     mov    bx,offset tcpdata    ; pass near pointer to msntni.asm
  2226.     call    dword ptr tcponptr    ; call ktcpstart
  2227.     cmp    ax,2            ; successful?
  2228.     je    tcpstart1        ; e = yes
  2229.     call    tcpclose
  2230.     stc                ; fail
  2231.     ret
  2232. tcpstart1:mov    pcnet,2
  2233.     or    nettype,tcpnet        ; say a session is active
  2234.     clc
  2235.     ret
  2236. tcpstart    endp
  2237.  
  2238. ; Close/shutdown/terminate a TCP/IP Telnet session
  2239. tcpclose    proc    near
  2240.     call    dword ptr tcpoffptr    ; call ktcpstop
  2241.     and    nettype,not tcpnet    ; clear activity flag
  2242.     mov    portn.portrdy,0        ; say the comms port is not ready
  2243.     mov    pcnet,0            ; say no network
  2244.     call    serrst            ; reset the serial port for reiniting
  2245. ;@@    mov    portin,-1        ; need port re-initialization
  2246.     cmp    ax,1            ; successful?
  2247.     je    tcpclo2            ; e = yes
  2248. tcpclo1:stc                ; fail
  2249.     ret
  2250. tcpclo2:
  2251.     clc
  2252.     ret
  2253. tcpclose    endp
  2254.  
  2255. ; Start a Novell NASI session. Set nettype if successful.
  2256. nasistart    proc    near
  2257.     mov    count,0
  2258.     mov    xmtcnt,0
  2259.     mov    net_port,0
  2260.     mov    net_read,NETCI_READ
  2261.     mov    net_write,NETCI_WRITE
  2262. ;
  2263. ;@@    mov    net_read,NASI_READ
  2264. ;@@    mov    net_write,NASI_WRITE
  2265. ;@@    mov    ah,11h            ; NASI alloc circuit
  2266. ;@@    mov    al,0
  2267. ;@@    int    NETCI_INT        ; NASI int = NETCI int
  2268. ;@@    jnc    nasistart1        ; nc = no error
  2269. ;@@    mov    ax,offset nasier1    ; set error message
  2270. ;@@    jmp    nasisterr        ; error return
  2271. nasistart1:
  2272. ;@@    mov    net_port,al        ; save circuit number
  2273. ;@@    push    ds
  2274. ;@@    pop    es            ; ES = DS
  2275. ;@@    mov    bx,offset nasi_port    ; port information
  2276. ;@@    mov    ah,21h            ; Query name
  2277. ;@@    mov    cx,0            ; sets service name
  2278. ;@@    int    NETCI_INT
  2279. ;@@    jnc    nasistart2        ; nc = no error
  2280. ;@@    mov    ax,offset nasier2    ; set error message
  2281. ;@@    jmp    nasisterr        ; error return
  2282. nasistart2:
  2283. ;@@    mov    al,net_port
  2284. ;@@    mov    bx,offset nasi_port
  2285. ;@@    xor    bx,bx
  2286. ;@@    xor    cx,cx
  2287. ;@@    mov    ah,16h            ; init virtual circuit
  2288. ;@@    int    NETCI_INT
  2289. ;@@    jnc    nasistart3        ; nc = no error
  2290. ;@@@    mov    ax,offset nasier3    ; set error message
  2291. ;@@@    jmp    nasisterr        ; error return
  2292. ;@@    jmp    nasistart2        ; try again
  2293. nasistart3:
  2294.     and    nettype,not tcpnet
  2295.     mov    pcnet,2
  2296.     clc                ; success
  2297.     ret
  2298. nasisterr:
  2299.     push    dx
  2300.     mov    dx,ax
  2301.     mov    ah,prstr
  2302.     int    DOS
  2303.     pop    dx
  2304.     stc
  2305.     ret
  2306. nasistart    endp
  2307.  
  2308. ; Close/shutdown/terminate a Novell NASI session
  2309. nasiclose    proc    near
  2310. ;@@    mov    al,net_port
  2311. ;@@    mov    ah,17h            ; disconnect
  2312. ;@@    int    NETCI_INT
  2313. ;@@    mov    portn.portrdy,0        ; say the comms port is not ready
  2314.     mov    ah,NETCI_CNTL
  2315.     mov    al,NETCI_PORT
  2316.     mov    cx,NETCI_DIS
  2317.     int    NETCI_INT
  2318.     mov    pcnet,0            ; say no network
  2319.     call    serrst            ; reset the serial port for reiniting
  2320. ;@@    mov    portin,-1        ; need port re-initialization
  2321. ;@@    cmp    ax,1            ; successful?
  2322. ;@@    je    nasiclo2        ; e = yes
  2323. ;@@nasiclo1:stc                ; fail
  2324. ;@@    ret
  2325. nasiclo2:
  2326.     clc
  2327.     ret
  2328. nasiclose    endp
  2329.  
  2330. ; Open NETCI port
  2331.  
  2332. ubstart    proc    near
  2333.     cmp    pcnet,0            ; netport is closed ?
  2334.     jne    ubstartx
  2335.     push    ax
  2336.     push    bx
  2337.     push    cx
  2338.     push    es
  2339. ;
  2340.     call    clrbuf
  2341.     mov    xmtcnt,0
  2342.     push    ds
  2343.     pop    es
  2344.     mov    bx,offset source
  2345.     mov    cx,bufsiz
  2346.     mov    ah,NETCI_OPEN
  2347.     mov    al,NETCI_PORT
  2348.     mov    net_port,al
  2349.     mov    net_write,NETCI_WRITE
  2350.     mov    net_read,NETCI_READ
  2351.     int    NETCI_INT
  2352.     mov    pcnet,2
  2353. ;
  2354.     pop    es
  2355.     pop    cx
  2356.     pop    bx
  2357.     pop    ax
  2358. ubstartx:
  2359.     clc
  2360.     ret
  2361. ubstart    endp
  2362.  
  2363. chknet    proc    near
  2364.     clc
  2365.     ret
  2366. chknet    endp
  2367.  
  2368. ; Get a file handle for the communications port.  Use DOS call to get the
  2369. ; next available handle.  If it fails, ask user what value to use (there
  2370. ; should be a predefined handle for the port, generally 3).  The open
  2371. ; will fail if the system uses names other than "COM1" or "COM2".
  2372.  
  2373. opnprt    proc    near
  2374.         mov     dx,offset prtnam        ; port name
  2375.         mov     ah,open2                ; open file/device
  2376.         mov     al,2                    ; for reading/writing
  2377.         int     dos
  2378.         jnc     opnpr2                  ; nc = no error so far
  2379.         stc                             ; set carry for failure
  2380.         ret
  2381. opnpr2: mov     prthnd,ax               ; Call succeeded
  2382.     mov    prtdev,1        ; device is assumed
  2383.         mov     ah,ioctl
  2384.         mov     al,00h                  ; get device info
  2385.         xor     dx,dx
  2386.         mov     bx,prthnd               ; port's handle
  2387.         int     dos
  2388.         test    dl,80h            ; is device ?
  2389.         jnz    opnpr3            ; nz = yes.
  2390.     mov    prtdev,0        ; say this is a file
  2391.         ret
  2392. opnpr3:
  2393.         or      dl,20h                  ; set raw mode in device info
  2394.         mov     dh,0
  2395.         mov     ah,ioctl
  2396.         mov     al,01h                  ; set device info
  2397.         int     dos
  2398.         ret                             ; carry clear for success
  2399. opnprt    endp
  2400.  
  2401. clsprt    proc    near
  2402.     cmp    prthnd,0        ; already closed ?
  2403.     je    clsprt1            ; e = yes. Do nothing.
  2404.     push    ax
  2405.     push    bx
  2406.     mov    ah,close2
  2407.     mov    bx,prthnd
  2408.     int    dos
  2409.     mov    prthnd,0
  2410.     pop    bx
  2411.     pop    ax
  2412. clsprt1:
  2413.     ret
  2414. clsprt    endp
  2415.  
  2416. chknew    proc    near
  2417.     mov    dx,offset naskpmt    ; prompt for New or Resume
  2418.     call    prompt
  2419.     mov    dx,offset nettab    ; table of answers
  2420.     xor    bx,bx            ; help for the question
  2421.     mov    ah,cmkey        ; get answer keyword
  2422.     mov    comand.cmcr,1        ; allow bare CR's
  2423.     call    comnd
  2424.     mov    comand.cmcr,0        ; dis-allow bare CR's
  2425.     jc    chknew1            ; c = failure, means Resume
  2426.     push    bx
  2427.     mov    ah,cmeol        ; get a confirm
  2428.     call    comnd
  2429.     pop    bx
  2430.     jc    chknew1            ; c = failure, resume session
  2431.     or    bx,bx            ; 0 for new?
  2432.     je    chknew1            ; set carry for resume
  2433.     stc
  2434. chknew1:ret
  2435. chknew    endp
  2436. ;
  2437. ; Set the current port.
  2438. COMS    PROC    NEAR
  2439.         mov    dx,offset comptab    ; table of legal comms ports
  2440.     xor    bx,bx            ; no extra help text
  2441.     mov    ah,cmkey        ; parse key word
  2442.     call    comnd
  2443.     jnc    coms0a            ; nc = success
  2444.     ret                ; failure
  2445. coms0a:    cmp    bl,'3'            ; networks?
  2446.     ja    comstrt            ; a = yes
  2447.     mov    ah,cmeol        ; non-network
  2448.     push    bx
  2449.     call    comnd            ; get a confirm
  2450.     pop    bx
  2451.     jnc    comstrt            ; nc = success
  2452.     ret                ; failure
  2453.  
  2454. COMSTRT:mov    temp,bx            ; port ident is in BL
  2455.     cmp    bl,'N'            ; Network ?
  2456.     jne    comst1        ; ne = no
  2457.     jmp    comsn        ; Yes, setup for networks
  2458. comst1:
  2459.     cmp    bl,'D'        ; Device ?
  2460.     jne    comst2
  2461.     jmp    comsd        ; Yes, setup for device
  2462. comst2:
  2463.     cmp    bl,'t'        ; Telnet, internal?
  2464.     jne    comst2a
  2465.     jmp    comstn
  2466. comst2a:
  2467.     cmp    bl,'W'        ; Novell NASI
  2468.     jne    comst3
  2469.     jmp    comsn
  2470. comst3:
  2471.     cmp    bl,'S'        ; SIAM?
  2472.     jne    comst4
  2473.     jmp    comss
  2474. comst4:
  2475.     mov    bx,temp            ; get port number/letter
  2476.     mov    flags.comflg,bl        ; remember port number
  2477.     xor    bh,bh            ; clear high byte
  2478.     mov    bl,flags.comflg        ; get COMx number (1-3)
  2479.     push    bx
  2480.         pop    bx
  2481.     mov    ax,offset port1
  2482.     mov    portval,ax
  2483.     call    inita
  2484.     clc
  2485.     ret
  2486. comsn:
  2487.     mov    temp,bx
  2488.     mov    ah,cmeol
  2489.     call    comnd            ; Get a confirm
  2490.     jnc    comsn0
  2491.     ret                ;  Didn't get a confirm
  2492. comsn0:
  2493.     call    serrst            ; reset serial port
  2494.     mov    bx,temp
  2495.     call    chknet            ; check network status
  2496.     jnc    comsn4            ; nc = OK
  2497.     ret                ; return failure
  2498. comsn4:
  2499.     mov    bx,temp
  2500.     mov    portval,offset portn    ; set netowrk port data
  2501.     mov    flags.comflg,bl        ; set the comm port flag.
  2502.     clc                ; return sucess
  2503.     ret
  2504. ;
  2505. comsd:
  2506.  
  2507. ; Set device name. Taken from 'setdmp' in MSSSET.ASM
  2508. ; Puts device name in global string prtnam.
  2509.  
  2510.         mov     dx,offset rdbuf         ; work area
  2511.         mov     rdbuf,0                 ; clear it
  2512.         mov     bx,offset prthlp    ; help message
  2513.         mov     ah,cmword               ; allow paths
  2514.         call    comnd
  2515.         jnc    comsd0
  2516.         ret
  2517. comsd0:
  2518.         mov     ah,cmeol
  2519.         call    comnd
  2520.         jnc    comsd1
  2521.         ret
  2522. comsd1:
  2523.         mov     dx,offset rdbuf         ; assume we will use this text
  2524.         call    strlen                  ; filename given?
  2525.     push    si
  2526.     push    di
  2527.         mov     si,dx                   ; for strcpy
  2528.         cmp     cx,0                    ; length of user's filename
  2529.         jg      comsd2            ; g = filename is given
  2530.         mov     si,offset prtdef    ; no name, use default instead
  2531. comsd2:
  2532.         mov     di,offset prtnam    ; copy to globally available loc
  2533.         call    strcpy
  2534.     pop    di
  2535.     pop    si
  2536.  
  2537.     call    serrst            ; reset serial port
  2538.     call    clsprt            ; close previous device if exists.
  2539.     call    opnprt            ; open device
  2540.     jnc    comsd3
  2541.     stc
  2542.     ret
  2543. comsd3:
  2544.     mov    portval,offset portd    ; set device port data
  2545.     mov    flags.comflg,'D'
  2546.     clc
  2547.     ret
  2548.                     ; TCP/IP Telnet
  2549. comstn:    mov    ah,cmword        ; get a word (remote node name)
  2550.     mov    comand.cmblen,60    ; set 60 byte limit plus null
  2551.     mov    dx,offset decbuf    ; work buffer
  2552.     mov    word ptr decbuf,0    ; insert terminator
  2553.     mov    bx,offset tcphlp    ; help message
  2554.     call    comnd            ; get the name
  2555.     jc    comstnx
  2556.  
  2557.     mov    ah,cmword        ; get optional Port number
  2558.     mov    comand.cmblen,5        ; set 5 byte limit plus null
  2559.     mov    dx,offset decbuf+81    ; far from real node names
  2560.     mov    decbuf+80,'\'        ; \number prefix, just in case
  2561.     mov    word ptr decbuf+81,0    ; clear entry
  2562.     mov    bx,offset tcpporthlp
  2563.     call    comnd
  2564.     jc    comstnx
  2565.     mov    ah,cmeol
  2566.     call    comnd            ; get a confirm
  2567.     jnc    comstn1            ; nc = ok so far
  2568. comstnx:ret                ; did not get a confirm
  2569.  
  2570. comstn1:cmp    decbuf,0        ; anything new given?
  2571.     jnz    comstn2            ; nz = yes, copy it
  2572.     cmp    tcphost,0        ; have a name already?
  2573.     jnz    comstn3            ; nz = yes
  2574.     stc                ; return failure (no host name)
  2575.     ret
  2576. comstn2:test    nettype,tcpnet        ; is there an active tcp session?
  2577.     jz    comstn2a        ; z = no
  2578.     call    chknew            ; ask about new/old connection
  2579.     jc    comstn3            ; c = resume old
  2580.     call    tcpclose        ; end old session
  2581. comstn2a:mov    si,offset decbuf
  2582.     mov    di,offset tcphost
  2583.     call    strcpy            ; copy new host name
  2584.     mov    si,offset decbuf+81    ; optional port number
  2585.     cmp    byte ptr [si],0        ; any port specified?
  2586.     je    comstn2c        ; e = no, use default
  2587.     cmp    byte ptr [si],'\'    ; user specified leading backslash?
  2588.     je    comstn2b        ; e = yes
  2589.     dec    si            ; then use ours
  2590. comstn2b:call    katoi            ; convert si to number in ax
  2591.     cmp    ax,25            ; this one?
  2592.     je    comstn4            ; e = yes
  2593.     or    ax,ax            ; this one?
  2594.     jnz    comstn2d        ; nz = no
  2595. comstn2c:mov    ax,23            ; use official Telnet port
  2596. comstn2d:mov    bx,tcpdata+16        ; holds offset of tcpport
  2597.     mov    [bx],ax            ; copy new port
  2598. comstn3:call    serrst            ; close current port
  2599.     mov    portval,offset portn ; set Network port data structure address
  2600.     push    bx
  2601.     mov    bx,portval
  2602. ;@@    mov    [bx].sndproc,offset ubsend
  2603. ;@@    mov    [bx].rcvproc,offset ubrecv
  2604.     pop    bx
  2605.     mov    flags.comflg,'t'    ; what we want, may not have yet
  2606.         mov     nsbrk,1                 ; network BREAK supported
  2607.     mov    portin,0
  2608.     clc
  2609.     ret
  2610. comstn4:mov    ah,prstr
  2611.     mov    dx,offset badport    ; say bad port number
  2612.     int    dos
  2613.     stc
  2614.     ret
  2615.  
  2616. ; SIAM interface section
  2617.  
  2618. comss:
  2619.     mov    temp,bx
  2620.     mov    ah,cmeol
  2621.     call    comnd            ; Get a confirm
  2622.     jnc    comss0
  2623.     ret                ;  Didn't get a confirm
  2624. comss0:
  2625.     call    serrst            ; reset serial port
  2626.     call    siam_setseg        ; check if SIAM exists
  2627.     jnc    comss1            ; nc = successful
  2628.     mov    ah, prstr
  2629.     mov    dx, offset siammsg_nosiam    ; SIAM does not exist
  2630.     int    dos
  2631.     stc                ; failed
  2632.     ret
  2633. comss1:
  2634.     mov    ah, GETPSP        ; get process ID
  2635.     int    21H
  2636.     mov    processID, bx
  2637.     siam_openSI    processID    ; check if SIAM is already used
  2638.     cmp    ax, processID
  2639.     je    comss2            ; kermit can use SIAM
  2640.     mov    ah, prstr
  2641.     mov    dx, offset siammsg_in_use    ; SIAM has been used
  2642.     int    dos
  2643.     stc                ; failed
  2644.     ret
  2645. comss2:
  2646.     mov    portval,offset ports ; set network port data structure address
  2647.     mov    flags.comflg,'S'    ; set the comm port flag.
  2648.     siam_closeSI    processID    ; close SIAM immediately
  2649.     siam_errReset            ; reset errors in SIAM
  2650.     call    getbaud            ; set baudrate and word length
  2651.     siam_initSI            ; initialize SIAM
  2652.     clc                ; return sucess
  2653.     ret
  2654. ;
  2655. COMS    ENDP
  2656.  
  2657. ; SIAM Interface section
  2658.  
  2659. ; check SIAM is resident and
  2660. ; if resident clear carry flag and
  2661. ;     set siam_seg to the segment address (in AX)
  2662. ;     (assigns the first SIAM driver found)
  2663. ; if not resident set carry flag
  2664.  
  2665. SIAM_SETSEG    PROC    NEAR
  2666.  
  2667.         mov    bh, AP_NO_SIAM
  2668. siam_setseg1:    push    bx
  2669.         mov    ax, MAGIC
  2670.         mov    bl, FN_NO_SIAM
  2671.         int    2FH
  2672.     cmp    bx, MAGIC2
  2673.         pop    bx
  2674.         jz    siam_found    ; Found
  2675.         inc    bh
  2676.         cmp    bh, (MAX_PORT - 1)
  2677.         jbe    siam_setseg1
  2678.         stc            ; Not found
  2679.         ret
  2680. siam_found:    mov    siam_seg, ax    ; Found
  2681.         clc
  2682.         ret
  2683.  
  2684. SIAM_SETSEG    ENDP
  2685.  
  2686. ; Set heath emulation on/off.
  2687.  
  2688. VTSTAT  PROC    NEAR    ; For Status display [jrd]
  2689.     push    ax
  2690.     push    bx
  2691.     push    cx
  2692.     push    dx
  2693.     push    si
  2694.     push    di
  2695.     push    es
  2696. ;
  2697.     push    ds
  2698.     pop    es
  2699.     cld
  2700. ;  CPU clock
  2701.     mov    si,offset clkmsg
  2702.     mov    cx,8
  2703.     cmp    cpu_clock,CPU_5M_CLOCK
  2704.     je    vtstat0
  2705.     add    si,cx
  2706. vtstat0:
  2707.     mov    di,offset vstmsg_clk
  2708.     rep    movsb
  2709. ;  Display
  2710.     mov    si,offset dspmsg
  2711.     mov    cx,8
  2712.     cmp    display_mode,0
  2713.     je    vtstat0_1
  2714.     add    si,cx
  2715. vtstat0_1:
  2716.     mov    di,offset vstmsg_dsp
  2717.     rep    movsb
  2718. ;  Keyclick
  2719.     mov    si,offset onmsg
  2720.     mov    cx,3
  2721.     test    vt100_flags,KEYCLICK_BIT
  2722.     jz    vtstat1
  2723.     add    si,cx
  2724. vtstat1:
  2725.     mov    di,offset vstmsg_key
  2726.     rep    movsb
  2727. ;  Log-cooked
  2728.     mov    si,offset onmsg
  2729.     mov    cx,3
  2730.     test    vt100_lflag,LOGCOOK_BIT
  2731.     jz    vtstat2
  2732.     add    si,cx
  2733. vtstat2:
  2734.     mov    di,offset vstmsg_logcook
  2735.     rep    movsb
  2736. ;  Autowrap
  2737.     mov    si,offset onmsg
  2738.     mov    cx,3
  2739.     test    vt100_flags,AUTOWRAP_BIT
  2740.     jz    vtstat3
  2741.     add    si,cx
  2742. vtstat3:
  2743.     mov    di,offset vstmsg_autow
  2744.     rep    movsb
  2745. ;  Cursor key mode
  2746.     mov    si,offset applmsg
  2747.     mov    cx,11
  2748.     mov    di,offset vstmsg_curmod
  2749.     cmp    curkey_mode,0
  2750.     je    vtstat5
  2751.     add    si,cx
  2752. vtstat5:
  2753.     rep    movsb
  2754. ;  Keypad mode
  2755.     mov    si,offset applmsg
  2756.     mov    cx,11
  2757.     mov    di,offset vstmsg_kpdmod
  2758.     cmp    keypad_mode,0
  2759.     je    vtstat7
  2760.     add    si,cx
  2761. vtstat7:
  2762.     rep    movsb
  2763. ;  Foreground
  2764.     mov    si,offset colmsg
  2765.     mov    di,offset def_color
  2766.     mov    al,[di]
  2767.     mov    ah,0
  2768.     mov    cx,7
  2769.     imul    cl
  2770.     add    si,ax
  2771.     mov    di,offset vstmsg_colf
  2772.     rep    movsb
  2773. ;  Background
  2774.     mov    si,offset colmsg
  2775.     mov    di,offset def_color
  2776.     mov    al,[di+1]
  2777.     mov    ah,0
  2778.     mov    cx,7
  2779.     imul    cl
  2780.     add    si,ax
  2781.     mov    di,offset vstmsg_colb
  2782.     rep    movsb
  2783. ;  Highlight
  2784.     mov    si,offset colmsg
  2785.     mov    di,offset def_color
  2786.     mov    al,[di+2]
  2787.     mov    ah,0
  2788.     mov    cx,7
  2789.     imul    cl
  2790.     add    si,ax
  2791.     mov    di,offset vstmsg_colh
  2792.     rep    movsb
  2793. ;  Modeline
  2794.     mov    si,offset colmsg
  2795.     mov    di,offset def_color
  2796.     mov    al,[di+3]
  2797.     mov    ah,0
  2798.     mov    cx,7
  2799.     imul    cl
  2800.     add    si,ax
  2801.     mov    di,offset vstmsg_colm
  2802.     rep    movsb
  2803. ;  Kanji-code send
  2804.     mov    si,offset knjmsg
  2805.     mov    ah,0
  2806.     mov    al,kanji_scode
  2807.     mov    cx,9
  2808.     imul    cl
  2809.     add    si,ax
  2810.     mov    di,offset vstmsg_sknj
  2811.     rep    movsb
  2812. ;  Kanji-code receive
  2813.     mov    si,offset knjmsg
  2814.     mov    ah,0
  2815.     mov    al,kanji_rcode
  2816.     mov    cx,9
  2817.     imul    cl
  2818.     add    si,ax
  2819.     mov    di,offset vstmsg_rknj
  2820.     rep    movsb
  2821. ;  Keyinput
  2822.     mov    si,offset keyinmsg
  2823.     mov    ah,0
  2824.     mov    al,keyin_dos
  2825.     mov    cx,6
  2826.     imul    cl
  2827.     add    si,ax
  2828.     mov    di,offset vstmsg_keyin
  2829.     rep    movsb
  2830. ;  Insert/Replace
  2831.     mov    si,offset insrepmsg
  2832.     mov    cx,7            ; message length
  2833.     test    vt100_flags,INSERT_BIT
  2834.     jz    vtstat10
  2835.     add    si,cx
  2836. vtstat10:
  2837.     mov    di,offset vstmsg_insrep
  2838.     rep    movsb
  2839. ;  Origin-mode
  2840.     mov    si,offset originmsg
  2841.     mov    cx,8
  2842.     test    vt100_flags,ORIGIN_BIT
  2843.     jz    vtstat11
  2844.     add    si,cx
  2845. vtstat11:
  2846.     mov    di,offset vstmsg_origin
  2847.     rep    movsb
  2848. ;  Line-feed/New-line
  2849.     mov    si,offset lfnlmsg
  2850.     mov    cx,9
  2851.     test    vt100_flags,NEWLINE_BIT
  2852.     jz    vtstat12
  2853.     add    si,cx
  2854. vtstat12:
  2855.     mov    di,offset vstmsg_lfnl
  2856.     rep    movsb
  2857. ;
  2858.     mov    ah,prstr
  2859.     mov    dx,offset vstmsg
  2860.     int    dos
  2861. ;
  2862.     call    tekstat
  2863.     mov    dx,si
  2864.     mov    ah,prstr
  2865.     int    dos
  2866. ;
  2867.     pop    es
  2868.     pop    di
  2869.     pop    si
  2870.     pop    dx
  2871.     pop    cx
  2872.     pop    bx
  2873.     pop    ax
  2874.         ret             ; no emulator status to display
  2875. VTSTAT  ENDP
  2876.  
  2877. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  2878. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  2879. ; is determined by mssset and is passed as pointer dmpname.
  2880.  
  2881. DUMPSCR PROC    NEAR    ; Dumps screen contents to a file. Just Beeps here
  2882.  
  2883.     push    ax
  2884.     push    bx
  2885.     push    cx
  2886.     push    dx
  2887.  
  2888.     mov     dmphand,-1              ; preset illegal handle
  2889.     mov     dx,offset dmpname       ; name of disk file, from mssset
  2890.     mov     ax,dx                   ; where isfile wants name ptr
  2891.     call    isfile                  ; what kind of file is this?
  2892.     jc      dmp5                    ; c = no such file, create it
  2893.     test    byte ptr filtst.dta+21,1fh ; file attributes, ok to write?
  2894.     jnz     dmp0                    ; nz = no.
  2895.     mov     al,1                    ; writing
  2896.     mov     ah,open2                ; open existing file
  2897.     int     dos
  2898.     jc      dmp0                    ; c = failure
  2899.     mov     dmphand,ax              ; save file handle
  2900.     mov     bx,ax                   ; need handle here
  2901.     mov     cx,0ffffh               ; setup file pointer
  2902.     mov     dx,-1                   ; and offset
  2903.     mov     al,2                    ; move to eof minus one byte
  2904.     mov     ah,lseek                ; seek the end
  2905.     int     dos
  2906.     jmp     dmp1
  2907.  
  2908. dmp5:    test    filtst.fstat,80h        ; access problem?
  2909.     jnz     dmp0                    ; nz = yes
  2910.     mov     ah,creat2               ; file did not exist
  2911.     mov     cx,20h                  ; attributes, archive bit
  2912.     int     dos
  2913.     mov     dmphand,ax              ; save file handle
  2914.     jnc     dmp1                    ; nc = ok
  2915.  
  2916. dmp0:    call    beep
  2917.     pop     dx
  2918.     pop     cx
  2919.     pop     bx
  2920.     pop     ax
  2921.     clc
  2922.     ret
  2923.  
  2924. dmp1:    mov     ah,ioctl                ; is destination ready for output?
  2925.     mov     al,7                    ; test output status
  2926.     mov     bx,dmphand              ; handle
  2927.     int     dos
  2928.     jc      dmp0                    ; c = error
  2929.     cmp     al,0ffh                 ; ready?
  2930.     jne     dmp0                    ; ne = not ready.
  2931. ;
  2932.     cmp    flags.vtflg,tttek
  2933.     jne    dmp_v1
  2934.     call    ent_vt
  2935. dmp_v1:
  2936.     mov     bx,dmphand              ; need file handle
  2937.     call    vt100_dump
  2938. ;
  2939.     mov    bx,offset tmpbuf
  2940.     mov    byte ptr [bx],CTLZ    ; put EOF mark
  2941.     mov    dx,bx
  2942.     mov    bx,dmphand
  2943.     mov    cx,1
  2944.     mov    ah,write2
  2945.     int    dos            ; write EOF
  2946. ;
  2947.     mov     ah,close2               ; close the file now
  2948.     int     dos
  2949. ;
  2950.     pop     dx
  2951.     pop     cx
  2952.     pop     bx
  2953.     pop     ax
  2954.     clc
  2955.     ret
  2956.  
  2957. DUMPSCR ENDP
  2958.  
  2959. ; Initialize variables to values used by this routine.
  2960.  
  2961. lclini:
  2962.     call    detclck        ; determine CPU clock
  2963.     call    pcwtst        ; adjust wait counter
  2964.     call    pc98_tstrt    ; start pc98 tick-timer
  2965.     call    scrncheck    ; check the screen
  2966.     mov    prthnd,0    ; No handle yet
  2967.     mov    portval,offset port1    ; default portval
  2968.     mov    pbaud_1,0FFFFh    ; previous baud rate is unknown
  2969.     mov    flags.comflg,1    ; Communication port 1
  2970.     mov    flags.chrset,932    ; force to CP932(Shift-JIS)
  2971.     mov    flags.vtflg,ttvt102    ; override default terminal type
  2972.     call    getbaud        ; Put the baud rate in portval [08-Feb-89]
  2973.     mov    curkey_mode,0    ; cursor key is ANSI normal
  2974.     mov    keypad_mode,0    ; keypad is normal
  2975.     mov    vt100_flags,AUTOTEK_BIT    ; set flags
  2976.     mov    vt100_lflag,LOGCOOK_BIT ; log mode is cooked
  2977.     mov    vt100_gflag,0
  2978.     mov    kanji_scode,KNJCODE_DEC    ; DEC kanji code
  2979.     mov    kanji_rcode,KNJCODE_DEC
  2980.     mov    kanji_smode,0    ; 1st character must be Kanji 1st byte.
  2981.     mov    kanji_rmode,0
  2982.     mov    xmtcnt,0        ; clear counter for xfer
  2983.     or    flags.remflg,d8bit    ; display 8-bit
  2984.     call    set_keydef
  2985.     mov    lclsusp,offset suspend    ; call this when suspending to DOS
  2986.     mov    lclrest,offset restore    ; call this when returning from DOS
  2987.     mov    lclexit,offset finexit    ; call this when exiting Kermit
  2988.         call    msuinit        ; declare keyboard translator present
  2989.         call    kbdlini        ; keyboard local initialize
  2990.     call    vt100_ini    ; initialize VT100 terminal emulator
  2991.     call    tek4014_ini    ; initialize TEK4014 terminal emulator
  2992.         push    si
  2993.         mov    si,offset def_color
  2994.         call    set_cur_color
  2995.         call    vt100_color    ; setup color index table
  2996.         call    tek4014_color    ; same for Tek4014
  2997.     pop    si
  2998.     mov    ah,prstr        ;@@
  2999.     mov    dx,offset fulscr    ;@@
  3000.     int    dos            ;@@
  3001.     clc
  3002.         ret
  3003.  
  3004. showkey:
  3005.         mov ax,offset shkmsg
  3006.         mov cx,shklen
  3007.         ret
  3008.  
  3009. scrncheck    proc    near
  3010.     push    ax
  3011.     mov    ah,0bh        ; sense CRT mode
  3012.     int    BIOS
  3013.     test    al,1        ; 25 line mode ?
  3014.     jz    scrncheck1    ; z = yes
  3015.     mov    scrn_lines,20
  3016.     mov    ah,19        ; lines/row - 1
  3017.     jmp    scrncheck2
  3018. scrncheck1:
  3019.     mov    scrn_lines,25
  3020.     mov    ah,15        ; lines/row - 1
  3021. scrncheck2:
  3022.     mov    al,0
  3023.     mov    vt100_cursr,ax
  3024.     pop    ax
  3025.     ret
  3026. scrncheck    endp
  3027.  
  3028. detclck    proc    near
  3029. ;
  3030. ;  determine CPU clock
  3031. ;
  3032.     mov    cpu_clock,CPU_5M_CLOCK
  3033.     push    ax
  3034.     in    al,042h
  3035.     test    al,0C0h
  3036.     jz    detclck1
  3037.     test    al,020h
  3038.     jz    detclck1
  3039.     mov    cpu_clock,CPU_8M_CLOCK
  3040. detclck1:
  3041.     pop    ax
  3042.     ret
  3043. detclck    endp
  3044.  
  3045. ; serial port interrupt routine.  This is not accessible outside this
  3046. ; module, handles serial port receiver interrupts.
  3047.  
  3048. SERINT    PROC  NEAR
  3049.     push ds            ; save these on remote stack
  3050.     push ax
  3051.     mov ax,seg data        ; get our own data segment
  3052.     mov ds,ax
  3053.     mov mnsp,sp        ; save remote stack information
  3054.     mov mnsseg,ss
  3055.     mov sp,offset mnstk    ; switch to local stack
  3056.     mov ss,ax
  3057.     push es            ; and save remaining registers
  3058.     push bp
  3059.     push di
  3060.     push si
  3061.     push dx
  3062.     push cx
  3063.     push bx
  3064.     mov es,ax
  3065.     call mnproc        ; process the interrupt
  3066.     mov al,icEOI
  3067.           mov dx,intcmda
  3068.     out dx,al
  3069.     pop bx            ; restore registers from stack
  3070.     pop cx
  3071.     pop dx
  3072.     pop si
  3073.     pop di
  3074.     pop bp
  3075.     pop es
  3076.     mov ax,mnsseg        ; switch back to remote stack
  3077.     mov ss,ax
  3078.     mov ax,mnsp
  3079.     mov sp,ax
  3080.     pop ax
  3081.     pop ds
  3082.     iret
  3083.  
  3084. ; handler for serial input
  3085.  
  3086. mnproc:    cld
  3087.     mov    dx,modem.mdstat        ; is data available?
  3088.     in    al,dx
  3089.     test    al,rxrdy
  3090.     jnz    mnpro0b            ; nz = yes
  3091.     jmp    mnpror
  3092. mnpro0b:
  3093.     mov    dx,modem.mddat
  3094.     in    al,dx            ; read the received character into al
  3095.     test    flowcnt,1        ; XON/XOFF flow control active?
  3096.     jz    mnpro2            ; z = no
  3097.     mov    dh,al            ; dh = working copy. Check flow ctrl
  3098.     and    dh,parmsk        ; strip parity temporarily, if any
  3099.     cmp    dh,flowoff        ; acting on Xoff?
  3100.     jne    mnpro1            ; ne = no, go on
  3101.     cmp    xofsnt,0        ; have we sent an outstanding XOFF?
  3102.     jne    mnpro4e            ; ne = yes, ignore (possible echo)
  3103.     mov    xofrcv,bufon        ; set the flag saying XOFF received
  3104.     jmp    short mnpro4e        ;  and continue the loop
  3105. mnpro1:    cmp    dh,flowon        ; acting Xon?
  3106.     jne    mnpro2            ; ne = no, go on
  3107.     mov    xofrcv,off        ; clear the XOFF received flag
  3108.     jmp    short mnpro4e        ;  and continue the loop
  3109. mnpro2:    push    bx
  3110. mnpro2a:mov    bx,srcpnt        ; address of buffer storage slot
  3111.     mov    byte ptr [bx],al    ; store the new char in buffer "source"
  3112.     inc    srcpnt            ; point to the next slot
  3113.     inc    bx
  3114.     cmp    bx,offset source + bufsiz ; beyond end of buffer?
  3115.     jb    mnpro3            ; not past end...
  3116.     mov    srcpnt,offset source    ; wrap buffer around
  3117. mnpro3:    cmp    count,bufsiz        ; filled already?
  3118.     jae    mnpro4            ; ae = yes
  3119.     inc    count            ; no, add a char
  3120. mnpro4:
  3121. mnpro4a:pop    bx
  3122. mnpro4e:
  3123.     cmp    count,mntrgh        ; past the high trigger point?
  3124.     jbe    mnpror            ; be = no, we're within our limit.
  3125.     test    xofsnt,bufon    ; has an XOFF been sent by buffer control?
  3126.     jnz    mnpror            ; nz = Yes
  3127.     test    flowcnt,2        ; using RTS/CTS flow control?
  3128.     jz    mnpro4b            ; z = no
  3129.     mov    dx,modem.mdcom        ; modem command port
  3130.     mov    al,cmdrtslow        ; drop RTS
  3131.     out    dx,al            ; tell the UART to drop RTS
  3132.     mov    xofsnt,bufon        ; remember RTS reset at buffer level
  3133.     jmp    short mnpror
  3134. mnpro4b:mov    al,flowoff        ; get the flow off char (XOFF or null)
  3135.     or    al,al            ; do not send null chars
  3136.     jz    mnpror            ; z = null, nothing to send
  3137.     call    dopar            ; set parity appropriately
  3138.     mov    ah,al            ; don't overwrite character with status
  3139.     push    cx            ; save reg
  3140.     xor    cx,cx            ; loop counter
  3141. mnpro5:    mov    dx,modem.mdstat
  3142.     in    al,dx
  3143.     test    al,txrdy        ; transmitter ready?
  3144.     jnz    mnpro6            ; nz = yes
  3145.     jmp    $+2            ; use time, prevent overdriving UART
  3146.     jmp    $+2
  3147.     loop    mnpro5
  3148.     jmp    short mnpro7        ; timeout
  3149. mnpro6:    mov    al,ah            ; now send out the flow control char
  3150.     mov    dx,modem.mddat
  3151.     jmp    $+2
  3152.     out    dx,al
  3153.     mov    xofsnt,bufon    ; remember we sent an XOFF at buffer level
  3154. mnpro7:    pop    cx            ; restore reg
  3155. mnpror:    ret
  3156.  
  3157. SERINT    ENDP
  3158.  
  3159. ; Initialization for using serial port.  Returns normally.
  3160.  
  3161. SERINI  PROC    NEAR
  3162.     cmp    portin,0        ; did we initialize port already?
  3163.     je    serin5            ; e = yes
  3164.     jl    serin0            ; l = no, not yet
  3165.     jmp    serin4            ; yes, update flow and leave
  3166. serin0:    mov    bl,flags.comflg        ; pass current port ident
  3167.     mov    portin,0        ; say have been here once
  3168.     call    comstrt            ; do SET PORT now
  3169.     jnc    serin5            ; nc = success
  3170.     ret                ; failed, exit now
  3171. serin5:    push    bx
  3172.     mov    bx,portval
  3173.     mov    bl,[bx].duplex        ; get full/half duplex flag, local cpy
  3174.     mov    dupflg,bl
  3175.     pop    bx
  3176.     cmp    flags.comflg,4        ; UART?
  3177.     jbe    serin2            ; be = yes, real thing
  3178.     jmp    serin3
  3179.  
  3180. serin2:
  3181.     call    inita
  3182.     call    clrbuf            ; Clear input buffer.
  3183.     jmp    serin4
  3184.  
  3185. serin3:
  3186. serin3d:cmp    flags.comflg,'N'    ; UB-NETCI ?
  3187.     jne    serin3e            ; ne = no
  3188.     call    ubstart
  3189.     jnc    serin4
  3190.     call    nethangup
  3191.     stc
  3192.     ret
  3193. serin3e:cmp    flags.comflg,'W'    ; Novell NASI ?
  3194.     jne    serin3f            ; ne = no
  3195.     call    nasistart        ; start NASI session
  3196.     jnc    serin4
  3197.     call    nethangup
  3198.     stc
  3199.     ret
  3200. serin3f:cmp    flags.comflg,'t'    ; TCP/IP ?
  3201.     jne    serin4            ; ne = no
  3202.     call    tcpstart        ; start TCP connection
  3203.     jnc    serin4
  3204.     call    nethangup
  3205.     stc
  3206.     ret
  3207. serin4:    push    bx
  3208.     mov    bx,portval        ; get port data structure
  3209.     mov    [bx].portrdy,1        ; say the comms port is ready
  3210.     mov    parmsk,0ffh        ; parity mask, assume parity is None
  3211.     cmp    [bx].parflg,parnon    ; is it None?
  3212.     je    serin1            ; e = yes
  3213.     mov    parmsk,07fh        ; no pass lower 7 bits as data
  3214. serin1:    xor    ax,ax
  3215.     mov    al,[bx].floflg        ; flow control kind
  3216.     mov    flowcnt,al        ; save here for active use
  3217.     mov    ax,[bx].flowc        ; get flow control chars
  3218. serin1a:mov    flowoff,al        ; xoff or null
  3219.     mov    flowon,ah        ; xon or null
  3220.     mov    xofrcv,off        ; clear xoff received flag
  3221.     pop    bx
  3222. ;@@    mov    quechar,0        ; clear outchr queued flow control
  3223.     mov    portin,1        ; say initialized
  3224.     clc                ; carry clear for success
  3225.     ret
  3226. SERINI  ENDP
  3227.  
  3228. ; Reset the serial port.  This is the opposite of serini.  Calling
  3229. ; this twice without intervening calls to serini should be harmless.
  3230. ; Returns normally.
  3231.  
  3232. SERRST  PROC    NEAR
  3233.     cmp    portin,0        ; Reset already?
  3234.     jg    srst3            ; g = no
  3235.     clc
  3236.     ret
  3237. srst3:    cmp    flags.comflg,'0'    ; Bios or networks?
  3238.     jb    srst4            ; b = no, real UART
  3239.     jmp    srst1            ; nz = yes (Bios or Net)
  3240. srst4:
  3241.     cmp    portinia,0        ; Did we reset port already?
  3242.     je    rsta0            ; Yes, so just leave.
  3243.     push    es
  3244.     cli                ; Disable interrupts
  3245.     xor    ax,ax            ; Address low memory
  3246.     mov    es,ax
  3247.     mov    ax,oldsera_ofs        ; Restore interrupt vector
  3248.     mov    es:[4*icsvcta],ax
  3249.     mov    ax,oldsera_sgm
  3250.     mov    es:[4*icsvcta+2],ax
  3251.     mov    dx,intmska        ; restore old master controller mask
  3252.     mov    al,oldmska
  3253.     out    dx,al
  3254.     mov    dx,mnmska        ; disable serial interrupts at port
  3255. ;    mov al,txmsk+rxmsk+tbemsk
  3256.     mov    al,oldmsdat
  3257.     out    dx,al
  3258.     mov    portinia,0        ; Remember port has been reset
  3259.     sti                ; Allow interrupts
  3260.     pop    es
  3261. rsta0:    jmp    short srst8
  3262.  
  3263. srst1:
  3264. srst8:    mov    portin,0        ; reset flag
  3265.     push    bx
  3266.     mov    bx,portval        ; port data structure
  3267.     mov    [bx].portrdy,0        ; say port is not ready
  3268.     pop    bx
  3269. ;@@    mov    quechar,0        ; clear any outchr queued char
  3270.     clc
  3271.     ret
  3272. SERRST  ENDP
  3273.  
  3274. ; Local routine to initialize the standard serial port
  3275.  
  3276. INITA    PROC    NEAR
  3277.     cmp    portinia,1    ; Did we initialize port already ?
  3278.     je    inita0        ; Yes, so just leave.
  3279. ;
  3280.     cli            ; Disable interrupts
  3281.     push    ax
  3282.     push    dx
  3283.     push    es
  3284. ;
  3285.     mov    ax,offset port1
  3286.     mov    portval,ax
  3287.     xor    ax,ax
  3288.     mov    es,ax
  3289.     mov    ax,es:[4*icsvcta]    ; save interrupt vector for port1
  3290.     mov    oldsera_ofs,ax
  3291.     mov    ax,es:[4*icsvcta+2]
  3292.     mov    oldsera_sgm,ax
  3293.     mov    ax,offset serint    ; pointer to our routine
  3294.     mov    es:[4*icsvcta],ax    ; set interrupt routine offset
  3295.     mov    es:[4*icsvcta+2],cs    ;  and segment
  3296.     mov    dx,intmska
  3297.     in    al,dx
  3298.     mov    oldmska,al        ; save old master controller mask
  3299. ;
  3300.     and    al,not icsmska        ; enable serial interrupt at master
  3301.     out    dx,al
  3302.     mov    dx,mnmska
  3303.     in    al,dx
  3304.     mov    oldmsdat,al
  3305.     and    al,0f8h
  3306.     or    al,rxmsk
  3307.     out    dx,al
  3308.     mov    modem.mddat,mndata
  3309.     mov    modem.mdstat,mnst1a
  3310.     mov    modem.mdcom,mncmda
  3311.     mov    modem.mdmsk,mnmska
  3312.     mov    modem.mdsig,mnrdsa
  3313.     mov    timer.tmdat,tmdata
  3314.     mov    timer.tmcmd,tmcmda
  3315.     mov    timer.tmsel,tmsela
  3316.     call    dobaud
  3317.     mov    portinia,1
  3318.     call    clrbuf
  3319. ;
  3320.     pop    es
  3321.     pop    dx
  3322.     pop    ax
  3323.     sti
  3324. inita0:    ret
  3325. INITA    ENDP
  3326.  
  3327. ;
  3328. ; Produce a short beep.  The PC DOS bell is long enough to cause a loss
  3329. ; of data at the port.  Returns normally.
  3330.  
  3331. BEEP    PROC    NEAR
  3332.         mov dl,bell
  3333.         mov ah,dconio
  3334.         int dos
  3335.         ret
  3336. BEEP    ENDP
  3337. ;
  3338.  
  3339.  
  3340. ; Terminal emulator.
  3341. ;
  3342. term    proc    near
  3343.     mov    oldsp,sp        ; remember stack for i/o failure
  3344.     mov    argadr,ax        ; save argument ptr
  3345.     mov    prthld,0        ; clear port hold flag at the beginning
  3346.     mov    replay_hold,0
  3347.     mov    bx,portval
  3348.     mov    bl,[bx].floflg
  3349.     mov    flowcnt,bl
  3350.     mov    bx,portval
  3351.     mov    bx,[bx].flowc        ; get flow control character
  3352.     mov    flowoff,bl
  3353.     mov    flowon,bh
  3354.     or    vt100_flags,AUTOTEK_BIT
  3355.     test    denyflg,tekxflg
  3356.     jz    term_01
  3357.     and    vt100_flags,(not AUTOTEK_BIT)
  3358. term_01:
  3359.     and    vt100_lflag,(not LOGENAB_BIT)
  3360.     test    flags.capflg,logses    ; session logging enabled?
  3361.     jz    term_02            ; z = no.
  3362.     or    vt100_lflag,LOGENAB_BIT
  3363. term_02:
  3364.     cmp    flags.vtflg,ttgenrc    ; no terminal emulation?
  3365.     je    term_02a        ; e = no emulation
  3366.     call    vt100_restore
  3367.     call    tek4014_restore
  3368. term_02a:
  3369.     mov    fairness,0
  3370.     mov    kanji_smode,0        ; clear Kanji pending flag
  3371.     mov    kanji_rmode,0
  3372.     mov    kanji_7smode,0
  3373.     mov    kanji_7rmode,0
  3374.         mov     si,argadr                  ; this is source
  3375.         mov     di,offset vt_ourarg        ; place to store arguments
  3376.         mov     ax,ds
  3377.         mov     es,ax                   ; address destination segment
  3378.         mov     cx,size termarg
  3379.         cld
  3380.         rep     movsb                   ; copy into our arg blk
  3381.         mov    bx,argadr        ; get the address of argument
  3382.         mov    al,[bx].flgs        ; get the flags
  3383.         mov    yflags,al        ; set yflags
  3384. ;@@    and    vt_ourarg.flgs,not (prtscr) ; no screen printing at startup
  3385. ;@@    mov    vt100_pflag,0
  3386.         mov     ax,vt_ourarg.captr
  3387.         mov     captrtn,ax              ; buffer capture routine
  3388.     test    vt_ourarg.flgs,modoff    ; mode line off?
  3389.     jnz    term_1
  3390.     call    set_modlin        ; setup mode line
  3391. term_1:
  3392.         mov     parmsk,0ffh             ; parity mask, assume parity = None
  3393.         cmp     vt_ourarg.parity,parnon    ; is parity None?
  3394.         je      term_2            ; e = yes, keep all 8 bits
  3395.         mov     parmsk,07fh             ; else keep lower 7 bits
  3396. term_2:
  3397.     mov    ax,KI_code
  3398.     call    ans_keystr
  3399.     mov    KI_len,cx
  3400.     mov    KI_ofs,bx
  3401.     mov    ax,KO_code
  3402.     call    ans_keystr
  3403.     mov    KO_len,cx
  3404.     mov    KO_ofs,bx
  3405. ;
  3406.     cmp    flags.vtflg,tttek    ; Tek4014 emulation ?
  3407.     je    term_tk            ; e = yes.
  3408.     cmp    flags.vtflg,ttgenrc    ; no emulation
  3409.     jne    term_vt            ; ne = yes, VT emulation
  3410.     jmp    term0            ; non supported terminal
  3411. ;
  3412. ;  vt100/vt52 emulation
  3413. term_vt:
  3414.     call    ent_vt
  3415.     jmp    term0
  3416. ;
  3417. ;  tek4014 emulation
  3418. term_tk:
  3419.     call    ent_tk
  3420. ;
  3421. term0:
  3422. ;    test    vt100_flags,LOOPTEST_BIT
  3423. ;    je    term1
  3424. ;    jmp    term_tst1
  3425.  
  3426. term1:  call    portchr         ; get char from port, apply parity mask
  3427.         jnc    short term1a    ; nc = char at port
  3428.         push    bx
  3429.         mov    bx,portval
  3430.         cmp    [bx].portrdy,0    ; is port ready for business?
  3431.         pop    bx
  3432.         jne    term1b
  3433.         mov    kbdflg,'C'    ; report 'C' to TERM's caller
  3434.         mov    sp,oldsp    ; recover startup stack pointer
  3435.         jmp    quit
  3436. term1a:
  3437.         call    outtty          ; display and capture char
  3438. term1b:
  3439.     inc    fairness
  3440.     cmp    fairness,10
  3441.     jb    term1        ; do quick loop back for more
  3442. term2:    mov    fairness,0
  3443. ;@@    call    pntflsh        ; flush printer buffer
  3444. ;@@    jnc    term2a        ; nc = success
  3445. ;@@    call    pntdead        ; call bad printer notifier
  3446. term2a:    call    keybd           ; keyboard translator to read and send text
  3447.         jnc     term1           ; nc = do not exit Connect mode
  3448.  
  3449. quit:    call    pntflsh        ; flush printer buffer
  3450.     cmp    flags.vtflg,ttgenrc    ; no emulation ?
  3451.     je    term3
  3452.     call    vt100_save
  3453.     call    tek4014_save
  3454. term3:    mov    al,1
  3455.     call    text_scrn    ; ON the text screen
  3456.     xor    al,al
  3457.     mov    ah,prstr
  3458.         mov    dx,offset retscr
  3459.     int    dos
  3460.     ret
  3461.  
  3462. ;term_tst1:
  3463. ;    mov    ax,3D00h    ; open file (read only)
  3464. ;    mov    dx,offset playback_fnam
  3465. ;    int    dos
  3466. ;    jc    term_tstz    ; if error, then normal operation
  3467. ;    mov    playback_hndl,ax
  3468. ;term_tst2:
  3469. ;@@    call    portchr
  3470. ;@@    jnc    short term_tst3
  3471. ;@@    call    outtty
  3472. ;@@    jmp    term_tst2
  3473. ;term_tst3:
  3474. ;    mov    ah,3Fh        ; read file/device
  3475. ;    mov    dx,offset tmpbuf
  3476. ;    mov    bx,playback_hndl
  3477. ;@@    mov    cx,8
  3478. ;    mov    cx,72        ;@@
  3479. ;    int    dos
  3480. ;    jc    term_tstx
  3481. ;    mov    cx,ax
  3482. ;    jcxz    term_tstx
  3483. ;    mov    si,offset tmpbuf
  3484. ;term_tst4:
  3485. ;    push    cx
  3486. ;    push    si
  3487. ;@@    mov    ah,[si]
  3488. ;@@    call    outchr
  3489. ;@@     nop
  3490. ;@@     nop
  3491. ;@@     nop
  3492. ;    mov    al,[si]        ;@@
  3493. ;    call    outtty        ;@@
  3494. ;    pop    si
  3495. ;    pop    cx
  3496. ;    inc    si
  3497. ;
  3498. ;  check the keyboard by using direct console i/o
  3499. ;  Any key can be used for toggle of screen output.
  3500. ;
  3501. ;    push    dx
  3502. ;    mov    ah,dconio    ; direct console i/o
  3503. ;    mov    dl,0ffh        ; read
  3504. ;    int    dos
  3505. ;    jz    term_tst5
  3506. ;term_tst6:
  3507. ;    mov    ah,dconio
  3508. ;    mov    dl,0ffh
  3509. ;    int    dos
  3510. ;    jz    term_tst6
  3511. ;    cmp    al,CR
  3512. ;    jne    term_tst5
  3513. ;    pop    dx
  3514. ;    jmp    term_tstx
  3515. ;term_tst5:
  3516. ;    pop    dx
  3517. ;
  3518. ;    loop    term_tst4
  3519. ;    jmp    term_tst2
  3520. ;term_tstx:
  3521. ;    mov    ah,3Eh
  3522. ;    mov    bx,playback_hndl
  3523. ;    int    dos
  3524. ;term_tstz:
  3525. ;    and    vt100_flags,NOT LOOPTEST_BIT
  3526. ;    clc
  3527. ;    jmp    term1
  3528.  
  3529. term    endp
  3530.  
  3531. ;; keyboard translator action routines, system dependent, called from msugen.
  3532. ; These are invoked by a jump instruction. Return carry clear for normal
  3533. ; processing, return carry set exit Connect mode (kbdflg has transfer char).
  3534.  
  3535. ; kanji_shiftin sends designation codes for G0 to JIS-C6226.
  3536. ; kanji_shiftout sends designation codes for G0 to JIS-roman.
  3537. ; These routines are called in chrout when JIS-7 is specified.
  3538.  
  3539. kanji_shiftin    proc    near
  3540.     push    ax        ; save ax
  3541.     push    cx
  3542.     push    si
  3543.     mov    cx,KI_len
  3544.     jcxz    kanji_shiftin2
  3545.     mov    si,KI_ofs
  3546. kanji_shiftin1:
  3547.     mov    al,[si]
  3548.     push    si        ; save si and cx.
  3549.     push    cx        ;   these are broken when local echo is on
  3550.     call    outprt
  3551.     pop    cx
  3552.     pop    si
  3553.     inc    si
  3554.     loop    kanji_shiftin1
  3555. kanji_shiftin2:
  3556.     mov    kanji_7smode,1
  3557.     pop    si
  3558.     pop    cx
  3559.     pop    ax
  3560.     ret
  3561. kanji_shiftin    endp
  3562.  
  3563. kanji_shiftout    proc    near
  3564.     push    ax        ; save ax
  3565.     push    cx
  3566.     push    si
  3567.     mov    cx,KO_len
  3568.     jcxz    kanji_shiftout2
  3569.     mov    si,KO_ofs
  3570. kanji_shiftout1:
  3571.     mov    al,[si]
  3572.     push    si        ; save si and cx.
  3573.     push    cx        ;   these are broken when local echo is on
  3574.     call    outprt
  3575.     pop    cx
  3576.     pop    si
  3577.     inc    si
  3578.     loop    kanji_shiftout1
  3579. kanji_shiftout2:
  3580.     mov    kanji_7smode,0
  3581.     pop    si
  3582.     pop    cx
  3583.     pop    ax
  3584.     ret
  3585. kanji_shiftout    endp
  3586.  
  3587. ; chrout is called from KEYBD after key definition translation.
  3588. ; the character is in AL.
  3589.  
  3590. chrout:
  3591.     cmp    kanji_scode,KNJCODE_NONE    ; if kanji is not used,
  3592.     je    chroutx2            ;   no translation
  3593.     cmp    kanji_scode,KNJCODE_SJIS    ; if shift-JIS is used,
  3594.     je    chroutx2            ;   no translation
  3595.     cmp    kanji_smode,0        ; 1st byte ?
  3596.     je    chrout_1        ; e = yes,
  3597.     jmp    chrout_knj2
  3598. chrout_1:
  3599.     call    is_kanji1        ; Kanji code 1st byte ?
  3600.     jnc    chroutx            ; nc = no. ASCII character
  3601.     mov    kanjis1,al
  3602.     mov    kanji_smode,1
  3603.     jmp    chroutxx
  3604. chroutx:
  3605.     cmp    kanji_scode,KNJCODE_JIS7    ; JIS-7 used ?
  3606.     jne    chroutx2        ; ne = no
  3607.     cmp    kanji_7smode,0        ; roman-mode ?
  3608.     je    chroutx2        ; e = yes.
  3609.     cmp    al,DEL            ; BS and DEL can be used in Kanji mode
  3610.     je    chroutx2
  3611.     cmp    al,BS
  3612.     je    chroutx2
  3613.     call    kanji_shiftout
  3614. chroutx2:
  3615.     test    vt100_flags,NEWLINE_BIT    ; newline mode ?
  3616.     jz    chroutx1        ; z = no
  3617.     cmp    al,0Dh            ; CR ?
  3618.     jne    chroutx1        ; ne = no
  3619.     call    outprt            ; send it
  3620.     mov    al,0Ah            ; send LF
  3621. chroutx1:
  3622.     call    outprt                  ; put char in al to serial port
  3623.     mov    kanji_smode,0
  3624. chroutxx:
  3625.         clc                             ; stay in Connect mode
  3626.         ret
  3627.  
  3628. chrout_knj2:
  3629.     mov    ah,al
  3630.     mov    al,kanjis1
  3631.     call    s2jis
  3632.     cmp    kanji_scode,KNJCODE_JIS7    ; JIS-7 used ?
  3633.     je    chrout_knj21            ; e = yes.
  3634.     or    ax,8080h        ; convert to DEC code
  3635.     jmp    chrout_knj22
  3636. chrout_knj21:
  3637.     cmp    kanji_7smode,0        ; roman-mode ?
  3638.     jne    chrout_knj22        ; ne = no.
  3639.     call    kanji_shiftin
  3640. chrout_knj22:
  3641.     mov    kanjis1,ah
  3642.     mov    ah,0
  3643.     call    outprt
  3644.     mov    al,kanjis1
  3645.     jmp    chroutx1
  3646.  
  3647. trnprs:    push    ax            ; toggle Copy screen to printer
  3648.     test    vt100_pflag,(AUTOPRINT_BIT+PRINTCTRL_BIT)
  3649.                     ; are we currently printing?
  3650.     jz    trnpr0            ; z = no, check the printer status
  3651.     and    vt100_pflag,(not (AUTOPRINT_BIT+PRINTCTRL_BIT))
  3652.                     ; clear printer flag
  3653.     jmp    trnpr1            ; and going off
  3654. trnpr0:
  3655.     push    bx
  3656.     mov    bx,prnhand        ; file handle for system printer
  3657.     mov    ah,ioctl
  3658.     mov    al,7            ; get output status of printer
  3659.     int    dos
  3660.     pop    bx
  3661.     jc    trnpr1            ; c = printer not ready
  3662.     cmp    al,0ffh            ; Ready status
  3663.     jne    trnpr3            ; ne = not-Ready    
  3664.     or    vt100_pflag,AUTOPRINT_BIT    ; set the autoprint flag
  3665. trnpr1:    call    set_modlin
  3666.     call    vt100_modlin
  3667. trnpr3:    pop    ax
  3668.     clc                ; return carry clear (don't quit)
  3669.     ret
  3670.  
  3671. prtscn:    call    vt100_prns
  3672.     clc
  3673.     ret
  3674.  
  3675. klogon    proc    near            ; resume logging (if any)
  3676.     test    flags.capflg,logses    ; session logging enabled?
  3677.     jz    klogn            ; z = no, forget it
  3678.         or      vt_ourarg.flgs,capt        ; turn on capture flag
  3679. klogn:  clc
  3680.         ret
  3681. klogon  endp
  3682.  
  3683. klogof  proc    near                    ; suspend logging (if any)
  3684.         and     argadr.flgs,not capt    ; stop capturing
  3685. klogo:  clc
  3686.         ret
  3687. klogof  endp
  3688.  
  3689. uparrw:    mov    al,'A'
  3690.     jmp    short comarr
  3691. dnarrw:    mov    al,'B'
  3692.     jmp    short comarr
  3693. rtarrw:    mov    al,'C'
  3694.     jmp    short comarr
  3695. lfarrw:    mov    al,'D'
  3696. comarr:    push    ax
  3697.     mov    al,ESCAPE        ; [06-July-1990]
  3698.     call    outprt            ; [06-July-1990]
  3699.     cmp    flags.vtflg,ttvt52
  3700.     je    comar2
  3701.     mov    al,'['            ; [06-July-1990]
  3702.     cmp    curkey_mode,0
  3703.     je    comar1
  3704.     mov    al,'O'            ; [06-July-1990]
  3705. comar1:    call    outprt            ; [06-July-1990]
  3706. comar2:
  3707.     pop    ax
  3708.     call    outprt            ; [06-July-1990]
  3709.     clc
  3710.     ret
  3711.  
  3712. pf1:    mov    al,'P'
  3713.     jmp    short compf
  3714. pf2:    mov    al,'Q'
  3715.     jmp    short compf
  3716. pf3:    mov    al,'R'
  3717.     jmp    short compf
  3718. pf4:    mov    al,'S'
  3719. compf:    push    ax
  3720.     mov    al,ESCAPE        ; [06-July-1990]
  3721.     call    outprt            ; [06-July-1990]
  3722.     cmp    flags.vtflg,ttvt52
  3723.     je    compf1
  3724.     mov    al,'O'
  3725.     call    outprt            ; [06-July-1990]
  3726. compf1:
  3727.     pop    ax
  3728.     call    outprt            ; [06-July-1990]
  3729.     clc
  3730.     ret
  3731.  
  3732. kp0:    mov    al,'p'
  3733.     jmp    short comkp
  3734. kp1:    mov    al,'q'
  3735.     jmp    short comkp
  3736. kp2:    mov    al,'r'
  3737.     jmp    short comkp
  3738. kp3:    mov    al,'s'
  3739.     jmp    short comkp
  3740. kp4:    mov    al,'t'
  3741.     jmp    short comkp
  3742. kp5:    mov    al,'u'
  3743.     jmp    short comkp
  3744. kp6:    mov    al,'v'
  3745.     jmp    short comkp
  3746. kp7:    mov    al,'w'
  3747.     jmp    short comkp
  3748. kp8:    mov    al,'x'
  3749.     jmp    short comkp
  3750. kp9:    mov    al,'y'
  3751.     jmp    short comkp
  3752. kpmins:    mov    al,'m'
  3753.     jmp    short comkp
  3754. kpcoma:    mov    al,'l'
  3755.     jmp    short comkp
  3756. kpentr:    mov    al,'M'
  3757.     jmp    short comkp
  3758. kpdot:    mov    al,'n'
  3759.     jmp    short comkp
  3760. comkp:    cmp    keypad_mode,0
  3761.     je    comkp1
  3762.     push    ax
  3763.     mov    al,ESCAPE        ; [06-July-1990]
  3764.     call    outprt            ; [06-July-1990]
  3765.     mov    al,'O'            ; [06-July-1990]
  3766.     cmp    flags.vtflg,ttvt52
  3767.     jne    comkp0
  3768.     mov    al,'?'            ; [06-July-1990]
  3769. comkp0:
  3770.     call    outprt            ; [06-July-1990]
  3771.     pop    ax
  3772.     jmp    short comkp2
  3773. comkp1:    sub    al,40h
  3774. comkp2:
  3775.     call    outprt            ; [06-July-1990]
  3776.     clc
  3777.     ret
  3778.  
  3779. decf6:
  3780. decf7:
  3781. decf8:
  3782. decf9:
  3783. decf10:
  3784. decf11:
  3785. decf12:
  3786. decf13:
  3787. decf14:
  3788. dechelp:
  3789. decdo:
  3790. decf17:
  3791. decf18:
  3792. decf19:
  3793. decf20:
  3794.     jmp    comdec1
  3795. decfind:
  3796.     mov    ah,'1'
  3797.     jmp    comdec
  3798. decinsert:
  3799.     mov    ah,'2'
  3800.     jmp    comdec
  3801. decremove:
  3802.     mov    ah,'3'
  3803.     jmp    comdec
  3804. decselect:
  3805.     mov    ah,'4'
  3806.     jmp    comdec
  3807. decprev:
  3808.     mov    ah,'5'
  3809.     jmp    comdec
  3810. decnext:
  3811.     mov    ah,'6'
  3812. comdec:
  3813.     push    ax
  3814.     mov    ah,ESCAPE
  3815.     call    outchr
  3816.     mov    ah,'['
  3817.     call    outchr
  3818.     pop    ax
  3819.     call    outchr
  3820.     mov    ah,'~'
  3821.     call    outchr
  3822. comdec1:
  3823.     clc
  3824.     ret
  3825.  
  3826. snull:  mov     ah,0                    ; send a null
  3827.         call    outchr                  ; send without echo or logging
  3828.          nop
  3829.          nop
  3830.          nop
  3831.         clc
  3832.         ret
  3833.  
  3834. keyinchg:
  3835.     xor    keyin_dos,1
  3836.     clc
  3837.     ret
  3838.  
  3839. ; change terminal emulator
  3840. ;
  3841. vtchg:
  3842.     cmp    flags.vtflg,ttgenrc    ; no emulation mode?
  3843.     je    vtchg1
  3844.     cmp    flags.vtflg,tttek    ; tek emulation mode?
  3845.     je    vtchgt
  3846.     call    vt100_save
  3847.     jmp    vtchg1
  3848. vtchgt:
  3849.     call    tek4014_save
  3850. vtchg1:
  3851.     cmp    flags.vtflg,ttgenrc
  3852.     jne    vtchg2
  3853.     call    ent_vt
  3854.     mov    flags.vtflg,ttvt52
  3855.     jmp    vtchgx
  3856. vtchg2:
  3857.     cmp    flags.vtflg,ttvt52
  3858.     jne    vtchg3
  3859.     mov    flags.vtflg,ttvt100
  3860.     jmp    vtchgx
  3861. vtchg3:
  3862.     cmp    flags.vtflg,ttvt100
  3863.     jne    vtchg4
  3864.     mov    flags.vtflg,ttvt102
  3865.     jmp    vtchgx
  3866. vtchg4:
  3867.     cmp    flags.vtflg,ttvt102
  3868.     jne    vtchg5
  3869.     call    ent_tk
  3870.     mov    flags.vtflg,tttek
  3871.     jmp    vtchgx
  3872. vtchg5:
  3873.     cmp    flags.vtflg,tttek
  3874.     jne    vtchg6
  3875.     call    ent_vt
  3876.     mov    flags.vtflg,ttgenrc
  3877. vtchg6:
  3878.     mov    flags.vtflg,ttgenrc
  3879. vtchgx:
  3880.     call    set_modlin
  3881.     call    vt100_modlin
  3882.     clc            ; stay in connect mode
  3883.     ret
  3884. ;
  3885. ; reset terminal
  3886. vtreset:
  3887.     cmp    flags.vtflg,ttgenrc
  3888.     je    vtreset2
  3889.     cmp    flags.vtflg,tttek
  3890.     je    vtreset1
  3891.     call    vt100_reset
  3892.     jmp    vtresetx
  3893. vtreset1:
  3894.     call    tek4014_reset
  3895.     jmp    vtresetx
  3896. vtreset2:
  3897. vtresetx:
  3898.     clc
  3899.     ret
  3900.  
  3901. upone:
  3902.     push    ax
  3903.     push    cx
  3904.     call    sense_sftkey
  3905.     test    al,08h        ; GRPH is pressed ?
  3906.     jz    upone_1        ; z=no
  3907.     mov    cx,6
  3908.     call    sixel_rollup
  3909.     jmp    upone_2
  3910. upone_1:
  3911.     mov    cx,1
  3912.     call    vt100_rupn
  3913. upone_2:
  3914.     pop    cx
  3915.     pop    ax
  3916.     clc
  3917.     ret
  3918.  
  3919. dnone:
  3920.     push    ax
  3921.     push    cx
  3922.     call    sense_sftkey
  3923.     test    al,08h        ; GRPH is pressed ?
  3924.     jz    dnone_1
  3925.     mov    cx,6
  3926.     call    sixel_rolldown
  3927.     jmp    dnone_2
  3928. dnone_1:
  3929.     mov    cx,1
  3930.     call    vt100_rdnn
  3931. dnone_2:
  3932.     pop    cx
  3933.     pop    ax
  3934.     clc
  3935.     ret
  3936.  
  3937. upscn:
  3938.     push    cx
  3939.     mov    cx,24
  3940.     call    vt100_rupn
  3941.     pop    cx
  3942.     clc
  3943.     ret
  3944.  
  3945. dnscn:
  3946.     push    cx
  3947.     mov    cx,24
  3948.     call    vt100_rdnn
  3949.     pop    cx
  3950.     clc
  3951.     ret
  3952.  
  3953. gupone:
  3954.     push    cx
  3955.     mov    cx,6
  3956.     call    sixel_rollup
  3957.     pop    cx
  3958.     clc
  3959.     ret
  3960.  
  3961. gdnone:
  3962.     push    cx
  3963.     mov    cx,6
  3964.     call    sixel_rolldown
  3965.     pop    cx
  3966.     clc
  3967.     ret
  3968.  
  3969. kdos:   mov     al,'P'                  ; Push to DOS
  3970.         jmp     short cmdcom
  3971. cstatus:mov     al,'S'                  ; these commands exit Connect mode
  3972.         jmp     short cmdcom
  3973. cquit:  mov     al,'C'
  3974.         jmp     short cmdcom
  3975. cquery: mov     al,'?'
  3976.         jmp     short cmdcom
  3977. chang:  mov     al,'H'                  ; Hangup, drop DTR & RTS
  3978.         jmp     short cmdcom
  3979. trnmod:    mov    al,'M'
  3980.     jmp    short cmdcom
  3981. cmdcom: mov     kbdflg,al               ; pass char to msster.asm via kbdflg
  3982.         stc                             ; say exit Connect mode
  3983.         ret
  3984.                                         ;; end of action routines
  3985. ;
  3986. ; capture routine.
  3987. ; If capture flag is ON, put the character in AL to the file.
  3988. ;
  3989. outcapt    proc    near
  3990.         push    bx
  3991.         mov     bx,argadr               ; args from msster directly
  3992.         test    [bx].flgs,capt          ; capturing output? Can be shut off
  3993.         pop     bx                      ;  if out dev becomes not ready
  3994.         jz      outcapt1        ; no, forget this part
  3995.         push    ax                      ; save char
  3996.         call    captrtn                 ; give it captured character
  3997.         pop     ax                      ; restore character and keep going
  3998. outcapt1:
  3999.     ret
  4000. outcapt    endp
  4001.  
  4002. ;
  4003. ; Dumb terminal emulator. AL is the character to be displayed.
  4004. ; Taken from MSXGEN.ASM .
  4005. ;
  4006. dumbterm    proc    near
  4007.     cmp    vt100_lflag,(LOGCOOK_BIT+LOGENAB_BIT)    ; is cooked logging ?
  4008.     jne    dumbterm1        ; ne = no.
  4009.     call    outcapt
  4010. dumbterm1:
  4011.     test    vt100_pflag,AUTOPRINT_BIT    ; should we be printing?
  4012.     jz    dumbterm2        ; no, keep going
  4013.         push    ax
  4014.         mov     ah,LSTOUT        ; write to system printer device
  4015.         mov     dl,al
  4016.         int     dos
  4017.         pop     ax
  4018.         jnc     dumbterm2        ; nc = successful print
  4019.         push    ax
  4020.         call    beep                    ; else make a noise and
  4021.         call    trnprs                  ;  turn off printing
  4022.         pop     ax
  4023. dumbterm2:
  4024.     test    vt_ourarg.flgs,trnctl      ; debug? if so use dos tty mode
  4025.         jz      dumbterm8        ; z = no
  4026.         mov     ah,conout
  4027.         cmp     al,7fh                  ; Ascii Del char or greater?
  4028.         jb    dumbterm4        ; b = no
  4029.         je    dumbterm3        ; e = Del char
  4030.         push    ax                      ; save the char
  4031.         mov     dl,7eh                  ; output a tilde for 8th bit
  4032.         int     dos
  4033.         pop     ax                      ; restore char
  4034.         and     al,7fh                  ; strip high bit
  4035. dumbterm3:
  4036.     cmp     al,7fh                  ; is char now a DEL?
  4037.         jne    dumbterm4        ; ne = no
  4038.         and     al,3fH            ; strip next highest bit (Del --> '?')
  4039.         jmp    dumbterm5        ; send, preceded by caret
  4040. dumbterm4:
  4041.     cmp     al,' '                  ; control char?
  4042.         jae    dumbterm6        ; ae = no
  4043.         add     al,'A'-1                ; make visible
  4044. dumbterm5:
  4045.     push    ax                      ; save char
  4046.         mov     dl,5eh                  ; caret
  4047.         int     dos                     ; display it
  4048.         pop     ax                      ; recover the non-printable char
  4049. dumbterm6:
  4050.     mov     dl,al
  4051.         int     dos
  4052.         ret
  4053. dumbterm7:
  4054.     test    flags.remflg,d8bit      ; keep 8 bits for displays?
  4055.         jnz     dumbterm8        ; nz = yes, 8 bits if possible
  4056.         and     al,7fh                  ; remove high bit
  4057. dumbterm8:
  4058.     mov     ah,conout               ; dostty screen mode
  4059.         mov     dl,al                   ; write without intervention
  4060.         int     dos                     ; else let dos display char
  4061.         ret                             ; and return
  4062. dumbterm    endp
  4063.  
  4064.  
  4065. ; put the character in al to the screen, do capture and printing,
  4066. ; does translation for Set Input command.
  4067. ; Adapted from msyibm.asm [jrd]
  4068.  
  4069. outtty  proc    near
  4070.         test    flags.remflg,d8bit      ; keep 8 bits for displays?
  4071.         jnz     outnp8                  ; nz = yes, 8 bits if possible
  4072.         and     al,7fh                  ; remove high bit
  4073. outnp8:
  4074.     cmp    vt100_lflag,LOGENAB_BIT    ; raw mode logging ?
  4075.     jne    outtty_lg1        ; ne = no.
  4076.     call    outcapt            ; log it
  4077. outtty_lg1:
  4078.         cmp     rxtable+256,0           ; is translation off?
  4079.         je      outtty_knj0        ; e = yes, off
  4080.         push    bx                      ; Translate incoming char
  4081.         mov     bx,offset rxtable       ; address of translate table
  4082.         xlatb                           ; new char is in al
  4083.         pop     bx
  4084. ;
  4085. ; Kanji test. If kanji is used for receiving characters,
  4086. ; do translation for capture file, printer and display.
  4087. ; The capture file and printer use shift-JIS. On the other hand,
  4088. ; VT100 emulator ueses DEC (extended UNIX - JIS-8) code.
  4089. ;
  4090. outtty_knj0:
  4091.     cmp    kanji_rcode,KNJCODE_NONE    ; Kanji code used ?
  4092.     je    outtty_knj2        ; e = no, no translation
  4093.     cmp    kanji_rcode,KNJCODE_DEC        ; DEC (EUC) code ?
  4094.     jne    outtty_knj1        ; ne = no
  4095.     jmp    outtty_dknj0        ; jump to DEC kanji processor
  4096. outtty_knj1:
  4097.     cmp    kanji_rcode,KNJCODE_SJIS    ; Shift-JIS code ?
  4098.     jne    outtty_knj2        ; ne = no
  4099.     jmp    outtty_sknj0        ; jump to Shift-JIS process
  4100. outtty_knj2:
  4101.     jmp    outtty_trm
  4102. ;
  4103. outtty_dknj0:
  4104.     cmp    flags.vtflg,0        ; dumb terminal ?
  4105.     je    outtty_dknj1        ; e = Yes. Needs code conversion.
  4106.     jmp    outtty_trm1
  4107. outtty_dknj1:
  4108.         cmp    kanji_rmode,0        ; 2-byte code in progress ?
  4109.     je    outtty_dknj2        ; e = No, not in progress.
  4110.     mov    kanjir2,al        ; put 2nd byte
  4111.     mov    ah,al            ; prepare to conversion
  4112.     mov    al,kanjir1        ; put 1st byte
  4113.     cmp    al,08Eh            ; SS2 ?
  4114.     jne    outtty_dknj5        ; ne = No.
  4115.     mov    al,kanjir2        ; get 2nd byte
  4116.     jmp    outtty_dknj3
  4117. outtty_dknj5:
  4118.     and    ax,7f7fh        ; mask 8-th bits
  4119.     call    jis2s            ; convert to Shift-JIS
  4120.     xchg    kanjir1,al        ; save the 2byte code
  4121.     xchg    kanjir2,ah
  4122.     mov    kanjio1,ah
  4123.     mov    al,kanjir1
  4124.     call    dumbterm
  4125.     mov    al,kanjir2
  4126.     jmp    outtty_dknj3
  4127. outtty_dknj2:
  4128.     cmp    al,08Eh            ; SS2 ?
  4129.     je    outtty_dknj4        ; e = Yes.
  4130.     cmp    al,0A0h            ; is Kanji ?
  4131.     jbe    outtty_dknj3        ; z = No.
  4132. outtty_dknj4:
  4133.     mov    kanji_rmode,1        ; set multi-byte flag
  4134.     mov    kanjio1,al        ; save 1st byte
  4135.     mov    kanjir1,al
  4136.     ret
  4137. outtty_dknj3:
  4138.     call    dumbterm
  4139.     mov    kanji_rmode,0
  4140.     ret
  4141. ;
  4142. outtty_sknj0:
  4143. outtty_sknj2:
  4144.     cmp     flags.vtflg,0           ; emulating a terminal?
  4145.         jnz    outtty_sknj3        ; nz = yup, go do something smart
  4146.     call    dumbterm        ; dumb terminal emulation
  4147.     ret
  4148. outtty_sknj3:
  4149.     cmp    kanji_rmode,0        ; is it 1st byte character?
  4150.     je    outtty_sknj4        ; e = yes.
  4151.     mov    kanjio2,al        ; put 2nd byte
  4152.     mov    ah,al            ; prepare to conversion
  4153.     mov    al,kanjio1        ; put 1st byte
  4154.     call    s2jis            ; convert to JIS
  4155.     or    ax,8080h        ; use GR set
  4156.     xchg    kanjio1,al        ; save the 2byte code
  4157.     xchg    kanjio2,ah
  4158.     mov    kanjir1,ah
  4159.     jmp    outtty_trm1
  4160. outtty_sknj4:
  4161.     call    is_kanji1        ; check if kanji
  4162.     jc    outtty_sknj6        ; c = Yes.
  4163.     test    al,80h            ; katakana ?
  4164.     jz    outtty_sknj5        ; z = No.
  4165.     mov    kanji_rmode,1        ; set multi-byte flag
  4166.     mov    kanjio1,08Eh        ; SS2 code
  4167.     mov    kanjio2,al        ; extended UNIX convention
  4168. outtty_sknj5:
  4169.     jmp    outtty_trm1
  4170. outtty_sknj6:
  4171.     mov    kanji_rmode,1
  4172.     mov    kanjir1,al
  4173.     mov    kanjio1,al
  4174.     ret
  4175. ;
  4176. outtty_trm:
  4177.     cmp    flags.vtflg,0
  4178.     jne    outtty_trm1
  4179.     call    dumbterm
  4180.     ret
  4181. outtty_trm1:
  4182.     cmp    flags.vtflg,tttek
  4183.     je    outtty_tk
  4184. ;
  4185. outtty_vt:
  4186. outtty_vt1:
  4187.     cmp    kanji_rmode,0
  4188.     je    outtty_vt3
  4189. outtty_vt2:
  4190.     mov    al,kanjio1
  4191.     call    vt100
  4192.     mov    al,kanjio2
  4193. outtty_vt3:
  4194.     call    vt100
  4195. ;
  4196.     cmp    ah,0
  4197.     jne    outtty_vt4
  4198.     jmp    outtty_snd
  4199. outtty_vt4:
  4200.     push    ax
  4201.     push    dx
  4202. ;;@@    call    vt100_save
  4203.     mov    flags.vtflg,tttek
  4204.     call    ent_tk
  4205.     pop    dx
  4206.     pop    ax
  4207.     cmp    ah,2
  4208.     je    outtty_tk3
  4209.     cmp    ah,3
  4210.     jne    outtty_vt5
  4211.     mov    kanjio1,dh
  4212.     mov    kanjio2,dl
  4213.     jmp    outtty_tk2
  4214. outtty_vt5:
  4215.     jmp    outtty_snd_ex
  4216.  
  4217. outtty_tk:
  4218. outtty_tk1:
  4219.     cmp    kanji_rmode,0
  4220.     je    outtty_tk3
  4221. outtty_tk2:
  4222.     mov    al,kanjio1
  4223.     call    tek4014
  4224.     jnc    outtty_tk2_2
  4225.     jcxz    outtty_tk2_2
  4226. outtty_tk2_1:
  4227.     lodsb
  4228.     push    cx
  4229.     push    si
  4230.     call    vt100
  4231.     pop    si
  4232.     pop    cx
  4233.     loop    outtty_tk2_1
  4234. outtty_tk2_2:
  4235.     mov    al,kanjio2
  4236. outtty_tk3:
  4237.     call    tek4014
  4238.     jnc    outtty_tk3_2
  4239.     jcxz    outtty_tk3_2
  4240. outtty_tk3_1:
  4241.     lodsb
  4242.     push    cx
  4243.     push    si
  4244.     call    vt100
  4245.     pop    si
  4246.     pop    cx
  4247.     loop    outtty_tk3_1
  4248. outtty_tk3_2:
  4249. ;
  4250.     cmp    ah,0
  4251.     jne    outtty_tk4
  4252.     jmp    outtty_snd
  4253. outtty_tk4:
  4254.     push    ax
  4255.     push    dx
  4256. ;;@@    call    tek4014_save
  4257.     mov    flags.vtflg,ttvt102
  4258.     call    ent_vt
  4259.     pop    dx
  4260.     pop    ax
  4261.     cmp    ah,2
  4262.     je    outtty_vt3
  4263.     cmp    ah,3
  4264.     jne    outtty_tk5
  4265.     mov    kanjio1,dh
  4266.     mov    kanjio2,dl
  4267.     jmp    outtty_vt2
  4268. outtty_tk5:
  4269.     jmp    outtty_snd_ex
  4270. ;
  4271. outtty_snd:
  4272.     mov    kanji_rmode,0
  4273.     jcxz    outtty_snd_ex        ; If there is no answer-back, return
  4274. outtty_snd1:
  4275.     mov    ah,[si]
  4276.     call    outchr            ; send character without echo
  4277.      nop
  4278.      nop
  4279.      nop
  4280.     inc    si
  4281.     loop    outtty_snd1
  4282. outtty_snd_ex:
  4283.     ret
  4284.  
  4285. outtty  endp
  4286.  
  4287. ; send the character in al out to the serial port; handle echoing.
  4288. ; Can send an 8 bit char while displaying only 7 bits locally.
  4289. outprt  proc    near
  4290.         test    yflags,lclecho        ; echoing?
  4291.         jz      outpr1                  ; z = no, forget it
  4292.         push    ax                      ; save char
  4293.         call    outtty                  ; print it
  4294.         pop     ax                      ; restore
  4295. outpr1: mov     ah,al                   ; this is where outchr expects it
  4296.         call    outchr                  ; output to the port
  4297.         ret
  4298. outprt  endp
  4299.  
  4300. pntdead    proc    near            ; display printer is inoperative msg
  4301.     push    ax
  4302.     test    vt_ourarg.flgs,modoff    ; mode line off?
  4303.     jnz    pntdea1            ; nz = off, skip msg
  4304.     push    bx
  4305.     mov    dx,offset pntmsg    ; say printer not ready
  4306.     call    putmod            ; write on mode line
  4307.     pop    bx
  4308. pntdea1:pop    ax
  4309.     stc                ; say printer not ready
  4310.     ret
  4311. pntdead    endp
  4312.  
  4313.  
  4314. ; Get a char from the serial port manager
  4315. ; returns with carry clear if a character is available
  4316. portchr proc    near
  4317.         call    prtchr                  ; character at port?
  4318.         jc    portc2            ; no character
  4319.     and     al,parmsk               ; apply 8/7 bit parity mask
  4320.         or      al,al                   ; catch nulls
  4321.         jnz    portc2            ; nz = non null
  4322.         stc                ; ignore null
  4323. portc2: ret
  4324. portchr endp
  4325.  
  4326. ; Jump here to exit Connect mode and execute macros 'TERMINALR' (vtrmac) or
  4327. ; 'TERMINALS' (vtsmac). Does nothing if macro does not exist.
  4328. ; Preserves registers except ax. Returns to TELNET caller with 'C' in kbdflg.
  4329. vtrmac    proc    near            ; RESET macro
  4330.     mov    vtmacname,offset vtrname ; select macro name
  4331.     mov    vtmaclen,vtrlen        ; and its length
  4332.     jmp    vtmacro
  4333. vtrmac    endp
  4334.  
  4335. vtsmac    proc    near            ; SET macro
  4336.     mov    vtmacname,offset vtsname
  4337.     mov    vtmaclen,vtslen
  4338.     jmp    vtmacro
  4339. vtsmac    endp
  4340.  
  4341. ; Invoked by keyboard translator when an unknown keyboard verb is used as
  4342. ; a string definition, such as {\ktest}. Enter with vtmacname pointing to
  4343. ; uppercased verb name, asciiz, and vtmaclen set to its length.
  4344. extmacro proc    near
  4345.     jmp    vtmacro
  4346. extmacro endp
  4347.  
  4348. ;
  4349. ; Reference    Macro structure for    db    number of entries (mac names)
  4350. ;  is file     table mcctab       |->    db    length of macroname, excl '$'
  4351. ;  mssset.asm        each entry |->     db    'macroname','$'
  4352. ;  where these               |->    dw    segment:0 of definition string
  4353. ;  are stored.                      (offset part is always 0)    
  4354. ;        Definition string in     db    length of <string with null>
  4355. ;         buffer macbuf          db    'string with trailing null'
  4356. ;
  4357. vtmacro    proc    far            ; common code for macros vtsmac,vtrmac
  4358.     push    bx            ; and Product
  4359.     push    cx
  4360.     push    si
  4361.     push    di
  4362.     push    es
  4363.     mov    ax,ds
  4364.     mov    es,ax
  4365.     mov    di,offset rdbuf+1    ; macro def buffer starts here
  4366.     mov    si,vtmacname        ; pointer to macro name
  4367.     mov    cl,vtmaclen        ; length of macro name<sp/null>text
  4368.     xor    ch,ch
  4369.     mov    [di-1],cl        ; counted string field
  4370.     cld
  4371.     rep    movsb            ; copy to rdbuf
  4372.     mov    byte ptr [di],0        ; null terminator
  4373.     mov    si,offset rdbuf+1    ; look for name-text separator
  4374.     mov    cl,vtmaclen
  4375.     xor    ch,ch
  4376. vtmac1:    lodsb
  4377.     cmp    al,' '            ; space separator?
  4378.     je    vtmac1a            ; e = yes, stop here
  4379.     or    al,al            ; null terminator?
  4380.     jz    vtmac1a            ; e = yes, stop here
  4381.     loop    vtmac1
  4382.     inc    si            ; to do null lenght correctly
  4383. vtmac1a:sub    si,offset rdbuf+1+1    ; compute length of macro name
  4384.     mov    cx,si
  4385.     mov    vtmaclen,cl        ; save a macro name length
  4386.                     ; check for existence of macro
  4387.     mov    bx,offset mcctab    ; table of macro names
  4388.     mov    cl,[bx]            ; number of names in table
  4389.     xor    ch,ch
  4390.     jcxz    vtmacx            ; z = empty table, do nothing
  4391.     inc    bx            ; point to length of first name
  4392. vtmac2:    mov    al,[bx]            ; length of this name
  4393.     xor    ah,ah
  4394.     cmp    al,vtmaclen        ; length same as desired keyword?
  4395.     jne    vtmac3            ; ne = no, search again
  4396.     mov    si,bx
  4397.     inc    si            ; point at first char of name
  4398.     push    cx            ; save name counter
  4399.     push    di            ; save reg
  4400.     mov    cl,vtmaclen        ; length of name, excluding '$'
  4401.     xor    ch,ch
  4402.     mov    di,vtmacname        ; point at desired macro name
  4403.     push    es            ; save reg
  4404.     push    ds
  4405.     pop    es            ; make es use data segment
  4406.     cld
  4407.     repe    cmpsb            ; match strings
  4408.     pop    es            ; need current si below
  4409.     pop    cx
  4410.     pop    di            ; recover saved regs
  4411.     je    vtmac4            ; e = matched
  4412. vtmac3:    add    bx,ax            ; step to next name, add name length
  4413.     add    bx,4            ; + count, dollar sign, def word ptr
  4414.     loop    vtmac2            ; try next name
  4415. vtmacx:    pop    es
  4416.     pop    di
  4417.     pop    si            ; no macro, return to Connect mode
  4418.     pop    cx
  4419.     pop    bx
  4420.     ret
  4421.  
  4422. vtmac4:    cmp    taklev,maxtak        ; room in Take level?
  4423.     jge    vtmacx            ; ge = no, exit with no action
  4424.     inc    taklev            ; increment take level
  4425.     add    takadr,size takinfo    ; make a new Take entry/macro
  4426.     mov    bx,takadr        ; point to current macro structure
  4427.     mov    ax,ds            ; segment of rdbuf
  4428.     mov    [bx].takbuf,ax        ; segment of definition string struc
  4429.     mov    cl,rdbuf        ; length of whole string
  4430.     xor    ch,ch
  4431.     mov    [bx].takcnt,cx        ; number of chars in definition
  4432.     mov    [bx].takargc,0        ; our argument count
  4433.     mov    [bx].takptr,offset rdbuf+1 ; where to read next command char
  4434.     mov    [bx].taktyp,0ffh    ; flag as a macro
  4435.     pop    es
  4436.     pop    di
  4437.     pop    si
  4438.     pop    cx
  4439.     pop    bx
  4440.     jmp    endcon            ; exit Connect mode
  4441. vtmacro    endp
  4442.  
  4443. ; Error recovery routine used when outchr reports unable to send character
  4444. ;  or when vtmacro requests exiting Connect mode.
  4445. ; Exit Connect mode cleanly, despite layers of intermediate calls.
  4446. endcon    proc    near
  4447.     mov    kbdflg,'C'        ; report 'C' to TERM's caller
  4448.     mov    sp,oldsp        ; recover startup stack pointer
  4449.                     ; TERM caller's return address is now
  4450.                     ; on the top of stack. A longjmp.
  4451.     jmp    quit            ; exit Connect mode cleanly
  4452. endcon    endp
  4453. code    ends
  4454.         end
  4455.