all repos — mgba @ 73cad3248d55bf5825536d03c4e9889868e3e008

mGBA Game Boy Advance Emulator

Merge branch 'master' (early part) into medusa
Vicki Pfau vi@endrift.com
Fri, 28 Jun 2019 17:04:09 -0700
commit

73cad3248d55bf5825536d03c4e9889868e3e008

parent

3d27d1d7fe6fbce0334a7411eb4f709e2b17c040

70 files changed, 708 insertions(+), 309 deletions(-)

jump to
M .gitignore.gitignore

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

-/build -/build-* *.user* *~ *.swp *.pyc + +/build +/build-* + +*.a +*.dylib +*.dll +*.exe +*.o +*.so +CMakeCache.txt +CMakeFiles +version.c
M CHANGESCHANGES

@@ -21,6 +21,12 @@

0.8.0: (Future) Bugfixes: - GBA: All IRQs have 7 cycle delay (fixes mgba.io/i/539, mgba.io/i/1208) + - GBA: Reset now reloads multiboot ROMs + - GBA BIOS: Fix multiboot entry point (fixes Magic Floor) +Misc: + - GBA Savedata: EEPROM performance fixes + - GBA Savedata: Automatically map 1Mbit Flash files as 1Mbit Flash + - GB Memory: Support running from blocked memory 0.7.0: (Future) Features:

@@ -87,6 +93,8 @@ - GB Audio: Fix channel 4 initial LFSR

- GB, GBA Video: Don't call finishFrame twice in thread proxy - GB Audio: Fix channel 1, 2 and 4 reset timing - Util: Fix wrapping edge cases in RingFIFO + - GBA Hardware: Fix RTC handshake transition (fixes mgba.io/i/1134) + - GBA BIOS: Fix BitUnPack narrowing Misc: - GBA Timer: Use global cycles for timers - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)

@@ -128,9 +136,11 @@ - Libretro: Add Game Boy cheat support

- Qt: Separate fast forward volume control (fixes mgba.io/i/846, mgba.io/i/1143) - Switch: Rumble support - Switch: Rotation support + - Switch: Screen stretching options - Qt: State file load/save menu options - Windows installer - Tile viewer now has adjustable width + - Python: Experimental audio API Bugfixes: - PSP2: Fix audio crackling after fast forward - PSP2: Fix audio crackling when buffer is full

@@ -144,6 +154,18 @@ - Qt: Fix FPS counter on Windows

- GB, GBA Savedata: Fix leaks when loading masked save (fixes mgba.io/i/1197) - Qt: Fix focus issues with load/save state overlay - GB Video: Fix SGB border hole size + - PSP2: Fix tearing issues (fixes mgba.io/i/1211) + - Qt: Fix mapping analog triggers (fixes mgba.io/i/495) + - Qt: Grab focus when game starts (fixes mgba.io/i/804) + - Core: Remember to deinit proxy ring FIFO + - GBA Savedata: Fix EEPROM writing codepath when savetype is not EEPROM + - Core: Reroot timing list when (de)scheduling + - GB Video: Changing LYC while LCDC off doesn't affect STAT (fixes mgba.io/i/1224) + - GBA I/O: SOUNDCNT_HI is readable when sound is off + - SDL: Fix handling of invalid gamepads (fixes mgba.io/i/1239) + - Libretro: Fix adding codes with hooks + - GBA: Fix GB Player features + - Qt: Ensure FATAL logs reach log view Misc: - mGUI: Add SGB border configuration option - mGUI: Add support for different settings types

@@ -156,6 +178,12 @@ - Libretro: Reduce rumble callbacks

- Debugger: Minor text fixes - Qt: Debugger console history - Qt: Detect presence of GL_ARB_framebuffer_object + - Python: Minor API improvements + - Qt: Minor memory view tweaks + - CMake: Fix libswresample version dependencies (fixes mgba.io/i/1229) + - Debugger: Readability improvements (fixes mgba.io/i/1238) + - GB Audio: Skip frame if enabled when clock is high + - Res: Improve modeling of AGB/AGS screen in shaders 0.7 beta 1: (2018-09-24) - Initial beta for 0.7
M CMakeLists.txtCMakeLists.txt

@@ -553,12 +553,7 @@ set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavcodec${LIBAVCODEC_VERSION_MAJOR}|libavcodec-extra-${LIBAVCODEC_VERSION_MAJOR}|libavcodec-ffmpeg${LIBAVCODEC_VERSION_MAJOR}|libavcodec-ffmpeg-extra${LIBAVCODEC_VERSION_MAJOR}")

set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavformat${LIBAVFORMAT_VERSION_MAJOR}|libavformat-ffmpeg${LIBAVFORMAT_VERSION_MAJOR}") if(USE_LIBSWRESAMPLE) string(REGEX MATCH "^[0-9]+" LIBSWRESAMPLE_VERSION_MAJOR ${libswresample_VERSION}) - if(${libswresample_VERSION} EQUAL "3.1.100") - set(LIBSWRESAMPLE_VERSION_DEBIAN 3) - else() - math(EXPR LIBSWRESAMPLE_VERSION_DEBIAN "${LIBSWRESAMPLE_VERSION_MAJOR} - 1") - endif() - set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswresample${LIBSWRESAMPLE_VERSION_DEBIAN}|libswresample-ffmpeg${LIBSWRESAMPLE_VERSION_DEBIAN}") + set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswresample${LIBSWRESAMPLE_VERSION_MAJOR}|libswresample-ffmpeg${LIBSWRESAMPLE_VERSION_MAJOR}") else() string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION}) set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavresample${LIBAVRESAMPLE_VERSION_MAJOR}|libavresample-ffmpeg${LIBAVRESAMPLE_VERSION_MAJOR}")
M README.mdREADME.md

@@ -125,7 +125,31 @@

Compiling --------- -Compiling requires using CMake 2.8.11 or newer. GCC and Clang are both known to work to compile medusa, but Visual Studio 2013 and older are known not to work. Support for Visual Studio 2015 and newer is coming soon. To use CMake to build on a Unix-based system, the recommended commands are as follows: +Compiling requires using CMake 3.1 or newer. GCC and Clang are both known to work to compile medusa, but Visual Studio 2013 and older are known not to work. Support for Visual Studio 2015 and newer is coming soon. + +#### Docker building + +The recommended way to build for most platforms is to use Docker. Several Docker images are provided that contain the requisite toolchain and dependencies for building mGBA across several platforms. + +To use a Docker image to build mGBA, simply run the following command while in the root of an mGBA checkout: + + docker run --rm -t -v $PWD:/home/mgba/src mgba/windows:w32 + +This will produce a `build-win32` directory with the build products. Replace `mgba/windows:w32` with another Docker image for other platforms, which will produce a corresponding other directory. The following Docker images available on Docker Hub: + +- mgba/3ds +- mgba/switch +- mgba/ubuntu:xenial +- mgba/ubuntu:bionic +- mgba/ubuntu:cosmic +- mgba/vita +- mgba/wii +- mgba/windows:w32 +- mgba/windows:w64 + +#### *nix building + +To use CMake to build on a Unix-based system, the recommended commands are as follows: mkdir build cd build

