cd12cfe12268c378a79abb6bf968f6d110655335
[pcsx_rearmed.git] / libpcsxcore / psxcommon.h
1 /***************************************************************************
2  *   Copyright (C) 2007 Ryan Schultz, PCSX-df Team, PCSX team              *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA.           *
18  ***************************************************************************/
19
20 /* 
21 * This file contains common definitions and includes for all parts of the 
22 * emulator core.
23 */
24
25 #ifndef __PSXCOMMON_H__
26 #define __PSXCOMMON_H__
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #include "config.h"
33
34 // XXX: don't care but maybe fix it someday
35 #if defined(__GNUC__) && __GNUC__ >= 8
36 #pragma GCC diagnostic ignored "-Wformat-truncation"
37 #pragma GCC diagnostic ignored "-Wformat-overflow"
38 #pragma GCC diagnostic ignored "-Wstringop-truncation"
39 #endif
40 // devkitpro has uint32_t as long, unfortunately
41 #ifdef _3DS
42 #pragma GCC diagnostic ignored "-Wformat"
43 #endif
44
45 // System includes
46 //#include <stdio.h>
47 #include <string.h>
48 #include <stdint.h>
49 #include <stdlib.h>
50 #ifndef __SWITCH__
51 #include <sys/types.h>
52 #endif
53
54 // Define types
55 typedef int8_t s8;
56 typedef int16_t s16;
57 typedef int32_t s32;
58 typedef int64_t s64;
59 typedef intptr_t sptr;
60
61 typedef uint8_t u8;
62 typedef uint16_t u16;
63 typedef uint32_t u32;
64 typedef uint64_t u64;
65 typedef uintptr_t uptr;
66
67 typedef uint8_t boolean;
68
69 #ifndef TRUE
70 #define TRUE 1
71 #endif
72
73 #ifndef FALSE
74 #define FALSE 0
75 #endif
76
77 // Local includes
78 #include "system.h"
79
80 #ifndef _WIN32
81 #define strnicmp strncasecmp
82 #endif
83
84 // Enables NLS/internationalization if active
85 #ifdef ENABLE_NLS
86
87 #include <libintl.h>
88
89 #undef _
90 #define _(String) gettext(String)
91 #ifdef gettext_noop
92 #  define N_(String) gettext_noop (String)
93 #else
94 #  define N_(String) (String)
95 #endif
96
97 #else
98
99 #define _(msgid) msgid
100 #define N_(msgid) msgid
101
102 #endif
103
104 // lots of timing depends on this and makes or breaks compatibility,
105 // don't change unless you're going to retest hundreds of games
106 #define CYCLE_MULT_DEFAULT 175
107
108 #define PSX_REGION_COUNT 3
109
110 typedef struct {
111         char Gpu[MAXPATHLEN];
112         char Spu[MAXPATHLEN];
113         char Sio1[MAXPATHLEN];
114         char Mcd1[MAXPATHLEN];
115         char Mcd2[MAXPATHLEN];
116         char Bios[PSX_REGION_COUNT][64]; // us, jp, eu; see psxMemReset()
117         char BiosDir[MAXPATHLEN];
118         char PluginsDir[MAXPATHLEN];
119         char PatchesDir[MAXPATHLEN];
120         boolean Xa;
121         boolean Mdec;
122         boolean PsxAuto;
123         boolean Cdda;
124         boolean CHD_Precache; /* loads disk image into memory, works with CHD only. */
125         boolean HLE;
126         uint8_t SlowBoot; // 0 = off, 1 = on, 2 = on, no PCSX 'ad'
127         boolean Debug;
128         boolean PsxOut;
129         boolean icache_emulation;
130         boolean DisableStalls;
131         boolean PreciseExceptions;
132         boolean TurboCD;
133         int cycle_multiplier; // 100 for 1.0
134         int cycle_multiplier_override;
135         int gpu_timing_override;
136         s8 GpuListWalking; // -1..1: -1 = auto, 0/1 = off/on
137         s8 FractionalFramerate; // -1..1, ~49.75 and ~59.81 instead of 50 and 60
138         s8 AlternativeFlip; // -1..1
139         u8 Cpu; // CPU_DYNAREC or CPU_INTERPRETER
140         u8 PsxType; // PSX_TYPE_NTSC or PSX_TYPE_PAL
141         u8 PsxRegion; // PSX_REGION_US, PSX_REGION_JP, PSX_REGION_EU
142         struct {
143                 boolean cdr_read_timing;
144                 boolean gpu_slow_list_walking;
145                 boolean gpu_centering;
146                 boolean dualshock_init_analog;
147                 boolean fractional_Framerate;
148                 boolean f1;
149                 boolean alt_flip;
150         } hacks;
151 } PcsxConfig;
152
153 extern PcsxConfig Config;
154
155 struct PcsxSaveFuncs {
156         void *(*open)(const char *name, const char *mode);
157         int   (*read)(void *file, void *buf, u32 len);
158         int   (*write)(void *file, const void *buf, u32 len);
159         long  (*seek)(void *file, long offs, int whence);
160         void  (*close)(void *file);
161 };
162 extern struct PcsxSaveFuncs SaveFuncs;
163
164 #define gzfreeze(ptr, size) { \
165         if (Mode == 1) SaveFuncs.write(f, ptr, size); \
166         if (Mode == 0) SaveFuncs.read(f, ptr, size); \
167 }
168
169 #define PSXCLK  33868800        /* 33.8688 MHz */
170
171 enum {
172         PSX_TYPE_NTSC = 0,
173         PSX_TYPE_PAL
174 }; // PSX Types
175
176 enum {
177         PSX_REGION_US = 0,
178         PSX_REGION_JP,
179         PSX_REGION_EU
180 };
181
182 enum {
183         CPU_DYNAREC = 0,
184         CPU_INTERPRETER
185 }; // CPU Types
186
187 int EmuInit();
188 void EmuReset();
189 void EmuShutdown();
190 void EmuUpdate();
191
192 #ifdef __cplusplus
193 }
194 #endif
195 #endif