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