You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

serial4.0 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. .PAG 'SERIAL ROUTINES'
  2. ;COMMAND SERIAL BUS DEVICE TO TALK
  3. ;
  4. TALK ORA #$40 ;MAKE A TALK ADR
  5. .BYT $2C ;SKIP TWO BYTES
  6. .SKI 3
  7. ;COMMAND SERIAL BUS DEVICE TO LISTEN
  8. ;
  9. LISTN ORA #$20 ;MAKE A LISTEN ADR
  10. JSR RSP232 ;PROTECT SELF FROM RS232 NMI'S
  11. LIST1 PHA
  12. ;
  13. ;
  14. BIT C3P0 ;CHARACTER LEFT IN BUF?
  15. BPL LIST2 ;NO...
  16. ;
  17. ;SEND BUFFERED CHARACTER
  18. ;
  19. SEC ;SET EOI FLAG
  20. ROR R2D2
  21. ;
  22. JSR ISOUR ;SEND LAST CHARACTER
  23. ;
  24. LSR C3P0 ;BUFFER CLEAR FLAG
  25. LSR R2D2 ;CLEAR EOI FLAG
  26. ;
  27. ;
  28. LIST2 PLA ;TALK/LISTEN ADDRESS
  29. STA BSOUR
  30. SEI
  31. JSR DATAHI
  32. CMP #$3F ;CLKHI ONLY ON UNLISTEN
  33. BNE LIST5
  34. JSR CLKHI
  35. ;
  36. LIST5 LDA D2PRA ;ASSERT ATTENTION
  37. ORA #$08
  38. STA D2PRA
  39. ;
  40. .SKI 3
  41. ISOURA SEI
  42. JSR CLKLO ;SET CLOCK LINE LOW
  43. JSR DATAHI
  44. JSR W1MS ;DELAY 1 MS
  45. .SKI 3
  46. ISOUR SEI ;NO IRQ'S ALLOWED
  47. JSR DATAHI ;MAKE SURE DATA IS RELEASED
  48. JSR DEBPIA ;DATA SHOULD BE LOW
  49. BCS NODEV
  50. JSR CLKHI ;CLOCK LINE HIGH
  51. BIT R2D2 ;EOI FLAG TEST
  52. BPL NOEOI
  53. ; DO THE EOI
  54. ISR02 JSR DEBPIA ;WAIT FOR DATA TO GO HIGH
  55. BCC ISR02
  56. ;
  57. ISR03 JSR DEBPIA ;WAIT FOR DATA TO GO LOW
  58. BCS ISR03
  59. ;
  60. NOEOI JSR DEBPIA ;WAIT FOR DATA HIGH
  61. BCC NOEOI
  62. JSR CLKLO ;SET CLOCK LOW
  63. ;
  64. ; SET TO SEND DATA
  65. ;
  66. LDA #$08 ;COUNT 8 BITS
  67. STA COUNT
  68. ;
  69. ISR01
  70. LDA D2PRA ;DEBOUNCE THE BUS
  71. CMP D2PRA
  72. BNE ISR01
  73. ASL A ;SET THE FLAGS
  74. BCC FRMERR ;DATA MUST BE HI
  75. ;
  76. ROR BSOUR ;NEXT BIT INTO CARRY
  77. BCS ISRHI
  78. JSR DATALO
  79. BNE ISRCLK
  80. ISRHI JSR DATAHI
  81. ISRCLK JSR CLKHI ;CLOCK HI
  82. NOP
  83. NOP
  84. NOP
  85. NOP
  86. LDA D2PRA
  87. AND #$FF-$20 ;DATA HIGH
  88. ORA #$10 ;CLOCK LOW
  89. STA D2PRA
  90. DEC COUNT
  91. BNE ISR01
  92. LDA #$04 ;SET TIMER FOR 1MS
  93. STA D1T2H
  94. LDA #TIMRB ;TRIGGER TIMER
  95. STA D1CRB
  96. LDA D1ICR ;CLEAR THE TIMER FLAGS<<<<<<<<<<<<<
  97. ISR04 LDA D1ICR
  98. AND #$02
  99. BNE FRMERR
  100. JSR DEBPIA
  101. BCS ISR04
  102. CLI ;LET IRQ'S CONTINUE
  103. RTS
  104. ;
  105. NODEV ;DEVICE NOT PRESENT ERROR
  106. LDA #$80
  107. .BYT $2C
  108. FRMERR ;FRAMING ERROR
  109. LDA #$03
  110. CSBERR JSR UDST ;COMMODORE SERIAL BUSS ERROR ENTRY
  111. CLI ;IRQ'S WERE OFF...TURN ON
  112. CLC ;MAKE SURE NO KERNAL ERROR RETURNED
  113. BCC DLABYE ;TURN ATN OFF ,RELEASE ALL LINES
  114. ;
  115. .SKI 3
  116. ;SEND SECONDARY ADDRESS AFTER LISTEN
  117. ;
  118. SECND STA BSOUR ;BUFFER CHARACTER
  119. JSR ISOURA ;SEND IT
  120. .SKI 3
  121. ;RELEASE ATTENTION AFTER LISTEN
  122. ;
  123. SCATN LDA D2PRA
  124. AND #$FF-$08
  125. STA D2PRA ;RELEASE ATTENTION
  126. RTS
  127. .SKI 3
  128. ;TALK SECOND ADDRESS
  129. ;
  130. TKSA STA BSOUR ;BUFFER CHARACTER
  131. JSR ISOURA ;SEND SECOND ADDR
  132. .SKI 3
  133. TKATN ;SHIFT OVER TO LISTENER
  134. SEI ;NO IRQ'S HERE
  135. JSR DATALO ;DATA LINE LOW
  136. JSR SCATN
  137. JSR CLKHI ;CLOCK LINE HIGH JSR/RTS
  138. TKATN1 JSR DEBPIA ;WAIT FOR CLOCK TO GO LOW
  139. BMI TKATN1
  140. CLI ;IRQ'S OKAY NOW
  141. RTS
  142. .SKI 3
  143. ;BUFFERED OUTPUT TO SERIAL BUS
  144. ;
  145. CIOUT BIT C3P0 ;BUFFERED CHAR?
  146. BMI CI2 ;YES...SEND LAST
  147. ;
  148. SEC ;NO...
  149. ROR C3P0 ;SET BUFFERED CHAR FLAG
  150. BNE CI4 ;BRANCH ALWAYS
  151. ;
  152. CI2 PHA ;SAVE CURRENT CHAR
  153. JSR ISOUR ;SEND LAST CHAR
  154. PLA ;RESTORE CURRENT CHAR
  155. CI4 STA BSOUR ;BUFFER CURRENT CHAR
  156. CLC ;CARRY-GOOD EXIT
  157. RTS
  158. .SKI 3
  159. ;SEND UNTALK COMMAND ON SERIAL BUS
  160. ;
  161. UNTLK SEI
  162. JSR CLKLO
  163. LDA D2PRA ;PULL ATN
  164. ORA #$08
  165. STA D2PRA
  166. LDA #$5F ;UNTALK COMMAND
  167. .BYT $2C ;SKIP TWO BYTES
  168. .SKI 3
  169. ;SEND UNLISTEN COMMAND ON SERIAL BUS
  170. ;
  171. UNLSN LDA #$3F ;UNLISTEN COMMAND
  172. JSR LIST1 ;SEND IT
  173. ;
  174. ; RELEASE ALL LINES
  175. DLABYE JSR SCATN ;ALWAYS RELEASE ATN
  176. ; DELAY THEN RELEASE CLOCK AND DATA
  177. ;
  178. DLADLH TXA ;DELAY APPROX 60 US
  179. LDX #10
  180. DLAD00 DEX
  181. BNE DLAD00
  182. TAX
  183. JSR CLKHI
  184. JMP DATAHI
  185. .SKI 3
  186. ;INPUT A BYTE FROM SERIAL BUS
  187. ;
  188. ACPTR
  189. SEI ;NO IRQ ALLOWED
  190. LDA #$00 ;SET EOI/ERROR FLAG
  191. STA COUNT
  192. JSR CLKHI ;MAKE SURE CLOCK LINE IS RELEASED
  193. ACP00A JSR DEBPIA ;WAIT FOR CLOCK HIGH
  194. BPL ACP00A
  195. ;
  196. EOIACP
  197. LDA #$01 ;SET TIMER 2 FOR 256US
  198. STA D1T2H
  199. LDA #TIMRB
  200. STA D1CRB
  201. JSR DATAHI ;DATA LINE HIGH (MAKES TIMMING MORE LIKE VIC-20
  202. LDA D1ICR ;CLEAR THE TIMER FLAGS<<<<<<<<<<<<
  203. ACP00 LDA D1ICR
  204. AND #$02 ;CHECK THE TIMER
  205. BNE ACP00B ;RAN OUT.....
  206. JSR DEBPIA ;CHECK THE CLOCK LINE
  207. BMI ACP00 ;NO NOT YET
  208. BPL ACP01 ;YES.....
  209. ;
  210. ACP00B LDA COUNT ;CHECK FOR ERROR (TWICE THRU TIMEOUTS)
  211. BEQ ACP00C
  212. LDA #2
  213. JMP CSBERR ; ST = 2 READ TIMEOUT
  214. ;
  215. ; TIMER RAN OUT DO AN EOI THING
  216. ;
  217. ACP00C JSR DATALO ;DATA LINE LOW
  218. JSR CLKHI ; DELAY AND THEN SET DATAHI (FIX FOR 40US C64)
  219. LDA #$40
  220. JSR UDST ;OR AN EOI BIT INTO STATUS
  221. INC COUNT ;GO AROUND AGAIN FOR ERROR CHECK ON EOI
  222. BNE EOIACP
  223. ;
  224. ; DO THE BYTE TRANSFER
  225. ;
  226. ACP01 LDA #08 ;SET UP COUNTER
  227. STA COUNT
  228. ;
  229. ACP03 LDA D2PRA ;WAIT FOR CLOCK HIGH
  230. CMP D2PRA ;DEBOUNCE
  231. BNE ACP03
  232. ASL A ;SHIFT DATA INTO CARRY
  233. BPL ACP03 ;CLOCK STILL LOW...
  234. ROR BSOUR1 ;ROTATE DATA IN
  235. ;
  236. ACP03A LDA D2PRA ;WAIT FOR CLOCK LOW
  237. CMP D2PRA ;DEBOUNCE
  238. BNE ACP03A
  239. ASL A
  240. BMI ACP03A
  241. DEC COUNT
  242. BNE ACP03 ;MORE BITS.....
  243. ;...EXIT...
  244. JSR DATALO ;DATA LOW
  245. BIT STATUS ;CHECK FOR EOI
  246. BVC ACP04 ;NONE...
  247. ;
  248. JSR DLADLH ;DELAY THEN SET DATA HIGH
  249. ;
  250. ACP04 LDA BSOUR1
  251. CLI ;IRQ IS OK
  252. CLC ;GOOD EXIT
  253. RTS
  254. ;
  255. CLKHI ;SET CLOCK LINE HIGH (INVERTED)
  256. LDA D2PRA
  257. AND #$FF-$10
  258. STA D2PRA
  259. RTS
  260. ;
  261. CLKLO ;SET CLOCK LINE LOW (INVERTED)
  262. LDA D2PRA
  263. ORA #$10
  264. STA D2PRA
  265. RTS
  266. ;
  267. ;
  268. DATAHI ;SET DATA LINE HIGH (INVERTED)
  269. LDA D2PRA
  270. AND #$FF-$20
  271. STA D2PRA
  272. RTS
  273. ;
  274. DATALO ;SET DATA LINE LOW (INVERTED)
  275. LDA D2PRA
  276. ORA #$20
  277. STA D2PRA
  278. RTS
  279. ;
  280. DEBPIA LDA D2PRA ;DEBOUNCE THE PIA
  281. CMP D2PRA
  282. BNE DEBPIA
  283. ASL A ;SHIFT THE DATA BIT INTO THE CARRY...
  284. RTS ;...AND THE CLOCK INTO NEG FLAG
  285. ;
  286. W1MS ;DELAY 1MS USING LOOP
  287. TXA ;SAVE .X
  288. LDX #200-16 ;1000US-(1000/500*8=#40US HOLDS)
  289. W1MS1 DEX ;5US LOOP
  290. BNE W1MS1
  291. TAX ;RESTORE .X
  292. RTS
  293. .END
  294. ;*******************************
  295. ;WRITTEN 8/11/80 BOB FAIRBAIRN
  296. ;TEST SERIAL0.6 8/12/80 RJF
  297. ;CHANGE I/O STRUCTURE 8/21/80 RJF
  298. ;MORE I/O CHANGES 8/24/80 RJF
  299. ;FINAL RELEASE INTO KERNAL 8/26/80 RJF
  300. ;SOME CLEAN UP 9/8/80 RSR
  301. ;ADD IRQ PROTECT ON ISOUR AND TKATN 9/22/80 RSR
  302. ;FIX UNTALK 10/7/80 RSR
  303. ;MODIFY FOR VIC-40 I/O SYSTEM 12/08/81 RSR
  304. ;ADD SEI TO (UNTLK,ISOURA,LIST2) 12/14/81 RSR
  305. ;MODIFY FOR 6526 FLAGS FIX ERRS 12/31/81 RSR
  306. ;MODIFY FOR COMMODORE 64 I/O 3/11/82 RSR
  307. ;CHANGE ACPTR EOI FOR BETTER RESPONSE 3/28/82 RSR
  308. ;CHANGE WAIT 1 MS ROUTINE FOR LESS CODE 4/8/82 RSR
  309. ;******************************
  310. .END