Skip to content
This repository has been archived by the owner on Jan 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #8 from JacopoSantoni/master
Browse files Browse the repository at this point in the history
Fix libpng bug introduced by my previous pull request + misc fixes
  • Loading branch information
Nebuleon committed Jan 27, 2014
2 parents 2c27d4e + a2ace31 commit 8cc84c1
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 42 deletions.
73 changes: 73 additions & 0 deletions Makefile.osx
Original file line number Diff line number Diff line change
@@ -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
18 changes: 9 additions & 9 deletions Makefile.osx_lib
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -22,15 +21,16 @@ 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) \
-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
Expand Down Expand Up @@ -64,7 +64,7 @@ $(TARGET).opk: $(TARGET)

%.o: %.cpp
$(SUM) " CXX $@"
$(CMD)$(CXX) $(CFLAGS) -c $< -o $@
$(CMD)$(CXX) $(CXXFLAGS) -c $< -o $@

.PHONY : clean
clean :
Expand Down
27 changes: 27 additions & 0 deletions gcwloader/gcwinterface.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 3 additions & 3 deletions menu/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pocketsnes/snes9x/apu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pocketsnes/snes9x/dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pocketsnes/snes9x/memmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions pocketsnes/snes9x/snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pocketsnes/snes9x/spc7110.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sal/include/sal_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions sal/linux/sal.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static u32 sal_Input(int held)
CASE(LEFT, LEFT);
CASE(RIGHT, RIGHT);
CASE(HOME, MENU);
default: break;
}

mInputRepeat = inputHeld;
Expand Down
4 changes: 2 additions & 2 deletions sal/linux/sal_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;


Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion sal/sal_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sal/unzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions sal/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8cc84c1

Please sign in to comment.