OXYGENHUB
◆ main openmsx / src / Autofire.hh
2.3 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef AUTOFIRE_HH
2
#define AUTOFIRE_HH
3
4
#include "DynamicClock.hh"
5
#include "EmuTime.hh"
6
#include "IntegerSetting.hh"
7
#include "Observer.hh"
8
#include "StateChange.hh"
9
#include "StateChangeListener.hh"
10
11
#include <cstdint>
12
13
namespace openmsx {
14
15
class MSXMotherBoard;
16
class Scheduler;
17
class StateChangeDistributor;
18
19
/**
20
 * Autofire is a device that is between two other devices and outside
21
 * the bus. For example, between the keyboard and the PPI
22
 * or between a joyPort connecter and the PSG.
23
 *
24
 * There can be multiple autofire circuits. For example, one used
25
 * by the Ren-Sha Turbo and another one built into a joystick.
26
 */
27
class Autofire final : private Observer<Setting>, private StateChangeListener
28
{
29
public:
30
	Autofire(MSXMotherBoard& motherBoard,
31
	         unsigned newMinInts, unsigned newMaxInts,
32
	         AutofireID id);
33
	~Autofire();
34
35
	/** Get the output signal in negative logic.
36
	  * @result When auto-fire is on, result will alternate between true
37
	  *         and false. When auto-fire if off result is false.
38
	  */
39
	[[nodiscard]] bool getSignal(EmuTime time) const;
40
41
	template<typename Archive>
42
	void serialize(Archive& ar, unsigned version);
43
44
private:
45
	void setSpeed(EmuTime time);
46
47
	/** Sets the clock frequency according to the current value of the speed
48
	  * settings.
49
	  */
50
	void setClock(int speed);
51
52
	// Observer<Setting>
53
	void update(const Setting& setting) noexcept override;
54
55
	// StateChangeListener
56
	void signalStateChange(const StateChange& event) override;
57
	void stopReplay(EmuTime time) noexcept override;
58
59
private:
60
	Scheduler& scheduler;
61
	StateChangeDistributor& stateChangeDistributor;
62
63
	// Following two values specify the range of the autofire
64
	// as measured by the test program:
65
	/** Number of interrupts at fastest setting (>=1).
66
	  * The number of interrupts for 50 periods, measured
67
	  * in ntsc mode (which gives 60 interrupts per second).
68
	  */
69
	const unsigned min_ints;
70
	/** Number of interrupts at slowest setting (>=min_ints+1).
71
	  * The number of interrupts for 50 periods, measured
72
	  * in ntsc mode (which gives 60 interrupts per second).
73
	  */
74
	const unsigned max_ints;
75
76
	/** The currently selected speed. */
77
	IntegerSetting speedSetting;
78
79
	/** Each tick of this clock, the signal changes.
80
	  * Frequency is derived from speed, min_ints and max_ints.
81
	  */
82
	DynamicClock clock;
83
84
	const AutofireID id;
85
};
86
87
} // namespace openmsx
88
89
#endif