]>
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 | ||
62 | ;------------------------------------------------ | |
63 | ; add 16 bit constant to register pair | |
64 | ||
65 | .macro addiw | |
66 | subi @0l, low(-@1) | |
67 | sbci @0h, high(-@1) | |
68 | .endm | |
69 | ||
4675c141 L |
70 | ;------------------------------------------------ |
71 | ; sub 16 bit constant from register pair | |
72 | ||
73 | .macro subiw | |
74 | subi @0l, low(@1) | |
75 | sbci @0h, high(@1) | |
76 | .endm | |
77 | ||
9c15f366 L |
78 | ;------------------------------------------------ |
79 | ; Move single bit between two registers | |
80 | ; | |
81 | ; bmov dstreg,dstbit,srcreg.srcbit | |
82 | ||
83 | .macro bmov | |
84 | bst @2,@3 | |
85 | bld @0,@1 | |
86 | .endm | |
87 | ||
4675c141 L |
88 | ;------------------------------------------------ |
89 | ; | |
90 | ; | |
91 | ; | |
92 | .macro INTERRUPT | |
93 | .set pos_ = PC | |
94 | .org @0 ; vector address | |
95 | .if abs(pos_ - PC) > 2048 | |
96 | jmp pos_ | |
97 | .else | |
98 | rjmp pos_ ; jump to handler | |
99 | .endif | |
100 | .org pos_ ; restore PC | |
101 | .endm | |
102 | ||
b741422e L |
103 | ;------------------------------------------------ |
104 | ; | |
105 | ; | |
106 | .macro ljmp | |
107 | .if FLASHEND > 0x0fff | |
108 | jmp @0 | |
109 | .else | |
110 | rjmp @0 | |
111 | .endif | |
112 | .endm | |
113 | ||
114 | ;------------------------------------------------ | |
115 | ; | |
116 | ; | |
117 | .macro lcall | |
118 | .if FLASHEND > 0x0fff | |
119 | ; call @0 | |
120 | ||
121 | .ifdef @0 | |
122 | .if abs(PC - @0) > 2048 | |
123 | call @0 | |
124 | .else | |
125 | rcall @0 | |
126 | .endif | |
127 | .else | |
128 | call @0 | |
129 | .endif | |
130 | .else | |
131 | rcall @0 | |
132 | .endif | |
133 | .endm | |
134 | ||
9c15f366 L |
135 | ;------------------------------------------------ |
136 | ; Print string. | |
137 | ; printstring "String" | |
138 | ||
139 | .macro printstring | |
64219415 | 140 | call printstr |
9c15f366 L |
141 | .if strlen(@0) % 2 |
142 | .db @0,0 | |
143 | .else | |
144 | .db @0,0,0 | |
145 | .endif | |
146 | .endm | |
147 | ||
148 | ;------------------------------------------------ | |
149 | ; Print newline | |
150 | ; print cr, lf | |
151 | ||
152 | .macro printnewline | |
b741422e | 153 | lcall printstr |
9c15f366 L |
154 | .db 13,0 |
155 | .endm | |
156 | ||
157 | ||
158 | ;------------------------------------------------ | |
159 | ; Print a Z80 flag | |
160 | ; print_zflag F | |
161 | ; where F is the flag to print | |
162 | ||
163 | .macro print_zflag | |
164 | ||
165 | .set S_ = 'S' | |
166 | .set Z_ = 'Z' | |
167 | .set H_ = 'H' | |
168 | .set P_ = 'P' | |
169 | .set N_ = 'N' | |
170 | .set C_ = 'C' | |
171 | ||
172 | ldi temp, ' ' | |
173 | sbrc z_flags,ZFL_@0 | |
174 | ldi temp, @0_ | |
175 | rcall uartputc | |
176 | .endm | |
177 | ||
178 | ;------------------------------------------------ | |
179 | ; db_version VMAJOR, VMINOR | |
180 | ||
181 | .macro db_version | |
182 | ||
183 | .set maj1_ = @0 / 10 | |
184 | .set maj0_ = @0 % 10 | |
185 | .set min1_ = @1 / 10 | |
186 | .set min0_ = @1 % 10 | |
187 | ||
188 | .if maj1_ | |
189 | .if min1_ | |
190 | .db maj1_+'0',maj0_+'0','.',min1_+'0',min0_+'0',0 | |
191 | .else | |
192 | .db maj1_+'0',maj0_+'0','.', min0_+'0',0,0 | |
193 | .endif | |
194 | .else | |
195 | .if min1_ | |
196 | .db maj0_+'0','.',min1_+'0',min0_+'0',0,0 | |
197 | .else | |
198 | .db maj0_+'0','.', min0_+'0',0 | |
199 | .endif | |
200 | .endif | |
201 | .endm | |
202 | ||
203 | ; vim:set ts=8 noet nowrap | |
204 |