Skip to content

Commit

Permalink
Merge branch 'feature/fix_gambatte' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
leiradel committed Sep 29, 2018
2 parents 93a9478 + 6b23a32 commit eee25ff
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 5 deletions.
65 changes: 65 additions & 0 deletions Makefile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# sudo apt-get install mingw-w64

CC=i686-w64-mingw32-gcc
CXX=i686-w64-mingw32-g++
RC=i686-w64-mingw32-windres

INCLUDES=-Isrc -I./src/RA_Integration/src -I./src/RA_Integration/src/rapidjson/include -Isrc/SDL2/include
DEFINES=-DOUTSIDE_SPEEX -DRANDOM_PREFIX=speex -DEXPORT= -D_USE_SSE2 -DFIXED_POINT
CFLAGS=-Wall -m32

LDFLAGS=\
-m32 -Lsrc/SDL2/lib/x86 -lmingw32 -lSDL2main -lSDL2.dll -lopengl32 -lwinhttp -lwinmm \
-lgdi32 -lversion -limm32 -lole32 -loleaut32 -lcomdlg32 -static-libstdc++

ifeq ($(DEBUG), 1)
CFLAGS+=-O0 -g -DDEBUG_FSM -DLOG_TO_FILE
else
CFLAGS+=-O3 -DNDEBUG -DLOG_TO_FILE
endif

CXXFLAGS=$(CFLAGS) -std=c++11

# main
OBJS=\
src/dynlib/dynlib.o src/jsonsax/jsonsax.o src/libretro/BareCore.o src/libretro/Core.o \
src/RA_Implementation.o src/RA_Integration/src/RA_Interface.o src/components/Audio.o \
src/components/Config.o src/components/Dialog.o src/components/Input.o \
src/components/Logger.o src/components/Video.o src/speex/resample.o src/About.o \
src/Application.o src/Emulator.o src/Fsm.o src/Git.o src/Gl.o src/GlUtil.o \
src/KeyBinds.o src/main.o src/menu.res src/Util.o

%.o: %.cpp
$(CXX) $(INCLUDES) $(DEFINES) $(CXXFLAGS) -c $< -o $@

%.o: %.c
$(CC) $(INCLUDES) $(DEFINES) $(CFLAGS) -c $< -o $@

%.res: %.rc
$(RC) $< -O coff -o $@

all: bin/RALibretro.exe

bin/RALibretro.exe: $(OBJS)
mkdir -p bin
$(CXX) -o $@ $+ $(LDFLAGS)

src/Git.cpp: etc/Git.cpp.template FORCE
cat $< | sed s/GITFULLHASH/`git rev-parse HEAD | tr -d "\n"`/g | sed s/GITMINIHASH/`git rev-parse HEAD | tr -d "\n" | cut -c 1-7`/g | sed s/GITRELEASE/`git describe | tr -d "\n"`/g > $@

zip:
rm -f bin/RALibretro-*.zip RALibretro-*.zip
zip -9 RALibretro-`git describe | tr -d "\n"`.zip bin/RALibretro.exe

clean:
rm -f bin/RALibretro $(OBJS) bin/RALibretro-*.zip RALibretro-*.zip

pack:
ifeq ("", "$(wildcard bin/RALibretro.exe)")
echo '"bin/RALibretro.exe" not found!'
else
rm -f bin/RALibretro-*.zip RALibretro-*.zip
zip -9r RALibretro-pack-`git describe | tr -d "\n"`.zip bin
endif

.PHONY: clean FORCE
89 changes: 85 additions & 4 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ bool Application::loadGame(const std::string& path)
}
}

static uint8_t _1k[1024] = {0};

_memoryBanks[0].count = 0;
_memoryBanks[1].count = 0;
unsigned numBanks = 0;
Expand All @@ -717,7 +719,6 @@ bool Application::loadGame(const std::string& path)
case Emulator::kGenesisPlusGx:
case Emulator::kHandy:
case Emulator::kBeetleSgx:
case Emulator::kGambatte:
case Emulator::kMednafenPsx:
case Emulator::kMednafenNgp:
case Emulator::kFBAlpha:
Expand All @@ -738,15 +739,95 @@ bool Application::loadGame(const std::string& path)

break;

case Emulator::kGambatte:
{
const struct retro_memory_map* mmap = _core.getMemoryMap();
struct retro_memory_descriptor* layout = new struct retro_memory_descriptor[mmap->num_descriptors + 2];
memcpy(layout, mmap->descriptors, mmap->num_descriptors * sizeof(struct retro_memory_descriptor));

layout[mmap->num_descriptors + 1] = {0, NULL, 0, 0x10000, 0, 0, 0, NULL};

for (unsigned i = 0; i < mmap->num_descriptors; i++)
{
if (layout[i].start == 0xc000)
{
layout[mmap->num_descriptors] = layout[i];
layout[mmap->num_descriptors].start = 0xe000;
layout[mmap->num_descriptors].len = 0x1e00;
}
else if (mmap->descriptors[i].start == 0xa000)
{
if (layout[i].len > 0x2000)
{
layout[i].len = 0x2000;
}
}
}

struct Comparator {
static int compare(const void* e1, const void* e2)
{
auto d1 = (const struct retro_memory_descriptor*)e1;
auto d2 = (const struct retro_memory_descriptor*)e2;

if (d1->start < d2->start)
{
return -1;
}
else if (d1->start > d2->start)
{
return 1;
}
else
{
return 0;
}
}
};

qsort(layout, mmap->num_descriptors + 2, sizeof(struct retro_memory_descriptor), Comparator::compare);

size_t address = 0;

for (unsigned i = 0; i < mmap->num_descriptors + 2; i++)
{
if (layout[i].start > address)
{
size_t fill = layout[i].start - address;

while (fill > 1024)
{
registerMemoryRegion(&numBanks, 0, _1k, 1024);
fill -= 1024;
}

if (fill != 0)
{
registerMemoryRegion(&numBanks, 0, _1k, fill);
}
}

if (layout[i].len != 0)
{
registerMemoryRegion(&numBanks, 0, layout[i].ptr, layout[i].len);
}

address = layout[i].start + layout[i].len;
}

delete[] layout;
}

break;

case Emulator::kFceumm:
{
static const uint8_t _1k[1024] = {0};
const struct retro_memory_map* mmap = _core.getMemoryMap();
void* pointer[64];

for (unsigned i = 0; i < 64; i++)
{
pointer[i] = (void*)_1k;
pointer[i] = _1k;
}

for (unsigned i = 0; i < mmap->num_descriptors; i++)
Expand Down Expand Up @@ -1369,7 +1450,7 @@ void Application::loadRecentList()
Deserialize ud;
ud.self = this;

jsonsax_result_t res = jsonsax_parse((char*)data, &ud, [](void* udata, jsonsax_event_t event, const char* str, size_t num)
jsonsax_parse((char*)data, &ud, [](void* udata, jsonsax_event_t event, const char* str, size_t num)
{
auto ud = (Deserialize*)udata;

Expand Down

0 comments on commit eee25ff

Please sign in to comment.