]> cloudbase.mooo.com Git - avrcpm.git/blame - avrcpm/avr/macros.inc
* Rest of 'remainders.asm' split:
[avrcpm.git] / avrcpm / avr / macros.inc
CommitLineData
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
9c15f366
L
103;------------------------------------------------
104; Print string.
105; printstring "String"
106
107.macro printstring
64219415 108 call printstr
9c15f366
L
109 .if strlen(@0) % 2
110 .db @0,0
111 .else
112 .db @0,0,0
113 .endif
114.endm
115
116;------------------------------------------------
117; Print newline
118; print cr, lf
119
120.macro printnewline
121 rcall printstr
122 .db 13,0
123.endm
124
125
126;------------------------------------------------
127; Print a Z80 flag
128; print_zflag F
129; where F is the flag to print
130
131.macro print_zflag
132
133.set S_ = 'S'
134.set Z_ = 'Z'
135.set H_ = 'H'
136.set P_ = 'P'
137.set N_ = 'N'
138.set C_ = 'C'
139
140 ldi temp, ' '
141 sbrc z_flags,ZFL_@0
142 ldi temp, @0_
143 rcall uartputc
144.endm
145
146;------------------------------------------------
147; db_version VMAJOR, VMINOR
148
149.macro db_version
150
151 .set maj1_ = @0 / 10
152 .set maj0_ = @0 % 10
153 .set min1_ = @1 / 10
154 .set min0_ = @1 % 10
155
156 .if maj1_
157 .if min1_
158 .db maj1_+'0',maj0_+'0','.',min1_+'0',min0_+'0',0
159 .else
160 .db maj1_+'0',maj0_+'0','.', min0_+'0',0,0
161 .endif
162 .else
163 .if min1_
164 .db maj0_+'0','.',min1_+'0',min0_+'0',0,0
165 .else
166 .db maj0_+'0','.', min0_+'0',0
167 .endif
168 .endif
169.endm
170
171; vim:set ts=8 noet nowrap
172