From 595791cee0e2db4a99dd684d30392653af8496d7 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 18 Jun 2016 08:51:18 -0400 Subject: [PATCH] Made the base 6522 class more abstract: you must now opt-in if you want the IRQ line to be sent to a delegate. --- Components/6522/6522.hpp | 34 ++++++++++++++++++++++------------ Machines/Vic-20/Vic20.hpp | 6 +++--- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Components/6522/6522.hpp b/Components/6522/6522.hpp index 15458d465..816f7ce8d 100644 --- a/Components/6522/6522.hpp +++ b/Components/6522/6522.hpp @@ -14,11 +14,6 @@ namespace MOS { -class MOS6522Delegate { - public: - virtual void mos6522_did_change_interrupt_status(void *mos6522) = 0; -}; - template class MOS6522 { private: enum InterruptFlag: uint8_t { @@ -181,11 +176,6 @@ template class MOS6522 { return !!interrupt_status; } - void set_delegate(MOS6522Delegate *delegate) - { - _delegate = delegate; - } - MOS6522() : _timer_is_running{false, false}, _last_posted_interrupt_status(false) @@ -197,7 +187,6 @@ template class MOS6522 { void set_port_output(int port, uint8_t value) {} // Delegate and communications - MOS6522Delegate *_delegate; bool _last_posted_interrupt_status; inline void reevaluate_interrupts() { @@ -205,7 +194,7 @@ template class MOS6522 { if(new_interrupt_status != _last_posted_interrupt_status) { _last_posted_interrupt_status = new_interrupt_status; - if(_delegate) _delegate->mos6522_did_change_interrupt_status(this); + static_cast(this)->set_interrupt_status(new_interrupt_status); } } @@ -228,6 +217,27 @@ template class MOS6522 { bool _timer_is_running[2]; }; +class MOS6522IRQDelegate { + public: + class Delegate { + public: + virtual void mos6522_did_change_interrupt_status(void *mos6522) = 0; + }; + + void set_delegate(Delegate *delegate) + { + _delegate = delegate; + } + + void set_interrupt_status(bool new_status) + { + if(_delegate) _delegate->mos6522_did_change_interrupt_status(this); + } + + private: + Delegate *_delegate; +}; + } #endif /* _522_hpp */ diff --git a/Machines/Vic-20/Vic20.hpp b/Machines/Vic-20/Vic20.hpp index 0910b8f40..ea4d26e3b 100644 --- a/Machines/Vic-20/Vic20.hpp +++ b/Machines/Vic-20/Vic20.hpp @@ -44,10 +44,10 @@ enum Key: uint16_t { Key9 = key(0, 0x10), KeyPlus = key(0, 0x20), KeyGBP = key(0, 0x40), KeyDelete = key(0, 0x80), }; -class UserPortVIA: public MOS::MOS6522 { +class UserPortVIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { }; -class KeyboardVIA: public MOS::MOS6522 { +class KeyboardVIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { public: void set_key_state(Key key, bool isPressed) { if(isPressed) @@ -88,7 +88,7 @@ class KeyboardVIA: public MOS::MOS6522 { uint8_t _activation_mask; }; -class Machine: public CPU6502::Processor, public CRTMachine::Machine, public MOS::MOS6522Delegate { +class Machine: public CPU6502::Processor, public CRTMachine::Machine, public MOS::MOS6522IRQDelegate::Delegate { public: Machine(); ~Machine();