home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / a / cpxbbi.asm < prev    next >
Assembly Source File  |  2020-01-01  |  18KB  |  619 lines

  1. IF NOT lasm
  2. .printx * CPXBBI.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.08
  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. ;
  22. ;
  23. ; revision history:
  24. ;
  25. ;edit 4, 7-Jan-1991 by MF. Added code to support the Ampro Little Board.
  26. ;    The code was contributed by Jay S. Rouman; 913 North Drive;
  27. ;    Mt. Pleasant, MI 48858 (voice (517)773-7887).
  28. ; edit 3, 23 July by OBSchou to massage file to suit CPXCOM.ASM
  29. ;
  30. ; edit 2 23 May 1987 by C.J.MILES@UMRCC.
  31. ;    Reorganised file to be similar in structure to that
  32. ;    of the Amstrad sys-dep file. Added hangup in clear
  33. ;    screen options in CONNECT mode.
  34. ;
  35. ; edit 1 10 May 1987 by Chris Miles (C.J.MILES@UMRCC)
  36. ;        Removed Kaypro, Xerox and Big Board from CPXSYS.ASM
  37. ;        and grouped them into this file as CPXBBI.ASM.
  38. ;
  39. ;
  40. ;
  41. ; Original code broken off and modified by:
  42. ;
  43. ; Chris Miles
  44. ; 344, Claremont Road,
  45. ; Rusholme,
  46. ; MANCHESTER,
  47. ; M14 6WB.
  48. ;
  49. ; Tel: (061) 226 7839
  50. ;
  51.  
  52. ;
  53. ;         *** MAIN CODE START ***
  54. ;
  55. ;
  56. ; Keep module name, edit number, and last revision date in memory.
  57.  
  58. sysedt: db      'CPXSYS.ASM (35) 01-Dec-86$'
  59. family: db    'CPXBBI.ASM (4)  7-Jan-1991$'
  60.  
  61.  
  62. ; Assembly time message announcing which version we're building
  63.  
  64. IF kpii
  65. .printx * Assembling Kaypro II KERMIT-80 *
  66. ENDIF
  67.  
  68. IF xer820
  69. .printx * Assembling Xerox 820 KERMIT-80 *
  70. ENDIF
  71.  
  72. IF bbII
  73. .printx * Assembling BigBoard II KERMIT-80 *
  74. ENDIF
  75.  
  76. IF ampro
  77. .printx * Assembling Ampro Little Board KERMIT-80 *
  78. ENDIF
  79.  
  80. z80    EQU    TRUE    ; They all use Z80s
  81.  
  82. IF xer820
  83. defesc  EQU     ']'-100O        ;The default escape character for Xerox
  84. ENDIF;xer820
  85.  
  86. IF kpII
  87. defesc  EQU     '\'-100O        ;The default escape character for Kaypro
  88. ENDIF;kpII
  89.  
  90. ; If one of the above, default to VT52-EMULATION ON.
  91. IF kpII OR xer820
  92. vtval   EQU     1
  93. ENDIF;kpII OR xer820
  94.  
  95.  
  96. ;
  97. ; Specific machine hardware information
  98. ;
  99. IF bbI
  100. mnport  equ     04h             ; Modem data port
  101. mnprts  equ     06h             ; Modem status port
  102. output  equ     04h             ; Transmit buffer empty
  103. input   equ     01h             ; Receive data available
  104. baudrt  equ     00h             ; Baud rate port for channel A
  105. ENDIF;bbI
  106.  
  107.  
  108. IF bbII
  109. mnport  equ     80h             ; Modem data port (SIO channel A)
  110. mnprts  equ     81h             ; Modem status port
  111. output  equ     04h             ; Transmit buffer empty
  112. input   equ     01h             ; Receive data available
  113. baudrt  equ     89h             ; Baud rate port for channel A
  114. ENDIF;bbII
  115.  
  116. IF ampro
  117. mnport  equ     88h             ; Modem data port (SIO channel B)
  118. mnprts  equ     8Ch             ; Modem status port
  119. output  equ     04h             ; Transmit buffer empty
  120. input   equ     01h             ; Receive data available
  121. baudrt  equ     50h             ; Baud rate port for channel B
  122. ENDIF;ampro
  123. ;
  124.  
  125. sysxin:        ;continuation of system initialisation code
  126.         lxi     d,siotbl        ; Load the address of the status able
  127.         mvi     c,siolen        ; Length of status table
  128. siolup:             ; Loop back here for each command byte
  129.         ldax    d               ; Load the first byte into A
  130.         inx     d               ; Index the pointer
  131.         out     mnprts          ; Send it to the status port
  132.         dcr     c               ; Decrement the byte counter
  133.         jnz     siolup          ; Jump back for more commands
  134.         ret                     ; return from system-dependent routine
  135.  
  136. ; List of commands to set up SIO channel A for asynchronous operation.
  137.  
  138. siotbl: DB      18H             ; Channel reset
  139.         DB      18H             ; another, in case register 0 wasn't selected
  140.         DB      04H             ; Select register 4
  141.         DB      44H             ; 1 stop bit, clock*16
  142.         DB      01H             ; Select register 1
  143.         DB      00H             ; No interrupts enabled
  144.         DB      03H             ; Select register 3
  145.         DB      0C1H            ; Rx enable, 8 bit Rx character
  146.         DB      05H             ; Select register 5
  147.         DB      0EAH            ; Tx enable, 8 bit Tx character,
  148.                                 ;  raise DTR and RTS
  149. siolen  equ     $-siotbl        ; length of command list
  150.  
  151.  
  152. ;
  153. ; sysexit - System-dependent termination processing
  154. ;         if we've changed anything, this is our last
  155. ;        chance to put it back.
  156. ;
  157. sysexit:
  158.         ret
  159.  
  160. ;
  161. ; syscon - System-dependent processing for start
  162. ;       of CONNECT command.
  163. ;
  164. syscon:
  165.     lxi    d,conmsg
  166.     call    prtstr
  167.         ret
  168.  
  169. conmsg:         ; Messages printed when entering transparent (CONNECT) mode:
  170.     db    cr,lf,'$'
  171. ;
  172. ; syscls - system-dependent close routine
  173. ;          called when exiting transparent session.
  174. ;
  175. syscls:
  176.         ret
  177. ;
  178. ; sysinh - help for system-dependent special functions.
  179. ;          called in response to <escape>?, after listing
  180. ;          all the system-independent escape sequences.
  181. ;
  182. sysinh:
  183.         lxi     d,inhlps        ; we got options...
  184.         call    prtstr          ; print them.
  185.         ret
  186.  
  187.  
  188. ; additional, system-dependent help for transparent mode
  189. ; (two-character escape sequences)
  190. inhlps:
  191.         db      cr,lf,'B  Transmit a BREAK'
  192.     db    cr,lf,'H  Hangup using DTR'
  193.     db    cr,lf,'W  Wipe screen clear'
  194.     db    '$'
  195.  
  196. ; sysint - system dependent special functions
  197. ;          called when transparent escape character has been typed;
  198. ;          the second character of the sequence is in A (and in B).
  199. ;          returns:-
  200. ;                non-skip: sequence has been processed
  201. ;                skip    : sequence was not recognized
  202. ;
  203. sysint: ani     137O            ; convert lower case to upper, for testing...
  204.         cpi     'B'             ; send break ?
  205.         jz      sendbr          ; then jump to send break routine
  206.     cpi    'H'        ; hang up ?
  207.     jz    hangup        ; then jump to hangup routine
  208.     cpi    'W'        ; clear screen ?
  209.     jz    clrtop        ; then jump to clear screen routine
  210.         jmp     rskp            ; take skip return - command not recognized.
  211.  
  212. ;
  213. ; Hangup and Break routines
  214. ;
  215. hangup:
  216.     mvi    d,0ah        ; set up hangup bit mask
  217.     mvi    e,255        ; time for hangup is 2 1/2 secs
  218.     jmp    setbit        ; skip Tx empty test
  219.  
  220. sendbr:
  221.     mvi    d,9ah        ; set up break bit mask
  222.     mvi    e,30        ; time for break is 300 ms
  223.  
  224. sndbr1: mvi     a,1             ; select Read Register 1
  225.         out     mnprts
  226.         in      mnprts          ; read the contents
  227.         ani     1               ; test "all done" flag
  228.         jz      sndbr1          ; loop until it's nonzero.
  229. ;
  230. ; Next, set the break or DTR bit on the SIO
  231. ;
  232. setbit:    
  233.     mvi     a,5        ; select Write Register 5
  234.         out     mnprts
  235.         mvi     a,6ah        ; Tx enable, 8 bit Tx character,
  236.     ora    d        ; OR with appropriate bit mask
  237.     out     mnprts          ; 
  238. ;
  239. ;       Now, delay for duration of hangup or break
  240.         mov     a,e        ; delay count
  241.         call    delay
  242. ;
  243. ;       Time's up. Put transmitter back in normal state and return.
  244.         mvi     a,5             ; select Write Register 5
  245.         out     mnprts
  246.         mvi     a,0eah        ; Tx enable, 8 bit Tx character,
  247.         out     mnprts          ;.
  248.         ret                     ; done.
  249.  
  250. ; sysflt - system-dependent filter
  251. ;          called with character in E.
  252. ;          if this character should not be printed, return with A = zero.
  253. ;          preserves bc, de, hl.
  254. ;          note: <xon>,<xoff>,<del>, and <nul> are always discarded.
  255. ;
  256. sysflt:
  257.         mov     a,e             ; get character for testing
  258.     ret
  259.  
  260. ;
  261. ; sysbye - system-dependent processing for BYE command.
  262. ;
  263. sysbye:
  264.         ret
  265. ;
  266. ; This is the system-dependent command to change the baud rate.
  267. ; DE contains the two-byte value from the baud rate table; this
  268. ; value is also stored in 'speed'.
  269. ;
  270. sysspd:
  271.  
  272. ; Set the speed for bigboard II
  273. IF bbII
  274.         di                      ; don't let anything between the data bytes
  275.         mvi     a,01000111b     ; get the command byte (load time constant)
  276.         out     baudrt          ; output it to CTC
  277.         mov     a,e             ; Get the parsed value.
  278.         out     baudrt          ; Tell the baud rate generator.
  279.         ei                      ; end of critical section
  280.         ret
  281. ENDIF;bbII
  282.  
  283.  
  284. ; Set the speed for bigboard I
  285. IF bbI
  286.         mov     a,e             ; get the parsed value
  287.         out     baudrt          ; Tell the baud rate generator.
  288.         ret
  289. ENDIF;bbI
  290.  
  291. ; set the speed for the Ampro Little Board
  292. if ampro
  293.     mvi    e,3fh        ; offset to port b ctc 3f hex bytes
  294.     call    getbios
  295.     mvi    a,47h        ; counter mode,ctc reset,value follows
  296.     mov    m,a        ; store value
  297.     lda    speed+1        ; get ctc divisor
  298.     inx    h        ; location of ctc divisor
  299.     mov    m,a        ; store new divisor
  300. ;
  301. ; set up wr4 clock divisor according to mspeed
  302. ;
  303.     mvi    e,50h        ; offset to dart wr4
  304.     call    getbios
  305.     mvi    a,3fh        ; mask for wr4 clock bits
  306.     ana    m        ; mask off bits
  307.     mov    m,a        ; and save to wr4
  308.     lda    speed        ; get clock flag
  309.     ora    a        ; set flags, zero = 300 bps
  310.     mvi    a,80h        ; x32 clock bit
  311.     jz    lbps        ; setup wr4 for 300 bps x32 clock
  312. ;
  313. ;  set up wr4 value for 1200 bps x16 clock 'hl' has wr4 loc
  314. ;
  315. hbps:    mvi    a,40h        ; x16 clock
  316. ;
  317. ;  setup wr4 value for 300 bps x32 clock 'hl' has wr4 loc
  318. ;
  319. lbps:    ora    m        ; set clock bits saving parity
  320.     mov    m,a        ; store new clock divisor to wr4 value
  321. ;
  322. ;  initialize sio/dart
  323. ;
  324. intsio:    lxi    h,intend
  325.     push    h        ; set up for return
  326.     mvi    e,36h        ; offset to ioinit
  327.     call    getbios
  328.     pchl            ; we pushed return address
  329. intend:    ret
  330.  
  331. ;
  332. ;  return bios location in 'hl' called with offset in 'e'
  333. ;
  334. getbios:
  335.     lhld    1        ; get bios location
  336.     mvi    d,0        ; clear 'd'
  337.     dad    d
  338.     ret
  339. ;
  340. ENDIF;ampro
  341.  
  342. ;
  343. ;       Speed tables
  344. ; (Note that speed tables MUST be in alphabetical order for later
  345. ; lookup procedures, and must begin with a value showing the total
  346. ; number of entries.  The speed help tables are just for us poor
  347. ; humans.
  348.  
  349. ;       db      string length,string,divisor (2 identical bytes or 1 word)
  350. ; [Toad Hall]
  351.  
  352. IF bbI
  353. spdtbl: db      10h                     ;16 entries
  354.         db      03h,'110$',     02h,02h
  355.         db      04h,'1200$',    07h,07h
  356.         db      05h,'134.5$',   03h,03h
  357.         db      03h,'150$',     04h,04h
  358.         db      04h,'1800$',    08h,08h
  359.         db      05h,'19200$',   0fh,0fh
  360.         db      04h,'2000$',    09h,09h
  361.         db      04h,'2400$',    0ah,0ah
  362.         db      03h,'300$',     05h,05h
  363.         db      04h,'3600$',    0bh,0bh
  364.         db      04h,'4800$',    0ch,0ch
  365.         db      02h,'50$',      00h,00h
  366.         db      03h,'600$',     06h,06h
  367.         db      04h,'7200$',    0dh,0dh
  368.         db      02h,'75$',      01h,01h
  369.         db      04h,'9600$',    0eh,0eh
  370.  
  371. sphtbl: db      cr,lf,'   50     75    110    134.5  150    300    600   1200'
  372.         db      cr,lf,' 1800   2000   2400   3600   4800   7200   9600  19200$'
  373. ENDIF;bbI
  374.  
  375. IF bbII
  376. spdtbl: db      8                       ; 8 entries
  377.         db      04h,'1200$',    20h,20h
  378.         db      05h,'19200$',   02h,02h
  379.         db      04h,'2400$',    10h,10h
  380.         db      03h,'300$',     80h,80h
  381.         db      05h,'38400$',   01h,01h
  382.         db      04h,'4800$',    08h,08h
  383.         db      03h,'600$',     40h,40h
  384.         db      04h,'9600$',    04h,04h
  385.  
  386. sphtbl: db      cr,lf,'   300   600  1200  2400  4800  9600 19200 38400$'
  387. ENDIF;bbII
  388.  
  389.  
  390. IF ampro
  391. spdtbl: db      6                       ; 6 entries
  392.         db      04h,'1200$',    1,104
  393.         db      04h,'2400$',    1,52
  394.         db      03h,'300$',     0,208
  395.         db      04h,'4800$',    1,26
  396.         db      03h,'600$',     1,208
  397.         db      04h,'9600$',    1,13
  398.  
  399. sphtbl: db      cr,lf,'   300  600  1200  2400  4800  9600$'
  400. ENDIF;ampro
  401.  
  402. ; This is the system-dependent SET PORT command.
  403. ; HL contains the argument from the command table.
  404. ;
  405. sysprt:
  406.         ret
  407. ;
  408.  
  409. prttbl  equ     0               ; SET PORT is not supported
  410. prhtbl  equ     0
  411.  
  412. ;
  413. ; selmdm - select modem port
  414. ; selcon - select console port
  415. ; selmdm is called before using inpmdm or outmdm;
  416. ; selcon is called before using inpcon or outcon.
  417. ; preserves BC, DE, HL.
  418. ;
  419. selmdm:
  420. selcon:
  421.         ret
  422. ;
  423. ; Get character from console, or return zero.
  424. ; result is returned in A.  destroys bc, de, hl.
  425. ;
  426. inpcon:
  427.         mvi     c,dconio        ;Direct console I/O BDOS call.
  428.         mvi     e,0FFH          ;Input.
  429.         call    BDOS
  430.         ret
  431. ;
  432. ;
  433. ;       Output character in E to the console.
  434. ;       destroys bc, de, hl
  435. ;
  436. outcon:
  437.  
  438.         mvi     c,dconio        ;Console output bdos call.
  439.         call    bdos            ;Output the char to the console.
  440.  
  441.         ret
  442. ;
  443. ;
  444. ;       outmdm - output a char from E to the modem.
  445. ;               the parity bit has been set as necessary.
  446. ;       returns nonskip; bc, de, hl preserved.
  447. outmdm:
  448.         in      mnprts          ;Get the output done flag.
  449.         ani     output          ;Is it set?
  450.         jz      outmdm          ;If not, loop until it is.
  451.         mov     a,e
  452.         out     mnport          ;Output it.
  453.         ret
  454.  
  455.  
  456. ;
  457. ;       get character from modem; return zero if none available.
  458. ;       destroys bc, de, hl.
  459. inpmdm:
  460.         in      mnprts          ;Get the port status into A.
  461.         ani     input           ;See if the input ready bit is on.
  462.         rz                      ;If not then return.
  463.         in      mnport          ;If so, get the char.
  464.  
  465.     ret                     ; return with character in A
  466.  
  467.  
  468. ;
  469. ;       flsmdm - flush comm line.
  470. ;       Modem is selected.
  471. ;       Currently, just gets characters until none are available.
  472.  
  473. flsmdm: call    inpmdm          ; Try to get a character
  474.         ora     a               ; Got one?
  475.         jnz     flsmdm          ; If so, try for another
  476.         ret                     ; Receiver is drained.  Return.
  477. ;
  478. ;       lptstat - get the printer status. Return a=0ffh if ok, or 0 if not.
  479. lptstat:
  480.         xra     a               ; assume it is ok.. this may not be necessary
  481.         ret
  482.  
  483. ;
  484. ;       outlpt - output character in E to printer
  485. ;       console is selected.
  486. ;       preserves de.
  487. outlpt:
  488.         push    d               ; save DE in either case
  489.         ana     a               ; if A = 0 do nothing,
  490.         jz      outlp1          ; [30] if a=0 do nothing
  491.         mvi     c,lstout
  492.         call    bdos            ;Char to printer
  493. outlp1: pop     d               ; restore saved register pair
  494.         ret
  495. ;
  496.  
  497. ;
  498. ;       Screen manipulation routines
  499. ;       csrpos - move to row B, column C
  500. ;
  501. ;       csrpos for terminals that use a leadin sequence followed
  502. ;        by (row + 31.) and (column + 31.)
  503. ;
  504. IF NOT (bbII OR ampro)            ;[obs I think ]
  505. csrpos: push    b               ; save coordinates
  506.         lxi     d,curldn        ; get cursor leadin sequence
  507.         call    prtstr          ; print it
  508.         pop     h               ; restore coordinates
  509.         mov     a,h             ; get row
  510.         adi     (' '-1)         ; space is row one
  511.         mov     e,a
  512.         push    h
  513.         call    outcon          ; output row
  514.         pop     h
  515.         mov     a,l             ; get column
  516.         adi     (' '-1)         ; space is column one
  517.         mov     e,a
  518.         jmp     outcon          ; output it and return
  519. ENDIF    ; NOT bbII OR ampro
  520.  
  521. ;
  522. ; delchr - make delete look like a backspace.  Unless delete is a
  523. ;          printing character, we just need to print a backspace
  524. ;          (we'll output clrsp afterwards)
  525. delchr:
  526.  
  527. IF bbI
  528.         lxi     d,delstr
  529.         jmp     prtstr
  530. ENDIF;bbI
  531.  
  532.  
  533. IF NOT bbI
  534.         mvi     e,bs            ;get a backspace
  535.         jmp     outcon
  536. ENDIF;NOT bbI
  537.  
  538. ; erase the character at the current cursor position
  539. clrspc: mvi     e,' '
  540.         call    outcon
  541.         mvi     e,bs            ;get a backspace
  542.         jmp     outcon
  543.  
  544. ; erase the current line
  545. clrlin: lxi     d,eralin
  546.         jmp     prtstr
  547.  
  548. ; erase the whole screen, and go home. preserves b (but not c)
  549. clrtop: lxi     d,erascr
  550.         jmp     prtstr
  551.  
  552. ; If its a BigBoard or Ampro, we need a terminal, so link to CPXVDU.ASM
  553. IF bbII
  554. sysver:    db    'Big Board II$'
  555. ENDIF;bbII
  556.  
  557. IF ampro
  558. sysver:    db    'Ampro Little Board$'
  559. ENDIF;ampro
  560.  
  561. IF (bbII AND lasm)    ; we need a terminal as well
  562. LINK CPXVDU.ASM
  563. ENDIF    ;(bbII AND lasm)
  564.  
  565. IF (ampro AND lasm)    ; we need a terminal as well
  566. LINK CPXVDU.ASM
  567. ENDIF    ;(ampro AND lasm)
  568.  
  569. ;If here, we are Kaypro or Xerox 820, or if from M80, we should skip
  570. ; a few lines if Bigboard.
  571.  
  572. IF kpii
  573. sysver:
  574. ttytyp:    db    'Kaypro II$'
  575. outlin:    db    subt,cr,lf,tab,tab,'$'
  576. erascr:    db    subt,'$'                ;Clear screen and home.
  577. eralin:    db    cr,18H,'$'              ;Clear line.
  578. curldn:    db    esc,'=$'                ;Cursor lead-in
  579. delstr:    db    bs,' ',bs,bs,'$'        ; adjust for echoing delete character
  580. ttab:                    ;Table start location.
  581. ta:    db    0BH,'$',0,0             ;Cursor up.
  582. tb:    db    0AH,'$',0,0             ;Cursor down.
  583. tc:    db    0CH,'$',0,0             ;Cursor right.
  584. td:    db    bs,'$',0,0              ;Cursor left
  585. te:    db    subt,'$',0,0            ;Clear display
  586. tf:    db    esc,'G$',0              ; Enter Graphics Mode (select Greek)
  587. tg:    db    esc,'A$',0              ; Exit Graphics mode (select ASCII)
  588. th:    db    1EH,'$',0,0             ; Cursor home.          [UTK016]
  589. ti:    db    esc,'E','$',0           ; Reverse linefeed. (insert line)
  590. tj:    db    'W'-100O,'$',0,0        ; Clear to end of screen.
  591. tk:    db    'X'-100O,'$',0,0        ; Clear to end of line.
  592. ENDIF ; kpii
  593. ;
  594.  
  595. IF xer820
  596. ttytyp:
  597. sysver:    db    'Xerox 820$'
  598. outlin:    db    subt,cr,lf,tab,tab,'$'
  599. erascr:    db    subt,'$'                ;Clear screen and home.
  600. eralin:    db    cr,18H,'$'              ;Clear line.
  601. curldn:    db    esc,'=$'                ;Cursor lead-in
  602. delstr:    db    bs,' ',bs,bs,'$'        ; adjust for echoing delete character
  603. ttab:                    ;Table start location.
  604. ta:    db    0BH,'$',0,0             ;Cursor up.
  605. tb:    db    0AH,'$',0,0             ;Cursor down.
  606. tc:    db    0CH,'$',0,0             ;Cursor right.
  607. td:    db    bs,'$',0,0              ;Cursor left
  608. te:    db    subt,'$',0,0            ;Clear display
  609. tf:    db    '$',0,0,0               ; Enter Graphics Mode (can't)
  610. tg:    db    '$',0,0,0               ; Exit Graphics mode (can't)
  611. th:    db    1EH,'$',0,0             ; Cursor home.          [UTK016]
  612. ti:    db    0BH,'$',0,0             ; Reverse linefeed. (cursor up)
  613. tj:    db    11H,'$',0,0             ; Clear to end of screen.
  614. tk:    db    18H,'$',0,0             ; Clear to end of line.
  615. ENDIF ; xer820
  616. ovlend    equ    $    ; End of overlay
  617.  
  618.     END
  619.