Skip to content

feature: add ppu settings #1849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ares/fc/ppu/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ auto PPU::writeIO(n16 address, n8 data) -> void {
//PPUCTRL
case 0:
scroll.nametable = data.bit(0,1);
if (io.lx == 257 && rendering())
if (ctrlGlitch->value() && io.lx == 257 && rendering())
var.nametableX = cpu.io.openBus.bit(0);

io.vramIncrement = data.bit(2) ? 32 : 1;
Expand Down Expand Up @@ -145,7 +145,7 @@ auto PPU::writeIO(n16 address, n8 data) -> void {
scroll.fineX = data.bit(0,2);
scroll.tileX = data.bit(3,7);

if (io.lx == 257 && rendering())
if (oamScrollGlitch->value() && io.lx == 257 && rendering())
var.tileX = cpu.io.openBus.bit(3,7);
} else {
scroll.fineY = data.bit(0,2);
Expand All @@ -157,7 +157,7 @@ auto PPU::writeIO(n16 address, n8 data) -> void {
case 6:
if(scroll.latch++ == 0) {
scroll.addressHi = data.bit(0,5);
if (io.lx == 257 && rendering())
if (oamAddressGlitch->value() && io.lx == 257 && rendering())
var.nametable = cpu.io.openBus.bit(2,3);
} else {
scroll.addressLo = data.bit(0,7);
Expand Down
12 changes: 12 additions & 0 deletions ares/fc/ppu/ppu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,25 @@ auto PPU::load(Node::Object parent) -> void {
Region::PAL() ? screen->setAspect(55.0, 43.0) :screen->setAspect(8.0, 7.0);
screen->refreshRateHint(system.frequency() / rate(), 341, vlines());

ctrlGlitch = node->append<Node::Setting::Boolean>("Control Glitch", false);
ctrlGlitch->setDynamic(false);

oamScrollGlitch = node->append<Node::Setting::Boolean>("OAM Scroll Glitch", false);
oamScrollGlitch->setDynamic(false);

oamAddressGlitch = node->append<Node::Setting::Boolean>("OAM Address Glitch", false);
oamAddressGlitch->setDynamic(false);

debugger.load(node);
}

auto PPU::unload() -> void {
screen->quit();
node->remove(screen);
debugger.unload();
ctrlGlitch.reset();
oamScrollGlitch.reset();
oamAddressGlitch.reset();
screen.reset();
node.reset();
ciram.reset();
Expand Down
4 changes: 4 additions & 0 deletions ares/fc/ppu/ppu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ struct PPU : Thread {
Memory::Writable<n8> oam;
Memory::Writable<n8> soam;

Node::Setting::Boolean ctrlGlitch;
Node::Setting::Boolean oamScrollGlitch;
Node::Setting::Boolean oamAddressGlitch;

struct Debugger {
//debugger.cpp
auto load(Node::Object) -> void;
Expand Down
20 changes: 20 additions & 0 deletions desktop-ui/emulator/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,26 @@ auto Emulator::unload() -> void {
locationQueue.reset();
}

auto Emulator::process(bool load) -> void {
#define bind(type, path, name) \
if(load) { \
if(auto node = settings[path]) name = node.type(); \
} else { \
settings(path).setValue(name); \
}\

string base = string{name}.replace(" ", "");
string name = {base, "/Visible"};
bind(boolean, name, configuration.visible);
for (auto& firmware : firmware) {
string name = {base, "/Firmware/", firmware.type, ".", firmware.region};
name.replace(" ", "-");
bind(string, name, firmware.location);
}

#undef bind
}

auto Emulator::load(mia::Pak& node, string name) -> bool {
if(auto fp = node.pak->read(name)) {
if(auto memory = file::read({node.location, name})) {
Expand Down
1 change: 1 addition & 0 deletions desktop-ui/emulator/emulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct Emulator {
auto load(shared_pointer<mia::Pak> pak, string& path) -> string;
auto loadFirmware(const Firmware&) -> shared_pointer<vfs::file>;
virtual auto unload() -> void;
virtual auto process(bool load) -> void;
auto refresh() -> void;
auto setBoolean(const string& name, bool value) -> bool;
auto setOverscan(bool value) -> bool;
Expand Down
66 changes: 66 additions & 0 deletions desktop-ui/emulator/famicom.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
struct Famicom : Emulator {
Famicom();
auto process(bool load) -> void override;
auto load() -> LoadResult override;
auto load(Menu menu) -> void override;
auto save() -> bool override;
auto pak(ares::Node::Object) -> shared_pointer<vfs::directory> override;

struct Settings {
bool ppuCtrlGlitch = false;
bool ppuOamScrollGlitch = false;
bool ppuOamAddressGlitch = false;
} local;
};

Famicom::Famicom() {
Expand Down Expand Up @@ -35,6 +43,26 @@ Famicom::Famicom() {
}
}

auto Famicom::process(bool load) -> void {
Emulator::process(load);
#define bind(type, path, name) \
if(load) { \
if(auto node = settings[path]) name = node.type(); \
} else { \
settings(path).setValue(name); \
}\

string base = string{name}.replace(" ", "");
string name = {base, "/PPU/ControlGlitch"};
bind(boolean, name, local.ppuCtrlGlitch);
name = {base, "/PPU/OAMScrollGlitch"};
bind(boolean, name, local.ppuOamScrollGlitch);
name = {base, "/PPU/OAMAddressGlitch"};
bind(boolean, name, local.ppuOamAddressGlitch);

#undef bind
}

auto Famicom::load() -> LoadResult {
game = mia::Medium::create("Famicom");
string location = Emulator::load(game, configuration.game);
Expand Down Expand Up @@ -74,6 +102,44 @@ auto Famicom::load() -> LoadResult {
return successful;
}

auto Famicom::load(Menu menu) -> void {
Menu ppuEmulationMenu{&menu};
ppuEmulationMenu.setText("PPU Emulation").setIcon(Icon::Device::Display);

if(auto ppuCtrlGlitch = root->find<ares::Node::Setting::Boolean>("PPU/Control Glitch")) {
MenuCheckItem item{&ppuEmulationMenu};
ppuCtrlGlitch->setValue(local.ppuCtrlGlitch);
item.setText("Control Glitch").setChecked(ppuCtrlGlitch->value()).onToggle([=] {
if(auto ppuCtrlGlitch = root->find<ares::Node::Setting::Boolean>("PPU/Control Glitch")) {
local.ppuCtrlGlitch = item.checked();
ppuCtrlGlitch->setValue(item.checked());
}
});
}

if(auto ppuOamScrollGlitch = root->find<ares::Node::Setting::Boolean>("PPU/OAM Scroll Glitch")) {
MenuCheckItem item{&ppuEmulationMenu};
ppuOamScrollGlitch->setValue(local.ppuOamScrollGlitch);
item.setText("OAM Scroll Glitch").setChecked(ppuOamScrollGlitch->value()).onToggle([=] {
if(auto ppuOamScrollGlitch = root->find<ares::Node::Setting::Boolean>("PPU/OAM Scroll Glitch")) {
local.ppuOamScrollGlitch = item.checked();
ppuOamScrollGlitch->setValue(item.checked());
}
});
}

if(auto ppuOamAddressGlitch = root->find<ares::Node::Setting::Boolean>("PPU/OAM Address Glitch")) {
MenuCheckItem item{&ppuEmulationMenu};
ppuOamAddressGlitch->setValue(local.ppuOamAddressGlitch);
item.setText("OAM Address Glitch").setChecked(ppuOamAddressGlitch->value()).onToggle([=] {
if(auto ppuOamAddressGlitch = root->find<ares::Node::Setting::Boolean>("PPU/OAM Address Glitch")) {
local.ppuOamAddressGlitch = item.checked();
ppuOamAddressGlitch->setValue(item.checked());
}
});
}
}

auto Famicom::save() -> bool {
root->save();
system->save(system->location);
Expand Down
8 changes: 6 additions & 2 deletions desktop-ui/presentation/presentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,16 @@ auto Presentation::loadEmulator() -> void {
}

auto Presentation::refreshSystemMenu() -> void {
int submenuCount = 0;
systemMenu.reset();

//allow each emulator core to create any specialized menus necessary:
//for instance, floppy disk and CD-ROM swapping support.
emulator->load(systemMenu);
if(systemMenu.actionCount() > 0) systemMenu.append(MenuSeparator());
if(systemMenu.actionCount() > submenuCount) {
systemMenu.append(MenuSeparator());
submenuCount = 2;
}

//Build the Dip Switch menu if the emulator core has a DIP Switches node
if(auto dipSwitches = ares::Node::find<ares::Node::Object>(emulator->root, "DIP Switches")) {
Expand Down Expand Up @@ -516,7 +520,7 @@ auto Presentation::refreshSystemMenu() -> void {

if(dipSwitchMenu.actionCount() > 0) systemMenu.append(dipSwitchMenu);
}
if(systemMenu.actionCount() > 0) systemMenu.append(MenuSeparator());
if(systemMenu.actionCount() > submenuCount) systemMenu.append(MenuSeparator());

u32 portsFound = 0;
for(auto port : ares::Node::enumerate<ares::Node::Port>(emulator->root)) {
Expand Down
14 changes: 2 additions & 12 deletions desktop-ui/settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,8 @@ auto Settings::process(bool load) -> void {
if(load == 1) for(u32 binding : range(BindingLimit)) mapping.assignments[binding] = value.split(";")(binding);
}

for(auto& emulator : emulators) {
string base = string{emulator->name}.replace(" ", ""), name;
name = {base, "/Visible"};
bind(boolean, name, emulator->configuration.visible);
name = {base, "/Path"};
bind(string, name, emulator->configuration.game);
for(auto& firmware : emulator->firmware) {
string name = {base, "/Firmware/", firmware.type, ".", firmware.region};
name.replace(" ", "-");
bind(string, name, firmware.location);
}
}
for(auto& emulator : emulators)
emulator->process(load);

#undef bind
}
Expand Down
Loading