Core commit. Compile and run on the OpenPandora
[mupen64plus-pandora.git] / source / mupen64plus-core / src / api / m64p_types.h
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  *   Mupen64plus-core - m64p_types.h                                       *
3  *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
4  *   Copyright (C) 2012 CasualJames                                        *
5  *   Copyright (C) 2009 Richard Goedeken                                   *
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or modify  *
8  *   it under the terms of the GNU General Public License as published by  *
9  *   the Free Software Foundation; either version 2 of the License, or     *
10  *   (at your option) any later version.                                   *
11  *                                                                         *
12  *   This program is distributed in the hope that it will be useful,       *
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15  *   GNU General Public License for more details.                          *
16  *                                                                         *
17  *   You should have received a copy of the GNU General Public License     *
18  *   along with this program; if not, write to the                         *
19  *   Free Software Foundation, Inc.,                                       *
20  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
21  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22
23 #if !defined(M64P_TYPES_H)
24 #define M64P_TYPES_H
25
26 /* ----------------------------------------- */
27 /* Platform-specific stuff                   */
28 /* ----------------------------------------- */
29
30 /* necessary headers */
31 #if defined(WIN32)
32   #include <windows.h>
33 #endif
34
35 /* DLL handles and function declaration specifiers */
36 #if defined(WIN32)
37   #define IMPORT extern "C" __declspec(dllimport)
38   #define EXPORT __declspec(dllexport)
39   #define CALL   __cdecl
40   typedef HMODULE m64p_dynlib_handle;
41 #else
42   #define IMPORT extern "C"
43   #define EXPORT __attribute__((visibility("default")))
44   #define CALL
45   typedef void * m64p_dynlib_handle;
46 #endif
47
48 /* ----------------------------------------- */
49 /* Structures and Types for Core library API */
50 /* ----------------------------------------- */
51
52 typedef void * m64p_handle;
53
54 typedef void (*m64p_frame_callback)(unsigned int FrameIndex);
55 typedef void (*m64p_input_callback)(void);
56 typedef void (*m64p_audio_callback)(void);
57 typedef void (*m64p_vi_callback)(void);
58
59 typedef enum {
60   M64TYPE_INT = 1,
61   M64TYPE_FLOAT,
62   M64TYPE_BOOL,
63   M64TYPE_STRING
64 } m64p_type;
65
66 typedef enum {
67   M64MSG_ERROR = 1,
68   M64MSG_WARNING,
69   M64MSG_INFO,
70   M64MSG_STATUS,
71   M64MSG_VERBOSE
72 } m64p_msg_level;
73
74 typedef enum {
75   M64ERR_SUCCESS = 0,
76   M64ERR_NOT_INIT,        /* Function is disallowed before InitMupen64Plus() is called */
77   M64ERR_ALREADY_INIT,    /* InitMupen64Plus() was called twice */
78   M64ERR_INCOMPATIBLE,    /* API versions between components are incompatible */
79   M64ERR_INPUT_ASSERT,    /* Invalid parameters for function call, such as ParamValue=NULL for GetCoreParameter() */
80   M64ERR_INPUT_INVALID,   /* Invalid input data, such as ParamValue="maybe" for SetCoreParameter() to set a BOOL-type value */
81   M64ERR_INPUT_NOT_FOUND, /* The input parameter(s) specified a particular item which was not found */
82   M64ERR_NO_MEMORY,       /* Memory allocation failed */
83   M64ERR_FILES,           /* Error opening, creating, reading, or writing to a file */
84   M64ERR_INTERNAL,        /* Internal error (bug) */
85   M64ERR_INVALID_STATE,   /* Current program state does not allow operation */
86   M64ERR_PLUGIN_FAIL,     /* A plugin function returned a fatal error */
87   M64ERR_SYSTEM_FAIL,     /* A system function call, such as an SDL or file operation, failed */
88   M64ERR_UNSUPPORTED,     /* Function call is not supported (ie, core not built with debugger) */
89   M64ERR_WRONG_TYPE       /* A given input type parameter cannot be used for desired operation */
90 } m64p_error;
91
92 typedef enum {
93   M64CAPS_DYNAREC = 1,
94   M64CAPS_DEBUGGER = 2,
95   M64CAPS_CORE_COMPARE = 4
96 } m64p_core_caps;
97
98 typedef enum {
99   M64PLUGIN_NULL = 0,
100   M64PLUGIN_RSP = 1,
101   M64PLUGIN_GFX,
102   M64PLUGIN_AUDIO,
103   M64PLUGIN_INPUT,
104   M64PLUGIN_CORE
105 } m64p_plugin_type;
106
107 typedef enum {
108   M64EMU_STOPPED = 1,
109   M64EMU_RUNNING,
110   M64EMU_PAUSED
111 } m64p_emu_state;
112
113 typedef enum {
114   M64VIDEO_NONE = 1,
115   M64VIDEO_WINDOWED,
116   M64VIDEO_FULLSCREEN
117 } m64p_video_mode;
118
119 typedef enum {
120   M64VIDEOFLAG_SUPPORT_RESIZING = 1
121 } m64p_video_flags;
122
123 typedef enum {
124   M64CORE_EMU_STATE = 1,
125   M64CORE_VIDEO_MODE,
126   M64CORE_SAVESTATE_SLOT,
127   M64CORE_SPEED_FACTOR,
128   M64CORE_SPEED_LIMITER,
129   M64CORE_VIDEO_SIZE,
130   M64CORE_AUDIO_VOLUME,
131   M64CORE_AUDIO_MUTE,
132   M64CORE_INPUT_GAMESHARK,
133   M64CORE_STATE_LOADCOMPLETE,
134   M64CORE_STATE_SAVECOMPLETE
135 } m64p_core_param;
136
137 typedef enum {
138   M64CMD_NOP = 0,
139   M64CMD_ROM_OPEN,
140   M64CMD_ROM_CLOSE,
141   M64CMD_ROM_GET_HEADER,
142   M64CMD_ROM_GET_SETTINGS,
143   M64CMD_EXECUTE,
144   M64CMD_STOP,
145   M64CMD_PAUSE,
146   M64CMD_RESUME,
147   M64CMD_CORE_STATE_QUERY,
148   M64CMD_STATE_LOAD,
149   M64CMD_STATE_SAVE,
150   M64CMD_STATE_SET_SLOT,
151   M64CMD_SEND_SDL_KEYDOWN,
152   M64CMD_SEND_SDL_KEYUP,
153   M64CMD_SET_FRAME_CALLBACK,
154   M64CMD_TAKE_NEXT_SCREENSHOT,
155   M64CMD_CORE_STATE_SET,
156   M64CMD_READ_SCREEN,
157   M64CMD_RESET,
158   M64CMD_ADVANCE_FRAME
159 } m64p_command;
160
161 typedef struct {
162   unsigned int address;
163   int          value;
164 } m64p_cheat_code;
165
166 /* ----------------------------------------- */
167 /* Structures to hold ROM image information  */
168 /* ----------------------------------------- */
169
170 typedef enum
171 {
172     SYSTEM_NTSC = 0,
173     SYSTEM_PAL,
174     SYSTEM_MPAL
175 } m64p_system_type;
176
177 typedef struct
178 {
179    unsigned char init_PI_BSB_DOM1_LAT_REG;  /* 0x00 */
180    unsigned char init_PI_BSB_DOM1_PGS_REG;  /* 0x01 */
181    unsigned char init_PI_BSB_DOM1_PWD_REG;  /* 0x02 */
182    unsigned char init_PI_BSB_DOM1_PGS_REG2; /* 0x03 */
183    unsigned int ClockRate;                  /* 0x04 */
184    unsigned int PC;                         /* 0x08 */
185    unsigned int Release;                    /* 0x0C */
186    unsigned int CRC1;                       /* 0x10 */
187    unsigned int CRC2;                       /* 0x14 */
188    unsigned int Unknown[2];                 /* 0x18 */
189    unsigned char Name[20];                  /* 0x20 */
190    unsigned int unknown;                    /* 0x34 */
191    unsigned int Manufacturer_ID;            /* 0x38 */
192    unsigned short Cartridge_ID;             /* 0x3C - Game serial number  */
193    unsigned short Country_code;             /* 0x3E */
194 } m64p_rom_header;
195
196 typedef struct
197 {
198    char goodname[256];
199    char MD5[33];
200    unsigned char savetype;
201    unsigned char status;  /* Rom status on a scale from 0-5. */
202    unsigned char players; /* Local players 0-4, 2/3/4 way Netplay indicated by 5/6/7. */
203    unsigned char rumble;  /* 0 - No, 1 - Yes boolean for rumble support. */
204 } m64p_rom_settings;
205
206 /* ----------------------------------------- */
207 /* Structures and Types for the Debugger     */
208 /* ----------------------------------------- */
209
210 typedef enum {
211   M64P_DBG_RUN_STATE = 1,
212   M64P_DBG_PREVIOUS_PC,
213   M64P_DBG_NUM_BREAKPOINTS,
214   M64P_DBG_CPU_DYNACORE,
215   M64P_DBG_CPU_NEXT_INTERRUPT
216 } m64p_dbg_state;
217
218 typedef enum {
219   M64P_DBG_MEM_TYPE = 1,
220   M64P_DBG_MEM_FLAGS,
221   M64P_DBG_MEM_HAS_RECOMPILED,
222   M64P_DBG_MEM_NUM_RECOMPILED,
223   M64P_DBG_RECOMP_OPCODE = 16,
224   M64P_DBG_RECOMP_ARGS,
225   M64P_DBG_RECOMP_ADDR
226 } m64p_dbg_mem_info;
227
228 typedef enum {
229   M64P_MEM_NOMEM = 0,
230   M64P_MEM_NOTHING,
231   M64P_MEM_RDRAM,
232   M64P_MEM_RDRAMREG,
233   M64P_MEM_RSPMEM,
234   M64P_MEM_RSPREG,
235   M64P_MEM_RSP,
236   M64P_MEM_DP,
237   M64P_MEM_DPS,
238   M64P_MEM_VI,
239   M64P_MEM_AI,
240   M64P_MEM_PI,
241   M64P_MEM_RI,
242   M64P_MEM_SI,
243   M64P_MEM_FLASHRAMSTAT,
244   M64P_MEM_ROM,
245   M64P_MEM_PIF,
246   M64P_MEM_MI,
247   M64P_MEM_BREAKPOINT
248 } m64p_dbg_mem_type;
249
250 typedef enum {
251   M64P_MEM_FLAG_READABLE = 0x01,
252   M64P_MEM_FLAG_WRITABLE = 0x02,
253   M64P_MEM_FLAG_READABLE_EMUONLY = 0x04,  // the EMUONLY flags signify that emulated code can read/write here, but debugger cannot
254   M64P_MEM_FLAG_WRITABLE_EMUONLY = 0x08
255 } m64p_dbg_mem_flags;
256
257 typedef enum {
258   M64P_DBG_PTR_RDRAM = 1,
259   M64P_DBG_PTR_PI_REG,
260   M64P_DBG_PTR_SI_REG,
261   M64P_DBG_PTR_VI_REG,
262   M64P_DBG_PTR_RI_REG,
263   M64P_DBG_PTR_AI_REG
264 } m64p_dbg_memptr_type;
265
266 typedef enum {
267   M64P_CPU_PC = 1,
268   M64P_CPU_REG_REG,
269   M64P_CPU_REG_HI,
270   M64P_CPU_REG_LO,
271   M64P_CPU_REG_COP0,
272   M64P_CPU_REG_COP1_DOUBLE_PTR,
273   M64P_CPU_REG_COP1_SIMPLE_PTR,
274   M64P_CPU_REG_COP1_FGR_64,
275   M64P_CPU_TLB
276 } m64p_dbg_cpu_data;
277
278 typedef enum {
279   M64P_BKP_CMD_ADD_ADDR = 1,
280   M64P_BKP_CMD_ADD_STRUCT,
281   M64P_BKP_CMD_REPLACE,
282   M64P_BKP_CMD_REMOVE_ADDR,
283   M64P_BKP_CMD_REMOVE_IDX,
284   M64P_BKP_CMD_ENABLE,
285   M64P_BKP_CMD_DISABLE,
286   M64P_BKP_CMD_CHECK
287 } m64p_dbg_bkp_command;
288
289 #define M64P_MEM_INVALID        0xFFFFFFFF  // invalid memory read will return this
290
291 #define BREAKPOINTS_MAX_NUMBER  128
292
293 #define BPT_FLAG_ENABLED        0x01
294 #define BPT_FLAG_CONDITIONAL    0x02
295 #define BPT_FLAG_COUNTER        0x04
296 #define BPT_FLAG_READ           0x08
297 #define BPT_FLAG_WRITE          0x10
298 #define BPT_FLAG_EXEC           0x20
299 #define BPT_FLAG_LOG            0x40 //Log to the console when this breakpoint hits.
300
301 #define BPT_CHECK_FLAG(a, b)  ((a.flags & b) == b)
302 #define BPT_SET_FLAG(a, b)    a.flags = (a.flags | b);
303 #define BPT_CLEAR_FLAG(a, b)  a.flags = (a.flags & (~b));
304 #define BPT_TOGGLE_FLAG(a, b) a.flags = (a.flags ^ b);
305
306 typedef struct _breakpoint {
307     unsigned int address; 
308     unsigned int endaddr;
309     unsigned int flags;
310     //unsigned int condition;  //Placeholder for breakpoint condition
311     } breakpoint;
312
313 /* ------------------------------------------------- */
314 /* Structures and Types for Core Video Extension API */
315 /* ------------------------------------------------- */
316
317 typedef struct {
318   unsigned int uiWidth;
319   unsigned int uiHeight;
320 } m64p_2d_size;
321
322 typedef enum {
323   M64P_GL_DOUBLEBUFFER = 1,
324   M64P_GL_BUFFER_SIZE,
325   M64P_GL_DEPTH_SIZE,
326   M64P_GL_RED_SIZE,
327   M64P_GL_GREEN_SIZE,
328   M64P_GL_BLUE_SIZE,
329   M64P_GL_ALPHA_SIZE,
330   M64P_GL_SWAP_CONTROL,
331   M64P_GL_MULTISAMPLEBUFFERS,
332   M64P_GL_MULTISAMPLESAMPLES
333 } m64p_GLattr;
334
335 typedef struct {
336   unsigned int Functions;
337   m64p_error (*VidExtFuncInit)(void);
338   m64p_error (*VidExtFuncQuit)(void);
339   m64p_error (*VidExtFuncListModes)(m64p_2d_size *, int *);
340   m64p_error (*VidExtFuncSetMode)(int, int, int, int, int);
341   void *     (*VidExtFuncGLGetProc)(const char*);
342   m64p_error (*VidExtFuncGLSetAttr)(m64p_GLattr, int);
343   m64p_error (*VidExtFuncGLGetAttr)(m64p_GLattr, int *);
344   m64p_error (*VidExtFuncGLSwapBuf)(void);
345   m64p_error (*VidExtFuncSetCaption)(const char *);
346   m64p_error (*VidExtFuncToggleFS)(void);
347   m64p_error (*VidExtFuncResizeWindow)(int, int);
348 } m64p_video_extension_functions;
349
350 #endif /* define M64P_TYPES_H */
351