all repos — mgba @ 87caf0a6acc558dcfbf90b7981e38d0a6a5128da

mGBA Game Boy Advance Emulator

Merge branch 'master' into medusa
Jeffrey Pfau jeffrey@endrift.com
Mon, 02 Jan 2017 18:17:50 -0800
commit

87caf0a6acc558dcfbf90b7981e38d0a6a5128da

parent

871ce36386905810de2b7cdff6d13feb10f83daf

413 files changed, 3824 insertions(+), 1563 deletions(-)

jump to
M .gitignore.gitignore

@@ -2,3 +2,4 @@ /build

*.user* *~ *.swp +*.pyc
M CHANGESCHANGES

@@ -7,43 +7,12 @@ - Sprite viewer

- 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 @@ - Test: Add a basic test suite

- 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 @@ - Qt: Move last directory setting from qt.ini to config.ini

- 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:
M CMakeLists.txtCMakeLists.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 @@ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

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(M_CORE_GBA)

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 @@ set_target_properties(${BINARY_NAME}-suite PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")

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 @@ add_executable(${BINARY_NAME}-example-client ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/client.c)

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 @@ message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")

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}")
A 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 <mgba-util/common.h> + +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
A include/mgba/internal/gb/sio.h

@@ -0,0 +1,60 @@

