2017-03-19 01:01:58 +00:00
|
|
|
//
|
|
|
|
// Bus.h
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/03/2017.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-03-19 01:01:58 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#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"
|
2017-04-04 01:16:39 +00:00
|
|
|
#include "TIA.hpp"
|
2017-12-18 02:26:06 +00:00
|
|
|
#include "TIASound.hpp"
|
2017-07-26 00:20:55 +00:00
|
|
|
|
2019-11-09 20:31:41 +00:00
|
|
|
#include "../../../Analyser/Dynamic/ConfidenceCounter.hpp"
|
|
|
|
#include "../../../ClockReceiver/ClockReceiver.hpp"
|
|
|
|
#include "../../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp"
|
2017-03-19 01:01:58 +00:00
|
|
|
|
|
|
|
namespace Atari2600 {
|
|
|
|
|
|
|
|
class Bus {
|
|
|
|
public:
|
|
|
|
Bus() :
|
2017-12-18 02:26:06 +00:00
|
|
|
tia_sound_(audio_queue_),
|
2018-03-07 19:26:07 +00:00
|
|
|
speaker_(tia_sound_) {}
|
2017-03-19 01:01:58 +00:00
|
|
|
|
2018-03-23 01:59:19 +00:00
|
|
|
virtual ~Bus() {
|
|
|
|
audio_queue_.flush();
|
|
|
|
}
|
|
|
|
|
2017-07-28 02:05:29 +00:00
|
|
|
virtual void run_for(const Cycles cycles) = 0;
|
2018-03-07 19:26:07 +00:00
|
|
|
virtual void apply_confidence(Analyser::Dynamic::ConfidenceCounter &confidence_counter) = 0;
|
2017-03-19 01:01:58 +00:00
|
|
|
virtual void set_reset_line(bool state) = 0;
|
2020-01-23 03:05:51 +00:00
|
|
|
virtual void flush() = 0;
|
2017-03-19 01:01:58 +00:00
|
|
|
|
|
|
|
// the RIOT, TIA and speaker
|
|
|
|
PIA mos6532_;
|
2018-11-30 02:26:05 +00:00
|
|
|
TIA tia_;
|
2017-12-18 02:26:06 +00:00
|
|
|
|
2022-07-16 18:41:04 +00:00
|
|
|
Concurrency::AsyncTaskQueue<false> audio_queue_;
|
2017-12-18 02:26:06 +00:00
|
|
|
TIASound tia_sound_;
|
2021-11-21 20:37:29 +00:00
|
|
|
Outputs::Speaker::PullLowpass<TIASound> speaker_;
|
2017-03-19 01:01:58 +00:00
|
|
|
|
|
|
|
// joystick state
|
2018-03-07 19:26:07 +00:00
|
|
|
uint8_t tia_input_value_[2] = {0xff, 0xff};
|
2017-03-19 01:01:58 +00:00
|
|
|
|
|
|
|
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-12-18 02:26:06 +00:00
|
|
|
speaker_.run_for(audio_queue_, 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() {
|
2019-07-29 01:49:54 +00:00
|
|
|
tia_.run_for(cycles_since_video_update_.flush<Cycles>());
|
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() {
|
2019-07-29 01:49:54 +00:00
|
|
|
mos6532_.run_for(cycles_since_6532_update_.flush<Cycles>());
|
2017-03-19 01:01:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Atari2600_Bus_hpp */
|