mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-27 01:31:42 +00:00
Made the base 6522 class more abstract: you must now opt-in if you want the IRQ line to be sent to a delegate.
This commit is contained in:
parent
d6cb4fe15c
commit
595791cee0
@ -14,11 +14,6 @@
|
||||
|
||||
namespace MOS {
|
||||
|
||||
class MOS6522Delegate {
|
||||
public:
|
||||
virtual void mos6522_did_change_interrupt_status(void *mos6522) = 0;
|
||||
};
|
||||
|
||||
template <class T> class MOS6522 {
|
||||
private:
|
||||
enum InterruptFlag: uint8_t {
|
||||
@ -181,11 +176,6 @@ template <class T> 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 T> 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 T> 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<T *>(this)->set_interrupt_status(new_interrupt_status);
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,6 +217,27 @@ template <class T> 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 */
|
||||
|
@ -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<UserPortVIA> {
|
||||
class UserPortVIA: public MOS::MOS6522<UserPortVIA>, public MOS::MOS6522IRQDelegate {
|
||||
};
|
||||
|
||||
class KeyboardVIA: public MOS::MOS6522<KeyboardVIA> {
|
||||
class KeyboardVIA: public MOS::MOS6522<KeyboardVIA>, public MOS::MOS6522IRQDelegate {
|
||||
public:
|
||||
void set_key_state(Key key, bool isPressed) {
|
||||
if(isPressed)
|
||||
@ -88,7 +88,7 @@ class KeyboardVIA: public MOS::MOS6522<KeyboardVIA> {
|
||||
uint8_t _activation_mask;
|
||||
};
|
||||
|
||||
class Machine: public CPU6502::Processor<Machine>, public CRTMachine::Machine, public MOS::MOS6522Delegate {
|
||||
class Machine: public CPU6502::Processor<Machine>, public CRTMachine::Machine, public MOS::MOS6522IRQDelegate::Delegate {
|
||||
public:
|
||||
Machine();
|
||||
~Machine();
|
||||
|
Loading…
Reference in New Issue
Block a user