+/* 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_H +#define GB_SIO_H + +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/core/log.h> +#include <mgba/core/timing.h> + +#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; + int remainingBits; + + 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); +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
A 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 <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/core/lockstep.h> +#include <mgba/core/timing.h> +#include <mgba/internal/gb/sio.h> + +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
A include/mgba/internal/gba/sio/lockstep.h

@@ -0,0 +1,53 @@

+/* Copyright (c) 2013-2015 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 GBA_SIO_LOCKSTEP_H +#define GBA_SIO_LOCKSTEP_H + +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/core/lockstep.h> +#include <mgba/core/timing.h> +#include <mgba/internal/gba/sio.h> + +struct GBASIOLockstep { + struct mLockstep d; + struct GBASIOLockstepNode* players[MAX_GBAS]; + int attachedMulti; + int attachedNormal; + + uint16_t multiRecv[MAX_GBAS]; + uint32_t normalRecv[MAX_GBAS]; +}; + +struct GBASIOLockstepNode { + struct GBASIODriver d; + struct GBASIOLockstep* p; + struct mTimingEvent event; + + volatile int32_t nextEvent; + int32_t eventDiff; + bool normalSO; + int id; + enum GBASIOMode mode; + bool transferFinished; +#ifndef NDEBUG + int transferId; + enum mLockstepPhase phase; +#endif +}; + +void GBASIOLockstepInit(struct GBASIOLockstep*); + +void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode*); + +bool GBASIOLockstepAttachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*); +void GBASIOLockstepDetachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*); + +CXX_GUARD_END + +#endif
M src/arm/arm.csrc/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 <mgba/internal/arm/arm.h> -#include "arm/isa-arm.h" -#include "arm/isa-inlines.h" -#include "arm/isa-thumb.h" +#include <mgba/internal/arm/isa-arm.h> +#include <mgba/internal/arm/isa-inlines.h> +#include <mgba/internal/arm/isa-thumb.h> static inline enum RegisterBank _ARMSelectBank(enum PrivilegeMode);
M src/arm/arm.hinclude/mgba/internal/arm/arm.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef ARM_H #define ARM_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/cpu.h" +CXX_GUARD_START + +#include <mgba/core/cpu.h> enum { ARM_SP = 13,

@@ -73,7 +75,7 @@ unsigned n : 1;

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 @@ unsigned priv : 5;

unsigned t : 1; unsigned f : 1; unsigned i : 1; - unsigned : 20; + unsigned unused : 20; unsigned v : 1; unsigned c : 1; unsigned z : 1;

@@ -260,5 +262,7 @@ void ARMv5Run(struct ARMCore* cpu);

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
M src/arm/debugger/cli-debugger.csrc/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 <mgba/internal/arm/debugger/cli-debugger.h> -#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 <mgba/core/core.h> +#include <mgba/internal/arm/debugger/debugger.h> +#include <mgba/internal/arm/debugger/memory-debugger.h> +#include <mgba/internal/arm/decoder.h> +#include <mgba/internal/debugger/cli-debugger.h> static void _printStatus(struct CLIDebuggerSystem*);
M src/arm/debugger/cli-debugger.hinclude/mgba/internal/arm/debugger/cli-debugger.h

@@ -6,9 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef ARM_CLI_DEBUGGER_H #define ARM_CLI_DEBUGGER_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct CLIDebuggerSystem; void ARMCLIDebuggerCreate(struct CLIDebuggerSystem* debugger); + +CXX_GUARD_END #endif
M src/arm/debugger/debugger.csrc/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 <mgba/internal/arm/debugger/debugger.h> -#include "arm/arm.h" -#include "arm/isa-inlines.h" -#include "arm/debugger/memory-debugger.h" -#include "core/core.h" +#include <mgba/core/core.h> +#include <mgba/internal/arm/arm.h> +#include <mgba/internal/arm/isa-inlines.h> +#include <mgba/internal/arm/debugger/memory-debugger.h> DEFINE_VECTOR(ARMDebugBreakpointList, struct ARMDebugBreakpoint); DEFINE_VECTOR(ARMDebugWatchpointList, struct ARMDebugWatchpoint);
M src/arm/debugger/debugger.hinclude/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 <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/internal/debugger/debugger.h> + +#include <mgba/internal/arm/arm.h> struct ARMDebugBreakpoint { uint32_t address;

@@ -40,3 +49,7 @@

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
M src/arm/debugger/memory-debugger.csrc/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 <mgba/internal/arm/debugger/memory-debugger.h> -#include "arm/debugger/debugger.h" +#include <mgba/internal/arm/debugger/debugger.h> -#include "util/math.h" +#include <mgba-util/math.h> #include <string.h>
M src/arm/debugger/memory-debugger.hinclude/mgba/internal/arm/debugger/memory-debugger.h

@@ -6,11 +6,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef MEMORY_DEBUGGER_H #define MEMORY_DEBUGGER_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct ARMDebugger; void ARMDebuggerInstallMemoryShim(struct ARMDebugger* debugger); void ARMDebuggerRemoveMemoryShim(struct ARMDebugger* debugger); + +CXX_GUARD_END #endif
M src/arm/decoder-arm.csrc/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 <mgba/internal/arm/decoder.h> -#include "decoder-inlines.h" -#include "emitter-arm.h" -#include "isa-inlines.h" +#include <mgba/internal/arm/decoder-inlines.h> +#include <mgba/internal/arm/emitter-arm.h> +#include <mgba/internal/arm/isa-inlines.h> #define ADDR_MODE_1_SHIFT(OP) \ info->op3.reg = opcode & 0x0000000F; \
M src/arm/decoder-thumb.csrc/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 <mgba/internal/arm/decoder.h> -#include "decoder-inlines.h" -#include "emitter-thumb.h" -#include "isa-inlines.h" +#include <mgba/internal/arm/decoder-inlines.h> +#include <mgba/internal/arm/emitter-thumb.h> +#include <mgba/internal/arm/isa-inlines.h> #define DEFINE_THUMB_DECODER(NAME, MNEMONIC, BODY) \ static void _ThumbDecode ## NAME (uint16_t opcode, struct ARMInstructionInfo* info) { \
M src/arm/decoder.csrc/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 <mgba/internal/arm/decoder.h> -#include "decoder-inlines.h" +#include <mgba/internal/arm/decoder-inlines.h> #define ADVANCE(AMOUNT) \ if (AMOUNT > blen) { \
M src/arm/decoder.hinclude/mgba/internal/arm/decoder.h

@@ -6,7 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef ARM_DECODER_H #define ARM_DECODER_H -#include "arm.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/internal/arm/arm.h> // Bit 0: a register is involved with this operand // Bit 1: an immediate is invovled with this operand

@@ -233,5 +237,7 @@ void ARMDecodeThumb(uint16_t opcode, struct ARMInstructionInfo* info);

bool ARMDecodeThumbCombine(struct ARMInstructionInfo* info1, struct ARMInstructionInfo* info2, struct ARMInstructionInfo* out); int ARMDisassemble(struct ARMInstructionInfo* info, uint32_t pc, char* buffer, int blen); + +CXX_GUARD_END #endif
M src/arm/isa-arm.csrc/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 <mgba/internal/arm/isa-arm.h> -#include "arm.h" -#include "emitter-arm.h" -#include "isa-inlines.h" -#include "util/math.h" +#include <mgba/internal/arm/arm.h> +#include <mgba/internal/arm/emitter-arm.h> +#include <mgba/internal/arm/isa-inlines.h> +#include <mgba-util/math.h> #define PSR_USER_MASK 0xF0000000 #define PSR_PRIV_MASK 0x000000CF

@@ -317,6 +317,19 @@ DEFINE_ALU_INSTRUCTION_EX_ARM(NAME ## I, S_BODY, _immediate, BODY)

#define DEFINE_MULTIPLY_INSTRUCTION_EX_ARM(NAME, BODY, S_BODY) \ DEFINE_INSTRUCTION_ARM(NAME, \ + int rd = (opcode >> 16) & 0xF; \ + int rs = (opcode >> 8) & 0xF; \ + int rm = opcode & 0xF; \ + if (rd == ARM_PC) { \ + return; \ + } \ + ARM_WAIT_MUL(cpu->gprs[rs]); \ + BODY; \ + 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; \

@@ -324,7 +337,7 @@ int rm = opcode & 0xF; \

if (rdHi == ARM_PC || rd == ARM_PC) { \ return; \ } \ - ARM_WAIT_MUL(cpu->gprs[rs]); \ + currentCycles += cpu->memory.stall(cpu, WAIT); \ BODY; \ S_BODY; \ currentCycles += cpu->memory.activeNonseqCycles32 - cpu->memory.activeSeqCycles32)

@@ -332,6 +345,10 @@

#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, \

@@ -486,36 +503,36 @@ // End ALU definitions

// 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
M src/arm/isa-arm.hinclude/mgba/internal/arm/isa-arm.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef ISA_ARM_H #define ISA_ARM_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START #define ARM_PREFETCH_CYCLES (1 + cpu->memory.activeSeqCycles32)

@@ -15,5 +17,7 @@

typedef void (*ARMInstruction)(struct ARMCore*, uint32_t opcode); extern const ARMInstruction _armv4Table[0x1000]; extern const ARMInstruction _armv5Table[0x1000]; + +CXX_GUARD_END #endif
M src/arm/isa-thumb.csrc/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 <mgba/internal/arm/isa-thumb.h> -#include "isa-inlines.h" -#include "emitter-thumb.h" +#include <mgba/internal/arm/isa-inlines.h> +#include <mgba/internal/arm/emitter-thumb.h> // Instruction definitions // Beware pre-processor insanity
M src/arm/isa-thumb.hinclude/mgba/internal/arm/isa-thumb.h

@@ -6,11 +6,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef ISA_THUMB_H #define ISA_THUMB_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct ARMCore; typedef void (*ThumbInstruction)(struct ARMCore*, uint16_t opcode); extern const ThumbInstruction _thumbTable[0x400]; + +CXX_GUARD_END #endif
M src/arm/macros.hinclude/mgba/internal/arm/macros.h

@@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef MACROS_H #define MACROS_H -#include "util/common.h" +#include <mgba-util/common.h> #define LOAD_64 LOAD_64LE #define LOAD_32 LOAD_32LE
M src/core/cheats.csrc/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 <mgba/core/cheats.h> -#include "core/core.h" -#include "util/string.h" -#include "util/vfs.h" +#include <mgba/core/core.h> +#include <mgba-util/string.h> +#include <mgba-util/vfs.h> #define MAX_LINE_LENGTH 128
M src/core/cheats.hinclude/mgba/core/cheats.h

@@ -6,11 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef CHEATS_H #define CHEATS_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/cpu.h" -#include "core/log.h" -#include "util/vector.h" +CXX_GUARD_START + +#include <mgba/core/cpu.h> +#include <mgba/core/log.h> +#include <mgba-util/vector.h> #define MAX_ROM_PATCHES 4

@@ -99,5 +101,7 @@ bool mCheatParseFile(struct mCheatDevice*, struct VFile*);

bool mCheatSaveFile(struct mCheatDevice*, struct VFile*); void mCheatRefresh(struct mCheatDevice*, struct mCheatSet*); + +CXX_GUARD_END #endif
M src/core/config.csrc/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 <mgba/core/config.h> -#include "core/version.h" -#include "util/formatting.h" -#include "util/string.h" -#include "util/vfs.h" +#include <mgba/core/version.h> +#include <mgba-util/formatting.h> +#include <mgba-util/string.h> +#include <mgba-util/vfs.h> #include <sys/stat.h>

@@ -24,7 +24,7 @@ #include <psp2/io/stat.h>

#endif #ifdef _3DS -#include "platform/3ds/3ds-vfs.h" +#include <mgba-util/platform/3ds/3ds-vfs.h> #endif #define SECTION_NAME_MAX 128
M src/core/config.hinclude/mgba/core/config.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_CORE_CONFIG_H #define M_CORE_CONFIG_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "util/configuration.h" +CXX_GUARD_START + +#include <mgba-util/configuration.h> struct mCoreConfig { struct Configuration configTable;

@@ -90,5 +92,7 @@ struct Configuration* mCoreConfigGetOverrides(struct mCoreConfig*);

const struct Configuration* mCoreConfigGetOverridesConst(const struct mCoreConfig*); void mCoreConfigFreeOpts(struct mCoreOptions* opts); + +CXX_GUARD_END #endif
M src/core/core.csrc/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 <mgba/core/core.h> -#include "core/log.h" -#include "core/serialize.h" -#include "util/vfs.h" +#include <mgba/core/log.h> +#include <mgba/core/serialize.h> +#include <mgba-util/vfs.h> #ifdef M_CORE_GB -#include "gb/core.h" -#include "gb/gb.h" +#include <mgba/gb/core.h> +// TODO: Fix layering violation +#include <mgba/internal/gb/gb.h> #endif #ifdef M_CORE_GBA -#include "gba/core.h" -#include "gba/gba.h" +#include <mgba/gba/core.h> +#include <mgba/internal/gba/gba.h> #endif #ifdef M_CORE_DS -#include "ds/core.h" -#include "ds/ds.h" +#include <mgba/ds/core.h> +#include <mgba/internal/ds/ds.h> #endif static struct mCoreFilter {

@@ -69,7 +70,7 @@ return PLATFORM_NONE;

} #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 -#include "util/png-io.h" +#include <mgba-util/png-io.h> #ifdef PSP2 #include <psp2/photoexport.h>
M src/core/core.hinclude/mgba/core/core.h

@@ -6,18 +6,21 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_CORE_H #define M_CORE_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/config.h" +CXX_GUARD_START + +#include <mgba/core/config.h> #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 -#include "core/directories.h" +#include <mgba/core/directories.h> #endif #ifndef MINIMAL_CORE -#include "core/input.h" +#include <mgba/core/input.h> #endif -#include "core/interface.h" +#include <mgba/core/interface.h> #ifdef USE_DEBUGGERS -#include "debugger/debugger.h" +// TODO: Fix layering violation +#include <mgba/internal/debugger/debugger.h> #endif enum mPlatform {

@@ -161,5 +164,7 @@

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
M src/core/cpu.hinclude/mgba/core/cpu.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_CPU_H #define M_CPU_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START enum mCPUComponentType { CPU_COMPONENT_DEBUGGER,

@@ -19,5 +21,7 @@ uint32_t id;

void (*init)(void* cpu, struct mCPUComponent* component); void (*deinit)(struct mCPUComponent* component); }; + +CXX_GUARD_END #endif
M src/core/directories.csrc/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 <mgba/core/directories.h> -#include "core/config.h" -#include "util/vfs.h" +#include <mgba/core/config.h> +#include <mgba-util/vfs.h> #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 void mDirectorySetInit(struct mDirectorySet* dirs) {
M src/core/directories.hinclude/mgba/core/directories.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DIRECTORIES_H #define DIRECTORIES_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 struct VDir;

@@ -33,5 +35,7 @@

struct mCoreOptions; void mDirectorySetMapOptions(struct mDirectorySet* dirs, const struct mCoreOptions* opts); #endif + +CXX_GUARD_END #endif
A 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
M src/core/input.csrc/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 <mgba/core/input.h> -#include "util/configuration.h" -#include "util/table.h" +#include <mgba-util/configuration.h> +#include <mgba-util/table.h> #include <inttypes.h>
M src/core/input.hinclude/mgba/core/input.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_INPUT_H #define M_INPUT_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct Configuration;

@@ -59,5 +61,7 @@ const char* mInputGetCustomValue(const struct Configuration* config, const char* platformName, uint32_t type, const char* key,

const char* profile); void mInputSetCustomValue(struct Configuration* config, const char* platformName, uint32_t type, const char* key, const char* value, const char* profile); + +CXX_GUARD_END #endif
M src/core/interface.csrc/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 <mgba/core/interface.h> -#include "core/core.h" +#include <mgba/core/core.h> #include <time.h> static time_t _rtcGenericCallback(struct mRTCSource* source) {
M src/core/interface.hinclude/mgba/core/interface.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef CORE_INTERFACE_H #define CORE_INTERFACE_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct mCore;

@@ -83,5 +85,7 @@

struct mRumble { void (*setRumble)(struct mRumble*, int enable); }; + +CXX_GUARD_END #endif
M src/core/library.csrc/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 <mgba/core/library.h> -#include "util/vfs.h" +#include <mgba-util/vfs.h> DEFINE_VECTOR(mLibraryListing, struct mLibraryEntry);
M src/core/library.hinclude/mgba/core/library.h

@@ -6,10 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_LIBRARY_H #define M_LIBRARY_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/core.h" -#include "util/vector.h" +CXX_GUARD_START + +#include <mgba/core/core.h> +#include <mgba-util/vector.h> struct mLibraryEntry { char* filename;

@@ -33,5 +35,7 @@ struct VDir;

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
A 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 <mgba/core/lockstep.h> + +void mLockstepInit(struct mLockstep* lockstep) { + lockstep->attached = 0; + lockstep->transferActive = 0; +#ifndef NDEBUG + lockstep->transferId = 0; +#endif +} + +// TODO: Migrate nodes
M src/core/log.csrc/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 <mgba/core/log.h> -#include "core/thread.h" +#include <mgba/core/thread.h> #define MAX_CATEGORY 64

@@ -42,6 +42,20 @@ if (category < MAX_CATEGORY) {

return _categoryNames[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")
M src/core/log.hinclude/mgba/core/log.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_LOG_H #define M_LOG_H -#include "util/common.h" +#include <mgba-util/common.h> + +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__)

@@ -57,5 +47,7 @@ return category; \

} mLOG_DECLARE_CATEGORY(STATUS) + +CXX_GUARD_END #endif
M src/core/rewind.csrc/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 <mgba/core/rewind.h> -#include "core/core.h" -#include "util/patch-fast.h" -#include "util/vfs.h" +#include <mgba/core/core.h> +#include <mgba-util/patch/fast.h> +#include <mgba-util/vfs.h> DEFINE_VECTOR(mCoreRewindPatches, struct PatchFast);
M src/core/rewind.hinclude/mgba/core/rewind.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_CORE_REWIND_H #define M_CORE_REWIND_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "util/vector.h" +CXX_GUARD_START + +#include <mgba-util/vector.h> DECLARE_VECTOR(mCoreRewindPatches, struct PatchFast);

@@ -27,5 +29,7 @@

struct mCore; void mCoreRewindAppend(struct mCoreRewindContext*, struct mCore*); bool mCoreRewindRestore(struct mCoreRewindContext*, struct mCore*); + +CXX_GUARD_END #endif
M src/core/serialize.csrc/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 <mgba/core/serialize.h> -#include "core/core.h" -#include "core/cheats.h" -#include "util/memory.h" -#include "util/vfs.h" +#include <mgba/core/core.h> +#include <mgba/core/cheats.h> +#include <mgba-util/memory.h> +#include <mgba-util/vfs.h> #ifdef USE_PNG -#include "util/png-io.h" +#include <mgba-util/png-io.h> #include <png.h> #include <zlib.h> #endif
M src/core/serialize.hinclude/mgba/core/serialize.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_SERIALIZE_H #define M_SERIALIZE_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START enum mStateExtdataTag { EXTDATA_NONE = 0,

@@ -43,5 +45,7 @@ struct mCore;

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
M src/core/sync.csrc/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 <mgba/core/sync.h> static void _changeVideoSync(struct mCoreSync* sync, bool frameOn) { // Make sure the video thread can process events while the GBA thread is paused
M src/core/sync.hinclude/mgba/core/sync.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_CORE_SYNC_H #define M_CORE_SYNC_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "util/threading.h" +CXX_GUARD_START + +#include <mgba-util/threading.h> struct mCoreSync { int videoFramePending;

@@ -35,5 +37,7 @@ void mCoreSyncProduceAudio(struct mCoreSync* sync, bool wait);

void mCoreSyncLockAudio(struct mCoreSync* sync); void mCoreSyncUnlockAudio(struct mCoreSync* sync); void mCoreSyncConsumeAudio(struct mCoreSync* sync); + +CXX_GUARD_END #endif
M src/core/test/core.csrc/core/test/core.c

@@ -5,8 +5,8 @@ * 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/test/suite.h" -#include "core/core.h" -#include "util/vfs.h" +#include <mgba/core/core.h> +#include <mgba-util/vfs.h> #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 M_TEST_DEFINE(findNullPath) {
M src/core/test/core.hsrc/core/test/core.h

@@ -5,7 +5,7 @@ * 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 TEST_M_CORE_H #define TEST_M_CORE_H -#include "util/common.h" +#include <mgba-util/common.h> int TestRunCore(void);
M src/core/thread.csrc/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 "core/core.h" -#include "util/patch.h" -#include "util/vfs.h" +#include <mgba/core/thread.h> -#include "feature/commandline.h" +#include <mgba/core/core.h> +#include <mgba-util/patch.h> +#include <mgba-util/vfs.h> #include <signal.h>
M src/core/thread.hinclude/mgba/core/thread.h

@@ -6,12 +6,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_CORE_THREAD_H #define M_CORE_THREAD_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" -#include "core/rewind.h" -#include "core/sync.h" -#include "util/threading.h" +CXX_GUARD_START + +#include <mgba/core/log.h> +#include <mgba/core/rewind.h> +#include <mgba/core/sync.h> +#include <mgba-util/threading.h> struct mCoreThread; struct mCore;

@@ -96,5 +98,7 @@ void mCoreThreadSetRewinding(struct mCoreThread* threadContext, bool);

struct mCoreThread* mCoreThreadGet(void); struct mLogger* mCoreThreadLogger(void); + +CXX_GUARD_END #endif
M src/core/tile-cache.csrc/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 <mgba/core/tile-cache.h> -#include "util/memory.h" +#include <mgba-util/memory.h> void mTileCacheInit(struct mTileCache* cache) { // TODO: Reconfigurable cache for space savings
M src/core/tile-cache.hinclude/mgba/core/tile-cache.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_TILE_CACHE_H #define M_TILE_CACHE_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START DECL_BITFIELD(mTileCacheConfiguration, uint32_t); DECL_BIT(mTileCacheConfiguration, ShouldStore, 0);

@@ -56,5 +58,7 @@ 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
M src/core/timing.csrc/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 <mgba/core/timing.h> void mTimingInit(struct mTiming* timing, int32_t* relativeCycles, int32_t* nextEvent) { timing->root = NULL;
M src/core/timing.hinclude/mgba/core/timing.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef M_CORE_TIMING #define M_CORE_TIMING -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct mTiming; struct mTimingEvent {

@@ -36,5 +38,7 @@ bool mTimingIsScheduled(const struct mTiming* timing, const struct mTimingEvent*);

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
M src/core/version.c.insrc/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 <mgba/core/version.h> const char* const gitCommit = "${GIT_COMMIT}"; const char* const gitCommitShort = "${GIT_COMMIT_SHORT}";
M src/debugger/cli-debugger.csrc/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 <mgba/internal/debugger/cli-debugger.h> -#include "core/core.h" -#include "core/version.h" -#include "debugger/parser.h" -#include "util/string.h" +#include <mgba/core/core.h> +#include <mgba/core/version.h> +#include <mgba/internal/debugger/parser.h> +#include <mgba-util/string.h> #if !defined(NDEBUG) && !defined(_WIN32) #include <signal.h>
M src/debugger/cli-debugger.hinclude/mgba/internal/debugger/cli-debugger.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef CLI_DEBUGGER_H #define CLI_DEBUGGER_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "debugger.h" +CXX_GUARD_START + +#include <mgba/internal/debugger/debugger.h> struct CLIDebugger;

@@ -85,5 +87,7 @@ void CLIDebuggerAttachSystem(struct CLIDebugger*, struct CLIDebuggerSystem*);

void CLIDebuggerAttachBackend(struct CLIDebugger*, struct CLIDebuggerBackend*); bool CLIDebuggerTabComplete(struct CLIDebugger*, const char* token, bool initial, size_t len); + +CXX_GUARD_END #endif
M src/debugger/debugger.csrc/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 <mgba/internal/debugger/debugger.h> -#include "core/core.h" +#include <mgba/core/core.h> -#include "debugger/cli-debugger.h" +#include <mgba/internal/debugger/cli-debugger.h> #ifdef USE_GDB_STUB -#include "debugger/gdb-stub.h" +#include <mgba/internal/debugger/gdb-stub.h> #endif const uint32_t DEBUGGER_ID = 0xDEADBEEF;
M src/debugger/debugger.hinclude/mgba/internal/debugger/debugger.h

@@ -6,11 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DEBUGGER_H #define DEBUGGER_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "arm/arm.h" -#include "core/log.h" -#include "util/vector.h" +CXX_GUARD_START + +#include <mgba/core/cpu.h> +#include <mgba/core/log.h> +#include <mgba-util/vector.h> mLOG_DECLARE_CATEGORY(DEBUGGER);

@@ -35,7 +37,7 @@

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
M src/debugger/gdb-stub.csrc/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 <mgba/internal/debugger/gdb-stub.h> -#include "arm/debugger/debugger.h" -#include "arm/isa-inlines.h" -#include "core/core.h" -#include "gba/memory.h" +#include <mgba/core/core.h> +#include <mgba/internal/arm/debugger/debugger.h> +#include <mgba/internal/arm/isa-inlines.h> +#include <mgba/internal/gba/memory.h> #include <signal.h>
M src/debugger/gdb-stub.hinclude/mgba/internal/debugger/gdb-stub.h

@@ -6,11 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GDB_STUB_H #define GDB_STUB_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "debugger/debugger.h" +CXX_GUARD_START -#include "util/socket.h" +#include <mgba/internal/debugger/debugger.h> + +#include <mgba-util/socket.h> #define GDB_STUB_MAX_LINE 1200 #define GDB_STUB_INTERVAL 32

@@ -46,5 +48,7 @@ void GDBStubHangup(struct GDBStub*);

void GDBStubShutdown(struct GDBStub*); void GDBStubUpdate(struct GDBStub*); + +CXX_GUARD_END #endif
M src/debugger/parser.csrc/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 <mgba/internal/debugger/parser.h> -#include "util/string.h" +#include <mgba-util/string.h> static struct LexVector* _lexOperator(struct LexVector* lv, char operator) { struct LexVector* lvNext = malloc(sizeof(struct LexVector));
M src/debugger/parser.hinclude/mgba/internal/debugger/parser.h

@@ -6,8 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef PARSER_H #define PARSER_H -#include "util/common.h" -#include "debugger.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/internal/debugger/debugger.h> enum LexState { LEX_ERROR = -1,

@@ -61,5 +64,7 @@ void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv);

void lexFree(struct LexVector* lv); void parseFree(struct ParseTree* tree); + +CXX_GUARD_END #endif
M src/ds/bios.csrc/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 <mgba/internal/ds/bios.h> -#include "arm/arm.h" +#include <mgba/internal/arm/arm.h> mLOG_DEFINE_CATEGORY(DS_BIOS, "DS BIOS");
M src/ds/bios.hinclude/mgba/internal/ds/bios.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DS_BIOS_H #define DS_BIOS_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" +CXX_GUARD_START + +#include <mgba/core/log.h> mLOG_DECLARE_CATEGORY(DS_BIOS);

@@ -20,5 +22,7 @@ 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
M src/ds/core.csrc/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 <mgba/ds/core.h> -#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 <mgba/core/cheats.h> +#include <mgba/core/core.h> +#include <mgba/core/log.h> +#include <mgba/internal/arm/debugger/debugger.h> +#include <mgba/internal/ds/ds.h> +#include <mgba/internal/ds/extra/cli.h> +#include <mgba-util/memory.h> +#include <mgba-util/patch.h> +#include <mgba-util/vfs.h> #define SLICE_CYCLES 2048
M src/ds/core.hinclude/mgba/ds/core.h

@@ -6,7 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DS_CORE_H #define DS_CORE_H +#include <mgba-util/common.h> + +CXX_GUARD_START + struct mCore; struct mCore* DSCoreCreate(void); + +CXX_GUARD_END #endif
M src/ds/ds.csrc/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 <mgba/internal/ds/ds.h> -#include "arm/decoder.h" -#include "arm/debugger/debugger.h" -#include "arm/isa-inlines.h" -#include "ds/bios.h" +#include <mgba/internal/arm/decoder.h> +#include <mgba/internal/arm/debugger/debugger.h> +#include <mgba/internal/arm/isa-inlines.h> +#include <mgba/internal/ds/bios.h> -#include "util/crc32.h" -#include "util/memory.h" -#include "util/math.h" -#include "util/vfs.h" +#include <mgba-util/crc32.h> +#include <mgba-util/memory.h> +#include <mgba-util/math.h> +#include <mgba-util/vfs.h> mLOG_DEFINE_CATEGORY(DS, "DS");
M src/ds/ds.hinclude/mgba/internal/ds/ds.h

@@ -6,14 +6,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DS_H #define DS_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "arm/arm.h" -#include "core/log.h" +CXX_GUARD_START -#include "ds/memory.h" -#include "ds/timer.h" -#include "ds/video.h" +#include <mgba/internal/arm/arm.h> +#include <mgba/core/log.h> + +#include <mgba/internal/ds/memory.h> +#include <mgba/internal/ds/timer.h> +#include <mgba/internal/ds/video.h> extern const uint32_t DS_ARM946ES_FREQUENCY; extern const uint32_t DS_ARM7TDMI_FREQUENCY;

@@ -139,5 +141,7 @@

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
M src/ds/extra/cli.csrc/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 <mgba/internal/ds/extra/cli.h> -#include "arm/debugger/cli-debugger.h" -#include "core/core.h" -#include "ds/core.h" -#include "ds/ds.h" +#include <mgba/internal/arm/debugger/cli-debugger.h> +#include <mgba/core/core.h> +#include <mgba/ds/core.h> +#include <mgba/internal/ds/ds.h> static void _DSCLIDebuggerInit(struct CLIDebuggerSystem*); static bool _DSCLIDebuggerCustom(struct CLIDebuggerSystem*);
M src/ds/extra/cli.hinclude/mgba/internal/ds/extra/cli.h

@@ -6,7 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DS_CLI_H #define DS_CLI_H -#include "debugger/cli-debugger.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/internal/debugger/cli-debugger.h> struct mCore;

@@ -20,5 +24,7 @@ bool inVblank;

}; struct DSCLIDebugger* DSCLIDebuggerCreate(struct mCore*); + +CXX_GUARD_END #endif
M src/ds/io.csrc/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 <mgba/internal/ds/io.h> -#include "ds/ds.h" +#include <mgba/internal/ds/ds.h> mLOG_DEFINE_CATEGORY(DS_IO, "DS I/O");
M src/ds/io.hinclude/mgba/internal/ds/io.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DS_IO_H #define DS_IO_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" +CXX_GUARD_START + +#include <mgba/core/log.h> 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
M src/ds/memory.csrc/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 <mgba/internal/ds/memory.h> -#include "arm/macros.h" +#include <mgba/internal/arm/macros.h> -#include "ds/ds.h" -#include "ds/io.h" -#include "util/math.h" -#include "util/memory.h" +#include <mgba/internal/ds/ds.h> +#include <mgba/internal/ds/io.h> +#include <mgba-util/math.h> +#include <mgba-util/memory.h> mLOG_DEFINE_CATEGORY(DS_MEM, "DS Memory");
M src/ds/memory.hinclude/mgba/internal/ds/memory.h

@@ -6,11 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DS_MEMORY_H #define DS_MEMORY_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "arm/arm.h" -#include "core/log.h" -#include "ds/io.h" +CXX_GUARD_START + +#include <mgba/internal/arm/arm.h> +#include <mgba/core/log.h> +#include <mgba/internal/ds/io.h> enum DSMemoryRegion { DS7_REGION_BIOS = 0x0,
M src/ds/timer.csrc/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 <mgba/internal/ds/timer.h> -#include "arm/arm.h" -#include "ds/ds.h" +#include <mgba/internal/arm/arm.h> +#include <mgba/internal/ds/ds.h> void DSTimerUpdateRegister(struct DSTimer* timer, struct ARMCore* cpu, uint16_t* io) { if (DSTimerFlagsIsEnable(timer->flags) && !DSTimerFlagsIsCountUp(timer->flags)) {
M src/ds/timer.hinclude/mgba/internal/ds/timer.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DS_TIMER_H #define DS_TIMER_H -#include "util/common.h" +#include <mgba-util/common.h> + +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* io, uint16_t control);

struct DS; int32_t DSTimersProcessEvents(struct DS* ds, int32_t cycles); + +CXX_GUARD_END + #endif
M src/ds/video.hinclude/mgba/internal/ds/video.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DS_VIDEO_H #define DS_VIDEO_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" +CXX_GUARD_START + +#include <mgba/core/log.h> mLOG_DECLARE_CATEGORY(DS_VIDEO);

@@ -47,5 +49,7 @@

void DSVideoInit(struct DSVideo* video); void DSVideoReset(struct DSVideo* video); void DSVideoDeinit(struct DSVideo* video); + +CXX_GUARD_START #endif
M src/feature/commandline.csrc/feature/commandline.c

@@ -5,13 +5,13 @@ * 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 "commandline.h" -#include "core/config.h" -#include "core/version.h" -#include "util/string.h" +#include <mgba/core/config.h> +#include <mgba/core/version.h> +#include <mgba-util/string.h> #include <fcntl.h> #ifdef _MSC_VER -#include "platform/windows/getopt.h" +#include <mgba-util/platform/windows/getopt.h> #else #include <getopt.h> #endif
M src/feature/commandline.hsrc/feature/commandline.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef COMMAND_LINE_H #define COMMAND_LINE_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "debugger/debugger.h" +CXX_GUARD_START + +#include <mgba/internal/debugger/debugger.h> struct mArguments { char* fname;

@@ -48,5 +50,7 @@ void usage(const char* arg0, const char* extraOptions);

void version(const char* arg0); void initParserForGraphics(struct mSubParser* parser, struct mGraphicsOpts* opts); + +CXX_GUARD_END #endif
M src/feature/editline/cli-el-backend.csrc/feature/editline/cli-el-backend.c

@@ -5,7 +5,7 @@ * 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-el-backend.h" -#include "core/version.h" +#include <mgba/core/version.h> #include <signal.h>
M src/feature/editline/cli-el-backend.hsrc/feature/editline/cli-el-backend.h

@@ -6,8 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef CLI_EL_BACKEND_H #define CLI_EL_BACKEND_H -#include "debugger/cli-debugger.h" -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/internal/debugger/cli-debugger.h> #include <histedit.h>

@@ -19,5 +22,7 @@ History* histate;

}; struct CLIDebuggerBackend* CLIDebuggerEditLineBackendCreate(void); + +CXX_GUARD_END #endif
M src/feature/ffmpeg/ffmpeg-encoder.csrc/feature/ffmpeg/ffmpeg-encoder.c

@@ -5,8 +5,8 @@ * 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 "ffmpeg-encoder.h" -#include "core/core.h" -#include "gba/video.h" +#include <mgba/core/core.h> +#include <mgba/internal/gba/video.h> #include <libavcodec/version.h> #include <libavcodec/avcodec.h>
M src/feature/ffmpeg/ffmpeg-encoder.hsrc/feature/ffmpeg/ffmpeg-encoder.h

@@ -6,7 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef FFMPEG_ENCODER #define FFMPEG_ENCODER -#include "gba/gba.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/internal/gba/gba.h> #include <libavformat/avformat.h> #include <libavcodec/version.h>

@@ -82,5 +86,7 @@ bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder*);

bool FFmpegEncoderOpen(struct FFmpegEncoder*, const char* outfile); void FFmpegEncoderClose(struct FFmpegEncoder*); bool FFmpegEncoderIsOpen(struct FFmpegEncoder*); + +CXX_GUARD_END #endif
M src/feature/gui/gui-config.csrc/feature/gui/gui-config.c

@@ -5,12 +5,13 @@ * 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-config.h" -#include "core/config.h" +#include <mgba/core/config.h> +#include <mgba/core/core.h> #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 <mgba/internal/gba/gba.h> +#include <mgba-util/gui/file-select.h> +#include <mgba-util/gui/menu.h> #ifndef GUI_MAX_INPUTS #define GUI_MAX_INPUTS 7
M src/feature/gui/gui-config.hsrc/feature/gui/gui-config.h

@@ -6,10 +6,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GUI_CONFIG_H #define GUI_CONFIG_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct mGUIRunner; struct GUIMenuItem; void mGUIShowConfig(struct mGUIRunner* runner, struct GUIMenuItem* extra, size_t nExtra); + +CXX_GUARD_END #endif
M src/feature/gui/gui-runner.csrc/feature/gui/gui-runner.c

@@ -5,18 +5,18 @@ * 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-runner.h" -#include "core/core.h" -#include "core/serialize.h" +#include <mgba/core/core.h> +#include <mgba/core/serialize.h> #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 <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/input.h> +#include <mgba/gba/interface.h> +#include <mgba-util/gui/file-select.h> +#include <mgba-util/gui/font.h> +#include <mgba-util/gui/menu.h> +#include <mgba-util/memory.h> +#include <mgba-util/png-io.h> +#include <mgba-util/vfs.h> #ifdef _3DS #include <3ds.h>
M src/feature/gui/gui-runner.hsrc/feature/gui/gui-runner.h

@@ -6,13 +6,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GUI_RUNNER_H #define GUI_RUNNER_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/config.h" +CXX_GUARD_START + +#include <mgba/core/config.h> #include "feature/gui/remap.h" -#include "gba/hardware.h" -#include "util/circle-buffer.h" -#include "util/gui.h" +#include <mgba/internal/gba/hardware.h> +#include <mgba-util/circle-buffer.h> +#include <mgba-util/gui.h> enum mGUIInput { mGUI_INPUT_INCREASE_BRIGHTNESS = GUI_INPUT_USER_START,

@@ -74,5 +76,7 @@ void mGUIInit(struct mGUIRunner*, const char* port);

void mGUIDeinit(struct mGUIRunner*); void mGUIRun(struct mGUIRunner*, const char* path); void mGUIRunloop(struct mGUIRunner*); + +CXX_GUARD_END #endif
M src/feature/gui/remap.csrc/feature/gui/remap.c

@@ -5,8 +5,8 @@ * 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 "remap.h" -#include "util/gui.h" -#include "util/gui/menu.h" +#include <mgba-util/gui.h> +#include <mgba-util/gui/menu.h> void mGUIRemapKeys(struct GUIParams* params, struct mInputMap* map, const struct GUIInputKeys* keys) { struct GUIMenu menu = {
M src/feature/gui/remap.hsrc/feature/gui/remap.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GUI_REMAP_H #define GUI_REMAP_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct GUIInputKeys { const char* name;

@@ -19,5 +21,7 @@ struct GUIParams;

struct mInputMap; void mGUIRemapKeys(struct GUIParams*, struct mInputMap*, const struct GUIInputKeys*); + +CXX_GUARD_END #endif
M src/feature/imagemagick/imagemagick-gif-encoder.csrc/feature/imagemagick/imagemagick-gif-encoder.c

@@ -5,8 +5,9 @@ * 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 "imagemagick-gif-encoder.h" -#include "gba/video.h" -#include "util/string.h" +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/video.h> +#include <mgba-util/string.h> static void _magickPostVideoFrame(struct mAVStream*, const color_t* pixels, size_t stride); static void _magickVideoDimensionsChanged(struct mAVStream*, unsigned width, unsigned height);
M src/feature/imagemagick/imagemagick-gif-encoder.hsrc/feature/imagemagick/imagemagick-gif-encoder.h

@@ -6,7 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef IMAGEMAGICK_GIF_ENCODER #define IMAGEMAGICK_GIF_ENCODER -#include "gba/gba.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/core/interface.h> #define MAGICKCORE_HDRI_ENABLE 0 #define MAGICKCORE_QUANTUM_DEPTH 8

@@ -32,5 +36,7 @@ void ImageMagickGIFEncoderSetParams(struct ImageMagickGIFEncoder* encoder, int frameskip, int delayMs);

bool ImageMagickGIFEncoderOpen(struct ImageMagickGIFEncoder*, const char* outfile); bool ImageMagickGIFEncoderClose(struct ImageMagickGIFEncoder*); bool ImageMagickGIFEncoderIsOpen(struct ImageMagickGIFEncoder*); + +CXX_GUARD_END #endif
M src/gb/audio.csrc/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 <mgba/internal/gb/audio.h> -#include "core/interface.h" -#include "core/sync.h" -#include "gb/gb.h" -#include "gb/serialize.h" -#include "gb/io.h" +#include <mgba/core/blip_buf.h> +#include <mgba/core/interface.h> +#include <mgba/core/sync.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/serialize.h> +#include <mgba/internal/gb/io.h> #ifdef _3DS #define blip_add_delta blip_add_delta_fast
M src/gb/audio.hinclude/mgba/internal/gb/audio.h

@@ -6,10 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_AUDIO_H #define GB_AUDIO_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START -#include "core/timing.h" -#include "third-party/blip_buf/blip_buf.h" +#include <mgba/core/timing.h> DECL_BITFIELD(GBAudioRegisterDuty, uint8_t); DECL_BITS(GBAudioRegisterDuty, Length, 0, 6);

@@ -155,8 +156,8 @@ struct GBAudioSquareChannel ch2;

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;

@@ -239,5 +240,7 @@

struct GBSerializedState; void GBAudioSerialize(const struct GBAudio* audio, struct GBSerializedState* state); void GBAudioDeserialize(struct GBAudio* audio, const struct GBSerializedState* state); + +CXX_GUARD_END #endif
M src/gb/cheats.csrc/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 <mgba/internal/gb/cheats.h> -#include "core/core.h" -#include "gb/gb.h" -#include "gb/memory.h" -#include "util/string.h" +#include <mgba/core/core.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/memory.h> +#include <mgba-util/string.h> DEFINE_VECTOR(GBCheatPatchList, struct GBCheatPatch);
M src/gb/cheats.hinclude/mgba/internal/gb/cheats.h

@@ -6,10 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_CHEATS_H #define GB_CHEATS_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/cheats.h" -#include "util/vector.h" +CXX_GUARD_START + +#include <mgba/core/cheats.h> +#include <mgba-util/vector.h> enum GBCheatType { GB_CHEAT_AUTODETECT,

@@ -35,5 +37,7 @@ struct GBCheatPatchList romPatches;

}; struct mCheatDevice* GBCheatDeviceCreate(void); + +CXX_GUARD_END #endif
M src/gb/core.csrc/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 <mgba/gb/core.h> -#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 <mgba/core/core.h> +#include <mgba/internal/gb/cheats.h> +#include <mgba/internal/gb/extra/cli.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/mbc.h> +#include <mgba/internal/gb/overrides.h> +#include <mgba/internal/gb/renderers/software.h> +#include <mgba/internal/gb/serialize.h> +#include <mgba/internal/lr35902/lr35902.h> +#include <mgba/internal/lr35902/debugger/debugger.h> +#include <mgba-util/crc32.h> +#include <mgba-util/memory.h> +#include <mgba-util/patch.h> +#include <mgba-util/vfs.h> struct GBCore { struct mCore d;
M src/gb/core.hinclude/mgba/gb/core.h

@@ -6,7 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_CORE_H #define GB_CORE_H +#include <mgba-util/common.h> + +CXX_GUARD_START + struct mCore; struct mCore* GBCoreCreate(void); + +CXX_GUARD_END #endif
M src/gb/extra/cli.csrc/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 <mgba/internal/gb/extra/cli.h> -#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 <mgba/core/core.h> +#include <mgba/core/serialize.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/io.h> +#include <mgba/internal/gb/video.h> +#include <mgba/internal/lr35902/debugger/cli-debugger.h> static void _GBCLIDebuggerInit(struct CLIDebuggerSystem*); static bool _GBCLIDebuggerCustom(struct CLIDebuggerSystem*);
M src/gb/extra/cli.hinclude/mgba/internal/gb/extra/cli.h

@@ -6,7 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_CLI_H #define GB_CLI_H -#include "debugger/cli-debugger.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/internal/debugger/cli-debugger.h> struct GBCLIDebugger { struct CLIDebuggerSystem d;

@@ -18,5 +22,7 @@ bool inVblank;

}; struct CLIDebuggerSystem* GBCLIDebuggerCreate(struct mCore*); + +CXX_GUARD_END #endif
M src/gb/gb.csrc/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 <mgba/internal/gb/gb.h> -#include "gb/io.h" -#include "gb/mbc.h" +#include <mgba/internal/gb/io.h> +#include <mgba/internal/gb/mbc.h> +#include <mgba/internal/lr35902/lr35902.h> -#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 <mgba/core/core.h> +#include <mgba/core/cheats.h> +#include <mgba-util/crc32.h> +#include <mgba-util/memory.h> +#include <mgba-util/math.h> +#include <mgba-util/patch.h> +#include <mgba-util/vfs.h> #define CLEANUP_THRESHOLD 15

@@ -433,6 +434,7 @@ cpu->pc = 0x100;

} gb->cpuBlocked = false; + gb->earlyExit = false; gb->doubleSpeed = 0; cpu->memory.setActiveRegion(cpu, cpu->pc);

@@ -548,6 +550,10 @@ nextEvent = mTimingTick(&gb->timing, nextEvent);

} 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) {
M src/gb/gb.hinclude/mgba/internal/gb/gb.h

@@ -6,19 +6,19 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_H #define GB_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" -#include "core/timing.h" +CXX_GUARD_START -#include "lr35902/lr35902.h" +#include <mgba/core/cpu.h> +#include <mgba/core/log.h> +#include <mgba/core/timing.h> -#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 <mgba/internal/gb/audio.h> +#include <mgba/internal/gb/memory.h> +#include <mgba/internal/gb/sio.h> +#include <mgba/internal/gb/timer.h> +#include <mgba/internal/gb/video.h> extern const uint32_t DMG_LR35902_FREQUENCY; extern const uint32_t CGB_LR35902_FREQUENCY;

@@ -43,6 +43,7 @@ GB_VECTOR_SIO = 0x58,

GB_VECTOR_KEYPAD = 0x60, }; +struct LR35902Core; struct mCoreSync; struct mAVStream; struct mCoreCallbacks;

@@ -79,6 +80,7 @@ struct mCoreCallbacks* coreCallbacks;

struct mAVStream* stream; bool cpuBlocked; + bool earlyExit; struct mTimingEvent eiPending; unsigned doubleSpeed; };

@@ -119,7 +121,6 @@

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);

@@ -139,5 +140,7 @@ void GBGetGameTitle(const struct GB* gba, char* out);

void GBGetGameCode(const struct GB* gba, char* out); void GBFrameEnded(struct GB* gb); + +CXX_GUARD_END #endif
M src/gb/interface.hinclude/mgba/gb/interface.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_INTERFACE_H #define GB_INTERFACE_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START enum GBModel { GB_MODEL_AUTODETECT = 0xFF,

@@ -31,5 +33,7 @@ GB_HuC3 = 0x12,

GB_MBC3_RTC = 0x103, GB_MBC5_RUMBLE = 0x105 }; + +CXX_GUARD_END #endif
M src/gb/io.csrc/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 <mgba/internal/gb/io.h> -#include "gb/gb.h" -#include "gb/sio.h" -#include "gb/serialize.h" +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/sio.h> +#include <mgba/internal/gb/serialize.h> mLOG_DEFINE_CATEGORY(GB_IO, "GB I/O");

@@ -158,6 +158,9 @@ }

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 @@ gb->audio.ch3.wavedata8[gb->audio.ch3.window >> 1] = value;

} break; case REG_JOYP: - case REG_SB: case REG_TIMA: case REG_TMA: // Handled transparently by the registers
M src/gb/io.hinclude/mgba/internal/gb/io.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_IO_H #define GB_IO_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" +CXX_GUARD_START + +#include <mgba/core/log.h> mLOG_DECLARE_CATEGORY(GB_IO);

@@ -117,5 +119,7 @@

struct GBSerializedState; void GBIOSerialize(const struct GB* gb, struct GBSerializedState* state); void GBIODeserialize(struct GB* gb, const struct GBSerializedState* state); + +CXX_GUARD_END #endif
M src/gb/mbc.csrc/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 <mgba/internal/gb/mbc.h> -#include "gb/gb.h" -#include "gb/memory.h" -#include "util/vfs.h" +#include <mgba/core/interface.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/memory.h> +#include <mgba-util/vfs.h> mLOG_DEFINE_CATEGORY(GB_MBC, "GB MBC");
M src/gb/mbc.hinclude/mgba/internal/gb/mbc.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_MBC_H #define GB_MBC_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" +CXX_GUARD_START + +#include <mgba/core/log.h> mLOG_DECLARE_CATEGORY(GB_MBC);

@@ -36,5 +38,7 @@ 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
M src/gb/memory.csrc/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 <mgba/internal/gb/memory.h> -#include "core/interface.h" -#include "gb/gb.h" -#include "gb/io.h" -#include "gb/mbc.h" -#include "gb/serialize.h" +#include <mgba/core/interface.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/io.h> +#include <mgba/internal/gb/mbc.h> +#include <mgba/internal/gb/serialize.h> +#include <mgba/internal/lr35902/lr35902.h> -#include "util/memory.h" +#include <mgba-util/memory.h> mLOG_DEFINE_CATEGORY(GB_MEM, "GB Memory");
M src/gb/memory.hinclude/mgba/internal/gb/memory.h

@@ -6,12 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_MEMORY_H #define GB_MEMORY_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" -#include "core/timing.h" -#include "gb/interface.h" -#include "lr35902/lr35902.h" +CXX_GUARD_START + +#include <mgba/core/log.h> +#include <mgba/core/timing.h> +#include <mgba/gb/interface.h> #include <time.h>

@@ -152,6 +153,7 @@ struct mRotationSource* rotation;

struct mRumble* rumble; }; +struct LR35902Core; void GBMemoryInit(struct GB* gb); void GBMemoryDeinit(struct GB* gb);

@@ -174,5 +176,7 @@

struct GBSerializedState; void GBMemorySerialize(const struct GB* gb, struct GBSerializedState* state); void GBMemoryDeserialize(struct GB* gb, const struct GBSerializedState* state); + +CXX_GUARD_END #endif
M src/gb/overrides.csrc/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 <mgba/internal/gb/overrides.h> -#include "gb/gb.h" +#include <mgba/internal/gb/gb.h> -#include "util/configuration.h" -#include "util/crc32.h" +#include <mgba-util/configuration.h> +#include <mgba-util/crc32.h> static const struct GBCartridgeOverride _overrides[] = { // None yet
M src/gb/overrides.hinclude/mgba/internal/gb/overrides.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_OVERRIDES_H #define GB_OVERRIDES_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "gb/interface.h" +CXX_GUARD_START + +#include <mgba/gb/interface.h> struct GBCartridgeOverride { int headerCrc32;

@@ -23,5 +25,7 @@

struct GB; void GBOverrideApply(struct GB*, const struct GBCartridgeOverride*); void GBOverrideApplyDefaults(struct GB*); + +CXX_GUARD_END #endif
M src/gb/renderers/software.csrc/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 <mgba/internal/gb/renderers/software.h> -#include "core/tile-cache.h" -#include "gb/io.h" -#include "util/memory.h" +#include <mgba/core/tile-cache.h> +#include <mgba/internal/gb/io.h> +#include <mgba-util/memory.h> static void GBVideoSoftwareRendererInit(struct GBVideoRenderer* renderer, enum GBModel model); static void GBVideoSoftwareRendererDeinit(struct GBVideoRenderer* renderer);
M src/gb/renderers/software.hinclude/mgba/internal/gb/renderers/software.h

@@ -6,11 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_RENDERER_SOFTWARE_H #define GB_RENDERER_SOFTWARE_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/core.h" -#include "gb/gb.h" -#include "gb/video.h" +CXX_GUARD_START + +#include <mgba/core/core.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/video.h> struct GBVideoSoftwareRenderer { struct GBVideoRenderer d;

@@ -35,5 +37,7 @@ enum GBModel model;

}; void GBVideoSoftwareRendererCreate(struct GBVideoSoftwareRenderer*); + +CXX_GUARD_END #endif
M src/gb/renderers/tile-cache.csrc/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 <mgba/internal/gb/renderers/tile-cache.h> -#include "core/tile-cache.h" -#include "gb/video.h" -#include "gb/renderers/tile-cache.h" +#include <mgba/core/tile-cache.h> +#include <mgba/internal/gb/video.h> +#include <mgba/internal/gb/renderers/tile-cache.h> void GBVideoTileCacheInit(struct mTileCache* cache) { mTileCacheInit(cache);
M src/gb/renderers/tile-cache.hinclude/mgba/internal/gb/renderers/tile-cache.h

@@ -6,12 +6,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_TILE_CACHE_H #define GB_TILE_CACHE_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct GBVideo; struct mTileCache; void GBVideoTileCacheInit(struct mTileCache* cache); void GBVideoTileCacheAssociate(struct mTileCache* cache, struct GBVideo* video); + +CXX_GUARD_END #endif
M src/gb/serialize.csrc/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 <mgba/internal/gb/serialize.h> -#include "gb/io.h" -#include "gb/timer.h" +#include <mgba/internal/gb/io.h> +#include <mgba/internal/gb/timer.h> +#include <mgba/internal/lr35902/lr35902.h> mLOG_DEFINE_CATEGORY(GB_STATE, "GB Savestate");
M src/gb/serialize.hinclude/mgba/internal/gb/serialize.h

@@ -6,10 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_SERIALIZE_H #define GB_SERIALIZE_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/core.h" -#include "gb/gb.h" +CXX_GUARD_START + +#include <mgba/core/core.h> +#include <mgba/internal/gb/gb.h> extern const uint32_t GB_SAVESTATE_MAGIC; extern const uint32_t GB_SAVESTATE_VERSION;

@@ -369,5 +371,7 @@ #pragma pack(pop)

bool GBDeserialize(struct GB* gb, const struct GBSerializedState* state); void GBSerialize(struct GB* gb, struct GBSerializedState* state); + +CXX_GUARD_END #endif
M src/gb/sio.csrc/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 <mgba/internal/gb/sio.h> -#include "gb/gb.h" -#include "gb/io.h" -#include "gb/serialize.h" +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/io.h> +#include <mgba/internal/gb/serialize.h> + +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 @@ sio->event.context = 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 @@ UNUSED(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); } }
D src/gb/sio.h

@@ -1,36 +0,0 @@

-/* 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_H -#define GB_SIO_H - -#include "util/common.h" - -#include "core/timing.h" - -struct GB; -struct GBSIO { - struct GB* p; - - struct mTimingEvent event; - - int32_t nextEvent; - int32_t period; - int remainingBits; - - uint8_t pendingSB; -}; - -DECL_BITFIELD(GBRegisterSC, uint8_t); -DECL_BIT(GBRegisterSC, ShiftClock, 0); -DECL_BIT(GBRegisterSC, ClockSpeed, 1); -DECL_BIT(GBRegisterSC, Enable, 7); - -void GBSIOInit(struct GBSIO* sio); -void GBSIOReset(struct GBSIO* sio); -void GBSIODeinit(struct GBSIO* sio); -void GBSIOWriteSC(struct GBSIO* sio, uint8_t sc); - -#endif
A 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 <mgba/internal/gb/sio/lockstep.h> + +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/io.h> + +#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; +}
M src/gb/test/core.csrc/gb/test/core.c

@@ -5,10 +5,10 @@ * 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/test/suite.h" -#include "core/core.h" -#include "gb/core.h" -#include "gb/gb.h" -#include "util/vfs.h" +#include <mgba/core/core.h> +#include <mgba/gb/core.h> +#include <mgba/internal/gb/gb.h> +#include <mgba-util/vfs.h> M_TEST_DEFINE(create) { struct mCore* core = GBCoreCreate();
M src/gb/test/gb.hsrc/gb/test/gb.h

@@ -5,7 +5,7 @@ * 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 TEST_GB_H #define TEST_GB_H -#include "util/common.h" +#include <mgba-util/common.h> int TestRunGB(void);
M src/gb/test/mbc.csrc/gb/test/mbc.c

@@ -5,11 +5,11 @@ * 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/test/suite.h" -#include "core/core.h" -#include "gb/core.h" -#include "gb/gb.h" -#include "gb/mbc.h" -#include "util/vfs.h" +#include <mgba/core/core.h> +#include <mgba/gb/core.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/mbc.h> +#include <mgba-util/vfs.h> M_TEST_SUITE_SETUP(GBMBC) { struct VFile* vf = VFileMemChunk(NULL, 2048);
M src/gb/test/memory.csrc/gb/test/memory.c

@@ -5,11 +5,11 @@ * 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/test/suite.h" -#include "core/core.h" -#include "gb/core.h" -#include "gb/gb.h" -#include "gb/mbc.h" -#include "util/vfs.h" +#include <mgba/core/core.h> +#include <mgba/gb/core.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/mbc.h> +#include <mgba-util/vfs.h> M_TEST_SUITE_SETUP(GBMemory) { struct VFile* vf = VFileMemChunk(NULL, GB_SIZE_CART_BANK0 * 4);
M src/gb/test/rtc.csrc/gb/test/rtc.c

@@ -5,11 +5,11 @@ * 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/test/suite.h" -#include "core/core.h" -#include "gb/core.h" -#include "gb/gb.h" -#include "gb/mbc.h" -#include "util/vfs.h" +#include <mgba/core/core.h> +#include <mgba/gb/core.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/mbc.h> +#include <mgba-util/vfs.h> struct GBRTCTest { struct mRTCSource d;
M src/gb/timer.csrc/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 <mgba/internal/gb/timer.h> -#include "gb/gb.h" -#include "gb/io.h" -#include "gb/serialize.h" +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/io.h> +#include <mgba/internal/gb/serialize.h> void _GBTimerIRQ(struct mTiming* timing, void* context, uint32_t cyclesLate) { UNUSED(timing);
M src/gb/timer.hinclude/mgba/internal/gb/timer.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_TIMER_H #define GB_TIMER_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/timing.h" +CXX_GUARD_START + +#include <mgba/core/timing.h> DECL_BITFIELD(GBRegisterTAC, uint8_t); DECL_BITS(GBRegisterTAC, Clock, 0, 2);

@@ -37,5 +39,7 @@

struct GBSerializedState; void GBTimerSerialize(const struct GBTimer* timer, struct GBSerializedState* state); void GBTimerDeserialize(struct GBTimer* timer, const struct GBSerializedState* state); + +CXX_GUARD_END #endif
M src/gb/video.csrc/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 <mgba/internal/gb/video.h> -#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 <mgba/core/sync.h> +#include <mgba/core/thread.h> +#include <mgba/core/tile-cache.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/io.h> +#include <mgba/internal/gb/serialize.h> +#include <mgba/internal/lr35902/lr35902.h> -#include "util/memory.h" +#include <mgba-util/memory.h> static void GBVideoDummyRendererInit(struct GBVideoRenderer* renderer, enum GBModel model); static void GBVideoDummyRendererDeinit(struct GBVideoRenderer* renderer);
M src/gb/video.hinclude/mgba/internal/gb/video.h

@@ -6,28 +6,28 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GB_VIDEO_H #define GB_VIDEO_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/interface.h" -#include "core/timing.h" -#include "gb/interface.h" -#include "gb/memory.h" +CXX_GUARD_START + +#include <mgba/core/timing.h> +#include <mgba/gb/interface.h> 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 @@ struct GBObj obj[40];

uint8_t raw[160]; }; -enum GBModel; struct mTileCache; struct GBVideoRenderer { void (*init)(struct GBVideoRenderer* renderer, enum GBModel model);

@@ -142,5 +141,7 @@

struct GBSerializedState; void GBVideoSerialize(const struct GBVideo* video, struct GBSerializedState* state); void GBVideoDeserialize(struct GBVideo* video, const struct GBSerializedState* state); + +CXX_GUARD_END #endif
M src/gba/audio.csrc/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 <mgba/internal/gba/audio.h> -#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 <mgba/internal/arm/macros.h> +#include <mgba/core/blip_buf.h> +#include <mgba/core/sync.h> +#include <mgba/internal/gba/dma.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/io.h> +#include <mgba/internal/gba/serialize.h> +#include <mgba/internal/gba/video.h> #ifdef _3DS #define blip_add_delta blip_add_delta_fast
M src/gba/audio.hinclude/mgba/internal/gba/audio.h

@@ -6,11 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_AUDIO_H #define GBA_AUDIO_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" -#include "gb/audio.h" -#include "util/circle-buffer.h" +CXX_GUARD_START + +#include <mgba/core/log.h> +#include <mgba/internal/gb/audio.h> +#include <mgba-util/circle-buffer.h> mLOG_DECLARE_CATEGORY(GBA_AUDIO);

@@ -115,5 +117,7 @@ void GBAAudioSerialize(const struct GBAAudio* audio, struct GBASerializedState* state);

void GBAAudioDeserialize(struct GBAAudio* audio, const struct GBASerializedState* state); float GBAAudioCalculateRatio(float inputSampleRate, float desiredFPS, float desiredSampleRatio); + +CXX_GUARD_END #endif
M src/gba/bios.csrc/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 <mgba/internal/gba/bios.h> -#include "arm/isa-inlines.h" -#include "arm/macros.h" -#include "gba/gba.h" -#include "gba/io.h" -#include "gba/memory.h" +#include <mgba/internal/arm/isa-inlines.h> +#include <mgba/internal/arm/macros.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/io.h> +#include <mgba/internal/gba/memory.h> const uint32_t GBA_BIOS_CHECKSUM = 0xBAAE187F; const uint32_t GBA_DS_BIOS_CHECKSUM = 0xBAAE1880;
M src/gba/bios.hinclude/mgba/internal/gba/bios.h

@@ -6,18 +6,22 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_BIOS_H #define GBA_BIOS_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "arm/arm.h" -#include "core/log.h" +CXX_GUARD_START + +#include <mgba/core/log.h> mLOG_DECLARE_CATEGORY(GBA_BIOS); +struct ARMCore; void GBASwi16(struct ARMCore* cpu, int immediate); void GBASwi32(struct ARMCore* cpu, int immediate); 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
M src/gba/cheats.csrc/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 <mgba/internal/gba/cheats.h> +#include <mgba/core/core.h> +#include <mgba/internal/gba/gba.h> +#include <mgba-util/string.h> #include "gba/cheats/gameshark.h" #include "gba/cheats/parv3.h" -#include "gba/gba.h" -#include "util/string.h" #define MAX_LINE_LENGTH 128
M src/gba/cheats.hinclude/mgba/internal/gba/cheats.h

@@ -6,10 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_CHEATS_H #define GBA_CHEATS_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "arm/arm.h" -#include "core/cheats.h" +CXX_GUARD_START + +#include <mgba/internal/arm/arm.h> +#include <mgba/core/cheats.h> #define MAX_ROM_PATCHES 4 #define COMPLETE ((size_t) -1)

@@ -173,5 +175,7 @@

bool GBACheatAddVBALine(struct GBACheatSet*, const char* line); int GBACheatAddressIsReal(uint32_t address); + +CXX_GUARD_END #endif
M src/gba/cheats/codebreaker.csrc/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 <mgba/internal/gba/cheats.h> -#include "gba/gba.h" -#include "gba/io.h" -#include "util/string.h" +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/io.h> +#include <mgba-util/string.h> static void _cbLoadByteswap(uint8_t* buffer, uint32_t op1, uint16_t op2) { buffer[0] = op1 >> 24;
M src/gba/cheats/gameshark.csrc/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 <mgba/internal/gba/cheats.h> #include "gba/cheats/parv3.h" -#include "gba/gba.h" -#include "util/string.h" +#include <mgba/internal/gba/gba.h> +#include <mgba-util/string.h> const uint32_t GBACheatGameSharkSeeds[4] = { 0x09F4FBBD, 0x9681884A, 0x352027E9, 0xF3DEE5A7 };
M src/gba/cheats/gameshark.hsrc/gba/cheats/gameshark.h

@@ -6,14 +6,19 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_CHEATS_GAMESHARK_H #define GBA_CHEATS_GAMESHARK_H -#include "gba/cheats.h" +#include <mgba-util/common.h> + +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
M src/gba/cheats/parv3.csrc/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 <mgba/internal/gba/cheats.h> #include "gba/cheats/gameshark.h" -#include "gba/gba.h" -#include "util/string.h" +#include <mgba/internal/gba/gba.h> +#include <mgba-util/string.h> const uint32_t GBACheatProActionReplaySeeds[4] = { 0x7AA9648F, 0x7FAE6994, 0xC0EFAAD5, 0x42712C57 };
M src/gba/cheats/parv3.hsrc/gba/cheats/parv3.h

@@ -6,11 +6,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_CHEATS_PARV3_H #define GBA_CHEATS_PARV3_H -#include "gba/cheats.h" +#include <mgba-util/common.h> + +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
M src/gba/core.csrc/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 <mgba/gba/core.h> -#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 <mgba/core/core.h> +#include <mgba/core/log.h> +#include <mgba/internal/arm/debugger/debugger.h> +#include <mgba/internal/gba/cheats.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/extra/cli.h> +#include <mgba/internal/gba/overrides.h> #ifndef DISABLE_THREADING -#include "gba/renderers/thread-proxy.h" +#include <mgba/internal/gba/renderers/thread-proxy.h> #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 <mgba/internal/gba/renderers/video-software.h> +#include <mgba/internal/gba/savedata.h> +#include <mgba/internal/gba/serialize.h> +#include <mgba-util/memory.h> +#include <mgba-util/patch.h> +#include <mgba-util/vfs.h> struct GBACore { struct mCore d;

@@ -198,6 +198,9 @@ }

} static bool _GBACoreLoadROM(struct mCore* core, struct VFile* vf) { + if (GBAIsMB(vf)) { + return GBALoadMB(core->board, vf); + } return GBALoadROM(core->board, vf); }
M src/gba/core.hinclude/mgba/gba/core.h

@@ -6,7 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_CORE_H #define GBA_CORE_H +#include <mgba-util/common.h> + +CXX_GUARD_START + struct mCore; struct mCore* GBACoreCreate(void); + +CXX_GUARD_END #endif
M src/gba/dma.csrc/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 <mgba/internal/gba/dma.h> -#include "gba/gba.h" -#include "gba/io.h" +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/io.h> static void _dmaEvent(struct mTiming* timing, void* context, uint32_t cyclesLate);
M src/gba/dma.hinclude/mgba/internal/gba/dma.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_DMA_H #define GBA_DMA_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct GBA; void GBADMAInit(struct GBA* gba);

@@ -22,5 +24,7 @@ void GBADMASchedule(struct GBA* gba, int number, struct GBADMA* info);

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
M src/gba/extra/cli.csrc/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 <mgba/internal/gba/extra/cli.h> -#include "arm/debugger/cli-debugger.h" -#include "core/serialize.h" -#include "gba/io.h" -#include "gba/serialize.h" +#include <mgba/core/core.h> +#include <mgba/core/serialize.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/io.h> +#include <mgba/internal/gba/video.h> +#include <mgba/internal/arm/debugger/cli-debugger.h> static void _GBACLIDebuggerInit(struct CLIDebuggerSystem*); static bool _GBACLIDebuggerCustom(struct CLIDebuggerSystem*);
M src/gba/extra/cli.hinclude/mgba/internal/gba/extra/cli.h

@@ -6,7 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_CLI_H #define GBA_CLI_H -#include "debugger/cli-debugger.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/internal/debugger/cli-debugger.h> struct mCore;

@@ -20,5 +24,7 @@ bool inVblank;

}; struct GBACLIDebugger* GBACLIDebuggerCreate(struct mCore*); + +CXX_GUARD_END #endif
M src/gba/gba.csrc/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 <mgba/internal/gba/gba.h> -#include "core/thread.h" +#include <mgba/internal/arm/isa-inlines.h> +#include <mgba/internal/arm/debugger/debugger.h> +#include <mgba/internal/arm/decoder.h> -#include "arm/decoder.h" -#include "arm/debugger/debugger.h" -#include "arm/isa-inlines.h" - -#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 <mgba/internal/gba/bios.h> +#include <mgba/internal/gba/cheats.h> +#include <mgba/internal/gba/io.h> +#include <mgba/internal/gba/overrides.h> +#include <mgba/internal/gba/rr/rr.h> -#include "util/crc32.h" -#include "util/memory.h" -#include "util/math.h" -#include "util/patch.h" -#include "util/vfs.h" +#include <mgba-util/patch.h> +#include <mgba-util/crc32.h> +#include <mgba-util/math.h> +#include <mgba-util/memory.h> +#include <mgba-util/vfs.h> mLOG_DEFINE_CATEGORY(GBA, "GBA"); mLOG_DEFINE_CATEGORY(GBA_DEBUG, "GBA Debug");
M src/gba/gba.hinclude/mgba/internal/gba/gba.h

@@ -6,18 +6,18 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_H #define GBA_H -#include "util/common.h" +#include <mgba-util/common.h> -#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 <mgba/core/log.h> +#include <mgba/core/timing.h> + +#include <mgba/internal/gba/memory.h> +#include <mgba/internal/gba/video.h> +#include <mgba/internal/gba/audio.h> +#include <mgba/internal/gba/sio.h> +#include <mgba/internal/gba/timer.h> #define GBA_ARM7TDMI_FREQUENCY 0x1000000U

@@ -50,6 +50,7 @@ SP_BASE_IRQ = 0x03007FA0,

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);

@@ -174,5 +178,7 @@ void GBAGetGameTitle(const struct GBA* gba, char* out);

void GBAFrameStarted(struct GBA* gba); void GBAFrameEnded(struct GBA* gba); + +CXX_GUARD_END #endif
M src/gba/hardware.csrc/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 <mgba/internal/gba/hardware.h> -#include "gba/io.h" -#include "gba/serialize.h" -#include "util/formatting.h" -#include "util/hash.h" +#include <mgba/internal/arm/macros.h> +#include <mgba/internal/gba/io.h> +#include <mgba/internal/gba/serialize.h> +#include <mgba-util/formatting.h> +#include <mgba-util/hash.h> mLOG_DEFINE_CATEGORY(GBA_HW, "GBA Pak Hardware");
M src/gba/hardware.hinclude/mgba/internal/gba/hardware.h

@@ -6,12 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_HARDWARE_H #define GBA_HARDWARE_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "arm/macros.h" -#include "core/log.h" -#include "core/timing.h" -#include "gba/interface.h" +CXX_GUARD_START + +#include <mgba/core/log.h> +#include <mgba/core/timing.h> +#include <mgba/gba/interface.h> #include <time.h>

@@ -143,5 +144,7 @@

struct GBASerializedState; void GBAHardwareSerialize(const struct GBACartridgeHardware* gpio, struct GBASerializedState* state); void GBAHardwareDeserialize(struct GBACartridgeHardware* gpio, const struct GBASerializedState* state); + +CXX_GUARD_END #endif
M src/gba/hle-bios.csrc/gba/hle-bios.c

@@ -1,6 +1,6 @@

#include "hle-bios.h" -#include "gba/memory.h" +#include <mgba/internal/gba/memory.h> const uint8_t hleBios[SIZE_BIOS] = { 0x06, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x0b, 0x00, 0x00, 0xea,
M src/gba/hle-bios.hsrc/gba/hle-bios.h

@@ -6,8 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef HLE_BIOS_H #define HLE_BIOS_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START extern const uint8_t hleBios[]; + +CXX_GUARD_END #endif
M src/gba/hle-bios.makesrc/gba/hle-bios.make

@@ -13,6 +13,6 @@

hle-bios.c: hle-bios.bin echo '#include "hle-bios.h"' > $@ echo >> $@ - echo '#include "gba/memory.h"' >> $@ + echo '#include <mgba/internal/gba/memory.h>' >> $@ echo >> $@ xxd -i $< | sed -e 's/unsigned char hle_bios_bin\[\]/const uint8_t hleBios[SIZE_BIOS]/' | grep -v hle_bios_bin_len >> $@
M src/gba/input.csrc/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 <mgba/internal/gba/input.h> -#include "gba/interface.h" +#include <mgba/gba/interface.h> const struct mInputPlatformInfo GBAInputInfo = { .platformName = "gba",
M src/gba/input.hinclude/mgba/internal/gba/input.h

@@ -6,7 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_INPUT_H #define GBA_INPUT_H -#include "core/input.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/core/input.h> extern const struct mInputPlatformInfo GBAInputInfo;

@@ -24,5 +28,7 @@ GBA_KEY_L = 9,

GBA_KEY_MAX, GBA_KEY_NONE = -1 }; + +CXX_GUARD_END #endif
M src/gba/interface.hinclude/mgba/gba/interface.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_INTERFACE_H #define GBA_INTERFACE_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/interface.h" +CXX_GUARD_START + +#include <mgba/core/interface.h> enum GBASIOMode { SIO_NORMAL_8 = 0,

@@ -41,5 +43,7 @@ bool (*load)(struct GBASIODriver* driver);

bool (*unload)(struct GBASIODriver* driver); uint16_t (*writeRegister)(struct GBASIODriver* driver, uint32_t address, uint16_t value); }; + +CXX_GUARD_END #endif
M src/gba/io.csrc/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 <mgba/internal/gba/io.h> -#include "gba/dma.h" -#include "gba/rr/rr.h" -#include "gba/serialize.h" -#include "gba/sio.h" -#include "gba/video.h" +#include <mgba/internal/arm/macros.h> +#include <mgba/internal/gba/dma.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/rr/rr.h> +#include <mgba/internal/gba/serialize.h> mLOG_DEFINE_CATEGORY(GBA_IO, "GBA I/O");

@@ -524,13 +524,15 @@ case REG_RCNT:

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 @@ // Write-only register

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 @@ case REG_SIOMULTI2:

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:
M src/gba/io.hinclude/mgba/internal/gba/io.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_IO_H #define GBA_IO_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "gba/gba.h" +CXX_GUARD_START + +#include <mgba/core/log.h> 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);

@@ -172,5 +175,7 @@

struct GBASerializedState; void GBAIOSerialize(struct GBA* gba, struct GBASerializedState* state); void GBAIODeserialize(struct GBA* gba, const struct GBASerializedState* state); + +CXX_GUARD_END #endif
M src/gba/memory.csrc/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 <mgba/internal/gba/memory.h> -#include "arm/decoder.h" -#include "gba/dma.h" -#include "gba/hardware.h" -#include "gba/io.h" -#include "gba/serialize.h" +#include <mgba/internal/arm/decoder.h> +#include <mgba/internal/arm/macros.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/dma.h> +#include <mgba/internal/gba/io.h> +#include <mgba/internal/gba/serialize.h> #include "gba/hle-bios.h" -#include "util/math.h" -#include "util/memory.h" -#include "util/vfs.h" + +#include <mgba-util/math.h> +#include <mgba-util/memory.h> +#include <mgba-util/vfs.h> #define IDLE_LOOP_THRESHOLD 10000
M src/gba/memory.hinclude/mgba/internal/gba/memory.h

@@ -6,14 +6,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_MEMORY_H #define GBA_MEMORY_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "arm/arm.h" -#include "core/timing.h" +CXX_GUARD_START -#include "gba/hardware.h" -#include "gba/savedata.h" -#include "gba/vfame.h" +#include <mgba/core/timing.h> + +#include <mgba/internal/arm/arm.h> +#include <mgba/internal/gba/hardware.h> +#include <mgba/internal/gba/savedata.h> +#include <mgba/internal/gba/vfame.h> enum GBAMemoryRegion { REGION_BIOS = 0x0,

@@ -116,7 +118,7 @@ uint32_t* bios;

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 @@

bool mirroring; }; +struct GBA; void GBAMemoryInit(struct GBA* gba); void GBAMemoryDeinit(struct GBA* gba);

@@ -179,5 +182,7 @@

struct GBASerializedState; void GBAMemorySerialize(const struct GBAMemory* memory, struct GBASerializedState* state); void GBAMemoryDeserialize(struct GBAMemory* memory, const struct GBASerializedState* state); + +CXX_GUARD_END #endif
M src/gba/overrides.csrc/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 <mgba/internal/gba/overrides.h> -#include "gba/gba.h" -#include "gba/hardware.h" +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/hardware.h> -#include "util/configuration.h" +#include <mgba-util/configuration.h> static const struct GBACartridgeOverride _overrides[] = { // Advance Wars
M src/gba/overrides.hinclude/mgba/internal/gba/overrides.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_OVERRIDES_H #define GBA_OVERRIDES_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "gba/savedata.h" +CXX_GUARD_START + +#include <mgba/internal/gba/savedata.h> #define IDLE_LOOP_NONE 0xFFFFFFFF

@@ -27,5 +29,7 @@

struct GBA; void GBAOverrideApply(struct GBA*, const struct GBACartridgeOverride*); void GBAOverrideApplyDefaults(struct GBA*); + +CXX_GUARD_END #endif
M src/gba/renderers/software-bg.csrc/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 <mgba/internal/gba/gba.h> #define MODE_2_COORD_OVERFLOW \ localX = x & (sizeAdjusted - 1); \
M src/gba/renderers/software-mode0.csrc/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 <mgba/internal/gba/gba.h> #define BACKGROUND_TEXT_SELECT_CHARACTER \ localX = tileX * 8 + inX; \
M src/gba/renderers/software-obj.csrc/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); \
M src/gba/renderers/software-private.hsrc/gba/renderers/software-private.h

@@ -6,7 +6,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef SOFTWARE_PRIVATE_H #define SOFTWARE_PRIVATE_H -#include "video-software.h" +#include <mgba/internal/arm/macros.h> +#include <mgba/internal/gba/renderers/video-software.h> #ifdef NDEBUG #define VIDEO_CHECKS false
M src/gba/renderers/thread-proxy.csrc/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 <mgba/internal/gba/renderers/thread-proxy.h> -#include "core/tile-cache.h" -#include "gba/io.h" -#include "gba/renderers/tile-cache.h" +#include <mgba/core/tile-cache.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/io.h> -#include "util/memory.h" +#include <mgba-util/memory.h> #ifndef DISABLE_THREADING
M src/gba/renderers/thread-proxy.hinclude/mgba/internal/gba/renderers/thread-proxy.h

@@ -6,9 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef VIDEO_THREAD_PROXY_H #define VIDEO_THREAD_PROXY_H -#include "gba/video.h" -#include "util/threading.h" -#include "util/ring-fifo.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/internal/gba/video.h> +#include <mgba-util/threading.h> +#include <mgba-util/ring-fifo.h> enum GBAVideoThreadProxyState { PROXY_THREAD_STOPPED = 0,

@@ -37,5 +41,7 @@ uint16_t paletteProxy[512];

}; void GBAVideoThreadProxyRendererCreate(struct GBAVideoThreadProxyRenderer* renderer, struct GBAVideoRenderer* backend); + +CXX_GUARD_END #endif
M src/gba/renderers/tile-cache.csrc/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 <mgba/internal/gba/renderers/tile-cache.h> -#include "core/tile-cache.h" -#include "gba/video.h" -#include "gba/renderers/tile-cache.h" +#include <mgba/core/tile-cache.h> +#include <mgba/internal/gba/video.h> void GBAVideoTileCacheInit(struct mTileCache* cache) { mTileCacheInit(cache);
M src/gba/renderers/tile-cache.hinclude/mgba/internal/gba/renderers/tile-cache.h

@@ -6,12 +6,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_TILE_CACHE_H #define GBA_TILE_CACHE_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct GBAVideo; struct mTileCache; void GBAVideoTileCacheInit(struct mTileCache* cache); void GBAVideoTileCacheAssociate(struct mTileCache* cache, struct GBAVideo* video); + +CXX_GUARD_END #endif
M src/gba/renderers/video-software.csrc/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 <mgba/core/tile-cache.h> +#include <mgba/internal/arm/macros.h> +#include <mgba/internal/gba/io.h> -#include "util/arm-algo.h" -#include "util/memory.h" +#include <mgba-util/arm-algo.h> +#include <mgba-util/memory.h> static void GBAVideoSoftwareRendererInit(struct GBAVideoRenderer* renderer); static void GBAVideoSoftwareRendererDeinit(struct GBAVideoRenderer* renderer);

@@ -459,7 +458,6 @@

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 @@ if (GBAObjAttributesAIsTransformed(obj.a)) {

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 @@ continue;

} 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) {
M src/gba/renderers/video-software.hinclude/mgba/internal/gba/renderers/video-software.h

@@ -6,10 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef VIDEO_SOFTWARE_H #define VIDEO_SOFTWARE_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/core.h" -#include "gba/video.h" +CXX_GUARD_START + +#include <mgba/core/core.h> +#include <mgba/internal/gba/video.h> struct GBAVideoSoftwareSprite { struct GBAObj obj;

@@ -152,14 +154,14 @@ struct GBAVideoSoftwareBackground bg[4];

int oamDirty; int oamMax; - int objwinMax; struct GBAVideoSoftwareSprite sprites[128]; - struct GBAVideoSoftwareSprite objwinSprites[128]; int start; int end; }; void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer); + +CXX_GUARD_START #endif
M src/gba/rr/mgm.csrc/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 <mgba/internal/gba/rr/mgm.h> -#include "gba/gba.h" -#include "gba/serialize.h" -#include "util/vfs.h" +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/serialize.h> +#include <mgba-util/vfs.h> #define BINARY_EXT ".mgm" #define BINARY_MAGIC "GBAb"
M src/gba/rr/mgm.hinclude/mgba/internal/gba/rr/mgm.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef RR_MGM_H #define RR_MGM_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "gba/rr/rr.h" +CXX_GUARD_START + +#include <mgba/internal/gba/rr/rr.h> struct GBA; struct VDir;

@@ -79,5 +81,7 @@ void GBAMGMContextCreate(struct GBAMGMContext*);

bool GBAMGMSetStream(struct GBAMGMContext* mgm, struct VDir* stream); bool GBAMGMCreateStream(struct GBAMGMContext* mgm, enum GBARRInitFrom initFrom); + +CXX_GUARD_END #endif
M src/gba/rr/rr.csrc/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 <mgba/internal/gba/rr/rr.h> -#include "core/serialize.h" -#include "util/vfs.h" +#include <mgba/core/log.h> +#include <mgba/core/serialize.h> +#include <mgba-util/vfs.h> mLOG_DEFINE_CATEGORY(GBA_RR, "GBA RR");
M src/gba/rr/rr.hinclude/mgba/internal/gba/rr/rr.h

@@ -6,10 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_RR_H #define GBA_RR_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" -#include "gba/serialize.h" +CXX_GUARD_START + +#include <mgba/core/log.h> +#include <mgba/internal/gba/serialize.h> struct VFile;

@@ -57,5 +59,7 @@ void GBARRDestroy(struct GBARRContext*);

void GBARRInitRecord(struct GBA*); void GBARRInitPlay(struct GBA*); + +CXX_GUARD_END #endif
M src/gba/rr/vbm.csrc/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 <mgba/internal/gba/rr/vbm.h> -#include "gba/gba.h" -#include "gba/serialize.h" -#include "util/vfs.h" +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/serialize.h> +#include <mgba-util/vfs.h> #ifdef USE_ZLIB #include <zlib.h>

@@ -245,7 +245,7 @@

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
M src/gba/rr/vbm.hinclude/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 <mgba-util/common.h> + +CXX_GUARD_START -#include "gba/rr/rr.h" +#include <mgba/internal/gba/rr/rr.h> struct GBAVBMContext { struct GBARRContext d;

@@ -19,3 +24,7 @@

void GBAVBMContextCreate(struct GBAVBMContext*); bool GBAVBMSetStream(struct GBAVBMContext*, struct VFile*); + +CXX_GUARD_END + +#endif
M src/gba/savedata.csrc/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 <mgba/internal/gba/savedata.h> -#include "gba/gba.h" -#include "gba/serialize.h" +#include <mgba/internal/arm/macros.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/serialize.h> -#include "util/memory.h" -#include "util/vfs.h" +#include <mgba-util/memory.h> +#include <mgba-util/vfs.h> #include <errno.h> #include <fcntl.h>
M src/gba/savedata.hinclude/mgba/internal/gba/savedata.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_SAVEDATA_H #define GBA_SAVEDATA_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" +CXX_GUARD_START + +#include <mgba/core/log.h> mLOG_DECLARE_CATEGORY(GBA_SAVE);

@@ -118,5 +120,7 @@

struct GBASerializedState; void GBASavedataSerialize(const struct GBASavedata* savedata, struct GBASerializedState* state); void GBASavedataDeserialize(struct GBASavedata* savedata, const struct GBASerializedState* state); + +CXX_GUARD_END #endif
M src/gba/serialize.csrc/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 <mgba/internal/gba/serialize.h> -#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 <mgba/internal/arm/macros.h> +#include <mgba/internal/gba/io.h> +#include <mgba/internal/gba/rr/rr.h> -#include "util/memory.h" -#include "util/vfs.h" +#include <mgba-util/memory.h> +#include <mgba-util/vfs.h> #include <fcntl.h> #ifdef _MSC_VER
M src/gba/serialize.hinclude/mgba/internal/gba/serialize.h

@@ -6,11 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_SERIALIZE_H #define GBA_SERIALIZE_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/core.h" -#include "gba/gba.h" -#include "gb/serialize.h" +CXX_GUARD_START + +#include <mgba/core/core.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gb/serialize.h> extern const uint32_t GBA_SAVESTATE_MAGIC; extern const uint32_t GBA_SAVESTATE_VERSION;

@@ -332,5 +334,7 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state);

struct GBASerializedState* GBAAllocateState(void); void GBADeallocateState(struct GBASerializedState* state); + +CXX_GUARD_END #endif
M src/gba/sharkport.csrc/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 <mgba/internal/gba/sharkport.h> -#include "gba/gba.h" -#include "util/vfs.h" +#include <mgba/internal/arm/macros.h> +#include <mgba/internal/gba/gba.h> +#include <mgba-util/vfs.h> static const char* const SHARKPORT_HEADER = "SharkPortSave";
M src/gba/sharkport.hinclude/mgba/internal/gba/sharkport.h

@@ -6,12 +6,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_SHARKPORT_H #define GBA_SHARKPORT_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct GBA; 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
M src/gba/sio.csrc/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 <mgba/internal/gba/sio.h> -#include "gba/io.h" +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/io.h> mLOG_DEFINE_CATEGORY(GBA_SIO, "GBA Serial I/O");
M src/gba/sio.hinclude/mgba/internal/gba/sio.h

@@ -6,10 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_SIO_H #define GBA_SIO_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" -#include "gba/interface.h" +CXX_GUARD_START + +#include <mgba/gba/interface.h> +#include <mgba/core/log.h> #define MAX_GBAS 4

@@ -19,6 +21,16 @@ mLOG_DECLARE_CATEGORY(GBA_SIO);

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 {

@@ -77,5 +89,7 @@

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
M src/gba/sio/lockstep.csrc/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 <mgba/internal/gba/sio/lockstep.h> -#include "gba/gba.h" -#include "gba/io.h" -#include "gba/video.h" +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/io.h> #define LOCKSTEP_INCREMENT 3000

@@ -20,6 +19,7 @@ static uint16_t GBASIOLockstepNodeNormalWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value);

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 @@ lockstep->multiRecv[0] = 0xFFFF;

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 @@ node->d.writeRegister = 0;

} 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 @@ case SIO_MULTI:

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 @@ default:

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 @@ break;

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, uint32_t address, uint16_t value) {

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 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 @@ node->p->multiRecv[1] = 0xFFFF;

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 @@ return node->nextEvent;

} 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 @@ signal = true;

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 @@ if (!node->id) {

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 @@ }

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) {
D src/gba/sio/lockstep.h

@@ -1,67 +0,0 @@

-/* Copyright (c) 2013-2015 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 "core/timing.h" -#include "gba/sio.h" - -enum GBASIOLockstepPhase { - TRANSFER_IDLE = 0, - TRANSFER_STARTING, - TRANSFER_STARTED, - TRANSFER_FINISHING, - TRANSFER_FINISHED -}; - -struct GBASIOLockstep { - 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 { - struct GBASIODriver d; - struct GBASIOLockstep* p; - struct mTimingEvent event; - - volatile int32_t nextEvent; - int32_t eventDiff; - bool normalSO; - int id; - enum GBASIOMode mode; - bool transferFinished; -#ifndef NDEBUG - int transferId; - enum GBASIOLockstepPhase 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*); - -#endif
M src/gba/test/core.csrc/gba/test/core.c

@@ -5,8 +5,8 @@ * 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/test/suite.h" -#include "core/core.h" -#include "gba/core.h" +#include <mgba/core/core.h> +#include <mgba/gba/core.h> M_TEST_DEFINE(create) { struct mCore* core = GBACoreCreate();
M src/gba/test/gba.hsrc/gba/test/gba.h

@@ -5,7 +5,7 @@ * 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 TEST_GBA_H #define TEST_GBA_H -#include "util/common.h" +#include <mgba-util/common.h> int TestRunGBA(void);
M src/gba/timer.csrc/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 <mgba/internal/gba/timer.h> -#include "gba/gba.h" -#include "gba/io.h" +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/io.h> static void GBATimerUpdate(struct mTiming* timing, struct GBA* gba, int timerId, uint32_t cyclesLate) { struct GBATimer* timer = &gba->timers[timerId];
M src/gba/timer.hinclude/mgba/internal/gba/timer.h

@@ -6,8 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_TIMER_H #define GBA_TIMER_H -#include "util/common.h" -#include "core/timing.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/core/timing.h> DECL_BITFIELD(GBATimerFlags, uint32_t); DECL_BITS(GBATimerFlags, PrescaleBits, 0, 4);

@@ -29,5 +32,7 @@ void GBATimerInit(struct GBA* gba);

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
M src/gba/vfame.csrc/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 <mgba/internal/gba/vfame.h> -#include "vfame.h" -#include "gba/gba.h" -#include "gba/memory.h" +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/memory.h> static const uint8_t ADDRESS_REORDERING[4][16] = { { 15, 14, 9, 1, 8, 10, 7, 3, 5, 11, 4, 0, 13, 12, 2, 6 },
M src/gba/vfame.hinclude/mgba/internal/gba/vfame.h

@@ -9,7 +9,9 @@

#ifndef GBA_VFAME_H #define GBA_VFAME_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START enum GBAVFameCartType { VFAME_NO = 0,

@@ -30,5 +32,7 @@ void GBAVFameDetect(struct GBAVFameCart* cart, uint32_t* rom, size_t romSize);

void GBAVFameSramWrite(struct GBAVFameCart* cart, uint32_t address, uint8_t value, uint8_t* sramData); uint32_t GBAVFameModifyRomAddress(struct GBAVFameCart* cart, uint32_t address, size_t romSize); uint32_t GBAVFameGetPatternValue(uint32_t address, int bits); + +CXX_GUARD_END #endif
M src/gba/video.csrc/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 <mgba/internal/gba/video.h> -#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 <mgba/core/sync.h> +#include <mgba/core/tile-cache.h> +#include <mgba/internal/arm/macros.h> +#include <mgba/internal/gba/dma.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/io.h> +#include <mgba/internal/gba/serialize.h> -#include "util/memory.h" +#include <mgba-util/memory.h> mLOG_DEFINE_CATEGORY(GBA_VIDEO, "GBA Video");
M src/gba/video.hinclude/mgba/internal/gba/video.h

@@ -6,11 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GBA_VIDEO_H #define GBA_VIDEO_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/core.h" -#include "core/timing.h" -#include "gba/memory.h" +CXX_GUARD_START + +#include <mgba/core/log.h> +#include <mgba/core/timing.h> mLOG_DECLARE_CATEGORY(GBA_VIDEO);

@@ -19,13 +20,13 @@ VIDEO_HORIZONTAL_PIXELS = 240,

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 @@

// VCOUNT int vcount; - uint16_t palette[SIZE_PALETTE_RAM >> 1]; + uint16_t palette[512]; uint16_t* vram; union GBAOAM oam;

@@ -198,5 +199,7 @@ void GBAVideoSerialize(const struct GBAVideo* video, struct GBASerializedState* state);

void GBAVideoDeserialize(struct GBAVideo* video, const struct GBASerializedState* state); extern const int GBAVideoObjSizes[16][2]; + +CXX_GUARD_END #endif
M src/lr35902/debugger/cli-debugger.csrc/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 <mgba/internal/lr35902/debugger/cli-debugger.h> -#include "core/core.h" -#include "debugger/cli-debugger.h" -#include "lr35902/lr35902.h" +#include <mgba/core/core.h> +#include <mgba/internal/debugger/cli-debugger.h> +#include <mgba/internal/lr35902/lr35902.h> static void _printStatus(struct CLIDebuggerSystem*);
M src/lr35902/debugger/cli-debugger.hinclude/mgba/internal/lr35902/debugger/cli-debugger.h

@@ -6,9 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef LR35902_CLI_DEBUGGER_H #define LR35902_CLI_DEBUGGER_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct CLIDebuggerSystem; void LR35902CLIDebuggerCreate(struct CLIDebuggerSystem* debugger); + +CXX_GUARD_END #endif
M src/lr35902/debugger/debugger.csrc/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 <mgba/internal/lr35902/debugger/debugger.h> -#include "lr35902/lr35902.h" -#include "core/core.h" +#include <mgba/core/core.h> +#include <mgba/internal/lr35902/lr35902.h> DEFINE_VECTOR(LR35902DebugBreakpointList, struct LR35902DebugBreakpoint); DEFINE_VECTOR(LR35902DebugWatchpointList, struct LR35902DebugWatchpoint);
M src/lr35902/debugger/debugger.hinclude/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 <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/internal/debugger/debugger.h> struct LR35902DebugBreakpoint { uint16_t address;

@@ -28,3 +35,7 @@ struct LR35902DebugWatchpointList watchpoints;

}; struct mDebuggerPlatform* LR35902DebuggerPlatformCreate(void); + +CXX_GUARD_END + +#endif
M src/lr35902/isa-lr35902.csrc/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 <mgba/internal/lr35902/isa-lr35902.h> + +#include <mgba/internal/lr35902/emitter-lr35902.h> +#include <mgba/internal/lr35902/lr35902.h> -#include "lr35902/emitter-lr35902.h" -#include "lr35902/lr35902.h" +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) { \
M src/lr35902/isa-lr35902.hinclude/mgba/internal/lr35902/isa-lr35902.h

@@ -6,11 +6,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef ISA_LR35902_H #define ISA_LR35902_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct LR35902Core; typedef void (*LR35902Instruction)(struct LR35902Core*); extern const LR35902Instruction _lr35902InstructionTable[0x100]; + +CXX_GUARD_END #endif
M src/lr35902/lr35902.csrc/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 <mgba/internal/lr35902/lr35902.h> -#include "isa-lr35902.h" +#include <mgba/internal/lr35902/isa-lr35902.h> void LR35902Init(struct LR35902Core* cpu) { cpu->master->init(cpu, cpu->master);
M src/lr35902/lr35902.hinclude/mgba/internal/lr35902/lr35902.h

@@ -6,10 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef LR35902_H #define LR35902_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/cpu.h" -#include "lr35902/isa-lr35902.h" +CXX_GUARD_START + +#include <mgba/core/cpu.h> +#include <mgba/internal/lr35902/isa-lr35902.h> struct LR35902Core;

@@ -21,9 +23,9 @@ unsigned z : 1;

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 @@ size_t numComponents;

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);

@@ -166,5 +138,7 @@ void LR35902RaiseIRQ(struct LR35902Core* cpu, uint8_t vector);

void LR35902Tick(struct LR35902Core* cpu); void LR35902Run(struct LR35902Core* cpu); + +CXX_GUARD_END #endif
M src/platform/3ds/3ds-memory.csrc/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 <mgba-util/memory.h> #include <3ds.h>
M src/platform/3ds/3ds-vfs.csrc/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 <mgba-util/platform/3ds/3ds-vfs.h> #ifdef USE_VFS_3DS -#include "util/memory.h" -#include "util/string.h" +#include <mgba-util/memory.h> +#include <mgba-util/string.h> struct VFile3DS { struct VFile d;
M src/platform/3ds/3ds-vfs.hinclude/mgba-util/platform/3ds/3ds-vfs.h

@@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef N3DS_VFS_H #define N3DS_VFS_H -#include "util/vfs.h" +#include <mgba-util/vfs.h> #include <3ds.h>
M src/platform/3ds/ctru-heap.csrc/platform/3ds/ctru-heap.c

@@ -28,7 +28,7 @@ #include <3ds/services/fs.h>

#include <3ds/services/hid.h> #include <3ds/svc.h> -#include "util/common.h" +#include <mgba-util/common.h> extern char* fake_heap_start; extern char* fake_heap_end;
M src/platform/3ds/gui-font.csrc/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 <mgba-util/gui/font.h> +#include <mgba-util/gui/font-metrics.h> +#include <mgba-util/png-io.h> +#include <mgba-util/vfs.h> #include "icons.h" #include "ctr-gpu.h"
M src/platform/3ds/main.csrc/platform/3ds/main.c

@@ -4,22 +4,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 <mgba/core/blip_buf.h> +#include <mgba/core/core.h> #ifdef M_CORE_GBA -#include "gba/gba.h" -#include "gba/input.h" -#include "gba/video.h" +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/input.h> +#include <mgba/internal/gba/video.h> #endif #ifdef M_CORE_GB -#include "gb/gb.h" +#include <mgba/internal/gb/gb.h> #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 <mgba-util/gui.h> +#include <mgba-util/gui/file-select.h> +#include <mgba-util/gui/font.h> +#include <mgba-util/gui/menu.h> +#include <mgba-util/memory.h> -#include "3ds-vfs.h" +#include <mgba-util/platform/3ds/3ds-vfs.h> #include "ctr-gpu.h" #include <3ds.h>
M src/platform/3ds/socket.csrc/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 <mgba-util/socket.h> u32* SOCUBuffer = NULL;
M src/platform/3ds/threading.hinclude/mgba-util/platform/3ds/threading.h

@@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef N3DS_THREADING_H #define N3DS_THREADING_H -#include "util/common.h" +#include <mgba-util/common.h> #include <3ds.h> #include <malloc.h>
M src/platform/example/client-server/client.csrc/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 <mgba/core/core.h> +#include <mgba/core/version.h> +#include <mgba-util/socket.h> #include <SDL.h>
M src/platform/example/client-server/server.csrc/platform/example/client-server/server.c

@@ -1,7 +1,7 @@

// This source file is placed into the public domain. -#include "core/core.h" +#include <mgba/core/core.h> #include "feature/commandline.h" -#include "util/socket.h" +#include <mgba-util/socket.h> #define DEFAULT_PORT 13721
M src/platform/libretro/libretro.csrc/platform/libretro/libretro.c

@@ -5,24 +5,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 "libretro.h" -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/core.h" -#include "core/version.h" +#include <mgba/core/blip_buf.h> +#include <mgba/core/cheats.h> +#include <mgba/core/core.h> +#include <mgba/core/version.h> #ifdef M_CORE_GB -#include "gb/core.h" -#include "gb/gb.h" +#include <mgba/gb/core.h> #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 <mgba/gba/core.h> +#include <mgba/gba/interface.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/video.h> #endif -#include "util/circle-buffer.h" -#include "util/memory.h" -#include "util/vfs.h" +#include <mgba-util/circle-buffer.h> +#include <mgba-util/memory.h> +#include <mgba-util/vfs.h> #define SAMPLES 1024 #define RUMBLE_PWM 35

@@ -146,7 +146,7 @@ info->geometry.base_height = height;

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 @@ struct GBA* gba = core->board;

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 @@ CircleBufferDeinit(&rumbleHistory);

} 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; }
M src/platform/openemu/mGBAGameCore.msrc/platform/openemu/mGBAGameCore.m

@@ -24,17 +24,18 @@ */

