-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdspbase.gas
213 lines (172 loc) · 3.91 KB
/
dspbase.gas
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
_dspbase::
.dsp
.org $f1b000
RISC_FLAGS .equ $f1a100
MODMASK .equ $f1a118
DIVCONTROL .equ $f1a11c
;MAIN_STACK .equ $f1d000
MAIN_STACK .equ $f1ce00
PERM_DATA .equ $f1ce00
LOADPOINT .equ $f1b140
_soundbuffer == $1f0000
R_DAC .equ $f1a148
L_DAC .equ $f1a14c
;=============================================================================
S_LE .ccdef $14 ; PL
U_LE .ccdef $04 ; CC
S_GT .ccdef $18 ; MI
U_GT .ccdef $08 ; CS
S_LT .ccdef $15 ; PL+NE
U_LT .ccdef $05 ; CC+NE
FP .equr r14
scratch .equr r10
scratch2 .equr r11
RETURNVALUE .equr r29
RETURNPOINT .equr r28
MATH_A .equr r27
MATH_B .equr r26
MATH_C .equr r25
MATH_RTS .equr r24
MATH_SIGN .equr r23
;==============================================================================
nop
nop
nop
nop
nop
nop
nop
nop
ALT_RISC_FLAGS .equr r13
ALT_FLAGSTEMP .equr r14
ALT_PCTEMP .equr r15
ALT_SAMPLECOUNT_P .equr r16
ALT_SCRATCH .equr r17
ALT_LDAC .equr r18
ALT_RDAC .equr r19
ALT_STACKRESET .equr r20
ALT_SAMPLE_P .equr r21
ALT_SAMPLE .equr r22
ALT_SAMPLECOUNT .equr r23
;----------------------
;
; int_1
;
; Sample output
; org $f1b010
;----------------------
int_1:
load (ALT_RISC_FLAGS),ALT_FLAGSTEMP ; get current flags
; start load of sample from external memory
loadw (ALT_SAMPLE_P),ALT_SAMPLE
addqmod #2,ALT_SAMPLE_P ; bump sample pos after getting flags
; start interrupt cleanup
bclr #3,ALT_FLAGSTEMP ; clear IMASK
bset #10,ALT_FLAGSTEMP ; and interrupt 1 latch
addq #1,ALT_SAMPLECOUNT ; bump fast timing counter
load (r31),ALT_PCTEMP ; get last instruction address
move ALT_STACKRESET,r31 ; reset stack to safe spot
addq #2,ALT_PCTEMP ; point to next instruction to execute
store ALT_SAMPLECOUNT,(ALT_SAMPLECOUNT_P) ; store it to memory
; play left and right samples through dacs
store ALT_SAMPLE,(ALT_LDAC)
store ALT_SAMPLE,(ALT_RDAC)
; return from interrupt
jump T,(ALT_PCTEMP) ; return
store ALT_FLAGSTEMP,(ALT_RISC_FLAGS) ; restore flags
.long
_samplecount:: .dc.l 0
_dspcodestart:: .dc.l 0
_dspfinished:: .dc.l $def6
_olddspcodestart:: .dc.l 0
_int_stack: .dc.l 0,0,0,0 ; give it some room to be flaky...
;--------------------
;
; startup code
;
;--------------------
_dspbase_init::
;
; set up bank 0 registers for interrupt usage
;
movei #RISC_FLAGS,ALT_RISC_FLAGS
movei #_samplecount,ALT_SAMPLECOUNT_P
movei #L_DAC,ALT_LDAC
movei #R_DAC,ALT_RDAC
movei #_int_stack+8,ALT_STACKRESET
movei #_soundbuffer,ALT_SAMPLE_P
moveq #0,ALT_SAMPLECOUNT
movei #MODMASK,scratch
movei #$ffffe000,scratch2
store scratch2,(scratch) ; set up for 16k circular buffers
move ALT_STACKRESET,r31 ; in register bank 0
movei #(1<<5)+(1<<14),r0 ; enable I2S interrupts and regpage
store r0,(ALT_RISC_FLAGS)
nop ; wait for the reg page to flip
nop
nop
nop
;--------------------
;
; wait for a load command
;
;--------------------
nothingwaiting:
waitcmd:
movei #_dspcodestart,r2
load (r2),r1
or r1,r1
jr EQ,nothingwaiting
nop
;
; if still in memory, skip the load
;
movei #_olddspcodestart,r3
load (r3),r4
cmp r1,r4
movei #skipload,r5
jump EQ,(r5) ; still in memory
store r1,(r3) ; delay slot
move r1,r2
subq #4,r2 ; code size is just before start
load (r2),r2
addq #7,r2
shrq #3,r2 ; number of phrases to bopy
movei #LOADPOINT,r0 ; destination for code
move r1,r3
move r0,r4
addq #4,r3
addq #4,r4
loadloop:
load (r1),r5
load (r3),r6
store r5,(r0)
addqt #8,r1
addqt #8,r3
store r6,(r4)
subq #1,r2 ; decrement count
addqt #8,r4
jr PL,loadloop
addqt #8,r0
nop
;
; call it
;
skipload:
movei #LOADPOINT,r0
movei #dspreturn,RETURNPOINT
movei #MAIN_STACK,r14
jump T,(r0)
nop
dspreturn:
movei #_dspcodestart,r2
moveq #0,r0
store r0,(r2) ; dspcodestart = 0
movei #_dspfinished,r2
movei #$def6,r0
store r0,(r2) ; dspcodestart = 0
movei #waitcmd,r0
jump T,(r0)
nop
.phrase
.68000