home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msxap3.asm < prev    next >
Assembly Source File  |  2020-01-01  |  73KB  |  1,726 lines

  1.        NAME    msxap3
  2.        Page    60,132
  3.  
  4. ; Last edit: 14 March 1988
  5. ; NEC APCIII Edit History
  6.  
  7. ;       RFGoeke, MIT Center for Space Research, 627-253-1910
  8. ;       Goeke @ SPACE.MIT.EDU
  9.  
  10. ; 14 March 1988                Rev. a for V2.30
  11. ;    Minor patches to get compatible with released IBM V2.30
  12. ;    Major shuffle to get text lined up with msxibm so diff will work
  13. ;    Change "esc" to "escape"; add shomodem and termtb; add vtemu.vtflgop
  14. ; 6 October 1987                             Rev.  F
  15. ;       Recreate SERRST to turn off all ports; called by mssker when exiting;
  16. ;       keeps incoming characters on unwatched line from bombing system.
  17. ;       NB this is also called by mssrcv, mssscp, ssssen, and msster !!!
  18. ;       so one has to keep the modem status lines ON at all times.
  19. ;       Also increased Hangup DTR drop to 2 seconds; recalibrated pcwait.
  20. ; 8 July 1987                                Rev.  E
  21. ;       Minor fix ups to keep pace with v/2.29C development; recalibrated
  22. ;       timer code in pcwait.
  23. ; 5 November 1986                            Rev.  D
  24. ;       Major bug in serini fixed (characters in unaddressed ports were
  25. ;       coming through and corrupting DOS
  26. ; 14 October 1986                            Rev.  B
  27. ;       Modified to work with [2.29a] code.
  28. ; 21 August 1986                             Rev.  N
  29. ;       Modified from the [2.29] code for msxibm
  30. ;       with help from the RAL Version 2.0.
  31.  
  32. ; General considerations:
  33. ;       The presence of ANSI.SYS in the booted CONFIG.SYS file is assumed.
  34. ;       If ports 2 or 3 are to be used, OPTRS232.SYS is required in CONFIG.SYS
  35. ;       References to modems have also been deleted.
  36.  
  37. ; Bugs found:
  38. ;       The NEC BIOS call to the screen (19H) tends to wipe out the SI
  39. ;               register; a lot of push/pops have been added for this reason.
  40. ;       The RS232 BIOS call miscalculates the end of the circular receive
  41. ;               buffer by 20 bytes (see comments in SERINI).
  42.  
  43. ; (The following comments are from msxibm.asm; not all apply here!)
  44. ; 1 Jan 1988 version 2.30
  45. ; 24 Dec 1987 Revise selection of COM1 to use COM1 name but COM2 addresses
  46. ;  if base address of 02f8 (COM2) is found in 40:00h and display notice.
  47. ;  Restore state of IRQ interrupt line when finished with serial port. [jrd]
  48. ; 31 Oct 1987 Add terminal type Tek4010, with Tek submode Tekflg. [jrd]
  49. ; 24 Oct 1987 Enhance clrbuf to empty any intermediate (net) buffers. [jrd]
  50. ; 19 Oct 1987 Fix stray tab-set at column 32. [jrd]
  51. ; 2 Oct 1987 Add PCjr baud rate table, from Ted Medin. [jrd]
  52. ; 6 Sept 1987 Allow serial port serint to send xoff when buffer fills even
  53. ;  though user may have sent xoff by hand. [jrd]
  54. ; 27 Aug 1987 Skip timeout test in OUTCHR if receive timeout is zero. [jrd]
  55. ; 23 August 1987 Add vtemu.vtflgop to hold runtime terminal settings so that
  56. ;  a reset command restores them to the Setup values, vtemu.vtflgst. Show
  57. ;  displays the vtemu.vtflgop operational values. [jrd]
  58. ; 17 August 1987 Make timing adjustments for Token Passing and single buffered
  59. ;  network adapter boards. Byte netdbfr indicates presence of double buffering;
  60. ;  it is set in chknet as a vendor option. To test your boards force dbl buf
  61. ;  then look for missing 256 byte parts of long packets sent out; missing parts
  62. ;  mean new material overwrote not-yet-sent old == single buffering. [jrd]
  63. ; 8 August 1987 Add interrupt chaining in serint. [jrd]
  64. ; 23 July 1987 Clear xofsnt and xofrcv xon/xoff flags in ihost(s/r). [jrd]
  65. ; 9 July 1987 Cure confusion about COM1/2 for IBM PCjr (address of regular
  66. ;  COM2 in 40:0h slot for COM1) with info from John Neufeld. [jrd]
  67. ; 2 July 1987 Route NetBios cancels through separate scb for systems, such
  68. ;  as Novell NetWare, which object to having active scbs touched. [jrd]
  69. ; 25 June 1987 Add trapping of Int 14H (Bios RS232 procedure) to allow
  70. ;  CTTY command to function without too much inteference from DOS. [jrd]
  71. ; 17 June 1987 Enlarge tab setting to full 132 columns at all times. [jrd]
  72. ; 11 June 1987 Add Set Term Roll on/off to control auto roll back of screen
  73. ;  when new characters are displayed; default is off (no unwinding). [jrd]
  74. ; 20 May 1987 Remove rejection of NULL and DEL chars, let callers do it. [jrd]
  75. ; 16 May 1987 Add distinction between user typed and receiver threshold
  76. ;  controlled sending of XOFF. User level overrides buffer control.[jrd]
  77. ;  Add COM3 and COM4 support: examine memory 40:00h->40:07h for selected
  78. ;  port COM1..4, resp. If word is null then set flags.comflg to 0 to say
  79. ;  undefined port. Otherwise, use that word in seg 40h as base of UART i/o
  80. ;  ports. Assume IRQ4 for COM1 and COM3 (same except for port addresses)
  81. ;  and IRQ4 for  COM2 and COM4 (again, same except for port addresses).
  82. ;  Serial port info sturcture (not values) assumed identical for all ports.
  83. ; 25 April 1987 Add Netbios compatible local area network support. [jrd]
  84. ;  Set Port command expanded to syntax SET PORT NET nodename. Use nodename
  85. ;  if acting as a client to named remote node, leave blank if running in
  86. ;  Server mode. Byte 'ttyact' is controlled by msster.asm to indicate Connect
  87. ;  mode is being used. Byte 'netdone' (stored in mssker.asm) holds offset of
  88. ;  network hangup procedure 'netclose' to be done when leaving Kermit. Hangup
  89. ;  command extended to to network hangup as well. Network uses IBM Netbios
  90. ;  standard calls (Int 5Ch) and allows for extensions of AT&T STARLAN for
  91. ;  longer node names via Int 2Bh (the later is tested before use). Virtual
  92. ;  circuits are employed. The Redirector is not necessary. Kermit can operate
  93. ;  as either a terminal (does a CALL at Connect mode startup), a file receiver
  94. ;  (does a CALL at startup), or a Kermit server (does an anonomous LISTEN at
  95. ;  startup, hence no nodename). Clients should Set Timer Off.
  96. ; 16 April 1987 Add measurement and correction of software timer pcwait. [jrd]
  97. ; 5 April 1987 Keep DTR & RTS low for 1/2 second in serhng, suggested by
  98. ;  Jack Bryans. [jrd]
  99. ; 28 March 1987 Reference screen coord wrt low_rgt from msyibm, let number
  100. ;  of tabs be full screen width. [jrd]
  101. ; 22 March 1987 Fix bug in pcwait code, from Stefan Vogel. [jrd]
  102. ; 6 March 1987 Make PCWAIT a global procedure, add SENDBL to send Long
  103. ;  Break. [jrd]
  104. ; 21 Feb 1987 Merge operations for semi-clone machines (those identical to
  105. ;  IBM PC's except the serial port must be accessed via the Bios rather than
  106. ;  from the real UART hardware). Ports automatically checked for 8250. [jrd]
  107. ; 1 Oct 1986 Version 2.29a
  108. ; 30 Sept 1986 Reject DEL char at serial port reception level to avoid
  109. ;  problems when DEL is used as a filler char (by Emacs). [jrd]
  110. ; 4 Sept 1986 Add Bob Goeke's change to move comms port table to a system
  111. ;  dependent module (typ msx---) to allow 3+ ports and localized idents. [jrd]
  112. ; 26 August 1986 Use parity mask when testing for nulls & Xon/Xoff in serial
  113. ;  port interrupt routine. [jrd]
  114. ; 16 August 1986 Use observed screen attributes for mode line. [jrd]
  115. ; 9 August 1986 Revise SERINT to insert control-G for overrun chars, give
  116. ;  faster return of interrupts to system, remove use of BP in code. [jrd]
  117. ; 17 July 1986 Minor clean up of Terminal Status display routine. [jrd]
  118. ; 22 June 1986 Leave 8250 UART signal OUT1 low to avoid resetting Hayes
  119. ;  1200B modems (thanks to Neil Rickert). [jrd]
  120. ;  Skip sending null byte in ihosts and ihostr (thanks to Skip Russell). [jrd]
  121. ; 22 May 1986 Rewrite serial port interrupt procedure and proc prtchr
  122. ;  to avoid lockups with interrupts disabled, buffer corruption, and to
  123. ;  minimize lost clock interrupts. Flow control not needed at 9600 baud,
  124. ;  slow screen refresh, VT102 emulation, on a 4.77 MHz IBM PC clone.
  125. ;  Added buffer low water mark to give more xon/xoff hysterisis. [jrd]
  126. ; [2.29] code frozen on 6 May 1986 [jrd]
  127. ; Note -
  128. ; When the Bios is used for serial port i/o the modem signals DSR and CTS
  129. ; must be asserted low before the Bios will access the hardware. Jumpers
  130. ; from pin 20 (DTR) to pin 6 (DSR) and from pin 4 (RTS) to pin 5 (CTS)
  131. ; will probably be necessary.
  132. ;       From Glenn Everhart (who suggested using the Bios alternative)
  133. ;
  134.         public  serini, serrst, clrbuf, outchr, coms, vts, vtstat
  135.         public  dodel, ctlu, cmblnk, locate, prtchr, dobaud, clearl
  136.         public  dodisk, getbaud, beep, termtb, shomodem
  137.         public  count, xofsnt, puthlp, putmod, clrmod, poscur
  138.         public  sendbr, sendbl, machnam, setktab, setkhlp, lclini, showkey
  139.         public  ihosts, ihostr, dtrlow, serhng, comptab, pcwait
  140.         include mssdef.h
  141.  
  142. false   equ     0
  143. true    equ     1
  144.  
  145. ; the following sets the text attributes                        RFG
  146.  
  147. att_low_mask    equ     1FH             ; Various attribute-related equates
  148. att_overline    equ     01H             ; this is all NEC version stuff RFG
  149. att_blink       equ     02H
  150. att_rev_video   equ     04H
  151. att_underline   equ     08H
  152. att_intensity   equ     att_rev_video
  153.  
  154. nec_black       equ     00H             ; This table gives colors       RFG
  155. nec_blue        equ     20H             ; (only bits 8,7,6 count)
  156. nec_red         equ     40H
  157. nec_magenta     equ     60H
  158. nec_green       equ     80H
  159. nec_cyan        equ     0A0H
  160. nec_yellow      equ     0C0H
  161. nec_white       equ     0E0H
  162.  
  163. ; constants used by serial port handler
  164.  
  165. KEYB    EQU     18H             ;       RFG
  166. BIOS    EQU     19H             ;       RFG
  167. ; external variables used:
  168. ; drives - # of disk drives on system
  169. ; flags - global flags as per flginfo structure defined in pcdefs
  170. ; trans - global transmission parameters, trinfo struct defined in pcdefs
  171. ; portval - pointer to current portinfo structure (currently either port1
  172. ;    or port2)
  173. ; port1, port2 - portinfo structures for the corresponding ports
  174. ; low_rgt - low byte = last column (typ 79), high byte = last text row
  175. ;  (typ 23) in screen coordinates (start at 0), set by msyibm.
  176.  
  177. ; global variables defined in this module:
  178. ; xofsnt, xofrcv - tell whether we saw or sent an xoff.
  179. ; setktab - keyword table for redefining keys (should contain a 0 if
  180. ;    not implemented)
  181. ; setkhlp - help for setktab.
  182.  
  183. datas   segment public 'datas'
  184.         extrn   drives:byte, flags:byte, trans:byte, ttyact:byte
  185.         extrn   portval:word, port1:byte, port2:byte, port3:byte, port4:byte
  186.         extrn   netdone:word, pcnet:byte
  187.         extrn   refresh:byte, scbattr:byte, low_rgt:word, vtemu:byte
  188.         extrn   vtroll:byte, tekflg:byte
  189.  
  190. ; structure for status information table sttab.
  191. stent   struc
  192. sttyp   dw      ?               ; type (actually routine to call)
  193. msg     dw      ?               ; message to print
  194. val2    dw      ?               ; needed value: another message, or tbl addr
  195. tstcel  dw      ?               ; address of cell to test, in data segment
  196. basval  dw      0               ; base value, if non-zero
  197. stent   ends
  198.  
  199. setktab db      0               ; superceded by msuibm code, return 0 here
  200. setkhlp db      '$'             ; and add empty help string
  201.  
  202. savsci  dd      ?               ; old serial port interrupt vector.
  203. sav232  dd      ?               ; Original Bios Int 14H address, in Code seg.
  204. savirq  db      ?               ; Original Interrupt mask for IRQ
  205. ; brkval  db      BRKBIT          ; What to send for a break.
  206. brkadr  dw      0               ; Where to send it.
  207. modem   mdminfo <>
  208. hngmsg  db      cr,lf,' The phone or network connection should have hungup.'
  209.         db      cr,lf,'$'
  210. nohngmsg db     cr,lf,' Command ineffective on this port.',cr,lf,'$'
  211. hnghlp  db      cr,lf,' The modem control lines DTR and RTS for the current'
  212.         db      ' port are forced low (off)'
  213.         db      cr,lf,' to hangup the phone. Normally, Kermit leaves them'
  214.         db      ' high (on) when it exits.',cr,lf
  215.         db      ' For networks, the active session is terminated.',cr,lf,'$'
  216. erms40  db      cr,lf,'?Warning: Unrecognized baud rate',cr,lf,'$'
  217. badbd   db      cr,lf,'Unimplemented baud rate$'
  218. prterr  db      '?Unrecognized value$'
  219. badprt  db      cr,lf,' Serial port COM$'
  220. badprt2 db      ' is not available.$'
  221. badprt3 db      cr,lf,' Notice: Port COM1 uses hardware addresses of COM2'
  222.         db      ' (safe).',cr,lf,'$'
  223. biosmsg db      cr,lf,'This port operates through the Bios',cr,lf,'$'
  224. msmsg1  db      cr,lf,' Modem is not ready: DSR is off$'
  225. msmsg2  db      cr,lf,' Modem is ready:     DSR is on$'
  226. msmsg3  db      cr,lf,' no Carrier Detect:  CD  is off$'
  227. msmsg4  db      cr,lf,' Carrier Detect:     CD  is on$'
  228. msmsg5  db      cr,lf,' no Clear To Send:   CTS is off$'
  229. msmsg6  db      cr,lf,' Clear To Send:      CTS is on$'
  230.  
  231. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; NEC Specific data follows
  232. machnam db      'NEC APC III (a)$'
  233. First   db      true            ; used in getbaud
  234. source  db      20 DUP(?)       ; Buffer for data from port; see comments
  235.         db      bufsiz DUP(?)   ;    in serini for why this must be bufsiz+20
  236. uart    db      01001110B        ; set up various parameters....
  237. ;                | | | |
  238. ;                | | | +--- Clock 10 x16, 11 x64
  239. ;                | | +----- Word Length 00 5, 01 6,10 7, 11 8
  240. ;                | +------- Parity 00 None, 01 Odd, 11 Even
  241. ;                +--------- Stop Bits 01 1, 10 1.5, 11 2
  242. stnorm  db      00100111B       ; This will be CL for serini, normally  RFG
  243. stbrk   db      00101111B       ; This will send a break from serini    RFG
  244. stdtr   db      00000101B       ; This will drop the DTR and RTS line   RFG
  245. stoff   db      00100010B       ; This kills send and receive enable    RFG
  246. ;                ||||||+--- Send enable
  247. ;                |||||+---- DTR on
  248. ;                ||||+----- Receive enable
  249. ;                |||+------ Force spacing on output (for break)
  250. ;                ||+------- Error request
  251. ;                |+-------- Request to send
  252. ;                +--------- Interrrupt reset
  253. saybr   db      escape,'[25;0H'
  254.         db      escape,'[35mBreak sent. . .',escape,'[0m$'
  255. initfail db     cr,lf,escape,'[31mSerial port could not be initialized',escape,'[m$'
  256. outfail db      cr,lf,escape,'[31mTime out on send via serial port',escape,'[m$'
  257. intfail db      cr,lf,escape,'[31mTime out on receive via serial port',escape,'[m$'
  258. inbfail db      cr,lf,escape,'[31mSerial port receive buffer overflow',escape,'[m$'
  259. mlcurat db      ?               ; used for the mode line cursor attributes
  260. clreol  db      escape,'[0K$'      ; Clear to end of line.......
  261. blank   db      escape,'[H',escape,'[J$' ; Home cursor, then Clear screen....
  262. ;;;;;;;;;;;;;;;;;;;;;;;;;;;; End of NEC specific stuff
  263.  
  264. crlf    db      cr,lf,'$'
  265. delstr  db      BS,BS,'  ',BS,BS,'$'    ; Delete string
  266. clrlin  db      cr,'$'                  ; Clear line (just the cr part).
  267. onmsg   db      'on$'
  268. offmsg  db      'off$'
  269. clone   db      0               ; clone flag (0 = real, 'B' = system Bios,
  270.                                 ;  'N' = NetBios/network)
  271. portin  db      0               ; Has comm port been initialized
  272. xofsnt  db      0               ; Say if we sent an XOFF.
  273. xofrcv  db      0               ; Say if we received an XOFF.
  274. parmsk  db      ?               ; parity mask, 0ffh for no parity, 07fh with.
  275. flowoff db      ?               ; flow-off char, Xoff or null (if no flow)
  276. flowon  db      ?               ; flow-on char, Xon or null
  277. overrun db      ?               ; holds status of receiver overrun
  278. pcwcnt  dw      240             ; number of loops for 1 millisec in pcwait
  279. temp    dw      0
  280. tempsci dw      0               ; temp storage for serint
  281. tempdum dw      0               ; temp storage for serdum
  282. rdbuf   db      80 dup (?)      ; temporary storage
  283.                                         ; begin Terminal emulator data set
  284. termtb  db      tttypes                 ; entries for Status, not Set
  285.         mkeyw   'Heath-19',ttheath
  286.         mkeyw   'none',ttgenrc
  287.         mkeyw   'Tek4010',tttek
  288.         mkeyw   'VT102',ttvt100
  289.         mkeyw   'VT52',ttvt52
  290.  
  291. vttbl   db      13                      ; twelve entries.
  292.         mkeyw   'Character-set',chaval
  293.         mkeyw   'Color',200H            ; screen fore/back colors; 200H=marker
  294.         mkeyw   'Cursor-style',curval
  295.         mkeyw   'Heath-19',ttheath+100H ; note 100H flag for decoding here
  296. ;        mkeyw   'Keyclick',keyval    ; NEC can't do internally
  297.         mkeyw   'Margin-bell',marval
  298.         mkeyw   'None',ttgenrc+100H
  299.         mkeyw   'Newline',newval
  300.         mkeyw   'Rollback',400h         ; note 400H flag for decoding
  301. ;        mkeyw   'Screen-background',scrval    ; NEC keep black back
  302.         mkeyw   'Tabstops',tabval
  303.         mkeyw   'Tek4010',tttek+100H
  304.         mkeyw   'VT102',ttvt100+100H
  305.         mkeyw   'VT52',ttvt52+100H
  306.         mkeyw   'Wrap',wraval
  307.  
  308. scrtab  db      02H                     ; screen attributes
  309.         mkeyw   'normal',00H
  310.         mkeyw   'reverse',01H
  311.  
  312. curtab  db      02H                     ; cursor attributes
  313.         mkeyw   'block',00H
  314.         mkeyw   'underline',01H
  315.  
  316. chatab  db      02H                     ; character set (pound sign choice)
  317.         mkeyw   'UK-ascii',01H
  318.         mkeyw   'US-ascii',00H          ; US ASCII is default (0).
  319.  
  320. tabtab  db      02H                     ; label says it all!
  321.         mkeyw   'at',0FFH               ; For setting tab stops.
  322.         mkeyw   'Clear',00H             ; For clearing tab stops.
  323.  
  324. alltab  db      02H                     ; more tab command decoding
  325.         mkeyw   'all',00H
  326.         mkeyw   'at',01H
  327.  
  328. vtable  dw      ontab, curtab, chatab, ontab, ontab, ontab, scrtab, 0
  329.  
  330. vtsflg equ      this byte               ; define small digits xxxval
  331. newval  equ     $-vtsflg                ; and mask for bit in byte
  332.         db      vsnewline
  333. curval  equ     $-vtsflg
  334.         db      vscursor
  335. chaval  equ     $-vtsflg
  336.         db      vsshift3
  337. keyval  equ     $-vtsflg
  338.         db      vskeyclick
  339. wraval  equ     $-vtsflg
  340.         db      vswrap
  341. marval  equ     $-vtsflg
  342.         db      vsmarginbell
  343. scrval  equ     $-vtsflg
  344.         db      vsscreen
  345. numflgs equ     $-vtsflg
  346. tabval  equ     $-vtsflg
  347.         db      0
  348. vtrtns  dw      numflgs dup (flgset), tabset ; dispatch table for vtsflg
  349.  
  350. clrset  db      ?                       ; Temp for SET Term Tabstops xxx
  351. tmptabs db      132 dup (?)             ; Temporary for unconfirmed tabs.
  352.  
  353. vthlp   db      ' one of the following:',cr,lf
  354.         db '  terminal types of:  None, Heath-19, Tek4010,'
  355.         db  ' VT52, or VT102',cr,lf
  356.         db '  Newline-mode    Cursor-style        Character-set (US UK)',cr,lf
  357.         db '  Tabstops        Wrap (long lines)   Color (of connect screen)'
  358.         db cr,lf,'  Roll (undo screen roll back before writing new chars,'
  359.         db      ' default=off)',cr,lf
  360.         db '  Margin-bell'
  361.         db '$'
  362.  
  363. clrhlp  db      ' one of the following:'
  364.         db      cr,lf,'  AT  #s  (to set tabs at column #s)'
  365.         db      cr,lf,'  Clear AT #s  or  Clear ALL  (to clear tabstops)'
  366.         db      cr,lf,'  Ex: Set Term Tab at 10, 20, 34        sets tabs'
  367.         db      cr,lf,'  Ex: Set Term Tab Clear at 9, 17, 65   clears tabs$'
  368. allhlp  db      ' one of the following:'
  369.         db      cr,lf,'  AT #s (to clear at specific columns)'
  370.         db      cr,lf,'  ALL   (to clear all tabstops)$'
  371. tbshlp  db      '  column number of tab stop to set, 1 to screen width-1$'
  372. tbchlp  db      '  column number of tab stop to clear, 1 to screen width-1$'
  373. tbserr  db      cr,lf,'?Column number is not in range 1 to screen width-1$'
  374.  
  375. ;;;;;;;;;;;;;;;;;;;; modified for the realities of the APC III
  376. colhlp  db      cr,lf,'  Color of:  '
  377.         db      escape,'[34mblue  '
  378.         db      escape,'[31mred  '
  379.         db      escape,'[35mmagenta  '
  380.         db      escape,'[32mgreen  '
  381.         db      escape,'[36mcyan  '
  382.         db      escape,'[33myellow  '
  383.         db      escape,'[37mwhite'
  384.         db      escape,'[0m$'
  385. colltb  db      7                       ; 7 entries
  386.         mkeyw   'Blue',nec_blue
  387.         mkeyw   'Cyan',nec_cyan
  388.         mkeyw   'Green',nec_green
  389.         mkeyw   'Magenta',nec_magenta
  390.         mkeyw   'Red',nec_red
  391.         mkeyw   'White',nec_white
  392.         mkeyw   'Yellow',nec_yellow
  393. ;;;;;;;;;;;;;;;;;;;; end of NEC colors
  394. vtwrap  db      '  Term wrap-lines: $'
  395. vtbell  db      '  Term margin-bell: $'
  396. vtnewln db      '  Term newline: $'
  397. vtcur   db      '  Term cursor-style: $'
  398. vtcset  db      '  Term character-set: $'
  399. ; vtclik  db      '  Term key-click: $'
  400. ; vtscrn  db      '  Term screen-background: $'
  401. colst1  db      '  Term color  foreground:3$'
  402. ; colst2  db      ' background:4$'
  403.                                                         ; terminal emulator
  404. vtstbl  stent   <srchkb,vtwrap,ontab,,vtsflg+wraval>    ; VT100 line wrap
  405.         stent   <srchkb,vtbell,ontab,,vtsflg+marval>    ; VT100 margin bell
  406.         stent   <srchkb,vtcur,curtab,,vtsflg+curval>    ; VT100 cursor type
  407.         stent   <srchkb,vtnewln,ontab,,vtsflg+newval>   ; VT100 newline
  408. ;        stent   <srchkb,vtscrn,scrtab,,vtsflg+scrval>   ; VT100 screen
  409.         stent   <srchkb,vtcset,chatab,,vtsflg+chaval>   ; VT100 character set
  410. ;        stent   <srchkb,vtclik,ontab,,vtsflg+keyval>    ; VT100 keyclick
  411.         stent   <colstat>                               ; VT100 colors
  412.         stent   <tabstat>       ; VT100 tab status - needs one whole line
  413.         dw      0               ; end of table
  414.                                                 ; end of Terminal data set
  415.  
  416. ontab   db      2                       ; Two entries.
  417.         mkeyw   'off',0                 ; Should be alphabetized
  418.         mkeyw   'on',1
  419.  
  420. comptab db      6               ; six entries for NEC
  421.         mkeyw   '1',1
  422.         mkeyw   '2',2
  423.         mkeyw   '3',3
  424.         mkeyw   'AUX',1
  425.         mkeyw   'AUX2',2
  426.         mkeyw   'AUX3',3
  427.  
  428. ; this table is indexed by the baud rate definitions given in
  429. ; pcdefs.  Unsupported baud rates should contain FF.
  430.  
  431. baudtab db      0FFH            ; 45.5
  432.         db      0FFH            ; 50
  433.         db      0               ; 75
  434.         db      0FFH            ; 110
  435.         db      0FFH            ; 134.5
  436.         db      1               ; 150
  437.         db      2               ; 300
  438.         db      3               ; 600
  439.         db      4               ; 1200
  440.         db      0FFH            ; 1800
  441.         db      0FFH            ; 2000
  442.         db      5               ; 2400
  443.         db      6               ; 4800
  444.         db      7               ; 9600
  445.         db      0FFH            ; 19.2k
  446.         db      0FFh            ; 38.4k
  447.         db      0FFh            ; 57.6k
  448.         db      0FFh            ; 115.2k
  449. nbaud   equ     $-baudtab
  450.  
  451. ; variables for serial interrupt handler
  452.                                 ; BIOS handles the buffer; count not used  RFG
  453. count   dw      0               ; Number of chars in int buffer.
  454. mdstreg db      0               ; Modem status register, current.
  455.  
  456. datas   ends
  457.  
  458. code    segment public 'code'
  459.         extrn   comnd:near, dopar:near, defkey:near, lclyini:near
  460.         extrn   sleep:near, atsclr:near, scrseg:near,scrloc:near, scrsync:near
  461.         extrn   atoi:near, strlen:near, prtscr:near, scroff:near, scron:near
  462.         extrn   anstat:near             ; RFG
  463.         assume  cs:code,ds:datas
  464.  
  465. int_rs232 macro                         ; this is necessary since we need to
  466.         local   rs1,rs2                 ; to use the 1A interrupt if we have
  467.         cmp     flags.comflg,1          ; only one port, and 1E if we have more
  468.         je      rs1
  469.         push    si              ; a necessary save
  470.         push    bx              ; a short save
  471.         mov     bh,0
  472.         mov     bl,flags.comflg ; get the port number
  473.         sub     bl,1            ; put it into NEC terms
  474.         mov     si,bx           ; then into the right place
  475.         pop     bx              ; and restore
  476.         int     1EH             ; now the multi-choice interrupt
  477.         pop     si              ; and restore
  478.         jmp     rs2
  479. rs1:    int     1AH
  480. rs2:    nop
  481.         endm
  482.  
  483. ; local initialization
  484.  
  485. lclini  proc    near
  486.         mov     flags.comflg,1  ; assume COM1 for communications port
  487. ;        call    coms2           ; setup serial port modem.info for COM1  RFG
  488. ;        call    model           ; get model of IBM machine  RFG
  489.         call    lclyini         ; let other modules initialize too...
  490.         ret
  491. lclini  endp
  492.  
  493. ; this is called by Kermit initialization.  It checks the
  494. ; number of disks on the system, sets the drives variable
  495. ; appropriately.  Returns normally.
  496. ; From RAL Version 2.0                          RFG
  497.  
  498. DODISK  PROC    NEAR
  499.         mov    ah,gcurdsk        ; Current disk value to AL.
  500.         int    dos
  501.         mov    dl,al            ; Put current disk in DL.
  502.         mov    ah,seldsk        ; Select current disk.
  503.         int    dos            ; Get number of drives in AL.
  504. dodsk0: mov     drives,al               ; Remember how many.
  505.         ret
  506. DODISK  ENDP
  507.  
  508. ; Returns normally. Obsolete, name here for external reference only.
  509. showkey proc    near
  510.         ret                             ; return
  511. showkey endp
  512.  
  513. ; SHOW MODEM, displays current status of lines DSR, CD, and CTS.
  514. ; Uses byte mdstreg, the modem line status register. [jrd]
  515. shomodem proc   near
  516.         mov     ah,cmcfm                ; get a confirm
  517.         call    comnd
  518.          jmp    r                       ; no confirm
  519.          nop
  520.     mov    ah,6            ; status request - NEC code follows
  521.     int_rs232            ; go get the answer
  522.     and    ch,80h            ; CH bit 7    Data set ready
  523.     xor    cl,0FFh            ; CL bit 6    Clear to Send = 0
  524.     and    cl,60h            ;        5    Carrier detect = 0
  525.     or    ch,cl            ; lump the answer together
  526.     mov    mdstreg,ch        ; and save it
  527.         mov     ah,prstr
  528.         mov     dx,offset msmsg1        ; modem ready msg
  529.         test    mdstreg,80h             ; is DSR asserted?
  530.         jz      shomd1                  ; z = no
  531.         mov     dx,offset msmsg2        ; say not asserted
  532. shomd1: int     dos
  533.         mov     dx,offset msmsg3        ; CD asserted msg
  534.         test    mdstreg,20h             ; CD asserted?
  535.         jz      shomd2                  ; z = no
  536.         mov     dx,offset msmsg4        ; say not asserted
  537. shomd2: int     dos
  538.         mov     dx,offset msmsg5        ; CTS asserted msg
  539.         test    mdstreg,40h             ; CTS asserted?
  540.         jz      shomd3                  ; z = no
  541.         mov     dx,offset msmsg6        ; say not asserted
  542. shomd3: int     dos
  543.         jmp     rskp
  544. shomodem endp
  545.  
  546. ; Clear the input buffer. This throws away all the characters in the
  547. ; serial interrupt buffer.  This is particularly important when
  548. ; talking to servers, since NAKs can accumulate in the buffer.
  549. ; Returns normally.
  550. ; On the NEC, where the buffer is (really) managed by the BIOS, we could
  551. ; clear it by calling serini or blindly reading everything out,  RFG
  552.  
  553. CLRBUF  PROC    NEAR
  554. clrb2:  mov     ah,2            ; Get data length in CX...Page SE-12
  555.         int_rs232               ; Call APC ROM BIOS
  556. clrb4:  or      ch,cl           ; check for zero in both halfs of CX
  557.         cmp     ch,0            ; is CH 0?
  558.         je      clrb1           ; If zero then buffer is clear else
  559.         mov     ah,4            ; Receive Character...by way of NEC BIOS
  560.         int_rs232
  561.         jmp     clrb2
  562. clrb1:
  563.         ret
  564. CLRBUF  ENDP
  565.  
  566. ; Clear to the end of the current line.  Returns normally.      RFG
  567.  
  568. CLEARL  PROC    NEAR
  569.         push    ax
  570.         push    dx
  571.         mov dx,offset clreol
  572.         mov ah,prstr
  573.         int dos
  574.         pop     dx
  575.         pop     ax
  576.         ret
  577. CLEARL  ENDP
  578.  
  579. ; This routine blanks the screen.  Returns normally.
  580.  
  581. CMBLNK  PROC    NEAR
  582.         mov ah,prstr
  583.         mov dx,offset blank
  584.         int dos
  585.         ret
  586. CMBLNK  ENDP
  587.  
  588. ; Locate: homes the cursor.  Returns normally.
  589.  
  590. LOCATE  PROC    NEAR
  591.         mov dx,0                ; Go to top left corner of screen.
  592.         jmp poscur
  593. LOCATE  ENDP
  594.  
  595. ; Position the cursor according to contents of DX:
  596. ; DH contains row, DL contains column.  Returns normally.
  597. POSCUR  PROC    NEAR
  598.         push    ax
  599.         push    bx
  600.         push    si        ; NEC
  601.         mov     ah,2            ; Position cursor.
  602.         mov     bh,0            ; page 0
  603.         int     bios
  604.         pop     si        ; NEC
  605.         pop     bx
  606.         pop     ax
  607.         ret
  608. POSCUR  ENDP
  609.  
  610. ; Delete a character from the terminal.  This works by printing
  611. ; backspaces and spaces.  Returns normally.
  612.  
  613. DODEL   PROC    NEAR
  614.         mov     ah,prstr
  615.         mov     dx,offset delstr        ; Erase weird character.
  616.         int     dos
  617.         ret
  618. DODEL   ENDP
  619.  
  620. ; Move the cursor to the left margin, then clear to end of line.
  621. ; Returns normally.
  622.  
  623. CTLU    PROC    NEAR
  624.         mov     ah,prstr
  625.         mov     dx,offset clrlin
  626.         int     dos
  627.         call    clearl
  628.         ret
  629. CTLU    ENDP
  630.         ret
  631.  
  632.  
  633. BEEP    PROC    NEAR            ; NEC version
  634.         mov dl,bell
  635.         mov ah,conout
  636.         int dos
  637.         ret
  638. BEEP    ENDP
  639.  
  640. ; write a line in inverse video at the bottom of the screen...
  641. ; the line is passed in dx, terminated by a $.  Returns normally.
  642. ; This is only used for the send/receive mode lines.            RFG
  643.  
  644. putmod  proc    near
  645.         push    ax              ; save regs
  646.         push    bx
  647.         push    cx
  648.         push    dx              ; preserve message
  649.     call    anstat          ; get the screen attributes   RPG
  650.         mov     bh,ah           ; mlbattr returned in ah
  651.         mov     mlcurat,ah      ; and put it in mlcurat
  652.         mov     cx,1800h        ; from line 24, column 0
  653.         mov     dx,184fh        ; to line 24, column 79
  654.         mov     ax,600h         ; do a scroll up
  655.         int     bios
  656.  
  657.         mov     dx,1800h        ; now address line 24
  658.         call    poscur
  659.         pop     si              ; get message back (from dx push)
  660.         mov     cx,1            ; only one char at a time
  661.         xor     bh,bh           ; page 0
  662. putmo1: lodsb                   ; get a byte
  663.         cmp     al,'$'          ; end of string?
  664.         je      putmo2
  665.         push    si              ; save si
  666.         push    ax              ; and the char
  667.         call    poscur
  668.         inc     dl              ; increment for next write
  669.         pop     ax              ; recover char
  670.         mov     ah,9            ; try this
  671.         mov     bl,mlcurat      ; page 0, inverse video
  672.         mov     bh,0
  673.         int     bios
  674.         pop     si              ; recover pointer
  675.         jmp     putmo1
  676. putmo2: pop     cx
  677.         pop     bx
  678.         pop     ax
  679.         ret
  680. putmod  endp
  681.  
  682. ; clear the mode line written by putmod.  Returns normally.
  683. ; separate out the text attributes                      RFG
  684. clrmod  proc    near
  685.         push    ax
  686.         push    bx
  687.         push    cx
  688.         push    dx
  689.         call    anstat          ; get the screen attributes   RPG
  690.         mov     bh,al           ; scbattr returned in al
  691.         mov     cx,1800h        ; from line 24, column 0
  692.         mov     dx,184fh        ; to line 24, column 79
  693.         mov     ax,600h         ; do a scroll up
  694.         int     bios
  695.         pop     dx
  696.         pop     cx
  697.         pop     bx
  698.         pop     ax
  699.         ret
  700. clrmod  endp
  701.  
  702. ; put a help message on the screen.  This one uses reverse video...
  703. ; pass the message in ax, terminated by a null.  Returns normally.
  704. ; separate out text attributes
  705. puthlp  proc    near
  706.         push    bx              ; save regs. [jrd]
  707.         push    cx
  708.         push    dx
  709.         push    si
  710.         push    ax              ; preserve this
  711.         cld
  712.         mov     si,ax           ; point to it
  713.         mov     dh,1            ; init counter
  714. puthl1: lodsb                   ; get a byte
  715.         cmp     al,lf           ; linefeed?
  716.         jne     puthl2          ; no, keep going
  717.         inc     dh              ; count it
  718.         jmp     puthl1          ; and keep looping
  719. puthl2: cmp     al,0            ; end of string?
  720.         jne     puthl1          ; no, keep going;
  721.         call    anstat          ; get screen attributes     RPG
  722.         mov     bh,ah           ; mlbattr returned in ah
  723.         mov     mlcurat,ah      ; and save it
  724.         mov     ax,600h         ; scroll to clear window
  725.         xor     cx,cx           ; from top left
  726.         mov     dl,4fh          ; to bottom right of needed piece
  727.         int     bios
  728.         call    locate          ; home cursor
  729.         mov     bh,0            ; Page 0
  730.         mov     bl,mlcurat
  731.         mov     cx,1            ; one char at a time
  732.         cld                     ; scan direction is forward [jrd]
  733.         pop     si              ; point to string again
  734. puthl3: lodsb                   ; get a byte
  735.         cmp     al,0            ; end of string?
  736.         je      puthl4          ; yes, stop
  737.         push    si              ; save around bios call
  738.         cmp     al,' '          ; printable?
  739.         jb      puth21          ; b = no
  740.         mov     ah,9            ; write char at current cursor position [jrd]
  741.         int     bios            ; do the Bios int 10h call
  742.         inc     dl              ; point to next column
  743.         jmp     puth23          ; move cursor there
  744. puth21: cmp     al,cr           ; carriage return?
  745.         jne     puth22          ; ne = no
  746.         xor     dl,dl           ; set to column zero
  747.         jmp     puth23
  748. puth22: cmp     al,lf           ; line feed?
  749.         jne     puth23
  750.         inc     dh              ; go to next line
  751. puth23: mov     ah,2            ; set cursor position to dx
  752.         int     bios
  753.         pop     si              ; restore pointer [jrd]
  754.         jmp     puthl3          ; and keep going
  755. puthl4: mov     dx,24 * 100H    ; go to last line
  756.         call    poscur          ; position cursor
  757.         pop     si              ; [jrd]
  758.         pop     dx
  759.         pop     cx
  760.         pop     bx
  761.         ret
  762. puthlp  endp
  763.  
  764.                                         ; begin Terminal set & status code
  765.  
  766. ; SET Term parameters, especially for use with VT100 emulator. [jrd]
  767. ; Taken from work done originally by James Harvey IUPUI.
  768. ; VTS is called only by mssset to set terminal type and characteristics.
  769.  
  770. VTS     proc    near                    ; SET TERM whatever
  771.         mov     ah,cmkey                ; Parse another keyword.
  772.         mov     bx,offset vthlp         ; Use this help
  773.         mov     dx,offset vttbl         ; Use this table
  774.         call    comnd
  775.          jmp    r                       ; Vsetup always returns +1.
  776.         cmp     bh,1H                   ; marker for terminal type?
  777.         je      vsetu0a                 ; e = yes
  778.  
  779.         cmp     bh,4H                   ; marker for roll back control?
  780.         je      vsetu3                  ; e = yes
  781.         cmp     bh,2h                   ; marker for set term color?
  782.         je      vsetu2                  ; e = yes
  783.         jmp     short vsetu1            ; else dispatch on bl
  784. vsetu0a:push    bx                      ; yes
  785.         mov     ah,cmcfm
  786.         call    comnd                   ; Get a confirm.
  787.          jmp    vsetu0                  ; Didn't get a confirm.
  788.          nop
  789.         pop     bx
  790.         mov     flags.vtflg,bl          ; Set the terminal emulation type
  791.         mov     tekflg,0                ; clear Tek sub mode
  792.         ret
  793. vsetu0: pop bx
  794.         ret
  795.  
  796. vsetu3: mov     ah,cmkey                ; Set Term Roll On/Off, auto roll back
  797.         mov     bx,0                    ; Use on/off table as help
  798.         mov     dx,offset ontab         ; Use on/off table
  799.         call    comnd
  800.          jmp    r                       ; bad keyword
  801.         push    bx
  802.         mov     ah,cmcfm                ; get a confirm
  803.         call    comnd
  804.          jmp    vsetu0                  ; did not get a confirm
  805.          nop
  806.         pop     bx
  807.         mov     vtroll,bl               ; set roll state (0=no auto rollback)
  808.         jmp     rskp                    ; return successfully
  809.  
  810. vsetu1: sal     bx,1                    ; Make bx a word index.
  811.         call    vtrtns[bx]              ; Dispatch.
  812.          jmp    r                       ; Vsetup always returns +1.
  813.         jmp     r                       ; Vsetup always returns +1.
  814.  
  815.                                 ; Set Term Color foreground, background
  816. vsetu2:
  817.         mov     ah,cmkey                ; COLOR - get value
  818.         mov     bx,offset colhlp        ; use this help text
  819.         mov     dx,offset colltb        ; parse by this table
  820.         call    comnd
  821.           jmp   r
  822.         push    bx                      ; save it
  823.         cmp     ah,0                    ; any response
  824.         jne     vsetu2a                 ; ne = yes
  825.         jmp     vsetux                  ; else give not confirmed msg
  826. vsetu2a:
  827.         pop     ax                      ; get value
  828.         mov     bx,vtemu.att_ptr        ; address of attributes byte
  829.         mov     byte ptr [bx],al        ; put the color in (plain, otherwise)
  830.         jmp     rskp
  831. vsetux: pop     bx                      ; throw away
  832.         jmp     r                       ; and exit complaining
  833.  
  834. ; SET Term flags. These are the (near) equivalent of VT100 Setup mode values.
  835.  
  836. flgset: push    bx                      ; Save bx for a second.
  837.         mov     ah,cmkey                ; Another keyword.
  838.         mov     dx,vtable[bx]           ; The table to use.
  839.         mov     bx,0                    ; Use default help.
  840.         call    comnd
  841.          jmp    flgse3
  842.         push    bx                      ; Save switch value.
  843.         mov     ah,cmcfm                ; Confirm it.
  844.         call    comnd
  845.          jmp    flgse2
  846.         pop     dx                      ; Restore switch value.
  847.         pop     bx                      ; And index.
  848.         sar     bx,1                    ; Make it a byte index.
  849.         mov     al,vtsflg[bx]           ; Get the flag.
  850.         cmp     dx,0                    ; Set or clear?
  851.         je      flgse1                  ; Go clear it.
  852.         or      vtemu.vtflgst,al        ; Set the flag.
  853.         or      vtemu.vtflgop,al        ; in runtime flags too
  854.         jmp     rskp                    ; Give good return.
  855.  
  856. flgse1: not     al                      ; Complement
  857.         and     vtemu.vtflgst,al        ; Clear the indicated setup flag.
  858.         and     vtemu.vtflgop,al        ; Clear the indicated runtime flag.
  859.         jmp     rskp                    ; Give good return.
  860. flgse2: pop     bx                      ; error exits
  861. flgse3: pop     bx
  862.         ret
  863.  
  864. ;       SET Term Tabstops Clear ALL
  865. ;       SET Term Tabstops Clear AT n1, n2, ..., nx
  866. ;       SET Term Tabstops At n1, n2, ..., nx
  867.  
  868. tabset: cld                             ; Make sure this is clear.
  869.         mov     di,offset tmptabs       ; clear our temp work area here.
  870.         mov     cx,132                  ; 132 columns
  871.         mov     al,0                    ; set "not touched" indicator
  872.         rep     stosb                   ; in all tmptabs slots
  873.         mov     ah,cmkey                ; Parse keyword.
  874.         mov     bx,offset clrhlp        ; Use this help text.
  875.         mov     dx,offset tabtab        ; This table.
  876.         call    comnd
  877.          jmp    r
  878.         mov     clrset,2                ; code for set a tab
  879.         cmp     bl,0                    ; Was it set or clear?
  880.         jne     tabse1                  ; SET - go parse column number(s).
  881.         mov     clrset,1                ; code for clear at/all tab(s)
  882.         mov     ah,cmkey                ; CLEAR - parse ALL or AT
  883.         mov     bx,offset allhlp        ; Use this help text.
  884.         mov     dx,offset alltab        ; Parse ALL or AT.
  885.         call    comnd
  886.          jmp    r
  887.         cmp     bx,0                    ; ALL?
  888.         jne     tabse1                  ; ne = AT, clear at specific places.
  889.         mov     al,1                    ; ALL, means clear all tab stops.
  890.         mov     cx,132                  ; use 132 columns
  891.         mov     di,offset tmptabs
  892.         rep     stosb
  893.         mov     ah,cmcfm                ; Confirm it.
  894.         call    comnd
  895.          jmp    r
  896.         jmp     tabcpy                  ; update active & coldstart tabs
  897.  
  898. tabse1: mov     dx,offset tbshlp        ; Tell them we want a column number.
  899.         cmp     clrset,1                ; Clearing?
  900.         jne     tabse2                  ; ne = Set. we guessed right on help.
  901.         mov     dx,offset tbchlp        ; Yes - use this help instead.
  902. tabse2: mov     ah,cmtxt                ; get text w/o white space
  903.         mov     bx,offset rdbuf         ; temp buffer
  904.         call    comnd
  905.          jmp    r
  906.         cmp     ah,0                    ; anything given?
  907.         jne     tabse4                  ; ne = yes.
  908.         jmp     r                       ; else give not confirmed msg
  909. tabse4: mov     ah,cmcfm                ; Parse confirm
  910.         mov     bx,0                    ; Use default help.
  911.         call    comnd
  912.          jmp    r                       ; not confirmed, complain.
  913.         mov     si,offset rdbuf         ; si = place where atoi wants text
  914. tabse5: mov     dx,si
  915.         call    strlen                  ; current length of text
  916.         mov     ah,cl                   ; put length where Atoi wants it
  917.         jcxz    tabcpy                  ; nothing left
  918.         call    atoi                    ; convert text to numeric in ax
  919.          jmp    tabcpy                  ;  no number available
  920.         mov     bx,ax                   ; for subscripting in code below
  921.         dec     bx                      ; Put column in range 0-79
  922.         cmp     bx,0                    ; check range (1-80 --> 0-79)
  923.         jl      tbsbad                  ; l = too small. complain
  924.         cmp     bl,132-1                ; more than the right most column?
  925.         jna     tabse3                  ; na = no, is ok
  926. tbsbad: mov     ah,prstr                ; Not in range - complain and exit.
  927.         mov     dx,offset tbserr
  928.         int     dos
  929.         jmp     rskp
  930.  
  931. tabse3: mov     al,clrset               ; Get value for setting or clearing.
  932.         mov     tmptabs[bx],al          ; store in tabs temp work array
  933.         jmp     short tabse5            ; look for more
  934.  
  935. tabcpy: mov     cx,132                  ; update all active tab stops
  936.         mov     si,vtemu.vttbst         ; in terminal emulator's active buffer
  937.         mov     di,vtemu.vttbs          ; and in the cold-start buffer.
  938.         mov     bx,0                    ; subscript
  939. tabcpy1:mov     al,byte ptr tmptabs [bx] ; get a table entry into al
  940.         or      al,al                   ; what is the code?
  941.         jz      tabcpy3                 ; z = do not touch
  942.         cmp     al,2                    ; set a tab?
  943.         je      tabcpy2                 ; e = set the tab
  944.         mov     byte ptr [bx+si],0      ; clear the tab
  945.         mov     byte ptr [bx+di],0      ; clear the tab
  946.         jmp     short tabcpy3
  947. tabcpy2:mov     byte ptr [bx+si],0ffh   ; set the tab
  948.         mov     byte ptr [bx+di],0ffh   ; set the tab
  949. tabcpy3:inc     bx                      ; inc subscript
  950.         loop    tabcpy1
  951.         jmp     rskp                    ; Give good return.
  952.  
  953. VTS     endp                            ; end of Set Term things.
  954.  
  955.               ; Terminal Status display, called within STAT0: in MSSSET.[jrd]
  956. VTSTAT  proc    near                ;enter with di within sttbuf, save bx, di
  957.         push    bx
  958.         push    di
  959.         mov     bx,ds
  960.         mov     es,bx
  961.         cld
  962.         mov     bx,offset vtstbl        ; table of things to show
  963.         xor     cx,cx
  964. vtsta1: cmp     word ptr [bx],0         ; end of table?
  965.         je      vtstax                  ; e = yes
  966.         push    bx
  967.         call    [bx].sttyp              ; call appropriate routine
  968.         pop     bx                      ; cx incremented by output count
  969.         cmp     cx,38                   ; place for second display
  970.         jbe     vtsta2                  ; le = only half full
  971.         mov     dx,offset crlf          ; over half full. send cr/lf
  972.         mov     ah,prstr
  973.         int     dos
  974.         xor     cx,cx                   ; say line is empty now
  975.         jmp     short vtsta4
  976. vtsta2: mov     ax,cx
  977.         mov     cx,38                   ; where we want to be next time
  978.         sub     cx,ax                   ; compute number of filler spaces
  979.         jcxz    vtsta4                  ; nothing to do
  980.         mov     ah,conout
  981.         mov     dl,' '
  982. vtsta3: int     dos                     ; fill with spaces
  983.         loop    vtsta3                  ; do cx times
  984.         mov     cx,38                   ; current column number
  985. vtsta4: add     bx,size stent           ; look at next entry
  986.         jmp     vtsta1                  ; and do it
  987. vtstax: pop     di
  988.         pop     bx
  989.         ret                             ; return to STAT0: in MSSSET.
  990.  
  991.                                         ; foreground/background color status
  992. colstat proc    near
  993.         mov     dx,offset colst1
  994.         mov     ah,prstr
  995.         int     dos                     ; print first part of msg
  996.  
  997.         mov     bx,vtemu.att_ptr        ; pointer to attributes byte
  998.         mov     al,byte ptr [bx]
  999.         and     al,0E0H                 ; color bits only, please
  1000.         mov     ah,0
  1001.         mov     bx,offset colltb
  1002.         call    prttab
  1003.         add     cx,18                   ; about the # columns we used
  1004.         ret
  1005. colstat endp
  1006.                                         ; Tabs Status display
  1007. tabstat proc    near                    ; display tabs ruler for Status
  1008.         push    dx
  1009.         jcxz    tabsta0                 ; empty line, as it should be
  1010.         xor     cx,cx                   ; used line, empty it
  1011.         mov     dx,offset crlf          ; cr, lf
  1012.         mov     ah,prstr
  1013.         int     dos
  1014. tabsta0:mov     si,vtemu.vttbst         ; active tabs address, not shadow
  1015.         mov     cl,byte ptr low_rgt     ; loop screen width-1 times
  1016.         xor     ch,ch                   ; clear high byte
  1017.         dec     si                      ; dec for inc below
  1018.         xor     ax,ax                   ; tens counter
  1019. tabsta1:mov     dl,0F9H                 ; default position symbol ( mid-dot )
  1020.         inc     si                      ; start with position 1
  1021.         inc     al
  1022.         cmp     al,10                   ; time to roll over?
  1023.         jb      tabsta2                 ; b = not yet
  1024.         mov     al,0                    ; modulo 10
  1025.         inc     ah
  1026.         mov     dl,ah                   ; display a tens-digit
  1027.         add     dl,'0'
  1028.         cmp     dl,'9'                  ; larger than 90?
  1029.         jbe     tabsta2                 ; be = no
  1030.         sub     dl,10                   ; roll over to 0, 1, etc
  1031. tabsta2:cmp     byte ptr [si],0         ; is tab set?
  1032.         je      tabsta3                 ; e = no
  1033.         mov     dl,'T'                  ; yes, display a 'T'
  1034. tabsta3:push    ax
  1035.         mov     ah,conout               ; console output
  1036.         int     dos
  1037.         pop     ax
  1038.         loop    tabsta1                 ; loop til done (cx has count)
  1039.         pop     dx
  1040.         mov     cx,38                   ; say line is used
  1041.         ret
  1042. tabstat endp
  1043.  
  1044. ; handler routines for status. All are called with bx/ stat ptr.
  1045.  
  1046. onoff   proc    near
  1047.         call    stmsg                   ; print the message
  1048.         mov     si,[bx].basval          ; get base value
  1049.         cmp     si,0                    ; any there?
  1050.         je      onoff1                  ; e = no
  1051.         mov     si,[si]                 ; yes, use as base address
  1052. onoff1: add     si,[bx].tstcel          ; add offset of test cell
  1053.         mov     al,[si]
  1054.         mov     dx,offset onmsg
  1055.         add     cx,2                    ; assume two byte on message
  1056.         or      al,al                   ; test value
  1057.         jnz     onoff2                  ; nz = on
  1058.         mov     dx,offset offmsg
  1059.         inc     cx                      ; three byte message
  1060. onoff2: mov     ah,prstr                ; display the message
  1061.         int     dos
  1062.         ret
  1063. onoff   endp
  1064.  
  1065. ; search a keyword table for a bit value, print that value. [jrd]
  1066. srchkb  proc    near
  1067.         call    stmsg                   ; first print message
  1068.         call    stbval                  ; get bit set or reset
  1069.         mov     ah,0                    ; al has 0/1, high order is 0
  1070.         mov     bx,[bx].val2            ; this is table address
  1071.         jmp     prttab                  ; and look in table.
  1072. srchkb  endp
  1073.  
  1074. ; get address of test value in stent.  Returns address in si. [jrd]
  1075. stbval  proc    near
  1076.         mov     si,[bx].basval          ; get address of test value
  1077.         cmp     si,0                    ; any there?
  1078.         je      stbva1                  ; no, quit with no match
  1079.         mov     al,byte ptr [si]        ; get byte value
  1080.         mov     ah,0
  1081.         test    al,vtemu.vtflgop ; bit test value against emulator flags byte
  1082.         jz      stbva1                  ; z = they don't match
  1083.         mov     al,1                    ;  match
  1084.         ret
  1085. stbva1: mov     al,0                    ; no match
  1086.         ret                             ; and return it
  1087. stbval  endp
  1088.  
  1089. ; get address of test value in stent.  Returns address in si
  1090. stval   proc    near
  1091.         mov     si,[bx].basval          ; get base value
  1092.         cmp     si,0                    ; any there?
  1093.         je      stva1                   ; no, keep going
  1094.         mov     si,[si]                 ; yes, use as base address
  1095. stva1:  add     si,[bx].tstcel          ; add offset of test cell
  1096.         ret                             ; and return it
  1097. stval   endp
  1098.  
  1099. ; copy the message to the screen
  1100. stmsg   proc    near
  1101.         mov     si,[bx].msg             ; get message address
  1102. stms1:  lodsb                           ; get a byte
  1103.         cmp     al,'$'                  ; end of message?
  1104.         je      stms2                   ; e = yes
  1105.         mov     dl,al                   ; display the character
  1106.         mov     ah,conout
  1107.         int     dos
  1108.         inc     cx                      ; count output chars
  1109.         jmp     stms1
  1110. stms2:  ret
  1111. stmsg   endp
  1112.  
  1113. ; Print value from table.  BX/address of table, AL/value of variable.
  1114. prttab: push    cx                      ; save column count
  1115.         mov cl,[bx]                     ; Number of entries in our table.
  1116.         inc     bx                      ; Point to the data.
  1117. prtt0:  mov     dl,[bx]                 ; Length of keyword.
  1118.         inc     bx                      ; Point to keyword.
  1119.         mov     dh,0
  1120.         inc     dx                      ; Account for "$" in table.
  1121.         mov     si,dx                   ; Put to index register.
  1122.         cmp     ax,[bx+si]              ; Is this the one?
  1123.         je      prtt1
  1124.         add     bx,dx                   ; Go to end of keyword.
  1125.         add     bx,2                    ; Point to next keyword.
  1126.         dec     cl                      ; Any more keywords to check?
  1127.         jnz     prtt0                   ; Yes, go to it.
  1128.         mov     bx,offset prterr
  1129. prtt1:  mov     si,bx
  1130.         pop     cx                      ; recover column count
  1131.         jmp     stms1                   ; copy in message
  1132.         ret                             ; and return
  1133. VTSTAT  endp                            ; end of Terminal set & status code
  1134.  
  1135. ; Wait for the # of milliseconds in ax
  1136. ; Thanks to Bernie Eiben for this one.
  1137. ; Recalibrated for 8 MHz clock on NEC -- RFG
  1138. pcwait  proc    near
  1139.         mov     cx,300          ; inner loop counter for 1 millisecond
  1140.                 ; was 240 for IBM PC
  1141. pcwai1: sub     cx,1            ; inner loop takes 20 clock cycles
  1142.         jnz     pcwai1
  1143.         dec     ax              ; outer loop counter
  1144.         jnz     pcwait          ; wait another millisecond
  1145.         ret
  1146. pcwait  endp
  1147.  
  1148. ; set the current port.
  1149. ; modified to use all 3 ports                   RFG
  1150.  
  1151. COMS    PROC    NEAR
  1152.         mov dx,offset comptab
  1153.         mov bx,0
  1154.         mov ah,cmkey
  1155.         call comnd
  1156.          jmp r
  1157.         push bx
  1158.         mov ah,cmcfm
  1159.         call comnd              ; Get a confirm.
  1160.          jmp comx               ;  Didn't get a confirm.
  1161.          nop
  1162.         pop bx
  1163.         mov flags.comflg,bl     ; Set the comm port flag.
  1164.         cmp flags.comflg,1      ; Using Com 1?
  1165.         jne coms0               ; Nope.
  1166.         mov ax,offset port1
  1167.         mov portval,ax
  1168.         ret
  1169. coms0:
  1170.         cmp flags.comflg,2      ; Using Com 2?
  1171.         jne coms1               ; Nope.
  1172.         mov ax,offset port2
  1173.         mov portval,ax
  1174.         ret
  1175. coms1:
  1176.         cmp flags.comflg,3      ; Using Com 3?
  1177.         jne comx                ; this can't be!
  1178.         mov ax,offset port3
  1179.         mov portval,ax
  1180.         ret
  1181. comx:   pop bx
  1182.         ret
  1183. COMS    ENDP
  1184.  
  1185. ; Test presently selected serial port for having a real 8250 UART.
  1186. ; Return carry clear and clone = 0 if 8250 present,
  1187. ;  else carry set and clone = 'B' for system Bios or
  1188. ;  carry set and clone = 'N' for network.
  1189. ; Method is to check UART's Interrupt Identification Register for high
  1190. ; five bits being zero; IBM does it this way. Assumes port structure
  1191. ; has been initialized with addresses of UART.  21 Feb 1987 [jrd]
  1192. ; 29 May 1987 Add double check by reading Line Status Register. [jrd]
  1193.  
  1194. chkport proc    near
  1195. chkport endp
  1196.  
  1197. ; Set the baud rate for the current port, based on the value
  1198. ; in the portinfo structure.  Returns normally.
  1199. ; lifted from the RAL version 2.0                               RFG
  1200.  
  1201. ; This routine should set the baud rate for the current port but it
  1202. ; is actually done in SERINI.
  1203. dobaud  proc    near
  1204.         push si                 ; [jrd]
  1205.         push bx
  1206.         mov bx,portval
  1207.         mov si,[bx].baud        ; get baud rate index pointer..
  1208.         pop bx
  1209.         mov al,baudtab[si]      ; load up baud rate.........
  1210.         pop si                  ; [jrd]
  1211.         cmp al,0FFH             ; Is Baud Rate Possible??
  1212.         je badbaud
  1213.         call    serini          ; Simply re-init port with new baud rate
  1214. dbret:  ret
  1215. BadBaud: mov ah,prstr           ; MS-DOS Print String...
  1216.         mov dx,offset badbd     ; point at message
  1217.         int DOS
  1218.         jmp dbret
  1219. dobaud  endp
  1220.  
  1221. ; Get the current baud rate from the serial card and set it
  1222. ; in the portinfo structure for the current port.  Returns normally.
  1223. ; This is used during initialization.
  1224.  
  1225. ; lifted from RAL version 2.0                           RFG
  1226. ;* RAL..This routine appears to be called every time a status is done.
  1227. ;* I will set baud rate first time, and simply return from then on.
  1228. ;*
  1229. ;*  Page SA-2 APC III Programmer Reference Manual
  1230.  
  1231. GETBAUD PROC    NEAR
  1232.         push    ax      ; addition to fix (bug) in msster       RFG
  1233.         push    bx
  1234.  
  1235.         mov     al,First    ; Check to see if this is the first time....
  1236.         cmp     al,false
  1237.         je      GBRET        ; Quit if baud rate already known.....
  1238.  
  1239.         mov     First,False ; Flip Flag...
  1240.         mov     bx,portval
  1241.         mov     [bx].baud,0Dh ; Default to 9600 Baud.....
  1242.         call    serini     ; Set up port........
  1243. GBRET:
  1244.         pop     bx
  1245.         pop     ax
  1246.         ret
  1247. GETBAUD ENDP
  1248.  
  1249. ; Get Char from serial port buffer.
  1250. ; skip returns if no character available at port,
  1251. ; otherwise returns with char in al, # of chars in buffer in dx.
  1252. ; Revised 22 May 1986, and again slightly 2 August 1986 by [jrd]
  1253. ; 21 Feb 1987 Add support for Bios calls (Clone) [jrd]
  1254. ; 25 April 1987 Add Netbios support, remove test for NUL and DEL. [jrd]
  1255.  
  1256. ; partially taken from RAL version 2.0
  1257. ; use call for all 3 RS232 ports                        RFG
  1258.  
  1259. PRTCHR  PROC    NEAR
  1260.         push    cx
  1261.         push    bx
  1262.  
  1263.         mov     ah,2            ; Get data length in CX...Page SE-12
  1264.         int_rs232               ; Call APC ROM BIOS
  1265.         or      ch,cl           ; check for zero in both halfs of CX
  1266.         cmp     ch,0            ; is CH 0?
  1267.         je      prtcn           ; give up if no characters........
  1268.  
  1269.         mov     ah,4            ; Receive Character...by way of NEC BIOS
  1270.         int_rs232
  1271.         cmp     ah,0            ; check return status
  1272.         je      prtc1           ; 0 = everything normal
  1273.                                 ; 1 = port not initialized
  1274.                                 ; 2 = (receive) buffer overflow
  1275.                                 ; 3 = timed out
  1276.         call    beep            ; say something
  1277.         cmp     ah,2
  1278.         je      prtc2
  1279.         mov     ah,prstr        ; say timed out
  1280.         mov     dx,offset intfail
  1281.         int     dos
  1282.         jmp     prtcx
  1283. prtc2:  mov     ah,prstr        ; say buffer overflow
  1284.         mov     dx,offset inbfail
  1285.         int     dos
  1286.         jmp     prtcx
  1287. prtc1:
  1288.         mov     al,ch           ; Character is returned in CH....
  1289.  
  1290. prtcx:  pop     bx
  1291.         pop     cx
  1292.         ret
  1293. prtcn:                          ; no characters in queue, check console
  1294.         pop     bx
  1295.         pop     cx
  1296.         jmp rskp
  1297. PRTCHR  ENDP
  1298.  
  1299. ; Network Receive packet routine. Request a net packet with no-wait option.
  1300. ; Return carry clear if success. If failure, reset serial port (Server mode
  1301. ; reinits serial port) and return carry set. No entry setup needed.
  1302. RECEIVE PROC    NEAR                    ; receive network session pkt
  1303. RECEIVE ENDP
  1304.  
  1305. ; Network Receive post processing interrupt routine.
  1306. ; Copy chars from rcvbuf to circular buffer source, act on xon/xoff,
  1307. ; clear rposted interlock flag. At entry, CS is our code segment,
  1308. ; es:bx points to scb, netbios stack, interrupts are off.
  1309. RPOST   PROC    FAR             ; network receive post interrupt routine
  1310. RPOST   endp
  1311.  
  1312. ; Put the char in AH to the serial port.  This assumes the
  1313. ; port has been initialized.  Should honor xon/xoff.  Skip returns on
  1314. ; success, returns normally if the character cannot be written.
  1315. ; 21 Feb 1987 Add support for Bios calls (Clone) [jrd]
  1316. ; 25 April 1987 Add Netbios support [jrd]
  1317. ; 16 May 1987 Add entry point OUTCH2 for non-flow controlled sending to
  1318. ; prevent confusion of flow control logic at top of outchr; used by receiver
  1319. ; buffer high/low water mark flow control code. [jrd]
  1320.  
  1321. ; XON/XOFF is handled by the BIOS an NEC                RFG
  1322.  
  1323. OUTCHR  PROC    NEAR
  1324.         push    dx
  1325.         push    bx
  1326.         mov     al,ah           ; parity works on AH
  1327.         call    dopar           ; do parity work before sending
  1328.         mov     ah,3            ; NEC ROM BIOS send character in AL
  1329.         int_rs232               ; Call ROM BIOS send character in AL
  1330.         cmp     ah,0            ; check return status
  1331.         je      outc1           ; 0 = everything normal
  1332.                                 ; 1 = port not initialized
  1333.                                 ; 2 = (receive) buffer overflow
  1334.                                 ; 3 = timed out
  1335.         call    beep            ; say something
  1336.         mov     ah,prstr
  1337.         mov     dx,offset outfail
  1338.         int     dos
  1339.         pop     bx
  1340.         pop     dx
  1341.         ret                     ; and return (abnormally?)
  1342. outc1:
  1343.         pop     bx
  1344.         pop     dx
  1345.         jmp     rskp
  1346. OUTCHR  ENDP
  1347.  
  1348. ; Network Send packet routine. Send xmt scb with no-wait option. Waits
  1349. ; up to 6 seconds for current Send to complete before emitting new Send.
  1350. ; Failure to Send resets serial port (Server mode allows reiniting of serial
  1351. ; port). Returns carry clear for success, carry set for failure.
  1352. ; Enter with xmtcnt holding length of data in xmtbuf to be sent.
  1353. SEND    PROC    NEAR                    ; Network. Send session packet
  1354. SEND    ENDP
  1355.  
  1356. ; Network Send packet completion interrupt routine. At entry CS is our
  1357. ; code segment, es:bx points to scb, netbios stack, interrupts are off.
  1358. SPOST   PROC    NEAR                    ; post routine for Send packets
  1359. SPOST   ENDP
  1360.  
  1361. ; dispatch prebuilt network session scb, enter with bx pointing to scb.
  1362. ; returns status in al (and ah too). Allows STARLAN Int 2ah for netint.
  1363. SESSION PROC    NEAR
  1364. SESSION ENDP
  1365.  
  1366. ; Make a virtual circuit Session, given preset scb's from proc chknet.
  1367. ; For Server mode, does a Listen to '*', otherwise does a Call to indicated
  1368. ; remote node. Updates vcid number in scb's. Shows success or fail msg.
  1369. ; Updates network status byte pcnet to 2 if session is established.
  1370. ; Does nothing if a session is active upon entry; otherwise, does a network
  1371. ; hangup first to clear old session material from adapter board. This is
  1372. ; the second procedure to call in initializing the network for usage.
  1373. SETNET  PROC    NEAR                    ; Network, make a connection
  1374. SETNET  ENDP
  1375.  
  1376. ; Called only when Kermit exits. Name passed to mssker by proc chknet
  1377. ; in word netdone.
  1378. NETCLOSE PROC   NEAR                    ; close entire network connection
  1379. NETCLOSE ENDP
  1380.  
  1381. ; Start connection process to network. Obtains Network board local name
  1382. ; and appends '.K' to form Kermit's local name (removed when Kermit exits).
  1383. ; If no local name is present then use name 'mskermit.K'.
  1384. ; Sets local name in scb's for xmt, rcv, lsn. (Does not need DOS 3.x)
  1385. ; Sets NETDONE pointer to procedure netclose for Kermit exit.
  1386. ; Verifies existance of interrupt 5ch support, verifies vendor specific
  1387. ; support for BREAK and other features, sets network type bit in nettype,
  1388. ; sets BREAK support in nsbrk, hangsup old session if new node name given,
  1389. ; fills in local and remote node names and name number in scbs (including ISN
  1390. ; names for STARLAN), and sets network status byte pcnet to 0 (no net) or
  1391. ; to 1 (net ready). This is the first procedure called to init network usage.
  1392. ; Byte count of new host name is in temp from COMS.
  1393. chknet  proc    near
  1394. chknet  endp
  1395.  
  1396. ; local routine to see if we have to transmit an xon
  1397. ; its handled by the hardware on the NEC                        RFG
  1398. chkxon  proc    near
  1399. chkxon  endp
  1400.  
  1401. ; IHOSTS - Initialize the host by sending XON, or equivalent, and enter the
  1402. ; cycle of clear input buffer, wait 1 second, test if buffer empty then exit
  1403. ; else repeat cycle. Requires that the port be initialized before hand.
  1404. ; Ihosts is used by the local send-file routine just after initializing
  1405. ; the serial port.
  1406. ; 22 March 1986 [jrd]
  1407. ; 22 June 1986 Don't send null char if not using flow control. [jrd]
  1408.  
  1409. IHOSTS  PROC    NEAR
  1410.         push    ax              ; save the registers
  1411.         push    bx
  1412.         push    cx
  1413.         push    dx
  1414.         mov     bx,portval      ; port indicator
  1415.         mov     ax,[bx].flowc   ; put Go-ahead flow control char in ah
  1416.         or      ah,ah           ; check for null char
  1417.         jz      ihostr1         ; z = null, don't send it
  1418.         call    outchr          ; send it (release Host's output queue)
  1419.          nop                    ; outchr can do skip return
  1420.          nop
  1421.          nop
  1422. ihosts1:call    clrbuf          ; clear out interrupt buffer
  1423.         mov     ax,1            ; sleep for 1 second
  1424.         call    sleep           ; procedure sleep is in msscom.asm
  1425.         call    prtchr          ; check for char at port
  1426.          jmp    ihosts1         ; have a char in al, repeat wait/read cycle
  1427.          nop                    ; prtchr does skip return on empty buffer
  1428.         pop     dx              ; empty buffer. we are done here.
  1429.         pop     cx
  1430.         pop     bx
  1431.         pop     ax
  1432.         ret
  1433. IHOSTS  ENDP
  1434.  
  1435. ; IHOSTR - initialize the remote host for our reception of a file by
  1436. ; sending the flow-on character (XON typically) to release any held
  1437. ; data. Called by receive-file code just after initializing the serial
  1438. ; port.         22 March 1986 [jrd]
  1439. IHOSTR  PROC    NEAR
  1440.         push    ax              ; save regs
  1441.         push    bx
  1442.         push    cx
  1443.         mov     bx,portval      ; port indicator
  1444.         mov     ax,[bx].flowc   ; put Go-ahead flow control char in ah
  1445.         or      ah,ah           ; check for null char
  1446.         jz      ihostr1         ; z = null, don't send it
  1447.         call    outchr          ; send it (release Host's output queue)
  1448.          nop                    ; outchr can do skip return
  1449.          nop
  1450.          nop
  1451. ihostr1:pop     cx
  1452.         pop     bx
  1453.         pop     ax
  1454.         ret
  1455. IHOSTR  ENDP
  1456.  
  1457. ; Send a break out the current serial port.  Returns normally.
  1458. ; an APC specific version                               RFG
  1459.  
  1460. SENDBR  PROC    NEAR
  1461.         push    dx
  1462.         push    cx
  1463.         push    ax
  1464.  
  1465.         mov     ah,prstr                ; tell the user on the status line
  1466.         mov     dx,offset saybr         ;   that we're sending it
  1467.         int     dos
  1468.  
  1469.         mov     ah,5            ; set the break bit
  1470.         mov     al,stbrk
  1471.         int_rs232
  1472.         mov     ax,275          ; # of ms to wait
  1473.         call    pcwait          ; hold break for desired interval
  1474.         mov     ah,5            ; and clear the break bit
  1475.         mov     al,stnorm
  1476.         int_rs232
  1477.  
  1478.         pop     ax
  1479.         pop     cx
  1480.         pop     dx
  1481.         ret
  1482. SENDBR  ENDP
  1483. SENDBL  PROC    NEAR                    ; Send a long break
  1484.         push    dx
  1485.         push    cx
  1486.         push    ax
  1487.  
  1488.         mov     ah,prstr                ; tell the user on the status line
  1489.         mov     dx,offset saybr         ;   that we're sending it
  1490.         int     dos
  1491.  
  1492.         mov     ah,5            ; set the break bit
  1493.         mov     al,stbrk
  1494.         int_rs232
  1495.         mov     ax,1800          ; # of ms to wait
  1496.         call    pcwait          ; hold break for desired interval
  1497.         mov     ah,5            ; and clear the break bit
  1498.         mov     al,stnorm
  1499.         int_rs232
  1500.  
  1501.         pop     ax
  1502.         pop     cx
  1503.         pop     dx
  1504.         ret
  1505. SENDBL  ENDP
  1506.  
  1507.  
  1508. ; Initialization for using serial port.  This routine performs
  1509. ; any initialization necessary for using the serial port, including
  1510. ; setting up interrupt routines, setting buffer pointers, etc.
  1511. ; Doing this twice in a row should be harmless (this version checks
  1512. ; a flag and returns if initialization has already been done).
  1513. ; SERRST below should restore any interrupt vectors that this changes.
  1514.  
  1515. ;************* RAL *****************************************************
  1516. ;* Page SE-10 MS-DOS Programmers Manual
  1517. ;* Performs Serial Port Initialization.............
  1518. ;***********************************************************************
  1519.  
  1520. ; Various mods to allow 3 ports and setting timeout parameters so that we
  1521. ;       won't hang forever if the line dies.                    RFG
  1522.  
  1523. SERINI  PROC    NEAR
  1524.     call serrst        ; Turn off the unused ports to avoid
  1525.                 ; characters coming in and causing a
  1526.                 ; d.e.l.a.y.e.d CRASH
  1527.  
  1528.         push es
  1529.         push di
  1530.         push    si              ; additional save               RFG
  1531.  
  1532.         mov AX,datas            ; point at start of this segement?
  1533.         mov ES,AX
  1534.         mov DI,offset source    ; Point at Serial Buffer....
  1535.  
  1536.         mov bx,portval
  1537.         mov parmsk,0ffh         ; parity mask, assume parity is None. [jrd]
  1538.         cmp [bx].parflg,parnon  ; is it None?
  1539.         je serin3               ; e = yes
  1540.         mov parmsk,07fh         ; no, pass lower 7 bits as data
  1541. serin3:
  1542.         mov si,[bx].baud        ; get baud rate index pointer..
  1543.         mov ah,[bx].floflg
  1544.  
  1545.         mov al,baudtab[si]      ; load up baud rate.........
  1546.  
  1547.                                 ; AH = 1 XON/XOFF flow control
  1548.                                 ; AH = 0 No Flow control
  1549.                                 ; Page SE-10 NEC Programmer Ref manual
  1550.  
  1551.         cmp     AH,0            ; doing flow control?
  1552.         je      NoFlow          ; 0 if not flow control
  1553.  
  1554.         mov ah,1                ; Init with Xon/Xoff
  1555.  
  1556. NoFlow:
  1557.         mov ch,uart             ; set up various UART parameters
  1558.  
  1559.         mov dx,bufsiz           ; load with Buffer Size...bufsiz in mssdef.h
  1560.                                 ;    (currently 2048 bytes)
  1561.                                 ; NB that since the BIOS uses 1 word per char,
  1562.                                 ;    this means the buffer is really only
  1563.                                 ;    bufsiz/2 long. (1 sec at 9600 baud)
  1564.                                 ; Due to a bug in the BIOS, the size is
  1565.                                 ;    miscalculated by the 20 bytes used at
  1566.                                 ;    the front by the BIOS for pointers, etc.;
  1567.                                 ;    without the pad put into the 'source'
  1568.                                 ;    definition, the handler would simply
  1569.                                 ;    overwrite the following data area.
  1570.                                 ; This is a circular buffer managed entirely
  1571.                                 ;    by the BIOS with XON set at 3/4 DX and
  1572.                                 ;    XOFF set at 1/4 DX.
  1573.  
  1574.  
  1575.         mov bh,2                ; time out on send is this number *500 ms
  1576.                                 ;       0 = infinity                    RFG
  1577.                                 ; this should /not/ affect waiting for XON
  1578.                                 ;       from the host (handled in BIOS again)
  1579.         mov bl,4                ; time out on receive is this number *500 ms
  1580.                                 ;       0 = infinity                    RFG
  1581.                                 ; since we're checking buffer before we read
  1582.                                 ;       (see prtchr), shouldn't be necessary.
  1583.  
  1584.         mov CL,stnorm           ; see NEC Ref Guide, Page SE-11     RFG
  1585.         mov CH,uart             ; set up various parameters....   again
  1586.  
  1587.         int_rs232               ; Call NEC Rom
  1588.  
  1589.         cmp ah,0                ; Did everything go ok??
  1590.         je serinx               ; continue if so...
  1591.         call    beep            ; otherwise, notify the authorities
  1592.         mov     ah,prstr
  1593.         mov     dx,offset initfail
  1594.         int     dos
  1595. serinx:
  1596.         pop     si              ; additional restore            RFG
  1597.         pop di
  1598.         pop es
  1599.         ret                     ; We're done. [21c]
  1600. SERINI  ENDP
  1601.  
  1602. ; Reset the serial port.  This is the opposite of serini.  Calling
  1603. ; this twice without intervening calls to serini should be harmless.
  1604. ; Returns normally.
  1605. ; in NEC land, we simply turn everyone OFF.        RFG
  1606.  
  1607. SERRST  PROC    NEAR
  1608.  
  1609.         push es
  1610.         push di
  1611.         push si
  1612.  
  1613.         mov AX,datas            ; point at start of this segement?
  1614.         mov ES,AX
  1615.         mov DI,offset source    ; Point at Serial Buffer....
  1616.  
  1617.     mov ch,uart        ; just as a formality
  1618.         mov cl,stoff            ; now we turn unused ports dead off 'cause
  1619.                                 ; if we don't, and come characters come in,
  1620.                                 ; we get a d.e.l.a.y.e.d crash!
  1621.         mov ah,0                ; initialize port mode
  1622.         mov al,0                ; baud probably irrelevant
  1623.         mov dx,bufsiz           ; just to give it a valid number
  1624.         mov bh,0                ; zip to the high byte
  1625.         mov bl,0                ; turn port 1 off
  1626.         mov si,bx
  1627.         int 1EH                 ; could have used 1AH here
  1628.     mov ch,uart
  1629.         mov cl,stoff
  1630.         mov ah,0
  1631.         mov al,0
  1632.         mov dx,bufsiz
  1633.         mov bh,0
  1634.         mov bl,1                ; turn port 2 off
  1635.         mov si,bx
  1636.         int 1EH
  1637.     mov ch,uart
  1638.         mov cl,stoff
  1639.         mov ah,0
  1640.         mov al,0
  1641.         mov dx,bufsiz
  1642.         mov bh,0
  1643.         mov bl,2                ; turn port 3 off
  1644.         mov si,bx
  1645.         int 1EH
  1646.  
  1647.         pop si
  1648.         pop di
  1649.         pop es
  1650.  
  1651.         ret                     ; All done.
  1652. SERRST  ENDP
  1653.  
  1654. ; Dummy Interrupt 14H to defeat DOS interference with serial port when CTTY
  1655. ; and Kermit use the port simultaneously. If ports differ then chain DOS to
  1656. ; original Int 14H Bios code. Else return dummy status=ok reports and
  1657. ; Backspace for Read, ignore char for Write.
  1658. ; Entered with AH = function request, AL = char to be sent, DX = com port num
  1659. ; CS is our code segment, DS is DOS's, SS is ours or DOS's, interrupts off.
  1660. ; 25 June 1987 [jrd]
  1661. SERDUM  PROC    FAR
  1662. SERDUM  ENDP
  1663.  
  1664. ; serial port interrupt routine.  This is not accessible outside this
  1665. ; module, handles serial port receiver interrupts.
  1666. ; Revised on 22 May 1986, again 2 August 1986 to run at 38.4kb on PC's. [jrd]
  1667. ; Srcpnt holds offset, within buffer Source, where next rcv'd char goes.
  1668. ; Count is number of chars now in buffer, and oldest char is srcpnt-count
  1669. ; done modulo size of Source. All pointer management is handled here.
  1670. ; Control-G char substituted for char(s) lost in overrun condition. [jrd]
  1671. ; Upgraded to read cause of interrupt from interrupt ident reg (accepts only
  1672. ;  data ready), chain to old interrupt if source is not our device. [jrd]
  1673.  
  1674. SERINT  PROC  FAR
  1675. SERINT  ENDP
  1676.  
  1677. DTRLOW  PROC    NEAR            ; Global proc to Hangup the Phone or Network
  1678.                                 ; by making DTR and RTS low (phone). [jrd]
  1679.         mov ah,cmtxt            ; allow text, to be able to display help
  1680.         mov bx,offset rdbuf     ; dummy buffer
  1681.         mov dx,offset hnghlp    ; help message
  1682.         call comnd              ; get a confirm
  1683.          jmp r
  1684.         call serhng             ; drop DTR and RTS
  1685.         mov ah,prstr            ; give a nice message
  1686.         mov dx,offset hngmsg
  1687.         int dos
  1688.         jmp rskp
  1689. DTRLOW  ENDP
  1690.  
  1691. ; 5 April 1987 Add 500 millisec wait with lines low before returning. [jrd]
  1692. ; Calling this twice without intervening calls to serini should be harmless.
  1693. ; If network then call nethangup procedure to hangup the session without
  1694. ; losing local name information.
  1695. ; Returns normally.
  1696.  
  1697. serhng  proc    near    ; clear modem's delta status bits and lower DTR & RTS
  1698.         push    ax
  1699.         mov     ah,5            ; direct to the UART
  1700.         mov     al,stdtr        ; lower the boom
  1701.         int_rs232               ; drop the DTR
  1702.         mov     ax,500         ; hold it low for a bit
  1703.         call    pcwait
  1704.         pop     ax
  1705.         ret
  1706. serhng  endp
  1707.  
  1708. ; Jumping to this location is like retskp.  It assumes the instruction
  1709. ;   after the call is a jmp addr.
  1710.  
  1711. RSKP    PROC    NEAR
  1712.         pop     bp
  1713.         add     bp,3
  1714.         push    bp
  1715.         ret
  1716. RSKP    ENDP
  1717.  
  1718. ; Jumping here is the same as a ret.
  1719.  
  1720. R       PROC    NEAR
  1721.         ret
  1722. R       ENDP
  1723.  
  1724. code    ends
  1725.         end
  1726.