diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 0e51c89bf..16ccfa9a1 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -67,6 +67,7 @@ void Machine::setup_output() // "return vec4(1.0);" "}"); _crt->set_output_device(Outputs::CRT::Monitor); + _crt->set_visible_area(_crt->get_rect_for_area(first_graphics_line - 3, 256, first_graphics_cycle * crt_cycles_multiplier, 80 * crt_cycles_multiplier, 4.0f / 3.0f)); // The maximum output frequency is 62500Hz and all other permitted output frequencies are integral divisions of that; // however setting the speaker on or off can happen on any 2Mhz cycle, and probably (?) takes effect immediately. So diff --git a/OSBindings/Mac/Clock Signal/Documents/Atari2600Document.swift b/OSBindings/Mac/Clock Signal/Documents/Atari2600Document.swift index c9b385399..8e42b1186 100644 --- a/OSBindings/Mac/Clock Signal/Documents/Atari2600Document.swift +++ b/OSBindings/Mac/Clock Signal/Documents/Atari2600Document.swift @@ -19,7 +19,6 @@ class Atari2600Document: MachineDocument { override func windowControllerDidLoadNib(aController: NSWindowController) { super.windowControllerDidLoadNib(aController) atari2600.view = openGLView -// openGLView.frameBounds = CGRectMake(0.1, 0.1, 0.8, 0.8) } override class func autosavesInPlace() -> Bool { diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index 86c909722..d5c99866c 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -357,3 +357,41 @@ void CRT::output_data(unsigned int number_of_cycles, unsigned int source_divider }; output_scan(&scan); } + +Outputs::CRT::Rect CRT::get_rect_for_area(int first_line_after_sync, int number_of_lines, int first_cycle_after_sync, int number_of_cycles, float aspect_ratio) +{ + first_cycle_after_sync *= _time_multiplier; + number_of_cycles *= _time_multiplier; + + // determine prima facie x extent + unsigned int horizontal_period = _horizontal_flywheel->get_standard_period(); + unsigned int horizontal_scan_period = _horizontal_flywheel->get_scan_period(); + unsigned int horizontal_retrace_period = horizontal_period - horizontal_scan_period; + + float start_x = (float)((unsigned)first_cycle_after_sync - horizontal_retrace_period) / (float)horizontal_scan_period; + float width = (float)number_of_cycles / (float)horizontal_scan_period; + + // determine prima facie y extent + unsigned int vertical_period = _vertical_flywheel->get_standard_period(); + unsigned int vertical_scan_period = _vertical_flywheel->get_scan_period(); + unsigned int vertical_retrace_period = vertical_period - vertical_scan_period; + float start_y = (float)(((unsigned)first_line_after_sync * horizontal_period) - vertical_retrace_period) / (float)vertical_scan_period; + float height = (float)((unsigned)number_of_lines * horizontal_period) / vertical_scan_period; + + // adjust to ensure aspect ratio is correct + float adjusted_aspect_ratio = (3.0f*aspect_ratio / 4.0f); + float ideal_width = height * adjusted_aspect_ratio; + if(ideal_width > width) + { + start_x -= (ideal_width - width) * 0.5f; + width = ideal_width; + } + else + { + float ideal_height = width / adjusted_aspect_ratio; + start_y -= (ideal_height - height) * 0.5f; + height = ideal_height; + } + + return Rect(start_x, start_y, width, height); +} diff --git a/Outputs/CRT/CRT.hpp b/Outputs/CRT/CRT.hpp index 5303fbe6c..2f2dadc26 100644 --- a/Outputs/CRT/CRT.hpp +++ b/Outputs/CRT/CRT.hpp @@ -247,6 +247,8 @@ class CRT { { _openGL_output_builder->set_visible_area(visible_area); } + + Rect get_rect_for_area(int first_line_after_sync, int number_of_lines, int first_cycle_after_sync, int number_of_cycles, float aspect_ratio); }; } diff --git a/Outputs/CRT/CRTTypes.hpp b/Outputs/CRT/CRTTypes.hpp index 262f01616..842c2f9f3 100644 --- a/Outputs/CRT/CRTTypes.hpp +++ b/Outputs/CRT/CRTTypes.hpp @@ -23,7 +23,7 @@ struct Rect { Rect() {} Rect(float x, float y, float width, float height) : - origin({.x = x, .y = y}), size({.width = width, .height =height}) {} + origin({.x = x, .y = y}), size({.width = width, .height = height}) {} }; enum DisplayType {