home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / modem / cp405src.ark / CP4TT.ASM < prev    next >
Assembly Source File  |  1986-12-25  |  23KB  |  693 lines

  1. ; CP4TT.ASM
  2. ;    KERMIT - (Celtic for "FREE")
  3. ;
  4. ;    This is the CP/M-80 implementation of the Columbia University
  5. ;    KERMIT file transfer protocol.
  6. ;
  7. ;    Version 4.0
  8. ;
  9. ;    Copyright June 1981,1982,1983,1984,1985
  10. ;    Columbia University
  11. ;
  12. ; Originally written by Bill Catchings of the Columbia University Center for
  13. ; Computing Activities, 612 W. 115th St., New York, NY 10025.
  14. ;
  15. ; Contributions by Frank da Cruz, Daphne Tzoar, Bernie Eiben,
  16. ; Bruce Tanner, Nick Bush, Greg Small, Kimmo Laaksonen, Jeff Damens, and many
  17. ; others. 
  18. ;
  19. ;    This file contains the code for the TRANSMIT and CONNECT commands,
  20. ;    which communicate with a host which is not running KERMIT.
  21. ;
  22. ; revision history:
  23. ; edit 4: 13-Jan-85 by Vanya J.Cooper Pima Commun. College Tel: 602-884-6809
  24. ;
  25. ;pcc002    28-Dec-84    modules:cp4tt,cp4utl
  26. ;    Add connect mode <esc>P command to toggle printer on
  27. ;    and off.  Conflicts with "official" recommended commands
  28. ;    in protocol manual, but I don't think CP/M will ever get
  29. ;    a PUSH command.
  30. ;
  31. ;pcc003-pcc005    2-Jan-85    vjc    modules:cp4mit,cp4tt,cp4utl
  32. ;    These edits must all be installed together and change the way
  33. ;    logging is handled.  The log file spec is moved to a separate
  34. ;    fcb, and not opened until an actual CONNECT command is given.
  35. ;    This takes care of a NASTY bug that if you used any other file
  36. ;    command between the LOG and CONNECT, the log file would get
  37. ;    written over the last file used.  This also allows logging to
  38. ;    be "permanently" enabled until an CLOSE (new command) for all
  39. ;    CONNECT sessions, like most other kermits do.  If a log file
  40. ;    already exists, it will be appended to.  Also add two new
  41. ;    CONNECT mode commands <esc>Q to suspend logging and <esc>R to
  42. ;    resume.  <esc>R means something else during TRANSMIT, but
  43. ;    logging is never on then, so there shouldn't be any conflict.
  44. ;    I also changed the write code, so that it can handle one more
  45. ;    character after the XOFF is send to stop the host.  This allows
  46. ;    a little "slop" for systems that don't stop immediately (such
  47. ;    as TOPS10), but it didn't help much.
  48. ;
  49. ;pcc008    2-Jan-85    vjc    modules:cp4def,cp4tt,cp4utl
  50. ;    Keyboard input during CONNECT mode can get locked out if
  51. ;    there is enough input from the modem port to keep prtchr
  52. ;    busy.  This can happen for example, if the printer is running
  53. ;    at the same speed as the modem line, leaving you helpless to
  54. ;    turn it off or abort the host.  Add a fairness count, so that
  55. ;    at least every prfair characters we look at console input.
  56. ;
  57. ;pcc012    4-Jan-85    vjc    modules:cp4mit,cp4tt,cp4utl
  58. ;    Use the big buffer for the log file.  Move the log file back
  59. ;    into the common fcb and only save the drive, name, and
  60. ;    extension between connects.  Add new routines to cp4utl to
  61. ;    create or append to an existing file, and to conditionally
  62. ;    advance buffers only if in memory.  Remove edit pcc003 that
  63. ;    allows one more character after the xoff, since it didn't
  64. ;    really work very well and does not fit in well with the way
  65. ;    the buffer advancing routines are set up.  If someone still
  66. ;    thinks this would be useful, it could be put back in with a
  67. ;    little more work.
  68. ;    
  69. ;    While testing this edit, I also noticed another bug that
  70. ;    the command parsing routines do not limit or check the
  71. ;    length of command lines or file specs, trashing what ever
  72. ;    comes after them.  Currently because of where the fcb and
  73. ;    command buffer are located, this does not usually cause a
  74. ;    problem, but could if an extremely long line was typed in,
  75. ;    or in the future multiple fcbs defined elsewhere in memory
  76. ;    were used.  Maybe this should be put on the bug list
  77. ;    somewhere.
  78. ;
  79. ; edit 3: July 27, 1984
  80. ;    Allow assembly with LASM: to CP4TT is linked by CP4PKT, and links
  81. ;    to CP4CPM; remove exclamation points so as not to confuse LASM.
  82. ;    Add Toad Hall TACtrap to TRANSMIT command (TAC intercept character
  83. ;    is only doubled if it's data; when typed by the user, they're not
  84. ;    automatically doubled)
  85. ;
  86. ; edit 2: June 7, 1984
  87. ;    formatting and documentation; add module version number; make sure
  88. ;    console is selected when leaving intchr.
  89. ;
  90. ; edit 1: May, 1984
  91. ;    extracted from CPMBASE.M80 version 3.9; modifications are described
  92. ;    in the accompanying .UPD file.
  93.  
  94. ttver:    db    'CP4TT.ASM  (4)  13-Jan-85$'
  95.  
  96. ;    This is the TRANSMIT command.  It attempts to send a file, even
  97. ;    though there is no KERMIT on the other side.
  98. ;    here from: kermit
  99.  
  100. xmit:    mvi    a,cmofi        ;Parse an input file spec (non-wild).
  101.     lxi    d,fcb        ;Give the address for the FCB.
  102.     call    comnd
  103.      jmp    kermit        ;Give up on bad parse.
  104.     call    cfmcmd
  105.     call    getfil        ;Open file.
  106.     cpi    0FFH        ;Succeed?
  107.     jnz    xmit1
  108.     lxi    d,erms15
  109.     call    prtstr        ;Display error msg.
  110.     jmp    kermit
  111.  
  112. xmit1:    lxi    d,inms19    ;Output start message.
  113.     call    prtstr
  114.     call    escpr        ;Print the escape character.
  115.     lxi    d,inms20    ;Output 2nd part.
  116.     call    prtstr
  117.     call    escpr        ;Print the escape character.
  118.     lxi    d,inms21    ;Print the rest.
  119.     call    prtstr
  120.     mvi    a,1        ;Start file I/O.
  121.     sta    fileio
  122.     xra    a        ;Clear XOFF flag.
  123.     sta    xofflg
  124.     ; fall through into xnext...
  125. ;
  126. ;    assemble another line from the disk file.
  127. ;    here from: previous page, rexmit
  128.  
  129. xnext:    call    prtchr        ; Copy characters from comm line to console
  130.     mvi    c,consta    ;  until user types anything on the console.
  131.     call    bdos
  132.     ora    a
  133.     jz    xnext        ; nothing at console yet.
  134.     lda    eoflag        ;EOF encountered?
  135.     ora    a
  136.     jnz    xend        ;Yes, finish.
  137.     xra    a        ;Reset line buffer counter.
  138.     mov    c,a
  139.     sta    cmaflg        ;Reset carriage return flag.
  140.     lxi    d,cmdbuf    ;Use comnd buffer as line buffer.
  141.     lhld    bufpnt        ; Get current buffer pointer.
  142.     lda    chrcnt        ; Get current byte count
  143.     mov    b,a        ;  in B
  144. xmit30:    dcr    b        ; Assume there's a character there
  145.     jp    xmit2        ; If there was, proceed.
  146.     call    inbuf        ; There wasn't.  Try for another buffer.
  147.      jmp    xmit38        ; End of file.
  148.     lhld    bufpnt        ; Got another buffer.  Get new pointer in HL
  149.     lda    chrcnt        ;  and new byte count
  150.     mov    b,a        ;  in B
  151. xmit2:    mov    a,m        ;Get a character from disk buffer.
  152.     inx    h
  153.     ani    7FH        ;Mask 7 bits.
  154.     jz    xmit30        ;Skip nulls.
  155.     cpi    cr        ;Carriage return?
  156.     jz    xmit32
  157.     cpi    subt        ;CTRL-Z (substitute)?
  158.     jz    xmit37
  159.     cpi    lf        ;Line feed?
  160.     jz    xmit39
  161.     stax    d        ;Save to buffer.
  162.     inx    d
  163.     lda    cmaflg        ;Carriage return seen?
  164.     ora    a
  165.     jnz    xmit31        ;Yes, don't count this character.
  166.     inr    c        ;Count it.
  167. xmit31:    jmp    xmit30        ;Loop for next input byte.
  168.  
  169. ; Carriage return seen.  Start discarding characters until we see a line-feed.
  170. xmit32:    sta    cmaflg        ;Mark return seen.
  171.     jmp    xmit30        ;And continue.
  172.  
  173. ; Control-Z seen. Force end of file, and send the current line.
  174. xmit37:    sta    eoflag        ;Mark EOF for next line.
  175.     ; fall through...
  176. ; End of File encountered. eoflag has already been set; just send current line.
  177. xmit38:
  178.     ; fall through...
  179. ; Linefeed seen. send the current line.
  180. xmit39:    shld    bufpnt        ;Save next buffer pointer.
  181.     mov    a,b        ;Save count of remaining characters.
  182.     sta    chrcnt
  183.     mov    a,c        ;Save line length.
  184.     sta    filcnt
  185.     ; fall through into rexmit...
  186. ;
  187.  
  188. ;    transmit the buffered line.
  189. ;    here from: previous page, intchr
  190.  
  191. rexmit:    lda    filcnt        ;Set up line length.
  192.     sta    cmccnt
  193.     lxi    h,cmdbuf    ;Set up line buffer pointer.
  194.     shld    cmcptr
  195. xmit40:    call    prtchr        ;Receive comm. line & display.
  196.     lda    xofflg        ;XOFF received?
  197.     ora    a
  198.     jnz    xmit40        ;Yes, wait for XON
  199.     lda    cmccnt        ;Any characters left?
  200.     dcr    a
  201.     jm    xmit49        ;No, next state.
  202.     sta    cmccnt
  203.     call    selmdm        ; select modem for outmdm
  204.     lhld    cmcptr        ;Get the character to be sent
  205.     mov    a,m
  206.     inx    h        ;Bump to next character.
  207.     shld    cmcptr
  208.     call    setpar        ;Set parity (if any).
  209.     mov    e,a        ;Save character (with parity)
  210.     call    outmdm        ;Output it to the comm. line.
  211. ; TAC trap: If this character is the TAC intercept character, and the TAC
  212. ; trap is enabled, we have to output it twice.  If the TAC trap is enabled,
  213. ; tacflg contains the intercept character.  (The current character cannot
  214. ; be NUL, so we don't have to worry about doubling nulls in the message)
  215.     lda    tacflg        ; get current intercept character, or zero.
  216.     cmp    m        ; compare against current data character.
  217.     jnz    xmit41        ; if different, do nothing.
  218.     call    setpar        ; match. set appropriate parity,
  219.     mov    e,a        ;  put it in the right register,
  220.     call    outmdm        ;  and output it a second time.
  221. xmit41:
  222.     lda    ecoflg        ;Local echo?
  223.     ora    a
  224.     jz    xmit40        ;No, continue.
  225.     mov    a,e        ;Get the character.
  226.     ani    7FH        ;Mask out parity.
  227.     mov    e,a        ;Display on console.
  228.     call    selcon
  229.     call    outcon
  230.     jmp    xmit40        ;Continue.
  231.  
  232. xmit49:    xra    a        ;Reset last character seen.
  233.     sta    lstchr
  234. xmit50:    call    prtchr        ;Receive comm. line & display.
  235.     call    conchr        ;Read keyboard & send.
  236.      jmp    xendc        ;CLOSE connection.
  237.     lda    lstchr        ;Check last keyboard character.
  238.     cpi    cr        ;Carriage return?
  239.     jz    xnext        ;Yes, prepare to send next line.
  240.     jmp    xmit50        ;Continue, until carriage return.
  241. ;
  242. ;    clean up.
  243. ;   xend - end of file reached. close file, go to connect mode.
  244. ;    here from: xnext.
  245. ;   xendc - user wants out. close file, go to command mode.
  246. ;    here from: rexmit.
  247.  
  248. xend:    call    xmtoff        ;Close file, etc.
  249.     lxi    d,inms22    ;Tell we're done with transmission
  250.     jmp    telnt1        ;Branch to CONNECT command.
  251.  
  252. xendc:    call    xmtoff        ;Close file, etc.
  253.     jmp    kermit        ;Back to command loop.
  254.  
  255. xmtoff:    mvi    c,closf        ;Close file.
  256.     lxi    d,fcb
  257.     call    bdos
  258.     xra    a        ;Terminate file I/O.
  259.     sta    fileio
  260.     ret
  261. ;
  262. ;   telnet - the CONNECT command.
  263. ;    here from: kermit
  264. ;   telnt1 - entry to connect mode from TRANSMIT command
  265. ;    here from: xend
  266.  
  267. telnet:    call    cfmcmd
  268.     lxi    d,infms7    ;Output start of message
  269. ; enter here from TRANSMIT command.
  270. telnt1:    call    prtstr
  271.     call    escpr        ;Print the escape char.
  272.     lxi    d,infms8    ;Output some more of the message
  273.     call    prtstr
  274.     call    escpr        ;Print the escape char again.
  275.     lxi    d,inms8a    ;Print the remainder of the message
  276.     call    prtstr
  277.     call    syscon        ;do system-dependent stuff
  278.     lda    logflg        ;[pcc005] Want a log?
  279.     ora    a        ;[pcc005]
  280.     cnz    logopn        ;[pcc005] Open if so
  281.  
  282. chrlup:    call    prtchr        ;See if char at port (send to console).
  283.     call    conchr        ;See if char at console (send to port).
  284.      jmp    kermit        ;requested to end session - go to command loop.
  285.     jmp    chrlup        ;Go do it again.
  286. ;
  287. ;
  288. ;    prtchr - copy characters from comm line to console
  289. ;    returns: nonskip, console selected.
  290. ;    called by: xnext, rexmit, telnet
  291. ;
  292.  
  293. prtchr:    call    selmdm        ; select modem port
  294.     call    inpmdm        ; try to get a character from it
  295.     ora    a        ; test character
  296.     jnz    prtch0        ; if non-zero, process it.
  297.     sta    prtcnt        ;[pcc008] zero out prt fairness count
  298.     call    selcon        ; select console
  299.     ret            ; return.
  300.  
  301. prtch0: ani    7FH        ; drop parity bit.
  302.     jz    prtchr        ; ignore null (filler)
  303.     cpi    del        ; ignore delete, too
  304.     jz    prtchr
  305.     cpi    xon        ;Is it an XON?
  306.     jz    prtxon        ;yes
  307.     cpi    xoff        ;Is it an XOFF?
  308.     jz    prtxof        ;yes
  309.     mov    e,a        ;Set the char aside.
  310.     lda    vtflg        ;Get the VT52 emulation flag.
  311.     cpi    1        ;Is the flag set?
  312.     jnz    prtch1        ;If not, don't do this stuff.
  313.     lda    escflg        ;Get the escape flag.
  314.     ora    a        ;Are we working on an escape sequence?
  315.     jz    prtch2        ;If not, continue.
  316.     call    vt52        ;If so, work on it some more
  317.     jmp    prtchr        ;try for more characters.
  318.  
  319. prtch2:    mov    a,e        ;normal text.
  320.     cpi    esc        ;Is the char an escape?
  321.     jnz    prtch1        ;If not skip on.
  322.     mvi    a,1
  323.     sta    escflg        ;Set the escape flag: escape seen.
  324.     jmp    prtchr        ;Get another char...
  325.  
  326. prtch1:    call    sysflt        ; ok to print this character (in E)?
  327.     ora    a
  328.     jz    prtchr        ; no, skip it.
  329.     lda    logflg        ;Get the log flag.
  330.     cpi    81H        ;[pcc003] Are we logging
  331.     cz    logit        ;[pcc003] Do so if needed
  332.     call    selcon        ; select console
  333.     lda    prnflg        ;Get Print parallel flag
  334.     ora    a
  335.     cnz    outlpt        ; output to printer if flag set
  336.     call    outcon        ; output to console.
  337.     lxi    h,prtcnt    ;[pcc008] point to prt fairness count
  338.     inr    m        ;[pcc008] bump
  339.     mov    a,m        ;[pcc008] get it in a
  340.     cpi    prfair+1    ;[pcc008] time to be fair?
  341.     jm    prtchr        ;[pcc008] no, go around again.
  342.     mvi    m,0        ;[pcc008] reset count
  343.     ret            ;[pcc008] and return
  344.  
  345. ; I don't think we want to print xon/xoff - this should be
  346. ; flow control only across the link between us and the host.
  347. ; (besides, IBM host xon's don't make sense to most micros)
  348. ; remember xon/xoff state in xofflg (zero = xon, non-zero = xoff)
  349. prtxon:    xra    a        ;Yes, reset XOFF flag
  350. prtxof:    sta    xofflg
  351.     jmp    prtchr        ; look for another character
  352. ; ;[pcc005] Log file routines
  353.  
  354. ;[pcc005]
  355. ;    logopn - open the log file
  356. ;    Open the log file and append to it if it already exists
  357. ;    or create one if not.
  358.  
  359. logopn:    lxi    h,lognam    ;[pcc012] copy name
  360.     lxi    d,fcb        ;[pcc012] to fcb
  361.     lxi    b,12        ;[pcc012] 12 bytes
  362.     call    mover        ;[pcc012] copy it
  363.     call    appfil        ;[pcc012] open file for appending
  364.     jmp    logerr        ;[pcc012] error
  365.     lxi    h,logflg    ;[pcc005] point to log flag
  366.     mvi    a,80H        ;[pcc005] file open flag
  367.     ora    m        ;[pcc005] or in contents of logflg
  368.     mov    m,a        ;[pcc005] and store back
  369.     lxi    d,inms28    ;[pcc005] assume logging is on
  370.     cpi    81H        ;[pcc005] check
  371.     jz    prtstr        ;[pcc005] print msg if true
  372.     lxi    d,inms27    ;[pcc005] no, must be suspended
  373.     jmp    prtstr        ;[pcc005] print and return
  374.  
  375. ;
  376. ;    logit - output character in E to log file.
  377. ;    we assume the host recognizes xon/xoff. (we probably shouldn't)
  378. ;    modem port is selected.
  379. ;    preserves de
  380. ;    called by: prtchr
  381.  
  382. logit:    lxi    h,chrcnt    ;[pcc012] point to buffer count
  383.     dcr    m        ;[pcc012] and decrement
  384.     jp    logit1        ;[pcc012] continue if ok
  385.     push    d        ;[pcc012] save de
  386.     call    outadv        ;[pcc012] advance buffer if in memory
  387.     call    logwrt        ;[pcc012] sigh, time to write to disk
  388.     pop    d        ;[pcc012] restore de
  389.     lda    logflg        ;[pcc012] get logging flag
  390.     ora    a        ;[pcc012] Did we quit because of an error
  391.     rz            ;[pcc012] return now if so
  392. logit1:    lhld    bufpnt        ;[pcc012] get buffer pointer
  393.     mov    m,e        ;Store the char.
  394.     inx    h
  395.     shld    bufpnt
  396.     ret            ;[pcc012] and return
  397.  
  398. ;[pcc012]
  399. ;  logwrt - write to log file with XON/XOFF since it may take a while.
  400.  
  401. logwrt:    mvi    a,xoff        ;^S to stop the host while we write the buffer.
  402.     call    setpar        ; set correct parity...
  403.     mov    e,a
  404.     call    outmdm        ; output it.
  405.     call    outbuf        ;[pcc012] output the buffer and advance
  406.     call    logerr        ;[pcc005] quit if error
  407.     mvi    a,xon        ;^Q to restart the host
  408.     call    setpar        ; set appropriate parity
  409.     mov    e,a
  410.     call    outmdm        ; send it.
  411.     ret            ;[pcc012]
  412.  
  413. ;[pcc005]
  414. ;    logcls - Close the log file and reset the flag
  415.  
  416. logcls:    lxi    d,infms6    ;[pcc005] Tell user we are closing file.
  417.     call    prtstr        ;[pcc005]
  418.     call    clofil        ;[pcc012] and do it
  419.     jmp    logerr        ;[pcc005] jump if error
  420.     lxi    h,logflg    ;[pcc005] point to flag
  421.     mov    a,m        ;[pcc005] get it
  422.     ani    7FH        ;[pcc005] clear the open bit
  423.     mov    m,a        ;[pcc005] and store back
  424.     ret            ;[pcc005]
  425.  
  426. ;[pcc005]
  427. ;    logerr - here on a variety of logging errors
  428. ;    just close the file and disable logging
  429. ;    called from logopn,logptr,logcls
  430.  
  431. logerr:    lxi    d,erms22    ;[pcc005] Error message
  432.     call    prtstr        ;[pcc005] print it
  433.     mvi    c,closf        ;[pcc005] Close the file.
  434.     lxi    d,fcb        ;[pcc012]
  435.     call    bdos        ;[pcc005] 
  436.     xra    a        ;[pcc005] clear logflg
  437.     sta    logflg        ;[pcc005] so don't try again
  438.     ret            ;[pcc005]
  439. ;
  440. ;
  441. ;    VT52 emulation.
  442. ;    called by: prtchr
  443. ;    A/ contents of escflg (guaranteed non-zero)
  444. ;    E/ current character
  445. ;    modem is selected.
  446. ;
  447. vt52:    cpi    1        ; first character after escape?
  448.     jnz    vt52y        ; no, must be doing cursor positioning.
  449. ;
  450. ;    E contains the character that followed the escape.
  451. ;    valid characters are:
  452. ;    A - cursor up
  453. ;    B - cursor down
  454. ;    C - cursor right
  455. ;    D - cursor left
  456. ;    F - enter graphics mode (hard to do on a non-vt52)
  457. ;    G - exit graphics mode
  458. ;    H - home
  459. ;    I - reverse linefeed
  460. ;    J - erase to end of screen
  461. ;    K - erase to end of line
  462. ;    Y - cursor positioning leadin
  463. ;    Z - identify terminal as VT52
  464. ;    [ - enter hold-screen mode (not supported)
  465. ;    \ - exit hold-screen mode (not supported)
  466. ;    > - enter alternate-keypad mode? (not supported)
  467. ;    = - exit alternate-keypad mode? (not supported)
  468. ;
  469. ;    Invalid sequences are handled as the VT52 does - the escape and
  470. ;    the following character are swallowed, never to be seen again.
  471. ;    For <esc>E, the translation table may contain just '$' (no action),
  472. ;    or may be used as clear-and-home, as in the Heath/Zenith H19.
  473. ;
  474.     mov    a,e        ; get the second character of the sequence.
  475.     cpi    'Y'        ; if cursor lead-in handle it.
  476.     jnz    vt52a        ; if not, go on.
  477.     mvi    a,2        ; state = 2: row follows.
  478.     sta    escflg        ; update the flag.
  479.     ret            ; back for another character
  480.  
  481. vt52a:    cpi    'Z'        ; VT52 ID query?
  482.     jz    vt52id        ; yes. claim to be one.
  483.     cpi    'A'        ;Less than an 'A'?
  484.     jm    vtig        ;Yes - ignore.
  485.     cpi    'K'+1        ;Greater than 'K'?
  486.     jp    vtig        ;Yes - ignore.
  487.     sui    'A'        ;Else make into index.
  488.     rlc            ;Multiply by four.
  489.     rlc            ;(Shift left twice.)
  490.     lhld    pttab        ;Load base addr of table.
  491.     mov    e,a        ;Move a into de pair.
  492.     mvi    d,00H        ;Zero out high byte.
  493.     dad    d        ;Double add index+offset.
  494.     xchg            ;Exchange de with hl.
  495.     call    selcon        ; select console
  496.     call    prtstr        ;and syscall.
  497. vtig:                ;Ignore escape sequence.
  498.     xra    a        ;Reset the ol' escape flag.
  499.     sta    escflg
  500.     ret            ;Return home.
  501.  
  502. ; here for <esc>Z.  Tell the host we're a VT52. (Sure we are...)
  503. vt52id:    mvi    a,esc        ; response is escape...
  504.     call    setpar        ; (need correct parity)
  505.     mov    e,a
  506.     call    outmdm        ; (console already selected)
  507.     mvi    a,'/'        ; ... slash ...
  508.     call    setpar        ; (with parity)
  509.     mov    e,a
  510.     call    outmdm
  511.     mvi    a,'K'        ; ... K.
  512.     call    setpar
  513.     mov    e,a
  514.     call    outmdm
  515.     jmp    vtig        ; clear escape-sequence flag and return.
  516.  
  517. ; here when escflg isn't 0 or 1 - processing cursor positioning sequence.
  518. vt52y:    cpi    2        ; looking for row? (y-coordinate)
  519.     jnz    vt52x        ; no, must be column.
  520.     mov    a,e        ; yes. get coordinate
  521.     sui    (' '-1)        ; convert from ascii (1 = top line)
  522.     sta    vtyval        ; store for later
  523.     mvi    a,3        ; advance to next state (x coord)
  524.     sta    escflg        ; store it
  525.     ret            ; try for another character
  526.  
  527. ; here when escflag isn't 0, 1, or 2 - it must be 3. (right?)
  528. ; E holds the last character of the cursor positioning sequence.
  529. vt52x:    xra    a        ; end of escape sequence, reset state.
  530.     sta    escflg
  531.     mov    a,e        ; get column (' ' is left margin)
  532.     sui    (' '-1)        ; make left margin be one
  533.     mov    c,a        ; stash column in c
  534.     lda    vtyval        ; get row number
  535.     mov    b,a        ;  in b
  536.     call    selcon        ; select console
  537.     call    csrpos        ; call system-dependent cursor positioner
  538.     ret            ; all through.
  539. ;
  540. ;
  541. ;    conchr - copy character from console to comm line, processing
  542. ;    (kermit's) escape sequences.
  543. ;    Enter and exit with console selected.
  544. ;    nonskip return: transparent mode terminated.
  545. ;    skip return:    still in transparent mode.
  546. ;    called by: rexmit, telnet
  547.  
  548. conchr:    call    inpcon        ;Try to get a character from the console
  549.     ani    07FH        ;Keep only 7 bits
  550.     jz    rskp        ;Null means nothing there.
  551.     mov    e,a        ;Move the char for comparison.
  552.     sta    lstchr        ;Save it
  553.     lda    escchr        ;Get the escape char.
  554.     cmp    e        ;Is it an escape char?
  555.     jz    intchr        ;If so go process it.
  556.     call    selmdm        ; select the modem
  557.     mov    a,e        ;Get the char.
  558.     call    setpar        ;Set parity (if any).
  559.     mov    e,a        ;Restore it.
  560.     call    outmdm        ;Output the char to the port.
  561.     call    selcon        ; reselect console
  562.     lda    ecoflg        ;Get the echo flag.
  563.     ora    a        ;Is it turned on?
  564.     jz    rskp        ;If not we're done here.
  565.     mov    a,e        ;Get the char.
  566.     ani    7FH        ;Turn off the parity bit.
  567.     mov    e,a
  568.     call    outcon        ; echo the character.
  569.     jmp    rskp        ; use skip return
  570. ;
  571. ;    transparent escape character has been typed. dispatch on second
  572. ;    character. (console is still selected)
  573. ;    here from: conchr
  574.  
  575. intchr: call    inpcon        ; get another character from the console
  576.     ora    a        ; zero means no character available yet.
  577.     jz    intchr        ; If so, loop until we get a char.
  578.     mov    b,a        ;Save the actual char.
  579.     cpi    ctrlc        ;is it Control-C?
  580.     jz    contc        ;yes
  581.     ani    137O        ;Convert to upper case.
  582.     cpi    'C'        ;Is it close?
  583.     jnz    intch0        ;If not proceed.
  584. contc:    lxi    d,infms9    ;Say we are back.
  585.     call    prtstr
  586.     call    syscls        ; call system-dependent close routine
  587.     lda    logflg        ;Get the log flag.
  588.     ora    a        ;[pcc005] Check if open
  589.     cm    logcls        ;[pcc005] Close if needed
  590.     ret
  591.  
  592. ;Here if not a 'C' or '^C'
  593.  
  594. intch0: cpi    'S'        ;Is it status?
  595.     jnz    inch01        ;If not, proceed.
  596.     call    stat01        ;Print out the status stuff.
  597.     call    prcrlf        ;[pcc011] add a crlf
  598.     jmp    rskp        ;return from conchr
  599.  
  600. inch01:    cpi    'R'-100O    ;Control-R?
  601.     jz    inch02        ;Yes
  602.     cpi    'R'        ;(plain) R?
  603.     jnz    inch03        ;No
  604. inch02:    lda    fileio        ;TRANSMIT in progress?
  605.     ora    a
  606.     jz    inch03        ;No,ignore
  607.     pop    b        ;Remove return address (non-local goto)
  608.     jmp    rexmit        ;Retransmit line
  609.  
  610. inch03:    mov    a,b        ;Get the char.
  611.     cpi    '?'        ;Is it a help request?
  612.     jnz    intch1        ;If not, go to the next check.
  613.     lda    fileio        ;TRANSMIT in progress?
  614.     ora    a
  615.     jz    inch3a        ;[pcc003] No
  616.     lxi    d,xmthlp    ;Tell about R too
  617.     call    prtstr
  618. inch3a:    lda    logflg        ;[pcc003] Logging flag
  619.     ora    a        ;[pcc003] see if active
  620.     jp    inch04        ;[pcc005] jump if no file open
  621.     lxi    d,loghlp    ;[pcc003] yes, tell about R AND Q
  622.     call    prtstr        ;[pcc003]
  623. inch04:    lxi    d,inthlp    ;If so, get the address of the help message.
  624.     call    prtstr
  625.     call    sysinh        ; print system-dependent help message
  626.     lxi    d,inhlp1    ; Tell about doubling the escape character
  627.     call    prtstr
  628.     call    escpr        ;Print escape character
  629.     lxi    d,inhlp2    ;Print the rest
  630.     call    prtstr
  631.     jmp    intchr        ;Get another char.
  632.  
  633. intch1: mov    a,b        ;Get the character.
  634.     cpi    '0'        ;Is it '0', to send a null?
  635.     jnz    intch3        ;No.
  636.     xra    a        ;Yes, send an ASCII zero.
  637.     call    setpar        ; with the correct parity
  638.     mov    e,a
  639.     call    selmdm        ; (to the modem...)
  640.     call    outmdm
  641.     call    selcon        ; return with console selected
  642.     jmp    rskp
  643.  
  644. intch3:    lda    escchr        ;Get the escape char.
  645.     cmp    b        ;Is it the escape char?
  646.     jnz    intch4        ;[pcc002] jump if not
  647.     mov    a,b        ;Get the char.
  648.     call    setpar
  649.     mov    e,a        ;Restore it.
  650.     call    selmdm
  651.     call    outmdm        ;Output it.
  652.     call    selcon        ;We promised console would be selected...
  653.     jmp    rskp        ;Return, we are done here.
  654. intch4:    mov    a,b        ;[pcc002] get it again
  655.     ani    137o        ;[pcc002] in upper case
  656.     cpi    'P'        ;[pcc002] toggle printer?
  657.     jnz    intch5        ;[pcc003] nope
  658.     lda    prnflg        ;[pcc002] get printer flag
  659.     xri    01h        ;[pcc002] complement it
  660.     sta    prnflg        ;[pcc002] and put back
  661.     jmp    rskp        ;[pcc002]
  662. intch5:    lda    logflg        ;[pcc003] get log flag
  663.     ora    a        ;[pcc003] See if open
  664.     jp    intch7        ;[pcc003] no, skip R and Q
  665.     mov    a,b        ;[pcc003] get back chr
  666.     ani    137o        ;[pcc003] make upper case
  667.     cpi    'R'        ;[pcc003] Is it R
  668.     jnz    intch6        ;[pcc003] Jump if not
  669.     mvi    a,81H        ;[pcc003] set flag for logging
  670.     sta    logflg        ;[pcc003] put it back
  671.     lxi    d,inms28    ;[pcc003] message
  672.     call    prtstr        ;[pcc003]
  673.     jmp    rskp        ;[pcc003] done
  674. intch6:    cpi    'Q'        ;[pcc003] Quit logging?
  675.     jnz    intch7        ;[pcc003] no
  676.     mvi    a,82H        ;[pcc003] flag for open, but suspended
  677.     sta    logflg        ;[pcc003] store away
  678.     lxi    d,inms27    ;[pcc003] keep them informed
  679.     call    prtstr        ;[pcc003]
  680.     jmp    rskp        ;[pcc003]
  681. intch7:                ;[pcc003]
  682.  
  683. intchz:    mov    a,b        ; not recognized. get saved copy back.
  684.     call    sysint        ; interpret system-dependent sequences
  685.      jmp    rskp        ;  done. return (from conchr).
  686.     mvi    e,'G'-100O    ;Otherwise send a beep.
  687.     call    outcon        ; to the console.
  688.     jmp    rskp
  689. ;
  690. IF lasm
  691.     LINK    CP4CPM
  692. ENDIF;lasm
  693.