1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-05 10:28:58 +00:00

Fixes initial state for 1kHz.

This commit is contained in:
Thomas Harte 2021-06-28 21:08:41 -04:00
parent 919e211bc4
commit 3c59042388
2 changed files with 10 additions and 16 deletions

View File

@ -235,22 +235,17 @@ void TimedInterruptSource::update_channel(int c, bool is_linked, int decrement)
if(channels_[c].sync) {
channels_[c].value = channels_[c].reload;
} else {
// TODO: the while loop below is far from efficient.
channels_[c].value -= decrement;
while(channels_[c].value < 0) {
channels_[c].value += channels_[c].reload + 1;
if(is_linked) {
if(channels_[c].level) {
interrupts_ |= uint8_t(Interrupt::VariableFrequency);
}
programmable_level_ = channels_[c].level;
if(decrement <= channels_[c].value) {
channels_[c].value -= decrement;
} else {
const int num_flips = (decrement - (channels_[c].value + 1)) / (channels_[c].reload + 1);
if(is_linked && num_flips + channels_[c].level >= 2) {
interrupts_ |= uint8_t(Interrupt::VariableFrequency);
}
channels_[c].level ^= true;
channels_[c].level ^= (num_flips & 1);
channels_[c].value = (decrement - (channels_[c].value + 1)) % (channels_[c].reload + 1);
}
}
}
void TimedInterruptSource::run_for(Cycles cycles) {

View File

@ -136,15 +136,14 @@ class TimedInterruptSource {
Cycles one_hz_offset_ = clock_rate;
int programmable_offset_ = std::numeric_limits<int>::max();
bool programmable_level_ = false;
enum class InterruptRate {
OnekHz,
FiftyHz,
ToneGenerator0,
ToneGenerator1,
} rate_ = InterruptRate::OnekHz;
int programmable_offset_ = programmble_reload(InterruptRate::OnekHz);
bool programmable_level_ = false;
struct Channel {
int value = 100, reload = 100;