From 000c7f854ccb5fd4191abdb4ce3f3946247e9256 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Sat, 16 Mar 2024 16:45:13 -0700 Subject: [PATCH] [Build] Move non-core common code to `components/` * Create multiple components library. These depend on the core code and are used by multiple frontends. * Clean up the filters declaration by moving them to a common header in `components/filters/filters.h`. * Clean up the include guards and include orders. * Fix the modified paths in `src/debian/copyright` to match their new location. --- CMakeLists.txt | 154 +--- doc/DevInfo.txt | 1 - src/Util.h | 18 - src/Util_common.cpp | 94 --- src/components/CMakeLists.txt | 7 + src/components/audio_sdl/CMakeLists.txt | 14 + .../audio_sdl/audio_sdl.cpp} | 5 +- .../audio_sdl/audio_sdl.h} | 6 +- src/components/av_recording/CMakeLists.txt | 18 + .../av_recording/av_recording.cpp} | 2 +- .../av_recording/av_recording.h} | 9 +- src/components/draw_text/CMakeLists.txt | 10 + .../draw_text/draw_text.cpp} | 2 + .../draw_text/draw_text.h} | 7 + src/components/filters/CMakeLists.txt | 47 ++ src/{wx => components/filters}/filters.h | 12 +- .../filters/internal}/2xSaI.cpp | 0 .../filters/internal}/2xSaImmx.asm | 0 .../filters/internal}/admame.cpp | 0 .../filters/internal}/bilinear.cpp | 0 .../filters/internal}/hq/asm/hq3x32.cpp | 0 .../filters/internal}/hq/asm/hq3x_16.asm | 0 .../filters/internal}/hq/asm/hq3x_32.asm | 0 .../filters/internal}/hq/asm/hq4x_16.asm | 0 .../filters/internal}/hq/asm/hq4x_32.asm | 0 .../filters/internal}/hq/asm/macros.mac | 0 .../filters/internal}/hq/c/hq3x_pattern.h | 0 .../filters/internal}/hq/c/hq4x_pattern.h | 0 .../filters/internal}/hq/c/hq_base.h | 0 .../internal}/hq/c/hq_implementation.cpp | 0 .../filters/internal}/hq/c/hq_shared.h | 0 .../filters/internal}/hq2x.cpp | 0 .../filters/internal}/hq2x.h | 0 .../filters/internal}/interp.h | 10 +- .../filters/internal}/lq2x.h | 0 .../filters/internal}/pixel.cpp | 0 .../filters/internal}/scanline.cpp | 0 .../filters/internal}/simpleFilter.cpp | 0 .../filters/internal}/xBRZ/config.h | 0 .../filters/internal}/xBRZ/xbrz.cpp | 0 .../filters/internal}/xBRZ/xbrz.h | 0 .../filters/internal}/xBRZ/xbrz_config.h | 0 .../filters/internal}/xBRZ/xbrz_tools.h | 0 .../filters/internal}/xbrzfilter.cpp | 0 src/components/filters_agb/CMakeLists.txt | 6 + .../filters_agb/filters_agb.cpp} | 26 +- src/components/filters_agb/filters_agb.h | 11 + .../filters_interframe/CMakeLists.txt | 6 + .../filters_interframe}/interframe.cpp | 2 +- .../filters_interframe/interframe.h} | 7 +- src/components/user_config/CMakeLists.txt | 6 + .../user_config/user_config.cpp} | 6 +- src/components/user_config/user_config.h | 15 + src/core/CMakeLists.txt | 32 +- src/core/base/CMakeLists.txt | 2 +- src/core/gba/gbaFilter.h | 10 - src/core/gba/gbaFlash.cpp | 59 ++ src/core/gba/gbaFlash.h | 2 + src/debian/copyright | 46 +- src/libretro/Makefile.common | 7 +- src/libretro/libretro.cpp | 11 +- src/sdl/ConfigManager.cpp | 18 +- src/sdl/SDL.cpp | 69 +- src/sdl/filters.cpp | 664 ++++++++---------- src/wx/CMakeLists.txt | 15 +- src/wx/cmdevents.cpp | 1 + src/wx/config/game-control.h | 4 +- src/wx/config/internal/option-internal.h | 7 +- src/wx/config/option.cpp | 3 +- src/wx/config/option.h | 5 +- src/wx/guiinit.cpp | 3 +- src/wx/panel.cpp | 21 +- src/wx/sys.cpp | 2 +- src/wx/tests/CMakeLists.txt | 3 +- src/wx/wxvbam.cpp | 4 +- src/wx/wxvbam.h | 4 +- third_party/include/nonstd/CMakeLists.txt | 25 + 77 files changed, 742 insertions(+), 776 deletions(-) delete mode 100644 src/Util.h delete mode 100644 src/Util_common.cpp create mode 100644 src/components/CMakeLists.txt create mode 100644 src/components/audio_sdl/CMakeLists.txt rename src/{common/SoundSDL.cpp => components/audio_sdl/audio_sdl.cpp} (99%) rename src/{common/SoundSDL.h => components/audio_sdl/audio_sdl.h} (93%) create mode 100644 src/components/av_recording/CMakeLists.txt rename src/{common/ffmpeg.cpp => components/av_recording/av_recording.cpp} (99%) rename src/{common/ffmpeg.h => components/av_recording/av_recording.h} (95%) create mode 100644 src/components/draw_text/CMakeLists.txt rename src/{sdl/text.cpp => components/draw_text/draw_text.cpp} (99%) rename src/{sdl/text.h => components/draw_text/draw_text.h} (85%) create mode 100644 src/components/filters/CMakeLists.txt rename src/{wx => components/filters}/filters.h (96%) rename src/{filters => components/filters/internal}/2xSaI.cpp (100%) rename src/{filters => components/filters/internal}/2xSaImmx.asm (100%) rename src/{filters => components/filters/internal}/admame.cpp (100%) rename src/{filters => components/filters/internal}/bilinear.cpp (100%) rename src/{filters => components/filters/internal}/hq/asm/hq3x32.cpp (100%) rename src/{filters => components/filters/internal}/hq/asm/hq3x_16.asm (100%) rename src/{filters => components/filters/internal}/hq/asm/hq3x_32.asm (100%) rename src/{filters => components/filters/internal}/hq/asm/hq4x_16.asm (100%) rename src/{filters => components/filters/internal}/hq/asm/hq4x_32.asm (100%) rename src/{filters => components/filters/internal}/hq/asm/macros.mac (100%) rename src/{filters => components/filters/internal}/hq/c/hq3x_pattern.h (100%) rename src/{filters => components/filters/internal}/hq/c/hq4x_pattern.h (100%) rename src/{filters => components/filters/internal}/hq/c/hq_base.h (100%) rename src/{filters => components/filters/internal}/hq/c/hq_implementation.cpp (100%) rename src/{filters => components/filters/internal}/hq/c/hq_shared.h (100%) rename src/{filters => components/filters/internal}/hq2x.cpp (100%) rename src/{filters => components/filters/internal}/hq2x.h (100%) rename src/{filters => components/filters/internal}/interp.h (98%) rename src/{filters => components/filters/internal}/lq2x.h (100%) rename src/{filters => components/filters/internal}/pixel.cpp (100%) rename src/{filters => components/filters/internal}/scanline.cpp (100%) rename src/{filters => components/filters/internal}/simpleFilter.cpp (100%) rename src/{filters => components/filters/internal}/xBRZ/config.h (100%) rename src/{filters => components/filters/internal}/xBRZ/xbrz.cpp (100%) rename src/{filters => components/filters/internal}/xBRZ/xbrz.h (100%) rename src/{filters => components/filters/internal}/xBRZ/xbrz_config.h (100%) rename src/{filters => components/filters/internal}/xBRZ/xbrz_tools.h (100%) rename src/{filters => components/filters/internal}/xbrzfilter.cpp (100%) create mode 100644 src/components/filters_agb/CMakeLists.txt rename src/{core/gba/gbaFilter.cpp => components/filters_agb/filters_agb.cpp} (86%) create mode 100644 src/components/filters_agb/filters_agb.h create mode 100644 src/components/filters_interframe/CMakeLists.txt rename src/{filters => components/filters_interframe}/interframe.cpp (99%) rename src/{filters/interframe.hpp => components/filters_interframe/interframe.h} (88%) create mode 100644 src/components/user_config/CMakeLists.txt rename src/{Util_desktop.cpp => components/user_config/user_config.cpp} (93%) create mode 100644 src/components/user_config/user_config.h delete mode 100644 src/core/gba/gbaFilter.h create mode 100644 third_party/include/nonstd/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 335e19b7..dd9682b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -238,19 +238,14 @@ if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg") endif() endif() -set(SDL2_TARGETS SDL2::SDL2 ${SDL2_LIBRARY_TEMP}) +set(VBAM_SDL2_LIBS SDL2::SDL2 ${SDL2_LIBRARY_TEMP}) # set the standard libraries all ports use set( VBAMCORE_LIBS - vbamcore - vbam-core-apu - vbam-core-base - vbam-core-emulator - vbam-fex - ${SDL2_TARGETS} + vbam-core + ${VBAM_SDL2_LIBS} ${OPENGL_LIBRARIES} - ${ZLIB_LIBRARY} ) set(VBAM_GENERATED_DIR ${CMAKE_BINARY_DIR}/generated) @@ -261,7 +256,6 @@ include_directories( ${VBAM_GENERATED_DIR} ) - if(ENABLE_FFMPEG) if(NOT FFMPEG_LIBRARIES) message(FATAL_ERROR "ENABLE_FFMPEG was specified, but required versions of ffmpeg libraries cannot be found!") @@ -304,16 +298,6 @@ add_compile_definitions(HAVE_NETINET_IN_H HAVE_ARPA_INET_H HAVE_ZLIB_H FINAL_VER add_compile_definitions(PKGDATADIR="${CMAKE_INSTALL_FULL_DATADIR}/vbam") add_compile_definitions(__STDC_FORMAT_MACROS) -# For C++, default to nonstd::optional and nonstd::variant for now due to mac -# build issues. -if(APPLE) - add_compile_definitions(optional_CONFIG_SELECT_OPTIONAL=optional_OPTIONAL_NONSTD) - add_compile_definitions(variant_CONFIG_SELECT_VARIANT=variant_VARIANT_NONSTD) -else() - add_compile_definitions(optional_CONFIG_SELECT_OPTIONAL=optional_OPTIONAL_STD) - add_compile_definitions(variant_CONFIG_SELECT_VARIANT=variant_VARIANT_STD) -endif() - if(ENABLE_LINK) # IPC linking code needs sem_timedwait which can be either in librt or pthreads if(NOT WIN32) @@ -364,54 +348,29 @@ if(ENABLE_NLS) find_library(LIBCHARSET_LIB NAMES libcharset charset) if(LIBINTL_LIB) list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBINTL_LIB}) - list(APPEND VBAMCORE_LIBS ${LIBINTL_LIB}) + list(APPEND NLS_LIBS ${LIBINTL_LIB}) endif() if(LIBICONV_LIB) list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBICONV_LIB}) - list(APPEND VBAMCORE_LIBS ${LIBICONV_LIB}) + list(APPEND NLS_LIBS ${LIBICONV_LIB}) endif() if(LIBCHARSET_LIB) list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBCHARSET_LIB}) - list(APPEND VBAMCORE_LIBS ${LIBCHARSET_LIB}) + list(APPEND NLS_LIBS ${LIBCHARSET_LIB}) endif() include(CheckFunctionExists) check_function_exists(gettext GETTEXT_FN) if(NOT (LIBINTL_INC OR GETTEXT_FN)) message(FATAL_ERROR "NLS requires libintl/gettext") endif() - include_directories(${LIBINTL_INC}) endif() endif() if(NOT TRANSLATIONS_ONLY) + add_subdirectory(third_party/include/nonstd) add_subdirectory(third_party/include/stb) add_subdirectory(src/core) -endif() - -set( - SRC_MAIN - src/Util_common.cpp - src/Util_desktop.cpp - src/common/SoundSDL.cpp -) - -if(MSVC) - set(SRC_MAIN ${SRC_MAIN} "dependencies/msvc/getopt.c") -endif() - -set( - HDR_MAIN - src/Util.h - src/common/SoundSDL.h -) - -if(MSVC) - set(HDR_MAIN ${HDR_MAIN} "dependencies/msvc/getopt.h") -endif() - -if(ENABLE_FFMPEG) - set(SRC_MAIN ${SRC_MAIN} src/common/ffmpeg.cpp) - set(HDR_MAIN ${HDR_MAIN} src/common/ffmpeg.h) + add_subdirectory(src/components) endif() set( @@ -425,8 +384,10 @@ set( src/sdl/iniparser.c src/sdl/inputSDL.cpp src/sdl/SDL.cpp - src/sdl/text.cpp ) +if(MSVC) + list(APPEND SRC_SDL "dependencies/msvc/getopt.c") +endif() set( HDR_SDL @@ -437,89 +398,9 @@ set( src/sdl/filters.h src/sdl/iniparser.h src/sdl/inputSDL.h - src/sdl/text.h ) - -set( - SRC_FILTERS - src/filters/2xSaI.cpp - src/filters/admame.cpp - src/filters/bilinear.cpp - src/filters/hq2x.cpp - src/filters/interframe.cpp - src/filters/pixel.cpp - src/filters/scanline.cpp - src/filters/simpleFilter.cpp - src/filters/xbrzfilter.cpp - src/filters/xBRZ/xbrz.cpp -) - -set( - HDR_FILTERS - src/filters/hq2x.h - src/filters/interp.h - src/filters/lq2x.h - src/filters/xBRZ/xbrz_config.h - src/filters/xBRZ/xbrz.h - src/filters/xBRZ/xbrz_tools.h -) - -set( - SRC_HQ_C - src/filters/hq/c/hq_implementation.cpp -) - -set( - HDR_HQ_C - src/filters/hq/c/hq3x_pattern.h - src/filters/hq/c/hq4x_pattern.h - src/filters/hq/c/hq_base.h - src/filters/hq/c/hq_shared.h -) - -set( - SRC_HQ_ASM - src/filters/hq/asm/hq3x_16.asm - src/filters/hq/asm/hq3x_32.asm - src/filters/hq/asm/hq4x_16.asm - src/filters/hq/asm/hq4x_32.asm - src/filters/hq/asm/hq3x32.cpp -) - -if(ENABLE_ASM_SCALERS) - set(SRC_FILTERS ${SRC_FILTERS} ${SRC_HQ_ASM}) - if(ENABLE_MMX) - set(SRC_FILTERS ${SRC_FILTERS} src/filters/2xSaImmx.asm) - endif() -else() - set(SRC_FILTERS ${SRC_FILTERS} ${SRC_HQ_C}) - set(HDR_FILTERS ${HDR_FILTERS} ${HDR_HQ_C}) - add_compile_definitions(NO_ASM) -endif() - - -include_directories( - ${ZLIB_INCLUDE_DIR} - third_party/include -) - -if(ENABLE_FFMPEG) - include_directories( - ${FFMPEG_INCLUDE_DIRS} - ) -endif() - -if(NOT TRANSLATIONS_ONLY) - add_library( - vbamcore - STATIC - ${PROJECT_SRCS} - ${SRC_MAIN} - ${HDR_MAIN} - ${SRC_FILTERS} - ${HDR_FILTERS} - ) - target_include_directories(vbamcore PUBLIC ${SDL2_INCLUDE_DIRS}) +if(MSVC) + list(APPEND HDR_SDL "dependencies/msvc/getopt.h") endif() if((NOT TRANSLATIONS_ONLY) AND ENABLE_SDL) @@ -543,8 +424,13 @@ if((NOT TRANSLATIONS_ONLY) AND ENABLE_SDL) set(LIRC_CLIENT_LIBRARY lirc_client) endif() - target_link_libraries( - vbam + target_link_libraries(vbam + vbam-components-audio-sdl + vbam-components-draw-text + vbam-components-filters + vbam-components-filters-agb + vbam-components-filters-interframe + vbam-components-user-config ${VBAMCORE_LIBS} ${WIN32_LIBRARIES} ${LIRC_CLIENT_LIBRARY} diff --git a/doc/DevInfo.txt b/doc/DevInfo.txt index 166132fc..f61d61e9 100644 --- a/doc/DevInfo.txt +++ b/doc/DevInfo.txt @@ -10,7 +10,6 @@ Known preprocessor switches: - FINAL_VERSION: Defined for release versions, disables additional GBA logging and completely disables GB logging. Increases the amount of CPU cycles being emulated in one go. - VBAM_ENABLE_DEBUGGER: Enable remote debugging support - MMX: Enable MMX instruction set -- NO_ASM: Use C++ version of hq3x/4x filters - RGB555: Use 16bit colors with 5bit green instead of 6bit green in hq3x/4x filters (C++ version) - NO_OGL: Exclude OpenGL code - NO_D3D: Exclude Direct3D code diff --git a/src/Util.h b/src/Util.h deleted file mode 100644 index 72155148..00000000 --- a/src/Util.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef UTIL_H -#define UTIL_H - -#include - -#ifdef _WIN32 -#define FILE_SEP '\\' -#else // MacOS, Unix -#define FILE_SEP '/' -#endif - -std::string get_xdg_user_config_home(); -std::string get_xdg_user_data_home(); - -void utilGBAFindSave(const int); -void utilUpdateSystemColorMaps(bool lcd = false); - -#endif // UTIL_H diff --git a/src/Util_common.cpp b/src/Util_common.cpp deleted file mode 100644 index c0ea7e90..00000000 --- a/src/Util_common.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "Util.h" - -#include - -#include "core/base/port.h" -#include "core/base/system.h" -#include "core/gba/gbaFilter.h" -#include "core/gba/gbaFlash.h" -#include "core/gba/gbaGlobals.h" -#include "core/gba/gbaRtc.h" - -#if defined(_MSC_VER) -#define strcasecmp _stricmp -#endif // defined(_MSC_VER) - -void utilUpdateSystemColorMaps(bool lcd) { - switch (systemColorDepth) { - case 16: { - for (int i = 0; i < 0x10000; i++) { - systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } - if (lcd) - gbafilter_pal(systemColorMap16, 0x10000); - } break; - case 24: - case 32: { - for (int i = 0; i < 0x10000; i++) { - systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | - (((i & 0x3e0) >> 5) << systemGreenShift) | - (((i & 0x7c00) >> 10) << systemBlueShift); - } - if (lcd) - gbafilter_pal32(systemColorMap32, 0x10000); - } break; - } -} - -void utilGBAFindSave(const int size) { - uint32_t* p = (uint32_t*)&g_rom[0]; - uint32_t* end = (uint32_t*)(&g_rom[0] + size); - int detectedSaveType = 0; - int flashSize = 0x10000; - bool rtcFound = false; - - while (p < end) { - uint32_t d = READ32LE(p); - - if (d == 0x52504545) { - if (memcmp(p, "EEPROM_", 7) == 0) { - if (detectedSaveType == 0 || detectedSaveType == 4) - detectedSaveType = 1; - } - } else if (d == 0x4D415253) { - if (memcmp(p, "SRAM_", 5) == 0) { - if (detectedSaveType == 0 || detectedSaveType == 1 || detectedSaveType == 4) - detectedSaveType = 2; - } - } else if (d == 0x53414C46) { - if (memcmp(p, "FLASH1M_", 8) == 0) { - if (detectedSaveType == 0) { - detectedSaveType = 3; - flashSize = 0x20000; - } - } else if (memcmp(p, "FLASH512_", 9) == 0) { - if (detectedSaveType == 0) { - detectedSaveType = 3; - flashSize = 0x10000; - } - } else if (memcmp(p, "FLASH", 5) == 0) { - if (detectedSaveType == 0) { - detectedSaveType = 4; - flashSize = 0x10000; - } - } - } else if (d == 0x52494953) { - if (memcmp(p, "SIIRTC_V", 8) == 0) - rtcFound = true; - } - p++; - } - // if no matches found, then set it to NONE - if (detectedSaveType == 0) { - detectedSaveType = 5; - } - if (detectedSaveType == 4) { - detectedSaveType = 3; - } - rtcEnable(rtcFound); - rtcEnableRumble(!rtcFound); - coreOptions.saveType = detectedSaveType; - flashSetSize(flashSize); -} diff --git a/src/components/CMakeLists.txt b/src/components/CMakeLists.txt new file mode 100644 index 00000000..f9cd7871 --- /dev/null +++ b/src/components/CMakeLists.txt @@ -0,0 +1,7 @@ +add_subdirectory(audio_sdl) +add_subdirectory(av_recording) +add_subdirectory(draw_text) +add_subdirectory(filters) +add_subdirectory(filters_agb) +add_subdirectory(filters_interframe) +add_subdirectory(user_config) diff --git a/src/components/audio_sdl/CMakeLists.txt b/src/components/audio_sdl/CMakeLists.txt new file mode 100644 index 00000000..438b9f14 --- /dev/null +++ b/src/components/audio_sdl/CMakeLists.txt @@ -0,0 +1,14 @@ +add_library(vbam-components-audio-sdl OBJECT) + +target_sources(vbam-components-audio-sdl + PRIVATE audio_sdl.cpp + PUBLIC audio_sdl.h +) + +target_include_directories(vbam-components-audio-sdl + PUBLIC ${SDL2_INCLUDE_DIRS} +) + +target_link_libraries(vbam-components-audio-sdl + PUBLIC vbam-core-base ${VBAM_SDL2_LIBS} +) diff --git a/src/common/SoundSDL.cpp b/src/components/audio_sdl/audio_sdl.cpp similarity index 99% rename from src/common/SoundSDL.cpp rename to src/components/audio_sdl/audio_sdl.cpp index e5ef6fc2..b2da031e 100644 --- a/src/common/SoundSDL.cpp +++ b/src/components/audio_sdl/audio_sdl.cpp @@ -15,10 +15,13 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +#include "components/audio_sdl/audio_sdl.h" + #include #include + #include -#include "SoundSDL.h" + #include "core/gba/gbaGlobals.h" #include "core/gba/gbaSound.h" diff --git a/src/common/SoundSDL.h b/src/components/audio_sdl/audio_sdl.h similarity index 93% rename from src/common/SoundSDL.h rename to src/components/audio_sdl/audio_sdl.h index 14f8c872..a05e207a 100644 --- a/src/common/SoundSDL.h +++ b/src/components/audio_sdl/audio_sdl.h @@ -15,8 +15,8 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -#ifndef __VBA_SOUND_SDL_H__ -#define __VBA_SOUND_SDL_H__ +#ifndef VBAM_COMPONENTS_AUDIO_SDL_AUDIO_SDL_H_ +#define VBAM_COMPONENTS_AUDIO_SDL_AUDIO_SDL_H_ #include @@ -60,4 +60,4 @@ private: static const double buftime; }; -#endif // __VBA_SOUND_SDL_H__ +#endif // VBAM_COMPONENTS_AUDIO_SDL_AUDIO_SDL_H_ diff --git a/src/components/av_recording/CMakeLists.txt b/src/components/av_recording/CMakeLists.txt new file mode 100644 index 00000000..21fda70e --- /dev/null +++ b/src/components/av_recording/CMakeLists.txt @@ -0,0 +1,18 @@ +if(NOT ENABLE_FFMPEG) + return() +endif() + +add_library(vbam-components-av-recording OBJECT) + +target_sources(vbam-components-av-recording + PRIVATE av_recording.cpp + PUBLIC av_recording.h +) + +target_include_directories(vbam-components-av-recording + PUBLIC ${FFMPEG_INCLUDE_DIRS} +) + +target_link_libraries(vbam-components-av-recording + PUBLIC ${FFMPEG_LIBRARIES} +) diff --git a/src/common/ffmpeg.cpp b/src/components/av_recording/av_recording.cpp similarity index 99% rename from src/common/ffmpeg.cpp rename to src/components/av_recording/av_recording.cpp index 662eeff8..d3ca99af 100644 --- a/src/common/ffmpeg.cpp +++ b/src/components/av_recording/av_recording.cpp @@ -1,4 +1,4 @@ -#include "ffmpeg.h" +#include "components/av_recording/av_recording.h" #define STREAM_FRAME_RATE 60 #define STREAM_PIXEL_FORMAT AV_PIX_FMT_YUV420P diff --git a/src/common/ffmpeg.h b/src/components/av_recording/av_recording.h similarity index 95% rename from src/common/ffmpeg.h rename to src/components/av_recording/av_recording.h index 614ce180..4230748d 100644 --- a/src/common/ffmpeg.h +++ b/src/components/av_recording/av_recording.h @@ -1,12 +1,12 @@ -#ifndef WX_FFMPEG_H -#define WX_FFMPEG_H +#ifndef VBAM_COMPONENTS_AV_RECORDING_AV_RECORDING_H_ +#define VBAM_COMPONENTS_AV_RECORDING_AV_RECORDING_H_ // simplified interface for recording audio and/or video from emulator extern "C" { /* From: http://redino.net/blog/2013/12/uint64_c-defined-including-libavformatavformat-h-vs-2008/ */ -#include +#include #ifndef INT64_C #define INT64_C(c) (c ## LL) @@ -29,7 +29,6 @@ extern "C" { } #include -#include namespace recording { @@ -127,4 +126,4 @@ class MediaRecorder } -#endif /* WX_FFMPEG_H */ +#endif // VBAM_COMPONENTS_AV_RECORDING_AV_RECORDING_H_ diff --git a/src/components/draw_text/CMakeLists.txt b/src/components/draw_text/CMakeLists.txt new file mode 100644 index 00000000..8c70cd33 --- /dev/null +++ b/src/components/draw_text/CMakeLists.txt @@ -0,0 +1,10 @@ +add_library(vbam-components-draw-text OBJECT) + +target_sources(vbam-components-draw-text + PRIVATE draw_text.cpp + PUBLIC draw_text.h +) + +target_link_libraries(vbam-components-draw-text + PRIVATE vbam-core-base +) diff --git a/src/sdl/text.cpp b/src/components/draw_text/draw_text.cpp similarity index 99% rename from src/sdl/text.cpp rename to src/components/draw_text/draw_text.cpp index 3d7e45a7..456a6dad 100644 --- a/src/sdl/text.cpp +++ b/src/components/draw_text/draw_text.cpp @@ -20,6 +20,8 @@ /* Code originally from fceu/drawing.h file, adapted by Forgotten */ +#include "components/draw_text/draw_text.h" + #include "core/base/system.h" extern int RGB_LOW_BITS_MASK; diff --git a/src/sdl/text.h b/src/components/draw_text/draw_text.h similarity index 85% rename from src/sdl/text.h rename to src/components/draw_text/draw_text.h index 061d105e..a4c34b9a 100644 --- a/src/sdl/text.h +++ b/src/components/draw_text/draw_text.h @@ -17,4 +17,11 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +#ifndef VBAM_COMPONENTS_DRAW_TEXT_DRAW_TEXT_H_ +#define VBAM_COMPONENTS_DRAW_TEXT_DRAW_TEXT_H_ + +#include + extern void drawText(uint8_t*, int, int, int, const char*, bool); + +#endif // VBAM_COMPONENTS_DRAW_TEXT_DRAW_TEXT_H_ diff --git a/src/components/filters/CMakeLists.txt b/src/components/filters/CMakeLists.txt new file mode 100644 index 00000000..e2b9ea07 --- /dev/null +++ b/src/components/filters/CMakeLists.txt @@ -0,0 +1,47 @@ +add_library(vbam-components-filters OBJECT) + +target_sources(vbam-components-filters + PRIVATE + internal/2xSaI.cpp + internal/admame.cpp + internal/bilinear.cpp + internal/hq2x.cpp + internal/hq2x.h + internal/interp.h + internal/lq2x.h + internal/pixel.cpp + internal/scanline.cpp + internal/simpleFilter.cpp + internal/xBRZ/xbrz.cpp + internal/xBRZ/xbrz.h + internal/xBRZ/xbrz_config.h + internal/xBRZ/xbrz_tools.h + internal/xbrzfilter.cpp + + PUBLIC + filters.h +) + +if(ENABLE_ASM_SCALERS) + target_sources(vbam-components-filters + PRIVATE + internal/hq/asm/hq3x_16.asm + internal/hq/asm/hq3x_32.asm + internal/hq/asm/hq4x_16.asm + internal/hq/asm/hq4x_32.asm + internal/hq/asm/hq3x32.cpp + internal/hq/asm/macros.mac + ) + if(ENABLE_MMX) + set(SRC_FILTERS ${SRC_FILTERS} internal/2xSaImmx.asm) + endif() +else() + target_sources(vbam-components-filters + PRIVATE + internal/hq/c/hq3x_pattern.h + internal/hq/c/hq4x_pattern.h + internal/hq/c/hq_base.h + internal/hq/c/hq_implementation.cpp + internal/hq/c/hq_shared.h + ) +endif() diff --git a/src/wx/filters.h b/src/components/filters/filters.h similarity index 96% rename from src/wx/filters.h rename to src/components/filters/filters.h index 0e313871..16f0f819 100644 --- a/src/wx/filters.h +++ b/src/components/filters/filters.h @@ -1,14 +1,12 @@ -#ifndef FILTERS_H -#define FILTERS_H +#ifndef VBAM_COMPONENTS_FILTERS_FILTERS_H_ +#define VBAM_COMPONENTS_FILTERS_FILTERS_H_ + +#include -// FIXME: these should be in a system header included by all users and all -// files which define these functions // most 16-bit filters require space in src rounded up to uint32_t // those that take delta take 1 src line of pixels, rounded up to uint32_t size // initial value appears to be all-0xff -#include "../filters/interframe.hpp" - void Pixelate32(uint8_t* src, uint32_t spitch, uint8_t*, uint8_t* dst, uint32_t dstp, int w, int h); void Pixelate(uint8_t* src, uint32_t spitch, uint8_t* delta, uint8_t* dst, uint32_t dstp, int w, int h); // next 3*2 use Init_2xSaI(555|565) and do not take into account @@ -71,4 +69,4 @@ void xbrz4x32(uint8_t* src, uint32_t spitch, uint8_t*, uint8_t* dst, uint32_t ds void xbrz5x32(uint8_t* src, uint32_t spitch, uint8_t*, uint8_t* dst, uint32_t dstp, int w, int h); void xbrz6x32(uint8_t* src, uint32_t spitch, uint8_t*, uint8_t* dst, uint32_t dstp, int w, int h); -#endif /* FILTERS_H */ +#endif // VBAM_COMPONENTS_FILTERS_FILTERS_H_ diff --git a/src/filters/2xSaI.cpp b/src/components/filters/internal/2xSaI.cpp similarity index 100% rename from src/filters/2xSaI.cpp rename to src/components/filters/internal/2xSaI.cpp diff --git a/src/filters/2xSaImmx.asm b/src/components/filters/internal/2xSaImmx.asm similarity index 100% rename from src/filters/2xSaImmx.asm rename to src/components/filters/internal/2xSaImmx.asm diff --git a/src/filters/admame.cpp b/src/components/filters/internal/admame.cpp similarity index 100% rename from src/filters/admame.cpp rename to src/components/filters/internal/admame.cpp diff --git a/src/filters/bilinear.cpp b/src/components/filters/internal/bilinear.cpp similarity index 100% rename from src/filters/bilinear.cpp rename to src/components/filters/internal/bilinear.cpp diff --git a/src/filters/hq/asm/hq3x32.cpp b/src/components/filters/internal/hq/asm/hq3x32.cpp similarity index 100% rename from src/filters/hq/asm/hq3x32.cpp rename to src/components/filters/internal/hq/asm/hq3x32.cpp diff --git a/src/filters/hq/asm/hq3x_16.asm b/src/components/filters/internal/hq/asm/hq3x_16.asm similarity index 100% rename from src/filters/hq/asm/hq3x_16.asm rename to src/components/filters/internal/hq/asm/hq3x_16.asm diff --git a/src/filters/hq/asm/hq3x_32.asm b/src/components/filters/internal/hq/asm/hq3x_32.asm similarity index 100% rename from src/filters/hq/asm/hq3x_32.asm rename to src/components/filters/internal/hq/asm/hq3x_32.asm diff --git a/src/filters/hq/asm/hq4x_16.asm b/src/components/filters/internal/hq/asm/hq4x_16.asm similarity index 100% rename from src/filters/hq/asm/hq4x_16.asm rename to src/components/filters/internal/hq/asm/hq4x_16.asm diff --git a/src/filters/hq/asm/hq4x_32.asm b/src/components/filters/internal/hq/asm/hq4x_32.asm similarity index 100% rename from src/filters/hq/asm/hq4x_32.asm rename to src/components/filters/internal/hq/asm/hq4x_32.asm diff --git a/src/filters/hq/asm/macros.mac b/src/components/filters/internal/hq/asm/macros.mac similarity index 100% rename from src/filters/hq/asm/macros.mac rename to src/components/filters/internal/hq/asm/macros.mac diff --git a/src/filters/hq/c/hq3x_pattern.h b/src/components/filters/internal/hq/c/hq3x_pattern.h similarity index 100% rename from src/filters/hq/c/hq3x_pattern.h rename to src/components/filters/internal/hq/c/hq3x_pattern.h diff --git a/src/filters/hq/c/hq4x_pattern.h b/src/components/filters/internal/hq/c/hq4x_pattern.h similarity index 100% rename from src/filters/hq/c/hq4x_pattern.h rename to src/components/filters/internal/hq/c/hq4x_pattern.h diff --git a/src/filters/hq/c/hq_base.h b/src/components/filters/internal/hq/c/hq_base.h similarity index 100% rename from src/filters/hq/c/hq_base.h rename to src/components/filters/internal/hq/c/hq_base.h diff --git a/src/filters/hq/c/hq_implementation.cpp b/src/components/filters/internal/hq/c/hq_implementation.cpp similarity index 100% rename from src/filters/hq/c/hq_implementation.cpp rename to src/components/filters/internal/hq/c/hq_implementation.cpp diff --git a/src/filters/hq/c/hq_shared.h b/src/components/filters/internal/hq/c/hq_shared.h similarity index 100% rename from src/filters/hq/c/hq_shared.h rename to src/components/filters/internal/hq/c/hq_shared.h diff --git a/src/filters/hq2x.cpp b/src/components/filters/internal/hq2x.cpp similarity index 100% rename from src/filters/hq2x.cpp rename to src/components/filters/internal/hq2x.cpp diff --git a/src/filters/hq2x.h b/src/components/filters/internal/hq2x.h similarity index 100% rename from src/filters/hq2x.h rename to src/components/filters/internal/hq2x.h diff --git a/src/filters/interp.h b/src/components/filters/internal/interp.h similarity index 98% rename from src/filters/interp.h rename to src/components/filters/internal/interp.h index 394a91db..72c255c4 100644 --- a/src/filters/interp.h +++ b/src/components/filters/internal/interp.h @@ -28,12 +28,10 @@ * do so, delete this exception statement from your version. */ -#ifndef __INTERP_H -#define __INTERP_H +#ifndef VBAM_COMPONENTS_FILTERS_INTERNAL_INTERP_H +#define VBAM_COMPONENTS_FILTERS_INTERNAL_INTERP_H -#define __STDC_CONSTANT_MACROS - -#include +#include typedef uint16_t interp_uint16; typedef uint32_t interp_uint32; @@ -342,4 +340,4 @@ static void interp_set(unsigned bits_per_pixel) } } -#endif +#endif // VBAM_COMPONENTS_FILTERS_INTERNAL_INTERP_H diff --git a/src/filters/lq2x.h b/src/components/filters/internal/lq2x.h similarity index 100% rename from src/filters/lq2x.h rename to src/components/filters/internal/lq2x.h diff --git a/src/filters/pixel.cpp b/src/components/filters/internal/pixel.cpp similarity index 100% rename from src/filters/pixel.cpp rename to src/components/filters/internal/pixel.cpp diff --git a/src/filters/scanline.cpp b/src/components/filters/internal/scanline.cpp similarity index 100% rename from src/filters/scanline.cpp rename to src/components/filters/internal/scanline.cpp diff --git a/src/filters/simpleFilter.cpp b/src/components/filters/internal/simpleFilter.cpp similarity index 100% rename from src/filters/simpleFilter.cpp rename to src/components/filters/internal/simpleFilter.cpp diff --git a/src/filters/xBRZ/config.h b/src/components/filters/internal/xBRZ/config.h similarity index 100% rename from src/filters/xBRZ/config.h rename to src/components/filters/internal/xBRZ/config.h diff --git a/src/filters/xBRZ/xbrz.cpp b/src/components/filters/internal/xBRZ/xbrz.cpp similarity index 100% rename from src/filters/xBRZ/xbrz.cpp rename to src/components/filters/internal/xBRZ/xbrz.cpp diff --git a/src/filters/xBRZ/xbrz.h b/src/components/filters/internal/xBRZ/xbrz.h similarity index 100% rename from src/filters/xBRZ/xbrz.h rename to src/components/filters/internal/xBRZ/xbrz.h diff --git a/src/filters/xBRZ/xbrz_config.h b/src/components/filters/internal/xBRZ/xbrz_config.h similarity index 100% rename from src/filters/xBRZ/xbrz_config.h rename to src/components/filters/internal/xBRZ/xbrz_config.h diff --git a/src/filters/xBRZ/xbrz_tools.h b/src/components/filters/internal/xBRZ/xbrz_tools.h similarity index 100% rename from src/filters/xBRZ/xbrz_tools.h rename to src/components/filters/internal/xBRZ/xbrz_tools.h diff --git a/src/filters/xbrzfilter.cpp b/src/components/filters/internal/xbrzfilter.cpp similarity index 100% rename from src/filters/xbrzfilter.cpp rename to src/components/filters/internal/xbrzfilter.cpp diff --git a/src/components/filters_agb/CMakeLists.txt b/src/components/filters_agb/CMakeLists.txt new file mode 100644 index 00000000..20dac393 --- /dev/null +++ b/src/components/filters_agb/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(vbam-components-filters-agb OBJECT) + +target_sources(vbam-components-filters-agb + PRIVATE filters_agb.cpp + PUBLIC filters_agb.h +) diff --git a/src/core/gba/gbaFilter.cpp b/src/components/filters_agb/filters_agb.cpp similarity index 86% rename from src/core/gba/gbaFilter.cpp rename to src/components/filters_agb/filters_agb.cpp index 12b9f2d6..6f29df72 100644 --- a/src/core/gba/gbaFilter.cpp +++ b/src/components/filters_agb/filters_agb.cpp @@ -1,4 +1,4 @@ -#include "core/gba/gbaFilter.h" +#include "components/filters_agb/filters_agb.h" extern int systemColorDepth; extern int systemRedShift; @@ -25,6 +25,30 @@ inline void swap(short& a, short& b) b = temp; } +void gbafilter_update_colors(bool lcd) { + switch (systemColorDepth) { + case 16: { + for (int i = 0; i < 0x10000; i++) { + systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | + (((i & 0x3e0) >> 5) << systemGreenShift) | + (((i & 0x7c00) >> 10) << systemBlueShift); + } + if (lcd) + gbafilter_pal(systemColorMap16, 0x10000); + } break; + case 24: + case 32: { + for (int i = 0; i < 0x10000; i++) { + systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | + (((i & 0x3e0) >> 5) << systemGreenShift) | + (((i & 0x7c00) >> 10) << systemBlueShift); + } + if (lcd) + gbafilter_pal32(systemColorMap32, 0x10000); + } break; + } +} + void gbafilter_pal(uint16_t* buf, int count) { short temp[3 * 3], s; diff --git a/src/components/filters_agb/filters_agb.h b/src/components/filters_agb/filters_agb.h new file mode 100644 index 00000000..6e40fe49 --- /dev/null +++ b/src/components/filters_agb/filters_agb.h @@ -0,0 +1,11 @@ +#ifndef VBAM_COMPONENTS_FILTERS_AGB_FILTERS_AGB_H_ +#define VBAM_COMPONENTS_FILTERS_AGB_FILTERS_AGB_H_ + +#include + +void gbafilter_update_colors(bool lcd = false); +void gbafilter_pal(uint16_t* buf, int count); +void gbafilter_pal32(uint32_t* buf, int count); +void gbafilter_pad(uint8_t* buf, int count); + +#endif // VBAM_COMPONENTS_FILTERS_AGB_FILTERS_AGB_H_ diff --git a/src/components/filters_interframe/CMakeLists.txt b/src/components/filters_interframe/CMakeLists.txt new file mode 100644 index 00000000..d80834a4 --- /dev/null +++ b/src/components/filters_interframe/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(vbam-components-filters-interframe OBJECT) + +target_sources(vbam-components-filters-interframe + PRIVATE interframe.cpp + PUBLIC interframe.h +) diff --git a/src/filters/interframe.cpp b/src/components/filters_interframe/interframe.cpp similarity index 99% rename from src/filters/interframe.cpp rename to src/components/filters_interframe/interframe.cpp index ba42c734..f46c7be1 100644 --- a/src/filters/interframe.cpp +++ b/src/components/filters_interframe/interframe.cpp @@ -1,4 +1,4 @@ -#include "interframe.hpp" +#include "components/filters_interframe/interframe.h" #include diff --git a/src/filters/interframe.hpp b/src/components/filters_interframe/interframe.h similarity index 88% rename from src/filters/interframe.hpp rename to src/components/filters_interframe/interframe.h index c5065e94..830ec067 100644 --- a/src/filters/interframe.hpp +++ b/src/components/filters_interframe/interframe.h @@ -1,7 +1,7 @@ /// Interframe blending filters -#ifndef INTERFRAME_HPP -#define INTERFRAME_HPP +#ifndef VBAM_COMPONENTS_FILTERS_INTERFRAME_INTERFRAME_H_ +#define VBAM_COMPONENTS_FILTERS_INTERFRAME_INTERFRAME_H_ #include @@ -30,4 +30,5 @@ void SmartIB(uint8_t *srcPtr, uint32_t srcPitch, int width, int height); void SmartIB32(uint8_t *srcPtr, uint32_t srcPitch, int width, int height); void MotionBlurIB(uint8_t *srcPtr, uint32_t srcPitch, int width, int height); void MotionBlurIB32(uint8_t *srcPtr, uint32_t srcPitch, int width, int height); -#endif //INTERFRAME_HPP + +#endif //VBAM_COMPONENTS_FILTERS_INTERFRAME_INTERFRAME_H_ diff --git a/src/components/user_config/CMakeLists.txt b/src/components/user_config/CMakeLists.txt new file mode 100644 index 00000000..35ff554b --- /dev/null +++ b/src/components/user_config/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(vbam-components-user-config OBJECT) + +target_sources(vbam-components-user-config + PRIVATE user_config.cpp + PUBLIC user_config.h +) diff --git a/src/Util_desktop.cpp b/src/components/user_config/user_config.cpp similarity index 93% rename from src/Util_desktop.cpp rename to src/components/user_config/user_config.cpp index 19cc8d37..42d0aef1 100644 --- a/src/Util_desktop.cpp +++ b/src/components/user_config/user_config.cpp @@ -1,4 +1,4 @@ -#include "Util.h" +#include "components/user_config/user_config.h" #include @@ -26,7 +26,7 @@ std::string get_xdg_user_config_home() path = xdg_var; } #endif - return path + FILE_SEP; + return path + kFileSep; } // Get user-specific data dir manually. @@ -53,6 +53,6 @@ std::string get_xdg_user_data_home() path = xdg_var; } #endif - return path + FILE_SEP; + return path + kFileSep; } diff --git a/src/components/user_config/user_config.h b/src/components/user_config/user_config.h new file mode 100644 index 00000000..a6469e3d --- /dev/null +++ b/src/components/user_config/user_config.h @@ -0,0 +1,15 @@ +#ifndef VBAM_COMPONENTS_USER_CONFIG_USER_CONFIG_H_ +#define VBAM_COMPONENTS_USER_CONFIG_USER_CONFIG_H_ + +#include + +#if defined(_WIN32) +static constexpr char kFileSep = '\\'; +#else // !defined(_WIN32) +static constexpr char kFileSep = '/'; +#endif // defined(_WIN32) + +std::string get_xdg_user_config_home(); +std::string get_xdg_user_data_home(); + +#endif // VBAM_COMPONENTS_USER_CONFIG_USER_CONFIG_H_ \ No newline at end of file diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 640e4459..275da503 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -2,13 +2,13 @@ add_subdirectory(apu) add_subdirectory(base) add_subdirectory(fex) -# The vbam-core-emulator target contains both the Game Boy and Game Boy Advance +# The vbam-core target contains both the Game Boy and Game Boy Advance # emulators. These should be broken down into 2 separate targets. The issue lies # with the Link and Sound emulation, which are tangled together between the two # systems. -add_library(vbam-core-emulator OBJECT) +add_library(vbam-core STATIC) -target_sources(vbam-core-emulator +target_sources(vbam-core PRIVATE # Game Boy gb/internal/gbCodes.h @@ -39,7 +39,6 @@ target_sources(vbam-core-emulator gba/gbaCheatSearch.cpp gba/gbaEeprom.cpp gba/gbaElf.cpp - gba/gbaFilter.cpp gba/gbaFlash.cpp gba/gbaGfx.cpp gba/gbaGlobals.cpp @@ -80,7 +79,6 @@ target_sources(vbam-core-emulator gba/gbaCpuArmDis.h gba/gbaEeprom.h gba/gbaElf.h - gba/gbaFilter.h gba/gbaFlash.h gba/gbaGfx.h gba/gbaGlobals.h @@ -90,17 +88,17 @@ target_sources(vbam-core-emulator gba/gbaSound.h ) -target_include_directories(vbam-core-base +target_include_directories(vbam-core PUBLIC ${ZLIB_INCLUDE_DIR} ) -target_link_libraries(vbam-core-emulator - PRIVATE vbam-core-apu +target_link_libraries(vbam-core + PRIVATE vbam-core-apu vbam-fex PUBLIC vbam-core-base ${ZLIB_LIBRARY} ) if(ENABLE_DEBUGGER) - target_sources(vbam-core-emulator + target_sources(vbam-core PRIVATE gba/gbaRemote.cpp gba/internal/gbaBreakpoint.cpp @@ -112,7 +110,7 @@ if(ENABLE_DEBUGGER) endif() if(ENABLE_LINK) - target_sources(vbam-core-emulator + target_sources(vbam-core PRIVATE gba/gbaLink.cpp gba/internal/gbaSockClient.cpp @@ -122,10 +120,18 @@ if(ENABLE_LINK) gba/gbaLink.h ) - target_include_directories(vbam-core-emulator + target_include_directories(vbam-core PRIVATE ${SFML_INCLUDE_DIR}) - target_link_libraries(vbam-core-emulator + target_link_libraries(vbam-core PRIVATE ${SFML_LIBRARIES}) -endif() + if(ENABLE_NLS) + # Add libintl.h + target_include_directories(vbam-core + PRIVATE ${LIBINTL_INC}) + target_link_libraries(vbam-core + PRIVATE ${NLS_LIBS}) + endif() + +endif() diff --git a/src/core/base/CMakeLists.txt b/src/core/base/CMakeLists.txt index 3c841524..b57a5d2f 100644 --- a/src/core/base/CMakeLists.txt +++ b/src/core/base/CMakeLists.txt @@ -56,6 +56,6 @@ target_include_directories(vbam-core-base ) target_link_libraries(vbam-core-base - INTERFACE vbam-fex stb-image + PRIVATE vbam-fex stb-image PUBLIC ${ZLIB_LIBRARY} ) diff --git a/src/core/gba/gbaFilter.h b/src/core/gba/gbaFilter.h deleted file mode 100644 index 0b8a7b89..00000000 --- a/src/core/gba/gbaFilter.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef VBAM_CORE_GBA_GBAFILTER_H_ -#define VBAM_CORE_GBA_GBAFILTER_H_ - -#include - -void gbafilter_pal(uint16_t* buf, int count); -void gbafilter_pal32(uint32_t* buf, int count); -void gbafilter_pad(uint8_t* buf, int count); - -#endif // VBAM_CORE_GBA_GBAFILTER_H_ diff --git a/src/core/gba/gbaFlash.cpp b/src/core/gba/gbaFlash.cpp index 2d533384..62dc268e 100644 --- a/src/core/gba/gbaFlash.cpp +++ b/src/core/gba/gbaFlash.cpp @@ -4,7 +4,10 @@ #include #include "core/base/file_util.h" +#include "core/base/port.h" #include "core/gba/gba.h" +#include "core/gba/gbaGlobals.h" +#include "core/gba/gbaRtc.h" #include "core/gba/internal/gbaSram.h" #define FLASH_READ_ARRAY 0 @@ -27,6 +30,62 @@ int flashDeviceID = 0x1b; int flashManufacturerID = 0x32; int flashBank = 0; +void flashDetectSaveType(const int size) { + uint32_t* p = (uint32_t*)&g_rom[0]; + uint32_t* end = (uint32_t*)(&g_rom[0] + size); + int detectedSaveType = 0; + int flashSize = 0x10000; + bool rtcFound = false; + + while (p < end) { + uint32_t d = READ32LE(p); + + if (d == 0x52504545) { + if (memcmp(p, "EEPROM_", 7) == 0) { + if (detectedSaveType == 0 || detectedSaveType == 4) + detectedSaveType = 1; + } + } else if (d == 0x4D415253) { + if (memcmp(p, "SRAM_", 5) == 0) { + if (detectedSaveType == 0 || detectedSaveType == 1 || detectedSaveType == 4) + detectedSaveType = 2; + } + } else if (d == 0x53414C46) { + if (memcmp(p, "FLASH1M_", 8) == 0) { + if (detectedSaveType == 0) { + detectedSaveType = 3; + flashSize = 0x20000; + } + } else if (memcmp(p, "FLASH512_", 9) == 0) { + if (detectedSaveType == 0) { + detectedSaveType = 3; + flashSize = 0x10000; + } + } else if (memcmp(p, "FLASH", 5) == 0) { + if (detectedSaveType == 0) { + detectedSaveType = 4; + flashSize = 0x10000; + } + } + } else if (d == 0x52494953) { + if (memcmp(p, "SIIRTC_V", 8) == 0) + rtcFound = true; + } + p++; + } + // if no matches found, then set it to NONE + if (detectedSaveType == 0) { + detectedSaveType = 5; + } + if (detectedSaveType == 4) { + detectedSaveType = 3; + } + rtcEnable(rtcFound); + rtcEnableRumble(!rtcFound); + coreOptions.saveType = detectedSaveType; + flashSetSize(flashSize); +} + void flashInit() { memset(flashSaveMemory, 0xff, sizeof(flashSaveMemory)); diff --git a/src/core/gba/gbaFlash.h b/src/core/gba/gbaFlash.h index 02c3bcfd..c188dee1 100644 --- a/src/core/gba/gbaFlash.h +++ b/src/core/gba/gbaFlash.h @@ -9,6 +9,8 @@ #define FLASH_128K_SZ 0x20000 +void flashDetectSaveType(const int size); + #if defined(__LIBRETRO__) extern void flashSaveGame(uint8_t*& data); extern void flashReadGame(const uint8_t*& data); diff --git a/src/debian/copyright b/src/debian/copyright index 8b4a4013..84d3b12a 100644 --- a/src/debian/copyright +++ b/src/debian/copyright @@ -25,22 +25,22 @@ Copyright: 2011-2017 VBA-M development team 2011 Thomas J. Moore (aka tjm, aka darktjm) License: GPL-2+ -Files: fex/* +Files: src/core/fex/* Copyright: 2005-2009 Shay Green License: LGPL-2.1+ -Files: fex/7z_C/* +Files: src/core/fex/7z_C/* Copyright: 2008-2010 Igor Pavlov License: public-domain -Files: fex/7z_C/Ppmd.h - fex/7z_C/Ppmd7.* - fex/7z_C/Ppmd7Dec.c +Files: src/core/fex/7z_C/Ppmd.h + src/core/fex/7z_C/Ppmd7.* + src/core/fex/7z_C/Ppmd7Dec.c Copyright: 2010 Igor Pavlov 2001 Dmitry Shkarin License: public-domain -Files: src/apu/* +Files: src/core/apu/* Copyright: 2003-2007 Shay Green License: LGPL-2.1+ @@ -51,30 +51,30 @@ Copyright: 2014, 2015 Sergio Benjamim (sergio-br2) 2006 Matteo Drera License: GPL-2+ -Files: src/common/iniparser.* - src/common/dictionary.* +Files: src/sdl/iniparser.* + src/sdl/dictionary.* Copyright: 2010-2014 Nicolas Devillard License: Expat -Files: src/common/memgzio.* +Files: src/core/base/internal/memgzio.* Copyright: 2007, 2009, 2011, 2012, 2013, 2015 VBA-M development team ????-2006 Forgotten 1995-2002 Jean-loup Gailly License: Zlib -Files: src/filters/hq/asm/hq3x_16.asm - src/filters/hq/asm/hq3x_32.asm - src/filters/hq/asm/hq4x_16.asm - src/filters/hq/asm/hq4x_32.asm +Files: src/components/filters/hq/asm/hq3x_16.asm + src/components/filters/internal/hq/asm/hq3x_32.asm + src/components/filters/internal/hq/asm/hq4x_16.asm + src/components/filters/internal/hq/asm/hq4x_32.asm Copyright: 2007, 2008 VBA-M development team 2003 Maxim Stepin (MaxSt) License: GPL-2+ -Files: src/filters/hq/asm/macros.mac +Files: src/components/filters/internal/hq/asm/macros.mac Copyright: 1997-2007 ZSNES Team (zsKnight, _Demo_, pagefault, Nach) License: GPL-2+ -Files: src/filters/xBRZ/* +Files: src/components/filters/internal/xBRZ/* Copyright: 2012-2015 Zenju (zenju AT gmx DOT de) License: GPL-3 Additionally and as a special exception, the author gives permission @@ -86,12 +86,12 @@ License: GPL-3 of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. -Files: src/filters/2xSaI.cpp - src/filters/2xSaImmx.asm +Files: src/components/filters/internal/2xSaI.cpp + src/components/filters/internal/2xSaImmx.asm Copyright: 1999-2001 Derek Liauw Kie Fa (aka Kreed) License: GPL-2+ -Files: src/filters/admame.cpp +Files: src/components/filters/internal/admame.cpp Copyright: 1999-2002 Andrea Mazzoleni License: GPL-2+ In addition, as a special exception, Andrea Mazzoleni @@ -109,15 +109,15 @@ License: GPL-2+ - the program is not used in commercial activities. - the whole source code of the program is released with the binary. -Files: src/filters/bilinear.cpp +Files: src/components/filters/internal/bilinear.cpp Copyright: 2008, 2009 VBA-M development team 2004 Forgotten and the VBA development team 2003 Forgotten 2000 Jeffrey S. Freedman (JSF) License: GPL-2+ -Files: src/filters/hq2x.* - src/filters/interp.h +Files: src/components/filters/internal/hq2x.* + src/components/filters/internal/interp.h Copyright: 2003 Andrea Mazzoleni License: GPL-2+ In addition, as a special exception, Andrea Mazzoleni @@ -130,7 +130,7 @@ License: GPL-2+ file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. -Files: src/gba/debugger-expr-yacc.* +Files: src/core/gba/debugger-expr-yacc.* Copyright: 2015 VBA-M development team 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. License: GPL-2+ @@ -147,7 +147,7 @@ License: GPL-2+ This special exception was added by the Free Software Foundation in version 2.2 of Bison. -Files: src/gba/GBALink.* +Files: src/core/gba/GBALink.* Copyright: 2008, 2009, 2010, 2011, 2012, 2015 VBA-M development team ???? Thomas J. Moore (aka tjm, aka darktjm) 2004-2006 denopqrihg diff --git a/src/libretro/Makefile.common b/src/libretro/Makefile.common index 73437df1..d906b74c 100644 --- a/src/libretro/Makefile.common +++ b/src/libretro/Makefile.common @@ -17,9 +17,6 @@ endif SOURCES_CXX := -SOURCES_CXX += \ - $(CORE_DIR)/Util_common.cpp \ - SOURCES_CXX += \ $(CORE_DIR)/libretro/libretro.cpp \ $(CORE_DIR)/libretro/SoundRetro.cpp @@ -72,5 +69,5 @@ SOURCES_CXX += \ # Filters SOURCES_CXX += \ - $(CORE_DIR)/filters/interframe.cpp \ - $(CORE_DIR)/core/gba/gbaFilter.cpp + $(CORE_DIR)/components/filters_agb/filters_agb.cpp \ + $(CORE_DIR)/components/filters_interframe/interframe.cpp diff --git a/src/libretro/libretro.cpp b/src/libretro/libretro.cpp index cecbfd37..81f3710f 100644 --- a/src/libretro/libretro.cpp +++ b/src/libretro/libretro.cpp @@ -10,7 +10,8 @@ #include "libretro_core_options.h" #include "scrc32.h" -#include "../Util.h" +#include "components/filters_agb/filters_agb.h" +#include "components/filters_interframe/interframe.h" #include "core/base/system.h" #include "core/base/file_util.h" #include "core/base/sizes.h" @@ -26,8 +27,6 @@ #include "core/gba/gbaRtc.h" #include "core/gba/gbaSound.h" -#include "../filters/interframe.hpp" - #define FRAMERATE (16777216.0 / 280896.0) // 59.73 #define SAMPLERATE 32768.0 @@ -855,7 +854,7 @@ static void load_image_preferences(void) coreOptions.mirroringEnable = (buffer[0] == 'F') ? true : false; if (!coreOptions.cpuSaveType) - utilGBAFindSave(romSize); + flashDetectSaveType(romSize); coreOptions.saveType = coreOptions.cpuSaveType; @@ -1220,7 +1219,7 @@ static void update_variables(bool startup) bool prev_lcdfilter = option_lcdfilter; option_lcdfilter = (!strcmp(var.value, "enabled")) ? true : false; if (prev_lcdfilter != option_lcdfilter) - utilUpdateSystemColorMaps(option_lcdfilter); + gbafilter_update_colors(option_lcdfilter); } var.key = "vbam_interframeblending"; @@ -1610,7 +1609,7 @@ bool retro_load_game(const struct retro_game_info *game) return false; } - utilUpdateSystemColorMaps(option_lcdfilter); + gbafilter_update_colors(option_lcdfilter); update_variables(true); soundInit(); diff --git a/src/sdl/ConfigManager.cpp b/src/sdl/ConfigManager.cpp index 202c5835..f210a2e2 100644 --- a/src/sdl/ConfigManager.cpp +++ b/src/sdl/ConfigManager.cpp @@ -1,4 +1,5 @@ #include "ConfigManager.h" +#include "components/user_config/user_config.h" // necessary to get portable strerror_r #undef _GNU_SOURCE @@ -14,7 +15,6 @@ #include #include -#include "../Util.h" #include "core/base/file_util.h" #include "core/gb/gbGlobals.h" #include "core/gb/gbSound.h" @@ -452,7 +452,7 @@ const char* FindConfigFile(const char *name) mkdir(fullDir, 0755); if (fullDir) { - sprintf(path, "%s%c%s", fullDir, FILE_SEP, name); + sprintf(path, "%s%c%s", fullDir, kFileSep, name); if (FileExists(path)) { return path; @@ -462,7 +462,7 @@ const char* FindConfigFile(const char *name) #ifdef _WIN32 char *home = getenv("USERPROFILE"); if (home != NULL) { - sprintf(path, "%s%c%s", home, FILE_SEP, name); + sprintf(path, "%s%c%s", home, kFileSep, name); if (FileExists(path)) { return path; @@ -479,10 +479,10 @@ const char* FindConfigFile(const char *name) char *tok = strtok(buffer, PATH_SEP); while (tok) { - sprintf(env_path, "%s%c%s", tok, FILE_SEP, EXE_NAME); + sprintf(env_path, "%s%c%s", tok, kFileSep, EXE_NAME); if (FileExists(env_path)) { static char path2[2048]; - sprintf(path2, "%s%c%s", tok, FILE_SEP, name); + sprintf(path2, "%s%c%s", tok, kFileSep, name); if (FileExists(path2)) { return path2; } @@ -494,10 +494,10 @@ const char* FindConfigFile(const char *name) else { // executable is relative to some directory strcpy(buffer, arg0); - char *p = strrchr(buffer, FILE_SEP); + char *p = strrchr(buffer, kFileSep); if (p) { *p = 0; - sprintf(path, "%s%c%s", buffer, FILE_SEP, name); + sprintf(path, "%s%c%s", buffer, kFileSep, name); if (FileExists(path)) { return path; @@ -505,13 +505,13 @@ const char* FindConfigFile(const char *name) } } #else // ! _WIN32 - sprintf(path, "%s%c%s", PKGDATADIR, FILE_SEP, name); + sprintf(path, "%s%c%s", PKGDATADIR, kFileSep, name); if (FileExists(path)) { return path; } - sprintf(path, "%s%c%s", SYSCONF_INSTALL_DIR, FILE_SEP, name); + sprintf(path, "%s%c%s", SYSCONF_INSTALL_DIR, kFileSep, name); if (FileExists(path)) { return path; diff --git a/src/sdl/SDL.cpp b/src/sdl/SDL.cpp index 0213940e..6766b8bb 100644 --- a/src/sdl/SDL.cpp +++ b/src/sdl/SDL.cpp @@ -43,7 +43,10 @@ #include -#include "../Util.h" +#include "components/audio_sdl/audio_sdl.h" +#include "components/draw_text/draw_text.h" +#include "components/filters_agb/filters_agb.h" +#include "components/user_config/user_config.h" #include "core/base/file_util.h" #include "core/base/message.h" #include "core/base/patch.h" @@ -59,12 +62,10 @@ #include "core/gba/gbaRtc.h" #include "core/gba/gbaSound.h" -#include "../common/SoundSDL.h" #include "ConfigManager.h" #include "filters.h" #include "inputSDL.h" -#include "text.h" // from: https://stackoverflow.com/questions/7608714/why-is-my-pointer-not-null-after-free #define freeSafe(ptr) free(ptr); ptr = NULL; @@ -287,7 +288,7 @@ void StartLirc(void) fprintf(stdout, "Success\n"); //read the config file char LIRCConfigLoc[2048]; - sprintf(LIRCConfigLoc, "%s%c%s", homeConfigDir, FILE_SEP, "lircrc"); + sprintf(LIRCConfigLoc, "%s%c%s", homeConfigDir, kFileSep, "lircrc"); fprintf(stdout, "LIRC Config file:"); if (lirc_readconfig(LIRCConfigLoc, &LIRCConfigInfo, NULL) == 0) { //check vbam dir for lircrc @@ -349,7 +350,7 @@ bool sdlCheckDirectory(const char* dir) char* sdlGetFilename(const char* name) { char path[1024]; - const char *filename = strrchr(name, FILE_SEP); + const char *filename = strrchr(name, kFileSep); if (filename) strcpy(path, filename + 1); else @@ -360,7 +361,7 @@ char* sdlGetFilename(const char* name) char* sdlGetFilePath(const char* name) { char path[1024]; - const char *filename = strrchr(name, FILE_SEP); + const char *filename = strrchr(name, kFileSep); if (filename) { size_t length = strlen(name) - strlen(filename); memcpy(path, name, length); @@ -368,7 +369,7 @@ char* sdlGetFilePath(const char* name) } else { path[0] = '.'; - path[1] = FILE_SEP; + path[1] = kFileSep; path[2] = '\0'; } return strdup(path); @@ -381,11 +382,11 @@ FILE* sdlFindFile(const char* name) #ifdef _WIN32 #define PATH_SEP ";" -#define FILE_SEP '\\' +#define kFileSep '\\' #define EXE_NAME "vbam.exe" #else // ! _WIN32 #define PATH_SEP ":" -#define FILE_SEP '/' +#define kFileSep '/' #define EXE_NAME "vbam" #endif // ! _WIN32 @@ -402,7 +403,7 @@ FILE* sdlFindFile(const char* name) if (strlen(homeDataDir)) { fprintf(stdout, "Searching home directory: %s\n", homeDataDir); - sprintf(path, "%s%c%s", homeDataDir, FILE_SEP, name); + sprintf(path, "%s%c%s", homeDataDir, kFileSep, name); f = fopen(path, "r"); if (f != NULL) return f; @@ -412,7 +413,7 @@ FILE* sdlFindFile(const char* name) char* profileDir = getenv("USERPROFILE"); if (profileDir != NULL) { fprintf(stdout, "Searching user profile directory: %s\n", profileDir); - sprintf(path, "%s%c%s", profileDir, FILE_SEP, name); + sprintf(path, "%s%c%s", profileDir, kFileSep, name); f = fopen(path, "r"); if (f != NULL) return f; @@ -428,12 +429,12 @@ FILE* sdlFindFile(const char* name) char* tok = strtok(buffer, PATH_SEP); while (tok) { - sprintf(path, "%s%c%s", tok, FILE_SEP, EXE_NAME); + sprintf(path, "%s%c%s", tok, kFileSep, EXE_NAME); f = fopen(path, "r"); if (f != NULL) { char path2[2048]; fclose(f); - sprintf(path2, "%s%c%s", tok, FILE_SEP, name); + sprintf(path2, "%s%c%s", tok, kFileSep, name); f = fopen(path2, "r"); if (f != NULL) { fprintf(stdout, "Found at %s\n", path2); @@ -447,10 +448,10 @@ FILE* sdlFindFile(const char* name) // executable is relative to some directory fprintf(stdout, "Searching executable directory\n"); strcpy(buffer, home); - char* p = strrchr(buffer, FILE_SEP); + char* p = strrchr(buffer, kFileSep); if (p) { *p = 0; - sprintf(path, "%s%c%s", buffer, FILE_SEP, name); + sprintf(path, "%s%c%s", buffer, kFileSep, name); f = fopen(path, "r"); if (f != NULL) return f; @@ -458,13 +459,13 @@ FILE* sdlFindFile(const char* name) } #else // ! _WIN32 fprintf(stdout, "Searching data directory: %s\n", PKGDATADIR); - sprintf(path, "%s%c%s", PKGDATADIR, FILE_SEP, name); + sprintf(path, "%s%c%s", PKGDATADIR, kFileSep, name); f = fopen(path, "r"); if (f != NULL) return f; fprintf(stdout, "Searching system config directory: %s\n", SYSCONF_INSTALL_DIR); - sprintf(path, "%s%c%s", SYSCONF_INSTALL_DIR, FILE_SEP, name); + sprintf(path, "%s%c%s", SYSCONF_INSTALL_DIR, kFileSep, name); f = fopen(path, "r"); if (f != NULL) return f; @@ -652,11 +653,11 @@ static char* sdlStateName(int num) char *gameFile = sdlGetFilename(filename); if (saveDir) - sprintf(stateName, "%s%c%s%d.sgm", saveDir, FILE_SEP, gameFile, num + 1); + sprintf(stateName, "%s%c%s%d.sgm", saveDir, kFileSep, gameFile, num + 1); else if (access(gameDir, W_OK) == 0) - sprintf(stateName, "%s%c%s%d.sgm", gameDir, FILE_SEP, gameFile, num + 1); + sprintf(stateName, "%s%c%s%d.sgm", gameDir, kFileSep, gameFile, num + 1); else - sprintf(stateName, "%s%c%s%d.sgm", homeDataDir, FILE_SEP, gameFile, num + 1); + sprintf(stateName, "%s%c%s%d.sgm", homeDataDir, kFileSep, gameFile, num + 1); freeSafe(gameDir); freeSafe(gameFile); @@ -755,11 +756,11 @@ void sdlWriteBattery() char *gameFile = sdlGetFilename(filename); if (batteryDir) - sprintf(buffer, "%s%c%s.sav", batteryDir, FILE_SEP, gameFile); + sprintf(buffer, "%s%c%s.sav", batteryDir, kFileSep, gameFile); else if (access(gameDir, W_OK) == 0) - sprintf(buffer, "%s%c%s.sav", gameDir, FILE_SEP, gameFile); + sprintf(buffer, "%s%c%s.sav", gameDir, kFileSep, gameFile); else - sprintf(buffer, "%s%c%s.sav", homeDataDir, FILE_SEP, gameFile); + sprintf(buffer, "%s%c%s.sav", homeDataDir, kFileSep, gameFile); bool result = emulator.emuWriteBattery(buffer); @@ -777,11 +778,11 @@ void sdlReadBattery() char *gameFile = sdlGetFilename(filename); if (batteryDir) - sprintf(buffer, "%s%c%s.sav", batteryDir, FILE_SEP, gameFile); + sprintf(buffer, "%s%c%s.sav", batteryDir, kFileSep, gameFile); else if (access(gameDir, W_OK) == 0) - sprintf(buffer, "%s%c%s.sav", gameDir, FILE_SEP, gameFile); + sprintf(buffer, "%s%c%s.sav", gameDir, kFileSep, gameFile); else - sprintf(buffer, "%s%c%s.sav", homeDataDir, FILE_SEP, gameFile); + sprintf(buffer, "%s%c%s.sav", homeDataDir, kFileSep, gameFile); bool result = emulator.emuReadBattery(buffer); @@ -1737,7 +1738,7 @@ int main(int argc, char** argv) failed = (size == 0); if (!failed) { if (coreOptions.cpuSaveType == 0) - utilGBAFindSave(size); + flashDetectSaveType(size); else coreOptions.saveType = coreOptions.cpuSaveType; @@ -1847,7 +1848,7 @@ int main(int argc, char** argv) fprintf(stdout, "Color depth: %d\n", systemColorDepth); - utilUpdateSystemColorMaps(); + gbafilter_update_colors(); if (delta == NULL) { delta = (uint8_t*)malloc(delta_size); @@ -2145,20 +2146,20 @@ void systemScreenCapture(int a) if (captureFormat) { if (screenShotDir) - sprintf(buffer, "%s%c%s%02d.bmp", screenShotDir, FILE_SEP, gameFile, a); + sprintf(buffer, "%s%c%s%02d.bmp", screenShotDir, kFileSep, gameFile, a); else if (access(gameDir, W_OK) == 0) - sprintf(buffer, "%s%c%s%02d.bmp", gameDir, FILE_SEP, gameFile, a); + sprintf(buffer, "%s%c%s%02d.bmp", gameDir, kFileSep, gameFile, a); else - sprintf(buffer, "%s%c%s%02d.bmp", homeDataDir, FILE_SEP, gameFile, a); + sprintf(buffer, "%s%c%s%02d.bmp", homeDataDir, kFileSep, gameFile, a); result = emulator.emuWriteBMP(buffer); } else { if (screenShotDir) - sprintf(buffer, "%s%c%s%02d.png", screenShotDir, FILE_SEP, gameFile, a); + sprintf(buffer, "%s%c%s%02d.png", screenShotDir, kFileSep, gameFile, a); else if (access(gameDir, W_OK) == 0) - sprintf(buffer, "%s%c%s%02d.png", gameDir, FILE_SEP, gameFile, a); + sprintf(buffer, "%s%c%s%02d.png", gameDir, kFileSep, gameFile, a); else - sprintf(buffer, "%s%c%s%02d.png", homeDataDir, FILE_SEP, gameFile, a); + sprintf(buffer, "%s%c%s%02d.png", homeDataDir, kFileSep, gameFile, a); result = emulator.emuWritePNG(buffer); } diff --git a/src/sdl/filters.cpp b/src/sdl/filters.cpp index 7c9d4952..f71d8809 100644 --- a/src/sdl/filters.cpp +++ b/src/sdl/filters.cpp @@ -18,206 +18,25 @@ #include "filters.h" -#include "../filters/interframe.hpp" +#include "components/filters/filters.h" +#include "components/filters_interframe/interframe.h" -// -// Screen filters -// - -extern int Init_2xSaI(uint32_t); -extern void hq2x_init(unsigned); -extern bool sdlStretchInit(int colorDepth, int sizeMultiplier, int srcWidth); - -extern void sdlStretch1x(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void sdlStretch2x(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void sdlStretch3x(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void sdlStretch4x(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void _2xSaI(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void _2xSaI32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void Super2xSaI(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void Super2xSaI32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void SuperEagle(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void SuperEagle32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void Pixelate(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void Pixelate32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void AdMame2x(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void AdMame2x32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void Bilinear(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void Bilinear32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void BilinearPlus(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void BilinearPlus32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void Scanlines(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void Scanlines32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void ScanlinesTV(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void ScanlinesTV32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void hq2x(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void hq2x32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void lq2x(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void lq2x32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void hq3x16(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void hq4x16(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void hq3x32_32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void hq4x32_32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void xbrz2x32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void xbrz3x32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void xbrz4x32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void xbrz5x32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); -extern void xbrz6x32(uint8_t*, uint32_t, uint8_t*, uint8_t*, uint32_t, int, int); - -struct FilterDesc { - char name[30]; - int enlargeFactor; - FilterFunc func16; - FilterFunc func24; - FilterFunc func32; -}; - -const FilterDesc Filters[] = { - { "Stretch 1x", 1, sdlStretch1x, sdlStretch1x, sdlStretch1x }, - { "Stretch 2x", 2, sdlStretch2x, sdlStretch2x, sdlStretch2x }, - { "2xSaI", 2, _2xSaI, 0, _2xSaI32 }, - { "Super 2xSaI", 2, Super2xSaI, 0, Super2xSaI32 }, - { "Super Eagle", 2, SuperEagle, 0, SuperEagle32 }, - { "Pixelate", 2, Pixelate, 0, Pixelate32 }, - { "AdvanceMAME Scale2x", 2, AdMame2x, 0, AdMame2x32 }, - { "Bilinear", 2, Bilinear, 0, Bilinear32 }, - { "Bilinear Plus", 2, BilinearPlus, 0, BilinearPlus32 }, - { "Scanlines", 2, Scanlines, 0, Scanlines32 }, - { "TV Mode", 2, ScanlinesTV, 0, ScanlinesTV32 }, - { "lq2x", 2, lq2x, 0, lq2x32 }, - { "hq2x", 2, hq2x, 0, hq2x32 }, - { "xbrz2x", 2, 0, 0, xbrz2x32 }, - { "Stretch 3x", 3, sdlStretch3x, sdlStretch3x, sdlStretch3x }, - { "hq3x", 3, hq3x16, 0, hq3x32_32 }, - { "xbrz3x", 3, 0, 0, xbrz3x32 }, - { "Stretch 4x", 4, sdlStretch4x, sdlStretch4x, sdlStretch4x }, - { "hq4x", 4, hq4x16, 0, hq4x32_32 }, - { "xbrz4x", 4, 0, 0, xbrz4x32 }, - { "xbrz5x", 5, 0, 0, xbrz5x32 }, - { "xbrz6x", 6, 0, 0, xbrz6x32 } -}; - -int getFilterEnlargeFactor(const int f) -{ - return Filters[f].enlargeFactor; -} - -char* getFilterName(const int f) -{ - return (char*)Filters[f].name; -} - -FilterFunc initFilter(const int f, const int colorDepth, const int srcWidth) -{ - FilterFunc func; - - switch (colorDepth) { - case 15: - case 16: - func = Filters[f].func16; - break; - case 24: - func = Filters[f].func24; - break; - case 32: - func = Filters[f].func32; - break; - default: - func = 0; - break; - } - - if (func) - switch (f) { - case kStretch1x: - sdlStretchInit(colorDepth, 0, srcWidth); - break; - case kStretch2x: - sdlStretchInit(colorDepth, 1, srcWidth); - break; - case kStretch3x: - sdlStretchInit(colorDepth, 2, srcWidth); - break; - case kStretch4x: - sdlStretchInit(colorDepth, 3, srcWidth); - break; - case k2xSaI: - case kSuper2xSaI: - case kSuperEagle: - if (colorDepth == 15) - Init_2xSaI(555); - else if (colorDepth == 16) - Init_2xSaI(565); - else - Init_2xSaI(colorDepth); - break; - case khq2x: - case klq2x: - hq2x_init(colorDepth); - break; - default: - break; - } - - return func; -} - -struct IFBFilterDesc { - char name[30]; - IFBFilterFunc func16; - IFBFilterFunc func32; -}; - -const IFBFilterDesc IFBFilters[] = { - { "No interframe blending", 0, 0 }, - { "Interframe motion blur", MotionBlurIB, MotionBlurIB32 }, - { "Smart interframe blending", SmartIB, SmartIB32 } -}; - -IFBFilterFunc initIFBFilter(const int f, const int colorDepth) -{ - IFBFilterFunc func; - - switch (colorDepth) { - case 15: - case 16: - func = IFBFilters[f].func16; - break; - case 32: - func = IFBFilters[f].func32; - break; - case 24: - default: - func = 0; - break; - } - - return func; -} - -char* getIFBFilterName(const IFBFilter f) -{ - return (char*)IFBFilters[f].name; -} +namespace { // // Optimized stretchers implementation // - #ifndef C_CORE uint8_t sdlStretcher[16384]; #ifdef _MSC_VER -#define SDL_CALL_STRETCHER \ - { \ - __asm mov eax, stretcher __asm mov edi, destPtr __asm mov esi, srcPtr __asm call eax \ - } -#else #define SDL_CALL_STRETCHER \ - asm volatile("call *%%eax" ::"a"(stretcher), "S"(srcPtr), "D"(dstPtr)) + { __asm mov eax, stretcher __asm mov edi, destPtr __asm mov esi, srcPtr __asm call eax } +#else +#define SDL_CALL_STRETCHER asm volatile("call *%%eax" ::"a"(stretcher), "S"(srcPtr), "D"(dstPtr)) #endif -#define SDL_LONG(val) \ +#define SDL_LONG(val) \ *((uint32_t*)&sdlStretcher[sdlStretcherPos]) = val; \ sdlStretcherPos += 4; @@ -282,38 +101,27 @@ uint8_t sdlStretcher[16384]; sdlStretcher[sdlStretcherPos++] = 0xc7; \ sdlStretcher[sdlStretcherPos++] = 0x03; -#define SDL_RET \ - sdlStretcher[sdlStretcherPos++] = 0xc3; +#define SDL_RET sdlStretcher[sdlStretcherPos++] = 0xc3; -#define SDL_PUSH_EAX \ - sdlStretcher[sdlStretcherPos++] = 0x50; +#define SDL_PUSH_EAX sdlStretcher[sdlStretcherPos++] = 0x50; -#define SDL_PUSH_ECX \ - sdlStretcher[sdlStretcherPos++] = 0x51; +#define SDL_PUSH_ECX sdlStretcher[sdlStretcherPos++] = 0x51; -#define SDL_PUSH_EBX \ - sdlStretcher[sdlStretcherPos++] = 0x53; +#define SDL_PUSH_EBX sdlStretcher[sdlStretcherPos++] = 0x53; -#define SDL_PUSH_ESI \ - sdlStretcher[sdlStretcherPos++] = 0x56; +#define SDL_PUSH_ESI sdlStretcher[sdlStretcherPos++] = 0x56; -#define SDL_PUSH_EDI \ - sdlStretcher[sdlStretcherPos++] = 0x57; +#define SDL_PUSH_EDI sdlStretcher[sdlStretcherPos++] = 0x57; -#define SDL_POP_EAX \ - sdlStretcher[sdlStretcherPos++] = 0x58; +#define SDL_POP_EAX sdlStretcher[sdlStretcherPos++] = 0x58; -#define SDL_POP_ECX \ - sdlStretcher[sdlStretcherPos++] = 0x59; +#define SDL_POP_ECX sdlStretcher[sdlStretcherPos++] = 0x59; -#define SDL_POP_EBX \ - sdlStretcher[sdlStretcherPos++] = 0x5b; +#define SDL_POP_EBX sdlStretcher[sdlStretcherPos++] = 0x5b; -#define SDL_POP_ESI \ - sdlStretcher[sdlStretcherPos++] = 0x5e; +#define SDL_POP_ESI sdlStretcher[sdlStretcherPos++] = 0x5e; -#define SDL_POP_EDI \ - sdlStretcher[sdlStretcherPos++] = 0x5f; +#define SDL_POP_EDI sdlStretcher[sdlStretcherPos++] = 0x5f; #define SDL_MOV_ECX(val) \ sdlStretcher[sdlStretcherPos++] = 0xb9; \ @@ -332,137 +140,134 @@ uint8_t sdlStretcher[16384]; sdlStretcher[sdlStretcherPos++] = 0xf3; \ sdlStretcher[sdlStretcherPos++] = 0xa5; -void sdlMakeStretcher(int width, int sizeOption) -{ +void sdlMakeStretcher(int width, int sizeOption) { int sdlStretcherPos; sdlStretcherPos = 0; switch (systemColorDepth) { - case 16: - if (sizeOption) { - SDL_PUSH_EAX; - SDL_PUSH_ESI; - SDL_PUSH_EDI; - for (int i = 0; i < width; i++) { - SDL_LOADW; - SDL_STOREW; - SDL_STOREW; - if (sizeOption > 1) { + case 16: + if (sizeOption) { + SDL_PUSH_EAX; + SDL_PUSH_ESI; + SDL_PUSH_EDI; + for (int i = 0; i < width; i++) { + SDL_LOADW; SDL_STOREW; - } - if (sizeOption > 2) { SDL_STOREW; + if (sizeOption > 1) { + SDL_STOREW; + } + if (sizeOption > 2) { + SDL_STOREW; + } } + SDL_POP_EDI; + SDL_POP_ESI; + SDL_POP_EAX; + SDL_RET; + } else { + SDL_PUSH_ESI; + SDL_PUSH_EDI; + SDL_PUSH_ECX; + SDL_MOV_ECX(width); + SDL_REP_MOVSW; + SDL_POP_ECX; + SDL_POP_EDI; + SDL_POP_ESI; + SDL_RET; } - SDL_POP_EDI; - SDL_POP_ESI; - SDL_POP_EAX; - SDL_RET; - } else { - SDL_PUSH_ESI; - SDL_PUSH_EDI; - SDL_PUSH_ECX; - SDL_MOV_ECX(width); - SDL_REP_MOVSW; - SDL_POP_ECX; - SDL_POP_EDI; - SDL_POP_ESI; - SDL_RET; - } - break; - case 24: - if (sizeOption) { - SDL_PUSH_EAX; - SDL_PUSH_ESI; - SDL_PUSH_EDI; - int w = width - 1; - for (int i = 0; i < w; i++) { + break; + case 24: + if (sizeOption) { + SDL_PUSH_EAX; + SDL_PUSH_ESI; + SDL_PUSH_EDI; + int w = width - 1; + for (int i = 0; i < w; i++) { + SDL_LOADL2; + SDL_STOREL2; + SDL_STOREL2; + if (sizeOption > 1) { + SDL_STOREL2; + } + if (sizeOption > 2) { + SDL_STOREL2; + } + } + // need to write the last one SDL_LOADL2; SDL_STOREL2; - SDL_STOREL2; if (sizeOption > 1) { SDL_STOREL2; } if (sizeOption > 2) { SDL_STOREL2; } - } - // need to write the last one - SDL_LOADL2; - SDL_STOREL2; - if (sizeOption > 1) { + SDL_AND_EAX(0x00ffffff); + SDL_PUSH_EBX; + SDL_LOADL_EBX; + SDL_AND_EBX(0xff000000); + SDL_OR_EAX_EBX; + SDL_POP_EBX; SDL_STOREL2; + SDL_POP_EDI; + SDL_POP_ESI; + SDL_POP_EAX; + SDL_RET; + } else { + SDL_PUSH_ESI; + SDL_PUSH_EDI; + SDL_PUSH_ECX; + SDL_MOV_ECX(3 * width); + SDL_REP_MOVSB; + SDL_POP_ECX; + SDL_POP_EDI; + SDL_POP_ESI; + SDL_RET; } - if (sizeOption > 2) { - SDL_STOREL2; - } - SDL_AND_EAX(0x00ffffff); - SDL_PUSH_EBX; - SDL_LOADL_EBX; - SDL_AND_EBX(0xff000000); - SDL_OR_EAX_EBX; - SDL_POP_EBX; - SDL_STOREL2; - SDL_POP_EDI; - SDL_POP_ESI; - SDL_POP_EAX; - SDL_RET; - } else { - SDL_PUSH_ESI; - SDL_PUSH_EDI; - SDL_PUSH_ECX; - SDL_MOV_ECX(3 * width); - SDL_REP_MOVSB; - SDL_POP_ECX; - SDL_POP_EDI; - SDL_POP_ESI; - SDL_RET; - } - break; - case 32: - if (sizeOption) { - SDL_PUSH_EAX; - SDL_PUSH_ESI; - SDL_PUSH_EDI; - for (int i = 0; i < width; i++) { - SDL_LOADL; - SDL_STOREL; - SDL_STOREL; - if (sizeOption > 1) { + break; + case 32: + if (sizeOption) { + SDL_PUSH_EAX; + SDL_PUSH_ESI; + SDL_PUSH_EDI; + for (int i = 0; i < width; i++) { + SDL_LOADL; SDL_STOREL; - } - if (sizeOption > 2) { SDL_STOREL; + if (sizeOption > 1) { + SDL_STOREL; + } + if (sizeOption > 2) { + SDL_STOREL; + } } + SDL_POP_EDI; + SDL_POP_ESI; + SDL_POP_EAX; + SDL_RET; + } else { + SDL_PUSH_ESI; + SDL_PUSH_EDI; + SDL_PUSH_ECX; + SDL_MOV_ECX(width); + SDL_REP_MOVSL; + SDL_POP_ECX; + SDL_POP_EDI; + SDL_POP_ESI; + SDL_RET; } - SDL_POP_EDI; - SDL_POP_ESI; - SDL_POP_EAX; - SDL_RET; - } else { - SDL_PUSH_ESI; - SDL_PUSH_EDI; - SDL_PUSH_ECX; - SDL_MOV_ECX(width); - SDL_REP_MOVSL; - SDL_POP_ECX; - SDL_POP_EDI; - SDL_POP_ESI; - SDL_RET; - } - break; + break; } } -#else // C_CORE +#else // C_CORE void (*sdlStretcher)(uint8_t*, uint8_t*, int) = 0; -#define SDL_CALL_STRETCHER \ - sdlStretcher(srcPtr, dstPtr, width) +#define SDL_CALL_STRETCHER sdlStretcher(srcPtr, dstPtr, width) template -void sdlStretchx1(uint8_t* src, uint8_t* dest, int width) -{ +void sdlStretchx1(uint8_t* src, uint8_t* dest, int width) { T* s = (T*)src; T* d = (T*)dest; for (int i = 0; i < width; i++) @@ -470,8 +275,7 @@ void sdlStretchx1(uint8_t* src, uint8_t* dest, int width) } template -void sdlStretchx2(uint8_t* src, uint8_t* dest, int width) -{ +void sdlStretchx2(uint8_t* src, uint8_t* dest, int width) { T* s = (T*)src; T* d = (T*)dest; for (int i = 0; i < width; i++) { @@ -481,8 +285,7 @@ void sdlStretchx2(uint8_t* src, uint8_t* dest, int width) } template -void sdlStretchx3(uint8_t* src, uint8_t* dest, int width) -{ +void sdlStretchx3(uint8_t* src, uint8_t* dest, int width) { T* s = (T*)src; T* d = (T*)dest; for (int i = 0; i < width; i++) { @@ -493,8 +296,7 @@ void sdlStretchx3(uint8_t* src, uint8_t* dest, int width) } template -void sdlStretchx4(uint8_t* src, uint8_t* dest, int width) -{ +void sdlStretchx4(uint8_t* src, uint8_t* dest, int width) { T* s = (T*)src; T* d = (T*)dest; for (int i = 0; i < width; i++) { @@ -506,21 +308,12 @@ void sdlStretchx4(uint8_t* src, uint8_t* dest, int width) } void (*sdlStretcher16[4])(uint8_t*, uint8_t*, int) = { - sdlStretchx1, - sdlStretchx2, - sdlStretchx3, - sdlStretchx4 -}; + sdlStretchx1, sdlStretchx2, sdlStretchx3, sdlStretchx4}; void (*sdlStretcher32[4])(uint8_t*, uint8_t*, int) = { - sdlStretchx1, - sdlStretchx2, - sdlStretchx3, - sdlStretchx4 -}; + sdlStretchx1, sdlStretchx2, sdlStretchx3, sdlStretchx4}; -void sdlStretch24x1(uint8_t* src, uint8_t* dest, int width) -{ +void sdlStretch24x1(uint8_t* src, uint8_t* dest, int width) { uint8_t* s = src; uint8_t* d = dest; for (int i = 0; i < width; i++) { @@ -530,8 +323,7 @@ void sdlStretch24x1(uint8_t* src, uint8_t* dest, int width) } } -void sdlStretch24x2(uint8_t* src, uint8_t* dest, int width) -{ +void sdlStretch24x2(uint8_t* src, uint8_t* dest, int width) { uint8_t* s = (uint8_t*)src; uint8_t* d = (uint8_t*)dest; for (int i = 0; i < width; i++) { @@ -546,8 +338,7 @@ void sdlStretch24x2(uint8_t* src, uint8_t* dest, int width) } } -void sdlStretch24x3(uint8_t* src, uint8_t* dest, int width) -{ +void sdlStretch24x3(uint8_t* src, uint8_t* dest, int width) { uint8_t* s = (uint8_t*)src; uint8_t* d = (uint8_t*)dest; for (int i = 0; i < width; i++) { @@ -566,8 +357,7 @@ void sdlStretch24x3(uint8_t* src, uint8_t* dest, int width) } } -void sdlStretch24x4(uint8_t* src, uint8_t* dest, int width) -{ +void sdlStretch24x4(uint8_t* src, uint8_t* dest, int width) { uint8_t* s = (uint8_t*)src; uint8_t* d = (uint8_t*)dest; for (int i = 0; i < width; i++) { @@ -590,40 +380,40 @@ void sdlStretch24x4(uint8_t* src, uint8_t* dest, int width) } } -void (*sdlStretcher24[4])(uint8_t*, uint8_t*, int) = { - sdlStretch24x1, - sdlStretch24x2, - sdlStretch24x3, - sdlStretch24x4 -}; +void (*sdlStretcher24[4])(uint8_t*, uint8_t*, int) = {sdlStretch24x1, sdlStretch24x2, + sdlStretch24x3, sdlStretch24x4}; -#endif // C_CORE +#endif // C_CORE -bool sdlStretchInit(int colorDepth, int sizeMultiplier, int srcWidth) -{ - (void)srcWidth; // unused params +bool sdlStretchInit(int colorDepth, int sizeMultiplier, int srcWidth) { + (void)srcWidth; // unused params #ifndef C_CORE sdlMakeStretcher(srcWidth, sizeMultiplier); #else switch (colorDepth) { - case 16: - sdlStretcher = sdlStretcher16[sizeMultiplier]; - break; - case 24: - sdlStretcher = sdlStretcher24[sizeMultiplier]; - break; - case 32: - sdlStretcher = sdlStretcher32[sizeMultiplier]; - break; - default: - return false; + case 16: + sdlStretcher = sdlStretcher16[sizeMultiplier]; + break; + case 24: + sdlStretcher = sdlStretcher24[sizeMultiplier]; + break; + case 32: + sdlStretcher = sdlStretcher32[sizeMultiplier]; + break; + default: + return false; } #endif return true; } -void sdlStretch1x(uint8_t* srcPtr, uint32_t srcPitch, uint8_t* /* deltaPtr */, uint8_t* dstPtr, uint32_t dstPitch, int width, int height) -{ +void sdlStretch1x(uint8_t* srcPtr, + uint32_t srcPitch, + uint8_t* /* deltaPtr */, + uint8_t* dstPtr, + uint32_t dstPitch, + int width, + int height) { int i; #ifndef C_CORE uint32_t* stretcher = (uint32_t*)sdlStretcher; @@ -634,8 +424,13 @@ void sdlStretch1x(uint8_t* srcPtr, uint32_t srcPitch, uint8_t* /* deltaPtr */, u dstPtr += dstPitch; } } -void sdlStretch2x(uint8_t* srcPtr, uint32_t srcPitch, uint8_t* /* deltaPtr */, uint8_t* dstPtr, uint32_t dstPitch, int width, int height) -{ +void sdlStretch2x(uint8_t* srcPtr, + uint32_t srcPitch, + uint8_t* /* deltaPtr */, + uint8_t* dstPtr, + uint32_t dstPitch, + int width, + int height) { int i; #ifndef C_CORE uint32_t* stretcher = (uint32_t*)sdlStretcher; @@ -648,8 +443,13 @@ void sdlStretch2x(uint8_t* srcPtr, uint32_t srcPitch, uint8_t* /* deltaPtr */, u dstPtr += dstPitch; } } -void sdlStretch3x(uint8_t* srcPtr, uint32_t srcPitch, uint8_t* /* deltaPtr */, uint8_t* dstPtr, uint32_t dstPitch, int width, int height) -{ +void sdlStretch3x(uint8_t* srcPtr, + uint32_t srcPitch, + uint8_t* /* deltaPtr */, + uint8_t* dstPtr, + uint32_t dstPitch, + int width, + int height) { int i; #ifndef C_CORE uint32_t* stretcher = (uint32_t*)sdlStretcher; @@ -664,8 +464,13 @@ void sdlStretch3x(uint8_t* srcPtr, uint32_t srcPitch, uint8_t* /* deltaPtr */, u dstPtr += dstPitch; } } -void sdlStretch4x(uint8_t* srcPtr, uint32_t srcPitch, uint8_t* /* deltaPtr */, uint8_t* dstPtr, uint32_t dstPitch, int width, int height) -{ +void sdlStretch4x(uint8_t* srcPtr, + uint32_t srcPitch, + uint8_t* /* deltaPtr */, + uint8_t* dstPtr, + uint32_t dstPitch, + int width, + int height) { int i; #ifndef C_CORE uint32_t* stretcher = (uint32_t*)sdlStretcher; @@ -682,3 +487,132 @@ void sdlStretch4x(uint8_t* srcPtr, uint32_t srcPitch, uint8_t* /* deltaPtr */, u dstPtr += dstPitch; } } + +} // namespace + +struct FilterDesc { + char name[30]; + int enlargeFactor; + FilterFunc func16; + FilterFunc func24; + FilterFunc func32; +}; + +const FilterDesc Filters[] = {{"Stretch 1x", 1, sdlStretch1x, sdlStretch1x, sdlStretch1x}, + {"Stretch 2x", 2, sdlStretch2x, sdlStretch2x, sdlStretch2x}, + {"2xSaI", 2, _2xSaI, 0, _2xSaI32}, + {"Super 2xSaI", 2, Super2xSaI, 0, Super2xSaI32}, + {"Super Eagle", 2, SuperEagle, 0, SuperEagle32}, + {"Pixelate", 2, Pixelate, 0, Pixelate32}, + {"AdvanceMAME Scale2x", 2, AdMame2x, 0, AdMame2x32}, + {"Bilinear", 2, Bilinear, 0, Bilinear32}, + {"Bilinear Plus", 2, BilinearPlus, 0, BilinearPlus32}, + {"Scanlines", 2, Scanlines, 0, Scanlines32}, + {"TV Mode", 2, ScanlinesTV, 0, ScanlinesTV32}, + {"lq2x", 2, lq2x, 0, lq2x32}, + {"hq2x", 2, hq2x, 0, hq2x32}, + {"xbrz2x", 2, 0, 0, xbrz2x32}, + {"Stretch 3x", 3, sdlStretch3x, sdlStretch3x, sdlStretch3x}, + {"hq3x", 3, hq3x16, 0, hq3x32_32}, + {"xbrz3x", 3, 0, 0, xbrz3x32}, + {"Stretch 4x", 4, sdlStretch4x, sdlStretch4x, sdlStretch4x}, + {"hq4x", 4, hq4x16, 0, hq4x32_32}, + {"xbrz4x", 4, 0, 0, xbrz4x32}, + {"xbrz5x", 5, 0, 0, xbrz5x32}, + {"xbrz6x", 6, 0, 0, xbrz6x32}}; + +int getFilterEnlargeFactor(const int f) { + return Filters[f].enlargeFactor; +} + +char* getFilterName(const int f) { + return (char*)Filters[f].name; +} + +FilterFunc initFilter(const int f, const int colorDepth, const int srcWidth) { + FilterFunc func; + + switch (colorDepth) { + case 15: + case 16: + func = Filters[f].func16; + break; + case 24: + func = Filters[f].func24; + break; + case 32: + func = Filters[f].func32; + break; + default: + func = 0; + break; + } + + if (func) + switch (f) { + case kStretch1x: + sdlStretchInit(colorDepth, 0, srcWidth); + break; + case kStretch2x: + sdlStretchInit(colorDepth, 1, srcWidth); + break; + case kStretch3x: + sdlStretchInit(colorDepth, 2, srcWidth); + break; + case kStretch4x: + sdlStretchInit(colorDepth, 3, srcWidth); + break; + case k2xSaI: + case kSuper2xSaI: + case kSuperEagle: + if (colorDepth == 15) + Init_2xSaI(555); + else if (colorDepth == 16) + Init_2xSaI(565); + else + Init_2xSaI(colorDepth); + break; + case khq2x: + case klq2x: + hq2x_init(colorDepth); + break; + default: + break; + } + + return func; +} + +struct IFBFilterDesc { + char name[30]; + IFBFilterFunc func16; + IFBFilterFunc func32; +}; + +const IFBFilterDesc IFBFilters[] = {{"No interframe blending", 0, 0}, + {"Interframe motion blur", MotionBlurIB, MotionBlurIB32}, + {"Smart interframe blending", SmartIB, SmartIB32}}; + +IFBFilterFunc initIFBFilter(const int f, const int colorDepth) { + IFBFilterFunc func; + + switch (colorDepth) { + case 15: + case 16: + func = IFBFilters[f].func16; + break; + case 32: + func = IFBFilters[f].func32; + break; + case 24: + default: + func = 0; + break; + } + + return func; +} + +char* getIFBFilterName(const IFBFilter f) { + return (char*)IFBFilters[f].name; +} diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index 3ee7230e..bd6d72f4 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -763,8 +763,6 @@ set( widgets/sdljoy.cpp widgets/user-input-ctrl.cpp widgets/wxmisc.cpp - # probably ought to be in common - ../sdl/text.cpp # from external source with minor modifications widgets/checkedlistctrl.cpp ) @@ -786,7 +784,6 @@ set( background-input.h wxlogdebug.h drawing.h - filters.h ioregs.h opts.h viewsupt.h @@ -819,8 +816,6 @@ set( widgets/wx/sdljoy.h widgets/wx/webupdatedef.h widgets/wx/wxmisc.h - # probably ought to be in common - ../sdl/text.h # from external source with minor modifications widgets/wx/checkedlistctrl.h ) @@ -924,6 +919,8 @@ if(NOT TRANSLATIONS_ONLY) ${CM_STUFF} ) + target_include_directories(visualboyadvance-m PRIVATE ${NONSTD_INCLUDE_DIR}) + if(WIN32 AND (X86_64 OR X86_32) AND ENABLE_ONLINEUPDATES) if(NOT DEFINED WINSPARKLE_BIN_RELEASE_DIR) set(WINSPARKLE_BIN_RELEASE_DIR ${CMAKE_SOURCE_DIR}/dependencies/WinSparkle-0.6.0) @@ -987,11 +984,19 @@ if(NOT TRANSLATIONS_ONLY) visualboyadvance-m ${wxWidgets_LIBRARIES} ${VBAM_LIBS} + nonstd-lib + vbam-components-audio-sdl + vbam-components-draw-text + vbam-components-filters + vbam-components-filters-agb + vbam-components-filters-interframe + vbam-components-user-config ) if(ENABLE_FFMPEG) target_link_libraries( visualboyadvance-m + vbam-components-av-recording ${FFMPEG_LIBRARIES} ) diff --git a/src/wx/cmdevents.cpp b/src/wx/cmdevents.cpp index bab8465f..8fe30b86 100644 --- a/src/wx/cmdevents.cpp +++ b/src/wx/cmdevents.cpp @@ -10,6 +10,7 @@ #include #include +#include "components/filters_interframe/interframe.h" #include "config/option-proxy.h" #include "config/option.h" #include "core/base/version.h" diff --git a/src/wx/config/game-control.h b/src/wx/config/game-control.h index 3e30c4a9..9d2473e6 100644 --- a/src/wx/config/game-control.h +++ b/src/wx/config/game-control.h @@ -3,8 +3,10 @@ #include #include -#include "nonstd/optional.hpp" #include + +#include + #include #include "config/user-input.h" diff --git a/src/wx/config/internal/option-internal.h b/src/wx/config/internal/option-internal.h index 915bb3e5..aa87baa1 100644 --- a/src/wx/config/internal/option-internal.h +++ b/src/wx/config/internal/option-internal.h @@ -2,12 +2,13 @@ #error "Do not include "config/internal/option-internal.h" outside of the implementation." #endif -#include #include -#include + +#include + +#include #include "config/option.h" -#include "nonstd/optional.hpp" namespace config { namespace internal { diff --git a/src/wx/config/option.cpp b/src/wx/config/option.cpp index 666bf86d..6a98b08b 100644 --- a/src/wx/config/option.cpp +++ b/src/wx/config/option.cpp @@ -1,7 +1,8 @@ #include "config/option.h" #include -#include "nonstd/variant.hpp" + +#include #include #include diff --git a/src/wx/config/option.h b/src/wx/config/option.h index 5d23e445..2df13805 100644 --- a/src/wx/config/option.h +++ b/src/wx/config/option.h @@ -1,13 +1,12 @@ #ifndef VBAM_WX_CONFIG_OPTIONS_H_ #define VBAM_WX_CONFIG_OPTIONS_H_ -#include "nonstd/variant.hpp" - #include #include -#include #include +#include + #include #include "config/option-id.h" diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index f75aa800..dda2e853 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -32,7 +32,6 @@ #include #include -#include "../Util.h" #include "config/option-proxy.h" #include "core/gb/gb.h" #include "core/gb/gbCheats.h" @@ -1458,7 +1457,7 @@ public: { (void)ev; // unused params uint32_t sz = wxGetApp().frame->GetPanel()->game_size(); - utilGBAFindSave(sz); + flashDetectSaveType(sz); type->SetSelection(coreOptions.saveType); if (coreOptions.saveType == GBA_SAVE_FLASH) { diff --git a/src/wx/panel.cpp b/src/wx/panel.cpp index 291f4a58..cd891664 100644 --- a/src/wx/panel.cpp +++ b/src/wx/panel.cpp @@ -1,6 +1,8 @@ #include #include #include +#include "components/filters_agb/filters_agb.h" +#include "components/filters_interframe/interframe.h" #ifdef __WXGTK__ #include @@ -20,9 +22,9 @@ #include #include -#include "../Util.h" -#include "../sdl/text.h" #include "background-input.h" +#include "components/draw_text/draw_text.h" +#include "components/filters/filters.h" #include "config/game-control.h" #include "config/option-proxy.h" #include "config/option.h" @@ -33,16 +35,15 @@ #include "core/gb/gb.h" #include "core/gb/gbCheats.h" #include "core/gb/gbGlobals.h" -#include "core/gb/gbSound.h" #include "core/gb/gbPrinter.h" +#include "core/gb/gbSound.h" #include "core/gba/gbaCheats.h" -#include "core/gba/gbaGlobals.h" #include "core/gba/gbaFlash.h" +#include "core/gba/gbaGlobals.h" #include "core/gba/gbaPrint.h" #include "core/gba/gbaRtc.h" #include "core/gba/gbaSound.h" #include "drawing.h" -#include "filters.h" #include "wayland.h" #include "widgets/render-plugin.h" #include "wxutil.h" @@ -354,7 +355,7 @@ void GameArea::LoadGame(const wxString& name) ovSaveType = 0; if (ovSaveType == 0) - utilGBAFindSave(rom_size); + flashDetectSaveType(rom_size); else coreOptions.saveType = ovSaveType; @@ -368,7 +369,7 @@ void GameArea::LoadGame(const wxString& name) coreOptions.cpuSaveType = 0; if (coreOptions.cpuSaveType == 0) - utilGBAFindSave(rom_size); + flashDetectSaveType(rom_size); else coreOptions.saveType = coreOptions.cpuSaveType; @@ -2680,11 +2681,11 @@ void GameArea::OnGBBorderChanged(config::Option* option) { void GameArea::UpdateLcdFilter() { if (loaded == IMAGE_GBA) - utilUpdateSystemColorMaps(OPTION(kGBALCDFilter)); + gbafilter_update_colors(OPTION(kGBALCDFilter)); else if (loaded == IMAGE_GB) - utilUpdateSystemColorMaps(OPTION(kGBLCDFilter)); + gbafilter_update_colors(OPTION(kGBLCDFilter)); else - utilUpdateSystemColorMaps(false); + gbafilter_update_colors(false); } void GameArea::SuspendScreenSaver() { diff --git a/src/wx/sys.cpp b/src/wx/sys.cpp index fe3b0ce7..cacc9e17 100644 --- a/src/wx/sys.cpp +++ b/src/wx/sys.cpp @@ -6,7 +6,7 @@ #include #include -#include "../common/SoundSDL.h" +#include "components/audio_sdl/audio_sdl.h" #include "config/game-control.h" #include "config/option-proxy.h" #include "core/base/image_util.h" diff --git a/src/wx/tests/CMakeLists.txt b/src/wx/tests/CMakeLists.txt index e337920a..2b22424d 100644 --- a/src/wx/tests/CMakeLists.txt +++ b/src/wx/tests/CMakeLists.txt @@ -12,7 +12,8 @@ function(add_doctest_test test_src) target_link_libraries("${test_name}" ${wxWidgets_LIBRARIES}) - target_include_directories("${test_name}" PRIVATE ${wxWidgets_INCLUDE_DIRS}) + target_include_directories("${test_name}" + PRIVATE ${wxWidgets_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/third_party/include) set_target_properties("${test_name}" PROPERTIES diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 028f9f38..477d563c 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -30,6 +30,7 @@ #include #include +#include "components/user_config/user_config.h" #include "core/gb/gbGlobals.h" #include "core/gba/gbaSound.h" @@ -42,7 +43,6 @@ // The built-in vba-over.ini #include "builtin-over.h" -#include "../Util.h" #include "config/game-control.h" #include "config/option-proxy.h" #include "config/option.h" @@ -223,7 +223,7 @@ static void get_config_path(wxPathList& path, bool exists = true) #if defined(__WXGTK__) // XDG spec manual support // ${XDG_CONFIG_HOME:-$HOME/.config}/`appname` - wxString old_config = wxString(getenv("HOME"), wxConvLibc) + wxT(FILE_SEP) + wxT(".vbam"); + wxString old_config = wxString(getenv("HOME"), wxConvLibc) + kFileSep + ".vbam"; wxString new_config(get_xdg_user_config_home().c_str(), wxConvLibc); if (!wxDirExists(old_config) && wxIsWritable(new_config)) { diff --git a/src/wx/wxvbam.h b/src/wx/wxvbam.h index dfee5521..c66d392f 100644 --- a/src/wx/wxvbam.h +++ b/src/wx/wxvbam.h @@ -24,7 +24,7 @@ #endif #ifndef NO_FFMPEG -#include "../common/ffmpeg.h" +#include "components/av_recording/av_recording.h" #endif #include "wxlogdebug.h" @@ -797,6 +797,4 @@ extern int autofire, autohold; #define KEYM_MOTION_IN (1 << 19) #define KEYM_MOTION_OUT (1 << 20) -#include "filters.h" - #endif /* WX_WXVBAM_H */ diff --git a/third_party/include/nonstd/CMakeLists.txt b/third_party/include/nonstd/CMakeLists.txt new file mode 100644 index 00000000..de3c5083 --- /dev/null +++ b/third_party/include/nonstd/CMakeLists.txt @@ -0,0 +1,25 @@ +# Defines the `NONSTD_INCLUDE_DIR` variable and `nonstd-lib` target. + +# nonstd library dependency (header-only). +set(NONSTD_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR} PARENT_SCOPE) +add_library(nonstd-lib INTERFACE) +target_sources(nonstd-lib + INTERFACE + optional.hpp + variant.hpp +) +# For C++, default to nonstd::optional and nonstd::variant for now due to mac +# build issues. +if(APPLE) + target_compile_definitions(nonstd-lib + INTERFACE + optional_CONFIG_SELECT_OPTIONAL=optional_OPTIONAL_NONSTD + variant_CONFIG_SELECT_VARIANT=variant_VARIANT_NONSTD + ) +else() + target_compile_definitions(nonstd-lib + INTERFACE + optional_CONFIG_SELECT_OPTIONAL=optional_OPTIONAL_STD + variant_CONFIG_SELECT_VARIANT=variant_VARIANT_STD + ) +endif() \ No newline at end of file