2015-07-19 17:36:27 +00:00
|
|
|
//
|
|
|
|
// CRT.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 19/07/2015.
|
|
|
|
// Copyright © 2015 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "CRT.hpp"
|
2015-07-20 01:21:34 +00:00
|
|
|
#include <stdarg.h>
|
2015-07-27 03:50:43 +00:00
|
|
|
#include <math.h>
|
2015-07-19 17:36:27 +00:00
|
|
|
|
|
|
|
using namespace Outputs;
|
|
|
|
|
2015-08-20 01:35:26 +00:00
|
|
|
static const uint32_t kCRTFixedPointRange = 0xf7ffffff;
|
|
|
|
static const uint32_t kCRTFixedPointOffset = 0x04000000;
|
2015-07-31 00:07:20 +00:00
|
|
|
|
2016-01-20 13:21:33 +00:00
|
|
|
//static const size_t kCRTVertexOffsetOfPosition = 0;
|
|
|
|
//static const size_t kCRTVertexOffsetOfTexCoord = 4;
|
|
|
|
//static const size_t kCRTVertexOffsetOfLateral = 8;
|
|
|
|
//static const size_t kCRTVertexOffsetOfPhase = 9;
|
|
|
|
//
|
|
|
|
//static const int kCRTSizeOfVertex = 10;
|
|
|
|
|
2015-07-27 03:50:43 +00:00
|
|
|
#define kRetraceXMask 0x01
|
|
|
|
#define kRetraceYMask 0x02
|
|
|
|
|
2016-02-07 22:32:38 +00:00
|
|
|
void CRT::set_new_timing(unsigned int cycles_per_line, unsigned int height_of_display, ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator)
|
2015-07-19 17:36:27 +00:00
|
|
|
{
|
2016-02-07 22:32:38 +00:00
|
|
|
_colour_space = colour_space;
|
|
|
|
_colour_cycle_numerator = colour_cycle_numerator;
|
|
|
|
_colour_cycle_denominator = colour_cycle_denominator;
|
|
|
|
|
2015-08-16 20:08:29 +00:00
|
|
|
const unsigned int syncCapacityLineChargeThreshold = 3;
|
2015-08-19 13:09:00 +00:00
|
|
|
const unsigned int millisecondsHorizontalRetraceTime = 7; // source: Dictionary of Video and Television Technology, p. 234
|
|
|
|
const unsigned int scanlinesVerticalRetraceTime = 10; // source: ibid
|
2015-07-22 22:15:18 +00:00
|
|
|
|
2015-08-19 02:36:32 +00:00
|
|
|
// To quote:
|
|
|
|
//
|
|
|
|
// "retrace interval; The interval of time for the return of the blanked scanning beam of
|
|
|
|
// a TV picture tube or camera tube to the starting point of a line or field. It is about 7 µs
|
|
|
|
// for horizontal retrace and 500 to 750 µs for vertical retrace in NTSC and PAL TV."
|
|
|
|
|
2015-07-25 03:36:44 +00:00
|
|
|
_time_multiplier = (1000 + cycles_per_line - 1) / cycles_per_line;
|
|
|
|
|
2015-07-21 20:37:39 +00:00
|
|
|
// store fundamental display configuration properties
|
2016-02-12 04:43:08 +00:00
|
|
|
_height_of_display = height_of_display;
|
2015-07-25 03:36:44 +00:00
|
|
|
_cycles_per_line = cycles_per_line * _time_multiplier;
|
2015-07-21 03:18:56 +00:00
|
|
|
|
2015-07-21 20:37:39 +00:00
|
|
|
// generate timing values implied by the given arbuments
|
2015-08-03 12:42:05 +00:00
|
|
|
_sync_capacitor_charge_threshold = ((syncCapacityLineChargeThreshold * _cycles_per_line) * 50) >> 7;
|
2015-08-16 20:08:29 +00:00
|
|
|
const unsigned int vertical_retrace_time = scanlinesVerticalRetraceTime * _cycles_per_line;
|
2015-08-19 02:22:47 +00:00
|
|
|
const float halfLineWidth = (float)_height_of_display * 2.0f;
|
2015-07-22 22:15:18 +00:00
|
|
|
|
2016-02-12 04:43:08 +00:00
|
|
|
// creat the two flywheels
|
|
|
|
unsigned int horizontal_retrace_time = scanlinesVerticalRetraceTime * _cycles_per_line;
|
|
|
|
_horizontal_flywheel = std::unique_ptr<Outputs::Flywheel>(new Outputs::Flywheel(_cycles_per_line, (millisecondsHorizontalRetraceTime * _cycles_per_line) >> 6));
|
|
|
|
_vertical_flywheel = std::unique_ptr<Outputs::Flywheel>(new Outputs::Flywheel(_cycles_per_line * height_of_display, scanlinesVerticalRetraceTime * _cycles_per_line));
|
|
|
|
|
2015-08-02 23:30:45 +00:00
|
|
|
for(int c = 0; c < 4; c++)
|
|
|
|
{
|
2016-02-12 04:43:08 +00:00
|
|
|
_scanSpeed[c].x = (c&kRetraceXMask) ? -(kCRTFixedPointRange / horizontal_retrace_time) : (kCRTFixedPointRange / _cycles_per_line);
|
2015-08-02 23:30:45 +00:00
|
|
|
_scanSpeed[c].y = (c&kRetraceYMask) ? -(kCRTFixedPointRange / vertical_retrace_time) : (kCRTFixedPointRange / (_height_of_display * _cycles_per_line));
|
|
|
|
|
|
|
|
// width should be 1.0 / _height_of_display, rotated to match the direction
|
|
|
|
float angle = atan2f(_scanSpeed[c].y, _scanSpeed[c].x);
|
2015-08-16 20:08:29 +00:00
|
|
|
_beamWidth[c].x = (uint32_t)((sinf(angle) / halfLineWidth) * kCRTFixedPointRange);
|
|
|
|
_beamWidth[c].y = (uint32_t)((cosf(angle) / halfLineWidth) * kCRTFixedPointRange);
|
2015-08-02 23:30:45 +00:00
|
|
|
}
|
2015-07-31 22:04:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-23 23:53:20 +00:00
|
|
|
void CRT::set_new_display_type(unsigned int cycles_per_line, DisplayType displayType)
|
2015-07-31 22:04:33 +00:00
|
|
|
{
|
2016-01-23 23:53:20 +00:00
|
|
|
switch(displayType)
|
|
|
|
{
|
|
|
|
case DisplayType::PAL50:
|
2016-02-07 22:32:38 +00:00
|
|
|
set_new_timing(cycles_per_line, 312, ColourSpace::YUV, 1135, 4);
|
2016-01-23 23:53:20 +00:00
|
|
|
break;
|
2015-07-27 03:50:43 +00:00
|
|
|
|
2016-01-23 23:53:20 +00:00
|
|
|
case DisplayType::NTSC60:
|
2016-02-07 22:32:38 +00:00
|
|
|
set_new_timing(cycles_per_line, 262, ColourSpace::YIQ, 545, 2);
|
2016-01-23 23:53:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRT::allocate_buffers(unsigned int number, va_list sizes)
|
|
|
|
{
|
2015-07-21 20:37:39 +00:00
|
|
|
// generate buffers for signal storage as requested — format is
|
|
|
|
// number of buffers, size of buffer 1, size of buffer 2...
|
2015-08-16 20:08:29 +00:00
|
|
|
const uint16_t bufferWidth = 2048;
|
|
|
|
const uint16_t bufferHeight = 2048;
|
2015-07-31 21:47:10 +00:00
|
|
|
for(int frame = 0; frame < sizeof(_frame_builders) / sizeof(*_frame_builders); frame++)
|
2015-07-20 01:21:34 +00:00
|
|
|
{
|
2015-07-23 00:33:20 +00:00
|
|
|
va_list va;
|
2016-01-23 23:53:20 +00:00
|
|
|
va_copy(va, sizes);
|
|
|
|
_frame_builders[frame] = new CRTFrameBuilder(bufferWidth, bufferHeight, number, va);
|
2015-07-23 00:33:20 +00:00
|
|
|
va_end(va);
|
2015-07-20 01:21:34 +00:00
|
|
|
}
|
2015-07-25 03:29:45 +00:00
|
|
|
_current_frame_builder = _frame_builders[0];
|
2016-01-23 23:53:20 +00:00
|
|
|
}
|
2015-07-21 20:37:39 +00:00
|
|
|
|
2016-01-23 23:53:20 +00:00
|
|
|
CRT::CRT() :
|
|
|
|
_next_scan(0),
|
|
|
|
_frame_read_pointer(0),
|
|
|
|
_sync_capacitor_charge_level(0),
|
|
|
|
_is_receiving_sync(false),
|
2016-02-05 03:28:50 +00:00
|
|
|
_current_frame_mutex(new std::mutex),
|
2016-02-08 03:18:55 +00:00
|
|
|
_visible_area(Rect(0, 0, 1, 1)),
|
2016-01-23 23:53:20 +00:00
|
|
|
_rasterPosition({.x = 0, .y = 0})
|
2016-02-05 03:57:46 +00:00
|
|
|
{
|
|
|
|
construct_openGL();
|
|
|
|
}
|
2016-01-23 23:53:20 +00:00
|
|
|
|
2016-02-07 22:32:38 +00:00
|
|
|
CRT::CRT(unsigned int cycles_per_line, unsigned int height_of_display, ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator, unsigned int number_of_buffers, ...) : CRT()
|
2016-01-23 23:53:20 +00:00
|
|
|
{
|
2016-02-07 22:32:38 +00:00
|
|
|
set_new_timing(cycles_per_line, height_of_display, colour_space, colour_cycle_numerator, colour_cycle_denominator);
|
2016-01-23 23:53:20 +00:00
|
|
|
|
|
|
|
va_list buffer_sizes;
|
|
|
|
va_start(buffer_sizes, number_of_buffers);
|
|
|
|
allocate_buffers(number_of_buffers, buffer_sizes);
|
|
|
|
va_end(buffer_sizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
CRT::CRT(unsigned int cycles_per_line, DisplayType displayType, unsigned int number_of_buffers, ...) : CRT()
|
|
|
|
{
|
|
|
|
set_new_display_type(cycles_per_line, displayType);
|
|
|
|
|
|
|
|
va_list buffer_sizes;
|
|
|
|
va_start(buffer_sizes, number_of_buffers);
|
|
|
|
allocate_buffers(number_of_buffers, buffer_sizes);
|
|
|
|
va_end(buffer_sizes);
|
2015-07-20 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CRT::~CRT()
|
|
|
|
{
|
2015-07-31 21:47:10 +00:00
|
|
|
for(int frame = 0; frame < sizeof(_frame_builders) / sizeof(*_frame_builders); frame++)
|
2015-07-20 01:21:34 +00:00
|
|
|
{
|
2015-07-25 03:29:45 +00:00
|
|
|
delete _frame_builders[frame];
|
2015-07-20 01:21:34 +00:00
|
|
|
}
|
2016-02-05 03:57:46 +00:00
|
|
|
destruct_openGL();
|
2015-07-19 17:36:27 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 01:43:00 +00:00
|
|
|
#pragma mark - Sync loop
|
2015-07-20 03:43:22 +00:00
|
|
|
|
2016-02-12 04:43:08 +00:00
|
|
|
Flywheel::SyncEvent CRT::get_next_vertical_sync_event(bool vsync_is_requested, unsigned int cycles_to_run_for, unsigned int *cycles_advanced)
|
2015-07-20 03:43:22 +00:00
|
|
|
{
|
2016-02-12 04:43:08 +00:00
|
|
|
return _vertical_flywheel->get_next_event_in_period(vsync_is_requested, cycles_to_run_for, cycles_advanced);
|
2015-07-20 03:43:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 04:43:08 +00:00
|
|
|
Flywheel::SyncEvent CRT::get_next_horizontal_sync_event(bool hsync_is_requested, unsigned int cycles_to_run_for, unsigned int *cycles_advanced)
|
2015-07-23 22:53:18 +00:00
|
|
|
{
|
2016-02-12 04:43:08 +00:00
|
|
|
return _horizontal_flywheel->get_next_event_in_period(hsync_is_requested, cycles_to_run_for, cycles_advanced);
|
2015-07-23 22:53:18 +00:00
|
|
|
}
|
|
|
|
|
2016-01-23 22:49:25 +00:00
|
|
|
void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divider, bool hsync_requested, bool vsync_requested, const bool vsync_charging, const Type type, uint16_t tex_x, uint16_t tex_y)
|
2015-07-20 03:43:22 +00:00
|
|
|
{
|
2015-07-25 03:36:44 +00:00
|
|
|
number_of_cycles *= _time_multiplier;
|
|
|
|
|
2015-07-27 03:50:43 +00:00
|
|
|
bool is_output_run = ((type == Type::Level) || (type == Type::Data));
|
2016-02-12 04:43:08 +00:00
|
|
|
vsync_requested &= (_sync_capacitor_charge_level >= _sync_capacitor_charge_threshold);
|
2015-07-21 03:18:56 +00:00
|
|
|
|
2015-07-21 01:43:00 +00:00
|
|
|
while(number_of_cycles) {
|
2015-07-21 20:37:39 +00:00
|
|
|
|
2015-08-16 20:08:29 +00:00
|
|
|
unsigned int time_until_vertical_sync_event, time_until_horizontal_sync_event;
|
2016-02-12 04:43:08 +00:00
|
|
|
Flywheel::SyncEvent next_vertical_sync_event = get_next_vertical_sync_event(vsync_requested, number_of_cycles, &time_until_vertical_sync_event);
|
|
|
|
Flywheel::SyncEvent next_horizontal_sync_event = get_next_horizontal_sync_event(hsync_requested, time_until_vertical_sync_event, &time_until_horizontal_sync_event);
|
2015-07-23 22:53:18 +00:00
|
|
|
|
2015-07-21 20:37:39 +00:00
|
|
|
// get the next sync event and its timing; hsync request is instantaneous (being edge triggered) so
|
|
|
|
// set it to false for the next run through this loop (if any)
|
2015-08-16 20:08:29 +00:00
|
|
|
unsigned int next_run_length = std::min(time_until_vertical_sync_event, time_until_horizontal_sync_event);
|
2015-07-20 03:43:22 +00:00
|
|
|
|
2015-08-06 01:12:33 +00:00
|
|
|
hsync_requested = false;
|
|
|
|
vsync_requested = false;
|
2015-08-03 12:42:05 +00:00
|
|
|
|
2015-08-06 01:12:33 +00:00
|
|
|
uint8_t *next_run = (is_output_run && _current_frame_builder && next_run_length) ? _current_frame_builder->get_next_run() : nullptr;
|
2016-02-12 04:43:08 +00:00
|
|
|
int lengthMask = (_horizontal_flywheel->is_in_retrace() ? kRetraceXMask : 0) | (_vertical_flywheel->is_in_retrace() ? kRetraceYMask : 0);
|
2015-07-23 00:33:20 +00:00
|
|
|
|
2015-08-06 01:12:33 +00:00
|
|
|
#define position_x(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfPosition + 0])
|
|
|
|
#define position_y(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfPosition + 2])
|
|
|
|
#define tex_x(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfTexCoord + 0])
|
|
|
|
#define tex_y(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfTexCoord + 2])
|
2015-08-02 18:25:21 +00:00
|
|
|
#define lateral(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfLateral]
|
|
|
|
|
2015-08-16 20:12:20 +00:00
|
|
|
#define InternalToUInt16(v) ((v) + 32768) >> 16
|
|
|
|
|
2015-07-25 03:29:45 +00:00
|
|
|
if(next_run)
|
2015-07-23 22:53:18 +00:00
|
|
|
{
|
2016-02-12 04:43:08 +00:00
|
|
|
unsigned int x_position = _horizontal_flywheel->get_current_output_position() * (kCRTFixedPointRange / 1024);
|
|
|
|
unsigned int y_position = (_vertical_flywheel->get_current_output_position() / 312) * (kCRTFixedPointRange / 1024);
|
|
|
|
|
2015-07-23 00:33:20 +00:00
|
|
|
// set the type, initial raster position and type of this run
|
2016-02-12 04:43:08 +00:00
|
|
|
position_x(0) = position_x(4) = InternalToUInt16(kCRTFixedPointOffset + x_position + _beamWidth[lengthMask].x);
|
|
|
|
position_y(0) = position_y(4) = InternalToUInt16(kCRTFixedPointOffset + y_position + _beamWidth[lengthMask].y);
|
|
|
|
position_x(1) = InternalToUInt16(kCRTFixedPointOffset + x_position - _beamWidth[lengthMask].x);
|
|
|
|
position_y(1) = InternalToUInt16(kCRTFixedPointOffset + y_position - _beamWidth[lengthMask].y);
|
2015-08-02 18:25:21 +00:00
|
|
|
|
|
|
|
tex_x(0) = tex_x(1) = tex_x(4) = tex_x;
|
2015-08-02 18:32:29 +00:00
|
|
|
|
|
|
|
// these things are constants across the line so just throw them out now
|
|
|
|
tex_y(0) = tex_y(4) = tex_y(1) = tex_y(2) = tex_y(3) = tex_y(5) = tex_y;
|
|
|
|
lateral(0) = lateral(4) = lateral(5) = 0;
|
|
|
|
lateral(1) = lateral(2) = lateral(3) = 1;
|
2015-07-25 03:29:45 +00:00
|
|
|
}
|
2015-07-23 00:33:20 +00:00
|
|
|
|
2016-02-12 04:43:08 +00:00
|
|
|
// decrement the number of cycles left to run for and increment the
|
|
|
|
// horizontal counter appropriately
|
|
|
|
number_of_cycles -= next_run_length;
|
2015-08-02 23:30:45 +00:00
|
|
|
|
2016-02-12 04:43:08 +00:00
|
|
|
// either charge or deplete the vertical retrace capacitor (making sure it stops at 0)
|
|
|
|
if (vsync_charging && !_vertical_flywheel->is_in_retrace())
|
|
|
|
_sync_capacitor_charge_level += next_run_length;
|
2015-07-25 03:29:45 +00:00
|
|
|
else
|
2016-02-12 04:43:08 +00:00
|
|
|
_sync_capacitor_charge_level = std::max(_sync_capacitor_charge_level - (int)next_run_length, 0);
|
2015-07-23 00:33:20 +00:00
|
|
|
|
2016-02-12 04:43:08 +00:00
|
|
|
// react to the incoming event...
|
|
|
|
_horizontal_flywheel->apply_event(next_run_length, (next_run_length == time_until_horizontal_sync_event) ? next_horizontal_sync_event : Flywheel::SyncEvent::None);
|
|
|
|
_vertical_flywheel->apply_event(next_run_length, (next_run_length == time_until_vertical_sync_event) ? next_vertical_sync_event : Flywheel::SyncEvent::None);
|
2015-07-23 00:33:20 +00:00
|
|
|
|
2015-07-25 03:29:45 +00:00
|
|
|
if(next_run)
|
|
|
|
{
|
2016-02-12 04:43:08 +00:00
|
|
|
unsigned int x_position = _horizontal_flywheel->get_current_output_position() * (kCRTFixedPointRange / 1024);
|
|
|
|
unsigned int y_position = (_vertical_flywheel->get_current_output_position() / 312) * (kCRTFixedPointRange / 1024);
|
|
|
|
|
2015-07-23 00:33:20 +00:00
|
|
|
// store the final raster position
|
2016-02-12 04:43:08 +00:00
|
|
|
position_x(2) = position_x(3) = InternalToUInt16(kCRTFixedPointOffset + x_position - _beamWidth[lengthMask].x);
|
|
|
|
position_y(2) = position_y(3) = InternalToUInt16(kCRTFixedPointOffset + y_position - _beamWidth[lengthMask].y);
|
|
|
|
position_x(5) = InternalToUInt16(kCRTFixedPointOffset + x_position + _beamWidth[lengthMask].x);
|
|
|
|
position_y(5) = InternalToUInt16(kCRTFixedPointOffset + y_position + _beamWidth[lengthMask].y);
|
2015-07-23 00:33:20 +00:00
|
|
|
|
|
|
|
// if this is a data run then advance the buffer pointer
|
2016-01-30 02:14:13 +00:00
|
|
|
if(type == Type::Data && source_divider) tex_x += next_run_length / (_time_multiplier * source_divider);
|
2015-07-23 00:33:20 +00:00
|
|
|
|
|
|
|
// if this is a data or level run then store the end point
|
2015-08-02 18:25:21 +00:00
|
|
|
tex_x(2) = tex_x(3) = tex_x(5) = tex_x;
|
2015-07-20 03:43:22 +00:00
|
|
|
}
|
2015-07-21 01:43:00 +00:00
|
|
|
|
2016-02-12 04:43:08 +00:00
|
|
|
if(next_run_length == time_until_vertical_sync_event && next_vertical_sync_event == Flywheel::SyncEvent::EndRetrace)
|
2015-07-23 22:53:18 +00:00
|
|
|
{
|
2016-02-12 04:43:08 +00:00
|
|
|
if(_current_frame_builder)
|
2015-07-23 22:53:18 +00:00
|
|
|
{
|
2016-02-12 04:43:08 +00:00
|
|
|
_current_frame_builder->complete();
|
|
|
|
_current_frame_mutex->lock();
|
|
|
|
_current_frame = &_current_frame_builder->frame;
|
|
|
|
_current_frame_mutex->unlock();
|
|
|
|
// TODO: how to communicate did_detect_vsync? Bring the delegate back?
|
|
|
|
// _delegate->crt_did_end_frame(this, &_current_frame_builder->frame, _did_detect_vsync);
|
2015-07-23 22:53:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 04:43:08 +00:00
|
|
|
// if(_frames_with_delegate < kCRTNumberOfFrames)
|
|
|
|
// {
|
|
|
|
_frame_read_pointer = (_frame_read_pointer + 1)%kCRTNumberOfFrames;
|
|
|
|
_current_frame_builder = _frame_builders[_frame_read_pointer];
|
|
|
|
_current_frame_builder->reset();
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// _current_frame_builder = nullptr;
|
|
|
|
|
2015-07-20 03:43:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - stream feeding methods
|
|
|
|
|
2016-01-23 22:49:25 +00:00
|
|
|
void CRT::output_scan()
|
2016-01-23 22:44:34 +00:00
|
|
|
{
|
2016-01-23 22:49:25 +00:00
|
|
|
_next_scan ^= 1;
|
|
|
|
Scan *scan = &_scans[_next_scan];
|
|
|
|
|
2016-01-23 22:44:34 +00:00
|
|
|
bool this_is_sync = (scan->type == Type::Sync);
|
|
|
|
bool hsync_requested = !_is_receiving_sync && this_is_sync;
|
2016-02-12 04:43:08 +00:00
|
|
|
bool vsync_requested = _is_receiving_sync && !this_is_sync;
|
2016-01-23 22:44:34 +00:00
|
|
|
_is_receiving_sync = this_is_sync;
|
|
|
|
|
2016-01-23 22:49:25 +00:00
|
|
|
advance_cycles(scan->number_of_cycles, scan->source_divider, hsync_requested, vsync_requested, this_is_sync, scan->type, scan->tex_x, scan->tex_y);
|
2016-01-23 22:44:34 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 20:37:39 +00:00
|
|
|
/*
|
|
|
|
These all merely channel into advance_cycles, supplying appropriate arguments
|
|
|
|
*/
|
2015-08-16 20:08:29 +00:00
|
|
|
void CRT::output_sync(unsigned int number_of_cycles)
|
2015-07-19 17:36:27 +00:00
|
|
|
{
|
2016-01-23 22:44:34 +00:00
|
|
|
_scans[_next_scan].type = Type::Sync;
|
|
|
|
_scans[_next_scan].number_of_cycles = number_of_cycles;
|
2016-01-23 22:49:25 +00:00
|
|
|
output_scan();
|
2015-07-19 17:36:27 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 20:08:29 +00:00
|
|
|
void CRT::output_blank(unsigned int number_of_cycles)
|
2015-07-19 17:36:27 +00:00
|
|
|
{
|
2016-01-23 22:44:34 +00:00
|
|
|
_scans[_next_scan].type = Type::Blank;
|
|
|
|
_scans[_next_scan].number_of_cycles = number_of_cycles;
|
2016-01-23 22:49:25 +00:00
|
|
|
output_scan();
|
2015-07-19 17:36:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-06 00:25:30 +00:00
|
|
|
void CRT::output_level(unsigned int number_of_cycles)
|
2015-07-19 17:36:27 +00:00
|
|
|
{
|
2016-01-23 22:44:34 +00:00
|
|
|
_scans[_next_scan].type = Type::Level;
|
|
|
|
_scans[_next_scan].number_of_cycles = number_of_cycles;
|
|
|
|
_scans[_next_scan].tex_x = _current_frame_builder ? _current_frame_builder->_write_x_position : 0;
|
|
|
|
_scans[_next_scan].tex_y = _current_frame_builder ? _current_frame_builder->_write_y_position : 0;
|
2016-01-23 22:49:25 +00:00
|
|
|
output_scan();
|
2016-01-23 22:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CRT::output_colour_burst(unsigned int number_of_cycles, uint8_t phase, uint8_t magnitude)
|
|
|
|
{
|
|
|
|
_scans[_next_scan].type = Type::ColourBurst;
|
|
|
|
_scans[_next_scan].number_of_cycles = number_of_cycles;
|
|
|
|
_scans[_next_scan].phase = phase;
|
|
|
|
_scans[_next_scan].magnitude = magnitude;
|
2016-01-23 22:49:25 +00:00
|
|
|
output_scan();
|
2015-07-21 01:43:00 +00:00
|
|
|
}
|
|
|
|
|
2016-01-22 02:17:47 +00:00
|
|
|
void CRT::output_data(unsigned int number_of_cycles, unsigned int source_divider)
|
2015-07-21 01:43:00 +00:00
|
|
|
{
|
2016-02-06 21:07:23 +00:00
|
|
|
if(_current_frame_builder) _current_frame_builder->reduce_previous_allocation_to(number_of_cycles / source_divider);
|
|
|
|
|
2016-01-23 22:44:34 +00:00
|
|
|
_scans[_next_scan].type = Type::Data;
|
|
|
|
_scans[_next_scan].number_of_cycles = number_of_cycles;
|
|
|
|
_scans[_next_scan].tex_x = _current_frame_builder ? _current_frame_builder->_write_x_position : 0;
|
|
|
|
_scans[_next_scan].tex_y = _current_frame_builder ? _current_frame_builder->_write_y_position : 0;
|
|
|
|
_scans[_next_scan].source_divider = source_divider;
|
2016-01-23 22:49:25 +00:00
|
|
|
output_scan();
|
2015-07-19 17:36:27 +00:00
|
|
|
}
|
2015-07-20 01:21:34 +00:00
|
|
|
|
2015-07-20 03:43:22 +00:00
|
|
|
#pragma mark - Buffer supply
|
2015-07-20 01:21:34 +00:00
|
|
|
|
|
|
|
void CRT::allocate_write_area(int required_length)
|
|
|
|
{
|
2015-07-25 03:29:45 +00:00
|
|
|
if(_current_frame_builder) _current_frame_builder->allocate_write_area(required_length);
|
2015-07-23 00:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t *CRT::get_write_target_for_buffer(int buffer)
|
|
|
|
{
|
2015-07-25 03:29:45 +00:00
|
|
|
if (!_current_frame_builder) return nullptr;
|
|
|
|
return _current_frame_builder->get_write_target_for_buffer(buffer);
|
2015-07-23 00:33:20 +00:00
|
|
|
}
|