]>
Commit | Line | Data |
---|---|---|
64219415 FZ |
1 | ; Virtual Ports for the BIOS Interaction |
2 | ; | |
29ce189c | 3 | ; Copyright (C) 2010 Leo C. |
64219415 FZ |
4 | ; |
5 | ; This file is part of avrcpm. | |
6 | ; | |
7 | ; avrcpm is free software: you can redistribute it and/or modify it | |
8 | ; under the terms of the GNU General Public License as published by | |
9 | ; the Free Software Foundation, either version 3 of the License, or | |
10 | ; (at your option) any later version. | |
11 | ; | |
12 | ; avrcpm is distributed in the hope that it will be useful, | |
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ; GNU General Public License for more details. | |
16 | ; | |
17 | ; You should have received a copy of the GNU General Public License | |
18 | ; along with avrcpm. If not, see <http://www.gnu.org/licenses/>. | |
19 | ; | |
20 | ; $Id$ | |
29ce189c L |
21 | ; |
22 | ||
23 | ||
24 | ; | |
25 | ; Port Direction Function | |
26 | ;hex dez | |
27 | ;------------------------------------------------------------------------- | |
28 | ;00 0 in - Con status. | |
29 | ; Returns 0xFF if the UART has a byte, 0 otherwise. | |
30 | ;01 1 in/out - Console input, aka UDR. / Console Output | |
31 | ;02 2 out - Console Output (deprecated) | |
32 | ;03 3 in - "UART" status: bit 0 = rx, bit 1 = tx | |
33 | ;04 4 in - "UART" data register, no wait | |
34 | ; | |
d8fa6a36 L |
35 | ;------------------------ Virtual I2C interface -------------------------- |
36 | ;05 5 out - Control Port: 1 = Start read operation | |
37 | ; 2 = Start write operation | |
38 | ;05 5 in - Status of last Transfer: 0 = ok, else fail | |
39 | ;06 6 in/out - Number of bytes to transfer, including Slave address | |
40 | ;07,08 7,8 in/out - Read/Write address low/high | |
41 | ; | |
42 | ;------------------------ Disk I/O --------------------------------------- | |
29ce189c L |
43 | ;0D,0E 13,14 in/out - Set address of Bios Controll Block |
44 | ;0F 15 in/out - Disk select | |
45 | ;10,11 16,17 in/out - Track select | |
46 | ;12,13 18,19 in/out - Sector select | |
47 | ;14,15 20,21 in/out - Write addr | |
48 | ; | |
49 | ;16 22 out - Trigger disk i/o operations | |
50 | ; Bit 7 = 1: Read sector | |
51 | ; Bit 6 = 1: Write sector | |
52 | ; Bit 5 = 1: BIOS WBOOT | |
53 | ; Bit 4 = 1: BIOS Home | |
54 | ; Only one of bits 4..7 may be set. | |
55 | ; If Write function (bit 6=1): | |
56 | ; Bits 0..2: 0 - write to allocated | |
57 | ; 1 - write to directory | |
58 | ; 2 - write unallocated | |
59 | ; 3 - write to directory | |
60 | ; | |
61 | ;16 22 in - Result of last read/write operation. | |
62 | ; 0x00 = ok, 0xff = error (--> Bad Sector) | |
63 | ; | |
d8fa6a36 L |
64 | ; |
65 | ; | |
66 | ;------------------------ Wall Clock and Timers -------------------------- | |
5482d75f | 67 | ;40 64-71 in/out - Timer/Clock control. |
fb050095 L |
68 | ;41-46 |
69 | ; | |
d8fa6a36 L |
70 | ;47-4D clock - BCD format: ss, mm, hh, DD, MM, YYl, YYh |
71 | ; | |
72 | ;------------------------ Ports ------------------------------------------ | |
73 | ;80-87 in/out - Port-Expander PCF8574 (max. 8 Chips) | |
74 | ;88-8F in/out - Port-Expander PCF8574A (not implemented yet!) | |
29ce189c L |
75 | |
76 | ||
64219415 | 77 | ; ---------------------------------------------- Start of Code Segment |
29ce189c L |
78 | .cseg |
79 | vport_tbl: | |
80 | .db 00,1 ;Port 0, length 1 | |
81 | .dw conStatus ; in | |
82 | .dw dbgOut ; out | |
83 | .db 01,1 | |
84 | .dw uartgetc | |
85 | .dw uartputc | |
86 | .db 02,1 ;Port 2 (old console output) | |
87 | .dw uartgetc ; filler | |
88 | .dw uartputc ; deprecated | |
89 | .db 03,1 | |
90 | .dw uartstat | |
91 | .dw vport_out_dummy | |
92 | .db 04,1 | |
93 | .dw uartin | |
94 | .dw uartout | |
95 | ||
fb050095 | 96 | .db 13,9 ; Port 13-21, (length 9) |
5482d75f L |
97 | .dw dsk_param_get |
98 | .dw dsk_param_set | |
29ce189c L |
99 | .db 22,1 |
100 | .dw dskErrorRet | |
101 | .dw dskDoIt | |
102 | ||
103 | .db TIMERPORT,7 | |
fb050095 L |
104 | .dw utimeget |
105 | .dw utimeput | |
106 | ||
d8fa6a36 | 107 | .db CLOCKPORT,7 ;Clock format (bcd): ss, mm, hh, DD, MM, YYl, YYh |
29ce189c L |
108 | .dw clockget |
109 | .dw clockput | |
80e1fa71 L |
110 | |
111 | .db DEBUGPORT,1 | |
112 | .dw dbg_stat | |
113 | .dw dbg_ctrl | |
d8fa6a36 L |
114 | |
115 | #if I2C | |
116 | .db I2CCTRL,1 | |
117 | .dw vi2c_stat_get | |
118 | .dw vi2c_ctrl | |
119 | ||
120 | .db I2CBLEN,3 ; | |
121 | .dw vi2c_param_get | |
122 | .dw vi2c_param_set | |
123 | ||
124 | .db PORT,8 | |
125 | .dw pcf8574_in | |
126 | .dw pcf8574_out | |
127 | #endif | |
128 | ||
29ce189c L |
129 | .db 0,0 ; Stop mark |
130 | ||
131 | ;--------------------------------------------------------------------- | |
132 | ||
133 | ;Called with port in temp2 and value in temp. | |
134 | portWrite: | |
135 | set | |
136 | rjmp vprw_start | |
137 | ||
138 | ;Called with port in temp2. Should return value in temp. | |
139 | portRead: | |
140 | clt | |
141 | ||
142 | vprw_start: | |
e7a0f403 L |
143 | push yh |
144 | push yl | |
29ce189c L |
145 | .if PORT_DEBUG > 1 |
146 | tst temp2 | |
147 | brne dvp_1 ;don't debug console status | |
148 | brts dvp_1 | |
149 | rjmp conStatus | |
150 | dvp_1: | |
151 | printnewline | |
152 | brts dvp_11 | |
153 | printstring "Port In: " | |
154 | rjmp dvp_12 | |
155 | dvp_11: | |
156 | printstring "Port Out: " | |
157 | dvp_12: | |
158 | push temp | |
159 | mov temp,temp2 | |
160 | rcall printhex | |
161 | pop temp | |
162 | .endif | |
163 | ldiw z,vport_tbl*2 | |
164 | ||
165 | vprw_loop: | |
166 | lpm _tmp0,z+ | |
167 | lpm temp4,z+ ;length | |
168 | cpi temp4,0 | |
169 | breq vprw_exit ;no more ports | |
170 | ||
171 | mov temp3,temp2 | |
172 | sub temp3,_tmp0 ;base port | |
173 | brcs vprw_next ;port # too high | |
174 | cp temp3,temp4 ;may be in range | |
175 | brcs vprw_found ; | |
176 | vprw_next: ;port # not in range, test next block. | |
177 | adiw z,4 | |
178 | rjmp vprw_loop | |
179 | vprw_found: | |
d8fa6a36 L |
180 | brtc PC+2 ;read or write? |
181 | adiw z,2 ;skip read function pointer | |
29ce189c L |
182 | lpm _tmp0,z+ |
183 | lpm _tmp1,z+ | |
184 | movw z,_tmp0 | |
185 | ||
186 | .if PORT_DEBUG > 1 | |
187 | push temp2 | |
188 | push temp | |
189 | printstring ", exec: " | |
190 | movw temp,z | |
191 | rcall printhexw | |
192 | printstring ", rel port: " | |
193 | mov temp,temp3 | |
194 | rcall printhex | |
195 | pop temp | |
196 | pop temp2 | |
197 | printstring ", val: " | |
198 | brts dvp_2 | |
199 | icall | |
200 | rcall printhex | |
201 | printstring " " | |
e7a0f403 L |
202 | pop yl |
203 | pop yh | |
29ce189c L |
204 | ret |
205 | dvp_2: | |
206 | rcall printhex | |
207 | printstring " " | |
e7a0f403 L |
208 | ; relative port # in temp3 |
209 | icall | |
210 | pop yl | |
211 | pop yh | |
212 | ret | |
29ce189c | 213 | .else |
e7a0f403 L |
214 | icall |
215 | pop yl | |
216 | pop yh | |
217 | ret | |
29ce189c L |
218 | .endif |
219 | ||
220 | vprw_exit: | |
221 | ; trap for nonexistent port? | |
222 | .if PORT_DEBUG > 1 | |
223 | printstring ", not found!" | |
224 | .endif | |
225 | vport_in_dummy: | |
226 | ldi temp,0xff | |
227 | vport_out_dummy: | |
e7a0f403 L |
228 | pop yl |
229 | pop yh | |
29ce189c L |
230 | ret |
231 | ||
232 | ||
64219415 FZ |
233 | uartstat: |
234 | clr temp | |
235 | lds temp2,rxcount | |
236 | cpse temp2,_0 | |
237 | sbr temp,0x01 | |
238 | lds temp2,txcount | |
239 | cpi temp2,TXBUFSIZE | |
240 | breq uartst_1 | |
241 | sbr temp,0x02 | |
242 | uartst_1: | |
243 | ret | |
244 | ||
29ce189c L |
245 | uartin: |
246 | clr temp | |
247 | lds temp2,rxcount | |
248 | cpse temp2,_0 | |
08716d4f | 249 | ljmp uartgetc |
29ce189c L |
250 | ret |
251 | ||
64219415 FZ |
252 | uartout: |
253 | lds temp2,txcount | |
254 | cpi temp2,TXBUFSIZE | |
255 | breq uartout_1 | |
08716d4f | 256 | ljmp uartputc |
64219415 FZ |
257 | uartout_1: |
258 | ret | |
259 | ||
29ce189c | 260 | |
64219415 FZ |
261 | conStatus: |
262 | lds temp,rxcount | |
263 | cpse temp,_0 | |
264 | ldi temp,0xff | |
265 | ret | |
266 | ||
64219415 FZ |
267 | |
268 | dbgOut: | |
269 | printnewline | |
270 | printstring "Debug: " | |
08716d4f | 271 | lcall printhex |
64219415 FZ |
272 | ret |
273 | ||
64219415 | 274 | |
80e1fa71 L |
275 | dbg_stat: |
276 | ldi temp,0 | |
277 | ret | |
278 | ||
279 | dbg_ctrl: | |
280 | bmov intstat,i_trace, temp,0 | |
281 | ret | |
282 | ||
283 | ||
284 | ||
64219415 | 285 | ;--------------------------------------------------------------------- |
29ce189c L |
286 | ; vim:set ts=8 noet nowrap |
287 |