]>
Commit | Line | Data |
---|---|---|
9c15f366 L |
1 | ; Commonly used macros |
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 | .macro outm8 | |
26 | .if @0 > 0x3f | |
27 | sts @0,@1 | |
28 | .else | |
29 | out @0,@1 | |
30 | .endif | |
31 | .endm | |
32 | ||
33 | ;------------------------------------------------ | |
34 | ; | |
35 | .macro inm8 | |
36 | .if @1 > 0x3f | |
37 | lds @0,@1 | |
38 | .else | |
39 | in @0,@1 | |
40 | .endif | |
41 | .endm | |
42 | ||
43 | ;------------------------------------------------ | |
44 | ; | |
45 | .macro sbism8 | |
46 | .if @0 > 0x1f | |
47 | in _tmp0,@0 | |
48 | sbrs _tmp0,@1 | |
49 | .else | |
50 | sbis @0,@1 | |
51 | .endif | |
52 | .endm | |
53 | ||
54 | ;------------------------------------------------ | |
55 | ; load 16 bit constant to register pair | |
56 | ||
57 | .macro ldiw | |
58 | ldi @0l, low(@1) | |
59 | ldi @0h, high(@1) | |
60 | .endm | |
61 | ||
e832c81a L |
62 | ;------------------------------------------------ |
63 | ; load 16 bit direct from data space | |
64 | ||
65 | .macro ldsw | |
66 | lds @0l, @1 | |
67 | lds @0h, @1+1 | |
68 | .endm | |
69 | ||
70 | ;------------------------------------------------ | |
71 | ; store 16 bit direct to data space | |
72 | ||
73 | .macro stsw | |
74 | sts @0, @1l | |
75 | sts @0+1,@1h | |
76 | .endm | |
77 | ||
9c15f366 L |
78 | ;------------------------------------------------ |
79 | ; add 16 bit constant to register pair | |
80 | ||
81 | .macro addiw | |
82 | subi @0l, low(-@1) | |
83 | sbci @0h, high(-@1) | |
84 | .endm | |
85 | ||
4675c141 L |
86 | ;------------------------------------------------ |
87 | ; sub 16 bit constant from register pair | |
88 | ||
89 | .macro subiw | |
90 | subi @0l, low(@1) | |
91 | sbci @0h, high(@1) | |
92 | .endm | |
93 | ||
9c15f366 L |
94 | ;------------------------------------------------ |
95 | ; Move single bit between two registers | |
96 | ; | |
97 | ; bmov dstreg,dstbit,srcreg.srcbit | |
98 | ||
99 | .macro bmov | |
100 | bst @2,@3 | |
101 | bld @0,@1 | |
102 | .endm | |
103 | ||
4675c141 L |
104 | ;------------------------------------------------ |
105 | ; | |
106 | ; | |
107 | ; | |
108 | .macro INTERRUPT | |
109 | .set pos_ = PC | |
110 | .org @0 ; vector address | |
111 | .if abs(pos_ - PC) > 2048 | |
112 | jmp pos_ | |
113 | .else | |
114 | rjmp pos_ ; jump to handler | |
115 | .endif | |
116 | .org pos_ ; restore PC | |
117 | .endm | |
118 | ||
b741422e L |
119 | ;------------------------------------------------ |
120 | ; | |
121 | ; | |
122 | .macro ljmp | |
123 | .if FLASHEND > 0x0fff | |
124 | jmp @0 | |
125 | .else | |
126 | rjmp @0 | |
127 | .endif | |
128 | .endm | |
129 | ||
130 | ;------------------------------------------------ | |
131 | ; | |
132 | ; | |
133 | .macro lcall | |
134 | .if FLASHEND > 0x0fff | |
135 | ; call @0 | |
136 | ||
137 | .ifdef @0 | |
e832c81a | 138 | .if abs(PC - @0) > 2047 |
b741422e L |
139 | call @0 |
140 | .else | |
141 | rcall @0 | |
142 | .endif | |
143 | .else | |
144 | call @0 | |
145 | .endif | |
146 | .else | |
147 | rcall @0 | |
148 | .endif | |
149 | .endm | |
150 | ||
9c15f366 L |
151 | ;------------------------------------------------ |
152 | ; Print string. | |
153 | ; printstring "String" | |
154 | ||
155 | .macro printstring | |
3f75a0d3 L |
156 | .if FLASHEND > 0x0fff |
157 | call printstr | |
158 | .else | |
159 | rcall printstr | |
160 | .endif | |
9c15f366 L |
161 | .if strlen(@0) % 2 |
162 | .db @0,0 | |
163 | .else | |
164 | .db @0,0,0 | |
165 | .endif | |
166 | .endm | |
167 | ||
168 | ;------------------------------------------------ | |
169 | ; Print newline | |
170 | ; print cr, lf | |
171 | ||
172 | .macro printnewline | |
b741422e | 173 | lcall printstr |
9c15f366 L |
174 | .db 13,0 |
175 | .endm | |
176 | ||
177 | ||
178 | ;------------------------------------------------ | |
179 | ; Print a Z80 flag | |
180 | ; print_zflag F | |
181 | ; where F is the flag to print | |
182 | ||
183 | .macro print_zflag | |
184 | ||
185 | .set S_ = 'S' | |
186 | .set Z_ = 'Z' | |
187 | .set H_ = 'H' | |
188 | .set P_ = 'P' | |
189 | .set N_ = 'N' | |
190 | .set C_ = 'C' | |
191 | ||
192 | ldi temp, ' ' | |
193 | sbrc z_flags,ZFL_@0 | |
194 | ldi temp, @0_ | |
195 | rcall uartputc | |
196 | .endm | |
197 | ||
198 | ;------------------------------------------------ | |
199 | ; db_version VMAJOR, VMINOR | |
200 | ||
201 | .macro db_version | |
202 | ||
203 | .set maj1_ = @0 / 10 | |
204 | .set maj0_ = @0 % 10 | |
205 | .set min1_ = @1 / 10 | |
206 | .set min0_ = @1 % 10 | |
207 | ||
208 | .if maj1_ | |
209 | .if min1_ | |
210 | .db maj1_+'0',maj0_+'0','.',min1_+'0',min0_+'0',0 | |
211 | .else | |
212 | .db maj1_+'0',maj0_+'0','.', min0_+'0',0,0 | |
213 | .endif | |
214 | .else | |
215 | .if min1_ | |
216 | .db maj0_+'0','.',min1_+'0',min0_+'0',0,0 | |
217 | .else | |
218 | .db maj0_+'0','.', min0_+'0',0 | |
219 | .endif | |
220 | .endif | |
221 | .endm | |
222 | ||
223 | ; vim:set ts=8 noet nowrap | |
224 |