@@ -151,11 +175,11 @@ To build on Windows for development, using MSYS2 is recommended. Follow the installation steps found on their [website](https://msys2.github.io). Make sure you're running the 32-bit version ("MSYS2 MinGW 32-bit") (or the 64-bit version "MSYS2 MinGW 64-bit" if you want to build for x86_64) and run this additional command (including the braces) to install the needed dependencies (please note that this involves downloading over 1100MiB of packages, so it will take a long time):

For x86 (32 bit) builds: - pacman -Sy base-devel git mingw-w64-i686-{cmake,ffmpeg,gcc,gdb,imagemagick,libelf,libepoxy,libzip,pkg-config,qt5,SDL2,ntldd-git} + pacman -Sy --needed base-devel git mingw-w64-i686-{cmake,ffmpeg,gcc,gdb,imagemagick,libelf,libepoxy,libzip,pkg-config,qt5,SDL2,ntldd-git} For x86_64 (64 bit) builds: - pacman -Sy base-devel git mingw-w64-x86_64-{cmake,ffmpeg,gcc,gdb,imagemagick,libelf,libepoxy,libzip,pkg-config,qt5,SDL2,ntldd-git} + pacman -Sy --needed base-devel git mingw-w64-x86_64-{cmake,ffmpeg,gcc,gdb,imagemagick,libelf,libepoxy,libzip,pkg-config,qt5,SDL2,ntldd-git} Check out the source code by running this command:

@@ -170,6 +194,22 @@ cmake .. -G "MSYS Makefiles"

make Please note that this build of medusa for Windows is not suitable for distribution, due to the scattering of DLLs it needs to run, but is perfect for development. However, if distributing such a build is desired (e.g. for testing on machines that don't have the MSYS2 environment installed), running `cpack -G ZIP` will prepare a zip file with all of the necessary DLLs. + +#### Toolchain building + +If you have devkitARM (for 3DS), devkitPPC (for Wii), devkitA64 (for Switch), or vitasdk (for PS Vita), you can use the following commands for building: + + mkdir build + cd build + cmake -DCMAKE_TOOLCHAIN_FILE=../src/platform/3ds/CMakeToolchain.txt .. + make + +Replace the `-DCMAKE_TOOLCHAIN_FILE` parameter for the following platforms: + +- 3DS: `../src/platform/3ds/CMakeToolchain.txt` +- Switch: `../src/platform/switch/CMakeToolchain.txt` +- Vita: `../src/platform/psp2/CMakeToolchain.vitasdk` +- Wii: `../src/platform/wii/CMakeToolchain.txt` ### Dependencies
M README_DE.mdREADME_DE.md

@@ -52,21 +52,18 @@ - MBC7

Die folgenden Mapper werden teilweise unterstützt: +- MBC6 +- MMM01 - Pocket Cam - TAMA5 +- HuC-1 - HuC-3 - -Die folgenden Mapper werden derzeit nicht unterstützt: - -- MBC6 -- HuC-1 -- MMM01 ### Geplante Features - Unterstützung für Link-Kabel-Multiplayer über ein Netzwerk. - Unterstützung für Link-Kabel über Dolphin/JOY-Bus. -- M4A-Audio-Abmischung für höhere Audio-Qualität. +- M4A-Audio-Abmischung für höhere Audio-Qualität als echte Hardware. - Unterstützung für Tool-Assisted Speedruns. - Lua-Unterstützung für Scripting. - Eine umfangreiche Debugging-Suite.

@@ -93,7 +90,7 @@

Downloads --------- -Download-Links befinden sich in der [Downloads][downloads]-Sektion auf der offizielle Website. Der Quellcode befindet sich auf [GitHub][source]. +Download-Links befinden sich in der [Downloads][downloads]-Sektion auf der offiziellen Website. Der Quellcode befindet sich auf [GitHub][source]. Steuerung ---------

@@ -110,7 +107,31 @@

Kompilieren ----------- -Um mGBA kompilieren zu können, wird CMake 2.8.11 oder neuer benötigt. GCC und Clang sind beide dafür bekannt, mGBA kompilieren zu können. Visual Studio 2013 und älter funktionieren nicht. Unterstützung für Visual Studio 2015 und neuer wird bald hinzugefügt. Um CMake auf einem Unix-basierten System zu verwenden, werden folgende Kommandos empfohlen: +Um mGBA kompilieren zu können, wird CMake 3.1 oder neuer benötigt. GCC und Clang sind beide dafür bekannt, mGBA kompilieren zu können. Visual Studio 2013 und älter funktionieren nicht. Unterstützung für Visual Studio 2015 und neuer wird bald hinzugefügt. + +#### Kompilieren mit Docker + +Der empfohlene Weg, um mGBA für die meisten Plattformen zu kompilieren, ist Docker. Mehrere Docker-Images sind verfügbar, welche die benötigte Compiler-Umgebung und alle benötigten Abhängigkeiten beinhaltet, um mGBA für verschiedene Plattformen zu bauen. + +Um ein Docker-Image zum Bau von mGBA zu verwenden, führe einfach folgenden Befehl in dem Verzeichnis aus, in welches Du den mGBA-Quellcode ausgecheckt hast: + + docker run --rm -t -v $PWD:/home/mgba/src mgba/windows:w32 + +Dieser Befehl erzeugt ein Verzeichnis `build-win32` mit den erzeugten Programmdateien. Ersetze `mgba/windows:32` durch ein Docker-Image für eine andere Plattform, wodurch dann das entsprechende Verzeichnis erzeugt wird. Die folgenden Docker-Images sind im Docker Hub verfügbar: + +- mgba/3ds +- mgba/switch +- mgba/ubuntu:xenial +- mgba/ubuntu:bionic +- mgba/ubuntu:cosmic +- mgba/vita +- mgba/wii +- mgba/windows:w32 +- mgba/windows:w64 + +#### Unter *nix kompilieren + +Verwende folgende Befehle, um mGBA mithilfe von CMake auf einem Unix-basierten System zu bauen: mkdir build cd build

@@ -118,9 +139,9 @@ cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..

make sudo make install -Damit wird mGBA gebaut und in `/usr/bin` und `/usr/lib` installiert. Installierte Abhängigkeiten werden automatisch erkannt. Features, die aufgrund fehlender Abhängigkeiten deaktiviert werden, werden nach dem `cmake`-Kommando aufgelistet. +Damit wird mGBA gebaut und in `/usr/bin` und `/usr/lib` installiert. Installierte Abhängigkeiten werden automatisch erkannt. Features, die aufgrund fehlender Abhängigkeiten deaktiviert wurden, werden nach dem `cmake`-Kommando angezeigt. -Wenn Du macOS verwendest, sind die einzelnen Schritte etwas anders. Angenommen, dass Du eine Homebrew-Paketverwaltung verwendest, werden folgende Schritte zum installieren der Abhängigkeiten und anschließenden bauen von mGBA empfohlen: +Wenn Du macOS verwendest, sind die einzelnen Schritte etwas anders. Angenommen, dass Du den Homebrew-Paketmanager verwendest, werden folgende Schritte zum installieren der Abhängigkeiten und anschließenden bauen von mGBA empfohlen: brew install cmake ffmpeg imagemagick libzip qt5 sdl2 libedit pkg-config mkdir build

@@ -136,11 +157,11 @@ Um mGBA auf Windows zu kompilieren, wird MSYS2 empfohlen. Befolge die Installationsschritte auf der [MSYS2-Website](https://msys2.github.io). Stelle sicher, dass Du die 32-Bit-Version ("MSYS2 MinGW 32-bit") (oder die 64-Bit-Version "MSYS2 MinGW 64-bit", wenn Du mGBA für x86_64 kompilieren willst) verwendest und führe folgendes Kommando (einschließlich der Klammern) aus, um alle benötigten Abhängigkeiten zu installieren. Bitte beachte, dass dafür über 1100MiB an Paketen heruntergeladen werden, was eine Weile dauern kann:

Für x86 (32 Bit): - pacman -Sy base-devel git mingw-w64-i686-{cmake,ffmpeg,gcc,gdb,imagemagick,libelf,libepoxy,libzip,pkg-config,qt5,SDL2,ntldd-git} + pacman -Sy --needed base-devel git mingw-w64-i686-{cmake,ffmpeg,gcc,gdb,imagemagick,libelf,libepoxy,libzip,pkg-config,qt5,SDL2,ntldd-git} Für x86_64 (64 Bit): - pacman -Sy base-devel git mingw-w64-x86_64-{cmake,ffmpeg,gcc,gdb,imagemagick,libelf,libepoxy,libzip,pkg-config,qt5,SDL2,ntldd-git} + pacman -Sy --needed base-devel git mingw-w64-x86_64-{cmake,ffmpeg,gcc,gdb,imagemagick,libelf,libepoxy,libzip,pkg-config,qt5,SDL2,ntldd-git} Lade den aktuellen mGBA-Quellcode mithilfe des folgenden Kommandos herunter:

@@ -154,7 +175,23 @@ cd build

cmake .. -G "MSYS Makefiles" make -Bitte beachte, dass mGBA für Windows aufgrund der Vielzahl an benötigten DLLs nicht für die weitere Verteilung geeignet ist, wenn es auf diese Weise gebaut wurde. Es ist jedoch perfekt für Entwickler geeignet. Soll mGBA dennoch weiter verteilt werden (beispielsweise zu Testzwecken auf Systemen, auf denen keine MSYS2-Umgebung installiert ist), kann mithilfe des Befehls 'cpack -G ZIP' ein ZIP-Archiv mit allen benötigten DLLs erstellt werden. +Bitte beachte, dass mGBA für Windows aufgrund der Vielzahl an benötigten DLLs nicht für die weitere Verteilung geeignet ist, wenn es auf diese Weise gebaut wurde. Es ist jedoch perfekt für Entwickler geeignet. Soll mGBA dennoch weiter verteilt werden (beispielsweise zu Testzwecken auf Systemen, auf denen keine MSYS2-Umgebung installiert ist), kann mithilfe des Befehls `cpack -G ZIP` ein ZIP-Archiv mit allen benötigten DLLs erstellt werden. + +#### Kompilieren mithilfe einer Toolchain + +Wenn Du devkitARM (für 3DS), devkitPPC (für Wii), devkitA64 (für Switch) oder vitasdk (für PS Vita) installiert hast, kannst Du die folgenden Befehle zum Kompilieren verwenden: + + mkdir build + cd build + cmake -DCMAKE_TOOLCHAIN_FILE=../src/platform/3ds/CMakeToolchain.txt .. + make + +Ersetze den Parameter `-DCMAKE_TOOLCHAIN_FILE` dabei folgendermaßen: + +- 3DS: `../src/platform/3ds/CMakeToolchain.txt` +- Switch: `../src/platform/switch/CMakeToolchain.txt` +- Vita: `../src/platform/psp2/CMakeToolchain.vitasdk` +- Wii: `../src/platform/wii/CMakeToolchain.txt` ### Abhängigkeiten
M include/mgba/core/core.hinclude/mgba/core/core.h

@@ -47,6 +47,7 @@ struct mVideoLogContext;

struct mCore { void* cpu; void* board; + struct mTiming* timing; struct mDebugger* debugger; struct mDebuggerSymbols* symbolTable;
M include/mgba/internal/arm/isa-inlines.hinclude/mgba/internal/arm/isa-inlines.h

@@ -55,21 +55,23 @@

#define ARM_STUB cpu->irqh.hitStub(cpu, opcode) #define ARM_ILL cpu->irqh.hitIllegal(cpu, opcode) -#define ARM_WRITE_PC \ - cpu->gprs[ARM_PC] = (cpu->gprs[ARM_PC] & -WORD_SIZE_ARM); \ - cpu->memory.setActiveRegion(cpu, cpu->gprs[ARM_PC]); \ - LOAD_32(cpu->prefetch[0], cpu->gprs[ARM_PC] & cpu->memory.activeMask, cpu->memory.activeRegion); \ - cpu->gprs[ARM_PC] += WORD_SIZE_ARM; \ - LOAD_32(cpu->prefetch[1], cpu->gprs[ARM_PC] & cpu->memory.activeMask, cpu->memory.activeRegion); \ - currentCycles += 2 + cpu->memory.activeNonseqCycles32 + cpu->memory.activeSeqCycles32; +static inline int32_t ARMWritePC(struct ARMCore* cpu) { + cpu->gprs[ARM_PC] = (cpu->gprs[ARM_PC] & -WORD_SIZE_ARM); + cpu->memory.setActiveRegion(cpu, cpu->gprs[ARM_PC]); + LOAD_32(cpu->prefetch[0], cpu->gprs[ARM_PC] & cpu->memory.activeMask, cpu->memory.activeRegion); + cpu->gprs[ARM_PC] += WORD_SIZE_ARM; + LOAD_32(cpu->prefetch[1], cpu->gprs[ARM_PC] & cpu->memory.activeMask, cpu->memory.activeRegion); + return 2 + cpu->memory.activeNonseqCycles32 + cpu->memory.activeSeqCycles32; +} -#define THUMB_WRITE_PC \ - cpu->gprs[ARM_PC] = (cpu->gprs[ARM_PC] & -WORD_SIZE_THUMB); \ - cpu->memory.setActiveRegion(cpu, cpu->gprs[ARM_PC]); \ - LOAD_16(cpu->prefetch[0], cpu->gprs[ARM_PC] & cpu->memory.activeMask, cpu->memory.activeRegion); \ - cpu->gprs[ARM_PC] += WORD_SIZE_THUMB; \ - LOAD_16(cpu->prefetch[1], cpu->gprs[ARM_PC] & cpu->memory.activeMask, cpu->memory.activeRegion); \ - currentCycles += 2 + cpu->memory.activeNonseqCycles16 + cpu->memory.activeSeqCycles16; +static inline int32_t ThumbWritePC(struct ARMCore* cpu) { + cpu->gprs[ARM_PC] = (cpu->gprs[ARM_PC] & -WORD_SIZE_THUMB); + cpu->memory.setActiveRegion(cpu, cpu->gprs[ARM_PC]); + LOAD_16(cpu->prefetch[0], cpu->gprs[ARM_PC] & cpu->memory.activeMask, cpu->memory.activeRegion); + cpu->gprs[ARM_PC] += WORD_SIZE_THUMB; + LOAD_16(cpu->prefetch[1], cpu->gprs[ARM_PC] & cpu->memory.activeMask, cpu->memory.activeRegion); + return 2 + cpu->memory.activeNonseqCycles16 + cpu->memory.activeSeqCycles16; +} static inline int _ARMModeHasSPSR(enum PrivilegeMode mode) { return mode != MODE_SYSTEM && mode != MODE_USER;
M include/mgba/internal/gb/audio.hinclude/mgba/internal/gb/audio.h

@@ -187,6 +187,7 @@ bool playingCh4;

uint8_t* nr52; int frame; + bool skipFrame; int32_t sampleInterval; enum GBAudioStyle style;
M include/mgba/internal/gb/serialize.hinclude/mgba/internal/gb/serialize.h

@@ -195,6 +195,7 @@ DECL_BITS(GBSerializedAudioFlags, Frame, 22, 3);

DECL_BIT(GBSerializedAudioFlags, Ch1SweepEnabled, 25); DECL_BIT(GBSerializedAudioFlags, Ch1SweepOccurred, 26); DECL_BIT(GBSerializedAudioFlags, Ch3Readable, 27); +DECL_BIT(GBSerializedAudioFlags, SkipFrame, 28); DECL_BITFIELD(GBSerializedAudioEnvelope, uint32_t); DECL_BITS(GBSerializedAudioEnvelope, Length, 0, 7);
M include/mgba/internal/gba/savedata.hinclude/mgba/internal/gba/savedata.h

@@ -23,7 +23,8 @@ SAVEDATA_FORCE_NONE = 0,

SAVEDATA_SRAM = 1, SAVEDATA_FLASH512 = 2, SAVEDATA_FLASH1M = 3, - SAVEDATA_EEPROM = 4 + SAVEDATA_EEPROM = 4, + SAVEDATA_EEPROM512 = 5 }; enum SavedataCommand {
M res/shaders/agb001.shader/agb001.fsres/shaders/agb001.shader/agb001.fs

@@ -4,18 +4,17 @@ uniform vec2 texSize;

void main() { vec4 color = texture2D(tex, texCoord); - vec3 arrayX[4]; - arrayX[0] = vec3(1.0, 0.2, 0.2); + vec3 arrayX[3]; + arrayX[0] = vec3(0.2, 0.2, 1.0); arrayX[1] = vec3(0.2, 1.0, 0.2); - arrayX[2] = vec3(0.2, 0.2, 1.0); - arrayX[3] = vec3(0.4, 0.4, 0.4); + arrayX[2] = vec3(1.0, 0.2, 0.2); vec3 arrayY[4]; arrayY[0] = vec3(1.0, 1.0, 1.0); arrayY[1] = vec3(1.0, 1.0, 1.0); arrayY[2] = vec3(1.0, 1.0, 1.0); arrayY[3] = vec3(0.8, 0.8, 0.8); color.rgb = pow(color.rgb * vec3(0.8, 0.8, 0.8), vec3(1.8, 1.8, 1.8)) + vec3(0.16, 0.16, 0.16); - color.rgb *= arrayX[int(mod(texCoord.s * texSize.x * 4.0, 4.0))]; + color.rgb *= arrayX[int(mod(texCoord.s * texSize.x * 3.0, 3.0))]; color.rgb *= arrayY[int(mod(texCoord.t * texSize.y * 4.0, 4.0))]; color.a = 0.5; gl_FragColor = color;
M res/shaders/agb001.shader/manifest.inires/shaders/agb001.shader/manifest.ini

@@ -7,5 +7,5 @@

[pass.0] fragmentShader=agb001.fs blend=1 -width=-4 +width=-3 height=-4
M res/shaders/ags001.shader/ags001.fsres/shaders/ags001.shader/ags001.fs

@@ -4,18 +4,17 @@ uniform vec2 texSize;

void main() { vec4 color = texture2D(tex, texCoord); - vec3 arrayX[4]; - arrayX[0] = vec3(1.0, 0.2, 0.2); + vec3 arrayX[3]; + arrayX[0] = vec3(0.2, 0.2, 1.0); arrayX[1] = vec3(0.2, 1.0, 0.2); - arrayX[2] = vec3(0.2, 0.2, 1.0); - arrayX[3] = vec3(0.4, 0.4, 0.4); + arrayX[2] = vec3(1.0, 0.2, 0.2); vec3 arrayY[4]; arrayY[0] = vec3(1.0, 1.0, 1.0); arrayY[1] = vec3(1.0, 1.0, 1.0); arrayY[2] = vec3(1.0, 1.0, 1.0); arrayY[3] = vec3(0.9, 0.9, 0.9); color.rgb = pow(color.rgb, vec3(1.6, 1.6, 1.6)); - color.rgb *= arrayX[int(mod(texCoord.s * texSize.x * 4.0, 4.0))]; + color.rgb *= arrayX[int(mod(texCoord.s * texSize.x * 3.0, 3.0))]; color.rgb *= arrayY[int(mod(texCoord.t * texSize.y * 4.0, 4.0))]; color.a = 0.8; gl_FragColor = color;
M res/shaders/ags001.shader/manifest.inires/shaders/ags001.shader/manifest.ini

@@ -7,12 +7,12 @@

[pass.0] fragmentShader=ags001.fs blend=1 -width=-4 +width=-3 height=-4 [pass.1] fragmentShader=ags001-light.fs -width=-4 +width=-3 height=-4 [pass.1.uniform.lightBrightness]
M src/arm/arm.csrc/arm/arm.c

@@ -140,9 +140,7 @@ cpu->shifterCarryOut = 0;

cpu->executionMode = MODE_THUMB; _ARMSetMode(cpu, MODE_ARM); - - int currentCycles = 0; - ARM_WRITE_PC; + ARMWritePC(cpu); cpu->cycles = 0; cpu->nextEvent = 0;

@@ -169,12 +167,10 @@ cpu->gprs[ARM_PC] = BASE_IRQ;

if (ARMControlRegIsVE(cpu->cp15.r1.c0)) { cpu->gprs[ARM_PC] |= 0xFFFF0000; } - int currentCycles = 0; - ARM_WRITE_PC; _ARMSetMode(cpu, MODE_ARM); + cpu->cycles += ARMWritePC(cpu); cpu->spsr = cpsr; cpu->cpsr.i = 1; - cpu->cycles += currentCycles; cpu->halted = 0; }

@@ -193,12 +189,10 @@ cpu->gprs[ARM_PC] = BASE_SWI;

if (ARMControlRegIsVE(cpu->cp15.r1.c0)) { cpu->gprs[ARM_PC] |= 0xFFFF0000; } - int currentCycles = 0; - ARM_WRITE_PC; _ARMSetMode(cpu, MODE_ARM); + cpu->cycles += ARMWritePC(cpu); cpu->spsr = cpsr; cpu->cpsr.i = 1; - cpu->cycles += currentCycles; } void ARMRaiseUndefined(struct ARMCore* cpu) {

@@ -216,12 +210,10 @@ cpu->gprs[ARM_PC] = BASE_UNDEF;

if (ARMControlRegIsVE(cpu->cp15.r1.c0)) { cpu->gprs[ARM_PC] |= 0xFFFF0000; } - int currentCycles = 0; - ARM_WRITE_PC; _ARMSetMode(cpu, MODE_ARM); + cpu->cycles += ARMWritePC(cpu); cpu->spsr = cpsr; cpu->cpsr.i = 1; - cpu->cycles += currentCycles; } void ARMHalt(struct ARMCore* cpu) {
M src/arm/debugger/cli-debugger.csrc/arm/debugger/cli-debugger.c

@@ -125,13 +125,14 @@ static void _printStatus(struct CLIDebuggerSystem* debugger) {

struct CLIDebuggerBackend* be = debugger->p->backend; struct ARMCore* cpu = debugger->p->d.core->cpu; int r; - for (r = 0; r < 4; ++r) { - be->printf(be, "%08X %08X %08X %08X\n", - cpu->gprs[r << 2], - cpu->gprs[(r << 2) + 1], - cpu->gprs[(r << 2) + 2], - cpu->gprs[(r << 2) + 3]); + for (r = 0; r < 16; r += 4) { + be->printf(be, "%sr%i: %08X %sr%i: %08X %sr%i: %08X %sr%i: %08X\n", + r < 10 ? " " : "", r, cpu->gprs[r], + r < 9 ? " " : "", r + 1, cpu->gprs[r + 1], + r < 8 ? " " : "", r + 2, cpu->gprs[r + 2], + r < 7 ? " " : "", r + 3, cpu->gprs[r + 3]); } + be->printf(be, "cpsr: "); _printPSR(be, cpu->cpsr); int instructionLength; enum ExecutionMode mode = cpu->cpsr.t;
M src/arm/debugger/debugger.csrc/arm/debugger/debugger.c

@@ -347,11 +347,10 @@ return true;

} if (strcmp(name, "pc") == 0) { cpu->gprs[ARM_PC] = value; - int32_t currentCycles = 0; if (cpu->executionMode == MODE_ARM) { - ARM_WRITE_PC; + ARMWritePC(cpu); } else { - THUMB_WRITE_PC; + ThumbWritePC(cpu); } return true; }

@@ -363,11 +362,10 @@ return false;

} cpu->gprs[reg] = value; if (reg == ARM_PC) { - int32_t currentCycles = 0; if (cpu->executionMode == MODE_ARM) { - ARM_WRITE_PC; + ARMWritePC(cpu); } else { - THUMB_WRITE_PC; + ThumbWritePC(cpu); } } return true;
M src/arm/isa-arm.csrc/arm/isa-arm.c

@@ -254,7 +254,7 @@ #define ADDR_MODE_2_INDEX(U_OP, M) (cpu->gprs[rn] U_OP M)

#define ADDR_MODE_2_WRITEBACK(ADDR) \ cpu->gprs[rn] = ADDR; \ if (UNLIKELY(rn == ARM_PC)) { \ - ARM_WRITE_PC; \ + currentCycles += ARMWritePC(cpu); \ } #define ADDR_MODE_2_LSL (cpu->gprs[rm] << ADDR_MODE_2_I)

@@ -285,7 +285,7 @@

#define ARM_LOAD_POST_BODY \ currentCycles += cpu->memory.activeNonseqCycles32 - cpu->memory.activeSeqCycles32; \ if (rd == ARM_PC) { \ - ARM_WRITE_PC; \ + currentCycles += ARMWritePC(cpu); \ } #define ARM_LOAD_POST_BODY_v5 \

@@ -294,9 +294,9 @@ if (rd == ARM_PC) { \

_ARMSetMode(cpu, cpu->gprs[ARM_PC] & 0x00000001); \ cpu->gprs[ARM_PC] &= 0xFFFFFFFE; \ if (cpu->executionMode == MODE_THUMB) { \ - THUMB_WRITE_PC; \ + currentCycles += ThumbWritePC(cpu); \ } else { \ - ARM_WRITE_PC; \ + currentCycles += ARMWritePC(cpu); \ } \ }

@@ -320,9 +320,9 @@ BODY; \

S_BODY; \ if (rd == ARM_PC) { \ if (cpu->executionMode == MODE_ARM) { \ - ARM_WRITE_PC; \ + currentCycles += ARMWritePC(cpu); \ } else { \ - THUMB_WRITE_PC; \ + currentCycles += ThumbWritePC(cpu); \ } \ })

@@ -682,7 +682,7 @@ DEFINE_LOAD_STORE_MULTIPLE_INSTRUCTION_ARM(LDM,

load, currentCycles += cpu->memory.activeNonseqCycles32 - cpu->memory.activeSeqCycles32; if (rs & 0x8000) { - ARM_WRITE_PC; + currentCycles += ARMWritePC(cpu); }) DEFINE_LOAD_STORE_MULTIPLE_INSTRUCTION_ARM_NO_S(LDMv5,

@@ -692,9 +692,9 @@ if (rs & 0x8000) {

_ARMSetMode(cpu, cpu->gprs[ARM_PC] & 0x00000001); cpu->gprs[ARM_PC] &= 0xFFFFFFFE; if (cpu->executionMode == MODE_THUMB) { - THUMB_WRITE_PC; + currentCycles += ThumbWritePC(cpu); } else { - ARM_WRITE_PC; + currentCycles += ARMWritePC(cpu); } })

@@ -727,22 +727,22 @@ DEFINE_INSTRUCTION_ARM(B,

int32_t offset = opcode << 8; offset >>= 6; cpu->gprs[ARM_PC] += offset; - ARM_WRITE_PC;) + currentCycles += ARMWritePC(cpu);) DEFINE_INSTRUCTION_ARM(BL, int32_t immediate = (opcode & 0x00FFFFFF) << 8; cpu->gprs[ARM_LR] = cpu->gprs[ARM_PC] - WORD_SIZE_ARM; cpu->gprs[ARM_PC] += immediate >> 6; - ARM_WRITE_PC;) + currentCycles += ARMWritePC(cpu);) DEFINE_INSTRUCTION_ARM(BX, int rm = opcode & 0x0000000F; _ARMSetMode(cpu, cpu->gprs[rm] & 0x00000001); cpu->gprs[ARM_PC] = cpu->gprs[rm] & 0xFFFFFFFE; if (cpu->executionMode == MODE_THUMB) { - THUMB_WRITE_PC; + currentCycles += ThumbWritePC(cpu); } else { - ARM_WRITE_PC; + currentCycles += ARMWritePC(cpu); })

@@ -751,7 +751,7 @@ int32_t immediate = (opcode & 0x00FFFFFF) << 8;

cpu->gprs[ARM_LR] = cpu->gprs[ARM_PC] - WORD_SIZE_ARM; cpu->gprs[ARM_PC] += (immediate >> 6) + ((opcode >> 23) & 2); _ARMSetMode(cpu, MODE_THUMB); - THUMB_WRITE_PC;) + currentCycles += ThumbWritePC(cpu);) DEFINE_INSTRUCTION_ARM(BLX2, int rm = opcode & 0x0000000F;

@@ -760,9 +760,9 @@ cpu->gprs[ARM_LR] = cpu->gprs[ARM_PC] - WORD_SIZE_ARM;

_ARMSetMode(cpu, address & 0x00000001); cpu->gprs[ARM_PC] = address & 0xFFFFFFFE; if (cpu->executionMode == MODE_THUMB) { - THUMB_WRITE_PC; + currentCycles += ThumbWritePC(cpu); } else { - ARM_WRITE_PC; + currentCycles += ARMWritePC(cpu); }) // End branch definitions
M src/arm/isa-thumb.csrc/arm/isa-thumb.c

