From a9571ff5b8abc9a7430b8aba219a15edf731b911 Mon Sep 17 00:00:00 2001 From: Talarubi Date: Mon, 23 Oct 2017 16:59:29 -0400 Subject: [PATCH] Fixed: Restore SPC7110 and S-RTC time properly Loading and unloading the RTC is a little odd, since it's normally always powered in the first place. What we want, and what the load() functions really do, is to resync using the saved timestamps or reset it. unload() proper doesn't do anything. However, an interface refactoring after v098 reordered the above operations, and this (along with a typo, shh!) was causing the already synced time to be cleared. I've added checks so that whenever rtc.ram can't be found, load() gets called with empty arguments to initialise the defaults (like putting in a fresh battery). --- higan/sfc/cartridge/load.cpp | 10 ++++++++-- higan/sfc/coprocessor/sharprtc/sharprtc.cpp | 2 -- higan/sfc/system/system.cpp | 4 ---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/higan/sfc/cartridge/load.cpp b/higan/sfc/cartridge/load.cpp index a66ff00b..7c2c31ee 100644 --- a/higan/sfc/cartridge/load.cpp +++ b/higan/sfc/cartridge/load.cpp @@ -261,9 +261,12 @@ auto Cartridge::loadEpsonRTC(Markup::Node node) -> void { if(auto fp = platform->open(ID::SuperFamicom, node["ram"]["name"].text(), File::Read)) { uint8 data[16] = {0}; - for(auto& byte : data) fp->read(); + for(auto& byte : data) byte = fp->read(); epsonrtc.load(data); } + else { + epsonrtc.load(); + } for(auto leaf : node.find("map")) loadMap(leaf, {&EpsonRTC::read, &epsonrtc}, {&EpsonRTC::write, &epsonrtc}); } @@ -273,9 +276,12 @@ auto Cartridge::loadSharpRTC(Markup::Node node) -> void { if(auto fp = platform->open(ID::SuperFamicom, node["ram"]["name"].text(), File::Read)) { uint8 data[16] = {0}; - for(auto& byte : data) fp->read(); + for(auto& byte : data) byte = fp->read(); sharprtc.load(data); } + else { + sharprtc.load(); + } for(auto leaf : node.find("map")) loadMap(leaf, {&SharpRTC::read, &sharprtc}, {&SharpRTC::write, &sharprtc}); } diff --git a/higan/sfc/coprocessor/sharprtc/sharprtc.cpp b/higan/sfc/coprocessor/sharprtc/sharprtc.cpp index 46b7bd4d..efc28fef 100644 --- a/higan/sfc/coprocessor/sharprtc/sharprtc.cpp +++ b/higan/sfc/coprocessor/sharprtc/sharprtc.cpp @@ -22,8 +22,6 @@ auto SharpRTC::init() -> void { } auto SharpRTC::load() -> void { - return; - second = 0; minute = 0; hour = 0; diff --git a/higan/sfc/system/system.cpp b/higan/sfc/system/system.cpp index c965d882..007caa76 100644 --- a/higan/sfc/system/system.cpp +++ b/higan/sfc/system/system.cpp @@ -80,8 +80,6 @@ auto System::load(Emulator::Interface* interface) -> bool { if(cartridge.has.ARMDSP) armdsp.load(); if(cartridge.has.HitachiDSP) hitachidsp.load(); if(cartridge.has.NECDSP) necdsp.load(); - if(cartridge.has.EpsonRTC) epsonrtc.load(); - if(cartridge.has.SharpRTC) sharprtc.load(); if(cartridge.has.SPC7110) spc7110.load(); if(cartridge.has.SDD1) sdd1.load(); if(cartridge.has.OBC1) obc1.load(); @@ -118,8 +116,6 @@ auto System::unload() -> void { if(cartridge.has.ARMDSP) armdsp.unload(); if(cartridge.has.HitachiDSP) hitachidsp.unload(); if(cartridge.has.NECDSP) necdsp.unload(); - if(cartridge.has.EpsonRTC) epsonrtc.unload(); - if(cartridge.has.SharpRTC) sharprtc.unload(); if(cartridge.has.SPC7110) spc7110.unload(); if(cartridge.has.SDD1) sdd1.unload(); if(cartridge.has.OBC1) obc1.unload();