Added initial support for Dreamcast (thanks HERO!)
authorSam Lantinga <slouken@libsdl.org>
Sat, 05 Oct 2002 16:50:56 +0000
changeset 509dad72daf44b3
parent 508 9ff7e90aaa94
child 510 875fbe29588d
Added initial support for Dreamcast (thanks HERO!)
Makefile.am
Makefile.dc
README.DC
docs.html
src/audio/Makefile.am
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
src/audio/dc/.cvsignore
src/audio/dc/Makefile.am
src/audio/dc/SDL_dcaudio.c
src/audio/dc/SDL_dcaudio.h
src/audio/dc/aica.c
src/audio/dc/aica.h
src/cdrom/Makefile.am
src/cdrom/dc/.cvsignore
src/cdrom/dc/Makefile.am
src/cdrom/dc/SDL_syscdrom.c
src/joystick/Makefile.am
src/joystick/dc/.cvsignore
src/joystick/dc/Makefile.am
src/joystick/dc/SDL_sysjoystick.c
src/thread/Makefile.am
src/thread/dc/SDL_syscond.c
src/thread/dc/SDL_syscond_c.h
src/thread/dc/SDL_sysmutex.c
src/thread/dc/SDL_sysmutex_c.h
src/thread/dc/SDL_syssem.c
src/thread/dc/SDL_syssem_c.h
src/thread/dc/SDL_systhread.c
src/thread/dc/SDL_systhread_c.h
src/timer/Makefile.am
src/timer/dc/SDL_systimer.c
src/video/Makefile.am
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/dc/.cvsignore
src/video/dc/Makefile.am
src/video/dc/SDL_dcevents.c
src/video/dc/SDL_dcevents_c.h
src/video/dc/SDL_dcmouse.c
src/video/dc/SDL_dcmouse_c.h
src/video/dc/SDL_dcvideo.c
src/video/dc/SDL_dcvideo.h
     1.1 --- a/Makefile.am	Sat Oct 05 16:27:56 2002 +0000
     1.2 +++ b/Makefile.am	Sat Oct 05 16:50:56 2002 +0000
     1.3 @@ -25,6 +25,7 @@
     1.4  	README		\
     1.5  	README.AmigaOS	\
     1.6  	README.CVS	\
     1.7 +	README.DC	\
     1.8  	README.Epoc	\
     1.9  	README.MacOS	\
    1.10  	README.MacOSX	\
    1.11 @@ -40,6 +41,7 @@
    1.12  	VisualC.html	\
    1.13  	VisualC.zip	\
    1.14  	VisualCE.zip	\
    1.15 +	Makefile.dc	\
    1.16  	MPWmake.sea.bin	\
    1.17  	CWprojects.sea.bin \
    1.18  	PBProjects.tar.gz \
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile.dc	Sat Oct 05 16:50:56 2002 +0000
     2.3 @@ -0,0 +1,105 @@
     2.4 +#GL=1
     2.5 +
     2.6 +CC = sh-elf-gcc -ml -m4-single-only
     2.7 +AR = sh-elf-ar
     2.8 +KOS_BASE=/prog/kos-1.1.7
     2.9 +INCS = -I$(KOS_BASE)/libc/include -I$(KOS_BASE)/include -I$(KOS_BASE)/kernel/arch/dreamcast/include
    2.10 +DEFS =-DNO_SIGNAL_H -DENABLE_DC
    2.11 +
    2.12 +ifdef GL
    2.13 +DEFS += -DHAVE_OPENGL
    2.14 +TARGET = libSDL_gl.a
    2.15 +else
    2.16 +TARGET = libSDL.a
    2.17 +endif
    2.18 +
    2.19 +OPTFLAGS=-O2 -fomit-frame-pointer
    2.20 +CFLAGS=-D_arch_dreamcast $(DEFS) $(INCS) -Iinclude -Isrc -Isrc/audio -Isrc/cdrom -Isrc/endian -Isrc/events -Isrc/joystick -Isrc/thread/dc -Isrc/thread -Isrc/timer -Isrc/video $(OPTFLAGS)
    2.21 +
    2.22 +SRCS = \
    2.23 +	src/audio/dc/SDL_dcaudio.c \
    2.24 +	src/audio/dc/aica.c \
    2.25 +	src/audio/SDL_audio.c \
    2.26 +	src/audio/SDL_audiocvt.c \
    2.27 +	src/audio/SDL_audiodev.c \
    2.28 +	src/audio/SDL_audiomem.c \
    2.29 +	src/audio/SDL_mixer.c \
    2.30 +	src/audio/SDL_wave.c \
    2.31 +	src/cdrom/dc/SDL_syscdrom.c \
    2.32 +	src/cdrom/SDL_cdrom.c \
    2.33 +	src/endian/SDL_endian.c \
    2.34 +	src/events/SDL_active.c \
    2.35 +	src/events/SDL_events.c \
    2.36 +	src/events/SDL_expose.c \
    2.37 +	src/events/SDL_keyboard.c \
    2.38 +	src/events/SDL_mouse.c \
    2.39 +	src/events/SDL_quit.c \
    2.40 +	src/events/SDL_resize.c \
    2.41 +	src/file/SDL_rwops.c \
    2.42 +	src/joystick/dc/SDL_sysjoystick.c \
    2.43 +	src/joystick/SDL_joystick.c \
    2.44 +	src/SDL.c \
    2.45 +	src/SDL_error.c \
    2.46 +	src/SDL_fatal.c \
    2.47 +	src/SDL_getenv.c \
    2.48 +	src/SDL_loadso.c \
    2.49 +	src/thread/dc/SDL_syscond.c \
    2.50 +	src/thread/dc/SDL_sysmutex.c \
    2.51 +	src/thread/dc/SDL_syssem.c \
    2.52 +	src/thread/dc/SDL_systhread.c \
    2.53 +	src/thread/SDL_thread.c \
    2.54 +	src/timer/dc/SDL_systimer.c \
    2.55 +	src/timer/SDL_timer.c \
    2.56 +	src/video/dc/SDL_dcevents.c \
    2.57 +	src/video/dc/SDL_dcvideo.c \
    2.58 +	src/video/SDL_blit.c \
    2.59 +	src/video/SDL_blit_0.c \
    2.60 +	src/video/SDL_blit_1.c \
    2.61 +	src/video/SDL_blit_A.c \
    2.62 +	src/video/SDL_blit_N.c \
    2.63 +	src/video/SDL_bmp.c \
    2.64 +	src/video/SDL_cursor.c \
    2.65 +	src/video/SDL_gamma.c \
    2.66 +	src/video/SDL_pixels.c \
    2.67 +	src/video/SDL_RLEaccel.c \
    2.68 +	src/video/SDL_stretch.c \
    2.69 +	src/video/SDL_surface.c \
    2.70 +	src/video/SDL_video.c \
    2.71 +	src/video/SDL_yuv.c \
    2.72 +	src/video/SDL_yuv_sw.c \
    2.73 +
    2.74 +OBJS = $(SRCS:.c=.o)
    2.75 +
    2.76 +TEST = \
    2.77 +	test/checkkeys.c \
    2.78 +	test/graywin.c \
    2.79 +	test/loopwave.c \
    2.80 +	test/testalpha.c \
    2.81 +	test/testbitmap.c \
    2.82 +	test/testcdrom.c \
    2.83 +	test/testerror.c \
    2.84 +	test/testgamma.c \
    2.85 +	test/testgl.c \
    2.86 +	test/testhread.c \
    2.87 +	test/testjoystick.c \
    2.88 +	test/testkeys.c \
    2.89 +	test/testlock.c \
    2.90 +	test/testoverlay.c \
    2.91 +	test/testpalette.c \
    2.92 +	test/testsem.c \
    2.93 +	test/testsprite.c \
    2.94 +	test/testtimer.c \
    2.95 +	test/testtypes.c \
    2.96 +	test/testver.c \
    2.97 +	test/testvidinfo.c \
    2.98 +	test/testwin.c \
    2.99 +	test/testwm.c \
   2.100 +	test/threadwin.c \
   2.101 +	test/torturethread.c \
   2.102 +
   2.103 +clean:
   2.104 +	rm $(OBJS)
   2.105 +
   2.106 +$(TARGET) : $(OBJS)
   2.107 +	$(AR) rcs $(TARGET) $(OBJS)
   2.108 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/README.DC	Sat Oct 05 16:50:56 2002 +0000
     3.3 @@ -0,0 +1,37 @@
     3.4 +SDL for Dreamcast (beta2)
     3.5 +
     3.6 +	BERO
     3.7 +	bero@geocities.co.jp
     3.8 +
     3.9 +	http://www.geocities.co.jp/Playtown/2004/
    3.10 +
    3.11 +this work with kos-newlib
    3.12 +http://sourceforge.net/projects/dcquake/
    3.13 +
    3.14 +compile
    3.15 +- edit KOS_BASE in Makefie.dc for your enviroment
    3.16 +- make -f Makefile.dc
    3.17 +
    3.18 +FIXME: The KOS thread files can be found on HERO's site - not in the SDL source.
    3.19 +- overwrite thread/*.c to kos-1.1.7/kernel/thread
    3.20 +- rebuild kos
    3.21 +
    3.22 +compile with gl support
    3.23 +- install latest libgl from http://sourceforge.net/projects/dcquake/
    3.24 +- uncomment GL=1 in Makefile.dc
    3.25 +- make -f Makefile.dc clean
    3.26 +- make -f Makefile.dc
    3.27 +
    3.28 +install
    3.29 +- copy include/*.h and libSDL.a or libSDL_gl.a for your enviroment
    3.30 +
    3.31 +changelog:
    3.32 +
    3.33 +beta2
    3.34 +- OpenGL support
    3.35 +- Hardware page flip support
    3.36 +
    3.37 +beta
    3.38 +- thread, timer don't tested so much.
    3.39 +- not support OpenGL
    3.40 +
     4.1 --- a/docs.html	Sat Oct 05 16:27:56 2002 +0000
     4.2 +++ b/docs.html	Sat Oct 05 16:50:56 2002 +0000
     4.3 @@ -16,6 +16,7 @@
     4.4  Major changes since SDL 1.0.0:
     4.5  </H2>
     4.6  <UL>
     4.7 +	<LI> 1.2.5: Added initial support for Dreamcast (thanks HERO!)
     4.8  	<LI> 1.2.5: Updated Borland projects for Kylix 3 (thanks Dominique)
     4.9  	<LI> 1.2.5: Added project files for embedded Visual C++ 4.0
    4.10  	<LI> 1.2.5: Added SDL_BUTTON_WHEELUP (4) and SDL_BUTTON_WHEELDOWN (5)
     5.1 --- a/src/audio/Makefile.am	Sat Oct 05 16:27:56 2002 +0000
     5.2 +++ b/src/audio/Makefile.am	Sat Oct 05 16:50:56 2002 +0000
     5.3 @@ -6,7 +6,7 @@
     5.4  # Define which subdirectories need to be built
     5.5  SUBDIRS = @AUDIO_SUBDIRS@
     5.6  DIST_SUBDIRS = alsa arts baudio dma dmedia dsp esd macrom nas nto openbsd \
     5.7 -	paudio sun ums windib windx5 disk mint
     5.8 +	paudio sun ums windib windx5 disk mint dc
     5.9  
    5.10  DRIVERS = @AUDIO_DRIVERS@
    5.11  
     6.1 --- a/src/audio/SDL_audio.c	Sat Oct 05 16:27:56 2002 +0000
     6.2 +++ b/src/audio/SDL_audio.c	Sat Oct 05 16:50:56 2002 +0000
     6.3 @@ -89,6 +89,9 @@
     6.4  #ifdef DISKAUD_SUPPORT
     6.5  	&DISKAUD_bootstrap,
     6.6  #endif
     6.7 +#ifdef ENABLE_DC
     6.8 +	&DCAUD_bootstrap,
     6.9 +#endif
    6.10  	NULL
    6.11  };
    6.12  SDL_AudioDevice *current_audio = NULL;
     7.1 --- a/src/audio/SDL_sysaudio.h	Sat Oct 05 16:27:56 2002 +0000
     7.2 +++ b/src/audio/SDL_sysaudio.h	Sat Oct 05 16:50:56 2002 +0000
     7.3 @@ -153,6 +153,9 @@
     7.4  #ifdef DISKAUD_SUPPORT
     7.5  extern AudioBootStrap DISKAUD_bootstrap;
     7.6  #endif
     7.7 +#ifdef ENABLE_DC
     7.8 +extern AudioBootStrap DCAUD_bootstrap;
     7.9 +#endif
    7.10  
    7.11  /* This is the current audio device */
    7.12  extern SDL_AudioDevice *current_audio;
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/audio/dc/.cvsignore	Sat Oct 05 16:50:56 2002 +0000
     8.3 @@ -0,0 +1,6 @@
     8.4 +Makefile.in
     8.5 +Makefile
     8.6 +.libs
     8.7 +*.o
     8.8 +*.lo
     8.9 +*.la
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/audio/dc/Makefile.am	Sat Oct 05 16:50:56 2002 +0000
     9.3 @@ -0,0 +1,11 @@
     9.4 +
     9.5 +## Makefile.am for SDL on the Dreamcast console
     9.6 +
     9.7 +noinst_LTLIBRARIES = libaudio_dc.la
     9.8 +libaudio_dc_la_SOURCES = $(SRCS)
     9.9 +
    9.10 +# The SDL audio driver sources
    9.11 +SRCS =	SDL_dcaudio.c	\
    9.12 +	SDL_dcaudio.h	\
    9.13 +	aica.c		\
    9.14 +	aica.h
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/audio/dc/SDL_dcaudio.c	Sat Oct 05 16:50:56 2002 +0000
    10.3 @@ -0,0 +1,245 @@
    10.4 +/*
    10.5 +    SDL - Simple DirectMedia Layer
    10.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    10.7 +
    10.8 +    This library is free software; you can redistribute it and/or
    10.9 +    modify it under the terms of the GNU Library General Public
   10.10 +    License as published by the Free Software Foundation; either
   10.11 +    version 2 of the License, or (at your option) any later version.
   10.12 +
   10.13 +    This library is distributed in the hope that it will be useful,
   10.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10.16 +    Library General Public License for more details.
   10.17 +
   10.18 +    You should have received a copy of the GNU Library General Public
   10.19 +    License along with this library; if not, write to the Free
   10.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   10.21 +
   10.22 +    BERO <bero@geocities.co.jp>
   10.23 +    based on SDL_diskaudio.c by Sam Lantinga <slouken@libsdl.org>
   10.24 +
   10.25 +*/
   10.26 +
   10.27 +#ifdef SAVE_RCSID
   10.28 +static char rcsid =
   10.29 + "@(#) $Id$";
   10.30 +#endif
   10.31 +
   10.32 +/* Output dreamcast aica */
   10.33 +
   10.34 +#include <stdlib.h>
   10.35 +#include <stdio.h>
   10.36 +#include <string.h>
   10.37 +#include <errno.h>
   10.38 +#include <unistd.h>
   10.39 +#include <sys/stat.h>
   10.40 +#include <sys/types.h>
   10.41 +#include <sys/stat.h>
   10.42 +#include <fcntl.h>
   10.43 +
   10.44 +
   10.45 +#include "SDL_audio.h"
   10.46 +#include "SDL_error.h"
   10.47 +#include "SDL_audiomem.h"
   10.48 +#include "SDL_audio_c.h"
   10.49 +#include "SDL_timer.h"
   10.50 +#include "SDL_audiodev_c.h"
   10.51 +#include "SDL_dcaudio.h"
   10.52 +
   10.53 +#include "aica.h"
   10.54 +#include <dc/spu.h>
   10.55 +
   10.56 +/* Audio driver functions */
   10.57 +static int DCAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
   10.58 +static void DCAUD_WaitAudio(_THIS);
   10.59 +static void DCAUD_PlayAudio(_THIS);
   10.60 +static Uint8 *DCAUD_GetAudioBuf(_THIS);
   10.61 +static void DCAUD_CloseAudio(_THIS);
   10.62 +
   10.63 +/* Audio driver bootstrap functions */
   10.64 +static int DCAUD_Available(void)
   10.65 +{
   10.66 +	return 1;
   10.67 +}
   10.68 +
   10.69 +static void DCAUD_DeleteDevice(SDL_AudioDevice *device)
   10.70 +{
   10.71 +	free(device->hidden);
   10.72 +	free(device);
   10.73 +}
   10.74 +
   10.75 +static SDL_AudioDevice *DCAUD_CreateDevice(int devindex)
   10.76 +{
   10.77 +	SDL_AudioDevice *this;
   10.78 +
   10.79 +	/* Initialize all variables that we clean on shutdown */
   10.80 +	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
   10.81 +	if ( this ) {
   10.82 +		memset(this, 0, (sizeof *this));
   10.83 +		this->hidden = (struct SDL_PrivateAudioData *)
   10.84 +				malloc((sizeof *this->hidden));
   10.85 +	}
   10.86 +	if ( (this == NULL) || (this->hidden == NULL) ) {
   10.87 +		SDL_OutOfMemory();
   10.88 +		if ( this ) {
   10.89 +			free(this);
   10.90 +		}
   10.91 +		return(0);
   10.92 +	}
   10.93 +	memset(this->hidden, 0, (sizeof *this->hidden));
   10.94 +
   10.95 +	/* Set the function pointers */
   10.96 +	this->OpenAudio = DCAUD_OpenAudio;
   10.97 +	this->WaitAudio = DCAUD_WaitAudio;
   10.98 +	this->PlayAudio = DCAUD_PlayAudio;
   10.99 +	this->GetAudioBuf = DCAUD_GetAudioBuf;
  10.100 +	this->CloseAudio = DCAUD_CloseAudio;
  10.101 +
  10.102 +	this->free = DCAUD_DeleteDevice;
  10.103 +
  10.104 +	spu_init();
  10.105 +
  10.106 +	return this;
  10.107 +}
  10.108 +
  10.109 +AudioBootStrap DCAUD_bootstrap = {
  10.110 +	"dcaudio", "Dreamcast AICA audio",
  10.111 +	DCAUD_Available, DCAUD_CreateDevice
  10.112 +};
  10.113 +
  10.114 +/* This function waits until it is possible to write a full sound buffer */
  10.115 +static void DCAUD_WaitAudio(_THIS)
  10.116 +{
  10.117 +	if (this->hidden->playing) {
  10.118 +		/* wait */
  10.119 +		while(aica_get_pos(0)/this->spec.samples == this->hidden->nextbuf) {
  10.120 +			thd_pass();
  10.121 +		}
  10.122 +	}
  10.123 +}
  10.124 +
  10.125 +#define	SPU_RAM_BASE	0xa0800000
  10.126 +
  10.127 +static void spu_memload_stereo8(int leftpos,int rightpos,void *src0,size_t size)
  10.128 +{
  10.129 +	uint8 *src = src0;
  10.130 +	uint32 *left  = (uint32*)(leftpos +SPU_RAM_BASE);
  10.131 +	uint32 *right = (uint32*)(rightpos+SPU_RAM_BASE);
  10.132 +	size = (size+7)/8;
  10.133 +	while(size--) {
  10.134 +		unsigned lval,rval;
  10.135 +		lval = *src++;
  10.136 +		rval = *src++;
  10.137 +		lval|= (*src++)<<8;
  10.138 +		rval|= (*src++)<<8;
  10.139 +		lval|= (*src++)<<16;
  10.140 +		rval|= (*src++)<<16;
  10.141 +		lval|= (*src++)<<24;
  10.142 +		rval|= (*src++)<<24;
  10.143 +		g2_write_32(left++,lval);
  10.144 +		g2_write_32(right++,rval);
  10.145 +		g2_fifo_wait();
  10.146 +	}
  10.147 +}
  10.148 +
  10.149 +static void spu_memload_stereo16(int leftpos,int rightpos,void *src0,size_t size)
  10.150 +{
  10.151 +	uint16 *src = src0;
  10.152 +	uint32 *left  = (uint32*)(leftpos +SPU_RAM_BASE);
  10.153 +	uint32 *right = (uint32*)(rightpos+SPU_RAM_BASE);
  10.154 +	size = (size+7)/8;
  10.155 +	while(size--) {
  10.156 +		unsigned lval,rval;
  10.157 +		lval = *src++;
  10.158 +		rval = *src++;
  10.159 +		lval|= (*src++)<<16;
  10.160 +		rval|= (*src++)<<16;
  10.161 +		g2_write_32(left++,lval);
  10.162 +		g2_write_32(right++,rval);
  10.163 +		g2_fifo_wait();
  10.164 +	}
  10.165 +}
  10.166 +
  10.167 +static void DCAUD_PlayAudio(_THIS)
  10.168 +{
  10.169 +	SDL_AudioSpec *spec = &this->spec;
  10.170 +	unsigned int offset;
  10.171 +
  10.172 +	if (this->hidden->playing) {
  10.173 +		/* wait */
  10.174 +		while(aica_get_pos(0)/spec->samples == this->hidden->nextbuf) {
  10.175 +			thd_pass();
  10.176 +		}
  10.177 +	}
  10.178 +
  10.179 +	offset = this->hidden->nextbuf*spec->size;
  10.180 +	this->hidden->nextbuf^=1;
  10.181 +	/* Write the audio data, checking for EAGAIN on broken audio drivers */
  10.182 +	if (spec->channels==1) {
  10.183 +		spu_memload(this->hidden->leftpos+offset,this->hidden->mixbuf,this->hidden->mixlen);
  10.184 +	} else {
  10.185 +		offset/=2;
  10.186 +		if ((this->spec.format&255)==8) {
  10.187 +			spu_memload_stereo8(this->hidden->leftpos+offset,this->hidden->rightpos+offset,this->hidden->mixbuf,this->hidden->mixlen);
  10.188 +		} else {
  10.189 +			spu_memload_stereo16(this->hidden->leftpos+offset,this->hidden->rightpos+offset,this->hidden->mixbuf,this->hidden->mixlen);
  10.190 +		}
  10.191 +	}
  10.192 +
  10.193 +	if (!this->hidden->playing) {
  10.194 +		int mode;
  10.195 +		this->hidden->playing = 1;
  10.196 +		mode = (spec->format==AUDIO_S8)?SM_8BIT:SM_16BIT;
  10.197 +		if (spec->channels==1) {
  10.198 +			aica_play(0,mode,this->hidden->leftpos,0,spec->samples*2,spec->freq,255,128,1);
  10.199 +		} else {
  10.200 +			aica_play(0,mode,this->hidden->leftpos ,0,spec->samples*2,spec->freq,255,0,1);
  10.201 +			aica_play(1,mode,this->hidden->rightpos,0,spec->samples*2,spec->freq,255,255,1);
  10.202 +		}
  10.203 +	}
  10.204 +}
  10.205 +
  10.206 +static Uint8 *DCAUD_GetAudioBuf(_THIS)
  10.207 +{
  10.208 +	return(this->hidden->mixbuf);
  10.209 +}
  10.210 +
  10.211 +static void DCAUD_CloseAudio(_THIS)
  10.212 +{
  10.213 +	aica_stop(0);
  10.214 +	if (this->spec.channels==2) aica_stop(1);
  10.215 +	if ( this->hidden->mixbuf != NULL ) {
  10.216 +		SDL_FreeAudioMem(this->hidden->mixbuf);
  10.217 +		this->hidden->mixbuf = NULL;
  10.218 +	}
  10.219 +}
  10.220 +
  10.221 +static int DCAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
  10.222 +{
  10.223 +	switch(spec->format&0xff) {
  10.224 +	case  8: spec->format = AUDIO_S8; break;
  10.225 +	case 16: spec->format = AUDIO_S16LSB; break;
  10.226 +	default:
  10.227 +		SDL_SetError("Unsupported audio format");
  10.228 +		return(-1);
  10.229 +	}
  10.230 +
  10.231 +	/* Update the fragment size as size in bytes */
  10.232 +	SDL_CalculateAudioSpec(spec);
  10.233 +
  10.234 +	/* Allocate mixing buffer */
  10.235 +	this->hidden->mixlen = spec->size;
  10.236 +	this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
  10.237 +	if ( this->hidden->mixbuf == NULL ) {
  10.238 +		return(-1);
  10.239 +	}
  10.240 +	memset(this->hidden->mixbuf, spec->silence, spec->size);
  10.241 +	this->hidden->leftpos = 0x11000;
  10.242 +	this->hidden->rightpos = 0x11000+spec->size;
  10.243 +	this->hidden->playing = 0;
  10.244 +	this->hidden->nextbuf = 0;
  10.245 +
  10.246 +	/* We're ready to rock and roll. :-) */
  10.247 +	return(0);
  10.248 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/audio/dc/SDL_dcaudio.h	Sat Oct 05 16:50:56 2002 +0000
    11.3 @@ -0,0 +1,45 @@
    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 +    BERO <bero@geocities.co.jp>
   11.23 +    based on SDL_diskaudio.h by Sam Lantinga <slouken@libsdl.org>
   11.24 +*/
   11.25 +
   11.26 +#ifdef SAVE_RCSID
   11.27 +static char rcsid =
   11.28 + "@(#) $Id$";
   11.29 +#endif
   11.30 +
   11.31 +#ifndef _SDL_diskaudio_h
   11.32 +#define _SDL_diskaudio_h
   11.33 +
   11.34 +#include "SDL_sysaudio.h"
   11.35 +
   11.36 +/* Hidden "this" pointer for the video functions */
   11.37 +#define _THIS	SDL_AudioDevice *this
   11.38 +
   11.39 +struct SDL_PrivateAudioData {
   11.40 +	/* The file descriptor for the audio device */
   11.41 +	Uint8 *mixbuf;
   11.42 +	Uint32 mixlen;
   11.43 +	int playing;
   11.44 +	int leftpos,rightpos;
   11.45 +	int nextbuf;
   11.46 +};
   11.47 +
   11.48 +#endif /* _SDL_diskaudio_h */
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/audio/dc/aica.c	Sat Oct 05 16:50:56 2002 +0000
    12.3 @@ -0,0 +1,267 @@
    12.4 +/* This file is part of the Dreamcast function library.
    12.5 + * Please see libdream.c for further details.
    12.6 + *
    12.7 + * (c)2000 Dan Potter
    12.8 + * modify BERO
    12.9 + */
   12.10 +#include "aica.h"
   12.11 +
   12.12 +/* #define dc_snd_base ((volatile unsigned char *)0x00800000) */ /* arm side */
   12.13 +#define dc_snd_base ((volatile unsigned char *)0xa0700000) /* dc side */
   12.14 +
   12.15 +/* Some convienence macros */
   12.16 +#define	SNDREGADDR(x)	(0xa0700000 + (x))
   12.17 +#define	CHNREGADDR(ch,x)	SNDREGADDR(0x80*(ch)+(x))
   12.18 +
   12.19 +
   12.20 +#define SNDREG32(x)	(*(volatile unsigned long *)SNDREGADDR(x))
   12.21 +#define SNDREG8(x)	(*(volatile unsigned char *)SNDREGADDR(x))
   12.22 +#define CHNREG32(ch, x) (*(volatile unsigned long *)CHNREGADDR(ch,x))
   12.23 +#define CHNREG8(ch, x)	(*(volatile unsigned long *)CHNREGADDR(ch,x))
   12.24 +
   12.25 +#define G2_LOCK(OLD) \
   12.26 +	do { \
   12.27 +		if (!irq_inside_int()) \
   12.28 +			OLD = irq_disable(); \
   12.29 +		/* suspend any G2 DMA here... */ \
   12.30 +		while((*(volatile unsigned int *)0xa05f688c) & 0x20) \
   12.31 +			; \
   12.32 +	} while(0)
   12.33 +
   12.34 +#define G2_UNLOCK(OLD) \
   12.35 +	do { \
   12.36 +		/* resume any G2 DMA here... */ \
   12.37 +		if (!irq_inside_int()) \
   12.38 +			irq_restore(OLD); \
   12.39 +	} while(0)
   12.40 +
   12.41 +
   12.42 +void aica_init() {
   12.43 +	int i, j, old;
   12.44 +	
   12.45 +	/* Initialize AICA channels */	
   12.46 +	G2_LOCK(old);
   12.47 +	SNDREG32(0x2800) = 0x0000;
   12.48 +	
   12.49 +	for (i=0; i<64; i++) {
   12.50 +		for (j=0; j<0x80; j+=4) {
   12.51 +			if ((j&31)==0) g2_fifo_wait();
   12.52 +			CHNREG32(i, j) = 0;
   12.53 +		}
   12.54 +		g2_fifo_wait();
   12.55 +		CHNREG32(i,0) = 0x8000;
   12.56 +		CHNREG32(i,20) = 0x1f;
   12.57 +	}
   12.58 +
   12.59 +	SNDREG32(0x2800) = 0x000f;
   12.60 +	g2_fifo_wait();
   12.61 +	G2_UNLOCK(old);
   12.62 +}
   12.63 +
   12.64 +/* Translates a volume from linear form to logarithmic form (required by
   12.65 +   the AICA chip */
   12.66 +/* int logs[] = {
   12.67 +
   12.68 +0, 40, 50, 58, 63, 68, 73, 77, 80, 83, 86, 89, 92, 94, 97, 99, 101, 103,
   12.69 +105, 107, 109, 111, 112, 114, 116, 117, 119, 120, 122, 123, 125, 126, 127,
   12.70 +129, 130, 131, 133, 134, 135, 136, 137, 139, 140, 141, 142, 143, 144, 145,
   12.71 +146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 156, 157, 158, 159,
   12.72 +160, 161, 162, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 170, 171,
   12.73 +172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, 180, 180, 181, 182,
   12.74 +182, 183, 183, 184, 185, 185, 186, 187, 187, 188, 188, 189, 190, 190, 191,
   12.75 +191, 192, 193, 193, 194, 194, 195, 196, 196, 197, 197, 198, 198, 199, 199,
   12.76 +200, 201, 201, 202, 202, 203, 203, 204, 204, 205, 205, 206, 206, 207, 207,
   12.77 +208, 208, 209, 209, 210, 210, 211, 211, 212, 212, 213, 213, 214, 214, 215,
   12.78 +215, 216, 216, 217, 217, 217, 218, 218, 219, 219, 220, 220, 221, 221, 222,
   12.79 +222, 222, 223, 223, 224, 224, 225, 225, 225, 226, 226, 227, 227, 228, 228,
   12.80 +228, 229, 229, 230, 230, 230, 231, 231, 232, 232, 232, 233, 233, 234, 234,
   12.81 +234, 235, 235, 236, 236, 236, 237, 237, 238, 238, 238, 239, 239, 240, 240,
   12.82 +240, 241, 241, 241, 242, 242, 243, 243, 243, 244, 244, 244, 245, 245, 245,
   12.83 +246, 246, 247, 247, 247, 248, 248, 248, 249, 249, 249, 250, 250, 250, 251,
   12.84 +251, 251, 252, 252, 252, 253, 253, 253, 254, 254, 254, 255
   12.85 +
   12.86 +}; */
   12.87 +
   12.88 +const static unsigned char logs[] = {
   12.89 +	0, 15, 22, 27, 31, 35, 39, 42, 45, 47, 50, 52, 55, 57, 59, 61,
   12.90 +	63, 65, 67, 69, 71, 73, 74, 76, 78, 79, 81, 82, 84, 85, 87, 88,
   12.91 +	90, 91, 92, 94, 95, 96, 98, 99, 100, 102, 103, 104, 105, 106,
   12.92 +	108, 109, 110, 111, 112, 113, 114, 116, 117, 118, 119, 120, 121,
   12.93 +	122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
   12.94 +	135, 136, 137, 138, 138, 139, 140, 141, 142, 143, 144, 145, 146,
   12.95 +	146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 156,
   12.96 +	157, 158, 159, 160, 160, 161, 162, 163, 164, 164, 165, 166, 167,
   12.97 +	167, 168, 169, 170, 170, 171, 172, 173, 173, 174, 175, 176, 176,
   12.98 +	177, 178, 178, 179, 180, 181, 181, 182, 183, 183, 184, 185, 185,
   12.99 +	186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194,
  12.100 +	195, 195, 196, 197, 197, 198, 199, 199, 200, 200, 201, 202, 202,
  12.101 +	203, 204, 204, 205, 205, 206, 207, 207, 208, 209, 209, 210, 210,
  12.102 +	211, 212, 212, 213, 213, 214, 215, 215, 216, 216, 217, 217, 218,
  12.103 +	219, 219, 220, 220, 221, 221, 222, 223, 223, 224, 224, 225, 225,
  12.104 +	226, 227, 227, 228, 228, 229, 229, 230, 230, 231, 232, 232, 233,
  12.105 +	233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 239, 239, 240,
  12.106 +	240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246,
  12.107 +	247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, 254, 255
  12.108 +};
  12.109 +
  12.110 +/* For the moment this is going to have to suffice, until we really
  12.111 +   figure out what these mean. */
  12.112 +#define AICA_PAN(x) ((x)==0x80?(0):((x)<0x80?(0x1f):(0x0f)))
  12.113 +#define AICA_VOL(x) (0xff - logs[128 + (((x) & 0xff) / 2)])
  12.114 +//#define AICA_VOL(x) (0xff - logs[x&255])
  12.115 +
  12.116 +static inline unsigned  AICA_FREQ(unsigned freq)	{
  12.117 +	unsigned long freq_lo, freq_base = 5644800;
  12.118 +	int freq_hi = 7;
  12.119 +
  12.120 +	/* Need to convert frequency to floating point format
  12.121 +	   (freq_hi is exponent, freq_lo is mantissa)
  12.122 +	   Formula is ferq = 44100*2^freq_hi*(1+freq_lo/1024) */
  12.123 +	while (freq < freq_base && freq_hi > -8) {
  12.124 +		freq_base >>= 1;
  12.125 +		--freq_hi;
  12.126 +	}
  12.127 +	while (freq < freq_base && freq_hi > -8) {
  12.128 +		freq_base >>= 1;
  12.129 +		freq_hi--;
  12.130 +	}
  12.131 +	freq_lo = (freq<<10) / freq_base;
  12.132 +	return (freq_hi << 11) | (freq_lo & 1023);
  12.133 +}
  12.134 +
  12.135 +/* Sets up a sound channel completely. This is generally good if you want
  12.136 +   a quick and dirty way to play notes. If you want a more comprehensive
  12.137 +   set of routines (more like PC wavetable cards) see below.
  12.138 +   
  12.139 +   ch is the channel to play on (0 - 63)
  12.140 +   smpptr is the pointer to the sound data; if you're running off the
  12.141 +     SH4, then this ought to be (ptr - 0xa0800000); otherwise it's just
  12.142 +     ptr. Basically, it's an offset into sound ram.
  12.143 +   mode is one of the mode constants (16 bit, 8 bit, ADPCM)
  12.144 +   nsamp is the number of samples to play (not number of bytes!)
  12.145 +   freq is the sampling rate of the sound
  12.146 +   vol is the volume, 0 to 0xff (0xff is louder)
  12.147 +   pan is a panning constant -- 0 is left, 128 is center, 255 is right.
  12.148 +
  12.149 +   This routine (and the similar ones) owe a lot to Marcus' sound example -- 
  12.150 +   I hadn't gotten quite this far into dissecting the individual regs yet. */
  12.151 +void aica_play(int ch,int mode,unsigned long smpptr,int loopst,int loopend,int freq,int vol,int pan,int loopflag) {
  12.152 +	int i;
  12.153 +	int val;
  12.154 +	int old;
  12.155 +
  12.156 +	/* Stop the channel (if it's already playing) */
  12.157 +	aica_stop(ch);
  12.158 +	/* doesn't seem to be needed, but it's here just in case */
  12.159 +/*
  12.160 +	for (i=0; i<256; i++) {
  12.161 +		asm("nop");
  12.162 +		asm("nop");
  12.163 +		asm("nop");
  12.164 +		asm("nop");
  12.165 +	}
  12.166 +*/
  12.167 +	G2_LOCK(old);
  12.168 +	/* Envelope setup. The first of these is the loop point,
  12.169 +	   e.g., where the sample starts over when it loops. The second
  12.170 +	   is the loop end. This is the full length of the sample when
  12.171 +	   you are not looping, or the loop end point when you are (though
  12.172 +	   storing more than that is a waste of memory if you're not doing
  12.173 +	   volume enveloping). */
  12.174 +	CHNREG32(ch, 8) = loopst & 0xffff;
  12.175 +	CHNREG32(ch, 12) = loopend & 0xffff;
  12.176 +	
  12.177 +	/* Write resulting values */
  12.178 +	CHNREG32(ch, 24) = AICA_FREQ(freq);
  12.179 +	
  12.180 +	/* Set volume, pan, and some other things that we don't know what
  12.181 +	   they do =) */
  12.182 +	CHNREG32(ch, 36) = AICA_PAN(pan) | (0xf<<8);
  12.183 +	/* Convert the incoming volume and pan into hardware values */
  12.184 +	/* Vol starts at zero so we can ramp */
  12.185 +	vol = AICA_VOL(vol);
  12.186 +	CHNREG32(ch, 40) = 0x24 | (vol<<8);
  12.187 +	/* Convert the incoming volume and pan into hardware values */
  12.188 +	/* Vol starts at zero so we can ramp */
  12.189 +
  12.190 +	/* If we supported volume envelopes (which we don't yet) then
  12.191 +	   this value would set that up. The top 4 bits determine the
  12.192 +	   envelope speed. f is the fastest, 1 is the slowest, and 0
  12.193 +	   seems to be an invalid value and does weird things). The
  12.194 +	   default (below) sets it into normal mode (play and terminate/loop).
  12.195 +	CHNREG32(ch, 16) = 0xf010;
  12.196 +	*/
  12.197 +	CHNREG32(ch, 16) = 0x1f;	/* No volume envelope */
  12.198 +	
  12.199 +	
  12.200 +	/* Set sample format, buffer address, and looping control. If
  12.201 +	   0x0200 mask is set on reg 0, the sample loops infinitely. If
  12.202 +	   it's not set, the sample plays once and terminates. We'll
  12.203 +	   also set the bits to start playback here. */
  12.204 +	CHNREG32(ch, 4) = smpptr & 0xffff;
  12.205 +	val = 0xc000 | 0x0000 | (mode<<7) | (smpptr >> 16);
  12.206 +	if (loopflag) val|=0x200;
  12.207 +	
  12.208 +	CHNREG32(ch, 0) = val;
  12.209 +	
  12.210 +	G2_UNLOCK(old);
  12.211 +
  12.212 +	/* Enable playback */
  12.213 +	/* CHNREG32(ch, 0) |= 0xc000; */
  12.214 +	g2_fifo_wait();
  12.215 +
  12.216 +#if 0
  12.217 +	for (i=0xff; i>=vol; i--) {
  12.218 +		if ((i&7)==0) g2_fifo_wait();
  12.219 +		CHNREG32(ch, 40) =  0x24 | (i<<8);;
  12.220 +	}
  12.221 +
  12.222 +	g2_fifo_wait();
  12.223 +#endif
  12.224 +}
  12.225 +
  12.226 +/* Stop the sound on a given channel */
  12.227 +void aica_stop(int ch) {
  12.228 +	g2_write_32(CHNREGADDR(ch, 0),(g2_read_32(CHNREGADDR(ch, 0)) & ~0x4000) | 0x8000);
  12.229 +	g2_fifo_wait();
  12.230 +}
  12.231 +
  12.232 +
  12.233 +/* The rest of these routines can change the channel in mid-stride so you
  12.234 +   can do things like vibrato and panning effects. */
  12.235 +   
  12.236 +/* Set channel volume */
  12.237 +void aica_vol(int ch,int vol) {
  12.238 +//	g2_write_8(CHNREGADDR(ch, 41),AICA_VOL(vol));
  12.239 +	g2_write_32(CHNREGADDR(ch, 40),(g2_read_32(CHNREGADDR(ch, 40))&0xffff00ff)|(AICA_VOL(vol)<<8) );
  12.240 +	g2_fifo_wait();
  12.241 +}
  12.242 +
  12.243 +/* Set channel pan */
  12.244 +void aica_pan(int ch,int pan) {
  12.245 +//	g2_write_8(CHNREGADDR(ch, 36),AICA_PAN(pan));
  12.246 +	g2_write_32(CHNREGADDR(ch, 36),(g2_read_32(CHNREGADDR(ch, 36))&0xffffff00)|(AICA_PAN(pan)) );
  12.247 +	g2_fifo_wait();
  12.248 +}
  12.249 +
  12.250 +/* Set channel frequency */
  12.251 +void aica_freq(int ch,int freq) {
  12.252 +	g2_write_32(CHNREGADDR(ch, 24),AICA_FREQ(freq));
  12.253 +	g2_fifo_wait();
  12.254 +}
  12.255 +
  12.256 +/* Get channel position */
  12.257 +int aica_get_pos(int ch) {
  12.258 +#if 1
  12.259 +	/* Observe channel ch */
  12.260 +	g2_write_32(SNDREGADDR(0x280c),(g2_read_32(SNDREGADDR(0x280c))&0xffff00ff) | (ch<<8));
  12.261 +	g2_fifo_wait();
  12.262 +	/* Update position counters */
  12.263 +	return g2_read_32(SNDREGADDR(0x2814)) & 0xffff;
  12.264 +#else
  12.265 +	/* Observe channel ch */
  12.266 +	g2_write_8(SNDREGADDR(0x280d),ch);
  12.267 +	/* Update position counters */
  12.268 +	return g2_read_32(SNDREGADDR(0x2814)) & 0xffff;
  12.269 +#endif
  12.270 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/audio/dc/aica.h	Sat Oct 05 16:50:56 2002 +0000
    13.3 @@ -0,0 +1,17 @@
    13.4 +#ifndef _AICA_H_
    13.5 +#define _AICA_H_
    13.6 +
    13.7 +#define	AICA_MEM	0xa0800000
    13.8 +
    13.9 +#define SM_8BIT		1
   13.10 +#define SM_16BIT	0
   13.11 +#define SM_ADPCM	2
   13.12 +
   13.13 +void aica_play(int ch,int mode,unsigned long smpptr,int looptst,int loopend,int freq,int vol,int pan,int loopflag);
   13.14 +void aica_stop(int ch);
   13.15 +void aica_vol(int ch,int vol);
   13.16 +void aica_pan(int ch,int pan);
   13.17 +void aica_freq(int ch,int freq);
   13.18 +int aica_get_pos(int ch);
   13.19 +
   13.20 +#endif
    14.1 --- a/src/cdrom/Makefile.am	Sat Oct 05 16:27:56 2002 +0000
    14.2 +++ b/src/cdrom/Makefile.am	Sat Oct 05 16:50:56 2002 +0000
    14.3 @@ -5,7 +5,7 @@
    14.4  
    14.5  # Define which subdirectories need to be built
    14.6  SUBDIRS = @CDROM_SUBDIRS@
    14.7 -DIST_SUBDIRS = aix beos bsdi dummy freebsd linux macos openbsd qnx win32
    14.8 +DIST_SUBDIRS = aix beos bsdi dc dummy freebsd linux macos openbsd qnx win32
    14.9  
   14.10  DRIVERS = @CDROM_DRIVERS@
   14.11  
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/cdrom/dc/.cvsignore	Sat Oct 05 16:50:56 2002 +0000
    15.3 @@ -0,0 +1,6 @@
    15.4 +Makefile.in
    15.5 +Makefile
    15.6 +.libs
    15.7 +*.o
    15.8 +*.lo
    15.9 +*.la
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/cdrom/dc/Makefile.am	Sat Oct 05 16:50:56 2002 +0000
    16.3 @@ -0,0 +1,8 @@
    16.4 +
    16.5 +## Makefile.am for the Dreamcast cdrom driver for SDL
    16.6 +
    16.7 +noinst_LTLIBRARIES = libcdrom_dc.la
    16.8 +libcdrom_dc_la_SOURCES = $(SRCS)
    16.9 +
   16.10 +# The SDL cdrom driver sources
   16.11 +SRCS = SDL_syscdrom.c
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/cdrom/dc/SDL_syscdrom.c	Sat Oct 05 16:50:56 2002 +0000
    17.3 @@ -0,0 +1,176 @@
    17.4 +/*
    17.5 +    SDL - Simple DirectMedia Layer
    17.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    17.7 +
    17.8 +    This library is free software; you can redistribute it and/or
    17.9 +    modify it under the terms of the GNU Library General Public
   17.10 +    License as published by the Free Software Foundation; either
   17.11 +    version 2 of the License, or (at your option) any later version.
   17.12 +
   17.13 +    This library is distributed in the hope that it will be useful,
   17.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   17.16 +    Library General Public License for more details.
   17.17 +
   17.18 +    You should have received a copy of the GNU Library General Public
   17.19 +    License along with this library; if not, write to the Free
   17.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17.21 +
   17.22 +    BERO
   17.23 +    bero@geocities.co.jp
   17.24 +
   17.25 +    based on win32/SDL_syscdrom.c by
   17.26 +
   17.27 +    Sam Lantinga
   17.28 +    slouken@libsdl.org
   17.29 +*/
   17.30 +
   17.31 +#ifdef SAVE_RCSID
   17.32 +static char rcsid =
   17.33 + "@(#) $Id$";
   17.34 +#endif
   17.35 +
   17.36 +/* Functions for system-level CD-ROM audio control */
   17.37 +
   17.38 +#include <stdlib.h>
   17.39 +#include <stdio.h>
   17.40 +#include <dc/cdrom.h>
   17.41 +#include <dc/spu.h>
   17.42 +
   17.43 +#include "SDL_error.h"
   17.44 +#include "SDL_cdrom.h"
   17.45 +#include "SDL_syscdrom.h"
   17.46 +
   17.47 +/* The system-dependent CD control functions */
   17.48 +static const char *SDL_SYS_CDName(int drive);
   17.49 +static int SDL_SYS_CDOpen(int drive);
   17.50 +static int SDL_SYS_CDGetTOC(SDL_CD *cdrom);
   17.51 +static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position);
   17.52 +static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length);
   17.53 +static int SDL_SYS_CDPause(SDL_CD *cdrom);
   17.54 +static int SDL_SYS_CDResume(SDL_CD *cdrom);
   17.55 +static int SDL_SYS_CDStop(SDL_CD *cdrom);
   17.56 +static int SDL_SYS_CDEject(SDL_CD *cdrom);
   17.57 +static void SDL_SYS_CDClose(SDL_CD *cdrom);
   17.58 +
   17.59 +
   17.60 +int  SDL_SYS_CDInit(void)
   17.61 +{
   17.62 +	/* Fill in our driver capabilities */
   17.63 +	SDL_CDcaps.Name = SDL_SYS_CDName;
   17.64 +	SDL_CDcaps.Open = SDL_SYS_CDOpen;
   17.65 +	SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   17.66 +	SDL_CDcaps.Status = SDL_SYS_CDStatus;
   17.67 +	SDL_CDcaps.Play = SDL_SYS_CDPlay;
   17.68 +	SDL_CDcaps.Pause = SDL_SYS_CDPause;
   17.69 +	SDL_CDcaps.Resume = SDL_SYS_CDResume;
   17.70 +	SDL_CDcaps.Stop = SDL_SYS_CDStop;
   17.71 +	SDL_CDcaps.Eject = SDL_SYS_CDEject;
   17.72 +	SDL_CDcaps.Close = SDL_SYS_CDClose;
   17.73 +
   17.74 +	return(0);
   17.75 +}
   17.76 +
   17.77 +static const char *SDL_SYS_CDName(int drive)
   17.78 +{
   17.79 +	return "/cd";
   17.80 +}
   17.81 +
   17.82 +static int SDL_SYS_CDOpen(int drive)
   17.83 +{
   17.84 +	return(drive);
   17.85 +}
   17.86 +
   17.87 +#define	TRACK_CDDA	0
   17.88 +static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
   17.89 +{
   17.90 +	CDROM_TOC toc;
   17.91 +	int ret,i;
   17.92 +
   17.93 +	ret = cdrom_read_toc(&toc,0);
   17.94 +	if (ret!=ERR_OK) {
   17.95 +		return -1;
   17.96 +	}
   17.97 +
   17.98 +	cdrom->numtracks = TOC_TRACK(toc.last)-TOC_TRACK(toc.first)+1;
   17.99 +	for(i=0;i<cdrom->numtracks;i++) {
  17.100 +		unsigned long entry = toc.entry[i];
  17.101 +		cdrom->track[i].id = i+1;
  17.102 +		cdrom->track[i].type = (TOC_CTRL(toc.entry[i])==TRACK_CDDA)?SDL_AUDIO_TRACK:SDL_DATA_TRACK;
  17.103 +		cdrom->track[i].offset = TOC_LBA(entry)-150;
  17.104 +		cdrom->track[i].length = TOC_LBA((i+1<toc.last)?toc.entry[i+1]:toc.dunno)-TOC_LBA(entry);
  17.105 +	}
  17.106 +
  17.107 +	return 0;
  17.108 +}
  17.109 +
  17.110 +/* Get CD-ROM status */
  17.111 +static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
  17.112 +{
  17.113 +	CDstatus status;
  17.114 +	int ret,dc_status,disc_type;
  17.115 +
  17.116 +	ret = cdrom_get_status(&dc_status,&disc_type);
  17.117 +	if (ret!=ERR_OK) return CD_ERROR;
  17.118 +
  17.119 +	switch(dc_status) {
  17.120 +//	case CD_STATUS_BUSY:
  17.121 +	case CD_STATUS_PAUSED:
  17.122 +		return CD_PAUSED;
  17.123 +	case CD_STATUS_STANDBY:
  17.124 +		return CD_STOPPED;
  17.125 +	case CD_STATUS_PLAYING:
  17.126 +		return CD_PLAYING;
  17.127 +//	case CD_STATUS_SEEKING:
  17.128 +//	case CD_STATUS_SCANING:
  17.129 +	case CD_STATUS_OPEN:
  17.130 +	case CD_STATUS_NO_DISC:
  17.131 +		return CD_TRAYEMPTY;
  17.132 +	default:
  17.133 +		return	CD_ERROR;
  17.134 +	}
  17.135 +}
  17.136 +
  17.137 +/* Start play */
  17.138 +static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
  17.139 +{
  17.140 +	int ret = cdrom_cdda_play(start-150,start-150+length,1,CDDA_SECTORS);
  17.141 +	return ret==ERR_OK?0:-1;
  17.142 +}
  17.143 +
  17.144 +/* Pause play */
  17.145 +static int SDL_SYS_CDPause(SDL_CD *cdrom)
  17.146 +{
  17.147 +	int ret=cdrom_cdda_pause();
  17.148 +	return ret==ERR_OK?0:-1;
  17.149 +}
  17.150 +
  17.151 +/* Resume play */
  17.152 +static int SDL_SYS_CDResume(SDL_CD *cdrom)
  17.153 +{
  17.154 +	int ret=cdrom_cdda_resume();
  17.155 +	return ret==ERR_OK?0:-1;
  17.156 +}
  17.157 +
  17.158 +/* Stop play */
  17.159 +static int SDL_SYS_CDStop(SDL_CD *cdrom)
  17.160 +{
  17.161 +	int ret=cdrom_spin_down();
  17.162 +	return ret==ERR_OK?0:-1;
  17.163 +}
  17.164 +
  17.165 +/* Eject the CD-ROM */
  17.166 +static int SDL_SYS_CDEject(SDL_CD *cdrom)
  17.167 +{
  17.168 +	return -1;
  17.169 +}
  17.170 +
  17.171 +/* Close the CD-ROM handle */
  17.172 +static void SDL_SYS_CDClose(SDL_CD *cdrom)
  17.173 +{
  17.174 +}
  17.175 +
  17.176 +void SDL_SYS_CDQuit(void)
  17.177 +{
  17.178 +
  17.179 +}
    18.1 --- a/src/joystick/Makefile.am	Sat Oct 05 16:27:56 2002 +0000
    18.2 +++ b/src/joystick/Makefile.am	Sat Oct 05 16:50:56 2002 +0000
    18.3 @@ -5,7 +5,7 @@
    18.4  
    18.5  # Define which subdirectories need to be built
    18.6  SUBDIRS = @JOYSTICK_SUBDIRS@
    18.7 -DIST_SUBDIRS = dummy amigaos beos bsd darwin linux macos mint win32
    18.8 +DIST_SUBDIRS = dummy amigaos beos bsd darwin dc linux macos mint win32
    18.9  
   18.10  DRIVERS = @JOYSTICK_DRIVERS@
   18.11  
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/joystick/dc/.cvsignore	Sat Oct 05 16:50:56 2002 +0000
    19.3 @@ -0,0 +1,6 @@
    19.4 +Makefile.in
    19.5 +Makefile
    19.6 +.libs
    19.7 +*.o
    19.8 +*.lo
    19.9 +*.la
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/joystick/dc/Makefile.am	Sat Oct 05 16:50:56 2002 +0000
    20.3 @@ -0,0 +1,8 @@
    20.4 +
    20.5 +## Makefile.am for the Dreamcast joystick driver for SDL
    20.6 +
    20.7 +noinst_LTLIBRARIES = libjoystick_dc.la
    20.8 +libjoystick_dc_la_SOURCES = $(SRCS)
    20.9 +
   20.10 +# The SDL joystick driver sources
   20.11 +SRCS =  SDL_sysjoystick.c
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/joystick/dc/SDL_sysjoystick.c	Sat Oct 05 16:50:56 2002 +0000
    21.3 @@ -0,0 +1,203 @@
    21.4 +/*
    21.5 +    SDL - Simple DirectMedia Layer
    21.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    21.7 +
    21.8 +    This library is free software; you can redistribute it and/or
    21.9 +    modify it under the terms of the GNU Library General Public
   21.10 +    License as published by the Free Software Foundation; either
   21.11 +    version 2 of the License, or (at your option) any later version.
   21.12 +
   21.13 +    This library is distributed in the hope that it will be useful,
   21.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   21.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   21.16 +    Library General Public License for more details.
   21.17 +
   21.18 +    You should have received a copy of the GNU Library General Public
   21.19 +    License along with this library; if not, write to the Free
   21.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21.21 +
   21.22 +    BERO
   21.23 +    bero@geocities.co.jp
   21.24 +
   21.25 +    based on win32/SDL_mmjoystick.c
   21.26 +
   21.27 +    Sam Lantinga
   21.28 +    slouken@libsdl.org
   21.29 +*/
   21.30 +
   21.31 +#ifdef SAVE_RCSID
   21.32 +static char rcsid =
   21.33 + "@(#) $Id$";
   21.34 +#endif
   21.35 +
   21.36 +/* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */
   21.37 +
   21.38 +#include <stdlib.h>
   21.39 +#include <stdio.h>		/* For the definition of NULL */
   21.40 +
   21.41 +#include "SDL_error.h"
   21.42 +#include "SDL_joystick.h"
   21.43 +#include "SDL_sysjoystick.h"
   21.44 +#include "SDL_joystick_c.h"
   21.45 +
   21.46 +#include <dc/maple.h>
   21.47 +#include <dc/maple/controller.h>
   21.48 +
   21.49 +#define MAX_JOYSTICKS	8	/* only 2 are supported in the multimedia API */
   21.50 +#define MAX_AXES	6	/* each joystick can have up to 6 axes */
   21.51 +#define MAX_BUTTONS	8	/* and 8 buttons                      */
   21.52 +#define	MAX_HATS	2
   21.53 +
   21.54 +#define	JOYNAMELEN	8
   21.55 +
   21.56 +/* array to hold joystick ID values */
   21.57 +static uint8	SYS_Joystick_addr[MAX_JOYSTICKS];
   21.58 +
   21.59 +/* The private structure used to keep track of a joystick */
   21.60 +struct joystick_hwdata
   21.61 +{
   21.62 +	cont_cond_t prev_cond;
   21.63 +	int prev_buttons;
   21.64 +};
   21.65 +
   21.66 +/* Function to scan the system for joysticks.
   21.67 + * This function should set SDL_numjoysticks to the number of available
   21.68 + * joysticks.  Joystick 0 should be the system default joystick.
   21.69 + * It should return 0, or -1 on an unrecoverable fatal error.
   21.70 + */
   21.71 +int SDL_SYS_JoystickInit(void)
   21.72 +{
   21.73 +	int numdevs;
   21.74 +
   21.75 +	int p,u;
   21.76 +
   21.77 +	numdevs = 0;
   21.78 +	for(p=0;p<MAPLE_PORT_COUNT;p++) {
   21.79 +		for(u=0;u<MAPLE_UNIT_COUNT;u++) {
   21.80 +			if (maple_device_func(p,u)&MAPLE_FUNC_CONTROLLER) {
   21.81 +				SYS_Joystick_addr[numdevs] = maple_addr(p,u);
   21.82 +				numdevs++;
   21.83 +			}
   21.84 +		}
   21.85 +	}
   21.86 +
   21.87 +	return(numdevs);
   21.88 +}
   21.89 +
   21.90 +/* Function to get the device-dependent name of a joystick */
   21.91 +const char *SDL_SYS_JoystickName(int index)
   21.92 +{
   21.93 +	maple_device_t *dev;
   21.94 +	if (maple_compat_resolve(SYS_Joystick_addr[index],&dev,MAPLE_FUNC_CONTROLLER)!=0) return NULL;
   21.95 +	return dev->info.product_name;
   21.96 +}
   21.97 +
   21.98 +/* Function to open a joystick for use.
   21.99 +   The joystick to open is specified by the index field of the joystick.
  21.100 +   This should fill the nbuttons and naxes fields of the joystick structure.
  21.101 +   It returns 0, or -1 if there is an error.
  21.102 + */
  21.103 +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
  21.104 +{
  21.105 +	/* allocate memory for system specific hardware data */
  21.106 +	joystick->hwdata = (struct joystick_hwdata *) malloc(sizeof(*joystick->hwdata));
  21.107 +	if (joystick->hwdata == NULL)
  21.108 +	{
  21.109 +		SDL_OutOfMemory();
  21.110 +		return(-1);
  21.111 +	}
  21.112 +	memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
  21.113 +
  21.114 +	/* fill nbuttons, naxes, and nhats fields */
  21.115 +	joystick->nbuttons = MAX_BUTTONS;
  21.116 +	joystick->naxes = MAX_AXES;
  21.117 +	joystick->nhats = MAX_HATS;
  21.118 +	return(0);
  21.119 +}
  21.120 +
  21.121 +
  21.122 +/* Function to update the state of a joystick - called as a device poll.
  21.123 + * This function shouldn't update the joystick structure directly,
  21.124 + * but instead should call SDL_PrivateJoystick*() to deliver events
  21.125 + * and update joystick device state.
  21.126 + */
  21.127 +
  21.128 +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
  21.129 +{
  21.130 +const	int sdl_buttons[] = {
  21.131 +	CONT_C,
  21.132 +	CONT_B,
  21.133 +	CONT_A,
  21.134 +	CONT_START,
  21.135 +	CONT_Z,
  21.136 +	CONT_Y,
  21.137 +	CONT_X,
  21.138 +	CONT_D
  21.139 +};
  21.140 +
  21.141 +	uint8 addr;
  21.142 +	cont_cond_t cond,*prev_cond;
  21.143 +	int buttons,prev_buttons,i,changed;
  21.144 +
  21.145 +	addr = SYS_Joystick_addr[joystick->index];
  21.146 +	if (cont_get_cond(addr,&cond)<0) return;
  21.147 +
  21.148 +	buttons = cond.buttons;
  21.149 +	prev_buttons = joystick->hwdata->prev_buttons;
  21.150 +	changed = buttons^prev_buttons;
  21.151 +
  21.152 +	if ((changed)&(CONT_DPAD_UP|CONT_DPAD_DOWN|CONT_DPAD_LEFT|CONT_DPAD_RIGHT)) {
  21.153 +		int hat = SDL_HAT_CENTERED;
  21.154 +		if (buttons&CONT_DPAD_UP) hat|=SDL_HAT_UP;
  21.155 +		if (buttons&CONT_DPAD_DOWN) hat|=SDL_HAT_DOWN;
  21.156 +		if (buttons&CONT_DPAD_LEFT) hat|=SDL_HAT_LEFT;
  21.157 +		if (buttons&CONT_DPAD_RIGHT) hat|=SDL_HAT_RIGHT;
  21.158 +		SDL_PrivateJoystickHat(joystick, 0, hat);
  21.159 +	}
  21.160 +	if ((changed)&(CONT_DPAD2_UP|CONT_DPAD2_DOWN|CONT_DPAD2_LEFT|CONT_DPAD2_RIGHT)) {
  21.161 +		int hat = SDL_HAT_CENTERED;
  21.162 +		if (buttons&CONT_DPAD2_UP) hat|=SDL_HAT_UP;
  21.163 +		if (buttons&CONT_DPAD2_DOWN) hat|=SDL_HAT_DOWN;
  21.164 +		if (buttons&CONT_DPAD2_LEFT) hat|=SDL_HAT_LEFT;
  21.165 +		if (buttons&CONT_DPAD2_RIGHT) hat|=SDL_HAT_RIGHT;
  21.166 +		SDL_PrivateJoystickHat(joystick, 1, hat);
  21.167 +	}
  21.168 +
  21.169 +	for(i=0;i<sizeof(sdl_buttons)/sizeof(sdl_buttons[0]);i++) {
  21.170 +		if (changed & sdl_buttons[i]) {
  21.171 +			SDL_PrivateJoystickButton(joystick, i, (buttons & sdl_buttons[i])?SDL_PRESSED:SDL_RELEASED);
  21.172 +		}
  21.173 +	}
  21.174 +
  21.175 +	prev_cond = &joystick->hwdata->prev_cond;
  21.176 +	if (cond.joyx!=prev_cond->joyx)
  21.177 +		SDL_PrivateJoystickAxis(joystick, 0, cond.joyx-128);
  21.178 +	if (cond.joyy!=prev_cond->joyy)
  21.179 +		SDL_PrivateJoystickAxis(joystick, 1, cond.joyy-128);
  21.180 +	if (cond.rtrig!=prev_cond->rtrig)
  21.181 +		SDL_PrivateJoystickAxis(joystick, 2, cond.rtrig);
  21.182 +	if (cond.ltrig!=prev_cond->ltrig)
  21.183 +		SDL_PrivateJoystickAxis(joystick, 3, cond.ltrig);
  21.184 +	if (cond.joy2x!=prev_cond->joy2x)
  21.185 +		SDL_PrivateJoystickAxis(joystick, 4, cond.joy2x-128);
  21.186 +	if (cond.joy2y!=prev_cond->joy2y)
  21.187 +		SDL_PrivateJoystickAxis(joystick, 5, cond.joy2y-128);
  21.188 +
  21.189 +	joystick->hwdata->prev_buttons = buttons;
  21.190 +	joystick->hwdata->prev_cond = cond;
  21.191 +}
  21.192 +
  21.193 +/* Function to close a joystick after use */
  21.194 +void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
  21.195 +{
  21.196 +	if (joystick->hwdata != NULL) {
  21.197 +		/* free system specific hardware data */
  21.198 +		free(joystick->hwdata);
  21.199 +	}
  21.200 +}
  21.201 +
  21.202 +/* Function to perform any system-specific joystick related cleanup */
  21.203 +void SDL_SYS_JoystickQuit(void)
  21.204 +{
  21.205 +	return;
  21.206 +}
    22.1 --- a/src/thread/Makefile.am	Sat Oct 05 16:27:56 2002 +0000
    22.2 +++ b/src/thread/Makefile.am	Sat Oct 05 16:50:56 2002 +0000
    22.3 @@ -7,6 +7,7 @@
    22.4                 $(srcdir)/amigaos	\
    22.5                 $(srcdir)/beos		\
    22.6                 $(srcdir)/bsdi		\
    22.7 +               $(srcdir)/dc		\
    22.8                 $(srcdir)/epoc		\
    22.9                 $(srcdir)/irix		\
   22.10                 $(srcdir)/linux		\
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/thread/dc/SDL_syscond.c	Sat Oct 05 16:50:56 2002 +0000
    23.3 @@ -0,0 +1,223 @@
    23.4 +/*
    23.5 +    SDL - Simple DirectMedia Layer
    23.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    23.7 +
    23.8 +    This library is free software; you can redistribute it and/or
    23.9 +    modify it under the terms of the GNU Library General Public
   23.10 +    License as published by the Free Software Foundation; either
   23.11 +    version 2 of the License, or (at your option) any later version.
   23.12 +
   23.13 +    This library is distributed in the hope that it will be useful,
   23.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   23.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   23.16 +    Library General Public License for more details.
   23.17 +
   23.18 +    You should have received a copy of the GNU Library General Public
   23.19 +    License along with this library; if not, write to the Free
   23.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23.21 +
   23.22 +    Sam Lantinga
   23.23 +    slouken@libsdl.org
   23.24 +*/
   23.25 +
   23.26 +#ifdef SAVE_RCSID
   23.27 +static char rcsid =
   23.28 + "@(#) $Id$";
   23.29 +#endif
   23.30 +
   23.31 +/* An implementation of condition variables using semaphores and mutexes */
   23.32 +/*
   23.33 +   This implementation borrows heavily from the BeOS condition variable
   23.34 +   implementation, written by Christopher Tate and Owen Smith.  Thanks!
   23.35 + */
   23.36 +
   23.37 +#include <stdio.h>
   23.38 +#include <stdlib.h>
   23.39 +
   23.40 +#include "SDL_error.h"
   23.41 +#include "SDL_thread.h"
   23.42 +
   23.43 +struct SDL_cond
   23.44 +{
   23.45 +	SDL_mutex *lock;
   23.46 +	int waiting;
   23.47 +	int signals;
   23.48 +	SDL_sem *wait_sem;
   23.49 +	SDL_sem *wait_done;
   23.50 +};
   23.51 +
   23.52 +/* Create a condition variable */
   23.53 +SDL_cond * SDL_CreateCond(void)
   23.54 +{
   23.55 +	SDL_cond *cond;
   23.56 +
   23.57 +	cond = (SDL_cond *) malloc(sizeof(SDL_cond));
   23.58 +	if ( cond ) {
   23.59 +		cond->lock = SDL_CreateMutex();
   23.60 +		cond->wait_sem = SDL_CreateSemaphore(0);
   23.61 +		cond->wait_done = SDL_CreateSemaphore(0);
   23.62 +		cond->waiting = cond->signals = 0;
   23.63 +		if ( ! cond->lock || ! cond->wait_sem || ! cond->wait_done ) {
   23.64 +			SDL_DestroyCond(cond);
   23.65 +			cond = NULL;
   23.66 +		}
   23.67 +	} else {
   23.68 +		SDL_OutOfMemory();
   23.69 +	}
   23.70 +	return(cond);
   23.71 +}
   23.72 +
   23.73 +/* Destroy a condition variable */
   23.74 +void SDL_DestroyCond(SDL_cond *cond)
   23.75 +{
   23.76 +	if ( cond ) {
   23.77 +		if ( cond->wait_sem ) {
   23.78 +			SDL_DestroySemaphore(cond->wait_sem);
   23.79 +		}
   23.80 +		if ( cond->wait_done ) {
   23.81 +			SDL_DestroySemaphore(cond->wait_done);
   23.82 +		}
   23.83 +		if ( cond->lock ) {
   23.84 +			SDL_DestroyMutex(cond->lock);
   23.85 +		}
   23.86 +		free(cond);
   23.87 +	}
   23.88 +}
   23.89 +
   23.90 +/* Restart one of the threads that are waiting on the condition variable */
   23.91 +int SDL_CondSignal(SDL_cond *cond)
   23.92 +{
   23.93 +	if ( ! cond ) {
   23.94 +		SDL_SetError("Passed a NULL condition variable");
   23.95 +		return -1;
   23.96 +	}
   23.97 +
   23.98 +	/* If there are waiting threads not already signalled, then
   23.99 +	   signal the condition and wait for the thread to respond.
  23.100 +	*/
  23.101 +	SDL_LockMutex(cond->lock);
  23.102 +	if ( cond->waiting > cond->signals ) {
  23.103 +		++cond->signals;
  23.104 +		SDL_SemPost(cond->wait_sem);
  23.105 +		SDL_UnlockMutex(cond->lock);
  23.106 +		SDL_SemWait(cond->wait_done);
  23.107 +	} else {
  23.108 +		SDL_UnlockMutex(cond->lock);
  23.109 +	}
  23.110 +
  23.111 +	return 0;
  23.112 +}
  23.113 +
  23.114 +/* Restart all threads that are waiting on the condition variable */
  23.115 +int SDL_CondBroadcast(SDL_cond *cond)
  23.116 +{
  23.117 +	if ( ! cond ) {
  23.118 +		SDL_SetError("Passed a NULL condition variable");
  23.119 +		return -1;
  23.120 +	}
  23.121 +
  23.122 +	/* If there are waiting threads not already signalled, then
  23.123 +	   signal the condition and wait for the thread to respond.
  23.124 +	*/
  23.125 +	SDL_LockMutex(cond->lock);
  23.126 +	if ( cond->waiting > cond->signals ) {
  23.127 +		int i, num_waiting;
  23.128 +
  23.129 +		num_waiting = (cond->waiting - cond->signals);
  23.130 +		cond->signals = cond->waiting;
  23.131 +		for ( i=0; i<num_waiting; ++i ) {
  23.132 +			SDL_SemPost(cond->wait_sem);
  23.133 +		}
  23.134 +		/* Now all released threads are blocked here, waiting for us.
  23.135 +		   Collect them all (and win fabulous prizes!) :-)
  23.136 +		 */
  23.137 +		SDL_UnlockMutex(cond->lock);
  23.138 +		for ( i=0; i<num_waiting; ++i ) {
  23.139 +			SDL_SemWait(cond->wait_done);
  23.140 +		}
  23.141 +	} else {
  23.142 +		SDL_UnlockMutex(cond->lock);
  23.143 +	}
  23.144 +
  23.145 +	return 0;
  23.146 +}
  23.147 +
  23.148 +/* Wait on the condition variable for at most 'ms' milliseconds.
  23.149 +   The mutex must be locked before entering this function!
  23.150 +   The mutex is unlocked during the wait, and locked again after the wait.
  23.151 +
  23.152 +Typical use:
  23.153 +
  23.154 +Thread A:
  23.155 +	SDL_LockMutex(lock);
  23.156 +	while ( ! condition ) {
  23.157 +		SDL_CondWait(cond);
  23.158 +	}
  23.159 +	SDL_UnlockMutex(lock);
  23.160 +
  23.161 +Thread B:
  23.162 +	SDL_LockMutex(lock);
  23.163 +	...
  23.164 +	condition = true;
  23.165 +	...
  23.166 +	SDL_UnlockMutex(lock);
  23.167 + */
  23.168 +int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
  23.169 +{
  23.170 +	int retval;
  23.171 +
  23.172 +	if ( ! cond ) {
  23.173 +		SDL_SetError("Passed a NULL condition variable");
  23.174 +		return -1;
  23.175 +	}
  23.176 +
  23.177 +	/* Obtain the protection mutex, and increment the number of waiters.
  23.178 +	   This allows the signal mechanism to only perform a signal if there
  23.179 +	   are waiting threads.
  23.180 +	 */
  23.181 +	SDL_LockMutex(cond->lock);
  23.182 +	++cond->waiting;
  23.183 +	SDL_UnlockMutex(cond->lock);
  23.184 +
  23.185 +	/* Unlock the mutex, as is required by condition variable semantics */
  23.186 +	SDL_UnlockMutex(mutex);
  23.187 +
  23.188 +	/* Wait for a signal */
  23.189 +	if ( ms == SDL_MUTEX_MAXWAIT ) {
  23.190 +		retval = SDL_SemWait(cond->wait_sem);
  23.191 +	} else {
  23.192 +		retval = SDL_SemWaitTimeout(cond->wait_sem, ms);
  23.193 +	}
  23.194 +
  23.195 +	/* Let the signaler know we have completed the wait, otherwise
  23.196 +           the signaler can race ahead and get the condition semaphore
  23.197 +           if we are stopped between the mutex unlock and semaphore wait,
  23.198 +           giving a deadlock.  See the following URL for details:
  23.199 +        http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html
  23.200 +	*/
  23.201 +	SDL_LockMutex(cond->lock);
  23.202 +	if ( cond->signals > 0 ) {
  23.203 +		/* If we timed out, we need to eat a condition signal */
  23.204 +		if ( retval > 0 ) {
  23.205 +			SDL_SemWait(cond->wait_sem);
  23.206 +		}
  23.207 +		/* We always notify the signal thread that we are done */
  23.208 +		SDL_SemPost(cond->wait_done);
  23.209 +
  23.210 +		/* Signal handshake complete */
  23.211 +		--cond->signals;
  23.212 +	}
  23.213 +	--cond->waiting;
  23.214 +	SDL_UnlockMutex(cond->lock);
  23.215 +
  23.216 +	/* Lock the mutex, as is required by condition variable semantics */
  23.217 +	SDL_LockMutex(mutex);
  23.218 +
  23.219 +	return retval;
  23.220 +}
  23.221 +
  23.222 +/* Wait on the condition variable forever */
  23.223 +int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
  23.224 +{
  23.225 +	return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
  23.226 +}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/src/thread/dc/SDL_syscond_c.h	Sat Oct 05 16:50:56 2002 +0000
    24.3 @@ -0,0 +1,27 @@
    24.4 +/*
    24.5 +    SDL - Simple DirectMedia Layer
    24.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    24.7 +
    24.8 +    This library is free software; you can redistribute it and/or
    24.9 +    modify it under the terms of the GNU Library General Public
   24.10 +    License as published by the Free Software Foundation; either
   24.11 +    version 2 of the License, or (at your option) any later version.
   24.12 +
   24.13 +    This library is distributed in the hope that it will be useful,
   24.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   24.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   24.16 +    Library General Public License for more details.
   24.17 +
   24.18 +    You should have received a copy of the GNU Library General Public
   24.19 +    License along with this library; if not, write to the Free
   24.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24.21 +
   24.22 +    Sam Lantinga
   24.23 +    slouken@libsdl.org
   24.24 +*/
   24.25 +
   24.26 +#ifdef SAVE_RCSID
   24.27 +static char rcsid =
   24.28 + "@(#) $Id$";
   24.29 +#endif
   24.30 +
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/src/thread/dc/SDL_sysmutex.c	Sat Oct 05 16:50:56 2002 +0000
    25.3 @@ -0,0 +1,135 @@
    25.4 +/*
    25.5 +    SDL - Simple DirectMedia Layer
    25.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    25.7 +
    25.8 +    This library is free software; you can redistribute it and/or
    25.9 +    modify it under the terms of the GNU Library General Public
   25.10 +    License as published by the Free Software Foundation; either
   25.11 +    version 2 of the License, or (at your option) any later version.
   25.12 +
   25.13 +    This library is distributed in the hope that it will be useful,
   25.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   25.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   25.16 +    Library General Public License for more details.
   25.17 +
   25.18 +    You should have received a copy of the GNU Library General Public
   25.19 +    License along with this library; if not, write to the Free
   25.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   25.21 +
   25.22 +    BERO
   25.23 +    bero@geocities.co.jp
   25.24 +
   25.25 +    based on generic/SDL_sysmutex.c
   25.26 +
   25.27 +    Sam Lantinga
   25.28 +    slouken@libsdl.org
   25.29 +*/
   25.30 +
   25.31 +#ifdef SAVE_RCSID
   25.32 +static char rcsid =
   25.33 + "@(#) $Id$";
   25.34 +#endif
   25.35 +
   25.36 +/* An implementation of mutexes using semaphores */
   25.37 +
   25.38 +#include <stdio.h>
   25.39 +#include <stdlib.h>
   25.40 +
   25.41 +#include "SDL_error.h"
   25.42 +#include "SDL_thread.h"
   25.43 +#include "SDL_systhread_c.h"
   25.44 +
   25.45 +#include <arch/spinlock.h>
   25.46 +
   25.47 +struct SDL_mutex {
   25.48 +	int recursive;
   25.49 +	Uint32 owner;
   25.50 +	spinlock_t mutex;
   25.51 +};
   25.52 +
   25.53 +/* Create a mutex */
   25.54 +SDL_mutex *SDL_CreateMutex(void)
   25.55 +{
   25.56 +	SDL_mutex *mutex;
   25.57 +
   25.58 +	/* Allocate mutex memory */
   25.59 +	mutex = (SDL_mutex *)malloc(sizeof(*mutex));
   25.60 +	if ( mutex ) {
   25.61 +		spinlock_init(&mutex->mutex);
   25.62 +		mutex->recursive = 0;
   25.63 +		mutex->owner = 0;
   25.64 +	} else {
   25.65 +		SDL_OutOfMemory();
   25.66 +	}
   25.67 +	return mutex;
   25.68 +}
   25.69 +
   25.70 +/* Free the mutex */
   25.71 +void SDL_DestroyMutex(SDL_mutex *mutex)
   25.72 +{
   25.73 +	if ( mutex ) {
   25.74 +		free(mutex);
   25.75 +	}
   25.76 +}
   25.77 +
   25.78 +/* Lock the semaphore */
   25.79 +int SDL_mutexP(SDL_mutex *mutex)
   25.80 +{
   25.81 +#ifdef DISABLE_THREADS
   25.82 +	return 0;
   25.83 +#else
   25.84 +	Uint32 this_thread;
   25.85 +
   25.86 +	if ( mutex == NULL ) {
   25.87 +		SDL_SetError("Passed a NULL mutex");
   25.88 +		return -1;
   25.89 +	}
   25.90 +
   25.91 +	this_thread = SDL_ThreadID();
   25.92 +	if ( mutex->owner == this_thread ) {
   25.93 +		++mutex->recursive;
   25.94 +	} else {
   25.95 +		/* The order of operations is important.
   25.96 +		   We set the locking thread id after we obtain the lock
   25.97 +		   so unlocks from other threads will fail.
   25.98 +		*/
   25.99 +		spinlock_lock(&mutex->mutex);
  25.100 +		mutex->owner = this_thread;
  25.101 +		mutex->recursive = 0;
  25.102 +	}
  25.103 +
  25.104 +	return 0;
  25.105 +#endif /* DISABLE_THREADS */
  25.106 +}
  25.107 +
  25.108 +/* Unlock the mutex */
  25.109 +int SDL_mutexV(SDL_mutex *mutex)
  25.110 +{
  25.111 +#ifdef DISABLE_THREADS
  25.112 +	return 0;
  25.113 +#else
  25.114 +	if ( mutex == NULL ) {
  25.115 +		SDL_SetError("Passed a NULL mutex");
  25.116 +		return -1;
  25.117 +	}
  25.118 +
  25.119 +	/* If we don't own the mutex, we can't unlock it */
  25.120 +	if ( SDL_ThreadID() != mutex->owner ) {
  25.121 +		SDL_SetError("mutex not owned by this thread");
  25.122 +		return -1;
  25.123 +	}
  25.124 +
  25.125 +	if ( mutex->recursive ) {
  25.126 +		--mutex->recursive;
  25.127 +	} else {
  25.128 +		/* The order of operations is important.
  25.129 +		   First reset the owner so another thread doesn't lock
  25.130 +		   the mutex and set the ownership before we reset it,
  25.131 +		   then release the lock semaphore.
  25.132 +		 */
  25.133 +		mutex->owner = 0;
  25.134 +		spinlock_unlock(&mutex->mutex);
  25.135 +	}
  25.136 +	return 0;
  25.137 +#endif /* DISABLE_THREADS */
  25.138 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/src/thread/dc/SDL_sysmutex_c.h	Sat Oct 05 16:50:56 2002 +0000
    26.3 @@ -0,0 +1,27 @@
    26.4 +/*
    26.5 +    SDL - Simple DirectMedia Layer
    26.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    26.7 +
    26.8 +    This library is free software; you can redistribute it and/or
    26.9 +    modify it under the terms of the GNU Library General Public
   26.10 +    License as published by the Free Software Foundation; either
   26.11 +    version 2 of the License, or (at your option) any later version.
   26.12 +
   26.13 +    This library is distributed in the hope that it will be useful,
   26.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   26.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   26.16 +    Library General Public License for more details.
   26.17 +
   26.18 +    You should have received a copy of the GNU Library General Public
   26.19 +    License along with this library; if not, write to the Free
   26.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   26.21 +
   26.22 +    Sam Lantinga
   26.23 +    slouken@libsdl.org
   26.24 +*/
   26.25 +
   26.26 +#ifdef SAVE_RCSID
   26.27 +static char rcsid =
   26.28 + "@(#) $Id$";
   26.29 +#endif
   26.30 +
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/src/thread/dc/SDL_syssem.c	Sat Oct 05 16:50:56 2002 +0000
    27.3 @@ -0,0 +1,180 @@
    27.4 +/*
    27.5 +    SDL - Simple DirectMedia Layer
    27.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    27.7 +
    27.8 +    This library is free software; you can redistribute it and/or
    27.9 +    modify it under the terms of the GNU Library General Public
   27.10 +    License as published by the Free Software Foundation; either
   27.11 +    version 2 of the License, or (at your option) any later version.
   27.12 +
   27.13 +    This library is distributed in the hope that it will be useful,
   27.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   27.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   27.16 +    Library General Public License for more details.
   27.17 +
   27.18 +    You should have received a copy of the GNU Library General Public
   27.19 +    License along with this library; if not, write to the Free
   27.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   27.21 +
   27.22 +    BERO
   27.23 +    bero@geocities.co.jp
   27.24 +
   27.25 +    based on generic/SDL_syssem.c
   27.26 +
   27.27 +    Sam Lantinga
   27.28 +    slouken@libsdl.org
   27.29 +*/
   27.30 +
   27.31 +#ifdef SAVE_RCSID
   27.32 +static char rcsid =
   27.33 + "@(#) $Id$";
   27.34 +#endif
   27.35 +
   27.36 +/* An implementation of semaphores using mutexes and condition variables */
   27.37 +
   27.38 +#include <stdlib.h>
   27.39 +
   27.40 +#include "SDL_error.h"
   27.41 +#include "SDL_timer.h"
   27.42 +#include "SDL_thread.h"
   27.43 +#include "SDL_systhread_c.h"
   27.44 +
   27.45 +
   27.46 +#ifdef DISABLE_THREADS
   27.47 +
   27.48 +SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
   27.49 +{
   27.50 +	SDL_SetError("SDL not configured with thread support");
   27.51 +	return (SDL_sem *)0;
   27.52 +}
   27.53 +
   27.54 +void SDL_DestroySemaphore(SDL_sem *sem)
   27.55 +{
   27.56 +	return;
   27.57 +}
   27.58 +
   27.59 +int SDL_SemTryWait(SDL_sem *sem)
   27.60 +{
   27.61 +	SDL_SetError("SDL not configured with thread support");
   27.62 +	return -1;
   27.63 +}
   27.64 +
   27.65 +int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
   27.66 +{
   27.67 +	SDL_SetError("SDL not configured with thread support");
   27.68 +	return -1;
   27.69 +}
   27.70 +
   27.71 +int SDL_SemWait(SDL_sem *sem)
   27.72 +{
   27.73 +	SDL_SetError("SDL not configured with thread support");
   27.74 +	return -1;
   27.75 +}
   27.76 +
   27.77 +Uint32 SDL_SemValue(SDL_sem *sem)
   27.78 +{
   27.79 +	return 0;
   27.80 +}
   27.81 +
   27.82 +int SDL_SemPost(SDL_sem *sem)
   27.83 +{
   27.84 +	SDL_SetError("SDL not configured with thread support");
   27.85 +	return -1;
   27.86 +}
   27.87 +
   27.88 +#else
   27.89 +
   27.90 +#include <kos/sem.h>
   27.91 +
   27.92 +struct SDL_semaphore
   27.93 +{
   27.94 +	semaphore_t sem;
   27.95 +};
   27.96 +
   27.97 +SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
   27.98 +{
   27.99 +	return (SDL_sem *)sem_create(initial_value);
  27.100 +}
  27.101 +
  27.102 +/* WARNING:
  27.103 +   You cannot call this function when another thread is using the semaphore.
  27.104 +*/
  27.105 +void SDL_DestroySemaphore(SDL_sem *sem)
  27.106 +{
  27.107 +	if ( ! sem ) {
  27.108 +		SDL_SetError("Passed a NULL semaphore");
  27.109 +		return;
  27.110 +	}
  27.111 +
  27.112 +	sem_destroy(&sem->sem);
  27.113 +}
  27.114 +
  27.115 +int SDL_SemTryWait(SDL_sem *sem)
  27.116 +{
  27.117 +	int retval;
  27.118 +
  27.119 +	if ( ! sem ) {
  27.120 +		SDL_SetError("Passed a NULL semaphore");
  27.121 +		return -1;
  27.122 +	}
  27.123 +
  27.124 +	retval = sem_trywait(&sem->sem);
  27.125 +	if (retval==0) return 0;
  27.126 +	else return SDL_MUTEX_TIMEDOUT;
  27.127 +
  27.128 +	return retval;
  27.129 +}
  27.130 +
  27.131 +int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
  27.132 +{
  27.133 +	int retval;
  27.134 +
  27.135 +	if ( ! sem ) {
  27.136 +		SDL_SetError("Passed a NULL semaphore");
  27.137 +		return -1;
  27.138 +	}
  27.139 +
  27.140 +	/* A timeout of 0 is an easy case */
  27.141 +	if ( timeout == 0 ) {
  27.142 +		return SDL_SemTryWait(sem);
  27.143 +	}
  27.144 +
  27.145 +	retval = sem_wait_timed(&sem->sem,timeout);
  27.146 +	if (retval==-1) retval= SDL_MUTEX_TIMEDOUT;
  27.147 +
  27.148 +	return retval;
  27.149 +}
  27.150 +
  27.151 +int SDL_SemWait(SDL_sem *sem)
  27.152 +{
  27.153 +	if ( ! sem ) {
  27.154 +		SDL_SetError("Passed a NULL semaphore");
  27.155 +		return -1;
  27.156 +	}
  27.157 +
  27.158 +	sem_wait(&sem->sem);
  27.159 +	return 0;
  27.160 +}
  27.161 +
  27.162 +Uint32 SDL_SemValue(SDL_sem *sem)
  27.163 +{
  27.164 +	if ( ! sem ) {
  27.165 +		SDL_SetError("Passed a NULL semaphore");
  27.166 +		return -1;
  27.167 +	}
  27.168 +
  27.169 +	return sem_count(&sem->sem);
  27.170 +}
  27.171 +
  27.172 +int SDL_SemPost(SDL_sem *sem)
  27.173 +{
  27.174 +	if ( ! sem ) {
  27.175 +		SDL_SetError("Passed a NULL semaphore");
  27.176 +		return -1;
  27.177 +	}
  27.178 +
  27.179 +	sem_signal(&sem->sem);
  27.180 +	return 0;
  27.181 +}
  27.182 +
  27.183 +#endif /* DISABLE_THREADS */
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/src/thread/dc/SDL_syssem_c.h	Sat Oct 05 16:50:56 2002 +0000
    28.3 @@ -0,0 +1,27 @@
    28.4 +/*
    28.5 +    SDL - Simple DirectMedia Layer
    28.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    28.7 +
    28.8 +    This library is free software; you can redistribute it and/or
    28.9 +    modify it under the terms of the GNU Library General Public
   28.10 +    License as published by the Free Software Foundation; either
   28.11 +    version 2 of the License, or (at your option) any later version.
   28.12 +
   28.13 +    This library is distributed in the hope that it will be useful,
   28.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   28.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   28.16 +    Library General Public License for more details.
   28.17 +
   28.18 +    You should have received a copy of the GNU Library General Public
   28.19 +    License along with this library; if not, write to the Free
   28.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   28.21 +
   28.22 +    Sam Lantinga
   28.23 +    slouken@libsdl.org
   28.24 +*/
   28.25 +
   28.26 +#ifdef SAVE_RCSID
   28.27 +static char rcsid =
   28.28 + "@(#) $Id$";
   28.29 +#endif
   28.30 +
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/src/thread/dc/SDL_systhread.c	Sat Oct 05 16:50:56 2002 +0000
    29.3 @@ -0,0 +1,98 @@
    29.4 +/*
    29.5 +    SDL - Simple DirectMedia Layer
    29.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    29.7 +
    29.8 +    This library is free software; you can redistribute it and/or
    29.9 +    modify it under the terms of the GNU Library General Public
   29.10 +    License as published by the Free Software Foundation; either
   29.11 +    version 2 of the License, or (at your option) any later version.
   29.12 +
   29.13 +    This library is distributed in the hope that it will be useful,
   29.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   29.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   29.16 +    Library General Public License for more details.
   29.17 +
   29.18 +    You should have received a copy of the GNU Library General Public
   29.19 +    License along with this library; if not, write to the Free
   29.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   29.21 +
   29.22 +    BERO
   29.23 +    bero@geocities.co.jp
   29.24 +
   29.25 +    based on generic/SDL_thread.c
   29.26 +
   29.27 +    Sam Lantinga
   29.28 +    slouken@libsdl.org
   29.29 +*/
   29.30 +
   29.31 +#ifdef SAVE_RCSID
   29.32 +static char rcsid =
   29.33 + "@(#) $Id$";
   29.34 +#endif
   29.35 +
   29.36 +/* Thread management routines for SDL */
   29.37 +
   29.38 +#include "SDL_error.h"
   29.39 +#include "SDL_thread.h"
   29.40 +#include "SDL_systhread.h"
   29.41 +
   29.42 +#include <kos/thread.h>
   29.43 +
   29.44 +#ifdef	DISABLE_THREADS
   29.45 +int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
   29.46 +{
   29.47 +	SDL_SetError("Threads are not supported on this platform");
   29.48 +	return(-1);
   29.49 +}
   29.50 +
   29.51 +void SDL_SYS_SetupThread(void)
   29.52 +{
   29.53 +	return;
   29.54 +}
   29.55 +
   29.56 +Uint32 SDL_ThreadID(void)
   29.57 +{
   29.58 +	return(0);
   29.59 +}
   29.60 +
   29.61 +void SDL_SYS_WaitThread(SDL_Thread *thread)
   29.62 +{
   29.63 +	return;
   29.64 +}
   29.65 +
   29.66 +void SDL_SYS_KillThread(SDL_Thread *thread)
   29.67 +{
   29.68 +	return;
   29.69 +}
   29.70 +
   29.71 +#else
   29.72 +int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
   29.73 +{
   29.74 +	thread->handle = thd_create(SDL_RunThread,args);
   29.75 +	if (thread->handle == NULL) {
   29.76 +		SDL_SetError("Not enough resources to create thread");
   29.77 +		return(-1);
   29.78 +	}
   29.79 +	return(0);
   29.80 +}
   29.81 +
   29.82 +void SDL_SYS_SetupThread(void)
   29.83 +{
   29.84 +	return;
   29.85 +}
   29.86 +
   29.87 +Uint32 SDL_ThreadID(void)
   29.88 +{
   29.89 +	return (Uint32)thd_get_current();
   29.90 +}
   29.91 +
   29.92 +void SDL_SYS_WaitThread(SDL_Thread *thread)
   29.93 +{
   29.94 +	thd_wait(thread->handle);
   29.95 +}
   29.96 +
   29.97 +void SDL_SYS_KillThread(SDL_Thread *thread)
   29.98 +{
   29.99 +	thd_destroy(thread->handle);
  29.100 +}
  29.101 +#endif
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/src/thread/dc/SDL_systhread_c.h	Sat Oct 05 16:50:56 2002 +0000
    30.3 @@ -0,0 +1,29 @@
    30.4 +/*
    30.5 +    SDL - Simple DirectMedia Layer
    30.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    30.7 +
    30.8 +    This library is free software; you can redistribute it and/or
    30.9 +    modify it under the terms of the GNU Library General Public
   30.10 +    License as published by the Free Software Foundation; either
   30.11 +    version 2 of the License, or (at your option) any later version.
   30.12 +
   30.13 +    This library is distributed in the hope that it will be useful,
   30.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   30.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   30.16 +    Library General Public License for more details.
   30.17 +
   30.18 +    You should have received a copy of the GNU Library General Public
   30.19 +    License along with this library; if not, write to the Free
   30.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   30.21 +
   30.22 +    Sam Lantinga
   30.23 +    slouken@libsdl.org
   30.24 +*/
   30.25 +
   30.26 +/* Stub until we implement threads on this platform */
   30.27 +typedef struct kthread* SYS_ThreadHandle;
   30.28 +/*
   30.29 +#ifndef DISABLE_THREADS
   30.30 +#define DISABLE_THREADS
   30.31 +#endif
   30.32 +*/
    31.1 --- a/src/timer/Makefile.am	Sat Oct 05 16:27:56 2002 +0000
    31.2 +++ b/src/timer/Makefile.am	Sat Oct 05 16:50:56 2002 +0000
    31.3 @@ -5,6 +5,7 @@
    31.4  
    31.5  ARCH_SUBDIRS = $(srcdir)/amigaos \
    31.6                 $(srcdir)/beos \
    31.7 +               $(srcdir)/dc \
    31.8                 $(srcdir)/epoc \
    31.9                 $(srcdir)/linux \
   31.10                 $(srcdir)/macos \
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/src/timer/dc/SDL_systimer.c	Sat Oct 05 16:50:56 2002 +0000
    32.3 @@ -0,0 +1,106 @@
    32.4 +/*
    32.5 +    SDL - Simple DirectMedia Layer
    32.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    32.7 +
    32.8 +    This library is free software; you can redistribute it and/or
    32.9 +    modify it under the terms of the GNU Library General Public
   32.10 +    License as published by the Free Software Foundation; either
   32.11 +    version 2 of the License, or (at your option) any later version.
   32.12 +
   32.13 +    This library is distributed in the hope that it will be useful,
   32.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   32.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   32.16 +    Library General Public License for more details.
   32.17 +
   32.18 +    You should have received a copy of the GNU Library General Public
   32.19 +    License along with this library; if not, write to the Free
   32.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   32.21 +
   32.22 +    BERO
   32.23 +    bero@geocities.co.jp
   32.24 +
   32.25 +    based on win32/SDL_systimer.c
   32.26 +
   32.27 +    Sam Lantinga
   32.28 +    slouken@libsdl.org
   32.29 +*/
   32.30 +
   32.31 +#ifdef SAVE_RCSID
   32.32 +static char rcsid =
   32.33 + "@(#) $Id$";
   32.34 +#endif
   32.35 +
   32.36 +#include <kos.h>
   32.37 +
   32.38 +#include "SDL_thread.h"
   32.39 +#include "SDL_timer.h"
   32.40 +#include "SDL_error.h"
   32.41 +#include "SDL_timer_c.h"
   32.42 +
   32.43 +static unsigned start;
   32.44 +
   32.45 +/* 
   32.46 +	jif =  ms * HZ /1000
   32.47 +	ms  = jif * 1000/HZ
   32.48 +*/
   32.49 +
   32.50 +void SDL_StartTicks(void)
   32.51 +{
   32.52 +	/* Set first ticks value */
   32.53 +	start = jiffies;
   32.54 +}
   32.55 +
   32.56 +Uint32 SDL_GetTicks(void)
   32.57 +{
   32.58 +	return((jiffies-start)*1000/HZ);
   32.59 +}
   32.60 +
   32.61 +void SDL_Delay(Uint32 ms)
   32.62 +{
   32.63 +	thd_sleep(ms);
   32.64 +}
   32.65 +
   32.66 +/* Data to handle a single periodic alarm */
   32.67 +static int timer_alive = 0;
   32.68 +static SDL_Thread *timer = NULL;
   32.69 +
   32.70 +static int RunTimer(void *unused)
   32.71 +{
   32.72 +	while ( timer_alive ) {
   32.73 +		if ( SDL_timer_running ) {
   32.74 +			SDL_ThreadedTimerCheck();
   32.75 +		}
   32.76 +		SDL_Delay(10);
   32.77 +	}
   32.78 +	return(0);
   32.79 +}
   32.80 +
   32.81 +/* This is only called if the event thread is not running */
   32.82 +int SDL_SYS_TimerInit(void)
   32.83 +{
   32.84 +	timer_alive = 1;
   32.85 +	timer = SDL_CreateThread(RunTimer, NULL);
   32.86 +	if ( timer == NULL )
   32.87 +		return(-1);
   32.88 +	return(SDL_SetTimerThreaded(1));
   32.89 +}
   32.90 +
   32.91 +void SDL_SYS_TimerQuit(void)
   32.92 +{
   32.93 +	timer_alive = 0;
   32.94 +	if ( timer ) {
   32.95 +		SDL_WaitThread(timer, NULL);
   32.96 +		timer = NULL;
   32.97 +	}
   32.98 +}
   32.99 +
  32.100 +int SDL_SYS_StartTimer(void)
  32.101 +{
  32.102 +	SDL_SetError("Internal logic error: DC uses threaded timer");
  32.103 +	return(-1);
  32.104 +}
  32.105 +
  32.106 +void SDL_SYS_StopTimer(void)
  32.107 +{
  32.108 +	return;
  32.109 +}
    33.1 --- a/src/video/Makefile.am	Sat Oct 05 16:27:56 2002 +0000
    33.2 +++ b/src/video/Makefile.am	Sat Oct 05 16:50:56 2002 +0000
    33.3 @@ -9,7 +9,7 @@
    33.4                 wincommon windib windx5 \
    33.5                 maccommon macdsp macrom quartz \
    33.6                 bwindow ps2gs photon cybergfx epoc picogui \
    33.7 -               ataricommon xbios gem XFree86
    33.8 +               ataricommon xbios gem dc XFree86
    33.9  
   33.10  DRIVERS = @VIDEO_DRIVERS@
   33.11  
    34.1 --- a/src/video/SDL_sysvideo.h	Sat Oct 05 16:27:56 2002 +0000
    34.2 +++ b/src/video/SDL_sysvideo.h	Sat Oct 05 16:50:56 2002 +0000
    34.3 @@ -406,6 +406,9 @@
    34.4  #ifdef ENABLE_PICOGUI
    34.5  extern VideoBootStrap PG_bootstrap;
    34.6  #endif
    34.7 +#ifdef ENABLE_DC
    34.8 +extern VideoBootStrap DC_bootstrap;
    34.9 +#endif
   34.10  /* This is the current video device */
   34.11  extern SDL_VideoDevice *current_video;
   34.12  
    35.1 --- a/src/video/SDL_video.c	Sat Oct 05 16:27:56 2002 +0000
    35.2 +++ b/src/video/SDL_video.c	Sat Oct 05 16:50:56 2002 +0000
    35.3 @@ -117,6 +117,9 @@
    35.4  #ifdef ENABLE_PICOGUI
    35.5  	&PG_bootstrap,
    35.6  #endif
    35.7 +#ifdef ENABLE_DC
    35.8 +	&DC_bootstrap,
    35.9 +#endif
   35.10  	NULL
   35.11  };
   35.12  
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/src/video/dc/.cvsignore	Sat Oct 05 16:50:56 2002 +0000
    36.3 @@ -0,0 +1,6 @@
    36.4 +Makefile.in
    36.5 +Makefile
    36.6 +.libs
    36.7 +*.o
    36.8 +*.lo
    36.9 +*.la
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/src/video/dc/Makefile.am	Sat Oct 05 16:50:56 2002 +0000
    37.3 @@ -0,0 +1,14 @@
    37.4 +
    37.5 +## Makefile.am for SDL using the Dreamcast video driver
    37.6 +
    37.7 +noinst_LTLIBRARIES = libvideo_dc.la
    37.8 +libvideo_dc_la_SOURCES = $(SRCS)
    37.9 +
   37.10 +# The SDL Dreamcast video driver sources
   37.11 +SRCS = 				\
   37.12 +	SDL_dcevents.c		\
   37.13 +	SDL_dcevents_c.h	\
   37.14 +	SDL_dcmouse.c		\
   37.15 +	SDL_dcmouse_c.h		\
   37.16 +	SDL_dcvideo.c		\
   37.17 +	SDL_dcvideo.h
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/src/video/dc/SDL_dcevents.c	Sat Oct 05 16:50:56 2002 +0000
    38.3 @@ -0,0 +1,164 @@
    38.4 +/*
    38.5 +    SDL - Simple DirectMedia Layer
    38.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    38.7 +
    38.8 +    This library is free software; you can redistribute it and/or
    38.9 +    modify it under the terms of the GNU Library General Public
   38.10 +    License as published by the Free Software Foundation; either
   38.11 +    version 2 of the License, or (at your option) any later version.
   38.12 +
   38.13 +    This library is distributed in the hope that it will be useful,
   38.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   38.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   38.16 +    Library General Public License for more details.
   38.17 +
   38.18 +    You should have received a copy of the GNU Library General Public
   38.19 +    License along with this library; if not, write to the Free
   38.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   38.21 +
   38.22 +    BERO
   38.23 +    bero@geocities.co.jp
   38.24 +
   38.25 +    based on SDL_nullevents.c by
   38.26 +
   38.27 +    Sam Lantinga
   38.28 +    slouken@libsdl.org
   38.29 +*/
   38.30 +
   38.31 +#ifdef SAVE_RCSID
   38.32 +static char rcsid =
   38.33 + "@(#) $Id$";
   38.34 +#endif
   38.35 +
   38.36 +/* Being a null driver, there's no event stream. We just define stubs for
   38.37 +   most of the API. */
   38.38 +
   38.39 +#include "SDL.h"
   38.40 +#include "SDL_sysevents.h"
   38.41 +#include "SDL_events_c.h"
   38.42 +#include "SDL_dcvideo.h"
   38.43 +#include "SDL_dcevents_c.h"
   38.44 +
   38.45 +#include <dc/maple.h>
   38.46 +#include <dc/maple/mouse.h>
   38.47 +#include <dc/maple/keyboard.h>
   38.48 +
   38.49 +const static unsigned short sdl_key[]= {
   38.50 +	/*0*/	0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
   38.51 +		'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
   38.52 +		'u', 'v', 'w', 'x', 'y', 'z',
   38.53 +	/*1e*/	'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
   38.54 +	/*28*/	SDLK_RETURN, SDLK_ESCAPE, SDLK_BACKSPACE, SDLK_TAB, SDLK_SPACE, SDLK_MINUS, SDLK_PLUS, SDLK_LEFTBRACKET, 
   38.55 +	SDLK_RIGHTBRACKET, SDLK_BACKSLASH , 0, SDLK_SEMICOLON, SDLK_QUOTE,
   38.56 +	/*35*/	'~', SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH, SDLK_CAPSLOCK, 
   38.57 +	SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12,
   38.58 +	/*46*/	SDLK_PRINT, SDLK_SCROLLOCK, SDLK_PAUSE, SDLK_INSERT, SDLK_HOME, SDLK_PAGEUP, SDLK_DELETE, SDLK_END, SDLK_PAGEDOWN, SDLK_RIGHT, SDLK_LEFT, SDLK_DOWN, SDLK_UP,
   38.59 +	/*53*/	SDLK_NUMLOCK, SDLK_KP_DIVIDE, SDLK_KP_MULTIPLY, SDLK_KP_MINUS, SDLK_KP_PLUS, SDLK_KP_ENTER, 
   38.60 +	SDLK_KP1, SDLK_KP2, SDLK_KP3, SDLK_KP4, SDLK_KP5, SDLK_KP6,
   38.61 +	/*5f*/	SDLK_KP7, SDLK_KP8, SDLK_KP9, SDLK_KP0, SDLK_KP_PERIOD, 0 /* S3 */
   38.62 +};
   38.63 +
   38.64 +const static unsigned short sdl_shift[] = {
   38.65 +	SDLK_LCTRL,SDLK_LSHIFT,SDLK_LALT,0 /* S1 */,
   38.66 +	SDLK_RCTRL,SDLK_RSHIFT,SDLK_RALT,0 /* S2 */,
   38.67 +};
   38.68 +
   38.69 +#define	MOUSE_WHEELUP 	(1<<4)
   38.70 +#define	MOUSE_WHEELDOWN	(1<<5)
   38.71 +
   38.72 +static void mouse_update(void)
   38.73 +{
   38.74 +const	static char sdl_mousebtn[] = {
   38.75 +	MOUSE_LEFTBUTTON,
   38.76 +	MOUSE_RIGHTBUTTON,
   38.77 +	MOUSE_SIDEBUTTON,
   38.78 +	MOUSE_WHEELUP,
   38.79 +	MOUSE_WHEELDOWN
   38.80 +};
   38.81 +
   38.82 +	uint8 addr;
   38.83 +	mouse_cond_t	cond;
   38.84 +
   38.85 +	static int prev_buttons;
   38.86 +	int buttons,changed;
   38.87 +	int i;
   38.88 +
   38.89 +	if ((addr = maple_first_mouse())==0 || mouse_get_cond(addr, &cond)<0) return;
   38.90 +
   38.91 +	buttons = cond.buttons^0xff;
   38.92 +	if (cond.dz<0) buttons|=MOUSE_WHEELUP;
   38.93 +	if (cond.dz>0) buttons|=MOUSE_WHEELDOWN;
   38.94 +
   38.95 +	if (cond.dx||cond.dy) SDL_PrivateMouseMotion(0,1,cond.dx,cond.dy);
   38.96 +
   38.97 +	changed = buttons^prev_buttons;
   38.98 +	for(i=0;i<sizeof(sdl_mousebtn);i++) {
   38.99 +		if (changed & sdl_mousebtn[i]) {
  38.100 +			SDL_PrivateMouseButton((buttons & sdl_mousebtn[i])?SDL_PRESSED:SDL_RELEASED,i,0,0);
  38.101 +		}
  38.102 +	}
  38.103 +	prev_buttons = buttons;
  38.104 +}
  38.105 +
  38.106 +static void keyboard_update(void)
  38.107 +{
  38.108 +	static kbd_state_t	old_state;
  38.109 +	static uint8 old_addr;
  38.110 +
  38.111 +	kbd_state_t	*state;
  38.112 +	uint8	addr;
  38.113 +	int	port,unit;
  38.114 +
  38.115 +	int shiftkeys;
  38.116 +	SDL_keysym keysym;
  38.117 +
  38.118 +	int i;
  38.119 +
  38.120 +	addr = maple_first_kb();
  38.121 +
  38.122 +	if (addr==0) return;
  38.123 +
  38.124 +	if (addr!=old_addr) {
  38.125 +		old_addr = addr;
  38.126 +		memset(&old_state,0,sizeof(old_state));
  38.127 +	}
  38.128 +
  38.129 +	maple_raddr(addr,&port,&unit);
  38.130 +
  38.131 +	state = kbd_get_state(port,unit);
  38.132 +	if (!state) return;
  38.133 +
  38.134 +	shiftkeys = state->shift_keys ^ old_state.shift_keys;
  38.135 +	for(i=0;i<sizeof(sdl_shift);i++) {
  38.136 +		if ((shiftkeys>>i)&1) {
  38.137 +			keysym.sym = sdl_shift[i];
  38.138 +			SDL_PrivateKeyboard(((state->shift_keys>>i)&1)?SDL_PRESSED:SDL_RELEASED,&keysym);
  38.139 +		}
  38.140 +	}
  38.141 +
  38.142 +	for(i=0;i<sizeof(sdl_key);i++) {
  38.143 +		if (state->matrix[i]!=old_state.matrix[i]) {
  38.144 +			int key = sdl_key[i];
  38.145 +			if (key) {
  38.146 +				keysym.sym = key;
  38.147 +				SDL_PrivateKeyboard(state->matrix[i]?SDL_PRESSED:SDL_RELEASED,&keysym);
  38.148 +			}
  38.149 +		}
  38.150 +	}
  38.151 +
  38.152 +	old_state = *state;
  38.153 +}
  38.154 +
  38.155 +void DC_PumpEvents(_THIS)
  38.156 +{
  38.157 +	keyboard_update();
  38.158 +	mouse_update();
  38.159 +}
  38.160 +
  38.161 +void DC_InitOSKeymap(_THIS)
  38.162 +{
  38.163 +	/* do nothing. */
  38.164 +}
  38.165 +
  38.166 +/* end of SDL_dcevents.c ... */
  38.167 +
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/src/video/dc/SDL_dcevents_c.h	Sat Oct 05 16:50:56 2002 +0000
    39.3 @@ -0,0 +1,42 @@
    39.4 +/*
    39.5 +    SDL - Simple DirectMedia Layer
    39.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    39.7 +
    39.8 +    This library is free software; you can redistribute it and/or
    39.9 +    modify it under the terms of the GNU Library General Public
   39.10 +    License as published by the Free Software Foundation; either
   39.11 +    version 2 of the License, or (at your option) any later version.
   39.12 +
   39.13 +    This library is distributed in the hope that it will be useful,
   39.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   39.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   39.16 +    Library General Public License for more details.
   39.17 +
   39.18 +    You should have received a copy of the GNU Library General Public
   39.19 +    License along with this library; if not, write to the Free
   39.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   39.21 +
   39.22 +    BERO
   39.23 +    bero@geocities.co.jp
   39.24 +
   39.25 +    based on SDL_nullevents.h by
   39.26 +
   39.27 +    Sam Lantinga
   39.28 +    slouken@libsdl.org
   39.29 +*/
   39.30 +
   39.31 +#ifdef SAVE_RCSID
   39.32 +static char rcsid =
   39.33 + "@(#) $Id$";
   39.34 +#endif
   39.35 +
   39.36 +#include "SDL_dcvideo.h"
   39.37 +
   39.38 +/* Variables and functions exported by SDL_sysevents.c to other parts 
   39.39 +   of the native video subsystem (SDL_sysvideo.c)
   39.40 +*/
   39.41 +extern void DC_InitOSKeymap(_THIS);
   39.42 +extern void DC_PumpEvents(_THIS);
   39.43 +
   39.44 +/* end of SDL_dcevents_c.h ... */
   39.45 +
    40.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.2 +++ b/src/video/dc/SDL_dcmouse.c	Sat Oct 05 16:50:56 2002 +0000
    40.3 @@ -0,0 +1,45 @@
    40.4 +/*
    40.5 +    SDL - Simple DirectMedia Layer
    40.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    40.7 +
    40.8 +    This library is free software; you can redistribute it and/or
    40.9 +    modify it under the terms of the GNU Library General Public
   40.10 +    License as published by the Free Software Foundation; either
   40.11 +    version 2 of the License, or (at your option) any later version.
   40.12 +
   40.13 +    This library is distributed in the hope that it will be useful,
   40.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   40.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   40.16 +    Library General Public License for more details.
   40.17 +
   40.18 +    You should have received a copy of the GNU Library General Public
   40.19 +    License along with this library; if not, write to the Free
   40.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   40.21 +
   40.22 +    BERO
   40.23 +    bero@geocities.co.jp
   40.24 +
   40.25 +    based on SDL_nullvideo.h by
   40.26 +
   40.27 +    Sam Lantinga
   40.28 +    slouken@libsdl.org
   40.29 +*/
   40.30 +
   40.31 +#ifdef SAVE_RCSID
   40.32 +static char rcsid =
   40.33 + "@(#) $Id$";
   40.34 +#endif
   40.35 +
   40.36 +#include <stdio.h>
   40.37 +
   40.38 +#include "SDL_error.h"
   40.39 +#include "SDL_mouse.h"
   40.40 +#include "SDL_events_c.h"
   40.41 +
   40.42 +#include "SDL_dcmouse_c.h"
   40.43 +
   40.44 +
   40.45 +/* The implementation dependent data for the window manager cursor */
   40.46 +struct WMcursor {
   40.47 +	int unused;
   40.48 +};
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/src/video/dc/SDL_dcmouse_c.h	Sat Oct 05 16:50:56 2002 +0000
    41.3 @@ -0,0 +1,35 @@
    41.4 +/*
    41.5 +    SDL - Simple DirectMedia Layer
    41.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    41.7 +
    41.8 +    This library is free software; you can redistribute it and/or
    41.9 +    modify it under the terms of the GNU Library General Public
   41.10 +    License as published by the Free Software Foundation; either
   41.11 +    version 2 of the License, or (at your option) any later version.
   41.12 +
   41.13 +    This library is distributed in the hope that it will be useful,
   41.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   41.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   41.16 +    Library General Public License for more details.
   41.17 +
   41.18 +    You should have received a copy of the GNU Library General Public
   41.19 +    License along with this library; if not, write to the Free
   41.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   41.21 +
   41.22 +    BERO
   41.23 +    bero@geocities.co.jp
   41.24 +
   41.25 +    based on SDL_nullmouse.h by
   41.26 +
   41.27 +    Sam Lantinga
   41.28 +    slouken@libsdl.org
   41.29 +*/
   41.30 +
   41.31 +#ifdef SAVE_RCSID
   41.32 +static char rcsid =
   41.33 + "@(#) $Id$";
   41.34 +#endif
   41.35 +
   41.36 +#include "SDL_dcvideo.h"
   41.37 +
   41.38 +/* Functions to be exported */
    42.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.2 +++ b/src/video/dc/SDL_dcvideo.c	Sat Oct 05 16:50:56 2002 +0000
    42.3 @@ -0,0 +1,477 @@
    42.4 +/*
    42.5 +    SDL - Simple DirectMedia Layer
    42.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    42.7 +
    42.8 +    This library is free software; you can redistribute it and/or
    42.9 +    modify it under the terms of the GNU Library General Public
   42.10 +    License as published by the Free Software Foundation; either
   42.11 +    version 2 of the License, or (at your option) any later version.
   42.12 +
   42.13 +    This library is distributed in the hope that it will be useful,
   42.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   42.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   42.16 +    Library General Public License for more details.
   42.17 +
   42.18 +    You should have received a copy of the GNU Library General Public
   42.19 +    License along with this library; if not, write to the Free
   42.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   42.21 +
   42.22 +    BERO
   42.23 +    bero@geocities.co.jp
   42.24 +
   42.25 +    based on SDL_nullvideo.c by
   42.26 +
   42.27 +    Sam Lantinga
   42.28 +    slouken@libsdl.org
   42.29 +*/
   42.30 +
   42.31 +#ifdef SAVE_RCSID
   42.32 +static char rcsid =
   42.33 + "@(#) $Id$";
   42.34 +#endif
   42.35 +
   42.36 +/* Dummy SDL video driver implementation; this is just enough to make an
   42.37 + *  SDL-based application THINK it's got a working video driver, for
   42.38 + *  applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
   42.39 + *  and also for use as a collection of stubs when porting SDL to a new
   42.40 + *  platform for which you haven't yet written a valid video driver.
   42.41 + *
   42.42 + * This is also a great way to determine bottlenecks: if you think that SDL
   42.43 + *  is a performance problem for a given platform, enable this driver, and
   42.44 + *  then see if your application runs faster without video overhead.
   42.45 + *
   42.46 + * Initial work by Ryan C. Gordon (icculus@linuxgames.com). A good portion
   42.47 + *  of this was cut-and-pasted from Stephane Peter's work in the AAlib
   42.48 + *  SDL video driver.  Renamed to "DC" by Sam Lantinga.
   42.49 + */
   42.50 +
   42.51 +#include <stdio.h>
   42.52 +#include <stdlib.h>
   42.53 +#include <string.h>
   42.54 +
   42.55 +#include "SDL.h"
   42.56 +#include "SDL_error.h"
   42.57 +#include "SDL_video.h"
   42.58 +#include "SDL_mouse.h"
   42.59 +#include "SDL_sysvideo.h"
   42.60 +#include "SDL_pixels_c.h"
   42.61 +#include "SDL_events_c.h"
   42.62 +
   42.63 +#include "SDL_dcvideo.h"
   42.64 +#include "SDL_dcevents_c.h"
   42.65 +#include "SDL_dcmouse_c.h"
   42.66 +
   42.67 +#include <dc/video.h>
   42.68 +#include <dc/pvr.h>
   42.69 +
   42.70 +#ifdef HAVE_OPENGL
   42.71 +#include <GL/gl.h>
   42.72 +#endif
   42.73 +
   42.74 +
   42.75 +/* Initialization/Query functions */
   42.76 +static int DC_VideoInit(_THIS, SDL_PixelFormat *vformat);
   42.77 +static SDL_Rect **DC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
   42.78 +static SDL_Surface *DC_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
   42.79 +static int DC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
   42.80 +static void DC_VideoQuit(_THIS);
   42.81 +
   42.82 +/* Hardware surface functions */
   42.83 +static int DC_AllocHWSurface(_THIS, SDL_Surface *surface);
   42.84 +static int DC_LockHWSurface(_THIS, SDL_Surface *surface);
   42.85 +static void DC_UnlockHWSurface(_THIS, SDL_Surface *surface);
   42.86 +static void DC_FreeHWSurface(_THIS, SDL_Surface *surface);
   42.87 +static int DC_FlipHWSurface(_THIS, SDL_Surface *surface);
   42.88 +
   42.89 +/* etc. */
   42.90 +static void DC_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
   42.91 +
   42.92 +/* OpenGL */
   42.93 +static void *DC_GL_GetProcAddress(_THIS, const char *proc);
   42.94 +static int DC_GL_LoadLibrary(_THIS, const char *path);
   42.95 +static int DC_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
   42.96 +static void DC_GL_SwapBuffers(_THIS);
   42.97 +
   42.98 +/* DC driver bootstrap functions */
   42.99 +
  42.100 +static int DC_Available(void)
  42.101 +{
  42.102 +	return 1;
  42.103 +}
  42.104 +
  42.105 +static void DC_DeleteDevice(SDL_VideoDevice *device)
  42.106 +{
  42.107 +	free(device->hidden);
  42.108 +	free(device);
  42.109 +}
  42.110 +
  42.111 +static SDL_VideoDevice *DC_CreateDevice(int devindex)
  42.112 +{
  42.113 +	SDL_VideoDevice *device;
  42.114 +
  42.115 +	/* Initialize all variables that we clean on shutdown */
  42.116 +	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
  42.117 +	if ( device ) {
  42.118 +		memset(device, 0, (sizeof *device));
  42.119 +		device->hidden = (struct SDL_PrivateVideoData *)
  42.120 +				malloc((sizeof *device->hidden));
  42.121 +	}
  42.122 +	if ( (device == NULL) || (device->hidden == NULL) ) {
  42.123 +		SDL_OutOfMemory();
  42.124 +		if ( device ) {
  42.125 +			free(device);
  42.126 +		}
  42.127 +		return(0);
  42.128 +	}
  42.129 +	memset(device->hidden, 0, (sizeof *device->hidden));
  42.130 +
  42.131 +	/* Set the function pointers */
  42.132 +	device->VideoInit = DC_VideoInit;
  42.133 +	device->ListModes = DC_ListModes;
  42.134 +	device->SetVideoMode = DC_SetVideoMode;
  42.135 +	device->CreateYUVOverlay = NULL;
  42.136 +	device->SetColors = DC_SetColors;
  42.137 +	device->UpdateRects = DC_UpdateRects;
  42.138 +	device->VideoQuit = DC_VideoQuit;
  42.139 +	device->AllocHWSurface = DC_AllocHWSurface;
  42.140 +	device->CheckHWBlit = NULL;
  42.141 +	device->FillHWRect = NULL;
  42.142 +	device->SetHWColorKey = NULL;
  42.143 +	device->SetHWAlpha = NULL;
  42.144 +	device->LockHWSurface = DC_LockHWSurface;
  42.145 +	device->UnlockHWSurface = DC_UnlockHWSurface;
  42.146 +	device->FlipHWSurface = DC_FlipHWSurface;
  42.147 +	device->FreeHWSurface = DC_FreeHWSurface;
  42.148 +#ifdef	HAVE_OPENGL
  42.149 +	device->GL_LoadLibrary = DC_GL_LoadLibrary;
  42.150 +	device->GL_GetProcAddress = DC_GL_GetProcAddress;
  42.151 +	device->GL_GetAttribute = DC_GL_GetAttribute;
  42.152 +	device->GL_MakeCurrent = NULL;
  42.153 +	device->GL_SwapBuffers = DC_GL_SwapBuffers;
  42.154 +#endif
  42.155 +	device->SetCaption = NULL;
  42.156 +	device->SetIcon = NULL;
  42.157 +	device->IconifyWindow = NULL;
  42.158 +	device->GrabInput = NULL;
  42.159 +	device->GetWMInfo = NULL;
  42.160 +	device->InitOSKeymap = DC_InitOSKeymap;
  42.161 +	device->PumpEvents = DC_PumpEvents;
  42.162 +
  42.163 +	device->free = DC_DeleteDevice;
  42.164 +
  42.165 +	return device;
  42.166 +}
  42.167 +
  42.168 +VideoBootStrap DC_bootstrap = {
  42.169 +	"dcvideo", "Dreamcast Video",
  42.170 +	DC_Available, DC_CreateDevice
  42.171 +};
  42.172 +
  42.173 +
  42.174 +int DC_VideoInit(_THIS, SDL_PixelFormat *vformat)
  42.175 +{
  42.176 +	/* Determine the screen depth (use default 8-bit depth) */
  42.177 +	/* we change this during the SDL_SetVideoMode implementation... */
  42.178 +	vformat->BitsPerPixel = 16;
  42.179 +	vformat->Rmask = 0x0000f800;
  42.180 +	vformat->Gmask = 0x000007e0;
  42.181 +	vformat->Bmask = 0x0000001f;
  42.182 +
  42.183 +	/* We're done! */
  42.184 +	return(0);
  42.185 +}
  42.186 +
  42.187 +const static SDL_Rect
  42.188 +	RECT_800x600 = {0,0,800,600},
  42.189 +	RECT_640x480 = {0,0,640,480},
  42.190 +	RECT_320x240 = {0,0,320,240};
  42.191 +const static SDL_Rect *vid_modes[] = {
  42.192 +	&RECT_800x600,
  42.193 +	&RECT_640x480,
  42.194 +	&RECT_320x240,
  42.195 +	NULL
  42.196 +};
  42.197 +
  42.198 +SDL_Rect **DC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
  42.199 +{
  42.200 +	switch(format->BitsPerPixel) {
  42.201 +	case 15:
  42.202 +	case 16:
  42.203 +		return &vid_modes;
  42.204 +	case 32:
  42.205 +		if (!(flags & SDL_OPENGL))
  42.206 +		return &vid_modes;
  42.207 +	default:
  42.208 +		return NULL;
  42.209 +	}
  42.210 +//	return (SDL_Rect **) -1;
  42.211 +}
  42.212 +
  42.213 +pvr_init_params_t params = {
  42.214 +        /* Enable opaque and translucent polygons with size 16 */
  42.215 +        { PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_16 },
  42.216 +
  42.217 +        /* Vertex buffer size */
  42.218 +        512*1024
  42.219 +};
  42.220 +
  42.221 +#ifdef HAVE_OPENGL
  42.222 +static int pvr_inited;
  42.223 +#endif
  42.224 +
  42.225 +SDL_Surface *DC_SetVideoMode(_THIS, SDL_Surface *current,
  42.226 +				int width, int height, int bpp, Uint32 flags)
  42.227 +{
  42.228 +	int disp_mode,pixel_mode,pitch;
  42.229 +	Uint32 Rmask, Gmask, Bmask;
  42.230 +
  42.231 +	if (width==320 && height==240) disp_mode=DM_320x240;
  42.232 +	else if (width==640 && height==480) disp_mode=DM_640x480;
  42.233 +	else if (width==800 && height==600) disp_mode=DM_800x608;
  42.234 +	else {
  42.235 +		SDL_SetError("Couldn't find requested mode in list");
  42.236 +		return(NULL);
  42.237 +	}
  42.238 +
  42.239 +	switch(bpp) {
  42.240 +	case 15: pixel_mode = PM_RGB555; pitch = width*2;
  42.241 +		/* 5-5-5 */
  42.242 +		Rmask = 0x00007c00;
  42.243 +		Gmask = 0x000003e0;
  42.244 +		Bmask = 0x0000001f;
  42.245 +		break;
  42.246 +	case 16: pixel_mode = PM_RGB565; pitch = width*2;
  42.247 +		/* 5-6-5 */
  42.248 +		Rmask = 0x0000f800;
  42.249 +		Gmask = 0x000007e0;
  42.250 +		Bmask = 0x0000001f;
  42.251 +		break;
  42.252 +	case 24: bpp = 32;
  42.253 +	case 32: pixel_mode = PM_RGB888; pitch = width*4;
  42.254 +		Rmask = 0x00ff0000;
  42.255 +		Gmask = 0x0000ff00;
  42.256 +		Bmask = 0x000000ff;
  42.257 +#ifdef	HAVE_OPENGL
  42.258 +		if (!(flags & SDL_OPENGL))
  42.259 +#endif
  42.260 +		break;
  42.261 +	default:
  42.262 +		SDL_SetError("Couldn't find requested mode in list");
  42.263 +		return(NULL);
  42.264 +	}
  42.265 +
  42.266 +//  if ( bpp != current->format->BitsPerPixel ) {
  42.267 +	if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) {
  42.268 +		return(NULL);
  42.269 +	}
  42.270 +//  }
  42.271 +
  42.272 +	/* Set up the new mode framebuffer */
  42.273 +	current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE);
  42.274 +	current->w = width;
  42.275 +	current->h = height;
  42.276 +	current->pitch = pitch;
  42.277 +
  42.278 +#ifdef HAVE_OPENGL
  42.279 +	if (pvr_inited) {
  42.280 +		pvr_inited = 0;
  42.281 +		pvr_shutdown();
  42.282 +	}
  42.283 +#endif
  42.284 +
  42.285 +	vid_set_mode(disp_mode,pixel_mode);
  42.286 +
  42.287 +	current->pixels = vram_s;
  42.288 +
  42.289 +#ifdef	HAVE_OPENGL
  42.290 +	if (flags & SDL_OPENGL) {
  42.291 +		this->gl_config.driver_loaded = 1;
  42.292 +		current->flags = SDL_FULLSCREEN | SDL_OPENGL;
  42.293 +		current->pixels = NULL;
  42.294 +		pvr_inited = 1;
  42.295 +		pvr_init(&params);
  42.296 +		glKosInit();
  42.297 +		glKosBeginFrame();
  42.298 +	} else
  42.299 +#endif
  42.300 +	if (flags | SDL_DOUBLEBUF) {
  42.301 +		current->flags |= SDL_DOUBLEBUF;
  42.302 +		current->pixels = (void*)((int)current->pixels | 0x400000);
  42.303 +	}
  42.304 +
  42.305 +	/* We're done */
  42.306 +	return(current);
  42.307 +}
  42.308 +
  42.309 +/* We don't actually allow hardware surfaces other than the main one */
  42.310 +static int DC_AllocHWSurface(_THIS, SDL_Surface *surface)
  42.311 +{
  42.312 +	return(-1);
  42.313 +}
  42.314 +static void DC_FreeHWSurface(_THIS, SDL_Surface *surface)
  42.315 +{
  42.316 +	return;
  42.317 +}
  42.318 +
  42.319 +/* We need to wait for vertical retrace on page flipped displays */
  42.320 +static int DC_LockHWSurface(_THIS, SDL_Surface *surface)
  42.321 +{
  42.322 +	return(0);
  42.323 +}
  42.324 +
  42.325 +static void DC_UnlockHWSurface(_THIS, SDL_Surface *surface)
  42.326 +{
  42.327 +	return;
  42.328 +}
  42.329 +
  42.330 +static int DC_FlipHWSurface(_THIS, SDL_Surface *surface)
  42.331 +{
  42.332 +	if (surface->flags & SDL_DOUBLEBUF) {
  42.333 +		vid_set_start((int)surface->pixels & 0xffffff);
  42.334 +		surface->pixels = (void*)((int)surface->pixels ^ 0x400000);
  42.335 +	}
  42.336 +	return(0);
  42.337 +}
  42.338 +
  42.339 +static void DC_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
  42.340 +{
  42.341 +	/* do nothing. */
  42.342 +}
  42.343 +
  42.344 +static int DC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
  42.345 +{
  42.346 +	/* do nothing of note. */
  42.347 +	return(1);
  42.348 +}
  42.349 +
  42.350 +/* Note:  If we are terminated, this could be called in the middle of
  42.351 +   another SDL video routine -- notably UpdateRects.
  42.352 +*/
  42.353 +static void DC_VideoQuit(_THIS)
  42.354 +{
  42.355 +#ifdef HAVE_OPENGL
  42.356 +	if (pvr_inited) {
  42.357 +		pvr_inited = 0;
  42.358 +		pvr_shutdown();
  42.359 +	}
  42.360 +#endif
  42.361 +}
  42.362 +
  42.363 +#ifdef HAVE_OPENGL
  42.364 +
  42.365 +void dmyfunc(void) {}
  42.366 +
  42.367 +typedef void (*funcptr)();
  42.368 +const static struct {
  42.369 +	char *name;
  42.370 +	funcptr addr;
  42.371 +} glfuncs[] = {
  42.372 +#define	DEF(func)	{#func,&func}
  42.373 +	DEF(glBegin),
  42.374 +	DEF(glBindTexture),
  42.375 +	DEF(glBlendFunc),
  42.376 +	DEF(glColor4f),
  42.377 +//	DEF(glCopyImageID),
  42.378 +	DEF(glDisable),
  42.379 +	DEF(glEnable),
  42.380 +	DEF(glEnd),
  42.381 +	DEF(glFlush),
  42.382 +	DEF(glGenTextures),
  42.383 +	DEF(glGetString),
  42.384 +	DEF(glLoadIdentity),
  42.385 +	DEF(glMatrixMode),
  42.386 +	DEF(glOrtho),
  42.387 +	DEF(glPixelStorei),
  42.388 +//	DEF(glPopAttrib),
  42.389 +//	DEF(glPopClientAttrib),
  42.390 +	{"glPopAttrib",&dmyfunc},
  42.391 +	{"glPopClientAttrib",&dmyfunc},
  42.392 +	DEF(glPopMatrix),
  42.393 +//	DEF(glPushAttrib),
  42.394 +//	DEF(glPushClientAttrib),
  42.395 +	{"glPushAttrib",&dmyfunc},
  42.396 +	{"glPushClientAttrib",&dmyfunc},
  42.397 +	DEF(glPushMatrix),
  42.398 +	DEF(glTexCoord2f),
  42.399 +	DEF(glTexEnvf),
  42.400 +	DEF(glTexImage2D),
  42.401 +	DEF(glTexParameteri),
  42.402 +	DEF(glTexSubImage2D),
  42.403 +	DEF(glVertex2i),
  42.404 +	DEF(glViewport),
  42.405 +#undef	DEF
  42.406 +};
  42.407 +
  42.408 +static void *DC_GL_GetProcAddress(_THIS, const char *proc)
  42.409 +{
  42.410 +	void *ret;
  42.411 +	int i;
  42.412 +
  42.413 +	ret = glKosGetProcAddress(proc);
  42.414 +	if (ret) return ret;
  42.415 +
  42.416 +	for(i=0;i<sizeof(glfuncs)/sizeof(glfuncs[0]);i++) {
  42.417 +		if (strcmp(proc,glfuncs[i].name)==0) return glfuncs[i].addr;
  42.418 +	}
  42.419 +
  42.420 +	return NULL;
  42.421 +}
  42.422 +
  42.423 +static int DC_GL_LoadLibrary(_THIS, const char *path)
  42.424 +{
  42.425 +	this->gl_config.driver_loaded = 1;
  42.426 +
  42.427 +	return 0;
  42.428 +}
  42.429 +
  42.430 +static int DC_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
  42.431 +{
  42.432 +	GLenum mesa_attrib;
  42.433 +	int val;
  42.434 +
  42.435 +	switch(attrib) {
  42.436 +	case SDL_GL_RED_SIZE:
  42.437 +		val = 5;
  42.438 +		break;
  42.439 +	case SDL_GL_GREEN_SIZE:
  42.440 +		val = 6;
  42.441 +		break;
  42.442 +	case SDL_GL_BLUE_SIZE:
  42.443 +		val = 5;
  42.444 +		break;
  42.445 +	case SDL_GL_ALPHA_SIZE:
  42.446 +		val = 0;
  42.447 +		break;
  42.448 +	case SDL_GL_DOUBLEBUFFER:
  42.449 +		val = 1;
  42.450 +		break;
  42.451 +	case SDL_GL_DEPTH_SIZE:
  42.452 +		val = 16; /* or 32? */
  42.453 +		break;
  42.454 +	case SDL_GL_STENCIL_SIZE:
  42.455 +		val = 0;
  42.456 +		break;
  42.457 +	case SDL_GL_ACCUM_RED_SIZE:
  42.458 +		val = 0;
  42.459 +		break;
  42.460 +	case SDL_GL_ACCUM_GREEN_SIZE:
  42.461 +		val = 0;
  42.462 +	case SDL_GL_ACCUM_BLUE_SIZE:
  42.463 +		val = 0;
  42.464 +		break;
  42.465 +	case SDL_GL_ACCUM_ALPHA_SIZE:
  42.466 +		val = 0;
  42.467 +		break;
  42.468 +	default :
  42.469 +		return -1;
  42.470 +	}
  42.471 +	*value = val;
  42.472 +	return 0;
  42.473 +}
  42.474 +
  42.475 +static void DC_GL_SwapBuffers(_THIS)
  42.476 +{
  42.477 +	glKosFinishFrame();
  42.478 +	glKosBeginFrame();
  42.479 +}
  42.480 +#endif
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/src/video/dc/SDL_dcvideo.h	Sat Oct 05 16:50:56 2002 +0000
    43.3 @@ -0,0 +1,51 @@
    43.4 +/*
    43.5 +    SDL - Simple DirectMedia Layer
    43.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
    43.7 +
    43.8 +    This library is free software; you can redistribute it and/or
    43.9 +    modify it under the terms of the GNU Library General Public
   43.10 +    License as published by the Free Software Foundation; either
   43.11 +    version 2 of the License, or (at your option) any later version.
   43.12 +
   43.13 +    This library is distributed in the hope that it will be useful,
   43.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   43.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   43.16 +    Library General Public License for more details.
   43.17 +
   43.18 +    You should have received a copy of the GNU Library General Public
   43.19 +    License along with this library; if not, write to the Free
   43.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   43.21 +
   43.22 +    BERO
   43.23 +    bero@geocities.co.jp
   43.24 +
   43.25 +    based on SDL_nullvideo.h by
   43.26 +
   43.27 +    Sam Lantinga
   43.28 +    slouken@libsdl.org
   43.29 +*/
   43.30 +
   43.31 +#ifdef SAVE_RCSID
   43.32 +static char rcsid =
   43.33 + "@(#) $Id$";
   43.34 +#endif
   43.35 +
   43.36 +#ifndef _SDL_dcvideo_h
   43.37 +#define _SDL_dcvideo_h
   43.38 +
   43.39 +#include "SDL_mouse.h"
   43.40 +#include "SDL_sysvideo.h"
   43.41 +#include "SDL_mutex.h"
   43.42 +
   43.43 +/* Hidden "this" pointer for the video functions */
   43.44 +#define _THIS	SDL_VideoDevice *this
   43.45 +
   43.46 +
   43.47 +/* Private display data */
   43.48 +
   43.49 +struct SDL_PrivateVideoData {
   43.50 +    int w, h;
   43.51 +    void *buffer;
   43.52 +};
   43.53 +
   43.54 +#endif /* _SDL_dcvideo_h */