@@ -238,14 +238,14 @@

DEFINE_INSTRUCTION_WITH_HIGH_THUMB(ADD4, cpu->gprs[rd] += cpu->gprs[rm]; if (rd == ARM_PC) { - THUMB_WRITE_PC; + currentCycles += ThumbWritePC(cpu); }) DEFINE_INSTRUCTION_WITH_HIGH_THUMB(CMP3, int32_t aluOut = cpu->gprs[rd] - cpu->gprs[rm]; THUMB_SUBTRACTION_S(cpu->gprs[rd], cpu->gprs[rm], aluOut)) DEFINE_INSTRUCTION_WITH_HIGH_THUMB(MOV3, cpu->gprs[rd] = cpu->gprs[rm]; if (rd == ARM_PC) { - THUMB_WRITE_PC; + currentCycles += ThumbWritePC(cpu); }) #define DEFINE_IMMEDIATE_WITH_REGISTER_THUMB(NAME, BODY) \

@@ -310,7 +310,7 @@ DEFINE_INSTRUCTION_THUMB(B ## COND, \

if (ARM_COND_ ## COND) { \ int8_t immediate = opcode; \ cpu->gprs[ARM_PC] += (int32_t) immediate << 1; \ - THUMB_WRITE_PC; \ + currentCycles += ThumbWritePC(cpu); \ }) DEFINE_CONDITIONAL_BRANCH_THUMB(EQ)

@@ -346,7 +346,7 @@ IA,

rs |= 1 << ARM_PC, THUMB_LOAD_POST_BODY; cpu->gprs[ARM_SP] = address; - THUMB_WRITE_PC;) + currentCycles += ThumbWritePC(cpu);) DEFINE_LOAD_STORE_MULTIPLE_THUMB(POPR, ARM_SP,

@@ -358,9 +358,9 @@ cpu->gprs[ARM_SP] = address;

_ARMSetMode(cpu, cpu->gprs[ARM_PC] & 0x00000001); cpu->gprs[ARM_PC] &= 0xFFFFFFFE; if (cpu->executionMode == MODE_THUMB) { - THUMB_WRITE_PC; + currentCycles += ThumbWritePC(cpu); } else { - ARM_WRITE_PC; + currentCycles += ARMWritePC(cpu); })

@@ -385,7 +385,7 @@ DEFINE_INSTRUCTION_THUMB(BKPT, cpu->irqh.bkpt16(cpu, opcode & 0xFF);)

DEFINE_INSTRUCTION_THUMB(B, int16_t immediate = (opcode & 0x07FF) << 5; cpu->gprs[ARM_PC] += (((int32_t) immediate) >> 4); - THUMB_WRITE_PC;) + currentCycles += ThumbWritePC(cpu);) DEFINE_INSTRUCTION_THUMB(BL1, int16_t immediate = (opcode & 0x07FF) << 5;

@@ -396,7 +396,7 @@ uint16_t immediate = (opcode & 0x07FF) << 1;

uint32_t pc = cpu->gprs[ARM_PC]; cpu->gprs[ARM_PC] = cpu->gprs[ARM_LR] + immediate; cpu->gprs[ARM_LR] = pc - 1; - THUMB_WRITE_PC;) + currentCycles += ThumbWritePC(cpu);) DEFINE_INSTRUCTION_THUMB(BLX1, uint16_t immediate = (opcode & 0x07FF) << 1;

@@ -404,7 +404,7 @@ uint32_t pc = cpu->gprs[ARM_PC];

cpu->gprs[ARM_PC] = (cpu->gprs[ARM_LR] + immediate) & 0xFFFFFFFC; cpu->gprs[ARM_LR] = pc - 1; _ARMSetMode(cpu, MODE_ARM); - ARM_WRITE_PC;) + currentCycles += ARMWritePC(cpu);) DEFINE_INSTRUCTION_THUMB(BX, int rm = (opcode >> 3) & 0xF;

@@ -415,9 +415,9 @@ misalign = cpu->gprs[rm] & 0x00000002;

} cpu->gprs[ARM_PC] = (cpu->gprs[rm] & 0xFFFFFFFE) - misalign; if (cpu->executionMode == MODE_THUMB) { - THUMB_WRITE_PC; + currentCycles += ThumbWritePC(cpu); } else { - ARM_WRITE_PC; + currentCycles += ARMWritePC(cpu); }) DEFINE_INSTRUCTION_THUMB(BLX2,

@@ -431,9 +431,9 @@ }

cpu->gprs[ARM_LR] = cpu->gprs[ARM_PC] - 1; cpu->gprs[ARM_PC] = (address & 0xFFFFFFFE) - misalign; if (cpu->executionMode == MODE_THUMB) { - THUMB_WRITE_PC; + currentCycles += ThumbWritePC(cpu); } else { - ARM_WRITE_PC; + currentCycles += ARMWritePC(cpu); }) DEFINE_INSTRUCTION_THUMB(SWI, cpu->irqh.swi16(cpu, opcode & 0xFF))
M src/core/log.csrc/core/log.c

