17 default:
return "unknown-autofire";
27 ,
id(id_), value(value_) {}
28 [[nodiscard]]
auto getId()
const {
return id; }
29 [[nodiscard]]
int getValue()
const {
return value; }
30 template<
typename Archive>
void serialize(Archive& ar,
unsigned )
32 ar.template serializeBase<StateChange>(*
this);
34 std::string name = Archive::IS_LOADER ?
"" : std::string(nameForId(
id));
35 ar.serialize(
"name", name,
37 if constexpr (Archive::IS_LOADER) {
52 unsigned newMinInts,
unsigned newMaxInts,
ID id_)
53 : scheduler(motherBoard.getScheduler())
54 , stateChangeDistributor(motherBoard.getStateChangeDistributor())
55 , min_ints(
std::max(newMinInts, 1u))
56 , max_ints(
std::max(newMaxInts, min_ints + 1))
57 , speedSetting(motherBoard.getCommandController(), nameForId(id_),
58 "controls autofire speed (0 = disabled)", 0, 0, 100)
59 , clock(scheduler.getCurrentTime())
62 setClock(speedSetting.
getInt());
65 speedSetting.
attach(*
this);
70 speedSetting.
detach(*
this);
74void Autofire::setSpeed(EmuTime::param time)
80void Autofire::setClock(
int speed)
84 (2 * 50 * 60) / (max_ints - (speed * (max_ints - min_ints)) / 100));
90void Autofire::update(
const Setting&
setting)
noexcept
93 assert(&
setting == &speedSetting);
94 setSpeed(scheduler.getCurrentTime());
97void Autofire::signalStateChange(
const StateChange& event)
99 const auto* as =
dynamic_cast<const AutofireStateChange*
>(&event);
101 if (as->getId() !=
id)
return;
103 setClock(as->getValue());
106void Autofire::stopReplay(EmuTime::param time)
noexcept
118template<
typename Archive>
121 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.
Autofire(MSXMotherBoard &motherBoard, unsigned newMinInts, unsigned newMaxInts, ID id)
void serialize(Archive &ar, unsigned version)
bool getSignal(EmuTime::param time) const
Get the output signal in negative logic.
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)
This file implemented 3 utility functions:
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)