#import "mGBAGameCore.h" -#include "util/common.h" +#include <mgba-util/common.h> -#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 <mgba/core/blip_buf.h> +#include <mgba/core/core.h> +#include <mgba/core/cheats.h> +#include <mgba/core/serialize.h> +#include <mgba/gba/core.h> +#include <mgba/internal/gba/cheats.h> +#include <mgba/internal/gba/input.h> +#include <mgba-util/circle-buffer.h> +#include <mgba-util/memory.h> +#include <mgba-util/vfs.h> #import <OpenEmuBase/OERingBuffer.h> #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
M src/platform/opengl/gl.csrc/platform/opengl/gl.c

@@ -5,7 +5,7 @@ * 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 "gl.h" -#include "util/math.h" +#include <mgba-util/math.h> static const GLint _glVertices[] = { 0, 0,
M src/platform/opengl/gl.hsrc/platform/opengl/gl.h

@@ -6,6 +6,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GL_H #define GL_H +#include <mgba-util/common.h> + +CXX_GUARD_START + #ifdef USE_EPOXY #include <epoxy/gl.h> #elif defined(__APPLE__)

@@ -26,5 +30,7 @@ GLuint tex;

}; void mGLContextCreate(struct mGLContext*); + +CXX_GUARD_END #endif
M src/platform/opengl/gles2.csrc/platform/opengl/gles2.c