@@ -128,13 +128,13 @@ }

} bool mLogFilterTest(struct mLogFilter* filter, int category, enum mLogLevel level) { - int value = (int) TableLookup(&filter->levels, category); + int value = (intptr_t) TableLookup(&filter->levels, category); if (value) { return value & level; } const char* cat = mLogCategoryId(category); if (cat) { - value = (int) HashTableLookup(&filter->categories, cat); + value = (intptr_t) HashTableLookup(&filter->categories, cat); if (value) { TableInsert(&filter->levels, category, (void*)(intptr_t) value); return value & level;
M src/core/tile-cache.csrc/core/tile-cache.c

@@ -198,7 +198,7 @@ #ifndef NDEBUG

if (tileId >= tiles) { abort(); } - if (paletteId >= 1 << mTileCacheSystemInfoGetPaletteCount(cache->sysConfig)) { + if (paletteId >= 1U << mTileCacheSystemInfoGetPaletteCount(cache->sysConfig)) { abort(); } #endif
M src/core/timing.csrc/core/timing.c

@@ -28,6 +28,10 @@ event->when = nextEvent + timing->masterCycles;

if (nextEvent < *timing->nextEvent) { *timing->nextEvent = nextEvent; } + if (timing->reroot) { + timing->root = timing->reroot; + timing->reroot = NULL; + } struct mTimingEvent** previous = &timing->root; struct mTimingEvent* next = timing->root; unsigned priority = event->priority;

@@ -44,6 +48,10 @@ *previous = event;

} void mTimingDeschedule(struct mTiming* timing, struct mTimingEvent* event) { + if (timing->reroot) { + timing->root = timing->reroot; + timing->reroot = NULL; + } struct mTimingEvent** previous = &timing->root; struct mTimingEvent* next = timing->root; while (next) {
M src/debugger/gdb-stub.csrc/debugger/gdb-stub.c

@@ -305,11 +305,10 @@ for (r = 0; r <= ARM_PC; ++r) {

cpu->gprs[r] = _hex2int(readAddress, 8); readAddress += 8; } - int32_t currentCycles = 0; if (cpu->executionMode == MODE_ARM) { - ARM_WRITE_PC; + ARMWritePC(cpu); } else { - THUMB_WRITE_PC; + ThumbWritePC(cpu); } strncpy(stub->outgoing, "OK", GDB_STUB_MAX_LINE - 4);

@@ -369,11 +368,10 @@

if (reg <= ARM_PC) { cpu->gprs[reg] = value; if (reg == ARM_PC) { - int32_t currentCycles = 0; if (cpu->executionMode == MODE_ARM) { - ARM_WRITE_PC; + ARMWritePC(cpu); } else { - THUMB_WRITE_PC; + ThumbWritePC(cpu); } } } else if (reg == 0x19) {
M src/ds/ds.csrc/ds/ds.c

@@ -329,8 +329,7 @@ }

cpu->gprs[12] = header->arm7Entry; cpu->gprs[ARM_LR] = header->arm7Entry; cpu->gprs[ARM_PC] = header->arm7Entry; - int currentCycles = 0; - ARM_WRITE_PC; + ARMWritePC(cpu); ds->romVf->unmap(ds->romVf, header, sizeof(*header)); }

@@ -369,8 +368,7 @@ }

cpu->gprs[12] = header->arm9Entry; cpu->gprs[ARM_LR] = header->arm9Entry; cpu->gprs[ARM_PC] = header->arm9Entry; - int currentCycles = 0; - ARM_WRITE_PC; + ARMWritePC(cpu); ds->romVf->unmap(ds->romVf, header, sizeof(*header)); }

@@ -632,10 +630,10 @@ if ((opcode & 0xFFFF) == (redzoneInstruction & 0xFFFF)) {

int currentCycles = 0; if (cpu->executionMode == MODE_THUMB) { cpu->gprs[ARM_PC] -= WORD_SIZE_THUMB * 2; - THUMB_WRITE_PC; + ThumbWritePC(cpu); } else { cpu->gprs[ARM_PC] -= WORD_SIZE_ARM * 2; - ARM_WRITE_PC; + ARMWritePC(cpu); } #ifdef USE_DEBUGGERS } else if (ds->debugger) {
M src/feature/thread-proxy.csrc/feature/thread-proxy.c

@@ -78,6 +78,7 @@ MutexUnlock(&proxyRenderer->mutex);

if (waiting) { ThreadJoin(proxyRenderer->thread); } + RingFIFODeinit(&proxyRenderer->dirtyQueue); ConditionDeinit(&proxyRenderer->fromThreadCond); ConditionDeinit(&proxyRenderer->toThreadCond); MutexDeinit(&proxyRenderer->mutex);
M src/gb/audio.csrc/gb/audio.c

@@ -470,7 +470,15 @@ }

} *audio->nr52 &= ~0x000F; } else if (!wasEnable) { + audio->skipFrame = false; audio->frame = 7; + + if (audio->p) { + unsigned timingFactor = 0x400 >> !audio->p->doubleSpeed; + if (audio->p->timer.internalDiv & timingFactor) { + audio->skipFrame = true; + } + } } }

@@ -483,6 +491,13 @@ }

} void GBAudioUpdateFrame(struct GBAudio* audio, struct mTiming* timing) { + if (!audio->enable) { + return; + } + if (audio->skipFrame) { + audio->skipFrame = false; + return; + } int frame = (audio->frame + 1) & 7; audio->frame = frame;

@@ -929,6 +944,7 @@ uint32_t ch2Flags = 0;

uint32_t ch4Flags = 0; flags = GBSerializedAudioFlagsSetFrame(flags, audio->frame); + flags = GBSerializedAudioFlagsSetSkipFrame(flags, audio->skipFrame); STORE_32LE(audio->frameEvent.when - mTimingCurrentTime(audio->timing), 0, &state->ch1.nextFrame); flags = GBSerializedAudioFlagsSetCh1Volume(flags, audio->ch1.envelope.currentVolume);

@@ -987,6 +1003,7 @@ }

LOAD_32LE(flags, 0, flagsIn); audio->frame = GBSerializedAudioFlagsGetFrame(flags); + audio->skipFrame = GBSerializedAudioFlagsGetSkipFrame(flags); LOAD_32LE(ch1Flags, 0, &state->ch1.envelope); audio->ch1.envelope.currentVolume = GBSerializedAudioFlagsGetCh1Volume(flags);
M src/gb/core.csrc/gb/core.c

@@ -104,6 +104,7 @@ return false;

} core->cpu = cpu; core->board = gb; + core->timing = &gb->timing; gbcore->overrides = NULL; gbcore->debuggerPlatform = NULL; gbcore->cheatDevice = NULL;
M src/gb/mbc.csrc/gb/mbc.c

@@ -188,11 +188,6 @@ case 1:

case 2: case 3: gb->memory.mbcType = GB_MBC1; - if (gb->memory.romSize >= GB_SIZE_CART_BANK0 * 0x31 && _isMulticart(gb->memory.rom)) { - gb->memory.mbcState.mbc1.multicartStride = 4; - } else { - gb->memory.mbcState.mbc1.multicartStride = 5; - } break; case 5: case 6:

@@ -255,6 +250,11 @@ gb->memory.mbcWrite = _GBMBCNone;

break; case GB_MBC1: gb->memory.mbcWrite = _GBMBC1; + if (gb->memory.romSize >= GB_SIZE_CART_BANK0 * 0x31 && _isMulticart(gb->memory.rom)) { + gb->memory.mbcState.mbc1.multicartStride = 4; + } else { + gb->memory.mbcState.mbc1.multicartStride = 5; + } break; case GB_MBC2: gb->memory.mbcWrite = _GBMBC2;
M src/gb/memory.csrc/gb/memory.c

@@ -45,6 +45,8 @@ GB_BUS_RAM, // 0xC000

GB_BUS_CPU // 0xE000 }; +static const uint8_t _blockedRegion[1] = { 0xFF }; + static void _pristineCow(struct GB* gba); static uint8_t GBFastLoad8(struct LR35902Core* cpu, uint16_t address) {

@@ -91,6 +93,15 @@ break;

default: cpu->memory.cpuLoad8 = GBLoad8; break; + } + if (gb->memory.dmaRemaining) { + const enum GBBus* block = gb->model < GB_MODEL_CGB ? _oamBlockDMG : _oamBlockCGB; + enum GBBus dmaBus = block[memory->dmaSource >> 13]; + enum GBBus accessBus = block[address >> 13]; + if ((dmaBus != GB_BUS_CPU && dmaBus == accessBus) || (address >= GB_BASE_OAM && address < GB_BASE_UNUSABLE)) { + cpu->memory.activeRegion = _blockedRegion; + cpu->memory.activeMask = 0; + } } }

@@ -177,6 +188,7 @@ gb->memory.hdmaEvent.priority = 0x41;

memset(&gb->memory.hram, 0, sizeof(gb->memory.hram)); + memset(&gb->memory.mbcState, 0, sizeof(gb->memory.mbcState)); GBMBCInit(gb); switch (gb->memory.mbcType) { case GB_MBC1:

@@ -192,8 +204,9 @@ break;

case GB_MMM01: GBMBCSwitchBank0(gb, gb->memory.romSize / GB_SIZE_CART_BANK0 - 2); GBMBCSwitchBank(gb, gb->memory.romSize / GB_SIZE_CART_BANK0 - 1); + break; default: - memset(&gb->memory.mbcState, 0, sizeof(gb->memory.mbcState)); + break; } gb->memory.sramBank = gb->memory.sram;
M src/gb/timer.csrc/gb/timer.c

@@ -30,7 +30,7 @@ if (!timer->p->memory.io[REG_TIMA]) {

mTimingSchedule(&timer->p->timing, &timer->irq, 7 - ((timer->p->cpu->executionState - cyclesLate) & 3)); } } - int timingFactor = 0x3FF >> !timer->p->doubleSpeed; + unsigned timingFactor = 0x3FF >> !timer->p->doubleSpeed; if ((timer->internalDiv & timingFactor) == timingFactor) { GBAudioUpdateFrame(&timer->p->audio, &timer->p->timing); }

@@ -80,8 +80,8 @@ if (!timer->p->memory.io[REG_TIMA]) {

mTimingSchedule(&timer->p->timing, &timer->irq, 7 - (timer->p->cpu->executionState & 3)); } } - int timingFactor = 0x200 >> !timer->p->doubleSpeed; - if (timer->internalDiv & 0x200) { + unsigned timingFactor = 0x400 >> !timer->p->doubleSpeed; + if (timer->internalDiv & timingFactor) { GBAudioUpdateFrame(&timer->p->audio, &timer->p->timing); } timer->p->memory.io[REG_DIV] = 0;
M src/gb/video.csrc/gb/video.c

@@ -449,10 +449,12 @@ }

void GBVideoWriteLYC(struct GBVideo* video, uint8_t value) { GBRegisterSTAT oldStat = video->stat; - video->stat = GBRegisterSTATSetLYC(video->stat, value == video->ly); - if (!_statIRQAsserted(video, oldStat) && _statIRQAsserted(video, video->stat)) { - video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT); - GBUpdateIRQs(video->p); + if (GBRegisterLCDCIsEnable(video->p->memory.io[REG_LCDC])) { + video->stat = GBRegisterSTATSetLYC(video->stat, value == video->ly); + if (!_statIRQAsserted(video, oldStat) && _statIRQAsserted(video, video->stat)) { + video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT); + GBUpdateIRQs(video->p); + } } video->p->memory.io[REG_STAT] = video->stat; }
M src/gba/bios.csrc/gba/bios.c

@@ -43,8 +43,7 @@ } else {

cpu->gprs[ARM_PC] = BASE_CART0; } _ARMSetMode(cpu, MODE_ARM); - int currentCycles = 0; - ARM_WRITE_PC; + ARMWritePC(cpu); } static void _RegisterRamReset(struct GBA* gba) {

@@ -820,7 +819,6 @@ unsigned scaled = in & ((1 << sourceWidth) - 1);

in >>= sourceWidth; if (scaled || bias & 0x80000000) { scaled += bias & 0x7FFFFFFF; - scaled &= (1 << destWidth) - 1; } bitsRemaining -= sourceWidth; out |= scaled << bitsEaten;

@@ -832,4 +830,6 @@ out = 0;

dest += 4; } } + cpu->gprs[0] = source; + cpu->gprs[1] = dest; }
M src/gba/cheats.csrc/gba/cheats.c

@@ -276,6 +276,9 @@ static void GBACheatRefresh(struct mCheatSet* cheats, struct mCheatDevice* device) {

struct GBACheatSet* gbaset = (struct GBACheatSet*) cheats; if (cheats->enabled) { _patchROM(device, gbaset); + if (gbaset->hook && !gbaset->hook->reentries) { + _addBreakpoint(device, gbaset); + } } else { _unpatchROM(device, gbaset); }
M src/gba/core.csrc/gba/core.c

@@ -152,6 +152,7 @@ return false;

} core->cpu = cpu; core->board = gba; + core->timing = &gba->timing; core->debugger = NULL; core->symbolTable = NULL; gbacore->overrides = NULL;
M src/gba/dma.csrc/gba/dma.c

@@ -266,11 +266,7 @@ cpu->memory.store32(cpu, dest, memory->dmaTransferRegister, 0);

