2823a4c8 |
1 | /* gameplaySP |
2 | * |
3 | * Copyright (C) 2006 Exophase <exophase@gmail.com> |
4 | * |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as |
7 | * published by the Free Software Foundation; either version 2 of |
8 | * the License, or (at your option) 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 GNU |
13 | * 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, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | */ |
19 | |
20 | #ifndef COMMON_H |
21 | #define COMMON_H |
22 | |
23 | #define ror(dest, value, shift) \ |
24 | dest = ((value) >> shift) | ((value) << (32 - shift)) \ |
25 | |
d0944fc9 |
26 | #if defined(_WIN32) || defined(_WIN32_WCE) |
27 | #define PATH_SEPARATOR "\\" |
28 | #define PATH_SEPARATOR_CHAR '\\' |
29 | #else |
30 | #define PATH_SEPARATOR "/" |
31 | #define PATH_SEPARATOR_CHAR '/' |
32 | #endif |
33 | |
2823a4c8 |
34 | // These includes must be used before SDL is included. |
35 | #ifdef ARM_ARCH |
36 | |
37 | #ifdef _WIN32_WCE |
38 | #include <windows.h> |
39 | #else |
8b6232a6 |
40 | #define _BSD_SOURCE // sync |
2823a4c8 |
41 | #include <stdlib.h> |
42 | #include <stdio.h> |
43 | #include <string.h> |
44 | #include <math.h> |
45 | #include <fcntl.h> |
46 | #include <unistd.h> |
47 | #include <stdarg.h> |
48 | #include <time.h> |
49 | #include <sys/time.h> |
50 | #endif /* _WIN32_WCE */ |
51 | |
52 | #ifdef GIZ_BUILD |
53 | #include "giz/giz.h" |
54 | #endif |
55 | #endif /* ARM_ARCH */ |
56 | |
57 | // Huge thanks to pollux for the heads up on using native file I/O |
58 | // functions on PSP for vastly improved memstick performance. |
59 | |
60 | #define file_write_mem(filename_tag, buffer, size) \ |
61 | { \ |
62 | memcpy(write_mem_ptr, buffer, size); \ |
63 | write_mem_ptr += size; \ |
64 | } \ |
65 | |
66 | #define file_write_mem_array(filename_tag, array) \ |
67 | file_write_mem(filename_tag, array, sizeof(array)) \ |
68 | |
69 | #define file_write_mem_variable(filename_tag, variable) \ |
70 | file_write_mem(filename_tag, &variable, sizeof(variable)) \ |
71 | |
72 | #ifdef PSP_BUILD |
73 | #define fastcall |
74 | |
75 | #include <pspkernel.h> |
76 | #include <pspdebug.h> |
77 | #include <pspctrl.h> |
78 | #include <pspgu.h> |
79 | #include <pspaudio.h> |
80 | #include <pspaudiolib.h> |
81 | #include <psprtc.h> |
82 | |
83 | #define function_cc |
84 | |
85 | #define convert_palette(value) \ |
86 | value = ((value & 0x7FE0) << 1) | (value & 0x1F) \ |
87 | |
88 | #define psp_file_open_read PSP_O_RDONLY |
89 | #define psp_file_open_write (PSP_O_CREAT | PSP_O_WRONLY | PSP_O_TRUNC) |
90 | |
91 | #define file_open(filename_tag, filename, mode) \ |
92 | s32 filename_tag = sceIoOpen(filename, psp_file_open_##mode, 0777) \ |
93 | |
94 | #define file_check_valid(filename_tag) \ |
95 | (filename_tag >= 0) \ |
96 | |
97 | #define file_close(filename_tag) \ |
98 | sceIoClose(filename_tag) \ |
99 | |
100 | #define file_read(filename_tag, buffer, size) \ |
101 | sceIoRead(filename_tag, buffer, size) \ |
102 | |
103 | #define file_write(filename_tag, buffer, size) \ |
104 | sceIoWrite(filename_tag, buffer, size) \ |
105 | |
106 | #define file_seek(filename_tag, offset, type) \ |
107 | sceIoLseek(filename_tag, offset, PSP_##type) \ |
108 | |
109 | #define file_tag_type s32 |
110 | |
111 | #include <time.h> |
112 | #include <stdio.h> |
113 | #else |
114 | #include "SDL.h" |
115 | |
116 | #ifdef ARM_ARCH |
117 | #define function_cc |
118 | #else |
119 | #define function_cc __attribute__((regparm(2))) |
120 | #endif |
121 | |
122 | typedef unsigned char u8; |
123 | typedef signed char s8; |
124 | typedef unsigned short int u16; |
125 | typedef signed short int s16; |
eac69717 |
126 | typedef unsigned int u32; |
127 | typedef signed int s32; |
2823a4c8 |
128 | typedef unsigned long long int u64; |
129 | typedef signed long long int s64; |
130 | |
131 | #define convert_palette(value) \ |
132 | value = ((value & 0x1F) << 11) | ((value & 0x03E0) << 1) | (value >> 10) \ |
133 | |
134 | #define stdio_file_open_read "rb" |
135 | #define stdio_file_open_write "wb" |
136 | |
137 | #define file_open(filename_tag, filename, mode) \ |
138 | FILE *filename_tag = fopen(filename, stdio_file_open_##mode) \ |
139 | |
140 | #define file_check_valid(filename_tag) \ |
141 | (filename_tag) \ |
142 | |
143 | #ifdef GP2X_BUILD |
144 | |
145 | #define file_close(filename_tag) \ |
146 | { \ |
2823a4c8 |
147 | fclose(filename_tag); \ |
638cc626 |
148 | sync(); \ |
2823a4c8 |
149 | } \ |
150 | |
151 | #else |
152 | |
153 | #define file_close(filename_tag) \ |
154 | fclose(filename_tag) \ |
155 | |
156 | #endif |
157 | |
158 | #define file_read(filename_tag, buffer, size) \ |
a88b0431 |
159 | fread(buffer, 1, size, filename_tag) \ |
2823a4c8 |
160 | |
161 | #define file_write(filename_tag, buffer, size) \ |
a88b0431 |
162 | fwrite(buffer, 1, size, filename_tag) \ |
2823a4c8 |
163 | |
164 | #define file_seek(filename_tag, offset, type) \ |
165 | fseek(filename_tag, offset, type) \ |
166 | |
167 | #define file_tag_type FILE * |
168 | |
2823a4c8 |
169 | #endif |
170 | |
171 | // These must be variables, not constants. |
172 | |
173 | #define file_read_variable(filename_tag, variable) \ |
174 | file_read(filename_tag, &variable, sizeof(variable)) \ |
175 | |
176 | #define file_write_variable(filename_tag, variable) \ |
177 | file_write(filename_tag, &variable, sizeof(variable)) \ |
178 | |
179 | // These must be statically declared arrays (ie, global or on the stack, |
180 | // not dynamically allocated on the heap) |
181 | |
182 | #define file_read_array(filename_tag, array) \ |
183 | file_read(filename_tag, array, sizeof(array)) \ |
184 | |
185 | #define file_write_array(filename_tag, array) \ |
186 | file_write(filename_tag, array, sizeof(array)) \ |
187 | |
188 | |
189 | |
190 | typedef u32 fixed16_16; |
2f1c528a |
191 | typedef u32 fixed8_24; |
2823a4c8 |
192 | |
193 | #define float_to_fp16_16(value) \ |
194 | (fixed16_16)((value) * 65536.0) \ |
195 | |
196 | #define fp16_16_to_float(value) \ |
197 | (float)((value) / 65536.0) \ |
198 | |
199 | #define u32_to_fp16_16(value) \ |
200 | ((value) << 16) \ |
201 | |
202 | #define fp16_16_to_u32(value) \ |
203 | ((value) >> 16) \ |
204 | |
205 | #define fp16_16_fractional_part(value) \ |
206 | ((value) & 0xFFFF) \ |
207 | |
2f1c528a |
208 | #define float_to_fp8_24(value) \ |
209 | (fixed8_24)((value) * 16777216.0) \ |
210 | |
211 | #define fp8_24_fractional_part(value) \ |
212 | ((value) & 0xFFFFFF) \ |
213 | |
2823a4c8 |
214 | #define fixed_div(numerator, denominator, bits) \ |
215 | (((numerator * (1 << bits)) + (denominator / 2)) / denominator) \ |
216 | |
217 | #define address8(base, offset) \ |
218 | *((u8 *)((u8 *)base + (offset))) \ |
219 | |
220 | #define address16(base, offset) \ |
221 | *((u16 *)((u8 *)base + (offset))) \ |
222 | |
223 | #define address32(base, offset) \ |
224 | *((u32 *)((u8 *)base + (offset))) \ |
225 | |
226 | #include <unistd.h> |
227 | #include <time.h> |
228 | #include <stdio.h> |
229 | #include <stdlib.h> |
230 | #include <string.h> |
231 | #include <stdarg.h> |
232 | #include "SDL.h" |
233 | #include "cpu.h" |
234 | #include "memory.h" |
235 | #include "video.h" |
236 | #include "input.h" |
237 | #include "sound.h" |
238 | #include "main.h" |
239 | #include "gui.h" |
240 | #include "zip.h" |
241 | #include "cheats.h" |
242 | |
c21718e9 |
243 | #ifdef ARM_ARCH |
244 | #include "arm/warm.h" |
245 | #endif |
2823a4c8 |
246 | |
247 | #ifdef PSP_BUILD |
248 | #define printf pspDebugScreenPrintf |
249 | #endif |
250 | |
251 | #ifdef PC_BUILD |
252 | #define STDIO_DEBUG |
253 | //#define REGISTER_USAGE_ANALYZE |
254 | #endif |
255 | |
256 | #ifdef GP2X_BUILD |
257 | #include <strings.h> |
258 | #include "gp2x/gp2x.h" |
259 | |
260 | #define printf(format, ...) \ |
261 | fprintf(stderr, format, ##__VA_ARGS__) \ |
262 | |
263 | #define vprintf(format, ap) \ |
264 | vfprintf(stderr, format, ap) \ |
265 | |
2823a4c8 |
266 | // #define STDIO_DEBUG |
267 | #endif |
268 | |
eb3668fc |
269 | #ifdef PND_BUILD |
270 | #include "pandora/pnd.h" |
271 | #endif |
272 | |
2823a4c8 |
273 | #endif |