@@ -5,11 +5,11 @@ * 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 "gles2.h" -#include "core/log.h" -#include "util/configuration.h" -#include "util/formatting.h" -#include "util/vector.h" -#include "util/vfs.h" +#include <mgba/core/log.h> +#include <mgba-util/configuration.h> +#include <mgba-util/formatting.h> +#include <mgba-util/vector.h> +#include <mgba-util/vfs.h> mLOG_DECLARE_CATEGORY(OPENGL); mLOG_DEFINE_CATEGORY(OPENGL, "OpenGL");
M src/platform/opengl/gles2.hsrc/platform/opengl/gles2.h

@@ -6,6 +6,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GLES2_H #define GLES2_H +#include <mgba-util/common.h> + +CXX_GUARD_START + #ifdef USE_EPOXY #include <epoxy/gl.h> #elif defined(BUILD_GL)

@@ -93,5 +97,7 @@

struct VDir; bool mGLES2ShaderLoad(struct VideoShader*, struct VDir*); void mGLES2ShaderFree(struct VideoShader*); + +CXX_GUARD_END #endif
M src/platform/posix/memory.csrc/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 <mgba-util/memory.h> #include <sys/mman.h>
M src/platform/posix/threading.hinclude/mgba-util/platform/posix/threading.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef POSIX_THREADING_H #define POSIX_THREADING_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START #include <pthread.h> #include <sys/time.h>

