Skip to content

Commit

Permalink
SNES: restore mapping and poll interval
Browse files Browse the repository at this point in the history
when stopping and restarting snes auto-tracking
  • Loading branch information
black-sliver committed Feb 28, 2024
1 parent 79fd59d commit 6af9c95
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/autotracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class AutoTracker final : public LuaInterface<AutoTracker>{
_snes->setMapping(USB2SNES::Mapping::EXHIROM);
else if (flags.find("sa-1") != flags.end())
_snes->setMapping(USB2SNES::Mapping::SA1);
_snesMapping = _snes->getMapping();
}
if (strcasecmp(platform.c_str(), "n64") == 0) {
_provider = new LuaConnector::LuaConnector(_name);
Expand Down Expand Up @@ -321,7 +322,9 @@ class AutoTracker final : public LuaInterface<AutoTracker>{
return false;
}

void setInterval(unsigned ms) {
void setInterval(unsigned ms)
{
_interval = ms;
if (_snes)
_snes->setUpdateInterval(ms);
if (_provider)
Expand Down Expand Up @@ -516,9 +519,12 @@ class AutoTracker final : public LuaInterface<AutoTracker>{
} else {
delete _snes;
}
_snes = new USB2SNES(_name);
_backendIndex.erase(_snes);
_snes = new USB2SNES(_name);
_backendIndex[_snes] = index;
_snes->setMapping(_snesMapping);
if (_interval != INTERVAL_UNSET)
_snes->setUpdateInterval(_interval);
}
if (_uat && _backendIndex[_uat] == index
&& _uat->getState() != UATClient::State::DISCONNECTED
Expand Down Expand Up @@ -589,6 +595,10 @@ class AutoTracker final : public LuaInterface<AutoTracker>{
std::string _name;
bool _sentState = false;
std::vector<std::string> _snesAddresses;
unsigned _interval = INTERVAL_UNSET;
USB2SNES::Mapping _snesMapping;

static constexpr unsigned INTERVAL_UNSET = std::numeric_limits<unsigned>::max();

static const std::string BACKEND_AP_NAME;
static const std::string BACKEND_UAT_NAME;
Expand Down
5 changes: 5 additions & 0 deletions src/usb2snes/usb2snes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,11 @@ void USB2SNES::setMapping(USB2SNES::Mapping value)
mapping = value;
}

USB2SNES::Mapping USB2SNES::getMapping() const
{
return mapping;
}

void USB2SNES::addWatch(uint32_t addr, unsigned len)
{
uint32_t usb2snes_addr = mapaddr(addr);
Expand Down
1 change: 1 addition & 0 deletions src/usb2snes/usb2snes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class USB2SNES {
bool wsConnected();
bool snesConnected();
void setMapping(Mapping mapping);
Mapping getMapping() const;
void addWatch(uint32_t addr, unsigned len=1);
void removeWatch(uint32_t addr, unsigned len=1);
uint8_t read(uint32_t addr);
Expand Down

0 comments on commit 6af9c95

Please sign in to comment.