src/audio/SDL_mixer_m68k.c
author Patrice Mandin <patmandin@gmail.com>
Tue, 03 Jun 2003 19:35:10 +0000
changeset 633 873c2598f969
child 769 b8d311d90021
permissions -rw-r--r--
Add m68k assembly mixing routines
patmandin@633
     1
/*
patmandin@633
     2
    SDL - Simple DirectMedia Layer
patmandin@633
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
patmandin@633
     4
patmandin@633
     5
    This library is free software; you can redistribute it and/or
patmandin@633
     6
    modify it under the terms of the GNU Library General Public
patmandin@633
     7
    License as published by the Free Software Foundation; either
patmandin@633
     8
    version 2 of the License, or (at your option) any later version.
patmandin@633
     9
patmandin@633
    10
    This library is distributed in the hope that it will be useful,
patmandin@633
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
patmandin@633
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
patmandin@633
    13
    Library General Public License for more details.
patmandin@633
    14
patmandin@633
    15
    You should have received a copy of the GNU Library General Public
patmandin@633
    16
    License along with this library; if not, write to the Free
patmandin@633
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
patmandin@633
    18
patmandin@633
    19
    Sam Lantinga
patmandin@633
    20
    slouken@libsdl.org
patmandin@633
    21
*/
patmandin@633
    22
patmandin@633
    23
/*
patmandin@633
    24
	m68k assembly mix routines
patmandin@633
    25
patmandin@633
    26
	Patrice Mandin
patmandin@633
    27
*/
patmandin@633
    28
patmandin@633
    29
#if defined(__M68000__) && defined(__GNUC__)
patmandin@633
    30
void SDL_MixAudio_m68k_U8(char* dst, char* src, long len, long volume, char* mix8)
patmandin@633
    31
{
patmandin@633
    32
    __asm__ __volatile__ (
patmandin@633
    33
patmandin@633
    34
	"tstl	%2\n"
patmandin@633
    35
"	beqs	stoploop_u8\n"
patmandin@633
    36
"mixloop_u8:\n"
patmandin@633
    37
patmandin@633
    38
	/* Mix a sample */
patmandin@633
    39
patmandin@633
    40
"	moveq	#0,%%d0\n"
patmandin@633
    41
"	moveq	#0,%%d1\n"
patmandin@633
    42
patmandin@633
    43
"	moveb	%1@+,%%d0\n"	/* d0 = *src++ */
patmandin@633
    44
"	sub	#128,%%d0\n"	/* d0 -= 128 */
patmandin@633
    45
"	muls	%3,%%d0\n"	/* d0 *= volume (0<=volume<=128) */
patmandin@633
    46
"	moveb	%0@,%%d1\n"	/* d1 = *dst */
patmandin@633
    47
"	asr	#7,%%d0\n"	/* d0 /= 128 (SDL_MIX_MAXVOLUME) */
patmandin@633
    48
"	add	#128,%%d0\n"	/* d0 += 128 */
patmandin@633
    49
patmandin@633
    50
"	add	%%d1,%%d0\n"
patmandin@633
    51
patmandin@633
    52
"	moveb	%4@(%%d0:w),%0@+\n"
patmandin@633
    53
patmandin@633
    54
	/* Loop till done */
patmandin@633
    55
patmandin@633
    56
"	subql	#1,%2\n"
patmandin@633
    57
"	bhis	mixloop_u8\n"
patmandin@633
    58
"stoploop_u8:\n"
patmandin@633
    59
patmandin@633
    60
	 : /* no return value */
patmandin@633
    61
	 : /* input */
patmandin@633
    62
	 	"a"(dst), "a"(src), "d"(len), "d"(volume), "a"(mix8)	
patmandin@633
    63
	 : /* clobbered registers */
patmandin@633
    64
	 	"d0", "d1", "cc", "memory" 
patmandin@633
    65
	 );
patmandin@633
    66
}
patmandin@633
    67
patmandin@633
    68