@@ -93,5 +95,7 @@ UNUSED(name);

return 0; #endif } + +CXX_GUARD_END #endif
M src/platform/psp2/gui-font.csrc/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 <mgba-util/gui/font.h> +#include <mgba-util/gui/font-metrics.h> +#include <mgba-util/string.h> #include <vita2d.h>
M src/platform/psp2/main.csrc/platform/psp2/main.c

@@ -5,12 +5,12 @@ * 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 "psp2-context.h" -#include "gba/gba.h" +#include <mgba/internal/gba/gba.h> #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 <mgba-util/gui.h> +#include <mgba-util/gui/font.h> +#include <mgba-util/gui/file-select.h> +#include <mgba-util/gui/menu.h> #include <psp2/ctrl.h> #include <psp2/display.h>
M src/platform/psp2/psp2-common.hsrc/platform/psp2/psp2-common.h

@@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef PSP2_COMMON_H #define PSP2_COMMON_H -#include "util/common.h" +#include <mgba-util/common.h> #define PSP2_HORIZONTAL_PIXELS 960 #define PSP2_VERTICAL_PIXELS 544
M src/platform/psp2/psp2-context.csrc/platform/psp2/psp2-context.c

@@ -5,25 +5,25 @@ * 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 "psp2-context.h" -#include "core/core.h" +#include <mgba/core/blip_buf.h> +#include <mgba/core/core.h> #ifdef M_CORE_GBA -#include "gba/gba.h" +#include <mgba/internal/gba/gba.h> #endif #ifdef M_CORE_GB -#include "gb/gb.h" +#include <mgba/internal/gb/gb.h> #endif #include "feature/gui/gui-runner.h" -#include "gba/input.h" +#include <mgba/internal/gba/input.h> -#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 <mgba-util/memory.h> +#include <mgba-util/circle-buffer.h> +#include <mgba-util/ring-fifo.h> +#include <mgba-util/threading.h> +#include <mgba-util/vfs.h> +#include <mgba-util/platform/psp2/sce-vfs.h> #include <psp2/audioout.h> #include <psp2/ctrl.h>
M src/platform/psp2/psp2-context.hsrc/platform/psp2/psp2-context.h

