3 * Copyright (C) 2006 Exophase <exophase@gmail.com>
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.
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.
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
23 #define ror(dest, value, shift) \
24 dest = ((value) >> shift) | ((value) << (32 - shift)) \
26 // These includes must be used before SDL is included.
41 #endif /* _WIN32_WCE */
48 // Huge thanks to pollux for the heads up on using native file I/O
49 // functions on PSP for vastly improved memstick performance.
51 #define file_write_mem(filename_tag, buffer, size) \
53 memcpy(write_mem_ptr, buffer, size); \
54 write_mem_ptr += size; \
57 #define file_write_mem_array(filename_tag, array) \
58 file_write_mem(filename_tag, array, sizeof(array)) \
60 #define file_write_mem_variable(filename_tag, variable) \
61 file_write_mem(filename_tag, &variable, sizeof(variable)) \
66 #include <pspkernel.h>
71 #include <pspaudiolib.h>
76 #define convert_palette(value) \
77 value = ((value & 0x7FE0) << 1) | (value & 0x1F) \
79 #define psp_file_open_read PSP_O_RDONLY
80 #define psp_file_open_write (PSP_O_CREAT | PSP_O_WRONLY | PSP_O_TRUNC)
82 #define file_open(filename_tag, filename, mode) \
83 s32 filename_tag = sceIoOpen(filename, psp_file_open_##mode, 0777) \
85 #define file_check_valid(filename_tag) \
88 #define file_close(filename_tag) \
89 sceIoClose(filename_tag) \
91 #define file_read(filename_tag, buffer, size) \
92 sceIoRead(filename_tag, buffer, size) \
94 #define file_write(filename_tag, buffer, size) \
95 sceIoWrite(filename_tag, buffer, size) \
97 #define file_seek(filename_tag, offset, type) \
98 sceIoLseek(filename_tag, offset, PSP_##type) \
100 #define file_tag_type s32
110 #define function_cc __attribute__((regparm(2)))
113 typedef unsigned char u8;
114 typedef signed char s8;
115 typedef unsigned short int u16;
116 typedef signed short int s16;
117 typedef unsigned long u32;
118 typedef signed long s32;
119 typedef unsigned long long int u64;
120 typedef signed long long int s64;
122 #define convert_palette(value) \
123 value = ((value & 0x1F) << 11) | ((value & 0x03E0) << 1) | (value >> 10) \
125 #define stdio_file_open_read "rb"
126 #define stdio_file_open_write "wb"
128 #define file_open(filename_tag, filename, mode) \
129 FILE *filename_tag = fopen(filename, stdio_file_open_##mode) \
131 #define file_check_valid(filename_tag) \
136 #define file_close(filename_tag) \
138 fclose(filename_tag); \
144 #define file_close(filename_tag) \
145 fclose(filename_tag) \
149 #define file_read(filename_tag, buffer, size) \
150 fread(buffer, size, 1, filename_tag) \
152 #define file_write(filename_tag, buffer, size) \
153 fwrite(buffer, size, 1, filename_tag) \
155 #define file_seek(filename_tag, offset, type) \
156 fseek(filename_tag, offset, type) \
158 #define file_tag_type FILE *
160 // The ARM arch uses SDL, and SDL requires you to know what resolution
161 // you want. Define the resolution for ARM arch builds here.
162 // Placed in common.h for use with video.c and gui.c.
166 #define GP2X_SCREEN_WIDTH 320
167 #define GP2X_SCREEN_HEIGHT 240
169 #define GIZ_SCREEN_WIDTH 320
170 #define GIZ_SCREEN_HEIGHT 240
173 #define SDL_SCREEN_WIDTH GP2X_SCREEN_WIDTH
174 #define SDL_SCREEN_HEIGHT GP2X_SCREEN_HEIGHT
176 #elif defined(GIZ_BUILD)
178 #define SDL_SCREEN_WIDTH GIZ_SCREEN_WIDTH
179 #define SDL_SCREEN_HEIGHT GIZ_SCREEN_HEIGHT
186 // These must be variables, not constants.
188 #define file_read_variable(filename_tag, variable) \
189 file_read(filename_tag, &variable, sizeof(variable)) \
191 #define file_write_variable(filename_tag, variable) \
192 file_write(filename_tag, &variable, sizeof(variable)) \
194 // These must be statically declared arrays (ie, global or on the stack,
195 // not dynamically allocated on the heap)
197 #define file_read_array(filename_tag, array) \
198 file_read(filename_tag, array, sizeof(array)) \
200 #define file_write_array(filename_tag, array) \
201 file_write(filename_tag, array, sizeof(array)) \
205 typedef u32 fixed16_16;
207 #define float_to_fp16_16(value) \
208 (fixed16_16)((value) * 65536.0) \
210 #define fp16_16_to_float(value) \
211 (float)((value) / 65536.0) \
213 #define u32_to_fp16_16(value) \
216 #define fp16_16_to_u32(value) \
219 #define fp16_16_fractional_part(value) \
222 #define fixed_div(numerator, denominator, bits) \
223 (((numerator * (1 << bits)) + (denominator / 2)) / denominator) \
225 #define address8(base, offset) \
226 *((u8 *)((u8 *)base + (offset))) \
228 #define address16(base, offset) \
229 *((u16 *)((u8 *)base + (offset))) \
231 #define address32(base, offset) \
232 *((u32 *)((u8 *)base + (offset))) \
253 #define printf pspDebugScreenPrintf
258 //#define REGISTER_USAGE_ANALYZE
263 #include "gp2x/gp2x.h"
265 #define printf(format, ...) \
266 fprintf(stderr, format, ##__VA_ARGS__) \
268 #define vprintf(format, ap) \
269 vfprintf(stderr, format, ap) \
271 // #define STDIO_DEBUG