]>
Commit | Line | Data |
---|---|---|
1 | ; Commonly used macros | |
2 | ; | |
3 | ; Copyright (C) 2010,2012,2013 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: macros.inc 241 2015-12-10 09:38:25Z rapid $ | |
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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
104 | ;------------------------------------------------ | |
105 | ; | |
106 | ; | |
107 | ; | |
108 | .macro INTERRUPT | |
109 | .set pos_ = PC ;save current position | |
110 | .org @0 ;vector address | |
111 | .set dist_ = pos_ - (PC+1) | |
112 | ||
113 | .if dist_ <= 2048 | |
114 | rjmp pos_ | |
115 | .elif (dist_ - (FLASHEND+1)) > -2048 | |
116 | .set disp_ = (dist_ - (FLASHEND+1)) & 0xFFF | |
117 | ; rjmp pos_ - (FLASHEND+1) | |
118 | .dw 0xC000 | disp_ | |
119 | .else | |
120 | jmp pos_ ;jump to handler | |
121 | .endif | |
122 | ||
123 | .org pos_ ;restore PC | |
124 | .endm | |
125 | ||
126 | ;------------------------------------------------ | |
127 | ; | |
128 | ; | |
129 | ||
130 | #if 1 | |
131 | ||
132 | .macro ljmp | |
133 | .if FLASHEND > 0x0fff | |
134 | .ifdef @0 | |
135 | .set dist_ = @0 - (PC+1) | |
136 | .if dist_ < 0 | |
137 | .if dist_ >= -2048 | |
138 | rjmp @0 | |
139 | .elif dist_ < -(FLASHEND+1-2048) | |
140 | .dw 0xC000 | (dist_ + (FLASHEND+1)) & 0xFFF | |
141 | .else | |
142 | jmp @0 | |
143 | .endif | |
144 | .else ; >0 | |
145 | .if (dist_ < 2048) | |
146 | rjmp @0 | |
147 | .elif dist_ > (FLASHEND+1-2048) | |
148 | .dw 0xC000 | (dist_ - (FLASHEND+1)) & 0xFFF | |
149 | .else | |
150 | jmp @0 | |
151 | .endif | |
152 | .endif | |
153 | .else ; not def @0 | |
154 | jmp @0 | |
155 | .endif | |
156 | .else ; <= 0x0fff | |
157 | rjmp @0 | |
158 | .endif | |
159 | .endm | |
160 | ||
161 | #else | |
162 | ||
163 | .macro ljmp | |
164 | .if FLASHEND > 0x0fff | |
165 | .ifdef @0 | |
166 | .if abs(PC - @0) > 2047 | |
167 | jmp @0 | |
168 | .else | |
169 | rjmp @0 | |
170 | .endif | |
171 | .else | |
172 | jmp @0 | |
173 | .endif | |
174 | .else | |
175 | rjmp @0 | |
176 | .endif | |
177 | .endm | |
178 | #endif | |
179 | ||
180 | ;------------------------------------------------ | |
181 | ; | |
182 | ; | |
183 | .macro lcall | |
184 | .if FLASHEND > 0x0fff | |
185 | .ifdef @0 | |
186 | .set dist_ = @0 - (PC+1) | |
187 | .if dist_ < 0 | |
188 | .if dist_ >= -2048 | |
189 | rcall @0 | |
190 | .elif dist_ < -(FLASHEND+1-2048) | |
191 | .dw 0xC000 | (dist_ + (FLASHEND+1)) & 0xFFF | |
192 | .else | |
193 | call @0 | |
194 | .endif | |
195 | .else ; >0 | |
196 | .if (dist_ < 2048) | |
197 | rcall @0 | |
198 | .elif dist_ > (FLASHEND+1-2048) | |
199 | .dw 0xC000 | (dist_ - (FLASHEND+1)) & 0xFFF | |
200 | .else | |
201 | call @0 | |
202 | .endif | |
203 | .endif | |
204 | .else ; not def @0 | |
205 | call @0 | |
206 | .endif | |
207 | .else ; <= 0x0fff | |
208 | rcall @0 | |
209 | .endif | |
210 | .endm | |
211 | ||
212 | ;------------------------------------------------ | |
213 | ; Make string. | |
214 | ; makestring "String" | |
215 | ||
216 | .macro makestring | |
217 | .if strlen(@0) % 2 | |
218 | .db @0,0 | |
219 | .else | |
220 | .db @0,0,0 | |
221 | .endif | |
222 | .endm | |
223 | ||
224 | ;------------------------------------------------ | |
225 | ; Print string. | |
226 | ; printstring "String" | |
227 | ||
228 | .macro printstring | |
229 | lcall printstr | |
230 | .if strlen(@0) % 2 | |
231 | .db @0,0 | |
232 | .else | |
233 | .db @0,0,0 | |
234 | .endif | |
235 | .endm | |
236 | ||
237 | ;------------------------------------------------ | |
238 | ; Print newline | |
239 | ; print cr, lf | |
240 | ||
241 | .macro printnewline | |
242 | lcall printstr | |
243 | .db 13,0 | |
244 | .endm | |
245 | ||
246 | ||
247 | ;------------------------------------------------ | |
248 | ; Print a Z80 flag | |
249 | ; print_zflag F | |
250 | ; where F is the flag to print | |
251 | ||
252 | .macro print_zflag | |
253 | ||
254 | .set S_ = 'S' | |
255 | .set Z_ = 'Z' | |
256 | .set H_ = 'H' | |
257 | .set P_ = 'P' | |
258 | .set N_ = 'N' | |
259 | .set C_ = 'C' | |
260 | ||
261 | ldi temp, ' ' | |
262 | sbrc z_flags,ZFL_@0 | |
263 | ldi temp, @0_ | |
264 | rcall uartputc | |
265 | .endm | |
266 | ||
267 | ;------------------------------------------------ | |
268 | ; db_version VMAJOR, VMINOR | |
269 | ||
270 | .macro db_version | |
271 | ||
272 | .set maj1_ = @0 / 10 | |
273 | .set maj0_ = @0 % 10 | |
274 | .set min1_ = @1 / 10 | |
275 | .set min0_ = @1 % 10 | |
276 | ||
277 | .if maj1_ | |
278 | .if min1_ | |
279 | .db maj1_+'0',maj0_+'0','.',min1_+'0',min0_+'0',0 | |
280 | .else | |
281 | .db maj1_+'0',maj0_+'0','.', min0_+'0',0,0 | |
282 | .endif | |
283 | .else | |
284 | .if min1_ | |
285 | .db maj0_+'0','.',min1_+'0',min0_+'0',0,0 | |
286 | .else | |
287 | .db maj0_+'0','.', min0_+'0',0 | |
288 | .endif | |
289 | .endif | |
290 | .endm | |
291 | ||
292 | ; vim:set ts=8 noet nowrap |