home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / modems / modem / cp405src.ark / CP4MIT.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-12-26  |  28.4 KB  |  963 lines

  1. ; CP4MIT.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 system-independent initialization, the main
  20. ;    loop, and the commands that don't have any place better to go
  21. ;    (BYE, EXIT, HELP, LOG, SET, SHOW, and STATUS).
  22. ;
  23. ; revision history:
  24. ; edit 8: February 6, 1895
  25. ;    Add a PORT status/show routine for those machines that have more
  26. ;    than one they can talk to. It also required a port storage variable
  27. ;     a la SPEED and the necessary code to handle it in the SET routine.
  28. ;    [Hal Hostetler]
  29. ;
  30. ; edit 7: 13-Jan-85 by Vanya J.Cooper Pima Commun. College Tel: 602-884-6809
  31. ;
  32. ;pcc003-pcc005    2-Jan-85    vjc    modules:cp4mit,cp4tt,cp4utl
  33. ;    These edits must all be installed together and change the way
  34. ;    logging is handled.  The log file spec is moved to a separate
  35. ;    fcb, and not opened until an actual CONNECT command is given.
  36. ;    This takes care of a NASTY bug that if you used any other file
  37. ;    command between the LOG and CONNECT, the log file would get
  38. ;    written over the last file used.  This also allows logging to
  39. ;    be "permanently" enabled until an CLOSE (new command) for all
  40. ;    CONNECT sessions, like most other kermits do.  If a log file
  41. ;    already exists, it will be appended to.  Also add two new
  42. ;    CONNECT mode commands <esc>Q to suspend logging and <esc>R to
  43. ;    resume.  <esc>R means something else during TRANSMIT, but
  44. ;    logging is never on then, so there shouldn't be any conflict.
  45. ;    I also changed the write code, so that it can handle one more
  46. ;    character after the XOFF is send to stop the host.  This allows
  47. ;    a little "slop" for systems that don't stop immediately (such
  48. ;    as TOPS10), but it didn't help much.
  49.  
  50. ;pcc012    4-Jan-85    vjc    modules:cp4mit,cp4tt,cp4utl
  51. ;    Use the big buffer for the log file.  Move the log file back
  52. ;    into the common fcb and only save the drive, name, and
  53. ;    extension between connects.  Add new routines to cp4utl to
  54. ;    create or append to an existing file, and to conditionally
  55. ;    advance buffers only if in memory.  Remove edit pcc003 that
  56. ;    allows one more character after the xoff, since it didn't
  57. ;    really work very well and does not fit in well with the way
  58. ;    the buffer advancing routines are set up.  If someone still
  59. ;    thinks this would be useful, it could be put back in with a
  60. ;    little more work.
  61. ;    
  62. ;    While testing this edit, I also noticed another bug that
  63. ;    the command parsing routines do not limit or check the
  64. ;    length of command lines or file specs, trashing what ever
  65. ;    comes after them.  Currently because of where the fcb and
  66. ;    command buffer are located, this does not usually cause a
  67. ;    problem, but could if an extremely long line was typed in,
  68. ;    or in the future multiple fcbs defined elsewhere in memory
  69. ;    were used.  Maybe this should be put on the bug list
  70. ;    somewhere.
  71.  
  72. ;pcc013    8-Jan-85    vjc    modules:cp4mit,cp4utl,cp4typ
  73. ;    Replace CLOSE command to cancel session logging to SET
  74. ;    LOGGING ON/OFF.  This seems to fit in with the command
  75. ;    structure better.  Default the log file to KERMIT.LOG
  76. ;    incase no previous LOG command.  Logging is also enabled
  77. ;    by LOG command, as before.
  78.  
  79. ; edit 6: September 8, 1984
  80. ;    Add VERSION command, to display the internal version strings.
  81. ;    Move command tables here from CP4UTL, and translate string
  82. ;    lengths in them to decimal (how many fingers do YOU got?).
  83. ;    Replace some jump tables with dispatch addresses in tables.
  84. ;    Make help text for SET command consistent with top level help text.
  85. ;
  86. ; edit 5: August 21, 1984
  87. ;    Add word at 0100H to allow us to exit cleanly from DDT (shifting
  88. ;    entry section by two bytes).
  89. ;
  90. ; edit 4: August 3, 1984 (CJC)
  91. ;    Remove "mover" from entry section, as it now lives in CP4SYS.
  92. ;
  93. ; edit 3: July 27, 1984 (CJC)
  94. ;    Merge LASM support from Toad Hall: most of CP4MIT is now in CP4UTL.
  95. ;    When assembling with LASM, CP4MIT is linked by CP4DEF; it links to
  96. ;    CP4PKT.  Add SET TACTRAP command.  Separate out display routines so
  97. ;    we can eventually do "SHOW <parameter>".  Save both bytes of baud
  98. ;    rate in speed, and check both bytes when displaying baud rate.  Move
  99. ;    header info to CP4KER.ASM.  Add onoff and chkkey routines to simplify
  100. ;    SET command (Toad Hall)
  101. ;
  102. ; edit 2: June 8, 1984
  103. ;    formatting and documentation; delete unreferenced variables and some
  104. ;    unnecessary labels; move setpar here from cp4pkt; add module version
  105. ;    string; make this version 4.01.
  106. ;
  107. ; edit 1: May, 1984
  108. ;    extracted from CPMBASE.M80 version 3.9; modifications are described
  109. ;    in the accompanying .UPD file.
  110.  
  111. ;
  112.     ASEG
  113.     ORG    100H
  114.  
  115. ; The CCP invokes programs with a CALL 100H, with the stack pointer set to
  116. ; 100H.  When we exit to CP/M, we do so with a RET, avoiding a warm boot.
  117. ; Unfortunately, DDT starts programs with a jump, not a call, so when we
  118. ; attempt to return to CP/M, we blow the stack and use the word at 100H as
  119. ; the new PC.  Put a 0 there so we reboot instead of dying horribly.
  120. ; (Fortunately, this happens to be two NOP's).
  121.     dw    0
  122.     jmp    start    ; Bypass entry section
  123.  
  124. ;
  125. ;    Entry section for system-independent part.  This contains
  126. ;    jumps to routines needed by the system support module.
  127. ;
  128. entries:
  129.     jmp    kermit        ; reentry address
  130.     jmp    nout        ; output HL in decimal
  131. entsiz    equ    $-entries    ; length of entry section
  132. ;
  133. ;    End of entry section.  As a consistency check, the expected
  134. ;    length of this section is stored by the system-dependent
  135. ;    module in the linkage section at the end of Kermit, and
  136. ;    tested at initialization.
  137.  
  138. mitver:    db    'CP4MIT.ASM (8)  6-Feb-85$'    ; name, edit number, date
  139. ;
  140. ;
  141. ;    Initialization
  142. ;
  143. start:    lxi    h,0        ; Clear out hl pair
  144.     dad    sp        ; and fetch the system stack pointer
  145.     shld    oldsp        ; and save for later restoral
  146.     lxi    sp,stack    ; move in our own stack.
  147.     lxi    d,version    ; print Kermit version
  148.     call    prtstr        ;  before we do too much
  149.     mvi    c,rddrv        ;Get our logged in drive
  150.     call    BDOS
  151.     inr    a        ;relative 1
  152.     sta    CURDSK        ;and save it for later
  153. ;
  154. ;    Make sure the overlay is in place...
  155. ;
  156.     lhld    lnkflg
  157.     mov    a,h
  158.     ora    l        ; if lnkflg is still zero,
  159.     jz    start1        ;  the configuration overlay is missing.
  160.     lxi    d,-lnksiz    ; if it's not equal to lnksiz,
  161.     dad    d        ;  we've probably got the wrong
  162.     mov    a,h        ;  version of the configuration overlay.
  163.     ora    l
  164.     jnz    start2
  165.     lhld    lnkent        ; make sure the overlay knows how long
  166.     lxi    d,-entsiz    ; our entry section is, so they don't miss.
  167.     dad    d
  168.     mov    a,h
  169.     ora    l
  170.     jnz    start2
  171.                 ; might be ok.
  172.     call    sysinit        ; do system-dependent initialization
  173.     lxi    d,inms26    ; offer some advice on getting help
  174.     call    prtstr
  175.     jmp    kermit        ; Start main loop.
  176.  
  177. start1:    lxi    d,erms20    ; "Kermit has not been configured"
  178.     call    prtstr        ; print error message
  179.     jmp    exit2        ;  and exit.
  180.  
  181. start2:    lxi    d,erms21    ; "Consistency check on configuration failed"
  182.     call    prtstr        ; print error message
  183.     jmp    exit2        ;  and exit.
  184. ;
  185. ;This is the main KERMIT loop.  It prompts for and gets the users commands.
  186.  
  187. kermit:    lxi    sp,stack    ; get new stack pointer, old one might be bad.
  188.     call    selcon        ; make sure console is selected.
  189.     xra    a
  190.     sta    mfflg1        ;reset MFNAME
  191.     sta    mfflg2        ;ditto
  192.     lda    curdsk        ; update the prompt
  193.     adi    'A'-1
  194.     sta    kerm1
  195.     lxi    d,kerm
  196.     call    prompt        ;Prompt the user.
  197.     lxi    d,comtab
  198.     lxi    h,tophlp
  199.     call    keycmd        ; Get a keyword
  200.     xchg            ; Get result (dispatch address) into HL
  201.     pchl            ; Dispatch.
  202.  
  203. ;    here from: log, setcom, read, cfmcmd
  204. kermt3:    lxi    d,ermes3    ;"Not confirmed"
  205.     call    prtstr
  206.     jmp    kermit        ;Do it again.
  207.  
  208. ;    Structure of command table:
  209. ;
  210. ;    1) Number of entries.
  211. ;    2) Each entry is arranged as follows:
  212. ;        a) length of command in bytes.
  213. ;        b) 'name of command and $-sign'
  214. ;        c) address of routine to process command
  215. ;
  216. ;    ---> Note this command table is in alphabetic order.
  217. ;
  218.  
  219. comtab:    db    17            ;[pcc013] 17 entries
  220.     db    3, 'BYE$'
  221.         dw bye
  222.     db    7, 'CONNECT$'
  223.         dw telnet
  224.     db    9, 'DIRECTORY$'
  225.         dw dir
  226.     db    5, 'ERASE$'
  227.         dw era
  228.     db    4, 'EXIT$'
  229.         dw exit
  230.     db    6, 'FINISH$'
  231.         dw finish
  232.     db    3, 'GET$'
  233.         dw read        ;Same as RECEIVE
  234.     db    4, 'HELP$'
  235.         dw help
  236.     db    3, 'LOG$'
  237.         dw log
  238.     db    6, 'LOGOUT$'
  239.         dw logout
  240.     db    7, 'RECEIVE$'
  241.         dw read
  242.     db    4, 'SEND$'
  243.         dw send
  244.     db    3, 'SET$'
  245.         dw setcom
  246.     db    4, 'SHOW$'
  247.         dw show
  248.     db    6, 'STATUS$'
  249.         dw status
  250.     db    8, 'TRANSMIT$'
  251.         dw xmit
  252.     db    7, 'VERSION$'
  253.         dw shover
  254.  
  255. ; top-level help message. Caps indicate keywords.
  256. ; this text is also printed by the HELP command.
  257.  
  258. tophlp:    db    cr,lf,'BYE to host (LOGOUT) and exit to CP/M'
  259.     db    cr,lf,'CONNECT to host on selected port'
  260.     db    cr,lf,'ERASE a CP/M file'
  261.     db    cr,lf,'EXIT to CP/M'
  262.     db    cr,lf,'FINISH running Kermit on the host'
  263.     db    cr,lf,'HELP by giving this message'
  264.     db    cr,lf,'DIRECTORY of current used Micro-disk'
  265.     db    cr,lf,'LOG the terminal sessions to a file'
  266.     db    cr,lf,'LOGOUT the host'
  267.     db    cr,lf,'RECEIVE file from host'
  268.     db    cr,lf,'SEND file to host'
  269.     db    cr,lf,'SET a parameter'
  270.     db    cr,lf,'SHOW the parameters'
  271.     db    cr,lf,'STATUS of Kermit'
  272.     db    cr,lf,'TRANSMIT file to host (in connect state)'
  273.     db    cr,lf,'VERSION of Kermit running$'        ;[pcc005]
  274.  
  275. ;
  276. ;    This is the BYE command.  It tells the remote KERSRV to logout,
  277. ;    then exits.
  278.  
  279. bye:    call    cfmcmd
  280.     call    logo        ;Tell the main frame to logout.
  281.      jmp    kermit        ;If it fails, don't exit.
  282.     call    sysbye        ; success. do system-dependent cleanup
  283.     jmp    exit1        ;Exit Kermit.
  284.  
  285. ;    This is the EXIT command.  It leaves KERMIT and returns to CP/M.
  286. ;    alternate entries: exit1, from BYE command;
  287. ;    exit2, from initialization (if it fails)
  288.  
  289. exit:    call    cfmcmd        ; confirm...
  290. exit1:    call    sysexit        ; do system-dependent termination
  291. exit2:    lhld    oldsp        ;Get back the system stack
  292.     sphl            ;and restore it.
  293.     ret            ;Then return to system.
  294.  
  295. ;    This is the HELP command.  It gives a list of the commands.
  296.  
  297. help:    call    cfmcmd
  298.     lxi    d,tophlp    ;The address of the help message.
  299.     call    prtstr
  300.     jmp    kermit
  301. ;
  302. ;    This is the LOG command.  It logs a session to a file.
  303.  
  304. log:    mvi    a,cmofi        ;[pcc005] Parse an output file spec.
  305.     lxi    d,fcb        ;[pcc012] where to put it
  306.     call    comnd
  307.      jmp    kermt3
  308.     call    cfmcmd
  309.     lxi    h,fcb        ;[pcc012] copy file name and ext
  310.     lxi    d,lognam    ;[pcc012] to a safe place
  311.     lxi    b,12        ;[pcc012] 12 bytes
  312.     call    mover        ;[pcc012] zap ...
  313.     mvi    a,1        ;[pcc005] set flag for logging
  314.     sta    logflg        ;[pcc005]
  315.     jmp    kermit        ;[pcc005]
  316.  
  317. ;
  318. ; This is the SET command.
  319.  
  320. setcom:    lxi    d,settab    ;Parse a keyword from the set table.
  321.     lxi    h,sethlp
  322.     call    keycmd
  323.     xchg            ; Get result (dispatch address) into HL
  324.     pchl            ; Dispatch.
  325.  
  326. settab:    db    16        ;[pcc013] 16 entries [Toad Hall]
  327.                 ; Value is address of processing routine.
  328.     db     9, 'BAUD-RATE$'
  329.         dw baud
  330.     db    16, 'BLOCK-CHECK-TYPE$'
  331.         dw blkset
  332.     db     5, 'DEBUG$'
  333.         dw setdbg
  334.     db    12, 'DEFAULT-DISK$'
  335.         dw setdisk
  336.     db     6, 'ESCAPE$'
  337.         dw escape
  338.     db     9, 'FILE-MODE$'
  339.         dw setcpm
  340.     db     3, 'IBM$'
  341.         dw ibmset
  342.     db    10, 'LOCAL-ECHO$'
  343.         dw locall
  344.     db     7, 'LOGGING$'            ;[pcc013]
  345.         dw setlog            ;[pcc013]
  346.     db     6, 'PARITY$'
  347.         dw parset
  348.     db     4, 'PORT$'
  349.         dw prtset
  350.     db     7, 'PRINTER$'
  351.         dw setprn
  352. ;*    db     7, 'RECEIVE$'
  353. ;*        dw kermt3            ;Not implemented yet.
  354. ;*    db     4, 'SEND$'
  355. ;*        dw setsnd            ;Ditto
  356.     db     7, 'TACTRAP$'
  357.         dw settac
  358.     db     5, 'TIMER$'
  359.         dw settim
  360.     db    14, 'VT52-EMULATION$'
  361.         dw vt52em
  362.     db     7, 'WARNING$'
  363.         dw filwar
  364.  
  365. ; help message for SET command. Caps indicate keywords
  366.  
  367. sethlp:    db    cr,lf,'BAUD-RATE'
  368.     db    cr,lf,'BLOCK-CHECK-TYPE for error detection'
  369.     db    cr,lf,'DEBUG message control'
  370.     db    cr,lf,'DEFAULT-DISK to receive data'
  371.     db    cr,lf,'ESCAPE character during CONNECT'
  372.     db    cr,lf,'FILE-MODE for outgoing files'
  373.     db    cr,lf,'IBM mode: parity and turn around handling'
  374.     db    cr,lf,'LOCAL-ECHO (half-duplex)'
  375.     db    cr,lf,'LOGGING of terminal sessions'    ;[pcc013]
  376.     db    cr,lf,'PARITY for communication line'
  377.     db    cr,lf,'PORT to communicate on'
  378.     db    cr,lf,'PRINTER copy control'
  379. ;*    db    cr,lf,'RECEIVE parameters'    ;Not currently implemented
  380. ;*    db    cr,lf,'SEND parameters'        ;Ditto
  381.     db    cr,lf,'TAC interface support'
  382.     db    cr,lf,'TIMER control'
  383.     db    cr,lf,'VT52-EMULATION'
  384.     db    cr,lf,'WARNING for filename conflicts'
  385.     db    '$'
  386.  
  387. ;
  388. ;SET BLOCK-CHECK-TYPE command.
  389.  
  390. blkset:    lxi    d,blktab    ;Get the address of the block-check table
  391.     lxi    h,blkhlp    ;And the address of the help text
  392.     call    chkkey        ;Go check input (val returns in A).
  393.     sta    chktyp        ;Save desired checksum type
  394.     jmp    kermit        ;Go get another command
  395.  
  396. blktab:    db    3        ;Three entries.
  397.     db    20, '1-CHARACTER-CHECKSUM$',    '1','1'
  398.     db    20, '2-CHARACTER-CHECKSUM$',    '2','2'
  399.     db    21, '3-CHARACTER-CRC-CCITT$',    '3','3'
  400.  
  401. blkhlp:    db    cr,lf,'1-CHARACTER-CHECKSUM'
  402.     db    cr,lf,'2-CHARACTER-CHECKSUM'
  403.     db    cr,lf,'3-CHARACTER-CRC-CCITT$'
  404.  
  405. ;SET DEFAULT DISK command
  406.  
  407. setdisk:lxi    d,fcb
  408.     mvi    a,cmifin    ;get "file-spec" silently
  409.     call    comnd
  410.      jmp    setdi1
  411. setdi1:    lda    fcb
  412.     ora    a        ;Was a drive specified? (if zero, no)
  413.     jnz    setdi2        ;he typed a drive-spec
  414.     lda    curdsk        ;he didn't - give him default
  415. setdi2:    sta    curdsk
  416.     mvi    c,inbdos    ;reset disks
  417.     call    bdos
  418.     lda    curdsk
  419.     dcr    a        ;LOGDSK is relative 0
  420.     mov     e,a
  421.     mvi    c,logdsk
  422.     call    bdos        ;and "LOG" it
  423.     jmp    kermit        ;all done
  424. ;
  425. ;SET SEND command. (not supported yet)
  426.  
  427. setsnd:    lxi    d,stsntb    ;Parse a keyword from the set send table.
  428.     lxi    h,stshlp
  429.     call    keycmd
  430.     xchg            ; Get dispatch address into HL
  431.     pchl            ; Go for it.
  432.  
  433. stsntb:    db    2        ;Two entries.
  434.     db    8, 'PAD-CHAR$'
  435.         dw stpdch
  436.     db    7, 'PADDING$'
  437.         dw stpad
  438.  
  439. stshlp:    db    cr,lf,'PAD-CHAR'
  440.     db    cr,lf,'PADDING$'
  441.  
  442. ; SET SEND PADDING command. does nothing.
  443. stpad:    call    cfmcmd
  444.     jmp    kermit
  445.  
  446. ; SET SEND PAD-CHAR command. does nothing.
  447. stpdch:    call    cfmcmd
  448.     jmp    kermit
  449.  
  450. ;[pcc013]
  451. ;    This is the SET LOGGING ON/OFF subcommand
  452.  
  453. setlog:    call    onoff        ;[pcc013] Get on/off
  454.     sta    logflg        ;[pcc013] Store flag
  455.     jmp    kermit
  456. ;
  457. ;    This is the SET ESCAPE character subcommand.
  458.  
  459. escape:    call    cfmcmd
  460.     lxi    d,escmes    ;Get the address of the escape message.
  461.     call    prtstr
  462.     mvi    c,conin        ;Get the char.
  463.     call    bdos
  464.     sta    escchr        ;Store the new escape character.
  465.     jmp    kermit
  466.  
  467. ;    This is the SET LOCAL-ECHO subcommand.
  468.  
  469. locall:    call    onoff        ;Get on/off setting [Toad Hall]
  470.     sta    ecoflg        ;Store local echo flag.
  471.     jmp    kermit
  472.  
  473. ;    This is the SET PRINTER ON/OFF subcommand
  474.  
  475. setprn:    call    onoff        ;Get on/off setting [Toad Hall]
  476.     sta    prnflg        ;Store printer flag
  477.     jmp    kermit
  478.  
  479. ;    This is the SET DEBUG ON/OFF subcommand
  480.  
  481. setdbg:    call    onoff        ;Get on/off setting [Toad Hall]
  482.     sta    dbgflg        ;Store debug flag
  483.     jmp    kermit
  484.  
  485. ;[jd] this is the SET TIMER subcommand
  486.  
  487. settim:    call    onoff        ;Get on/off setting [Toad Hall]
  488.     sta    timflg        ;Store timer flag value
  489.     jmp    kermit
  490.  
  491. ;This is the SET FILE-WARNING subcommand
  492.  
  493. filwar:    call    onoff        ;Get on/off setting [Toad Hall]
  494.     sta    flwflg        ;Store file-warning flag.
  495.     jmp    kermit
  496.  
  497. ;    This is the SET IBM command.
  498.  
  499. ibmset:    call    onoff        ;Get on/off setting [Toad Hall]
  500.     sta    ibmflg        ;Store IBM flag.
  501.     ora    a        ;Is it turned on?
  502.     jz    ibmst1        ;If not, set parity to the default.
  503.     mvi    a,ibmpar    ;Get the IBM parity.
  504.     mvi    b,1        ;Set local echo on.
  505.     jmp    ibmst2
  506. ibmst1:    mvi    a,defpar
  507.     mvi    b,0        ;Set local echo off.
  508. ibmst2:    sta    parity        ;Save them.
  509.     mov    a,b
  510.     sta    ecoflg
  511.     sta    timflg        ;[jd] timer is same as local echo
  512.     jmp    kermit
  513.  
  514. ;
  515. ;    SET FILE-MODE command.
  516.  
  517. setcpm:    lxi    d,typtab
  518.     lxi    h,typhlp
  519.     call    chkkey        ;Get and confirm keyword, or die trying
  520.     sta    cpmflg        ;Set the CPM flag.
  521.     jmp    kermit
  522.  
  523. typtab:    db    3        ;Three entries
  524.     db    5, 'ASCII$',    01H,01H
  525.     db    6, 'BINARY$',    02H,02H
  526.     db    7, 'DEFAULT$',    00H,00H
  527.  
  528. typhlp: db    cr,lf,'ASCII    BINARY    DEFAULT$'
  529.  
  530. ;    This is the SET PARITY subcommand.
  531.  
  532. parset:    lxi    d,partab
  533.     lxi    h,parhlp
  534.     call    chkkey        ;Get and confirm keyword, or die trying
  535.     sta    parity        ;Set the parity flag.
  536.     jmp    kermit
  537.  
  538. partab:    db    5        ;Five entries.
  539.     db    4, 'EVEN$',    parevn,parevn
  540.     db    4, 'MARK$',    parmrk,parmrk
  541.     db    4, 'NONE$',    parnon,parnon
  542.     db    3, 'ODD$',    parodd,parodd
  543.     db    5, 'SPACE$',    parspc,parspc
  544.  
  545. parhlp:    db    cr,lf,'EVEN    MARK    NONE    ODD    SPACE$'
  546.  
  547. ;    This is the SET TACTRAP subcommand.
  548. ;    options are ON, OFF, or CHARACTER.  (for CHARACTER, we request the
  549. ;    new TAC Intercept character, and turn the TACtrap on)
  550.  
  551. settac:    lxi    d,tactab
  552.     lxi    h,tachlp
  553.     call    chkkey        ;Get and confirm keyword
  554.     ora    a        ;Was it "OFF" (zero)?
  555.     jz    settc2        ;If so, go disable TACtrap.
  556.     cpi    1        ;Was it "ON"?
  557.     jz    settc1        ;If so, go enable TACtrap.
  558.     lxi    d,tacmes    ;"CHARACTER". request new TAC Intercept char.
  559.     call    prtstr
  560.     mvi    c,conin        ;Get the char.
  561.     call    bdos
  562.     sta    tacchr        ;Store the new TAC Intercept character.
  563. settc1:    lda    tacchr        ;Copy tacchr to tacflg to enable TACtrap.
  564. settc2:    sta    tacflg        ;Enable/disable TACtrap
  565.     jmp    kermit
  566.  
  567. tactab:    db    3        ;Three entries.
  568.     db    9,    'CHARACTER$',    02H,02H
  569.     db    3,    'OFF$',        00H,00H
  570.     db    2,    'ON$',        01H,01H
  571.  
  572. tachlp:    db    cr,lf,'ON to enable TAC trap'
  573.     db    cr,lf,'OFF to disable TAC trap'
  574.     db    cr,lf,'CHARACTER to enable TAC trap and'
  575.     db    ' specify intercept character$'
  576.  
  577. ;    This is the SET VT52-EMULATION subcommand.
  578.  
  579. vt52em:    lda    vtflg        ;get the flag value
  580.     cpi    0ffH        ;0ffH means not allowed -
  581.     jz    notimp        ; say it's not implemented.
  582.     call    onoff        ;Get keyword (ON or OFF)
  583.     sta    vtflg        ;Set the VT52 emulation flag.
  584.     jmp    kermit
  585. ;
  586. ;    Note:  For the SET BAUD and SET PORT commands, which might not be
  587. ;    supported for the current system, the command tables are stored in
  588. ;    the overlay.  We locate them through pointers in the linkage area:
  589. ;    spdtab for SET BAUD, prttab for SET PORT.  The contents of spdtab
  590. ;    (or prttab) is the address of the beginning of the table (the table
  591. ;    does NOT begin at spdtab).  If the address is zero, the command is
  592. ;    not supported.  If the table address is nonzero, then there is a
  593. ;    corresponding help message pointed to by (NOT starting at) spdhlp
  594. ;    or prthlp.
  595.  
  596. ;    This is the SET BAUD command
  597.  
  598. baud:    lhld    spdtab        ; get pointer to speed table
  599.     mov    a,h
  600.     ora    l        ; test for NULL (zero)
  601.     jz    notimp        ; if so, say it's not implemented
  602.     xchg            ; move speed table address to DE
  603.     lhld    spdhlp        ; get pointer to speed help text
  604.     call    keycmd
  605.     push    d        ; save selected speed
  606.     call    cfmcmd        ; confirm...
  607.     pop    h        ; restore speed to HL
  608.     shld    speed        ; save all 16 bits of speed value
  609.     xchg            ; move speed to DE
  610.     call    sysspd        ; do system-dependent speed setting.
  611.     jmp    kermit        ; return to command level
  612.  
  613. ;    This is the SET PORT command
  614.  
  615. prtset:    lhld    prttab        ; get pointer to port table
  616.     mov    a,h
  617.     ora    l        ; test for NULL
  618.     jz    notimp        ; not supported if pointer was null.
  619.     xchg            ; move port table address to DE
  620.     lhld    prthlp        ; get pointer to port help text
  621.     call    keycmd
  622.     push    d        ; save selected port entry
  623.     call    cfmcmd        ; confirm...
  624.     pop    h        ; restore table address to HL
  625.     shld    port        ;[hh] save all 16 bits of port value
  626.     call    sysprt        ; go do port stuff
  627.     jmp    kermit
  628. ;
  629. ;    Subroutines for SET subcommands
  630.  
  631. ;    ontab - command table for onoff.
  632. ;    onhlp - help text for onoff.
  633. ;    onoff - accept "ON" or "OFF" keyword.
  634. ;    returns:
  635. ;        success: value in A (non-zero = ON)
  636. ;        error: no return to caller. print error message and return to
  637. ;        main loop.
  638. ontab:    db    2        ;Two entries.
  639.     db    3, 'OFF$',    00H,00H
  640.     db    2, 'ON$',    01H,01H
  641.  
  642. onhlp:    db    cr,lf,'OFF    ON$'
  643.  
  644. onoff:    lxi    d,ontab
  645.     lxi    h,onhlp
  646.     ;Fall through to check input.  [Toad Hall]
  647.  
  648. ;    chkkey - parse and confirm keyword.
  649. ;    called with:
  650. ;        DE/ address of keyword table
  651. ;        HL/ address of help text
  652. ;    returns:
  653. ;        success: low byte of keyword value (from table) in A.
  654. ;        error: no return to caller.  print error message and return to
  655. ;        main loop.  (Since the main loop reloads the stack pointer,
  656. ;        we don't have to attempt to clean up the stack here)
  657.  
  658. chkkey:    call    keycmd        ; Parse a keyword (might not return)
  659.     sta    temp1        ; Save the parsed value
  660.     call    cfmcmd        ; Request confirmation (might not return)
  661.     lda    temp1        ; Get saved value
  662.     ret            ; Return
  663.  
  664. ;[hh]     fndkyw - find a keyword string from a table using 
  665. ;         it's associated value
  666. ;    called with:
  667. ;        HL/ address of keyword table
  668. ;         A/ value associated with keyword string
  669. ;    returns:
  670. ;        success: HL points to first byte of keyword string
  671. ;             CY flag is cleared
  672. ;        error:   HL points to error string (?Not found)
  673. ;             CY flag is set
  674.  
  675. fndkyw:    mov    d,m        ;get count of entries
  676.     inx    h        ;advance over count value
  677. fndkw1:    mov    b,m        ;get string length
  678.     inr    b        ;account for $
  679.     inx    h        ;advance over length value
  680.     shld    temp1        ;save string pointer
  681. fndkw2:    inx    h        ;loop over string
  682.     dcr    b
  683.     jnz    fndkw2
  684.     mov    c,m        ;get keyword value from table
  685.     cmp    c        ;do they match?
  686.     jz    fndkw3        ;Yup
  687.     inx    h        ;bump to next keyword
  688.     inx    h        ;
  689.     dcr    d        ;decrement entry count
  690.     jnz    fndkw1        ;check the remaining keywords
  691.     lxi    h,kywdnf    ;point to not found message
  692.     stc            ;give calling routine a not found flag
  693.     ret
  694. fndkw3:    ora    a        ;clear CY to tell caller we succeeded
  695.     lhld    temp1        ;restore the saved string pointer
  696.     ret
  697.  
  698. kywdnf:    db    cr,lf,'?Not found$'    ;not found message
  699.  
  700. ;
  701. ;    This is the SHOW command.
  702.  
  703. show:    call    cfmcmd
  704. ;* Reconcile this and status.
  705.     call    clrtop        ;[hh] Clear screen first
  706.     call    stat01        ;For now just cop out.
  707.     jmp    kermit
  708.  
  709. ;    This is the STATUS command.
  710.  
  711. status:    call    cfmcmd
  712.     call    clrtop        ;[hh] Clear screen first
  713.     call    stat01
  714.     jmp    kermit
  715.  
  716. ;    processor for SHOW, STATUS and <escape>S commands
  717. ;    called by: show, status, intchr
  718.  
  719. stat01:    lda    fileio        ;Are we in transmit?
  720.     ora    a
  721.     jz    sta01b        ;No
  722.     lxi    d,xmtst        ;Yes,say so
  723.     call    prtstr
  724. sta01b:    call    staeco        ; Tell about local echo flag
  725.     lda    vtflg        ; Get the VT52 emulation flag
  726.     cpi    0ffH        ; Supported for this terminal?
  727.     cnz    stavt        ; If so, tell whether it's on or off.
  728.     call    stafil        ; Tell about file type
  729.     call    staibm        ; Tell about IBM flag
  730.     call    stawrn        ; Tell about file-warning flag
  731.     call    stalpt        ; Tell about printer copy flag
  732.     call    stalog        ; [pcc003] Tell about log file status
  733.     call    stapar        ; Tell about parity
  734.     lhld    prttab        ;[hh] Got a port table? (is pointer nonzero?)
  735.     mov    a,h        ;[hh]
  736.     ora    l        ;[hh]
  737.     cnz    stapor        ;[hh] If so, tell which port we're using
  738.     lhld    spdtab        ; Got a speed table? (is pointer nonzero?)
  739.     mov    a,h
  740.     ora    l
  741.     cnz    staspd        ; If so, tell what speed we're running.
  742.     call    stabcc        ; Tell current block check type
  743.     call    staesc        ; Tell current escape character
  744.     call    statim        ; Tell about timer flag
  745.     call    statac        ; Tell about TAC flag/intercept character.
  746.     ret
  747.  
  748. ;    Show the value of the LOCAL-ECHO flag (On or Off).
  749.  
  750. staeco:    lxi    d,locst        ;Get the address of the local echo string.
  751.     call    prtstr
  752.     lda    ecoflg        ;Get the local echo flag.
  753.     jmp    staton        ;Say ON or OFF, and return
  754.  
  755. ;    Show the value of the VT52-EMULATION flag (On, Off, or Not Supported).
  756.  
  757. stavt:    lxi    d,vtemst    ; Get the address of the VT52 emulation string.
  758.     call    prtstr
  759.     lda    vtflg        ; Get the VT52 emulation flag.
  760.     cpi    0ffH        ; Is it supported?
  761.     jnz    staton        ; If so, say ON or OFF, and return
  762.     jmp    notimp        ; Not supported.  print appropriate message.
  763.  
  764. ;    Show the value of the FILE-MODE flag (ASCII, Binary, or Default).
  765.  
  766. stafil:    lxi    d,cpmst        ; Get the address of the file mode message.
  767.     call    prtstr
  768.     lda    cpmflg        ; Get the file mode flag.
  769.     lxi    d,defstr    ; Assume Default (0).
  770.     ora    a        ; Is it?
  771.     jz    prtstr        ; If so, say so, and return.
  772.     lxi    d,ascstr    ; Not default, assume ASCII
  773.     cpi    1        ; Is it ASCII?
  774.     jz    prtstr        ; Say ASCII, and return
  775.     lxi    d,binstr    ; Not default or ASCII, must be binary
  776.     jmp    prtstr        ; Print type, and return.
  777.  
  778. ;    Show the value of the IBM-MODE flag (On or Off).
  779.  
  780. staibm:    lxi    d,ibmst        ;IBM string.
  781.     call    prtstr
  782.     lda    ibmflg        ; Get IBM flag.
  783.     jmp    staton        ; Print its value and return
  784.  
  785. ;    Show the value of the FILE-WARNING flag (On or Off).
  786.  
  787. stawrn:    lxi    d,filst        ; File warning string.
  788.     call    prtstr
  789.     lda    flwflg        ; File warning flag.
  790.     jmp    staton        ; Say ON or OFF
  791.  
  792. ;    Show the value of the PRINTER flag (On or Off).
  793.  
  794. stalpt:    lxi    d,prst        ;Printer copy string
  795.     call    prtstr
  796.     lda    prnflg        ;Printer ON/OFF flag
  797.     jmp    staton        ; Say ON or OFF
  798.  
  799. ;    Show status of log file
  800. stalog:    lxi    d,logst        ;[pcc003] Logging
  801.     call    prtstr        ;[pcc003]
  802.     lda    logflg        ;[pcc003] get the flag
  803.     ani    7FH        ;[pcc003] ignore open flag
  804.     cpi    2        ;[pcc003] is it suspended?
  805.     jnz    staton        ;[pcc003] no, must be on or off
  806.     lxi    d,susstr    ;[pcc003] suspended
  807.     jp    prtstr        ;[pcc003] print and return
  808.  
  809. ;    Show the value of the PARITY flag (Odd, Even, Mark, Space, or None).
  810.  
  811. stapar:    lxi    d,parst        ;Parity string.
  812.     call    prtstr
  813.     lda    parity        ;Get the parity setting.
  814.     lxi    d,pnonst    ;Assume parity is NONE
  815.     cpi    parnon        ;Were we right?
  816.     jz    prtstr        ;Yep, go say None, and return
  817.     lxi    d,pmrkst    ;Get ready to say Mark
  818.     cpi    parmrk        ;Is it mark?
  819.     jz    prtstr        ;Yep, go say Mark, and return
  820.     lxi    d,pspcst    ;Get ready to say Space
  821.     cpi    parspc        ;Is it space?
  822.     jz    prtstr        ;Yep, go say Space, and return
  823.     lxi    d,poddst    ;Get ready to say Odd
  824.     cpi    parodd        ;Is it odd?
  825.     jz    prtstr        ;Yep, go say Odd, and return
  826.     lxi    d,pevnst    ;Must be Even.
  827.     jmp    prtstr        ;Say Even, and return.
  828.  
  829. ;[hh]    Show the current port (if known).
  830.  
  831. stapor:    lxi    d,porst        ;[hh]
  832.     call    prtstr        ;[hh]
  833.     lda    port        ;[hh] Get current port value
  834.     lxi    h,spdust    ;[hh] Assume undefined (this error msg is fine)
  835.     cpi    0FFH        ;[hh] Is it?
  836.     jz    stat73        ;[hh] Yup. Say so
  837.     lhld    prttab        ;[hh] Address of port keyword table
  838.     call    fndkyw        ;[hh] Look for correct keyword string
  839.     jnc    stpr1        ;[hh] Found a match
  840.     lxi    h,spdust    ;[hh] No match found - say it's undefined
  841. stpr1:    jmp    stat73        ;[hh] Print it and return
  842.  
  843. ;    Show the current line speed (if known).
  844.  
  845. staspd:    lxi    d,spdst
  846.     call    prtstr
  847.     lda    speed        ;Get current speed.
  848.     lxi    h,spdust    ;Assume undefined.
  849.     cpi    0FFH        ;Is it?
  850.     jz    stat73        ;Yes.
  851.     lhld    spdtab        ;Start scanning keyword table.
  852.     mov    d,m        ; get count of entries
  853.     inx    h        ; advance over it.
  854. stat70:    mov    b,m        ;Get string length.
  855.     inr    b        ;Account for $.
  856.     inx    h
  857.     shld    temp1        ;Save string pointer.
  858. stat71:    inx    h        ;Loop over string.
  859.     dcr    b
  860.     jnz    stat71
  861.     mov    c,m        ;Get speed value
  862.     cmp    c        ;Match?
  863.     jz    stat72        ;Yes.
  864.     inx    h        ;Bump to next keyword.
  865.     inx    h
  866.     dcr    d        ; decrement entry count
  867.     jnz    stat70        ; if more left, check them.
  868.     lxi    h,spdust    ; can't find it. say it's undefined.
  869.     jmp    stat73        ; print the message.
  870.  
  871. stat72:    lhld    temp1        ;Restore saved string pointer.
  872. stat73:    xchg            ;Set into DE for display.
  873.     jmp    prtstr        ; print it, and return.
  874.  
  875. ;    Show the current BLOCK-CHECK-TYPE (1-, 2-, or 3-character).
  876.  
  877. stabcc:    lxi    d,bckst        ;Get the string
  878.     call    prtstr        ;Print "Block check type: "
  879.     lda    chktyp        ;Get the type (character 1, 2, or 3)
  880.     mov    e,a        ;Put into E
  881.     mvi    c,conout    ;Want to print it
  882.     call    BDOS        ;Do so
  883.     lxi    d,bckst1    ;Get rest of text ("-character")
  884.     jmp    prtstr        ;Print it and return
  885.  
  886. ;    Print the current escape character
  887.  
  888. staesc:    lxi    d,escst        ;Escape string.
  889.     call    prtstr
  890.     call    escpr        ;Print the escape char.
  891.     jmp    prcrlf        ;Print CR/LF and return  [Toad Hall]
  892.  
  893. ;    Show the value of the TIMER flag
  894. statim:    lxi    d,timmsg    ;[jd] 
  895.     call    prtstr        ;[jd] 
  896.     lda    timflg
  897.     jmp    staton        ;Tell whether it's on or off.
  898.  
  899. ;    Show internal versions (edit strings)
  900. shover:    call    cfmcmd
  901.     call    prcrlf
  902.     lxi    h,vertab    ; Get address of version list
  903. shovr1:    mov    e,m        ; Get next word from list
  904.     inx    h
  905.     mov    d,m        ; Next version string is in DE
  906.     inx    h
  907.     mov    a,d        ; Test for zero (end of list)
  908.     ora    e
  909.     jz    shovr2        ; Done with list if zero
  910.     push    h        ; Save position in list
  911.     call    prtstr        ; Not zero.  Print it.
  912.     call    prcrlf        ; Follow with crlf
  913.     pop    h        ; Restore position in list
  914.     jmp    shovr1        ;  and go see if there are any more.
  915.  
  916. shovr2:    lhld    ovlver        ; Get overlay version string
  917.     xchg            ;  into DE
  918.     call    prtstr        ; Print it
  919.     call    prcrlf        ; Output crlf
  920.     jmp    kermit        ; Return to main loop.
  921.  
  922. ; table of pointers to version strings.
  923. vertab:    dw    mitver        ; CP4MIT
  924.     dw    pktver        ; CP4PKT
  925.     dw    ttver        ; CP4TT
  926.     dw    cpmver        ; CP4CPM
  927.     dw    wldver        ; CP4WLD
  928.     dw    cmdver        ; CP4CMD
  929.     dw    utlver        ; CP4UTL
  930.     dw    0        ; end of list
  931.  
  932. ;    Show TACTrap status (On or Off, and intercept character)
  933. statac:    lxi    d,tacst        ;"Current TACTrap status/char: "
  934.     call    prtstr
  935.     lxi    d,offstr    ;Assume set off
  936.     lda    tacflg        ;Get the TACTrap char/flag
  937.     ora    a        ;Is it off?
  938.     jz    prtstr        ;Yep, go print OFF...
  939.     mvi    c,conout    ;Display...
  940.     mov    e,a        ;...the current intercept char
  941.     call    bdos
  942.     jmp    prcrlf
  943.  
  944. ;    Display current state of a boolean flag.
  945. ;    called with A/ value (zero = Off, non-zero = On)
  946.  
  947. staton:    lxi    d,onstr        ; Assume it's on.
  948.     ora    a        ; Is it on?
  949.     jnz    prtstr        ; If so, say so, then return.
  950.     lxi    d,offstr    ; No, say off.
  951.     jmp    prtstr        ; Print the string, then return.
  952.  
  953. ;    Print "(not implemented)".
  954. ;    here from vt52em, baud, prtset, stavt
  955.  
  956. notimp:    lxi    d,inms12    ; Say it's not implemented.
  957.     call    prtstr
  958.     jmp    kermit        ; Return to main loop.
  959.  
  960. IF lasm                ; If using LASM, chain to the next file.
  961.     LINK    CP4PKT
  962. ENDIF;lasm
  963.