1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-06 01:28:57 +00:00

Got a bit more explicit with range returned by get_cycles_until_horizontal_blank and hence attempted a more thorough (/correct) version of WSYNC.

This commit is contained in:
Thomas Harte 2017-02-07 22:14:45 -05:00
parent 944d835eea
commit a477499724
3 changed files with 11 additions and 6 deletions

View File

@ -54,14 +54,15 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin
// leap to the end of ready only once ready is signalled — because on a 6502 ready doesn't take
// effect until the next read; therefore it isn't safe to assume that signalling ready immediately
// skips to the end of the line.
if(operation == CPU6502::BusOperation::Ready) {
if(operation == CPU6502::BusOperation::Ready)
cycles_run_for = (unsigned int)tia_->get_cycles_until_horizontal_blank(cycles_since_video_update_);
set_ready_line(false);
}
cycles_since_speaker_update_ += cycles_run_for;
cycles_since_video_update_ += cycles_run_for;
if(!tia_->get_cycles_until_horizontal_blank(cycles_since_video_update_))
set_ready_line(false);
if(operation != CPU6502::BusOperation::Ready) {
// check for a paging access
@ -134,8 +135,8 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin
case 0x01: update_video(); tia_->set_blank(!!(*value & 0x02)); break;
case 0x02:
set_ready_line(true);
// TODO: if(horizontal_timer_)
if(tia_->get_cycles_until_horizontal_blank(cycles_since_video_update_))
set_ready_line(true);
break;
case 0x03: update_video(); tia_->reset_horizontal_counter(); break;
// TODO: audio will now be out of synchronisation — fix

View File

@ -212,7 +212,7 @@ void TIA::reset_horizontal_counter()
int TIA::get_cycles_until_horizontal_blank(unsigned int from_offset)
{
return 4 + (cycles_per_line - (horizontal_counter_ + (int)from_offset) % cycles_per_line);
return (cycles_per_line - (horizontal_counter_ + (int)from_offset) % cycles_per_line) % cycles_per_line;
}
void TIA::set_background_colour(uint8_t colour)

View File

@ -34,6 +34,10 @@ class TIA {
void set_blank(bool blank);
void reset_horizontal_counter(); // Reset is delayed by four cycles.
/*!
@returns the number of cycles between (current TIA time) + from_offset to the current or
next horizontal blanking period. Returns numbers in the range [0, 227].
*/
int get_cycles_until_horizontal_blank(unsigned int from_offset);
void set_background_colour(uint8_t colour);