1 module m64p_types;
2 
3 import dynalib : expandEnum;
4 
5 alias m64p_dynlib_handle = void*;
6 alias m64p_handle = void*;
7 
8 /* ----------------------------------------- */
9 /* Structures and Types for Core library API */
10 /* ----------------------------------------- */
11 
12 alias m64p_function       = void function();
13 alias m64p_frame_callback = void function(uint FrameIndex);
14 alias m64p_input_callback = void function();
15 alias m64p_audio_callback = void function();
16 alias m64p_vi_callback    = void function();
17 
18 enum m64p_type
19 {
20   M64TYPE_INT = 1,
21   M64TYPE_FLOAT,
22   M64TYPE_BOOL,
23   M64TYPE_STRING
24 } mixin(expandEnum!m64p_type);
25 
26 enum m64p_msg_level
27 {
28   M64MSG_ERROR = 1,
29   M64MSG_WARNING,
30   M64MSG_INFO,
31   M64MSG_STATUS,
32   M64MSG_VERBOSE
33 } mixin(expandEnum!m64p_msg_level);
34 
35 enum m64p_error
36 {
37   M64ERR_SUCCESS = 0,
38   M64ERR_NOT_INIT,        /* Function is disallowed before InitMupen64Plus() is called */
39   M64ERR_ALREADY_INIT,    /* InitMupen64Plus() was called twice */
40   M64ERR_INCOMPATIBLE,    /* API versions between components are incompatible */
41   M64ERR_INPUT_ASSERT,    /* Invalid parameters for function call, such as ParamValue=NULL for GetCoreParameter() */
42   M64ERR_INPUT_INVALID,   /* Invalid input data, such as ParamValue="maybe" for SetCoreParameter() to set a BOOL-type value */
43   M64ERR_INPUT_NOT_FOUND, /* The input parameter(s) specified a particular item which was not found */
44   M64ERR_NO_MEMORY,       /* Memory allocation failed */
45   M64ERR_FILES,           /* Error opening, creating, reading, or writing to a file */
46   M64ERR_INTERNAL,        /* Internal error (bug) */
47   M64ERR_INVALID_STATE,   /* Current program state does not allow operation */
48   M64ERR_PLUGIN_FAIL,     /* A plugin function returned a fatal error */
49   M64ERR_SYSTEM_FAIL,     /* A system function call, such as an SDL or file operation, failed */
50   M64ERR_UNSUPPORTED,     /* Function call is not supported (ie, core not built with debugger) */
51   M64ERR_WRONG_TYPE       /* A given input type parameter cannot be used for desired operation */
52 } mixin(expandEnum!m64p_error);
53 
54 enum m64p_core_caps
55 {
56   M64CAPS_DYNAREC = 1,
57   M64CAPS_DEBUGGER = 2,
58   M64CAPS_CORE_COMPARE = 4
59 } mixin(expandEnum!m64p_core_caps);
60 
61 enum m64p_plugin_type
62 {
63   M64PLUGIN_NULL = 0,
64   M64PLUGIN_RSP = 1,
65   M64PLUGIN_GFX,
66   M64PLUGIN_AUDIO,
67   M64PLUGIN_INPUT,
68   M64PLUGIN_CORE
69 } mixin(expandEnum!m64p_plugin_type);
70 
71 enum m64p_emu_state
72 {
73   M64EMU_STOPPED = 1,
74   M64EMU_RUNNING,
75   M64EMU_PAUSED
76 } mixin(expandEnum!m64p_emu_state);
77 
78 enum m64p_video_mode
79 {
80   M64VIDEO_NONE = 1,
81   M64VIDEO_WINDOWED,
82   M64VIDEO_FULLSCREEN
83 } mixin(expandEnum!m64p_video_mode);
84 
85 enum m64p_video_flags
86 {
87   M64VIDEOFLAG_SUPPORT_RESIZING = 1
88 } mixin(expandEnum!m64p_video_flags);
89 
90 enum m64p_core_param
91 {
92   M64CORE_EMU_STATE = 1,
93   M64CORE_VIDEO_MODE,
94   M64CORE_SAVESTATE_SLOT,
95   M64CORE_SPEED_FACTOR,
96   M64CORE_SPEED_LIMITER,
97   M64CORE_VIDEO_SIZE,
98   M64CORE_AUDIO_VOLUME,
99   M64CORE_AUDIO_MUTE,
100   M64CORE_INPUT_GAMESHARK,
101   M64CORE_STATE_LOADCOMPLETE,
102   M64CORE_STATE_SAVECOMPLETE
103 } mixin(expandEnum!m64p_core_param);
104 
105 enum m64p_command
106 {
107   M64CMD_NOP = 0,
108   M64CMD_ROM_OPEN,
109   M64CMD_ROM_CLOSE,
110   M64CMD_ROM_GET_HEADER,
111   M64CMD_ROM_GET_SETTINGS,
112   M64CMD_EXECUTE,
113   M64CMD_STOP,
114   M64CMD_PAUSE,
115   M64CMD_RESUME,
116   M64CMD_CORE_STATE_QUERY,
117   M64CMD_STATE_LOAD,
118   M64CMD_STATE_SAVE,
119   M64CMD_STATE_SET_SLOT,
120   M64CMD_SEND_SDL_KEYDOWN,
121   M64CMD_SEND_SDL_KEYUP,
122   M64CMD_SET_FRAME_CALLBACK,
123   M64CMD_TAKE_NEXT_SCREENSHOT,
124   M64CMD_CORE_STATE_SET,
125   M64CMD_READ_SCREEN,
126   M64CMD_RESET,
127   M64CMD_ADVANCE_FRAME,
128   M64CMD_SET_MEDIA_LOADER,
129   M64CMD_NETPLAY_INIT,
130   M64CMD_NETPLAY_CONTROL_PLAYER,
131   M64CMD_NETPLAY_GET_VERSION,
132   M64CMD_NETPLAY_CLOSE,
133   M64CMD_PIF_OPEN,
134   M64CMD_ROM_SET_SETTINGS
135 } mixin(expandEnum!m64p_command);
136 
137 struct m64p_cheat_code
138 {
139   uint address;
140   int  value;
141 }
142 
143 struct m64p_media_loader
144 {
145   @nogc nothrow __gshared extern(C):
146     /* Frontend-defined callback data. */
147     void* cb_data;
148 
149     /* Allow the frontend to specify the GB cart ROM file to load
150     * cb_data: points to frontend-defined callback data.
151     * controller_num: (0-3) tell the frontend which controller is about to load a GB cart
152     * Returns a NULL-terminated string owned by the core specifying the GB cart ROM filename to load.
153     * Empty or NULL string results in no GB cart being loaded (eg. empty transferpak).
154     */
155     char* function(void* cb_data, int controller_num) get_gb_cart_rom;
156 
157     /* Allow the frontend to specify the GB cart RAM file to load
158     * cb_data: points to frontend-defined callback data.
159     * controller_num: (0-3) tell the frontend which controller is about to load a GB cart
160     * Returns a NULL-terminated string owned by the core specifying the GB cart RAM filename to load
161     * Empty or NULL string results in the core generating a default save file with empty content.
162     */
163     char* function(void* cb_data, int controller_num) get_gb_cart_ram;
164 
165     /* Allow the frontend to specify the DD IPL ROM file to load
166     * cb_data: points to frontend-defined callback data.
167     * Returns a NULL-terminated string owned by the core specifying the DD IPL ROM filename to load
168     * Empty or NULL string results in disabled 64DD.
169     */
170     char* function(void* cb_data) get_dd_rom;
171 
172     /* Allow the frontend to specify the DD disk file to load
173     * cb_data: points to frontend-defined callback data.
174     * Returns a NULL-terminated string owned by the core specifying the DD disk filename to load
175     * Empty or NULL string results in no DD disk being loaded (eg. empty disk drive).
176     */
177     char* function(void* cb_data) get_dd_disk;
178 }
179 
180 /* ----------------------------------------- */
181 /* Structures to hold ROM image information  */
182 /* ----------------------------------------- */
183 
184 enum m64p_system_type
185 {
186     SYSTEM_NTSC = 0,
187     SYSTEM_PAL,
188     SYSTEM_MPAL
189 } mixin(expandEnum!m64p_system_type);
190 
191 enum m64p_rom_save_type
192 {
193     SAVETYPE_EEPROM_4KB = 0,
194     SAVETYPE_EEPROM_16KB,
195     SAVETYPE_SRAM,
196     SAVETYPE_FLASH_RAM,
197     SAVETYPE_CONTROLLER_PACK,
198     SAVETYPE_NONE
199 } mixin(expandEnum!m64p_rom_save_type);
200 
201 struct m64p_rom_header
202 {
203    ubyte     init_PI_BSB_DOM1_LAT_REG;  /* 0x00 */
204    ubyte     init_PI_BSB_DOM1_PGS_REG;  /* 0x01 */
205    ubyte     init_PI_BSB_DOM1_PWD_REG;  /* 0x02 */
206    ubyte     init_PI_BSB_DOM1_PGS_REG2; /* 0x03 */
207    uint      ClockRate;                 /* 0x04 */
208    uint      PC;                        /* 0x08 */
209    uint      Release;                   /* 0x0C */
210    uint      CRC1;                      /* 0x10 */
211    uint      CRC2;                      /* 0x14 */
212    uint[2]   Unknown;                   /* 0x18 */
213    ubyte[20] Name;                      /* 0x20 */
214    uint      unknown;                   /* 0x34 */
215    uint      Manufacturer_ID;           /* 0x38 */
216    ushort    Cartridge_ID;              /* 0x3C - Game serial number  */
217    ushort    Country_code;              /* 0x3E */
218 }
219 
220 struct m64p_rom_settings
221 {
222    char[256] goodname;
223    char[33] MD5;
224    ubyte savetype;
225    ubyte status;          /* Rom status on a scale from 0-5. */
226    ubyte players;         /* Local players 0-4, 2/3/4 way Netplay indicated by 5/6/7. */
227    ubyte rumble;          /* 0 - No, 1 - Yes boolean for rumble support. */
228    ubyte transferpak;     /* 0 - No, 1 - Yes boolean for transfer pak support. */
229    ubyte mempak;          /* 0 - No, 1 - Yes boolean for memory pak support. */
230    ubyte biopak;          /* 0 - No, 1 - Yes boolean for bio pak support. */
231    ubyte disableextramem; /* 0 - No, 1 - Yes boolean for disabling 4MB expansion RAM pack */
232    uint countperop;       /* Number of CPU cycles per instruction. */
233    uint sidmaduration;    /* Default SI DMA duration */
234 }
235 
236 /* ----------------------------------------- */
237 /* Structures and Types for the Debugger     */
238 /* ----------------------------------------- */
239 
240 enum m64p_dbg_state
241 {
242   M64P_DBG_RUN_STATE = 1,
243   M64P_DBG_PREVIOUS_PC,
244   M64P_DBG_NUM_BREAKPOINTS,
245   M64P_DBG_CPU_DYNACORE,
246   M64P_DBG_CPU_NEXT_INTERRUPT
247 } mixin(expandEnum!m64p_dbg_state);
248 
249 enum m64p_dbg_runstate
250 {
251   M64P_DBG_RUNSTATE_PAUSED = 0,
252   M64P_DBG_RUNSTATE_STEPPING,
253   M64P_DBG_RUNSTATE_RUNNING
254 } mixin(expandEnum!m64p_dbg_runstate);
255 
256 enum m64p_dbg_mem_info
257 {
258   M64P_DBG_MEM_TYPE = 1,
259   M64P_DBG_MEM_FLAGS,
260   M64P_DBG_MEM_HAS_RECOMPILED,
261   M64P_DBG_MEM_NUM_RECOMPILED,
262   M64P_DBG_RECOMP_OPCODE = 16,
263   M64P_DBG_RECOMP_ARGS,
264   M64P_DBG_RECOMP_ADDR
265 } mixin(expandEnum!m64p_dbg_mem_info);
266 
267 enum m64p_dbg_mem_type
268 {
269   M64P_MEM_NOMEM = 0,
270   M64P_MEM_NOTHING,
271   M64P_MEM_RDRAM,
272   M64P_MEM_RDRAMREG,
273   M64P_MEM_RSPMEM,
274   M64P_MEM_RSPREG,
275   M64P_MEM_RSP,
276   M64P_MEM_DP,
277   M64P_MEM_DPS,
278   M64P_MEM_VI,
279   M64P_MEM_AI,
280   M64P_MEM_PI,
281   M64P_MEM_RI,
282   M64P_MEM_SI,
283   M64P_MEM_FLASHRAMSTAT,
284   M64P_MEM_ROM,
285   M64P_MEM_PIF,
286   M64P_MEM_MI,
287   M64P_MEM_BREAKPOINT
288 } mixin(expandEnum!m64p_dbg_mem_type);
289 
290 enum m64p_dbg_mem_flags
291 {
292   M64P_MEM_FLAG_READABLE = 0x01,
293   M64P_MEM_FLAG_WRITABLE = 0x02,
294   M64P_MEM_FLAG_READABLE_EMUONLY = 0x04,  /* the EMUONLY flags signify that emulated code can read/write here, but debugger cannot */
295   M64P_MEM_FLAG_WRITABLE_EMUONLY = 0x08
296 } mixin(expandEnum!m64p_dbg_mem_flags);
297 
298 enum m64p_dbg_memptr_type
299 {
300   M64P_DBG_PTR_RDRAM = 1,
301   M64P_DBG_PTR_PI_REG,
302   M64P_DBG_PTR_SI_REG,
303   M64P_DBG_PTR_VI_REG,
304   M64P_DBG_PTR_RI_REG,
305   M64P_DBG_PTR_AI_REG
306 } mixin(expandEnum!m64p_dbg_memptr_type);
307 
308 enum m64p_dbg_cpu_data
309 {
310   M64P_CPU_PC = 1,
311   M64P_CPU_REG_REG,
312   M64P_CPU_REG_HI,
313   M64P_CPU_REG_LO,
314   M64P_CPU_REG_COP0,
315   M64P_CPU_REG_COP1_DOUBLE_PTR,
316   M64P_CPU_REG_COP1_SIMPLE_PTR,
317   M64P_CPU_REG_COP1_FGR_64,
318   M64P_CPU_TLB
319 } mixin(expandEnum!m64p_dbg_cpu_data);
320 
321 enum m64p_dbg_bkp_command
322 {
323   M64P_BKP_CMD_ADD_ADDR = 1,
324   M64P_BKP_CMD_ADD_STRUCT,
325   M64P_BKP_CMD_REPLACE,
326   M64P_BKP_CMD_REMOVE_ADDR,
327   M64P_BKP_CMD_REMOVE_IDX,
328   M64P_BKP_CMD_ENABLE,
329   M64P_BKP_CMD_DISABLE,
330   M64P_BKP_CMD_CHECK
331 } mixin(expandEnum!m64p_dbg_bkp_command);
332 
333 enum M64P_MEM_INVALID       = 0xFFFFFFFF;  /* invalid memory read will return this */
334 
335 enum BREAKPOINTS_MAX_NUMBER = 128;
336 
337 enum m64p_dbg_bkp_flags
338 {
339   M64P_BKP_FLAG_ENABLED = 0x01,
340   M64P_BKP_FLAG_READ = 0x02,
341   M64P_BKP_FLAG_WRITE = 0x04,
342   M64P_BKP_FLAG_EXEC = 0x08,
343   M64P_BKP_FLAG_LOG = 0x10 /* Log to the console when this breakpoint hits */
344 } mixin(expandEnum!m64p_dbg_bkp_flags);
345 
346 import std.traits : isNumeric;
347 bool BPT_CHECK_FLAG(T)(ref m64p_breakpoint a, T b) if (isNumeric!T) { return (a.flags & b) == b; }
348 void BPT_SET_FLAG(T)(ref m64p_breakpoint a, T b) if (isNumeric!T) { a.flags = (a.flags | b); }
349 void BPT_CLEAR_FLAG(T)(ref m64p_breakpoint a, T b) if (isNumeric!T) { a.flags = (a.flags & (~b)); }
350 void BPT_TOGGLE_FLAG(T)(ref m64p_breakpoint a, T b) if (isNumeric!T) { a.flags = (a.flags ^ b); }
351 
352 struct m64p_breakpoint
353 {
354   uint address;
355   uint endaddr;
356   uint flags;
357 }
358 
359 /* ------------------------------------------------- */
360 /* Structures and Types for Core Video Extension API */
361 /* ------------------------------------------------- */
362 
363 struct m64p_2d_size
364 {
365   uint uiWidth;
366   uint uiHeight;
367 }
368 
369 enum m64p_GLattr
370 {
371   M64P_GL_DOUBLEBUFFER = 1,
372   M64P_GL_BUFFER_SIZE,
373   M64P_GL_DEPTH_SIZE,
374   M64P_GL_RED_SIZE,
375   M64P_GL_GREEN_SIZE,
376   M64P_GL_BLUE_SIZE,
377   M64P_GL_ALPHA_SIZE,
378   M64P_GL_SWAP_CONTROL,
379   M64P_GL_MULTISAMPLEBUFFERS,
380   M64P_GL_MULTISAMPLESAMPLES,
381   M64P_GL_CONTEXT_MAJOR_VERSION,
382   M64P_GL_CONTEXT_MINOR_VERSION,
383   M64P_GL_CONTEXT_PROFILE_MASK
384 } mixin(expandEnum!m64p_GLattr);
385 
386 enum m64p_GLContextType
387 {
388   M64P_GL_CONTEXT_PROFILE_CORE,
389   M64P_GL_CONTEXT_PROFILE_COMPATIBILITY,
390   M64P_GL_CONTEXT_PROFILE_ES
391 } mixin(expandEnum!m64p_GLContextType);
392 
393 struct m64p_video_extension_functions
394 {
395   @nogc nothrow __gshared extern(C):
396     uint          Functions;
397     m64p_error    function() VidExtFuncInit;
398     m64p_error    function() VidExtFuncQuit;
399     m64p_error    function(m64p_2d_size*, int*) VidExtFuncListModes;
400     m64p_error    function(m64p_2d_size, int*, int*) VidExtFuncListRates;
401     m64p_error    function(int, int, int, int, int) VidExtFuncSetMode;
402     m64p_error    function(int, int, int, int, int, int) VidExtFuncSetModeWithRate;
403     m64p_function function(const char*) VidExtFuncGLGetProc;
404     m64p_error    function(m64p_GLattr, int) VidExtFuncGLSetAttr;
405     m64p_error    function(m64p_GLattr, int*) VidExtFuncGLGetAttr;
406     m64p_error    function() VidExtFuncGLSwapBuf;
407     m64p_error    function(const char*) VidExtFuncSetCaption;
408     m64p_error    function() VidExtFuncToggleFS;
409     m64p_error    function(int, int) VidExtFuncResizeWindow;
410     uint          function() VidExtFuncGLGetDefaultFramebuffer;
411 }