]>
Commit | Line | Data |
---|---|---|
1 | ; Print and Debug functions | |
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 | .cseg | |
25 | ||
26 | ||
27 | ;Print a unsigned lonng value to the uart | |
28 | ; temp4:temp3:temp2:temp = value | |
29 | ||
30 | print_ultoa: | |
31 | push yh | |
32 | push yl | |
33 | push z_flags | |
34 | push temp4 | |
35 | push temp3 | |
36 | push temp2 | |
37 | push temp | |
38 | ||
39 | clr yl ;yl = stack level | |
40 | ||
41 | ultoa1: ldi z_flags, 32 ;yh = temp4:temp % 10 | |
42 | clr yh ;temp4:temp /= 10 | |
43 | ultoa2: lsl temp | |
44 | rol temp2 | |
45 | rol temp3 | |
46 | rol temp4 | |
47 | rol yh | |
48 | cpi yh,10 | |
49 | brcs ultoa3 | |
50 | subi yh,10 | |
51 | inc temp | |
52 | ultoa3: dec z_flags | |
53 | brne ultoa2 | |
54 | cpi yh, 10 ;yh is a numeral digit '0'-'9' | |
55 | subi yh, -'0' | |
56 | push yh ;Stack it | |
57 | inc yl | |
58 | cp temp,_0 ;Repeat until temp4:temp gets zero | |
59 | cpc temp2,_0 | |
60 | cpc temp3,_0 | |
61 | cpc temp4,_0 | |
62 | brne ultoa1 | |
63 | ||
64 | ldi temp, '0' | |
65 | ultoa5: cpi yl,3 ; at least 3 digits (ms) | |
66 | brge ultoa6 | |
67 | push temp | |
68 | inc yl | |
69 | rjmp ultoa5 | |
70 | ||
71 | ultoa6: pop temp ;Flush stacked digits | |
72 | rcall uartputc | |
73 | dec yl | |
74 | brne ultoa6 | |
75 | ||
76 | pop temp | |
77 | pop temp2 | |
78 | pop temp3 | |
79 | pop temp4 | |
80 | pop z_flags | |
81 | pop yl | |
82 | pop yh | |
83 | ret | |
84 | ||
85 | ||
86 | ;Prints temp2:temp in hex to the uart | |
87 | printhexw: | |
88 | push temp | |
89 | mov temp,temp2 | |
90 | rcall printhex | |
91 | pop temp | |
92 | ;fall thru | |
93 | ||
94 | ;Prints temp in hex to the uart | |
95 | printhex: | |
96 | swap temp | |
97 | rcall printhexn | |
98 | swap temp | |
99 | ;fall thru | |
100 | ||
101 | ;Prints the lower nibble | |
102 | printhexn: | |
103 | push temp | |
104 | andi temp,0xf | |
105 | cpi temp,0xA | |
106 | brlo printhexn_isno | |
107 | subi temp,-7 | |
108 | printhexn_isno: | |
109 | subi temp,-'0' | |
110 | rcall uartputc | |
111 | pop temp | |
112 | ret | |
113 | ||
114 | ||
115 | ; Prints a single space | |
116 | ||
117 | dbg_printspace: | |
118 | ldi temp,' ' | |
119 | rjmp uartputc | |
120 | ||
121 | ; Prints 16 bytes pointed to by Z in hex. | |
122 | ||
123 | dbg_hexdump_line: ;Address in z | |
124 | push temp2 | |
125 | push temp | |
126 | printnewline | |
127 | movw temp,z ;Print address | |
128 | rcall printhexw | |
129 | ldi temp2,16 ;16 byte per line | |
130 | rcall dbg_printspace | |
131 | dbg_hdl1: | |
132 | cpi temp2,8 | |
133 | brne PC+2 | |
134 | rcall dbg_printspace | |
135 | ||
136 | rcall dbg_printspace | |
137 | ld temp,z+ | |
138 | rcall printhex | |
139 | dec temp2 | |
140 | brne dbg_hdl1 | |
141 | sbiw z,16 | |
142 | ||
143 | rcall dbg_printspace | |
144 | rcall dbg_printspace | |
145 | ldi temp2,16 | |
146 | dbg_hdl2: | |
147 | ld temp,z+ | |
148 | cpi temp,' ' | |
149 | brlo dbg_hdpd | |
150 | cpi temp,0x7F | |
151 | brlo dbg_hdp | |
152 | dbg_hdpd: | |
153 | ldi temp,'.' | |
154 | dbg_hdp: | |
155 | rcall uartputc | |
156 | dec temp2 | |
157 | brne dbg_hdl2 | |
158 | sbiw z,16 | |
159 | rcall dbg_printspace | |
160 | pop temp | |
161 | pop temp2 | |
162 | ret | |
163 | ||
164 | ||
165 | ;Prints the zero-terminated string following the call statement. | |
166 | ||
167 | printstr: | |
168 | push zh ;SP+5 | |
169 | push zl ; 4 | |
170 | push yh ; 3 | |
171 | push yl ; 2 | |
172 | push temp ; 1 | |
173 | in yh,sph | |
174 | in yl,spl | |
175 | ldd zl,y+7 ;SP+7 == "return adr." == String adr. | |
176 | ldd zh,y+6 ;SP+6 | |
177 | ||
178 | lsl zl ;word to byte conv. | |
179 | rol zh | |
180 | printstr_loop: | |
181 | lpm temp,z+ | |
182 | cpi temp,0 | |
183 | breq printstr_end | |
184 | rcall uartputc | |
185 | cpi temp,13 | |
186 | brne printstr_loop | |
187 | ldi temp,10 | |
188 | rcall uartputc | |
189 | rjmp printstr_loop | |
190 | ||
191 | printstr_end: | |
192 | adiw zl,1 ;rounding up | |
193 | lsr zh ;byte to word conv. | |
194 | ror zl | |
195 | ||
196 | std y+7,zl | |
197 | std y+6,zh | |
198 | pop temp | |
199 | pop yl | |
200 | pop yh | |
201 | pop zl | |
202 | pop zh | |
203 | ret | |
204 | ||
205 | ; --------------- Debugging stuff --------------- | |
206 | ; Print a line with the 8080/Z80 registers | |
207 | ||
208 | printregs: | |
209 | mov temp,z_flags | |
210 | rcall printflags | |
211 | printstring " A =" | |
212 | mov temp,z_a | |
213 | rcall printhex | |
214 | printstring " BC =" | |
215 | ldd temp2,y+oz_b | |
216 | ldd temp,y+oz_c | |
217 | rcall printhexw | |
218 | printstring " DE =" | |
219 | ldd temp2,y+oz_d | |
220 | ldd temp,y+oz_e | |
221 | rcall printhexw | |
222 | printstring " HL =" | |
223 | ldd temp2,y+oz_h | |
224 | ldd temp,y+oz_l | |
225 | rcall printhexw | |
226 | printstring " SP=" | |
227 | movw temp, z_spl | |
228 | rcall printhexw | |
229 | printstring " PC=" | |
230 | movw temp, z_pcl | |
231 | rcall printhexw | |
232 | printstring " " | |
233 | movw xl,z_pcl | |
234 | lcall dram_read_pp | |
235 | rcall printhex | |
236 | printstring " " | |
237 | lcall dram_read_pp | |
238 | rcall printhex | |
239 | printstring " " | |
240 | lcall dram_read | |
241 | rcall printhex | |
242 | printstring " " | |
243 | ||
244 | #if EM_Z80 | |
245 | ldd temp,y+oz_f2 | |
246 | rcall printflags | |
247 | printstring " a'=" | |
248 | ldd temp,y+oz_a2 | |
249 | rcall printhex | |
250 | printstring " bc'=" | |
251 | ldd temp2,y+oz_b2 | |
252 | ldd temp,y+oz_c2 | |
253 | rcall printhexw | |
254 | printstring " de'=" | |
255 | ldd temp2,y+oz_d2 | |
256 | ldd temp,y+oz_e2 | |
257 | rcall printhexw | |
258 | printstring " hl'=" | |
259 | ldd temp2,y+oz_h2 | |
260 | ldd temp,y+oz_l2 | |
261 | rcall printhexw | |
262 | printstring " IX=" | |
263 | ldd temp2,y+oz_xh | |
264 | ldd temp,y+oz_xl | |
265 | rcall printhexw | |
266 | printstring " IY=" | |
267 | ldd temp2,y+oz_yh | |
268 | ldd temp,y+oz_yl | |
269 | rcall printhexw | |
270 | printstring " I=" | |
271 | ldd temp,y+oz_i | |
272 | rcall printhex | |
273 | ||
274 | printstring " " | |
275 | #endif | |
276 | ret | |
277 | ||
278 | ||
279 | #if EM_Z80 | |
280 | zflags_to_ch: | |
281 | .db "SZ H VNC",0,0 | |
282 | #else | |
283 | zflags_to_ch: | |
284 | .db "SZ H PNC",0,0 | |
285 | #endif | |
286 | ||
287 | printflags: | |
288 | push temp2 | |
289 | mov temp2,temp | |
290 | printnewline | |
291 | push zl | |
292 | push zh | |
293 | ldiw z,zflags_to_ch*2 | |
294 | pr_zfl_next: | |
295 | lpm temp,z+ | |
296 | tst temp | |
297 | breq pr_zfl_end | |
298 | cpi temp,' ' ; Test if no flag | |
299 | breq pr_zfl_noflag | |
300 | sbrs temp2,7 ; | |
301 | ldi temp,' ' ; Flag not set | |
302 | rcall uartputc | |
303 | pr_zfl_noflag: | |
304 | rol temp2 | |
305 | rjmp pr_zfl_next | |
306 | pr_zfl_end: | |
307 | pop zh | |
308 | pop zl | |
309 | pop temp2 | |
310 | ret | |
311 | ||
312 | ; vim:set ts=8 noet nowrap | |
313 |