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 #ifndef M64P_TYPES_H
24 #define M64P_TYPES_H
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 
29 /* ----------------------------------------- */
30 /* Platform-specific stuff                   */
31 /* ----------------------------------------- */
32 
33 /* necessary headers */
34 #if defined(WIN32)
35   #include <windows.h>
36 #endif
37 
38 /* DLL handles and function declaration specifiers */
39 #define IMPORT
40 #define EXPORT
41 #define CALL
42 typedef void * m64p_dynlib_handle;
43 
44 /* ----------------------------------------- */
45 /* Structures and Types for Core library API */
46 /* ----------------------------------------- */
47 
48 typedef void * m64p_handle;
49 
50 typedef void (*m64p_frame_callback)(unsigned int FrameIndex);
51 typedef void (*m64p_input_callback)(void);
52 typedef void (*m64p_audio_callback)(void);
53 typedef void (*m64p_vi_callback)(void);
54 
55 typedef enum
56 {
57    M64TYPE_INT = 1,
58    M64TYPE_FLOAT,
59    M64TYPE_BOOL,
60    M64TYPE_STRING
61 } m64p_type;
62 
63 typedef enum
64 {
65    M64MSG_ERROR = 1,
66    M64MSG_WARNING,
67    M64MSG_INFO,
68    M64MSG_STATUS,
69    M64MSG_VERBOSE
70 } m64p_msg_level;
71 
72 typedef enum
73 {
74    M64ERR_SUCCESS = 0,
75    M64ERR_NOT_INIT,        /* Function is disallowed before InitMupen64Plus() is called */
76    M64ERR_ALREADY_INIT,    /* InitMupen64Plus() was called twice */
77    M64ERR_INCOMPATIBLE,    /* API versions between components are incompatible */
78    M64ERR_INPUT_ASSERT,    /* Invalid parameters for function call, such as ParamValue=NULL for GetCoreParameter() */
79    M64ERR_INPUT_INVALID,   /* Invalid input data, such as ParamValue="maybe" for SetCoreParameter() to set a BOOL-type value */
80    M64ERR_INPUT_NOT_FOUND, /* The input parameter(s) specified a particular item which was not found */
81    M64ERR_NO_MEMORY,       /* Memory allocation failed */
82    M64ERR_FILES,           /* Error opening, creating, reading, or writing to a file */
83    M64ERR_INTERNAL,        /* Internal error (bug) */
84    M64ERR_INVALID_STATE,   /* Current program state does not allow operation */
85    M64ERR_PLUGIN_FAIL,     /* A plugin function returned a fatal error */
86    M64ERR_SYSTEM_FAIL,     /* A system function call, such as an SDL or file operation, failed */
87    M64ERR_UNSUPPORTED,     /* Function call is not supported (ie, core not built with debugger) */
88    M64ERR_WRONG_TYPE       /* A given input type parameter cannot be used for desired operation */
89 } m64p_error;
90 
91 typedef enum
92 {
93    M64CAPS_DYNAREC = 1,
94    M64CAPS_DEBUGGER = 2,
95    M64CAPS_CORE_COMPARE = 4
96 } m64p_core_caps;
97 
98 typedef enum
99 {
100    M64PLUGIN_NULL = 0,
101    M64PLUGIN_RSP = 1,
102    M64PLUGIN_GFX,
103    M64PLUGIN_AUDIO,
104    M64PLUGIN_INPUT,
105    M64PLUGIN_CORE
106 } m64p_plugin_type;
107 
108 typedef enum
109 {
110    M64EMU_STOPPED = 1,
111    M64EMU_RUNNING,
112    M64EMU_PAUSED
113 } m64p_emu_state;
114 
115 typedef enum
116 {
117    M64VIDEO_NONE = 1,
118    M64VIDEO_WINDOWED,
119    M64VIDEO_FULLSCREEN
120 } m64p_video_mode;
121 
122 typedef enum
123 {
124    M64VIDEOFLAG_SUPPORT_RESIZING = 1
125 } m64p_video_flags;
126 
127 typedef enum
128 {
129    M64CORE_EMU_STATE = 1,
130    M64CORE_VIDEO_SIZE,
131    M64CORE_INPUT_GAMESHARK,
132    M64CORE_STATE_LOADCOMPLETE,
133    M64CORE_STATE_SAVECOMPLETE
134 } m64p_core_param;
135 
136 typedef enum {
137    M64CMD_NOP = 0,
138    M64CMD_ROM_OPEN,
139    M64CMD_ROM_CLOSE,
140    M64CMD_ROM_GET_HEADER,
141    M64CMD_ROM_GET_SETTINGS,
142    M64CMD_EXECUTE,
143    M64CMD_STOP,
144    M64CMD_PAUSE,
145    M64CMD_RESUME,
146    M64CMD_CORE_STATE_QUERY,
147    M64CMD_SET_FRAME_CALLBACK,
148    M64CMD_CORE_STATE_SET,
149    M64CMD_READ_SCREEN,
150    M64CMD_RESET,
151    M64CMD_ADVANCE_FRAME,
152    M64CMD_DDROM_OPEN,
153    M64CMD_DISK_OPEN,
154    M64CMD_DISK_CLOSE
155 } m64p_command;
156 
157 typedef struct
158 {
159    uint32_t     address;
160    int          value;
161 } m64p_cheat_code;
162 
163 /* ----------------------------------------- */
164 /* Structures to hold ROM image information  */
165 /* ----------------------------------------- */
166 
167 typedef enum
168 {
169    SYSTEM_NTSC = 0,
170    SYSTEM_PAL,
171    SYSTEM_MPAL
172 } m64p_system_type;
173 
174 typedef struct
175 {
176    uint8_t init_PI_BSB_DOM1_LAT_REG;  /* 0x00 */
177    uint8_t init_PI_BSB_DOM1_PGS_REG;  /* 0x01 */
178    uint8_t init_PI_BSB_DOM1_PWD_REG;  /* 0x02 */
179    uint8_t init_PI_BSB_DOM1_PGS_REG2; /* 0x03 */
180    uint32_t     ClockRate;                  /* 0x04 */
181    uint32_t     PC;                         /* 0x08 */
182    uint32_t     Release;                    /* 0x0C */
183    uint32_t     CRC1;                       /* 0x10 */
184    uint32_t     CRC2;                       /* 0x14 */
185    uint32_t     Unknown[2];                 /* 0x18 */
186    uint8_t       Name[20];                  /* 0x20 to 0x33 */
187    uint32_t unknown;
188    uint32_t     Manufacturer_ID;            /* 0x3B */
189    uint16_t       Cartridge_ID;             /* 0x3C to 0x3D  */
190    char destination_code;                    /* 0x3E */
191    unsigned char mask_ROM_version;           /* 0x3F */
192 } m64p_rom_header;
193 
194 typedef struct
195 {
196    char goodname[256];
197    char MD5[33];
198    unsigned char savetype;
199    unsigned char status;  /* Rom status on a scale from 0-5. */
200    unsigned char players; /* Local players 0-4, 2/3/4 way Netplay indicated by 5/6/7. */
201    unsigned char rumble;  /* 0 - No, 1 - Yes boolean for rumble support. */
202    unsigned int sidmaduration;
203 } m64p_rom_settings;
204 
205 /* ----------------------------------------- */
206 /* Structures and Types for the Debugger     */
207 /* ----------------------------------------- */
208 
209 typedef enum
210 {
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 {
220    M64P_DBG_RUNSTATE_PAUSED = 0,
221    M64P_DBG_RUNSTATE_STEPPING,
222    M64P_DBG_RUNSTATE_RUNNING
223 } m64p_dbg_runstate;
224 
225 typedef enum
226 {
227    M64P_DBG_MEM_TYPE = 1,
228    M64P_DBG_MEM_FLAGS,
229    M64P_DBG_MEM_HAS_RECOMPILED,
230    M64P_DBG_MEM_NUM_RECOMPILED,
231    M64P_DBG_RECOMP_OPCODE = 16,
232    M64P_DBG_RECOMP_ARGS,
233    M64P_DBG_RECOMP_ADDR
234 } m64p_dbg_mem_info;
235 
236 typedef enum {
237    M64P_MEM_NOMEM = 0,
238    M64P_MEM_NOTHING,
239    M64P_MEM_RDRAM,
240    M64P_MEM_RDRAMREG,
241    M64P_MEM_RSPMEM,
242    M64P_MEM_RSPREG,
243    M64P_MEM_RSP,
244    M64P_MEM_DP,
245    M64P_MEM_DPS,
246    M64P_MEM_VI,
247    M64P_MEM_AI,
248    M64P_MEM_PI,
249    M64P_MEM_RI,
250    M64P_MEM_SI,
251    M64P_MEM_FLASHRAMSTAT,
252    M64P_MEM_ROM,
253    M64P_MEM_PIF,
254    M64P_MEM_MI,
255    M64P_MEM_BREAKPOINT,
256    M64P_MEM_DD
257 } m64p_dbg_mem_type;
258 
259 typedef enum
260 {
261    M64P_MEM_FLAG_READABLE = 0x01,
262    M64P_MEM_FLAG_WRITABLE = 0x02,
263    M64P_MEM_FLAG_READABLE_EMUONLY = 0x04,  /* the EMUONLY flags signify that emulated code can read/write here, but debugger cannot */
264    M64P_MEM_FLAG_WRITABLE_EMUONLY = 0x08
265 } m64p_dbg_mem_flags;
266 
267 typedef enum {
268    M64P_DBG_PTR_RDRAM = 1,
269    M64P_DBG_PTR_PI_REG,
270    M64P_DBG_PTR_SI_REG,
271    M64P_DBG_PTR_VI_REG,
272    M64P_DBG_PTR_RI_REG,
273    M64P_DBG_PTR_AI_REG
274 } m64p_dbg_memptr_type;
275 
276 typedef enum {
277    M64P_CPU_PC = 1,
278    M64P_CPU_REG_REG,
279    M64P_CPU_REG_HI,
280    M64P_CPU_REG_LO,
281    M64P_CPU_REG_COP0,
282    M64P_CPU_REG_COP1_DOUBLE_PTR,
283    M64P_CPU_REG_COP1_SIMPLE_PTR,
284    M64P_CPU_REG_COP1_FGR_64,
285    M64P_CPU_TLB
286 } m64p_dbg_cpu_data;
287 
288 typedef enum {
289    M64P_BKP_CMD_ADD_ADDR = 1,
290    M64P_BKP_CMD_ADD_STRUCT,
291    M64P_BKP_CMD_REPLACE,
292    M64P_BKP_CMD_REMOVE_ADDR,
293    M64P_BKP_CMD_REMOVE_IDX,
294    M64P_BKP_CMD_ENABLE,
295    M64P_BKP_CMD_DISABLE,
296    M64P_BKP_CMD_CHECK
297 } m64p_dbg_bkp_command;
298 
299 #define M64P_MEM_INVALID        0xFFFFFFFF  /* invalid memory read will return this */
300 
301 #define BREAKPOINTS_MAX_NUMBER  128
302 
303 typedef enum
304 {
305   M64P_BKP_FLAG_ENABLED = 0x01,
306   M64P_BKP_FLAG_READ = 0x02,
307   M64P_BKP_FLAG_WRITE = 0x04,
308   M64P_BKP_FLAG_EXEC = 0x08,
309   M64P_BKP_FLAG_LOG = 0x10 /* Log to the console when this breakpoint hits */
310 } m64p_dbg_bkp_flags;
311 
312 #define BPT_CHECK_FLAG(a, b)  ((a.flags & b) == b)
313 #define BPT_SET_FLAG(a, b)    a.flags = (a.flags | b);
314 #define BPT_CLEAR_FLAG(a, b)  a.flags = (a.flags & (~b));
315 #define BPT_TOGGLE_FLAG(a, b) a.flags = (a.flags ^ b);
316 
317 typedef struct
318 {
319    uint32_t address;
320    uint32_t endaddr;
321    unsigned int flags;
322 } m64p_breakpoint;
323 
324 /* ------------------------------------------------- */
325 /* Structures and Types for Core Video Extension API */
326 /* ------------------------------------------------- */
327 
328 typedef struct {
329    unsigned int uiWidth;
330    unsigned int uiHeight;
331 } m64p_2d_size;
332 
333 typedef enum {
334    M64P_GL_DOUBLEBUFFER = 1,
335    M64P_GL_BUFFER_SIZE,
336    M64P_GL_DEPTH_SIZE,
337    M64P_GL_RED_SIZE,
338    M64P_GL_GREEN_SIZE,
339    M64P_GL_BLUE_SIZE,
340    M64P_GL_ALPHA_SIZE,
341    M64P_GL_SWAP_CONTROL,
342    M64P_GL_MULTISAMPLEBUFFERS,
343    M64P_GL_MULTISAMPLESAMPLES,
344    M64P_GL_CONTEXT_MAJOR_VERSION,
345    M64P_GL_CONTEXT_MINOR_VERSION,
346    M64P_GL_CONTEXT_PROFILE_MASK,
347 } m64p_GLattr;
348 
349 
350 typedef enum
351 {
352   M64P_GL_CONTEXT_PROFILE_CORE,
353   M64P_GL_CONTEXT_PROFILE_COMPATIBILITY,
354   M64P_GL_CONTEXT_PROFILE_ES
355 } m64p_GLContextType;
356 
357 typedef struct
358 {
359    unsigned int Functions;
360    m64p_error (*VidExtFuncInit)(void);
361    m64p_error (*VidExtFuncQuit)(void);
362    m64p_error (*VidExtFuncListModes)(m64p_2d_size *, int *);
363    m64p_error (*VidExtFuncSetMode)(int, int, int, int, int);
364    void *     (*VidExtFuncGLGetProc)(const char*);
365    m64p_error (*VidExtFuncGLSetAttr)(m64p_GLattr, int);
366    m64p_error (*VidExtFuncGLGetAttr)(m64p_GLattr, int *);
367    m64p_error (*VidExtFuncGLSwapBuf)(void);
368    m64p_error (*VidExtFuncSetCaption)(const char *);
369    m64p_error (*VidExtFuncToggleFS)(void);
370    m64p_error (*VidExtFuncResizeWindow)(int, int);
371 } m64p_video_extension_functions;
372 
373 /* ------------------------------------------ */
374 /* Structures and Types for Audio Backend API */
375 /* ------------------------------------------ */
376 /* Audio backend object
377  *
378  * user_data is a pointer which will ba passed as the first argument of audio backend functions.
379  * Frontend writers are free to use it as they please.
380  *
381  * set_audio_format function allow the audio backend to be notified of the format of incoming samples.
382  * 2nd parameter frequency is the sample rate of incoming samples.
383  * 3rd parameter bits is the sample resolution (usually 16 bits)
384  *
385  * This function should be called by the core at least one time before any call to "push_audio_samples".
386  * Audio backends are expected to handle gracefully eventual changes of audio format
387  * even after this"initial" setup. Though in practice, very few game, if any,
388  * changes the audio format after the initial setup.
389  *
390  * push_audio_samples function notify the audio backend of new samples ready to be played.
391  * 2nd parameter buffer is a pointer to the beginning of the incoming samples.
392  * 3rd parameter size is the size in bytes of the buffer.
393  *
394  * Samples are in stereo interleaved format (LR LR LR ...) and their resolution (bits per channel)
395  * is specified by prior calls of set_audio_format.
396  * Audio backends are expected not to block during the servicing of this function.
397  * We invite audio backends writers to buffer (and maybe resample) the incoming samples
398  * and return control to the core as soon as possible.
399  */
400 
401 struct m64p_audio_backend
402 {
403    void* user_data;
404    void (*set_audio_format)(void*, unsigned int, unsigned int);
405    void (*push_audio_samples)(void*, const void*, size_t);
406 };
407 
408 #endif /* define M64P_TYPES_H */
409 
410