home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / cpm80 / cpxpro.asm < prev    next >
Assembly Source File  |  2020-01-01  |  15KB  |  562 lines

  1. IF NOT lasm
  2. .printx * CPXPRO.ASM *
  3. ENDIF    ;NOT lasm
  4. ;       KERMIT - (Celtic for "FREE")
  5. ;
  6. ;       This is the CP/M-80 implementation of the Columbia University
  7. ;       KERMIT file transfer protocol.
  8. ;
  9. ;       Version 4.0
  10. ;
  11. ;       Copyright June 1981,1982,1983,1984,1985
  12. ;       Columbia University
  13. ;
  14. ; Originally written by Bill Catchings of the Columbia University Center for
  15. ; Computing Activities, 612 W. 115th St., New York, NY 10025.
  16. ;
  17. ; Contributions by Frank da Cruz, Daphne Tzoar, Bernie Eiben,
  18. ; Bruce Tanner, Nick Bush, Greg Small, Kimmo Laaksonen, Jeff Damens, and many
  19. ; others.
  20. ;
  21. ; revision history:
  22. ;
  23. ;edit 2, 16-Oct-1990 by MF.  Reformatted speed tables according to
  24. ;    current usage and reworked sysspd routine accordingly.
  25. ;    Also eliminated cursor-positioning routines as we now link to
  26. ;    cpxvdu.asm.  Reworked version message according to current usage.
  27. ;edit 1, 17 November, 1987, by OBSchou.  Extracted Compupro code
  28. ;    from CPMPRO.ASM    and massaged fort CP/M kermit V4.09
  29. ;
  30. ; Modifications to KERMIT-80 for use with Compupro Interfacer 3/4 "[gv]"
  31. ;
  32. ; Guy Valiquette, M.D.
  33. ; Black Bldg. Rm 322
  34. ; Dept. of Neurology
  35. ; College of Physicians & Surgeons
  36. ; Columbia University
  37. ; 630 W. 168th Street
  38. ; New York, NY 10032
  39. ; (212) 694-3965
  40. ;
  41. ; I/O routines for Interfacer 3/4 board
  42. ; Allow sending break with <ESC> B while CONNECTed
  43. ; Terminal control sequences for Wyse Technology WY-100
  44. ; Add calls to "hangup" subroutine in EXIT and BYE to hang-up phone if
  45. ;    using a smart modem by disabling UART (and withdrawing DTR signal)
  46. ;
  47. ;
  48. ; Using KERMIT with Compupro Interfacer 3/4:
  49. ;    - Set compro below to TRUE, all other to FALSE
  50. ;    - Select the ABSOLUTE USER number you want with the user EQUate
  51. ;    - Select the terminal control string set needed (or write your
  52. ;      own if not there)
  53. ;    - Note that I had to use a kludge to get the signon message right.
  54. ;      Code in KERMIT as I found it did not, nor could it, work.  Search
  55. ;      for the section of code under:  IF compro AND wy100  and imitate.
  56. ;    - If you have a smart modem, CONNECT puts you in contact with your
  57. ;      modem.  Use your usual "wake-up" character sequence to dial out.
  58. ;      You can CONNECT and return to KERMIT repeateadly without hanging up
  59. ;      UNLESS you change the baud rate, execute the BYE command or EXIT.
  60. ;    - Baud rate set up in code to use 1200 baud as default. Can easily
  61. ;      be changed to 300 (or whatever). The byte defined at label "baudrt"
  62. ;      is the mode register 2 used to initialize the UART on first CONNECT.
  63. ;      The low order nibble of this byte is the baud rate.  Refer to the
  64. ;      Compupro manual to set whatever default baud rate desired by changing
  65. ;      this low nibble at  baudrt db 0011$xxxxb.
  66. ;
  67. ; Note: "Wrapup" work (outlined below) to clean up code not done since
  68. ;    new version of KERMIT is due out in a few weeks (says fdc)
  69. ; WRAPUP:
  70. ;    - outchri modification done for IF inout ONLY
  71. ;    - stchr routine implemented for IF inout ONLY
  72. ;      and used by outchr only
  73. ;
  74. ;
  75. ; Keep module name, edit number, and last revision date in memory.
  76. family: db      'CPXPRO.ASM (2)  16-Oct-1990 $'
  77. ;
  78. ; Assembly time message to let me know I'm building the right version.
  79. ; LASM generates an 'S' error along with the message, which is messy, but
  80. ; better than trying to put everything inside a IF m80 OR mac80 conditional,
  81. ; because LASM doesn't like nested IF's, either.
  82.  
  83. IF compro
  84. .printx * Assembling Kermit-80 for Compupro Interfacer 4 (or 3) *
  85. ENDIF
  86.  
  87. iobyte  EQU     03H     ;Location of I/O byte
  88.  
  89. IF compro
  90. if4    EQU    10H        ;standard base address of Interfacer 4/3 board
  91. datap    EQU    if4+0        ;data port (read/write)
  92. stat    EQU    if4+1        ;status port (read/write)
  93. mode    EQU    if4+2        ;mode registers (read/write)
  94. command    EQU    if4+3        ;command register (read/write)
  95. txint    EQU    if4+4        ;transmit interrupts status/mask (read/write)
  96. rxint    EQU    if4+5        ;receive interrupts status/mask (read/write)
  97. ;        if4+6         not used
  98. usersel    EQU    if4+7        ;absolute user number select register
  99. output    EQU    1
  100. input    EQU    2
  101. ; Note: tested with CP/M Ver2.2, and Racal-Vadic Auto Dial VA212 modem
  102. ;    and USRobotics Password modems. [gv]
  103. user    EQU    7        ;ABSOLUTE user number on IF4 or IF3
  104. ; Also remember to select a terminal!!!
  105. ENDIF;compro
  106. ;
  107.  
  108. sysxin:    ;system initialisation not covered by sysinit
  109.         ret                     ; return from system-dependent routine
  110.  
  111. ;
  112. ;
  113. ;       system-dependent termination processing
  114. ;       If we've changed anything, this is our last chance to put it back.
  115. sysexit:
  116.         ret
  117.  
  118. ;
  119. ;       system-dependent processing for start of CONNECT command
  120. ;
  121. syscon:
  122.         ret
  123.  
  124. ;
  125. ;
  126. ;       syscls - system-dependent close routine
  127. ;       called when exiting transparent session.
  128. ;
  129. syscls:
  130.         ret
  131. ;
  132. ;
  133. ;       sysinh - help for system-dependent special functions.
  134. ;       called in response to <escape>?, after listing all the
  135. ;       system-independent escape sequences.
  136. ;
  137. sysinh:    
  138.     lxi    d,inhlps    ; we got options...
  139.     call    prtstr        ; print them.
  140.         ret
  141. inhlps:
  142.  
  143.     db    cr,lf,'D - drop the line'
  144.     db    cr,lf,'B - send a break'
  145.     db    cr,lf
  146.         db      '$'                     ;[hh] table terminator
  147.  
  148. ;
  149. ;       sysint - system dependent special functions
  150. ;       called when transparent escape character has been typed;
  151. ;       the second character of the sequence is in A (and in B).
  152. ;       returns:
  153. ;       non-skip: sequence has been processed
  154. ;       skip:   sequence was not recognized
  155. sysint:
  156.     ani     137O            ; convert lower case to upper, for testing...
  157.  
  158.     cpi    'D'        ;Disconnect modem?
  159.     jnz    intc00        ;no
  160. hangup:    xra    a        ;get a null byte
  161.     out    command        ;disable UART
  162.     sta    ckdialf        ;pull down flag to reinitialize UART
  163.     ret            ;most smart modems will hang up on loosing DTR
  164. intc00:
  165.     cpi    'B'        ; Send a reak?
  166.     jz    sendbr
  167.         ret
  168.  
  169.  
  170. ;send a break
  171. sendbr:    mvi    a,user        ;select our UART
  172.     di            ;quiet
  173.     out    usersel        ;select it
  174.     in    command        ;get current command byte
  175.     ori    00001000b    ;set "send break" bit
  176.     out    command        ;send to UART
  177.     ei
  178.  
  179.         ;now for 300 msec timing loop (at 4 MHz, 0 wait state)
  180.     mvi    a,30        ;[obs] call delay for 300 ms
  181.     call    delay
  182.  
  183.     mvi    a,user        ;now, go back to UART
  184.     di            ;quiet
  185.     out     usersel
  186.     in    command        ;get current command
  187.     ani    11110111b    ;reset "send break" bit
  188.     ori    00010000b    ;and set "reset errors" command bit (in case)
  189.     out    command        ;send back to UART
  190.     ei
  191.     jmp    rskp
  192.  
  193.  
  194. ckdial:
  195.     lda    ckdialf        ;check flag that forces reinitialization
  196.     ora    a        ;test it
  197.     jz    ckdial0        ;must redo it
  198.     mvi    a,user        ;user number
  199.     di
  200.     out    usersel        ;select it
  201.     in    command        ;get current command register
  202.     ei
  203.     ani    00000111b    ;mask for normal operating mode
  204.                 ;(DTR on, RX and TX both enabled)
  205.     cpi    00000111b    ;is it?
  206.     jz    rskp        ;UART is on, start terminal emulation
  207. ; else initialize UART...
  208. ckdial0:di
  209.     mvi    a,user        ;select user
  210.     out    usersel
  211.     mvi    a,0001$0000b    ;reset errors command
  212.     out    command        ;send to command register
  213.     out    command
  214.     out    command        ;...make sure it got it
  215.     in    command        ;confirm
  216.     lda    moderg1        ;get mode register 1
  217.     out    mode        ;send it
  218.     lda    moderg2        ;get mode register 2
  219.     out    mode        ;send it
  220.     mvi    a,0011$0111b    ;command register to start things
  221.     out    command        ;send it
  222.     ei            ;turn interrupts back on
  223.     mvi    a,0ffh        ;get a non-zero byte
  224.     sta    ckdialf        ;pull down flag
  225. ;
  226.     jmp    rskp        ;start terminal emulation
  227.  
  228.  
  229. ;    sysflt - system-dependent filter.
  230. ;    called with the character in E.
  231. ;       preserves bc, de, hl.
  232. ;       note: <xon>,<xoff>,<del>, and <nul> are always discarded.
  233. sysflt:
  234.         mov     a,e             ; get character for testing
  235.         ret
  236.  
  237. ;       mdmflt - modem filter [30]
  238. ;       called with character to be sent to printer in E
  239. ;       with parity set as appropriate.
  240. ;       return with accumulator = 0 do do nothing,
  241. ;                               <> 0 to send char in E.
  242. mdmflt:
  243.         mov     a,e             ;[30] get character to test
  244.         ret
  245.  
  246.  
  247. ;       prtflt - printer filter [30]
  248. ;       called with character to be sent to printer in E
  249. ;       returns with a = 0 to do nothing
  250. ;                    a <> 0 to print it.
  251. ;
  252. ;       this routine for those printer that automatically insert
  253. ;       a lf on cr, or cr for lf.  Should this be shifted to 
  254. ;       the system indep. stuff, in say 4.06?
  255. prtflt:
  256.         mov     a,e             ; [30] get character to test
  257.         ret
  258.  
  259.  
  260. ;
  261. ;
  262. ; system-dependent processing for BYE command.
  263. ;  for apmmdm, heath, and lobo, hang up the phone.
  264. sysbye:
  265.  
  266.     call    hangup
  267.         ret
  268. ;
  269. ;       This is the system-dependent command to change the baud rate.
  270. ;       DE contains the two-byte value from the baud rate table; this
  271. ;       value is also stored in 'speed'.
  272. sysspd:
  273.  
  274.  
  275. IF compro
  276.     lda    speed        ;[MF]Get requested baud-rate
  277.         mov     b,a             ;Save the number.
  278.     lxi    h,baudrt    ;point to current baud rate
  279.     mov    a,m        ;get it
  280.     ani    0f0h        ;keep high nibble
  281.     ora    b        ;merge back baud rate
  282.     mov    m,a        ;store back
  283.     xra    a        ;clear A
  284.     sta    ckdialf        ;put up flag to force reinitialization
  285.     ret            ;...at next connect
  286.  
  287. ENDIF;compro
  288.  
  289.  
  290. ;
  291.  
  292. ;       Speed tables
  293. ; (Note that speed tables MUST be in alphabetical order for later
  294. ; lookup procedures, and must begin with a value showing the total
  295. ; number of entries.  The speed help tables are just for us poor
  296. ; humans.
  297.  
  298. ;       db      string length,string,divisor (2 identical bytes or 1 word)
  299. ; [Toad Hall]
  300.  
  301. spdtbl:    db    8        ;[MF]8 entries in speed table
  302.     db    3,'110$'
  303.     db    02h,02h        ;[MF]110 baud
  304.     db    4,'1200$'
  305.     db    07h,07h        ;[MF]1200 baud
  306.     db    5,'134.5$'
  307.     db    03h,03h        ;[MF]134.5 baud
  308.     db    3,'150$'
  309.     db    04h,04h        ;[MF]150 baud
  310.     db    4,'1800$'
  311.     db    08h,08h        ;[MF]1800 baud
  312.     db    5,'19200$'
  313.     db    0fh,0fh        ;[MF]19200 baud
  314.     db    4,'2000$'
  315.     db    09h,09h        ;[MF]2000 baud
  316.     db    4,'2400$'
  317.     db    0ah,0ah        ;[MF]2400 baud
  318.     db    3,'300$'
  319.     db    05h,05h        ;[MF]300 baud
  320.     db    4,'3600$'
  321.     db    0bh,0bh        ;[MF]3600 baud
  322.     db    4,'4800$'
  323.     db    0ch,0ch        ;[MF]4800 baud
  324.     db    2,'50$'
  325.     db    00h,00h        ;[MF]50 baud
  326.     db    3,'600$'
  327.     db    06h,06h        ;[MF]600 baud
  328.     db    4,'7200$'
  329.     db    0dh,0dh        ;[MF]7200 baud
  330.     db    2,'75$'
  331.     db    01h,01h        ;[MF]75 baud
  332.     db    4,'9600$'
  333.     db    0eh,0eh        ;[MF]9600 baud
  334.  
  335. sphtbl:    db    cr,lf,'50  75  110  134   150  300  600  1200'
  336.     db    cr,lf,'1800  2000  2400  3600  4800  7200  9600  19200$'
  337.  
  338. ckdialf:db    0            ;force UART initialization on entry
  339. baudrt:    db    0011$0111b    ;default baud rate: 1200 baud
  340. moderg1:db    0100$1110b    ;default mode register 1:
  341.                 ; -asynch, 8 data bits, 1 stop bit,
  342.                 ; -parity odd, disabled
  343. moderg2    EQU    baudrt
  344. ENDIF;compro
  345. ;
  346.  
  347. ;
  348. ; The following conditionals were once a huge if not statement.  There
  349. ; wasn't enough room to add the lobo to the list, so it had to be broken
  350. ; into 2, which you can't do with an if not.  I redid it as two ifs and
  351. ; applied them to those that wouldn't set baud. [Hal Hostetler]
  352. ;       This is the system-dependent SET PORT command.
  353. ;       HL contains the argument from the command table.
  354. sysprt:
  355.         ret
  356. ;
  357. ;
  358. ;    Port table not applicable
  359. prttbl   EQU     0
  360. prhtbl   EQU     0               ;
  361.  
  362. ;
  363. ;
  364. ;       selmdm - select modem port
  365. ;       selcon - select console port
  366. ;       selmdm is called before using inpmdm or outmdm;
  367. ;       selcon is called before using inpcon or outcon.
  368. ;       For iobyt systems, diddle the I/O byte to select console or comm port;
  369. ;       For Decision I, switches Multi I/O board to console or modem serial
  370. ;       port.  [Toad Hall]
  371. ;       For the rest, does nothing.
  372. ;       preserves bc, de, hl.
  373. selmdm:
  374.         ret
  375.  
  376. selcon:
  377.         ret
  378. ;
  379. ;       Get character from console, or return zero.
  380. ;       result is returned in A.  destroys bc, de, hl.
  381. ;
  382. inpcon:
  383.         mvi     c,dconio        ;Direct console I/O BDOS call.
  384.         mvi     e,0FFH          ;Input.
  385.         call    BDOS
  386.         ret
  387. ;
  388. ;
  389. ;       Output character in E to the console.
  390. ;       destroys bc, de, hl
  391. ;
  392. outcon:
  393.         mvi     c,dconio        ;Console output bdos call.
  394.         call    bdos            ;Output the char to the console.
  395.         ret
  396. ;
  397. ;
  398. ;       outmdm - output a char from E to the modem.
  399. ;               the parity bit has been set as necessary.
  400. ;       returns nonskip; bc, de, hl preserved.
  401. outmdm:
  402. ;************************System Dependent****************************
  403. ;
  404. ; Addition by [gv], 16/7/84
  405. ;    Return the status of the modem port:
  406. ;        Z flag set if NO input available
  407. ;        C flag set in NOT output ready
  408. ;    Destroys A and flags, preserves all other registers
  409. ;
  410. stchr:
  411.     di
  412.     mvi    a,user
  413.     out    usersel
  414.     in    stat
  415.     ani    output
  416.     in    stat
  417.     ei
  418.     jz    outmdm        ;not output ready, try again
  419. ; else...
  420.     di            ;no interrupts
  421.     mvi    a,user
  422.     out    usersel
  423.     mov    a,e        ;get back character
  424.     out    datap
  425.     ei
  426.     ret
  427.  
  428. ;
  429.  
  430. ;
  431. ;
  432. ;       get character from modem; return zero if none available.
  433. ;       for IOBYT systems, the modem port has already been selected.
  434. ;       destroys bc, de, hl.
  435. inpmdm:
  436. ;
  437.     di
  438.     mvi    a,user
  439.     out    usersel
  440.     in    stat
  441.     ei
  442.     ani    input        ;test for input status (C flag reset by ANI n)
  443.     rz            ; no input available
  444. ;
  445. ;************************System Dependent****************************
  446. ;
  447. ; Addition by [gv], 16/7/84
  448. ;    get a character "raw" (i.e. just get it in A)
  449. ;
  450. ; Note: MUST have character ready before call, use stchr
  451.     mvi    a,user
  452.     di
  453.     out    usersel
  454.     in    datap
  455.     ei
  456.     ret
  457. ;
  458. ;
  459.  
  460. ;
  461. ;       flsmdm - flush comm line.
  462. ;       Modem is selected.
  463. ;       Currently, just gets characters until none are available.
  464.  
  465. flsmdm: call    inpmdm          ; Try to get a character
  466.         ora     a               ; Got one?
  467.         jnz     flsmdm          ; If so, try for another
  468.         ret                     ; Receiver is drained.  Return.
  469.  
  470.  
  471. ;
  472. ;
  473. ;       lptstat - get the printer status. Return a=0 if ok, or 0ffh if not.
  474. lptstat:
  475.         xra     a               ; assume it is ok.. this may not be necessary
  476.         ret
  477. ;
  478. ;
  479. ;       outlpt - output character in E to printer
  480. ;       console is selected.
  481. ;       preserves de.
  482. outlpt:
  483.         push    d               ; save DE in either case
  484.         call    prtflt          ; go through printer filter [30]
  485.         ana     a               ; if A = 0 do nothing,
  486.         jz      outlp1          ; [30] if a=0 do nothing
  487.         mvi     c,lstout
  488.         call    bdos            ;Char to printer
  489. outlp1: pop     d               ; restore saved register pair
  490.  
  491.  
  492.  
  493. IF inout
  494. prtout:
  495. ENDIF ;inout
  496. IF compro AND inout
  497.     di
  498.     mvi    a,user
  499.     out    usersel
  500.     in    stat
  501.     ei
  502. ENDIF;compro AND inout
  503. IF (NOT compro) AND inout
  504.         in      mnprts          ;Get the output ready flag.
  505. ENDIF;(NOT compro) AND inout
  506. IF inout
  507.         ani     output          ;Is it set?
  508.         jz      prtout          ;If so, loop until it isn't.
  509. ENDIF ;inout
  510. IF compro AND inout
  511.     di
  512.     mvi    a,user
  513.     out    usersel
  514.     mov    a,e
  515.     out    datap
  516.     ei
  517. ENDIF;compro AND inout
  518. IF (NOT compro) AND inout
  519.         mov     a,e             ;Get the char to output.
  520. prtou2: out     mnport          ;Output it.
  521. ENDIF;(NOT compro) AND inout
  522.         ret
  523.  
  524.  
  525. ;
  526.  
  527. ;
  528. ;       Screen manipulation routines
  529. ;
  530. ; delchr - make delete look like a backspace.  Unless delete is a printing
  531. ;       character, we just need to print a backspace. (we'll output clrspc
  532. ;       afterwards)
  533. ;       For Kaypro and Vector General, delete puts a blotch on the screen.
  534. ;       For Apple and Osborne 1, delete moves but doesn't print.
  535. delchr:
  536.     mvi    e,bs
  537.     call    outcon
  538.  
  539. ; erase the character at the current cursor position
  540. clrspc: mvi     e,' '
  541.         call    outcon
  542.         mvi     e,bs            ;get a backspace
  543.         jmp     outcon
  544.  
  545. ; erase the current line
  546. clrlin: lxi     d,eralin
  547.         jmp     prtstr
  548.  
  549. ; erase the whole screen, and go home. preserves b (but not c)
  550. clrtop: lxi     d,erascr
  551.         jmp     prtstr
  552.  
  553.  
  554. IF compro; [gv]
  555. sysver:    db    '[Compupro IF4-',user+'0',']$'
  556. ENDIF;compro
  557.  
  558. IF lasm
  559. LINK    CPXVDU.ASM
  560. ENDIF ;lasm
  561.