1 #LyX 2.0 created this file. For more info see http://www.lyx.org/
6 \use_default_options true
7 \maintain_unincluded_children false
9 \language_package default
14 \font_typewriter default
15 \font_default_family default
16 \use_non_tex_fonts false
23 \default_output_format default
25 \bibtex_command default
26 \index_command default
27 \paperfontsize default
31 \pdf_bookmarksnumbered false
32 \pdf_bookmarksopen false
33 \pdf_bookmarksopenlevel 1
48 \paperorientation portrait
64 \paragraph_separation indent
65 \paragraph_indentation default
66 \quotes_language english
69 \paperpagestyle default
70 \tracking_changes false
80 lsnes Lua functions reference
87 \begin_layout Standard
88 \begin_inset CommandInset toc
89 LatexCommand tableofcontents
96 \begin_layout Standard
97 \begin_inset Newpage pagebreak
103 \begin_layout Section
107 \begin_layout Standard
108 These tokens are special, and are expanded while the script is being loaded
111 \begin_layout Subsection
112 @@LUA_SCRIPT_FILENAME@@
115 \begin_layout Standard
116 Expanded to string token containing path and filename of this Lua script.
117 Handy for referencing other lua scripts or resources that are relative
121 \begin_layout Standard
122 In practicular, this is suitable to be passed as base argument of various
123 functions like loadfile, dofile, resolve_filename, gui.bitmap_load, gui.bitmap_lo
124 ad_png and gui.bitmap_load_pal.
127 \begin_layout Section
131 \begin_layout Subsection
132 print: Print values to console
135 \begin_layout Itemize
136 Syntax: none print(value...
140 \begin_layout Standard
141 Prints specified values to console.
144 \begin_layout Subsection
145 exec: Execute lsnes commands
148 \begin_layout Itemize
149 Syntax: none exec(string cmd)
152 \begin_layout Standard
153 Execute lsnes command <cmd>.
156 \begin_layout Subsection
157 utime: Get current time
160 \begin_layout Itemize
161 Syntax: (number,number) utime()
164 \begin_layout Standard
166 First is time since some epoch in seconds, the second is microseconds mod
167 10^6 since that epoch.
170 \begin_layout Subsection
171 emulator_ready: Check if emulator has been fully initialized
174 \begin_layout Itemize
175 Syntax: boolean emulator_ready()
178 \begin_layout Standard
179 Returns true if emulator has finished booting, false if not (on_startup()
180 will be issued later).
183 \begin_layout Subsection
184 set_idle_timeout: Run function after timeout when emulator is idle
187 \begin_layout Itemize
188 Syntax: none set_idle_timeout(number timeout)
191 \begin_layout Standard
192 Set number of microseconds to block idle for.
193 After this timeout has expired, on_idle() will be called once.
196 \begin_layout Subsection
197 set_timer_timeout: Run function after timeout.
200 \begin_layout Itemize
201 Syntax: none set_timer_timeout(number timeout)
204 \begin_layout Standard
205 Set number of microseconds to block timer for.
206 After this timeout has expired, on_timer() will be called once.
209 \begin_layout Subsection
210 bus_address: Look up address in system bus.
213 \begin_layout Itemize
214 Syntax: none bus_address(number bus_addr)
217 \begin_layout Standard
218 Returns virtual address corresponding to specified address on system bus.
221 \begin_layout Subsection
222 loopwrapper: Convert loop into callable function
225 \begin_layout Itemize
226 Syntax: function loopwrapper(function fun, ...)
229 \begin_layout Standard
230 Calls function <fun> with function and specified arguments.
231 The function passed suspends execution until the function returned is called.
232 Handy for linear flow control among multiple invocations of a hook.
236 \begin_layout LyX-Code
237 on_paint = loopwrapper(function(wait)
241 \begin_layout LyX-Code
246 \begin_layout LyX-Code
248 \begin_inset Quotes eld
252 \begin_inset Quotes erd
258 \begin_layout LyX-Code
263 \begin_layout LyX-Code
268 \begin_layout LyX-Code
272 \begin_layout Subsection
273 list_bindings: List keybindings
276 \begin_layout Itemize
277 Syntax: table list_bindings([string cmd])
280 \begin_layout Standard
281 Get table of all keybindings, indexed by keyspec (modifiers|mask/key).
282 If <cmd> is specified, the table is limited to that command.
283 Also searches for controller keys.
286 \begin_layout Subsection
287 get_alias: Get expansion of alias
290 \begin_layout Itemize
291 Syntax: string get_alias(string aname)
294 \begin_layout Standard
295 Get expansion of given alias <aname>.
298 \begin_layout Subsection
299 set_alias: Set expansion of alias
302 \begin_layout Itemize
303 Syntax: none set_alias(string aname, string value)
306 \begin_layout Standard
307 Set expansion of given alias.
310 \begin_layout Subsection
311 create_ibind: Create invese binding
314 \begin_layout Itemize
315 Syntax: INVERSEBIND create_ibind(string name, string cmd)
318 \begin_layout Standard
319 Return object representing inverse binding with specified name <name> and
320 specified command <cmd>.
323 \begin_layout Itemize
324 Note: To create press/release commands, use aliases +foo and -foo .
327 \begin_layout Itemize
328 Note: Keep the returned object around.
331 \begin_layout Subsection
332 create_command: Create a command
335 \begin_layout Itemize
336 Syntax: COMMANDBIND create_commmand(string name, function a)
339 \begin_layout Itemize
340 Syntax: COMMANDBIND create_commmand(string name, function a, function b)
343 \begin_layout Standard
344 Return object representing a command (pair).
347 \begin_layout Itemize
348 If only one function is specied, the command is level-sensitive, <a> is
352 \begin_layout Itemize
353 If <b> is function, the function is edge-sensitive, <a> is positive edge
354 callback and <b> is negative edge callback.
357 \begin_layout Itemize
358 All callbacks get single argument: The parameters passed.
361 \begin_layout Itemize
362 Keep the returned object around.
365 \begin_layout Subsection
366 loadfile: Load Lua script
369 \begin_layout Itemize
370 Syntax: function loadfile(string filename[, string base])
373 \begin_layout Standard
374 Load lua script from <filename>, resolved relative to <base> (if empty,
378 \begin_layout Subsection
379 dofile: Execute Lua script
382 \begin_layout Itemize
383 Syntax: function dofile(string filename[, string base])
386 \begin_layout Standard
387 Execute lua script from <filename>, resolved relative to <base> (if empty,
388 current directory) and return all return values.
391 \begin_layout Subsection
392 open_file: Open a stream
395 \begin_layout Itemize
396 Syntax: FILEREADER open_file(string filename[, string base])
399 \begin_layout Standard
400 Open file <filename>, resolved relative to <base> (if empty, current directory)
404 \begin_layout Subsection
405 FILEREADER(): Read line/bytes from stream
408 \begin_layout Itemize
409 Syntax: string/nil FILEREADER()
412 \begin_layout Itemize
413 Syntax: string/nil FILEREADER(number bytes)
416 \begin_layout Standard
417 Reads next line or <bytes> bytes from specified file handle.
418 On EOF, nil is returned.
421 \begin_layout Itemize
422 Note: The line-oriented variant reads in text mode, so CR at end of line
426 \begin_layout Subsection
427 FILEREADER:lines: Iterator to read all lines
430 \begin_layout Itemize
431 Syntax: for line in <foo>:lines() do ...
435 \begin_layout Standard
436 Iterator for reading all lines of <foo> in a loop.
439 \begin_layout Subsection
440 resolve_filename: Resolve name of file relative to another
443 \begin_layout Itemize
444 Syntax: string resolve_file(string filename, string base)
447 \begin_layout Standard
448 Resolve name of file <filename> relative to <base> and return the result.
451 \begin_layout Standard
452 \begin_inset Newpage pagebreak
458 \begin_layout Section
462 \begin_layout Standard
463 Bitwise logical functions and related.
466 \begin_layout Subsection
467 bit.none/bit.bnot: Bitwise none or NOT function
470 \begin_layout Itemize
471 Syntax: number bit.none(number...)
474 \begin_layout Itemize
475 Syntax: number bit.bnot(number...)
478 \begin_layout Standard
479 48-bit bitwise NOT / NONE function (set bits that are set in none of the
483 \begin_layout Subsection
484 bit.any/bit.bor: Bitwise any or OR function
487 \begin_layout Itemize
488 Syntax: number bit.any(number...)
491 \begin_layout Itemize
492 Syntax: number bit.bor(number...)
495 \begin_layout Standard
496 48-bit bitwise OR / ANY function (set bits that are set in any of the arguments).
499 \begin_layout Subsection
500 bit.all/bit.band: Bitwise all or AND function
503 \begin_layout Itemize
504 Syntax: number bit.all(number...)
507 \begin_layout Itemize
508 Syntax: number bit.band(number...)
511 \begin_layout Standard
512 48-bit bitwise AND / ALL function (set bits that are set in all of the arguments
516 \begin_layout Subsection
517 bit.parity/bit.bxor: Bitwise parity or XOR function
520 \begin_layout Itemize
521 Syntax: number bit.parity(number...)
524 \begin_layout Itemize
525 Syntax: number bit.bxor(number...)
528 \begin_layout Standard
529 48-bit bitwise XOR / PARITY function (set bits that are set in odd number
533 \begin_layout Subsection
534 bit.lrotate: Rotate a number left
537 \begin_layout Itemize
538 Syntax: number bit.lrotate(number base[, number amount[, number bits]])
541 \begin_layout Standard
542 Rotate <bits>-bit (max 48, default 48) number <base> left by <amount> (default
546 \begin_layout Subsection
547 bit.rrotate: Rotate a number right
550 \begin_layout Itemize
551 Syntax: number bit.rrotate(number base[, number amount[, number bits]])
554 \begin_layout Standard
555 Rotate <bits>-bit (max 48, default 48) number <base> right by <amount> (default
559 \begin_layout Subsection
560 bit.lshift: Shift a number left
563 \begin_layout Itemize
564 Syntax: number bit.lshift(number base[, number amount[, number bits]])
567 \begin_layout Standard
568 Shift <bits>-bit (max 48, default 48) number <base> left by <amount> (default
570 The new bits are filled with zeroes.
573 \begin_layout Subsection
574 bit.lrshift: Shift a number right (logical)
577 \begin_layout Itemize
578 Syntax: number bit.lrshift(number base[, number amount[, number bits]])
581 \begin_layout Standard
582 Shift <bits>-bit (max 48, default 48) number <base> logically right by <amount>
584 The new bits are filled with zeroes.
587 \begin_layout Subsection
588 bit.arshift: Shift a number right (arithmetic)
591 \begin_layout Itemize
592 Syntax: number bit.arshift(number base[, number amount[, number bits]])
595 \begin_layout Standard
596 Shift <bits>-bit (max 48, default 48) number <base> logically right by <amount>
598 The new bits are shifted in with copy of the high bit.
601 \begin_layout Subsection
602 bit.extract: Extract/shuffle bits from number
605 \begin_layout Itemize
606 Syntax: number bit.extract(number base[, number bit0[, number bit1,...]])
609 \begin_layout Standard
610 Returns number that has bit0-th bit as bit 0, bit1-th bit as 1 and so on.
613 \begin_layout Itemize
614 Note: Bit numbers up to 51 should work reliably (then things start falling
615 apart due to double precision issues).
618 \begin_layout Itemize
619 Note: There are two special bit positions, true and false, standing for
620 always set bit and always clear bit.
623 \begin_layout Subsection
624 bit.value: Construct number with specified bits set
627 \begin_layout Itemize
628 Syntax: number bit.value([number bit1[, number bit2,...]])
631 \begin_layout Standard
632 Returns bitwise OR of 1 left shifted by <bit1> places, 1 left shifted by
633 <bit2> places and so on.
634 As special value, nil argument is no-op.
637 \begin_layout Subsection
638 bit.test_any: Test if any bit is set
641 \begin_layout Itemize
642 Syntax: boolean bit.test_any(number a, number b)
645 \begin_layout Standard
646 Returns true if bitwise and of <a> and <b> is nonzero, otherwise false.
649 \begin_layout Subsection
650 bit.test_all: Test if all bits are set
653 \begin_layout Itemize
654 Syntax: boolean bit.test_all(number a, number b)
657 \begin_layout Standard
658 Returns true if bitwise and of <a> and <b> equals <b>, otherwise false.
661 \begin_layout Subsection
662 bit.popcount: Population count
665 \begin_layout Itemize
666 Syntax: number bit.popcount(number a)
669 \begin_layout Standard
670 Returns number of set bits in <a>.
673 \begin_layout Subsection
674 bit.clshift: Chained left shift
677 \begin_layout Itemize
678 Syntax: (number, number) bit.clshift(number a, number b, [number amount,[number
682 \begin_layout Standard
683 Does chained left shift on <a>, <b> by <amount> positions (default 1), assuming
684 numbers to be of specified number of bits <bits> (default 48).
687 \begin_layout Subsection
688 bit.crshift: Chained right shift
691 \begin_layout Itemize
692 Syntax: (number, number) bit.crshift(number a, number b, [number amount,[number
696 \begin_layout Standard
697 Does chained right shift on <a>, <b> by <amount> positions (default 1),
698 assuming numbers to be of specified number of bits <bits> (default 48).
701 \begin_layout Subsection
702 bit.flagdecode: Decode bitfield into flags
705 \begin_layout Itemize
706 Syntax: string bit.flagdecode(number a, number bits, [string on, [string
710 \begin_layout Standard
711 Return string of length bits where ith character is ith character of on
712 if bit i is on, otherwise ith character of off.
713 Out of range reads give last character.
716 \begin_layout Itemize
717 Note: <on> defaults to '*' if empty.
720 \begin_layout Itemize
721 Note: <off> defaults to '-' if empty.
724 \begin_layout Subsection
725 bit.rflagdecode: Decode bitfield into flags
728 \begin_layout Itemize
729 Syntax: string bit.rflagdecode(number a, number bits, [string on, [string
733 \begin_layout Standard
734 Like bit.flagdecode, but outputs the string in the opposite order (most significa
738 \begin_layout Standard
739 \begin_inset Newpage pagebreak
745 \begin_layout Section
749 \begin_layout Itemize
750 Functions that draw to screen can only only be called in on_paint and on_video
751 callbacks or if non-default render queue has been set.
754 \begin_layout Itemize
756 Bits 0-7 are the blue component, bits 8-15 are the green component, bits
757 16-23 are the red component, bits 24-31 are alpha component (0 is fully
758 opaque, 255 is almost transparent).
759 -1 is the fully transparent color.
762 \begin_layout Itemize
763 Alpha values greater than 127 do work properly.
766 \begin_layout Itemize
767 Origin of coordinates is at top left corner of game display area.
768 Left and top gaps correspond to negative coordinates.
771 \begin_layout Subsection
772 gui.resolution: Get current resolution
775 \begin_layout Itemize
776 Syntax: (number, number) gui.resolution()
779 \begin_layout Standard
780 Returns 2-tuple (hresolution, vresolution).
783 \begin_layout Subsection
784 gui.left_gap/gui.right_gap/gui.top_gap/gui.bottom_gap: Set edge gaps
787 \begin_layout Itemize
788 Syntax: number gui.left_gap(number gap)
791 \begin_layout Itemize
792 Syntax: number gui.right_gap(number gap)
795 \begin_layout Itemize
796 Syntax: number gui.top_gap(number gap)
799 \begin_layout Itemize
800 Syntax: number gui.bottom_gap(number gap)
803 \begin_layout Standard
804 Set the specified edge gap to specified value <gap> (max gap is 8191).
805 If successful, old gap is returned.
808 \begin_layout Subsection
809 gui.delta_left_gap/gui.delta_right_gap/gui.delta_top_gap/gui.delta_bottom_gap:
813 \begin_layout Itemize
814 Syntax: number gui.delta_left_gap(number dgap)
817 \begin_layout Itemize
818 Syntax: number gui.delta_right_gap(number dgap)
821 \begin_layout Itemize
822 Syntax: number gui.delta_top_gap(number dgap)
825 \begin_layout Itemize
826 Syntax: number gui.delta_bottom_gap(number dgap)
829 \begin_layout Standard
830 Increase the specified edge gap by specified value <dgap> (max gap is 8191)
831 and return the old gap (returns nothing on error).
834 \begin_layout Subsection
835 gui.text/gui.textH/gui.textV,gui.textHV: Draw text
838 \begin_layout Itemize
839 Syntax: none gui.text(number x, number y, string text[, number fgc[, number
843 \begin_layout Itemize
844 Syntax: none gui.textH(number x, number y, string text[, number fgc[, number
848 \begin_layout Itemize
849 Syntax: none gui.textV(number x, number y, string text[, number fgc[, number
853 \begin_layout Itemize
854 Syntax: none gui.textHV(number x, number y, string text[, number fgc[, number
858 \begin_layout Standard
859 Draw specified text on the GUI (each character cell is 8 or 16 wide and
864 \begin_layout Itemize
865 x: X-coordinate to start the drawing from (and x-coordinate at begining
869 \begin_layout Itemize
870 y: Y-coordinate to start the drawing from.
873 \begin_layout Itemize
874 text: The text to draw.
877 \begin_layout Itemize
878 fgc: Text color (default is 0xFFFFFF (white))
881 \begin_layout Itemize
882 bgc: Background color (default is -1 (transparent))
885 \begin_layout Standard
886 Note: The H variants draw at double width and V variants draw at double
890 \begin_layout Subsection
891 gui.rectangle: Draw a rectangle
894 \begin_layout Itemize
895 Syntax: none gui.rectangle(number x, number y, number width, number height[,
896 number thickness[, number outline[, number fill]]])
899 \begin_layout Standard
900 Draw rectangle on the GUI.
904 \begin_layout Itemize
905 x: X-coordinate of left edge.
908 \begin_layout Itemize
909 y: Y-coordinate of upper edge.
912 \begin_layout Itemize
913 width: Width of rectangle.
916 \begin_layout Itemize
917 height: Height of rectangle.
920 \begin_layout Itemize
921 thickness: Thickness of outline (default is 1).
924 \begin_layout Itemize
925 outline: Color of outline (default is 0xFFFFFF (white))
928 \begin_layout Itemize
929 fill: Color of fill (default is -1 (transparent))
932 \begin_layout Subsection
933 gui.box: Draw a 3D-effect box
936 \begin_layout Itemize
937 Syntax: none gui.box(number x, number y, number width, number height[, number
938 thickness[, number outline1[,number outline2[, number fill]]]])
941 \begin_layout Standard
942 Draw rectangle with 3D effect on the GUI.
946 \begin_layout Itemize
947 x: X-coordinate of left edge.
950 \begin_layout Itemize
951 y: Y-coordinate of upper edge.
954 \begin_layout Itemize
955 width: Width of rectangle.
958 \begin_layout Itemize
959 height: Height of rectangle.
962 \begin_layout Itemize
963 thickness: Thickness of outline (default is 1).
966 \begin_layout Itemize
967 outline1: First color of outline (default is 0xFFFFFF (white))
970 \begin_layout Itemize
971 outline2: First color of outline (default is 0x808080 (dark gray))
974 \begin_layout Itemize
975 fill: Color of fill (default is 0xC0C0C0 (light grayy))
978 \begin_layout Subsection
979 gui.pixel: Draw a single pixel
982 \begin_layout Itemize
983 Syntax: none gui.pixel(number x, number y[, number color])
986 \begin_layout Standard
987 Draw one pixel on the GUI.
991 \begin_layout Itemize
992 x: X-coordinate of the pixel
995 \begin_layout Itemize
996 y: Y-coordinate of the pixel
999 \begin_layout Itemize
1000 color: Color of the pixel (default is 0xFFFFFF (white))
1003 \begin_layout Subsection
1004 gui.crosshair: Draw a crosshair
1007 \begin_layout Itemize
1008 Syntax: none gui.crosshair(number x, number y[, number length[, number color]])
1011 \begin_layout Standard
1016 \begin_layout Itemize
1017 x: X-coordinate of the crosshair
1020 \begin_layout Itemize
1021 y: Y-coordinate of the crosshair
1024 \begin_layout Itemize
1025 length: Length of the crosshair lines (default 10).
1028 \begin_layout Itemize
1029 color: Color of the crosshair (default is 0xFFFFFF (white))
1032 \begin_layout Subsection
1033 gui.line: Draw a line
1036 \begin_layout Itemize
1037 Syntax: none gui.line(number x1, number y1, number x2, number y2[, number
1041 \begin_layout Standard
1046 \begin_layout Itemize
1047 x1: X-coordinate of one end.
1050 \begin_layout Itemize
1051 y1: Y-coordinate of one end.
1054 \begin_layout Itemize
1055 x2: X-coordinate of the other end.
1058 \begin_layout Itemize
1059 y2: Y-coordinate of the other end.
1062 \begin_layout Itemize
1063 color: Color of the line (default is 0xFFFFFF (white)).
1066 \begin_layout Subsection
1067 gui.circle: Draw a (filled) circle
1070 \begin_layout Itemize
1071 Syntax: none gui.circle(number x, number y, number r[, number thick[, number
1072 border[, number fil]]])
1075 \begin_layout Standard
1080 \begin_layout Itemize
1081 x: X-coordinate of the center
1084 \begin_layout Itemize
1085 y: Y-coordinate of the center
1088 \begin_layout Itemize
1089 r: The radius of the circle
1092 \begin_layout Itemize
1093 thick: Border thickness
1096 \begin_layout Itemize
1097 border: Border color (default is 0xFFFFFF (white))
1100 \begin_layout Itemize
1101 fill: Fill color (default is -1 (transparent)).
1104 \begin_layout Subsection
1105 gui.bitmap_draw: Draw a bitmap
1108 \begin_layout Itemize
1109 Syntax: none gui.bitmap_draw(number x, number y, BITMAP bitmap, PALETTE palette)
1112 \begin_layout Itemize
1113 Syntax: none gui.bitmap_draw(number x, number y, DBITMAP bitmap)
1116 \begin_layout Standard
1117 Draw a bitmap <bitmap> on screen with specified palette <palette> (if bitmap
1122 \begin_layout Itemize
1123 x: X-coordinate of left edge.
1126 \begin_layout Itemize
1127 y: Y-coordinate of top edge.
1130 \begin_layout Itemize
1131 bitmap: The bitmap to draw
1134 \begin_layout Itemize
1135 palette: The palette to draw the bitmap using.
1138 \begin_layout Subsection
1139 gui.palette_new: Create a new palette
1142 \begin_layout Itemize
1143 Syntax: PALETTE gui.palette_new()
1146 \begin_layout Standard
1147 Returns a new palette (initially all transparent).
1151 \begin_layout Subsection
1152 gui.bitmap_new: Create a new bitmap
1155 \begin_layout Itemize
1156 Syntax: BITMAP/DBITMAP gui.bitmap_new(number w, number h, boolean direct[,
1160 \begin_layout Standard
1161 Returns a new bitmap/dbitmap.
1164 \begin_layout Standard
1168 \begin_layout Itemize
1169 w: The width of new bitmap
1172 \begin_layout Itemize
1173 h: The height of new bitmap
1176 \begin_layout Itemize
1177 direct: If true, the returned bitmap is dbitmap, otherwise bitmap.
1180 \begin_layout Itemize
1181 icolor: Initital fill color (defaults to 0 on BITMAP, -1 on DBITMAP)
1184 \begin_layout Subsection
1185 gui.bitmap_load/gui.bitmap_load_str: Load a bitmap from file or string
1188 \begin_layout Itemize
1189 Syntax: DBITMAP/(BITMAP, PALETTE) gui.bitmap_load(string file[, string base])
1192 \begin_layout Itemize
1193 Syntax: DBITMAP/(BITMAP, PALETTE) gui.bitmap_load_str(string content)
1196 \begin_layout Standard
1197 Reads file <file> (resolved relative to <base>) or string <content> and
1198 returns loaded bitmap/dbitmap (if bitmap, the second return value is palette
1202 \begin_layout Subsection
1203 gui.bitmap_load_png/gui.bitmap_load_png_str: Load a bitmap from PNG
1206 \begin_layout Itemize
1207 Syntax: DBITMAP/(BITMAP, PALETTE) gui.bitmap_load_png(string file[, string
1211 \begin_layout Itemize
1212 Syntax: DBITMAP/(BITMAP, PALETTE) gui.bitmap_load_png_str(string content)
1215 \begin_layout Standard
1216 Load a bitmap from PNG file <file> (resolved relative to <base>) or BASE64
1217 encoded content <content>.
1220 \begin_layout Itemize
1221 If the PNG is of color type 3 (PALETTE), returns two value.
1222 First is BITMAP containing the image data from the PNG and second is PALETTE
1223 containg the palette data from the PNG.
1226 \begin_layout Itemize
1227 For color types 0 (GRAY), 2 (RGB), 4 (GRAY_ALPHA) and 6 (RGBA), returns
1228 one DBITMAP containg the image data loaded from the PNG.
1231 \begin_layout Subsection
1232 gui.bitmap_load_pal/gui.bitmap_load_pal_str: Load a palette
1235 \begin_layout Itemize
1236 Syntax: PALETTE gui.bitmap_load_pal(string file[, string base])
1239 \begin_layout Itemize
1240 Syntax: PALETTE gui.bitmap_load_pal_str(string content)
1243 \begin_layout Standard
1244 Load a palette from file <file>(resolved relative to <base>) or string <content>.
1247 \begin_layout Itemize
1248 The kinds of lines supported:
1252 \begin_layout Itemize
1253 Blank or just whitespace: Ignored
1256 \begin_layout Itemize
1257 First non-whitespace is '#': Ignored
1260 \begin_layout Itemize
1261 <r> <g> <b>: Fully opaque color with specified RGB values (0-255)
1264 \begin_layout Itemize
1265 <r> <g> <b> <a>: Color with specified RGB values (0-255) and specified alpha
1266 (0-256, 0 being fully transparent and 256 fully opaque).
1269 \begin_layout Itemize
1270 transparent: Fully transparent color
1274 \begin_layout Subsection
1275 gui.palette_set: Set palette entry
1278 \begin_layout Itemize
1279 Syntax: none gui.palette_set(PALETTE palette, number index, number color)
1282 \begin_layout Standard
1283 Sets color in palette.
1287 \begin_layout Itemize
1288 palette: The palette to manipulate
1291 \begin_layout Itemize
1292 index: Index of color (0-65535).
1295 \begin_layout Itemize
1296 color: The color value.
1299 \begin_layout Subsection
1300 gui.bitmap_pset: Set pixel in bitmap
1303 \begin_layout Itemize
1304 Syntax: none gui.bitmap_pset(BITMAP/DBITMAP bitmap, number x, number y, number
1308 \begin_layout Standard
1309 Sets specified pixel in bitmap.
1313 \begin_layout Itemize
1314 bitmap: The bitmap to manipulate
1317 \begin_layout Itemize
1318 x: The x-coordinate of the pixel.
1321 \begin_layout Itemize
1322 y: The y-coordinate of the pixel.
1325 \begin_layout Itemize
1326 color: If bitmap is a bitmap, color index (0-65535).
1327 Otherwise color value.
1330 \begin_layout Subsection
1331 gui.bitmap_pget: Get pixel in bitmap
1334 \begin_layout Itemize
1335 Syntax: number gui.bitmap_pget(BITMAP/DBITMAP bitmap, number x, number y)
1338 \begin_layout Standard
1339 Gets specified pixel in bitmap.
1343 \begin_layout Itemize
1344 bitmap: The bitmap to query
1347 \begin_layout Itemize
1348 x: The x-coordinate of the pixel.
1351 \begin_layout Itemize
1352 y: The y-coordinate of the pixel.
1355 \begin_layout Standard
1356 The bitmap color (color index if paletted, otherwise color value).
1359 \begin_layout Subsection
1360 gui.bitmap_size: Get size of bitmap
1363 \begin_layout Itemize
1364 Syntax: (number, number) gui.bitmap_size(BITMAP/DBITMAP bitmap)
1367 \begin_layout Standard
1368 Get size of bitmap <bitmap>.
1369 The first return is the width, the second is the height.
1372 \begin_layout Itemize
1373 Note: Can be used anywhere.
1376 \begin_layout Subsection
1377 gui.bitmap_blit: Blit a bitmap into another
1380 \begin_layout Itemize
1381 Syntax: none gui.bitmap_blit(BITMAP/DBITMAP dest, number dx, number dy, BITMAP/DB
1382 ITMAP src, number sx, number sy, number w, number h[, number ck])
1385 \begin_layout Standard
1386 Blit a part of bitmap to another.
1390 \begin_layout Itemize
1391 dest: Destination to blit to.
1394 \begin_layout Itemize
1395 dx: left edge of target
1398 \begin_layout Itemize
1399 dy: Top edge of target
1402 \begin_layout Itemize
1403 src: The source to blit from.
1404 Must be of the same type as destination.
1407 \begin_layout Itemize
1408 sx: left edge of source
1411 \begin_layout Itemize
1412 sy: Top edge of source
1415 \begin_layout Itemize
1419 \begin_layout Itemize
1420 h: Height of region.
1423 \begin_layout Itemize
1425 Pixels of this color are not blitted.
1429 \begin_layout Itemize
1430 If bitmaps are bitmaps, this is color index of colorkey.
1431 Values outside range 0-65535 cause no key to be used as colorkey.
1434 \begin_layout Itemize
1435 If bitmaps are dbitmaps, this color value of colorkey.
1438 \begin_layout Itemize
1439 May be absent or nil for no colorkey blit.
1443 \begin_layout Subsection
1444 gui.repaint: Arrange a repaint
1447 \begin_layout Itemize
1448 Syntax: none gui.repaint()
1451 \begin_layout Standard
1452 Request on_repaint() to happen as soon as possible.
1455 \begin_layout Subsection
1456 gui.synchronous_repaint: Paint screen now
1459 \begin_layout Itemize
1460 Syntax: none gui.synchronous_repaint(RENDERQUEUE queue)
1463 \begin_layout Standard
1464 Paints specified render queue on screen right there and then.
1467 \begin_layout Subsection
1468 gui.subframe_update: Enable/Disable subframe updates
1471 \begin_layout Itemize
1472 Syntax: none gui.subframe_update(boolean on)
1475 \begin_layout Standard
1476 Request subframe updates (calling on_paint() on subframes) to happen (<on>=true)
1477 or not happen (<on>=false).
1480 \begin_layout Subsection
1481 gui.screenshot: Write a screenshot
1484 \begin_layout Itemize
1485 Syntax: none gui.screenshot(string filename)
1488 \begin_layout Standard
1489 Write PNG screenshot of the current frame (no drawings) to specified file
1493 \begin_layout Subsection
1494 gui.color: Compose a color.
1497 \begin_layout Itemize
1498 Syntax: number gui.color(number r, number g, number b[, number a])
1501 \begin_layout Standard
1502 Returns color (in notation Lua scripts use) corresponding to color (<r>,<g>,<b>)
1503 , each component in scale 0-255.
1504 If <a> is specified, that is alpha (0 is fully transparent, 256(sic) is
1506 The default alpha is 256.
1509 \begin_layout Subsection
1510 gui.status: Set status variable
1513 \begin_layout Itemize
1514 Syntax: none gui.status(string name, string value)
1517 \begin_layout Standard
1519 \begin_inset Quotes eld
1523 \begin_inset Quotes erd
1526 to <value> in status area.
1529 \begin_layout Subsection
1530 gui.rainbow: Rainbow color calculation
1533 \begin_layout Itemize
1534 Syntax: number gui.rainbow(number step, number steps[, number color])
1537 \begin_layout Standard
1538 Perform hue rotation of color <color> (default bright red), by <step> steps.
1539 The number of steps per full rotation is given by absolute value of <steps>.
1542 \begin_layout Standard
1543 If <steps> is negative, the rotation will be counterclockwise.
1546 \begin_layout Subsection
1547 gui.renderq_new: Create a render queue
1550 \begin_layout Itemize
1551 Syntax: RENDERQUEUE gui.renderq_new(number width, number height)
1554 \begin_layout Standard
1555 Create render queue with specified reported size and return it.
1558 \begin_layout Subsection
1559 gui.renderq_clear: Clear a render queue
1562 \begin_layout Itemize
1563 Syntax: none gui.renderq_clear(RENDERQUEUE queue)
1566 \begin_layout Standard
1567 Clear specified render queue.
1570 \begin_layout Subsection
1571 gui.renderq_set: Change active render queue
1574 \begin_layout Itemize
1575 Syntax: none gui.renderq_set(RENDERQUEUE queue)
1578 \begin_layout Standard
1579 Switch to specified render queue.
1580 Use nil as queue to switch to default queue.
1583 \begin_layout Itemize
1584 Note: When switched to another queue, all drawing functions work and draw
1585 there, even outside on_video/on_paint.
1588 \begin_layout Subsection
1589 gui.renderq_run: Run render queue
1592 \begin_layout Itemize
1593 Syntax: none gui.renderq_run(RENDERQUEUE queue)
1596 \begin_layout Standard
1597 Run specified render queue, copying the objects to current render queue.
1601 \begin_layout Itemize
1602 Warning: Don't try to run the current render queue.
1605 \begin_layout Subsection
1606 gui.loadfont: Load a font file
1609 \begin_layout Itemize
1610 Syntax: CUSTOMFONT gui.loadfont(string filename)
1613 \begin_layout Standard
1614 Loads font from specified file (CUSTOMFONT object).
1617 \begin_layout Subsection
1618 CUSTOMFONT(): Render text to screen
1621 \begin_layout Itemize
1622 Syntax: none CUSTOMFONT(number x, number y, string text[, number fgc[, number
1623 bgc[, number hlc]]])
1626 \begin_layout Standard
1627 Draw string with custom font to screen.
1628 The parameters are the same as in gui.text, except <hlc> is the halo color
1629 (default is no halo).
1633 \begin_layout Subsection
1634 gui.adjust_transparency: Adjust transparency of DBITMAP or PALETTE
1637 \begin_layout Itemize
1638 Syntax: none gui.adjust_transparency(DBITMAP obj, number adj)
1641 \begin_layout Itemize
1642 Syntax: none gui.adjust_transparency(PALETTE obj, number adj)
1645 \begin_layout Standard
1646 Multiply alpha channel of <obj> by <adj>/256.
1648 \begin_inset Quotes eld
1652 \begin_inset Quotes erd
1655 out of solid bitmaps.
1658 \begin_layout Subsection
1659 gui.kill_frame: Kill video frame and associated sound
1662 \begin_layout Itemize
1663 Syntax: none gui.kill_frame()
1666 \begin_layout Standard
1667 Kills the currently dumped video frame + the associated sound.
1668 Only valid in on_video callback.
1671 \begin_layout Standard
1672 \begin_inset Newpage pagebreak
1678 \begin_layout Section
1682 \begin_layout Standard
1684 Functions manipulating input are only available in on_input callback.
1687 \begin_layout Subsection
1688 input.get: Read controller button/axis (deprecated)
1691 \begin_layout Itemize
1692 Syntax: number input.get(number controller, number index)
1695 \begin_layout Standard
1696 Read the specified index <index> (zero-based) from specified controller
1697 <controller> (zero-based).
1701 \begin_layout Subsection
1702 input.set: Write controller button/axis (deprecated)
1705 \begin_layout Itemize
1706 Syntax: none input.set(number controller, number index, number value)
1709 \begin_layout Standard
1710 Write the specified index <index> (zero-based) from specified controller
1711 <controller> (zero-based), storing value <value>.
1714 \begin_layout Subsection
1715 input.get2: Read controller button/axis
1718 \begin_layout Itemize
1719 Syntax: number input.get2(number port, number controller, number index)
1722 \begin_layout Standard
1723 Read the specified input tuple.
1724 Port 0 is system port.
1727 \begin_layout Subsection
1728 input.set2: Write controller button/axis
1731 \begin_layout Itemize
1732 Syntax: input.set2(number port, number controller, number index, number value)
1735 \begin_layout Standard
1736 Write the specified input tuple.
1737 Port 0 is system port.
1740 \begin_layout Subsection
1741 input.lcid_to_pcid2: Look up logical controller
1744 \begin_layout Itemize
1745 Syntax: (number, number) input.lcid_to_pcid2(number lcid)
1748 \begin_layout Standard
1749 Look up physical pcid pair (port, controller) corresponding to specified
1750 logical controller (1-based).
1751 Returns nothing if controller does not exist.
1754 \begin_layout Subsection
1755 input.port_type: Look up port type
1758 \begin_layout Itemize
1759 Syntax: string input.port_type(number port)
1762 \begin_layout Standard
1763 Return type of specified port.
1766 \begin_layout Subsection
1767 input.controller_info: Get information about controller
1770 \begin_layout Itemize
1771 Syntax: table input.controller_info(number port, number controller)
1774 \begin_layout Standard
1775 Get controller info for specified controller.
1776 If controller does not exist, returns nil.
1777 Otherwise returns a table with following fields:
1780 \begin_layout Itemize
1781 type (string): Type of the controller.
1784 \begin_layout Itemize
1785 class (string): Class of the controller.
1788 \begin_layout Itemize
1789 classnum (number): Number of the controller within its class (1-based)
1792 \begin_layout Itemize
1793 lcid (number): Logical controller number of the controller.
1796 \begin_layout Itemize
1797 button_count (number): Number of buttons on controller
1800 \begin_layout Itemize
1801 buttons (array): Array of following info about each button:
1805 \begin_layout Itemize
1806 type (string): Type of button.
1808 \begin_inset Quotes eld
1812 \begin_inset Quotes erd
1816 \begin_inset Quotes eld
1820 \begin_inset Quotes erd
1824 \begin_inset Quotes eld
1828 \begin_inset Quotes erd
1832 \begin_inset Quotes eld
1836 \begin_inset Quotes erd
1842 \begin_layout Itemize
1843 name (string): Name of button.
1846 \begin_layout Itemize
1847 symbol (string): Symbol of button.
1848 Only present for type
1849 \begin_inset Quotes eld
1853 \begin_inset Quotes erd
1859 \begin_layout Itemize
1860 hidden (boolean): True if hidden button.
1865 \begin_layout Subsection
1866 input.veto_button: Veto a button press
1869 \begin_layout Itemize
1870 Syntax: none input.veto_button()
1873 \begin_layout Standard
1874 Signals that the button event should be vetoed.
1875 Only valid in on_button callback.
1878 \begin_layout Subsection
1879 input.geta: Get all buttons for controller (deprecated)
1882 \begin_layout Itemize
1883 Syntax: (number, number...) input.geta(number controller)
1886 \begin_layout Standard
1887 Get input state for entiere controller.
1888 Returns n return values.
1891 \begin_layout Itemize
1892 1st return value: Bitmask: bit i is set if i:th index is nonzero
1895 \begin_layout Itemize
1896 2nd- return value: value of i:th index.
1899 \begin_layout Subsection
1900 input.seta: Set all buttons for controller (deprecated)
1903 \begin_layout Itemize
1904 Syntax: none input.seta(number controller, number bitmask, number args...)
1907 \begin_layout Standard
1908 Set state for entiere controller.
1909 args is up to N values for indices (overriding values in bitmask if specified).
1912 \begin_layout Subsection
1913 input.controllertype: Get controller type (deprecated)
1916 \begin_layout Itemize
1917 syntax: string input.controllertype(number controller)
1920 \begin_layout Standard
1921 Get the type of controller as string.
1924 \begin_layout Subsection
1925 input.reset: Execute (delayed) reset
1928 \begin_layout Itemize
1929 Syntax: none input.reset([number cycles])
1932 \begin_layout Standard
1934 If <cycles> is greater than zero, do delayed reset.
1935 0 (or no value) causes immediate reset.
1938 \begin_layout Itemize
1939 Note: Only available with subframe flag false.
1942 \begin_layout Subsection
1943 input.raw: Return raw input data
1946 \begin_layout Itemize
1947 Syntax: table input.raw()
1950 \begin_layout Standard
1951 Returns table of tables of all available keys and axes.
1952 The first table is indexed by key name (platform-dependent!), and the inner
1953 table has the following fields:
1956 \begin_layout Itemize
1957 value: Last reported value for control
1961 \begin_layout Itemize
1962 For keys: 1 for pressed, 0 for released.
1965 \begin_layout Itemize
1966 For axes: -32767...32767.
1969 \begin_layout Itemize
1970 For presure-sensitive buttons: 0...32767.
1973 \begin_layout Itemize
1974 For hats: Bitmask: 1=>Up, 2=>Right, 4=>Down, 8=>Left.
1977 \begin_layout Itemize
1978 For mouse: Coordinates relative to game area.
1982 \begin_layout Itemize
1983 ktype: Type of key (disabled, key, mouse, axis, hat, pressure).
1986 \begin_layout Subsection
1987 input.keyhook: Hook a key
1990 \begin_layout Itemize
1991 Syntax: none input.keyhook(string key, boolean state)
1994 \begin_layout Standard
1995 Requests that keyhook events to be sent for key <key> (<state>=true) or
1996 not sent (<state>=false).
1999 \begin_layout Subsection
2000 input.joyget: Get controls for controller
2003 \begin_layout Itemize
2004 Syntax: table input.joyget(number logical)
2007 \begin_layout Standard
2008 Returns table for current controls for specified logical controller <logical>.
2009 The names of fields vary by controller type.
2012 \begin_layout Itemize
2013 The buttons have the same name as those are referred to in other contexts
2017 \begin_layout Itemize
2018 The analog axes are usually
2019 \begin_inset Quotes eld
2023 \begin_inset Quotes erd
2027 \begin_inset Quotes eld
2031 \begin_inset Quotes erd
2037 \begin_layout Itemize
2038 Each field is numeric or boolean depending on axis/button.
2041 \begin_layout Subsection
2042 input.joyset: Set controls for controller
2045 \begin_layout Itemize
2046 Syntax: none input.joyset(number controller, table controls)
2049 \begin_layout Standard
2050 Set the the state of specified controller to values specified in specified
2054 \begin_layout Itemize
2055 Each field can be boolean or number.
2058 \begin_layout Itemize
2059 Also, buttons allow strings, which cause value to be inverted.
2062 \begin_layout Subsection
2063 input.lcid_to_pcid: Look up logical controller (deprecated)
2066 \begin_layout Itemize
2067 Syntax: (number, number, number) input.lcid_to_pcid(number lcid)
2070 \begin_layout Standard
2071 Returns the legacy pcid for controller (or false if there isn't one), followed
2073 Returns nothing if controller does not exist.
2076 \begin_layout Standard
2077 \begin_inset Newpage pagebreak
2083 \begin_layout Section
2087 \begin_layout Standard
2088 Various keybinding-related functions
2091 \begin_layout Subsection
2092 keyboard.bind: Bind a key
2095 \begin_layout Itemize
2096 Syntax: none keyboard.bind(string mod, string mask, string key, string cmd)
2099 \begin_layout Standard
2100 Bind specified key with specified modifers to specified command.
2103 \begin_layout Subsection
2104 keyboard.unbind: Unbind a key
2107 \begin_layout Itemize
2108 Syntax: none keyboard.unbind(string mod, string mask, string key)
2111 \begin_layout Standard
2112 Unbind specified key with specified modifers.
2115 \begin_layout Subsection
2116 keyboard.alias: Set alias expansion
2119 \begin_layout Itemize
2120 Syntax: none keyboard.alias(string alias, string expansion)
2123 \begin_layout Standard
2124 Set expansion of given command.
2127 \begin_layout Standard
2128 \begin_inset Newpage pagebreak
2134 \begin_layout Section
2138 \begin_layout Standard
2142 \begin_layout Subsection
2143 subtitle.byindex: Look up start and length of subtitle by index
2146 \begin_layout Itemize
2147 Syntax: (number, number) subtitle.byindex(number i)
2150 \begin_layout Standard
2151 Read the frame and length of ith subtitle.
2152 Returns nothing if not present.
2155 \begin_layout Subsection
2156 subtitle.set: Write a subtitle
2159 \begin_layout Itemize
2160 Syntax: none subtitle.set(number f, number l, string txt)
2163 \begin_layout Standard
2164 Set the text of subtitle.
2167 \begin_layout Subsection
2168 subtitle.get: Read a subtitle
2171 \begin_layout Itemize
2172 Syntax: string subtitle.get(number f, number l)
2175 \begin_layout Standard
2176 Get the text of subtitle.
2179 \begin_layout Subsection
2180 subtitle.delete: Delete a subtitle
2183 \begin_layout Itemize
2184 Syntax: nonesubtitle.delete(number f, number l)
2187 \begin_layout Standard
2188 Delete specified subtitle.
2191 \begin_layout Standard
2192 \begin_inset Newpage pagebreak
2198 \begin_layout Section
2202 \begin_layout Standard
2203 Host memory handling (extra memory saved to savestates).
2204 Host memory starts empty.
2207 \begin_layout Itemize
2208 Reads out of range return false.
2211 \begin_layout Itemize
2212 Writes out of range extend the memory.
2215 \begin_layout Subsection
2216 hostmemory.read: Read byte from host memory
2219 \begin_layout Itemize
2220 Syntax: number hostmemory.read(number address)
2223 \begin_layout Standard
2224 Reads byte from hostmemory slot address <address>.
2227 \begin_layout Subsection
2228 hostmemory.write: Write byte to host memory
2231 \begin_layout Itemize
2232 Syntax: none hostmemory.write(number address, number value)
2235 \begin_layout Standard
2236 Writes hostmemory slot with value <value> 0-255.
2239 \begin_layout Subsection
2240 hostmemory.read{,s}{byte,{,d,q}word}: Read from host memory
2243 \begin_layout Itemize
2244 Syntax: number hostmemory.readbyte(number address)
2247 \begin_layout Itemize
2248 Syntax: number hostmemory.readsbyte(number address)
2251 \begin_layout Itemize
2252 Syntax: number hostmemory.readword(number address)
2255 \begin_layout Itemize
2256 Syntax: number hostmemory.readsword(number address)
2259 \begin_layout Itemize
2260 Syntax: number hostmemory.readdword(number address)
2263 \begin_layout Itemize
2264 Syntax: number hostmemory.readsdword(number address)
2267 \begin_layout Itemize
2268 Syntax: number hostmemory.readqword(number address)
2271 \begin_layout Itemize
2272 Syntax: number hostmemory.readsqword(number address)
2275 \begin_layout Standard
2276 Read elements (little-endian) from given address <address>.
2279 \begin_layout Itemize
2283 \begin_layout Itemize
2287 \begin_layout Itemize
2291 \begin_layout Itemize
2292 qword is 8 elements.
2295 \begin_layout Itemize
2296 The 's' variants do signed read.
2299 \begin_layout Subsection
2300 hostmemory.write{,s}{byte,{,d,q}word}: Write to host memory
2303 \begin_layout Itemize
2304 Syntax: number hostmemory.writebyte(number address, number value)
2307 \begin_layout Itemize
2308 Syntax: number hostmemory.writesbyte(number address, number value)
2311 \begin_layout Itemize
2312 Syntax: number hostmemory.writeword(number address, number value)
2315 \begin_layout Itemize
2316 Syntax: number hostmemory.writesword(number address, number value)
2319 \begin_layout Itemize
2320 Syntax: number hostmemory.writedword(number address, number value)
2323 \begin_layout Itemize
2324 Syntax: number hostmemory.writesdword(number address, number value)
2327 \begin_layout Itemize
2328 Syntax: number hostmemory.writeqword(number address, number value)
2331 \begin_layout Itemize
2332 Syntax: number hostmemory.writesqword(number address, number value)
2335 \begin_layout Standard
2336 Write value <value> to elements (little-endian) starting from given address
2340 \begin_layout Itemize
2344 \begin_layout Itemize
2348 \begin_layout Itemize
2352 \begin_layout Itemize
2353 qword is 8 elements.
2356 \begin_layout Itemize
2357 The 's' variants do signed write.
2360 \begin_layout Standard
2361 \begin_inset Newpage pagebreak
2367 \begin_layout Section
2371 \begin_layout Standard
2375 \begin_layout Subsection
2376 movie.currentframe: Get current frame number
2379 \begin_layout Itemize
2380 Syntax: number movie.currentframe()
2383 \begin_layout Standard
2384 Return number of current frame.
2387 \begin_layout Subsection
2388 movie.framecount: Get move frame count
2391 \begin_layout Itemize
2392 Syntax: number movie.framecount()
2395 \begin_layout Standard
2396 Return number of frames in movie.
2399 \begin_layout Subsection
2400 movie.readonly: Is in readonly mode?
2403 \begin_layout Itemize
2404 Syntax: boolean movie.readonly()
2407 \begin_layout Standard
2408 Return true if in readonly mode, false if in readwrite.
2411 \begin_layout Subsection
2412 movie.rerecords: Movie rerecord count
2415 \begin_layout Itemize
2416 Syntax: number movie.rerecords()
2419 \begin_layout Standard
2420 Returns the current value of rerecord count.
2423 \begin_layout Subsection
2424 movie.set_readwrite: Set read-write mode.
2427 \begin_layout Itemize
2428 Syntax: none movie.set_readwrite()
2431 \begin_layout Standard
2432 Set readwrite mode (does not cause on_readwrite callback).
2435 \begin_layout Subsection
2436 movie.frame_subframes: Count subframes in frame
2439 \begin_layout Itemize
2440 Syntax: number movie.frame_subframes(number frame)
2443 \begin_layout Standard
2444 Count number of subframes in specified frame <frame> (frame numbers are
2445 1-based) and return that.
2448 \begin_layout Subsection
2449 movie.read_subframes: Read subframe data (deprecated)
2452 \begin_layout Itemize
2453 Syntax: table movie.read_subframes(number frame, number subframe)
2456 \begin_layout Standard
2457 Read specifed subframe in specified frame and return data as array.
2460 \begin_layout Subsection
2461 movie.read_rtc: Read current RTC time
2464 \begin_layout Itemize
2465 Syntax: (number, number) movie.read_rtc()
2468 \begin_layout Standard
2469 Returns the current value of the RTC as a pair (second, subsecond).
2472 \begin_layout Subsection
2473 movie.unsafe_rewind: Fast movie rewind to saved state
2476 \begin_layout Itemize
2477 Syntax: none movie.unsafe_rewind([UNSAFEREWIND state])
2480 \begin_layout Standard
2481 Start setting point for unsafe rewind or jump to point of unsafe rewind.
2484 \begin_layout Itemize
2485 If called without argument, causes emulator to start process of setting
2486 unsafe rewind point.
2487 When this has finished, callback on_set_rewind occurs, passing the rewind
2488 state to lua script.
2491 \begin_layout Itemize
2492 If called with argument, causes emulator rewind to passed rewind point as
2494 Readwrite mode is implicitly activated.
2497 \begin_layout Standard
2498 The following warnings apply to unsafe rewinding:
2501 \begin_layout Itemize
2502 There are no safety checks against misuse (that's what
2503 \begin_inset Quotes eld
2507 \begin_inset Quotes erd
2513 \begin_layout Itemize
2514 Only call rewind from timeline rewind point was set from.
2517 \begin_layout Itemize
2518 Only call rewind from after the rewind point was set.
2521 \begin_layout Subsection
2522 movie.to_rewind: Load savestate as rewind point
2525 \begin_layout Itemize
2526 Syntax: UNSAFEREWIND movie.to_rewind(string filename)
2529 \begin_layout Standard
2530 Load specified savestate file <filename> as rewind point and return UNSAFEREWIND
2531 corresponding to it.
2534 \begin_layout Itemize
2535 Note: This operation does not take emulated time.
2538 \begin_layout Subsection
2539 movie.copy_movie/INPUTMOVIE::copy_movie: Copy movie to movie object
2542 \begin_layout Itemize
2543 Syntax: INPUTMOVIE movie.copy_movie([INPUTMOVIE movie])
2546 \begin_layout Itemize
2547 Syntax: INPUTMOVIE INPUTMOVIE::copy_movie()
2550 \begin_layout Standard
2551 Copies specified movie <movie>/current object (if none or nil, the active
2552 movie) as new movie object.
2555 \begin_layout Subsection
2556 movie.get_frame/INPUTMOVIE::get_frame: Read specified frame in movie.
2559 \begin_layout Itemize
2560 Syntax: INPUTFRAME movie.get_frame([INPUTMOVIE movie,] number frame)
2563 \begin_layout Itemize
2564 Syntax: INPUTFRAME INPUTMOVIE::get_frame(number frame);
2567 \begin_layout Standard
2568 Get INPUTFRAME object corresponding to specified frame in specified movie.
2571 \begin_layout Subsection
2572 movie.set_frame/INPUTMOVIE::set_frame: Write speicifed frame in movie.
2575 \begin_layout Itemize
2576 Syntax: none movie.set_frame([INPUTMOVIE movie,] number frame, INPUTFRAME
2580 \begin_layout Itemize
2581 Syntax: none INPUTMOVIE::set_frame(number frame, INPUTFRAME data)
2584 \begin_layout Standard
2585 Set data in specified frame.
2588 \begin_layout Itemize
2589 Note: Past can't be edited in active movie.
2592 \begin_layout Subsection
2593 movie.get_size/INPUTMOVIE::get_size: Get size of movie
2596 \begin_layout Itemize
2597 Syntax: integer movie.get_size([INPUTMOVIE movie])
2600 \begin_layout Itemize
2601 Syntax: integer INPUTMOVIE::get_size()
2604 \begin_layout Standard
2605 Return number of subframes in specified movie.
2608 \begin_layout Subsection
2609 movie.count_frames/INPUTMOVIE::count_frames: Count frames in movie
2612 \begin_layout Itemize
2613 Syntax: number movie.count_frames([INPUTMOVIE movie])
2616 \begin_layout Itemize
2617 Syntax: number INPUTMOVIE::count_frames()
2620 \begin_layout Standard
2621 Return number of frames in movie.
2624 \begin_layout Subsection
2625 movie.find_frame/INPUTMOVIE::find_frame: Find subframe corresponding to frame
2628 \begin_layout Itemize
2629 Syntax: number movie.find_frame([INPUTMOVIE movie], number frame)
2632 \begin_layout Itemize
2633 Syntax: number INPUTMOVIE::find_frame(number frame)
2636 \begin_layout Standard
2637 Returns starting subframe of given frame (frame numbers are 1-based).
2638 Returns -1 if frame number is bad.
2641 \begin_layout Subsection
2642 movie.blank_frame/INPUTMOVIE::blank_frame: Return a blank frame
2645 \begin_layout Itemize
2646 Syntax: INPUTFRAME movie.blank_frame([INPUTMOVIE movie])
2649 \begin_layout Itemize
2650 Syntax: INPUTFRAME INPUTMOVIE::blank_frame()
2653 \begin_layout Standard
2654 Return blank INPUTFRAME with frame type from specified movie.
2657 \begin_layout Subsection
2658 movie.append_frames/INPUTMOVIE::append_frames: Append blank frames
2661 \begin_layout Itemize
2662 Syntax: none movie.append_frames([INPUTMOVIE movie,] number frames)
2665 \begin_layout Itemize
2666 Syntax: none INPUTMOVIE::append_frames(number frames)
2669 \begin_layout Standard
2670 Append specified number <frames> of frames.
2673 \begin_layout Subsection
2674 movie.append_frame/INPUTMOVIE::append_frame: Append a frame
2677 \begin_layout Itemize
2678 Syntax: none movie.append_frame([INPUTMOVIE movie,] INPUTFRAME frame)
2681 \begin_layout Itemize
2682 Syntax: none INPUTMOVIE::append_frame(INPUTFRAME frame)
2685 \begin_layout Standard
2686 Append specified frame <frame>.
2687 Past of current movie can't be edited.
2690 \begin_layout Subsection
2691 movie.truncate/INPUTMOVIE::truncate: Truncate a movie.
2694 \begin_layout Itemize
2695 Syntax: none movie.truncate([INPUTMOVIE movie,] number frames)
2698 \begin_layout Itemize
2699 Syntax: none INPUTMOVIE::truncate(number frames)
2702 \begin_layout Standard
2703 Truncate the specified movie to specified number of frames.
2706 \begin_layout Subsection
2707 movie.edit/INPUTMOVIE::edit: Edit a movie
2710 \begin_layout Itemize
2711 Syntax: none movie.edit([INPUTMOVIE movie,] number frame, number port, number
2712 controller, number control, number/bool value)
2715 \begin_layout Itemize
2716 Syntax: none INPUTMOVIE::edit(number frame, number port, number controller,
2717 number control, number/bool value)
2720 \begin_layout Standard
2721 Change specified control in specified frame in specified movie.
2722 Past can't be edited in active movie.
2725 \begin_layout Subsection
2726 movie.copy_frames2: Copy frames between movies
2729 \begin_layout Itemize
2730 Syntax: none movie.copy_frames2([INPUTMOVIE dstmov,] number dst, [INPUTMOVIE
2731 srcmov,] number src, number count)
2734 \begin_layout Standard
2735 Copy specified number of frames between two movies.
2736 The copy proceeeds in forward direction.
2739 \begin_layout Subsection
2740 movie.copy_frames/INPUTMOVIE::copy_frames: Copy frames in movie
2743 \begin_layout Itemize
2744 Syntax: none movie.copy_frames([INPUTMOVIE mov,] number dst, number src,
2745 number count, bool backwards)
2748 \begin_layout Itemize
2749 Syntax: none INPUTMOVIE::copy_frames(number dst, number src, number count,
2753 \begin_layout Standard
2754 Copy specified number of frames from one point in movie to another.
2755 If backwards is true, the copy will be done backwards.
2758 \begin_layout Subsection
2759 movie.serialize/INPUTMOVIE::serialize: Serialize movie
2762 \begin_layout Itemize
2763 Syntax: none movie.serialize([INPUTMOVIE movie,] string filename, bool binary)
2766 \begin_layout Itemize
2767 Syntax: none INPUTMOIVE::serialize(string filename, bool binary)
2770 \begin_layout Standard
2771 Serialize given movie into file.
2772 If binary is true, binary format (more compact and much faster) is used.
2775 \begin_layout Subsection
2776 movie.unserialize: Unserialize movie
2779 \begin_layout Itemize
2780 Syntax: INPUTMOVIE movie.unserialize(INPUTFRAME template, string filename,
2784 \begin_layout Standard
2785 Unserialize movie from file.
2786 The given frame is used as template to decide the frame type.
2787 If binary is true, binary format is decoded (much faster).
2790 \begin_layout Subsection
2791 movie.current_first_subframe: Return first subframe in current frame
2794 \begin_layout Itemize
2795 Syntax: number movie.current_first_subframe()
2798 \begin_layout Standard
2799 Returns first subframe in current frame.
2802 \begin_layout Subsection
2803 movie.pollcounter: Return poll counter for speified control
2806 \begin_layout Itemize
2807 Syntax: number movie.pollcounter(number port, number controller, number control)
2810 \begin_layout Standard
2811 Returns number of times the specified control has been polled this frame.
2814 \begin_layout Subsection
2815 INPUTFRAME::get_button: Get button
2818 \begin_layout Itemize
2819 Syntax: boolean INPUTFRAME::get_button(number port, number controller, number
2823 \begin_layout Standard
2824 Returns state of given button as boolean.
2827 \begin_layout Subsection
2828 INPUTFRAME::get_axis: Get axis
2831 \begin_layout Itemize
2832 Syntax: number INPUTFRAME::get_axis(number port, number controller, number
2836 \begin_layout Standard
2837 Returns state of given axis as number.
2840 \begin_layout Subsection
2841 INPUTFRAME::set_button/INPUTFRAME::set_axis: Set button or axis
2844 \begin_layout Itemize
2845 Syntax: none INPUTFRAME::set_button(number port, number controller, number
2846 control, number/bool value)
2849 \begin_layout Itemize
2850 Syntax: none INPUTFRAME::set_axis(number port, number controller, number
2854 \begin_layout Standard
2855 Set the given button/axis to given value.
2858 \begin_layout Subsection
2859 INPUTFRAME::serialize: Serialize a frame
2862 \begin_layout Itemize
2863 Syntax: string INPUTFRAME::serialize()
2866 \begin_layout Standard
2867 Return string representation of frame.
2870 \begin_layout Subsection
2871 INPUTFRAME::unserialize: Unserialize a frame
2874 \begin_layout Itemize
2875 Syntax: none INPUTFRAME::unserialize(string data)
2878 \begin_layout Standard
2879 Set current frame from given data.
2882 \begin_layout Subsection
2883 INPUTFRAME::get_stride: Get movie stride
2886 \begin_layout Itemize
2887 Syntax: number INPUTFRAME::get_stride()
2890 \begin_layout Standard
2891 Return number of bytes needed to store the input frame.
2892 Mainly useful for some debugging.
2895 \begin_layout Standard
2896 \begin_inset Newpage pagebreak
2902 \begin_layout Section
2906 \begin_layout Standard
2907 Routines for settings manipulation
2910 \begin_layout Subsection
2911 settings.get: Get value of setting
2914 \begin_layout Itemize
2915 Syntax: string settings.get(string name)
2918 \begin_layout Standard
2919 Get value of setting <name>.
2920 If setting value can't be obtained, returns (nil, error message).
2923 \begin_layout Subsection
2924 settings.set: Set value of setting
2927 \begin_layout Itemize
2928 Syntax: none settings.set(string name, string value)
2931 \begin_layout Standard
2932 Set value <value> of setting <name>.
2933 If setting can't be set, returns (nil, error message).
2936 \begin_layout Standard
2937 \begin_inset Newpage pagebreak
2943 \begin_layout Section
2947 \begin_layout Standard
2948 Contains various functions for managing memory
2951 \begin_layout Subsection
2952 memory.vma_count: Count number of VMAs.
2955 \begin_layout Itemize
2956 Syntax: number memory.vma_count()
2959 \begin_layout Standard
2960 Returns the number of VMAs
2963 \begin_layout Subsection
2964 memory.read_vma: Lookup VMA info by index
2967 \begin_layout Itemize
2968 Syntax: string memory.read_vma(number index)
2971 \begin_layout Standard
2972 Reads the specified VMA (indices start from zero).
2973 Trying to read invalid VMA gives nil.
2974 The read VMA is table with the following fields:
2977 \begin_layout Itemize
2978 region_name (string): The readable name of the VMA
2981 \begin_layout Itemize
2982 baseaddr (number): Base address of the VMA
2985 \begin_layout Itemize
2986 lastaddr (number): Last address in the VMA.
2989 \begin_layout Itemize
2990 size (number): The size of VMA in bytes.
2993 \begin_layout Itemize
2994 readonly (boolean): True of the VMA corresponds to ROM.
2997 \begin_layout Itemize
2998 iospace (boolean): True if the VMA is I/O space.
3001 \begin_layout Itemize
3002 native_endian (boolean): True if the VMA has native endian as opposed to
3006 \begin_layout Subsection
3007 memory.find_vma: Find VMA info by address
3010 \begin_layout Itemize
3011 Syntax: table memory.find_vma(number address)
3014 \begin_layout Standard
3015 Finds the VMA containing specified address.
3016 Returns table in the same format as read_vma or nil if not found.
3019 \begin_layout Subsection
3020 memory.read{,s}{byte,{,d,q}word}: Write memory
3023 \begin_layout Itemize
3024 Syntax: none memory.readbyte([string vma, ]number address)
3027 \begin_layout Itemize
3028 Syntax: none memory.readword([string vma, ]number address)
3031 \begin_layout Itemize
3032 Syntax: none memory.readdword([string vma, ]number address)
3035 \begin_layout Itemize
3036 Syntax: none memory.readqword([string vma, ]number address)
3039 \begin_layout Itemize
3040 Syntax: none memory.readsbyte([string vma, ]number address)
3043 \begin_layout Itemize
3044 Syntax: none memory.readsword([string vma, ]number address)
3047 \begin_layout Itemize
3048 Syntax: none memory.readsdword([string vma, ]number address)
3051 \begin_layout Itemize
3052 Syntax: none memory.readsqword([string vma, ]number address)
3055 \begin_layout Standard
3056 Reads the specified address <ddress> (if 's' variant is used, do undergo
3060 \begin_layout Subsection
3061 memory.write{byte,{,d,q}word}: Write memory
3064 \begin_layout Itemize
3065 Syntax: none memory.writebyte([string vma, ]number address, number value)
3068 \begin_layout Itemize
3069 Syntax: none memory.writeword([string vma, ]number address, number value)
3072 \begin_layout Itemize
3073 Syntax: none memory.writedword([string vma, ]number address, number value)
3076 \begin_layout Itemize
3077 Syntax: none memory.writeqword([string vma, ]number address, number value)
3080 \begin_layout Standard
3081 Writes the specified value <value> (negative values undergo 2's complement)
3082 to specified address <address>.
3085 \begin_layout Subsection
3086 memory.map{,s}{byte,{,d,q}word}: Map an array
3089 \begin_layout Itemize
3090 Syntax: userdata memory.map<type>([[string vma, ]number base, number size])
3093 \begin_layout Standard
3094 Returns a table mapping specified memory aperture for read/write.
3095 If parameters are omitted, entiere map space is the aperture.
3098 \begin_layout Itemize
3099 Type may be one of: byte, sbyte, word, sword, dword, sdword, qword or sqword.
3102 \begin_layout Subsection
3103 memory.hash_region: Hash region of memory
3106 \begin_layout Itemize
3107 Syntax: string memory.hash_region([string vma, ]number base, number size)
3110 \begin_layout Standard
3111 Hash specified number of bytes starting from specified address and return
3115 \begin_layout Subsection
3116 memory.hash_state: Hash system state
3119 \begin_layout Itemize
3120 Syntax: string memory.hash_state()
3123 \begin_layout Standard
3124 Hash the current system state.
3125 Mainly useful for debugging savestates.
3128 \begin_layout Subsection
3129 memory.readregion: Read region of memory
3132 \begin_layout Itemize
3133 Syntax: table memory.readregion([string vma, ]number base, number size)
3136 \begin_layout Standard
3137 Read a region of memory.
3140 \begin_layout Itemize
3141 Warning: If the region crosses VMA boundary, the results are undefined.
3144 \begin_layout Subsection
3145 memory.writeregion: Write region of memory
3148 \begin_layout Itemize
3149 Syntax: none memory.writeregion([string vma, ]number base, number size, table
3153 \begin_layout Standard
3154 Write a region of memory.
3157 \begin_layout Itemize
3158 Warning: If the region crosses VMA boundary, the results are undefined.
3161 \begin_layout Subsection
3162 memory.map_structure: Create mmap structure
3165 \begin_layout Itemize
3166 syntax: MMAP_STRUCT memory.map_structure()
3169 \begin_layout Standard
3170 Returns a new mapping structure (MMAP_STRUCT)
3173 \begin_layout Subsection
3174 MMAP_STRUCT(): Bind key in mmap structure
3177 \begin_layout Itemize
3178 Syntax: none MMAP_STRUCT(string key, [string vma, ]number address, string
3182 \begin_layout Standard
3183 Bind key <key> in mmap structure to specified address <address> with specified
3187 \begin_layout Itemize
3188 Type may be one of: byte, sbyte, word, sword, dword, sdword, qword or sqword.
3191 \begin_layout Subsection
3192 memory.read_expr: Evaluate memory watch expression
3195 \begin_layout Itemize
3196 Syntax: string memory.read_expr(string expr)
3199 \begin_layout Standard
3200 Evaluate specified watch expression and return result
3203 \begin_layout Subsection
3204 memory.action: Run core action
3207 \begin_layout Itemize
3208 memory.action(string action, [<params>])
3211 \begin_layout Standard
3213 The different models expect parameters as:
3216 \begin_layout Itemize
3220 \begin_layout Itemize
3224 \begin_layout Itemize
3228 \begin_layout Itemize
3232 \begin_layout Itemize
3236 \begin_layout Subsection
3237 memory.get_lag_flag: Get lag flag
3240 \begin_layout Itemize
3241 Syntax: boolean memory.get_lag_flag()
3244 \begin_layout Standard
3245 Get the value of core lag flag.
3246 True if this frame has been lag so far, false if poll has been detected.
3249 \begin_layout Subsection
3250 memory.set_lag_flag: Set lag flag
3253 \begin_layout Itemize
3254 Syntax: none memory.set_lag_flag(boolean flag)
3257 \begin_layout Standard
3258 Set the value of core lag flag.
3259 This flag automatically gets cleared if poll is detected, but can be forcibly
3260 set or cleared if game so requires.
3263 \begin_layout Itemize
3264 Should only be used in on_frame_emulated callback.
3267 \begin_layout Itemize
3268 Setting or clearing this affects the emulator lag counter.
3271 \begin_layout Standard
3272 \begin_inset Newpage pagebreak
3278 \begin_layout Section
3282 \begin_layout Standard
3283 Contains newer memory functions.
3286 \begin_layout Subsection
3287 memory2(): Get all VMA names.
3290 \begin_layout Itemize
3291 Syntax: table memory2()
3294 \begin_layout Standard
3295 Returns array of all valid VMA names.
3298 \begin_layout Subsection
3299 memory2.<vma>:info: Get VMA info
3302 \begin_layout Itemize
3303 Syntax: table memory2.<vma>:info()
3306 \begin_layout Standard
3307 Return table describing given VMA.
3308 Includes fields address, size, last, readonly, special and endian.
3311 \begin_layout Subsection
3312 memory2.<vma>:<op>: Read/Write memory
3315 \begin_layout Itemize
3316 Syntax: none memory2.<vma>:<op>(number offset, number value)
3319 \begin_layout Itemize
3320 Syntax: number memory2.<vma>:<op>(number offset)
3323 \begin_layout Standard
3324 Read/Write value from/to given VMA <vma> at given offset <offset> (must
3326 The value written is <value>.
3327 <Op> is of form: [i][s]<type>, where:
3330 \begin_layout Itemize
3331 <type> is one of 'byte', 'word', 'dword', 'qword'.
3334 \begin_layout Itemize
3335 'i' signifies that the value is treated as opposite-to-normal endianess,
3338 \begin_layout Itemize
3339 's' signifies that value is treated as signed.
3342 \begin_layout Standard
3343 \begin_inset Newpage pagebreak
3349 \begin_layout Section
3353 \begin_layout Standard
3354 Various callback-related functions.
3357 \begin_layout Subsection
3358 \begin_inset CommandInset label
3360 name "sub:callback.register:-Register-a"
3364 callback.register: Register a callback
3367 \begin_layout Itemize
3368 Syntax: function callback.register(string cbname, function cbfun);
3371 \begin_layout Standard
3372 Instruct function <cbfun> to be added to list of callbacks to call on event
3373 <cbname> (See section
3374 \begin_inset CommandInset ref
3376 reference "sec:Callbacks"
3381 The callback name does not have the 'on_' prefix (e.g.
3383 \begin_inset Quotes eld
3387 \begin_inset Quotes erd
3394 \begin_layout Subsection
3395 \begin_inset CommandInset label
3397 name "sub:callback.unregister:-Unregister-"
3401 callback.unregister: Unregister a callback
3404 \begin_layout Itemize
3405 Syntax: function callback.unregister(string cbname, function cbfun);
3408 \begin_layout Standard
3409 Instruct function <cbfun> to be removed from list of callbacks to call on
3413 \begin_layout Subsection
3414 callback.<cbname>:register: Register callback
3417 \begin_layout Itemize
3418 Syntax: function callback.<cbname>:register(function cbfun)
3421 \begin_layout Standard
3422 Synonym for callback.register (section
3423 \begin_inset CommandInset ref
3425 reference "sub:callback.register:-Register-a"
3429 ), albeit with callback name specified differently.
3432 \begin_layout Subsection
3433 callback.<cbname>:unregister: Register callback
3436 \begin_layout Itemize
3437 Syntax: function callback.<cbname>:unregister(function cbfun)
3440 \begin_layout Standard
3441 Synonym for callback.unregister (section
3442 \begin_inset CommandInset ref
3444 reference "sub:callback.unregister:-Unregister-"
3448 ), albeit with callback name specified differently.
3451 \begin_layout Section
3455 \begin_layout Standard
3456 Contains copy of global variables from time of Lua initialization.
3460 \begin_layout Standard
3461 \begin_inset Newpage pagebreak
3467 \begin_layout Section
3468 \begin_inset CommandInset label
3470 name "sec:Callbacks"
3477 \begin_layout Standard
3478 Various callbacks to Lua that can occur.
3481 \begin_layout Subsection
3482 on_paint: Screen is being painted
3485 \begin_layout Itemize
3486 Callback: on_paint(bool not_synth)
3489 \begin_layout Standard
3490 Called when screen is being painted.
3491 Any gui.* calls requiring graphic context draw on the screen.
3494 \begin_layout Itemize
3495 not_synth is true if this hook is being called in response to received frame,
3499 \begin_layout Subsection
3500 on_video: Dumped video frame is being painted
3503 \begin_layout Itemize
3504 Callback: on_video()
3507 \begin_layout Standard
3508 Called when video dump frame is being painted.
3509 Any gui.* calls requiring graphic context draw on the video.
3512 \begin_layout Subsection
3513 on_frame_emulated: Frame emulation complete
3516 \begin_layout Itemize
3517 Callback: on_frame_emulated()
3520 \begin_layout Standard
3521 Called when emulating frame has completed and on_paint()/on_video() calls
3522 are about to be issued.
3525 \begin_layout Subsection
3526 on_frame: Frame emulation starting.
3529 \begin_layout Itemize
3530 Callback: on_frame()
3533 \begin_layout Standard
3534 Called on each starting whole frame.
3537 \begin_layout Subsection
3538 on_startup: Emulator startup complete
3541 \begin_layout Itemize
3542 Callback: on_startup()
3545 \begin_layout Standard
3546 Called when the emulator is starting (lsnes.rc and --run files has been run).
3549 \begin_layout Subsection
3550 on_rewind: Movie rewound to beginning
3553 \begin_layout Itemize
3554 Callback: on_rewind()
3557 \begin_layout Standard
3558 Called when rewind movie to beginning has completed.
3561 \begin_layout Subsection
3562 on_pre_load: Load operation is about to start
3565 \begin_layout Itemize
3566 Callback: on_pre_load(string name)
3569 \begin_layout Standard
3570 Called just before savestate/movie load occurs (note: loads are always delayed,
3571 so this occurs even when load was initiated by lua).
3574 \begin_layout Subsection
3575 on_err_Load: Load failed
3578 \begin_layout Itemize
3579 Callback: on_err_load(string name)
3582 \begin_layout Standard
3583 Called if loadstate goes wrong.
3586 \begin_layout Subsection
3587 on_post_load: Load completed
3590 \begin_layout Itemize
3591 Callback: on_post_load(string name, boolean was_savestate)
3594 \begin_layout Standard
3595 Called on successful loadstate.
3596 was_savestate gives if this was a savestate or a movie.
3599 \begin_layout Subsection
3600 on_pre_save: Save operation is about to start
3603 \begin_layout Itemize
3604 Callback: on_pre_save(string name, boolean is_savestate)
3607 \begin_layout Standard
3608 Called just before savestate save occurs (note: movie saves are synchronous
3609 and won't trigger these callbacks if called from Lua).
3612 \begin_layout Subsection
3613 on_err_save: Save failed
3616 \begin_layout Itemize
3617 Callback: on_err_save(string name)
3620 \begin_layout Standard
3621 Called if savestate goes wrong.
3624 \begin_layout Subsection
3625 on_post_save: Save completed
3628 \begin_layout Itemize
3629 Callback: on_post_save(string name, boolean is_savestate)
3632 \begin_layout Standard
3633 Called on successful savaestate.
3634 is_savestate gives if this was a savestate or a movie.
3637 \begin_layout Subsection
3638 on_quit: Emulator is shutting down
3641 \begin_layout Itemize
3645 \begin_layout Standard
3646 Called when emulator is shutting down.
3649 \begin_layout Subsection
3650 on_input: Polling for input
3653 \begin_layout Standard
3654 Called when emulator is just sending input to bsnes core.
3655 Warning: This is called even in readonly mode, but the results are ignored.
3658 \begin_layout Subsection
3659 on_reset: System has been reset
3662 \begin_layout Itemize
3663 Callback: on_reset()
3666 \begin_layout Standard
3667 Called when system is reset.
3670 \begin_layout Subsection
3671 on_readwrite: Entered readwrite mode
3674 \begin_layout Itemize
3675 Callback: on_readwrite()
3678 \begin_layout Standard
3679 Called when moving into readwrite mode as result of
3680 \begin_inset Quotes eld
3684 \begin_inset Quotes erd
3687 command (note: moving to rwmode by Lua won't trigger this, as per recursive
3691 \begin_layout Subsection
3692 on_snoop/on_snoop2: Snoop core controller reads
3695 \begin_layout Itemize
3696 Callback: on_snoop(number port, number controller, number index, number
3700 \begin_layout Itemize
3701 Callback: on_snoop2(number port, number controller, number index, number
3705 \begin_layout Standard
3706 Called each time bsnes asks for input.
3707 The value is the final value to be sent to bsnes core (readonly mode, autohold
3708 and autofire have been taken into account).
3709 Might be useful when translating movies to format suitable for console
3711 Note: There is no way to modify the value to be sent.
3714 \begin_layout Itemize
3715 On_snoop2 is called instead of on_snoop if defined.
3716 Reserves port 0 for system, having first user port be port 1.
3719 \begin_layout Subsection
3720 on_keyhook: Hooked key/axis has been moved
3723 \begin_layout Itemize
3724 Callback: on_keyhook(string keyname, table state)
3727 \begin_layout Standard
3728 Sent when key that has keyhook events requested changes state.
3729 Keyname is name of the key (group) and state is the state (same kind as
3730 table values in input.raw).
3733 \begin_layout Subsection
3737 \begin_layout Itemize
3741 \begin_layout Standard
3742 Called when requested by set_idle_timeout(), the timeout has expired and
3743 emulator is waiting.
3746 \begin_layout Subsection
3747 on_timer: Timer event
3750 \begin_layout Itemize
3751 Callback: on_timer()
3754 \begin_layout Standard
3755 Called when requested by set_idle_timeout() and the timeout has expired
3756 (regardless if emulator is waiting).
3759 \begin_layout Subsection
3760 on_set_rewind: Rewind point has been set
3763 \begin_layout Itemize
3764 Callback: on_set_rewind(UNSAFEREWIND r)
3767 \begin_layout Standard
3768 Called when unsafe rewind object has been constructed.
3771 \begin_layout Subsection
3772 on_pre_rewind: Rewind is about to occur
3775 \begin_layout Itemize
3776 Callback: on_pre_rewind()
3779 \begin_layout Standard
3780 Called just before unsafe rewind is about to occur.
3783 \begin_layout Subsection
3784 on_post_rewind: Rewind has occured
3787 \begin_layout Itemize
3788 Callback: on_post_rewind()
3791 \begin_layout Standard
3792 Called just after unsafe rewind has occured.
3795 \begin_layout Subsection
3796 on_button: Button has been pressed
3799 \begin_layout Itemize
3800 Callback: on_button(number port, number controller, number index, string
3804 \begin_layout Standard
3805 Called on controller button press, with following parameters:
3808 \begin_layout Itemize
3809 port: Port number (0 is system)
3812 \begin_layout Itemize
3813 controller: Controller within port
3816 \begin_layout Itemize
3817 index: Index of button.
3820 \begin_layout Itemize
3821 type: Type of event, one of:
3825 \begin_layout Itemize
3826 \begin_inset Quotes eld
3830 \begin_inset Quotes erd
3833 : Button was pressed.
3836 \begin_layout Itemize
3837 \begin_inset Quotes eld
3841 \begin_inset Quotes erd
3844 : Button was released.
3847 \begin_layout Itemize
3848 \begin_inset Quotes eld
3852 \begin_inset Quotes erd
3858 \begin_layout Itemize
3859 \begin_inset Quotes eld
3863 \begin_inset Quotes erd
3866 : Released from hold.
3869 \begin_layout Itemize
3870 \begin_inset Quotes eld
3874 \begin_inset Quotes erd
3877 : Typing input on button.
3880 \begin_layout Itemize
3881 \begin_inset Quotes eld
3885 \begin_inset Quotes erd
3888 : Typing input undone.
3891 \begin_layout Itemize
3892 \begin_inset Quotes eld
3895 autofire <duty> <cycle>
3896 \begin_inset Quotes erd
3899 : Autofire with specifie duty and cycle.
3902 \begin_layout Itemize
3903 \begin_inset Quotes eld
3907 \begin_inset Quotes erd
3913 \begin_layout Itemize
3914 \begin_inset Quotes eld
3918 \begin_inset Quotes erd
3921 : Analog action on axis.
3925 \begin_layout Subsection
3926 on_movie_lost: Movie data is about to be lost
3929 \begin_layout Itemize
3930 Callback: on_movie_lost(STRING kind)
3933 \begin_layout Standard
3934 Called just before something would happen that could lose movie data.
3938 \begin_layout Itemize
3939 readwrite: Switching to readwrite mode.
3942 \begin_layout Itemize
3943 reload: ROM is being reloaded in readwrite mode.
3946 \begin_layout Itemize
3947 load: New movie is being loaded.
3950 \begin_layout Itemize
3951 unsaferewind: Unsafe rewind is happening.