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.subframe_update: Enable/Disable subframe updates
1459 \begin_layout Itemize
1460 Syntax: none gui.subframe_update(boolean on)
1463 \begin_layout Standard
1464 Request subframe updates (calling on_paint() on subframes) to happen (<on>=true)
1465 or not happen (<on>=false).
1468 \begin_layout Subsection
1469 gui.screenshot: Write a screenshot
1472 \begin_layout Itemize
1473 Syntax: none gui.screenshot(string filename)
1476 \begin_layout Standard
1477 Write PNG screenshot of the current frame (no drawings) to specified file
1481 \begin_layout Subsection
1482 gui.color: Compose a color.
1485 \begin_layout Itemize
1486 Syntax: number gui.color(number r, number g, number b[, number a])
1489 \begin_layout Standard
1490 Returns color (in notation Lua scripts use) corresponding to color (<r>,<g>,<b>)
1491 , each component in scale 0-255.
1492 If <a> is specified, that is alpha (0 is fully transparent, 256(sic) is
1494 The default alpha is 256.
1497 \begin_layout Subsection
1498 gui.status: Set status variable
1501 \begin_layout Itemize
1502 Syntax: none gui.status(string name, string value)
1505 \begin_layout Standard
1507 \begin_inset Quotes eld
1511 \begin_inset Quotes erd
1514 to <value> in status area.
1517 \begin_layout Subsection
1518 gui.rainbow: Rainbow color calculation
1521 \begin_layout Itemize
1522 Syntax: number gui.rainbow(number step, number steps[, number color])
1525 \begin_layout Standard
1526 Perform hue rotation of color <color> (default bright red), by <step> steps.
1527 The number of steps per full rotation is given by absolute value of <steps>.
1530 \begin_layout Standard
1531 If <steps> is negative, the rotation will be counterclockwise.
1534 \begin_layout Subsection
1535 gui.renderq_new: Create a render queue
1538 \begin_layout Itemize
1539 Syntax: RENDERQUEUE gui.renderq_new(number width, number height)
1542 \begin_layout Standard
1543 Create render queue with specified reported size and return it.
1546 \begin_layout Subsection
1547 gui.renderq_clear: Clear a render queue
1550 \begin_layout Itemize
1551 Syntax: none gui.renderq_clear(RENDERQUEUE queue)
1554 \begin_layout Standard
1555 Clear specified render queue.
1558 \begin_layout Subsection
1559 gui.renderq_set: Change active render queue
1562 \begin_layout Itemize
1563 Syntax: none gui.renderq_set(RENDERQUEUE queue)
1566 \begin_layout Standard
1567 Switch to specified render queue.
1568 Use nil as queue to switch to default queue.
1571 \begin_layout Itemize
1572 Note: When switched to another queue, all drawing functions work and draw
1573 there, even outside on_video/on_paint.
1576 \begin_layout Subsection
1577 gui.renderq_run: Run render queue
1580 \begin_layout Itemize
1581 Syntax: none gui.renderq_run(RENDERQUEUE queue)
1584 \begin_layout Standard
1585 Run specified render queue, copying the objects to current render queue.
1589 \begin_layout Itemize
1590 Warning: Don't try to run the current render queue.
1593 \begin_layout Subsection
1594 gui.loadfont: Load a font file
1597 \begin_layout Itemize
1598 Syntax: CUSTOMFONT gui.loadfont(string filename)
1601 \begin_layout Standard
1602 Loads font from specified file (CUSTOMFONT object).
1605 \begin_layout Subsection
1606 CUSTOMFONT(): Render text to screen
1609 \begin_layout Itemize
1610 Syntax: none CUSTOMFONT(number x, number y, string text[, number fgc[, number
1611 bgc[, number hlc]]])
1614 \begin_layout Standard
1615 Draw string with custom font to screen.
1616 The parameters are the same as in gui.text, except <hlc> is the halo color
1617 (default is no halo).
1621 \begin_layout Subsection
1622 gui.adjust_transparency: Adjust transparency of DBITMAP or PALETTE
1625 \begin_layout Itemize
1626 Syntax: none gui.adjust_transparency(DBITMAP obj, number adj)
1629 \begin_layout Itemize
1630 Syntax: none gui.adjust_transparency(PALETTE obj, number adj)
1633 \begin_layout Standard
1634 Multiply alpha channel of <obj> by <adj>/256.
1636 \begin_inset Quotes eld
1640 \begin_inset Quotes erd
1643 out of solid bitmaps.
1646 \begin_layout Subsection
1647 gui.kill_frame: Kill video frame and associated sound
1650 \begin_layout Itemize
1651 Syntax: none gui.kill_frame()
1654 \begin_layout Standard
1655 Kills the currently dumped video frame + the associated sound.
1656 Only valid in on_video callback.
1659 \begin_layout Standard
1660 \begin_inset Newpage pagebreak
1666 \begin_layout Section
1670 \begin_layout Standard
1672 Functions manipulating input are only available in on_input callback.
1675 \begin_layout Subsection
1676 input.get: Read controller button/axis (deprecated)
1679 \begin_layout Itemize
1680 Syntax: number input.get(number controller, number index)
1683 \begin_layout Standard
1684 Read the specified index <index> (zero-based) from specified controller
1685 <controller> (zero-based).
1689 \begin_layout Subsection
1690 input.set: Write controller button/axis (deprecated)
1693 \begin_layout Itemize
1694 Syntax: none input.set(number controller, number index, number value)
1697 \begin_layout Standard
1698 Write the specified index <index> (zero-based) from specified controller
1699 <controller> (zero-based), storing value <value>.
1702 \begin_layout Subsection
1703 input.get2: Read controller button/axis
1706 \begin_layout Itemize
1707 Syntax: number input.get2(number port, number controller, number index)
1710 \begin_layout Standard
1711 Read the specified input tuple.
1712 Port 0 is system port.
1715 \begin_layout Subsection
1716 input.set2: Write controller button/axis
1719 \begin_layout Itemize
1720 Syntax: input.set2(number port, number controller, number index, number value)
1723 \begin_layout Standard
1724 Write the specified input tuple.
1725 Port 0 is system port.
1728 \begin_layout Subsection
1729 input.lcid_to_pcid2: Look up logical controller
1732 \begin_layout Itemize
1733 Syntax: (number, number) input.lcid_to_pcid2(number lcid)
1736 \begin_layout Standard
1737 Look up physical pcid pair (port, controller) corresponding to specified
1738 logical controller (1-based).
1739 Returns nothing if controller does not exist.
1742 \begin_layout Subsection
1743 input.port_type: Look up port type
1746 \begin_layout Itemize
1747 Syntax: string input.port_type(number port)
1750 \begin_layout Standard
1751 Return type of specified port.
1754 \begin_layout Subsection
1755 input.controller_info: Get information about controller
1758 \begin_layout Itemize
1759 Syntax: table input.controller_info(number port, number controller)
1762 \begin_layout Standard
1763 Get controller info for specified controller.
1764 If controller does not exist, returns nil.
1765 Otherwise returns a table with following fields:
1768 \begin_layout Itemize
1769 type (string): Type of the controller.
1772 \begin_layout Itemize
1773 class (string): Class of the controller.
1776 \begin_layout Itemize
1777 classnum (number): Number of the controller within its class (1-based)
1780 \begin_layout Itemize
1781 lcid (number): Logical controller number of the controller.
1784 \begin_layout Itemize
1785 button_count (number): Number of buttons on controller
1788 \begin_layout Itemize
1789 buttons (array): Array of following info about each button:
1793 \begin_layout Itemize
1794 type (string): Type of button.
1796 \begin_inset Quotes eld
1800 \begin_inset Quotes erd
1804 \begin_inset Quotes eld
1808 \begin_inset Quotes erd
1812 \begin_inset Quotes eld
1816 \begin_inset Quotes erd
1820 \begin_inset Quotes eld
1824 \begin_inset Quotes erd
1830 \begin_layout Itemize
1831 name (string): Name of button.
1834 \begin_layout Itemize
1835 symbol (string): Symbol of button.
1836 Only present for type
1837 \begin_inset Quotes eld
1841 \begin_inset Quotes erd
1847 \begin_layout Itemize
1848 hidden (boolean): True if hidden button.
1853 \begin_layout Subsection
1854 input.veto_button: Veto a button press
1857 \begin_layout Itemize
1858 Syntax: none input.veto_button()
1861 \begin_layout Standard
1862 Signals that the button event should be vetoed.
1863 Only valid in on_button callback.
1866 \begin_layout Subsection
1867 input.geta: Get all buttons for controller (deprecated)
1870 \begin_layout Itemize
1871 Syntax: (number, number...) input.geta(number controller)
1874 \begin_layout Standard
1875 Get input state for entiere controller.
1876 Returns n return values.
1879 \begin_layout Itemize
1880 1st return value: Bitmask: bit i is set if i:th index is nonzero
1883 \begin_layout Itemize
1884 2nd- return value: value of i:th index.
1887 \begin_layout Subsection
1888 input.seta: Set all buttons for controller (deprecated)
1891 \begin_layout Itemize
1892 Syntax: none input.seta(number controller, number bitmask, number args...)
1895 \begin_layout Standard
1896 Set state for entiere controller.
1897 args is up to N values for indices (overriding values in bitmask if specified).
1900 \begin_layout Subsection
1901 input.controllertype: Get controller type (deprecated)
1904 \begin_layout Itemize
1905 syntax: string input.controllertype(number controller)
1908 \begin_layout Standard
1909 Get the type of controller as string.
1912 \begin_layout Subsection
1913 input.reset: Execute (delayed) reset
1916 \begin_layout Itemize
1917 Syntax: none input.reset([number cycles])
1920 \begin_layout Standard
1922 If <cycles> is greater than zero, do delayed reset.
1923 0 (or no value) causes immediate reset.
1926 \begin_layout Itemize
1927 Note: Only available with subframe flag false.
1930 \begin_layout Subsection
1931 input.raw: Return raw input data
1934 \begin_layout Itemize
1935 Syntax: table input.raw()
1938 \begin_layout Standard
1939 Returns table of tables of all available keys and axes.
1940 The first table is indexed by key name (platform-dependent!), and the inner
1941 table has the following fields:
1944 \begin_layout Itemize
1945 value: Last reported value for control
1949 \begin_layout Itemize
1950 For keys: 1 for pressed, 0 for released.
1953 \begin_layout Itemize
1954 For axes: -32767...32767.
1957 \begin_layout Itemize
1958 For presure-sensitive buttons: 0...32767.
1961 \begin_layout Itemize
1962 For hats: Bitmask: 1=>Up, 2=>Right, 4=>Down, 8=>Left.
1965 \begin_layout Itemize
1966 For mouse: Coordinates relative to game area.
1970 \begin_layout Itemize
1971 ktype: Type of key (disabled, key, mouse, axis, hat, pressure).
1974 \begin_layout Subsection
1975 input.keyhook: Hook a key
1978 \begin_layout Itemize
1979 Syntax: none input.keyhook(string key, boolean state)
1982 \begin_layout Standard
1983 Requests that keyhook events to be sent for key <key> (<state>=true) or
1984 not sent (<state>=false).
1987 \begin_layout Subsection
1988 input.joyget: Get controls for controller
1991 \begin_layout Itemize
1992 Syntax: table input.joyget(number logical)
1995 \begin_layout Standard
1996 Returns table for current controls for specified logical controller <logical>.
1997 The names of fields vary by controller type.
2000 \begin_layout Itemize
2001 The buttons have the same name as those are referred to in other contexts
2005 \begin_layout Itemize
2006 The analog axes are usually
2007 \begin_inset Quotes eld
2011 \begin_inset Quotes erd
2015 \begin_inset Quotes eld
2019 \begin_inset Quotes erd
2025 \begin_layout Itemize
2026 Each field is numeric or boolean depending on axis/button.
2029 \begin_layout Subsection
2030 input.joyset: Set controls for controller
2033 \begin_layout Itemize
2034 Syntax: none input.joyset(number controller, table controls)
2037 \begin_layout Standard
2038 Set the the state of specified controller to values specified in specified
2042 \begin_layout Itemize
2043 Each field can be boolean or number.
2046 \begin_layout Itemize
2047 Also, buttons allow strings, which cause value to be inverted.
2050 \begin_layout Subsection
2051 input.lcid_to_pcid: Look up logical controller (deprecated)
2054 \begin_layout Itemize
2055 Syntax: (number, number, number) input.lcid_to_pcid(number lcid)
2058 \begin_layout Standard
2059 Returns the legacy pcid for controller (or false if there isn't one), followed
2061 Returns nothing if controller does not exist.
2064 \begin_layout Standard
2065 \begin_inset Newpage pagebreak
2071 \begin_layout Section
2075 \begin_layout Standard
2076 Various keybinding-related functions
2079 \begin_layout Subsection
2080 keyboard.bind: Bind a key
2083 \begin_layout Itemize
2084 Syntax: none keyboard.bind(string mod, string mask, string key, string cmd)
2087 \begin_layout Standard
2088 Bind specified key with specified modifers to specified command.
2091 \begin_layout Subsection
2092 keyboard.unbind: Unbind a key
2095 \begin_layout Itemize
2096 Syntax: none keyboard.unbind(string mod, string mask, string key)
2099 \begin_layout Standard
2100 Unbind specified key with specified modifers.
2103 \begin_layout Subsection
2104 keyboard.alias: Set alias expansion
2107 \begin_layout Itemize
2108 Syntax: none keyboard.alias(string alias, string expansion)
2111 \begin_layout Standard
2112 Set expansion of given command.
2115 \begin_layout Standard
2116 \begin_inset Newpage pagebreak
2122 \begin_layout Section
2126 \begin_layout Standard
2130 \begin_layout Subsection
2131 subtitle.byindex: Look up start and length of subtitle by index
2134 \begin_layout Itemize
2135 Syntax: (number, number) subtitle.byindex(number i)
2138 \begin_layout Standard
2139 Read the frame and length of ith subtitle.
2140 Returns nothing if not present.
2143 \begin_layout Subsection
2144 subtitle.set: Write a subtitle
2147 \begin_layout Itemize
2148 Syntax: none subtitle.set(number f, number l, string txt)
2151 \begin_layout Standard
2152 Set the text of subtitle.
2155 \begin_layout Subsection
2156 subtitle.get: Read a subtitle
2159 \begin_layout Itemize
2160 Syntax: string subtitle.get(number f, number l)
2163 \begin_layout Standard
2164 Get the text of subtitle.
2167 \begin_layout Subsection
2168 subtitle.delete: Delete a subtitle
2171 \begin_layout Itemize
2172 Syntax: nonesubtitle.delete(number f, number l)
2175 \begin_layout Standard
2176 Delete specified subtitle.
2179 \begin_layout Standard
2180 \begin_inset Newpage pagebreak
2186 \begin_layout Section
2190 \begin_layout Standard
2191 Host memory handling (extra memory saved to savestates).
2192 Host memory starts empty.
2195 \begin_layout Itemize
2196 Reads out of range return false.
2199 \begin_layout Itemize
2200 Writes out of range extend the memory.
2203 \begin_layout Subsection
2204 hostmemory.read: Read byte from host memory
2207 \begin_layout Itemize
2208 Syntax: number hostmemory.read(number address)
2211 \begin_layout Standard
2212 Reads byte from hostmemory slot address <address>.
2215 \begin_layout Subsection
2216 hostmemory.write: Write byte to host memory
2219 \begin_layout Itemize
2220 Syntax: none hostmemory.write(number address, number value)
2223 \begin_layout Standard
2224 Writes hostmemory slot with value <value> 0-255.
2227 \begin_layout Subsection
2228 hostmemory.read{,s}{byte,{,d,q}word}: Read from host memory
2231 \begin_layout Itemize
2232 Syntax: number hostmemory.readbyte(number address)
2235 \begin_layout Itemize
2236 Syntax: number hostmemory.readsbyte(number address)
2239 \begin_layout Itemize
2240 Syntax: number hostmemory.readword(number address)
2243 \begin_layout Itemize
2244 Syntax: number hostmemory.readsword(number address)
2247 \begin_layout Itemize
2248 Syntax: number hostmemory.readdword(number address)
2251 \begin_layout Itemize
2252 Syntax: number hostmemory.readsdword(number address)
2255 \begin_layout Itemize
2256 Syntax: number hostmemory.readqword(number address)
2259 \begin_layout Itemize
2260 Syntax: number hostmemory.readsqword(number address)
2263 \begin_layout Standard
2264 Read elements (little-endian) from given address <address>.
2267 \begin_layout Itemize
2271 \begin_layout Itemize
2275 \begin_layout Itemize
2279 \begin_layout Itemize
2280 qword is 8 elements.
2283 \begin_layout Itemize
2284 The 's' variants do signed read.
2287 \begin_layout Subsection
2288 hostmemory.write{,s}{byte,{,d,q}word}: Write to host memory
2291 \begin_layout Itemize
2292 Syntax: number hostmemory.writebyte(number address, number value)
2295 \begin_layout Itemize
2296 Syntax: number hostmemory.writesbyte(number address, number value)
2299 \begin_layout Itemize
2300 Syntax: number hostmemory.writeword(number address, number value)
2303 \begin_layout Itemize
2304 Syntax: number hostmemory.writesword(number address, number value)
2307 \begin_layout Itemize
2308 Syntax: number hostmemory.writedword(number address, number value)
2311 \begin_layout Itemize
2312 Syntax: number hostmemory.writesdword(number address, number value)
2315 \begin_layout Itemize
2316 Syntax: number hostmemory.writeqword(number address, number value)
2319 \begin_layout Itemize
2320 Syntax: number hostmemory.writesqword(number address, number value)
2323 \begin_layout Standard
2324 Write value <value> to elements (little-endian) starting from given address
2328 \begin_layout Itemize
2332 \begin_layout Itemize
2336 \begin_layout Itemize
2340 \begin_layout Itemize
2341 qword is 8 elements.
2344 \begin_layout Itemize
2345 The 's' variants do signed write.
2348 \begin_layout Standard
2349 \begin_inset Newpage pagebreak
2355 \begin_layout Section
2359 \begin_layout Standard
2363 \begin_layout Subsection
2364 movie.currentframe: Get current frame number
2367 \begin_layout Itemize
2368 Syntax: number movie.currentframe()
2371 \begin_layout Standard
2372 Return number of current frame.
2375 \begin_layout Subsection
2376 movie.framecount: Get move frame count
2379 \begin_layout Itemize
2380 Syntax: number movie.framecount()
2383 \begin_layout Standard
2384 Return number of frames in movie.
2387 \begin_layout Subsection
2388 movie.readonly: Is in readonly mode?
2391 \begin_layout Itemize
2392 Syntax: boolean movie.readonly()
2395 \begin_layout Standard
2396 Return true if in readonly mode, false if in readwrite.
2399 \begin_layout Subsection
2400 movie.rerecords: Movie rerecord count
2403 \begin_layout Itemize
2404 Syntax: number movie.rerecords()
2407 \begin_layout Standard
2408 Returns the current value of rerecord count.
2411 \begin_layout Subsection
2412 movie.set_readwrite: Set read-write mode.
2415 \begin_layout Itemize
2416 Syntax: none movie.set_readwrite()
2419 \begin_layout Standard
2420 Set readwrite mode (does not cause on_readwrite callback).
2423 \begin_layout Subsection
2424 movie.frame_subframes: Count subframes in frame
2427 \begin_layout Itemize
2428 Syntax: number movie.frame_subframes(number frame)
2431 \begin_layout Standard
2432 Count number of subframes in specified frame <frame> (frame numbers are
2433 1-based) and return that.
2436 \begin_layout Subsection
2437 movie.read_subframes: Read subframe data (deprecated)
2440 \begin_layout Itemize
2441 Syntax: table movie.read_subframes(number frame, number subframe)
2444 \begin_layout Standard
2445 Read specifed subframe in specified frame and return data as array.
2448 \begin_layout Subsection
2449 movie.read_rtc: Read current RTC time
2452 \begin_layout Itemize
2453 Syntax: (number, number) movie.read_rtc()
2456 \begin_layout Standard
2457 Returns the current value of the RTC as a pair (second, subsecond).
2460 \begin_layout Subsection
2461 movie.unsafe_rewind: Fast movie rewind to saved state
2464 \begin_layout Itemize
2465 Syntax: none movie.unsafe_rewind([UNSAFEREWIND state])
2468 \begin_layout Standard
2469 Start setting point for unsafe rewind or jump to point of unsafe rewind.
2472 \begin_layout Itemize
2473 If called without argument, causes emulator to start process of setting
2474 unsafe rewind point.
2475 When this has finished, callback on_set_rewind occurs, passing the rewind
2476 state to lua script.
2479 \begin_layout Itemize
2480 If called with argument, causes emulator rewind to passed rewind point as
2482 Readwrite mode is implicitly activated.
2485 \begin_layout Standard
2486 The following warnings apply to unsafe rewinding:
2489 \begin_layout Itemize
2490 There are no safety checks against misuse (that's what
2491 \begin_inset Quotes eld
2495 \begin_inset Quotes erd
2501 \begin_layout Itemize
2502 Only call rewind from timeline rewind point was set from.
2505 \begin_layout Itemize
2506 Only call rewind from after the rewind point was set.
2509 \begin_layout Subsection
2510 movie.to_rewind: Load savestate as rewind point
2513 \begin_layout Itemize
2514 Syntax: UNSAFEREWIND movie.to_rewind(string filename)
2517 \begin_layout Standard
2518 Load specified savestate file <filename> as rewind point and return UNSAFEREWIND
2519 corresponding to it.
2522 \begin_layout Itemize
2523 Note: This operation does not take emulated time.
2526 \begin_layout Subsection
2527 movie.copy_movie/INPUTMOVIE::copy_movie: Copy movie to movie object
2530 \begin_layout Itemize
2531 Syntax: INPUTMOVIE movie.copy_movie([INPUTMOVIE movie])
2534 \begin_layout Itemize
2535 Syntax: INPUTMOVIE INPUTMOVIE::copy_movie()
2538 \begin_layout Standard
2539 Copies specified movie <movie>/current object (if none or nil, the active
2540 movie) as new movie object.
2543 \begin_layout Subsection
2544 movie.get_frame/INPUTMOVIE::get_frame: Read specified frame in movie.
2547 \begin_layout Itemize
2548 Syntax: INPUTFRAME movie.get_frame([INPUTMOVIE movie,] number frame)
2551 \begin_layout Itemize
2552 Syntax: INPUTFRAME INPUTMOVIE::get_frame(number frame);
2555 \begin_layout Standard
2556 Get INPUTFRAME object corresponding to specified frame in specified movie.
2559 \begin_layout Subsection
2560 movie.set_frame/INPUTMOVIE::set_frame: Write speicifed frame in movie.
2563 \begin_layout Itemize
2564 Syntax: none movie.set_frame([INPUTMOVIE movie,] number frame, INPUTFRAME
2568 \begin_layout Itemize
2569 Syntax: none INPUTMOVIE::set_frame(number frame, INPUTFRAME data)
2572 \begin_layout Standard
2573 Set data in specified frame.
2576 \begin_layout Itemize
2577 Note: Past can't be edited in active movie.
2580 \begin_layout Subsection
2581 movie.get_size/INPUTMOVIE::get_size: Get size of movie
2584 \begin_layout Itemize
2585 Syntax: integer movie.get_size([INPUTMOVIE movie])
2588 \begin_layout Itemize
2589 Syntax: integer INPUTMOVIE::get_size()
2592 \begin_layout Standard
2593 Return number of subframes in specified movie.
2596 \begin_layout Subsection
2597 movie.count_frames/INPUTMOVIE::count_frames: Count frames in movie
2600 \begin_layout Itemize
2601 Syntax: number movie.count_frames([INPUTMOVIE movie])
2604 \begin_layout Itemize
2605 Syntax: number INPUTMOVIE::count_frames()
2608 \begin_layout Standard
2609 Return number of frames in movie.
2612 \begin_layout Subsection
2613 movie.find_frame/INPUTMOVIE::find_frame: Find subframe corresponding to frame
2616 \begin_layout Itemize
2617 Syntax: number movie.find_frame([INPUTMOVIE movie], number frame)
2620 \begin_layout Itemize
2621 Syntax: number INPUTMOVIE::find_frame(number frame)
2624 \begin_layout Standard
2625 Returns starting subframe of given frame (frame numbers are 1-based).
2626 Returns -1 if frame number is bad.
2629 \begin_layout Subsection
2630 movie.blank_frame/INPUTMOVIE::blank_frame: Return a blank frame
2633 \begin_layout Itemize
2634 Syntax: INPUTFRAME movie.blank_frame([INPUTMOVIE movie])
2637 \begin_layout Itemize
2638 Syntax: INPUTFRAME INPUTMOVIE::blank_frame()
2641 \begin_layout Standard
2642 Return blank INPUTFRAME with frame type from specified movie.
2645 \begin_layout Subsection
2646 movie.append_frames/INPUTMOVIE::append_frames: Append blank frames
2649 \begin_layout Itemize
2650 Syntax: none movie.append_frames([INPUTMOVIE movie,] number frames)
2653 \begin_layout Itemize
2654 Syntax: none INPUTMOVIE::append_frames(number frames)
2657 \begin_layout Standard
2658 Append specified number <frames> of frames.
2661 \begin_layout Subsection
2662 movie.append_frame/INPUTMOVIE::append_frame: Append a frame
2665 \begin_layout Itemize
2666 Syntax: none movie.append_frame([INPUTMOVIE movie,] INPUTFRAME frame)
2669 \begin_layout Itemize
2670 Syntax: none INPUTMOVIE::append_frame(INPUTFRAME frame)
2673 \begin_layout Standard
2674 Append specified frame <frame>.
2675 Past of current movie can't be edited.
2678 \begin_layout Subsection
2679 movie.truncate/INPUTMOVIE::truncate: Truncate a movie.
2682 \begin_layout Itemize
2683 Syntax: none movie.truncate([INPUTMOVIE movie,] number frames)
2686 \begin_layout Itemize
2687 Syntax: none INPUTMOVIE::truncate(number frames)
2690 \begin_layout Standard
2691 Truncate the specified movie to specified number of frames.
2694 \begin_layout Subsection
2695 movie.edit/INPUTMOVIE::edit: Edit a movie
2698 \begin_layout Itemize
2699 Syntax: none movie.edit([INPUTMOVIE movie,] number frame, number port, number
2700 controller, number control, number/bool value)
2703 \begin_layout Itemize
2704 Syntax: none INPUTMOVIE::edit(number frame, number port, number controller,
2705 number control, number/bool value)
2708 \begin_layout Standard
2709 Change specified control in specified frame in specified movie.
2710 Past can't be edited in active movie.
2713 \begin_layout Subsection
2714 movie.copy_frames2: Copy frames between movies
2717 \begin_layout Itemize
2718 Syntax: none movie.copy_frames2([INPUTMOVIE dstmov,] number dst, [INPUTMOVIE
2719 srcmov,] number src, number count)
2722 \begin_layout Standard
2723 Copy specified number of frames between two movies.
2724 The copy proceeeds in forward direction.
2727 \begin_layout Subsection
2728 movie.copy_frames/INPUTMOVIE::copy_frames: Copy frames in movie
2731 \begin_layout Itemize
2732 Syntax: none movie.copy_frames([INPUTMOVIE mov,] number dst, number src,
2733 number count, bool backwards)
2736 \begin_layout Itemize
2737 Syntax: none INPUTMOVIE::copy_frames(number dst, number src, number count,
2741 \begin_layout Standard
2742 Copy specified number of frames from one point in movie to another.
2743 If backwards is true, the copy will be done backwards.
2746 \begin_layout Subsection
2747 movie.serialize/INPUTMOVIE::serialize: Serialize movie
2750 \begin_layout Itemize
2751 Syntax: none movie.serialize([INPUTMOVIE movie,] string filename, bool binary)
2754 \begin_layout Itemize
2755 Syntax: none INPUTMOIVE::serialize(string filename, bool binary)
2758 \begin_layout Standard
2759 Serialize given movie into file.
2760 If binary is true, binary format (more compact and much faster) is used.
2763 \begin_layout Subsection
2764 movie.unserialize: Unserialize movie
2767 \begin_layout Itemize
2768 Syntax: INPUTMOVIE movie.unserialize(INPUTFRAME template, string filename,
2772 \begin_layout Standard
2773 Unserialize movie from file.
2774 The given frame is used as template to decide the frame type.
2775 If binary is true, binary format is decoded (much faster).
2778 \begin_layout Subsection
2779 movie.current_first_subframe: Return first subframe in current frame
2782 \begin_layout Itemize
2783 Syntax: number movie.current_first_subframe()
2786 \begin_layout Standard
2787 Returns first subframe in current frame.
2790 \begin_layout Subsection
2791 movie.pollcounter: Return poll counter for speified control
2794 \begin_layout Itemize
2795 Syntax: number movie.pollcounter(number port, number controller, number control)
2798 \begin_layout Standard
2799 Returns number of times the specified control has been polled this frame.
2802 \begin_layout Subsection
2803 INPUTFRAME::get_button: Get button
2806 \begin_layout Itemize
2807 Syntax: boolean INPUTFRAME::get_button(number port, number controller, number
2811 \begin_layout Standard
2812 Returns state of given button as boolean.
2815 \begin_layout Subsection
2816 INPUTFRAME::get_axis: Get axis
2819 \begin_layout Itemize
2820 Syntax: number INPUTFRAME::get_axis(number port, number controller, number
2824 \begin_layout Standard
2825 Returns state of given axis as number.
2828 \begin_layout Subsection
2829 INPUTFRAME::set_button/INPUTFRAME::set_axis: Set button or axis
2832 \begin_layout Itemize
2833 Syntax: none INPUTFRAME::set_button(number port, number controller, number
2834 control, number/bool value)
2837 \begin_layout Itemize
2838 Syntax: none INPUTFRAME::set_axis(number port, number controller, number
2842 \begin_layout Standard
2843 Set the given button/axis to given value.
2846 \begin_layout Subsection
2847 INPUTFRAME::serialize: Serialize a frame
2850 \begin_layout Itemize
2851 Syntax: string INPUTFRAME::serialize()
2854 \begin_layout Standard
2855 Return string representation of frame.
2858 \begin_layout Subsection
2859 INPUTFRAME::unserialize: Unserialize a frame
2862 \begin_layout Itemize
2863 Syntax: none INPUTFRAME::unserialize(string data)
2866 \begin_layout Standard
2867 Set current frame from given data.
2870 \begin_layout Subsection
2871 INPUTFRAME::get_stride: Get movie stride
2874 \begin_layout Itemize
2875 Syntax: number INPUTFRAME::get_stride()
2878 \begin_layout Standard
2879 Return number of bytes needed to store the input frame.
2880 Mainly useful for some debugging.
2883 \begin_layout Standard
2884 \begin_inset Newpage pagebreak
2890 \begin_layout Section
2894 \begin_layout Standard
2895 Routines for settings manipulation
2898 \begin_layout Subsection
2899 settings.get: Get value of setting
2902 \begin_layout Itemize
2903 Syntax: string settings.get(string name)
2906 \begin_layout Standard
2907 Get value of setting <name>.
2908 If setting value can't be obtained, returns (nil, error message).
2911 \begin_layout Subsection
2912 settings.set: Set value of setting
2915 \begin_layout Itemize
2916 Syntax: none settings.set(string name, string value)
2919 \begin_layout Standard
2920 Set value <value> of setting <name>.
2921 If setting can't be set, returns (nil, error message).
2924 \begin_layout Standard
2925 \begin_inset Newpage pagebreak
2931 \begin_layout Section
2935 \begin_layout Standard
2936 Contains various functions for managing memory
2939 \begin_layout Subsection
2940 memory.vma_count: Count number of VMAs.
2943 \begin_layout Itemize
2944 Syntax: number memory.vma_count()
2947 \begin_layout Standard
2948 Returns the number of VMAs
2951 \begin_layout Subsection
2952 memory.read_vma: Lookup VMA info by index
2955 \begin_layout Itemize
2956 Syntax: string memory.read_vma(number index)
2959 \begin_layout Standard
2960 Reads the specified VMA (indices start from zero).
2961 Trying to read invalid VMA gives nil.
2962 The read VMA is table with the following fields:
2965 \begin_layout Itemize
2966 region_name (string): The readable name of the VMA
2969 \begin_layout Itemize
2970 baseaddr (number): Base address of the VMA
2973 \begin_layout Itemize
2974 lastaddr (number): Last address in the VMA.
2977 \begin_layout Itemize
2978 size (number): The size of VMA in bytes.
2981 \begin_layout Itemize
2982 readonly (boolean): True of the VMA corresponds to ROM.
2985 \begin_layout Itemize
2986 iospace (boolean): True if the VMA is I/O space.
2989 \begin_layout Itemize
2990 native_endian (boolean): True if the VMA has native endian as opposed to
2994 \begin_layout Subsection
2995 memory.find_vma: Find VMA info by address
2998 \begin_layout Itemize
2999 Syntax: table memory.find_vma(number address)
3002 \begin_layout Standard
3003 Finds the VMA containing specified address.
3004 Returns table in the same format as read_vma or nil if not found.
3007 \begin_layout Subsection
3008 memory.read{,s}{byte,{,d,q}word}: Write memory
3011 \begin_layout Itemize
3012 Syntax: none memory.readbyte([string vma, ]number address)
3015 \begin_layout Itemize
3016 Syntax: none memory.readword([string vma, ]number address)
3019 \begin_layout Itemize
3020 Syntax: none memory.readdword([string vma, ]number address)
3023 \begin_layout Itemize
3024 Syntax: none memory.readqword([string vma, ]number address)
3027 \begin_layout Itemize
3028 Syntax: none memory.readsbyte([string vma, ]number address)
3031 \begin_layout Itemize
3032 Syntax: none memory.readsword([string vma, ]number address)
3035 \begin_layout Itemize
3036 Syntax: none memory.readsdword([string vma, ]number address)
3039 \begin_layout Itemize
3040 Syntax: none memory.readsqword([string vma, ]number address)
3043 \begin_layout Standard
3044 Reads the specified address <ddress> (if 's' variant is used, do undergo
3048 \begin_layout Subsection
3049 memory.write{byte,{,d,q}word}: Write memory
3052 \begin_layout Itemize
3053 Syntax: none memory.writebyte([string vma, ]number address, number value)
3056 \begin_layout Itemize
3057 Syntax: none memory.writeword([string vma, ]number address, number value)
3060 \begin_layout Itemize
3061 Syntax: none memory.writedword([string vma, ]number address, number value)
3064 \begin_layout Itemize
3065 Syntax: none memory.writeqword([string vma, ]number address, number value)
3068 \begin_layout Standard
3069 Writes the specified value <value> (negative values undergo 2's complement)
3070 to specified address <address>.
3073 \begin_layout Subsection
3074 memory.map{,s}{byte,{,d,q}word}: Map an array
3077 \begin_layout Itemize
3078 Syntax: userdata memory.map<type>([[string vma, ]number base, number size])
3081 \begin_layout Standard
3082 Returns a table mapping specified memory aperture for read/write.
3083 If parameters are omitted, entiere map space is the aperture.
3086 \begin_layout Itemize
3087 Type may be one of: byte, sbyte, word, sword, dword, sdword, qword or sqword.
3090 \begin_layout Subsection
3091 memory.hash_region: Hash region of memory
3094 \begin_layout Itemize
3095 Syntax: string memory.hash_region([string vma, ]number base, number size)
3098 \begin_layout Standard
3099 Hash specified number of bytes starting from specified address and return
3103 \begin_layout Subsection
3104 memory.hash_state: Hash system state
3107 \begin_layout Itemize
3108 Syntax: string memory.hash_state()
3111 \begin_layout Standard
3112 Hash the current system state.
3113 Mainly useful for debugging savestates.
3116 \begin_layout Subsection
3117 memory.readregion: Read region of memory
3120 \begin_layout Itemize
3121 Syntax: table memory.readregion([string vma, ]number base, number size)
3124 \begin_layout Standard
3125 Read a region of memory.
3128 \begin_layout Itemize
3129 Warning: If the region crosses VMA boundary, the results are undefined.
3132 \begin_layout Subsection
3133 memory.writeregion: Write region of memory
3136 \begin_layout Itemize
3137 Syntax: none memory.writeregion([string vma, ]number base, number size, table
3141 \begin_layout Standard
3142 Write a region of memory.
3145 \begin_layout Itemize
3146 Warning: If the region crosses VMA boundary, the results are undefined.
3149 \begin_layout Subsection
3150 memory.map_structure: Create mmap structure
3153 \begin_layout Itemize
3154 syntax: MMAP_STRUCT memory.map_structure()
3157 \begin_layout Standard
3158 Returns a new mapping structure (MMAP_STRUCT)
3161 \begin_layout Subsection
3162 MMAP_STRUCT(): Bind key in mmap structure
3165 \begin_layout Itemize
3166 Syntax: none MMAP_STRUCT(string key, [string vma, ]number address, string
3170 \begin_layout Standard
3171 Bind key <key> in mmap structure to specified address <address> with specified
3175 \begin_layout Itemize
3176 Type may be one of: byte, sbyte, word, sword, dword, sdword, qword or sqword.
3179 \begin_layout Subsection
3180 memory.read_expr: Evaluate memory watch expression
3183 \begin_layout Itemize
3184 Syntax: string memory.read_expr(string expr)
3187 \begin_layout Standard
3188 Evaluate specified watch expression and return result
3191 \begin_layout Subsection
3192 memory.action: Run core action
3195 \begin_layout Itemize
3196 memory.action(string action, [<params>])
3199 \begin_layout Standard
3201 The different models expect parameters as:
3204 \begin_layout Itemize
3208 \begin_layout Itemize
3212 \begin_layout Itemize
3216 \begin_layout Itemize
3220 \begin_layout Itemize
3224 \begin_layout Subsection
3225 memory.get_lag_flag: Get lag flag
3228 \begin_layout Itemize
3229 Syntax: boolean memory.get_lag_flag()
3232 \begin_layout Standard
3233 Get the value of core lag flag.
3234 True if this frame has been lag so far, false if poll has been detected.
3237 \begin_layout Subsection
3238 memory.set_lag_flag: Set lag flag
3241 \begin_layout Itemize
3242 Syntax: none memory.set_lag_flag(boolean flag)
3245 \begin_layout Standard
3246 Set the value of core lag flag.
3247 This flag automatically gets cleared if poll is detected, but can be forcibly
3248 set or cleared if game so requires.
3251 \begin_layout Itemize
3252 Should only be used in on_frame_emulated callback.
3255 \begin_layout Itemize
3256 Setting or clearing this affects the emulator lag counter.
3259 \begin_layout Standard
3260 \begin_inset Newpage pagebreak
3266 \begin_layout Section
3270 \begin_layout Standard
3271 Contains newer memory functions.
3274 \begin_layout Subsection
3275 memory2(): Get all VMA names.
3278 \begin_layout Itemize
3279 Syntax: table memory2()
3282 \begin_layout Standard
3283 Returns array of all valid VMA names.
3286 \begin_layout Subsection
3287 memory2.<vma>:info: Get VMA info
3290 \begin_layout Itemize
3291 Syntax: table memory2.<vma>:info()
3294 \begin_layout Standard
3295 Return table describing given VMA.
3296 Includes fields address, size, last, readonly, special and endian.
3299 \begin_layout Subsection
3300 memory2.<vma>:<op>: Read/Write memory
3303 \begin_layout Itemize
3304 Syntax: none memory2.<vma>:<op>(number offset, number value)
3307 \begin_layout Itemize
3308 Syntax: number memory2.<vma>:<op>(number offset)
3311 \begin_layout Standard
3312 Read/Write value from/to given VMA <vma> at given offset <offset> (must
3314 The value written is <value>.
3315 <Op> is of form: [i][s]<type>, where:
3318 \begin_layout Itemize
3319 <type> is one of 'byte', 'word', 'dword', 'qword'.
3322 \begin_layout Itemize
3323 'i' signifies that the value is treated as opposite-to-normal endianess,
3326 \begin_layout Itemize
3327 's' signifies that value is treated as signed.
3330 \begin_layout Standard
3331 \begin_inset Newpage pagebreak
3337 \begin_layout Section
3341 \begin_layout Standard
3342 Various callback-related functions.
3345 \begin_layout Subsection
3346 \begin_inset CommandInset label
3348 name "sub:callback.register:-Register-a"
3352 callback.register: Register a callback
3355 \begin_layout Itemize
3356 Syntax: function callback.register(string cbname, function cbfun);
3359 \begin_layout Standard
3360 Instruct function <cbfun> to be added to list of callbacks to call on event
3361 <cbname> (See section
3362 \begin_inset CommandInset ref
3364 reference "sec:Callbacks"
3369 The callback name does not have the 'on_' prefix (e.g.
3371 \begin_inset Quotes eld
3375 \begin_inset Quotes erd
3382 \begin_layout Subsection
3383 \begin_inset CommandInset label
3385 name "sub:callback.unregister:-Unregister-"
3389 callback.unregister: Unregister a callback
3392 \begin_layout Itemize
3393 Syntax: function callback.unregister(string cbname, function cbfun);
3396 \begin_layout Standard
3397 Instruct function <cbfun> to be removed from list of callbacks to call on
3401 \begin_layout Subsection
3402 callback.<cbname>:register: Register callback
3405 \begin_layout Itemize
3406 Syntax: function callback.<cbname>:register(function cbfun)
3409 \begin_layout Standard
3410 Synonym for callback.register (section
3411 \begin_inset CommandInset ref
3413 reference "sub:callback.register:-Register-a"
3417 ), albeit with callback name specified differently.
3420 \begin_layout Subsection
3421 callback.<cbname>:unregister: Register callback
3424 \begin_layout Itemize
3425 Syntax: function callback.<cbname>:unregister(function cbfun)
3428 \begin_layout Standard
3429 Synonym for callback.unregister (section
3430 \begin_inset CommandInset ref
3432 reference "sub:callback.unregister:-Unregister-"
3436 ), albeit with callback name specified differently.
3439 \begin_layout Section
3443 \begin_layout Standard
3444 Contains copy of global variables from time of Lua initialization.
3448 \begin_layout Standard
3449 \begin_inset Newpage pagebreak
3455 \begin_layout Section
3456 \begin_inset CommandInset label
3458 name "sec:Callbacks"
3465 \begin_layout Standard
3466 Various callbacks to Lua that can occur.
3469 \begin_layout Subsection
3470 on_paint: Screen is being painted
3473 \begin_layout Itemize
3474 Callback: on_paint(bool not_synth)
3477 \begin_layout Standard
3478 Called when screen is being painted.
3479 Any gui.* calls requiring graphic context draw on the screen.
3482 \begin_layout Itemize
3483 not_synth is true if this hook is being called in response to received frame,
3487 \begin_layout Subsection
3488 on_video: Dumped video frame is being painted
3491 \begin_layout Itemize
3492 Callback: on_video()
3495 \begin_layout Standard
3496 Called when video dump frame is being painted.
3497 Any gui.* calls requiring graphic context draw on the video.
3500 \begin_layout Subsection
3501 on_frame_emulated: Frame emulation complete
3504 \begin_layout Itemize
3505 Callback: on_frame_emulated()
3508 \begin_layout Standard
3509 Called when emulating frame has completed and on_paint()/on_video() calls
3510 are about to be issued.
3513 \begin_layout Subsection
3514 on_frame: Frame emulation starting.
3517 \begin_layout Itemize
3518 Callback: on_frame()
3521 \begin_layout Standard
3522 Called on each starting whole frame.
3525 \begin_layout Subsection
3526 on_startup: Emulator startup complete
3529 \begin_layout Itemize
3530 Callback: on_startup()
3533 \begin_layout Standard
3534 Called when the emulator is starting (lsnes.rc and --run files has been run).
3537 \begin_layout Subsection
3538 on_rewind: Movie rewound to beginning
3541 \begin_layout Itemize
3542 Callback: on_rewind()
3545 \begin_layout Standard
3546 Called when rewind movie to beginning has completed.
3549 \begin_layout Subsection
3550 on_pre_load: Load operation is about to start
3553 \begin_layout Itemize
3554 Callback: on_pre_load(string name)
3557 \begin_layout Standard
3558 Called just before savestate/movie load occurs (note: loads are always delayed,
3559 so this occurs even when load was initiated by lua).
3562 \begin_layout Subsection
3563 on_err_Load: Load failed
3566 \begin_layout Itemize
3567 Callback: on_err_load(string name)
3570 \begin_layout Standard
3571 Called if loadstate goes wrong.
3574 \begin_layout Subsection
3575 on_post_load: Load completed
3578 \begin_layout Itemize
3579 Callback: on_post_load(string name, boolean was_savestate)
3582 \begin_layout Standard
3583 Called on successful loadstate.
3584 was_savestate gives if this was a savestate or a movie.
3587 \begin_layout Subsection
3588 on_pre_save: Save operation is about to start
3591 \begin_layout Itemize
3592 Callback: on_pre_save(string name, boolean is_savestate)
3595 \begin_layout Standard
3596 Called just before savestate save occurs (note: movie saves are synchronous
3597 and won't trigger these callbacks if called from Lua).
3600 \begin_layout Subsection
3601 on_err_save: Save failed
3604 \begin_layout Itemize
3605 Callback: on_err_save(string name)
3608 \begin_layout Standard
3609 Called if savestate goes wrong.
3612 \begin_layout Subsection
3613 on_post_save: Save completed
3616 \begin_layout Itemize
3617 Callback: on_post_save(string name, boolean is_savestate)
3620 \begin_layout Standard
3621 Called on successful savaestate.
3622 is_savestate gives if this was a savestate or a movie.
3625 \begin_layout Subsection
3626 on_quit: Emulator is shutting down
3629 \begin_layout Itemize
3633 \begin_layout Standard
3634 Called when emulator is shutting down.
3637 \begin_layout Subsection
3638 on_input: Polling for input
3641 \begin_layout Standard
3642 Called when emulator is just sending input to bsnes core.
3643 Warning: This is called even in readonly mode, but the results are ignored.
3646 \begin_layout Subsection
3647 on_reset: System has been reset
3650 \begin_layout Itemize
3651 Callback: on_reset()
3654 \begin_layout Standard
3655 Called when system is reset.
3658 \begin_layout Subsection
3659 on_readwrite: Entered readwrite mode
3662 \begin_layout Itemize
3663 Callback: on_readwrite()
3666 \begin_layout Standard
3667 Called when moving into readwrite mode as result of
3668 \begin_inset Quotes eld
3672 \begin_inset Quotes erd
3675 command (note: moving to rwmode by Lua won't trigger this, as per recursive
3679 \begin_layout Subsection
3680 on_snoop/on_snoop2: Snoop core controller reads
3683 \begin_layout Itemize
3684 Callback: on_snoop(number port, number controller, number index, number
3688 \begin_layout Itemize
3689 Callback: on_snoop2(number port, number controller, number index, number
3693 \begin_layout Standard
3694 Called each time bsnes asks for input.
3695 The value is the final value to be sent to bsnes core (readonly mode, autohold
3696 and autofire have been taken into account).
3697 Might be useful when translating movies to format suitable for console
3699 Note: There is no way to modify the value to be sent.
3702 \begin_layout Itemize
3703 On_snoop2 is called instead of on_snoop if defined.
3704 Reserves port 0 for system, having first user port be port 1.
3707 \begin_layout Subsection
3708 on_keyhook: Hooked key/axis has been moved
3711 \begin_layout Itemize
3712 Callback: on_keyhook(string keyname, table state)
3715 \begin_layout Standard
3716 Sent when key that has keyhook events requested changes state.
3717 Keyname is name of the key (group) and state is the state (same kind as
3718 table values in input.raw).
3721 \begin_layout Subsection
3725 \begin_layout Itemize
3729 \begin_layout Standard
3730 Called when requested by set_idle_timeout(), the timeout has expired and
3731 emulator is waiting.
3734 \begin_layout Subsection
3735 on_timer: Timer event
3738 \begin_layout Itemize
3739 Callback: on_timer()
3742 \begin_layout Standard
3743 Called when requested by set_idle_timeout() and the timeout has expired
3744 (regardless if emulator is waiting).
3747 \begin_layout Subsection
3748 on_set_rewind: Rewind point has been set
3751 \begin_layout Itemize
3752 Callback: on_set_rewind(UNSAFEREWIND r)
3755 \begin_layout Standard
3756 Called when unsafe rewind object has been constructed.
3759 \begin_layout Subsection
3760 on_pre_rewind: Rewind is about to occur
3763 \begin_layout Itemize
3764 Callback: on_pre_rewind()
3767 \begin_layout Standard
3768 Called just before unsafe rewind is about to occur.
3771 \begin_layout Subsection
3772 on_post_rewind: Rewind has occured
3775 \begin_layout Itemize
3776 Callback: on_post_rewind()
3779 \begin_layout Standard
3780 Called just after unsafe rewind has occured.
3783 \begin_layout Subsection
3784 on_button: Button has been pressed
3787 \begin_layout Itemize
3788 Callback: on_button(number port, number controller, number index, string
3792 \begin_layout Standard
3793 Called on controller button press, with following parameters:
3796 \begin_layout Itemize
3797 port: Port number (0 is system)
3800 \begin_layout Itemize
3801 controller: Controller within port
3804 \begin_layout Itemize
3805 index: Index of button.
3808 \begin_layout Itemize
3809 type: Type of event, one of:
3813 \begin_layout Itemize
3814 \begin_inset Quotes eld
3818 \begin_inset Quotes erd
3821 : Button was pressed.
3824 \begin_layout Itemize
3825 \begin_inset Quotes eld
3829 \begin_inset Quotes erd
3832 : Button was released.
3835 \begin_layout Itemize
3836 \begin_inset Quotes eld
3840 \begin_inset Quotes erd
3846 \begin_layout Itemize
3847 \begin_inset Quotes eld
3851 \begin_inset Quotes erd
3854 : Released from hold.
3857 \begin_layout Itemize
3858 \begin_inset Quotes eld
3862 \begin_inset Quotes erd
3865 : Typing input on button.
3868 \begin_layout Itemize
3869 \begin_inset Quotes eld
3873 \begin_inset Quotes erd
3876 : Typing input undone.
3879 \begin_layout Itemize
3880 \begin_inset Quotes eld
3883 autofire <duty> <cycle>
3884 \begin_inset Quotes erd
3887 : Autofire with specifie duty and cycle.
3890 \begin_layout Itemize
3891 \begin_inset Quotes eld
3895 \begin_inset Quotes erd
3901 \begin_layout Itemize
3902 \begin_inset Quotes eld
3906 \begin_inset Quotes erd
3909 : Analog action on axis.
3913 \begin_layout Subsection
3914 on_movie_lost: Movie data is about to be lost
3917 \begin_layout Itemize
3918 Callback: on_movie_lost(STRING kind)
3921 \begin_layout Standard
3922 Called just before something would happen that could lose movie data.
3926 \begin_layout Itemize
3927 readwrite: Switching to readwrite mode.
3930 \begin_layout Itemize
3931 reload: ROM is being reloaded in readwrite mode.
3934 \begin_layout Itemize
3935 load: New movie is being loaded.
3938 \begin_layout Itemize
3939 unsaferewind: Unsafe rewind is happening.