Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/Cherry/Core/include/definitions.h
2 views
1
/*
2
* Gearcoleco - ColecoVision Emulator
3
* Copyright (C) 2021 Ignacio Sanchez
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 as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see http://www.gnu.org/licenses/
17
*
18
*/
19
20
#ifndef DEFINITIONS_H
21
#define DEFINITIONS_H
22
23
#include <stdarg.h>
24
#include <stdlib.h>
25
#include <stdio.h>
26
#include <string.h>
27
#include <stdint.h>
28
#include <iostream>
29
#include <fstream>
30
#include <sstream>
31
32
#ifndef EMULATOR_BUILD
33
#define EMULATOR_BUILD "undefined"
34
#endif
35
36
#define GEARCOLECO_TITLE "Gearcoleco"
37
#define GEARCOLECO_VERSION EMULATOR_BUILD
38
#define GEARCOLECO_TITLE_ASCII "" \
39
" ____ _ \n" \
40
" / ___| ___ __ _ _ __ ___ ___ | | ___ ___ ___ \n" \
41
" | | _ / _ \\/ _` | '__/ __/ _ \\| |/ _ \\/ __/ _ \\ \n" \
42
" | |_| | __/ (_| | | | (_| (_) | | __/ (_| (_) | \n" \
43
" \\____|\\___|\\__,_|_| \\___\\___/|_|\\___|\\___\\___/ \n"
44
45
46
#ifdef DEBUG
47
#define DEBUG_GEARCOLECO 0
48
#endif
49
50
#if defined(PS2) || defined(PSP)
51
#define PERFORMANCE
52
#endif
53
54
#ifndef NULL
55
#define NULL 0
56
#endif
57
58
#ifdef _WIN32
59
#define BLARGG_USE_NAMESPACE 1
60
#endif
61
62
//#define GEARCOLECO_DISABLE_DISASSEMBLER
63
64
#define MAX_ROM_SIZE 0x800000
65
66
#define SafeDelete(pointer) if(pointer != NULL) {delete pointer; pointer = NULL;}
67
#define SafeDeleteArray(pointer) if(pointer != NULL) {delete [] pointer; pointer = NULL;}
68
69
#define InitPointer(pointer) ((pointer) = NULL)
70
#define IsValidPointer(pointer) ((pointer) != NULL)
71
72
#if defined(MSB_FIRST) || defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
73
#define IS_BIG_ENDIAN
74
#else
75
#define IS_LITTLE_ENDIAN
76
#endif
77
78
#define MIN(a, b) ((a) < (b) ? (a) : (b))
79
#define MAX(a, b) ((a) > (b) ? (a) : (b))
80
#define CLAMP(value, min, max) MIN(MAX(value, min), max)
81
82
typedef uint8_t u8;
83
typedef int8_t s8;
84
typedef uint16_t u16;
85
typedef int16_t s16;
86
typedef uint32_t u32;
87
typedef int32_t s32;
88
typedef uint64_t u64;
89
typedef int64_t s64;
90
91
typedef void (*RamChangedCallback) (void);
92
93
#define FLAG_CARRY 0x01
94
#define FLAG_NEGATIVE 0x02
95
#define FLAG_PARITY 0x04
96
#define FLAG_X 0x08
97
#define FLAG_HALF 0x10
98
#define FLAG_Y 0x20
99
#define FLAG_ZERO 0x40
100
#define FLAG_SIGN 0x80
101
#define FLAG_NONE 0
102
103
#define GC_RESOLUTION_WIDTH 256
104
#define GC_RESOLUTION_HEIGHT 192
105
106
#define GC_MAX_GAMEPADS 2
107
108
#define GC_RESOLUTION_WIDTH_WITH_OVERSCAN 320
109
#define GC_RESOLUTION_HEIGHT_WITH_OVERSCAN 288
110
#define GC_RESOLUTION_SMS_OVERSCAN_H_320_L 32
111
#define GC_RESOLUTION_SMS_OVERSCAN_H_320_R 32
112
#define GC_RESOLUTION_SMS_OVERSCAN_H_284_L 14
113
#define GC_RESOLUTION_SMS_OVERSCAN_H_284_R 14
114
#define GC_RESOLUTION_OVERSCAN_V 24
115
#define GC_RESOLUTION_OVERSCAN_V_PAL 48
116
117
#define GC_CYCLES_PER_LINE 228
118
119
#define GC_MASTER_CLOCK_NTSC 3579545
120
#define GC_LINES_PER_FRAME_NTSC 262
121
#define GC_FRAMES_PER_SECOND_NTSC 60
122
123
#define GC_MASTER_CLOCK_PAL 3546893
124
#define GC_LINES_PER_FRAME_PAL 313
125
#define GC_FRAMES_PER_SECOND_PAL 50
126
127
#define GC_AUDIO_SAMPLE_RATE 44100
128
#define GC_AUDIO_BUFFER_SIZE 8192
129
130
#define GC_SAVESTATE_MAGIC 0x09200902
131
132
struct GC_Color
133
{
134
u8 red;
135
u8 green;
136
u8 blue;
137
};
138
139
enum GC_Color_Format
140
{
141
GC_PIXEL_RGB565,
142
GC_PIXEL_RGB555,
143
GC_PIXEL_RGB888,
144
GC_PIXEL_BGR565,
145
GC_PIXEL_BGR555,
146
GC_PIXEL_BGR888
147
};
148
149
enum GC_Keys
150
{
151
Keypad_8 = 0x01,
152
Keypad_4 = 0x02,
153
Keypad_5 = 0x03,
154
Key_Blue = 0x04,
155
Keypad_7 = 0x05,
156
Keypad_Hash = 0x06,
157
Keypad_2 = 0x07,
158
Key_Purple = 0x08,
159
Keypad_Asterisk = 0x09,
160
Keypad_0 = 0x0A,
161
Keypad_9 = 0x0B,
162
Keypad_3 = 0x0C,
163
Keypad_1 = 0x0D,
164
Keypad_6 = 0x0E,
165
Key_Up = 0x10,
166
Key_Right = 0x11,
167
Key_Down = 0x12,
168
Key_Left = 0x13,
169
Key_Left_Button = 0x14,
170
Key_Right_Button = 0x15
171
};
172
173
enum GC_Controllers
174
{
175
Controller_1 = 0,
176
Controller_2 = 1
177
};
178
179
enum GC_Region
180
{
181
Region_NTSC,
182
Region_PAL
183
};
184
185
struct GC_RuntimeInfo
186
{
187
int screen_width;
188
int screen_height;
189
GC_Region region;
190
};
191
192
inline u8 SetBit(const u8 value, const u8 bit)
193
{
194
return value | (0x01 << bit);
195
}
196
197
inline u8 UnsetBit(const u8 value, const u8 bit)
198
{
199
return value & (~(0x01 << bit));
200
}
201
202
inline bool IsSetBit(const u8 value, const u8 bit)
203
{
204
return (value & (0x01 << bit)) != 0;
205
}
206
207
inline u8 FlipBit(const u8 value, const u8 bit)
208
{
209
return value ^ (0x01 << bit);
210
}
211
212
inline u8 ReverseBits(const u8 value)
213
{
214
u8 ret = value;
215
ret = (ret & 0xF0) >> 4 | (ret & 0x0F) << 4;
216
ret = (ret & 0xCC) >> 2 | (ret & 0x33) << 2;
217
ret = (ret & 0xAA) >> 1 | (ret & 0x55) << 1;
218
return ret;
219
}
220
221
inline int AsHex(const char c)
222
{
223
return c >= 'A' ? c - 'A' + 0xA : c - '0';
224
}
225
226
inline unsigned int Pow2Ceil(u16 n)
227
{
228
--n;
229
n |= n >> 1;
230
n |= n >> 2;
231
n |= n >> 4;
232
n |= n >> 8;
233
++n;
234
return n;
235
}
236
237
#endif /* DEFINITIONS_H */
238
239