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 / MBTRS3-2.ASM < prev    next >
Assembly Source File  |  2000-06-30  |  7KB  |  212 lines

  1. ;***********************************************************************
  2. ;
  3. ;             MBYE (Modular 'BYE')
  4. ;          TRS-80 Model III UART I/O routines
  5. ;            v2.0 (02/19/84) by Kim Levitt
  6. ;
  7. ;    These routines will allow the easy patching of MBYE for any 
  8. ; type of modem/serial port combination.  Certain routines must return
  9. ; status flags, so please be careful to set the flags as directed.
  10. ;
  11. ; NOTE: The TRS-80 Model III uses the Western Digital TR1602 UART along
  12. ; with some additional circuts and latches used to interface it to the
  13. ; RS-232C port. The modem status port addresses a set of latches which
  14. ; are apparently reset when any data is output to this port, at which
  15. ; point a master reset also occurs on the UART, causing DTR to go off,
  16. ; the recv/xmit holding registers to be cleared, etc. There is no way
  17. ; I know of to reset the modem status latches WITHOUT ALSO resetting the
  18. ; UART, and the latches do not reset automatically when the line they
  19. ; are monitoring goes off. This means the carrier can be detected going
  20. ; ON after a disconnect, (during which a UART reset is done), but it
  21. ; CANNOT DETECT CARRIER LOSS DURING MODEM I/O (because the UART cannot
  22. ; be repeatedly reset during I/O to reset those blasted modem status
  23. ; latches...) WHAT THIS MEANS IS: You MUST set TIMEOUT EQU YES, other-
  24. ; wise, if someone hangs up without saying BYE, the system will never
  25. ; reset for a new caller... (With the timeout set, it will recover after
  26. ; the timeout, which could be several minutes, so set the timeout for
  27. ; 2 or 3 minutes maximum...)
  28. ;
  29. ;-----------------------------------------------------------------------
  30. ;
  31. ; 02/17/84  Fixed some glaring bugs/deficiencies, added
  32. ;        important note re: TRS modem status latches - Kim Levitt
  33. ; 02/07/84  Altered and renamed to work with MBYE    - Kim Levitt
  34. ; 11/27/83  Altered and renamed to work with BYE3.    - Irv Hoff
  35. ; 08/08/83  Routines added, no fuss, mess, or frills.    - Paul Traina
  36. ;
  37. ;-----------------------------------------------------------------------
  38. ;
  39. ; Port addresses:
  40. ;
  41. MSPORT:    EQU    0E8H        ;modem status/uart reset port    
  42. BPORT:    EQU    0E9H        ;baud rate port
  43. SPORT:    EQU    0EAH        ;uart status port
  44. CPORT:    EQU    0EAH        ;uart control port
  45. DPORT:    EQU    0EBH        ;data I/O port
  46. ;
  47. ; MSPORT modem status port masks:
  48. ;
  49. RI:    EQU    00010000b    ;ring indicator
  50. DCD:    EQU    00100000b    ;data carrier detect
  51. DSR:    EQU    01000000b    ;data set ready
  52. CTS:    EQU    10000000b    ;clear to send
  53. ;
  54. ; MSPORT command:
  55. ;
  56. RESET:    EQU    00000010b    ;UART/modem status reset cmd
  57. ;
  58. ; SPORT status port masks:
  59. ;
  60. TBMT:    EQU    01000000b    ;xmit buffer empty
  61. DAV:    EQU    10000000b    ;data available
  62. ;
  63. PE:    EQU    00001000b    ;parity error
  64. FE:    EQU    00010000b    ;framing error
  65. OE:    EQU    00100000b    ;overrun error
  66. ERR:    EQU    PE+FE+OE    ;error bits
  67. ;
  68. ; CPORT control port commands:
  69. ;
  70. CBASE:    EQU    01101100b    ;everything on, 8 no 1, no dtr or rts
  71. DTR:    EQU    00000010b    ;data terminal ready
  72. RTS:    EQU    00000001b    ;request to send
  73. ;
  74. ; BPORT Baud rate values:
  75. ;
  76. BD110:    EQU    22H        ;110 baud
  77. BD300:    EQU    55H        ;300 baud
  78. BD600:    EQU    66H        ;600 baud
  79. BD1200:    EQU    77H        ;1200 baud
  80. ;
  81. ;***********************************************************************
  82. ;
  83. ; If any of your routines zaps anything other than the Accumulator,
  84. ; then you must preserve all other registers.
  85. ;
  86. ;***********************************************************************
  87. ;
  88. ; This routine should turn off everything on the modem,  but set baud-
  89. ; rate to 300 bps, and get it ready to wait for a ring.  (Also hang it
  90. ; up)
  91. ;
  92. MDINIT:
  93.     MVI    A,RESET        ;reset uart, enable modem control
  94.     OUT    MSPORT
  95.     MVI    A,CBASE        ;Xmit on, Recv on, DTR off, RTS off  
  96.     OUT    CPORT
  97.     RET
  98. ;
  99. ; The following is a routine to determine if there is a character wait-
  100. ; ing to be received.  If there are none, the Zero flag will be set,
  101. ; otherwise, 0FFH will be returned in register 'A'.  Remember that the
  102. ; system will like you a little more if you also mask out framing, par-
  103. ; ity, and overrun errors.
  104. ;
  105. MDINST:
  106.     IN    SPORT        ;Get status
  107.     ANI    DAV        ;Got a character?
  108.     RZ            ;return now if none
  109.     ORI    0FFH        ;else say we got one
  110.     RET            ;...and return
  111. ;
  112. ; The following is a routine to determine if the transmit buffer is em-
  113. ; pty.  If empty, it will return with the Zero flag clear.  If not, it
  114. ; will return with the Zero flag set.
  115. ;
  116. MDOUTST:
  117.     IN    SPORT        ;read port
  118.     ANI    TBMT        ;mask crap
  119.     RET
  120. ;
  121. ; The following is a routine that will check to make sure we still have
  122. ; carrier.  If no carrier, it will return with the Zero flag set.
  123. ; (Actually, on the TRS-80 Model III, it will only detect carrier coming
  124. ; on in the initial wait for carrier routine, thereafter it will always
  125. ; return NZ until MDINIT or MDRING is called to reset the modem status
  126. ; latches.) (See lengthy note at beginning of program.)
  127. ;
  128. MDCARCK:
  129.     IN    MSPORT        ;read modem status port
  130.     ANI    DCD        ;mask carrier detect
  131.     RET
  132. ;
  133. ; The following routine will check to see if the phone is ringing, if it
  134. ; isn't, it will return with Zero set, otherwise Zero will be cleared.
  135. ;
  136. MDRING:
  137.     MVI    A,RESET        ;reset modem status latches
  138.     OUT    MSPORT        ;to get current status
  139.     NOP ! NOP ! NOP ! NOP    ;pause (allow latch to set)
  140.     IN    MSPORT        ;read modem status port
  141.     ANI    RI        ;check if RI on..
  142.     RET
  143. ;
  144. ; The following is a routine that will input one character from the mo-
  145. ; dem port.  If there is nothing there, it will return garbage... so use
  146. ; the MDINST routine first.
  147. ;
  148. MDINP:
  149.     IN    DPORT        ;get character
  150.     ANI    7FH        ;strip parity and other garbage
  151.     RET
  152. ;
  153. ; The following is a routine that will output one character in reg. 'A'
  154. ; to the modem.  REMEMBER, that is reg. 'A', not reg. 'C'.
  155. ;
  156. ; ** Use MDOUTST first to see if buffer is empty **
  157. ;
  158. MDOUTP:
  159.     OUT    DPORT        ;send it
  160.     RET
  161. ;
  162. ; The following routine will make the modem answer the phone.
  163. ; (Raises DTR and RTS.)
  164. ;
  165. MDANSW:
  166.     MVI    A,CBASE+DTR+RTS    ;turn on DTR and RTS which will allow
  167.     OUT    CPORT        ;..the modem to answer on next ring
  168.     RET
  169. ;
  170. ;
  171. ;***********************************************************************
  172. ;
  173. ; These next routines set the proper baud rates for the modem.  If you
  174. ; do not support the particular rate, then simply set the appropriate
  175. ; equates in the main program.
  176. ;
  177. SET110:
  178.     MVI    A,BD110
  179.     JMP    SETBAUD
  180. ;
  181. SET300:
  182.     MVI    A,BD300
  183.     JMP    SETBAUD
  184. ;
  185. SET600:
  186.     MVI    A,BD600
  187.     JMP    SETBAUD
  188. ;
  189. SET1200:
  190.     MVI    A,BD1200
  191. ;
  192. SETBAUD:
  193.     OUT    BPORT        ;set baud rate
  194.     XRA    A        ;say rate ok
  195.     RET            ;and return
  196. ;
  197. ; The following rates, (450 & 710), are not supported for the Model III
  198. ;
  199. SET450:
  200. SET710:
  201.     ORI    0FFH        ;say rate ng
  202.     RET            ;and return
  203. ;
  204. ;**********************************************************************
  205. ;
  206. ; Ok, that's all of the modem dependent routines that MBYE uses, so if
  207. ; you patch this file into your copy of MBYE, then it should work out
  208. ; well.
  209. ;
  210. ;**********************************************************************
  211. ;
  212.