-
Notifications
You must be signed in to change notification settings - Fork 82
/
serial2.1
306 lines (306 loc) · 6.11 KB
/
serial2.1
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
.PAG 'SERIAL ROUTINES'
;COMMAND SERIAL BUS DEVICE TO TALK
;
TALK ORA #$40 ;MAKE A TALK ADR
.BYT $2C ;SKIP TWO BYTES
.SKI 5
;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
JSR DATAHI
CMP #$3F ;CLKHI ONLY ON UNLISTEN
BNE LIST5
JSR CLKHI
;
LIST5 LDA D1ORA ;ASSERT ATTENTION
ORA #$80
STA D1ORA
;
.SKI 5
ISOURA
JSR CLKLO ;SET CLOCK LINE LOW
JSR DATAHI
JSR W1MS ;DELAY 1 MS
.SKI 5
ISOUR SEI ;NO IRQ'S ALLOWED
JSR DATAHI ;MAKE SURE DATA IS RELEASED
JSR DEBPIA ;DATA SHOULD BE LOW
LSR A
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
LSR A
BCC ISR02
;
ISR03 JSR DEBPIA ;WAIT FOR DATA TO GO LOW
LSR A
BCS ISR03
;
NOEOI JSR DEBPIA ;WAIT FOR DATA HIGH
LSR A
BCC NOEOI
JSR CLKLO ;SET CLOCK LOW
;
; SET TO SEND DATA
;
LDA #$08 ;COUNT 8 BITS
STA COUNT
;
ISR01
LDA D1ORA ;DEBOUNCE THE BUS
CMP D1ORA
BNE ISR01
LSR A
LSR A
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 D2PCR
AND #%11011111 ;DATA HIGH
ORA #$02 ;CLOCK LOW
STA D2PCR
DEC COUNT
BNE ISR01
LDA #$04 ;SET TIMER FOR 1MS
STA D2T2H
ISR04 LDA D2IFR
AND #$20
BNE FRMERR
JSR DEBPIA
LSR A
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 5
;SEND SECONDARY ADDRESS AFTER LISTEN
;
SECND STA BSOUR ;BUFFER CHARACTER
JSR ISOURA ;SEND IT
.SKI 5
;RELEASE ATTENTION AFTER LISTEN
;
SCATN LDA D1ORA
AND #$7F
STA D1ORA ;RELEASE ATTENTION
RTS
.SKI 5
;TALK SECOND ADDRESS
;
TKSA STA BSOUR ;BUFFER CHARACTER
JSR ISOURA ;SEND SECOND ADDR
.SKI 5
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
BCS TKATN1
CLI ;IRQ'S OKAY NOW
RTS
.SKI 5
;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 5
;SEND UNTALK COMMAND ON SERIAL BUS
;
UNTLK JSR CLKLO
LDA D1ORA ;PULL ATN
ORA #$80
STA D1ORA
LDA #$5F ;UNTALK COMMAND
.BYT $2C ;SKIP TWO BYTES
.SKI 5
;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 #11
DLAD00 DEX
BNE DLAD00
TAX
JSR CLKHI
JMP DATAHI
.SKI 5
;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
BCC ACP00A
JSR DATAHI ;DATA LINE HIGH
;
EOIACP LDA #$01 ;SET TIMER 2 FOR 256US
STA D2T2H
ACP00 LDA D2IFR
AND #$20 ;CHECK THE TIMER
BNE ACP00B ;RAN OUT.....
JSR DEBPIA ;CHECK THE CLOCK LINE
BCS ACP00 ;NO NOT YET
BCC 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 DLADLH ;DELAY AND THEN SET DATAHI (ALSO CLKHI)
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 D1ORA ;WAIT FOR CLOCK HIGH
CMP D1ORA ;DEBOUNCE
BNE ACP03
LSR A
BCC ACP03
LSR A ;PUT DATA BIT INTO CARRY
ROR BSOUR1 ;ROTATE DATA IN
;
ACP03A LDA D1ORA ;WAIT FOR CLOCK LOW
CMP D1ORA ;DEBOUNCE
BNE ACP03A
LSR A
BCS ACP03A
DEC COUNT
BNE ACP03 ;MORE BITS.....
;...EXIT...
JSR DATALO ;DATA LOW
LDA STATUS ;CHECK FOR EOI
BEQ 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 D2PCR
AND #%11111101
STA D2PCR
RTS
;
CLKLO ;SET CLOCK LINE LOW (INVERTED)
LDA D2PCR
ORA #$02
STA D2PCR
RTS
AROUND =*
;
; MOVED BECAUSE OF NEEDED PATCH SPACE
;
*=$E4A0 ;PATCH AREA
DATAHI ;SET DATA LINE HIGH (INVERTED)
LDA D2PCR
AND #%11011111
STA D2PCR
RTS
;
DATALO ;SET DATA LINE LOW (INVERTED)
LDA D2PCR
ORA #$20
STA D2PCR
RTS
;
DEBPIA LDA D1ORA ;DEBPUNCE THE PIA
CMP D1ORA
BNE DEBPIA
LSR A ;SHIFT THE CLOCK BIT INTO THE CARRY
RTS
KSP2 =* ;KERNAL SPACE FOR PATCH 2
*=AROUND
W1MS ;DELAY 1MS USING TIMER 2
LDA #$04
STA D2T2H
W1MS1 ;TIMER WAIT LOOP
LDA D2IFR
AND #$20
BEQ W1MS1
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
;******************************