15 default:
return "unknown-autofire";
25 ,
id(id_), value(value_) {}
26 [[nodiscard]]
auto getId()
const {
return id; }
27 [[nodiscard]]
int getValue()
const {
return value; }
28 template<
typename Archive>
void serialize(Archive& ar,
unsigned )
30 ar.template serializeBase<StateChange>(*
this);
32 std::string name = Archive::IS_LOADER ?
"" : std::string(nameForId(
id));
33 ar.serialize(
"name", name,
35 if constexpr (Archive::IS_LOADER) {
50 unsigned newMinInts,
unsigned newMaxInts,
ID id_)
51 : scheduler(motherBoard.getScheduler())
52 , stateChangeDistributor(motherBoard.getStateChangeDistributor())
53 , min_ints(
std::
max(newMinInts, 1u))
54 , max_ints(
std::
max(newMaxInts, min_ints + 1))
55 , speedSetting(motherBoard.getCommandController(), nameForId(id_),
56 "controls autofire speed (0 = disabled)", 0, 0, 100)
57 , clock(scheduler.getCurrentTime())
60 setClock(speedSetting.
getInt());
63 speedSetting.
attach(*
this);
68 speedSetting.
detach(*
this);
72void Autofire::setSpeed(EmuTime::param time)
78void Autofire::setClock(
int speed)
82 (2 * 50 * 60) / (max_ints - (speed * (max_ints - min_ints)) / 100));
88void Autofire::update(
const Setting&
setting)
noexcept
91 assert(&
setting == &speedSetting);
92 setSpeed(scheduler.getCurrentTime());
95void Autofire::signalStateChange(
const StateChange& event)
97 const auto* as =
dynamic_cast<const AutofireStateChange*
>(&event);
99 if (as->getId() !=
id)
return;
101 setClock(as->getValue());
104void Autofire::stopReplay(EmuTime::param time)
noexcept
116template<
typename Archive>
119 ar.serialize(
"clock", clock);
AutofireStateChange(EmuTime::param time_, Autofire::ID id_, int value_)
void serialize(Archive &ar, unsigned)
AutofireStateChange()=default
Autofire is a device that is between two other devices and outside the bus.
bool getSignal(EmuTime::param time)
Get the output signal in negative logic.
Autofire(MSXMotherBoard &motherBoard, unsigned newMinInts, unsigned newMaxInts, ID id)
void serialize(Archive &ar, unsigned version)
unsigned getTicksTill(EmuTime::param e) const
Calculate the number of ticks for this clock until the given time.
EmuDuration getPeriod() const
Returns the length of one clock-cycle.
void setPeriod(EmuDuration period)
Set the duration of a clock tick.
void setFreq(unsigned freq)
Change the frequency at which this clock ticks.
static constexpr EmuDuration zero()
int getInt() const noexcept
void registerListener(StateChangeListener &listener)
(Un)registers the given object to receive state change events.
void distributeNew(EmuTime::param time, Args &&...args)
Deliver the event to all registered listeners MSX input devices should call the distributeNew() versi...
void unregisterListener(StateChangeListener &listener)
Base class for all external MSX state changing events.
void detach(Observer< T > &observer)
void attach(Observer< T > &observer)
constexpr vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
This file implemented 3 utility functions:
REGISTER_POLYMORPHIC_CLASS(StateChange, AutofireStateChange, "AutofireStateChange")
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)