memory->dmaTransferRegister &= 0xFFFF0000; memory->dmaTransferRegister |= memory->dmaTransferRegister >> 16; } else { - if (sourceRegion == REGION_CART2_EX && memory->savedata.type == SAVEDATA_EEPROM) { - if (memory->savedata.type == SAVEDATA_AUTODETECT) { - mLOG(GBA_MEM, INFO, "Detected EEPROM savegame"); - GBASavedataInitEEPROM(&memory->savedata); - } + if (sourceRegion == REGION_CART2_EX && (memory->savedata.type == SAVEDATA_EEPROM || memory->savedata.type == SAVEDATA_EEPROM512)) { memory->dmaTransferRegister = GBASavedataReadEEPROM(&memory->savedata); } else { if (source) {

@@ -282,7 +278,9 @@ if (memory->savedata.type == SAVEDATA_AUTODETECT) {

mLOG(GBA_MEM, INFO, "Detected EEPROM savegame"); GBASavedataInitEEPROM(&memory->savedata); } - GBASavedataWriteEEPROM(&memory->savedata, memory->dmaTransferRegister, wordsRemaining); + if (memory->savedata.type == SAVEDATA_EEPROM512 || memory->savedata.type == SAVEDATA_EEPROM) { + GBASavedataWriteEEPROM(&memory->savedata, memory->dmaTransferRegister, wordsRemaining); + } } else { cpu->memory.store16(cpu, dest, memory->dmaTransferRegister, 0);
M src/gba/gba.csrc/gba/gba.c

@@ -216,6 +216,20 @@ GBATimerInit(gba);

GBASIOReset(&gba->sio); + bool isELF = false; +#ifdef USE_ELF + struct ELF* elf = ELFOpen(gba->romVf); + if (elf) { + isELF = true; + ELFClose(elf); + } +#endif + + if (GBAIsMB(gba->romVf) && !isELF) { + gba->romVf->seek(gba->romVf, 0, SEEK_SET); + gba->romVf->read(gba->romVf, gba->memory.wram, gba->pristineRomSize); + } + gba->lastJump = 0; gba->haltPending = false; gba->idleDetectionStep = 0;

@@ -242,8 +256,7 @@ cpu->gprs[ARM_PC] = BASE_WORKING_RAM;

} gba->memory.io[REG_VCOUNT >> 1] = 0x7E; gba->memory.io[REG_POSTFLG >> 1] = 1; - int currentCycles = 0; - ARM_WRITE_PC; + ARMWritePC(cpu); } }

@@ -344,11 +357,6 @@ gba->pristineRomSize = SIZE_WORKING_RAM;

} gba->isPristine = true; memset(gba->memory.wram, 0, SIZE_WORKING_RAM); - vf->read(vf, gba->memory.wram, gba->pristineRomSize); - if (!gba->memory.wram) { - mLOG(GBA, WARN, "Couldn't map ROM"); - return false; - } gba->yankedRomSize = 0; gba->memory.romSize = 0; gba->memory.romMask = 0;

