-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_macros.INC
304 lines (247 loc) · 5.01 KB
/
util_macros.INC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
;; call_cntstack address if equal
BUTTON_PASSIVE EQU 0
BUTTON_RB4_SET_PRESSED EQU 1
BUTTON_RB5_ADJUST_PRESSED EQU 2
#define GOTO_BANK0 bcf STATUS, RP0
#define GOTO_BANK1 bsf STATUS, RP0
;call_cntstack macro address
; local here, makeCall
; movwf stackwtmp
; bcf INTCON, GIE
; incf stackcounter, F
;
;
;
; movfw stackcounter
; subwf stackmax,w ; subtract w from f
; ; stackmax - stackcounter
; ; if stackmax == stackcounter then now Z=1.
; ; if stackmax < stackcounter then now C=0.
; ; if stackmax > stackcounter then now C=1.
; btfsc STATUS, Z
; goto makeCall
; btfsc STATUS, C
; goto makeCall
; movfw stackcounter
; movwf stackmax
; bsf INTCON, GIE
fcall macro address
local here, makeCall
lcall address
pagesel here
endm
;makeCall:
; movfw stackwtmp
;
;
; lcall address
; pagesel here
; endm
;
;
;
;return_cntstack macro
; decf stackcounter,f
; return
; endm
cifeq macro register,literal,address
movlw literal
xorwf register,w
skpnz
call_cntstack address
endm
; call_cntstack address if not equal
cifneq macro register,literal,address
movlw literal
xorwf register,w
skpz
call_cntstack address
endm
; Jump to address if not equal
jifneq macro register,literal,address
movlw literal
xorwf register,w
skpz
goto address
endm
; Jump to address if equal
jifeq macro register,literal,address
movlw literal
xorwf register,w
skpnz
goto address
endm
if_A_greaterthan_B_goto macro address
call compare32bitReg
xorlw 0x01
skpnz
goto address
endm
Jump_If_Adjust_Pressed macro address
JIFEQ ButtonPressedValue, BUTTON_RB4_ADJUST_PRESSED, address
endm
Jump_If_Set_Pressed macro address
JIFEQ ButtonPressedValue, BUTTON_RB5_SET_PRESSED, address
endm
clear16bitReg macro fileRegister
clrf fileRegister
clrf fileRegister+1
endm
clear32bitReg macro fileRegister
clrf fileRegister+2
clrf fileRegister+3
clrf fileRegister+1
clrf fileRegister
endm
clear48bitReg macro fileRegister
clrf fileRegister+4
clrf fileRegister+5
clrf fileRegister+2
clrf fileRegister+3
clrf fileRegister+1
clrf fileRegister
endm
move32bitReg macro src,dest
movfw src
movwf dest
movfw src+1
movwf dest+1
movfw src+2
movwf dest+2
movfw src+3
movwf dest+3
endm
move48bitReg macro src,dest
move32bitReg src,dest
movfw src+4
movwf dest+4
movfw src+5
movwf dest+5
endm
move16bitReg macro src, dest
movfw src
movwf dest
movfw src+1
movwf dest+1
endm
move16bitRegTo32bitReg macro src, dest
clear32bitReg dest
move16bitReg src, dest
endm
move16RegToReg48 macro src, dest
clear48bitReg dest
move16bitReg src, dest
endm
;*******************************************************************
; Double Precision Multiplication
;
; argA1 : argA0 * argA3 : argA2 -> argB3:argB2:argB1:argB0
;
; Standard shift and add.
; Execution time: 215 to 295 clock cycles.
; Code space: 22 locations
;
; Cleaned up and corrected version from Microchip Ap note by BF.
; Note: Ap note has errors! Additional mods by Scott Dattalo.
;
;*******************************************************************
mpy16b16: macro
local nextbit, nobit_l, nobit_h
clrf argB3
clrf argB2
clrf argB1
movlw 0x80
movwf argB0
nextbit
rrf argA1,f
rrf argA0,f
btfss STATUS, C
goto nobit_l
movf argA2,w
addwf argB1,f
movf argA3, w
btfsc STATUS, C
incfsz argA3, w
addwf argB2, f
btfsc STATUS, C
incf argB3, f
bcf STATUS, C
nobit_l
btfss argA0, 7
goto nobit_h
movf argA2,w
addwf argB2,f
movf argA3, w
btfsc STATUS, C
incfsz argA3, w
addwf argB3, f
nobit_h
rrf argB3,f
rrf argB2,f
rrf argB1,f
rrf argB0,f
btfss STATUS, C
goto nextbit
endm
#define argA0 argA
#define argA1 argA+1
#define argA2 argA+2
#define argA3 argA+3
#define argB0 argB
#define argB1 argB+1
#define argB2 argB+2
#define argB3 argB+3
PrintString macro string
movlw high string ; point to the string
movwf printchar_hi ; in printchar_hi & low
movlw low string
movwf printchar_lo
call print ; go process it
endm
setArgA macro a, b, c, d
movlw d
movwf argA
movlw c
movwf argA+1
movlw b
movwf argA+2
movlw a
movwf argA+3
endm
setArgB macro a, b, c, d
movlw d
movwf argB
movlw c
movwf argB+1
movlw b
movwf argB+2
movlw a
movwf argB+3
endm
set32bitReg macro Reg, a, b, c, d
movlw d
movwf Reg
movlw c
movwf Reg+1
movlw b
movwf Reg+2
movlw a
movwf Reg+3
endm
set16bitReg macro Reg, c, d
movlw d
movwf Reg
movlw c
movwf Reg+1
endm
increment32bitReg macro regName, onComplete
bcf STATUS, Z
incfsz regName,F
goto onComplete
incfsz regName+1,F
goto onComplete
incfsz regName+2,F
goto onComplete
incf regName+3,F
goto onComplete
endm