2019-10-05 01:34:15 +00:00
|
|
|
//
|
|
|
|
// Video.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 04/10/2019.
|
|
|
|
// Copyright © 2019 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2019-10-09 01:18:08 +00:00
|
|
|
#ifndef Atari_ST_Video_hpp
|
|
|
|
#define Atari_ST_Video_hpp
|
2019-10-05 01:34:15 +00:00
|
|
|
|
2019-11-09 20:31:41 +00:00
|
|
|
#include "../../../Outputs/CRT/CRT.hpp"
|
|
|
|
#include "../../../ClockReceiver/ClockReceiver.hpp"
|
2019-12-14 00:57:54 +00:00
|
|
|
#include "../../../ClockReceiver/DeferredQueue.hpp"
|
2019-10-05 01:34:15 +00:00
|
|
|
|
2019-11-18 04:28:00 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2019-12-30 01:55:34 +00:00
|
|
|
// Testing hook; not for any other user.
|
|
|
|
class VideoTester;
|
|
|
|
|
2019-10-05 01:34:15 +00:00
|
|
|
namespace Atari {
|
|
|
|
namespace ST {
|
|
|
|
|
2020-01-28 04:40:01 +00:00
|
|
|
struct LineLength {
|
|
|
|
int length = 1024;
|
2020-01-29 01:38:20 +00:00
|
|
|
int hsync_start = 1024;
|
|
|
|
int hsync_end = 1024;
|
2020-01-28 04:40:01 +00:00
|
|
|
};
|
|
|
|
|
2019-11-18 02:28:51 +00:00
|
|
|
/*!
|
|
|
|
Models a combination of the parts of the GLUE, MMU and Shifter that in net
|
|
|
|
form the video subsystem of the Atari ST. So not accurate to a real chip, but
|
|
|
|
(hopefully) to a subsystem.
|
|
|
|
*/
|
2019-10-05 01:34:15 +00:00
|
|
|
class Video {
|
|
|
|
public:
|
|
|
|
Video();
|
|
|
|
|
2019-11-18 02:28:51 +00:00
|
|
|
/*!
|
|
|
|
Sets the memory pool that provides video, and its size.
|
|
|
|
*/
|
|
|
|
void set_ram(uint16_t *, size_t size);
|
|
|
|
|
2019-10-05 01:34:15 +00:00
|
|
|
/*!
|
|
|
|
Sets the target device for video data.
|
|
|
|
*/
|
|
|
|
void set_scan_target(Outputs::Display::ScanTarget *scan_target);
|
|
|
|
|
2020-01-21 02:45:10 +00:00
|
|
|
/// Gets the current scan status.
|
2020-01-22 03:28:25 +00:00
|
|
|
Outputs::Display::ScanStatus get_scaled_scan_status() const;
|
2020-01-21 02:45:10 +00:00
|
|
|
|
2019-12-21 01:49:14 +00:00
|
|
|
/*!
|
|
|
|
Sets the type of output.
|
|
|
|
*/
|
|
|
|
void set_display_type(Outputs::Display::DisplayType);
|
|
|
|
|
2020-03-18 03:52:55 +00:00
|
|
|
/*!
|
|
|
|
Gets the type of output.
|
|
|
|
*/
|
|
|
|
Outputs::Display::DisplayType get_display_type();
|
|
|
|
|
2019-10-05 01:34:15 +00:00
|
|
|
/*!
|
|
|
|
Produces the next @c duration period of pixels.
|
|
|
|
*/
|
|
|
|
void run_for(HalfCycles duration);
|
|
|
|
|
2019-11-18 02:28:51 +00:00
|
|
|
|
2019-10-09 01:18:08 +00:00
|
|
|
/*!
|
|
|
|
@returns the number of cycles until there is next a change in the hsync,
|
|
|
|
vsync or display_enable outputs.
|
|
|
|
*/
|
|
|
|
HalfCycles get_next_sequence_point();
|
|
|
|
|
2019-11-18 02:28:51 +00:00
|
|
|
/*!
|
|
|
|
@returns @c true if the horizontal sync output is currently active; @c false otherwise.
|
|
|
|
|
|
|
|
@discussion On an Atari ST, this generates a VPA-style interrupt, which is often erroneously
|
|
|
|
documented as being triggered by horizontal blank.
|
|
|
|
*/
|
2019-11-09 02:25:28 +00:00
|
|
|
bool hsync();
|
2019-11-18 02:28:51 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns @c true if the vertical sync output is currently active; @c false otherwise.
|
|
|
|
|
|
|
|
@discussion On an Atari ST, this generates a VPA-style interrupt, which is often erroneously
|
|
|
|
documented as being triggered by vertical blank.
|
|
|
|
*/
|
2019-10-09 01:18:08 +00:00
|
|
|
bool vsync();
|
|
|
|
|
2019-11-18 02:28:51 +00:00
|
|
|
/*!
|
|
|
|
@returns @c true if the display enabled output is currently active; @c false otherwise.
|
2019-10-11 02:46:58 +00:00
|
|
|
|
2019-11-18 02:28:51 +00:00
|
|
|
@discussion On an Atari ST this is fed to the MFP. The documentation that I've been able to
|
|
|
|
find implies a total 28-cycle delay between the real delay enabled signal changing and its effect
|
|
|
|
on the 68000 interrupt input via the MFP. As I have yet to determine how much delay is caused
|
|
|
|
by the MFP a full 28-cycle delay is applied by this class. This should be dialled down when the
|
|
|
|
MFP's responsibility is clarified.
|
|
|
|
*/
|
|
|
|
bool display_enabled();
|
|
|
|
|
|
|
|
/// @returns the effect of reading from @c address; only the low 6 bits are decoded.
|
2019-11-02 03:01:06 +00:00
|
|
|
uint16_t read(int address);
|
2019-11-18 02:28:51 +00:00
|
|
|
|
|
|
|
/// Writes @c value to @c address, of which only the low 6 bits are decoded.
|
2019-10-11 03:29:46 +00:00
|
|
|
void write(int address, uint16_t value);
|
2019-10-10 03:01:11 +00:00
|
|
|
|
2019-11-18 02:28:51 +00:00
|
|
|
/// Used internally to track state.
|
|
|
|
enum class FieldFrequency {
|
|
|
|
Fifty = 0, Sixty = 1, SeventyTwo = 2
|
|
|
|
};
|
|
|
|
|
2019-12-09 01:20:13 +00:00
|
|
|
struct RangeObserver {
|
|
|
|
/// Indicates to the observer that the memory access range has changed.
|
|
|
|
virtual void video_did_change_access_range(Video *) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Sets a range observer, which is an actor that will be notified if the memory access range changes.
|
|
|
|
void set_range_observer(RangeObserver *);
|
|
|
|
|
|
|
|
struct Range {
|
|
|
|
uint32_t low_address, high_address;
|
|
|
|
};
|
|
|
|
/*!
|
|
|
|
@returns the range of addresses that the video might read from.
|
|
|
|
*/
|
|
|
|
Range get_memory_access_range();
|
|
|
|
|
2019-10-05 01:34:15 +00:00
|
|
|
private:
|
2020-01-30 03:46:08 +00:00
|
|
|
DeferredQueue<HalfCycles> deferrer_;
|
2019-12-14 00:57:54 +00:00
|
|
|
|
2019-10-05 01:34:15 +00:00
|
|
|
Outputs::CRT::CRT crt_;
|
2019-12-09 01:20:13 +00:00
|
|
|
RangeObserver *range_observer_ = nullptr;
|
2019-10-09 01:18:08 +00:00
|
|
|
|
2019-11-08 04:11:06 +00:00
|
|
|
uint16_t raw_palette_[16];
|
2019-10-10 03:01:11 +00:00
|
|
|
uint16_t palette_[16];
|
2019-10-11 02:46:58 +00:00
|
|
|
int base_address_ = 0;
|
2019-12-09 01:20:13 +00:00
|
|
|
int previous_base_address_ = 0;
|
2019-10-11 02:46:58 +00:00
|
|
|
int current_address_ = 0;
|
|
|
|
|
2019-11-18 02:28:51 +00:00
|
|
|
uint16_t *ram_ = nullptr;
|
2019-10-10 03:01:11 +00:00
|
|
|
|
2019-11-09 03:18:47 +00:00
|
|
|
int x_ = 0, y_ = 0, next_y_ = 0;
|
2019-12-11 02:24:15 +00:00
|
|
|
bool load_ = false;
|
|
|
|
int load_base_ = 0;
|
2019-10-28 02:39:00 +00:00
|
|
|
|
2019-11-02 03:01:06 +00:00
|
|
|
uint16_t video_mode_ = 0;
|
2019-11-06 04:02:25 +00:00
|
|
|
uint16_t sync_mode_ = 0;
|
|
|
|
|
|
|
|
FieldFrequency field_frequency_ = FieldFrequency::Fifty;
|
|
|
|
enum class OutputBpp {
|
|
|
|
One, Two, Four
|
2019-11-18 02:28:51 +00:00
|
|
|
} output_bpp_ = OutputBpp::Four;
|
2019-11-06 04:02:25 +00:00
|
|
|
void update_output_mode();
|
|
|
|
|
2019-11-09 03:18:47 +00:00
|
|
|
struct HorizontalState {
|
2019-11-06 04:02:25 +00:00
|
|
|
bool enable = false;
|
|
|
|
bool blank = false;
|
|
|
|
bool sync = false;
|
2019-11-09 03:18:47 +00:00
|
|
|
} horizontal_;
|
|
|
|
struct VerticalState {
|
|
|
|
bool enable = false;
|
|
|
|
bool blank = false;
|
|
|
|
|
|
|
|
enum class SyncSchedule {
|
|
|
|
/// No sync events this line.
|
|
|
|
None,
|
|
|
|
/// Sync should begin during this horizontal line.
|
|
|
|
Begin,
|
|
|
|
/// Sync should end during this horizontal line.
|
|
|
|
End,
|
|
|
|
} sync_schedule = SyncSchedule::None;
|
|
|
|
bool sync = false;
|
|
|
|
} vertical_, next_vertical_;
|
2020-01-28 04:40:01 +00:00
|
|
|
LineLength line_length_;
|
2019-11-06 04:02:25 +00:00
|
|
|
|
|
|
|
int data_latch_position_ = 0;
|
2019-12-13 04:20:28 +00:00
|
|
|
int data_latch_read_position_ = 0;
|
|
|
|
uint16_t data_latch_[128];
|
|
|
|
void push_latched_data();
|
|
|
|
|
2019-12-12 04:22:20 +00:00
|
|
|
void reset_fifo();
|
2019-11-06 04:02:25 +00:00
|
|
|
|
2019-12-28 03:47:34 +00:00
|
|
|
/*!
|
|
|
|
Provides a target for control over the output video stream, which is considered to be
|
|
|
|
a permanently shifting shifter, that you need to reload when appropriate, which can be
|
|
|
|
overridden by the blank and sync levels.
|
|
|
|
|
|
|
|
This stream will automatically insert a colour burst.
|
|
|
|
*/
|
2019-12-28 00:03:10 +00:00
|
|
|
class VideoStream {
|
2019-11-11 02:39:40 +00:00
|
|
|
public:
|
2019-12-28 00:03:10 +00:00
|
|
|
VideoStream(Outputs::CRT::CRT &crt, uint16_t *palette) : crt_(crt), palette_(palette) {}
|
2019-11-11 02:39:40 +00:00
|
|
|
|
2019-12-28 03:47:34 +00:00
|
|
|
enum class OutputMode {
|
|
|
|
Sync, Blank, ColourBurst, Pixels,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Sets the current data format for the shifter. Changes in output BPP flush the shifter.
|
|
|
|
void set_bpp(OutputBpp bpp);
|
|
|
|
|
2019-12-28 15:45:10 +00:00
|
|
|
/// Outputs signal of type @c mode for @c duration.
|
2019-12-28 03:47:34 +00:00
|
|
|
void output(int duration, OutputMode mode);
|
|
|
|
|
2019-12-28 15:45:10 +00:00
|
|
|
/// Warns the video stream that the border colour, included in the palette that it holds a pointer to,
|
|
|
|
/// will change momentarily. This should be called after the relevant @c output() updates, and
|
|
|
|
/// is used to help elide border-regio output.
|
|
|
|
void will_change_border_colour();
|
|
|
|
|
2019-12-28 03:47:34 +00:00
|
|
|
/// Loads 64 bits into the Shifter. The shifter shifts continuously. If you also declare
|
|
|
|
/// a pixels region then whatever is being shifted will reach the display, in a form that
|
|
|
|
/// depends on the current output BPP.
|
2019-11-11 02:39:40 +00:00
|
|
|
void load(uint64_t value);
|
|
|
|
|
|
|
|
private:
|
2019-12-28 03:47:34 +00:00
|
|
|
// The target CRT and the palette to use.
|
|
|
|
Outputs::CRT::CRT &crt_;
|
|
|
|
uint16_t *palette_ = nullptr;
|
|
|
|
|
|
|
|
// Internal stateful processes.
|
|
|
|
void generate(int duration, OutputMode mode, bool is_terminal);
|
|
|
|
|
|
|
|
void flush_border();
|
|
|
|
void flush_pixels();
|
|
|
|
void shift(int duration);
|
|
|
|
void output_pixels(int duration);
|
|
|
|
|
|
|
|
// Internal state that is a function of output intent.
|
2019-11-11 02:39:40 +00:00
|
|
|
int duration_ = 0;
|
2019-12-28 03:47:34 +00:00
|
|
|
OutputMode output_mode_ = OutputMode::Sync;
|
2019-11-18 02:28:51 +00:00
|
|
|
OutputBpp bpp_ = OutputBpp::Four;
|
2019-11-11 02:39:40 +00:00
|
|
|
union {
|
|
|
|
uint64_t output_shifter_;
|
|
|
|
uint32_t shifter_halves_[2];
|
|
|
|
};
|
|
|
|
|
2019-12-28 03:47:34 +00:00
|
|
|
// Internal state for handling output serialisation.
|
2019-11-18 02:28:51 +00:00
|
|
|
uint16_t *pixel_buffer_ = nullptr;
|
2019-12-28 03:47:34 +00:00
|
|
|
int pixel_pointer_ = 0;
|
2019-12-28 00:03:10 +00:00
|
|
|
} video_stream_;
|
2019-11-18 04:28:00 +00:00
|
|
|
|
|
|
|
/// Contains copies of the various observeable fields, after the relevant propagation delay.
|
|
|
|
struct PublicState {
|
|
|
|
bool display_enable = false;
|
2019-12-29 22:37:09 +00:00
|
|
|
bool hsync = false;
|
2019-12-30 00:03:08 +00:00
|
|
|
bool vsync = false;
|
2019-11-18 04:28:00 +00:00
|
|
|
} public_state_;
|
|
|
|
|
2019-12-30 01:55:34 +00:00
|
|
|
friend class ::VideoTester;
|
2019-10-05 01:34:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 01:18:08 +00:00
|
|
|
#endif /* Atari_ST_Video_hpp */
|