Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/interruptrequester.h
2 views
1
/***************************************************************************
2
* Copyright (C) 2010 by Sindre Aamås *
3
* [email protected] *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License version 2 as *
7
* published by the Free Software Foundation. *
8
* *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License version 2 for more details. *
13
* *
14
* You should have received a copy of the GNU General Public License *
15
* version 2 along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
19
#ifndef INTERRUPT_REQUESTER_H
20
#define INTERRUPT_REQUESTER_H
21
22
#include "counterdef.h"
23
#include "minkeeper.h"
24
#include "newstate.h"
25
26
namespace gambatte {
27
struct SaveState;
28
enum MemEventId { UNHALT, END, BLIT, SERIAL, OAM, DMA, TIMA, VIDEO, INTERRUPTS };
29
30
class InterruptRequester {
31
MinKeeper<INTERRUPTS + 1> eventTimes;
32
unsigned long minIntTime;
33
unsigned ifreg_;
34
unsigned iereg_;
35
36
class IntFlags {
37
friend class InterruptRequester;
38
unsigned char flags_;
39
enum { IME_MASK = 1, HALTED_MASK = 2 };
40
41
public:
42
IntFlags() : flags_(0) {}
43
44
bool ime() const { return flags_ & IME_MASK; }
45
bool halted() const { return flags_ & HALTED_MASK; }
46
bool imeOrHalted() const { return flags_; }
47
48
void setIme() { flags_ |= IME_MASK; }
49
void unsetIme() { flags_ &= ~IME_MASK; }
50
51
void setHalted() { flags_ |= HALTED_MASK; }
52
void unsetHalted() { flags_ &= ~HALTED_MASK; }
53
54
void set(const bool ime, const bool halted) { flags_ = halted * HALTED_MASK + ime * IME_MASK; }
55
} intFlags;
56
57
public:
58
InterruptRequester();
59
60
void loadState(const SaveState &);
61
62
void resetCc(unsigned long oldCc, unsigned long newCc);
63
64
unsigned ifreg() const { return ifreg_; }
65
unsigned pendingIrqs() const { return ifreg_ & iereg_; }
66
bool ime() const { return intFlags.ime(); }
67
bool halted() const { return intFlags.halted(); }
68
69
void ei(unsigned long cc);
70
void di();
71
void halt();
72
void unhalt();
73
void flagIrq(unsigned bit);
74
void ackIrq(unsigned bit);
75
void setIereg(unsigned iereg);
76
void setIfreg(unsigned ifreg);
77
78
MemEventId minEventId() const { return static_cast<MemEventId>(eventTimes.min()); }
79
unsigned long minEventTime() const { return eventTimes.minValue(); }
80
template<MemEventId id> void setEventTime(unsigned long value) { eventTimes.setValue<id>(value); }
81
void setEventTime(const MemEventId id, unsigned long value) { eventTimes.setValue(id, value); }
82
unsigned long eventTime(MemEventId id) const { return eventTimes.value(id); }
83
84
template<bool isReader>void SyncState(NewState *ns);
85
};
86
87
inline void flagHdmaReq(InterruptRequester *const intreq) { intreq->setEventTime<DMA>(0); }
88
inline void flagGdmaReq(InterruptRequester *const intreq) { intreq->setEventTime<DMA>(1); }
89
inline void ackDmaReq(InterruptRequester *const intreq) { intreq->setEventTime<DMA>(DISABLED_TIME); }
90
inline bool hdmaReqFlagged(const InterruptRequester &intreq) { return intreq.eventTime(DMA) == 0; }
91
inline bool gdmaReqFlagged(const InterruptRequester &intreq) { return intreq.eventTime(DMA) == 1; }
92
93
}
94
95
#endif
96
97