diff --git a/.gitignore b/.gitignore index 2241cd0aa..37cb57e2d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.user* *~ *.swp +*.pyc diff --git a/CHANGES b/CHANGES index c574e396b..9349ce4c5 100644 --- a/CHANGES +++ b/CHANGES @@ -7,43 +7,12 @@ Features: - Debugging console - Improved memory viewer Bugfixes: - - Libretro: Fix unterminated SET_INPUT_DESCRIPTORS - LR35902: Fix core never exiting with certain event patterns - GB Timer: Improve DIV reset behavior - - GBA Memory: Fix misaligned BIOS reads - - GBA BIOS: Fix MidiKey2Freq BIOS reads - - GBA BIOS: Fix invalid CpuSet not setting BIOS prefetch - - GB MBC: Fix SRAM dangling pointer with RTC games - - Windows: Fix Unicode directory handling - - Qt: Fix changing resolution of software renderer - - Qt: Fix setting overrides - - GBA Cheats: Fix GameShark ROM patches - - Qt: Fix cut off tiles and alignment issues in tile viewer - - GB MBC: Fix initializing MBC when no ROM is loaded - - VFS: Fix resizing memory chunks when not needed - - GB Memory: Fix patching ROM bank 0 - - GB: Fix audio not being deinitialized - - GBA Memory: Fix VCOUNT being writable - GBA Memory: Improve initial skipped BIOS state - - Qt: Only reset window dimensions when first shown - - GB Memory: Fix starting HDMAs during mode 0 - - Qt: Fix Qt Multimedia audio driver on big endian - - GBA: Fix IRQs firing after already being cleared - - All: Fix fullscreen config option being ignored - GBA BIOS: Implement BitUnPack - - GBA: Add savegame override for Crash Bandicoot 2 - - ARM7: PSR mode bits should not get sign extended - - GBA: Only unhalt CPU if appropriate bit is set in IE - - GBA Video: Fix out of bounds sprite transforms - - GB: Fix crash when masking savedata - - GB Audio: Fix serialization of channel 3 and NR52 properties - - GB: Properly initialize sramRealVf variable - - Qt: Fix Apply button for key and controller configurations - - GB Video: Initialize LCDC in renderer - - GBA I/O: Mask off WAITCNT bits that cannot be written - - GB Memory: Fix HDMA5 value after DMA completes - - GB Video: Hblank IRQs should mask LYC=LY IRQs - - GB Audio: Reset envelope timer when reseting sound channel + - ARM7: Fix MLA/*MULL/*MLAL timing + - GBA: Fix multiboot ROM loading - SDL: Prevent crash on cores with no audio - ARM7: Decode MCR/MRC - ARM7: Clean up instruction decoding for future expandability @@ -54,8 +23,6 @@ Misc: - GBA Video: Allow multiple handles into the same tile cache - VFS: Call msync when syncing mapped data - GBA Video, GB Video: Colors are now fully scaled - - PSP2: Improved controller rumble - - GB, GBA: Prevent loading null ROMs - VFS: Allow truncating memory chunk VFiles - Debugger: Modularize CLI debugger - Core: Clean up some thread state checks @@ -67,11 +34,55 @@ Misc: - 3DS, PSP2, Wii: Last directory loaded is saved - GB Audio: Simplify envelope code - GB Audio: Improve initial envelope samples - - GB Audio: Initialize wave RAM to GBC values - Debugger: Add functions for read- or write-only watchpoints - - GB Memory: Reset ROM bank when loading a ROM - GBA DMA: Refactor DMA out of memory.c - GBA DMA: Move DMAs to using absolute timing + - All: Add C++ header guards + - GBA I/O: Clear JOYSTAT RECV flag when reading JOY_RECV registers + - GBA I/O: Set JOYSTAT TRANS flag when writing JOY_TRANS registers + +0.5.2: (2016-12-31) +Bugfixes: + - All: Fix fullscreen config option being ignored + - ARM7: PSR mode bits should not get sign extended + - GB: Fix audio not being deinitialized + - GB: Fix crash when masking savedata + - GB: Properly initialize sramRealVf variable + - GB Audio: Fix serialization of channel 3 and NR52 properties + - GB Audio: Reset envelope timer when reseting sound channel + - GB MBC: Fix SRAM dangling pointer with RTC games + - GB MBC: Fix initializing MBC when no ROM is loaded + - GB Memory: Fix patching ROM bank 0 + - GB Memory: Fix starting HDMAs during mode 0 + - GB Memory: Fix HDMA5 value after DMA completes + - GB Video: Initialize LCDC in renderer + - GB Video: Hblank IRQs should mask LYC=LY IRQs + - GBA: Fix IRQs firing after already being cleared + - GBA: Only unhalt CPU if appropriate bit is set in IE + - GBA: Add savegame override for Crash Bandicoot 2 + - GBA BIOS: Fix MidiKey2Freq BIOS reads + - GBA BIOS: Fix invalid CpuSet not setting BIOS prefetch + - GBA Cheats: Fix GameShark ROM patches + - GBA I/O: Mask off WAITCNT bits that cannot be written + - GBA Memory: Fix misaligned BIOS reads + - GBA Memory: Fix VCOUNT being writable + - GBA Video: Fix out of bounds sprite transforms + - Libretro: Fix unterminated SET_INPUT_DESCRIPTORS + - Libretro: Fix disabling BIOS + - Libretro: Fix Game Boy savestates and audio + - Qt: Fix changing resolution of software renderer + - Qt: Fix setting overrides + - Qt: Fix cut off tiles and alignment issues in tile viewer + - Qt: Only reset window dimensions when first shown + - Qt: Fix Qt Multimedia audio driver on big endian + - Qt: Fix Apply button for key and controller configurations + - VFS: Fix resizing memory chunks when not needed + - Windows: Fix Unicode directory handling +Misc: + - GB, GBA: Prevent loading null ROMs + - GB Audio: Initialize wave RAM to GBC values + - GB Memory: Reset ROM bank when loading a ROM + - PSP2: Improved controller rumble 0.5.1: (2016-10-05) Bugfixes: diff --git a/CMakeLists.txt b/CMakeLists.txt index c36a49f33..8de6fa750 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ set(BUILD_PERF OFF CACHE BOOL "Build performance profiling tool") set(BUILD_TEST OFF CACHE BOOL "Build testing harness") set(BUILD_SUITE OFF CACHE BOOL "Build test suite") set(BUILD_EXAMPLE OFF CACHE BOOL "Build example frontends") +set(BUILD_PYTHON OFF CACHE BOOL "Build Python bindings") set(BUILD_STATIC OFF CACHE BOOL "Build a static library") set(BUILD_SHARED ON CACHE BOOL "Build a shared library") set(SKIP_LIBRARY OFF CACHE BOOL "Skip building the library (useful for only building libretro or OpenEmu cores)") @@ -53,7 +54,8 @@ file(GLOB UTIL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/*.[cSs]) file(GLOB UTIL_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/test/*.c) file(GLOB GUI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/gui/*.c ${CMAKE_CURRENT_SOURCE_DIR}/src/feature/gui/*.c) file(GLOB GBA_RENDERER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/renderers/*.c) -file(GLOB SIO_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/sio/lockstep.c) +file(GLOB GBA_SIO_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/sio/lockstep.c) +file(GLOB GB_SIO_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/sio/lockstep.c) file(GLOB GB_RENDERER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/renderers/*.c) file(GLOB THIRD_PARTY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/inih/*.c) set(CLI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/feature/commandline.c) @@ -61,12 +63,12 @@ set(CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-mem.c) set(VFS_SRC) source_group("ARM core" FILES ${ARM_SRC}) source_group("LR35902 core" FILES ${LR35902_SRC}) -source_group("GBA board" FILES ${GBA_SRC} ${GBA_RENDERER_SRC} ${SIO_SRC}) +source_group("GBA board" FILES ${GBA_SRC} ${GBA_RENDERER_SRC} ${GBA_SIO_SRC}) source_group("GBA extra" FILES ${GBA_CHEATS_SRC} ${GBA_RR_SRC}) -source_group("GB board" FILES ${GB_SRC}) +source_group("GB board" FILES ${GB_SRC} ${GB_SIO_SRC}) source_group("DS board" FILES ${DS_SRC}) source_group("Utilities" FILES ${UTIL_SRC}) -include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src) +include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type (e.g. Release or Debug)" FORCE) @@ -153,6 +155,9 @@ add_custom_target(version-info ALL include(${CMAKE_CURRENT_SOURCE_DIR}/version.cmake) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/core/version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/core/flags.h.in ${CMAKE_CURRENT_BINARY_DIR}/flags.h) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/flags.h DESTINATION include/mgba COMPONENT lib${BINARY_NAME}) + list(APPEND UTIL_SRC ${CMAKE_CURRENT_BINARY_DIR}/version.c) source_group("Generated sources" FILES ${CMAKE_CURRENT_BINARY_DIR}/version.c) @@ -643,7 +648,11 @@ if(NOT MINIMAL_CORE) list(APPEND SRC ${GBA_RR_SRC} ${GBA_EXTRA_SRC} - ${SIO_SRC}) + ${GBA_SIO_SRC}) + endif() + if(M_CORE_GB) + list(APPEND SRC + ${GB_SIO_SRC}) endif() list(APPEND SRC ${FEATURE_SRC} @@ -777,6 +786,11 @@ if(BUILD_SUITE) add_test(${BINARY_NAME}-suite ${BINARY_NAME}-suite) endif() +if(BUILD_PYTHON) + enable_testing() + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/python ${CMAKE_CURRENT_BINARY_DIR}/python) +endif() + if(BUILD_EXAMPLE) add_executable(${BINARY_NAME}-example-server ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/server.c) target_link_libraries(${BINARY_NAME}-example-server ${BINARY_NAME}) @@ -787,7 +801,7 @@ if(BUILD_EXAMPLE) target_link_libraries(${BINARY_NAME}-example-client ${BINARY_NAME} ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY}) set_target_properties(${BINARY_NAME}-example-client PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}" - INCLUDE_DIRECTORIES "${SDL_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/src") + INCLUDE_DIRECTORIES "${SDL_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/src;${CMAKE_CURRENT_SOURCE_DIR}/include") endif() endif() @@ -861,6 +875,7 @@ if(NOT QUIET) message(STATUS " Profiling: ${BUILD_PERF}") message(STATUS " Test harness: ${BUILD_TEST}") message(STATUS " Test suite: ${BUILD_SUITE}") + message(STATUS " Python bindings: ${BUILD_PYTHON}") message(STATUS " Examples: ${BUILD_EXAMPLE}") message(STATUS "Cores:") message(STATUS " Libretro core: ${BUILD_LIBRETRO}") diff --git a/src/util/arm-algo.h b/include/mgba-util/arm-algo.h similarity index 100% rename from src/util/arm-algo.h rename to include/mgba-util/arm-algo.h diff --git a/src/util/circle-buffer.h b/include/mgba-util/circle-buffer.h similarity index 95% rename from src/util/circle-buffer.h rename to include/mgba-util/circle-buffer.h index 77650ca84..28d436e03 100644 --- a/src/util/circle-buffer.h +++ b/include/mgba-util/circle-buffer.h @@ -6,7 +6,9 @@ #ifndef CIRCLE_BUFFER_H #define CIRCLE_BUFFER_H -#include "util/common.h" +#include + +CXX_GUARD_START struct CircleBuffer { void* data; @@ -30,4 +32,6 @@ int CircleBufferRead32(struct CircleBuffer* buffer, int32_t* value); size_t CircleBufferRead(struct CircleBuffer* buffer, void* output, size_t length); size_t CircleBufferDump(const struct CircleBuffer* buffer, void* output, size_t length); +CXX_GUARD_END + #endif diff --git a/src/util/common.h b/include/mgba-util/common.h similarity index 97% rename from src/util/common.h rename to include/mgba-util/common.h index 050db0513..bfe4f3a92 100644 --- a/src/util/common.h +++ b/include/mgba-util/common.h @@ -6,6 +6,16 @@ #ifndef COMMON_H #define COMMON_H +#ifdef __cplusplus +#define CXX_GUARD_START extern "C" { +#define CXX_GUARD_END } +#else +#define CXX_GUARD_START +#define CXX_GUARD_END +#endif + +CXX_GUARD_START + #include #include #include @@ -46,7 +56,9 @@ typedef intptr_t ssize_t; #define SSIZE_MAX ((ssize_t) (SIZE_MAX >> 1)) #endif +#ifndef UNUSED #define UNUSED(V) (void)(V) +#endif #ifndef M_PI #define M_PI 3.141592654f @@ -177,4 +189,6 @@ typedef intptr_t ssize_t; #define ROR(I, ROTATE) ((((uint32_t) (I)) >> ROTATE) | ((uint32_t) (I) << ((-ROTATE) & 31))) +CXX_GUARD_END + #endif diff --git a/src/util/configuration.h b/include/mgba-util/configuration.h similarity index 94% rename from src/util/configuration.h rename to include/mgba-util/configuration.h index 5d16324dd..e2e6ba7d3 100644 --- a/src/util/configuration.h +++ b/include/mgba-util/configuration.h @@ -6,7 +6,11 @@ #ifndef CONFIGURATION_H #define CONFIGURATION_H -#include "util/table.h" +#include + +CXX_GUARD_START + +#include struct VFile; @@ -35,4 +39,6 @@ bool ConfigurationWriteSection(const struct Configuration*, const char* path, co void ConfigurationEnumerateSections(const struct Configuration* configuration, void (*handler)(const char* sectionName, void* user), void* user); +CXX_GUARD_END + #endif diff --git a/src/util/crc32.h b/include/mgba-util/crc32.h similarity index 88% rename from src/util/crc32.h rename to include/mgba-util/crc32.h index 5e34b3feb..225998bb9 100644 --- a/src/util/crc32.h +++ b/include/mgba-util/crc32.h @@ -6,7 +6,9 @@ #ifndef CRC32_H #define CRC32_H -#include "util/common.h" +#include + +CXX_GUARD_START struct VFile; @@ -14,4 +16,6 @@ uint32_t doCrc32(const void* buf, size_t size); uint32_t updateCrc32(uint32_t crc, const void* buf, size_t size); uint32_t fileCrc32(struct VFile* file, size_t endOffset); +CXX_GUARD_END + #endif diff --git a/src/util/export.h b/include/mgba-util/export.h similarity index 88% rename from src/util/export.h rename to include/mgba-util/export.h index 3e933620c..92047b93b 100644 --- a/src/util/export.h +++ b/include/mgba-util/export.h @@ -6,11 +6,15 @@ #ifndef EXPORT_H #define EXPORT_H -#include "util/common.h" +#include + +CXX_GUARD_START struct VFile; bool exportPaletteRIFF(struct VFile* vf, size_t entries, const uint16_t* colors); bool exportPaletteACT(struct VFile* vf, size_t entries, const uint16_t* colors); +CXX_GUARD_END + #endif diff --git a/src/util/formatting.h b/include/mgba-util/formatting.h similarity index 93% rename from src/util/formatting.h rename to include/mgba-util/formatting.h index b09c12944..4395879aa 100644 --- a/src/util/formatting.h +++ b/include/mgba-util/formatting.h @@ -6,7 +6,9 @@ #ifndef FORMATTING_H #define FORMATTING_H -#include "util/common.h" +#include + +CXX_GUARD_START #include "locale.h" @@ -29,4 +31,6 @@ float strtof_u(const char* restrict str, char** restrict end); struct tm* localtime_r(const time_t* timep, struct tm* result); #endif +CXX_GUARD_END + #endif diff --git a/src/util/gui.h b/include/mgba-util/gui.h similarity index 91% rename from src/util/gui.h rename to include/mgba-util/gui.h index fe7d851a0..183fcfa80 100644 --- a/src/util/gui.h +++ b/include/mgba-util/gui.h @@ -6,10 +6,13 @@ #ifndef GUI_H #define GUI_H -#include "util/common.h" +#include -#include "core/input.h" -#include "util/vector.h" +CXX_GUARD_START + +// TODO: Fix layering violation +#include +#include struct GUIFont; @@ -81,4 +84,6 @@ void GUIPollInput(struct GUIParams* params, uint32_t* newInput, uint32_t* heldIn enum GUICursorState GUIPollCursor(struct GUIParams* params, unsigned* x, unsigned* y); void GUIInvalidateKeys(struct GUIParams* params); +CXX_GUARD_END + #endif diff --git a/src/util/gui/file-select.h b/include/mgba-util/gui/file-select.h similarity index 82% rename from src/util/gui/file-select.h rename to include/mgba-util/gui/file-select.h index e804d66a7..1d27673a2 100644 --- a/src/util/gui/file-select.h +++ b/include/mgba-util/gui/file-select.h @@ -6,10 +6,16 @@ #ifndef GUI_FILE_CHOOSER_H #define GUI_FILE_CHOOSER_H -#include "util/gui.h" +#include + +CXX_GUARD_START + +#include struct VFile; bool GUISelectFile(struct GUIParams*, char* outPath, size_t outLen, bool (*filter)(struct VFile*)); +CXX_GUARD_END + #endif diff --git a/src/util/gui/font-metrics.h b/include/mgba-util/gui/font-metrics.h similarity index 92% rename from src/util/gui/font-metrics.h rename to include/mgba-util/gui/font-metrics.h index 8cb3ffeb4..c60d6dfc8 100644 --- a/src/util/gui/font-metrics.h +++ b/include/mgba-util/gui/font-metrics.h @@ -6,7 +6,7 @@ #ifndef DEFAULT_FONT_METRICS_H #define DEFAULT_FONT_METRICS_H -#include "util/gui/font.h" +#include extern struct GUIFontGlyphMetric defaultFontMetrics[]; extern struct GUIIconMetric defaultIconMetrics[]; diff --git a/src/util/gui/font.h b/include/mgba-util/gui/font.h similarity index 97% rename from src/util/gui/font.h rename to include/mgba-util/gui/font.h index 7c936ffb9..3ace00071 100644 --- a/src/util/gui/font.h +++ b/include/mgba-util/gui/font.h @@ -6,7 +6,9 @@ #ifndef GUI_FONT_H #define GUI_FONT_H -#include "util/common.h" +#include + +CXX_GUARD_START struct GUIFont; struct GUIFont* GUIFontCreate(void); @@ -84,4 +86,6 @@ void GUIFontDrawGlyph(const struct GUIFont*, int x, int y, uint32_t color, uint3 void GUIFontDrawIcon(const struct GUIFont*, int x, int y, enum GUIAlignment, enum GUIOrientation, uint32_t color, enum GUIIcon); void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon); +CXX_GUARD_END + #endif diff --git a/src/util/gui/menu.h b/include/mgba-util/gui/menu.h similarity index 93% rename from src/util/gui/menu.h rename to include/mgba-util/gui/menu.h index eb34d99cd..72a099a15 100644 --- a/src/util/gui/menu.h +++ b/include/mgba-util/gui/menu.h @@ -6,7 +6,11 @@ #ifndef GUI_MENU_H #define GUI_MENU_H -#include "util/vector.h" +#include + +CXX_GUARD_START + +#include struct GUIMenu; struct GUIMenuItem { @@ -49,4 +53,6 @@ enum GUIMenuExitReason GUIShowMessageBox(struct GUIParams* params, int buttons, void GUIDrawBattery(struct GUIParams* params); void GUIDrawClock(struct GUIParams* params); +CXX_GUARD_END + #endif diff --git a/src/util/hash.h b/include/mgba-util/hash.h similarity index 84% rename from src/util/hash.h rename to include/mgba-util/hash.h index 7a8e82099..7376ba425 100644 --- a/src/util/hash.h +++ b/include/mgba-util/hash.h @@ -6,8 +6,12 @@ #ifndef HASH_H #define HASH_H -#include "util/common.h" +#include + +CXX_GUARD_START uint32_t hash32(const void* key, int len, uint32_t seed); +CXX_GUARD_END + #endif diff --git a/src/util/math.h b/include/mgba-util/math.h similarity index 96% rename from src/util/math.h rename to include/mgba-util/math.h index 654d44517..3c27bba69 100644 --- a/src/util/math.h +++ b/include/mgba-util/math.h @@ -6,7 +6,9 @@ #ifndef UTIL_MATH_H #define UTIL_MATH_H -#include "util/common.h" +#include + +CXX_GUARD_START static inline uint32_t popcount32(unsigned bits) { bits = bits - ((bits >> 1) & 0x55555555); @@ -59,4 +61,6 @@ static inline uint32_t toPow2(uint32_t bits) { return 1 << (32 - lz); } +CXX_GUARD_END + #endif diff --git a/src/util/memory.h b/include/mgba-util/memory.h similarity index 86% rename from src/util/memory.h rename to include/mgba-util/memory.h index e78d87c7a..325f748f6 100644 --- a/src/util/memory.h +++ b/include/mgba-util/memory.h @@ -6,9 +6,13 @@ #ifndef MEMORY_H #define MEMORY_H -#include "util/common.h" +#include + +CXX_GUARD_START void* anonymousMemoryMap(size_t size); void mappedMemoryFree(void* memory, size_t size); +CXX_GUARD_END + #endif diff --git a/src/util/nointro.h b/include/mgba-util/nointro.h similarity index 91% rename from src/util/nointro.h rename to include/mgba-util/nointro.h index 50f4a23d2..6c8a3e6b5 100644 --- a/src/util/nointro.h +++ b/include/mgba-util/nointro.h @@ -6,7 +6,9 @@ #ifndef NOINTRO_H #define NOINTRO_H -#include "util/common.h" +#include + +CXX_GUARD_START struct NoIntroGame { const char* name; @@ -26,4 +28,6 @@ struct NoIntroDB* NoIntroDBLoad(struct VFile* vf); void NoIntroDBDestroy(struct NoIntroDB* db); bool NoIntroDBLookupGameByCRC(const struct NoIntroDB* db, uint32_t crc32, struct NoIntroGame* game); +CXX_GUARD_END + #endif diff --git a/src/util/patch.h b/include/mgba-util/patch.h similarity index 90% rename from src/util/patch.h rename to include/mgba-util/patch.h index f84d859df..7bf81dc93 100644 --- a/src/util/patch.h +++ b/include/mgba-util/patch.h @@ -6,7 +6,9 @@ #ifndef PATCH_H #define PATCH_H -#include "util/common.h" +#include + +CXX_GUARD_START struct VFile; @@ -19,4 +21,6 @@ struct Patch { bool loadPatch(struct VFile* vf, struct Patch* patch); +CXX_GUARD_END + #endif diff --git a/src/util/patch-fast.h b/include/mgba-util/patch/fast.h similarity index 86% rename from src/util/patch-fast.h rename to include/mgba-util/patch/fast.h index 34988160c..6657a0419 100644 --- a/src/util/patch-fast.h +++ b/include/mgba-util/patch/fast.h @@ -6,10 +6,12 @@ #ifndef PATCH_FAST_H #define PATCH_FAST_H -#include "util/common.h" +#include -#include "util/patch.h" -#include "util/vector.h" +CXX_GUARD_START + +#include +#include #define PATCH_FAST_EXTENT 256 @@ -31,4 +33,6 @@ void initPatchFast(struct PatchFast*); void deinitPatchFast(struct PatchFast*); bool diffPatchFast(struct PatchFast* patch, const void* restrict in, const void* restrict out, size_t size); +CXX_GUARD_END + #endif diff --git a/src/util/patch-ips.h b/include/mgba-util/patch/ips.h similarity index 85% rename from src/util/patch-ips.h rename to include/mgba-util/patch/ips.h index 39c8f6e65..2047d21e7 100644 --- a/src/util/patch-ips.h +++ b/include/mgba-util/patch/ips.h @@ -6,10 +6,14 @@ #ifndef PATCH_IPS_H #define PATCH_IPS_H -#include "util/common.h" +#include + +CXX_GUARD_START struct Patch; bool loadPatchIPS(struct Patch* patch); +CXX_GUARD_END + #endif diff --git a/src/util/patch-ups.h b/include/mgba-util/patch/ups.h similarity index 85% rename from src/util/patch-ups.h rename to include/mgba-util/patch/ups.h index 23293409b..2e53cda45 100644 --- a/src/util/patch-ups.h +++ b/include/mgba-util/patch/ups.h @@ -6,10 +6,14 @@ #ifndef PATCH_UPS_H #define PATCH_UPS_H -#include "util/common.h" +#include + +CXX_GUARD_START struct Patch; bool loadPatchUPS(struct Patch* patch); +CXX_GUARD_END + #endif diff --git a/src/platform/3ds/3ds-vfs.h b/include/mgba-util/platform/3ds/3ds-vfs.h similarity index 94% rename from src/platform/3ds/3ds-vfs.h rename to include/mgba-util/platform/3ds/3ds-vfs.h index 35c6dfbe7..71344b76e 100644 --- a/src/platform/3ds/3ds-vfs.h +++ b/include/mgba-util/platform/3ds/3ds-vfs.h @@ -6,7 +6,7 @@ #ifndef N3DS_VFS_H #define N3DS_VFS_H -#include "util/vfs.h" +#include #include <3ds.h> diff --git a/src/platform/3ds/threading.h b/include/mgba-util/platform/3ds/threading.h similarity index 98% rename from src/platform/3ds/threading.h rename to include/mgba-util/platform/3ds/threading.h index 69d48c6cb..0eda3dd43 100644 --- a/src/platform/3ds/threading.h +++ b/include/mgba-util/platform/3ds/threading.h @@ -6,7 +6,7 @@ #ifndef N3DS_THREADING_H #define N3DS_THREADING_H -#include "util/common.h" +#include #include <3ds.h> #include diff --git a/src/platform/posix/threading.h b/include/mgba-util/platform/posix/threading.h similarity index 97% rename from src/platform/posix/threading.h rename to include/mgba-util/platform/posix/threading.h index e13240f3e..b880c548d 100644 --- a/src/platform/posix/threading.h +++ b/include/mgba-util/platform/posix/threading.h @@ -6,7 +6,9 @@ #ifndef POSIX_THREADING_H #define POSIX_THREADING_H -#include "util/common.h" +#include + +CXX_GUARD_START #include #include @@ -94,4 +96,6 @@ static inline int ThreadSetName(const char* name) { #endif } +CXX_GUARD_END + #endif diff --git a/src/platform/psp2/sce-vfs.h b/include/mgba-util/platform/psp2/sce-vfs.h similarity index 100% rename from src/platform/psp2/sce-vfs.h rename to include/mgba-util/platform/psp2/sce-vfs.h diff --git a/src/platform/psp2/threading.h b/include/mgba-util/platform/psp2/threading.h similarity index 100% rename from src/platform/psp2/threading.h rename to include/mgba-util/platform/psp2/threading.h diff --git a/src/platform/windows/getopt.h b/include/mgba-util/platform/windows/getopt.h similarity index 100% rename from src/platform/windows/getopt.h rename to include/mgba-util/platform/windows/getopt.h diff --git a/src/platform/windows/threading.h b/include/mgba-util/platform/windows/threading.h similarity index 98% rename from src/platform/windows/threading.h rename to include/mgba-util/platform/windows/threading.h index efcf3a091..33af88b58 100644 --- a/src/platform/windows/threading.h +++ b/include/mgba-util/platform/windows/threading.h @@ -6,7 +6,7 @@ #ifndef WINDOWS_THREADING_H #define WINDOWS_THREADING_H -#include "util/common.h" +#include #define _WIN32_WINNT 0x0600 #include diff --git a/src/util/png-io.h b/include/mgba-util/png-io.h similarity index 95% rename from src/util/png-io.h rename to include/mgba-util/png-io.h index d0fff9c70..1f8fea331 100644 --- a/src/util/png-io.h +++ b/include/mgba-util/png-io.h @@ -6,7 +6,9 @@ #ifndef PNG_IO_H #define PNG_IO_H -#include "util/common.h" +#include + +CXX_GUARD_START #ifdef USE_PNG @@ -37,4 +39,6 @@ void PNGReadClose(png_structp png, png_infop info, png_infop end); #endif +CXX_GUARD_END + #endif diff --git a/src/util/ring-fifo.h b/include/mgba-util/ring-fifo.h similarity index 92% rename from src/util/ring-fifo.h rename to include/mgba-util/ring-fifo.h index 6ceb02ff7..c5b1fdcc5 100644 --- a/src/util/ring-fifo.h +++ b/include/mgba-util/ring-fifo.h @@ -6,7 +6,9 @@ #ifndef RING_FIFO_H #define RING_FIFO_H -#include "util/common.h" +#include + +CXX_GUARD_START struct RingFIFO { void* data; @@ -22,4 +24,6 @@ void RingFIFOClear(struct RingFIFO* buffer); size_t RingFIFOWrite(struct RingFIFO* buffer, const void* value, size_t length); size_t RingFIFORead(struct RingFIFO* buffer, void* output, size_t length); +CXX_GUARD_END + #endif diff --git a/src/util/socket.h b/include/mgba-util/socket.h similarity index 99% rename from src/util/socket.h rename to include/mgba-util/socket.h index 6ffe13608..327c2c69c 100644 --- a/src/util/socket.h +++ b/include/mgba-util/socket.h @@ -6,7 +6,9 @@ #ifndef SOCKET_H #define SOCKET_H -#include "util/common.h" +#include + +CXX_GUARD_START #if defined(__cplusplus) && !defined(restrict) #define restrict __restrict__ @@ -316,4 +318,6 @@ static inline int SocketPoll(size_t nSockets, Socket* reads, Socket* writes, Soc return result; } +CXX_GUARD_END + #endif diff --git a/src/util/string.h b/include/mgba-util/string.h similarity index 95% rename from src/util/string.h rename to include/mgba-util/string.h index 4bf161f8a..831ce8e44 100644 --- a/src/util/string.h +++ b/include/mgba-util/string.h @@ -6,7 +6,9 @@ #ifndef UTIL_STRING_H #define UTIL_STRING_H -#include "util/common.h" +#include + +CXX_GUARD_START #ifndef HAVE_STRNDUP // This is sometimes a macro @@ -36,4 +38,6 @@ const char* hex4(const char* line, uint8_t* out); void rtrim(char* string); +CXX_GUARD_END + #endif diff --git a/src/util/table.h b/include/mgba-util/table.h similarity index 82% rename from src/util/table.h rename to include/mgba-util/table.h index 5dee643fd..a03fb3734 100644 --- a/src/util/table.h +++ b/include/mgba-util/table.h @@ -6,7 +6,9 @@ #ifndef TABLE_H #define TABLE_H -#include "util/common.h" +#include + +CXX_GUARD_START struct TableList; @@ -29,13 +31,8 @@ void TableClear(struct Table*); void TableEnumerate(const struct Table*, void (handler(uint32_t key, void* value, void* user)), void* user); size_t TableSize(const struct Table*); -static inline void HashTableInit(struct Table* table, size_t initialSize, void (deinitializer(void*))) { - TableInit(table, initialSize, deinitializer); -} - -static inline void HashTableDeinit(struct Table* table) { - TableDeinit(table); -} +void HashTableInit(struct Table* table, size_t initialSize, void (deinitializer(void*))); +void HashTableDeinit(struct Table* table); void* HashTableLookup(const struct Table*, const char* key); void HashTableInsert(struct Table*, const char* key, void* value); @@ -46,4 +43,6 @@ void HashTableClear(struct Table*); void HashTableEnumerate(const struct Table*, void (handler(const char* key, void* value, void* user)), void* user); size_t HashTableSize(const struct Table*); +CXX_GUARD_END + #endif diff --git a/src/util/text-codec.h b/include/mgba-util/text-codec.h similarity index 94% rename from src/util/text-codec.h rename to include/mgba-util/text-codec.h index e17436c7b..284705a19 100644 --- a/src/util/text-codec.h +++ b/include/mgba-util/text-codec.h @@ -6,7 +6,9 @@ #ifndef TEXT_CODEC_H #define TEXT_CODEC_H -#include "util/common.h" +#include + +CXX_GUARD_START struct TextCodecNode; struct TextCodec { @@ -29,4 +31,6 @@ void TextCodecStartEncode(struct TextCodec*, struct TextCodecIterator*); ssize_t TextCodecAdvance(struct TextCodecIterator*, uint8_t byte, uint8_t* output, size_t outputLength); ssize_t TextCodecFinish(struct TextCodecIterator*, uint8_t* output, size_t outputLength); +CXX_GUARD_END + #endif diff --git a/src/util/threading.h b/include/mgba-util/threading.h similarity index 85% rename from src/util/threading.h rename to include/mgba-util/threading.h index 32d805c67..d59ebcc5a 100644 --- a/src/util/threading.h +++ b/include/mgba-util/threading.h @@ -6,17 +6,19 @@ #ifndef THREADING_H #define THREADING_H -#include "util/common.h" +#include + +CXX_GUARD_START #ifndef DISABLE_THREADING #ifdef USE_PTHREADS -#include "platform/posix/threading.h" +#include #elif _WIN32 -#include "platform/windows/threading.h" +#include #elif PSP2 -#include "platform/psp2/threading.h" +#include #elif _3DS -#include "platform/3ds/threading.h" +#include #else #define DISABLE_THREADING #endif @@ -85,4 +87,6 @@ static inline int ConditionWake(Condition* cond) { } #endif +CXX_GUARD_END + #endif diff --git a/src/util/vector.h b/include/mgba-util/vector.h similarity index 98% rename from src/util/vector.h rename to include/mgba-util/vector.h index dee7ed77a..0839d61b2 100644 --- a/src/util/vector.h +++ b/include/mgba-util/vector.h @@ -6,7 +6,9 @@ #ifndef VECTOR_H #define VECTOR_H -#include "util/common.h" +#include + +CXX_GUARD_START #define DECLARE_VECTOR(NAME, TYPE) \ struct NAME { \ @@ -84,4 +86,6 @@ return member - (const TYPE*) vector->vector; \ } \ +CXX_GUARD_END + #endif diff --git a/src/util/vfs.h b/include/mgba-util/vfs.h similarity index 96% rename from src/util/vfs.h rename to include/mgba-util/vfs.h index 19c71da92..abe723d98 100644 --- a/src/util/vfs.h +++ b/include/mgba-util/vfs.h @@ -6,7 +6,9 @@ #ifndef VFS_H #define VFS_H -#include "util/common.h" +#include + +CXX_GUARD_START #ifdef _WIN32 #include @@ -65,12 +67,11 @@ struct VDir { struct VFile* VFileOpen(const char* path, int flags); struct VFile* VFileOpenFD(const char* path, int flags); -struct VFile* VFileFOpen(const char* path, const char* mode); struct VFile* VFileFromFD(int fd); + struct VFile* VFileFromMemory(void* mem, size_t size); struct VFile* VFileFromConstMemory(const void* mem, size_t size); struct VFile* VFileMemChunk(const void* mem, size_t size); -struct VFile* VFileFromFILE(FILE* file); struct VDir* VDirOpen(const char* path); struct VDir* VDirOpenArchive(const char* path); @@ -83,7 +84,11 @@ struct VDir* VDirOpenZip(const char* path, int flags); struct VDir* VDirOpen7z(const char* path, int flags); #endif +#if defined(__wii__) || defined(_3DS) +struct VFile* VFileFOpen(const char* path, const char* mode); +struct VFile* VFileFromFILE(FILE* file); struct VDir* VDeviceList(void); +#endif void separatePath(const char* path, char* dirname, char* basename, char* extension); @@ -97,4 +102,6 @@ ssize_t VFileWrite16LE(struct VFile* vf, int16_t hword); ssize_t VFileRead32LE(struct VFile* vf, void* word); ssize_t VFileRead16LE(struct VFile* vf, void* hword); +CXX_GUARD_END + #endif diff --git a/src/third-party/blip_buf/blip_buf.h b/include/mgba/core/blip_buf.h similarity index 98% rename from src/third-party/blip_buf/blip_buf.h rename to include/mgba/core/blip_buf.h index 52703643c..22b0a3ec8 100644 --- a/src/third-party/blip_buf/blip_buf.h +++ b/include/mgba/core/blip_buf.h @@ -24,7 +24,7 @@ void blip_set_rates( blip_t*, double clock_rate, double sample_rate ); enum { /** Maximum clock_rate/sample_rate ratio. For a given sample_rate, clock_rate must not be greater than sample_rate*blip_max_ratio. */ -blip_max_ratio = 1 << 20 }; +blip_max_ratio = 0x100000 }; /** Clears entire buffer. Afterwards, blip_samples_avail() == 0. */ void blip_clear( blip_t* ); diff --git a/src/core/cheats.h b/include/mgba/core/cheats.h similarity index 94% rename from src/core/cheats.h rename to include/mgba/core/cheats.h index 1cc3dedc6..7960ae58b 100644 --- a/src/core/cheats.h +++ b/include/mgba/core/cheats.h @@ -6,11 +6,13 @@ #ifndef CHEATS_H #define CHEATS_H -#include "util/common.h" +#include -#include "core/cpu.h" -#include "core/log.h" -#include "util/vector.h" +CXX_GUARD_START + +#include +#include +#include #define MAX_ROM_PATCHES 4 @@ -100,4 +102,6 @@ bool mCheatSaveFile(struct mCheatDevice*, struct VFile*); void mCheatRefresh(struct mCheatDevice*, struct mCheatSet*); +CXX_GUARD_END + #endif diff --git a/src/core/config.h b/include/mgba/core/config.h similarity index 97% rename from src/core/config.h rename to include/mgba/core/config.h index 806fadde3..6fe37ce6d 100644 --- a/src/core/config.h +++ b/include/mgba/core/config.h @@ -6,9 +6,11 @@ #ifndef M_CORE_CONFIG_H #define M_CORE_CONFIG_H -#include "util/common.h" +#include -#include "util/configuration.h" +CXX_GUARD_START + +#include struct mCoreConfig { struct Configuration configTable; @@ -91,4 +93,6 @@ const struct Configuration* mCoreConfigGetOverridesConst(const struct mCoreConfi void mCoreConfigFreeOpts(struct mCoreOptions* opts); +CXX_GUARD_END + #endif diff --git a/src/core/core.h b/include/mgba/core/core.h similarity index 95% rename from src/core/core.h rename to include/mgba/core/core.h index c9b078f26..c9970fd54 100644 --- a/src/core/core.h +++ b/include/mgba/core/core.h @@ -6,18 +6,21 @@ #ifndef M_CORE_H #define M_CORE_H -#include "util/common.h" +#include -#include "core/config.h" +CXX_GUARD_START + +#include #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 -#include "core/directories.h" +#include #endif #ifndef MINIMAL_CORE -#include "core/input.h" +#include #endif -#include "core/interface.h" +#include #ifdef USE_DEBUGGERS -#include "debugger/debugger.h" +// TODO: Fix layering violation +#include #endif enum mPlatform { @@ -162,4 +165,6 @@ void mCoreInitConfig(struct mCore* core, const char* port); void mCoreLoadConfig(struct mCore* core); void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config); +CXX_GUARD_END + #endif diff --git a/src/core/cpu.h b/include/mgba/core/cpu.h similarity index 89% rename from src/core/cpu.h rename to include/mgba/core/cpu.h index e55f5a19f..fe6caedd3 100644 --- a/src/core/cpu.h +++ b/include/mgba/core/cpu.h @@ -6,7 +6,9 @@ #ifndef M_CPU_H #define M_CPU_H -#include "util/common.h" +#include + +CXX_GUARD_START enum mCPUComponentType { CPU_COMPONENT_DEBUGGER, @@ -20,4 +22,6 @@ struct mCPUComponent { void (*deinit)(struct mCPUComponent* component); }; +CXX_GUARD_END + #endif diff --git a/src/core/directories.h b/include/mgba/core/directories.h similarity index 94% rename from src/core/directories.h rename to include/mgba/core/directories.h index 55f3df513..8715c1025 100644 --- a/src/core/directories.h +++ b/include/mgba/core/directories.h @@ -6,7 +6,9 @@ #ifndef DIRECTORIES_H #define DIRECTORIES_H -#include "util/common.h" +#include + +CXX_GUARD_START #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 struct VDir; @@ -34,4 +36,6 @@ struct mCoreOptions; void mDirectorySetMapOptions(struct mDirectorySet* dirs, const struct mCoreOptions* opts); #endif +CXX_GUARD_END + #endif diff --git a/src/core/input.h b/include/mgba/core/input.h similarity index 97% rename from src/core/input.h rename to include/mgba/core/input.h index 4a7fc5a7b..0d9955981 100644 --- a/src/core/input.h +++ b/include/mgba/core/input.h @@ -6,7 +6,9 @@ #ifndef M_INPUT_H #define M_INPUT_H -#include "util/common.h" +#include + +CXX_GUARD_START struct Configuration; @@ -60,4 +62,6 @@ const char* mInputGetCustomValue(const struct Configuration* config, const char* void mInputSetCustomValue(struct Configuration* config, const char* platformName, uint32_t type, const char* key, const char* value, const char* profile); +CXX_GUARD_END + #endif diff --git a/src/core/interface.h b/include/mgba/core/interface.h similarity index 97% rename from src/core/interface.h rename to include/mgba/core/interface.h index 3d35cb059..2e78390cf 100644 --- a/src/core/interface.h +++ b/include/mgba/core/interface.h @@ -6,7 +6,9 @@ #ifndef CORE_INTERFACE_H #define CORE_INTERFACE_H -#include "util/common.h" +#include + +CXX_GUARD_START struct mCore; @@ -84,4 +86,6 @@ struct mRumble { void (*setRumble)(struct mRumble*, int enable); }; +CXX_GUARD_END + #endif diff --git a/src/core/library.h b/include/mgba/core/library.h similarity index 87% rename from src/core/library.h rename to include/mgba/core/library.h index cb9f2a48c..be5dec001 100644 --- a/src/core/library.h +++ b/include/mgba/core/library.h @@ -6,10 +6,12 @@ #ifndef M_LIBRARY_H #define M_LIBRARY_H -#include "util/common.h" +#include -#include "core/core.h" -#include "util/vector.h" +CXX_GUARD_START + +#include +#include struct mLibraryEntry { char* filename; @@ -34,4 +36,6 @@ struct VFile; void mLibraryLoadDirectory(struct mLibrary* library, struct VDir* dir); void mLibraryAddEntry(struct mLibrary* library, const char* filename, struct VFile* vf); +CXX_GUARD_END + #endif diff --git a/include/mgba/core/lockstep.h b/include/mgba/core/lockstep.h new file mode 100644 index 000000000..06c1bc6b6 --- /dev/null +++ b/include/mgba/core/lockstep.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef SIO_LOCKSTEP_H +#define SIO_LOCKSTEP_H + +#include + +CXX_GUARD_START + +enum mLockstepPhase { + TRANSFER_IDLE = 0, + TRANSFER_STARTING, + TRANSFER_STARTED, + TRANSFER_FINISHING, + TRANSFER_FINISHED +}; + +struct mLockstep { + int attached; + enum mLockstepPhase transferActive; + int32_t transferCycles; + + bool (*signal)(struct mLockstep*, unsigned mask); + bool (*wait)(struct mLockstep*, unsigned mask); + void (*addCycles)(struct mLockstep*, int id, int32_t cycles); + int32_t (*useCycles)(struct mLockstep*, int id, int32_t cycles); + void (*unload)(struct mLockstep*, int id); + void* context; +#ifndef NDEBUG + int transferId; +#endif +}; + +void mLockstepInit(struct mLockstep*); + +CXX_GUARD_END + +#endif diff --git a/src/core/log.h b/include/mgba/core/log.h similarity index 75% rename from src/core/log.h rename to include/mgba/core/log.h index 03fb31ee9..6c8615c93 100644 --- a/src/core/log.h +++ b/include/mgba/core/log.h @@ -6,7 +6,9 @@ #ifndef M_LOG_H #define M_LOG_H -#include "util/common.h" +#include + +CXX_GUARD_START enum mLogLevel { mLOG_FATAL = 0x01, @@ -30,19 +32,7 @@ int mLogGenerateCategory(const char*); const char* mLogCategoryName(int); ATTRIBUTE_FORMAT(printf, 3, 4) -static inline void mLog(int category, enum mLogLevel level, const char* format, ...) { - struct mLogger* context = mLogGetContext(); - va_list args; - va_start(args, format); - if (context) { - context->log(context, category, level, format, args); - } else { - printf("%s: ", mLogCategoryName(category)); - vprintf(format, args); - printf("\n"); - } - va_end(args); -} +void mLog(int category, enum mLogLevel level, const char* format, ...); #define mLOG(CATEGORY, LEVEL, ...) mLog(_mLOG_CAT_ ## CATEGORY (), mLOG_ ## LEVEL, __VA_ARGS__) @@ -58,4 +48,6 @@ static inline void mLog(int category, enum mLogLevel level, const char* format, mLOG_DECLARE_CATEGORY(STATUS) +CXX_GUARD_END + #endif diff --git a/src/core/rewind.h b/include/mgba/core/rewind.h similarity index 89% rename from src/core/rewind.h rename to include/mgba/core/rewind.h index 50844c545..a1a748d3d 100644 --- a/src/core/rewind.h +++ b/include/mgba/core/rewind.h @@ -6,9 +6,11 @@ #ifndef M_CORE_REWIND_H #define M_CORE_REWIND_H -#include "util/common.h" +#include -#include "util/vector.h" +CXX_GUARD_START + +#include DECLARE_VECTOR(mCoreRewindPatches, struct PatchFast); @@ -28,4 +30,6 @@ struct mCore; void mCoreRewindAppend(struct mCoreRewindContext*, struct mCore*); bool mCoreRewindRestore(struct mCoreRewindContext*, struct mCore*); +CXX_GUARD_END + #endif diff --git a/src/core/serialize.h b/include/mgba/core/serialize.h similarity index 95% rename from src/core/serialize.h rename to include/mgba/core/serialize.h index d639aaae4..266cab0ca 100644 --- a/src/core/serialize.h +++ b/include/mgba/core/serialize.h @@ -6,7 +6,9 @@ #ifndef M_SERIALIZE_H #define M_SERIALIZE_H -#include "util/common.h" +#include + +CXX_GUARD_START enum mStateExtdataTag { EXTDATA_NONE = 0, @@ -44,4 +46,6 @@ bool mCoreSaveStateNamed(struct mCore* core, struct VFile* vf, int flags); bool mCoreLoadStateNamed(struct mCore* core, struct VFile* vf, int flags); void* mCoreExtractState(struct mCore* core, struct VFile* vf, struct mStateExtdata* extdata); +CXX_GUARD_END + #endif diff --git a/src/core/sync.h b/include/mgba/core/sync.h similarity index 91% rename from src/core/sync.h rename to include/mgba/core/sync.h index 8932951aa..1ca30335a 100644 --- a/src/core/sync.h +++ b/include/mgba/core/sync.h @@ -6,9 +6,11 @@ #ifndef M_CORE_SYNC_H #define M_CORE_SYNC_H -#include "util/common.h" +#include -#include "util/threading.h" +CXX_GUARD_START + +#include struct mCoreSync { int videoFramePending; @@ -36,4 +38,6 @@ void mCoreSyncLockAudio(struct mCoreSync* sync); void mCoreSyncUnlockAudio(struct mCoreSync* sync); void mCoreSyncConsumeAudio(struct mCoreSync* sync); +CXX_GUARD_END + #endif diff --git a/src/core/thread.h b/include/mgba/core/thread.h similarity index 93% rename from src/core/thread.h rename to include/mgba/core/thread.h index b28569212..b0a60ac80 100644 --- a/src/core/thread.h +++ b/include/mgba/core/thread.h @@ -6,12 +6,14 @@ #ifndef M_CORE_THREAD_H #define M_CORE_THREAD_H -#include "util/common.h" +#include -#include "core/log.h" -#include "core/rewind.h" -#include "core/sync.h" -#include "util/threading.h" +CXX_GUARD_START + +#include +#include +#include +#include struct mCoreThread; struct mCore; @@ -97,4 +99,6 @@ void mCoreThreadSetRewinding(struct mCoreThread* threadContext, bool); struct mCoreThread* mCoreThreadGet(void); struct mLogger* mCoreThreadLogger(void); +CXX_GUARD_END + #endif diff --git a/src/core/tile-cache.h b/include/mgba/core/tile-cache.h similarity index 96% rename from src/core/tile-cache.h rename to include/mgba/core/tile-cache.h index 052dca884..0a71c690a 100644 --- a/src/core/tile-cache.h +++ b/include/mgba/core/tile-cache.h @@ -6,7 +6,9 @@ #ifndef M_TILE_CACHE_H #define M_TILE_CACHE_H -#include "util/common.h" +#include + +CXX_GUARD_START DECL_BITFIELD(mTileCacheConfiguration, uint32_t); DECL_BIT(mTileCacheConfiguration, ShouldStore, 0); @@ -57,4 +59,6 @@ void mTileCacheSetPalette(struct mTileCache* cache, int palette); const uint16_t* mTileCacheGetTile(struct mTileCache* cache, unsigned tileId, unsigned paletteId); const uint16_t* mTileCacheGetTileIfDirty(struct mTileCache* cache, struct mTileCacheEntry* entry, unsigned tileId, unsigned paletteId); +CXX_GUARD_END + #endif diff --git a/src/core/timing.h b/include/mgba/core/timing.h similarity index 95% rename from src/core/timing.h rename to include/mgba/core/timing.h index ed99ff2e6..19de59dc7 100644 --- a/src/core/timing.h +++ b/include/mgba/core/timing.h @@ -6,7 +6,9 @@ #ifndef M_CORE_TIMING #define M_CORE_TIMING -#include "util/common.h" +#include + +CXX_GUARD_START struct mTiming; struct mTimingEvent { @@ -37,4 +39,6 @@ int32_t mTimingTick(struct mTiming* timing, int32_t cycles); int32_t mTimingCurrentTime(const struct mTiming* timing); int32_t mTimingNextEvent(struct mTiming* timing); +CXX_GUARD_END + #endif diff --git a/src/core/version.h b/include/mgba/core/version.h similarity index 100% rename from src/core/version.h rename to include/mgba/core/version.h diff --git a/src/ds/core.h b/include/mgba/ds/core.h similarity index 84% rename from src/ds/core.h rename to include/mgba/ds/core.h index 2b66f9982..fd3ee9ec1 100644 --- a/src/ds/core.h +++ b/include/mgba/ds/core.h @@ -6,7 +6,13 @@ #ifndef DS_CORE_H #define DS_CORE_H +#include + +CXX_GUARD_START + struct mCore; struct mCore* DSCoreCreate(void); +CXX_GUARD_END + #endif diff --git a/src/gb/core.h b/include/mgba/gb/core.h similarity index 84% rename from src/gb/core.h rename to include/mgba/gb/core.h index 10f7dc70d..10b284803 100644 --- a/src/gb/core.h +++ b/include/mgba/gb/core.h @@ -6,7 +6,13 @@ #ifndef GB_CORE_H #define GB_CORE_H +#include + +CXX_GUARD_START + struct mCore; struct mCore* GBCoreCreate(void); +CXX_GUARD_END + #endif diff --git a/src/gb/interface.h b/include/mgba/gb/interface.h similarity index 91% rename from src/gb/interface.h rename to include/mgba/gb/interface.h index 246b8f858..098a5e5dd 100644 --- a/src/gb/interface.h +++ b/include/mgba/gb/interface.h @@ -6,7 +6,9 @@ #ifndef GB_INTERFACE_H #define GB_INTERFACE_H -#include "util/common.h" +#include + +CXX_GUARD_START enum GBModel { GB_MODEL_AUTODETECT = 0xFF, @@ -32,4 +34,6 @@ enum GBMemoryBankControllerType { GB_MBC5_RUMBLE = 0x105 }; +CXX_GUARD_END + #endif diff --git a/src/gba/core.h b/include/mgba/gba/core.h similarity index 84% rename from src/gba/core.h rename to include/mgba/gba/core.h index c68277c25..cb4c1a862 100644 --- a/src/gba/core.h +++ b/include/mgba/gba/core.h @@ -6,7 +6,13 @@ #ifndef GBA_CORE_H #define GBA_CORE_H +#include + +CXX_GUARD_START + struct mCore; struct mCore* GBACoreCreate(void); +CXX_GUARD_END + #endif diff --git a/src/gba/interface.h b/include/mgba/gba/interface.h similarity index 91% rename from src/gba/interface.h rename to include/mgba/gba/interface.h index e0d27de98..3a5412645 100644 --- a/src/gba/interface.h +++ b/include/mgba/gba/interface.h @@ -6,9 +6,11 @@ #ifndef GBA_INTERFACE_H #define GBA_INTERFACE_H -#include "util/common.h" +#include -#include "core/interface.h" +CXX_GUARD_START + +#include enum GBASIOMode { SIO_NORMAL_8 = 0, @@ -42,4 +44,6 @@ struct GBASIODriver { uint16_t (*writeRegister)(struct GBASIODriver* driver, uint32_t address, uint16_t value); }; +CXX_GUARD_END + #endif diff --git a/src/arm/arm.h b/include/mgba/internal/arm/arm.h similarity index 97% rename from src/arm/arm.h rename to include/mgba/internal/arm/arm.h index f220091e4..ac2734172 100644 --- a/src/arm/arm.h +++ b/include/mgba/internal/arm/arm.h @@ -6,9 +6,11 @@ #ifndef ARM_H #define ARM_H -#include "util/common.h" +#include -#include "core/cpu.h" +CXX_GUARD_START + +#include enum { ARM_SP = 13, @@ -73,7 +75,7 @@ union PSR { unsigned z : 1; unsigned c : 1; unsigned v : 1; - unsigned : 20; + unsigned unused : 20; unsigned i : 1; unsigned f : 1; unsigned t : 1; @@ -83,7 +85,7 @@ union PSR { unsigned t : 1; unsigned f : 1; unsigned i : 1; - unsigned : 20; + unsigned unused : 20; unsigned v : 1; unsigned c : 1; unsigned z : 1; @@ -261,4 +263,6 @@ void ARMv5RunLoop(struct ARMCore* cpu); int32_t ARMv5RunCycles(struct ARMCore* cpu, int32_t cycles); void ARMRunFake(struct ARMCore* cpu, uint32_t opcode); +CXX_GUARD_END + #endif diff --git a/src/arm/debugger/cli-debugger.h b/include/mgba/internal/arm/debugger/cli-debugger.h similarity index 86% rename from src/arm/debugger/cli-debugger.h rename to include/mgba/internal/arm/debugger/cli-debugger.h index e0e26b79f..70f9b1885 100644 --- a/src/arm/debugger/cli-debugger.h +++ b/include/mgba/internal/arm/debugger/cli-debugger.h @@ -6,9 +6,13 @@ #ifndef ARM_CLI_DEBUGGER_H #define ARM_CLI_DEBUGGER_H -#include "util/common.h" +#include + +CXX_GUARD_START struct CLIDebuggerSystem; void ARMCLIDebuggerCreate(struct CLIDebuggerSystem* debugger); +CXX_GUARD_END + #endif diff --git a/src/arm/debugger/debugger.h b/include/mgba/internal/arm/debugger/debugger.h similarity index 87% rename from src/arm/debugger/debugger.h rename to include/mgba/internal/arm/debugger/debugger.h index aaedfc0fc..d5a05e6fd 100644 --- a/src/arm/debugger/debugger.h +++ b/include/mgba/internal/arm/debugger/debugger.h @@ -3,7 +3,16 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "debugger/debugger.h" +#ifndef ARM_DEBUGGER_H +#define ARM_DEBUGGER_H + +#include + +CXX_GUARD_START + +#include + +#include struct ARMDebugBreakpoint { uint32_t address; @@ -40,3 +49,7 @@ struct ARMDebugger { struct mDebuggerPlatform* ARMDebuggerPlatformCreate(void); bool ARMDebuggerSetSoftwareBreakpoint(struct mDebuggerPlatform* debugger, uint32_t address, enum ExecutionMode mode); void ARMDebuggerClearSoftwareBreakpoint(struct mDebuggerPlatform* debugger, uint32_t address); + +CXX_GUARD_END + +#endif diff --git a/src/arm/debugger/memory-debugger.h b/include/mgba/internal/arm/debugger/memory-debugger.h similarity index 88% rename from src/arm/debugger/memory-debugger.h rename to include/mgba/internal/arm/debugger/memory-debugger.h index 58a717617..1ec675992 100644 --- a/src/arm/debugger/memory-debugger.h +++ b/include/mgba/internal/arm/debugger/memory-debugger.h @@ -6,11 +6,15 @@ #ifndef MEMORY_DEBUGGER_H #define MEMORY_DEBUGGER_H -#include "util/common.h" +#include + +CXX_GUARD_START struct ARMDebugger; void ARMDebuggerInstallMemoryShim(struct ARMDebugger* debugger); void ARMDebuggerRemoveMemoryShim(struct ARMDebugger* debugger); +CXX_GUARD_END + #endif diff --git a/src/arm/decoder-inlines.h b/include/mgba/internal/arm/decoder-inlines.h similarity index 100% rename from src/arm/decoder-inlines.h rename to include/mgba/internal/arm/decoder-inlines.h diff --git a/src/arm/decoder.h b/include/mgba/internal/arm/decoder.h similarity index 98% rename from src/arm/decoder.h rename to include/mgba/internal/arm/decoder.h index 7faf2f98b..fe2240f6a 100644 --- a/src/arm/decoder.h +++ b/include/mgba/internal/arm/decoder.h @@ -6,7 +6,11 @@ #ifndef ARM_DECODER_H #define ARM_DECODER_H -#include "arm.h" +#include + +CXX_GUARD_START + +#include // Bit 0: a register is involved with this operand // Bit 1: an immediate is invovled with this operand @@ -234,4 +238,6 @@ bool ARMDecodeThumbCombine(struct ARMInstructionInfo* info1, struct ARMInstructi struct ARMInstructionInfo* out); int ARMDisassemble(struct ARMInstructionInfo* info, uint32_t pc, char* buffer, int blen); +CXX_GUARD_END + #endif diff --git a/src/arm/emitter-arm.h b/include/mgba/internal/arm/emitter-arm.h similarity index 100% rename from src/arm/emitter-arm.h rename to include/mgba/internal/arm/emitter-arm.h diff --git a/src/arm/emitter-inlines.h b/include/mgba/internal/arm/emitter-inlines.h similarity index 100% rename from src/arm/emitter-inlines.h rename to include/mgba/internal/arm/emitter-inlines.h diff --git a/src/arm/emitter-thumb.h b/include/mgba/internal/arm/emitter-thumb.h similarity index 100% rename from src/arm/emitter-thumb.h rename to include/mgba/internal/arm/emitter-thumb.h diff --git a/src/arm/isa-arm.h b/include/mgba/internal/arm/isa-arm.h similarity index 89% rename from src/arm/isa-arm.h rename to include/mgba/internal/arm/isa-arm.h index 77a72e28f..5296e5f44 100644 --- a/src/arm/isa-arm.h +++ b/include/mgba/internal/arm/isa-arm.h @@ -6,7 +6,9 @@ #ifndef ISA_ARM_H #define ISA_ARM_H -#include "util/common.h" +#include + +CXX_GUARD_START #define ARM_PREFETCH_CYCLES (1 + cpu->memory.activeSeqCycles32) @@ -16,4 +18,6 @@ typedef void (*ARMInstruction)(struct ARMCore*, uint32_t opcode); extern const ARMInstruction _armv4Table[0x1000]; extern const ARMInstruction _armv5Table[0x1000]; +CXX_GUARD_END + #endif diff --git a/src/arm/isa-inlines.h b/include/mgba/internal/arm/isa-inlines.h similarity index 100% rename from src/arm/isa-inlines.h rename to include/mgba/internal/arm/isa-inlines.h diff --git a/src/arm/isa-thumb.h b/include/mgba/internal/arm/isa-thumb.h similarity index 87% rename from src/arm/isa-thumb.h rename to include/mgba/internal/arm/isa-thumb.h index dd018441e..330a4faf8 100644 --- a/src/arm/isa-thumb.h +++ b/include/mgba/internal/arm/isa-thumb.h @@ -6,11 +6,15 @@ #ifndef ISA_THUMB_H #define ISA_THUMB_H -#include "util/common.h" +#include + +CXX_GUARD_START struct ARMCore; typedef void (*ThumbInstruction)(struct ARMCore*, uint16_t opcode); extern const ThumbInstruction _thumbTable[0x400]; +CXX_GUARD_END + #endif diff --git a/src/arm/macros.h b/include/mgba/internal/arm/macros.h similarity index 93% rename from src/arm/macros.h rename to include/mgba/internal/arm/macros.h index abde45bf1..4832f0546 100644 --- a/src/arm/macros.h +++ b/include/mgba/internal/arm/macros.h @@ -6,7 +6,7 @@ #ifndef MACROS_H #define MACROS_H -#include "util/common.h" +#include #define LOAD_64 LOAD_64LE #define LOAD_32 LOAD_32LE diff --git a/src/debugger/cli-debugger.h b/include/mgba/internal/debugger/cli-debugger.h similarity index 96% rename from src/debugger/cli-debugger.h rename to include/mgba/internal/debugger/cli-debugger.h index 98e19b5ab..2f86590ee 100644 --- a/src/debugger/cli-debugger.h +++ b/include/mgba/internal/debugger/cli-debugger.h @@ -6,9 +6,11 @@ #ifndef CLI_DEBUGGER_H #define CLI_DEBUGGER_H -#include "util/common.h" +#include -#include "debugger.h" +CXX_GUARD_START + +#include struct CLIDebugger; @@ -86,4 +88,6 @@ void CLIDebuggerAttachBackend(struct CLIDebugger*, struct CLIDebuggerBackend*); bool CLIDebuggerTabComplete(struct CLIDebugger*, const char* token, bool initial, size_t len); +CXX_GUARD_END + #endif diff --git a/src/debugger/debugger.h b/include/mgba/internal/debugger/debugger.h similarity index 94% rename from src/debugger/debugger.h rename to include/mgba/internal/debugger/debugger.h index a4ce367f6..3cd228dc7 100644 --- a/src/debugger/debugger.h +++ b/include/mgba/internal/debugger/debugger.h @@ -6,11 +6,13 @@ #ifndef DEBUGGER_H #define DEBUGGER_H -#include "util/common.h" +#include -#include "arm/arm.h" -#include "core/log.h" -#include "util/vector.h" +CXX_GUARD_START + +#include +#include +#include mLOG_DECLARE_CATEGORY(DEBUGGER); @@ -35,7 +37,7 @@ enum mDebuggerState { enum mWatchpointType { WATCHPOINT_WRITE = 1, WATCHPOINT_READ = 2, - WATCHPOINT_RW = WATCHPOINT_WRITE | WATCHPOINT_READ + WATCHPOINT_RW = 3 }; enum mBreakpointType { @@ -111,5 +113,6 @@ void mDebuggerAttach(struct mDebugger*, struct mCore*); void mDebuggerRun(struct mDebugger*); void mDebuggerEnter(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*); +CXX_GUARD_END #endif diff --git a/src/debugger/gdb-stub.h b/include/mgba/internal/debugger/gdb-stub.h similarity index 87% rename from src/debugger/gdb-stub.h rename to include/mgba/internal/debugger/gdb-stub.h index 6e723e48e..9e6be2239 100644 --- a/src/debugger/gdb-stub.h +++ b/include/mgba/internal/debugger/gdb-stub.h @@ -6,11 +6,13 @@ #ifndef GDB_STUB_H #define GDB_STUB_H -#include "util/common.h" +#include -#include "debugger/debugger.h" +CXX_GUARD_START -#include "util/socket.h" +#include + +#include #define GDB_STUB_MAX_LINE 1200 #define GDB_STUB_INTERVAL 32 @@ -47,4 +49,6 @@ void GDBStubShutdown(struct GDBStub*); void GDBStubUpdate(struct GDBStub*); +CXX_GUARD_END + #endif diff --git a/src/debugger/parser.h b/include/mgba/internal/debugger/parser.h similarity index 91% rename from src/debugger/parser.h rename to include/mgba/internal/debugger/parser.h index c68f08d9e..c5ab01446 100644 --- a/src/debugger/parser.h +++ b/include/mgba/internal/debugger/parser.h @@ -6,8 +6,11 @@ #ifndef PARSER_H #define PARSER_H -#include "util/common.h" -#include "debugger.h" +#include + +CXX_GUARD_START + +#include enum LexState { LEX_ERROR = -1, @@ -62,4 +65,6 @@ void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv); void lexFree(struct LexVector* lv); void parseFree(struct ParseTree* tree); +CXX_GUARD_END + #endif diff --git a/src/ds/bios.h b/include/mgba/internal/ds/bios.h similarity index 87% rename from src/ds/bios.h rename to include/mgba/internal/ds/bios.h index 6c054db94..3801f43b5 100644 --- a/src/ds/bios.h +++ b/include/mgba/internal/ds/bios.h @@ -6,9 +6,11 @@ #ifndef DS_BIOS_H #define DS_BIOS_H -#include "util/common.h" +#include -#include "core/log.h" +CXX_GUARD_START + +#include mLOG_DECLARE_CATEGORY(DS_BIOS); @@ -21,4 +23,6 @@ void DS9Swi32(struct ARMCore* cpu, int immediate); extern const uint32_t DS7_BIOS_CHECKSUM; extern const uint32_t DS9_BIOS_CHECKSUM; +CXX_GUARD_END + #endif diff --git a/src/ds/ds.h b/include/mgba/internal/ds/ds.h similarity index 92% rename from src/ds/ds.h rename to include/mgba/internal/ds/ds.h index e2de69d23..eb4c4e8ca 100644 --- a/src/ds/ds.h +++ b/include/mgba/internal/ds/ds.h @@ -6,14 +6,16 @@ #ifndef DS_H #define DS_H -#include "util/common.h" +#include -#include "arm/arm.h" -#include "core/log.h" +CXX_GUARD_START -#include "ds/memory.h" -#include "ds/timer.h" -#include "ds/video.h" +#include +#include + +#include +#include +#include extern const uint32_t DS_ARM946ES_FREQUENCY; extern const uint32_t DS_ARM7TDMI_FREQUENCY; @@ -140,4 +142,6 @@ void DSWriteIME(struct ARMCore* cpu, uint16_t* io, uint16_t value); void DSWriteIE(struct ARMCore* cpu, uint16_t* io, uint32_t value); void DSRaiseIRQ(struct ARMCore* cpu, uint16_t* io, enum DSIRQ irq); +CXX_GUARD_END + #endif diff --git a/src/ds/extra/cli.h b/include/mgba/internal/ds/extra/cli.h similarity index 81% rename from src/ds/extra/cli.h rename to include/mgba/internal/ds/extra/cli.h index 19f6afd91..a749e609b 100644 --- a/src/ds/extra/cli.h +++ b/include/mgba/internal/ds/extra/cli.h @@ -6,7 +6,11 @@ #ifndef DS_CLI_H #define DS_CLI_H -#include "debugger/cli-debugger.h" +#include + +CXX_GUARD_START + +#include struct mCore; @@ -21,4 +25,6 @@ struct DSCLIDebugger { struct DSCLIDebugger* DSCLIDebuggerCreate(struct mCore*); +CXX_GUARD_END + #endif diff --git a/src/ds/io.h b/include/mgba/internal/ds/io.h similarity index 99% rename from src/ds/io.h rename to include/mgba/internal/ds/io.h index b1623b1ea..1683291ef 100644 --- a/src/ds/io.h +++ b/include/mgba/internal/ds/io.h @@ -6,9 +6,11 @@ #ifndef DS_IO_H #define DS_IO_H -#include "util/common.h" +#include -#include "core/log.h" +CXX_GUARD_START + +#include enum DS7IORegisters { // Video @@ -339,4 +341,7 @@ void DS9IOWrite(struct DS* ds, uint32_t address, uint16_t value); void DS9IOWrite8(struct DS* ds, uint32_t address, uint8_t value); void DS9IOWrite32(struct DS* ds, uint32_t address, uint32_t value); uint16_t DS9IORead(struct DS* ds, uint32_t address); + +CXX_GUARD_END + #endif diff --git a/src/ds/memory.h b/include/mgba/internal/ds/memory.h similarity index 97% rename from src/ds/memory.h rename to include/mgba/internal/ds/memory.h index 97f467bb6..18fa89f17 100644 --- a/src/ds/memory.h +++ b/include/mgba/internal/ds/memory.h @@ -6,11 +6,13 @@ #ifndef DS_MEMORY_H #define DS_MEMORY_H -#include "util/common.h" +#include -#include "arm/arm.h" -#include "core/log.h" -#include "ds/io.h" +CXX_GUARD_START + +#include +#include +#include enum DSMemoryRegion { DS7_REGION_BIOS = 0x0, diff --git a/src/ds/timer.h b/include/mgba/internal/ds/timer.h similarity index 94% rename from src/ds/timer.h rename to include/mgba/internal/ds/timer.h index c43a82774..2e0faee3d 100644 --- a/src/ds/timer.h +++ b/include/mgba/internal/ds/timer.h @@ -6,7 +6,9 @@ #ifndef DS_TIMER_H #define DS_TIMER_H -#include "util/common.h" +#include + +CXX_GUARD_START DECL_BITFIELD(DSTimerFlags, uint32_t); DECL_BITS(DSTimerFlags, PrescaleBits, 0, 4); @@ -31,4 +33,7 @@ void DSTimerWriteTMCNT_HI(struct DSTimer* timer, struct ARMCore* cpu, uint16_t* struct DS; int32_t DSTimersProcessEvents(struct DS* ds, int32_t cycles); + +CXX_GUARD_END + #endif diff --git a/src/ds/video.h b/include/mgba/internal/ds/video.h similarity index 92% rename from src/ds/video.h rename to include/mgba/internal/ds/video.h index 958b95394..c1abe872f 100644 --- a/src/ds/video.h +++ b/include/mgba/internal/ds/video.h @@ -6,9 +6,11 @@ #ifndef DS_VIDEO_H #define DS_VIDEO_H -#include "util/common.h" +#include -#include "core/log.h" +CXX_GUARD_START + +#include mLOG_DECLARE_CATEGORY(DS_VIDEO); @@ -48,4 +50,6 @@ void DSVideoInit(struct DSVideo* video); void DSVideoReset(struct DSVideo* video); void DSVideoDeinit(struct DSVideo* video); +CXX_GUARD_START + #endif diff --git a/src/gb/audio.h b/include/mgba/internal/gb/audio.h similarity index 97% rename from src/gb/audio.h rename to include/mgba/internal/gb/audio.h index 4c38fcef8..b1e86e299 100644 --- a/src/gb/audio.h +++ b/include/mgba/internal/gb/audio.h @@ -6,10 +6,11 @@ #ifndef GB_AUDIO_H #define GB_AUDIO_H -#include "util/common.h" +#include -#include "core/timing.h" -#include "third-party/blip_buf/blip_buf.h" +CXX_GUARD_START + +#include DECL_BITFIELD(GBAudioRegisterDuty, uint8_t); DECL_BITS(GBAudioRegisterDuty, Length, 0, 6); @@ -155,8 +156,8 @@ struct GBAudio { struct GBAudioWaveChannel ch3; struct GBAudioNoiseChannel ch4; - blip_t* left; - blip_t* right; + struct blip_t* left; + struct blip_t* right; int16_t lastLeft; int16_t lastRight; int clock; @@ -240,4 +241,6 @@ struct GBSerializedState; void GBAudioSerialize(const struct GBAudio* audio, struct GBSerializedState* state); void GBAudioDeserialize(struct GBAudio* audio, const struct GBSerializedState* state); +CXX_GUARD_END + #endif diff --git a/src/gb/cheats.h b/include/mgba/internal/gb/cheats.h similarity index 85% rename from src/gb/cheats.h rename to include/mgba/internal/gb/cheats.h index 1e5b4da24..0eb7d3b3c 100644 --- a/src/gb/cheats.h +++ b/include/mgba/internal/gb/cheats.h @@ -6,10 +6,12 @@ #ifndef GB_CHEATS_H #define GB_CHEATS_H -#include "util/common.h" +#include -#include "core/cheats.h" -#include "util/vector.h" +CXX_GUARD_START + +#include +#include enum GBCheatType { GB_CHEAT_AUTODETECT, @@ -36,4 +38,6 @@ struct GBCheatSet { struct mCheatDevice* GBCheatDeviceCreate(void); +CXX_GUARD_END + #endif diff --git a/src/gb/extra/cli.h b/include/mgba/internal/gb/extra/cli.h similarity index 80% rename from src/gb/extra/cli.h rename to include/mgba/internal/gb/extra/cli.h index 013843ce5..19c2c711b 100644 --- a/src/gb/extra/cli.h +++ b/include/mgba/internal/gb/extra/cli.h @@ -6,7 +6,11 @@ #ifndef GB_CLI_H #define GB_CLI_H -#include "debugger/cli-debugger.h" +#include + +CXX_GUARD_START + +#include struct GBCLIDebugger { struct CLIDebuggerSystem d; @@ -19,4 +23,6 @@ struct GBCLIDebugger { struct CLIDebuggerSystem* GBCLIDebuggerCreate(struct mCore*); +CXX_GUARD_END + #endif diff --git a/src/gb/gb.h b/include/mgba/internal/gb/gb.h similarity index 88% rename from src/gb/gb.h rename to include/mgba/internal/gb/gb.h index 89e38c6de..d047f1c2c 100644 --- a/src/gb/gb.h +++ b/include/mgba/internal/gb/gb.h @@ -6,19 +6,19 @@ #ifndef GB_H #define GB_H -#include "util/common.h" +#include -#include "core/log.h" -#include "core/timing.h" +CXX_GUARD_START -#include "lr35902/lr35902.h" +#include +#include +#include -#include "gb/audio.h" -#include "gb/interface.h" -#include "gb/memory.h" -#include "gb/sio.h" -#include "gb/timer.h" -#include "gb/video.h" +#include +#include +#include +#include +#include extern const uint32_t DMG_LR35902_FREQUENCY; extern const uint32_t CGB_LR35902_FREQUENCY; @@ -43,6 +43,7 @@ enum GBIRQVector { GB_VECTOR_KEYPAD = 0x60, }; +struct LR35902Core; struct mCoreSync; struct mAVStream; struct mCoreCallbacks; @@ -79,6 +80,7 @@ struct GB { struct mAVStream* stream; bool cpuBlocked; + bool earlyExit; struct mTimingEvent eiPending; unsigned doubleSpeed; }; @@ -119,7 +121,6 @@ void GBHalt(struct LR35902Core* cpu); struct VFile; bool GBLoadROM(struct GB* gb, struct VFile* vf); bool GBLoadSave(struct GB* gb, struct VFile* vf); -void GBYankROM(struct GB* gb); void GBUnloadROM(struct GB* gb); void GBSynthesizeROM(struct VFile* vf); @@ -140,4 +141,6 @@ void GBGetGameCode(const struct GB* gba, char* out); void GBFrameEnded(struct GB* gb); +CXX_GUARD_END + #endif diff --git a/src/gb/io.h b/include/mgba/internal/gb/io.h similarity index 96% rename from src/gb/io.h rename to include/mgba/internal/gb/io.h index ffd6f47c9..5ed4cb0fe 100644 --- a/src/gb/io.h +++ b/include/mgba/internal/gb/io.h @@ -6,9 +6,11 @@ #ifndef GB_IO_H #define GB_IO_H -#include "util/common.h" +#include -#include "core/log.h" +CXX_GUARD_START + +#include mLOG_DECLARE_CATEGORY(GB_IO); @@ -118,4 +120,6 @@ struct GBSerializedState; void GBIOSerialize(const struct GB* gb, struct GBSerializedState* state); void GBIODeserialize(struct GB* gb, const struct GBSerializedState* state); +CXX_GUARD_END + #endif diff --git a/src/gb/mbc.h b/include/mgba/internal/gb/mbc.h similarity index 91% rename from src/gb/mbc.h rename to include/mgba/internal/gb/mbc.h index c750db707..32496177f 100644 --- a/src/gb/mbc.h +++ b/include/mgba/internal/gb/mbc.h @@ -6,9 +6,11 @@ #ifndef GB_MBC_H #define GB_MBC_H -#include "util/common.h" +#include -#include "core/log.h" +CXX_GUARD_START + +#include mLOG_DECLARE_CATEGORY(GB_MBC); @@ -37,4 +39,6 @@ void GBMBCRTCWrite(struct GB* gb); uint8_t GBMBC7Read(struct GBMemory*, uint16_t address); void GBMBC7Write(struct GBMemory*, uint16_t address, uint8_t value); +CXX_GUARD_END + #endif diff --git a/src/gb/memory.h b/include/mgba/internal/gb/memory.h similarity index 95% rename from src/gb/memory.h rename to include/mgba/internal/gb/memory.h index cb3cf1b1d..45a3f0aed 100644 --- a/src/gb/memory.h +++ b/include/mgba/internal/gb/memory.h @@ -6,12 +6,13 @@ #ifndef GB_MEMORY_H #define GB_MEMORY_H -#include "util/common.h" +#include -#include "core/log.h" -#include "core/timing.h" -#include "gb/interface.h" -#include "lr35902/lr35902.h" +CXX_GUARD_START + +#include +#include +#include #include @@ -152,6 +153,7 @@ struct GBMemory { struct mRumble* rumble; }; +struct LR35902Core; void GBMemoryInit(struct GB* gb); void GBMemoryDeinit(struct GB* gb); @@ -175,4 +177,6 @@ struct GBSerializedState; void GBMemorySerialize(const struct GB* gb, struct GBSerializedState* state); void GBMemoryDeserialize(struct GB* gb, const struct GBSerializedState* state); +CXX_GUARD_END + #endif diff --git a/src/gb/overrides.h b/include/mgba/internal/gb/overrides.h similarity index 88% rename from src/gb/overrides.h rename to include/mgba/internal/gb/overrides.h index fc4f8f39a..fd787163c 100644 --- a/src/gb/overrides.h +++ b/include/mgba/internal/gb/overrides.h @@ -6,9 +6,11 @@ #ifndef GB_OVERRIDES_H #define GB_OVERRIDES_H -#include "util/common.h" +#include -#include "gb/interface.h" +CXX_GUARD_START + +#include struct GBCartridgeOverride { int headerCrc32; @@ -24,4 +26,6 @@ struct GB; void GBOverrideApply(struct GB*, const struct GBCartridgeOverride*); void GBOverrideApplyDefaults(struct GB*); +CXX_GUARD_END + #endif diff --git a/src/gb/renderers/software.h b/include/mgba/internal/gb/renderers/software.h similarity index 81% rename from src/gb/renderers/software.h rename to include/mgba/internal/gb/renderers/software.h index 6ea90a6e1..038c660b8 100644 --- a/src/gb/renderers/software.h +++ b/include/mgba/internal/gb/renderers/software.h @@ -6,11 +6,13 @@ #ifndef GB_RENDERER_SOFTWARE_H #define GB_RENDERER_SOFTWARE_H -#include "util/common.h" +#include -#include "core/core.h" -#include "gb/gb.h" -#include "gb/video.h" +CXX_GUARD_START + +#include +#include +#include struct GBVideoSoftwareRenderer { struct GBVideoRenderer d; @@ -36,4 +38,6 @@ struct GBVideoSoftwareRenderer { void GBVideoSoftwareRendererCreate(struct GBVideoSoftwareRenderer*); +CXX_GUARD_END + #endif diff --git a/src/gb/renderers/tile-cache.h b/include/mgba/internal/gb/renderers/tile-cache.h similarity index 88% rename from src/gb/renderers/tile-cache.h rename to include/mgba/internal/gb/renderers/tile-cache.h index 630b9e8e9..1b739ca46 100644 --- a/src/gb/renderers/tile-cache.h +++ b/include/mgba/internal/gb/renderers/tile-cache.h @@ -6,7 +6,9 @@ #ifndef GB_TILE_CACHE_H #define GB_TILE_CACHE_H -#include "util/common.h" +#include + +CXX_GUARD_START struct GBVideo; struct mTileCache; @@ -14,4 +16,6 @@ struct mTileCache; void GBVideoTileCacheInit(struct mTileCache* cache); void GBVideoTileCacheAssociate(struct mTileCache* cache, struct GBVideo* video); +CXX_GUARD_END + #endif diff --git a/src/gb/serialize.h b/include/mgba/internal/gb/serialize.h similarity index 98% rename from src/gb/serialize.h rename to include/mgba/internal/gb/serialize.h index 3329141db..e370c997b 100644 --- a/src/gb/serialize.h +++ b/include/mgba/internal/gb/serialize.h @@ -6,10 +6,12 @@ #ifndef GB_SERIALIZE_H #define GB_SERIALIZE_H -#include "util/common.h" +#include -#include "core/core.h" -#include "gb/gb.h" +CXX_GUARD_START + +#include +#include extern const uint32_t GB_SAVESTATE_MAGIC; extern const uint32_t GB_SAVESTATE_VERSION; @@ -370,4 +372,6 @@ struct GBSerializedState { bool GBDeserialize(struct GB* gb, const struct GBSerializedState* state); void GBSerialize(struct GB* gb, struct GBSerializedState* state); +CXX_GUARD_END + #endif diff --git a/src/gb/sio.h b/include/mgba/internal/gb/sio.h similarity index 54% rename from src/gb/sio.h rename to include/mgba/internal/gb/sio.h index 715b5b9c8..004cf16e8 100644 --- a/src/gb/sio.h +++ b/include/mgba/internal/gb/sio.h @@ -6,15 +6,26 @@ #ifndef GB_SIO_H #define GB_SIO_H -#include "util/common.h" +#include -#include "core/timing.h" +CXX_GUARD_START + +#include +#include + +#define MAX_GBS 2 + +extern const int GBSIOCyclesPerTransfer[2]; + +mLOG_DECLARE_CATEGORY(GB_SIO); struct GB; +struct GBSIODriver; struct GBSIO { struct GB* p; struct mTimingEvent event; + struct GBSIODriver* driver; int32_t nextEvent; int32_t period; @@ -23,6 +34,15 @@ struct GBSIO { uint8_t pendingSB; }; +struct GBSIODriver { + struct GBSIO* p; + + bool (*init)(struct GBSIODriver* driver); + void (*deinit)(struct GBSIODriver* driver); + void (*writeSB)(struct GBSIODriver* driver, uint8_t value); + uint8_t (*writeSC)(struct GBSIODriver* driver, uint8_t value); +}; + DECL_BITFIELD(GBRegisterSC, uint8_t); DECL_BIT(GBRegisterSC, ShiftClock, 0); DECL_BIT(GBRegisterSC, ClockSpeed, 1); @@ -31,6 +51,10 @@ DECL_BIT(GBRegisterSC, Enable, 7); void GBSIOInit(struct GBSIO* sio); void GBSIOReset(struct GBSIO* sio); void GBSIODeinit(struct GBSIO* sio); +void GBSIOSetDriver(struct GBSIO* sio, struct GBSIODriver* driver); void GBSIOWriteSC(struct GBSIO* sio, uint8_t sc); +void GBSIOWriteSB(struct GBSIO* sio, uint8_t sb); + +CXX_GUARD_END #endif diff --git a/include/mgba/internal/gb/sio/lockstep.h b/include/mgba/internal/gb/sio/lockstep.h new file mode 100644 index 000000000..25f6d9c74 --- /dev/null +++ b/include/mgba/internal/gb/sio/lockstep.h @@ -0,0 +1,49 @@ +/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef GB_SIO_LOCKSTEP_H +#define GB_SIO_LOCKSTEP_H + +#include + +CXX_GUARD_START + +#include +#include +#include + +struct GBSIOLockstep { + struct mLockstep d; + struct GBSIOLockstepNode* players[MAX_GBS]; + + uint8_t pendingSB[MAX_GBS]; + bool masterClaimed; +}; + +struct GBSIOLockstepNode { + struct GBSIODriver d; + struct GBSIOLockstep* p; + struct mTimingEvent event; + + volatile int32_t nextEvent; + int32_t eventDiff; + int id; + bool transferFinished; +#ifndef NDEBUG + int transferId; + enum mLockstepPhase phase; +#endif +}; + +void GBSIOLockstepInit(struct GBSIOLockstep*); + +void GBSIOLockstepNodeCreate(struct GBSIOLockstepNode*); + +bool GBSIOLockstepAttachNode(struct GBSIOLockstep*, struct GBSIOLockstepNode*); +void GBSIOLockstepDetachNode(struct GBSIOLockstep*, struct GBSIOLockstepNode*); + +CXX_GUARD_END + +#endif diff --git a/src/gb/timer.h b/include/mgba/internal/gb/timer.h similarity index 91% rename from src/gb/timer.h rename to include/mgba/internal/gb/timer.h index 9ce673b56..b81ff1c34 100644 --- a/src/gb/timer.h +++ b/include/mgba/internal/gb/timer.h @@ -6,9 +6,11 @@ #ifndef GB_TIMER_H #define GB_TIMER_H -#include "util/common.h" +#include -#include "core/timing.h" +CXX_GUARD_START + +#include DECL_BITFIELD(GBRegisterTAC, uint8_t); DECL_BITS(GBRegisterTAC, Clock, 0, 2); @@ -38,4 +40,6 @@ struct GBSerializedState; void GBTimerSerialize(const struct GBTimer* timer, struct GBSerializedState* state); void GBTimerDeserialize(struct GBTimer* timer, const struct GBSerializedState* state); +CXX_GUARD_END + #endif diff --git a/src/gb/video.h b/include/mgba/internal/gb/video.h similarity index 88% rename from src/gb/video.h rename to include/mgba/internal/gb/video.h index a2ddccdb3..67bf96405 100644 --- a/src/gb/video.h +++ b/include/mgba/internal/gb/video.h @@ -6,28 +6,28 @@ #ifndef GB_VIDEO_H #define GB_VIDEO_H -#include "util/common.h" +#include -#include "core/interface.h" -#include "core/timing.h" -#include "gb/interface.h" -#include "gb/memory.h" +CXX_GUARD_START + +#include +#include enum { GB_VIDEO_HORIZONTAL_PIXELS = 160, GB_VIDEO_VERTICAL_PIXELS = 144, GB_VIDEO_VBLANK_PIXELS = 10, - GB_VIDEO_VERTICAL_TOTAL_PIXELS = GB_VIDEO_VERTICAL_PIXELS + GB_VIDEO_VBLANK_PIXELS, + GB_VIDEO_VERTICAL_TOTAL_PIXELS = 154, // TODO: Figure out exact lengths GB_VIDEO_MODE_2_LENGTH = 76, GB_VIDEO_MODE_3_LENGTH_BASE = 171, GB_VIDEO_MODE_0_LENGTH_BASE = 209, - GB_VIDEO_HORIZONTAL_LENGTH = GB_VIDEO_MODE_0_LENGTH_BASE + GB_VIDEO_MODE_2_LENGTH + GB_VIDEO_MODE_3_LENGTH_BASE, + GB_VIDEO_HORIZONTAL_LENGTH = 456, - GB_VIDEO_MODE_1_LENGTH = GB_VIDEO_HORIZONTAL_LENGTH * GB_VIDEO_VBLANK_PIXELS, - GB_VIDEO_TOTAL_LENGTH = GB_VIDEO_HORIZONTAL_LENGTH * GB_VIDEO_VERTICAL_TOTAL_PIXELS, + GB_VIDEO_MODE_1_LENGTH = 65664, + GB_VIDEO_TOTAL_LENGTH = 70224, GB_BASE_MAP = 0x1800, GB_SIZE_MAP = 0x0400 @@ -53,7 +53,6 @@ union GBOAM { uint8_t raw[160]; }; -enum GBModel; struct mTileCache; struct GBVideoRenderer { void (*init)(struct GBVideoRenderer* renderer, enum GBModel model); @@ -143,4 +142,6 @@ struct GBSerializedState; void GBVideoSerialize(const struct GBVideo* video, struct GBSerializedState* state); void GBVideoDeserialize(struct GBVideo* video, const struct GBSerializedState* state); +CXX_GUARD_END + #endif diff --git a/src/gba/audio.h b/include/mgba/internal/gba/audio.h similarity index 95% rename from src/gba/audio.h rename to include/mgba/internal/gba/audio.h index 7f8175380..10f5a7e65 100644 --- a/src/gba/audio.h +++ b/include/mgba/internal/gba/audio.h @@ -6,11 +6,13 @@ #ifndef GBA_AUDIO_H #define GBA_AUDIO_H -#include "util/common.h" +#include -#include "core/log.h" -#include "gb/audio.h" -#include "util/circle-buffer.h" +CXX_GUARD_START + +#include +#include +#include mLOG_DECLARE_CATEGORY(GBA_AUDIO); @@ -116,4 +118,6 @@ void GBAAudioDeserialize(struct GBAAudio* audio, const struct GBASerializedState float GBAAudioCalculateRatio(float inputSampleRate, float desiredFPS, float desiredSampleRatio); +CXX_GUARD_END + #endif diff --git a/src/gba/bios.h b/include/mgba/internal/gba/bios.h similarity index 84% rename from src/gba/bios.h rename to include/mgba/internal/gba/bios.h index fdda39402..a89edfd68 100644 --- a/src/gba/bios.h +++ b/include/mgba/internal/gba/bios.h @@ -6,13 +6,15 @@ #ifndef GBA_BIOS_H #define GBA_BIOS_H -#include "util/common.h" +#include -#include "arm/arm.h" -#include "core/log.h" +CXX_GUARD_START + +#include mLOG_DECLARE_CATEGORY(GBA_BIOS); +struct ARMCore; void GBASwi16(struct ARMCore* cpu, int immediate); void GBASwi32(struct ARMCore* cpu, int immediate); @@ -20,4 +22,6 @@ uint32_t GBAChecksum(uint32_t* memory, size_t size); extern const uint32_t GBA_BIOS_CHECKSUM; extern const uint32_t GBA_DS_BIOS_CHECKSUM; +CXX_GUARD_END + #endif diff --git a/src/gba/cheats.h b/include/mgba/internal/gba/cheats.h similarity index 96% rename from src/gba/cheats.h rename to include/mgba/internal/gba/cheats.h index 31f5acadc..83912f660 100644 --- a/src/gba/cheats.h +++ b/include/mgba/internal/gba/cheats.h @@ -6,10 +6,12 @@ #ifndef GBA_CHEATS_H #define GBA_CHEATS_H -#include "util/common.h" +#include -#include "arm/arm.h" -#include "core/cheats.h" +CXX_GUARD_START + +#include +#include #define MAX_ROM_PATCHES 4 #define COMPLETE ((size_t) -1) @@ -174,4 +176,6 @@ bool GBACheatAddVBALine(struct GBACheatSet*, const char* line); int GBACheatAddressIsReal(uint32_t address); +CXX_GUARD_END + #endif diff --git a/src/gba/dma.h b/include/mgba/internal/gba/dma.h similarity index 93% rename from src/gba/dma.h rename to include/mgba/internal/gba/dma.h index 405a9e554..fd86829af 100644 --- a/src/gba/dma.h +++ b/include/mgba/internal/gba/dma.h @@ -6,7 +6,9 @@ #ifndef GBA_DMA_H #define GBA_DMA_H -#include "util/common.h" +#include + +CXX_GUARD_START struct GBA; void GBADMAInit(struct GBA* gba); @@ -23,4 +25,6 @@ void GBADMARunHblank(struct GBA* gba, int32_t cycles); void GBADMARunVblank(struct GBA* gba, int32_t cycles); void GBADMAUpdate(struct GBA* gba); +CXX_GUARD_END + #endif diff --git a/src/gba/extra/cli.h b/include/mgba/internal/gba/extra/cli.h similarity index 81% rename from src/gba/extra/cli.h rename to include/mgba/internal/gba/extra/cli.h index 347f45437..2b2d407fe 100644 --- a/src/gba/extra/cli.h +++ b/include/mgba/internal/gba/extra/cli.h @@ -6,7 +6,11 @@ #ifndef GBA_CLI_H #define GBA_CLI_H -#include "debugger/cli-debugger.h" +#include + +CXX_GUARD_START + +#include struct mCore; @@ -21,4 +25,6 @@ struct GBACLIDebugger { struct GBACLIDebugger* GBACLIDebuggerCreate(struct mCore*); +CXX_GUARD_END + #endif diff --git a/src/gba/gba.h b/include/mgba/internal/gba/gba.h similarity index 91% rename from src/gba/gba.h rename to include/mgba/internal/gba/gba.h index cfcaa94e3..73171095b 100644 --- a/src/gba/gba.h +++ b/include/mgba/internal/gba/gba.h @@ -6,18 +6,18 @@ #ifndef GBA_H #define GBA_H -#include "util/common.h" +#include -#include "arm/arm.h" -#include "core/log.h" -#include "core/timing.h" +CXX_GUARD_START -#include "gba/interface.h" -#include "gba/memory.h" -#include "gba/video.h" -#include "gba/audio.h" -#include "gba/sio.h" -#include "gba/timer.h" +#include +#include + +#include +#include +#include +#include +#include #define GBA_ARM7TDMI_FREQUENCY 0x1000000U @@ -50,6 +50,7 @@ enum { SP_BASE_SUPERVISOR = 0x03007FE0 }; +struct ARMCore; struct GBA; struct Patch; struct VFile; @@ -150,8 +151,11 @@ void GBAHalt(struct GBA* gba); void GBAStop(struct GBA* gba); void GBADebug(struct GBA* gba, uint16_t value); +#ifdef USE_DEBUGGERS +struct mDebugger; void GBAAttachDebugger(struct GBA* gba, struct mDebugger* debugger); void GBADetachDebugger(struct GBA* gba); +#endif void GBASetBreakpoint(struct GBA* gba, struct mCPUComponent* component, uint32_t address, enum ExecutionMode mode, uint32_t* opcode); @@ -175,4 +179,6 @@ void GBAGetGameTitle(const struct GBA* gba, char* out); void GBAFrameStarted(struct GBA* gba); void GBAFrameEnded(struct GBA* gba); +CXX_GUARD_END + #endif diff --git a/src/gba/hardware.h b/include/mgba/internal/gba/hardware.h similarity index 95% rename from src/gba/hardware.h rename to include/mgba/internal/gba/hardware.h index bf7915c2c..8aa98ba47 100644 --- a/src/gba/hardware.h +++ b/include/mgba/internal/gba/hardware.h @@ -6,12 +6,13 @@ #ifndef GBA_HARDWARE_H #define GBA_HARDWARE_H -#include "util/common.h" +#include -#include "arm/macros.h" -#include "core/log.h" -#include "core/timing.h" -#include "gba/interface.h" +CXX_GUARD_START + +#include +#include +#include #include @@ -144,4 +145,6 @@ struct GBASerializedState; void GBAHardwareSerialize(const struct GBACartridgeHardware* gpio, struct GBASerializedState* state); void GBAHardwareDeserialize(struct GBACartridgeHardware* gpio, const struct GBASerializedState* state); +CXX_GUARD_END + #endif diff --git a/src/gba/input.h b/include/mgba/internal/gba/input.h similarity index 86% rename from src/gba/input.h rename to include/mgba/internal/gba/input.h index 5b3a418c1..03cb8b5e0 100644 --- a/src/gba/input.h +++ b/include/mgba/internal/gba/input.h @@ -6,7 +6,11 @@ #ifndef GBA_INPUT_H #define GBA_INPUT_H -#include "core/input.h" +#include + +CXX_GUARD_START + +#include extern const struct mInputPlatformInfo GBAInputInfo; @@ -25,4 +29,6 @@ enum GBAKey { GBA_KEY_NONE = -1 }; +CXX_GUARD_END + #endif diff --git a/src/gba/io.h b/include/mgba/internal/gba/io.h similarity index 97% rename from src/gba/io.h rename to include/mgba/internal/gba/io.h index 5a73bce34..959babf05 100644 --- a/src/gba/io.h +++ b/include/mgba/internal/gba/io.h @@ -6,9 +6,11 @@ #ifndef GBA_IO_H #define GBA_IO_H -#include "util/common.h" +#include -#include "gba/gba.h" +CXX_GUARD_START + +#include enum GBAIORegisters { // Video @@ -161,6 +163,7 @@ mLOG_DECLARE_CATEGORY(GBA_IO); extern const char* const GBAIORegisterNames[]; +struct GBA; void GBAIOInit(struct GBA* gba); void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value); void GBAIOWrite8(struct GBA* gba, uint32_t address, uint8_t value); @@ -173,4 +176,6 @@ struct GBASerializedState; void GBAIOSerialize(struct GBA* gba, struct GBASerializedState* state); void GBAIODeserialize(struct GBA* gba, const struct GBASerializedState* state); +CXX_GUARD_END + #endif diff --git a/src/gba/memory.h b/include/mgba/internal/gba/memory.h similarity index 94% rename from src/gba/memory.h rename to include/mgba/internal/gba/memory.h index 08d89e9df..9507f0e29 100644 --- a/src/gba/memory.h +++ b/include/mgba/internal/gba/memory.h @@ -6,14 +6,16 @@ #ifndef GBA_MEMORY_H #define GBA_MEMORY_H -#include "util/common.h" +#include -#include "arm/arm.h" -#include "core/timing.h" +CXX_GUARD_START -#include "gba/hardware.h" -#include "gba/savedata.h" -#include "gba/vfame.h" +#include + +#include +#include +#include +#include enum GBAMemoryRegion { REGION_BIOS = 0x0, @@ -116,7 +118,7 @@ struct GBAMemory { uint32_t* wram; uint32_t* iwram; uint32_t* rom; - uint16_t io[SIZE_IO >> 1]; + uint16_t io[512]; struct GBACartridgeHardware hw; struct GBASavedata savedata; @@ -146,6 +148,7 @@ struct GBAMemory { bool mirroring; }; +struct GBA; void GBAMemoryInit(struct GBA* gba); void GBAMemoryDeinit(struct GBA* gba); @@ -180,4 +183,6 @@ struct GBASerializedState; void GBAMemorySerialize(const struct GBAMemory* memory, struct GBASerializedState* state); void GBAMemoryDeserialize(struct GBAMemory* memory, const struct GBASerializedState* state); +CXX_GUARD_END + #endif diff --git a/src/gba/overrides.h b/include/mgba/internal/gba/overrides.h similarity index 88% rename from src/gba/overrides.h rename to include/mgba/internal/gba/overrides.h index 58c005588..4240fea2e 100644 --- a/src/gba/overrides.h +++ b/include/mgba/internal/gba/overrides.h @@ -6,9 +6,11 @@ #ifndef GBA_OVERRIDES_H #define GBA_OVERRIDES_H -#include "util/common.h" +#include -#include "gba/savedata.h" +CXX_GUARD_START + +#include #define IDLE_LOOP_NONE 0xFFFFFFFF @@ -28,4 +30,6 @@ struct GBA; void GBAOverrideApply(struct GBA*, const struct GBACartridgeOverride*); void GBAOverrideApplyDefaults(struct GBA*); +CXX_GUARD_END + #endif diff --git a/src/gba/renderers/thread-proxy.h b/include/mgba/internal/gba/renderers/thread-proxy.h similarity index 84% rename from src/gba/renderers/thread-proxy.h rename to include/mgba/internal/gba/renderers/thread-proxy.h index 3f39176c4..6fa07215a 100644 --- a/src/gba/renderers/thread-proxy.h +++ b/include/mgba/internal/gba/renderers/thread-proxy.h @@ -6,9 +6,13 @@ #ifndef VIDEO_THREAD_PROXY_H #define VIDEO_THREAD_PROXY_H -#include "gba/video.h" -#include "util/threading.h" -#include "util/ring-fifo.h" +#include + +CXX_GUARD_START + +#include +#include +#include enum GBAVideoThreadProxyState { PROXY_THREAD_STOPPED = 0, @@ -38,4 +42,6 @@ struct GBAVideoThreadProxyRenderer { void GBAVideoThreadProxyRendererCreate(struct GBAVideoThreadProxyRenderer* renderer, struct GBAVideoRenderer* backend); +CXX_GUARD_END + #endif diff --git a/src/gba/renderers/tile-cache.h b/include/mgba/internal/gba/renderers/tile-cache.h similarity index 88% rename from src/gba/renderers/tile-cache.h rename to include/mgba/internal/gba/renderers/tile-cache.h index 04463a4ec..3e2143f35 100644 --- a/src/gba/renderers/tile-cache.h +++ b/include/mgba/internal/gba/renderers/tile-cache.h @@ -6,7 +6,9 @@ #ifndef GBA_TILE_CACHE_H #define GBA_TILE_CACHE_H -#include "util/common.h" +#include + +CXX_GUARD_START struct GBAVideo; struct mTileCache; @@ -14,4 +16,6 @@ struct mTileCache; void GBAVideoTileCacheInit(struct mTileCache* cache); void GBAVideoTileCacheAssociate(struct mTileCache* cache, struct GBAVideo* video); +CXX_GUARD_END + #endif diff --git a/src/gba/renderers/video-software.h b/include/mgba/internal/gba/renderers/video-software.h similarity index 95% rename from src/gba/renderers/video-software.h rename to include/mgba/internal/gba/renderers/video-software.h index c6def6d60..ba9db50f7 100644 --- a/src/gba/renderers/video-software.h +++ b/include/mgba/internal/gba/renderers/video-software.h @@ -6,10 +6,12 @@ #ifndef VIDEO_SOFTWARE_H #define VIDEO_SOFTWARE_H -#include "util/common.h" +#include -#include "core/core.h" -#include "gba/video.h" +CXX_GUARD_START + +#include +#include struct GBAVideoSoftwareSprite { struct GBAObj obj; @@ -152,9 +154,7 @@ struct GBAVideoSoftwareRenderer { int oamDirty; int oamMax; - int objwinMax; struct GBAVideoSoftwareSprite sprites[128]; - struct GBAVideoSoftwareSprite objwinSprites[128]; int start; int end; @@ -162,4 +162,6 @@ struct GBAVideoSoftwareRenderer { void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer); +CXX_GUARD_START + #endif diff --git a/src/gba/rr/mgm.h b/include/mgba/internal/gba/rr/mgm.h similarity index 94% rename from src/gba/rr/mgm.h rename to include/mgba/internal/gba/rr/mgm.h index 9c494d50f..fd455a830 100644 --- a/src/gba/rr/mgm.h +++ b/include/mgba/internal/gba/rr/mgm.h @@ -6,9 +6,11 @@ #ifndef RR_MGM_H #define RR_MGM_H -#include "util/common.h" +#include -#include "gba/rr/rr.h" +CXX_GUARD_START + +#include struct GBA; struct VDir; @@ -80,4 +82,6 @@ void GBAMGMContextCreate(struct GBAMGMContext*); bool GBAMGMSetStream(struct GBAMGMContext* mgm, struct VDir* stream); bool GBAMGMCreateStream(struct GBAMGMContext* mgm, enum GBARRInitFrom initFrom); +CXX_GUARD_END + #endif diff --git a/src/gba/rr/rr.h b/include/mgba/internal/gba/rr/rr.h similarity index 92% rename from src/gba/rr/rr.h rename to include/mgba/internal/gba/rr/rr.h index eb2964e1e..b4fc2e627 100644 --- a/src/gba/rr/rr.h +++ b/include/mgba/internal/gba/rr/rr.h @@ -6,10 +6,12 @@ #ifndef GBA_RR_H #define GBA_RR_H -#include "util/common.h" +#include -#include "core/log.h" -#include "gba/serialize.h" +CXX_GUARD_START + +#include +#include struct VFile; @@ -58,4 +60,6 @@ void GBARRDestroy(struct GBARRContext*); void GBARRInitRecord(struct GBA*); void GBARRInitPlay(struct GBA*); +CXX_GUARD_END + #endif diff --git a/src/gba/rr/vbm.h b/include/mgba/internal/gba/rr/vbm.h similarity index 76% rename from src/gba/rr/vbm.h rename to include/mgba/internal/gba/rr/vbm.h index a314b9b0b..66d19b76e 100644 --- a/src/gba/rr/vbm.h +++ b/include/mgba/internal/gba/rr/vbm.h @@ -3,9 +3,14 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/common.h" +#ifndef GBA_VBM_H +#define GBA_VBM_H -#include "gba/rr/rr.h" +#include + +CXX_GUARD_START + +#include struct GBAVBMContext { struct GBARRContext d; @@ -19,3 +24,7 @@ struct GBAVBMContext { void GBAVBMContextCreate(struct GBAVBMContext*); bool GBAVBMSetStream(struct GBAVBMContext*, struct VFile*); + +CXX_GUARD_END + +#endif diff --git a/src/gba/savedata.h b/include/mgba/internal/gba/savedata.h similarity index 97% rename from src/gba/savedata.h rename to include/mgba/internal/gba/savedata.h index 98feb52b4..2b0bbfe38 100644 --- a/src/gba/savedata.h +++ b/include/mgba/internal/gba/savedata.h @@ -6,9 +6,11 @@ #ifndef GBA_SAVEDATA_H #define GBA_SAVEDATA_H -#include "util/common.h" +#include -#include "core/log.h" +CXX_GUARD_START + +#include mLOG_DECLARE_CATEGORY(GBA_SAVE); @@ -119,4 +121,6 @@ struct GBASerializedState; void GBASavedataSerialize(const struct GBASavedata* savedata, struct GBASerializedState* state); void GBASavedataDeserialize(struct GBASavedata* savedata, const struct GBASerializedState* state); +CXX_GUARD_END + #endif diff --git a/src/gba/serialize.h b/include/mgba/internal/gba/serialize.h similarity index 98% rename from src/gba/serialize.h rename to include/mgba/internal/gba/serialize.h index 6db9eec1e..fd2c191b0 100644 --- a/src/gba/serialize.h +++ b/include/mgba/internal/gba/serialize.h @@ -6,11 +6,13 @@ #ifndef GBA_SERIALIZE_H #define GBA_SERIALIZE_H -#include "util/common.h" +#include -#include "core/core.h" -#include "gba/gba.h" -#include "gb/serialize.h" +CXX_GUARD_START + +#include +#include +#include extern const uint32_t GBA_SAVESTATE_MAGIC; extern const uint32_t GBA_SAVESTATE_VERSION; @@ -333,4 +335,6 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state); struct GBASerializedState* GBAAllocateState(void); void GBADeallocateState(struct GBASerializedState* state); +CXX_GUARD_END + #endif diff --git a/src/gba/sharkport.h b/include/mgba/internal/gba/sharkport.h similarity index 88% rename from src/gba/sharkport.h rename to include/mgba/internal/gba/sharkport.h index 520ec246e..361d4eb44 100644 --- a/src/gba/sharkport.h +++ b/include/mgba/internal/gba/sharkport.h @@ -6,7 +6,9 @@ #ifndef GBA_SHARKPORT_H #define GBA_SHARKPORT_H -#include "util/common.h" +#include + +CXX_GUARD_START struct GBA; struct VFile; @@ -14,4 +16,6 @@ struct VFile; bool GBASavedataImportSharkPort(struct GBA* gba, struct VFile* vf, bool testChecksum); bool GBASavedataExportSharkPort(const struct GBA* gba, struct VFile* vf); +CXX_GUARD_END + #endif diff --git a/src/gba/sio.h b/include/mgba/internal/gba/sio.h similarity index 86% rename from src/gba/sio.h rename to include/mgba/internal/gba/sio.h index d9cfc83f0..d7b702edb 100644 --- a/src/gba/sio.h +++ b/include/mgba/internal/gba/sio.h @@ -6,10 +6,12 @@ #ifndef GBA_SIO_H #define GBA_SIO_H -#include "util/common.h" +#include -#include "core/log.h" -#include "gba/interface.h" +CXX_GUARD_START + +#include +#include #define MAX_GBAS 4 @@ -21,6 +23,16 @@ enum { RCNT_INITIAL = 0x8000 }; +enum { + JOY_CMD_RESET = 0xFF, + JOY_CMD_POLL = 0x00, + JOY_CMD_TRANS = 0x14, + JOY_CMD_RECV = 0x15, + + JOYSTAT_TRANS_BIT = 8, + JOYSTAT_RECV_BIT = 2, +}; + struct GBASIODriverSet { struct GBASIODriver* normal; struct GBASIODriver* multiplayer; @@ -78,4 +90,6 @@ void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value); void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value); uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t value); +CXX_GUARD_END + #endif diff --git a/src/gba/sio/lockstep.h b/include/mgba/internal/gba/sio/lockstep.h similarity index 57% rename from src/gba/sio/lockstep.h rename to include/mgba/internal/gba/sio/lockstep.h index 6da3d0dc3..13c181039 100644 --- a/src/gba/sio/lockstep.h +++ b/include/mgba/internal/gba/sio/lockstep.h @@ -3,40 +3,25 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef SIO_LOCKSTEP_H -#define SIO_LOCKSTEP_H +#ifndef GBA_SIO_LOCKSTEP_H +#define GBA_SIO_LOCKSTEP_H -#include "core/timing.h" -#include "gba/sio.h" +#include -enum GBASIOLockstepPhase { - TRANSFER_IDLE = 0, - TRANSFER_STARTING, - TRANSFER_STARTED, - TRANSFER_FINISHING, - TRANSFER_FINISHED -}; +CXX_GUARD_START + +#include +#include +#include struct GBASIOLockstep { + struct mLockstep d; struct GBASIOLockstepNode* players[MAX_GBAS]; - int attached; int attachedMulti; int attachedNormal; uint16_t multiRecv[MAX_GBAS]; uint32_t normalRecv[MAX_GBAS]; - enum GBASIOLockstepPhase transferActive; - int32_t transferCycles; - - bool (*signal)(struct GBASIOLockstep*, unsigned mask); - bool (*wait)(struct GBASIOLockstep*, unsigned mask); - void (*addCycles)(struct GBASIOLockstep*, int id, int32_t cycles); - int32_t (*useCycles)(struct GBASIOLockstep*, int id, int32_t cycles); - void (*unload)(struct GBASIOLockstep*, int id); - void* context; -#ifndef NDEBUG - int transferId; -#endif }; struct GBASIOLockstepNode { @@ -52,16 +37,17 @@ struct GBASIOLockstepNode { bool transferFinished; #ifndef NDEBUG int transferId; - enum GBASIOLockstepPhase phase; + enum mLockstepPhase phase; #endif }; void GBASIOLockstepInit(struct GBASIOLockstep*); -void GBASIOLockstepDeinit(struct GBASIOLockstep*); void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode*); bool GBASIOLockstepAttachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*); void GBASIOLockstepDetachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*); +CXX_GUARD_END + #endif diff --git a/src/gba/timer.h b/include/mgba/internal/gba/timer.h similarity index 90% rename from src/gba/timer.h rename to include/mgba/internal/gba/timer.h index 08314a4cf..d031f3d4f 100644 --- a/src/gba/timer.h +++ b/include/mgba/internal/gba/timer.h @@ -6,8 +6,11 @@ #ifndef GBA_TIMER_H #define GBA_TIMER_H -#include "util/common.h" -#include "core/timing.h" +#include + +CXX_GUARD_START + +#include DECL_BITFIELD(GBATimerFlags, uint32_t); DECL_BITS(GBATimerFlags, PrescaleBits, 0, 4); @@ -30,4 +33,6 @@ void GBATimerUpdateRegister(struct GBA* gba, int timer); void GBATimerWriteTMCNT_LO(struct GBA* gba, int timer, uint16_t value); void GBATimerWriteTMCNT_HI(struct GBA* gba, int timer, uint16_t value); +CXX_GUARD_END + #endif diff --git a/src/gba/vfame.h b/include/mgba/internal/gba/vfame.h similarity index 94% rename from src/gba/vfame.h rename to include/mgba/internal/gba/vfame.h index d418f7a9b..eff24a039 100644 --- a/src/gba/vfame.h +++ b/include/mgba/internal/gba/vfame.h @@ -9,7 +9,9 @@ #ifndef GBA_VFAME_H #define GBA_VFAME_H -#include "util/common.h" +#include + +CXX_GUARD_START enum GBAVFameCartType { VFAME_NO = 0, @@ -31,4 +33,6 @@ void GBAVFameSramWrite(struct GBAVFameCart* cart, uint32_t address, uint8_t valu uint32_t GBAVFameModifyRomAddress(struct GBAVFameCart* cart, uint32_t address, size_t romSize); uint32_t GBAVFameGetPatternValue(uint32_t address, int bits); +CXX_GUARD_END + #endif diff --git a/src/gba/video.h b/include/mgba/internal/gba/video.h similarity index 94% rename from src/gba/video.h rename to include/mgba/internal/gba/video.h index da9f85848..3a1aa14e8 100644 --- a/src/gba/video.h +++ b/include/mgba/internal/gba/video.h @@ -6,11 +6,12 @@ #ifndef GBA_VIDEO_H #define GBA_VIDEO_H -#include "util/common.h" +#include -#include "core/core.h" -#include "core/timing.h" -#include "gba/memory.h" +CXX_GUARD_START + +#include +#include mLOG_DECLARE_CATEGORY(GBA_VIDEO); @@ -19,13 +20,13 @@ enum { VIDEO_HBLANK_PIXELS = 68, VIDEO_HDRAW_LENGTH = 1006, VIDEO_HBLANK_LENGTH = 226, - VIDEO_HORIZONTAL_LENGTH = VIDEO_HDRAW_LENGTH + VIDEO_HBLANK_LENGTH, + VIDEO_HORIZONTAL_LENGTH = 1232, VIDEO_VERTICAL_PIXELS = 160, VIDEO_VBLANK_PIXELS = 68, - VIDEO_VERTICAL_TOTAL_PIXELS = VIDEO_VERTICAL_PIXELS + VIDEO_VBLANK_PIXELS, + VIDEO_VERTICAL_TOTAL_PIXELS = 228, - VIDEO_TOTAL_LENGTH = VIDEO_HORIZONTAL_LENGTH * VIDEO_VERTICAL_TOTAL_PIXELS, + VIDEO_TOTAL_LENGTH = 280896, OBJ_HBLANK_FREE_LENGTH = 954, OBJ_LENGTH = 1210, @@ -177,7 +178,7 @@ struct GBAVideo { // VCOUNT int vcount; - uint16_t palette[SIZE_PALETTE_RAM >> 1]; + uint16_t palette[512]; uint16_t* vram; union GBAOAM oam; @@ -199,4 +200,6 @@ void GBAVideoDeserialize(struct GBAVideo* video, const struct GBASerializedState extern const int GBAVideoObjSizes[16][2]; +CXX_GUARD_END + #endif diff --git a/src/lr35902/debugger/cli-debugger.h b/include/mgba/internal/lr35902/debugger/cli-debugger.h similarity index 86% rename from src/lr35902/debugger/cli-debugger.h rename to include/mgba/internal/lr35902/debugger/cli-debugger.h index 5e6a8b1a3..995f10649 100644 --- a/src/lr35902/debugger/cli-debugger.h +++ b/include/mgba/internal/lr35902/debugger/cli-debugger.h @@ -6,9 +6,13 @@ #ifndef LR35902_CLI_DEBUGGER_H #define LR35902_CLI_DEBUGGER_H -#include "util/common.h" +#include + +CXX_GUARD_START struct CLIDebuggerSystem; void LR35902CLIDebuggerCreate(struct CLIDebuggerSystem* debugger); +CXX_GUARD_END + #endif diff --git a/src/lr35902/debugger/debugger.h b/include/mgba/internal/lr35902/debugger/debugger.h similarity index 82% rename from src/lr35902/debugger/debugger.h rename to include/mgba/internal/lr35902/debugger/debugger.h index 53e022c30..06801d77b 100644 --- a/src/lr35902/debugger/debugger.h +++ b/include/mgba/internal/lr35902/debugger/debugger.h @@ -3,7 +3,14 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "debugger/debugger.h" +#ifndef LR35902_DEBUGGER_H +#define LR35902_DEBUGGER_H + +#include + +CXX_GUARD_START + +#include struct LR35902DebugBreakpoint { uint16_t address; @@ -28,3 +35,7 @@ struct LR35902Debugger { }; struct mDebuggerPlatform* LR35902DebuggerPlatformCreate(void); + +CXX_GUARD_END + +#endif diff --git a/src/lr35902/emitter-lr35902.h b/include/mgba/internal/lr35902/emitter-lr35902.h similarity index 100% rename from src/lr35902/emitter-lr35902.h rename to include/mgba/internal/lr35902/emitter-lr35902.h diff --git a/src/lr35902/isa-lr35902.h b/include/mgba/internal/lr35902/isa-lr35902.h similarity index 87% rename from src/lr35902/isa-lr35902.h rename to include/mgba/internal/lr35902/isa-lr35902.h index 0b73c8deb..151524a43 100644 --- a/src/lr35902/isa-lr35902.h +++ b/include/mgba/internal/lr35902/isa-lr35902.h @@ -6,11 +6,15 @@ #ifndef ISA_LR35902_H #define ISA_LR35902_H -#include "util/common.h" +#include + +CXX_GUARD_START struct LR35902Core; typedef void (*LR35902Instruction)(struct LR35902Core*); extern const LR35902Instruction _lr35902InstructionTable[0x100]; +CXX_GUARD_END + #endif diff --git a/src/lr35902/lr35902.h b/include/mgba/internal/lr35902/lr35902.h similarity index 78% rename from src/lr35902/lr35902.h rename to include/mgba/internal/lr35902/lr35902.h index 84eddfb73..59811cc8b 100644 --- a/src/lr35902/lr35902.h +++ b/include/mgba/internal/lr35902/lr35902.h @@ -6,10 +6,12 @@ #ifndef LR35902_H #define LR35902_H -#include "util/common.h" +#include -#include "core/cpu.h" -#include "lr35902/isa-lr35902.h" +CXX_GUARD_START + +#include +#include struct LR35902Core; @@ -21,9 +23,9 @@ union FlagRegister { unsigned n : 1; unsigned h : 1; unsigned c : 1; - unsigned : 4; + unsigned unused : 4; #else - unsigned : 4; + unsigned unused : 4; unsigned c : 1; unsigned h : 1; unsigned n : 1; @@ -125,36 +127,6 @@ struct LR35902Core { struct mCPUComponent** components; }; -static inline uint16_t LR35902ReadHL(struct LR35902Core* cpu) { - uint16_t hl; - LOAD_16LE(hl, 0, &cpu->hl); - return hl; -} - -static inline void LR35902WriteHL(struct LR35902Core* cpu, uint16_t hl) { - STORE_16LE(hl, 0, &cpu->hl); -} - -static inline uint16_t LR35902ReadBC(struct LR35902Core* cpu) { - uint16_t bc; - LOAD_16LE(bc, 0, &cpu->bc); - return bc; -} - -static inline void LR35902WriteBC(struct LR35902Core* cpu, uint16_t bc) { - STORE_16LE(bc, 0, &cpu->bc); -} - -static inline uint16_t LR35902ReadDE(struct LR35902Core* cpu) { - uint16_t de; - LOAD_16LE(de, 0, &cpu->de); - return de; -} - -static inline void LR35902WriteDE(struct LR35902Core* cpu, uint16_t de) { - STORE_16LE(de, 0, &cpu->de); -} - void LR35902Init(struct LR35902Core* cpu); void LR35902Deinit(struct LR35902Core* cpu); void LR35902SetComponents(struct LR35902Core* cpu, struct mCPUComponent* master, int extra, struct mCPUComponent** extras); @@ -167,4 +139,6 @@ void LR35902RaiseIRQ(struct LR35902Core* cpu, uint8_t vector); void LR35902Tick(struct LR35902Core* cpu); void LR35902Run(struct LR35902Core* cpu); +CXX_GUARD_END + #endif diff --git a/src/arm/arm.c b/src/arm/arm.c index 09cfb06b9..dc6714681 100644 --- a/src/arm/arm.c +++ b/src/arm/arm.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "arm.h" +#include -#include "arm/isa-arm.h" -#include "arm/isa-inlines.h" -#include "arm/isa-thumb.h" +#include +#include +#include static inline enum RegisterBank _ARMSelectBank(enum PrivilegeMode); diff --git a/src/arm/debugger/cli-debugger.c b/src/arm/debugger/cli-debugger.c index dbee4c538..87a1655c5 100644 --- a/src/arm/debugger/cli-debugger.c +++ b/src/arm/debugger/cli-debugger.c @@ -3,13 +3,13 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "cli-debugger.h" +#include -#include "arm/debugger/debugger.h" -#include "arm/debugger/memory-debugger.h" -#include "arm/decoder.h" -#include "core/core.h" -#include "debugger/cli-debugger.h" +#include +#include +#include +#include +#include static void _printStatus(struct CLIDebuggerSystem*); diff --git a/src/arm/debugger/debugger.c b/src/arm/debugger/debugger.c index ba9204726..76b474841 100644 --- a/src/arm/debugger/debugger.c +++ b/src/arm/debugger/debugger.c @@ -3,12 +3,12 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "debugger.h" +#include -#include "arm/arm.h" -#include "arm/isa-inlines.h" -#include "arm/debugger/memory-debugger.h" -#include "core/core.h" +#include +#include +#include +#include DEFINE_VECTOR(ARMDebugBreakpointList, struct ARMDebugBreakpoint); DEFINE_VECTOR(ARMDebugWatchpointList, struct ARMDebugWatchpoint); diff --git a/src/arm/debugger/memory-debugger.c b/src/arm/debugger/memory-debugger.c index 2844af5e6..faa8651f4 100644 --- a/src/arm/debugger/memory-debugger.c +++ b/src/arm/debugger/memory-debugger.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "memory-debugger.h" +#include -#include "arm/debugger/debugger.h" +#include -#include "util/math.h" +#include #include diff --git a/src/arm/decoder-arm.c b/src/arm/decoder-arm.c index 3b3d81b8f..2b7b61251 100644 --- a/src/arm/decoder-arm.c +++ b/src/arm/decoder-arm.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "decoder.h" +#include -#include "decoder-inlines.h" -#include "emitter-arm.h" -#include "isa-inlines.h" +#include +#include +#include #define ADDR_MODE_1_SHIFT(OP) \ info->op3.reg = opcode & 0x0000000F; \ diff --git a/src/arm/decoder-thumb.c b/src/arm/decoder-thumb.c index 707324023..a53da00e9 100644 --- a/src/arm/decoder-thumb.c +++ b/src/arm/decoder-thumb.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "decoder.h" +#include -#include "decoder-inlines.h" -#include "emitter-thumb.h" -#include "isa-inlines.h" +#include +#include +#include #define DEFINE_THUMB_DECODER(NAME, MNEMONIC, BODY) \ static void _ThumbDecode ## NAME (uint16_t opcode, struct ARMInstructionInfo* info) { \ diff --git a/src/arm/decoder.c b/src/arm/decoder.c index 98caeeac5..32e92f23a 100644 --- a/src/arm/decoder.c +++ b/src/arm/decoder.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "decoder.h" +#include -#include "decoder-inlines.h" +#include #define ADVANCE(AMOUNT) \ if (AMOUNT > blen) { \ diff --git a/src/arm/isa-arm.c b/src/arm/isa-arm.c index 443eb7a49..d49c3e3c6 100644 --- a/src/arm/isa-arm.c +++ b/src/arm/isa-arm.c @@ -3,12 +3,12 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "isa-arm.h" +#include -#include "arm.h" -#include "emitter-arm.h" -#include "isa-inlines.h" -#include "util/math.h" +#include +#include +#include +#include #define PSR_USER_MASK 0xF0000000 #define PSR_PRIV_MASK 0x000000CF @@ -317,11 +317,10 @@ static inline void _immediate(struct ARMCore* cpu, uint32_t opcode) { #define DEFINE_MULTIPLY_INSTRUCTION_EX_ARM(NAME, BODY, S_BODY) \ DEFINE_INSTRUCTION_ARM(NAME, \ - int rd = (opcode >> 12) & 0xF; \ - int rdHi = (opcode >> 16) & 0xF; \ + int rd = (opcode >> 16) & 0xF; \ int rs = (opcode >> 8) & 0xF; \ int rm = opcode & 0xF; \ - if (rdHi == ARM_PC || rd == ARM_PC) { \ + if (rd == ARM_PC) { \ return; \ } \ ARM_WAIT_MUL(cpu->gprs[rs]); \ @@ -329,10 +328,28 @@ static inline void _immediate(struct ARMCore* cpu, uint32_t opcode) { S_BODY; \ currentCycles += cpu->memory.activeNonseqCycles32 - cpu->memory.activeSeqCycles32) +#define DEFINE_MULTIPLY_INSTRUCTION_2_EX_ARM(NAME, BODY, S_BODY, WAIT) \ + DEFINE_INSTRUCTION_ARM(NAME, \ + int rd = (opcode >> 12) & 0xF; \ + int rdHi = (opcode >> 16) & 0xF; \ + int rs = (opcode >> 8) & 0xF; \ + int rm = opcode & 0xF; \ + if (rdHi == ARM_PC || rd == ARM_PC) { \ + return; \ + } \ + currentCycles += cpu->memory.stall(cpu, WAIT); \ + BODY; \ + S_BODY; \ + currentCycles += cpu->memory.activeNonseqCycles32 - cpu->memory.activeSeqCycles32) + #define DEFINE_MULTIPLY_INSTRUCTION_ARM(NAME, BODY, S_BODY) \ DEFINE_MULTIPLY_INSTRUCTION_EX_ARM(NAME, BODY, ) \ DEFINE_MULTIPLY_INSTRUCTION_EX_ARM(NAME ## S, BODY, S_BODY) +#define DEFINE_MULTIPLY_INSTRUCTION_2_ARM(NAME, BODY, S_BODY, WAIT) \ + DEFINE_MULTIPLY_INSTRUCTION_2_EX_ARM(NAME, BODY, , WAIT) \ + DEFINE_MULTIPLY_INSTRUCTION_2_EX_ARM(NAME ## S, BODY, S_BODY, WAIT) + #define DEFINE_LOAD_STORE_INSTRUCTION_EX_ARM(NAME, ADDRESS, WRITEBACK, BODY) \ DEFINE_INSTRUCTION_ARM(NAME, \ uint32_t address; \ @@ -486,36 +503,36 @@ DEFINE_ALU_INSTRUCTION_S_ONLY_ARM(TST, ARM_NEUTRAL_S(cpu->gprs[rn], cpu->shifter // Begin multiply definitions -DEFINE_MULTIPLY_INSTRUCTION_ARM(MLA, cpu->gprs[rdHi] = cpu->gprs[rm] * cpu->gprs[rs] + cpu->gprs[rd], ARM_NEUTRAL_S(, , cpu->gprs[rdHi])) -DEFINE_MULTIPLY_INSTRUCTION_ARM(MUL, cpu->gprs[rdHi] = cpu->gprs[rm] * cpu->gprs[rs], ARM_NEUTRAL_S(cpu->gprs[rm], cpu->gprs[rs], cpu->gprs[rdHi])) +DEFINE_MULTIPLY_INSTRUCTION_2_ARM(MLA, cpu->gprs[rdHi] = cpu->gprs[rm] * cpu->gprs[rs] + cpu->gprs[rd], ARM_NEUTRAL_S(, , cpu->gprs[rdHi]), 2) +DEFINE_MULTIPLY_INSTRUCTION_ARM(MUL, cpu->gprs[rd] = cpu->gprs[rm] * cpu->gprs[rs], ARM_NEUTRAL_S(cpu->gprs[rm], cpu->gprs[rs], cpu->gprs[rd])) -DEFINE_MULTIPLY_INSTRUCTION_ARM(SMLAL, +DEFINE_MULTIPLY_INSTRUCTION_2_ARM(SMLAL, int64_t d = ((int64_t) cpu->gprs[rm]) * ((int64_t) cpu->gprs[rs]); int32_t dm = cpu->gprs[rd]; int32_t dn = d; cpu->gprs[rd] = dm + dn; cpu->gprs[rdHi] = cpu->gprs[rdHi] + (d >> 32) + ARM_CARRY_FROM(dm, dn, cpu->gprs[rd]);, - ARM_NEUTRAL_HI_S(cpu->gprs[rd], cpu->gprs[rdHi])) + ARM_NEUTRAL_HI_S(cpu->gprs[rd], cpu->gprs[rdHi]), 3) -DEFINE_MULTIPLY_INSTRUCTION_ARM(SMULL, +DEFINE_MULTIPLY_INSTRUCTION_2_ARM(SMULL, int64_t d = ((int64_t) cpu->gprs[rm]) * ((int64_t) cpu->gprs[rs]); cpu->gprs[rd] = d; cpu->gprs[rdHi] = d >> 32;, - ARM_NEUTRAL_HI_S(cpu->gprs[rd], cpu->gprs[rdHi])) + ARM_NEUTRAL_HI_S(cpu->gprs[rd], cpu->gprs[rdHi]), 2) -DEFINE_MULTIPLY_INSTRUCTION_ARM(UMLAL, +DEFINE_MULTIPLY_INSTRUCTION_2_ARM(UMLAL, uint64_t d = ARM_UXT_64(cpu->gprs[rm]) * ARM_UXT_64(cpu->gprs[rs]); int32_t dm = cpu->gprs[rd]; int32_t dn = d; cpu->gprs[rd] = dm + dn; cpu->gprs[rdHi] = cpu->gprs[rdHi] + (d >> 32) + ARM_CARRY_FROM(dm, dn, cpu->gprs[rd]);, - ARM_NEUTRAL_HI_S(cpu->gprs[rd], cpu->gprs[rdHi])) + ARM_NEUTRAL_HI_S(cpu->gprs[rd], cpu->gprs[rdHi]), 3) -DEFINE_MULTIPLY_INSTRUCTION_ARM(UMULL, +DEFINE_MULTIPLY_INSTRUCTION_2_ARM(UMULL, uint64_t d = ARM_UXT_64(cpu->gprs[rm]) * ARM_UXT_64(cpu->gprs[rs]); cpu->gprs[rd] = d; cpu->gprs[rdHi] = d >> 32;, - ARM_NEUTRAL_HI_S(cpu->gprs[rd], cpu->gprs[rdHi])) + ARM_NEUTRAL_HI_S(cpu->gprs[rd], cpu->gprs[rdHi]), 2) // End multiply definitions diff --git a/src/arm/isa-thumb.c b/src/arm/isa-thumb.c index 7c587f618..54faf6ddc 100644 --- a/src/arm/isa-thumb.c +++ b/src/arm/isa-thumb.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "isa-thumb.h" +#include -#include "isa-inlines.h" -#include "emitter-thumb.h" +#include +#include // Instruction definitions // Beware pre-processor insanity diff --git a/src/core/cheats.c b/src/core/cheats.c index efcbf4aa0..fe6e59c99 100644 --- a/src/core/cheats.c +++ b/src/core/cheats.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "cheats.h" +#include -#include "core/core.h" -#include "util/string.h" -#include "util/vfs.h" +#include +#include +#include #define MAX_LINE_LENGTH 128 diff --git a/src/core/config.c b/src/core/config.c index d66baddb3..0a2d146b3 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -3,12 +3,12 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "config.h" +#include -#include "core/version.h" -#include "util/formatting.h" -#include "util/string.h" -#include "util/vfs.h" +#include +#include +#include +#include #include @@ -24,7 +24,7 @@ #endif #ifdef _3DS -#include "platform/3ds/3ds-vfs.h" +#include #endif #define SECTION_NAME_MAX 128 diff --git a/src/core/core.c b/src/core/core.c index d14bf1745..5c266e25f 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -3,23 +3,24 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "core.h" +#include -#include "core/log.h" -#include "core/serialize.h" -#include "util/vfs.h" +#include +#include +#include #ifdef M_CORE_GB -#include "gb/core.h" -#include "gb/gb.h" +#include +// TODO: Fix layering violation +#include #endif #ifdef M_CORE_GBA -#include "gba/core.h" -#include "gba/gba.h" +#include +#include #endif #ifdef M_CORE_DS -#include "ds/core.h" -#include "ds/ds.h" +#include +#include #endif static struct mCoreFilter { @@ -69,7 +70,7 @@ enum mPlatform mCoreIsCompatible(struct VFile* vf) { } #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 -#include "util/png-io.h" +#include #ifdef PSP2 #include diff --git a/src/core/directories.c b/src/core/directories.c index db4ec1b26..ca261dbd9 100644 --- a/src/core/directories.c +++ b/src/core/directories.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "directories.h" +#include -#include "core/config.h" -#include "util/vfs.h" +#include +#include #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 void mDirectorySetInit(struct mDirectorySet* dirs) { diff --git a/src/core/flags.h.in b/src/core/flags.h.in new file mode 100644 index 000000000..aa2236dd1 --- /dev/null +++ b/src/core/flags.h.in @@ -0,0 +1,96 @@ +#ifndef FLAGS_H +#define FLAGS_H + +#ifndef MINIMAL_CORE +#cmakedefine MINIMAL_CORE @MINIMAL_CORE@ +#endif + +// BUILD flags + +#ifndef BUILD_GL +#cmakedefine BUILD_GL +#endif + +#ifndef BUILD_GLES2 +#cmakedefine BUILD_GLES2 +#endif + +// COLOR flags + +#ifndef COLOR_16_BIT +#cmakedefine COLOR_16_BIT +#endif + +#ifndef COLOR_5_6_5 +#cmakedefine COLOR_5_6_5 +#endif + +// M_CORE flags + +#ifndef M_CORE_GBA +#cmakedefine M_CORE_GBA +#endif + +#ifndef M_CORE_GB +#cmakedefine M_CORE_GB +#endif + +// USE flags + +#ifndef MINIMAL_CORE + +#ifndef USE_DEBUGGERS +#cmakedefine USE_DEBUGGERS +#endif + +#ifndef USE_EDITLINE +#cmakedefine USE_EDITLINE +#endif + +#ifndef USE_EPOXY +#cmakedefine USE_EPOXY +#endif + +#ifndef USE_FFMPEG +#cmakedefine USE_FFMPEG +#endif + +#ifndef USE_GDB_STUB +#cmakedefine USE_GDB_STUB +#endif + +#ifndef USE_LIBAV +#cmakedefine USE_LIBAV +#endif + +#ifndef USE_LIBZIP +#cmakedefine USE_LIBZIP +#endif + +#ifndef USE_LZMA +#cmakedefine USE_LZMA +#endif + +#ifndef USE_MAGICK +#cmakedefine USE_MAGICK +#endif + +#ifndef USE_MINIZIP +#cmakedefine USE_MINIZIP +#endif + +#ifndef USE_PNG +#cmakedefine USE_PNG +#endif + +#ifndef USE_PTHREADS +#cmakedefine USE_PTHREADS +#endif + +#ifndef USE_ZLIB +#cmakedefine USE_ZLIB +#endif + +#endif + +#endif diff --git a/src/core/input.c b/src/core/input.c index 4614e3549..86145f176 100644 --- a/src/core/input.c +++ b/src/core/input.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "input.h" +#include -#include "util/configuration.h" -#include "util/table.h" +#include +#include #include diff --git a/src/core/interface.c b/src/core/interface.c index 272afd948..66b372800 100644 --- a/src/core/interface.c +++ b/src/core/interface.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "interface.h" +#include -#include "core/core.h" +#include #include static time_t _rtcGenericCallback(struct mRTCSource* source) { diff --git a/src/core/library.c b/src/core/library.c index 995772cf9..425405bac 100644 --- a/src/core/library.c +++ b/src/core/library.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "library.h" +#include -#include "util/vfs.h" +#include DEFINE_VECTOR(mLibraryListing, struct mLibraryEntry); diff --git a/src/core/lockstep.c b/src/core/lockstep.c new file mode 100644 index 000000000..40b1f1e2e --- /dev/null +++ b/src/core/lockstep.c @@ -0,0 +1,16 @@ +/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + +void mLockstepInit(struct mLockstep* lockstep) { + lockstep->attached = 0; + lockstep->transferActive = 0; +#ifndef NDEBUG + lockstep->transferId = 0; +#endif +} + +// TODO: Migrate nodes diff --git a/src/core/log.c b/src/core/log.c index 880379fd9..65ec99924 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "log.h" +#include -#include "core/thread.h" +#include #define MAX_CATEGORY 64 @@ -44,4 +44,18 @@ const char* mLogCategoryName(int category) { return 0; } +void mLog(int category, enum mLogLevel level, const char* format, ...) { + struct mLogger* context = mLogGetContext(); + va_list args; + va_start(args, format); + if (context) { + context->log(context, category, level, format, args); + } else { + printf("%s: ", mLogCategoryName(category)); + vprintf(format, args); + printf("\n"); + } + va_end(args); +} + mLOG_DEFINE_CATEGORY(STATUS, "Status") diff --git a/src/core/rewind.c b/src/core/rewind.c index e48b2eb8b..56a59e47d 100644 --- a/src/core/rewind.c +++ b/src/core/rewind.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "rewind.h" +#include -#include "core/core.h" -#include "util/patch-fast.h" -#include "util/vfs.h" +#include +#include +#include DEFINE_VECTOR(mCoreRewindPatches, struct PatchFast); diff --git a/src/core/serialize.c b/src/core/serialize.c index 14a3795ac..f5b143fec 100644 --- a/src/core/serialize.c +++ b/src/core/serialize.c @@ -3,15 +3,15 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "serialize.h" +#include -#include "core/core.h" -#include "core/cheats.h" -#include "util/memory.h" -#include "util/vfs.h" +#include +#include +#include +#include #ifdef USE_PNG -#include "util/png-io.h" +#include #include #include #endif diff --git a/src/core/sync.c b/src/core/sync.c index 640628024..5fc5e72d9 100644 --- a/src/core/sync.c +++ b/src/core/sync.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "sync.h" +#include static void _changeVideoSync(struct mCoreSync* sync, bool frameOn) { // Make sure the video thread can process events while the GBA thread is paused diff --git a/src/core/test/core.c b/src/core/test/core.c index 12f67a900..3fcebaf31 100644 --- a/src/core/test/core.c +++ b/src/core/test/core.c @@ -5,8 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/test/suite.h" -#include "core/core.h" -#include "util/vfs.h" +#include +#include #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 M_TEST_DEFINE(findNullPath) { diff --git a/src/core/test/core.h b/src/core/test/core.h index f5cbd16a0..add2a4c02 100644 --- a/src/core/test/core.h +++ b/src/core/test/core.h @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef TEST_M_CORE_H #define TEST_M_CORE_H -#include "util/common.h" +#include int TestRunCore(void); diff --git a/src/core/thread.c b/src/core/thread.c index 4c7eb90eb..f3509071e 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -3,13 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "thread.h" +#include -#include "core/core.h" -#include "util/patch.h" -#include "util/vfs.h" - -#include "feature/commandline.h" +#include +#include +#include #include diff --git a/src/core/tile-cache.c b/src/core/tile-cache.c index 17572fe0b..85c2f7032 100644 --- a/src/core/tile-cache.c +++ b/src/core/tile-cache.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "tile-cache.h" +#include -#include "util/memory.h" +#include void mTileCacheInit(struct mTileCache* cache) { // TODO: Reconfigurable cache for space savings diff --git a/src/core/timing.c b/src/core/timing.c index 384d92617..d7e7653bd 100644 --- a/src/core/timing.c +++ b/src/core/timing.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "timing.h" +#include void mTimingInit(struct mTiming* timing, int32_t* relativeCycles, int32_t* nextEvent) { timing->root = NULL; diff --git a/src/core/version.c.in b/src/core/version.c.in index 98fcd6428..b8c87fb70 100644 --- a/src/core/version.c.in +++ b/src/core/version.c.in @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "core/version.h" +#include const char* const gitCommit = "${GIT_COMMIT}"; const char* const gitCommitShort = "${GIT_COMMIT_SHORT}"; diff --git a/src/debugger/cli-debugger.c b/src/debugger/cli-debugger.c index 8f5a7d6b6..d5b6dc535 100644 --- a/src/debugger/cli-debugger.c +++ b/src/debugger/cli-debugger.c @@ -3,12 +3,12 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "cli-debugger.h" +#include -#include "core/core.h" -#include "core/version.h" -#include "debugger/parser.h" -#include "util/string.h" +#include +#include +#include +#include #if !defined(NDEBUG) && !defined(_WIN32) #include diff --git a/src/debugger/debugger.c b/src/debugger/debugger.c index 6ddbc7dcb..0e7e3fc1a 100644 --- a/src/debugger/debugger.c +++ b/src/debugger/debugger.c @@ -3,14 +3,14 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "debugger.h" +#include -#include "core/core.h" +#include -#include "debugger/cli-debugger.h" +#include #ifdef USE_GDB_STUB -#include "debugger/gdb-stub.h" +#include #endif const uint32_t DEBUGGER_ID = 0xDEADBEEF; diff --git a/src/debugger/gdb-stub.c b/src/debugger/gdb-stub.c index 227418176..b497c24d7 100644 --- a/src/debugger/gdb-stub.c +++ b/src/debugger/gdb-stub.c @@ -3,12 +3,12 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "gdb-stub.h" +#include -#include "arm/debugger/debugger.h" -#include "arm/isa-inlines.h" -#include "core/core.h" -#include "gba/memory.h" +#include +#include +#include +#include #include diff --git a/src/debugger/parser.c b/src/debugger/parser.c index 4d3cfd6b2..a755af505 100644 --- a/src/debugger/parser.c +++ b/src/debugger/parser.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "parser.h" +#include -#include "util/string.h" +#include static struct LexVector* _lexOperator(struct LexVector* lv, char operator) { struct LexVector* lvNext = malloc(sizeof(struct LexVector)); diff --git a/src/ds/bios.c b/src/ds/bios.c index 5641a837b..de8e3cfbd 100644 --- a/src/ds/bios.c +++ b/src/ds/bios.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "bios.h" +#include -#include "arm/arm.h" +#include mLOG_DEFINE_CATEGORY(DS_BIOS, "DS BIOS"); diff --git a/src/ds/core.c b/src/ds/core.c index 58bcb271f..5b0b1efcd 100644 --- a/src/ds/core.c +++ b/src/ds/core.c @@ -3,17 +3,17 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "core.h" +#include -#include "core/cheats.h" -#include "core/core.h" -#include "core/log.h" -#include "arm/debugger/debugger.h" -#include "ds/ds.h" -#include "ds/extra/cli.h" -#include "util/memory.h" -#include "util/patch.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #define SLICE_CYCLES 2048 diff --git a/src/ds/ds.c b/src/ds/ds.c index c8f0837f9..89f751fdd 100644 --- a/src/ds/ds.c +++ b/src/ds/ds.c @@ -3,17 +3,17 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "ds.h" +#include -#include "arm/decoder.h" -#include "arm/debugger/debugger.h" -#include "arm/isa-inlines.h" -#include "ds/bios.h" +#include +#include +#include +#include -#include "util/crc32.h" -#include "util/memory.h" -#include "util/math.h" -#include "util/vfs.h" +#include +#include +#include +#include mLOG_DEFINE_CATEGORY(DS, "DS"); diff --git a/src/ds/extra/cli.c b/src/ds/extra/cli.c index ffeddeb6a..3681fca3b 100644 --- a/src/ds/extra/cli.c +++ b/src/ds/extra/cli.c @@ -1,14 +1,14 @@ -/* Copyright (c) 2013-2015 Jeffrey Pfau +/* Copyright (c) 2013-2017 Jeffrey Pfau * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "cli.h" +#include -#include "arm/debugger/cli-debugger.h" -#include "core/core.h" -#include "ds/core.h" -#include "ds/ds.h" +#include +#include +#include +#include static void _DSCLIDebuggerInit(struct CLIDebuggerSystem*); static bool _DSCLIDebuggerCustom(struct CLIDebuggerSystem*); diff --git a/src/ds/io.c b/src/ds/io.c index f8576b8d8..05b39bd91 100644 --- a/src/ds/io.c +++ b/src/ds/io.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "io.h" +#include -#include "ds/ds.h" +#include mLOG_DEFINE_CATEGORY(DS_IO, "DS I/O"); diff --git a/src/ds/memory.c b/src/ds/memory.c index 01f6fb97b..fc14cff77 100644 --- a/src/ds/memory.c +++ b/src/ds/memory.c @@ -3,14 +3,14 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "memory.h" +#include -#include "arm/macros.h" +#include -#include "ds/ds.h" -#include "ds/io.h" -#include "util/math.h" -#include "util/memory.h" +#include +#include +#include +#include mLOG_DEFINE_CATEGORY(DS_MEM, "DS Memory"); diff --git a/src/ds/timer.c b/src/ds/timer.c index a395bd6d1..5adee65ab 100644 --- a/src/ds/timer.c +++ b/src/ds/timer.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "timer.h" +#include -#include "arm/arm.h" -#include "ds/ds.h" +#include +#include void DSTimerUpdateRegister(struct DSTimer* timer, struct ARMCore* cpu, uint16_t* io) { if (DSTimerFlagsIsEnable(timer->flags) && !DSTimerFlagsIsCountUp(timer->flags)) { diff --git a/src/feature/commandline.c b/src/feature/commandline.c index 9fc75bacb..ae9f72c18 100644 --- a/src/feature/commandline.c +++ b/src/feature/commandline.c @@ -5,13 +5,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "commandline.h" -#include "core/config.h" -#include "core/version.h" -#include "util/string.h" +#include +#include +#include #include #ifdef _MSC_VER -#include "platform/windows/getopt.h" +#include #else #include #endif diff --git a/src/feature/commandline.h b/src/feature/commandline.h index 9fbb64f79..322c8e87b 100644 --- a/src/feature/commandline.h +++ b/src/feature/commandline.h @@ -6,9 +6,11 @@ #ifndef COMMAND_LINE_H #define COMMAND_LINE_H -#include "util/common.h" +#include -#include "debugger/debugger.h" +CXX_GUARD_START + +#include struct mArguments { char* fname; @@ -49,4 +51,6 @@ void version(const char* arg0); void initParserForGraphics(struct mSubParser* parser, struct mGraphicsOpts* opts); +CXX_GUARD_END + #endif diff --git a/src/feature/editline/cli-el-backend.c b/src/feature/editline/cli-el-backend.c index ac0a935d4..530019b03 100644 --- a/src/feature/editline/cli-el-backend.c +++ b/src/feature/editline/cli-el-backend.c @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "cli-el-backend.h" -#include "core/version.h" +#include #include diff --git a/src/feature/editline/cli-el-backend.h b/src/feature/editline/cli-el-backend.h index df3986e07..89ceec641 100644 --- a/src/feature/editline/cli-el-backend.h +++ b/src/feature/editline/cli-el-backend.h @@ -6,8 +6,11 @@ #ifndef CLI_EL_BACKEND_H #define CLI_EL_BACKEND_H -#include "debugger/cli-debugger.h" -#include "util/common.h" +#include + +CXX_GUARD_START + +#include #include @@ -20,4 +23,6 @@ struct CLIDebuggerEditLineBackend { struct CLIDebuggerBackend* CLIDebuggerEditLineBackendCreate(void); +CXX_GUARD_END + #endif diff --git a/src/feature/ffmpeg/ffmpeg-encoder.c b/src/feature/ffmpeg/ffmpeg-encoder.c index ac239f650..a902d6abf 100644 --- a/src/feature/ffmpeg/ffmpeg-encoder.c +++ b/src/feature/ffmpeg/ffmpeg-encoder.c @@ -5,8 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "ffmpeg-encoder.h" -#include "core/core.h" -#include "gba/video.h" +#include +#include #include #include diff --git a/src/feature/ffmpeg/ffmpeg-encoder.h b/src/feature/ffmpeg/ffmpeg-encoder.h index 6a8d9bf4a..feeeddc77 100644 --- a/src/feature/ffmpeg/ffmpeg-encoder.h +++ b/src/feature/ffmpeg/ffmpeg-encoder.h @@ -6,7 +6,11 @@ #ifndef FFMPEG_ENCODER #define FFMPEG_ENCODER -#include "gba/gba.h" +#include + +CXX_GUARD_START + +#include #include #include @@ -83,4 +87,6 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder*, const char* outfile); void FFmpegEncoderClose(struct FFmpegEncoder*); bool FFmpegEncoderIsOpen(struct FFmpegEncoder*); +CXX_GUARD_END + #endif diff --git a/src/feature/gui/gui-config.c b/src/feature/gui/gui-config.c index 72c311cc1..9d4e39fb2 100644 --- a/src/feature/gui/gui-config.c +++ b/src/feature/gui/gui-config.c @@ -5,12 +5,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "gui-config.h" -#include "core/config.h" +#include +#include #include "feature/gui/gui-runner.h" #include "feature/gui/remap.h" -#include "gba/gba.h" -#include "util/gui/file-select.h" -#include "util/gui/menu.h" +#include +#include +#include #ifndef GUI_MAX_INPUTS #define GUI_MAX_INPUTS 7 diff --git a/src/feature/gui/gui-config.h b/src/feature/gui/gui-config.h index 0771f2133..f869e1c46 100644 --- a/src/feature/gui/gui-config.h +++ b/src/feature/gui/gui-config.h @@ -6,10 +6,14 @@ #ifndef GUI_CONFIG_H #define GUI_CONFIG_H -#include "util/common.h" +#include + +CXX_GUARD_START struct mGUIRunner; struct GUIMenuItem; void mGUIShowConfig(struct mGUIRunner* runner, struct GUIMenuItem* extra, size_t nExtra); +CXX_GUARD_END + #endif diff --git a/src/feature/gui/gui-runner.c b/src/feature/gui/gui-runner.c index 2a0ee06a7..0fce5b791 100644 --- a/src/feature/gui/gui-runner.c +++ b/src/feature/gui/gui-runner.c @@ -5,18 +5,18 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "gui-runner.h" -#include "core/core.h" -#include "core/serialize.h" +#include +#include #include "feature/gui/gui-config.h" -#include "gba/gba.h" -#include "gba/input.h" -#include "gba/interface.h" -#include "util/gui/file-select.h" -#include "util/gui/font.h" -#include "util/gui/menu.h" -#include "util/memory.h" -#include "util/png-io.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef _3DS #include <3ds.h> diff --git a/src/feature/gui/gui-runner.h b/src/feature/gui/gui-runner.h index 556c4f269..0a288951f 100644 --- a/src/feature/gui/gui-runner.h +++ b/src/feature/gui/gui-runner.h @@ -6,13 +6,15 @@ #ifndef GUI_RUNNER_H #define GUI_RUNNER_H -#include "util/common.h" +#include -#include "core/config.h" +CXX_GUARD_START + +#include #include "feature/gui/remap.h" -#include "gba/hardware.h" -#include "util/circle-buffer.h" -#include "util/gui.h" +#include +#include +#include enum mGUIInput { mGUI_INPUT_INCREASE_BRIGHTNESS = GUI_INPUT_USER_START, @@ -75,4 +77,6 @@ void mGUIDeinit(struct mGUIRunner*); void mGUIRun(struct mGUIRunner*, const char* path); void mGUIRunloop(struct mGUIRunner*); +CXX_GUARD_END + #endif diff --git a/src/feature/gui/remap.c b/src/feature/gui/remap.c index 2db8517fa..b17560319 100644 --- a/src/feature/gui/remap.c +++ b/src/feature/gui/remap.c @@ -5,8 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "remap.h" -#include "util/gui.h" -#include "util/gui/menu.h" +#include +#include void mGUIRemapKeys(struct GUIParams* params, struct mInputMap* map, const struct GUIInputKeys* keys) { struct GUIMenu menu = { diff --git a/src/feature/gui/remap.h b/src/feature/gui/remap.h index ab6a0e70c..a604c3950 100644 --- a/src/feature/gui/remap.h +++ b/src/feature/gui/remap.h @@ -6,7 +6,9 @@ #ifndef GUI_REMAP_H #define GUI_REMAP_H -#include "util/common.h" +#include + +CXX_GUARD_START struct GUIInputKeys { const char* name; @@ -20,4 +22,6 @@ struct mInputMap; void mGUIRemapKeys(struct GUIParams*, struct mInputMap*, const struct GUIInputKeys*); +CXX_GUARD_END + #endif diff --git a/src/feature/imagemagick/imagemagick-gif-encoder.c b/src/feature/imagemagick/imagemagick-gif-encoder.c index 2eb4ad358..faa44d9d9 100644 --- a/src/feature/imagemagick/imagemagick-gif-encoder.c +++ b/src/feature/imagemagick/imagemagick-gif-encoder.c @@ -5,8 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "imagemagick-gif-encoder.h" -#include "gba/video.h" -#include "util/string.h" +#include +#include +#include static void _magickPostVideoFrame(struct mAVStream*, const color_t* pixels, size_t stride); static void _magickVideoDimensionsChanged(struct mAVStream*, unsigned width, unsigned height); diff --git a/src/feature/imagemagick/imagemagick-gif-encoder.h b/src/feature/imagemagick/imagemagick-gif-encoder.h index 554813737..13505e6db 100644 --- a/src/feature/imagemagick/imagemagick-gif-encoder.h +++ b/src/feature/imagemagick/imagemagick-gif-encoder.h @@ -6,7 +6,11 @@ #ifndef IMAGEMAGICK_GIF_ENCODER #define IMAGEMAGICK_GIF_ENCODER -#include "gba/gba.h" +#include + +CXX_GUARD_START + +#include #define MAGICKCORE_HDRI_ENABLE 0 #define MAGICKCORE_QUANTUM_DEPTH 8 @@ -33,4 +37,6 @@ bool ImageMagickGIFEncoderOpen(struct ImageMagickGIFEncoder*, const char* outfil bool ImageMagickGIFEncoderClose(struct ImageMagickGIFEncoder*); bool ImageMagickGIFEncoderIsOpen(struct ImageMagickGIFEncoder*); +CXX_GUARD_END + #endif diff --git a/src/gb/audio.c b/src/gb/audio.c index 14f501096..183927730 100644 --- a/src/gb/audio.c +++ b/src/gb/audio.c @@ -3,13 +3,14 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "audio.h" +#include -#include "core/interface.h" -#include "core/sync.h" -#include "gb/gb.h" -#include "gb/serialize.h" -#include "gb/io.h" +#include +#include +#include +#include +#include +#include #ifdef _3DS #define blip_add_delta blip_add_delta_fast diff --git a/src/gb/cheats.c b/src/gb/cheats.c index a29711c61..118ddde20 100644 --- a/src/gb/cheats.c +++ b/src/gb/cheats.c @@ -3,12 +3,12 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "cheats.h" +#include -#include "core/core.h" -#include "gb/gb.h" -#include "gb/memory.h" -#include "util/string.h" +#include +#include +#include +#include DEFINE_VECTOR(GBCheatPatchList, struct GBCheatPatch); diff --git a/src/gb/core.c b/src/gb/core.c index fabe88f8c..6380f9ff1 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -3,21 +3,22 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "core.h" +#include -#include "core/core.h" -#include "gb/cheats.h" -#include "gb/extra/cli.h" -#include "gb/gb.h" -#include "gb/mbc.h" -#include "gb/overrides.h" -#include "gb/renderers/software.h" -#include "gb/serialize.h" -#include "lr35902/debugger/debugger.h" -#include "util/crc32.h" -#include "util/memory.h" -#include "util/patch.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include struct GBCore { struct mCore d; diff --git a/src/gb/extra/cli.c b/src/gb/extra/cli.c index 0f8f7d945..78e10a1b6 100644 --- a/src/gb/extra/cli.c +++ b/src/gb/extra/cli.c @@ -3,14 +3,14 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "cli.h" +#include -#include "core/core.h" -#include "core/serialize.h" -#include "gb/gb.h" -#include "gb/io.h" -#include "gb/video.h" -#include "lr35902/debugger/cli-debugger.h" +#include +#include +#include +#include +#include +#include static void _GBCLIDebuggerInit(struct CLIDebuggerSystem*); static bool _GBCLIDebuggerCustom(struct CLIDebuggerSystem*); diff --git a/src/gb/gb.c b/src/gb/gb.c index 9a307e23d..e53a7e579 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -3,18 +3,19 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "gb.h" +#include -#include "gb/io.h" -#include "gb/mbc.h" +#include +#include +#include -#include "core/core.h" -#include "core/cheats.h" -#include "util/crc32.h" -#include "util/memory.h" -#include "util/math.h" -#include "util/patch.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include +#include +#include #define CLEANUP_THRESHOLD 15 @@ -433,6 +434,7 @@ void GBReset(struct LR35902Core* cpu) { } gb->cpuBlocked = false; + gb->earlyExit = false; gb->doubleSpeed = 0; cpu->memory.setActiveRegion(cpu, cpu->pc); @@ -548,6 +550,10 @@ void GBProcessEvents(struct LR35902Core* cpu) { } while (gb->cpuBlocked); cpu->nextEvent = nextEvent; + if (gb->earlyExit) { + gb->earlyExit = false; + break; + } if (cpu->halted) { cpu->cycles = cpu->nextEvent; if (!gb->memory.ie || !gb->memory.ime) { diff --git a/src/gb/io.c b/src/gb/io.c index bcdee83da..82f3855ef 100644 --- a/src/gb/io.c +++ b/src/gb/io.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "io.h" +#include -#include "gb/gb.h" -#include "gb/sio.h" -#include "gb/serialize.h" +#include +#include +#include mLOG_DEFINE_CATEGORY(GB_IO, "GB I/O"); @@ -158,6 +158,9 @@ void GBIOReset(struct GB* gb) { void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) { switch (address) { + case REG_SB: + GBSIOWriteSB(&gb->sio, value); + break; case REG_SC: GBSIOWriteSC(&gb->sio, value); break; @@ -338,7 +341,6 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) { } break; case REG_JOYP: - case REG_SB: case REG_TIMA: case REG_TMA: // Handled transparently by the registers diff --git a/src/gb/mbc.c b/src/gb/mbc.c index 9357fcbe3..0ae353b05 100644 --- a/src/gb/mbc.c +++ b/src/gb/mbc.c @@ -3,11 +3,12 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "mbc.h" +#include -#include "gb/gb.h" -#include "gb/memory.h" -#include "util/vfs.h" +#include +#include +#include +#include mLOG_DEFINE_CATEGORY(GB_MBC, "GB MBC"); diff --git a/src/gb/memory.c b/src/gb/memory.c index 3b2656001..0334e136e 100644 --- a/src/gb/memory.c +++ b/src/gb/memory.c @@ -3,15 +3,16 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "memory.h" +#include -#include "core/interface.h" -#include "gb/gb.h" -#include "gb/io.h" -#include "gb/mbc.h" -#include "gb/serialize.h" +#include +#include +#include +#include +#include +#include -#include "util/memory.h" +#include mLOG_DEFINE_CATEGORY(GB_MEM, "GB Memory"); diff --git a/src/gb/overrides.c b/src/gb/overrides.c index 9e19b7d87..d86f08f5f 100644 --- a/src/gb/overrides.c +++ b/src/gb/overrides.c @@ -3,12 +3,12 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "overrides.h" +#include -#include "gb/gb.h" +#include -#include "util/configuration.h" -#include "util/crc32.h" +#include +#include static const struct GBCartridgeOverride _overrides[] = { // None yet diff --git a/src/gb/renderers/software.c b/src/gb/renderers/software.c index 1e6f914fc..61daa9f98 100644 --- a/src/gb/renderers/software.c +++ b/src/gb/renderers/software.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "software.h" +#include -#include "core/tile-cache.h" -#include "gb/io.h" -#include "util/memory.h" +#include +#include +#include static void GBVideoSoftwareRendererInit(struct GBVideoRenderer* renderer, enum GBModel model); static void GBVideoSoftwareRendererDeinit(struct GBVideoRenderer* renderer); diff --git a/src/gb/renderers/tile-cache.c b/src/gb/renderers/tile-cache.c index b10ee972d..4780649b8 100644 --- a/src/gb/renderers/tile-cache.c +++ b/src/gb/renderers/tile-cache.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "tile-cache.h" +#include -#include "core/tile-cache.h" -#include "gb/video.h" -#include "gb/renderers/tile-cache.h" +#include +#include +#include void GBVideoTileCacheInit(struct mTileCache* cache) { mTileCacheInit(cache); diff --git a/src/gb/serialize.c b/src/gb/serialize.c index abec007ac..61b4b5a09 100644 --- a/src/gb/serialize.c +++ b/src/gb/serialize.c @@ -3,10 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "serialize.h" +#include -#include "gb/io.h" -#include "gb/timer.h" +#include +#include +#include mLOG_DEFINE_CATEGORY(GB_STATE, "GB Savestate"); diff --git a/src/gb/sio.c b/src/gb/sio.c index 2758cafa4..944064752 100644 --- a/src/gb/sio.c +++ b/src/gb/sio.c @@ -3,11 +3,18 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "sio.h" +#include -#include "gb/gb.h" -#include "gb/io.h" -#include "gb/serialize.h" +#include +#include +#include + +mLOG_DEFINE_CATEGORY(GB_SIO, "GB Serial I/O"); + +const int GBSIOCyclesPerTransfer[2] = { + 512, + 16 +}; void _GBSIOProcessEvents(struct mTiming* timing, void* context, uint32_t cyclesLate); @@ -17,6 +24,8 @@ void GBSIOInit(struct GBSIO* sio) { sio->event.name = "GB SIO"; sio->event.callback = _GBSIOProcessEvents; sio->event.priority = 0x30; + + sio->driver = NULL; } void GBSIOReset(struct GBSIO* sio) { @@ -29,28 +38,66 @@ void GBSIODeinit(struct GBSIO* sio) { // Nothing to do yet } +void GBSIOSetDriver(struct GBSIO* sio, struct GBSIODriver* driver) { + if (sio->driver) { + if (sio->driver->deinit) { + sio->driver->deinit(sio->driver); + } + } + if (driver) { + driver->p = sio; + + if (driver->init) { + if (!driver->init(driver)) { + driver->deinit(driver); + mLOG(GB_SIO, ERROR, "Could not initialize SIO driver"); + return; + } + } + } + sio->driver = driver; +} + void _GBSIOProcessEvents(struct mTiming* timing, void* context, uint32_t cyclesLate) { UNUSED(cyclesLate); struct GBSIO* sio = context; - --sio->remainingBits; - sio->p->memory.io[REG_SB] &= ~(8 >> sio->remainingBits); - sio->p->memory.io[REG_SB] |= sio->pendingSB & ~(8 >> sio->remainingBits); + bool doIRQ = false; + if (sio->remainingBits) { + doIRQ = true; + --sio->remainingBits; + sio->p->memory.io[REG_SB] &= ~(128 >> sio->remainingBits); + sio->p->memory.io[REG_SB] |= sio->pendingSB & (128 >> sio->remainingBits); + } if (!sio->remainingBits) { - sio->p->memory.io[REG_IF] |= (1 << GB_IRQ_SIO); sio->p->memory.io[REG_SC] = GBRegisterSCClearEnable(sio->p->memory.io[REG_SC]); - GBUpdateIRQs(sio->p); + if (doIRQ) { + sio->p->memory.io[REG_IF] |= (1 << GB_IRQ_SIO); + GBUpdateIRQs(sio->p); + sio->pendingSB = 0xFF; + } } else { mTimingSchedule(timing, &sio->event, sio->period); } } +void GBSIOWriteSB(struct GBSIO* sio, uint8_t sb) { + if (!sio->driver) { + return; + } + sio->driver->writeSB(sio->driver, sb); +} + void GBSIOWriteSC(struct GBSIO* sio, uint8_t sc) { - sio->period = 0x1000; // TODO Shift Clock + sio->period = GBSIOCyclesPerTransfer[GBRegisterSCGetClockSpeed(sc)]; // TODO Shift Clock if (GBRegisterSCIsEnable(sc)) { + mTimingDeschedule(&sio->p->timing, &sio->event); if (GBRegisterSCIsShiftClock(sc)) { mTimingSchedule(&sio->p->timing, &sio->event, sio->period); + sio->remainingBits = 8; } - sio->remainingBits = 8; + } + if (sio->driver) { + sio->driver->writeSC(sio->driver, sc); } } diff --git a/src/gb/sio/lockstep.c b/src/gb/sio/lockstep.c new file mode 100644 index 000000000..c60978ffe --- /dev/null +++ b/src/gb/sio/lockstep.c @@ -0,0 +1,242 @@ +/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + +#include +#include + +#define LOCKSTEP_INCREMENT 512 + +static bool GBSIOLockstepNodeInit(struct GBSIODriver* driver); +static void GBSIOLockstepNodeDeinit(struct GBSIODriver* driver); +static void GBSIOLockstepNodeWriteSB(struct GBSIODriver* driver, uint8_t value); +static uint8_t GBSIOLockstepNodeWriteSC(struct GBSIODriver* driver, uint8_t value); +static void _GBSIOLockstepNodeProcessEvents(struct mTiming* timing, void* driver, uint32_t cyclesLate); + +void GBSIOLockstepInit(struct GBSIOLockstep* lockstep) { + mLockstepInit(&lockstep->d); + lockstep->players[0] = NULL; + lockstep->players[1] = NULL; + lockstep->pendingSB[0] = 0xFF; + lockstep->pendingSB[1] = 0xFF; + lockstep->masterClaimed = false; +} + +void GBSIOLockstepNodeCreate(struct GBSIOLockstepNode* node) { + node->d.init = GBSIOLockstepNodeInit; + node->d.deinit = GBSIOLockstepNodeDeinit; + node->d.writeSB = GBSIOLockstepNodeWriteSB; + node->d.writeSC = GBSIOLockstepNodeWriteSC; +} + +bool GBSIOLockstepAttachNode(struct GBSIOLockstep* lockstep, struct GBSIOLockstepNode* node) { + if (lockstep->d.attached == MAX_GBS) { + return false; + } + lockstep->players[lockstep->d.attached] = node; + node->p = lockstep; + node->id = lockstep->d.attached; + ++lockstep->d.attached; + return true; +} + +void GBSIOLockstepDetachNode(struct GBSIOLockstep* lockstep, struct GBSIOLockstepNode* node) { + if (lockstep->d.attached == 0) { + return; + } + int i; + for (i = 0; i < lockstep->d.attached; ++i) { + if (lockstep->players[i] != node) { + continue; + } + for (++i; i < lockstep->d.attached; ++i) { + lockstep->players[i - 1] = lockstep->players[i]; + lockstep->players[i - 1]->id = i - 1; + } + --lockstep->d.attached; + break; + } +} + +bool GBSIOLockstepNodeInit(struct GBSIODriver* driver) { + struct GBSIOLockstepNode* node = (struct GBSIOLockstepNode*) driver; + mLOG(GB_SIO, DEBUG, "Lockstep %i: Node init", node->id); + node->event.context = node; + node->event.name = "GB SIO Lockstep"; + node->event.callback = _GBSIOLockstepNodeProcessEvents; + node->event.priority = 0x80; + + node->nextEvent = 0; + node->eventDiff = 0; + mTimingSchedule(&driver->p->p->timing, &node->event, 0); +#ifndef NDEBUG + node->phase = node->p->d.transferActive; + node->transferId = node->p->d.transferId; +#endif + return true; +} + +void GBSIOLockstepNodeDeinit(struct GBSIODriver* driver) { + struct GBSIOLockstepNode* node = (struct GBSIOLockstepNode*) driver; + node->p->d.unload(&node->p->d, node->id); + mTimingDeschedule(&driver->p->p->timing, &node->event); +} + +static void _finishTransfer(struct GBSIOLockstepNode* node) { + if (node->transferFinished) { + return; + } + struct GBSIO* sio = node->d.p; + sio->pendingSB = node->p->pendingSB[!node->id]; + if (GBRegisterSCIsEnable(sio->p->memory.io[REG_SC])) { + sio->remainingBits = 8; + mTimingDeschedule(&sio->p->timing, &sio->event); + mTimingSchedule(&sio->p->timing, &sio->event, 0); + } + node->transferFinished = true; +#ifndef NDEBUG + ++node->transferId; +#endif +} + + +static int32_t _masterUpdate(struct GBSIOLockstepNode* node) { + bool needsToWait = false; + int i; + switch (node->p->d.transferActive) { + case TRANSFER_IDLE: + // If the master hasn't initiated a transfer, it can keep going. + node->nextEvent += LOCKSTEP_INCREMENT; + break; + case TRANSFER_STARTING: + // Start the transfer, but wait for the other GBs to catch up + node->transferFinished = false; + needsToWait = true; + ATOMIC_STORE(node->p->d.transferActive, TRANSFER_STARTED); + node->nextEvent += 4; + break; + case TRANSFER_STARTED: + // All the other GBs have caught up and are sleeping, we can all continue now + node->nextEvent += 4; + ATOMIC_STORE(node->p->d.transferActive, TRANSFER_FINISHING); + break; + case TRANSFER_FINISHING: + // Finish the transfer + // We need to make sure the other GBs catch up so they don't get behind + node->nextEvent += node->d.p->period - 8; // Split the cycles to avoid waiting too long +#ifndef NDEBUG + ATOMIC_ADD(node->p->d.transferId, 1); +#endif + needsToWait = true; + ATOMIC_STORE(node->p->d.transferActive, TRANSFER_FINISHED); + break; + case TRANSFER_FINISHED: + // Everything's settled. We're done. + _finishTransfer(node); + ATOMIC_STORE(node->p->masterClaimed, false); + node->nextEvent += LOCKSTEP_INCREMENT; + ATOMIC_STORE(node->p->d.transferActive, TRANSFER_IDLE); + break; + } + int mask = 0; + for (i = 1; i < node->p->d.attached; ++i) { + mask |= 1 << i; + } + if (mask) { + if (needsToWait) { + if (!node->p->d.wait(&node->p->d, mask)) { + abort(); + } + } else { + node->p->d.signal(&node->p->d, mask); + } + } + // Tell the other GBs they can continue up to where we were + node->p->d.addCycles(&node->p->d, 0, node->eventDiff); +#ifndef NDEBUG + node->phase = node->p->d.transferActive; +#endif + if (needsToWait) { + return 0; + } + return node->nextEvent; +} + +static uint32_t _slaveUpdate(struct GBSIOLockstepNode* node) { + bool signal = false; + switch (node->p->d.transferActive) { + case TRANSFER_IDLE: + node->p->d.addCycles(&node->p->d, node->id, LOCKSTEP_INCREMENT); + break; + case TRANSFER_STARTING: + case TRANSFER_FINISHING: + break; + case TRANSFER_STARTED: + node->transferFinished = false; + signal = true; + break; + case TRANSFER_FINISHED: + _finishTransfer(node); + signal = true; + break; + } +#ifndef NDEBUG + node->phase = node->p->d.transferActive; +#endif + if (signal) { + node->p->d.signal(&node->p->d, 1 << node->id); + } + return 0; +} + +static void _GBSIOLockstepNodeProcessEvents(struct mTiming* timing, void* user, uint32_t cyclesLate) { + struct GBSIOLockstepNode* node = user; + if (node->p->d.attached < 2) { + return; + } + int32_t cycles = 0; + node->nextEvent -= cyclesLate; + if (node->nextEvent <= 0) { + if (!node->id) { + cycles = _masterUpdate(node); + } else { + cycles = _slaveUpdate(node); + cycles += node->p->d.useCycles(&node->p->d, node->id, node->eventDiff); + } + node->eventDiff = 0; + } else { + cycles = node->nextEvent; + } + if (cycles > 0) { + node->nextEvent = 0; + node->eventDiff += cycles; + mTimingDeschedule(timing, &node->event); + mTimingSchedule(timing, &node->event, cycles); + } else { + node->d.p->p->earlyExit = true; + mTimingSchedule(timing, &node->event, cyclesLate + 1); + } +} + +static void GBSIOLockstepNodeWriteSB(struct GBSIODriver* driver, uint8_t value) { + struct GBSIOLockstepNode* node = (struct GBSIOLockstepNode*) driver; + node->p->pendingSB[node->id] = value; +} + +static uint8_t GBSIOLockstepNodeWriteSC(struct GBSIODriver* driver, uint8_t value) { + struct GBSIOLockstepNode* node = (struct GBSIOLockstepNode*) driver; + if ((value & 0x81) == 0x81 && node->p->d.attached > 1) { + bool claimed = false; + if (ATOMIC_CMPXCHG(node->p->masterClaimed, claimed, true)) { + node->p->d.transferActive = TRANSFER_STARTING; + node->p->d.transferCycles = GBSIOCyclesPerTransfer[(value >> 1) & 1]; + mTimingDeschedule(&driver->p->p->timing, &driver->p->event); + mTimingDeschedule(&driver->p->p->timing, &node->event); + mTimingSchedule(&driver->p->p->timing, &node->event, 0); + } + } + return value; +} diff --git a/src/gb/test/core.c b/src/gb/test/core.c index c5ed2fdfa..09f9ca25a 100644 --- a/src/gb/test/core.c +++ b/src/gb/test/core.c @@ -5,10 +5,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/test/suite.h" -#include "core/core.h" -#include "gb/core.h" -#include "gb/gb.h" -#include "util/vfs.h" +#include +#include +#include +#include M_TEST_DEFINE(create) { struct mCore* core = GBCoreCreate(); diff --git a/src/gb/test/gb.h b/src/gb/test/gb.h index 2bb574f01..572a21466 100644 --- a/src/gb/test/gb.h +++ b/src/gb/test/gb.h @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef TEST_GB_H #define TEST_GB_H -#include "util/common.h" +#include int TestRunGB(void); diff --git a/src/gb/test/mbc.c b/src/gb/test/mbc.c index d4e94b401..a9448892b 100644 --- a/src/gb/test/mbc.c +++ b/src/gb/test/mbc.c @@ -5,11 +5,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/test/suite.h" -#include "core/core.h" -#include "gb/core.h" -#include "gb/gb.h" -#include "gb/mbc.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include M_TEST_SUITE_SETUP(GBMBC) { struct VFile* vf = VFileMemChunk(NULL, 2048); diff --git a/src/gb/test/memory.c b/src/gb/test/memory.c index 35768916a..f4e0ee642 100644 --- a/src/gb/test/memory.c +++ b/src/gb/test/memory.c @@ -5,11 +5,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/test/suite.h" -#include "core/core.h" -#include "gb/core.h" -#include "gb/gb.h" -#include "gb/mbc.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include M_TEST_SUITE_SETUP(GBMemory) { struct VFile* vf = VFileMemChunk(NULL, GB_SIZE_CART_BANK0 * 4); diff --git a/src/gb/test/rtc.c b/src/gb/test/rtc.c index 8e6010775..5ad393a64 100644 --- a/src/gb/test/rtc.c +++ b/src/gb/test/rtc.c @@ -5,11 +5,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/test/suite.h" -#include "core/core.h" -#include "gb/core.h" -#include "gb/gb.h" -#include "gb/mbc.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include struct GBRTCTest { struct mRTCSource d; diff --git a/src/gb/timer.c b/src/gb/timer.c index 3426cafad..0cd2571a9 100644 --- a/src/gb/timer.c +++ b/src/gb/timer.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "timer.h" +#include -#include "gb/gb.h" -#include "gb/io.h" -#include "gb/serialize.h" +#include +#include +#include void _GBTimerIRQ(struct mTiming* timing, void* context, uint32_t cyclesLate) { UNUSED(timing); diff --git a/src/gb/video.c b/src/gb/video.c index 37e58b5a8..cfabfe4ce 100644 --- a/src/gb/video.c +++ b/src/gb/video.c @@ -3,16 +3,17 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "video.h" +#include -#include "core/sync.h" -#include "core/thread.h" -#include "core/tile-cache.h" -#include "gb/gb.h" -#include "gb/io.h" -#include "gb/serialize.h" +#include +#include +#include +#include +#include +#include +#include -#include "util/memory.h" +#include static void GBVideoDummyRendererInit(struct GBVideoRenderer* renderer, enum GBModel model); static void GBVideoDummyRendererDeinit(struct GBVideoRenderer* renderer); diff --git a/src/gba/audio.c b/src/gba/audio.c index 9f01889ed..52d99d883 100644 --- a/src/gba/audio.c +++ b/src/gba/audio.c @@ -3,14 +3,16 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "audio.h" +#include -#include "core/sync.h" -#include "gba/dma.h" -#include "gba/gba.h" -#include "gba/io.h" -#include "gba/serialize.h" -#include "gba/video.h" +#include +#include +#include +#include +#include +#include +#include +#include #ifdef _3DS #define blip_add_delta blip_add_delta_fast diff --git a/src/gba/bios.c b/src/gba/bios.c index a61cf88d8..83e43b302 100644 --- a/src/gba/bios.c +++ b/src/gba/bios.c @@ -3,13 +3,13 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "bios.h" +#include -#include "arm/isa-inlines.h" -#include "arm/macros.h" -#include "gba/gba.h" -#include "gba/io.h" -#include "gba/memory.h" +#include +#include +#include +#include +#include const uint32_t GBA_BIOS_CHECKSUM = 0xBAAE187F; const uint32_t GBA_DS_BIOS_CHECKSUM = 0xBAAE1880; diff --git a/src/gba/cheats.c b/src/gba/cheats.c index 81497ec62..2e1a30b54 100644 --- a/src/gba/cheats.c +++ b/src/gba/cheats.c @@ -3,12 +3,13 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "cheats.h" +#include +#include +#include +#include #include "gba/cheats/gameshark.h" #include "gba/cheats/parv3.h" -#include "gba/gba.h" -#include "util/string.h" #define MAX_LINE_LENGTH 128 diff --git a/src/gba/cheats/codebreaker.c b/src/gba/cheats/codebreaker.c index 5c7f6fb58..bca859b68 100644 --- a/src/gba/cheats/codebreaker.c +++ b/src/gba/cheats/codebreaker.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "gba/cheats.h" +#include -#include "gba/gba.h" -#include "gba/io.h" -#include "util/string.h" +#include +#include +#include static void _cbLoadByteswap(uint8_t* buffer, uint32_t op1, uint16_t op2) { buffer[0] = op1 >> 24; diff --git a/src/gba/cheats/gameshark.c b/src/gba/cheats/gameshark.c index 58dcb749c..1fc476aff 100644 --- a/src/gba/cheats/gameshark.c +++ b/src/gba/cheats/gameshark.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "gameshark.h" +#include #include "gba/cheats/parv3.h" -#include "gba/gba.h" -#include "util/string.h" +#include +#include const uint32_t GBACheatGameSharkSeeds[4] = { 0x09F4FBBD, 0x9681884A, 0x352027E9, 0xF3DEE5A7 }; diff --git a/src/gba/cheats/gameshark.h b/src/gba/cheats/gameshark.h index 09bdfe997..af4d10469 100644 --- a/src/gba/cheats/gameshark.h +++ b/src/gba/cheats/gameshark.h @@ -6,14 +6,19 @@ #ifndef GBA_CHEATS_GAMESHARK_H #define GBA_CHEATS_GAMESHARK_H -#include "gba/cheats.h" +#include + +CXX_GUARD_START extern const uint32_t GBACheatGameSharkSeeds[4]; +struct GBACheatSet; void GBACheatDecryptGameShark(uint32_t* op1, uint32_t* op2, const uint32_t* seeds); void GBACheatReseedGameShark(uint32_t* seeds, uint16_t params, const uint8_t* t1, const uint8_t* t2); void GBACheatSetGameSharkVersion(struct GBACheatSet* cheats, int version); bool GBACheatAddGameSharkRaw(struct GBACheatSet* cheats, uint32_t op1, uint32_t op2); int GBACheatGameSharkProbability(uint32_t op1, uint32_t op2); +CXX_GUARD_END + #endif diff --git a/src/gba/cheats/parv3.c b/src/gba/cheats/parv3.c index 5cad2b342..ccd6c34b0 100644 --- a/src/gba/cheats/parv3.c +++ b/src/gba/cheats/parv3.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "parv3.h" +#include #include "gba/cheats/gameshark.h" -#include "gba/gba.h" -#include "util/string.h" +#include +#include const uint32_t GBACheatProActionReplaySeeds[4] = { 0x7AA9648F, 0x7FAE6994, 0xC0EFAAD5, 0x42712C57 }; diff --git a/src/gba/cheats/parv3.h b/src/gba/cheats/parv3.h index 66a0e26fe..814f9b1df 100644 --- a/src/gba/cheats/parv3.h +++ b/src/gba/cheats/parv3.h @@ -6,11 +6,16 @@ #ifndef GBA_CHEATS_PARV3_H #define GBA_CHEATS_PARV3_H -#include "gba/cheats.h" +#include + +CXX_GUARD_START extern const uint32_t GBACheatProActionReplaySeeds[4]; +struct GBACheatSet; bool GBACheatAddProActionReplayRaw(struct GBACheatSet* cheats, uint32_t op1, uint32_t op2); int GBACheatProActionReplayProbability(uint32_t op1, uint32_t op2); +CXX_GUARD_END + #endif diff --git a/src/gba/core.c b/src/gba/core.c index c9211a435..992ec7c52 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -3,24 +3,24 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "core.h" +#include -#include "core/core.h" -#include "core/log.h" -#include "arm/debugger/debugger.h" -#include "gba/cheats.h" -#include "gba/gba.h" -#include "gba/extra/cli.h" -#include "gba/overrides.h" +#include +#include +#include +#include +#include +#include +#include #ifndef DISABLE_THREADING -#include "gba/renderers/thread-proxy.h" +#include #endif -#include "gba/renderers/video-software.h" -#include "gba/savedata.h" -#include "gba/serialize.h" -#include "util/memory.h" -#include "util/patch.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include +#include struct GBACore { struct mCore d; @@ -198,6 +198,9 @@ static void _GBACoreSetAVStream(struct mCore* core, struct mAVStream* stream) { } static bool _GBACoreLoadROM(struct mCore* core, struct VFile* vf) { + if (GBAIsMB(vf)) { + return GBALoadMB(core->board, vf); + } return GBALoadROM(core->board, vf); } diff --git a/src/gba/dma.c b/src/gba/dma.c index 7560bdb2f..5c5499ebf 100644 --- a/src/gba/dma.c +++ b/src/gba/dma.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "dma.h" +#include -#include "gba/gba.h" -#include "gba/io.h" +#include +#include static void _dmaEvent(struct mTiming* timing, void* context, uint32_t cyclesLate); diff --git a/src/gba/extra/cli.c b/src/gba/extra/cli.c index ca16a9117..a9ad7841b 100644 --- a/src/gba/extra/cli.c +++ b/src/gba/extra/cli.c @@ -3,12 +3,14 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "cli.h" +#include -#include "arm/debugger/cli-debugger.h" -#include "core/serialize.h" -#include "gba/io.h" -#include "gba/serialize.h" +#include +#include +#include +#include +#include +#include static void _GBACLIDebuggerInit(struct CLIDebuggerSystem*); static bool _GBACLIDebuggerCustom(struct CLIDebuggerSystem*); diff --git a/src/gba/gba.c b/src/gba/gba.c index e1c379fc6..857552ed2 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -3,29 +3,23 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "gba.h" +#include -#include "core/thread.h" +#include +#include +#include -#include "arm/decoder.h" -#include "arm/debugger/debugger.h" -#include "arm/isa-inlines.h" +#include +#include +#include +#include +#include -#include "gba/bios.h" -#include "gba/cheats.h" -#include "gba/io.h" -#include "gba/overrides.h" -#include "gba/rr/rr.h" -#include "gba/serialize.h" -#include "gba/sio.h" -#include "gba/timer.h" -#include "gba/vfame.h" - -#include "util/crc32.h" -#include "util/memory.h" -#include "util/math.h" -#include "util/patch.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include mLOG_DEFINE_CATEGORY(GBA, "GBA"); mLOG_DEFINE_CATEGORY(GBA_DEBUG, "GBA Debug"); diff --git a/src/gba/hardware.c b/src/gba/hardware.c index a47339ba7..5c9032de4 100644 --- a/src/gba/hardware.c +++ b/src/gba/hardware.c @@ -3,12 +3,13 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "hardware.h" +#include -#include "gba/io.h" -#include "gba/serialize.h" -#include "util/formatting.h" -#include "util/hash.h" +#include +#include +#include +#include +#include mLOG_DEFINE_CATEGORY(GBA_HW, "GBA Pak Hardware"); diff --git a/src/gba/hle-bios.c b/src/gba/hle-bios.c index eff5e682f..be450acd4 100644 --- a/src/gba/hle-bios.c +++ b/src/gba/hle-bios.c @@ -1,6 +1,6 @@ #include "hle-bios.h" -#include "gba/memory.h" +#include const uint8_t hleBios[SIZE_BIOS] = { 0x06, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x0b, 0x00, 0x00, 0xea, diff --git a/src/gba/hle-bios.h b/src/gba/hle-bios.h index 6aa4cb92f..cc15e2f5c 100644 --- a/src/gba/hle-bios.h +++ b/src/gba/hle-bios.h @@ -6,8 +6,12 @@ #ifndef HLE_BIOS_H #define HLE_BIOS_H -#include "util/common.h" +#include + +CXX_GUARD_START extern const uint8_t hleBios[]; +CXX_GUARD_END + #endif diff --git a/src/gba/hle-bios.make b/src/gba/hle-bios.make index 20c2b50e3..1022c4c12 100644 --- a/src/gba/hle-bios.make +++ b/src/gba/hle-bios.make @@ -13,6 +13,6 @@ hle-bios.bin: hle-bios.o hle-bios.c: hle-bios.bin echo '#include "hle-bios.h"' > $@ echo >> $@ - echo '#include "gba/memory.h"' >> $@ + echo '#include ' >> $@ echo >> $@ xxd -i $< | sed -e 's/unsigned char hle_bios_bin\[\]/const uint8_t hleBios[SIZE_BIOS]/' | grep -v hle_bios_bin_len >> $@ diff --git a/src/gba/input.c b/src/gba/input.c index e21d0b774..c478e4a05 100644 --- a/src/gba/input.c +++ b/src/gba/input.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "input.h" +#include -#include "gba/interface.h" +#include const struct mInputPlatformInfo GBAInputInfo = { .platformName = "gba", diff --git a/src/gba/io.c b/src/gba/io.c index 0168b31ab..c788fb243 100644 --- a/src/gba/io.c +++ b/src/gba/io.c @@ -3,13 +3,13 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "io.h" +#include -#include "gba/dma.h" -#include "gba/rr/rr.h" -#include "gba/serialize.h" -#include "gba/sio.h" -#include "gba/video.h" +#include +#include +#include +#include +#include mLOG_DEFINE_CATEGORY(GBA_IO, "GBA I/O"); @@ -524,13 +524,15 @@ void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) { value &= 0xC1FF; GBASIOWriteRCNT(&gba->sio, value); break; + case REG_JOY_TRANS_LO: + case REG_JOY_TRANS_HI: + gba->memory.io[REG_JOYSTAT >> 1] |= JOYSTAT_TRANS_BIT; + // Fall through case REG_SIOMLT_SEND: case REG_JOYCNT: case REG_JOYSTAT: case REG_JOY_RECV_LO: case REG_JOY_RECV_HI: - case REG_JOY_TRANS_LO: - case REG_JOY_TRANS_HI: value = GBASIOWriteRegister(&gba->sio, address, value); break; @@ -806,6 +808,11 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address) { mLOG(GBA_IO, GAME_ERROR, "Read from write-only I/O register: %03X", address); return 0; + case REG_JOY_RECV_LO: + case REG_JOY_RECV_HI: + gba->memory.io[REG_JOYSTAT >> 1] &= ~JOYSTAT_RECV_BIT; + break; + case REG_SOUNDBIAS: case REG_KEYCNT: case REG_POSTFLG: @@ -862,8 +869,6 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address) { case REG_SIOMULTI3: case REG_SIOMLT_SEND: case REG_JOYCNT: - case REG_JOY_RECV_LO: - case REG_JOY_RECV_HI: case REG_JOY_TRANS_LO: case REG_JOY_TRANS_HI: case REG_JOYSTAT: diff --git a/src/gba/memory.c b/src/gba/memory.c index 53ceeb3e9..674ba5a7d 100644 --- a/src/gba/memory.c +++ b/src/gba/memory.c @@ -3,17 +3,19 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "memory.h" +#include -#include "arm/decoder.h" -#include "gba/dma.h" -#include "gba/hardware.h" -#include "gba/io.h" -#include "gba/serialize.h" +#include +#include +#include +#include +#include +#include #include "gba/hle-bios.h" -#include "util/math.h" -#include "util/memory.h" -#include "util/vfs.h" + +#include +#include +#include #define IDLE_LOOP_THRESHOLD 10000 diff --git a/src/gba/overrides.c b/src/gba/overrides.c index c83f3d9c0..787690945 100644 --- a/src/gba/overrides.c +++ b/src/gba/overrides.c @@ -3,12 +3,12 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "overrides.h" +#include -#include "gba/gba.h" -#include "gba/hardware.h" +#include +#include -#include "util/configuration.h" +#include static const struct GBACartridgeOverride _overrides[] = { // Advance Wars diff --git a/src/gba/renderers/software-bg.c b/src/gba/renderers/software-bg.c index ef0c69413..f22a3a589 100644 --- a/src/gba/renderers/software-bg.c +++ b/src/gba/renderers/software-bg.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "software-private.h" +#include "gba/renderers/software-private.h" -#include "gba/gba.h" +#include #define MODE_2_COORD_OVERFLOW \ localX = x & (sizeAdjusted - 1); \ diff --git a/src/gba/renderers/software-mode0.c b/src/gba/renderers/software-mode0.c index 704ef3d61..74db03180 100644 --- a/src/gba/renderers/software-mode0.c +++ b/src/gba/renderers/software-mode0.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "software-private.h" +#include "gba/renderers/software-private.h" -#include "gba/gba.h" +#include #define BACKGROUND_TEXT_SELECT_CHARACTER \ localX = tileX * 8 + inX; \ diff --git a/src/gba/renderers/software-obj.c b/src/gba/renderers/software-obj.c index fccc108c0..f3ee2bd49 100644 --- a/src/gba/renderers/software-obj.c +++ b/src/gba/renderers/software-obj.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "software-private.h" +#include "gba/renderers/software-private.h" #define SPRITE_NORMAL_LOOP(DEPTH, TYPE) \ SPRITE_YBASE_ ## DEPTH(inY); \ diff --git a/src/gba/renderers/software-private.h b/src/gba/renderers/software-private.h index b387e78bc..582af7329 100644 --- a/src/gba/renderers/software-private.h +++ b/src/gba/renderers/software-private.h @@ -6,7 +6,8 @@ #ifndef SOFTWARE_PRIVATE_H #define SOFTWARE_PRIVATE_H -#include "video-software.h" +#include +#include #ifdef NDEBUG #define VIDEO_CHECKS false diff --git a/src/gba/renderers/thread-proxy.c b/src/gba/renderers/thread-proxy.c index 1221dec5c..15c8bba0e 100644 --- a/src/gba/renderers/thread-proxy.c +++ b/src/gba/renderers/thread-proxy.c @@ -3,13 +3,13 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "thread-proxy.h" +#include -#include "core/tile-cache.h" -#include "gba/io.h" -#include "gba/renderers/tile-cache.h" +#include +#include +#include -#include "util/memory.h" +#include #ifndef DISABLE_THREADING diff --git a/src/gba/renderers/tile-cache.c b/src/gba/renderers/tile-cache.c index e39e727ed..20e24849a 100644 --- a/src/gba/renderers/tile-cache.c +++ b/src/gba/renderers/tile-cache.c @@ -3,11 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "tile-cache.h" +#include -#include "core/tile-cache.h" -#include "gba/video.h" -#include "gba/renderers/tile-cache.h" +#include +#include void GBAVideoTileCacheInit(struct mTileCache* cache) { mTileCacheInit(cache); diff --git a/src/gba/renderers/video-software.c b/src/gba/renderers/video-software.c index e4c7e90d7..3e04be736 100644 --- a/src/gba/renderers/video-software.c +++ b/src/gba/renderers/video-software.c @@ -3,15 +3,14 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "software-private.h" +#include "gba/renderers/software-private.h" -#include "core/tile-cache.h" -#include "gba/gba.h" -#include "gba/io.h" -#include "gba/renderers/tile-cache.h" +#include +#include +#include -#include "util/arm-algo.h" -#include "util/memory.h" +#include +#include static void GBAVideoSoftwareRendererInit(struct GBAVideoRenderer* renderer); static void GBAVideoSoftwareRendererDeinit(struct GBAVideoRenderer* renderer); @@ -459,7 +458,6 @@ static void _breakWindowInner(struct GBAVideoSoftwareRenderer* softwareRenderer, static void _cleanOAM(struct GBAVideoSoftwareRenderer* renderer) { int i; int oamMax = 0; - int objwinMax = 0; for (i = 0; i < 128; ++i) { struct GBAObj obj; LOAD_16(obj.a, 0, &renderer->d.oam->obj[i].a); @@ -471,22 +469,14 @@ static void _cleanOAM(struct GBAVideoSoftwareRenderer* renderer) { height <<= GBAObjAttributesAGetDoubleSize(obj.a); } if (GBAObjAttributesAGetY(obj.a) < VIDEO_VERTICAL_PIXELS || GBAObjAttributesAGetY(obj.a) + height >= VIDEO_VERTICAL_TOTAL_PIXELS) { - if (GBAObjAttributesAGetMode(obj.a) == OBJ_MODE_OBJWIN) { - renderer->objwinSprites[objwinMax].y = GBAObjAttributesAGetY(obj.a); - renderer->objwinSprites[objwinMax].endY = GBAObjAttributesAGetY(obj.a) + height; - renderer->objwinSprites[objwinMax].obj = obj; - ++objwinMax; - } else { - renderer->sprites[oamMax].y = GBAObjAttributesAGetY(obj.a); - renderer->sprites[oamMax].endY = GBAObjAttributesAGetY(obj.a) + height; - renderer->sprites[oamMax].obj = obj; - ++oamMax; - } + renderer->sprites[oamMax].y = GBAObjAttributesAGetY(obj.a); + renderer->sprites[oamMax].endY = GBAObjAttributesAGetY(obj.a) + height; + renderer->sprites[oamMax].obj = obj; + ++oamMax; } } } renderer->oamMax = oamMax; - renderer->objwinMax = objwinMax; renderer->oamDirty = 0; } @@ -742,20 +732,7 @@ static void _drawScanline(struct GBAVideoSoftwareRenderer* renderer, int y) { } int i; int drawn; - for (i = 0; i < renderer->objwinMax; ++i) { - int localY = y; - if (renderer->spriteCyclesRemaining <= 0) { - break; - } - struct GBAVideoSoftwareSprite* sprite = &renderer->objwinSprites[i]; - if (GBAObjAttributesAIsMosaic(sprite->obj.a)) { - localY = mosaicY; - } - if ((localY < sprite->y && (sprite->endY - 256 < 0 || localY >= sprite->endY - 256)) || localY >= sprite->endY) { - continue; - } - GBAVideoSoftwareRendererPreprocessSprite(renderer, &sprite->obj, localY); - } + for (i = 0; i < renderer->oamMax; ++i) { int localY = y; if (renderer->spriteCyclesRemaining <= 0) { diff --git a/src/gba/rr/mgm.c b/src/gba/rr/mgm.c index c578c1b5e..d56e979bb 100644 --- a/src/gba/rr/mgm.c +++ b/src/gba/rr/mgm.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "mgm.h" +#include -#include "gba/gba.h" -#include "gba/serialize.h" -#include "util/vfs.h" +#include +#include +#include #define BINARY_EXT ".mgm" #define BINARY_MAGIC "GBAb" diff --git a/src/gba/rr/rr.c b/src/gba/rr/rr.c index f2af0a0d4..da6c48349 100644 --- a/src/gba/rr/rr.c +++ b/src/gba/rr/rr.c @@ -3,10 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "rr.h" +#include -#include "core/serialize.h" -#include "util/vfs.h" +#include +#include +#include mLOG_DEFINE_CATEGORY(GBA_RR, "GBA RR"); diff --git a/src/gba/rr/vbm.c b/src/gba/rr/vbm.c index 5a3f0d0b6..2845b74bc 100644 --- a/src/gba/rr/vbm.c +++ b/src/gba/rr/vbm.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "vbm.h" +#include -#include "gba/gba.h" -#include "gba/serialize.h" -#include "util/vfs.h" +#include +#include +#include #ifdef USE_ZLIB #include @@ -245,7 +245,7 @@ bool GBAVBMSetStream(struct GBAVBMContext* vbm, struct VFile* vf) { uint8_t flags; vf->read(vf, &flags, sizeof(flags)); if (flags & 2) { -#if USE_ZLIB +#ifdef USE_ZLIB vbm->d.initFrom = INIT_FROM_SAVEGAME; #else // zlib is needed to parse the savegame diff --git a/src/gba/savedata.c b/src/gba/savedata.c index 63666161a..f84246f2b 100644 --- a/src/gba/savedata.c +++ b/src/gba/savedata.c @@ -3,13 +3,14 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "savedata.h" +#include -#include "gba/gba.h" -#include "gba/serialize.h" +#include +#include +#include -#include "util/memory.h" -#include "util/vfs.h" +#include +#include #include #include diff --git a/src/gba/serialize.c b/src/gba/serialize.c index efa931212..77f7bc968 100644 --- a/src/gba/serialize.c +++ b/src/gba/serialize.c @@ -3,17 +3,14 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "serialize.h" +#include -#include "core/serialize.h" -#include "gba/audio.h" -#include "gba/cheats.h" -#include "gba/io.h" -#include "gba/rr/rr.h" -#include "gba/video.h" +#include +#include +#include -#include "util/memory.h" -#include "util/vfs.h" +#include +#include #include #ifdef _MSC_VER diff --git a/src/gba/sharkport.c b/src/gba/sharkport.c index 5284e57b1..4ada2360c 100644 --- a/src/gba/sharkport.c +++ b/src/gba/sharkport.c @@ -3,10 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "sharkport.h" +#include -#include "gba/gba.h" -#include "util/vfs.h" +#include +#include +#include static const char* const SHARKPORT_HEADER = "SharkPortSave"; diff --git a/src/gba/sio.c b/src/gba/sio.c index 1e191e93c..661d9d09b 100644 --- a/src/gba/sio.c +++ b/src/gba/sio.c @@ -3,9 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "sio.h" +#include -#include "gba/io.h" +#include +#include mLOG_DEFINE_CATEGORY(GBA_SIO, "GBA Serial I/O"); diff --git a/src/gba/sio/lockstep.c b/src/gba/sio/lockstep.c index 1fd3d6b6d..c196fc3fa 100644 --- a/src/gba/sio/lockstep.c +++ b/src/gba/sio/lockstep.c @@ -3,11 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "lockstep.h" +#include -#include "gba/gba.h" -#include "gba/io.h" -#include "gba/video.h" +#include +#include #define LOCKSTEP_INCREMENT 3000 @@ -20,6 +19,7 @@ static uint16_t GBASIOLockstepNodeNormalWriteRegister(struct GBASIODriver* drive static void _GBASIOLockstepNodeProcessEvents(struct mTiming* timing, void* driver, uint32_t cyclesLate); void GBASIOLockstepInit(struct GBASIOLockstep* lockstep) { + mLockstepInit(&lockstep->d); lockstep->players[0] = 0; lockstep->players[1] = 0; lockstep->players[2] = 0; @@ -28,16 +28,7 @@ void GBASIOLockstepInit(struct GBASIOLockstep* lockstep) { lockstep->multiRecv[1] = 0xFFFF; lockstep->multiRecv[2] = 0xFFFF; lockstep->multiRecv[3] = 0xFFFF; - lockstep->attached = 0; lockstep->attachedMulti = 0; - lockstep->transferActive = 0; -#ifndef NDEBUG - lockstep->transferId = 0; -#endif -} - -void GBASIOLockstepDeinit(struct GBASIOLockstep* lockstep) { - UNUSED(lockstep); } void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode* node) { @@ -49,30 +40,30 @@ void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode* node) { } bool GBASIOLockstepAttachNode(struct GBASIOLockstep* lockstep, struct GBASIOLockstepNode* node) { - if (lockstep->attached == MAX_GBAS) { + if (lockstep->d.attached == MAX_GBAS) { return false; } - lockstep->players[lockstep->attached] = node; + lockstep->players[lockstep->d.attached] = node; node->p = lockstep; - node->id = lockstep->attached; - ++lockstep->attached; + node->id = lockstep->d.attached; + ++lockstep->d.attached; return true; } void GBASIOLockstepDetachNode(struct GBASIOLockstep* lockstep, struct GBASIOLockstepNode* node) { - if (lockstep->attached == 0) { + if (lockstep->d.attached == 0) { return; } int i; - for (i = 0; i < lockstep->attached; ++i) { + for (i = 0; i < lockstep->d.attached; ++i) { if (lockstep->players[i] != node) { continue; } - for (++i; i < lockstep->attached; ++i) { + for (++i; i < lockstep->d.attached; ++i) { lockstep->players[i - 1] = lockstep->players[i]; lockstep->players[i - 1]->id = i - 1; } - --lockstep->attached; + --lockstep->d.attached; break; } } @@ -103,7 +94,7 @@ bool GBASIOLockstepNodeLoad(struct GBASIODriver* driver) { node->d.writeRegister = GBASIOLockstepNodeMultiWriteRegister; node->d.p->rcnt |= 3; ++node->p->attachedMulti; - node->d.p->multiplayerControl.ready = node->p->attachedMulti == node->p->attached; + node->d.p->multiplayerControl.ready = node->p->attachedMulti == node->p->d.attached; if (node->id) { node->d.p->rcnt |= 4; node->d.p->multiplayerControl.slave = 1; @@ -116,8 +107,8 @@ bool GBASIOLockstepNodeLoad(struct GBASIODriver* driver) { break; } #ifndef NDEBUG - node->phase = node->p->transferActive; - node->transferId = node->p->transferId; + node->phase = node->p->d.transferActive; + node->transferId = node->p->d.transferId; #endif return true; } @@ -132,7 +123,7 @@ bool GBASIOLockstepNodeUnload(struct GBASIODriver* driver) { default: break; } - node->p->unload(node->p, node->id); + node->p->d.unload(&node->p->d, node->id); mTimingDeschedule(&driver->p->p->timing, &node->event); return true; } @@ -141,11 +132,11 @@ static uint16_t GBASIOLockstepNodeMultiWriteRegister(struct GBASIODriver* driver struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver; if (address == REG_SIOCNT) { mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIOCNT <- %04x", node->id, value); - if (value & 0x0080 && node->p->transferActive == TRANSFER_IDLE) { + if (value & 0x0080 && node->p->d.transferActive == TRANSFER_IDLE) { if (!node->id && node->d.p->multiplayerControl.ready) { mLOG(GBA_SIO, DEBUG, "Lockstep %i: Transfer initiated", node->id); - node->p->transferActive = TRANSFER_STARTING; - node->p->transferCycles = GBASIOCyclesPerTransfer[node->d.p->multiplayerControl.baud][node->p->attached - 1]; + node->p->d.transferActive = TRANSFER_STARTING; + node->p->d.transferCycles = GBASIOCyclesPerTransfer[node->d.p->multiplayerControl.baud][node->p->d.attached - 1]; mTimingDeschedule(&driver->p->p->timing, &node->event); mTimingSchedule(&driver->p->p->timing, &node->event, 0); } else { @@ -218,11 +209,11 @@ static void _finishTransfer(struct GBASIOLockstepNode* node) { static int32_t _masterUpdate(struct GBASIOLockstepNode* node) { bool needsToWait = false; int i; - switch (node->p->transferActive) { + switch (node->p->d.transferActive) { case TRANSFER_IDLE: // If the master hasn't initiated a transfer, it can keep going. node->nextEvent += LOCKSTEP_INCREMENT; - node->d.p->multiplayerControl.ready = node->p->attachedMulti == node->p->attached; + node->d.p->multiplayerControl.ready = node->p->attachedMulti == node->p->d.attached; break; case TRANSFER_STARTING: // Start the transfer, but wait for the other GBAs to catch up @@ -232,51 +223,51 @@ static int32_t _masterUpdate(struct GBASIOLockstepNode* node) { node->p->multiRecv[2] = 0xFFFF; node->p->multiRecv[3] = 0xFFFF; needsToWait = true; - ATOMIC_STORE(node->p->transferActive, TRANSFER_STARTED); + ATOMIC_STORE(node->p->d.transferActive, TRANSFER_STARTED); node->nextEvent += 512; break; case TRANSFER_STARTED: // All the other GBAs have caught up and are sleeping, we can all continue now node->p->multiRecv[0] = node->d.p->p->memory.io[REG_SIOMLT_SEND >> 1]; node->nextEvent += 512; - ATOMIC_STORE(node->p->transferActive, TRANSFER_FINISHING); + ATOMIC_STORE(node->p->d.transferActive, TRANSFER_FINISHING); break; case TRANSFER_FINISHING: // Finish the transfer // We need to make sure the other GBAs catch up so they don't get behind - node->nextEvent += node->p->transferCycles - 1024; // Split the cycles to avoid waiting too long + node->nextEvent += node->p->d.transferCycles - 1024; // Split the cycles to avoid waiting too long #ifndef NDEBUG - ATOMIC_ADD(node->p->transferId, 1); + ATOMIC_ADD(node->p->d.transferId, 1); #endif needsToWait = true; - ATOMIC_STORE(node->p->transferActive, TRANSFER_FINISHED); + ATOMIC_STORE(node->p->d.transferActive, TRANSFER_FINISHED); break; case TRANSFER_FINISHED: // Everything's settled. We're done. _finishTransfer(node); node->nextEvent += LOCKSTEP_INCREMENT; - ATOMIC_STORE(node->p->transferActive, TRANSFER_IDLE); + ATOMIC_STORE(node->p->d.transferActive, TRANSFER_IDLE); break; } int mask = 0; - for (i = 1; i < node->p->attached; ++i) { + for (i = 1; i < node->p->d.attached; ++i) { if (node->p->players[i]->mode == node->mode) { mask |= 1 << i; } } if (mask) { if (needsToWait) { - if (!node->p->wait(node->p, mask)) { + if (!node->p->d.wait(&node->p->d, mask)) { abort(); } } else { - node->p->signal(node->p, mask); + node->p->d.signal(&node->p->d, mask); } } // Tell the other GBAs they can continue up to where we were - node->p->addCycles(node->p, 0, node->eventDiff); + node->p->d.addCycles(&node->p->d, 0, node->eventDiff); #ifndef NDEBUG - node->phase = node->p->transferActive; + node->phase = node->p->d.transferActive; #endif if (needsToWait) { return 0; @@ -285,12 +276,12 @@ static int32_t _masterUpdate(struct GBASIOLockstepNode* node) { } static uint32_t _slaveUpdate(struct GBASIOLockstepNode* node) { - node->d.p->multiplayerControl.ready = node->p->attachedMulti == node->p->attached; + node->d.p->multiplayerControl.ready = node->p->attachedMulti == node->p->d.attached; bool signal = false; - switch (node->p->transferActive) { + switch (node->p->d.transferActive) { case TRANSFER_IDLE: if (!node->d.p->multiplayerControl.ready) { - node->p->addCycles(node->p, node->id, LOCKSTEP_INCREMENT); + node->p->d.addCycles(&node->p->d, node->id, LOCKSTEP_INCREMENT); } break; case TRANSFER_STARTING: @@ -329,17 +320,17 @@ static uint32_t _slaveUpdate(struct GBASIOLockstepNode* node) { break; } #ifndef NDEBUG - node->phase = node->p->transferActive; + node->phase = node->p->d.transferActive; #endif if (signal) { - node->p->signal(node->p, 1 << node->id); + node->p->d.signal(&node->p->d, 1 << node->id); } return 0; } static void _GBASIOLockstepNodeProcessEvents(struct mTiming* timing, void* user, uint32_t cyclesLate) { struct GBASIOLockstepNode* node = user; - if (node->p->attached < 2) { + if (node->p->d.attached < 2) { return; } int32_t cycles = 0; @@ -349,7 +340,7 @@ static void _GBASIOLockstepNodeProcessEvents(struct mTiming* timing, void* user, cycles = _masterUpdate(node); } else { cycles = _slaveUpdate(node); - cycles += node->p->useCycles(node->p, node->id, node->eventDiff); + cycles += node->p->d.useCycles(&node->p->d, node->id, node->eventDiff); } node->eventDiff = 0; } else { @@ -377,13 +368,13 @@ static uint16_t GBASIOLockstepNodeNormalWriteRegister(struct GBASIODriver* drive if (value & 0x0080 && !node->id) { // Internal shift clock if (value & 1) { - node->p->transferActive = TRANSFER_STARTING; + node->p->d.transferActive = TRANSFER_STARTING; } // Frequency if (value & 2) { - node->p->transferCycles = GBA_ARM7TDMI_FREQUENCY / 1024; + node->p->d.transferCycles = GBA_ARM7TDMI_FREQUENCY / 1024; } else { - node->p->transferCycles = GBA_ARM7TDMI_FREQUENCY / 8192; + node->p->d.transferCycles = GBA_ARM7TDMI_FREQUENCY / 8192; } } } else if (address == REG_SIODATA32_LO) { diff --git a/src/gba/test/core.c b/src/gba/test/core.c index 5864f3d05..acb0165af 100644 --- a/src/gba/test/core.c +++ b/src/gba/test/core.c @@ -5,8 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/test/suite.h" -#include "core/core.h" -#include "gba/core.h" +#include +#include M_TEST_DEFINE(create) { struct mCore* core = GBACoreCreate(); diff --git a/src/gba/test/gba.h b/src/gba/test/gba.h index c769e5320..1e50b1d39 100644 --- a/src/gba/test/gba.h +++ b/src/gba/test/gba.h @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef TEST_GBA_H #define TEST_GBA_H -#include "util/common.h" +#include int TestRunGBA(void); diff --git a/src/gba/timer.c b/src/gba/timer.c index 3ae17f50c..49722ed4d 100644 --- a/src/gba/timer.c +++ b/src/gba/timer.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "timer.h" +#include -#include "gba/gba.h" -#include "gba/io.h" +#include +#include static void GBATimerUpdate(struct mTiming* timing, struct GBA* gba, int timerId, uint32_t cyclesLate) { struct GBATimer* timer = &gba->timers[timerId]; diff --git a/src/gba/vfame.c b/src/gba/vfame.c index ae8b44cca..9dc6def16 100644 --- a/src/gba/vfame.c +++ b/src/gba/vfame.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include -#include "vfame.h" -#include "gba/gba.h" -#include "gba/memory.h" +#include +#include static const uint8_t ADDRESS_REORDERING[4][16] = { { 15, 14, 9, 1, 8, 10, 7, 3, 5, 11, 4, 0, 13, 12, 2, 6 }, diff --git a/src/gba/video.c b/src/gba/video.c index d05151486..bfd4e5175 100644 --- a/src/gba/video.c +++ b/src/gba/video.c @@ -3,18 +3,17 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "video.h" +#include -#include "core/sync.h" -#include "core/tile-cache.h" -#include "gba/dma.h" -#include "gba/gba.h" -#include "gba/io.h" -#include "gba/renderers/tile-cache.h" -#include "gba/rr/rr.h" -#include "gba/serialize.h" +#include +#include +#include +#include +#include +#include +#include -#include "util/memory.h" +#include mLOG_DEFINE_CATEGORY(GBA_VIDEO, "GBA Video"); diff --git a/src/lr35902/debugger/cli-debugger.c b/src/lr35902/debugger/cli-debugger.c index 349578dbf..65d65b0b7 100644 --- a/src/lr35902/debugger/cli-debugger.c +++ b/src/lr35902/debugger/cli-debugger.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "cli-debugger.h" +#include -#include "core/core.h" -#include "debugger/cli-debugger.h" -#include "lr35902/lr35902.h" +#include +#include +#include static void _printStatus(struct CLIDebuggerSystem*); diff --git a/src/lr35902/debugger/debugger.c b/src/lr35902/debugger/debugger.c index 620650aec..a5f08a394 100644 --- a/src/lr35902/debugger/debugger.c +++ b/src/lr35902/debugger/debugger.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "debugger.h" +#include -#include "lr35902/lr35902.h" -#include "core/core.h" +#include +#include DEFINE_VECTOR(LR35902DebugBreakpointList, struct LR35902DebugBreakpoint); DEFINE_VECTOR(LR35902DebugWatchpointList, struct LR35902DebugWatchpoint); diff --git a/src/lr35902/isa-lr35902.c b/src/lr35902/isa-lr35902.c index c9298f57d..a625662c8 100644 --- a/src/lr35902/isa-lr35902.c +++ b/src/lr35902/isa-lr35902.c @@ -3,10 +3,40 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "isa-lr35902.h" +#include -#include "lr35902/emitter-lr35902.h" -#include "lr35902/lr35902.h" +#include +#include + +static inline uint16_t LR35902ReadHL(struct LR35902Core* cpu) { + uint16_t hl; + LOAD_16LE(hl, 0, &cpu->hl); + return hl; +} + +static inline void LR35902WriteHL(struct LR35902Core* cpu, uint16_t hl) { + STORE_16LE(hl, 0, &cpu->hl); +} + +static inline uint16_t LR35902ReadBC(struct LR35902Core* cpu) { + uint16_t bc; + LOAD_16LE(bc, 0, &cpu->bc); + return bc; +} + +static inline void LR35902WriteBC(struct LR35902Core* cpu, uint16_t bc) { + STORE_16LE(bc, 0, &cpu->bc); +} + +static inline uint16_t LR35902ReadDE(struct LR35902Core* cpu) { + uint16_t de; + LOAD_16LE(de, 0, &cpu->de); + return de; +} + +static inline void LR35902WriteDE(struct LR35902Core* cpu, uint16_t de) { + STORE_16LE(de, 0, &cpu->de); +} #define DEFINE_INSTRUCTION_LR35902(NAME, BODY) \ static void _LR35902Instruction ## NAME (struct LR35902Core* cpu) { \ diff --git a/src/lr35902/lr35902.c b/src/lr35902/lr35902.c index 5b6255b2c..8d1f3f005 100644 --- a/src/lr35902/lr35902.c +++ b/src/lr35902/lr35902.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "lr35902.h" +#include -#include "isa-lr35902.h" +#include void LR35902Init(struct LR35902Core* cpu) { cpu->master->init(cpu, cpu->master); diff --git a/src/platform/3ds/3ds-memory.c b/src/platform/3ds/3ds-memory.c index e3417c828..c37e4637b 100644 --- a/src/platform/3ds/3ds-memory.c +++ b/src/platform/3ds/3ds-memory.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/memory.h" +#include #include <3ds.h> diff --git a/src/platform/3ds/3ds-vfs.c b/src/platform/3ds/3ds-vfs.c index 11e894c95..9de4b1ab3 100644 --- a/src/platform/3ds/3ds-vfs.c +++ b/src/platform/3ds/3ds-vfs.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "3ds-vfs.h" +#include #ifdef USE_VFS_3DS -#include "util/memory.h" -#include "util/string.h" +#include +#include struct VFile3DS { struct VFile d; diff --git a/src/platform/3ds/ctru-heap.c b/src/platform/3ds/ctru-heap.c index f1639687c..42608f8b9 100644 --- a/src/platform/3ds/ctru-heap.c +++ b/src/platform/3ds/ctru-heap.c @@ -28,7 +28,7 @@ #include <3ds/services/hid.h> #include <3ds/svc.h> -#include "util/common.h" +#include extern char* fake_heap_start; extern char* fake_heap_end; diff --git a/src/platform/3ds/gui-font.c b/src/platform/3ds/gui-font.c index 2b79e730d..3c1abc0a0 100644 --- a/src/platform/3ds/gui-font.c +++ b/src/platform/3ds/gui-font.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/gui/font.h" -#include "util/gui/font-metrics.h" -#include "util/png-io.h" -#include "util/vfs.h" +#include +#include +#include +#include #include "icons.h" #include "ctr-gpu.h" diff --git a/src/platform/3ds/main.c b/src/platform/3ds/main.c index 727ab71fa..0d17ba9fa 100644 --- a/src/platform/3ds/main.c +++ b/src/platform/3ds/main.c @@ -4,22 +4,24 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include +#include #ifdef M_CORE_GBA -#include "gba/gba.h" -#include "gba/input.h" -#include "gba/video.h" +#include +#include +#include #endif #ifdef M_CORE_GB -#include "gb/gb.h" +#include #endif #include "feature/gui/gui-runner.h" -#include "util/gui.h" -#include "util/gui/file-select.h" -#include "util/gui/font.h" -#include "util/gui/menu.h" -#include "util/memory.h" +#include +#include +#include +#include +#include -#include "3ds-vfs.h" +#include #include "ctr-gpu.h" #include <3ds.h> diff --git a/src/platform/3ds/socket.c b/src/platform/3ds/socket.c index d15c6500b..6c380ec49 100644 --- a/src/platform/3ds/socket.c +++ b/src/platform/3ds/socket.c @@ -3,6 +3,6 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/socket.h" +#include u32* SOCUBuffer = NULL; diff --git a/src/platform/example/client-server/client.c b/src/platform/example/client-server/client.c index c80e54df0..86d8fdc6f 100644 --- a/src/platform/example/client-server/client.c +++ b/src/platform/example/client-server/client.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "core/core.h" -#include "core/version.h" -#include "util/socket.h" +#include +#include +#include #include diff --git a/src/platform/example/client-server/server.c b/src/platform/example/client-server/server.c index b1e05a81d..75af4edb1 100644 --- a/src/platform/example/client-server/server.c +++ b/src/platform/example/client-server/server.c @@ -1,7 +1,7 @@ // This source file is placed into the public domain. -#include "core/core.h" +#include #include "feature/commandline.h" -#include "util/socket.h" +#include #define DEFAULT_PORT 13721 diff --git a/src/platform/libretro/libretro.c b/src/platform/libretro/libretro.c index 40f8ba00b..1f7727f5b 100644 --- a/src/platform/libretro/libretro.c +++ b/src/platform/libretro/libretro.c @@ -5,24 +5,24 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "libretro.h" -#include "util/common.h" +#include -#include "core/core.h" -#include "core/version.h" +#include +#include +#include +#include #ifdef M_CORE_GB -#include "gb/core.h" -#include "gb/gb.h" +#include #endif #ifdef M_CORE_GBA -#include "gba/bios.h" -#include "gba/core.h" -#include "gba/cheats.h" -#include "gba/core.h" -#include "gba/serialize.h" +#include +#include +#include +#include #endif -#include "util/circle-buffer.h" -#include "util/memory.h" -#include "util/vfs.h" +#include +#include +#include #define SAMPLES 1024 #define RUMBLE_PWM 35 @@ -146,7 +146,7 @@ void retro_get_system_av_info(struct retro_system_av_info* info) { info->geometry.max_width = width; info->geometry.max_height = height; info->geometry.aspect_ratio = width / (double) height; - info->timing.fps = GBA_ARM7TDMI_FREQUENCY / (float) VIDEO_TOTAL_LENGTH; + info->timing.fps = core->frequency(core) / (float) core->frameCycles(core); info->timing.sample_rate = 32768; } @@ -413,7 +413,7 @@ bool retro_load_game(const struct retro_game_info* game) { gba->luminanceSource = &lux; const char* sysDir = 0; - if (environCallback(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &sysDir)) { + if (core->opts.useBios && environCallback(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &sysDir)) { char biosPath[PATH_MAX]; snprintf(biosPath, sizeof(biosPath), "%s%s%s", sysDir, PATH_SEP, "gba_bios.bin"); struct VFile* bios = VFileOpen(biosPath, O_RDONLY); @@ -443,14 +443,14 @@ void retro_unload_game(void) { } size_t retro_serialize_size(void) { - return sizeof(struct GBASerializedState); + return core->stateSize(core); } bool retro_serialize(void* data, size_t size) { if (size != retro_serialize_size()) { return false; } - GBASerialize(core->board, data); + core->saveState(core, data); return true; } @@ -458,7 +458,7 @@ bool retro_unserialize(const void* data, size_t size) { if (size != retro_serialize_size()) { return false; } - GBADeserialize(core->board, data); + core->loadState(core, data); return true; } diff --git a/src/platform/openemu/mGBAGameCore.m b/src/platform/openemu/mGBAGameCore.m index 91ef7b892..1ddf5482f 100644 --- a/src/platform/openemu/mGBAGameCore.m +++ b/src/platform/openemu/mGBAGameCore.m @@ -24,17 +24,18 @@ #import "mGBAGameCore.h" -#include "util/common.h" +#include -#include "core/serialize.h" -#include "core/core.h" -#include "gba/cheats.h" -#include "gba/core.h" -#include "gba/gba.h" -#include "gba/input.h" -#include "util/circle-buffer.h" -#include "util/memory.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #import #import "OEGBASystemResponderClient.h" @@ -129,8 +130,8 @@ - (void)setupEmulation { - blip_set_rates(core->getAudioChannel(core, 0), GBA_ARM7TDMI_FREQUENCY, 32768); - blip_set_rates(core->getAudioChannel(core, 1), GBA_ARM7TDMI_FREQUENCY, 32768); + blip_set_rates(core->getAudioChannel(core, 0), core->frequency(core), 32768); + blip_set_rates(core->getAudioChannel(core, 1), core->frequency(core), 32768); } #pragma mark - Video @@ -176,7 +177,7 @@ - (NSTimeInterval)frameInterval { - return GBA_ARM7TDMI_FREQUENCY / (double) VIDEO_TOTAL_LENGTH; + return core->frequency(core) / (double) core->frameCycles(core); } #pragma mark - Audio diff --git a/src/platform/opengl/gl.c b/src/platform/opengl/gl.c index 51bb64365..31bb101aa 100644 --- a/src/platform/opengl/gl.c +++ b/src/platform/opengl/gl.c @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "gl.h" -#include "util/math.h" +#include static const GLint _glVertices[] = { 0, 0, diff --git a/src/platform/opengl/gl.h b/src/platform/opengl/gl.h index 0370e2ea7..a6412e919 100644 --- a/src/platform/opengl/gl.h +++ b/src/platform/opengl/gl.h @@ -6,6 +6,10 @@ #ifndef GL_H #define GL_H +#include + +CXX_GUARD_START + #ifdef USE_EPOXY #include #elif defined(__APPLE__) @@ -27,4 +31,6 @@ struct mGLContext { void mGLContextCreate(struct mGLContext*); +CXX_GUARD_END + #endif diff --git a/src/platform/opengl/gles2.c b/src/platform/opengl/gles2.c index 604384055..781217e57 100644 --- a/src/platform/opengl/gles2.c +++ b/src/platform/opengl/gles2.c @@ -5,11 +5,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "gles2.h" -#include "core/log.h" -#include "util/configuration.h" -#include "util/formatting.h" -#include "util/vector.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include mLOG_DECLARE_CATEGORY(OPENGL); mLOG_DEFINE_CATEGORY(OPENGL, "OpenGL"); diff --git a/src/platform/opengl/gles2.h b/src/platform/opengl/gles2.h index fabdebc14..f6d050bc9 100644 --- a/src/platform/opengl/gles2.h +++ b/src/platform/opengl/gles2.h @@ -6,6 +6,10 @@ #ifndef GLES2_H #define GLES2_H +#include + +CXX_GUARD_START + #ifdef USE_EPOXY #include #elif defined(BUILD_GL) @@ -94,4 +98,6 @@ struct VDir; bool mGLES2ShaderLoad(struct VideoShader*, struct VDir*); void mGLES2ShaderFree(struct VideoShader*); +CXX_GUARD_END + #endif diff --git a/src/platform/posix/memory.c b/src/platform/posix/memory.c index 47760275e..7892a5985 100644 --- a/src/platform/posix/memory.c +++ b/src/platform/posix/memory.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/memory.h" +#include #include diff --git a/src/platform/psp2/gui-font.c b/src/platform/psp2/gui-font.c index 37c94be7b..f0296d541 100644 --- a/src/platform/psp2/gui-font.c +++ b/src/platform/psp2/gui-font.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/gui/font.h" -#include "util/gui/font-metrics.h" -#include "util/string.h" +#include +#include +#include #include diff --git a/src/platform/psp2/main.c b/src/platform/psp2/main.c index c184c419d..95dabc13c 100644 --- a/src/platform/psp2/main.c +++ b/src/platform/psp2/main.c @@ -5,12 +5,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "psp2-context.h" -#include "gba/gba.h" +#include #include "feature/gui/gui-runner.h" -#include "util/gui.h" -#include "util/gui/font.h" -#include "util/gui/file-select.h" -#include "util/gui/menu.h" +#include +#include +#include +#include #include #include diff --git a/src/platform/psp2/psp2-common.h b/src/platform/psp2/psp2-common.h index 18e70067a..7f34d1d10 100644 --- a/src/platform/psp2/psp2-common.h +++ b/src/platform/psp2/psp2-common.h @@ -6,7 +6,7 @@ #ifndef PSP2_COMMON_H #define PSP2_COMMON_H -#include "util/common.h" +#include #define PSP2_HORIZONTAL_PIXELS 960 #define PSP2_VERTICAL_PIXELS 544 diff --git a/src/platform/psp2/psp2-context.c b/src/platform/psp2/psp2-context.c index 8b75af17c..f58ee6a1d 100644 --- a/src/platform/psp2/psp2-context.c +++ b/src/platform/psp2/psp2-context.c @@ -5,25 +5,25 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "psp2-context.h" -#include "core/core.h" +#include +#include #ifdef M_CORE_GBA -#include "gba/gba.h" +#include #endif #ifdef M_CORE_GB -#include "gb/gb.h" +#include #endif #include "feature/gui/gui-runner.h" -#include "gba/input.h" +#include -#include "util/memory.h" -#include "util/circle-buffer.h" -#include "util/ring-fifo.h" -#include "util/threading.h" -#include "util/vfs.h" -#include "platform/psp2/sce-vfs.h" -#include "third-party/blip_buf/blip_buf.h" +#include +#include +#include +#include +#include +#include #include #include diff --git a/src/platform/psp2/psp2-context.h b/src/platform/psp2/psp2-context.h index 6702c39d7..28a403ba3 100644 --- a/src/platform/psp2/psp2-context.h +++ b/src/platform/psp2/psp2-context.h @@ -7,8 +7,8 @@ #define PSP2_CONTEXT_H #include "psp2-common.h" -#include "core/interface.h" -#include "util/gui.h" +#include +#include struct mGUIRunner; void mPSP2Setup(struct mGUIRunner* runner); diff --git a/src/platform/psp2/psp2-memory.c b/src/platform/psp2/psp2-memory.c index 1118ee901..7ff56318b 100644 --- a/src/platform/psp2/psp2-memory.c +++ b/src/platform/psp2/psp2-memory.c @@ -3,8 +3,8 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/memory.h" -#include "util/vector.h" +#include +#include #include #include diff --git a/src/platform/psp2/sce-vfs.c b/src/platform/psp2/sce-vfs.c index 4a1e1c559..4b6fdce52 100644 --- a/src/platform/psp2/sce-vfs.c +++ b/src/platform/psp2/sce-vfs.c @@ -3,12 +3,12 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "sce-vfs.h" +#include #include -#include "util/vfs.h" -#include "util/memory.h" +#include +#include struct VFileSce { struct VFile d; diff --git a/src/platform/python/CMakeLists.txt b/src/platform/python/CMakeLists.txt new file mode 100644 index 000000000..adda679bd --- /dev/null +++ b/src/platform/python/CMakeLists.txt @@ -0,0 +1,12 @@ +find_program(PYTHON python) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py) + +add_custom_command(OUTPUT build/lib/${BINARY_NAME}/__init__.py + COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build --build-base ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${BINARY_NAME} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setup.py + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py) + +add_custom_target(${BINARY_NAME}-py ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/build/lib/${BINARY_NAME}/__init__.py) diff --git a/src/platform/python/_builder.h b/src/platform/python/_builder.h new file mode 100644 index 000000000..58a214d93 --- /dev/null +++ b/src/platform/python/_builder.h @@ -0,0 +1,49 @@ +#define COMMON_H +#define PNG_H +#define _SYS_TIME_H +#define _SYS_TIME_H_ +#define _TIME_H +#define _TIME_H_ + +#define ATTRIBUTE_FORMAT(X, Y, Z) +#define DECL_BITFIELD(newtype, oldtype) typedef oldtype newtype +#define DECL_BIT(type, name, bit) +#define DECL_BITS(type, name, bit, nbits) + +#define CXX_GUARD_START +#define CXX_GUARD_END + +typedef int... time_t; +typedef int... off_t; +typedef ... va_list; +typedef ...* png_structp; +typedef ...* png_infop; +typedef ...* png_unknown_chunkp; + +void free(void*); + +#include +#undef const + +#include "flags.h" + +#include +#include +#include "platform/python/vfs-py.h" +#include "platform/python/log.h" + +#ifdef USE_PNG +#include +#endif +#ifdef M_CORE_GBA +#include +#include +#include +#include +#endif +#ifdef M_CORE_GB +#include +#include +#include +#include +#endif diff --git a/src/platform/python/_builder.py b/src/platform/python/_builder.py new file mode 100644 index 000000000..94babdb55 --- /dev/null +++ b/src/platform/python/_builder.py @@ -0,0 +1,65 @@ +import cffi +import os, os.path +import shlex +import subprocess +import sys + +ffi = cffi.FFI() +pydir = os.path.dirname(os.path.abspath(__file__)) +srcdir = os.path.join(pydir, "..", "..") +incdir = os.path.join(pydir, "..", "..", "..", "include") +bindir = os.environ.get("BINDIR", os.path.join(os.getcwd(), "..")) + +cpp = shlex.split(os.environ.get("CPP", "cc -E")) +cppflags = shlex.split(os.environ.get("CPPFLAGS", "")) +if __name__ == "__main__": + cppflags.extend(sys.argv[1:]) +cppflags.extend(["-I" + incdir, "-I" + srcdir, "-I" + bindir]) + +ffi.set_source("mgba._pylib", """ +#include "flags.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct VFile* VFileFromPython(void* fileobj); + +struct VFilePy { + struct VFile d; + void* fileobj; +}; + +struct mLogger* mLoggerPythonCreate(void* pyobj); + +struct mLoggerPy { + struct mLogger d; + void* pyobj; +}; +""", include_dirs=[incdir, srcdir], + extra_compile_args=cppflags, + libraries=["mgba"], + library_dirs=[bindir], + sources=[os.path.join(pydir, path) for path in ["vfs-py.c", "log.c"]]) + +preprocessed = subprocess.check_output(cpp + ["-fno-inline", "-P"] + cppflags + [os.path.join(pydir, "_builder.h")], universal_newlines=True) + +lines = [] +for line in preprocessed.splitlines(): + line = line.strip() + if line.startswith('#'): + continue + lines.append(line) +ffi.cdef('\n'.join(lines)) + +if __name__ == "__main__": + ffi.compile() diff --git a/src/platform/python/log.c b/src/platform/python/log.c new file mode 100644 index 000000000..6066da4a0 --- /dev/null +++ b/src/platform/python/log.c @@ -0,0 +1,27 @@ +/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + +struct mLoggerPy { + struct mLogger d; + void* pyobj; +}; + +void _pyLog(void* logger, int category, enum mLogLevel level, const char* message); + +static void _pyLogShim(struct mLogger* logger, int category, enum mLogLevel level, const char* format, va_list args) { + struct mLoggerPy* pylogger = (struct mLoggerPy*) logger; + char message[256] = {0}; + vsnprintf(message, sizeof(message) - 1, format, args); + _pyLog(pylogger, category, level, message); +} + +struct mLogger* mLoggerPythonCreate(void* pyobj) { + struct mLoggerPy* logger = malloc(sizeof(*logger)); + logger->d.log = _pyLogShim; + logger->pyobj = pyobj; + return &logger->d; +} diff --git a/src/platform/python/log.h b/src/platform/python/log.h new file mode 100644 index 000000000..f29dba8bb --- /dev/null +++ b/src/platform/python/log.h @@ -0,0 +1,15 @@ +/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + +struct mLoggerPy { + struct mLogger d; + void* pyobj; +}; + +struct mLogger* mLoggerPythonCreate(void* pyobj); + +extern "Python+C" void _pyLog(void* logger, int category, enum mLogLevel level, const char* message); diff --git a/src/platform/python/mgba/__init__.py b/src/platform/python/mgba/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/platform/python/mgba/arm.py b/src/platform/python/mgba/arm.py new file mode 100644 index 000000000..a594a6823 --- /dev/null +++ b/src/platform/python/mgba/arm.py @@ -0,0 +1,28 @@ +# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +from ._pylib import ffi, lib + +class _ARMRegisters: + def __init__(self, cpu): + self._cpu = cpu + + def __getitem__(self, r): + if r > lib.ARM_PC: + raise IndexError("Register out of range") + return self._cpu._native.gprs[r] + + def __setitem__(self, r, value): + if r >= lib.ARM_PC: + raise IndexError("Register out of range") + self._cpu._native.gprs[r] = value + +class ARMCore: + def __init__(self, native): + self._native = ffi.cast("struct ARMCore*", native) + self.gprs = _ARMRegisters(self) + self.cpsr = self._native.cpsr + self.spsr = self._native.spsr + diff --git a/src/platform/python/mgba/core.py b/src/platform/python/mgba/core.py new file mode 100644 index 000000000..8d86e3127 --- /dev/null +++ b/src/platform/python/mgba/core.py @@ -0,0 +1,162 @@ +# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +from ._pylib import ffi, lib +from . import tile +from cached_property import cached_property + +def find(path): + core = lib.mCoreFind(path.encode('UTF-8')) + if core == ffi.NULL: + return None + return Core._init(core) + +def findVF(vf): + core = lib.mCoreFindVF(vf.handle) + if core == ffi.NULL: + return None + return Core._init(core) + +def loadPath(path): + core = find(path) + if not core or not core.loadFile(path): + return None + return core + +def loadVF(vf): + core = findVF(vf) + if not core or not core.loadROM(vf): + return None + return core + +def needsReset(f): + def wrapper(self, *args, **kwargs): + if not self._wasReset: + raise RuntimeError("Core must be reset first") + return f(self, *args, **kwargs) + return wrapper + +class Core(object): + def __init__(self, native): + self._core = native + self._wasReset = False + + @cached_property + def tiles(self): + return tile.TileView(self) + + @classmethod + def _init(cls, native): + core = ffi.gc(native, native.deinit) + success = bool(core.init(core)) + if not success: + raise RuntimeError("Failed to initialize core") + if hasattr(cls, 'PLATFORM_GBA') and core.platform(core) == cls.PLATFORM_GBA: + return GBA(core) + if hasattr(cls, 'PLATFORM_GB') and core.platform(core) == cls.PLATFORM_GB: + return GB(core) + return Core(core) + + def _deinit(self): + self._core.deinit(self._core) + + def loadFile(self, path): + return bool(lib.mCoreLoadFile(self._core, path.encode('UTF-8'))) + + def isROM(self, vf): + return bool(self._core.isROM(vf.handle)) + + def loadROM(self, vf): + return bool(self._core.loadROM(self._core, vf.handle)) + + def loadSave(self, vf): + return bool(self._core.loadSave(self._core, vf.handle)) + + def loadTemporarySave(self, vf): + return bool(self._core.loadTemporarySave(self._core, vf.handle)) + + def loadPatch(self, vf): + return bool(self._core.loadPatch(self._core, vf.handle)) + + def autoloadSave(self): + return bool(lib.mCoreAutoloadSave(self._core)) + + def autoloadPatch(self): + return bool(lib.mCoreAutoloadPatch(self._core)) + + def platform(self): + return self._core.platform(self._core) + + def desiredVideoDimensions(self): + width = ffi.new("unsigned*") + height = ffi.new("unsigned*") + self._core.desiredVideoDimensions(self._core, width, height) + return width[0], height[0] + + def setVideoBuffer(self, image): + self._core.setVideoBuffer(self._core, image.buffer, image.stride) + + def reset(self): + self._core.reset(self._core) + self._wasReset = True + + @needsReset + def runFrame(self): + self._core.runFrame(self._core) + + @needsReset + def runLoop(self): + self._core.runLoop(self._core) + + @needsReset + def step(self): + self._core.step(self._core) + + @staticmethod + def _keysToInt(*args, **kwargs): + keys = 0 + if 'raw' in kwargs: + keys = kwargs['raw'] + for key in args: + keys |= 1 << key + return keys + + def setKeys(self, *args, **kwargs): + self._core.setKeys(self._core, self._keysToInt(*args, **kwargs)) + + def addKeys(self, *args, **kwargs): + self._core.addKeys(self._core, self._keysToInt(*args, **kwargs)) + + def clearKeys(self, *args, **kwargs): + self._core.clearKeys(self._core, self._keysToInt(*args, **kwargs)) + + @needsReset + def frameCounter(self): + return self._core.frameCounter(self._core) + + def frameCycles(self): + return self._core.frameCycles(self._core) + + def frequency(self): + return self._core.frequency(self._core) + + def getGameTitle(self): + title = ffi.new("char[16]") + self._core.getGameTitle(self._core, title) + return ffi.string(title, 16).decode("ascii") + + def getGameCode(self): + code = ffi.new("char[12]") + self._core.getGameCode(self._core, code) + return ffi.string(code, 12).decode("ascii") + +if hasattr(lib, 'PLATFORM_GBA'): + from .gba import GBA + Core.PLATFORM_GBA = lib.PLATFORM_GBA + +if hasattr(lib, 'PLATFORM_GB'): + from .gb import GB + from .lr35902 import LR35902Core + Core.PLATFORM_GB = lib.PLATFORM_GB diff --git a/src/platform/python/mgba/gb.py b/src/platform/python/mgba/gb.py new file mode 100644 index 000000000..0caf7ec99 --- /dev/null +++ b/src/platform/python/mgba/gb.py @@ -0,0 +1,81 @@ +# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +from ._pylib import ffi, lib +from .lr35902 import LR35902Core +from .core import Core, needsReset +from .memory import Memory +from .tile import Sprite + +class GB(Core): + KEY_A = lib.GBA_KEY_A + KEY_B = lib.GBA_KEY_B + KEY_SELECT = lib.GBA_KEY_SELECT + KEY_START = lib.GBA_KEY_START + KEY_DOWN = lib.GBA_KEY_DOWN + KEY_UP = lib.GBA_KEY_UP + KEY_LEFT = lib.GBA_KEY_LEFT + KEY_RIGHT = lib.GBA_KEY_RIGHT + + def __init__(self, native): + super(GB, self).__init__(native) + self._native = ffi.cast("struct GB*", native.board) + self.sprites = GBObjs(self) + self.cpu = LR35902Core(self._core.cpu) + + @needsReset + def _initTileCache(self, cache): + lib.GBVideoTileCacheInit(cache) + lib.GBVideoTileCacheAssociate(cache, ffi.addressof(self._native.video)) + + def _deinitTileCache(self, cache): + self._native.video.renderer.cache = ffi.NULL + lib.mTileCacheDeinit(cache) + +class GBMemory(Memory): + def __init__(self, core): + super(GBMemory, self).__init__(core, 0x10000) + + self.cart = Memory(core, lib.GB_SIZE_CART_BANK0 * 2, lib.GB_BASE_CART_BANK0) + self.vram = Memory(core, lib.GB_SIZE_VRAM, lib.GB_BASE_VRAM) + self.sram = Memory(core, lib.GB_SIZE_EXTERNAL_RAM, lib.GB_REGION_EXTERNAL_RAM) + self.iwram = Memory(core, lib.GB_SIZE_WORKING_RAM_BANK0, lib.GB_BASE_WORKING_RAM_BANK0) + self.oam = Memory(core, lib.GB_SIZE_OAM, lib.GB_BASE_OAM) + self.io = Memory(core, lib.GB_SIZE_IO, lib.GB_BASE_IO) + self.hram = Memory(core, lib.GB_SIZE_HRAM, lib.GB_BASE_HRAM) + +class GBSprite(Sprite): + PALETTE_BASE = 8, + + def __init__(self, obj, core): + self.x = obj.x + self.y = obj.y + self.tile = obj.tile + self._attr = obj.attr + self.width = 8 + lcdc = core._native.memory.io[0x40] + self.height = 16 if lcdc & 4 else 8 + if core._native.model >= lib.GB_MODEL_CGB: + if self._attr & 8: + self.tile += 512 + self.paletteId = self._attr & 7 + else: + self.paletteId = (self._attr >> 4) & 1 + + +class GBObjs: + def __init__(self, core): + self._core = core + self._obj = core._native.video.oam.obj + + def __len__(self): + return 40 + + def __getitem__(self, index): + if index >= len(self): + raise IndexError() + sprite = GBSprite(self._obj[index], self._core) + sprite.constitute(self._core.tiles, 0, 0) + return sprite diff --git a/src/platform/python/mgba/gba.py b/src/platform/python/mgba/gba.py new file mode 100644 index 000000000..0b8e12fee --- /dev/null +++ b/src/platform/python/mgba/gba.py @@ -0,0 +1,96 @@ +# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +from ._pylib import ffi, lib +from .arm import ARMCore +from .core import Core, needsReset +from .tile import Sprite +from .memory import Memory + +class GBA(Core): + KEY_A = lib.GBA_KEY_A + KEY_B = lib.GBA_KEY_B + KEY_SELECT = lib.GBA_KEY_SELECT + KEY_START = lib.GBA_KEY_START + KEY_DOWN = lib.GBA_KEY_DOWN + KEY_UP = lib.GBA_KEY_UP + KEY_LEFT = lib.GBA_KEY_LEFT + KEY_RIGHT = lib.GBA_KEY_RIGHT + KEY_L = lib.GBA_KEY_L + KEY_R = lib.GBA_KEY_R + + def __init__(self, native): + super(GBA, self).__init__(native) + self._native = ffi.cast("struct GBA*", native.board) + self.sprites = GBAObjs(self) + self.cpu = ARMCore(self._core.cpu) + + @needsReset + def _initTileCache(self, cache): + lib.GBAVideoTileCacheInit(cache) + lib.GBAVideoTileCacheAssociate(cache, ffi.addressof(self._native.video)) + + def _deinitTileCache(self, cache): + self._native.video.renderer.cache = ffi.NULL + lib.mTileCacheDeinit(cache) + + def reset(self): + super(GBA, self).reset() + self.memory = GBAMemory(self._core, self._native.memory.romSize) + +class GBAMemory(Memory): + def __init__(self, core, romSize=lib.SIZE_CART0): + super(GBAMemory, self).__init__(core, 0x100000000) + + self.bios = Memory(core, lib.SIZE_BIOS, lib.BASE_BIOS) + self.wram = Memory(core, lib.SIZE_WORKING_RAM, lib.BASE_WORKING_RAM) + self.iwram = Memory(core, lib.SIZE_WORKING_IRAM, lib.BASE_WORKING_IRAM) + self.io = Memory(core, lib.SIZE_IO, lib.BASE_IO) + self.palette = Memory(core, lib.SIZE_PALETTE_RAM, lib.BASE_PALETTE_RAM) + self.vram = Memory(core, lib.SIZE_VRAM, lib.BASE_VRAM) + self.oam = Memory(core, lib.SIZE_OAM, lib.BASE_OAM) + self.cart0 = Memory(core, romSize, lib.BASE_CART0) + self.cart1 = Memory(core, romSize, lib.BASE_CART1) + self.cart2 = Memory(core, romSize, lib.BASE_CART2) + self.cart = self.cart0 + self.rom = self.cart0 + self.sram = Memory(core, lib.SIZE_CART_SRAM, lib.BASE_CART_SRAM) + +class GBASprite(Sprite): + TILE_BASE = 0x800, 0x400 + PALETTE_BASE = 0x10, 1 + + def __init__(self, obj): + self._a = obj.a + self._b = obj.b + self._c = obj.c + self.x = self._b & 0x1FF + self.y = self._a & 0xFF + self._shape = self._a >> 14 + self._size = self._b >> 14 + self._256Color = bool(self._a & 0x2000) + self.width, self.height = lib.GBAVideoObjSizes[self._shape * 4 + self._size] + self.tile = self._c & 0x3FF + if self._256Color: + self.paletteId = 0 + self.tile >>= 1 + else: + self.paletteId = self._c >> 12 + +class GBAObjs: + def __init__(self, core): + self._core = core + self._obj = core._native.video.oam.obj + + def __len__(self): + return 128 + + def __getitem__(self, index): + if index >= len(self): + raise IndexError() + sprite = GBASprite(self._obj[index]) + map1D = bool(self._core._native.memory.io[0] & 0x40) + sprite.constitute(self._core.tiles, 0 if map1D else 0x20, int(sprite._256Color)) + return sprite diff --git a/src/platform/python/mgba/image.py b/src/platform/python/mgba/image.py new file mode 100644 index 000000000..f76945b32 --- /dev/null +++ b/src/platform/python/mgba/image.py @@ -0,0 +1,69 @@ +# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +from ._pylib import ffi, lib +from . import png + +class Image: + def __init__(self, width, height, stride=0): + self.width = width + self.height = height + self.stride = stride + self.constitute() + + def constitute(self): + if self.stride <= 0: + self.stride = self.width + self.buffer = ffi.new("color_t[{}]".format(self.stride * self.height)) + + def savePNG(self, f): + p = png.PNG(f) + success = p.writeHeader(self) + success = success and p.writePixels(self) + p.writeClose() + return success + +def u16ToU32(c): + r = c & 0x1F + g = (c >> 5) & 0x1F + b = (c >> 10) & 0x1F + a = (c >> 15) & 1 + abgr = r << 3 + abgr |= g << 11 + abgr |= b << 19 + abgr |= (a * 0xFF) << 24 + return abgr + +def u32ToU16(c): + r = (c >> 3) & 0x1F + g = (c >> 11) & 0x1F + b = (c >> 19) & 0x1F + a = c >> 31 + abgr = r + abgr |= g << 5 + abgr |= b << 10 + abgr |= a << 15 + return abgr + +if ffi.sizeof("color_t") == 2: + def colorToU16(c): + return c + + colorToU32 = u16ToU32 + + def u16ToColor(c): + return c + + u32ToColor = u32ToU16 +else: + def colorToU32(c): + return c + + colorToU16 = u32ToU16 + + def u32ToColor(c): + return c + + u16ToColor = u16ToU32 diff --git a/src/platform/python/mgba/log.py b/src/platform/python/mgba/log.py new file mode 100644 index 000000000..a3412b186 --- /dev/null +++ b/src/platform/python/mgba/log.py @@ -0,0 +1,38 @@ +# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +from ._pylib import ffi, lib + +@ffi.def_extern() +def _pyLog(logger, category, level, message): + l = ffi.cast("struct mLoggerPy*", logger) + ffi.from_handle(l.pyobj).log(category, level, ffi.string(message).decode('UTF-8')) + +def installDefault(logger): + lib.mLogSetDefaultLogger(logger._native) + +class Logger(object): + FATAL = lib.mLOG_FATAL + DEBUG = lib.mLOG_DEBUG + INFO = lib.mLOG_INFO + WARN = lib.mLOG_WARN + ERROR = lib.mLOG_ERROR + STUB = lib.mLOG_STUB + GAME_ERROR = lib.mLOG_GAME_ERROR + + def __init__(self): + self._handle = ffi.new_handle(self) + self._native = ffi.gc(lib.mLoggerPythonCreate(self._handle), lib.free) + + @staticmethod + def categoryName(category): + return ffi.string(lib.mLogCategoryName(category)).decode('UTF-8') + + def log(self, category, level, message): + print("{}: {}".format(self.categoryName(category), message)) + +class NullLogger(Logger): + def log(self, category, level, message): + pass diff --git a/src/platform/python/mgba/lr35902.py b/src/platform/python/mgba/lr35902.py new file mode 100644 index 000000000..77400c0b0 --- /dev/null +++ b/src/platform/python/mgba/lr35902.py @@ -0,0 +1,123 @@ +# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +from ._pylib import ffi, lib + +class LR35902Core: + def __init__(self, native): + self._native = ffi.cast("struct LR35902Core*", native) + + @property + def a(self): + return self._native.a + + @property + def b(self): + return self._native.b + + @property + def c(self): + return self._native.c + + @property + def d(self): + return self._native.d + + @property + def e(self): + return self._native.e + + @property + def f(self): + return self._native.f + + @property + def h(self): + return self._native.h + + @property + def l(self): + return self._native.l + + @property + def sp(self): + return self._native.sp + + @property + def pc(self): + return self._native.pc + + @property + def af(self): + return (self.a << 8) | self.f + + @property + def bc(self): + return (self.b << 8) | self.c + + @property + def de(self): + return (self.d << 8) | self.e + + @property + def hl(self): + return (self.h << 8) | self.l + + @a.setter + def a(self, value): + self._native.a = value + + @b.setter + def b(self, value): + self._native.b = value + + @c.setter + def c(self, value): + self._native.c = value + + @d.setter + def d(self, value): + self._native.d = value + + @e.setter + def e(self, value): + self._native.e = value + + @f.setter + def f(self, value): + self._native.f.packed = value + self._native.f.unused = 0 + + @h.setter + def h(self, value): + self._native.h = value + + @l.setter + def l(self, value): + self._native.l = value + + @sp.setter + def sp(self, value): + self._native.sp = value + + @af.setter + def af(self, value): + self.a = value >> 8 + self.f = value & 0xFF + + @bc.setter + def bc(self, value): + self.b = value >> 8 + self.c = value & 0xFF + + @de.setter + def de(self, value): + self.d = value >> 8 + self.e = value & 0xFF + + @hl.setter + def hl(self, value): + self.h = value >> 8 + self.l = value & 0xFF diff --git a/src/platform/python/mgba/memory.py b/src/platform/python/mgba/memory.py new file mode 100644 index 000000000..a7f52e22e --- /dev/null +++ b/src/platform/python/mgba/memory.py @@ -0,0 +1,83 @@ +# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +from ._pylib import ffi, lib + +class MemoryView(object): + def __init__(self, core, width, size, base=0, sign="u"): + self._core = core + self._width = width + self._size = size + self._base = base + self._busRead = getattr(self._core, "busRead" + str(width * 8)) + self._busWrite = getattr(self._core, "busWrite" + str(width * 8)) + self._rawRead = getattr(self._core, "rawRead" + str(width * 8)) + self._rawWrite = getattr(self._core, "rawWrite" + str(width * 8)) + self._mask = (1 << (width * 8)) - 1 # Used to force values to fit within range so that negative values work + if sign == "u" or sign == "unsigned": + self._type = "uint{}_t".format(width * 8) + elif sign == "i" or sign == "s" or sign == "signed": + self._type = "int{}_t".format(width * 8) + else: + raise ValueError("Invalid sign type: '{}'".format(sign)) + + def _addrCheck(self, address): + if isinstance(address, slice): + start = address.start or 0 + stop = self._size - self._width if address.stop is None else address.stop + else: + start = address + stop = address + self._width + if start >= self._size or stop > self._size: + raise IndexError() + if start < 0 or stop < 0: + raise IndexError() + + def __len__(self): + return self._size + + def __getitem__(self, address): + self._addrCheck(address) + if isinstance(address, slice): + start = address.start or 0 + stop = self._size - self._width if address.stop is None else address.stop + step = address.step or self._width + return [int(ffi.cast(self._type, self._busRead(self._core, self._base + a))) for a in range(start, stop, step)] + else: + return int(ffi.cast(self._type, self._busRead(self._core, self._base + address))) + + def __setitem__(self, address, value): + self._addrCheck(address) + if isinstance(address, slice): + start = address.start or 0 + stop = self._size - self._width if address.stop is None else address.stop + step = address.step or self._width + for a in range(start, stop, step): + self._busWrite(self._core, self._base + a, value[a] & self._mask) + else: + self._busWrite(self._core, self._base + address, value & self._mask) + + def rawRead(self, address, segment=-1): + self._addrCheck(address) + return int(ffi.cast(self._type, self._rawRead(self._core, self._base + address, segment))) + + def rawWrite(self, address, value, segment=-1): + self._addrCheck(address) + self._rawWrite(self._core, self._base + address, segment, value & self._mask) + +class Memory(object): + def __init__(self, core, size, base=0): + self.size = size + self.base = base + + self.u8 = MemoryView(core, 1, size, base, "u") + self.u16 = MemoryView(core, 2, size, base, "u") + self.u32 = MemoryView(core, 4, size, base, "u") + self.s8 = MemoryView(core, 1, size, base, "s") + self.s16 = MemoryView(core, 2, size, base, "s") + self.s32 = MemoryView(core, 4, size, base, "s") + + def __len__(self): + return self._size diff --git a/src/platform/python/mgba/png.py b/src/platform/python/mgba/png.py new file mode 100644 index 000000000..bc1ff836c --- /dev/null +++ b/src/platform/python/mgba/png.py @@ -0,0 +1,24 @@ +# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +from ._pylib import ffi, lib +from . import vfs + +class PNG: + def __init__(self, f): + self.vf = vfs.open(f) + + def writeHeader(self, image): + self._png = lib.PNGWriteOpen(self.vf.handle) + self._info = lib.PNGWriteHeader(self._png, image.width, image.height) + return self._info != ffi.NULL + + def writePixels(self, image): + return lib.PNGWritePixels(self._png, image.width, image.height, image.stride, image.buffer) + + def writeClose(self): + lib.PNGWriteClose(self._png, self._info) + del self._png + del self._info diff --git a/src/platform/python/mgba/tile.py b/src/platform/python/mgba/tile.py new file mode 100644 index 000000000..4d89f8869 --- /dev/null +++ b/src/platform/python/mgba/tile.py @@ -0,0 +1,57 @@ +# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +from ._pylib import ffi, lib +from . import image + +class Tile: + def __init__(self, data): + self.buffer = data + + def toImage(self): + i = image.Image(8, 8) + self.composite(i, 0, 0) + return i + + def composite(self, i, x, y): + for iy in range(8): + for ix in range(8): + i.buffer[ix + x + (iy + y) * i.stride] = image.u16ToColor(self.buffer[ix + iy * 8]) + +class TileView: + def __init__(self, core): + self.core = core + self.cache = ffi.gc(ffi.new("struct mTileCache*"), core._deinitTileCache) + core._initTileCache(self.cache) + lib.mTileCacheSetPalette(self.cache, 0) + self.paletteSet = 0 + + def getTile(self, tile, palette): + return Tile(lib.mTileCacheGetTile(self.cache, tile, palette)) + + def setPalette(self, paletteSet): + if paletteSet > 1 or paletteSet < 0: + raise IndexError("Palette Set ID out of bounds") + lib.mTileCacheSetPalette(self.cache, paletteSet) + self.paletteSet = paletteSet + +class Sprite(object): + TILE_BASE = 0, 0 + PALETTE_BASE = 0, 0 + + def constitute(self, tileView, tilePitch, paletteSet): + oldPaletteSet = tileView.paletteSet + tileView.setPalette(paletteSet) + i = image.Image(self.width, self.height) + tileId = self.tile + self.TILE_BASE[paletteSet] + for y in range(self.height // 8): + for x in range(self.width // 8): + tile = tileView.getTile(tileId, self.paletteId + self.PALETTE_BASE[paletteSet]) + tile.composite(i, x * 8, y * 8) + tileId += 1 + if tilePitch: + tileId += tilePitch - self.width // 8 + self.image = i + tileView.setPalette(oldPaletteSet) diff --git a/src/platform/python/mgba/vfs.py b/src/platform/python/mgba/vfs.py new file mode 100644 index 000000000..158c07639 --- /dev/null +++ b/src/platform/python/mgba/vfs.py @@ -0,0 +1,130 @@ +# Copyright (c) 2013-2016 Jeffrey Pfau +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +from ._pylib import ffi, lib +import mmap +import os + +@ffi.def_extern() +def _vfpClose(vf): + vfp = ffi.cast("struct VFilePy*", vf) + ffi.from_handle(vfp.fileobj).close() + +@ffi.def_extern() +def _vfpSeek(vf, offset, whence): + vfp = ffi.cast("struct VFilePy*", vf) + f = ffi.from_handle(vfp.fileobj) + f.seek(offset, whence) + return f.tell() + +@ffi.def_extern() +def _vfpRead(vf, buffer, size): + vfp = ffi.cast("struct VFilePy*", vf) + pybuf = ffi.buffer(buffer, size) + ffi.from_handle(vfp.fileobj).readinto(pybuf) + return size + +@ffi.def_extern() +def _vfpWrite(vf, buffer, size): + vfp = ffi.cast("struct VFilePy*", vf) + pybuf = ffi.buffer(buffer, size) + ffi.from_handle(vfp.fileobj).write(pybuf) + return size + +@ffi.def_extern() +def _vfpMap(vf, size, flags): + pass + +@ffi.def_extern() +def _vfpUnmap(vf, memory, size): + pass + +@ffi.def_extern() +def _vfpTruncate(vf, size): + vfp = ffi.cast("struct VFilePy*", vf) + ffi.from_handle(vfp.fileobj).truncate(size) + +@ffi.def_extern() +def _vfpSize(vf): + vfp = ffi.cast("struct VFilePy*", vf) + f = ffi.from_handle(vfp.fileobj) + pos = f.tell() + f.seek(0, os.SEEK_END) + size = f.tell() + f.seek(pos, os.SEEK_SET) + return size + +@ffi.def_extern() +def _vfpSync(vf, buffer, size): + vfp = ffi.cast("struct VFilePy*", vf) + f = ffi.from_handle(vfp.fileobj) + if buffer and size: + pos = f.tell() + f.seek(0, os.SEEK_SET) + _vfpWrite(vf, buffer, size) + f.seek(pos, os.SEEK_SET) + f.flush() + os.fsync() + return True + +def open(f): + handle = ffi.new_handle(f) + vf = VFile(lib.VFileFromPython(handle)) + # Prevent garbage collection + vf._fileobj = f + vf._handle = handle + return vf + +def openPath(path, mode="r"): + flags = 0 + if mode.startswith("r"): + flags |= os.O_RDONLY + elif mode.startswith("w"): + flags |= os.O_WRONLY | os.O_CREAT | os.O_TRUNC + elif mode.startswith("a"): + flags |= os.O_WRONLY | os.O_CREAT | os.O_APPEND + else: + return None + + if "+" in mode[1:]: + flags |= os.O_RDWR + if "x" in mode[1:]: + flags |= os.O_EXCL + + return VFile(lib.VFileOpen(path.encode("UTF-8"), flags)) + +class VFile: + def __init__(self, vf): + self.handle = vf + + def close(self): + return self.handle.close(self.handle) + + def seek(self, offset, whence): + return self.handle.seek(self.handle, offset, whence) + + def read(self, buffer, size): + return self.handle.read(self.handle, buffer, size) + + def readline(self, buffer, size): + return self.handle.readline(self.handle, buffer, size) + + def write(self, buffer, size): + return self.handle.write(self.handle, buffer, size) + + def map(self, size, flags): + return self.handle.map(self.handle, size, flags) + + def unmap(self, memory, size): + self.handle.unmap(self.handle, memory, size) + + def truncate(self, size): + self.handle.truncate(self.handle, size) + + def size(self): + return self.handle.size(self.handle) + + def sync(self, buffer, size): + return self.handle.sync(self.handle, buffer, size) diff --git a/src/platform/python/setup.py.in b/src/platform/python/setup.py.in new file mode 100644 index 000000000..31ce6cd52 --- /dev/null +++ b/src/platform/python/setup.py.in @@ -0,0 +1,24 @@ +from setuptools import setup +import re + +classifiers = [ + "Programming Language :: C", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", + "Topic :: Games/Entertainment", + "Topic :: System :: Emulators" +] + +setup(name="${BINARY_NAME}", + version=re.sub("/", "-", "${VERSION_STRING}"), + author="Jeffrey Pfau", + author_email="jeffrey@endrift.com", + url="http://github.com/mgba-emu/mgba/", + packages=["mgba"], + setup_requires=['cffi>=1.6'], + install_requires=['cffi>=1.6', 'cached-property'], + cffi_modules=["_builder.py:ffi"], + license="MPL 2.0", + classifiers=classifiers + ) diff --git a/src/platform/python/vfs-py.c b/src/platform/python/vfs-py.c new file mode 100644 index 000000000..f393832cd --- /dev/null +++ b/src/platform/python/vfs-py.c @@ -0,0 +1,46 @@ +/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + +struct VFilePy { + struct VFile d; + void* fileobj; +}; + +bool _vfpClose(struct VFile* vf); +off_t _vfpSeek(struct VFile* vf, off_t offset, int whence); +ssize_t _vfpRead(struct VFile* vf, void* buffer, size_t size); +ssize_t _vfpWrite(struct VFile* vf, const void* buffer, size_t size); +void* _vfpMap(struct VFile* vf, size_t size, int flags); +void _vfpUnmap(struct VFile* vf, void* memory, size_t size); +void _vfpTruncate(struct VFile* vf, size_t size); +ssize_t _vfpSize(struct VFile* vf); +bool _vfpSync(struct VFile* vf, const void* buffer, size_t size); + +struct VFile* VFileFromPython(void* fileobj) { + if (!fileobj) { + return 0; + } + + struct VFilePy* vfp = malloc(sizeof(struct VFilePy)); + if (!vfp) { + return 0; + } + + vfp->fileobj = fileobj; + vfp->d.close = _vfpClose; + vfp->d.seek = _vfpSeek; + vfp->d.read = _vfpRead; + vfp->d.readline = VFileReadline; + vfp->d.write = _vfpWrite; + vfp->d.map = _vfpMap; + vfp->d.unmap = _vfpUnmap; + vfp->d.truncate = _vfpTruncate; + vfp->d.size = _vfpSize; + vfp->d.sync = _vfpSync; + + return &vfp->d; +} diff --git a/src/platform/python/vfs-py.h b/src/platform/python/vfs-py.h new file mode 100644 index 000000000..2842d4812 --- /dev/null +++ b/src/platform/python/vfs-py.h @@ -0,0 +1,28 @@ +/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include + +struct VFilePy { + struct VFile d; + void* fileobj; +}; + +struct VFile* VFileFromPython(void* fileobj); + +extern "Python+C" { + +bool _vfpClose(struct VFile* vf); +off_t _vfpSeek(struct VFile* vf, off_t offset, int whence); +ssize_t _vfpRead(struct VFile* vf, void* buffer, size_t size); +ssize_t _vfpWrite(struct VFile* vf, const void* buffer, size_t size); +void* _vfpMap(struct VFile* vf, size_t size, int flags); +void _vfpUnmap(struct VFile* vf, void* memory, size_t size); +void _vfpTruncate(struct VFile* vf, size_t size); +ssize_t _vfpSize(struct VFile* vf); +bool _vfpSync(struct VFile* vf, const void* buffer, size_t size); + +} diff --git a/src/platform/qt/AboutScreen.cpp b/src/platform/qt/AboutScreen.cpp index e2743ce4e..0dce32d2b 100644 --- a/src/platform/qt/AboutScreen.cpp +++ b/src/platform/qt/AboutScreen.cpp @@ -5,9 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "AboutScreen.h" -extern "C" { -#include "core/version.h" -} +#include #include #include diff --git a/src/platform/qt/ArchiveInspector.cpp b/src/platform/qt/ArchiveInspector.cpp index 368b47a0d..3dfd38d0e 100644 --- a/src/platform/qt/ArchiveInspector.cpp +++ b/src/platform/qt/ArchiveInspector.cpp @@ -5,9 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "ArchiveInspector.h" -extern "C" { -#include "util/vfs.h" -} +#include using namespace QGBA; diff --git a/src/platform/qt/AssetTile.cpp b/src/platform/qt/AssetTile.cpp index e2e39b18d..74dcdf961 100644 --- a/src/platform/qt/AssetTile.cpp +++ b/src/platform/qt/AssetTile.cpp @@ -9,15 +9,13 @@ #include -extern "C" { -#include "core/interface.h" +#include #ifdef M_CORE_GBA -#include "gba/memory.h" +#include #endif #ifdef M_CORE_GB -#include "gb/memory.h" +#include #endif -} using namespace QGBA; diff --git a/src/platform/qt/AssetTile.h b/src/platform/qt/AssetTile.h index b8cd6b53a..c3bf729f0 100644 --- a/src/platform/qt/AssetTile.h +++ b/src/platform/qt/AssetTile.h @@ -10,9 +10,7 @@ #include "ui_AssetTile.h" -extern "C" { -#include "core/tile-cache.h" -} +#include namespace QGBA { diff --git a/src/platform/qt/AssetView.cpp b/src/platform/qt/AssetView.cpp index ebb337ed1..cd95749b8 100644 --- a/src/platform/qt/AssetView.cpp +++ b/src/platform/qt/AssetView.cpp @@ -7,12 +7,6 @@ #include -extern "C" { -#ifdef M_CORE_GBA -#include "gba/gba.h" -#endif -} - using namespace QGBA; AssetView::AssetView(GameController* controller, QWidget* parent) diff --git a/src/platform/qt/AudioDevice.cpp b/src/platform/qt/AudioDevice.cpp index 5f61dbb58..a74e67f50 100644 --- a/src/platform/qt/AudioDevice.cpp +++ b/src/platform/qt/AudioDevice.cpp @@ -7,10 +7,10 @@ #include "LogController.h" -extern "C" { -#include "core/thread.h" -#include "gba/audio.h" -} +#include +#include +#include +#include using namespace QGBA; diff --git a/src/platform/qt/AudioProcessorQt.cpp b/src/platform/qt/AudioProcessorQt.cpp index b999124bb..1ff237b01 100644 --- a/src/platform/qt/AudioProcessorQt.cpp +++ b/src/platform/qt/AudioProcessorQt.cpp @@ -10,9 +10,8 @@ #include -extern "C" { -#include "core/thread.h" -} +#include +#include using namespace QGBA; diff --git a/src/platform/qt/AudioProcessorSDL.cpp b/src/platform/qt/AudioProcessorSDL.cpp index 08c1fe908..0e8d50af6 100644 --- a/src/platform/qt/AudioProcessorSDL.cpp +++ b/src/platform/qt/AudioProcessorSDL.cpp @@ -7,9 +7,7 @@ #include "LogController.h" -extern "C" { -#include "core/thread.h" -} +#include using namespace QGBA; diff --git a/src/platform/qt/AudioProcessorSDL.h b/src/platform/qt/AudioProcessorSDL.h index 2559ed49e..cd1d53957 100644 --- a/src/platform/qt/AudioProcessorSDL.h +++ b/src/platform/qt/AudioProcessorSDL.h @@ -9,9 +9,7 @@ #ifdef BUILD_SDL -extern "C" { #include "platform/sdl/sdl-audio.h" -} namespace QGBA { diff --git a/src/platform/qt/CheatsModel.cpp b/src/platform/qt/CheatsModel.cpp index 5d6b8cf65..79041ecea 100644 --- a/src/platform/qt/CheatsModel.cpp +++ b/src/platform/qt/CheatsModel.cpp @@ -10,9 +10,8 @@ #include -extern "C" { -#include "core/cheats.h" -} +#include +#include using namespace QGBA; diff --git a/src/platform/qt/CheatsView.cpp b/src/platform/qt/CheatsView.cpp index a990ff25f..b3e912c55 100644 --- a/src/platform/qt/CheatsView.cpp +++ b/src/platform/qt/CheatsView.cpp @@ -11,15 +11,13 @@ #include #include -extern "C" { -#include "core/cheats.h" +#include #ifdef M_CORE_GBA -#include "gba/cheats.h" +#include #endif #ifdef M_CORE_GB -#include "gb/cheats.h" +#include #endif -} using namespace QGBA; diff --git a/src/platform/qt/ConfigController.cpp b/src/platform/qt/ConfigController.cpp index 50462d7e8..d008fd756 100644 --- a/src/platform/qt/ConfigController.cpp +++ b/src/platform/qt/ConfigController.cpp @@ -11,9 +11,7 @@ #include #include -extern "C" { #include "feature/commandline.h" -} using namespace QGBA; diff --git a/src/platform/qt/ConfigController.h b/src/platform/qt/ConfigController.h index 4d8ab80a0..2ce8868fd 100644 --- a/src/platform/qt/ConfigController.h +++ b/src/platform/qt/ConfigController.h @@ -15,11 +15,9 @@ #include -extern "C" { -#include "core/config.h" -#include "util/configuration.h" +#include +#include #include "feature/commandline.h" -} class QAction; class QMenu; diff --git a/src/platform/qt/DebuggerConsoleController.cpp b/src/platform/qt/DebuggerConsoleController.cpp index 22cc9b3ff..0752eb89e 100644 --- a/src/platform/qt/DebuggerConsoleController.cpp +++ b/src/platform/qt/DebuggerConsoleController.cpp @@ -9,9 +9,7 @@ #include -extern "C" { -#include "debugger/cli-debugger.h" -} +#include using namespace QGBA; diff --git a/src/platform/qt/DebuggerConsoleController.h b/src/platform/qt/DebuggerConsoleController.h index 1128aabca..36e7903cb 100644 --- a/src/platform/qt/DebuggerConsoleController.h +++ b/src/platform/qt/DebuggerConsoleController.h @@ -12,9 +12,7 @@ #include #include -extern "C" { -#include "debugger/cli-debugger.h" -} +#include namespace QGBA { diff --git a/src/platform/qt/Display.cpp b/src/platform/qt/Display.cpp index a8af613ec..506afe76b 100644 --- a/src/platform/qt/Display.cpp +++ b/src/platform/qt/Display.cpp @@ -8,13 +8,11 @@ #include "DisplayGL.h" #include "DisplayQt.h" -extern "C" { #ifdef M_CORE_GB -#include "gb/video.h" +#include #elif defined(M_CORE_GBA) -#include "gba/video.h" +#include #endif -} using namespace QGBA; diff --git a/src/platform/qt/Display.h b/src/platform/qt/Display.h index 841cd4278..a78810fe8 100644 --- a/src/platform/qt/Display.h +++ b/src/platform/qt/Display.h @@ -6,9 +6,7 @@ #ifndef QGBA_DISPLAY #define QGBA_DISPLAY -extern "C" { -#include "util/common.h" -} +#include #include diff --git a/src/platform/qt/DisplayGL.cpp b/src/platform/qt/DisplayGL.cpp index c565b545e..4a1cfff87 100644 --- a/src/platform/qt/DisplayGL.cpp +++ b/src/platform/qt/DisplayGL.cpp @@ -8,9 +8,8 @@ #include #include -extern "C" { -#include "core/core.h" -#include "core/thread.h" +#include +#include #ifdef BUILD_GL #include "platform/opengl/gl.h" #endif @@ -20,7 +19,6 @@ extern "C" { #include #endif #endif -} using namespace QGBA; diff --git a/src/platform/qt/DisplayGL.h b/src/platform/qt/DisplayGL.h index 5803dfd92..d89c26418 100644 --- a/src/platform/qt/DisplayGL.h +++ b/src/platform/qt/DisplayGL.h @@ -22,9 +22,7 @@ #include #include -extern "C" { #include "platform/video-backend.h" -} namespace QGBA { diff --git a/src/platform/qt/DisplayQt.cpp b/src/platform/qt/DisplayQt.cpp index b11294638..284347d58 100644 --- a/src/platform/qt/DisplayQt.cpp +++ b/src/platform/qt/DisplayQt.cpp @@ -7,10 +7,8 @@ #include -extern "C" { -#include "core/core.h" -#include "core/thread.h" -} +#include +#include using namespace QGBA; diff --git a/src/platform/qt/GBAApp.cpp b/src/platform/qt/GBAApp.cpp index 377f9f67d..ea42ed128 100644 --- a/src/platform/qt/GBAApp.cpp +++ b/src/platform/qt/GBAApp.cpp @@ -16,13 +16,14 @@ #include #include -extern "C" { -#include "core/version.h" +#include +#include +#include +#include +#include +/* #include "feature/commandline.h" -#include "util/nointro.h" -#include "util/socket.h" -} - +*/ using namespace QGBA; static GBAApp* g_app = nullptr; diff --git a/src/platform/qt/GBAApp.h b/src/platform/qt/GBAApp.h index d54712744..a0e13a60e 100644 --- a/src/platform/qt/GBAApp.h +++ b/src/platform/qt/GBAApp.h @@ -14,9 +14,7 @@ struct NoIntroDB; -extern "C" { -#include "core/log.h" -} +#include mLOG_DECLARE_CATEGORY(QT); diff --git a/src/platform/qt/GBAKeyEditor.cpp b/src/platform/qt/GBAKeyEditor.cpp index 0c33058ba..439b4294c 100644 --- a/src/platform/qt/GBAKeyEditor.cpp +++ b/src/platform/qt/GBAKeyEditor.cpp @@ -16,9 +16,7 @@ #include "KeyEditor.h" #ifdef BUILD_SDL -extern "C" { #include "platform/sdl/sdl-events.h" -} #endif using namespace QGBA; diff --git a/src/platform/qt/GBAKeyEditor.h b/src/platform/qt/GBAKeyEditor.h index bbd839063..7274a6078 100644 --- a/src/platform/qt/GBAKeyEditor.h +++ b/src/platform/qt/GBAKeyEditor.h @@ -11,9 +11,7 @@ #include #include -extern "C" { -#include "gba/input.h" -} +#include class QComboBox; class QTimer; diff --git a/src/platform/qt/GBAOverride.cpp b/src/platform/qt/GBAOverride.cpp index 1181162e2..61a01b6d7 100644 --- a/src/platform/qt/GBAOverride.cpp +++ b/src/platform/qt/GBAOverride.cpp @@ -5,9 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "GBAOverride.h" -extern "C" { -#include "core/core.h" -} +#include using namespace QGBA; diff --git a/src/platform/qt/GBAOverride.h b/src/platform/qt/GBAOverride.h index 71d67f90d..a668a0d57 100644 --- a/src/platform/qt/GBAOverride.h +++ b/src/platform/qt/GBAOverride.h @@ -8,9 +8,7 @@ #include "Override.h" -extern "C" { -#include "gba/overrides.h" -} +#include namespace QGBA { diff --git a/src/platform/qt/GBOverride.cpp b/src/platform/qt/GBOverride.cpp index d04e90082..e0ff2b4d8 100644 --- a/src/platform/qt/GBOverride.cpp +++ b/src/platform/qt/GBOverride.cpp @@ -5,11 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "GBOverride.h" -extern "C" { -#include "core/core.h" -#include "gb/gb.h" -#include "util/crc32.h" -} +#include +#include +#include using namespace QGBA; diff --git a/src/platform/qt/GBOverride.h b/src/platform/qt/GBOverride.h index 5fb7c057d..7c52b497a 100644 --- a/src/platform/qt/GBOverride.h +++ b/src/platform/qt/GBOverride.h @@ -8,9 +8,7 @@ #include "Override.h" -extern "C" { -#include "gb/overrides.h" -} +#include namespace QGBA { diff --git a/src/platform/qt/GDBController.h b/src/platform/qt/GDBController.h index fa295a074..206c8a27e 100644 --- a/src/platform/qt/GDBController.h +++ b/src/platform/qt/GDBController.h @@ -10,9 +10,7 @@ #ifdef USE_GDB_STUB -extern "C" { -#include "debugger/gdb-stub.h" -} +#include namespace QGBA { diff --git a/src/platform/qt/GIFView.cpp b/src/platform/qt/GIFView.cpp index 427bb9459..e72475150 100644 --- a/src/platform/qt/GIFView.cpp +++ b/src/platform/qt/GIFView.cpp @@ -12,6 +12,9 @@ #include +#include +#include + using namespace QGBA; GIFView::GIFView(QWidget* parent) diff --git a/src/platform/qt/GIFView.h b/src/platform/qt/GIFView.h index ccfeddbc0..6641d8d94 100644 --- a/src/platform/qt/GIFView.h +++ b/src/platform/qt/GIFView.h @@ -12,9 +12,7 @@ #include "ui_GIFView.h" -extern "C" { #include "feature/imagemagick/imagemagick-gif-encoder.h" -} namespace QGBA { diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index eb5ef964c..a86fbf8ac 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -17,24 +17,23 @@ #include -extern "C" { -#include "core/config.h" -#include "core/directories.h" -#include "core/serialize.h" -#include "core/tile-cache.h" +#include +#include +#include +#include #ifdef M_CORE_GBA -#include "gba/bios.h" -#include "gba/core.h" -#include "gba/gba.h" -#include "gba/renderers/tile-cache.h" -#include "gba/sharkport.h" +#include +#include +#include +#include +#include +#include #endif #ifdef M_CORE_GB -#include "gb/gb.h" -#include "gb/renderers/tile-cache.h" +#include +#include #endif -#include "util/vfs.h" -} +#include using namespace QGBA; using namespace std; diff --git a/src/platform/qt/GameController.h b/src/platform/qt/GameController.h index 17282ad3a..63383ac23 100644 --- a/src/platform/qt/GameController.h +++ b/src/platform/qt/GameController.h @@ -15,17 +15,13 @@ #include -extern "C" { -#include "core/core.h" -#include "core/thread.h" -#include "gba/cheats.h" -#include "gba/hardware.h" -#include "gba/input.h" -#include "gba/overrides.h" +#include +#include +#include +#include #ifdef BUILD_SDL #include "platform/sdl/sdl-events.h" #endif -} struct Configuration; struct GBAAudio; diff --git a/src/platform/qt/GamepadAxisEvent.h b/src/platform/qt/GamepadAxisEvent.h index 09a1b015d..68234ccdc 100644 --- a/src/platform/qt/GamepadAxisEvent.h +++ b/src/platform/qt/GamepadAxisEvent.h @@ -8,9 +8,7 @@ #include -extern "C" { -#include "gba/input.h" -} +#include namespace QGBA { diff --git a/src/platform/qt/GamepadButtonEvent.h b/src/platform/qt/GamepadButtonEvent.h index 375a0e05f..b0751f4b6 100644 --- a/src/platform/qt/GamepadButtonEvent.h +++ b/src/platform/qt/GamepadButtonEvent.h @@ -8,9 +8,7 @@ #include -extern "C" { -#include "gba/input.h" -} +#include namespace QGBA { diff --git a/src/platform/qt/IOViewer.cpp b/src/platform/qt/IOViewer.cpp index a69c6e731..b308de6a4 100644 --- a/src/platform/qt/IOViewer.cpp +++ b/src/platform/qt/IOViewer.cpp @@ -12,13 +12,13 @@ #include #include -extern "C" { -#include "gba/io.h" -} +#include +#include + +struct ARMCore; using namespace QGBA; - QList IOViewer::s_registers; const QList& IOViewer::registerDescriptions() { diff --git a/src/platform/qt/InputController.cpp b/src/platform/qt/InputController.cpp index 82a3ad1e4..eca5dfe97 100644 --- a/src/platform/qt/InputController.cpp +++ b/src/platform/qt/InputController.cpp @@ -14,10 +14,8 @@ #include #include -extern "C" { -#include "core/interface.h" -#include "util/configuration.h" -} +#include +#include using namespace QGBA; diff --git a/src/platform/qt/InputController.h b/src/platform/qt/InputController.h index 307007867..8dc5af196 100644 --- a/src/platform/qt/InputController.h +++ b/src/platform/qt/InputController.h @@ -14,13 +14,11 @@ class QTimer; -extern "C" { -#include "gba/input.h" +#include #ifdef BUILD_SDL #include "platform/sdl/sdl-events.h" #endif -} struct mRotationSource; struct mRumble; diff --git a/src/platform/qt/InputProfile.h b/src/platform/qt/InputProfile.h index 7180a70d1..431bd4b4f 100644 --- a/src/platform/qt/InputProfile.h +++ b/src/platform/qt/InputProfile.h @@ -8,9 +8,7 @@ #include "GamepadAxisEvent.h" -extern "C" { -#include "gba/interface.h" -} +#include namespace QGBA { diff --git a/src/platform/qt/LibraryModel.cpp b/src/platform/qt/LibraryModel.cpp index 5341268e9..9973af042 100644 --- a/src/platform/qt/LibraryModel.cpp +++ b/src/platform/qt/LibraryModel.cpp @@ -5,9 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "LibraryModel.h" -extern "C" { -#include "util/vfs.h" -} +#include using namespace QGBA; diff --git a/src/platform/qt/LibraryModel.h b/src/platform/qt/LibraryModel.h index 3cf80f355..5f8999461 100644 --- a/src/platform/qt/LibraryModel.h +++ b/src/platform/qt/LibraryModel.h @@ -8,9 +8,7 @@ #include -extern "C" { -#include "core/library.h" -} +#include struct VDir; diff --git a/src/platform/qt/LoadSaveState.cpp b/src/platform/qt/LoadSaveState.cpp index 4c6786a12..122cb133e 100644 --- a/src/platform/qt/LoadSaveState.cpp +++ b/src/platform/qt/LoadSaveState.cpp @@ -14,13 +14,9 @@ #include #include -extern "C" { -#include "core/serialize.h" -#ifdef M_CORE_GBA -#include "gba/serialize.h" -#endif -#include "util/memory.h" -} +#include +#include +#include using namespace QGBA; diff --git a/src/platform/qt/LogController.h b/src/platform/qt/LogController.h index bf02a9b85..0a4be0159 100644 --- a/src/platform/qt/LogController.h +++ b/src/platform/qt/LogController.h @@ -11,10 +11,6 @@ #include #include -extern "C" { -#include "gba/gba.h" -} - namespace QGBA { class LogController : public QObject { diff --git a/src/platform/qt/MemoryModel.cpp b/src/platform/qt/MemoryModel.cpp index a97e54f3c..e7f4d126e 100644 --- a/src/platform/qt/MemoryModel.cpp +++ b/src/platform/qt/MemoryModel.cpp @@ -19,9 +19,8 @@ #include #include -extern "C" { -#include "core/core.h" -} +#include +#include using namespace QGBA; diff --git a/src/platform/qt/MemoryModel.h b/src/platform/qt/MemoryModel.h index 2defb510e..a32bb8c36 100644 --- a/src/platform/qt/MemoryModel.h +++ b/src/platform/qt/MemoryModel.h @@ -13,9 +13,7 @@ #include #include -extern "C" { -#include "util/text-codec.h" -} +#include struct mCore; diff --git a/src/platform/qt/MemoryView.cpp b/src/platform/qt/MemoryView.cpp index 07ad16254..20a6dce16 100644 --- a/src/platform/qt/MemoryView.cpp +++ b/src/platform/qt/MemoryView.cpp @@ -8,15 +8,13 @@ #include "GameController.h" -extern "C" { -#include "core/core.h" +#include #ifdef M_CORE_GBA -#include "gba/memory.h" +#include #endif #ifdef M_CORE_GB -#include "gb/memory.h" +#include #endif -} using namespace QGBA; diff --git a/src/platform/qt/MessagePainter.cpp b/src/platform/qt/MessagePainter.cpp index 7aa19a98e..629ce4878 100644 --- a/src/platform/qt/MessagePainter.cpp +++ b/src/platform/qt/MessagePainter.cpp @@ -9,9 +9,7 @@ #include -extern "C" { -#include "gba/video.h" -} +#include using namespace QGBA; diff --git a/src/platform/qt/MultiplayerController.cpp b/src/platform/qt/MultiplayerController.cpp index 489c2b1e2..dc5e54ebb 100644 --- a/src/platform/qt/MultiplayerController.cpp +++ b/src/platform/qt/MultiplayerController.cpp @@ -7,19 +7,19 @@ #include "GameController.h" -extern "C" { #ifdef M_CORE_GBA -#include "gba/gba.h" +#include +#endif +#ifdef M_CORE_GB +#include #endif -} - using namespace QGBA; MultiplayerController::MultiplayerController() { - GBASIOLockstepInit(&m_lockstep); + mLockstepInit(&m_lockstep); m_lockstep.context = this; - m_lockstep.signal = [](GBASIOLockstep* lockstep, unsigned mask) { + m_lockstep.signal = [](mLockstep* lockstep, unsigned mask) { MultiplayerController* controller = static_cast(lockstep->context); Player* player = &controller->m_players[0]; bool woke = false; @@ -33,7 +33,7 @@ MultiplayerController::MultiplayerController() { controller->m_lock.unlock(); return woke; }; - m_lockstep.wait = [](GBASIOLockstep* lockstep, unsigned mask) { + m_lockstep.wait = [](mLockstep* lockstep, unsigned mask) { MultiplayerController* controller = static_cast(lockstep->context); controller->m_lock.lock(); Player* player = &controller->m_players[0]; @@ -47,7 +47,7 @@ MultiplayerController::MultiplayerController() { controller->m_lock.unlock(); return slept; }; - m_lockstep.addCycles = [](GBASIOLockstep* lockstep, int id, int32_t cycles) { + m_lockstep.addCycles = [](mLockstep* lockstep, int id, int32_t cycles) { if (cycles < 0) { abort(); } @@ -56,14 +56,27 @@ MultiplayerController::MultiplayerController() { if (!id) { for (int i = 1; i < controller->m_players.count(); ++i) { Player* player = &controller->m_players[i]; - if (player->node->d.p->mode != controller->m_players[0].node->d.p->mode) { + if (player->controller->platform() == PLATFORM_GBA && player->gbaNode->d.p->mode != controller->m_players[0].gbaNode->d.p->mode) { player->controller->setSync(true); continue; } player->controller->setSync(false); player->cyclesPosted += cycles; if (player->awake < 1) { - player->node->nextEvent += player->cyclesPosted; + switch (player->controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + player->gbaNode->nextEvent += player->cyclesPosted; + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + player->gbNode->nextEvent += player->cyclesPosted; + break; +#endif + default: + break; + } mCoreThreadStopWaiting(player->controller->thread()); player->awake = 1; } @@ -74,7 +87,7 @@ MultiplayerController::MultiplayerController() { } controller->m_lock.unlock(); }; - m_lockstep.useCycles = [](GBASIOLockstep* lockstep, int id, int32_t cycles) { + m_lockstep.useCycles = [](mLockstep* lockstep, int id, int32_t cycles) { MultiplayerController* controller = static_cast(lockstep->context); controller->m_lock.lock(); Player* player = &controller->m_players[id]; @@ -87,7 +100,7 @@ MultiplayerController::MultiplayerController() { controller->m_lock.unlock(); return cycles; }; - m_lockstep.unload = [](GBASIOLockstep* lockstep, int id) { + m_lockstep.unload = [](mLockstep* lockstep, int id) { MultiplayerController* controller = static_cast(lockstep->context); controller->m_lock.lock(); Player* player = &controller->m_players[id]; @@ -102,9 +115,35 @@ MultiplayerController::MultiplayerController() { for (int i = 1; i < controller->m_players.count(); ++i) { Player* player = &controller->m_players[i]; player->controller->setSync(true); - player->cyclesPosted += lockstep->players[0]->eventDiff; + switch (player->controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + player->cyclesPosted += reinterpret_cast(lockstep)->players[0]->eventDiff; + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + player->cyclesPosted += reinterpret_cast(lockstep)->players[0]->eventDiff; + break; +#endif + default: + break; + } if (player->awake < 1) { - player->node->nextEvent += player->cyclesPosted; + switch (player->controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + player->gbaNode->nextEvent += player->cyclesPosted; + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + player->gbNode->nextEvent += player->cyclesPosted; + break; +#endif + default: + break; + } mCoreThreadStopWaiting(player->controller->thread()); player->awake = 1; } @@ -114,29 +153,44 @@ MultiplayerController::MultiplayerController() { }; } -MultiplayerController::~MultiplayerController() { - GBASIOLockstepDeinit(&m_lockstep); -} - bool MultiplayerController::attachGame(GameController* controller) { if (m_lockstep.attached == MAX_GBAS) { return false; } + if (m_lockstep.attached == 0) { + switch (controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + GBASIOLockstepInit(&m_gbaLockstep); + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + GBSIOLockstepInit(&m_gbLockstep); + break; +#endif + default: + return false; + } + } + mCoreThread* thread = controller->thread(); if (!thread) { return false; } + switch (controller->platform()) { #ifdef M_CORE_GBA - if (controller->platform() == PLATFORM_GBA) { + case PLATFORM_GBA: { GBA* gba = static_cast(thread->core->board); GBASIOLockstepNode* node = new GBASIOLockstepNode; GBASIOLockstepNodeCreate(node); - GBASIOLockstepAttachNode(&m_lockstep, node); + GBASIOLockstepAttachNode(&m_gbaLockstep, node); m_players.append({ controller, + nullptr, node, 1, 0, @@ -149,6 +203,31 @@ bool MultiplayerController::attachGame(GameController* controller) { return true; } #endif +#ifdef M_CORE_GB + case PLATFORM_GB: { + GB* gb = static_cast(thread->core->board); + + GBSIOLockstepNode* node = new GBSIOLockstepNode; + GBSIOLockstepNodeCreate(node); + GBSIOLockstepAttachNode(&m_gbLockstep, node); + m_players.append({ + controller, + node, + nullptr, + 1, + 0, + 0 + }); + + GBSIOSetDriver(&gb->sio, &node->d); + + emit gameAttached(); + return true; + } +#endif + default: + break; + } return false; } @@ -161,17 +240,34 @@ void MultiplayerController::detachGame(GameController* controller) { for (int i = 0; i < m_players.count(); ++i) { m_players[i].controller->threadInterrupt(); } + switch (controller->platform()) { #ifdef M_CORE_GBA - if (controller->platform() == PLATFORM_GBA) { + case PLATFORM_GBA: { GBA* gba = static_cast(thread->core->board); GBASIOLockstepNode* node = reinterpret_cast(gba->sio.drivers.multiplayer); GBASIOSetDriver(&gba->sio, nullptr, SIO_MULTI); if (node) { - GBASIOLockstepDetachNode(&m_lockstep, node); + GBASIOLockstepDetachNode(&m_gbaLockstep, node); delete node; } + break; } #endif +#ifdef M_CORE_GB + case PLATFORM_GB: { + GB* gb = static_cast(thread->core->board); + GBSIOLockstepNode* node = reinterpret_cast(gb->sio.driver); + GBSIOSetDriver(&gb->sio, nullptr); + if (node) { + GBSIOLockstepDetachNode(&m_gbLockstep, node); + delete node; + } + break; + } +#endif + default: + break; + } controller->threadContinue(); for (int i = 0; i < m_players.count(); ++i) { diff --git a/src/platform/qt/MultiplayerController.h b/src/platform/qt/MultiplayerController.h index 166fa83c0..42de75bcb 100644 --- a/src/platform/qt/MultiplayerController.h +++ b/src/platform/qt/MultiplayerController.h @@ -10,9 +10,13 @@ #include #include -extern "C" { -#include "gba/sio/lockstep.h" -} +#include +#ifdef M_CORE_GBA +#include +#endif +#ifdef M_CORE_GB +#include +#endif namespace QGBA { @@ -23,7 +27,6 @@ Q_OBJECT public: MultiplayerController(); - ~MultiplayerController(); bool attachGame(GameController*); void detachGame(GameController*); @@ -38,12 +41,21 @@ signals: private: struct Player { GameController* controller; - GBASIOLockstepNode* node; + GBSIOLockstepNode* gbNode; + GBASIOLockstepNode* gbaNode; int awake; int32_t cyclesPosted; unsigned waitMask; }; - GBASIOLockstep m_lockstep; + union { + mLockstep m_lockstep; +#ifdef M_CORE_GB + GBSIOLockstep m_gbLockstep; +#endif +#ifdef M_CORE_GBA + GBASIOLockstep m_gbaLockstep; +#endif + }; QList m_players; QMutex m_lock; }; diff --git a/src/platform/qt/ObjView.cpp b/src/platform/qt/ObjView.cpp index 569b24890..f2471226b 100644 --- a/src/platform/qt/ObjView.cpp +++ b/src/platform/qt/ObjView.cpp @@ -10,13 +10,11 @@ #include #include -extern "C" { -#include "gba/gba.h" +#include #ifdef M_CORE_GB -#include "gb/gb.h" -#include "gb/io.h" +#include +#include #endif -} using namespace QGBA; diff --git a/src/platform/qt/ObjView.h b/src/platform/qt/ObjView.h index 61cf43282..725fabfd4 100644 --- a/src/platform/qt/ObjView.h +++ b/src/platform/qt/ObjView.h @@ -11,9 +11,7 @@ #include "ui_ObjView.h" -extern "C" { -#include "core/tile-cache.h" -} +#include namespace QGBA { diff --git a/src/platform/qt/OverrideView.cpp b/src/platform/qt/OverrideView.cpp index 249baac52..ad0819616 100644 --- a/src/platform/qt/OverrideView.cpp +++ b/src/platform/qt/OverrideView.cpp @@ -12,16 +12,12 @@ #ifdef M_CORE_GBA #include "GBAOverride.h" -extern "C" { -#include "gba/gba.h" -} +#include #endif #ifdef M_CORE_GB #include "GBOverride.h" -extern "C" { -#include "gb/gb.h" -} +#include #endif using namespace QGBA; diff --git a/src/platform/qt/OverrideView.h b/src/platform/qt/OverrideView.h index dc31f2223..c7f3fad99 100644 --- a/src/platform/qt/OverrideView.h +++ b/src/platform/qt/OverrideView.h @@ -9,9 +9,7 @@ #include #ifdef M_CORE_GB -extern "C" { -#include "gb/overrides.h" -} +#include #endif #include "ui_OverrideView.h" diff --git a/src/platform/qt/PaletteView.cpp b/src/platform/qt/PaletteView.cpp index dd917b555..af55bdd4b 100644 --- a/src/platform/qt/PaletteView.cpp +++ b/src/platform/qt/PaletteView.cpp @@ -12,17 +12,15 @@ #include #include -extern "C" { -#include "core/core.h" -#include "util/export.h" -#ifdef M_CORE_GA -#include "gba/gba.h" +#include +#ifdef M_CORE_GBA +#include #endif #ifdef M_CORE_GB -#include "gb/gb.h" +#include #endif -#include "util/vfs.h" -} +#include +#include using namespace QGBA; diff --git a/src/platform/qt/ROMInfo.cpp b/src/platform/qt/ROMInfo.cpp index 4271dc07d..d83b4cf2c 100644 --- a/src/platform/qt/ROMInfo.cpp +++ b/src/platform/qt/ROMInfo.cpp @@ -8,16 +8,14 @@ #include "GBAApp.h" #include "GameController.h" -extern "C" { -#include "core/core.h" +#include #ifdef M_CORE_GB -#include "gb/gb.h" +#include #endif #ifdef M_CORE_GBA -#include "gba/gba.h" +#include #endif -#include "util/nointro.h" -} +#include using namespace QGBA; diff --git a/src/platform/qt/SensorView.cpp b/src/platform/qt/SensorView.cpp index a5997ac3b..b0e86cc64 100644 --- a/src/platform/qt/SensorView.cpp +++ b/src/platform/qt/SensorView.cpp @@ -9,10 +9,8 @@ #include "GamepadAxisEvent.h" #include "InputController.h" -extern "C" { -#include "core/core.h" -#include "gba/gba.h" -} +#include +#include using namespace QGBA; diff --git a/src/platform/qt/SettingsView.cpp b/src/platform/qt/SettingsView.cpp index 8302ddb34..d4625e13e 100644 --- a/src/platform/qt/SettingsView.cpp +++ b/src/platform/qt/SettingsView.cpp @@ -13,10 +13,8 @@ #include "InputController.h" #include "ShortcutView.h" -extern "C" { -#include "core/serialize.h" -#include "gba/gba.h" -} +#include +#include using namespace QGBA; diff --git a/src/platform/qt/ShaderSelector.cpp b/src/platform/qt/ShaderSelector.cpp index 3f60aeb61..928cef505 100644 --- a/src/platform/qt/ShaderSelector.cpp +++ b/src/platform/qt/ShaderSelector.cpp @@ -17,14 +17,13 @@ #include #include -extern "C" { -#include "core/version.h" +#include +#include #include "platform/video-backend.h" #if !defined(_WIN32) || defined(USE_EPOXY) #include "platform/opengl/gles2.h" #endif -} using namespace QGBA; diff --git a/src/platform/qt/Swatch.cpp b/src/platform/qt/Swatch.cpp index f672a404d..8c0e64212 100644 --- a/src/platform/qt/Swatch.cpp +++ b/src/platform/qt/Swatch.cpp @@ -8,9 +8,7 @@ #include #include -extern "C" { -#include "core/interface.h" -} +#include using namespace QGBA; diff --git a/src/platform/qt/TileView.cpp b/src/platform/qt/TileView.cpp index 5ac2edc84..eb4dbd18d 100644 --- a/src/platform/qt/TileView.cpp +++ b/src/platform/qt/TileView.cpp @@ -10,11 +10,9 @@ #include #include -extern "C" { #ifdef M_CORE_GB -#include "gb/gb.h" +#include #endif -} using namespace QGBA; diff --git a/src/platform/qt/TileView.h b/src/platform/qt/TileView.h index 37b5ca78d..623d83a47 100644 --- a/src/platform/qt/TileView.h +++ b/src/platform/qt/TileView.h @@ -11,9 +11,7 @@ #include "ui_TileView.h" -extern "C" { -#include "core/tile-cache.h" -} +#include namespace QGBA { diff --git a/src/platform/qt/VFileDevice.cpp b/src/platform/qt/VFileDevice.cpp index 3e15c9f62..04da09353 100644 --- a/src/platform/qt/VFileDevice.cpp +++ b/src/platform/qt/VFileDevice.cpp @@ -5,6 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "VFileDevice.h" +#include + using namespace QGBA; VFileDevice::VFileDevice(VFile* vf, QObject* parent) diff --git a/src/platform/qt/VFileDevice.h b/src/platform/qt/VFileDevice.h index a99b39dba..71baecd1a 100644 --- a/src/platform/qt/VFileDevice.h +++ b/src/platform/qt/VFileDevice.h @@ -8,9 +8,8 @@ #include -extern "C" { -#include "util/vfs.h" -} +struct VDir; +struct VFile; namespace QGBA { diff --git a/src/platform/qt/VideoView.cpp b/src/platform/qt/VideoView.cpp index bb3805a4e..6a6523b6e 100644 --- a/src/platform/qt/VideoView.cpp +++ b/src/platform/qt/VideoView.cpp @@ -12,12 +12,6 @@ #include -#ifdef M_CORE_GB -extern "C" { -#include "gb/video.h" -} -#endif - using namespace QGBA; QMap VideoView::s_acodecMap; diff --git a/src/platform/qt/VideoView.h b/src/platform/qt/VideoView.h index 360de48df..aeb4c0b02 100644 --- a/src/platform/qt/VideoView.h +++ b/src/platform/qt/VideoView.h @@ -12,9 +12,7 @@ #include "ui_VideoView.h" -extern "C" { #include "feature/ffmpeg/ffmpeg-encoder.h" -} namespace QGBA { diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 42f367b51..9a2d594a6 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -42,15 +42,14 @@ #include "TileView.h" #include "VideoView.h" -extern "C" { -#include "core/version.h" +#include #ifdef M_CORE_GB -#include "gb/gb.h" +#include +#include #endif #include "feature/commandline.h" -#include "util/nointro.h" -#include "util/vfs.h" -} +#include +#include using namespace QGBA; diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index 14212bb5c..087977fb3 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -13,10 +13,7 @@ #include -extern "C" { -#include "core/thread.h" -#include "gba/gba.h" -} +#include #include "InputController.h" #include "LoadSaveState.h" diff --git a/src/platform/sdl/gl-common.c b/src/platform/sdl/gl-common.c index 3e4f7add2..7ed9aa95b 100644 --- a/src/platform/sdl/gl-common.c +++ b/src/platform/sdl/gl-common.c @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "main.h" -#include "core/version.h" +#include void mSDLGLCommonSwap(struct VideoBackend* context) { struct mSDLRenderer* renderer = (struct mSDLRenderer*) context->user; diff --git a/src/platform/sdl/gl-common.h b/src/platform/sdl/gl-common.h index 62f3a407c..b517dd436 100644 --- a/src/platform/sdl/gl-common.h +++ b/src/platform/sdl/gl-common.h @@ -5,9 +5,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef SDL_GL_COMMON_H #define SDL_GL_COMMON_H + +#include + +CXX_GUARD_START + #include "main.h" void mSDLGLCommonSwap(struct VideoBackend* context); void mSDLGLCommonInit(struct mSDLRenderer* renderer); +CXX_GUARD_END + #endif diff --git a/src/platform/sdl/gl-sdl.c b/src/platform/sdl/gl-sdl.c index 0a34b7600..0ecf67ecd 100644 --- a/src/platform/sdl/gl-sdl.c +++ b/src/platform/sdl/gl-sdl.c @@ -7,8 +7,8 @@ #include "gl-common.h" -#include "core/core.h" -#include "core/thread.h" +#include +#include #include "platform/opengl/gl.h" static void _doViewport(int w, int h, struct VideoBackend* v) { diff --git a/src/platform/sdl/gles2-sdl.c b/src/platform/sdl/gles2-sdl.c index c45821ddf..7d55362c9 100644 --- a/src/platform/sdl/gles2-sdl.c +++ b/src/platform/sdl/gles2-sdl.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2015 Jeffrey Pfau +/* Copyright (c) 2013-2016 Jeffrey Pfau * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -7,16 +7,20 @@ #include "gl-common.h" +#include "core/thread.h" + +#ifndef __APPLE__ #include +#endif static bool mSDLGLES2Init(struct mSDLRenderer* renderer); -static void mSDLGLES2RunloopGBA(struct mSDLRenderer* renderer, void* user); +static void mSDLGLES2Runloop(struct mSDLRenderer* renderer, void* user); static void mSDLGLES2Deinit(struct mSDLRenderer* renderer); void mSDLGLES2Create(struct mSDLRenderer* renderer) { renderer->init = mSDLGLES2Init; renderer->deinit = mSDLGLES2Deinit; - renderer->runloop = mSDLGLES2RunloopGBA; + renderer->runloop = mSDLGLES2Runloop; } bool mSDLGLES2Init(struct mSDLRenderer* renderer) { @@ -93,8 +97,13 @@ bool mSDLGLES2Init(struct mSDLRenderer* renderer) { mSDLGLCommonInit(renderer); #endif - renderer->d.outputBuffer = memalign(16, VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4); - renderer->d.outputBufferStride = VIDEO_HORIZONTAL_PIXELS; +#ifndef __APPLE__ + renderer->outputBuffer = memalign(16, renderer->width * renderer->height * BYTES_PER_PIXEL); +#else + posix_memalign((void**) &renderer->outputBuffer, 16, renderer->width * renderer->height * BYTES_PER_PIXEL); +#endif + memset(renderer->outputBuffer, 0, renderer->width * renderer->height * BYTES_PER_PIXEL); + renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, renderer->width); mGLES2ContextCreate(&renderer->gl2); renderer->gl2.d.user = renderer; @@ -107,17 +116,17 @@ bool mSDLGLES2Init(struct mSDLRenderer* renderer) { } void mSDLGLES2Runloop(struct mSDLRenderer* renderer, void* user) { - struct GBAThread* context = user; + struct mCoreThread* context = user; SDL_Event event; struct VideoBackend* v = &renderer->gl2.d; while (context->state < THREAD_EXITING) { while (SDL_PollEvent(&event)) { - mSDLHandleEventGBA(context, &renderer->player, &event); + mSDLHandleEvent(context, &renderer->player, &event); } if (mCoreSyncWaitFrameStart(&context->sync)) { - v->postFrame(v, renderer->d.outputBuffer); + v->postFrame(v, renderer->outputBuffer); } mCoreSyncWaitFrameEnd(&context->sync); v->drawFrame(v); @@ -142,5 +151,5 @@ void mSDLGLES2Deinit(struct mSDLRenderer* renderer) { #elif SDL_VERSION_ATLEAST(2, 0, 0) SDL_GL_DeleteContext(renderer->glCtx); #endif - free(renderer->d.outputBuffer); + free(renderer->outputBuffer); } diff --git a/src/platform/sdl/main.c b/src/platform/sdl/main.c index c6621ecf5..9bbabedbc 100644 --- a/src/platform/sdl/main.c +++ b/src/platform/sdl/main.c @@ -5,33 +5,23 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "main.h" -#include "debugger/cli-debugger.h" +#include #ifdef USE_GDB_STUB -#include "debugger/gdb-stub.h" +#include #endif #ifdef USE_EDITLINE #include "feature/editline/cli-el-backend.h" #endif -#include "core/core.h" -#include "core/config.h" -#include "core/input.h" -#include "core/thread.h" -#include "gba/input.h" -#ifdef M_CORE_GBA -#include "gba/core.h" -#include "gba/gba.h" -#include "gba/video.h" -#endif -#ifdef M_CORE_GB -#include "gb/core.h" -#include "gb/gb.h" -#include "gb/video.h" -#endif +#include +#include +#include +#include +#include + #include "feature/commandline.h" -#include "util/configuration.h" -#include "util/vfs.h" +#include #include diff --git a/src/platform/sdl/main.h b/src/platform/sdl/main.h index ccfb052a5..0477692cb 100644 --- a/src/platform/sdl/main.h +++ b/src/platform/sdl/main.h @@ -6,13 +6,9 @@ #ifndef SDL_MAIN_H #define SDL_MAIN_H -#ifdef M_CORE_GBA -#include "gba/renderers/video-software.h" -#endif +#include -#ifdef M_CORE_GB -#include "gb/renderers/software.h" -#endif +CXX_GUARD_START #include "sdl-audio.h" #include "sdl-events.h" @@ -106,4 +102,7 @@ void mSDLGLCreate(struct mSDLRenderer* renderer); #if defined(BUILD_GLES2) || defined(USE_EPOXY) void mSDLGLES2Create(struct mSDLRenderer* renderer); #endif + +CXX_GUARD_END + #endif diff --git a/src/platform/sdl/sdl-audio.c b/src/platform/sdl/sdl-audio.c index b0745ba26..3028cd4ec 100644 --- a/src/platform/sdl/sdl-audio.c +++ b/src/platform/sdl/sdl-audio.c @@ -5,10 +5,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "sdl-audio.h" -#include "core/thread.h" -#include "gba/gba.h" +#include +#include +#include +#include -#include "third-party/blip_buf/blip_buf.h" +#include #define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2) diff --git a/src/platform/sdl/sdl-audio.h b/src/platform/sdl/sdl-audio.h index e51832d5d..dc21cb86c 100644 --- a/src/platform/sdl/sdl-audio.h +++ b/src/platform/sdl/sdl-audio.h @@ -6,9 +6,11 @@ #ifndef SDL_AUDIO_H #define SDL_AUDIO_H -#include "util/common.h" +#include -#include "core/log.h" +CXX_GUARD_START + +#include #include @@ -36,4 +38,6 @@ void mSDLDeinitAudio(struct mSDLAudio* context); void mSDLPauseAudio(struct mSDLAudio* context); void mSDLResumeAudio(struct mSDLAudio* context); +CXX_GUARD_END + #endif diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index 3da4c2a78..474265ce4 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -5,18 +5,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "sdl-events.h" -#include "core/input.h" -#include "core/serialize.h" -#include "core/thread.h" -#include "debugger/debugger.h" -#include "gba/input.h" -#include "gba/io.h" -#include "gba/rr/rr.h" -#include "gba/video.h" -#include "gba/renderers/video-software.h" -#include "util/configuration.h" -#include "util/formatting.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #if SDL_VERSION_ATLEAST(2, 0, 0) && defined(__APPLE__) #define GUI_MOD KMOD_GUI diff --git a/src/platform/sdl/sdl-events.h b/src/platform/sdl/sdl-events.h index 435072d2a..bebf02cea 100644 --- a/src/platform/sdl/sdl-events.h +++ b/src/platform/sdl/sdl-events.h @@ -6,12 +6,14 @@ #ifndef SDL_EVENTS_H #define SDL_EVENTS_H -#include "util/common.h" +#include -#include "core/interface.h" -#include "core/log.h" -#include "util/circle-buffer.h" -#include "util/vector.h" +CXX_GUARD_START + +#include +#include +#include +#include #include @@ -110,4 +112,6 @@ void mSDLResumeScreensaver(struct mSDLEvents*); void mSDLSetScreensaverSuspendable(struct mSDLEvents*, bool suspendable); #endif +CXX_GUARD_END + #endif diff --git a/src/platform/test/fuzz-main.c b/src/platform/test/fuzz-main.c index b8009f82e..d40a15937 100644 --- a/src/platform/test/fuzz-main.c +++ b/src/platform/test/fuzz-main.c @@ -3,17 +3,19 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "core/cheats.h" -#include "core/config.h" -#include "core/core.h" -#include "core/serialize.h" -#include "gb/core.h" -#include "gba/gba.h" +#include +#include +#include +#include +#include +#include +#include +#include #include "feature/commandline.h" -#include "util/memory.h" -#include "util/string.h" -#include "util/vfs.h" +#include +#include +#include #include #include diff --git a/src/platform/test/perf-main.c b/src/platform/test/perf-main.c index 390c49402..03fe093ce 100644 --- a/src/platform/test/perf-main.c +++ b/src/platform/test/perf-main.c @@ -3,16 +3,18 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "core/config.h" -#include "core/serialize.h" -#include "gba/core.h" -#include "gba/gba.h" -#include "gba/renderers/video-software.h" +#include +#include +#include +#include +#include +#include +#include #include "feature/commandline.h" -#include "util/socket.h" -#include "util/string.h" -#include "util/vfs.h" +#include +#include +#include #ifdef _3DS #include <3ds.h> diff --git a/src/platform/test/tbl-fuzz-main.c b/src/platform/test/tbl-fuzz-main.c index bd7e2ff00..d1c39fbd2 100644 --- a/src/platform/test/tbl-fuzz-main.c +++ b/src/platform/test/tbl-fuzz-main.c @@ -3,8 +3,8 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/text-codec.h" -#include "util/vfs.h" +#include +#include int main(int argc, char** argv) { struct TextCodec codec; diff --git a/src/platform/video-backend.h b/src/platform/video-backend.h index b67b676be..79264c4e2 100644 --- a/src/platform/video-backend.h +++ b/src/platform/video-backend.h @@ -6,7 +6,9 @@ #ifndef VIDEO_BACKEND_H #define VIDEO_BACKEND_H -#include "util/common.h" +#include + +CXX_GUARD_START #ifdef _WIN32 #include @@ -44,4 +46,6 @@ struct VideoShader { size_t nPasses; }; +CXX_GUARD_END + #endif diff --git a/src/platform/wii/gui-font.c b/src/platform/wii/gui-font.c index 101ca383b..1a247c751 100644 --- a/src/platform/wii/gui-font.c +++ b/src/platform/wii/gui-font.c @@ -3,8 +3,8 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/gui/font.h" -#include "util/gui/font-metrics.h" +#include +#include #include "icons.h" #include "font.h" diff --git a/src/platform/wii/main.c b/src/platform/wii/main.c index bcc9c8251..29096042e 100644 --- a/src/platform/wii/main.c +++ b/src/platform/wii/main.c @@ -12,18 +12,19 @@ #include #include -#include "util/common.h" +#include -#include "core/core.h" +#include +#include #include "feature/gui/gui-runner.h" -#include "gba/audio.h" -#include "gba/gba.h" -#include "gba/input.h" -#include "util/gui.h" -#include "util/gui/file-select.h" -#include "util/gui/font.h" -#include "util/gui/menu.h" -#include "util/vfs.h" +#include +#include +#include +#include +#include +#include +#include +#include #define GCN1_INPUT 0x47434E31 #define GCN2_INPUT 0x47434E32 diff --git a/src/platform/wii/wii-memory.c b/src/platform/wii/wii-memory.c index e034bf760..419b58f9a 100644 --- a/src/platform/wii/wii-memory.c +++ b/src/platform/wii/wii-memory.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/memory.h" +#include void* anonymousMemoryMap(size_t size) { return malloc(size); diff --git a/src/platform/windows/memory.c b/src/platform/windows/memory.c index d2baddbb1..3c05b02d7 100644 --- a/src/platform/windows/memory.c +++ b/src/platform/windows/memory.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/memory.h" +#include #include diff --git a/src/platform/windows/vfs-w32.c b/src/platform/windows/vfs-w32.c index 565feee07..398ec5ba4 100644 --- a/src/platform/windows/vfs-w32.c +++ b/src/platform/windows/vfs-w32.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/vfs.h" +#include -#include "util/string.h" +#include #include static bool _vdwClose(struct VDir* vd); @@ -63,6 +63,7 @@ struct VDir* VDirOpen(const char* path) { vd->vde.d.name = _vdweName; vd->vde.d.type = _vdweType; vd->vde.ffData = ffData; + vd->vde.utf8Name = NULL; return &vd->d; } diff --git a/src/third-party/blip_buf/blip_buf.c b/src/third-party/blip_buf/blip_buf.c index 362eede49..6bc7da8bd 100644 --- a/src/third-party/blip_buf/blip_buf.c +++ b/src/third-party/blip_buf/blip_buf.c @@ -1,6 +1,6 @@ /* blip_buf 1.1.0. http://www.slack.net/~ant/ */ -#include "blip_buf.h" +#include #include #include diff --git a/src/util/circle-buffer.c b/src/util/circle-buffer.c index 5220ced44..deb426473 100644 --- a/src/util/circle-buffer.c +++ b/src/util/circle-buffer.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "circle-buffer.h" +#include #ifndef NDEBUG static int _checkIntegrity(struct CircleBuffer* buffer) { diff --git a/src/util/configuration.c b/src/util/configuration.c index adae7f300..1021c5137 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "configuration.h" +#include -#include "util/formatting.h" -#include "util/string.h" -#include "util/vfs.h" +#include +#include +#include #include "third-party/inih/ini.h" diff --git a/src/util/crc32.c b/src/util/crc32.c index 77c1715f1..21a4354d4 100644 --- a/src/util/crc32.c +++ b/src/util/crc32.c @@ -40,9 +40,9 @@ * CRC32 code derived from work by Gary S. Brown. */ -#include "util/crc32.h" +#include -#include "util/vfs.h" +#include enum { BUFFER_SIZE = 1024 diff --git a/src/util/export.c b/src/util/export.c index 3e7145f7e..cb138ce5a 100644 --- a/src/util/export.c +++ b/src/util/export.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "export.h" +#include -#include "gba/video.h" -#include "util/vfs.h" +#include +#include bool exportPaletteRIFF(struct VFile* vf, size_t entries, const uint16_t* colors) { if (entries > 0xFFFF) { diff --git a/src/util/formatting.c b/src/util/formatting.c index e0f200ed6..ccd874622 100644 --- a/src/util/formatting.c +++ b/src/util/formatting.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "formatting.h" +#include #include #include diff --git a/src/util/gui.c b/src/util/gui.c index 5aed3d58b..ec37f99e5 100644 --- a/src/util/gui.c +++ b/src/util/gui.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "gui.h" +#include void GUIInit(struct GUIParams* params) { memset(params->inputHistory, 0, sizeof(params->inputHistory)); diff --git a/src/util/gui/file-select.c b/src/util/gui/file-select.c index 70bc91120..96bb632f2 100644 --- a/src/util/gui/file-select.c +++ b/src/util/gui/file-select.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "file-select.h" +#include -#include "util/gui/font.h" -#include "util/gui/menu.h" -#include "util/vfs.h" +#include +#include +#include #include diff --git a/src/util/gui/font-metrics.c b/src/util/gui/font-metrics.c index 3513fec70..0e965a3e6 100644 --- a/src/util/gui/font-metrics.c +++ b/src/util/gui/font-metrics.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/gui/font.h" +#include const struct GUIFontGlyphMetric defaultFontMetrics[128] = { { 0, 0, { 0, 0, 0, 0 }}, // 0x00 diff --git a/src/util/gui/font.c b/src/util/gui/font.c index 03965bf24..05ceffa92 100644 --- a/src/util/gui/font.c +++ b/src/util/gui/font.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/gui/font.h" +#include -#include "util/string.h" +#include unsigned GUIFontSpanWidth(const struct GUIFont* font, const char* text) { unsigned width = 0; diff --git a/src/util/gui/menu.c b/src/util/gui/menu.c index dcfdfdab7..6f8eb8327 100644 --- a/src/util/gui/menu.c +++ b/src/util/gui/menu.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "menu.h" +#include -#include "util/gui.h" -#include "util/gui/font.h" +#include +#include #ifdef _3DS #include <3ds.h> diff --git a/src/util/hash.c b/src/util/hash.c index 96e2ffb7f..9db508c13 100644 --- a/src/util/hash.c +++ b/src/util/hash.c @@ -1,7 +1,7 @@ // MurmurHash3 was written by Austin Appleby, and is placed in the public // domain. The author hereby disclaims copyright to this source code. -#include "hash.h" +#include #if defined(_MSC_VER) diff --git a/src/util/nointro.c b/src/util/nointro.c index fdf3008b3..bb5471572 100644 --- a/src/util/nointro.c +++ b/src/util/nointro.c @@ -3,12 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nointro.h" +#include -#include "util/crc32.h" -#include "util/table.h" -#include "util/vector.h" -#include "util/vfs.h" +#include +#include +#include #define KEY_STACK_SIZE 8 diff --git a/src/util/patch-fast.c b/src/util/patch-fast.c index d2722792f..81b3aa45a 100644 --- a/src/util/patch-fast.c +++ b/src/util/patch-fast.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "patch-fast.h" +#include DEFINE_VECTOR(PatchFastExtents, struct PatchFastExtent); diff --git a/src/util/patch-ips.c b/src/util/patch-ips.c index 0249f9ce9..34b41658d 100644 --- a/src/util/patch-ips.c +++ b/src/util/patch-ips.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/patch-ips.h" +#include -#include "util/patch.h" -#include "util/vfs.h" +#include +#include static size_t _IPSOutputSize(struct Patch* patch, size_t inSize); static bool _IPSApplyPatch(struct Patch* patch, const void* in, size_t inSize, void* out, size_t outSize); diff --git a/src/util/patch-ups.c b/src/util/patch-ups.c index 80573387a..d58ee2216 100644 --- a/src/util/patch-ups.c +++ b/src/util/patch-ups.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/patch-ips.h" +#include -#include "util/crc32.h" -#include "util/patch.h" -#include "util/vfs.h" +#include +#include +#include enum { IN_CHECKSUM = -12, diff --git a/src/util/patch.c b/src/util/patch.c index d4e950e6c..b83c0d853 100644 --- a/src/util/patch.c +++ b/src/util/patch.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/patch.h" +#include -#include "util/patch-ips.h" -#include "util/patch-ups.h" +#include +#include bool loadPatch(struct VFile* vf, struct Patch* patch) { patch->vf = vf; diff --git a/src/util/png-io.c b/src/util/png-io.c index 09631dbe4..e3e17ff5e 100644 --- a/src/util/png-io.c +++ b/src/util/png-io.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/png-io.h" +#include #ifdef USE_PNG -#include "vfs.h" +#include static void _pngWrite(png_structp png, png_bytep buffer, png_size_t size) { struct VFile* vf = png_get_io_ptr(png); diff --git a/src/util/ring-fifo.c b/src/util/ring-fifo.c index 5cac3f2c4..167690c61 100644 --- a/src/util/ring-fifo.c +++ b/src/util/ring-fifo.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "ring-fifo.h" +#include -#include "util/memory.h" +#include void RingFIFOInit(struct RingFIFO* buffer, size_t capacity) { buffer->data = anonymousMemoryMap(capacity); diff --git a/src/util/string.c b/src/util/string.c index eb05768db..7e18a8547 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/string.h" +#include #include diff --git a/src/util/table.c b/src/util/table.c index ebc756c29..179d40a00 100644 --- a/src/util/table.c +++ b/src/util/table.c @@ -3,10 +3,10 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "table.h" +#include -#include "util/hash.h" -#include "util/string.h" +#include +#include #define LIST_INITIAL_SIZE 8 #define TABLE_INITIAL_SIZE 8 @@ -163,6 +163,14 @@ size_t TableSize(const struct Table* table) { return table->size; } +void HashTableInit(struct Table* table, size_t initialSize, void (deinitializer(void*))) { + TableInit(table, initialSize, deinitializer); +} + +void HashTableDeinit(struct Table* table) { + TableDeinit(table); +} + void* HashTableLookup(const struct Table* table, const char* key) { uint32_t hash = hash32(key, strlen(key), 0); const struct TableList* list; diff --git a/src/util/test/suite.h b/src/util/test/suite.h index f446e2cf6..dd947830d 100644 --- a/src/util/test/suite.h +++ b/src/util/test/suite.h @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef SUITE_H #define SUITE_H -#include "util/common.h" +#include #include #include diff --git a/src/util/test/text-codec.c b/src/util/test/text-codec.c index 75e382f8c..54c05703f 100644 --- a/src/util/test/text-codec.c +++ b/src/util/test/text-codec.c @@ -5,8 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/test/suite.h" -#include "util/text-codec.h" -#include "util/vfs.h" +#include +#include M_TEST_DEFINE(emptyCodec) { struct VFile* vf = VFileMemChunk(NULL, 0); diff --git a/src/util/test/util.h b/src/util/test/util.h index e5a374554..0a665b995 100644 --- a/src/util/test/util.h +++ b/src/util/test/util.h @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef TEST_UTIL_H #define TEST_UTIL_H -#include "util/common.h" +#include int TestRunUtil(void); diff --git a/src/util/test/vfs.c b/src/util/test/vfs.c index b011d5039..cc623d1b0 100644 --- a/src/util/test/vfs.c +++ b/src/util/test/vfs.c @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/test/suite.h" -#include "util/vfs.h" +#include #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 M_TEST_DEFINE(openNullPathR) { diff --git a/src/util/text-codec.c b/src/util/text-codec.c index 399016f59..173f2b36c 100644 --- a/src/util/text-codec.c +++ b/src/util/text-codec.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "text-codec.h" +#include -#include "util/string.h" -#include "util/table.h" -#include "util/vfs.h" +#include +#include +#include struct TextCodecNode { uint8_t* leaf; diff --git a/src/util/vfs.c b/src/util/vfs.c index 5f6533762..82035ec1e 100644 --- a/src/util/vfs.c +++ b/src/util/vfs.c @@ -3,15 +3,15 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "vfs.h" +#include -#include "util/string.h" +#include #ifdef PSP2 -#include "platform/psp2/sce-vfs.h" +#include #endif #ifdef _3DS -#include "platform/3ds/3ds-vfs.h" +#include #endif struct VFile* VFileOpen(const char* path, int flags) { @@ -104,7 +104,7 @@ struct VDir* VDirOpenArchive(const char* path) { dir = VDirOpenZip(path, 0); } #endif -#if USE_LZMA +#ifdef USE_LZMA if (!dir) { dir = VDirOpen7z(path, 0); } diff --git a/src/util/vfs/vfs-devlist.c b/src/util/vfs/vfs-devlist.c index 8f25feb17..667ffd193 100644 --- a/src/util/vfs/vfs-devlist.c +++ b/src/util/vfs/vfs-devlist.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/vfs.h" +#include #include diff --git a/src/util/vfs/vfs-dirent.c b/src/util/vfs/vfs-dirent.c index 7104af808..d124af355 100644 --- a/src/util/vfs/vfs-dirent.c +++ b/src/util/vfs/vfs-dirent.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/vfs.h" +#include -#include "util/string.h" +#include #include #include diff --git a/src/util/vfs/vfs-fd.c b/src/util/vfs/vfs-fd.c index 2b0f418c9..39b2164ee 100644 --- a/src/util/vfs/vfs-fd.c +++ b/src/util/vfs/vfs-fd.c @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/vfs.h" +#include #include #include diff --git a/src/util/vfs/vfs-file.c b/src/util/vfs/vfs-file.c index 57ab37efa..bfde30e93 100644 --- a/src/util/vfs/vfs-file.c +++ b/src/util/vfs/vfs-file.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/vfs.h" +#include -#include "util/memory.h" +#include #include #include diff --git a/src/util/vfs/vfs-lzma.c b/src/util/vfs/vfs-lzma.c index 359628abd..53bf5e619 100644 --- a/src/util/vfs/vfs-lzma.c +++ b/src/util/vfs/vfs-lzma.c @@ -3,11 +3,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/vfs.h" +#include #ifdef USE_LZMA -#include "util/string.h" +#include #include "third-party/lzma/7z.h" #include "third-party/lzma/7zAlloc.h" diff --git a/src/util/vfs/vfs-mem.c b/src/util/vfs/vfs-mem.c index 2d8798012..7264577cf 100644 --- a/src/util/vfs/vfs-mem.c +++ b/src/util/vfs/vfs-mem.c @@ -3,8 +3,8 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/vfs.h" -#include "util/memory.h" +#include +#include struct VFileMem { struct VFile d; diff --git a/src/util/vfs/vfs-zip.c b/src/util/vfs/vfs-zip.c index a0773ae8a..13220a303 100644 --- a/src/util/vfs/vfs-zip.c +++ b/src/util/vfs/vfs-zip.c @@ -3,9 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "util/vfs.h" +#include -#include "util/string.h" +#include #ifdef USE_LIBZIP #include @@ -41,7 +41,7 @@ enum { #else #include "third-party/zlib/contrib/minizip/unzip.h" #endif -#include "util/memory.h" +#include struct VDirEntryZip { struct VDirEntry d;