void SDL_MixAudio_m68k_S8(char* dst, char* src, long len, long volume)
patmandin@633
    69
{
patmandin@633
    70
    __asm__ __volatile__ (
patmandin@633
    71
patmandin@633
    72
	"tstl	%2\n"
patmandin@633
    73
"	beqs	stoploop_s8\n"
patmandin@633
    74
"	moveq	#-128,%%d2\n"
patmandin@633
    75
"	moveq	#127,%%d3\n"
patmandin@633
    76
"mixloop_s8:\n"
patmandin@633
    77
patmandin@633
    78
	/* Mix a sample */
patmandin@633
    79
patmandin@633
    80
"	moveq	#0,%%d0\n"
patmandin@633
    81
"	moveq	#0,%%d1\n"
patmandin@633
    82
patmandin@633
    83
"	moveb	%1@+,%%d0\n"	/* d0 = *src++ */
patmandin@633
    84
"	muls	%3,%%d0\n"	/* d0 *= volume (0<=volume<=128) */
patmandin@633
    85
"	moveb	%0@,%%d1\n"	/* d1 = *dst */
patmandin@633
    86
"	asr	#7,%%d0\n"	/* d0 /= 128 (SDL_MIX_MAXVOLUME) */
patmandin@633
    87
patmandin@633
    88
"	add	%%d1,%%d0\n"
patmandin@633
    89
patmandin@633
    90
"	cmp	%%d2,%%d0\n"
patmandin@633
    91
"	bges	lower_limit_s8\n"
patmandin@633
    92
"	move	%%d2,%%d0\n"
patmandin@633
    93
"lower_limit_s8:\n"
patmandin@633
    94
patmandin@633
    95
"	cmp	%%d3,%%d0\n"
patmandin@633
    96
"	bles	upper_limit_s8\n"
patmandin@633
    97
"	move	%%d3,%%d0\n"
patmandin@633
    98
"upper_limit_s8:\n"
patmandin@633
    99
"	moveb	%%d0,%0@+\n"
patmandin@633
   100
patmandin@633
   101
	/* Loop till done */
patmandin@633
   102
patmandin@633
   103
"	subql	#1,%2\n"
patmandin@633
   104
"	bhis	mixloop_s8\n"
patmandin@633
   105
"stoploop_s8:\n"
patmandin@633
   106
patmandin@633
   107
	 : /* no return value */
patmandin@633
   108
	 : /* input */
patmandin@633
   109
	 	"a"(dst), "a"(src), "d"(len), "d"(volume)	
patmandin@633
   110
	 : /* clobbered registers */
patmandin@633
   111
	 	"d0", "d1", "d2", "d3", "cc", "memory" 
patmandin@633
   112
	 );
patmandin@633
   113
}
patmandin@633
   114
patmandin@633
   115
void SDL_MixAudio_m68k_S16MSB(short* dst, short* src, long len, long volume)
patmandin@633
   116
{
patmandin@633
   117
    __asm__ __volatile__ (
patmandin@633
   118
patmandin@633
   119
	"tstl	%2\n"
patmandin@633
   120
"	beqs	stoploop_s16msb\n"
patmandin@633
   121
"	movel	#-32768,%%d2\n"
patmandin@633
   122
"	movel	#32767,%%d3\n"
patmandin@633
   123
"	lsrl	#1,%2\n"
patmandin@633
   124
"mixloop_s16msb:\n"
patmandin@633
   125
patmandin@633
   126
	/* Mix a sample */
patmandin@633
   127
patmandin@633
   128
"	move	%1@+,%%d0\n"	/* d0 = *src++ */
patmandin@633
   129
"	muls	%3,%%d0\n"	/* d0 *= volume (0<=volume<=128) */
patmandin@633
   130
"	move	%0@,%%d1\n"	/* d1 = *dst */
patmandin@633
   131
"	extl	%%d1\n"		/* extend d1 to 32 bits */
patmandin@633
   132
"	asrl	#7,%%d0\n"	/* d0 /= 128 (SDL_MIX_MAXVOLUME) */
patmandin@633
   133
patmandin@633
   134
"	addl	%%d1,%%d0\n"
patmandin@633
   135
patmandin@633
   136
"	cmpl	%%d2,%%d0\n"
patmandin@633
   137
"	bges	lower_limit_s16msb\n"
patmandin@633
   138
"	move	%%d2,%%d0\n"
patmandin@633
   139
"lower_limit_s16msb:\n"
patmandin@633
   140
patmandin@633
   141
"	cmpl	%%d3,%%d0\n"
patmandin@633
   142
"	bles	upper_limit_s16msb\n"
patmandin@633
   143
"	move	%%d3,%%d0\n"
patmandin@633
   144
"upper_limit_s16msb:\n"
patmandin@633
   145
"	move	%%d0,%0@+\n"
patmandin@633
   146
patmandin@633
   147
	/* Loop till done */
patmandin@633
   148
patmandin@633
   149
"	subql	#1,%2\n"
patmandin@633
   150
"	bhis	mixloop_s16msb\n"
patmandin@633
   151
"stoploop_s16msb:\n"
patmandin@633
   152
patmandin@633
   153
	 : /* no return value */
patmandin@633
   154
	 : /* input */
patmandin@633
   155
	 	"a"(dst), "a"(src), "d"(len), "d"(volume)	
patmandin@633
   156
	 : /* clobbered registers */
patmandin@633
   157
	 	"d0", "d1", "d2", "d3", "cc", "memory" 
patmandin@633
   158
	 );
patmandin@633
   159
}
patmandin@633
   160
