From 537fe6c637b18d8168b5180001b3db70454ad1c8 Mon Sep 17 00:00:00 2001 From: Kirill Isakov Date: Sun, 15 Dec 2019 16:57:51 +0600 Subject: [PATCH 01/22] Fix SPIRV linking error on Ubuntu/Debian --- gtk/meson.build | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gtk/meson.build b/gtk/meson.build index b47833e7..66555110 100644 --- a/gtk/meson.build +++ b/gtk/meson.build @@ -93,13 +93,14 @@ endif if slang and opengl glslang_dep = c_compiler.find_library('glslang', required: false) + hlsl_dep = c_compiler.find_library('HLSL', required: false) spirv_dep = c_compiler.find_library('SPIRV', required: false) osdependent_dep = c_compiler.find_library('OSDependent', required: false) ogl_compiler_dep = c_compiler.find_library('OGLCompiler', required: false) spv_remapper_dep = c_compiler.find_library('SPVRemapper', required: false) - if glslang_dep.found() and spirv_dep.found() and osdependent_dep.found() and ogl_compiler_dep.found() and spv_remapper_dep.found() - deps += [glslang_dep, spirv_dep, osdependent_dep, ogl_compiler_dep, spv_remapper_dep] + if glslang_dep.found() and hlsl_dep.found() and spirv_dep.found() and osdependent_dep.found() and ogl_compiler_dep.found() and spv_remapper_dep.found() + deps += [glslang_dep, hlsl_dep, spirv_dep, osdependent_dep, ogl_compiler_dep, spv_remapper_dep] args += ['-DUSE_SLANG', '-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS', From 169af1d00279982845de2243fdfd8282ddd5b148 Mon Sep 17 00:00:00 2001 From: Kirill Isakov Date: Sun, 15 Dec 2019 22:01:44 +0600 Subject: [PATCH 02/22] Add automated builds via Cirrus CI (Linux & macOS) --- .cirrus.yml | 38 ++++++++++++++++++++++++++++++++++++++ .gitignore | 4 ++++ README.md | 9 +++++++++ 3 files changed, 51 insertions(+) create mode 100644 .cirrus.yml diff --git a/.cirrus.yml b/.cirrus.yml new file mode 100644 index 00000000..fdff5fba --- /dev/null +++ b/.cirrus.yml @@ -0,0 +1,38 @@ +# vim: sts=2 sw=2 ai + +linux_task: + container: + image: gcc:latest + + setup_script: + - git submodule update --init shaders/SPIRV-Cross + - apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install meson gettext libsdl2-dev libgtk-3-dev libminizip-dev portaudio19-dev glslang-dev + + compile_script: + - meson build gtk --buildtype=release --strip + - ninja -j2 -C build + + package_script: + - mkdir snes9x + - cp -ar build/snes9x-gtk README.md LICENSE docs data gtk/AUTHORS snes9x/ + - tar -caf "snes9x-${CIRRUS_CHANGE_IN_REPO}.txz" snes9x + + build_artifacts: + path: "snes9x-${CIRRUS_CHANGE_IN_REPO}.txz" + + +macOS_task: + osx_instance: + image: mojave-xcode + + compile_script: + - xcodebuild -project macosx/snes9x.xcodeproj -target Snes9x -configuration Release build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO + + package_script: + - mkdir snes9x + - cp -R macosx/build/Release/Snes9x.app macosx/docs README.md LICENSE snes9x/ + - zip -r "snes9x-${CIRRUS_CHANGE_IN_REPO}.zip" snes9x + + build_artifacts: + path: "snes9x-${CIRRUS_CHANGE_IN_REPO}.zip" + diff --git a/.gitignore b/.gitignore index f0cf4db1..e6cf053c 100644 --- a/.gitignore +++ b/.gitignore @@ -495,3 +495,7 @@ healthchecksdb MigrationBackup/ # End of https://www.gitignore.io/api/c,c++,xcode,visualstudio + +# vim +*.swp + diff --git a/README.md b/README.md index 9014f5da..efe7f58d 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,12 @@ This is the official source code repository for the Snes9x project. Please check the [Wiki](https://github.com/snes9xgit/snes9x/wiki) for additional information. + +## Nightly builds + +Download nightly builds from continuous integration: + +[![Build Status](https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=linux)](https://cirrus-ci.com/github/snes9xgit/snes9x) +[![Build Status](https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=macOS)](https://cirrus-ci.com/github/snes9xgit/snes9x) +[![Build Status](https://ci.appveyor.com/api/projects/status/github/snes9xgit/snes9x?branch=master&svg=true)](https://ci.appveyor.com/project/snes9x/snes9x) + From 26ea0cc26b37bdf3ff9f4fce1f60674e10238ac4 Mon Sep 17 00:00:00 2001 From: Kirill Isakov Date: Mon, 16 Dec 2019 00:37:22 +0600 Subject: [PATCH 03/22] Add libretro core CI builds on more platforms --- .cirrus.yml | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++- README.md | 48 ++++++++++++++++++-- 2 files changed, 171 insertions(+), 5 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index fdff5fba..67098637 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,6 +1,10 @@ # vim: sts=2 sw=2 ai -linux_task: +################################################################################ +# snes9x +################################################################################ + +snes9x_linux-amd64_task: container: image: gcc:latest @@ -21,7 +25,7 @@ linux_task: path: "snes9x-${CIRRUS_CHANGE_IN_REPO}.txz" -macOS_task: +snes9x_macOS-amd64_task: osx_instance: image: mojave-xcode @@ -36,3 +40,123 @@ macOS_task: build_artifacts: path: "snes9x-${CIRRUS_CHANGE_IN_REPO}.zip" +################################################################################ +# libretro +################################################################################ + +libretro_linux-amd64_task: + container: + image: gcc:latest + compile_script: + - make -j2 -C libretro + build_artifacts: + path: "libretro/snes9x_libretro.so" + + +libretro_linux-i386_task: + container: + image: dockcross/linux-x86 + compile_script: + - make -j2 -C libretro + build_artifacts: + path: "libretro/snes9x_libretro.so" + + +libretro_linux-armhf_task: + container: + image: dockcross/linux-armv7 + compile_script: + - make -j2 -C libretro + build_artifacts: + path: "libretro/snes9x_libretro.so" + + +libretro_linux-armv7-neon-hf_task: + container: + image: dockcross/linux-armv7 + compile_script: + - make -j2 -C libretro platform=unix-armv7-neon-hardfloat + build_artifacts: + path: "libretro/snes9x_libretro.so" + + +libretro_linux-arm64_task: + container: + image: dockcross/linux-arm64 + compile_script: + - make -j2 -C libretro + build_artifacts: + path: "libretro/snes9x_libretro.so" + + +libretro_android-arm_task: + container: + image: dockcross/android-arm + compile_script: + - make -j2 -C libretro platform=unix + build_artifacts: + path: "libretro/snes9x_libretro.so" + + +libretro_android-arm64_task: + container: + image: dockcross/android-arm64 + compile_script: + - make -j2 -C libretro platform=unix-arm64 + build_artifacts: + path: "libretro/snes9x_libretro.so" + + +libretro_emscripten_task: + container: + image: gcc:latest + compile_script: + - make -j2 -C libretro platform=emscripten + build_artifacts: + path: "libretro/snes9x_libretro_emscripten.bc" + + +libretro_macOS-amd64_task: + osx_instance: + image: mojave-xcode + compile_script: + - make -j2 -C libretro + build_artifacts: + path: "libretro/snes9x_libretro.dylib" + + +libretro_nintendo-wii_task: + container: + image: devkitpro/devkitppc + compile_script: + - make -j2 -C libretro platform=wii + build_artifacts: + path: "libretro/snes9x_libretro_wii.a" + + +libretro_nintendo-switch-libnx_task: + container: + image: devkitpro/devkita64 + compile_script: + - make -j2 -C libretro platform=libnx + build_artifacts: + path: "libretro/snes9x_libretro_libnx.a" + + +libretro_nintendo-ngc_task: + container: + image: devkitpro/devkitppc + compile_script: + - make -j2 -C libretro platform=ngc + build_artifacts: + path: "libretro/snes9x_libretro_ngc.a" + + +libretro_playstation-psp_task: + container: + image: bkcsoft/psptoolchain + compile_script: + - make -j2 -C libretro platform=unix + build_artifacts: + path: "libretro/snes9x_libretro.so" + diff --git a/README.md b/README.md index efe7f58d..95cd0d02 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,49 @@ Please check the [Wiki](https://github.com/snes9xgit/snes9x/wiki) for additional Download nightly builds from continuous integration: -[![Build Status](https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=linux)](https://cirrus-ci.com/github/snes9xgit/snes9x) -[![Build Status](https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=macOS)](https://cirrus-ci.com/github/snes9xgit/snes9x) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/snes9xgit/snes9x?branch=master&svg=true)](https://ci.appveyor.com/project/snes9x/snes9x) +### snes9x +| OS | status | +|---------|--------------------------------------------| +| Windows | [![Status][s9x-win-all]][appveyor] | +| Linux | [![Status][snes9x_linux-amd64]][cirrus-ci] | +| macOS | [![Status][snes9x_macOS-amd64]][cirrus-ci] | + +[appveyor]: https://ci.appveyor.com/project/snes9x/snes9x +[cirrus-ci]: http://cirrus-ci.com/github/snes9xgit/snes9x + +[s9x-win-all]: https://ci.appveyor.com/api/projects/status/github/snes9xgit/snes9x?branch=master&svg=true +[snes9x_linux-amd64]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=snes9x_linux-amd64 +[snes9x_macOS-amd64]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=snes9x_macOS-amd64 + +### libretro core + +| OS | status | +|---------------------|---------------------------------------------------------| +| Linux/amd64 | [![Status][libretro_linux-amd64]][cirrus-ci] | +| Linux/i386 | [![Status][libretro_linux-i386]][cirrus-ci] | +| Linux/armhf | [![Status][libretro_linux-armhf]][cirrus-ci] | +| Linux/armv7-neon-hf | [![Status][libretro_linux-armv7-neon-hf]][cirrus-ci] | +| Linux/arm64 | [![Status][libretro_linux-arm64]][cirrus-ci] | +| Android/arm | [![Status][libretro_android-arm]][cirrus-ci] | +| Android/arm64 | [![Status][libretro_android-arm64]][cirrus-ci] | +| Emscripten | [![Status][libretro_emscripten]][cirrus-ci] | +| macOS/amd64 | [![Status][libretro_macOS-amd64]][cirrus-ci] | +| Nintendo Wii | [![Status][libretro_nintendo-wii]][cirrus-ci] | +| Nintendo Switch | [![Status][libretro_nintendo-switch-libnx]][cirrus-ci] | +| Nintendo GameCube | [![Status][libretro_nintendo-ngc]][cirrus-ci] | +| PSP | [![Status][libretro_playstation-psp]][cirrus-ci] | + +[libretro_linux-amd64]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_linux-amd64 +[libretro_linux-i386]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_linux-i386 +[libretro_linux-armhf]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_linux-armhf +[libretro_linux-armv7-neon-hf]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_linux-armv7-neon-hf +[libretro_linux-arm64]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_linux-arm64 +[libretro_android-arm]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_android-arm +[libretro_android-arm64]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_android-arm64 +[libretro_emscripten]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_emscripten +[libretro_macOS-amd64]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_macOS-amd64 +[libretro_nintendo-wii]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_nintendo-wii +[libretro_nintendo-switch-libnx]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_nintendo-switch-libnx +[libretro_nintendo-ngc]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_nintendo-ngc +[libretro_playstation-psp]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=libretro_playstation-psp From c480642fb839e62140763fe11238afda695c3437 Mon Sep 17 00:00:00 2001 From: Kirill Isakov Date: Mon, 16 Dec 2019 13:21:57 +0600 Subject: [PATCH 04/22] Add Linux & FreeBSD X11 CI builds --- .cirrus.yml | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- README.md | 16 ++++++++++------ 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 67098637..edac7a65 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -4,7 +4,7 @@ # snes9x ################################################################################ -snes9x_linux-amd64_task: +snes9x_linux-gtk-amd64_task: container: image: gcc:latest @@ -19,10 +19,54 @@ snes9x_linux-amd64_task: package_script: - mkdir snes9x - cp -ar build/snes9x-gtk README.md LICENSE docs data gtk/AUTHORS snes9x/ - - tar -caf "snes9x-${CIRRUS_CHANGE_IN_REPO}.txz" snes9x + - tar -caf "snes9x-gtk-${CIRRUS_CHANGE_IN_REPO}.txz" snes9x build_artifacts: - path: "snes9x-${CIRRUS_CHANGE_IN_REPO}.txz" + path: "snes9x-gtk-${CIRRUS_CHANGE_IN_REPO}.txz" + + +snes9x_linux-x11-amd64_task: + container: + image: gcc:latest + + setup_script: + - apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install libxv-dev libxinerama-dev + + compile_script: + - cd unix + - touch configure + - ./configure + - make -j2 + + package_script: + - mkdir snes9x + - cp -ar unix/snes9x unix/docs unix/snes9x.conf.default README.md LICENSE data snes9x/ + - tar -caf "snes9x-x11-${CIRRUS_CHANGE_IN_REPO}.txz" snes9x + + build_artifacts: + path: "snes9x-x11-${CIRRUS_CHANGE_IN_REPO}.txz" + + +snes9x_freebsd-x11-amd64_task: + freebsd_instance: + image: freebsd-12-1-release-amd64 + + setup_script: + - pkg install -y gmake pkgconf minizip libX11 libXext + + compile_script: + - cd unix + - touch configure + - ./configure + - gmake -j2 + + package_script: + - mkdir snes9x + - cp -a unix/snes9x unix/docs unix/snes9x.conf.default README.md LICENSE data snes9x/ + - tar -caf "snes9x-x11-${CIRRUS_CHANGE_IN_REPO}.txz" snes9x + + build_artifacts: + path: "snes9x-x11-${CIRRUS_CHANGE_IN_REPO}.txz" snes9x_macOS-amd64_task: diff --git a/README.md b/README.md index 95cd0d02..54b38fbc 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,21 @@ Download nightly builds from continuous integration: ### snes9x -| OS | status | -|---------|--------------------------------------------| -| Windows | [![Status][s9x-win-all]][appveyor] | -| Linux | [![Status][snes9x_linux-amd64]][cirrus-ci] | -| macOS | [![Status][snes9x_macOS-amd64]][cirrus-ci] | +| OS | status | +|---------------|--------------------------------------------------| +| Windows | [![Status][s9x-win-all]][appveyor] | +| Linux (GTK) | [![Status][snes9x_linux-gtk-amd64]][cirrus-ci] | +| Linux (X11) | [![Status][snes9x_linux-x11-amd64]][cirrus-ci] | +| FreeBSD (X11) | [![Status][snes9x_freebsd-x11-amd64]][cirrus-ci] | +| macOS | [![Status][snes9x_macOS-amd64]][cirrus-ci] | [appveyor]: https://ci.appveyor.com/project/snes9x/snes9x [cirrus-ci]: http://cirrus-ci.com/github/snes9xgit/snes9x [s9x-win-all]: https://ci.appveyor.com/api/projects/status/github/snes9xgit/snes9x?branch=master&svg=true -[snes9x_linux-amd64]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=snes9x_linux-amd64 +[snes9x_linux-gtk-amd64]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=snes9x_linux-gtk-amd64 +[snes9x_linux-x11-amd64]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=snes9x_linux-x11-amd64 +[snes9x_freebsd-x11-amd64]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=snes9x_freebsd-x11-amd64 [snes9x_macOS-amd64]: https://api.cirrus-ci.com/github/snes9xgit/snes9x.svg?task=snes9x_macOS-amd64 ### libretro core From b11657cd0f349a271c60041ff3e64f42b12a358f Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Sun, 12 Jan 2020 15:47:58 -0800 Subject: [PATCH 05/22] Mac: Fix HID parsing for gamepads --- macosx/mac-joypad.mm | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/macosx/mac-joypad.mm b/macosx/mac-joypad.mm index 35a0388e..748d15f9 100755 --- a/macosx/mac-joypad.mm +++ b/macosx/mac-joypad.mm @@ -274,7 +274,7 @@ void findControls(struct JoypadDevice &device, NSDictionary *properties, NSMutab if (properties == nil) { return; - } + } int usagePage = [properties[@kIOHIDElementUsagePageKey] intValue]; int usage = [properties[@kIOHIDElementUsageKey] intValue]; @@ -293,13 +293,11 @@ void findControls(struct JoypadDevice &device, NSDictionary *properties, NSMutab *hat = [properties[@kIOHIDElementCookieKey] intValue]; } } - else - { - for ( NSDictionary *child in properties[@kIOHIDElementKey] ) - { - findControls(device, child, buttons, axes, hat); - } - } + + for ( NSDictionary *child in properties[@kIOHIDElementKey] ) + { + findControls(device, child, buttons, axes, hat); + } } void ParseDefaults (void) From 173e882c7d48393cb5011028a5b60c2f3c1d0188 Mon Sep 17 00:00:00 2001 From: George Talusan Date: Mon, 13 Jan 2020 00:00:05 -0500 Subject: [PATCH 06/22] Mac: make HID hat switches work --- macosx/mac-joypad.mm | 114 ++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 61 deletions(-) diff --git a/macosx/mac-joypad.mm b/macosx/mac-joypad.mm index 35a0388e..feca209d 100755 --- a/macosx/mac-joypad.mm +++ b/macosx/mac-joypad.mm @@ -34,31 +34,6 @@ #include "mac-os.h" #include "mac-joypad.h" -#define kUp(i) (i * 4) -#define kDn(i) (i * 4 + 1) -#define kLf(i) (i * 4 + 2) -#define kRt(i) (i * 4 + 3) - -#define kPadElemTypeNone 0 -#define kPadElemTypeHat4 1 -#define kPadElemTypeHat8 2 -#define kPadElemTypeAxis 3 -#define kPadElemTypeButton 4 -#define kPadElemTypeOtherHat4 5 -#define kPadElemTypeOtherHat8 6 - -#define kPadXAxis 1 -#define kPadYAxis 0 -#define kPadHat 0 - -#define kMaskUp 0x0800 -#define kMaskDn 0x0400 -#define kMaskLf 0x0200 -#define kMaskRt 0x0100 - -typedef hu_device_t *pRecDevice; -typedef hu_element_t *pRecElement; - std::unordered_set allDevices; std::unordered_map>> defaultAxes; std::unordered_map> defaultButtons; @@ -175,7 +150,7 @@ void gamepadAction(void *inContext, IOReturn inResult, void *inSender, IOHIDValu objcInput.value =inputStruct.value; pthread_mutex_unlock(&keyLock); - if (info.min != info.max) + if (info.usage != kHIDUsage_GD_Hatswitch && info.min != info.max) { if (inputStruct.value <= info.min || inputStruct.value >= info.max) { @@ -187,16 +162,19 @@ void gamepadAction(void *inContext, IOReturn inResult, void *inSender, IOHIDValu } else { - if ([inputDelegate handleInput:objcInput fromJoypad:objcJoypad]) + if (inputStruct.value >= info.min && inputStruct.value <= info.max) { - return; + if ([inputDelegate handleInput:objcInput fromJoypad:objcJoypad]) + { + return; + } } } pthread_mutex_lock(&keyLock); struct JoypadInput oppositeInputStruct = inputStruct; - if (info.min != info.max) + if (info.usage != kHIDUsage_GD_Hatswitch && info.min != info.max) { if (inputStruct.value < info.min) { @@ -230,28 +208,45 @@ void gamepadAction(void *inContext, IOReturn inResult, void *inSender, IOHIDValu { int32 value = inputStruct.value; - inputStruct.value = 1; - if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) + for (int i = info.min; i <= info.max; i++) { - pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = (value & inputStruct.value); + inputStruct.value = i; + if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) + { + pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = false; + } } - inputStruct.value = 2; - if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) + if (value >= info.min && value <= info.max) { - pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = (value & inputStruct.value); - } - - inputStruct.value = 4; - if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) - { - pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = (value & inputStruct.value); - } - - inputStruct.value = 8; - if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) - { - pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = (value & inputStruct.value); + if (value % 2 == 0) + { + inputStruct.value = value; + if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) + { + pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = true; + } + } + else + { + for (int i = value - 1; i <= value + 1; i++) + { + int button = i; + if (i < info.min) + { + button = info.max; + } + else if (i > info.max) + { + button = info.min; + } + inputStruct.value = button; + if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) + { + pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = true; + } + } + } } } else @@ -269,7 +264,7 @@ void gamepadAction(void *inContext, IOReturn inResult, void *inSender, IOHIDValu pthread_mutex_unlock(&keyLock); } -void findControls(struct JoypadDevice &device, NSDictionary *properties, NSMutableArray *buttons, NSMutableArray *axes, int64 *hat) +void findControls(struct JoypadDevice &device, NSDictionary *properties, NSMutableArray *buttons, NSMutableArray *axes, NSMutableDictionary *hat) { if (properties == nil) { @@ -288,10 +283,7 @@ void findControls(struct JoypadDevice &device, NSDictionary *properties, NSMutab } else if (usagePage == kHIDPage_GenericDesktop && usage == kHIDUsage_GD_Hatswitch) { - if (hat != NULL) - { - *hat = [properties[@kIOHIDElementCookieKey] intValue]; - } + [hat setDictionary:properties]; } else { @@ -506,7 +498,7 @@ void AddDevice (IOHIDDeviceRef device) NSMutableArray *buttons = [NSMutableArray new]; NSMutableArray *axes = [NSMutableArray new]; - int64 hat = -1; + NSMutableDictionary *hat = [NSMutableDictionary new]; struct JoypadDevice deviceStruct; deviceStruct.vendorID = vendor.unsignedIntValue; @@ -538,7 +530,7 @@ void AddDevice (IOHIDDeviceRef device) for ( NSDictionary *child in ((__bridge NSDictionary *)properties)[@kIOHIDElementKey] ) { - findControls(deviceStruct, child, buttons, axes, &hat); + findControls(deviceStruct, child, buttons, axes, hat); } NSComparisonResult (^comparitor)(NSDictionary *a, NSDictionary *b) = ^NSComparisonResult(NSDictionary *a, NSDictionary *b) @@ -626,17 +618,17 @@ void AddDevice (IOHIDDeviceRef device) infoByCookie[cookie] = info; } - if (hat >= 0) + if ([hat count] >= 0) { struct JoypadCookie cookie; struct JoypadCookieInfo info; cookie.device = deviceStruct; - cookie.cookie = (uint32)hat; + cookie.cookie = hat[@kIOHIDElementCookieKey].unsignedIntValue; info.usage = kHIDUsage_GD_Hatswitch; - info.min = 0; - info.max = 0; + info.min = hat[@kIOHIDElementMinKey].intValue; + info.max = hat[@kIOHIDElementMaxKey].intValue; info.midpoint = 0; if (defaultHatValues.find(defaultsKey) != defaultHatValues.end()) @@ -822,7 +814,7 @@ bool SetButtonCodeForJoypadControl(uint32 vendorID, uint32 productID, uint32 ind { auto info = infoByCookie[cookieStruct]; - if ( info.min != info.max ) + if (info.usage != kHIDUsage_GD_Hatswitch && info.min != info.max) { if (value <= info.min) { @@ -1017,7 +1009,7 @@ std::string LabelForInput(uint32 vendorID, uint32 productID, uint32 cookie, int3 } } - if (value == 1) + if (value == 0) { return "D-Pad Up"; } @@ -1029,7 +1021,7 @@ std::string LabelForInput(uint32 vendorID, uint32 productID, uint32 cookie, int3 { return "D-Pad Down"; } - else if (value == 8) + else if (value == 6) { return "D-Pad Left"; } From 404c01019fb5241f762f41c3577cc9957107ffe0 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Wed, 15 Jan 2020 19:40:22 -0800 Subject: [PATCH 07/22] Mac: Fix keyboard preferences for players 2-8 --- macosx/Snes9x/S9xPrefsViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macosx/Snes9x/S9xPrefsViewController.m b/macosx/Snes9x/S9xPrefsViewController.m index 45478bfd..3f6bb424 100644 --- a/macosx/Snes9x/S9xPrefsViewController.m +++ b/macosx/Snes9x/S9xPrefsViewController.m @@ -114,7 +114,7 @@ for (NSUInteger i = 0; i < kNumButtons; ++i) { - controlsDict[@(i)] = keyboardDict[@(i + playerNum).stringValue]; + controlsDict[@(i)] = keyboardDict[@(i + (playerNum * kNumButtons)).stringValue]; } for (NSView *subview in self.view.subviews) From 70b3345476ff13f3b6aabd853117bf6c0881e3f7 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Wed, 15 Jan 2020 20:01:56 -0800 Subject: [PATCH 08/22] Mac: Fix keyboard implementation for players 2-8 --- macosx/mac-os.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index 9b5cf5ef..0ed92f3a 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -2838,7 +2838,7 @@ void QuitWithFatalError ( NSString *message) pthread_mutex_lock(&keyLock); S9xButton button = keyCodes[event.keyCode]; - if ( button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player <= 0 && button.player <= MAC_MAX_PLAYERS) + if ( button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player >= 0 && button.player <= MAC_MAX_PLAYERS) { pressedKeys[button.player][button.buttonCode] = true; } @@ -2866,7 +2866,7 @@ void QuitWithFatalError ( NSString *message) pthread_mutex_lock(&keyLock); S9xButton button = keyCodes[event.keyCode]; - if ( button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player <= 0 && button.player <= MAC_MAX_PLAYERS) + if ( button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player >= 0 && button.player <= MAC_MAX_PLAYERS) { pressedKeys[button.player][button.buttonCode] = false; } From e7c47ef25d93dc2fdd92ec2c852001e48cf8a864 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Wed, 15 Jan 2020 20:10:10 -0800 Subject: [PATCH 09/22] Mac: Report button presses for all 8 players, not just the first 2 --- macosx/mac-os.mm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index 0ed92f3a..54ae7e27 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -2419,8 +2419,10 @@ static void ProcessInput (void) } } - ControlPadFlagsToS9xReportButtons(0, controlPad[0]); - ControlPadFlagsToS9xReportButtons(1, controlPad[1]); + for (int i = 0; i < MAC_MAX_PLAYERS; ++i) + { + ControlPadFlagsToS9xReportButtons(i, controlPad[i]); + } if (macControllerOption == SNES_JUSTIFIER_2) ControlPadFlagsToS9xPseudoPointer(controlPad[1]); From 3b5f04a5d19c901fd1f4e40d162b36a44e18d5be Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Wed, 15 Jan 2020 20:23:05 -0800 Subject: [PATCH 10/22] Fix joypads for multiple players --- macosx/Snes9x/AppDelegate.m | 10 ++++++++++ macosx/mac-joypad.mm | 6 ------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/macosx/Snes9x/AppDelegate.m b/macosx/Snes9x/AppDelegate.m index 40267439..82249616 100644 --- a/macosx/Snes9x/AppDelegate.m +++ b/macosx/Snes9x/AppDelegate.m @@ -140,6 +140,8 @@ static NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; [self setButtonCode:buttonCode forKeyCode:self.keys[control].integerValue player:player]; } + NSDictionary *joypadPlayerPrefs = [defaults objectForKey:kJoypadPlayerPrefs]; + for ( S9xJoypad *joypad in [self listJoypads]) { NSMutableDictionary *joypadPrefs = [[defaults objectForKey:kJoypadInputPrefs] mutableCopy]; @@ -152,6 +154,14 @@ static NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; NSString *key = [self prefsKeyForVendorID:joypad.vendorID productID:joypad.productID index:joypad.index]; + for ( NSString *playerString in joypadPlayerPrefs ) + { + if ( [key isEqualToString:joypadPlayerPrefs[playerString]] ) + { + [self setPlayer:playerString.intValue forVendorID:joypad.vendorID productID:joypad.productID index:joypad.index]; + } + } + NSMutableDictionary *devicePrefs = [joypadPrefs[key] mutableCopy]; if (devicePrefs == nil) { diff --git a/macosx/mac-joypad.mm b/macosx/mac-joypad.mm index 748d15f9..bf0042b3 100755 --- a/macosx/mac-joypad.mm +++ b/macosx/mac-joypad.mm @@ -753,12 +753,6 @@ void SetUpHID (void) { AddDevice((__bridge IOHIDDeviceRef)device); } - - if (orderedDevices.count == 1) - { - const struct JoypadDevice &deviceStruct = *(allDevices.begin()); - SetPlayerForJoypad(0, deviceStruct.vendorID, deviceStruct.productID, deviceStruct.index, NULL); - } } else { From c7a2fc2290467c330cc75ff549dc34c28622e29f Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Fri, 17 Jan 2020 06:30:23 -0800 Subject: [PATCH 11/22] Mac: Re-enable high resolution graphics --- macosx/mac-os.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index 54ae7e27..8361bffa 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -2547,7 +2547,7 @@ static void Initialize (void) Settings.Stereo = true; Settings.SoundPlaybackRate = 32000; Settings.SoundInputRate = 31950; - Settings.SupportHiRes = false; + Settings.SupportHiRes = true; Settings.Transparency = true; Settings.AutoDisplayMessages = true; Settings.InitialInfoStringTimeout = 120; From a35f6ce72040ee9b50152b92eb530cb859a39289 Mon Sep 17 00:00:00 2001 From: Eric Newport Date: Sat, 18 Jan 2020 13:54:00 -0500 Subject: [PATCH 12/22] Fix Super Scope typo --- macosx/Snes9x/S9xPrefsViewController.xib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macosx/Snes9x/S9xPrefsViewController.xib b/macosx/Snes9x/S9xPrefsViewController.xib index 60d60bed..b7e176a2 100644 --- a/macosx/Snes9x/S9xPrefsViewController.xib +++ b/macosx/Snes9x/S9xPrefsViewController.xib @@ -279,7 +279,7 @@ - + From 7f6d9d6432d912cd90763c64f7c92270b3e6c182 Mon Sep 17 00:00:00 2001 From: gocha Date: Sun, 19 Jan 2020 12:48:06 +0900 Subject: [PATCH 13/22] win32: fix compilation error in vs2019 --- conffile.cpp | 2 +- conffile.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/conffile.cpp b/conffile.cpp index 817afae7..fa7de3fa 100644 --- a/conffile.cpp +++ b/conffile.cpp @@ -452,7 +452,7 @@ void ConfigFile::ClearLines() } } -bool ConfigFile::ConfigEntry::section_then_key_less::operator()(const ConfigEntry &a, const ConfigEntry &b) { +bool ConfigFile::ConfigEntry::section_then_key_less::operator()(const ConfigEntry &a, const ConfigEntry &b) const{ if(curConfigFile && a.section!=b.section){ const int sva = curConfigFile->GetSectionSize(a.section); const int svb = curConfigFile->GetSectionSize(b.section); diff --git a/conffile.h b/conffile.h index ba69812d..d92128cb 100644 --- a/conffile.h +++ b/conffile.h @@ -90,7 +90,7 @@ class ConfigFile { mutable bool used; struct section_then_key_less { - bool operator()(const ConfigEntry &a, const ConfigEntry &b); + bool operator()(const ConfigEntry &a, const ConfigEntry &b) const; }; struct key_less { @@ -101,8 +101,8 @@ class ConfigFile { }; struct line_less { - bool operator()(const ConfigEntry &a, const ConfigEntry &b){ - if(a.line==b.line) return (b.val.empty() && !a.val.empty()) || a.key Date: Sun, 1 Mar 2020 16:59:00 -0800 Subject: [PATCH 14/22] Mac: Make metal layer inherit content sale from window to fix issues swapping between retina and non-retina monitors --- macosx/mac-render.mm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/macosx/mac-render.mm b/macosx/mac-render.mm index 74e7b1cf..ae2697ba 100644 --- a/macosx/mac-render.mm +++ b/macosx/mac-render.mm @@ -55,7 +55,18 @@ typedef struct vector_float2 textureCoordinate; } MetalVertex; +@interface MetalLayerDelegate: NSObject +@end + +@implementation MetalLayerDelegate +- (BOOL)layer:(CALayer *)layer shouldInheritContentsScale:(CGFloat)newScale fromWindow:(NSWindow *)window +{ + return YES; +} +@end + CAMetalLayer *metalLayer = nil; +MetalLayerDelegate *layerDelegate = nil; id metalDevice = nil; id metalTexture = nil; id metalCommandQueue = nil; @@ -147,6 +158,8 @@ static void S9xInitMetal (void) glScreenH = glScreenBounds.size.height; metalLayer = (CAMetalLayer *)s9xView.layer; + layerDelegate = [MetalLayerDelegate new]; + metalLayer.delegate = layerDelegate; metalDevice = s9xView.device; From 4d0b99ef12003ff9f1960ae8028b53eaf268baab Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Thu, 6 Feb 2020 06:21:22 -0800 Subject: [PATCH 15/22] Mac: Prevent centering analog stick from affecting hat values --- macosx/mac-joypad.mm | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/macosx/mac-joypad.mm b/macosx/mac-joypad.mm index 3c308f6b..140e452d 100755 --- a/macosx/mac-joypad.mm +++ b/macosx/mac-joypad.mm @@ -194,14 +194,26 @@ void gamepadAction(void *inContext, IOReturn inResult, void *inSender, IOHIDValu if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) { pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = true; - pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[oppositeInputStruct]] = false; + + if ( buttonCodeByJoypadInput.find(oppositeInputStruct) != buttonCodeByJoypadInput.end() ) + { + pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[oppositeInputStruct]] = false; + } + } else { oppositeInputStruct.value = info.min; - pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[oppositeInputStruct]] = false; + if ( buttonCodeByJoypadInput.find(oppositeInputStruct) != buttonCodeByJoypadInput.end() ) + { + pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[oppositeInputStruct]] = false; + } oppositeInputStruct.value = info.max; - pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[oppositeInputStruct]] = false; + + if ( buttonCodeByJoypadInput.find(oppositeInputStruct) != buttonCodeByJoypadInput.end() ) + { + pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[oppositeInputStruct]] = false; + } } } else if (info.usage == kHIDUsage_GD_Hatswitch) From d6a0fa8ea57cf7a4a0e9440bbe74052a3ac9564b Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Sun, 1 Mar 2020 17:19:06 -0800 Subject: [PATCH 16/22] Mac: Another fix to joypad hats --- macosx/mac-joypad.mm | 59 +++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/macosx/mac-joypad.mm b/macosx/mac-joypad.mm index 140e452d..78f4a5e8 100755 --- a/macosx/mac-joypad.mm +++ b/macosx/mac-joypad.mm @@ -229,37 +229,34 @@ void gamepadAction(void *inContext, IOReturn inResult, void *inSender, IOHIDValu } } - if (value >= info.min && value <= info.max) - { - if (value % 2 == 0) - { - inputStruct.value = value; - if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) - { - pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = true; - } - } - else - { - for (int i = value - 1; i <= value + 1; i++) - { - int button = i; - if (i < info.min) - { - button = info.max; - } - else if (i > info.max) - { - button = info.min; - } - inputStruct.value = button; - if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) - { - pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = true; - } - } - } - } + if (value % 2 == 0) + { + inputStruct.value = value; + if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) + { + pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = true; + } + } + else + { + for (int i = value - 1; i <= value + 1; i++) + { + int button = i; + if (i < info.min) + { + button = info.max; + } + else if (i > info.max) + { + button = info.min; + } + inputStruct.value = button; + if (buttonCodeByJoypadInput.find(inputStruct) != buttonCodeByJoypadInput.end()) + { + pressedGamepadButtons[playerNum][buttonCodeByJoypadInput[inputStruct]] = true; + } + } + } } else { From 7d028a4e74c6a4d5911ba8e39c2358a3149b6b97 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Wed, 18 Mar 2020 17:22:39 -0700 Subject: [PATCH 17/22] Mac: Fix window redraw crash --- macosx/Snes9x/AppDelegate.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/macosx/Snes9x/AppDelegate.m b/macosx/Snes9x/AppDelegate.m index 82249616..1b462171 100644 --- a/macosx/Snes9x/AppDelegate.m +++ b/macosx/Snes9x/AppDelegate.m @@ -129,6 +129,8 @@ static NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; }; [defaults registerDefaults:defaultSettings]; + [defaults setBool:NO forKey:@"NSWindowAssertWhenDisplayCycleLimitReached"]; + [defaults synchronize]; self.keys = [[defaults objectForKey:kKeyboardPrefs] mutableCopy]; From a4b207cbaaf7625a51815fb9d7de42383d37ce08 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Wed, 18 Mar 2020 17:22:51 -0700 Subject: [PATCH 18/22] Mac: Always save SRAM on window close and quit --- macosx/Snes9x/AppDelegate.m | 4 ++-- macosx/mac-os.h | 1 + macosx/mac-os.mm | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/macosx/Snes9x/AppDelegate.m b/macosx/Snes9x/AppDelegate.m index 1b462171..46575a5a 100644 --- a/macosx/Snes9x/AppDelegate.m +++ b/macosx/Snes9x/AppDelegate.m @@ -68,12 +68,12 @@ static NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; [NSNotificationCenter.defaultCenter addObserverForName:NSWindowWillCloseNotification object:window queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *notification) { - [self.s9xEngine pause]; + [self.s9xEngine quit]; }]; } - (void)applicationWillTerminate:(NSNotification *)aNotification { - // Insert code here to tear down your application + [self.s9xEngine quit]; } - (void)setupDefaults diff --git a/macosx/mac-os.h b/macosx/mac-os.h index 76687519..e0eebf10 100644 --- a/macosx/mac-os.h +++ b/macosx/mac-os.h @@ -167,6 +167,7 @@ extern id inputDelegate; - (BOOL)isRunning; - (BOOL)isPaused; - (void)pause; +- (void)quit; - (void)resume; - (BOOL)setButton:(S9xButtonCode)button forKey:(int16)key player:(int8)player oldButton:(S9xButtonCode *)oldButton oldPlayer:(int8 *)oldPlayer oldKey:(int16 *)oldKey; diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index 8361bffa..09f98c40 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -3015,6 +3015,7 @@ void QuitWithFatalError ( NSString *message) - (void)stop { + SNES9X_Quit(); S9xExit(); } @@ -3034,6 +3035,12 @@ void QuitWithFatalError ( NSString *message) [s9xView setNeedsDisplay:YES]; } +- (void)quit +{ + SNES9X_Quit(); + [self pause]; +} + - (void)resume { pauseEmulation = false; From 09dc8f19c0ffa155346847c0fe2e174fcef6022b Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Wed, 18 Mar 2020 17:54:18 -0700 Subject: [PATCH 19/22] Mac: Fix pause fade after closing and reopening window --- macosx/mac-os.h | 5 ++++- macosx/mac-os.mm | 27 ++++++++++++++++----------- macosx/mac-render.mm | 1 + 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/macosx/mac-os.h b/macosx/mac-os.h index e0eebf10..2e094fbd 100644 --- a/macosx/mac-os.h +++ b/macosx/mac-os.h @@ -124,7 +124,10 @@ extern bool8 pressedKeys[MAC_MAX_PLAYERS][kNumButtons]; extern bool8 pressedGamepadButtons[MAC_MAX_PLAYERS][kNumButtons]; extern pthread_mutex_t keyLock; -extern MTKView *s9xView; +@interface S9xView: MTKView +- (void)updatePauseOverlay; +@end +extern S9xView *s9xView; void AdjustMenus (void); void UpdateMenuCommandStatus (Boolean); diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index 09f98c40..b74454a7 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -219,7 +219,7 @@ bool8 pressedRawKeyboardButtons[MAC_NUM_KEYCODES] = { 0 }; bool8 heldFunctionButtons[kNumFunctionButtons] = { 0 }; pthread_mutex_t keyLock; -MTKView *s9xView; +S9xView *s9xView; enum { @@ -348,6 +348,8 @@ static inline void EmulationLoop (void) pauseEmulation = false; frameAdvance = false; + [s9xView updatePauseOverlay]; + if (macQTRecord) { @@ -2218,6 +2220,7 @@ static void ProcessInput (void) case ToggleEmulationPause: pauseEmulation = !pauseEmulation; + [s9xView updatePauseOverlay]; break; case AdvanceFrame: @@ -2239,6 +2242,7 @@ static void ProcessInput (void) if (ISpKeyIsPressed(keys, gamepadButtons, kISpEsc)) { pauseEmulation = true; + [s9xView updatePauseOverlay]; dispatch_async(dispatch_get_main_queue(), ^ { @@ -2796,9 +2800,6 @@ void QuitWithFatalError ( NSString *message) [NSApp terminate:nil]; } -@interface S9xView : MTKView -@end - @implementation S9xView + (void)initialize @@ -2929,15 +2930,18 @@ void QuitWithFatalError ( NSString *message) - (void)mouseDown:(NSEvent *)event { pauseEmulation = true; - [self setNeedsDisplay:YES]; + [s9xView updatePauseOverlay]; } -- (void)drawRect:(NSRect)dirtyRect +- (void)updatePauseOverlay { - self.subviews[0].hidden = !pauseEmulation; - CGFloat scaleFactor = MAX(self.window.backingScaleFactor, 1.0); - glScreenW = self.frame.size.width * scaleFactor; - glScreenH = self.frame.size.height * scaleFactor; + dispatch_async(dispatch_get_main_queue(), ^{ + NSLog(@"%d", pauseEmulation); + self.subviews[0].hidden = !pauseEmulation; + CGFloat scaleFactor = MAX(self.window.backingScaleFactor, 1.0); + glScreenW = self.frame.size.width * scaleFactor; + glScreenH = self.frame.size.height * scaleFactor; + }); } - (void)setFrame:(NSRect)frame @@ -3032,7 +3036,7 @@ void QuitWithFatalError ( NSString *message) - (void)pause { pauseEmulation = true; - [s9xView setNeedsDisplay:YES]; + [s9xView updatePauseOverlay]; } - (void)quit @@ -3044,6 +3048,7 @@ void QuitWithFatalError ( NSString *message) - (void)resume { pauseEmulation = false; + [s9xView updatePauseOverlay]; } - (NSArray *)listJoypads diff --git a/macosx/mac-render.mm b/macosx/mac-render.mm index ae2697ba..3ce4e9a1 100644 --- a/macosx/mac-render.mm +++ b/macosx/mac-render.mm @@ -63,6 +63,7 @@ typedef struct { return YES; } + @end CAMetalLayer *metalLayer = nil; From bdd7db354d86b5319a8bb3654d96f3858d3f4acc Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Wed, 18 Mar 2020 20:14:57 -0700 Subject: [PATCH 20/22] Mac: Fix redraw issues on dual monitor setups when closing and reopening the window --- macosx/Snes9x/AppDelegate.m | 19 +++++++++++-------- macosx/mac-os.h | 2 ++ macosx/mac-os.mm | 25 ++++++++++++++++--------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/macosx/Snes9x/AppDelegate.m b/macosx/Snes9x/AppDelegate.m index 46575a5a..ccc206a6 100644 --- a/macosx/Snes9x/AppDelegate.m +++ b/macosx/Snes9x/AppDelegate.m @@ -52,13 +52,6 @@ static NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; window.frameAutosaveName = kMainWindowIdentifier; window.releasedWhenClosed = NO; - [window.contentView addSubview:s9xView]; - [s9xView.topAnchor constraintEqualToAnchor:window.contentView.topAnchor].active = YES; - [s9xView.bottomAnchor constraintEqualToAnchor:window.contentView.bottomAnchor].active = YES; - [s9xView.centerXAnchor constraintEqualToAnchor:window.contentView.centerXAnchor].active = YES; - [s9xView.leftAnchor constraintGreaterThanOrEqualToAnchor:window.contentView.leftAnchor].active = YES; - [s9xView.rightAnchor constraintLessThanOrEqualToAnchor:window.contentView.rightAnchor].active = YES; - if ( ![window setFrameUsingName:kMainWindowIdentifier] ) { [window center]; @@ -456,8 +449,18 @@ static NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; { if ([self.s9xEngine loadROM:url]) { + [self.s9xEngine recreateS9xView]; + + NSWindow *window = self.window; + [window.contentView addSubview:s9xView]; + [s9xView.topAnchor constraintEqualToAnchor:window.contentView.topAnchor].active = YES; + [s9xView.bottomAnchor constraintEqualToAnchor:window.contentView.bottomAnchor].active = YES; + [s9xView.centerXAnchor constraintEqualToAnchor:window.contentView.centerXAnchor].active = YES; + [s9xView.leftAnchor constraintGreaterThanOrEqualToAnchor:window.contentView.leftAnchor].active = YES; + [s9xView.rightAnchor constraintLessThanOrEqualToAnchor:window.contentView.rightAnchor].active = YES; - [self.window makeKeyAndOrderFront:self]; + + [window makeKeyAndOrderFront:self]; [NSDocumentController.sharedDocumentController noteNewRecentDocumentURL:url]; return YES; } diff --git a/macosx/mac-os.h b/macosx/mac-os.h index 2e094fbd..3b6e9e9f 100644 --- a/macosx/mac-os.h +++ b/macosx/mac-os.h @@ -164,6 +164,8 @@ extern id inputDelegate; @property (nonatomic, weak) id inputDelegate; +- (void)recreateS9xView; + - (void)start; - (void)stop; diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index b74454a7..9828acd7 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -2976,15 +2976,7 @@ void QuitWithFatalError ( NSString *message) if (self = [super init]) { Initialize(); - - CGRect frame = NSMakeRect(0, 0, SNES_WIDTH * 2, SNES_HEIGHT * 2); - s9xView = [[S9xView alloc] initWithFrame:frame]; - s9xView.translatesAutoresizingMaskIntoConstraints = NO; - s9xView.autoresizingMask = NSViewWidthSizable|NSViewHeightSizable; - [s9xView addConstraint:[NSLayoutConstraint constraintWithItem:s9xView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:s9xView attribute:NSLayoutAttributeWidth multiplier:(CGFloat)SNES_HEIGHT/(CGFloat)SNES_WIDTH constant:0.0]]; - [s9xView addConstraint:[NSLayoutConstraint constraintWithItem:s9xView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:SNES_WIDTH * 2.0]]; - [s9xView addConstraint:[NSLayoutConstraint constraintWithItem:s9xView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:SNES_HEIGHT * 2.0]]; - s9xView.device = MTLCreateSystemDefaultDevice(); + [self recreateS9xView]; } return self; @@ -2995,6 +2987,21 @@ void QuitWithFatalError ( NSString *message) Deinitialize(); } +- (void)recreateS9xView +{ + [s9xView removeFromSuperview]; + S9xDeinitDisplay(); + CGRect frame = NSMakeRect(0, 0, SNES_WIDTH * 2, SNES_HEIGHT * 2); + s9xView = [[S9xView alloc] initWithFrame:frame]; + s9xView.translatesAutoresizingMaskIntoConstraints = NO; + s9xView.autoresizingMask = NSViewWidthSizable|NSViewHeightSizable; + [s9xView addConstraint:[NSLayoutConstraint constraintWithItem:s9xView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:s9xView attribute:NSLayoutAttributeWidth multiplier:(CGFloat)SNES_HEIGHT/(CGFloat)SNES_WIDTH constant:0.0]]; + [s9xView addConstraint:[NSLayoutConstraint constraintWithItem:s9xView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:SNES_WIDTH * 2.0]]; + [s9xView addConstraint:[NSLayoutConstraint constraintWithItem:s9xView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:SNES_HEIGHT * 2.0]]; + s9xView.device = MTLCreateSystemDefaultDevice(); + S9xInitDisplay(NULL, NULL); +} + - (void)start { #ifdef DEBUGGER From a70aa17c564f96ef6a10118f5c40d9e5ffe374c5 Mon Sep 17 00:00:00 2001 From: Paul Brannan Date: Tue, 31 Mar 2020 06:35:29 -0400 Subject: [PATCH 21/22] Increase SRAM size to 512KB Increased SRAM size from 128KB to 512KB. This fixes a crash in the emulator when writing to SRAM between addresses $720000 and $7DFFFF. --- memmap.cpp | 4 ++-- snapshot.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/memmap.cpp b/memmap.cpp index e29fab4d..1178e889 100644 --- a/memmap.cpp +++ b/memmap.cpp @@ -894,7 +894,7 @@ static void S9xDeinterleaveGD24 (int size, uint8 *base) bool8 CMemory::Init (void) { RAM = (uint8 *) malloc(0x20000); - SRAM = (uint8 *) malloc(0x20000); + SRAM = (uint8 *) malloc(0x80000); VRAM = (uint8 *) malloc(0x10000); ROM = (uint8 *) malloc(MAX_ROM_SIZE + 0x200 + 0x8000); @@ -935,7 +935,7 @@ bool8 CMemory::Init (void) } memset(RAM, 0, 0x20000); - memset(SRAM, 0, 0x20000); + memset(SRAM, 0, 0x80000); memset(VRAM, 0, 0x10000); memset(ROM, 0, MAX_ROM_SIZE + 0x200 + 0x8000); diff --git a/snapshot.cpp b/snapshot.cpp index 84dd9c41..b2a845da 100644 --- a/snapshot.cpp +++ b/snapshot.cpp @@ -1199,7 +1199,7 @@ void S9xFreezeToStream (STREAM stream) FreezeBlock (stream, "RAM", Memory.RAM, 0x20000); - FreezeBlock (stream, "SRA", Memory.SRAM, 0x20000); + FreezeBlock (stream, "SRA", Memory.SRAM, 0x80000); FreezeBlock (stream, "FIL", Memory.FillRAM, 0x8000); @@ -1404,9 +1404,9 @@ int S9xUnfreezeFromStream (STREAM stream) break; if (fast) - result = UnfreezeBlock(stream, "SRA", Memory.SRAM, 0x20000); + result = UnfreezeBlock(stream, "SRA", Memory.SRAM, 0x80000); else - result = UnfreezeBlockCopy (stream, "SRA", &local_sram, 0x20000); + result = UnfreezeBlockCopy (stream, "SRA", &local_sram, 0x80000); if (result != SUCCESS) break; @@ -1576,7 +1576,7 @@ int S9xUnfreezeFromStream (STREAM stream) memcpy(Memory.RAM, local_ram, 0x20000); if (local_sram) - memcpy(Memory.SRAM, local_sram, 0x20000); + memcpy(Memory.SRAM, local_sram, 0x80000); if (local_fillram) memcpy(Memory.FillRAM, local_fillram, 0x8000); From 995f0be52ca73f11d33b0d79e97f043b6bffe2e0 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Sun, 7 Jun 2020 15:38:01 -0500 Subject: [PATCH 22/22] SA1: Remove memory remapping at load state. This fixes the Mega Man X SA1 patch. --- sa1.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sa1.cpp b/sa1.cpp index aa008590..e56bf6ad 100644 --- a/sa1.cpp +++ b/sa1.cpp @@ -117,10 +117,12 @@ void S9xSA1PostLoadState (void) SA1.VirtualBitmapFormat = (Memory.FillRAM[0x223f] & 0x80) ? 2 : 4; Memory.BWRAM = Memory.SRAM + (Memory.FillRAM[0x2224] & 0x1f) * 0x2000; S9xSA1SetBWRAMMemMap(Memory.FillRAM[0x2225]); +#if 0 S9xSetSA1(Memory.FillRAM[0x2220], 0x2220); S9xSetSA1(Memory.FillRAM[0x2221], 0x2221); S9xSetSA1(Memory.FillRAM[0x2222], 0x2222); S9xSetSA1(Memory.FillRAM[0x2223], 0x2223); +#endif } static void S9xSetSA1MemMap (uint32 which1, uint8 map) @@ -168,7 +170,7 @@ static void S9xSetSA1MemMap (uint32 which1, uint8 map) { offset = (((map & 0x80) ? (map - 4) : which1) & 7) * 0x100000 + (c << 11) - 0x8000; block = Memory.ROM + Multi.cartOffsetB + offset; - } + } } for (int i = c + 8; i < c + 16; i++) Memory.Map[start2 + i] = SA1.Map[start2 + i] = block;