Atari MiNT: added more audio drivers
authorPatrice Mandin <patmandin@gmail.com>
Mon, 07 Jul 2003 19:16:03 +0000
changeset 644594422ab8f9f
parent 643 564716cfb502
child 645 5bcfbd1abac6
Atari MiNT: added more audio drivers
README.MiNT
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
src/audio/mint/Makefile.am
src/audio/mint/SDL_mintaudio.c
src/audio/mint/SDL_mintaudio.h
src/audio/mint/SDL_mintaudio_dma8.c
src/audio/mint/SDL_mintaudio_dma8.h
src/audio/mint/SDL_mintaudio_gsxb.c
src/audio/mint/SDL_mintaudio_gsxb.h
src/audio/mint/SDL_mintaudio_it.S
src/audio/mint/SDL_mintaudio_mcsn.c
src/audio/mint/SDL_mintaudio_mcsn.h
src/audio/mint/SDL_mintaudio_stfa.c
src/audio/mint/SDL_mintaudio_stfa.h
src/audio/mint/SDL_mintaudio_xbios.c
     1.1 --- a/README.MiNT	Tue Jul 01 16:35:54 2003 +0000
     1.2 +++ b/README.MiNT	Mon Jul 07 19:16:03 2003 +0000
     1.3 @@ -49,18 +49,18 @@
     1.4  Video (XBIOS (Fullscreen), GEM (Windowed and Fullscreen))
     1.5  Timer (VBL vector, GNU pth library)
     1.6  Joystick and joypad support (Ikbd, Hardware)
     1.7 -Audio support (Hardware, XBIOS, GSXB, /dev/audio if threads enabled)
     1.8 +Audio support (Hardware, XBIOS, GSXB, MCSN, STFA, /dev/audio if threads enabled)
     1.9  Threads support (Multitasking OS only via GNU pth library)
    1.10  
    1.11  - What is missing:
    1.12  CDROM support (Metados, /dev/cdrom)
    1.13  
    1.14  - Driver combinations:
    1.15 -Video	Kbd	Mouse	Timer	Jstick	Joypads
    1.16 -xbios	ikbd	ikbd	vbl(2)	ikbd	hardware
    1.17 -xbios	gemdos	xbios	vbl(2)	xbios	hardware
    1.18 -xbios	bios	xbios	vbl(2)	xbios	hardware
    1.19 -gem	gem	gem(1)	vbl(2)	xbios	hardware
    1.20 +Video	Kbd	Mouse	Timer	Joystick
    1.21 +xbios	ikbd	ikbd	vbl(2)	ikbd
    1.22 +xbios	gemdos	xbios	vbl(2)	xbios
    1.23 +xbios	bios	xbios	vbl(2)	xbios
    1.24 +gem	gem	gem(1)	vbl(2)	xbios
    1.25  
    1.26  (1) GEM does not report relative mouse motion, so xbios mouse driver is used
    1.27  to report this type event.
    1.28 @@ -76,7 +76,11 @@
    1.29  	Set to 'gem' to force gem video driver
    1.30  
    1.31  SDL_AUDIODRIVER:
    1.32 -	Set to 'mint' to force Atari audio driver
    1.33 +	Set to 'mint_gsxb' to force Atari GSXB audio driver
    1.34 +	Set to 'mint_mcsn' to force Atari MCSN audio driver
    1.35 +	Set to 'mint_stfa' to force Atari STFA audio driver
    1.36 +	Set to 'mint_xbios' to force Atari Xbios audio driver
    1.37 +	Set to 'mint_dma8' to force Atari 8 bits DMA audio driver
    1.38  	Set to 'audio' to force Sun /dev/audio audio driver
    1.39  	Set to 'disk' to force disk-writing audio driver
    1.40  
    1.41 @@ -163,17 +167,30 @@
    1.42  VBL timer driver:
    1.43  	Available on all machines (I think).
    1.44  
    1.45 -Audio driver:
    1.46 -	Cookie _SND is used to detect supported audio capabilities
    1.47 +Audio drivers:
    1.48 +	Cookies _SND, MCSN, STFA and GSXB used to detect supported audio
    1.49 +	capabilities.
    1.50  
    1.51  	STE, Mega STE, TT:
    1.52  		8 bits DMA (hardware access)
    1.53 +		STFA, MCSN or GSXB driver if installed
    1.54 +	Falcon:
    1.55 +		8 bits DMA (hardware access)
    1.56 +		Xbios functions
    1.57 +		STFA, MCSN or GSXB driver if installed
    1.58 +	Other machines:
    1.59 +		STFA, MCSN or GSXB driver if installed
    1.60  
    1.61 -	Falcon, machines with GSXB driver:
    1.62 -		Xbios functions
    1.63 -
    1.64 -	Other machines:
    1.65 -		Not supported
    1.66 +	STFA driver:
    1.67 +		http://removers.free.fr/softs/stfa.html
    1.68 +	GSXB driver:
    1.69 +		http://assemsoft.atari.org/gsxb/
    1.70 +	MacSound driver:
    1.71 +		http://jf.omnis.ch/software/tos/
    1.72 +	MagicSound driver (MCSN,GSXB compatible):
    1.73 +		http://perso.wanadoo.fr/didierm/
    1.74 +	X-Sound driver (GSXB compatible):
    1.75 +		http://www.uni-ulm.de/~s_thuth/atari/xsound_e.html
    1.76  
    1.77  -- 
    1.78  Patrice Mandin <pmandin@caramail.com>
     2.1 --- a/src/audio/SDL_audio.c	Tue Jul 01 16:35:54 2003 +0000
     2.2 +++ b/src/audio/SDL_audio.c	Mon Jul 07 19:16:03 2003 +0000
     2.3 @@ -84,7 +84,11 @@
     2.4  	&AHI_bootstrap,
     2.5  #endif
     2.6  #ifdef MINTAUDIO_SUPPORT
     2.7 -	&MINTAUDIO_bootstrap,
     2.8 +	&MINTAUDIO_GSXB_bootstrap,
     2.9 +	&MINTAUDIO_MCSN_bootstrap,
    2.10 +	&MINTAUDIO_STFA_bootstrap,
    2.11 +	&MINTAUDIO_XBIOS_bootstrap,
    2.12 +	&MINTAUDIO_DMA8_bootstrap,
    2.13  #endif
    2.14  #ifdef DISKAUD_SUPPORT
    2.15  	&DISKAUD_bootstrap,
     3.1 --- a/src/audio/SDL_sysaudio.h	Tue Jul 01 16:35:54 2003 +0000
     3.2 +++ b/src/audio/SDL_sysaudio.h	Mon Jul 07 19:16:03 2003 +0000
     3.3 @@ -148,7 +148,11 @@
     3.4  extern AudioBootStrap AHI_bootstrap;
     3.5  #endif
     3.6  #ifdef MINTAUDIO_SUPPORT
     3.7 -extern AudioBootStrap MINTAUDIO_bootstrap;
     3.8 +extern AudioBootStrap MINTAUDIO_GSXB_bootstrap;
     3.9 +extern AudioBootStrap MINTAUDIO_MCSN_bootstrap;
    3.10 +extern AudioBootStrap MINTAUDIO_STFA_bootstrap;
    3.11 +extern AudioBootStrap MINTAUDIO_XBIOS_bootstrap;
    3.12 +extern AudioBootStrap MINTAUDIO_DMA8_bootstrap;
    3.13  #endif
    3.14  #ifdef DISKAUD_SUPPORT
    3.15  extern AudioBootStrap DISKAUD_bootstrap;
     4.1 --- a/src/audio/mint/Makefile.am	Tue Jul 01 16:35:54 2003 +0000
     4.2 +++ b/src/audio/mint/Makefile.am	Mon Jul 07 19:16:03 2003 +0000
     4.3 @@ -1,14 +1,19 @@
     4.4 -
     4.5  ## Makefile.am for SDL using Xbios/Dma/whatever available audio functions
     4.6  
     4.7  noinst_LTLIBRARIES = libaudio_mintaudio.la
     4.8  libaudio_mintaudio_la_SOURCES = $(SRCS)
     4.9  
    4.10  # The SDL audio driver sources
    4.11 -SRCS =	SDL_mintaudio.c	\
    4.12 +SRCS = \
    4.13 +	SDL_mintaudio.c	\
    4.14  	SDL_mintaudio.h	\
    4.15 -	SDL_mintaudiointerrupt.S \
    4.16 -	SDL_mintaudiointerrupt_s.h \
    4.17 -	SDL_mintaudiodma.h \
    4.18 -	SDL_mintaudiogsxb.h
    4.19 -
    4.20 +	SDL_mintaudio_dma8.c	\
    4.21 +	SDL_mintaudio_dma8.h	\
    4.22 +	SDL_mintaudio_gsxb.c	\
    4.23 +	SDL_mintaudio_gsxb.h	\
    4.24 +	SDL_mintaudio_it.S	\
    4.25 +	SDL_mintaudio_mcsn.c	\
    4.26 +	SDL_mintaudio_mcsn.h	\
    4.27 +	SDL_mintaudio_stfa.c	\
    4.28 +	SDL_mintaudio_stfa.h	\
    4.29 +	SDL_mintaudio_xbios.c
     5.1 --- a/src/audio/mint/SDL_mintaudio.c	Tue Jul 01 16:35:54 2003 +0000
     5.2 +++ b/src/audio/mint/SDL_mintaudio.c	Mon Jul 07 19:16:03 2003 +0000
     5.3 @@ -1,628 +1,93 @@
     5.4  /*
     5.5 - * MiNT audio driver
     5.6 - * 
     5.7 - * Patrice Mandin
     5.8 - */
     5.9 +    SDL - Simple DirectMedia Layer
    5.10 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    5.11  
    5.12 -#include <stdlib.h>
    5.13 -#include <stdio.h>
    5.14 +    This library is free software; you can redistribute it and/or
    5.15 +    modify it under the terms of the GNU Library General Public
    5.16 +    License as published by the Free Software Foundation; either
    5.17 +    version 2 of the License, or (at your option) any later version.
    5.18 +
    5.19 +    This library is distributed in the hope that it will be useful,
    5.20 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.21 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.22 +    Library General Public License for more details.
    5.23 +
    5.24 +    You should have received a copy of the GNU Library General Public
    5.25 +    License along with this library; if not, write to the Free
    5.26 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.27 +
    5.28 +    Sam Lantinga
    5.29 +    slouken@libsdl.org
    5.30 +*/
    5.31 +
    5.32 +/*
    5.33 +	Audio interrupt variables and callback function
    5.34 +
    5.35 +	Patrice Mandin
    5.36 +*/
    5.37 +
    5.38  #include <string.h>
    5.39  
    5.40 -/* Mint includes */
    5.41 -#include <mint/osbind.h>
    5.42 -#include <mint/falcon.h>
    5.43 -#include <mint/cookie.h>
    5.44 -
    5.45 -#include "SDL_endian.h"
    5.46 +#include "SDL_types.h"
    5.47  #include "SDL_audio.h"
    5.48 -#include "SDL_audio_c.h"
    5.49 -#include "SDL_audiomem.h"
    5.50 -#include "SDL_sysaudio.h"
    5.51  
    5.52  #include "SDL_mintaudio.h"
    5.53 -#include "SDL_mintaudiodma.h"
    5.54 -#include "SDL_mintaudiogsxb.h"
    5.55 -#include "SDL_mintaudiointerrupt_s.h"
    5.56 +#include "SDL_mintaudio_stfa.h"
    5.57  
    5.58 -#include "SDL_atarimxalloc_c.h"
    5.59 +/* The audio device */
    5.60  
    5.61 -/*--- Defines ---*/
    5.62 +SDL_AudioDevice *SDL_MintAudio_device;
    5.63 +Uint8 *SDL_MintAudio_audiobuf[2];	/* Pointers to buffers */
    5.64 +long SDL_MintAudio_audiosize;		/* Length of audio buffer=spec->size */
    5.65 +long SDL_MintAudio_numbuf;		/* Buffer to play */
    5.66 +long SDL_MintAudio_mutex;
    5.67 +cookie_stfa_t	*SDL_MintAudio_stfa;
    5.68  
    5.69 -#define MINT_AUDIO_DRIVER_NAME "mint"
    5.70 +/* The callback function, called by each driver whenever needed */
    5.71  
    5.72 -/* Master clocks for replay frequencies */
    5.73 -#define MASTERCLOCK_STE		8010666		/* Not sure of this one */
    5.74 -#define MASTERCLOCK_TT		16107953	/* Not sure of this one */
    5.75 -#define MASTERCLOCK_FALCON1	25175000
    5.76 -#define MASTERCLOCK_FALCON2	32000000	/* Only usable for DSP56K */
    5.77 -#define MASTERCLOCK_FALCONEXT	-1		/* Clock on DSP56K port, unknown */
    5.78 -#define MASTERCLOCK_MILAN1	22579200	/* Standard clock for 44.1 Khz */
    5.79 -#define MASTERCLOCK_MILAN2	24576000	/* Standard clock for 48 Khz */
    5.80 -
    5.81 -/* Master clock predivisors */
    5.82 -#define MASTERPREDIV_STE	160
    5.83 -#define MASTERPREDIV_TT		320
    5.84 -#define MASTERPREDIV_FALCON	256
    5.85 -#define MASTERPREDIV_MILAN	256
    5.86 -
    5.87 -/* Values>>16 in _MCH cookie */
    5.88 -enum {
    5.89 -	MCH_ST=0,
    5.90 -	MCH_STE,
    5.91 -	MCH_TT,
    5.92 -	MCH_F30
    5.93 -};
    5.94 -
    5.95 -/* MFP 68901 interrupt sources */
    5.96 -enum {
    5.97 -	MFP_PARALLEL=0,
    5.98 -	MFP_DCD,
    5.99 -	MFP_CTS,
   5.100 -	MFP_BITBLT,
   5.101 -	MFP_TIMERD,
   5.102 -	MFP_BAUDRATE=MFP_TIMERD,
   5.103 -	MFP_TIMERC,
   5.104 -	MFP_200HZ=MFP_TIMERC,
   5.105 -	MFP_ACIA,
   5.106 -	MFP_DISK,
   5.107 -	MFP_TIMERB,
   5.108 -	MFP_HBLANK=MFP_TIMERB,
   5.109 -	MFP_TERR,
   5.110 -	MFP_TBE,
   5.111 -	MFP_RERR,
   5.112 -	MFP_RBF,
   5.113 -	MFP_TIMERA,
   5.114 -	MFP_DMASOUND=MFP_TIMERA,
   5.115 -	MFP_RING,
   5.116 -	MFP_MONODETECT
   5.117 -};
   5.118 -
   5.119 -/* Xbtimer() timers */
   5.120 -enum {
   5.121 -	XB_TIMERA=0,
   5.122 -	XB_TIMERB,
   5.123 -	XB_TIMERC,
   5.124 -	XB_TIMERD
   5.125 -};
   5.126 -
   5.127 -/*--- Static variables ---*/
   5.128 -
   5.129 -static unsigned long cookie_snd, cookie_mch, cookie_gsxb;
   5.130 -static Uint16 hardfreq[16];
   5.131 -static Uint16 numfreq;
   5.132 -static SDL_AudioDevice *SDL_MintAudio_device;
   5.133 -
   5.134 -/*--- Audio driver functions ---*/
   5.135 -
   5.136 -static void Mint_CloseAudio(_THIS);
   5.137 -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec);
   5.138 -static void Mint_LockAudio(_THIS);
   5.139 -static void Mint_UnlockAudio(_THIS);
   5.140 -
   5.141 -/*--- Audio driver bootstrap functions ---*/
   5.142 -
   5.143 -static int Audio_Available(void)
   5.144 -{
   5.145 -	const char *envr = getenv("SDL_AUDIODRIVER");
   5.146 -
   5.147 -	/* Check if user asked a different audio driver */
   5.148 -	if ((envr) && (strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
   5.149 -		return 0;
   5.150 -	}
   5.151 -
   5.152 -	/* Cookie _SND present ? if not, assume ST machine */
   5.153 -	if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
   5.154 -		cookie_snd = SND_PSG;
   5.155 -	}
   5.156 -
   5.157 -	/* Cookie _MCH present ? if not, assume ST machine */
   5.158 -	if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
   5.159 -		cookie_mch = MCH_ST << 16;
   5.160 -	}
   5.161 -
   5.162 -	/* Cookie GSXB present ? */
   5.163 -	cookie_gsxb = (Getcookie(C_GSXB, &cookie_gsxb) == C_FOUND);
   5.164 -
   5.165 -	/* Check if we have xbios functions (Falcon, clones) */
   5.166 -	if ((cookie_snd & SND_16BIT)!=0) {
   5.167 -		/* Check if audio is lockable */
   5.168 -		if (Locksnd()==1) {
   5.169 -			Unlocksnd();
   5.170 -		} else {
   5.171 -			/* Already in use */
   5.172 -			return(0);
   5.173 -		}
   5.174 -
   5.175 -		return(1);
   5.176 -	}
   5.177 -
   5.178 -	/* Check if we have 8 bits DMA audio (STE, TT) */
   5.179 -	if ((cookie_snd & SND_8BIT)!=0) {
   5.180 -		return(1);
   5.181 -	}
   5.182 -
   5.183 -    return(0);
   5.184 -}
   5.185 -
   5.186 -static void Audio_DeleteDevice(SDL_AudioDevice *device)
   5.187 -{
   5.188 -    free(device->hidden);
   5.189 -    free(device);
   5.190 -}
   5.191 -
   5.192 -static SDL_AudioDevice *Audio_CreateDevice(int devindex)
   5.193 -{
   5.194 -    SDL_AudioDevice *this;
   5.195 -
   5.196 -    /* Initialize all variables that we clean on shutdown */
   5.197 -    this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
   5.198 -    if ( this ) {
   5.199 -        memset(this, 0, (sizeof *this));
   5.200 -    }
   5.201 -    if ( this == NULL ) {
   5.202 -        SDL_OutOfMemory();
   5.203 -        if ( this ) {
   5.204 -            free(this);
   5.205 -        }
   5.206 -        return(0);
   5.207 -    }
   5.208 -
   5.209 -    /* Set the function pointers */
   5.210 -    this->OpenAudio   = Mint_OpenAudio;
   5.211 -    this->CloseAudio  = Mint_CloseAudio;
   5.212 -    this->LockAudio   = Mint_LockAudio;
   5.213 -    this->UnlockAudio = Mint_UnlockAudio;
   5.214 -    this->free        = Audio_DeleteDevice;
   5.215 -
   5.216 -    return this;
   5.217 -}
   5.218 -
   5.219 -AudioBootStrap MINTAUDIO_bootstrap = {
   5.220 -	MINT_AUDIO_DRIVER_NAME, "MiNT audio driver",
   5.221 -	Audio_Available, Audio_CreateDevice
   5.222 -};
   5.223 -
   5.224 -static void Mint_LockAudio(_THIS)
   5.225 -{
   5.226 -	void *oldpile;
   5.227 -
   5.228 -	/* Stop replay */
   5.229 -	if ((cookie_snd & SND_16BIT)!=0) {
   5.230 -		Buffoper(0);
   5.231 -	} else if ((cookie_snd & SND_8BIT)!=0) {
   5.232 -		oldpile=(void *)Super(0);
   5.233 -		DMAAUDIO_IO.control=0;
   5.234 -		Super(oldpile);
   5.235 -	}
   5.236 -}
   5.237 -
   5.238 -static void Mint_UnlockAudio(_THIS)
   5.239 -{
   5.240 -	void *oldpile;
   5.241 -
   5.242 -	/* Restart replay */
   5.243 -	if ((cookie_snd & SND_16BIT)!=0) {
   5.244 -		Buffoper(SB_PLA_ENA|SB_PLA_RPT);
   5.245 -	} else if ((cookie_snd & SND_8BIT)!=0) {
   5.246 -		oldpile=(void *)Super(0);
   5.247 -		DMAAUDIO_IO.control=3;
   5.248 -		Super(oldpile);
   5.249 -	}
   5.250 -}
   5.251 -
   5.252 -/* This is called from the interrupt routine */
   5.253  void SDL_MintAudio_Callback(void)
   5.254  {
   5.255 -	SDL_AudioDevice *audio;
   5.256  	Uint8 *buffer;
   5.257  
   5.258 -	audio = SDL_MintAudio_device;
   5.259   	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
   5.260 +	memset(buffer, SDL_MintAudio_device->spec.silence, SDL_MintAudio_device->spec.size);
   5.261  
   5.262 -	if ( ! audio->paused ) {
   5.263 -		if ( audio->convert.needed ) {
   5.264 -			audio->spec.callback(audio->spec.userdata,
   5.265 -				(Uint8 *)audio->convert.buf,audio->convert.len);
   5.266 -			SDL_ConvertAudio(&audio->convert);
   5.267 -			memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
   5.268 +	if ( ! SDL_MintAudio_device->paused ) {
   5.269 +		if ( SDL_MintAudio_device->convert.needed ) {
   5.270 +			SDL_MintAudio_device->spec.callback(SDL_MintAudio_device->spec.userdata,
   5.271 +				(Uint8 *)SDL_MintAudio_device->convert.buf,SDL_MintAudio_device->convert.len);
   5.272 +			SDL_ConvertAudio(&SDL_MintAudio_device->convert);
   5.273 +			memcpy(buffer, SDL_MintAudio_device->convert.buf, SDL_MintAudio_device->convert.len_cvt);
   5.274  		} else {
   5.275 -			audio->spec.callback(audio->spec.userdata, buffer, audio->spec.size);
   5.276 +			SDL_MintAudio_device->spec.callback(SDL_MintAudio_device->spec.userdata, buffer, SDL_MintAudio_device->spec.size);
   5.277  		}
   5.278  	}
   5.279  }
   5.280  
   5.281 -static void Mint_StopAudio_Dma8(void)
   5.282 -{
   5.283 -	void *oldpile;
   5.284 -	
   5.285 -	oldpile=(void *)Super(0);
   5.286 -	DMAAUDIO_IO.control=0;
   5.287 -	Super(oldpile);
   5.288 -
   5.289 -	Jdisint(MFP_DMASOUND);
   5.290 -}
   5.291 -
   5.292 -static void Mint_StopAudio_Xbios(void)
   5.293 -{
   5.294 -	Buffoper(0);
   5.295 -	Jdisint(MFP_DMASOUND);
   5.296 -}
   5.297 -
   5.298 -static void Mint_StopAudio_Gsxb(void)
   5.299 -{
   5.300 -	Buffoper(0);
   5.301 -}
   5.302 -
   5.303 -static void Mint_CloseAudio(_THIS)
   5.304 -{
   5.305 -	if (cookie_gsxb && ((cookie_snd & (SND_GSXB|SND_16BIT))==(SND_GSXB|SND_16BIT)) ) {
   5.306 -		Mint_StopAudio_Gsxb();
   5.307 -	} else if ((cookie_snd & SND_16BIT)!=0) {
   5.308 -		Mint_StopAudio_Xbios();
   5.309 -	} else if ((cookie_snd & SND_8BIT)!=0) {
   5.310 -		Mint_StopAudio_Dma8();
   5.311 -	}
   5.312 -
   5.313 -	/* Clear buffers */
   5.314 -	if (SDL_MintAudio_audiobuf[0]) {
   5.315 -		Mfree(SDL_MintAudio_audiobuf[0]);
   5.316 -		SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
   5.317 -	}
   5.318 -
   5.319 -	/* Unlock sound system */
   5.320 -	if ((cookie_snd & SND_16BIT)!=0) {
   5.321 -		Unlocksnd();
   5.322 -	}
   5.323 -}
   5.324 -
   5.325 -static void Mint_CheckAudio_Dma8(SDL_AudioSpec *spec)
   5.326 +/* Simple function to search for the nearest frequency */
   5.327 +int SDL_MintAudio_SearchFrequency(_THIS, int falcon_codec, int desired_freq)
   5.328  {
   5.329  	int i;
   5.330  
   5.331 -	spec->format = AUDIO_S8;
   5.332 -
   5.333 -	switch(cookie_mch>>16) {
   5.334 -		case MCH_STE:
   5.335 -			/* STE replay frequencies */
   5.336 -			for (i=0;i<4;i++) {
   5.337 -				hardfreq[i]=MASTERCLOCK_STE/(MASTERPREDIV_STE*(i+1));
   5.338 -			}
   5.339 -
   5.340 -			if (spec->freq>=(hardfreq[0]+hardfreq[1])>>1) {
   5.341 -				numfreq=3;		/* 50066 */
   5.342 -			} else if (spec->freq>=(hardfreq[1]+hardfreq[2])>>1) {
   5.343 -				numfreq=2;		/* 25033 */
   5.344 -			} else if (spec->freq>=(hardfreq[2]+hardfreq[3])>>1) {
   5.345 -				numfreq=1;		/* 12517 */
   5.346 -			} else {
   5.347 -				numfreq=0;		/* 6258 */
   5.348 -			}
   5.349 -
   5.350 -			spec->freq=hardfreq[numfreq];
   5.351 -			break;
   5.352 -		case MCH_TT:
   5.353 -			/* TT replay frequencies */
   5.354 -			for (i=0;i<4;i++) {
   5.355 -				hardfreq[i]=MASTERCLOCK_TT/(MASTERPREDIV_TT*(i+1));
   5.356 -			}
   5.357 -
   5.358 -			if (spec->freq>=(hardfreq[0]+hardfreq[1])>>1) {
   5.359 -				numfreq=3;		/* 50337 */
   5.360 -			} else if (spec->freq>=(hardfreq[1]+hardfreq[2])>>1) {
   5.361 -				numfreq=2;		/* 25169 */
   5.362 -			} else if (spec->freq>=(hardfreq[2]+hardfreq[3])>>1) {
   5.363 -				numfreq=1;		/* 12584 */
   5.364 -			} else {
   5.365 -				numfreq=0;		/* 6292 */
   5.366 -			}
   5.367 -			spec->freq=hardfreq[numfreq];
   5.368 -			break;
   5.369 -	}
   5.370 -}
   5.371 -
   5.372 -static void Mint_CheckAudio_Xbios(SDL_AudioSpec *spec)
   5.373 -{
   5.374 -	int i;
   5.375 -
   5.376 -	/* Check conversions needed */
   5.377 -	switch (spec->format & 0xff) {
   5.378 -		case 8:
   5.379 -			spec->format = AUDIO_S8;
   5.380 -			break;
   5.381 -		case 16:
   5.382 -			spec->format = AUDIO_S16MSB;
   5.383 -			break;
   5.384 -	}
   5.385 -	
   5.386 -	/* Check hardware channels */
   5.387 -	if ((spec->channels==1) && ((spec->format & 0xff)==16)) {
   5.388 -		spec->channels=2;
   5.389 +	/* Only 1 freq ? */
   5.390 +	if (MINTAUDIO_nfreq==1) {
   5.391 +		return(MINTAUDIO_sfreq);
   5.392  	}
   5.393  
   5.394 -	/* Falcon replay frequencies */
   5.395 -	for (i=0;i<16;i++) {
   5.396 -		hardfreq[i]=MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1));
   5.397 -	}
   5.398 +	/* Check the array */
   5.399 +	for (i=MINTAUDIO_sfreq; i<MINTAUDIO_nfreq-1; i++) {
   5.400 +		/* Remove unusable falcon codec frequencies */
   5.401 +		if (falcon_codec) {
   5.402 +			if ((i==6) || (i==8) || (i==10)) {
   5.403 +				continue;
   5.404 +			}
   5.405 +		}
   5.406  
   5.407 -	/* The Falcon CODEC only support some frequencies */
   5.408 -	if (spec->freq>=(hardfreq[CLK50K]+hardfreq[CLK33K])>>1) {
   5.409 -		numfreq=CLK50K;		/* 49170 */
   5.410 -	} else if (spec->freq>=(hardfreq[CLK33K]+hardfreq[CLK25K])>>1) {
   5.411 -		numfreq=CLK33K;		/* 32780 */
   5.412 -	} else if (spec->freq>=(hardfreq[CLK25K]+hardfreq[CLK20K])>>1) {
   5.413 -		numfreq=CLK25K;		/* 24585 */
   5.414 -	} else if (spec->freq>=(hardfreq[CLK20K]+hardfreq[CLK16K])>>1) {
   5.415 -		numfreq=CLK20K;		/* 19668 */
   5.416 -	} else if (spec->freq>=(hardfreq[CLK16K]+hardfreq[CLK12K])>>1) {
   5.417 -		numfreq=CLK16K;		/* 16390 */
   5.418 -	} else if (spec->freq>=(hardfreq[CLK12K]+hardfreq[CLK10K])>>1) {
   5.419 -		numfreq=CLK12K;		/* 12292 */
   5.420 -	} else if (spec->freq>=(hardfreq[CLK10K]+hardfreq[CLK8K])>>1) {
   5.421 -		numfreq=CLK10K;		/* 9834 */
   5.422 -	} else {
   5.423 -		numfreq=CLK8K;		/* 8195 */
   5.424 -	}				
   5.425 -
   5.426 -	spec->freq=hardfreq[numfreq];
   5.427 -}
   5.428 -
   5.429 -static int Mint_CheckAudio_Gsxb(SDL_AudioSpec *spec)
   5.430 -{
   5.431 -	long snd_format;
   5.432 -	int i, resolution, format_signed, format_bigendian;
   5.433 -
   5.434 -	resolution = spec->format & 0x00ff;
   5.435 -	format_signed = ((spec->format & 0x8000)!=0);
   5.436 -	format_bigendian = ((spec->format & 0x1000)!=0);
   5.437 -
   5.438 -	/* Check formats available */
   5.439 -	snd_format = Sndstatus(SND_QUERYFORMATS);
   5.440 -	switch (resolution) {
   5.441 -		case 8:
   5.442 -			if ((snd_format & SND_FORMAT8)==0) {
   5.443 -				SDL_SetError("Mint_CheckAudio: 8 bits samples not supported");
   5.444 -				return -1;
   5.445 -			}
   5.446 -			snd_format = Sndstatus(SND_QUERY8BIT);
   5.447 -			break;
   5.448 -		case 16:
   5.449 -			if ((snd_format & SND_FORMAT16)==0) {
   5.450 -				SDL_SetError("Mint_CheckAudio: 16 bits samples not supported");
   5.451 -				return -1;
   5.452 -			}
   5.453 -			snd_format = Sndstatus(SND_QUERY16BIT);
   5.454 -			break;
   5.455 -		default:
   5.456 -			SDL_SetError("Mint_CheckAudio: Unsupported sample resolution");
   5.457 -			return -1;
   5.458 -			break;
   5.459 -	}
   5.460 -
   5.461 -	/* Check signed/unsigned format */
   5.462 -	if (format_signed) {
   5.463 -		if (snd_format & SND_FORMATSIGNED) {
   5.464 -			/* Ok */
   5.465 -		} else if (snd_format & SND_FORMATUNSIGNED) {
   5.466 -			/* Give unsigned format */
   5.467 -			spec->format = spec->format & (~0x8000);
   5.468 -		}
   5.469 -	} else {
   5.470 -		if (snd_format & SND_FORMATUNSIGNED) {
   5.471 -			/* Ok */
   5.472 -		} else if (snd_format & SND_FORMATSIGNED) {
   5.473 -			/* Give signed format */
   5.474 -			spec->format |= 0x8000;
   5.475 +		if (desired_freq >= ((MINTAUDIO_hardfreq[i]+MINTAUDIO_hardfreq[i+1])>>1)) {
   5.476 +			return i;
   5.477  		}
   5.478  	}
   5.479  
   5.480 -	if (format_bigendian) {
   5.481 -		if (snd_format & SND_FORMATBIGENDIAN) {
   5.482 -			/* Ok */
   5.483 -		} else if (snd_format & SND_FORMATLITTLEENDIAN) {
   5.484 -			/* Give little endian format */
   5.485 -			spec->format = spec->format & (~0x1000);
   5.486 -		}
   5.487 -	} else {
   5.488 -		if (snd_format & SND_FORMATBIGENDIAN) {
   5.489 -			/* Ok */
   5.490 -		} else if (snd_format & SND_FORMATLITTLEENDIAN) {
   5.491 -			/* Give big endian format */
   5.492 -			spec->format |= 0x1000;
   5.493 -		}
   5.494 -	}
   5.495 -	
   5.496 -	/* Only xbios functions available = clone with PC board */
   5.497 -	for (i=0;i<8;i++) {
   5.498 -		hardfreq[i]=MASTERCLOCK_MILAN1/(MASTERPREDIV_MILAN*(i+1));
   5.499 -	}
   5.500 -
   5.501 -	if (spec->freq>=(hardfreq[CLK_44K]+hardfreq[CLK_22K])>>1) {
   5.502 -		numfreq = CLK_44K;	/* 44100 */
   5.503 -	} else if (spec->freq>=(hardfreq[CLK_22K]+hardfreq[CLK_11K])>>1) {
   5.504 -		numfreq = CLK_22K;	/* 22050 */
   5.505 -	} else {
   5.506 -		numfreq = CLK_11K;	/* 11025 */
   5.507 -	}				
   5.508 -
   5.509 -	spec->freq=hardfreq[numfreq];
   5.510 -
   5.511 -	return 0;
   5.512 +	/* Not in the array, give the latest */
   5.513 +	return MINTAUDIO_nfreq-1;
   5.514  }
   5.515 -
   5.516 -static void Mint_InitAudio_Dma8(SDL_AudioSpec *spec)
   5.517 -{
   5.518 -	void *oldpile;
   5.519 -	unsigned long buffer;
   5.520 -	unsigned char mode;
   5.521 -	
   5.522 -	oldpile=(void *)Super(0);
   5.523 -
   5.524 -	/* Stop currently playing sound */
   5.525 -	DMAAUDIO_IO.control=0;
   5.526 -
   5.527 -	/* Set buffer */
   5.528 -	buffer = (unsigned long) SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
   5.529 -	DMAAUDIO_IO.start_high = (buffer>>16) & 255;
   5.530 -	DMAAUDIO_IO.start_mid = (buffer>>8) & 255;
   5.531 -	DMAAUDIO_IO.start_low = buffer & 255;
   5.532 -
   5.533 -	buffer += SDL_MintAudio_audiosize;
   5.534 -	DMAAUDIO_IO.end_high = (buffer>>16) & 255;
   5.535 -	DMAAUDIO_IO.end_mid = (buffer>>8) & 255;
   5.536 -	DMAAUDIO_IO.end_low = buffer & 255;
   5.537 -
   5.538 -	mode = numfreq;
   5.539 -	if (spec->channels==1) {
   5.540 -		mode |= 1<<7;
   5.541 -	}
   5.542 -	DMAAUDIO_IO.mode = mode;	
   5.543 -
   5.544 -	/* Set interrupt */
   5.545 -	Jdisint(MFP_DMASOUND);
   5.546 -	Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_IntDma);
   5.547 -	Jenabint(MFP_DMASOUND);
   5.548 -
   5.549 -	/* Go */
   5.550 -	DMAAUDIO_IO.control = 3;	/* playback + repeat */
   5.551 -
   5.552 -	Super(oldpile);
   5.553 -}
   5.554 -
   5.555 -static void Mint_InitAudio_Xbios(SDL_AudioSpec *spec)
   5.556 -{
   5.557 -	int channels_mode;
   5.558 -	void *buffer;
   5.559 -
   5.560 -	/* Stop currently playing sound */
   5.561 -	Buffoper(0);
   5.562 -
   5.563 -	Settracks(0,0);
   5.564 -	Setmontracks(0);
   5.565 -
   5.566 -	switch (spec->format & 0xff) {
   5.567 -		case 8:
   5.568 -			if (spec->channels==2) {
   5.569 -				channels_mode=STEREO8;
   5.570 -			} else {
   5.571 -				channels_mode=MONO8;
   5.572 -			}
   5.573 -			break;
   5.574 -		case 16:
   5.575 -		default:
   5.576 -			channels_mode=STEREO16;
   5.577 -			break;
   5.578 -	}
   5.579 -	Setmode(channels_mode);
   5.580 -
   5.581 -	Devconnect(DMAPLAY, DAC, CLK25M, numfreq, 1);
   5.582 -
   5.583 -	/* Set buffer */
   5.584 -	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
   5.585 -	Setbuffer(0, buffer, buffer+SDL_MintAudio_audiosize);
   5.586 -	
   5.587 -	/* Install interrupt */
   5.588 -	Setinterrupt(SI_TIMERA, SI_PLAY);
   5.589 -
   5.590 -	Jdisint(MFP_DMASOUND);
   5.591 -	Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_IntXbios);
   5.592 -	Jenabint(MFP_DMASOUND);
   5.593 -
   5.594 -	/* Go */
   5.595 -	Buffoper(SB_PLA_ENA|SB_PLA_RPT);
   5.596 -}
   5.597 -
   5.598 -static void Mint_InitAudio_Gsxb(SDL_AudioSpec *spec)
   5.599 -{
   5.600 -	int channels_mode;
   5.601 -	void *buffer;
   5.602 -
   5.603 -	/* Stop currently playing sound */
   5.604 -	Buffoper(0);
   5.605 -
   5.606 -	switch (spec->format & 0xff) {
   5.607 -		case 8:
   5.608 -			if (spec->channels==2) {
   5.609 -				channels_mode=STEREO8;
   5.610 -			} else {
   5.611 -				channels_mode=MONO8;
   5.612 -			}
   5.613 -			break;
   5.614 -		case 16:
   5.615 -			if (spec->channels==2) {
   5.616 -				channels_mode=STEREO16;
   5.617 -			} else {
   5.618 -				channels_mode=MONO16;
   5.619 -			}
   5.620 -			break;
   5.621 -		default:
   5.622 -			channels_mode=STEREO16;
   5.623 -			break;
   5.624 -	}
   5.625 -	Setmode(channels_mode);
   5.626 -
   5.627 -	Devconnect(0, 0, CLKEXT, numfreq, 1);
   5.628 -
   5.629 -	/* Set buffer */
   5.630 -	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
   5.631 -	Setbuffer(0, buffer, buffer+SDL_MintAudio_audiosize);
   5.632 -	
   5.633 -	/* Install interrupt */
   5.634 -	NSetinterrupt(2, SI_PLAY, SDL_MintAudio_IntGsxb);
   5.635 -		
   5.636 -	/* Go */
   5.637 -	Buffoper(SB_PLA_ENA|SB_PLA_RPT);
   5.638 -}
   5.639 -
   5.640 -static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec)
   5.641 -{
   5.642 -	/* Lock sound system */
   5.643 -	if ((cookie_snd & SND_16BIT)!=0) {
   5.644 -		if (Locksnd()!=1) {
   5.645 -    	    SDL_SetError("Mint_OpenAudio: Audio system already in use");
   5.646 -	        return(-1);
   5.647 -		}
   5.648 -	}
   5.649 -
   5.650 -	/* Check audio capabilities */
   5.651 -	if (cookie_gsxb && ((cookie_snd & (SND_GSXB|SND_16BIT))==(SND_GSXB|SND_16BIT)) ) {
   5.652 -		if (Mint_CheckAudio_Gsxb(spec)==-1) {
   5.653 -			return -1;
   5.654 -		}
   5.655 -	} else if ((cookie_snd & SND_16BIT)!=0) {
   5.656 -		Mint_CheckAudio_Xbios(spec);
   5.657 -	} else if ((cookie_snd & SND_8BIT)!=0) {
   5.658 -		Mint_CheckAudio_Dma8(spec);
   5.659 -	}
   5.660 -
   5.661 -	SDL_CalculateAudioSpec(spec);
   5.662 -
   5.663 -	/* Allocate memory for audio buffers in DMA-able RAM */
   5.664 -	spec->size = spec->samples;
   5.665 -	spec->size *= spec->channels;
   5.666 -	spec->size *= (spec->format & 0xFF)/8;
   5.667 -
   5.668 -	SDL_MintAudio_audiosize = spec->size;
   5.669 -
   5.670 -	SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(SDL_MintAudio_audiosize *2, MX_STRAM);
   5.671 -	if (SDL_MintAudio_audiobuf[0]==NULL) {
   5.672 -		SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
   5.673 -		return (-1);
   5.674 -	}
   5.675 -	SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + SDL_MintAudio_audiosize;
   5.676 -	SDL_MintAudio_numbuf=0;
   5.677 -	memset(SDL_MintAudio_audiobuf[0], 0, SDL_MintAudio_audiosize * 2);
   5.678 -	SDL_MintAudio_mutex = 0;
   5.679 -
   5.680 -	SDL_MintAudio_device = this;
   5.681 -
   5.682 -	/* Setup audio hardware */
   5.683 -	if (cookie_gsxb && ((cookie_snd & (SND_GSXB|SND_16BIT))==(SND_GSXB|SND_16BIT)) ) {
   5.684 -		Mint_InitAudio_Gsxb(spec);
   5.685 -	} else if ((cookie_snd & SND_16BIT)!=0) {
   5.686 -		Mint_InitAudio_Xbios(spec);
   5.687 -	} else if ((cookie_snd & SND_8BIT)!=0) {
   5.688 -		Mint_InitAudio_Dma8(spec);
   5.689 -	}
   5.690 -
   5.691 -    return 1;
   5.692 -}
     6.1 --- a/src/audio/mint/SDL_mintaudio.h	Tue Jul 01 16:35:54 2003 +0000
     6.2 +++ b/src/audio/mint/SDL_mintaudio.h	Mon Jul 07 19:16:03 2003 +0000
     6.3 @@ -1,15 +1,125 @@
     6.4  /*
     6.5 - * MiNT audio driver
     6.6 - * 
     6.7 - * Patrice Mandin
     6.8 - */
     6.9 +    SDL - Simple DirectMedia Layer
    6.10 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    6.11 +
    6.12 +    This library is free software; you can redistribute it and/or
    6.13 +    modify it under the terms of the GNU Library General Public
    6.14 +    License as published by the Free Software Foundation; either
    6.15 +    version 2 of the License, or (at your option) any later version.
    6.16 +
    6.17 +    This library is distributed in the hope that it will be useful,
    6.18 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.19 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.20 +    Library General Public License for more details.
    6.21 +
    6.22 +    You should have received a copy of the GNU Library General Public
    6.23 +    License along with this library; if not, write to the Free
    6.24 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.25 +
    6.26 +    Sam Lantinga
    6.27 +    slouken@libsdl.org
    6.28 +*/
    6.29 +
    6.30 +/*
    6.31 +	MiNT audio driver
    6.32 +
    6.33 +	Patrice Mandin
    6.34 +*/
    6.35  
    6.36  #ifndef _SDL_mintaudio_h
    6.37  #define _SDL_mintaudio_h
    6.38  
    6.39  #include "SDL_sysaudio.h"
    6.40 +#include "SDL_mintaudio_stfa.h"
    6.41  
    6.42  /* Hidden "this" pointer for the audio functions */
    6.43  #define _THIS	SDL_AudioDevice *this
    6.44  
    6.45 +struct SDL_PrivateAudioData {
    6.46 +	Uint32	hardfreq[16];	/* Array of replay freqs of the hardware */
    6.47 +	int		sfreq;			/* First number of freq to use in the array */
    6.48 +	int 	nfreq;			/* Number of freqs to use in the array */
    6.49 +	int		numfreq;		/* Number of selected frequency */
    6.50 +};
    6.51 +
    6.52 +/* Old variable names */
    6.53 +#define MINTAUDIO_hardfreq		(this->hidden->hardfreq)
    6.54 +#define MINTAUDIO_sfreq			(this->hidden->sfreq)
    6.55 +#define MINTAUDIO_nfreq			(this->hidden->nfreq)
    6.56 +#define MINTAUDIO_numfreq		(this->hidden->numfreq)
    6.57 +
    6.58 +/* _MCH cookie (values>>16) */
    6.59 +enum {
    6.60 +	MCH_ST=0,
    6.61 +	MCH_STE,
    6.62 +	MCH_TT,
    6.63 +	MCH_F30
    6.64 +};
    6.65 +
    6.66 +/* Master clocks for replay frequencies */
    6.67 +#define MASTERCLOCK_STE		8010666		/* Not sure of this one */
    6.68 +#define MASTERCLOCK_TT		16107953	/* Not sure of this one */
    6.69 +#define MASTERCLOCK_FALCON1	25175000
    6.70 +#define MASTERCLOCK_FALCON2	32000000	/* Only usable for DSP56K */
    6.71 +#define MASTERCLOCK_FALCONEXT	-1		/* Clock on DSP56K port, unknown */
    6.72 +#define MASTERCLOCK_44K		22579200	/* Standard clock for 44.1 Khz */
    6.73 +#define MASTERCLOCK_48K		24576000	/* Standard clock for 48 Khz */
    6.74 +
    6.75 +/* Master clock predivisors */
    6.76 +#define MASTERPREDIV_STE	160
    6.77 +#define MASTERPREDIV_TT		320
    6.78 +#define MASTERPREDIV_FALCON	256
    6.79 +#define MASTERPREDIV_MILAN	256
    6.80 +
    6.81 +/* MFP 68901 interrupt sources */
    6.82 +enum {
    6.83 +	MFP_PARALLEL=0,
    6.84 +	MFP_DCD,
    6.85 +	MFP_CTS,
    6.86 +	MFP_BITBLT,
    6.87 +	MFP_TIMERD,
    6.88 +	MFP_BAUDRATE=MFP_TIMERD,
    6.89 +	MFP_TIMERC,
    6.90 +	MFP_200HZ=MFP_TIMERC,
    6.91 +	MFP_ACIA,
    6.92 +	MFP_DISK,
    6.93 +	MFP_TIMERB,
    6.94 +	MFP_HBLANK=MFP_TIMERB,
    6.95 +	MFP_TERR,
    6.96 +	MFP_TBE,
    6.97 +	MFP_RERR,
    6.98 +	MFP_RBF,
    6.99 +	MFP_TIMERA,
   6.100 +	MFP_DMASOUND=MFP_TIMERA,
   6.101 +	MFP_RING,
   6.102 +	MFP_MONODETECT
   6.103 +};
   6.104 +
   6.105 +/* Xbtimer() timers */
   6.106 +enum {
   6.107 +	XB_TIMERA=0,
   6.108 +	XB_TIMERB,
   6.109 +	XB_TIMERC,
   6.110 +	XB_TIMERD
   6.111 +};
   6.112 +
   6.113 +/* Variables */
   6.114 +extern SDL_AudioDevice *SDL_MintAudio_device;
   6.115 +extern Uint8 *SDL_MintAudio_audiobuf[2];	/* Pointers to buffers */
   6.116 +extern long SDL_MintAudio_audiosize;		/* Length of audio buffer=spec->size */
   6.117 +extern long SDL_MintAudio_numbuf;		/* Buffer to play */
   6.118 +extern long SDL_MintAudio_mutex;
   6.119 +extern cookie_stfa_t *SDL_MintAudio_stfa;
   6.120 +
   6.121 +/* Functions */
   6.122 +void SDL_MintAudio_Callback(void);
   6.123 +int SDL_MintAudio_SearchFrequency(_THIS, int falcon_codec, int desired_freq);
   6.124 +
   6.125 +/* ASM interrupt functions */
   6.126 +void SDL_MintAudio_GsxbInterrupt(void);
   6.127 +void SDL_MintAudio_EmptyGsxbInterrupt(void);
   6.128 +void SDL_MintAudio_XbiosInterrupt(void);
   6.129 +void SDL_MintAudio_Dma8Interrupt(void);
   6.130 +void SDL_MintAudio_StfaInterrupt(void);
   6.131 +
   6.132  #endif /* _SDL_mintaudio_h */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/audio/mint/SDL_mintaudio_dma8.c	Mon Jul 07 19:16:03 2003 +0000
     7.3 @@ -0,0 +1,354 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     7.7 +
     7.8 +    This library is free software; you can redistribute it and/or
     7.9 +    modify it under the terms of the GNU Library General Public
    7.10 +    License as published by the Free Software Foundation; either
    7.11 +    version 2 of the License, or (at your option) any later version.
    7.12 +
    7.13 +    This library is distributed in the hope that it will be useful,
    7.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +    Library General Public License for more details.
    7.17 +
    7.18 +    You should have received a copy of the GNU Library General Public
    7.19 +    License along with this library; if not, write to the Free
    7.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.21 +
    7.22 +    Sam Lantinga
    7.23 +    slouken@libsdl.org
    7.24 +*/
    7.25 +
    7.26 +/*
    7.27 +	MiNT audio driver
    7.28 +	using DMA 8bits (hardware access)
    7.29 +
    7.30 +	Patrice Mandin
    7.31 +*/
    7.32 +
    7.33 +#include <stdlib.h>
    7.34 +#include <stdio.h>
    7.35 +#include <string.h>
    7.36 +
    7.37 +/* Mint includes */
    7.38 +#include <mint/osbind.h>
    7.39 +#include <mint/falcon.h>
    7.40 +#include <mint/cookie.h>
    7.41 +
    7.42 +#include "SDL_endian.h"
    7.43 +#include "SDL_audio.h"
    7.44 +#include "SDL_audio_c.h"
    7.45 +#include "SDL_audiomem.h"
    7.46 +#include "SDL_sysaudio.h"
    7.47 +
    7.48 +#include "SDL_atarimxalloc_c.h"
    7.49 +
    7.50 +#include "SDL_mintaudio.h"
    7.51 +#include "SDL_mintaudio_dma8.h"
    7.52 +
    7.53 +/*--- Defines ---*/
    7.54 +
    7.55 +#define MINT_AUDIO_DRIVER_NAME "mint_dma8"
    7.56 +
    7.57 +/* Debug print info */
    7.58 +#define DEBUG_NAME "audio:dma8: "
    7.59 +#if 0
    7.60 +#define DEBUG_PRINT(what) \
    7.61 +	{ \
    7.62 +		printf what; \
    7.63 +	}
    7.64 +#else
    7.65 +#define DEBUG_PRINT(what)
    7.66 +#endif
    7.67 +
    7.68 +/*--- Static variables ---*/
    7.69 +
    7.70 +static unsigned long cookie_snd, cookie_mch;
    7.71 +
    7.72 +/*--- Audio driver functions ---*/
    7.73 +
    7.74 +static void Mint_CloseAudio(_THIS);
    7.75 +static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec);
    7.76 +static void Mint_LockAudio(_THIS);
    7.77 +static void Mint_UnlockAudio(_THIS);
    7.78 +
    7.79 +/* To check/init hardware audio */
    7.80 +static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec);
    7.81 +static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec);
    7.82 +
    7.83 +/*--- Audio driver bootstrap functions ---*/
    7.84 +
    7.85 +static int Audio_Available(void)
    7.86 +{
    7.87 +	const char *envr = getenv("SDL_AUDIODRIVER");
    7.88 +
    7.89 +	/* Check if user asked a different audio driver */
    7.90 +	if ((envr) && (strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
    7.91 +		DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
    7.92 +		return 0;
    7.93 +	}
    7.94 +
    7.95 +	/* Cookie _MCH present ? if not, assume ST machine */
    7.96 +	if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
    7.97 +		cookie_mch = MCH_ST;
    7.98 +	}
    7.99 +
   7.100 +	/* Cookie _SND present ? if not, assume ST machine */
   7.101 +	if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
   7.102 +		cookie_snd = SND_PSG;
   7.103 +	}
   7.104 +
   7.105 +	/* Check if we have 8 bits audio */
   7.106 +	if ((cookie_snd & SND_8BIT)==0) {
   7.107 +		DEBUG_PRINT((DEBUG_NAME "no 8 bits sound\n"));
   7.108 +	    return(0);
   7.109 +	}
   7.110 +
   7.111 +	if ((cookie_mch>>16)>MCH_F30) {
   7.112 +		DEBUG_PRINT((DEBUG_NAME "unknown 8 bits audio chip\n"));
   7.113 +		return 0;
   7.114 +	}
   7.115 +
   7.116 +	/* Check if audio is lockable */
   7.117 +	if ((cookie_mch>>16) == MCH_F30) {
   7.118 +		if (Locksnd()!=1) {
   7.119 +			DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n"));
   7.120 +			return(0);
   7.121 +		}
   7.122 +
   7.123 +		Unlocksnd();
   7.124 +	}
   7.125 +
   7.126 +	DEBUG_PRINT((DEBUG_NAME "8 bits audio available!\n"));
   7.127 +	return(1);
   7.128 +}
   7.129 +
   7.130 +static void Audio_DeleteDevice(SDL_AudioDevice *device)
   7.131 +{
   7.132 +    free(device->hidden);
   7.133 +    free(device);
   7.134 +}
   7.135 +
   7.136 +static SDL_AudioDevice *Audio_CreateDevice(int devindex)
   7.137 +{
   7.138 +	SDL_AudioDevice *this;
   7.139 +
   7.140 +	/* Initialize all variables that we clean on shutdown */
   7.141 +	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
   7.142 +    if ( this ) {
   7.143 +        memset(this, 0, (sizeof *this));
   7.144 +        this->hidden = (struct SDL_PrivateAudioData *)
   7.145 +                malloc((sizeof *this->hidden));
   7.146 +    }
   7.147 +    if ( (this == NULL) || (this->hidden == NULL) ) {
   7.148 +        SDL_OutOfMemory();
   7.149 +        if ( this ) {
   7.150 +            free(this);
   7.151 +        }
   7.152 +        return(0);
   7.153 +    }
   7.154 +    memset(this->hidden, 0, (sizeof *this->hidden));
   7.155 +
   7.156 +    /* Set the function pointers */
   7.157 +    this->OpenAudio   = Mint_OpenAudio;
   7.158 +    this->CloseAudio  = Mint_CloseAudio;
   7.159 +    this->LockAudio   = Mint_LockAudio;
   7.160 +    this->UnlockAudio = Mint_UnlockAudio;
   7.161 +    this->free        = Audio_DeleteDevice;
   7.162 +
   7.163 +    return this;
   7.164 +}
   7.165 +
   7.166 +AudioBootStrap MINTAUDIO_DMA8_bootstrap = {
   7.167 +	MINT_AUDIO_DRIVER_NAME, "MiNT DMA 8 bits audio driver",
   7.168 +	Audio_Available, Audio_CreateDevice
   7.169 +};
   7.170 +
   7.171 +static void Mint_LockAudio(_THIS)
   7.172 +{
   7.173 +	void *oldpile;
   7.174 +
   7.175 +	/* Stop replay */
   7.176 +	oldpile=(void *)Super(0);
   7.177 +	DMAAUDIO_IO.control=0;
   7.178 +	Super(oldpile);
   7.179 +}
   7.180 +
   7.181 +static void Mint_UnlockAudio(_THIS)
   7.182 +{
   7.183 +	void *oldpile;
   7.184 +
   7.185 +	/* Restart replay */
   7.186 +	oldpile=(void *)Super(0);
   7.187 +	DMAAUDIO_IO.control=3;
   7.188 +	Super(oldpile);
   7.189 +}
   7.190 +
   7.191 +static void Mint_CloseAudio(_THIS)
   7.192 +{
   7.193 +	void *oldpile;
   7.194 +
   7.195 +	/* Stop replay */
   7.196 +	oldpile=(void *)Super(0);
   7.197 +	DMAAUDIO_IO.control=0;
   7.198 +	Super(oldpile);
   7.199 +
   7.200 +	DEBUG_PRINT((DEBUG_NAME "closeaudio: replay stopped\n"));
   7.201 +
   7.202 +	/* Disable interrupt */
   7.203 +	Jdisint(MFP_DMASOUND);
   7.204 +
   7.205 +	DEBUG_PRINT((DEBUG_NAME "closeaudio: interrupt disabled\n"));
   7.206 +
   7.207 +	/* Wait if currently playing sound */
   7.208 +	while (SDL_MintAudio_mutex != 0) {
   7.209 +	}
   7.210 +
   7.211 +	DEBUG_PRINT((DEBUG_NAME "closeaudio: no more interrupt running\n"));
   7.212 +
   7.213 +	/* Clear buffers */
   7.214 +	if (SDL_MintAudio_audiobuf[0]) {
   7.215 +		Mfree(SDL_MintAudio_audiobuf[0]);
   7.216 +		SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
   7.217 +	}
   7.218 +
   7.219 +	DEBUG_PRINT((DEBUG_NAME "closeaudio: buffers freed\n"));
   7.220 +}
   7.221 +
   7.222 +static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
   7.223 +{
   7.224 +	int i, masterprediv;
   7.225 +	unsigned long masterclock;
   7.226 +
   7.227 +	DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff));
   7.228 +	DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
   7.229 +	DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x8000)!=0)));
   7.230 +	DEBUG_PRINT(("channels=%d, ", spec->channels));
   7.231 +	DEBUG_PRINT(("freq=%d\n", spec->freq));
   7.232 +
   7.233 +	/* Check formats available */
   7.234 +	spec->format = AUDIO_S8;
   7.235 +	
   7.236 +	/* Calculate and select the closest frequency */
   7.237 +	MINTAUDIO_nfreq=4;
   7.238 +	MINTAUDIO_sfreq=0;
   7.239 +	masterclock=MASTERCLOCK_STE;
   7.240 +	masterprediv=MASTERPREDIV_STE;
   7.241 +	switch(cookie_mch>>16) {
   7.242 +/*
   7.243 +		case MCH_STE:
   7.244 +			masterclock=MASTERCLOCK_STE;
   7.245 +			masterprediv=MASTERPREDIV_STE;
   7.246 +			break;
   7.247 +*/
   7.248 +		case MCH_TT:
   7.249 +			masterclock=MASTERCLOCK_TT;
   7.250 +			masterprediv=MASTERPREDIV_TT;
   7.251 +			break;
   7.252 +		case MCH_F30:
   7.253 +			masterclock=MASTERCLOCK_FALCON1;
   7.254 +			masterprediv=MASTERPREDIV_FALCON<<1;
   7.255 +			MINTAUDIO_nfreq=3;
   7.256 +			MINTAUDIO_sfreq=1;
   7.257 +			break;
   7.258 +	}
   7.259 +	for (i=MINTAUDIO_sfreq;i<MINTAUDIO_nfreq;i++) {
   7.260 +		MINTAUDIO_hardfreq[i]=masterclock/(masterprediv*(1<<i));
   7.261 +		DEBUG_PRINT((DEBUG_NAME "calc:freq(%d)=%lu\n", i, MINTAUDIO_hardfreq[i]));
   7.262 +	}
   7.263 +
   7.264 +	MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, 0, spec->freq);
   7.265 +	spec->freq=MINTAUDIO_hardfreq[MINTAUDIO_numfreq];
   7.266 +
   7.267 +	DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff));
   7.268 +	DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
   7.269 +	DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x8000)!=0)));
   7.270 +	DEBUG_PRINT(("channels=%d, ", spec->channels));
   7.271 +	DEBUG_PRINT(("freq=%d\n", spec->freq));
   7.272 +
   7.273 +	return 0;
   7.274 +}
   7.275 +
   7.276 +static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec)
   7.277 +{
   7.278 +	void *oldpile;
   7.279 +	unsigned long buffer;
   7.280 +	unsigned char mode;
   7.281 +	
   7.282 +	/* Set replay tracks */
   7.283 +	if (cookie_snd & SND_16BIT) {
   7.284 +		Settracks(0,0);
   7.285 +		Setmontracks(0);
   7.286 +	}
   7.287 +
   7.288 +	oldpile=(void *)Super(0);
   7.289 +
   7.290 +	/* Stop currently playing sound */
   7.291 +	DMAAUDIO_IO.control=0;
   7.292 +
   7.293 +	/* Set buffer */
   7.294 +	buffer = (unsigned long) SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
   7.295 +	DMAAUDIO_IO.start_high = (buffer>>16) & 255;
   7.296 +	DMAAUDIO_IO.start_mid = (buffer>>8) & 255;
   7.297 +	DMAAUDIO_IO.start_low = buffer & 255;
   7.298 +
   7.299 +	buffer += SDL_MintAudio_audiosize;
   7.300 +	DMAAUDIO_IO.end_high = (buffer>>16) & 255;
   7.301 +	DMAAUDIO_IO.end_mid = (buffer>>8) & 255;
   7.302 +	DMAAUDIO_IO.end_low = buffer & 255;
   7.303 +
   7.304 +	mode = 3-MINTAUDIO_numfreq;
   7.305 +	if (spec->channels==1) {
   7.306 +		mode |= 1<<7;
   7.307 +	}
   7.308 +	DMAAUDIO_IO.mode = mode;	
   7.309 +
   7.310 +	/* Set interrupt */
   7.311 +	Jdisint(MFP_DMASOUND);
   7.312 +	Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_Dma8Interrupt);
   7.313 +	Jenabint(MFP_DMASOUND);
   7.314 +
   7.315 +	/* Go */
   7.316 +	DMAAUDIO_IO.control = 3;	/* playback + repeat */
   7.317 +
   7.318 +	Super(oldpile);
   7.319 +}
   7.320 +
   7.321 +static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec)
   7.322 +{
   7.323 +	SDL_MintAudio_device = this;
   7.324 +
   7.325 +	/* Check audio capabilities */
   7.326 +	if (Mint_CheckAudio(this, spec)==-1) {
   7.327 +		return -1;
   7.328 +	}
   7.329 +
   7.330 +	SDL_CalculateAudioSpec(spec);
   7.331 +
   7.332 +	/* Allocate memory for audio buffers in DMA-able RAM */
   7.333 +	spec->size = spec->samples;
   7.334 +	spec->size *= spec->channels;
   7.335 +	spec->size *= (spec->format & 0xFF)/8;
   7.336 +
   7.337 +	DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
   7.338 +
   7.339 +	SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM);
   7.340 +	if (SDL_MintAudio_audiobuf[0]==NULL) {
   7.341 +		SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
   7.342 +		return (-1);
   7.343 +	}
   7.344 +	SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ;
   7.345 +	SDL_MintAudio_numbuf=0;
   7.346 +	memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
   7.347 +	SDL_MintAudio_audiosize = spec->size;
   7.348 +	SDL_MintAudio_mutex = 0;
   7.349 +
   7.350 +	DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0]));
   7.351 +	DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1]));
   7.352 +
   7.353 +	/* Setup audio hardware */
   7.354 +	Mint_InitAudio(this, spec);
   7.355 +
   7.356 +    return(1);	/* We don't use threaded audio */
   7.357 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/audio/mint/SDL_mintaudio_dma8.h	Mon Jul 07 19:16:03 2003 +0000
     8.3 @@ -0,0 +1,65 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Library General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Library General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Library General Public
    8.19 +    License along with this library; if not, write to the Free
    8.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@libsdl.org
    8.24 +*/
    8.25 +
    8.26 +/*
    8.27 +	DMA 8bits audio definitions
    8.28 +
    8.29 +	Patrice Mandin
    8.30 +*/
    8.31 +
    8.32 +#ifndef _SDL_mintaudio_dma8_h
    8.33 +#define _SDL_mintaudio_dma8_h
    8.34 +
    8.35 +#define DMAAUDIO_IO_BASE (0xffff8900)
    8.36 +struct DMAAUDIO_IO_S {
    8.37 +	unsigned char int_ctrl;
    8.38 +	unsigned char control;
    8.39 +
    8.40 +	unsigned char dummy1;
    8.41 +	unsigned char start_high;
    8.42 +	unsigned char dummy2;
    8.43 +	unsigned char start_mid;
    8.44 +	unsigned char dummy3;
    8.45 +	unsigned char start_low;
    8.46 +
    8.47 +	unsigned char dummy4;
    8.48 +	unsigned char cur_high;
    8.49 +	unsigned char dummy5;
    8.50 +	unsigned char cur_mid;
    8.51 +	unsigned char dummy6;
    8.52 +	unsigned char cur_low;
    8.53 +
    8.54 +	unsigned char dummy7;
    8.55 +	unsigned char end_high;
    8.56 +	unsigned char dummy8;
    8.57 +	unsigned char end_mid;
    8.58 +	unsigned char dummy9;
    8.59 +	unsigned char end_low;
    8.60 +
    8.61 +	unsigned char dummy10[12];
    8.62 +
    8.63 +	unsigned char track_select; /* CODEC only */
    8.64 +	unsigned char mode;
    8.65 +};
    8.66 +#define DMAAUDIO_IO ((*(volatile struct DMAAUDIO_IO_S *)DMAAUDIO_IO_BASE))
    8.67 +
    8.68 +#endif /* _SDL_mintaudio_dma8_h */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/audio/mint/SDL_mintaudio_gsxb.c	Mon Jul 07 19:16:03 2003 +0000
     9.3 @@ -0,0 +1,395 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Library General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Library General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Library General Public
    9.19 +    License along with this library; if not, write to the Free
    9.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@libsdl.org
    9.24 +*/
    9.25 +
    9.26 +/*
    9.27 +	MiNT audio driver
    9.28 +	using XBIOS functions (GSXB compatible driver)
    9.29 +
    9.30 +	Patrice Mandin
    9.31 +*/
    9.32 +
    9.33 +#include <stdlib.h>
    9.34 +#include <stdio.h>
    9.35 +#include <string.h>
    9.36 +
    9.37 +/* Mint includes */
    9.38 +#include <mint/osbind.h>
    9.39 +#include <mint/falcon.h>
    9.40 +#include <mint/cookie.h>
    9.41 +
    9.42 +#include "SDL_endian.h"
    9.43 +#include "SDL_audio.h"
    9.44 +#include "SDL_audio_c.h"
    9.45 +#include "SDL_audiomem.h"
    9.46 +#include "SDL_sysaudio.h"
    9.47 +
    9.48 +#include "SDL_atarimxalloc_c.h"
    9.49 +
    9.50 +#include "SDL_mintaudio.h"
    9.51 +#include "SDL_mintaudio_gsxb.h"
    9.52 +
    9.53 +/*--- Defines ---*/
    9.54 +
    9.55 +#define MINT_AUDIO_DRIVER_NAME "mint_gsxb"
    9.56 +
    9.57 +/* Debug print info */
    9.58 +#define DEBUG_NAME "audio:gsxb: "
    9.59 +#if 0
    9.60 +#define DEBUG_PRINT(what) \
    9.61 +	{ \
    9.62 +		printf what; \
    9.63 +	}
    9.64 +#else
    9.65 +#define DEBUG_PRINT(what)
    9.66 +#endif
    9.67 +
    9.68 +/*--- Static variables ---*/
    9.69 +
    9.70 +static unsigned long cookie_snd, cookie_gsxb;
    9.71 +
    9.72 +/*--- Audio driver functions ---*/
    9.73 +
    9.74 +static void Mint_CloseAudio(_THIS);
    9.75 +static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec);
    9.76 +static void Mint_LockAudio(_THIS);
    9.77 +static void Mint_UnlockAudio(_THIS);
    9.78 +
    9.79 +/* To check/init hardware audio */
    9.80 +static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec);
    9.81 +static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec);
    9.82 +
    9.83 +/*--- Audio driver bootstrap functions ---*/
    9.84 +
    9.85 +static int Audio_Available(void)
    9.86 +{
    9.87 +	const char *envr = getenv("SDL_AUDIODRIVER");
    9.88 +
    9.89 +	/* Check if user asked a different audio driver */
    9.90 +	if ((envr) && (strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
    9.91 +		DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
    9.92 +		return(0);
    9.93 +	}
    9.94 +
    9.95 +	/* Cookie _SND present ? if not, assume ST machine */
    9.96 +	if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
    9.97 +		cookie_snd = SND_PSG;
    9.98 +	}
    9.99 +
   9.100 +	/* Check if we have 16 bits audio */
   9.101 +	if ((cookie_snd & SND_16BIT)==0) {
   9.102 +		DEBUG_PRINT((DEBUG_NAME "no 16 bits sound\n"));
   9.103 +	    return(0);
   9.104 +	}
   9.105 +
   9.106 +	/* Cookie GSXB present ? */
   9.107 +	cookie_gsxb = (Getcookie(C_GSXB, &cookie_gsxb) == C_FOUND);
   9.108 +
   9.109 +	/* Is it GSXB ? */
   9.110 +	if (((cookie_snd & SND_GSXB)==0) || (cookie_gsxb==0)) {
   9.111 +		DEBUG_PRINT((DEBUG_NAME "no GSXB audio\n"));
   9.112 +		return(0);
   9.113 +	}
   9.114 +
   9.115 +	/* Check if audio is lockable */
   9.116 +	if (Locksnd()!=1) {
   9.117 +		DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n"));
   9.118 +		return(0);
   9.119 +	}
   9.120 +
   9.121 +	Unlocksnd();
   9.122 +
   9.123 +	DEBUG_PRINT((DEBUG_NAME "GSXB audio available!\n"));
   9.124 +	return(1);
   9.125 +}
   9.126 +
   9.127 +static void Audio_DeleteDevice(SDL_AudioDevice *device)
   9.128 +{
   9.129 +    free(device->hidden);
   9.130 +    free(device);
   9.131 +}
   9.132 +
   9.133 +static SDL_AudioDevice *Audio_CreateDevice(int devindex)
   9.134 +{
   9.135 +	SDL_AudioDevice *this;
   9.136 +
   9.137 +	/* Initialize all variables that we clean on shutdown */
   9.138 +	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
   9.139 +    if ( this ) {
   9.140 +        memset(this, 0, (sizeof *this));
   9.141 +        this->hidden = (struct SDL_PrivateAudioData *)
   9.142 +                malloc((sizeof *this->hidden));
   9.143 +    }
   9.144 +    if ( (this == NULL) || (this->hidden == NULL) ) {
   9.145 +        SDL_OutOfMemory();
   9.146 +        if ( this ) {
   9.147 +            free(this);
   9.148 +        }
   9.149 +        return(0);
   9.150 +    }
   9.151 +    memset(this->hidden, 0, (sizeof *this->hidden));
   9.152 +
   9.153 +    /* Set the function pointers */
   9.154 +    this->OpenAudio   = Mint_OpenAudio;
   9.155 +    this->CloseAudio  = Mint_CloseAudio;
   9.156 +    this->LockAudio   = Mint_LockAudio;
   9.157 +    this->UnlockAudio = Mint_UnlockAudio;
   9.158 +    this->free        = Audio_DeleteDevice;
   9.159 +
   9.160 +    return this;
   9.161 +}
   9.162 +
   9.163 +AudioBootStrap MINTAUDIO_GSXB_bootstrap = {
   9.164 +	MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver",
   9.165 +	Audio_Available, Audio_CreateDevice
   9.166 +};
   9.167 +
   9.168 +static void Mint_LockAudio(_THIS)
   9.169 +{
   9.170 +	/* Stop replay */
   9.171 +	Buffoper(0);
   9.172 +}
   9.173 +
   9.174 +static void Mint_UnlockAudio(_THIS)
   9.175 +{
   9.176 +	/* Restart replay */
   9.177 +	Buffoper(SB_PLA_ENA|SB_PLA_RPT);
   9.178 +}
   9.179 +
   9.180 +static void Mint_CloseAudio(_THIS)
   9.181 +{
   9.182 +	/* Stop replay */
   9.183 +	Buffoper(0);
   9.184 +
   9.185 +	DEBUG_PRINT((DEBUG_NAME "closeaudio: replay stopped\n"));
   9.186 +
   9.187 +	/* Uninstall interrupt */
   9.188 +	if (NSetinterrupt(2, SI_NONE, SDL_MintAudio_EmptyGsxbInterrupt)<0) {
   9.189 +		DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n"));
   9.190 +	}
   9.191 +
   9.192 +	DEBUG_PRINT((DEBUG_NAME "closeaudio: interrupt disabled\n"));
   9.193 +
   9.194 +	/* Wait if currently playing sound */
   9.195 +	while (SDL_MintAudio_mutex != 0) {
   9.196 +	}
   9.197 +
   9.198 +	DEBUG_PRINT((DEBUG_NAME "closeaudio: no more interrupt running\n"));
   9.199 +
   9.200 +	/* Clear buffers */
   9.201 +	if (SDL_MintAudio_audiobuf[0]) {
   9.202 +		Mfree(SDL_MintAudio_audiobuf[0]);
   9.203 +		SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
   9.204 +	}
   9.205 +
   9.206 +	DEBUG_PRINT((DEBUG_NAME "closeaudio: buffers freed\n"));
   9.207 +
   9.208 +	/* Unlock sound system */
   9.209 +	Unlocksnd();
   9.210 +}
   9.211 +
   9.212 +static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
   9.213 +{
   9.214 +	long snd_format;
   9.215 +	int i, resolution, format_signed, format_bigendian;
   9.216 +
   9.217 +	resolution = spec->format & 0x00ff;
   9.218 +	format_signed = ((spec->format & 0x8000)!=0);
   9.219 +	format_bigendian = ((spec->format & 0x1000)!=0);
   9.220 +	DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",resolution));
   9.221 +	DEBUG_PRINT(("signed=%d, ", format_signed));
   9.222 +	DEBUG_PRINT(("big endian=%d, ", format_bigendian));
   9.223 +	DEBUG_PRINT(("channels=%d, ", spec->channels));
   9.224 +	DEBUG_PRINT(("freq=%d\n", spec->freq));
   9.225 +
   9.226 +	/* Check formats available */
   9.227 +	snd_format = Sndstatus(SND_QUERYFORMATS);
   9.228 +	switch (resolution) {
   9.229 +		case 8:
   9.230 +			if ((snd_format & SND_FORMAT8)==0) {
   9.231 +				SDL_SetError("Mint_CheckAudio: 8 bits samples not supported");
   9.232 +				return -1;
   9.233 +			}
   9.234 +			snd_format = Sndstatus(SND_QUERY8BIT);
   9.235 +			break;
   9.236 +		case 16:
   9.237 +			if ((snd_format & SND_FORMAT16)==0) {
   9.238 +				SDL_SetError("Mint_CheckAudio: 16 bits samples not supported");
   9.239 +				return -1;
   9.240 +			}
   9.241 +			snd_format = Sndstatus(SND_QUERY16BIT);
   9.242 +			break;
   9.243 +		default:
   9.244 +			SDL_SetError("Mint_CheckAudio: Unsupported sample resolution");
   9.245 +			return -1;
   9.246 +			break;
   9.247 +	}
   9.248 +
   9.249 +	/* Check signed/unsigned format */
   9.250 +	if (format_signed) {
   9.251 +		if (snd_format & SND_FORMATSIGNED) {
   9.252 +			/* Ok */
   9.253 +		} else if (snd_format & SND_FORMATUNSIGNED) {
   9.254 +			/* Give unsigned format */
   9.255 +			spec->format = spec->format & (~0x8000);
   9.256 +		}
   9.257 +	} else {
   9.258 +		if (snd_format & SND_FORMATUNSIGNED) {
   9.259 +			/* Ok */
   9.260 +		} else if (snd_format & SND_FORMATSIGNED) {
   9.261 +			/* Give signed format */
   9.262 +			spec->format |= 0x8000;
   9.263 +		}
   9.264 +	}
   9.265 +
   9.266 +	if (format_bigendian) {
   9.267 +		if (snd_format & SND_FORMATBIGENDIAN) {
   9.268 +			/* Ok */
   9.269 +		} else if (snd_format & SND_FORMATLITTLEENDIAN) {
   9.270 +			/* Give little endian format */
   9.271 +			spec->format = spec->format & (~0x1000);
   9.272 +		}
   9.273 +	} else {
   9.274 +		if (snd_format & SND_FORMATBIGENDIAN) {
   9.275 +			/* Ok */
   9.276 +		} else if (snd_format & SND_FORMATLITTLEENDIAN) {
   9.277 +			/* Give big endian format */
   9.278 +			spec->format |= 0x1000;
   9.279 +		}
   9.280 +	}
   9.281 +	
   9.282 +	/* Calculate and select the closest frequency */
   9.283 +	MINTAUDIO_sfreq=1;
   9.284 +	MINTAUDIO_nfreq=12;
   9.285 +	for (i=MINTAUDIO_sfreq;i<MINTAUDIO_nfreq;i++) {
   9.286 +		MINTAUDIO_hardfreq[i]=MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(i+1));
   9.287 +		DEBUG_PRINT((DEBUG_NAME "calc:freq(%d)=%lu\n", i, MINTAUDIO_hardfreq[i]));
   9.288 +	}
   9.289 +
   9.290 +	MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, 1, spec->freq);
   9.291 +	spec->freq=MINTAUDIO_hardfreq[MINTAUDIO_numfreq];
   9.292 +
   9.293 +	DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff));
   9.294 +	DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
   9.295 +	DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x8000)!=0)));
   9.296 +	DEBUG_PRINT(("channels=%d, ", spec->channels));
   9.297 +	DEBUG_PRINT(("freq=%d\n", spec->freq));
   9.298 +
   9.299 +	return 0;
   9.300 +}
   9.301 +
   9.302 +static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec)
   9.303 +{
   9.304 +	int channels_mode;
   9.305 +	void *buffer;
   9.306 +
   9.307 +	/* Stop currently playing sound */
   9.308 +	Buffoper(0);
   9.309 +
   9.310 +	/* Set replay tracks */
   9.311 +	Settracks(0,0);
   9.312 +	Setmontracks(0);
   9.313 +
   9.314 +	/* Select replay format */
   9.315 +	switch (spec->format & 0xff) {
   9.316 +		case 8:
   9.317 +			if (spec->channels==2) {
   9.318 +				channels_mode=STEREO8;
   9.319 +			} else {
   9.320 +				channels_mode=MONO8;
   9.321 +			}
   9.322 +			break;
   9.323 +		case 16:
   9.324 +			if (spec->channels==2) {
   9.325 +				channels_mode=STEREO16;
   9.326 +			} else {
   9.327 +				channels_mode=MONO16;
   9.328 +			}
   9.329 +			break;
   9.330 +		default:
   9.331 +			channels_mode=STEREO16;
   9.332 +			break;
   9.333 +	}
   9.334 +	if (Setmode(channels_mode)<0) {
   9.335 +		DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n"));
   9.336 +	}
   9.337 +
   9.338 +	Devconnect(DMAPLAY, DAC, CLKEXT, MINTAUDIO_numfreq, 1);
   9.339 +
   9.340 +	/* Set buffer */
   9.341 +	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
   9.342 +	if (Setbuffer(0, buffer, buffer + spec->size)<0) {
   9.343 +		DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));
   9.344 +	}
   9.345 +	
   9.346 +	/* Install interrupt */
   9.347 +	if (NSetinterrupt(2, SI_PLAY, SDL_MintAudio_GsxbInterrupt)<0) {
   9.348 +		DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed\n"));
   9.349 +	}
   9.350 +
   9.351 +	/* Go */
   9.352 +	Buffoper(SB_PLA_ENA|SB_PLA_RPT);
   9.353 +	DEBUG_PRINT((DEBUG_NAME "hardware initialized\n"));
   9.354 +}
   9.355 +
   9.356 +static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec)
   9.357 +{
   9.358 +	/* Lock sound system */
   9.359 +	if (Locksnd()!=1) {
   9.360 +   	    SDL_SetError("Mint_OpenAudio: Audio system already in use");
   9.361 +        return(-1);
   9.362 +	}
   9.363 +
   9.364 +	SDL_MintAudio_device = this;
   9.365 +
   9.366 +	/* Check audio capabilities */
   9.367 +	if (Mint_CheckAudio(this, spec)==-1) {
   9.368 +		return -1;
   9.369 +	}
   9.370 +
   9.371 +	SDL_CalculateAudioSpec(spec);
   9.372 +
   9.373 +	/* Allocate memory for audio buffers in DMA-able RAM */
   9.374 +	spec->size = spec->samples;
   9.375 +	spec->size *= spec->channels;
   9.376 +	spec->size *= (spec->format & 0xFF)/8;
   9.377 +
   9.378 +	DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
   9.379 +
   9.380 +	SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM);
   9.381 +	if (SDL_MintAudio_audiobuf[0]==NULL) {
   9.382 +		SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
   9.383 +		return (-1);
   9.384 +	}
   9.385 +	SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ;
   9.386 +	SDL_MintAudio_numbuf=0;
   9.387 +	memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
   9.388 +	SDL_MintAudio_audiosize = spec->size;
   9.389 +	SDL_MintAudio_mutex = 0;
   9.390 +
   9.391 +	DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0]));
   9.392 +	DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1]));
   9.393 +
   9.394 +	/* Setup audio hardware */
   9.395 +	Mint_InitAudio(this, spec);
   9.396 +
   9.397 +    return(1);	/* We don't use threaded audio */
   9.398 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/audio/mint/SDL_mintaudio_gsxb.h	Mon Jul 07 19:16:03 2003 +0000
    10.3 @@ -0,0 +1,85 @@
    10.4 +/*
    10.5 + * GSXB audio definitions
    10.6 + * 
    10.7 + * Patrice Mandin
    10.8 + */
    10.9 +
   10.10 +#ifndef _SDL_mintaudio_gsxb_h
   10.11 +#define _SDL_mintaudio_gsxb_h
   10.12 +
   10.13 +#include <mint/falcon.h>	/* for trap_14_xxx macros */
   10.14 +
   10.15 +/* GSXB Cookie */
   10.16 +
   10.17 +#define C_GSXB		0x47535842L
   10.18 +
   10.19 +/* Bit 5 in cookie _SND */
   10.20 +
   10.21 +#define SND_GSXB	(1<<5)
   10.22 +
   10.23 +/* NSoundcmd modes */
   10.24 +
   10.25 +#define SETRATE			7	/* Set sample rate */
   10.26 +#define SET8BITFORMAT	8	/* 8 bits format */
   10.27 +#define SET16BITFORMAT	9	/* 16 bits format */
   10.28 +#define SET24BITFORMAT	10	/* 24 bits format */
   10.29 +#define SET32BITFORMAT	11	/* 32 bits format */
   10.30 +#define LTATTEN_MASTER	12	/* Attenuation */
   10.31 +#define RTATTEN_MASTER	13
   10.32 +#define LTATTEN_MICIN	14
   10.33 +#define RTATTEN_MICIN	15
   10.34 +#define LTATTEN_FMGEN	16
   10.35 +#define RTATTEN_FMGEN	17
   10.36 +#define LTATTEN_LINEIN	18
   10.37 +#define RTATTEN_LINEIN	19
   10.38 +#define LTATTEN_CDIN	20
   10.39 +#define RTATTEN_CDIN	21
   10.40 +#define LTATTEN_VIDIN	22
   10.41 +#define RTATTEN_VIDIN	23
   10.42 +#define LTATTEN_AUXIN	24
   10.43 +#define RTATTEN_AUXIN	25
   10.44 +
   10.45 +/* Setmode modes */
   10.46 +
   10.47 +#define MONO16		3
   10.48 +#define STEREO24	4
   10.49 +#define STEREO32	5
   10.50 +#define MONO24		6
   10.51 +#define MONO32		7
   10.52 +
   10.53 +/* Sndstatus modes */
   10.54 +
   10.55 +#define SND_QUERYFORMATS	2
   10.56 +#define SND_QUERYMIXERS		3
   10.57 +#define SND_QUERYSOURCES	4
   10.58 +#define SND_QUERYDUPLEX		5
   10.59 +#define SND_QUERY8BIT		8
   10.60 +#define SND_QUERY16BIT		9
   10.61 +#define SND_QUERY24BIT		10
   10.62 +#define SND_QUERY32BIT		11
   10.63 +
   10.64 +#define SND_FORMAT8		(1<<0)
   10.65 +#define SND_FORMAT16	(1<<1)
   10.66 +#define SND_FORMAT24	(1<<2)
   10.67 +#define SND_FORMAT32	(1<<3)
   10.68 +
   10.69 +#define SND_FORMATSIGNED		(1<<0)
   10.70 +#define SND_FORMATUNSIGNED		(1<<1)
   10.71 +#define SND_FORMATBIGENDIAN		(1<<2)
   10.72 +#define SND_FORMATLITTLEENDIAN	(1<<3)
   10.73 +
   10.74 +/* Devconnect prescalers */
   10.75 +
   10.76 +#define CLK_44K		1
   10.77 +#define CLK_22K		3
   10.78 +#define CLK_11K		7
   10.79 +
   10.80 +/* Extra xbios functions */
   10.81 +
   10.82 +#define NSoundcmd(mode,data,data2)	\
   10.83 +	(long)trap_14_wwl((short)130,(short)(mode),(short)(data),(long)(data2))
   10.84 +#define NSetinterrupt(src_inter,cause,inth_addr)	\
   10.85 +	(long)trap_14_wwwl((short)135,(short)(src_inter),(short)(cause),	\
   10.86 +		(long)(inth_addr))
   10.87 +
   10.88 +#endif /* _SDL_mintaudio_gsxb_h */
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/audio/mint/SDL_mintaudio_it.S	Mon Jul 07 19:16:03 2003 +0000
    11.3 @@ -0,0 +1,242 @@
    11.4 +/*
    11.5 +    SDL - Simple DirectMedia Layer
    11.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    11.7 +
    11.8 +    This library is free software; you can redistribute it and/or
    11.9 +    modify it under the terms of the GNU Library General Public
   11.10 +    License as published by the Free Software Foundation; either
   11.11 +    version 2 of the License, or (at your option) any later version.
   11.12 +
   11.13 +    This library is distributed in the hope that it will be useful,
   11.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.16 +    Library General Public License for more details.
   11.17 +
   11.18 +    You should have received a copy of the GNU Library General Public
   11.19 +    License along with this library; if not, write to the Free
   11.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.21 +
   11.22 +    Sam Lantinga
   11.23 +    slouken@libsdl.org
   11.24 +*/
   11.25 +
   11.26 +/*
   11.27 +	Audio interrupts
   11.28 +
   11.29 +	Patrice Mandin
   11.30 + */
   11.31 +
   11.32 +	.text
   11.33 +
   11.34 +	.globl	_SDL_MintAudio_Callback
   11.35 +
   11.36 +	.globl	_SDL_MintAudio_GsxbInterrupt
   11.37 +	.globl	_SDL_MintAudio_EmptyGsxbInterrupt
   11.38 +	.globl	_SDL_MintAudio_XbiosInterrupt
   11.39 +	.globl	_SDL_MintAudio_Dma8Interrupt
   11.40 +	.globl	_SDL_MintAudio_StfaInterrupt
   11.41 +
   11.42 +	.globl	_SDL_MintAudio_mutex
   11.43 +	.globl	_SDL_MintAudio_audiobuf
   11.44 +	.globl	_SDL_MintAudio_numbuf
   11.45 +	.globl	_SDL_MintAudio_audiosize
   11.46 +
   11.47 +	.globl	_SDL_MintAudio_stfa
   11.48 +
   11.49 +/*
   11.50 +	How it works:
   11.51 +	- Audio is playing buffer #0 (resp. #1)
   11.52 +	- We must calculate a sample in buffer #1 (resp. #0)
   11.53 +	  so we first call the callback to do it
   11.54 +	- Then we swap the buffers
   11.55 +*/
   11.56 +
   11.57 +/*--- GSXB interrupt vector ---*/
   11.58 +
   11.59 +	.text
   11.60 +_SDL_MintAudio_GsxbInterrupt:
   11.61 +
   11.62 +	/* Check if we are not already running */
   11.63 +	tstw	_SDL_MintAudio_mutex
   11.64 +	bnes	_SDL_MintAudio_EmptyGsxbInterrupt
   11.65 +	notw	_SDL_MintAudio_mutex
   11.66 +	
   11.67 +	/* Swap buffers */
   11.68 +	moveml	d0-d2/a0-a2,sp@-
   11.69 +
   11.70 +	movel	_SDL_MintAudio_numbuf,d0
   11.71 +	movel	_SDL_MintAudio_audiobuf,a0
   11.72 +	eorl	#1,d0
   11.73 +	beqs	SDL_MintAudio_GsxbBuffer0
   11.74 +	movel	_SDL_MintAudio_audiobuf+4,a0
   11.75 +SDL_MintAudio_GsxbBuffer0:
   11.76 +	movel	d0,_SDL_MintAudio_numbuf
   11.77 +
   11.78 +	/* Callback */
   11.79 +	movel	a0,sp@-
   11.80 +	jsr	_SDL_MintAudio_Callback
   11.81 +	movel	sp@+,a0
   11.82 +
   11.83 +	/* Setbuffer xbios function */
   11.84 +	movel	_SDL_MintAudio_audiosize,d1
   11.85 +	lea	a0@(0,d1:l),a1
   11.86 +
   11.87 +	movel	a1,sp@-
   11.88 +	movel	a0,sp@-
   11.89 +	clrw	sp@-
   11.90 +	movew	#131,sp@-
   11.91 +	trap	#14
   11.92 +	lea	sp@(12),sp
   11.93 +
   11.94 +	moveml	sp@+,d0-d2/a0-a2
   11.95 +
   11.96 +	clrw	_SDL_MintAudio_mutex
   11.97 +_SDL_MintAudio_EmptyGsxbInterrupt:
   11.98 +	rts
   11.99 +
  11.100 +/*--- Xbios interrupt vector ---*/
  11.101 +
  11.102 +_SDL_MintAudio_XbiosInterrupt:
  11.103 +
  11.104 +	/* Reenable interrupts, so other interrupts can work */
  11.105 +	movew	#0x2300,sr
  11.106 +
  11.107 +	/* Clear service bit, so other MFP interrupts can work */
  11.108 +	bclr	#5,0xfffffa0f:w
  11.109 +
  11.110 +	/* Check if we are not already running */
  11.111 +	tstw	_SDL_MintAudio_mutex
  11.112 +	bnes	SDL_MintAudio_XbiosEnd
  11.113 +	notw	_SDL_MintAudio_mutex
  11.114 +	
  11.115 +	/* Swap buffers */
  11.116 +	moveml	d0-d2/a0-a2,sp@-
  11.117 +
  11.118 +	movel	_SDL_MintAudio_numbuf,d0
  11.119 +	movel	_SDL_MintAudio_audiobuf,a0
  11.120 +	eorl	#1,d0
  11.121 +	beqs	SDL_MintAudio_XbiosBuffer0
  11.122 +	movel	_SDL_MintAudio_audiobuf+4,a0
  11.123 +SDL_MintAudio_XbiosBuffer0:
  11.124 +	movel	d0,_SDL_MintAudio_numbuf
  11.125 +
  11.126 +	/* Callback */
  11.127 +	movel	a0,sp@-
  11.128 +	jsr	_SDL_MintAudio_Callback
  11.129 +	movel	sp@+,a0
  11.130 +
  11.131 +	/* Setbuffer xbios function */
  11.132 +	movel	_SDL_MintAudio_audiosize,d1
  11.133 +	lea	a0@(0,d1:l),a1
  11.134 +
  11.135 +	movel	a1,sp@-
  11.136 +	movel	a0,sp@-
  11.137 +	clrw	sp@-
  11.138 +	movew	#131,sp@-
  11.139 +	trap	#14
  11.140 +	lea	sp@(12),sp
  11.141 +
  11.142 +	moveml	sp@+,d0-d2/a0-a2
  11.143 +
  11.144 +	clrw	_SDL_MintAudio_mutex
  11.145 +SDL_MintAudio_XbiosEnd:
  11.146 +	rte
  11.147 +
  11.148 +/*--- DMA 8 bits interrupt vector ---*/
  11.149 +
  11.150 +_SDL_MintAudio_Dma8Interrupt:
  11.151 +
  11.152 +	/* Reenable interrupts, so other interrupts can work */
  11.153 +	movew	#0x2300,sr
  11.154 +
  11.155 +	/* Clear service bit, so other MFP interrupts can work */
  11.156 +	bclr	#5,0xfffffa0f:w
  11.157 +
  11.158 +	/* Check if we are not already running */
  11.159 +	tstw	_SDL_MintAudio_mutex
  11.160 +	bnes	SDL_MintAudio_Dma8End
  11.161 +	notw	_SDL_MintAudio_mutex
  11.162 +	
  11.163 +	/* Swap buffers */
  11.164 +	moveml	d0-d1/a0-a1,sp@-
  11.165 +
  11.166 +	movel	_SDL_MintAudio_numbuf,d0
  11.167 +	movel	_SDL_MintAudio_audiobuf,d1
  11.168 +	eorl	#1,d0
  11.169 +	beqs	SDL_MintAudio_Dma8Buffer0
  11.170 +	movel	_SDL_MintAudio_audiobuf+4,d1
  11.171 +SDL_MintAudio_Dma8Buffer0:
  11.172 +	movel	d0,_SDL_MintAudio_numbuf
  11.173 +
  11.174 +	/* Callback */
  11.175 +	movel	d1,sp@-
  11.176 +	jsr	_SDL_MintAudio_Callback
  11.177 +	movel	sp@+,d1
  11.178 +
  11.179 +	/* Modify DMA addresses */
  11.180 +	lea	0xffff8900:w,a0
  11.181 +
  11.182 +	moveb	d1,a0@(0x07)	/* Start address */
  11.183 +	rorl	#8,d1
  11.184 +	moveb	d1,a0@(0x05)
  11.185 +	rorl	#8,d1
  11.186 +	moveb	d1,a0@(0x03)
  11.187 +	swap	d1
  11.188 +
  11.189 +	addl	_SDL_MintAudio_audiosize,d1
  11.190 +
  11.191 +	moveb	d1,a0@(0x13)	/* End address */
  11.192 +	rorl	#8,d1
  11.193 +	moveb	d1,a0@(0x11)
  11.194 +	rorl	#8,d1
  11.195 +	moveb	d1,a0@(0x0f)
  11.196 +
  11.197 +	moveml	sp@+,d0-d1/a0-a1
  11.198 +
  11.199 +	clrw	_SDL_MintAudio_mutex
  11.200 +SDL_MintAudio_Dma8End:
  11.201 +	rte
  11.202 +
  11.203 +/*--- STFA interrupt vector ---*/
  11.204 +
  11.205 +STFA_SOUND_START	=	6
  11.206 +STFA_SOUND_END		=	STFA_SOUND_START+8
  11.207 +
  11.208 +_SDL_MintAudio_StfaInterrupt:
  11.209 +
  11.210 +	/* Reenable interrupts, so other interrupts can work */
  11.211 +	movew	#0x2300,sr
  11.212 +
  11.213 +	/* Check if we are not already running */
  11.214 +	tstw	_SDL_MintAudio_mutex
  11.215 +	bnes	SDL_MintAudio_StfaEnd
  11.216 +	notw	_SDL_MintAudio_mutex
  11.217 +	
  11.218 +	/* Swap buffers */
  11.219 +	moveml	d0-d1/a0-a1,sp@-
  11.220 +
  11.221 +	movel	_SDL_MintAudio_numbuf,d0
  11.222 +	movel	_SDL_MintAudio_audiobuf,d1
  11.223 +	eorl	#1,d0
  11.224 +	beqs	SDL_MintAudio_StfaBuffer0
  11.225 +	movel	_SDL_MintAudio_audiobuf+4,d1
  11.226 +SDL_MintAudio_StfaBuffer0:
  11.227 +	movel	d0,_SDL_MintAudio_numbuf
  11.228 +
  11.229 +	/* Callback */
  11.230 +	movel	d1,sp@-
  11.231 +	jsr	_SDL_MintAudio_Callback
  11.232 +	movel	sp@+,d1
  11.233 +
  11.234 +	/* Modify STFA replay buffers */
  11.235 +	movel	_SDL_MintAudio_stfa,a0
  11.236 +	movel	d1,a0@(STFA_SOUND_START)
  11.237 +	addl	_SDL_MintAudio_audiosize,d1
  11.238 +	movel	d1,a0@(STFA_SOUND_END)
  11.239 +
  11.240 +	moveml	sp@+,d0-d1/a0-a1
  11.241 +
  11.242 +	clrw	_SDL_MintAudio_mutex
  11.243 +SDL_MintAudio_StfaEnd:
  11.244 +	rte
  11.245 +
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/audio/mint/SDL_mintaudio_mcsn.c	Mon Jul 07 19:16:03 2003 +0000
    12.3 @@ -0,0 +1,379 @@
    12.4 +/*
    12.5 +    SDL - Simple DirectMedia Layer
    12.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    12.7 +
    12.8 +    This library is free software; you can redistribute it and/or
    12.9 +    modify it under the terms of the GNU Library General Public
   12.10 +    License as published by the Free Software Foundation; either
   12.11 +    version 2 of the License, or (at your option) any later version.
   12.12 +
   12.13 +    This library is distributed in the hope that it will be useful,
   12.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.16 +    Library General Public License for more details.
   12.17 +
   12.18 +    You should have received a copy of the GNU Library General Public
   12.19 +    License along with this library; if not, write to the Free
   12.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.21 +
   12.22 +    Sam Lantinga
   12.23 +    slouken@libsdl.org
   12.24 +*/
   12.25 +
   12.26 +/*
   12.27 +	MiNT audio driver
   12.28 +	using XBIOS functions (MacSound compatible driver)
   12.29 +
   12.30 +	Patrice Mandin
   12.31 +*/
   12.32 +
   12.33 +#include <stdlib.h>
   12.34 +#include <stdio.h>
   12.35 +#include <string.h>
   12.36 +
   12.37 +/* Mint includes */
   12.38 +#include <mint/osbind.h>
   12.39 +#include <mint/falcon.h>
   12.40 +#include <mint/cookie.h>
   12.41 +
   12.42 +#include "SDL_endian.h"
   12.43 +#include "SDL_audio.h"
   12.44 +#include "SDL_audio_c.h"
   12.45 +#include "SDL_audiomem.h"
   12.46 +#include "SDL_sysaudio.h"
   12.47 +
   12.48 +#include "SDL_atarimxalloc_c.h"
   12.49 +
   12.50 +#include "SDL_mintaudio.h"
   12.51 +#include "SDL_mintaudio_mcsn.h"
   12.52 +
   12.53 +/*--- Defines ---*/
   12.54 +
   12.55 +#define MINT_AUDIO_DRIVER_NAME "mint_mcsn"
   12.56 +
   12.57 +/* Debug print info */
   12.58 +#define DEBUG_NAME "audio:mcsn: "
   12.59 +#if 0
   12.60 +#define DEBUG_PRINT(what) \
   12.61 +	{ \
   12.62 +		printf what; \
   12.63 +	}
   12.64 +#else
   12.65 +#define DEBUG_PRINT(what)
   12.66 +#endif
   12.67 +
   12.68 +/*--- Static variables ---*/
   12.69 +
   12.70 +static unsigned long cookie_snd, cookie_mch;
   12.71 +static cookie_mcsn_t *cookie_mcsn;
   12.72 +
   12.73 +/*--- Audio driver functions ---*/
   12.74 +
   12.75 +static void Mint_CloseAudio(_THIS);
   12.76 +static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec);
   12.77 +static void Mint_LockAudio(_THIS);
   12.78 +static void Mint_UnlockAudio(_THIS);
   12.79 +
   12.80 +/* To check/init hardware audio */
   12.81 +static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec);
   12.82 +static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec);
   12.83 +
   12.84 +/*--- Audio driver bootstrap functions ---*/
   12.85 +
   12.86 +static int Audio_Available(void)
   12.87 +{
   12.88 +	const char *envr = getenv("SDL_AUDIODRIVER");
   12.89 +
   12.90 +	/* Check if user asked a different audio driver */
   12.91 +	if ((envr) && (strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
   12.92 +		DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
   12.93 +		return(0);
   12.94 +	}
   12.95 +
   12.96 +	/* Cookie _MCH present ? if not, assume ST machine */
   12.97 +	if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
   12.98 +		cookie_mch = MCH_ST;
   12.99 +	}
  12.100 +
  12.101 +	/* Cookie _SND present ? if not, assume ST machine */
  12.102 +	if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
  12.103 +		cookie_snd = SND_PSG;
  12.104 +	}
  12.105 +
  12.106 +	/* Check if we have 16 bits audio */
  12.107 +	if ((cookie_snd & SND_16BIT)==0) {
  12.108 +		DEBUG_PRINT((DEBUG_NAME "no 16 bits sound\n"));
  12.109 +	    return(0);
  12.110 +	}
  12.111 +
  12.112 +	/* Cookie MCSN present ? */
  12.113 +	if (Getcookie(C_McSn, (long *) &cookie_mcsn) != C_FOUND) {
  12.114 +		DEBUG_PRINT((DEBUG_NAME "no MCSN audio\n"));
  12.115 +		return(0);
  12.116 +	}
  12.117 +
  12.118 +	/* Check if interrupt at end of replay */
  12.119 +	if (cookie_mcsn->pint == 0) {
  12.120 +		DEBUG_PRINT((DEBUG_NAME "no interrupt at end of replay\n"));
  12.121 +		return(0);
  12.122 +	}
  12.123 +
  12.124 +	/* Check if audio is lockable */
  12.125 +	if (Locksnd()!=1) {
  12.126 +		DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n"));
  12.127 +		return(0);
  12.128 +	}
  12.129 +
  12.130 +	Unlocksnd();
  12.131 +
  12.132 +	DEBUG_PRINT((DEBUG_NAME "MCSN audio available!\n"));
  12.133 +	return(1);
  12.134 +}
  12.135 +
  12.136 +static void Audio_DeleteDevice(SDL_AudioDevice *device)
  12.137 +{
  12.138 +    free(device->hidden);
  12.139 +    free(device);
  12.140 +}
  12.141 +
  12.142 +static SDL_AudioDevice *Audio_CreateDevice(int devindex)
  12.143 +{
  12.144 +	SDL_AudioDevice *this;
  12.145 +
  12.146 +	/* Initialize all variables that we clean on shutdown */
  12.147 +	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
  12.148 +    if ( this ) {
  12.149 +        memset(this, 0, (sizeof *this));
  12.150 +        this->hidden = (struct SDL_PrivateAudioData *)
  12.151 +                malloc((sizeof *this->hidden));
  12.152 +    }
  12.153 +    if ( (this == NULL) || (this->hidden == NULL) ) {
  12.154 +        SDL_OutOfMemory();
  12.155 +        if ( this ) {
  12.156 +            free(this);
  12.157 +        }
  12.158 +        return(0);
  12.159 +    }
  12.160 +    memset(this->hidden, 0, (sizeof *this->hidden));
  12.161 +
  12.162 +    /* Set the function pointers */
  12.163 +    this->OpenAudio   = Mint_OpenAudio;
  12.164 +    this->CloseAudio  = Mint_CloseAudio;
  12.165 +    this->LockAudio   = Mint_LockAudio;
  12.166 +    this->UnlockAudio = Mint_UnlockAudio;
  12.167 +    this->free        = Audio_DeleteDevice;
  12.168 +
  12.169 +    return this;
  12.170 +}
  12.171 +
  12.172 +AudioBootStrap MINTAUDIO_MCSN_bootstrap = {
  12.173 +	MINT_AUDIO_DRIVER_NAME, "MiNT MCSN audio driver",
  12.174 +	Audio_Available, Audio_CreateDevice
  12.175 +};
  12.176 +
  12.177 +static void Mint_LockAudio(_THIS)
  12.178 +{
  12.179 +	/* Stop replay */
  12.180 +	Buffoper(0);
  12.181 +}
  12.182 +
  12.183 +static void Mint_UnlockAudio(_THIS)
  12.184 +{
  12.185 +	/* Restart replay */
  12.186 +	Buffoper(SB_PLA_ENA|SB_PLA_RPT);
  12.187 +}
  12.188 +
  12.189 +static void Mint_CloseAudio(_THIS)
  12.190 +{
  12.191 +	/* Stop replay */
  12.192 +	Buffoper(0);
  12.193 +
  12.194 +	/* Uninstall interrupt */
  12.195 +	Jdisint(MFP_DMASOUND);
  12.196 +
  12.197 +	/* Wait if currently playing sound */
  12.198 +	while (SDL_MintAudio_mutex != 0) {
  12.199 +	}
  12.200 +
  12.201 +	/* Clear buffers */
  12.202 +	if (SDL_MintAudio_audiobuf[0]) {
  12.203 +		Mfree(SDL_MintAudio_audiobuf[0]);
  12.204 +		SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
  12.205 +	}
  12.206 +
  12.207 +	/* Unlock sound system */
  12.208 +	Unlocksnd();
  12.209 +}
  12.210 +
  12.211 +static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
  12.212 +{
  12.213 +	int i;
  12.214 +	unsigned long masterclock, masterprediv;
  12.215 +
  12.216 +	DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff));
  12.217 +	DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
  12.218 +	DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x8000)!=0)));
  12.219 +	DEBUG_PRINT(("channels=%d, ", spec->channels));
  12.220 +	DEBUG_PRINT(("freq=%d\n", spec->freq));
  12.221 +
  12.222 +	/* Check formats available */
  12.223 +	MINTAUDIO_nfreq=4;
  12.224 +	MINTAUDIO_sfreq=0;
  12.225 +	switch(cookie_mcsn->play) {
  12.226 +		case MCSN_ST:
  12.227 +			spec->channels=1;
  12.228 +			spec->format=8; /* FIXME: is it signed or unsigned ? */
  12.229 +			MINTAUDIO_nfreq=1;
  12.230 +			MINTAUDIO_hardfreq[0]=12500;
  12.231 +			break;
  12.232 +		case MCSN_TT:	/* Also STE, Mega STE */
  12.233 +			spec->format=AUDIO_S8;
  12.234 +			masterclock=MASTERCLOCK_STE;
  12.235 +			masterprediv=MASTERPREDIV_STE;
  12.236 +			if ((cookie_mch>>16)==MCH_TT) {
  12.237 +				masterclock=MASTERCLOCK_TT;
  12.238 +				masterprediv=MASTERPREDIV_TT;
  12.239 +			}
  12.240 +			for (i=MINTAUDIO_sfreq;i<MINTAUDIO_nfreq;i++) {
  12.241 +				MINTAUDIO_hardfreq[i]=masterclock/(masterprediv*(1<<i));
  12.242 +				DEBUG_PRINT((DEBUG_NAME "calc:freq(%d)=%lu\n", i, MINTAUDIO_hardfreq[i]));
  12.243 +			}
  12.244 +			break;
  12.245 +		case MCSN_FALCON:	/* Also Mac */
  12.246 +			MINTAUDIO_nfreq=12;
  12.247 +			MINTAUDIO_sfreq=1;
  12.248 +			masterclock=MASTERCLOCK_FALCON1;
  12.249 +			if (cookie_mcsn->res1 != 0) {
  12.250 +				masterclock=cookie_mcsn->res1;
  12.251 +			}
  12.252 +			for (i=MINTAUDIO_sfreq;i<MINTAUDIO_nfreq;i++) {
  12.253 +				MINTAUDIO_hardfreq[i]=masterclock/(MASTERPREDIV_FALCON*(i+1));
  12.254 +				DEBUG_PRINT((DEBUG_NAME "calc:freq(%d)=%lu\n", i, MINTAUDIO_hardfreq[i]));
  12.255 +			}
  12.256 +			spec->format |= 0x8000;	/* Audio is always signed */
  12.257 +			if ((spec->format & 0x00ff)==16) {
  12.258 +				spec->format |= 0x1000;	/* Audio is always big endian */
  12.259 +				spec->channels=2;	/* 16 bits always stereo */
  12.260 +			}
  12.261 +			break;
  12.262 +	}
  12.263 +
  12.264 +	MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, (cookie_mch>>16)==MCH_F30, spec->freq);
  12.265 +	spec->freq=MINTAUDIO_hardfreq[MINTAUDIO_numfreq];
  12.266 +
  12.267 +	DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff));
  12.268 +	DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
  12.269 +	DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x8000)!=0)));
  12.270 +	DEBUG_PRINT(("channels=%d, ", spec->channels));
  12.271 +	DEBUG_PRINT(("freq=%d\n", spec->freq));
  12.272 +
  12.273 +	return 0;
  12.274 +}
  12.275 +
  12.276 +static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec)
  12.277 +{
  12.278 +	int channels_mode;
  12.279 +	void *buffer;
  12.280 +
  12.281 +	/* Stop currently playing sound */
  12.282 +	Buffoper(0);
  12.283 +
  12.284 +	/* Set replay tracks */
  12.285 +	Settracks(0,0);
  12.286 +	Setmontracks(0);
  12.287 +
  12.288 +	/* Select replay format */
  12.289 +	channels_mode=STEREO16;
  12.290 +	switch (spec->format & 0xff) {
  12.291 +		case 8:
  12.292 +			if (spec->channels==2) {
  12.293 +				channels_mode=STEREO8;
  12.294 +			} else {
  12.295 +				channels_mode=MONO8;
  12.296 +			}
  12.297 +			break;
  12.298 +	}
  12.299 +	if (Setmode(channels_mode)<0) {
  12.300 +		DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n"));
  12.301 +	}
  12.302 +
  12.303 +	switch(cookie_mcsn->play) {
  12.304 +		case MCSN_TT:
  12.305 +			Devconnect(DMAPLAY, DAC, CLK25M, CLKOLD, 1);
  12.306 +			Soundcmd(SETPRESCALE, 3-MINTAUDIO_numfreq);
  12.307 +			DEBUG_PRINT((DEBUG_NAME "STE/TT prescaler selected\n"));
  12.308 +			break;
  12.309 +		case MCSN_FALCON:
  12.310 +			if (cookie_mcsn->res1 != 0) {
  12.311 +				Devconnect(DMAPLAY, DAC, CLKEXT, MINTAUDIO_numfreq, 1);
  12.312 +				DEBUG_PRINT((DEBUG_NAME "External clock selected, prescaler %d\n", MINTAUDIO_numfreq));
  12.313 +			} else {
  12.314 +				Devconnect(DMAPLAY, DAC, CLK25M, MINTAUDIO_numfreq, 1);
  12.315 +				DEBUG_PRINT((DEBUG_NAME "25.175 MHz clock selected, prescaler %d\n", MINTAUDIO_numfreq));
  12.316 +			}
  12.317 +			break;
  12.318 +	}
  12.319 +
  12.320 +	/* Set buffer */
  12.321 +	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
  12.322 +	if (Setbuffer(0, buffer, buffer + spec->size)<0) {
  12.323 +		DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));
  12.324 +	}
  12.325 +	
  12.326 +	/* Install interrupt */
  12.327 +	Jdisint(MFP_DMASOUND);
  12.328 +	Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_XbiosInterrupt);
  12.329 +	Jenabint(MFP_DMASOUND);
  12.330 +
  12.331 +	if (Setinterrupt(SI_TIMERA, SI_PLAY)<0) {
  12.332 +		DEBUG_PRINT((DEBUG_NAME "Setinterrupt() failed\n"));
  12.333 +	}
  12.334 +
  12.335 +	/* Go */
  12.336 +	Buffoper(SB_PLA_ENA|SB_PLA_RPT);
  12.337 +	DEBUG_PRINT((DEBUG_NAME "hardware initialized\n"));
  12.338 +}
  12.339 +
  12.340 +static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec)
  12.341 +{
  12.342 +	/* Lock sound system */
  12.343 +	if (Locksnd()!=1) {
  12.344 +   	    SDL_SetError("Mint_OpenAudio: Audio system already in use");
  12.345 +        return(-1);
  12.346 +	}
  12.347 +
  12.348 +	SDL_MintAudio_device = this;
  12.349 +
  12.350 +	/* Check audio capabilities */
  12.351 +	if (Mint_CheckAudio(this, spec)==-1) {
  12.352 +		return -1;
  12.353 +	}
  12.354 +
  12.355 +	SDL_CalculateAudioSpec(spec);
  12.356 +
  12.357 +	/* Allocate memory for audio buffers in DMA-able RAM */
  12.358 +	spec->size = spec->samples;
  12.359 +	spec->size *= spec->channels;
  12.360 +	spec->size *= (spec->format & 0xFF)/8;
  12.361 +
  12.362 +	DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
  12.363 +
  12.364 +	SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM);
  12.365 +	if (SDL_MintAudio_audiobuf[0]==NULL) {
  12.366 +		SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
  12.367 +		return (-1);
  12.368 +	}
  12.369 +	SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ;
  12.370 +	SDL_MintAudio_numbuf=0;
  12.371 +	memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
  12.372 +	SDL_MintAudio_audiosize = spec->size;
  12.373 +	SDL_MintAudio_mutex = 0;
  12.374 +
  12.375 +	DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0]));
  12.376 +	DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1]));
  12.377 +
  12.378 +	/* Setup audio hardware */
  12.379 +	Mint_InitAudio(this, spec);
  12.380 +
  12.381 +    return(1);	/* We don't use threaded audio */
  12.382 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/audio/mint/SDL_mintaudio_mcsn.h	Mon Jul 07 19:16:03 2003 +0000
    13.3 @@ -0,0 +1,58 @@
    13.4 +/*
    13.5 +    SDL - Simple DirectMedia Layer
    13.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    13.7 +
    13.8 +    This library is free software; you can redistribute it and/or
    13.9 +    modify it under the terms of the GNU Library General Public
   13.10 +    License as published by the Free Software Foundation; either
   13.11 +    version 2 of the License, or (at your option) any later version.
   13.12 +
   13.13 +    This library is distributed in the hope that it will be useful,
   13.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.16 +    Library General Public License for more details.
   13.17 +
   13.18 +    You should have received a copy of the GNU Library General Public
   13.19 +    License along with this library; if not, write to the Free
   13.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.21 +
   13.22 +    Sam Lantinga
   13.23 +    slouken@libsdl.org
   13.24 +*/
   13.25 +
   13.26 +/*
   13.27 +	MCSN control structure
   13.28 +
   13.29 +	Patrice Mandin
   13.30 +*/
   13.31 +
   13.32 +#ifndef _SDL_mintaudio_mcsh_h
   13.33 +#define _SDL_mintaudio_mcsh_h
   13.34 +
   13.35 +typedef struct {
   13.36 +	unsigned short version;	/* Version */
   13.37 +	unsigned short size;	/* Size of structure */
   13.38 +
   13.39 +	unsigned short play;	/* Replay capability */
   13.40 +	unsigned short record;	/* Record capability */
   13.41 +	unsigned short dsp;		/* DSP56K present */
   13.42 +	unsigned short pint;	/* Interrupt at end of replay */
   13.43 +	unsigned short rint;	/* Interrupt at end of record */
   13.44 +
   13.45 +	unsigned long res1;		/* Frequency of external clock */
   13.46 +	unsigned long res2;
   13.47 +	unsigned long res3;
   13.48 +	unsigned long res4;
   13.49 +} cookie_mcsn_t __attribute__((packed));
   13.50 +
   13.51 +enum {
   13.52 +	MCSN_ST=0,
   13.53 +	MCSN_TT,
   13.54 +	MCSN_STE=MCSN_TT,
   13.55 +	MCSN_FALCON,
   13.56 +	MCSN_MAC=MCSN_FALCON
   13.57 +};
   13.58 +
   13.59 +#define SETSMPFREQ	7	/* Set sample frequency */
   13.60 +
   13.61 +#endif /* _SDL_mintaudio_mcsh_h */
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/audio/mint/SDL_mintaudio_stfa.c	Mon Jul 07 19:16:03 2003 +0000
    14.3 @@ -0,0 +1,319 @@
    14.4 +/*
    14.5 +    SDL - Simple DirectMedia Layer
    14.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    14.7 +
    14.8 +    This library is free software; you can redistribute it and/or
    14.9 +    modify it under the terms of the GNU Library General Public
   14.10 +    License as published by the Free Software Foundation; either
   14.11 +    version 2 of the License, or (at your option) any later version.
   14.12 +
   14.13 +    This library is distributed in the hope that it will be useful,
   14.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14.16 +    Library General Public License for more details.
   14.17 +
   14.18 +    You should have received a copy of the GNU Library General Public
   14.19 +    License along with this library; if not, write to the Free
   14.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   14.21 +
   14.22 +    Sam Lantinga
   14.23 +    slouken@libsdl.org
   14.24 +*/
   14.25 +
   14.26 +/*
   14.27 +	MiNT audio driver
   14.28 +	using XBIOS functions (STFA driver)
   14.29 +
   14.30 +	Patrice Mandin
   14.31 +*/
   14.32 +
   14.33 +#include <stdlib.h>
   14.34 +#include <stdio.h>
   14.35 +#include <string.h>
   14.36 +
   14.37 +/* Mint includes */
   14.38 +#include <mint/osbind.h>
   14.39 +#include <mint/falcon.h>
   14.40 +#include <mint/cookie.h>
   14.41 +
   14.42 +#include "SDL_endian.h"
   14.43 +#include "SDL_audio.h"
   14.44 +#include "SDL_audio_c.h"
   14.45 +#include "SDL_audiomem.h"
   14.46 +#include "SDL_sysaudio.h"
   14.47 +
   14.48 +#include "SDL_atarimxalloc_c.h"
   14.49 +
   14.50 +#include "SDL_mintaudio.h"
   14.51 +#include "SDL_mintaudio_stfa.h"
   14.52 +
   14.53 +/*--- Defines ---*/
   14.54 +
   14.55 +#define MINT_AUDIO_DRIVER_NAME "mint_stfa"
   14.56 +
   14.57 +/* Debug print info */
   14.58 +#define DEBUG_NAME "audio:stfa: "
   14.59 +#if 0
   14.60 +#define DEBUG_PRINT(what) \
   14.61 +	{ \
   14.62 +		printf what; \
   14.63 +	}
   14.64 +#else
   14.65 +#define DEBUG_PRINT(what)
   14.66 +#endif
   14.67 +
   14.68 +/*--- Static variables ---*/
   14.69 +
   14.70 +static unsigned long cookie_snd, cookie_mch;
   14.71 +static cookie_stfa_t *cookie_stfa;
   14.72 +
   14.73 +static const int freqs[16]={
   14.74 +	4995,	6269,	7493,	8192,
   14.75 +	9830,	10971,	12538,	14985,
   14.76 +	16384,	19819,	21943,	24576,
   14.77 +	30720,	32336,	43885,	49152
   14.78 +};
   14.79 +
   14.80 +/*--- Audio driver functions ---*/
   14.81 +
   14.82 +static void Mint_CloseAudio(_THIS);
   14.83 +static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec);
   14.84 +static void Mint_LockAudio(_THIS);
   14.85 +static void Mint_UnlockAudio(_THIS);
   14.86 +
   14.87 +/* To check/init hardware audio */
   14.88 +static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec);
   14.89 +static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec);
   14.90 +
   14.91 +/*--- Audio driver bootstrap functions ---*/
   14.92 +
   14.93 +static int Audio_Available(void)
   14.94 +{
   14.95 +	const char *envr = getenv("SDL_AUDIODRIVER");
   14.96 +
   14.97 +	/* Check if user asked a different audio driver */
   14.98 +	if ((envr) && (strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
   14.99 +		DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
  14.100 +		return(0);
  14.101 +	}
  14.102 +
  14.103 +	/* Cookie _MCH present ? if not, assume ST machine */
  14.104 +	if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
  14.105 +		cookie_mch = MCH_ST;
  14.106 +	}
  14.107 +
  14.108 +	/* Cookie _SND present ? if not, assume ST machine */
  14.109 +	if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
  14.110 +		cookie_snd = SND_PSG;
  14.111 +	}
  14.112 +
  14.113 +	/* Cookie STFA present ? */
  14.114 +	if (Getcookie(C_STFA, (long *) &cookie_stfa) != C_FOUND) {
  14.115 +		DEBUG_PRINT((DEBUG_NAME "no STFA audio\n"));
  14.116 +		return(0);
  14.117 +	}
  14.118 +
  14.119 +	SDL_MintAudio_stfa = cookie_stfa;
  14.120 +
  14.121 +	DEBUG_PRINT((DEBUG_NAME "STFA audio available!\n"));
  14.122 +	return(1);
  14.123 +}
  14.124 +
  14.125 +static void Audio_DeleteDevice(SDL_AudioDevice *device)
  14.126 +{
  14.127 +    free(device->hidden);
  14.128 +    free(device);
  14.129 +}
  14.130 +
  14.131 +static SDL_AudioDevice *Audio_CreateDevice(int devindex)
  14.132 +{
  14.133 +	SDL_AudioDevice *this;
  14.134 +
  14.135 +	/* Initialize all variables that we clean on shutdown */
  14.136 +	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
  14.137 +    if ( this ) {
  14.138 +        memset(this, 0, (sizeof *this));
  14.139 +        this->hidden = (struct SDL_PrivateAudioData *)
  14.140 +                malloc((sizeof *this->hidden));
  14.141 +    }
  14.142 +    if ( (this == NULL) || (this->hidden == NULL) ) {
  14.143 +        SDL_OutOfMemory();
  14.144 +        if ( this ) {
  14.145 +            free(this);
  14.146 +        }
  14.147 +        return(0);
  14.148 +    }
  14.149 +    memset(this->hidden, 0, (sizeof *this->hidden));
  14.150 +
  14.151 +    /* Set the function pointers */
  14.152 +    this->OpenAudio   = Mint_OpenAudio;
  14.153 +    this->CloseAudio  = Mint_CloseAudio;
  14.154 +    this->LockAudio   = Mint_LockAudio;
  14.155 +    this->UnlockAudio = Mint_UnlockAudio;
  14.156 +    this->free        = Audio_DeleteDevice;
  14.157 +
  14.158 +    return this;
  14.159 +}
  14.160 +
  14.161 +AudioBootStrap MINTAUDIO_STFA_bootstrap = {
  14.162 +	MINT_AUDIO_DRIVER_NAME, "MiNT STFA audio driver",
  14.163 +	Audio_Available, Audio_CreateDevice
  14.164 +};
  14.165 +
  14.166 +static void Mint_LockAudio(_THIS)
  14.167 +{
  14.168 +	void *oldpile;
  14.169 +
  14.170 +	/* Stop replay */
  14.171 +	oldpile=(void *)Super(0);
  14.172 +	cookie_stfa->sound_enable=STFA_PLAY_DISABLE;
  14.173 +	Super(oldpile);
  14.174 +}
  14.175 +
  14.176 +static void Mint_UnlockAudio(_THIS)
  14.177 +{
  14.178 +	void *oldpile;
  14.179 +
  14.180 +	/* Restart replay */
  14.181 +	oldpile=(void *)Super(0);
  14.182 +	cookie_stfa->sound_enable=STFA_PLAY_ENABLE|STFA_PLAY_REPEAT;
  14.183 +	Super(oldpile);
  14.184 +}
  14.185 +
  14.186 +static void Mint_CloseAudio(_THIS)
  14.187 +{
  14.188 +	void *oldpile;
  14.189 +
  14.190 +	/* Stop replay */
  14.191 +	oldpile=(void *)Super(0);
  14.192 +	cookie_stfa->sound_enable=STFA_PLAY_DISABLE;
  14.193 +	Super(oldpile);
  14.194 +
  14.195 +	/* Wait if currently playing sound */
  14.196 +	while (SDL_MintAudio_mutex != 0) {
  14.197 +	}
  14.198 +
  14.199 +	/* Clear buffers */
  14.200 +	if (SDL_MintAudio_audiobuf[0]) {
  14.201 +		Mfree(SDL_MintAudio_audiobuf[0]);
  14.202 +		SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
  14.203 +	}
  14.204 +}
  14.205 +
  14.206 +static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
  14.207 +{
  14.208 +	int i;
  14.209 +
  14.210 +	DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff));
  14.211 +	DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
  14.212 +	DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x8000)!=0)));
  14.213 +	DEBUG_PRINT(("channels=%d, ", spec->channels));
  14.214 +	DEBUG_PRINT(("freq=%d\n", spec->freq));
  14.215 +
  14.216 +	/* Check formats available */
  14.217 +	MINTAUDIO_nfreq=16;
  14.218 +	MINTAUDIO_sfreq=0;
  14.219 +	for (i=MINTAUDIO_sfreq;i<MINTAUDIO_nfreq;i++) {
  14.220 +		MINTAUDIO_hardfreq[i]=freqs[15-i];
  14.221 +		DEBUG_PRINT((DEBUG_NAME "calc:freq(%d)=%lu\n", i, MINTAUDIO_hardfreq[i]));
  14.222 +	}
  14.223 +
  14.224 +	MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, 0, spec->freq);
  14.225 +	spec->freq=MINTAUDIO_hardfreq[MINTAUDIO_numfreq];
  14.226 +
  14.227 +	DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff));
  14.228 +	DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
  14.229 +	DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x8000)!=0)));
  14.230 +	DEBUG_PRINT(("channels=%d, ", spec->channels));
  14.231 +	DEBUG_PRINT(("freq=%d\n", spec->freq));
  14.232 +
  14.233 +	return 0;
  14.234 +}
  14.235 +
  14.236 +static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec)
  14.237 +{
  14.238 +	void *buffer;
  14.239 +	void *oldpile;
  14.240 +
  14.241 +	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
  14.242 +
  14.243 +	oldpile=(void *)Super(0);
  14.244 +
  14.245 +	/* Stop replay */
  14.246 +	cookie_stfa->sound_enable=STFA_PLAY_DISABLE;
  14.247 +
  14.248 +	/* Select replay format */
  14.249 +	cookie_stfa->sound_control = 15-MINTAUDIO_numfreq;
  14.250 +	if ((spec->format & 0xff)==8) {
  14.251 +		cookie_stfa->sound_control |= STFA_FORMAT_8BIT;
  14.252 +	} else {
  14.253 +		cookie_stfa->sound_control |= STFA_FORMAT_16BIT;
  14.254 +	}
  14.255 +	if (spec->channels==2) {
  14.256 +		cookie_stfa->sound_control |= STFA_FORMAT_STEREO;
  14.257 +	} else {
  14.258 +		cookie_stfa->sound_control |= STFA_FORMAT_MONO;
  14.259 +	}
  14.260 +	if (spec->format & 0x8000) {
  14.261 +		cookie_stfa->sound_control |= STFA_FORMAT_SIGNED;
  14.262 +	} else {
  14.263 +		cookie_stfa->sound_control |= STFA_FORMAT_UNSIGNED;
  14.264 +	}
  14.265 +	if (spec->format & 0x1000) {
  14.266 +		cookie_stfa->sound_control |= STFA_FORMAT_LITENDIAN;
  14.267 +	} else {
  14.268 +		cookie_stfa->sound_control |= STFA_FORMAT_BIGENDIAN;
  14.269 +	}
  14.270 +
  14.271 +	/* Set buffer */
  14.272 +	cookie_stfa->sound_start = (unsigned long) buffer;
  14.273 +	cookie_stfa->sound_end = (unsigned long) (buffer + spec->size);
  14.274 +
  14.275 +	/* Set interrupt */
  14.276 +	cookie_stfa->stfa_it = SDL_MintAudio_StfaInterrupt;
  14.277 +
  14.278 +	/* Restart replay */
  14.279 +	cookie_stfa->sound_enable=STFA_PLAY_ENABLE|STFA_PLAY_REPEAT;
  14.280 +
  14.281 +	Super(oldpile);
  14.282 +
  14.283 +	DEBUG_PRINT((DEBUG_NAME "hardware initialized\n"));
  14.284 +}
  14.285 +
  14.286 +static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec)
  14.287 +{
  14.288 +	SDL_MintAudio_device = this;
  14.289 +
  14.290 +	/* Check audio capabilities */
  14.291 +	if (Mint_CheckAudio(this, spec)==-1) {
  14.292 +		return -1;
  14.293 +	}
  14.294 +
  14.295 +	SDL_CalculateAudioSpec(spec);
  14.296 +
  14.297 +	/* Allocate memory for audio buffers in DMA-able RAM */
  14.298 +	spec->size = spec->samples;
  14.299 +	spec->size *= spec->channels;
  14.300 +	spec->size *= (spec->format & 0xFF)/8;
  14.301 +
  14.302 +	DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
  14.303 +
  14.304 +	SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM);
  14.305 +	if (SDL_MintAudio_audiobuf[0]==NULL) {
  14.306 +		SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
  14.307 +		return (-1);
  14.308 +	}
  14.309 +	SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ;
  14.310 +	SDL_MintAudio_numbuf=0;
  14.311 +	memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
  14.312 +	SDL_MintAudio_audiosize = spec->size;
  14.313 +	SDL_MintAudio_mutex = 0;
  14.314 +
  14.315 +	DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0]));
  14.316 +	DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1]));
  14.317 +
  14.318 +	/* Setup audio hardware */
  14.319 +	Mint_InitAudio(this, spec);
  14.320 +
  14.321 +    return(1);	/* We don't use threaded audio */
  14.322 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/audio/mint/SDL_mintaudio_stfa.h	Mon Jul 07 19:16:03 2003 +0000
    15.3 @@ -0,0 +1,99 @@
    15.4 +/*
    15.5 +    SDL - Simple DirectMedia Layer
    15.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    15.7 +
    15.8 +    This library is free software; you can redistribute it and/or
    15.9 +    modify it under the terms of the GNU Library General Public
   15.10 +    License as published by the Free Software Foundation; either
   15.11 +    version 2 of the License, or (at your option) any later version.
   15.12 +
   15.13 +    This library is distributed in the hope that it will be useful,
   15.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15.16 +    Library General Public License for more details.
   15.17 +
   15.18 +    You should have received a copy of the GNU Library General Public
   15.19 +    License along with this library; if not, write to the Free
   15.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   15.21 +
   15.22 +    Sam Lantinga
   15.23 +    slouken@libsdl.org
   15.24 +*/
   15.25 +
   15.26 +/*
   15.27 +	STFA control structure
   15.28 +
   15.29 +	Patrice Mandin
   15.30 +*/
   15.31 +
   15.32 +#ifndef _SDL_mintaudio_stfa_h
   15.33 +#define _SDL_mintaudio_stfa_h
   15.34 +
   15.35 +/*--- Defines ---*/
   15.36 +
   15.37 +#define C_STFA	0x53544641L	/* Sound treiber für atari (seb/The removers) */
   15.38 +
   15.39 +#define STFA_PLAY_ENABLE	(1<<0)
   15.40 +#define STFA_PLAY_DISABLE	(0<<0)
   15.41 +#define STFA_PLAY_REPEAT	(1<<1)
   15.42 +#define STFA_PLAY_SINGLE	(0<<1)
   15.43 +
   15.44 +#define STFA_FORMAT_SIGNED		(1<<15)
   15.45 +#define STFA_FORMAT_UNSIGNED	(0<<15)
   15.46 +#define STFA_FORMAT_STEREO		(1<<14)
   15.47 +#define STFA_FORMAT_MONO		(0<<14)
   15.48 +#define STFA_FORMAT_16BIT		(1<<13)
   15.49 +#define STFA_FORMAT_8BIT		(0<<13)
   15.50 +#define STFA_FORMAT_LITENDIAN	(1<<9)
   15.51 +#define STFA_FORMAT_BIGENDIAN	(0<<9)
   15.52 +#define STFA_FORMAT_FREQ_MASK	0x0f
   15.53 +enum {
   15.54 +	STFA_FORMAT_F4995=0,
   15.55 +	STFA_FORMAT_F6269,
   15.56 +	STFA_FORMAT_F7493,
   15.57 +	STFA_FORMAT_F8192,
   15.58 +
   15.59 +	STFA_FORMAT_F9830,
   15.60 +	STFA_FORMAT_F10971,
   15.61 +	STFA_FORMAT_F12538,
   15.62 +	STFA_FORMAT_F14985,
   15.63 +
   15.64 +	STFA_FORMAT_F16384,
   15.65 +	STFA_FORMAT_F19819,
   15.66 +	STFA_FORMAT_F21943,
   15.67 +	STFA_FORMAT_F24576,
   15.68 +
   15.69 +	STFA_FORMAT_F30720,
   15.70 +	STFA_FORMAT_F32336,
   15.71 +	STFA_FORMAT_F43885,
   15.72 +	STFA_FORMAT_F49152
   15.73 +};
   15.74 +
   15.75 +/*--- Types ---*/
   15.76 +
   15.77 +typedef struct {
   15.78 +	unsigned short sound_enable;
   15.79 +	unsigned short sound_control;
   15.80 +	unsigned short sound_output;
   15.81 +	unsigned long sound_start;
   15.82 +	unsigned long sound_current;
   15.83 +	unsigned long sound_end;
   15.84 +	unsigned short version;
   15.85 +	void *old_vbl;
   15.86 +	void *old_timera;
   15.87 +	unsigned long old_mfp_status;
   15.88 +	void *new_vbl;
   15.89 +	void *drivers_list;
   15.90 +	void *play_stop;
   15.91 +	unsigned short frequency;
   15.92 +	void *set_frequency;
   15.93 +	
   15.94 +	unsigned short frequency_threshold;
   15.95 +	unsigned short *custom_freq_table;
   15.96 +	unsigned short stfa_on_off;
   15.97 +	void *new_drivers_list;
   15.98 +	unsigned long old_bit_2_of_cookie_snd;
   15.99 +	void (*stfa_it)(void);
  15.100 +} cookie_stfa_t __attribute__((packed));
  15.101 +
  15.102 +#endif /* _SDL_mintaudio_stfa_h */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/audio/mint/SDL_mintaudio_xbios.c	Mon Jul 07 19:16:03 2003 +0000
    16.3 @@ -0,0 +1,319 @@
    16.4 +/*
    16.5 +    SDL - Simple DirectMedia Layer
    16.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    16.7 +
    16.8 +    This library is free software; you can redistribute it and/or
    16.9 +    modify it under the terms of the GNU Library General Public
   16.10 +    License as published by the Free Software Foundation; either
   16.11 +    version 2 of the License, or (at your option) any later version.
   16.12 +
   16.13 +    This library is distributed in the hope that it will be useful,
   16.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   16.16 +    Library General Public License for more details.
   16.17 +
   16.18 +    You should have received a copy of the GNU Library General Public
   16.19 +    License along with this library; if not, write to the Free
   16.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   16.21 +
   16.22 +    Sam Lantinga
   16.23 +    slouken@libsdl.org
   16.24 +*/
   16.25 +
   16.26 +/*
   16.27 +	MiNT audio driver
   16.28 +	using XBIOS functions (Falcon)
   16.29 +
   16.30 +	Patrice Mandin
   16.31 +*/
   16.32 +
   16.33 +#include <stdlib.h>
   16.34 +#include <stdio.h>
   16.35 +#include <string.h>
   16.36 +
   16.37 +/* Mint includes */
   16.38 +#include <mint/osbind.h>
   16.39 +#include <mint/falcon.h>
   16.40 +#include <mint/cookie.h>
   16.41 +
   16.42 +#include "SDL_endian.h"
   16.43 +#include "SDL_audio.h"
   16.44 +#include "SDL_audio_c.h"
   16.45 +#include "SDL_audiomem.h"
   16.46 +#include "SDL_sysaudio.h"
   16.47 +
   16.48 +#include "SDL_atarimxalloc_c.h"
   16.49 +
   16.50 +#include "SDL_mintaudio.h"
   16.51 +
   16.52 +/*--- Defines ---*/
   16.53 +
   16.54 +#define MINT_AUDIO_DRIVER_NAME "mint_xbios"
   16.55 +
   16.56 +/* Debug print info */
   16.57 +#define DEBUG_NAME "audio:xbios: "
   16.58 +#if 0
   16.59 +#define DEBUG_PRINT(what) \
   16.60 +	{ \
   16.61 +		printf what; \
   16.62 +	}
   16.63 +#else
   16.64 +#define DEBUG_PRINT(what)
   16.65 +#endif
   16.66 +
   16.67 +/*--- Static variables ---*/
   16.68 +
   16.69 +static unsigned long cookie_snd;
   16.70 +
   16.71 +/*--- Audio driver functions ---*/
   16.72 +
   16.73 +static void Mint_CloseAudio(_THIS);
   16.74 +static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec);
   16.75 +static void Mint_LockAudio(_THIS);
   16.76 +static void Mint_UnlockAudio(_THIS);
   16.77 +
   16.78 +/* To check/init hardware audio */
   16.79 +static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec);
   16.80 +static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec);
   16.81 +
   16.82 +/*--- Audio driver bootstrap functions ---*/
   16.83 +
   16.84 +static int Audio_Available(void)
   16.85 +{
   16.86 +	const char *envr = getenv("SDL_AUDIODRIVER");
   16.87 +
   16.88 +	/* Check if user asked a different audio driver */
   16.89 +	if ((envr) && (strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
   16.90 +		DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
   16.91 +		return(0);
   16.92 +	}
   16.93 +
   16.94 +	/* Cookie _SND present ? if not, assume ST machine */
   16.95 +	if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
   16.96 +		cookie_snd = SND_PSG;
   16.97 +	}
   16.98 +
   16.99 +	/* Check if we have 16 bits audio */
  16.100 +	if ((cookie_snd & SND_16BIT)==0) {
  16.101 +		DEBUG_PRINT((DEBUG_NAME "no 16 bits sound\n"));
  16.102 +	    return(0);
  16.103 +	}
  16.104 +
  16.105 +	/* Check if audio is lockable */
  16.106 +	if (Locksnd()!=1) {
  16.107 +		DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n"));
  16.108 +		return(0);
  16.109 +	}
  16.110 +
  16.111 +	Unlocksnd();
  16.112 +
  16.113 +	DEBUG_PRINT((DEBUG_NAME "XBIOS audio available!\n"));
  16.114 +	return(1);
  16.115 +}
  16.116 +
  16.117 +static void Audio_DeleteDevice(SDL_AudioDevice *device)
  16.118 +{
  16.119 +    free(device->hidden);
  16.120 +    free(device);
  16.121 +}
  16.122 +
  16.123 +static SDL_AudioDevice *Audio_CreateDevice(int devindex)
  16.124 +{
  16.125 +	SDL_AudioDevice *this;
  16.126 +
  16.127 +	/* Initialize all variables that we clean on shutdown */
  16.128 +	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
  16.129 +    if ( this ) {
  16.130 +        memset(this, 0, (sizeof *this));
  16.131 +        this->hidden = (struct SDL_PrivateAudioData *)
  16.132 +                malloc((sizeof *this->hidden));
  16.133 +    }
  16.134 +    if ( (this == NULL) || (this->hidden == NULL) ) {
  16.135 +        SDL_OutOfMemory();
  16.136 +        if ( this ) {
  16.137 +            free(this);
  16.138 +        }
  16.139 +        return(0);
  16.140 +    }
  16.141 +    memset(this->hidden, 0, (sizeof *this->hidden));
  16.142 +
  16.143 +    /* Set the function pointers */
  16.144 +    this->OpenAudio   = Mint_OpenAudio;
  16.145 +    this->CloseAudio  = Mint_CloseAudio;
  16.146 +    this->LockAudio   = Mint_LockAudio;
  16.147 +    this->UnlockAudio = Mint_UnlockAudio;
  16.148 +    this->free        = Audio_DeleteDevice;
  16.149 +
  16.150 +    return this;
  16.151 +}
  16.152 +
  16.153 +AudioBootStrap MINTAUDIO_XBIOS_bootstrap = {
  16.154 +	MINT_AUDIO_DRIVER_NAME, "MiNT XBIOS audio driver",
  16.155 +	Audio_Available, Audio_CreateDevice
  16.156 +};
  16.157 +
  16.158 +static void Mint_LockAudio(_THIS)
  16.159 +{
  16.160 +	/* Stop replay */
  16.161 +	Buffoper(0);
  16.162 +}
  16.163 +
  16.164 +static void Mint_UnlockAudio(_THIS)
  16.165 +{
  16.166 +	/* Restart replay */
  16.167 +	Buffoper(SB_PLA_ENA|SB_PLA_RPT);
  16.168 +}
  16.169 +
  16.170 +static void Mint_CloseAudio(_THIS)
  16.171 +{
  16.172 +	/* Stop replay */
  16.173 +	Buffoper(0);
  16.174 +
  16.175 +	/* Uninstall interrupt */
  16.176 +	Jdisint(MFP_DMASOUND);
  16.177 +
  16.178 +	/* Wait if currently playing sound */
  16.179 +	while (SDL_MintAudio_mutex != 0) {
  16.180 +	}
  16.181 +
  16.182 +	/* Clear buffers */
  16.183 +	if (SDL_MintAudio_audiobuf[0]) {
  16.184 +		Mfree(SDL_MintAudio_audiobuf[0]);
  16.185 +		SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
  16.186 +	}
  16.187 +
  16.188 +	/* Unlock sound system */
  16.189 +	Unlocksnd();
  16.190 +}
  16.191 +
  16.192 +static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
  16.193 +{
  16.194 +	int i;
  16.195 +
  16.196 +	DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff));
  16.197 +	DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
  16.198 +	DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x8000)!=0)));
  16.199 +	DEBUG_PRINT(("channels=%d, ", spec->channels));
  16.200 +	DEBUG_PRINT(("freq=%d\n", spec->freq));
  16.201 +
  16.202 +	spec->format |= 0x8000;	/* Audio is always signed */
  16.203 +	if ((spec->format & 0x00ff)==16) {
  16.204 +		spec->format |= 0x1000;	/* Audio is always big endian */
  16.205 +		spec->channels=2;	/* 16 bits always stereo */
  16.206 +	}
  16.207 +
  16.208 +	/* FIXME: check for an external clock */
  16.209 +	MINTAUDIO_sfreq=1;
  16.210 +	MINTAUDIO_nfreq=12;
  16.211 +	for (i=MINTAUDIO_sfreq;i<MINTAUDIO_nfreq;i++) {
  16.212 +		MINTAUDIO_hardfreq[i]=MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1));
  16.213 +		DEBUG_PRINT((DEBUG_NAME "calc:freq(%d)=%lu\n", i, MINTAUDIO_hardfreq[i]));
  16.214 +	}
  16.215 +
  16.216 +	MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, 1, spec->freq);
  16.217 +	spec->freq=MINTAUDIO_hardfreq[MINTAUDIO_numfreq];
  16.218 +
  16.219 +	DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff));
  16.220 +	DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
  16.221 +	DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x8000)!=0)));
  16.222 +	DEBUG_PRINT(("channels=%d, ", spec->channels));
  16.223 +	DEBUG_PRINT(("freq=%d\n", spec->freq));
  16.224 +
  16.225 +	return 0;
  16.226 +}
  16.227 +
  16.228 +static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec)
  16.229 +{
  16.230 +	int channels_mode;
  16.231 +	void *buffer;
  16.232 +
  16.233 +	/* Stop currently playing sound */
  16.234 +	Buffoper(0);
  16.235 +
  16.236 +	/* Set replay tracks */
  16.237 +	Settracks(0,0);
  16.238 +	Setmontracks(0);
  16.239 +
  16.240 +	/* Select replay format */
  16.241 +	channels_mode=STEREO16;
  16.242 +	switch (spec->format & 0xff) {
  16.243 +		case 8:
  16.244 +			if (spec->channels==2) {
  16.245 +				channels_mode=STEREO8;
  16.246 +			} else {
  16.247 +				channels_mode=MONO8;
  16.248 +			}
  16.249 +			break;
  16.250 +	}
  16.251 +	if (Setmode(channels_mode)<0) {
  16.252 +		DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n"));
  16.253 +	}
  16.254 +
  16.255 +	/* FIXME: select an external clock */
  16.256 +
  16.257 +	Devconnect(DMAPLAY, DAC, CLK25M, MINTAUDIO_numfreq, 1);
  16.258 +	DEBUG_PRINT((DEBUG_NAME "25.175 MHz clock selected, prescaler %d\n", MINTAUDIO_numfreq));
  16.259 +
  16.260 +	/* Set buffer */
  16.261 +	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
  16.262 +	if (Setbuffer(0, buffer, buffer + spec->size)<0) {
  16.263 +		DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));
  16.264 +	}
  16.265 +	
  16.266 +	/* Install interrupt */
  16.267 +	Jdisint(MFP_DMASOUND);
  16.268 +	Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_XbiosInterrupt);
  16.269 +	Jenabint(MFP_DMASOUND);
  16.270 +
  16.271 +	if (Setinterrupt(SI_TIMERA, SI_PLAY)<0) {
  16.272 +		DEBUG_PRINT((DEBUG_NAME "Setinterrupt() failed\n"));
  16.273 +	}
  16.274 +
  16.275 +	/* Go */
  16.276 +	Buffoper(SB_PLA_ENA|SB_PLA_RPT);
  16.277 +	DEBUG_PRINT((DEBUG_NAME "hardware initialized\n"));
  16.278 +}
  16.279 +
  16.280 +static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec)
  16.281 +{
  16.282 +	/* Lock sound system */
  16.283 +	if (Locksnd()!=1) {
  16.284 +   	    SDL_SetError("Mint_OpenAudio: Audio system already in use");
  16.285 +        return(-1);
  16.286 +	}
  16.287 +
  16.288 +	SDL_MintAudio_device = this;
  16.289 +
  16.290 +	/* Check audio capabilities */
  16.291 +	if (Mint_CheckAudio(this, spec)==-1) {
  16.292 +		return -1;
  16.293 +	}
  16.294 +
  16.295 +	SDL_CalculateAudioSpec(spec);
  16.296 +
  16.297 +	/* Allocate memory for audio buffers in DMA-able RAM */
  16.298 +	spec->size = spec->samples;
  16.299 +	spec->size *= spec->channels;
  16.300 +	spec->size *= (spec->format & 0xFF)/8;
  16.301 +
  16.302 +	DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
  16.303 +
  16.304 +	SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM);
  16.305 +	if (SDL_MintAudio_audiobuf[0]==NULL) {
  16.306 +		SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
  16.307 +		return (-1);
  16.308 +	}
  16.309 +	SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ;
  16.310 +	SDL_MintAudio_numbuf=0;
  16.311 +	memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
  16.312 +	SDL_MintAudio_audiosize = spec->size;
  16.313 +	SDL_MintAudio_mutex = 0;
  16.314 +
  16.315 +	DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0]));
  16.316 +	DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1]));
  16.317 +
  16.318 +	/* Setup audio hardware */
  16.319 +	Mint_InitAudio(this, spec);
  16.320 +
  16.321 +    return(1);	/* We don't use threaded audio */
  16.322 +}