2017-03-19 01:01:58 +00:00
|
|
|
//
|
|
|
|
// Bus.h
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/03/2017.
|
|
|
|
// Copyright © 2017 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Atari2600_Bus_hpp
|
|
|
|
#define Atari2600_Bus_hpp
|
|
|
|
|
2017-04-04 01:16:39 +00:00
|
|
|
#include "Atari2600.hpp"
|
2017-03-19 01:01:58 +00:00
|
|
|
#include "PIA.hpp"
|
|
|
|
#include "Speaker.hpp"
|
2017-04-04 01:16:39 +00:00
|
|
|
#include "TIA.hpp"
|
2017-07-26 00:20:55 +00:00
|
|
|
|
|
|
|
#include "../../ClockReceiver/ClockReceiver.hpp"
|
2017-03-19 01:01:58 +00:00
|
|
|
|
|
|
|
namespace Atari2600 {
|
|
|
|
|
|
|
|
class Bus {
|
|
|
|
public:
|
|
|
|
Bus() :
|
|
|
|
tia_input_value_{0xff, 0xff},
|
2017-07-25 02:53:13 +00:00
|
|
|
cycles_since_speaker_update_(0) {}
|
2017-03-19 01:01:58 +00:00
|
|
|
|
2017-07-23 02:17:29 +00:00
|
|
|
virtual void run_for(const Cycles &cycles) = 0;
|
2017-03-19 01:01:58 +00:00
|
|
|
virtual void set_reset_line(bool state) = 0;
|
|
|
|
|
|
|
|
// the RIOT, TIA and speaker
|
|
|
|
PIA mos6532_;
|
|
|
|
std::shared_ptr<TIA> tia_;
|
|
|
|
std::shared_ptr<Speaker> speaker_;
|
|
|
|
|
|
|
|
// joystick state
|
|
|
|
uint8_t tia_input_value_[2];
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// speaker backlog accumlation counter
|
2017-07-25 11:15:31 +00:00
|
|
|
Cycles cycles_since_speaker_update_;
|
2017-03-19 01:01:58 +00:00
|
|
|
inline void update_audio() {
|
2017-07-25 11:15:31 +00:00
|
|
|
speaker_->run_for(cycles_since_speaker_update_.divide(Cycles(CPUTicksPerAudioTick * 3)));
|
2017-03-19 01:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// video backlog accumulation counter
|
2017-07-25 02:53:13 +00:00
|
|
|
Cycles cycles_since_video_update_;
|
2017-03-19 01:01:58 +00:00
|
|
|
inline void update_video() {
|
2017-07-26 00:42:51 +00:00
|
|
|
tia_->run_for(cycles_since_video_update_.flush());
|
2017-03-19 01:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RIOT backlog accumulation counter
|
2017-07-25 02:53:13 +00:00
|
|
|
Cycles cycles_since_6532_update_;
|
2017-03-19 01:01:58 +00:00
|
|
|
inline void update_6532() {
|
2017-07-26 00:42:51 +00:00
|
|
|
mos6532_.run_for(cycles_since_6532_update_.flush());
|
2017-03-19 01:01:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Atari2600_Bus_hpp */
|