Mercurial > hg > Members > kono > nitros9-code
comparison level1/modules/dwread.asm @ 2182:b1b374ada668
Added 38.4kbps routines from Darren Atkinson
author | boisy |
---|---|
date | Sun, 08 Mar 2009 14:11:52 +0000 |
parents | 660cc987e18d |
children | 27f07aa0bca0 |
comparison
equal
deleted
inserted
replaced
2181:c34956608086 | 2182:b1b374ada668 |
---|---|
1 IFNE H6309-1 | 1 IFNE BAUD38400 |
2 | |
3 ****************************************************************************** | |
4 * COCO 38400 BAUD BIT-BANGER RECEIVER | |
5 ****************************************************************************** | |
6 * | |
7 * WAITS FOR A SPECIFIED TIMEOUT PERIOD UNTIL A START-BIT APPEARS ON THE | |
8 * BIT-BANGER INPUT. DATA RECEPTION IS INITIATED IF A START-BIT APPEARS | |
9 * BEFORE THE TIMEOUT PERIOD EXPIRES. THE SERIAL DATA FORMAT MUST BE: | |
10 * 1 START BIT, 8 DATA BITS, NO PARITY, 1..2 STOP BITS. | |
11 * | |
12 * DATA RECPEPTION TERMINATES WHEN: | |
13 * - A PERIOD OF 4 MS ELLAPSES WITHOUT A NEW START BIT | |
14 * - A FRAMING ERROR IS DETECTED. | |
15 * | |
16 * ON ENTRY: | |
17 * X = ADDRESS FOR DATA STORAGE | |
18 * A = TIMEOUT VALUE (125 = APPROX ONE SECOND) | |
19 * | |
20 * ON EXIT: | |
21 * Y = DATA CHECKSUM | |
22 * D = NUMBER OF BYTES RECEIVED | |
23 * X AND U ARE PRESERVED | |
24 * CC.CARRY IS SET ONLY IF A FRAMING ERROR WAS DETECTED | |
25 * | |
26 ****************************************************************************** | |
27 BBIN EQU $FF22 ; BIT-BANGER INPUT ADDRESS | |
28 BUFBAS EQU 1 ; OFFSET TO STORAGE ADDRESS ON STACK | |
29 | |
30 DWRead | |
31 RCV38K CLRB ; CLEAR CARRY FLAG (NO FRAMING ERROR) | |
32 PSHS U,X,CC ; PRESERVE REGISTERS | |
33 ORCC #$50 ; MASK INTERRUPTS | |
34 TFR D,Y ; SET Y TO INITIAL TIMEOUT COUNTER | |
35 LEAU ,X ; POINT U TO STORAGE BUFFER | |
36 LDX #0 ; INITIALIZE CHECKSUM | |
37 LDA #1 ; A = SERIAL INPUT MASK | |
38 | |
39 WAIT1 LEAY ,Y ; TEST TIMEOUT COUNTER | |
40 BEQ FINISH ; BRANCH IF TIMEOUT HAS EXPIRED | |
41 WAIT2 BITA BBIN ; CHECK FOR START BIT | |
42 BEQ BSTART ; BRANCH IF START BIT DETECTED | |
43 LEAY -1,Y ; DECREMENT TIMEOUT COUNTER | |
44 BITA BBIN ; CHECK FOR START BIT | |
45 BNE WAIT1 ; LOOP IF STILL NO START BIT | |
46 | |
47 BSTART LDY #BBIN ; POINT Y TO BIT BANGER INPUT REGISTER | |
48 LEAU ,U ; 4 CYCLE DELAY | |
49 LDB #$7F ; INITIALIZE B FOR SHIFT COUNTER | |
50 RDLOOP TST ,Y++ ; 9 CYCLE DELAY | |
51 LDA ,--Y ; READ DATA BIT | |
52 LSRA ; SHIFT DATA INTO CARRY | |
53 RORB ; ROTATE INTO BYTE ACCUMULATOR | |
54 BCS RDLOOP ; LOOP UNTIL 8 DATA BITS HAVE BEEN READ | |
55 | |
56 STB ,U+ ; STORE RECEIVED BYTE | |
57 ABX ; ACCUMULATE CHECKSUM | |
58 CLRA ; DO THE EQUIVALENT OF.. | |
59 INCA ; ..LDA #1 USING 4 CYCLES | |
60 ANDA ,Y ; CHECK FOR THE STOP BIT | |
61 LDY #128 ; SET TIMEOUT COUNTER TO 4MS | |
62 TSTA ; IF STOP BIT IS GOOD THEN.. | |
63 BNE WAIT2 ; ..GO WAIT FOR NEXT BYTE | |
64 | |
65 FINISH INCA ; A=1 IF FRAMING ERROR, 2 OTHERWISE | |
66 ORA ,S ; SETS CARRY BIT IN CC VALUE ON.. | |
67 STA ,S ; ..STACK IF FRAMING ERROR DETECTED | |
68 LEAY ,X ; RETURN CHECKSUM IN Y | |
69 TFR U,D ; CALCULATE NUMBER.. | |
70 SUBD BUFBAS,S ; ..OF BYTES RECEIVED | |
71 PULS CC,X,U,PC ; RESTORE REGISTERS AND RETURN | |
72 | |
73 ELSE | |
74 IFNE H6309-1 | |
2 ** | 75 ** |
3 ** Rev 3 Notes: | 76 ** Rev 3 Notes: |
4 ** | 77 ** |
5 ** For CoCo 1,2 or 3 | 78 ** For CoCo 1,2 or 3 |
6 ** 6809 Timing | 79 ** 6809 Timing |
113 SUBD BUFBAS,S ; ..OF BYTES RECEIVED | 186 SUBD BUFBAS,S ; ..OF BYTES RECEIVED |
114 LEAS 2,S ; POP TIMEOUT AND BIT LOOP COUNTERS | 187 LEAS 2,S ; POP TIMEOUT AND BIT LOOP COUNTERS |
115 PULS CC,DP,X,U,PC ; RESTORE REGISTERS AND RETURN | 188 PULS CC,DP,X,U,PC ; RESTORE REGISTERS AND RETURN |
116 SETDP $00 | 189 SETDP $00 |
117 | 190 |
118 | 191 ELSE |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 ELSE | |
126 | |
127 | |
128 | 192 |
129 ** Rev 4 Notes: | 193 ** Rev 4 Notes: |
130 ** | 194 ** |
131 ** For CoCo 2 or 3 | 195 ** For CoCo 2 or 3 |
132 ** 6309 Native Mode | 196 ** 6309 Native Mode |
222 TFR Y,D ; CALCULATE ACTUAL NUMBER.. | 286 TFR Y,D ; CALCULATE ACTUAL NUMBER.. |
223 SUBD BUFBAS,S ; ..OF BYTES RECEIVED | 287 SUBD BUFBAS,S ; ..OF BYTES RECEIVED |
224 LEAY ,X ; RETURN CHECKSUM IN Y | 288 LEAY ,X ; RETURN CHECKSUM IN Y |
225 PULS CC,X,U,PC ; RESTORE REGISTERS AND RETURN | 289 PULS CC,X,U,PC ; RESTORE REGISTERS AND RETURN |
226 | 290 |
227 ENDC | 291 ENDC |
228 | 292 ENDC |
229 | 293 |