224caa541ab64dd3db5a50d7264eabe36c9612c1
[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 <stdarg.h>
49 #include <stdint.h>
50 #include <stdlib.h>
51 #include <math.h>
52 #include <time.h>
53 #include <ctype.h>
54 #include <sys/types.h>
55 #include <assert.h>
56
57 // Define types
58 typedef int8_t s8;
59 typedef int16_t s16;
60 typedef int32_t s32;
61 typedef int64_t s64;
62 typedef intptr_t sptr;
63
64 typedef uint8_t u8;
65 typedef uint16_t u16;
66 typedef uint32_t u32;
67 typedef uint64_t u64;
68 typedef uintptr_t uptr;
69
70 typedef uint8_t boolean;
71
72 #ifndef TRUE
73 #define TRUE 1
74 #endif
75
76 #ifndef FALSE
77 #define FALSE 0
78 #endif
79
80 // Local includes
81 #include "system.h"
82
83 #ifndef _WIN32
84 #define strnicmp strncasecmp
85 #endif
86 #define __inline inline
87
88 // Enables NLS/internationalization if active
89 #ifdef ENABLE_NLS
90
91 #include <libintl.h>
92
93 #undef _
94 #define _(String) gettext(String)
95 #ifdef gettext_noop
96 #  define N_(String) gettext_noop (String)
97 #else
98 #  define N_(String) (String)
99 #endif
100
101 #else
102
103 #define _(msgid) msgid
104 #define N_(msgid) msgid
105
106 #endif
107
108 extern FILE *emuLog;
109 extern int Log;
110
111 void __Log(char *fmt, ...);
112
113 typedef struct {
114         char Gpu[MAXPATHLEN];
115         char Spu[MAXPATHLEN];
116         char Cdr[MAXPATHLEN];
117         char Pad1[MAXPATHLEN];
118         char Pad2[MAXPATHLEN];
119         char Net[MAXPATHLEN];
120     char Sio1[MAXPATHLEN];
121         char Mcd1[MAXPATHLEN];
122         char Mcd2[MAXPATHLEN];
123         char Bios[MAXPATHLEN];
124         char BiosDir[MAXPATHLEN];
125         char PluginsDir[MAXPATHLEN];
126         char PatchesDir[MAXPATHLEN];
127         boolean Xa;
128         boolean Sio;
129         boolean Mdec;
130         boolean PsxAuto;
131         boolean Cdda;
132         boolean HLE;
133         boolean Debug;
134         boolean PsxOut;
135         boolean SpuIrq;
136         boolean RCntFix;
137         boolean UseNet;
138         boolean VSyncWA;
139         boolean icache_emulation;
140         boolean DisableStalls;
141         u8 Cpu; // CPU_DYNAREC or CPU_INTERPRETER
142         u8 PsxType; // PSX_TYPE_NTSC or PSX_TYPE_PAL
143 #ifdef _WIN32
144         char Lang[256];
145 #endif
146 } PcsxConfig;
147
148 extern PcsxConfig Config;
149 extern boolean NetOpened;
150
151 struct PcsxSaveFuncs {
152         void *(*open)(const char *name, const char *mode);
153         int   (*read)(void *file, void *buf, u32 len);
154         int   (*write)(void *file, const void *buf, u32 len);
155         long  (*seek)(void *file, long offs, int whence);
156         void  (*close)(void *file);
157 };
158 extern struct PcsxSaveFuncs SaveFuncs;
159
160 #define gzfreeze(ptr, size) { \
161         if (Mode == 1) SaveFuncs.write(f, ptr, size); \
162         if (Mode == 0) SaveFuncs.read(f, ptr, size); \
163 }
164
165 // Make the timing events trigger faster as we are currently assuming everything
166 // takes one cycle, which is not the case on real hardware.
167 // FIXME: Count the proper cycle and get rid of this
168 #define BIAS    2
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         CPU_DYNAREC = 0,
178         CPU_INTERPRETER
179 }; // CPU Types
180
181 int EmuInit();
182 void EmuReset();
183 void EmuShutdown();
184 void EmuUpdate();
185
186 #ifdef __cplusplus
187 }
188 #endif
189 #endif