2163
|
1 NAM llio_coco3
|
|
2 TTL CoCo 3 low-level I/O handler
|
|
3
|
|
4 PSECT llio_coco3,0,0,0,0,llio
|
|
5
|
|
6 VSECT
|
|
7 ENDSECT
|
|
8
|
|
9 llio:
|
|
10 lbsr llinit
|
|
11 lbsr llread
|
|
12 lbsr llwrite
|
|
13 lbsr llterm
|
|
14
|
|
15 ********** I/O ROUTINES **********
|
|
16
|
|
17 * 6551 Parameters
|
|
18 ADDR EQU $FF68
|
|
19
|
|
20 A_RXD EQU ADDR+$00
|
|
21 A_TXD EQU ADDR+$00
|
|
22 A_STATUS EQU ADDR+$01
|
|
23 A_RESET EQU ADDR+$01
|
|
24 A_CMD EQU ADDR+$02
|
|
25 A_CTRL EQU ADDR+$03
|
|
26
|
|
27 * Baud rates
|
|
28 _B2400 EQU $1A 2400 bps, 8-N-1
|
|
29 _B4800 EQU $1C 4800 bps, 8-N-1
|
|
30 _B9600 EQU $1E 9600 bps, 8-N-1
|
|
31 _B19200 EQU $1F 19200 bps, 8-N-1
|
|
32
|
|
33 BAUD EQU _B9600
|
|
34
|
|
35 * ll_init - Initialize the low-level I/O
|
|
36 * Exit: Carry = 0: Init success; Carry = 1; Init failed
|
|
37 llinit
|
|
38 sta A_RESET soft reset (value not important)
|
|
39 * Set specific modes and functions:
|
|
40 * - no parity, no echo, no Tx interrupt
|
|
41 * - no Rx interrupt, enable Tx/Rx
|
|
42 lda #$0B
|
|
43 sta A_CMD save to command register
|
|
44 lda #BAUD
|
|
45 sta A_CTRL select proper baud rate
|
|
46 * Read any junk rx byte that may be in the register
|
|
47 lda A_RXD
|
|
48 rts
|
|
49
|
|
50
|
|
51 * llread - Read one character from 6551
|
|
52 *
|
|
53 * Entry: None
|
|
54 * Exit: A = character that was read
|
|
55 *
|
|
56 * Note, this routine currently doesn't timeout
|
|
57 llread
|
|
58 r lda A_STATUS get status byte
|
|
59 anda #$08 mask rx buffer status flag
|
|
60 beq r loop if rx buffer empty
|
|
61 lda A_RXD get byte from ACIA data port
|
|
62 rts
|
|
63
|
|
64 * llwrite - Write one character to 6551
|
|
65 *
|
|
66 * Entry: A = character to write
|
|
67 * Exit: None
|
|
68 llwrite
|
|
69 pshs a save byte to write
|
|
70 w lda A_STATUS get status byte
|
|
71 anda #$10 mask tx buffer status flag
|
|
72 beq w loop if tx buffer full
|
|
73 puls a get byte
|
|
74 sta A_TXD save to ACIA data port
|
|
75 rts
|
|
76
|
|
77
|
|
78 llterm
|
|
79 rts
|
|
80
|
|
81 IFNE 0
|
|
82 * llwout - Write an entire string
|
|
83 * llwerr - Write an entire string
|
|
84 llwerr
|
|
85 llwout
|
|
86 pshs a
|
|
87 l@ lda ,x+
|
|
88 cmpa #C$CR
|
|
89 beq e@
|
|
90 leay -1,y
|
|
91 beq f@
|
|
92 bsr Write
|
|
93 bra l@
|
|
94 e@ bsr Write
|
|
95 lda #C$LF
|
|
96 bsr Write
|
|
97 f@ ldx <buffptr
|
|
98 clrb
|
|
99 puls a,pc
|
|
100
|
|
101 * ReadLine - Read an entire string, up to CR
|
|
102 * Entry: X = address to place string being read (CR terminated)
|
|
103 * Y = maximum number of bytes to read (including nul byte)
|
|
104 ReadLine
|
|
105 ldx <buffptr
|
|
106 pshs y,x,a
|
|
107 ldy #80
|
|
108 l@ bsr Read read 1 character
|
|
109 cmpa #C$CR carriage return?
|
|
110 beq e@ branch if so...
|
|
111 cmpa #$08 backspace?
|
|
112 beq bs@
|
|
113 cmpy #$0000 anymore room?
|
|
114 beq l@
|
|
115 leay -1,y back up one char
|
|
116 sta ,x+ and save in input buffer
|
|
117 m@ bsr Write echo back out
|
|
118 bra l@
|
|
119 e@ sta ,x
|
|
120 bsr Write
|
|
121 lda #C$LF
|
|
122 bsr Write
|
|
123 clrb
|
|
124 puls a,x,y,pc
|
|
125 bs@ cmpx 1,s are we at start
|
|
126 beq l@ if so, do nothing
|
|
127 clr ,-x else erase last byte
|
|
128 lbsr Write write backspace
|
|
129 lda #C$SPAC a space...
|
|
130 lbsr Write write it
|
|
131 leay 1,y count back up free char
|
|
132 lda #$08 another backspace
|
|
133 bra m@
|
|
134 ENDC
|
|
135
|
|
136 endsect
|