]> cloudbase.mooo.com Git - avrcpm.git/blob - avr/virt_ports.asm
* minor corrections/enhancements
[avrcpm.git] / avr / virt_ports.asm
1 ; Virtual Ports for the BIOS Interaction
2 ;
3 ; Copyright (C) 2010 Leo C.
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$
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 ;
35 ;0D,0E 13,14 in/out - Set address of Bios Controll Block
36 ;0F 15 in/out - Disk select
37 ;10,11 16,17 in/out - Track select
38 ;12,13 18,19 in/out - Sector select
39 ;14,15 20,21 in/out - Write addr
40 ;
41 ;16 22 out - Trigger disk i/o operations
42 ; Bit 7 = 1: Read sector
43 ; Bit 6 = 1: Write sector
44 ; Bit 5 = 1: BIOS WBOOT
45 ; Bit 4 = 1: BIOS Home
46 ; Only one of bits 4..7 may be set.
47 ; If Write function (bit 6=1):
48 ; Bits 0..2: 0 - write to allocated
49 ; 1 - write to directory
50 ; 2 - write unallocated
51 ; 3 - write to directory
52 ;
53 ;16 22 in - Result of last read/write operation.
54 ; 0x00 = ok, 0xff = error (--> Bad Sector)
55 ;
56 ;40 64-71 in/out - Timer/Clock control.
57 ;41-46
58 ;
59 ;47-4C clock - Binary format: y, m, d, h, m, s
60
61
62 ; ---------------------------------------------- Start of Code Segment
63 .cseg
64 vport_tbl:
65 .db 00,1 ;Port 0, length 1
66 .dw conStatus ; in
67 .dw dbgOut ; out
68 .db 01,1
69 .dw uartgetc
70 .dw uartputc
71 .db 02,1 ;Port 2 (old console output)
72 .dw uartgetc ; filler
73 .dw uartputc ; deprecated
74 .db 03,1
75 .dw uartstat
76 .dw vport_out_dummy
77 .db 04,1
78 .dw uartin
79 .dw uartout
80
81 .db 13,9 ; Port 13-21, (length 9)
82 .dw dsk_param_get
83 .dw dsk_param_set
84 .db 22,1
85 .dw dskErrorRet
86 .dw dskDoIt
87
88 .db TIMERPORT,7
89 .dw utimeget
90 .dw utimeput
91
92 .db CLOCKPORT,6 ;Clock format (bin): y, m, d, h, m, s
93 .dw clockget
94 .dw clockput
95
96 .db DEBUGPORT,1
97 .dw dbg_stat
98 .dw dbg_ctrl
99 .db 0,0 ; Stop mark
100
101 ;---------------------------------------------------------------------
102
103 ;Called with port in temp2 and value in temp.
104 portWrite:
105 set
106 rjmp vprw_start
107
108 ;Called with port in temp2. Should return value in temp.
109 portRead:
110 clt
111
112 vprw_start:
113 push yh
114 push yl
115 .if PORT_DEBUG > 1
116 tst temp2
117 brne dvp_1 ;don't debug console status
118 brts dvp_1
119 rjmp conStatus
120 dvp_1:
121 printnewline
122 brts dvp_11
123 printstring "Port In: "
124 rjmp dvp_12
125 dvp_11:
126 printstring "Port Out: "
127 dvp_12:
128 push temp
129 mov temp,temp2
130 rcall printhex
131 pop temp
132 .endif
133 ldiw z,vport_tbl*2
134
135 vprw_loop:
136 lpm _tmp0,z+
137 lpm temp4,z+ ;length
138 cpi temp4,0
139 breq vprw_exit ;no more ports
140
141 mov temp3,temp2
142 sub temp3,_tmp0 ;base port
143 brcs vprw_next ;port # too high
144 cp temp3,temp4 ;may be in range
145 brcs vprw_found ;
146 vprw_next: ;port # not in range, test next block.
147 adiw z,4
148 rjmp vprw_loop
149 vprw_found:
150 brtc PC+2
151 adiw z,2
152 lpm _tmp0,z+
153 lpm _tmp1,z+
154 movw z,_tmp0
155
156 .if PORT_DEBUG > 1
157 push temp2
158 push temp
159 printstring ", exec: "
160 movw temp,z
161 rcall printhexw
162 printstring ", rel port: "
163 mov temp,temp3
164 rcall printhex
165 pop temp
166 pop temp2
167 printstring ", val: "
168 brts dvp_2
169 icall
170 rcall printhex
171 printstring " "
172 pop yl
173 pop yh
174 ret
175 dvp_2:
176 rcall printhex
177 printstring " "
178 ; relative port # in temp3
179 icall
180 pop yl
181 pop yh
182 ret
183 .else
184 icall
185 pop yl
186 pop yh
187 ret
188 .endif
189
190 vprw_exit:
191 ; trap for nonexistent port?
192 .if PORT_DEBUG > 1
193 printstring ", not found!"
194 .endif
195 vport_in_dummy:
196 ldi temp,0xff
197 vport_out_dummy:
198 pop yl
199 pop yh
200 ret
201
202
203 uartstat:
204 clr temp
205 lds temp2,rxcount
206 cpse temp2,_0
207 sbr temp,0x01
208 lds temp2,txcount
209 cpi temp2,TXBUFSIZE
210 breq uartst_1
211 sbr temp,0x02
212 uartst_1:
213 ret
214
215 uartin:
216 clr temp
217 lds temp2,rxcount
218 cpse temp2,_0
219 rjmp uartgetc
220 ret
221
222 uartout:
223 lds temp2,txcount
224 cpi temp2,TXBUFSIZE
225 breq uartout_1
226 rjmp uartputc
227 uartout_1:
228 ret
229
230
231 conStatus:
232 lds temp,rxcount
233 cpse temp,_0
234 ldi temp,0xff
235 ret
236
237
238 dbgOut:
239 printnewline
240 printstring "Debug: "
241 rcall printhex
242 ret
243
244
245 dbg_stat:
246 ldi temp,0
247 ret
248
249 dbg_ctrl:
250 bmov intstat,i_trace, temp,0
251 ret
252
253
254
255 ;---------------------------------------------------------------------
256 ; vim:set ts=8 noet nowrap
257