libsidplayfp  2.0.2
interrupt.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2018 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright 2000 Simon White
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INTERRUPT_H
24 #define INTERRUPT_H
25 
26 #include "Event.h"
27 #include "EventScheduler.h"
28 
29 #include <stdint.h>
30 
31 #include "sidcxx11.h"
32 
33 namespace libsidplayfp
34 {
35 
36 class MOS6526;
37 
41 class InterruptSource : protected Event
42 {
43 public:
44  enum
45  {
49  INTERRUPT_ALARM = 1 << 2,
50  INTERRUPT_SP = 1 << 3,
51  INTERRUPT_FLAG = 1 << 4,
52  INTERRUPT_REQUEST = 1 << 7
53  };
54 
55 protected:
58 
61 
62 private:
64  uint8_t icr;
65 
67  uint8_t idr;
68 
69 protected:
70  bool interruptMasked() const { return icr & idr; }
71 
72  bool interruptTriggered() const { return idr & INTERRUPT_REQUEST; }
73 
74  void triggerInterrupt() { idr |= INTERRUPT_REQUEST; }
75 
76  void triggerBug() { idr &= ~INTERRUPT_UNDERFLOW_B; }
77 
78 protected:
86  Event("CIA Interrupt"),
87  parent(parent),
88  eventScheduler(scheduler),
89  icr(0),
90  idr(0)
91  {}
92 
93 public:
94  virtual ~InterruptSource() {}
95 
101  virtual void trigger(uint8_t interruptMask) { idr |= interruptMask; }
102 
108  virtual uint8_t clear()
109  {
110  uint8_t const old = idr;
111  idr = 0;
112  return old;
113  }
114 
119  virtual void reset()
120  {
121  icr = 0;
122  idr = 0;
123  eventScheduler.cancel(*this);
124  }
125 
131  void set(uint8_t interruptMask)
132  {
133  if (interruptMask & 0x80)
134  {
135  icr |= interruptMask & ~INTERRUPT_REQUEST;
137  }
138  else
139  {
140  icr &= ~interruptMask;
141  }
142  }
143 };
144 
145 }
146 
147 #endif // INTERRUPT_H
libsidplayfp::EventScheduler::cancel
void cancel(Event &event)
Definition: EventScheduler.cpp:35
libsidplayfp::MOS6526
Definition: mos6526.h:182
libsidplayfp::InterruptSource::INTERRUPT_SP
@ INTERRUPT_SP
serial port
Definition: interrupt.h:50
libsidplayfp::EventScheduler
Definition: EventScheduler.h:62
libsidplayfp::InterruptSource::set
void set(uint8_t interruptMask)
Definition: interrupt.h:131
libsidplayfp::InterruptSource::INTERRUPT_REQUEST
@ INTERRUPT_REQUEST
control bit
Definition: interrupt.h:52
libsidplayfp::InterruptSource::INTERRUPT_UNDERFLOW_B
@ INTERRUPT_UNDERFLOW_B
underflow Timer B
Definition: interrupt.h:48
libsidplayfp::InterruptSource::INTERRUPT_NONE
@ INTERRUPT_NONE
no interrupt
Definition: interrupt.h:46
libsidplayfp::InterruptSource::parent
MOS6526 & parent
Pointer to the MOS6526 which this Interrupt belongs to.
Definition: interrupt.h:57
libsidplayfp::InterruptSource
Definition: interrupt.h:42
libsidplayfp::InterruptSource::INTERRUPT_UNDERFLOW_A
@ INTERRUPT_UNDERFLOW_A
underflow Timer A
Definition: interrupt.h:47
libsidplayfp::InterruptSource::reset
virtual void reset()
Definition: interrupt.h:119
libsidplayfp::InterruptSource::InterruptSource
InterruptSource(EventScheduler &scheduler, MOS6526 &parent)
Definition: interrupt.h:85
libsidplayfp::InterruptSource::INTERRUPT_FLAG
@ INTERRUPT_FLAG
external flag
Definition: interrupt.h:51
libsidplayfp::InterruptSource::clear
virtual uint8_t clear()
Definition: interrupt.h:108
libsidplayfp::InterruptSource::trigger
virtual void trigger(uint8_t interruptMask)
Definition: interrupt.h:101
libsidplayfp::InterruptSource::eventScheduler
EventScheduler & eventScheduler
Event scheduler.
Definition: interrupt.h:60
libsidplayfp::InterruptSource::INTERRUPT_ALARM
@ INTERRUPT_ALARM
alarm clock
Definition: interrupt.h:49
libsidplayfp::Event
Definition: Event.h:39