From caffe56a2d5fd11a650e4dfa9d68cb4b2c04496b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 27 Jul 2015 00:28:47 -0400 Subject: [PATCH] Slightly expanded width of cathode ray gun, decided to figure out exactly how to deal with off-by-one lengths and precision at a later date, ensured that failure to catch vertical sync doesn't cause out-of-bounds buffer access on the hard-coded, assumed large enough, 512x512 data textures. --- Machines/Atari2600.cpp | 2 +- .../Mac/Clock Signal/CSCathodeRayView.m | 4 +-- Outputs/CRT.cpp | 27 ++++++------------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/Machines/Atari2600.cpp b/Machines/Atari2600.cpp index 0c1c10202..b81c4c986 100644 --- a/Machines/Atari2600.cpp +++ b/Machines/Atari2600.cpp @@ -101,7 +101,7 @@ void Machine::output_state(OutputState state, uint8_t *pixel) if(state == OutputState::Pixel && _outputBuffer) { - _outputBuffer[(_lastOutputStateDuration * 4) + 0] = 0x40;//pixel[0]; + _outputBuffer[(_lastOutputStateDuration * 4) + 0] = pixel[0]; _outputBuffer[(_lastOutputStateDuration * 4) + 1] = pixel[1]; _outputBuffer[(_lastOutputStateDuration * 4) + 2] = pixel[2]; _outputBuffer[(_lastOutputStateDuration * 4) + 3] = 0xff; diff --git a/OSBindings/Mac/Clock Signal/CSCathodeRayView.m b/OSBindings/Mac/Clock Signal/CSCathodeRayView.m index 4bf57c10e..7b5049f35 100644 --- a/OSBindings/Mac/Clock Signal/CSCathodeRayView.m +++ b/OSBindings/Mac/Clock Signal/CSCathodeRayView.m @@ -49,7 +49,7 @@ CVDisplayLinkStart(displayLink); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glBlendFunc(GL_ONE, GL_ONE); } static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *now, const CVTimeStamp *outputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) @@ -131,7 +131,7 @@ const char *vertexShader = "\n" "void main (void)\n" "{\n" - "srcCoordinatesVarying = vec2((srcCoordinates.x + 0.5) / 511.0, (srcCoordinates.y + 0.5) / 511.0);\n" + "srcCoordinatesVarying = vec2(srcCoordinates.x / 512.0, srcCoordinates.y / 512.0);\n" "gl_Position = vec4(position.x * 2.0 - 1.0, 1.0 - position.y * 2.0, 0.0, 1.0);\n" "}\n"; diff --git a/Outputs/CRT.cpp b/Outputs/CRT.cpp index 6c93f6394..18b688226 100644 --- a/Outputs/CRT.cpp +++ b/Outputs/CRT.cpp @@ -54,7 +54,7 @@ CRT::CRT(int cycles_per_line, int height_of_display, int number_of_buffers, ...) // width should be 1.0 / _height_of_display, rotated to match the direction float angle = atan2f(scanSpeedYfl, scanSpeedXfl); - float halfLineWidth = (float)_height_of_display * 2.0f; + float halfLineWidth = (float)_height_of_display * 1.9f; _widths[0][0] = (sinf(angle) / halfLineWidth) * UINT32_MAX; _widths[0][1] = (cosf(angle) / halfLineWidth) * UINT32_MAX; @@ -205,14 +205,13 @@ void CRT::advance_cycles(int number_of_cycles, bool hsync_requested, const bool if(next_run) { // set the type, initial raster position and type of this run - next_run[0] = (_rasterPosition.x + width[0]) >> 16; - next_run[1] = (_rasterPosition.y + width[1]) >> 16; + next_run[0] = next_run[20] = (_rasterPosition.x + width[0]) >> 16; + next_run[1] = next_run[21] = (_rasterPosition.y + width[1]) >> 16; next_run[4] = (_rasterPosition.x - width[0]) >> 16; next_run[5] = (_rasterPosition.y - width[1]) >> 16; - next_run[2] = next_run[6] = tex_x; - next_run[3] = next_run[7] = tex_y; - + next_run[2] = next_run[6] = next_run[22] = tex_x; + next_run[3] = next_run[7] = next_run[23] = tex_y; } // advance the raster position as dictated by current sync status @@ -236,23 +235,13 @@ void CRT::advance_cycles(int number_of_cycles, bool hsync_requested, const bool next_run[16] = (_rasterPosition.x + width[0]) >> 16; next_run[17] = (_rasterPosition.y + width[1]) >> 16; - next_run[20] = next_run[0]; - next_run[21] = next_run[1]; - // if this is a data run then advance the buffer pointer if(type == Type::Data) tex_x += next_run_length / _time_multiplier; // if this is a data or level run then store the end point - next_run[10] = tex_x; - next_run[11] = tex_y; - next_run[14] = tex_x; - next_run[15] = tex_y; - next_run[18] = tex_x; - next_run[19] = tex_y; - - next_run[22] = next_run[2]; - next_run[23] = next_run[3]; + next_run[10] = next_run[14] = next_run[18] = tex_x; + next_run[11] = next_run[15] = next_run[19] = tex_y; } // decrement the number of cycles left to run for and increment the @@ -443,7 +432,7 @@ void CRTFrameBuilder::allocate_write_area(int required_length) if (_next_write_x_position + required_length > frame.size.width) { _next_write_x_position = 0; - _next_write_y_position++; + _next_write_y_position = (_next_write_y_position+1)&(frame.size.height-1); frame.dirty_size.height++; }