From 9b525dba5742728b530baaf3b0fe509e9e7d56c2 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Sat, 29 Sep 2018 12:04:39 +0100 Subject: [PATCH 1/5] Fixed memory locations --- Makefile.linux | 65 +++++++++++++++++++++++++++++++++ src/Application.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 Makefile.linux diff --git a/Makefile.linux b/Makefile.linux new file mode 100644 index 0000000..9f9b62c --- /dev/null +++ b/Makefile.linux @@ -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 -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 diff --git a/src/Application.cpp b/src/Application.cpp index 1ccb70f..1adbb0d 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -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; @@ -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: @@ -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[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); + address += 1024; + fill -= 1024; + } + + if (fill != 0) + { + registerMemoryRegion(&numBanks, 0, _1k, fill); + address += fill; + } + } + + if (layout[i].len != 0) + { + registerMemoryRegion(&numBanks, 0, layout[i].ptr, layout[i].len); + address += layout[i].len; + } + + } + } + + 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++) @@ -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; From 05e33fdbd06a4f5fcca08660fd24ef832cca27f7 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Sat, 29 Sep 2018 12:30:48 +0100 Subject: [PATCH 2/5] Use SDL2.dll instead of static linking --- Makefile.linux | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.linux b/Makefile.linux index 9f9b62c..f7cb953 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -9,7 +9,7 @@ DEFINES=-DOUTSIDE_SPEEX -DRANDOM_PREFIX=speex -DEXPORT= -D_USE_SSE2 -DFIXED_POIN CFLAGS=-Wall -m32 LDFLAGS=\ - -m32 -Lsrc/SDL2/lib/x86 -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lwinhttp -lwinmm \ + -m32 -Lsrc/SDL2/lib/x86 -lmingw32 -lSDL2main -lSDL2.dll -lopengl32 -lwinhttp -lwinmm \ -lgdi32 -lversion -limm32 -lole32 -loleaut32 -lcomdlg32 -static-libstdc++ ifeq ($(DEBUG), 1) From ea241ba717357bc0dde1c265d59ce958fe17c1d5 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Sat, 29 Sep 2018 12:31:00 +0100 Subject: [PATCH 3/5] Do less work --- src/Application.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 1adbb0d..c4fe14d 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -798,23 +798,21 @@ bool Application::loadGame(const std::string& path) while (fill > 1024) { registerMemoryRegion(&numBanks, 0, _1k, 1024); - address += 1024; fill -= 1024; } if (fill != 0) { registerMemoryRegion(&numBanks, 0, _1k, fill); - address += fill; } } if (layout[i].len != 0) { registerMemoryRegion(&numBanks, 0, layout[i].ptr, layout[i].len); - address += layout[i].len; } + address = layout[i].start + layout[i].len; } } From 7a101923c388b698527c7d726f126e93c92abbd8 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Sat, 29 Sep 2018 14:21:48 +0100 Subject: [PATCH 4/5] Fix usage of gcc-only extension --- src/Application.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Application.cpp b/src/Application.cpp index c4fe14d..2f7f4a4 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -742,7 +742,7 @@ bool Application::loadGame(const std::string& path) case Emulator::kGambatte: { const struct retro_memory_map* mmap = _core.getMemoryMap(); - struct retro_memory_descriptor layout[mmap->num_descriptors + 2]; + 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}; @@ -814,6 +814,8 @@ bool Application::loadGame(const std::string& path) address = layout[i].start + layout[i].len; } + + delete[] layout; } break; From 6b23a32ab236f71f60d7331265faf7a5e6630978 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Sat, 29 Sep 2018 16:01:27 +0100 Subject: [PATCH 5/5] Updated SDL2 to include MinGW libraries --- src/SDL2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SDL2 b/src/SDL2 index 488eaa6..20dd1cd 160000 --- a/src/SDL2 +++ b/src/SDL2 @@ -1 +1 @@ -Subproject commit 488eaa601709c872fcfc72b14a45993905f92136 +Subproject commit 20dd1cda543e478633aab74282111ece96497cb6