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