src/audio/SDL_mixer_m68k.c
changeset 5536 05af1b9ff46d
parent 5535 96594ac5fd1a
child 5537 8a66741be632
equal deleted inserted replaced
5535:96594ac5fd1a 5536:05af1b9ff46d
     1 /*
       
     2     SDL - Simple DirectMedia Layer
       
     3     Copyright (C) 1997-2011 Sam Lantinga
       
     4 
       
     5     This library is free software; you can redistribute it and/or
       
     6     modify it under the terms of the GNU Lesser General Public
       
     7     License as published by the Free Software Foundation; either
       
     8     version 2.1 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     Lesser General Public License for more details.
       
    14 
       
    15     You should have received a copy of the GNU Lesser General Public
       
    16     License along with this library; if not, write to the Free Software
       
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  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(__M68000__) && !defined(__mcoldfire__) && defined(__GNUC__)
       
    31 void
       
    32 SDL_MixAudio_m68k_U8(char *dst, char *src, long len, long volume, char *mix8)
       
    33 {
       
    34     __asm__ __volatile__("tstl	%2\n" "	beqs	stoploop_u8\n" "mixloop_u8:\n"
       
    35                          /* Mix a sample */
       
    36                          "	moveq	#0,%%d0\n" "	moveq	#0,%%d1\n" "	moveb	%1@+,%%d0\n"    /* d0 = *src++ */
       
    37                          "	sub	#128,%%d0\n"    /* d0 -= 128 */
       
    38                          "	muls	%3,%%d0\n"      /* d0 *= volume (0<=volume<=128) */
       
    39                          "	moveb	%0@,%%d1\n"     /* d1 = *dst */
       
    40                          "	asr	#7,%%d0\n"      /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
       
    41                          "	add	#128,%%d0\n"    /* d0 += 128 */
       
    42                          "	add	%%d1,%%d0\n"
       
    43                          "	moveb	%4@(%%d0:w),%0@+\n"
       
    44                          /* Loop till done */
       
    45                          "	subql	#1,%2\n" "	bhis	mixloop_u8\n" "stoploop_u8:\n": /* no return value */
       
    46                          :      /* input */
       
    47                          "a"(dst), "a"(src), "d"(len), "d"(volume), "a"(mix8):  /* clobbered registers */
       
    48                          "d0", "d1", "cc", "memory");
       
    49 }
       
    50 
       
    51 void
       
    52 SDL_MixAudio_m68k_S8(char *dst, char *src, long len, long volume)
       
    53 {
       
    54     __asm__ __volatile__("tstl	%2\n"
       
    55                          "	beqs	stoploop_s8\n"
       
    56                          "	moveq	#-128,%%d2\n"
       
    57                          "	moveq	#127,%%d3\n" "mixloop_s8:\n"
       
    58                          /* Mix a sample */
       
    59                          "	moveq	#0,%%d0\n" "	moveq	#0,%%d1\n" "	moveb	%1@+,%%d0\n"    /* d0 = *src++ */
       
    60                          "	muls	%3,%%d0\n"      /* d0 *= volume (0<=volume<=128) */
       
    61                          "	moveb	%0@,%%d1\n"     /* d1 = *dst */
       
    62                          "	asr	#7,%%d0\n"      /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
       
    63                          "	add	%%d1,%%d0\n"
       
    64                          "	cmp	%%d2,%%d0\n"
       
    65                          "	bges	lower_limit_s8\n"
       
    66                          "	move	%%d2,%%d0\n"
       
    67                          "lower_limit_s8:\n"
       
    68                          "	cmp	%%d3,%%d0\n"
       
    69                          "	bles	upper_limit_s8\n"
       
    70                          "	move	%%d3,%%d0\n"
       
    71                          "upper_limit_s8:\n" "	moveb	%%d0,%0@+\n"
       
    72                          /* Loop till done */
       
    73                          "	subql	#1,%2\n" "	bhis	mixloop_s8\n" "stoploop_s8:\n": /* no return value */
       
    74                          :      /* input */
       
    75                          "a"(dst), "a"(src), "d"(len), "d"(volume):     /* clobbered registers */
       
    76                          "d0", "d1", "d2", "d3", "cc", "memory");
       
    77 }
       
    78 
       
    79 void
       
    80 SDL_MixAudio_m68k_S16MSB(short *dst, short *src, long len, long volume)
       
    81 {
       
    82     __asm__ __volatile__("tstl	%2\n"
       
    83                          "	beqs	stoploop_s16msb\n"
       
    84                          "	movel	#-32768,%%d2\n"
       
    85                          "	movel	#32767,%%d3\n"
       
    86                          "	lsrl	#1,%2\n" "mixloop_s16msb:\n"
       
    87                          /* Mix a sample */
       
    88                          "	move	%1@+,%%d0\n"    /* d0 = *src++ */
       
    89                          "	muls	%3,%%d0\n"      /* d0 *= volume (0<=volume<=128) */
       
    90                          "	move	%0@,%%d1\n"     /* d1 = *dst */
       
    91                          "	extl	%%d1\n" /* extend d1 to 32 bits */
       
    92                          "	asrl	#7,%%d0\n"      /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
       
    93                          "	addl	%%d1,%%d0\n"
       
    94                          "	cmpl	%%d2,%%d0\n"
       
    95                          "	bges	lower_limit_s16msb\n"
       
    96                          "	move	%%d2,%%d0\n"
       
    97                          "lower_limit_s16msb:\n"
       
    98                          "	cmpl	%%d3,%%d0\n"
       
    99                          "	bles	upper_limit_s16msb\n"
       
   100                          "	move	%%d3,%%d0\n"
       
   101                          "upper_limit_s16msb:\n" "	move	%%d0,%0@+\n"
       
   102                          /* Loop till done */
       
   103                          "	subql	#1,%2\n" "	bhis	mixloop_s16msb\n" "stoploop_s16msb:\n": /* no return value */
       
   104                          :      /* input */
       
   105                          "a"(dst), "a"(src), "d"(len), "d"(volume):     /* clobbered registers */
       
   106                          "d0", "d1", "d2", "d3", "cc", "memory");
       
   107 }
       
   108 
       
   109 void
       
   110 SDL_MixAudio_m68k_S16LSB(short *dst, short *src, long len, long volume)
       
   111 {
       
   112     __asm__ __volatile__("tstl	%2\n"
       
   113                          "	beqs	stoploop_s16lsb\n"
       
   114                          "	movel	#-32768,%%d2\n"
       
   115                          "	movel	#32767,%%d3\n"
       
   116                          "	lsrl	#1,%2\n" "mixloop_s16lsb:\n"
       
   117                          /* Mix a sample */
       
   118                          "	move	%1@+,%%d0\n"    /* d0 = *src++ */
       
   119                          "	rorw	#8,%%d0\n" "	muls	%3,%%d0\n"      /* d0 *= volume (0<=volume<=128) */
       
   120                          "	move	%0@,%%d1\n"     /* d1 = *dst */
       
   121                          "	rorw	#8,%%d1\n" "	extl	%%d1\n" /* extend d1 to 32 bits */
       
   122                          "	asrl	#7,%%d0\n"      /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
       
   123                          "	addl	%%d1,%%d0\n"
       
   124                          "	cmpl	%%d2,%%d0\n"
       
   125                          "	bges	lower_limit_s16lsb\n"
       
   126                          "	move	%%d2,%%d0\n"
       
   127                          "lower_limit_s16lsb:\n"
       
   128                          "	cmpl	%%d3,%%d0\n"
       
   129                          "	bles	upper_limit_s16lsb\n"
       
   130                          "	move	%%d3,%%d0\n"
       
   131                          "upper_limit_s16lsb:\n"
       
   132                          "	rorw	#8,%%d0\n" "	move	%%d0,%0@+\n"
       
   133                          /* Loop till done */
       
   134                          "	subql	#1,%2\n" "	bhis	mixloop_s16lsb\n" "stoploop_s16lsb:\n": /* no return value */
       
   135                          :      /* input */
       
   136                          "a"(dst), "a"(src), "d"(len), "d"(volume):     /* clobbered registers */
       
   137                          "d0", "d1", "d2", "d3", "cc", "memory");
       
   138 }
       
   139 #endif
       
   140 /* vi: set ts=4 sw=4 expandtab: */