1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00

Corrected TIA's WSYNC lookahead to accept Cycles.

This commit is contained in:
Thomas Harte 2017-07-25 22:13:41 -04:00
parent 1c2f68f129
commit d9c6b3bcf7
4 changed files with 8 additions and 9 deletions

View File

@ -24,7 +24,7 @@ template<class T> class Cartridge:
void run_for(const Cycles &cycles) { CPU::MOS6502::Processor<Cartridge<T>>::run_for(cycles); }
void set_reset_line(bool state) { CPU::MOS6502::Processor<Cartridge<T>>::set_reset_line(state); }
void advance_cycles(unsigned int cycles) {}
void advance_cycles(int cycles) {}
// to satisfy CPU::MOS6502::Processor
unsigned int perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) {
@ -41,7 +41,7 @@ template<class T> class Cartridge:
cycles_since_speaker_update_ += Cycles(cycles_run_for);
cycles_since_video_update_ += Cycles(cycles_run_for);
cycles_since_6532_update_ += Cycles(cycles_run_for / 3);
static_cast<T *>(this)->advance_cycles((unsigned int)cycles_run_for / 3);
static_cast<T *>(this)->advance_cycles(cycles_run_for / 3);
if(operation != CPU::MOS6502::BusOperation::Ready) {
// give the cartridge a chance to respond to the bus access

View File

@ -22,7 +22,7 @@ class CartridgePitfall2: public Cartridge<CartridgePitfall2> {
rom_ptr_ = rom_.data();
}
void advance_cycles(unsigned int cycles) {
void advance_cycles(int cycles) {
cycles_since_audio_update_ += cycles;
}
@ -105,8 +105,7 @@ class CartridgePitfall2: public Cartridge<CartridgePitfall2> {
inline uint8_t update_audio() {
const unsigned int clock_divisor = 57;
unsigned int cycles_to_run_for = cycles_since_audio_update_ / clock_divisor;
cycles_since_audio_update_ %= clock_divisor;
int cycles_to_run_for = cycles_since_audio_update_.divide(clock_divisor).as_int();
int table_position = 0;
for(int c = 0; c < 3; c++) {
@ -126,7 +125,7 @@ class CartridgePitfall2: public Cartridge<CartridgePitfall2> {
uint8_t random_number_generator_;
uint8_t *rom_ptr_;
uint8_t audio_channel_[3];
unsigned int cycles_since_audio_update_;
Cycles cycles_since_audio_update_;
};
}

View File

@ -198,8 +198,8 @@ void TIA::set_blank(bool blank) {
void TIA::reset_horizontal_counter() {
}
int TIA::get_cycles_until_horizontal_blank(unsigned int from_offset) {
return (cycles_per_line - (horizontal_counter_ + (int)from_offset) % cycles_per_line) % cycles_per_line;
int TIA::get_cycles_until_horizontal_blank(const Cycles &from_offset) {
return (cycles_per_line - (horizontal_counter_ + from_offset.as_int()) % cycles_per_line) % cycles_per_line;
}
void TIA::set_background_colour(uint8_t colour) {

View File

@ -43,7 +43,7 @@ class TIA: public ClockReceiver<TIA> {
@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);
int get_cycles_until_horizontal_blank(const Cycles &from_offset);
void set_background_colour(uint8_t colour);