Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/source/globals.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 __GLOBALS_H__
18
#define __GLOBALS_H__
19
20
#include <algorithm>
21
#include <stdint.h>
22
23
#define SPDUP_FRMSKIP 9
24
#define SPDUP_SNDSKIP 3969
25
26
#define R(reg) CPU.Reg(reg)
27
28
#define CPU _cpu
29
#define MEM _memory
30
#define IO _io
31
#define DMA _dma
32
#define LCD _lcd
33
#define SOUND _sound
34
#define KEYPAD _keypad
35
#define CLOCK _clock
36
#define TIMER0 _timer0
37
#define TIMER1 _timer1
38
#define TIMER2 _timer2
39
#define TIMER3 _timer3
40
41
#define CYCLES16NSeq(add, count) \
42
CLOCK.TimePass(MEM.GetCycles16NoSeq(add, count))
43
#define CYCLES16Seq(add, count) \
44
CLOCK.TimePass(MEM.GetCycles16Seq(add, count))
45
#define CYCLES32NSeq(add, count) \
46
CLOCK.TimePass(MEM.GetCycles32NoSeq(add, count))
47
#define CYCLES32Seq(add, count) \
48
CLOCK.TimePass(MEM.GetCycles32Seq(add, count))
49
#define ICYCLES(i) \
50
CLOCK.TimePass(i)
51
// we don't mind if the following code is slow since a MUL
52
// instruction is slow on a GBA too
53
#define MULICYCLES(reg) \
54
{ \
55
uint32_t rs = R(reg) >> 8; \
56
for (uint8_t i = 1; i <= 4; ++i, rs >>= 8) \
57
{ \
58
if (!rs || rs == (0xFFFFFFFF >> (i*8))) \
59
{ \
60
ICYCLES(i); \
61
break; \
62
} \
63
} \
64
}
65
66
#define CPSR (CPU.Cpsr().dw)
67
#define ICPSR (CPU.ICpsr())
68
#define SPSR (CPU.Spsr().dw)
69
#define FLAG_Z (CPU.ICpsr().f_zero)
70
#define FLAG_N (CPU.ICpsr().f_sign)
71
#define FLAG_C (CPU.ICpsr().f_carry)
72
#define FLAG_V (CPU.ICpsr().f_overflow)
73
#define FLAG_T (CPU.ICpsr().thumb)
74
#define SETF(flag, val) \
75
FLAG_##flag = (val) ? 1 : 0
76
#define SETFB(flag, val) \
77
FLAG_##flag = (val)
78
79
#define FZ(val) \
80
SETF(Z, !(val))
81
#define FN(val) \
82
SETF(N, NEG(val))
83
84
#define POS(a) ((~a) >> 31)
85
#define NEG(a) ((a) >> 31)
86
87
// inspired by VisualBoyAdvance
88
#define ADDCARRY(a, b, c) \
89
((NEG(a) & NEG(b)) | \
90
(NEG(a) & POS(c)) | \
91
(NEG(b) & POS(c)))
92
#define ADDOVERFLOW(a, b, c) \
93
((NEG(a) & NEG(b) & POS(c)) | \
94
(POS(a) & POS(b) & NEG(c)))
95
#define SUBCARRY(a, b, c) \
96
((NEG(a) & POS(b)) | \
97
(NEG(a) & POS(c)) | \
98
(POS(b) & POS(c)))
99
#define SUBOVERFLOW(a, b, c) \
100
((NEG(a) & POS(b) & POS(c)) | \
101
(POS(a) & NEG(b) & NEG(c)))
102
103
// Save states macros
104
#define SS_WRITE_VAR(var) \
105
if (!stream.write((char*)&var, sizeof(var))) \
106
return false
107
#define SS_WRITE_ARRAY(var) \
108
if (!stream.write((char*)var, sizeof(var))) \
109
return false
110
#define SS_WRITE_DATA(var, size) \
111
if (!stream.write((char*)var, size)) \
112
return false
113
#define SS_READ_VAR(var) \
114
if (!stream.read((char*)&var, sizeof(var))) \
115
return false
116
#define SS_READ_ARRAY(var) \
117
if (!stream.read((char*)var, sizeof(var))) \
118
return false
119
#define SS_READ_DATA(var, size) \
120
if (!stream.read((char*)var, size)) \
121
return false
122
123
// macro to avoid getting warnings about and unused parameter on GCC
124
#ifdef _MSC_VER
125
#define MET_UNUSED(v)
126
#else
127
#define MET_UNUSED(v) \
128
__attribute__((unused)) MET_UNUSED_##v
129
#endif
130
131
namespace AMeteor
132
{
133
// ROtate Right
134
inline uint32_t ROR(uint32_t val, uint8_t shift)
135
{
136
return (val >> shift) | (val << (32 - shift));
137
}
138
}
139
140
#endif
141
142