1/*
2    SDL - Simple DirectMedia Layer
3    Copyright (C) 1997-2012 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#include "SDL_config.h"
23
24/*
25	m68k assembly mix routines
26
27	Patrice Mandin
28*/
29
30#if (defined(__m68k__) && !defined(__mcoldfire__)) && defined(__GNUC__)
31void SDL_MixAudio_m68k_U8(char* dst, char* src, long len, long volume, char* mix8)
32{
33    __asm__ __volatile__ (
34
35	"tstl	%2\n"
36"	beqs	stoploop_u8\n"
37"mixloop_u8:\n"
38
39	/* Mix a sample */
40
41"	moveq	#0,%%d0\n"
42"	moveq	#0,%%d1\n"
43
44"	moveb	%1@+,%%d0\n"	/* d0 = *src++ */
45"	sub	#128,%%d0\n"	/* d0 -= 128 */
46"	muls	%3,%%d0\n"	/* d0 *= volume (0<=volume<=128) */
47"	moveb	%0@,%%d1\n"	/* d1 = *dst */
48"	asr	#7,%%d0\n"	/* d0 /= 128 (SDL_MIX_MAXVOLUME) */
49"	add	#128,%%d0\n"	/* d0 += 128 */
50
51"	add	%%d1,%%d0\n"
52
53"	moveb	%4@(%%d0:w),%0@+\n"
54
55	/* Loop till done */
56
57"	subql	#1,%2\n"
58"	bhis	mixloop_u8\n"
59"stoploop_u8:\n"
60
61	 : /* no return value */
62	 : /* input */
63	 	"a"(dst), "a"(src), "d"(len), "d"(volume), "a"(mix8)
64	 : /* clobbered registers */
65	 	"d0", "d1", "cc", "memory"
66	 );
67}
68
69void SDL_MixAudio_m68k_S8(char* dst, char* src, long len, long volume)
70{
71    __asm__ __volatile__ (
72
73	"tstl	%2\n"
74"	beqs	stoploop_s8\n"
75"	moveq	#-128,%%d2\n"
76"	moveq	#127,%%d3\n"
77"mixloop_s8:\n"
78
79	/* Mix a sample */
80
81"	moveq	#0,%%d0\n"
82"	moveq	#0,%%d1\n"
83
84"	moveb	%1@+,%%d0\n"	/* d0 = *src++ */
85"	muls	%3,%%d0\n"	/* d0 *= volume (0<=volume<=128) */
86"	moveb	%0@,%%d1\n"	/* d1 = *dst */
87"	asr	#7,%%d0\n"	/* d0 /= 128 (SDL_MIX_MAXVOLUME) */
88
89"	add	%%d1,%%d0\n"
90
91"	cmp	%%d2,%%d0\n"
92"	bges	lower_limit_s8\n"
93"	move	%%d2,%%d0\n"
94"lower_limit_s8:\n"
95
96"	cmp	%%d3,%%d0\n"
97"	bles	upper_limit_s8\n"
98"	move	%%d3,%%d0\n"
99"upper_limit_s8:\n"
100"	moveb	%%d0,%0@+\n"
101
102	/* Loop till done */
103
104"	subql	#1,%2\n"
105"	bhis	mixloop_s8\n"
106"stoploop_s8:\n"
107
108	 : /* no return value */
109	 : /* input */
110	 	"a"(dst), "a"(src), "d"(len), "d"(volume)
111	 : /* clobbered registers */
112	 	"d0", "d1", "d2", "d3", "cc", "memory"
113	 );
114}
115
116void SDL_MixAudio_m68k_S16MSB(short* dst, short* src, long len, long volume)
117{
118    __asm__ __volatile__ (
119
120	"tstl	%2\n"
121"	beqs	stoploop_s16msb\n"
122"	movel	#-32768,%%d2\n"
123"	movel	#32767,%%d3\n"
124"	lsrl	#1,%2\n"
125"mixloop_s16msb:\n"
126
127	/* Mix a sample */
128
129"	move	%1@+,%%d0\n"	/* d0 = *src++ */
130"	muls	%3,%%d0\n"	/* d0 *= volume (0<=volume<=128) */
131"	move	%0@,%%d1\n"	/* d1 = *dst */
132"	extl	%%d1\n"		/* extend d1 to 32 bits */
133"	asrl	#7,%%d0\n"	/* d0 /= 128 (SDL_MIX_MAXVOLUME) */
134
135"	addl	%%d1,%%d0\n"
136
137"	cmpl	%%d2,%%d0\n"
138"	bges	lower_limit_s16msb\n"
139"	move	%%d2,%%d0\n"
140"lower_limit_s16msb:\n"
141
142"	cmpl	%%d3,%%d0\n"
143"	bles	upper_limit_s16msb\n"
144"	move	%%d3,%%d0\n"
145"upper_limit_s16msb:\n"
146"	move	%%d0,%0@+\n"
147
148	/* Loop till done */
149
150"	subql	#1,%2\n"
151"	bhis	mixloop_s16msb\n"
152"stoploop_s16msb:\n"
153
154	 : /* no return value */
155	 : /* input */
156	 	"a"(dst), "a"(src), "d"(len), "d"(volume)
157	 : /* clobbered registers */
158	 	"d0", "d1", "d2", "d3", "cc", "memory"
159	 );
160}
161
162void SDL_MixAudio_m68k_S16LSB(short* dst, short* src, long len, long volume)
163{
164    __asm__ __volatile__ (
165
166	"tstl	%2\n"
167"	beqs	stoploop_s16lsb\n"
168"	movel	#-32768,%%d2\n"
169"	movel	#32767,%%d3\n"
170"	lsrl	#1,%2\n"
171"mixloop_s16lsb:\n"
172
173	/* Mix a sample */
174
175"	move	%1@+,%%d0\n"	/* d0 = *src++ */
176"	rorw	#8,%%d0\n"
177"	muls	%3,%%d0\n"	/* d0 *= volume (0<=volume<=128) */
178"	move	%0@,%%d1\n"	/* d1 = *dst */
179"	rorw	#8,%%d1\n"
180"	extl	%%d1\n"		/* extend d1 to 32 bits */
181"	asrl	#7,%%d0\n"	/* d0 /= 128 (SDL_MIX_MAXVOLUME) */
182
183"	addl	%%d1,%%d0\n"
184
185"	cmpl	%%d2,%%d0\n"
186"	bges	lower_limit_s16lsb\n"
187"	move	%%d2,%%d0\n"
188"lower_limit_s16lsb:\n"
189
190"	cmpl	%%d3,%%d0\n"
191"	bles	upper_limit_s16lsb\n"
192"	move	%%d3,%%d0\n"
193"upper_limit_s16lsb:\n"
194"	rorw	#8,%%d0\n"
195"	move	%%d0,%0@+\n"
196
197	/* Loop till done */
198
199"	subql	#1,%2\n"
200"	bhis	mixloop_s16lsb\n"
201"stoploop_s16lsb:\n"
202
203	 : /* no return value */
204	 : /* input */
205	 	"a"(dst), "a"(src), "d"(len), "d"(volume)
206	 : /* clobbered registers */
207	 	"d0", "d1", "d2", "d3", "cc", "memory"
208	 );
209}
210#endif
211