]>
Commit | Line | Data |
---|---|---|
f0d2aa0e 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 | ||
70 | ;------------------------------------------------ | |
71 | ; Move single bit between two registers | |
72 | ; | |
73 | ; bmov dstreg,dstbit,srcreg.srcbit | |
74 | ||
75 | .macro bmov | |
76 | bst @2,@3 | |
77 | bld @0,@1 | |
78 | .endm | |
79 | ||
80 | ;------------------------------------------------ | |
81 | ; Print string. | |
82 | ; printstring "String" | |
83 | ||
84 | .macro printstring | |
8b13b36c | 85 | call printstr |
f0d2aa0e L |
86 | .if strlen(@0) % 2 |
87 | .db @0,0 | |
88 | .else | |
89 | .db @0,0,0 | |
90 | .endif | |
91 | .endm | |
92 | ||
93 | ;------------------------------------------------ | |
94 | ; Print newline | |
95 | ; print cr, lf | |
96 | ||
97 | .macro printnewline | |
98 | rcall printstr | |
99 | .db 13,0 | |
100 | .endm | |
101 | ||
102 | ||
103 | ;------------------------------------------------ | |
104 | ; Print a Z80 flag | |
105 | ; print_zflag F | |
106 | ; where F is the flag to print | |
107 | ||
108 | .macro print_zflag | |
109 | ||
110 | .set S_ = 'S' | |
111 | .set Z_ = 'Z' | |
112 | .set H_ = 'H' | |
113 | .set P_ = 'P' | |
114 | .set N_ = 'N' | |
115 | .set C_ = 'C' | |
116 | ||
117 | ldi temp, ' ' | |
118 | sbrc z_flags,ZFL_@0 | |
119 | ldi temp, @0_ | |
120 | rcall uartputc | |
121 | .endm | |
122 | ||
123 | ;------------------------------------------------ | |
124 | ; db_version VMAJOR, VMINOR | |
125 | ||
126 | .macro db_version | |
127 | ||
128 | .set maj1_ = @0 / 10 | |
129 | .set maj0_ = @0 % 10 | |
130 | .set min1_ = @1 / 10 | |
131 | .set min0_ = @1 % 10 | |
132 | ||
133 | .if maj1_ | |
134 | .if min1_ | |
135 | .db maj1_+'0',maj0_+'0','.',min1_+'0',min0_+'0',0 | |
136 | .else | |
137 | .db maj1_+'0',maj0_+'0','.', min0_+'0',0,0 | |
138 | .endif | |
139 | .else | |
140 | .if min1_ | |
141 | .db maj0_+'0','.',min1_+'0',min0_+'0',0,0 | |
142 | .else | |
143 | .db maj0_+'0','.', min0_+'0',0 | |
144 | .endif | |
145 | .endif | |
146 | .endm | |
147 | ||
148 | ; vim:set ts=8 noet nowrap | |
149 |