-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleds.asm
executable file
·210 lines (178 loc) · 3.56 KB
/
leds.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
; leds.asm
;
; Interface to the low-level HT1624 driver.
.include "ht1624.asm"
; mod w
.macro REVERSE ; dst,src
ldi w,8
reverse_lp:
ror @1
rol @0
dec w
brne reverse_lp
.endmacro
leds_init:
rcall ht_init
ret
; Redraw the entire thing on our LED matrix
leds_draw_ui:
rcall ht_startdata
LDIX ui
ldi w,24 ; For each of the 24 rows
push w
_leds_draw_ui_0:
pop w
tst w
breq _leds_draw_ui_end; (loop end)
dec w
push w
ld a1,X+
REVERSE a0,a1
push a0 ; This half gets drawn later
ld a1,X+
REVERSE a0,a1
ldi b0,1<<7
rcall ht_writebits
pop a0 ; (screwy screen drawing logic)
ldi b0,1<<7
rcall ht_writebits
rjmp _leds_draw_ui_0
_leds_draw_ui_end:
rcall ht_enddata
ret
; Flash the entire matrix panel (soft)
; Good choice for line clears
; mod w,a0
leds_flash:
CA ht_sendcmd,HT_CMD_PWM14
rcall leds_wait_medium
CA ht_sendcmd,HT_CMD_PWM13
rcall leds_wait_medium
CA ht_sendcmd,HT_CMD_PWM12
rcall leds_wait_medium
CA ht_sendcmd,HT_CMD_PWM13
rcall leds_wait_medium
CA ht_sendcmd,HT_CMD_PWM14
rcall leds_wait_medium
CA ht_sendcmd,HT_CMD_PWM15
rcall leds_wait_medium
CA ht_sendcmd,HT_CMD_PWM14
rcall leds_wait_medium
CA ht_sendcmd,HT_CMD_PWM13
rcall leds_wait_medium
CA ht_sendcmd,HT_CMD_PWM12
rcall leds_wait_medium
CA ht_sendcmd,HT_CMD_PWM13
rcall leds_wait_medium
CA ht_sendcmd,HT_CMD_PWM14
rcall leds_wait_medium
CA ht_sendcmd,HT_CMD_PWM15
ret
; Flash the entire matrix panel 4x (stronger)
; Good choice for game over
; mod w,a0
leds_flash_strong:
CA ht_sendcmd,HT_CMD_PWM14
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM11
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM08
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM11
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM14
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM11
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM08
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM11
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM14
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM11
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM08
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM11
rcall leds_wait_long
CA ht_sendcmd,HT_CMD_PWM14
ret
; Fade out using PWM (~0.375s)
; mod w
leds_fadeout_fast:
ldi a0,HT_CMD_PWM15
rcall ht_sendcmd
ldi w,14 ; Loop 14 times
tst w
breq PC+6 ; (loop again)
dec w
dec a0
rcall leds_wait_short
rcall ht_sendcmd
rjmp PC-6 ; (loop end)
ret
; Fade in using PWM (~0.375s)
; mod w
leds_fadein_fast:
ldi a0,HT_CMD_PWM01
rcall ht_sendcmd
ldi w,14 ; Loop 14 times
tst w
breq PC+6 ; (loop again)
dec w
inc a0
rcall leds_wait_short
rcall ht_sendcmd
rjmp PC-6 ; (loop end)
ret
; Fade in using PWM (~0.75s)
; mod w
leds_fadein_slow:
ldi a0,HT_CMD_PWM01
rcall ht_sendcmd
ldi w,14 ; Loop 14 times
tst w
breq PC+6 ; (loop again)
dec w
inc a0
rcall leds_wait_long
rcall ht_sendcmd
rjmp PC-6 ; (loop end)
ret
; Wait slightly less than 49 ms
; mod u
leds_wait_long:
push w ; Save w (nice when used inside loops)
ldi w,0xff
rcall leds_wait
pop w
ret
; Wait slightly less than 20 ms
leds_wait_medium:
push w
ldi w,0x68
rcall leds_wait
pop w
ret
; Wait slightly less than 10 ms
leds_wait_short:
push w
ldi w,0x34
rcall leds_wait
pop w
ret
; Configurable wait period
; in w (multiples of 191 us)
; mod u,w
leds_wait:
push w
ldi w,0xff
mov u,w
pop w
dec u
brne PC-1 ; Inner loop
dec u ; Adjustment for outer loop
dec w
brne PC-4 ; Outer loop
ret