From a7b30b069c702894cdeb70a95ca44fa89dbb9b88 Mon Sep 17 00:00:00 2001 From: byuu <2107894+byuu@users.noreply.github.com> Date: Thu, 1 Aug 2019 01:10:27 +0900 Subject: [PATCH] Fix blur emulation in the accurate PPU mode. --- bsnes/sfc/ppu/ppu.cpp | 10 ++++++++++ bsnes/target-bsnes/presentation/presentation.cpp | 2 +- bsnes/target-bsnes/program/game.cpp | 1 + bsnes/target-bsnes/program/program.hpp | 1 + bsnes/target-bsnes/program/video.cpp | 4 ++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bsnes/sfc/ppu/ppu.cpp b/bsnes/sfc/ppu/ppu.cpp index 3f5b050a..7c2b15ab 100644 --- a/bsnes/sfc/ppu/ppu.cpp +++ b/bsnes/sfc/ppu/ppu.cpp @@ -250,6 +250,16 @@ auto PPU::refresh() -> void { auto pitch = 512; auto width = 512; auto height = 480; + if(configuration.video.blurEmulation) { + for(uint y : range(height)) { + auto data = output + y * pitch; + for(uint x : range(width - 1)) { + auto a = data[x + 0]; + auto b = data[x + 1]; + data[x] = (a + b - ((a ^ b) & 0x0421)) >> 1; + } + } + } if(auto device = controllerPort2.device) device->draw(output, pitch * sizeof(uint16), width, height); platform->videoFrame(output, pitch * sizeof(uint16), width, height, /* scale = */ 1); } diff --git a/bsnes/target-bsnes/presentation/presentation.cpp b/bsnes/target-bsnes/presentation/presentation.cpp index 3be8b9a2..076078af 100644 --- a/bsnes/target-bsnes/presentation/presentation.cpp +++ b/bsnes/target-bsnes/presentation/presentation.cpp @@ -50,7 +50,7 @@ auto Presentation::create() -> void { }); blurEmulation.setText("Blur Emulation").setChecked(settings.video.blur).onToggle([&] { settings.video.blur = blurEmulation.checked(); - emulator->configure("Video/BlurEmulation", blurEmulation.checked()); + emulator->configure("Video/BlurEmulation", settings.video.blur); }).doToggle(); filterMenu.setIcon(Icon::Emblem::Image).setText("Filter"); filterNone.setText("None").onActivate([&] { settings.video.filter = "None"; }); diff --git a/bsnes/target-bsnes/program/game.cpp b/bsnes/target-bsnes/program/game.cpp index e11709ed..d8988392 100644 --- a/bsnes/target-bsnes/program/game.cpp +++ b/bsnes/target-bsnes/program/game.cpp @@ -70,6 +70,7 @@ auto Program::load() -> void { presentation.addRecentGame(games.trimRight("|", 1L)); updateVideoPalette(); + updateVideoEffects(); updateAudioEffects(); updateAudioFrequency(); } diff --git a/bsnes/target-bsnes/program/program.hpp b/bsnes/target-bsnes/program/program.hpp index 7fcc8299..b2072257 100644 --- a/bsnes/target-bsnes/program/program.hpp +++ b/bsnes/target-bsnes/program/program.hpp @@ -95,6 +95,7 @@ struct Program : Lock, Emulator::Platform { auto updateVideoFormat() -> void; auto updateVideoShader() -> void; auto updateVideoPalette() -> void; + auto updateVideoEffects() -> void; //audio.cpp auto updateAudioDriver(Window parent) -> void; diff --git a/bsnes/target-bsnes/program/video.cpp b/bsnes/target-bsnes/program/video.cpp index 55777ba3..29288217 100644 --- a/bsnes/target-bsnes/program/video.cpp +++ b/bsnes/target-bsnes/program/video.cpp @@ -110,3 +110,7 @@ auto Program::updateVideoPalette() -> void { emulator->configure("Video/ColorEmulation", false); } + +auto Program::updateVideoEffects() -> void { + emulator->configure("Video/BlurEmulation", settings.video.blur); +}