@@ -7,8 +7,8 @@ #ifndef PSP2_CONTEXT_H

#define PSP2_CONTEXT_H #include "psp2-common.h" -#include "core/interface.h" -#include "util/gui.h" +#include <mgba/core/interface.h> +#include <mgba-util/gui.h> struct mGUIRunner; void mPSP2Setup(struct mGUIRunner* runner);
M src/platform/psp2/psp2-memory.csrc/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 <mgba-util/memory.h> +#include <mgba-util/vector.h> #include <psp2/kernel/sysmem.h> #include <psp2/types.h>
M src/platform/psp2/sce-vfs.csrc/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 <mgba-util/platform/psp2/sce-vfs.h> #include <psp2/io/dirent.h> -#include "util/vfs.h" -#include "util/memory.h" +#include <mgba-util/vfs.h> +#include <mgba-util/memory.h> struct VFileSce { struct VFile d;
A 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)
A 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 <limits.h> +#undef const + +#include "flags.h" + +#include <mgba/core/core.h> +#include <mgba/core/tile-cache.h> +#include "platform/python/vfs-py.h" +#include "platform/python/log.h" + +#ifdef USE_PNG +#include <mgba-util/png-io.h> +#endif +#ifdef M_CORE_GBA +#include <mgba/internal/arm/arm.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/input.h> +#include <mgba/internal/gba/renderers/tile-cache.h> +#endif +#ifdef M_CORE_GB +#include <mgba/internal/lr35902/lr35902.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gba/input.h> +#include <mgba/internal/gb/renderers/tile-cache.h> +#endif
A 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 <mgba-util/common.h> +#include <mgba/core/core.h> +#include <mgba/core/log.h> +#include <mgba/core/tile-cache.h> +#include <mgba/internal/arm/arm.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/input.h> +#include <mgba/internal/gba/renderers/tile-cache.h> +#include <mgba/internal/lr35902/lr35902.h> +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/renderers/tile-cache.h> +#include <mgba-util/png-io.h> +#include <mgba-util/vfs.h> + +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()
A 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 <mgba/core/log.h> + +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; +}
A 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 <mgba/core/log.h> + +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);
A 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 +
A 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
A 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
A 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
A 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
A 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
A 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
A 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
A 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
A 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)
A 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)
A 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 + )
A 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 <mgba-util/vfs.h> + +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; +}
A 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 <mgba-util/vfs.h> + +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); + +}
M src/platform/qt/AboutScreen.cppsrc/platform/qt/AboutScreen.cpp

