| 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 | |
| 26 | // These includes must be used before SDL is included. |
| 27 | #ifdef ARM_ARCH |
| 28 | |
| 29 | #ifdef _WIN32_WCE |
| 30 | #include <windows.h> |
| 31 | #else |
| 32 | #include <stdlib.h> |
| 33 | #include <stdio.h> |
| 34 | #include <string.h> |
| 35 | #include <math.h> |
| 36 | #include <fcntl.h> |
| 37 | #include <unistd.h> |
| 38 | #include <stdarg.h> |
| 39 | #include <time.h> |
| 40 | #include <sys/time.h> |
| 41 | #endif /* _WIN32_WCE */ |
| 42 | |
| 43 | #ifdef GIZ_BUILD |
| 44 | #include "giz/giz.h" |
| 45 | #endif |
| 46 | #endif /* ARM_ARCH */ |
| 47 | |
| 48 | // Huge thanks to pollux for the heads up on using native file I/O |
| 49 | // functions on PSP for vastly improved memstick performance. |
| 50 | |
| 51 | #define file_write_mem(filename_tag, buffer, size) \ |
| 52 | { \ |
| 53 | memcpy(write_mem_ptr, buffer, size); \ |
| 54 | write_mem_ptr += size; \ |
| 55 | } \ |
| 56 | |
| 57 | #define file_write_mem_array(filename_tag, array) \ |
| 58 | file_write_mem(filename_tag, array, sizeof(array)) \ |
| 59 | |
| 60 | #define file_write_mem_variable(filename_tag, variable) \ |
| 61 | file_write_mem(filename_tag, &variable, sizeof(variable)) \ |
| 62 | |
| 63 | #ifdef PSP_BUILD |
| 64 | #define fastcall |
| 65 | |
| 66 | #include <pspkernel.h> |
| 67 | #include <pspdebug.h> |
| 68 | #include <pspctrl.h> |
| 69 | #include <pspgu.h> |
| 70 | #include <pspaudio.h> |
| 71 | #include <pspaudiolib.h> |
| 72 | #include <psprtc.h> |
| 73 | |
| 74 | #define function_cc |
| 75 | |
| 76 | #define convert_palette(value) \ |
| 77 | value = ((value & 0x7FE0) << 1) | (value & 0x1F) \ |
| 78 | |
| 79 | #define psp_file_open_read PSP_O_RDONLY |
| 80 | #define psp_file_open_write (PSP_O_CREAT | PSP_O_WRONLY | PSP_O_TRUNC) |
| 81 | |
| 82 | #define file_open(filename_tag, filename, mode) \ |
| 83 | s32 filename_tag = sceIoOpen(filename, psp_file_open_##mode, 0777) \ |
| 84 | |
| 85 | #define file_check_valid(filename_tag) \ |
| 86 | (filename_tag >= 0) \ |
| 87 | |
| 88 | #define file_close(filename_tag) \ |
| 89 | sceIoClose(filename_tag) \ |
| 90 | |
| 91 | #define file_read(filename_tag, buffer, size) \ |
| 92 | sceIoRead(filename_tag, buffer, size) \ |
| 93 | |
| 94 | #define file_write(filename_tag, buffer, size) \ |
| 95 | sceIoWrite(filename_tag, buffer, size) \ |
| 96 | |
| 97 | #define file_seek(filename_tag, offset, type) \ |
| 98 | sceIoLseek(filename_tag, offset, PSP_##type) \ |
| 99 | |
| 100 | #define file_tag_type s32 |
| 101 | |
| 102 | #include <time.h> |
| 103 | #include <stdio.h> |
| 104 | #else |
| 105 | #include "SDL.h" |
| 106 | |
| 107 | #ifdef ARM_ARCH |
| 108 | #define function_cc |
| 109 | #else |
| 110 | #define function_cc __attribute__((regparm(2))) |
| 111 | #endif |
| 112 | |
| 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; |
| 121 | |
| 122 | #define convert_palette(value) \ |
| 123 | value = ((value & 0x1F) << 11) | ((value & 0x03E0) << 1) | (value >> 10) \ |
| 124 | |
| 125 | #define stdio_file_open_read "rb" |
| 126 | #define stdio_file_open_write "wb" |
| 127 | |
| 128 | #define file_open(filename_tag, filename, mode) \ |
| 129 | FILE *filename_tag = fopen(filename, stdio_file_open_##mode) \ |
| 130 | |
| 131 | #define file_check_valid(filename_tag) \ |
| 132 | (filename_tag) \ |
| 133 | |
| 134 | #ifdef GP2X_BUILD |
| 135 | |
| 136 | #define file_close(filename_tag) \ |
| 137 | { \ |
| 138 | fclose(filename_tag); \ |
| 139 | sync(); \ |
| 140 | } \ |
| 141 | |
| 142 | #else |
| 143 | |
| 144 | #define file_close(filename_tag) \ |
| 145 | fclose(filename_tag) \ |
| 146 | |
| 147 | #endif |
| 148 | |
| 149 | #define file_read(filename_tag, buffer, size) \ |
| 150 | fread(buffer, size, 1, filename_tag) \ |
| 151 | |
| 152 | #define file_write(filename_tag, buffer, size) \ |
| 153 | fwrite(buffer, size, 1, filename_tag) \ |
| 154 | |
| 155 | #define file_seek(filename_tag, offset, type) \ |
| 156 | fseek(filename_tag, offset, type) \ |
| 157 | |
| 158 | #define file_tag_type FILE * |
| 159 | |
| 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. |
| 163 | |
| 164 | #ifndef PC_BUILD |
| 165 | |
| 166 | #define GP2X_SCREEN_WIDTH 320 |
| 167 | #define GP2X_SCREEN_HEIGHT 240 |
| 168 | |
| 169 | #define GIZ_SCREEN_WIDTH 320 |
| 170 | #define GIZ_SCREEN_HEIGHT 240 |
| 171 | |
| 172 | #ifdef GP2X_BUILD |
| 173 | #define SDL_SCREEN_WIDTH GP2X_SCREEN_WIDTH |
| 174 | #define SDL_SCREEN_HEIGHT GP2X_SCREEN_HEIGHT |
| 175 | |
| 176 | #elif defined(GIZ_BUILD) |
| 177 | |
| 178 | #define SDL_SCREEN_WIDTH GIZ_SCREEN_WIDTH |
| 179 | #define SDL_SCREEN_HEIGHT GIZ_SCREEN_HEIGHT |
| 180 | #endif |
| 181 | |
| 182 | #endif |
| 183 | |
| 184 | #endif |
| 185 | |
| 186 | // These must be variables, not constants. |
| 187 | |
| 188 | #define file_read_variable(filename_tag, variable) \ |
| 189 | file_read(filename_tag, &variable, sizeof(variable)) \ |
| 190 | |
| 191 | #define file_write_variable(filename_tag, variable) \ |
| 192 | file_write(filename_tag, &variable, sizeof(variable)) \ |
| 193 | |
| 194 | // These must be statically declared arrays (ie, global or on the stack, |
| 195 | // not dynamically allocated on the heap) |
| 196 | |
| 197 | #define file_read_array(filename_tag, array) \ |
| 198 | file_read(filename_tag, array, sizeof(array)) \ |
| 199 | |
| 200 | #define file_write_array(filename_tag, array) \ |
| 201 | file_write(filename_tag, array, sizeof(array)) \ |
| 202 | |
| 203 | |
| 204 | |
| 205 | typedef u32 fixed16_16; |
| 206 | |
| 207 | #define float_to_fp16_16(value) \ |
| 208 | (fixed16_16)((value) * 65536.0) \ |
| 209 | |
| 210 | #define fp16_16_to_float(value) \ |
| 211 | (float)((value) / 65536.0) \ |
| 212 | |
| 213 | #define u32_to_fp16_16(value) \ |
| 214 | ((value) << 16) \ |
| 215 | |
| 216 | #define fp16_16_to_u32(value) \ |
| 217 | ((value) >> 16) \ |
| 218 | |
| 219 | #define fp16_16_fractional_part(value) \ |
| 220 | ((value) & 0xFFFF) \ |
| 221 | |
| 222 | #define fixed_div(numerator, denominator, bits) \ |
| 223 | (((numerator * (1 << bits)) + (denominator / 2)) / denominator) \ |
| 224 | |
| 225 | #define address8(base, offset) \ |
| 226 | *((u8 *)((u8 *)base + (offset))) \ |
| 227 | |
| 228 | #define address16(base, offset) \ |
| 229 | *((u16 *)((u8 *)base + (offset))) \ |
| 230 | |
| 231 | #define address32(base, offset) \ |
| 232 | *((u32 *)((u8 *)base + (offset))) \ |
| 233 | |
| 234 | #include <unistd.h> |
| 235 | #include <time.h> |
| 236 | #include <stdio.h> |
| 237 | #include <stdlib.h> |
| 238 | #include <string.h> |
| 239 | #include <stdarg.h> |
| 240 | #include "SDL.h" |
| 241 | #include "cpu.h" |
| 242 | #include "memory.h" |
| 243 | #include "video.h" |
| 244 | #include "input.h" |
| 245 | #include "sound.h" |
| 246 | #include "main.h" |
| 247 | #include "gui.h" |
| 248 | #include "zip.h" |
| 249 | #include "cheats.h" |
| 250 | |
| 251 | |
| 252 | #ifdef PSP_BUILD |
| 253 | #define printf pspDebugScreenPrintf |
| 254 | #endif |
| 255 | |
| 256 | #ifdef PC_BUILD |
| 257 | #define STDIO_DEBUG |
| 258 | //#define REGISTER_USAGE_ANALYZE |
| 259 | #endif |
| 260 | |
| 261 | #ifdef GP2X_BUILD |
| 262 | #include <strings.h> |
| 263 | #include "gp2x/gp2x.h" |
| 264 | |
| 265 | #define printf(format, ...) \ |
| 266 | fprintf(stderr, format, ##__VA_ARGS__) \ |
| 267 | |
| 268 | #define vprintf(format, ap) \ |
| 269 | vfprintf(stderr, format, ap) \ |
| 270 | |
| 271 | // #define STDIO_DEBUG |
| 272 | #endif |
| 273 | |
| 274 | #endif |