openMSX
Autofire.cc
Go to the documentation of this file.
1 #include "Autofire.hh"
2 #include <algorithm>
3 #include <cassert>
4 
5 namespace openmsx {
6 
8  unsigned newMinInts, unsigned newMaxInts, string_ref name)
9  : min_ints(std::max(newMinInts, 1u))
10  , max_ints(std::max(newMaxInts, min_ints + 1))
11  , speedSetting(commandController, name,
12  "controls the speed of this autofire circuit", 0, 0, 100)
13  , clock(EmuTime::zero)
14 {
15  setClock();
16  speedSetting.attach(*this);
17 }
18 
20 {
21  speedSetting.detach(*this);
22 }
23 
24 void Autofire::setClock()
25 {
26  int speed = speedSetting.getInt();
27  clock.setFreq(
28  (2 * 50 * 60) / (max_ints - (speed * (max_ints - min_ints)) / 100));
29 }
30 
31 void Autofire::update(const Setting& setting)
32 {
33  (void)setting;
34  assert(&setting == &speedSetting);
35  setClock();
36 }
37 
39 {
40  return speedSetting.getInt() == 0 ?
41  false : clock.getTicksTill(time) & 1;
42 }
43 
44 } // namespace openmsx
STL namespace.
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:277
Autofire(CommandController &commandController, unsigned newMinInts, unsigned newMaxInts, string_ref name)
Definition: Autofire.cc:7
void attach(Observer< T > &observer)
Definition: Subject.hh:52
void setFreq(unsigned freq)
Change the frequency at which this clock ticks.
Definition: DynamicClock.hh:86
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
bool getSignal(EmuTime::param time)
Get the output signal in negative logic.
Definition: Autofire.cc:38
void detach(Observer< T > &observer)
Definition: Subject.hh:58
unsigned getTicksTill(EmuTime::param e) const
Calculate the number of ticks for this clock until the given time.
Definition: DynamicClock.hh:51