@@ -512,7 +520,7 @@ if (GBADebugFlagsIsSend(gba->debugFlags)) {

int level = 1 << GBADebugFlagsGetLevel(gba->debugFlags); level &= 0x1F; char oolBuf[0x101]; - strncpy(oolBuf, gba->debugString, sizeof(gba->debugString)); + strncpy(oolBuf, gba->debugString, sizeof(oolBuf) - 1); memset(gba->debugString, 0, sizeof(gba->debugString)); oolBuf[0x100] = '\0'; mLog(_mLOG_CAT_GBA_DEBUG(), level, "%s", oolBuf);
M src/gba/hardware.csrc/gba/hardware.c

@@ -169,7 +169,7 @@ break;

case 1: if ((hw->pinState & 5) == 5) { hw->rtc.transferStep = 2; - } else { + } else if ((hw->pinState & 5) != 1) { hw->rtc.transferStep = 0; } break;

@@ -532,9 +532,9 @@

uint16_t _gbpRead(struct mKeyCallback* callback) { struct GBAGBPKeyCallback* gbpCallback = (struct GBAGBPKeyCallback*) callback; if (gbpCallback->p->gbpInputsPosted == 2) { - return 0x30F; + return 0xF0; } - return 0x3FF; + return 0; } uint16_t _gbpSioWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value) {
M src/gba/hle-bios.csrc/gba/hle-bios.c

@@ -6,7 +6,7 @@ const uint8_t hleBios[SIZE_BIOS] = {

0x06, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x0b, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x00, 0x00, 0xa0, 0xe1, 0x2c, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x02, 0x03, 0xa0, 0xe3, - 0x03, 0x10, 0xd0, 0xe5, 0xea, 0x00, 0x51, 0xe3, 0x02, 0x04, 0xa0, 0x13, + 0x03, 0x10, 0xd0, 0xe5, 0xea, 0x00, 0x51, 0xe3, 0xec, 0x01, 0x9f, 0x15, 0x10, 0xff, 0x2f, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x29, 0xe1, 0x00, 0x00, 0x5d, 0xe3, 0x01, 0xd3, 0xa0, 0x03, 0x20, 0xd0, 0x4d, 0x02, 0x00, 0x58, 0x2d, 0xe9, 0x02, 0xb0, 0x5e, 0xe5, 0x9c, 0xc0, 0xa0, 0xe3,

@@ -48,5 +48,5 @@ 0x03, 0x70, 0xa0, 0xe1, 0x03, 0x80, 0xa0, 0xe1, 0x03, 0x90, 0xa0, 0xe1,

0x03, 0xa0, 0xa0, 0xe1, 0x02, 0x00, 0x51, 0xe1, 0xf8, 0x07, 0xa1, 0xb8, 0xfc, 0xff, 0xff, 0xba, 0x03, 0x00, 0x00, 0xea, 0x02, 0x00, 0x51, 0xe1, 0xf8, 0x07, 0xb0, 0xb8, 0xf8, 0x07, 0xa1, 0xb8, 0xfb, 0xff, 0xff, 0xba, - 0xf0, 0x87, 0xbd, 0xe8 + 0xf0, 0x87, 0xbd, 0xe8, 0xc0, 0x00, 0x00, 0x02 };
M src/gba/hle-bios.ssrc/gba/hle-bios.s

@@ -20,7 +20,7 @@ resetBase:

mov r0, #0x8000000 ldrb r1, [r0, #3] cmp r1, #0xEA -movne r0, #0x2000000 +ldrne r0, =0x20000C0 bx r0 .word 0 .word 0xE129F000

@@ -183,3 +183,5 @@ stmltia r1!, {r3-r10}

blt 0b 2: ldmfd sp!, {r4-r10, pc} + +.ltorg
M src/gba/io.csrc/gba/io.c

@@ -728,7 +728,7 @@ case REG_KEYINPUT:

if (gba->rr && gba->rr->isPlaying(gba->rr)) { return 0x3FF ^ gba->rr->queryInput(gba->rr); } else { - uint16_t input = 0x3FF; + uint16_t input = 0; if (gba->keyCallback) { input = gba->keyCallback->readKeys(gba->keyCallback); if (gba->keySource) {

@@ -736,16 +736,16 @@ *gba->keySource = input;

} } else if (gba->keySource) { input = *gba->keySource; - } - if (!gba->allowOpposingDirections) { - unsigned rl = input & 0x030; - unsigned ud = input & 0x0C0; - input &= 0x30F; - if (rl != 0x030) { - input |= rl; - } - if (ud != 0x0C0) { - input |= ud; + if (!gba->allowOpposingDirections) { + unsigned rl = input & 0x030; + unsigned ud = input & 0x0C0; + input &= 0x30F; + if (rl != 0x030) { + input |= rl; + } + if (ud != 0x0C0) { + input |= ud; + } } } if (gba->rr && gba->rr->isRecording(gba->rr)) {

@@ -841,7 +841,6 @@ case REG_SOUND3CNT_X:

case REG_SOUND4CNT_LO: case REG_SOUND4CNT_HI: case REG_SOUNDCNT_LO: - case REG_SOUNDCNT_HI: if (!GBAudioEnableIsEnable(gba->memory.io[REG_SOUNDCNT_X >> 1])) { // TODO: Is writing allowed when the circuit is disabled? return 0;

@@ -858,6 +857,7 @@ case REG_WININ:

case REG_WINOUT: case REG_BLDCNT: case REG_BLDALPHA: + case REG_SOUNDCNT_HI: case REG_SOUNDCNT_X: case REG_WAVE_RAM0_LO: case REG_WAVE_RAM0_HI:
M src/gba/memory.csrc/gba/memory.c

@@ -558,7 +558,7 @@ }

break; case REGION_CART2_EX: wait = memory->waitstatesNonseq16[address >> BASE_OFFSET]; - if (memory->savedata.type == SAVEDATA_EEPROM) { + if (memory->savedata.type == SAVEDATA_EEPROM || memory->savedata.type == SAVEDATA_EEPROM512) { value = GBASavedataReadEEPROM(&memory->savedata); } else if ((address & (SIZE_CART0 - 1)) < memory->romSize) { LOAD_16(value, address & (SIZE_CART0 - 2), memory->rom);

@@ -892,7 +892,11 @@ if (memory->savedata.type == SAVEDATA_AUTODETECT) {

mLOG(GBA_MEM, INFO, "Detected EEPROM savegame"); GBASavedataInitEEPROM(&memory->savedata); } - GBASavedataWriteEEPROM(&memory->savedata, value, 1); + if (memory->savedata.type == SAVEDATA_EEPROM512 || memory->savedata.type == SAVEDATA_EEPROM) { + GBASavedataWriteEEPROM(&memory->savedata, value, 1); + break; + } + mLOG(GBA_MEM, GAME_ERROR, "Bad memory Store16: 0x%08X", address); break; case REGION_CART_SRAM: case REGION_CART_SRAM_MIRROR:
M src/gba/overrides.csrc/gba/overrides.c

@@ -223,6 +223,9 @@ override->savetype = SAVEDATA_SRAM;

} else if (strcasecmp(savetype, "EEPROM") == 0) { found = true; override->savetype = SAVEDATA_EEPROM; + } else if (strcasecmp(savetype, "EEPROM512") == 0) { + found = true; + override->savetype = SAVEDATA_EEPROM512; } else if (strcasecmp(savetype, "FLASH512") == 0) { found = true; override->savetype = SAVEDATA_FLASH512;

@@ -266,6 +269,9 @@ savetype = "SRAM";

break; case SAVEDATA_EEPROM: savetype = "EEPROM"; + break; + case SAVEDATA_EEPROM512: + savetype = "EEPROM512"; break; case SAVEDATA_FLASH512: savetype = "FLASH512";
M src/gba/renderers/cache-set.csrc/gba/renderers/cache-set.c

@@ -158,10 +158,10 @@ void GBAVideoCacheWriteVideoRegister(struct mCacheSet* cache, uint32_t address, uint16_t value) {

switch (address) { case REG_DISPCNT: GBAVideoCacheWriteDISPCNT(cache, value); - GBAVideoCacheWriteBGCNT(cache, 0, (uint16_t) mMapCacheSetGetPointer(&cache->maps, 0)->context); - GBAVideoCacheWriteBGCNT(cache, 1, (uint16_t) mMapCacheSetGetPointer(&cache->maps, 1)->context); - GBAVideoCacheWriteBGCNT(cache, 2, (uint16_t) mMapCacheSetGetPointer(&cache->maps, 2)->context); - GBAVideoCacheWriteBGCNT(cache, 3, (uint16_t) mMapCacheSetGetPointer(&cache->maps, 3)->context); + GBAVideoCacheWriteBGCNT(cache, 0, (uintptr_t) mMapCacheSetGetPointer(&cache->maps, 0)->context); + GBAVideoCacheWriteBGCNT(cache, 1, (uintptr_t) mMapCacheSetGetPointer(&cache->maps, 1)->context); + GBAVideoCacheWriteBGCNT(cache, 2, (uintptr_t) mMapCacheSetGetPointer(&cache->maps, 2)->context); + GBAVideoCacheWriteBGCNT(cache, 3, (uintptr_t) mMapCacheSetGetPointer(&cache->maps, 3)->context); break; case REG_BG0CNT: GBAVideoCacheWriteBGCNT(cache, 0, value);
M src/gba/savedata.csrc/gba/savedata.c

@@ -77,6 +77,9 @@ break;

case SAVEDATA_EEPROM: mappedMemoryFree(savedata->data, SIZE_CART_EEPROM); break; + case SAVEDATA_EEPROM512: + mappedMemoryFree(savedata->data, SIZE_CART_EEPROM512); + break; case SAVEDATA_FORCE_NONE: case SAVEDATA_AUTODETECT: break;

@@ -127,6 +130,8 @@ case SAVEDATA_FLASH1M:

return out->write(out, savedata->data, SIZE_CART_FLASH1M) == SIZE_CART_FLASH1M; case SAVEDATA_EEPROM: return out->write(out, savedata->data, SIZE_CART_EEPROM) == SIZE_CART_EEPROM; + case SAVEDATA_EEPROM512: + return out->write(out, savedata->data, SIZE_CART_EEPROM512) == SIZE_CART_EEPROM512; case SAVEDATA_AUTODETECT: case SAVEDATA_FORCE_NONE: return true;

@@ -152,7 +157,9 @@ return SIZE_CART_FLASH512;

case SAVEDATA_FLASH1M: return SIZE_CART_FLASH1M; case SAVEDATA_EEPROM: - return (savedata->vf && savedata->vf->size(savedata->vf) == SIZE_CART_EEPROM512) ? SIZE_CART_EEPROM512 : SIZE_CART_EEPROM; + return SIZE_CART_EEPROM; + case SAVEDATA_EEPROM512: + return SIZE_CART_EEPROM512; case SAVEDATA_FORCE_NONE: return 0; case SAVEDATA_AUTODETECT:

@@ -218,6 +225,8 @@ savedata->type = type;

GBASavedataInitFlash(savedata); break; case SAVEDATA_EEPROM: + case SAVEDATA_EEPROM512: + savedata->type = type; GBASavedataInitEEPROM(savedata); break; case SAVEDATA_SRAM:

@@ -263,22 +272,23 @@ }

void GBASavedataInitEEPROM(struct GBASavedata* savedata) { if (savedata->type == SAVEDATA_AUTODETECT) { - savedata->type = SAVEDATA_EEPROM; - } else { + savedata->type = SAVEDATA_EEPROM512; + } else if (savedata->type != SAVEDATA_EEPROM512 && savedata->type != SAVEDATA_EEPROM) { mLOG(GBA_SAVE, WARN, "Can't re-initialize savedata"); return; } int32_t eepromSize = SIZE_CART_EEPROM512; + if (savedata->type == SAVEDATA_EEPROM) { + eepromSize = SIZE_CART_EEPROM; + } off_t end; if (!savedata->vf) { end = 0; savedata->data = anonymousMemoryMap(SIZE_CART_EEPROM); } else { end = savedata->vf->size(savedata->vf); - if (end < SIZE_CART_EEPROM512) { - savedata->vf->truncate(savedata->vf, SIZE_CART_EEPROM512); - } else if (end > SIZE_CART_EEPROM512) { - eepromSize = SIZE_CART_EEPROM; + if (end < eepromSize) { + savedata->vf->truncate(savedata->vf, eepromSize); } savedata->data = savedata->vf->map(savedata->vf, eepromSize, savedata->mapMode); }

@@ -420,13 +430,21 @@ static void _ensureEeprom(struct GBASavedata* savedata, uint32_t size) {

if (size < SIZE_CART_EEPROM512) { return; } - if (!savedata->vf || savedata->vf->size(savedata->vf) > SIZE_CART_EEPROM512) { + if (savedata->type == SAVEDATA_EEPROM) { + return; + } + savedata->type = SAVEDATA_EEPROM; + if (!savedata->vf) { return; } savedata->vf->unmap(savedata->vf, savedata->data, SIZE_CART_EEPROM512); - savedata->vf->truncate(savedata->vf, SIZE_CART_EEPROM); - savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_EEPROM, savedata->mapMode); - memset(&savedata->data[SIZE_CART_EEPROM512], 0xFF, SIZE_CART_EEPROM - SIZE_CART_EEPROM512); + if (savedata->vf->size(savedata->vf) < SIZE_CART_EEPROM) { + savedata->vf->truncate(savedata->vf, SIZE_CART_EEPROM); + savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_EEPROM, savedata->mapMode); + memset(&savedata->data[SIZE_CART_EEPROM512], 0xFF, SIZE_CART_EEPROM - SIZE_CART_EEPROM512); + } else { + savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_EEPROM, savedata->mapMode); + } } void GBASavedataWriteEEPROM(struct GBASavedata* savedata, uint16_t value, uint32_t writeSize) {

@@ -586,7 +604,7 @@ mLOG(GBA_SAVE, INFO, "Updating flash chip from 512kb to 1Mb");

savedata->type = SAVEDATA_FLASH1M; if (savedata->vf) { savedata->vf->unmap(savedata->vf, savedata->data, SIZE_CART_FLASH512); - if (savedata->vf->size(savedata->vf) == SIZE_CART_FLASH512) { + if (savedata->vf->size(savedata->vf) < SIZE_CART_FLASH1M) { savedata->vf->truncate(savedata->vf, SIZE_CART_FLASH1M); savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_FLASH1M, MAP_WRITE); memset(&savedata->data[SIZE_CART_FLASH512], 0xFF, SIZE_CART_FLASH512);
M src/lr35902/debugger/cli-debugger.csrc/lr35902/debugger/cli-debugger.c

@@ -21,7 +21,7 @@ { 0, 0, 0, 0 }

}; static inline void _printFlags(struct CLIDebuggerBackend* be, union FlagRegister f) { - be->printf(be, "[%c%c%c%c]\n", + be->printf(be, "F: [%c%c%c%c]\n", f.z ? 'Z' : '-', f.n ? 'N' : '-', f.h ? 'H' : '-',

@@ -82,16 +82,16 @@

static void _printStatus(struct CLIDebuggerSystem* debugger) { struct CLIDebuggerBackend* be = debugger->p->backend; struct LR35902Core* cpu = debugger->p->d.core->cpu; - be->printf(be, "A: %02X F: %02X (AF: %04X)\n", cpu->a, cpu->f.packed, cpu->af); - be->printf(be, "B: %02X C: %02X (BC: %04X)\n", cpu->b, cpu->c, cpu->bc); - be->printf(be, "D: %02X E: %02X (DE: %04X)\n", cpu->d, cpu->e, cpu->de); - be->printf(be, "H: %02X L: %02X (HL: %04X)\n", cpu->h, cpu->l, cpu->hl); - be->printf(be, "PC: %04X SP: %04X\n", cpu->pc, cpu->sp); + be->printf(be, "A: %02X F: %02X (AF: %04X)\n", cpu->a, cpu->f.packed, cpu->af); + be->printf(be, "B: %02X C: %02X (BC: %04X)\n", cpu->b, cpu->c, cpu->bc); + be->printf(be, "D: %02X E: %02X (DE: %04X)\n", cpu->d, cpu->e, cpu->de); + be->printf(be, "H: %02X L: %02X (HL: %04X)\n", cpu->h, cpu->l, cpu->hl); + be->printf(be, "PC: %04X SP: %04X\n", cpu->pc, cpu->sp); struct LR35902Debugger* platDebugger = (struct LR35902Debugger*) debugger->p->d.platform; size_t i; for (i = 0; platDebugger->segments[i].name; ++i) { - be->printf(be, "%s%s: %02X", i ? " " : "", platDebugger->segments[i].name, cpu->memory.currentSegment(cpu, platDebugger->segments[i].start)); + be->printf(be, "%s%s: %02X", i ? " " : "", platDebugger->segments[i].name, cpu->memory.currentSegment(cpu, platDebugger->segments[i].start)); } if (i) { be->printf(be, "\n");
M src/lr35902/debugger/debugger.csrc/lr35902/debugger/debugger.c

@@ -213,10 +213,10 @@ disPtr[1] = ' ';

disPtr += 2; LR35902Disassemble(&info, disPtr, sizeof(disassembly) - (disPtr - disassembly)); - *length = snprintf(out, *length, "A: %02X F: %02X B: %02X C: %02X D: %02X E: %02X H: %02X L: %02X SP: %04X PC: %04X | %s", + *length = snprintf(out, *length, "A: %02X F: %02X B: %02X C: %02X D: %02X E: %02X H: %02X L: %02X SP: %04X PC: %02X:%04X | %s", cpu->a, cpu->f.packed, cpu->b, cpu->c, cpu->d, cpu->e, cpu->h, cpu->l, - cpu->sp, cpu->pc, disassembly); + cpu->sp, cpu->memory.currentSegment(cpu, cpu->pc), cpu->pc, disassembly); } bool LR35902DebuggerGetRegister(struct mDebuggerPlatform* d, const char* name, int32_t* value) {
M src/platform/3ds/main.csrc/platform/3ds/main.c

@@ -84,7 +84,8 @@ DSP_SUPPORTED

} hasSound; // TODO: Move into context -static void* outputBuffer; +static color_t* outputBuffer = NULL; +static color_t* screenshotBuffer = NULL; static struct mAVStream stream; static int16_t* audioLeft = 0; static size_t audioPos = 0;

@@ -135,6 +136,11 @@ ctrDeinitGpu();

if (outputBuffer) { linearFree(outputBuffer); + outputBuffer = NULL; + } + if (screenshotBuffer) { + linearFree(screenshotBuffer); + screenshotBuffer = NULL; } C3D_RenderTargetDelete(topScreen[0]);

@@ -276,7 +282,7 @@ _map3DSKey(&runner->core->inputMap, KEY_RIGHT, GBA_KEY_RIGHT);

_map3DSKey(&runner->core->inputMap, KEY_L, GBA_KEY_L); _map3DSKey(&runner->core->inputMap, KEY_R, GBA_KEY_R); - outputBuffer = linearMemAlign(256 * 224 * 2, 0x80); + outputBuffer = linearMemAlign(256 * 224 * sizeof(color_t), 0x80); runner->core->setVideoBuffer(runner->core, outputBuffer, 256); unsigned mode;

@@ -547,7 +553,7 @@ C3D_Tex* tex = &outputTexture;

GSPGPU_FlushDataCache(outputBuffer, 256 * VIDEO_VERTICAL_PIXELS * 2); C3D_SyncDisplayTransfer( - outputBuffer, GX_BUFFER_DIM(256, VIDEO_VERTICAL_PIXELS), + (u32*) outputBuffer, GX_BUFFER_DIM(256, VIDEO_VERTICAL_PIXELS), tex->data, GX_BUFFER_DIM(256, 256), GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGB565) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB565) |

@@ -564,22 +570,22 @@

static void _drawScreenshot(struct mGUIRunner* runner, const color_t* pixels, unsigned width, unsigned height, bool faded) { C3D_Tex* tex = &outputTexture; - color_t* newPixels = linearMemAlign(256 * height * sizeof(color_t), 0x100); - + if (!screenshotBuffer) { + screenshotBuffer = linearMemAlign(256 * 224 * sizeof(color_t), 0x80); + } unsigned y; for (y = 0; y < height; ++y) { - memcpy(&newPixels[y * 256], &pixels[y * width], width * sizeof(color_t)); - memset(&newPixels[y * 256 + width], 0, (256 - width) * sizeof(color_t)); + memcpy(&screenshotBuffer[y * 256], &pixels[y * width], width * sizeof(color_t)); + memset(&screenshotBuffer[y * 256 + width], 0, (256 - width) * sizeof(color_t)); } - GSPGPU_FlushDataCache(newPixels, 256 * height * sizeof(u32)); + GSPGPU_FlushDataCache(screenshotBuffer, 256 * height * sizeof(color_t)); C3D_SyncDisplayTransfer( - (u32*) newPixels, GX_BUFFER_DIM(256, height), + (u32*) screenshotBuffer, GX_BUFFER_DIM(256, height), tex->data, GX_BUFFER_DIM(256, 256), GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGB565) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB565) | GX_TRANSFER_OUT_TILED(1) | GX_TRANSFER_FLIP_VERT(1)); - linearFree(newPixels); _drawTex(runner->core, faded); }
M src/platform/libretro/libretro.csrc/platform/libretro/libretro.c

@@ -490,6 +490,7 @@

core->setPeripheral(core, mPERIPH_RUMBLE, &rumble); savedata = anonymousMemoryMap(SIZE_CART_FLASH1M); + memset(savedata, 0xFF, SIZE_CART_FLASH1M); struct VFile* save = VFileFromMemory(savedata, SIZE_CART_FLASH1M); _reloadSettings();

@@ -657,6 +658,7 @@ ++pos;

} } #endif + cheatSet->refresh(cheatSet, device); } unsigned retro_get_region(void) {
M src/platform/psp2/main.csrc/platform/psp2/main.c

@@ -25,18 +25,18 @@

#include <vita2d.h> static void _drawStart(void) { - vita2d_set_vblank_wait(false); + static int vcount = 0; + extern bool frameLimiter; + int oldVCount = vcount; + vcount = sceDisplayGetVcount(); + vita2d_set_vblank_wait(frameLimiter && vcount + 1 >= oldVCount); vita2d_start_drawing(); vita2d_clear_screen(); } static void _drawEnd(void) { - static int vcount = 0; - extern bool frameLimiter; - int oldVCount = vcount; vita2d_end_drawing(); - vcount = sceDisplayGetVcount(); - vita2d_set_vblank_wait(frameLimiter && vcount + 1 >= oldVCount); + vita2d_wait_rendering_done(); vita2d_swap_buffers(); }
M src/platform/python/_builder.hsrc/platform/python/_builder.h

@@ -36,6 +36,7 @@ #include <limits.h>

#include "flags.h" +#include <mgba/core/blip_buf.h> #include <mgba/core/cache-set.h> #include <mgba/core/core.h> #include <mgba/core/map-cache.h>
M src/platform/python/_builder.pysrc/platform/python/_builder.py

@@ -20,6 +20,7 @@ #define static

#define inline #include "flags.h" #define OPAQUE_THREADING +#include <mgba/core/blip_buf.h> #include <mgba/core/cache-set.h> #include <mgba-util/common.h> #include <mgba/core/core.h>
M src/platform/python/engine.csrc/platform/python/engine.c

@@ -65,7 +65,6 @@ return true;

} void mPythonScriptEngineDeinit(struct mScriptEngine* se) { - struct mPythonScriptEngine* engine = (struct mPythonScriptEngine*) se; free(se); }

@@ -76,7 +75,7 @@ return endswith(name, ".py");

} bool mPythonScriptEngineLoadScript(struct mScriptEngine* se, const char* name, struct VFile* vf) { - struct mPythonScriptEngine* engine = (struct mPythonScriptEngine*) se; + UNUSED(se); return mPythonLoadScript(name, vf); }

@@ -94,7 +93,7 @@ mPythonRunPending();

} bool mPythonScriptEngineLookupSymbol(struct mScriptEngine* se, const char* name, int32_t* out) { - struct mPythonScriptEngine* engine = (struct mPythonScriptEngine*) se; + UNUSED(se); return mPythonLookupSymbol(name, out); }
A src/platform/python/mgba/audio.py

@@ -0,0 +1,57 @@

+# Copyright (c) 2013-2018 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 # pylint: disable=no-name-in-module + + +class Buffer(object): + def __init__(self, native, internal_rate): + self._native = native + self._internal_rate = internal_rate + + @property + def available(self): + return lib.blip_samples_avail(self._native) + + def set_rate(self, rate): + lib.blip_set_rates(self._native, self._internal_rate, rate) + + def read(self, samples): + buffer = ffi.new("short[%i]" % samples) + count = self.read_into(buffer, samples, 1, 0) + return buffer[:count] + + def read_into(self, buffer, samples, channels=1, interleave=0): + return lib.blip_read_samples(self._native, ffi.addressof(buffer, interleave), samples, channels == 2) + + def clear(self): + lib.blip_clear(self._native) + + +class StereoBuffer(object): + def __init__(self, left, right): + self._left = left + self._right = right + + @property + def available(self): + return min(self._left.available, self._right.available) + + def set_rate(self, rate): + self._left.set_rate(rate) + self._right.set_rate(rate) + + def read(self, samples): + buffer = ffi.new("short[%i]" % (2 * samples)) + count = self.read_into(buffer, samples) + return buffer[0:2 * count] + + def read_into(self, buffer, samples): + samples = self._left.read_into(buffer, samples, 2, 0) + return self._right.read_into(buffer, samples, 2, 1) + + def clear(self): + self._left.clear() + self._right.clear()
M src/platform/python/mgba/core.pysrc/platform/python/mgba/core.py

@@ -4,7 +4,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/. from ._pylib import ffi, lib # pylint: disable=no-name-in-module -from . import tile +from . import tile, audio from cached_property import cached_property from functools import wraps

@@ -173,51 +173,81 @@

def _load(self): self._was_reset = True + @protected def load_file(self, path): return bool(lib.mCoreLoadFile(self._core, path.encode('UTF-8'))) def is_rom(self, vfile): return bool(self._core.isROM(vfile.handle)) + @protected def load_rom(self, vfile): return bool(self._core.loadROM(self._core, vfile.handle)) + @protected def load_bios(self, vfile, id=0): return bool(self._core.loadBIOS(self._core, vfile.handle, id)) + @protected def load_save(self, vfile): return bool(self._core.loadSave(self._core, vfile.handle)) + @protected def load_temporary_save(self, vfile): return bool(self._core.loadTemporarySave(self._core, vfile.handle)) + @protected def load_patch(self, vfile): return bool(self._core.loadPatch(self._core, vfile.handle)) + @protected def load_config(self, config): lib.mCoreLoadForeignConfig(self._core, config._native) + @protected def autoload_save(self): return bool(lib.mCoreAutoloadSave(self._core)) + @protected def autoload_patch(self): return bool(lib.mCoreAutoloadPatch(self._core)) + @protected def autoload_cheats(self): return bool(lib.mCoreAutoloadCheats(self._core)) + @property def platform(self): return self._core.platform(self._core) + @protected def desired_video_dimensions(self): width = ffi.new("unsigned*") height = ffi.new("unsigned*") self._core.desiredVideoDimensions(self._core, width, height) return width[0], height[0] + @protected def set_video_buffer(self, image): self._core.setVideoBuffer(self._core, image.buffer, image.stride) + @protected + def set_audio_buffer_size(self, size): + self._core.setAudioBufferSize(self._core, size) + + @property + def audio_buffer_size(self): + return self._core.getAudioBufferSize(self._core) + + @protected + def get_audio_channels(self): + return audio.StereoBuffer(self.get_audio_channel(0), self.get_audio_channel(1)); + + @protected + def get_audio_channel(self, channel): + return audio.Buffer(self._core.getAudioChannel(self._core, channel), self.frequency) + + @protected def reset(self): self._core.reset(self._core) self._load()

@@ -233,6 +263,7 @@ def run_loop(self):

self._core.runLoop(self._core) @needs_reset + @protected def step(self): self._core.step(self._core)
M src/platform/python/mgba/gamedata.pysrc/platform/python/mgba/gamedata.py

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

def search(core): crc32 = None - if hasattr(core, 'PLATFORM_GBA') and core.platform() == core.PLATFORM_GBA: + if hasattr(core, 'PLATFORM_GBA') and core.platform == core.PLATFORM_GBA: platform = 'GBA' crc32 = core.crc32 - if hasattr(core, 'PLATFORM_GB') and core.platform() == core.PLATFORM_GB: + if hasattr(core, 'PLATFORM_GB') and core.platform == core.PLATFORM_GB: platform = 'GB' crc32 = core.crc32 cls = mgba_gamedata.registry.search(platform, {'crc32': crc32})
M src/platform/qt/CoreController.cppsrc/platform/qt/CoreController.cpp

@@ -185,12 +185,12 @@ }

message = QString().vsprintf(format, args); QMetaObject::invokeMethod(controller, "statusPosted", Q_ARG(const QString&, message)); } + message = QString().vsprintf(format, args); + QMetaObject::invokeMethod(controller, "logPosted", Q_ARG(int, level), Q_ARG(int, category), Q_ARG(const QString&, message)); if (level == mLOG_FATAL) { mCoreThreadMarkCrashed(controller->thread()); QMetaObject::invokeMethod(controller, "crashed", Q_ARG(const QString&, QString().vsprintf(format, args))); } - message = QString().vsprintf(format, args); - QMetaObject::invokeMethod(controller, "logPosted", Q_ARG(int, level), Q_ARG(int, category), Q_ARG(const QString&, message)); }; }
M src/platform/qt/GBAApp.cppsrc/platform/qt/GBAApp.cpp

@@ -75,9 +75,11 @@ while (!m_workerJobs.isEmpty()) {

finishJob(m_workerJobs.firstKey()); } +#ifdef USE_SQLITE3 if (m_db) { NoIntroDBDestroy(m_db); } +#endif } bool GBAApp::event(QEvent* event) {
M src/platform/qt/GBAKeyEditor.cppsrc/platform/qt/GBAKeyEditor.cpp

@@ -278,13 +278,13 @@ GBAKeyEditor* self = static_cast<GBAKeyEditor*>(user);

if (description->highDirection != GBA_KEY_NONE) { KeyEditor* key = self->keyById(static_cast<enum GBAKey>(description->highDirection)); if (key) { - key->setValueAxis(axis, description->deadHigh); + key->setValueAxis(axis, GamepadAxisEvent::POSITIVE); } } if (description->lowDirection != GBA_KEY_NONE) { KeyEditor* key = self->keyById(static_cast<enum GBAKey>(description->lowDirection)); if (key) { - key->setValueAxis(axis, description->deadLow); + key->setValueAxis(axis, GamepadAxisEvent::NEGATIVE); } } }, this);

