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