lsnes rr2-β23
[lsnes.git] / include / interface / c-interface.h
blob51bbd399e558d6e8ce8642535471cfbe0961fb78
1 #ifndef _interface__c_interface__h__included__
2 #define _interface__c_interface__h__included__
4 /*
6 Copyright (c) 2013 Ilari Liusvaara
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
28 /**
29 * Some general information about the interface:
30 * - The parameter type for LSNES_CORE_FOO is struct lsnes_core_foo*
31 * - There are also some other enumerations/structures.
32 * - The only exposed entry point (lsnes_core_entrypoint) has fp type of lsnes_core_func_t.
33 * - By nature, this interface does not reference any symbols (exception is lsnes_register_builtin_core).
34 * - Some fields may be conditional on API version.
35 * - The following functions are required:
36 * * LSNES_CORE_ENUMERATE_CORES
37 * * LSNES_CORE_GET_CORE_INFO
38 * * LSNES_CORE_GET_TYPE_INFO
39 * * LSNES_CORE_GET_REGION_INFO
40 * * LSNES_CORE_GET_SYSREGION_INFO
41 * * LSNES_CORE_GET_AV_STATE
42 * * LSNES_CORE_EMULATE
43 * * LSNES_CORE_SAVESTATE
44 * * LSNES_CORE_LOADSTATE
45 * * LSNES_CORE_GET_CONTROLLERCONFIG
46 * * LSNES_CORE_LOAD_ROM
47 * - Scratch buffers from emulator side last for duration of the call.
48 * - Scratch buffers form core side last until next call.
49 * - Never free buffer from emulator in core or vice versa.
50 * - The spaces for Core, Type, Region and Sysregion IDs are distinct.
51 * - If you only have one region, use ID of 0 for that and GET_REGION/SET_REGION are not needed.
54 #include <stdint.h>
55 #include <time.h>
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
61 //API version.
62 #define LSNES_CORE_API 0
64 /** Constants. **/
65 //VMA is read-only.
66 #define LSNES_CORE_VMA_READONLY 1
67 //VMA has special semantics (no read/write consistency).
68 #define LSNES_CORE_VMA_SPECIAL 2
69 //VMA is volatile (and uninitialized on poweron).
70 #define LSNES_CORE_VMA_VOLATILE 4
72 /** Capabilities. **/
73 //Core supports multiple regions (By supporting LSNES_CORE_GET_REGION/LSNES_CORE_SET_REGION).
74 #define LSNES_CORE_CAP1_MULTIREGION 0x00000001U
75 //Core supports poll flags (By supporting LSNES_CORE_GET_PFLAG/LSNES_CORE_SET_PFLAG).
76 #define LSNES_CORE_CAP1_PFLAG 0x00000002U
77 //Core supports actions (By supporting LSNES_CORE_GET_ACTION_FLAGS/LSNES_CORE_EXECUTE_ACTION).
78 #define LSNES_CORE_CAP1_ACTION 0x00000004U
79 //Core supports bus map (By supporting LSNES_CORE_GET_BUS_MAPPING).
80 #define LSNES_CORE_CAP1_BUSMAP 0x00000008U
81 //Core supports SRAM (By supporting LSNES_CORE_ENUMERATE_SRAM/LSNES_CORE_LOAD_SRAM/LSNES_CORE_SAVE_SRAM).
82 #define LSNES_CORE_CAP1_SRAM 0x00000010U
83 //Core supports resets (By supporting LSNES_CORE_GET_RESET_ACTION). LSNES_CORE_CAP1_ACTION is required.
84 #define LSNES_CORE_CAP1_RESET 0x00000020U
85 //Core supports custom scale computation (By supporting LSNES_CORE_COMPUTE_SCALE).
86 #define LSNES_CORE_CAP1_SCALE 0x00000040U
87 //Core supports explicit save points (By supporting LSNES_CORE_RUNTOSAVE).
88 #define LSNES_CORE_CAP1_RUNTOSAVE 0x00000080U
89 //Core supports powerons (By supporting LSNES_CORE_POWERON).
90 #define LSNES_CORE_CAP1_POWERON 0x00000100U
91 //Core supports cartridge unload (By supporting LSNES_CORE_UNLOAD_CARTRIDGE).
92 #define LSNES_CORE_CAP1_UNLOAD 0x00000200U
93 //Core supports debugging (By supporting LSNES_CORE_DEBUG_RESET and LSNES_CORE_SET_DEBUG_FLAGS[breakpoints]).
94 //LSNES_CORE_CAP1_MEMWATCH is required.
95 #define LSNES_CORE_CAP1_DEBUG 0x00000400U
96 //Core supports tracing (By supporting LSNES_CORE_DEBUG_RESET and LSNES_CORE_SET_DEBUG_FLAGS[tracing]).
97 //LSNES_CORE_CAP1_MEMWATCH is required.
98 #define LSNES_CORE_CAP1_TRACE 0x00000800U
99 //Core supports cheating (By supporting LSNES_CORE_DEBUG_RESET and LSNES_CORE_SET_CHEAT).
100 //LSNES_CORE_CAP1_MEMWATCH is required.
101 #define LSNES_CORE_CAP1_CHEAT 0x00001000U
102 //Core supports cover pages (By supporting LSNES_CORE_DRAW_COVER).
103 #define LSNES_CORE_CAP1_COVER 0x00002000U
104 //Core supports pre-emulate (By supporting LSNES_CORE_PRE_EMULATE).
105 #define LSNES_CORE_CAP1_PREEMULATE 0x00004000U
106 //Core supports registers (By supporting LSNES_CORE_GET_DEVICE_REGS).
107 #define LSNES_CORE_CAP1_REGISTERS 0x00008000U
108 //Core supports memory watch (By supporting LSNES_CORE_GET_VMA_LIST).
109 #define LSNES_CORE_CAP1_MEMWATCH 0x00010000U
110 //Core supports lightguns (By setting lightgun_height/lightgun_width in LSNES_CORE_GET_AV_STATE).
111 #define LSNES_CORE_CAP1_LIGHTGUN 0x00020000U
112 //Core supports fast reinit (By supporting LSNES_CORE_REINIT).
113 #define LSNES_CORE_CAP1_REINIT 0x00040000U
114 //Reserved capabilities.
115 #define LSNES_CORE_CAP1_RESERVED19 0x00080000U
116 #define LSNES_CORE_CAP1_RESERVED20 0x00100000U
117 #define LSNES_CORE_CAP1_RESERVED21 0x00200000U
118 #define LSNES_CORE_CAP1_RESERVED22 0x00400000U
119 #define LSNES_CORE_CAP1_RESERVED23 0x00800000U
120 #define LSNES_CORE_CAP1_RESERVED24 0x01000000U
121 #define LSNES_CORE_CAP1_RESERVED25 0x02000000U
122 #define LSNES_CORE_CAP1_RESERVED26 0x04000000U
123 #define LSNES_CORE_CAP1_RESERVED27 0x08000000U
124 #define LSNES_CORE_CAP1_RESERVED28 0x10000000U
125 #define LSNES_CORE_CAP1_RESERVED29 0x20000000U
126 #define LSNES_CORE_CAP1_RESERVED30 0x40000000U
127 #define LSNES_CORE_CAP1_CAPS2 0x80000000U
129 #define LSNES_END_OF_LIST 0xFFFFFFFFU
131 //Do action <action> on item <item> with parameters <params>.
132 //If successful, return 0.
133 //If supported but unsuccessful, return -1 and fill <error> (will not be released, only needs to be stable to next
134 //call).
135 //In dynamic libs, this is looked up as lsnes_core_fn.
136 typedef int(*lsnes_core_func_t)(unsigned action, unsigned item, void* params, const char** error);
138 //Pixel format.
139 enum lsnes_core_pixel_format
141 LSNES_CORE_PIXFMT_RGB15,
142 LSNES_CORE_PIXFMT_BGR15,
143 LSNES_CORE_PIXFMT_RGB16,
144 LSNES_CORE_PIXFMT_BGR16,
145 LSNES_CORE_PIXFMT_RGB24,
146 LSNES_CORE_PIXFMT_BGR24,
147 LSNES_CORE_PIXFMT_RGB32,
148 LSNES_CORE_PIXFMT_LRGB
151 //Framebuffer.
152 struct lsnes_core_framebuffer_info
154 //Pixel format of framebuffer.
155 enum lsnes_core_pixel_format type;
156 //The physical memory backing the framebuffer.
157 const char* mem;
158 //Physical width of framebuffer.
159 size_t physwidth;
160 //Physical height of framebuffer.
161 size_t physheight;
162 //Physical stride of framebuffer (in bytes).
163 size_t physstride;
164 //Visible width of framebuffer.
165 size_t width;
166 //Visible height of framebuffer.
167 size_t height;
168 //Visible stride of framebuffer (in bytes).
169 size_t stride;
170 //Visible X offset of framebuffer.
171 size_t offset_x;
172 //Visible Y offset of framebuffer.
173 size_t offset_y;
176 struct lsnes_core_sram
178 //Name.
179 const char* name;
180 //Content size.
181 size_t size;
182 //Data.
183 const char* data;
186 struct lsnes_core_system_setting
188 //Name.
189 const char* name;
190 //Value.
191 const char* value;
194 struct lsnes_core_disassembler
196 //Name.
197 const char* name;
198 //Routine.
199 const char* (*fn)(uint64_t base, unsigned char(*fetch)(void* ctx), void* ctx);
202 //Font rendering request.
203 struct lsnes_core_fontrender_req
205 //Input: Context to pass to callbacks.
206 void* cb_ctx;
207 //Input: Allocate bitmap memory.
208 //cb_ctx => cb_ctx from above.
209 //mem_size => Number of bytes needed to allocate.
210 //return buffer at least mem_size bytes. Or return NULL on error.
211 void* (*alloc)(void* cb_ctx, size_t mem_size);
212 //Input: Text to render (UTF-8).
213 const char* text;
214 //Input: Length of text in bytes. If negative, text is null-terminated.
215 long text_len;
216 //Input: Bytes per pixel to request. Can be 1, 2, 3 or 4.
217 unsigned bytes_pp;
218 //Input: Foreground color (native endian).
219 unsigned fg_color;
220 //Input: Background color (native endian).
221 unsigned bg_color;
222 //Output: The allocated bitmap (this comes from ->alloc). Not released on failure.
223 void* bitmap;
224 //Output: Width of the bitmap.
225 size_t width;
226 //Output: Height of the bitmap.
227 size_t height;
230 //Request 0: Initialize and enumerate cores.
231 //Item: 0.
232 //Default action: (required)
233 //Called as the first call. Do the needed initialization and return list of core IDs.
234 #define LSNES_CORE_ENUMERATE_CORES 0
235 struct lsnes_core_enumerate_cores
237 //Output: List of sysregion ids. Terminated by 0xFFFFFFFF.
238 unsigned* sysregions;
239 //Input: Emulator capability flags 1.
240 unsigned emu_flags1;
241 //Input: Function to print message line.
242 void (*message)(const char* msg, size_t length);
243 //Input: Get input.
244 short (*get_input)(unsigned port, unsigned index, unsigned control);
245 //Input: Notify that state of action has updated.
246 void (*notify_action_update)();
247 //Input: Notify that time has ticked.
248 void (*timer_tick)(uint32_t increment, uint32_t per_second);
249 //Input: Get firmware path. The return value is temporary.
250 const char* (*get_firmware_path)();
251 //Input: Get cartridge base path. The return value is temporary.
252 const char* (*get_base_path)();
253 //Input: Get current time.
254 time_t (*get_time)();
255 //Input: Get random seed.
256 time_t (*get_randomseed)();
257 //Input: Notify that memory has been read.
258 void (*memory_read)(uint64_t addr, uint64_t value);
259 //Input: Notify that memory is about to be written.
260 void (*memory_write)(uint64_t addr, uint64_t value);
261 //Input: Notify that memory is about to be executed.
262 void (*memory_execute)(uint64_t addr, uint64_t cpunum);
263 //Input: Notify memory trace event. Str needs to be valid during call.
264 void (*memory_trace)(uint64_t proc, const char* str, int insn);
265 //Input: Submit sound.
266 void (*submit_sound)(const int16_t* samples, size_t count, int stereo, double rate);
267 //Input: Notify latch event. Parameters are NULL-terminated and need to be remain during call.
268 void (*notify_latch)(const char** params);
269 //Input: Output a frame.
270 void (*submit_frame)(struct lsnes_core_framebuffer_info* fb, uint32_t fps_n, uint32_t fps_d);
271 //Input: Add disassembler. Only available if emu_flags1>=1.
272 void* (*add_disasm)(struct lsnes_core_disassembler* disasm);
273 //Input: Remove disassembler. Only available if emu_flags1>=1.
274 void (*remove_disasm)(void* handle);
275 //Input: Render text into bitmap. Returns 0 on success, -1 on failure. Only available if emu_flags>=2.
276 int (*render_text)(struct lsnes_core_fontrender_req* req);
279 //Request 1: Request information about core.
280 //Item id: Core ID.
281 //Default action: (required)
282 //Obtain information about core.
283 #define LSNES_CORE_GET_CORE_INFO 1
284 struct lsnes_core_get_core_info_aparam
286 //Name of the parameter.
287 const char* name;
288 //Model:
289 //bool: boolean
290 //int:<val>,<val>: Integer in specified range.
291 //string[:<regex>]: String with regex.
292 //enum:<json-array-of-strings>: Enumeration.
293 //toggle: Not a real parameter, boolean toggle, must be the first.
294 const char* model;
296 struct lsnes_core_get_core_info_action
298 //Internal id of the action.
299 int id;
300 //Internal name of the action.
301 const char* iname;
302 //Human-readable Name of the action
303 const char* hname;
304 //Array of parameters. Terminated by parameter with NULL name.
305 struct lsnes_core_get_core_info_aparam* parameters;
307 struct lsnes_core_get_core_info
309 //Output: The JSON text.
310 const char* json;
311 //Output: JSON pointer to root of the port array.
312 const char* root_ptr;
313 //Output: Short core name.
314 const char* shortname;
315 //Output: Full core name.
316 const char* fullname;
317 //Output: Capability flags #1 (LSNES_CORE_CAP1_*).
318 unsigned cap_flags1;
319 //Output: Array of actions. Terminated by action with NUL iname. Only if LSNES_CORE_CAP1_ACTION is set.
320 struct lsnes_core_get_core_info_action* actions;
321 //Output: List of trace CPUs. Terminated by NULL. Only if LSNES_CORE_CAP1_TRACE is set.
322 const char** trace_cpu_list;
325 //Request 2: Request information about system type.
326 //Item id: Type ID.
327 //Default action: (required)
328 //Obtain information about system type.
329 #define LSNES_CORE_GET_TYPE_INFO 2
330 struct lsnes_core_get_type_info_paramval
332 const char* iname;
333 const char* hname;
334 signed index;
336 struct lsnes_core_get_type_info_param
338 //Internal name.
339 const char* iname;
340 //Human-readable name.
341 const char* hname;
342 //Default value.
343 const char* dflt;
344 //Enumeration of values (if enumerated, ended by value with NULL iname).
345 //If values are false and true, this is boolean.
346 struct lsnes_core_get_type_info_paramval* values;
347 //Validation regex (only for non-enumerated).
348 const char* regex;
350 struct lsnes_core_get_type_info_romimage
352 //Internal name.
353 const char* iname;
354 //Human-readable name.
355 const char* hname;
356 //Mandatory mask (OR of all preset ones must equal OR of all).
357 unsigned mandatory;
358 //Pass mode: 0 => Content. 1 => Filename, 2 => Directory.
359 int pass_mode;
360 //Optional header size.
361 unsigned headersize;
362 //Standard extensions (split by ;).
363 const char* extensions;
365 struct lsnes_core_get_type_info
367 //Output: ID of core emulating this.
368 unsigned core;
369 //Output: internal name.
370 const char* iname;
371 //Output: human-readable name.
372 const char* hname;
373 //Output: Short System name (e.g. SNES).
374 const char* sysname;
375 //Output: BIOS name.
376 const char* bios;
377 //Output: List of regions. Terminated by 0xFFFFFFFF.
378 unsigned* regions;
379 //Output: List of images. Terminated by image with NULL iname.
380 struct lsnes_core_get_type_info_romimage* images;
381 //Output: List of settings. Terminated by setting with NULL iname.
382 struct lsnes_core_get_type_info_param* settings;
385 //Request 3: Request information about region.
386 //Item id: Region ID.
387 //Default action: (required)
388 //Obtain information about region.
389 #define LSNES_CORE_GET_REGION_INFO 3
390 struct lsnes_core_get_region_info
392 //Output: Internal name.
393 const char* iname;
394 //Output: Human-readable name.
395 const char* hname;
396 //Output: Priority
397 unsigned priority;
398 //Output: Multi-region flag.
399 int multi;
400 //Output: Fps numerator.
401 uint32_t fps_n;
402 //Output: Fps denomerator.
403 uint32_t fps_d;
404 //Output: Compatible run regions, ended with 0xFFFFFFFF.
405 unsigned* compatible_runs;
408 //Request 4: Get sysregion info.
409 //Item id: Sysregion ID.
410 //Default action: (required)
411 //Get information about specific sysregion.
412 #define LSNES_CORE_GET_SYSREGION_INFO 4
413 struct lsnes_core_get_sysregion_info
415 //Output: The name of sysregion.
416 const char* name;
417 //Output: The type ID.
418 unsigned type;
419 //Output: The region ID.
420 unsigned region;
421 //Output: The system name this is for.
422 const char* for_system;
426 //Request 5: Get current A/V state.
427 //Item: Core ID.
428 //Default action: (required)
429 //Fill the structure with current A/V state.
430 #define LSNES_CORE_GET_AV_STATE 5
431 struct lsnes_core_get_av_state
433 uint32_t fps_n;
434 uint32_t fps_d;
435 double par;
436 uint32_t rate_n;
437 uint32_t rate_d;
438 unsigned lightgun_width;
439 unsigned lightgun_height;
443 //Request 6: Emulate a frame
444 //Item: Core ID.
445 //Default action: (required).
446 //Emulate a frame and output the video and audio data resulting.
447 #define LSNES_CORE_EMULATE 6
448 struct lsnes_core_emulate
452 //Request 7: Save state.
453 //Item: Core ID.
454 //Default action: (required).
455 //Save core state.
456 #define LSNES_CORE_SAVESTATE 7
457 struct lsnes_core_savestate
459 //Output: Size of the savestate.
460 size_t size;
461 //Output: Savestate data. Only needs to be stable to next call.
462 const char* data;
465 //Request 8: Load state.
466 //Item: Core ID.
467 //Default action: (required).
468 //Load core state.
469 #define LSNES_CORE_LOADSTATE 8
470 struct lsnes_core_loadstate
472 //Input: Size of the savestate.
473 size_t size;
474 //Input: Savestate data. Only stable during call.
475 const char* data;
478 //Request 9: Get controller set.
479 //Item id: Type ID.
480 //Default action: (required).
481 //Get the controller set.
482 #define LSNES_CORE_GET_CONTROLLERCONFIG 9
483 struct lsnes_core_get_controllerconfig_logical_entry
485 //port
486 unsigned port;
487 //controller
488 unsigned controller;
490 struct lsnes_core_get_controllerconfig
492 //Input: System settings. Ended by entry with NULL name.
493 struct lsnes_core_system_setting* settings;
494 //Output: Port types, indexed by 0-based ID to port type root JSON array. Ended by 0xFFFFFFFF.
495 unsigned* controller_types;
496 //Output: Logical map (ended by 0,0).
497 struct lsnes_core_get_controllerconfig_logical_entry* logical_map;
500 //Request 10: Load ROM.
501 //Item id: Type ID.
502 //Default action: (required).
503 //Load given ROM.
504 #define LSNES_CORE_LOAD_ROM 10
505 struct lsnes_core_load_rom_image
507 //ROM image (or filename thereof)
508 const char* data;
509 //Size of ROM image.
510 size_t size;
511 //Markup.
512 const char* markup;
514 struct lsnes_core_load_rom
516 //Input: The image set.
517 struct lsnes_core_load_rom_image* images;
518 //Input: System settings. Ended by entry with NULL name.
519 struct lsnes_core_system_setting* settings;
520 //Input: RTC second.
521 uint64_t rtc_sec;
522 //Input: RTC subsecond.
523 uint64_t rtc_subsec;
526 //Request 11: Get region.
527 //Item: Core ID.
528 //Default action: Fill region 0.
529 //Return the current region.
530 #define LSNES_CORE_GET_REGION 11
531 struct lsnes_core_get_region
533 //Output: The region.
534 unsigned region;
537 //Request 12: Set region.
538 //Item: Core ID.
539 //Default action: If region is 0, succeed, otherwise fail.
540 //Set current region.
541 #define LSNES_CORE_SET_REGION 12
542 struct lsnes_core_set_region
544 //Input: The region ID.
545 unsigned region;
548 //Request 13: Deinitialize
549 //Item: 0.
550 //Default action: No-op
551 //Deinitialize the state.
552 #define LSNES_CORE_DEINITIALIZE 13
553 struct lsnes_core_deinitialize
557 //Request 14: Get poll flag state.
558 //Item: Core ID.
559 //Default action: Return flag inferred from polls.
560 //Return the poll flag state.
561 //The poll flag gets automatically set to 1 if core reads controllers.
562 #define LSNES_CORE_GET_PFLAG 14
563 struct lsnes_core_get_pflag
565 //Output: The poll flag state.
566 int pflag;
569 //Request 15: Set poll flag state.
570 //Item: Core ID.
571 //Default action: Set flag inferred from polls.
572 //Sets the poll flag state.
573 #define LSNES_CORE_SET_PFLAG 15
574 struct lsnes_core_set_pflag
576 //Input: The poll flag state.
577 int pflag;
580 //Request 16: Get action flags.
581 //Item: Core ID.
582 //Default action: Act as if flags was 1.
583 //Get flags for given action.
584 #define LSNES_CORE_GET_ACTION_FLAGS 16
585 struct lsnes_core_get_action_flags
587 //Input: The ID of action.
588 unsigned action;
589 //Output: The flags.
590 //Bit 0: Enabled.
591 //Bit 1: Checked.
592 unsigned flags;
595 //Request 17: Execute action.
596 //Item: Core ID.
597 //Default action: Do nothing.
598 //Execute given action.
599 #define LSNES_CORE_EXECUTE_ACTION 17
600 struct lsnes_core_execute_action_param
602 union {
603 int boolean;
604 int64_t integer;
605 struct {
606 const char* base;
607 size_t length;
608 } string;
611 struct lsnes_core_execute_action
613 //Input: The ID of action.
614 unsigned action;
615 //Parameters block (length is set by action info).
616 struct lsnes_core_execute_action_param* params;
619 //Request 18: Get bus mapping.
620 //Item: Core ID.
621 //Default action: base=0, size=0 (no mapping).
622 //Get the base and size of bus mapping.
623 #define LSNES_CORE_GET_BUS_MAPPING 18
624 struct lsnes_core_get_bus_mapping
626 //Output: The base address of the mapping.
627 uint64_t base;
628 //Output: The size of the mapping.
629 uint64_t size;
632 //Request 19: Enumerate SRAMs.
633 //Item iD: Core ID.
634 //Default action: Return empty set.
635 //Get the set of SRAMs available.
636 #define LSNES_CORE_ENUMERATE_SRAM 19
637 struct lsnes_core_enumerate_sram
639 //Output: List of SRAMs, NULL terminated (valid until next call).
640 const char** srams;
643 //Request 20: Save SRAMs.
644 //Item id: Core ID.
645 //Default action: Return empty set.
646 //Save the contents of SRAMs.
647 #define LSNES_CORE_SAVE_SRAM 20
648 struct lsnes_core_save_sram
650 //Output: The SRAMs, terminated by entry with NULL name. Valid until next call.
651 struct lsnes_core_sram* srams;
654 //Request 21: Load SRAMs.
655 //Item id: Core ID.
656 //Default action: Warn about any SRAMs present.
657 //Load the contents of SRAMs.
658 #define LSNES_CORE_LOAD_SRAM 21
659 struct lsnes_core_load_sram
661 //Intput: The SRAMs, terminated by entry with NULL name. Valid during call.
662 struct lsnes_core_sram* srams;
665 //Request 22: Get reset action number.
666 //Item id: Core ID.
667 //Default action: Return -1 for both (not supported).
668 //Return the IDs for reset actions.
669 #define LSNES_CORE_GET_RESET_ACTION 22
670 struct lsnes_core_get_reset_action
672 //Output: Soft reset action (-1 if not supported).
673 int softreset;
674 //Output: Hard reset action (-1 if not supported).
675 int hardreset;
678 //Request 23: Get scale factors.
679 //Item id: Core ID.
680 //Default action: Scale to at least 360 width, 320 height.
681 //Compute scale factors for given resolution.
682 #define LSNES_CORE_COMPUTE_SCALE 23
683 struct lsnes_core_compute_scale
685 //Input: Width
686 unsigned width;
687 //Input: Height.
688 unsigned height;
689 //Output: Horizontal scale factor.
690 uint32_t hfactor;
691 //Output: Vertical scale factor.
692 uint32_t vfactor;
695 //Request 24: Run to save.
696 //Item id: Core ID.
697 //Default action: Do nothing.
698 //Run to next save point (can be at most frame).
699 #define LSNES_CORE_RUNTOSAVE 24
700 struct lsnes_core_runtosave
704 //Request 25: Poweron the system
705 //Item id: Core ID.
706 //Default action: Do nothing.
707 //Powers on the emulate system.
708 #define LSNES_CORE_POWERON 25
709 struct lsnes_core_poweron
713 //Request 26: Unload the ROM.
714 //Item id: Core ID.
715 //Default action: Do nothing.
716 //Signals that the ROM is no longer needed and can be unloaded.
717 #define LSNES_CORE_UNLOAD_CARTRIDGE 26
718 struct lsnes_core_unload_cartridge
722 //Request 27: Reset debugging.
723 //Item id: Core ID.
724 //Default action: Do nothing.
725 //Signals that debugging system should discard all breakpoints, cheats and tracks.
726 #define LSNES_CORE_DEBUG_RESET 27
727 struct lsnes_core_debug_reset
731 //Request 28: Set debug flags.
732 //Item id: Core ID.
733 //Default action: Do nothing.
734 //Set debugging flags.
735 #define LSNES_CORE_SET_DEBUG_FLAGS 28
736 struct lsnes_core_set_debug_flags
738 //Input: Address or CPU id.
739 uint64_t addr;
740 //Input: Flags to set.
741 //1 => Break on read.
742 //2 => Break on write.
743 //4 => Break on execute.
744 //8 => Trace.
745 unsigned set;
746 //Input: Flags to clear.
747 unsigned clear;
750 //Request 29: Set cheat.
751 //Item id: Core ID.
752 //Default action: Do nothing.
753 //Set or clear cheat.
754 #define LSNES_CORE_SET_CHEAT 29
755 struct lsnes_core_set_cheat
757 //Input: Address to set on.
758 uint64_t addr;
759 //Input: Value to set.
760 uint64_t value;
761 //Input: If nonzero, set cheat, else clear it.
762 int set;
765 //Request 30: Draw cover page.
766 //Item id: Core ID.
767 //Default action: Draw black screen.
768 //Draw the cover page.
769 #define LSNES_CORE_DRAW_COVER 30
770 struct lsnes_core_draw_cover
772 //Output: The cover page. Needs to stay valid to next call.
773 struct lsnes_core_framebuffer_info* coverpage;
776 //Request 31: Set system controls before emulating frame.
777 //Item id: Core ID.
778 //Default action: Do nothing.
779 //Set the system controls before frame is emulated.
780 #define LSNES_CORE_PRE_EMULATE 31
781 struct lsnes_core_pre_emulate
783 //Input: Context to pass to the function.
784 void* context;
785 //Input: Set input function.
786 void (*set_input)(void* context, unsigned port, unsigned controller, unsigned index, short value);
789 //Request 32: Get list of device registers.
790 //Item id: Core ID.
791 //Default action: Return no registers.
792 //Return list of device registers.
793 #define LSNES_CORE_GET_DEVICE_REGS 32
794 struct lsnes_core_get_device_regs_reg
796 //Name of the register.
797 const char* name;
798 //Read function.
799 uint64_t (*read)();
800 //Write function.
801 void (*write)(uint64_t v);
802 //Is boolean?
803 int boolean;
805 struct lsnes_core_get_device_regs
807 //Output: List of registers. Terminated with register with NULL name.
808 struct lsnes_core_get_device_regs_reg* regs;
811 //Request 33: Get VMA list.
812 //Item id: Core ID.
813 //Default action: Return no VMAs.
814 //Get the list of VMAs.
815 #define LSNES_CORE_GET_VMA_LIST 33
816 struct lsnes_core_get_vma_list_vma
818 //Name of region.
819 const char* name;
820 //Base address.
821 uint64_t base;
822 //Size of region.
823 uint64_t size;
824 //Endianess of region (-1 => little, 0 => host, 1 => big).
825 int endian;
826 //flags (LSNES_CORE_VMA_*).
827 int flags;
828 //Direct mapping for the region. If not NULL, read/write will not be used, instead all operations directly
829 //manipulate this buffer (faster). Must be NULL for special regions.
830 unsigned char* direct_map;
831 //Function to read region (if direct_map is NULL).
832 uint8_t (*read)(uint64_t offset);
833 //Function to write region (if direct_map is NULL and readonly is 0).
834 void (*write)(uint64_t offset, uint8_t value);
836 struct lsnes_core_get_vma_list
838 //Output: List of VMAs. NULL-terminated.
839 struct lsnes_core_get_vma_list_vma** vmas;
842 //Request 34: Reinit core to last loaded state.
843 //Item id: Core ID.
844 //Default action: Emulate using loadstate.
845 //Signals that the core state should be reset to state just after last load (load savestate at moment of initial
846 //poweron).
847 #define LSNES_CORE_REINIT 27
848 struct lsnes_core_reinit
853 #ifdef LSNES_BUILD_AS_BUILTIN_CORE
854 void lsnes_register_builtin_core(lsnes_core_func_t fn);
855 #else
856 int lsnes_core_entrypoint(unsigned action, unsigned item, void* params, const char** error);
857 #endif
859 #ifdef __cplusplus
861 #endif
863 #endif