• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2    SDL - Simple DirectMedia Layer
3    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public
16    License along with this library; if not, write to the Free
17    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19    Sam Lantinga
20    slouken@libsdl.org
21*/
22
23/*
24	Audio interrupts
25
26	Patrice Mandin, Didier M�quignon
27 */
28
29	.text
30
31	.globl	_SDL_MintAudio_Callback
32
33	.globl	_SDL_MintAudio_XbiosInterrupt
34	.globl	_SDL_MintAudio_XbiosInterruptMeasureClock
35	.globl	_SDL_MintAudio_Dma8Interrupt
36	.globl	_SDL_MintAudio_StfaInterrupt
37
38	.globl	_SDL_MintAudio_mutex
39	.globl	_SDL_MintAudio_audiobuf
40	.globl	_SDL_MintAudio_numbuf
41	.globl	_SDL_MintAudio_audiosize
42	.globl	_SDL_MintAudio_clocktics
43	.globl	_SDL_MintAudio_hasfpu
44
45	.globl	_SDL_MintAudio_stfa
46
47/*
48	How it works:
49	- Audio is playing buffer #0 (resp. #1)
50	- We must calculate a sample in buffer #1 (resp. #0)
51	  so we first call the callback to do it
52	- Then we swap the buffers
53*/
54
55#define	savptr	0x4a2
56#define	savamt	0x46
57
58/*--- Xbios interrupt vector to measure Falcon external clock ---*/
59
60_SDL_MintAudio_XbiosInterruptMeasureClock:          /* 1 mS */
61
62	btst	#0,0xFFFF8901:w	/* state DMA sound */
63	beqs	SDL_MintAudio_EndIntMeasure
64	addql	#1,_SDL_MintAudio_clocktics
65SDL_MintAudio_EndIntMeasure:
66	bclr	#5,0xFFFFFA0F:w	/* Clear service bit */
67	rte
68
69/*--- Xbios interrupt vector ---*/
70
71_SDL_MintAudio_XbiosInterrupt:
72
73	/* Reenable interrupts, so other interrupts can work */
74	movew	#0x2300,sr
75
76	/* Clear service bit, so other MFP interrupts can work */
77	bclr	#5,0xfffffa0f:w
78
79	/* Check if we are not already running */
80	tstw	_SDL_MintAudio_mutex
81	bne	SDL_MintAudio_XbiosEnd
82	notw	_SDL_MintAudio_mutex
83
84	/* Swap buffers */
85	eorw	#1,_SDL_MintAudio_numbuf
86
87	moveml	d0-d7/a0-a6,sp@-
88
89	/* Save FPU if needed */
90	tstw	_SDL_MintAudio_hasfpu
91	beqs	SDL_MintAudio_Xbios_nofpu1
92	.chip	68060
93	fsave	sp@-
94	fmoveml fpcr/fpsr/fpiar,sp@-
95	fmovemx	fp0-fp7,sp@-
96	.chip	68000
97SDL_MintAudio_Xbios_nofpu1:
98
99	/* Callback */
100	jsr	_SDL_MintAudio_Callback
101
102	/* Restore FPU if needed */
103	tstw	_SDL_MintAudio_hasfpu
104	beqs	SDL_MintAudio_Xbios_nofpu2
105	.chip	68060
106	fmovemx	sp@+,fp0-fp7
107	fmoveml	sp@+,fpcr/fpsr/fpiar
108	frestore	sp@+
109	.chip	68000
110SDL_MintAudio_Xbios_nofpu2:
111
112	/* Reserve space for registers */
113	subl	#savamt,savptr
114
115	/* Set new buffer */
116
117	moveq	#0,d0
118	movel	_SDL_MintAudio_audiosize,d1
119
120	movew	_SDL_MintAudio_numbuf,d0
121	lsll	#2,d0
122	lea	_SDL_MintAudio_audiobuf,a0
123	movel	a0@(d0:l),a1
124
125	lea	a1@(d1:l),a2
126
127	movel	a2,sp@-
128	movel	a1,sp@-
129	clrw	sp@-
130	movew	#131,sp@-
131	trap	#14
132	lea	sp@(12),sp
133
134	/* Restore registers space */
135	addl	#savamt,savptr
136
137	moveml	sp@+,d0-d7/a0-a6
138
139	clrw	_SDL_MintAudio_mutex
140SDL_MintAudio_XbiosEnd:
141	rte
142
143/*--- DMA 8 bits interrupt vector ---*/
144
145_SDL_MintAudio_Dma8Interrupt:
146
147	/* Reenable interrupts, so other interrupts can work */
148	movew	#0x2300,sr
149
150	/* Clear service bit, so other MFP interrupts can work */
151	bclr	#5,0xfffffa0f:w
152
153	/* Check if we are not already running */
154	tstw	_SDL_MintAudio_mutex
155	bne	SDL_MintAudio_Dma8End
156	notw	_SDL_MintAudio_mutex
157
158	/* Swap buffers */
159	eorw	#1,_SDL_MintAudio_numbuf
160
161	moveml	d0-d1/a0-a1,sp@-
162
163	/* Save FPU if needed */
164	tstw	_SDL_MintAudio_hasfpu
165	beqs	SDL_MintAudio_Dma8_nofpu1
166	.chip	68060
167	fsave	sp@-
168	fmoveml fpcr/fpsr/fpiar,sp@-
169	fmovemx	fp0-fp7,sp@-
170	.chip	68000
171SDL_MintAudio_Dma8_nofpu1:
172
173	/* Callback */
174	jsr	_SDL_MintAudio_Callback
175
176	/* Restore FPU if needed */
177	tstw	_SDL_MintAudio_hasfpu
178	beqs	SDL_MintAudio_Dma8_nofpu2
179	.chip	68060
180	fmovemx	sp@+,fp0-fp7
181	fmoveml	sp@+,fpcr/fpsr/fpiar
182	frestore	sp@+
183	.chip	68000
184SDL_MintAudio_Dma8_nofpu2:
185
186	/* Set new buffer */
187
188	moveq	#0,d0
189
190	movew	_SDL_MintAudio_numbuf,d0
191	lslw	#2,d0
192	lea	_SDL_MintAudio_audiobuf,a0
193	movel	a0@(d0:w),d1
194
195	/* Modify DMA addresses */
196	lea	0xffff8900:w,a0
197
198	moveb	d1,a0@(0x07)	/* Start address */
199	rorl	#8,d1
200	moveb	d1,a0@(0x05)
201	rorl	#8,d1
202	moveb	d1,a0@(0x03)
203	swap	d1
204
205	addl	_SDL_MintAudio_audiosize,d1
206
207	moveb	d1,a0@(0x13)	/* End address */
208	rorl	#8,d1
209	moveb	d1,a0@(0x11)
210	rorl	#8,d1
211	moveb	d1,a0@(0x0f)
212
213	moveml	sp@+,d0-d1/a0-a1
214
215	clrw	_SDL_MintAudio_mutex
216SDL_MintAudio_Dma8End:
217	rte
218
219/*--- STFA interrupt vector ---*/
220
221STFA_SOUND_START	=	6
222STFA_SOUND_END		=	STFA_SOUND_START+8
223
224_SDL_MintAudio_StfaInterrupt:
225
226	/* Reenable interrupts, so other interrupts can work */
227	movew	#0x2300,sr
228
229	/* Check if we are not already running */
230	tstw	_SDL_MintAudio_mutex
231	bnes	SDL_MintAudio_StfaEnd
232	notw	_SDL_MintAudio_mutex
233
234	/* Swap buffers */
235	eorw	#1,_SDL_MintAudio_numbuf
236
237	moveml	d0-d7/a0-a6,sp@-
238
239	/* Save FPU if needed */
240	tstw	_SDL_MintAudio_hasfpu
241	beqs	SDL_MintAudio_Stfa_nofpu1
242	.chip	68060
243	fsave	sp@-
244	fmoveml fpcr/fpsr/fpiar,sp@-
245	fmovemx	fp0-fp7,sp@-
246	.chip	68000
247SDL_MintAudio_Stfa_nofpu1:
248
249	/* Callback */
250	jsr	_SDL_MintAudio_Callback
251
252	/* Restore FPU if needed */
253	tstw	_SDL_MintAudio_hasfpu
254	beqs	SDL_MintAudio_Stfa_nofpu2
255	.chip	68060
256	fmovemx	sp@+,fp0-fp7
257	fmoveml	sp@+,fpcr/fpsr/fpiar
258	frestore	sp@+
259	.chip	68000
260SDL_MintAudio_Stfa_nofpu2:
261
262	/* Set new buffer */
263
264	moveq	#0,d0
265	movel	_SDL_MintAudio_stfa,a1
266
267	movew	_SDL_MintAudio_numbuf,d0
268	lslw	#2,d0
269	lea	_SDL_MintAudio_audiobuf,a0
270	movel	a0@(d0:w),d1
271
272	/* Modify STFA replay buffers */
273	movel	d1,a1@(STFA_SOUND_START)
274	addl	_SDL_MintAudio_audiosize,d1
275	movel	d1,a1@(STFA_SOUND_END)
276
277	moveml	sp@+,d0-d7/a0-a6
278
279	clrw	_SDL_MintAudio_mutex
280SDL_MintAudio_StfaEnd:
281	rte
282