@@ -5,9 +5,7 @@ * 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 "AboutScreen.h" -extern "C" { -#include "core/version.h" -} +#include <mgba/core/version.h> #include <QFile> #include <QPixmap>
M src/platform/qt/ArchiveInspector.cppsrc/platform/qt/ArchiveInspector.cpp

@@ -5,9 +5,7 @@ * 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 "ArchiveInspector.h" -extern "C" { -#include "util/vfs.h" -} +#include <mgba-util/vfs.h> using namespace QGBA;
M src/platform/qt/AssetTile.cppsrc/platform/qt/AssetTile.cpp

@@ -9,15 +9,13 @@ #include "GBAApp.h"

#include <QFontDatabase> -extern "C" { -#include "core/interface.h" +#include <mgba/core/interface.h> #ifdef M_CORE_GBA -#include "gba/memory.h" +#include <mgba/internal/gba/memory.h> #endif #ifdef M_CORE_GB -#include "gb/memory.h" +#include <mgba/internal/gb/memory.h> #endif -} using namespace QGBA;
M src/platform/qt/AssetTile.hsrc/platform/qt/AssetTile.h

@@ -10,9 +10,7 @@ #include "GameController.h"

#include "ui_AssetTile.h" -extern "C" { -#include "core/tile-cache.h" -} +#include <mgba/core/tile-cache.h> namespace QGBA {
M src/platform/qt/AssetView.cppsrc/platform/qt/AssetView.cpp

@@ -7,12 +7,6 @@ #include "AssetView.h"

#include <QTimer> -extern "C" { -#ifdef M_CORE_GBA -#include "gba/gba.h" -#endif -} - using namespace QGBA; AssetView::AssetView(GameController* controller, QWidget* parent)
M src/platform/qt/AudioDevice.cppsrc/platform/qt/AudioDevice.cpp

@@ -7,10 +7,10 @@ #include "AudioDevice.h"

#include "LogController.h" -extern "C" { -#include "core/thread.h" -#include "gba/audio.h" -} +#include <mgba/core/blip_buf.h> +#include <mgba/core/core.h> +#include <mgba/core/thread.h> +#include <mgba/internal/gba/audio.h> using namespace QGBA;
M src/platform/qt/AudioProcessorQt.cppsrc/platform/qt/AudioProcessorQt.cpp

@@ -10,9 +10,8 @@ #include "LogController.h"

#include <QAudioOutput> -extern "C" { -#include "core/thread.h" -} +#include <mgba/core/core.h> +#include <mgba/core/thread.h> using namespace QGBA;
M src/platform/qt/AudioProcessorSDL.cppsrc/platform/qt/AudioProcessorSDL.cpp

@@ -7,9 +7,7 @@ #include "AudioProcessorSDL.h"

#include "LogController.h" -extern "C" { -#include "core/thread.h" -} +#include <mgba/core/thread.h> using namespace QGBA;
M src/platform/qt/AudioProcessorSDL.hsrc/platform/qt/AudioProcessorSDL.h

@@ -9,9 +9,7 @@ #include "AudioProcessor.h"

#ifdef BUILD_SDL -extern "C" { #include "platform/sdl/sdl-audio.h" -} namespace QGBA {
M src/platform/qt/CheatsModel.cppsrc/platform/qt/CheatsModel.cpp

@@ -10,9 +10,8 @@ #include "VFileDevice.h"

#include <QSet> -extern "C" { -#include "core/cheats.h" -} +#include <mgba/core/cheats.h> +#include <mgba-util/vfs.h> using namespace QGBA;
M src/platform/qt/CheatsView.cppsrc/platform/qt/CheatsView.cpp

@@ -11,15 +11,13 @@

#include <QClipboard> #include <QPushButton> -extern "C" { -#include "core/cheats.h" +#include <mgba/core/cheats.h> #ifdef M_CORE_GBA -#include "gba/cheats.h" +#include <mgba/internal/gba/cheats.h> #endif #ifdef M_CORE_GB -#include "gb/cheats.h" +#include <mgba/internal/gb/cheats.h> #endif -} using namespace QGBA;
M src/platform/qt/ConfigController.cppsrc/platform/qt/ConfigController.cpp

@@ -11,9 +11,7 @@ #include <QAction>

#include <QDir> #include <QMenu> -extern "C" { #include "feature/commandline.h" -} using namespace QGBA;
M src/platform/qt/ConfigController.hsrc/platform/qt/ConfigController.h

@@ -15,11 +15,9 @@ #include <QVariant>

#include <functional> -extern "C" { -#include "core/config.h" -#include "util/configuration.h" +#include <mgba/core/config.h> +#include <mgba-util/configuration.h> #include "feature/commandline.h" -} class QAction; class QMenu;
M src/platform/qt/DebuggerConsoleController.cppsrc/platform/qt/DebuggerConsoleController.cpp

@@ -9,9 +9,7 @@ #include "GameController.h"

#include <QMutexLocker> -extern "C" { -#include "debugger/cli-debugger.h" -} +#include <mgba/internal/debugger/cli-debugger.h> using namespace QGBA;
M src/platform/qt/DebuggerConsoleController.hsrc/platform/qt/DebuggerConsoleController.h

@@ -12,9 +12,7 @@ #include <QMutex>

#include <QStringList> #include <QWaitCondition> -extern "C" { -#include "debugger/cli-debugger.h" -} +#include <mgba/internal/debugger/cli-debugger.h> namespace QGBA {
M src/platform/qt/Display.cppsrc/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 <mgba/internal/gb/video.h> #elif defined(M_CORE_GBA) -#include "gba/video.h" +#include <mgba/internal/gba/video.h> #endif -} using namespace QGBA;
M src/platform/qt/Display.hsrc/platform/qt/Display.h

@@ -6,9 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef QGBA_DISPLAY #define QGBA_DISPLAY -extern "C" { -#include "util/common.h" -} +#include <mgba-util/common.h> #include <QWidget>
M src/platform/qt/DisplayGL.cppsrc/platform/qt/DisplayGL.cpp

@@ -8,9 +8,8 @@

#include <QApplication> #include <QResizeEvent> -extern "C" { -#include "core/core.h" -#include "core/thread.h" +#include <mgba/core/core.h> +#include <mgba/core/thread.h> #ifdef BUILD_GL #include "platform/opengl/gl.h" #endif

@@ -20,7 +19,6 @@ #ifdef _WIN32

#include <epoxy/wgl.h> #endif #endif -} using namespace QGBA;
M src/platform/qt/DisplayGL.hsrc/platform/qt/DisplayGL.h

@@ -22,9 +22,7 @@ #include <QQueue>

#include <QThread> #include <QTimer> -extern "C" { #include "platform/video-backend.h" -} namespace QGBA {
M src/platform/qt/DisplayQt.cppsrc/platform/qt/DisplayQt.cpp

@@ -7,10 +7,8 @@ #include "DisplayQt.h"

#include <QPainter> -extern "C" { -#include "core/core.h" -#include "core/thread.h" -} +#include <mgba/core/core.h> +#include <mgba/core/thread.h> using namespace QGBA;
M src/platform/qt/GBAApp.cppsrc/platform/qt/GBAApp.cpp

@@ -16,13 +16,14 @@ #include <QFileOpenEvent>

#include <QIcon> #include <QTranslator> -extern "C" { -#include "core/version.h" +#include <mgba/core/version.h> +#include <mgba/internal/gba/video.h> +#include <mgba-util/socket.h> +#include <mgba-util/nointro.h> +#include <mgba-util/vfs.h> +/* #include "feature/commandline.h" -#include "util/nointro.h" -#include "util/socket.h" -} - +*/ using namespace QGBA; static GBAApp* g_app = nullptr;
M src/platform/qt/GBAApp.hsrc/platform/qt/GBAApp.h

@@ -14,9 +14,7 @@ #include "MultiplayerController.h"

struct NoIntroDB; -extern "C" { -#include "core/log.h" -} +#include <mgba/core/log.h> mLOG_DECLARE_CATEGORY(QT);
M src/platform/qt/GBAKeyEditor.cppsrc/platform/qt/GBAKeyEditor.cpp

@@ -16,9 +16,7 @@ #include "InputController.h"

#include "KeyEditor.h" #ifdef BUILD_SDL -extern "C" { #include "platform/sdl/sdl-events.h" -} #endif using namespace QGBA;
M src/platform/qt/GBAKeyEditor.hsrc/platform/qt/GBAKeyEditor.h

@@ -11,9 +11,7 @@ #include <QPicture>

#include <QSet> #include <QWidget> -extern "C" { -#include "gba/input.h" -} +#include <mgba/internal/gba/input.h> class QComboBox; class QTimer;
M src/platform/qt/GBAOverride.cppsrc/platform/qt/GBAOverride.cpp

@@ -5,9 +5,7 @@ * 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 "GBAOverride.h" -extern "C" { -#include "core/core.h" -} +#include <mgba/core/core.h> using namespace QGBA;
M src/platform/qt/GBAOverride.hsrc/platform/qt/GBAOverride.h

@@ -8,9 +8,7 @@ #define QGBA_GBA_OVERRIDE

#include "Override.h" -extern "C" { -#include "gba/overrides.h" -} +#include <mgba/internal/gba/overrides.h> namespace QGBA {
M src/platform/qt/GBOverride.cppsrc/platform/qt/GBOverride.cpp

@@ -5,11 +5,9 @@ * 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 "GBOverride.h" -extern "C" { -#include "core/core.h" -#include "gb/gb.h" -#include "util/crc32.h" -} +#include <mgba/core/core.h> +#include <mgba/internal/gb/gb.h> +#include <mgba-util/crc32.h> using namespace QGBA;
M src/platform/qt/GBOverride.hsrc/platform/qt/GBOverride.h

@@ -8,9 +8,7 @@ #define QGBA_GB_OVERRIDE

#include "Override.h" -extern "C" { -#include "gb/overrides.h" -} +#include <mgba/internal/gb/overrides.h> namespace QGBA {
M src/platform/qt/GDBController.hsrc/platform/qt/GDBController.h

@@ -10,9 +10,7 @@ #include "DebuggerController.h"

#ifdef USE_GDB_STUB -extern "C" { -#include "debugger/gdb-stub.h" -} +#include <mgba/internal/debugger/gdb-stub.h> namespace QGBA {
M src/platform/qt/GIFView.cppsrc/platform/qt/GIFView.cpp

@@ -12,6 +12,9 @@ #include "LogController.h"

#include <QMap> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/video.h> + using namespace QGBA; GIFView::GIFView(QWidget* parent)
M src/platform/qt/GIFView.hsrc/platform/qt/GIFView.h

@@ -12,9 +12,7 @@ #include <QWidget>

#include "ui_GIFView.h" -extern "C" { #include "feature/imagemagick/imagemagick-gif-encoder.h" -} namespace QGBA {
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -17,24 +17,23 @@ #include <QThread>

#include <ctime> -extern "C" { -#include "core/config.h" -#include "core/directories.h" -#include "core/serialize.h" -#include "core/tile-cache.h" +#include <mgba/core/config.h> +#include <mgba/core/directories.h> +#include <mgba/core/serialize.h> +#include <mgba/core/tile-cache.h> #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 <mgba/gba/interface.h> +#include <mgba/internal/gba/bios.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/gba/core.h> +#include <mgba/internal/gba/renderers/tile-cache.h> +#include <mgba/internal/gba/sharkport.h> #endif #ifdef M_CORE_GB -#include "gb/gb.h" -#include "gb/renderers/tile-cache.h" +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/renderers/tile-cache.h> #endif -#include "util/vfs.h" -} +#include <mgba-util/vfs.h> using namespace QGBA; using namespace std;
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -15,17 +15,13 @@ #include <QTimer>

#include <memory> -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 <mgba/core/core.h> +#include <mgba/core/thread.h> +#include <mgba/gba/interface.h> +#include <mgba/internal/gba/input.h> #ifdef BUILD_SDL #include "platform/sdl/sdl-events.h" #endif -} struct Configuration; struct GBAAudio;
M src/platform/qt/GamepadAxisEvent.hsrc/platform/qt/GamepadAxisEvent.h

@@ -8,9 +8,7 @@ #define QGBA_GAMEPAD_AXIS_EVENT

#include <QEvent> -extern "C" { -#include "gba/input.h" -} +#include <mgba/internal/gba/input.h> namespace QGBA {
M src/platform/qt/GamepadButtonEvent.hsrc/platform/qt/GamepadButtonEvent.h

@@ -8,9 +8,7 @@ #define QGBA_GAMEPAD_BUTTON_EVENT

#include <QEvent> -extern "C" { -#include "gba/input.h" -} +#include <mgba/internal/gba/input.h> namespace QGBA {
M src/platform/qt/IOViewer.cppsrc/platform/qt/IOViewer.cpp

@@ -12,12 +12,12 @@ #include <QFontDatabase>

#include <QGridLayout> #include <QSpinBox> -extern "C" { -#include "gba/io.h" -} +#include <mgba/internal/gba/io.h> +#include <mgba/internal/gba/memory.h> -using namespace QGBA; +struct ARMCore; +using namespace QGBA; QList<IOViewer::RegisterDescription> IOViewer::s_registers;
M src/platform/qt/InputController.cppsrc/platform/qt/InputController.cpp

@@ -14,10 +14,8 @@ #include <QApplication>

#include <QTimer> #include <QWidget> -extern "C" { -#include "core/interface.h" -#include "util/configuration.h" -} +#include <mgba/core/interface.h> +#include <mgba-util/configuration.h> using namespace QGBA;
M src/platform/qt/InputController.hsrc/platform/qt/InputController.h

@@ -14,13 +14,11 @@ #include <QVector>

class QTimer; -extern "C" { -#include "gba/input.h" +#include <mgba/internal/gba/input.h> #ifdef BUILD_SDL #include "platform/sdl/sdl-events.h" #endif -} struct mRotationSource; struct mRumble;
M src/platform/qt/InputProfile.hsrc/platform/qt/InputProfile.h

@@ -8,9 +8,7 @@ #define QGBA_INPUT_PROFILE

#include "GamepadAxisEvent.h" -extern "C" { -#include "gba/interface.h" -} +#include <mgba/gba/interface.h> namespace QGBA {
M src/platform/qt/LibraryModel.cppsrc/platform/qt/LibraryModel.cpp

@@ -5,9 +5,7 @@ * 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 "LibraryModel.h" -extern "C" { -#include "util/vfs.h" -} +#include <mgba-util/vfs.h> using namespace QGBA;
M src/platform/qt/LibraryModel.hsrc/platform/qt/LibraryModel.h

@@ -8,9 +8,7 @@ #define QGBA_LIBRARY_MODEL

#include <QAbstractItemModel> -extern "C" { -#include "core/library.h" -} +#include <mgba/core/library.h> struct VDir;
M src/platform/qt/LoadSaveState.cppsrc/platform/qt/LoadSaveState.cpp

@@ -14,13 +14,9 @@ #include <QDateTime>

#include <QKeyEvent> #include <QPainter> -extern "C" { -#include "core/serialize.h" -#ifdef M_CORE_GBA -#include "gba/serialize.h" -#endif -#include "util/memory.h" -} +#include <mgba/core/serialize.h> +#include <mgba-util/memory.h> +#include <mgba-util/vfs.h> using namespace QGBA;
M src/platform/qt/LogController.hsrc/platform/qt/LogController.h

@@ -11,10 +11,6 @@

#include <QObject> #include <QStringList> -extern "C" { -#include "gba/gba.h" -} - namespace QGBA { class LogController : public QObject {
M src/platform/qt/MemoryModel.cppsrc/platform/qt/MemoryModel.cpp

@@ -19,9 +19,8 @@ #include <QScrollBar>

#include <QSlider> #include <QWheelEvent> -extern "C" { -#include "core/core.h" -} +#include <mgba/core/core.h> +#include <mgba-util/vfs.h> using namespace QGBA;
M src/platform/qt/MemoryModel.hsrc/platform/qt/MemoryModel.h

@@ -13,9 +13,7 @@ #include <QStaticText>

#include <QVector> #include <memory> -extern "C" { -#include "util/text-codec.h" -} +#include <mgba-util/text-codec.h> struct mCore;
M src/platform/qt/MemoryView.cppsrc/platform/qt/MemoryView.cpp

@@ -8,15 +8,13 @@ #include "MemoryView.h"

#include "GameController.h" -extern "C" { -#include "core/core.h" +#include <mgba/core/core.h> #ifdef M_CORE_GBA -#include "gba/memory.h" +#include <mgba/internal/gba/memory.h> #endif #ifdef M_CORE_GB -#include "gb/memory.h" +#include <mgba/internal/gb/memory.h> #endif -} using namespace QGBA;
M src/platform/qt/MessagePainter.cppsrc/platform/qt/MessagePainter.cpp

@@ -9,9 +9,7 @@ #include <QPainter>

#include <QDebug> -extern "C" { -#include "gba/video.h" -} +#include <mgba/internal/gba/video.h> using namespace QGBA;
M src/platform/qt/MultiplayerController.cppsrc/platform/qt/MultiplayerController.cpp

@@ -7,19 +7,19 @@ #include "MultiplayerController.h"

#include "GameController.h" -extern "C" { #ifdef M_CORE_GBA -#include "gba/gba.h" +#include <mgba/internal/gba/gba.h> +#endif +#ifdef M_CORE_GB +#include <mgba/internal/gb/gb.h> #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<MultiplayerController*>(lockstep->context); Player* player = &controller->m_players[0]; bool woke = false;

@@ -33,7 +33,7 @@ }

controller->m_lock.unlock(); return woke; }; - m_lockstep.wait = [](GBASIOLockstep* lockstep, unsigned mask) { + m_lockstep.wait = [](mLockstep* lockstep, unsigned mask) { MultiplayerController* controller = static_cast<MultiplayerController*>(lockstep->context); controller->m_lock.lock(); Player* player = &controller->m_players[0];

@@ -47,7 +47,7 @@ }

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 @@ controller->m_lock.lock();

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 @@ controller->m_players[id].cyclesPosted += cycles;

} 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<MultiplayerController*>(lockstep->context); controller->m_lock.lock(); Player* player = &controller->m_players[id];

@@ -87,7 +100,7 @@ cycles = player->cyclesPosted;

controller->m_lock.unlock(); return cycles; }; - m_lockstep.unload = [](GBASIOLockstep* lockstep, int id) { + m_lockstep.unload = [](mLockstep* lockstep, int id) { MultiplayerController* controller = static_cast<MultiplayerController*>(lockstep->context); controller->m_lock.lock(); Player* player = &controller->m_players[id];

@@ -102,9 +115,35 @@ } else {

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<GBASIOLockstep*>(lockstep)->players[0]->eventDiff; + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + player->cyclesPosted += reinterpret_cast<GBSIOLockstep*>(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,13 +153,26 @@ controller->m_lock.unlock();

}; } -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();

@@ -128,15 +180,17 @@ if (!thread) {

return false; } + switch (controller->platform()) { #ifdef M_CORE_GBA - if (controller->platform() == PLATFORM_GBA) { + case PLATFORM_GBA: { GBA* gba = static_cast<GBA*>(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 @@ emit gameAttached();

return true; } #endif +#ifdef M_CORE_GB + case PLATFORM_GB: { + GB* gb = static_cast<GB*>(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 @@ }

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<GBA*>(thread->core->board); GBASIOLockstepNode* node = reinterpret_cast<GBASIOLockstepNode*>(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<GB*>(thread->core->board); + GBSIOLockstepNode* node = reinterpret_cast<GBSIOLockstepNode*>(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) {
M src/platform/qt/MultiplayerController.hsrc/platform/qt/MultiplayerController.h

@@ -10,9 +10,13 @@ #include <QMutex>

#include <QList> #include <QObject> -extern "C" { -#include "gba/sio/lockstep.h" -} +#include <mgba/core/lockstep.h> +#ifdef M_CORE_GBA +#include <mgba/internal/gba/sio/lockstep.h> +#endif +#ifdef M_CORE_GB +#include <mgba/internal/gb/sio/lockstep.h> +#endif namespace QGBA {

@@ -23,7 +27,6 @@ Q_OBJECT

public: MultiplayerController(); - ~MultiplayerController(); bool attachGame(GameController*); void detachGame(GameController*);

@@ -38,12 +41,21 @@

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<Player> m_players; QMutex m_lock; };
M src/platform/qt/ObjView.cppsrc/platform/qt/ObjView.cpp

@@ -10,13 +10,11 @@

#include <QFontDatabase> #include <QTimer> -extern "C" { -#include "gba/gba.h" +#include <mgba/internal/gba/gba.h> #ifdef M_CORE_GB -#include "gb/gb.h" -#include "gb/io.h" +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/io.h> #endif -} using namespace QGBA;
M src/platform/qt/ObjView.hsrc/platform/qt/ObjView.h

@@ -11,9 +11,7 @@ #include "GameController.h"

#include "ui_ObjView.h" -extern "C" { -#include "core/tile-cache.h" -} +#include <mgba/core/tile-cache.h> namespace QGBA {
M src/platform/qt/OverrideView.cppsrc/platform/qt/OverrideView.cpp

@@ -12,16 +12,12 @@ #include "GameController.h"

#ifdef M_CORE_GBA #include "GBAOverride.h" -extern "C" { -#include "gba/gba.h" -} +#include <mgba/internal/gba/gba.h> #endif #ifdef M_CORE_GB #include "GBOverride.h" -extern "C" { -#include "gb/gb.h" -} +#include <mgba/internal/gb/gb.h> #endif using namespace QGBA;
M src/platform/qt/OverrideView.hsrc/platform/qt/OverrideView.h

@@ -9,9 +9,7 @@

#include <QDialog> #ifdef M_CORE_GB -extern "C" { -#include "gb/overrides.h" -} +#include <mgba/gb/interface.h> #endif #include "ui_OverrideView.h"
M src/platform/qt/PaletteView.cppsrc/platform/qt/PaletteView.cpp

@@ -12,17 +12,15 @@

#include <QFileDialog> #include <QFontDatabase> -extern "C" { -#include "core/core.h" -#include "util/export.h" -#ifdef M_CORE_GA -#include "gba/gba.h" +#include <mgba/core/core.h> +#ifdef M_CORE_GBA +#include <mgba/internal/gba/gba.h> #endif #ifdef M_CORE_GB -#include "gb/gb.h" +#include <mgba/internal/gb/gb.h> #endif -#include "util/vfs.h" -} +#include <mgba-util/export.h> +#include <mgba-util/vfs.h> using namespace QGBA;
M src/platform/qt/ROMInfo.cppsrc/platform/qt/ROMInfo.cpp

@@ -8,16 +8,14 @@

#include "GBAApp.h" #include "GameController.h" -extern "C" { -#include "core/core.h" +#include <mgba/core/core.h> #ifdef M_CORE_GB -#include "gb/gb.h" +#include <mgba/internal/gb/gb.h> #endif #ifdef M_CORE_GBA -#include "gba/gba.h" +#include <mgba/internal/gba/gba.h> #endif -#include "util/nointro.h" -} +#include <mgba-util/nointro.h> using namespace QGBA;
M src/platform/qt/SensorView.cppsrc/platform/qt/SensorView.cpp

@@ -9,10 +9,8 @@ #include "GameController.h"

#include "GamepadAxisEvent.h" #include "InputController.h" -extern "C" { -#include "core/core.h" -#include "gba/gba.h" -} +#include <mgba/core/core.h> +#include <mgba/internal/gba/gba.h> using namespace QGBA;
M src/platform/qt/SettingsView.cppsrc/platform/qt/SettingsView.cpp

@@ -13,10 +13,8 @@ #include "GBAKeyEditor.h"

#include "InputController.h" #include "ShortcutView.h" -extern "C" { -#include "core/serialize.h" -#include "gba/gba.h" -} +#include <mgba/core/serialize.h> +#include <mgba/internal/gba/gba.h> using namespace QGBA;
M src/platform/qt/ShaderSelector.cppsrc/platform/qt/ShaderSelector.cpp

@@ -17,14 +17,13 @@ #include <QFormLayout>

#include <QGridLayout> #include <QSpinBox> -extern "C" { -#include "core/version.h" +#include <mgba/core/version.h> +#include <mgba-util/vfs.h> #include "platform/video-backend.h" #if !defined(_WIN32) || defined(USE_EPOXY) #include "platform/opengl/gles2.h" #endif -} using namespace QGBA;
M src/platform/qt/Swatch.cppsrc/platform/qt/Swatch.cpp

@@ -8,9 +8,7 @@

#include <QMouseEvent> #include <QPainter> -extern "C" { -#include "core/interface.h" -} +#include <mgba/core/interface.h> using namespace QGBA;
M src/platform/qt/TileView.cppsrc/platform/qt/TileView.cpp

@@ -10,11 +10,9 @@

#include <QFontDatabase> #include <QTimer> -extern "C" { #ifdef M_CORE_GB -#include "gb/gb.h" +#include <mgba/internal/gb/gb.h> #endif -} using namespace QGBA;
M src/platform/qt/TileView.hsrc/platform/qt/TileView.h

@@ -11,9 +11,7 @@ #include "GameController.h"

#include "ui_TileView.h" -extern "C" { -#include "core/tile-cache.h" -} +#include <mgba/core/tile-cache.h> namespace QGBA {
M src/platform/qt/VFileDevice.cppsrc/platform/qt/VFileDevice.cpp

@@ -5,6 +5,8 @@ * 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 "VFileDevice.h" +#include <mgba-util/vfs.h> + using namespace QGBA; VFileDevice::VFileDevice(VFile* vf, QObject* parent)
M src/platform/qt/VFileDevice.hsrc/platform/qt/VFileDevice.h

@@ -8,9 +8,8 @@ #define QGBA_VFILE_DEVICE

#include <QFileDevice> -extern "C" { -#include "util/vfs.h" -} +struct VDir; +struct VFile; namespace QGBA {
M src/platform/qt/VideoView.cppsrc/platform/qt/VideoView.cpp

@@ -12,12 +12,6 @@ #include "LogController.h"

#include <QMap> -#ifdef M_CORE_GB -extern "C" { -#include "gb/video.h" -} -#endif - using namespace QGBA; QMap<QString, QString> VideoView::s_acodecMap;
M src/platform/qt/VideoView.hsrc/platform/qt/VideoView.h

@@ -12,9 +12,7 @@ #include <QWidget>

#include "ui_VideoView.h" -extern "C" { #include "feature/ffmpeg/ffmpeg-encoder.h" -} namespace QGBA {
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -42,15 +42,14 @@ #include "ShortcutController.h"

#include "TileView.h" #include "VideoView.h" -extern "C" { -#include "core/version.h" +#include <mgba/core/version.h> #ifdef M_CORE_GB -#include "gb/gb.h" +#include <mgba/internal/gb/gb.h> +#include <mgba/internal/gb/video.h> #endif #include "feature/commandline.h" -#include "util/nointro.h" -#include "util/vfs.h" -} +#include <mgba-util/nointro.h> +#include <mgba-util/vfs.h> using namespace QGBA;
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -13,10 +13,7 @@ #include <QTimer>

#include <functional> -extern "C" { -#include "core/thread.h" -#include "gba/gba.h" -} +#include <mgba/core/thread.h> #include "InputController.h" #include "LoadSaveState.h"
M src/platform/sdl/gl-common.csrc/platform/sdl/gl-common.c

@@ -5,7 +5,7 @@ * 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 "main.h" -#include "core/version.h" +#include <mgba/core/version.h> void mSDLGLCommonSwap(struct VideoBackend* context) { struct mSDLRenderer* renderer = (struct mSDLRenderer*) context->user;
M src/platform/sdl/gl-common.hsrc/platform/sdl/gl-common.h

@@ -5,9 +5,16 @@ * 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 SDL_GL_COMMON_H #define SDL_GL_COMMON_H + +#include <mgba-util/common.h> + +CXX_GUARD_START + #include "main.h" void mSDLGLCommonSwap(struct VideoBackend* context); void mSDLGLCommonInit(struct mSDLRenderer* renderer); + +CXX_GUARD_END #endif
M src/platform/sdl/gl-sdl.csrc/platform/sdl/gl-sdl.c

@@ -7,8 +7,8 @@ #include "main.h"

#include "gl-common.h" -#include "core/core.h" -#include "core/thread.h" +#include <mgba/core/core.h> +#include <mgba/core/thread.h> #include "platform/opengl/gl.h" static void _doViewport(int w, int h, struct VideoBackend* v) {
M src/platform/sdl/gles2-sdl.csrc/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 "main.h"

#include "gl-common.h" +#include "core/thread.h" + +#ifndef __APPLE__ #include <malloc.h> +#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 @@ #else

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 @@ return true;

} 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 @@ bcm_host_deinit();

#elif SDL_VERSION_ATLEAST(2, 0, 0) SDL_GL_DeleteContext(renderer->glCtx); #endif - free(renderer->d.outputBuffer); + free(renderer->outputBuffer); }
M src/platform/sdl/main.csrc/platform/sdl/main.c

@@ -5,33 +5,23 @@ * 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 "main.h" -#include "debugger/cli-debugger.h" +#include <mgba/internal/debugger/cli-debugger.h> #ifdef USE_GDB_STUB -#include "debugger/gdb-stub.h" +#include <mgba/internal/debugger/gdb-stub.h> #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 <mgba/core/core.h> +#include <mgba/core/config.h> +#include <mgba/core/input.h> +#include <mgba/core/thread.h> +#include <mgba/internal/gba/input.h> + #include "feature/commandline.h" -#include "util/configuration.h" -#include "util/vfs.h" +#include <mgba-util/vfs.h> #include <SDL.h>
M src/platform/sdl/main.hsrc/platform/sdl/main.h

@@ -6,13 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef SDL_MAIN_H #define SDL_MAIN_H -#ifdef M_CORE_GBA -#include "gba/renderers/video-software.h" -#endif +#include <mgba-util/common.h> -#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 @@

#if defined(BUILD_GLES2) || defined(USE_EPOXY) void mSDLGLES2Create(struct mSDLRenderer* renderer); #endif + +CXX_GUARD_END + #endif
M src/platform/sdl/sdl-audio.csrc/platform/sdl/sdl-audio.c

@@ -5,10 +5,12 @@ * 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 "sdl-audio.h" -#include "core/thread.h" -#include "gba/gba.h" +#include <mgba/core/core.h> +#include <mgba/core/thread.h> +#include <mgba/internal/gba/audio.h> +#include <mgba/internal/gba/gba.h> -#include "third-party/blip_buf/blip_buf.h" +#include <mgba/core/blip_buf.h> #define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2)
M src/platform/sdl/sdl-audio.hsrc/platform/sdl/sdl-audio.h

@@ -6,9 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef SDL_AUDIO_H #define SDL_AUDIO_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/log.h" +CXX_GUARD_START + +#include <mgba/core/log.h> #include <SDL.h>

@@ -35,5 +37,7 @@ bool mSDLInitAudio(struct mSDLAudio* context, struct mCoreThread*);

void mSDLDeinitAudio(struct mSDLAudio* context); void mSDLPauseAudio(struct mSDLAudio* context); void mSDLResumeAudio(struct mSDLAudio* context); + +CXX_GUARD_END #endif
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -5,18 +5,15 @@ * 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 "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 <mgba/core/core.h> +#include <mgba/core/input.h> +#include <mgba/core/serialize.h> +#include <mgba/core/thread.h> +#include <mgba/internal/debugger/debugger.h> +#include <mgba/internal/gba/input.h> +#include <mgba-util/configuration.h> +#include <mgba-util/formatting.h> +#include <mgba-util/vfs.h> #if SDL_VERSION_ATLEAST(2, 0, 0) && defined(__APPLE__) #define GUI_MOD KMOD_GUI
M src/platform/sdl/sdl-events.hsrc/platform/sdl/sdl-events.h

@@ -6,12 +6,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef SDL_EVENTS_H #define SDL_EVENTS_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/interface.h" -#include "core/log.h" -#include "util/circle-buffer.h" -#include "util/vector.h" +CXX_GUARD_START + +#include <mgba/core/interface.h> +#include <mgba/core/log.h> +#include <mgba-util/circle-buffer.h> +#include <mgba-util/vector.h> #include <SDL.h>

@@ -109,5 +111,7 @@ void mSDLSuspendScreensaver(struct mSDLEvents*);

void mSDLResumeScreensaver(struct mSDLEvents*); void mSDLSetScreensaverSuspendable(struct mSDLEvents*, bool suspendable); #endif + +CXX_GUARD_END #endif
M src/platform/test/fuzz-main.csrc/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 <mgba/core/blip_buf.h> +#include <mgba/core/cheats.h> +#include <mgba/core/config.h> +#include <mgba/core/core.h> +#include <mgba/core/serialize.h> +#include <mgba/gb/core.h> +#include <mgba/gba/core.h> +#include <mgba/internal/gba/gba.h> #include "feature/commandline.h" -#include "util/memory.h" -#include "util/string.h" -#include "util/vfs.h" +#include <mgba-util/memory.h> +#include <mgba-util/string.h> +#include <mgba-util/vfs.h> #include <errno.h> #include <signal.h>
M src/platform/test/perf-main.csrc/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 <mgba/core/blip_buf.h> +#include <mgba/core/cheats.h> +#include <mgba/core/config.h> +#include <mgba/core/core.h> +#include <mgba/core/serialize.h> +#include <mgba/gb/core.h> +#include <mgba/gba/core.h> #include "feature/commandline.h" -#include "util/socket.h" -#include "util/string.h" -#include "util/vfs.h" +#include <mgba-util/socket.h> +#include <mgba-util/string.h> +#include <mgba-util/vfs.h> #ifdef _3DS #include <3ds.h>
M src/platform/test/tbl-fuzz-main.csrc/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 <mgba-util/text-codec.h> +#include <mgba-util/vfs.h> int main(int argc, char** argv) { struct TextCodec codec;
M src/platform/video-backend.hsrc/platform/video-backend.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef VIDEO_BACKEND_H #define VIDEO_BACKEND_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START #ifdef _WIN32 #include <windows.h>

@@ -43,5 +45,7 @@ void* preprocessShader;

void* passes; size_t nPasses; }; + +CXX_GUARD_END #endif
M src/platform/wii/gui-font.csrc/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 <mgba-util/gui/font.h> +#include <mgba-util/gui/font-metrics.h> #include "icons.h" #include "font.h"
M src/platform/wii/main.csrc/platform/wii/main.c

@@ -12,18 +12,19 @@ #include <malloc.h>

#include <unistd.h> #include <wiiuse/wpad.h> -#include "util/common.h" +#include <mgba-util/common.h> -#include "core/core.h" +#include <mgba/core/blip_buf.h> +#include <mgba/core/core.h> #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 <mgba/internal/gba/audio.h> +#include <mgba/internal/gba/gba.h> +#include <mgba/internal/gba/input.h> +#include <mgba-util/gui.h> +#include <mgba-util/gui/file-select.h> +#include <mgba-util/gui/font.h> +#include <mgba-util/gui/menu.h> +#include <mgba-util/vfs.h> #define GCN1_INPUT 0x47434E31 #define GCN2_INPUT 0x47434E32
M src/platform/wii/wii-memory.csrc/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 <mgba-util/memory.h> void* anonymousMemoryMap(size_t size) { return malloc(size);
M src/platform/windows/memory.csrc/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 <mgba-util/memory.h> #include <windows.h>
M src/platform/windows/threading.hinclude/mgba-util/platform/windows/threading.h

@@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef WINDOWS_THREADING_H #define WINDOWS_THREADING_H -#include "util/common.h" +#include <mgba-util/common.h> #define _WIN32_WINNT 0x0600 #include <windows.h>
M src/platform/windows/vfs-w32.csrc/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 <mgba-util/vfs.h> -#include "util/string.h" +#include <mgba-util/string.h> #include <strsafe.h> static bool _vdwClose(struct VDir* vd);

@@ -63,6 +63,7 @@

vd->vde.d.name = _vdweName; vd->vde.d.type = _vdweType; vd->vde.ffData = ffData; + vd->vde.utf8Name = NULL; return &vd->d; }
M src/third-party/blip_buf/blip_buf.csrc/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 <mgba/core/blip_buf.h> #include <assert.h> #include <limits.h>
M src/third-party/blip_buf/blip_buf.hinclude/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* );
M src/util/circle-buffer.csrc/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 <mgba-util/circle-buffer.h> #ifndef NDEBUG static int _checkIntegrity(struct CircleBuffer* buffer) {
M src/util/circle-buffer.hinclude/mgba-util/circle-buffer.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef CIRCLE_BUFFER_H #define CIRCLE_BUFFER_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct CircleBuffer { void* data;

@@ -29,5 +31,7 @@ int CircleBufferRead16(struct CircleBuffer* buffer, int16_t* value);

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
M src/util/common.hinclude/mgba-util/common.h

@@ -6,6 +6,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#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 <ctype.h> #include <fcntl.h> #include <inttypes.h>

@@ -46,7 +56,9 @@ #ifndef SSIZE_MAX

#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

@@ -176,5 +188,7 @@ #define UNLIKELY(X) (!!(X))

#endif #define ROR(I, ROTATE) ((((uint32_t) (I)) >> ROTATE) | ((uint32_t) (I) << ((-ROTATE) & 31))) + +CXX_GUARD_END #endif
M src/util/configuration.csrc/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 <mgba-util/configuration.h> -#include "util/formatting.h" -#include "util/string.h" -#include "util/vfs.h" +#include <mgba-util/formatting.h> +#include <mgba-util/string.h> +#include <mgba-util/vfs.h> #include "third-party/inih/ini.h"
M src/util/configuration.hinclude/mgba-util/configuration.h

@@ -6,7 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef CONFIGURATION_H #define CONFIGURATION_H -#include "util/table.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba-util/table.h> struct VFile;

@@ -34,5 +38,7 @@ bool ConfigurationWrite(const struct Configuration*, const char* path);

bool ConfigurationWriteSection(const struct Configuration*, const char* path, const char* section); void ConfigurationEnumerateSections(const struct Configuration* configuration, void (*handler)(const char* sectionName, void* user), void* user); + +CXX_GUARD_END #endif
M src/util/crc32.csrc/util/crc32.c

@@ -40,9 +40,9 @@ *

* CRC32 code derived from work by Gary S. Brown. */ -#include "util/crc32.h" +#include <mgba-util/crc32.h> -#include "util/vfs.h" +#include <mgba-util/vfs.h> enum { BUFFER_SIZE = 1024
M src/util/crc32.hinclude/mgba-util/crc32.h

@@ -6,12 +6,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef CRC32_H #define CRC32_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct VFile; 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
M src/util/export.csrc/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 <mgba-util/export.h> -#include "gba/video.h" -#include "util/vfs.h" +#include <mgba/core/interface.h> +#include <mgba-util/vfs.h> bool exportPaletteRIFF(struct VFile* vf, size_t entries, const uint16_t* colors) { if (entries > 0xFFFF) {
M src/util/export.hinclude/mgba-util/export.h

@@ -6,11 +6,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef EXPORT_H #define EXPORT_H -#include "util/common.h" +#include <mgba-util/common.h> + +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
M src/util/formatting.csrc/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 <mgba-util/formatting.h> #include <float.h> #include <time.h>
M src/util/formatting.hinclude/mgba-util/formatting.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef FORMATTING_H #define FORMATTING_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START #include "locale.h"

@@ -28,5 +30,7 @@

#ifndef HAVE_LOCALTIME_R struct tm* localtime_r(const time_t* timep, struct tm* result); #endif + +CXX_GUARD_END #endif
M src/util/gui.csrc/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 <mgba-util/gui.h> void GUIInit(struct GUIParams* params) { memset(params->inputHistory, 0, sizeof(params->inputHistory));
M src/util/gui.hinclude/mgba-util/gui.h

@@ -6,10 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GUI_H #define GUI_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START -#include "core/input.h" -#include "util/vector.h" +// TODO: Fix layering violation +#include <mgba/core/input.h> +#include <mgba-util/vector.h> struct GUIFont;

@@ -80,5 +83,7 @@ void GUIInit(struct GUIParams* params);

void GUIPollInput(struct GUIParams* params, uint32_t* newInput, uint32_t* heldInput); enum GUICursorState GUIPollCursor(struct GUIParams* params, unsigned* x, unsigned* y); void GUIInvalidateKeys(struct GUIParams* params); + +CXX_GUARD_END #endif
M src/util/gui/file-select.csrc/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 <mgba-util/gui/file-select.h> -#include "util/gui/font.h" -#include "util/gui/menu.h" -#include "util/vfs.h" +#include <mgba-util/gui/font.h> +#include <mgba-util/gui/menu.h> +#include <mgba-util/vfs.h> #include <stdlib.h>
M src/util/gui/file-select.hinclude/mgba-util/gui/file-select.h

@@ -6,10 +6,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GUI_FILE_CHOOSER_H #define GUI_FILE_CHOOSER_H -#include "util/gui.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba-util/gui.h> struct VFile; bool GUISelectFile(struct GUIParams*, char* outPath, size_t outLen, bool (*filter)(struct VFile*)); + +CXX_GUARD_END #endif
M src/util/gui/font-metrics.csrc/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 <mgba-util/gui/font.h> const struct GUIFontGlyphMetric defaultFontMetrics[128] = { { 0, 0, { 0, 0, 0, 0 }}, // 0x00
M src/util/gui/font-metrics.hinclude/mgba-util/gui/font-metrics.h

@@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DEFAULT_FONT_METRICS_H #define DEFAULT_FONT_METRICS_H -#include "util/gui/font.h" +#include <mgba-util/gui/font.h> extern struct GUIFontGlyphMetric defaultFontMetrics[]; extern struct GUIIconMetric defaultIconMetrics[];
M src/util/gui/font.csrc/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 <mgba-util/gui/font.h> -#include "util/string.h" +#include <mgba-util/string.h> unsigned GUIFontSpanWidth(const struct GUIFont* font, const char* text) { unsigned width = 0;
M src/util/gui/font.hinclude/mgba-util/gui/font.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GUI_FONT_H #define GUI_FONT_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct GUIFont; struct GUIFont* GUIFontCreate(void);

@@ -83,5 +85,7 @@ void GUIFontPrint(const struct GUIFont*, int x, int y, enum GUIAlignment, uint32_t color, const char* text);

void GUIFontDrawGlyph(const struct GUIFont*, int x, int y, uint32_t color, uint32_t glyph); 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
M src/util/gui/menu.csrc/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 <mgba-util/gui/menu.h> -#include "util/gui.h" -#include "util/gui/font.h" +#include <mgba-util/gui.h> +#include <mgba-util/gui/font.h> #ifdef _3DS #include <3ds.h>
M src/util/gui/menu.hinclude/mgba-util/gui/menu.h

@@ -6,7 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GUI_MENU_H #define GUI_MENU_H -#include "util/vector.h" +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba-util/vector.h> struct GUIMenu; struct GUIMenuItem {

@@ -48,5 +52,7 @@ enum GUIMenuExitReason GUIShowMessageBox(struct GUIParams* params, int buttons, int frames, const char* format, ...);

void GUIDrawBattery(struct GUIParams* params); void GUIDrawClock(struct GUIParams* params); + +CXX_GUARD_END #endif
M src/util/hash.csrc/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 <mgba-util/hash.h> #if defined(_MSC_VER)
M src/util/hash.hinclude/mgba-util/hash.h

@@ -6,8 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef HASH_H #define HASH_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START uint32_t hash32(const void* key, int len, uint32_t seed); + +CXX_GUARD_END #endif
M src/util/math.hinclude/mgba-util/math.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef UTIL_MATH_H #define UTIL_MATH_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START static inline uint32_t popcount32(unsigned bits) { bits = bits - ((bits >> 1) & 0x55555555);

@@ -58,5 +60,7 @@ }

unsigned lz = clz32(bits - 1); return 1 << (32 - lz); } + +CXX_GUARD_END #endif
M src/util/memory.hinclude/mgba-util/memory.h

@@ -6,9 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef MEMORY_H #define MEMORY_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START void* anonymousMemoryMap(size_t size); void mappedMemoryFree(void* memory, size_t size); + +CXX_GUARD_END #endif
M src/util/nointro.csrc/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 <mgba-util/nointro.h> -#include "util/crc32.h" -#include "util/table.h" -#include "util/vector.h" -#include "util/vfs.h" +#include <mgba-util/table.h> +#include <mgba-util/vector.h> +#include <mgba-util/vfs.h> #define KEY_STACK_SIZE 8
M src/util/nointro.hinclude/mgba-util/nointro.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef NOINTRO_H #define NOINTRO_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct NoIntroGame { const char* name;

@@ -25,5 +27,7 @@

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
M src/util/patch-fast.csrc/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 <mgba-util/patch/fast.h> DEFINE_VECTOR(PatchFastExtents, struct PatchFastExtent);
M src/util/patch-fast.hinclude/mgba-util/patch/fast.h

@@ -6,10 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef PATCH_FAST_H #define PATCH_FAST_H -#include "util/common.h" +#include <mgba-util/common.h> -#include "util/patch.h" -#include "util/vector.h" +CXX_GUARD_START + +#include <mgba-util/patch.h> +#include <mgba-util/vector.h> #define PATCH_FAST_EXTENT 256

@@ -30,5 +32,7 @@

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
M src/util/patch-ips.csrc/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 <mgba-util/patch/ips.h> -#include "util/patch.h" -#include "util/vfs.h" +#include <mgba-util/patch.h> +#include <mgba-util/vfs.h> 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);
M src/util/patch-ips.hinclude/mgba-util/patch/ips.h

@@ -6,10 +6,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef PATCH_IPS_H #define PATCH_IPS_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct Patch; bool loadPatchIPS(struct Patch* patch); + +CXX_GUARD_END #endif
M src/util/patch-ups.csrc/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 <mgba-util/patch/ips.h> -#include "util/crc32.h" -#include "util/patch.h" -#include "util/vfs.h" +#include <mgba-util/crc32.h> +#include <mgba-util/patch.h> +#include <mgba-util/vfs.h> enum { IN_CHECKSUM = -12,
M src/util/patch-ups.hinclude/mgba-util/patch/ups.h

@@ -6,10 +6,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef PATCH_UPS_H #define PATCH_UPS_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct Patch; bool loadPatchUPS(struct Patch* patch); + +CXX_GUARD_END #endif
M src/util/patch.csrc/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 <mgba-util/patch.h> -#include "util/patch-ips.h" -#include "util/patch-ups.h" +#include <mgba-util/patch/ips.h> +#include <mgba-util/patch/ups.h> bool loadPatch(struct VFile* vf, struct Patch* patch) { patch->vf = vf;
M src/util/patch.hinclude/mgba-util/patch.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef PATCH_H #define PATCH_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct VFile;

@@ -18,5 +20,7 @@ bool (*applyPatch)(struct Patch* patch, const void* in, size_t inSize, void* out, size_t outSize);

}; bool loadPatch(struct VFile* vf, struct Patch* patch); + +CXX_GUARD_END #endif
M src/util/png-io.csrc/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 <mgba-util/png-io.h> #ifdef USE_PNG -#include "vfs.h" +#include <mgba-util/vfs.h> static void _pngWrite(png_structp png, png_bytep buffer, png_size_t size) { struct VFile* vf = png_get_io_ptr(png);
M src/util/png-io.hinclude/mgba-util/png-io.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef PNG_IO_H #define PNG_IO_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START #ifdef USE_PNG

@@ -36,5 +38,7 @@ bool PNGReadFooter(png_structp png, png_infop end);

void PNGReadClose(png_structp png, png_infop info, png_infop end); #endif + +CXX_GUARD_END #endif
M src/util/ring-fifo.csrc/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 <mgba-util/ring-fifo.h> -#include "util/memory.h" +#include <mgba-util/memory.h> void RingFIFOInit(struct RingFIFO* buffer, size_t capacity) { buffer->data = anonymousMemoryMap(capacity);
M src/util/ring-fifo.hinclude/mgba-util/ring-fifo.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef RING_FIFO_H #define RING_FIFO_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct RingFIFO { void* data;

@@ -21,5 +23,7 @@ size_t RingFIFOCapacity(const struct RingFIFO* buffer);

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
M src/util/socket.hinclude/mgba-util/socket.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef SOCKET_H #define SOCKET_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START #if defined(__cplusplus) && !defined(restrict) #define restrict __restrict__

@@ -315,5 +317,7 @@ }

} return result; } + +CXX_GUARD_END #endif
M src/util/string.csrc/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 <mgba-util/string.h> #include <string.h>
M src/util/string.hinclude/mgba-util/string.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef UTIL_STRING_H #define UTIL_STRING_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START #ifndef HAVE_STRNDUP // This is sometimes a macro

