Lock out odd/even when in graphics mode
[jpcrr.git] / manual.txt
blob452edf0b5d2704b1ed262bba75762587f076b90e
1 JPC-RR: User's manual
3 1 Licence
5 JPC-RR is licenced under GNU GPL v2. See file “LICENSE”
7 2 Getting started
9 2.1 Prerequisites
11 To get started, you need BIOS image, VGABIOS image and DOS boot 
12 floppy and JDK for Java 6 standard edition (later versions should 
13 they appear should also work). Note: JRE is not enough. 
15 Note that to play back recorded movies, you need exact same 
16 version of BIOS image, VGABIOS image and DOS boot floppy as was 
17 used when making the movie (in addition to exact same versions of 
18 other needed media).
20 2.2 Compiling
22 See compile.sh or compile.bat. The streamtools stuff is only 
23 needed for dumping videos.
25 2.3 Getting started
27 First you need to get and make some important images. Obtain BIOS 
28 image, VGABIOS image and DOS boot floppy from somewhere. After 
29 starting the emulator, use Drives -> Import Image to import the 
30 images (ignore the error about no BIOS images being found).
32 2.4 Running emulator
34 There is premade autoexec script called assemble.bat that has 
35 fairly reasonable defaults. To use it:
37 java JPCApplication -library library -autoexec assemble.bat
39 The “-library library” specifies that contents of directory 
40 'library' are to be used as library. The script pops up settings 
41 for new emulated PC (if you want to load savestate, click 
42 cancel). Select BIOS and VGABIOS for BIOS and VGABIOS image (they 
43 should be already selected), DOSfloppy for fda (boot device 
44 should be set to fda) and game image as some HD drive 
46 2.5 Bootup tips
48 • Putting the game as hdd (the fourth hard disk slot) causes boot 
49   to be bit faster.
51 • Some BIOS versions have “press F12 to select boot device”. Hit 
52   <enter> from emulated keyboard and that prompt will go away in 
53   about half emulated second (it stays several emulated seconds 
54   otherwise). 
56 • If game doesn't need lots of memory, hitting F5 to skip 
57   intialization files is fastest. If it does need more memory, 
58   run config.sys commands but not autoexec.bat. 
60 • Some DOS disks have DOSIDLE with them, don't use it as it 
61   messes badly with emulator.
63 3 Making JPC-RR format images from raw images
65 Due to various factors, JPC-RR can't use raw image files directly 
66 but requires its own image format. 
68 3.1 Importing images from GUI:
70 Use Drives -> Import Image to import existing directories or 
71 image files. Dialog prompting parameters will be displayed. When 
72 importing floppy images, check “standard geometry” if possible, 
73 that enables geometry autodetection, which is reasonable 
74 virtually all of the time it is offered.
76 3.2 Notes
78 • If making image from directory, the names of the files must 
79   conform to FAT naming restrictions (8+3 character names, no 
80   spaces, etc). Avoid filenames with non-ASCII characters. 
82 • The DOS limit of 112 or 224 files for floppies does not apply 
83   to images created from directory trees. The minimum limit value 
84   used is 512. If even that isn't enough, the limit is 
85   automatically increased to fit all the needed directory 
86   entries.
88 • Making boot disks from tree does NOT work. Even if you got 
89   system boot files there, it still won't work.
91 • Only floppy disks and hard drives can be made from directory 
92   trees. BIOS images and CDROM images require image file.
94 • Avoid floppies with custom geometry (floppy geometry does 
95   affect disk ID). Disks with over 63 sectors per track don't 
96   work with DOS. Wheither disks with over 127 tracks per side 
97   work with DOS is unknown. Also avoid 1024-tracks per side HDDs.
99 • The geometry limits are: 2-1024 tracks per side for HDD, 1-256 
100   tracks per side for floppy. 1-63 sectors per track for HDD, 
101   1-255 sectors per track for floppy. 1-16 sides for HDD, 1 or 2 
102   sides for floppy. This gives size limit of 65280KiB for floppy 
103   disks (but note the DOS limit!) and 516096KiB for HDDs.
105 • There are multiple image file contents that represent the same 
106   image. The one with smallest size is picked when creating 
107   image.
109 • Note: Although the IDs are 128 bits long, they are not MD5 
110   hashes. 
112 3.3 Importing from command line
114 There is tool called ImageMaker that can make JPC-RR images from 
115 raw images. Each image has format, ID an name. Format and name 
116 are specified when making image. ID is automatically calculated 
117 from format and contents. Name does not affect the ID but is 
118 purely for convience so one doesn't have to specify long image 
119 IDs manually.
121 3.3.1 Syntax
123 The syntax for ImageMaker when making images is:
125 $ java ImageMaker <format> [<options>...] <destination> <source> 
126 <name>
128 <destination> is file name for JPC-RR format image to write. 
129 <source> is either name of regular file (raw image file) or name 
130 of directory tree with files (supported for making floppy or hard 
131 disk images only). In case of directory tree, the files are 
132 layout deterministically to disk, so the ID will always be the 
133 same for given geometry and type. <name> is name to give to disk. 
134 <format> is one of:
136 --BIOS BIOS image (note: VGABIOS is also of this type).
138 --CDROM CD-ROM image.
140 --HDD=cylinders,sectors,heads Hard disk with specified geometry.
142 --floppy=tracks,sectors,sides Floppy disk with specified 
143 geometry.
145 --floppy160 160KiB floppy (40 tracks, 8 sectors, Single sided).
147 --floppy180 180KiB floppy (40 tracks, 9 sectors, Single sided).
149 --floppy320 320KiB floppy (40 tracks, 8 sectors, Double sided).
151 --floppy360 360KiB floppy (40 tracks, 9 sectors, Double sided).
153 --floppy410 410KiB floppy (41 tracks, 10 sectors, Double sided).
155 --floppy420 420KiB floppy (42 tracks, 10 sectors, Double sided).
157 --floppy720 720KiB floppy (80 tracks, 9 sectors, Double sided).
159 --floppy800 800KiB floppy (80 tracks, 10 sectors, Double sided).
161 --floppy820 820KiB floppy (82 tracks, 10 sectors, Double sided).
163 --floppy830 830KiB floppy (83 tracks, 10 sectors, Double sided).
165 --floppy880 880KiB floppy (80 tracks, 11 sectors, Double sided).
167 --floppy1040 1040KiB floppy (80 tracks, 13 sectors, Double 
168 sided).
170 --floppy1120 1120KiB floppy (80 tracks, 14 sectors, Double 
171 sided).
173 --floppy1200 1200KiB floppy (80 tracks, 15 sectors, Double 
174 sided).
176 --floppy1440 1440KiB floppy (80 tracks, 18 sectors, Double 
177 sided).
179 --floppy1476 1476KiB floppy (82 tracks, 18 sectors, Double 
180 sided).
182 --floppy1494 1494KiB floppy (83 tracks, 18 sectors, Double 
183 sided).
185 --floppy1600 1600KiB floppy (80 tracks, 20 sectors, Double 
186 sided).
188 --floppy1680 1680KiB floppy (80 tracks, 21 sectors, Double 
189 sided).
191 --floppy1722 1722KiB floppy (82 tracks, 21 sectors, Double 
192 sided).
194 --floppy1743 1743KiB floppy (83 tracks, 21 sectors, Double 
195 sided).
197 --floppy1760 1760KiB floppy (80 tracks, 22 sectors, Double 
198 sided).
200 --floppy1840 1840KiB floppy (80 tracks, 23 sectors, Double 
201 sided).
203 --floppy1920 1920KiB floppy (80 tracks, 24 sectors, Double 
204 sided).
206 --floppy2880 2880KiB floppy (80 tracks, 36 sectors, Double 
207 sided).
209 --floppy3120 3120KiB floppy (80 tracks, 39 sectors, Double 
210 sided).
212 --floppy3200 3200KiB floppy (80 tracks, 40 sectors, Double 
213 sided).
215 --floppy3520 3520KiB floppy (80 tracks, 44 sectors, Double 
216 sided).
218 --floppy3840 3840KiB floppy (80 tracks, 48 sectors, Double 
219 sided).
221 3.3.2 Other options
223 --volumelabel=label Give specified volume label (affects ID). 
224 Only meaningful when making image out of directory tree. Default 
225 is no volume label.
227 --timestamp=YYYYMMDDHHMMSS Give specified timestamp for files 
228 (affects ID). Only meaningful when making image out of directory 
229 tree. The default timestamp is 19900101T000000Z.
231 3.3.3 Image information
233 When invoked as:
235 $ java ImageMaker <imagefile>
237 Variety of information about image is displayed (especially for 
238 floppies/HDDs). Two important fields are calculated and claimed 
239 disk ID. They should be the same. If they are not, then the image 
240 file is corrupt (sadly, imagemaker has bugs and bugs that cause 
241 it to write corrupt images have been seen).
243 3.4 Advanced: The disk ID algorithm
245 The disk ID is calculated as:
247 Skein-256-128-deprecated(<typecode>|<geometry>|<image>)
249 Where Skein-256-128-deprecated is Skein hash function with 
250 256-bit internal state and 128-bit output using the deprecated 
251 rotation constants (as specified in Skein hash function reference 
252 documentation versions 1.0 and 1.1). The <image> is the whole 
253 image, including parts not stored in image file. The reason for 
254 keeping using the deprecated constants are:
256 • Changing the constants would change the IDs, which would 
257   invalidate existing images
259 • This is not about cryptographic security
261 • The new constants don't improve security that much anyway.
263 3.4.1 Floppies and HDDs
265 Floppies have <typecode> value 0 (single byte) and HDDs have 1 
266 (single byte). <geometry> is as follows (this is exactly the same 
267 form as it appears in image header):
269 Byte 0 bits 0-1: Bits 8-9 of track count per side - 1.
271 Byte 0 bits 2-5: Head count - 1.
273 Byte 0 bits 6-7: Reserved, must be 0.
275 Byte 1: Bits 0-7 of track count per side - 1.
277 Byte 2: Sector count per track - 1.
279 3.4.2 CD-ROM and BIOS images
281 CD-ROMs have <typecode> value 2 (single byte) and BIOS images 
282 have 3 (single byte). <geometry> is blank.
284 3.5 Advanced: Disk Image format
286 The disk image consists of following parts, concatenated in this 
287 order without padding:
289 • Magic
291 • Disk ID
293 • Type code
295 • Disk name length
297 • Disk name
299 • type-specific geometry/size data
301 • Actual image data
303 • Comments
305 3.5.1 Magic
307 Magic in disk image files is following 5 bytes: “IMAGE”
309 3.5.2 Disk ID
311 Disk ID is given as 16 bytes, encoding the 128-bit disk ID.
313 3.5.3 Type code
315 Type code is single byte. 0 for floppies, 1 for HDDs, 2 for 
316 CD-ROMs and 3 for BIOS images. Other values are reserved.
318 3.5.4 Disk name length
320 Obsolete. Disk name length is given as two-byte big-endian value. 
321 New images should have 0 here.
323 3.5.5 Disk name
325 Ignored. Name field is there for backward compatiblity. Disk name 
326 length gives length of this field in bytes.
328 3.5.6 Type-specific geometry/size data (floppies and HDDs)
330 Floppies and HDDs have 3-byte geometry data:
332 Byte 0 bits 0-1: Bits 8-9 of track count per side - 1.
334 Byte 0 bits 2-5: Head count - 1.
336 Byte 0 bits 6-7: Reserved, must be 0.
338 Byte 1: Bits 0-7 of track count per side - 1.
340 Byte 2: Sector count per track - 1.
342 3.5.7 Type specific-geometry/size data (CD-ROMs)
344 CD-ROMs have 4-byte big-endian sector (512 bytes!) count.
346 3.5.8 Type specific-geometry/size data (BIOS images)
348 BIOS images have 4-byte big-endian byte (not sector or block) 
349 count.
351 3.5.9 Actual image data (floppy/HDD)
353 Floppy or HDD imagedata consists of following subparts:
355 • Storage method
357 • Sectors present
359 • Image data header
361 • Image data
363 Storage method is single byte. Sectors present gives number of 
364 last nonzero sector + 1 (zero if image is all zeroes)
366 3.5.10 Floppy/HDD storage method 0: Raw storage
368 This storage method has empty header. Image data is raw dump of 
369 first sectors present sectors.
371 3.5.11 Floppy/HDD storage method 1: Sectormap
373 Image data header contains bitfield with just enough bytes to 
374 have one bit per present sector. The order of bits is such that 
375 number of bit corresponding to each sector in byte is sector 
376 number modulo 8 and byte number is floor of sector number divided 
377 by 8 when sector numbers are counted from zero. If bit 
378 corresponding to sector is set, then the sector is present in 
379 image data, otherwise it is absent and assumed to be all-zeroes.
381 Image data contains dumps of all present sectors in order of 
382 increasing sector number.
384 3.5.12 Floppy/HDD storage method 2: Extent first sector zero
386 Image data is empty as storage-specific data is mangled with 
387 image data. The image data alternates between blocks encoding 
388 zero sectors and blocks encoding nonzero sectors. The first block 
389 encodes zero sectors. 
391 Block encoding zero sectors consist of single 1-4 byte 
392 little-endian value encoding number of sectors in block - 1. 
393 Number of bytes is determined by sectors present value. It is 1 
394 for 1-256 sectors, 2 for 257-65536, 3 for 65537-16777216 and 4 
395 for more than 16777216. All sectors in block are filled with 
396 zeroes and are not stored.
398 Block encoding nonzero sectors has same block count as zero 
399 sector block but is followed by the sectors stored raw.
401 3.5.13 Floppy/HDD storage method 3: Extent first sector nonzero
403 Same as storage method 2 but first block is nonzero sector block.
405 3.5.14 Actual image data (CD-ROMs and BIOS images)
407 These store image data raw. The amount of data is specified by 
408 sector/byte count.
410 3.5.15 Comments
412 Comments are given as list of strings, with UTF-8 encoded strings 
413 following 2-octet big-endian length. Comment list is terminated 
414 by entry with length 0 (0x00 0x00). Comments are optional and may 
415 be absent.
417 4 The actual emulator
419 The actual emulator is invoked as:
421 $ java JPCApplication <options>...
423 The valid options are:
425 -library <library> Use the specified directory when searching for 
426 images (can only be specified once).
428 -autoexec <script> Execute contents of specified file as commands 
429 when starting up.
431 4.1 Command line
433 When emulator is started, command line comes up. Following 
434 commands are known:
436 • 'exit': exit immediately
438 • 'load <plugin>': Load plugin (no arguments)
440 • 'load <plugin>(<arguments>)': load plugin with arguments.
442 • 'command <command> [<arguments>...]': Invoke command via 
443   external command interface.
445 • 'call<command> [<arguments>...]': Invoke command via external 
446   command interface and print return values.
448 When one gets command line, its useful to load some plugins. See 
449 section about plugins. Note: Load runner plugin 
450 (PCControl/PCRunner and so) last, as some runners like to start 
451 PC immediately.
453 4.2 PC settings dialog notes
455 • CPU divider base frequency before division is 1GHz.
457 • Images can be specified by name or by ID. Name is relative to 
458   library directory. If the image is in subdirectory of image 
459   directory, the directory separator is is '/' regardless of what 
460   the host OS uses.
462 • CD-ROM and hdc are mutually exclusive
464 • Modules is comma-seperated list of modules to load. To pass 
465   arguments to some modules, enclose the arguments in (). Same 
466   module can be specified twice only if parameters differ.
468 • Setting boot device doesn't work with some BIOS versions. Those 
469   versions prompt the boot device anyway.
471 4.3 Audio output channels
473 PC can have one or more audio output channels. The name of audio 
474 output associated with PC speaker is: 
475 'org.jpc.emulator.peripheral.PCSpeaker-0'. Modules that have 
476 audio outputs get channel names of form <classname>-<sequential>, 
477 where <classname> is name of main module class and sequential is 
478 number starting from zero. Note that same module can have 
479 multiple output channels. If multiple modules of same class 
480 request audio outputs, the <sequential> values of subsequent 
481 module start where previous left off.
483 4.4 Plugins
485 Plugins actually execute the tasks of the emulator. They can be 
486 loaded using “load <plugin>” or 'load <plugin>(<arguments>)” from 
487 command line.
489 Different Plugins using the same output (like running PCMonitor 
490 and RAWVideoDumper) should not conflict because connector output 
491 hold locking is desinged to handle multiple readers.
493 If no plugin used requires GUI, then the emulator can be run 
494 without having GUI available.
496 4.4.1 plugin: org.jpc.plugins.PCControl
498 No arguments, requires and uses GUI.
500 Runs the PC emulator core. Has capability to start/stop 
501 emulation, breakpoint after certain time or start/end of VGA 
502 vertical retrace. Also can create, savestate and loadstate PC 
503 emulation. Memory dumping is supported. 
505 4.4.2 plugin: org.jpc.plugins.PCRunner
507 Takes 'movie=<file>' as argument and optionally 'stoptime=<time>' 
508 Does not require nor use GUI.
510 Loads PC from savestate and just runs it. CTRL+C to quit. Also 
511 automatically quits once stoptime is reached.
513 4.4.3 plugin: org.jpc.plugins.PCMonitor
515 No arguments, requires and uses GUI.
517 VGA monitor for emulated PC.
519 4.4.4 plugin: org.jpc.plugins.VirtualKeyboard
521 No arguments, requires and uses GUI.
523 On-screen keyboard for emulated PC.
525 4.4.5 plugin: org.jpc.plugins.PCStartStopTest
527 No arguments, requires and uses GUI.
529 Small plugin testing remote PC start/stop. Also supports sending 
530 some common keypresses.
532 4.4.6 plugin: org.jpc.plugins.RAWVideoDumper
534 Takes 'rawoutput=<file>' as argument. Does not require nor use 
535 GUI.
537 Dumps all generated frames to RAW file <file>. Rawoutput is 
538 required. The raw file consists of concatenation of zlib streams. 
539 The uncompressed stream is concatenation of time skips (FFh FFh 
540 FFh FFh), each acting as time offset of 2^32-1 nanoseconds and 
541 saved frames. The saved frame has time offset in nanoseconds (big 
542 endian) as first four bytes (must be at most 2^32-2, as 2^32-1 is 
543 reserved for time skip). The next two bytes are big-endian width, 
544 next two big-endian height. Finally frame has 4 * width * height 
545 bytes of data that encodes pixels using 4 bytes per pixel, in 
546 left-to-right, up-to-down order. Byte 0 of each pixel is 
547 reserved, byte 1 is the red channel, byte 2 is green channel and 
548 byte 3 is blue channel.
550 Dumping to pipe is supported.
552 4.4.7 plugin: org.jpc.plugins.RAWAudioDumper
554 Takes 'src=<name of audio output channel>', 
555 'file=<output-filename>' and 'offset=<offset>' as arguments, 
556 separated by ','. Does not require nor use GUI.
558 Dumps output from specified audio output channel (src, mandatory) 
559 to RAW-format file (file, mandatory). The resulting file consists 
560 of records, 4 or 8 bytes each. 4 byte record consists of 0xFF 
561 0xFF 0xFF 0xFF and means to increase next time delta by 2^{32}-1
562 ns. Otherwise record is 8 bytes. Each 8 byte record has three 
563 fields. First 4 byte unsinged big endian timedelta value (in 
564 nanoseconds, must be smaller than 2^{32}-1), then 2 byte signed 
565 big endian new left channel volume, then 2 byte signed big endian 
566 new right channel volume. Optionally 'offset' can be set to 
567 positive value (in nanoseconds) to delay the audio by.
569 4.4.8 plugin: org.jpc.plugins.LuaPlugin
571 Takes 'kernel=<name of lua kernel file>', other parameters are 
572 passed to kernel, requires and uses GUI.
574 Lua VM for executing scripts.
576 4.4.9 plugin: org.jpc.plugins.JoystickInput
578 No parameters. Displays window for sending joystick input.
580 5 Modules
582 5.1 org.jpc.modules.Joystick:
584 • Arguments: none.
586 • Resources: I/O port 0x201
588 Emulates joystick game port.
590 5.2 org.jpc.modules.SoundCard
592 • Arguments: Optional resources specification
594 • Resources (defaults): I/O port 0x220-0x22F, IRQ 5, DMA 1, DMA 5
596 Emulates Sound card.
598 5.3 org.jpc.modules.FMCard
600 • Arguments: Optional resources specification
602 • Resources (defaults): I/O port 0x338-0x33B
604 Emulates FM card.
606 5.4 org.jpc.modules.BasicFPU:
608 • Arguments: none.
610 • Resources: None.
612 Crude FPU (x87) emulator.
614 6 Hacks
616 Hacks are saved to savestates but not movies.
618 6.1 NO_FPU
620 Force bit 1 of physical address 0x0410 to zero, signaling that 
621 the system has no FPU. BIOS assumes system has FPU but some games 
622 use that bit to detect FPU, trying to use it if it is “present”. 
623 Try this if game startup hangs with lots of trying to use FPU but 
624 not present errors. Don't use if there is FPU present. Needed to 
625 get games like Blake Stone / Wolfenstein 3-D to work (FPU 
626 emulator allows it to start but causes graphical glitches).
628 6.2 VGA_DRAW
630 Update basic VGA parameters before vretrace, not after it. Some 
631 games (e.g. Commander Keen 4) don't like if this isn't done and 
632 some games (e.g. Mario & Luigi) don't like if it is done. Wrong 
633 value manifests as jerky scrolling (scrolling back and forth and 
634 fixed statusbars move).
636 7 Some error messages and explanations
638 • <filename> is Not a valid image file
640 • <filename> is not image file
642 • <filename> claims to be floppy with illegal geometry: <x> 
643   tracks, <y> sides and <z> sectors.
645 • <filename> claims to be HDD with illegal geometry: <x> tracks, 
646   <y> sides and <z> sectors.
648 • Can't read disk image sector map.
650 • Can't read disk image extent.
652 Code expects <filename> to be valid JPC-RR format image, but it 
653 isn't JPC-RR image at all or its corrupt.
655 • <filename> is image of unknown type.
657 • <filename> has unrecognized geometry <x> <y> <z>
659 Possibly corrupt image, not JPC-RR image, or JPC-RR image from 
660 future version containing something current version can't 
661 comprehend.
663 • Invalid format specifier <something>.
665 • Invalid syntax of --floppy= or --HDD= option.
667 • Invalid format specifier/option <something>.
669 Invalid option or format specifier was given. Check for typos.
671 • java ImageMaker [<options>...] <format> <destination> <source> 
672   <diskname>
674 Check syntax of command. Especially that diskname is present!
676 • The image has <nnn> sectors while it should have <yyy> 
677   according to selected geometry.
679 • Raw image file length not divisible by 512.
681 • Trying to read sector out of range.
683 The selected geometry is wrong or raw image is incomplete.
685 • Invalid disk name (Should not happen!).
687 • Invalid geometry to be written.
689 This is a very likely a bug in program.
691 • What the heck <filename> is? It's not regular file nor 
692   directory.
694 That sort of file can't be used as input for image making, or the 
695 file just doesn't exist.
697 • BIOS images can only be made out of regular files.
699 • CD images can only be made out of regular files.
701 Source image specified is not regular file, but image of that 
702 type can't be made of anything else.
704 • Can't read raw bios image file.
706 • Can't read sector <nnn> from image.
708 Reading the raw image file failed for some reason.
710 • Bad library line: "<something>". Ignored.
712 Syntax error in image library.
714 • Removing image <something> a.k.a. "<something>" as it no longer 
715   exists.
717 The image file no longer exists so it gets removed from library.
719 • Removing image <something> a.k.a. "<something>" due to <some> 
720   conflict.
722 Image library code killed some image from library due to some 
723 kind of conflict with image being added.
725 • Too much data to fit into given space.
727 The tree you gave contains takes just too much space to fit into 
728 disk of this size.
730 8 Advanced: Savestate/movie format
732 8.1 Special character classes
734 8.1.1 SPACE
736 Following Unicode codepoints (encoded as UTF-8) are interpretted 
737 as space characters:
739 • Codepoints 0x20, and 0x09.
741 • Codepoints 0x1680, 0x180E, 0x2028, 0x205F and 0x3000
743 • Codepoints 0x2000-0x200A.
745 8.1.2 LINEFEED
747 Following byte sequences are interpretted as linefeeds (line 
748 change):
750 • Byte 0x0A (UTF-8 encoded codepoint 0x0A)
752 • Byte 0x0D (UTF-8 encoded codepoint 0x0D)
754 • Byte 0x1C (UTF-8 encoded codepoint 0x1C)
756 • Byte 0x1D (UTF-8 encoded codepoint 0x1D)
758 • Byte 0x1E (UTF-8 encoded codepoint 0x1E)
760 • Bytes 0xC2 0x85 (UTF-8 for unicode control character NL, 
761   codepoint 0x85)
763 • Bytes 0xE2 0x80 0xA9 (UTF-8 encoded codepoint 0x2029)
765 8.2 JRSR archive
767 JRSR archive format packs multiple text archive members to text 
768 archive. It does not support binary members. JRSR archives have 
769 first five or six bytes form the magic. It is “JRSR” followed by 
770 LINEFEED character There are four kinds of lines after that 
771 (lines are terminated by LINEFEED byte/bytes):
773 • Start member
775 • Member line
777 • End member
779 • Blank line
781 Sequencing rules are as follows: Start member is allowed anywhere 
782 (after magic). Member line is allowed only inside member (member 
783 started but not ended). End member is only allowed inside member. 
784 End of file is only allowed outside member. Blank line is allowed 
785 anywhere after magic.
787 8.2.1 Start member
789 Start member line is given as “!BEGIN” <SPACE>+ <membername> 
790 <LINEFEED>. <SPACE>+ any number of SPACE characters at least one 
791 and <LINEFEED> is LINEFEED chacter. The member name is UTF-8 
792 encoded and maximum allowed line length is 2048 bytes (including 
793 LINEFEED, which means name is limited to 509-2040 codepoints 
794 depending on characters used). Starting member inside another 
795 implicitly ends the previous member.
797 8.2.2 Member line:
799 Member line is given as “+”<content><LINEFEED>. It gives another 
800 line for member contents. <content> is passed raw to layers above 
801 (followed by line termination)
803 8.2.3 End member
805 End member line is given as “!END”<LINEFEED>. It ends the current 
806 member. The following line can only be start member line or file 
807 may end.
809 8.2.4 Blank line
811 Blank line is given as <LINEFEED>. Lines like that are ignored.
813 8.3 Four-to-Five encoding
815 Binary members are encoded into text by so-called four-to-five 
816 encoding. This encoding can encode single byte to two, two bytes 
817 to three, three bytes to four and four bytes to five. 
818 Four-to-five encoding has five kinds of blocks. All SPACE and 
819 LINEFEED characters are completely ignored, even in middle of 
820 blocks.
822 8.3.1 End stream block
824 End stream block is encoded as '!'. It ends the stream instantly. 
825 There is also implicit end of stream at end of input to decoding.
827 8.3.2 Other four block types
829 Other four block types take the value to be encoded, read it as 
830 big-endian value. Then they write it as base-93 big-endian value. 
831 Then length specific constants are added to digits of that number 
832 to yield ASCII values for characters (those are stored in order):
835 +------------+------------+------------+------------+------------+-----------+
836 | To encode  | 1st char.  | 2nd char.  | 3rd char.  | 4th char.  | 5th char. |
837 +------------+------------+------------+------------+------------+-----------+
838 +------------+------------+------------+------------+------------+-----------+
839 |  1 byte    |    34      |    34      |     -      |     -      |     -     |
840 +------------+------------+------------+------------+------------+-----------+
841 |  2 bytes   |    37      |    34      |    34      |     -      |     -     |
842 +------------+------------+------------+------------+------------+-----------+
843 |  3 bytes   |    45      |    34      |    34      |    34      |     -     |
844 +------------+------------+------------+------------+------------+-----------+
845 |  4 bytes   |    66      |    34      |    34      |    34      |    34     |
846 +------------+------------+------------+------------+------------+-----------+
849 Blocks which encode values greater than what is possible for 
850 value of that length are fatal errors. 
852 8.4 Line component encoing
854 Line component encoding sits on top of UTF-8 encoding. Line 
855 component encoding encodes non-empty 1-D array of non-empty 
856 strings into line, and thus array of those into member. Empty 
857 lines or lines that don't contain any components are ignored. 
858 Line starts with depth value of 0 and must end with depth value 
859 of zero.
861 Components are seperated by component separators. Empty 
862 components are ignored. Following codepoints are separators on 
863 depth 0 if not escaped:
865 • Codepoint of '('. The depth is read pre-increment.
867 • Codepoint of ')'. The depth is read post-decrement.
869 • Any SPACE character
871 The following characters are special:
873 • '('. Increments depth by 1 if not escaped (and appears in 
874   component).
876 • ')'. Decrements depth by 1 if not escaped (and appears in 
877   component). Depth going negative is an error.
879 • '\'. Next character is interpretted as literal. Error if at end 
880   of line.
882 Otherwise, characters are interpretted as literals and appear in 
883 components. Depth must be zero at end of line.
885 8.5 Header section:
887 Header section is in archive member "header". It uses line 
888 component encoding. The first component of each line is name of 
889 header, and subsequent ones are arguments. How many parameters 
890 are expected is dependent on what header it is:
892 8.5.1 PROJECTID header:
894 • Header name: "PROJECTID"
896 • Components: 2
898 • Argument #1: <project-id-string>
900 • Mandatory: Yes
902 Gives project ID. Project ID is generated when PC is assembled 
903 and is then preserved in save states. It is used for computing 
904 rerecord counts. Emulator treats it as opaque string, the IDs it 
905 generates are formed by 48 random hexadecimal digits.
907 8.5.2 SAVESTATEID header:
909 • Header name: "SAVESTATEID"
911 • Components: 2
913 • Argument #1: <savestate-id-string>
915 • Mandatory: No
917 Gives save state ID. Each save state has its own save state ID. 
918 Treated as opaque string, but generated as 48 random hexadecimal 
919 digits. The presence of this header signals whether there is save 
920 state to be loaded. If this header is present, save state load 
921 will be attempted. If absent, save state is not to be loaded even 
922 if present (and correct savestate load would be technically 
923 impossible anyway).
925 The value is used to prevent loading incompatible save states in 
926 preserve event stream mode and also to find the point in event 
927 stream where one left off.
929 8.5.3 RERECORDS header:
931 • Header name: "RERECORDS"
933 • Components: 2
935 • Argument #1: <rerecords>
937 • Mandatory: Yes
939 Gives rerecord count. PC assembly (except when loading save 
940 state) initializes current rerecord count to zero. Must be 
941 non-negative and decimal number using ASCII digit characters.
943 On loading save state:
945 1) If project ID matches with previous:
947 1a) If loaded rerecord count is larger or equal to current 
948 rerecord count:
950 1a-a) Current rerecord count is loaded rerecord count + 1.
952 1b) Otherwise
954 1b-a) Current rerecord count increments by 1.
956 2) Otherwise
958 2a) Current rerecord count is loaded rerecord count + 1.
960 The current rerecord count at time of save is saved to save 
961 state.
963 8.5.4 AUTHORS header:
965 • Header name: "AUTHORS"
967 • Components: 2 or more
969 • Arguments: free form
971 • Mandatory: No
973 Gives authors of run. Each argument gives one author. May be 
974 present multiple times.
976 8.5.5 COMMENT header:
978 • Header name: "COMMENT"
980 • Components: 2 or more
982 • Arguments: free form
984 • Mandatory: No
986 Various kinds of free form data. Not parsed further by emulator.
988 8.6 Initialization segment:
990 If SAVESTATEID header isn't present (not a save state), member 
991 "initialization" gives PC initialization parameters for 
992 assembling the PC. It is present anyway even if SAVESTATEID is 
993 present (savestate).
995 Following parameters are used (space separates components):
997 "BIOS" <id>
999 Gives Image ID of main system BIOS (mandatory)
1001 "VGABIOS" <id>
1003 Gives Image ID of VGA BIOS (mandatory).
1005 "HDA" <id>
1007 Gives Image ID of hda. Present only if system has hard disk hda.
1009 "HDB" <id>
1011 Gives Image ID of hdb. Present only if system has hard disk hdb.
1013 "HDC" <id>
1015 Gives Image ID of hdc. Present only if system has hard disk hdc.
1017 "HDD" <id>
1019 Gives Image ID of hdd. Present only if system has hard disk hdd.
1021 "DISK" <num> <id>
1023 Gives Image ID of disk in slot <num>. Slot number must be 
1024 non-negative.
1026 “DISKNAME” <num> <name>
1028 kGives image name of disk in slot <num>. Slot number must be 
1029 non-negative. The slot must be previously declared using “DISK”.
1031 "FDA" <num>
1033 Gives Image slot to initially put into floppy drive fda. Disk 
1034 must be of floppy type. If none present, no disk is initially put 
1035 there.
1037 "FDB" <num>
1039 Gives Image slot to initially put into floppy drive fdb. Disk 
1040 must be of floppy type. If none present, no disk is initially put 
1041 there.
1043 "CDROM" <num>
1045 Gives Image slot to initially put into CD-ROM drive hdc. Not 
1046 allowed if hard disk hdc is present. Disk must be of CD-ROM type. 
1047 If none present no disk is initially put there.
1049 "INITIALTIME" <time>
1051 Number of milliseconds since Unix epoch to system start up time. 
1052 Allowed range:
1054 0-4102444799999. Mandatory.
1056 "CPUDIVIDER" <divider>
1058 Set CPU frequency divider (dividing the 1GHz master clock). 
1059 Allowed range is 1-256. Mandatory.
1061 "MEMORYSIZE" <pages>
1063 Number of 4KiB pages of RAM memory. Allowed range 256-262144. 
1064 Mandatory.
1066 "BOOT" <device>
1068 Set boot device. Valid devices are "FLOPPY" (boot from fda), 
1069 "HDD" (boot from hda) and "CDROM" (boot from CD).
1071 "LOADMODULEA" <module> <parameters>
1073 Load module <module> with parameters <parameters>.
1075 "LOADMODULE" <module>
1077 Load module <module> with no parameters
1079 “FPU” <fpu>
1081 Use class <fpu> as FPU emulator.
1083 “IOPORTDELAY”
1085 Use I/O port delay emulation (each I/O port read/write takes 
1086 666ns).
1088 “VGAHRETRACE”
1090 Emulate VGA horizontal retrace.
1092 8.7 Event record format:
1094 Event record is in archive member "events". It uses line 
1095 component encoding. Each line gives an event. First component of 
1096 each line gives time stamp. These timestamps MUST be in 
1097 increasing order and all MUST be non-negative. Time stamp time 
1098 unit is exactly 1 nanosecond of emulated time.
1100 The second component of each line is name of class to dispatch 
1101 to. Further components are passed as-is to event handlers. 
1102 Classes with names consisting only of uppercase A-Z and 0-9 are 
1103 special and reserved. It is error to encounter unknown such 
1104 special class.
1106 8.7.1 Savestate event
1108 • Dispatch to: SAVESTATE
1110 • Argument #1: Savestate id
1112 • Argument #2 (optional): Rerecord count at time of saving 
1113   savestate
1115 Signals that savestate has occured here. The save state IDs MUST 
1116 be unique in entire event stream. The second argument to 
1117 savestate (if present) is rerecord count at time of saving that 
1118 savestate (useful for calulating rerecord count of movie starting 
1119 from savestate). No time restrictions
1121 8.7.2 Option event
1123 • Dispatch to: OPTION
1125 • Argument #1: “ABSOLUTE” or “RELATIVE”
1127 Controls various options. “ABSOLUTE” turns on absolute mode 
1128 (default) where event timestamps are absolute. “RELATIVE” turns 
1129 on relative mode where event timestamps are relative to last 
1130 event in stream. The OPTION event itself is not affected by 
1131 timing change. No time restrictions. Unknown arguments are 
1132 errors.
1134 8.7.3 Keyboard keypress/keyrelease event:
1136 • Dispatch to: org.jpc.emulator.peripheral.Keyboard
1138 • Argument #1: Fixed: "KEYEDGE"
1140 • Argument #2: Key number. Valid values are 1-83, 85-95, 129-197 
1141   and 199-223
1143 Send key press or key release. Keys work in toggle button manner. 
1144 The event time must be multiple of 66 666, and must not be less 
1145 than 60 * 66 666 TUs after last PAUSE event, 20 * 66 666 TUs 
1146 after last KEYEDGE on key >128 and 10 * 66 666 TUs after last 
1147 KEYEDGE on key <128.
1149 8.7.4 Pause event:
1151 • Dispatch to: org.jpc.emulator.peripheral.Keyboard
1153 • Argument #1: Fixed: "PAUSE"
1155 Send pause key event. The time restrictions are identical to 
1156 KEYEDGE event.
1158 8.7.5 Mouse button event:
1160 • Dispatch to: org.jpc.emulator.peripheral.Keyboard
1162 • Argument #1: Fixed: "MOUSEBUTTON"
1164 • Argument #2: Number of button to release or press (0-4)
1166 Presses or releases the designated mouse button.
1168 8.7.6 X mouse motion event:
1170 • Dispatch to: org.jpc.emulator.peripheral.Keyboard
1172 • Argument #1: Fixed: "XMOUSEMOTION"
1174 • Argument #2: Number of units to move (-255 - 255)
1176 Move the mouse in X direction by specified amount. Positive is 
1177 right.
1179 8.7.7 Y mouse motion event:
1181 • Dispatch to: org.jpc.emulator.peripheral.Keyboard
1183 • Argument #1: Fixed: "YMOUSEMOTION"
1185 • Argument #2: Number of units to move (-255 - 255)
1187 Move the mouse in Y direction by specified amount. Positive is 
1190 8.7.8 Z mouse motion event:
1192 • Dispatch to: org.jpc.emulator.peripheral.Keyboard
1194 • Argument #1: Fixed: "ZMOUSEMOTION"
1196 • Argument #2: Number of units to move (-7 - 7)
1198 Move the mouse in Z direction (scrollwheel) by specified amount.
1200 8.7.9 Joystick button event:
1202 • Dispatch to: org.jpc.modules.Joystick
1204 • Argument #1: “BUTTONA”, “BUTTONB”, “BUTTONC” or “BUTTOND”
1206 • Argument #2: “0” if released, “1” if pressed
1208 Send button down/up event. No time restrictions.
1210 8.7.10 Joystick axis event:
1212 • Dispatch to: org.jpc.modules.Joystick
1214 • Argument #1: “AXISA”, “AXISB”, “AXISC” or “AXISD”
1216 • Argument #2: Multivibrator unstable state length in ns.
1218 Set amount of time multivibrator remains in unstable state. No 
1219 time restrictions.
1221 8.7.11 Reboot:
1223 • Dispatch to: org.jpc.emulator.PC$ResetButton
1225 • No arguments
1227 Reboots the PC.
1229 8.7.12 Fda disk change:
1231 • Dispatch to: org.jpc.emulator.PC$DiskChanger
1233 • Argument #1: Fixed: "FDA"
1235 • Argument #2: Number of image slot to put there. 
1237 The disk number MUST be -1 or valid disk number. -1 MUST NOT be 
1238 used if there is no disk in floppy drive A. This event causes 
1239 specified disk to be placed to FDA or FDA disk to be ejected with 
1240 no replacement if disk number is -1. The specified disk if not -1 
1241 must be of floppy type. The specified disk if valid must not be 
1242 in any other drive.
1244 8.7.13 Fdb disk change:
1246 • Dispatch to: org.jpc.emulator.PC$DiskChanger
1248 • Argument #1: Fixed: "FDB"
1250 • Argument #2: Number of image slot to put there. 
1252 The disk number MUST be -1 or valid disk number. -1 MUST NOT be 
1253 used if there is no disk in floppy drive B. This event causes 
1254 specified disk to be placed to FDB or FDB disk to be ejected with 
1255 no replacement if disk number is -1. The specified disk if not -1 
1256 must be of floppy type. The specified disk if valid must not be 
1257 in any other drive.
1259 8.7.14 Change CDROM:
1261 • Dispatch to: org.jpc.emulator.PC$DiskChanger
1263 • Argument #1: Fixed: "CDROM"
1265 • Argument #2: Number of image slot to put there. 
1267 The disk number MUST be -1 or valid disk number. -1 MUST NOT be 
1268 used if there is no disk in CD-ROM. This event causes specified 
1269 disk to be placed to CD-ROM or CD-ROM disk to be ejected with no 
1270 replacement if disk number is -1. The specified disk if not -1 
1271 must be of CD-ROM type.
1273 This event has no effect if CD-ROM is locked.
1275 8.7.15 Write protect floppy:
1277 • Dispatch to: org.jpc.emulator.PC$DiskChanger
1279 • Argument #1: Fixed: "WRITEPROTECT"
1281 • Argument #2: Number of image slot to manipulate 
1283 Write protects specified disk. The disk MUST NOT be in any drive 
1284 and MUST be valid floppy-type disk.
1286 8.7.16 Write unprotect floppy:
1288 • Dispatch to: org.jpc.emulator.PC$DiskChanger
1290 • Argument #1: Fixed: "WRITEUNPROTECT"
1292 • Argument #2: Number of image slot to manipulate 
1294 Disables write protection specified disk. The disk MUST NOT be in 
1295 any drive and MUST be valid floppy-type disk.
1297 8.8 Diskinfo sections
1299 Diskinfo sections are named “diskinfo-”<id of disk>. They use 
1300 line component encoding, fieldtype being first component on each 
1301 line (value being the second). Following fields are defined:
1303 8.8.1 TYPE
1305 Gives type of image. Possible values are
1307 • “FLOPPY” (floppy disk)
1309 • “HDD” (Hard disk)
1311 • “CDROM” (CD-ROM)
1313 • “BIOS” (BIOS/VGABIOS image)
1315 • “UNKNOWN” (what the heck is this???)
1317 8.8.2 ID
1319 Gives ID of disk.
1321 8.8.3 IMAGELENGTH
1323 (BIOS images only) Gives length of BIOS image
1325 8.8.4 IMAGEMD5
1327 MD5 of raw disk/BIOS image without any headers or trailers.
1329 8.8.5 TOTALSECTORS
1331 (FLOPPY/HDD/CDROM images only) Number of total sectors on disk.
1333 8.8.6 TRACKS
1335 (FLOPPY/HDD images only) Number of tracks on disk per side (1-256 
1336 for floppy, 1-1024 for HDD).
1338 8.8.7 SIDES
1340 (FLOPPY/HDD images only) Number of sides on disk (1 or 2 for 
1341 floppy, 1-16 for HDD).
1343 8.8.8 SECTORS
1345 (FLOPPY/HDD images only) Number of sectors per track (1-255 for 
1346 floppy, 1-63 for HDD).
1348 8.8.9 COMMENT
1350 Line from image comment block. Usually give data about files 
1351 image has. May or may not be present (multiple times)
1353 8.9 Output info
1355 Output info is stored in section “output-info”. Its relatively 
1356 new, so it might not be present (then the contents have to be 
1357 guessed based on modules present). Each line gives information 
1358 about one output, first field being the type of output.
1360 8.9.1 Video output
1362 For video output, there are no parameters so line is just “VIDEO” 
1363 (one component).
1365 8.9.2 Audio output
1367 For audio output, the only parameter is name of output, so first 
1368 component is “AUDIO” and second component is name of audio 
1369 output.
1371 8.10 Savestates
1373 Actual savestate format is not documented here. It is close to 
1374 impossible to comprehend without access to emulator source 
1375 anyway.
1377 9 Advanced: Making class dumpable
1379 Class is made dumpable by implementing interface 
1380 org.jpc.emulator.SRDumpable and implementing method 
1381 dumpSRPartial(org.jpc.emulator.SRDumper) and constructor 
1382 <init>(org.jpc.emulator.SRLoader). Non-static inner classes can 
1383 not be dumpable (make them static using tricks similar to what 
1384 javac uses).
1386 If dumped class has dumpable superclass, the first thing dumping 
1387 function needs to do is to call dumper function of superclass and 
1388 first thing loading constructor needs to do is to call loading 
1389 constructor of superclass. If class has no dumpable superclass, 
1390 dumper doesn't need to do anything special, while loader needs to 
1391 call objectCreated(this) on SRLoader object passed as parameter. 
1393 Following these fixed parts, dump all members that are part of 
1394 mutable state in emulator core.
1396 9.1 Member dumping/loading functions
1398 There is dumping/loading function for following (all functions 
1399 dumping/loading reference types can handle null):
1401 • boolean: SRDumper.dumpBoolean, SRLoader.loadBoolean
1403 • byte: SRDumper.dumpByte, SRLoader.loadByte
1405 • short: SRDumper.dumpShort, SRLoader.loadShort
1407 • int: SRDumper.dumpInt, SRLoader.loadInt
1409 • long: SRDumper.dumpLong, SRLoader.loadLong
1411 • String: SRDumper.dumpString, SRLoader.loadString
1413 • boolean[]: SRDumper.dumpArray, SRLoader.loadArrayBoolean
1415 • byte[]: SRDumper.dumpArray, SRLoader.loadArrayByte
1417 • short[]: SRDumper.dumpArray, SRLoader.loadArrayShort
1419 • int[]: SRDumper.dumpArray, SRLoader.loadArrayInt
1421 • long[]: SRDumper.dumpArray, SRLoader.loadArrayLong
1423 • double[]: SRDumper.dumpArray, SRLoader.loadArrayDouble
1425 • <dumpable type>: SRDumper.dumpObject, SRLoader.loadObject
1427 • special object: SRDumper.specialObject, SRLoader.specialObject
1429 9.1.1 Notes:
1431 • Dumpable objects come out as type of 
1432   org.jpc.emulator.SRDumpable.
1434 • Special objects are various static objects that don't need to 
1435   be stored because they don't have mutable fields.
1437 • Don't dump fields related to event state feedback.
1439 • Don't dump temporary flags that are only used while PC is 
1440   running. Savestate when PC is running isn't possible anyway.
1442 • Some connectors dump fields related to connector output, some 
1443   don't.
1445 10 Advanced: Making output connectors
1447 Implementing interface org.jpc.emulator.DisplayController signals 
1448 that this is display controller, inhibiting loading of the 
1449 standard VGA display controller if loaded as module. 
1451 10.1 Interface org.jpc.emulator.OutputConnector
1453 Class is made to be output connector by implementing this 
1454 interface. This interface specifies the methods used for output 
1455 hold locking. Class org.jpc.emulator.OutputConnectorLocking has 
1456 implementations of these that are suitable for calling. 
1458 10.1.1 Method subscribeOutput(Object)
1460 Subscribes the output, with specified object as handle.
1462 10.1.2 Method unsubscribeOutput(Object)
1464 Unsubscribe the specified handle object from output.
1466 10.1.3 Method waitOutput(Object)
1468 Wait for output on specified connector using specified handle 
1469 object. Returns true on success, false if wait was interrupted by 
1470 thread interrupt. Blocking.
1472 10.1.4 Method releaseOutput(Object)
1474 Release connector from p.o.v. of given handle. Does not block.
1476 10.1.5 Method holdOutput()
1478 Release threads waiting on waitOutput() and block until all 
1479 subscribers have returned from waitOutput() and enteired 
1480 releaseOutput().
1482 10.1.6 Method releaseOutputWaitAll(object)
1484 Like releaseOutput(), but waits until all handles have released 
1485 their output.
1487 10.2 Class org.jpc.emulator.VGADigtalOut
1489 Class org.jpc.emulator.VGADigtalOut (already implements 
1490 OutputConnector) implements VGA output connector. If module 
1491 provodes output connector, it needs to implement 
1492 org.jpc.emulator.DisplayController.
1494 10.2.1 Method getWidth()
1496 Get width of display (watch out, can return 0).
1498 10.2.2 Method getHeight()
1500 Get height of display (watch out, can return 0).
1502 10.2.3 Methods getDirtyXMin(), getDirtyXMax(), getDirtyYMin(), 
1503   getDirtyYMax()
1505 Returns the dirty region (region modified since last output).
1507 10.2.4 Method getBuffer()
1509 Get buffer of ints, at least width * height elements 
1510 (left-to-right, top-down, one value per pixel) giving pixel data. 
1511 Value for each pixel is 65536 * <red-component> + 256 * 
1512 <green-component> + <blue-component>.
1514 10.2.5 Method resizeDisplay(int _width, int _height)
1516 Resize the display to be of specified size.
1518 10.2.6 Method dirtyDisplayRegion(int x, int y, int w, int h)
1520 Mark the specified region as dirty.
1522 10.2.7 Method resetDirtyRegion()
1524 Resets the dirty region to be empty.
1526 10.3 Class org.jpc.emulator.PC method getVideoOutput()
1528 Get VGA output connector for PC.
1530 10.4 Interface org.jpc.emulator.DisplayController.
1532 Implementing this class signals that module is VGA controller. 
1533 There can be only one such module active at time and presence of 
1534 such module prevents loading builtin VGA controller emulation 
1535 code.
1537 10.4.1 Method getOutputDevice()
1539 Get VGA output connector for this VGA device.
1541 10.5 Class org.jpc.emulator.SoundDigitalOut
1543 Class org.jpc.emulator.SoundDigitalOut provodes output connector 
1544 for sound. Each connector can transfer stereo signal at arbitiary 
1545 sampling rate. Modules that have audio connectors need to 
1546 implement interface org.jpc.emulator.SoundOutputDevice, as this 
1547 signals that output connectors should be created.
1549 10.5.1 Method addSample(long, short, short)
1551 Add stereo sample at time given by first argument. The second and 
1552 third arguments give volume on left and right channels.
1554 10.5.2 Method addSample(long, short)
1556 Add mono sample at time given by first argument. The second 
1557 argument give volume on both channels.
1559 10.5.3 Method readBlock(Block)
1561 Reads block of output (atomic versus addSample). Block structure 
1562 has following fields which are filled:
1564 • timeBase: Time base for block.
1566 • baseLeft: Left volume at time base.
1568 • baseRight: Right volume at time base
1570 • blockNo: Sequence number of block filled.
1572 • samples: Number of samples in block
1574 • sampleTiming: Number of nanoseconds since last sample
1576 • sampleLeft: Left channel samples
1578 • sampleRight: Right channel samples
1580 10.6 Interface org.jpc.emulator.SoundOutputDevice
1582 Implementing this interface signals that module has audio output 
1583 channels.
1585 10.6.1 Method 
1586   org.jpc.emulator.SoundOutputDevice.requestedSoundChannels()
1588 Return the number of sound channels module has.
1590 10.6.2 Method 
1591   org.jpc.emulator.SoundOutputDevice.soundChannelCallback(SoundDigitalOut)
1593 This is called once per sound channel requested giving precreated 
1594 sound channel.
1596 10.7 Class org.jpc.emulator.PC method getSoundOut(String)
1598 Get sound output with specified name.
1600 11 Advanced: Writing event targets
1602 Whereas output connectors are the way output is dispatched, input 
1603 is dispatched via event targets. Event targets need to implement 
1604 interface org.jpc.emulator.EventDispatchTarget.
1606 Event targets also provode methods which then encode events and 
1607 dispatch them forward (without doing anything else) to event 
1608 recorder. Also, event targets may have methods for obtaining 
1609 state.
1611 11.1 Interface org.jpc.emulator.EventDispatchTarget
1613 Interface that marks class capable of receiving events.
1615 11.1.1 Method setEventRecorder(EventRecorder)
1617 Set the event recorder input events are sent to.
1619 11.1.2 Method startEventCheck()
1621 Signals target to reset all state related to event checking and 
1622 state feedback. This may be called at any time in order to 
1623 reinitialialize event checking/feedback state.
1625 11.1.3 Method doEvent(long, String[], int) throws IOException
1627 Event dispatch handler. The first argument is event time, second 
1628 is parameters and third is what to do with it. If target doesn't 
1629 like the event, throw IOException. Following types (the integer 
1630 parameter) are used:
1632 0 (EventRecorder.EVENT_TIMED): Time has been assigned for event.
1634 1 (EventRecorder.EVENT_STATE_EFFECT_FUTURE): Future event in 
1635 event replay for reinitialization
1637 2 (EventRecorder.EVENT_STATE_EFFECT): Past event in event replay 
1638 reinitialization
1640 3 (EventRecorder.EVENT_EXECUTE): This event occurs now. Execute 
1641 the effect.
1643 11.1.4 Method endEventCheock()
1645 End event reinitialization. Usually unused.
1647 11.1.5 Method getEventTimeLowBound(long, String[]) throws 
1648   IOException
1650 Return the time value that's the earliest possiblity for this 
1651 event to occur. Returning any time in past (including -1) causes 
1652 event to fire as soon as possible. The long parameter gives the 
1653 current scheduled time for event.
1655 12 Writing modules
1657 Modules are various extensions that run inside emulator core. As 
1658 such, they affect sync. Modules must implement interface 
1659 org.jpc.emulator.HardwareComponent (they are hardware components) 
1660 and must be dumpable. Additionally, they need either constructor 
1661 <init>() or <init>(String). The first is if no parameters are 
1662 passed, the second is for case where parameters are passed.
1664 Aside of the constructors, modules need to obey the ordinary 
1665 conventions for hardware components. No code outside modules 
1666 needs to know that module exists.
1668 13 Writing plugins
1670 Plugins handle various UI tasks. They need to implement interface 
1671 org.jpc.Plugin.
1673 13.1 Interface org.jpc.pluginsbase.Plugin
1675 13.1.1 Method systemShutdown()
1677 Called when emulator shuts down. Either called in dedicated 
1678 thread or in thread that called emulatorShutdown(). These 
1679 handlers should do the bare minimum to get files on disk to 
1680 consistent state. After these calls from all plugins have 
1681 finished, emulator exits. Do not try to manipulate UI from these 
1682 methods, as doing that easily leads into deadlock.
1684 13.1.2 Method reconnect(PC) 
1686 Gives new PC to connect to. Null is passed if plugin should 
1687 disconnect.
1689 13.1.3 Method main()
1691 Called in dedicated thread after plugin is initialized.
1693 13.1.4 Method pcStopping()
1695 Called after PC has stopped.
1697 13.1.5 Method pcStarting()
1699 Called before PC starts.
1701 13.1.6 Method notifyArguments(String[])
1703 Pass arguments from command line.
1705 13.1.7 Constructor <init>(Plugins)
1707 This constructor is used to initialize plugins that don't take 
1708 parameters.
1710 13.1.8 Constructor <init>(Plugins, String)
1712 This constructor is used to initialize plugins that take 
1713 parameters.
1715 13.2 Class org.jpc.pluginsbase.Plugins
1717 This class provodes various methods for manipulating plugins.
1719 13.2.1 Method isShuttingDown()
1721 Returns true if Plugins.shutdownEmulator() has been called 
1722 somehow, either via VM exit, CTRL+C or explicitly. Useful to skip 
1723 cleanups involving GUI, as these are too deadlock-prone.
1725 13.2.2 Method shutdownEmulator()
1727 Shut down and exit the emulator. All plugin shutdown functions 
1728 are called in this thread.
1730 13.2.3 Method reconnectPC(PC)
1732 Signal reconnectPC event to all plugins.
1734 13.2.4 Method pcStarted()
1736 Signal pcStarting() event to all plugins.
1738 13.2.5 Method pcStopped()
1740 Signal pcStopping() event to all plugins.
1742 14 Inter-plugin communication
1744 14.1 Receiving communications
1746 To receive invocation/call by name 'foo-bar', declare public 
1747 method named 'eci_foo_bar'. Arguments to this method can 
1748 currently be String, Integer (int) or Long (long). Last argument 
1749 may be array over these types to get variable number of 
1750 arguments. On call, each argument gets value from call. If last 
1751 argument is array, it gets all overflowing arguments. If return 
1752 type is void or method returns boolean false, call is assumed to 
1753 have completed. If return value is boolean true, it is assumed 
1754 that there is more processing.
1756 14.2 void 
1757   org.jpc.pluginsbase.Plugins.invokeExternalCommand(String cmd, 
1758   Object[] args) 
1760 Invoke command asynchronously, broadcasting to all plugins. Does 
1761 not wait for slow commands to complete. cmd is the name to send 
1762 and args are the arguments to pass.
1764 14.3 void 
1765   org.jpc.pluginsbase.Plugins.invokeExternalCommandSynchronous(String 
1766   cmd, Object[] args) 
1768 Same as invokeExternalCommand, but waits for slow commands to 
1769 complete.
1771 14.4 Object[] 
1772   org.jpc.pluginsbase.Plugins.invokeExternalCommandReturn(String 
1773   cmd, Object[] args) 
1775 Similar to invokeExternalCommandSynchornous, but:
1777 • Quits calling more plugins when it gets successful reply.
1779 • Returns said reply
1781 14.5 void org.jpc.pluginsbase.Plugins.returnValue(Object... ret)
1783 Gives return value to return from call and signals that command 
1784 has completed.
1786 14.6 void org.jpc.pluginsbase.Plugins.signalCommandCompletion()
1788 Signals that command has completed. Only needed if there is no 
1789 return value and eci_ method returned false (not done yet).
1791 15 Lua kernel programming
1793 At startup, kernel gets its arguments in 'args' table and the 
1794 script name to run in 'scriptname' string. It should enter the 
1795 named script in protected mode.
1797 The Lua VM exports numerious callbacks to kernel. The kernel can 
1798 then choose to omit, wrap or re-export these to Lua scripts.
1800 • Always grab any functions used into local variables so nobody 
1801   can mess with them
1803 • Don't use global variables in kernel (except for those passed).