-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.asm
217 lines (193 loc) · 6.51 KB
/
utils.asm
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
genBitmask ;{
andlw 0x0f
addlw -8
bc genBitmask1
call bitTable
movwf bitmaskLo
clrf bitmaskHi
return
genBitmask1 call bitTable
movwf bitmaskHi
clrf bitmaskLo
genBitmask2 return ;}
bitTable ;{
andlw 0x07
tabj
bitTable1 retlw 0x01
retlw 0x02
retlw 0x04
retlw 0x08
retlw 0x10
retlw 0x20
retlw 0x40
retlw 0x80 ;}
checkOutput ;{
; compares outputs to bitmask
; in: outputLo/Hi
; in: bitmaskLo/Hi
; out: status-Z
movfw outputLo
andwf bitmaskLo,w
skpz
return
movfw outputHi
andwf bitmaskHi,w
return ;}
clrDelay ;{
; zero out all delay bytes
; in: W pointer to delay bytes
movwf FSR
bsf STATUS,IRP
clrf INDF
incf FSR,f
clrf INDF
incf FSR,f
clrf INDF
incf FSR,f
clrf INDF
incf FSR,f
clrf INDF
incf FSR,f
return ;}
chkDelay ;{
; check if all delay bytes are zero
; in: W pointer to delay bytes
; out: status-Z
movwf FSR
bsf STATUS,IRP
movf INDF,w
incf FSR,f
iorwf INDF,w
incf FSR,f
iorwf INDF,w
incf FSR,f
iorwf INDF,w
incf FSR,f
iorwf INDF,w
return ;}
genDelayF ;{
movwf FSR ; entry point for fast delays
movfw funcDelay
movwf temp1
swapf funcPrescMode,w
andlw 0x0f
addlw 2 ; smallest interval 1/250 second
goto genDelay0
genDelay: movwf FSR ; normal entry point
movfw funcDelay
movwf temp1
swapf funcPrescMode,w
andlw 0x0f
addlw 4 ; smallest interval 1/62.5 second
genDelay0: clrf temp2
clrf temp3
clrf temp4
clrf temp5
genDelay1 clrc
rlf temp1,f
rlf temp2,f
rlf temp3,f
addlw -1
bnz genDelay1
movf time+0,w ; add delay to current time
addwf temp1,f
movf time+1,w
skpnc
incfsz time+1,w
addwf temp2,f
movf time+2,w
skpnc
incfsz time+2,w
addwf temp3,f
movf time+3,w
skpnc
incfsz time+3,w
addwf temp4,f
movf time+4,w
skpnc
incfsz time+4,w
addwf temp5,f
bsf STATUS,IRP ; store the result
movfw temp1
movwf INDF
incf FSR,f
movfw temp2
movwf INDF
incf FSR,f
movfw temp3
movwf INDF
incf FSR,f
movfw temp4
movwf INDF
incf FSR,f
movfw temp5
movwf INDF
return ;}
compareTime ;{
addlw 4
movwf FSR
bsf STATUS,IRP ; upper ram
movfw time+4
subwf INDF,w ; X>Y..zc,X<Y..zC,X=Y..ZC -
bnc TIMEisgreater ; result: TIME>DELAY
bnz TIMEislower ; result: TIME<DELAY
decf FSR,f
movfw time+3
subwf INDF,w ; X>Y..zc,X<Y..zC,X=Y..ZC
bnc TIMEisgreater ; result: TIME>DELAY
bnz TIMEislower ; result: TIME<DELAY
decf FSR,f
movfw time+2
subwf INDF,w ; X>Y..zc,X<Y..zC,X=Y..ZC
bnc TIMEisgreater ; result: TIME>DELAY
bnz TIMEislower ; result: TIME<DELAY
decf FSR,f
movfw time+1
subwf INDF,w ; X>Y..zc,X<Y..zC,X=Y..ZC
bnc TIMEisgreater ; result: TIME>DELAY
bnz TIMEislower ; result: TIME<DELAY
decf FSR,f
movfw time+0
subwf INDF,w ; X>Y..zc,X<Y..zC,X=Y..ZC
bnc TIMEisgreater ; result: TIME>DELAY
bnz TIMEislower ; result: TIME<DELAY
TIMEisequal return ; Z=1;C=0
TIMEislower return ; Z=0;C=1
TIMEisgreater return ; Z=O;C=0
;}
safeOutput ;{
banksel outputLo
movfw outputLo
banksel eeByte
movwf eeByte
movlw eeOutputLo
pcall eeWrite
banksel outputHi
movfw outputHi
banksel eeByte
movwf eeByte
movlw eeOutputHi
goto eeWrite
;}
CRC8 ;{
xorwf crc,f
clrw
btfsc crc,0
xorlw 0x5e
btfsc crc,1
xorlw 0xbc
btfsc crc,2
xorlw 0x61
btfsc crc,3
xorlw 0xc2
btfsc crc,4
xorlw 0x9d
btfsc crc,5
xorlw 0x23
btfsc crc,6
xorlw 0x46
btfsc crc,7
xorlw 0x8c
movwf crc
return
;}