diff --git a/Assets/dll/libsameboy.dll b/Assets/dll/libsameboy.dll index e9d105409e..235750683c 100644 Binary files a/Assets/dll/libsameboy.dll and b/Assets/dll/libsameboy.dll differ diff --git a/submodules/sameboy/.gitignore b/submodules/sameboy/.gitignore index 28a478fa19..3722ac63ca 100644 --- a/submodules/sameboy/.gitignore +++ b/submodules/sameboy/.gitignore @@ -1 +1 @@ -/obj +build/ diff --git a/submodules/sameboy/BizInterface.c b/submodules/sameboy/BizInterface.c index 950c64e01d..d2bdeea66b 100644 --- a/submodules/sameboy/BizInterface.c +++ b/submodules/sameboy/BizInterface.c @@ -1,10 +1,13 @@ -#undef GB_INTERNAL // don't rely on GB_INTERNAL in interface +#include +#include -#include "gb.h" #include "blip_buf.h" -#include "stdio.h" -#define EXPORT __attribute__((visibility("default"))) +#ifdef _WIN32 + #define EXPORT __declspec(dllexport) +#else + #define EXPORT __attribute__((visibility("default"))) +#endif typedef int8_t s8; typedef int16_t s16; @@ -129,6 +132,11 @@ static void PrinterCallbackRelay(GB_gameboy_t* gb, u32* image, u8 height, u8 top ((biz_t*)gb)->printer_cb(image, height, top_margin, bottom_margin, exposure); } +static void PrinterDoneCallbackRelay(GB_gameboy_t* gb) +{ + // nothing to do +} + static void ScanlineCallbackRelay(GB_gameboy_t* gb, u8 line) { biz_t* biz = (biz_t*)gb; @@ -503,7 +511,7 @@ EXPORT void sameboy_setprintercallback(biz_t* biz, printer_callback_t callback) biz->printer_cb = callback; if (callback) { - GB_connect_printer(&biz->gb, PrinterCallbackRelay); + GB_connect_printer(&biz->gb, PrinterCallbackRelay, PrinterDoneCallbackRelay); } else { diff --git a/submodules/sameboy/CMakeLists.txt b/submodules/sameboy/CMakeLists.txt new file mode 100644 index 0000000000..e83434d9dc --- /dev/null +++ b/submodules/sameboy/CMakeLists.txt @@ -0,0 +1,116 @@ +cmake_minimum_required(VERSION 3.12 FATAL_ERROR) + +if(POLICY CMP0092) + cmake_policy(SET CMP0092 NEW) +endif() + +project(sameboy C) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) +set(CMAKE_C_VISIBILITY_PRESET hidden) + +if(MSVC) + # max warnings + add_compile_options(/W4) + + # ignore some warnings on clang + if(CMAKE_C_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wno-unused-parameter -Wno-sign-compare -Wno-missing-braces -Wno-missing-field-initializers) + endif() + + # all files are utf8 + add_compile_options(/utf-8) + + # max conformance mode + add_compile_options(/permissive-) + add_compile_options(/volatile:iso) + add_compile_options(/fp:precise) +else() + # max warnings + add_compile_options(-Wall -Wextra) + # ignore a few warnings + add_compile_options(-Wno-unused-parameter -Wno-sign-compare -Wno-missing-braces -Wno-missing-field-initializers) + + # strip in release, optimize for gdb usage in debug + add_link_options($<$:-s>) + add_compile_options($<$:-ggdb>) + + # use lld for clang (needed if doing lto) + if(CMAKE_C_COMPILER_ID MATCHES "Clang") + add_link_options(-fuse-ld=lld) + endif() +endif() + +# make sure we have a "lib" prefix (currently expected across all platforms) +set(CMAKE_STATIC_LIBRARY_PREFIX "lib") +set(CMAKE_SHARED_LIBRARY_PREFIX "lib") + +set(CORE_DIR ${CMAKE_SOURCE_DIR}/libsameboy/Core) + +add_library( + core + STATIC + ${CORE_DIR}/apu.c + ${CORE_DIR}/apu.h + ${CORE_DIR}/camera.c + ${CORE_DIR}/camera.h + ${CORE_DIR}/defs.h + ${CORE_DIR}/display.c + ${CORE_DIR}/display.h + ${CORE_DIR}/gb.c + ${CORE_DIR}/gb.h + ${CORE_DIR}/joypad.c + ${CORE_DIR}/joypad.h + ${CORE_DIR}/mbc.c + ${CORE_DIR}/mbc.h + ${CORE_DIR}/memory.c + ${CORE_DIR}/memory.h + ${CORE_DIR}/model.h + ${CORE_DIR}/printer.c + ${CORE_DIR}/printer.h + ${CORE_DIR}/random.c + ${CORE_DIR}/random.h + ${CORE_DIR}/rumble.c + ${CORE_DIR}/rumble.h + ${CORE_DIR}/save_state.c + ${CORE_DIR}/save_state.h + ${CORE_DIR}/sgb.c + ${CORE_DIR}/sgb.h + ${CORE_DIR}/sm83_cpu.c + ${CORE_DIR}/sm83_cpu.h + ${CORE_DIR}/timing.c + ${CORE_DIR}/timing.h +) + +target_compile_definitions(core PUBLIC _USE_MATH_DEFINES _CRT_SECURE_NO_WARNINGS) +target_compile_definitions(core PUBLIC GB_DISABLE_DEBUGGER GB_DISABLE_CHEATS GB_DISABLE_TIMEKEEPING GB_DISABLE_REWIND GB_VERSION="BizHawk") +target_compile_definitions(core PRIVATE GB_INTERNAL) +target_include_directories(core PUBLIC ${CORE_DIR}) + +if(MSVC) + target_include_directories(core PUBLIC ${CMAKE_SOURCE_DIR}/libsameboy/Windows) +endif() + +add_library( + sameboy + SHARED + ${CMAKE_SOURCE_DIR}/BizInterface.c + ${CMAKE_SOURCE_DIR}/blip_buf.c +) + +target_link_libraries(sameboy PRIVATE core) + +add_custom_command( + TARGET sameboy + POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $ ${CMAKE_SOURCE_DIR}/../../Assets/dll + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $ ${CMAKE_SOURCE_DIR}/../../output/dll +) + +if(MSVC) + set(PDB_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/../../output/dll) +endif() diff --git a/submodules/sameboy/build_debug.bat b/submodules/sameboy/build_debug.bat new file mode 100644 index 0000000000..7707e36a85 --- /dev/null +++ b/submodules/sameboy/build_debug.bat @@ -0,0 +1,6 @@ +rmdir /s /q build +mkdir build +cd build +cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang-cl -G Ninja +ninja +cd .. diff --git a/submodules/sameboy/build_debug.sh b/submodules/sameboy/build_debug.sh new file mode 100755 index 0000000000..bce7d74972 --- /dev/null +++ b/submodules/sameboy/build_debug.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e +if [ -z "$CC" ]; then export CC="clang"; fi + +rm -rf build +mkdir build +cd build +cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=$CC -G Ninja +ninja diff --git a/submodules/sameboy/build_release.bat b/submodules/sameboy/build_release.bat new file mode 100644 index 0000000000..630473cd34 --- /dev/null +++ b/submodules/sameboy/build_release.bat @@ -0,0 +1,6 @@ +rmdir /s /q build +mkdir build +cd build +cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DCMAKE_C_COMPILER=clang-cl -G Ninja +ninja +cd .. diff --git a/submodules/sameboy/build_release.sh b/submodules/sameboy/build_release.sh new file mode 100755 index 0000000000..81d43cab39 --- /dev/null +++ b/submodules/sameboy/build_release.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e +if [ -z "$CC" ]; then export CC="clang"; fi + +rm -rf build +mkdir build +cd build +cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DCMAKE_C_COMPILER=$CC -G Ninja +ninja diff --git a/submodules/sameboy/libsameboy b/submodules/sameboy/libsameboy index 55507274d6..bd31258725 160000 --- a/submodules/sameboy/libsameboy +++ b/submodules/sameboy/libsameboy @@ -1 +1 @@ -Subproject commit 55507274d6efdf3a511eceabf9c89d7a096702b3 +Subproject commit bd31258725ff587f56536c6b31e9fa128e2f38ef