-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathdefinitions.h
242 lines (200 loc) · 5.56 KB
/
definitions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
* Gearsystem - Sega Master System / Game Gear Emulator
* Copyright (C) 2013 Ignacio Sanchez
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*
*/
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <sstream>
#ifdef DEBUG
#define DEBUG_GEARSYSTEM 1
#endif
#if defined(PS2) || defined(PSP)
#define PERFORMANCE
#endif
#if !defined(EMULATOR_BUILD)
#define EMULATOR_BUILD "undefined"
#endif
#define GEARSYSTEM_TITLE "Gearsystem"
#define GEARSYSTEM_VERSION EMULATOR_BUILD
#define GEARSYSTEM_TITLE_ASCII "" \
" ____ _ \n" \
" / ___| ___ __ _ _ __ ___ _ _ ___| |_ ___ _ __ ___ \n" \
" | | _ / _ \\/ _` | '__/ __| | | / __| __/ _ \\ '_ ` _ \\ \n" \
" | |_| | __/ (_| | | \\__ \\ |_| \\__ \\ || __/ | | | | | \n" \
" \\____|\\___|\\__,_|_| |___/\\__, |___/\\__\\___|_| |_| |_| \n" \
" |___/ \n"
#ifndef NULL
#define NULL 0
#endif
#ifdef _WIN32
#define BLARGG_USE_NAMESPACE 1
#endif
//#define GEARSYSTEM_DISABLE_DISASSEMBLER
#define MAX_ROM_SIZE 0x800000
#define SafeDelete(pointer) if(pointer != NULL) {delete pointer; pointer = NULL;}
#define SafeDeleteArray(pointer) if(pointer != NULL) {delete [] pointer; pointer = NULL;}
#define InitPointer(pointer) ((pointer) = NULL)
#define IsValidPointer(pointer) ((pointer) != NULL)
#if defined(MSB_FIRST) || defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define IS_BIG_ENDIAN
#else
#define IS_LITTLE_ENDIAN
#endif
typedef uint8_t u8;
typedef int8_t s8;
typedef uint16_t u16;
typedef int16_t s16;
typedef uint32_t u32;
typedef int32_t s32;
typedef uint64_t u64;
typedef int64_t s64;
typedef void (*RamChangedCallback) (void);
#define FLAG_CARRY 0x01
#define FLAG_NEGATIVE 0x02
#define FLAG_PARITY 0x04
#define FLAG_X 0x08
#define FLAG_HALF 0x10
#define FLAG_Y 0x20
#define FLAG_ZERO 0x40
#define FLAG_SIGN 0x80
#define FLAG_NONE 0
#define GS_RESOLUTION_MAX_WIDTH 256
#define GS_RESOLUTION_MAX_HEIGHT 224
#define GS_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN 320
#define GS_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN 288
#define GS_RESOLUTION_SMS_WIDTH 256
#define GS_RESOLUTION_SMS_HEIGHT 192
#define GS_RESOLUTION_SMS_HEIGHT_EXTENDED 224
#define GS_RESOLUTION_SMS_OVERSCAN_H_320_L 32
#define GS_RESOLUTION_SMS_OVERSCAN_H_320_R 32
#define GS_RESOLUTION_SMS_OVERSCAN_H_284_L 14
#define GS_RESOLUTION_SMS_OVERSCAN_H_284_R 14
#define GS_RESOLUTION_SMS_OVERSCAN_V 24
#define GS_RESOLUTION_SMS_OVERSCAN_V_PAL 48
#define GS_RESOLUTION_GG_WIDTH 160
#define GS_RESOLUTION_GG_HEIGHT 144
#define GS_RESOLUTION_GG_X_OFFSET 48
#define GS_RESOLUTION_GG_Y_OFFSET 24
#define GS_RESOLUTION_GG_Y_OFFSET_EXTENDED 40
#define GS_MASTER_CLOCK_NTSC 3579545
#define GS_LINES_PER_FRAME_NTSC 262
#define GS_FRAMES_PER_SECOND_NTSC 60
#define GS_CYCLES_PER_LINE 228
#define GS_MASTER_CLOCK_PAL 3546893
#define GS_LINES_PER_FRAME_PAL 313
#define GS_FRAMES_PER_SECOND_PAL 50
#define GS_AUDIO_SAMPLE_RATE 44100
#define GS_AUDIO_BUFFER_SIZE 4096
#define GS_SAVESTATE_MAGIC 0x03121220
enum GS_Color_Format
{
GS_PIXEL_RGB565,
GS_PIXEL_RGB555,
GS_PIXEL_RGBA8888,
GS_PIXEL_BGR565,
GS_PIXEL_BGR555,
GS_PIXEL_BGRA8888
};
enum GS_Keys
{
Key_Up = 0,
Key_Down = 1,
Key_Left = 2,
Key_Right = 3,
Key_1 = 4,
Key_2 = 5,
Key_Start = 6,
};
enum GS_Joypads
{
Joypad_1 = 0,
Joypad_2 = 1
};
enum GS_System
{
System_SMS_NTSC_USA,
System_SMS_NTSC_JAP,
System_SMS_PAL,
System_GG
};
enum GS_Region
{
Region_NTSC,
Region_PAL
};
struct GS_RuntimeInfo
{
int screen_width;
int screen_height;
GS_Region region;
};
inline u8 SetBit(const u8 value, const u8 bit)
{
return value | (0x01 << bit);
}
inline u8 UnsetBit(const u8 value, const u8 bit)
{
return value & (~(0x01 << bit));
}
inline bool IsSetBit(const u8 value, const u8 bit)
{
return (value & (0x01 << bit)) != 0;
}
inline u8 FlipBit(const u8 value, const u8 bit)
{
return value ^ (0x01 << bit);
}
inline u8 ReverseBits(const u8 value)
{
u8 ret = value;
ret = (ret & 0xF0) >> 4 | (ret & 0x0F) << 4;
ret = (ret & 0xCC) >> 2 | (ret & 0x33) << 2;
ret = (ret & 0xAA) >> 1 | (ret & 0x55) << 1;
return ret;
}
inline int AsHex(const char c)
{
return c >= 'A' ? c - 'A' + 0xA : c - '0';
}
inline unsigned int Pow2Ceil(u16 n)
{
--n;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
++n;
return n;
}
#if !defined(DEBUG_GEARSYSTEM)
#if defined(__GNUC__) || defined(__clang__)
#if !defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__)
#warning "Compiling without optimizations."
#define GEARSYSTEM_NO_OPTIMIZATIONS
#endif
#elif defined(_MSC_VER)
#if !defined(NDEBUG)
#pragma message("Compiling without optimizations.")
#define GEARSYSTEM_NO_OPTIMIZATIONS
#endif
#endif
#endif
#endif /* DEFINITIONS_H */