]>
Commit | Line | Data |
---|---|---|
5985ce1c L |
1 | ; Print and Debug functions |
2 | ; | |
e8384f88 | 3 | ; Copyright (C) 2010-2013 Leo C. |
5985ce1c L |
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 | |
825ecc9d | 28 | ; r15:r14:temp2:temp = value |
5985ce1c L |
29 | |
30 | print_ultoa: | |
31 | push yh | |
32 | push yl | |
33 | push z_flags | |
825ecc9d L |
34 | push r15 |
35 | push r14 | |
5985ce1c L |
36 | push temp2 |
37 | push temp | |
38 | ||
39 | clr yl ;yl = stack level | |
40 | ||
825ecc9d L |
41 | ultoa1: ldi z_flags, 32 ;yh = r15:temp % 10 |
42 | clr yh ;r15:temp /= 10 | |
5985ce1c L |
43 | ultoa2: lsl temp |
44 | rol temp2 | |
825ecc9d L |
45 | rol r14 |
46 | rol r15 | |
5985ce1c L |
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 | |
825ecc9d | 58 | cp temp,_0 ;Repeat until r15:temp gets zero |
5985ce1c | 59 | cpc temp2,_0 |
825ecc9d L |
60 | cpc r14,_0 |
61 | cpc r15,_0 | |
5985ce1c L |
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 | |
825ecc9d L |
78 | pop r14 |
79 | pop r15 | |
5985ce1c L |
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 | ||
dd7aea8c L |
114 | |
115 | ; Prints a single space | |
116 | ||
e8384f88 | 117 | printspace: |
dd7aea8c | 118 | push temp |
e8384f88 | 119 | ldi temp,' ' |
dd7aea8c | 120 | rcall uartputc |
dd7aea8c | 121 | pop temp |
dd7aea8c | 122 | ret |
e8384f88 | 123 | |
98979541 | 124 | ;----------------------------------------------------------------------- |
5985ce1c L |
125 | ;Prints the zero-terminated string following the call statement. |
126 | ||
127 | printstr: | |
5482d75f L |
128 | push zh ;SP+5 |
129 | push zl ; 4 | |
130 | push yh ; 3 | |
131 | push yl ; 2 | |
132 | push temp ; 1 | |
5985ce1c L |
133 | in yh,sph |
134 | in yl,spl | |
5482d75f L |
135 | ldd zl,y+7 ;SP+7 == "return adr." == String adr. |
136 | ldd zh,y+6 ;SP+6 | |
5985ce1c | 137 | |
5482d75f | 138 | lsl zl ;word to byte conv. |
5985ce1c L |
139 | rol zh |
140 | printstr_loop: | |
141 | lpm temp,z+ | |
142 | cpi temp,0 | |
143 | breq printstr_end | |
144 | rcall uartputc | |
145 | cpi temp,13 | |
146 | brne printstr_loop | |
147 | ldi temp,10 | |
148 | rcall uartputc | |
149 | rjmp printstr_loop | |
150 | ||
151 | printstr_end: | |
5482d75f L |
152 | adiw zl,1 ;rounding up |
153 | lsr zh ;byte to word conv. | |
5985ce1c L |
154 | ror zl |
155 | ||
156 | std y+7,zl | |
157 | std y+6,zh | |
158 | pop temp | |
159 | pop yl | |
160 | pop yh | |
161 | pop zl | |
162 | pop zh | |
163 | ret | |
164 | ||
623dd899 L |
165 | ; ------------------------ String functions ------------------------- |
166 | ; | |
167 | ||
168 | #if 0 | |
169 | ; String compare (z, y), one z-string in flash. | |
170 | ||
171 | strcmp_p: | |
98979541 | 172 | ld temp,y+ |
623dd899 L |
173 | lpm _tmp0, z+ |
174 | sub temp,_tmp0 | |
175 | brne strcmp_pex | |
176 | tst _tmp0 | |
177 | brne strcmp_p | |
98979541 | 178 | sub temp,temp |
623dd899 L |
179 | strcmp_pex: |
180 | ret | |
98979541 L |
181 | |
182 | #endif | |
183 | ||
184 | #if 0 | |
185 | ||
186 | strcmp_p: | |
187 | ld temp,y+ | |
188 | lpm _tmp0,z+ | |
189 | sub temp,_tmp0 | |
190 | cpse _tmp0,_0 | |
191 | breq strcmp_p | |
192 | ret | |
193 | ||
194 | ||
623dd899 L |
195 | #endif |
196 | ||
98979541 | 197 | ;----------------------------------------------------------------------- |
623dd899 L |
198 | ; String compare (x, y, temp2). Max temp2 bytes are compared. |
199 | ||
200 | strncmp_p: | |
201 | subi temp2,1 | |
202 | brcs strncmp_peq | |
203 | ld temp,y+ | |
204 | lpm _tmp0, z+ | |
205 | sub temp,_tmp0 | |
206 | brne strncmp_pex | |
207 | tst _tmp0 | |
208 | brne strncmp_p | |
209 | strncmp_peq: | |
210 | sub temp,temp | |
211 | strncmp_pex: | |
212 | ret | |
213 | ||
98979541 L |
214 | ;----------------------------------------------------------------------- |
215 | ; Memory compare: DRAM - AVR-RAM | |
216 | ; DRAM-Addr. in x, AVRRAM-Addr. in y | |
217 | ; Compare temp3 bytes. | |
218 | ; | |
219 | ; Return Z-Flag == 1 if match | |
220 | ; temp, _tmp0 destroyed | |
221 | ; | |
222 | ||
223 | memcmp_d: | |
224 | rcall dram_read_pp | |
225 | ld _tmp0,y+ | |
226 | cp temp,_tmp0 | |
227 | brne memcmpd_nomatch | |
228 | dec temp3 | |
229 | brne memcmp_d | |
230 | memcmpd_nomatch: | |
231 | ret | |
623dd899 | 232 | |
5985ce1c | 233 | ; --------------- Debugging stuff --------------- |
98979541 L |
234 | |
235 | ||
236 | .if SRAM_FILL | |
237 | ||
238 | stackusage_print: | |
239 | ldiw z,ramtop | |
240 | ldi temp, low(RAMEND+1) | |
241 | ldi temp2,high(RAMEND+1) | |
242 | ldi temp3,SRAMFILL_VAL | |
243 | stack_search_l: | |
244 | ld _tmp0,z+ | |
245 | cp temp3,_tmp0 | |
246 | brne stack_search_found | |
247 | cp zl,temp | |
248 | cpc zh,temp2 | |
249 | brne stack_search_l | |
250 | ||
251 | stack_search_found: | |
252 | sbiw z,1 | |
253 | sub temp, zl | |
254 | sbc temp2,zh | |
255 | printnewline | |
256 | printstring "Stack used (bytes): " | |
257 | push r15 | |
258 | push r14 | |
259 | clr r14 | |
260 | clr r15 | |
261 | rcall print_ultoa | |
262 | pop r14 | |
263 | pop r15 | |
264 | ret | |
265 | .endif | |
266 | ||
267 | ||
268 | ||
e8384f88 L |
269 | ;----------------------------------------------------------------------- |
270 | ; Prints 16 bytes RAM, pointed to by Z in hex. | |
271 | ||
272 | #if 0 | |
273 | ||
274 | dbg_hexdump_line: ;Address in z | |
275 | push temp2 | |
276 | push temp | |
277 | printnewline | |
278 | movw temp,z ;Print address | |
279 | rcall printhexw | |
280 | ldi temp2,16 ;16 byte per line | |
281 | rcall printspace | |
282 | dbg_hdl1: | |
283 | cpi temp2,8 | |
284 | brne PC+2 | |
285 | rcall printspace | |
286 | ||
287 | rcall printspace | |
288 | ld temp,z+ | |
289 | rcall printhex | |
290 | dec temp2 | |
291 | brne dbg_hdl1 | |
292 | sbiw z,16 | |
293 | ||
294 | rcall printspace | |
295 | rcall printspace | |
296 | ldi temp2,16 | |
297 | dbg_hdl2: | |
298 | ld temp,z+ | |
299 | cpi temp,' ' | |
300 | brlo dbg_hdpd | |
301 | cpi temp,0x7F | |
302 | brlo dbg_hdp | |
303 | dbg_hdpd: | |
304 | ldi temp,'.' | |
305 | dbg_hdp: | |
306 | rcall uartputc | |
307 | dec temp2 | |
308 | brne dbg_hdl2 | |
309 | sbiw z,16 | |
310 | rcall printspace | |
311 | pop temp | |
312 | pop temp2 | |
313 | ret | |
314 | #endif | |
315 | ||
98979541 | 316 | ;----------------------------------------------------------------------- |
80e1fa71 | 317 | ; Print a line with the 8080/Z80 registers |
5985ce1c | 318 | |
5985ce1c | 319 | printregs: |
80e1fa71 L |
320 | mov temp,z_flags |
321 | rcall printflags | |
5985ce1c L |
322 | printstring " A =" |
323 | mov temp,z_a | |
324 | rcall printhex | |
325 | printstring " BC =" | |
825ecc9d L |
326 | #if 1 |
327 | movw temp,z_c | |
328 | #else | |
e7a0f403 L |
329 | ldd temp2,y+oz_b |
330 | ldd temp,y+oz_c | |
825ecc9d | 331 | #endif |
5985ce1c L |
332 | rcall printhexw |
333 | printstring " DE =" | |
825ecc9d L |
334 | #if 1 |
335 | movw temp,z_e | |
336 | #else | |
e7a0f403 L |
337 | ldd temp2,y+oz_d |
338 | ldd temp,y+oz_e | |
825ecc9d | 339 | #endif |
5985ce1c L |
340 | rcall printhexw |
341 | printstring " HL =" | |
825ecc9d L |
342 | #if 1 |
343 | movw temp,z_l | |
344 | #else | |
e7a0f403 | 345 | ldd temp,y+oz_l |
825ecc9d L |
346 | ldd temp2,y+oz_h |
347 | #endif | |
5985ce1c | 348 | rcall printhexw |
80e1fa71 | 349 | printstring " SP=" |
5985ce1c L |
350 | movw temp, z_spl |
351 | rcall printhexw | |
80e1fa71 | 352 | printstring " PC=" |
5985ce1c L |
353 | movw temp, z_pcl |
354 | rcall printhexw | |
355 | printstring " " | |
356 | movw xl,z_pcl | |
096f3a91 | 357 | lcall dram_read_pp |
5985ce1c L |
358 | rcall printhex |
359 | printstring " " | |
096f3a91 | 360 | lcall dram_read_pp |
5985ce1c L |
361 | rcall printhex |
362 | printstring " " | |
096f3a91 | 363 | lcall dram_read |
5985ce1c L |
364 | rcall printhex |
365 | printstring " " | |
80e1fa71 L |
366 | |
367 | #if EM_Z80 | |
e7a0f403 | 368 | ldd temp,y+oz_f2 |
80e1fa71 | 369 | rcall printflags |
096f3a91 | 370 | printstring " a'=" |
e7a0f403 | 371 | ldd temp,y+oz_a2 |
80e1fa71 | 372 | rcall printhex |
096f3a91 | 373 | printstring " bc'=" |
e7a0f403 L |
374 | ldd temp2,y+oz_b2 |
375 | ldd temp,y+oz_c2 | |
80e1fa71 | 376 | rcall printhexw |
096f3a91 | 377 | printstring " de'=" |
e7a0f403 L |
378 | ldd temp2,y+oz_d2 |
379 | ldd temp,y+oz_e2 | |
80e1fa71 | 380 | rcall printhexw |
096f3a91 | 381 | printstring " hl'=" |
e7a0f403 L |
382 | ldd temp2,y+oz_h2 |
383 | ldd temp,y+oz_l2 | |
80e1fa71 L |
384 | rcall printhexw |
385 | printstring " IX=" | |
e7a0f403 L |
386 | ldd temp2,y+oz_xh |
387 | ldd temp,y+oz_xl | |
80e1fa71 L |
388 | rcall printhexw |
389 | printstring " IY=" | |
e7a0f403 L |
390 | ldd temp2,y+oz_yh |
391 | ldd temp,y+oz_yl | |
80e1fa71 L |
392 | rcall printhexw |
393 | printstring " I=" | |
e7a0f403 | 394 | ldd temp,y+oz_i |
80e1fa71 L |
395 | rcall printhex |
396 | ||
397 | printstring " " | |
398 | #endif | |
399 | ret | |
400 | ||
401 | ||
402 | #if EM_Z80 | |
403 | zflags_to_ch: | |
404 | .db "SZ H VNC",0,0 | |
405 | #else | |
406 | zflags_to_ch: | |
407 | .db "SZ H PNC",0,0 | |
408 | #endif | |
409 | ||
410 | printflags: | |
411 | push temp2 | |
412 | mov temp2,temp | |
413 | printnewline | |
414 | push zl | |
415 | push zh | |
416 | ldiw z,zflags_to_ch*2 | |
417 | pr_zfl_next: | |
418 | lpm temp,z+ | |
419 | tst temp | |
420 | breq pr_zfl_end | |
421 | cpi temp,' ' ; Test if no flag | |
422 | breq pr_zfl_noflag | |
423 | sbrs temp2,7 ; | |
424 | ldi temp,' ' ; Flag not set | |
425 | rcall uartputc | |
426 | pr_zfl_noflag: | |
427 | rol temp2 | |
428 | rjmp pr_zfl_next | |
429 | pr_zfl_end: | |
430 | pop zh | |
431 | pop zl | |
432 | pop temp2 | |
5985ce1c | 433 | ret |
5985ce1c L |
434 | |
435 | ; vim:set ts=8 noet nowrap | |
436 |