@@ -350,14 +350,6 @@ return m_currentKey != m_keyOrder.end();

} #ifdef BUILD_SDL -void GBAKeyEditor::setAxisValue(int axis, int32_t value) { - if (!findFocus()) { - return; - } - KeyEditor* focused = *m_currentKey; - focused->setValueAxis(axis, value); -} - void GBAKeyEditor::selectGamepad(int index) { m_controller->setGamepad(m_type, index); m_profile = m_profileSelect->currentText();
M src/platform/qt/GBAKeyEditor.hsrc/platform/qt/GBAKeyEditor.h

@@ -42,7 +42,6 @@ private slots:

void setNext(); void refresh(); #ifdef BUILD_SDL - void setAxisValue(int axis, int32_t value); void selectGamepad(int index); void updateJoysticks(); #endif
M src/platform/qt/KeyEditor.cppsrc/platform/qt/KeyEditor.cpp

@@ -48,10 +48,10 @@ m_button = true;

setValue(button); } -void KeyEditor::setValueAxis(int axis, int32_t value) { +void KeyEditor::setValueAxis(int axis, GamepadAxisEvent::Direction direction) { m_button = true; m_axis = axis; - m_direction = value < 0 ? GamepadAxisEvent::NEGATIVE : GamepadAxisEvent::POSITIVE; + m_direction = direction; updateButtonText(); emit axisChanged(axis, m_direction); }
M src/platform/qt/KeyEditor.hsrc/platform/qt/KeyEditor.h

@@ -33,7 +33,7 @@ public slots:

void setValue(int key); void setValueKey(int key); void setValueButton(int button); - void setValueAxis(int axis, int32_t value); + void setValueAxis(int axis, GamepadAxisEvent::Direction value); void setValueHat(int hat, GamepadHatEvent::Direction value); void clearButton(); void clearAxis();
M src/platform/qt/MemoryView.uisrc/platform/qt/MemoryView.ui

@@ -6,8 +6,8 @@ <property name="geometry">

<rect> <x>0</x> <y>0</y> - <width>565</width> - <height>658</height> + <width>822</width> + <height>886</height> </rect> </property> <property name="windowTitle">

@@ -98,7 +98,7 @@ </item>

<item> <widget class="QRadioButton" name="width8"> <property name="text"> - <string>1 Byte</string> + <string>&amp;1 Byte</string> </property> <property name="checked"> <bool>true</bool>

@@ -121,7 +121,7 @@ </item>

<item> <widget class="QRadioButton" name="width16"> <property name="text"> - <string>2 Bytes</string> + <string>&amp;2 Bytes</string> </property> </widget> </item>

@@ -141,7 +141,7 @@ </item>

<item> <widget class="QRadioButton" name="width32"> <property name="text"> - <string>4 Bytes</string> + <string>&amp;4 Bytes</string> </property> </widget> </item>

@@ -168,7 +168,6 @@ <horstretch>0</horstretch>

<verstretch>0</verstretch> </sizepolicy> </property> - <zorder></zorder> </widget> </item> <item>
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -765,6 +765,7 @@ }

attachWidget(m_display.get()); setMouseTracking(true); m_display->setMinimumSize(size); + setFocus(); #ifndef Q_OS_MAC if (isFullScreen()) {
M src/platform/qt/ts/medusa-emu-de.tssrc/platform/qt/ts/medusa-emu-de.ts

@@ -4687,19 +4687,29 @@ <source>Tiles</source>

<translation>Tiles</translation> </message> <message> - <location filename="../TileView.ui" line="140"/> + <location filename="../TileView.ui" line="110"/> <source>256 colors</source> <translation>256 Farben</translation> </message> <message> - <location filename="../TileView.ui" line="31"/> + <location filename="../TileView.ui" line="123"/> <source>×</source> <translation>×</translation> </message> <message> - <location filename="../TileView.ui" line="44"/> + <location filename="../TileView.ui" line="136"/> <source>Magnification</source> <translation>Vergrößerung</translation> + </message> + <message> + <location filename="../TileView.ui" line="159"/> + <source>Tiles per row</source> + <translation>Tiles pro Zeile</translation> + </message> + <message> + <location filename="../TileView.ui" line="166"/> + <source>Fit to window</source> + <translation>An Fenster anpassen</translation> </message> </context> <context>
M src/platform/sdl/CMakeLists.txtsrc/platform/sdl/CMakeLists.txt

@@ -15,7 +15,7 @@

if(SDL_VERSION EQUAL "1.2" OR NOT SDL2_FOUND) find_package(SDL 1.2) if(SDL_FOUND) - set(SDL_VERSION "1.2" PARENT_SCOPE) + set(SDL_VERSION "1.2") set(SDL_VERSION_DEBIAN "1.2debian") set(USE_PIXMAN ON) endif()

@@ -26,6 +26,7 @@ set(SDL_FOUND OFF PARENT_SCOPE)

return() endif() +set(SDL_VERSION "${SDL_VERSION}" PARENT_SCOPE) add_definitions(-DBUILD_SDL) find_feature(USE_PIXMAN "pixman-1")

@@ -85,7 +86,11 @@ list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c)

include_directories(${OPENGLES2_INCLUDE_DIR}) endif() if(NOT BUILD_GL AND NOT BUILD_GLES2) - list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl.c) + if(SDL_VERSION EQUAL "2") + list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl2.c) + else() + list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl1.c) + endif() endif() endif()
M src/platform/sdl/gl-common.csrc/platform/sdl/gl-common.c

@@ -55,5 +55,6 @@ SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_OPENGL | (SDL_FULLSCREEN * renderer->fullscreen));

#else SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 32, SDL_OPENGL | (SDL_FULLSCREEN * renderer->fullscreen)); #endif + SDL_WM_SetCaption(projectName, ""); #endif }
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -64,8 +64,12 @@ // Some OSes don't do hotplug detection

