home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msxhp1.asm < prev    next >
Assembly Source File  |  2020-01-01  |  56KB  |  2,040 lines

  1.     name msxhp1
  2. ; File MSXHP1.ASM
  3.     include mssdef.h
  4. ;       Copyright (C) 1982,1991, Trustees of Columbia University in the
  5. ;       City of New York.  Permission is granted to any individual or
  6. ;       institution to use, copy, or redistribute this software as long as
  7. ;       it is not sold for profit and this copyright notice is retained.
  8. ; System dependent module for HP150.
  9. ; Use with file MSUHP1.ASM (keyboard translator)
  10. ; Edit history
  11. ; 2 March 1991 version 3.10
  12. ; Nov. 24, 1990. Remove references to prserr to make linker happy.
  13. ; Nov. 21, 1990. Dump capture buffer (cptdmp) when exiting connect mode. [jan]
  14. ; Sept. 1990. Read 20 characters a time from dcomm. Read keyboard
  15. ;  once every 16 reads of dc port. Start port at 7 bits so firmware
  16. ;  flow control works. Disable our own flow control. Now works at 4800
  17. ;  baud with no flow control.
  18. ; August 1990 update to 3.0. Incorporate tektronix. Add replay. [jan].
  19. ; John Nyenhuis, Purdue University, School of Electrical Engineering
  20. ; West Lafayette, Indiana 47907 USA (317)494-3524  nyenhuis@ecn.purdue.edu
  21. ; 1 July 1988 Version 2.31
  22. ; 11 Jan 1988 update to 2.30 consistency level.
  23. ; 1 Jan 1988 version 2.30
  24.  
  25.  
  26. writechar   macro saying
  27.     pushf
  28.     push    dx
  29.     push    ax
  30.     mov    ah,2
  31.     mov    dl,saying
  32.     int    dos
  33.     pop    ax
  34.     pop    dx
  35.     popf
  36. endm
  37.  
  38. writestring   macro saying
  39.     pushf
  40.     push    ax
  41.     push    dx
  42.     mov    ah,prstr
  43.     mov    dx,offset saying
  44.     int    dos
  45.     pop    dx
  46.     pop    ax
  47.     popf
  48. endm
  49.  
  50. saveregs macro
  51.     push    ax
  52.     push    bx
  53.     push    cx
  54.     push    dx
  55.     push    es
  56.     push    di
  57.     push    si
  58.     push    ds
  59.     push    bp
  60.     pushf
  61. endm
  62.  
  63. restoreregs  macro
  64.     popf
  65.     pop    bp
  66.     pop    ds
  67.     pop    si
  68.     pop    di
  69.     pop    es
  70.     pop    dx
  71.     pop    cx
  72.     pop    bx
  73.     pop    ax
  74. endm
  75.  
  76. ;; below 40 publics are the minimum necessary
  77.     public  baudst, ihostr, bdtab, getbaud, chrout, pcwait, putmod
  78.     public  serrst, trnprs, prtchr, poscur, outchr, dtrlow, vts, puthlp
  79.     public    vtstat, coms, cquery, ctlu, shomodem, portval, getmodem
  80.     public  term, dumpscr, cmblnk, cquit, locate, clearl, machnam, lclini
  81.     public  sendbl, comptab, sendbr, clrmod, cstatus, termtb, serhng
  82.     public  clrbuf, beep, serini
  83. ;;additional system dependent publics
  84.     public    termtog, kclrscn, kdos, snull, cquit, cquery
  85.     public    toterminal, klogtog, setchtab, vtstbl
  86.  
  87. false    equ    0
  88. true    equ    1
  89. instat    equ    6
  90. print_out equ    05h            ; dos function to print to printer
  91. prtscr    equ    80h            ; print screen pressed
  92.  
  93. wrdev    equ    40H
  94. rddev    equ    3fH
  95. open    equ    3dH
  96. close    equ    3eH
  97. rdchan    equ    2
  98. e_send_break equ 6
  99. e_ioctl equ    44h        ; DOS i/o control function
  100. passall equ    0803h        ; Port transparency mode [WHM]
  101. xofcnt    equ    32        ; number of characters to send xoff
  102. xoncnt    equ    16        ; number of characters to send xon
  103. dos201    equ    201h
  104. dos211    equ    20bh        ; dosnum for 2.11
  105. data   segment public 'data'
  106.     extrn    lclexit:word, flags:byte, trans:byte, dmpname:byte
  107.     extrn    kbdflg:byte, rxtable:byte, denyflg:word, repflg:byte
  108.     extrn    diskio:byte ; for replay feature
  109.     extrn    dosnum:word, agiosbuff:byte
  110.     extrn    sloghnd:word     ; session log handle from msster
  111.     extrn    prnhand:word
  112.  
  113. machnam db    'HP-150$'
  114. erms40    db    cr,lf,'?Warning: Unrecognized baud rate$'
  115. erms41    db    cr,lf,'?Warning: Cannot open com port$'
  116. noimp    db    cr,lf,'Command not implemented.$'
  117. hngmsg    db    cr,lf,' The phone should have hungup.',cr,lf,'$'
  118. hnghlp    db    cr,lf,' The modem control lines DTR and RTS for the current'
  119.     db    ' port are forced low (off)'
  120.     db    cr,lf,' to hangup the phone. Normally, Kermit leaves them'
  121.     db    ' high (on) when it exits.'
  122.     db    cr,lf,'$'
  123. msmsg1    db    cr,lf,' Communications port is not ready.$'
  124. msmsg2    db    cr,lf,' Communications port is ready.$'
  125. rdbuf    db    80 dup (0)        ; temp buf
  126. setktab db    0
  127. setkhlp db    0
  128. shkmsg    db    '?Not implemented.'
  129. shklen    equ    $-shkmsg
  130. anspflg    db    0            ; printing active status
  131. crlf    db    cr,lf,'$'
  132. delstr    db    BS,BS,'  ',BS,BS,'$'    ; Delete string
  133. clrlin    db    cr,ESCAPE,'K$'
  134. xofsnt    db    0            ; Say if we sent an XOFF
  135. xofrcv    db    0            ; Say if we received an XOFF
  136. invseq    db    ESCAPE,'&dJ$'        ; Reverse video
  137. nrmseq    db    ESCAPE,'&d@$'        ; Normal mode
  138. ivlseq    db    80 dup (' '),ESCAPE,'A','$' ; [ak] Make a line inverse video
  139. keydelay db 0                ; delay for keyboard reads
  140. tmp    db    0,'$'
  141. temp    dw    0
  142. temp1    dw    0
  143. temp2    dw    0
  144.  
  145. eightstatustxt    db 'No. Bits: $'
  146. eightflg    db eightbitnum
  147. transparencytxt db 'Port Status: $'
  148. transparentflg    db transonnum
  149. rawtxt        db 'Port Mode: $'
  150. rawflg        db rawonnum
  151. tekstatustxt    db 'Tek Auto Entry: $'
  152. tekbyte        db tekonnum      ; tek auto entry
  153. temp3        dw 0
  154.  
  155.  
  156. ; structure for status information table sttab.
  157. stent    struc
  158. sttyp    dw  0            ; type (actually routine to call)
  159. msg    dw  0            ; message to print
  160. val2    dw  0            ; needed value: another message, or tbl addr
  161. tstcel    dw  0            ; address of cell to test, in data segment
  162. basval    dw  0            ; base value, if non-zero
  163. stent    ends
  164.  
  165.             ; table with datacomm status for the status command
  166. vtstbl stent <srchkw,eightstatustxt,termtb,eightflg> ; tell 7 or 8 bits
  167. stent <srchkw,transparencytxt,termtb,transparentflg> ; tell if transparent
  168. stent <srchkw,rawtxt,termtb,rawflg>        ; tell if raw or cooked
  169. stent <srchkw,tekstatustxt,termtb,tekbyte>    ; tell if raw or cooked
  170.     dw 0                    ; end of table
  171.  
  172. ; Entries for choosing communications port
  173. comptab db    4                ; four entries
  174.     mkeyw    '1',1
  175.     mkeyw    '2',2
  176.     mkeyw    'COM1',1
  177.     mkeyw    'COM2',2
  178.  
  179. port1    prtinfo    <0FFFH,0,defpar,1,0,defhand,floxon,0>
  180. port2    prtinfo    <0FFFH,0,defpar,1,0,defhand,floxon,0>
  181. portval    dw    port1            ; Default is to use port 1
  182.  
  183. bdtab    db     9                   ; baud rate table
  184.      mkeyw     '110',0
  185.      mkeyw     '150',1
  186.      mkeyw     '300',2
  187.      mkeyw     '600',3
  188.      mkeyw     '1200',4
  189.      mkeyw     '2400',5
  190.      mkeyw     '4800',6
  191.      mkeyw     '9600',7
  192.      mkeyw     '19200',8
  193.  
  194.              ; mappings for baud settings from hp to our table
  195. ourbdtab db  0,0       ; not applicable
  196.      db  1,0       ; na
  197.      db  2,0       ; 110
  198.      db  3,0       ; na
  199.      db  4,1       ; 150
  200.      db  5,2       ; 300
  201.      db  6,3       ; 600
  202.      db  7,4       ; 1200
  203.      db  8,0       ; na
  204.      db  9,0       ; na
  205.      db  10,5       ; 2400
  206.      db  11,0       ; na
  207.      db  12,6       ; 4800
  208.      db  13,0       ; na
  209.      db  14,7       ; 9600
  210.      db  15,8       ; 19200
  211.                  ; mappings for baud setting from our table to hp
  212. ourbdtab1  db  0,2       ; 300
  213.      db  1,4       ; 150
  214.      db  2,5       ; 300
  215.      db  3,6       ; 600
  216.      db  4,7       ; 1200
  217.      db  5,10       ; 2400
  218.      db  6,12       ; 4800
  219.      db  7,14       ; 9600
  220.      db  8,15       ; 19200
  221.  
  222.  
  223. setchtab  db   1; set file character-set table
  224.     mkeyw      'CP437',437
  225.  
  226. sevenbitnum    equ 7
  227. eightbitnum    equ 8
  228. transonnum    equ 9
  229. transoffnum    equ 10
  230. rawonnum    equ 11
  231. rawoffnum    equ 12
  232. tekonnum    equ 13
  233. tekoffnum    equ 14
  234.  
  235. termtb    db    10           ; entries for Status, not Set
  236.     mkeyw    'HP150',ttgenrc
  237.     mkeyw    'Tek4014',tttek
  238.     mkeyw    '7bit',sevenbitnum
  239.  
  240.     mkeyw    '8bit',eightbitnum
  241.     mkeyw    'OnTransparency',transonnum
  242.     mkeyw    'OffTransparency',transoffnum
  243.     mkeyw    'Raw',rawonnum
  244.     mkeyw    'Cooked',rawoffnum
  245.     mkeyw    'EnableTek',tekonnum
  246.     mkeyw    'DisableTek',tekoffnum
  247.  
  248.  
  249. ; variables for serial interrupt handler
  250.  
  251. source    db    bufsiz DUP(?)    ; Buffer for data from port
  252. bufout    dw    0        ; buffer removal ptr
  253. count    dw    0        ; Number of chars in int buffer
  254. bufin    dw    0        ; buffer insertion ptr
  255. telflg    db    0        ; Are we acting as a terminal
  256. clreol    db    ESCAPE,'K$'
  257. prttab    dw    com1,com2
  258. com1    db    'COM1',0
  259. com2    db    'COM2',0
  260. blank    db    ESCAPE,'H',ESCAPE,'J$'
  261. movcur    db    ESCAPE,'&a'
  262. colno    db    20 dup (0)
  263. ten    db    10
  264. prthnd    dw    0
  265. argadr    dw    0        ; address of arg blk from msster.asm
  266. parmsk    db    0ffh        ; 8/7 bit parity mask, for reception
  267. flowoff db    0        ; flow-off char, Xoff or null (if no flow)
  268. flowon    db    0        ; flow-on char, Xon or null
  269. captrtn dw    cptchr        ; routine to call for captured output
  270. logflag db    false        ; if true, we are logging session
  271. ; (we have taken cptchr from msster and placed in
  272. ; in msxhp1 to avoid flow control problems)
  273. tempbuf dw    10 dup(0)
  274. ourarg    termarg <>
  275.  
  276. ;;new stuff to scan escape sequences from comm port  [jan]
  277. stringtab    dw    tekst1,tekst2     ; strings for matching
  278.         dw    tekst3
  279. numstrings    equ   3            ; number of strings to match
  280. disptab        dw    toteknoplay,totekplay      ; dispatch table
  281.         dw    leavetek
  282.         dw    ignoreall, ignoreall
  283. tekst1        db    escape,'[?38h',0    ;1st string to get into tek mode [jan]
  284. tekst2        db    escape,FF,0    ;2nd string to get into tek mode [jan]
  285. tekst3        db    escape,'[?38l',0    ; string to exit tekmode
  286. stringchekbuff    db    16 dup (0)
  287. stringchekcnt    dw     0        ; characters already in buffer
  288. matchsofar    dw    false        ; no match yet
  289. match        dw    0
  290. playem        db    false        ; don't play back switch characters
  291. ; end of data for string scannine
  292. prtrdy        db    true     ; if false, we get out of connect mode
  293.  
  294. capbuf        db     cptsiz dup (0)    ; session logging buffer
  295. capbp        dw     capbuf
  296. caplft        dw     cptsiz
  297. capterr        db escape,'Error in writing log file ','$'
  298. alpha_disp  db escape,'&s0P',escape,'&s0Q','$'          ; alpha active
  299. tek_disp    db escape,'&s1P',escape,'&s0Q',escape,'*t1D','$' ; tek active
  300. alpha_on    db escape,'*dE','$'        ; turn on alpha display
  301. alpha_off   db escape,'*dF','$'        ; turn off alpha display
  302. tek_on        db escape,'*dC','$'          ; turn on tek display
  303. tek_off        db escape,'*dD','$'          ; turn off tek display
  304. alpha_clear db escape,'H',escape,'J', '$' ; clear alpha
  305. tek_clear   db escape,'*dA',escape,'*dL',escape,'*d0,380O','$'; clear tek
  306. to_term_msg db 'Entering Firmware terminal '
  307.         db 'Press SHIFT STOP to return to Kermit','$'
  308.  
  309. ;;;; Data for reading data comm configuration in firmware
  310. ;*******************************************
  311. ;
  312. e_cnp_rom_segment equ 0000h
  313. e_cnp_entry equ 045ch
  314. e_dhp_entry equ 0425h
  315. e_dhp_driver equ 042ah
  316. e_long_call equ 09ah
  317. ;
  318. e_port1_read    equ 2
  319. e_port2_read    equ 4
  320. e_port1_save    equ 2
  321. e_port2_save    equ 11
  322.  
  323. e_port1    equ 1             ; values for the two physcial ports.
  324. e_port2 equ 2
  325.  
  326. e_true equ 1
  327. e_false equ 0
  328. ;
  329. ;************** LOCAL DECLARATIONS **************
  330. ;
  331. ;
  332. CONFIGURATION_DATA_AREA struc
  333. predef_values db ?
  334. barrel_index db ?
  335. dc_port db ?
  336. dc_bool1 db ?
  337. dc_bool2 db ?
  338. dc_baud_rate db ?
  339. dc_parity db ?
  340. dc_clock db ?
  341. dc_asterisk db ?
  342. dc_recv_pace db ?
  343. dev_token  dw ? 
  344. CONFIGURATION_DATA_AREA ends
  345.  
  346. dc_status_struc struc        ; status for datacomm
  347. eightbit    db 0        ; true if 8 bit, false if 7 bit
  348. transparent    db 0      ; true if transparent, false if not transparent
  349. raw        db 0        ; true if raw, false if cooked
  350. dc_status_struc ends
  351.  
  352. ; scratch space.
  353. ;
  354. err_flag    db 0
  355. readid        dw 0
  356. saveid        dw 0
  357. work_config CONFIGURATION_DATA_AREA    <>
  358. dc_status dc_status_struc <true,true,true>
  359.  
  360. ;
  361. ;************************************
  362. ;
  363. ; Macros for absolute long calls.
  364. ;
  365. ;************************************
  366. ;
  367. call_cnp_entry macro
  368.     db  e_long_call
  369.     dw  e_cnp_entry
  370.     dw  e_cnp_rom_segment
  371. endm
  372. call_dhp_entry macro
  373.     db  e_long_call
  374.     dw  e_dhp_entry
  375.     dw  e_cnp_rom_segment
  376. endm
  377.  
  378. call_dhp_driver macro
  379.     db  e_long_call
  380.     dw  e_dhp_driver
  381.     dw  e_cnp_rom_segment
  382. endm
  383. baud_port equ 0ch    ; port address of baud rate controller
  384. ;
  385. ; table to print out value of a nibble on the screen
  386. asciitab  db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  387. ;
  388. porta_baud    db 0         ; stored baud codes
  389. portb_baud    db 0
  390. start_porta_baud db 0
  391. start_portb_baud db 0
  392. data   ends
  393.  
  394.  
  395. code    segment public 'code'
  396.     extrn    comnd:near, dopar:near, atoi:near, prompt:near
  397.     extrn    sleep:near,statc:near, srchkw:near
  398.     extrn    msuinit:near, keybd:near        ; in msuhp1.asm
  399.     extrn    keybdopen:near, keybdclose:near        ; in msuhp1.asm
  400.     extrn    getkey:near                ; in msuhp1.asm
  401.     extrn    clearlabels:near, labelsoftkeys:near    ; in msuhp1.asm
  402.     extrn    displaylogoffkey:near, displaylogonkey:near ; in msuhp1
  403.     extrn    pntchr:near, pntflsh:near
  404.  
  405.     assume    cs:code, ds:data, es:nothing
  406.  
  407. ; Clear the input buffer before sending a packet.
  408.  
  409. CLRBUF    PROC    NEAR
  410.     cmp     repflg,0        ; doing replay?
  411.     je     clrb0            ; e => no replay
  412.     ret                ; don't clear if replaying
  413. clrb0:    push     ax            ; need to save for CROSHAIR in msggri
  414.     cli
  415.     mov    ax,offset source
  416.     mov    bufin,ax
  417.     mov    bufout,ax
  418.     mov    count,0
  419.     sti
  420. clrb1:    call    prtchr            ; get a character
  421.     jnc    clrb1            ; until there aren't any more
  422.     nop
  423.     pop    ax
  424.     ret
  425. CLRBUF    ENDP
  426.  
  427. ; Common routine to clear to end-of-line
  428.  
  429. CLEARL    PROC    NEAR
  430.     push    ax
  431.     push    dx
  432.     mov    dx,offset clreol
  433.     mov    ah,prstr
  434.     int    dos
  435.     pop    dx
  436.     pop    ax
  437.     ret
  438. CLEARL endp
  439.  
  440. ; Set the baud rate for the current port, based on the value
  441. ; in the portinfo structure.  Returns carry clear.
  442.  
  443. BAUDST    PROC    NEAR
  444.     mov    dx,offset bdtab        ; baud rate table, ascii
  445.     xor    bx,bx            ; help is the table itself
  446.     mov    ah,cmkey        ; get keyword
  447.     call    comnd
  448.     jc    baudst1            ; c = failure
  449.     push    bx            ; save result
  450.     mov    ah,cmeol        ; get confirmation
  451.     call    comnd
  452.     pop    bx
  453.     jc    baudst1            ; c = failure
  454.     mov    si,portval
  455.     mov    ax,[si].baud        ; remember original value
  456.     mov    [si].baud,bx        ; set the baud rate
  457.     call    dobaud            ; use common code
  458.     clc
  459. baudst1:ret
  460. BAUDST    ENDP
  461.  
  462.                 ; on entrance bx has baud rate from bdtab
  463. dobaud    proc    near        ; updated by [jan] to set baud
  464.     mov    ax,portval
  465.     cmp    ax,offset port1 ; using port 1?
  466.     jne    dobaud1        ; ne => not using port 1
  467.     mov    al,1        ; port 1 set
  468.     mov    ah,bl        ; baud code
  469.     call    set_baud    ; set the baud rate
  470.     ret
  471. dobaud1:mov    al,2        ;  set port 2 baud
  472.     mov    ah,bl        ; ah has baud code
  473.     call    set_baud
  474.     ret
  475. dobaud endp
  476.  
  477. ; Send the break signal out data comm
  478. sendbl:                    ; long break (same as regular h
  479. sendbr: mov    al,e_send_break        ; regular break
  480.     call    dc_ioctl
  481.     clc                ; clear carry bit (stay in Connect)
  482.     ret
  483.  
  484. ; Set some data comm ioctl option.  AL has function code
  485. dc_ioctl proc    near
  486.     push    ax            ; save regs
  487.     push    bx
  488.     push    cx
  489.     push    dx
  490.     mov    ah,8h
  491.     mov    tempbuf,ax
  492.     mov    dx,offset tempbuf
  493.     mov    ah,e_ioctl
  494.     mov    al,3
  495.     mov    bx,prthnd
  496.     mov    cx,2
  497.     int    dos
  498.     pop    dx            ; restore regs
  499.     pop    cx
  500.     pop    bx
  501.     pop    ax
  502.     ret
  503. dc_ioctl endp
  504.  
  505. shomodem proc    near
  506.     mov    ah,cmeol    ; get a confirm
  507.     call    comnd
  508.     jnc    shomod00    ; nc => success
  509.     ret            ; get out if failure
  510. shomod00:
  511.     cmp    prthnd,0    ; Got a handle yet?
  512.     jne    shmod0        ; Yup just go on
  513.     call    opnprt        ; Else 'open' the port
  514. shmod0: mov    dx,offset msmsg1 ; say port is not ready
  515.     mov    bx,prthnd
  516.     mov    al,7        ; output status command
  517.     mov    ah,ioctl    ; ask DOS to look for us
  518.     int    dos
  519.     jc    shmod1        ; c = call failed, device not ready
  520.     or    al,al
  521.     jz    shmod1        ; not ready
  522.     mov    dx,offset msmsg2 ; say port is ready
  523. shmod1: mov    ah,prstr
  524.     int    dos
  525.     clc
  526.     ret
  527. shomodem endp
  528.  
  529. getmodem proc near
  530.     mov    al,0
  531.     ret
  532. getmodem endp
  533.  
  534. ; Put the char in AH to the serial port.  This assumes the
  535. ; port has been initialized.  Should honor xon/xoff.  Skip returns on
  536. ; success, returns normally if the character cannot be written
  537. outchr    proc    near
  538.     push    cx
  539.     or    ah,ah        ; sending a null?
  540.     jz    outch2        ; z = yes
  541.     xor    cx,cx        ; clear counter
  542.     cmp    ah,flowoff    ; sending xoff?
  543.     jne    outch1        ; ne = no
  544.     mov    xofsnt,false    ; supress xon from chkxon buffer routine
  545. outch1: cmp    xofrcv,true    ; Are we being held?
  546.     jne    outch2        ; No - it's OK to go on
  547.     loop    outch1        ; held, try for a while
  548.     mov    xofrcv,false    ; timed out, force it off and fall thru
  549. outch2: push    dx        ; Save register
  550.     mov    al,ah        ; Parity routine works on AL
  551.     call    dopar        ; Set parity appropriately
  552.                 ; Begin revised output routine
  553.     mov    byte ptr temp,al ; put data there
  554.     cmp    prthnd,0    ; Got a handle yet?
  555.     jne    outch3        ; Yup just go on
  556.     call    opnprt        ; Else 'open' the port
  557. outch3: push    bx
  558.     mov    bx,prthnd    ; port handle
  559.     mov    cx,1        ; one byte to write
  560.     mov    dx,offset temp    ; place where data will be found
  561.     mov    ah,write2    ; dos 2 write to file/device
  562.     int    dos
  563.     pop    bx        ; restore registers
  564.     pop    dx
  565.     pop    cx
  566.     clc
  567.     ret
  568. outchr    endp
  569.  
  570. ; Get a file handle for the communications port.  Use DOS call to get the
  571. ; next available handle.  If it fails, ask user what value to use (there
  572. ; should be a predefined handle for the port, generally 3).  The open
  573. ; will fail if the system uses names other than "COM1" or "COM2".
  574. opnprt    proc  near
  575.     mov    al,flags.comflg
  576.     dec    al        ; flags.comflg is 1 for com1, 2 for com2
  577.     mov    ah,0
  578.     push    si
  579.     mov    si,ax
  580.     shl    si,1            ; double index
  581.     mov    dx,prttab[si]
  582.     pop    si
  583.     mov    ah,open2
  584.     mov    al,2
  585.     int    dos
  586.     jnc    opnpr2
  587.     mov    ah,prstr        ; it didn't like the string
  588.     mov    dx,offset erms41
  589.     int    dos
  590.     ret
  591. opnpr2: mov    prthnd,ax        ; Call succeeded
  592.     call    set_port_param        ; set appropriate parameters
  593.     call    serini            ; set appropriate parameters
  594.     ret
  595. opnprt    endp
  596.  
  597. ; This routine blanks the screen.
  598.  
  599. CMBLNK    PROC    NEAR        ; This is stolen from the IBM example
  600.     push    ax
  601.     push    dx
  602.     mov    ah,prstr
  603.     mov    dx,offset blank
  604.     int    dos
  605.     pop    dx
  606.     pop    ax
  607.     ret
  608. CMBLNK    ENDP
  609.  
  610. LOCATE    PROC    NEAR
  611.     mov    dx,0        ; Go to top left corner of screen
  612.     jmp    poscur        ; Go and move the cursor
  613. LOCATE    ENDP
  614.  
  615. ; To get the baud, it is likely we would need to 
  616. ; directly access the UART. Not implemented.
  617. GETBAUD PROC    NEAR
  618.     ret
  619. GETBAUD ENDP
  620.  
  621.  
  622. ; Carry set if no character available at the port. If carry clear,
  623. ; returns with char in al, # of chars in buffer in dx.
  624.  
  625. PRTCHR    PROC    NEAR
  626.     cmp    repflg,0    ; doing replay?
  627.     je    prtch0        ; e=> not doing replay
  628.     jmp    getrepchr    ; get replay character if in replay
  629. prtch0:
  630.     push    bx
  631.     push    cx
  632.     push    si
  633.     cmp    prthnd,0    ; have a handle yet?
  634.     jne    prtch1        ; yes, keep going
  635.     call    opnprt
  636. prtch1: cmp    count,0        ; no characters?
  637.     jne    prtch2        ; no, go fill buffer
  638.     mov    bx,prthnd
  639.     mov    al,rdchan
  640.     mov    ah,ioctl
  641.     mov    dx,offset source ; buffer to read into
  642.     mov    cx,20        ; read 20 characters at a time
  643.                 ; More characters cause problems for
  644.                 ; early firmware versions
  645.     int    dos
  646.     jc    prtch4        ; c = error
  647.     mov    count,ax    ; reset count
  648.     mov    keydelay, -1    ; read keyboard next go around
  649.     mov    dx,ax        ; needed to obey rules
  650.     or    ax,ax
  651.     jz    prtch4        ; still no chars
  652.     mov    bufout,offset source ; this is output ptr
  653. prtch2: dec    count
  654.     mov    dx,count    ; return count in dx
  655.     mov    si,bufout
  656.     cld
  657.     lodsb            ; get character
  658.     mov    bufout,si    ; update ptr
  659. prtch3: pop    si
  660.     pop    cx
  661.     pop    bx
  662.     clc            ; clc if there is a character
  663.     ret            ; exit success
  664. prtch4: pop    si
  665.     pop    cx
  666.     pop    bx
  667.     stc             ; set carry if no characters
  668.     ret
  669. PRTCHR    ENDP
  670.  
  671. ; IHOSTS - Initialize the host by sending XON, or equivalent, and enter the
  672. ; cycle of clear input buffer, wait 1 second, test if buffer empty then exit
  673. ; else repeat cycle. Requires that the port be initialized before hand.
  674. ; Ihosts is used by the local send-file routine just after initializing
  675. ; the serial port.
  676. ; 22 March 1986 [jrd]
  677.  
  678. IHOSTS    PROC    NEAR
  679.     push    ax        ; save the registers
  680.     push    bx
  681.     push    cx
  682.     push    dx
  683.     mov    bx,portval    ; port indicator
  684.     mov    ax,[bx].flowc    ; put Go-ahead flow control char in ah
  685.     or    ah,ah        ; don't send null if flow = none
  686.     jz    ihosts1        ; z = null
  687.     call    outchr        ; send it (release Host's output queue)
  688. ihosts1:call    clrbuf        ; clear out interrupt buffer
  689.     pop    dx        ; empty buffer. we are done here
  690.     pop    cx
  691.     pop    bx
  692.     pop    ax
  693.     ret
  694. IHOSTS    ENDP
  695.  
  696. ; IHOSTR - initialize the remote host for our reception of a file by
  697. ; sending the flow-on character (XON typically) to release any held
  698. ; data. Called by receive-file code just after initializing the serial
  699. ; port.        22 March 1986 [jrd]
  700. IHOSTR    PROC    NEAR
  701.     push    ax        ; save regs
  702.     push    bx
  703.     push    cx
  704.     mov    bx,portval    ; port indicator
  705.     mov    ax,[bx].flowc    ; put Go-ahead flow control char in ah
  706.     or    ah,ah        ; don't send null if flow = none
  707.     jz    ihostr1        ; z = null
  708.     call    outchr        ; send it (release Host's output queue)
  709. ihostr1:pop    cx
  710.     pop    bx
  711.     pop    ax
  712.     ret
  713. IHOSTR    ENDP
  714.  
  715. DTRLOW    PROC    NEAR        ; Global proc to Hangup the Phone by making
  716.     mov    ah,cmline    ; allow text to be able to display help
  717.     mov    bx,offset rdbuf    ; dummy buffer
  718.     mov    dx,offset hnghlp ; help message
  719.     call    comnd        ; get a confirm
  720.     jnc    dtrlow1        ; nc => success
  721.     ret            ; get out if failure
  722. dtrlow1:call    serhng        ; drop DTR and RTS
  723.     writestring hngmsg    ; tell user of success
  724.     clc            ; success
  725.     ret
  726. DTRLOW    ENDP
  727.  
  728. ; Hang up the Phone. Similar to SERRST except it just forces DTR and RTS low
  729. ; to terminate the connection. 29 March 1986 [jrd]
  730. ; Calling this twice without intervening calls to serini should be harmless.
  731. ; Returns normally. Implemented by [jan].
  732. SERHNG    PROC    NEAR
  733.      mov    al,5            ; modem disconnect code
  734.      call    dc_ioctl
  735.      clc                ; stay in connect mode
  736.      ret
  737. SERHNG    ENDP
  738.  
  739. ; Position the cursor according to contents of DX
  740.  
  741. POSCUR    PROC    NEAR
  742.     push    ax            ; save regs
  743.     push    dx
  744.     push    di
  745.     push    es
  746.     mov    ax,ds
  747.     mov    es,ax            ; address data segment
  748.     cld
  749.     mov    di,offset colno
  750.     mov    al,dl            ; column
  751.     call    nout
  752.     mov    al,'c'
  753.     stosb
  754.     mov    al,dh            ; row
  755.     call    nout
  756.     mov    al,'Y'
  757.     stosb
  758.     mov    al,'$'
  759.     stosb
  760.     mov    dx,offset movcur
  761.     mov    ah,prstr
  762.     int    dos            ; print the sequence
  763.     pop    es            ; restore regs
  764.     pop    di
  765.     pop    dx
  766.     pop    ax
  767.     ret
  768. POSCUR    ENDP
  769.  
  770. NOUT    PROC    NEAR
  771.     cbw            ; extend to word
  772.     div    byte ptr ten    ; divide by 10
  773.     or    al,al        ; any quotient?
  774.     jz    nout1        ; no, forget this
  775.     push    ax        ; save current result
  776.     call    nout        ; output high order
  777.     pop    ax        ; restore
  778. nout1:    mov    al,ah        ; get digit
  779.     add    al,'0'        ; make printable
  780.     stosb
  781.     ret            ; put in buffer and return
  782. NOUT    endp
  783.  
  784. ; Write a line in inverse video at the bottom of the screen...
  785. ; the line is passed in dx, terminated by a $.    Returns normally.
  786. putmod    proc    near
  787.     push    dx        ; preserve message
  788.     mov    dx,24 * 100H    ; line 24
  789.     call    poscur
  790.     mov    dx,offset invseq ; put into inverse video
  791.     mov    ah,prstr
  792.     int    dos
  793.     pop    dx
  794.     int    dos
  795.     mov    dx,offset nrmseq ; normal videw
  796.     int    dos
  797.     ret            ; and return
  798. putmod    endp
  799.  
  800. ; Clear the mode line written by putmod.  Returns normally.
  801. clrmod    proc    near
  802.     mov    dx,24 * 100H
  803.     call    poscur
  804.     call    clearl
  805.     ret
  806. clrmod    endp
  807.  
  808. ; Put a help message one the screen in reverse video.  Pass
  809. ; the message in AX, terminated by a null.  Returns normally.
  810. ; The message is put wherever the cursor currently is located.
  811. puthlp    proc    near
  812.     push    ax            ; save some regs
  813.     push    si
  814.     push    dx
  815.     push    ax
  816.     mov    ah,prstr        ; Leave some room before the message
  817.     mov    dx,offset crlf
  818.     int    dos
  819.     pop    si            ; Put message address here
  820. puth0:    mov    ah,prstr
  821.     mov    dx,offset invseq    ; Put into reverse video
  822.     int    dos
  823.     mov    ah,prstr
  824.     mov    dx,offset ivlseq    ; Make line inverse video
  825.     int    dos
  826.     cld
  827. puth1:    lodsb
  828.     cmp    al,0            ; Terminated with a null
  829.     je    puth2
  830.     mov    dl,al
  831.     mov    ah,conout
  832.     int    dos
  833.     cmp    al,lf            ; Line feed?
  834.     je    puth0            ; e = yes, clear the next line
  835.     jmp    puth1            ; else, just keep on writing
  836. puth2:    mov    dx,offset crlf
  837.     mov    ah,prstr
  838.     int    dos
  839.     mov    dx,offset nrmseq    ; Normal video
  840.     int    dos
  841.     pop    si
  842.     pop    dx
  843.     pop    ax
  844.     ret
  845. puthlp    endp
  846.  
  847. ; Perform a delete.
  848.  
  849. DODEL    PROC    NEAR
  850.     push    ax
  851.     push    dx
  852.     mov    ah,prstr
  853.     mov    dx,offset delstr    ; Erase character
  854.     int    dos
  855.     pop    dx
  856.     pop    ax
  857.     ret
  858. DODEL    ENDP
  859.  
  860. ; Perform a Control-U.
  861.  
  862. CTLU    PROC    NEAR
  863.     push    ax
  864.     push    dx
  865.     mov    ah,prstr
  866.     mov    dx,offset clrlin
  867.     int    dos
  868.     pop    dx
  869.     pop    ax
  870.     ret
  871. CTLU    ENDP
  872.  
  873. COMS    PROC    NEAR
  874.     mov    dx,offset comptab    ; comms port table
  875.     mov    bx,0            ; use keywords as help
  876.     mov    ah,cmkey        ; parse keyword
  877.     call    comnd
  878.     jnc    coms1            ; nc => success
  879.     ret                ; get out if failure
  880. coms1:    push    bx
  881.     mov    ah,cmeol
  882.     call    comnd            ; Get a confirm
  883.     jc    comx            ; didn't get a confirm
  884.     call    serrst            ; close existing port before opening
  885.     pop    bx            ; the new one
  886.     mov    flags.comflg,bl        ; Set the comm port flag
  887.     cmp    flags.comflg,1        ; Using Com 1?
  888.     jne    coms2            ; ne = no
  889.     mov    portval,offset port1
  890.     call    serini            ; initialize new port
  891.     ret
  892. coms2:    mov portval,offset port2    ; use Com2
  893.     call serini            ; initialize port
  894.     ret
  895. comx:    pop bx
  896.     ret
  897. COMS    ENDP
  898.  
  899. VTS    PROC    NEAR            ; Set Term code
  900.     mov    dx, offset termtb
  901.     mov    bx,0
  902.     mov    ah,cmkey
  903.     call    comnd
  904.     jnc    vts1            ; nc => success
  905.     ret                ; return if failure
  906. vts1:    push    bx
  907.     mov    ah,cmeol
  908.     call    comnd
  909.     jnc    vts2            ; nc=> success
  910.     pop    bx
  911.     ret                ; return if failure
  912. vts2:    pop    bx            ; bl has number from termtb
  913.     mov    di,offset dc_status
  914.     cmp    bl,eightbitnum        ; doing 8 bits?
  915.     jne    vts3
  916.     mov    [di].eightbit,true
  917.     call    set_port_param        ; set port parameters
  918.     clc
  919.     ret
  920. vts3:    cmp    bl,sevenbitnum        ; doing 7 bits?
  921.     jne    vts4            ; ne => not 7 bits
  922.     mov    [di].eightbit,false
  923.     call    set_port_param        ; set port parameters
  924.     clc
  925.     ret
  926. vts4:    cmp    bl,transonnum        ; transparency on?
  927.     jne    vts5
  928.     mov    [di].transparent,true
  929.     call    set_port_param        ; set port parameters
  930.     clc
  931.     ret
  932. vts5:    cmp    bl,transoffnum        ; transparency off?
  933.     jne    vts6
  934.     mov    [di].transparent,false
  935.     call    set_port_param        ; set port parameters
  936.     clc
  937.     ret
  938. vts6:    cmp    bl,rawonnum        ; make port raw?
  939.     jne    vts7
  940.     mov    [di].raw,true
  941.     call    set_port_param        ; set port parameters
  942.     clc
  943.     ret
  944. vts7:    cmp    bl,rawoffnum        ; cook the port?
  945.     jne    vts7a
  946.     mov    [di].raw,false
  947.     call    set_port_param        ; set port parameters
  948.     clc
  949.     ret
  950. vts7a:    cmp    bl,tekonnum        ; enable tek?
  951.     jne    vts7b            ; ne => don't enable
  952.     and    denyflg,not tekxflg    ; clear tekx bit
  953.     mov    tekbyte,bl        ; for status display
  954.     clc
  955.     ret
  956. vts7b:    cmp    bl,tekoffnum        ; disable tek
  957.     jne    vts8            ; ne => don't disable
  958.     or    denyflg,tekxflg        ; set tek deny bit
  959.     mov    tekbyte,bl        ; for status display
  960.     clc
  961.     ret
  962. vts8:    cmp    bl,ttgenrc        ; hp150 emulation selected?
  963.     jne    vts9
  964.     mov    flags.vtflg,bl        ; set emulator type
  965.     clc
  966.     ret
  967. vts9:    cmp    bl,tttek        ; tek emulation selected?
  968.     jne    vts10
  969.     mov    flags.vtflg,bl
  970. vts10:    clc
  971.     ret                ; success
  972. VTS    ENDP
  973.  
  974.  
  975. VTSTAT    PROC    NEAR            ; For Status display
  976.     mov    bx,offset vtstbl    ; table of things to show
  977.     jmp    statc            ; common status code
  978. VTSTAT    ENDP
  979.  
  980. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  981. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  982. ; is determined by mssset and is passed as pointer dmpname.
  983.  
  984. DUMPSCR PROC    NEAR    ; Dumps screen contents to a file. Just Beeps here
  985.     call    beep
  986.     ret
  987. DUMPSCR ENDP
  988.  
  989.  
  990. lclini proc near
  991.     saveregs
  992.     call    read_baud        ; use firmware to read baud rates
  993.     mov    lclexit,offset lclose    ; routine to call when closing
  994.     mov    prtrdy,true        ; port is ready
  995.     mov    flags.vtflg,0        ; no terminal emulation. [jrd]
  996.     mov    prthnd,0        ; no port handle yet. [jrd]
  997.     call    msuinit            ; initialize keyboard module msugen
  998.     call    serini            ; initialize port
  999.     restoreregs
  1000.     ret
  1001. lclini    endp
  1002.  
  1003.  
  1004.  
  1005. ; Wait for the # of milliseconds in ax, for non-IBM compatibles.
  1006. ; Thanks to Bernie Eiben for this one.
  1007. pcwait    proc    near
  1008.     mov    cx, 180        ; hp150 has effective clock of only 3.6 MHz!!!
  1009. pcwai1: sub    cx,1        ; inner loop takes 20 clock cycles
  1010.     jnz    pcwai1
  1011.     dec    ax        ; outer loop counter
  1012.     jnz    pcwait        ; wait another millisecond
  1013.     ret
  1014. pcwait    endp
  1015.  
  1016. ; Initialization for using serial port.     Returns normally.
  1017. ; Attempts to put port device in binary mode. [jrd]
  1018. SERINI    PROC    NEAR
  1019.     cld            ; Do increments in string operations
  1020.     cmp prthnd,0        ; Got a handle yet?
  1021.     jne serin0
  1022.  
  1023.     push bx
  1024.     call opnprt        ; Else 'open' the port
  1025.     pop bx
  1026. serin0: push bx
  1027.     mov bx,portval        ; get port [jrd]
  1028.     mov parmsk,0ffh        ; parity mask, assume parity is None
  1029.     cmp [bx].parflg,parnon    ; is it None?
  1030.     je serin1        ; e = yes
  1031.     mov parmsk,07fh        ; no, pass lower 7 bits as data
  1032. serin1: mov bx,[bx].flowc    ; get flow control chars
  1033.     mov flowoff,bl        ; xoff or null
  1034.     mov flowon,bh        ; xon or null
  1035.     pop bx
  1036.     clc            ; carry clear for success
  1037.     ret
  1038. SERINI    ENDP
  1039.  
  1040. SERRST    PROC    NEAR
  1041.      push bx         ; save reg
  1042.     push di
  1043.     mov bx,prthnd
  1044.     cmp bx,0        ; none there?
  1045.     je serrs6        ; no, don't try to close
  1046. ; return the port to the orignal status
  1047.     mov bx, prthnd        ; handle
  1048.     call  cookedon        ; cook the port first
  1049.     mov al, e_port1        ; assume port 1
  1050.     mov bx, offset port1
  1051.     cmp portval, bx        ; are we using port 1?
  1052.     je  serrs2
  1053.     mov al, e_port2           ; using port 2
  1054. serrs2: call get_config_values ; read configuration di points to work_config
  1055.     mov  al, 1           ; assume 7 bit mode
  1056.     test [di].dc_bool2, 2    ; if bit2 set => 7 bit
  1057.     jnz serrs3           ; nx => yes 7 bit
  1058.     mov al,2           ; 2 for 8 bit
  1059. serrs3: call dc_ioctl           ; update the number of bits
  1060.     mov al, 4           ; disable data comm transparency
  1061.     call dc_ioctl
  1062.     mov bx, prthnd        ; port handle in bx for close
  1063.     mov ah,close
  1064.     int dos            ; close handle
  1065.     mov prthnd,0        ; the port is now closed
  1066. serrs6: pop di
  1067.     pop bx
  1068.     ret            ; All done
  1069. SERRST    ENDP
  1070.  
  1071. ; Generate a short beep.
  1072.  
  1073. BEEP    PROC    NEAR
  1074.     mov dl,bell
  1075.     mov ah,conout
  1076.     int dos
  1077.     ret
  1078. BEEP    ENDP
  1079.  
  1080. ; Dumb terminal emulator.  Doesn't work too well above 1200 baud (and
  1081. ; even at 1200 baud you sometimes lose the first one or two characters
  1082. ; on a line). Does capture (logging), local echo, debug display, tests
  1083. ; for printer/logging device not ready. 27 Sept 86 [jrd].
  1084. term    proc    near
  1085.     mov    argadr,ax        ; save argument ptr
  1086.     mov    si,ax            ; this is source
  1087.     mov    di,offset ourarg    ; place to store arguments
  1088.     push    es            ; save register
  1089.     push    ds
  1090.     pop    es            ; make es point to datas segment
  1091.     mov    cx,size termarg
  1092.     cld
  1093.     rep    movsb            ; copy into our arg blk
  1094.     pop    es            ; recover reg
  1095.     mov    ax,ourarg.captr
  1096. ;;;       mov captrtn,ax        ; buffer capture routine
  1097.     call    pntflsh            ; flush printer buffer
  1098.     mov    keydelay,0        ; initizize keyboard counter [jan]
  1099.     mov    parmsk,0ffh        ; parity mask, assume parity = None
  1100.     call    keybdopen        ; turn on keycode mode
  1101.     call    labelsoftkeys
  1102.     call    displaylogkey    ; decide whehter to display logging softkey
  1103.     cmp    flags.vtflg,tttek    ; in tektronix emulation?
  1104.     jne    term0            ; ne=> doing alpha
  1105.     call    tekini            ; initialize emulator
  1106.  
  1107. term0:    mov    parmsk,0ffh        ; 8 bit parity by default
  1108.     cmp    ourarg.parity,parnon    ; is parity None?
  1109.     je    term1            ; e = yes, keep all 8 bits
  1110.     mov    parmsk,07fh        ; else keep lower 7 bits
  1111.  
  1112. term1:    cmp    prtrdy,false        ; ready to read port?
  1113.     jne    term2             ; ne = yes
  1114.     mov    kbdflg,'C'         ; so we exit connect mode
  1115.     mov    prtrdy,true         ; get ready for next connect
  1116.     jmp    term5             ; get out
  1117. term2:    call    portchr            ; get char from port, mask parity
  1118.     jnc    short term4        ; nc = no char, go on
  1119.     call    stringchek        ; check the string for escape sequence
  1120.     jnc    short term4        ; nc => no key to show
  1121. term3:    call    outtty              ; display and capture char
  1122. term4:    inc    keydelay        ; increment counter
  1123.     mov    ah,keydelay        ; move into ah
  1124.     and    ah,15            ; clear high bits and read keyboard
  1125.     jne    term1            ; once each 16 reads of serial port
  1126.     call    keybd            ; call keyboard translator in msu
  1127.     jnc    term1            ; nc = no char or have processed it
  1128. term5:                    ; carry set = quit Connect mode
  1129.     call    pntflsh            ; flush printer buffer
  1130.     call    clearlabels        ; blank softkey labels
  1131.     call    keybdclose        ; turn off keycode mode
  1132.     writestring alpha_disp        ; make sure we are in alpha upon exit
  1133.     writestring alpha_on        ; turn on alpha
  1134.     writestring tek_off        ; turn off tek
  1135.     call    test_baud_change    ; check for baud change
  1136.     call    cptdmp            ; empty the capture buffer
  1137.     ret
  1138. term    endp
  1139.  
  1140.  
  1141. ; put the character in al to the screen, do capture and printing,
  1142. ; does translation for Set Input command.
  1143. ; Adapted from msyibm.asm [jrd]
  1144. outtty    proc    near
  1145.     test    flags.remflg,d8bit    ; keep 8 bits for displays?
  1146.     jnz    outnp8            ; nz = yes, 8 bits if possible
  1147.     and    al,7fh            ; remove high bit
  1148. outnp8: cmp    rxtable+256,0        ; is translation off?
  1149.     je    outnp7            ; e = yes, off
  1150.     push    bx            ; Translate incoming char
  1151.     mov    bx,offset rxtable    ; address of translate table
  1152.     xlatb                ; new char is in al
  1153.     pop    bx
  1154. outnp7:    cmp    logflag,true        ; are we logging?
  1155.     jne    outnoc            ; ne => no, forget logging
  1156.     push    ax            ; save char
  1157.     call    captrtn            ; give it captured character
  1158.     pop    ax            ; restore character and keep going
  1159. outnoc:    test    anspflg,prtscr        ; should we be printing?
  1160.     jz    outnop            ; no, keep going
  1161.     call    pntchr            ; queue char for printer
  1162.     jnc    outnop            ; nc = successful print
  1163.     push    ax
  1164.     call    beep            ; else make a noise and
  1165.     call    trnprs            ;  turn off printing
  1166.     pop    ax
  1167. outnop: cmp    flags.vtflg,0        ; emulating a terminal?
  1168.     jnz    outnop1            ; nz = yup, go do something smart
  1169.     test    ourarg.flgs,trnctl    ; debug? if so use dos tty mode
  1170.     jz    outnp4            ; z = no
  1171.     mov    ah,conout
  1172.     cmp    al,7fh            ; Ascii Del char or greater?
  1173.     jb    outnp1            ; b = no
  1174.     je    outnp0            ; e = Del char
  1175.     push    ax            ; save the char
  1176.     mov    dl,7eh            ; output a tilde for 8th bit
  1177.     int    dos
  1178.     pop    ax            ; restore char
  1179.     and    al,7fh            ; strip high bit
  1180. outnp0: cmp    al,7fh            ; is char now a DEL?
  1181.     jne    outnp1            ; ne = no
  1182.     and    al,3fH            ; strip next highest bit (Del --> '?')
  1183.     jmp    outnp2            ; send, preceded by caret
  1184. outnp1: cmp    al,' '            ; control char?
  1185.     jae    outnp3            ; ae = no
  1186.     add    al,'A'-1        ; make visible
  1187. outnp2: push    ax            ; save char
  1188.     mov    dl,5eh            ; caret
  1189.     int    dos            ; display it
  1190.     pop    ax            ; recover the non-printable char
  1191. outnp3: mov    dl,al
  1192.     int    dos
  1193.     ret
  1194. outnp4: ;cmp     al,bell         ; bell (Control G)?
  1195.     ;jne     outnp5             ; ne = no
  1196.     ;jmp     beep             ; use short beep, avoid char loss
  1197. outnop1:
  1198. outnp5:     
  1199.     mov    dl,al             ; write without intervention
  1200.     mov    ah,6            ; direct console i/o
  1201.     int    dos            ; else let dos display char
  1202.     ret                ; and return
  1203. outtty    endp
  1204.  
  1205.  
  1206. ; send the character in al out to the serial port; handle echoing.
  1207. ; Can send an 8 bit char while displaying only 7 bits locally.
  1208. outprt    proc    near
  1209.     test    ourarg.flgs,lclecho    ; echoing?
  1210.     jz    outpr1            ; z = no, forget it
  1211.     push    ax            ; save char
  1212.     call    outtty            ; print it
  1213.     pop    ax            ; restore
  1214. outpr1: mov    ah,al            ; this is where outchr expects it
  1215.     call    outchr            ; output to the port
  1216.     ret
  1217. outprt    endp
  1218.  
  1219. ; Get a char from the serial port manager
  1220. ; returns with carry on if a character is available
  1221. portchr proc    near
  1222.     call    prtchr            ; character at port?
  1223.     jnc    portc1            ; nc = yes there is a character
  1224. portc0: clc                ; no carry -> no character
  1225.     ret                ; and return
  1226. portc1: and    al,parmsk        ; apply 8/7 bit parity mask
  1227.     stc                ; have a character
  1228.     ret                ; and return
  1229. portchr endp
  1230.  
  1231. ;; keyboard translator action routines, system dependent, called from msugen.
  1232. ; These are invoked by a jump instruction. Return carry clear for normal
  1233. ; processing, return carry set to exit Connect mode (kbdflg has transfer char)
  1234.  
  1235. chrout    proc    near
  1236.     cmp    repflg,0        ; in replay mode?
  1237.     je    chrout1            ; e=> not doing replay
  1238.     jmp    repchrout        ; display the replay character
  1239. chrout1:call    outprt            ; put char in al to serial port
  1240.     clc                ; stay in Connect mode
  1241.     ret
  1242. chrout    endp
  1243.  
  1244. trnprs:    push    ax            ; toggle Copy screen to printer
  1245.     test    anspflg,prtscr        ; should we be printing?
  1246.     jnz    trnpr2            ; nz = yes, its on and going off
  1247.     mov    ah,ioctl
  1248.     mov    al,7            ; get output status of printer
  1249.     push    bx
  1250.     mov    bx,prnhand        ; file handle for system printer
  1251.     int    dos
  1252.     pop    bx
  1253.     jc    trnpr1            ; c = printer not ready
  1254.     cmp    al,0ffh            ; Ready status?
  1255.     je    trnpr2            ; e = Ready    
  1256. trnpr1:    call    beep            ; Not Ready, complain
  1257.     jmp    short trnpr3        ; and ignore request
  1258. trnpr2:    xor    anspflg,prtscr        ; toggle print flag
  1259. trnpr3:    pop    ax
  1260.     clc
  1261.     ret
  1262.  
  1263. displaylogkey  proc near        ; display logging softkey?
  1264.     test    flags.capflg, logses    ; session logging enables?
  1265.     jz    displaylogkey3        ; z= no, forget it
  1266.     cmp    logflag, true        ; are we logging?
  1267.     jne    displaylogkey1        ; ne => not logging
  1268.     call     displaylogoffkey      ; off key if capturing
  1269.     jmp     displaylogkey2           ; make a good exit
  1270. displaylogkey1:
  1271.     call   displaylogonkey           ; show log on function key
  1272. displaylogkey2:
  1273.     clc
  1274.     ret
  1275. displaylogkey3:
  1276.     mov  logflag, false     ; not logging
  1277.     clc
  1278.     ret
  1279. displaylogkey  endp
  1280.  
  1281. klogtog     proc    near            ; toggle session logging key
  1282.     test    flags.capflg, logses    ; session logging enables?
  1283.     jz    klogtogn        ; z= no, forget it
  1284.     cmp    logflag, true        ; are we capturing?
  1285.     jne    klogtog1        ; ne => not logging
  1286.     mov    logflag, false        ; turn off loggin
  1287.     push    bx
  1288.     mov    bx, argadr
  1289.     and    [bx].flgs, not capt    ; tell kermit we are stopping capture
  1290.     and    ourarg.flgs, not capt    ; turn off local capture flag
  1291.     pop    bx            ; restore the register
  1292.     call    displaylogkey        ; turn on appropriate log key
  1293.     call    cptdmp            ; dump the capture buffer to file
  1294.     jmp    klogtog2
  1295. klogtog1:
  1296.      mov    logflag, true         ; turn on logging
  1297.     push    bx
  1298.     mov    bx, argadr
  1299.     or    [bx].flgs, capt           ; tell kermit we are resuming capture
  1300.     or    ourarg.flgs, capt      ; turn on local capture flag
  1301.     pop    bx               ; restore the register
  1302.     call  displaylogkey          ; turn on log off key
  1303. klogtog2: clc
  1304.       ret
  1305. klogtogn: mov logflag, false           ; not logging so turn off flag
  1306.       clc
  1307.       ret
  1308. klogtog      endp
  1309.  
  1310.  
  1311. snull:    mov    ah,0            ; send a null
  1312.     call    outchr            ; send without echo or logging
  1313.     clc
  1314.     ret
  1315.  
  1316. kdos:    mov    al,'P'            ; Push to DOS
  1317.     jmp    short cmdcom
  1318. cstatus:
  1319.      mov     al,'S'             ; these commands exit Connect mode
  1320.     jmp    short cmdcom
  1321. cquit:
  1322.      mov     al,'C'
  1323.     jmp    short cmdcom
  1324. cquery:
  1325.     mov    al,'?'
  1326.     jmp    short cmdcom
  1327. cmdcom: mov    kbdflg,al        ; pass char to msster.asm via kbdflg
  1328.     stc                ; say exit Connect mode
  1329.     ret
  1330.                     ;; end of action routines
  1331.  
  1332. ; set comm port parameters based on dc_status structure
  1333. set_port_param proc near
  1334.     push    di
  1335.     cmp    prthnd,0            ; got a handle yet
  1336.     jne    set_port_param1            ; ne = yes
  1337.     call    opnprt
  1338.     jmp    set_port_param5        ; opnprt calls this so don't repeat
  1339. set_port_param1:
  1340.     mov    di,offset dc_status
  1341.     cmp    [di].eightbit,true        ; doing 8 bit?
  1342.     je    set_port_param2            ; e=> yes, doing 8 7 bit
  1343.     mov    eightflg,sevenbitnum    ; so status knows we have seven bits
  1344.     mov    al,1                ; dc_ioctl code  for 7 bit
  1345.     call    dc_ioctl
  1346.     jmp    set_port_param2a        ; check transparent
  1347. set_port_param2:
  1348.     mov    eightflg,eightbitnum    ; so status knows we have eight bits
  1349.     mov    al,2                ; code for 8 bit
  1350.     call    dc_ioctl
  1351. set_port_param2a:
  1352.     cmp    [di].transparent,true        ; in transparency mode?
  1353.     je    set_port_param3            ; e=> yes
  1354.     mov    transparentflg,transoffnum ; so status knows transparency off
  1355.     mov    al,4                ; code to disable transparency
  1356.     call    dc_ioctl
  1357.     jmp    set_port_param3a        ; check raw/cooked situation
  1358. set_port_param3:
  1359.     mov    transparentflg,transonnum  ; so status knows transparency on
  1360.     mov    al,3                ; code to enable transparency
  1361.     call    dc_ioctl
  1362. set_port_param3a:
  1363.     cmp    [di].raw,true            ; raw mode set?
  1364.     je    set_port_param4            ; e => raw on
  1365.     mov    rawflg,rawoffnum        ; so status knows we're cooked
  1366.     mov    bx,prthnd            ; cooked on needs port handle
  1367.     call    cookedon
  1368.     jmp    set_port_param5            ; done
  1369. set_port_param4:
  1370.     mov    rawflg,rawonnum            ; tell status port is raw
  1371.     mov    bx,prthnd            ; port handle for raw on
  1372.     call    rawon
  1373. set_port_param5:
  1374.     pop    di
  1375.     clc
  1376.     ret
  1377. set_port_param endp
  1378.  
  1379. ;check string to see if we need to do something special
  1380.  
  1381. stringchek  proc  near
  1382.        cmp   stringchekcnt,0     ; nobody in yet?
  1383.        jne   stringchek1     ; ne => already have characters
  1384.        cmp   al,escape         ; is this escape?
  1385.        je    stringchek1     ; it is escape, so go and process
  1386.        cmp   al,escape+80h     ; in case parity is odd
  1387.        je    stringchek1     ; process escape
  1388.        stc             ; display the character
  1389.        ret             ; return quickly if nothing to do
  1390. stringchek1:             ; here is escape already in
  1391.        saveregs
  1392.        and     al,07fh         ;strip high bit
  1393.        mov     bx,stringchekcnt
  1394.        mov     stringchekbuff[bx],al  ;put character in buffer
  1395.        inc     stringchekcnt          ;one more character in buffer
  1396.        call    stringtest     ; does the string in stringchekbuff match?
  1397.        cmp    match,0         ; 0 means no match
  1398.        je      stringchek2
  1399.        mov     si,match           ; here means we have a match
  1400.        shl     si,1           ; multiply by 2
  1401.        dec     si
  1402.        dec     si           ; 1=0, 2=1 etc
  1403.        call    disptab[si]       ; call appropriate function
  1404.        call    stringbuffplay          ; play back the buffer
  1405.        clc               ; don't display
  1406.        jmp     stringchek3       ; return and don't display character
  1407. stringchek2:
  1408.      clc              ; don not display
  1409.      cmp   matchsofar,true      ; do we have a match so far
  1410.      je    stringchek3         ; e=true , get out
  1411.      mov   playem,true
  1412.      call  stringbuffplay           ; clean out the buffer
  1413.      clc               ; don't display character
  1414. stringchek3:
  1415.      restoreregs
  1416.      ret
  1417. stringchek   endp
  1418.  
  1419. ;test to see if input string is a match to toggle terminal  [jan]
  1420.  
  1421.  
  1422. ; stringtab gives addresses of 0 terminated strings
  1423. ; teststring in stringchekbuff
  1424. ; numstrings is the number to checked
  1425. ; matchsofar will have be true if there is a possilbe match
  1426. ; match will be non-zero 1, 2, 3 indicating number of match if a match
  1427. ; if no match yet, match will be 0
  1428. ; severaal registers get destroyed
  1429. stringtest proc near
  1430.     mov    matchsofar,false    ; assume no match
  1431.     mov    match,0            ; no match
  1432.     xor    si,si            ; pointer to string tab
  1433.     dec    si
  1434.     dec    si            ; step back 1 item
  1435.     mov    cx,0            ; cx points to number of string
  1436. strtst1:
  1437.     inc    cx            ; strings number
  1438.     cmp    cx,numstrings        ; done parsing table?
  1439.     ja    strtst5            ; we're done, get out of here
  1440.     mov    di,offset stringchekbuff
  1441.     inc    si
  1442.     inc    si            ; point to next item
  1443.     mov    bx,stringtab[si]    ; offset of string
  1444. strtst2:
  1445.     mov    al,[di]            ; stringchekbuff in al
  1446.     mov    ah,[bx]            ; string element to test in ah
  1447.     cmp    al,0            ; end of stringchekbuff
  1448.     jne    strtst2a        ; ne=> not at end of buffer
  1449.     mov    matchsofar,true        ; we have a match so far
  1450.     jmp    strtst5            ; return to caller
  1451. strtst2a:
  1452.     cmp    ah,0            ; at end of string?
  1453.     je    strtst1            ; failure, go to next string
  1454.     cmp    ah,al            ; match?
  1455.     jne    strtst1            ; no match, on to next string
  1456.                     ; here if match
  1457.     mov    ah,[bx+1]        ; next byte from string
  1458.     cmp    ah,0            ; are we done with string?
  1459.     je    strtst3            ; e => yes, a match
  1460.     inc    bx            ; next element in string
  1461.     inc    di            ; next character in stringchekbuff
  1462.     jmp    strtst2            ; check next item in string
  1463. strtst3:                ; here if we have a match
  1464.      mov    match,cx
  1465.      mov    matchsofar,true
  1466. strtst5:ret
  1467. stringtest endp
  1468.  
  1469.  
  1470.  
  1471. ;play back characters in string buffer ..called by stringchek
  1472. stringbuffplay proc near
  1473.     xor      bx,bx
  1474.     mov      cx,stringchekcnt
  1475. stringbuffplay1:
  1476.     mov    al,stringchekbuff[bx]
  1477.     cmp    playem,true        ; playback characters?
  1478.     jne    stringbuffplay2        ; ne = no don't play back
  1479.     push    bx            ; save index
  1480.     push    cx            ; save count
  1481.     call    outtty            ; print the character
  1482.     pop     cx            ; restore count
  1483.     pop     bx            ; restore index
  1484. stringbuffplay2:
  1485.     mov      stringchekbuff[bx],0    ; set to 0
  1486.     inc      bx            ; point to next character
  1487.     loop     stringbuffplay1    ; repeat until buffer is empty
  1488.     mov      stringchekcnt,0    ; now no characters in buffer
  1489.     ret
  1490. stringbuffplay endp
  1491.  
  1492. ignoretek proc near           ; ignore this escape sequence in tek mode
  1493.     mov    playem,false
  1494.     cmp    flags.vtflg,tttek      ; are in in tek emulation
  1495.     je    ignoretek1           ; e=yes do not play back
  1496.     mov    playem,true
  1497. ignoretek1:ret
  1498. ignoretek endp
  1499.  
  1500. ignoreall proc near            ; always ignore this escape sequence
  1501.     mov    playem,false
  1502.     call    beep             ; let user know of illegal sequence
  1503.     ret
  1504. ignoreall endp
  1505.  
  1506. totekplay proc near            ; turn on tektronix
  1507.     mov    playem,true         ; play back characters
  1508.     jmp    totek
  1509. totekplay endp
  1510.  
  1511. toteknoplay proc near
  1512.     mov    playem,false
  1513.     jmp    totek
  1514. toteknoplay endp
  1515.  
  1516.  
  1517. totek proc near                ; turn on tektronix
  1518.     test    denyflg,tekxflg        ; tek auto entry enabled?
  1519.     jz    totek1
  1520.     mov    playem,true        ; play back characters
  1521.     ret
  1522. totek1:    cmp    flags.vtflg,tttek    ; already doing tek
  1523.     je    totek2
  1524.     call    termtog            ; toggle to tektronix
  1525. totek2: ret
  1526. totek endp
  1527.  
  1528. leavetek proc near            ; turn off tektronix
  1529.     mov    playem,false        ; don't play back characters
  1530.     test    denyflg,tekxflg        ; tek auto entry/exit enabled?
  1531.     jz    leavetek1
  1532.     mov    playem,true        ; play back characters
  1533.     ret
  1534. leavetek1:
  1535.     cmp    flags.vtflg,tttek    ; already doing tek
  1536.     jne    leavetek2        ; ne => doing alpha so ignore
  1537.     call    termtog            ; toggle to alpha
  1538. leavetek2:ret
  1539. leavetek endp
  1540.  
  1541. getrepchr proc    near          ; get replay character for file
  1542.       mov    ah,readf2          ; read from replay file
  1543.       mov    bx,diskio.handle
  1544.       mov    cx,1          ; read 1 character
  1545.       mov    dx,offset rdbuf  ; to this buffer
  1546.       int    dos
  1547.       jc     getrepchr1          ; c => failure
  1548.       cmp    ax,cx          ; read the byte?
  1549.       jne    getrepchr1
  1550.       mov    al,rdbuf          ; al has character
  1551.       clc              ; character available in al
  1552.       ret
  1553. getrepchr1:
  1554.       call   beep         ; announce file is done
  1555.       call   beep
  1556.       call   waitkey          ; wait for a key to be pressed
  1557.       mov    prtrdy,false    ; so we exit connect mode
  1558.       stc
  1559.       ret             ; no character available
  1560. getrepchr    endp
  1561.  
  1562. repchrout  proc     near        ; process key in al  while replaying
  1563.     and   al,7fh        ; strip parity
  1564. repchrout1:
  1565.     cmp   al,'C'-40h    ; Control C?(to exit playback mode)
  1566.     je    repchrout3    ; e=> yes, return failure
  1567.     cmp   al,XOFF        ; user wants to stop?
  1568.     jne   repchrout2    ; ne => ok to continue
  1569.     call  waitkey         ; wait and get a key
  1570.     jmp   repchrout1    ; now process this key
  1571. repchrout2:
  1572.     clc            ; return success
  1573.     ret
  1574. repchrout3:
  1575.     mov   prtrdy,false    ; exit terminal
  1576.     stc            ; exit connect mode
  1577.     ret
  1578. repchrout  endp
  1579.  
  1580. termtog proc  near            ; toggle terminal type [jan]
  1581.     cmp    flags.vtflg,tttek    ; doing tek emulation ?
  1582.     jne    termtog1        ; ne means  doing tek
  1583.     writestring tek_off        ; turn off tek
  1584.     writestring alpha_disp        ; turn on alpha
  1585.     writestring alpha_on        ; and turn on the alpha
  1586.     mov    flags.vtflg,ttgenrc    ; turn on alpha display
  1587.     clc
  1588.     ret
  1589. termtog1:mov    flags.vtflg,tttek    ; turn on tek display
  1590.     writestring alpha_off        ; turn off alpha
  1591.     writestring tek_disp
  1592.     writestring tek_on        ; and turn on the tek
  1593.     clc                ; do not exit Connect mode
  1594.     ret                ; stay in connect mode
  1595. termtog endp
  1596.  
  1597. kclrscn proc near            ; clear the screen
  1598.     cmp    flags.vtflg,tttek    ; doing tek emulation
  1599.     je    kclrscn1        ; e=> yes
  1600.     writestring alpha_clear        ; clear the alpha
  1601.     clc                ; stay in connect mode
  1602.     ret                ; return to caller
  1603. kclrscn1:writestring tek_clear        ; clear the tektronix
  1604.     clc                ; stay in connect mode
  1605.     ret
  1606. kclrscn     endp
  1607.  
  1608. waitkey proc near        ; wait for a key to be pressed
  1609. waitkey0:call    getkey        ; get a key; carry set => no key; code in ax
  1610.     jc    waitkey0    ; repeat until its pressed
  1611.     ret
  1612. waitkey endp
  1613.  
  1614. tekini proc near            ; initialize tek emulator
  1615.     writestring alpha_off
  1616.     writestring tek_disp            ; enable tektronix
  1617.     writestring tek_on            ; turn on tek
  1618.     ret
  1619. tekini    endp
  1620.  
  1621.  
  1622. toterminal proc near               ; go to firmware terminal mode
  1623.     cmp    dosnum,dos211        ; dos 2.11 or above?
  1624.     jae    toterminal1        ; ae=> ok to go to terminal
  1625.     mov    ah,2
  1626.     mov    dl,7
  1627.     int    dos            ; ring the bell
  1628.     clc                ; stay in connect mode
  1629.     ret
  1630. toterminal1:
  1631.     call    clearlabels        ; blank softkey labels
  1632.     call    keybdclose        ; get out of keycode
  1633.     writestring to_term_msg
  1634.     mov    ax,1750
  1635.     call    pcwait            ; 1 3/4 second time to read message
  1636.     mov    bx,offset agiosbuff
  1637.     mov    word ptr [bx],26      ; function code to get into terminal
  1638.     mov    ax,4403h        ; io control write
  1639.     mov    bx,1            ; console handle
  1640.     mov    cx,2            ; 2 bytes in buffer
  1641.     mov    dx,offset agiosbuff
  1642.     int    dos            ; now in terminal mode
  1643.     call    labelsoftkeys         ; turn keys on when we return
  1644.     call    keybdopen        ; back to keycode mode
  1645.     clc                ; stay in connect mode
  1646.     ret                ; back to terminal
  1647. toterminal endp
  1648.  
  1649. cookedon proc near            ; cook handle in bx
  1650.     push    ax
  1651.     push    dx            ; save registers
  1652.     push    bx            ; save handle
  1653.     mov     ax,4400h        ; get device information
  1654.     int     dos
  1655.     xor     dh,dh            ; clear high byte
  1656.     and     dl,0dfh        ; clear raw bit without changing other bits
  1657.     mov     ax,4401h        ; put device information
  1658.     pop     bx            ; restore handle
  1659.     int     dos            ; turn off raw mode
  1660.     pop     dx            ; restore registers
  1661.     pop     ax
  1662.     clc                ; always returns success
  1663.     ret
  1664. cookedon endp
  1665.  
  1666. rawon proc near
  1667.     push    ax
  1668.     push    dx            ; save registers
  1669.     push    bx            ; save handle
  1670.     mov     ax,4400h        ; get device information
  1671.     int     dos
  1672.     xor     dh,dh            ; clear high byte
  1673.     or      dl,20h            ; set raw bit
  1674.     mov     ax,4401h        ; put device information
  1675.     pop     bx            ; restore handle
  1676.     int     dos            ; turn on raw mode
  1677.     pop     dx
  1678.     pop     ax            ; restore registers
  1679.     clc                ; always returns success
  1680.     ret
  1681. rawon endp
  1682.  
  1683. ;;;cptchr and cptdmp taken from msster to fix the problem
  1684. ; of com buffer overflow with logging the session
  1685. cptchr    proc    near            ; session capture routine, char in al
  1686.     push    di
  1687.     mov    di,capbp        ; buffer pointer
  1688.     mov    byte ptr [di],al
  1689.     inc    capbp
  1690.     pop    di
  1691.     dec    caplft            ; decrement chars remaining
  1692.     jg    cptch1            ; more room, forget this part
  1693.     call    cptdmp            ; dump the info
  1694. cptch1:    ret
  1695. cptchr    endp
  1696.  
  1697. cptdmp    proc    near            ; empty the capture buffer
  1698.     push    ax
  1699.     push    bx
  1700.     push    cx
  1701.     push    dx
  1702.     mov    bx,sloghnd        ; get file handle
  1703.     cmp    bx,0            ; is file open?
  1704.     jle    cptdm1            ; le = no, skip it
  1705.     push    bx            ; save handle
  1706.     mov    bx,portval        ; doing flow control?
  1707.     cmp    [bx].floflg,0        ; e = no
  1708.     je    cptdmp01    
  1709.     cmp    xofsnt,true        ; have we sent xoff?
  1710.     je    cptdmp01        ; don't send it again
  1711.     mov    ah,flowoff        ; get the xoff
  1712.     or    ah,ah            ; null (no flow control?)
  1713.     jz    cptdmp01
  1714.     call    outchr            ; send xoff to port
  1715.     mov    xofsnt,true        ; remember we've sent it
  1716. cptdmp01:pop    bx            ; restore handle
  1717.     mov    cx,cptsiz        ; original buffer size
  1718.     sub    cx,caplft        ; minus number remaining
  1719.     jl    cptdm2            ; means error
  1720.     jcxz    cptdm1            ; z = nothing to do
  1721.     mov    dx,offset capbuf    ; the capture routine buffer
  1722.     mov    ah,write2        ; write with filehandle
  1723.     int    dos            ; write out the block
  1724.     jc    cptdm2            ; carry set means error
  1725.     mov    capbp,offset capbuf
  1726.     mov    caplft,cptsiz        ; init buffer ptr & chrs left
  1727.     jmp    short cptdm1
  1728. cptdm2:    and    flags.capflg,not logses    ; so please stop capturing
  1729. ;    and    targ.flgs,not capt    ; so please stop capturing
  1730. and ourarg.flgs, not capt  ; so please stop capturing
  1731.     mov    dx,offset capterr    ; tell user the bad news
  1732.     mov    ah,prstr
  1733.     int    dos
  1734. cptdm1: cmp    xofsnt, true          ; xoff sent
  1735.     jne    cptdm02
  1736.     mov    ah,flowon        ; get the xon
  1737.     or    ah,ah              ; null?
  1738.     jz    cptdm02
  1739.     call    outchr              ; send xon
  1740.     mov    xofsnt,false          ; remember we've sent it
  1741. cptdm02:pop    dx
  1742.     pop    cx
  1743.     pop    bx
  1744.     pop    ax
  1745.     ret
  1746. cptdmp    endp
  1747.  
  1748. test_baud_change proc near        ; check if firmware baud changed
  1749.     mov    al,e_port1
  1750.     call    get_config_values
  1751.     mov    al,[di].dc_baud_rate
  1752.     cmp    al,start_porta_baud ; baud rate changed by firmware (via user)
  1753.     je    test_baud_change1    ; e = not changed
  1754.     call    read_bauda        ; redo port a baud
  1755. test_baud_change1:
  1756.     mov    al,e_port2        ; check if port 2 changed
  1757.     call    get_config_values
  1758.     mov    al,[di].dc_baud_rate
  1759.     cmp    al,start_portb_baud
  1760.     je    test_baud_change2    ; e = not changed
  1761.     call    read_baudb        ; read port b baud
  1762. test_baud_change2:
  1763.     ret
  1764. test_baud_change endp
  1765.  
  1766. read_baud proc near
  1767.     call    read_bauda          ; read port 1 baud
  1768.     call    read_baudb          ; read port 2 baud
  1769.     ret
  1770. read_baud endp
  1771.  
  1772. read_bauda proc near      ; read baud on port 1 and update port info
  1773.     mov    al,e_port1
  1774.     call    get_config_values    ; get port 1 configuration
  1775.     mov    si,offset port1
  1776.     mov    di,offset work_config
  1777.     mov    bl,[di].dc_baud_rate    ; baud rate into bl
  1778.     mov    start_porta_baud,bl    ; remember startup baud
  1779.     mov    portb_baud,bl        ; remember startup baud
  1780.     mov    di,offset ourbdtab    ; translate hp baud into kermit code
  1781.     shl    bl,1            ; multiply by 2 for 2 bytes per entry
  1782.     xor    bh,bh
  1783.     mov    bl,[di+bx+1]
  1784.     mov    [si].baud,bx        ; write baud in port 1 info
  1785.     ret
  1786. read_bauda endp
  1787.  
  1788. ; Read the port 2 status
  1789. read_baudb proc near
  1790.     mov    al,e_port2
  1791.     call    get_config_values    ; get port 2 configuration
  1792.     mov    si,offset port2
  1793.     mov    di,offset work_config
  1794.     mov    bl,[di].dc_baud_rate    ; baud rate into bl
  1795.     mov    start_portb_baud,bl    ; remember startup baud
  1796.     mov    portb_baud,bl        ; current baud on port b
  1797.     mov    di,offset ourbdtab    ; translate hp baud into kermit code
  1798.     shl    bl,1              ; multiply by 2 since 2 bytes per entry
  1799.     xor    bh,bh
  1800.     mov    bl,[di+bx+1]
  1801.     mov    [si].baud,bx        ; write baud in port 2 info
  1802.     ret
  1803. read_baudb endp
  1804.  
  1805. ;;; read data comm configuration. taken off dc.asm from compuserve
  1806. ;*******************************************
  1807. ;
  1808. ; Firmware Programming Notes:
  1809. ;
  1810. ; 1) The firmware has a modular structure and generally consists
  1811. ;     of a bunch of processing modules which all have a separate
  1812. ;     logical segment and a limited number of entry points
  1813. ;     (generally only one).
  1814. ; 2) The desired processing is accessed by passing the required
  1815. ;     parameters and the proper function code on entry to a
  1816. ;     module.
  1817. ; 3) A call to a procedure outside the logical module is always
  1818. ;     a long call and inter segment (logical segment).
  1819. ; 4) Parameters for a call to a procedure outside the logical
  1820. ;     module are pushed on the stack. This includes the function
  1821. ;     code.    The procedure called has the responsibility of
  1822. ;     cleaning up the stack.
  1823. ; 5) The procedure called should always return status in AX.
  1824. ;     Registers BX, CX, and DX may also contain outputs.
  1825. ; 6) The caller should always assume registers AX, BX, CX, and
  1826. ;     DX have been modified. The caller should always assume
  1827. ;     registers SI, DI, SP, BP, DS, ES, and SS are the same on
  1828. ;     return.
  1829. ; 7) Calls to external procedures are made through jump tables
  1830. ;     at the beginning of each rom.    Thus the application is
  1831. ;     insulated from re-releases of the HP150 firmware.
  1832. ;
  1833. ;*******************************************
  1834. page;
  1835. ;*************** GRYPHON DECLARATIONS ************
  1836. ; To simplify external linking to absolute firmware jump locations,
  1837. ; we include the long calls as constants. Note that we still have
  1838. ; some measure of ROM independence because we entry the routines
  1839. ; through fixed jump tables at the start of the RAM.
  1840. ;
  1841. ;-------------------------------------------
  1842. ;
  1843. ; COMMENTS:
  1844. ; 1) The bytes PREDEF_VALUES and BARREL_INDEX are used by
  1845. ;     configuration processing during normal operation where a
  1846. ;     configuration form is brought onto the screen. Their
  1847. ;     values can be set and then ignored.
  1848. ; 2) The bytes DC_PORT through DC_RECV_PACE are the actual
  1849. ;     datacomm configuration values.
  1850. ; 3) The word DC_DEVICE_TOKEN is used to access the datacomm
  1851. ;     device.
  1852. ;
  1853. ;-------------------------------------------
  1854.  
  1855. ;*******************************************
  1856. ;
  1857. ; The data format for the datacomm configuration values are as
  1858. ; follows:
  1859. ;
  1860. ;    1) DC_PORT=    2    (port 1)
  1861. ;            11    (port 2)
  1862. ;
  1863. ;    2) DC_BOOL1    (a graphical representation follows)
  1864. ;    3) DC_BOOL2
  1865. ;
  1866. ;     HP Point-to-Point Boolean Bit Positions
  1867. ;
  1868. ;        7        6        5        4        3        2        1        0
  1869. ;    +-------+-------+-------+-------+-------+-------+-------+-------+
  1870. ;    | 1 Stop| CS(CB)|  SRR    | RR(CF)|  SRR    | SR(CH)|  Chk    |  ENQ    |
  1871. ;    |  Bit    |  Xmit | Invert|  Recv |  Xmit |    | Parity|  ACK    |
  1872. ;    +-------+-------+-------+-------+-------+-------+-------+-------+
  1873. ;    | TR(CD)| DM(CC)|    |    |    |    | 7 Data|  Xmit |
  1874. ;    |    |  Xmit |    |    |    |    |  Bits |  Pace |
  1875. ;    +-------+-------+-------+-------+-------+-------+-------+-------+
  1876. ;
  1877. ;     DC_BOOL1:
  1878. ;
  1879. ;        Bit 0:        0 = No        1 = Yes
  1880. ;        Bit 1:        0 = No        1 = Yes
  1881. ;        Bit 2:        0 = Lo        1 = Hi
  1882. ;        Bit 3:        0 = No        1 = Yes
  1883. ;        Bit 4:        0 = No        1 = Yes
  1884. ;        Bit 5:        0 = No        1 = Yes
  1885. ;        Bit 6:        0 = No        1 = Yes
  1886. ;        Bit 7:        0 = 2 Stop Bits 1 = 1 Stop Bit
  1887. ;
  1888. ;     DC_BOOL2:
  1889. ;
  1890. ;        Bit 0:        0 = None    1 = Xon/Xoff
  1891. ;        Bit 1:        0 = 8 Data Bits 1 = 7 Data Bits
  1892. ;        Bit 6:        0 = No        1 = Yes
  1893. ;        Bit 7:        0 = Lo        1 = Hi
  1894. ;
  1895. ;    4) DC_BAUD_RATE =    02H     (110 Baud)
  1896. ;                04H     (150 Baud)
  1897. ;                05H     (300 Baud)
  1898. ;                06H     (600 Baud)
  1899. ;                07H    (1200 Baud)
  1900. ;                0AH    (2400 Baud)
  1901. ;                0CH    (4800 Baud)
  1902. ;                0EH    (9600 Baud)
  1903. ;                0FH    (19200 Baud)
  1904. ;
  1905. ;    5) DC_PARITY =        0    (Zeros)
  1906. ;                1    (Ones)
  1907. ;                2    (Even)
  1908. ;                3    (Odd)
  1909. ;                4    (None)
  1910. ;
  1911. ;    6) DC_CLOCK =        0    (INT CLOCK)
  1912. ;                1    (EXT X1 CLOCK)
  1913. ;                2    (EXT X16 CLOCK)
  1914. ;
  1915. ;    7) DC_ASTERISK =    0    (No Asterisk)
  1916. ;                1    (DM Asterisk)
  1917. ;                2    (RR Asterisk)
  1918. ;                3    (Line Asterisk)
  1919. ;                4    (CS Asterisk)
  1920. ;
  1921. ;    8) DC_RECV_PACE =    0    (No Recv Pace)
  1922. ;                1    (Xon/Xoff Recv Pace)
  1923. ;                2    (TR(CD) Recv Pace)
  1924. ;
  1925. ;*******************************************
  1926. ;
  1927. ;
  1928. ;-------------------------------------------
  1929. ;
  1930. ; PROCEDURE NAME:    GET_CONFIG_VALUES
  1931. ;
  1932. ; FUNCTION:
  1933. ; 1) Specify a block of configuration parameters to be obtained
  1934. ;     by config processing.    The parameters define how datacomm
  1935. ;     is configured.
  1936. ; 2) Config processing will get the data out of NVRAM.    The
  1937. ;     values reflect the current configuration of the 150.
  1938. ; 3) The data is written into the data area supplied by the
  1939. ;     caller and is in the format used by the datacomm driver.
  1940. ;
  1941. ; INPUTS:
  1942. ; 1) DS - segment of CONFIGURATION_DATA_AREA
  1943. ; 2) DI - offset of CONFIGURATION_DATA_AREA
  1944. ;
  1945. ; OUTPUTS:
  1946. ;     The configuration data area will have all the necessary
  1947. ;     values needed to specify the datacomm configuration.    These
  1948. ;     can be modified so when they are passed to the datacomm
  1949. ;     driver, the new configuration will take effect.
  1950. ;
  1951. ; REGISTERS MODIFIED: ax, bx, cx, dx
  1952. ;
  1953. ;-------------------------------------------
  1954. GET_CONFIG_VALUES proc near
  1955.  
  1956.     mov    readid,e_port1_read
  1957.     mov    saveid,e_port1_save
  1958.     cmp    al,e_port1
  1959.     je    init90
  1960.     mov    readid,e_port2_read
  1961.     mov    saveid,e_port2_save
  1962. init90:    mov    di,offset work_config
  1963.     ;----------------------------------------
  1964.     ; Initialize the variables of the config data area required
  1965.     ; by config processing.
  1966.     ;----------------------------------------
  1967.     mov    [di].PREDEF_VALUES,3
  1968.     mov    [di].BARREL_INDEX,6
  1969.     mov    ax,readid
  1970.     mov    [di].DC_PORT,al
  1971.  
  1972.     ;----------------------------------------
  1973.     ; Get the datacomm configuration values.
  1974.     ;----------------------------------------
  1975.     mov    ah,al            ; Port X config type in AH
  1976.     mov    al,4            ; full duplex, hardwired form.
  1977.     push    ax
  1978.     mov    ax,0201h        ; 01 -> Personality ID
  1979.     push    ax            ; C02 -> Config values are required.
  1980.     push    ds            ; segment of CONFIGURATION_DATA_AREA
  1981.     push    di            ; pointer to start of data area
  1982.     lea    ax,[di].DC_PORT        ; pointer to start of config values
  1983.     push    ax
  1984.     mov    ax,3            ; function code for CNP_GET_DEV_CONFIG
  1985.     push    ax
  1986.     CALL_CNP_ENTRY
  1987.     mov    ax,saveid
  1988.     mov    [di].dc_port,al
  1989.     ret
  1990. GET_CONFIG_VALUES endp
  1991.  
  1992.  
  1993. ; Set baud  port (1 or 2) in al, Kermit baud code from bdtab in ah.
  1994. ; First translate Kermit baud into HP baud
  1995. set_baud proc near 
  1996.     mov    dx,ax            ; save baud and port
  1997.     mov    di,offset ourbdtab1
  1998.     mov    bl,ah            ; put baud code in bl
  1999.     xor    bh,bh            ; bh=0 for indexing
  2000.     shl    bl,1            ; x2 since two bytes per baud entry
  2001.     mov    al,[di+bx+1]        ; al now has hp baud code
  2002.     cmp    dl,1            ; is it port 1?
  2003.     je    set_baud1        ; e = yes
  2004.     mov    portb_baud,al        ; save it
  2005.     mov    cl,4
  2006.     shl    al,cl            ; port b in left nibble
  2007.     or    al,porta_baud        ; port a baud in right nibble
  2008.     out    baud_port,al        ; write the port a and port b baud
  2009.     clc                ; success
  2010.     ret
  2011. set_baud1:                ; set port 1 baud
  2012.     mov    porta_baud,al        ; save the baud
  2013.     mov    dl,portb_baud
  2014.     mov    cl,4
  2015.     shl    dl,cl
  2016.     or    al,dl         ; port a in right nibble , port b in left nibble
  2017.     out    0ch,al            ; write the port a and port b baud
  2018.     clc                ; success
  2019.     ret
  2020. set_baud endp
  2021.  
  2022. lclose proc near            ; this gets called when kermit quits
  2023.     mov    al,e_port1        ; reset baud to match firmware values
  2024.     call    get_config_values
  2025.     mov    al,[di].dc_baud_rate    ; port a baud rate
  2026.     push    ax            ; save this baud
  2027.     mov    al,e_port2
  2028.     call    get_config_values
  2029.     mov    bl,[di].dc_baud_rate    ; port 2 baud rate
  2030.     mov    cl,4
  2031.     shl    bl,cl            ; port b baud in left nibble
  2032.     pop    ax            ; al has port a baud
  2033.     or    al,bl            ; both bauds in al
  2034.     out    baud_port,al        ; write the baud rate
  2035.     ret
  2036. lclose endp
  2037.  
  2038. code    ends
  2039.     end
  2040.