openMSX
ThrottleManager.cc
Go to the documentation of this file.
1 #include "ThrottleManager.hh"
2 
3 namespace openmsx {
4 
5 // class ThrottleManager:
6 
8  : throttleSetting(
9  commandController, "throttle",
10  "controls speed throttling", true, Setting::DONT_SAVE)
11  , fullSpeedLoadingSetting(
12  commandController, "fullspeedwhenloading",
13  "sets openMSX to full speed when the MSX is loading", false)
14  , loading(0), throttle(true)
15 {
16  throttleSetting .attach(*this);
17  fullSpeedLoadingSetting.attach(*this);
18 }
19 
21 {
22  throttleSetting .detach(*this);
23  fullSpeedLoadingSetting.detach(*this);
24 }
25 
26 void ThrottleManager::updateStatus()
27 {
28  bool newThrottle = throttleSetting.getBoolean() &&
29  (!loading || !fullSpeedLoadingSetting.getBoolean());
30  if (throttle != newThrottle) {
31  throttle = newThrottle;
32  notify();
33  }
34 }
35 
36 void ThrottleManager::indicateLoadingState(bool state)
37 {
38  if (state) {
39  ++loading;
40  } else {
41  --loading;
42  }
43  assert(loading >= 0);
44  updateStatus();
45 }
46 
47 void ThrottleManager::update(const Setting& /*setting*/)
48 {
49  updateStatus();
50 }
51 
52 
53 // class LoadingIndicator:
54 
56  : throttleManager(throttleManager_)
57  , isLoading(false)
58 {
59 }
60 
62 {
63  update(false);
64 }
65 
66 void LoadingIndicator::update(bool newState)
67 {
68  if (isLoading != newState) {
69  isLoading = newState;
70  throttleManager.indicateLoadingState(isLoading);
71  }
72 }
73 
74 } // namespace openmsx
void attach(Observer< T > &observer)
Definition: Subject.hh:50
bool getBoolean() const noexcept
void update(bool newState)
Called by the device to indicate its loading state may have changed.
ThrottleManager(CommandController &commandController)
LoadingIndicator(ThrottleManager &throttleManager)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
Manages the throttle state of openMSX.
void detach(Observer< T > &observer)
Definition: Subject.hh:56