home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BBSING / MBBS / MBZSIO-2.AQM / MBZSIO-2.ASM
Assembly Source File  |  2000-06-30  |  10KB  |  359 lines

  1. ;
  2. ;***********************************************************************
  3. ;
  4. ;             MBYE (Modular 'BYE')
  5. ;        Zilog Z80-SIO/DART USART/UART routines
  6. ;            v2.1 (02/21/84) by Kim Levitt
  7. ;
  8. ; These routines will allow the easy patching of MBYE for any type of
  9. ; modem/serial port combination.  Certain routines must return status
  10. ; flags, so please be careful to set the flags as directed.
  11. ;
  12. ; NOTE: set NORING EQU YES in the main MBYE program if you have an SIO
  13. ; chip. Normally, the SIO doesn't allow monitoring of the RI status.
  14. ; The DART, however, does have RI has a standard function. If you have
  15. ; a DART, set NORING EQU NO (unless you are using a Smartmodem). (Also
  16. ; set DART EQU YES below.)
  17. ;
  18. ; This version is for the Zilog SIO chip that is hooked up to an extern-
  19. ; al modem.  A Z80-CTC or 8116 can be used as baud rate generator. If
  20. ; you have a KAYPRO, XEROX 820-II, or another "BigBoard"-based system,
  21. ; set the KAYPRO equate true and the rest is automatic.
  22. ;
  23. ;-----------------------------------------------------------------------
  24. ;
  25. ; 02/21/84  Removed exclaimation mark from comment      - Kim Levitt oops!
  26. ; 02/20/84  Added comments for XEROX 820-II & BigBoards,
  27. ;        code for DARTs and modified SIOs to read RI - Kim Levitt
  28. ; 02/02/84  Fixed and renamed to work with MBYE 3.0    - Kim Levitt
  29. ;        (Also added conditional equates 8116, CTC and KAYPRO.)
  30. ; 11/27/83  Altered and renamed to work with BYE3    - Irv Hoff
  31. ; 08/04/83  Updated for use with ByeII version 1.6    - Paul Traina
  32. ; 07/19/83  Improved operation of modem initialization.    - Paul Traina
  33. ; 04/18/83  Added option to use 300/1200 Smartmodem.    - Don Brown
  34. ; 04/14/83  Added option for alt. CTC baud set format.    - Paul Traina
  35. ; 02/21/83  Initial version.                - Steve Fox
  36. ;
  37. ;-----------------------------------------------------------------------
  38. ;
  39. KAYPRO:    EQU    YES        ;yes, if Kaypro, Xerox 820 or BigBoard
  40. ;
  41.      IF    KAYPRO
  42. CTC:    EQU    NO
  43. C8116:    EQU    YES        ;BigBoards use the 8116 baud rate clock
  44.      ENDIF
  45. ;
  46.      IF    NOT KAYPRO
  47. CTC:    EQU    YES
  48. C8116:    EQU    NO        ;most other systems use CTC
  49.      ENDIF
  50. ;
  51. ; Set base ports for SIO/DART & baud rate clock
  52. ;
  53.      IF    KAYPRO
  54. DART:    EQU    NO        ;BigBoards use a true SIO
  55. BASEP:    EQU    04H        ;Base port for SIO
  56. BASEC:    EQU    00H        ;Base port for 8116
  57.      ENDIF
  58. ;
  59.      IF    NOT KAYPRO
  60. DART:    EQU    NO        ;Yes, if DART used and not SIO
  61. BASEP:    EQU    20H        ;Set Base port for SIO (data port)
  62. BASEC:    EQU    32H        ;Set Base port for CTC
  63.      ENDIF
  64. ;
  65. ; The following define the port addresses to use.
  66. ;
  67. DPORT:    EQU    BASEP        ;Data port
  68. SPORT:    EQU    BASEP+2        ;Status/Control port
  69. BPORT:    EQU    BASEC        ;Baud rate port
  70. ;
  71. ;
  72. ; The following are SPORT commands (output these to SPORT)
  73. ;
  74. ; WR0:
  75. RESCHN:    EQU    00011000B    ;Reset channel
  76. RESSTA:    EQU    00010000B    ;Reset ext/status
  77. RESERR:    EQU    00110000B    ;Error reset
  78. ;
  79. WRREG1:    EQU    00000000B    ;WR1 - No interrupts
  80. WRREG3:    EQU    11000001B    ;WR3 - Rx 8 bits/char, Rx enable
  81. WRREG4:    EQU    01000100B    ;WR4 - 16x, 1 stop bit, no parity
  82. ;
  83. ; WR5:
  84. DTROFF:    EQU    01101000B    ;DTR off, Tx 8 bits, Tx enable, RTS off
  85. DTRON:    EQU    11101010B    ;DTR on, Tx 8 bits, Tx enable, RTS on
  86. ;
  87. ;
  88. ; The following are SPORT status masks
  89. ;
  90. ; RR0:
  91. DAV:    EQU    00000001B    ;Data available
  92. TBMT:    EQU    00000100B    ;Transmit buffer empty
  93. DCD:    EQU    00001000B    ;Data carrier detect
  94. RI:    EQU    00010000B    ;Ring Indicator (DARTs only)
  95. ;
  96. ;(Normally, only DARTs can detect Ring Indicator...... HOWEVER,
  97. ; with special wiring to SYNC pin, SIOs can detect RI on this bit
  98. ; in asynchronous receive mode, wheras it is normally used only
  99. ; in synchronous mode. If you have this hardware mod done, your
  100. ; SIO will in effect function as a DART and this "SYNC/HUNT" bit
  101. ; in read reg. 0 will function as a RI status bit.) (Connect
  102. ; SYNCA pin 11 of SIO to pin 22 of RS-232C connector, not sure if
  103. ; any intermediate circut is necessary, though, so DON'T TRY IT
  104. ; UNLESS YOU KNOW WHAT YOU'RE DOING and really NEED ring detect,
  105. ; also realize you will lose synchronous capabilities...)
  106. ;
  107. ; RR1:
  108. OE:    EQU    00100000B    ;Overrun error
  109. FE:    EQU    01000000B    ;Framing error
  110. ERR:    EQU    OE+FE        ;Overrun and framing errors
  111. ;
  112.      IF    CTC
  113. ;
  114. ; First Byte of CTC Command:
  115. ;
  116. BDCMD1:    EQU    07H        ;110 baud        (timer mode)
  117. BDCMD2:    EQU    47H        ;300, 600 & 1200 baud    (counter mode)
  118. ;
  119. ;
  120. ; The following are baud rates for BPORT -- they may have to be changed
  121. ; for your particular system's CTC.
  122. ;
  123. BD300:    EQU    128        ;300 bps
  124. BD600:    EQU    64        ;600 bps  (not supported by Smartmodem)
  125. BD1200:    EQU    32        ;1200 bps
  126. ;
  127.      ENDIF    ;CTC
  128. ;
  129.      IF    KAYPRO
  130. ;
  131. ; 8116 (on Kaypros at least) is initialized by system on cold boot,
  132. ; only need to set baud rate as single command to baud rate port.
  133. ;
  134. BD110:    EQU    02H
  135. BD300:    EQU    05H
  136. BD600:    EQU    06H
  137. BD1200:    EQU    07H
  138. BD2400:    EQU    0AH    ;2400 - 19.2 K baud values
  139. BD4800:    EQU    0CH    ;not currently supported, but could be
  140. BD9600:    EQU    0EH    ;used on a high speed link so are
  141. BD19K:    EQU    0FH    ;included for informational purposes
  142. ;
  143.      ENDIF    ;KAYPRO
  144. ;
  145.      IF    C8116 AND NOT KAYPRO
  146. ;
  147. BD110:    EQU    02H    
  148. BD300:    EQU    05H    ;you may have to change these if you're not
  149. BD600:    EQU    06H    ;on a Kaypro system
  150. BD1200:    EQU    07H
  151. ;
  152.      ENDIF
  153. ;
  154. ;***********************************************************************
  155. ;
  156. ; If any of your routines zap anything other than the Accumulator, then
  157. ; you must preserve all other registers.
  158. ;
  159. ;***********************************************************************
  160. ;
  161. ; This routine should turn off everything on the modem, hang it up, and
  162. ; get it ready to wait for a ring. (DTR off)
  163. ;
  164. MDINIT:
  165.     MVI    A,RESCHN    ;Reset channel (DTR, RTS off)
  166.     OUT    SPORT
  167.     MVI    A,4        ;Setup to write register 4
  168.     OUT    SPORT
  169.     MVI    A,WRREG4    ;set 16x clock, 1 stop bit, no parity
  170.     OUT    SPORT
  171.     MVI    A,1        ;Setup to write register 1
  172.     OUT    SPORT
  173.     MVI    A,WRREG1    ;set no interrupts
  174.     OUT    SPORT
  175.     MVI    A,3        ;Setup to write register 3
  176.     OUT    SPORT
  177.     MVI    A,WRREG3    ;set Rx 8 bits, enable recv
  178.     OUT    SPORT
  179.     MVI    A,5        ;Setup to write register 5
  180.     OUT    SPORT
  181.     MVI    A,DTROFF    ;leave DTR OFF initially
  182.     OUT    SPORT
  183.     RET            ;Return
  184. ;.....
  185. ;
  186. ; This routine will check the Ring Indicator status,
  187. ; returning a non-zero value if the RI line is active.
  188. ; (This routine is only valid for DARTs or modified SIOs,
  189. ; see notes above.)
  190. ;
  191.      IF    DART    ;Only DARTs or modified SIOs can do this
  192. ;
  193. MDRING:
  194.     IN    SPORT
  195.     ANI    RI
  196.     RET
  197. ;
  198.      ENDIF    ;DART
  199. ;.....
  200. ;
  201. ;
  202. ; The following routine will raise DTR. (and RTS)
  203. ;
  204. MDANSW:
  205.     MVI    A,5        ;address WR5
  206.     OUT    SPORT
  207.     MVI    A,DTRON        ;raise DTR, RTS
  208.     OUT    SPORT
  209.     RET            ;Return
  210. ;
  211. ;
  212. ; The following routine checks to make sure we still have carrier.  If
  213. ; there is no carrier, it will return with the Zero flag set.
  214. ;
  215. MDCARCK:
  216.     MVI    A,RESSTA    ;Reset status
  217.     OUT    SPORT
  218.     IN    SPORT        ;Get status
  219.     ANI    DCD        ;Check for data carrier
  220.     RET            ;Return
  221. ;
  222. ;
  223. ; The following routine determines if there is a character waiting to
  224. ; be received.  If no character is waiting, the Zero flag will be set,
  225. ; otherwise, 255 will be returned in register A. (Error conditions are
  226. ; checked, and, if present, the character is ignored.)
  227. ;
  228. MDINST:
  229.     IN    SPORT        ;Get status
  230.     ANI    DAV        ;Got a character?
  231.     RZ            ;Return if none
  232.     MVI    A,1        ;else, check error bits
  233.     OUT    SPORT        ;(address RR1)
  234.     IN    SPORT        ;read RR1
  235.     ANI    ERR        ;mask error bits
  236.     JZ    MDINST1        ;no error, ok
  237.     MVI    A,RESERR    ;else, reset error bits
  238.     OUT    SPORT
  239.     IN    DPORT        ;clear out garbage
  240.     XRA    A        ;say no data
  241.     RET            ;and return
  242. MDINST1:
  243.     ORI    0FFH        ;say we got one
  244.     RET            ;...and return
  245. ;.....
  246. ;
  247. ;
  248. ; The following is a routine that will input one character from the
  249. ; modem port.  If there is nothing there, it will return garbage... so
  250. ; use the MDINST routine first.
  251. ;
  252. MDINP:
  253.     IN    DPORT        ;Get character
  254.     ANI    7FH        ;Strip parity
  255.     RET            ;Return
  256. ;.....
  257. ;
  258. ;
  259. ; The following is a routine to determine if the transmit buffer is
  260. ; empty.  If it is empty, it will return with the Zero flag clear.  If
  261. ; the transmitter is busy, then it will return with the Zero flag set.
  262. ;
  263. MDOUTST:
  264.     IN    SPORT
  265.     ANI    TBMT        ;Mask it
  266.     RET            ;Return
  267. ;.....
  268. ;
  269. ;
  270. ; The following is a routine that will output one character in register
  271. ; A to the modem.  REMEMBER, that is register A, not register C.
  272. ;
  273. ; **** Use MDOUTST first to see if buffer is empty ****
  274. ;
  275. MDOUTP:
  276.     OUT    DPORT        ;Send it
  277.     RET            ;Return
  278. ;.....
  279. ;
  280. ;
  281. ; These next routines set the proper baud rates for the modem.  If you
  282. ; do not support the particular rate, then simply put the label in front
  283. ; of the ORI 0FFH / RET. If the baud rate change was successful, make
  284. ; SURE the Zero flag is set (XRA A).
  285. ;
  286.      IF    CTC
  287. ;
  288. SET300:
  289.     MVI    A,BDCMD1    ;Get first byte of command
  290.     OUT    BPORT        ;send it
  291.     MVI    A,BD300        ;Load rate
  292.     JMP    SETBAUD
  293. ;
  294. SET1200:
  295.     MVI    A,BDCMD2    ;Get first byte of command
  296.     OUT    BPORT        ;send it
  297.     MVI    A,BD1200    ;Load rate
  298. ;
  299. SETBAUD:
  300.     OUT    BPORT        ;Send 2nd byte of command (rate)
  301.     XRA    A        ;Say rate is OK
  302.     RET            ;Return
  303. ;
  304. ; The following routine returns a 255 because we were not able to set to
  305. ; the proper baud rate because either the serial port or the modem can't
  306. ; handle it.
  307. ;
  308. SET110:
  309. SET450:
  310. SET600:
  311. SET710:
  312.     ORI    0FFH        ;Make sure zero flag is not set
  313.     RET            ;Return
  314. ;
  315.      ENDIF    ;CTC
  316. ;.....
  317. ;
  318. ;
  319.      IF    C8116
  320. ;
  321. SET110:
  322.     MVI    A,BD110
  323.     JMP    SETBAUD
  324. ;
  325. SET300:
  326.     MVI    A,BD300
  327.     JMP    SETBAUD
  328. ;
  329. SET600:
  330.     MVI    A,BD600
  331.     JMP    SETBAUD
  332. ;
  333. SET1200:
  334.     MVI    A,BD1200
  335. ;
  336. SETBAUD:
  337.     OUT    BPORT        ;set baud rate
  338.     XRA    A        ;say rate ok
  339.     RET            ;and return
  340. ;
  341. ; The following rates, (450 & 710), are not supported for the 8116/SIO
  342. ;
  343. SET450:
  344. SET710:
  345.     ORI    0FFH        ;say rate ng
  346.     RET
  347. ;
  348.      ENDIF    ;C8116
  349. ;.....
  350. ;
  351. ; Ok, that's all of the modem dependent routines that MBYE uses, so if
  352. ; you patch this file into your copy of MBYE, then it should work out
  353. ; well. (Be sure to set the SMODEM and SM1200 equates in the main program
  354. ; section to indicate if you are using a Hayes Smartmodem or compatible
  355. ; or not.)
  356. ;
  357. ;***********************************************************************
  358. ;
  359.