diff --git a/makefile.sdl b/makefile.sdl new file mode 100644 index 000000000..d0cefed14 --- /dev/null +++ b/makefile.sdl @@ -0,0 +1,556 @@ +# Makefile for FBASDL, for use with GNU make & GCC +# +# The first pass makes sure all intermediary targets are present. The second pass updates +# any targets, if necessary. (Intermediary) targets which have their own unique rules +# are generated as required. + +unexport + +# +# Flags. Uncomment any of these declarations to enable their function. +# + +# Check for changes in header files +DEPEND = 1 + + + +# +# Declare variables +# + +# Specify the name of the executable file, without ".exe" +NAME = fbasdl + +ifdef BUILD_X64_EXE +ifdef BUILD_A68K +undefine BUILD_A68K +endif +ifdef BUILD_X86_ASM +undefine BUILD_X86_ASM +endif +endif + +ifndef CPUTYPE + CPUTYPE = i686 +endif + +MMX = 0 + +ifndef BUILD_X86_ASM + NAME := $(NAME)n +endif +ifdef BUILD_X64_EXE + NAME = $(NAME)64 +endif +ifdef DEBUG + NAME := $(NAME)d +endif +ifdef SYMBOL + NAME := $(NAME)s +endif +ifndef UNICODE + NAME := $(NAME)a +endif + +ifeq ($(CPUTYPE),i686) + ppro = ppro +else + NAME := $(NAME)$(CPUTYPE) +endif + + + +# +# Specify paths/files +# + +objdir = obj/SDL/$(NAME)/ + + +srcdir = src/ + +include makefile.rules + +incdir = $(foreach dir,$(alldir),-I$(srcdir)$(dir)) -I$(objdir)depend/generated + +lib += `sdl-config --libs` + +depobj += resource.o \ + +autdep = $(depobj:.o=.d) + +ifdef BUILD_A68K +a68k.o = $(objdir)cpu/a68k/a68k.o +endif + + +license.rtf = $(srcdir)depend/generated/license.rtf +driverlist.h = $(srcdir)depend/generated/driverlist.h +ctv.h = $(srcdir)depend/generated/ctv.h +toa_gp9001_func.h = $(srcdir)depend/generated/toa_gp9001_func.h +neo_sprite_func.h = $(srcdir)depend/generated/neo_sprite_func.h +cave_tile_func.h = $(srcdir)depend/generated/cave_tile_func.h +cave_sprite_func.h = $(srcdir)depend/generated/cave_sprite_func.h +psikyo_tile_func.h = $(srcdir)depend/generated/psikyo_tile_func.h +pgm_sprite.h = $(srcdir)depend/generated/pgm_sprite.h +build_details.h = $(srcdir)depend/generated/build_details.h + +allobj = $(objdir)cpu/m68k/m68kcpu.o $(objdir)cpu/m68k/m68kopnz.o $(objdir)cpu/m68k/m68kopdm.o $(objdir)cpu/m68k/m68kopac.o $(objdir)cpu/m68k/m68kops.o \ + $(foreach file,$(autobj:.o=.c), \ + $(foreach dir,$(alldir),$(subst $(srcdir),$(objdir), \ + $(firstword $(subst .c,.o,$(wildcard $(srcdir)$(dir)/$(file))))))) \ + $(foreach file,$(autobj:.o=.cpp), \ + $(foreach dir,$(alldir),$(subst $(srcdir),$(objdir), \ + $(firstword $(subst .cpp,.o,$(wildcard $(srcdir)$(dir)/$(file))))))) \ + $(foreach file,$(autobj:.o=.asm), \ + $(foreach dir,$(alldir),$(subst $(srcdir),$(objdir), \ + $(firstword $(subst .asm,.o,$(wildcard $(srcdir)$(dir)/$(file))))))) \ + +ifdef BUILD_A68K +allobj += $(a68k.o) +endif + +alldep = $(foreach file,$(autobj:.o=.c), \ + $(foreach dir,$(alldir),$(subst $(srcdir),$(objdir), \ + $(firstword $(subst .c,.d,$(wildcard $(srcdir)$(dir)/$(file))))))) \ + $(foreach file,$(autobj:.o=.cpp), \ + $(foreach dir,$(alldir),$(subst $(srcdir),$(objdir), \ + $(firstword $(subst .cpp,.d,$(wildcard $(srcdir)$(dir)/$(file))))))) \ + +# +# +# Specify compiler/linker/assembler +# +# + +CC = gcc +CXX = g++ +LD = $(CXX) +AS = nasm + +LDFLAGS = -static + + +CFLAGS = -pipe \ + -std=gnu99 -march=$(CPUTYPE) -O1 \ + -fforce-mem -fforce-addr -finline-limit=1200 -fthread-jumps \ + -freduce-all-givs -fmove-all-movables -fexpensive-optimizations \ + -Wall -Wno-long-long -Wno-sign-compare -Wno-uninitialized -Wno-unused \ + $(DEF) $(incdir) `sdl-config --cflags` + +CXXFLAGS = -pipe \ + -march=$(CPUTYPE) -O1 \ + -fforce-mem -fforce-addr -finline-limit=1200 -fthread-jumps \ + -freduce-all-givs -fmove-all-movables -fexpensive-optimizations \ + -fcheck-new \ + -Wall -W -pedantic -Wno-long-long \ + -Wunknown-pragmas -Wundef -Wconversion -Wno-missing-braces \ + -Wuninitialized -Wpointer-arith -Winline -Wno-multichar \ + $(DEF) $(incdir) `sdl-config --cflags` +endif + +ifdef BUILD_X64_EXE + CFLAGS += -m64 + CXXFLAGS += -m64 + LDFLAGS += -m64 +else + CFLAGS += -m32 + CXXFLAGS += -m32 + LDFLAGS += -m32 +endif +endif + +ASFLAGS = -O1 -f coff -w-orphan-labels + +# D3DUtils & D3DMath need these +# DEF = -Dsinf=\(float\)sin -Dcosf=\(float\)cos -Dasinf=\(float\)asin -Dacosf=\(float\)acos -Dsqrtf=\(float\)sqrt + + DEF := -DUSE_SPEEDHACKS -DFILENAME=$(NAME) -DMMX=0 + +ifdef UNICODE + DEF := $(DEF) -D_UNICODE +endif + +ifdef SPECIALBUILD + DEF := $(DEF) -DSPECIALBUILD=$(SPECIALBUILD) +endif + +ifdef FASTCALL + DEF := $(DEF) -DFASTCALL +endif + +ifdef DEBUG + DEF := $(DEF) -DFBA_DEBUG +endif + +ifdef ROM_VERIFY + DEF := $(DEF) -DROM_VERIFY +endif + +ifdef BUILD_A68K + DEF := $(DEF) -DBUILD_A68K +endif + +ifdef BUILD_X86_ASM + DEF := $(DEF) -DBUILD_X86_ASM +endif + +ifdef BUILD_X64_EXE + DEF := $(DEF) -DBUILD_X64_EXE +endif + +ifdef SYMBOL + + CFLAGS += -ggdb3 + ASFLAGS += -g + DEF := $(DEF) -D_DEBUG + +ifdef PROFILE + CFLAGS += -pg + CXXFLAGS += -pg +else + CFLAGS += -fomit-frame-pointer + CXXFLAGS += -fomit-frame-pointer +endif + +else + LDFLAGS += -s +endif + + +# For zlib +DEF := $(DEF) -DNO_VIZ -D_LARGEFILE64_SOURCE=0 -D_FILE_OFFSET_BITS=32 + +# +# +# Specify paths +# +# + +vpath %.asm $(foreach dir,$(alldir),$(srcdir)$(dir)/ ) +vpath %.cpp $(foreach dir,$(alldir),$(srcdir)$(dir)/ ) +vpath %.c $(foreach dir,$(alldir),$(srcdir)$(dir)/ ) +vpath %.h $(foreach dir,$(alldir),$(srcdir)$(dir)/ ) + +vpath %.o $(foreach dir,$(alldir),$(objdir)$(dir)/ ) +vpath %.d $(foreach dir,$(alldir),$(objdir)$(dir)/ ) + +# +# +# Rules +# +# + +.PHONY: all init cleandep touch clean + +ifeq ($(MAKELEVEL),1) +ifdef DEPEND + +all: init $(autdep) $(autobj) +@$(MAKE) -f makefile.sdl + +else + +all: init $(autobj) +@$(MAKE) -f makefile.sdl + +endif +else + +all: $(NAME).exe + +endif + +# +# +# Rule for linking the executable +# +# + +ifeq ($(MAKELEVEL),2) + +$(NAME).exe: $(allobj) + @echo + @echo Linking executable... $(NAME).exe + @$(LD) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(lib) + +ifdef DEBUG + +# Don't compress when making a debug build + +else +ifdef COMPRESS + @upx --best $@ +endif +endif +endif + +ifeq ($(MAKELEVEL),1) +ifdef FORCE_UPDATE +$(build_details.h): FORCE +endif +endif + +# +# Generate the gamelist +# + +burn.o burn.d: driverlist.h + +$(driverlist.h): $(drvobj) $(srcdir)depend/scripts/gamelist.pl +ifdef PERL + @$(srcdir)depend/scripts/gamelist.pl -o $@ -l gamelist.txt \ + $(filter %.cpp,$(foreach file,$(drvobj:.o=.cpp),$(foreach dir,$(alldir), \ + $(firstword $(wildcard $(srcdir)$(dir)/$(file)))))) +else +ifeq ($(MAKELEVEL),2) + @echo + @echo Warning: Perl is not available on this system. + @echo $@ cannot be updated or created! + @echo +endif +endif + +# +# Verify if driverlist.h needs to be updated +# + +#ifeq ($(MAKELEVEL),1) +#ifdef FORCE_UPDATE +#$(driverlist.h): FORCE +#endif +#endif + + +# +# Generate some info on the build details +# + +about.o about.d: $(build_details.h) + +$(build_details.h): $(srcdir)depend/scripts/build_details.cpp + @$(CXX) -mconsole $(CXXFLAGS) $(LDFLAGS) $< -o $(objdir)depend/generated/build_details.exe + @$(objdir)depend/generated/build_details.exe >$@ + +# +# Compile 68000 cores +# + +# A68K + +ifdef BUILD_A68K +$(a68k.o): fba_make68k.c + @echo Compiling A68K MC68000 core... + @$(CC) -mconsole $(CFLAGS) $(LDFLAGS) -DWIN32 -Wno-unused -Wno-conversion -Wno-missing-prototypes \ + -s $< -o $(subst $(srcdir),$(objdir),$($@ + +# +# Extra rules for generated header file toa_gp9001_func.h, needed by toa_gp9001.cpp +# + +toa_bcu2.d toa_bcu2.o toa_gp9001.d toa_gp9001.o: $(toa_gp9001_func.h) + +$(toa_gp9001_func.h): $(srcdir)depend/scripts/toa_gp9001_func.pl + @$(srcdir)depend/scripts/toa_gp9001_func.pl -o $(toa_gp9001_func.h) + +# +# Extra rules for generated header file neo_sprite_func.h, needed by neo_sprite.cpp +# + +neo_sprite.d neo_sprite.o: $(neo_sprite_func.h) + +$(neo_sprite_func.h): $(srcdir)depend/scripts/neo_sprite_func.pl + @$(srcdir)depend/scripts/neo_sprite_func.pl -o $(neo_sprite_func.h) + +# +# Extra rules for generated header file cave_tile_func.h, needed by cave_tile.cpp +# + +cave_tile.d cave_tile.o: $(cave_tile_func.h) + +$(cave_tile_func.h): $(srcdir)depend/scripts/cave_tile_func.pl + @$(srcdir)depend/scripts/cave_tile_func.pl -o $(cave_tile_func.h) + +# +# Extra rules for generated header file cave_sprite_func.h, needed by cave_sprite.cpp +# + +cave_sprite.d cave_sprite.o: $(cave_sprite_func.h) + +$(cave_sprite_func.h): $(srcdir)depend/scripts/cave_sprite_func.pl + @$(srcdir)depend/scripts/cave_sprite_func.pl -o $(cave_sprite_func.h) + +# +# Extra rules for generated header file psikyo_tile_func.h / psikyo_sprite_func.h, needed by psikyo_tile.cpp / psikyo_sprite.cpp +# + +psikyo_tile.d psikyo_tile.o psikyosprite.d psikyo_sprite.o: $(psikyo_tile_func.h) + +$(psikyo_tile_func.h): $(srcdir)depend/scripts/psikyo_tile_func.pl + $(srcdir)depend/scripts/psikyo_tile_func.pl -o $(psikyo_tile_func.h) + +# +# Extra rules for generated header file pgm_sprite.h, needed by pgm_draw.cpp +# + +pgm_draw.d pgm_draw.o: $(pgm_sprite.h) + +$(pgm_sprite.h): pgm_sprite_create.cpp + @echo Generating $(srcdir)depend/generated/$(@F)... + @$(CC) -mconsole $(CXXFLAGS) $(LDFLAGS) $< \ + -o $(subst $(srcdir),$(objdir),$($@ + + +ifeq ($(MAKELEVEL),2) +ifdef DEPEND + +include $(alldep) + +endif +endif + + +# +# Generic rules for C/C++ files +# + +ifeq ($(MAKELEVEL),1) + +%.o: %.cpp + @echo Compiling $<... + @$(CC) $(CXXFLAGS) -c $< -o $(subst $(srcdir),$(objdir),$($(subst $(srcdir),$(objdir),$($(subst $(srcdir),$(objdir),$($(subst $(srcdir),$(objdir),$( -class AudioSDL : public Audio { -public: - SDL_AudioSpec SDLAudioSpec; +static unsigned int nSoundFps; - short* SDLAudBuffer; - int nSDLPlayPos; - int nSDLFillSeg; +int (*GetNextSound)(int); // Callback used to request more sound - int (*SDLGetNextSound)(int); +static SDL_AudioSpec audiospec; - int set(int (*callback)(int)) - { - if (callback == NULL) { - SDLGetNextSound = AudWriteSlience; - } else { - SDLGetNextSound = callback; - dprintf(_T("SDL callback set\n")); +static short* SDLAudBuffer; +static int nSDLPlayPos; +static int nSDLFillSeg; +static int nAudLoopLen; + +void audiospec_callback(void* /* data */, Uint8* stream, int len) +{ +// dprintf(_T("audiospec_callback %i"), len); + + int end = nSDLPlayPos + len; + if (end > nAudLoopLen) { + +// dprintf(_T(" %i - %i"), nSDLPlayPos, nSDLPlayPos + nAudLoopLen - nSDLPlayPos); + + SDL_MixAudio(stream, (Uint8*)SDLAudBuffer + nSDLPlayPos, nAudLoopLen - nSDLPlayPos, SDL_MIX_MAXVOLUME); + end -= nAudLoopLen; + +// dprintf(_T(", %i - %i (%i)"), 0, end, nAudLoopLen - nSDLPlayPos + end); + + SDL_MixAudio(stream + nAudLoopLen - nSDLPlayPos, (Uint8*)SDLAudBuffer, end, SDL_MIX_MAXVOLUME); + nSDLPlayPos = end; + } else { + SDL_MixAudio(stream, (Uint8*)SDLAudBuffer + nSDLPlayPos, len, SDL_MIX_MAXVOLUME); + nSDLPlayPos = end; + + if (nSDLPlayPos == nAudLoopLen) { + nSDLPlayPos = 0; } + } + +// dprintf(_T("\n")); +} + +static int SDLSoundGetNextSoundFiller(int) // int bDraw +{ + if (nAudNextSound == NULL) { + return 1; + } + memset(nAudNextSound, 0, nAudSegLen << 2); // Write silence into the buffer + + return 0; +} + +static int SDLSoundBlankSound() +{ + dprintf (_T("SDLBlankSound\n")); + if (nAudNextSound) { + dprintf (_T("blanking nAudNextSound\n")); + memset(nAudNextSound, 0, nAudSegLen << 2); + } + return 0; +} + +#define WRAP_INC(x) { x++; if (x >= nAudSegCount) x = 0; } + +static int SDLSoundCheck() +{ + int nPlaySeg, nFollowingSeg; + + if (!bAudPlaying) { + dprintf(_T("SDLSoundCheck (not playing)\n")); return 0; } - int blank() - { - dprintf (_T("SDLBlankSound\n")); + // Since the SDL buffer is smaller than a segment, only fill the buffer up to the start of the currently playing segment + nPlaySeg = nSDLPlayPos / (nAudSegLen << 2) - 1; - if (SDLAudBuffer) { - memset(SDLAudBuffer, 0, loopLen); - } +// dprintf(_T("SDLSoundCheck (seg %i)\n"), nPlaySeg); - if (pAudNextSound) { - dprintf (_T("blanking pAudNextSound\n")); - AudWriteSlience(); - } + if (nPlaySeg >= nAudSegCount) { + nPlaySeg -= nAudSegCount; + } + if (nPlaySeg < 0) { + nPlaySeg = nAudSegCount - 1; + } + + if (nSDLFillSeg == nPlaySeg) { + SDL_Delay(1); return 0; } - int check() - { - #define WRAP_INC(x) { x++; if (x >= nAudSegCount) x = 0; } + // work out which seg we will fill next + nFollowingSeg = nSDLFillSeg; + WRAP_INC(nFollowingSeg); - // Since the SDL buffer is smaller than a segment, - // only fill the buffer up to the start of the currently playing segment - int nPlaySeg = nSDLPlayPos / nAudAllocSegLen - 1; + while (nSDLFillSeg != nPlaySeg) { + int bDraw; - if (nPlaySeg >= nAudSegCount) { - nPlaySeg -= nAudSegCount; - } - if (nPlaySeg < 0) { - nPlaySeg = nAudSegCount - 1; - } + // fill nSDLFillSeg +// dprintf(_T("Filling seg %i at %i\n"), nSDLFillSeg, nSDLFillSeg * (nAudSegLen << 2)); - // dprintf(_T("SDLSoundCheck (seg %i)\n"), nPlaySeg); + bDraw = (nFollowingSeg == nPlaySeg);// || bAlwaysDrawFrames; // If this is the last seg of sound, flag bDraw (to draw the graphics) - if (nSDLFillSeg == nPlaySeg) { - SDL_Delay(1); - return 0; - } +// nAudNextSound = SDLAudBuffer + nSDLFillSeg * (nAudSegLen << 1); + GetNextSound(bDraw); // get more sound into nAudNextSound - // work out which seg we will fill next - int nFollowingSeg = nSDLFillSeg; +// if (nAudDSPModule) { +// DspDo(nAudNextSound, nAudSegLen); +// } + + memcpy((char*)SDLAudBuffer + nSDLFillSeg * (nAudSegLen << 2), nAudNextSound, nAudSegLen << 2); + + nSDLFillSeg = nFollowingSeg; WRAP_INC(nFollowingSeg); + } + + return 0; +} - while (nSDLFillSeg != nPlaySeg) { - // fill nSDLFillSeg - // dprintf(_T("Filling seg %i at %i\n"), nSDLFillSeg, nSDLFillSeg * (nAudAllocSegLen)); +static int SDLSoundExit() +{ + dprintf(_T("SDLSoundExit\n")); - memcpy((char*)SDLAudBuffer + nSDLFillSeg * nAudAllocSegLen, pAudNextSound, nAudAllocSegLen); + SDL_CloseAudio(); - // If this is the last seg of sound, flag bDraw (to draw the graphics) - int bDraw = (nFollowingSeg == nPlaySeg);// || !autoFrameSkip; + free(SDLAudBuffer); + SDLAudBuffer = NULL; - // pAudNextSound = SDLAudBuffer + nSDLFillSeg * (nAudSegLen << 1); - SDLGetNextSound(bDraw); // get more sound into pAudNextSound + free(nAudNextSound); + nAudNextSound = NULL; - if (nAudDSPModule & 1) { - if (bRunPause) - AudWriteSlience(); - else - DspDo(pAudNextSound, nAudSegLen); - } + return 0; +} - nSDLFillSeg = nFollowingSeg; - WRAP_INC(nFollowingSeg); - } +static int SDLSetCallback(int (*pCallback)(int)) +{ + if (pCallback == NULL) { + GetNextSound = SDLSoundGetNextSoundFiller; + } else { + GetNextSound = pCallback; + dprintf(_T("SDL callback set\n")); + } + return 0; +} - return 0; +static int SDLSoundInit() +{ + SDL_AudioSpec audiospec_req; + int nSDLBufferSize; + + dprintf(_T("SDLSoundInit (%dHz)"), nAudSampleRate); + + if (nAudSampleRate <= 0) { + return 1; } - int exit() - { - dprintf(_T("SDLSoundExit\n")); + nSoundFps = nAppVirtualFps; + nAudSegLen = (nAudSampleRate * 100 + (nSoundFps >> 1)) / nSoundFps; + nAudLoopLen = (nAudSegLen * nAudSegCount) << 2; + for (nSDLBufferSize = 64; nSDLBufferSize < (nAudSegLen >> 1); nSDLBufferSize <<= 1) { } - DspExit(); + audiospec_req.freq = nAudSampleRate; + audiospec_req.format = AUDIO_S16; + audiospec_req.channels = 2; + audiospec_req.samples = nSDLBufferSize; + audiospec_req.callback = audiospec_callback; - SDL_CloseAudio(); + SDLAudBuffer = (short*)malloc(nAudLoopLen); + if (SDLAudBuffer == NULL) { + dprintf(_T("Couldn't malloc SDLAudBuffer\n")); + SDLSoundExit(); + return 1; + } + memset(SDLAudBuffer, 0, nAudLoopLen); - free(SDLAudBuffer); - SDLAudBuffer = NULL; - - free(pAudNextSound); - pAudNextSound = NULL; - - return 0; + nAudNextSound = (short*)malloc(nAudSegLen << 2); + if (nAudNextSound == NULL) { + SDLSoundExit(); + return 1; } - void audiospec_callback(void* /* data */, Uint8* stream, int len) - { - // dprintf(_T("audiospec_callback %i"), len); + nAudNextSound = SDLAudBuffer; + nSDLPlayPos = 0; + nSDLFillSeg = nAudSegCount - 1; - int end = nSDLPlayPos + len; - if (end > loopLen) { - // dprintf(_T(" %i - %i"), nSDLPlayPos, nSDLPlayPos + loopLen - nSDLPlayPos); + if(SDL_OpenAudio(&audiospec_req, &audiospec)) { + fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); + dprintf(_T("Couldn't open audio: %s\n"), SDL_GetError()); + return 1; + } - SDL_MixAudio(stream, (Uint8*)SDLAudBuffer + nSDLPlayPos, loopLen - nSDLPlayPos, volume); - end -= loopLen; + SDLSetCallback(NULL); - // dprintf(_T(", %i - %i (%i)"), 0, end, loopLen - nSDLPlayPos + end); + return 0; +} - SDL_MixAudio(stream + loopLen - nSDLPlayPos, (Uint8*)SDLAudBuffer, end, volume); - nSDLPlayPos = end; - } else { - SDL_MixAudio(stream, (Uint8*)SDLAudBuffer + nSDLPlayPos, len, volume); - nSDLPlayPos = end; +static int SDLSoundPlay() +{ + dprintf(_T("SDLSoundPlay\n")); - if (nSDLPlayPos == loopLen) { - nSDLPlayPos = 0; - } - } + SDL_PauseAudio(0); + bAudPlaying = 1; - // dprintf(_T("\n")); - } + return 0; +} - int init() - { - dprintf(_T("SDLSoundInit (%dHz)"), nAudSampleRate); +static int SDLSoundStop() +{ + dprintf(_T("SDLSoundStop\n")); - if (nAudSampleRate <= 0) { - return 1; - } + SDL_PauseAudio(1); + bAudPlaying = 0; - fps = nAppVirtualFps; - nAudSegLen = (nAudSampleRate * 100 + (fps >> 1)) / fps; - nAudAllocSegLen = nAudSegLen << 2; - loopLen = (nAudSegLen * nAudSegCount) << 2; + return 0; +} - int nSDLBufferSize; - for (nSDLBufferSize = 64; nSDLBufferSize < (nAudSegLen >> 1); nSDLBufferSize <<= 1) { } +static int SDLSoundSetVolume() +{ + dprintf(_T("SDLSoundSetVolume\n")); + return 1; +} - SDL_AudioSpec audiospec_req; - audiospec_req.freq = nAudSampleRate; - audiospec_req.format = AUDIO_S16; - audiospec_req.channels = 2; - audiospec_req.samples = nSDLBufferSize; - audiospec_req.callback = audiospec_callback; +static int SDLGetSettings(InterfaceInfo* /* pInfo */) +{ + return 0; +} - SDLAudBuffer = (short*)malloc(loopLen); - if (SDLAudBuffer == NULL) { - dprintf(_T("Couldn't malloc SDLAudBuffer\n")); - exit(); - return 1; - } - memset(SDLAudBuffer, 0, loopLen); - - pAudNextSound = (short*)malloc(nAudAllocSegLen); - if (pAudNextSound == NULL) { - exit(); - return 1; - } - - nSDLPlayPos = 0; - nSDLFillSeg = nAudSegCount - 1; - - if (SDL_OpenAudio(&audiospec_req, &SDLAudioSpec)) { - fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); - dprintf(_T("Couldn't open audio: %s\n"), SDL_GetError()); - return 1; - } - - set(NULL); - - DspInit(); - - return 0; - } - - int play() - { - dprintf(_T("SDLSoundPlay\n")); - - SDL_PauseAudio(0); - - return 0; - } - - int stop() - { - dprintf(_T("SDLSoundStop\n")); - - SDL_PauseAudio(1); - - return 0; - } - - int setvolume(int vol) - { - dprintf(_T("SDLSoundSetVolume\n")); - - if (vol == 10000) { - volume = SDL_MIX_MAXVOLUME; - } else { - if (vol == 0) { - volume = 0; - } else { - volume = SDL_MIX_MAXVOLUME * vol / 10000; - } - } - - if (volume < 0) { - volume = 0; - } - - return 0; - } - - int get(void* info) - { - return 0; - } - - int setfps() - { - if (nAudSampleRate <= 0) { - return 0; - } - - return 0; - } - - AudioSDL() { - SDLAudBuffer = NULL; - nSDLPlayPos = 0; - nSDLFillSeg = 0; - - loopLen = 0; - fps = 0; - volume = SDL_MIX_MAXVOLUME; - } - - ~AudioSDL() { - exit(); - } -}; - -#endif +struct AudOut AudOutSDL = { SDLSoundBlankSound, SDLSoundCheck, SDLSoundInit, SDLSetCallback, SDLSoundPlay, SDLSoundStop, SDLSoundExit, SDLSoundSetVolume, SDLGetSettings, _T("SDL audio output") }; diff --git a/src/interface/input/sdl/inp_sdl.cpp b/src/interface/input/sdl/inp_sdl.cpp index 2a5fe88b0..6321a8fe3 100644 --- a/src/interface/input/sdl/inp_sdl.cpp +++ b/src/interface/input/sdl/inp_sdl.cpp @@ -1,15 +1,8 @@ // Module for input using SDL - -#ifdef BUILD_SDL +#include #include "burner.h" #include "inp_sdl_keys.h" -#include "../../lib/SDL/SDL.h" - -#ifdef _MSC_VER -#pragma comment(lib, "SDL") -#pragma comment(lib, "SDLmain") -#endif #define MAX_JOYSTICKS (8) @@ -81,11 +74,13 @@ int SDLinpExit() int SDLinpInit() { + int nSize; + SDLinpExit(); memset(&JoyList, 0, sizeof(JoyList)); - int nSize = MAX_JOYSTICKS * 8 * sizeof(int); + nSize = MAX_JOYSTICKS * 8 * sizeof(int); if ((JoyPrevAxes = (int*)malloc(nSize)) == NULL) { SDLinpExit(); return 1; @@ -185,11 +180,12 @@ int SDLinpJoyAxis(int i, int nAxis) // Read the keyboard static int ReadKeyboard() { + int numkeys; + if (bKeyboardRead) { // already read this frame - ready to go return 0; } - int numkeys; SDLinpKeyboardState = SDL_GetKeyState(&numkeys); if (SDLinpKeyboardState == NULL) { return 1; @@ -217,7 +213,7 @@ static int ReadMouse() // Read one mouse axis int SDLinpMouseAxis(int i, int nAxis) { - if (i < 0 || i >= 1) { // Only the system mouse is supported by SDL + if (i < 0 || i >= 1) { // Only the system mouse is supported by SDL return 0; } @@ -234,15 +230,15 @@ int SDLinpMouseAxis(int i, int nAxis) // Check a subcode (the 40xx bit in 4001, 4102 etc) for a joystick input code static int JoystickState(int i, int nSubCode) { - if (i < 0 || i >= nJoystickCount) { // This joystick isn't connected + if (i < 0 || i >= nJoystickCount) { // This joystick isn't connected return 0; } - if (ReadJoystick() != 0) { // Error polling the joystick + if (ReadJoystick() != 0) { // Error polling the joystick return 0; } - if (nSubCode < 0x10) { // Joystick directions + if (nSubCode < 0x10) { // Joystick directions const int DEADZONE = 0x4000; if (SDL_JoystickNumAxes(JoyList[i]) <= nSubCode) { @@ -319,10 +315,10 @@ int SDLinpState(int nCode) } if (nCode < 0x100) { - if (ReadKeyboard() != 0) { // Check keyboard has been read - return not pressed on error + if (ReadKeyboard() != 0) { // Check keyboard has been read - return not pressed on error return 0; } - return SDL_KEY_DOWN(nCode); // Return key state + return SDL_KEY_DOWN(nCode); // Return key state } if (nCode < 0x4000) { @@ -339,10 +335,10 @@ int SDLinpState(int nCode) if (nCode < 0xC000) { // Codes 8000-C000 = Mouse - if ((nCode - 0x8000) >> 8) { // Only the system mouse is supported by SDL + if ((nCode - 0x8000) >> 8) { // Only the system mouse is supported by SDL return 0; } - if (ReadMouse() != 0) { // Error polling the mouse + if (ReadMouse() != 0) { // Error polling the mouse return 0; } return CheckMouseState(nCode & 0xFF); @@ -354,7 +350,7 @@ int SDLinpState(int nCode) // This function finds which key is pressed, and returns its code int SDLinpFind(bool CreateBaseline) { - int nRetVal = -1; // assume nothing pressed + int nRetVal = -1; // assume nothing pressed // check if any keyboard keys are pressed if (ReadKeyboard() == 0) { @@ -369,11 +365,11 @@ int SDLinpFind(bool CreateBaseline) // Now check all the connected joysticks for (int i = 0; i < nJoystickCount; i++) { int j; - if (ReadJoystick() != 0) { // There was an error polling the joystick + if (ReadJoystick() != 0) { // There was an error polling the joystick continue; } - for (j = 0; j < 0x10; j++) { // Axes + for (j = 0; j < 0x10; j++) { // Axes int nDelta = JoyPrevAxes[(i << 3) + (j >> 1)] - SDLinpJoyAxis(i, (j >> 1)); if (nDelta < -0x4000 || nDelta > 0x4000) { if (JoystickState(i, j)) { @@ -383,7 +379,7 @@ int SDLinpFind(bool CreateBaseline) } } - for (j = 0x10; j < 0x20; j++) { // POV hats + for (j = 0x10; j < 0x20; j++) { // POV hats if (JoystickState(i, j)) { nRetVal = 0x4000 | (i << 8) | j; goto End; @@ -456,7 +452,7 @@ int SDLinpGetControlName(int nCode, TCHAR* pszDeviceName, TCHAR* pszControlName) if (i >= nJoystickCount) { // This joystick isn't connected return 0; } - _stprintf(pszDeviceName, _T("%hs"), SDL_JoystickName(i)); + _tsprintf(pszDeviceName, "%hs", SDL_JoystickName(i)); break; } @@ -475,6 +471,4 @@ int SDLinpGetControlName(int nCode, TCHAR* pszDeviceName, TCHAR* pszControlName) return 0; } -struct InputInOut InputInOutSDL = { SDLinpInit, SDLinpExit, SDLinpSetCooperativeLevel, SDLinpStart, SDLinpState, SDLinpJoyAxis, SDLinpMouseAxis, SDLinpFind, SDLinpGetControlName, NULL }; - -#endif +struct InputInOut InputInOutSDL = { SDLinpInit, SDLinpExit, SDLinpSetCooperativeLevel, SDLinpStart, SDLinpState, SDLinpJoyAxis, SDLinpMouseAxis, SDLinpFind, SDLinpGetControlName, NULL, _T("SDL input") }; diff --git a/src/interface/video/sdl/vid_sdlfx.cpp b/src/interface/video/sdl/vid_sdlfx.cpp index 7c94c69b7..7677b41e6 100644 --- a/src/interface/video/sdl/vid_sdlfx.cpp +++ b/src/interface/video/sdl/vid_sdlfx.cpp @@ -1,26 +1,20 @@ // Software blitter effects via SDL - -#ifdef BUILD_SDL - #include "burner.h" #include "vid_support.h" -#include "vid_filter.h" - -#ifdef _MSC_VER -#pragma comment(lib, "SDL") -#pragma comment(lib, "SDLmain") -#endif +#include "vid_softfx.h" static int nInitedSubsytems = 0; +static int nGameWidth = 0, nGameHeight = 0; // screen size SDL_Surface* sdlsBlitFX[2] = {NULL, }; // The image surfaces SDL_Surface* sdlsFramebuf = NULL; static int nSize; static int nUseBlitter; -static int nUseSys = 0; +static int nUseSys; static int nDirectAccess = 1; +static int nRotateGame = 0; static int PrimClear() { @@ -85,10 +79,9 @@ static int BlitFXInit() nVidImageHeight = nGameHeight; } -// if (nUseBlitter == FILTER_HQ2X || nUseBlitter == FILTER_HQ3X) { -// nVidImageDepth = 16; // Use 565 format -// } else - { + if (nUseBlitter >= 7 && nUseBlitter <= 9) { + nVidImageDepth = 16; // Use 565 format + } else { nVidImageDepth = sdlsFramebuf->format->BitsPerPixel;// Use color depth of primary surface } nVidImageBPP = sdlsFramebuf->format->BytesPerPixel; @@ -131,11 +124,33 @@ static int Init() SDL_InitSubSystem(SDL_INIT_VIDEO); } - nUseBlitter = nVidFilter;//nVidBlitterOpt[nVidSelect] & 0xFF; + nUseBlitter = nVidBlitterOpt[nVidSelect] & 0xFF; - VidInitInfo(); + nGameWidth = nVidImageWidth; nGameHeight = nVidImageHeight; - nSize = VidFilterGetZoom(nUseBlitter); + nRotateGame = 0; + if (bDrvOkay) { + // Get the game screen size + BurnDrvGetVisibleSize(&nGameWidth, &nGameHeight); + + if (BurnDrvGetFlags() & BDF_ORIENTATION_VERTICAL) { + if (nVidRotationAdjust & 1) { + int n = nGameWidth; + nGameWidth = nGameHeight; + nGameHeight = n; + nRotateGame |= (nVidRotationAdjust & 2); + } else { + nRotateGame |= 1; + } + } + + if (BurnDrvGetFlags() & BDF_ORIENTATION_FLIPPED) { + nRotateGame ^= 2; + } + } + + nSize = VidSoftFXGetZoom(nUseBlitter); + bVidScanlines = 0; // !!! if (nVidFullscreen) { @@ -156,8 +171,8 @@ static int Init() // Initialize the buffer surfaces BlitFXInit(); - if (VidFilterInit(nUseBlitter, nRotateGame)) { - if (VidFilterInit(0, nRotateGame)) { + if (VidSoftFXInit(nUseBlitter, nRotateGame)) { + if (VidSoftFXInit(0, nRotateGame)) { Exit(); return 1; } @@ -166,32 +181,14 @@ static int Init() return 0; } -static int vidScale(RECT* pRect, int nWidth, int nHeight) +static int vidScale(RECT* , int, int) { - if (vidUseFilter && vidForceFilterSize) { - return VidFilterScale(pRect, nWidth, nHeight); - } - - return VidSScaleImage(pRect, nWidth, nHeight); -} - -static int vidFilterApplyEffect(SDL_Surface* pSurf) -{ - // Lock the surface so we can write to it - if (SDL_LockSurface(pSurf)) { - return 1; - } - - VidFilterApplyEffect((unsigned char*)pSurf->pixels, pSurf->pitch); - - SDL_UnlockSurface(pSurf); - return 0; } static int MemToSurf() { - vidFilterApplyEffect(sdlsBlitFX[1 ^ nDirectAccess]); + VidSoftFXApplyEffectSDL(sdlsBlitFX[1 ^ nDirectAccess]); if (nUseSys == 0 && nDirectAccess == 0) { @@ -282,6 +279,9 @@ static int GetSettings(InterfaceInfo* pInfo) { TCHAR szString[MAX_PATH] = _T(""); + _sntprintf(szString, MAX_PATH, _T("Prescaling using %s (%i× zoom)"), VidSoftFXGetEffect(nUseBlitter), nSize); + IntInfoAddStringModule(pInfo, szString); + if (nRotateGame) { IntInfoAddStringModule(pInfo, _T("Using software rotation")); } @@ -290,6 +290,5 @@ static int GetSettings(InterfaceInfo* pInfo) } // The Video Output plugin: -struct VidOut VidOutSDLFX = { Init, Exit, Frame, Paint, vidScale, GetSettings }; +struct VidOut VidOutSDLFX = { Init, Exit, Frame, Paint, vidScale, GetSettings, _T("SDL Software Effects video output") }; -#endif diff --git a/src/interface/video/sdl/vid_sdlopengl.cpp b/src/interface/video/sdl/vid_sdlopengl.cpp index 515ea2aeb..a8da7e748 100644 --- a/src/interface/video/sdl/vid_sdlopengl.cpp +++ b/src/interface/video/sdl/vid_sdlopengl.cpp @@ -311,32 +311,21 @@ void SurfToTex() { memcpy(pd, ps, nPitch); } -/* if (nVidImageBPP==3) - { - glTexImage2D(GL_TEXTURE_2D, 0, nVidImageBPP, nTextureWidth, nTextureHeight, 0, color_type,texture_type, texture); - } - else -*/ { - glTexImage2D(GL_TEXTURE_2D, 0,3, nTextureWidth, nTextureHeight, 0, GL_RGB, texture_type, texture); - } + glTexImage2D(GL_TEXTURE_2D, 0,3, nTextureWidth, nTextureHeight, 0, GL_RGB, texture_type, texture); } void TexToQuad() { -// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer - // glColor3f(1,1,1); - glBegin(GL_QUADS); - glTexCoord2f(0,0); + glTexCoord2f(0,0); glVertex2i(0,0); - glTexCoord2f(0,1); + glTexCoord2f(0,1); glVertex2i(0,nTextureHeight); glTexCoord2f(1,1); glVertex2i(nTextureWidth,nTextureHeight); glTexCoord2f(1,0); glVertex2i(nTextureWidth,0); glEnd(); - //glFlush(); glFinish(); }