diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index a5113400f..429a084dc 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -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 diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index 92f2c7a96..e1fe9ca0c 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -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; } } diff --git a/Outputs/CRT/Internals/CRTOpenGL.cpp b/Outputs/CRT/Internals/CRTOpenGL.cpp index ecd1eb6f4..f929da5b2 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.cpp +++ b/Outputs/CRT/Internals/CRTOpenGL.cpp @@ -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)