1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-10-01 13:58:20 +00:00

The cathode ray view no longer hard codes the frame size. So that's one less coupling. Doubled pixel output size to give sufficient sampling detail to capture the NTSC colour clock (ummm, hopefully).

This commit is contained in:
Thomas Harte 2015-08-05 21:45:47 -04:00
parent 67e82c713f
commit fd36f13baf
3 changed files with 29 additions and 18 deletions

View File

@ -20,7 +20,7 @@ Machine::Machine()
_horizontalTimer = horizontalTimerReload;
_lastOutputStateDuration = 0;
_lastOutputState = OutputState::Sync;
_crt = new Outputs::CRT(228, 262, 1, 4);
_crt = new Outputs::CRT(456, 262, 1, 4);
_piaTimerStatus = 0xff;
setup6502();
@ -33,7 +33,7 @@ Machine::~Machine()
void Machine::switch_region()
{
_crt->set_new_timing(228, 312);
_crt->set_new_timing(456, 312);
}
void Machine::get_output_pixel(uint8_t *pixel, int offset)
@ -127,10 +127,10 @@ void Machine::get_output_pixel(uint8_t *pixel, int offset)
}
// map that colour to an RGBA
pixel[0] = palette[outputColour >> 4][0];
pixel[1] = palette[outputColour >> 4][1];
pixel[2] = palette[outputColour >> 4][2];
pixel[3] = alphaValues[(outputColour >> 1)&7];
pixel[0] = pixel[4] = palette[outputColour >> 4][0];
pixel[1] = pixel[5] = palette[outputColour >> 4][1];
pixel[2] = pixel[6] = palette[outputColour >> 4][2];
pixel[3] = pixel[7] = alphaValues[(outputColour >> 1)&7];
}
void Machine::output_pixels(int count)
@ -175,22 +175,22 @@ void Machine::output_pixels(int count)
{
switch(_lastOutputState)
{
case OutputState::Blank: _crt->output_blank(_lastOutputStateDuration); break;
case OutputState::Sync: _crt->output_sync(_lastOutputStateDuration); break;
case OutputState::Pixel: _crt->output_data(_lastOutputStateDuration, atari2600DataType); break;
case OutputState::Blank: _crt->output_blank(_lastOutputStateDuration*2); break;
case OutputState::Sync: _crt->output_sync(_lastOutputStateDuration*2); break;
case OutputState::Pixel: _crt->output_data(_lastOutputStateDuration*2, atari2600DataType); break;
}
_lastOutputStateDuration = 0;
_lastOutputState = state;
if(state == OutputState::Pixel)
{
_crt->allocate_write_area(160);
_crt->allocate_write_area(320);
_outputBuffer = _crt->get_write_target_for_buffer(0);
}
}
if(state == OutputState::Pixel && _outputBuffer)
get_output_pixel(&_outputBuffer[_lastOutputStateDuration * 4], 159 - _horizontalTimer);
get_output_pixel(&_outputBuffer[_lastOutputStateDuration * 8], 159 - _horizontalTimer);
// assumption here: signed shifts right; otherwise it's just
// an attempt to avoid both the % operator and a conditional

View File

@ -22,6 +22,10 @@
GLint _textureCoordinatesAttribute;
GLint _lateralAttribute;
GLint _texIDUniform;
GLint _textureSizeUniform;
GLint _alphaUniform;
GLuint _textureName;
CRTSize _textureSize;
@ -161,11 +165,13 @@ const char *vertexShader =
"out vec2 srcCoordinatesVarying;\n"
"out float lateralVarying;\n"
"\n"
"uniform vec2 textureSize;\n"
"\n"
"void main (void)\n"
"{\n"
"srcCoordinatesVarying = vec2(srcCoordinates.x / 512.0, (srcCoordinates.y + 0.5) / 512.0);\n"
"srcCoordinatesVarying = vec2(srcCoordinates.x / textureSize.x, (srcCoordinates.y + 0.5) / textureSize.y);\n"
"lateralVarying = lateral + 1.0707963267949;\n"
"gl_Position = vec4(position.x * 2.0 - 1.0, 1.0 - position.y * 2.0 + position.x / 131.0, 0.0, 1.0);\n"
"gl_Position = vec4(position.x * 2.0 - 1.0, 1.0 - position.y * 2.0 , 0.0, 1.0);\n" // + position.x / 131.0
"}\n";
// TODO: this should be factored out and be per project
@ -175,6 +181,7 @@ const char *fragmentShader =
"in vec2 srcCoordinatesVarying;\n"
"in float lateralVarying;"
"out vec4 fragColour;\n"
"\n"
"uniform sampler2D texID;\n"
"uniform float alpha;\n"
"\n"
@ -231,9 +238,12 @@ const char *fragmentShader =
glUseProgram(_shaderProgram);
_positionAttribute = glGetAttribLocation(_shaderProgram, "position");
_textureCoordinatesAttribute = glGetAttribLocation(_shaderProgram, "srcCoordinates");
_lateralAttribute = glGetAttribLocation(_shaderProgram, "lateral");
_positionAttribute = glGetAttribLocation(_shaderProgram, "position");
_textureCoordinatesAttribute = glGetAttribLocation(_shaderProgram, "srcCoordinates");
_lateralAttribute = glGetAttribLocation(_shaderProgram, "lateral");
_texIDUniform = glGetUniformLocation(_shaderProgram, "texID");
_alphaUniform = glGetUniformLocation(_shaderProgram, "alpha");
_textureSizeUniform = glGetUniformLocation(_shaderProgram, "textureSize");
glEnableVertexAttribArray(_positionAttribute);
glEnableVertexAttribArray(_textureCoordinatesAttribute);
@ -260,6 +270,7 @@ const char *fragmentShader =
if (_crtFrame)
{
glUniform2f(_textureSizeUniform, _crtFrame->size.width, _crtFrame->size.height);
glDrawArrays(GL_TRIANGLES, 0, _crtFrame->number_of_runs*6);
}

View File

@ -57,8 +57,8 @@ CRT::CRT(int cycles_per_line, int height_of_display, int number_of_buffers, ...)
// generate buffers for signal storage as requested — format is
// number of buffers, size of buffer 1, size of buffer 2...
const int bufferWidth = 512;
const int bufferHeight = 512;
const int bufferWidth = 2048;
const int bufferHeight = 2048;
for(int frame = 0; frame < sizeof(_frame_builders) / sizeof(*_frame_builders); frame++)
{
va_list va;