Core commit. Compile and run on the OpenPandora
[mupen64plus-pandora.git] / source / mupen64plus-core / doc / emuwiki-api-doc / Mupen64Plus_v2.0_Core_Front-End.txt
1 [[Mupen64Plus v2.0 Core API v1.0|Mupen64Plus v2.0 API]]
2
3 = Mupen64Plus v2.0 Core<-->Front-End API =
4
5 Most libmupen64plus functions return an <tt>m64p_error</tt> return code, which is an enumerated type defined in [[Mupen64Plus v2.0 headers#m64p_types.h|m64p_types.h]].  Front-end code should check the return value of each call to a libmupen64plus function.
6
7 == Startup/Shutdown Functions ==
8 {| border="1"
9 |Prototype
10 |'''<tt>m64p_error CoreStartup(int APIVersion, const char *ConfigPath, const char *DataPath, void *Context, void (*DebugCallback)(void *Context, int level, const char *message), void *Context2, void (*StateCallback)(void *Context2, m64p_core_param ParamChanged, int NewValue))</tt>'''
11 |-
12 |Input Parameters
13 |'''<tt>APIVersion</tt>''' Integer containing the version number of the Core API used by the front-end.<br />
14 '''<tt>ConfigPath</tt>''' File path to folder containing Mupen64Plus.cfg.  Can be NULL.<br />
15 '''<tt>DataPath</tt>''' Folder to search first when looking for shared data files.  Can be NULL.<br />
16 '''<tt>Context</tt>''' Pointer which will be passed back to the '''<tt>DebugCallback</tt>''' function.  Can be NULL.<br />
17 '''<tt>DebugCallback</tt>''' Pointer to function in front-end for receiving debug information and warnings from the core.  This function must be thread-safe.  Can be NULL.  The value of <tt>level</tt> is 1 for an error, 2 for a warning, 3 for info, and 4 for verbose info.<br />
18 '''<tt>Context2</tt>''' Pointer which will be passed back to the '''<tt>StateCallback</tt>''' function.  Can be NULL.<br />
19 '''<tt>StateCallback</tt>''' Pointer to function in front-end for receiving core state change notifications.  This function must be thread-safe.  Can be NULL.
20 |-
21 |Requirements
22 |This function must be called before any other libmupen64plus functions.
23 |-
24 |Usage
25 |This function initializes libmupen64plus for use by allocating memory, creating data structures, and loading the configuration file.  If '''<tt>ConfigPath</tt>''' is NULL, libmupen64plus will search for the configuration file in its usual place (On Linux, in <tt>~/.config/mupen64plus/</tt>).  This function may return <tt>M64ERR_INCOMPATIBLE</tt> if older front-end is used with newer core.
26 |}
27 <br />
28 {| border="1"
29 |Prototype
30 |'''<tt>m64p_error CoreShutdown(void)</tt>'''
31 |-
32 |Input Parameters
33 |N/A
34 |-
35 |Usage
36 |This function saves the configuration file, then destroys data structures and releases memory allocated by the core library.
37 |}
38 <br />
39 {| border="1"
40 |Prototype
41 |'''<tt>m64p_error CoreAttachPlugin(m64p_plugin_type PluginType, m64p_dynlib_handle PluginLibHandle)</tt>'''
42 |-
43 |Input Parameters
44 |'''<tt>PluginType</tt>''' Enumerated type specifying the plugin type to attach to the core.  If this type of plugin is currently attached to the core, an error will be returned.<br />
45 '''<tt>PluginLibHandle</tt>''' Dynamic library handle (defined in [[Mupen64Plus v2.0 headers#m64p_types.h|m64p_types.h]]) corresponding with the plugin object to attach.
46 |-
47 |Requirements
48 |Both the core library and the plugin library must already be initialized with the <tt>CoreStartup()/PluginStartup()</tt> functions, and a ROM must be open.  This function cannot be called while the emulator is running.  The plugins must be attached in the following order: Video, Audio, Input, RSP.
49 |-
50 |Usage
51 |This function attaches the given plugin to the emulator core.  There can only be one plugin of each type attached to the core at any given time.
52 |}
53 <br />
54 {| border="1"
55 |Prototype
56 |'''<tt>m64p_error CoreDetachPlugin(m64p_plugin_type PluginType)</tt>'''
57 |-
58 |Input Parameters
59 |'''<tt>PluginType</tt>''' Enumerated type specifying the plugin type to detach from the core.  If no plugin of this type is currently attached to the core, this function will exit with a return value of <tt>M64ERR_SUCCESS</tt>.
60 |-
61 |Requirements
62 |Both the core library and the plugin library must already be initialized with the <tt>CoreStartup()/PluginStartup()</tt> functions.  This function cannot be called while the emulator is running.
63 |-
64 |Usage
65 |This function detaches the given plugin from the emulator core, and re-attaches the 'dummy' plugin functions.
66 |}
67
68 == Command Functions ==
69 {| border="1"
70 |Prototype
71 |'''<tt>m64p_error CoreDoCommand(m64p_command Command, int ParamInt, void *ParamPtr)</tt>'''
72 |-
73 |Input Parameters
74 |'''<tt>Command</tt>''' Enumerated type specifying which command should be executed.<br />
75 '''<tt>ParamInt</tt>''' An integer value which may be used as an input to the command.<br />
76 '''<tt>ParamPtr</tt>''' A pointer which may be used as an input to the command.<br />
77 |-
78 |Requirements
79 |The core library must already be initialized with the <tt>CoreStartup()</tt> function.  Each command may have its own requirements as well.
80 |-
81 |Usage
82 |This function sends a command to the emulator core.  A table of all commands is given below.
83 |}
84 <br />
85
86 {| border="1"
87 !Command!!Function!!Input Parameters!!Requirements
88 |-
89 |M64CMD_ROM_OPEN
90 |This will cause the core to read in a binary ROM image provided by the front-end.
91 |'''<tt>ParamPtr</tt>''' Pointer to the uncompressed ROM image in memory.<br />'''<tt>ParamInt</tt>''' The size in bytes of the ROM image.
92 |The emulator cannot be currently running.  A ROM image must not be currently opened.
93 |-
94 |M64CMD_ROM_CLOSE
95 |This will close any currently open ROM.  The current cheat code list will also be deleted.
96 |N/A
97 |The emulator cannot be currently running.  A ROM image must have been previously opened.  There should be no plugins currently attached.
98 |-
99 |M64CMD_ROM_GET_HEADER
100 |This will retrieve the header data of the currently open ROM.
101 |'''<tt>ParamPtr</tt>''' Pointer to a <tt>rom_header</tt> struct to receive the data.<br />'''<tt>ParamInt</tt>''' The size in bytes of the <tt>rom_header</tt> struct.
102 |A ROM image must be open.
103 |-
104 |M64CMD_ROM_GET_SETTINGS
105 |This will retrieve the settings data of the currently open ROM.
106 |'''<tt>ParamPtr</tt>''' Pointer to a <tt>rom_settings</tt> struct to receive the data.<br />'''<tt>ParamInt</tt>''' The size in bytes of the <tt>rom_settings</tt> struct.
107 |A ROM image must be open.
108 |-
109 |M64CMD_EXECUTE
110 |This command will start the emulator and begin executing the ROM image.  This function call will not return until the game has been stopped.
111 |N/A
112 |The emulator cannot be currently running.  A ROM image must have been previously opened.
113 |-
114 |M64CMD_STOP
115 |This will stop the emulator, if it is currently running.
116 |N/A
117 |This command will execute asynchronously.
118 |-
119 |M64CMD_PAUSE
120 |This command will pause the emulator if it is running.
121 |N/A
122 |This function will return a non-successful error code if the emulator is in the stopped state.  This command may execute asynchronously.
123 |-
124 |M64CMD_RESUME
125 |This command will resume execution of the emulator if it is paused.
126 |N/A
127 |This function will return a non-successful error code if the emulator is in the stopped state.  This command may execute asynchronously.
128 |-
129 |M64CMD_CORE_STATE_QUERY
130 |This command will query the emulator core for the value of a state parameter
131 |'''<tt>ParamInt</tt>''' An <tt>m64p_core_param</tt> enumerated type specifying the desired state variable'''<br /><tt>ParamPtr</tt>''' Pointer to an integer to receive the value of the requested state variable.
132 |None
133 |-
134 |M64CMD_CORE_STATE_SET
135 |This command will set the value of a state parameter in the emulator core
136 |'''<tt>ParamInt</tt>''' An <tt>m64p_core_param</tt> enumerated type specifying the desired state variable'''<br /><tt>ParamPtr</tt>''' Pointer to an integer to containing the value of the requested state variable.
137 |The initial requirements vary depending upon the variable being set.  Setting some variables requires the emulator to be running.
138 |-
139 |M64CMD_STATE_LOAD
140 |This command will attempt to load a saved state file.  If '''<tt>ParamPtr</tt>''' is not NULL, this function will load a state file from a full pathname specified by this pointer.  Otherwise ('''<tt>ParamPtr</tt>''' is NULL), it will load from the current slot.
141 |'''<tt>ParamInt</tt>''' Ignored'''<br /><tt>ParamPtr</tt>''' Pointer to string containing state file path and name, or NULL
142 |The emulator must be currently running or paused.  This command will execute asynchronously.
143 |-
144 |M64CMD_STATE_SAVE
145 |This command will save a state file.  If '''<tt>ParamPtr</tt>''' is not NULL, this function will save a state file to a full pathname specified by this pointer.  Otherwise ('''<tt>ParamPtr</tt>''' is NULL), it will save to the current slot.
146 |'''<tt>ParamInt</tt>''' This parameter will only be used if '''<tt>ParamPtr</tt>''' is not NULL. If 1, a Mupen64Plus state file will be saved.  If 2, a Project64 compressed state file will be saved. If 3, a Project64 uncompressed state file will be saved. '''<br /><tt>ParamPtr</tt>''' Pointer to string containing state file path and name, or NULL<br />
147 |The emulator must be currently running or paused.  This command will execute asynchronously.
148 |-
149 |M64CMD_STATE_SET_SLOT
150 |This command will set the currently selected save slot index
151 |'''<tt>ParamInt</tt>''' Value to set for the current slot index.  Must be between 0 and 9'''<br /><tt>ParamPtr</tt>''' Ignored<br />
152 |None
153 |-
154 |M64CMD_SEND_SDL_KEYDOWN
155 |This command will inject an SDL_KEYDOWN event into the emulator's core event loop.  Keys not handled by the core will be passed to the input plugin.
156 |'''<tt>ParamInt</tt>''' Key value of the keypress event to inject, with SDLMod in the upper 16 bits and SDLKey in the lower 16 bits.
157 |The emulator must be currently running or paused.
158 |-
159 |M64CMD_SEND_SDL_KEYUP
160 |This command will inject an SDL_KEYUP event into the emulator's core event loop.
161 |'''<tt>ParamInt</tt>''' Key value of the keypress event to inject, with SDLMod in the upper 16 bits and SDLKey in the lower 16 bits.
162 |The emulator must be currently running or paused.
163 |-
164 |M64CMD_SET_FRAME_CALLBACK
165 |This command either registers or removes (if '''<tt>ParamPtr</tt>''' is NULL) a frame callback function.  This function will be called after each video frame is rendered.  The front-end callback function may call the video plugin's ReadScreen2() function to retrieve the frame if desired.
166 |'''<tt>ParamPtr</tt>''' Can be either NULL or a <tt>m64p_frame_callback</tt> object.
167 |None
168 |-
169 |M64CMD_TAKE_NEXT_SCREENSHOT
170 |This will cause the core to save a screenshot at the next possible opportunity.
171 |N/A
172 |The emulator must be currently running or paused.  This command will execute asynchronously.
173 |-
174 |M64CMD_READ_SCREEN
175 |This command will copy the current contents of the video display to the buffer pointer by '''<tt>ParamPtr</tt>'''.
176 |'''<tt>ParamInt</tt>''' 1 to copy the buffer that is currently displayed (front buffer), 0 to copy the buffer that is being drawn (back buffer).'''<br /><tt>ParamPtr</tt>'''A pointer to a buffer of at least width*height*3 bytes. The buffer will be filled with the current display. The format is RGB888 with the origin in the lower left corner.
177 |The emulator must be currently running or paused.
178 |-
179 |M64CMD_RESET
180 |Reset the emulated machine.
181 |'''<tt>ParamInt</tt>''' 0 to do a soft reset, 1 to do a hard reset.'''<br /><tt>ParamPtr</tt>''' Ignored
182 |The emulator must be currently running or paused.
183 |-
184 |M64CMD_ADVANCE_FRAME
185 |Advance one frame (the emulator will run until the next frame, then pause).
186 |'''<tt>ParamInt</tt>''' Ignored'''<br /><tt>ParamPtr</tt>''' Ignored
187 |The emulator must be currently running or paused.
188 |}
189 <br />
190
191
192 == Core State Parameters ==
193 These core parameters may be read and/or written using the M64CMD_CORE_STATE_QUERY and M64CMD_CORE_STATE_SET commands.  The front-end application will receive a callback (via the <tt>StateCallback</tt> function pointer given to the '''<tt>CoreStartup</tt>''' function) when these parameters change value.  This callback will be sent even if the function which caused the state change was called by the front-end application itself.  Not all of these parameters are readable or writable.  Each parameter's value is held in a single 32-bit integer.  The meaning of this integer is given in the Parameter Encoding column. See the table below for details on these core parameters.
194 <br />
195 {| border="1"
196 !Name!!Readable!!Writable!!<tt>int</tt> Parameter Encoding!!Notes
197 |-
198 |M64CORE_EMU_STATE
199 |Yes
200 |Yes
201 |<tt>enum m64p_emu_state</tt>
202 |<tt>1</tt>=Stopped, <tt>2</tt>=Running, <tt>3</tt>=Paused
203 |-
204 |M64CORE_VIDEO_MODE
205 |Yes
206 |Yes
207 |<tt>enum m64p_video_mode</tt>
208 |<tt>1</tt>=None (video not running), <tt>2</tt>=Windowed, <tt>3</tt>=Fullscreen
209 |-
210 |M64CORE_SAVESTATE_SLOT
211 |Yes
212 |Yes
213 |
214 |Valid values are 0 through 9.
215 |-
216 |M64CORE_SPEED_FACTOR
217 |Yes
218 |Yes
219 |Emulator playback speed in percent
220 |Valid values are 1 to 1000.
221 |-
222 |M64CORE_SPEED_LIMITER
223 |Yes
224 |Yes
225 |<tt>1</tt> to enable speed limiter, or <tt>0</tt> to disable speed limiter.
226 |When speed limiter is disabled, emulator will run as fast as possible (useful for benchmarking).
227 |-
228 |M64CORE_VIDEO_SIZE
229 |Yes
230 |Yes
231 |<tt>(ScreenWidth << 16) + ScreenHeight</tt>
232 |This parameter can only be read or written when the emulator is running or paused.  This parameter may be written by the front-end application in response to a window resizing event.  Upon receiving this command, the core will pass the new width and height to the ResizeVideoOutput function in the video plugin (video API v2.2.0).  If the video plugin supports resizing, it will update its viewport and then call the video extension function VidExt_ResizeWindow to update the window manager.
233 |-
234 |M64CORE_AUDIO_VOLUME
235 |Yes
236 |Yes
237 |Volume level in percent, 0 - 100
238 |
239 |-
240 |M64CORE_AUDIO_MUTE
241 |Yes
242 |Yes
243 |<tt>1</tt> if muted, otherwise <tt>0</tt>
244 |
245 |-
246 |M64CORE_INPUT_GAMESHARK
247 |Yes
248 |Yes
249 |<tt>1</tt> when Gameshark button pressed, <tt>0</tt> when button released.
250 |Callback function will be invoked on both button press and release.
251 |-
252 |M64CORE_STATE_LOADCOMPLETE
253 |No
254 |No
255 |<tt>1</tt> if state loading was successful, <tt>0</tt> if state loading failed.
256 |This parameter cannot be read or written.  It is only used for callbacks, because the state load/save operations are asynchronous.
257 |-
258 |M64CORE_STATE_SAVECOMPLETE
259 |No
260 |No
261 |<tt>1</tt> if state saving was successful, <tt>0</tt> if state saving failed.
262 |This parameter cannot be read or written.  It is only used for callbacks, because the state load/save operations are asynchronous.
263 |}
264 <br />
265
266 == ROM Handling Functions ==
267 {| border="1"
268 |Prototype
269 |'''<tt>m64p_error CoreGetRomSettings(m64p_rom_settings *RomSettings, int RomSettingsLength, int Crc1, int Crc2)</tt>'''
270 |-
271 |Input Parameters
272 |'''<tt>RomSettings</tt>''' Pointer to <tt>m64p_rom_settings</tt> object to be filled in with data.<br />
273 '''<tt>RomSettingsLength</tt>''' Size of the object pointed to by '''<tt>RomSettings</tt>''' in bytes.<br />
274 '''<tt>Crc1</tt>''' A 32-bit integer value containing the first CRC (taken from the ROM header) to identify the ROM.<br />
275 '''<tt>Crc2</tt>''' A 32-bit integer value containing the second CRC (taken from the ROM header) to identify the ROM.
276 |-
277 |Requirements
278 |The core library must already be initialized with the <tt>CoreStartup()</tt> function.  The '''<tt>RomSettings</tt>''' pointer must not be NULL.  The '''<tt>RomSettingsLength</tt>''' value must be greater than or equal to the size of the <tt>m64p_rom_settings</tt> structure.  This function does not require any ROM image to be currently open.
279 |-
280 |Usage
281 |This function searches through the data in the <tt>Mupen64Plus.ini</tt> file to find an entry which matches the given '''<tt>Crc1</tt>''' and '''<tt>Crc2</tt>''' hashes, and if found, fills in the '''<tt>RomSettings</tt>''' structure with the data from the <tt>Mupen64Plus.ini</tt> file.
282 |}
283 <br />
284
285 == Video Extension Functions ==
286 {| border="1"
287 |Prototype
288 |'''<tt>m64p_error CoreOverrideVidExt(m64p_video_extension_functions *VideoFunctionStruct);</tt>'''
289 |-
290 |Input Parameters
291 |'''<tt>VideoFunctionStruct</tt>''' Pointer to a structure (defined in [[Mupen64Plus v2.0 headers#m64p_types.h|m64p_types.h]]) containing pointers to the Front-end's custom Video Extension functions to override the default SDL functions
292 |-
293 |Requirements
294 |The Mupen64Plus library must already be initialized before calling this function.  This function cannot be called while the emulator is running.
295 |-
296 |Usage
297 |This function overrides the core's internal SDL-based OpenGL functions which are called from the video plugin to perform various basic tasks like opening the video window, toggling between windowed and fullscreen modes, and swapping frame buffers after a frame has been rendered.  This override functionality allows a front-end to define its own video extension functions to be used instead of the SDL functions, such as for the purpose of embedding the emulator display window inside of a Qt GUI window.  If any of the function pointers in the structure are NULL, the override function will be disabled and the core's internal SDL functions will be used.  The core library with a Video Extension API v3.0 expects the <tt>Functions</tt> struct member to be equal to 11 or more.
298 |}
299 <br />
300
301 == Cheat Functions ==
302 {| border="1"
303 |Prototype
304 |'''<tt>m64p_error CoreAddCheat(const char *CheatName, m64p_cheat_code *CodeList, int NumCodes)</tt>'''
305 |-
306 |Input Parameters
307 |'''<tt>CheatName</tt>''' Pointer to NULL-terminated string containing a unique name for this Cheat Function.<br />
308 '''<tt>CodeList</tt>''' Pointer to an array of <tt>m64p_cheat_code</tt> objects.<br />
309 '''<tt>NumCodes</tt>''' Number of <tt>m64p_cheat_code</tt> elements in the cheat code array.
310 |-
311 |Requirements
312 |The Mupen64Plus library must already be initialized before calling this function.  A ROM image must be currently opened.
313 |-
314 |Usage
315 |This function will add a Cheat Function to a list of currently active cheats which are applied to the open ROM, and set its state to Enabled.  This function may be called before a ROM begins execution or while a ROM is currently running.  Some cheat codes must be applied before the ROM begins executing, and may not work correctly if added after the ROM begins execution.  A Cheat Function consists of a list of one or more <tt>m64p_cheat_code</tt> elements.  If a Cheat Function with the given '''<tt>CheatName</tt>''' already exists, it will be removed and the new Cheat Function will be added in its place.
316 |}
317 <br />
318 {| border="1"
319 |Prototype
320 |'''<tt>m64p_error CoreCheatEnabled(const char *CheatName, int Enabled)</tt>'''
321 |-
322 |Input Parameters
323 |'''<tt>CheatName</tt>''' Pointer to NULL-terminated string containing the name of an existing Cheat Function.<br />
324 '''<tt>Enabled</tt>''' Boolean value to which to set the enabled state of the specified Cheat Function.
325 |-
326 |Requirements
327 |The Mupen64Plus library must already be initialized before calling this function.  A ROM image must be currently opened.
328 |-
329 |Usage
330 |This function enables or disables a specified Cheat Function.
331 |}
332