if (!SDL_JoystickListSize(&context->joysticks)) { int i; for (i = 0; i < nJoysticks; ++i) { + SDL_Joystick* sdlJoystick = SDL_JoystickOpen(i); + if (!sdlJoystick) { + continue; + } struct SDL_JoystickCombo* joystick = SDL_JoystickListAppend(&context->joysticks); - joystick->joystick = SDL_JoystickOpen(i); + joystick->joystick = sdlJoystick; joystick->index = SDL_JoystickListSize(&context->joysticks) - 1; #if SDL_VERSION_ATLEAST(2, 0, 0) joystick->id = SDL_JoystickInstanceID(joystick->joystick);

@@ -200,6 +204,9 @@ joystickName = SDL_JoystickName(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick);

#else joystickName = SDL_JoystickName(SDL_JoystickIndex(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick)); #endif + if (!joystickName) { + continue; + } if (events->preferredJoysticks[player->playerId] && strcmp(events->preferredJoysticks[player->playerId], joystickName) == 0) { index = i; break;

@@ -250,6 +257,9 @@ const char* name = SDL_JoystickName(context->joystick->joystick);

#else const char* name = SDL_JoystickName(SDL_JoystickIndex(context->joystick->joystick)); #endif + if (!name) { + return; + } mInputProfileLoad(context->bindings, SDL_BINDING_BUTTON, config, name); const char* value;

@@ -301,7 +311,10 @@ const char* name = SDL_JoystickName(context->joystick->joystick);

#else const char* name = SDL_JoystickName(SDL_JoystickIndex(context->joystick->joystick)); #endif - char value[12]; + if (!name) { + return; + } + char value[16]; snprintf(value, sizeof(value), "%i", context->rotation.axisX); mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "tiltAxisX", value, name); snprintf(value, sizeof(value), "%i", context->rotation.axisY);

@@ -329,8 +342,12 @@ #if SDL_VERSION_ATLEAST(2, 0, 0)

SDL_Event event; while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED) > 0) { if (event.type == SDL_JOYDEVICEADDED) { + SDL_Joystick* sdlJoystick = SDL_JoystickOpen(event.jdevice.which); + if (!sdlJoystick) { + continue; + } struct SDL_JoystickCombo* joystick = SDL_JoystickListAppend(&events->joysticks); - joystick->joystick = SDL_JoystickOpen(event.jdevice.which); + joystick->joystick = sdlJoystick; joystick->id = SDL_JoystickInstanceID(joystick->joystick); joystick->index = SDL_JoystickListSize(&events->joysticks) - 1; #if SDL_VERSION_ATLEAST(2, 0, 0)

@@ -344,16 +361,18 @@ #else

joystickName = SDL_JoystickName(SDL_JoystickIndex(joystick->joystick)); #endif size_t i; - for (i = 0; (int) i < events->playersAttached; ++i) { - if (events->players[i]->joystick) { - continue; - } - if (events->preferredJoysticks[i] && strcmp(events->preferredJoysticks[i], joystickName) == 0) { - events->players[i]->joystick = joystick; - if (config && events->players[i]->bindings) { - mInputProfileLoad(events->players[i]->bindings, SDL_BINDING_BUTTON, config, joystickName); + if (joystickName) { + for (i = 0; (int) i < events->playersAttached; ++i) { + if (events->players[i]->joystick) { + continue; } - return; + if (events->preferredJoysticks[i] && strcmp(events->preferredJoysticks[i], joystickName) == 0) { + events->players[i]->joystick = joystick; + if (config && events->players[i]->bindings) { + mInputProfileLoad(events->players[i]->bindings, SDL_BINDING_BUTTON, config, joystickName); + } + return; + } } } for (i = 0; (int) i < events->playersAttached; ++i) {

@@ -361,7 +380,7 @@ if (events->players[i]->joystick) {

continue; } events->players[i]->joystick = joystick; - if (config && events->players[i]->bindings) { + if (config && events->players[i]->bindings && joystickName) { mInputProfileLoad(events->players[i]->bindings, SDL_BINDING_BUTTON, config, joystickName); } break;
M src/platform/sdl/sw-sdl.csrc/platform/sdl/sw-sdl1.c

@@ -21,35 +21,15 @@ renderer->runloop = mSDLSWRunloop;

} bool mSDLSWInit(struct mSDLRenderer* renderer) { -#if !SDL_VERSION_ATLEAST(2, 0, 0) #ifdef COLOR_16_BIT - SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_DOUBLEBUF | SDL_HWSURFACE); + SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_DOUBLEBUF | SDL_HWSURFACE | (SDL_FULLSCREEN * renderer->fullscreen)); #else - SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 32, SDL_DOUBLEBUF | SDL_HWSURFACE); -#endif + SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 32, SDL_DOUBLEBUF | SDL_HWSURFACE | (SDL_FULLSCREEN * renderer->fullscreen)); #endif + SDL_WM_SetCaption(projectName, ""); unsigned width, height; renderer->core->desiredVideoDimensions(renderer->core, &width, &height); -#if SDL_VERSION_ATLEAST(2, 0, 0) - renderer->window = SDL_CreateWindow(projectName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer->viewportWidth, renderer->viewportHeight, SDL_WINDOW_OPENGL | (SDL_WINDOW_FULLSCREEN_DESKTOP * renderer->player.fullscreen)); - SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); - renderer->player.window = renderer->window; - renderer->sdlRenderer = SDL_CreateRenderer(renderer->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); -#ifdef COLOR_16_BIT -#ifdef COLOR_5_6_5 - renderer->sdlTex = SDL_CreateTexture(renderer->sdlRenderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height); -#else - renderer->sdlTex = SDL_CreateTexture(renderer->sdlRenderer, SDL_PIXELFORMAT_ABGR1555, SDL_TEXTUREACCESS_STREAMING, width, height); -#endif -#else - renderer->sdlTex = SDL_CreateTexture(renderer->sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, width, height); -#endif - - int stride; - SDL_LockTexture(renderer->sdlTex, 0, (void**) &renderer->outputBuffer, &stride); - renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, stride / BYTES_PER_PIXEL); -#else SDL_Surface* surface = SDL_GetVideoSurface(); SDL_LockSurface(surface);

@@ -81,7 +61,6 @@ #else

return false; #endif } -#endif return true; }

@@ -89,9 +68,7 @@

void mSDLSWRunloop(struct mSDLRenderer* renderer, void* user) { struct mCoreThread* context = user; SDL_Event event; -#if !SDL_VERSION_ATLEAST(2, 0, 0) SDL_Surface* surface = SDL_GetVideoSurface(); -#endif while (mCoreThreadIsActive(context)) { while (SDL_PollEvent(&event)) {

@@ -99,14 +76,6 @@ mSDLHandleEvent(context, &renderer->player, &event);

} if (mCoreSyncWaitFrameStart(&context->impl->sync)) { -#if SDL_VERSION_ATLEAST(2, 0, 0) - SDL_UnlockTexture(renderer->sdlTex); - SDL_RenderCopy(renderer->sdlRenderer, renderer->sdlTex, 0, 0); - SDL_RenderPresent(renderer->sdlRenderer); - int stride; - SDL_LockTexture(renderer->sdlTex, 0, (void**) &renderer->outputBuffer, &stride); - renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, stride / BYTES_PER_PIXEL); -#else #ifdef USE_PIXMAN if (renderer->ratio > 1) { pixman_image_composite32(PIXMAN_OP_SRC, renderer->pix, 0, renderer->screenpix,

@@ -132,7 +101,6 @@ #endif

SDL_UnlockSurface(surface); SDL_Flip(surface); SDL_LockSurface(surface); -#endif } mCoreSyncWaitFrameEnd(&context->impl->sync); }

@@ -141,13 +109,11 @@

void mSDLSWDeinit(struct mSDLRenderer* renderer) { if (renderer->ratio > 1) { free(renderer->outputBuffer); +#ifdef USE_PIXMAN + pixman_image_unref(renderer->pix); + pixman_image_unref(renderer->screenpix); +#endif } -#if !SDL_VERSION_ATLEAST(2, 0, 0) SDL_Surface* surface = SDL_GetVideoSurface(); SDL_UnlockSurface(surface); -#ifdef USE_PIXMAN - pixman_image_unref(renderer->pix); - pixman_image_unref(renderer->screenpix); -#endif -#endif }
A src/platform/sdl/sw-sdl2.c

@@ -0,0 +1,72 @@

+/* 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/. */ +#include "main.h" + +#include <mgba/core/core.h> +#include <mgba/core/thread.h> +#include <mgba/core/version.h> +#include <mgba-util/arm-algo.h> + +static bool mSDLSWInit(struct mSDLRenderer* renderer); +static void mSDLSWRunloop(struct mSDLRenderer* renderer, void* user); +static void mSDLSWDeinit(struct mSDLRenderer* renderer); + +void mSDLSWCreate(struct mSDLRenderer* renderer) { + renderer->init = mSDLSWInit; + renderer->deinit = mSDLSWDeinit; + renderer->runloop = mSDLSWRunloop; +} + +bool mSDLSWInit(struct mSDLRenderer* renderer) { + unsigned width, height; + renderer->core->desiredVideoDimensions(renderer->core, &width, &height); + renderer->window = SDL_CreateWindow(projectName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer->viewportWidth, renderer->viewportHeight, SDL_WINDOW_OPENGL | (SDL_WINDOW_FULLSCREEN_DESKTOP * renderer->player.fullscreen)); + SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); + renderer->player.window = renderer->window; + renderer->sdlRenderer = SDL_CreateRenderer(renderer->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); +#ifdef COLOR_16_BIT +#ifdef COLOR_5_6_5 + renderer->sdlTex = SDL_CreateTexture(renderer->sdlRenderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height); +#else + renderer->sdlTex = SDL_CreateTexture(renderer->sdlRenderer, SDL_PIXELFORMAT_ABGR1555, SDL_TEXTUREACCESS_STREAMING, width, height); +#endif +#else + renderer->sdlTex = SDL_CreateTexture(renderer->sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, width, height); +#endif + + int stride; + SDL_LockTexture(renderer->sdlTex, 0, (void**) &renderer->outputBuffer, &stride); + renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, stride / BYTES_PER_PIXEL); + + return true; +} + +void mSDLSWRunloop(struct mSDLRenderer* renderer, void* user) { + struct mCoreThread* context = user; + SDL_Event event; + + while (mCoreThreadIsActive(context)) { + while (SDL_PollEvent(&event)) { + mSDLHandleEvent(context, &renderer->player, &event); + } + + if (mCoreSyncWaitFrameStart(&context->impl->sync)) { + SDL_UnlockTexture(renderer->sdlTex); + SDL_RenderCopy(renderer->sdlRenderer, renderer->sdlTex, 0, 0); + SDL_RenderPresent(renderer->sdlRenderer); + int stride; + SDL_LockTexture(renderer->sdlTex, 0, (void**) &renderer->outputBuffer, &stride); + renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, stride / BYTES_PER_PIXEL); + } + mCoreSyncWaitFrameEnd(&context->impl->sync); + } +} + +void mSDLSWDeinit(struct mSDLRenderer* renderer) { + if (renderer->ratio > 1) { + free(renderer->outputBuffer); + } +}
M src/platform/switch/main.csrc/platform/switch/main.c

@@ -92,6 +92,13 @@ static unsigned framecap = 10;

static u32 vibrationDeviceHandles[4]; static HidVibrationValue vibrationStop = { .freq_low = 160.f, .freq_high = 320.f }; +static enum ScreenMode { + SM_PA, + SM_AF, + SM_SF, + SM_MAX +} screenMode = SM_PA; + static bool initEgl() { s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (!s_display) {

@@ -113,7 +120,7 @@ if (!numConfigs) {

goto _fail1; } - s_surface = eglCreateWindowSurface(s_display, config, "", NULL); + s_surface = eglCreateWindowSurface(s_display, config, nwindowGetDefault(), NULL); if (!s_surface) { goto _fail1; }

@@ -238,6 +245,11 @@ runner->core->setVideoBuffer(runner->core, frameBuffer, 256);

runner->core->setPeripheral(runner->core, mPERIPH_RUMBLE, &rumble.d); runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation); runner->core->setAVStream(runner->core, &stream); + + unsigned mode; + if (mCoreConfigGetUIntValue(&runner->config, "screenMode", &mode) && mode < SM_MAX) { + screenMode = mode; + } } static void _gameLoaded(struct mGUIRunner* runner) {

@@ -249,6 +261,11 @@ blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), samplerate * ratio);

mCoreConfigGetUIntValue(&runner->config, "fastForwardCap", &framecap); + unsigned mode; + if (mCoreConfigGetUIntValue(&runner->config, "screenMode", &mode) && mode < SM_MAX) { + screenMode = mode; + } + rumble.up = 0; rumble.down = 0; }

@@ -270,11 +287,26 @@ glUseProgram(program);

glBindVertexArray(vao); float aspectX = width / (float) runner->params.width; float aspectY = height / (float) runner->params.height; - float max; - if (aspectX > aspectY) { - max = floor(1.0 / aspectX); - } else { - max = floor(1.0 / aspectY); + float max = 1.f; + switch (screenMode) { + case SM_PA: + if (aspectX > aspectY) { + max = floor(1.0 / aspectX); + } else { + max = floor(1.0 / aspectY); + } + break; + case SM_AF: + if (aspectX > aspectY) { + max = 1.0 / aspectX; + } else { + max = 1.0 / aspectY; + } + break; + case SM_SF: + aspectX = 1.0; + aspectY = 1.0; + break; } aspectX *= max;

@@ -354,6 +386,12 @@ static uint16_t _pollGameInput(struct mGUIRunner* runner) {

return _pollInput(&runner->core->inputMap); } +static void _incrementScreenMode(struct mGUIRunner* runner) { + UNUSED(runner); + screenMode = (screenMode + 1) % SM_MAX; + mCoreConfigSetUIntValue(&runner->config, "screenMode", screenMode); +} + static void _setFrameLimiter(struct mGUIRunner* runner, bool limit) { UNUSED(runner); if (!frameLimiter && limit) {

@@ -365,6 +403,7 @@ enqueuedBuffers -= audoutNReleasedBuffers;

} } frameLimiter = limit; + eglSwapInterval(s_surface, limit); } static bool _running(struct mGUIRunner* runner) {

@@ -608,16 +647,29 @@ { .id = 0 }

}, .configExtra = (struct GUIMenuItem[]) { { + .title = "Screen mode", + .data = "screenMode", + .submenu = 0, + .state = SM_PA, + .validStates = (const char*[]) { + "Pixel-Accurate", + "Aspect-Ratio Fit", + "Stretched", + }, + .nStates = 3 + }, + { .title = "Fast forward cap", .data = "fastForwardCap", .submenu = 0, .state = 7, .validStates = (const char*[]) { - "3", "4", "5", "6", "7", "8", "9", + "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "20", "30" }, .stateMappings = (const struct GUIVariant[]) { + GUI_V_U(2), GUI_V_U(3), GUI_V_U(4), GUI_V_U(5),

@@ -634,10 +686,10 @@ GUI_V_U(15),

GUI_V_U(20), GUI_V_U(30), }, - .nStates = 15 + .nStates = 16 }, }, - .nConfigExtra = 1, + .nConfigExtra = 2, .setup = _setup, .teardown = NULL, .gameLoaded = _gameLoaded,

@@ -647,7 +699,7 @@ .drawFrame = _drawFrame,

.drawScreenshot = _drawScreenshot, .paused = _gameUnloaded, .unpaused = _gameLoaded, - .incrementScreenMode = NULL, + .incrementScreenMode = _incrementScreenMode, .setFrameLimiter = _setFrameLimiter, .pollGameInput = _pollGameInput, .running = _running