2016-05-31 21:23:44 -04:00
|
|
|
//
|
|
|
|
// CRTMachine.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 31/05/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef CRTMachine_hpp
|
|
|
|
#define CRTMachine_hpp
|
|
|
|
|
|
|
|
#include "../Outputs/CRT/CRT.hpp"
|
2017-12-17 21:26:06 -05:00
|
|
|
#include "../Outputs/Speaker/Speaker.hpp"
|
2017-07-25 20:20:55 -04:00
|
|
|
#include "../ClockReceiver/ClockReceiver.hpp"
|
2018-03-21 22:18:13 -04:00
|
|
|
#include "../ClockReceiver/TimeTypes.hpp"
|
2017-11-07 21:19:51 -05:00
|
|
|
#include "ROMMachine.hpp"
|
2016-05-31 21:23:44 -04:00
|
|
|
|
2018-03-31 22:14:34 -04:00
|
|
|
#include "../Configurable/StandardOptions.hpp"
|
|
|
|
|
2018-03-21 22:18:13 -04:00
|
|
|
#include <cmath>
|
|
|
|
|
2016-05-31 21:23:44 -04:00
|
|
|
namespace CRTMachine {
|
|
|
|
|
2016-06-30 08:46:29 -04:00
|
|
|
/*!
|
|
|
|
A CRTMachine::Machine is a mostly-abstract base class for machines that connect to a CRT,
|
|
|
|
that optionally provide a speaker, and that nominate a clock rate and can announce to a delegate
|
|
|
|
should that clock rate change.
|
|
|
|
*/
|
2017-11-07 21:19:51 -05:00
|
|
|
class Machine: public ROMMachine::Machine {
|
2016-05-31 21:23:44 -04:00
|
|
|
public:
|
2017-07-22 17:31:12 -04:00
|
|
|
/*!
|
|
|
|
Causes the machine to set up its CRT and, if it has one, speaker. The caller guarantees
|
|
|
|
that an OpenGL context is bound.
|
|
|
|
*/
|
2016-05-31 21:23:44 -04:00
|
|
|
virtual void setup_output(float aspect_ratio) = 0;
|
2017-07-22 17:31:12 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Gives the machine a chance to release all owned resources. The caller guarantees that the
|
|
|
|
OpenGL context is bound.
|
|
|
|
*/
|
2016-05-31 21:23:44 -04:00
|
|
|
virtual void close_output() = 0;
|
2017-11-07 22:51:06 -05:00
|
|
|
|
2017-07-22 17:31:12 -04:00
|
|
|
/// @returns The CRT this machine is drawing to. Should not be @c nullptr.
|
2017-12-17 21:26:06 -05:00
|
|
|
virtual Outputs::CRT::CRT *get_crt() = 0;
|
2017-07-22 17:31:12 -04:00
|
|
|
|
|
|
|
/// @returns The speaker that receives this machine's output, or @c nullptr if this machine is mute.
|
2017-12-17 21:26:06 -05:00
|
|
|
virtual Outputs::Speaker::Speaker *get_speaker() = 0;
|
2016-05-31 21:23:44 -04:00
|
|
|
|
2018-02-01 07:53:52 -05:00
|
|
|
/// @returns The confidence that this machine is running content it understands.
|
|
|
|
virtual float get_confidence() { return 0.5f; }
|
|
|
|
virtual void print_type() {}
|
|
|
|
|
2018-03-21 22:18:13 -04:00
|
|
|
/// Runs the machine for @c duration seconds.
|
|
|
|
virtual void run_for(Time::Seconds duration) {
|
|
|
|
const double cycles = (duration * clock_rate_) + clock_conversion_error_;
|
|
|
|
clock_conversion_error_ = std::fmod(cycles, 1.0);
|
|
|
|
run_for(Cycles(static_cast<int>(cycles)));
|
2016-08-14 13:33:20 -04:00
|
|
|
}
|
2018-03-21 22:18:13 -04:00
|
|
|
|
2016-06-16 20:39:46 -04:00
|
|
|
protected:
|
2018-03-21 22:18:13 -04:00
|
|
|
/// Runs the machine for @c cycles.
|
|
|
|
virtual void run_for(const Cycles cycles) = 0;
|
2016-08-14 13:33:20 -04:00
|
|
|
void set_clock_rate(double clock_rate) {
|
2018-03-21 22:18:13 -04:00
|
|
|
clock_rate_ = clock_rate;
|
2016-09-12 22:06:03 -04:00
|
|
|
}
|
2018-03-22 10:01:18 -04:00
|
|
|
double get_clock_rate() {
|
|
|
|
return clock_rate_;
|
|
|
|
}
|
2016-08-14 13:33:20 -04:00
|
|
|
|
2018-03-31 22:14:34 -04:00
|
|
|
void set_video_signal_configurable(Configurable::Display type) {
|
|
|
|
Outputs::CRT::VideoSignal signal;
|
|
|
|
switch(type) {
|
|
|
|
default:
|
|
|
|
case Configurable::Display::RGB:
|
|
|
|
signal = Outputs::CRT::VideoSignal::RGB;
|
|
|
|
break;
|
|
|
|
case Configurable::Display::SVideo:
|
|
|
|
signal = Outputs::CRT::VideoSignal::SVideo;
|
|
|
|
break;
|
|
|
|
case Configurable::Display::Composite:
|
|
|
|
signal = Outputs::CRT::VideoSignal::Composite;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
get_crt()->set_video_signal(signal);
|
|
|
|
}
|
|
|
|
|
2016-08-14 13:33:20 -04:00
|
|
|
private:
|
2017-11-10 22:08:40 -05:00
|
|
|
double clock_rate_ = 1.0;
|
2018-03-21 22:18:13 -04:00
|
|
|
double clock_conversion_error_ = 0.0;
|
2016-05-31 21:23:44 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CRTMachine_hpp */
|