From 5313b48ebdf67a7066b882aa6b4391590939837a Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 2 Aug 2015 20:32:18 -0400 Subject: [PATCH] I'm ashamed to admit, I: played with numbers until enough things looked stable such that I can investigate other things. Discovery: my PAL autodetection was way off. Fixed, hopefully. --- Machines/Atari2600.cpp | 19 +++++++++++-------- OSBindings/Mac/Clock Signal/CSAtari2600.mm | 4 ++-- .../Mac/Clock Signal/CSCathodeRayView.m | 1 + Outputs/CRT.cpp | 8 ++++---- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Machines/Atari2600.cpp b/Machines/Atari2600.cpp index 5bc8aed51..e1ac8617f 100644 --- a/Machines/Atari2600.cpp +++ b/Machines/Atari2600.cpp @@ -135,6 +135,9 @@ void Machine::get_output_pixel(uint8_t *pixel, int offset) void Machine::output_pixels(int count) { + const int32_t start_of_sync = 214; + const int32_t end_of_sync = 188; + _timestamp += count; while(count--) { @@ -143,7 +146,7 @@ void Machine::output_pixels(int count) // logic: if in vsync, output that; otherwise if in vblank then output that; // otherwise output a pixel if(_vSyncEnabled) { - state = (_horizontalTimer < 212) ? OutputState::Sync : OutputState::Blank; + state = (_horizontalTimer < start_of_sync) ? OutputState::Sync : OutputState::Blank; } else { // blank is decoded as 68 counts; sync and colour burst as 16 counts @@ -155,8 +158,8 @@ void Machine::output_pixels(int count) // it'll be about 43 cycles from start of hsync to start of visible frame, so... // guesses, until I can find information: 26 cycles blank, 16 sync, 40 blank, 160 pixels - if(_horizontalTimer >= 212) state = OutputState::Blank; - else if (_horizontalTimer >= 196) state = OutputState::Sync; + if(_horizontalTimer >= start_of_sync) state = OutputState::Blank; + else if (_horizontalTimer >= end_of_sync) state = OutputState::Sync; else if (_horizontalTimer >= 160) state = OutputState::Blank; else { if(_vBlankEnabled) { @@ -259,11 +262,11 @@ int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t add case 0x0e: _playfield[1] = *value; break; case 0x0f: _playfield[2] = *value; break; - case 0x10: _playerPosition[0] = _horizontalTimer; break; - case 0x11: _playerPosition[1] = _horizontalTimer; break; - case 0x12: _missilePosition[0] = _horizontalTimer; break; - case 0x13: _missilePosition[1] = _horizontalTimer; break; - case 0x14: _ballPosition = _horizontalTimer; break; + case 0x10: _playerPosition[0] = _horizontalTimer - 5; break; + case 0x11: _playerPosition[1] = _horizontalTimer - 5; break; + case 0x12: _missilePosition[0] = _horizontalTimer - 4; break; + case 0x13: _missilePosition[1] = _horizontalTimer - 4; break; + case 0x14: _ballPosition = _horizontalTimer - 4; break; case 0x1c: _ballGraphicsEnable = _ballGraphicsEnableLatch; diff --git a/OSBindings/Mac/Clock Signal/CSAtari2600.mm b/OSBindings/Mac/Clock Signal/CSAtari2600.mm index 7b5d4812c..d45ccf40f 100644 --- a/OSBindings/Mac/Clock Signal/CSAtari2600.mm +++ b/OSBindings/Mac/Clock Signal/CSAtari2600.mm @@ -31,7 +31,7 @@ struct Atari2600CRTDelegate: public Outputs::CRT::CRTDelegate { if(!didDetectVSync) { - _failedVSyncCount++; + _failedVSyncCount+=2; if(_failedVSyncCount == 60) { @@ -40,7 +40,7 @@ struct Atari2600CRTDelegate: public Outputs::CRT::CRTDelegate { } else { - _failedVSyncCount = MAX(_failedVSyncCount - 2, 0); + _failedVSyncCount = MAX(_failedVSyncCount - 1, 0); } dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/OSBindings/Mac/Clock Signal/CSCathodeRayView.m b/OSBindings/Mac/Clock Signal/CSCathodeRayView.m index c9435ad10..764e0949d 100644 --- a/OSBindings/Mac/Clock Signal/CSCathodeRayView.m +++ b/OSBindings/Mac/Clock Signal/CSCathodeRayView.m @@ -176,6 +176,7 @@ const char *fragmentShader = "in float lateralVarying;" "out vec4 fragColour;\n" "uniform sampler2D texID;\n" + "uniform float alpha;\n" "\n" "void main(void)\n" "{\n" diff --git a/Outputs/CRT.cpp b/Outputs/CRT.cpp index 5207d7277..ab4ce5a6c 100644 --- a/Outputs/CRT.cpp +++ b/Outputs/CRT.cpp @@ -20,9 +20,9 @@ static const uint32_t kCRTFixedPointOffset = 0x08000000; void CRT::set_new_timing(int cycles_per_line, int height_of_display) { - const int syncCapacityLineChargeThreshold = 4; - const int millisecondsHorizontalRetraceTime = 10; // source: Dictionary of Video and Television Technology, p. 234 - const int scanlinesVerticalRetraceTime = 7; // source: ibid + const int syncCapacityLineChargeThreshold = 5; + const int millisecondsHorizontalRetraceTime = 7; // source: Dictionary of Video and Television Technology, p. 234 + const int scanlinesVerticalRetraceTime = 10; // source: ibid _time_multiplier = (1000 + cycles_per_line - 1) / cycles_per_line; height_of_display += (height_of_display / 20); // this is the overrun area we'll use to @@ -299,7 +299,7 @@ void CRT::advance_cycles(int number_of_cycles, bool hsync_requested, const bool { _current_frame_builder->complete(); _frames_with_delegate++; - _delegate->crt_did_end_frame(this, &_current_frame_builder->frame, _did_detect_hsync); + _delegate->crt_did_end_frame(this, &_current_frame_builder->frame, _did_detect_vsync); } if(_frames_with_delegate < kCRTNumberOfFrames)