@@ -35,5 +37,7 @@ const char* hex8(const char* line, uint8_t* out);

const char* hex4(const char* line, uint8_t* out); void rtrim(char* string); + +CXX_GUARD_END #endif
M src/util/table.csrc/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 <mgba-util/table.h> -#include "util/hash.h" -#include "util/string.h" +#include <mgba-util/hash.h> +#include <mgba-util/string.h> #define LIST_INITIAL_SIZE 8 #define TABLE_INITIAL_SIZE 8

@@ -161,6 +161,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) {
M src/util/table.hinclude/mgba-util/table.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef TABLE_H #define TABLE_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct TableList;

@@ -29,13 +31,8 @@

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);

@@ -45,5 +42,7 @@ 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
M src/util/test/suite.hsrc/util/test/suite.h

@@ -5,7 +5,7 @@ * 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 SUITE_H #define SUITE_H -#include "util/common.h" +#include <mgba-util/common.h> #include <setjmp.h> #include <cmocka.h>
M src/util/test/text-codec.csrc/util/test/text-codec.c

@@ -5,8 +5,8 @@ * 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/test/suite.h" -#include "util/text-codec.h" -#include "util/vfs.h" +#include <mgba-util/text-codec.h> +#include <mgba-util/vfs.h> M_TEST_DEFINE(emptyCodec) { struct VFile* vf = VFileMemChunk(NULL, 0);
M src/util/test/util.hsrc/util/test/util.h

@@ -5,7 +5,7 @@ * 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 TEST_UTIL_H #define TEST_UTIL_H -#include "util/common.h" +#include <mgba-util/common.h> int TestRunUtil(void);
M src/util/test/vfs.csrc/util/test/vfs.c

@@ -5,7 +5,7 @@ * 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/test/suite.h" -#include "util/vfs.h" +#include <mgba-util/vfs.h> #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 M_TEST_DEFINE(openNullPathR) {
M src/util/text-codec.csrc/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 <mgba-util/text-codec.h> -#include "util/string.h" -#include "util/table.h" -#include "util/vfs.h" +#include <mgba-util/string.h> +#include <mgba-util/table.h> +#include <mgba-util/vfs.h> struct TextCodecNode { uint8_t* leaf;
M src/util/text-codec.hinclude/mgba-util/text-codec.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef TEXT_CODEC_H #define TEXT_CODEC_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START struct TextCodecNode; struct TextCodec {

@@ -28,5 +30,7 @@ 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
M src/util/threading.hinclude/mgba-util/threading.h

@@ -6,17 +6,19 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef THREADING_H #define THREADING_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START #ifndef DISABLE_THREADING #ifdef USE_PTHREADS -#include "platform/posix/threading.h" +#include <mgba-util/platform/posix/threading.h> #elif _WIN32 -#include "platform/windows/threading.h" +#include <mgba-util/platform/windows/threading.h> #elif PSP2 -#include "platform/psp2/threading.h" +#include <mgba-util/platform/psp2/threading.h> #elif _3DS -#include "platform/3ds/threading.h" +#include <mgba-util/platform/3ds/threading.h> #else #define DISABLE_THREADING #endif

@@ -84,5 +86,7 @@ UNUSED(cond);

return 0; } #endif + +CXX_GUARD_END #endif
M src/util/vector.hinclude/mgba-util/vector.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef VECTOR_H #define VECTOR_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START #define DECLARE_VECTOR(NAME, TYPE) \ struct NAME { \

@@ -83,5 +85,7 @@ } \

size_t NAME ## Index(const struct NAME* vector, const TYPE* member) { \ return member - (const TYPE*) vector->vector; \ } \ + +CXX_GUARD_END #endif
M src/util/vfs.csrc/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 <mgba-util/vfs.h> -#include "util/string.h" +#include <mgba-util/string.h> #ifdef PSP2 -#include "platform/psp2/sce-vfs.h" +#include <mgba-util/platform/psp2/sce-vfs.h> #endif #ifdef _3DS -#include "platform/3ds/3ds-vfs.h" +#include <mgba-util/platform/3ds/3ds-vfs.h> #endif struct VFile* VFileOpen(const char* path, int flags) {

@@ -104,7 +104,7 @@ if (!dir) {

dir = VDirOpenZip(path, 0); } #endif -#if USE_LZMA +#ifdef USE_LZMA if (!dir) { dir = VDirOpen7z(path, 0); }
M src/util/vfs.hinclude/mgba-util/vfs.h

@@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef VFS_H #define VFS_H -#include "util/common.h" +#include <mgba-util/common.h> + +CXX_GUARD_START #ifdef _WIN32 #include <io.h>

@@ -65,12 +67,11 @@

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 @@ #ifdef USE_LZMA

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);

@@ -96,5 +101,7 @@ ssize_t VFileWrite32LE(struct VFile* vf, int32_t word);

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
M src/util/vfs/vfs-devlist.csrc/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 <mgba-util/vfs.h> #include <sys/iosupport.h>
M src/util/vfs/vfs-dirent.csrc/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 <mgba-util/vfs.h> -#include "util/string.h" +#include <mgba-util/string.h> #include <dirent.h> #include <sys/stat.h>
M src/util/vfs/vfs-fd.csrc/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 <mgba-util/vfs.h> #include <fcntl.h> #include <sys/stat.h>
M src/util/vfs/vfs-file.csrc/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 <mgba-util/vfs.h> -#include "util/memory.h" +#include <mgba-util/memory.h> #include <errno.h> #include <stdio.h>
M src/util/vfs/vfs-lzma.csrc/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 <mgba-util/vfs.h> #ifdef USE_LZMA -#include "util/string.h" +#include <mgba-util/string.h> #include "third-party/lzma/7z.h" #include "third-party/lzma/7zAlloc.h"
M src/util/vfs/vfs-mem.csrc/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 <mgba-util/vfs.h> +#include <mgba-util/memory.h> struct VFileMem { struct VFile d;
M src/util/vfs/vfs-zip.csrc/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 <mgba-util/vfs.h> -#include "util/string.h" +#include <mgba-util/string.h> #ifdef USE_LIBZIP #include <zip.h>

@@ -41,7 +41,7 @@ #include <minizip/unzip.h>

#else #include "third-party/zlib/contrib/minizip/unzip.h" #endif -#include "util/memory.h" +#include <mgba-util/memory.h> struct VDirEntryZip { struct VDirEntry d;