Mercurial > hg > Members > kono > nitros9-code
comparison level1/modules/dw4read.asm @ 2576:35c61c91bc29
Added 6309 code from Darren
author | boisy |
---|---|
date | Mon, 16 May 2011 00:57:24 +0000 |
parents | 236dd2507569 |
children | b839b516cb35 |
comparison
equal
deleted
inserted
replaced
2575:a9a5be5114b2 | 2576:35c61c91bc29 |
---|---|
1 IFNE H6309-1 | |
2 | |
3 ******************************************************* | |
4 * | |
5 * DWRead - 6309 native Turbo Edition 115k / 230k | |
6 * Receive a response from the DriveWire server. | |
7 * Times out if no data received within 1.3 (0.66) seconds. | |
8 * | |
9 * THIS VERSION REQUIRES ONE OR MORE SYNC BYTES | |
10 * WHERE THE THE FINAL SYNC BYTE IS $C0 AND ANY | |
11 * PRECEDING SYNC BYTES ARE $FF. | |
12 * | |
13 * THE DATA BYTES MUST BE TRANSMITTED IN REVERSE | |
14 * BIT ORDER (MOST-SIGNIFICANT FIRST). | |
15 * | |
16 * Serial data format: 8-N-2 (TWO STOP BITS MANDATORY) | |
17 * | |
18 * Entry: | |
19 * X = storage address for incoming data | |
20 * Y = number of bytes requested | |
21 * | |
22 * Exit: | |
23 * CC = Z set on success, cleared on timeout | |
24 * Y = checksum | |
25 * U is preserved | |
26 * All others clobbered | |
27 * | |
28 BBIN equ $FF22 ; bit banger input port | |
29 | |
30 DWRead clra ; ACCA = 0, clear Carry | |
31 pshs u,dp,a,cc ; save registers (A allocates space for status) | |
32 orcc #$50 ; mask interrupts | |
33 deca ; select hardware page.. | |
34 tfr a,dp ; ..as the direct page | |
35 ldu #BBIN ; point U at input port | |
36 tfr y,w ; W = request count | |
37 leay ,x ; Y = storage ptr | |
38 ldx #0 ; initialize timeout counter | |
39 stx <$FF92 ; disable GIME interrupts | |
40 ldd <$FF92 ; clear spurious interrupts | |
41 | |
42 * Turn off PIA interrupt sources except for the CD input pin. | |
43 lda <$FF01 ; save PIA 0 controls on the stack | |
44 ldb <$FF03 | |
45 pshs d | |
46 andd #$FCFC ; clear IRQ enables | |
47 sta <$FF01 ; set new control state for PIA 0 | |
48 stb <$FF03 | |
49 lda <$FF00 ; ensure that IRQ outputs are cleared | |
50 ldb <$FF02 | |
51 lda <$FF21 ; save PIA 1 controls on the stack | |
52 ldb <$FF23 | |
53 pshs d | |
54 andd #$FCFC ; clear FIRQ enables | |
55 inca ; set CD FIRQ enable | |
56 sta <$FF21 ; set new control state for PIA 1 | |
57 stb <$FF23 | |
58 | |
59 * Wait for Sync Byte(s) or Timeout | |
60 sync1 ldd #$0102 ; ACCA = serial in mask, ACCB = shift counter | |
61 sync2 bita ,u ; sample input | |
62 beq sync3 ; branch if low | |
63 leax -1,x ; decrement timeout counter | |
64 bne sync1 ; loop if timeout has not expired | |
65 bra rxDone ; exit due to timeout | |
66 sync3 lsrb ; have there been 2 consecutive low samples? | |
67 bcc sync2 ; keep waiting if no | |
68 ldx #0 ; initialize checksum | |
69 sync4 bita ,u ; sample input | |
70 bne rxByte ; branch if input has returned hi | |
71 rorb ; bump secondary timeout counter | |
72 bcc sync4 ; branch if not timeout | |
73 bra rxDone ; exit due to timeout | |
74 | |
75 * Byte receiver loop | |
76 rxByte lda <$FF20 ; reset FIRQ | |
77 sync ; wait for start bit | |
78 leau ,u | |
79 lda ,u ; bit 0 | |
80 lsra | |
81 rolb | |
82 lda ,u++ ; bit 1 | |
83 lsra | |
84 rolb | |
85 lda -2,u ; bit 2 | |
86 lsra | |
87 rolb | |
88 lda ,--u ; bit 3 | |
89 lsra | |
90 rolb | |
91 lda ,u++ ; bit 4 | |
92 lsra | |
93 rolb | |
94 lda ,--u ; bit 5 | |
95 lsra | |
96 rolb | |
97 lda ,u+ ; bit 6 | |
98 lsra | |
99 rolb | |
100 nop | |
101 lda ,-u ; bit 7 | |
102 lsra | |
103 rolb | |
104 abx ; update checksum | |
105 stb ,y+ ; put byte to storage | |
106 decw ; decrement counter | |
107 bne rxByte ; loop if more bytes to read | |
108 clra ; status = SUCCESS | |
109 rxDone sta 5,s ; store status on stack | |
110 | |
111 * Restore previous PIA control settings | |
112 puls d ; restore original PIA 1 controls | |
113 sta <$FF21 | |
114 stb <$FF23 | |
115 puls d ; restore original PIA 0 controls | |
116 sta <$FF01 | |
117 stb <$FF03 | |
118 lda <$FF20 ; make sure the CD FIRQ has been cleared | |
119 | |
120 IFNE NITROS9-1 | |
121 * Restoration of GIME interrupts in NitrOS9 | |
122 ldd >D.IRQER ; retrieve shadow copy of IRQ/FIRQ enable regs | |
123 std <$FF92 ; restore GIME | |
124 ldd <$FF92 ; clear spurious interrupts | |
125 ENDIF | |
126 | |
127 * Clean up and return | |
128 leay ,x ; return checksum in Y | |
129 puls cc,a,dp,u ; ACCA = status; restore IRQ masks, DP and U | |
130 tsta ; set CC.Z if status = SUCCESS | |
131 rts ; return | |
132 | |
133 ELSE | |
134 | |
1 ******************************************************* | 135 ******************************************************* |
2 * | 136 * |
3 * DWRead - 6809 Turbo Edition 115k / 230k | 137 * DWRead - 6809 Turbo Edition 115k / 230k |
4 * Receive a response from the DriveWire server. | 138 * Receive a response from the DriveWire server. |
5 * Times out if no data received within 1.3 (0.66) seconds. | 139 * Times out if no data received within 1.3 (0.66) seconds. |
117 puls d ; restore original PIA 0 controls | 251 puls d ; restore original PIA 0 controls |
118 sta <$FF01 | 252 sta <$FF01 |
119 stb <$FF03 | 253 stb <$FF03 |
120 lda <$FF20 ; make sure the CD FIRQ has been cleared | 254 lda <$FF20 ; make sure the CD FIRQ has been cleared |
121 | 255 |
122 IF NITROS | 256 IFNE NITROS9-1 |
123 * Restoration of GIME interrupts in NitrOS9 | 257 * Restoration of GIME interrupts in NitrOS9 |
124 ldd >D.IRQER ; retrieve shadow copy of IRQ/FIRQ enable regs | 258 ldd >D.IRQER ; retrieve shadow copy of IRQ/FIRQ enable regs |
125 std <$FF92 ; restore GIME | 259 std <$FF92 ; restore GIME |
126 ldd <$FF92 ; clear spurious interrupts | 260 ldd <$FF92 ; clear spurious interrupts |
127 ENDIF | 261 ENDIF |
128 | 262 |
129 * Checksum computation | 263 * Checksum computation |
130 clrb ; initialize checksum LSB | 264 clrb ; initialize checksum LSB |
131 puls cc,a,dp,x,y ; restore IRQ masks, DP and the caller params | 265 puls cc,a,dp,x,y ; restore IRQ masks, DP and the caller params |
132 tsta ; timeout error? | 266 tsta ; timeout error? |
136 leay -1,y ; decrement counter | 270 leay -1,y ; decrement counter |
137 bne sumLoop ; loop until all data summed | 271 bne sumLoop ; loop until all data summed |
138 andcc #$FE ; clear carry (no framing error) | 272 andcc #$FE ; clear carry (no framing error) |
139 rxExit tfr d,y ; move checksum into Y without affecting CC.Z | 273 rxExit tfr d,y ; move checksum into Y without affecting CC.Z |
140 rts ; return | 274 rts ; return |
275 | |
276 ENDC |