annotate level1/modules/dw4read.asm @ 2743:b44abaa5da88

Found that the lib folder was not being processed. Corrected issue.
author drencor-xeen
date Tue, 08 Jan 2013 14:01:56 -0600
parents d1976224b314
children 28ed72477814
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2741
d1976224b314 Found duplicated code and IFNE H6309-1 statements in dwwrite.asm. Verified it was duplicated code. Must have been accidently copied at some point. Removed second copy of this IFNE H6309-1.
drencor-xeen
parents: 2602
diff changeset
1 IFNE H6309
2576
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
2
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
3 *******************************************************
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
4 *
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
5 * DWRead - 6309 native Turbo Edition 115k / 230k
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
6 * Receive a response from the DriveWire server.
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
7 * Times out if no data received within 1.3 (0.66) seconds.
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
8 *
2743
b44abaa5da88 Found that the lib folder was not being processed. Corrected issue.
drencor-xeen
parents: 2741
diff changeset
9 * THIS VERSION REQUIRES ONE OR MORE SYNC BYTES
2576
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
10 * WHERE THE THE FINAL SYNC BYTE IS $C0 AND ANY
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
11 * PRECEDING SYNC BYTES ARE $FF.
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
12 *
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
13 * THE DATA BYTES MUST BE TRANSMITTED IN REVERSE
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
14 * BIT ORDER (MOST-SIGNIFICANT FIRST).
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
15 *
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
16 * Serial data format: 8-N-2 (TWO STOP BITS MANDATORY)
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
17 *
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
18 * Entry:
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
19 * X = storage address for incoming data
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
20 * Y = number of bytes requested
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
21 *
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
22 * Exit:
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
23 * CC = Z set on success, cleared on timeout
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
24 * Y = checksum
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
25 * U is preserved
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
26 * All others clobbered
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
27 *
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
28 BBIN equ $FF22 ; bit banger input port
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
29
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
30 DWRead clra ; ACCA = 0, clear Carry
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
31 pshs u,dp,a,cc ; save registers (A allocates space for status)
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
32 orcc #$50 ; mask interrupts
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
33 deca ; select hardware page..
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
34 tfr a,dp ; ..as the direct page
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
35 ldu #BBIN ; point U at input port
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
36 tfr y,w ; W = request count
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
37 leay ,x ; Y = storage ptr
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
38 ldx #0 ; initialize timeout counter
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
39 stx <$FF92 ; disable GIME interrupts
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
40 ldd <$FF92 ; clear spurious interrupts
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
41
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
42 * Turn off PIA interrupt sources except for the CD input pin.
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
43 lda <$FF01 ; save PIA 0 controls on the stack
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
44 ldb <$FF03
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
45 pshs d
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
46 andd #$FCFC ; clear IRQ enables
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
47 sta <$FF01 ; set new control state for PIA 0
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
48 stb <$FF03
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
49 lda <$FF00 ; ensure that IRQ outputs are cleared
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
50 ldb <$FF02
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
51 lda <$FF21 ; save PIA 1 controls on the stack
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
52 ldb <$FF23
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
53 pshs d
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
54 andd #$FCFC ; clear FIRQ enables
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
55 inca ; set CD FIRQ enable
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
56 sta <$FF21 ; set new control state for PIA 1
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
57 stb <$FF23
2743
b44abaa5da88 Found that the lib folder was not being processed. Corrected issue.
drencor-xeen
parents: 2741
diff changeset
58
2576
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
59 * Wait for Sync Byte(s) or Timeout
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
60 sync1 ldd #$0102 ; ACCA = serial in mask, ACCB = shift counter
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
61 sync2 bita ,u ; sample input
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
62 beq sync3 ; branch if low
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
63 leax -1,x ; decrement timeout counter
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
64 bne sync1 ; loop if timeout has not expired
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
65 bra rxDone ; exit due to timeout
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
66 sync3 lsrb ; have there been 2 consecutive low samples?
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
67 bcc sync2 ; keep waiting if no
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
68 ldx #0 ; initialize checksum
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
69 sync4 bita ,u ; sample input
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
70 bne rxByte ; branch if input has returned hi
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
71 rorb ; bump secondary timeout counter
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
72 bcc sync4 ; branch if not timeout
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
73 bra rxDone ; exit due to timeout
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
74
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
75 * Byte receiver loop
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
76 rxByte lda <$FF20 ; reset FIRQ
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
77 sync ; wait for start bit
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
78 leau ,u
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
79 lda ,u ; bit 0
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
80 lsra
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
81 rolb
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
82 lda ,u++ ; bit 1
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
83 lsra
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
84 rolb
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
85 lda -2,u ; bit 2
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
86 lsra
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
87 rolb
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
88 lda ,--u ; bit 3
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
89 lsra
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
90 rolb
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
91 lda ,u++ ; bit 4
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
92 lsra
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
93 rolb
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
94 lda ,--u ; bit 5
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
95 lsra
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
96 rolb
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
97 lda ,u+ ; bit 6
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
98 lsra
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
99 rolb
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
100 nop
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
101 lda ,-u ; bit 7
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
102 lsra
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
103 rolb
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
104 abx ; update checksum
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
105 stb ,y+ ; put byte to storage
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
106 decw ; decrement counter
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
107 bne rxByte ; loop if more bytes to read
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
108 clra ; status = SUCCESS
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
109 rxDone sta 5,s ; store status on stack
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
110
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
111 * Restore previous PIA control settings
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
112 puls d ; restore original PIA 1 controls
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
113 sta <$FF21
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
114 stb <$FF23
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
115 puls d ; restore original PIA 0 controls
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
116 sta <$FF01
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
117 stb <$FF03
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
118 lda <$FF20 ; make sure the CD FIRQ has been cleared
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
119
2602
b839b516cb35 Inverted conditionals
boisy
parents: 2576
diff changeset
120 IFEQ NITROS9-1
2576
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
121 * Restoration of GIME interrupts in NitrOS9
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
122 ldd >D.IRQER ; retrieve shadow copy of IRQ/FIRQ enable regs
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
123 std <$FF92 ; restore GIME
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
124 ldd <$FF92 ; clear spurious interrupts
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
125 ENDIF
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
126
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
127 * Clean up and return
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
128 leay ,x ; return checksum in Y
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
129 puls cc,a,dp,u ; ACCA = status; restore IRQ masks, DP and U
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
130 tsta ; set CC.Z if status = SUCCESS
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
131 rts ; return
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
132
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
133 ELSE
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
134
2574
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
135 *******************************************************
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
136 *
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
137 * DWRead - 6809 Turbo Edition 115k / 230k
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
138 * Receive a response from the DriveWire server.
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
139 * Times out if no data received within 1.3 (0.66) seconds.
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
140 *
2743
b44abaa5da88 Found that the lib folder was not being processed. Corrected issue.
drencor-xeen
parents: 2741
diff changeset
141 * THIS VERSION REQUIRES ONE OR MORE SYNC BYTES
2574
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
142 * WHERE THE THE FINAL SYNC BYTE IS $C0 AND ANY
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
143 * PRECEDING SYNC BYTES ARE $FF.
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
144 *
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
145 * THE DATA BYTES MUST BE TRANSMITTED IN REVERSE
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
146 * BIT ORDER (MOST-SIGNIFICANT FIRST).
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
147 *
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
148 * Serial data format: 8-N-2 (TWO STOP BITS MANDATORY)
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
149 *
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
150 * Entry:
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
151 * X = storage address for incoming data
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
152 * Y = number of bytes required
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
153 *
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
154 * Exit:
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
155 * CC = Z set on success, cleared on timeout
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
156 * Y = checksum
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
157 * U is preserved
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
158 * All others clobbered
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
159 *
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
160 *BBIN equ $FF22 ; bit banger input port
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
161 SETDP $FF
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
162 DWRead pshs y,x,dp,a,cc ; save registers (A allocates space for status)
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
163 orcc #$50 ; mask interrupts
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
164 lda #$FF ; select hardware page..
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
165 tfr a,dp ; ..as the direct page
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
166 ldx #0 ; initialize timeout counter
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
167 stx <$FF92 ; disable GIME interrupts
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
168 ldd <$FF92 ; clear spurious interrupts
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
169
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
170 * Turn off PIA interrupt sources except for the bit banger's CD input pin.
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
171 * Also enable sound output from the DAC to stabilize the single-bit sound line.
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
172 lda <$FF01 ; save PIA 0 controls on the stack
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
173 ldb <$FF03
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
174 pshs d
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
175 anda #$F6 ; clear IRQ enables and audio mux selects
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
176 andb #$F6
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
177 sta <$FF01 ; set new control state for PIA 0
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
178 stb <$FF03
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
179 lda <$FF00 ; ensure the IRQ outputs are cleared
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
180 ldb <$FF02
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
181 lda <$FF21 ; save PIA 1 controls on the stack
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
182 ldb <$FF23
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
183 pshs d,cc ; CC allocates space for byte adjustment value
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
184 anda #$FC ; clear FIRQ enables and sound enable
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
185 andb #$F6
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
186 addd #$0108 ; set CD FIRQ enable and sound enable
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
187 sta <$FF21 ; set new control state for PIA 1
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
188 stb <$FF23
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
189
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
190 * Setup byte adjustment value
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
191 ldd #$01FE ; ACCA = serial in mask; ACCB = byte adjust mask
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
192 andb <BBIN ; ACCB = byte adjust value
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
193 stb ,s ; save in pre-allocated stack space
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
194
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
195 * Wait for Sync Byte(s) or Timeout
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
196 sync1 ldb #2 ; set counter to wait for 2 low samples
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
197 sync2 bita <BBIN ; sample input
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
198 beq sync3 ; branch if low
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
199 leax ,-x ; decrement timeout counter
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
200 bne sync1 ; loop if timeout has not expired
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
201 bra rxDone ; exit due to timeout
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
202 sync3 lsrb ; have there been 2 consecutive low samples?
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
203 bcc sync2 ; keep waiting if no
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
204 ldx 8,s ; point X to storage buffer and..
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
205 leax -1,x ; ..adjust for pre-increment
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
206 sync4 bita <BBIN ; sample input
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
207 bne rxStart ; branch if input has returned hi
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
208 rorb ; bump secondary timeout counter
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
209 bcc sync4 ; branch if not timeout
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
210 bra rxDone ; exit due to timeout
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
211 rxStart lda <$FF20 ; reset FIRQ
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
212 sync ; wait for the first byte's start bit
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
213 jmp <rxFirst,pcr ; 4-cycle equivalent of: bra rxFirst
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
214
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
215 * Byte receiver loop
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
216 rxNext sync ; wait for start bit
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
217 sta ,x ; store previous data byte
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
218 rxFirst lda <BBIN ; bit 0
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
219 asla
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
220 nop
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
221 adda <BBIN ; bit 1
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
222 asla
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
223 adda >BBIN ; bit 2
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
224 asla
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
225 nop
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
226 adda <BBIN ; bit 3
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
227 asla
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
228 clrb ; ACCB = 0
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
229 adda <BBIN ; bit 4
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
230 asla
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
231 incb ; ACCB = 1
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
232 adda <BBIN ; bit 5
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
233 asla
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
234 adda >BBIN ; bit 6
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
235 asla
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
236 abx ; increment storage ptr
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
237 adda <BBIN ; bit 7
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
238 adda ,s ; adjust byte value
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
239 bita <$FF20 ; reset FIRQ
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
240 leay -1,y ; decrement counter
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
241 bne rxNext ; loop if more bytes to read
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
242 sta ,x ; store final byte
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
243 clra ; status = SUCCESS
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
244 rxDone sta 6,s ; store status on stack
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
245 leas 1,s ; pop byte adjustment value
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
246
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
247 * Restore previous PIA control settings
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
248 puls d ; restore original PIA 1 controls
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
249 sta <$FF21
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
250 stb <$FF23
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
251 puls d ; restore original PIA 0 controls
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
252 sta <$FF01
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
253 stb <$FF03
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
254 lda <$FF20 ; make sure the CD FIRQ has been cleared
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
255
2602
b839b516cb35 Inverted conditionals
boisy
parents: 2576
diff changeset
256 IFEQ NITROS9-1
2574
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
257 * Restoration of GIME interrupts in NitrOS9
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
258 ldd >D.IRQER ; retrieve shadow copy of IRQ/FIRQ enable regs
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
259 std <$FF92 ; restore GIME
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
260 ldd <$FF92 ; clear spurious interrupts
2576
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
261 ENDIF
2574
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
262
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
263 * Checksum computation
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
264 clrb ; initialize checksum LSB
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
265 puls cc,a,dp,x,y ; restore IRQ masks, DP and the caller params
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
266 tsta ; timeout error?
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
267 bne rxExit ; branch if yes
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
268 sumLoop addb ,x+ ; get one byte and add to..
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
269 adca #0 ; ..the 16-bit checksum in ACCD
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
270 leay -1,y ; decrement counter
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
271 bne sumLoop ; loop until all data summed
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
272 andcc #$FE ; clear carry (no framing error)
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
273 rxExit tfr d,y ; move checksum into Y without affecting CC.Z
236dd2507569 Added DW4 code from Darren A.
boisy
parents:
diff changeset
274 rts ; return
2576
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
275
35c61c91bc29 Added 6309 code from Darren
boisy
parents: 2574
diff changeset
276 ENDC