patmandin@633
   161
void SDL_MixAudio_m68k_S16LSB(short* dst, short* src, long len, long volume)
patmandin@633
   162
{
patmandin@633
   163
    __asm__ __volatile__ (
patmandin@633
   164
patmandin@633
   165
	"tstl	%2\n"
patmandin@633
   166
"	beqs	stoploop_s16lsb\n"
patmandin@633
   167
"	movel	#-32768,%%d2\n"
patmandin@633
   168
"	movel	#32767,%%d3\n"
patmandin@633
   169
"	lsrl	#1,%2\n"
patmandin@633
   170
"mixloop_s16lsb:\n"
patmandin@633
   171
patmandin@633
   172
	/* Mix a sample */
patmandin@633
   173
patmandin@633
   174
"	move	%1@+,%%d0\n"	/* d0 = *src++ */
patmandin@633
   175
"	rorw	#8,%%d0\n"
patmandin@633
   176
"	muls	%3,%%d0\n"	/* d0 *= volume (0<=volume<=128) */
patmandin@633
   177
"	move	%0@,%%d1\n"	/* d1 = *dst */
patmandin@633
   178
"	rorw	#8,%%d1\n"
patmandin@633
   179
"	extl	%%d1\n"		/* extend d1 to 32 bits */
patmandin@633
   180
"	asrl	#7,%%d0\n"	/* d0 /= 128 (SDL_MIX_MAXVOLUME) */
patmandin@633
   181
patmandin@633
   182
"	addl	%%d1,%%d0\n"
patmandin@633
   183
patmandin@633
   184
"	cmpl	%%d2,%%d0\n"
patmandin@633
   185
"	bges	lower_limit_s16lsb\n"
patmandin@633
   186
"	move	%%d2,%%d0\n"
patmandin@633
   187
"lower_limit_s16lsb:\n"
patmandin@633
   188
patmandin@633
   189
"	cmpl	%%d3,%%d0\n"
patmandin@633
   190
"	bles	upper_limit_s16lsb\n"
patmandin@633
   191
"	move	%%d3,%%d0\n"
patmandin@633
   192
"upper_limit_s16lsb:\n"
patmandin@633
   193
"	rorw	#8,%%d0\n"
patmandin@633
   194
"	move	%%d0,%0@+\n"
patmandin@633
   195
patmandin@633
   196
	/* Loop till done */
patmandin@633
   197
patmandin@633
   198
"	subql	#1,%2\n"
patmandin@633
   199
"	bhis	mixloop_s16lsb\n"
patmandin@633
   200
"stoploop_s16lsb:\n"
patmandin@633
   201
patmandin@633
   202
	 : /* no return value */
patmandin@633
   203
	 : /* input */
patmandin@633
   204
	 	"a"(dst), "a"(src), "d"(len), "d"(volume)	
patmandin@633
   205
	 : /* clobbered registers */
patmandin@633
   206
	 	"d0", "d1", "d2", "d3", "cc", "memory" 
patmandin@633
   207
	 );
patmandin@633
   208
}
patmandin@633
   209
#endif
patmandin@633
   210