#include namespace WonderSwan { Interface* interface = nullptr; Settings settings; Interface::Interface() { interface = this; information.manufacturer = "Bandai"; information.name = "WonderSwan"; information.width = 224; //note: technically 224x144; but screen can be rotated information.height = 224; //by using a square size; this can be done in the core information.overscan = false; information.aspectRatio = 1.0; information.resettable = false; information.capability.states = true; information.capability.cheats = true; media.append({ID::WonderSwan, "WonderSwan", "ws" }); media.append({ID::WonderSwanColor, "WonderSwan Color", "wsc"}); Port hardwarePort{ID::Port::Hardware, "Hardware"}; { Device device{ID::Device::HorizontalControls, "Horizontal Controls"}; device.inputs.append({0, "Y1"}); device.inputs.append({0, "Y2"}); device.inputs.append({0, "Y3"}); device.inputs.append({0, "Y4"}); device.inputs.append({0, "X1"}); device.inputs.append({0, "X2"}); device.inputs.append({0, "X3"}); device.inputs.append({0, "X4"}); device.inputs.append({0, "B"}); device.inputs.append({0, "A"}); device.inputs.append({0, "Start"}); device.inputs.append({0, "Rotate"}); hardwarePort.devices.append(device); } { Device device{ID::Device::VerticalControls, "Vertical Controls"}; device.inputs.append({0, "Y1"}); device.inputs.append({0, "Y2"}); device.inputs.append({0, "Y3"}); device.inputs.append({0, "Y4"}); device.inputs.append({0, "X1"}); device.inputs.append({0, "X2"}); device.inputs.append({0, "X3"}); device.inputs.append({0, "X4"}); device.inputs.append({0, "B"}); device.inputs.append({0, "A"}); device.inputs.append({0, "Start"}); device.inputs.append({0, "Rotate"}); hardwarePort.devices.append(device); } ports.append(move(hardwarePort)); } auto Interface::manifest() -> string { return cartridge.information.manifest; } auto Interface::title() -> string { return cartridge.information.title; } auto Interface::videoFrequency() -> double { return 3072000.0 / (159.0 * 256.0); //~75.47hz } auto Interface::videoColors() -> uint32 { return 1 << 12; } auto Interface::videoColor(uint32 color) -> uint64 { uint b = color.bits(0, 3); uint g = color.bits(4, 7); uint r = color.bits(8,11); uint64_t R = image::normalize(r, 4, 16); uint64_t G = image::normalize(g, 4, 16); uint64_t B = image::normalize(b, 4, 16); if(settings.colorEmulation) { R = (r * 26 + g * 4 + b * 2); G = ( g * 24 + b * 8); B = (r * 6 + g * 4 + b * 22); R = image::normalize(min(480, R), 9, 16); G = image::normalize(min(480, G), 9, 16); B = image::normalize(min(480, B), 9, 16); } return R << 32 | G << 16 | B << 0; } auto Interface::audioFrequency() -> double { return 3072000.0; } auto Interface::loaded() -> bool { return system.loaded(); } auto Interface::sha256() -> string { return cartridge.information.sha256; } auto Interface::load(uint id) -> bool { if(id == ID::WonderSwan) return system.load(Model::WonderSwan); if(id == ID::WonderSwanColor) return system.load(Model::WonderSwanColor); return false; } auto Interface::save() -> void { system.save(); } auto Interface::unload() -> void { save(); system.unload(); } auto Interface::power() -> void { system.power(); } auto Interface::run() -> void { system.run(); } auto Interface::serialize() -> serializer { system.runToSave(); return system.serialize(); } auto Interface::unserialize(serializer& s) -> bool { return system.unserialize(s); } auto Interface::cheatSet(const lstring& list) -> void { cheat.reset(); for(auto& codeset : list) { lstring codes = codeset.split("+"); for(auto& code : codes) { lstring part = code.split("/"); if(part.size() == 2) cheat.append(hex(part[0]), hex(part[1])); if(part.size() == 3) cheat.append(hex(part[0]), hex(part[1]), hex(part[2])); } } } auto Interface::cap(const string& name) -> bool { if(name == "Blur Emulation") return true; if(name == "Color Emulation") return true; return false; } auto Interface::get(const string& name) -> any { if(name == "Blur Emulation") return settings.blurEmulation; if(name == "Color Emulation") return settings.colorEmulation; return {}; } auto Interface::set(const string& name, const any& value) -> bool { if(name == "Blur Emulation" && value.is()) { settings.blurEmulation = value.get(); system.configureVideoEffects(); return true; } if(name == "Color Emulation" && value.is()) { settings.colorEmulation = value.get(); system.configureVideoPalette(); return true; } return false; } }