From 274ef6a796234254f7fffe8249bbd8da8cd830cd Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Fri, 9 Oct 2020 10:31:15 +0100 Subject: [PATCH] Fix sa2 to work with recent code. Signed-off-by: Andrea Odetti --- source/frontends/ncurses/resources.cpp | 11 ++++++++--- source/frontends/ncurses/resources.h | 3 +++ source/frontends/sa2/bitmaps.cpp | 15 +++++++++------ source/frontends/sa2/main.cpp | 19 ++++++++++--------- 4 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 source/frontends/ncurses/resources.h diff --git a/source/frontends/ncurses/resources.cpp b/source/frontends/ncurses/resources.cpp index 343505b7..2175da74 100644 --- a/source/frontends/ncurses/resources.cpp +++ b/source/frontends/ncurses/resources.cpp @@ -25,7 +25,7 @@ namespace } } - std::string getResourcePath() + std::string getResourcePathImpl() { char self[1024] = {0}; const int ch = readlink("/proc/self/exe", self, sizeof(self)); @@ -51,7 +51,12 @@ namespace return std::string(); } - const std::string resourcePath = getResourcePath(); +} + +const std::string & getResourcePath() +{ + static const std::string path = getResourcePathImpl(); + return path; } HRSRC FindResource(void *, const char * filename, const char *) @@ -60,7 +65,7 @@ HRSRC FindResource(void *, const char * filename, const char *) if (filename) { - const std::string path = resourcePath + filename; + const std::string path = getResourcePath() + filename; int fd = open(path.c_str(), O_RDONLY); diff --git a/source/frontends/ncurses/resources.h b/source/frontends/ncurses/resources.h new file mode 100644 index 00000000..b092e587 --- /dev/null +++ b/source/frontends/ncurses/resources.h @@ -0,0 +1,3 @@ +#include + +const std::string & getResourcePath(); diff --git a/source/frontends/sa2/bitmaps.cpp b/source/frontends/sa2/bitmaps.cpp index 85352e74..408f7670 100644 --- a/source/frontends/sa2/bitmaps.cpp +++ b/source/frontends/sa2/bitmaps.cpp @@ -4,18 +4,19 @@ #include #include +#include struct CBITMAP : public CHANDLE { std::shared_ptr surface; }; -std::string getPath(const std::string & resource) +std::string getFilename(const std::string & resource) { - if (resource == "CHARSET40") return "resource/CHARSET4.BMP"; - if (resource == "CHARSET82") return "resource/CHARSET82.bmp"; - if (resource == "CHARSET8M") return "resource/CHARSET8M.bmp"; - if (resource == "CHARSET8C") return "resource/CHARSET8C.bmp"; + if (resource == "CHARSET40") return "CHARSET4.BMP"; + if (resource == "CHARSET82") return "CHARSET82.bmp"; + if (resource == "CHARSET8M") return "CHARSET8M.bmp"; + if (resource == "CHARSET8C") return "CHARSET8C.bmp"; return resource; } @@ -24,7 +25,9 @@ HBITMAP LoadBitmap(HINSTANCE hInstance, const char * resource) { if (resource) { - const std::string path = getPath(resource); + const std::string filename = getFilename(resource); + const std::string path = getResourcePath() + filename; + std::shared_ptr surface(SDL_LoadBMP(path.c_str()), SDL_FreeSurface); if (surface) { diff --git a/source/frontends/sa2/main.cpp b/source/frontends/sa2/main.cpp index 16340820..167c8b90 100644 --- a/source/frontends/sa2/main.cpp +++ b/source/frontends/sa2/main.cpp @@ -164,6 +164,16 @@ BYTE SpkrToggle (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG uExecutedCycles) return MemReadFloatingBus(uExecutedCycles); } + +// Mockingboard +void registerSoundBuffer(IDirectSoundBuffer * buffer) +{ +} + +void unregisterSoundBuffer(IDirectSoundBuffer * buffer) +{ +} + void run_sdl() { InitializeRegistry("applen.conf"); @@ -285,12 +295,3 @@ int main(int, char**) return exit; } - -// Mockingboard -void registerSoundBuffer(IDirectSoundBuffer * buffer) -{ -} - -void unregisterSoundBuffer(IDirectSoundBuffer * buffer) -{ -}