1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-23 20:29:42 +00:00

Switched back to one texel per colour clock, at least for now. Attempted to break _RGBA assumption within the cathode ray view.

This commit is contained in:
Thomas Harte 2015-08-05 23:36:04 -04:00
parent fd36f13baf
commit eb23a493e5
2 changed files with 26 additions and 14 deletions

View File

@ -20,7 +20,7 @@ Machine::Machine()
_horizontalTimer = horizontalTimerReload;
_lastOutputStateDuration = 0;
_lastOutputState = OutputState::Sync;
_crt = new Outputs::CRT(456, 262, 1, 4);
_crt = new Outputs::CRT(228, 262, 1, 4);
_piaTimerStatus = 0xff;
setup6502();
@ -33,7 +33,7 @@ Machine::~Machine()
void Machine::switch_region()
{
_crt->set_new_timing(456, 312);
_crt->set_new_timing(228, 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] = 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];
pixel[0] = palette[outputColour >> 4][0];
pixel[1] = palette[outputColour >> 4][1];
pixel[2] = palette[outputColour >> 4][2];
pixel[3] = 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*2); break;
case OutputState::Sync: _crt->output_sync(_lastOutputStateDuration*2); break;
case OutputState::Pixel: _crt->output_data(_lastOutputStateDuration*2, atari2600DataType); break;
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;
}
_lastOutputStateDuration = 0;
_lastOutputState = state;
if(state == OutputState::Pixel)
{
_crt->allocate_write_area(320);
_crt->allocate_write_area(160);
_outputBuffer = _crt->get_write_target_for_buffer(0);
}
}
if(state == OutputState::Pixel && _outputBuffer)
get_output_pixel(&_outputBuffer[_lastOutputStateDuration * 8], 159 - _horizontalTimer);
get_output_pixel(&_outputBuffer[_lastOutputStateDuration * 4], 159 - _horizontalTimer);
// assumption here: signed shifts right; otherwise it's just
// an attempt to avoid both the % operator and a conditional
@ -205,7 +205,7 @@ int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t add
uint8_t returnValue = 0xff;
output_pixels(3);
if(_horizontalTimer == horizontalTimerReload)
if(_horizontalTimer == horizontalTimerReload-3)
set_ready_line(false);
if(operation != CPU6502::BusOperation::Ready) {

View File

@ -124,6 +124,17 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
self.wantsBestResolutionOpenGLSurface = YES;
}
- (GLint)formatForDepth:(int)depth
{
switch(depth)
{
default: return -1;
case 1: return GL_RED;
case 2: return GL_RG;
case 3: return GL_RGB;
case 4: return GL_RGBA;
}
}
- (BOOL)pushFrame:(CRTFrame * __nonnull)crtFrame
{
@ -140,11 +151,12 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
if(_textureSize.width != _crtFrame->size.width || _textureSize.height != _crtFrame->size.height)
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _crtFrame->size.width, _crtFrame->size.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data);
GLint format = [self formatForDepth:_crtFrame->buffers[0].depth];
glTexImage2D(GL_TEXTURE_2D, 0, format, _crtFrame->size.width, _crtFrame->size.height, 0, format, GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data);
_textureSize = _crtFrame->size;
}
else
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _crtFrame->size.width, _crtFrame->dirty_size.height, GL_RGBA, GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _crtFrame->size.width, _crtFrame->dirty_size.height, [self formatForDepth:_crtFrame->buffers[0].depth], GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data);
}
return hadFrame;