]> cloudbase.mooo.com Git - avrcpm.git/blob - utils.asm
* Test: change directory hierarchy.
[avrcpm.git] / utils.asm
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 ;Prints the zero-terminated string following the call statement.
115
116 printstr:
117 push zh
118 push zl
119 push yh
120 push yl
121 push temp
122 in yh,sph
123 in yl,spl
124 ldd zl,y+7
125 ldd zh,y+6
126
127 lsl zl
128 rol zh
129 printstr_loop:
130 lpm temp,z+
131 cpi temp,0
132 breq printstr_end
133 rcall uartputc
134 cpi temp,13
135 brne printstr_loop
136 ldi temp,10
137 rcall uartputc
138 rjmp printstr_loop
139
140 printstr_end:
141 adiw zl,1 ;rounding
142 lsr zh
143 ror zl
144
145 std y+7,zl
146 std y+6,zh
147 pop temp
148 pop yl
149 pop yh
150 pop zl
151 pop zh
152 ret
153
154 ; --------------- Debugging stuff ---------------
155 ; Print a line with the Z80 main registers
156
157 ;.if INS_DEBUG
158
159 zflags_to_ch:
160 .db "SZ H PNC",0,0
161
162 printregs:
163 printnewline
164
165 push zl
166 push zh
167 ldiw z,zflags_to_ch*2
168 mov temp2,z_flags
169 pr_zfl_next:
170 lpm temp,z+
171 tst temp
172 breq pr_zfl_end
173 cpi temp,' ' ; Test if no flag
174 breq pr_zfl_noflag
175 sbrs temp2,7 ;
176 ldi temp,' ' ; Flag not set
177 rcall uartputc
178 pr_zfl_noflag:
179 rol temp2
180 rjmp pr_zfl_next
181 pr_zfl_end:
182 pop zh
183 pop zl
184
185 printstring " A ="
186 mov temp,z_a
187 rcall printhex
188 printstring " BC ="
189 lds temp2,z_b
190 lds temp, z_c
191 rcall printhexw
192 printstring " DE ="
193 lds temp2,z_d
194 lds temp, z_e
195 rcall printhexw
196 printstring " HL ="
197 lds temp2,z_h
198 lds temp, z_l
199 rcall printhexw
200 printstring " SP ="
201 movw temp, z_spl
202 rcall printhexw
203 printstring " PC ="
204 movw temp, z_pcl
205 rcall printhexw
206 printstring " "
207 movw xl,z_pcl
208 mem_read
209 rcall printhex
210 printstring " "
211 adiw x,1
212 mem_read
213 rcall printhex
214 printstring " "
215 adiw x,1
216 mem_read
217 rcall printhex
218 printstring " "
219 ret
220 ;.endif
221
222 ; vim:set ts=8 noet nowrap
223