]> cloudbase.mooo.com Git - avrcpm.git/blob - avrcpm/avr/macros.inc
* avr/dsk_fat16.asm
[avrcpm.git] / avrcpm / avr / macros.inc
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
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
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
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
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
135 ;------------------------------------------------
136 ; Print string.
137 ; printstring "String"
138
139 .macro printstring
140 .if FLASHEND > 0x0fff
141 call printstr
142 .else
143 rcall printstr
144 .endif
145 .if strlen(@0) % 2
146 .db @0,0
147 .else
148 .db @0,0,0
149 .endif
150 .endm
151
152 ;------------------------------------------------
153 ; Print newline
154 ; print cr, lf
155
156 .macro printnewline
157 lcall printstr
158 .db 13,0
159 .endm
160
161
162 ;------------------------------------------------
163 ; Print a Z80 flag
164 ; print_zflag F
165 ; where F is the flag to print
166
167 .macro print_zflag
168
169 .set S_ = 'S'
170 .set Z_ = 'Z'
171 .set H_ = 'H'
172 .set P_ = 'P'
173 .set N_ = 'N'
174 .set C_ = 'C'
175
176 ldi temp, ' '
177 sbrc z_flags,ZFL_@0
178 ldi temp, @0_
179 rcall uartputc
180 .endm
181
182 ;------------------------------------------------
183 ; db_version VMAJOR, VMINOR
184
185 .macro db_version
186
187 .set maj1_ = @0 / 10
188 .set maj0_ = @0 % 10
189 .set min1_ = @1 / 10
190 .set min0_ = @1 % 10
191
192 .if maj1_
193 .if min1_
194 .db maj1_+'0',maj0_+'0','.',min1_+'0',min0_+'0',0
195 .else
196 .db maj1_+'0',maj0_+'0','.', min0_+'0',0,0
197 .endif
198 .else
199 .if min1_
200 .db maj0_+'0','.',min1_+'0',min0_+'0',0,0
201 .else
202 .db maj0_+'0','.', min0_+'0',0
203 .endif
204 .endif
205 .endm
206
207 ; vim:set ts=8 noet nowrap
208