diff --git a/Components/6526/Implementation/6526Implementation.hpp b/Components/6526/Implementation/6526Implementation.hpp index 3668fd367..b4d1ca655 100644 --- a/Components/6526/Implementation/6526Implementation.hpp +++ b/Components/6526/Implementation/6526Implementation.hpp @@ -253,42 +253,6 @@ void MOS6526::run_for(const HalfCycles half_cycles) { } } -/*template -void MOS6526::advance_counters(int sub) { - // Is counter A running and linked to the clock input? - int counter_a_underflows = 0; - if(counter_[0].control & 0x20) { - printf("Unimplemented: Timer A CNT \n"); - } else { - counter_a_underflows = counter_[0].subtract(sub); - } - - // Counter A might be clocking the shift register. - if(counter_a_underflows && counter_[0].control & 0x40) { - printf("Unimplemented shift register clocking\n"); - } - - // Update counter B. - int counter_b_underflows = 0; - switch(counter_[1].control & 0x61) { - case 0x01: - counter_b_underflows = counter_[1].subtract(sub); - break; - case 0x41: - counter_b_underflows = counter_[1].subtract(counter_a_underflows); - break; - default: - if(counter_[1].control & 1) { - printf("Unimplemented 6526 CNT input\n"); - assert(false); - } - break; - } - - // Apply interrupts. - posit_interrupt((counter_a_underflows ? 0x01 : 0x00) | (counter_b_underflows ? 0x02 : 0x00)); -}*/ - template void MOS6526::advance_tod(int count) { if(!count) return; diff --git a/Components/6526/Implementation/6526Storage.hpp b/Components/6526/Implementation/6526Storage.hpp index e954db88e..77d74513d 100644 --- a/Components/6526/Implementation/6526Storage.hpp +++ b/Components/6526/Implementation/6526Storage.hpp @@ -52,7 +52,7 @@ struct MOS6526Storage { pending <<= 1; if(control & 0x10) { - pending |= ReloadInTwo; + pending |= ReloadInOne; control &= ~0x10; } @@ -60,16 +60,14 @@ struct MOS6526Storage { pending |= ApplyClockInTwo; } if(control & 0x08) { - pending |= OneShotInOne; + pending |= OneShotInTwo; } if((pending & ReloadNow) || (hit_zero && (pending & ApplyClockInTwo))) { value = reload; - pending &= ~ApplyClockInOne; + pending &= ~ApplyClockInOne; // Skip one decrement. } - pending &= PendingClearMask; - if(pending & ApplyClockNow) { --value; hit_zero = !value; @@ -80,6 +78,9 @@ struct MOS6526Storage { if(hit_zero && pending&(OneShotInOne | OneShotNow)) { control &= ~1; } + + // Clear any bits that would flow into the wrong field. + pending &= PendingClearMask; } private: @@ -90,13 +91,14 @@ struct MOS6526Storage { static constexpr int ReloadInOne = 1 << 2; static constexpr int ReloadNow = 1 << 3; - static constexpr int OneShotInOne = 1 << 4; - static constexpr int OneShotNow = 1 << 5; + static constexpr int OneShotInTwo = 1 << 4; + static constexpr int OneShotInOne = 1 << 5; + static constexpr int OneShotNow = 1 << 6; - static constexpr int ApplyClockInThree = 1 << 6; - static constexpr int ApplyClockInTwo = 1 << 7; - static constexpr int ApplyClockInOne = 1 << 8; - static constexpr int ApplyClockNow = 1 << 9; + static constexpr int ApplyClockInThree = 1 << 7; + static constexpr int ApplyClockInTwo = 1 << 8; + static constexpr int ApplyClockInOne = 1 << 9; + static constexpr int ApplyClockNow = 1 << 10; static constexpr int PendingClearMask = ~(ReloadNow | OneShotNow | ApplyClockNow);