Lua: Don't lua_error() out of context with pending dtors
[lsnes.git] / manual.txt
blob43ac4a4edda61c75c8983c82413cbb286076d8a2
1 1 Introduction
3 lsnes is SNES rerecording emulator based on bsnes core.
5 2 Dependencies
7 1. bsnes libsnes (for bsnes SNES core)
9   (a) v084-v087 (v084 or v085 for delayreset support)
11   (b) accuracy or compatiblity core with debugger enabled.
13   (c) Patched version (using included 7 patches)
15 2. gambatte (for gambatte core)
17   (a) SVN r320, r358 or r364
19   (b) Patched with included patches
21 3. Zlib
23 4. boost_iostreams
25 5. boost_filesystem
27 6. boost_thread (if native std::thread is not available)
29 7. libsdl (SDL only)
31 8. sdlmain (SDL only, part of SDL)
33 9. boost_conversion (this is header-only library)
35 10. libswscale (wxwidgets graphics only)
37 11. Portaudio (portaudio sound only)
39 12. libao (libao sound only)
41 13. Lua version 5.1.X or 5.2.X
43 14. G++ 4.6 or 4.7
45 15. libopus (optional, for commentary track tool)
47 3 Building
49 • Copy bsnes sources (the bsnes subdirectory) to subdirectory 
50   'bsnes' (for bsnes core).
52 • Copy gambatte sources to subdirectory 'gambatte' (for gambatte 
53   core).
55 • Patch the bsnes sources with included patches (directory 
56   'bsnes-patches/<version>', bsnes core)
58 • Patch the gambatte sources with included patches (directory 
59   'gambatte-patches/<version>', gambatte core)
61 • Edit options.build (or copy of that file)
63 • Run make (passing 'OPTIONS=<filename>' if using something else 
64   than options.build).
66 4 Command line options
68 4.1 Wxwidgets options
70 4.1.1 --rom=<file>
72 Load <file> as ROM.
74 4.1.2 <file>
76 Load <file> as ROM.
78 4.1.3 --load=<file>
80 Load <file> as movie or savestate file on startup.
82 4.1.4 --settings
84 Instead of starting the emulator, only display the settings.
86 4.1.5 --pluginmanager
88 Instead of starting the emulator, display the plugin manager 
89 (useful to disable some plugin that causes emulator to crash on 
90 startup)
92 4.1.6 --lua=<file>
94 Run this Lua file on startup
96 4.2 dump options (lsnes-dumpavi only)
98 4.2.1 --rom=<file>
100 Load <file> as ROM. Required.
102 4.2.2 <filename>
104 Load <filename> as movie or savestate file on startup. Required.
106 4.2.3 --dumper=<dumper>
108 Set the dumper to use (required). Use 'list' for listing of known 
109 dumpers.
111 4.2.4 --firmware-path=<path>
113 Set path to look for firmware.
115 4.2.5 --mode=<mode>
117 Set the mode to use (required for dumpers with multiple modes, 
118 forbidden otherwise). Use 'list' for known modes.
120 4.2.6 --prefix=<prefix>
122 Set dump prefix. Default is “avidump”.
124 4.2.7 --option=<name>=<value>
126 Set option <name> to value <value>.
128 4.2.8 --length=<length>
130 Set number of frames to dump. Mandatory, unless --overdump-length 
131 is specified.
133 4.2.9 --overdump-length=<length>
135 Set number of frames to dump after movie end. Mutually exclusive 
136 with --length.
138 4.2.10 --lua=<script>
140 Run specified lua script (lsnes-dumpavi does not have 
141 initialization files).
143 4.2.11 --load-library=<library>
145 Load the specified shared object / dynamic library / dynamic link 
146 library.
148 4.3 lsnes settings directory
150 The lsnes settings directory is (in order of decreasing 
151 perference):
153 • Windows: %APPDATA%\lsnes (if %APPDATA% exists)
155 • Unix: $XDG_CONFIG_HOME/lsnes (if $XDG_CONFIG_HOME exists)
157 • Unix: $HOME/.config/lsnes (if $HOME exists)
159 • All: . (fallback default).
161 If leading directories do not exist, attempt to create them is 
162 made.
164 5 Internal commands
166 • Commands beginning with '*' invoke the corresponding command 
167   without alias expansion.
169 • If command starts with '+' (after possible '*'), the command is 
170   executed as-is when button is pressed, and when button is 
171   released, it is executed with '+' replaced by '-'.
173 • Commands without '+' execute only on negative edge (release).
175 5.1 run-script <script>
177 Run <script> as if commands were entered on the command line.
179 5.2 Memory manipulation
181 • <address> can be one of:
183   – Decimal number
185   – Hexadecimal number (prefixed with 0x)
187   – <memarea>+<hexoffset> (no 0x prefix for offset).
189 <value> can be hexadecimal (prefixed with '0x'), unsigned or 
190 signed (prefixed with '-') decimal.
192 The available element <sizes> are:
194 • byte: 1 byte
196 • word: 2 bytes
198 • hword: 3 bytes
200 • dword: 4 bytes
202 • qword: 8 bytes
204 • float: 4 bytes (floating-point)
206 • double: 8 bytes (floating-point)
208 When reading RAM and ROM, multi-byte reads/writes are big-endian. 
209 When dealing with DSP memory, multi-byte reads/writes are 
210 native-endian (do not use operand sizes exceeding DSP bitness, 
211 except dword is OK for 24-bit memory).
213 5.2.1 read-<size> <address>
215 Read the value of byte in <address>.
217 5.2.2 read-s<size> <address>
219 Read the value of signed byte in <address>.
221 5.2.3 write-<size> <address> <value>
223 Write <value> to byte in address <address>.
225 5.3 Main commands
227 These commands are not available in lsnesrc, but are available 
228 after ROM has been loaded.
230 5.3.1 quit-emulator
232 Quits the emulator.
234 5.3.2 pause-emulator
236 Toggle paused/unpaused
238 5.3.3 +advance-frame 
240 Advance frame. If the button is still held after configurable 
241 timeout expires, game unpauses for the duration frame advance is 
242 held.
244 5.3.4 +advance-poll 
246 Advance subframe. If the button is still held after configurable 
247 timeout expires, game unpauses for the duration frame advance is 
248 held.
250 5.3.5 advance-skiplag 
252 Skip to first poll in frame after current.
254 5.3.6 reset 
256 Reset the SNES after this frame.
258 5.3.7 load <filename> 
260 Load savestate <filename> in current mode.
262 5.3.8 load-state <filename> 
264 Load savestate <filename> in readwrite mode.
266 5.3.9 load-readonly <filename> 
268 Load savestate <filename> in readonly mode.
270 5.3.10 load-preserve <filename> 
272 Load savestate <filename> in readonly mode, preserving current 
273 events.
275 5.3.11 load-movie <filename> 
277 Load savestate <filename>, ignoring save part in readonly mode.
279 5.3.12 save-state <filename> 
281 Save system state to <filename> as soon as possible.
283 5.3.13 save-movie <filename> 
285 Save movie to <filename>.
287 5.3.14 set-rwmode 
289 Set recording mode.
291 5.3.15 set-romode 
293 Set playback mode
295 5.3.16 toggle-rwmode 
297 Toggle between playback and recording modes.
299 5.3.17 test-1, test-2, test-3
301 Internal test commands. Don't use.
303 5.3.18 take-screenshot <filename> 
305 Save screenshot to <filename>.
307 5.3.19 +controller <class>-<#>-<button>
309 Press button <button> on controller <num> of class <class>.
311 • Class 'gamepad': A, B, X, Y, L, R, select, start, up, down, 
312   left, right, ext0, ext1, ext2, ext3
314 • Class 'mouse': L, R
316 • Class 'superscope': trigger, cursor, turbo, pause
318 • Class 'justifier': trigger, start
320 • Class 'gb': A, B, select, start, up, down, left, right
322 5.3.20 hold-controller <class>-<#>-<button>
324 Hold/unhold button <button> on controller <num> of class <class>.
326 5.3.21 type-controller <class>-<#>-<button>
328 Hold/unhold button <button> on controller <num> of class <class> 
329 for the next frame. See +controller for button names.
331 Cauntion: Does not work properly if outside frame advance.
333 5.3.22 +autofire-controller <class>-<#>-<button> [[<duty>] 
334   <cyclelen>]
336 Start autofire. If duty is not specified, defaults to 1. If 
337 <cyclelen> is not specified, defaults to 2.
339 5.3.23 -autofire-controller <class>-<#>-<button> [[<duty>] 
340   <cyclelen>]
342 End autofire.
344 5.3.24 autofire-controller <class>-<#>-<button> [[<duty>] 
345   <cyclelen>]
347 Toggle autofire. If autofire is turned on, specified cycle is 
348 used.
350 5.3.25 designate-position <class>-<#>-analog<n>
352 Designate position for analog pair. <n> is only there if there 
353 are multiple axis pairs.
355 5.3.26 repaint
357 Force a repaint.
359 5.3.27 toggle-pause-on-end
361 Toggle pause on end flag.
363 5.3.28 set-pause-on-end
365 Set pause on end flag.
367 5.3.29 clear-pause-on-end
369 Clear pause on end flag.
371 5.3.30 action <action> [<parameters>]
373 Run specified core action.
375 5.4 Save jukebox 
377 5.4.1 cycle-jukebox-backward
379 Cycle save jukebox backwards.
381 5.4.2 cycle-jukebox-forward
383 Cycle save jukebox forwards
385 5.4.3 set-jukebox-slot <slot>
387 Set current jukebox slot
389 5.4.4 load-jukebox
391 Do load from jukebox (current mode).
393 5.4.5 save-jukebox
395 Do state save to jukebox.
397 5.5 Slot branches
399 5.5.1 list-branches
401 List all branches
403 5.5.2 create-branch <pid> <name>
405 Create a new branch, with <pid> as parent and <name> as name.
407 5.5.3 rename-branch <id> <name>
409 Rename branch <id> to <name>.
411 5.5.4 reparent-branch <id> <pid>
413 Set parent of branch <id> to <pid>.
415 5.5.5 set-branch <id>
417 Set current branch to <id>.
419 5.5.6 delete-branch <id>
421 Delete branch <id>.
425 5.6 Lua 
427 5.6.1 evaluate-lua <luacode>
429 Run Lua code <luacode> using built-in Lua interpretter.
431 5.6.2 L <luacode>
433 Synonym for evaluate-lua.
435 5.6.3 run-lua <script>
437 Run specified lua file using built-in Lua interpretter.
439 5.6.4 reset-lua
441 Clear the Lua VM state and restore to factory defaults.
443 5.7 Sound 
445 5.7.1 enable-sound <on/off> 
447 Enable/Disable sound.
449 5.8 Misc.
451 5.8.1 reload-rom [<file>]
453 Reloads the main ROM image from <file>.
455 5.8.2 +tangent
457 Tangent for recording voice for commentary track. While pressed, 
458 record a stream.
460 5.8.3 advance-subframe-timeout
462 Subframe advance timeout in milliseconds. Default is 100.
464 5.8.4 set-speed <speed>
466 Set the speed multiplier. <speed> may be positive number (1 is 
467 normal speed) or “turbo” for turbo.
469 6 Settings
471 6.1 Core settings
473 6.2 AVI dumper settings
475 6.2.1 avi-large
477 AVI dumper: Always dump at 512x448 or 512x478 regardless of what 
478 the console outputs.
480 6.2.2 avi-left-border
482 AVI dumper: Set the default left border thickness (unless lua 
483 overrides) for dumps. Range 0-8191. Default is 0.
485 6.2.3 avi-right-border
487 AVI dumper: Set the default right border thickness (unless lua 
488 overrides) for dumps. Range 0-8191. Default is 0.
490 6.2.4 avi-top-border
492 AVI dumper: Set the default top border thickness (unless lua 
493 overrides) for dumps. Range 0-8191. Default is 0.
495 6.2.5 avi-bottom-border
497 AVI dumper: Set the default bottom border thickness (unless lua 
498 overrides) for dumps. Range 0-8191. Default is 0.
500 6.2.6 avi-maxframes
502 AVI dumper: Maximum number of frames per dump segment (0 => 
503 unlimited). Range 0-999999999. Default is 0.
505 6.2.7 avi-compresison
507 AVI dumper: Compression level (0-18).
509 • Compression levels 10 and above are not compatible with stock 
510   CSCD codec.
512 • Recomended level is 7.
514 6.2.8 avi-soundrate
516 AVI dumper: Set method of determining the sound rate.
518 • 0: Pick nearest of 8, 11.025, 12, 16, 22.05, 24, 32, 44.1, 48, 
519   64, 88.2, 96, 128, 176.4 and 192 kHz.
521 • 1: Round down to nearest integer.
523 • 2: Round up to nearest ingeter.
525 • 3: Multiply by denominator.
527 • 4: High quality 44.1kHz (SRC needed).
529 • 5: High quality 48kHz (SRC needed).
531 6.3 JMD options
533 6.3.1 jmd-compression
535 JMD dumper: Compression level (0-9).
537 7 Movie editor
539 • The editor edits in-memory movie.
541 • Because past can't be edited and readwrite mode doesn't allow 
542   future, editing only works in read only mode.
544 • Keyboard triggers the normal hotkeys and bindings.
546 7.1 Left button actions
548 • Clicking on cell in future (indicated by lack of redish 
549   background) toggles it (if it is a button) or prompts for a 
550   value (if it is an axis)
552 • Dragging vertically toggles sequence of buttons or changes a 
553   sequence of axis values.
555 7.2 Right button actions
557 The right mouse button pops up a context-sensitive menu:
559 • Toggle <something>: Toggle this button
561 • Change <something>: Change this axis value
563 • Insert frame after: Insert a frame after this frame
565 • Append frame: Append a frame to movie
567 • Append frames: Append specified number of frames to movie
569 • Delete frame: Delete this frame
571 • Delete subframe: Delete this subframe
573 • Truncate movie: Delete this subframe and everything after it.
575 • Scroll to frame: Prompt for a frame and scroll the display to 
576   that frame.
578 • Scroll to current frame: Scroll the display to current position
580 • Run to frame: Prompts for frame and runs the emulation to that 
581   frame.
583 • Change number of lines visible: Change the height of the movie 
584   display (1 to 255).
586 • Lock scroll to playback: While playing back or rewinding 
587   movies, the display will follow if enabled.
589 8 Memory watch expression syntax
591 Memory watch expressions has the following syntax elements:
593 ${foo}     The value of memory watch foo.
595 0x1234     Hexadecimal number 1234
597 12345      Decimal number 12345
599 3.141      Decimal number 3.141
601 -a         Unary negation
603 ~a         Bitwise NOT (integers only)
605 a*b        Multiplication
607 a/b        Division/quotent
609 a%b        Remainder (integers only)
611 a+b        Sum or string concatenation
613 a-b        Difference
615 a<<b       Shift left (integers only)
617 a>>b       Shift right (integers only). Arithmetic for signed.
619 a<b        Less than
621 a<=b       Less or equal to
623 a==b       Equal to
625 a!=b       Not equal to
627 a>=b       Greater or equal to
629 a>b        Greater than
631 a&b        Bitwise AND (integers only)
633 a^b        Bitwise XOR (integers only)
635 a|b        Bitwise OR (integers only)
637 a&&b       Logical AND
639 a||b       Logical OR
641 π          Numeric constant pi.
643 i          Imaginary unit
645 if(x,y)    If x is true, y, else false.
647 if(x,y,z)  If x is true, y, else z.
649 select(x...)
651            First value in x... that is not false, or false if 
652 none.
654 unsigned(x)
656            Cast x to unsigned.
658 signed(x)
660            Cast x to signed.
662 float(x)
664            Cast x to float.
666 min(x...)  The smallest value among x... or false if empty.
668 max(x...)  The largest value among x... or false if empty.
670 sum(x...)  Sum/concatenation of x... or false if empty.
672 prod(x...) Product of x... or false if empty.
674 sqrt(x)    Square root of x.
676 log(x)     Natural log of x.
678 log(x,y)   Log of y to base x.
680 exp(x)     e^x.
682 exp(x,y)   x^y
684 sin(x)     Sine of x
686 cos(x)     Cosine of x
688 tan(x)     Tangent of x
690 asin(x)    Arcsine of x
692 acos(x)    Arccosine of x
694 atan(x)    Arctangent of x
696 atan(x,y)  Angle between vector (x,y) and x-axis.
698 sinh(x)    Hyperbolic sine of x
700 cosh(x)    Hyperbolic cosine of x
702 tanh(x)    Hyperbolic tangent of x
704 arsinh(x)  Hyperbolic arsine of x
706 arcosh(x)  Hyperbolic arcosine of x
708 artanh(x)  Hyperbolic artangent of x
710 torad(x)   Convert x degrees to radians.
712 todeg(x)   Convert x radians to degrees.
714 re(x)      Real part of complex number x.
716 im(x)      Imaginary part of complex number x.
718 conj(x)    Complex conjugate of x.
720 abs(x)     Absolute value of x.
722 arg(x)     Argument of x.
724 pyth(x...) sqrt(sum(x^2)). I.e. pythagorean distance.
726 e          Base of natural logarithm
728 pi         Pi
730 true       Constant true
732 false      Constant false
736 9 Modifier and key names:
738 9.1 wxWidgets platform
740 9.1.1 Modifier names:
742 Following modifier names are known:
744 • alt
746 • ctrl
748 • shift 
750 • meta
752 • cmd (Mac OS X only)
754 9.1.2 Key names:
756 Following key names are known:
758 • back, tab, return, escape, space, exclaim, quotedbl, hash, 
759   dollar, percent, ampersand, quote, leftparen, rightparen, 
760   asterisk, plus, comma, minus, period, slash, 0, 1, 2, 3, 4, 5, 
761   6, 7, 8, 9, colon, semicolon, less, equals, greater, question, 
762   at, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, 
763   u, v, w, x, y, z, leftbracket, backslash, rightbracket, caret, 
764   underscore, backquote, a, b, c, d, e, f, g, h, i, j, k, l, m, 
765   n, o, p, q, r, s, t, u, v, w, x, y, z, leftcurly, pipe, 
766   rightcurly, tilde, delete, start, lbutton, rbutton, cancel, 
767   mbutton, clear, shift, alt, control, menu, pause, capital, end, 
768   home, lefT, up, right, down, select, print, execute, snapshot, 
769   insert, help, numpad0, numpad1, numpad2, numpad3, numpad4, 
770   numpad5, numpad6, numpad7, numpad8, numpad9, multiply, add, 
771   separator, subtract, decimal, divide, f1, f2, f3, f4, f5, f6, 
772   f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, 
773   f20, f21, f22, f23, f24, numlock, scroll, pageup, pagedown, 
774   numpad_space, numpad_tab, numpad_enter, numpad_f1, numpad_f2, 
775   numpad_f3, numpad_f4, numpad_home, numpad_left, numpad_up, 
776   numpad_right, numpad_down, numpad_pageup, numpad_pagedown, 
777   numpad_end, numpad_begin, numpad_insert, numpad_delete, 
778   numpad_equal, numpad_multiply, numpad_add, numpad_separator, 
779   numpad_subtract, numpad_decimal, numpad_divide, windows_left, 
780   windows_right, windows_menu, command, special1, special2, 
781   special3, special4, special5, special6, special7, special8, 
782   special9, special10, special11, special12, special13, 
783   special14, special15, special16, special17, special18, 
784   special19, special20
786 10 Movie file format
788 Movie file is .zip archive in itself, normal ZIP archive tools 
789 work on it (note: If you recompress it, do not use compression 
790 methods other than store and deflate and especially do not use 
791 encryption of any kind).
793 10.1 Detecting clean start/SRAM/Savestate
795 • If file has member “savestate” it is savestate, otherwise:
797 • If file has members with names starting “moviesram.” it is 
798   movie starting from SRAM, otherwise:
800 • It is movie starting from clear state.
802 10.2 Member: gametype
804 Type of game ROM and region (as one line). Valid values are:
807 +--------------+---------------------+--------+
808 |    Value     |       System        | Region |
809 +--------------+---------------------+--------+
810 +--------------+---------------------+--------+
811 |  snes_pal    |     Super NES       |  PAL   |
812 +--------------+---------------------+--------+
813 |   sgb_pal    |   Super Game Boy    |  PAL   |
814 +--------------+---------------------+--------+
815 |  snes_ntsc   |     Super NES       |  NTSC  |
816 +--------------+---------------------+--------+
817 |  sgb_ntsc    |   Super Game Boy    |  NTSC  |
818 +--------------+---------------------+--------+
819 |     bsx      | BS-X (non-slotted)  |  NTSC  |
820 +--------------+---------------------+--------+
821 | bsxslotted   |   BS-X (slotted)    |  NTSC  |
822 +--------------+---------------------+--------+
823 | sufamiturbo  |    Sufami Turbo     |  NTSC  |
824 +--------------+---------------------+--------+
827 Frame rates are:
830 +---------+-----------------+
831 | Region  | Framerate (fps) |
832 +---------+-----------------+
833 +---------+-----------------+
834 |  PAL    |   322445/6448   |
835 +---------+-----------------+
836 |  NTSC   | 10738636/178683 |
837 +---------+-----------------+
840 10.3 Member: port1
842 Contains type of port #1 (as one line). Valid values are 'none', 
843 'gamepad', 'multitap' and 'mouse'. If not present, defaults to 
844 'gamepad'.
846 10.4 Member: port2
848 Contains type of port #2 (as one line). Valid values are 'none', 
849 'gamepad', 'multitap', 'mouse', 'superscope', 'justifier' and 
850 'justifiers'. If not present, defaults to 'none'.
852 10.5 Member: gamename
854 Contains name of the game (as one line).
856 10.6 Member: authors
858 Contains authors, one per line. Part before '|' is the full name, 
859 part after is the nickname.
861 10.7 Member: systemid
863 Always “lsnes-rr1” (one line). Used to reject other saves.
865 10.8 Member: controlsversion
867 Always “0” (one line). Used to identify what controls are there.
869 10.9 Member: “coreversion”
871 Contains bsnes core version number (as one line).
873 10.10 Member: projectid
875 Contains project ID (as one line). Used to identify if two movies 
876 are part of the same project.
878 10.11 Member: {rom,slota,slotb}{,xml}.sha256
880 Contains SHA-256 of said ROM or ROM mapping file (as one line). 
881 Absent if corresponding file is absent.
883 10.12 Member: moviesram.<name>
885 Raw binary startup SRAM of kind <name>. Only present in 
886 savestates and movies starting from SRAM.
888 10.13 Member: saveframe
890 Contains frame number (as one line) of frame movie was saved on. 
891 Only present in savestates.
893 10.14 Member: lagcounter
895 Current value of lag counter (as one line). Only present in 
896 savestates.
898 10.15 Member: pollcounters
900 Contains poll counters (currently 100 of them), one per line. 
901 Each line is raw poll count if DRDY is set for it. Otherwise it 
902 is negative poll count minus one. Only present in savestates.
904 10.16 Member: hostmemory
906 Raw binary dump of host memory. Only present in savestates.
908 10.17 Member: savestate
910 The raw binary savestate itself. Savestate detection uses this 
911 file, only present in savestates.
913 10.18 Member: screenshot
915 Screenshot of current frame. Only present in savestates. First 2 
916 bytes are big-endian width of image, rest are 24-bit RGB image 
917 data. Height of image is inferred from the width and size of 
918 data.
920 10.19 Member: sram.<name>
922 Raw binary SRAM of kind <name> at time of savestate. Only present 
923 in savestates.
925 10.20 Member: input
927 The actual input track, one line per subframe (blank lines are 
928 skipped).
930 • If the first byte of each line is '.', ' ', <tab> or '|', then 
931   the line is part of same frame as previous, otherwise it starts 
932   a new frame.
934 • First subframe must start a new frame.
936 Length of movie in frames is number of lines in input file that 
937 start a new frame.
939 10.21 Member: subtitles
941 Subtitle track. Optional.
943 • Each line is in form <firstframe> <numframes> <text>.
945 • Linefeed is encoded as \n, backslash is encoded as \\.
947 10.22 Member: rerecords
949 Contains textual base-10 rerecord count (as one line; emulator 
950 just writes this, it doesn't read it) + 1.
952 10.23 Member: rrdata
954 This member stores set of load IDs. There is one load ID per 
955 rerecord (plus one corresponding to start of project).
957 • This member constists of concatenation of records
959 • Each record is 2-36 bytes long and can represent 1-16,843,009 
960   consequtive IDs.
962 • IDs are interpretted as 256-bit big-endian integers with 
963   warparound.
965 • Initial predicted ID is all zeroes.
967 Format of each record is:
969 • 1 byte: Opcode byte. Bits 0-4 are prefix length (prefixlen), 
970   bits 5-6 are count length (countlen). Bit 7 is unused.
972 • 32-prefixlen bytes of ID.
974 • countlen bytes of big-endian count (count).
976 Records are processed as follows:
978 • To form the first ID encoded by record, take the first 
979   prefixlen bytes predicted ID and append the read ID value to 
980   it. The result is the first ID encoded.
982 • If countlen is 0, record encodes 1 ID.
984 • If countlen is 1, record encodes 2+count IDs.
986 • If countlen is 2, record encodes 258+count IDs.
988 • If countlen is 3, record encodes 65794+count IDs.
990 • The new predicted ID is the next ID after last one encoded by 
991   the record.
993 The number of rerecords + 1 is equal to the sum of number of IDs 
994 encoded by all records.
996 10.24 Member: starttime.second
998 Movie starting time, second part. Epoch is Unix epoch. Default is 
999 1,000,000,000.
1001 10.25 Member: starttime.subsecond
1003 Movie starting time, subsecond part. Unit is CPU clocks. Default 
1004 is 0.
1006 10.26 Member: savetime.second
1008 Movie saving time, second part. Default is starttime.second. Only 
1009 present in savestates.
1011 10.27 Member: savetime.subsecond
1013 Movie saving time, subsecond part. Default is 
1014 starttime.subsecond. Only present in savestates.
1016 11 lsvs file format (commentary tracks)
1018 11.1 Clusters
1020 • Each cluster is 8kB (8192 bytes) in size.
1022 • Cluster n starts at offset 8192*n in file.
1024 • The following clusters are system special:
1026   – Cluster 0 and all clusters with number multiple of 2048 
1027     (cluster tables)
1029   – Cluster 1 (superblock)
1031 11.2 Cluster tables
1033 • The cluster table describing cluster n is stored in cluster n & 
1034   ~0x7FF (zero last 11 bits of n).
1036 • This cluster table consists of 2048 4-byte big-endian integers.
1038 • Each entry describes a cluster in 16MB supercluster, in order.
1040 • The valid values for entries are:
1042   – 0x00000000: Free cluster
1044   – 0x00000001: Last cluster in chain.
1046   – 0xFFFFFFFF: System cluster (cluster tables and superblock)
1048   – (anything else): Number of next cluster in chain. Must not be 
1049     multiple of 2048.
1051 • Due to limitations of the format, there can be at most 2097052 
1052   superclusters, giving maximum file size of 16TB.
1054 11.3 Stream table
1056 • The stream table chain always starts in cluster 2.
1058 • Otherwise, it follows normal chaining.
1060 • The stream table consists of 16-byte entries:
1062   – The first 8 bytes of entry give big-endian beginning position 
1063     of stream in units of 1/48000 s.
1065   – The next 4 bytes of entry give big-endian beginning cluster 
1066     for control data. 0 here marks the entry as not present.
1068   – The last 4 bytes of entry give big-endian beginning cluster 
1069     for codec data.
1071 • Stream table clusters are normal clusters, following normal 
1072   chaining.
1074 • The stream begnning position is not guarenteed unique. There 
1075   can be multiple streams with the same starting position in the 
1076   file.
1078 11.4 Stream control data
1080 • The stream control data consists of entries 4 bytes each:
1082   – The first 2 bytes of entry gives big-endian length of packet
1084   – The next byte of entry gives audio length of packet in units 
1085     of 1/400 s.
1087   – The last byte is control byte.
1089     ∗ 0 means this entry is not present and the control data 
1090       ends.
1092     ∗ 1 is valid control entry.
1094 • The stream control data can also end by running into end of the 
1095   readable chain.
1097   – This happens if there happens to be exact multiple of 2048 
1098     packets in stream and number of packets is nonzero.
1100 • These clusters follow normal chaining.
1102 11.5 Stream codec data
1104 • Stream codec data consists of raw Opus data packets packed back 
1105   to back with nothing in between.
1107 • Warning: Due to internal limitations, this data must reside in 
1108   the first 65536 superclusters (that is, the first 1TB of the 
1109   file).
1111 11.6 Superblock
1113 • The superblock is stored in cluster 1. 
1115 • The first 11 bytes are “sefs-magic”<NUL>.
1117 • The rest are unused.
1119 • This cluster 1 is marked as system special.
1121 12 Known ROM extensions
1123 • SNES cartridge ROMs: sfc, smc, swc, fig, ufo, sf2, gd3, gd7, 
1124   dx2, mgd, mgh.
1126 • DMG cartridge ROMs: dmg, gb.
1128 • GBC cartridge ROMs: cgb, gbc.
1130 13 Gamepack files
1132 • The first line must be: “[GAMEPACK FILE]”.
1134 • There is one needed line: “type <systype>”. This sets system 
1135   type to <systype>. The following system types are valid:
1137   – snes (SNES)
1139   – bsx (BS-X non-slotted)
1141   – bsxslotted (BS-X slotted)
1143   – sufamiturbo (Sufami Turbo)
1145   – sgb (Super Game Boy)
1147   – dmg (Game Boy)
1149   – gbc (Game Boy Color)
1151   – gbc_gba (Game Boy Color with GBA initial register values)
1153 • Optionally a region can be specified: “region <region>”. The 
1154   following values are valid:
1156   – autodetect (Autodetect region: snes and sgb only)
1158   – ntsc (NTSC: snes, bsx, bsxslotted, sufamiturbo, sgb)
1160   – pal (PAL: snes, sgb)
1162   – world (World: dmg, gbc, gbc_gba)
1164 • ROM images are loaded as: “rom <type> <file>”. The following 
1165   types are valid:
1167   – rom (Cartridge ROM in snes, dmg, gbc, gbc_gba. BIOS in bsx, 
1168     bsxslotted, sufamiturbo)
1170   – bsx (Cartridge ROM in bsx, bsxslotted)
1172   – slot-a (Cartridge ROM in sufamiturbo)
1174   – slot-b (Cartridge ROM in sufamiturbo)
1176 • ROM markup can be loaded as: “xml <type> <file>”. The types 
1177   valid are the same as for ROMs.
1179 • Patches can be loaded as “patch[<offset>] <type> <file>”. The 
1180   types are the same as for ROMs.
1182   – Offset is given in form [+-]<number>. Usually offset is 
1183     either +0 or -512.
1185   – Default offset is +0.
1187 13.1 Example:
1189 [GAMEPACK FILE]
1191 type snes
1193 rom rom speedygonzales.sfc
1195 patch-512 rom sonicthehedgehog.ips
1197 13.2 Example 2:
1199 [GAMEPACK FILE]
1201 type sgb
1203 rom rom supergameboy.sfc
1205 rom dmg megamanV.dmg
1207 14 Quick'n'dirty encode guide
1209 1. Start the emulator and load the ROM and movie file.
1211 2. Set large AVI option 'set-setting avi-large on'
1213 3. Enable dumping 'dump-avi tmpdump' 
1215 4. Unpause and let it run until you want to end dumping.
1217 5. Close the emulator (closing the window is the easiest way). Or 
1218   use 'end-avi'.
1220 6. For each tmpdump*.avi file created, on command prompt, do 
1221   'x264 --crf 10 -o tmpdump_<numbers>.mkv tmpdump_<numbers>.avi'.
1223 7. Do 'sox tmpdump.sox tmpdump.ogg rate -v 32000'
1225 8. Do 'mkvmerge -o tmpdump_video.mkv tmpdump_0000000.mkv + 
1226   tmpdump_0000001.mkv + tmpdump_0000002.mkv' (list every 
1227   tmpdump_<numbers>.mkv, with + in between).
1229 9. Do 'mkvmerge -o final.mkv tmpdump_video.mkv tmpdump.ogg'. Now 
1230   final.mkv contains quick'n'dirty encode.
1232 15 Axis configurations for some gamepad types:
1234 15.1 XBox360 controller:
1236 Axes 2 and 5 (joystick<n>axis2 and joystick<n>axis5) should be 
1237 set to pressure-+.
1239 set-axis joystick0axis2 pressure-+
1241 set-axis joystick0axis5 pressure-+
1243 • This is needed for SDL only. EVDEV sets those types correctly.
1245 15.2 PS3 “sixaxis” controller:
1247 Axes 8-19 should be disabled.
1249 set-axis joystick0axis8 disabled
1251 set-axis joystick0axis9 disabled
1253 set-axis joystick0axis10 disabled
1255 set-axis joystick0axis11 disabled
1257 set-axis joystick0axis12 disabled
1259 set-axis joystick0axis13 disabled
1261 set-axis joystick0axis14 disabled
1263 set-axis joystick0axis15 disabled
1265 set-axis joystick0axis16 disabled
1267 set-axis joystick0axis17 disabled
1269 set-axis joystick0axis18 disabled
1271 set-axis joystick0axis19 disabled
1273 16 Errata:
1275 16.1 Problems from BSNES core:
1277 • The whole pending save stuff.
1279 • It is slow (especially accuracy).
1281 • Firmwares can't be loaded from ZIP archives.
1283 16.2 Other problems:
1285 • Modifiers don't work with pseudo-keys.
1287 • Audio for last dumped frame is not itself dumped.
1289 • Audio in UI is pretty bad in quality if game doesn't run at 
1290   full speed.