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

  1. IF NOT LASM
  2. .printx * CPXNOR.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. ;       This file contains the system-dependent code and data for various
  22. ;       NorthStar KERMITs.  This has the Family name of CPXNOR.ASM.
  23. ;
  24. ; revision history (last edit first)
  25. ;
  26. ;edit 4, 16-Jan-1991 by MF. Fixed a bug in OUTCON wherein the final RET
  27. ;    was missing (bug reported by David P. Arnot of Scottish
  28. ;    Agricultural College).
  29. ;edit 3, 12-Oct-1990 by MF.  Added a semicolon before the comment
  30. ;    beginning "Family is the string so we don't get errors
  31. ; edit 2, 23 July, 1987 by OBSchou to massage file to suit CPXCOM.ASM.
  32. ;
  33. ; edit 1:  1 June, 1986 by OBSchou, Loughborogh University, UK.
  34. ;       Hived off northstar and Comart system dependent modules from 
  35. ;       CPXSYS.ASM.  This assembles ok, but I cannot test it.  Any comments?
  36.  
  37.  
  38. IF norths
  39. .printx    * Assembling for NorthStar Horizon with    HSIO-4 board *
  40. ENDIF;norths
  41.  
  42. IF horizon    ;[25]
  43. .printx    * Assembling KERMIT-80 for the NorthStar Horizon *
  44. ENDIF;horizon
  45.  
  46. IF advant    ;[22]
  47. .printx    * Assembling kermit-80 for North Star Advantage    *
  48. ENDIF    ;[22]
  49.  
  50. IF basicns    ;[29]
  51. .printx    * Assembling KERMIT-80 for the Northstar Horizon using printer port *
  52. ENDIF    ;basicns [29]
  53.  
  54. IF comart
  55. .printx    * Assembling KERMIT-80 for Comart Communicator *
  56. ENDIF ; comart
  57.  
  58. ; the basics...
  59. IF norths ;The basic Northstar Horizon BIOS does not access ports 2-5
  60. port0d    equ    02h        ;Port 0 data (console)
  61. port0s    equ    03h        ;Port 0 status
  62. port1d    equ    04h        ;Port 1 data (printer)
  63. port1s    equ    05h        ;Port 1 status
  64.  
  65. port2b    equ    10h        ;Port 2 baud
  66. port2i    equ    11h        ;Port 2 interrupt mask
  67. port2d    equ    12h        ;Port 2 data
  68. port2s    equ    13h        ;Port 2 status
  69.  
  70. port3b    equ    14h        ;Port 3 baud
  71. port3i    equ    15h        ;Port 3 interrupt mask
  72. port3d    equ    16h        ;Port 3 data
  73. port3s    equ    17h        ;Port 3 status
  74.  
  75. port4b    equ    18h        ;Port 4 baud
  76. port4i    equ    19h        ;Port 4 interrupt mask
  77. port4d    equ    1Ah        ;Port 4 data
  78. port4s    equ    1Bh        ;Port 4 status
  79.  
  80. port5b    equ    1Ch        ;Port 5 baud
  81. port5i    equ    1Dh        ;Port 5 interrupt mask
  82. port5d    equ    1Eh        ;Port 5 data
  83. port5s    equ    1Fh        ;Port 5 status
  84.  
  85. NS19K2    EQU    00H        ;19.2 kilobaud
  86. NS9600    EQU    01H        ;9600 baud
  87. NS4800    EQU    02H        ;4800 baud
  88. NS2400    EQU    03H        ;2400 baud
  89. NS1200    EQU    04H        ;1200 baud
  90. NS0600    EQU    05H        ; 600 baud
  91. NS0300    EQU    06H        ; 300 baud
  92. NS0110    EQU    07H        ; 110 baud
  93. ;; Set to use port 5 at 1200 baud
  94. mnport    equ    port5d        ;Data port
  95. mnprts    equ    port5s        ;Status port
  96. baudrt    equ    port5b        ;Baud rate port
  97. baudini    equ    ns1200        ;Initial baud rate
  98. output    EQU    1        ;Bit of UART status for transmitter ready
  99. input    EQU    2        ;Bit of UART status for receiver ready
  100. z80    EQU    TRUE        ;This one's a Z80.
  101. ENDIF;norths
  102.  
  103. IF basicns    ;[29]
  104. mnport    equ    04h        ;printer port data
  105. mnprts    equ    05h        ; printer port status
  106. output    equ    1        ;transmitter ready
  107. input    equ    2        ;receiver ready
  108. z80    equ    FALSE        ; not important
  109. ENDIF    ;basicns [29]
  110.  
  111. IF horizon        ;[25]
  112. mnport    EQU    004H    ;Modem data port
  113. mnprts    EQU    005H    ;Modem status port
  114. output    EQU    01H    ;Transmitter empty
  115. input    EQU    02H    ;Input data available
  116. TxEmpty    EQU    04h    ;Transmitter empty
  117. ;Note:  Needs terminal definition (vt100, vt52, tvi925, adm3a or crt above)
  118. z80    EQU    TRUE    ;This one's a Z80.
  119. ENDIF;horizon
  120.  
  121. IF advant    ;[22]
  122. vtval    EQU    1        ; we do emulation of VT52s
  123. slot    EQU    1        ;SIO card slot
  124. mnport    EQU    (6-slot)*16    ;Modem data port
  125. mnprts    EQU    mnport+1    ;Modem status port
  126. baudrt    EQU    mnport+8    ;Baud rate register
  127. output    EQU    01H        ;Transmitter buffer empty
  128. input    EQU    02H        ;Input data available
  129. TxEmpty    EQU    04h        ;Transmitter empty flag
  130. z80    EQU    TRUE
  131. ENDIF;[22] advant
  132.  
  133. IF comart        ;[25]
  134. mnport    EQU    002H    ;Modem data port
  135. mnprts    EQU    003H    ;Modem status port
  136. output    EQU    01H    ;Transmitter empty
  137. input    EQU    02H    ;Input data available
  138. TxEmpty    EQU    04h    ;Transmitter empty
  139. ;Note:  Needs terminal definition (vt100, vt52, tvi925, adm3a or crt above)
  140. z80    EQU    TRUE    ;This one's a Z80.
  141. ENDIF;comart
  142.  
  143.  
  144. IF advant
  145. defesc    EQU    '\'-100O
  146. ENDIF;advant
  147.  
  148. ;
  149. ;      Family is the string used in VERSION to say which of several 
  150. ;       smaller overlay files are used.  These are (will be) derived from 
  151. ;       the juge CP4SYS.ASM file, in which case we will never get here.  
  152. ;       Just a Dollar, but put a sting in for a family of machines.
  153. ;
  154. family:    db    'CPXNOR.ASM  (4)  16-Jan-1991$'    ; Used for family versions....
  155.  
  156.  
  157.  
  158. sysxin:        ; continuation of system dependent initialisation code
  159. IF advant    ;[22]
  160.     mvi    a,40h
  161.     out    mnprts        ; Reset USART
  162.     lxi    h,7070h        ; Default to 1200 baud
  163.     shld    speed        ; store current speed
  164.     xchg
  165.     call    sysspd        ; set default baud rate
  166.     mvi    a,4Eh        ; Set UART mode to async 16x clock, 8 data
  167.     out    mnprts        ;    bits, no parity, and 1 stop bit
  168.     mvi    a,37h        ; Set command to Tx enable, DTR on, Rx enable,
  169.     out    mnprts        ;    break off, error reset, and RTS on
  170. ENDIF;[22] advant
  171.  
  172. IF norths
  173.     mvi    a,baudini    ;Get initial speed
  174.     out    baudrt
  175.     sta    speed        ;save for status display
  176.     sta    speed+1
  177. ENDIF;norths
  178.  
  179. IF comart OR horizon        ;[25]
  180. ; The PD8251/PD8251A is reset by three successive 00 Hex or two
  181. ; successive 80 Hex command instructions followed by a software
  182. ; reset command instruction (40 Hex).
  183.     mvi    a,80h        ; Send UART reset
  184.     out    mnprts
  185.     mvi    a,80h
  186.     out    mnprts
  187.     mvi    a,40h
  188.     out    mnprts
  189.     mvi    a,4Eh        ; Set UART mode to async 16x clock, 8 data
  190.     out    mnprts        ;    bits, no parity, and 1 stop bit
  191.     mvi    a,37h        ; Set command to Tx enable, DTR on, Rx enable,
  192.     out    mnprts        ;    break off, error reset, and RTS on
  193. ENDIF;comart OR horizon
  194.  
  195.  
  196.     ret            ; return from system-dependent routine
  197. ;
  198.  
  199. ;
  200. ;       system-dependent termination processing
  201. ;       If we've changed anything, this is our last chance to put it back.
  202. sysexit:
  203.  
  204.     ret
  205.  
  206. ;
  207. ;       system-dependent processing for start of CONNECT command
  208. ;
  209. syscon:
  210.     ret
  211.  
  212. conmsg:        ; Messages printed when entering transparent (CONNECT) mode:
  213. ;
  214.  
  215. ;
  216. ;       syscls - system-dependent close routine
  217. ;       called when exiting transparent session.
  218. ;
  219. syscls:
  220.     ret
  221. ;
  222.  
  223. ;
  224. ;       sysinh - help for system-dependent special functions.
  225. ;       called in response to <escape>?, after listing all the
  226. ;       system-independent escape sequences.
  227. ;
  228. sysinh:
  229. IF advant OR comart OR horizon ; some more
  230.     lxi    d,inhlps    ; we got options...
  231.     call    prtstr        ; print them.
  232. ENDIF;[22] advant OR comart OR horizon [29]
  233.  
  234.     ret
  235.  
  236.  
  237. ;additional, system-dependent help for transparent mode
  238. ; (two-character escape sequences)
  239. inhlps:
  240.  
  241. ; [16] [18] have added super brain and Torch to the list of Breaking machines.
  242. IF advant OR comart OR horizon ; ... some more
  243.     db    cr,lf,'B  Transmit a BREAK'
  244. ENDIF;[22] advant OR comart OR horizon
  245.  
  246.     db    '$'                     ;[hh] table terminator
  247.  
  248. ;
  249. ;       sysint - system dependent special functions
  250. ;       called when transparent escape character has been typed;
  251. ;       the second character of the sequence is in A (and in B).
  252. ;       returns:
  253. ;       non-skip: sequence has been processed
  254. ;       skip:   sequence was not recognized
  255. sysint:    ani    137O        ; convert lower case to upper, for testing...
  256. IF advant OR comart OR horizon    ; [22] [25] ... some more
  257.     cpi    'B'             ; send break?
  258.     jz    sendbr        ; yes, go do it.  return nonskip when through.
  259. ENDIF;advant OR comart OR horizon [32]
  260.  
  261.     jmp    rskp        ; take skip return - command not recognized.
  262.  
  263.  
  264. ;
  265.  
  266. IF advant OR comart OR horizon    ;[lmj] 
  267. sendbr:
  268. ;
  269. ;       Ensure that the transmitter has finished sending buffered chars
  270. sndbr1:    in    mnprts        ; get UART status
  271.     ani    TxEmpty        ; everything sent?
  272.     jz    sndbr1        ; no, wait a bit more
  273. ;
  274. ;       Begin sending a break by setting bit in UART command register
  275.     mvi    a,3Fh        ; Set TxEna, DTR, RxEna, SBreak, ErrRst, RTS
  276.     out    mnprts
  277. ;
  278. ;       Wait for 250 milliseconds (using hundredths second delay routine)
  279.     mvi    a,25
  280.     call    delay
  281. ;
  282. ;       Resume normal operation by clearing the SendBreak command bit
  283.     mvi    a,37h        ;Set TxEna, DTR, RxEna, ErrRst, RTS
  284.     out    mnprts
  285. ;
  286.     ret            ;done
  287. ENDIF;advant OR comart OR horizon
  288.  
  289. ;
  290.  
  291. ;
  292. ;       sysflt - system-dependent filter
  293. ;       called with character in E.
  294. ;       if this character should not be printed, return with A = zero.
  295. ;       preserves bc, de, hl.
  296. ;       note: <xon>,<xoff>,<del>, and <nul> are always discarded.
  297. sysflt:
  298.     mov    a,e        ; get character for testing
  299. IF advant    ;[22]
  300.     cpi    'D'-100O        ;Control-D's reset video
  301.     rnz            ; if not control-D, it's ok.
  302.     xra    a        ; don't allow control-D out.
  303. ENDIF;[22] advant
  304.     ret
  305.  
  306. ;       mdmflt - modem filter [30]
  307. ;       called with character to be sent to printer in E
  308. ;       with parity set as appropriate.
  309. ;       return with accumulator = 0 do do nothing,
  310. ;                               <> 0 to send char in E.
  311. mdmflt:
  312.     mov    a,e        ;[30] get character to test
  313.     ret
  314.  
  315.  
  316.  
  317. ;       prtflt - printer filter [30]
  318. ;       called with character to be sent to printer in E
  319. ;       returns with a = 0 to do nothing
  320. ;                    a <> 0 to print it.
  321. ;
  322. ;       this routine for those printer that automatically insert
  323. ;       a lf on cr, or cr for lf.  Should this be shifted to 
  324. ;       the system indep. stuff, in say 4.06?
  325. prtflt:
  326.     mov    a,e        ; [30] get character to test
  327.     ret
  328.  
  329.  
  330. ;
  331.  
  332. ;
  333. ; system-dependent processing for BYE command.
  334. ;  for apmmdm, heath, and lobo, hang up the phone.
  335. sysbye:
  336.     ret
  337. ;
  338.  
  339. ;       This is the system-dependent command to change the baud rate.
  340. ;       DE contains the two-byte value from the baud rate table; this
  341. ;       value is also stored in 'speed'.
  342. sysspd:
  343. IF norths OR advant ;
  344.     mov    a,e        ; get the parsed value
  345.     out    baudrt        ; Tell the baud rate generator.
  346.     ret
  347. ENDIF;norths OR advant 
  348.  
  349. IF advant    ;[22]
  350. spdtbl:    db    6            ; 6 entries
  351.     db    04,'1200$',     70h,70h
  352.     db    04,'2400$',     78h,78h
  353.     db    03,'300$',      40h,40h
  354.     db    04,'4800$',     7Ch,7Ch
  355.     db    03,'600$',      60h,60h
  356.     db    04,'9600$',     7Eh,7Eh
  357.  
  358. sphtbl:    db    cr,lf,'   300    600    1200    2400    4800    9600$'
  359. ENDIF;[22] advant
  360.  
  361.  
  362. IF norths
  363. spdtbl:    db    8        ; 8 entries
  364.     db    3,'110$',       07H,07H
  365.     db    4,'1200$',      04H,04H
  366.     db    5,'19200$',     00H,00H
  367.     db    4,'2400$',      03H,03H
  368.     db    3,'300$',       06H,06H
  369.     db    4,'4800$',      02H,02H
  370.     db    3,'600$',       05H,05H
  371.     db    4,'9600$',      01H,01H
  372.  
  373.  
  374. sphtbl:    db    cr,lf
  375.     db    '   110   300   600  12000  2400  4800  9600 19200$'
  376. ENDIF;norths
  377.  
  378. ; The following conditionals were once a huge if not statement.  There
  379. ; wasn't enough room to add the lobo to the list, so it had to be broken
  380. ; into 2, which you can't do with an if not.  I redid it as two ifs and
  381. ; applied them to those that wouldn't set baud. [Hal Hostetler]
  382. IF NOT (advant OR norths)
  383. spdtbl    EQU    0        ;[hh] SET BAUD not supported.
  384. sphtbl    EQU    0        ;[hh] ran out of room above...
  385. ENDIF    ;NOT (advant OR norths)
  386. ;
  387. ;
  388.  
  389. ;       This is the system-dependent SET PORT command.
  390. ;       HL contains the argument from the command table.
  391. sysprt:
  392.     ret
  393.  
  394. prttbl    equ    0        ; SET PORT not supported
  395. prhtbl    equ    0
  396. ;
  397.  
  398. ;
  399. ;       selmdm - select modem port
  400. ;       selcon - select console port
  401. ;       selmdm is called before using inpmdm or outmdm;
  402. ;       selcon is called before using inpcon or outcon.
  403. ;       For iobyt systems, diddle the I/O byte to select console or comm port;
  404. ;       For Decision I, switches Multi I/O board to console or modem serial
  405. ;       port.  [Toad Hall]
  406. ;       For the rest, does nothing.
  407. ;       preserves bc, de, hl.
  408. selmdm:
  409. selcon:
  410.     ret
  411. ;
  412.  
  413. ;       Get character from console, or return zero.
  414. ;       result is returned in A.  destroys bc, de, hl.
  415. ;
  416. inpcon:
  417.     mvi    c,dconio    ;Direct console I/O BDOS call.
  418.     mvi    e,0FFH        ;Input.
  419.     call    BDOS
  420.     ret
  421. ;
  422.  
  423. ;
  424. ;       Output character in E to the console.
  425. ;       destroys bc, de, hl
  426. ;
  427. outcon:
  428.     mvi    c,dconio    ;Console output bdos call.
  429.     call    bdos        ;Output the char to the console.
  430.     ret            ;[MF]per David P. Arnot
  431. ;
  432.  
  433. ;
  434. ;       outmdm - output a char from E to the modem.
  435. ;               the parity bit has been set as necessary.
  436. ;       returns nonskip; bc, de, hl preserved.
  437. outmdm:
  438.     in    mnprts        ;Get the output done flag.
  439.     ani    output        ;Is it set?
  440.     jz    outmdm        ;If not, loop until it is.
  441.     mov    a,e
  442.     out    mnport        ;Output it.
  443.     ret
  444. ;
  445.  
  446. ;
  447. ;       get character from modem; return zero if none available.
  448. ;       for IOBYT systems, the modem port has already been selected.
  449. ;       destroys bc, de, hl.
  450. inpmdm:
  451. ;Note: modem port should already be selected for mdI.  [Toad Hall]
  452.     in    mnprts        ;Get the port status into A.
  453.     ani    input        ;See if the input ready bit is on.
  454.     rz            ;If not then return.
  455.     in    mnport        ;If so, get the char.
  456.     ret            ; return with character in A
  457.  
  458.  
  459. ;
  460. ;       flsmdm - flush comm line.
  461. ;       Modem is selected.
  462. ;       Currently, just gets characters until none are available.
  463.  
  464. flsmdm:    call    inpmdm        ; Try to get a character
  465.     ora    a        ; Got one?
  466.     jnz    flsmdm        ; If so, try for another
  467.     ret            ; Receiver is drained.  Return.
  468. ;
  469.  
  470. ;
  471. ;       lptstat - get the printer status. Return a=0ffh if ok, or 0 if not.
  472. lptstat:
  473.     xra    a        ; assume it is ok.. this may not be necessary
  474.     ret
  475.  
  476. ;
  477. ;       outlpt - output character in E to printer
  478. ;       console is selected.
  479. ;       preserves de.
  480. outlpt:
  481.     push    d        ; save DE in either case
  482.     call    prtflt        ; go through printer filter [30]
  483.     ana    a        ; if A = 0 do nothing,
  484.     jz    outlp1        ; [30] if a=0 do nothing
  485.     mvi    c,lstout
  486.     call    bdos        ;Char to printer
  487. outlp1:    pop    d        ; restore saved register pair
  488.     ret
  489. IF advant    ; all others require terminals
  490. ;
  491.  
  492. ;
  493. ;       Screen manipulation routines
  494. ;       csrpos - move to row B, column C
  495. ;
  496. ;       csrpos for terminals that use a leadin sequence followed
  497. ;        by (row + 31.) and (column + 31.)
  498. ;
  499. csrpos:    push    b        ; save coordinates
  500.     lxi    d,curldn    ; get cursor leadin sequence
  501.     call    prtstr        ; print it
  502.     pop    h        ; restore coordinates
  503.     mov    a,h        ; get row
  504.     adi    (' '-1)         ; space is row one
  505.     mov    e,a
  506.     push    h
  507.     call    outcon        ; output row
  508.     pop    h
  509.     mov    a,l        ; get column
  510.     adi    (' '-1)         ; space is column one
  511.     mov    e,a
  512.     jmp    outcon        ; output it and return
  513. ENDIF    ;advant
  514.  
  515. ;
  516. ; delchr - make delete look like a backspace.  Unless delete is a printing
  517. ;       character, we just need to print a backspace. (we'll output clrspc
  518. ;       afterwards)
  519. ;       For Kaypro and Vector General, delete puts a blotch on the screen.
  520. ;       For Apple and Osborne 1, delete moves but doesn't print.
  521. delchr:
  522. IF advant        ;[22]
  523.     ret
  524. ENDIF;advant 
  525. IF NOT (advant );[22]
  526.     mvi    e,bs        ;get a backspace
  527.     jmp    outcon
  528. ENDIF;NOT (advant) [22]
  529.  
  530. ; erase the character at the current cursor position
  531. clrspc:    mvi    e,' '
  532.     call    outcon
  533.     mvi    e,bs        ;get a backspace
  534.     jmp    outcon
  535.  
  536. ; erase the current line
  537. clrlin:    lxi    d,eralin
  538.     jmp    prtstr
  539.  
  540. ; erase the whole screen, and go home. preserves b (but not c)
  541. clrtop:    lxi    d,erascr
  542.     jmp    prtstr
  543.  
  544.  
  545. IF norths
  546. sysver:    db    'Northstar Horizon$'
  547. ENDIF;norths
  548.  
  549. IF basicns    ;[29]
  550. sysver:    db    'Northstar using printer port$'
  551. ENDIF    ;basicns [29]
  552.  
  553. IF comart    ;[25]
  554. sysver:    db    'Comart Communicator$'
  555. ENDIF;comart
  556.  
  557. IF horizon    ;[25]
  558. sysver:    db    'Northstar Horizon$'
  559. ENDIF;horizon
  560.  
  561. IF advant    ;[22]
  562. sysver:    db    'North Star Advantage$'
  563. outlin:    db    04H,cr,lf,tab,'$'
  564. erascr:    db    04H,'$'                 ;Clear screen and go home.
  565. eralin:    db    cr,0EH,'$'              ;Clear line.
  566. curldn:    db    esc,'=$'                ;cursor leadin
  567. ttab:                    ;Table start location.
  568. ta:    db    0BH,'$',0,0             ;Cursor up.
  569. tb:    db    0AH,'$',0,0             ;Cursor down.
  570. tc:    db    0CH,'$',0,0             ;Cursor right.
  571. td:    db    bs,'$',0,0              ;Cursor left
  572. te:    db    04H,'$',0,0             ;Clear display
  573. tf:    db    12H,'$',0,0             ;Enter Graphics Mode
  574. tg:    db    13H,'$',0,0             ;Exit Graphics mode
  575. th:    db    1EH,'$',0,0             ;Cursor home.
  576. ti:    db    0BH,'$',0,0             ;Reverse linefeed.
  577. tj:    db    0FH,'$',0,0             ;Clear to end of screen.
  578. tk:    db    0EH,'$',0,0             ;Clear to end of line.
  579. ENDIF;[22] advant
  580. IF lasm AND (NOT advant)
  581. LINK CPXVDU.ASM
  582. ENDIF   ;lasm - m80 will INCLUDE CPXVDU.ASM
  583.  
  584. IF lasm    ; here if not a terminal selected and in LASM
  585. ovlend    equ    $
  586.     END
  587. ENDIF    ;lasm
  588.