From 80a3169674994e17a8d1843934c781c719dab4de Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 24 Apr 2016 06:56:08 -0400 Subject: [PATCH] Started reviving the Atari 2600 emulation. Put new startup sequence into place. --- Machines/Atari2600/Atari2600.cpp | 25 +++++++++++-------- Machines/Atari2600/Atari2600.hpp | 1 + .../Mac/Clock Signal/Wrappers/CSAtari2600.mm | 18 +++++++++++-- .../Mac/Clock Signal/Wrappers/CSElectron.mm | 1 - Outputs/CRT/CRT.hpp | 6 ++--- Outputs/CRT/Internals/CRTOpenGL.cpp | 3 ++- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index 8b92ad490..9a9463b6f 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -24,20 +24,25 @@ Machine::Machine() : _piaDataValue{0xff, 0xff}, _tiaInputValue{0xff, 0xff} { - _crt = new Outputs::CRT::CRT(228, 1, Outputs::CRT::DisplayType::NTSC60, 2); - _crt->set_composite_sampling_function( - "float composite_sample(vec2 coordinate, float phase)\n" - "{\n" - "vec2 c = texture(texID, coordinate).rg;" - "float y = 0.1 + c.x * 0.91071428571429;\n" - "float aOffset = 6.283185308 * (c.y - 3.0 / 16.0) * 1.14285714285714;\n" - "return y + step(0.03125, c.y) * 0.1 * cos((coordinate.x * 2.0 * 3.141592654) - aOffset);\n" - "}"); - _crt->set_output_device(Outputs::CRT::Television); memset(_collisions, 0xff, sizeof(_collisions)); set_reset_line(true); } +void Machine::setup_output(float aspect_ratio) +{ + _crt = new Outputs::CRT::CRT(228, 1, Outputs::CRT::DisplayType::NTSC60, 2); + _crt->set_composite_sampling_function( + "float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)\n" + "{\n" + "return 0.9;" +// "vec2 c = vec2(1.0);"//vec2(texture(texID, coordinate).rg) / vec2(255.0);" +// "float y = 0.1 + c.x * 0.91071428571429;\n" +// "float aOffset = 6.283185308 * (c.y - 3.0 / 16.0) * 1.14285714285714;\n" +// "return y + step(0.03125, c.y) * 0.1 * cos((coordinate.x * 2.0 * 3.141592654) - aOffset);\n" + "}"); + _crt->set_output_device(Outputs::CRT::Television); +} + Machine::~Machine() { delete[] _rom; diff --git a/Machines/Atari2600/Atari2600.hpp b/Machines/Atari2600/Atari2600.hpp index c3b5d6209..e0b2653b1 100644 --- a/Machines/Atari2600/Atari2600.hpp +++ b/Machines/Atari2600/Atari2600.hpp @@ -30,6 +30,7 @@ class Machine: public CPU6502::Processor { void set_digital_input(Atari2600DigitalInput input, bool state); Outputs::CRT::CRT *get_crt() { return _crt; } + void setup_output(float aspect_ratio); private: uint8_t *_rom, *_romPages[4], _ram[128]; diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm index 2fc2ca00a..74cc46b7f 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm @@ -43,8 +43,10 @@ [super crt:crt didEndFrame:frame didDetectVSync:didDetectVSync]; }*/ -- (void)doRunForNumberOfCycles:(int)numberOfCycles { - _atari2600.run_for_cycles(numberOfCycles); +- (void)runForNumberOfCycles:(int)numberOfCycles { + @synchronized(self) { + _atari2600.run_for_cycles(numberOfCycles); + } } - (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty { @@ -52,15 +54,27 @@ } - (void)setROM:(NSData *)rom { + @synchronized(self) { _atari2600.set_rom(rom.length, (const uint8_t *)rom.bytes); + } } - (void)setState:(BOOL)state forDigitalInput:(Atari2600DigitalInput)digitalInput { + @synchronized(self) { _atari2600.set_digital_input(digitalInput, state ? true : false); + } } - (void)setResetLineEnabled:(BOOL)enabled { + @synchronized(self) { _atari2600.set_reset_line(enabled ? true : false); + } +} + +- (void)setupOutputWithAspectRatio:(float)aspectRatio { + @synchronized(self) { + _atari2600.setup_output(aspectRatio); + } } @end diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm index 52607f738..fe03ee17a 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm @@ -60,7 +60,6 @@ - (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(int)sampleRate { @synchronized(self) { _electron.get_speaker()->set_output_rate(sampleRate, 256); -// _electron.get_speaker()->set_output_quality(47); _electron.get_speaker()->set_delegate(delegate); return YES; } diff --git a/Outputs/CRT/CRT.hpp b/Outputs/CRT/CRT.hpp index 25c2482c9..ed4ca7fbd 100644 --- a/Outputs/CRT/CRT.hpp +++ b/Outputs/CRT/CRT.hpp @@ -202,9 +202,9 @@ class CRT { /*! Sets a function that will map from whatever data the machine provided to a composite signal. @param shader A GLSL fragment including a function with the signature - `float composite_sample(vec2 coordinate, float phase)` that evaluates to the composite signal - level as a function of a source buffer sampling location and the provided colour carrier phase. - The shader may assume a uniform array of sampler2Ds named `buffers` provides access to all input data. + `float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)` + that evaluates to the composite signal level as a function of a source buffer, sampling location, colour + carrier phase and amplitude. */ inline void set_composite_sampling_function(const char *shader) { diff --git a/Outputs/CRT/Internals/CRTOpenGL.cpp b/Outputs/CRT/Internals/CRTOpenGL.cpp index f69ec2d08..a9afeb42e 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.cpp +++ b/Outputs/CRT/Internals/CRTOpenGL.cpp @@ -861,7 +861,8 @@ std::unique_ptr OpenGLOutputBuilder::prepare_output_shader(char void OpenGLOutputBuilder::prepare_rgb_output_shader() { - rgb_shader_program = prepare_output_shader(get_rgb_output_vertex_shader(), get_rgb_output_fragment_shader(), source_data_texture_unit); + if(_rgb_shader) + rgb_shader_program = prepare_output_shader(get_rgb_output_vertex_shader(), get_rgb_output_fragment_shader(), source_data_texture_unit); } void OpenGLOutputBuilder::prepare_composite_output_shader()