Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/interruptrequester.cpp
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
#include "interruptrequester.h"
20
#include "savestate.h"
21
22
namespace gambatte {
23
24
InterruptRequester::InterruptRequester() : minIntTime(0), ifreg_(0), iereg_(0) {}
25
26
void InterruptRequester::loadState(const SaveState &state) {
27
minIntTime = state.mem.minIntTime;
28
ifreg_ = state.mem.ioamhram.get()[0x10F];
29
iereg_ = state.mem.ioamhram.get()[0x1FF] & 0x1F;
30
intFlags.set(state.mem.IME, state.mem.halted);
31
32
eventTimes.setValue<INTERRUPTS>(intFlags.imeOrHalted() && pendingIrqs() ? minIntTime : static_cast<unsigned long>(DISABLED_TIME));
33
}
34
35
void InterruptRequester::resetCc(const unsigned long oldCc, const unsigned long newCc) {
36
minIntTime = minIntTime < oldCc ? 0 : minIntTime - (oldCc - newCc);
37
38
if (eventTimes.value(INTERRUPTS) != DISABLED_TIME)
39
eventTimes.setValue<INTERRUPTS>(minIntTime);
40
}
41
42
void InterruptRequester::ei(const unsigned long cc) {
43
intFlags.setIme();
44
minIntTime = cc + 1;
45
46
if (pendingIrqs())
47
eventTimes.setValue<INTERRUPTS>(minIntTime);
48
}
49
50
void InterruptRequester::di() {
51
intFlags.unsetIme();
52
53
if (!intFlags.imeOrHalted())
54
eventTimes.setValue<INTERRUPTS>(DISABLED_TIME);
55
}
56
57
void InterruptRequester::halt() {
58
intFlags.setHalted();
59
60
if (pendingIrqs())
61
eventTimes.setValue<INTERRUPTS>(minIntTime);
62
}
63
64
void InterruptRequester::unhalt() {
65
intFlags.unsetHalted();
66
67
if (!intFlags.imeOrHalted())
68
eventTimes.setValue<INTERRUPTS>(DISABLED_TIME);
69
}
70
71
void InterruptRequester::flagIrq(const unsigned bit) {
72
ifreg_ |= bit;
73
74
if (intFlags.imeOrHalted() && pendingIrqs())
75
eventTimes.setValue<INTERRUPTS>(minIntTime);
76
}
77
78
void InterruptRequester::ackIrq(const unsigned bit) {
79
ifreg_ ^= bit;
80
di();
81
}
82
83
void InterruptRequester::setIereg(const unsigned iereg) {
84
iereg_ = iereg & 0x1F;
85
86
if (intFlags.imeOrHalted())
87
eventTimes.setValue<INTERRUPTS>(pendingIrqs() ? minIntTime : static_cast<unsigned long>(DISABLED_TIME));
88
}
89
90
void InterruptRequester::setIfreg(const unsigned ifreg) {
91
ifreg_ = ifreg;
92
93
if (intFlags.imeOrHalted())
94
eventTimes.setValue<INTERRUPTS>(pendingIrqs() ? minIntTime : static_cast<unsigned long>(DISABLED_TIME));
95
}
96
97
SYNCFUNC(InterruptRequester)
98
{
99
SSS(eventTimes);
100
NSS(minIntTime);
101
NSS(ifreg_);
102
NSS(iereg_);
103
NSS(intFlags.flags_);
104
}
105
106
}
107
108