1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-16 18:30:32 +00:00

Made an attempt to make execution flow through this loop more straightforward for a branch predictor.

This commit is contained in:
Thomas Harte 2016-10-30 15:30:39 -04:00
parent 7843a244b0
commit 1ff9b474bf

View File

@ -54,11 +54,20 @@ void VideoOutput::run_for_cycles(int number_of_cycles)
// Vertical: 039: pixels; otherwise blank; 4853 sync, 5456 colour burst
// Horizontal: 0223: pixels; otherwise blank; 256259 sync
while(number_of_cycles--)
while(number_of_cycles)
{
_counter = (_counter + 1)%_counter_period;
int h_counter =_counter & 63;
int cycles_run_for = 0;
if(_counter >= _v_sync_start_position && _counter <= _v_sync_end_position)
{
// this is a sync line
cycles_run_for = std::min(64 - h_counter, number_of_cycles);
_crt->output_sync((unsigned int)cycles_run_for * 6);
}
else if(_counter < 224*64 && h_counter < 40)
{
// this is a pixel line
if(!h_counter)
{
_ink = 0xff;
@ -66,10 +75,11 @@ void VideoOutput::run_for_cycles(int number_of_cycles)
_use_alternative_character_set = _use_double_height_characters = _blink_text = false;
set_character_set_base_address();
_phase += 64;
_pixel_target = _crt->allocate_write_area(120);
if(!_counter)
{
_phase += 128;
_phase += 128; // TODO: incorporate all the lines that were missed
_frame_counter++;
_v_sync_start_position = _next_frame_is_sixty_hertz ? PAL60VSyncStartPosition : PAL50VSyncStartPosition;
@ -78,30 +88,11 @@ void VideoOutput::run_for_cycles(int number_of_cycles)
}
}
cycles_run_for = std::min(40 - h_counter, number_of_cycles);
int columns = cycles_run_for;
State new_state = Blank;
if(
(h_counter >= 48 && h_counter <= 53) ||
(_counter >= _v_sync_start_position && _counter <= _v_sync_end_position)) new_state = Sync;
else if(h_counter >= 54 && h_counter <= 56) new_state = ColourBurst;
else if(_counter < 224*64 && h_counter < 40) new_state = Pixels;
if(_state != new_state)
while(columns--)
{
switch(_state)
{
case ColourBurst: _crt->output_colour_burst(_cycles_in_state * 6, _phase, 128); break;
case Sync: _crt->output_sync(_cycles_in_state * 6); break;
case Blank: _crt->output_blank(_cycles_in_state * 6); break;
case Pixels: _crt->output_data(_cycles_in_state * 6, 2); break;
}
_state = new_state;
_cycles_in_state = 0;
if(_state == Pixels) _pixel_target = _crt->allocate_write_area(120);
}
_cycles_in_state++;
if(new_state == Pixels) {
uint8_t pixels, control_byte;
if(_is_graphics_mode && _counter < 200*64)
@ -174,6 +165,40 @@ void VideoOutput::run_for_cycles(int number_of_cycles)
if(_pixel_target) _pixel_target[0] = _pixel_target[1] = _pixel_target[2] = (uint8_t)(_paper ^ inverse_mask);
}
if(_pixel_target) _pixel_target += 3;
h_counter++;
}
if(h_counter == 40)
{
_crt->output_data(40 * 6, 2);
}
}
else
{
// this is a blank line (or the equivalent part of a pixel line)
if(h_counter < 48)
{
cycles_run_for = std::min(48 - h_counter, number_of_cycles);
_crt->output_blank((unsigned int)cycles_run_for * 6);
}
else if(h_counter < 54)
{
cycles_run_for = std::min(54 - h_counter, number_of_cycles);
_crt->output_sync((unsigned int)cycles_run_for * 6);
}
else if(h_counter < 56)
{
cycles_run_for = std::min(56 - h_counter, number_of_cycles);
_crt->output_colour_burst((unsigned int)cycles_run_for * 6, _phase, 128);
}
else
{
cycles_run_for = std::min(64 - h_counter, number_of_cycles);
_crt->output_blank((unsigned int)cycles_run_for * 6);
}
}
_counter = (_counter + cycles_run_for)%_counter_period;
number_of_cycles -= cycles_run_for;
}
}