-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbang.z80
178 lines (148 loc) · 2.79 KB
/
bitbang.z80
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
macro bitbang_init
; destroys: DE,HL
; BC = 0
ld hl,waves
ld de,waves_ram
ld bc,waves.size
ldir
ld hl,interrupt
ld de,interrupt_ram
ld c,interrupt.size
ldir
end macro
interrupt:
virtual at interrupt_ram
ex af,af'
exx
out [$00],a
ld a,$03
out [$31],a
jp hl
.size := $ - $$
load .data: .size from $$
end virtual
db .data
repeat 4,i:0
smcable pulsewave#i.freq.val, pulsewave#i.freq
smcable pulsewave#i.width.val, pulsewave#i.width
smcable pulsewave#i.mask.val, pulsewave#i.mask
smcable pulsewave#i.next.val, pulsewave#i.next
end repeat
pulsewave_chsize := 21
assert pulsewave0 + pulsewave_chsize = pulsewave1 - 1
assert pulsewave1 + pulsewave_chsize - 1 = pulsewave2
assert pulsewave2 + pulsewave_chsize = pulsewave3
assert pulsewave3 + pulsewave_chsize = noisewave
repeat 3,i:0
assert pulsewave#i.freq = pulsewave#i + 1
repeat 1,j:i+1
iterate v, width,mask,next
assert pulsewave#i.v + pulsewave_chsize = pulsewave#j.v
end iterate
end repeat
end repeat
waves:
virtual at waves_ram
pulsewave0:
ld hl,pulsewave2.freq.val + 1
add hl,bc
ld c,l
ld b,h
ld a,ixh
cp pulsewave0.width.val
sbc a,a
and pulsewave0.mask.val
ld hl,pulsewave0.next.val + pulsewave1
ex af,af'
exx
ei
ret
nop
nop
pulsewave1:
ld hl,pulsewave3.freq.val
add hl,de
ex de,hl
ld a,iyh
cp pulsewave1.width.val
sbc a,a
and pulsewave1.mask.val
ld hl,pulsewave1.next.val + pulsewave2
ex af,af'
exx
ei
ret
nop
pulsewave2:
ld hl,pulsewave0.freq.val
ex de,hl
add ix,de
ex de,hl
ld a,b
cp pulsewave2.width.val
sbc a,a
and pulsewave2.mask.val
ld hl,pulsewave2.next.val + pulsewave3
ex af,af'
exx
ei
ret
nop
pulsewave3:
ld hl,pulsewave1.freq.val
ex de,hl
add iy,de
ex de,hl
ld a,d
cp pulsewave3.width.val
sbc a,a
and pulsewave3.mask.val
ld hl,pulsewave3.next.val + noisewave
ex af,af'
exx
ei
ret
smcable noisewave.seed, noisewave.seed.addr, $0001
smcable noisewave.mask.val, noisewave.mask
smcable noisewave.next.val, noisewave.next
noisewave:
ld hl,noisewave.seed
add hl,hl
sbc a,a
and $2d
xor l
ld l,a
ld [noisewave.seed.addr],hl
add a,c
and noisewave.mask.val
ld hl,noisewave.next.val + pulsewave0
ex af,af'
exx
ei
ret
smcable basswave.state, basswave.state.addr, $f000
basswave.framestate.addr := basswave.state.addr + 1
smcable basswave.length.val, basswave.length
smcable basswave.mask.val, basswave.mask
smcable basswave.next.val, basswave.next
basswave:
ld hl,basswave.state
dec l
ld a,h
rlca
jr nz,.end
ld h,a
ld l,basswave.length.val
.end
ld [basswave.state.addr],hl
sbc a,a
and basswave.mask.val
ld hl,basswave.next.val + pulsewave0
ex af,af'
exx
ei
ret
waves.size := $ - $$
load waves.data: waves.size from $$
end virtual
db waves.data