2016-06-01 01:23:44 +00:00
|
|
|
//
|
|
|
|
// CRTMachine.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 31/05/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-06-01 01:23:44 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef CRTMachine_hpp
|
|
|
|
#define CRTMachine_hpp
|
|
|
|
|
2018-11-04 01:54:25 +00:00
|
|
|
#include "../Outputs/ScanTarget.hpp"
|
2017-12-18 02:26:06 +00:00
|
|
|
#include "../Outputs/Speaker/Speaker.hpp"
|
2017-07-26 00:20:55 +00:00
|
|
|
#include "../ClockReceiver/ClockReceiver.hpp"
|
2018-03-22 02:18:13 +00:00
|
|
|
#include "../ClockReceiver/TimeTypes.hpp"
|
2017-11-08 02:19:51 +00:00
|
|
|
#include "ROMMachine.hpp"
|
2016-06-01 01:23:44 +00:00
|
|
|
|
2018-04-01 02:14:34 +00:00
|
|
|
#include "../Configurable/StandardOptions.hpp"
|
|
|
|
|
2018-03-22 02:18:13 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2018-11-04 01:54:25 +00:00
|
|
|
// TODO: rename.
|
2016-06-01 01:23:44 +00:00
|
|
|
namespace CRTMachine {
|
|
|
|
|
2016-06-30 12:46:29 +00: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.
|
|
|
|
*/
|
2018-07-11 00:00:46 +00:00
|
|
|
class Machine {
|
2016-06-01 01:23:44 +00:00
|
|
|
public:
|
2017-07-22 21:31:12 +00:00
|
|
|
/*!
|
2018-11-04 01:54:25 +00:00
|
|
|
Causes the machine to set up its display and, if it has one, speaker.
|
2017-07-22 21:31:12 +00:00
|
|
|
|
2018-11-04 01:54:25 +00:00
|
|
|
The @c scan_target will receive all video output; the caller guarantees
|
|
|
|
that it is non-null.
|
2017-07-22 21:31:12 +00:00
|
|
|
*/
|
2018-11-15 02:52:57 +00:00
|
|
|
virtual void set_scan_target(Outputs::Display::ScanTarget *scan_target) = 0;
|
2017-07-22 21:31:12 +00:00
|
|
|
|
|
|
|
/// @returns The speaker that receives this machine's output, or @c nullptr if this machine is mute.
|
2017-12-18 02:26:06 +00:00
|
|
|
virtual Outputs::Speaker::Speaker *get_speaker() = 0;
|
2016-06-01 01:23:44 +00:00
|
|
|
|
2018-02-01 12:53:52 +00: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-22 02:18:13 +00: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 17:33:20 +00:00
|
|
|
}
|
2018-03-22 02:18:13 +00:00
|
|
|
|
2016-06-17 00:39:46 +00:00
|
|
|
protected:
|
2018-03-22 02:18:13 +00:00
|
|
|
/// Runs the machine for @c cycles.
|
|
|
|
virtual void run_for(const Cycles cycles) = 0;
|
2016-08-14 17:33:20 +00:00
|
|
|
void set_clock_rate(double clock_rate) {
|
2018-03-22 02:18:13 +00:00
|
|
|
clock_rate_ = clock_rate;
|
2016-09-13 02:06:03 +00:00
|
|
|
}
|
2018-03-22 14:01:18 +00:00
|
|
|
double get_clock_rate() {
|
|
|
|
return clock_rate_;
|
|
|
|
}
|
2016-08-14 17:33:20 +00:00
|
|
|
|
2018-04-04 23:14:42 +00:00
|
|
|
/*!
|
2018-11-04 01:54:25 +00:00
|
|
|
Maps from Configurable::Display to Outputs::Display::VideoSignal and calls
|
2018-04-04 23:14:42 +00:00
|
|
|
@c set_video_signal with the result.
|
|
|
|
*/
|
2018-04-01 02:14:34 +00:00
|
|
|
void set_video_signal_configurable(Configurable::Display type) {
|
2018-11-04 01:54:25 +00:00
|
|
|
Outputs::Display::VideoSignal signal;
|
2018-04-01 02:14:34 +00:00
|
|
|
switch(type) {
|
|
|
|
default:
|
|
|
|
case Configurable::Display::RGB:
|
2018-11-04 01:54:25 +00:00
|
|
|
signal = Outputs::Display::VideoSignal::RGB;
|
2018-04-01 02:14:34 +00:00
|
|
|
break;
|
|
|
|
case Configurable::Display::SVideo:
|
2018-11-04 01:54:25 +00:00
|
|
|
signal = Outputs::Display::VideoSignal::SVideo;
|
2018-04-01 02:14:34 +00:00
|
|
|
break;
|
|
|
|
case Configurable::Display::Composite:
|
2018-11-04 01:54:25 +00:00
|
|
|
signal = Outputs::Display::VideoSignal::Composite;
|
2018-04-01 02:14:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-04-04 23:14:42 +00:00
|
|
|
set_video_signal(signal);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Forwards the video signal to the CRT returned by get_crt().
|
|
|
|
*/
|
2018-11-04 01:54:25 +00:00
|
|
|
virtual void set_video_signal(Outputs::Display::VideoSignal video_signal) {
|
2018-11-03 23:58:44 +00:00
|
|
|
// get_crt()->set_video_signal(video_signal);
|
2018-04-01 02:14:34 +00:00
|
|
|
}
|
|
|
|
|
2016-08-14 17:33:20 +00:00
|
|
|
private:
|
2017-11-11 03:08:40 +00:00
|
|
|
double clock_rate_ = 1.0;
|
2018-03-22 02:18:13 +00:00
|
|
|
double clock_conversion_error_ = 0.0;
|
2016-06-01 01:23:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CRTMachine_hpp */
|