Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/include/ameteor/cpu.hpp
2 views
1
// Meteor - A Nintendo Gameboy Advance emulator
2
// Copyright (C) 2009-2011 Philippe Daouadi
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
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 for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
#ifndef __CPU_H__
18
#define __CPU_H__
19
20
#include <stdint.h>
21
#include <istream>
22
#include <ostream>
23
24
namespace AMeteor
25
{
26
class Cpu
27
{
28
public :
29
union Psr
30
{
31
uint32_t dw;
32
struct
33
{
34
unsigned int mode : 5;
35
unsigned int thumb : 1;
36
unsigned int fiq_d : 1;
37
unsigned int irq_d : 1;
38
unsigned int reserved : 19;
39
unsigned int s_overflow : 1;
40
unsigned int f_overflow : 1;
41
unsigned int f_carry : 1;
42
unsigned int f_zero : 1;
43
unsigned int f_sign : 1;
44
} b;
45
};
46
struct IPsr
47
{
48
uint8_t mode;
49
bool thumb;
50
bool fiq_d;
51
bool irq_d;
52
bool s_overflow;
53
bool f_overflow;
54
bool f_carry;
55
bool f_zero;
56
bool f_sign;
57
};
58
enum Modes
59
{
60
M_USR = 0x10,
61
M_FIQ = 0x11,
62
M_IRQ = 0x12,
63
M_SVC = 0x13,
64
M_ABT = 0x17,
65
M_UND = 0x1B,
66
M_SYS = 0x1F
67
};
68
69
Cpu ();
70
virtual ~Cpu () {}
71
72
virtual void Reset ();
73
virtual void SoftReset ();
74
75
void UpdateICpsr ();
76
void UpdateCpsr ();
77
void SwitchToMode (uint8_t newmode);
78
void SwitchModeBack ();
79
80
virtual void SendInterrupt (uint16_t interrupt) = 0;
81
virtual void CheckInterrupt () = 0;
82
void Interrupt ();
83
void SoftwareInterrupt (uint32_t comment);
84
void SoftwareInterrupt ();
85
86
uint32_t& Reg(uint8_t r)
87
{
88
return m_st.r[r];
89
}
90
91
Psr& Cpsr()
92
{
93
return m_st.cpsr;
94
}
95
IPsr& ICpsr()
96
{
97
return m_st.icpsr;
98
}
99
Psr& Spsr()
100
{
101
return m_st.spsr;
102
}
103
104
bool SaveState (std::ostream& stream);
105
bool LoadState (std::istream& stream);
106
107
protected :
108
struct CPUState
109
{
110
// Current registers
111
uint32_t r[16];
112
Psr cpsr, spsr;
113
IPsr icpsr;
114
115
// System/User
116
uint32_t usr_r[7]; // from 8 to 14
117
118
// FIQ
119
uint32_t fiq_r[7]; // from 8 to 14
120
Psr fiq_spsr;
121
122
// Supervisor
123
uint32_t svc_r[2]; // 13 and 14
124
Psr svc_spsr;
125
126
// Abort
127
uint32_t abt_r[2]; // 13 and 14
128
Psr abt_spsr;
129
130
// IRQ
131
uint32_t irq_r[2]; // 13 and 14
132
Psr irq_spsr;
133
134
// Undefined
135
uint32_t und_r[2]; // 13 and 14
136
Psr und_spsr;
137
};
138
139
CPUState m_st;
140
141
virtual void SetInterrupt (bool interrupt) = 0;
142
143
private :
144
void SaveMode (uint8_t mode);
145
};
146
}
147
148
#endif
149
150