From a5c07a3fc0c02a8c24055f1dab573a3ba2d685c5 Mon Sep 17 00:00:00 2001 From: Jacopo Santoni Date: Mon, 27 Jan 2014 01:46:03 +0100 Subject: [PATCH 1/4] fixed some warnings --- Makefile.osx_lib | 3 ++- menu/main.cpp | 6 +++--- pocketsnes/snes9x/spc7110.cpp | 4 ++-- sal/include/sal_common.h | 2 +- sal/linux/sal.c | 1 + sal/linux/sal_sound.c | 4 ++-- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Makefile.osx_lib b/Makefile.osx_lib index 1e86b3b..d811dc5 100644 --- a/Makefile.osx_lib +++ b/Makefile.osx_lib @@ -22,7 +22,8 @@ endif INCLUDE = -I pocketsnes \ -I sal/linux/include -I sal/include \ -I pocketsnes/include \ - -I menu -I pocketsnes/linux -I pocketsnes/snes9x + -I menu -I pocketsnes/linux -I pocketsnes/snes9x \ + -I /Library/Frameworks/SDL.framework/headers CFLAGS = $(INCLUDE) -DRC_OPTIMIZED -D__LINUX__ -D__DINGUX__ \ -g -O3 -pipe -ffast-math $(SDL_CFLAGS) \ diff --git a/menu/main.cpp b/menu/main.cpp index 273a9e8..769fc01 100644 --- a/menu/main.cpp +++ b/menu/main.cpp @@ -98,12 +98,12 @@ bool8 S9xOpenSnapshotFile (const char *fname, bool8 read_only, STREAM *file) { if (read_only) { - if (*file = OPEN_STREAM(fname,"rb")) + if ((*file = OPEN_STREAM(fname,"rb"))) return(TRUE); } else { - if (*file = OPEN_STREAM(fname,"w+b")) + if ((*file = OPEN_STREAM(fname,"w+b"))) return(TRUE); } @@ -424,7 +424,7 @@ int Run(int sound) done++; if (mMenuOptions.frameSkip == 0) //Auto IPPU.RenderThisFrame = (done >= aim); - else if (IPPU.RenderThisFrame = (--skip <= 0)) + else if ((IPPU.RenderThisFrame = (--skip <= 0))) skip = mMenuOptions.frameSkip; //Run SNES for one glorious frame diff --git a/pocketsnes/snes9x/spc7110.cpp b/pocketsnes/snes9x/spc7110.cpp index ac835a6..f6aab8c 100644 --- a/pocketsnes/snes9x/spc7110.cpp +++ b/pocketsnes/snes9x/spc7110.cpp @@ -1391,14 +1391,14 @@ void S9xSetSPC7110 (uint8 data, uint16 Address) } if(0x0F==rtc_f9.index) { - if(data&0x01&&!(rtc_f9.reg[0x0F]&0x01)) + if((data & 0x01) &&!(rtc_f9.reg[0x0F]&0x01)) { S9xUpdateRTC(); rtc_f9.reg[0]=0; rtc_f9.reg[1]=0; rtc_f9.last_used=time(NULL); } - if(data&0x02&&!(rtc_f9.reg[0x0F]&0x02)) + if((data & 0x02) &&!(rtc_f9.reg[0x0F]&0x02)) { S9xUpdateRTC(); rtc_f9.last_used=time(NULL); diff --git a/sal/include/sal_common.h b/sal/include/sal_common.h index 61280bb..3721cb1 100644 --- a/sal/include/sal_common.h +++ b/sal/include/sal_common.h @@ -66,7 +66,7 @@ s32 sal_AudioInit(s32 rate, s32 bits, s32 stereo, s32 Hz); void sal_AudioPause(void); void sal_AudioResume(void); void sal_AudioClose(void); -u32 sal_AudioGenerate(u32 samples); +void sal_AudioGenerate(u32 samples); u32 sal_AudioGetFramesBuffered(); u32 sal_AudioGetMaxFrames(); u32 sal_AudioGetSamplesPerFrame(); diff --git a/sal/linux/sal.c b/sal/linux/sal.c index 37d164f..60f35e2 100644 --- a/sal/linux/sal.c +++ b/sal/linux/sal.c @@ -58,6 +58,7 @@ static u32 sal_Input(int held) CASE(LEFT, LEFT); CASE(RIGHT, RIGHT); CASE(HOME, MENU); + default: break; } mInputRepeat = inputHeld; diff --git a/sal/linux/sal_sound.c b/sal/linux/sal_sound.c index 69279bc..62277c7 100644 --- a/sal/linux/sal_sound.c +++ b/sal/linux/sal_sound.c @@ -45,7 +45,7 @@ s32 sal_AudioInit(s32 rate, s32 bits, s32 stereo, s32 Hz) audiospec.format = AUDIO_S16; audiospec.samples = (rate / Hz); - if (!stereo && audiospec.samples & 1) + if (!stereo && (audiospec.samples & 1)) audiospec.samples--; @@ -80,7 +80,7 @@ void sal_AudioClose(void) SDL_CloseAudio(); } -u32 sal_AudioGenerate(u32 samples) +void sal_AudioGenerate(u32 samples) { u32 SamplesAvailable, LocalReadPos = ReadPos /* isolate a bit against races */; if (LocalReadPos <= WritePos) From 001533ca5887c2ea18da172491f3f9b273670b82 Mon Sep 17 00:00:00 2001 From: Jacopo Santoni Date: Mon, 27 Jan 2014 20:12:26 +0100 Subject: [PATCH 2/4] misc compilation fixes for clang++ and added gcwinterface.cpp --- Makefile.osx_lib | 15 +++++++-------- menu/gcwinterface.cpp | 27 +++++++++++++++++++++++++++ pocketsnes/snes9x/apu.cpp | 6 +++--- pocketsnes/snes9x/dma.cpp | 4 ++-- pocketsnes/snes9x/memmap.cpp | 2 +- pocketsnes/snes9x/snapshot.cpp | 30 +++++++++++++++--------------- sal/unzip.c | 2 +- sal/zip.c | 4 ++-- 8 files changed, 58 insertions(+), 32 deletions(-) create mode 100644 menu/gcwinterface.cpp diff --git a/Makefile.osx_lib b/Makefile.osx_lib index d811dc5..17618ee 100644 --- a/Makefile.osx_lib +++ b/Makefile.osx_lib @@ -3,11 +3,10 @@ TARGET = PocketSNES.dylib -CC := $(CROSS_COMPILE)gcc -CXX := $(CROSS_COMPILE)g++ +CC := $(CROSS_COMPILE)clang +CXX := $(CROSS_COMPILE)clang++ STRIP := $(CROSS_COMPILE)strip -SYSROOT := $(shell $(CC) --print-sysroot) SDL_CFLAGS := `sdl-config --cflags` SDL_LIBS := `sdl-config --libs` @@ -26,12 +25,12 @@ INCLUDE = -I pocketsnes \ -I /Library/Frameworks/SDL.framework/headers CFLAGS = $(INCLUDE) -DRC_OPTIMIZED -D__LINUX__ -D__DINGUX__ \ - -g -O3 -pipe -ffast-math $(SDL_CFLAGS) \ - -flto +# -g -O3 -pipe -ffast-math \ + $(SDL_CFLAGS) -flto -CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti +CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -std=c++0x -stdlib=libc++ -LDFLAGS = -dynamiclib $(CXXFLAGS) -lpthread -lz -lpng -lm -lgcc $(SDL_LIBS) +LDFLAGS = -dynamiclib $(CXXFLAGS) -lpthread -lz -lpng -lm $(SDL_LIBS) # Find all source files SOURCE = pocketsnes/snes9x menu sal/linux sal @@ -65,7 +64,7 @@ $(TARGET).opk: $(TARGET) %.o: %.cpp $(SUM) " CXX $@" - $(CMD)$(CXX) $(CFLAGS) -c $< -o $@ + $(CMD)$(CXX) $(CXXFLAGS) -c $< -o $@ .PHONY : clean clean : diff --git a/menu/gcwinterface.cpp b/menu/gcwinterface.cpp new file mode 100644 index 0000000..cbda8be --- /dev/null +++ b/menu/gcwinterface.cpp @@ -0,0 +1,27 @@ +#include "../../emu_interface.h" + + +extern "C" int mainEntry(int argc, char** argv); + +using namespace std; + +class PocketSnesEmulator : public CoreInterface +{ + private: + + public: + PocketSnesEmulator() + { + registerInformations(CONSOLE_SUPER_NINTENDO, "pocketsnes", "PocketSNES", "1.0"); + registerExtension("smc"); + } + + virtual void run(int argc, char **argv) { mainEntry(argc, argv); } +}; + +static PocketSnesEmulator emulator; + +extern "C" CoreInterface* retrieve() +{ + return &emulator; +} diff --git a/pocketsnes/snes9x/apu.cpp b/pocketsnes/snes9x/apu.cpp index 769d2bc..90bfb1a 100644 --- a/pocketsnes/snes9x/apu.cpp +++ b/pocketsnes/snes9x/apu.cpp @@ -744,7 +744,7 @@ void S9xFixEnvelope (int channel, uint8 gain, uint8 adsr1, uint8 adsr2) 1200, 740, 440, 290, 180, 110, 74, 37 }; static unsigned long SustainRate [32] = { - ~0, 38000, 28000, 24000, 19000, 14000, 12000, 9400, + (unsigned long)~0, 38000, 28000, 24000, 19000, 14000, 12000, 9400, 7100, 5900, 4700, 3500, 2900, 2400, 1800, 1500, 1200, 880, 740, 590, 440, 370, 290, 220, 180, 150, 110, 92, 74, 55, 37, 18 @@ -786,13 +786,13 @@ void S9xFixEnvelope (int channel, uint8 gain, uint8 adsr1, uint8 adsr2) else { static unsigned long IncreaseRate [32] = { - ~0, 4100, 3100, 2600, 2000, 1500, 1300, 1000, + (unsigned long)~0, 4100, 3100, 2600, 2000, 1500, 1300, 1000, 770, 640, 510, 380, 320, 260, 190, 160, 130, 96, 80, 64, 48, 40, 32, 24, 20, 16, 12, 10, 8, 6, 4, 2 }; static unsigned long DecreaseRateExp [32] = { - ~0, 38000, 28000, 24000, 19000, 14000, 12000, 9400, + (unsigned long)~0, 38000, 28000, 24000, 19000, 14000, 12000, 9400, 7100, 5900, 4700, 3500, 2900, 2400, 1800, 1500, 1200, 880, 740, 590, 440, 370, 290, 220, 180, 150, 110, 92, 74, 55, 37, 18 diff --git a/pocketsnes/snes9x/dma.cpp b/pocketsnes/snes9x/dma.cpp index 96f705f..fb1c5e5 100644 --- a/pocketsnes/snes9x/dma.cpp +++ b/pocketsnes/snes9x/dma.cpp @@ -260,12 +260,12 @@ void S9xDoDMA (uint8 Channel) for (uint32 i = 0; i < Memory.SDD1LoggedDataCount; i++, p += 8) { - if (*p == d->ABank || + if (*p == d->ABank || ( *(p + 1) == (d->AAddress >> 8) && *(p + 2) == (d->AAddress & 0xff) && *(p + 3) == (count >> 8) && *(p + 4) == (count & 0xff) && - *(p + 7) == SDD1Bank) + *(p + 7) == SDD1Bank) ) { found = TRUE; break; diff --git a/pocketsnes/snes9x/memmap.cpp b/pocketsnes/snes9x/memmap.cpp index 20110f9..cd1f8dc 100644 --- a/pocketsnes/snes9x/memmap.cpp +++ b/pocketsnes/snes9x/memmap.cpp @@ -2484,7 +2484,7 @@ void CMemory::TalesROMMap (bool8 Interleaved) if((strncmp("TALES",(char*)Map[8]+0xFFC0, 5)==0)) { - if(((*(Map[8]+0xFFDE))==(*(Map[0x808]+0xFFDE)))) + if((*(Map[8]+0xFFDE))==(*(Map[0x808]+0xFFDE))) { Settings.DisplayColor=BUILD_PIXEL(31,0,0); SET_UI_COLOR(255,0,0); diff --git a/pocketsnes/snes9x/snapshot.cpp b/pocketsnes/snes9x/snapshot.cpp index c2f14f6..e5252cc 100644 --- a/pocketsnes/snes9x/snapshot.cpp +++ b/pocketsnes/snes9x/snapshot.cpp @@ -325,21 +325,21 @@ static FreezeData SnapPPU [] = { static FreezeData SnapDMA [] = { #define O(N) \ - {OFFSET (TransferDirection) + N * sizeof (struct SDMA), 1, INT_V}, \ - {OFFSET (AAddressFixed) + N * sizeof (struct SDMA), 1, INT_V}, \ - {OFFSET (AAddressDecrement) + N * sizeof (struct SDMA), 1, INT_V}, \ - {OFFSET (TransferMode) + N * sizeof (struct SDMA), 1, INT_V}, \ - {OFFSET (ABank) + N * sizeof (struct SDMA), 1, INT_V}, \ - {OFFSET (AAddress) + N * sizeof (struct SDMA), 2, INT_V}, \ - {OFFSET (Address) + N * sizeof (struct SDMA), 2, INT_V}, \ - {OFFSET (BAddress) + N * sizeof (struct SDMA), 1, INT_V}, \ - {OFFSET (TransferBytes) + N * sizeof (struct SDMA), 2, INT_V}, \ - {OFFSET (HDMAIndirectAddressing) + N * sizeof (struct SDMA), 1, INT_V}, \ - {OFFSET (IndirectAddress) + N * sizeof (struct SDMA), 2, INT_V}, \ - {OFFSET (IndirectBank) + N * sizeof (struct SDMA), 1, INT_V}, \ - {OFFSET (Repeat) + N * sizeof (struct SDMA), 1, INT_V}, \ - {OFFSET (LineCount) + N * sizeof (struct SDMA), 1, INT_V}, \ - {OFFSET (FirstLine) + N * sizeof (struct SDMA), 1, INT_V} + {(int) (OFFSET (TransferDirection) + N * sizeof (struct SDMA)), 1, INT_V}, \ + {(int) (OFFSET (AAddressFixed) + N * sizeof (struct SDMA)), 1, INT_V}, \ + {(int) (OFFSET (AAddressDecrement) + N * sizeof (struct SDMA)), 1, INT_V}, \ + {(int) (OFFSET (TransferMode) + N * sizeof (struct SDMA)), 1, INT_V}, \ + {(int) (OFFSET (ABank) + N * sizeof (struct SDMA)), 1, INT_V}, \ + {(int) (OFFSET (AAddress) + N * sizeof (struct SDMA)), 2, INT_V}, \ + {(int) (OFFSET (Address) + N * sizeof (struct SDMA)), 2, INT_V}, \ + {(int) (OFFSET (BAddress) + N * sizeof (struct SDMA)), 1, INT_V}, \ + {(int) (OFFSET (TransferBytes) + N * sizeof (struct SDMA)), 2, INT_V}, \ + {(int) (OFFSET (HDMAIndirectAddressing) + N * sizeof (struct SDMA)), 1, INT_V}, \ + {(int) (OFFSET (IndirectAddress) + N * sizeof (struct SDMA)), 2, INT_V}, \ + {(int) (OFFSET (IndirectBank) + N * sizeof (struct SDMA)), 1, INT_V}, \ + {(int) (OFFSET (Repeat) + N * sizeof (struct SDMA)), 1, INT_V}, \ + {(int) (OFFSET (LineCount) + N * sizeof (struct SDMA)), 1, INT_V}, \ + {(int) (OFFSET (FirstLine) + N * sizeof (struct SDMA)), 1, INT_V} O(0), O(1), O(2), O(3), O(4), O(5), O(6), O(7) #undef O diff --git a/sal/unzip.c b/sal/unzip.c index 473b665..904ae41 100644 --- a/sal/unzip.c +++ b/sal/unzip.c @@ -1239,7 +1239,7 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len) return UNZ_PARAMERROR; - if ((pfile_in_zip_read_info->read_buffer == NULL)) + if (pfile_in_zip_read_info->read_buffer == NULL) return UNZ_END_OF_LIST_OF_FILE; if (len==0) return 0; diff --git a/sal/zip.c b/sal/zip.c index 95a83e2..acb57dd 100644 --- a/sal/zip.c +++ b/sal/zip.c @@ -758,9 +758,9 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, zi->ci.flag = 0; if ((level==8) || (level==9)) zi->ci.flag |= 2; - if ((level==2)) + if (level==2) zi->ci.flag |= 4; - if ((level==1)) + if (level==1) zi->ci.flag |= 6; if (password != NULL) zi->ci.flag |= 1; From 033db5e0ca067a5f5ee5d1777866a3cb58f46867 Mon Sep 17 00:00:00 2001 From: Jacopo Santoni Date: Mon, 27 Jan 2014 23:41:42 +0100 Subject: [PATCH 3/4] added Makefile.osx to compile on OS X --- Makefile.osx | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Makefile.osx diff --git a/Makefile.osx b/Makefile.osx new file mode 100644 index 0000000..c071666 --- /dev/null +++ b/Makefile.osx @@ -0,0 +1,73 @@ + +# Define the applications properties here: + +TARGET = PocketSNES + +CC := $(CROSS_COMPILE)clang +CXX := $(CROSS_COMPILE)clang++ +STRIP := $(CROSS_COMPILE)strip + +SDL_CFLAGS := `sdl-config --cflags` +SDL_LIBS := `sdl-config --libs` + +ifdef V + CMD:= + SUM:=@\# +else + CMD:=@ + SUM:=@echo +endif + +INCLUDE = -I pocketsnes \ + -I sal/linux/include -I sal/include \ + -I pocketsnes/include \ + -I menu -I pocketsnes/linux -I pocketsnes/snes9x \ + -I /Library/Frameworks/SDL.framework/headers + +CFLAGS = $(INCLUDE) -DRC_OPTIMIZED -D__LINUX__ -D__DINGUX__ \ +# -g -O3 -pipe -ffast-math \ + $(SDL_CFLAGS) -flto + +CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -std=c++0x -stdlib=libc++ + +LDFLAGS = $(CXXFLAGS) -lpthread -lz -lpng -lm $(SDL_LIBS) + +# Find all source files +SOURCE = pocketsnes/snes9x menu sal/linux sal +SRC_CPP = $(foreach dir, $(SOURCE), $(wildcard $(dir)/*.cpp)) +SRC_C = $(foreach dir, $(SOURCE), $(wildcard $(dir)/*.c)) +OBJ_CPP = $(patsubst %.cpp, %.o, $(SRC_CPP)) +OBJ_C = $(patsubst %.c, %.o, $(SRC_C)) +OBJS = $(OBJ_CPP) $(OBJ_C) + +.PHONY : all +all : $(TARGET) + +.PHONY: opk +opk: $(TARGET).opk + +$(TARGET) : $(OBJS) + $(SUM) " LD $@" + $(CMD)$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) + +$(TARGET).opk: $(TARGET) + $(SUM) " OPK $@" + $(CMD)rm -rf .opk_data + $(CMD)cp -r data .opk_data + $(CMD)cp $< .opk_data/pocketsnes.gcw0 + $(CMD)$(STRIP) .opk_data/pocketsnes.gcw0 + $(CMD)mksquashfs .opk_data $@ -all-root -noappend -no-exports -no-xattrs -no-progress >/dev/null + +%.o: %.c + $(SUM) " CC $@" + $(CMD)$(CC) $(CFLAGS) -c $< -o $@ + +%.o: %.cpp + $(SUM) " CXX $@" + $(CMD)$(CXX) $(CXXFLAGS) -c $< -o $@ + +.PHONY : clean +clean : + $(SUM) " CLEAN ." + $(CMD)rm -f $(OBJS) $(TARGET) + $(CMD)rm -rf .opk_data $(TARGET).opk From a2ace31872bf55d9662e2e1036e6a2b301496b6a Mon Sep 17 00:00:00 2001 From: Jacopo Santoni Date: Mon, 27 Jan 2014 23:45:02 +0100 Subject: [PATCH 4/4] moved gcwinterface to its own folder and fixed libpng bit depth bug --- {menu => gcwloader}/gcwinterface.cpp | 0 sal/sal_common.c | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) rename {menu => gcwloader}/gcwinterface.cpp (100%) diff --git a/menu/gcwinterface.cpp b/gcwloader/gcwinterface.cpp similarity index 100% rename from menu/gcwinterface.cpp rename to gcwloader/gcwinterface.cpp diff --git a/sal/sal_common.c b/sal/sal_common.c index c5f9480..fb5b4ee 100644 --- a/sal/sal_common.c +++ b/sal/sal_common.c @@ -928,7 +928,8 @@ s32 sal_ImageLoad(const char *fname, void *dest, u32 width, u32 height) u32 h; unsigned short *dst = dest; - if (png_get_bit_depth(png_ptr, info_ptr) != 24) + + if (png_get_bit_depth(png_ptr, info_ptr) != 8 || png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_RGB) { sal_LastErrorSet("bg image not 24bpp"); png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : NULL, (png_infopp)NULL);