1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-06 01:28:57 +00:00

These functions appear correctly to model the NTSC and PAL palettes; the CRT's attempt to switch function doesn't work properly yet though.

This commit is contained in:
Thomas Harte 2016-05-11 21:07:18 -04:00
parent 93760bf8fa
commit 4b3c4082d2
3 changed files with 29 additions and 7 deletions

View File

@ -30,18 +30,37 @@ Machine::Machine() :
void Machine::setup_output(float aspect_ratio)
{
_crt = new Outputs::CRT::CRT(228, 1, 263, Outputs::CRT::ColourSpace::YIQ, 228, 1, 1);
// this is the NTSC phase offset function; see below for PAL
_crt->set_composite_sampling_function(
"float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)\n"
"{"
"uint c = texture(texID, coordinate).r;"
"uint y = (c >> 1) & 7u;"
"uint iPhase = (c >> 4);"
"float phaseOffset = 6.283185308 * float(iPhase + 13u) / 16.0;"
"float phaseOffset = 6.283185308 * float(iPhase + 13u) / 14.0;"
"return (float(y) / 7.0) * (1.0 - amplitude) + step(1, iPhase) * amplitude * cos(phase + phaseOffset);"
"}");
_crt->set_output_device(Outputs::CRT::Television);
}
void Machine::switch_region()
{
// the PAL function
_crt->set_composite_sampling_function(
"float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)\n"
"{"
"uint c = texture(texID, coordinate).r;"
"uint y = (c >> 1) & 7u;"
"uint iPhase = (c >> 4);"
"float phaseOffset = (0.5 + 2.0 * (float(iPhase&1u) - 0.5) * (float((iPhase >> 1) + (iPhase&1u)) / 14.0));"
"return (float(y) / 7.0) * (1.0 - amplitude) + step(2, iPhase) * step(iPhase, 13) * amplitude * cos(phase + 6.283185308 * phaseOffset);"
"}");
_crt->set_new_timing(228, 312, Outputs::CRT::ColourSpace::YUV, 228, 1);
}
void Machine::close_output()
{
delete _crt;
@ -54,11 +73,6 @@ Machine::~Machine()
close_output();
}
void Machine::switch_region()
{
_crt->set_new_timing(228, 312, Outputs::CRT::ColourSpace::YUV, 228, 1);
}
void Machine::get_output_pixel(uint8_t *pixel, int offset)
{
// get the playfield pixel and hence a proposed colour

View File

@ -216,9 +216,13 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi
if(_delegate)
{
_frames_since_last_delegate_call++;
if(_frames_since_last_delegate_call == 100)
if(_frames_since_last_delegate_call == 20)
{
// Yuck: to deal with the permitted ability of the delegate to make CRT changes that require the lock to be
// asserted during the delegate call, temporarily release the lock. TODO: find a less blunt instrument.
_openGL_output_builder->unlock_output();
_delegate->crt_did_end_batch_of_frames(this, _frames_since_last_delegate_call, _vertical_flywheel->get_and_reset_number_of_surprises());
_openGL_output_builder->lock_output();
_frames_since_last_delegate_call = 0;
}
}

View File

@ -337,7 +337,11 @@ void OpenGLOutputBuilder::set_openGL_context_will_change(bool should_delete_reso
void OpenGLOutputBuilder::set_composite_sampling_function(const char *shader)
{
_output_mutex->lock();
_composite_shader = strdup(shader);
output_shader_program = nullptr;
framebuffer = nullptr;
_output_mutex->unlock();
}
void OpenGLOutputBuilder::set_rgb_sampling_function(const char *shader)