1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

The TIA is now a ClockReceiver.

This commit is contained in:
Thomas Harte 2017-07-24 21:48:34 -04:00
parent 915f587ef1
commit 13f7aa4063
4 changed files with 15 additions and 14 deletions

View File

@ -48,7 +48,7 @@ class Bus {
// video backlog accumulation counter
unsigned int cycles_since_video_update_;
inline void update_video() {
tia_->run_for_cycles((int)cycles_since_video_update_);
tia_->run_for(Cycles((int)cycles_since_video_update_));
cycles_since_video_update_ = 0;
}

View File

@ -165,13 +165,14 @@ void TIA::set_output_mode(Atari2600::TIA::OutputMode output_mode) {
/* speaker_->set_input_rate((float)(get_clock_rate() / 38.0));*/
}
void TIA::run_for_cycles(int number_of_cycles)
{
void TIA::run_for(const Cycles &cycles) {
int number_of_cycles = cycles.as_int();
// if part way through a line, definitely perform a partial, at most up to the end of the line
if(horizontal_counter_) {
int cycles = std::min(number_of_cycles, cycles_per_line - horizontal_counter_);
output_for_cycles(cycles);
number_of_cycles -= cycles;
int output_cycles = std::min(number_of_cycles, cycles_per_line - horizontal_counter_);
output_for_cycles(output_cycles);
number_of_cycles -= output_cycles;
}
// output full lines for as long as possible

View File

@ -11,10 +11,11 @@
#include <cstdint>
#include "../CRTMachine.hpp"
#include "../../Components/ClockReceiver.hpp"
namespace Atari2600 {
class TIA {
class TIA: public ClockReceiver<TIA> {
public:
TIA();
// The supplied hook is for unit testing only; if instantiated with a line_end_function then it will
@ -27,10 +28,9 @@ class TIA {
};
/*!
Advances the TIA by @c number_of_cycles cycles. Any queued setters take effect in the
first cycle performed.
Advances the TIA by @c cycles. Any queued setters take effect in the first cycle performed.
*/
void run_for_cycles(int number_of_cycles);
void run_for(const Cycles &cycles);
void set_output_mode(OutputMode output_mode);
void set_sync(bool sync);

View File

@ -47,7 +47,7 @@ static void receive_line(uint8_t *next_line)
_tia->set_playfield(0, 0x10);
_tia->set_playfield(1, 0xf0);
_tia->set_playfield(2, 0x0e);
_tia->run_for_cycles(228);
_tia->run_for(Cycles(228));
XCTAssert(line != nullptr, @"228 cycles should have ended the line");
@ -70,7 +70,7 @@ static void receive_line(uint8_t *next_line)
_tia->set_playfield(1, 0xf0);
_tia->set_playfield(2, 0x0e);
_tia->run_for_cycles(228);
_tia->run_for(Cycles(228));
XCTAssert(line != nullptr, @"228 cycles should have ended the line");
uint8_t expected_line[] = {
@ -90,7 +90,7 @@ static void receive_line(uint8_t *next_line)
_tia->set_player_graphic(0, 0xff);
_tia->set_player_position(0);
_tia->run_for_cycles(228);
_tia->run_for(Cycles(228));
uint8_t first_expected_line[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -103,7 +103,7 @@ static void receive_line(uint8_t *next_line)
XCTAssert(!memcmp(first_expected_line, line, sizeof(first_expected_line)));
line = nullptr;
_tia->run_for_cycles(228);
_tia->run_for(Cycles(228));
uint8_t second_expected_line[] = {
0, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,