<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.kodewerx.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Parasyte</id>
		<title>Kodewerx - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://www.kodewerx.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Parasyte"/>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/wiki/Special:Contributions/Parasyte"/>
		<updated>2026-05-15T22:42:51Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.30.2</generator>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=RLM&amp;diff=2045</id>
		<title>RLM</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=RLM&amp;diff=2045"/>
				<updated>2020-12-28T06:28:11Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;RLM is a program designed to &amp;quot;unprotect&amp;quot; Super Mario World ROM hacks that were &amp;quot;protected&amp;quot; with the Lunar Magic level editor. RLM stands for &amp;quot;Recover Lunar Magic&amp;quot;. Also seen in the source code, &amp;quot;Rape Lunar Magic&amp;quot; was once considered.&lt;br /&gt;
&lt;br /&gt;
==Version History==&lt;br /&gt;
&lt;br /&gt;
v1.3 (12-26-09):&lt;br /&gt;
* Fixed yet another last-known-problem with (what I believe is) &amp;quot;Super ExGFX&amp;quot;.&lt;br /&gt;
* Support for drag-n-drop (see &amp;quot;Using RLM&amp;quot;).&lt;br /&gt;
* Readme cleanup.&lt;br /&gt;
&lt;br /&gt;
v1.2 (04-18-05):&lt;br /&gt;
* Fixed the last known problem with OverWorld decryption.&lt;br /&gt;
&lt;br /&gt;
v1.1 (01-16-05):&lt;br /&gt;
* Fixed a problem with OverWorld decryption.&lt;br /&gt;
* Changed copyright years from 2003-2004 to 2003-2005.&lt;br /&gt;
* Added a version number define to make version changes easier.&lt;br /&gt;
&lt;br /&gt;
v1.0 (01-13-05):&lt;br /&gt;
* Initial release!&lt;br /&gt;
&lt;br /&gt;
==Lunar Magic Protection==&lt;br /&gt;
&lt;br /&gt;
The protection scheme used by Lunar Magic is simple albeit effective against inexperienced hackers. When protecting a hack, the editor will write a few bytes into the SMC header as well as the SNES ROM header which it uses to signal to itself that the ROM is protected. Reversing these changes is enough to bypass the &amp;quot;Lunar Magic cannot open this ROM&amp;quot; message, but you will run into trouble when you open the edited stages.&lt;br /&gt;
&lt;br /&gt;
Almost everything that Lunar Magic edits will be encrypted with a simple XOR operation, when a hack is protected; unedited stages and objects will remain in their original, unencrypted state.&lt;br /&gt;
&lt;br /&gt;
The first thing encrypted is the stage pointers. To anyone looking in a hex editor, they appear to point to invalid stage data (because they do). Decrypting these pointers shows you were to find the valid &amp;quot;RATS&amp;quot; headers, as well as encrypted stage data. At this point, decrypting the stage data is enough to open the hack in Lunar Magic. However, the ROM will not work on an SNES or an emulator, due to an assembly hack in place which will try to decrypt the already-decrypted stage data. Reverting the assembly hack will make the ROM playable.&lt;br /&gt;
&lt;br /&gt;
Other edited objects in the ROM are also encrypted in a similar manner. The overworld is a particularly big example. I believe the &amp;quot;ExGFX&amp;quot; are also encrypted.&lt;br /&gt;
&lt;br /&gt;
==RLM Specifics==&lt;br /&gt;
&lt;br /&gt;
RLM contains code which allows it to handle LoROM and ExHiROM SNES ROMs in the SMC format. The main decryption loop, decryptLunar(), is a very simplified Super Mario World stage data parser. Most data blocks in this stage format are 3 bytes, but some are 4 or 5 bytes. RLM has to understand this concept (at the very least) in order to decrypt the stage data properly; Only the first two bytes of each block are encrypted.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
RLM is available under the terms of the [https://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License]. You can download the zip/gz/bz2 compressed source code from [https://github.com/parasyte/rlm github] or if you have git, clone the source code repository with the following command:&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/parasyte/rlm.git&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
 $ ./rlm&lt;br /&gt;
 RLM (Recover Lunar Magic) - v1.3&lt;br /&gt;
 Copyright 2003-2009 Parasyte (parasyte@kodewerx.org)&lt;br /&gt;
 http://www.kodewerx.org/&lt;br /&gt;
 &lt;br /&gt;
 Usage: ./rlm &amp;lt;in-file.smc&amp;gt; [out-file.smc]&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;in-file.smc&amp;gt; is the name of the protected Super Mario World ROM, and [out-file.smc] is the file name that you want RLM to create with the unprotected data. Note that [out-file.smc] is optional; if not specified, it will create a new file with the extension of the input file name changed to &amp;quot;.unlocked.smc&amp;quot;. For example, &amp;quot;in-file.smc&amp;quot; becomes &amp;quot;in-file.unlocked.smc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Snesrc&amp;diff=2044</id>
		<title>Snesrc</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Snesrc&amp;diff=2044"/>
				<updated>2020-12-28T06:22:10Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;quot;SNESRC&amp;quot; is an acronym meaning Super Nintendo Entertainment System Re-Compiler. When referring to the program, it is spelled with lowercase letters: snesrc.&lt;br /&gt;
&lt;br /&gt;
Snesrc was an experiment intended to reproduce the complete assembler source code for SNES games. Its main algorithm is a recursive half-emulation of the 65c816 CPU. The theory is that doing this, it can trace all possible program paths to create a &amp;quot;map&amp;quot; of the ROM file which can disassemble the file with proper code/data separation.&lt;br /&gt;
&lt;br /&gt;
==Downloads==&lt;br /&gt;
&lt;br /&gt;
Snesrc is released under the terms of the [https://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License 2.0]. The source code can be downloaded from [https://github.com/parasyte/snesrc github]. You can download the source with git using the following clone command:&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/parasyte/snesrc.git&lt;br /&gt;
&lt;br /&gt;
==The Map==&lt;br /&gt;
&lt;br /&gt;
The map contains information about whether a byte is part of an instruction; is read as data by another instruction; is the destination of a branch, jump or pointer; or was fixed or not marked 'clean'. The map also contains some information about the state of the CPU when that instruction was encountered.&lt;br /&gt;
&lt;br /&gt;
==The Algorithm==&lt;br /&gt;
&lt;br /&gt;
Because of the recursive nature of the algorithm, it will never trace over a byte twice. This aspect also gives it some severe design flaws. The biggest one being that the CPU status attempts to evolve throughout the recursive tree. A branch- or jump-instruction creates a new branch (fork) within the recursive tree; when that branch ends, the algorithm backs out to the last fork and continues running.&lt;br /&gt;
&lt;br /&gt;
The three conditions which can end a branch are: interrupt returns, hitting an instruction which was already traced, or hitting an instruction which appears to be invalid. In the latter case, the algorithm attempts to make an adjustment to the CPU state and re-run over the last branch of instructions (which are still marked 'dirty'). If the branch then ends on one of the other two conditions, the map is marked 'clean' (all dirty bits are removed) and the algorithm continues from the last fork.&lt;br /&gt;
&lt;br /&gt;
==Problem Areas==&lt;br /&gt;
&lt;br /&gt;
The biggest concern with the 65c816 is that its instruction sizes can change dynamically as the program runs (similar to the ARM line of CPUs). This makes it difficult to disassemble the program; let alone to separate code from data. Therefore, it is possible for a string of instructions to be interpreted differently depending on the CPU state when the string is executed. The CPU can have four possible states which can change instruction sizes. These states depend upon the three CPU status bits which change the size of the accumulator and index registers: ''I'', ''M'', and ''E'':&lt;br /&gt;
&lt;br /&gt;
* When ''I'' is set, the index registers X and Y are 8-bit. When clear, X and Y are 16-bit.&lt;br /&gt;
* When ''M'' is set, the accumulator register is 8-bit. When clear, the accumulator is 16-bit.&lt;br /&gt;
* When ''E'' is set, both the index registers X and Y, and accumulator register are 8-bit. When clear, X, Y and accumulator sizes depend on the states of ''I'' and ''M'', respectively.&lt;br /&gt;
&lt;br /&gt;
Another common problem area encountered is with jump tables: seen with JMP ($xxxx,X) and JSR ($xxxx,X) instructions, where $xxxx is often a ROM address listing several pointers. Some of these tables can be found and recursed into by snesrc, but not in all cases.&lt;br /&gt;
&lt;br /&gt;
When $xxxx is a RAM address, we have no idea what it's trying to jump to; this is also a problem for JMP (indirect) and JMP [indirect long] instructions. (See [[#Known Bugs|Known Bugs]].) This is common when a function pointer is sent to a subroutine as an argument, or when a pointer needs to be modified in some way. These corner cases are difficult to anticipate and handle correctly. Especially with this particular algorithm.&lt;br /&gt;
&lt;br /&gt;
The recursion itself is problematic; RTS/RTL instructions do not back out to the last fork, but instead try to pull the return address off the stack. This leaves the CPU state as it was when it left the subroutine (technically correct). But we still run into strange cases where the emulator will throw a warning or an error (usually an invalid instruction). This seems to be caused by incorrectly following the program path, but expecting the CPU status to be correct in all cases.&lt;br /&gt;
&lt;br /&gt;
===Known Bugs===&lt;br /&gt;
&lt;br /&gt;
* JMP (indirect) and JMP [indirect long] instructions are not supported.&lt;br /&gt;
* The ''-fcop'', ''-fstp'', and ''-fwdm'' command line arguments are ignored.&lt;br /&gt;
* Needs a command line argument to force the header size (to 0 or 512).&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
 $ ./snesrc&lt;br /&gt;
 snesrc - The SNES Recompiler v0.01&lt;br /&gt;
 Copyright 2005 Parasyte&lt;br /&gt;
 &lt;br /&gt;
 Usage:&lt;br /&gt;
 snesrc [options] &amp;lt;input file&amp;gt; &amp;lt;output dir&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 Options:&lt;br /&gt;
         -l:           Force LoROM&lt;br /&gt;
         -h:           Force HiROM&lt;br /&gt;
         -r&amp;lt;n&amp;gt;:        Set pointer table range check size&lt;br /&gt;
         -fbrk:        Attempt to fix code which reaches a BRK instruction&lt;br /&gt;
         -fcop:        Attempt to fix code which reaches a COP instruction&lt;br /&gt;
         -fstp:        Attempt to fix code which reaches a STP instruction&lt;br /&gt;
         -fwdm:        Attempt to fix code which reaches a WDM instruction&lt;br /&gt;
&lt;br /&gt;
I used the [https://www.pouet.net/prod.php?which=15713 2.68 MHz Demo by Abandon] for most of the testing. It's not possible to force the header size, so you will want to chop off the first 512 bytes of the .smc file using a hex editor. (This 512 bytes is the SMC header; it's mostly null bytes). This ROM file is also not padded correctly, so you must force snesrc to read the ROM with the LoROM algorithm, using the -l command line argument.&lt;br /&gt;
&lt;br /&gt;
 $ ./snesrc -l -fbrk 2mhz.smc 2mhz&lt;br /&gt;
&lt;br /&gt;
This will create a new subdirectory called 2mhz/ where you will find the disassembled bank files (bankXX.asm) and the disassembler pass logs: pass1.log, pass3.log. Since Pass 2 is specific to flushing map bytes, it does not currently log anything.&lt;br /&gt;
&lt;br /&gt;
==Case Study==&lt;br /&gt;
&lt;br /&gt;
This experiment shows some promise that it is possible to reproduce valid (although not always complete) assembler source code out of simple SNES ROMs. In my tests, I've seen the most success with small &amp;quot;public domain&amp;quot; SNES ROMs. (Technically, these are homebrew ROMs, and are subject to the author's copyright as applicable.)&lt;br /&gt;
&lt;br /&gt;
It would be better to replace the recursive tree with a [https://en.wikipedia.org/wiki/FIFO FIFO] system. Thus, any time a conditional branch or subroutine call is found, the destination address and CPU status are placed on top of the FIFO. Pull that information out of the FIFO for each run until the FIFO is empty. This would make tracing much easier to debug than a maze-like recursion tree. It should also be much closer to the path taken by an assembler as it was creating the ROM.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Syndrome&amp;diff=2043</id>
		<title>Syndrome</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Syndrome&amp;diff=2043"/>
				<updated>2020-12-28T06:18:51Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Syndrome is a level editor for the Mega Man 7 SNES game. Syndrome has undergone 2 complete rewrites since the project began (three iterations in all). The most recent rewrite makes it platform independent, with main development taking place mostly on Mac OS X.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
&lt;br /&gt;
Work on Syndrome began on September 25, 2002 as a Visual Studio 6 MFC project. The screenshots below depict two different builds of the interface. On the left, an older version showing the first time a complete screen was rendered. On the right, a newer version with some tile issues fixed (also with transparency rendered in pink) and an empty sidebar added (once planned to become a toolbox):&lt;br /&gt;
&lt;br /&gt;
[[Image:Syndrome.png]] [[Image:Syndrome2.png]]&lt;br /&gt;
&lt;br /&gt;
On May 23, 2004, I decided to drop MFC (and C++, for that matter) and entirely rewrote the program in C for MinGW. This iteration saw a completely new interface, using an [https://en.wikipedia.org/wiki/Multiple_document_interface MDI] layout and resizable windows. A console window was also included which would output debug information:&lt;br /&gt;
&lt;br /&gt;
[[Image:Syn1.png|800px]] [[Image:Syn2.png|800px]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Syn3.png]] [[Image:Syn4.png]]&lt;br /&gt;
&lt;br /&gt;
On February 8, 2009, over 6 years after the project started, I decided to drop the Win32 dependencies completely. This second rewrite (or third iteration) is currently in progress, written in JavaScript for XULRunner. The plan is to eventually include C++ modules for efficiency reasons.&lt;br /&gt;
&lt;br /&gt;
On December 21, 2020, after an extra decade of dormancy, the project was barely resurrected from extinction since Bitbucket decided to hard-deprecate and delete all Mercurial repos. I was able to find a copy on the [https://web.archive.org/web/20141120183658/https://bitbucket.org/parasyte/syndrome Internet Wayback Machine] and created a new repo on github.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
Syndrome source code is available on github: [https://github.com/parasyte/syndrome]. You can also clone the git repository with the following command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone https://github.com/parasyte/syndrome.git&lt;br /&gt;
&lt;br /&gt;
==Building==&lt;br /&gt;
&lt;br /&gt;
The current source tree is a minimal implementation of a XULRunner application; the XUL, CSS, and JS sources are available in the /src subdirectory, and two shell scripts are included for launching the application. Note that XULRunner has been retired by Mozilla. Some modern replacement technologies are [https://nwjs.io/ NW.js] and [https://github.com/electron/electron Electron]. A light weight alternative is [https://github.com/webview/webview webview].&lt;br /&gt;
&lt;br /&gt;
The linux shell script requires XULRunner to be installed and available in your PATH. If you are on a recent version of Ubuntu, you already have everything needed to try it out:&lt;br /&gt;
&lt;br /&gt;
 $ ./syndrome-linux&lt;br /&gt;
&lt;br /&gt;
The Mac OS X shell script will build an application bundle and place it into a new /Applications/Kodewerx directory. Then it will run the application. To use this, you must download a recent copy of the [https://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ XULRunner runtime]. At this time, the most current release is version 1.9.2.10:&lt;br /&gt;
&lt;br /&gt;
 $ ./syndrome-osx&lt;br /&gt;
&lt;br /&gt;
For Windows, just double click the &amp;quot;syndrome-win&amp;quot; shortcut. You must have Firefox 3.0 (or newer) installed in the default location (C:\Program Files\Mozilla Firefox) for the shortcut to work. If you have Firefox installed to a different location, you can change the shortcut to point to the firefox.exe file by right clicking the shortcut and choosing &amp;quot;Properties&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
XULRunner 1.9.1 adds some much needed functionality such as better support for the HTML Canvas element and much faster JavaScript execution time. Version 1.9.2 is also in the works which adds even more interesting features, such as scaling canvases (and images) with the nearest neighbor algorithm to prevent ugly blurring artifacts; perfect for low resolution pixel art. This can be done with the CSS [https://developer.mozilla.org/En/CSS/Image-rendering image-rendering: -moz-crisp-edges;], or the [https://developer.mozilla.org/en/Canvas_tutorial/Using_images#Controlling_image_scaling_behavior mozImageSmoothingEnabled] property on canvases.&lt;br /&gt;
&lt;br /&gt;
We need a proper build environment using configure/make on Linux and Mac OS X, and a Visual Studio project for Windows. [https://www.cmake.org/ CMake] might be a good choice. Though recently, I am really liking [https://www.scons.org/ SCons].&lt;br /&gt;
&lt;br /&gt;
==Syndrome==&lt;br /&gt;
&lt;br /&gt;
===The Name===&lt;br /&gt;
&lt;br /&gt;
I am often asked why the editor is called Syndrome; the name isn't typical of ROM hacking tools. The word 'syndrome' itself does not directly relate to Mega Man 7 or the Mega Man series in any way. The main reason for this is just to be different! But that doesn't explain where the name came from.&lt;br /&gt;
&lt;br /&gt;
I'm not a big fan of the Mega Man series, to be entirely honest. (Writing an editor for this game was a suggestion that I took one day when bored and feeling an intense urge to build an editor.) I'm not familiar with many of the characters in the series, even; however, I knew that there was a character ... somewhere ... named Sigma. Sigma is a nice name. Almost as fancy as Epsilon. But that's another story.&lt;br /&gt;
&lt;br /&gt;
The words 'sigma' and 'syndrome' (in my head, at least) have a very synesthetic feeling about them. Such that when I hear 'sigma' in my head, I also heard 'syndrome'. And that's the ultimately boring story about how the project came to be known as Syndrome!&lt;br /&gt;
&lt;br /&gt;
===The Reasoning Behind XULRunner===&lt;br /&gt;
&lt;br /&gt;
XULRunner is a nice platform; especially for people who are already familiar with doing web application programming. It's easy for web developers to pick up a XULRunner app and modify it to fit their needs. However, it's not very easy for a web developer to start a XULRunner application from scratch -- that's what XULRunner developers are for.&lt;br /&gt;
&lt;br /&gt;
Briefly, I chose XULRunner as my cross platform framework because I wanted to avoid A) non-native looking widgets (rules out GTK+) and B) C++ (rules out wxWidgets and a whole lot of other similar toolkits). On top of that, I realized the potential of the XULRunner platform in Firefox (extensions, themes, internationalization, accessibility, ...) and I feel that Syndrome can benefit from these technologies.&lt;br /&gt;
&lt;br /&gt;
Back to web developers; Most people who can write an application can also write a web page, but not vice-versa. One of the things missing from the ROM hacking communities is a firm grasp on open source software. Granted, it has been getting better in recent years. One thing I would like to accomplish with Syndrome is creating an open ROM hacking editor framework; something which contains general utilities useful to ROM hacking editors. (In other words ... a really simple place to start when someone wants to make their own editor. And if they know HTML and some JavaScript, they can probably get going in the right direction with Syndrome.)&lt;br /&gt;
&lt;br /&gt;
===Mega Man 7 Information===&lt;br /&gt;
&lt;br /&gt;
Syndrome is hard-coded to read data out of the US Mega Man 7 ROM. Other regions probably will not work. The first thing it does after opening the ROM file is detecting the ROM mapping mode. (This is part of the 'general utilities' described above!) Mega Man 7 is strictly a HiROM-mapped SNES ROM; but Syndrome does not care. It will detect the mapping mode anyway. This makes the ROM reading class general purpose. (This class also handles SMC format ROMs with or without the SMC header -- another win for modularity.)&lt;br /&gt;
&lt;br /&gt;
The next thing Syndrome does is read the ROM title from the header, but in its current state it will not verify this information (currently used for debugging only).&lt;br /&gt;
&lt;br /&gt;
Finally, it begins to &amp;quot;build&amp;quot; the first stage. This is a convoluted process (due to compression) which ends up with a very large HTML canvas (4864 x 1536 px) and a very basic SNES video mode buffer. The video mode buffer is a collection of: tiles, palettes, tile maps. These buffers are the same format as used by SNES.&lt;br /&gt;
&lt;br /&gt;
The next logical step is drawing pixels to the canvas using the tile maps, tiles, and palettes. Unfortunately, trying to do that in JavaScript alone was far too slow in my tests. I'm trying to learn the XULRunner XPCOM system well enough to write the rendering code in C++.&lt;br /&gt;
&lt;br /&gt;
====Compression====&lt;br /&gt;
&lt;br /&gt;
The compression algorithm used on tiles is an [https://en.wikipedia.org/wiki/Lempel-Ziv-Storer-Szymanski LZSS] derivative. It may also be used on other kinds of data.&lt;br /&gt;
&lt;br /&gt;
Another intermediate form of compression used is often referred to as &amp;quot;Tile Squaroid Assembler&amp;quot; (&amp;quot;TSA&amp;quot;) in the ROM hacking community. I dislike this name (in part because &amp;quot;Squaroid&amp;quot; is not a word in the English language) but do not have a better one to suggest. The method resembles a &amp;quot;[https://en.wikipedia.org/wiki/Dictionary_coder Dictionary Table Encoded]&amp;quot; (&amp;quot;DTE&amp;quot;) array; a very simple form of [https://en.wikipedia.org/wiki/Hash_tables Hash Table].&lt;br /&gt;
&lt;br /&gt;
The idea behind the DTE/hash table is to represent several bytes (a &amp;quot;block&amp;quot;) of information as a smaller block (typically only a single byte) of information. As an example, it is easy to represent a 2x2 square of tiles in only one byte; the byte used can therefore reference a total of 256 different 2x2 block combinations. The combinations available are first compiled into a big list called a dictionary. To decode a byte ''n'' into the resulting 2x2 square of tiles, you simply have to look up the ''n''th entry in the dictionary.&lt;br /&gt;
&lt;br /&gt;
Given each tile in the background layer tile map consumes 2 bytes, a stage the size of the MM7 intro level (4864 x 768 px for just the foreground) would require a tile map that's 116,736 bytes long. (Nearly 5% of the full ROM! And this is probably the smallest stage in the game.) That does not even include the tiles or palettes.&lt;br /&gt;
&lt;br /&gt;
One way to &amp;quot;compress&amp;quot; a stage this size into something more reasonable is by breaking everything into smaller 'chunks' and indexing the crap out of it. To illustrate, we can start at the 'stage' level; a stage of 4864 x 768 px can be broken into chunks of 256 x 256 px 'rooms', giving a total map size of 19 x 3 'rooms' (that's 57 bytes!)&lt;br /&gt;
&lt;br /&gt;
Now break each 'room' into 8 x 8 'structures', giving a total of 64 bytes per 'room'.&lt;br /&gt;
&lt;br /&gt;
Break each 'structure' into 2 x 2 'blocks', giving a total of 8 bytes per 'structure'.&lt;br /&gt;
&lt;br /&gt;
Break each 'block' into 2 x 2 tiles, giving a total of 8 bytes per 'block'.&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
You might imagine how this 'chunkifying' saves a whole lot of space, because it reduces redundancy (the main method of data compression, after all). With a stage like the intro (57 total rooms in the map) you might only use a maximum of 15 different kinds of rooms. And the same goes for creating rooms, structures, and blocks.&lt;br /&gt;
&lt;br /&gt;
===The Editor Interface===&lt;br /&gt;
&lt;br /&gt;
This is an area that I've spent a good deal of time exploring. Over 6 years worth of exploration, in fact. I think the best interface for this kind of game (considering the compression used, as explained above) will be to edit only one piece of the overall 'stage' at a time. For instance, the editor will start up in map edit mode on stage 0 (intro). In the map edit mode, the main canvas will display the complete stage. A toolbox will allow the user to select what kind of tool to use (in this example, a 'stamp' tool, to make changes). And below the toolbox, a palette for selecting one of the available 'rooms': Select an available room from the palette, and with the stamp tool, click on the map to 'stamp' that room into the location where the mouse is hovering.&lt;br /&gt;
&lt;br /&gt;
Now this is fine for moving rooms around the map. But to get finer grained control over your editing, you would want to enter 'room edit mode' by double clicking on one of the rooms displayed in the palette. This will change the main canvas to display the room you double clicked, and the palette will change to display all available structures which can be placed into that room.&lt;br /&gt;
&lt;br /&gt;
Double clicking a structure will then go one level deeper into structure edit mode; structure in the main canvas, and all available blocks in the palette.&lt;br /&gt;
&lt;br /&gt;
And again, enter block edit mode by double clicking, and finally, tile edit mode by double clicking a tile in the block edit mode's palette. (The tile editing mode has a palette containing ... well, a color palette! Would it also be reasonable to enter a 'palette editing mode' by double clicking one of the available colors?)&lt;br /&gt;
&lt;br /&gt;
This represents an overall of 5-6 nesting levels (map, room, structure, block, tile, ?palette?). To make this easy to use, 'back and forward' buttons should be made available. Links to all higher levels should also be available, similar to the GTK+ file picker window.&lt;br /&gt;
&lt;br /&gt;
==TODO==&lt;br /&gt;
&lt;br /&gt;
Wiki Article:&lt;br /&gt;
* Mockup screenshots to help illustrate conceptual ideas such as the nested-style user interface. Use [https://balsamiq.com/wireframes/ Balsamiq Wireframes] to create the mockups.&lt;br /&gt;
&lt;br /&gt;
Syndrome:&lt;br /&gt;
* Write the rendering module in C as a dynamic library; call exported functions with [https://developer.mozilla.org/en/js-ctypes js-ctypes].&lt;br /&gt;
* Extend the GetDataX() functions: maybe GetDataPtrX() ? or functions to get arrays...&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Kwiki&amp;diff=2042</id>
		<title>Kwiki</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Kwiki&amp;diff=2042"/>
				<updated>2020-12-28T05:53:01Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Welcome to the Kodewerx wiki. While browsing its contents, remember that ''you'' can make changes to anything you see here. It might be as simple as bad spelling or grammar, or it could be an entirely new page that you create; it's up to you to help the Kodewerx wiki grow into a valuable resource for hackers and programmers alike.&lt;br /&gt;
&lt;br /&gt;
To get you started, here's what we have going on right now:&lt;br /&gt;
&lt;br /&gt;
==Kodewerx Projects==&lt;br /&gt;
&lt;br /&gt;
The main page for &amp;quot;Kodewerx Projects&amp;quot; can be found at the [[:Category:Developer Documentation|Developer Documentation]] page. Most of these projects are immature, and not yet usable for ordinary users. (We need your help!) Source code is available at https://github.com/parasyte, https://github.com/blipjoy, and https://github.com/rust-console/cargo-n64&lt;br /&gt;
&lt;br /&gt;
-[[User:Parasyte|Parasyte]] 06:57, 21 October 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Debugging_Modern_Computer_Architectures&amp;diff=2041</id>
		<title>Debugging Modern Computer Architectures</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Debugging_Modern_Computer_Architectures&amp;diff=2041"/>
				<updated>2020-12-28T05:51:37Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: Fix link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;How does one solve the problems with current debuggers? First, by identifying those problems. Next by addressing them. Finally, in implementation.&lt;br /&gt;
&lt;br /&gt;
==Problems with integrated debuggers==&lt;br /&gt;
&lt;br /&gt;
So what are the problems with debuggers integrated in today's emulators? Well, for one thing, they are integrated. This can cause portability problems, in many cases (I am ashamed to admit my guilt in perpetuating this problem, by writing debuggers that vendor lock users to the Windows operating system). It can also cause undue stress for debugger developers. We are a lazy species, and we do not like rewriting the same debugger multiple times, attempting to port our work to a newer, better emulator, or porting it to a completely new emulated architecture. And then there is the problem of features, or lack thereof. Some hackers and homebrewers need specialized features in their debuggers.&lt;br /&gt;
&lt;br /&gt;
==Solutions==&lt;br /&gt;
&lt;br /&gt;
===Modularity===&lt;br /&gt;
&lt;br /&gt;
Modularity is one possible solution to these problems.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is segregate the low-level debug primitives (functions and whatnot) from the user interface; make the interface modular, interchangeable with any interface. Then you define how the debug primitives interact with the interface via a communications link; make the communications link modular, able to establish communication using any number of interchangeable modules for TCP/IP sockets, operating system pipes, RS232, USB, etc. Next, you define the protocol; make the protocol modular, a 'universal language' that describes generic debug primitives, and allow it to be extensible as necessary. Finally, you define those debug primitives and provide a base implementation that can be expanded if required. However, a well-defined set of primitives is unlikely to need expansion for anything but the most exotic architecture configurations.&lt;br /&gt;
&lt;br /&gt;
===Standardization===&lt;br /&gt;
&lt;br /&gt;
What does all of this mean? Where does it leave us, the debugger developers? And where does it place the users, the hackers, and the homebrew developers?&lt;br /&gt;
&lt;br /&gt;
It means that the debugger developers can implement an accepted standard (accepted being the keyword) for debugger support within not only emulators, but any kind of virtual machine or interpreted byte code in any kind of program. It could be a simple set of debug primitives (in a static or linked library, for example) added by an emulator author (or emulator extender) that connects to a debugger interface of the user's choice. The interface might be highly specialized for a particular architecture, or it might be very complex and advanced with universal support for many architectures.&lt;br /&gt;
&lt;br /&gt;
This would put a large number of options into the hands of users.&lt;br /&gt;
&lt;br /&gt;
===The protocol===&lt;br /&gt;
 &lt;br /&gt;
Now let me try to get a more solid description of this idea out there. The number one underlying technology to be assessed to make any of this work is simply the protocol. That means, a formal description of how a target (an emulator, or other program wishing to use debugger functionality) talks to an interface (a separate program designed to give the user direct access to the debug primitives and link them together in ways that provide many very advanced features ... such as stepping backwards in architecture-time).&lt;br /&gt;
&lt;br /&gt;
This would probably be a command reference which supplies things like:&lt;br /&gt;
&lt;br /&gt;
# A description of the architecture (the emulated system, like NES). This description would include the number of CPUs available, the type of the CPUs, endianness, memory maps as accessible by the CPU, memory maps not accessible to the CPU, etc. Basically a complete virtual model of the architecture.&lt;br /&gt;
# Debug primitives: breakpoints and stepping functionality; read/write access to the memory maps, cpu registers and statuses, and access to internal hardware registers; interrupt and exception handling; scripted macros with callback functions; essentially all of the basic functions which the interface can use to procedurally create high-level features.&lt;br /&gt;
# Extensibility; able to provide expansions to architecture descriptions, debug primitives, and other specialty features.&lt;br /&gt;
&lt;br /&gt;
With such a protocol in place, the interface can do the rest of the high-level work; disassembling, video memory viewing and modification, hex editing, cheat searching and management, etc.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
There is currently an ongoing effort to research the possibilities defined in this article. You can read more about the current progress of this project, along with related details, on the [[Universal Debugger Project]] page.&lt;br /&gt;
&lt;br /&gt;
==Closing statements==&lt;br /&gt;
&lt;br /&gt;
I'm hoping this has been verbose enough that you all understand where I am coming from, but not too verbose that I've created confusion or completely went the wrong direction in the discussion.&lt;br /&gt;
&lt;br /&gt;
Bottom line is, I think we only need to agree on one thing: the protocol. If you refuse to believe that, and only want to do your own thing with your own emulator, that's quite alright. But if you want to reap the benefits of interchangeable debugger interfaces [pick your favorite, or just choose the right one for the job at hand] that are platform-independent [can run on any host operating system, even a completely different machine from the target emulator; not at all bound to the target emulator] and potentially architecture-independent [capable of debugging NES, Genesis, PS2, Wii, Java, brainf**k, the custom scripting language in your new game, you name it!] then I say let's work some crazy Voodoo and invent ourselves a standard for modern debugging!&lt;br /&gt;
&lt;br /&gt;
That said, [https://tools.ietf.org/html/rfc909 RFC-909, Loader Debugger Protocol] looks like a good place to start.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Snesrc&amp;diff=2040</id>
		<title>Snesrc</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Snesrc&amp;diff=2040"/>
				<updated>2020-12-28T05:47:54Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: HTTPS&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;quot;SNESRC&amp;quot; is an acronym meaning Super Nintendo Entertainment System Re-Compiler. When referring to the program, it is spelled with lowercase letters: snesrc.&lt;br /&gt;
&lt;br /&gt;
Snesrc was an experiment intended to reproduce the complete assembler source code for SNES games. Its main algorithm is a recursive half-emulation of the 65c816 CPU. The theory is that doing this, it can trace all possible program paths to create a &amp;quot;map&amp;quot; of the ROM file which can disassemble the file with proper code/data separation.&lt;br /&gt;
&lt;br /&gt;
==Downloads==&lt;br /&gt;
&lt;br /&gt;
Snesrc is released under the terms of the [https://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License 2.0]. The source code can be downloaded from [https://github.com/parasyte/snesrc github]. You can download the source with git using the following clone command:&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/parasyte/snesrc&lt;br /&gt;
&lt;br /&gt;
==The Map==&lt;br /&gt;
&lt;br /&gt;
The map contains information about whether a byte is part of an instruction; is read as data by another instruction; is the destination of a branch, jump or pointer; or was fixed or not marked 'clean'. The map also contains some information about the state of the CPU when that instruction was encountered.&lt;br /&gt;
&lt;br /&gt;
==The Algorithm==&lt;br /&gt;
&lt;br /&gt;
Because of the recursive nature of the algorithm, it will never trace over a byte twice. This aspect also gives it some severe design flaws. The biggest one being that the CPU status attempts to evolve throughout the recursive tree. A branch- or jump-instruction creates a new branch (fork) within the recursive tree; when that branch ends, the algorithm backs out to the last fork and continues running.&lt;br /&gt;
&lt;br /&gt;
The three conditions which can end a branch are: interrupt returns, hitting an instruction which was already traced, or hitting an instruction which appears to be invalid. In the latter case, the algorithm attempts to make an adjustment to the CPU state and re-run over the last branch of instructions (which are still marked 'dirty'). If the branch then ends on one of the other two conditions, the map is marked 'clean' (all dirty bits are removed) and the algorithm continues from the last fork.&lt;br /&gt;
&lt;br /&gt;
==Problem Areas==&lt;br /&gt;
&lt;br /&gt;
The biggest concern with the 65c816 is that its instruction sizes can change dynamically as the program runs (similar to the ARM line of CPUs). This makes it difficult to disassemble the program; let alone to separate code from data. Therefore, it is possible for a string of instructions to be interpreted differently depending on the CPU state when the string is executed. The CPU can have four possible states which can change instruction sizes. These states depend upon the three CPU status bits which change the size of the accumulator and index registers: ''I'', ''M'', and ''E'':&lt;br /&gt;
&lt;br /&gt;
* When ''I'' is set, the index registers X and Y are 8-bit. When clear, X and Y are 16-bit.&lt;br /&gt;
* When ''M'' is set, the accumulator register is 8-bit. When clear, the accumulator is 16-bit.&lt;br /&gt;
* When ''E'' is set, both the index registers X and Y, and accumulator register are 8-bit. When clear, X, Y and accumulator sizes depend on the states of ''I'' and ''M'', respectively.&lt;br /&gt;
&lt;br /&gt;
Another common problem area encountered is with jump tables: seen with JMP ($xxxx,X) and JSR ($xxxx,X) instructions, where $xxxx is often a ROM address listing several pointers. Some of these tables can be found and recursed into by snesrc, but not in all cases.&lt;br /&gt;
&lt;br /&gt;
When $xxxx is a RAM address, we have no idea what it's trying to jump to; this is also a problem for JMP (indirect) and JMP [indirect long] instructions. (See [[#Known Bugs|Known Bugs]].) This is common when a function pointer is sent to a subroutine as an argument, or when a pointer needs to be modified in some way. These corner cases are difficult to anticipate and handle correctly. Especially with this particular algorithm.&lt;br /&gt;
&lt;br /&gt;
The recursion itself is problematic; RTS/RTL instructions do not back out to the last fork, but instead try to pull the return address off the stack. This leaves the CPU state as it was when it left the subroutine (technically correct). But we still run into strange cases where the emulator will throw a warning or an error (usually an invalid instruction). This seems to be caused by incorrectly following the program path, but expecting the CPU status to be correct in all cases.&lt;br /&gt;
&lt;br /&gt;
===Known Bugs===&lt;br /&gt;
&lt;br /&gt;
* JMP (indirect) and JMP [indirect long] instructions are not supported.&lt;br /&gt;
* The ''-fcop'', ''-fstp'', and ''-fwdm'' command line arguments are ignored.&lt;br /&gt;
* Needs a command line argument to force the header size (to 0 or 512).&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
 $ ./snesrc&lt;br /&gt;
 snesrc - The SNES Recompiler v0.01&lt;br /&gt;
 Copyright 2005 Parasyte&lt;br /&gt;
 &lt;br /&gt;
 Usage:&lt;br /&gt;
 snesrc [options] &amp;lt;input file&amp;gt; &amp;lt;output dir&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 Options:&lt;br /&gt;
         -l:           Force LoROM&lt;br /&gt;
         -h:           Force HiROM&lt;br /&gt;
         -r&amp;lt;n&amp;gt;:        Set pointer table range check size&lt;br /&gt;
         -fbrk:        Attempt to fix code which reaches a BRK instruction&lt;br /&gt;
         -fcop:        Attempt to fix code which reaches a COP instruction&lt;br /&gt;
         -fstp:        Attempt to fix code which reaches a STP instruction&lt;br /&gt;
         -fwdm:        Attempt to fix code which reaches a WDM instruction&lt;br /&gt;
&lt;br /&gt;
I used the [https://www.pouet.net/prod.php?which=15713 2.68 MHz Demo by Abandon] for most of the testing. It's not possible to force the header size, so you will want to chop off the first 512 bytes of the .smc file using a hex editor. (This 512 bytes is the SMC header; it's mostly null bytes). This ROM file is also not padded correctly, so you must force snesrc to read the ROM with the LoROM algorithm, using the -l command line argument.&lt;br /&gt;
&lt;br /&gt;
 $ ./snesrc -l -fbrk 2mhz.smc 2mhz&lt;br /&gt;
&lt;br /&gt;
This will create a new subdirectory called 2mhz/ where you will find the disassembled bank files (bankXX.asm) and the disassembler pass logs: pass1.log, pass3.log. Since Pass 2 is specific to flushing map bytes, it does not currently log anything.&lt;br /&gt;
&lt;br /&gt;
==Case Study==&lt;br /&gt;
&lt;br /&gt;
This experiment shows some promise that it is possible to reproduce valid (although not always complete) assembler source code out of simple SNES ROMs. In my tests, I've seen the most success with small &amp;quot;public domain&amp;quot; SNES ROMs. (Technically, these are homebrew ROMs, and are subject to the author's copyright as applicable.)&lt;br /&gt;
&lt;br /&gt;
It would be better to replace the recursive tree with a [https://en.wikipedia.org/wiki/FIFO FIFO] system. Thus, any time a conditional branch or subroutine call is found, the destination address and CPU status are placed on top of the FIFO. Pull that information out of the FIFO for each run until the FIFO is empty. This would make tracing much easier to debug than a maze-like recursion tree. It should also be much closer to the path taken by an assembler as it was creating the ROM.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Snesrc&amp;diff=2039</id>
		<title>Snesrc</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Snesrc&amp;diff=2039"/>
				<updated>2020-12-28T05:46:48Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: Fix links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;quot;SNESRC&amp;quot; is an acronym meaning Super Nintendo Entertainment System Re-Compiler. When referring to the program, it is spelled with lowercase letters: snesrc.&lt;br /&gt;
&lt;br /&gt;
Snesrc was an experiment intended to reproduce the complete assembler source code for SNES games. Its main algorithm is a recursive half-emulation of the 65c816 CPU. The theory is that doing this, it can trace all possible program paths to create a &amp;quot;map&amp;quot; of the ROM file which can disassemble the file with proper code/data separation.&lt;br /&gt;
&lt;br /&gt;
==Downloads==&lt;br /&gt;
&lt;br /&gt;
Snesrc is released under the terms of the [https://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License 2.0]. The source code can be downloaded from [https://github.com/parasyte/snesrc github]. You can download the source with git using the following clone command:&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/parasyte/snesrc&lt;br /&gt;
&lt;br /&gt;
==The Map==&lt;br /&gt;
&lt;br /&gt;
The map contains information about whether a byte is part of an instruction; is read as data by another instruction; is the destination of a branch, jump or pointer; or was fixed or not marked 'clean'. The map also contains some information about the state of the CPU when that instruction was encountered.&lt;br /&gt;
&lt;br /&gt;
==The Algorithm==&lt;br /&gt;
&lt;br /&gt;
Because of the recursive nature of the algorithm, it will never trace over a byte twice. This aspect also gives it some severe design flaws. The biggest one being that the CPU status attempts to evolve throughout the recursive tree. A branch- or jump-instruction creates a new branch (fork) within the recursive tree; when that branch ends, the algorithm backs out to the last fork and continues running.&lt;br /&gt;
&lt;br /&gt;
The three conditions which can end a branch are: interrupt returns, hitting an instruction which was already traced, or hitting an instruction which appears to be invalid. In the latter case, the algorithm attempts to make an adjustment to the CPU state and re-run over the last branch of instructions (which are still marked 'dirty'). If the branch then ends on one of the other two conditions, the map is marked 'clean' (all dirty bits are removed) and the algorithm continues from the last fork.&lt;br /&gt;
&lt;br /&gt;
==Problem Areas==&lt;br /&gt;
&lt;br /&gt;
The biggest concern with the 65c816 is that its instruction sizes can change dynamically as the program runs (similar to the ARM line of CPUs). This makes it difficult to disassemble the program; let alone to separate code from data. Therefore, it is possible for a string of instructions to be interpreted differently depending on the CPU state when the string is executed. The CPU can have four possible states which can change instruction sizes. These states depend upon the three CPU status bits which change the size of the accumulator and index registers: ''I'', ''M'', and ''E'':&lt;br /&gt;
&lt;br /&gt;
* When ''I'' is set, the index registers X and Y are 8-bit. When clear, X and Y are 16-bit.&lt;br /&gt;
* When ''M'' is set, the accumulator register is 8-bit. When clear, the accumulator is 16-bit.&lt;br /&gt;
* When ''E'' is set, both the index registers X and Y, and accumulator register are 8-bit. When clear, X, Y and accumulator sizes depend on the states of ''I'' and ''M'', respectively.&lt;br /&gt;
&lt;br /&gt;
Another common problem area encountered is with jump tables: seen with JMP ($xxxx,X) and JSR ($xxxx,X) instructions, where $xxxx is often a ROM address listing several pointers. Some of these tables can be found and recursed into by snesrc, but not in all cases.&lt;br /&gt;
&lt;br /&gt;
When $xxxx is a RAM address, we have no idea what it's trying to jump to; this is also a problem for JMP (indirect) and JMP [indirect long] instructions. (See [[#Known Bugs|Known Bugs]].) This is common when a function pointer is sent to a subroutine as an argument, or when a pointer needs to be modified in some way. These corner cases are difficult to anticipate and handle correctly. Especially with this particular algorithm.&lt;br /&gt;
&lt;br /&gt;
The recursion itself is problematic; RTS/RTL instructions do not back out to the last fork, but instead try to pull the return address off the stack. This leaves the CPU state as it was when it left the subroutine (technically correct). But we still run into strange cases where the emulator will throw a warning or an error (usually an invalid instruction). This seems to be caused by incorrectly following the program path, but expecting the CPU status to be correct in all cases.&lt;br /&gt;
&lt;br /&gt;
===Known Bugs===&lt;br /&gt;
&lt;br /&gt;
* JMP (indirect) and JMP [indirect long] instructions are not supported.&lt;br /&gt;
* The ''-fcop'', ''-fstp'', and ''-fwdm'' command line arguments are ignored.&lt;br /&gt;
* Needs a command line argument to force the header size (to 0 or 512).&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
 $ ./snesrc&lt;br /&gt;
 snesrc - The SNES Recompiler v0.01&lt;br /&gt;
 Copyright 2005 Parasyte&lt;br /&gt;
 &lt;br /&gt;
 Usage:&lt;br /&gt;
 snesrc [options] &amp;lt;input file&amp;gt; &amp;lt;output dir&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 Options:&lt;br /&gt;
         -l:           Force LoROM&lt;br /&gt;
         -h:           Force HiROM&lt;br /&gt;
         -r&amp;lt;n&amp;gt;:        Set pointer table range check size&lt;br /&gt;
         -fbrk:        Attempt to fix code which reaches a BRK instruction&lt;br /&gt;
         -fcop:        Attempt to fix code which reaches a COP instruction&lt;br /&gt;
         -fstp:        Attempt to fix code which reaches a STP instruction&lt;br /&gt;
         -fwdm:        Attempt to fix code which reaches a WDM instruction&lt;br /&gt;
&lt;br /&gt;
I used the [http://www.pouet.net/prod.php?which=15713 2.68 MHz Demo by Abandon] for most of the testing. It's not possible to force the header size, so you will want to chop off the first 512 bytes of the .smc file using a hex editor. (This 512 bytes is the SMC header; it's mostly null bytes). This ROM file is also not padded correctly, so you must force snesrc to read the ROM with the LoROM algorithm, using the -l command line argument.&lt;br /&gt;
&lt;br /&gt;
 $ ./snesrc -l -fbrk 2mhz.smc 2mhz&lt;br /&gt;
&lt;br /&gt;
This will create a new subdirectory called 2mhz/ where you will find the disassembled bank files (bankXX.asm) and the disassembler pass logs: pass1.log, pass3.log. Since Pass 2 is specific to flushing map bytes, it does not currently log anything.&lt;br /&gt;
&lt;br /&gt;
==Case Study==&lt;br /&gt;
&lt;br /&gt;
This experiment shows some promise that it is possible to reproduce valid (although not always complete) assembler source code out of simple SNES ROMs. In my tests, I've seen the most success with small &amp;quot;public domain&amp;quot; SNES ROMs. (Technically, these are homebrew ROMs, and are subject to the author's copyright as applicable.)&lt;br /&gt;
&lt;br /&gt;
It would be better to replace the recursive tree with a [http://en.wikipedia.org/wiki/FIFO FIFO] system. Thus, any time a conditional branch or subroutine call is found, the destination address and CPU status are placed on top of the FIFO. Pull that information out of the FIFO for each run until the FIFO is empty. This would make tracing much easier to debug than a maze-like recursion tree. It should also be much closer to the path taken by an assembler as it was creating the ROM.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=2038</id>
		<title>Scalable Remote Debugger Protocol</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=2038"/>
				<updated>2020-12-28T05:23:24Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: Update protocol to HTTPS&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently serving as a reference to kick-start development of the universal debugger protocol which will be used by the [[Universal Debugger Project]] and hopefully many, many other debuggers and debugger interfaces in the years to come.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
These references are listed in order of relevance; most relevant first.&lt;br /&gt;
&lt;br /&gt;
# [https://tools.ietf.org/html/rfc909 RFC-909: Loader Debugger Protocol]&lt;br /&gt;
# [https://sourceware.org/gdb/onlinedocs/gdb/Remote-Protocol.html GDB Remote Serial Protocol]&lt;br /&gt;
# [https://tools.ietf.org/html/rfc643 RFC-643: Network Debugging Protocol]&lt;br /&gt;
# [http://networksorcery.com/enp/ien/ien158.txt IEN-158: XNET Debugging Protocol]&lt;br /&gt;
# [https://xdebug.org/docs/dbgp DBGp: A common debugger protocol for languages and debugger UI communication]&lt;br /&gt;
&lt;br /&gt;
The relevancy I've determined for this list is due to interest in these specs, as well as potential generic uses and protocol extension.&lt;br /&gt;
&lt;br /&gt;
RFC-909 is so far the closest thing I have found which resembles the general idea I have for a &amp;quot;Universal Debugger Protocol&amp;quot;. It's composed as a simple binary packet, it's extensible, and it's designed to be stacked on top of existing transport protocols such as TCP/IP. I doubt this exact spec will fit all of our needs, but it is certainly a good start.&lt;br /&gt;
&lt;br /&gt;
GDB provides a fairly popular protocol. This one is designed for serial communications, so it will work well with small embedded devices. But it could be complicated to extend while retaining its GDB friendliness.&lt;br /&gt;
&lt;br /&gt;
RFC-643 and IEN-158 are interesting only because they show that some experimentation on the ideas of remote debugging have been employed in the past. Unfortunately, these specs were designed for a specific architecture, and are of little practical use for our purposes.&lt;br /&gt;
&lt;br /&gt;
DBGp shows what a modern remote debugging protocol can look like; including modern XML syntax. The downside to this is that low-level debuggers in small embedded devices are unlikely to parse XML at all.&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
&lt;br /&gt;
This section represents my ([[User:Parasyte|Parasyte]]) own personal opinions and ideas, and should not be taken as advocacy for standardization.&lt;br /&gt;
&lt;br /&gt;
One of the main goals of developing a &amp;quot;universal&amp;quot; protocol for debugging is that it must be usable everywhere; in small embedded devices, and some of the most powerful machines in the world. This kind of flexibility must be designed around multiple layers of abstraction. See [https://en.wikipedia.org/wiki/OSI_Model OSI Model] and [https://en.wikipedia.org/wiki/Internet_Protocol_Suite Internet Protocol Suite] for examples of abstraction layers used in communications technologies.&lt;br /&gt;
&lt;br /&gt;
At the lowest layer, you find the ''wire''; the physical means of transmitting information over distance. For our purposes, we should not limit ourselves to a single wire. Instead, we should allow the use of multiple wires, user-selectable, but never more than one at a time.&lt;br /&gt;
&lt;br /&gt;
The following layers get more and more generic and abstract, until you reach the highest layer which represents what the application sees and interacts with. This would be the &amp;quot;protocol&amp;quot; itself.&lt;br /&gt;
&lt;br /&gt;
So let's break these components down, hypothetically, and get into some details, ordered lowest layer first:&lt;br /&gt;
&lt;br /&gt;
# '''Physical layer''': Some examples of wires to support include LAN (Ethernet/WiFi), Wireless (Bluetooth), RS-232 (serial port, USB serial port), Inter-Process Communication (Domain Sockets? DBUS?)&lt;br /&gt;
# '''Transport layer''': Some examples of transport protocols include TCP/IP, UDP/IP (LAN, Domain Sockets), UART (RS-232), IPC-specific (DBUS)&lt;br /&gt;
# '''Application layer''': A library (or similar service, E.G. a daemon) to tie all transport layers into a single API that, to the application, looks like one simple interface to connect and send/receive data. The library/daemon will have to handle the transport-specific details behind-the-scenes.&lt;br /&gt;
&lt;br /&gt;
Thinking about this led to a conundrum; If we support multiple wires, we have to support multiple transport protocols which are compatible with those wires. And if we support multiple transport protocols, we have to know which one our target implements. To make the API as simple as possible, we must not force clients to choose from configurable options (for a bad example) that requires a large degree of changes for each different type of connection made. How do we simplify the API so that a user can just plain connect without doing any pre-setup work?&lt;br /&gt;
&lt;br /&gt;
Answer: The [https://en.wikipedia.org/wiki/URI_scheme URI scheme]. The unfortunate downside to this solution is that it is undesired to use URI schemes without registering them with IANA. However, an argument could be made that these schemes would not be used for general network/internet communication. A few popular examples of similarly non-networked schemes are the file: and about: URI schemes. (The exception here is that at least one physical layer (LAN) could be used for over-the-internet communication; but this has great benefits in its own right.)&lt;br /&gt;
&lt;br /&gt;
===Example URI Schemes===&lt;br /&gt;
&lt;br /&gt;
The following table represents some examples of how URI schemes could be used as debugger protocols:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp://192.168.1.20/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | TCP/IP to remote host 192.168.1.20 on a pre-defined default port&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+udp://192.168.1.20:9424/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UDP/IP to remote host 192.168.1.20 on port 9424&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+usb://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | USB (SRDP-compatible devices) on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+uart://localhost:3/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UART COM port 3 on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+dbus://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | DBUS IPC on localhost&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'srdp' prefix on these examples is to specify the 'Scalable Remote Debugger Protocol.' The + and suffix defines an additional layer (or protocol) below SRDP.&lt;br /&gt;
&lt;br /&gt;
The latter three examples look a bit odd with localhost being the destination, but this is necessary, since the localhost ''is'' the destination for hosting the UART RS-232 port, USB port, and IPC interface. Using non-loopback interfaces (IP addresses outside of the local machine) with these protocols should be undefined, unless there is evidence that connecting to RS-232/USB/IPC interfaces on other machines across a network is practical and plausible.&lt;br /&gt;
&lt;br /&gt;
===Simplified Configuration===&lt;br /&gt;
&lt;br /&gt;
These URI schemes give a very simple and elegant solution to the concerns they address. No longer will you be stuck with complicated configuration settings like the example below (upper left group box) ... and this is not an incredibly complex configuration dialog, as it is; instead, connecting to ANY low-level debugger in the world will be as simple as typing a URL.&lt;br /&gt;
&lt;br /&gt;
Example of what '''''not''''' to do:&lt;br /&gt;
&lt;br /&gt;
[[Image:Gscc_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Operation Groups===&lt;br /&gt;
&lt;br /&gt;
The protocol is defined as a set of usable &amp;quot;requests&amp;quot; (AKA &amp;quot;operations&amp;quot; or &amp;quot;commands&amp;quot;) requested by the client to the debugger, or vice-versa. Operations should be grouped according to a specific metric. The metric I've chosen is hardware (architecture) relationships. The table below shows an example of such groups (currently 6 in total) and example operations assigned to each group.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 1)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Diagnostics (Info, Ping/Pong, Reset, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 2)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | CPU handling (Register read/write, Arbitrary code execution, General CPU control, General process/thread control...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 3)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Memory handling (Read, Write, Address conversion, Hardware I/O, Cache control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 4)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Breakpoint handling (Add, Delete, Edit, Get, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 5)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Stream handling (stdin/stdout/stderr, Debugger-specific messages, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 6)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Vendor-specific (Custom command sets; should be discouraged unless absolutely necessary)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Proposal==&lt;br /&gt;
&lt;br /&gt;
This section defines a proposed specification which may be adopted as the &amp;quot;Scalable Remote Debugger Protocol&amp;quot;. It is considered a work in progress and is currently open for peer-review, meaning we are interested in receiving comments, criticisms, and suggestions.&lt;br /&gt;
&lt;br /&gt;
===Protocol Goals===&lt;br /&gt;
&lt;br /&gt;
Goals of the protocol include:&lt;br /&gt;
&lt;br /&gt;
# '''Client/server relationship''': Target (debuggee) acts as a server, quietly listening for any SRDP requests; User Interface acts as a client, making explicit requests to a listening server.&lt;br /&gt;
# '''Asynchronous requests''': A client must send requests without expecting an immediate response. A server accepting requests may not respond immediately to those requests.&lt;br /&gt;
# '''Scalable''': The data structure (format) used in the protocol must be adaptable to the future; The structure must be as forgiving and dynamic as possible, avoiding fixed contents (except where absolutely necessary) and allowing for [non-mission-critical] non-standard contents.&lt;br /&gt;
# '''Easy to implement''': Basic features of the protocol should be easy to implement from an API point-of-view, as well as having a small memory footprint; the protocol must be usable on small embedded machines with few resources.&lt;br /&gt;
# '''Robust''': Ambiguity should be kept to a minimum in all aspects of the protocol; every bit transferred should have a useful meaning.&lt;br /&gt;
# '''Easy to debug''': A debugger protocol that cannot itself be debugged (observed and verified to work as expected) is a failure in and of itself. For this reason, the protocol should be human-readable in its most basic form.&lt;br /&gt;
&lt;br /&gt;
===Underlying Protocols===&lt;br /&gt;
&lt;br /&gt;
There are no reservations on any underlying protocols (protocols used to move data from the client to the server, and back again -- SRDP is not one of these protocols). The only requirement is that they provide hand-shaking (transmission control), sequential ordering of packet data arrival, and data integrity checking. Some examples of suitable underlying protocols include [https://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/UDP/IP], and [https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART].&lt;br /&gt;
&lt;br /&gt;
The initial reference implementation will use TCP/IP for remote connections. For local-listening servers, the reference implementation will use UNIX Domain Sockets on UNIX-like operating systems, and Named Pipes on Windows.&lt;br /&gt;
&lt;br /&gt;
===Requests, Responses, Alerts===&lt;br /&gt;
&lt;br /&gt;
Packets are given different names depending on their transmission direction (client -&amp;gt; server, or server -&amp;gt; client) and intended recipient (server, specific client, or all clients).&lt;br /&gt;
&lt;br /&gt;
Response, requests, and alerts must have a unique identifier associated with them. This will allow clients and servers to stay in sync, knowing which responses are for which requests, for example.&lt;br /&gt;
&lt;br /&gt;
====Requests====&lt;br /&gt;
&lt;br /&gt;
A packet is called a request if it is from a client to the server. The name &amp;quot;request&amp;quot; comes from the idea that the client is requesting information or a specific action to be performed by the server.&lt;br /&gt;
&lt;br /&gt;
====Responses====&lt;br /&gt;
&lt;br /&gt;
Responses are packets from a server to a specific client. Responses are always sent in response to a request (hence the name). However, not all requests are required to send responses (which is why &amp;quot;requests&amp;quot; are not called &amp;quot;commands&amp;quot;). Responses are only sent to the client which initiated the specific request being handled.&lt;br /&gt;
&lt;br /&gt;
====Alerts====&lt;br /&gt;
&lt;br /&gt;
An alert is a special type of response (a packet from the server to clients); an alert is sent to all connected/listening clients. This is synonymous with network &amp;quot;broadcast&amp;quot; packets, and it useful for notifying all clients of information they might like to know.&lt;br /&gt;
&lt;br /&gt;
A few examples of information that all clients might like to know are:&lt;br /&gt;
&lt;br /&gt;
* Breakpoint hits&lt;br /&gt;
* Pausing/resuming execution&lt;br /&gt;
* Resets&lt;br /&gt;
* Debugging messages (log messages)&lt;br /&gt;
&lt;br /&gt;
Not all alerts are initiated by requests from clients, but most will be. Log messages are typically spewed by programs without explicit requests; SRDP can allow listening for and capturing these messages.&lt;br /&gt;
&lt;br /&gt;
====Commands====&lt;br /&gt;
&lt;br /&gt;
The all-encompassing term for requests, responses and alerts is &amp;quot;commands&amp;quot;. Any time a &amp;quot;command&amp;quot; is mentioned, it refers to any combination of requests, responses, or alerts.&lt;br /&gt;
&lt;br /&gt;
===Protocol Packet Data Structure===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;goals&amp;quot; section outlines the major features which formed the following data structure. Inspiration comes mainly from [https://en.wikipedia.org/wiki/JSON JSON], the JavaScript Object Notation. As JSON is a serialization [text format] of JavaScript objects, the SRDP data structure is a serialization of the data being transmitted.&lt;br /&gt;
&lt;br /&gt;
The structure also shares some inspiration from [https://en.wikipedia.org/wiki/Remote_procedure_call RPC]; An example is that your client may want to read work RAM from the target. The SRDP request for &amp;quot;read memory&amp;quot; is technically similar to remotely running a &amp;quot;read memory&amp;quot; function on the server, invoked by the client. For this reason, each SRDP packet contains one or more &amp;quot;arguments&amp;quot; which you could imagine are passed directly to a plain old function.&lt;br /&gt;
&lt;br /&gt;
Each packet is sent as a series of 8-bit bytes. Packets are broken down into a &amp;quot;request/response/alert&amp;quot; name (called a command), encapsulating a series of &amp;quot;arguments&amp;quot;. You can think of it like a C function call. The &amp;quot;info&amp;quot; command, for example, requests information about the target machine architecture; it requires no arguments. The info command looks like this, and is a complete and valid SRDP packet:&lt;br /&gt;
&lt;br /&gt;
  info()&lt;br /&gt;
&lt;br /&gt;
Each argument has a name (made of one or more characters: alpha-numeric, underscore (_), or hyphen (-). The argument name is followed by a colon (:) and then a single byte representing the data type of the argument, then an equals sign (=) and the argument's value. All arguments are separated with a comma (,).&lt;br /&gt;
&lt;br /&gt;
The argument syntax is similar to that of [https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]. In pseudo-form, it looks something like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:{type}={value}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Valid data types:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | {type}&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Name&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | n&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any positive integer, encoded as a [http://www.dlugosz.com/ZIP2/VLI.html VLI]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | s&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Signed Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any negative integer, encoded as a [https://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement one's complement] VLI&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | f&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Floating Point Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any non-integer number, Infinity, or [https://en.wikipedia.org/wiki/NaN NaN], encoded as a null-terminated UTF-8 string, or null-terminated UTF-16 or UTF-32 string with BOM; To be decoded by [https://en.wikipedia.org/wiki/Scanf#Format_string_specifications sscanf]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | a&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob), preceded by a VLI to indicate the length of the array.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | c&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Compressed Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob) with [https://en.wikipedia.org/wiki/Run-length_encoding RLE] compression. See [[#Compressed Array Data Type]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | t&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Text&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Null-terminated UTF-8 string without [https://en.wikipedia.org/wiki/Byte-order_mark BOM], or null-terminated UTF-16 or UTF-32 string with BOM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some example arguments. (Please keep in mind that all of the argument names listed within this section are for demonstration purposes only, and are not recommended for reference purposes.)&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | msg:t=Hello, World!␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | num:n=□&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | pi:f=3.141592␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | ram_dump:a=□■■■■&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | my-compressed-data:c=□□■■■■□■□■■■&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
What the symbols mean:&lt;br /&gt;
&lt;br /&gt;
  ␀: Null-terminator&lt;br /&gt;
  □: VLI&lt;br /&gt;
  ■: Data byte&lt;br /&gt;
&lt;br /&gt;
====Compressed Array Data Type====&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; padding: 10px;&amp;quot; | '''''One suggestion is making this data-type optional, and changing this spec to use a standard library, like zlib. In this way, slow machines with few resources can adhere to the SRDP spec without wasting precious footprint space and computational power implementing such &amp;quot;heavy&amp;quot; libraries.&lt;br /&gt;
&lt;br /&gt;
Using a &amp;quot;heavy-weight&amp;quot; compression library will help achieve better compression ratios, but will add processing overhead. The added overhead may turn out to be an overall hindrance. For example, a memory editor might want to refresh a memory display as fast as possible (several times per second) within a small visible view-port window. This kind of editor will need to download the contents of memory within the visible range quickly. Using compression in a use-case like this is a good idea, but only if transferring the smaller packet can make up for the time required to compress and decompress the data.'''''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Compressed arrays are similar to the standard &amp;quot;Array&amp;quot; data type. The compressed array starts with a single VLI to represent the total data size of the value (e.g. the size of the compressed data, ''x''). The following data is a series of alternating raw data and RLE data.&lt;br /&gt;
&lt;br /&gt;
# '''Raw Data''': A VLI representing raw data size in bytes (''n''), followed by ''n'' bytes of actual data.&lt;br /&gt;
# '''RLE Data''': A VLI representing RLE data size in bytes (''n''), followed by a single byte to be repeated (''n'' + 4) times in the output.&lt;br /&gt;
&lt;br /&gt;
This series is repeated until there are no more bytes to be read from input (''x'' bytes of the argument value have been read).&lt;br /&gt;
&lt;br /&gt;
For the RLE compression to be useful (efficient) it must not be used for any less than 4 bytes (therefore, the VLI is said to be a &amp;quot;4-based&amp;quot; number). The number 4 is derived from the minimum overhead introduced by the serial alternation and VLIs; 1 VLI for RLE output length, 1 byte of RLE data, 1 VLI for raw data length.&lt;br /&gt;
&lt;br /&gt;
Thus, in order for the RLE to perform &amp;quot;compression&amp;quot;, the RLE output must be larger than the smallest sequence required to switch from raw data and back again. Some examples to illustrate, '''''bold-italic''''' bytes are for VLI &amp;quot;control sequences&amp;quot; (the data lengths specified above):&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 1'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 01&lt;br /&gt;
 &lt;br /&gt;
 Incorrectly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''&amp;lt;u&amp;gt;03&amp;lt;/u&amp;gt;''''' 00 '''''01''''' 01&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''08''''' 94 24 51 73 00 00 00 01&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 2'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''00''''' 00&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 3'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 00 00 00 00 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''00''''' '''''04''''' 00&lt;br /&gt;
&lt;br /&gt;
The reason the second line in example 1 above is &amp;quot;incorrectly&amp;quot; compressed is because the second VLI is expecting the length to be 0-based. If this was the case, you would be simply adding overhead to replace any bytes saved by the &amp;quot;compression&amp;quot;. For this reason, the &amp;quot;correct&amp;quot; way to compress the example is to use a single length of raw data. This example is non-compressible, and should not be sent as a compressed array data type.&lt;br /&gt;
&lt;br /&gt;
In the second example, the data can be compressed nicely, saving a byte overall (including compression overhead). Since this is the &amp;quot;correct&amp;quot; way to compress the data, it is using a 4-based VLI on the RLE Data: &amp;quot;'''''00'''''&amp;quot; means 4 bytes of output, &amp;quot;'''''01'''''&amp;quot; means 5 bytes, &amp;quot;'''''02'''''&amp;quot; means 6 bytes, etc.&lt;br /&gt;
&lt;br /&gt;
The third example shows how to compress a series of bytes that starts with repeating data, instead of non-repeating &amp;quot;raw data&amp;quot;. The first VLI of '''''00''''' means there is no raw data for output (this is required: compressed arrays always begin with the Raw Data, followed by RLE Data). The second VLI '''''04''''' is the length of the RLE Data; 8 bytes. Even if the non-compressed data was 4 bytes of &amp;quot;00&amp;quot;, the compressed array would still be only 3 bytes of total data, saving one byte. This helps explain the reasoning behind the 4-based VLI for RLE Data.&lt;br /&gt;
&lt;br /&gt;
====Object Data Type====&lt;br /&gt;
&lt;br /&gt;
The basic structure and data types shown so far are very powerful; your server can tell the client vast amounts of information, such as CPU architecture, memory maps, I/O maps, etc. with just a handful of arguments. However, grouping these arguments in a meaningful way may be difficult. You might be inclined to do some &amp;quot;mock&amp;quot; namespacing, like prefixing each CPU-related argument with &amp;quot;cpu_&amp;quot;. This is effective, but also slightly wasteful and error-prone.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;object&amp;quot; data type is designed to handle such situations. This data type allows an argument to be a container for other arguments. Its format looks like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:[...]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Where the set of ellipses denotes one or more &amp;quot;regular&amp;quot; arguments. Here is an example of what a &amp;quot;cpu&amp;quot; object might look like:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
(Note the white-space is for readability only; it is not meant to be transferred as part of the protocol data.)&lt;br /&gt;
&lt;br /&gt;
In this example, the &amp;quot;cpu&amp;quot; object contains two arguments: cpu.arch and cpu.name; both strings.&lt;br /&gt;
&lt;br /&gt;
But there are also times when you will want your server to send that same information for two [or more] CPU architectures on a single target. Some platforms may have multiple CPUs, each with its own individual set of resources (memory maps and the like), as well as shared resources between the CPUs. For this, the packet data structure needs a more advanced method of communicating these kinds of details.&lt;br /&gt;
&lt;br /&gt;
For this case, you can optionally create arrays of objects by including a comma (,) after the closing square bracket, followed by another series of arguments enclosed in their own square brackets, ''ad infinitum''. In other words, any leading object definitions without explicit names will be treated as additional array elements for the previously named object.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM7TDMI␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now our &amp;quot;cpu&amp;quot; object defines two CPUs: an ARM9 and ARM7, ready for Nintendo DS hacking. These arguments can be referenced as cpu[0].arch, cpu[0].name, cpu[1].arch, and cpu[1].name respectively.&lt;br /&gt;
&lt;br /&gt;
Objects can be arbitrarily complex, containing arrays of other objects. Here is an example of a simple memory map, containing Work RAM (read/write/execute) and ROM (read/execute) sections. The Work RAM section is broken into two distinct memory ranges. This is quite easily expressed:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;memory:[&lt;br /&gt;
:name:t=Work RAM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&amp;lt;br/&amp;gt;&lt;br /&gt;
:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RWX␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:name:t=ROM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RX␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Command Reference===&lt;br /&gt;
&lt;br /&gt;
'''''FIXME: WIP'''''&lt;br /&gt;
&lt;br /&gt;
====Requests====&lt;br /&gt;
&lt;br /&gt;
=====info()=====&lt;br /&gt;
Request information about the target machine architecture. The '''info()''' request is implied during connection: A response will be sent after a connection is successfully established. This allows clients to gather necessary information about the target during the connection phase, without explicitly making the request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Return values'':&lt;br /&gt;
&lt;br /&gt;
Must only return one of the following:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;sys&amp;lt;/u&amp;gt;''' (string):&amp;lt;br/&amp;gt;A shorthand for defining known machines (mostly video game systems).&amp;lt;br/&amp;gt;See below for supported values&lt;br /&gt;
* '''&amp;lt;u&amp;gt;machine&amp;lt;/u&amp;gt;''' (object):&amp;lt;br/&amp;gt;A longhand for defining the complete machine architecture.&amp;lt;br/&amp;gt;TODO: Specify all object elements and their meanings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The currently supported values for '''&amp;lt;u&amp;gt;sys&amp;lt;/u&amp;gt;''' are:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NES&amp;lt;/u&amp;gt;''': Nintendo Entertainment System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SNES&amp;lt;/u&amp;gt;''': Super Nintendo Entertainment System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;N64&amp;lt;/u&amp;gt;''': Nintendo 64&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGC&amp;lt;/u&amp;gt;''': Nintendo GameCube&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS1&amp;lt;/u&amp;gt;''': Sony Playstation&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS2&amp;lt;/u&amp;gt;''': Sony Playstation 2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Planned future support:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GB&amp;lt;/u&amp;gt;''': Nintendo GameBoy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GBC&amp;lt;/u&amp;gt;''': Nintendo GameBoy Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GBA&amp;lt;/u&amp;gt;''': Nintendo GameBoy Advance&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NDS&amp;lt;/u&amp;gt;''': Nintendo DS/DSi&lt;br /&gt;
* '''&amp;lt;u&amp;gt;VB&amp;lt;/u&amp;gt;''': Nintendo Virtual Boy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WII&amp;lt;/u&amp;gt;''': Nintendo Wii&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SMS&amp;lt;/u&amp;gt;''': Sega Master System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SMD&amp;lt;/u&amp;gt;''': Sega Genesis/Mega Drive&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SCD&amp;lt;/u&amp;gt;''': Sega CD/Mega CD&lt;br /&gt;
* '''&amp;lt;u&amp;gt;32X&amp;lt;/u&amp;gt;''': Sega 32X&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GG&amp;lt;/u&amp;gt;''': Sega GameGear&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SAT&amp;lt;/u&amp;gt;''': Sega Saturn&lt;br /&gt;
* '''&amp;lt;u&amp;gt;DC&amp;lt;/u&amp;gt;''': Sega Dreamcast&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PSP&amp;lt;/u&amp;gt;''': Sony Playstation Portable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TGC&amp;lt;/u&amp;gt;''': Tiger Game.com&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Considering support &amp;quot;some day&amp;quot;:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;3DO&amp;lt;/u&amp;gt;''': 3DO&lt;br /&gt;
* '''&amp;lt;u&amp;gt;A26&amp;lt;/u&amp;gt;''': Atari 2600&lt;br /&gt;
* '''&amp;lt;u&amp;gt;LYNX&amp;lt;/u&amp;gt;''': Atari Lynx/Lynx II&lt;br /&gt;
* '''&amp;lt;u&amp;gt;JAG&amp;lt;/u&amp;gt;''': Atari Jaguar&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WS&amp;lt;/u&amp;gt;''': Bandai Wonder Swan&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WSC&amp;lt;/u&amp;gt;''': Bandai Wonder Swan Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GP32&amp;lt;/u&amp;gt;''': GamePark 32&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GP2X&amp;lt;/u&amp;gt;''': GamePark Holdings GP2X&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WIZ&amp;lt;/u&amp;gt;''': GamePark Holdings GP2X Wiz&lt;br /&gt;
* '''&amp;lt;u&amp;gt;XBOX&amp;lt;/u&amp;gt;''': Microsoft XBox&lt;br /&gt;
* '''&amp;lt;u&amp;gt;X360&amp;lt;/u&amp;gt;''': Microsoft XBox 360&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TG16&amp;lt;/u&amp;gt;''': NEC TurboGrafx-16/PC Engine&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TGCD&amp;lt;/u&amp;gt;''': NEC TurboGrafx-CD/PC Engine CD&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SGFX&amp;lt;/u&amp;gt;''': NEC SuperGrafx&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGEO&amp;lt;/u&amp;gt;''': Neo*Geo AES/MVS&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGP&amp;lt;/u&amp;gt;''': Neo*Geo Pocket&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGPC&amp;lt;/u&amp;gt;''': Neo*Geo Pocket Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PKMN&amp;lt;/u&amp;gt;''': Nintendo Pokémon Mini&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SGB&amp;lt;/u&amp;gt;''': Nintendo Super GameBoy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;CDI&amp;lt;/u&amp;gt;''': Philips CD-i&lt;br /&gt;
* '''&amp;lt;u&amp;gt;VMU&amp;lt;/u&amp;gt;''': Sega Dreamcast VMU&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS3&amp;lt;/u&amp;gt;''': Sony Playstation 3&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SV&amp;lt;/u&amp;gt;''': SuperVision&lt;br /&gt;
&lt;br /&gt;
===Proposal Comments===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Protocol Goals&amp;quot; have lead much of the motivation for developing this proposal. This presents what seems to be several very strange choices, at first glance. The choice of representing floating point numbers as a string of text seems extremely odd, until you consider that using the target-native floating point data format would make no sense when sending that data to a remote client (which is most likely running on a different architecture, and may have totally different native floating point formats). In order to express floating points with arbitrary precision in a data format-agnostic way, it is necessary to use a non-native format like text.&lt;br /&gt;
&lt;br /&gt;
Another oddity in this spec is the use of VLIs (variable-length integers) and their affect on the rest of the format. The main purpose for using VLIs is address widths. Some architectures can express their full address range within a single byte. Others require up to 8 bytes for a full 64-bit address range. Future architectures are by no means limited to 64-bit address widths. For this very reason, it is necessary to scale down as well as up. A VLI can express an address in as little as a single byte, or scale upward to arbitrarily large numbers. This makes VLIs perfect for addressing requirements among any architecture.&lt;br /&gt;
&lt;br /&gt;
VLIs present their own issues, however. For example, expressing a negative number as a VLI is nearly incomprehensible. Some might be inclined to reserve one bit within a VLI to indicate signedness, but that's another bit that cannot be used to minimize VLI overhead. The overhead is additional bytes required to represent a full number in a VLI system. For example, it is common for numbers 0 - 127 to be contained entirely within a single byte, including the overhead. But numbers between 128 - 255 require an additional byte to include more VLI &amp;quot;header&amp;quot; information (used to extend VLIs into arbitrarily long numbers). This is counter-intuitive, where a single byte itself can hold numbers between 0 - 255. Adding an additional sign bit reduces the range of VLIs by half: a single byte can only encode numbers between 0 - 63.&lt;br /&gt;
&lt;br /&gt;
The solution is to use a different data type specifically for expressing negative numbers. The VLI is encoded just like a positive number, but when interpreting the VLI, it must be converted to a negative number by either subtracting from zero (0 - ''n'') or multiplying by negative one (''n'' * -1). This is referred to as a &amp;quot;one's complement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In general, the efficiency of a VLI is very static. That means, a number using 0 - 7 bits of data (for example, the number &amp;quot;0&amp;quot; uses 0 bits of data, and the number &amp;quot;64&amp;quot; [binary: 100000] uses 6 bits) can be encoded into a single byte, a number using 8 - 14 bits can be encoded into 2 bytes, a number using 15 - 21 bits can be encoded into 3 bytes, etc. See http://www.dlugosz.com/ZIP2/VLI.html for more information on the kind of VLI I am considering for this proposal.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=2037</id>
		<title>Scalable Remote Debugger Protocol</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=2037"/>
				<updated>2020-12-28T05:19:54Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: Fix external links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently serving as a reference to kick-start development of the universal debugger protocol which will be used by the [[Universal Debugger Project]] and hopefully many, many other debuggers and debugger interfaces in the years to come.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
These references are listed in order of relevance; most relevant first.&lt;br /&gt;
&lt;br /&gt;
# [https://tools.ietf.org/html/rfc909 RFC-909: Loader Debugger Protocol]&lt;br /&gt;
# [https://sourceware.org/gdb/onlinedocs/gdb/Remote-Protocol.html GDB Remote Serial Protocol]&lt;br /&gt;
# [https://tools.ietf.org/html/rfc643 RFC-643: Network Debugging Protocol]&lt;br /&gt;
# [http://networksorcery.com/enp/ien/ien158.txt IEN-158: XNET Debugging Protocol]&lt;br /&gt;
# [https://xdebug.org/docs/dbgp DBGp: A common debugger protocol for languages and debugger UI communication]&lt;br /&gt;
&lt;br /&gt;
The relevancy I've determined for this list is due to interest in these specs, as well as potential generic uses and protocol extension.&lt;br /&gt;
&lt;br /&gt;
RFC-909 is so far the closest thing I have found which resembles the general idea I have for a &amp;quot;Universal Debugger Protocol&amp;quot;. It's composed as a simple binary packet, it's extensible, and it's designed to be stacked on top of existing transport protocols such as TCP/IP. I doubt this exact spec will fit all of our needs, but it is certainly a good start.&lt;br /&gt;
&lt;br /&gt;
GDB provides a fairly popular protocol. This one is designed for serial communications, so it will work well with small embedded devices. But it could be complicated to extend while retaining its GDB friendliness.&lt;br /&gt;
&lt;br /&gt;
RFC-643 and IEN-158 are interesting only because they show that some experimentation on the ideas of remote debugging have been employed in the past. Unfortunately, these specs were designed for a specific architecture, and are of little practical use for our purposes.&lt;br /&gt;
&lt;br /&gt;
DBGp shows what a modern remote debugging protocol can look like; including modern XML syntax. The downside to this is that low-level debuggers in small embedded devices are unlikely to parse XML at all.&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
&lt;br /&gt;
This section represents my ([[User:Parasyte|Parasyte]]) own personal opinions and ideas, and should not be taken as advocacy for standardization.&lt;br /&gt;
&lt;br /&gt;
One of the main goals of developing a &amp;quot;universal&amp;quot; protocol for debugging is that it must be usable everywhere; in small embedded devices, and some of the most powerful machines in the world. This kind of flexibility must be designed around multiple layers of abstraction. See [http://en.wikipedia.org/wiki/OSI_Model OSI Model] and [http://en.wikipedia.org/wiki/Internet_Protocol_Suite Internet Protocol Suite] for examples of abstraction layers used in communications technologies.&lt;br /&gt;
&lt;br /&gt;
At the lowest layer, you find the ''wire''; the physical means of transmitting information over distance. For our purposes, we should not limit ourselves to a single wire. Instead, we should allow the use of multiple wires, user-selectable, but never more than one at a time.&lt;br /&gt;
&lt;br /&gt;
The following layers get more and more generic and abstract, until you reach the highest layer which represents what the application sees and interacts with. This would be the &amp;quot;protocol&amp;quot; itself.&lt;br /&gt;
&lt;br /&gt;
So let's break these components down, hypothetically, and get into some details, ordered lowest layer first:&lt;br /&gt;
&lt;br /&gt;
# '''Physical layer''': Some examples of wires to support include LAN (Ethernet/WiFi), Wireless (Bluetooth), RS-232 (serial port, USB serial port), Inter-Process Communication (Domain Sockets? DBUS?)&lt;br /&gt;
# '''Transport layer''': Some examples of transport protocols include TCP/IP, UDP/IP (LAN, Domain Sockets), UART (RS-232), IPC-specific (DBUS)&lt;br /&gt;
# '''Application layer''': A library (or similar service, E.G. a daemon) to tie all transport layers into a single API that, to the application, looks like one simple interface to connect and send/receive data. The library/daemon will have to handle the transport-specific details behind-the-scenes.&lt;br /&gt;
&lt;br /&gt;
Thinking about this led to a conundrum; If we support multiple wires, we have to support multiple transport protocols which are compatible with those wires. And if we support multiple transport protocols, we have to know which one our target implements. To make the API as simple as possible, we must not force clients to choose from configurable options (for a bad example) that requires a large degree of changes for each different type of connection made. How do we simplify the API so that a user can just plain connect without doing any pre-setup work?&lt;br /&gt;
&lt;br /&gt;
Answer: The [http://en.wikipedia.org/wiki/URI_scheme URI scheme]. The unfortunate downside to this solution is that it is undesired to use URI schemes without registering them with IANA. However, an argument could be made that these schemes would not be used for general network/internet communication. A few popular examples of similarly non-networked schemes are the file: and about: URI schemes. (The exception here is that at least one physical layer (LAN) could be used for over-the-internet communication; but this has great benefits in its own right.)&lt;br /&gt;
&lt;br /&gt;
===Example URI Schemes===&lt;br /&gt;
&lt;br /&gt;
The following table represents some examples of how URI schemes could be used as debugger protocols:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp://192.168.1.20/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | TCP/IP to remote host 192.168.1.20 on a pre-defined default port&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+udp://192.168.1.20:9424/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UDP/IP to remote host 192.168.1.20 on port 9424&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+usb://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | USB (SRDP-compatible devices) on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+uart://localhost:3/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UART COM port 3 on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+dbus://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | DBUS IPC on localhost&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'srdp' prefix on these examples is to specify the 'Scalable Remote Debugger Protocol.' The + and suffix defines an additional layer (or protocol) below SRDP.&lt;br /&gt;
&lt;br /&gt;
The latter three examples look a bit odd with localhost being the destination, but this is necessary, since the localhost ''is'' the destination for hosting the UART RS-232 port, USB port, and IPC interface. Using non-loopback interfaces (IP addresses outside of the local machine) with these protocols should be undefined, unless there is evidence that connecting to RS-232/USB/IPC interfaces on other machines across a network is practical and plausible.&lt;br /&gt;
&lt;br /&gt;
===Simplified Configuration===&lt;br /&gt;
&lt;br /&gt;
These URI schemes give a very simple and elegant solution to the concerns they address. No longer will you be stuck with complicated configuration settings like the example below (upper left group box) ... and this is not an incredibly complex configuration dialog, as it is; instead, connecting to ANY low-level debugger in the world will be as simple as typing a URL.&lt;br /&gt;
&lt;br /&gt;
Example of what '''''not''''' to do:&lt;br /&gt;
&lt;br /&gt;
[[Image:Gscc_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Operation Groups===&lt;br /&gt;
&lt;br /&gt;
The protocol is defined as a set of usable &amp;quot;requests&amp;quot; (AKA &amp;quot;operations&amp;quot; or &amp;quot;commands&amp;quot;) requested by the client to the debugger, or vice-versa. Operations should be grouped according to a specific metric. The metric I've chosen is hardware (architecture) relationships. The table below shows an example of such groups (currently 6 in total) and example operations assigned to each group.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 1)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Diagnostics (Info, Ping/Pong, Reset, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 2)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | CPU handling (Register read/write, Arbitrary code execution, General CPU control, General process/thread control...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 3)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Memory handling (Read, Write, Address conversion, Hardware I/O, Cache control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 4)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Breakpoint handling (Add, Delete, Edit, Get, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 5)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Stream handling (stdin/stdout/stderr, Debugger-specific messages, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 6)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Vendor-specific (Custom command sets; should be discouraged unless absolutely necessary)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Proposal==&lt;br /&gt;
&lt;br /&gt;
This section defines a proposed specification which may be adopted as the &amp;quot;Scalable Remote Debugger Protocol&amp;quot;. It is considered a work in progress and is currently open for peer-review, meaning we are interested in receiving comments, criticisms, and suggestions.&lt;br /&gt;
&lt;br /&gt;
===Protocol Goals===&lt;br /&gt;
&lt;br /&gt;
Goals of the protocol include:&lt;br /&gt;
&lt;br /&gt;
# '''Client/server relationship''': Target (debuggee) acts as a server, quietly listening for any SRDP requests; User Interface acts as a client, making explicit requests to a listening server.&lt;br /&gt;
# '''Asynchronous requests''': A client must send requests without expecting an immediate response. A server accepting requests may not respond immediately to those requests.&lt;br /&gt;
# '''Scalable''': The data structure (format) used in the protocol must be adaptable to the future; The structure must be as forgiving and dynamic as possible, avoiding fixed contents (except where absolutely necessary) and allowing for [non-mission-critical] non-standard contents.&lt;br /&gt;
# '''Easy to implement''': Basic features of the protocol should be easy to implement from an API point-of-view, as well as having a small memory footprint; the protocol must be usable on small embedded machines with few resources.&lt;br /&gt;
# '''Robust''': Ambiguity should be kept to a minimum in all aspects of the protocol; every bit transferred should have a useful meaning.&lt;br /&gt;
# '''Easy to debug''': A debugger protocol that cannot itself be debugged (observed and verified to work as expected) is a failure in and of itself. For this reason, the protocol should be human-readable in its most basic form.&lt;br /&gt;
&lt;br /&gt;
===Underlying Protocols===&lt;br /&gt;
&lt;br /&gt;
There are no reservations on any underlying protocols (protocols used to move data from the client to the server, and back again -- SRDP is not one of these protocols). The only requirement is that they provide hand-shaking (transmission control), sequential ordering of packet data arrival, and data integrity checking. Some examples of suitable underlying protocols include [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/UDP/IP], and [http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART].&lt;br /&gt;
&lt;br /&gt;
The initial reference implementation will use TCP/IP for remote connections. For local-listening servers, the reference implementation will use UNIX Domain Sockets on UNIX-like operating systems, and Named Pipes on Windows.&lt;br /&gt;
&lt;br /&gt;
===Requests, Responses, Alerts===&lt;br /&gt;
&lt;br /&gt;
Packets are given different names depending on their transmission direction (client -&amp;gt; server, or server -&amp;gt; client) and intended recipient (server, specific client, or all clients).&lt;br /&gt;
&lt;br /&gt;
Response, requests, and alerts must have a unique identifier associated with them. This will allow clients and servers to stay in sync, knowing which responses are for which requests, for example.&lt;br /&gt;
&lt;br /&gt;
====Requests====&lt;br /&gt;
&lt;br /&gt;
A packet is called a request if it is from a client to the server. The name &amp;quot;request&amp;quot; comes from the idea that the client is requesting information or a specific action to be performed by the server.&lt;br /&gt;
&lt;br /&gt;
====Responses====&lt;br /&gt;
&lt;br /&gt;
Responses are packets from a server to a specific client. Responses are always sent in response to a request (hence the name). However, not all requests are required to send responses (which is why &amp;quot;requests&amp;quot; are not called &amp;quot;commands&amp;quot;). Responses are only sent to the client which initiated the specific request being handled.&lt;br /&gt;
&lt;br /&gt;
====Alerts====&lt;br /&gt;
&lt;br /&gt;
An alert is a special type of response (a packet from the server to clients); an alert is sent to all connected/listening clients. This is synonymous with network &amp;quot;broadcast&amp;quot; packets, and it useful for notifying all clients of information they might like to know.&lt;br /&gt;
&lt;br /&gt;
A few examples of information that all clients might like to know are:&lt;br /&gt;
&lt;br /&gt;
* Breakpoint hits&lt;br /&gt;
* Pausing/resuming execution&lt;br /&gt;
* Resets&lt;br /&gt;
* Debugging messages (log messages)&lt;br /&gt;
&lt;br /&gt;
Not all alerts are initiated by requests from clients, but most will be. Log messages are typically spewed by programs without explicit requests; SRDP can allow listening for and capturing these messages.&lt;br /&gt;
&lt;br /&gt;
====Commands====&lt;br /&gt;
&lt;br /&gt;
The all-encompassing term for requests, responses and alerts is &amp;quot;commands&amp;quot;. Any time a &amp;quot;command&amp;quot; is mentioned, it refers to any combination of requests, responses, or alerts.&lt;br /&gt;
&lt;br /&gt;
===Protocol Packet Data Structure===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;goals&amp;quot; section outlines the major features which formed the following data structure. Inspiration comes mainly from [http://en.wikipedia.org/wiki/JSON JSON], the JavaScript Object Notation. As JSON is a serialization [text format] of JavaScript objects, the SRDP data structure is a serialization of the data being transmitted.&lt;br /&gt;
&lt;br /&gt;
The structure also shares some inspiration from [http://en.wikipedia.org/wiki/Remote_procedure_call RPC]; An example is that your client may want to read work RAM from the target. The SRDP request for &amp;quot;read memory&amp;quot; is technically similar to remotely running a &amp;quot;read memory&amp;quot; function on the server, invoked by the client. For this reason, each SRDP packet contains one or more &amp;quot;arguments&amp;quot; which you could imagine are passed directly to a plain old function.&lt;br /&gt;
&lt;br /&gt;
Each packet is sent as a series of 8-bit bytes. Packets are broken down into a &amp;quot;request/response/alert&amp;quot; name (called a command), encapsulating a series of &amp;quot;arguments&amp;quot;. You can think of it like a C function call. The &amp;quot;info&amp;quot; command, for example, requests information about the target machine architecture; it requires no arguments. The info command looks like this, and is a complete and valid SRDP packet:&lt;br /&gt;
&lt;br /&gt;
  info()&lt;br /&gt;
&lt;br /&gt;
Each argument has a name (made of one or more characters: alpha-numeric, underscore (_), or hyphen (-). The argument name is followed by a colon (:) and then a single byte representing the data type of the argument, then an equals sign (=) and the argument's value. All arguments are separated with a comma (,).&lt;br /&gt;
&lt;br /&gt;
The argument syntax is similar to that of [http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]. In pseudo-form, it looks something like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:{type}={value}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Valid data types:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | {type}&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Name&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | n&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any positive integer, encoded as a [http://www.dlugosz.com/ZIP2/VLI.html VLI]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | s&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Signed Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any negative integer, encoded as a [http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement one's complement] VLI&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | f&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Floating Point Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any non-integer number, Infinity, or [http://en.wikipedia.org/wiki/NaN NaN], encoded as a null-terminated UTF-8 string, or null-terminated UTF-16 or UTF-32 string with BOM; To be decoded by [http://en.wikipedia.org/wiki/Scanf#Format_string_specifications sscanf]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | a&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob), preceded by a VLI to indicate the length of the array.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | c&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Compressed Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob) with [http://en.wikipedia.org/wiki/Run-length_encoding RLE] compression. See [[#Compressed Array Data Type]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | t&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Text&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Null-terminated UTF-8 string without [http://en.wikipedia.org/wiki/Byte-order_mark BOM], or null-terminated UTF-16 or UTF-32 string with BOM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some example arguments. (Please keep in mind that all of the argument names listed within this section are for demonstration purposes only, and are not recommended for reference purposes.)&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | msg:t=Hello, World!␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | num:n=□&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | pi:f=3.141592␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | ram_dump:a=□■■■■&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | my-compressed-data:c=□□■■■■□■□■■■&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
What the symbols mean:&lt;br /&gt;
&lt;br /&gt;
  ␀: Null-terminator&lt;br /&gt;
  □: VLI&lt;br /&gt;
  ■: Data byte&lt;br /&gt;
&lt;br /&gt;
====Compressed Array Data Type====&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; padding: 10px;&amp;quot; | '''''One suggestion is making this data-type optional, and changing this spec to use a standard library, like zlib. In this way, slow machines with few resources can adhere to the SRDP spec without wasting precious footprint space and computational power implementing such &amp;quot;heavy&amp;quot; libraries.&lt;br /&gt;
&lt;br /&gt;
Using a &amp;quot;heavy-weight&amp;quot; compression library will help achieve better compression ratios, but will add processing overhead. The added overhead may turn out to be an overall hindrance. For example, a memory editor might want to refresh a memory display as fast as possible (several times per second) within a small visible view-port window. This kind of editor will need to download the contents of memory within the visible range quickly. Using compression in a use-case like this is a good idea, but only if transferring the smaller packet can make up for the time required to compress and decompress the data.'''''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Compressed arrays are similar to the standard &amp;quot;Array&amp;quot; data type. The compressed array starts with a single VLI to represent the total data size of the value (e.g. the size of the compressed data, ''x''). The following data is a series of alternating raw data and RLE data.&lt;br /&gt;
&lt;br /&gt;
# '''Raw Data''': A VLI representing raw data size in bytes (''n''), followed by ''n'' bytes of actual data.&lt;br /&gt;
# '''RLE Data''': A VLI representing RLE data size in bytes (''n''), followed by a single byte to be repeated (''n'' + 4) times in the output.&lt;br /&gt;
&lt;br /&gt;
This series is repeated until there are no more bytes to be read from input (''x'' bytes of the argument value have been read).&lt;br /&gt;
&lt;br /&gt;
For the RLE compression to be useful (efficient) it must not be used for any less than 4 bytes (therefore, the VLI is said to be a &amp;quot;4-based&amp;quot; number). The number 4 is derived from the minimum overhead introduced by the serial alternation and VLIs; 1 VLI for RLE output length, 1 byte of RLE data, 1 VLI for raw data length.&lt;br /&gt;
&lt;br /&gt;
Thus, in order for the RLE to perform &amp;quot;compression&amp;quot;, the RLE output must be larger than the smallest sequence required to switch from raw data and back again. Some examples to illustrate, '''''bold-italic''''' bytes are for VLI &amp;quot;control sequences&amp;quot; (the data lengths specified above):&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 1'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 01&lt;br /&gt;
 &lt;br /&gt;
 Incorrectly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''&amp;lt;u&amp;gt;03&amp;lt;/u&amp;gt;''''' 00 '''''01''''' 01&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''08''''' 94 24 51 73 00 00 00 01&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 2'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''00''''' 00&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 3'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 00 00 00 00 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''00''''' '''''04''''' 00&lt;br /&gt;
&lt;br /&gt;
The reason the second line in example 1 above is &amp;quot;incorrectly&amp;quot; compressed is because the second VLI is expecting the length to be 0-based. If this was the case, you would be simply adding overhead to replace any bytes saved by the &amp;quot;compression&amp;quot;. For this reason, the &amp;quot;correct&amp;quot; way to compress the example is to use a single length of raw data. This example is non-compressible, and should not be sent as a compressed array data type.&lt;br /&gt;
&lt;br /&gt;
In the second example, the data can be compressed nicely, saving a byte overall (including compression overhead). Since this is the &amp;quot;correct&amp;quot; way to compress the data, it is using a 4-based VLI on the RLE Data: &amp;quot;'''''00'''''&amp;quot; means 4 bytes of output, &amp;quot;'''''01'''''&amp;quot; means 5 bytes, &amp;quot;'''''02'''''&amp;quot; means 6 bytes, etc.&lt;br /&gt;
&lt;br /&gt;
The third example shows how to compress a series of bytes that starts with repeating data, instead of non-repeating &amp;quot;raw data&amp;quot;. The first VLI of '''''00''''' means there is no raw data for output (this is required: compressed arrays always begin with the Raw Data, followed by RLE Data). The second VLI '''''04''''' is the length of the RLE Data; 8 bytes. Even if the non-compressed data was 4 bytes of &amp;quot;00&amp;quot;, the compressed array would still be only 3 bytes of total data, saving one byte. This helps explain the reasoning behind the 4-based VLI for RLE Data.&lt;br /&gt;
&lt;br /&gt;
====Object Data Type====&lt;br /&gt;
&lt;br /&gt;
The basic structure and data types shown so far are very powerful; your server can tell the client vast amounts of information, such as CPU architecture, memory maps, I/O maps, etc. with just a handful of arguments. However, grouping these arguments in a meaningful way may be difficult. You might be inclined to do some &amp;quot;mock&amp;quot; namespacing, like prefixing each CPU-related argument with &amp;quot;cpu_&amp;quot;. This is effective, but also slightly wasteful and error-prone.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;object&amp;quot; data type is designed to handle such situations. This data type allows an argument to be a container for other arguments. Its format looks like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:[...]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Where the set of ellipses denotes one or more &amp;quot;regular&amp;quot; arguments. Here is an example of what a &amp;quot;cpu&amp;quot; object might look like:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
(Note the white-space is for readability only; it is not meant to be transferred as part of the protocol data.)&lt;br /&gt;
&lt;br /&gt;
In this example, the &amp;quot;cpu&amp;quot; object contains two arguments: cpu.arch and cpu.name; both strings.&lt;br /&gt;
&lt;br /&gt;
But there are also times when you will want your server to send that same information for two [or more] CPU architectures on a single target. Some platforms may have multiple CPUs, each with its own individual set of resources (memory maps and the like), as well as shared resources between the CPUs. For this, the packet data structure needs a more advanced method of communicating these kinds of details.&lt;br /&gt;
&lt;br /&gt;
For this case, you can optionally create arrays of objects by including a comma (,) after the closing square bracket, followed by another series of arguments enclosed in their own square brackets, ''ad infinitum''. In other words, any leading object definitions without explicit names will be treated as additional array elements for the previously named object.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM7TDMI␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now our &amp;quot;cpu&amp;quot; object defines two CPUs: an ARM9 and ARM7, ready for Nintendo DS hacking. These arguments can be referenced as cpu[0].arch, cpu[0].name, cpu[1].arch, and cpu[1].name respectively.&lt;br /&gt;
&lt;br /&gt;
Objects can be arbitrarily complex, containing arrays of other objects. Here is an example of a simple memory map, containing Work RAM (read/write/execute) and ROM (read/execute) sections. The Work RAM section is broken into two distinct memory ranges. This is quite easily expressed:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;memory:[&lt;br /&gt;
:name:t=Work RAM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&amp;lt;br/&amp;gt;&lt;br /&gt;
:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RWX␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:name:t=ROM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RX␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Command Reference===&lt;br /&gt;
&lt;br /&gt;
'''''FIXME: WIP'''''&lt;br /&gt;
&lt;br /&gt;
====Requests====&lt;br /&gt;
&lt;br /&gt;
=====info()=====&lt;br /&gt;
Request information about the target machine architecture. The '''info()''' request is implied during connection: A response will be sent after a connection is successfully established. This allows clients to gather necessary information about the target during the connection phase, without explicitly making the request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Return values'':&lt;br /&gt;
&lt;br /&gt;
Must only return one of the following:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;sys&amp;lt;/u&amp;gt;''' (string):&amp;lt;br/&amp;gt;A shorthand for defining known machines (mostly video game systems).&amp;lt;br/&amp;gt;See below for supported values&lt;br /&gt;
* '''&amp;lt;u&amp;gt;machine&amp;lt;/u&amp;gt;''' (object):&amp;lt;br/&amp;gt;A longhand for defining the complete machine architecture.&amp;lt;br/&amp;gt;TODO: Specify all object elements and their meanings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The currently supported values for '''&amp;lt;u&amp;gt;sys&amp;lt;/u&amp;gt;''' are:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NES&amp;lt;/u&amp;gt;''': Nintendo Entertainment System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SNES&amp;lt;/u&amp;gt;''': Super Nintendo Entertainment System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;N64&amp;lt;/u&amp;gt;''': Nintendo 64&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGC&amp;lt;/u&amp;gt;''': Nintendo GameCube&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS1&amp;lt;/u&amp;gt;''': Sony Playstation&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS2&amp;lt;/u&amp;gt;''': Sony Playstation 2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Planned future support:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GB&amp;lt;/u&amp;gt;''': Nintendo GameBoy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GBC&amp;lt;/u&amp;gt;''': Nintendo GameBoy Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GBA&amp;lt;/u&amp;gt;''': Nintendo GameBoy Advance&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NDS&amp;lt;/u&amp;gt;''': Nintendo DS/DSi&lt;br /&gt;
* '''&amp;lt;u&amp;gt;VB&amp;lt;/u&amp;gt;''': Nintendo Virtual Boy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WII&amp;lt;/u&amp;gt;''': Nintendo Wii&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SMS&amp;lt;/u&amp;gt;''': Sega Master System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SMD&amp;lt;/u&amp;gt;''': Sega Genesis/Mega Drive&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SCD&amp;lt;/u&amp;gt;''': Sega CD/Mega CD&lt;br /&gt;
* '''&amp;lt;u&amp;gt;32X&amp;lt;/u&amp;gt;''': Sega 32X&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GG&amp;lt;/u&amp;gt;''': Sega GameGear&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SAT&amp;lt;/u&amp;gt;''': Sega Saturn&lt;br /&gt;
* '''&amp;lt;u&amp;gt;DC&amp;lt;/u&amp;gt;''': Sega Dreamcast&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PSP&amp;lt;/u&amp;gt;''': Sony Playstation Portable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TGC&amp;lt;/u&amp;gt;''': Tiger Game.com&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Considering support &amp;quot;some day&amp;quot;:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;3DO&amp;lt;/u&amp;gt;''': 3DO&lt;br /&gt;
* '''&amp;lt;u&amp;gt;A26&amp;lt;/u&amp;gt;''': Atari 2600&lt;br /&gt;
* '''&amp;lt;u&amp;gt;LYNX&amp;lt;/u&amp;gt;''': Atari Lynx/Lynx II&lt;br /&gt;
* '''&amp;lt;u&amp;gt;JAG&amp;lt;/u&amp;gt;''': Atari Jaguar&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WS&amp;lt;/u&amp;gt;''': Bandai Wonder Swan&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WSC&amp;lt;/u&amp;gt;''': Bandai Wonder Swan Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GP32&amp;lt;/u&amp;gt;''': GamePark 32&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GP2X&amp;lt;/u&amp;gt;''': GamePark Holdings GP2X&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WIZ&amp;lt;/u&amp;gt;''': GamePark Holdings GP2X Wiz&lt;br /&gt;
* '''&amp;lt;u&amp;gt;XBOX&amp;lt;/u&amp;gt;''': Microsoft XBox&lt;br /&gt;
* '''&amp;lt;u&amp;gt;X360&amp;lt;/u&amp;gt;''': Microsoft XBox 360&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TG16&amp;lt;/u&amp;gt;''': NEC TurboGrafx-16/PC Engine&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TGCD&amp;lt;/u&amp;gt;''': NEC TurboGrafx-CD/PC Engine CD&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SGFX&amp;lt;/u&amp;gt;''': NEC SuperGrafx&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGEO&amp;lt;/u&amp;gt;''': Neo*Geo AES/MVS&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGP&amp;lt;/u&amp;gt;''': Neo*Geo Pocket&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGPC&amp;lt;/u&amp;gt;''': Neo*Geo Pocket Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PKMN&amp;lt;/u&amp;gt;''': Nintendo Pokémon Mini&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SGB&amp;lt;/u&amp;gt;''': Nintendo Super GameBoy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;CDI&amp;lt;/u&amp;gt;''': Philips CD-i&lt;br /&gt;
* '''&amp;lt;u&amp;gt;VMU&amp;lt;/u&amp;gt;''': Sega Dreamcast VMU&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS3&amp;lt;/u&amp;gt;''': Sony Playstation 3&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SV&amp;lt;/u&amp;gt;''': SuperVision&lt;br /&gt;
&lt;br /&gt;
===Proposal Comments===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Protocol Goals&amp;quot; have lead much of the motivation for developing this proposal. This presents what seems to be several very strange choices, at first glance. The choice of representing floating point numbers as a string of text seems extremely odd, until you consider that using the target-native floating point data format would make no sense when sending that data to a remote client (which is most likely running on a different architecture, and may have totally different native floating point formats). In order to express floating points with arbitrary precision in a data format-agnostic way, it is necessary to use a non-native format like text.&lt;br /&gt;
&lt;br /&gt;
Another oddity in this spec is the use of VLIs (variable-length integers) and their affect on the rest of the format. The main purpose for using VLIs is address widths. Some architectures can express their full address range within a single byte. Others require up to 8 bytes for a full 64-bit address range. Future architectures are by no means limited to 64-bit address widths. For this very reason, it is necessary to scale down as well as up. A VLI can express an address in as little as a single byte, or scale upward to arbitrarily large numbers. This makes VLIs perfect for addressing requirements among any architecture.&lt;br /&gt;
&lt;br /&gt;
VLIs present their own issues, however. For example, expressing a negative number as a VLI is nearly incomprehensible. Some might be inclined to reserve one bit within a VLI to indicate signedness, but that's another bit that cannot be used to minimize VLI overhead. The overhead is additional bytes required to represent a full number in a VLI system. For example, it is common for numbers 0 - 127 to be contained entirely within a single byte, including the overhead. But numbers between 128 - 255 require an additional byte to include more VLI &amp;quot;header&amp;quot; information (used to extend VLIs into arbitrarily long numbers). This is counter-intuitive, where a single byte itself can hold numbers between 0 - 255. Adding an additional sign bit reduces the range of VLIs by half: a single byte can only encode numbers between 0 - 63.&lt;br /&gt;
&lt;br /&gt;
The solution is to use a different data type specifically for expressing negative numbers. The VLI is encoded just like a positive number, but when interpreting the VLI, it must be converted to a negative number by either subtracting from zero (0 - ''n'') or multiplying by negative one (''n'' * -1). This is referred to as a &amp;quot;one's complement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In general, the efficiency of a VLI is very static. That means, a number using 0 - 7 bits of data (for example, the number &amp;quot;0&amp;quot; uses 0 bits of data, and the number &amp;quot;64&amp;quot; [binary: 100000] uses 6 bits) can be encoded into a single byte, a number using 8 - 14 bits can be encoded into 2 bytes, a number using 15 - 21 bits can be encoded into 3 bytes, etc. See http://www.dlugosz.com/ZIP2/VLI.html for more information on the kind of VLI I am considering for this proposal.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=As85&amp;diff=2036</id>
		<title>As85</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=As85&amp;diff=2036"/>
				<updated>2012-12-30T05:19:12Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Development */ Update source link to git&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;as85 is a simple assembler for the Sharp sm8521; the same microcontroller used in the Tiger Game.com. Game.com was released in 1998 and had only a few games ever made for it. It also has not had any homebrew games made for it. as85 is an attempt to build an assembler that will help hackers write homebrew code that will run on Game.com hardware.&lt;br /&gt;
&lt;br /&gt;
Documentation on the Game.com hardware is available at [http://gamecom.guruwork.de/ Game.commies].&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The source code is available at http://git.kodewerx.org/as85/src/&lt;br /&gt;
&lt;br /&gt;
==Current Progress==&lt;br /&gt;
&lt;br /&gt;
The current state of as85 is &amp;quot;almost usable, but not quite there yet.&amp;quot; A number of bugs exist which need to be fixed before it can be used as a development tool:&lt;br /&gt;
&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=2 Bug 2]: Add support for jump/call/branch instructions&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=3 Bug 3]: Output object code&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=4 Bug 4]: Write a linker&lt;br /&gt;
&lt;br /&gt;
I've also filed a bug about giving the project a better name [http://bugzilla.kodewerx.org/show_bug.cgi?id=5].&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
The program takes one argument; the file name of an sm8521 assembly file. The files in the [http://git.kodewerx.org/as85/src/09f8ba9f769d47fc2038e81d9cc5866d80f96748/examples?at=master /examples] directory are a good place to start.&lt;br /&gt;
&lt;br /&gt;
* test.asm is an example of what the beginning of a Game.com program might look like; it contains a header, and some [random] instructions to give you an idea.&lt;br /&gt;
* test2.asm is for testing the integrity of the parser with complex strings.&lt;br /&gt;
* test3.asm lists all possible sm8521 instructions; for verifying the output binary is correct.&lt;br /&gt;
&lt;br /&gt;
==Example Output==&lt;br /&gt;
&lt;br /&gt;
The following command:&lt;br /&gt;
 $ ./as85 ../examples/test3.asm&lt;br /&gt;
&lt;br /&gt;
Produces the following output:&lt;br /&gt;
 00 01           clr     R1&lt;br /&gt;
 01 01           neg     R1&lt;br /&gt;
 02 01           com     R1&lt;br /&gt;
 03 01           rr      R1&lt;br /&gt;
 04 01           rl      R1&lt;br /&gt;
 05 01           rrc     R1&lt;br /&gt;
 06 01           rlc     R1&lt;br /&gt;
 07 01           srl     R1&lt;br /&gt;
 08 01           inc     R1&lt;br /&gt;
 09 01           dec     R1&lt;br /&gt;
 0A 01           sra     R1&lt;br /&gt;
 0B 01           sll     R1&lt;br /&gt;
 0C 01           da      R1&lt;br /&gt;
 0D 01           swap    R1&lt;br /&gt;
 0E 01           push    R1&lt;br /&gt;
 0F 01           pop     R1&lt;br /&gt;
 10 0A           cmp     r1, r2&lt;br /&gt;
 11 0A           add     r1, r2&lt;br /&gt;
 12 0A           sub     r1, r2&lt;br /&gt;
 13 0A           adc     r1, r2&lt;br /&gt;
 14 0A           sbc     r1, r2&lt;br /&gt;
 15 0A           and     r1, r2&lt;br /&gt;
 16 0A           or      r1, r2&lt;br /&gt;
 17 0A           xor     r1, r2&lt;br /&gt;
 18 02           incw    RR2&lt;br /&gt;
 19 02           decw    RR2&lt;br /&gt;
 1A 08           clr     @r1&lt;br /&gt;
 1A 09           neg     @r1&lt;br /&gt;
 1A 0A           com     @r1&lt;br /&gt;
 1A 0B           rr      @r1&lt;br /&gt;
 1A 0C           rl      @r1&lt;br /&gt;
 1A 0D           rrc     @r1&lt;br /&gt;
 1A 0E           rlc     @r1&lt;br /&gt;
 1A 0F           srl     @r1&lt;br /&gt;
 1B 08           inc     @r1&lt;br /&gt;
 1B 09           dec     @r1&lt;br /&gt;
 1B 0A           sra     @r1&lt;br /&gt;
 1B 0B           sll     @r1&lt;br /&gt;
 1B 0C           da      @r1&lt;br /&gt;
 1B 0D           swap    @r1&lt;br /&gt;
 1B 0E           push    @r1&lt;br /&gt;
 1B 0F           pop     @r1&lt;br /&gt;
 1C 07 24        bclr    0xFF24, #7&lt;br /&gt;
 1C 0F 94        bclr    0x94(r1), #7&lt;br /&gt;
 1D 07 24        bset    0xFF24, #7&lt;br /&gt;
 1D 0F 94        bset    0x94(r1), #7&lt;br /&gt;
 1E 02           pushw   RR2&lt;br /&gt;
 1F 02           popw    RR2&lt;br /&gt;
 20 0A           cmp     r1, @r2&lt;br /&gt;
 20 4A           cmp     r1, (r2)+&lt;br /&gt;
 20 88 94        cmp     r1, @0x94&lt;br /&gt;
 20 8A 94        cmp     r1, 0x94(r2)&lt;br /&gt;
 20 CA           cmp     r1, -(r2)&lt;br /&gt;
 21 0A           add     r1, @r2&lt;br /&gt;
 21 4A           add     r1, (r2)+&lt;br /&gt;
 21 88 94        add     r1, @0x94&lt;br /&gt;
 21 8A 94        add     r1, 0x94(r2)&lt;br /&gt;
 21 CA           add     r1, -(r2)&lt;br /&gt;
 22 0A           sub     r1, @r2&lt;br /&gt;
 22 4A           sub     r1, (r2)+&lt;br /&gt;
 22 88 94        sub     r1, @0x94&lt;br /&gt;
 22 8A 94        sub     r1, 0x94(r2)&lt;br /&gt;
 22 CA           sub     r1, -(r2)&lt;br /&gt;
 23 0A           adc     r1, @r2&lt;br /&gt;
 23 4A           adc     r1, (r2)+&lt;br /&gt;
 23 88 94        adc     r1, @0x94&lt;br /&gt;
 23 8A 94        adc     r1, 0x94(r2)&lt;br /&gt;
 23 CA           adc     r1, -(r2)&lt;br /&gt;
 24 0A           sbc     r1, @r2&lt;br /&gt;
 24 4A           sbc     r1, (r2)+&lt;br /&gt;
 24 88 94        sbc     r1, @0x94&lt;br /&gt;
 24 8A 94        sbc     r1, 0x94(r2)&lt;br /&gt;
 24 CA           sbc     r1, -(r2)&lt;br /&gt;
 25 0A           and     r1, @r2&lt;br /&gt;
 25 4A           and     r1, (r2)+&lt;br /&gt;
 25 88 94        and     r1, @0x94&lt;br /&gt;
 25 8A 94        and     r1, 0x94(r2)&lt;br /&gt;
 25 CA           and     r1, -(r2)&lt;br /&gt;
 26 0A           or      r1, @r2&lt;br /&gt;
 26 4A           or      r1, (r2)+&lt;br /&gt;
 26 88 94        or      r1, @0x94&lt;br /&gt;
 26 8A 94        or      r1, 0x94(r2)&lt;br /&gt;
 26 CA           or      r1, -(r2)&lt;br /&gt;
 27 0A           xor     r1, @r2&lt;br /&gt;
 27 4A           xor     r1, (r2)+&lt;br /&gt;
 27 88 94        xor     r1, @0x94&lt;br /&gt;
 27 8A 94        xor     r1, 0x94(r2)&lt;br /&gt;
 27 CA           xor     r1, -(r2)&lt;br /&gt;
 28 0A           mov     r1, @r2&lt;br /&gt;
 28 4A           mov     r1, (r2)+&lt;br /&gt;
 28 88 94        mov     r1, @0x94&lt;br /&gt;
 28 8A 94        mov     r1, 0x94(r2)&lt;br /&gt;
 28 CA           mov     r1, -(r2)&lt;br /&gt;
 29 11           mov     @r1, r2&lt;br /&gt;
 29 51           mov     (r1)+, r2&lt;br /&gt;
 29 90 94        mov     @0x94, r2&lt;br /&gt;
 29 91 94        mov     0x94(r1), r2&lt;br /&gt;
 29 D1           mov     -(r1), r2&lt;br /&gt;
 2C 02           exts    RR2&lt;br /&gt;
 2E 94           mov     ps0, #0x94&lt;br /&gt;
 2F 94 01        btst    R1, #0x94&lt;br /&gt;
 30 09           cmp     r1, @rr2&lt;br /&gt;
 30 49           cmp     r1, (rr2)+&lt;br /&gt;
 30 88 24 94     cmp     r1, @0x9424&lt;br /&gt;
 30 89 24 94     cmp     r1, 0x9424(rr2)&lt;br /&gt;
 30 C9           cmp     r1, -(rr2)&lt;br /&gt;
 31 09           add     r1, @rr2&lt;br /&gt;
 31 49           add     r1, (rr2)+&lt;br /&gt;
 31 88 24 94     add     r1, @0x9424&lt;br /&gt;
 31 89 24 94     add     r1, 0x9424(rr2)&lt;br /&gt;
 31 C9           add     r1, -(rr2)&lt;br /&gt;
 32 09           sub     r1, @rr2&lt;br /&gt;
 32 49           sub     r1, (rr2)+&lt;br /&gt;
 32 88 24 94     sub     r1, @0x9424&lt;br /&gt;
 32 89 24 94     sub     r1, 0x9424(rr2)&lt;br /&gt;
 32 C9           sub     r1, -(rr2)&lt;br /&gt;
 33 09           adc     r1, @rr2&lt;br /&gt;
 33 49           adc     r1, (rr2)+&lt;br /&gt;
 33 88 24 94     adc     r1, @0x9424&lt;br /&gt;
 33 89 24 94     adc     r1, 0x9424(rr2)&lt;br /&gt;
 33 C9           adc     r1, -(rr2)&lt;br /&gt;
 34 09           sbc     r1, @rr2&lt;br /&gt;
 34 49           sbc     r1, (rr2)+&lt;br /&gt;
 34 88 24 94     sbc     r1, @0x9424&lt;br /&gt;
 34 89 24 94     sbc     r1, 0x9424(rr2)&lt;br /&gt;
 34 C9           sbc     r1, -(rr2)&lt;br /&gt;
 35 09           and     r1, @rr2&lt;br /&gt;
 35 49           and     r1, (rr2)+&lt;br /&gt;
 35 88 24 94     and     r1, @0x9424&lt;br /&gt;
 35 89 24 94     and     r1, 0x9424(rr2)&lt;br /&gt;
 35 C9           and     r1, -(rr2)&lt;br /&gt;
 36 09           or      r1, @rr2&lt;br /&gt;
 36 49           or      r1, (rr2)+&lt;br /&gt;
 36 88 24 94     or      r1, @0x9424&lt;br /&gt;
 36 89 24 94     or      r1, 0x9424(rr2)&lt;br /&gt;
 36 C9           or      r1, -(rr2)&lt;br /&gt;
 37 09           xor     r1, @rr2&lt;br /&gt;
 37 49           xor     r1, (rr2)+&lt;br /&gt;
 37 88 24 94     xor     r1, @0x9424&lt;br /&gt;
 37 89 24 94     xor     r1, 0x9424(rr2)&lt;br /&gt;
 37 C9           xor     r1, -(rr2)&lt;br /&gt;
 38 09           mov     r1, @rr2&lt;br /&gt;
 38 49           mov     r1, (rr2)+&lt;br /&gt;
 38 88 24 94     mov     r1, @0x9424&lt;br /&gt;
 38 89 24 94     mov     r1, 0x9424(rr2)&lt;br /&gt;
 38 C9           mov     r1, -(rr2)&lt;br /&gt;
 39 21           mov     @rr2, r4&lt;br /&gt;
 39 61           mov     (rr2)+, r4&lt;br /&gt;
 39 A0 24 94     mov     @0x9424, r4&lt;br /&gt;
 39 A1 24 94     mov     0x9424(rr2), r4&lt;br /&gt;
 39 E1           mov     -(rr2), r4&lt;br /&gt;
 3A 14           movw    rr2, @rr4&lt;br /&gt;
 3A 54           movw    rr2, (rr4)+&lt;br /&gt;
 3A 90 24 94     movw    rr2, @0x9424&lt;br /&gt;
 3A 94 24 94     movw    rr2, 0x9424(rr4)&lt;br /&gt;
 3A D4           movw    rr2, -(rr4)&lt;br /&gt;
 3B 22           movw    @rr2, rr4&lt;br /&gt;
 3B 62           movw    (rr2)+, rr4&lt;br /&gt;
 3B A0 24 94     movw    @0x9424, rr4&lt;br /&gt;
 3B A2 24 94     movw    0x9424(rr2), rr4&lt;br /&gt;
 3B E2           movw    -(rr2), rr4&lt;br /&gt;
 3C 14           movw    rr2, rr4&lt;br /&gt;
 40 02 01        cmp     R1, R2&lt;br /&gt;
 41 02 01        add     R1, R2&lt;br /&gt;
 42 02 01        sub     R1, R2&lt;br /&gt;
 43 02 01        adc     R1, R2&lt;br /&gt;
 44 02 01        sbc     R1, R2&lt;br /&gt;
 45 02 01        and     R1, R2&lt;br /&gt;
 46 02 01        or      R1, R2&lt;br /&gt;
 47 02 01        xor     R1, R2&lt;br /&gt;
 48 02 01        mov     R1, R2&lt;br /&gt;
 4A 04 02        movw    RR2, RR4&lt;br /&gt;
 4B 02 24 94     movw    RR2, #0x9424&lt;br /&gt;
 4C 04 02        mult    RR2, R4&lt;br /&gt;
 4D 94 02        mult    RR2, #0x94&lt;br /&gt;
 4E 07 01        bmov    bf, R1, #7&lt;br /&gt;
 4E 47 01        bmov    R1, #7, bf&lt;br /&gt;
 4F 07 01        bcmp    bf, R1, #7&lt;br /&gt;
 4F 47 01        band    bf, R1, #7&lt;br /&gt;
 4F 87 01        bor     bf, R1, #7&lt;br /&gt;
 4F C7 01        bxor    bf, R1, #7&lt;br /&gt;
 50 94 01        cmp     R1, #0x94&lt;br /&gt;
 51 94 01        add     R1, #0x94&lt;br /&gt;
 52 94 01        sub     R1, #0x94&lt;br /&gt;
 53 94 01        adc     R1, #0x94&lt;br /&gt;
 54 94 01        sbc     R1, #0x94&lt;br /&gt;
 55 94 01        and     R1, #0x94&lt;br /&gt;
 56 94 01        or      R1, #0x94&lt;br /&gt;
 57 94 01        xor     R1, #0x94&lt;br /&gt;
 58 94 01        mov     R1, #0x94&lt;br /&gt;
 5C 04 02        div     RR2, RR4&lt;br /&gt;
 5D 94 02        div     RR2, #0x94&lt;br /&gt;
 5E 01 94 02     movm    R1, #0x94, R2&lt;br /&gt;
 5F 01 94 24     movm    R1, #0x94, #0x24&lt;br /&gt;
 60 04 02        cmpw    RR2, RR4&lt;br /&gt;
 61 04 02        addw    RR2, RR4&lt;br /&gt;
 62 04 02        subw    RR2, RR4&lt;br /&gt;
 63 04 02        adcw    RR2, RR4&lt;br /&gt;
 64 04 02        sbcw    RR2, RR4&lt;br /&gt;
 65 04 02        andw    RR2, RR4&lt;br /&gt;
 66 04 02        orw     RR2, RR4&lt;br /&gt;
 67 04 02        xorw    RR2, RR4&lt;br /&gt;
 68 02 24 94     cmpw    RR2, #0x9424&lt;br /&gt;
 69 02 24 94     addw    RR2, #0x9424&lt;br /&gt;
 6A 02 24 94     subw    RR2, #0x9424&lt;br /&gt;
 6B 02 24 94     adcw    RR2, #0x9424&lt;br /&gt;
 6C 02 24 94     sbcw    RR2, #0x9424&lt;br /&gt;
 6D 02 24 94     andw    RR2, #0x9424&lt;br /&gt;
 6E 02 24 94     orw     RR2, #0x9424&lt;br /&gt;
 6F 02 24 94     xorw    RR2, #0x9424&lt;br /&gt;
 78 24 94        movw    rr0, #0x9424&lt;br /&gt;
 79 24 94        movw    rr8, #0x9424&lt;br /&gt;
 7A 24 94        movw    rr2, #0x9424&lt;br /&gt;
 7B 24 94        movw    rr10, #0x9424&lt;br /&gt;
 7C 24 94        movw    rr4, #0x9424&lt;br /&gt;
 7D 24 94        movw    rr12, #0x9424&lt;br /&gt;
 7E 24 94        movw    rr6, #0x9424&lt;br /&gt;
 7F 24 94        movw    rr14, #0x9424&lt;br /&gt;
 A0 01           bclr    R1, #0&lt;br /&gt;
 A1 01           bclr    R1, #1&lt;br /&gt;
 A2 01           bclr    R1, #2&lt;br /&gt;
 A3 01           bclr    R1, #3&lt;br /&gt;
 A4 01           bclr    R1, #4&lt;br /&gt;
 A5 01           bclr    R1, #5&lt;br /&gt;
 A6 01           bclr    R1, #6&lt;br /&gt;
 A7 01           bclr    R1, #7&lt;br /&gt;
 A8 01           bset    R1, #0&lt;br /&gt;
 A9 01           bset    R1, #1&lt;br /&gt;
 AA 01           bset    R1, #2&lt;br /&gt;
 AB 01           bset    R1, #3&lt;br /&gt;
 AC 01           bset    R1, #4&lt;br /&gt;
 AD 01           bset    R1, #5&lt;br /&gt;
 AE 01           bset    R1, #6&lt;br /&gt;
 AF 01           bset    R1, #7&lt;br /&gt;
 B0 01           mov     r0, R1&lt;br /&gt;
 B1 01           mov     r1, R1&lt;br /&gt;
 B2 01           mov     r2, R1&lt;br /&gt;
 B3 01           mov     r3, R1&lt;br /&gt;
 B4 01           mov     r4, R1&lt;br /&gt;
 B5 01           mov     r5, R1&lt;br /&gt;
 B6 01           mov     r6, R1&lt;br /&gt;
 B7 01           mov     r7, R1&lt;br /&gt;
 B8 01           mov     R1, r0&lt;br /&gt;
 B9 01           mov     R1, r1&lt;br /&gt;
 BA 01           mov     R1, r2&lt;br /&gt;
 BB 01           mov     R1, r3&lt;br /&gt;
 BC 01           mov     R1, r4&lt;br /&gt;
 BD 01           mov     R1, r5&lt;br /&gt;
 BE 01           mov     R1, r6&lt;br /&gt;
 BF 01           mov     R1, r7&lt;br /&gt;
 C0 94           mov     r0, #0x94&lt;br /&gt;
 C1 94           mov     r1, #0x94&lt;br /&gt;
 C2 94           mov     r2, #0x94&lt;br /&gt;
 C3 94           mov     r3, #0x94&lt;br /&gt;
 C4 94           mov     r4, #0x94&lt;br /&gt;
 C5 94           mov     r5, #0x94&lt;br /&gt;
 C6 94           mov     r6, #0x94&lt;br /&gt;
 C7 94           mov     r7, #0x94&lt;br /&gt;
 C8 94           mov     ie0, #0x94&lt;br /&gt;
 C9 94           mov     ie1, #0x94&lt;br /&gt;
 CA 94           mov     ir0, #0x94&lt;br /&gt;
 CB 94           mov     ir1, #0x94&lt;br /&gt;
 CC 94           mov     p0, #0x94&lt;br /&gt;
 CD 94           mov     p1, #0x94&lt;br /&gt;
 CE 94           mov     p2, #0x94&lt;br /&gt;
 CF 94           mov     p3, #0x94&lt;br /&gt;
 F0              stop&lt;br /&gt;
 F1              halt&lt;br /&gt;
 F8              ret&lt;br /&gt;
 F9              iret&lt;br /&gt;
 FA              clrc&lt;br /&gt;
 FB              comc&lt;br /&gt;
 FC              setc&lt;br /&gt;
 FD              ei&lt;br /&gt;
 FE              di&lt;br /&gt;
 FF              nop&lt;br /&gt;
 assemble() returned 0: OK&lt;br /&gt;
 Clean up...&lt;br /&gt;
&lt;br /&gt;
Note: The output binary has not been verified for accuracy.&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
As85 is a fairly simple assembler. It doesn't use any sort of 'compiler-compiler' for lexical analysis. In fact, its lexical analysis is very specific to the sm8521 MCU.&lt;br /&gt;
&lt;br /&gt;
The main loop (assemble() function, defined in [http://git.kodewerx.org/as85/src/09f8ba9f769d/src/asm.c?at=master#cl-315 asm.c]) does the input text parsing inline. (This should probably be moved out to a new source file.) After splitting a line into two pieces; op[0] containing the instruction, and op[1] containing its operands; a string comparison against op[0] is done over all supported instructions. If a match is found, the operands string is passed to a dynamically chosen function (from a [http://git.kodewerx.org/as85/src/09f8ba9f769d/src/inst.c?at=master#cl-156 function pointer table], indexed by the matched instruction). This function performs the lexical analysis required to decide which instruction we are trying to assemble.&lt;br /&gt;
&lt;br /&gt;
Since the sm8521 is a CISC machine, its instruction set contains a number of different ways to assemble the same instruction mnemonic. For example, several different addressing modes for the ''mov'' instruction are shown above in the test3.asm output. The lexical analysis is the voodoo which picks the proper addressing mode and byte codes by analyzing the operands.&lt;br /&gt;
&lt;br /&gt;
The lexical analyzing functions are defined in inst.c (following the function pointer table mentioned previously). The function handling the current instruction will test the operands string against a series of lexical patterns with the [http://git.kodewerx.org/as85/src/09f8ba9f769d/src/asm.c?at=master#cl-89 chk_pattern()] function (defined in asm.c, although this should probably be moved).&lt;br /&gt;
&lt;br /&gt;
chk_pattern() uses a scanf-like formatting string, rather than a regular expression, which is more common in lexical analysis. Documentation for the formatting string can be found in [http://git.kodewerx.org/as85/src/09f8ba9f769d/src/inst.h?at=master#cl-29 inst.h]. With just a few pattern primitives, any of the sm8521's addressing modes can be matched, with the matching primitives output as part of an array. It makes good use of the format scanners defined in [http://git.kodewerx.org/as85/src/09f8ba9f769d/src/scan.c?at=master scan.c].&lt;br /&gt;
&lt;br /&gt;
If chk_pattern() manages to find a match, the matching data may be further checked for validity on a per-context basis. Finally, the full instruction byte codes will be put together and returned to the assemble() loop. This is where the object code would be built. Currently the only thing that happens now is dumping the assembled instruction to stdout, in a debug build. [http://git.kodewerx.org/as85/src/09f8ba9f769d/src/asm.c?at=master#cl-464]&lt;br /&gt;
&lt;br /&gt;
===Optimization Concerns===&lt;br /&gt;
&lt;br /&gt;
Some optimization could be done within this lexical analysis process. The first improvement would be replacing the linear string comparison with a binary search tree. The second thing that would help in this immediate area would be replacing the string comparison itself with a hash comparison. The hash algorithm would have to be suitably small and fast enough to make much of a difference.&lt;br /&gt;
&lt;br /&gt;
The next big optimization would be rearranging the chk_pattern() calls within each lexical analyzer to check the most likely patterns first. The best way to choose the best order is static analysis of sm8521 source code, which is obviously in very short supply. Accurate disassemblies of commercial Game.com games would be helpful to this end, however.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=As85&amp;diff=2035</id>
		<title>As85</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=As85&amp;diff=2035"/>
				<updated>2012-12-30T05:14:59Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Usage */ Update source link to git&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;as85 is a simple assembler for the Sharp sm8521; the same microcontroller used in the Tiger Game.com. Game.com was released in 1998 and had only a few games ever made for it. It also has not had any homebrew games made for it. as85 is an attempt to build an assembler that will help hackers write homebrew code that will run on Game.com hardware.&lt;br /&gt;
&lt;br /&gt;
Documentation on the Game.com hardware is available at [http://gamecom.guruwork.de/ Game.commies].&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The source code is available at http://git.kodewerx.org/as85/src/&lt;br /&gt;
&lt;br /&gt;
==Current Progress==&lt;br /&gt;
&lt;br /&gt;
The current state of as85 is &amp;quot;almost usable, but not quite there yet.&amp;quot; A number of bugs exist which need to be fixed before it can be used as a development tool:&lt;br /&gt;
&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=2 Bug 2]: Add support for jump/call/branch instructions&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=3 Bug 3]: Output object code&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=4 Bug 4]: Write a linker&lt;br /&gt;
&lt;br /&gt;
I've also filed a bug about giving the project a better name [http://bugzilla.kodewerx.org/show_bug.cgi?id=5].&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
The program takes one argument; the file name of an sm8521 assembly file. The files in the [http://git.kodewerx.org/as85/src/09f8ba9f769d47fc2038e81d9cc5866d80f96748/examples?at=master /examples] directory are a good place to start.&lt;br /&gt;
&lt;br /&gt;
* test.asm is an example of what the beginning of a Game.com program might look like; it contains a header, and some [random] instructions to give you an idea.&lt;br /&gt;
* test2.asm is for testing the integrity of the parser with complex strings.&lt;br /&gt;
* test3.asm lists all possible sm8521 instructions; for verifying the output binary is correct.&lt;br /&gt;
&lt;br /&gt;
==Example Output==&lt;br /&gt;
&lt;br /&gt;
The following command:&lt;br /&gt;
 $ ./as85 ../examples/test3.asm&lt;br /&gt;
&lt;br /&gt;
Produces the following output:&lt;br /&gt;
 00 01           clr     R1&lt;br /&gt;
 01 01           neg     R1&lt;br /&gt;
 02 01           com     R1&lt;br /&gt;
 03 01           rr      R1&lt;br /&gt;
 04 01           rl      R1&lt;br /&gt;
 05 01           rrc     R1&lt;br /&gt;
 06 01           rlc     R1&lt;br /&gt;
 07 01           srl     R1&lt;br /&gt;
 08 01           inc     R1&lt;br /&gt;
 09 01           dec     R1&lt;br /&gt;
 0A 01           sra     R1&lt;br /&gt;
 0B 01           sll     R1&lt;br /&gt;
 0C 01           da      R1&lt;br /&gt;
 0D 01           swap    R1&lt;br /&gt;
 0E 01           push    R1&lt;br /&gt;
 0F 01           pop     R1&lt;br /&gt;
 10 0A           cmp     r1, r2&lt;br /&gt;
 11 0A           add     r1, r2&lt;br /&gt;
 12 0A           sub     r1, r2&lt;br /&gt;
 13 0A           adc     r1, r2&lt;br /&gt;
 14 0A           sbc     r1, r2&lt;br /&gt;
 15 0A           and     r1, r2&lt;br /&gt;
 16 0A           or      r1, r2&lt;br /&gt;
 17 0A           xor     r1, r2&lt;br /&gt;
 18 02           incw    RR2&lt;br /&gt;
 19 02           decw    RR2&lt;br /&gt;
 1A 08           clr     @r1&lt;br /&gt;
 1A 09           neg     @r1&lt;br /&gt;
 1A 0A           com     @r1&lt;br /&gt;
 1A 0B           rr      @r1&lt;br /&gt;
 1A 0C           rl      @r1&lt;br /&gt;
 1A 0D           rrc     @r1&lt;br /&gt;
 1A 0E           rlc     @r1&lt;br /&gt;
 1A 0F           srl     @r1&lt;br /&gt;
 1B 08           inc     @r1&lt;br /&gt;
 1B 09           dec     @r1&lt;br /&gt;
 1B 0A           sra     @r1&lt;br /&gt;
 1B 0B           sll     @r1&lt;br /&gt;
 1B 0C           da      @r1&lt;br /&gt;
 1B 0D           swap    @r1&lt;br /&gt;
 1B 0E           push    @r1&lt;br /&gt;
 1B 0F           pop     @r1&lt;br /&gt;
 1C 07 24        bclr    0xFF24, #7&lt;br /&gt;
 1C 0F 94        bclr    0x94(r1), #7&lt;br /&gt;
 1D 07 24        bset    0xFF24, #7&lt;br /&gt;
 1D 0F 94        bset    0x94(r1), #7&lt;br /&gt;
 1E 02           pushw   RR2&lt;br /&gt;
 1F 02           popw    RR2&lt;br /&gt;
 20 0A           cmp     r1, @r2&lt;br /&gt;
 20 4A           cmp     r1, (r2)+&lt;br /&gt;
 20 88 94        cmp     r1, @0x94&lt;br /&gt;
 20 8A 94        cmp     r1, 0x94(r2)&lt;br /&gt;
 20 CA           cmp     r1, -(r2)&lt;br /&gt;
 21 0A           add     r1, @r2&lt;br /&gt;
 21 4A           add     r1, (r2)+&lt;br /&gt;
 21 88 94        add     r1, @0x94&lt;br /&gt;
 21 8A 94        add     r1, 0x94(r2)&lt;br /&gt;
 21 CA           add     r1, -(r2)&lt;br /&gt;
 22 0A           sub     r1, @r2&lt;br /&gt;
 22 4A           sub     r1, (r2)+&lt;br /&gt;
 22 88 94        sub     r1, @0x94&lt;br /&gt;
 22 8A 94        sub     r1, 0x94(r2)&lt;br /&gt;
 22 CA           sub     r1, -(r2)&lt;br /&gt;
 23 0A           adc     r1, @r2&lt;br /&gt;
 23 4A           adc     r1, (r2)+&lt;br /&gt;
 23 88 94        adc     r1, @0x94&lt;br /&gt;
 23 8A 94        adc     r1, 0x94(r2)&lt;br /&gt;
 23 CA           adc     r1, -(r2)&lt;br /&gt;
 24 0A           sbc     r1, @r2&lt;br /&gt;
 24 4A           sbc     r1, (r2)+&lt;br /&gt;
 24 88 94        sbc     r1, @0x94&lt;br /&gt;
 24 8A 94        sbc     r1, 0x94(r2)&lt;br /&gt;
 24 CA           sbc     r1, -(r2)&lt;br /&gt;
 25 0A           and     r1, @r2&lt;br /&gt;
 25 4A           and     r1, (r2)+&lt;br /&gt;
 25 88 94        and     r1, @0x94&lt;br /&gt;
 25 8A 94        and     r1, 0x94(r2)&lt;br /&gt;
 25 CA           and     r1, -(r2)&lt;br /&gt;
 26 0A           or      r1, @r2&lt;br /&gt;
 26 4A           or      r1, (r2)+&lt;br /&gt;
 26 88 94        or      r1, @0x94&lt;br /&gt;
 26 8A 94        or      r1, 0x94(r2)&lt;br /&gt;
 26 CA           or      r1, -(r2)&lt;br /&gt;
 27 0A           xor     r1, @r2&lt;br /&gt;
 27 4A           xor     r1, (r2)+&lt;br /&gt;
 27 88 94        xor     r1, @0x94&lt;br /&gt;
 27 8A 94        xor     r1, 0x94(r2)&lt;br /&gt;
 27 CA           xor     r1, -(r2)&lt;br /&gt;
 28 0A           mov     r1, @r2&lt;br /&gt;
 28 4A           mov     r1, (r2)+&lt;br /&gt;
 28 88 94        mov     r1, @0x94&lt;br /&gt;
 28 8A 94        mov     r1, 0x94(r2)&lt;br /&gt;
 28 CA           mov     r1, -(r2)&lt;br /&gt;
 29 11           mov     @r1, r2&lt;br /&gt;
 29 51           mov     (r1)+, r2&lt;br /&gt;
 29 90 94        mov     @0x94, r2&lt;br /&gt;
 29 91 94        mov     0x94(r1), r2&lt;br /&gt;
 29 D1           mov     -(r1), r2&lt;br /&gt;
 2C 02           exts    RR2&lt;br /&gt;
 2E 94           mov     ps0, #0x94&lt;br /&gt;
 2F 94 01        btst    R1, #0x94&lt;br /&gt;
 30 09           cmp     r1, @rr2&lt;br /&gt;
 30 49           cmp     r1, (rr2)+&lt;br /&gt;
 30 88 24 94     cmp     r1, @0x9424&lt;br /&gt;
 30 89 24 94     cmp     r1, 0x9424(rr2)&lt;br /&gt;
 30 C9           cmp     r1, -(rr2)&lt;br /&gt;
 31 09           add     r1, @rr2&lt;br /&gt;
 31 49           add     r1, (rr2)+&lt;br /&gt;
 31 88 24 94     add     r1, @0x9424&lt;br /&gt;
 31 89 24 94     add     r1, 0x9424(rr2)&lt;br /&gt;
 31 C9           add     r1, -(rr2)&lt;br /&gt;
 32 09           sub     r1, @rr2&lt;br /&gt;
 32 49           sub     r1, (rr2)+&lt;br /&gt;
 32 88 24 94     sub     r1, @0x9424&lt;br /&gt;
 32 89 24 94     sub     r1, 0x9424(rr2)&lt;br /&gt;
 32 C9           sub     r1, -(rr2)&lt;br /&gt;
 33 09           adc     r1, @rr2&lt;br /&gt;
 33 49           adc     r1, (rr2)+&lt;br /&gt;
 33 88 24 94     adc     r1, @0x9424&lt;br /&gt;
 33 89 24 94     adc     r1, 0x9424(rr2)&lt;br /&gt;
 33 C9           adc     r1, -(rr2)&lt;br /&gt;
 34 09           sbc     r1, @rr2&lt;br /&gt;
 34 49           sbc     r1, (rr2)+&lt;br /&gt;
 34 88 24 94     sbc     r1, @0x9424&lt;br /&gt;
 34 89 24 94     sbc     r1, 0x9424(rr2)&lt;br /&gt;
 34 C9           sbc     r1, -(rr2)&lt;br /&gt;
 35 09           and     r1, @rr2&lt;br /&gt;
 35 49           and     r1, (rr2)+&lt;br /&gt;
 35 88 24 94     and     r1, @0x9424&lt;br /&gt;
 35 89 24 94     and     r1, 0x9424(rr2)&lt;br /&gt;
 35 C9           and     r1, -(rr2)&lt;br /&gt;
 36 09           or      r1, @rr2&lt;br /&gt;
 36 49           or      r1, (rr2)+&lt;br /&gt;
 36 88 24 94     or      r1, @0x9424&lt;br /&gt;
 36 89 24 94     or      r1, 0x9424(rr2)&lt;br /&gt;
 36 C9           or      r1, -(rr2)&lt;br /&gt;
 37 09           xor     r1, @rr2&lt;br /&gt;
 37 49           xor     r1, (rr2)+&lt;br /&gt;
 37 88 24 94     xor     r1, @0x9424&lt;br /&gt;
 37 89 24 94     xor     r1, 0x9424(rr2)&lt;br /&gt;
 37 C9           xor     r1, -(rr2)&lt;br /&gt;
 38 09           mov     r1, @rr2&lt;br /&gt;
 38 49           mov     r1, (rr2)+&lt;br /&gt;
 38 88 24 94     mov     r1, @0x9424&lt;br /&gt;
 38 89 24 94     mov     r1, 0x9424(rr2)&lt;br /&gt;
 38 C9           mov     r1, -(rr2)&lt;br /&gt;
 39 21           mov     @rr2, r4&lt;br /&gt;
 39 61           mov     (rr2)+, r4&lt;br /&gt;
 39 A0 24 94     mov     @0x9424, r4&lt;br /&gt;
 39 A1 24 94     mov     0x9424(rr2), r4&lt;br /&gt;
 39 E1           mov     -(rr2), r4&lt;br /&gt;
 3A 14           movw    rr2, @rr4&lt;br /&gt;
 3A 54           movw    rr2, (rr4)+&lt;br /&gt;
 3A 90 24 94     movw    rr2, @0x9424&lt;br /&gt;
 3A 94 24 94     movw    rr2, 0x9424(rr4)&lt;br /&gt;
 3A D4           movw    rr2, -(rr4)&lt;br /&gt;
 3B 22           movw    @rr2, rr4&lt;br /&gt;
 3B 62           movw    (rr2)+, rr4&lt;br /&gt;
 3B A0 24 94     movw    @0x9424, rr4&lt;br /&gt;
 3B A2 24 94     movw    0x9424(rr2), rr4&lt;br /&gt;
 3B E2           movw    -(rr2), rr4&lt;br /&gt;
 3C 14           movw    rr2, rr4&lt;br /&gt;
 40 02 01        cmp     R1, R2&lt;br /&gt;
 41 02 01        add     R1, R2&lt;br /&gt;
 42 02 01        sub     R1, R2&lt;br /&gt;
 43 02 01        adc     R1, R2&lt;br /&gt;
 44 02 01        sbc     R1, R2&lt;br /&gt;
 45 02 01        and     R1, R2&lt;br /&gt;
 46 02 01        or      R1, R2&lt;br /&gt;
 47 02 01        xor     R1, R2&lt;br /&gt;
 48 02 01        mov     R1, R2&lt;br /&gt;
 4A 04 02        movw    RR2, RR4&lt;br /&gt;
 4B 02 24 94     movw    RR2, #0x9424&lt;br /&gt;
 4C 04 02        mult    RR2, R4&lt;br /&gt;
 4D 94 02        mult    RR2, #0x94&lt;br /&gt;
 4E 07 01        bmov    bf, R1, #7&lt;br /&gt;
 4E 47 01        bmov    R1, #7, bf&lt;br /&gt;
 4F 07 01        bcmp    bf, R1, #7&lt;br /&gt;
 4F 47 01        band    bf, R1, #7&lt;br /&gt;
 4F 87 01        bor     bf, R1, #7&lt;br /&gt;
 4F C7 01        bxor    bf, R1, #7&lt;br /&gt;
 50 94 01        cmp     R1, #0x94&lt;br /&gt;
 51 94 01        add     R1, #0x94&lt;br /&gt;
 52 94 01        sub     R1, #0x94&lt;br /&gt;
 53 94 01        adc     R1, #0x94&lt;br /&gt;
 54 94 01        sbc     R1, #0x94&lt;br /&gt;
 55 94 01        and     R1, #0x94&lt;br /&gt;
 56 94 01        or      R1, #0x94&lt;br /&gt;
 57 94 01        xor     R1, #0x94&lt;br /&gt;
 58 94 01        mov     R1, #0x94&lt;br /&gt;
 5C 04 02        div     RR2, RR4&lt;br /&gt;
 5D 94 02        div     RR2, #0x94&lt;br /&gt;
 5E 01 94 02     movm    R1, #0x94, R2&lt;br /&gt;
 5F 01 94 24     movm    R1, #0x94, #0x24&lt;br /&gt;
 60 04 02        cmpw    RR2, RR4&lt;br /&gt;
 61 04 02        addw    RR2, RR4&lt;br /&gt;
 62 04 02        subw    RR2, RR4&lt;br /&gt;
 63 04 02        adcw    RR2, RR4&lt;br /&gt;
 64 04 02        sbcw    RR2, RR4&lt;br /&gt;
 65 04 02        andw    RR2, RR4&lt;br /&gt;
 66 04 02        orw     RR2, RR4&lt;br /&gt;
 67 04 02        xorw    RR2, RR4&lt;br /&gt;
 68 02 24 94     cmpw    RR2, #0x9424&lt;br /&gt;
 69 02 24 94     addw    RR2, #0x9424&lt;br /&gt;
 6A 02 24 94     subw    RR2, #0x9424&lt;br /&gt;
 6B 02 24 94     adcw    RR2, #0x9424&lt;br /&gt;
 6C 02 24 94     sbcw    RR2, #0x9424&lt;br /&gt;
 6D 02 24 94     andw    RR2, #0x9424&lt;br /&gt;
 6E 02 24 94     orw     RR2, #0x9424&lt;br /&gt;
 6F 02 24 94     xorw    RR2, #0x9424&lt;br /&gt;
 78 24 94        movw    rr0, #0x9424&lt;br /&gt;
 79 24 94        movw    rr8, #0x9424&lt;br /&gt;
 7A 24 94        movw    rr2, #0x9424&lt;br /&gt;
 7B 24 94        movw    rr10, #0x9424&lt;br /&gt;
 7C 24 94        movw    rr4, #0x9424&lt;br /&gt;
 7D 24 94        movw    rr12, #0x9424&lt;br /&gt;
 7E 24 94        movw    rr6, #0x9424&lt;br /&gt;
 7F 24 94        movw    rr14, #0x9424&lt;br /&gt;
 A0 01           bclr    R1, #0&lt;br /&gt;
 A1 01           bclr    R1, #1&lt;br /&gt;
 A2 01           bclr    R1, #2&lt;br /&gt;
 A3 01           bclr    R1, #3&lt;br /&gt;
 A4 01           bclr    R1, #4&lt;br /&gt;
 A5 01           bclr    R1, #5&lt;br /&gt;
 A6 01           bclr    R1, #6&lt;br /&gt;
 A7 01           bclr    R1, #7&lt;br /&gt;
 A8 01           bset    R1, #0&lt;br /&gt;
 A9 01           bset    R1, #1&lt;br /&gt;
 AA 01           bset    R1, #2&lt;br /&gt;
 AB 01           bset    R1, #3&lt;br /&gt;
 AC 01           bset    R1, #4&lt;br /&gt;
 AD 01           bset    R1, #5&lt;br /&gt;
 AE 01           bset    R1, #6&lt;br /&gt;
 AF 01           bset    R1, #7&lt;br /&gt;
 B0 01           mov     r0, R1&lt;br /&gt;
 B1 01           mov     r1, R1&lt;br /&gt;
 B2 01           mov     r2, R1&lt;br /&gt;
 B3 01           mov     r3, R1&lt;br /&gt;
 B4 01           mov     r4, R1&lt;br /&gt;
 B5 01           mov     r5, R1&lt;br /&gt;
 B6 01           mov     r6, R1&lt;br /&gt;
 B7 01           mov     r7, R1&lt;br /&gt;
 B8 01           mov     R1, r0&lt;br /&gt;
 B9 01           mov     R1, r1&lt;br /&gt;
 BA 01           mov     R1, r2&lt;br /&gt;
 BB 01           mov     R1, r3&lt;br /&gt;
 BC 01           mov     R1, r4&lt;br /&gt;
 BD 01           mov     R1, r5&lt;br /&gt;
 BE 01           mov     R1, r6&lt;br /&gt;
 BF 01           mov     R1, r7&lt;br /&gt;
 C0 94           mov     r0, #0x94&lt;br /&gt;
 C1 94           mov     r1, #0x94&lt;br /&gt;
 C2 94           mov     r2, #0x94&lt;br /&gt;
 C3 94           mov     r3, #0x94&lt;br /&gt;
 C4 94           mov     r4, #0x94&lt;br /&gt;
 C5 94           mov     r5, #0x94&lt;br /&gt;
 C6 94           mov     r6, #0x94&lt;br /&gt;
 C7 94           mov     r7, #0x94&lt;br /&gt;
 C8 94           mov     ie0, #0x94&lt;br /&gt;
 C9 94           mov     ie1, #0x94&lt;br /&gt;
 CA 94           mov     ir0, #0x94&lt;br /&gt;
 CB 94           mov     ir1, #0x94&lt;br /&gt;
 CC 94           mov     p0, #0x94&lt;br /&gt;
 CD 94           mov     p1, #0x94&lt;br /&gt;
 CE 94           mov     p2, #0x94&lt;br /&gt;
 CF 94           mov     p3, #0x94&lt;br /&gt;
 F0              stop&lt;br /&gt;
 F1              halt&lt;br /&gt;
 F8              ret&lt;br /&gt;
 F9              iret&lt;br /&gt;
 FA              clrc&lt;br /&gt;
 FB              comc&lt;br /&gt;
 FC              setc&lt;br /&gt;
 FD              ei&lt;br /&gt;
 FE              di&lt;br /&gt;
 FF              nop&lt;br /&gt;
 assemble() returned 0: OK&lt;br /&gt;
 Clean up...&lt;br /&gt;
&lt;br /&gt;
Note: The output binary has not been verified for accuracy.&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
As85 is a fairly simple assembler. It doesn't use any sort of 'compiler-compiler' for lexical analysis. In fact, its lexical analysis is very specific to the sm8521 MCU.&lt;br /&gt;
&lt;br /&gt;
The main loop (assemble() function, defined in [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/asm.c?at=default#cl-315 asm.c]) does the input text parsing inline. (This should probably be moved out to a new source file.) After splitting a line into two pieces; op[0] containing the instruction, and op[1] containing its operands; a string comparison against op[0] is done over all supported instructions. If a match is found, the operands string is passed to a dynamically chosen function (from a [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/inst.c?at=default#cl-156 function pointer table], indexed by the matched instruction). This function performs the lexical analysis required to decide which instruction we are trying to assemble.&lt;br /&gt;
&lt;br /&gt;
Since the sm8521 is a CISC machine, its instruction set contains a number of different ways to assemble the same instruction mnemonic. For example, several different addressing modes for the ''mov'' instruction are shown above in the test3.asm output. The lexical analysis is the voodoo which picks the proper addressing mode and byte codes by analyzing the operands.&lt;br /&gt;
&lt;br /&gt;
The lexical analyzing functions are defined in inst.c (following the function pointer table mentioned previously). The function handling the current instruction will test the operands string against a series of lexical patterns with the [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/asm.c?at=default#cl-89 chk_pattern()] function (defined in asm.c, although this should probably be moved).&lt;br /&gt;
&lt;br /&gt;
chk_pattern() uses a scanf-like formatting string, rather than a regular expression, which is more common in lexical analysis. Documentation for the formatting string can be found in [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/inst.h?at=default#cl-29 inst.h]. With just a few pattern primitives, any of the sm8521's addressing modes can be matched, with the matching primitives output as part of an array. It makes good use of the format scanners defined in [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/scan.c?at=default scan.c].&lt;br /&gt;
&lt;br /&gt;
If chk_pattern() manages to find a match, the matching data may be further checked for validity on a per-context basis. Finally, the full instruction byte codes will be put together and returned to the assemble() loop. This is where the object code would be built. Currently the only thing that happens now is dumping the assembled instruction to stdout, in a debug build. [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/asm.c?at=default#cl-464]&lt;br /&gt;
&lt;br /&gt;
===Optimization Concerns===&lt;br /&gt;
&lt;br /&gt;
Some optimization could be done within this lexical analysis process. The first improvement would be replacing the linear string comparison with a binary search tree. The second thing that would help in this immediate area would be replacing the string comparison itself with a hash comparison. The hash algorithm would have to be suitably small and fast enough to make much of a difference.&lt;br /&gt;
&lt;br /&gt;
The next big optimization would be rearranging the chk_pattern() calls within each lexical analyzer to check the most likely patterns first. The best way to choose the best order is static analysis of sm8521 source code, which is obviously in very short supply. Accurate disassemblies of commercial Game.com games would be helpful to this end, however.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=As85&amp;diff=2034</id>
		<title>As85</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=As85&amp;diff=2034"/>
				<updated>2012-12-30T04:13:23Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Development */ Update source links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;as85 is a simple assembler for the Sharp sm8521; the same microcontroller used in the Tiger Game.com. Game.com was released in 1998 and had only a few games ever made for it. It also has not had any homebrew games made for it. as85 is an attempt to build an assembler that will help hackers write homebrew code that will run on Game.com hardware.&lt;br /&gt;
&lt;br /&gt;
Documentation on the Game.com hardware is available at [http://gamecom.guruwork.de/ Game.commies].&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The source code is available at http://git.kodewerx.org/as85/src/&lt;br /&gt;
&lt;br /&gt;
==Current Progress==&lt;br /&gt;
&lt;br /&gt;
The current state of as85 is &amp;quot;almost usable, but not quite there yet.&amp;quot; A number of bugs exist which need to be fixed before it can be used as a development tool:&lt;br /&gt;
&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=2 Bug 2]: Add support for jump/call/branch instructions&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=3 Bug 3]: Output object code&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=4 Bug 4]: Write a linker&lt;br /&gt;
&lt;br /&gt;
I've also filed a bug about giving the project a better name [http://bugzilla.kodewerx.org/show_bug.cgi?id=5].&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
The program takes one argument; the file name of an sm8521 assembly file. The files in the [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/examples?at=default /examples] directory are a good place to start.&lt;br /&gt;
&lt;br /&gt;
* test.asm is an example of what the beginning of a Game.com program might look like; it contains a header, and some [random] instructions to give you an idea.&lt;br /&gt;
* test2.asm is for testing the integrity of the parser with complex strings.&lt;br /&gt;
* test3.asm lists all possible sm8521 instructions; for verifying the output binary is correct.&lt;br /&gt;
&lt;br /&gt;
==Example Output==&lt;br /&gt;
&lt;br /&gt;
The following command:&lt;br /&gt;
 $ ./as85 ../examples/test3.asm&lt;br /&gt;
&lt;br /&gt;
Produces the following output:&lt;br /&gt;
 00 01           clr     R1&lt;br /&gt;
 01 01           neg     R1&lt;br /&gt;
 02 01           com     R1&lt;br /&gt;
 03 01           rr      R1&lt;br /&gt;
 04 01           rl      R1&lt;br /&gt;
 05 01           rrc     R1&lt;br /&gt;
 06 01           rlc     R1&lt;br /&gt;
 07 01           srl     R1&lt;br /&gt;
 08 01           inc     R1&lt;br /&gt;
 09 01           dec     R1&lt;br /&gt;
 0A 01           sra     R1&lt;br /&gt;
 0B 01           sll     R1&lt;br /&gt;
 0C 01           da      R1&lt;br /&gt;
 0D 01           swap    R1&lt;br /&gt;
 0E 01           push    R1&lt;br /&gt;
 0F 01           pop     R1&lt;br /&gt;
 10 0A           cmp     r1, r2&lt;br /&gt;
 11 0A           add     r1, r2&lt;br /&gt;
 12 0A           sub     r1, r2&lt;br /&gt;
 13 0A           adc     r1, r2&lt;br /&gt;
 14 0A           sbc     r1, r2&lt;br /&gt;
 15 0A           and     r1, r2&lt;br /&gt;
 16 0A           or      r1, r2&lt;br /&gt;
 17 0A           xor     r1, r2&lt;br /&gt;
 18 02           incw    RR2&lt;br /&gt;
 19 02           decw    RR2&lt;br /&gt;
 1A 08           clr     @r1&lt;br /&gt;
 1A 09           neg     @r1&lt;br /&gt;
 1A 0A           com     @r1&lt;br /&gt;
 1A 0B           rr      @r1&lt;br /&gt;
 1A 0C           rl      @r1&lt;br /&gt;
 1A 0D           rrc     @r1&lt;br /&gt;
 1A 0E           rlc     @r1&lt;br /&gt;
 1A 0F           srl     @r1&lt;br /&gt;
 1B 08           inc     @r1&lt;br /&gt;
 1B 09           dec     @r1&lt;br /&gt;
 1B 0A           sra     @r1&lt;br /&gt;
 1B 0B           sll     @r1&lt;br /&gt;
 1B 0C           da      @r1&lt;br /&gt;
 1B 0D           swap    @r1&lt;br /&gt;
 1B 0E           push    @r1&lt;br /&gt;
 1B 0F           pop     @r1&lt;br /&gt;
 1C 07 24        bclr    0xFF24, #7&lt;br /&gt;
 1C 0F 94        bclr    0x94(r1), #7&lt;br /&gt;
 1D 07 24        bset    0xFF24, #7&lt;br /&gt;
 1D 0F 94        bset    0x94(r1), #7&lt;br /&gt;
 1E 02           pushw   RR2&lt;br /&gt;
 1F 02           popw    RR2&lt;br /&gt;
 20 0A           cmp     r1, @r2&lt;br /&gt;
 20 4A           cmp     r1, (r2)+&lt;br /&gt;
 20 88 94        cmp     r1, @0x94&lt;br /&gt;
 20 8A 94        cmp     r1, 0x94(r2)&lt;br /&gt;
 20 CA           cmp     r1, -(r2)&lt;br /&gt;
 21 0A           add     r1, @r2&lt;br /&gt;
 21 4A           add     r1, (r2)+&lt;br /&gt;
 21 88 94        add     r1, @0x94&lt;br /&gt;
 21 8A 94        add     r1, 0x94(r2)&lt;br /&gt;
 21 CA           add     r1, -(r2)&lt;br /&gt;
 22 0A           sub     r1, @r2&lt;br /&gt;
 22 4A           sub     r1, (r2)+&lt;br /&gt;
 22 88 94        sub     r1, @0x94&lt;br /&gt;
 22 8A 94        sub     r1, 0x94(r2)&lt;br /&gt;
 22 CA           sub     r1, -(r2)&lt;br /&gt;
 23 0A           adc     r1, @r2&lt;br /&gt;
 23 4A           adc     r1, (r2)+&lt;br /&gt;
 23 88 94        adc     r1, @0x94&lt;br /&gt;
 23 8A 94        adc     r1, 0x94(r2)&lt;br /&gt;
 23 CA           adc     r1, -(r2)&lt;br /&gt;
 24 0A           sbc     r1, @r2&lt;br /&gt;
 24 4A           sbc     r1, (r2)+&lt;br /&gt;
 24 88 94        sbc     r1, @0x94&lt;br /&gt;
 24 8A 94        sbc     r1, 0x94(r2)&lt;br /&gt;
 24 CA           sbc     r1, -(r2)&lt;br /&gt;
 25 0A           and     r1, @r2&lt;br /&gt;
 25 4A           and     r1, (r2)+&lt;br /&gt;
 25 88 94        and     r1, @0x94&lt;br /&gt;
 25 8A 94        and     r1, 0x94(r2)&lt;br /&gt;
 25 CA           and     r1, -(r2)&lt;br /&gt;
 26 0A           or      r1, @r2&lt;br /&gt;
 26 4A           or      r1, (r2)+&lt;br /&gt;
 26 88 94        or      r1, @0x94&lt;br /&gt;
 26 8A 94        or      r1, 0x94(r2)&lt;br /&gt;
 26 CA           or      r1, -(r2)&lt;br /&gt;
 27 0A           xor     r1, @r2&lt;br /&gt;
 27 4A           xor     r1, (r2)+&lt;br /&gt;
 27 88 94        xor     r1, @0x94&lt;br /&gt;
 27 8A 94        xor     r1, 0x94(r2)&lt;br /&gt;
 27 CA           xor     r1, -(r2)&lt;br /&gt;
 28 0A           mov     r1, @r2&lt;br /&gt;
 28 4A           mov     r1, (r2)+&lt;br /&gt;
 28 88 94        mov     r1, @0x94&lt;br /&gt;
 28 8A 94        mov     r1, 0x94(r2)&lt;br /&gt;
 28 CA           mov     r1, -(r2)&lt;br /&gt;
 29 11           mov     @r1, r2&lt;br /&gt;
 29 51           mov     (r1)+, r2&lt;br /&gt;
 29 90 94        mov     @0x94, r2&lt;br /&gt;
 29 91 94        mov     0x94(r1), r2&lt;br /&gt;
 29 D1           mov     -(r1), r2&lt;br /&gt;
 2C 02           exts    RR2&lt;br /&gt;
 2E 94           mov     ps0, #0x94&lt;br /&gt;
 2F 94 01        btst    R1, #0x94&lt;br /&gt;
 30 09           cmp     r1, @rr2&lt;br /&gt;
 30 49           cmp     r1, (rr2)+&lt;br /&gt;
 30 88 24 94     cmp     r1, @0x9424&lt;br /&gt;
 30 89 24 94     cmp     r1, 0x9424(rr2)&lt;br /&gt;
 30 C9           cmp     r1, -(rr2)&lt;br /&gt;
 31 09           add     r1, @rr2&lt;br /&gt;
 31 49           add     r1, (rr2)+&lt;br /&gt;
 31 88 24 94     add     r1, @0x9424&lt;br /&gt;
 31 89 24 94     add     r1, 0x9424(rr2)&lt;br /&gt;
 31 C9           add     r1, -(rr2)&lt;br /&gt;
 32 09           sub     r1, @rr2&lt;br /&gt;
 32 49           sub     r1, (rr2)+&lt;br /&gt;
 32 88 24 94     sub     r1, @0x9424&lt;br /&gt;
 32 89 24 94     sub     r1, 0x9424(rr2)&lt;br /&gt;
 32 C9           sub     r1, -(rr2)&lt;br /&gt;
 33 09           adc     r1, @rr2&lt;br /&gt;
 33 49           adc     r1, (rr2)+&lt;br /&gt;
 33 88 24 94     adc     r1, @0x9424&lt;br /&gt;
 33 89 24 94     adc     r1, 0x9424(rr2)&lt;br /&gt;
 33 C9           adc     r1, -(rr2)&lt;br /&gt;
 34 09           sbc     r1, @rr2&lt;br /&gt;
 34 49           sbc     r1, (rr2)+&lt;br /&gt;
 34 88 24 94     sbc     r1, @0x9424&lt;br /&gt;
 34 89 24 94     sbc     r1, 0x9424(rr2)&lt;br /&gt;
 34 C9           sbc     r1, -(rr2)&lt;br /&gt;
 35 09           and     r1, @rr2&lt;br /&gt;
 35 49           and     r1, (rr2)+&lt;br /&gt;
 35 88 24 94     and     r1, @0x9424&lt;br /&gt;
 35 89 24 94     and     r1, 0x9424(rr2)&lt;br /&gt;
 35 C9           and     r1, -(rr2)&lt;br /&gt;
 36 09           or      r1, @rr2&lt;br /&gt;
 36 49           or      r1, (rr2)+&lt;br /&gt;
 36 88 24 94     or      r1, @0x9424&lt;br /&gt;
 36 89 24 94     or      r1, 0x9424(rr2)&lt;br /&gt;
 36 C9           or      r1, -(rr2)&lt;br /&gt;
 37 09           xor     r1, @rr2&lt;br /&gt;
 37 49           xor     r1, (rr2)+&lt;br /&gt;
 37 88 24 94     xor     r1, @0x9424&lt;br /&gt;
 37 89 24 94     xor     r1, 0x9424(rr2)&lt;br /&gt;
 37 C9           xor     r1, -(rr2)&lt;br /&gt;
 38 09           mov     r1, @rr2&lt;br /&gt;
 38 49           mov     r1, (rr2)+&lt;br /&gt;
 38 88 24 94     mov     r1, @0x9424&lt;br /&gt;
 38 89 24 94     mov     r1, 0x9424(rr2)&lt;br /&gt;
 38 C9           mov     r1, -(rr2)&lt;br /&gt;
 39 21           mov     @rr2, r4&lt;br /&gt;
 39 61           mov     (rr2)+, r4&lt;br /&gt;
 39 A0 24 94     mov     @0x9424, r4&lt;br /&gt;
 39 A1 24 94     mov     0x9424(rr2), r4&lt;br /&gt;
 39 E1           mov     -(rr2), r4&lt;br /&gt;
 3A 14           movw    rr2, @rr4&lt;br /&gt;
 3A 54           movw    rr2, (rr4)+&lt;br /&gt;
 3A 90 24 94     movw    rr2, @0x9424&lt;br /&gt;
 3A 94 24 94     movw    rr2, 0x9424(rr4)&lt;br /&gt;
 3A D4           movw    rr2, -(rr4)&lt;br /&gt;
 3B 22           movw    @rr2, rr4&lt;br /&gt;
 3B 62           movw    (rr2)+, rr4&lt;br /&gt;
 3B A0 24 94     movw    @0x9424, rr4&lt;br /&gt;
 3B A2 24 94     movw    0x9424(rr2), rr4&lt;br /&gt;
 3B E2           movw    -(rr2), rr4&lt;br /&gt;
 3C 14           movw    rr2, rr4&lt;br /&gt;
 40 02 01        cmp     R1, R2&lt;br /&gt;
 41 02 01        add     R1, R2&lt;br /&gt;
 42 02 01        sub     R1, R2&lt;br /&gt;
 43 02 01        adc     R1, R2&lt;br /&gt;
 44 02 01        sbc     R1, R2&lt;br /&gt;
 45 02 01        and     R1, R2&lt;br /&gt;
 46 02 01        or      R1, R2&lt;br /&gt;
 47 02 01        xor     R1, R2&lt;br /&gt;
 48 02 01        mov     R1, R2&lt;br /&gt;
 4A 04 02        movw    RR2, RR4&lt;br /&gt;
 4B 02 24 94     movw    RR2, #0x9424&lt;br /&gt;
 4C 04 02        mult    RR2, R4&lt;br /&gt;
 4D 94 02        mult    RR2, #0x94&lt;br /&gt;
 4E 07 01        bmov    bf, R1, #7&lt;br /&gt;
 4E 47 01        bmov    R1, #7, bf&lt;br /&gt;
 4F 07 01        bcmp    bf, R1, #7&lt;br /&gt;
 4F 47 01        band    bf, R1, #7&lt;br /&gt;
 4F 87 01        bor     bf, R1, #7&lt;br /&gt;
 4F C7 01        bxor    bf, R1, #7&lt;br /&gt;
 50 94 01        cmp     R1, #0x94&lt;br /&gt;
 51 94 01        add     R1, #0x94&lt;br /&gt;
 52 94 01        sub     R1, #0x94&lt;br /&gt;
 53 94 01        adc     R1, #0x94&lt;br /&gt;
 54 94 01        sbc     R1, #0x94&lt;br /&gt;
 55 94 01        and     R1, #0x94&lt;br /&gt;
 56 94 01        or      R1, #0x94&lt;br /&gt;
 57 94 01        xor     R1, #0x94&lt;br /&gt;
 58 94 01        mov     R1, #0x94&lt;br /&gt;
 5C 04 02        div     RR2, RR4&lt;br /&gt;
 5D 94 02        div     RR2, #0x94&lt;br /&gt;
 5E 01 94 02     movm    R1, #0x94, R2&lt;br /&gt;
 5F 01 94 24     movm    R1, #0x94, #0x24&lt;br /&gt;
 60 04 02        cmpw    RR2, RR4&lt;br /&gt;
 61 04 02        addw    RR2, RR4&lt;br /&gt;
 62 04 02        subw    RR2, RR4&lt;br /&gt;
 63 04 02        adcw    RR2, RR4&lt;br /&gt;
 64 04 02        sbcw    RR2, RR4&lt;br /&gt;
 65 04 02        andw    RR2, RR4&lt;br /&gt;
 66 04 02        orw     RR2, RR4&lt;br /&gt;
 67 04 02        xorw    RR2, RR4&lt;br /&gt;
 68 02 24 94     cmpw    RR2, #0x9424&lt;br /&gt;
 69 02 24 94     addw    RR2, #0x9424&lt;br /&gt;
 6A 02 24 94     subw    RR2, #0x9424&lt;br /&gt;
 6B 02 24 94     adcw    RR2, #0x9424&lt;br /&gt;
 6C 02 24 94     sbcw    RR2, #0x9424&lt;br /&gt;
 6D 02 24 94     andw    RR2, #0x9424&lt;br /&gt;
 6E 02 24 94     orw     RR2, #0x9424&lt;br /&gt;
 6F 02 24 94     xorw    RR2, #0x9424&lt;br /&gt;
 78 24 94        movw    rr0, #0x9424&lt;br /&gt;
 79 24 94        movw    rr8, #0x9424&lt;br /&gt;
 7A 24 94        movw    rr2, #0x9424&lt;br /&gt;
 7B 24 94        movw    rr10, #0x9424&lt;br /&gt;
 7C 24 94        movw    rr4, #0x9424&lt;br /&gt;
 7D 24 94        movw    rr12, #0x9424&lt;br /&gt;
 7E 24 94        movw    rr6, #0x9424&lt;br /&gt;
 7F 24 94        movw    rr14, #0x9424&lt;br /&gt;
 A0 01           bclr    R1, #0&lt;br /&gt;
 A1 01           bclr    R1, #1&lt;br /&gt;
 A2 01           bclr    R1, #2&lt;br /&gt;
 A3 01           bclr    R1, #3&lt;br /&gt;
 A4 01           bclr    R1, #4&lt;br /&gt;
 A5 01           bclr    R1, #5&lt;br /&gt;
 A6 01           bclr    R1, #6&lt;br /&gt;
 A7 01           bclr    R1, #7&lt;br /&gt;
 A8 01           bset    R1, #0&lt;br /&gt;
 A9 01           bset    R1, #1&lt;br /&gt;
 AA 01           bset    R1, #2&lt;br /&gt;
 AB 01           bset    R1, #3&lt;br /&gt;
 AC 01           bset    R1, #4&lt;br /&gt;
 AD 01           bset    R1, #5&lt;br /&gt;
 AE 01           bset    R1, #6&lt;br /&gt;
 AF 01           bset    R1, #7&lt;br /&gt;
 B0 01           mov     r0, R1&lt;br /&gt;
 B1 01           mov     r1, R1&lt;br /&gt;
 B2 01           mov     r2, R1&lt;br /&gt;
 B3 01           mov     r3, R1&lt;br /&gt;
 B4 01           mov     r4, R1&lt;br /&gt;
 B5 01           mov     r5, R1&lt;br /&gt;
 B6 01           mov     r6, R1&lt;br /&gt;
 B7 01           mov     r7, R1&lt;br /&gt;
 B8 01           mov     R1, r0&lt;br /&gt;
 B9 01           mov     R1, r1&lt;br /&gt;
 BA 01           mov     R1, r2&lt;br /&gt;
 BB 01           mov     R1, r3&lt;br /&gt;
 BC 01           mov     R1, r4&lt;br /&gt;
 BD 01           mov     R1, r5&lt;br /&gt;
 BE 01           mov     R1, r6&lt;br /&gt;
 BF 01           mov     R1, r7&lt;br /&gt;
 C0 94           mov     r0, #0x94&lt;br /&gt;
 C1 94           mov     r1, #0x94&lt;br /&gt;
 C2 94           mov     r2, #0x94&lt;br /&gt;
 C3 94           mov     r3, #0x94&lt;br /&gt;
 C4 94           mov     r4, #0x94&lt;br /&gt;
 C5 94           mov     r5, #0x94&lt;br /&gt;
 C6 94           mov     r6, #0x94&lt;br /&gt;
 C7 94           mov     r7, #0x94&lt;br /&gt;
 C8 94           mov     ie0, #0x94&lt;br /&gt;
 C9 94           mov     ie1, #0x94&lt;br /&gt;
 CA 94           mov     ir0, #0x94&lt;br /&gt;
 CB 94           mov     ir1, #0x94&lt;br /&gt;
 CC 94           mov     p0, #0x94&lt;br /&gt;
 CD 94           mov     p1, #0x94&lt;br /&gt;
 CE 94           mov     p2, #0x94&lt;br /&gt;
 CF 94           mov     p3, #0x94&lt;br /&gt;
 F0              stop&lt;br /&gt;
 F1              halt&lt;br /&gt;
 F8              ret&lt;br /&gt;
 F9              iret&lt;br /&gt;
 FA              clrc&lt;br /&gt;
 FB              comc&lt;br /&gt;
 FC              setc&lt;br /&gt;
 FD              ei&lt;br /&gt;
 FE              di&lt;br /&gt;
 FF              nop&lt;br /&gt;
 assemble() returned 0: OK&lt;br /&gt;
 Clean up...&lt;br /&gt;
&lt;br /&gt;
Note: The output binary has not been verified for accuracy.&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
As85 is a fairly simple assembler. It doesn't use any sort of 'compiler-compiler' for lexical analysis. In fact, its lexical analysis is very specific to the sm8521 MCU.&lt;br /&gt;
&lt;br /&gt;
The main loop (assemble() function, defined in [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/asm.c?at=default#cl-315 asm.c]) does the input text parsing inline. (This should probably be moved out to a new source file.) After splitting a line into two pieces; op[0] containing the instruction, and op[1] containing its operands; a string comparison against op[0] is done over all supported instructions. If a match is found, the operands string is passed to a dynamically chosen function (from a [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/inst.c?at=default#cl-156 function pointer table], indexed by the matched instruction). This function performs the lexical analysis required to decide which instruction we are trying to assemble.&lt;br /&gt;
&lt;br /&gt;
Since the sm8521 is a CISC machine, its instruction set contains a number of different ways to assemble the same instruction mnemonic. For example, several different addressing modes for the ''mov'' instruction are shown above in the test3.asm output. The lexical analysis is the voodoo which picks the proper addressing mode and byte codes by analyzing the operands.&lt;br /&gt;
&lt;br /&gt;
The lexical analyzing functions are defined in inst.c (following the function pointer table mentioned previously). The function handling the current instruction will test the operands string against a series of lexical patterns with the [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/asm.c?at=default#cl-89 chk_pattern()] function (defined in asm.c, although this should probably be moved).&lt;br /&gt;
&lt;br /&gt;
chk_pattern() uses a scanf-like formatting string, rather than a regular expression, which is more common in lexical analysis. Documentation for the formatting string can be found in [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/inst.h?at=default#cl-29 inst.h]. With just a few pattern primitives, any of the sm8521's addressing modes can be matched, with the matching primitives output as part of an array. It makes good use of the format scanners defined in [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/scan.c?at=default scan.c].&lt;br /&gt;
&lt;br /&gt;
If chk_pattern() manages to find a match, the matching data may be further checked for validity on a per-context basis. Finally, the full instruction byte codes will be put together and returned to the assemble() loop. This is where the object code would be built. Currently the only thing that happens now is dumping the assembled instruction to stdout, in a debug build. [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/src/asm.c?at=default#cl-464]&lt;br /&gt;
&lt;br /&gt;
===Optimization Concerns===&lt;br /&gt;
&lt;br /&gt;
Some optimization could be done within this lexical analysis process. The first improvement would be replacing the linear string comparison with a binary search tree. The second thing that would help in this immediate area would be replacing the string comparison itself with a hash comparison. The hash algorithm would have to be suitably small and fast enough to make much of a difference.&lt;br /&gt;
&lt;br /&gt;
The next big optimization would be rearranging the chk_pattern() calls within each lexical analyzer to check the most likely patterns first. The best way to choose the best order is static analysis of sm8521 source code, which is obviously in very short supply. Accurate disassemblies of commercial Game.com games would be helpful to this end, however.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=As85&amp;diff=2033</id>
		<title>As85</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=As85&amp;diff=2033"/>
				<updated>2012-12-30T04:09:37Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Usage */ Update source link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;as85 is a simple assembler for the Sharp sm8521; the same microcontroller used in the Tiger Game.com. Game.com was released in 1998 and had only a few games ever made for it. It also has not had any homebrew games made for it. as85 is an attempt to build an assembler that will help hackers write homebrew code that will run on Game.com hardware.&lt;br /&gt;
&lt;br /&gt;
Documentation on the Game.com hardware is available at [http://gamecom.guruwork.de/ Game.commies].&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The source code is available at http://git.kodewerx.org/as85/src/&lt;br /&gt;
&lt;br /&gt;
==Current Progress==&lt;br /&gt;
&lt;br /&gt;
The current state of as85 is &amp;quot;almost usable, but not quite there yet.&amp;quot; A number of bugs exist which need to be fixed before it can be used as a development tool:&lt;br /&gt;
&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=2 Bug 2]: Add support for jump/call/branch instructions&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=3 Bug 3]: Output object code&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=4 Bug 4]: Write a linker&lt;br /&gt;
&lt;br /&gt;
I've also filed a bug about giving the project a better name [http://bugzilla.kodewerx.org/show_bug.cgi?id=5].&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
The program takes one argument; the file name of an sm8521 assembly file. The files in the [http://git.kodewerx.org/as85/src/a90c47020126a58874638e66c0fbf90fb5ab53c2/examples?at=default /examples] directory are a good place to start.&lt;br /&gt;
&lt;br /&gt;
* test.asm is an example of what the beginning of a Game.com program might look like; it contains a header, and some [random] instructions to give you an idea.&lt;br /&gt;
* test2.asm is for testing the integrity of the parser with complex strings.&lt;br /&gt;
* test3.asm lists all possible sm8521 instructions; for verifying the output binary is correct.&lt;br /&gt;
&lt;br /&gt;
==Example Output==&lt;br /&gt;
&lt;br /&gt;
The following command:&lt;br /&gt;
 $ ./as85 ../examples/test3.asm&lt;br /&gt;
&lt;br /&gt;
Produces the following output:&lt;br /&gt;
 00 01           clr     R1&lt;br /&gt;
 01 01           neg     R1&lt;br /&gt;
 02 01           com     R1&lt;br /&gt;
 03 01           rr      R1&lt;br /&gt;
 04 01           rl      R1&lt;br /&gt;
 05 01           rrc     R1&lt;br /&gt;
 06 01           rlc     R1&lt;br /&gt;
 07 01           srl     R1&lt;br /&gt;
 08 01           inc     R1&lt;br /&gt;
 09 01           dec     R1&lt;br /&gt;
 0A 01           sra     R1&lt;br /&gt;
 0B 01           sll     R1&lt;br /&gt;
 0C 01           da      R1&lt;br /&gt;
 0D 01           swap    R1&lt;br /&gt;
 0E 01           push    R1&lt;br /&gt;
 0F 01           pop     R1&lt;br /&gt;
 10 0A           cmp     r1, r2&lt;br /&gt;
 11 0A           add     r1, r2&lt;br /&gt;
 12 0A           sub     r1, r2&lt;br /&gt;
 13 0A           adc     r1, r2&lt;br /&gt;
 14 0A           sbc     r1, r2&lt;br /&gt;
 15 0A           and     r1, r2&lt;br /&gt;
 16 0A           or      r1, r2&lt;br /&gt;
 17 0A           xor     r1, r2&lt;br /&gt;
 18 02           incw    RR2&lt;br /&gt;
 19 02           decw    RR2&lt;br /&gt;
 1A 08           clr     @r1&lt;br /&gt;
 1A 09           neg     @r1&lt;br /&gt;
 1A 0A           com     @r1&lt;br /&gt;
 1A 0B           rr      @r1&lt;br /&gt;
 1A 0C           rl      @r1&lt;br /&gt;
 1A 0D           rrc     @r1&lt;br /&gt;
 1A 0E           rlc     @r1&lt;br /&gt;
 1A 0F           srl     @r1&lt;br /&gt;
 1B 08           inc     @r1&lt;br /&gt;
 1B 09           dec     @r1&lt;br /&gt;
 1B 0A           sra     @r1&lt;br /&gt;
 1B 0B           sll     @r1&lt;br /&gt;
 1B 0C           da      @r1&lt;br /&gt;
 1B 0D           swap    @r1&lt;br /&gt;
 1B 0E           push    @r1&lt;br /&gt;
 1B 0F           pop     @r1&lt;br /&gt;
 1C 07 24        bclr    0xFF24, #7&lt;br /&gt;
 1C 0F 94        bclr    0x94(r1), #7&lt;br /&gt;
 1D 07 24        bset    0xFF24, #7&lt;br /&gt;
 1D 0F 94        bset    0x94(r1), #7&lt;br /&gt;
 1E 02           pushw   RR2&lt;br /&gt;
 1F 02           popw    RR2&lt;br /&gt;
 20 0A           cmp     r1, @r2&lt;br /&gt;
 20 4A           cmp     r1, (r2)+&lt;br /&gt;
 20 88 94        cmp     r1, @0x94&lt;br /&gt;
 20 8A 94        cmp     r1, 0x94(r2)&lt;br /&gt;
 20 CA           cmp     r1, -(r2)&lt;br /&gt;
 21 0A           add     r1, @r2&lt;br /&gt;
 21 4A           add     r1, (r2)+&lt;br /&gt;
 21 88 94        add     r1, @0x94&lt;br /&gt;
 21 8A 94        add     r1, 0x94(r2)&lt;br /&gt;
 21 CA           add     r1, -(r2)&lt;br /&gt;
 22 0A           sub     r1, @r2&lt;br /&gt;
 22 4A           sub     r1, (r2)+&lt;br /&gt;
 22 88 94        sub     r1, @0x94&lt;br /&gt;
 22 8A 94        sub     r1, 0x94(r2)&lt;br /&gt;
 22 CA           sub     r1, -(r2)&lt;br /&gt;
 23 0A           adc     r1, @r2&lt;br /&gt;
 23 4A           adc     r1, (r2)+&lt;br /&gt;
 23 88 94        adc     r1, @0x94&lt;br /&gt;
 23 8A 94        adc     r1, 0x94(r2)&lt;br /&gt;
 23 CA           adc     r1, -(r2)&lt;br /&gt;
 24 0A           sbc     r1, @r2&lt;br /&gt;
 24 4A           sbc     r1, (r2)+&lt;br /&gt;
 24 88 94        sbc     r1, @0x94&lt;br /&gt;
 24 8A 94        sbc     r1, 0x94(r2)&lt;br /&gt;
 24 CA           sbc     r1, -(r2)&lt;br /&gt;
 25 0A           and     r1, @r2&lt;br /&gt;
 25 4A           and     r1, (r2)+&lt;br /&gt;
 25 88 94        and     r1, @0x94&lt;br /&gt;
 25 8A 94        and     r1, 0x94(r2)&lt;br /&gt;
 25 CA           and     r1, -(r2)&lt;br /&gt;
 26 0A           or      r1, @r2&lt;br /&gt;
 26 4A           or      r1, (r2)+&lt;br /&gt;
 26 88 94        or      r1, @0x94&lt;br /&gt;
 26 8A 94        or      r1, 0x94(r2)&lt;br /&gt;
 26 CA           or      r1, -(r2)&lt;br /&gt;
 27 0A           xor     r1, @r2&lt;br /&gt;
 27 4A           xor     r1, (r2)+&lt;br /&gt;
 27 88 94        xor     r1, @0x94&lt;br /&gt;
 27 8A 94        xor     r1, 0x94(r2)&lt;br /&gt;
 27 CA           xor     r1, -(r2)&lt;br /&gt;
 28 0A           mov     r1, @r2&lt;br /&gt;
 28 4A           mov     r1, (r2)+&lt;br /&gt;
 28 88 94        mov     r1, @0x94&lt;br /&gt;
 28 8A 94        mov     r1, 0x94(r2)&lt;br /&gt;
 28 CA           mov     r1, -(r2)&lt;br /&gt;
 29 11           mov     @r1, r2&lt;br /&gt;
 29 51           mov     (r1)+, r2&lt;br /&gt;
 29 90 94        mov     @0x94, r2&lt;br /&gt;
 29 91 94        mov     0x94(r1), r2&lt;br /&gt;
 29 D1           mov     -(r1), r2&lt;br /&gt;
 2C 02           exts    RR2&lt;br /&gt;
 2E 94           mov     ps0, #0x94&lt;br /&gt;
 2F 94 01        btst    R1, #0x94&lt;br /&gt;
 30 09           cmp     r1, @rr2&lt;br /&gt;
 30 49           cmp     r1, (rr2)+&lt;br /&gt;
 30 88 24 94     cmp     r1, @0x9424&lt;br /&gt;
 30 89 24 94     cmp     r1, 0x9424(rr2)&lt;br /&gt;
 30 C9           cmp     r1, -(rr2)&lt;br /&gt;
 31 09           add     r1, @rr2&lt;br /&gt;
 31 49           add     r1, (rr2)+&lt;br /&gt;
 31 88 24 94     add     r1, @0x9424&lt;br /&gt;
 31 89 24 94     add     r1, 0x9424(rr2)&lt;br /&gt;
 31 C9           add     r1, -(rr2)&lt;br /&gt;
 32 09           sub     r1, @rr2&lt;br /&gt;
 32 49           sub     r1, (rr2)+&lt;br /&gt;
 32 88 24 94     sub     r1, @0x9424&lt;br /&gt;
 32 89 24 94     sub     r1, 0x9424(rr2)&lt;br /&gt;
 32 C9           sub     r1, -(rr2)&lt;br /&gt;
 33 09           adc     r1, @rr2&lt;br /&gt;
 33 49           adc     r1, (rr2)+&lt;br /&gt;
 33 88 24 94     adc     r1, @0x9424&lt;br /&gt;
 33 89 24 94     adc     r1, 0x9424(rr2)&lt;br /&gt;
 33 C9           adc     r1, -(rr2)&lt;br /&gt;
 34 09           sbc     r1, @rr2&lt;br /&gt;
 34 49           sbc     r1, (rr2)+&lt;br /&gt;
 34 88 24 94     sbc     r1, @0x9424&lt;br /&gt;
 34 89 24 94     sbc     r1, 0x9424(rr2)&lt;br /&gt;
 34 C9           sbc     r1, -(rr2)&lt;br /&gt;
 35 09           and     r1, @rr2&lt;br /&gt;
 35 49           and     r1, (rr2)+&lt;br /&gt;
 35 88 24 94     and     r1, @0x9424&lt;br /&gt;
 35 89 24 94     and     r1, 0x9424(rr2)&lt;br /&gt;
 35 C9           and     r1, -(rr2)&lt;br /&gt;
 36 09           or      r1, @rr2&lt;br /&gt;
 36 49           or      r1, (rr2)+&lt;br /&gt;
 36 88 24 94     or      r1, @0x9424&lt;br /&gt;
 36 89 24 94     or      r1, 0x9424(rr2)&lt;br /&gt;
 36 C9           or      r1, -(rr2)&lt;br /&gt;
 37 09           xor     r1, @rr2&lt;br /&gt;
 37 49           xor     r1, (rr2)+&lt;br /&gt;
 37 88 24 94     xor     r1, @0x9424&lt;br /&gt;
 37 89 24 94     xor     r1, 0x9424(rr2)&lt;br /&gt;
 37 C9           xor     r1, -(rr2)&lt;br /&gt;
 38 09           mov     r1, @rr2&lt;br /&gt;
 38 49           mov     r1, (rr2)+&lt;br /&gt;
 38 88 24 94     mov     r1, @0x9424&lt;br /&gt;
 38 89 24 94     mov     r1, 0x9424(rr2)&lt;br /&gt;
 38 C9           mov     r1, -(rr2)&lt;br /&gt;
 39 21           mov     @rr2, r4&lt;br /&gt;
 39 61           mov     (rr2)+, r4&lt;br /&gt;
 39 A0 24 94     mov     @0x9424, r4&lt;br /&gt;
 39 A1 24 94     mov     0x9424(rr2), r4&lt;br /&gt;
 39 E1           mov     -(rr2), r4&lt;br /&gt;
 3A 14           movw    rr2, @rr4&lt;br /&gt;
 3A 54           movw    rr2, (rr4)+&lt;br /&gt;
 3A 90 24 94     movw    rr2, @0x9424&lt;br /&gt;
 3A 94 24 94     movw    rr2, 0x9424(rr4)&lt;br /&gt;
 3A D4           movw    rr2, -(rr4)&lt;br /&gt;
 3B 22           movw    @rr2, rr4&lt;br /&gt;
 3B 62           movw    (rr2)+, rr4&lt;br /&gt;
 3B A0 24 94     movw    @0x9424, rr4&lt;br /&gt;
 3B A2 24 94     movw    0x9424(rr2), rr4&lt;br /&gt;
 3B E2           movw    -(rr2), rr4&lt;br /&gt;
 3C 14           movw    rr2, rr4&lt;br /&gt;
 40 02 01        cmp     R1, R2&lt;br /&gt;
 41 02 01        add     R1, R2&lt;br /&gt;
 42 02 01        sub     R1, R2&lt;br /&gt;
 43 02 01        adc     R1, R2&lt;br /&gt;
 44 02 01        sbc     R1, R2&lt;br /&gt;
 45 02 01        and     R1, R2&lt;br /&gt;
 46 02 01        or      R1, R2&lt;br /&gt;
 47 02 01        xor     R1, R2&lt;br /&gt;
 48 02 01        mov     R1, R2&lt;br /&gt;
 4A 04 02        movw    RR2, RR4&lt;br /&gt;
 4B 02 24 94     movw    RR2, #0x9424&lt;br /&gt;
 4C 04 02        mult    RR2, R4&lt;br /&gt;
 4D 94 02        mult    RR2, #0x94&lt;br /&gt;
 4E 07 01        bmov    bf, R1, #7&lt;br /&gt;
 4E 47 01        bmov    R1, #7, bf&lt;br /&gt;
 4F 07 01        bcmp    bf, R1, #7&lt;br /&gt;
 4F 47 01        band    bf, R1, #7&lt;br /&gt;
 4F 87 01        bor     bf, R1, #7&lt;br /&gt;
 4F C7 01        bxor    bf, R1, #7&lt;br /&gt;
 50 94 01        cmp     R1, #0x94&lt;br /&gt;
 51 94 01        add     R1, #0x94&lt;br /&gt;
 52 94 01        sub     R1, #0x94&lt;br /&gt;
 53 94 01        adc     R1, #0x94&lt;br /&gt;
 54 94 01        sbc     R1, #0x94&lt;br /&gt;
 55 94 01        and     R1, #0x94&lt;br /&gt;
 56 94 01        or      R1, #0x94&lt;br /&gt;
 57 94 01        xor     R1, #0x94&lt;br /&gt;
 58 94 01        mov     R1, #0x94&lt;br /&gt;
 5C 04 02        div     RR2, RR4&lt;br /&gt;
 5D 94 02        div     RR2, #0x94&lt;br /&gt;
 5E 01 94 02     movm    R1, #0x94, R2&lt;br /&gt;
 5F 01 94 24     movm    R1, #0x94, #0x24&lt;br /&gt;
 60 04 02        cmpw    RR2, RR4&lt;br /&gt;
 61 04 02        addw    RR2, RR4&lt;br /&gt;
 62 04 02        subw    RR2, RR4&lt;br /&gt;
 63 04 02        adcw    RR2, RR4&lt;br /&gt;
 64 04 02        sbcw    RR2, RR4&lt;br /&gt;
 65 04 02        andw    RR2, RR4&lt;br /&gt;
 66 04 02        orw     RR2, RR4&lt;br /&gt;
 67 04 02        xorw    RR2, RR4&lt;br /&gt;
 68 02 24 94     cmpw    RR2, #0x9424&lt;br /&gt;
 69 02 24 94     addw    RR2, #0x9424&lt;br /&gt;
 6A 02 24 94     subw    RR2, #0x9424&lt;br /&gt;
 6B 02 24 94     adcw    RR2, #0x9424&lt;br /&gt;
 6C 02 24 94     sbcw    RR2, #0x9424&lt;br /&gt;
 6D 02 24 94     andw    RR2, #0x9424&lt;br /&gt;
 6E 02 24 94     orw     RR2, #0x9424&lt;br /&gt;
 6F 02 24 94     xorw    RR2, #0x9424&lt;br /&gt;
 78 24 94        movw    rr0, #0x9424&lt;br /&gt;
 79 24 94        movw    rr8, #0x9424&lt;br /&gt;
 7A 24 94        movw    rr2, #0x9424&lt;br /&gt;
 7B 24 94        movw    rr10, #0x9424&lt;br /&gt;
 7C 24 94        movw    rr4, #0x9424&lt;br /&gt;
 7D 24 94        movw    rr12, #0x9424&lt;br /&gt;
 7E 24 94        movw    rr6, #0x9424&lt;br /&gt;
 7F 24 94        movw    rr14, #0x9424&lt;br /&gt;
 A0 01           bclr    R1, #0&lt;br /&gt;
 A1 01           bclr    R1, #1&lt;br /&gt;
 A2 01           bclr    R1, #2&lt;br /&gt;
 A3 01           bclr    R1, #3&lt;br /&gt;
 A4 01           bclr    R1, #4&lt;br /&gt;
 A5 01           bclr    R1, #5&lt;br /&gt;
 A6 01           bclr    R1, #6&lt;br /&gt;
 A7 01           bclr    R1, #7&lt;br /&gt;
 A8 01           bset    R1, #0&lt;br /&gt;
 A9 01           bset    R1, #1&lt;br /&gt;
 AA 01           bset    R1, #2&lt;br /&gt;
 AB 01           bset    R1, #3&lt;br /&gt;
 AC 01           bset    R1, #4&lt;br /&gt;
 AD 01           bset    R1, #5&lt;br /&gt;
 AE 01           bset    R1, #6&lt;br /&gt;
 AF 01           bset    R1, #7&lt;br /&gt;
 B0 01           mov     r0, R1&lt;br /&gt;
 B1 01           mov     r1, R1&lt;br /&gt;
 B2 01           mov     r2, R1&lt;br /&gt;
 B3 01           mov     r3, R1&lt;br /&gt;
 B4 01           mov     r4, R1&lt;br /&gt;
 B5 01           mov     r5, R1&lt;br /&gt;
 B6 01           mov     r6, R1&lt;br /&gt;
 B7 01           mov     r7, R1&lt;br /&gt;
 B8 01           mov     R1, r0&lt;br /&gt;
 B9 01           mov     R1, r1&lt;br /&gt;
 BA 01           mov     R1, r2&lt;br /&gt;
 BB 01           mov     R1, r3&lt;br /&gt;
 BC 01           mov     R1, r4&lt;br /&gt;
 BD 01           mov     R1, r5&lt;br /&gt;
 BE 01           mov     R1, r6&lt;br /&gt;
 BF 01           mov     R1, r7&lt;br /&gt;
 C0 94           mov     r0, #0x94&lt;br /&gt;
 C1 94           mov     r1, #0x94&lt;br /&gt;
 C2 94           mov     r2, #0x94&lt;br /&gt;
 C3 94           mov     r3, #0x94&lt;br /&gt;
 C4 94           mov     r4, #0x94&lt;br /&gt;
 C5 94           mov     r5, #0x94&lt;br /&gt;
 C6 94           mov     r6, #0x94&lt;br /&gt;
 C7 94           mov     r7, #0x94&lt;br /&gt;
 C8 94           mov     ie0, #0x94&lt;br /&gt;
 C9 94           mov     ie1, #0x94&lt;br /&gt;
 CA 94           mov     ir0, #0x94&lt;br /&gt;
 CB 94           mov     ir1, #0x94&lt;br /&gt;
 CC 94           mov     p0, #0x94&lt;br /&gt;
 CD 94           mov     p1, #0x94&lt;br /&gt;
 CE 94           mov     p2, #0x94&lt;br /&gt;
 CF 94           mov     p3, #0x94&lt;br /&gt;
 F0              stop&lt;br /&gt;
 F1              halt&lt;br /&gt;
 F8              ret&lt;br /&gt;
 F9              iret&lt;br /&gt;
 FA              clrc&lt;br /&gt;
 FB              comc&lt;br /&gt;
 FC              setc&lt;br /&gt;
 FD              ei&lt;br /&gt;
 FE              di&lt;br /&gt;
 FF              nop&lt;br /&gt;
 assemble() returned 0: OK&lt;br /&gt;
 Clean up...&lt;br /&gt;
&lt;br /&gt;
Note: The output binary has not been verified for accuracy.&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
As85 is a fairly simple assembler. It doesn't use any sort of 'compiler-compiler' for lexical analysis. In fact, its lexical analysis is very specific to the sm8521 MCU.&lt;br /&gt;
&lt;br /&gt;
The main loop (assemble() function, defined in [http://hg.kodewerx.org/as85/file/a90c47020126/src/asm.c#l315 asm.c]) does the input text parsing inline. (This should probably be moved out to a new source file.) After splitting a line into two pieces; op[0] containing the instruction, and op[1] containing its operands; a string comparison against op[0] is done over all supported instructions. If a match is found, the operands string is passed to a dynamically chosen function (from a [http://hg.kodewerx.org/as85/file/a90c47020126/src/inst.c#l156 function pointer table], indexed by the matched instruction). This function performs the lexical analysis required to decide which instruction we are trying to assemble.&lt;br /&gt;
&lt;br /&gt;
Since the sm8521 is a CISC machine, its instruction set contains a number of different ways to assemble the same instruction mnemonic. For example, several different addressing modes for the ''mov'' instruction are shown above in the test3.asm output. The lexical analysis is the voodoo which picks the proper addressing mode and byte codes by analyzing the operands.&lt;br /&gt;
&lt;br /&gt;
The lexical analyzing functions are defined in inst.c (following the function pointer table mentioned previously). The function handling the current instruction will test the operands string against a series of lexical patterns with the [http://hg.kodewerx.org/as85/file/a90c47020126/src/asm.c#l89 chk_pattern()] function (defined in asm.c, although this should probably be moved).&lt;br /&gt;
&lt;br /&gt;
chk_pattern() uses a scanf-like formatting string, rather than a regular expression, which is more common in lexical analysis. Documentation for the formatting string can be found in [http://hg.kodewerx.org/as85/file/a90c47020126/src/inst.h#l29 inst.h]. With just a few pattern primitives, any of the sm8521's addressing modes can be matched, with the matching primitives output as part of an array. It makes good use of the format scanners defined in [http://hg.kodewerx.org/as85/file/a90c47020126/src/scan.c scan.c].&lt;br /&gt;
&lt;br /&gt;
If chk_pattern() manages to find a match, the matching data may be further checked for validity on a per-context basis. Finally, the full instruction byte codes will be put together and returned to the assemble() loop. This is where the object code would be built. Currently the only thing that happens now is dumping the assembled instruction to stdout, in a debug build. [http://hg.kodewerx.org/as85/file/a90c47020126/src/asm.c#l464]&lt;br /&gt;
&lt;br /&gt;
===Optimization Concerns===&lt;br /&gt;
&lt;br /&gt;
Some optimization could be done within this lexical analysis process. The first improvement would be replacing the linear string comparison with a binary search tree. The second thing that would help in this immediate area would be replacing the string comparison itself with a hash comparison. The hash algorithm would have to be suitably small and fast enough to make much of a difference.&lt;br /&gt;
&lt;br /&gt;
The next big optimization would be rearranging the chk_pattern() calls within each lexical analyzer to check the most likely patterns first. The best way to choose the best order is static analysis of sm8521 source code, which is obviously in very short supply. Accurate disassemblies of commercial Game.com games would be helpful to this end, however.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=As85&amp;diff=2032</id>
		<title>As85</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=As85&amp;diff=2032"/>
				<updated>2012-12-30T04:08:56Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Download */ Update source link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;as85 is a simple assembler for the Sharp sm8521; the same microcontroller used in the Tiger Game.com. Game.com was released in 1998 and had only a few games ever made for it. It also has not had any homebrew games made for it. as85 is an attempt to build an assembler that will help hackers write homebrew code that will run on Game.com hardware.&lt;br /&gt;
&lt;br /&gt;
Documentation on the Game.com hardware is available at [http://gamecom.guruwork.de/ Game.commies].&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The source code is available at http://git.kodewerx.org/as85/src/&lt;br /&gt;
&lt;br /&gt;
==Current Progress==&lt;br /&gt;
&lt;br /&gt;
The current state of as85 is &amp;quot;almost usable, but not quite there yet.&amp;quot; A number of bugs exist which need to be fixed before it can be used as a development tool:&lt;br /&gt;
&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=2 Bug 2]: Add support for jump/call/branch instructions&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=3 Bug 3]: Output object code&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=4 Bug 4]: Write a linker&lt;br /&gt;
&lt;br /&gt;
I've also filed a bug about giving the project a better name [http://bugzilla.kodewerx.org/show_bug.cgi?id=5].&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
The program takes one argument; the file name of an sm8521 assembly file. The files in the [http://hg.kodewerx.org/as85/file/tip/examples /examples] directory are a good place to start.&lt;br /&gt;
&lt;br /&gt;
* test.asm is an example of what the beginning of a Game.com program might look like; it contains a header, and some [random] instructions to give you an idea.&lt;br /&gt;
* test2.asm is for testing the integrity of the parser with complex strings.&lt;br /&gt;
* test3.asm lists all possible sm8521 instructions; for verifying the output binary is correct.&lt;br /&gt;
&lt;br /&gt;
==Example Output==&lt;br /&gt;
&lt;br /&gt;
The following command:&lt;br /&gt;
 $ ./as85 ../examples/test3.asm&lt;br /&gt;
&lt;br /&gt;
Produces the following output:&lt;br /&gt;
 00 01           clr     R1&lt;br /&gt;
 01 01           neg     R1&lt;br /&gt;
 02 01           com     R1&lt;br /&gt;
 03 01           rr      R1&lt;br /&gt;
 04 01           rl      R1&lt;br /&gt;
 05 01           rrc     R1&lt;br /&gt;
 06 01           rlc     R1&lt;br /&gt;
 07 01           srl     R1&lt;br /&gt;
 08 01           inc     R1&lt;br /&gt;
 09 01           dec     R1&lt;br /&gt;
 0A 01           sra     R1&lt;br /&gt;
 0B 01           sll     R1&lt;br /&gt;
 0C 01           da      R1&lt;br /&gt;
 0D 01           swap    R1&lt;br /&gt;
 0E 01           push    R1&lt;br /&gt;
 0F 01           pop     R1&lt;br /&gt;
 10 0A           cmp     r1, r2&lt;br /&gt;
 11 0A           add     r1, r2&lt;br /&gt;
 12 0A           sub     r1, r2&lt;br /&gt;
 13 0A           adc     r1, r2&lt;br /&gt;
 14 0A           sbc     r1, r2&lt;br /&gt;
 15 0A           and     r1, r2&lt;br /&gt;
 16 0A           or      r1, r2&lt;br /&gt;
 17 0A           xor     r1, r2&lt;br /&gt;
 18 02           incw    RR2&lt;br /&gt;
 19 02           decw    RR2&lt;br /&gt;
 1A 08           clr     @r1&lt;br /&gt;
 1A 09           neg     @r1&lt;br /&gt;
 1A 0A           com     @r1&lt;br /&gt;
 1A 0B           rr      @r1&lt;br /&gt;
 1A 0C           rl      @r1&lt;br /&gt;
 1A 0D           rrc     @r1&lt;br /&gt;
 1A 0E           rlc     @r1&lt;br /&gt;
 1A 0F           srl     @r1&lt;br /&gt;
 1B 08           inc     @r1&lt;br /&gt;
 1B 09           dec     @r1&lt;br /&gt;
 1B 0A           sra     @r1&lt;br /&gt;
 1B 0B           sll     @r1&lt;br /&gt;
 1B 0C           da      @r1&lt;br /&gt;
 1B 0D           swap    @r1&lt;br /&gt;
 1B 0E           push    @r1&lt;br /&gt;
 1B 0F           pop     @r1&lt;br /&gt;
 1C 07 24        bclr    0xFF24, #7&lt;br /&gt;
 1C 0F 94        bclr    0x94(r1), #7&lt;br /&gt;
 1D 07 24        bset    0xFF24, #7&lt;br /&gt;
 1D 0F 94        bset    0x94(r1), #7&lt;br /&gt;
 1E 02           pushw   RR2&lt;br /&gt;
 1F 02           popw    RR2&lt;br /&gt;
 20 0A           cmp     r1, @r2&lt;br /&gt;
 20 4A           cmp     r1, (r2)+&lt;br /&gt;
 20 88 94        cmp     r1, @0x94&lt;br /&gt;
 20 8A 94        cmp     r1, 0x94(r2)&lt;br /&gt;
 20 CA           cmp     r1, -(r2)&lt;br /&gt;
 21 0A           add     r1, @r2&lt;br /&gt;
 21 4A           add     r1, (r2)+&lt;br /&gt;
 21 88 94        add     r1, @0x94&lt;br /&gt;
 21 8A 94        add     r1, 0x94(r2)&lt;br /&gt;
 21 CA           add     r1, -(r2)&lt;br /&gt;
 22 0A           sub     r1, @r2&lt;br /&gt;
 22 4A           sub     r1, (r2)+&lt;br /&gt;
 22 88 94        sub     r1, @0x94&lt;br /&gt;
 22 8A 94        sub     r1, 0x94(r2)&lt;br /&gt;
 22 CA           sub     r1, -(r2)&lt;br /&gt;
 23 0A           adc     r1, @r2&lt;br /&gt;
 23 4A           adc     r1, (r2)+&lt;br /&gt;
 23 88 94        adc     r1, @0x94&lt;br /&gt;
 23 8A 94        adc     r1, 0x94(r2)&lt;br /&gt;
 23 CA           adc     r1, -(r2)&lt;br /&gt;
 24 0A           sbc     r1, @r2&lt;br /&gt;
 24 4A           sbc     r1, (r2)+&lt;br /&gt;
 24 88 94        sbc     r1, @0x94&lt;br /&gt;
 24 8A 94        sbc     r1, 0x94(r2)&lt;br /&gt;
 24 CA           sbc     r1, -(r2)&lt;br /&gt;
 25 0A           and     r1, @r2&lt;br /&gt;
 25 4A           and     r1, (r2)+&lt;br /&gt;
 25 88 94        and     r1, @0x94&lt;br /&gt;
 25 8A 94        and     r1, 0x94(r2)&lt;br /&gt;
 25 CA           and     r1, -(r2)&lt;br /&gt;
 26 0A           or      r1, @r2&lt;br /&gt;
 26 4A           or      r1, (r2)+&lt;br /&gt;
 26 88 94        or      r1, @0x94&lt;br /&gt;
 26 8A 94        or      r1, 0x94(r2)&lt;br /&gt;
 26 CA           or      r1, -(r2)&lt;br /&gt;
 27 0A           xor     r1, @r2&lt;br /&gt;
 27 4A           xor     r1, (r2)+&lt;br /&gt;
 27 88 94        xor     r1, @0x94&lt;br /&gt;
 27 8A 94        xor     r1, 0x94(r2)&lt;br /&gt;
 27 CA           xor     r1, -(r2)&lt;br /&gt;
 28 0A           mov     r1, @r2&lt;br /&gt;
 28 4A           mov     r1, (r2)+&lt;br /&gt;
 28 88 94        mov     r1, @0x94&lt;br /&gt;
 28 8A 94        mov     r1, 0x94(r2)&lt;br /&gt;
 28 CA           mov     r1, -(r2)&lt;br /&gt;
 29 11           mov     @r1, r2&lt;br /&gt;
 29 51           mov     (r1)+, r2&lt;br /&gt;
 29 90 94        mov     @0x94, r2&lt;br /&gt;
 29 91 94        mov     0x94(r1), r2&lt;br /&gt;
 29 D1           mov     -(r1), r2&lt;br /&gt;
 2C 02           exts    RR2&lt;br /&gt;
 2E 94           mov     ps0, #0x94&lt;br /&gt;
 2F 94 01        btst    R1, #0x94&lt;br /&gt;
 30 09           cmp     r1, @rr2&lt;br /&gt;
 30 49           cmp     r1, (rr2)+&lt;br /&gt;
 30 88 24 94     cmp     r1, @0x9424&lt;br /&gt;
 30 89 24 94     cmp     r1, 0x9424(rr2)&lt;br /&gt;
 30 C9           cmp     r1, -(rr2)&lt;br /&gt;
 31 09           add     r1, @rr2&lt;br /&gt;
 31 49           add     r1, (rr2)+&lt;br /&gt;
 31 88 24 94     add     r1, @0x9424&lt;br /&gt;
 31 89 24 94     add     r1, 0x9424(rr2)&lt;br /&gt;
 31 C9           add     r1, -(rr2)&lt;br /&gt;
 32 09           sub     r1, @rr2&lt;br /&gt;
 32 49           sub     r1, (rr2)+&lt;br /&gt;
 32 88 24 94     sub     r1, @0x9424&lt;br /&gt;
 32 89 24 94     sub     r1, 0x9424(rr2)&lt;br /&gt;
 32 C9           sub     r1, -(rr2)&lt;br /&gt;
 33 09           adc     r1, @rr2&lt;br /&gt;
 33 49           adc     r1, (rr2)+&lt;br /&gt;
 33 88 24 94     adc     r1, @0x9424&lt;br /&gt;
 33 89 24 94     adc     r1, 0x9424(rr2)&lt;br /&gt;
 33 C9           adc     r1, -(rr2)&lt;br /&gt;
 34 09           sbc     r1, @rr2&lt;br /&gt;
 34 49           sbc     r1, (rr2)+&lt;br /&gt;
 34 88 24 94     sbc     r1, @0x9424&lt;br /&gt;
 34 89 24 94     sbc     r1, 0x9424(rr2)&lt;br /&gt;
 34 C9           sbc     r1, -(rr2)&lt;br /&gt;
 35 09           and     r1, @rr2&lt;br /&gt;
 35 49           and     r1, (rr2)+&lt;br /&gt;
 35 88 24 94     and     r1, @0x9424&lt;br /&gt;
 35 89 24 94     and     r1, 0x9424(rr2)&lt;br /&gt;
 35 C9           and     r1, -(rr2)&lt;br /&gt;
 36 09           or      r1, @rr2&lt;br /&gt;
 36 49           or      r1, (rr2)+&lt;br /&gt;
 36 88 24 94     or      r1, @0x9424&lt;br /&gt;
 36 89 24 94     or      r1, 0x9424(rr2)&lt;br /&gt;
 36 C9           or      r1, -(rr2)&lt;br /&gt;
 37 09           xor     r1, @rr2&lt;br /&gt;
 37 49           xor     r1, (rr2)+&lt;br /&gt;
 37 88 24 94     xor     r1, @0x9424&lt;br /&gt;
 37 89 24 94     xor     r1, 0x9424(rr2)&lt;br /&gt;
 37 C9           xor     r1, -(rr2)&lt;br /&gt;
 38 09           mov     r1, @rr2&lt;br /&gt;
 38 49           mov     r1, (rr2)+&lt;br /&gt;
 38 88 24 94     mov     r1, @0x9424&lt;br /&gt;
 38 89 24 94     mov     r1, 0x9424(rr2)&lt;br /&gt;
 38 C9           mov     r1, -(rr2)&lt;br /&gt;
 39 21           mov     @rr2, r4&lt;br /&gt;
 39 61           mov     (rr2)+, r4&lt;br /&gt;
 39 A0 24 94     mov     @0x9424, r4&lt;br /&gt;
 39 A1 24 94     mov     0x9424(rr2), r4&lt;br /&gt;
 39 E1           mov     -(rr2), r4&lt;br /&gt;
 3A 14           movw    rr2, @rr4&lt;br /&gt;
 3A 54           movw    rr2, (rr4)+&lt;br /&gt;
 3A 90 24 94     movw    rr2, @0x9424&lt;br /&gt;
 3A 94 24 94     movw    rr2, 0x9424(rr4)&lt;br /&gt;
 3A D4           movw    rr2, -(rr4)&lt;br /&gt;
 3B 22           movw    @rr2, rr4&lt;br /&gt;
 3B 62           movw    (rr2)+, rr4&lt;br /&gt;
 3B A0 24 94     movw    @0x9424, rr4&lt;br /&gt;
 3B A2 24 94     movw    0x9424(rr2), rr4&lt;br /&gt;
 3B E2           movw    -(rr2), rr4&lt;br /&gt;
 3C 14           movw    rr2, rr4&lt;br /&gt;
 40 02 01        cmp     R1, R2&lt;br /&gt;
 41 02 01        add     R1, R2&lt;br /&gt;
 42 02 01        sub     R1, R2&lt;br /&gt;
 43 02 01        adc     R1, R2&lt;br /&gt;
 44 02 01        sbc     R1, R2&lt;br /&gt;
 45 02 01        and     R1, R2&lt;br /&gt;
 46 02 01        or      R1, R2&lt;br /&gt;
 47 02 01        xor     R1, R2&lt;br /&gt;
 48 02 01        mov     R1, R2&lt;br /&gt;
 4A 04 02        movw    RR2, RR4&lt;br /&gt;
 4B 02 24 94     movw    RR2, #0x9424&lt;br /&gt;
 4C 04 02        mult    RR2, R4&lt;br /&gt;
 4D 94 02        mult    RR2, #0x94&lt;br /&gt;
 4E 07 01        bmov    bf, R1, #7&lt;br /&gt;
 4E 47 01        bmov    R1, #7, bf&lt;br /&gt;
 4F 07 01        bcmp    bf, R1, #7&lt;br /&gt;
 4F 47 01        band    bf, R1, #7&lt;br /&gt;
 4F 87 01        bor     bf, R1, #7&lt;br /&gt;
 4F C7 01        bxor    bf, R1, #7&lt;br /&gt;
 50 94 01        cmp     R1, #0x94&lt;br /&gt;
 51 94 01        add     R1, #0x94&lt;br /&gt;
 52 94 01        sub     R1, #0x94&lt;br /&gt;
 53 94 01        adc     R1, #0x94&lt;br /&gt;
 54 94 01        sbc     R1, #0x94&lt;br /&gt;
 55 94 01        and     R1, #0x94&lt;br /&gt;
 56 94 01        or      R1, #0x94&lt;br /&gt;
 57 94 01        xor     R1, #0x94&lt;br /&gt;
 58 94 01        mov     R1, #0x94&lt;br /&gt;
 5C 04 02        div     RR2, RR4&lt;br /&gt;
 5D 94 02        div     RR2, #0x94&lt;br /&gt;
 5E 01 94 02     movm    R1, #0x94, R2&lt;br /&gt;
 5F 01 94 24     movm    R1, #0x94, #0x24&lt;br /&gt;
 60 04 02        cmpw    RR2, RR4&lt;br /&gt;
 61 04 02        addw    RR2, RR4&lt;br /&gt;
 62 04 02        subw    RR2, RR4&lt;br /&gt;
 63 04 02        adcw    RR2, RR4&lt;br /&gt;
 64 04 02        sbcw    RR2, RR4&lt;br /&gt;
 65 04 02        andw    RR2, RR4&lt;br /&gt;
 66 04 02        orw     RR2, RR4&lt;br /&gt;
 67 04 02        xorw    RR2, RR4&lt;br /&gt;
 68 02 24 94     cmpw    RR2, #0x9424&lt;br /&gt;
 69 02 24 94     addw    RR2, #0x9424&lt;br /&gt;
 6A 02 24 94     subw    RR2, #0x9424&lt;br /&gt;
 6B 02 24 94     adcw    RR2, #0x9424&lt;br /&gt;
 6C 02 24 94     sbcw    RR2, #0x9424&lt;br /&gt;
 6D 02 24 94     andw    RR2, #0x9424&lt;br /&gt;
 6E 02 24 94     orw     RR2, #0x9424&lt;br /&gt;
 6F 02 24 94     xorw    RR2, #0x9424&lt;br /&gt;
 78 24 94        movw    rr0, #0x9424&lt;br /&gt;
 79 24 94        movw    rr8, #0x9424&lt;br /&gt;
 7A 24 94        movw    rr2, #0x9424&lt;br /&gt;
 7B 24 94        movw    rr10, #0x9424&lt;br /&gt;
 7C 24 94        movw    rr4, #0x9424&lt;br /&gt;
 7D 24 94        movw    rr12, #0x9424&lt;br /&gt;
 7E 24 94        movw    rr6, #0x9424&lt;br /&gt;
 7F 24 94        movw    rr14, #0x9424&lt;br /&gt;
 A0 01           bclr    R1, #0&lt;br /&gt;
 A1 01           bclr    R1, #1&lt;br /&gt;
 A2 01           bclr    R1, #2&lt;br /&gt;
 A3 01           bclr    R1, #3&lt;br /&gt;
 A4 01           bclr    R1, #4&lt;br /&gt;
 A5 01           bclr    R1, #5&lt;br /&gt;
 A6 01           bclr    R1, #6&lt;br /&gt;
 A7 01           bclr    R1, #7&lt;br /&gt;
 A8 01           bset    R1, #0&lt;br /&gt;
 A9 01           bset    R1, #1&lt;br /&gt;
 AA 01           bset    R1, #2&lt;br /&gt;
 AB 01           bset    R1, #3&lt;br /&gt;
 AC 01           bset    R1, #4&lt;br /&gt;
 AD 01           bset    R1, #5&lt;br /&gt;
 AE 01           bset    R1, #6&lt;br /&gt;
 AF 01           bset    R1, #7&lt;br /&gt;
 B0 01           mov     r0, R1&lt;br /&gt;
 B1 01           mov     r1, R1&lt;br /&gt;
 B2 01           mov     r2, R1&lt;br /&gt;
 B3 01           mov     r3, R1&lt;br /&gt;
 B4 01           mov     r4, R1&lt;br /&gt;
 B5 01           mov     r5, R1&lt;br /&gt;
 B6 01           mov     r6, R1&lt;br /&gt;
 B7 01           mov     r7, R1&lt;br /&gt;
 B8 01           mov     R1, r0&lt;br /&gt;
 B9 01           mov     R1, r1&lt;br /&gt;
 BA 01           mov     R1, r2&lt;br /&gt;
 BB 01           mov     R1, r3&lt;br /&gt;
 BC 01           mov     R1, r4&lt;br /&gt;
 BD 01           mov     R1, r5&lt;br /&gt;
 BE 01           mov     R1, r6&lt;br /&gt;
 BF 01           mov     R1, r7&lt;br /&gt;
 C0 94           mov     r0, #0x94&lt;br /&gt;
 C1 94           mov     r1, #0x94&lt;br /&gt;
 C2 94           mov     r2, #0x94&lt;br /&gt;
 C3 94           mov     r3, #0x94&lt;br /&gt;
 C4 94           mov     r4, #0x94&lt;br /&gt;
 C5 94           mov     r5, #0x94&lt;br /&gt;
 C6 94           mov     r6, #0x94&lt;br /&gt;
 C7 94           mov     r7, #0x94&lt;br /&gt;
 C8 94           mov     ie0, #0x94&lt;br /&gt;
 C9 94           mov     ie1, #0x94&lt;br /&gt;
 CA 94           mov     ir0, #0x94&lt;br /&gt;
 CB 94           mov     ir1, #0x94&lt;br /&gt;
 CC 94           mov     p0, #0x94&lt;br /&gt;
 CD 94           mov     p1, #0x94&lt;br /&gt;
 CE 94           mov     p2, #0x94&lt;br /&gt;
 CF 94           mov     p3, #0x94&lt;br /&gt;
 F0              stop&lt;br /&gt;
 F1              halt&lt;br /&gt;
 F8              ret&lt;br /&gt;
 F9              iret&lt;br /&gt;
 FA              clrc&lt;br /&gt;
 FB              comc&lt;br /&gt;
 FC              setc&lt;br /&gt;
 FD              ei&lt;br /&gt;
 FE              di&lt;br /&gt;
 FF              nop&lt;br /&gt;
 assemble() returned 0: OK&lt;br /&gt;
 Clean up...&lt;br /&gt;
&lt;br /&gt;
Note: The output binary has not been verified for accuracy.&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
As85 is a fairly simple assembler. It doesn't use any sort of 'compiler-compiler' for lexical analysis. In fact, its lexical analysis is very specific to the sm8521 MCU.&lt;br /&gt;
&lt;br /&gt;
The main loop (assemble() function, defined in [http://hg.kodewerx.org/as85/file/a90c47020126/src/asm.c#l315 asm.c]) does the input text parsing inline. (This should probably be moved out to a new source file.) After splitting a line into two pieces; op[0] containing the instruction, and op[1] containing its operands; a string comparison against op[0] is done over all supported instructions. If a match is found, the operands string is passed to a dynamically chosen function (from a [http://hg.kodewerx.org/as85/file/a90c47020126/src/inst.c#l156 function pointer table], indexed by the matched instruction). This function performs the lexical analysis required to decide which instruction we are trying to assemble.&lt;br /&gt;
&lt;br /&gt;
Since the sm8521 is a CISC machine, its instruction set contains a number of different ways to assemble the same instruction mnemonic. For example, several different addressing modes for the ''mov'' instruction are shown above in the test3.asm output. The lexical analysis is the voodoo which picks the proper addressing mode and byte codes by analyzing the operands.&lt;br /&gt;
&lt;br /&gt;
The lexical analyzing functions are defined in inst.c (following the function pointer table mentioned previously). The function handling the current instruction will test the operands string against a series of lexical patterns with the [http://hg.kodewerx.org/as85/file/a90c47020126/src/asm.c#l89 chk_pattern()] function (defined in asm.c, although this should probably be moved).&lt;br /&gt;
&lt;br /&gt;
chk_pattern() uses a scanf-like formatting string, rather than a regular expression, which is more common in lexical analysis. Documentation for the formatting string can be found in [http://hg.kodewerx.org/as85/file/a90c47020126/src/inst.h#l29 inst.h]. With just a few pattern primitives, any of the sm8521's addressing modes can be matched, with the matching primitives output as part of an array. It makes good use of the format scanners defined in [http://hg.kodewerx.org/as85/file/a90c47020126/src/scan.c scan.c].&lt;br /&gt;
&lt;br /&gt;
If chk_pattern() manages to find a match, the matching data may be further checked for validity on a per-context basis. Finally, the full instruction byte codes will be put together and returned to the assemble() loop. This is where the object code would be built. Currently the only thing that happens now is dumping the assembled instruction to stdout, in a debug build. [http://hg.kodewerx.org/as85/file/a90c47020126/src/asm.c#l464]&lt;br /&gt;
&lt;br /&gt;
===Optimization Concerns===&lt;br /&gt;
&lt;br /&gt;
Some optimization could be done within this lexical analysis process. The first improvement would be replacing the linear string comparison with a binary search tree. The second thing that would help in this immediate area would be replacing the string comparison itself with a hash comparison. The hash algorithm would have to be suitably small and fast enough to make much of a difference.&lt;br /&gt;
&lt;br /&gt;
The next big optimization would be rearranging the chk_pattern() calls within each lexical analyzer to check the most likely patterns first. The best way to choose the best order is static analysis of sm8521 source code, which is obviously in very short supply. Accurate disassemblies of commercial Game.com games would be helpful to this end, however.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=File:Syndrome2.png&amp;diff=2031</id>
		<title>File:Syndrome2.png</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=File:Syndrome2.png&amp;diff=2031"/>
				<updated>2011-07-02T08:49:10Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: uploaded a new version of &amp;amp;quot;File:Syndrome2.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First version of Syndrome, with empty sidebar; C++, MFC.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=File:Syndrome.png&amp;diff=2030</id>
		<title>File:Syndrome.png</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=File:Syndrome.png&amp;diff=2030"/>
				<updated>2011-07-02T08:48:54Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: uploaded a new version of &amp;amp;quot;File:Syndrome.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First version of syndrome; C++, MFC.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=File:Syn4.png&amp;diff=2029</id>
		<title>File:Syn4.png</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=File:Syn4.png&amp;diff=2029"/>
				<updated>2011-07-02T08:48:40Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: uploaded a new version of &amp;amp;quot;File:Syn4.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Second version of Syndrome; C, Win32API.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=File:Syn3.png&amp;diff=2028</id>
		<title>File:Syn3.png</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=File:Syn3.png&amp;diff=2028"/>
				<updated>2011-07-02T08:48:24Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: uploaded a new version of &amp;amp;quot;File:Syn3.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Second version of Syndrome; C, Win32API.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=File:Syn2.png&amp;diff=2027</id>
		<title>File:Syn2.png</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=File:Syn2.png&amp;diff=2027"/>
				<updated>2011-07-02T08:47:52Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: uploaded a new version of &amp;amp;quot;File:Syn2.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Second version of Syndrome; C, Win32API.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=File:Syn1.png&amp;diff=2026</id>
		<title>File:Syn1.png</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=File:Syn1.png&amp;diff=2026"/>
				<updated>2011-07-02T08:45:30Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: uploaded a new version of &amp;amp;quot;File:Syn1.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Second version of Syndrome; C, Win32API.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=File:Syn1.png&amp;diff=2025</id>
		<title>File:Syn1.png</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=File:Syn1.png&amp;diff=2025"/>
				<updated>2011-07-02T08:42:44Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: uploaded a new version of &amp;amp;quot;File:Syn1.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Second version of Syndrome; C, Win32API.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Main_Page&amp;diff=2024</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Main_Page&amp;diff=2024"/>
				<updated>2011-04-09T18:51:21Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: Redirected page to Kwiki&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Kwiki]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Universal_Debugger_Project&amp;diff=1010</id>
		<title>Universal Debugger Project</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Universal_Debugger_Project&amp;diff=1010"/>
				<updated>2010-10-21T07:38:52Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Preparation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a reference and general documentation for a project I ([[:User:Parasyte|Parasyte]]) have been interested in pursuing for several years. This article will discuss the project's history, current developments, and future.&lt;br /&gt;
&lt;br /&gt;
I've made an effort to write this document with as little technical jargon as possible. The nature of debuggers and debugging, however, is extremely technical, so it has been difficult to keep it down to a decent reading level. For this reason, I've included an Appendix which should ease the use of language throughout this documentation.&lt;br /&gt;
&lt;br /&gt;
Finally, I hope this information is not too redundant. Some things (examples given, explanations, etc) may be repeated more than once. This document is supposed to be highly detailed, but concise. If you see many repetitious things, please point them out on the discussion page.&lt;br /&gt;
&lt;br /&gt;
==Project history==&lt;br /&gt;
&lt;br /&gt;
I began my research into debuggers sometime in 1999. Things were different back then; computers were just barely able to emulate SNES, even with emulators of the time taking numerous shortcuts to help speed up emulation. At the time, I only knew of one SNES emulator pre-compiled with any kind of debugging functionality, and that was a build of SNES9x (then a chromeless application which was horribly difficult to use) by LordTech. It allowed the user to enable and disable assembly tracing while the game ran. This was a good start; you could see what the game was doing, and gain a lot of information from it. But it was still clunky.&lt;br /&gt;
&lt;br /&gt;
To find the assembly which read or wrote to a specific address, you had to search through (often many megabytes of) text for those addresses. It gave you a good piece of the puzzle, but it did not give you the whole picture. Often many instructions were branched over, and were entirely missing from the log.&lt;br /&gt;
&lt;br /&gt;
A few years later, I had some C programming experience of my own under my belt, and I had also found a new NES emulator called NESten. It wasn't a great NES emulator, but it was decent; it ran most of the NES games I was interested in, and it also had a fairly nice debugger built in! It was during this time that I got my first real taste of debugging. (Previously I experimented with UltraHLE's debugging features, but I don't recall them being much use; it used another &amp;quot;look but don't touch&amp;quot; passive take on debugging.)&lt;br /&gt;
&lt;br /&gt;
NESten's debugger (and the emulator itself) did have some annoying flaws. And after getting sick of it, I decided (like many pioneering hackers before me) to take a decent open source emulator and extend it with some decent debugging capabilities. I chose FCEU (FamiCom Emulator Ultra) by Xodnizel as my base. (Note: FCEU was previously based on FCE, by Bero.) FCEU was a good candidate because it had decent emulation capabilities, and also because it was quite fast; you really need a fast base if you're just going to slow it down with powerful features. And I'll get to that point later.&lt;br /&gt;
&lt;br /&gt;
===FCEUd===&lt;br /&gt;
&lt;br /&gt;
And with that, FCEUd (FCEU-debug) was born. It did not take long to get a stable debugger integrated into the CPU core and hooked up with a little chrome. Seems like it was only 3 or 4 months before it was usable, and a total of 6 months or so development time before I was happy with it. This debugger took all of the major ideas from NESten (including its disassembler syntax for displaying current work addresses) and added some crucial elements that NESten lacked (write breakpoints triggered by INC/DEC instructions, which increment and decrement bytes in memory). I also used ideas from PSX debuggers, such as &amp;quot;step out&amp;quot; which mutually completes the &amp;quot;step in&amp;quot; and &amp;quot;step over&amp;quot; process. And I'll get to that point, again, later.&lt;br /&gt;
&lt;br /&gt;
Since then, FCEUd has been further extended by other members of the emulation/ROM hacking scenes. To this day, FCE has been the most widely forked emulator, in part, because of the work we did extending it from an NES player to an NES development tool. But as you will see, this will bring me to another point later: The work done on FCE-derived forks is very widespread without much communication between parties. Ultimately, it's a mish-mash mix of talent tackling the same ideas from different vantage points without direct collaboration. And I think it's a shame.&lt;br /&gt;
&lt;br /&gt;
===GCNrd===&lt;br /&gt;
&lt;br /&gt;
The main development cycle on FCEUd was during 2002. I learned quite a bit from this project, and it got me interested in debugging other architectures. The next architecture I took on was Nintendo GameCube, officially abbreviated &amp;quot;GCN&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Sometime in 2003, hackers discovered a flaw in the GCN game Phantasy Star Online, which was compatible with the GCN BroadBand Adapter (BBA). This quickly became known as the PSO exploit, and allowed running &amp;quot;homebrew&amp;quot; code on a consumer GCN.&lt;br /&gt;
&lt;br /&gt;
The PSO exploit worked something like this: Hacker Joe sets up his own DNS server, and tells PSO to use that server IP address as its default gateway. This way, PSO asks Hacker Joe's DNS server where it can find Sega's PSO server. Hacker Joe's DNS server tells PSO that Sega's server is located on Hacker Joe's PSO server. PSO happily connects to Hacker Joe's PSO server, which then tells PSO that there is an update available. PSO happily downloads the &amp;quot;PSO loader stub&amp;quot; which is posing as an official update to PSO. PSO happily launches the PSO loader stub which takes over the GCN and begins downloading a larger executable (of Hacker Joe's choice) from Hacker Joe's PSO server. The PSO loader stub then launches Hacker Joe's executable, and Hacker Joe now has total control over his GCN. In short, PSO is tricked by Hacker Joe into running code that it never should have in the first place.&lt;br /&gt;
&lt;br /&gt;
This was a huge breakthrough for GCN hacking. I was in a very poorly state at the time, with no real job and no real income. I was doing work for a certain company selling GBA flash carts. It got me by, but it was a far cry from decent living. I mention this because it means I couldn't afford PSO or a BBA; the two things I needed to begin work on GCN debugging. I had the skill to accomplish it certainly, so I took up donations from members in the community. Only a few responded, but that's all I needed. About $100 USD was enough to pick up the two items I needed, and I was on my way to fame...&lt;br /&gt;
&lt;br /&gt;
====History of GCNrd====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;06-22-03: First GCN AR codes decrypted.&lt;br /&gt;
06-23-03: GCNcrypt v1.0 released.&lt;br /&gt;
06-25-03: First unofficial GCN AR codes released: Sonic Adventure DX (U) codes,&lt;br /&gt;
          by Sappharad.&lt;br /&gt;
06-27-03: GCNcrypt v1.1 released.&lt;br /&gt;
07-03-03: Planning for GCNrd begins.&lt;br /&gt;
07-07-03: GCNrd development begins.&lt;br /&gt;
08-27-03: Development on GCN network library begins.&lt;br /&gt;
08-29-03: First data received from GCN over network, using homebrew network&lt;br /&gt;
          library.&lt;br /&gt;
09-01-03: First data received by GCN over network, using homebrew network&lt;br /&gt;
          library.&lt;br /&gt;
09-13-03: Harddrive crash causes problems. Interest in GCNrd is lost.&lt;br /&gt;
12-31-03: After 3 months without working on GCNrd, aside from the occasional&lt;br /&gt;
          bugfix in the libs, GCNrd development finally continues.&lt;br /&gt;
12-31-03: Milestone #1. First successful RAM dump grabbed from a GCN game using&lt;br /&gt;
          GCNrd. It takes 35.735 seconds to complete.&lt;br /&gt;
12-31-03: BBA is started in 100mbit full duplex mode. Full RAM dump completes&lt;br /&gt;
          in 14.687 seconds.&lt;br /&gt;
01-03-04: Work on screenshot support begins. First successful screenshots are&lt;br /&gt;
          taken from Rayman 3 and Rogue Leader.&lt;br /&gt;
01-12-04: Mario Kart: Double Dash!! (U) is supported by GCNrd. This was the&lt;br /&gt;
          first successful &amp;quot;BBA Reset&amp;quot; patch for a LAN\network-enabled game.&lt;br /&gt;
01-15-04: Milestone #2. GCNrd rightly claims better compatability than Datel's&lt;br /&gt;
          FreeLoader v1.06b.&lt;br /&gt;
01-17-04: All tested games boot! 64 of 64.&lt;br /&gt;
01-19-04: Kenobi begins work on a GUI for GCNrd, making the program a bit&lt;br /&gt;
          easier to use, and adding code search features.&lt;br /&gt;
01-23-04: Milestone #3. First GCN AR code created using only GCNrd and Kenobi's&lt;br /&gt;
          GCNrd GUI. Wave Race: Blue Storm (U), 99 Points, by Knux0rz.&lt;br /&gt;
01-25-04: Started adding breakpoint support. Breaks work for Read, Write, and&lt;br /&gt;
          Read+Write. Execution breakpoints will be next. BPR\W gave me a bit&lt;br /&gt;
          of trouble. The biggest problem I had was getting around the 8-byte&lt;br /&gt;
          boundary which PowerPC uses for data breakpoints. This was completely&lt;br /&gt;
          unacceptable. As an example, if you set a breakpoint on address&lt;br /&gt;
          805E4FF5, a break would be reported every time an address between&lt;br /&gt;
          805E4FF0 - 805E4FF8 was accessed. Even though only one address within&lt;br /&gt;
          that range had a breakpoint set. My current solution to this problem&lt;br /&gt;
          is pretty nasty, but it works. In fact, it only reports a hit if the&lt;br /&gt;
          break addresses match perfectly. Maybe a little inconvenient, but&lt;br /&gt;
          hey!&lt;br /&gt;
03-11-04: GCN CodeType Helper v1.0 released.&lt;br /&gt;
03-11-04: GCNcrypt v1.2 released.&lt;br /&gt;
03-16-04: Finished up breakpoint support today, which should now be 100% fixed.&lt;br /&gt;
          The debugger now waits until just before returning to the game&lt;br /&gt;
          before enabling any r\w breakpoint. This will help bypass any&lt;br /&gt;
          misleading break hits that are caused by the debugger itself. Such as&lt;br /&gt;
          when accessing the stack and etc.&lt;br /&gt;
          New plan in the works to work-around memory constraints. May not work&lt;br /&gt;
          on all games, but should solve all problems with PacMan World 2.&lt;br /&gt;
          Which currently suffers from a nasty crash when accessing the memory&lt;br /&gt;
          card. The crash appears to be caused by how much memory I have&lt;br /&gt;
          allocated for the debugger.&lt;br /&gt;
03-17-04: Work begins on patching AR's code engine. With the patch in place,&lt;br /&gt;
          the code engine will run GCNrd's memory-resident debugger, allowing&lt;br /&gt;
          users to hack games with multiple executables, such as demo discs and&lt;br /&gt;
          the James Bond 007 games.&lt;br /&gt;
03-18-04: Kenobi adds real-time AR code list handling to the GUI. Supported AR&lt;br /&gt;
          versions are v1.06 and v1.08. Support for additional versions will be&lt;br /&gt;
          made available as soon as we receive AR RAM dumps from the other&lt;br /&gt;
          versions.&lt;br /&gt;
03-19-04: Win9x compatibility issues are worked on. GCNrd console now accepts&lt;br /&gt;
          commands passed on the command line. With commands entered on the&lt;br /&gt;
          command line, the console program will exit immediately after&lt;br /&gt;
          completing the requested command. Support for Win9x compatibility in&lt;br /&gt;
          the GUI is limited, but progressing rapidly.&lt;br /&gt;
03-20-04: Support for AR v1.11 completed.&lt;br /&gt;
03-31-04: First public release! GCNrd v1.00b is made available to hackers&lt;br /&gt;
          everywhere.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====GCNrd GUI====&lt;br /&gt;
&lt;br /&gt;
The GUI for GCNrd (Nintendo Gamecube Remote Debugger) was written entirely separately from my own GCNrd development. It was called simply GCNrdGUI and was written by a French hacker, Kenobi, in Delphi. This split up the workload considerably, and also added a new level of modularity to the project overall. The overall GCNrd project consisted of four components:&lt;br /&gt;
&lt;br /&gt;
* GCNrd Loader: The UI that the user is presented with on the GCN itself. The loader is responsible for GCN-side configuration, initializing the network hardware, launching DVDs, and setting up the debugger/hooking the executable.&lt;br /&gt;
* GCNrd debugger: This is a piece that the user never sees, but directly interacts with. It's a very small program (32KB total program code and memory usage) that runs &amp;quot;behind&amp;quot; the game, listening for instructions coming over the network, and acting upon them.&lt;br /&gt;
* GCNrd client: A command-line application run on the user's PC which can be used to send and receive commands and data to/from the debugger over the network.&lt;br /&gt;
* GCNrdGUI: Kenobi's GUI for interacting with the GCNrd client.&lt;br /&gt;
&lt;br /&gt;
It was not necessary for the GUI to interact with the debugger through my CLI client, but that was the option chosen for GCNrdGUI. Later on another hacker, Sappharad, wrote his own GUI in Java which communicated with the debugger directly, bypassing the need for GCNrd client; the modularity of the project comes full circle.&lt;br /&gt;
&lt;br /&gt;
====GCNrd v1.10b and beyond====&lt;br /&gt;
&lt;br /&gt;
GCNrd v1.10b was released July 28th, 2005. It contained a number of bug fixes and new features. Some new features were only shiney on the surface (background images and UI colors in the loader, date/time display...), but some were actually quite important. The MMU handling, for example, allowed hacking games like Star Wars: Rogue Leader, Star Wars: Rebel Strike, and Metal Gear Solid: The Twin Snakes, which used the MMU extensively. It was a slightly rushed released, even though it did show some promise.&lt;br /&gt;
&lt;br /&gt;
This was the last official release I made, along with a private release (only available to close friends) which included some special features like DVD dumping and loading/debugging DVD images over the BBA. This &amp;quot;DVD simulation&amp;quot; was quite advanced for its time, and allowed me (and a few others) to hack downloaded/dumped games. There are often times that the only way to get a copy of a game is downloading it. Either because it was never officially released in your region, or because it hasn't been officially released ''at all''. This private &amp;quot;v1.10b+&amp;quot; version was never made public due to piracy concerns. &lt;br /&gt;
&lt;br /&gt;
Those piracy concerns were actually forfeited after other hackers disabled the DVD booting code in v1.10b to allow debugging DVD-Rs booted with a &amp;quot;Cobra-like&amp;quot; DVD BIOS.&lt;br /&gt;
&lt;br /&gt;
I had plans at one time to rewrite GCNrd so that it could be relocatable within GCN memory. This would solve problems with memory allocation on games that don't play nice. Resident Evil 4 is a good example of such games; it cannot be booted at all by any version of GCNrd. The rewrite would also make the source code legible enough that I could release it under the [http://www.gnu.org/copyleft/gpl.html GPL]. Granted, legibility is not necessary for source code release, but it was important for reasons of maintainability.&lt;br /&gt;
&lt;br /&gt;
GCNrd source code used a wild mix of C and assembly in its main debug core. Escaping the low levels of assembly was impossible, but it could be structured nicely anyway. This wasn't the only problem, of course. Both the loader and debugger had to have their own separate build of the network library. It was too costly (memory-wise) to put the full library into the debugger, even though this would allow the loader to use the debugger for all of its networking tasks.&lt;br /&gt;
&lt;br /&gt;
Instead, the debugger had a very minimal network library; I cut out all of the initialization sequences, all of the CRC code for packet data integrity checking, and a whole lot of other not-completely-necessary packet handling code. It was important to keep the debugger as small as possible so it would not interfere with the game's use of memory.&lt;br /&gt;
&lt;br /&gt;
That gave me two entirely different network stacks to maintain; one was already quite a bit of work, as it was. There was also the problem of compiling the debugger separately from the loader, and then compiling the debugger binary directly into the loader itself.&lt;br /&gt;
&lt;br /&gt;
There are a number of ways these issues could have been addressed, and I'm not going to cover them all. But I will get back to the early point about modularity. As you will see, I am hoping to solve a great deal of these problems using that frame of mind. Needless to say, I never did complete the rewrite of GCNrd, which would have become &amp;quot;GCNrd v2&amp;quot;. But the problems displayed by it were the cornerstones of what was to become the Universal Debugger Project.&lt;br /&gt;
&lt;br /&gt;
===PCS and Mupen 64===&lt;br /&gt;
&lt;br /&gt;
The next year, in 2006, I went back to hacking N64. This was a time when some very interesting N64 hacks were made [http://doc.kodewerx.net/hacking_n64.html#asm_jesus_mode]. By this time, we were all very familiar with Nemu and its debugging/cheating capabilities. The debugger was not bad, but its emulation left quite a bit to be desired. Once again, unhappy with the tools available, I set out to tackle the problem and create my own tools.&lt;br /&gt;
&lt;br /&gt;
The first was [http://doc.kodewerx.net/hacking_n64.html#emulator_pcs Parasytic Cheat Search], a ''video'' plugin for PJ64 (and other emulators compatible with its plugin spec) that allowed cheat searching through the emulator's memory. It contained many bugs and architectural flaws (being a video plugin which passed all video-related messages to a ''real'' video plugin) but it provided a start for me to get into N64 emulator development.&lt;br /&gt;
&lt;br /&gt;
My next N64 project was tackling the debugger problem. Unlike a simple passive cheat searching program, a debugger has to be hooked directly to the CPU to work consistently. Like the FCEUd project years earlier, I wanted to start with a decent open source emulator and extend its capabilities to include decent debugging features.&lt;br /&gt;
&lt;br /&gt;
I chose Mupen 64 as my base, this time. It had relatively high compatibility, stability, and speed. It also contained a debugger for its GTK+ build, which I knew I could use to my advantage. I was still a Win32 programmer at the time; I did not have much experience outside of Windows. Naturally, I focused on Mupen's Windows code, which is where my debugger would live.&lt;br /&gt;
&lt;br /&gt;
After patching Mupen's CPU core (all three of them!) I started implementing the debugger window and all of its fancy widgets. This is when a very bad case of Deja Vu hit me. I had done all of this work before; I was reinventing the wheel. Not good. So I left Mupen 64 with a bare-bones cheat feature (including search) and debugger. This is when I began formulating the idea that debugger interfaces should be modular, just like GCNrd. Then came an avalanche of questions and issues. More on that later.&lt;br /&gt;
&lt;br /&gt;
===NTRrd and Kwurdi===&lt;br /&gt;
&lt;br /&gt;
In 2007, we had Nintendo DS (officially abbreviated NTR, unofficial NDS), and we had a means to hack it thanks to the efforts of the PassMe crew. I did not jump into DS dev quite as enthusiastically as I had GCN, but I eventually got into it and started playing around with ideas to debug the little machine. There were several problems, initially: The first was a communications port. I chose to use the GBA X-port, which was a rather expensive device (especially for video game hackers, who are typically in their teens, and without jobs; in hindsight, it was probably a very bad idea), but it was attractive to me because of its FPGA.&lt;br /&gt;
&lt;br /&gt;
The X-port comes by default with a simple LPT serial port that can be used as a communications link. But it is generally slow and unreliable for large data transfers. On the other hand, the FPGA (and a LOT of IO) can be leveraged to implement a much faster and more stable communications link. And that's exactly what I did, writing custom FPGA logic for a simple 8-bit ECP-mode LPT port. The result was a much faster (~4MB/s ... still much slower than ethernet, WiFi, or USB would have been) and much more reliable (~0.0001% error rate) communications link that I could use to dump NDS memory to perform cheat searching.&lt;br /&gt;
&lt;br /&gt;
The initial result of this work was &amp;quot;NTRrd&amp;quot; (Nintendo DS Remote Debugger) which never saw any kind of release. That's when the ideas from past projects began to meld into an idea well ahead of its time. The idea of a universal debugger. Or at least, a universal debugger interface. So I came up with a silly acronym: KWURDI, for KodeWerx Universal Remote Debugger Interface. And I wanted NTRrd to be its first &amp;quot;client&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The idea was that NTRrd would be a three-piece project: NTRrd loader, NTRrd debugger, NTRrd client. And Kwurdi would be its GUI. The loader would load the debugger, the debugger would talk to the client, and the client would talk to the GUI. That's a lot of levels of abstraction. As it turns out, though, all of those levels are quite important. In fact, it's this level of abstraction and modularity which make this idea of a universal debugger important.&lt;br /&gt;
&lt;br /&gt;
==The universal debugger==&lt;br /&gt;
&lt;br /&gt;
The original article for the Universal Debugger Project can be found in the [[Debugging Modern Computer Architectures]] article. While it covers a good general scope of the idea itself, it does not lay down any foundation other than a very generic description of the roles that each piece of the project ''might'' play. To highlight the main points of the project:&lt;br /&gt;
&lt;br /&gt;
* The universal debugger interface itself is a user interface to allow interaction with a low-level debugger.&lt;br /&gt;
* The low-level debugger may or may not live on the same machine as the universal debugger interface. The universal debugger interface communicates with the low-level debugger through a standard communications link and protocol.&lt;br /&gt;
* The communications link should be an existing standard. For example, UNIX domain sockets or DBUS for a local low-level debugger, and TCP/IP for a remote low-level debugger.&lt;br /&gt;
* The protocol should also be an existing standard, but to this date, there does not appear to be anything which fits the goals of a universal debugger interface. One possibility is [http://www.rfc-archive.org/getrfc.php?rfc=909 RFC-909, Loader Debugger Protocol].&lt;br /&gt;
&lt;br /&gt;
===Project goals===&lt;br /&gt;
&lt;br /&gt;
The long term goals of the Universal Debugger Project include:&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
* Standardization&lt;br /&gt;
&lt;br /&gt;
These items are to be taken as mutually inclusive. For modularity to work, there must be a set of standards in place. For a set of standards to be successful, the modularity granted by the standards must be exploited.&lt;br /&gt;
&lt;br /&gt;
For our purposes, I wish to implement a set of standards for a &amp;quot;universal debugger&amp;quot; with the help of the community, and implement a debugger interface on top of those standards as an example of modularity. The implementation has the following goals:&lt;br /&gt;
&lt;br /&gt;
# It will be Free Software, released under a free software license comparable to the [http://www.gnu.org/copyleft/gpl.html GNU General Public License].&lt;br /&gt;
# It will be a community-oriented project; accepting ideas, patches, code, images, and documentation, among other items, from the community which supports it.&lt;br /&gt;
# It will be designed as a cross-platform application, able to be used on multiple operating systems.&lt;br /&gt;
# It will be built with internationalization and localization in mind; capable of being adapted to different languages.&lt;br /&gt;
# It will be designed to work well with modern accessibility software.&lt;br /&gt;
# It will communicate with and support any low-level debugger which supports the standards defined by the Universal Debugger Project.&lt;br /&gt;
# It will be configurable, extensible, and modular by nature, to support any conceivable current or future architecture.&lt;br /&gt;
# It will support highly advanced debugging techniques and bleeding-edge technologies to get the most out of the user's debugging experience.&lt;br /&gt;
# It will support and encourage community activity through collaborative debugging.&lt;br /&gt;
&lt;br /&gt;
I will cover these points one at a time in more detail:&lt;br /&gt;
&lt;br /&gt;
====Free software====&lt;br /&gt;
&lt;br /&gt;
Free Software released under the [http://www.gnu.org/copyleft/gpl.html GNU General Public License] or a comparable license is meant to be community-driven. This means, anyone who wants to participate in the development of the project is free to participate. You don't become a community member by being one of a few elite deemed &amp;quot;worthy&amp;quot;; you become a member simply by joining an active discussion or contributing in some other way.&lt;br /&gt;
&lt;br /&gt;
The source code will be made available for everyone to look at or extend, which benefits from many eyes keeping the code safe and secure, and also from many hands working in parallel to quickly produce a stable product that is free for anyone to use in any way they see fit. These are two of the basic freedoms granted by a Free Software license: Freedom to look at and extent the product, and freedom to use the product in any way. There are many more freedoms granted by Free Software, and if interested you should consult the GPL documentation or other authoritative sources.&lt;br /&gt;
&lt;br /&gt;
====Community-oriented, community-driven====&lt;br /&gt;
&lt;br /&gt;
A community-oriented and community-driven software project benefits from its main source of use: its own users. Such projects become self-sustaining, as their users take the secondary roles of developers. I will not cover many of the details relating to community-oriented or community-driven software, but there are plenty of great resources available for further reading. Some suggested reading includes The Cathedral and the Bazaar [http://www.catb.org/~esr/writings/cathedral-bazaar/cathedral-bazaar/index.html#catbmain] by Eric S. Raymond, the About Mozilla pages [http://www.mozilla.org/about] [http://www.mozilla.org/about/manifesto] [http://www.mozilla.org/mission.html] [http://www.mozilla.org/editorials/mozilla-overview.html], and the online book Open Sources: Voices from the Open Source Revolution [http://oreilly.com/catalog/opensources/book/toc.html], written by many influential people from many open source communities.&lt;br /&gt;
&lt;br /&gt;
As a community-oriented, community-driven project, I believe there is no end to the ways in which we, as a community of programmers and hackers, will be able to debug. This community would ideally involve the active roles of everyone from video game and ROM hackers, application and operating system developers, and people in the field of academic research of computer architectures. It doesn't have to be the biggest and the best of the debugging communities (and it probably won't!) but it does have to be an accepting community, willing to allow contributions from anyone and everyone who wishes to contribute.&lt;br /&gt;
&lt;br /&gt;
====Cross-platform design====&lt;br /&gt;
&lt;br /&gt;
Among the design goals of the project, the universal debugger implementation must be able to run on multiple computer platforms and operating systems. This is a difficult undertaking, especially for a program focusing on a graphical user environment. Several bases for cross-platform development already exist, so dealing with intricacies of operating systems can be cut down to a minimum, while retaining a high level of overall product quality.&lt;br /&gt;
&lt;br /&gt;
I have personally researched several offerings for cross-platform frameworks and libraries, and I believe the best choice is the Mozilla platform, [http://developer.mozilla.org/en/XULRunner XULRunner]. XULRunner is still in its infancy, but is already very capable; it's the powerhouse behind the Firefox web browser, which runs on a large percentage of popular operating systems.&lt;br /&gt;
&lt;br /&gt;
Here is a short list of advantages to using XULRunner over just any cross-platform framework:&lt;br /&gt;
&lt;br /&gt;
* XULRunner is Free Software, and its development is community-oriented.&lt;br /&gt;
* Unlike Java and .NET, XULRunner applications are built with native code and have a native look-and-feel (&amp;quot;native&amp;quot; is in reference to the host operating system).&lt;br /&gt;
* Also unlike Java and .NET, XULRunner applications are written in C++, a highly portable and widely used programming language.&lt;br /&gt;
* XULRunner provides many features that Firefox users are already familiar with: scripting with Javascript, application extensibility through &amp;quot;extensions&amp;quot;, networking and popular web protocols support, HTML processing (and a LOT more) with the Gecko layout engine.&lt;br /&gt;
* User interfaces in XULRunner are written in XUL (an XML dialect), styled with CSS, and setup to &amp;quot;do things&amp;quot; with Javascript -- all current web standards. The use of CSS allows the user interface to be &amp;quot;skinned&amp;quot; to a user's personal tastes.&lt;br /&gt;
* UI functionality is mostly implemented with Javascript, but backbone and critical code can be written in C++ and accessed from the Javascript environment.&lt;br /&gt;
&lt;br /&gt;
For a very informative read on the Mozilla platform, I recommend the online book [http://books.mozdev.org/chapters/index.html Creating Applications with Mozilla].&lt;br /&gt;
&lt;br /&gt;
====Internationalized and localized====&lt;br /&gt;
&lt;br /&gt;
Because community strengths are so important to a project of this size and magnitude, the global community becomes an invaluable asset. And as a diverse global community, not everyone will speak or understand a single common language. In this case, I am directly referring to the English language, which is personally my primary language, and the only language I am entirely fluent. Programmers and hackers in a similar situation, though with a different primary language, will benefit from a universal debugger. We should not neglect any user in the community. Making the universal debugger accessible and usable for everybody must be a top priority of the project.&lt;br /&gt;
&lt;br /&gt;
Choosing the Mozilla platform as the application's foundation will play a crucial role in the internationalization of the product. Because the user interface elements are written in an XML dialect, all text can be referenced with DTD entities, just like you might write &amp;amp;amp;gt; in XHTML to print the greater-than sign (&amp;amp;gt;). Likewise, you might write&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;caption label=&amp;quot;&amp;amp;amp;hello;&amp;quot;&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in XUL which would display a label with &amp;quot;Hello&amp;quot; or &amp;quot;こんにちは&amp;quot; depending on the locale set on the user's machine when the XUL application is started.&lt;br /&gt;
&lt;br /&gt;
DTD entities are not magic translators; the text must be translated by a human who is fluent in both (source and destination) languages. However, using DTD entities is a great way to write user interfaces (and other things, like configuration files, for example) without locking the program to a specific language. It also makes the translator's work much easier, since all text strings which require translation will be neatly stored in a single location.&lt;br /&gt;
&lt;br /&gt;
Having the capability to bring a universal debugger to anyone, no matter their ethnic background, will help to expand the debugger's user base and ultimately its supporting community of developers. Designed from the beginning with breaking language barriers in mind, there should be few stumbling points along the road to the success of reaching this goal.&lt;br /&gt;
&lt;br /&gt;
====Accessible for everyone====&lt;br /&gt;
&lt;br /&gt;
On a personal note, I had the chance to tutor someone in hacking a few years ago who told me that he was blind in one eye. This made me realize that we're not all perfectly capable of using most debuggers available in the wild. Most of us hackers can get along fine with them, while a few are left to try their best at making use of such applications.&lt;br /&gt;
&lt;br /&gt;
Mozilla once again comes to the rescue with a modern, mature, stable API for application accessibility. Some examples include integration and coherence with screen readers and voice recognition software. There may not be a great deal of hackers which could make use of these technologies, but having the option available is important to the individuals who would have never thought to bother with debuggers, otherwise.&lt;br /&gt;
&lt;br /&gt;
And let's face grim reality here; I could one day end up physically mangled in a horrible accident, unable to see or use a keyboard or mouse. That won't change my love and desire to continue hacking. I could almost consider debugger accessibility a personal insurance for myself, let alone many hundreds of potential users ''today''.&lt;br /&gt;
&lt;br /&gt;
====Standards compliant====&lt;br /&gt;
&lt;br /&gt;
Standards make the technological world work. And standards compliance makes compatibility issues entirely negligible. This is perhaps the most important point I will make within this documentation: defining a series of open standards to encompass ''all'' foreseeable debugging functionality is a necessity.&lt;br /&gt;
&lt;br /&gt;
The major reason for adopting a standard or series of standards is for compatibility purposes. Compatibility is critical for modular designs. And modularity is an important part of the overall user-configuration and extensibility of an application or sets of applications. Modularity also has the benefit of splitting workloads, as we did previously with GCNrd. Splitting workloads decreases development times, improves communication, and in some cases even improves product quality.&lt;br /&gt;
&lt;br /&gt;
In simpler terms, starting with splitting developer workloads, we all know that it's easier to cover more ground by splitting up. So long as you have a central location to meet up later, this tactic works wonderfully for rapid application development. In the case of developing a debugger, you might typically have one team focusing on the low-level handling of the CPU and hardware, another team tackling the user interface to the low-level debugger, and perhaps a third team covering the protocol between the two.&lt;br /&gt;
&lt;br /&gt;
I realize that the &amp;quot;third team&amp;quot; in this example is most likely set aside as another task for the first team in the real world. But if your project does require some sort of communication layer and you pull that out of the first team's hands, you can effectively pass that responsibility to a sort of &amp;quot;standards body&amp;quot; who will oversee the development and ''standardization'' of that communication layer. The job of such a body would be to ensure the standard is usable by anyone and for any purpose, generic enough to support all current and foreseeable architectures, and extensible enough to support all unforeseeable future architectures.&lt;br /&gt;
&lt;br /&gt;
The extensibility of the standard would be the most difficult to maintain. While a protocol or communication layer of this sort should be extensible for the reasons listed, it should only be extensible to the extent that any new features added would not break previous features or introduce new compatibility issues with previous designs and implementations of the protocol or communication layer. This means, generally, that the extensibility must remain open and ''optional''; no extended feature should ever be mandatory for any user to implement.&lt;br /&gt;
&lt;br /&gt;
There will undoubtedly be important new technologies which require mandatory extensions to the protocol during the life cycle and evolution of debugging technology. Under these circumstances, the standards body would be responsible for designing and publishing a new major version of the protocol with the new mandatory technologies. Implementers of the protocol, should they choose to support newer major versions, would then be required to implement all mandatory features in order to claim standards compliance of their implementation.&lt;br /&gt;
&lt;br /&gt;
What we need is a standards body; a group of individuals, mostly volunteers or &amp;quot;elected&amp;quot; members, to define and publish a series of standards for debugging modern computer architectures. They will be responsible for taking everyone's concerns from the community into account, and act on those concerns within their design and definition. They will be responsible for knowing that if they fail to do a good job, the community will stop listening to them and they will easily be replaced by anyone who steps up with a better idea.&lt;br /&gt;
&lt;br /&gt;
The goals of the standards body will be defining:&lt;br /&gt;
&lt;br /&gt;
* The ''wire''; how we get data from point A (low-level debugger) to point B (user interface). Ethernet? RS232? ...&lt;br /&gt;
* The ''language''; how our data is interpreted as points A and B speak. XML? JSON? Pure binary packets? ...&lt;br /&gt;
* The ''expansion''; how we can introduce new features without creating vendor locks or introducing incompatibilities. Header/Info/About/Options commands which specify the optional/extended features we support? ...&lt;br /&gt;
&lt;br /&gt;
The goals for us developers will be inheriting some of these responsibilities as we implement these standards, to create a flourishing environment for debugger developers to contribute with innovation and healthy competition.&lt;br /&gt;
&lt;br /&gt;
====Configurable, extensible, and modular====&lt;br /&gt;
&lt;br /&gt;
Debuggers are all about user experience. I say this with honest integrity because debugging, by its very nature, is a difficult task. Making a debugger very simple to use is a bullet point; you don't want to overwhelm a user (who is already working on a very difficult problem) with bad user experience. To improve the user experience, it is important to allow a level of customization among the user interface. Also important is extensibility and modularity, to make it easy for the user to expand the interface to fit her needs, and easy to replace one component with another that she prefers.&lt;br /&gt;
&lt;br /&gt;
Some of the items of the user interface which should be configurable include the overall look-and-feel of the interface (skin), the organization of windows and widgets (tabs, information panes, etc.), and the styles of text, fonts, and [image-]backgrounds used throughout.&lt;br /&gt;
&lt;br /&gt;
The look of the application, as well as the functionality, should be extensible using styling and scripting languages. The Mozilla platform once again becomes an asset as it allows simple integration of CSS and Javascript for the purposes of extending applications based on the platform. Extensions can be written and managed by the user community, much the same way that Firefox extensions are written and distributed. A central management location for extensions would be a great thing to have, but is not necessary to the success of a thriving extension-based sub-community.&lt;br /&gt;
&lt;br /&gt;
Including certain feature sets in the application's base install as pre-installed extensions means that users may uninstall those extensions at will to remove undesired features, or replace those extensions with other extensions that implement comparable (and often better) features. This modular design will help to increase the user experience as well as the user's personal productivity with the application. This, too, can be supported by a thriving extension-based sub-community, and the community at large.&lt;br /&gt;
&lt;br /&gt;
====Advanced debugging technologies====&lt;br /&gt;
&lt;br /&gt;
When built on top of a well-designed, well-documented (and equally well-supported) standard, a debugger could implement advanced techniques and technologies to do things we can only dream of now. Some examples of my dreams:&lt;br /&gt;
&lt;br /&gt;
* The debugger interface records its target's activity using simple standard protocol features such as single stepping, and reading register and memory states. When the user pauses the target, the interface has collected enough information to step ''backwards'' in architecture time. Essentially, a runtime undo feature.&lt;br /&gt;
* The communications layer, being very generic, does not need to know the specifics of how the interface uses the data it is transmitting. A very simple example is that the user might be able to use the interface for capturing audio and video samples from a game running on the target architecture, simply by recording the state of the frame and audio buffers (using simple memory reads supported by the protocol) at a specified interval.&lt;br /&gt;
* The debugger interface allows incoming connections from other users to the debugging session in progress. There is a chat pane where connected users can talk about what they are doing, and they can watch each other scroll through the disassembler listing and making changes to instructions and assembler comments in real time. This &amp;quot;collaborative debugging&amp;quot; feature will be expanded upon in the next section.&lt;br /&gt;
&lt;br /&gt;
Creating &amp;quot;high level&amp;quot; debugging capability out of a limited set of &amp;quot;low level&amp;quot; primitive debugging functions is what makes the idea of a standardized communications layer so appealing to me. The first two examples given in the list above are highly specialized and advanced features built on top of a relatively small and &amp;quot;unexciting&amp;quot; set of functions; Reading and writing registers or parts of the memory map, controlling code flow with instruction stepping, etc. These latter functions are the kinds of things you would ''expect'' any debugger to do. What you might not expect is how these simple functions can be chained together to create very interesting features.&lt;br /&gt;
&lt;br /&gt;
This is where the foundation of standardization really comes into play with a universal debugger. As an example, if your NDS and PS2 both have debuggers implementing a single, standardized protocol, the universal debugger only needs to differentiate the two by their architectures. That is, the CPU type and configuration, register maps, memory maps, hardware I/O maps, etc. And once the architectures are known to the universal debugger, it can run the same advanced features (stepping backward, rewinding execution, audio/video recording, etc.) on both; just by using slightly different interpretations of the data it receives over the communication layer. No need for anyone to write a whole new codebase or interface; no more reinventing the wheel.&lt;br /&gt;
&lt;br /&gt;
With these kinds of extraordinary possibilities in mind, I can only expect standardization to be the only way forward in the subtle world of debugging modern computer architectures.&lt;br /&gt;
&lt;br /&gt;
====Encouraging community activity====&lt;br /&gt;
&lt;br /&gt;
Having an entire community to back a project of this type will be incredibly important. Communities are seeded with an idea, and nurtured with equal opportunity to participate. In order to allow greater community participation, I believe it is essential that the project encourage activity as much as the community itself does. One way to accomplish this is by including program features which directly involve multiple users to collaborate with each other.&lt;br /&gt;
&lt;br /&gt;
Two quotations come to mind in the spirit of collaborative debugging:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;quot;Debugging is parallelizable&amp;quot;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;quot;Given enough eyes, all bugs are shallow.&amp;quot;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first is a direct reference to multiple users working on debugging the same item, in parallel. The latter quote is slightly on the opposite; it means that you can have multiple users covering more ground by looking at different pieces of the code being debugged, and viewed from their own personal perspective on the problem. These are both great ideas to employ for large or difficult problems that many projects will face. The only problem is, it's usually handled with an &amp;quot;every man for himself&amp;quot; mentality. Multiple people running their own copies of the target, being debugged with their own debuggers, keeping their own notes, and writing and testing their own patches. All in solemn solitude.&lt;br /&gt;
&lt;br /&gt;
Why not take these two ideas one more step to the extreme? We can have several eyes on the same code, so let's also put several eyes on the same debugging session. Let's parallelize the debugging process with several minds double-checking each others work in real time, as they work; providing ideas and suggestions, and introducing patches directly into the stream for immediate testing.&lt;br /&gt;
&lt;br /&gt;
This would be done with similar ideas to those employed by today's collaborative text editors [http://gobby.0x539.de/trac] [http://www.codingmonkeys.de/subethaengine]. Indeed, the universal debugger itself must be a type of editor; users need to make modifications to code and data in real time, while the target is paused, or for those who enjoy living dangerously, while the target runs its program under normal execution.&lt;br /&gt;
&lt;br /&gt;
How would this work? Well, one user, Hacker Sue, would begin a debugging session by connecting to her target over the standard communications layer, and she would then host the session as a server over plain old TCP/IP. She would invite other users to join her session in progress, and she would be notified when others attempt to make a connection. For reasons of practical security, these connections should be authenticated and encrypted with SSL or similar. She may choose to allow a connection from Hacker Joe only once, or she may agree to &amp;quot;remember&amp;quot; his public key/encryption certificate. Perhaps even more importantly, she may choose to reject all connection requests from Hacker Joe.&lt;br /&gt;
&lt;br /&gt;
Now that Hacker Joe has successfully connected and authenticated with Hacker Sue's debugging session, they set to work. The debugger interface contains a chat pane during hosted sessions, so they are able to talk about what they are seeing and doing. The interface also has &amp;quot;user markers&amp;quot; displayed within its content windows, like the disassembler and the memory editor. These user markers would provide a visual indication of what each user is currently looking at in the target. They could also provide a quick method to &amp;quot;jump&amp;quot; the view to the other users' view ports, and could even be &amp;quot;pinned&amp;quot; or made static; a way to automatically follow someone's view port as they move around in the code.&lt;br /&gt;
&lt;br /&gt;
Hacker Sue and Hacker Joe can now both control the target, stepping through code and watching how it works. They can also change data in memory and instructions within the CPU's code flow path. Each change made will be highlighted in colors specific to each user. They can't undo each others' work through standard-undo commands, but they can patch it just like any other data.&lt;br /&gt;
&lt;br /&gt;
After a long debugging session, both users are making good progress. But Hacker Joe starts doing a tedious and repetitive task of changing every other byte in a 10KB section of memory to the hex value 0x01. He suggests to Hacker Sue that this would be much easier if they both work on a different piece of the editing at the same time. Hacker Sue has a better idea: She knows a script can be written that will do all the work for them, but she's not quite sure how to do it. Hacker Joe writes a simple script in the script editor, and submits it to Hacker Sue to run. After Hacker Sue fixes some typos and potential bugs, she likes the script and saves it as a macro to the session. When Hacker Joe runs the script, and Hacker Sue agrees, the tedious task is completed in a fraction of a second.&lt;br /&gt;
&lt;br /&gt;
This scenario highlights an interesting concept of collaborative scripting within a debugging session. The importance of an authentication and encryption scheme over this TCP/IP connection becomes apparent: With access to scripting capabilities and low-level access to programs running on the target machine (some times this target machine may be the same as the host machine!) security will be of utmost importance. That could be Hacker Sue's computer that Hacker Joe has complete access to. It is important to secure such collaborative debugging as best as possible, but then again the true security of this model will all come down to real trust.&lt;br /&gt;
&lt;br /&gt;
Scripting and macros should be written and run with a kind of &amp;quot;approval&amp;quot; model. A script editor built into the interface would provide similar collaborative editing, where everyone can see what's being written and edited. It would then give the debugger host the final say for what becomes a runnable macro or not, and she also has the final say over who can run the available macros, and when.&lt;br /&gt;
&lt;br /&gt;
There is an incredible potential to include an entire community in not only developing a universal debugger interface, but also including anyone from the community to contribute to the work done ''with'' the tool they are developing. This is a fine point which would provide many new advantages to an already self-sustaining open source community.&lt;br /&gt;
&lt;br /&gt;
===Use-case scenarios===&lt;br /&gt;
&lt;br /&gt;
This section will cover some simple use-case scenarios to serve as examples of what kind of advantages we may find in the application of similar technologies. These scenarios will be written in story format, and will be kept concise.&lt;br /&gt;
&lt;br /&gt;
====The custom interface====&lt;br /&gt;
&lt;br /&gt;
Hacker Joe downloads a debugger for PS2 from the internet. The debugger supports the universal debugger protocol, and comes with a simple debugger interface that he can use to connect to his PS2 from his Windows PC. After using the interface for a few days, he's annoyed by its lack of features. Even though it is an open source interface written in Java, he doesn't like Java and will not add the features himself. Luckily, Hacker Joe knows and trusts C++ and has documentation on the universal debugger protocol (documentation of the spec is a key feature for its use), so he sets out to write his own simple interface.&lt;br /&gt;
&lt;br /&gt;
With the help of the universal debugger protocol documentation and an open source library for it that other users in the community have written, Hacker Joe is able to build his own interface with his own programming language and the help of the community. No Java required.&lt;br /&gt;
&lt;br /&gt;
====Choices, choices====&lt;br /&gt;
&lt;br /&gt;
Hacker Sue likes debugging GBA. So do a lot of other hackers. This means there are a lot of debugger interfaces she can choose from. When she finds one she likes, she can use it on GBA hardware with her favorite low-level debugger. She can also use it on her favorite GBA emulator with universal debugger support.&lt;br /&gt;
&lt;br /&gt;
Internally, these two low-level debuggers use different means of connecting to the interface (RS232 vs IPC, for example) but neither side knows about it or cares; the universal debugger protocol handles the details almost transparently.&lt;br /&gt;
&lt;br /&gt;
When a newer, prettier, more promising interface comes out, Hacker Sue can switch to it without problems. This is the power of interchangeability and modularity, and she likes it.&lt;br /&gt;
&lt;br /&gt;
====One debugger to rule them all====&lt;br /&gt;
&lt;br /&gt;
Hacker Tom wrote a universal debugger interface; it supports 32 architectures and runs on 5 different operating systems. When a new low-level debugger is created for a new architecture, Hacker Tom just has to make some small adjustments to his One Debugger to Rule Them All; maybe add a new disassembler, and he's able to use all of his spiffy debugging features on a 33rd architecture. All in about an hour.&lt;br /&gt;
&lt;br /&gt;
====Leveraging existing technology====&lt;br /&gt;
&lt;br /&gt;
Hacker Kim is writing a low-level debugger for i686. She heard about the universal debugger protocol, and decides to give it a try. She uses an open source library to handle the universal debugger protocol, because this is the easiest solution. The existing debugger interfaces for i686 are perfect; she doesn't have to write her own interface, so she can spend more time on her low-level debugger. She's also very impressed when she discovers she can connect to her debugger over TCP/IP without making any changes to the source. This allows her debugger to be self-hosting; capable of debugging a second instance of itself on a sandbox machine, without interfering with her development machine.&lt;br /&gt;
&lt;br /&gt;
====Automagic rollover====&lt;br /&gt;
&lt;br /&gt;
Hacker Ted spends months perfecting a low-level debugger he has been adding to a fast, lightweight NES emulator. Rather than write the debugger interface with an OS-dependent user interface API, he gets his friend, Hacker Liz, to write the interface as a separate application. They decide to use the universal debugger protocol to communicate between the two applications.&lt;br /&gt;
&lt;br /&gt;
After a few years, it becomes apparent that Hacker Ted's choice of emulator wasn't the best foundation for his debugger; the emulator runs fast and generally works well for most NES games. But because of some subtle inaccuracies in emulation, there are a few very challenging problems that cannot be debugged. Hacker Ted needs to optimize his homebrew NES game to perform complex artificial intelligence, special video tricks which rely heavily on timing the assembly code exactly in sync with the PPU, and many other fancy effects. Unfortunately, the emulator he is doing his debugging in is not quite accurate enough to run his homebrew game exactly like it does on actual NES hardware, so debugging it is impossible.&lt;br /&gt;
&lt;br /&gt;
Luckily, by this time there are several new NES emulators available which are considered super-accurate (at the cost of blazing fast emulation speed). Hacker Ted decides it is worth it to take the speed hit, so he sets about porting his low-level debugger to the new emulator. He's surprised to find that Hacker Liz's interface works beautifully with the new low-level debugger and emulator, and he's now able to find his bug thanks to the super-accurate emulation. Even better, he can switch back to the old emulator when emulation speed is more important than accuracy, and he still has the same pretty debugger interface, no matter where he goes.&lt;br /&gt;
&lt;br /&gt;
===Project implementation===&lt;br /&gt;
&lt;br /&gt;
The implementation of the project will be the final say in how well these ideas work in practice. There is a great deal of work to be done until any of this can be properly realized. And I understand that it will be up to me to do the initial foundational work in implementation; the programming. This section will cover the details and specifications of the project implementation. That's a fancy way of saying I will use this portion of the document to guide you through the stages from preparation to having a useful program.&lt;br /&gt;
&lt;br /&gt;
====Preparation====&lt;br /&gt;
&lt;br /&gt;
This very document is an integral part of the preparation for a fairly large-scale project. I intend to use the material here as a general guide for the project as a whole. It may not cover every situation and problem encountered along the way, but it should contain enough information to keep the project on track through the initial development stages and into the stable development stages. I will also include some thoughts on the future of the project; what I expect to see accomplished possibly far in the future after the code base has grown and had time to mature.&lt;br /&gt;
&lt;br /&gt;
One (of many) of the goals of this document is to gather resources and information from community members who may hold a valuable interest in the Universal Debugger Project's goals. One such resource is the collective brainpower of today's debugger developers. The immediate use of this collective brainpower would be for laying down the groundwork for the series of standards that the rest of the project will comply with and further be based upon. I want this collective brainpower to be assembled as a standards body independently and neutrally of the main project (and its implementation) in order to provide a constructive neutral territory where the standards body may collaborate without prior reservations or bias.&lt;br /&gt;
&lt;br /&gt;
In preparation for this project, I believe it is essential that a group of volunteers or &amp;quot;elected&amp;quot; members of a standards body assemble to define the series of standards necessary to make modular debugging and interoperability possible. This should be considered a top priority considering the success of universal debugging depends on it entirely. However, the programming work on a universal debugger interface can be done in parallel to, or entirely without, a standards body working out the finer details.&lt;br /&gt;
&lt;br /&gt;
Apart from the documentation guidelines and definition of acceptable open standards in debugging, preparation for this project also has dependencies on the base platform we will be working with. The Mozilla platform, [http://developer.mozilla.org/en/XULRunner XULRunner], has been chosen as the base for the project's debugger interface. Several potent references exist for the Mozilla platform, including a complete online book [http://books.mozdev.org/chapters/index.html]. Developers interested in the project's implementation should familiarize themselves with these and other resources.&lt;br /&gt;
&lt;br /&gt;
Familiarity with the following technologies (as applicable to the Mozilla platform) would be beneficial: Javascript, CSS, XHTML, XML, XUL, XBL, XPCOM, C++.&lt;br /&gt;
&lt;br /&gt;
CSS, XUL, and XBL (the latter two being dialects of XML) are useful for building user interfaces on the Mozilla platform. Javascript handles functionality on the user interface elements, and handles data to/from XPCOM. XPCOM is a means to allow Javascript to communicate with (and directly run) functions compiled in C++. Finally, CSS, XHTML, and Javascript are useful for user interface elements rendered with Gecko.&lt;br /&gt;
&lt;br /&gt;
A particularly good example of using XHTML in a Gecko browser widget is with a disassembler: assembly syntax can be highlighted and styled with CSS, subroutines can be contracted and expanded (code folding) with CSS and Javascript. And the entire document can be parsed as an XML document to re-assemble the code at a later time, or to export it to a txt file. Anchors (links) to subroutines and text strings (cross-references) can be clicked on to instantly jump to the relevant code. The browser can be put into &amp;quot;editing mode&amp;quot; to add comments, change instructions, and define new subroutines. Code flow analysis can be visually shown as Bezier curves with arrows pointing to the relevant instructions, drawn within a canvas element. And as with any [X]HTML document, the CSS can be changed to fit the user's tastes.&lt;br /&gt;
&lt;br /&gt;
This use of the Gecko layout engine provides some unique advantages: First, it makes the disassembler super-portable; no need to rewrite platform-specific custom controls that do difficult text layout and line drawing code, not to mention making it all editable. Second, it provides the perfect means to be styled by the user (CSS) any way she likes, and it will always look the same, no matter which operating system it runs on (with the exception of, perhaps, which fonts are installed and which are used by the CSS). Finally, it provides dynamic control over the content via Javascript and DOM manipulation, once again in a completely platform-independent way.&lt;br /&gt;
&lt;br /&gt;
The final element of preparation is defining the naming conventions. It would be unwise to stick to &amp;quot;Universal Debugger Project&amp;quot; because as Lazy|Bastard of [http://www.gshi.org GSHI] publicly points out, the acronym UDP is already synonymous with the popular [http://en.wikipedia.org/wiki/User_Datagram_Protocol User Datagram Protocol]. He goes on to suggest a surrogate for the term &amp;quot;universal&amp;quot; (which is inaccurate at best; think &amp;quot;universal remote&amp;quot;) with the more appropriate term &amp;quot;versatile&amp;quot;. The naming of the project and protocol should be independent and chosen by their respective core contributors. [[Scalable Remote Debugger Protocol]] is the name chosen for the protocol.&lt;br /&gt;
&lt;br /&gt;
The project and protocol will each have a healthy start without settling on a name early on, but I might recommend that, at the very least, temporary code-names are chosen so that they may be referred to during the early development stages. I have no reservation on code-names, so any suggestions would be appreciated. As a final word on project naming, I realize that brands are important. Having an easily recognizable and understandable name will become a priority as the project starts coming into fruition.&lt;br /&gt;
&lt;br /&gt;
====Development====&lt;br /&gt;
&lt;br /&gt;
Initial development requires a great deal of effort. First, I will need a version control system that can handle a fairly large project with a fairly large number of developers. I've decided to go with [http://www.selenic.com/mercurial/wiki/ Mercurial].&lt;br /&gt;
&lt;br /&gt;
I would then devise some coding style guidelines (probably to be hosted on this wiki). Which would define the manner that code is written for the project. It would cover things like indentation style, tab widths, naming conventions... The general idea is to keep the code readable, manageable, and maintainable for all contributors. This document would possibly look similar to the style guidelines I previously wrote for the EnHacklopedia project [http://doc.kodewerx.org/guidelines.html].&lt;br /&gt;
&lt;br /&gt;
Also of importance would be developer- (and eventually user-) documentation. This could also live on the wiki, and would be easy for others to contribute to.&lt;br /&gt;
&lt;br /&gt;
Next I would provide bug tracking software for users and developers to file bug reports, feature/enhancement requests, and a means for developers to track the status of their own points of focus on the project. I've decided on [http://trac.edgewall.org Trac] to track the project.&lt;br /&gt;
&lt;br /&gt;
Finally, it would be a matter of hacking away at the project and making an initial commit to the version control repository. From there, provide a few core developers with commit access and watch the project begin to evolve into a tangible and proven debugger interface.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
===Terminology===&lt;br /&gt;
&lt;br /&gt;
* '''Communications Layer''' - The second part of a two-tier communication system between low-level and high-level debuggers. This layer defines the communications link used between the two, as well as the protocol in which they speak.&lt;br /&gt;
* '''Communications Link''' - A physical wire or wireless process for transmitting data.&lt;br /&gt;
* '''Debugger''' - A generic term for any program which can be used to aid in the study of the low-level inner workings of another program.&lt;br /&gt;
* '''High-Level Debugger''' - Portions and features of the debugger interface which, upon acting on data from the low-level debugger, can perform high-level tasks outside of the scope of the low-level debugger or communications layer.&lt;br /&gt;
* '''Host''' - The computer and operating system hosting the debugger user interface. Can also refer to an emulator or similar software which explicitly hosts a target.&lt;br /&gt;
* '''Low-level Debugger''' - Usually a very small program (debugger stub) either A) compiled into a target program, B) hooked into a precompiled target program with simple runtime patches, or C) compiled into a host program, for example an emulator which supports debugging its emulated programs with universal debuggers.&lt;br /&gt;
* '''Protocol''' - Describes a specific interpretation for data transmitted over a communications link.&lt;br /&gt;
* '''Realtime Debugger''' - A high-level debugger which either itself runs a target, or watches the target run from outside of its own context. The realtime debugger typically has full control over its target, including the data and code of the target itself, as well as when and how the target is run.&lt;br /&gt;
* '''Recursion''' - See ''Recursion''.&lt;br /&gt;
* '''Remote Debugger''' - A target-specific set of low-level and high-level debuggers with each debugger living on different target and host machines.&lt;br /&gt;
* '''Standard''' - A formal technical description, usually written by an independent and neutral group or organization, with the intention of providing a set of mandatory and optional &amp;quot;rules&amp;quot; to be used for the purpose of compatibility. When used by the vast majority, a standard becomes a De-Facto standard.&lt;br /&gt;
* '''Standards Conformance''' - A program which claims to be in conformance with a standard has conformed its non-standard implementation to be compatible with the standard; the program does not fully comply with the standard, but is compatible.&lt;br /&gt;
* '''Standards Compliance''' - Any program which claims to be compliant with a standard is said to have implemented the standard to the best of their ability; the program complies with the standard as-is.&lt;br /&gt;
* '''Static Debugger''' - A program which &amp;quot;debugs&amp;quot; a target without actually running or watching a running target. This is typically a simple disassembler or other kind of high-level view of the data contained within the target.&lt;br /&gt;
* '''Target''' - The computer or device &amp;quot;targeted&amp;quot; by the debugger. This machine often runs a special low-level debugger program to perform debugging actions. The machine's hardware may or may not be emulated.&lt;br /&gt;
* '''Universal Debugger''' - An all-encompassing term to describe the three main pieces of the project: The user interface/high-level host debugger, the low-level target debugger, and the standardized communications layer/universal protocol which they use to speak to one another. Also describes a target- and host-independent series of low- and high-level debuggers which may be used interchangeably anywhere that the universal protocol is supported.&lt;br /&gt;
* '''Universal Debugger Project''' - An initiative to assemble a community willing to pursue the research and development of ideas and standards described within the ''Universal Debugger Project'' documentation.&lt;br /&gt;
* '''Universal Debugger Protocol''' - An open standard definition language to facilitate the use of interchangeable low-level and high-level debuggers; any debugger (high- or low-level) which speaks this language may interact with any other debugger to provide useful results to its users.&lt;br /&gt;
* '''Universal Protocol''' - See ''Universal Debugger Protocol''.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Scalable Remote Debugger Protocol]]&lt;br /&gt;
* [[Debugging Modern Computer Architectures]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Universal_Debugger_Project&amp;diff=1009</id>
		<title>Universal Debugger Project</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Universal_Debugger_Project&amp;diff=1009"/>
				<updated>2010-10-21T07:35:51Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Development */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a reference and general documentation for a project I ([[:User:Parasyte|Parasyte]]) have been interested in pursuing for several years. This article will discuss the project's history, current developments, and future.&lt;br /&gt;
&lt;br /&gt;
I've made an effort to write this document with as little technical jargon as possible. The nature of debuggers and debugging, however, is extremely technical, so it has been difficult to keep it down to a decent reading level. For this reason, I've included an Appendix which should ease the use of language throughout this documentation.&lt;br /&gt;
&lt;br /&gt;
Finally, I hope this information is not too redundant. Some things (examples given, explanations, etc) may be repeated more than once. This document is supposed to be highly detailed, but concise. If you see many repetitious things, please point them out on the discussion page.&lt;br /&gt;
&lt;br /&gt;
==Project history==&lt;br /&gt;
&lt;br /&gt;
I began my research into debuggers sometime in 1999. Things were different back then; computers were just barely able to emulate SNES, even with emulators of the time taking numerous shortcuts to help speed up emulation. At the time, I only knew of one SNES emulator pre-compiled with any kind of debugging functionality, and that was a build of SNES9x (then a chromeless application which was horribly difficult to use) by LordTech. It allowed the user to enable and disable assembly tracing while the game ran. This was a good start; you could see what the game was doing, and gain a lot of information from it. But it was still clunky.&lt;br /&gt;
&lt;br /&gt;
To find the assembly which read or wrote to a specific address, you had to search through (often many megabytes of) text for those addresses. It gave you a good piece of the puzzle, but it did not give you the whole picture. Often many instructions were branched over, and were entirely missing from the log.&lt;br /&gt;
&lt;br /&gt;
A few years later, I had some C programming experience of my own under my belt, and I had also found a new NES emulator called NESten. It wasn't a great NES emulator, but it was decent; it ran most of the NES games I was interested in, and it also had a fairly nice debugger built in! It was during this time that I got my first real taste of debugging. (Previously I experimented with UltraHLE's debugging features, but I don't recall them being much use; it used another &amp;quot;look but don't touch&amp;quot; passive take on debugging.)&lt;br /&gt;
&lt;br /&gt;
NESten's debugger (and the emulator itself) did have some annoying flaws. And after getting sick of it, I decided (like many pioneering hackers before me) to take a decent open source emulator and extend it with some decent debugging capabilities. I chose FCEU (FamiCom Emulator Ultra) by Xodnizel as my base. (Note: FCEU was previously based on FCE, by Bero.) FCEU was a good candidate because it had decent emulation capabilities, and also because it was quite fast; you really need a fast base if you're just going to slow it down with powerful features. And I'll get to that point later.&lt;br /&gt;
&lt;br /&gt;
===FCEUd===&lt;br /&gt;
&lt;br /&gt;
And with that, FCEUd (FCEU-debug) was born. It did not take long to get a stable debugger integrated into the CPU core and hooked up with a little chrome. Seems like it was only 3 or 4 months before it was usable, and a total of 6 months or so development time before I was happy with it. This debugger took all of the major ideas from NESten (including its disassembler syntax for displaying current work addresses) and added some crucial elements that NESten lacked (write breakpoints triggered by INC/DEC instructions, which increment and decrement bytes in memory). I also used ideas from PSX debuggers, such as &amp;quot;step out&amp;quot; which mutually completes the &amp;quot;step in&amp;quot; and &amp;quot;step over&amp;quot; process. And I'll get to that point, again, later.&lt;br /&gt;
&lt;br /&gt;
Since then, FCEUd has been further extended by other members of the emulation/ROM hacking scenes. To this day, FCE has been the most widely forked emulator, in part, because of the work we did extending it from an NES player to an NES development tool. But as you will see, this will bring me to another point later: The work done on FCE-derived forks is very widespread without much communication between parties. Ultimately, it's a mish-mash mix of talent tackling the same ideas from different vantage points without direct collaboration. And I think it's a shame.&lt;br /&gt;
&lt;br /&gt;
===GCNrd===&lt;br /&gt;
&lt;br /&gt;
The main development cycle on FCEUd was during 2002. I learned quite a bit from this project, and it got me interested in debugging other architectures. The next architecture I took on was Nintendo GameCube, officially abbreviated &amp;quot;GCN&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Sometime in 2003, hackers discovered a flaw in the GCN game Phantasy Star Online, which was compatible with the GCN BroadBand Adapter (BBA). This quickly became known as the PSO exploit, and allowed running &amp;quot;homebrew&amp;quot; code on a consumer GCN.&lt;br /&gt;
&lt;br /&gt;
The PSO exploit worked something like this: Hacker Joe sets up his own DNS server, and tells PSO to use that server IP address as its default gateway. This way, PSO asks Hacker Joe's DNS server where it can find Sega's PSO server. Hacker Joe's DNS server tells PSO that Sega's server is located on Hacker Joe's PSO server. PSO happily connects to Hacker Joe's PSO server, which then tells PSO that there is an update available. PSO happily downloads the &amp;quot;PSO loader stub&amp;quot; which is posing as an official update to PSO. PSO happily launches the PSO loader stub which takes over the GCN and begins downloading a larger executable (of Hacker Joe's choice) from Hacker Joe's PSO server. The PSO loader stub then launches Hacker Joe's executable, and Hacker Joe now has total control over his GCN. In short, PSO is tricked by Hacker Joe into running code that it never should have in the first place.&lt;br /&gt;
&lt;br /&gt;
This was a huge breakthrough for GCN hacking. I was in a very poorly state at the time, with no real job and no real income. I was doing work for a certain company selling GBA flash carts. It got me by, but it was a far cry from decent living. I mention this because it means I couldn't afford PSO or a BBA; the two things I needed to begin work on GCN debugging. I had the skill to accomplish it certainly, so I took up donations from members in the community. Only a few responded, but that's all I needed. About $100 USD was enough to pick up the two items I needed, and I was on my way to fame...&lt;br /&gt;
&lt;br /&gt;
====History of GCNrd====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;06-22-03: First GCN AR codes decrypted.&lt;br /&gt;
06-23-03: GCNcrypt v1.0 released.&lt;br /&gt;
06-25-03: First unofficial GCN AR codes released: Sonic Adventure DX (U) codes,&lt;br /&gt;
          by Sappharad.&lt;br /&gt;
06-27-03: GCNcrypt v1.1 released.&lt;br /&gt;
07-03-03: Planning for GCNrd begins.&lt;br /&gt;
07-07-03: GCNrd development begins.&lt;br /&gt;
08-27-03: Development on GCN network library begins.&lt;br /&gt;
08-29-03: First data received from GCN over network, using homebrew network&lt;br /&gt;
          library.&lt;br /&gt;
09-01-03: First data received by GCN over network, using homebrew network&lt;br /&gt;
          library.&lt;br /&gt;
09-13-03: Harddrive crash causes problems. Interest in GCNrd is lost.&lt;br /&gt;
12-31-03: After 3 months without working on GCNrd, aside from the occasional&lt;br /&gt;
          bugfix in the libs, GCNrd development finally continues.&lt;br /&gt;
12-31-03: Milestone #1. First successful RAM dump grabbed from a GCN game using&lt;br /&gt;
          GCNrd. It takes 35.735 seconds to complete.&lt;br /&gt;
12-31-03: BBA is started in 100mbit full duplex mode. Full RAM dump completes&lt;br /&gt;
          in 14.687 seconds.&lt;br /&gt;
01-03-04: Work on screenshot support begins. First successful screenshots are&lt;br /&gt;
          taken from Rayman 3 and Rogue Leader.&lt;br /&gt;
01-12-04: Mario Kart: Double Dash!! (U) is supported by GCNrd. This was the&lt;br /&gt;
          first successful &amp;quot;BBA Reset&amp;quot; patch for a LAN\network-enabled game.&lt;br /&gt;
01-15-04: Milestone #2. GCNrd rightly claims better compatability than Datel's&lt;br /&gt;
          FreeLoader v1.06b.&lt;br /&gt;
01-17-04: All tested games boot! 64 of 64.&lt;br /&gt;
01-19-04: Kenobi begins work on a GUI for GCNrd, making the program a bit&lt;br /&gt;
          easier to use, and adding code search features.&lt;br /&gt;
01-23-04: Milestone #3. First GCN AR code created using only GCNrd and Kenobi's&lt;br /&gt;
          GCNrd GUI. Wave Race: Blue Storm (U), 99 Points, by Knux0rz.&lt;br /&gt;
01-25-04: Started adding breakpoint support. Breaks work for Read, Write, and&lt;br /&gt;
          Read+Write. Execution breakpoints will be next. BPR\W gave me a bit&lt;br /&gt;
          of trouble. The biggest problem I had was getting around the 8-byte&lt;br /&gt;
          boundary which PowerPC uses for data breakpoints. This was completely&lt;br /&gt;
          unacceptable. As an example, if you set a breakpoint on address&lt;br /&gt;
          805E4FF5, a break would be reported every time an address between&lt;br /&gt;
          805E4FF0 - 805E4FF8 was accessed. Even though only one address within&lt;br /&gt;
          that range had a breakpoint set. My current solution to this problem&lt;br /&gt;
          is pretty nasty, but it works. In fact, it only reports a hit if the&lt;br /&gt;
          break addresses match perfectly. Maybe a little inconvenient, but&lt;br /&gt;
          hey!&lt;br /&gt;
03-11-04: GCN CodeType Helper v1.0 released.&lt;br /&gt;
03-11-04: GCNcrypt v1.2 released.&lt;br /&gt;
03-16-04: Finished up breakpoint support today, which should now be 100% fixed.&lt;br /&gt;
          The debugger now waits until just before returning to the game&lt;br /&gt;
          before enabling any r\w breakpoint. This will help bypass any&lt;br /&gt;
          misleading break hits that are caused by the debugger itself. Such as&lt;br /&gt;
          when accessing the stack and etc.&lt;br /&gt;
          New plan in the works to work-around memory constraints. May not work&lt;br /&gt;
          on all games, but should solve all problems with PacMan World 2.&lt;br /&gt;
          Which currently suffers from a nasty crash when accessing the memory&lt;br /&gt;
          card. The crash appears to be caused by how much memory I have&lt;br /&gt;
          allocated for the debugger.&lt;br /&gt;
03-17-04: Work begins on patching AR's code engine. With the patch in place,&lt;br /&gt;
          the code engine will run GCNrd's memory-resident debugger, allowing&lt;br /&gt;
          users to hack games with multiple executables, such as demo discs and&lt;br /&gt;
          the James Bond 007 games.&lt;br /&gt;
03-18-04: Kenobi adds real-time AR code list handling to the GUI. Supported AR&lt;br /&gt;
          versions are v1.06 and v1.08. Support for additional versions will be&lt;br /&gt;
          made available as soon as we receive AR RAM dumps from the other&lt;br /&gt;
          versions.&lt;br /&gt;
03-19-04: Win9x compatibility issues are worked on. GCNrd console now accepts&lt;br /&gt;
          commands passed on the command line. With commands entered on the&lt;br /&gt;
          command line, the console program will exit immediately after&lt;br /&gt;
          completing the requested command. Support for Win9x compatibility in&lt;br /&gt;
          the GUI is limited, but progressing rapidly.&lt;br /&gt;
03-20-04: Support for AR v1.11 completed.&lt;br /&gt;
03-31-04: First public release! GCNrd v1.00b is made available to hackers&lt;br /&gt;
          everywhere.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====GCNrd GUI====&lt;br /&gt;
&lt;br /&gt;
The GUI for GCNrd (Nintendo Gamecube Remote Debugger) was written entirely separately from my own GCNrd development. It was called simply GCNrdGUI and was written by a French hacker, Kenobi, in Delphi. This split up the workload considerably, and also added a new level of modularity to the project overall. The overall GCNrd project consisted of four components:&lt;br /&gt;
&lt;br /&gt;
* GCNrd Loader: The UI that the user is presented with on the GCN itself. The loader is responsible for GCN-side configuration, initializing the network hardware, launching DVDs, and setting up the debugger/hooking the executable.&lt;br /&gt;
* GCNrd debugger: This is a piece that the user never sees, but directly interacts with. It's a very small program (32KB total program code and memory usage) that runs &amp;quot;behind&amp;quot; the game, listening for instructions coming over the network, and acting upon them.&lt;br /&gt;
* GCNrd client: A command-line application run on the user's PC which can be used to send and receive commands and data to/from the debugger over the network.&lt;br /&gt;
* GCNrdGUI: Kenobi's GUI for interacting with the GCNrd client.&lt;br /&gt;
&lt;br /&gt;
It was not necessary for the GUI to interact with the debugger through my CLI client, but that was the option chosen for GCNrdGUI. Later on another hacker, Sappharad, wrote his own GUI in Java which communicated with the debugger directly, bypassing the need for GCNrd client; the modularity of the project comes full circle.&lt;br /&gt;
&lt;br /&gt;
====GCNrd v1.10b and beyond====&lt;br /&gt;
&lt;br /&gt;
GCNrd v1.10b was released July 28th, 2005. It contained a number of bug fixes and new features. Some new features were only shiney on the surface (background images and UI colors in the loader, date/time display...), but some were actually quite important. The MMU handling, for example, allowed hacking games like Star Wars: Rogue Leader, Star Wars: Rebel Strike, and Metal Gear Solid: The Twin Snakes, which used the MMU extensively. It was a slightly rushed released, even though it did show some promise.&lt;br /&gt;
&lt;br /&gt;
This was the last official release I made, along with a private release (only available to close friends) which included some special features like DVD dumping and loading/debugging DVD images over the BBA. This &amp;quot;DVD simulation&amp;quot; was quite advanced for its time, and allowed me (and a few others) to hack downloaded/dumped games. There are often times that the only way to get a copy of a game is downloading it. Either because it was never officially released in your region, or because it hasn't been officially released ''at all''. This private &amp;quot;v1.10b+&amp;quot; version was never made public due to piracy concerns. &lt;br /&gt;
&lt;br /&gt;
Those piracy concerns were actually forfeited after other hackers disabled the DVD booting code in v1.10b to allow debugging DVD-Rs booted with a &amp;quot;Cobra-like&amp;quot; DVD BIOS.&lt;br /&gt;
&lt;br /&gt;
I had plans at one time to rewrite GCNrd so that it could be relocatable within GCN memory. This would solve problems with memory allocation on games that don't play nice. Resident Evil 4 is a good example of such games; it cannot be booted at all by any version of GCNrd. The rewrite would also make the source code legible enough that I could release it under the [http://www.gnu.org/copyleft/gpl.html GPL]. Granted, legibility is not necessary for source code release, but it was important for reasons of maintainability.&lt;br /&gt;
&lt;br /&gt;
GCNrd source code used a wild mix of C and assembly in its main debug core. Escaping the low levels of assembly was impossible, but it could be structured nicely anyway. This wasn't the only problem, of course. Both the loader and debugger had to have their own separate build of the network library. It was too costly (memory-wise) to put the full library into the debugger, even though this would allow the loader to use the debugger for all of its networking tasks.&lt;br /&gt;
&lt;br /&gt;
Instead, the debugger had a very minimal network library; I cut out all of the initialization sequences, all of the CRC code for packet data integrity checking, and a whole lot of other not-completely-necessary packet handling code. It was important to keep the debugger as small as possible so it would not interfere with the game's use of memory.&lt;br /&gt;
&lt;br /&gt;
That gave me two entirely different network stacks to maintain; one was already quite a bit of work, as it was. There was also the problem of compiling the debugger separately from the loader, and then compiling the debugger binary directly into the loader itself.&lt;br /&gt;
&lt;br /&gt;
There are a number of ways these issues could have been addressed, and I'm not going to cover them all. But I will get back to the early point about modularity. As you will see, I am hoping to solve a great deal of these problems using that frame of mind. Needless to say, I never did complete the rewrite of GCNrd, which would have become &amp;quot;GCNrd v2&amp;quot;. But the problems displayed by it were the cornerstones of what was to become the Universal Debugger Project.&lt;br /&gt;
&lt;br /&gt;
===PCS and Mupen 64===&lt;br /&gt;
&lt;br /&gt;
The next year, in 2006, I went back to hacking N64. This was a time when some very interesting N64 hacks were made [http://doc.kodewerx.net/hacking_n64.html#asm_jesus_mode]. By this time, we were all very familiar with Nemu and its debugging/cheating capabilities. The debugger was not bad, but its emulation left quite a bit to be desired. Once again, unhappy with the tools available, I set out to tackle the problem and create my own tools.&lt;br /&gt;
&lt;br /&gt;
The first was [http://doc.kodewerx.net/hacking_n64.html#emulator_pcs Parasytic Cheat Search], a ''video'' plugin for PJ64 (and other emulators compatible with its plugin spec) that allowed cheat searching through the emulator's memory. It contained many bugs and architectural flaws (being a video plugin which passed all video-related messages to a ''real'' video plugin) but it provided a start for me to get into N64 emulator development.&lt;br /&gt;
&lt;br /&gt;
My next N64 project was tackling the debugger problem. Unlike a simple passive cheat searching program, a debugger has to be hooked directly to the CPU to work consistently. Like the FCEUd project years earlier, I wanted to start with a decent open source emulator and extend its capabilities to include decent debugging features.&lt;br /&gt;
&lt;br /&gt;
I chose Mupen 64 as my base, this time. It had relatively high compatibility, stability, and speed. It also contained a debugger for its GTK+ build, which I knew I could use to my advantage. I was still a Win32 programmer at the time; I did not have much experience outside of Windows. Naturally, I focused on Mupen's Windows code, which is where my debugger would live.&lt;br /&gt;
&lt;br /&gt;
After patching Mupen's CPU core (all three of them!) I started implementing the debugger window and all of its fancy widgets. This is when a very bad case of Deja Vu hit me. I had done all of this work before; I was reinventing the wheel. Not good. So I left Mupen 64 with a bare-bones cheat feature (including search) and debugger. This is when I began formulating the idea that debugger interfaces should be modular, just like GCNrd. Then came an avalanche of questions and issues. More on that later.&lt;br /&gt;
&lt;br /&gt;
===NTRrd and Kwurdi===&lt;br /&gt;
&lt;br /&gt;
In 2007, we had Nintendo DS (officially abbreviated NTR, unofficial NDS), and we had a means to hack it thanks to the efforts of the PassMe crew. I did not jump into DS dev quite as enthusiastically as I had GCN, but I eventually got into it and started playing around with ideas to debug the little machine. There were several problems, initially: The first was a communications port. I chose to use the GBA X-port, which was a rather expensive device (especially for video game hackers, who are typically in their teens, and without jobs; in hindsight, it was probably a very bad idea), but it was attractive to me because of its FPGA.&lt;br /&gt;
&lt;br /&gt;
The X-port comes by default with a simple LPT serial port that can be used as a communications link. But it is generally slow and unreliable for large data transfers. On the other hand, the FPGA (and a LOT of IO) can be leveraged to implement a much faster and more stable communications link. And that's exactly what I did, writing custom FPGA logic for a simple 8-bit ECP-mode LPT port. The result was a much faster (~4MB/s ... still much slower than ethernet, WiFi, or USB would have been) and much more reliable (~0.0001% error rate) communications link that I could use to dump NDS memory to perform cheat searching.&lt;br /&gt;
&lt;br /&gt;
The initial result of this work was &amp;quot;NTRrd&amp;quot; (Nintendo DS Remote Debugger) which never saw any kind of release. That's when the ideas from past projects began to meld into an idea well ahead of its time. The idea of a universal debugger. Or at least, a universal debugger interface. So I came up with a silly acronym: KWURDI, for KodeWerx Universal Remote Debugger Interface. And I wanted NTRrd to be its first &amp;quot;client&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The idea was that NTRrd would be a three-piece project: NTRrd loader, NTRrd debugger, NTRrd client. And Kwurdi would be its GUI. The loader would load the debugger, the debugger would talk to the client, and the client would talk to the GUI. That's a lot of levels of abstraction. As it turns out, though, all of those levels are quite important. In fact, it's this level of abstraction and modularity which make this idea of a universal debugger important.&lt;br /&gt;
&lt;br /&gt;
==The universal debugger==&lt;br /&gt;
&lt;br /&gt;
The original article for the Universal Debugger Project can be found in the [[Debugging Modern Computer Architectures]] article. While it covers a good general scope of the idea itself, it does not lay down any foundation other than a very generic description of the roles that each piece of the project ''might'' play. To highlight the main points of the project:&lt;br /&gt;
&lt;br /&gt;
* The universal debugger interface itself is a user interface to allow interaction with a low-level debugger.&lt;br /&gt;
* The low-level debugger may or may not live on the same machine as the universal debugger interface. The universal debugger interface communicates with the low-level debugger through a standard communications link and protocol.&lt;br /&gt;
* The communications link should be an existing standard. For example, UNIX domain sockets or DBUS for a local low-level debugger, and TCP/IP for a remote low-level debugger.&lt;br /&gt;
* The protocol should also be an existing standard, but to this date, there does not appear to be anything which fits the goals of a universal debugger interface. One possibility is [http://www.rfc-archive.org/getrfc.php?rfc=909 RFC-909, Loader Debugger Protocol].&lt;br /&gt;
&lt;br /&gt;
===Project goals===&lt;br /&gt;
&lt;br /&gt;
The long term goals of the Universal Debugger Project include:&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
* Standardization&lt;br /&gt;
&lt;br /&gt;
These items are to be taken as mutually inclusive. For modularity to work, there must be a set of standards in place. For a set of standards to be successful, the modularity granted by the standards must be exploited.&lt;br /&gt;
&lt;br /&gt;
For our purposes, I wish to implement a set of standards for a &amp;quot;universal debugger&amp;quot; with the help of the community, and implement a debugger interface on top of those standards as an example of modularity. The implementation has the following goals:&lt;br /&gt;
&lt;br /&gt;
# It will be Free Software, released under a free software license comparable to the [http://www.gnu.org/copyleft/gpl.html GNU General Public License].&lt;br /&gt;
# It will be a community-oriented project; accepting ideas, patches, code, images, and documentation, among other items, from the community which supports it.&lt;br /&gt;
# It will be designed as a cross-platform application, able to be used on multiple operating systems.&lt;br /&gt;
# It will be built with internationalization and localization in mind; capable of being adapted to different languages.&lt;br /&gt;
# It will be designed to work well with modern accessibility software.&lt;br /&gt;
# It will communicate with and support any low-level debugger which supports the standards defined by the Universal Debugger Project.&lt;br /&gt;
# It will be configurable, extensible, and modular by nature, to support any conceivable current or future architecture.&lt;br /&gt;
# It will support highly advanced debugging techniques and bleeding-edge technologies to get the most out of the user's debugging experience.&lt;br /&gt;
# It will support and encourage community activity through collaborative debugging.&lt;br /&gt;
&lt;br /&gt;
I will cover these points one at a time in more detail:&lt;br /&gt;
&lt;br /&gt;
====Free software====&lt;br /&gt;
&lt;br /&gt;
Free Software released under the [http://www.gnu.org/copyleft/gpl.html GNU General Public License] or a comparable license is meant to be community-driven. This means, anyone who wants to participate in the development of the project is free to participate. You don't become a community member by being one of a few elite deemed &amp;quot;worthy&amp;quot;; you become a member simply by joining an active discussion or contributing in some other way.&lt;br /&gt;
&lt;br /&gt;
The source code will be made available for everyone to look at or extend, which benefits from many eyes keeping the code safe and secure, and also from many hands working in parallel to quickly produce a stable product that is free for anyone to use in any way they see fit. These are two of the basic freedoms granted by a Free Software license: Freedom to look at and extent the product, and freedom to use the product in any way. There are many more freedoms granted by Free Software, and if interested you should consult the GPL documentation or other authoritative sources.&lt;br /&gt;
&lt;br /&gt;
====Community-oriented, community-driven====&lt;br /&gt;
&lt;br /&gt;
A community-oriented and community-driven software project benefits from its main source of use: its own users. Such projects become self-sustaining, as their users take the secondary roles of developers. I will not cover many of the details relating to community-oriented or community-driven software, but there are plenty of great resources available for further reading. Some suggested reading includes The Cathedral and the Bazaar [http://www.catb.org/~esr/writings/cathedral-bazaar/cathedral-bazaar/index.html#catbmain] by Eric S. Raymond, the About Mozilla pages [http://www.mozilla.org/about] [http://www.mozilla.org/about/manifesto] [http://www.mozilla.org/mission.html] [http://www.mozilla.org/editorials/mozilla-overview.html], and the online book Open Sources: Voices from the Open Source Revolution [http://oreilly.com/catalog/opensources/book/toc.html], written by many influential people from many open source communities.&lt;br /&gt;
&lt;br /&gt;
As a community-oriented, community-driven project, I believe there is no end to the ways in which we, as a community of programmers and hackers, will be able to debug. This community would ideally involve the active roles of everyone from video game and ROM hackers, application and operating system developers, and people in the field of academic research of computer architectures. It doesn't have to be the biggest and the best of the debugging communities (and it probably won't!) but it does have to be an accepting community, willing to allow contributions from anyone and everyone who wishes to contribute.&lt;br /&gt;
&lt;br /&gt;
====Cross-platform design====&lt;br /&gt;
&lt;br /&gt;
Among the design goals of the project, the universal debugger implementation must be able to run on multiple computer platforms and operating systems. This is a difficult undertaking, especially for a program focusing on a graphical user environment. Several bases for cross-platform development already exist, so dealing with intricacies of operating systems can be cut down to a minimum, while retaining a high level of overall product quality.&lt;br /&gt;
&lt;br /&gt;
I have personally researched several offerings for cross-platform frameworks and libraries, and I believe the best choice is the Mozilla platform, [http://developer.mozilla.org/en/XULRunner XULRunner]. XULRunner is still in its infancy, but is already very capable; it's the powerhouse behind the Firefox web browser, which runs on a large percentage of popular operating systems.&lt;br /&gt;
&lt;br /&gt;
Here is a short list of advantages to using XULRunner over just any cross-platform framework:&lt;br /&gt;
&lt;br /&gt;
* XULRunner is Free Software, and its development is community-oriented.&lt;br /&gt;
* Unlike Java and .NET, XULRunner applications are built with native code and have a native look-and-feel (&amp;quot;native&amp;quot; is in reference to the host operating system).&lt;br /&gt;
* Also unlike Java and .NET, XULRunner applications are written in C++, a highly portable and widely used programming language.&lt;br /&gt;
* XULRunner provides many features that Firefox users are already familiar with: scripting with Javascript, application extensibility through &amp;quot;extensions&amp;quot;, networking and popular web protocols support, HTML processing (and a LOT more) with the Gecko layout engine.&lt;br /&gt;
* User interfaces in XULRunner are written in XUL (an XML dialect), styled with CSS, and setup to &amp;quot;do things&amp;quot; with Javascript -- all current web standards. The use of CSS allows the user interface to be &amp;quot;skinned&amp;quot; to a user's personal tastes.&lt;br /&gt;
* UI functionality is mostly implemented with Javascript, but backbone and critical code can be written in C++ and accessed from the Javascript environment.&lt;br /&gt;
&lt;br /&gt;
For a very informative read on the Mozilla platform, I recommend the online book [http://books.mozdev.org/chapters/index.html Creating Applications with Mozilla].&lt;br /&gt;
&lt;br /&gt;
====Internationalized and localized====&lt;br /&gt;
&lt;br /&gt;
Because community strengths are so important to a project of this size and magnitude, the global community becomes an invaluable asset. And as a diverse global community, not everyone will speak or understand a single common language. In this case, I am directly referring to the English language, which is personally my primary language, and the only language I am entirely fluent. Programmers and hackers in a similar situation, though with a different primary language, will benefit from a universal debugger. We should not neglect any user in the community. Making the universal debugger accessible and usable for everybody must be a top priority of the project.&lt;br /&gt;
&lt;br /&gt;
Choosing the Mozilla platform as the application's foundation will play a crucial role in the internationalization of the product. Because the user interface elements are written in an XML dialect, all text can be referenced with DTD entities, just like you might write &amp;amp;amp;gt; in XHTML to print the greater-than sign (&amp;amp;gt;). Likewise, you might write&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;caption label=&amp;quot;&amp;amp;amp;hello;&amp;quot;&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in XUL which would display a label with &amp;quot;Hello&amp;quot; or &amp;quot;こんにちは&amp;quot; depending on the locale set on the user's machine when the XUL application is started.&lt;br /&gt;
&lt;br /&gt;
DTD entities are not magic translators; the text must be translated by a human who is fluent in both (source and destination) languages. However, using DTD entities is a great way to write user interfaces (and other things, like configuration files, for example) without locking the program to a specific language. It also makes the translator's work much easier, since all text strings which require translation will be neatly stored in a single location.&lt;br /&gt;
&lt;br /&gt;
Having the capability to bring a universal debugger to anyone, no matter their ethnic background, will help to expand the debugger's user base and ultimately its supporting community of developers. Designed from the beginning with breaking language barriers in mind, there should be few stumbling points along the road to the success of reaching this goal.&lt;br /&gt;
&lt;br /&gt;
====Accessible for everyone====&lt;br /&gt;
&lt;br /&gt;
On a personal note, I had the chance to tutor someone in hacking a few years ago who told me that he was blind in one eye. This made me realize that we're not all perfectly capable of using most debuggers available in the wild. Most of us hackers can get along fine with them, while a few are left to try their best at making use of such applications.&lt;br /&gt;
&lt;br /&gt;
Mozilla once again comes to the rescue with a modern, mature, stable API for application accessibility. Some examples include integration and coherence with screen readers and voice recognition software. There may not be a great deal of hackers which could make use of these technologies, but having the option available is important to the individuals who would have never thought to bother with debuggers, otherwise.&lt;br /&gt;
&lt;br /&gt;
And let's face grim reality here; I could one day end up physically mangled in a horrible accident, unable to see or use a keyboard or mouse. That won't change my love and desire to continue hacking. I could almost consider debugger accessibility a personal insurance for myself, let alone many hundreds of potential users ''today''.&lt;br /&gt;
&lt;br /&gt;
====Standards compliant====&lt;br /&gt;
&lt;br /&gt;
Standards make the technological world work. And standards compliance makes compatibility issues entirely negligible. This is perhaps the most important point I will make within this documentation: defining a series of open standards to encompass ''all'' foreseeable debugging functionality is a necessity.&lt;br /&gt;
&lt;br /&gt;
The major reason for adopting a standard or series of standards is for compatibility purposes. Compatibility is critical for modular designs. And modularity is an important part of the overall user-configuration and extensibility of an application or sets of applications. Modularity also has the benefit of splitting workloads, as we did previously with GCNrd. Splitting workloads decreases development times, improves communication, and in some cases even improves product quality.&lt;br /&gt;
&lt;br /&gt;
In simpler terms, starting with splitting developer workloads, we all know that it's easier to cover more ground by splitting up. So long as you have a central location to meet up later, this tactic works wonderfully for rapid application development. In the case of developing a debugger, you might typically have one team focusing on the low-level handling of the CPU and hardware, another team tackling the user interface to the low-level debugger, and perhaps a third team covering the protocol between the two.&lt;br /&gt;
&lt;br /&gt;
I realize that the &amp;quot;third team&amp;quot; in this example is most likely set aside as another task for the first team in the real world. But if your project does require some sort of communication layer and you pull that out of the first team's hands, you can effectively pass that responsibility to a sort of &amp;quot;standards body&amp;quot; who will oversee the development and ''standardization'' of that communication layer. The job of such a body would be to ensure the standard is usable by anyone and for any purpose, generic enough to support all current and foreseeable architectures, and extensible enough to support all unforeseeable future architectures.&lt;br /&gt;
&lt;br /&gt;
The extensibility of the standard would be the most difficult to maintain. While a protocol or communication layer of this sort should be extensible for the reasons listed, it should only be extensible to the extent that any new features added would not break previous features or introduce new compatibility issues with previous designs and implementations of the protocol or communication layer. This means, generally, that the extensibility must remain open and ''optional''; no extended feature should ever be mandatory for any user to implement.&lt;br /&gt;
&lt;br /&gt;
There will undoubtedly be important new technologies which require mandatory extensions to the protocol during the life cycle and evolution of debugging technology. Under these circumstances, the standards body would be responsible for designing and publishing a new major version of the protocol with the new mandatory technologies. Implementers of the protocol, should they choose to support newer major versions, would then be required to implement all mandatory features in order to claim standards compliance of their implementation.&lt;br /&gt;
&lt;br /&gt;
What we need is a standards body; a group of individuals, mostly volunteers or &amp;quot;elected&amp;quot; members, to define and publish a series of standards for debugging modern computer architectures. They will be responsible for taking everyone's concerns from the community into account, and act on those concerns within their design and definition. They will be responsible for knowing that if they fail to do a good job, the community will stop listening to them and they will easily be replaced by anyone who steps up with a better idea.&lt;br /&gt;
&lt;br /&gt;
The goals of the standards body will be defining:&lt;br /&gt;
&lt;br /&gt;
* The ''wire''; how we get data from point A (low-level debugger) to point B (user interface). Ethernet? RS232? ...&lt;br /&gt;
* The ''language''; how our data is interpreted as points A and B speak. XML? JSON? Pure binary packets? ...&lt;br /&gt;
* The ''expansion''; how we can introduce new features without creating vendor locks or introducing incompatibilities. Header/Info/About/Options commands which specify the optional/extended features we support? ...&lt;br /&gt;
&lt;br /&gt;
The goals for us developers will be inheriting some of these responsibilities as we implement these standards, to create a flourishing environment for debugger developers to contribute with innovation and healthy competition.&lt;br /&gt;
&lt;br /&gt;
====Configurable, extensible, and modular====&lt;br /&gt;
&lt;br /&gt;
Debuggers are all about user experience. I say this with honest integrity because debugging, by its very nature, is a difficult task. Making a debugger very simple to use is a bullet point; you don't want to overwhelm a user (who is already working on a very difficult problem) with bad user experience. To improve the user experience, it is important to allow a level of customization among the user interface. Also important is extensibility and modularity, to make it easy for the user to expand the interface to fit her needs, and easy to replace one component with another that she prefers.&lt;br /&gt;
&lt;br /&gt;
Some of the items of the user interface which should be configurable include the overall look-and-feel of the interface (skin), the organization of windows and widgets (tabs, information panes, etc.), and the styles of text, fonts, and [image-]backgrounds used throughout.&lt;br /&gt;
&lt;br /&gt;
The look of the application, as well as the functionality, should be extensible using styling and scripting languages. The Mozilla platform once again becomes an asset as it allows simple integration of CSS and Javascript for the purposes of extending applications based on the platform. Extensions can be written and managed by the user community, much the same way that Firefox extensions are written and distributed. A central management location for extensions would be a great thing to have, but is not necessary to the success of a thriving extension-based sub-community.&lt;br /&gt;
&lt;br /&gt;
Including certain feature sets in the application's base install as pre-installed extensions means that users may uninstall those extensions at will to remove undesired features, or replace those extensions with other extensions that implement comparable (and often better) features. This modular design will help to increase the user experience as well as the user's personal productivity with the application. This, too, can be supported by a thriving extension-based sub-community, and the community at large.&lt;br /&gt;
&lt;br /&gt;
====Advanced debugging technologies====&lt;br /&gt;
&lt;br /&gt;
When built on top of a well-designed, well-documented (and equally well-supported) standard, a debugger could implement advanced techniques and technologies to do things we can only dream of now. Some examples of my dreams:&lt;br /&gt;
&lt;br /&gt;
* The debugger interface records its target's activity using simple standard protocol features such as single stepping, and reading register and memory states. When the user pauses the target, the interface has collected enough information to step ''backwards'' in architecture time. Essentially, a runtime undo feature.&lt;br /&gt;
* The communications layer, being very generic, does not need to know the specifics of how the interface uses the data it is transmitting. A very simple example is that the user might be able to use the interface for capturing audio and video samples from a game running on the target architecture, simply by recording the state of the frame and audio buffers (using simple memory reads supported by the protocol) at a specified interval.&lt;br /&gt;
* The debugger interface allows incoming connections from other users to the debugging session in progress. There is a chat pane where connected users can talk about what they are doing, and they can watch each other scroll through the disassembler listing and making changes to instructions and assembler comments in real time. This &amp;quot;collaborative debugging&amp;quot; feature will be expanded upon in the next section.&lt;br /&gt;
&lt;br /&gt;
Creating &amp;quot;high level&amp;quot; debugging capability out of a limited set of &amp;quot;low level&amp;quot; primitive debugging functions is what makes the idea of a standardized communications layer so appealing to me. The first two examples given in the list above are highly specialized and advanced features built on top of a relatively small and &amp;quot;unexciting&amp;quot; set of functions; Reading and writing registers or parts of the memory map, controlling code flow with instruction stepping, etc. These latter functions are the kinds of things you would ''expect'' any debugger to do. What you might not expect is how these simple functions can be chained together to create very interesting features.&lt;br /&gt;
&lt;br /&gt;
This is where the foundation of standardization really comes into play with a universal debugger. As an example, if your NDS and PS2 both have debuggers implementing a single, standardized protocol, the universal debugger only needs to differentiate the two by their architectures. That is, the CPU type and configuration, register maps, memory maps, hardware I/O maps, etc. And once the architectures are known to the universal debugger, it can run the same advanced features (stepping backward, rewinding execution, audio/video recording, etc.) on both; just by using slightly different interpretations of the data it receives over the communication layer. No need for anyone to write a whole new codebase or interface; no more reinventing the wheel.&lt;br /&gt;
&lt;br /&gt;
With these kinds of extraordinary possibilities in mind, I can only expect standardization to be the only way forward in the subtle world of debugging modern computer architectures.&lt;br /&gt;
&lt;br /&gt;
====Encouraging community activity====&lt;br /&gt;
&lt;br /&gt;
Having an entire community to back a project of this type will be incredibly important. Communities are seeded with an idea, and nurtured with equal opportunity to participate. In order to allow greater community participation, I believe it is essential that the project encourage activity as much as the community itself does. One way to accomplish this is by including program features which directly involve multiple users to collaborate with each other.&lt;br /&gt;
&lt;br /&gt;
Two quotations come to mind in the spirit of collaborative debugging:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;quot;Debugging is parallelizable&amp;quot;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;quot;Given enough eyes, all bugs are shallow.&amp;quot;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first is a direct reference to multiple users working on debugging the same item, in parallel. The latter quote is slightly on the opposite; it means that you can have multiple users covering more ground by looking at different pieces of the code being debugged, and viewed from their own personal perspective on the problem. These are both great ideas to employ for large or difficult problems that many projects will face. The only problem is, it's usually handled with an &amp;quot;every man for himself&amp;quot; mentality. Multiple people running their own copies of the target, being debugged with their own debuggers, keeping their own notes, and writing and testing their own patches. All in solemn solitude.&lt;br /&gt;
&lt;br /&gt;
Why not take these two ideas one more step to the extreme? We can have several eyes on the same code, so let's also put several eyes on the same debugging session. Let's parallelize the debugging process with several minds double-checking each others work in real time, as they work; providing ideas and suggestions, and introducing patches directly into the stream for immediate testing.&lt;br /&gt;
&lt;br /&gt;
This would be done with similar ideas to those employed by today's collaborative text editors [http://gobby.0x539.de/trac] [http://www.codingmonkeys.de/subethaengine]. Indeed, the universal debugger itself must be a type of editor; users need to make modifications to code and data in real time, while the target is paused, or for those who enjoy living dangerously, while the target runs its program under normal execution.&lt;br /&gt;
&lt;br /&gt;
How would this work? Well, one user, Hacker Sue, would begin a debugging session by connecting to her target over the standard communications layer, and she would then host the session as a server over plain old TCP/IP. She would invite other users to join her session in progress, and she would be notified when others attempt to make a connection. For reasons of practical security, these connections should be authenticated and encrypted with SSL or similar. She may choose to allow a connection from Hacker Joe only once, or she may agree to &amp;quot;remember&amp;quot; his public key/encryption certificate. Perhaps even more importantly, she may choose to reject all connection requests from Hacker Joe.&lt;br /&gt;
&lt;br /&gt;
Now that Hacker Joe has successfully connected and authenticated with Hacker Sue's debugging session, they set to work. The debugger interface contains a chat pane during hosted sessions, so they are able to talk about what they are seeing and doing. The interface also has &amp;quot;user markers&amp;quot; displayed within its content windows, like the disassembler and the memory editor. These user markers would provide a visual indication of what each user is currently looking at in the target. They could also provide a quick method to &amp;quot;jump&amp;quot; the view to the other users' view ports, and could even be &amp;quot;pinned&amp;quot; or made static; a way to automatically follow someone's view port as they move around in the code.&lt;br /&gt;
&lt;br /&gt;
Hacker Sue and Hacker Joe can now both control the target, stepping through code and watching how it works. They can also change data in memory and instructions within the CPU's code flow path. Each change made will be highlighted in colors specific to each user. They can't undo each others' work through standard-undo commands, but they can patch it just like any other data.&lt;br /&gt;
&lt;br /&gt;
After a long debugging session, both users are making good progress. But Hacker Joe starts doing a tedious and repetitive task of changing every other byte in a 10KB section of memory to the hex value 0x01. He suggests to Hacker Sue that this would be much easier if they both work on a different piece of the editing at the same time. Hacker Sue has a better idea: She knows a script can be written that will do all the work for them, but she's not quite sure how to do it. Hacker Joe writes a simple script in the script editor, and submits it to Hacker Sue to run. After Hacker Sue fixes some typos and potential bugs, she likes the script and saves it as a macro to the session. When Hacker Joe runs the script, and Hacker Sue agrees, the tedious task is completed in a fraction of a second.&lt;br /&gt;
&lt;br /&gt;
This scenario highlights an interesting concept of collaborative scripting within a debugging session. The importance of an authentication and encryption scheme over this TCP/IP connection becomes apparent: With access to scripting capabilities and low-level access to programs running on the target machine (some times this target machine may be the same as the host machine!) security will be of utmost importance. That could be Hacker Sue's computer that Hacker Joe has complete access to. It is important to secure such collaborative debugging as best as possible, but then again the true security of this model will all come down to real trust.&lt;br /&gt;
&lt;br /&gt;
Scripting and macros should be written and run with a kind of &amp;quot;approval&amp;quot; model. A script editor built into the interface would provide similar collaborative editing, where everyone can see what's being written and edited. It would then give the debugger host the final say for what becomes a runnable macro or not, and she also has the final say over who can run the available macros, and when.&lt;br /&gt;
&lt;br /&gt;
There is an incredible potential to include an entire community in not only developing a universal debugger interface, but also including anyone from the community to contribute to the work done ''with'' the tool they are developing. This is a fine point which would provide many new advantages to an already self-sustaining open source community.&lt;br /&gt;
&lt;br /&gt;
===Use-case scenarios===&lt;br /&gt;
&lt;br /&gt;
This section will cover some simple use-case scenarios to serve as examples of what kind of advantages we may find in the application of similar technologies. These scenarios will be written in story format, and will be kept concise.&lt;br /&gt;
&lt;br /&gt;
====The custom interface====&lt;br /&gt;
&lt;br /&gt;
Hacker Joe downloads a debugger for PS2 from the internet. The debugger supports the universal debugger protocol, and comes with a simple debugger interface that he can use to connect to his PS2 from his Windows PC. After using the interface for a few days, he's annoyed by its lack of features. Even though it is an open source interface written in Java, he doesn't like Java and will not add the features himself. Luckily, Hacker Joe knows and trusts C++ and has documentation on the universal debugger protocol (documentation of the spec is a key feature for its use), so he sets out to write his own simple interface.&lt;br /&gt;
&lt;br /&gt;
With the help of the universal debugger protocol documentation and an open source library for it that other users in the community have written, Hacker Joe is able to build his own interface with his own programming language and the help of the community. No Java required.&lt;br /&gt;
&lt;br /&gt;
====Choices, choices====&lt;br /&gt;
&lt;br /&gt;
Hacker Sue likes debugging GBA. So do a lot of other hackers. This means there are a lot of debugger interfaces she can choose from. When she finds one she likes, she can use it on GBA hardware with her favorite low-level debugger. She can also use it on her favorite GBA emulator with universal debugger support.&lt;br /&gt;
&lt;br /&gt;
Internally, these two low-level debuggers use different means of connecting to the interface (RS232 vs IPC, for example) but neither side knows about it or cares; the universal debugger protocol handles the details almost transparently.&lt;br /&gt;
&lt;br /&gt;
When a newer, prettier, more promising interface comes out, Hacker Sue can switch to it without problems. This is the power of interchangeability and modularity, and she likes it.&lt;br /&gt;
&lt;br /&gt;
====One debugger to rule them all====&lt;br /&gt;
&lt;br /&gt;
Hacker Tom wrote a universal debugger interface; it supports 32 architectures and runs on 5 different operating systems. When a new low-level debugger is created for a new architecture, Hacker Tom just has to make some small adjustments to his One Debugger to Rule Them All; maybe add a new disassembler, and he's able to use all of his spiffy debugging features on a 33rd architecture. All in about an hour.&lt;br /&gt;
&lt;br /&gt;
====Leveraging existing technology====&lt;br /&gt;
&lt;br /&gt;
Hacker Kim is writing a low-level debugger for i686. She heard about the universal debugger protocol, and decides to give it a try. She uses an open source library to handle the universal debugger protocol, because this is the easiest solution. The existing debugger interfaces for i686 are perfect; she doesn't have to write her own interface, so she can spend more time on her low-level debugger. She's also very impressed when she discovers she can connect to her debugger over TCP/IP without making any changes to the source. This allows her debugger to be self-hosting; capable of debugging a second instance of itself on a sandbox machine, without interfering with her development machine.&lt;br /&gt;
&lt;br /&gt;
====Automagic rollover====&lt;br /&gt;
&lt;br /&gt;
Hacker Ted spends months perfecting a low-level debugger he has been adding to a fast, lightweight NES emulator. Rather than write the debugger interface with an OS-dependent user interface API, he gets his friend, Hacker Liz, to write the interface as a separate application. They decide to use the universal debugger protocol to communicate between the two applications.&lt;br /&gt;
&lt;br /&gt;
After a few years, it becomes apparent that Hacker Ted's choice of emulator wasn't the best foundation for his debugger; the emulator runs fast and generally works well for most NES games. But because of some subtle inaccuracies in emulation, there are a few very challenging problems that cannot be debugged. Hacker Ted needs to optimize his homebrew NES game to perform complex artificial intelligence, special video tricks which rely heavily on timing the assembly code exactly in sync with the PPU, and many other fancy effects. Unfortunately, the emulator he is doing his debugging in is not quite accurate enough to run his homebrew game exactly like it does on actual NES hardware, so debugging it is impossible.&lt;br /&gt;
&lt;br /&gt;
Luckily, by this time there are several new NES emulators available which are considered super-accurate (at the cost of blazing fast emulation speed). Hacker Ted decides it is worth it to take the speed hit, so he sets about porting his low-level debugger to the new emulator. He's surprised to find that Hacker Liz's interface works beautifully with the new low-level debugger and emulator, and he's now able to find his bug thanks to the super-accurate emulation. Even better, he can switch back to the old emulator when emulation speed is more important than accuracy, and he still has the same pretty debugger interface, no matter where he goes.&lt;br /&gt;
&lt;br /&gt;
===Project implementation===&lt;br /&gt;
&lt;br /&gt;
The implementation of the project will be the final say in how well these ideas work in practice. There is a great deal of work to be done until any of this can be properly realized. And I understand that it will be up to me to do the initial foundational work in implementation; the programming. This section will cover the details and specifications of the project implementation. That's a fancy way of saying I will use this portion of the document to guide you through the stages from preparation to having a useful program.&lt;br /&gt;
&lt;br /&gt;
====Preparation====&lt;br /&gt;
&lt;br /&gt;
This very document is an integral part of the preparation for a fairly large-scale project. I intend to use the material here as a general guide for the project as a whole. It may not cover every situation and problem encountered along the way, but it should contain enough information to keep the project on track through the initial development stages and into the stable development stages. I will also include some thoughts on the future of the project; what I expect to see accomplished possibly far in the future after the code base has grown and had time to mature.&lt;br /&gt;
&lt;br /&gt;
One (of many) of the goals of this document is to gather resources and information from community members who may hold a valuable interest in the Universal Debugger Project's goals. One such resource is the collective brainpower of today's debugger developers. The immediate use of this collective brainpower would be for laying down the groundwork for the series of standards that the rest of the project will comply with and further be based upon. I want this collective brainpower to be assembled as a standards body independently and neutrally of the main project (and its implementation) in order to provide a constructive neutral territory where the standards body may collaborate without prior reservations or bias.&lt;br /&gt;
&lt;br /&gt;
In preparation for this project, I believe it is essential that a group of volunteers or &amp;quot;elected&amp;quot; members of a standards body assemble to define the series of standards necessary to make modular debugging and interoperability possible. This should be considered a top priority considering the success of universal debugging depends on it entirely. However, the programming work on a universal debugger interface can be done in parallel to, or entirely without, a standards body working out the finer details.&lt;br /&gt;
&lt;br /&gt;
Apart from the documentation guidelines and definition of acceptable open standards in debugging, preparation for this project also has dependencies on the base platform we will be working with. The Mozilla platform, [http://developer.mozilla.org/en/XULRunner XULRunner], has been chosen as the base for the project's debugger interface. Several potent references exist for the Mozilla platform, including a complete online book [http://books.mozdev.org/chapters/index.html]. Developers interested in the project's implementation should familiarize themselves with these and other resources.&lt;br /&gt;
&lt;br /&gt;
Familiarity with the following technologies (as applicable to the Mozilla platform) would be beneficial: Javascript, CSS, XHTML, XML, XUL, XBL, XPCOM, C++.&lt;br /&gt;
&lt;br /&gt;
CSS, XUL, and XBL (the latter two being dialects of XML) are useful for building user interfaces on the Mozilla platform. Javascript handles functionality on the user interface elements, and handles data to/from XPCOM. XPCOM is a means to allow Javascript to communicate with (and directly run) functions compiled in C++. Finally, CSS, XHTML, and Javascript are useful for user interface elements rendered with Gecko.&lt;br /&gt;
&lt;br /&gt;
A particularly good example of using XHTML in a Gecko browser widget is with a disassembler: assembly syntax can be highlighted and styled with CSS, subroutines can be contracted and expanded (code folding) with CSS and Javascript. And the entire document can be parsed as an XML document to re-assemble the code at a later time, or to export it to a txt file. Anchors (links) to subroutines and text strings (cross-references) can be clicked on to instantly jump to the relevant code. The browser can be put into &amp;quot;editing mode&amp;quot; to add comments, change instructions, and define new subroutines. Code flow analysis can be visually shown as Bezier curves with arrows pointing to the relevant instructions, drawn within a canvas element. And as with any [X]HTML document, the CSS can be changed to fit the user's tastes.&lt;br /&gt;
&lt;br /&gt;
This use of the Gecko layout engine provides some unique advantages: First, it makes the disassembler super-portable; no need to rewrite platform-specific custom controls that do difficult text layout and line drawing code, not to mention making it all editable. Second, it provides the perfect means to be styled by the user (CSS) any way she likes, and it will always look the same, no matter which operating system it runs on (with the exception of, perhaps, which fonts are installed and which are used by the CSS). Finally, it provides dynamic control over the content via Javascript and DOM manipulation, once again in a completely platform-independent way.&lt;br /&gt;
&lt;br /&gt;
The final element of preparation is defining the naming conventions. It would be unwise to stick to &amp;quot;Universal Debugger Project&amp;quot; and &amp;quot;Universal Debugger Protocol&amp;quot; because as Lazy|Bastard of [http://www.gshi.org GSHI] publicly points out, the acronym UDP is already synonymous with the popular [http://en.wikipedia.org/wiki/User_Datagram_Protocol User Datagram Protocol]. He goes on to suggest a surrogate for the term &amp;quot;universal&amp;quot; (which is inaccurate at best; think &amp;quot;universal remote&amp;quot;) with the more appropriate term &amp;quot;versatile&amp;quot;. The naming of the project and protocol should be independent and chosen by their respective core contributors.&lt;br /&gt;
&lt;br /&gt;
The project and protocol will each have a healthy start without settling on a name early on, but I might recommend that, at the very least, temporary code-names are chosen so that they may be referred to during the early development stages. I have no reservation on code-names, so any suggestions would be appreciated. As a final word on project naming, I realize that brands are important. Having an easily recognizable and understandable name will become a priority as the project starts coming into fruition.&lt;br /&gt;
&lt;br /&gt;
====Development====&lt;br /&gt;
&lt;br /&gt;
Initial development requires a great deal of effort. First, I will need a version control system that can handle a fairly large project with a fairly large number of developers. I've decided to go with [http://www.selenic.com/mercurial/wiki/ Mercurial].&lt;br /&gt;
&lt;br /&gt;
I would then devise some coding style guidelines (probably to be hosted on this wiki). Which would define the manner that code is written for the project. It would cover things like indentation style, tab widths, naming conventions... The general idea is to keep the code readable, manageable, and maintainable for all contributors. This document would possibly look similar to the style guidelines I previously wrote for the EnHacklopedia project [http://doc.kodewerx.org/guidelines.html].&lt;br /&gt;
&lt;br /&gt;
Also of importance would be developer- (and eventually user-) documentation. This could also live on the wiki, and would be easy for others to contribute to.&lt;br /&gt;
&lt;br /&gt;
Next I would provide bug tracking software for users and developers to file bug reports, feature/enhancement requests, and a means for developers to track the status of their own points of focus on the project. I've decided on [http://trac.edgewall.org Trac] to track the project.&lt;br /&gt;
&lt;br /&gt;
Finally, it would be a matter of hacking away at the project and making an initial commit to the version control repository. From there, provide a few core developers with commit access and watch the project begin to evolve into a tangible and proven debugger interface.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
===Terminology===&lt;br /&gt;
&lt;br /&gt;
* '''Communications Layer''' - The second part of a two-tier communication system between low-level and high-level debuggers. This layer defines the communications link used between the two, as well as the protocol in which they speak.&lt;br /&gt;
* '''Communications Link''' - A physical wire or wireless process for transmitting data.&lt;br /&gt;
* '''Debugger''' - A generic term for any program which can be used to aid in the study of the low-level inner workings of another program.&lt;br /&gt;
* '''High-Level Debugger''' - Portions and features of the debugger interface which, upon acting on data from the low-level debugger, can perform high-level tasks outside of the scope of the low-level debugger or communications layer.&lt;br /&gt;
* '''Host''' - The computer and operating system hosting the debugger user interface. Can also refer to an emulator or similar software which explicitly hosts a target.&lt;br /&gt;
* '''Low-level Debugger''' - Usually a very small program (debugger stub) either A) compiled into a target program, B) hooked into a precompiled target program with simple runtime patches, or C) compiled into a host program, for example an emulator which supports debugging its emulated programs with universal debuggers.&lt;br /&gt;
* '''Protocol''' - Describes a specific interpretation for data transmitted over a communications link.&lt;br /&gt;
* '''Realtime Debugger''' - A high-level debugger which either itself runs a target, or watches the target run from outside of its own context. The realtime debugger typically has full control over its target, including the data and code of the target itself, as well as when and how the target is run.&lt;br /&gt;
* '''Recursion''' - See ''Recursion''.&lt;br /&gt;
* '''Remote Debugger''' - A target-specific set of low-level and high-level debuggers with each debugger living on different target and host machines.&lt;br /&gt;
* '''Standard''' - A formal technical description, usually written by an independent and neutral group or organization, with the intention of providing a set of mandatory and optional &amp;quot;rules&amp;quot; to be used for the purpose of compatibility. When used by the vast majority, a standard becomes a De-Facto standard.&lt;br /&gt;
* '''Standards Conformance''' - A program which claims to be in conformance with a standard has conformed its non-standard implementation to be compatible with the standard; the program does not fully comply with the standard, but is compatible.&lt;br /&gt;
* '''Standards Compliance''' - Any program which claims to be compliant with a standard is said to have implemented the standard to the best of their ability; the program complies with the standard as-is.&lt;br /&gt;
* '''Static Debugger''' - A program which &amp;quot;debugs&amp;quot; a target without actually running or watching a running target. This is typically a simple disassembler or other kind of high-level view of the data contained within the target.&lt;br /&gt;
* '''Target''' - The computer or device &amp;quot;targeted&amp;quot; by the debugger. This machine often runs a special low-level debugger program to perform debugging actions. The machine's hardware may or may not be emulated.&lt;br /&gt;
* '''Universal Debugger''' - An all-encompassing term to describe the three main pieces of the project: The user interface/high-level host debugger, the low-level target debugger, and the standardized communications layer/universal protocol which they use to speak to one another. Also describes a target- and host-independent series of low- and high-level debuggers which may be used interchangeably anywhere that the universal protocol is supported.&lt;br /&gt;
* '''Universal Debugger Project''' - An initiative to assemble a community willing to pursue the research and development of ideas and standards described within the ''Universal Debugger Project'' documentation.&lt;br /&gt;
* '''Universal Debugger Protocol''' - An open standard definition language to facilitate the use of interchangeable low-level and high-level debuggers; any debugger (high- or low-level) which speaks this language may interact with any other debugger to provide useful results to its users.&lt;br /&gt;
* '''Universal Protocol''' - See ''Universal Debugger Protocol''.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Scalable Remote Debugger Protocol]]&lt;br /&gt;
* [[Debugging Modern Computer Architectures]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Syndrome&amp;diff=1008</id>
		<title>Syndrome</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Syndrome&amp;diff=1008"/>
				<updated>2010-10-21T07:31:05Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Building */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Syndrome is a level editor for the Mega Man 7 SNES game. Syndrome has undergone 2 complete rewrites since the project began (three iterations in all). The most recent rewrite makes it platform independent, with main development taking place mostly on Mac OS X.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
&lt;br /&gt;
Work on Syndrome began on September 25, 2002 as a Visual Studio 6 MFC project. The screenshots below depict two different builds of the interface. On the left, an older version showing the first time a complete screen was rendered. On the right, a newer version with some tile issues fixed (also with transparency rendered in pink) and an empty sidebar added (once planned to become a toolbox):&lt;br /&gt;
&lt;br /&gt;
[[Image:Syndrome.png]] [[Image:Syndrome2.png]]&lt;br /&gt;
&lt;br /&gt;
On May 23, 2004, I decided to drop MFC (and C++, for that matter) and entirely rewrote the program in C for MinGW. This iteration saw a completely new interface, using an [http://en.wikipedia.org/wiki/Multiple_document_interface MDI] layout and resizable windows. A console window was also included which would output debug information:&lt;br /&gt;
&lt;br /&gt;
[[Image:Syn1.png|800px]] [[Image:Syn2.png|800px]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Syn3.png]] [[Image:Syn4.png]]&lt;br /&gt;
&lt;br /&gt;
On February 8, 2009, over 6 years after the project started, I decided to drop the Win32 dependencies completely. This second rewrite (or third iteration) is currently in progress, written in JavaScript for XULRunner. The plan is to eventually include C++ modules for efficiency reasons.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
Syndrome source code is available on hgkw: [http://hg.kodewerx.org/syndrome]. You can also clone the Mercurial repository with the following command:&lt;br /&gt;
&lt;br /&gt;
 $ hg clone http://hg.kodewerx.org/syndrome&lt;br /&gt;
&lt;br /&gt;
==Building==&lt;br /&gt;
&lt;br /&gt;
The current source tree is a minimal implementation of a XULRunner application; the XUL, CSS, and JS sources are available in the /src subdirectory, and two shell scripts are included for launching the application.&lt;br /&gt;
&lt;br /&gt;
The linux shell script requires XULRunner to be installed and available in your PATH. If you are on a recent version of Ubuntu, you already have everything needed to try it out:&lt;br /&gt;
&lt;br /&gt;
 $ ./syndrome-linux&lt;br /&gt;
&lt;br /&gt;
The Mac OS X shell script will build an application bundle and place it into a new /Applications/Kodewerx directory. Then it will run the application. To use this, you must download a recent copy of the [http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ XULRunner runtime]. At this time, the most current release is version 1.9.2.10:&lt;br /&gt;
&lt;br /&gt;
 $ ./syndrome-osx&lt;br /&gt;
&lt;br /&gt;
For Windows, just double click the &amp;quot;syndrome-win&amp;quot; shortcut. You must have Firefox 3.0 (or newer) installed in the default location (C:\Program Files\Mozilla Firefox) for the shortcut to work. If you have Firefox installed to a different location, you can change the shortcut to point to the firefox.exe file by right clicking the shortcut and choosing &amp;quot;Properties&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
XULRunner 1.9.1 adds some much needed functionality such as better support for the HTML Canvas element and much faster JavaScript execution time. Version 1.9.2 is also in the works which adds even more interesting features, such as scaling canvases (and images) with the nearest neighbor algorithm to prevent ugly blurring artifacts; perfect for low resolution pixel art. This can be done with the CSS [https://developer.mozilla.org/En/CSS/Image-rendering image-rendering: -moz-crisp-edges;], or the [https://developer.mozilla.org/en/Canvas_tutorial/Using_images#Controlling_image_scaling_behavior mozImageSmoothingEnabled] property on canvases.&lt;br /&gt;
&lt;br /&gt;
We need a proper build environment using configure/make on Linux and Mac OS X, and a Visual Studio project for Windows. [http://www.cmake.org/ CMake] might be a good choice. Though recently, I am really liking [http://www.scons.org/ SCons].&lt;br /&gt;
&lt;br /&gt;
==Syndrome==&lt;br /&gt;
&lt;br /&gt;
===The Name===&lt;br /&gt;
&lt;br /&gt;
I am often asked why the editor is called Syndrome; the name isn't typical of ROM hacking tools. The word 'syndrome' itself does not directly relate to Mega Man 7 or the Mega Man series in any way. The main reason for this is just to be different! But that doesn't explain where the name came from.&lt;br /&gt;
&lt;br /&gt;
I'm not a big fan of the Mega Man series, to be entirely honest. (Writing an editor for this game was a suggestion that I took one day when bored and feeling an intense urge to build an editor.) I'm not familiar with many of the characters in the series, even; however, I knew that there was a character ... somewhere ... named Sigma. Sigma is a nice name. Almost as fancy as Epsilon. But that's another story.&lt;br /&gt;
&lt;br /&gt;
The words 'sigma' and 'syndrome' (in my head, at least) have a very synesthetic feeling about them. Such that when I hear 'sigma' in my head, I also heard 'syndrome'. And that's the ultimately boring story about how the project came to be known as Syndrome!&lt;br /&gt;
&lt;br /&gt;
===The Reasoning Behind XULRunner===&lt;br /&gt;
&lt;br /&gt;
XULRunner is a nice platform; especially for people who are already familiar with doing web application programming. It's easy for web developers to pick up a XULRunner app and modify it to fit their needs. However, it's not very easy for a web developer to start a XULRunner application from scratch -- that's what XULRunner developers are for.&lt;br /&gt;
&lt;br /&gt;
Briefly, I chose XULRunner as my cross platform framework because I wanted to avoid A) non-native looking widgets (rules out GTK+) and B) C++ (rules out wxWidgets and a whole lot of other similar toolkits). On top of that, I realized the potential of the XULRunner platform in Firefox (extensions, themes, internationalization, accessibility, ...) and I feel that Syndrome can benefit from these technologies.&lt;br /&gt;
&lt;br /&gt;
Back to web developers; Most people who can write an application can also write a web page, but not vice-versa. One of the things missing from the ROM hacking communities is a firm grasp on open source software. Granted, it has been getting better in recent years. One thing I would like to accomplish with Syndrome is creating an open ROM hacking editor framework; something which contains general utilities useful to ROM hacking editors. (In other words ... a really simple place to start when someone wants to make their own editor. And if they know HTML and some JavaScript, they can probably get going in the right direction with Syndrome.)&lt;br /&gt;
&lt;br /&gt;
===Mega Man 7 Information===&lt;br /&gt;
&lt;br /&gt;
Syndrome is hard-coded to read data out of the US Mega Man 7 ROM. Other regions probably will not work. The first thing it does after opening the ROM file is detecting the ROM mapping mode. (This is part of the 'general utilities' described above!) Mega Man 7 is strictly a HiROM-mapped SNES ROM; but Syndrome does not care. It will detect the mapping mode anyway. This makes the ROM reading class general purpose. (This class also handles SMC format ROMs with or without the SMC header -- another win for modularity.)&lt;br /&gt;
&lt;br /&gt;
The next thing Syndrome does is read the ROM title from the header, but in its current state it will not verify this information (currently used for debugging only).&lt;br /&gt;
&lt;br /&gt;
Finally, it begins to &amp;quot;build&amp;quot; the first stage. This is a convoluted process (due to compression) which ends up with a very large HTML canvas (4864 x 1536 px) and a very basic SNES video mode buffer. The video mode buffer is a collection of: tiles, palettes, tile maps. These buffers are the same format as used by SNES.&lt;br /&gt;
&lt;br /&gt;
The next logical step is drawing pixels to the canvas using the tile maps, tiles, and palettes. Unfortunately, trying to do that in JavaScript alone was far too slow in my tests. I'm trying to learn the XULRunner XPCOM system well enough to write the rendering code in C++.&lt;br /&gt;
&lt;br /&gt;
====Compression====&lt;br /&gt;
&lt;br /&gt;
The compression algorithm used on tiles is an [http://en.wikipedia.org/wiki/Lempel-Ziv-Storer-Szymanski LZSS] derivative. It may also be used on other kinds of data.&lt;br /&gt;
&lt;br /&gt;
Another intermediate form of compression used is often referred to as &amp;quot;Tile Squaroid Assembler&amp;quot; (&amp;quot;TSA&amp;quot;) in the ROM hacking community. I dislike this name (in part because &amp;quot;Squaroid&amp;quot; is not a word in the English language) but do not have a better one to suggest. The method resembles a &amp;quot;[http://en.wikipedia.org/wiki/Dictionary_coder Dictionary Table Encoded]&amp;quot; (&amp;quot;DTE&amp;quot;) array; a very simple form of [http://en.wikipedia.org/wiki/Hash_tables Hash Table].&lt;br /&gt;
&lt;br /&gt;
The idea behind the DTE/hash table is to represent several bytes (a &amp;quot;block&amp;quot;) of information as a smaller block (typically only a single byte) of information. As an example, it is easy to represent a 2x2 square of tiles in only one byte; the byte used can therefore reference a total of 256 different 2x2 block combinations. The combinations available are first compiled into a big list called a dictionary. To decode a byte ''n'' into the resulting 2x2 square of tiles, you simply have to look up the ''n''th entry in the dictionary.&lt;br /&gt;
&lt;br /&gt;
Given each tile in the background layer tile map consumes 2 bytes, a stage the size of the MM7 intro level (4864 x 768 px for just the foreground) would require a tile map that's 116,736 bytes long. (Nearly 5% of the full ROM! And this is probably the smallest stage in the game.) That does not even include the tiles or palettes.&lt;br /&gt;
&lt;br /&gt;
One way to &amp;quot;compress&amp;quot; a stage this size into something more reasonable is by breaking everything into smaller 'chunks' and indexing the crap out of it. To illustrate, we can start at the 'stage' level; a stage of 4864 x 768 px can be broken into chunks of 256 x 256 px 'rooms', giving a total map size of 19 x 3 'rooms' (that's 57 bytes!)&lt;br /&gt;
&lt;br /&gt;
Now break each 'room' into 8 x 8 'structures', giving a total of 64 bytes per 'room'.&lt;br /&gt;
&lt;br /&gt;
Break each 'structure' into 2 x 2 'blocks', giving a total of 8 bytes per 'structure'.&lt;br /&gt;
&lt;br /&gt;
Break each 'block' into 2 x 2 tiles, giving a total of 8 bytes per 'block'.&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
You might imagine how this 'chunkifying' saves a whole lot of space, because it reduces redundancy (the main method of data compression, after all). With a stage like the intro (57 total rooms in the map) you might only use a maximum of 15 different kinds of rooms. And the same goes for creating rooms, structures, and blocks.&lt;br /&gt;
&lt;br /&gt;
===The Editor Interface===&lt;br /&gt;
&lt;br /&gt;
This is an area that I've spent a good deal of time exploring. Over 6 years worth of exploration, in fact. I think the best interface for this kind of game (considering the compression used, as explained above) will be to edit only one piece of the overall 'stage' at a time. For instance, the editor will start up in map edit mode on stage 0 (intro). In the map edit mode, the main canvas will display the complete stage. A toolbox will allow the user to select what kind of tool to use (in this example, a 'stamp' tool, to make changes). And below the toolbox, a palette for selecting one of the available 'rooms': Select an available room from the palette, and with the stamp tool, click on the map to 'stamp' that room into the location where the mouse is hovering.&lt;br /&gt;
&lt;br /&gt;
Now this is fine for moving rooms around the map. But to get finer grained control over your editing, you would want to enter 'room edit mode' by double clicking on one of the rooms displayed in the palette. This will change the main canvas to display the room you double clicked, and the palette will change to display all available structures which can be placed into that room.&lt;br /&gt;
&lt;br /&gt;
Double clicking a structure will then go one level deeper into structure edit mode; structure in the main canvas, and all available blocks in the palette.&lt;br /&gt;
&lt;br /&gt;
And again, enter block edit mode by double clicking, and finally, tile edit mode by double clicking a tile in the block edit mode's palette. (The tile editing mode has a palette containing ... well, a color palette! Would it also be reasonable to enter a 'palette editing mode' by double clicking one of the available colors?)&lt;br /&gt;
&lt;br /&gt;
This represents an overall of 5-6 nesting levels (map, room, structure, block, tile, ?palette?). To make this easy to use, 'back and forward' buttons should be made available. Links to all higher levels should also be available, similar to the GTK+ file picker window.&lt;br /&gt;
&lt;br /&gt;
==TODO==&lt;br /&gt;
&lt;br /&gt;
Wiki Article:&lt;br /&gt;
* Mockup screenshots to help illustrate conceptual ideas such as the nested-style user interface. Use [http://balsamiq.com/products/mockups Balsamiq Mockups] to create the mockups.&lt;br /&gt;
&lt;br /&gt;
Syndrome:&lt;br /&gt;
* Write the rendering module in C as a dynamic library; call exported functions with [https://developer.mozilla.org/en/js-ctypes js-ctypes].&lt;br /&gt;
* Extend the GetDataX() functions: maybe GetDataPtrX() ? or functions to get arrays...&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Syndrome&amp;diff=1007</id>
		<title>Syndrome</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Syndrome&amp;diff=1007"/>
				<updated>2010-10-21T07:30:21Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* TODO */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Syndrome is a level editor for the Mega Man 7 SNES game. Syndrome has undergone 2 complete rewrites since the project began (three iterations in all). The most recent rewrite makes it platform independent, with main development taking place mostly on Mac OS X.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
&lt;br /&gt;
Work on Syndrome began on September 25, 2002 as a Visual Studio 6 MFC project. The screenshots below depict two different builds of the interface. On the left, an older version showing the first time a complete screen was rendered. On the right, a newer version with some tile issues fixed (also with transparency rendered in pink) and an empty sidebar added (once planned to become a toolbox):&lt;br /&gt;
&lt;br /&gt;
[[Image:Syndrome.png]] [[Image:Syndrome2.png]]&lt;br /&gt;
&lt;br /&gt;
On May 23, 2004, I decided to drop MFC (and C++, for that matter) and entirely rewrote the program in C for MinGW. This iteration saw a completely new interface, using an [http://en.wikipedia.org/wiki/Multiple_document_interface MDI] layout and resizable windows. A console window was also included which would output debug information:&lt;br /&gt;
&lt;br /&gt;
[[Image:Syn1.png|800px]] [[Image:Syn2.png|800px]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Syn3.png]] [[Image:Syn4.png]]&lt;br /&gt;
&lt;br /&gt;
On February 8, 2009, over 6 years after the project started, I decided to drop the Win32 dependencies completely. This second rewrite (or third iteration) is currently in progress, written in JavaScript for XULRunner. The plan is to eventually include C++ modules for efficiency reasons.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
Syndrome source code is available on hgkw: [http://hg.kodewerx.org/syndrome]. You can also clone the Mercurial repository with the following command:&lt;br /&gt;
&lt;br /&gt;
 $ hg clone http://hg.kodewerx.org/syndrome&lt;br /&gt;
&lt;br /&gt;
==Building==&lt;br /&gt;
&lt;br /&gt;
The current source tree is a minimal implementation of a XULRunner application; the XUL, CSS, and JS sources are available in the /src subdirectory, and two shell scripts are included for launching the application.&lt;br /&gt;
&lt;br /&gt;
The linux shell script requires XULRunner to be installed and available in your PATH. If you are on a recent version of Ubuntu, you already have everything needed to try it out:&lt;br /&gt;
&lt;br /&gt;
 $ ./syndrome-linux&lt;br /&gt;
&lt;br /&gt;
The Mac OS X shell script will build an application bundle and place it into a new /Applications/Kodewerx directory. Then it will run the application. To use this, you must download a recent copy of the [http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ XULRunner runtime]. At this time, the most current release is version 1.9.1.4:&lt;br /&gt;
&lt;br /&gt;
 $ ./syndrome-osx&lt;br /&gt;
&lt;br /&gt;
For Windows, just double click the &amp;quot;syndrome-win&amp;quot; shortcut. You must have Firefox 3.0 (or newer) installed in the default location (C:\Program Files\Mozilla Firefox) for the shortcut to work. If you have Firefox installed to a different location, you can change the shortcut to point to the firefox.exe file by right clicking the shortcut and choosing &amp;quot;Properties&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
XULRunner 1.9.1 adds some much needed functionality such as better support for the HTML Canvas element and much faster JavaScript execution time. Version 1.9.2 is also in the works which adds even more interesting features, such as scaling canvases (and images) with the nearest neighbor algorithm to prevent ugly blurring artifacts; perfect for low resolution pixel art. This can be done with the CSS [https://developer.mozilla.org/En/CSS/Image-rendering image-rendering: -moz-crisp-edges;], or the [https://developer.mozilla.org/en/Canvas_tutorial/Using_images#Controlling_image_scaling_behavior mozImageSmoothingEnabled] property on canvases.&lt;br /&gt;
&lt;br /&gt;
We need a proper build environment using configure/make on Linux and Mac OS X, and a Visual Studio project for Windows. [http://www.cmake.org/ CMake] might be a good choice. Though recently, I am really liking [http://www.scons.org/ SCons].&lt;br /&gt;
&lt;br /&gt;
==Syndrome==&lt;br /&gt;
&lt;br /&gt;
===The Name===&lt;br /&gt;
&lt;br /&gt;
I am often asked why the editor is called Syndrome; the name isn't typical of ROM hacking tools. The word 'syndrome' itself does not directly relate to Mega Man 7 or the Mega Man series in any way. The main reason for this is just to be different! But that doesn't explain where the name came from.&lt;br /&gt;
&lt;br /&gt;
I'm not a big fan of the Mega Man series, to be entirely honest. (Writing an editor for this game was a suggestion that I took one day when bored and feeling an intense urge to build an editor.) I'm not familiar with many of the characters in the series, even; however, I knew that there was a character ... somewhere ... named Sigma. Sigma is a nice name. Almost as fancy as Epsilon. But that's another story.&lt;br /&gt;
&lt;br /&gt;
The words 'sigma' and 'syndrome' (in my head, at least) have a very synesthetic feeling about them. Such that when I hear 'sigma' in my head, I also heard 'syndrome'. And that's the ultimately boring story about how the project came to be known as Syndrome!&lt;br /&gt;
&lt;br /&gt;
===The Reasoning Behind XULRunner===&lt;br /&gt;
&lt;br /&gt;
XULRunner is a nice platform; especially for people who are already familiar with doing web application programming. It's easy for web developers to pick up a XULRunner app and modify it to fit their needs. However, it's not very easy for a web developer to start a XULRunner application from scratch -- that's what XULRunner developers are for.&lt;br /&gt;
&lt;br /&gt;
Briefly, I chose XULRunner as my cross platform framework because I wanted to avoid A) non-native looking widgets (rules out GTK+) and B) C++ (rules out wxWidgets and a whole lot of other similar toolkits). On top of that, I realized the potential of the XULRunner platform in Firefox (extensions, themes, internationalization, accessibility, ...) and I feel that Syndrome can benefit from these technologies.&lt;br /&gt;
&lt;br /&gt;
Back to web developers; Most people who can write an application can also write a web page, but not vice-versa. One of the things missing from the ROM hacking communities is a firm grasp on open source software. Granted, it has been getting better in recent years. One thing I would like to accomplish with Syndrome is creating an open ROM hacking editor framework; something which contains general utilities useful to ROM hacking editors. (In other words ... a really simple place to start when someone wants to make their own editor. And if they know HTML and some JavaScript, they can probably get going in the right direction with Syndrome.)&lt;br /&gt;
&lt;br /&gt;
===Mega Man 7 Information===&lt;br /&gt;
&lt;br /&gt;
Syndrome is hard-coded to read data out of the US Mega Man 7 ROM. Other regions probably will not work. The first thing it does after opening the ROM file is detecting the ROM mapping mode. (This is part of the 'general utilities' described above!) Mega Man 7 is strictly a HiROM-mapped SNES ROM; but Syndrome does not care. It will detect the mapping mode anyway. This makes the ROM reading class general purpose. (This class also handles SMC format ROMs with or without the SMC header -- another win for modularity.)&lt;br /&gt;
&lt;br /&gt;
The next thing Syndrome does is read the ROM title from the header, but in its current state it will not verify this information (currently used for debugging only).&lt;br /&gt;
&lt;br /&gt;
Finally, it begins to &amp;quot;build&amp;quot; the first stage. This is a convoluted process (due to compression) which ends up with a very large HTML canvas (4864 x 1536 px) and a very basic SNES video mode buffer. The video mode buffer is a collection of: tiles, palettes, tile maps. These buffers are the same format as used by SNES.&lt;br /&gt;
&lt;br /&gt;
The next logical step is drawing pixels to the canvas using the tile maps, tiles, and palettes. Unfortunately, trying to do that in JavaScript alone was far too slow in my tests. I'm trying to learn the XULRunner XPCOM system well enough to write the rendering code in C++.&lt;br /&gt;
&lt;br /&gt;
====Compression====&lt;br /&gt;
&lt;br /&gt;
The compression algorithm used on tiles is an [http://en.wikipedia.org/wiki/Lempel-Ziv-Storer-Szymanski LZSS] derivative. It may also be used on other kinds of data.&lt;br /&gt;
&lt;br /&gt;
Another intermediate form of compression used is often referred to as &amp;quot;Tile Squaroid Assembler&amp;quot; (&amp;quot;TSA&amp;quot;) in the ROM hacking community. I dislike this name (in part because &amp;quot;Squaroid&amp;quot; is not a word in the English language) but do not have a better one to suggest. The method resembles a &amp;quot;[http://en.wikipedia.org/wiki/Dictionary_coder Dictionary Table Encoded]&amp;quot; (&amp;quot;DTE&amp;quot;) array; a very simple form of [http://en.wikipedia.org/wiki/Hash_tables Hash Table].&lt;br /&gt;
&lt;br /&gt;
The idea behind the DTE/hash table is to represent several bytes (a &amp;quot;block&amp;quot;) of information as a smaller block (typically only a single byte) of information. As an example, it is easy to represent a 2x2 square of tiles in only one byte; the byte used can therefore reference a total of 256 different 2x2 block combinations. The combinations available are first compiled into a big list called a dictionary. To decode a byte ''n'' into the resulting 2x2 square of tiles, you simply have to look up the ''n''th entry in the dictionary.&lt;br /&gt;
&lt;br /&gt;
Given each tile in the background layer tile map consumes 2 bytes, a stage the size of the MM7 intro level (4864 x 768 px for just the foreground) would require a tile map that's 116,736 bytes long. (Nearly 5% of the full ROM! And this is probably the smallest stage in the game.) That does not even include the tiles or palettes.&lt;br /&gt;
&lt;br /&gt;
One way to &amp;quot;compress&amp;quot; a stage this size into something more reasonable is by breaking everything into smaller 'chunks' and indexing the crap out of it. To illustrate, we can start at the 'stage' level; a stage of 4864 x 768 px can be broken into chunks of 256 x 256 px 'rooms', giving a total map size of 19 x 3 'rooms' (that's 57 bytes!)&lt;br /&gt;
&lt;br /&gt;
Now break each 'room' into 8 x 8 'structures', giving a total of 64 bytes per 'room'.&lt;br /&gt;
&lt;br /&gt;
Break each 'structure' into 2 x 2 'blocks', giving a total of 8 bytes per 'structure'.&lt;br /&gt;
&lt;br /&gt;
Break each 'block' into 2 x 2 tiles, giving a total of 8 bytes per 'block'.&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
You might imagine how this 'chunkifying' saves a whole lot of space, because it reduces redundancy (the main method of data compression, after all). With a stage like the intro (57 total rooms in the map) you might only use a maximum of 15 different kinds of rooms. And the same goes for creating rooms, structures, and blocks.&lt;br /&gt;
&lt;br /&gt;
===The Editor Interface===&lt;br /&gt;
&lt;br /&gt;
This is an area that I've spent a good deal of time exploring. Over 6 years worth of exploration, in fact. I think the best interface for this kind of game (considering the compression used, as explained above) will be to edit only one piece of the overall 'stage' at a time. For instance, the editor will start up in map edit mode on stage 0 (intro). In the map edit mode, the main canvas will display the complete stage. A toolbox will allow the user to select what kind of tool to use (in this example, a 'stamp' tool, to make changes). And below the toolbox, a palette for selecting one of the available 'rooms': Select an available room from the palette, and with the stamp tool, click on the map to 'stamp' that room into the location where the mouse is hovering.&lt;br /&gt;
&lt;br /&gt;
Now this is fine for moving rooms around the map. But to get finer grained control over your editing, you would want to enter 'room edit mode' by double clicking on one of the rooms displayed in the palette. This will change the main canvas to display the room you double clicked, and the palette will change to display all available structures which can be placed into that room.&lt;br /&gt;
&lt;br /&gt;
Double clicking a structure will then go one level deeper into structure edit mode; structure in the main canvas, and all available blocks in the palette.&lt;br /&gt;
&lt;br /&gt;
And again, enter block edit mode by double clicking, and finally, tile edit mode by double clicking a tile in the block edit mode's palette. (The tile editing mode has a palette containing ... well, a color palette! Would it also be reasonable to enter a 'palette editing mode' by double clicking one of the available colors?)&lt;br /&gt;
&lt;br /&gt;
This represents an overall of 5-6 nesting levels (map, room, structure, block, tile, ?palette?). To make this easy to use, 'back and forward' buttons should be made available. Links to all higher levels should also be available, similar to the GTK+ file picker window.&lt;br /&gt;
&lt;br /&gt;
==TODO==&lt;br /&gt;
&lt;br /&gt;
Wiki Article:&lt;br /&gt;
* Mockup screenshots to help illustrate conceptual ideas such as the nested-style user interface. Use [http://balsamiq.com/products/mockups Balsamiq Mockups] to create the mockups.&lt;br /&gt;
&lt;br /&gt;
Syndrome:&lt;br /&gt;
* Write the rendering module in C as a dynamic library; call exported functions with [https://developer.mozilla.org/en/js-ctypes js-ctypes].&lt;br /&gt;
* Extend the GetDataX() functions: maybe GetDataPtrX() ? or functions to get arrays...&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Syndrome&amp;diff=1006</id>
		<title>Syndrome</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Syndrome&amp;diff=1006"/>
				<updated>2010-10-21T07:29:08Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* TODO */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Syndrome is a level editor for the Mega Man 7 SNES game. Syndrome has undergone 2 complete rewrites since the project began (three iterations in all). The most recent rewrite makes it platform independent, with main development taking place mostly on Mac OS X.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
&lt;br /&gt;
Work on Syndrome began on September 25, 2002 as a Visual Studio 6 MFC project. The screenshots below depict two different builds of the interface. On the left, an older version showing the first time a complete screen was rendered. On the right, a newer version with some tile issues fixed (also with transparency rendered in pink) and an empty sidebar added (once planned to become a toolbox):&lt;br /&gt;
&lt;br /&gt;
[[Image:Syndrome.png]] [[Image:Syndrome2.png]]&lt;br /&gt;
&lt;br /&gt;
On May 23, 2004, I decided to drop MFC (and C++, for that matter) and entirely rewrote the program in C for MinGW. This iteration saw a completely new interface, using an [http://en.wikipedia.org/wiki/Multiple_document_interface MDI] layout and resizable windows. A console window was also included which would output debug information:&lt;br /&gt;
&lt;br /&gt;
[[Image:Syn1.png|800px]] [[Image:Syn2.png|800px]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Syn3.png]] [[Image:Syn4.png]]&lt;br /&gt;
&lt;br /&gt;
On February 8, 2009, over 6 years after the project started, I decided to drop the Win32 dependencies completely. This second rewrite (or third iteration) is currently in progress, written in JavaScript for XULRunner. The plan is to eventually include C++ modules for efficiency reasons.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
Syndrome source code is available on hgkw: [http://hg.kodewerx.org/syndrome]. You can also clone the Mercurial repository with the following command:&lt;br /&gt;
&lt;br /&gt;
 $ hg clone http://hg.kodewerx.org/syndrome&lt;br /&gt;
&lt;br /&gt;
==Building==&lt;br /&gt;
&lt;br /&gt;
The current source tree is a minimal implementation of a XULRunner application; the XUL, CSS, and JS sources are available in the /src subdirectory, and two shell scripts are included for launching the application.&lt;br /&gt;
&lt;br /&gt;
The linux shell script requires XULRunner to be installed and available in your PATH. If you are on a recent version of Ubuntu, you already have everything needed to try it out:&lt;br /&gt;
&lt;br /&gt;
 $ ./syndrome-linux&lt;br /&gt;
&lt;br /&gt;
The Mac OS X shell script will build an application bundle and place it into a new /Applications/Kodewerx directory. Then it will run the application. To use this, you must download a recent copy of the [http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ XULRunner runtime]. At this time, the most current release is version 1.9.1.4:&lt;br /&gt;
&lt;br /&gt;
 $ ./syndrome-osx&lt;br /&gt;
&lt;br /&gt;
For Windows, just double click the &amp;quot;syndrome-win&amp;quot; shortcut. You must have Firefox 3.0 (or newer) installed in the default location (C:\Program Files\Mozilla Firefox) for the shortcut to work. If you have Firefox installed to a different location, you can change the shortcut to point to the firefox.exe file by right clicking the shortcut and choosing &amp;quot;Properties&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
XULRunner 1.9.1 adds some much needed functionality such as better support for the HTML Canvas element and much faster JavaScript execution time. Version 1.9.2 is also in the works which adds even more interesting features, such as scaling canvases (and images) with the nearest neighbor algorithm to prevent ugly blurring artifacts; perfect for low resolution pixel art. This can be done with the CSS [https://developer.mozilla.org/En/CSS/Image-rendering image-rendering: -moz-crisp-edges;], or the [https://developer.mozilla.org/en/Canvas_tutorial/Using_images#Controlling_image_scaling_behavior mozImageSmoothingEnabled] property on canvases.&lt;br /&gt;
&lt;br /&gt;
We need a proper build environment using configure/make on Linux and Mac OS X, and a Visual Studio project for Windows. [http://www.cmake.org/ CMake] might be a good choice. Though recently, I am really liking [http://www.scons.org/ SCons].&lt;br /&gt;
&lt;br /&gt;
==Syndrome==&lt;br /&gt;
&lt;br /&gt;
===The Name===&lt;br /&gt;
&lt;br /&gt;
I am often asked why the editor is called Syndrome; the name isn't typical of ROM hacking tools. The word 'syndrome' itself does not directly relate to Mega Man 7 or the Mega Man series in any way. The main reason for this is just to be different! But that doesn't explain where the name came from.&lt;br /&gt;
&lt;br /&gt;
I'm not a big fan of the Mega Man series, to be entirely honest. (Writing an editor for this game was a suggestion that I took one day when bored and feeling an intense urge to build an editor.) I'm not familiar with many of the characters in the series, even; however, I knew that there was a character ... somewhere ... named Sigma. Sigma is a nice name. Almost as fancy as Epsilon. But that's another story.&lt;br /&gt;
&lt;br /&gt;
The words 'sigma' and 'syndrome' (in my head, at least) have a very synesthetic feeling about them. Such that when I hear 'sigma' in my head, I also heard 'syndrome'. And that's the ultimately boring story about how the project came to be known as Syndrome!&lt;br /&gt;
&lt;br /&gt;
===The Reasoning Behind XULRunner===&lt;br /&gt;
&lt;br /&gt;
XULRunner is a nice platform; especially for people who are already familiar with doing web application programming. It's easy for web developers to pick up a XULRunner app and modify it to fit their needs. However, it's not very easy for a web developer to start a XULRunner application from scratch -- that's what XULRunner developers are for.&lt;br /&gt;
&lt;br /&gt;
Briefly, I chose XULRunner as my cross platform framework because I wanted to avoid A) non-native looking widgets (rules out GTK+) and B) C++ (rules out wxWidgets and a whole lot of other similar toolkits). On top of that, I realized the potential of the XULRunner platform in Firefox (extensions, themes, internationalization, accessibility, ...) and I feel that Syndrome can benefit from these technologies.&lt;br /&gt;
&lt;br /&gt;
Back to web developers; Most people who can write an application can also write a web page, but not vice-versa. One of the things missing from the ROM hacking communities is a firm grasp on open source software. Granted, it has been getting better in recent years. One thing I would like to accomplish with Syndrome is creating an open ROM hacking editor framework; something which contains general utilities useful to ROM hacking editors. (In other words ... a really simple place to start when someone wants to make their own editor. And if they know HTML and some JavaScript, they can probably get going in the right direction with Syndrome.)&lt;br /&gt;
&lt;br /&gt;
===Mega Man 7 Information===&lt;br /&gt;
&lt;br /&gt;
Syndrome is hard-coded to read data out of the US Mega Man 7 ROM. Other regions probably will not work. The first thing it does after opening the ROM file is detecting the ROM mapping mode. (This is part of the 'general utilities' described above!) Mega Man 7 is strictly a HiROM-mapped SNES ROM; but Syndrome does not care. It will detect the mapping mode anyway. This makes the ROM reading class general purpose. (This class also handles SMC format ROMs with or without the SMC header -- another win for modularity.)&lt;br /&gt;
&lt;br /&gt;
The next thing Syndrome does is read the ROM title from the header, but in its current state it will not verify this information (currently used for debugging only).&lt;br /&gt;
&lt;br /&gt;
Finally, it begins to &amp;quot;build&amp;quot; the first stage. This is a convoluted process (due to compression) which ends up with a very large HTML canvas (4864 x 1536 px) and a very basic SNES video mode buffer. The video mode buffer is a collection of: tiles, palettes, tile maps. These buffers are the same format as used by SNES.&lt;br /&gt;
&lt;br /&gt;
The next logical step is drawing pixels to the canvas using the tile maps, tiles, and palettes. Unfortunately, trying to do that in JavaScript alone was far too slow in my tests. I'm trying to learn the XULRunner XPCOM system well enough to write the rendering code in C++.&lt;br /&gt;
&lt;br /&gt;
====Compression====&lt;br /&gt;
&lt;br /&gt;
The compression algorithm used on tiles is an [http://en.wikipedia.org/wiki/Lempel-Ziv-Storer-Szymanski LZSS] derivative. It may also be used on other kinds of data.&lt;br /&gt;
&lt;br /&gt;
Another intermediate form of compression used is often referred to as &amp;quot;Tile Squaroid Assembler&amp;quot; (&amp;quot;TSA&amp;quot;) in the ROM hacking community. I dislike this name (in part because &amp;quot;Squaroid&amp;quot; is not a word in the English language) but do not have a better one to suggest. The method resembles a &amp;quot;[http://en.wikipedia.org/wiki/Dictionary_coder Dictionary Table Encoded]&amp;quot; (&amp;quot;DTE&amp;quot;) array; a very simple form of [http://en.wikipedia.org/wiki/Hash_tables Hash Table].&lt;br /&gt;
&lt;br /&gt;
The idea behind the DTE/hash table is to represent several bytes (a &amp;quot;block&amp;quot;) of information as a smaller block (typically only a single byte) of information. As an example, it is easy to represent a 2x2 square of tiles in only one byte; the byte used can therefore reference a total of 256 different 2x2 block combinations. The combinations available are first compiled into a big list called a dictionary. To decode a byte ''n'' into the resulting 2x2 square of tiles, you simply have to look up the ''n''th entry in the dictionary.&lt;br /&gt;
&lt;br /&gt;
Given each tile in the background layer tile map consumes 2 bytes, a stage the size of the MM7 intro level (4864 x 768 px for just the foreground) would require a tile map that's 116,736 bytes long. (Nearly 5% of the full ROM! And this is probably the smallest stage in the game.) That does not even include the tiles or palettes.&lt;br /&gt;
&lt;br /&gt;
One way to &amp;quot;compress&amp;quot; a stage this size into something more reasonable is by breaking everything into smaller 'chunks' and indexing the crap out of it. To illustrate, we can start at the 'stage' level; a stage of 4864 x 768 px can be broken into chunks of 256 x 256 px 'rooms', giving a total map size of 19 x 3 'rooms' (that's 57 bytes!)&lt;br /&gt;
&lt;br /&gt;
Now break each 'room' into 8 x 8 'structures', giving a total of 64 bytes per 'room'.&lt;br /&gt;
&lt;br /&gt;
Break each 'structure' into 2 x 2 'blocks', giving a total of 8 bytes per 'structure'.&lt;br /&gt;
&lt;br /&gt;
Break each 'block' into 2 x 2 tiles, giving a total of 8 bytes per 'block'.&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
You might imagine how this 'chunkifying' saves a whole lot of space, because it reduces redundancy (the main method of data compression, after all). With a stage like the intro (57 total rooms in the map) you might only use a maximum of 15 different kinds of rooms. And the same goes for creating rooms, structures, and blocks.&lt;br /&gt;
&lt;br /&gt;
===The Editor Interface===&lt;br /&gt;
&lt;br /&gt;
This is an area that I've spent a good deal of time exploring. Over 6 years worth of exploration, in fact. I think the best interface for this kind of game (considering the compression used, as explained above) will be to edit only one piece of the overall 'stage' at a time. For instance, the editor will start up in map edit mode on stage 0 (intro). In the map edit mode, the main canvas will display the complete stage. A toolbox will allow the user to select what kind of tool to use (in this example, a 'stamp' tool, to make changes). And below the toolbox, a palette for selecting one of the available 'rooms': Select an available room from the palette, and with the stamp tool, click on the map to 'stamp' that room into the location where the mouse is hovering.&lt;br /&gt;
&lt;br /&gt;
Now this is fine for moving rooms around the map. But to get finer grained control over your editing, you would want to enter 'room edit mode' by double clicking on one of the rooms displayed in the palette. This will change the main canvas to display the room you double clicked, and the palette will change to display all available structures which can be placed into that room.&lt;br /&gt;
&lt;br /&gt;
Double clicking a structure will then go one level deeper into structure edit mode; structure in the main canvas, and all available blocks in the palette.&lt;br /&gt;
&lt;br /&gt;
And again, enter block edit mode by double clicking, and finally, tile edit mode by double clicking a tile in the block edit mode's palette. (The tile editing mode has a palette containing ... well, a color palette! Would it also be reasonable to enter a 'palette editing mode' by double clicking one of the available colors?)&lt;br /&gt;
&lt;br /&gt;
This represents an overall of 5-6 nesting levels (map, room, structure, block, tile, ?palette?). To make this easy to use, 'back and forward' buttons should be made available. Links to all higher levels should also be available, similar to the GTK+ file picker window.&lt;br /&gt;
&lt;br /&gt;
==TODO==&lt;br /&gt;
&lt;br /&gt;
Wiki Article:&lt;br /&gt;
* Mockup screenshots to help illustrate conceptual ideas such as the nested-style user interface.&lt;br /&gt;
&lt;br /&gt;
Syndrome:&lt;br /&gt;
* Write the rendering module in C as a dynamic library; call exported functions with [https://developer.mozilla.org/en/js-ctypes js-ctypes].&lt;br /&gt;
* Extend the GetDataX() functions: maybe GetDataPtrX() ? or functions to get arrays...&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Syndrome&amp;diff=1005</id>
		<title>Syndrome</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Syndrome&amp;diff=1005"/>
				<updated>2010-10-21T07:27:22Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Building */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Syndrome is a level editor for the Mega Man 7 SNES game. Syndrome has undergone 2 complete rewrites since the project began (three iterations in all). The most recent rewrite makes it platform independent, with main development taking place mostly on Mac OS X.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
&lt;br /&gt;
Work on Syndrome began on September 25, 2002 as a Visual Studio 6 MFC project. The screenshots below depict two different builds of the interface. On the left, an older version showing the first time a complete screen was rendered. On the right, a newer version with some tile issues fixed (also with transparency rendered in pink) and an empty sidebar added (once planned to become a toolbox):&lt;br /&gt;
&lt;br /&gt;
[[Image:Syndrome.png]] [[Image:Syndrome2.png]]&lt;br /&gt;
&lt;br /&gt;
On May 23, 2004, I decided to drop MFC (and C++, for that matter) and entirely rewrote the program in C for MinGW. This iteration saw a completely new interface, using an [http://en.wikipedia.org/wiki/Multiple_document_interface MDI] layout and resizable windows. A console window was also included which would output debug information:&lt;br /&gt;
&lt;br /&gt;
[[Image:Syn1.png|800px]] [[Image:Syn2.png|800px]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Syn3.png]] [[Image:Syn4.png]]&lt;br /&gt;
&lt;br /&gt;
On February 8, 2009, over 6 years after the project started, I decided to drop the Win32 dependencies completely. This second rewrite (or third iteration) is currently in progress, written in JavaScript for XULRunner. The plan is to eventually include C++ modules for efficiency reasons.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
Syndrome source code is available on hgkw: [http://hg.kodewerx.org/syndrome]. You can also clone the Mercurial repository with the following command:&lt;br /&gt;
&lt;br /&gt;
 $ hg clone http://hg.kodewerx.org/syndrome&lt;br /&gt;
&lt;br /&gt;
==Building==&lt;br /&gt;
&lt;br /&gt;
The current source tree is a minimal implementation of a XULRunner application; the XUL, CSS, and JS sources are available in the /src subdirectory, and two shell scripts are included for launching the application.&lt;br /&gt;
&lt;br /&gt;
The linux shell script requires XULRunner to be installed and available in your PATH. If you are on a recent version of Ubuntu, you already have everything needed to try it out:&lt;br /&gt;
&lt;br /&gt;
 $ ./syndrome-linux&lt;br /&gt;
&lt;br /&gt;
The Mac OS X shell script will build an application bundle and place it into a new /Applications/Kodewerx directory. Then it will run the application. To use this, you must download a recent copy of the [http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ XULRunner runtime]. At this time, the most current release is version 1.9.1.4:&lt;br /&gt;
&lt;br /&gt;
 $ ./syndrome-osx&lt;br /&gt;
&lt;br /&gt;
For Windows, just double click the &amp;quot;syndrome-win&amp;quot; shortcut. You must have Firefox 3.0 (or newer) installed in the default location (C:\Program Files\Mozilla Firefox) for the shortcut to work. If you have Firefox installed to a different location, you can change the shortcut to point to the firefox.exe file by right clicking the shortcut and choosing &amp;quot;Properties&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
XULRunner 1.9.1 adds some much needed functionality such as better support for the HTML Canvas element and much faster JavaScript execution time. Version 1.9.2 is also in the works which adds even more interesting features, such as scaling canvases (and images) with the nearest neighbor algorithm to prevent ugly blurring artifacts; perfect for low resolution pixel art. This can be done with the CSS [https://developer.mozilla.org/En/CSS/Image-rendering image-rendering: -moz-crisp-edges;], or the [https://developer.mozilla.org/en/Canvas_tutorial/Using_images#Controlling_image_scaling_behavior mozImageSmoothingEnabled] property on canvases.&lt;br /&gt;
&lt;br /&gt;
We need a proper build environment using configure/make on Linux and Mac OS X, and a Visual Studio project for Windows. [http://www.cmake.org/ CMake] might be a good choice. Though recently, I am really liking [http://www.scons.org/ SCons].&lt;br /&gt;
&lt;br /&gt;
==Syndrome==&lt;br /&gt;
&lt;br /&gt;
===The Name===&lt;br /&gt;
&lt;br /&gt;
I am often asked why the editor is called Syndrome; the name isn't typical of ROM hacking tools. The word 'syndrome' itself does not directly relate to Mega Man 7 or the Mega Man series in any way. The main reason for this is just to be different! But that doesn't explain where the name came from.&lt;br /&gt;
&lt;br /&gt;
I'm not a big fan of the Mega Man series, to be entirely honest. (Writing an editor for this game was a suggestion that I took one day when bored and feeling an intense urge to build an editor.) I'm not familiar with many of the characters in the series, even; however, I knew that there was a character ... somewhere ... named Sigma. Sigma is a nice name. Almost as fancy as Epsilon. But that's another story.&lt;br /&gt;
&lt;br /&gt;
The words 'sigma' and 'syndrome' (in my head, at least) have a very synesthetic feeling about them. Such that when I hear 'sigma' in my head, I also heard 'syndrome'. And that's the ultimately boring story about how the project came to be known as Syndrome!&lt;br /&gt;
&lt;br /&gt;
===The Reasoning Behind XULRunner===&lt;br /&gt;
&lt;br /&gt;
XULRunner is a nice platform; especially for people who are already familiar with doing web application programming. It's easy for web developers to pick up a XULRunner app and modify it to fit their needs. However, it's not very easy for a web developer to start a XULRunner application from scratch -- that's what XULRunner developers are for.&lt;br /&gt;
&lt;br /&gt;
Briefly, I chose XULRunner as my cross platform framework because I wanted to avoid A) non-native looking widgets (rules out GTK+) and B) C++ (rules out wxWidgets and a whole lot of other similar toolkits). On top of that, I realized the potential of the XULRunner platform in Firefox (extensions, themes, internationalization, accessibility, ...) and I feel that Syndrome can benefit from these technologies.&lt;br /&gt;
&lt;br /&gt;
Back to web developers; Most people who can write an application can also write a web page, but not vice-versa. One of the things missing from the ROM hacking communities is a firm grasp on open source software. Granted, it has been getting better in recent years. One thing I would like to accomplish with Syndrome is creating an open ROM hacking editor framework; something which contains general utilities useful to ROM hacking editors. (In other words ... a really simple place to start when someone wants to make their own editor. And if they know HTML and some JavaScript, they can probably get going in the right direction with Syndrome.)&lt;br /&gt;
&lt;br /&gt;
===Mega Man 7 Information===&lt;br /&gt;
&lt;br /&gt;
Syndrome is hard-coded to read data out of the US Mega Man 7 ROM. Other regions probably will not work. The first thing it does after opening the ROM file is detecting the ROM mapping mode. (This is part of the 'general utilities' described above!) Mega Man 7 is strictly a HiROM-mapped SNES ROM; but Syndrome does not care. It will detect the mapping mode anyway. This makes the ROM reading class general purpose. (This class also handles SMC format ROMs with or without the SMC header -- another win for modularity.)&lt;br /&gt;
&lt;br /&gt;
The next thing Syndrome does is read the ROM title from the header, but in its current state it will not verify this information (currently used for debugging only).&lt;br /&gt;
&lt;br /&gt;
Finally, it begins to &amp;quot;build&amp;quot; the first stage. This is a convoluted process (due to compression) which ends up with a very large HTML canvas (4864 x 1536 px) and a very basic SNES video mode buffer. The video mode buffer is a collection of: tiles, palettes, tile maps. These buffers are the same format as used by SNES.&lt;br /&gt;
&lt;br /&gt;
The next logical step is drawing pixels to the canvas using the tile maps, tiles, and palettes. Unfortunately, trying to do that in JavaScript alone was far too slow in my tests. I'm trying to learn the XULRunner XPCOM system well enough to write the rendering code in C++.&lt;br /&gt;
&lt;br /&gt;
====Compression====&lt;br /&gt;
&lt;br /&gt;
The compression algorithm used on tiles is an [http://en.wikipedia.org/wiki/Lempel-Ziv-Storer-Szymanski LZSS] derivative. It may also be used on other kinds of data.&lt;br /&gt;
&lt;br /&gt;
Another intermediate form of compression used is often referred to as &amp;quot;Tile Squaroid Assembler&amp;quot; (&amp;quot;TSA&amp;quot;) in the ROM hacking community. I dislike this name (in part because &amp;quot;Squaroid&amp;quot; is not a word in the English language) but do not have a better one to suggest. The method resembles a &amp;quot;[http://en.wikipedia.org/wiki/Dictionary_coder Dictionary Table Encoded]&amp;quot; (&amp;quot;DTE&amp;quot;) array; a very simple form of [http://en.wikipedia.org/wiki/Hash_tables Hash Table].&lt;br /&gt;
&lt;br /&gt;
The idea behind the DTE/hash table is to represent several bytes (a &amp;quot;block&amp;quot;) of information as a smaller block (typically only a single byte) of information. As an example, it is easy to represent a 2x2 square of tiles in only one byte; the byte used can therefore reference a total of 256 different 2x2 block combinations. The combinations available are first compiled into a big list called a dictionary. To decode a byte ''n'' into the resulting 2x2 square of tiles, you simply have to look up the ''n''th entry in the dictionary.&lt;br /&gt;
&lt;br /&gt;
Given each tile in the background layer tile map consumes 2 bytes, a stage the size of the MM7 intro level (4864 x 768 px for just the foreground) would require a tile map that's 116,736 bytes long. (Nearly 5% of the full ROM! And this is probably the smallest stage in the game.) That does not even include the tiles or palettes.&lt;br /&gt;
&lt;br /&gt;
One way to &amp;quot;compress&amp;quot; a stage this size into something more reasonable is by breaking everything into smaller 'chunks' and indexing the crap out of it. To illustrate, we can start at the 'stage' level; a stage of 4864 x 768 px can be broken into chunks of 256 x 256 px 'rooms', giving a total map size of 19 x 3 'rooms' (that's 57 bytes!)&lt;br /&gt;
&lt;br /&gt;
Now break each 'room' into 8 x 8 'structures', giving a total of 64 bytes per 'room'.&lt;br /&gt;
&lt;br /&gt;
Break each 'structure' into 2 x 2 'blocks', giving a total of 8 bytes per 'structure'.&lt;br /&gt;
&lt;br /&gt;
Break each 'block' into 2 x 2 tiles, giving a total of 8 bytes per 'block'.&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
You might imagine how this 'chunkifying' saves a whole lot of space, because it reduces redundancy (the main method of data compression, after all). With a stage like the intro (57 total rooms in the map) you might only use a maximum of 15 different kinds of rooms. And the same goes for creating rooms, structures, and blocks.&lt;br /&gt;
&lt;br /&gt;
===The Editor Interface===&lt;br /&gt;
&lt;br /&gt;
This is an area that I've spent a good deal of time exploring. Over 6 years worth of exploration, in fact. I think the best interface for this kind of game (considering the compression used, as explained above) will be to edit only one piece of the overall 'stage' at a time. For instance, the editor will start up in map edit mode on stage 0 (intro). In the map edit mode, the main canvas will display the complete stage. A toolbox will allow the user to select what kind of tool to use (in this example, a 'stamp' tool, to make changes). And below the toolbox, a palette for selecting one of the available 'rooms': Select an available room from the palette, and with the stamp tool, click on the map to 'stamp' that room into the location where the mouse is hovering.&lt;br /&gt;
&lt;br /&gt;
Now this is fine for moving rooms around the map. But to get finer grained control over your editing, you would want to enter 'room edit mode' by double clicking on one of the rooms displayed in the palette. This will change the main canvas to display the room you double clicked, and the palette will change to display all available structures which can be placed into that room.&lt;br /&gt;
&lt;br /&gt;
Double clicking a structure will then go one level deeper into structure edit mode; structure in the main canvas, and all available blocks in the palette.&lt;br /&gt;
&lt;br /&gt;
And again, enter block edit mode by double clicking, and finally, tile edit mode by double clicking a tile in the block edit mode's palette. (The tile editing mode has a palette containing ... well, a color palette! Would it also be reasonable to enter a 'palette editing mode' by double clicking one of the available colors?)&lt;br /&gt;
&lt;br /&gt;
This represents an overall of 5-6 nesting levels (map, room, structure, block, tile, ?palette?). To make this easy to use, 'back and forward' buttons should be made available. Links to all higher levels should also be available, similar to the GTK+ file picker window.&lt;br /&gt;
&lt;br /&gt;
==TODO==&lt;br /&gt;
&lt;br /&gt;
Wiki Article:&lt;br /&gt;
* Mockup screenshots to help illustrate conceptual ideas such as the nested-style user interface.&lt;br /&gt;
&lt;br /&gt;
Syndrome:&lt;br /&gt;
* Create the C++ rendering module.&lt;br /&gt;
* Extend the GetDataX() functions: maybe GetDataPtrX() ? or functions to get arrays...&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=As85&amp;diff=1004</id>
		<title>As85</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=As85&amp;diff=1004"/>
				<updated>2010-10-21T07:23:51Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: Fix hgkw links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;as85 is a simple assembler for the Sharp sm8521; the same microcontroller used in the Tiger Game.com. Game.com was released in 1998 and had only a few games ever made for it. It also has not had any homebrew games made for it. as85 is an attempt to build an assembler that will help hackers write homebrew code that will run on Game.com hardware.&lt;br /&gt;
&lt;br /&gt;
Documentation on the Game.com hardware is available at [http://gamecom.guruwork.de/ Game.commies].&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The source code is available at http://hg.kodewerx.org/as85/&lt;br /&gt;
&lt;br /&gt;
==Current Progress==&lt;br /&gt;
&lt;br /&gt;
The current state of as85 is &amp;quot;almost usable, but not quite there yet.&amp;quot; A number of bugs exist which need to be fixed before it can be used as a development tool:&lt;br /&gt;
&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=2 Bug 2]: Add support for jump/call/branch instructions&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=3 Bug 3]: Output object code&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=4 Bug 4]: Write a linker&lt;br /&gt;
&lt;br /&gt;
I've also filed a bug about giving the project a better name [http://bugzilla.kodewerx.org/show_bug.cgi?id=5].&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
The program takes one argument; the file name of an sm8521 assembly file. The files in the [http://hg.kodewerx.org/as85/file/tip/examples /examples] directory are a good place to start.&lt;br /&gt;
&lt;br /&gt;
* test.asm is an example of what the beginning of a Game.com program might look like; it contains a header, and some [random] instructions to give you an idea.&lt;br /&gt;
* test2.asm is for testing the integrity of the parser with complex strings.&lt;br /&gt;
* test3.asm lists all possible sm8521 instructions; for verifying the output binary is correct.&lt;br /&gt;
&lt;br /&gt;
==Example Output==&lt;br /&gt;
&lt;br /&gt;
The following command:&lt;br /&gt;
 $ ./as85 ../examples/test3.asm&lt;br /&gt;
&lt;br /&gt;
Produces the following output:&lt;br /&gt;
 00 01           clr     R1&lt;br /&gt;
 01 01           neg     R1&lt;br /&gt;
 02 01           com     R1&lt;br /&gt;
 03 01           rr      R1&lt;br /&gt;
 04 01           rl      R1&lt;br /&gt;
 05 01           rrc     R1&lt;br /&gt;
 06 01           rlc     R1&lt;br /&gt;
 07 01           srl     R1&lt;br /&gt;
 08 01           inc     R1&lt;br /&gt;
 09 01           dec     R1&lt;br /&gt;
 0A 01           sra     R1&lt;br /&gt;
 0B 01           sll     R1&lt;br /&gt;
 0C 01           da      R1&lt;br /&gt;
 0D 01           swap    R1&lt;br /&gt;
 0E 01           push    R1&lt;br /&gt;
 0F 01           pop     R1&lt;br /&gt;
 10 0A           cmp     r1, r2&lt;br /&gt;
 11 0A           add     r1, r2&lt;br /&gt;
 12 0A           sub     r1, r2&lt;br /&gt;
 13 0A           adc     r1, r2&lt;br /&gt;
 14 0A           sbc     r1, r2&lt;br /&gt;
 15 0A           and     r1, r2&lt;br /&gt;
 16 0A           or      r1, r2&lt;br /&gt;
 17 0A           xor     r1, r2&lt;br /&gt;
 18 02           incw    RR2&lt;br /&gt;
 19 02           decw    RR2&lt;br /&gt;
 1A 08           clr     @r1&lt;br /&gt;
 1A 09           neg     @r1&lt;br /&gt;
 1A 0A           com     @r1&lt;br /&gt;
 1A 0B           rr      @r1&lt;br /&gt;
 1A 0C           rl      @r1&lt;br /&gt;
 1A 0D           rrc     @r1&lt;br /&gt;
 1A 0E           rlc     @r1&lt;br /&gt;
 1A 0F           srl     @r1&lt;br /&gt;
 1B 08           inc     @r1&lt;br /&gt;
 1B 09           dec     @r1&lt;br /&gt;
 1B 0A           sra     @r1&lt;br /&gt;
 1B 0B           sll     @r1&lt;br /&gt;
 1B 0C           da      @r1&lt;br /&gt;
 1B 0D           swap    @r1&lt;br /&gt;
 1B 0E           push    @r1&lt;br /&gt;
 1B 0F           pop     @r1&lt;br /&gt;
 1C 07 24        bclr    0xFF24, #7&lt;br /&gt;
 1C 0F 94        bclr    0x94(r1), #7&lt;br /&gt;
 1D 07 24        bset    0xFF24, #7&lt;br /&gt;
 1D 0F 94        bset    0x94(r1), #7&lt;br /&gt;
 1E 02           pushw   RR2&lt;br /&gt;
 1F 02           popw    RR2&lt;br /&gt;
 20 0A           cmp     r1, @r2&lt;br /&gt;
 20 4A           cmp     r1, (r2)+&lt;br /&gt;
 20 88 94        cmp     r1, @0x94&lt;br /&gt;
 20 8A 94        cmp     r1, 0x94(r2)&lt;br /&gt;
 20 CA           cmp     r1, -(r2)&lt;br /&gt;
 21 0A           add     r1, @r2&lt;br /&gt;
 21 4A           add     r1, (r2)+&lt;br /&gt;
 21 88 94        add     r1, @0x94&lt;br /&gt;
 21 8A 94        add     r1, 0x94(r2)&lt;br /&gt;
 21 CA           add     r1, -(r2)&lt;br /&gt;
 22 0A           sub     r1, @r2&lt;br /&gt;
 22 4A           sub     r1, (r2)+&lt;br /&gt;
 22 88 94        sub     r1, @0x94&lt;br /&gt;
 22 8A 94        sub     r1, 0x94(r2)&lt;br /&gt;
 22 CA           sub     r1, -(r2)&lt;br /&gt;
 23 0A           adc     r1, @r2&lt;br /&gt;
 23 4A           adc     r1, (r2)+&lt;br /&gt;
 23 88 94        adc     r1, @0x94&lt;br /&gt;
 23 8A 94        adc     r1, 0x94(r2)&lt;br /&gt;
 23 CA           adc     r1, -(r2)&lt;br /&gt;
 24 0A           sbc     r1, @r2&lt;br /&gt;
 24 4A           sbc     r1, (r2)+&lt;br /&gt;
 24 88 94        sbc     r1, @0x94&lt;br /&gt;
 24 8A 94        sbc     r1, 0x94(r2)&lt;br /&gt;
 24 CA           sbc     r1, -(r2)&lt;br /&gt;
 25 0A           and     r1, @r2&lt;br /&gt;
 25 4A           and     r1, (r2)+&lt;br /&gt;
 25 88 94        and     r1, @0x94&lt;br /&gt;
 25 8A 94        and     r1, 0x94(r2)&lt;br /&gt;
 25 CA           and     r1, -(r2)&lt;br /&gt;
 26 0A           or      r1, @r2&lt;br /&gt;
 26 4A           or      r1, (r2)+&lt;br /&gt;
 26 88 94        or      r1, @0x94&lt;br /&gt;
 26 8A 94        or      r1, 0x94(r2)&lt;br /&gt;
 26 CA           or      r1, -(r2)&lt;br /&gt;
 27 0A           xor     r1, @r2&lt;br /&gt;
 27 4A           xor     r1, (r2)+&lt;br /&gt;
 27 88 94        xor     r1, @0x94&lt;br /&gt;
 27 8A 94        xor     r1, 0x94(r2)&lt;br /&gt;
 27 CA           xor     r1, -(r2)&lt;br /&gt;
 28 0A           mov     r1, @r2&lt;br /&gt;
 28 4A           mov     r1, (r2)+&lt;br /&gt;
 28 88 94        mov     r1, @0x94&lt;br /&gt;
 28 8A 94        mov     r1, 0x94(r2)&lt;br /&gt;
 28 CA           mov     r1, -(r2)&lt;br /&gt;
 29 11           mov     @r1, r2&lt;br /&gt;
 29 51           mov     (r1)+, r2&lt;br /&gt;
 29 90 94        mov     @0x94, r2&lt;br /&gt;
 29 91 94        mov     0x94(r1), r2&lt;br /&gt;
 29 D1           mov     -(r1), r2&lt;br /&gt;
 2C 02           exts    RR2&lt;br /&gt;
 2E 94           mov     ps0, #0x94&lt;br /&gt;
 2F 94 01        btst    R1, #0x94&lt;br /&gt;
 30 09           cmp     r1, @rr2&lt;br /&gt;
 30 49           cmp     r1, (rr2)+&lt;br /&gt;
 30 88 24 94     cmp     r1, @0x9424&lt;br /&gt;
 30 89 24 94     cmp     r1, 0x9424(rr2)&lt;br /&gt;
 30 C9           cmp     r1, -(rr2)&lt;br /&gt;
 31 09           add     r1, @rr2&lt;br /&gt;
 31 49           add     r1, (rr2)+&lt;br /&gt;
 31 88 24 94     add     r1, @0x9424&lt;br /&gt;
 31 89 24 94     add     r1, 0x9424(rr2)&lt;br /&gt;
 31 C9           add     r1, -(rr2)&lt;br /&gt;
 32 09           sub     r1, @rr2&lt;br /&gt;
 32 49           sub     r1, (rr2)+&lt;br /&gt;
 32 88 24 94     sub     r1, @0x9424&lt;br /&gt;
 32 89 24 94     sub     r1, 0x9424(rr2)&lt;br /&gt;
 32 C9           sub     r1, -(rr2)&lt;br /&gt;
 33 09           adc     r1, @rr2&lt;br /&gt;
 33 49           adc     r1, (rr2)+&lt;br /&gt;
 33 88 24 94     adc     r1, @0x9424&lt;br /&gt;
 33 89 24 94     adc     r1, 0x9424(rr2)&lt;br /&gt;
 33 C9           adc     r1, -(rr2)&lt;br /&gt;
 34 09           sbc     r1, @rr2&lt;br /&gt;
 34 49           sbc     r1, (rr2)+&lt;br /&gt;
 34 88 24 94     sbc     r1, @0x9424&lt;br /&gt;
 34 89 24 94     sbc     r1, 0x9424(rr2)&lt;br /&gt;
 34 C9           sbc     r1, -(rr2)&lt;br /&gt;
 35 09           and     r1, @rr2&lt;br /&gt;
 35 49           and     r1, (rr2)+&lt;br /&gt;
 35 88 24 94     and     r1, @0x9424&lt;br /&gt;
 35 89 24 94     and     r1, 0x9424(rr2)&lt;br /&gt;
 35 C9           and     r1, -(rr2)&lt;br /&gt;
 36 09           or      r1, @rr2&lt;br /&gt;
 36 49           or      r1, (rr2)+&lt;br /&gt;
 36 88 24 94     or      r1, @0x9424&lt;br /&gt;
 36 89 24 94     or      r1, 0x9424(rr2)&lt;br /&gt;
 36 C9           or      r1, -(rr2)&lt;br /&gt;
 37 09           xor     r1, @rr2&lt;br /&gt;
 37 49           xor     r1, (rr2)+&lt;br /&gt;
 37 88 24 94     xor     r1, @0x9424&lt;br /&gt;
 37 89 24 94     xor     r1, 0x9424(rr2)&lt;br /&gt;
 37 C9           xor     r1, -(rr2)&lt;br /&gt;
 38 09           mov     r1, @rr2&lt;br /&gt;
 38 49           mov     r1, (rr2)+&lt;br /&gt;
 38 88 24 94     mov     r1, @0x9424&lt;br /&gt;
 38 89 24 94     mov     r1, 0x9424(rr2)&lt;br /&gt;
 38 C9           mov     r1, -(rr2)&lt;br /&gt;
 39 21           mov     @rr2, r4&lt;br /&gt;
 39 61           mov     (rr2)+, r4&lt;br /&gt;
 39 A0 24 94     mov     @0x9424, r4&lt;br /&gt;
 39 A1 24 94     mov     0x9424(rr2), r4&lt;br /&gt;
 39 E1           mov     -(rr2), r4&lt;br /&gt;
 3A 14           movw    rr2, @rr4&lt;br /&gt;
 3A 54           movw    rr2, (rr4)+&lt;br /&gt;
 3A 90 24 94     movw    rr2, @0x9424&lt;br /&gt;
 3A 94 24 94     movw    rr2, 0x9424(rr4)&lt;br /&gt;
 3A D4           movw    rr2, -(rr4)&lt;br /&gt;
 3B 22           movw    @rr2, rr4&lt;br /&gt;
 3B 62           movw    (rr2)+, rr4&lt;br /&gt;
 3B A0 24 94     movw    @0x9424, rr4&lt;br /&gt;
 3B A2 24 94     movw    0x9424(rr2), rr4&lt;br /&gt;
 3B E2           movw    -(rr2), rr4&lt;br /&gt;
 3C 14           movw    rr2, rr4&lt;br /&gt;
 40 02 01        cmp     R1, R2&lt;br /&gt;
 41 02 01        add     R1, R2&lt;br /&gt;
 42 02 01        sub     R1, R2&lt;br /&gt;
 43 02 01        adc     R1, R2&lt;br /&gt;
 44 02 01        sbc     R1, R2&lt;br /&gt;
 45 02 01        and     R1, R2&lt;br /&gt;
 46 02 01        or      R1, R2&lt;br /&gt;
 47 02 01        xor     R1, R2&lt;br /&gt;
 48 02 01        mov     R1, R2&lt;br /&gt;
 4A 04 02        movw    RR2, RR4&lt;br /&gt;
 4B 02 24 94     movw    RR2, #0x9424&lt;br /&gt;
 4C 04 02        mult    RR2, R4&lt;br /&gt;
 4D 94 02        mult    RR2, #0x94&lt;br /&gt;
 4E 07 01        bmov    bf, R1, #7&lt;br /&gt;
 4E 47 01        bmov    R1, #7, bf&lt;br /&gt;
 4F 07 01        bcmp    bf, R1, #7&lt;br /&gt;
 4F 47 01        band    bf, R1, #7&lt;br /&gt;
 4F 87 01        bor     bf, R1, #7&lt;br /&gt;
 4F C7 01        bxor    bf, R1, #7&lt;br /&gt;
 50 94 01        cmp     R1, #0x94&lt;br /&gt;
 51 94 01        add     R1, #0x94&lt;br /&gt;
 52 94 01        sub     R1, #0x94&lt;br /&gt;
 53 94 01        adc     R1, #0x94&lt;br /&gt;
 54 94 01        sbc     R1, #0x94&lt;br /&gt;
 55 94 01        and     R1, #0x94&lt;br /&gt;
 56 94 01        or      R1, #0x94&lt;br /&gt;
 57 94 01        xor     R1, #0x94&lt;br /&gt;
 58 94 01        mov     R1, #0x94&lt;br /&gt;
 5C 04 02        div     RR2, RR4&lt;br /&gt;
 5D 94 02        div     RR2, #0x94&lt;br /&gt;
 5E 01 94 02     movm    R1, #0x94, R2&lt;br /&gt;
 5F 01 94 24     movm    R1, #0x94, #0x24&lt;br /&gt;
 60 04 02        cmpw    RR2, RR4&lt;br /&gt;
 61 04 02        addw    RR2, RR4&lt;br /&gt;
 62 04 02        subw    RR2, RR4&lt;br /&gt;
 63 04 02        adcw    RR2, RR4&lt;br /&gt;
 64 04 02        sbcw    RR2, RR4&lt;br /&gt;
 65 04 02        andw    RR2, RR4&lt;br /&gt;
 66 04 02        orw     RR2, RR4&lt;br /&gt;
 67 04 02        xorw    RR2, RR4&lt;br /&gt;
 68 02 24 94     cmpw    RR2, #0x9424&lt;br /&gt;
 69 02 24 94     addw    RR2, #0x9424&lt;br /&gt;
 6A 02 24 94     subw    RR2, #0x9424&lt;br /&gt;
 6B 02 24 94     adcw    RR2, #0x9424&lt;br /&gt;
 6C 02 24 94     sbcw    RR2, #0x9424&lt;br /&gt;
 6D 02 24 94     andw    RR2, #0x9424&lt;br /&gt;
 6E 02 24 94     orw     RR2, #0x9424&lt;br /&gt;
 6F 02 24 94     xorw    RR2, #0x9424&lt;br /&gt;
 78 24 94        movw    rr0, #0x9424&lt;br /&gt;
 79 24 94        movw    rr8, #0x9424&lt;br /&gt;
 7A 24 94        movw    rr2, #0x9424&lt;br /&gt;
 7B 24 94        movw    rr10, #0x9424&lt;br /&gt;
 7C 24 94        movw    rr4, #0x9424&lt;br /&gt;
 7D 24 94        movw    rr12, #0x9424&lt;br /&gt;
 7E 24 94        movw    rr6, #0x9424&lt;br /&gt;
 7F 24 94        movw    rr14, #0x9424&lt;br /&gt;
 A0 01           bclr    R1, #0&lt;br /&gt;
 A1 01           bclr    R1, #1&lt;br /&gt;
 A2 01           bclr    R1, #2&lt;br /&gt;
 A3 01           bclr    R1, #3&lt;br /&gt;
 A4 01           bclr    R1, #4&lt;br /&gt;
 A5 01           bclr    R1, #5&lt;br /&gt;
 A6 01           bclr    R1, #6&lt;br /&gt;
 A7 01           bclr    R1, #7&lt;br /&gt;
 A8 01           bset    R1, #0&lt;br /&gt;
 A9 01           bset    R1, #1&lt;br /&gt;
 AA 01           bset    R1, #2&lt;br /&gt;
 AB 01           bset    R1, #3&lt;br /&gt;
 AC 01           bset    R1, #4&lt;br /&gt;
 AD 01           bset    R1, #5&lt;br /&gt;
 AE 01           bset    R1, #6&lt;br /&gt;
 AF 01           bset    R1, #7&lt;br /&gt;
 B0 01           mov     r0, R1&lt;br /&gt;
 B1 01           mov     r1, R1&lt;br /&gt;
 B2 01           mov     r2, R1&lt;br /&gt;
 B3 01           mov     r3, R1&lt;br /&gt;
 B4 01           mov     r4, R1&lt;br /&gt;
 B5 01           mov     r5, R1&lt;br /&gt;
 B6 01           mov     r6, R1&lt;br /&gt;
 B7 01           mov     r7, R1&lt;br /&gt;
 B8 01           mov     R1, r0&lt;br /&gt;
 B9 01           mov     R1, r1&lt;br /&gt;
 BA 01           mov     R1, r2&lt;br /&gt;
 BB 01           mov     R1, r3&lt;br /&gt;
 BC 01           mov     R1, r4&lt;br /&gt;
 BD 01           mov     R1, r5&lt;br /&gt;
 BE 01           mov     R1, r6&lt;br /&gt;
 BF 01           mov     R1, r7&lt;br /&gt;
 C0 94           mov     r0, #0x94&lt;br /&gt;
 C1 94           mov     r1, #0x94&lt;br /&gt;
 C2 94           mov     r2, #0x94&lt;br /&gt;
 C3 94           mov     r3, #0x94&lt;br /&gt;
 C4 94           mov     r4, #0x94&lt;br /&gt;
 C5 94           mov     r5, #0x94&lt;br /&gt;
 C6 94           mov     r6, #0x94&lt;br /&gt;
 C7 94           mov     r7, #0x94&lt;br /&gt;
 C8 94           mov     ie0, #0x94&lt;br /&gt;
 C9 94           mov     ie1, #0x94&lt;br /&gt;
 CA 94           mov     ir0, #0x94&lt;br /&gt;
 CB 94           mov     ir1, #0x94&lt;br /&gt;
 CC 94           mov     p0, #0x94&lt;br /&gt;
 CD 94           mov     p1, #0x94&lt;br /&gt;
 CE 94           mov     p2, #0x94&lt;br /&gt;
 CF 94           mov     p3, #0x94&lt;br /&gt;
 F0              stop&lt;br /&gt;
 F1              halt&lt;br /&gt;
 F8              ret&lt;br /&gt;
 F9              iret&lt;br /&gt;
 FA              clrc&lt;br /&gt;
 FB              comc&lt;br /&gt;
 FC              setc&lt;br /&gt;
 FD              ei&lt;br /&gt;
 FE              di&lt;br /&gt;
 FF              nop&lt;br /&gt;
 assemble() returned 0: OK&lt;br /&gt;
 Clean up...&lt;br /&gt;
&lt;br /&gt;
Note: The output binary has not been verified for accuracy.&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
As85 is a fairly simple assembler. It doesn't use any sort of 'compiler-compiler' for lexical analysis. In fact, its lexical analysis is very specific to the sm8521 MCU.&lt;br /&gt;
&lt;br /&gt;
The main loop (assemble() function, defined in [http://hg.kodewerx.org/as85/file/a90c47020126/src/asm.c#l315 asm.c]) does the input text parsing inline. (This should probably be moved out to a new source file.) After splitting a line into two pieces; op[0] containing the instruction, and op[1] containing its operands; a string comparison against op[0] is done over all supported instructions. If a match is found, the operands string is passed to a dynamically chosen function (from a [http://hg.kodewerx.org/as85/file/a90c47020126/src/inst.c#l156 function pointer table], indexed by the matched instruction). This function performs the lexical analysis required to decide which instruction we are trying to assemble.&lt;br /&gt;
&lt;br /&gt;
Since the sm8521 is a CISC machine, its instruction set contains a number of different ways to assemble the same instruction mnemonic. For example, several different addressing modes for the ''mov'' instruction are shown above in the test3.asm output. The lexical analysis is the voodoo which picks the proper addressing mode and byte codes by analyzing the operands.&lt;br /&gt;
&lt;br /&gt;
The lexical analyzing functions are defined in inst.c (following the function pointer table mentioned previously). The function handling the current instruction will test the operands string against a series of lexical patterns with the [http://hg.kodewerx.org/as85/file/a90c47020126/src/asm.c#l89 chk_pattern()] function (defined in asm.c, although this should probably be moved).&lt;br /&gt;
&lt;br /&gt;
chk_pattern() uses a scanf-like formatting string, rather than a regular expression, which is more common in lexical analysis. Documentation for the formatting string can be found in [http://hg.kodewerx.org/as85/file/a90c47020126/src/inst.h#l29 inst.h]. With just a few pattern primitives, any of the sm8521's addressing modes can be matched, with the matching primitives output as part of an array. It makes good use of the format scanners defined in [http://hg.kodewerx.org/as85/file/a90c47020126/src/scan.c scan.c].&lt;br /&gt;
&lt;br /&gt;
If chk_pattern() manages to find a match, the matching data may be further checked for validity on a per-context basis. Finally, the full instruction byte codes will be put together and returned to the assemble() loop. This is where the object code would be built. Currently the only thing that happens now is dumping the assembled instruction to stdout, in a debug build. [http://hg.kodewerx.org/as85/file/a90c47020126/src/asm.c#l464]&lt;br /&gt;
&lt;br /&gt;
===Optimization Concerns===&lt;br /&gt;
&lt;br /&gt;
Some optimization could be done within this lexical analysis process. The first improvement would be replacing the linear string comparison with a binary search tree. The second thing that would help in this immediate area would be replacing the string comparison itself with a hash comparison. The hash algorithm would have to be suitably small and fast enough to make much of a difference.&lt;br /&gt;
&lt;br /&gt;
The next big optimization would be rearranging the chk_pattern() calls within each lexical analyzer to check the most likely patterns first. The best way to choose the best order is static analysis of sm8521 source code, which is obviously in very short supply. Accurate disassemblies of commercial Game.com games would be helpful to this end, however.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=As85&amp;diff=1003</id>
		<title>As85</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=As85&amp;diff=1003"/>
				<updated>2010-10-21T07:19:23Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;as85 is a simple assembler for the Sharp sm8521; the same microcontroller used in the Tiger Game.com. Game.com was released in 1998 and had only a few games ever made for it. It also has not had any homebrew games made for it. as85 is an attempt to build an assembler that will help hackers write homebrew code that will run on Game.com hardware.&lt;br /&gt;
&lt;br /&gt;
Documentation on the Game.com hardware is available at [http://gamecom.guruwork.de/ Game.commies].&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The source code is available at http://hg.kodewerx.org/as85/&lt;br /&gt;
&lt;br /&gt;
==Current Progress==&lt;br /&gt;
&lt;br /&gt;
The current state of as85 is &amp;quot;almost usable, but not quite there yet.&amp;quot; A number of bugs exist which need to be fixed before it can be used as a development tool:&lt;br /&gt;
&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=2 Bug 2]: Add support for jump/call/branch instructions&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=3 Bug 3]: Output object code&lt;br /&gt;
* [http://bugzilla.kodewerx.org/show_bug.cgi?id=4 Bug 4]: Write a linker&lt;br /&gt;
&lt;br /&gt;
I've also filed a bug about giving the project a better name [http://bugzilla.kodewerx.org/show_bug.cgi?id=5].&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
The program takes one argument; the file name of an sm8521 assembly file. The files in the [http://hg.kodewerx.org/index.cgi/as85/file/tip/examples /examples] directory are a good place to start.&lt;br /&gt;
&lt;br /&gt;
* test.asm is an example of what the beginning of a Game.com program might look like; it contains a header, and some [random] instructions to give you an idea.&lt;br /&gt;
* test2.asm is for testing the integrity of the parser with complex strings.&lt;br /&gt;
* test3.asm lists all possible sm8521 instructions; for verifying the output binary is correct.&lt;br /&gt;
&lt;br /&gt;
==Example Output==&lt;br /&gt;
&lt;br /&gt;
The following command:&lt;br /&gt;
 $ ./as85 ../examples/test3.asm&lt;br /&gt;
&lt;br /&gt;
Produces the following output:&lt;br /&gt;
 00 01           clr     R1&lt;br /&gt;
 01 01           neg     R1&lt;br /&gt;
 02 01           com     R1&lt;br /&gt;
 03 01           rr      R1&lt;br /&gt;
 04 01           rl      R1&lt;br /&gt;
 05 01           rrc     R1&lt;br /&gt;
 06 01           rlc     R1&lt;br /&gt;
 07 01           srl     R1&lt;br /&gt;
 08 01           inc     R1&lt;br /&gt;
 09 01           dec     R1&lt;br /&gt;
 0A 01           sra     R1&lt;br /&gt;
 0B 01           sll     R1&lt;br /&gt;
 0C 01           da      R1&lt;br /&gt;
 0D 01           swap    R1&lt;br /&gt;
 0E 01           push    R1&lt;br /&gt;
 0F 01           pop     R1&lt;br /&gt;
 10 0A           cmp     r1, r2&lt;br /&gt;
 11 0A           add     r1, r2&lt;br /&gt;
 12 0A           sub     r1, r2&lt;br /&gt;
 13 0A           adc     r1, r2&lt;br /&gt;
 14 0A           sbc     r1, r2&lt;br /&gt;
 15 0A           and     r1, r2&lt;br /&gt;
 16 0A           or      r1, r2&lt;br /&gt;
 17 0A           xor     r1, r2&lt;br /&gt;
 18 02           incw    RR2&lt;br /&gt;
 19 02           decw    RR2&lt;br /&gt;
 1A 08           clr     @r1&lt;br /&gt;
 1A 09           neg     @r1&lt;br /&gt;
 1A 0A           com     @r1&lt;br /&gt;
 1A 0B           rr      @r1&lt;br /&gt;
 1A 0C           rl      @r1&lt;br /&gt;
 1A 0D           rrc     @r1&lt;br /&gt;
 1A 0E           rlc     @r1&lt;br /&gt;
 1A 0F           srl     @r1&lt;br /&gt;
 1B 08           inc     @r1&lt;br /&gt;
 1B 09           dec     @r1&lt;br /&gt;
 1B 0A           sra     @r1&lt;br /&gt;
 1B 0B           sll     @r1&lt;br /&gt;
 1B 0C           da      @r1&lt;br /&gt;
 1B 0D           swap    @r1&lt;br /&gt;
 1B 0E           push    @r1&lt;br /&gt;
 1B 0F           pop     @r1&lt;br /&gt;
 1C 07 24        bclr    0xFF24, #7&lt;br /&gt;
 1C 0F 94        bclr    0x94(r1), #7&lt;br /&gt;
 1D 07 24        bset    0xFF24, #7&lt;br /&gt;
 1D 0F 94        bset    0x94(r1), #7&lt;br /&gt;
 1E 02           pushw   RR2&lt;br /&gt;
 1F 02           popw    RR2&lt;br /&gt;
 20 0A           cmp     r1, @r2&lt;br /&gt;
 20 4A           cmp     r1, (r2)+&lt;br /&gt;
 20 88 94        cmp     r1, @0x94&lt;br /&gt;
 20 8A 94        cmp     r1, 0x94(r2)&lt;br /&gt;
 20 CA           cmp     r1, -(r2)&lt;br /&gt;
 21 0A           add     r1, @r2&lt;br /&gt;
 21 4A           add     r1, (r2)+&lt;br /&gt;
 21 88 94        add     r1, @0x94&lt;br /&gt;
 21 8A 94        add     r1, 0x94(r2)&lt;br /&gt;
 21 CA           add     r1, -(r2)&lt;br /&gt;
 22 0A           sub     r1, @r2&lt;br /&gt;
 22 4A           sub     r1, (r2)+&lt;br /&gt;
 22 88 94        sub     r1, @0x94&lt;br /&gt;
 22 8A 94        sub     r1, 0x94(r2)&lt;br /&gt;
 22 CA           sub     r1, -(r2)&lt;br /&gt;
 23 0A           adc     r1, @r2&lt;br /&gt;
 23 4A           adc     r1, (r2)+&lt;br /&gt;
 23 88 94        adc     r1, @0x94&lt;br /&gt;
 23 8A 94        adc     r1, 0x94(r2)&lt;br /&gt;
 23 CA           adc     r1, -(r2)&lt;br /&gt;
 24 0A           sbc     r1, @r2&lt;br /&gt;
 24 4A           sbc     r1, (r2)+&lt;br /&gt;
 24 88 94        sbc     r1, @0x94&lt;br /&gt;
 24 8A 94        sbc     r1, 0x94(r2)&lt;br /&gt;
 24 CA           sbc     r1, -(r2)&lt;br /&gt;
 25 0A           and     r1, @r2&lt;br /&gt;
 25 4A           and     r1, (r2)+&lt;br /&gt;
 25 88 94        and     r1, @0x94&lt;br /&gt;
 25 8A 94        and     r1, 0x94(r2)&lt;br /&gt;
 25 CA           and     r1, -(r2)&lt;br /&gt;
 26 0A           or      r1, @r2&lt;br /&gt;
 26 4A           or      r1, (r2)+&lt;br /&gt;
 26 88 94        or      r1, @0x94&lt;br /&gt;
 26 8A 94        or      r1, 0x94(r2)&lt;br /&gt;
 26 CA           or      r1, -(r2)&lt;br /&gt;
 27 0A           xor     r1, @r2&lt;br /&gt;
 27 4A           xor     r1, (r2)+&lt;br /&gt;
 27 88 94        xor     r1, @0x94&lt;br /&gt;
 27 8A 94        xor     r1, 0x94(r2)&lt;br /&gt;
 27 CA           xor     r1, -(r2)&lt;br /&gt;
 28 0A           mov     r1, @r2&lt;br /&gt;
 28 4A           mov     r1, (r2)+&lt;br /&gt;
 28 88 94        mov     r1, @0x94&lt;br /&gt;
 28 8A 94        mov     r1, 0x94(r2)&lt;br /&gt;
 28 CA           mov     r1, -(r2)&lt;br /&gt;
 29 11           mov     @r1, r2&lt;br /&gt;
 29 51           mov     (r1)+, r2&lt;br /&gt;
 29 90 94        mov     @0x94, r2&lt;br /&gt;
 29 91 94        mov     0x94(r1), r2&lt;br /&gt;
 29 D1           mov     -(r1), r2&lt;br /&gt;
 2C 02           exts    RR2&lt;br /&gt;
 2E 94           mov     ps0, #0x94&lt;br /&gt;
 2F 94 01        btst    R1, #0x94&lt;br /&gt;
 30 09           cmp     r1, @rr2&lt;br /&gt;
 30 49           cmp     r1, (rr2)+&lt;br /&gt;
 30 88 24 94     cmp     r1, @0x9424&lt;br /&gt;
 30 89 24 94     cmp     r1, 0x9424(rr2)&lt;br /&gt;
 30 C9           cmp     r1, -(rr2)&lt;br /&gt;
 31 09           add     r1, @rr2&lt;br /&gt;
 31 49           add     r1, (rr2)+&lt;br /&gt;
 31 88 24 94     add     r1, @0x9424&lt;br /&gt;
 31 89 24 94     add     r1, 0x9424(rr2)&lt;br /&gt;
 31 C9           add     r1, -(rr2)&lt;br /&gt;
 32 09           sub     r1, @rr2&lt;br /&gt;
 32 49           sub     r1, (rr2)+&lt;br /&gt;
 32 88 24 94     sub     r1, @0x9424&lt;br /&gt;
 32 89 24 94     sub     r1, 0x9424(rr2)&lt;br /&gt;
 32 C9           sub     r1, -(rr2)&lt;br /&gt;
 33 09           adc     r1, @rr2&lt;br /&gt;
 33 49           adc     r1, (rr2)+&lt;br /&gt;
 33 88 24 94     adc     r1, @0x9424&lt;br /&gt;
 33 89 24 94     adc     r1, 0x9424(rr2)&lt;br /&gt;
 33 C9           adc     r1, -(rr2)&lt;br /&gt;
 34 09           sbc     r1, @rr2&lt;br /&gt;
 34 49           sbc     r1, (rr2)+&lt;br /&gt;
 34 88 24 94     sbc     r1, @0x9424&lt;br /&gt;
 34 89 24 94     sbc     r1, 0x9424(rr2)&lt;br /&gt;
 34 C9           sbc     r1, -(rr2)&lt;br /&gt;
 35 09           and     r1, @rr2&lt;br /&gt;
 35 49           and     r1, (rr2)+&lt;br /&gt;
 35 88 24 94     and     r1, @0x9424&lt;br /&gt;
 35 89 24 94     and     r1, 0x9424(rr2)&lt;br /&gt;
 35 C9           and     r1, -(rr2)&lt;br /&gt;
 36 09           or      r1, @rr2&lt;br /&gt;
 36 49           or      r1, (rr2)+&lt;br /&gt;
 36 88 24 94     or      r1, @0x9424&lt;br /&gt;
 36 89 24 94     or      r1, 0x9424(rr2)&lt;br /&gt;
 36 C9           or      r1, -(rr2)&lt;br /&gt;
 37 09           xor     r1, @rr2&lt;br /&gt;
 37 49           xor     r1, (rr2)+&lt;br /&gt;
 37 88 24 94     xor     r1, @0x9424&lt;br /&gt;
 37 89 24 94     xor     r1, 0x9424(rr2)&lt;br /&gt;
 37 C9           xor     r1, -(rr2)&lt;br /&gt;
 38 09           mov     r1, @rr2&lt;br /&gt;
 38 49           mov     r1, (rr2)+&lt;br /&gt;
 38 88 24 94     mov     r1, @0x9424&lt;br /&gt;
 38 89 24 94     mov     r1, 0x9424(rr2)&lt;br /&gt;
 38 C9           mov     r1, -(rr2)&lt;br /&gt;
 39 21           mov     @rr2, r4&lt;br /&gt;
 39 61           mov     (rr2)+, r4&lt;br /&gt;
 39 A0 24 94     mov     @0x9424, r4&lt;br /&gt;
 39 A1 24 94     mov     0x9424(rr2), r4&lt;br /&gt;
 39 E1           mov     -(rr2), r4&lt;br /&gt;
 3A 14           movw    rr2, @rr4&lt;br /&gt;
 3A 54           movw    rr2, (rr4)+&lt;br /&gt;
 3A 90 24 94     movw    rr2, @0x9424&lt;br /&gt;
 3A 94 24 94     movw    rr2, 0x9424(rr4)&lt;br /&gt;
 3A D4           movw    rr2, -(rr4)&lt;br /&gt;
 3B 22           movw    @rr2, rr4&lt;br /&gt;
 3B 62           movw    (rr2)+, rr4&lt;br /&gt;
 3B A0 24 94     movw    @0x9424, rr4&lt;br /&gt;
 3B A2 24 94     movw    0x9424(rr2), rr4&lt;br /&gt;
 3B E2           movw    -(rr2), rr4&lt;br /&gt;
 3C 14           movw    rr2, rr4&lt;br /&gt;
 40 02 01        cmp     R1, R2&lt;br /&gt;
 41 02 01        add     R1, R2&lt;br /&gt;
 42 02 01        sub     R1, R2&lt;br /&gt;
 43 02 01        adc     R1, R2&lt;br /&gt;
 44 02 01        sbc     R1, R2&lt;br /&gt;
 45 02 01        and     R1, R2&lt;br /&gt;
 46 02 01        or      R1, R2&lt;br /&gt;
 47 02 01        xor     R1, R2&lt;br /&gt;
 48 02 01        mov     R1, R2&lt;br /&gt;
 4A 04 02        movw    RR2, RR4&lt;br /&gt;
 4B 02 24 94     movw    RR2, #0x9424&lt;br /&gt;
 4C 04 02        mult    RR2, R4&lt;br /&gt;
 4D 94 02        mult    RR2, #0x94&lt;br /&gt;
 4E 07 01        bmov    bf, R1, #7&lt;br /&gt;
 4E 47 01        bmov    R1, #7, bf&lt;br /&gt;
 4F 07 01        bcmp    bf, R1, #7&lt;br /&gt;
 4F 47 01        band    bf, R1, #7&lt;br /&gt;
 4F 87 01        bor     bf, R1, #7&lt;br /&gt;
 4F C7 01        bxor    bf, R1, #7&lt;br /&gt;
 50 94 01        cmp     R1, #0x94&lt;br /&gt;
 51 94 01        add     R1, #0x94&lt;br /&gt;
 52 94 01        sub     R1, #0x94&lt;br /&gt;
 53 94 01        adc     R1, #0x94&lt;br /&gt;
 54 94 01        sbc     R1, #0x94&lt;br /&gt;
 55 94 01        and     R1, #0x94&lt;br /&gt;
 56 94 01        or      R1, #0x94&lt;br /&gt;
 57 94 01        xor     R1, #0x94&lt;br /&gt;
 58 94 01        mov     R1, #0x94&lt;br /&gt;
 5C 04 02        div     RR2, RR4&lt;br /&gt;
 5D 94 02        div     RR2, #0x94&lt;br /&gt;
 5E 01 94 02     movm    R1, #0x94, R2&lt;br /&gt;
 5F 01 94 24     movm    R1, #0x94, #0x24&lt;br /&gt;
 60 04 02        cmpw    RR2, RR4&lt;br /&gt;
 61 04 02        addw    RR2, RR4&lt;br /&gt;
 62 04 02        subw    RR2, RR4&lt;br /&gt;
 63 04 02        adcw    RR2, RR4&lt;br /&gt;
 64 04 02        sbcw    RR2, RR4&lt;br /&gt;
 65 04 02        andw    RR2, RR4&lt;br /&gt;
 66 04 02        orw     RR2, RR4&lt;br /&gt;
 67 04 02        xorw    RR2, RR4&lt;br /&gt;
 68 02 24 94     cmpw    RR2, #0x9424&lt;br /&gt;
 69 02 24 94     addw    RR2, #0x9424&lt;br /&gt;
 6A 02 24 94     subw    RR2, #0x9424&lt;br /&gt;
 6B 02 24 94     adcw    RR2, #0x9424&lt;br /&gt;
 6C 02 24 94     sbcw    RR2, #0x9424&lt;br /&gt;
 6D 02 24 94     andw    RR2, #0x9424&lt;br /&gt;
 6E 02 24 94     orw     RR2, #0x9424&lt;br /&gt;
 6F 02 24 94     xorw    RR2, #0x9424&lt;br /&gt;
 78 24 94        movw    rr0, #0x9424&lt;br /&gt;
 79 24 94        movw    rr8, #0x9424&lt;br /&gt;
 7A 24 94        movw    rr2, #0x9424&lt;br /&gt;
 7B 24 94        movw    rr10, #0x9424&lt;br /&gt;
 7C 24 94        movw    rr4, #0x9424&lt;br /&gt;
 7D 24 94        movw    rr12, #0x9424&lt;br /&gt;
 7E 24 94        movw    rr6, #0x9424&lt;br /&gt;
 7F 24 94        movw    rr14, #0x9424&lt;br /&gt;
 A0 01           bclr    R1, #0&lt;br /&gt;
 A1 01           bclr    R1, #1&lt;br /&gt;
 A2 01           bclr    R1, #2&lt;br /&gt;
 A3 01           bclr    R1, #3&lt;br /&gt;
 A4 01           bclr    R1, #4&lt;br /&gt;
 A5 01           bclr    R1, #5&lt;br /&gt;
 A6 01           bclr    R1, #6&lt;br /&gt;
 A7 01           bclr    R1, #7&lt;br /&gt;
 A8 01           bset    R1, #0&lt;br /&gt;
 A9 01           bset    R1, #1&lt;br /&gt;
 AA 01           bset    R1, #2&lt;br /&gt;
 AB 01           bset    R1, #3&lt;br /&gt;
 AC 01           bset    R1, #4&lt;br /&gt;
 AD 01           bset    R1, #5&lt;br /&gt;
 AE 01           bset    R1, #6&lt;br /&gt;
 AF 01           bset    R1, #7&lt;br /&gt;
 B0 01           mov     r0, R1&lt;br /&gt;
 B1 01           mov     r1, R1&lt;br /&gt;
 B2 01           mov     r2, R1&lt;br /&gt;
 B3 01           mov     r3, R1&lt;br /&gt;
 B4 01           mov     r4, R1&lt;br /&gt;
 B5 01           mov     r5, R1&lt;br /&gt;
 B6 01           mov     r6, R1&lt;br /&gt;
 B7 01           mov     r7, R1&lt;br /&gt;
 B8 01           mov     R1, r0&lt;br /&gt;
 B9 01           mov     R1, r1&lt;br /&gt;
 BA 01           mov     R1, r2&lt;br /&gt;
 BB 01           mov     R1, r3&lt;br /&gt;
 BC 01           mov     R1, r4&lt;br /&gt;
 BD 01           mov     R1, r5&lt;br /&gt;
 BE 01           mov     R1, r6&lt;br /&gt;
 BF 01           mov     R1, r7&lt;br /&gt;
 C0 94           mov     r0, #0x94&lt;br /&gt;
 C1 94           mov     r1, #0x94&lt;br /&gt;
 C2 94           mov     r2, #0x94&lt;br /&gt;
 C3 94           mov     r3, #0x94&lt;br /&gt;
 C4 94           mov     r4, #0x94&lt;br /&gt;
 C5 94           mov     r5, #0x94&lt;br /&gt;
 C6 94           mov     r6, #0x94&lt;br /&gt;
 C7 94           mov     r7, #0x94&lt;br /&gt;
 C8 94           mov     ie0, #0x94&lt;br /&gt;
 C9 94           mov     ie1, #0x94&lt;br /&gt;
 CA 94           mov     ir0, #0x94&lt;br /&gt;
 CB 94           mov     ir1, #0x94&lt;br /&gt;
 CC 94           mov     p0, #0x94&lt;br /&gt;
 CD 94           mov     p1, #0x94&lt;br /&gt;
 CE 94           mov     p2, #0x94&lt;br /&gt;
 CF 94           mov     p3, #0x94&lt;br /&gt;
 F0              stop&lt;br /&gt;
 F1              halt&lt;br /&gt;
 F8              ret&lt;br /&gt;
 F9              iret&lt;br /&gt;
 FA              clrc&lt;br /&gt;
 FB              comc&lt;br /&gt;
 FC              setc&lt;br /&gt;
 FD              ei&lt;br /&gt;
 FE              di&lt;br /&gt;
 FF              nop&lt;br /&gt;
 assemble() returned 0: OK&lt;br /&gt;
 Clean up...&lt;br /&gt;
&lt;br /&gt;
Note: The output binary has not been verified for accuracy.&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
As85 is a fairly simple assembler. It doesn't use any sort of 'compiler-compiler' for lexical analysis. In fact, its lexical analysis is very specific to the sm8521 MCU.&lt;br /&gt;
&lt;br /&gt;
The main loop (assemble() function, defined in [http://hg.kodewerx.org/index.cgi/as85/file/a90c47020126/src/asm.c#l315 asm.c]) does the input text parsing inline. (This should probably be moved out to a new source file.) After splitting a line into two pieces; op[0] containing the instruction, and op[1] containing its operands; a string comparison against op[0] is done over all supported instructions. If a match is found, the operands string is passed to a dynamically chosen function (from a [http://hg.kodewerx.org/index.cgi/as85/file/a90c47020126/src/inst.c#l156 function pointer table], indexed by the matched instruction). This function performs the lexical analysis required to decide which instruction we are trying to assemble.&lt;br /&gt;
&lt;br /&gt;
Since the sm8521 is a CISC machine, its instruction set contains a number of different ways to assemble the same instruction mnemonic. For example, several different addressing modes for the ''mov'' instruction are shown above in the test3.asm output. The lexical analysis is the voodoo which picks the proper addressing mode and byte codes by analyzing the operands.&lt;br /&gt;
&lt;br /&gt;
The lexical analyzing functions are defined in inst.c (following the function pointer table mentioned previously). The function handling the current instruction will test the operands string against a series of lexical patterns with the [http://hg.kodewerx.org/index.cgi/as85/file/a90c47020126/src/asm.c#l89 chk_pattern()] function (defined in asm.c, although this should probably be moved).&lt;br /&gt;
&lt;br /&gt;
chk_pattern() uses a scanf-like formatting string, rather than a regular expression, which is more common in lexical analysis. Documentation for the formatting string can be found in [http://hg.kodewerx.org/index.cgi/as85/file/a90c47020126/src/inst.h#l29 inst.h]. With just a few pattern primitives, any of the sm8521's addressing modes can be matched, with the matching primitives output as part of an array. It makes good use of the format scanners defined in [http://hg.kodewerx.org/index.cgi/as85/file/a90c47020126/src/scan.c scan.c].&lt;br /&gt;
&lt;br /&gt;
If chk_pattern() manages to find a match, the matching data may be further checked for validity on a per-context basis. Finally, the full instruction byte codes will be put together and returned to the assemble() loop. This is where the object code would be built. Currently the only thing that happens now is dumping the assembled instruction to stdout, in a debug build. [http://hg.kodewerx.org/index.cgi/as85/file/a90c47020126/src/asm.c#l464]&lt;br /&gt;
&lt;br /&gt;
===Optimization Concerns===&lt;br /&gt;
&lt;br /&gt;
Some optimization could be done within this lexical analysis process. The first improvement would be replacing the linear string comparison with a binary search tree. The second thing that would help in this immediate area would be replacing the string comparison itself with a hash comparison. The hash algorithm would have to be suitably small and fast enough to make much of a difference.&lt;br /&gt;
&lt;br /&gt;
The next big optimization would be rearranging the chk_pattern() calls within each lexical analyzer to check the most likely patterns first. The best way to choose the best order is static analysis of sm8521 source code, which is obviously in very short supply. Accurate disassemblies of commercial Game.com games would be helpful to this end, however.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Descend&amp;diff=1002</id>
		<title>Descend</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Descend&amp;diff=1002"/>
				<updated>2010-10-21T07:06:43Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Push Changesets to hgkw */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Descend is a proof of concept, showing the possibilities of creating an open source debugger UI with Mozilla [https://developer.mozilla.org/En/XULRunner XULRunner]. Descend is distributed under the [http://www.mozilla.org/MPL/ MPL]/[http://www.gnu.org/licenses/gpl.html GPL]/[http://www.gnu.org/licenses/lgpl.html LGPL] tri-license.&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
The Descend source code is available in a [http://www.selenic.com/mercurial/wiki/ Mercurial] repository. Mercurial can be downloaded from [http://www.selenic.com/mercurial/wiki/index.cgi/BinaryPackages Selenic]. Windows users may find [http://tortoisehg.sourceforge.net/ TortoiseHG] useful.&lt;br /&gt;
&lt;br /&gt;
Descend currently does not contain a local copy of XULRunner (and may never have one; It would be best to use a globally available XULRunner). You can use the XULRunner bundled with Firefox 3.x to run Descend.&lt;br /&gt;
&lt;br /&gt;
==Setup Your Mercurial Client==&lt;br /&gt;
&lt;br /&gt;
At the minimum, you should configure your Mercurial client with a &amp;quot;username&amp;quot;. For hg, add the following to your ~/.hgrc file (or create a new one)&lt;br /&gt;
&lt;br /&gt;
 [ui]&lt;br /&gt;
 username = Real Name &amp;lt;email@address.tld&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
===Clone the Source Repository===&lt;br /&gt;
&lt;br /&gt;
Create a local repository with the following command:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;$ hg clone http://hg.kodewerx.org/descend&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create a new subdirectory called &amp;quot;descend&amp;quot; containing all of the source code and repository history.&lt;br /&gt;
&lt;br /&gt;
===Push Changesets to hgkw===&lt;br /&gt;
&lt;br /&gt;
If you have developer access to push changesets to the hgkw repository, use the following command: (Don't forget to commit to your local repository, first!)&lt;br /&gt;
&lt;br /&gt;
 $ hg push ssh://hg@hg.kodewerx.org/repos/descend&lt;br /&gt;
&lt;br /&gt;
==Running Descend==&lt;br /&gt;
&lt;br /&gt;
On Linux, run the included ''descend_linux'' shell script. (Tested on Ubuntu 8.10)&lt;br /&gt;
&lt;br /&gt;
On Mac OS X, run the included ''descend_osx'' shell script.&lt;br /&gt;
&lt;br /&gt;
On Windows, go to Start -&amp;gt; Run, and type:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;C:\Program Files\Mozilla Firefox\firefox.exe&amp;quot; --app &amp;quot;path/to/descend&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be sure to verify the path the your Firefox installation is correct. You can also create a batch script to do the same thing.&lt;br /&gt;
&lt;br /&gt;
==Developer Notes==&lt;br /&gt;
&lt;br /&gt;
In its current form, Descend is just a &amp;quot;syntax highlighter&amp;quot; that can process simple 6502 assembly source code. It will spit out an XHTML-ized copy of the source, with some pretty CSS.&lt;br /&gt;
&lt;br /&gt;
===Style Contexts===&lt;br /&gt;
&lt;br /&gt;
The concept of a &amp;quot;Style Context&amp;quot; is greatly inspired by [http://qbnz.com/highlighter/ GeSHi], which uses &amp;quot;[http://qbnz.com/highlighter/geshi-doc.html#language-files Language Files]&amp;quot; to define to the highlighter engine how text should be styled. Descend uses files similar to GeSHi's Language Files (called Syntax Contexts) to define syntax.&lt;br /&gt;
&lt;br /&gt;
Writing new syntax highlighters should be very simple. See ''[http://hg.kodewerx.org/index.cgi/descend/file/tip/chrome/content/styles/6502.js descend/chrome/content/styles/6502.js]'' for the 6502 style context.&lt;br /&gt;
&lt;br /&gt;
The ''Style Context'' is a JavaScript object which tells [http://hg.kodewerx.org/index.cgi/descend/file/tip/chrome/content/highlight.js highlight.js] how to interpret the input text. It is technically an array of simple objects, where each object contains (at a minimum) a ''rule'' and a ''class''.&lt;br /&gt;
&lt;br /&gt;
The ''rule'' tells highlight.js what to search for. It can be either a regular expression (do use the /g flag if you want to find all occurrences) or an array of strings.&lt;br /&gt;
&lt;br /&gt;
The ''class'' is simply which CSS class to give the text which matches ''rule''. The CSS used is [http://hg.kodewerx.org/index.cgi/descend/file/tip/chrome/content/template.css template.css].&lt;br /&gt;
&lt;br /&gt;
====Example Style Context====&lt;br /&gt;
&lt;br /&gt;
 var style = [&lt;br /&gt;
     {&lt;br /&gt;
         rule: /hello,?\s*world!/g,&lt;br /&gt;
         class: 'hello-world'&lt;br /&gt;
     },&lt;br /&gt;
     {&lt;br /&gt;
         rule: [ 'hello', 'world' ],&lt;br /&gt;
         class: 'hello-world'&lt;br /&gt;
     }&lt;br /&gt;
 ];&lt;br /&gt;
&lt;br /&gt;
====Style Context Reference====&lt;br /&gt;
&lt;br /&gt;
Each object contains two mandatory members; ''rule'' and ''class'':&lt;br /&gt;
{| cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! style=&amp;quot;width: 100px;&amp;quot; |''rule''&lt;br /&gt;
|Specifies a matching rule as either a single RegExp or as an Array of Strings which will later each be searched for as exact matches.&lt;br /&gt;
Notes for using RegExps:&lt;br /&gt;
&lt;br /&gt;
Always include the 'g' flag; Only use the 'm' and 'i' flags if you truly need them (eg. using ^ or $ to match the beginning/end of lines, or if your RegExp includes strings that must match case-insensitively!) There is currently no need for the 'y' flag. Use remembering-parentheses sparingly (and only with the ''id'' member).&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width: 100px;&amp;quot; |''class''&lt;br /&gt;
|Specifies which CSS class[es] should be used to style the matches. Multiple classes should be separated by spaces.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In addition, each object may have zero or more optional members:&lt;br /&gt;
&lt;br /&gt;
{| cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! style=&amp;quot;width: 100px;&amp;quot; |''anchor''&lt;br /&gt;
|A String which specifies that these matches should be generated as HTML anchors. The String given is used as a prefix for the anchor's 'name' attribute.&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width: 100px;&amp;quot; |''delim''&lt;br /&gt;
|An Array containing 1 or 2 Strings that specifies which characters are allowed to appear before [0] and after [1] the rule. An empty String designates that any character is allowed (default). If only one String is specified, it is used for both before and after delimiters. Only has effect with String ''rule''s.&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width: 100px;&amp;quot; |''icase''&lt;br /&gt;
|A Boolean value identifying the rule as case-insensitive (true) or case-sensitive (false, default). Only has effect with String ''rule''s.&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width: 100px;&amp;quot; |''id''&lt;br /&gt;
|A Number representing which remembered match to use for the ''anchor'' or ''link'' name. Defaults to 0. Only has effect with ''anchor'' or ''link'', and RegExp ''rule''s.&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width: 100px;&amp;quot; |''link''&lt;br /&gt;
|A String which specifies that these matches should be generated as HTML links. The String given is used as a prefix for the target ''anchor''.&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width: 100px;&amp;quot; |''sub''&lt;br /&gt;
|A sub-context: an Array of Objects containing ''rule''s, ''class''es, etc. The text matching ''rule'' will be recursively styled with this sub-context.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The highlighter will match text in Object-order. For example, you should match single line comments (beginning with //) before matching division operators (a single /) by writing your comment-matching rule first. If they are specified in opposite order, you will be given two consecutive division operators and the comment will not be styled.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Kwiki&amp;diff=1001</id>
		<title>Kwiki</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Kwiki&amp;diff=1001"/>
				<updated>2010-10-21T06:57:11Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Welcome to the Kodewerx wiki. While browsing its contents, remember that ''you'' can make changes to anything you see here. It might be as simple as bad spelling or grammar, or it could be an entirely new page that you create; it's up to you to help the Kodewerx wiki grow into a valuable resource for hackers and programmers alike.&lt;br /&gt;
&lt;br /&gt;
To get you started, here's what we have going on right now:&lt;br /&gt;
&lt;br /&gt;
==Kodewerx Projects==&lt;br /&gt;
&lt;br /&gt;
The main page for &amp;quot;Kodewerx Projects&amp;quot; can be found at the [[:Category:Developer Documentation|Developer Documentation]] page. Most of these projects are immature, and not yet usable for ordinary users. (We need your help!) Source code is available at http://hg.kodewerx.org/ and issue tracking provided at http://trac.kodewerx.org/&lt;br /&gt;
&lt;br /&gt;
-[[User:Parasyte|Parasyte]] 06:57, 21 October 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=A_Brief_Introduction_To_XULRunner:_Part_2&amp;diff=999</id>
		<title>A Brief Introduction To XULRunner: Part 2</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=A_Brief_Introduction_To_XULRunner:_Part_2&amp;diff=999"/>
				<updated>2010-04-14T00:31:36Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* XUL Editors and Designers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Now that you are familiar with what XULRunner ''is'', let's explore ''how'' to use it. More generally, let's explore how to use Mozilla tools that were designed to make building XULRunner applications easier.&lt;br /&gt;
&lt;br /&gt;
==How to Use XULRunner==&lt;br /&gt;
&lt;br /&gt;
===Setting Up a XULRunner Development Environment===&lt;br /&gt;
&lt;br /&gt;
Setting up your XULRunner development environment is very easy. You need just a few programs to get started:&lt;br /&gt;
&lt;br /&gt;
* A text editor of your choosing. If you don't have one with XML/XUL/JavaScript/CSS syntax highlighting, you might want to check out one of the many [http://www.scintilla.org/ Scintilla]-based editors: [http://www.geany.org Geany] is excellent for Linux (GTK+) users, and decent on Windows ([http://www.scintilla.org/SciTE.html SciTE] is similar); [http://www.activestate.com/komodo_edit/ Komodo Edit] is excellent on any XULRunner-supported platform (Hooray for XULRunner!); and there are [http://www.scintilla.org/ScintillaRelated.html many others] to choose from.&lt;br /&gt;
* The XULRunner Runtime itself. Download the latest stable version from Mozilla: http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ (Note: Go into the most recent sub-directory and then the &amp;quot;runtimes&amp;quot; sub-directory. You don't need the SDK.)&lt;br /&gt;
&lt;br /&gt;
After installing the XULRunner runtime and text editor of your choice, you can begin creating a new project template.&lt;br /&gt;
&lt;br /&gt;
===Creating a XULRunner Application Template===&lt;br /&gt;
&lt;br /&gt;
Developers familiar with C and C++ know that all C/C++ applications must have a function called main(). Or in Win32 development, things are even more convoluted; a WinMain() function is required, along with a message pump and some other nonsense. Similarly, all XULRunner applications have a series of requirements (functional and structural) to &amp;quot;bootstrap&amp;quot; the application.&lt;br /&gt;
&lt;br /&gt;
Often, this task of creating a new project is tedious, mundane, and repetitive (to name just a few adjectives). This is why most C/C++ developers just copy startup (and maybe other) code from an existing project when creating a whole new one. That takes care of the bootstrapping process, without having to remember everything required to get up and running. This can certainly be done with new XULRunner applications, if you like. But there is an easier way...&lt;br /&gt;
&lt;br /&gt;
====FizzyPop, Or &amp;quot;How I Made My XULRunner Application&amp;quot;====&lt;br /&gt;
&lt;br /&gt;
Those clever folks at Mozilla know how bothersome it is to create a base XULRunner application (for the curious among you, have a look at the [https://developer.mozilla.org/en/Getting_started_with_XULRunner official tutorial, steps 3 - 7]). And so they created a project called [https://wiki.mozilla.org/FizzyPop FizzyPop] which will create all that fun boilerplate stuff for you; just give your project a name, maybe a version number, give it your name as the author, select a few options ... and BAM! Instant XULRunner Application: Just Add Water (tm).&lt;br /&gt;
&lt;br /&gt;
So here we go! To use this magical &amp;quot;FizzyPop&amp;quot; thing, just point your web browser to it! There are currently two different resources available for it (to my knowledge). The latter has been tagged a &amp;quot;prototype&amp;quot; so it might not be the one you want to use. But don't quote me on that! Without further ado, just go there:&lt;br /&gt;
&lt;br /&gt;
* [http://www.mozdev.org/projects/wizard/ Mozilla Project Wizard] ... OR ...&lt;br /&gt;
* [http://starkravingfinkle.org/projects/fizzypop/ FizzyPop prototype]&lt;br /&gt;
&lt;br /&gt;
Choose the &amp;quot;Application&amp;quot; Start link. Now there are just a couple of [very, very simple] steps to follow, and you'll be on your way:&lt;br /&gt;
&lt;br /&gt;
# Give your project a name. I chose &amp;quot;Hello World&amp;quot;.&lt;br /&gt;
# And an ID. The ID is in the form of an email address, which seems odd at first, but makes sense in the proper context ([[#Project ID]]). I chose &amp;quot;helloworld@kodewerx.org&amp;quot; for mine. If you don't have a domain, you can just use your own name in place of one.&lt;br /&gt;
# A short &amp;quot;package name&amp;quot; as well; for mine, &amp;quot;helloworld&amp;quot;.&lt;br /&gt;
# You can leave the version number and build ID at their default values (note that the &amp;quot;prototype&amp;quot; does not give you any default values) ... or go ahead and punch in some different numbers. It won't matter much.&lt;br /&gt;
# It also requires some author information (that's you!) Enter your name here.&lt;br /&gt;
# Set the Platform Details minimum and maximum version numbers according to the XULRunner runtime version you're using. In my case, minimum is set to &amp;quot;1.9.2.0&amp;quot; and maximum is &amp;quot;1.9.2.*&amp;quot;.&lt;br /&gt;
# You may leave the other entries blank, or configure them to your liking.&lt;br /&gt;
# Click the final &amp;quot;Create&amp;quot; button, and it will start to download a zip archive containing all of the necessary files and directory structures for a basic XULRunner application.&lt;br /&gt;
# Extract the zip file somewhere on your local drive. A &amp;quot;projects&amp;quot; folder for example.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is write some XUL to make it look like a program, and some JavaScript to make it do something! Or, you could always run the base application, just to see if your XULRunner setup works. This isn't a bad idea, after all.&lt;br /&gt;
&lt;br /&gt;
====Testing and Installation====&lt;br /&gt;
&lt;br /&gt;
=====On Mac OS X=====&lt;br /&gt;
&lt;br /&gt;
To test your application boilerplate, run XULRunner from the command line, passing the path to the &amp;quot;application.ini&amp;quot; as an argument. For example, on Mac OS X, I run this from the Terminal:&lt;br /&gt;
&lt;br /&gt;
 /Library/Frameworks/XUL.framework/xulrunner-bin /Users/parasyte/Desktop/helloworld-app-project/application.ini&lt;br /&gt;
&lt;br /&gt;
Note: XULRunner on OS X requires the full path to the application.ini file&lt;br /&gt;
&lt;br /&gt;
After making sure it works (you should be given a blank window) you can install the application to make it act more like a real app. (For example, installation will give it a Dock icon, menu bar, etc.) To install on OS X:&lt;br /&gt;
&lt;br /&gt;
 /Library/Frameworks/XUL.framework/xulrunner-bin --install-app /Users/parasyte/Desktop/helloworld-app-project&lt;br /&gt;
&lt;br /&gt;
Note: Don't include the &amp;quot;/application.ini&amp;quot; when installing the app!&lt;br /&gt;
&lt;br /&gt;
With the application installed, you can find it in your /Applications/ directory. If you set a &amp;quot;Vendor&amp;quot; when you created the boilerplate, then it will be put into /Applications/vendor-name/&lt;br /&gt;
&lt;br /&gt;
=====On Windows=====&lt;br /&gt;
&lt;br /&gt;
From the &amp;quot;Run&amp;quot; window (Start -&amp;gt; Run...) use the following command:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;%PROGRAMFILES%\XULRunner\xulrunner.exe&amp;quot; &amp;quot;path\to\application.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Where &amp;quot;path\to\application.ini&amp;quot; is the actual path the the actual application.ini file. If it works, you will get a blank window. You can then install the application with the following:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;%PROGRAMFILES%\XULRunner\xulrunner.exe&amp;quot; --install-app &amp;quot;path\to\application&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Where &amp;quot;path\to\application&amp;quot; is the path to the application's top-level directory; NOT the application.ini file. This will install the application to &amp;quot;%PROGRAMFILES%\application-name\&amp;quot;, or if you set the &amp;quot;Vendor&amp;quot; field when you created the boilerplate, in &amp;quot;%PROGRAMFILES%\vendor-name\application-name\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=====On Ubuntu Linux=====&lt;br /&gt;
&lt;br /&gt;
In a terminal:&lt;br /&gt;
&lt;br /&gt;
 /path/to/xulrunner-bin &amp;quot;/path/to/application.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A blank window appearing means all worked well. To install:&lt;br /&gt;
&lt;br /&gt;
 /path/to/xulrunner-bin --install-app &amp;quot;/path/to/application&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Note: Do not point the installer to the application.ini file; point it instead to the application's top-level directory.&lt;br /&gt;
&lt;br /&gt;
====Project ID====&lt;br /&gt;
&lt;br /&gt;
The XULRunner Project ID is a unique identifier, which allows certain features of XULRunner to work properly. I can't exactly name any specific use for it off-hand, but I believe it can be used by extensions to access specific data local to your application.&lt;br /&gt;
&lt;br /&gt;
===Hello World===&lt;br /&gt;
&lt;br /&gt;
To complete the first step towards world domination with XULRunner, you'll want to make the application do something (or at least, ''say'' something) ...&lt;br /&gt;
&lt;br /&gt;
Open the file /chrome/content/main.xul in your application directory. You will be greeted with a lot of XML. This is the file that defines the complete GUI for your application's main window. You can add any XUL elements to this file to create any kind of widget in your main window. For starters, just add a simple label element before the &amp;lt;/vbox&amp;gt; tag, near the end of the file. Something like this:&lt;br /&gt;
&lt;br /&gt;
   &amp;lt;hbox id=&amp;quot;main_box&amp;quot; flex=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;lt;vbox id=&amp;quot;workspace_box&amp;quot; flex=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;&amp;lt;label value=&amp;quot;Hello, World!&amp;quot;/&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
     &amp;lt;/vbox&amp;gt;&lt;br /&gt;
   &amp;lt;/hbox&amp;gt;&lt;br /&gt;
 &amp;lt;/window&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the app to see your changes. Reinstall it, if you like. When reinstalling, it is a good idea to first delete the old already-installed application, but this is not always necessary.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
Now that you have a Hello World XULRunner app, you can continue exploring the rest of what XULRunner has to offer. This means XUL and JavaScript... The following sections provide some helpful resources (API references, tutorials, etc.) which will get your on your way. Since you are up and running with a minimal application, it won't take much longer until you have a killer-app of your very own!&lt;br /&gt;
&lt;br /&gt;
===Developer Resources===&lt;br /&gt;
&lt;br /&gt;
This is a list of websites relevant to XULRunner and creating applications for it. While this list is produced entirely without any specific order, I've attempted to keep the most important of these near the top.&lt;br /&gt;
&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_Tutorial Mozilla Developer Central: XUL Tutorial] (Slightly old, but still one of the best sources of information on XUL.)&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL Mozilla Developer Central: XUL Information] (Specifically, the complete [https://developer.mozilla.org/en/XUL_Reference XUL Reference].)&lt;br /&gt;
* [https://developer.mozilla.org/en/XULRunner Mozilla Developer Central: XULRunner Information]&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_School Mozilla Developer Central: XUL School] (Targets Firefox Extension developers, but contains XUL tutorial)&lt;br /&gt;
* [http://www.xul.fr/tutorial/ XUL.fr Tutorial]&lt;br /&gt;
* [http://books.mozdev.org/chapters/index.html Creating Applications With Mozilla] (Online book.)&lt;br /&gt;
* [http://mb.eschew.org/ Rapid Application Development With Mozilla] (Online book.)&lt;br /&gt;
* [https://developer.mozilla.org/en/Creating_XPCOM_Components Creating XPCOM Components] (Online book.)&lt;br /&gt;
* [http://www.oxymoronical.com/experiments/xpcomref/ Mozilla XPCOM Reference] (All interfaces and components; always kept up-to-date.)&lt;br /&gt;
* [https://addons.mozilla.org/en-US/developers Mozilla Add-on Developer Hub] (Mostly related to Firefox add-on development; but useful for XULRunner, too.)&lt;br /&gt;
* [http://parasyte.kodewerx.org/projects/xulrunner/x-xulintro-pdf.pdf IBM developerWorks: An introduction to XML User Interface Language (XUL) development] (PDF, mirrored here because IBM requires compulsory registration to download this from their website. Original location: http://www.ibm.com/developerworks/edu/x-dw-x-xulintro.html)&lt;br /&gt;
* [http://kb.mozillazine.org/Development_resources MozillaZine: Development Resources] (Semi-outdated.)&lt;br /&gt;
* [http://xml.coverpages.org/xul.html Cover Pages: Extensible User Interface Language (XUL)] (Extremely outdated, but historically relevant.)&lt;br /&gt;
&lt;br /&gt;
====XUL Editors and Designers====&lt;br /&gt;
&lt;br /&gt;
I've found these applications helpful, while learning XUL.&lt;br /&gt;
&lt;br /&gt;
* [http://ted.mielczarek.org/code/mozilla/xuledit/xuledit.xul Ted Mielczarek's Real-Time XUL Editor] (Great for quickly testing XUL from directly within Firefox.)&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_Explorer XUL Explorer] (Similar to the Real-Time XUL Editor above, but as a XULRunner application.)&lt;br /&gt;
* [http://kukuru.s7.xrea.com/xulpix/ XULPIX] (A ''great'' XUL editor; the closest thing to a form designer that we currently have ... without Eclipse! Yucky...)&lt;br /&gt;
* [http://www.evolus.vn/Pencil/Home.html Pencil Project] (Firefox extension for &amp;quot;sketching&amp;quot;. It allows you to prototype/mockup UI elements. Not really a form designer, but pretty close.)&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;br /&gt;
&lt;br /&gt;
===Packaging===&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Packaging&amp;quot; is the process of creating an installer for your application. So far as I know, you have two choices here:&lt;br /&gt;
&lt;br /&gt;
# Create a self-contained installer, which includes its own private copy of the XULRunner runtime.&lt;br /&gt;
# Create an XPI; an archive that can be installed as a XULRunner application by a pre-existing XULRunner runtime.&lt;br /&gt;
&lt;br /&gt;
The latter option requires that your users install the XULRunner runtime (just like you did at the beginning of this introduction). The former option just requires that the user download the installer and install it. This option has the disadvantage that the file the user must download is a *LOT* larger than just the simple XPI. About 9MB for Windows and Linux, or 17MB for Mac OS X; compared to just a few KB (typically 10KB for a small app, like our Hello World) for the XPI!&lt;br /&gt;
&lt;br /&gt;
I haven't yet investigated XULRunner application packaging. This section is in need of completion.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=A_Brief_Introduction_To_XULRunner:_Part_2&amp;diff=998</id>
		<title>A Brief Introduction To XULRunner: Part 2</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=A_Brief_Introduction_To_XULRunner:_Part_2&amp;diff=998"/>
				<updated>2010-04-14T00:13:13Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Developer Resources */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Now that you are familiar with what XULRunner ''is'', let's explore ''how'' to use it. More generally, let's explore how to use Mozilla tools that were designed to make building XULRunner applications easier.&lt;br /&gt;
&lt;br /&gt;
==How to Use XULRunner==&lt;br /&gt;
&lt;br /&gt;
===Setting Up a XULRunner Development Environment===&lt;br /&gt;
&lt;br /&gt;
Setting up your XULRunner development environment is very easy. You need just a few programs to get started:&lt;br /&gt;
&lt;br /&gt;
* A text editor of your choosing. If you don't have one with XML/XUL/JavaScript/CSS syntax highlighting, you might want to check out one of the many [http://www.scintilla.org/ Scintilla]-based editors: [http://www.geany.org Geany] is excellent for Linux (GTK+) users, and decent on Windows ([http://www.scintilla.org/SciTE.html SciTE] is similar); [http://www.activestate.com/komodo_edit/ Komodo Edit] is excellent on any XULRunner-supported platform (Hooray for XULRunner!); and there are [http://www.scintilla.org/ScintillaRelated.html many others] to choose from.&lt;br /&gt;
* The XULRunner Runtime itself. Download the latest stable version from Mozilla: http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ (Note: Go into the most recent sub-directory and then the &amp;quot;runtimes&amp;quot; sub-directory. You don't need the SDK.)&lt;br /&gt;
&lt;br /&gt;
After installing the XULRunner runtime and text editor of your choice, you can begin creating a new project template.&lt;br /&gt;
&lt;br /&gt;
===Creating a XULRunner Application Template===&lt;br /&gt;
&lt;br /&gt;
Developers familiar with C and C++ know that all C/C++ applications must have a function called main(). Or in Win32 development, things are even more convoluted; a WinMain() function is required, along with a message pump and some other nonsense. Similarly, all XULRunner applications have a series of requirements (functional and structural) to &amp;quot;bootstrap&amp;quot; the application.&lt;br /&gt;
&lt;br /&gt;
Often, this task of creating a new project is tedious, mundane, and repetitive (to name just a few adjectives). This is why most C/C++ developers just copy startup (and maybe other) code from an existing project when creating a whole new one. That takes care of the bootstrapping process, without having to remember everything required to get up and running. This can certainly be done with new XULRunner applications, if you like. But there is an easier way...&lt;br /&gt;
&lt;br /&gt;
====FizzyPop, Or &amp;quot;How I Made My XULRunner Application&amp;quot;====&lt;br /&gt;
&lt;br /&gt;
Those clever folks at Mozilla know how bothersome it is to create a base XULRunner application (for the curious among you, have a look at the [https://developer.mozilla.org/en/Getting_started_with_XULRunner official tutorial, steps 3 - 7]). And so they created a project called [https://wiki.mozilla.org/FizzyPop FizzyPop] which will create all that fun boilerplate stuff for you; just give your project a name, maybe a version number, give it your name as the author, select a few options ... and BAM! Instant XULRunner Application: Just Add Water (tm).&lt;br /&gt;
&lt;br /&gt;
So here we go! To use this magical &amp;quot;FizzyPop&amp;quot; thing, just point your web browser to it! There are currently two different resources available for it (to my knowledge). The latter has been tagged a &amp;quot;prototype&amp;quot; so it might not be the one you want to use. But don't quote me on that! Without further ado, just go there:&lt;br /&gt;
&lt;br /&gt;
* [http://www.mozdev.org/projects/wizard/ Mozilla Project Wizard] ... OR ...&lt;br /&gt;
* [http://starkravingfinkle.org/projects/fizzypop/ FizzyPop prototype]&lt;br /&gt;
&lt;br /&gt;
Choose the &amp;quot;Application&amp;quot; Start link. Now there are just a couple of [very, very simple] steps to follow, and you'll be on your way:&lt;br /&gt;
&lt;br /&gt;
# Give your project a name. I chose &amp;quot;Hello World&amp;quot;.&lt;br /&gt;
# And an ID. The ID is in the form of an email address, which seems odd at first, but makes sense in the proper context ([[#Project ID]]). I chose &amp;quot;helloworld@kodewerx.org&amp;quot; for mine. If you don't have a domain, you can just use your own name in place of one.&lt;br /&gt;
# A short &amp;quot;package name&amp;quot; as well; for mine, &amp;quot;helloworld&amp;quot;.&lt;br /&gt;
# You can leave the version number and build ID at their default values (note that the &amp;quot;prototype&amp;quot; does not give you any default values) ... or go ahead and punch in some different numbers. It won't matter much.&lt;br /&gt;
# It also requires some author information (that's you!) Enter your name here.&lt;br /&gt;
# Set the Platform Details minimum and maximum version numbers according to the XULRunner runtime version you're using. In my case, minimum is set to &amp;quot;1.9.2.0&amp;quot; and maximum is &amp;quot;1.9.2.*&amp;quot;.&lt;br /&gt;
# You may leave the other entries blank, or configure them to your liking.&lt;br /&gt;
# Click the final &amp;quot;Create&amp;quot; button, and it will start to download a zip archive containing all of the necessary files and directory structures for a basic XULRunner application.&lt;br /&gt;
# Extract the zip file somewhere on your local drive. A &amp;quot;projects&amp;quot; folder for example.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is write some XUL to make it look like a program, and some JavaScript to make it do something! Or, you could always run the base application, just to see if your XULRunner setup works. This isn't a bad idea, after all.&lt;br /&gt;
&lt;br /&gt;
====Testing and Installation====&lt;br /&gt;
&lt;br /&gt;
=====On Mac OS X=====&lt;br /&gt;
&lt;br /&gt;
To test your application boilerplate, run XULRunner from the command line, passing the path to the &amp;quot;application.ini&amp;quot; as an argument. For example, on Mac OS X, I run this from the Terminal:&lt;br /&gt;
&lt;br /&gt;
 /Library/Frameworks/XUL.framework/xulrunner-bin /Users/parasyte/Desktop/helloworld-app-project/application.ini&lt;br /&gt;
&lt;br /&gt;
Note: XULRunner on OS X requires the full path to the application.ini file&lt;br /&gt;
&lt;br /&gt;
After making sure it works (you should be given a blank window) you can install the application to make it act more like a real app. (For example, installation will give it a Dock icon, menu bar, etc.) To install on OS X:&lt;br /&gt;
&lt;br /&gt;
 /Library/Frameworks/XUL.framework/xulrunner-bin --install-app /Users/parasyte/Desktop/helloworld-app-project&lt;br /&gt;
&lt;br /&gt;
Note: Don't include the &amp;quot;/application.ini&amp;quot; when installing the app!&lt;br /&gt;
&lt;br /&gt;
With the application installed, you can find it in your /Applications/ directory. If you set a &amp;quot;Vendor&amp;quot; when you created the boilerplate, then it will be put into /Applications/vendor-name/&lt;br /&gt;
&lt;br /&gt;
=====On Windows=====&lt;br /&gt;
&lt;br /&gt;
From the &amp;quot;Run&amp;quot; window (Start -&amp;gt; Run...) use the following command:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;%PROGRAMFILES%\XULRunner\xulrunner.exe&amp;quot; &amp;quot;path\to\application.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Where &amp;quot;path\to\application.ini&amp;quot; is the actual path the the actual application.ini file. If it works, you will get a blank window. You can then install the application with the following:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;%PROGRAMFILES%\XULRunner\xulrunner.exe&amp;quot; --install-app &amp;quot;path\to\application&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Where &amp;quot;path\to\application&amp;quot; is the path to the application's top-level directory; NOT the application.ini file. This will install the application to &amp;quot;%PROGRAMFILES%\application-name\&amp;quot;, or if you set the &amp;quot;Vendor&amp;quot; field when you created the boilerplate, in &amp;quot;%PROGRAMFILES%\vendor-name\application-name\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=====On Ubuntu Linux=====&lt;br /&gt;
&lt;br /&gt;
In a terminal:&lt;br /&gt;
&lt;br /&gt;
 /path/to/xulrunner-bin &amp;quot;/path/to/application.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A blank window appearing means all worked well. To install:&lt;br /&gt;
&lt;br /&gt;
 /path/to/xulrunner-bin --install-app &amp;quot;/path/to/application&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Note: Do not point the installer to the application.ini file; point it instead to the application's top-level directory.&lt;br /&gt;
&lt;br /&gt;
====Project ID====&lt;br /&gt;
&lt;br /&gt;
The XULRunner Project ID is a unique identifier, which allows certain features of XULRunner to work properly. I can't exactly name any specific use for it off-hand, but I believe it can be used by extensions to access specific data local to your application.&lt;br /&gt;
&lt;br /&gt;
===Hello World===&lt;br /&gt;
&lt;br /&gt;
To complete the first step towards world domination with XULRunner, you'll want to make the application do something (or at least, ''say'' something) ...&lt;br /&gt;
&lt;br /&gt;
Open the file /chrome/content/main.xul in your application directory. You will be greeted with a lot of XML. This is the file that defines the complete GUI for your application's main window. You can add any XUL elements to this file to create any kind of widget in your main window. For starters, just add a simple label element before the &amp;lt;/vbox&amp;gt; tag, near the end of the file. Something like this:&lt;br /&gt;
&lt;br /&gt;
   &amp;lt;hbox id=&amp;quot;main_box&amp;quot; flex=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;lt;vbox id=&amp;quot;workspace_box&amp;quot; flex=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;&amp;lt;label value=&amp;quot;Hello, World!&amp;quot;/&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
     &amp;lt;/vbox&amp;gt;&lt;br /&gt;
   &amp;lt;/hbox&amp;gt;&lt;br /&gt;
 &amp;lt;/window&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the app to see your changes. Reinstall it, if you like. When reinstalling, it is a good idea to first delete the old already-installed application, but this is not always necessary.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
Now that you have a Hello World XULRunner app, you can continue exploring the rest of what XULRunner has to offer. This means XUL and JavaScript... The following sections provide some helpful resources (API references, tutorials, etc.) which will get your on your way. Since you are up and running with a minimal application, it won't take much longer until you have a killer-app of your very own!&lt;br /&gt;
&lt;br /&gt;
===Developer Resources===&lt;br /&gt;
&lt;br /&gt;
This is a list of websites relevant to XULRunner and creating applications for it. While this list is produced entirely without any specific order, I've attempted to keep the most important of these near the top.&lt;br /&gt;
&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_Tutorial Mozilla Developer Central: XUL Tutorial] (Slightly old, but still one of the best sources of information on XUL.)&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL Mozilla Developer Central: XUL Information] (Specifically, the complete [https://developer.mozilla.org/en/XUL_Reference XUL Reference].)&lt;br /&gt;
* [https://developer.mozilla.org/en/XULRunner Mozilla Developer Central: XULRunner Information]&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_School Mozilla Developer Central: XUL School] (Targets Firefox Extension developers, but contains XUL tutorial)&lt;br /&gt;
* [http://www.xul.fr/tutorial/ XUL.fr Tutorial]&lt;br /&gt;
* [http://books.mozdev.org/chapters/index.html Creating Applications With Mozilla] (Online book.)&lt;br /&gt;
* [http://mb.eschew.org/ Rapid Application Development With Mozilla] (Online book.)&lt;br /&gt;
* [https://developer.mozilla.org/en/Creating_XPCOM_Components Creating XPCOM Components] (Online book.)&lt;br /&gt;
* [http://www.oxymoronical.com/experiments/xpcomref/ Mozilla XPCOM Reference] (All interfaces and components; always kept up-to-date.)&lt;br /&gt;
* [https://addons.mozilla.org/en-US/developers Mozilla Add-on Developer Hub] (Mostly related to Firefox add-on development; but useful for XULRunner, too.)&lt;br /&gt;
* [http://parasyte.kodewerx.org/projects/xulrunner/x-xulintro-pdf.pdf IBM developerWorks: An introduction to XML User Interface Language (XUL) development] (PDF, mirrored here because IBM requires compulsory registration to download this from their website. Original location: http://www.ibm.com/developerworks/edu/x-dw-x-xulintro.html)&lt;br /&gt;
* [http://kb.mozillazine.org/Development_resources MozillaZine: Development Resources] (Semi-outdated.)&lt;br /&gt;
* [http://xml.coverpages.org/xul.html Cover Pages: Extensible User Interface Language (XUL)] (Extremely outdated, but historically relevant.)&lt;br /&gt;
&lt;br /&gt;
====XUL Editors and Designers====&lt;br /&gt;
&lt;br /&gt;
I've found these applications helpful, while learning XUL.&lt;br /&gt;
&lt;br /&gt;
* [http://ted.mielczarek.org/code/mozilla/xuledit/xuledit.xul Ted Mielczarek's Real-Time XUL Editor] (Great for quickly testing XUL from directly within Firefox.)&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_Explorer XUL Explorer] (Similar to the Real-Time XUL Editor above, but as a XULRunner application.)&lt;br /&gt;
* [http://kukuru.s7.xrea.com/xulpix/ XULPIX] (A ''great'' XUL editor; the closest thing to a form designer that we currently have ... without Eclipse! Yucky...)&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;br /&gt;
&lt;br /&gt;
===Packaging===&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Packaging&amp;quot; is the process of creating an installer for your application. So far as I know, you have two choices here:&lt;br /&gt;
&lt;br /&gt;
# Create a self-contained installer, which includes its own private copy of the XULRunner runtime.&lt;br /&gt;
# Create an XPI; an archive that can be installed as a XULRunner application by a pre-existing XULRunner runtime.&lt;br /&gt;
&lt;br /&gt;
The latter option requires that your users install the XULRunner runtime (just like you did at the beginning of this introduction). The former option just requires that the user download the installer and install it. This option has the disadvantage that the file the user must download is a *LOT* larger than just the simple XPI. About 9MB for Windows and Linux, or 17MB for Mac OS X; compared to just a few KB (typically 10KB for a small app, like our Hello World) for the XPI!&lt;br /&gt;
&lt;br /&gt;
I haven't yet investigated XULRunner application packaging. This section is in need of completion.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=A_Brief_Introduction_To_XULRunner:_Part_2&amp;diff=997</id>
		<title>A Brief Introduction To XULRunner: Part 2</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=A_Brief_Introduction_To_XULRunner:_Part_2&amp;diff=997"/>
				<updated>2010-04-14T00:09:43Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Hello World */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Now that you are familiar with what XULRunner ''is'', let's explore ''how'' to use it. More generally, let's explore how to use Mozilla tools that were designed to make building XULRunner applications easier.&lt;br /&gt;
&lt;br /&gt;
==How to Use XULRunner==&lt;br /&gt;
&lt;br /&gt;
===Setting Up a XULRunner Development Environment===&lt;br /&gt;
&lt;br /&gt;
Setting up your XULRunner development environment is very easy. You need just a few programs to get started:&lt;br /&gt;
&lt;br /&gt;
* A text editor of your choosing. If you don't have one with XML/XUL/JavaScript/CSS syntax highlighting, you might want to check out one of the many [http://www.scintilla.org/ Scintilla]-based editors: [http://www.geany.org Geany] is excellent for Linux (GTK+) users, and decent on Windows ([http://www.scintilla.org/SciTE.html SciTE] is similar); [http://www.activestate.com/komodo_edit/ Komodo Edit] is excellent on any XULRunner-supported platform (Hooray for XULRunner!); and there are [http://www.scintilla.org/ScintillaRelated.html many others] to choose from.&lt;br /&gt;
* The XULRunner Runtime itself. Download the latest stable version from Mozilla: http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ (Note: Go into the most recent sub-directory and then the &amp;quot;runtimes&amp;quot; sub-directory. You don't need the SDK.)&lt;br /&gt;
&lt;br /&gt;
After installing the XULRunner runtime and text editor of your choice, you can begin creating a new project template.&lt;br /&gt;
&lt;br /&gt;
===Creating a XULRunner Application Template===&lt;br /&gt;
&lt;br /&gt;
Developers familiar with C and C++ know that all C/C++ applications must have a function called main(). Or in Win32 development, things are even more convoluted; a WinMain() function is required, along with a message pump and some other nonsense. Similarly, all XULRunner applications have a series of requirements (functional and structural) to &amp;quot;bootstrap&amp;quot; the application.&lt;br /&gt;
&lt;br /&gt;
Often, this task of creating a new project is tedious, mundane, and repetitive (to name just a few adjectives). This is why most C/C++ developers just copy startup (and maybe other) code from an existing project when creating a whole new one. That takes care of the bootstrapping process, without having to remember everything required to get up and running. This can certainly be done with new XULRunner applications, if you like. But there is an easier way...&lt;br /&gt;
&lt;br /&gt;
====FizzyPop, Or &amp;quot;How I Made My XULRunner Application&amp;quot;====&lt;br /&gt;
&lt;br /&gt;
Those clever folks at Mozilla know how bothersome it is to create a base XULRunner application (for the curious among you, have a look at the [https://developer.mozilla.org/en/Getting_started_with_XULRunner official tutorial, steps 3 - 7]). And so they created a project called [https://wiki.mozilla.org/FizzyPop FizzyPop] which will create all that fun boilerplate stuff for you; just give your project a name, maybe a version number, give it your name as the author, select a few options ... and BAM! Instant XULRunner Application: Just Add Water (tm).&lt;br /&gt;
&lt;br /&gt;
So here we go! To use this magical &amp;quot;FizzyPop&amp;quot; thing, just point your web browser to it! There are currently two different resources available for it (to my knowledge). The latter has been tagged a &amp;quot;prototype&amp;quot; so it might not be the one you want to use. But don't quote me on that! Without further ado, just go there:&lt;br /&gt;
&lt;br /&gt;
* [http://www.mozdev.org/projects/wizard/ Mozilla Project Wizard] ... OR ...&lt;br /&gt;
* [http://starkravingfinkle.org/projects/fizzypop/ FizzyPop prototype]&lt;br /&gt;
&lt;br /&gt;
Choose the &amp;quot;Application&amp;quot; Start link. Now there are just a couple of [very, very simple] steps to follow, and you'll be on your way:&lt;br /&gt;
&lt;br /&gt;
# Give your project a name. I chose &amp;quot;Hello World&amp;quot;.&lt;br /&gt;
# And an ID. The ID is in the form of an email address, which seems odd at first, but makes sense in the proper context ([[#Project ID]]). I chose &amp;quot;helloworld@kodewerx.org&amp;quot; for mine. If you don't have a domain, you can just use your own name in place of one.&lt;br /&gt;
# A short &amp;quot;package name&amp;quot; as well; for mine, &amp;quot;helloworld&amp;quot;.&lt;br /&gt;
# You can leave the version number and build ID at their default values (note that the &amp;quot;prototype&amp;quot; does not give you any default values) ... or go ahead and punch in some different numbers. It won't matter much.&lt;br /&gt;
# It also requires some author information (that's you!) Enter your name here.&lt;br /&gt;
# Set the Platform Details minimum and maximum version numbers according to the XULRunner runtime version you're using. In my case, minimum is set to &amp;quot;1.9.2.0&amp;quot; and maximum is &amp;quot;1.9.2.*&amp;quot;.&lt;br /&gt;
# You may leave the other entries blank, or configure them to your liking.&lt;br /&gt;
# Click the final &amp;quot;Create&amp;quot; button, and it will start to download a zip archive containing all of the necessary files and directory structures for a basic XULRunner application.&lt;br /&gt;
# Extract the zip file somewhere on your local drive. A &amp;quot;projects&amp;quot; folder for example.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is write some XUL to make it look like a program, and some JavaScript to make it do something! Or, you could always run the base application, just to see if your XULRunner setup works. This isn't a bad idea, after all.&lt;br /&gt;
&lt;br /&gt;
====Testing and Installation====&lt;br /&gt;
&lt;br /&gt;
=====On Mac OS X=====&lt;br /&gt;
&lt;br /&gt;
To test your application boilerplate, run XULRunner from the command line, passing the path to the &amp;quot;application.ini&amp;quot; as an argument. For example, on Mac OS X, I run this from the Terminal:&lt;br /&gt;
&lt;br /&gt;
 /Library/Frameworks/XUL.framework/xulrunner-bin /Users/parasyte/Desktop/helloworld-app-project/application.ini&lt;br /&gt;
&lt;br /&gt;
Note: XULRunner on OS X requires the full path to the application.ini file&lt;br /&gt;
&lt;br /&gt;
After making sure it works (you should be given a blank window) you can install the application to make it act more like a real app. (For example, installation will give it a Dock icon, menu bar, etc.) To install on OS X:&lt;br /&gt;
&lt;br /&gt;
 /Library/Frameworks/XUL.framework/xulrunner-bin --install-app /Users/parasyte/Desktop/helloworld-app-project&lt;br /&gt;
&lt;br /&gt;
Note: Don't include the &amp;quot;/application.ini&amp;quot; when installing the app!&lt;br /&gt;
&lt;br /&gt;
With the application installed, you can find it in your /Applications/ directory. If you set a &amp;quot;Vendor&amp;quot; when you created the boilerplate, then it will be put into /Applications/vendor-name/&lt;br /&gt;
&lt;br /&gt;
=====On Windows=====&lt;br /&gt;
&lt;br /&gt;
From the &amp;quot;Run&amp;quot; window (Start -&amp;gt; Run...) use the following command:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;%PROGRAMFILES%\XULRunner\xulrunner.exe&amp;quot; &amp;quot;path\to\application.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Where &amp;quot;path\to\application.ini&amp;quot; is the actual path the the actual application.ini file. If it works, you will get a blank window. You can then install the application with the following:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;%PROGRAMFILES%\XULRunner\xulrunner.exe&amp;quot; --install-app &amp;quot;path\to\application&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Where &amp;quot;path\to\application&amp;quot; is the path to the application's top-level directory; NOT the application.ini file. This will install the application to &amp;quot;%PROGRAMFILES%\application-name\&amp;quot;, or if you set the &amp;quot;Vendor&amp;quot; field when you created the boilerplate, in &amp;quot;%PROGRAMFILES%\vendor-name\application-name\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=====On Ubuntu Linux=====&lt;br /&gt;
&lt;br /&gt;
In a terminal:&lt;br /&gt;
&lt;br /&gt;
 /path/to/xulrunner-bin &amp;quot;/path/to/application.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A blank window appearing means all worked well. To install:&lt;br /&gt;
&lt;br /&gt;
 /path/to/xulrunner-bin --install-app &amp;quot;/path/to/application&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Note: Do not point the installer to the application.ini file; point it instead to the application's top-level directory.&lt;br /&gt;
&lt;br /&gt;
====Project ID====&lt;br /&gt;
&lt;br /&gt;
The XULRunner Project ID is a unique identifier, which allows certain features of XULRunner to work properly. I can't exactly name any specific use for it off-hand, but I believe it can be used by extensions to access specific data local to your application.&lt;br /&gt;
&lt;br /&gt;
===Hello World===&lt;br /&gt;
&lt;br /&gt;
To complete the first step towards world domination with XULRunner, you'll want to make the application do something (or at least, ''say'' something) ...&lt;br /&gt;
&lt;br /&gt;
Open the file /chrome/content/main.xul in your application directory. You will be greeted with a lot of XML. This is the file that defines the complete GUI for your application's main window. You can add any XUL elements to this file to create any kind of widget in your main window. For starters, just add a simple label element before the &amp;lt;/vbox&amp;gt; tag, near the end of the file. Something like this:&lt;br /&gt;
&lt;br /&gt;
   &amp;lt;hbox id=&amp;quot;main_box&amp;quot; flex=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;lt;vbox id=&amp;quot;workspace_box&amp;quot; flex=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;span style=&amp;quot;color:green;&amp;quot;&amp;gt;&amp;lt;label value=&amp;quot;Hello, World!&amp;quot;/&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
     &amp;lt;/vbox&amp;gt;&lt;br /&gt;
   &amp;lt;/hbox&amp;gt;&lt;br /&gt;
 &amp;lt;/window&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the app to see your changes. Reinstall it, if you like. When reinstalling, it is a good idea to first delete the old already-installed application, but this is not always necessary.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
Now that you have a Hello World XULRunner app, you can continue exploring the rest of what XULRunner has to offer. This means XUL and JavaScript... The following sections provide some helpful resources (API references, tutorials, etc.) which will get your on your way. Since you are up and running with a minimal application, it won't take much longer until you have a killer-app of your very own!&lt;br /&gt;
&lt;br /&gt;
===Developer Resources===&lt;br /&gt;
&lt;br /&gt;
This is a list of websites relevant to XULRunner and creating applications for it. While this list is produced entirely without any specific order, I've attempted to keep the most important of these near the top.&lt;br /&gt;
&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_Tutorial Mozilla Developer Central: XUL Tutorial] (Slightly old, but still one of the best sources of information on XUL.)&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL Mozilla Developer Central: XUL Information] (Specifically, the complete [https://developer.mozilla.org/en/XUL_Reference XUL Reference].)&lt;br /&gt;
* [https://developer.mozilla.org/en/XULRunner Mozilla Developer Central: XULRunner Information]&lt;br /&gt;
* [http://www.xul.fr/tutorial/ XUL.fr Tutorial]&lt;br /&gt;
* [http://books.mozdev.org/chapters/index.html Creating Applications With Mozilla] (Online book.)&lt;br /&gt;
* [http://mb.eschew.org/ Rapid Application Development With Mozilla] (Online book.)&lt;br /&gt;
* [https://developer.mozilla.org/en/Creating_XPCOM_Components Creating XPCOM Components] (Online book.)&lt;br /&gt;
* [http://www.oxymoronical.com/experiments/xpcomref/ Mozilla XPCOM Reference] (All interfaces and components; always kept up-to-date.)&lt;br /&gt;
* [https://addons.mozilla.org/en-US/developers Mozilla Add-on Developer Hub] (Mostly related to Firefox add-on development; but useful for XULRunner, too.)&lt;br /&gt;
* [http://parasyte.kodewerx.org/projects/xulrunner/x-xulintro-pdf.pdf IBM developerWorks: An introduction to XML User Interface Language (XUL) development] (PDF, mirrored here because IBM requires compulsory registration to download this from their website. Original location: http://www.ibm.com/developerworks/edu/x-dw-x-xulintro.html)&lt;br /&gt;
* [http://kb.mozillazine.org/Development_resources MozillaZine: Development Resources] (Semi-outdated.)&lt;br /&gt;
* [http://xml.coverpages.org/xul.html Cover Pages: Extensible User Interface Language (XUL)] (Extremely outdated, but historically relevant.)&lt;br /&gt;
&lt;br /&gt;
====XUL Editors and Designers====&lt;br /&gt;
&lt;br /&gt;
I've found these applications helpful, while learning XUL.&lt;br /&gt;
&lt;br /&gt;
* [http://ted.mielczarek.org/code/mozilla/xuledit/xuledit.xul Ted Mielczarek's Real-Time XUL Editor] (Great for quickly testing XUL from directly within Firefox.)&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_Explorer XUL Explorer] (Similar to the Real-Time XUL Editor above, but as a XULRunner application.)&lt;br /&gt;
* [http://kukuru.s7.xrea.com/xulpix/ XULPIX] (A ''great'' XUL editor; the closest thing to a form designer that we currently have ... without Eclipse! Yucky...)&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;br /&gt;
&lt;br /&gt;
===Packaging===&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Packaging&amp;quot; is the process of creating an installer for your application. So far as I know, you have two choices here:&lt;br /&gt;
&lt;br /&gt;
# Create a self-contained installer, which includes its own private copy of the XULRunner runtime.&lt;br /&gt;
# Create an XPI; an archive that can be installed as a XULRunner application by a pre-existing XULRunner runtime.&lt;br /&gt;
&lt;br /&gt;
The latter option requires that your users install the XULRunner runtime (just like you did at the beginning of this introduction). The former option just requires that the user download the installer and install it. This option has the disadvantage that the file the user must download is a *LOT* larger than just the simple XPI. About 9MB for Windows and Linux, or 17MB for Mac OS X; compared to just a few KB (typically 10KB for a small app, like our Hello World) for the XPI!&lt;br /&gt;
&lt;br /&gt;
I haven't yet investigated XULRunner application packaging. This section is in need of completion.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=A_Brief_Introduction_To_XULRunner:_Part_2&amp;diff=996</id>
		<title>A Brief Introduction To XULRunner: Part 2</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=A_Brief_Introduction_To_XULRunner:_Part_2&amp;diff=996"/>
				<updated>2010-04-14T00:06:39Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* FizzyPop, Or &amp;quot;How I Made My XULRunner Application&amp;quot; */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Now that you are familiar with what XULRunner ''is'', let's explore ''how'' to use it. More generally, let's explore how to use Mozilla tools that were designed to make building XULRunner applications easier.&lt;br /&gt;
&lt;br /&gt;
==How to Use XULRunner==&lt;br /&gt;
&lt;br /&gt;
===Setting Up a XULRunner Development Environment===&lt;br /&gt;
&lt;br /&gt;
Setting up your XULRunner development environment is very easy. You need just a few programs to get started:&lt;br /&gt;
&lt;br /&gt;
* A text editor of your choosing. If you don't have one with XML/XUL/JavaScript/CSS syntax highlighting, you might want to check out one of the many [http://www.scintilla.org/ Scintilla]-based editors: [http://www.geany.org Geany] is excellent for Linux (GTK+) users, and decent on Windows ([http://www.scintilla.org/SciTE.html SciTE] is similar); [http://www.activestate.com/komodo_edit/ Komodo Edit] is excellent on any XULRunner-supported platform (Hooray for XULRunner!); and there are [http://www.scintilla.org/ScintillaRelated.html many others] to choose from.&lt;br /&gt;
* The XULRunner Runtime itself. Download the latest stable version from Mozilla: http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ (Note: Go into the most recent sub-directory and then the &amp;quot;runtimes&amp;quot; sub-directory. You don't need the SDK.)&lt;br /&gt;
&lt;br /&gt;
After installing the XULRunner runtime and text editor of your choice, you can begin creating a new project template.&lt;br /&gt;
&lt;br /&gt;
===Creating a XULRunner Application Template===&lt;br /&gt;
&lt;br /&gt;
Developers familiar with C and C++ know that all C/C++ applications must have a function called main(). Or in Win32 development, things are even more convoluted; a WinMain() function is required, along with a message pump and some other nonsense. Similarly, all XULRunner applications have a series of requirements (functional and structural) to &amp;quot;bootstrap&amp;quot; the application.&lt;br /&gt;
&lt;br /&gt;
Often, this task of creating a new project is tedious, mundane, and repetitive (to name just a few adjectives). This is why most C/C++ developers just copy startup (and maybe other) code from an existing project when creating a whole new one. That takes care of the bootstrapping process, without having to remember everything required to get up and running. This can certainly be done with new XULRunner applications, if you like. But there is an easier way...&lt;br /&gt;
&lt;br /&gt;
====FizzyPop, Or &amp;quot;How I Made My XULRunner Application&amp;quot;====&lt;br /&gt;
&lt;br /&gt;
Those clever folks at Mozilla know how bothersome it is to create a base XULRunner application (for the curious among you, have a look at the [https://developer.mozilla.org/en/Getting_started_with_XULRunner official tutorial, steps 3 - 7]). And so they created a project called [https://wiki.mozilla.org/FizzyPop FizzyPop] which will create all that fun boilerplate stuff for you; just give your project a name, maybe a version number, give it your name as the author, select a few options ... and BAM! Instant XULRunner Application: Just Add Water (tm).&lt;br /&gt;
&lt;br /&gt;
So here we go! To use this magical &amp;quot;FizzyPop&amp;quot; thing, just point your web browser to it! There are currently two different resources available for it (to my knowledge). The latter has been tagged a &amp;quot;prototype&amp;quot; so it might not be the one you want to use. But don't quote me on that! Without further ado, just go there:&lt;br /&gt;
&lt;br /&gt;
* [http://www.mozdev.org/projects/wizard/ Mozilla Project Wizard] ... OR ...&lt;br /&gt;
* [http://starkravingfinkle.org/projects/fizzypop/ FizzyPop prototype]&lt;br /&gt;
&lt;br /&gt;
Choose the &amp;quot;Application&amp;quot; Start link. Now there are just a couple of [very, very simple] steps to follow, and you'll be on your way:&lt;br /&gt;
&lt;br /&gt;
# Give your project a name. I chose &amp;quot;Hello World&amp;quot;.&lt;br /&gt;
# And an ID. The ID is in the form of an email address, which seems odd at first, but makes sense in the proper context ([[#Project ID]]). I chose &amp;quot;helloworld@kodewerx.org&amp;quot; for mine. If you don't have a domain, you can just use your own name in place of one.&lt;br /&gt;
# A short &amp;quot;package name&amp;quot; as well; for mine, &amp;quot;helloworld&amp;quot;.&lt;br /&gt;
# You can leave the version number and build ID at their default values (note that the &amp;quot;prototype&amp;quot; does not give you any default values) ... or go ahead and punch in some different numbers. It won't matter much.&lt;br /&gt;
# It also requires some author information (that's you!) Enter your name here.&lt;br /&gt;
# Set the Platform Details minimum and maximum version numbers according to the XULRunner runtime version you're using. In my case, minimum is set to &amp;quot;1.9.2.0&amp;quot; and maximum is &amp;quot;1.9.2.*&amp;quot;.&lt;br /&gt;
# You may leave the other entries blank, or configure them to your liking.&lt;br /&gt;
# Click the final &amp;quot;Create&amp;quot; button, and it will start to download a zip archive containing all of the necessary files and directory structures for a basic XULRunner application.&lt;br /&gt;
# Extract the zip file somewhere on your local drive. A &amp;quot;projects&amp;quot; folder for example.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is write some XUL to make it look like a program, and some JavaScript to make it do something! Or, you could always run the base application, just to see if your XULRunner setup works. This isn't a bad idea, after all.&lt;br /&gt;
&lt;br /&gt;
====Testing and Installation====&lt;br /&gt;
&lt;br /&gt;
=====On Mac OS X=====&lt;br /&gt;
&lt;br /&gt;
To test your application boilerplate, run XULRunner from the command line, passing the path to the &amp;quot;application.ini&amp;quot; as an argument. For example, on Mac OS X, I run this from the Terminal:&lt;br /&gt;
&lt;br /&gt;
 /Library/Frameworks/XUL.framework/xulrunner-bin /Users/parasyte/Desktop/helloworld-app-project/application.ini&lt;br /&gt;
&lt;br /&gt;
Note: XULRunner on OS X requires the full path to the application.ini file&lt;br /&gt;
&lt;br /&gt;
After making sure it works (you should be given a blank window) you can install the application to make it act more like a real app. (For example, installation will give it a Dock icon, menu bar, etc.) To install on OS X:&lt;br /&gt;
&lt;br /&gt;
 /Library/Frameworks/XUL.framework/xulrunner-bin --install-app /Users/parasyte/Desktop/helloworld-app-project&lt;br /&gt;
&lt;br /&gt;
Note: Don't include the &amp;quot;/application.ini&amp;quot; when installing the app!&lt;br /&gt;
&lt;br /&gt;
With the application installed, you can find it in your /Applications/ directory. If you set a &amp;quot;Vendor&amp;quot; when you created the boilerplate, then it will be put into /Applications/vendor-name/&lt;br /&gt;
&lt;br /&gt;
=====On Windows=====&lt;br /&gt;
&lt;br /&gt;
From the &amp;quot;Run&amp;quot; window (Start -&amp;gt; Run...) use the following command:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;%PROGRAMFILES%\XULRunner\xulrunner.exe&amp;quot; &amp;quot;path\to\application.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Where &amp;quot;path\to\application.ini&amp;quot; is the actual path the the actual application.ini file. If it works, you will get a blank window. You can then install the application with the following:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;%PROGRAMFILES%\XULRunner\xulrunner.exe&amp;quot; --install-app &amp;quot;path\to\application&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Where &amp;quot;path\to\application&amp;quot; is the path to the application's top-level directory; NOT the application.ini file. This will install the application to &amp;quot;%PROGRAMFILES%\application-name\&amp;quot;, or if you set the &amp;quot;Vendor&amp;quot; field when you created the boilerplate, in &amp;quot;%PROGRAMFILES%\vendor-name\application-name\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=====On Ubuntu Linux=====&lt;br /&gt;
&lt;br /&gt;
In a terminal:&lt;br /&gt;
&lt;br /&gt;
 /path/to/xulrunner-bin &amp;quot;/path/to/application.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A blank window appearing means all worked well. To install:&lt;br /&gt;
&lt;br /&gt;
 /path/to/xulrunner-bin --install-app &amp;quot;/path/to/application&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Note: Do not point the installer to the application.ini file; point it instead to the application's top-level directory.&lt;br /&gt;
&lt;br /&gt;
====Project ID====&lt;br /&gt;
&lt;br /&gt;
The XULRunner Project ID is a unique identifier, which allows certain features of XULRunner to work properly. I can't exactly name any specific use for it off-hand, but I believe it can be used by extensions to access specific data local to your application.&lt;br /&gt;
&lt;br /&gt;
===Hello World===&lt;br /&gt;
&lt;br /&gt;
To complete the first step towards world domination with XULRunner, you'll want to make the application do something (or at least, ''say'' something) ...&lt;br /&gt;
&lt;br /&gt;
Open the file /chrome/content/main.xul in your application directory. You will be greeted with a lot of XML. This is the file that defines the complete GUI for your application's main window. You can add any XUL elements to this file to create any kind of widget in your main window. For starters, just add a simple label element before the &amp;lt;/vbox&amp;gt; tag, near the end of the file. Something like this:&lt;br /&gt;
&lt;br /&gt;
   &amp;lt;hbox id=&amp;quot;main_box&amp;quot; flex=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;lt;vbox id=&amp;quot;workspace_box&amp;quot; flex=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
      '''''&amp;lt;label value=&amp;quot;Hello, World!&amp;quot;/&amp;gt;'''''&lt;br /&gt;
     &amp;lt;/vbox&amp;gt;&lt;br /&gt;
   &amp;lt;/hbox&amp;gt;&lt;br /&gt;
 &amp;lt;/window&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the app to see your changes. Reinstall it, if you like. When reinstalling, it is a good idea to first delete the old already-installed application, but this is not always necessary.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
Now that you have a Hello World XULRunner app, you can continue exploring the rest of what XULRunner has to offer. This means XUL and JavaScript... The following sections provide some helpful resources (API references, tutorials, etc.) which will get your on your way. Since you are up and running with a minimal application, it won't take much longer until you have a killer-app of your very own!&lt;br /&gt;
&lt;br /&gt;
===Developer Resources===&lt;br /&gt;
&lt;br /&gt;
This is a list of websites relevant to XULRunner and creating applications for it. While this list is produced entirely without any specific order, I've attempted to keep the most important of these near the top.&lt;br /&gt;
&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_Tutorial Mozilla Developer Central: XUL Tutorial] (Slightly old, but still one of the best sources of information on XUL.)&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL Mozilla Developer Central: XUL Information] (Specifically, the complete [https://developer.mozilla.org/en/XUL_Reference XUL Reference].)&lt;br /&gt;
* [https://developer.mozilla.org/en/XULRunner Mozilla Developer Central: XULRunner Information]&lt;br /&gt;
* [http://www.xul.fr/tutorial/ XUL.fr Tutorial]&lt;br /&gt;
* [http://books.mozdev.org/chapters/index.html Creating Applications With Mozilla] (Online book.)&lt;br /&gt;
* [http://mb.eschew.org/ Rapid Application Development With Mozilla] (Online book.)&lt;br /&gt;
* [https://developer.mozilla.org/en/Creating_XPCOM_Components Creating XPCOM Components] (Online book.)&lt;br /&gt;
* [http://www.oxymoronical.com/experiments/xpcomref/ Mozilla XPCOM Reference] (All interfaces and components; always kept up-to-date.)&lt;br /&gt;
* [https://addons.mozilla.org/en-US/developers Mozilla Add-on Developer Hub] (Mostly related to Firefox add-on development; but useful for XULRunner, too.)&lt;br /&gt;
* [http://parasyte.kodewerx.org/projects/xulrunner/x-xulintro-pdf.pdf IBM developerWorks: An introduction to XML User Interface Language (XUL) development] (PDF, mirrored here because IBM requires compulsory registration to download this from their website. Original location: http://www.ibm.com/developerworks/edu/x-dw-x-xulintro.html)&lt;br /&gt;
* [http://kb.mozillazine.org/Development_resources MozillaZine: Development Resources] (Semi-outdated.)&lt;br /&gt;
* [http://xml.coverpages.org/xul.html Cover Pages: Extensible User Interface Language (XUL)] (Extremely outdated, but historically relevant.)&lt;br /&gt;
&lt;br /&gt;
====XUL Editors and Designers====&lt;br /&gt;
&lt;br /&gt;
I've found these applications helpful, while learning XUL.&lt;br /&gt;
&lt;br /&gt;
* [http://ted.mielczarek.org/code/mozilla/xuledit/xuledit.xul Ted Mielczarek's Real-Time XUL Editor] (Great for quickly testing XUL from directly within Firefox.)&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_Explorer XUL Explorer] (Similar to the Real-Time XUL Editor above, but as a XULRunner application.)&lt;br /&gt;
* [http://kukuru.s7.xrea.com/xulpix/ XULPIX] (A ''great'' XUL editor; the closest thing to a form designer that we currently have ... without Eclipse! Yucky...)&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;br /&gt;
&lt;br /&gt;
===Packaging===&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Packaging&amp;quot; is the process of creating an installer for your application. So far as I know, you have two choices here:&lt;br /&gt;
&lt;br /&gt;
# Create a self-contained installer, which includes its own private copy of the XULRunner runtime.&lt;br /&gt;
# Create an XPI; an archive that can be installed as a XULRunner application by a pre-existing XULRunner runtime.&lt;br /&gt;
&lt;br /&gt;
The latter option requires that your users install the XULRunner runtime (just like you did at the beginning of this introduction). The former option just requires that the user download the installer and install it. This option has the disadvantage that the file the user must download is a *LOT* larger than just the simple XPI. About 9MB for Windows and Linux, or 17MB for Mac OS X; compared to just a few KB (typically 10KB for a small app, like our Hello World) for the XPI!&lt;br /&gt;
&lt;br /&gt;
I haven't yet investigated XULRunner application packaging. This section is in need of completion.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=A_Brief_Introduction_To_XULRunner:_Part_2&amp;diff=995</id>
		<title>A Brief Introduction To XULRunner: Part 2</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=A_Brief_Introduction_To_XULRunner:_Part_2&amp;diff=995"/>
				<updated>2010-04-13T00:07:43Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Setting Up a XULRunner Development Environment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Now that you are familiar with what XULRunner ''is'', let's explore ''how'' to use it. More generally, let's explore how to use Mozilla tools that were designed to make building XULRunner applications easier.&lt;br /&gt;
&lt;br /&gt;
==How to Use XULRunner==&lt;br /&gt;
&lt;br /&gt;
===Setting Up a XULRunner Development Environment===&lt;br /&gt;
&lt;br /&gt;
Setting up your XULRunner development environment is very easy. You need just a few programs to get started:&lt;br /&gt;
&lt;br /&gt;
* A text editor of your choosing. If you don't have one with XML/XUL/JavaScript/CSS syntax highlighting, you might want to check out one of the many [http://www.scintilla.org/ Scintilla]-based editors: [http://www.geany.org Geany] is excellent for Linux (GTK+) users, and decent on Windows ([http://www.scintilla.org/SciTE.html SciTE] is similar); [http://www.activestate.com/komodo_edit/ Komodo Edit] is excellent on any XULRunner-supported platform (Hooray for XULRunner!); and there are [http://www.scintilla.org/ScintillaRelated.html many others] to choose from.&lt;br /&gt;
* The XULRunner Runtime itself. Download the latest stable version from Mozilla: http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/ (Note: Go into the most recent sub-directory and then the &amp;quot;runtimes&amp;quot; sub-directory. You don't need the SDK.)&lt;br /&gt;
&lt;br /&gt;
After installing the XULRunner runtime and text editor of your choice, you can begin creating a new project template.&lt;br /&gt;
&lt;br /&gt;
===Creating a XULRunner Application Template===&lt;br /&gt;
&lt;br /&gt;
Developers familiar with C and C++ know that all C/C++ applications must have a function called main(). Or in Win32 development, things are even more convoluted; a WinMain() function is required, along with a message pump and some other nonsense. Similarly, all XULRunner applications have a series of requirements (functional and structural) to &amp;quot;bootstrap&amp;quot; the application.&lt;br /&gt;
&lt;br /&gt;
Often, this task of creating a new project is tedious, mundane, and repetitive (to name just a few adjectives). This is why most C/C++ developers just copy startup (and maybe other) code from an existing project when creating a whole new one. That takes care of the bootstrapping process, without having to remember everything required to get up and running. This can certainly be done with new XULRunner applications, if you like. But there is an easier way...&lt;br /&gt;
&lt;br /&gt;
====FizzyPop, Or &amp;quot;How I Made My XULRunner Application&amp;quot;====&lt;br /&gt;
&lt;br /&gt;
Those clever folks at Mozilla know how bothersome it is to create a base XULRunner application (for the curious among you, have a look at the [https://developer.mozilla.org/en/Getting_started_with_XULRunner official tutorial, steps 3 - 7]). And so they created a project called [https://wiki.mozilla.org/FizzyPop FizzyPop] which will create all that fun boilerplate stuff for you; just give your project a name, maybe a version number, give it your name as the author, select a few options ... and BAM! Instant XULRunner Application: Just Add Water (tm).&lt;br /&gt;
&lt;br /&gt;
So here we go! To use this magical &amp;quot;FizzyPop&amp;quot; thing, just point your web browser to it! There are currently two different resources available for it (to my knowledge). The latter has been tagged a &amp;quot;prototype&amp;quot; so it might not be the one you want to use. But don't quote me on that! Without further ado, just go there:&lt;br /&gt;
&lt;br /&gt;
* [http://www.mozdev.org/projects/wizard/ Mozilla Project Wizard] ... OR ...&lt;br /&gt;
* [http://starkravingfinkle.org/projects/fizzypop/ FizzyPop prototype]&lt;br /&gt;
&lt;br /&gt;
Choose the &amp;quot;Application&amp;quot; Start link. Now there are just a couple of [very, very simple] steps to follow, and you'll be on your way:&lt;br /&gt;
&lt;br /&gt;
# Give your project a name. I chose &amp;quot;Hello World&amp;quot;.&lt;br /&gt;
# And an ID. The ID is in the form of an email address, which seems odd at first, but makes sense in the proper context ([[#Project ID]]). I chose &amp;quot;helloworld@kodewerx.org&amp;quot; for mine. If you don't have a domain, you can just use your own name in place of one.&lt;br /&gt;
# A short &amp;quot;package name&amp;quot; as well; for mine, &amp;quot;helloworld&amp;quot;.&lt;br /&gt;
# You can leave the version number and build ID at their default values (note that the &amp;quot;prototype&amp;quot; does not give you any default values) ... or go ahead and punch in some different numbers. It won't matter much.&lt;br /&gt;
# It also requires some author information (that's you!) Enter your name here.&lt;br /&gt;
# Set the Platform Details minimum and maximum version numbers according to the XULRunner runtime version you're using. In my case, minimum is set to &amp;quot;1.9.1.0&amp;quot; and maximum is &amp;quot;1.9.1.*&amp;quot;.&lt;br /&gt;
# You may leave the other entries blank, or configure them to your liking.&lt;br /&gt;
# Click the final &amp;quot;Create&amp;quot; button, and it will start to download a zip archive containing all of the necessary files and directory structures for a basic XULRunner application.&lt;br /&gt;
# Extract the zip file somewhere on your local drive. A &amp;quot;projects&amp;quot; folder for example.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is write some XUL to make it look like a program, and some JavaScript to make it do something! Or, you could always run the base application, just to see if your XULRunner setup works. This isn't a bad idea, after all.&lt;br /&gt;
&lt;br /&gt;
====Testing and Installation====&lt;br /&gt;
&lt;br /&gt;
=====On Mac OS X=====&lt;br /&gt;
&lt;br /&gt;
To test your application boilerplate, run XULRunner from the command line, passing the path to the &amp;quot;application.ini&amp;quot; as an argument. For example, on Mac OS X, I run this from the Terminal:&lt;br /&gt;
&lt;br /&gt;
 /Library/Frameworks/XUL.framework/xulrunner-bin /Users/parasyte/Desktop/helloworld-app-project/application.ini&lt;br /&gt;
&lt;br /&gt;
Note: XULRunner on OS X requires the full path to the application.ini file&lt;br /&gt;
&lt;br /&gt;
After making sure it works (you should be given a blank window) you can install the application to make it act more like a real app. (For example, installation will give it a Dock icon, menu bar, etc.) To install on OS X:&lt;br /&gt;
&lt;br /&gt;
 /Library/Frameworks/XUL.framework/xulrunner-bin --install-app /Users/parasyte/Desktop/helloworld-app-project&lt;br /&gt;
&lt;br /&gt;
Note: Don't include the &amp;quot;/application.ini&amp;quot; when installing the app!&lt;br /&gt;
&lt;br /&gt;
With the application installed, you can find it in your /Applications/ directory. If you set a &amp;quot;Vendor&amp;quot; when you created the boilerplate, then it will be put into /Applications/vendor-name/&lt;br /&gt;
&lt;br /&gt;
=====On Windows=====&lt;br /&gt;
&lt;br /&gt;
From the &amp;quot;Run&amp;quot; window (Start -&amp;gt; Run...) use the following command:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;%PROGRAMFILES%\XULRunner\xulrunner.exe&amp;quot; &amp;quot;path\to\application.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Where &amp;quot;path\to\application.ini&amp;quot; is the actual path the the actual application.ini file. If it works, you will get a blank window. You can then install the application with the following:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;%PROGRAMFILES%\XULRunner\xulrunner.exe&amp;quot; --install-app &amp;quot;path\to\application&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Where &amp;quot;path\to\application&amp;quot; is the path to the application's top-level directory; NOT the application.ini file. This will install the application to &amp;quot;%PROGRAMFILES%\application-name\&amp;quot;, or if you set the &amp;quot;Vendor&amp;quot; field when you created the boilerplate, in &amp;quot;%PROGRAMFILES%\vendor-name\application-name\&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=====On Ubuntu Linux=====&lt;br /&gt;
&lt;br /&gt;
In a terminal:&lt;br /&gt;
&lt;br /&gt;
 /path/to/xulrunner-bin &amp;quot;/path/to/application.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A blank window appearing means all worked well. To install:&lt;br /&gt;
&lt;br /&gt;
 /path/to/xulrunner-bin --install-app &amp;quot;/path/to/application&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Note: Do not point the installer to the application.ini file; point it instead to the application's top-level directory.&lt;br /&gt;
&lt;br /&gt;
====Project ID====&lt;br /&gt;
&lt;br /&gt;
The XULRunner Project ID is a unique identifier, which allows certain features of XULRunner to work properly. I can't exactly name any specific use for it off-hand, but I believe it can be used by extensions to access specific data local to your application.&lt;br /&gt;
&lt;br /&gt;
===Hello World===&lt;br /&gt;
&lt;br /&gt;
To complete the first step towards world domination with XULRunner, you'll want to make the application do something (or at least, ''say'' something) ...&lt;br /&gt;
&lt;br /&gt;
Open the file /chrome/content/main.xul in your application directory. You will be greeted with a lot of XML. This is the file that defines the complete GUI for your application's main window. You can add any XUL elements to this file to create any kind of widget in your main window. For starters, just add a simple label element before the &amp;lt;/vbox&amp;gt; tag, near the end of the file. Something like this:&lt;br /&gt;
&lt;br /&gt;
   &amp;lt;hbox id=&amp;quot;main_box&amp;quot; flex=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;lt;vbox id=&amp;quot;workspace_box&amp;quot; flex=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
      '''''&amp;lt;label value=&amp;quot;Hello, World!&amp;quot;/&amp;gt;'''''&lt;br /&gt;
     &amp;lt;/vbox&amp;gt;&lt;br /&gt;
   &amp;lt;/hbox&amp;gt;&lt;br /&gt;
 &amp;lt;/window&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the app to see your changes. Reinstall it, if you like. When reinstalling, it is a good idea to first delete the old already-installed application, but this is not always necessary.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
Now that you have a Hello World XULRunner app, you can continue exploring the rest of what XULRunner has to offer. This means XUL and JavaScript... The following sections provide some helpful resources (API references, tutorials, etc.) which will get your on your way. Since you are up and running with a minimal application, it won't take much longer until you have a killer-app of your very own!&lt;br /&gt;
&lt;br /&gt;
===Developer Resources===&lt;br /&gt;
&lt;br /&gt;
This is a list of websites relevant to XULRunner and creating applications for it. While this list is produced entirely without any specific order, I've attempted to keep the most important of these near the top.&lt;br /&gt;
&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_Tutorial Mozilla Developer Central: XUL Tutorial] (Slightly old, but still one of the best sources of information on XUL.)&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL Mozilla Developer Central: XUL Information] (Specifically, the complete [https://developer.mozilla.org/en/XUL_Reference XUL Reference].)&lt;br /&gt;
* [https://developer.mozilla.org/en/XULRunner Mozilla Developer Central: XULRunner Information]&lt;br /&gt;
* [http://www.xul.fr/tutorial/ XUL.fr Tutorial]&lt;br /&gt;
* [http://books.mozdev.org/chapters/index.html Creating Applications With Mozilla] (Online book.)&lt;br /&gt;
* [http://mb.eschew.org/ Rapid Application Development With Mozilla] (Online book.)&lt;br /&gt;
* [https://developer.mozilla.org/en/Creating_XPCOM_Components Creating XPCOM Components] (Online book.)&lt;br /&gt;
* [http://www.oxymoronical.com/experiments/xpcomref/ Mozilla XPCOM Reference] (All interfaces and components; always kept up-to-date.)&lt;br /&gt;
* [https://addons.mozilla.org/en-US/developers Mozilla Add-on Developer Hub] (Mostly related to Firefox add-on development; but useful for XULRunner, too.)&lt;br /&gt;
* [http://parasyte.kodewerx.org/projects/xulrunner/x-xulintro-pdf.pdf IBM developerWorks: An introduction to XML User Interface Language (XUL) development] (PDF, mirrored here because IBM requires compulsory registration to download this from their website. Original location: http://www.ibm.com/developerworks/edu/x-dw-x-xulintro.html)&lt;br /&gt;
* [http://kb.mozillazine.org/Development_resources MozillaZine: Development Resources] (Semi-outdated.)&lt;br /&gt;
* [http://xml.coverpages.org/xul.html Cover Pages: Extensible User Interface Language (XUL)] (Extremely outdated, but historically relevant.)&lt;br /&gt;
&lt;br /&gt;
====XUL Editors and Designers====&lt;br /&gt;
&lt;br /&gt;
I've found these applications helpful, while learning XUL.&lt;br /&gt;
&lt;br /&gt;
* [http://ted.mielczarek.org/code/mozilla/xuledit/xuledit.xul Ted Mielczarek's Real-Time XUL Editor] (Great for quickly testing XUL from directly within Firefox.)&lt;br /&gt;
* [https://developer.mozilla.org/en/XUL_Explorer XUL Explorer] (Similar to the Real-Time XUL Editor above, but as a XULRunner application.)&lt;br /&gt;
* [http://kukuru.s7.xrea.com/xulpix/ XULPIX] (A ''great'' XUL editor; the closest thing to a form designer that we currently have ... without Eclipse! Yucky...)&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;br /&gt;
&lt;br /&gt;
===Packaging===&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Packaging&amp;quot; is the process of creating an installer for your application. So far as I know, you have two choices here:&lt;br /&gt;
&lt;br /&gt;
# Create a self-contained installer, which includes its own private copy of the XULRunner runtime.&lt;br /&gt;
# Create an XPI; an archive that can be installed as a XULRunner application by a pre-existing XULRunner runtime.&lt;br /&gt;
&lt;br /&gt;
The latter option requires that your users install the XULRunner runtime (just like you did at the beginning of this introduction). The former option just requires that the user download the installer and install it. This option has the disadvantage that the file the user must download is a *LOT* larger than just the simple XPI. About 9MB for Windows and Linux, or 17MB for Mac OS X; compared to just a few KB (typically 10KB for a small app, like our Hello World) for the XPI!&lt;br /&gt;
&lt;br /&gt;
I haven't yet investigated XULRunner application packaging. This section is in need of completion.&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=994</id>
		<title>Scalable Remote Debugger Protocol</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=994"/>
				<updated>2010-01-13T05:01:36Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* info() */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently serving as a reference to kick-start development of the universal debugger protocol which will be used by the [[Universal Debugger Project]] and hopefully many, many other debuggers and debugger interfaces in the years to come.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
These references are listed in order of relevance; most relevant first.&lt;br /&gt;
&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc909.txt RFC-909: Loader Debugger Protocol]&lt;br /&gt;
# [http://sourceware.org/gdb/download/onlinedocs/gdb_33.html GDB Remote Serial Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc643.txt RFC-643: Network Debugging Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/ien/ien158.txt IEN-158: XNET Debugging Protocol]&lt;br /&gt;
# [http://www.xdebug.org/docs-dbgp.php DBGp: A common debugger protocol for languages and debugger UI communication]&lt;br /&gt;
&lt;br /&gt;
The relevancy I've determined for this list is due to interest in these specs, as well as potential generic uses and protocol extension.&lt;br /&gt;
&lt;br /&gt;
RFC-909 is so far the closest thing I have found which resembles the general idea I have for a &amp;quot;Universal Debugger Protocol&amp;quot;. It's composed as a simple binary packet, it's extensible, and it's designed to be stacked on top of existing transport protocols such as TCP/IP. I doubt this exact spec will fit all of our needs, but it is certainly a good start.&lt;br /&gt;
&lt;br /&gt;
GDB provides a fairly popular protocol. This one is designed for serial communications, so it will work well with small embedded devices. But it could be complicated to extend while retaining its GDB friendliness.&lt;br /&gt;
&lt;br /&gt;
RFC-643 and IEN-158 are interesting only because they show that some experimentation on the ideas of remote debugging have been employed in the past. Unfortunately, these specs were designed for a specific architecture, and are of little practical use for our purposes.&lt;br /&gt;
&lt;br /&gt;
DBGp shows what a modern remote debugging protocol can look like; including modern XML syntax. The downside to this is that low-level debuggers in small embedded devices are unlikely to parse XML at all.&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
&lt;br /&gt;
This section represents my ([[User:Parasyte|Parasyte]]) own personal opinions and ideas, and should not be taken as advocacy for standardization.&lt;br /&gt;
&lt;br /&gt;
One of the main goals of developing a &amp;quot;universal&amp;quot; protocol for debugging is that it must be usable everywhere; in small embedded devices, and some of the most powerful machines in the world. This kind of flexibility must be designed around multiple layers of abstraction. See [http://en.wikipedia.org/wiki/OSI_Model OSI Model] and [http://en.wikipedia.org/wiki/Internet_Protocol_Suite Internet Protocol Suite] for examples of abstraction layers used in communications technologies.&lt;br /&gt;
&lt;br /&gt;
At the lowest layer, you find the ''wire''; the physical means of transmitting information over distance. For our purposes, we should not limit ourselves to a single wire. Instead, we should allow the use of multiple wires, user-selectable, but never more than one at a time.&lt;br /&gt;
&lt;br /&gt;
The following layers get more and more generic and abstract, until you reach the highest layer which represents what the application sees and interacts with. This would be the &amp;quot;protocol&amp;quot; itself.&lt;br /&gt;
&lt;br /&gt;
So let's break these components down, hypothetically, and get into some details, ordered lowest layer first:&lt;br /&gt;
&lt;br /&gt;
# '''Physical layer''': Some examples of wires to support include LAN (Ethernet/WiFi), Wireless (Bluetooth), RS-232 (serial port, USB serial port), Inter-Process Communication (Domain Sockets? DBUS?)&lt;br /&gt;
# '''Transport layer''': Some examples of transport protocols include TCP/IP, UDP/IP (LAN, Domain Sockets), UART (RS-232), IPC-specific (DBUS)&lt;br /&gt;
# '''Application layer''': A library (or similar service, E.G. a daemon) to tie all transport layers into a single API that, to the application, looks like one simple interface to connect and send/receive data. The library/daemon will have to handle the transport-specific details behind-the-scenes.&lt;br /&gt;
&lt;br /&gt;
Thinking about this led to a conundrum; If we support multiple wires, we have to support multiple transport protocols which are compatible with those wires. And if we support multiple transport protocols, we have to know which one our target implements. To make the API as simple as possible, we must not force clients to choose from configurable options (for a bad example) that requires a large degree of changes for each different type of connection made. How do we simplify the API so that a user can just plain connect without doing any pre-setup work?&lt;br /&gt;
&lt;br /&gt;
Answer: The [http://en.wikipedia.org/wiki/URI_scheme URI scheme]. The unfortunate downside to this solution is that it is undesired to use URI schemes without registering them with IANA. However, an argument could be made that these schemes would not be used for general network/internet communication. A few popular examples of similarly non-networked schemes are the file: and about: URI schemes. (The exception here is that at least one physical layer (LAN) could be used for over-the-internet communication; but this has great benefits in its own right.)&lt;br /&gt;
&lt;br /&gt;
===Example URI Schemes===&lt;br /&gt;
&lt;br /&gt;
The following table represents some examples of how URI schemes could be used as debugger protocols:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp://192.168.1.20/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | TCP/IP to remote host 192.168.1.20 on a pre-defined default port&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+udp://192.168.1.20:9424/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UDP/IP to remote host 192.168.1.20 on port 9424&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+usb://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | USB (SRDP-compatible devices) on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+uart://localhost:3/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UART COM port 3 on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+dbus://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | DBUS IPC on localhost&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'srdp' prefix on these examples is to specify the 'Scalable Remote Debugger Protocol.' The + and suffix defines an additional layer (or protocol) below SRDP.&lt;br /&gt;
&lt;br /&gt;
The latter three examples look a bit odd with localhost being the destination, but this is necessary, since the localhost ''is'' the destination for hosting the UART RS-232 port, USB port, and IPC interface. Using non-loopback interfaces (IP addresses outside of the local machine) with these protocols should be undefined, unless there is evidence that connecting to RS-232/USB/IPC interfaces on other machines across a network is practical and plausible.&lt;br /&gt;
&lt;br /&gt;
===Simplified Configuration===&lt;br /&gt;
&lt;br /&gt;
These URI schemes give a very simple and elegant solution to the concerns they address. No longer will you be stuck with complicated configuration settings like the example below (upper left group box) ... and this is not an incredibly complex configuration dialog, as it is; instead, connecting to ANY low-level debugger in the world will be as simple as typing a URL.&lt;br /&gt;
&lt;br /&gt;
Example of what '''''not''''' to do:&lt;br /&gt;
&lt;br /&gt;
[[Image:Gscc_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Operation Groups===&lt;br /&gt;
&lt;br /&gt;
The protocol is defined as a set of usable &amp;quot;requests&amp;quot; (AKA &amp;quot;operations&amp;quot; or &amp;quot;commands&amp;quot;) requested by the client to the debugger, or vice-versa. Operations should be grouped according to a specific metric. The metric I've chosen is hardware (architecture) relationships. The table below shows an example of such groups (currently 6 in total) and example operations assigned to each group.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 1)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Diagnostics (Info, Ping/Pong, Reset, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 2)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | CPU handling (Register read/write, Arbitrary code execution, General CPU control, General process/thread control...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 3)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Memory handling (Read, Write, Address conversion, Hardware I/O, Cache control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 4)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Breakpoint handling (Add, Delete, Edit, Get, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 5)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Stream handling (stdin/stdout/stderr, Debugger-specific messages, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 6)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Vendor-specific (Custom command sets; should be discouraged unless absolutely necessary)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Proposal==&lt;br /&gt;
&lt;br /&gt;
This section defines a proposed specification which may be adopted as the &amp;quot;Scalable Remote Debugger Protocol&amp;quot;. It is considered a work in progress and is currently open for peer-review, meaning we are interested in receiving comments, criticisms, and suggestions.&lt;br /&gt;
&lt;br /&gt;
===Protocol Goals===&lt;br /&gt;
&lt;br /&gt;
Goals of the protocol include:&lt;br /&gt;
&lt;br /&gt;
# '''Client/server relationship''': Target (debuggee) acts as a server, quietly listening for any SRDP requests; User Interface acts as a client, making explicit requests to a listening server.&lt;br /&gt;
# '''Asynchronous requests''': A client must send requests without expecting an immediate response. A server accepting requests may not respond immediately to those requests.&lt;br /&gt;
# '''Scalable''': The data structure (format) used in the protocol must be adaptable to the future; The structure must be as forgiving and dynamic as possible, avoiding fixed contents (except where absolutely necessary) and allowing for [non-mission-critical] non-standard contents.&lt;br /&gt;
# '''Easy to implement''': Basic features of the protocol should be easy to implement from an API point-of-view, as well as having a small memory footprint; the protocol must be usable on small embedded machines with few resources.&lt;br /&gt;
# '''Robust''': Ambiguity should be kept to a minimum in all aspects of the protocol; every bit transferred should have a useful meaning.&lt;br /&gt;
# '''Easy to debug''': A debugger protocol that cannot itself be debugged (observed and verified to work as expected) is a failure in and of itself. For this reason, the protocol should be human-readable in its most basic form.&lt;br /&gt;
&lt;br /&gt;
===Underlying Protocols===&lt;br /&gt;
&lt;br /&gt;
There are no reservations on any underlying protocols (protocols used to move data from the client to the server, and back again -- SRDP is not one of these protocols). The only requirement is that they provide hand-shaking (transmission control), sequential ordering of packet data arrival, and data integrity checking. Some examples of suitable underlying protocols include [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/UDP/IP], and [http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART].&lt;br /&gt;
&lt;br /&gt;
The initial reference implementation will use TCP/IP for remote connections. For local-listening servers, the reference implementation will use UNIX Domain Sockets on UNIX-like operating systems, and Named Pipes on Windows.&lt;br /&gt;
&lt;br /&gt;
===Requests, Responses, Alerts===&lt;br /&gt;
&lt;br /&gt;
Packets are given different names depending on their transmission direction (client -&amp;gt; server, or server -&amp;gt; client) and intended recipient (server, specific client, or all clients).&lt;br /&gt;
&lt;br /&gt;
Response, requests, and alerts must have a unique identifier associated with them. This will allow clients and servers to stay in sync, knowing which responses are for which requests, for example.&lt;br /&gt;
&lt;br /&gt;
====Requests====&lt;br /&gt;
&lt;br /&gt;
A packet is called a request if it is from a client to the server. The name &amp;quot;request&amp;quot; comes from the idea that the client is requesting information or a specific action to be performed by the server.&lt;br /&gt;
&lt;br /&gt;
====Responses====&lt;br /&gt;
&lt;br /&gt;
Responses are packets from a server to a specific client. Responses are always sent in response to a request (hence the name). However, not all requests are required to send responses (which is why &amp;quot;requests&amp;quot; are not called &amp;quot;commands&amp;quot;). Responses are only sent to the client which initiated the specific request being handled.&lt;br /&gt;
&lt;br /&gt;
====Alerts====&lt;br /&gt;
&lt;br /&gt;
An alert is a special type of response (a packet from the server to clients); an alert is sent to all connected/listening clients. This is synonymous with network &amp;quot;broadcast&amp;quot; packets, and it useful for notifying all clients of information they might like to know.&lt;br /&gt;
&lt;br /&gt;
A few examples of information that all clients might like to know are:&lt;br /&gt;
&lt;br /&gt;
* Breakpoint hits&lt;br /&gt;
* Pausing/resuming execution&lt;br /&gt;
* Resets&lt;br /&gt;
* Debugging messages (log messages)&lt;br /&gt;
&lt;br /&gt;
Not all alerts are initiated by requests from clients, but most will be. Log messages are typically spewed by programs without explicit requests; SRDP can allow listening for and capturing these messages.&lt;br /&gt;
&lt;br /&gt;
====Commands====&lt;br /&gt;
&lt;br /&gt;
The all-encompassing term for requests, responses and alerts is &amp;quot;commands&amp;quot;. Any time a &amp;quot;command&amp;quot; is mentioned, it refers to any combination of requests, responses, or alerts.&lt;br /&gt;
&lt;br /&gt;
===Protocol Packet Data Structure===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;goals&amp;quot; section outlines the major features which formed the following data structure. Inspiration comes mainly from [http://en.wikipedia.org/wiki/JSON JSON], the JavaScript Object Notation. As JSON is a serialization [text format] of JavaScript objects, the SRDP data structure is a serialization of the data being transmitted.&lt;br /&gt;
&lt;br /&gt;
The structure also shares some inspiration from [http://en.wikipedia.org/wiki/Remote_procedure_call RPC]; An example is that your client may want to read work RAM from the target. The SRDP request for &amp;quot;read memory&amp;quot; is technically similar to remotely running a &amp;quot;read memory&amp;quot; function on the server, invoked by the client. For this reason, each SRDP packet contains one or more &amp;quot;arguments&amp;quot; which you could imagine are passed directly to a plain old function.&lt;br /&gt;
&lt;br /&gt;
Each packet is sent as a series of 8-bit bytes. Packets are broken down into a &amp;quot;request/response/alert&amp;quot; name (called a command), encapsulating a series of &amp;quot;arguments&amp;quot;. You can think of it like a C function call. The &amp;quot;info&amp;quot; command, for example, requests information about the target machine architecture; it requires no arguments. The info command looks like this, and is a complete and valid SRDP packet:&lt;br /&gt;
&lt;br /&gt;
  info()&lt;br /&gt;
&lt;br /&gt;
Each argument has a name (made of one or more characters: alpha-numeric, underscore (_), or hyphen (-). The argument name is followed by a colon (:) and then a single byte representing the data type of the argument, then an equals sign (=) and the argument's value. All arguments are separated with a comma (,).&lt;br /&gt;
&lt;br /&gt;
The argument syntax is similar to that of [http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]. In pseudo-form, it looks something like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:{type}={value}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Valid data types:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | {type}&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Name&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | n&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any positive integer, encoded as a [http://www.dlugosz.com/ZIP2/VLI.html VLI]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | s&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Signed Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any negative integer, encoded as a [http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement one's complement] VLI&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | f&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Floating Point Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any non-integer number, Infinity, or [http://en.wikipedia.org/wiki/NaN NaN], encoded as a null-terminated UTF-8 string, or null-terminated UTF-16 or UTF-32 string with BOM; To be decoded by [http://en.wikipedia.org/wiki/Scanf#Format_string_specifications sscanf]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | a&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob), preceded by a VLI to indicate the length of the array.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | c&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Compressed Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob) with [http://en.wikipedia.org/wiki/Run-length_encoding RLE] compression. See [[#Compressed Array Data Type]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | t&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Text&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Null-terminated UTF-8 string without [http://en.wikipedia.org/wiki/Byte-order_mark BOM], or null-terminated UTF-16 or UTF-32 string with BOM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some example arguments. (Please keep in mind that all of the argument names listed within this section are for demonstration purposes only, and are not recommended for reference purposes.)&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | msg:t=Hello, World!␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | num:n=□&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | pi:f=3.141592␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | ram_dump:a=□■■■■&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | my-compressed-data:c=□□■■■■□■□■■■&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
What the symbols mean:&lt;br /&gt;
&lt;br /&gt;
  ␀: Null-terminator&lt;br /&gt;
  □: VLI&lt;br /&gt;
  ■: Data byte&lt;br /&gt;
&lt;br /&gt;
====Compressed Array Data Type====&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; padding: 10px;&amp;quot; | '''''One suggestion is making this data-type optional, and changing this spec to use a standard library, like zlib. In this way, slow machines with few resources can adhere to the SRDP spec without wasting precious footprint space and computational power implementing such &amp;quot;heavy&amp;quot; libraries.&lt;br /&gt;
&lt;br /&gt;
Using a &amp;quot;heavy-weight&amp;quot; compression library will help achieve better compression ratios, but will add processing overhead. The added overhead may turn out to be an overall hindrance. For example, a memory editor might want to refresh a memory display as fast as possible (several times per second) within a small visible view-port window. This kind of editor will need to download the contents of memory within the visible range quickly. Using compression in a use-case like this is a good idea, but only if transferring the smaller packet can make up for the time required to compress and decompress the data.'''''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Compressed arrays are similar to the standard &amp;quot;Array&amp;quot; data type. The compressed array starts with a single VLI to represent the total data size of the value (e.g. the size of the compressed data, ''x''). The following data is a series of alternating raw data and RLE data.&lt;br /&gt;
&lt;br /&gt;
# '''Raw Data''': A VLI representing raw data size in bytes (''n''), followed by ''n'' bytes of actual data.&lt;br /&gt;
# '''RLE Data''': A VLI representing RLE data size in bytes (''n''), followed by a single byte to be repeated (''n'' + 4) times in the output.&lt;br /&gt;
&lt;br /&gt;
This series is repeated until there are no more bytes to be read from input (''x'' bytes of the argument value have been read).&lt;br /&gt;
&lt;br /&gt;
For the RLE compression to be useful (efficient) it must not be used for any less than 4 bytes (therefore, the VLI is said to be a &amp;quot;4-based&amp;quot; number). The number 4 is derived from the minimum overhead introduced by the serial alternation and VLIs; 1 VLI for RLE output length, 1 byte of RLE data, 1 VLI for raw data length.&lt;br /&gt;
&lt;br /&gt;
Thus, in order for the RLE to perform &amp;quot;compression&amp;quot;, the RLE output must be larger than the smallest sequence required to switch from raw data and back again. Some examples to illustrate, '''''bold-italic''''' bytes are for VLI &amp;quot;control sequences&amp;quot; (the data lengths specified above):&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 1'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 01&lt;br /&gt;
 &lt;br /&gt;
 Incorrectly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''&amp;lt;u&amp;gt;03&amp;lt;/u&amp;gt;''''' 00 '''''01''''' 01&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''08''''' 94 24 51 73 00 00 00 01&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 2'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''00''''' 00&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 3'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 00 00 00 00 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''00''''' '''''04''''' 00&lt;br /&gt;
&lt;br /&gt;
The reason the second line in example 1 above is &amp;quot;incorrectly&amp;quot; compressed is because the second VLI is expecting the length to be 0-based. If this was the case, you would be simply adding overhead to replace any bytes saved by the &amp;quot;compression&amp;quot;. For this reason, the &amp;quot;correct&amp;quot; way to compress the example is to use a single length of raw data. This example is non-compressible, and should not be sent as a compressed array data type.&lt;br /&gt;
&lt;br /&gt;
In the second example, the data can be compressed nicely, saving a byte overall (including compression overhead). Since this is the &amp;quot;correct&amp;quot; way to compress the data, it is using a 4-based VLI on the RLE Data: &amp;quot;'''''00'''''&amp;quot; means 4 bytes of output, &amp;quot;'''''01'''''&amp;quot; means 5 bytes, &amp;quot;'''''02'''''&amp;quot; means 6 bytes, etc.&lt;br /&gt;
&lt;br /&gt;
The third example shows how to compress a series of bytes that starts with repeating data, instead of non-repeating &amp;quot;raw data&amp;quot;. The first VLI of '''''00''''' means there is no raw data for output (this is required: compressed arrays always begin with the Raw Data, followed by RLE Data). The second VLI '''''04''''' is the length of the RLE Data; 8 bytes. Even if the non-compressed data was 4 bytes of &amp;quot;00&amp;quot;, the compressed array would still be only 3 bytes of total data, saving one byte. This helps explain the reasoning behind the 4-based VLI for RLE Data.&lt;br /&gt;
&lt;br /&gt;
====Object Data Type====&lt;br /&gt;
&lt;br /&gt;
The basic structure and data types shown so far are very powerful; your server can tell the client vast amounts of information, such as CPU architecture, memory maps, I/O maps, etc. with just a handful of arguments. However, grouping these arguments in a meaningful way may be difficult. You might be inclined to do some &amp;quot;mock&amp;quot; namespacing, like prefixing each CPU-related argument with &amp;quot;cpu_&amp;quot;. This is effective, but also slightly wasteful and error-prone.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;object&amp;quot; data type is designed to handle such situations. This data type allows an argument to be a container for other arguments. Its format looks like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:[...]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Where the set of ellipses denotes one or more &amp;quot;regular&amp;quot; arguments. Here is an example of what a &amp;quot;cpu&amp;quot; object might look like:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
(Note the white-space is for readability only; it is not meant to be transferred as part of the protocol data.)&lt;br /&gt;
&lt;br /&gt;
In this example, the &amp;quot;cpu&amp;quot; object contains two arguments: cpu.arch and cpu.name; both strings.&lt;br /&gt;
&lt;br /&gt;
But there are also times when you will want your server to send that same information for two [or more] CPU architectures on a single target. Some platforms may have multiple CPUs, each with its own individual set of resources (memory maps and the like), as well as shared resources between the CPUs. For this, the packet data structure needs a more advanced method of communicating these kinds of details.&lt;br /&gt;
&lt;br /&gt;
For this case, you can optionally create arrays of objects by including a comma (,) after the closing square bracket, followed by another series of arguments enclosed in their own square brackets, ''ad infinitum''. In other words, any leading object definitions without explicit names will be treated as additional array elements for the previously named object.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM7TDMI␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now our &amp;quot;cpu&amp;quot; object defines two CPUs: an ARM9 and ARM7, ready for Nintendo DS hacking. These arguments can be referenced as cpu[0].arch, cpu[0].name, cpu[1].arch, and cpu[1].name respectively.&lt;br /&gt;
&lt;br /&gt;
Objects can be arbitrarily complex, containing arrays of other objects. Here is an example of a simple memory map, containing Work RAM (read/write/execute) and ROM (read/execute) sections. The Work RAM section is broken into two distinct memory ranges. This is quite easily expressed:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;memory:[&lt;br /&gt;
:name:t=Work RAM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&amp;lt;br/&amp;gt;&lt;br /&gt;
:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RWX␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:name:t=ROM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RX␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Command Reference===&lt;br /&gt;
&lt;br /&gt;
'''''FIXME: WIP'''''&lt;br /&gt;
&lt;br /&gt;
====Requests====&lt;br /&gt;
&lt;br /&gt;
=====info()=====&lt;br /&gt;
Request information about the target machine architecture. The '''info()''' request is implied during connection: A response will be sent after a connection is successfully established. This allows clients to gather necessary information about the target during the connection phase, without explicitly making the request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Return values'':&lt;br /&gt;
&lt;br /&gt;
Must only return one of the following:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;sys&amp;lt;/u&amp;gt;''' (string):&amp;lt;br/&amp;gt;A shorthand for defining known machines (mostly video game systems).&amp;lt;br/&amp;gt;See below for supported values&lt;br /&gt;
* '''&amp;lt;u&amp;gt;machine&amp;lt;/u&amp;gt;''' (object):&amp;lt;br/&amp;gt;A longhand for defining the complete machine architecture.&amp;lt;br/&amp;gt;TODO: Specify all object elements and their meanings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The currently supported values for '''&amp;lt;u&amp;gt;sys&amp;lt;/u&amp;gt;''' are:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NES&amp;lt;/u&amp;gt;''': Nintendo Entertainment System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SNES&amp;lt;/u&amp;gt;''': Super Nintendo Entertainment System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;N64&amp;lt;/u&amp;gt;''': Nintendo 64&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGC&amp;lt;/u&amp;gt;''': Nintendo GameCube&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS1&amp;lt;/u&amp;gt;''': Sony Playstation&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS2&amp;lt;/u&amp;gt;''': Sony Playstation 2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Planned future support:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GB&amp;lt;/u&amp;gt;''': Nintendo GameBoy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GBC&amp;lt;/u&amp;gt;''': Nintendo GameBoy Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GBA&amp;lt;/u&amp;gt;''': Nintendo GameBoy Advance&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NDS&amp;lt;/u&amp;gt;''': Nintendo DS/DSi&lt;br /&gt;
* '''&amp;lt;u&amp;gt;VB&amp;lt;/u&amp;gt;''': Nintendo Virtual Boy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WII&amp;lt;/u&amp;gt;''': Nintendo Wii&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SMS&amp;lt;/u&amp;gt;''': Sega Master System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SMD&amp;lt;/u&amp;gt;''': Sega Genesis/Mega Drive&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SCD&amp;lt;/u&amp;gt;''': Sega CD/Mega CD&lt;br /&gt;
* '''&amp;lt;u&amp;gt;32X&amp;lt;/u&amp;gt;''': Sega 32X&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GG&amp;lt;/u&amp;gt;''': Sega GameGear&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SAT&amp;lt;/u&amp;gt;''': Sega Saturn&lt;br /&gt;
* '''&amp;lt;u&amp;gt;DC&amp;lt;/u&amp;gt;''': Sega Dreamcast&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PSP&amp;lt;/u&amp;gt;''': Sony Playstation Portable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TGC&amp;lt;/u&amp;gt;''': Tiger Game.com&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Considering support &amp;quot;some day&amp;quot;:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;3DO&amp;lt;/u&amp;gt;''': 3DO&lt;br /&gt;
* '''&amp;lt;u&amp;gt;A26&amp;lt;/u&amp;gt;''': Atari 2600&lt;br /&gt;
* '''&amp;lt;u&amp;gt;LYNX&amp;lt;/u&amp;gt;''': Atari Lynx/Lynx II&lt;br /&gt;
* '''&amp;lt;u&amp;gt;JAG&amp;lt;/u&amp;gt;''': Atari Jaguar&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WS&amp;lt;/u&amp;gt;''': Bandai Wonder Swan&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WSC&amp;lt;/u&amp;gt;''': Bandai Wonder Swan Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GP32&amp;lt;/u&amp;gt;''': GamePark 32&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GP2X&amp;lt;/u&amp;gt;''': GamePark Holdings GP2X&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WIZ&amp;lt;/u&amp;gt;''': GamePark Holdings GP2X Wiz&lt;br /&gt;
* '''&amp;lt;u&amp;gt;XBOX&amp;lt;/u&amp;gt;''': Microsoft XBox&lt;br /&gt;
* '''&amp;lt;u&amp;gt;X360&amp;lt;/u&amp;gt;''': Microsoft XBox 360&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TG16&amp;lt;/u&amp;gt;''': NEC TurboGrafx-16/PC Engine&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TGCD&amp;lt;/u&amp;gt;''': NEC TurboGrafx-CD/PC Engine CD&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SGFX&amp;lt;/u&amp;gt;''': NEC SuperGrafx&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGEO&amp;lt;/u&amp;gt;''': Neo*Geo AES/MVS&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGP&amp;lt;/u&amp;gt;''': Neo*Geo Pocket&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGPC&amp;lt;/u&amp;gt;''': Neo*Geo Pocket Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PKMN&amp;lt;/u&amp;gt;''': Nintendo Pokémon Mini&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SGB&amp;lt;/u&amp;gt;''': Nintendo Super GameBoy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;CDI&amp;lt;/u&amp;gt;''': Philips CD-i&lt;br /&gt;
* '''&amp;lt;u&amp;gt;VMU&amp;lt;/u&amp;gt;''': Sega Dreamcast VMU&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS3&amp;lt;/u&amp;gt;''': Sony Playstation 3&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SV&amp;lt;/u&amp;gt;''': SuperVision&lt;br /&gt;
&lt;br /&gt;
===Proposal Comments===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Protocol Goals&amp;quot; have lead much of the motivation for developing this proposal. This presents what seems to be several very strange choices, at first glance. The choice of representing floating point numbers as a string of text seems extremely odd, until you consider that using the target-native floating point data format would make no sense when sending that data to a remote client (which is most likely running on a different architecture, and may have totally different native floating point formats). In order to express floating points with arbitrary precision in a data format-agnostic way, it is necessary to use a non-native format like text.&lt;br /&gt;
&lt;br /&gt;
Another oddity in this spec is the use of VLIs (variable-length integers) and their affect on the rest of the format. The main purpose for using VLIs is address widths. Some architectures can express their full address range within a single byte. Others require up to 8 bytes for a full 64-bit address range. Future architectures are by no means limited to 64-bit address widths. For this very reason, it is necessary to scale down as well as up. A VLI can express an address in as little as a single byte, or scale upward to arbitrarily large numbers. This makes VLIs perfect for addressing requirements among any architecture.&lt;br /&gt;
&lt;br /&gt;
VLIs present their own issues, however. For example, expressing a negative number as a VLI is nearly incomprehensible. Some might be inclined to reserve one bit within a VLI to indicate signedness, but that's another bit that cannot be used to minimize VLI overhead. The overhead is additional bytes required to represent a full number in a VLI system. For example, it is common for numbers 0 - 127 to be contained entirely within a single byte, including the overhead. But numbers between 128 - 255 require an additional byte to include more VLI &amp;quot;header&amp;quot; information (used to extend VLIs into arbitrarily long numbers). This is counter-intuitive, where a single byte itself can hold numbers between 0 - 255. Adding an additional sign bit reduces the range of VLIs by half: a single byte can only encode numbers between 0 - 63.&lt;br /&gt;
&lt;br /&gt;
The solution is to use a different data type specifically for expressing negative numbers. The VLI is encoded just like a positive number, but when interpreting the VLI, it must be converted to a negative number by either subtracting from zero (0 - ''n'') or multiplying by negative one (''n'' * -1). This is referred to as a &amp;quot;one's complement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In general, the efficiency of a VLI is very static. That means, a number using 0 - 7 bits of data (for example, the number &amp;quot;0&amp;quot; uses 0 bits of data, and the number &amp;quot;64&amp;quot; [binary: 100000] uses 6 bits) can be encoded into a single byte, a number using 8 - 14 bits can be encoded into 2 bytes, a number using 15 - 21 bits can be encoded into 3 bytes, etc. See http://www.dlugosz.com/ZIP2/VLI.html for more information on the kind of VLI I am considering for this proposal.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=993</id>
		<title>Scalable Remote Debugger Protocol</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=993"/>
				<updated>2010-01-13T04:59:33Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Command Reference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently serving as a reference to kick-start development of the universal debugger protocol which will be used by the [[Universal Debugger Project]] and hopefully many, many other debuggers and debugger interfaces in the years to come.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
These references are listed in order of relevance; most relevant first.&lt;br /&gt;
&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc909.txt RFC-909: Loader Debugger Protocol]&lt;br /&gt;
# [http://sourceware.org/gdb/download/onlinedocs/gdb_33.html GDB Remote Serial Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc643.txt RFC-643: Network Debugging Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/ien/ien158.txt IEN-158: XNET Debugging Protocol]&lt;br /&gt;
# [http://www.xdebug.org/docs-dbgp.php DBGp: A common debugger protocol for languages and debugger UI communication]&lt;br /&gt;
&lt;br /&gt;
The relevancy I've determined for this list is due to interest in these specs, as well as potential generic uses and protocol extension.&lt;br /&gt;
&lt;br /&gt;
RFC-909 is so far the closest thing I have found which resembles the general idea I have for a &amp;quot;Universal Debugger Protocol&amp;quot;. It's composed as a simple binary packet, it's extensible, and it's designed to be stacked on top of existing transport protocols such as TCP/IP. I doubt this exact spec will fit all of our needs, but it is certainly a good start.&lt;br /&gt;
&lt;br /&gt;
GDB provides a fairly popular protocol. This one is designed for serial communications, so it will work well with small embedded devices. But it could be complicated to extend while retaining its GDB friendliness.&lt;br /&gt;
&lt;br /&gt;
RFC-643 and IEN-158 are interesting only because they show that some experimentation on the ideas of remote debugging have been employed in the past. Unfortunately, these specs were designed for a specific architecture, and are of little practical use for our purposes.&lt;br /&gt;
&lt;br /&gt;
DBGp shows what a modern remote debugging protocol can look like; including modern XML syntax. The downside to this is that low-level debuggers in small embedded devices are unlikely to parse XML at all.&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
&lt;br /&gt;
This section represents my ([[User:Parasyte|Parasyte]]) own personal opinions and ideas, and should not be taken as advocacy for standardization.&lt;br /&gt;
&lt;br /&gt;
One of the main goals of developing a &amp;quot;universal&amp;quot; protocol for debugging is that it must be usable everywhere; in small embedded devices, and some of the most powerful machines in the world. This kind of flexibility must be designed around multiple layers of abstraction. See [http://en.wikipedia.org/wiki/OSI_Model OSI Model] and [http://en.wikipedia.org/wiki/Internet_Protocol_Suite Internet Protocol Suite] for examples of abstraction layers used in communications technologies.&lt;br /&gt;
&lt;br /&gt;
At the lowest layer, you find the ''wire''; the physical means of transmitting information over distance. For our purposes, we should not limit ourselves to a single wire. Instead, we should allow the use of multiple wires, user-selectable, but never more than one at a time.&lt;br /&gt;
&lt;br /&gt;
The following layers get more and more generic and abstract, until you reach the highest layer which represents what the application sees and interacts with. This would be the &amp;quot;protocol&amp;quot; itself.&lt;br /&gt;
&lt;br /&gt;
So let's break these components down, hypothetically, and get into some details, ordered lowest layer first:&lt;br /&gt;
&lt;br /&gt;
# '''Physical layer''': Some examples of wires to support include LAN (Ethernet/WiFi), Wireless (Bluetooth), RS-232 (serial port, USB serial port), Inter-Process Communication (Domain Sockets? DBUS?)&lt;br /&gt;
# '''Transport layer''': Some examples of transport protocols include TCP/IP, UDP/IP (LAN, Domain Sockets), UART (RS-232), IPC-specific (DBUS)&lt;br /&gt;
# '''Application layer''': A library (or similar service, E.G. a daemon) to tie all transport layers into a single API that, to the application, looks like one simple interface to connect and send/receive data. The library/daemon will have to handle the transport-specific details behind-the-scenes.&lt;br /&gt;
&lt;br /&gt;
Thinking about this led to a conundrum; If we support multiple wires, we have to support multiple transport protocols which are compatible with those wires. And if we support multiple transport protocols, we have to know which one our target implements. To make the API as simple as possible, we must not force clients to choose from configurable options (for a bad example) that requires a large degree of changes for each different type of connection made. How do we simplify the API so that a user can just plain connect without doing any pre-setup work?&lt;br /&gt;
&lt;br /&gt;
Answer: The [http://en.wikipedia.org/wiki/URI_scheme URI scheme]. The unfortunate downside to this solution is that it is undesired to use URI schemes without registering them with IANA. However, an argument could be made that these schemes would not be used for general network/internet communication. A few popular examples of similarly non-networked schemes are the file: and about: URI schemes. (The exception here is that at least one physical layer (LAN) could be used for over-the-internet communication; but this has great benefits in its own right.)&lt;br /&gt;
&lt;br /&gt;
===Example URI Schemes===&lt;br /&gt;
&lt;br /&gt;
The following table represents some examples of how URI schemes could be used as debugger protocols:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp://192.168.1.20/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | TCP/IP to remote host 192.168.1.20 on a pre-defined default port&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+udp://192.168.1.20:9424/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UDP/IP to remote host 192.168.1.20 on port 9424&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+usb://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | USB (SRDP-compatible devices) on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+uart://localhost:3/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UART COM port 3 on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+dbus://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | DBUS IPC on localhost&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'srdp' prefix on these examples is to specify the 'Scalable Remote Debugger Protocol.' The + and suffix defines an additional layer (or protocol) below SRDP.&lt;br /&gt;
&lt;br /&gt;
The latter three examples look a bit odd with localhost being the destination, but this is necessary, since the localhost ''is'' the destination for hosting the UART RS-232 port, USB port, and IPC interface. Using non-loopback interfaces (IP addresses outside of the local machine) with these protocols should be undefined, unless there is evidence that connecting to RS-232/USB/IPC interfaces on other machines across a network is practical and plausible.&lt;br /&gt;
&lt;br /&gt;
===Simplified Configuration===&lt;br /&gt;
&lt;br /&gt;
These URI schemes give a very simple and elegant solution to the concerns they address. No longer will you be stuck with complicated configuration settings like the example below (upper left group box) ... and this is not an incredibly complex configuration dialog, as it is; instead, connecting to ANY low-level debugger in the world will be as simple as typing a URL.&lt;br /&gt;
&lt;br /&gt;
Example of what '''''not''''' to do:&lt;br /&gt;
&lt;br /&gt;
[[Image:Gscc_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Operation Groups===&lt;br /&gt;
&lt;br /&gt;
The protocol is defined as a set of usable &amp;quot;requests&amp;quot; (AKA &amp;quot;operations&amp;quot; or &amp;quot;commands&amp;quot;) requested by the client to the debugger, or vice-versa. Operations should be grouped according to a specific metric. The metric I've chosen is hardware (architecture) relationships. The table below shows an example of such groups (currently 6 in total) and example operations assigned to each group.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 1)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Diagnostics (Info, Ping/Pong, Reset, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 2)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | CPU handling (Register read/write, Arbitrary code execution, General CPU control, General process/thread control...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 3)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Memory handling (Read, Write, Address conversion, Hardware I/O, Cache control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 4)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Breakpoint handling (Add, Delete, Edit, Get, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 5)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Stream handling (stdin/stdout/stderr, Debugger-specific messages, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 6)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Vendor-specific (Custom command sets; should be discouraged unless absolutely necessary)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Proposal==&lt;br /&gt;
&lt;br /&gt;
This section defines a proposed specification which may be adopted as the &amp;quot;Scalable Remote Debugger Protocol&amp;quot;. It is considered a work in progress and is currently open for peer-review, meaning we are interested in receiving comments, criticisms, and suggestions.&lt;br /&gt;
&lt;br /&gt;
===Protocol Goals===&lt;br /&gt;
&lt;br /&gt;
Goals of the protocol include:&lt;br /&gt;
&lt;br /&gt;
# '''Client/server relationship''': Target (debuggee) acts as a server, quietly listening for any SRDP requests; User Interface acts as a client, making explicit requests to a listening server.&lt;br /&gt;
# '''Asynchronous requests''': A client must send requests without expecting an immediate response. A server accepting requests may not respond immediately to those requests.&lt;br /&gt;
# '''Scalable''': The data structure (format) used in the protocol must be adaptable to the future; The structure must be as forgiving and dynamic as possible, avoiding fixed contents (except where absolutely necessary) and allowing for [non-mission-critical] non-standard contents.&lt;br /&gt;
# '''Easy to implement''': Basic features of the protocol should be easy to implement from an API point-of-view, as well as having a small memory footprint; the protocol must be usable on small embedded machines with few resources.&lt;br /&gt;
# '''Robust''': Ambiguity should be kept to a minimum in all aspects of the protocol; every bit transferred should have a useful meaning.&lt;br /&gt;
# '''Easy to debug''': A debugger protocol that cannot itself be debugged (observed and verified to work as expected) is a failure in and of itself. For this reason, the protocol should be human-readable in its most basic form.&lt;br /&gt;
&lt;br /&gt;
===Underlying Protocols===&lt;br /&gt;
&lt;br /&gt;
There are no reservations on any underlying protocols (protocols used to move data from the client to the server, and back again -- SRDP is not one of these protocols). The only requirement is that they provide hand-shaking (transmission control), sequential ordering of packet data arrival, and data integrity checking. Some examples of suitable underlying protocols include [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/UDP/IP], and [http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART].&lt;br /&gt;
&lt;br /&gt;
The initial reference implementation will use TCP/IP for remote connections. For local-listening servers, the reference implementation will use UNIX Domain Sockets on UNIX-like operating systems, and Named Pipes on Windows.&lt;br /&gt;
&lt;br /&gt;
===Requests, Responses, Alerts===&lt;br /&gt;
&lt;br /&gt;
Packets are given different names depending on their transmission direction (client -&amp;gt; server, or server -&amp;gt; client) and intended recipient (server, specific client, or all clients).&lt;br /&gt;
&lt;br /&gt;
Response, requests, and alerts must have a unique identifier associated with them. This will allow clients and servers to stay in sync, knowing which responses are for which requests, for example.&lt;br /&gt;
&lt;br /&gt;
====Requests====&lt;br /&gt;
&lt;br /&gt;
A packet is called a request if it is from a client to the server. The name &amp;quot;request&amp;quot; comes from the idea that the client is requesting information or a specific action to be performed by the server.&lt;br /&gt;
&lt;br /&gt;
====Responses====&lt;br /&gt;
&lt;br /&gt;
Responses are packets from a server to a specific client. Responses are always sent in response to a request (hence the name). However, not all requests are required to send responses (which is why &amp;quot;requests&amp;quot; are not called &amp;quot;commands&amp;quot;). Responses are only sent to the client which initiated the specific request being handled.&lt;br /&gt;
&lt;br /&gt;
====Alerts====&lt;br /&gt;
&lt;br /&gt;
An alert is a special type of response (a packet from the server to clients); an alert is sent to all connected/listening clients. This is synonymous with network &amp;quot;broadcast&amp;quot; packets, and it useful for notifying all clients of information they might like to know.&lt;br /&gt;
&lt;br /&gt;
A few examples of information that all clients might like to know are:&lt;br /&gt;
&lt;br /&gt;
* Breakpoint hits&lt;br /&gt;
* Pausing/resuming execution&lt;br /&gt;
* Resets&lt;br /&gt;
* Debugging messages (log messages)&lt;br /&gt;
&lt;br /&gt;
Not all alerts are initiated by requests from clients, but most will be. Log messages are typically spewed by programs without explicit requests; SRDP can allow listening for and capturing these messages.&lt;br /&gt;
&lt;br /&gt;
====Commands====&lt;br /&gt;
&lt;br /&gt;
The all-encompassing term for requests, responses and alerts is &amp;quot;commands&amp;quot;. Any time a &amp;quot;command&amp;quot; is mentioned, it refers to any combination of requests, responses, or alerts.&lt;br /&gt;
&lt;br /&gt;
===Protocol Packet Data Structure===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;goals&amp;quot; section outlines the major features which formed the following data structure. Inspiration comes mainly from [http://en.wikipedia.org/wiki/JSON JSON], the JavaScript Object Notation. As JSON is a serialization [text format] of JavaScript objects, the SRDP data structure is a serialization of the data being transmitted.&lt;br /&gt;
&lt;br /&gt;
The structure also shares some inspiration from [http://en.wikipedia.org/wiki/Remote_procedure_call RPC]; An example is that your client may want to read work RAM from the target. The SRDP request for &amp;quot;read memory&amp;quot; is technically similar to remotely running a &amp;quot;read memory&amp;quot; function on the server, invoked by the client. For this reason, each SRDP packet contains one or more &amp;quot;arguments&amp;quot; which you could imagine are passed directly to a plain old function.&lt;br /&gt;
&lt;br /&gt;
Each packet is sent as a series of 8-bit bytes. Packets are broken down into a &amp;quot;request/response/alert&amp;quot; name (called a command), encapsulating a series of &amp;quot;arguments&amp;quot;. You can think of it like a C function call. The &amp;quot;info&amp;quot; command, for example, requests information about the target machine architecture; it requires no arguments. The info command looks like this, and is a complete and valid SRDP packet:&lt;br /&gt;
&lt;br /&gt;
  info()&lt;br /&gt;
&lt;br /&gt;
Each argument has a name (made of one or more characters: alpha-numeric, underscore (_), or hyphen (-). The argument name is followed by a colon (:) and then a single byte representing the data type of the argument, then an equals sign (=) and the argument's value. All arguments are separated with a comma (,).&lt;br /&gt;
&lt;br /&gt;
The argument syntax is similar to that of [http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]. In pseudo-form, it looks something like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:{type}={value}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Valid data types:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | {type}&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Name&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | n&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any positive integer, encoded as a [http://www.dlugosz.com/ZIP2/VLI.html VLI]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | s&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Signed Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any negative integer, encoded as a [http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement one's complement] VLI&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | f&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Floating Point Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any non-integer number, Infinity, or [http://en.wikipedia.org/wiki/NaN NaN], encoded as a null-terminated UTF-8 string, or null-terminated UTF-16 or UTF-32 string with BOM; To be decoded by [http://en.wikipedia.org/wiki/Scanf#Format_string_specifications sscanf]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | a&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob), preceded by a VLI to indicate the length of the array.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | c&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Compressed Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob) with [http://en.wikipedia.org/wiki/Run-length_encoding RLE] compression. See [[#Compressed Array Data Type]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | t&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Text&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Null-terminated UTF-8 string without [http://en.wikipedia.org/wiki/Byte-order_mark BOM], or null-terminated UTF-16 or UTF-32 string with BOM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some example arguments. (Please keep in mind that all of the argument names listed within this section are for demonstration purposes only, and are not recommended for reference purposes.)&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | msg:t=Hello, World!␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | num:n=□&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | pi:f=3.141592␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | ram_dump:a=□■■■■&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | my-compressed-data:c=□□■■■■□■□■■■&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
What the symbols mean:&lt;br /&gt;
&lt;br /&gt;
  ␀: Null-terminator&lt;br /&gt;
  □: VLI&lt;br /&gt;
  ■: Data byte&lt;br /&gt;
&lt;br /&gt;
====Compressed Array Data Type====&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; padding: 10px;&amp;quot; | '''''One suggestion is making this data-type optional, and changing this spec to use a standard library, like zlib. In this way, slow machines with few resources can adhere to the SRDP spec without wasting precious footprint space and computational power implementing such &amp;quot;heavy&amp;quot; libraries.&lt;br /&gt;
&lt;br /&gt;
Using a &amp;quot;heavy-weight&amp;quot; compression library will help achieve better compression ratios, but will add processing overhead. The added overhead may turn out to be an overall hindrance. For example, a memory editor might want to refresh a memory display as fast as possible (several times per second) within a small visible view-port window. This kind of editor will need to download the contents of memory within the visible range quickly. Using compression in a use-case like this is a good idea, but only if transferring the smaller packet can make up for the time required to compress and decompress the data.'''''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Compressed arrays are similar to the standard &amp;quot;Array&amp;quot; data type. The compressed array starts with a single VLI to represent the total data size of the value (e.g. the size of the compressed data, ''x''). The following data is a series of alternating raw data and RLE data.&lt;br /&gt;
&lt;br /&gt;
# '''Raw Data''': A VLI representing raw data size in bytes (''n''), followed by ''n'' bytes of actual data.&lt;br /&gt;
# '''RLE Data''': A VLI representing RLE data size in bytes (''n''), followed by a single byte to be repeated (''n'' + 4) times in the output.&lt;br /&gt;
&lt;br /&gt;
This series is repeated until there are no more bytes to be read from input (''x'' bytes of the argument value have been read).&lt;br /&gt;
&lt;br /&gt;
For the RLE compression to be useful (efficient) it must not be used for any less than 4 bytes (therefore, the VLI is said to be a &amp;quot;4-based&amp;quot; number). The number 4 is derived from the minimum overhead introduced by the serial alternation and VLIs; 1 VLI for RLE output length, 1 byte of RLE data, 1 VLI for raw data length.&lt;br /&gt;
&lt;br /&gt;
Thus, in order for the RLE to perform &amp;quot;compression&amp;quot;, the RLE output must be larger than the smallest sequence required to switch from raw data and back again. Some examples to illustrate, '''''bold-italic''''' bytes are for VLI &amp;quot;control sequences&amp;quot; (the data lengths specified above):&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 1'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 01&lt;br /&gt;
 &lt;br /&gt;
 Incorrectly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''&amp;lt;u&amp;gt;03&amp;lt;/u&amp;gt;''''' 00 '''''01''''' 01&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''08''''' 94 24 51 73 00 00 00 01&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 2'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''00''''' 00&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 3'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 00 00 00 00 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''00''''' '''''04''''' 00&lt;br /&gt;
&lt;br /&gt;
The reason the second line in example 1 above is &amp;quot;incorrectly&amp;quot; compressed is because the second VLI is expecting the length to be 0-based. If this was the case, you would be simply adding overhead to replace any bytes saved by the &amp;quot;compression&amp;quot;. For this reason, the &amp;quot;correct&amp;quot; way to compress the example is to use a single length of raw data. This example is non-compressible, and should not be sent as a compressed array data type.&lt;br /&gt;
&lt;br /&gt;
In the second example, the data can be compressed nicely, saving a byte overall (including compression overhead). Since this is the &amp;quot;correct&amp;quot; way to compress the data, it is using a 4-based VLI on the RLE Data: &amp;quot;'''''00'''''&amp;quot; means 4 bytes of output, &amp;quot;'''''01'''''&amp;quot; means 5 bytes, &amp;quot;'''''02'''''&amp;quot; means 6 bytes, etc.&lt;br /&gt;
&lt;br /&gt;
The third example shows how to compress a series of bytes that starts with repeating data, instead of non-repeating &amp;quot;raw data&amp;quot;. The first VLI of '''''00''''' means there is no raw data for output (this is required: compressed arrays always begin with the Raw Data, followed by RLE Data). The second VLI '''''04''''' is the length of the RLE Data; 8 bytes. Even if the non-compressed data was 4 bytes of &amp;quot;00&amp;quot;, the compressed array would still be only 3 bytes of total data, saving one byte. This helps explain the reasoning behind the 4-based VLI for RLE Data.&lt;br /&gt;
&lt;br /&gt;
====Object Data Type====&lt;br /&gt;
&lt;br /&gt;
The basic structure and data types shown so far are very powerful; your server can tell the client vast amounts of information, such as CPU architecture, memory maps, I/O maps, etc. with just a handful of arguments. However, grouping these arguments in a meaningful way may be difficult. You might be inclined to do some &amp;quot;mock&amp;quot; namespacing, like prefixing each CPU-related argument with &amp;quot;cpu_&amp;quot;. This is effective, but also slightly wasteful and error-prone.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;object&amp;quot; data type is designed to handle such situations. This data type allows an argument to be a container for other arguments. Its format looks like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:[...]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Where the set of ellipses denotes one or more &amp;quot;regular&amp;quot; arguments. Here is an example of what a &amp;quot;cpu&amp;quot; object might look like:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
(Note the white-space is for readability only; it is not meant to be transferred as part of the protocol data.)&lt;br /&gt;
&lt;br /&gt;
In this example, the &amp;quot;cpu&amp;quot; object contains two arguments: cpu.arch and cpu.name; both strings.&lt;br /&gt;
&lt;br /&gt;
But there are also times when you will want your server to send that same information for two [or more] CPU architectures on a single target. Some platforms may have multiple CPUs, each with its own individual set of resources (memory maps and the like), as well as shared resources between the CPUs. For this, the packet data structure needs a more advanced method of communicating these kinds of details.&lt;br /&gt;
&lt;br /&gt;
For this case, you can optionally create arrays of objects by including a comma (,) after the closing square bracket, followed by another series of arguments enclosed in their own square brackets, ''ad infinitum''. In other words, any leading object definitions without explicit names will be treated as additional array elements for the previously named object.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM7TDMI␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now our &amp;quot;cpu&amp;quot; object defines two CPUs: an ARM9 and ARM7, ready for Nintendo DS hacking. These arguments can be referenced as cpu[0].arch, cpu[0].name, cpu[1].arch, and cpu[1].name respectively.&lt;br /&gt;
&lt;br /&gt;
Objects can be arbitrarily complex, containing arrays of other objects. Here is an example of a simple memory map, containing Work RAM (read/write/execute) and ROM (read/execute) sections. The Work RAM section is broken into two distinct memory ranges. This is quite easily expressed:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;memory:[&lt;br /&gt;
:name:t=Work RAM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&amp;lt;br/&amp;gt;&lt;br /&gt;
:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RWX␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:name:t=ROM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RX␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Command Reference===&lt;br /&gt;
&lt;br /&gt;
'''''FIXME: WIP'''''&lt;br /&gt;
&lt;br /&gt;
====Requests====&lt;br /&gt;
&lt;br /&gt;
=====info()=====&lt;br /&gt;
Request information about the target machine architecture. The '''info()''' request is implied during connection: A response will be sent after a connection is successfully established. This allows clients to gather necessary information about the target during the connection phase, without explicitly making the request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Return values'':&lt;br /&gt;
&lt;br /&gt;
Must only return one of the following:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;sys&amp;lt;/u&amp;gt;''' (string):&amp;lt;br/&amp;gt;A shorthand for defining known machines (mostly video game systems).&amp;lt;br/&amp;gt;See below for supported values&lt;br /&gt;
* '''&amp;lt;u&amp;gt;machine&amp;lt;/u&amp;gt;''' (object):&amp;lt;br/&amp;gt;A longhand for defining the complete machine architecture.&amp;lt;br/&amp;gt;TODO: Specify all object elements and their meanings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The currently supported values for '''&amp;lt;u&amp;gt;sys&amp;lt;/u&amp;gt;''' are:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NES&amp;lt;/u&amp;gt;''': Nintendo Entertainment System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SNES&amp;lt;/u&amp;gt;''': Super Nintendo Entertainment System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;N64&amp;lt;/u&amp;gt;''': Nintendo 64&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGC&amp;lt;/u&amp;gt;''': Nintendo GameCube&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS1&amp;lt;/u&amp;gt;''': Sony Playstation&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS2&amp;lt;/u&amp;gt;''': Sony Playstation 2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Planned future support:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GB&amp;lt;/u&amp;gt;''': Nintendo GameBoy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GBC&amp;lt;/u&amp;gt;''': Nintendo GameBoy Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GBA&amp;lt;/u&amp;gt;''': Nintendo GameBoy Advance&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NDS&amp;lt;/u&amp;gt;''': Nintendo DS/DSi&lt;br /&gt;
* '''&amp;lt;u&amp;gt;VB&amp;lt;/u&amp;gt;''': Nintendo Virtual Boy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WII&amp;lt;/u&amp;gt;''': Nintendo Wii&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SMS&amp;lt;/u&amp;gt;''': Sega Master System&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SMD&amp;lt;/u&amp;gt;''': Sega Genesis/Mega Drive&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SCD&amp;lt;/u&amp;gt;''': Sega CD/Mega CD&lt;br /&gt;
* '''&amp;lt;u&amp;gt;32X&amp;lt;/u&amp;gt;''': Sega 32X&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GG&amp;lt;/u&amp;gt;''': Sega GameGear&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SAT&amp;lt;/u&amp;gt;''': Sega Saturn&lt;br /&gt;
* '''&amp;lt;u&amp;gt;DC&amp;lt;/u&amp;gt;''': Sega Dreamcast&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PSP&amp;lt;/u&amp;gt;''': Sony Playstation Portable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TGC&amp;lt;/u&amp;gt;''': Tiger Game.com&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Considering support &amp;quot;some day&amp;quot;:&lt;br /&gt;
* '''&amp;lt;u&amp;gt;3DO&amp;lt;/u&amp;gt;''': 3DO&lt;br /&gt;
* '''&amp;lt;u&amp;gt;A26&amp;lt;/u&amp;gt;''': Atari 2600&lt;br /&gt;
* '''&amp;lt;u&amp;gt;LYNX&amp;lt;/u&amp;gt;''': Atari Lynx/Lynx II&lt;br /&gt;
* '''&amp;lt;u&amp;gt;JAG&amp;lt;/u&amp;gt;''': Atari Jaguar&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WS&amp;lt;/u&amp;gt;''': Bandai Wonder Swan&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WSC&amp;lt;/u&amp;gt;''': Bandai Wonder Swan Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GP32&amp;lt;/u&amp;gt;''': GamePark 32&lt;br /&gt;
* '''&amp;lt;u&amp;gt;GP2X&amp;lt;/u&amp;gt;''': GamePark Holdings GP2X&lt;br /&gt;
* '''&amp;lt;u&amp;gt;WIZ&amp;lt;/u&amp;gt;''': GamePark Holdings GP2X Wiz&lt;br /&gt;
* '''&amp;lt;u&amp;gt;XBOX&amp;lt;/u&amp;gt;''': Microsoft XBox&lt;br /&gt;
* '''&amp;lt;u&amp;gt;X360&amp;lt;/u&amp;gt;''': Microsoft XBox 360&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TG16&amp;lt;/u&amp;gt;''': NEC TurboGrafx-16/PC Engine&lt;br /&gt;
* '''&amp;lt;u&amp;gt;TGCD&amp;lt;/u&amp;gt;''': NEC TurboGrafx-CD/PC Engine CD&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SGFX&amp;lt;/u&amp;gt;''': NEC SuperGrafx&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGEO&amp;lt;/u&amp;gt;''': Neo*Geo AES/MVS&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGP&amp;lt;/u&amp;gt;''': Neo*Geo Pocket&lt;br /&gt;
* '''&amp;lt;u&amp;gt;NGPC&amp;lt;/u&amp;gt;''': Neo*Geo Pocket Color&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PKMN&amp;lt;/u&amp;gt;''': Nintendo Pokémon Mini&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SGB&amp;lt;/u&amp;gt;''': Nintendo Super GameBoy&lt;br /&gt;
* '''&amp;lt;u&amp;gt;CDI&amp;lt;/u&amp;gt;''': Philips CD-i&lt;br /&gt;
* '''&amp;lt;u&amp;gt;PS3&amp;lt;/u&amp;gt;''': Sony Playstation 3&lt;br /&gt;
* '''&amp;lt;u&amp;gt;SV&amp;lt;/u&amp;gt;''': SuperVision&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Proposal Comments===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Protocol Goals&amp;quot; have lead much of the motivation for developing this proposal. This presents what seems to be several very strange choices, at first glance. The choice of representing floating point numbers as a string of text seems extremely odd, until you consider that using the target-native floating point data format would make no sense when sending that data to a remote client (which is most likely running on a different architecture, and may have totally different native floating point formats). In order to express floating points with arbitrary precision in a data format-agnostic way, it is necessary to use a non-native format like text.&lt;br /&gt;
&lt;br /&gt;
Another oddity in this spec is the use of VLIs (variable-length integers) and their affect on the rest of the format. The main purpose for using VLIs is address widths. Some architectures can express their full address range within a single byte. Others require up to 8 bytes for a full 64-bit address range. Future architectures are by no means limited to 64-bit address widths. For this very reason, it is necessary to scale down as well as up. A VLI can express an address in as little as a single byte, or scale upward to arbitrarily large numbers. This makes VLIs perfect for addressing requirements among any architecture.&lt;br /&gt;
&lt;br /&gt;
VLIs present their own issues, however. For example, expressing a negative number as a VLI is nearly incomprehensible. Some might be inclined to reserve one bit within a VLI to indicate signedness, but that's another bit that cannot be used to minimize VLI overhead. The overhead is additional bytes required to represent a full number in a VLI system. For example, it is common for numbers 0 - 127 to be contained entirely within a single byte, including the overhead. But numbers between 128 - 255 require an additional byte to include more VLI &amp;quot;header&amp;quot; information (used to extend VLIs into arbitrarily long numbers). This is counter-intuitive, where a single byte itself can hold numbers between 0 - 255. Adding an additional sign bit reduces the range of VLIs by half: a single byte can only encode numbers between 0 - 63.&lt;br /&gt;
&lt;br /&gt;
The solution is to use a different data type specifically for expressing negative numbers. The VLI is encoded just like a positive number, but when interpreting the VLI, it must be converted to a negative number by either subtracting from zero (0 - ''n'') or multiplying by negative one (''n'' * -1). This is referred to as a &amp;quot;one's complement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In general, the efficiency of a VLI is very static. That means, a number using 0 - 7 bits of data (for example, the number &amp;quot;0&amp;quot; uses 0 bits of data, and the number &amp;quot;64&amp;quot; [binary: 100000] uses 6 bits) can be encoded into a single byte, a number using 8 - 14 bits can be encoded into 2 bytes, a number using 15 - 21 bits can be encoded into 3 bytes, etc. See http://www.dlugosz.com/ZIP2/VLI.html for more information on the kind of VLI I am considering for this proposal.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=992</id>
		<title>Scalable Remote Debugger Protocol</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=992"/>
				<updated>2010-01-13T03:24:42Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Requests, Responses, Alerts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently serving as a reference to kick-start development of the universal debugger protocol which will be used by the [[Universal Debugger Project]] and hopefully many, many other debuggers and debugger interfaces in the years to come.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
These references are listed in order of relevance; most relevant first.&lt;br /&gt;
&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc909.txt RFC-909: Loader Debugger Protocol]&lt;br /&gt;
# [http://sourceware.org/gdb/download/onlinedocs/gdb_33.html GDB Remote Serial Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc643.txt RFC-643: Network Debugging Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/ien/ien158.txt IEN-158: XNET Debugging Protocol]&lt;br /&gt;
# [http://www.xdebug.org/docs-dbgp.php DBGp: A common debugger protocol for languages and debugger UI communication]&lt;br /&gt;
&lt;br /&gt;
The relevancy I've determined for this list is due to interest in these specs, as well as potential generic uses and protocol extension.&lt;br /&gt;
&lt;br /&gt;
RFC-909 is so far the closest thing I have found which resembles the general idea I have for a &amp;quot;Universal Debugger Protocol&amp;quot;. It's composed as a simple binary packet, it's extensible, and it's designed to be stacked on top of existing transport protocols such as TCP/IP. I doubt this exact spec will fit all of our needs, but it is certainly a good start.&lt;br /&gt;
&lt;br /&gt;
GDB provides a fairly popular protocol. This one is designed for serial communications, so it will work well with small embedded devices. But it could be complicated to extend while retaining its GDB friendliness.&lt;br /&gt;
&lt;br /&gt;
RFC-643 and IEN-158 are interesting only because they show that some experimentation on the ideas of remote debugging have been employed in the past. Unfortunately, these specs were designed for a specific architecture, and are of little practical use for our purposes.&lt;br /&gt;
&lt;br /&gt;
DBGp shows what a modern remote debugging protocol can look like; including modern XML syntax. The downside to this is that low-level debuggers in small embedded devices are unlikely to parse XML at all.&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
&lt;br /&gt;
This section represents my ([[User:Parasyte|Parasyte]]) own personal opinions and ideas, and should not be taken as advocacy for standardization.&lt;br /&gt;
&lt;br /&gt;
One of the main goals of developing a &amp;quot;universal&amp;quot; protocol for debugging is that it must be usable everywhere; in small embedded devices, and some of the most powerful machines in the world. This kind of flexibility must be designed around multiple layers of abstraction. See [http://en.wikipedia.org/wiki/OSI_Model OSI Model] and [http://en.wikipedia.org/wiki/Internet_Protocol_Suite Internet Protocol Suite] for examples of abstraction layers used in communications technologies.&lt;br /&gt;
&lt;br /&gt;
At the lowest layer, you find the ''wire''; the physical means of transmitting information over distance. For our purposes, we should not limit ourselves to a single wire. Instead, we should allow the use of multiple wires, user-selectable, but never more than one at a time.&lt;br /&gt;
&lt;br /&gt;
The following layers get more and more generic and abstract, until you reach the highest layer which represents what the application sees and interacts with. This would be the &amp;quot;protocol&amp;quot; itself.&lt;br /&gt;
&lt;br /&gt;
So let's break these components down, hypothetically, and get into some details, ordered lowest layer first:&lt;br /&gt;
&lt;br /&gt;
# '''Physical layer''': Some examples of wires to support include LAN (Ethernet/WiFi), Wireless (Bluetooth), RS-232 (serial port, USB serial port), Inter-Process Communication (Domain Sockets? DBUS?)&lt;br /&gt;
# '''Transport layer''': Some examples of transport protocols include TCP/IP, UDP/IP (LAN, Domain Sockets), UART (RS-232), IPC-specific (DBUS)&lt;br /&gt;
# '''Application layer''': A library (or similar service, E.G. a daemon) to tie all transport layers into a single API that, to the application, looks like one simple interface to connect and send/receive data. The library/daemon will have to handle the transport-specific details behind-the-scenes.&lt;br /&gt;
&lt;br /&gt;
Thinking about this led to a conundrum; If we support multiple wires, we have to support multiple transport protocols which are compatible with those wires. And if we support multiple transport protocols, we have to know which one our target implements. To make the API as simple as possible, we must not force clients to choose from configurable options (for a bad example) that requires a large degree of changes for each different type of connection made. How do we simplify the API so that a user can just plain connect without doing any pre-setup work?&lt;br /&gt;
&lt;br /&gt;
Answer: The [http://en.wikipedia.org/wiki/URI_scheme URI scheme]. The unfortunate downside to this solution is that it is undesired to use URI schemes without registering them with IANA. However, an argument could be made that these schemes would not be used for general network/internet communication. A few popular examples of similarly non-networked schemes are the file: and about: URI schemes. (The exception here is that at least one physical layer (LAN) could be used for over-the-internet communication; but this has great benefits in its own right.)&lt;br /&gt;
&lt;br /&gt;
===Example URI Schemes===&lt;br /&gt;
&lt;br /&gt;
The following table represents some examples of how URI schemes could be used as debugger protocols:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp://192.168.1.20/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | TCP/IP to remote host 192.168.1.20 on a pre-defined default port&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+udp://192.168.1.20:9424/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UDP/IP to remote host 192.168.1.20 on port 9424&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+usb://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | USB (SRDP-compatible devices) on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+uart://localhost:3/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UART COM port 3 on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+dbus://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | DBUS IPC on localhost&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'srdp' prefix on these examples is to specify the 'Scalable Remote Debugger Protocol.' The + and suffix defines an additional layer (or protocol) below SRDP.&lt;br /&gt;
&lt;br /&gt;
The latter three examples look a bit odd with localhost being the destination, but this is necessary, since the localhost ''is'' the destination for hosting the UART RS-232 port, USB port, and IPC interface. Using non-loopback interfaces (IP addresses outside of the local machine) with these protocols should be undefined, unless there is evidence that connecting to RS-232/USB/IPC interfaces on other machines across a network is practical and plausible.&lt;br /&gt;
&lt;br /&gt;
===Simplified Configuration===&lt;br /&gt;
&lt;br /&gt;
These URI schemes give a very simple and elegant solution to the concerns they address. No longer will you be stuck with complicated configuration settings like the example below (upper left group box) ... and this is not an incredibly complex configuration dialog, as it is; instead, connecting to ANY low-level debugger in the world will be as simple as typing a URL.&lt;br /&gt;
&lt;br /&gt;
Example of what '''''not''''' to do:&lt;br /&gt;
&lt;br /&gt;
[[Image:Gscc_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Operation Groups===&lt;br /&gt;
&lt;br /&gt;
The protocol is defined as a set of usable &amp;quot;requests&amp;quot; (AKA &amp;quot;operations&amp;quot; or &amp;quot;commands&amp;quot;) requested by the client to the debugger, or vice-versa. Operations should be grouped according to a specific metric. The metric I've chosen is hardware (architecture) relationships. The table below shows an example of such groups (currently 6 in total) and example operations assigned to each group.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 1)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Diagnostics (Info, Ping/Pong, Reset, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 2)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | CPU handling (Register read/write, Arbitrary code execution, General CPU control, General process/thread control...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 3)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Memory handling (Read, Write, Address conversion, Hardware I/O, Cache control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 4)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Breakpoint handling (Add, Delete, Edit, Get, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 5)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Stream handling (stdin/stdout/stderr, Debugger-specific messages, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 6)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Vendor-specific (Custom command sets; should be discouraged unless absolutely necessary)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Proposal==&lt;br /&gt;
&lt;br /&gt;
This section defines a proposed specification which may be adopted as the &amp;quot;Scalable Remote Debugger Protocol&amp;quot;. It is considered a work in progress and is currently open for peer-review, meaning we are interested in receiving comments, criticisms, and suggestions.&lt;br /&gt;
&lt;br /&gt;
===Protocol Goals===&lt;br /&gt;
&lt;br /&gt;
Goals of the protocol include:&lt;br /&gt;
&lt;br /&gt;
# '''Client/server relationship''': Target (debuggee) acts as a server, quietly listening for any SRDP requests; User Interface acts as a client, making explicit requests to a listening server.&lt;br /&gt;
# '''Asynchronous requests''': A client must send requests without expecting an immediate response. A server accepting requests may not respond immediately to those requests.&lt;br /&gt;
# '''Scalable''': The data structure (format) used in the protocol must be adaptable to the future; The structure must be as forgiving and dynamic as possible, avoiding fixed contents (except where absolutely necessary) and allowing for [non-mission-critical] non-standard contents.&lt;br /&gt;
# '''Easy to implement''': Basic features of the protocol should be easy to implement from an API point-of-view, as well as having a small memory footprint; the protocol must be usable on small embedded machines with few resources.&lt;br /&gt;
# '''Robust''': Ambiguity should be kept to a minimum in all aspects of the protocol; every bit transferred should have a useful meaning.&lt;br /&gt;
# '''Easy to debug''': A debugger protocol that cannot itself be debugged (observed and verified to work as expected) is a failure in and of itself. For this reason, the protocol should be human-readable in its most basic form.&lt;br /&gt;
&lt;br /&gt;
===Underlying Protocols===&lt;br /&gt;
&lt;br /&gt;
There are no reservations on any underlying protocols (protocols used to move data from the client to the server, and back again -- SRDP is not one of these protocols). The only requirement is that they provide hand-shaking (transmission control), sequential ordering of packet data arrival, and data integrity checking. Some examples of suitable underlying protocols include [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/UDP/IP], and [http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART].&lt;br /&gt;
&lt;br /&gt;
The initial reference implementation will use TCP/IP for remote connections. For local-listening servers, the reference implementation will use UNIX Domain Sockets on UNIX-like operating systems, and Named Pipes on Windows.&lt;br /&gt;
&lt;br /&gt;
===Requests, Responses, Alerts===&lt;br /&gt;
&lt;br /&gt;
Packets are given different names depending on their transmission direction (client -&amp;gt; server, or server -&amp;gt; client) and intended recipient (server, specific client, or all clients).&lt;br /&gt;
&lt;br /&gt;
Response, requests, and alerts must have a unique identifier associated with them. This will allow clients and servers to stay in sync, knowing which responses are for which requests, for example.&lt;br /&gt;
&lt;br /&gt;
====Requests====&lt;br /&gt;
&lt;br /&gt;
A packet is called a request if it is from a client to the server. The name &amp;quot;request&amp;quot; comes from the idea that the client is requesting information or a specific action to be performed by the server.&lt;br /&gt;
&lt;br /&gt;
====Responses====&lt;br /&gt;
&lt;br /&gt;
Responses are packets from a server to a specific client. Responses are always sent in response to a request (hence the name). However, not all requests are required to send responses (which is why &amp;quot;requests&amp;quot; are not called &amp;quot;commands&amp;quot;). Responses are only sent to the client which initiated the specific request being handled.&lt;br /&gt;
&lt;br /&gt;
====Alerts====&lt;br /&gt;
&lt;br /&gt;
An alert is a special type of response (a packet from the server to clients); an alert is sent to all connected/listening clients. This is synonymous with network &amp;quot;broadcast&amp;quot; packets, and it useful for notifying all clients of information they might like to know.&lt;br /&gt;
&lt;br /&gt;
A few examples of information that all clients might like to know are:&lt;br /&gt;
&lt;br /&gt;
* Breakpoint hits&lt;br /&gt;
* Pausing/resuming execution&lt;br /&gt;
* Resets&lt;br /&gt;
* Debugging messages (log messages)&lt;br /&gt;
&lt;br /&gt;
Not all alerts are initiated by requests from clients, but most will be. Log messages are typically spewed by programs without explicit requests; SRDP can allow listening for and capturing these messages.&lt;br /&gt;
&lt;br /&gt;
====Commands====&lt;br /&gt;
&lt;br /&gt;
The all-encompassing term for requests, responses and alerts is &amp;quot;commands&amp;quot;. Any time a &amp;quot;command&amp;quot; is mentioned, it refers to any combination of requests, responses, or alerts.&lt;br /&gt;
&lt;br /&gt;
===Protocol Packet Data Structure===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;goals&amp;quot; section outlines the major features which formed the following data structure. Inspiration comes mainly from [http://en.wikipedia.org/wiki/JSON JSON], the JavaScript Object Notation. As JSON is a serialization [text format] of JavaScript objects, the SRDP data structure is a serialization of the data being transmitted.&lt;br /&gt;
&lt;br /&gt;
The structure also shares some inspiration from [http://en.wikipedia.org/wiki/Remote_procedure_call RPC]; An example is that your client may want to read work RAM from the target. The SRDP request for &amp;quot;read memory&amp;quot; is technically similar to remotely running a &amp;quot;read memory&amp;quot; function on the server, invoked by the client. For this reason, each SRDP packet contains one or more &amp;quot;arguments&amp;quot; which you could imagine are passed directly to a plain old function.&lt;br /&gt;
&lt;br /&gt;
Each packet is sent as a series of 8-bit bytes. Packets are broken down into a &amp;quot;request/response/alert&amp;quot; name (called a command), encapsulating a series of &amp;quot;arguments&amp;quot;. You can think of it like a C function call. The &amp;quot;info&amp;quot; command, for example, requests information about the target machine architecture; it requires no arguments. The info command looks like this, and is a complete and valid SRDP packet:&lt;br /&gt;
&lt;br /&gt;
  info()&lt;br /&gt;
&lt;br /&gt;
Each argument has a name (made of one or more characters: alpha-numeric, underscore (_), or hyphen (-). The argument name is followed by a colon (:) and then a single byte representing the data type of the argument, then an equals sign (=) and the argument's value. All arguments are separated with a comma (,).&lt;br /&gt;
&lt;br /&gt;
The argument syntax is similar to that of [http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]. In pseudo-form, it looks something like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:{type}={value}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Valid data types:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | {type}&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Name&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | n&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any positive integer, encoded as a [http://www.dlugosz.com/ZIP2/VLI.html VLI]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | s&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Signed Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any negative integer, encoded as a [http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement one's complement] VLI&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | f&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Floating Point Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any non-integer number, Infinity, or [http://en.wikipedia.org/wiki/NaN NaN], encoded as a null-terminated UTF-8 string, or null-terminated UTF-16 or UTF-32 string with BOM; To be decoded by [http://en.wikipedia.org/wiki/Scanf#Format_string_specifications sscanf]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | a&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob), preceded by a VLI to indicate the length of the array.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | c&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Compressed Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob) with [http://en.wikipedia.org/wiki/Run-length_encoding RLE] compression. See [[#Compressed Array Data Type]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | t&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Text&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Null-terminated UTF-8 string without [http://en.wikipedia.org/wiki/Byte-order_mark BOM], or null-terminated UTF-16 or UTF-32 string with BOM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some example arguments. (Please keep in mind that all of the argument names listed within this section are for demonstration purposes only, and are not recommended for reference purposes.)&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | msg:t=Hello, World!␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | num:n=□&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | pi:f=3.141592␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | ram_dump:a=□■■■■&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | my-compressed-data:c=□□■■■■□■□■■■&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
What the symbols mean:&lt;br /&gt;
&lt;br /&gt;
  ␀: Null-terminator&lt;br /&gt;
  □: VLI&lt;br /&gt;
  ■: Data byte&lt;br /&gt;
&lt;br /&gt;
====Compressed Array Data Type====&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; padding: 10px;&amp;quot; | '''''One suggestion is making this data-type optional, and changing this spec to use a standard library, like zlib. In this way, slow machines with few resources can adhere to the SRDP spec without wasting precious footprint space and computational power implementing such &amp;quot;heavy&amp;quot; libraries.&lt;br /&gt;
&lt;br /&gt;
Using a &amp;quot;heavy-weight&amp;quot; compression library will help achieve better compression ratios, but will add processing overhead. The added overhead may turn out to be an overall hindrance. For example, a memory editor might want to refresh a memory display as fast as possible (several times per second) within a small visible view-port window. This kind of editor will need to download the contents of memory within the visible range quickly. Using compression in a use-case like this is a good idea, but only if transferring the smaller packet can make up for the time required to compress and decompress the data.'''''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Compressed arrays are similar to the standard &amp;quot;Array&amp;quot; data type. The compressed array starts with a single VLI to represent the total data size of the value (e.g. the size of the compressed data, ''x''). The following data is a series of alternating raw data and RLE data.&lt;br /&gt;
&lt;br /&gt;
# '''Raw Data''': A VLI representing raw data size in bytes (''n''), followed by ''n'' bytes of actual data.&lt;br /&gt;
# '''RLE Data''': A VLI representing RLE data size in bytes (''n''), followed by a single byte to be repeated (''n'' + 4) times in the output.&lt;br /&gt;
&lt;br /&gt;
This series is repeated until there are no more bytes to be read from input (''x'' bytes of the argument value have been read).&lt;br /&gt;
&lt;br /&gt;
For the RLE compression to be useful (efficient) it must not be used for any less than 4 bytes (therefore, the VLI is said to be a &amp;quot;4-based&amp;quot; number). The number 4 is derived from the minimum overhead introduced by the serial alternation and VLIs; 1 VLI for RLE output length, 1 byte of RLE data, 1 VLI for raw data length.&lt;br /&gt;
&lt;br /&gt;
Thus, in order for the RLE to perform &amp;quot;compression&amp;quot;, the RLE output must be larger than the smallest sequence required to switch from raw data and back again. Some examples to illustrate, '''''bold-italic''''' bytes are for VLI &amp;quot;control sequences&amp;quot; (the data lengths specified above):&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 1'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 01&lt;br /&gt;
 &lt;br /&gt;
 Incorrectly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''&amp;lt;u&amp;gt;03&amp;lt;/u&amp;gt;''''' 00 '''''01''''' 01&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''08''''' 94 24 51 73 00 00 00 01&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 2'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''00''''' 00&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 3'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 00 00 00 00 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''00''''' '''''04''''' 00&lt;br /&gt;
&lt;br /&gt;
The reason the second line in example 1 above is &amp;quot;incorrectly&amp;quot; compressed is because the second VLI is expecting the length to be 0-based. If this was the case, you would be simply adding overhead to replace any bytes saved by the &amp;quot;compression&amp;quot;. For this reason, the &amp;quot;correct&amp;quot; way to compress the example is to use a single length of raw data. This example is non-compressible, and should not be sent as a compressed array data type.&lt;br /&gt;
&lt;br /&gt;
In the second example, the data can be compressed nicely, saving a byte overall (including compression overhead). Since this is the &amp;quot;correct&amp;quot; way to compress the data, it is using a 4-based VLI on the RLE Data: &amp;quot;'''''00'''''&amp;quot; means 4 bytes of output, &amp;quot;'''''01'''''&amp;quot; means 5 bytes, &amp;quot;'''''02'''''&amp;quot; means 6 bytes, etc.&lt;br /&gt;
&lt;br /&gt;
The third example shows how to compress a series of bytes that starts with repeating data, instead of non-repeating &amp;quot;raw data&amp;quot;. The first VLI of '''''00''''' means there is no raw data for output (this is required: compressed arrays always begin with the Raw Data, followed by RLE Data). The second VLI '''''04''''' is the length of the RLE Data; 8 bytes. Even if the non-compressed data was 4 bytes of &amp;quot;00&amp;quot;, the compressed array would still be only 3 bytes of total data, saving one byte. This helps explain the reasoning behind the 4-based VLI for RLE Data.&lt;br /&gt;
&lt;br /&gt;
====Object Data Type====&lt;br /&gt;
&lt;br /&gt;
The basic structure and data types shown so far are very powerful; your server can tell the client vast amounts of information, such as CPU architecture, memory maps, I/O maps, etc. with just a handful of arguments. However, grouping these arguments in a meaningful way may be difficult. You might be inclined to do some &amp;quot;mock&amp;quot; namespacing, like prefixing each CPU-related argument with &amp;quot;cpu_&amp;quot;. This is effective, but also slightly wasteful and error-prone.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;object&amp;quot; data type is designed to handle such situations. This data type allows an argument to be a container for other arguments. Its format looks like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:[...]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Where the set of ellipses denotes one or more &amp;quot;regular&amp;quot; arguments. Here is an example of what a &amp;quot;cpu&amp;quot; object might look like:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
(Note the white-space is for readability only; it is not meant to be transferred as part of the protocol data.)&lt;br /&gt;
&lt;br /&gt;
In this example, the &amp;quot;cpu&amp;quot; object contains two arguments: cpu.arch and cpu.name; both strings.&lt;br /&gt;
&lt;br /&gt;
But there are also times when you will want your server to send that same information for two [or more] CPU architectures on a single target. Some platforms may have multiple CPUs, each with its own individual set of resources (memory maps and the like), as well as shared resources between the CPUs. For this, the packet data structure needs a more advanced method of communicating these kinds of details.&lt;br /&gt;
&lt;br /&gt;
For this case, you can optionally create arrays of objects by including a comma (,) after the closing square bracket, followed by another series of arguments enclosed in their own square brackets, ''ad infinitum''. In other words, any leading object definitions without explicit names will be treated as additional array elements for the previously named object.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM7TDMI␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now our &amp;quot;cpu&amp;quot; object defines two CPUs: an ARM9 and ARM7, ready for Nintendo DS hacking. These arguments can be referenced as cpu[0].arch, cpu[0].name, cpu[1].arch, and cpu[1].name respectively.&lt;br /&gt;
&lt;br /&gt;
Objects can be arbitrarily complex, containing arrays of other objects. Here is an example of a simple memory map, containing Work RAM (read/write/execute) and ROM (read/execute) sections. The Work RAM section is broken into two distinct memory ranges. This is quite easily expressed:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;memory:[&lt;br /&gt;
:name:t=Work RAM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&amp;lt;br/&amp;gt;&lt;br /&gt;
:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RWX␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:name:t=ROM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RX␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comments===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Protocol Goals&amp;quot; have lead much of the motivation for developing this proposal. This presents what seems to be several very strange choices, at first glance. The choice of representing floating point numbers as a string of text seems extremely odd, until you consider that using the target-native floating point data format would make no sense when sending that data to a remote client (which is most likely running on a different architecture, and may have totally different native floating point formats). In order to express floating points with arbitrary precision in a data format-agnostic way, it is necessary to use a non-native format like text.&lt;br /&gt;
&lt;br /&gt;
Another oddity in this spec is the use of VLIs (variable-length integers) and their affect on the rest of the format. The main purpose for using VLIs is address widths. Some architectures can express their full address range within a single byte. Others require up to 8 bytes for a full 64-bit address range. Future architectures are by no means limited to 64-bit address widths. For this very reason, it is necessary to scale down as well as up. A VLI can express an address in as little as a single byte, or scale upward to arbitrarily large numbers. This makes VLIs perfect for addressing requirements among any architecture.&lt;br /&gt;
&lt;br /&gt;
VLIs present their own issues, however. For example, expressing a negative number as a VLI is nearly incomprehensible. Some might be inclined to reserve one bit within a VLI to indicate signedness, but that's another bit that cannot be used to minimize VLI overhead. The overhead is additional bytes required to represent a full number in a VLI system. For example, it is common for numbers 0 - 127 to be contained entirely within a single byte, including the overhead. But numbers between 128 - 255 require an additional byte to include more VLI &amp;quot;header&amp;quot; information (used to extend VLIs into arbitrarily long numbers). This is counter-intuitive, where a single byte itself can hold numbers between 0 - 255. Adding an additional sign bit reduces the range of VLIs by half: a single byte can only encode numbers between 0 - 63.&lt;br /&gt;
&lt;br /&gt;
The solution is to use a different data type specifically for expressing negative numbers. The VLI is encoded just like a positive number, but when interpreting the VLI, it must be converted to a negative number by either subtracting from zero (0 - ''n'') or multiplying by negative one (''n'' * -1). This is referred to as a &amp;quot;one's complement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In general, the efficiency of a VLI is very static. That means, a number using 0 - 7 bits of data (for example, the number &amp;quot;0&amp;quot; uses 0 bits of data, and the number &amp;quot;64&amp;quot; [binary: 100000] uses 6 bits) can be encoded into a single byte, a number using 8 - 14 bits can be encoded into 2 bytes, a number using 15 - 21 bits can be encoded into 3 bytes, etc. See http://www.dlugosz.com/ZIP2/VLI.html for more information on the kind of VLI I am considering for this proposal.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=991</id>
		<title>Scalable Remote Debugger Protocol</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=991"/>
				<updated>2010-01-13T03:21:40Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Underlying Protocols */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently serving as a reference to kick-start development of the universal debugger protocol which will be used by the [[Universal Debugger Project]] and hopefully many, many other debuggers and debugger interfaces in the years to come.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
These references are listed in order of relevance; most relevant first.&lt;br /&gt;
&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc909.txt RFC-909: Loader Debugger Protocol]&lt;br /&gt;
# [http://sourceware.org/gdb/download/onlinedocs/gdb_33.html GDB Remote Serial Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc643.txt RFC-643: Network Debugging Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/ien/ien158.txt IEN-158: XNET Debugging Protocol]&lt;br /&gt;
# [http://www.xdebug.org/docs-dbgp.php DBGp: A common debugger protocol for languages and debugger UI communication]&lt;br /&gt;
&lt;br /&gt;
The relevancy I've determined for this list is due to interest in these specs, as well as potential generic uses and protocol extension.&lt;br /&gt;
&lt;br /&gt;
RFC-909 is so far the closest thing I have found which resembles the general idea I have for a &amp;quot;Universal Debugger Protocol&amp;quot;. It's composed as a simple binary packet, it's extensible, and it's designed to be stacked on top of existing transport protocols such as TCP/IP. I doubt this exact spec will fit all of our needs, but it is certainly a good start.&lt;br /&gt;
&lt;br /&gt;
GDB provides a fairly popular protocol. This one is designed for serial communications, so it will work well with small embedded devices. But it could be complicated to extend while retaining its GDB friendliness.&lt;br /&gt;
&lt;br /&gt;
RFC-643 and IEN-158 are interesting only because they show that some experimentation on the ideas of remote debugging have been employed in the past. Unfortunately, these specs were designed for a specific architecture, and are of little practical use for our purposes.&lt;br /&gt;
&lt;br /&gt;
DBGp shows what a modern remote debugging protocol can look like; including modern XML syntax. The downside to this is that low-level debuggers in small embedded devices are unlikely to parse XML at all.&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
&lt;br /&gt;
This section represents my ([[User:Parasyte|Parasyte]]) own personal opinions and ideas, and should not be taken as advocacy for standardization.&lt;br /&gt;
&lt;br /&gt;
One of the main goals of developing a &amp;quot;universal&amp;quot; protocol for debugging is that it must be usable everywhere; in small embedded devices, and some of the most powerful machines in the world. This kind of flexibility must be designed around multiple layers of abstraction. See [http://en.wikipedia.org/wiki/OSI_Model OSI Model] and [http://en.wikipedia.org/wiki/Internet_Protocol_Suite Internet Protocol Suite] for examples of abstraction layers used in communications technologies.&lt;br /&gt;
&lt;br /&gt;
At the lowest layer, you find the ''wire''; the physical means of transmitting information over distance. For our purposes, we should not limit ourselves to a single wire. Instead, we should allow the use of multiple wires, user-selectable, but never more than one at a time.&lt;br /&gt;
&lt;br /&gt;
The following layers get more and more generic and abstract, until you reach the highest layer which represents what the application sees and interacts with. This would be the &amp;quot;protocol&amp;quot; itself.&lt;br /&gt;
&lt;br /&gt;
So let's break these components down, hypothetically, and get into some details, ordered lowest layer first:&lt;br /&gt;
&lt;br /&gt;
# '''Physical layer''': Some examples of wires to support include LAN (Ethernet/WiFi), Wireless (Bluetooth), RS-232 (serial port, USB serial port), Inter-Process Communication (Domain Sockets? DBUS?)&lt;br /&gt;
# '''Transport layer''': Some examples of transport protocols include TCP/IP, UDP/IP (LAN, Domain Sockets), UART (RS-232), IPC-specific (DBUS)&lt;br /&gt;
# '''Application layer''': A library (or similar service, E.G. a daemon) to tie all transport layers into a single API that, to the application, looks like one simple interface to connect and send/receive data. The library/daemon will have to handle the transport-specific details behind-the-scenes.&lt;br /&gt;
&lt;br /&gt;
Thinking about this led to a conundrum; If we support multiple wires, we have to support multiple transport protocols which are compatible with those wires. And if we support multiple transport protocols, we have to know which one our target implements. To make the API as simple as possible, we must not force clients to choose from configurable options (for a bad example) that requires a large degree of changes for each different type of connection made. How do we simplify the API so that a user can just plain connect without doing any pre-setup work?&lt;br /&gt;
&lt;br /&gt;
Answer: The [http://en.wikipedia.org/wiki/URI_scheme URI scheme]. The unfortunate downside to this solution is that it is undesired to use URI schemes without registering them with IANA. However, an argument could be made that these schemes would not be used for general network/internet communication. A few popular examples of similarly non-networked schemes are the file: and about: URI schemes. (The exception here is that at least one physical layer (LAN) could be used for over-the-internet communication; but this has great benefits in its own right.)&lt;br /&gt;
&lt;br /&gt;
===Example URI Schemes===&lt;br /&gt;
&lt;br /&gt;
The following table represents some examples of how URI schemes could be used as debugger protocols:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp://192.168.1.20/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | TCP/IP to remote host 192.168.1.20 on a pre-defined default port&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+udp://192.168.1.20:9424/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UDP/IP to remote host 192.168.1.20 on port 9424&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+usb://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | USB (SRDP-compatible devices) on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+uart://localhost:3/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UART COM port 3 on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+dbus://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | DBUS IPC on localhost&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'srdp' prefix on these examples is to specify the 'Scalable Remote Debugger Protocol.' The + and suffix defines an additional layer (or protocol) below SRDP.&lt;br /&gt;
&lt;br /&gt;
The latter three examples look a bit odd with localhost being the destination, but this is necessary, since the localhost ''is'' the destination for hosting the UART RS-232 port, USB port, and IPC interface. Using non-loopback interfaces (IP addresses outside of the local machine) with these protocols should be undefined, unless there is evidence that connecting to RS-232/USB/IPC interfaces on other machines across a network is practical and plausible.&lt;br /&gt;
&lt;br /&gt;
===Simplified Configuration===&lt;br /&gt;
&lt;br /&gt;
These URI schemes give a very simple and elegant solution to the concerns they address. No longer will you be stuck with complicated configuration settings like the example below (upper left group box) ... and this is not an incredibly complex configuration dialog, as it is; instead, connecting to ANY low-level debugger in the world will be as simple as typing a URL.&lt;br /&gt;
&lt;br /&gt;
Example of what '''''not''''' to do:&lt;br /&gt;
&lt;br /&gt;
[[Image:Gscc_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Operation Groups===&lt;br /&gt;
&lt;br /&gt;
The protocol is defined as a set of usable &amp;quot;requests&amp;quot; (AKA &amp;quot;operations&amp;quot; or &amp;quot;commands&amp;quot;) requested by the client to the debugger, or vice-versa. Operations should be grouped according to a specific metric. The metric I've chosen is hardware (architecture) relationships. The table below shows an example of such groups (currently 6 in total) and example operations assigned to each group.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 1)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Diagnostics (Info, Ping/Pong, Reset, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 2)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | CPU handling (Register read/write, Arbitrary code execution, General CPU control, General process/thread control...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 3)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Memory handling (Read, Write, Address conversion, Hardware I/O, Cache control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 4)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Breakpoint handling (Add, Delete, Edit, Get, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 5)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Stream handling (stdin/stdout/stderr, Debugger-specific messages, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 6)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Vendor-specific (Custom command sets; should be discouraged unless absolutely necessary)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Proposal==&lt;br /&gt;
&lt;br /&gt;
This section defines a proposed specification which may be adopted as the &amp;quot;Scalable Remote Debugger Protocol&amp;quot;. It is considered a work in progress and is currently open for peer-review, meaning we are interested in receiving comments, criticisms, and suggestions.&lt;br /&gt;
&lt;br /&gt;
===Protocol Goals===&lt;br /&gt;
&lt;br /&gt;
Goals of the protocol include:&lt;br /&gt;
&lt;br /&gt;
# '''Client/server relationship''': Target (debuggee) acts as a server, quietly listening for any SRDP requests; User Interface acts as a client, making explicit requests to a listening server.&lt;br /&gt;
# '''Asynchronous requests''': A client must send requests without expecting an immediate response. A server accepting requests may not respond immediately to those requests.&lt;br /&gt;
# '''Scalable''': The data structure (format) used in the protocol must be adaptable to the future; The structure must be as forgiving and dynamic as possible, avoiding fixed contents (except where absolutely necessary) and allowing for [non-mission-critical] non-standard contents.&lt;br /&gt;
# '''Easy to implement''': Basic features of the protocol should be easy to implement from an API point-of-view, as well as having a small memory footprint; the protocol must be usable on small embedded machines with few resources.&lt;br /&gt;
# '''Robust''': Ambiguity should be kept to a minimum in all aspects of the protocol; every bit transferred should have a useful meaning.&lt;br /&gt;
# '''Easy to debug''': A debugger protocol that cannot itself be debugged (observed and verified to work as expected) is a failure in and of itself. For this reason, the protocol should be human-readable in its most basic form.&lt;br /&gt;
&lt;br /&gt;
===Underlying Protocols===&lt;br /&gt;
&lt;br /&gt;
There are no reservations on any underlying protocols (protocols used to move data from the client to the server, and back again -- SRDP is not one of these protocols). The only requirement is that they provide hand-shaking (transmission control), sequential ordering of packet data arrival, and data integrity checking. Some examples of suitable underlying protocols include [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/UDP/IP], and [http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART].&lt;br /&gt;
&lt;br /&gt;
The initial reference implementation will use TCP/IP for remote connections. For local-listening servers, the reference implementation will use UNIX Domain Sockets on UNIX-like operating systems, and Named Pipes on Windows.&lt;br /&gt;
&lt;br /&gt;
===Requests, Responses, Alerts===&lt;br /&gt;
&lt;br /&gt;
Packets are given different names depending on their transmission direction (client -&amp;gt; server, or server -&amp;gt; client) and intended recipient (server, specific client, or all clients).&lt;br /&gt;
&lt;br /&gt;
Response, requests, and alerts must have a unique identifier associated with them. This will allow clients and servers to stay in sync, knowing which responses are for which requests, for example.&lt;br /&gt;
&lt;br /&gt;
====Requests====&lt;br /&gt;
&lt;br /&gt;
A packet is called a request if it is from a client to the server. The name &amp;quot;request&amp;quot; comes from the idea that the client is requesting information or a specific action to be performed by the server.&lt;br /&gt;
&lt;br /&gt;
====Responses====&lt;br /&gt;
&lt;br /&gt;
Responses are packets from a server to a specific client. Responses are always sent in response to a request (hence the name). However, not all requests are required to send responses (which is why &amp;quot;requests&amp;quot; are not called &amp;quot;commands&amp;quot;). Responses are only sent to the client which initiated the specific request being handled.&lt;br /&gt;
&lt;br /&gt;
====Alerts====&lt;br /&gt;
&lt;br /&gt;
An alert is a special type of response (a packet from the server to clients); an alert is sent to all connected/listening clients. This is synonymous with network &amp;quot;broadcast&amp;quot; packets, and it useful for notifying all clients of information they might like to know.&lt;br /&gt;
&lt;br /&gt;
A few examples of information that all clients might like to know are:&lt;br /&gt;
&lt;br /&gt;
* Breakpoint hits&lt;br /&gt;
* Pausing/resuming execution&lt;br /&gt;
* Resets&lt;br /&gt;
* Debugging messages (log messages)&lt;br /&gt;
&lt;br /&gt;
Not all alerts are initiated by requests from clients, but most will be. Log messages are typically spewed by programs without explicit requests; SRDP can allow listening for and capturing these messages.&lt;br /&gt;
&lt;br /&gt;
===Protocol Packet Data Structure===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;goals&amp;quot; section outlines the major features which formed the following data structure. Inspiration comes mainly from [http://en.wikipedia.org/wiki/JSON JSON], the JavaScript Object Notation. As JSON is a serialization [text format] of JavaScript objects, the SRDP data structure is a serialization of the data being transmitted.&lt;br /&gt;
&lt;br /&gt;
The structure also shares some inspiration from [http://en.wikipedia.org/wiki/Remote_procedure_call RPC]; An example is that your client may want to read work RAM from the target. The SRDP request for &amp;quot;read memory&amp;quot; is technically similar to remotely running a &amp;quot;read memory&amp;quot; function on the server, invoked by the client. For this reason, each SRDP packet contains one or more &amp;quot;arguments&amp;quot; which you could imagine are passed directly to a plain old function.&lt;br /&gt;
&lt;br /&gt;
Each packet is sent as a series of 8-bit bytes. Packets are broken down into a &amp;quot;request/response/alert&amp;quot; name (called a command), encapsulating a series of &amp;quot;arguments&amp;quot;. You can think of it like a C function call. The &amp;quot;info&amp;quot; command, for example, requests information about the target machine architecture; it requires no arguments. The info command looks like this, and is a complete and valid SRDP packet:&lt;br /&gt;
&lt;br /&gt;
  info()&lt;br /&gt;
&lt;br /&gt;
Each argument has a name (made of one or more characters: alpha-numeric, underscore (_), or hyphen (-). The argument name is followed by a colon (:) and then a single byte representing the data type of the argument, then an equals sign (=) and the argument's value. All arguments are separated with a comma (,).&lt;br /&gt;
&lt;br /&gt;
The argument syntax is similar to that of [http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]. In pseudo-form, it looks something like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:{type}={value}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Valid data types:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | {type}&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Name&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | n&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any positive integer, encoded as a [http://www.dlugosz.com/ZIP2/VLI.html VLI]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | s&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Signed Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any negative integer, encoded as a [http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement one's complement] VLI&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | f&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Floating Point Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any non-integer number, Infinity, or [http://en.wikipedia.org/wiki/NaN NaN], encoded as a null-terminated UTF-8 string, or null-terminated UTF-16 or UTF-32 string with BOM; To be decoded by [http://en.wikipedia.org/wiki/Scanf#Format_string_specifications sscanf]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | a&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob), preceded by a VLI to indicate the length of the array.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | c&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Compressed Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob) with [http://en.wikipedia.org/wiki/Run-length_encoding RLE] compression. See [[#Compressed Array Data Type]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | t&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Text&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Null-terminated UTF-8 string without [http://en.wikipedia.org/wiki/Byte-order_mark BOM], or null-terminated UTF-16 or UTF-32 string with BOM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some example arguments. (Please keep in mind that all of the argument names listed within this section are for demonstration purposes only, and are not recommended for reference purposes.)&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | msg:t=Hello, World!␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | num:n=□&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | pi:f=3.141592␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | ram_dump:a=□■■■■&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | my-compressed-data:c=□□■■■■□■□■■■&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
What the symbols mean:&lt;br /&gt;
&lt;br /&gt;
  ␀: Null-terminator&lt;br /&gt;
  □: VLI&lt;br /&gt;
  ■: Data byte&lt;br /&gt;
&lt;br /&gt;
====Compressed Array Data Type====&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; padding: 10px;&amp;quot; | '''''One suggestion is making this data-type optional, and changing this spec to use a standard library, like zlib. In this way, slow machines with few resources can adhere to the SRDP spec without wasting precious footprint space and computational power implementing such &amp;quot;heavy&amp;quot; libraries.&lt;br /&gt;
&lt;br /&gt;
Using a &amp;quot;heavy-weight&amp;quot; compression library will help achieve better compression ratios, but will add processing overhead. The added overhead may turn out to be an overall hindrance. For example, a memory editor might want to refresh a memory display as fast as possible (several times per second) within a small visible view-port window. This kind of editor will need to download the contents of memory within the visible range quickly. Using compression in a use-case like this is a good idea, but only if transferring the smaller packet can make up for the time required to compress and decompress the data.'''''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Compressed arrays are similar to the standard &amp;quot;Array&amp;quot; data type. The compressed array starts with a single VLI to represent the total data size of the value (e.g. the size of the compressed data, ''x''). The following data is a series of alternating raw data and RLE data.&lt;br /&gt;
&lt;br /&gt;
# '''Raw Data''': A VLI representing raw data size in bytes (''n''), followed by ''n'' bytes of actual data.&lt;br /&gt;
# '''RLE Data''': A VLI representing RLE data size in bytes (''n''), followed by a single byte to be repeated (''n'' + 4) times in the output.&lt;br /&gt;
&lt;br /&gt;
This series is repeated until there are no more bytes to be read from input (''x'' bytes of the argument value have been read).&lt;br /&gt;
&lt;br /&gt;
For the RLE compression to be useful (efficient) it must not be used for any less than 4 bytes (therefore, the VLI is said to be a &amp;quot;4-based&amp;quot; number). The number 4 is derived from the minimum overhead introduced by the serial alternation and VLIs; 1 VLI for RLE output length, 1 byte of RLE data, 1 VLI for raw data length.&lt;br /&gt;
&lt;br /&gt;
Thus, in order for the RLE to perform &amp;quot;compression&amp;quot;, the RLE output must be larger than the smallest sequence required to switch from raw data and back again. Some examples to illustrate, '''''bold-italic''''' bytes are for VLI &amp;quot;control sequences&amp;quot; (the data lengths specified above):&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 1'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 01&lt;br /&gt;
 &lt;br /&gt;
 Incorrectly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''&amp;lt;u&amp;gt;03&amp;lt;/u&amp;gt;''''' 00 '''''01''''' 01&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''08''''' 94 24 51 73 00 00 00 01&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 2'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''00''''' 00&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 3'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 00 00 00 00 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''00''''' '''''04''''' 00&lt;br /&gt;
&lt;br /&gt;
The reason the second line in example 1 above is &amp;quot;incorrectly&amp;quot; compressed is because the second VLI is expecting the length to be 0-based. If this was the case, you would be simply adding overhead to replace any bytes saved by the &amp;quot;compression&amp;quot;. For this reason, the &amp;quot;correct&amp;quot; way to compress the example is to use a single length of raw data. This example is non-compressible, and should not be sent as a compressed array data type.&lt;br /&gt;
&lt;br /&gt;
In the second example, the data can be compressed nicely, saving a byte overall (including compression overhead). Since this is the &amp;quot;correct&amp;quot; way to compress the data, it is using a 4-based VLI on the RLE Data: &amp;quot;'''''00'''''&amp;quot; means 4 bytes of output, &amp;quot;'''''01'''''&amp;quot; means 5 bytes, &amp;quot;'''''02'''''&amp;quot; means 6 bytes, etc.&lt;br /&gt;
&lt;br /&gt;
The third example shows how to compress a series of bytes that starts with repeating data, instead of non-repeating &amp;quot;raw data&amp;quot;. The first VLI of '''''00''''' means there is no raw data for output (this is required: compressed arrays always begin with the Raw Data, followed by RLE Data). The second VLI '''''04''''' is the length of the RLE Data; 8 bytes. Even if the non-compressed data was 4 bytes of &amp;quot;00&amp;quot;, the compressed array would still be only 3 bytes of total data, saving one byte. This helps explain the reasoning behind the 4-based VLI for RLE Data.&lt;br /&gt;
&lt;br /&gt;
====Object Data Type====&lt;br /&gt;
&lt;br /&gt;
The basic structure and data types shown so far are very powerful; your server can tell the client vast amounts of information, such as CPU architecture, memory maps, I/O maps, etc. with just a handful of arguments. However, grouping these arguments in a meaningful way may be difficult. You might be inclined to do some &amp;quot;mock&amp;quot; namespacing, like prefixing each CPU-related argument with &amp;quot;cpu_&amp;quot;. This is effective, but also slightly wasteful and error-prone.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;object&amp;quot; data type is designed to handle such situations. This data type allows an argument to be a container for other arguments. Its format looks like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:[...]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Where the set of ellipses denotes one or more &amp;quot;regular&amp;quot; arguments. Here is an example of what a &amp;quot;cpu&amp;quot; object might look like:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
(Note the white-space is for readability only; it is not meant to be transferred as part of the protocol data.)&lt;br /&gt;
&lt;br /&gt;
In this example, the &amp;quot;cpu&amp;quot; object contains two arguments: cpu.arch and cpu.name; both strings.&lt;br /&gt;
&lt;br /&gt;
But there are also times when you will want your server to send that same information for two [or more] CPU architectures on a single target. Some platforms may have multiple CPUs, each with its own individual set of resources (memory maps and the like), as well as shared resources between the CPUs. For this, the packet data structure needs a more advanced method of communicating these kinds of details.&lt;br /&gt;
&lt;br /&gt;
For this case, you can optionally create arrays of objects by including a comma (,) after the closing square bracket, followed by another series of arguments enclosed in their own square brackets, ''ad infinitum''. In other words, any leading object definitions without explicit names will be treated as additional array elements for the previously named object.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM7TDMI␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now our &amp;quot;cpu&amp;quot; object defines two CPUs: an ARM9 and ARM7, ready for Nintendo DS hacking. These arguments can be referenced as cpu[0].arch, cpu[0].name, cpu[1].arch, and cpu[1].name respectively.&lt;br /&gt;
&lt;br /&gt;
Objects can be arbitrarily complex, containing arrays of other objects. Here is an example of a simple memory map, containing Work RAM (read/write/execute) and ROM (read/execute) sections. The Work RAM section is broken into two distinct memory ranges. This is quite easily expressed:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;memory:[&lt;br /&gt;
:name:t=Work RAM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&amp;lt;br/&amp;gt;&lt;br /&gt;
:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RWX␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:name:t=ROM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RX␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comments===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Protocol Goals&amp;quot; have lead much of the motivation for developing this proposal. This presents what seems to be several very strange choices, at first glance. The choice of representing floating point numbers as a string of text seems extremely odd, until you consider that using the target-native floating point data format would make no sense when sending that data to a remote client (which is most likely running on a different architecture, and may have totally different native floating point formats). In order to express floating points with arbitrary precision in a data format-agnostic way, it is necessary to use a non-native format like text.&lt;br /&gt;
&lt;br /&gt;
Another oddity in this spec is the use of VLIs (variable-length integers) and their affect on the rest of the format. The main purpose for using VLIs is address widths. Some architectures can express their full address range within a single byte. Others require up to 8 bytes for a full 64-bit address range. Future architectures are by no means limited to 64-bit address widths. For this very reason, it is necessary to scale down as well as up. A VLI can express an address in as little as a single byte, or scale upward to arbitrarily large numbers. This makes VLIs perfect for addressing requirements among any architecture.&lt;br /&gt;
&lt;br /&gt;
VLIs present their own issues, however. For example, expressing a negative number as a VLI is nearly incomprehensible. Some might be inclined to reserve one bit within a VLI to indicate signedness, but that's another bit that cannot be used to minimize VLI overhead. The overhead is additional bytes required to represent a full number in a VLI system. For example, it is common for numbers 0 - 127 to be contained entirely within a single byte, including the overhead. But numbers between 128 - 255 require an additional byte to include more VLI &amp;quot;header&amp;quot; information (used to extend VLIs into arbitrarily long numbers). This is counter-intuitive, where a single byte itself can hold numbers between 0 - 255. Adding an additional sign bit reduces the range of VLIs by half: a single byte can only encode numbers between 0 - 63.&lt;br /&gt;
&lt;br /&gt;
The solution is to use a different data type specifically for expressing negative numbers. The VLI is encoded just like a positive number, but when interpreting the VLI, it must be converted to a negative number by either subtracting from zero (0 - ''n'') or multiplying by negative one (''n'' * -1). This is referred to as a &amp;quot;one's complement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In general, the efficiency of a VLI is very static. That means, a number using 0 - 7 bits of data (for example, the number &amp;quot;0&amp;quot; uses 0 bits of data, and the number &amp;quot;64&amp;quot; [binary: 100000] uses 6 bits) can be encoded into a single byte, a number using 8 - 14 bits can be encoded into 2 bytes, a number using 15 - 21 bits can be encoded into 3 bytes, etc. See http://www.dlugosz.com/ZIP2/VLI.html for more information on the kind of VLI I am considering for this proposal.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=990</id>
		<title>Scalable Remote Debugger Protocol</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=990"/>
				<updated>2010-01-13T03:08:17Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Operation Groups */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently serving as a reference to kick-start development of the universal debugger protocol which will be used by the [[Universal Debugger Project]] and hopefully many, many other debuggers and debugger interfaces in the years to come.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
These references are listed in order of relevance; most relevant first.&lt;br /&gt;
&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc909.txt RFC-909: Loader Debugger Protocol]&lt;br /&gt;
# [http://sourceware.org/gdb/download/onlinedocs/gdb_33.html GDB Remote Serial Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc643.txt RFC-643: Network Debugging Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/ien/ien158.txt IEN-158: XNET Debugging Protocol]&lt;br /&gt;
# [http://www.xdebug.org/docs-dbgp.php DBGp: A common debugger protocol for languages and debugger UI communication]&lt;br /&gt;
&lt;br /&gt;
The relevancy I've determined for this list is due to interest in these specs, as well as potential generic uses and protocol extension.&lt;br /&gt;
&lt;br /&gt;
RFC-909 is so far the closest thing I have found which resembles the general idea I have for a &amp;quot;Universal Debugger Protocol&amp;quot;. It's composed as a simple binary packet, it's extensible, and it's designed to be stacked on top of existing transport protocols such as TCP/IP. I doubt this exact spec will fit all of our needs, but it is certainly a good start.&lt;br /&gt;
&lt;br /&gt;
GDB provides a fairly popular protocol. This one is designed for serial communications, so it will work well with small embedded devices. But it could be complicated to extend while retaining its GDB friendliness.&lt;br /&gt;
&lt;br /&gt;
RFC-643 and IEN-158 are interesting only because they show that some experimentation on the ideas of remote debugging have been employed in the past. Unfortunately, these specs were designed for a specific architecture, and are of little practical use for our purposes.&lt;br /&gt;
&lt;br /&gt;
DBGp shows what a modern remote debugging protocol can look like; including modern XML syntax. The downside to this is that low-level debuggers in small embedded devices are unlikely to parse XML at all.&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
&lt;br /&gt;
This section represents my ([[User:Parasyte|Parasyte]]) own personal opinions and ideas, and should not be taken as advocacy for standardization.&lt;br /&gt;
&lt;br /&gt;
One of the main goals of developing a &amp;quot;universal&amp;quot; protocol for debugging is that it must be usable everywhere; in small embedded devices, and some of the most powerful machines in the world. This kind of flexibility must be designed around multiple layers of abstraction. See [http://en.wikipedia.org/wiki/OSI_Model OSI Model] and [http://en.wikipedia.org/wiki/Internet_Protocol_Suite Internet Protocol Suite] for examples of abstraction layers used in communications technologies.&lt;br /&gt;
&lt;br /&gt;
At the lowest layer, you find the ''wire''; the physical means of transmitting information over distance. For our purposes, we should not limit ourselves to a single wire. Instead, we should allow the use of multiple wires, user-selectable, but never more than one at a time.&lt;br /&gt;
&lt;br /&gt;
The following layers get more and more generic and abstract, until you reach the highest layer which represents what the application sees and interacts with. This would be the &amp;quot;protocol&amp;quot; itself.&lt;br /&gt;
&lt;br /&gt;
So let's break these components down, hypothetically, and get into some details, ordered lowest layer first:&lt;br /&gt;
&lt;br /&gt;
# '''Physical layer''': Some examples of wires to support include LAN (Ethernet/WiFi), Wireless (Bluetooth), RS-232 (serial port, USB serial port), Inter-Process Communication (Domain Sockets? DBUS?)&lt;br /&gt;
# '''Transport layer''': Some examples of transport protocols include TCP/IP, UDP/IP (LAN, Domain Sockets), UART (RS-232), IPC-specific (DBUS)&lt;br /&gt;
# '''Application layer''': A library (or similar service, E.G. a daemon) to tie all transport layers into a single API that, to the application, looks like one simple interface to connect and send/receive data. The library/daemon will have to handle the transport-specific details behind-the-scenes.&lt;br /&gt;
&lt;br /&gt;
Thinking about this led to a conundrum; If we support multiple wires, we have to support multiple transport protocols which are compatible with those wires. And if we support multiple transport protocols, we have to know which one our target implements. To make the API as simple as possible, we must not force clients to choose from configurable options (for a bad example) that requires a large degree of changes for each different type of connection made. How do we simplify the API so that a user can just plain connect without doing any pre-setup work?&lt;br /&gt;
&lt;br /&gt;
Answer: The [http://en.wikipedia.org/wiki/URI_scheme URI scheme]. The unfortunate downside to this solution is that it is undesired to use URI schemes without registering them with IANA. However, an argument could be made that these schemes would not be used for general network/internet communication. A few popular examples of similarly non-networked schemes are the file: and about: URI schemes. (The exception here is that at least one physical layer (LAN) could be used for over-the-internet communication; but this has great benefits in its own right.)&lt;br /&gt;
&lt;br /&gt;
===Example URI Schemes===&lt;br /&gt;
&lt;br /&gt;
The following table represents some examples of how URI schemes could be used as debugger protocols:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp://192.168.1.20/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | TCP/IP to remote host 192.168.1.20 on a pre-defined default port&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+udp://192.168.1.20:9424/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UDP/IP to remote host 192.168.1.20 on port 9424&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+usb://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | USB (SRDP-compatible devices) on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+uart://localhost:3/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UART COM port 3 on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+dbus://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | DBUS IPC on localhost&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'srdp' prefix on these examples is to specify the 'Scalable Remote Debugger Protocol.' The + and suffix defines an additional layer (or protocol) below SRDP.&lt;br /&gt;
&lt;br /&gt;
The latter three examples look a bit odd with localhost being the destination, but this is necessary, since the localhost ''is'' the destination for hosting the UART RS-232 port, USB port, and IPC interface. Using non-loopback interfaces (IP addresses outside of the local machine) with these protocols should be undefined, unless there is evidence that connecting to RS-232/USB/IPC interfaces on other machines across a network is practical and plausible.&lt;br /&gt;
&lt;br /&gt;
===Simplified Configuration===&lt;br /&gt;
&lt;br /&gt;
These URI schemes give a very simple and elegant solution to the concerns they address. No longer will you be stuck with complicated configuration settings like the example below (upper left group box) ... and this is not an incredibly complex configuration dialog, as it is; instead, connecting to ANY low-level debugger in the world will be as simple as typing a URL.&lt;br /&gt;
&lt;br /&gt;
Example of what '''''not''''' to do:&lt;br /&gt;
&lt;br /&gt;
[[Image:Gscc_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Operation Groups===&lt;br /&gt;
&lt;br /&gt;
The protocol is defined as a set of usable &amp;quot;requests&amp;quot; (AKA &amp;quot;operations&amp;quot; or &amp;quot;commands&amp;quot;) requested by the client to the debugger, or vice-versa. Operations should be grouped according to a specific metric. The metric I've chosen is hardware (architecture) relationships. The table below shows an example of such groups (currently 6 in total) and example operations assigned to each group.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 1)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Diagnostics (Info, Ping/Pong, Reset, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 2)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | CPU handling (Register read/write, Arbitrary code execution, General CPU control, General process/thread control...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 3)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Memory handling (Read, Write, Address conversion, Hardware I/O, Cache control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 4)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Breakpoint handling (Add, Delete, Edit, Get, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 5)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Stream handling (stdin/stdout/stderr, Debugger-specific messages, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 6)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Vendor-specific (Custom command sets; should be discouraged unless absolutely necessary)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Proposal==&lt;br /&gt;
&lt;br /&gt;
This section defines a proposed specification which may be adopted as the &amp;quot;Scalable Remote Debugger Protocol&amp;quot;. It is considered a work in progress and is currently open for peer-review, meaning we are interested in receiving comments, criticisms, and suggestions.&lt;br /&gt;
&lt;br /&gt;
===Protocol Goals===&lt;br /&gt;
&lt;br /&gt;
Goals of the protocol include:&lt;br /&gt;
&lt;br /&gt;
# '''Client/server relationship''': Target (debuggee) acts as a server, quietly listening for any SRDP requests; User Interface acts as a client, making explicit requests to a listening server.&lt;br /&gt;
# '''Asynchronous requests''': A client must send requests without expecting an immediate response. A server accepting requests may not respond immediately to those requests.&lt;br /&gt;
# '''Scalable''': The data structure (format) used in the protocol must be adaptable to the future; The structure must be as forgiving and dynamic as possible, avoiding fixed contents (except where absolutely necessary) and allowing for [non-mission-critical] non-standard contents.&lt;br /&gt;
# '''Easy to implement''': Basic features of the protocol should be easy to implement from an API point-of-view, as well as having a small memory footprint; the protocol must be usable on small embedded machines with few resources.&lt;br /&gt;
# '''Robust''': Ambiguity should be kept to a minimum in all aspects of the protocol; every bit transferred should have a useful meaning.&lt;br /&gt;
# '''Easy to debug''': A debugger protocol that cannot itself be debugged (observed and verified to work as expected) is a failure in and of itself. For this reason, the protocol should be human-readable in its most basic form.&lt;br /&gt;
&lt;br /&gt;
===Underlying Protocols===&lt;br /&gt;
&lt;br /&gt;
There are no reservations on any underlying protocols (protocols used to move data from the client to the server, and back again -- SRDP is not one of these protocols). The only requirement is that they provide hand-shaking (transmission control), sequential ordering of packet data arrival, and data integrity checking. Some examples of suitable underlying protocols include [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/UDP/IP], and [http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART].&lt;br /&gt;
&lt;br /&gt;
The initial reference implementation will use TCP/IP for remote connections. For local-listening servers, the reference implementation will use UNIX Domain Sockets on UNIX-like operating systems, and Named Pipes on Windows.&lt;br /&gt;
&lt;br /&gt;
===Protocol Packet Data Structure===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;goals&amp;quot; section outlines the major features which formed the following data structure. Inspiration comes mainly from [http://en.wikipedia.org/wiki/JSON JSON], the JavaScript Object Notation. As JSON is a serialization [text format] of JavaScript objects, the SRDP data structure is a serialization of the data being transmitted.&lt;br /&gt;
&lt;br /&gt;
The structure also shares some inspiration from [http://en.wikipedia.org/wiki/Remote_procedure_call RPC]; An example is that your client may want to read work RAM from the target. The SRDP request for &amp;quot;read memory&amp;quot; is technically similar to remotely running a &amp;quot;read memory&amp;quot; function on the server, invoked by the client. For this reason, each SRDP packet contains one or more &amp;quot;arguments&amp;quot; which you could imagine are passed directly to a plain old function.&lt;br /&gt;
&lt;br /&gt;
Each packet is sent as a series of 8-bit bytes. Packets are broken down into a &amp;quot;request/response/alert&amp;quot; name (called a command), encapsulating a series of &amp;quot;arguments&amp;quot;. You can think of it like a C function call. The &amp;quot;info&amp;quot; command, for example, requests information about the target machine architecture; it requires no arguments. The info command looks like this, and is a complete and valid SRDP packet:&lt;br /&gt;
&lt;br /&gt;
  info()&lt;br /&gt;
&lt;br /&gt;
Each argument has a name (made of one or more characters: alpha-numeric, underscore (_), or hyphen (-). The argument name is followed by a colon (:) and then a single byte representing the data type of the argument, then an equals sign (=) and the argument's value. All arguments are separated with a comma (,).&lt;br /&gt;
&lt;br /&gt;
The argument syntax is similar to that of [http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]. In pseudo-form, it looks something like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:{type}={value}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Valid data types:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | {type}&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Name&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | n&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any positive integer, encoded as a [http://www.dlugosz.com/ZIP2/VLI.html VLI]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | s&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Signed Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any negative integer, encoded as a [http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement one's complement] VLI&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | f&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Floating Point Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any non-integer number, Infinity, or [http://en.wikipedia.org/wiki/NaN NaN], encoded as a null-terminated UTF-8 string, or null-terminated UTF-16 or UTF-32 string with BOM; To be decoded by [http://en.wikipedia.org/wiki/Scanf#Format_string_specifications sscanf]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | a&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob), preceded by a VLI to indicate the length of the array.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | c&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Compressed Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob) with [http://en.wikipedia.org/wiki/Run-length_encoding RLE] compression. See [[#Compressed Array Data Type]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | t&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Text&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Null-terminated UTF-8 string without [http://en.wikipedia.org/wiki/Byte-order_mark BOM], or null-terminated UTF-16 or UTF-32 string with BOM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some example arguments. (Please keep in mind that all of the argument names listed within this section are for demonstration purposes only, and are not recommended for reference purposes.)&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | msg:t=Hello, World!␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | num:n=□&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | pi:f=3.141592␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | ram_dump:a=□■■■■&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | my-compressed-data:c=□□■■■■□■□■■■&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
What the symbols mean:&lt;br /&gt;
&lt;br /&gt;
  ␀: Null-terminator&lt;br /&gt;
  □: VLI&lt;br /&gt;
  ■: Data byte&lt;br /&gt;
&lt;br /&gt;
====Compressed Array Data Type====&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; padding: 10px;&amp;quot; | '''''One suggestion is making this data-type optional, and changing this spec to use a standard library, like zlib. In this way, slow machines with few resources can adhere to the SRDP spec without wasting precious footprint space and computational power implementing such &amp;quot;heavy&amp;quot; libraries.&lt;br /&gt;
&lt;br /&gt;
Using a &amp;quot;heavy-weight&amp;quot; compression library will help achieve better compression ratios, but will add processing overhead. The added overhead may turn out to be an overall hindrance. For example, a memory editor might want to refresh a memory display as fast as possible (several times per second) within a small visible view-port window. This kind of editor will need to download the contents of memory within the visible range quickly. Using compression in a use-case like this is a good idea, but only if transferring the smaller packet can make up for the time required to compress and decompress the data.'''''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Compressed arrays are similar to the standard &amp;quot;Array&amp;quot; data type. The compressed array starts with a single VLI to represent the total data size of the value (e.g. the size of the compressed data, ''x''). The following data is a series of alternating raw data and RLE data.&lt;br /&gt;
&lt;br /&gt;
# '''Raw Data''': A VLI representing raw data size in bytes (''n''), followed by ''n'' bytes of actual data.&lt;br /&gt;
# '''RLE Data''': A VLI representing RLE data size in bytes (''n''), followed by a single byte to be repeated (''n'' + 4) times in the output.&lt;br /&gt;
&lt;br /&gt;
This series is repeated until there are no more bytes to be read from input (''x'' bytes of the argument value have been read).&lt;br /&gt;
&lt;br /&gt;
For the RLE compression to be useful (efficient) it must not be used for any less than 4 bytes (therefore, the VLI is said to be a &amp;quot;4-based&amp;quot; number). The number 4 is derived from the minimum overhead introduced by the serial alternation and VLIs; 1 VLI for RLE output length, 1 byte of RLE data, 1 VLI for raw data length.&lt;br /&gt;
&lt;br /&gt;
Thus, in order for the RLE to perform &amp;quot;compression&amp;quot;, the RLE output must be larger than the smallest sequence required to switch from raw data and back again. Some examples to illustrate, '''''bold-italic''''' bytes are for VLI &amp;quot;control sequences&amp;quot; (the data lengths specified above):&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 1'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 01&lt;br /&gt;
 &lt;br /&gt;
 Incorrectly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''&amp;lt;u&amp;gt;03&amp;lt;/u&amp;gt;''''' 00 '''''01''''' 01&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''08''''' 94 24 51 73 00 00 00 01&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 2'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''00''''' 00&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 3'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 00 00 00 00 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''00''''' '''''04''''' 00&lt;br /&gt;
&lt;br /&gt;
The reason the second line in example 1 above is &amp;quot;incorrectly&amp;quot; compressed is because the second VLI is expecting the length to be 0-based. If this was the case, you would be simply adding overhead to replace any bytes saved by the &amp;quot;compression&amp;quot;. For this reason, the &amp;quot;correct&amp;quot; way to compress the example is to use a single length of raw data. This example is non-compressible, and should not be sent as a compressed array data type.&lt;br /&gt;
&lt;br /&gt;
In the second example, the data can be compressed nicely, saving a byte overall (including compression overhead). Since this is the &amp;quot;correct&amp;quot; way to compress the data, it is using a 4-based VLI on the RLE Data: &amp;quot;'''''00'''''&amp;quot; means 4 bytes of output, &amp;quot;'''''01'''''&amp;quot; means 5 bytes, &amp;quot;'''''02'''''&amp;quot; means 6 bytes, etc.&lt;br /&gt;
&lt;br /&gt;
The third example shows how to compress a series of bytes that starts with repeating data, instead of non-repeating &amp;quot;raw data&amp;quot;. The first VLI of '''''00''''' means there is no raw data for output (this is required: compressed arrays always begin with the Raw Data, followed by RLE Data). The second VLI '''''04''''' is the length of the RLE Data; 8 bytes. Even if the non-compressed data was 4 bytes of &amp;quot;00&amp;quot;, the compressed array would still be only 3 bytes of total data, saving one byte. This helps explain the reasoning behind the 4-based VLI for RLE Data.&lt;br /&gt;
&lt;br /&gt;
====Object Data Type====&lt;br /&gt;
&lt;br /&gt;
The basic structure and data types shown so far are very powerful; your server can tell the client vast amounts of information, such as CPU architecture, memory maps, I/O maps, etc. with just a handful of arguments. However, grouping these arguments in a meaningful way may be difficult. You might be inclined to do some &amp;quot;mock&amp;quot; namespacing, like prefixing each CPU-related argument with &amp;quot;cpu_&amp;quot;. This is effective, but also slightly wasteful and error-prone.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;object&amp;quot; data type is designed to handle such situations. This data type allows an argument to be a container for other arguments. Its format looks like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:[...]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Where the set of ellipses denotes one or more &amp;quot;regular&amp;quot; arguments. Here is an example of what a &amp;quot;cpu&amp;quot; object might look like:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
(Note the white-space is for readability only; it is not meant to be transferred as part of the protocol data.)&lt;br /&gt;
&lt;br /&gt;
In this example, the &amp;quot;cpu&amp;quot; object contains two arguments: cpu.arch and cpu.name; both strings.&lt;br /&gt;
&lt;br /&gt;
But there are also times when you will want your server to send that same information for two [or more] CPU architectures on a single target. Some platforms may have multiple CPUs, each with its own individual set of resources (memory maps and the like), as well as shared resources between the CPUs. For this, the packet data structure needs a more advanced method of communicating these kinds of details.&lt;br /&gt;
&lt;br /&gt;
For this case, you can optionally create arrays of objects by including a comma (,) after the closing square bracket, followed by another series of arguments enclosed in their own square brackets, ''ad infinitum''. In other words, any leading object definitions without explicit names will be treated as additional array elements for the previously named object.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM7TDMI␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now our &amp;quot;cpu&amp;quot; object defines two CPUs: an ARM9 and ARM7, ready for Nintendo DS hacking. These arguments can be referenced as cpu[0].arch, cpu[0].name, cpu[1].arch, and cpu[1].name respectively.&lt;br /&gt;
&lt;br /&gt;
Objects can be arbitrarily complex, containing arrays of other objects. Here is an example of a simple memory map, containing Work RAM (read/write/execute) and ROM (read/execute) sections. The Work RAM section is broken into two distinct memory ranges. This is quite easily expressed:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;memory:[&lt;br /&gt;
:name:t=Work RAM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&amp;lt;br/&amp;gt;&lt;br /&gt;
:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RWX␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:name:t=ROM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RX␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comments===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Protocol Goals&amp;quot; have lead much of the motivation for developing this proposal. This presents what seems to be several very strange choices, at first glance. The choice of representing floating point numbers as a string of text seems extremely odd, until you consider that using the target-native floating point data format would make no sense when sending that data to a remote client (which is most likely running on a different architecture, and may have totally different native floating point formats). In order to express floating points with arbitrary precision in a data format-agnostic way, it is necessary to use a non-native format like text.&lt;br /&gt;
&lt;br /&gt;
Another oddity in this spec is the use of VLIs (variable-length integers) and their affect on the rest of the format. The main purpose for using VLIs is address widths. Some architectures can express their full address range within a single byte. Others require up to 8 bytes for a full 64-bit address range. Future architectures are by no means limited to 64-bit address widths. For this very reason, it is necessary to scale down as well as up. A VLI can express an address in as little as a single byte, or scale upward to arbitrarily large numbers. This makes VLIs perfect for addressing requirements among any architecture.&lt;br /&gt;
&lt;br /&gt;
VLIs present their own issues, however. For example, expressing a negative number as a VLI is nearly incomprehensible. Some might be inclined to reserve one bit within a VLI to indicate signedness, but that's another bit that cannot be used to minimize VLI overhead. The overhead is additional bytes required to represent a full number in a VLI system. For example, it is common for numbers 0 - 127 to be contained entirely within a single byte, including the overhead. But numbers between 128 - 255 require an additional byte to include more VLI &amp;quot;header&amp;quot; information (used to extend VLIs into arbitrarily long numbers). This is counter-intuitive, where a single byte itself can hold numbers between 0 - 255. Adding an additional sign bit reduces the range of VLIs by half: a single byte can only encode numbers between 0 - 63.&lt;br /&gt;
&lt;br /&gt;
The solution is to use a different data type specifically for expressing negative numbers. The VLI is encoded just like a positive number, but when interpreting the VLI, it must be converted to a negative number by either subtracting from zero (0 - ''n'') or multiplying by negative one (''n'' * -1). This is referred to as a &amp;quot;one's complement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In general, the efficiency of a VLI is very static. That means, a number using 0 - 7 bits of data (for example, the number &amp;quot;0&amp;quot; uses 0 bits of data, and the number &amp;quot;64&amp;quot; [binary: 100000] uses 6 bits) can be encoded into a single byte, a number using 8 - 14 bits can be encoded into 2 bytes, a number using 15 - 21 bits can be encoded into 3 bytes, etc. See http://www.dlugosz.com/ZIP2/VLI.html for more information on the kind of VLI I am considering for this proposal.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=989</id>
		<title>Scalable Remote Debugger Protocol</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=989"/>
				<updated>2010-01-13T03:06:54Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Operation Groups */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently serving as a reference to kick-start development of the universal debugger protocol which will be used by the [[Universal Debugger Project]] and hopefully many, many other debuggers and debugger interfaces in the years to come.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
These references are listed in order of relevance; most relevant first.&lt;br /&gt;
&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc909.txt RFC-909: Loader Debugger Protocol]&lt;br /&gt;
# [http://sourceware.org/gdb/download/onlinedocs/gdb_33.html GDB Remote Serial Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc643.txt RFC-643: Network Debugging Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/ien/ien158.txt IEN-158: XNET Debugging Protocol]&lt;br /&gt;
# [http://www.xdebug.org/docs-dbgp.php DBGp: A common debugger protocol for languages and debugger UI communication]&lt;br /&gt;
&lt;br /&gt;
The relevancy I've determined for this list is due to interest in these specs, as well as potential generic uses and protocol extension.&lt;br /&gt;
&lt;br /&gt;
RFC-909 is so far the closest thing I have found which resembles the general idea I have for a &amp;quot;Universal Debugger Protocol&amp;quot;. It's composed as a simple binary packet, it's extensible, and it's designed to be stacked on top of existing transport protocols such as TCP/IP. I doubt this exact spec will fit all of our needs, but it is certainly a good start.&lt;br /&gt;
&lt;br /&gt;
GDB provides a fairly popular protocol. This one is designed for serial communications, so it will work well with small embedded devices. But it could be complicated to extend while retaining its GDB friendliness.&lt;br /&gt;
&lt;br /&gt;
RFC-643 and IEN-158 are interesting only because they show that some experimentation on the ideas of remote debugging have been employed in the past. Unfortunately, these specs were designed for a specific architecture, and are of little practical use for our purposes.&lt;br /&gt;
&lt;br /&gt;
DBGp shows what a modern remote debugging protocol can look like; including modern XML syntax. The downside to this is that low-level debuggers in small embedded devices are unlikely to parse XML at all.&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
&lt;br /&gt;
This section represents my ([[User:Parasyte|Parasyte]]) own personal opinions and ideas, and should not be taken as advocacy for standardization.&lt;br /&gt;
&lt;br /&gt;
One of the main goals of developing a &amp;quot;universal&amp;quot; protocol for debugging is that it must be usable everywhere; in small embedded devices, and some of the most powerful machines in the world. This kind of flexibility must be designed around multiple layers of abstraction. See [http://en.wikipedia.org/wiki/OSI_Model OSI Model] and [http://en.wikipedia.org/wiki/Internet_Protocol_Suite Internet Protocol Suite] for examples of abstraction layers used in communications technologies.&lt;br /&gt;
&lt;br /&gt;
At the lowest layer, you find the ''wire''; the physical means of transmitting information over distance. For our purposes, we should not limit ourselves to a single wire. Instead, we should allow the use of multiple wires, user-selectable, but never more than one at a time.&lt;br /&gt;
&lt;br /&gt;
The following layers get more and more generic and abstract, until you reach the highest layer which represents what the application sees and interacts with. This would be the &amp;quot;protocol&amp;quot; itself.&lt;br /&gt;
&lt;br /&gt;
So let's break these components down, hypothetically, and get into some details, ordered lowest layer first:&lt;br /&gt;
&lt;br /&gt;
# '''Physical layer''': Some examples of wires to support include LAN (Ethernet/WiFi), Wireless (Bluetooth), RS-232 (serial port, USB serial port), Inter-Process Communication (Domain Sockets? DBUS?)&lt;br /&gt;
# '''Transport layer''': Some examples of transport protocols include TCP/IP, UDP/IP (LAN, Domain Sockets), UART (RS-232), IPC-specific (DBUS)&lt;br /&gt;
# '''Application layer''': A library (or similar service, E.G. a daemon) to tie all transport layers into a single API that, to the application, looks like one simple interface to connect and send/receive data. The library/daemon will have to handle the transport-specific details behind-the-scenes.&lt;br /&gt;
&lt;br /&gt;
Thinking about this led to a conundrum; If we support multiple wires, we have to support multiple transport protocols which are compatible with those wires. And if we support multiple transport protocols, we have to know which one our target implements. To make the API as simple as possible, we must not force clients to choose from configurable options (for a bad example) that requires a large degree of changes for each different type of connection made. How do we simplify the API so that a user can just plain connect without doing any pre-setup work?&lt;br /&gt;
&lt;br /&gt;
Answer: The [http://en.wikipedia.org/wiki/URI_scheme URI scheme]. The unfortunate downside to this solution is that it is undesired to use URI schemes without registering them with IANA. However, an argument could be made that these schemes would not be used for general network/internet communication. A few popular examples of similarly non-networked schemes are the file: and about: URI schemes. (The exception here is that at least one physical layer (LAN) could be used for over-the-internet communication; but this has great benefits in its own right.)&lt;br /&gt;
&lt;br /&gt;
===Example URI Schemes===&lt;br /&gt;
&lt;br /&gt;
The following table represents some examples of how URI schemes could be used as debugger protocols:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp://192.168.1.20/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | TCP/IP to remote host 192.168.1.20 on a pre-defined default port&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+udp://192.168.1.20:9424/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UDP/IP to remote host 192.168.1.20 on port 9424&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+usb://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | USB (SRDP-compatible devices) on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+uart://localhost:3/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UART COM port 3 on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+dbus://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | DBUS IPC on localhost&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'srdp' prefix on these examples is to specify the 'Scalable Remote Debugger Protocol.' The + and suffix defines an additional layer (or protocol) below SRDP.&lt;br /&gt;
&lt;br /&gt;
The latter three examples look a bit odd with localhost being the destination, but this is necessary, since the localhost ''is'' the destination for hosting the UART RS-232 port, USB port, and IPC interface. Using non-loopback interfaces (IP addresses outside of the local machine) with these protocols should be undefined, unless there is evidence that connecting to RS-232/USB/IPC interfaces on other machines across a network is practical and plausible.&lt;br /&gt;
&lt;br /&gt;
===Simplified Configuration===&lt;br /&gt;
&lt;br /&gt;
These URI schemes give a very simple and elegant solution to the concerns they address. No longer will you be stuck with complicated configuration settings like the example below (upper left group box) ... and this is not an incredibly complex configuration dialog, as it is; instead, connecting to ANY low-level debugger in the world will be as simple as typing a URL.&lt;br /&gt;
&lt;br /&gt;
Example of what '''''not''''' to do:&lt;br /&gt;
&lt;br /&gt;
[[Image:Gscc_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Operation Groups===&lt;br /&gt;
&lt;br /&gt;
The protocol is defined as a set of usable &amp;quot;requests&amp;quot; (AKA &amp;quot;operations&amp;quot; or &amp;quot;commands&amp;quot;) requested by the client to the debugger, or vice-versa. Operations should be grouped according to a specific metric. The metric I've chosen is hardware (architecture) relationships. The table below shows an example of such groups (currently 6 in total) and example operations assigned to each group.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 1)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Diagnostics (Connect, Disconnect, Info, Ping/Pong, Reset, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 2)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | CPU handling (Register read/write, Arbitrary code execution, General CPU control, General process/thread control...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 3)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Memory handling (Read, Write, Address conversion, Hardware I/O, Cache control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 4)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Breakpoint handling (Add, Delete, Edit, Get, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 5)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Stream handling (stdin/stdout/stderr, Debugger-specific messages, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 6)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Vendor-specific (Custom command sets; should be discouraged unless absolutely necessary)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Proposal==&lt;br /&gt;
&lt;br /&gt;
This section defines a proposed specification which may be adopted as the &amp;quot;Scalable Remote Debugger Protocol&amp;quot;. It is considered a work in progress and is currently open for peer-review, meaning we are interested in receiving comments, criticisms, and suggestions.&lt;br /&gt;
&lt;br /&gt;
===Protocol Goals===&lt;br /&gt;
&lt;br /&gt;
Goals of the protocol include:&lt;br /&gt;
&lt;br /&gt;
# '''Client/server relationship''': Target (debuggee) acts as a server, quietly listening for any SRDP requests; User Interface acts as a client, making explicit requests to a listening server.&lt;br /&gt;
# '''Asynchronous requests''': A client must send requests without expecting an immediate response. A server accepting requests may not respond immediately to those requests.&lt;br /&gt;
# '''Scalable''': The data structure (format) used in the protocol must be adaptable to the future; The structure must be as forgiving and dynamic as possible, avoiding fixed contents (except where absolutely necessary) and allowing for [non-mission-critical] non-standard contents.&lt;br /&gt;
# '''Easy to implement''': Basic features of the protocol should be easy to implement from an API point-of-view, as well as having a small memory footprint; the protocol must be usable on small embedded machines with few resources.&lt;br /&gt;
# '''Robust''': Ambiguity should be kept to a minimum in all aspects of the protocol; every bit transferred should have a useful meaning.&lt;br /&gt;
# '''Easy to debug''': A debugger protocol that cannot itself be debugged (observed and verified to work as expected) is a failure in and of itself. For this reason, the protocol should be human-readable in its most basic form.&lt;br /&gt;
&lt;br /&gt;
===Underlying Protocols===&lt;br /&gt;
&lt;br /&gt;
There are no reservations on any underlying protocols (protocols used to move data from the client to the server, and back again -- SRDP is not one of these protocols). The only requirement is that they provide hand-shaking (transmission control), sequential ordering of packet data arrival, and data integrity checking. Some examples of suitable underlying protocols include [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/UDP/IP], and [http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART].&lt;br /&gt;
&lt;br /&gt;
The initial reference implementation will use TCP/IP for remote connections. For local-listening servers, the reference implementation will use UNIX Domain Sockets on UNIX-like operating systems, and Named Pipes on Windows.&lt;br /&gt;
&lt;br /&gt;
===Protocol Packet Data Structure===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;goals&amp;quot; section outlines the major features which formed the following data structure. Inspiration comes mainly from [http://en.wikipedia.org/wiki/JSON JSON], the JavaScript Object Notation. As JSON is a serialization [text format] of JavaScript objects, the SRDP data structure is a serialization of the data being transmitted.&lt;br /&gt;
&lt;br /&gt;
The structure also shares some inspiration from [http://en.wikipedia.org/wiki/Remote_procedure_call RPC]; An example is that your client may want to read work RAM from the target. The SRDP request for &amp;quot;read memory&amp;quot; is technically similar to remotely running a &amp;quot;read memory&amp;quot; function on the server, invoked by the client. For this reason, each SRDP packet contains one or more &amp;quot;arguments&amp;quot; which you could imagine are passed directly to a plain old function.&lt;br /&gt;
&lt;br /&gt;
Each packet is sent as a series of 8-bit bytes. Packets are broken down into a &amp;quot;request/response/alert&amp;quot; name (called a command), encapsulating a series of &amp;quot;arguments&amp;quot;. You can think of it like a C function call. The &amp;quot;info&amp;quot; command, for example, requests information about the target machine architecture; it requires no arguments. The info command looks like this, and is a complete and valid SRDP packet:&lt;br /&gt;
&lt;br /&gt;
  info()&lt;br /&gt;
&lt;br /&gt;
Each argument has a name (made of one or more characters: alpha-numeric, underscore (_), or hyphen (-). The argument name is followed by a colon (:) and then a single byte representing the data type of the argument, then an equals sign (=) and the argument's value. All arguments are separated with a comma (,).&lt;br /&gt;
&lt;br /&gt;
The argument syntax is similar to that of [http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]. In pseudo-form, it looks something like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:{type}={value}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Valid data types:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | {type}&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Name&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | n&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any positive integer, encoded as a [http://www.dlugosz.com/ZIP2/VLI.html VLI]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | s&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Signed Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any negative integer, encoded as a [http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement one's complement] VLI&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | f&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Floating Point Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any non-integer number, Infinity, or [http://en.wikipedia.org/wiki/NaN NaN], encoded as a null-terminated UTF-8 string, or null-terminated UTF-16 or UTF-32 string with BOM; To be decoded by [http://en.wikipedia.org/wiki/Scanf#Format_string_specifications sscanf]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | a&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob), preceded by a VLI to indicate the length of the array.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | c&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Compressed Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob) with [http://en.wikipedia.org/wiki/Run-length_encoding RLE] compression. See [[#Compressed Array Data Type]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | t&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Text&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Null-terminated UTF-8 string without [http://en.wikipedia.org/wiki/Byte-order_mark BOM], or null-terminated UTF-16 or UTF-32 string with BOM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some example arguments. (Please keep in mind that all of the argument names listed within this section are for demonstration purposes only, and are not recommended for reference purposes.)&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | msg:t=Hello, World!␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | num:n=□&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | pi:f=3.141592␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | ram_dump:a=□■■■■&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | my-compressed-data:c=□□■■■■□■□■■■&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
What the symbols mean:&lt;br /&gt;
&lt;br /&gt;
  ␀: Null-terminator&lt;br /&gt;
  □: VLI&lt;br /&gt;
  ■: Data byte&lt;br /&gt;
&lt;br /&gt;
====Compressed Array Data Type====&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; padding: 10px;&amp;quot; | '''''One suggestion is making this data-type optional, and changing this spec to use a standard library, like zlib. In this way, slow machines with few resources can adhere to the SRDP spec without wasting precious footprint space and computational power implementing such &amp;quot;heavy&amp;quot; libraries.&lt;br /&gt;
&lt;br /&gt;
Using a &amp;quot;heavy-weight&amp;quot; compression library will help achieve better compression ratios, but will add processing overhead. The added overhead may turn out to be an overall hindrance. For example, a memory editor might want to refresh a memory display as fast as possible (several times per second) within a small visible view-port window. This kind of editor will need to download the contents of memory within the visible range quickly. Using compression in a use-case like this is a good idea, but only if transferring the smaller packet can make up for the time required to compress and decompress the data.'''''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Compressed arrays are similar to the standard &amp;quot;Array&amp;quot; data type. The compressed array starts with a single VLI to represent the total data size of the value (e.g. the size of the compressed data, ''x''). The following data is a series of alternating raw data and RLE data.&lt;br /&gt;
&lt;br /&gt;
# '''Raw Data''': A VLI representing raw data size in bytes (''n''), followed by ''n'' bytes of actual data.&lt;br /&gt;
# '''RLE Data''': A VLI representing RLE data size in bytes (''n''), followed by a single byte to be repeated (''n'' + 4) times in the output.&lt;br /&gt;
&lt;br /&gt;
This series is repeated until there are no more bytes to be read from input (''x'' bytes of the argument value have been read).&lt;br /&gt;
&lt;br /&gt;
For the RLE compression to be useful (efficient) it must not be used for any less than 4 bytes (therefore, the VLI is said to be a &amp;quot;4-based&amp;quot; number). The number 4 is derived from the minimum overhead introduced by the serial alternation and VLIs; 1 VLI for RLE output length, 1 byte of RLE data, 1 VLI for raw data length.&lt;br /&gt;
&lt;br /&gt;
Thus, in order for the RLE to perform &amp;quot;compression&amp;quot;, the RLE output must be larger than the smallest sequence required to switch from raw data and back again. Some examples to illustrate, '''''bold-italic''''' bytes are for VLI &amp;quot;control sequences&amp;quot; (the data lengths specified above):&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 1'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 01&lt;br /&gt;
 &lt;br /&gt;
 Incorrectly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''&amp;lt;u&amp;gt;03&amp;lt;/u&amp;gt;''''' 00 '''''01''''' 01&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''08''''' 94 24 51 73 00 00 00 01&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 2'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''00''''' 00&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 3'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 00 00 00 00 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''00''''' '''''04''''' 00&lt;br /&gt;
&lt;br /&gt;
The reason the second line in example 1 above is &amp;quot;incorrectly&amp;quot; compressed is because the second VLI is expecting the length to be 0-based. If this was the case, you would be simply adding overhead to replace any bytes saved by the &amp;quot;compression&amp;quot;. For this reason, the &amp;quot;correct&amp;quot; way to compress the example is to use a single length of raw data. This example is non-compressible, and should not be sent as a compressed array data type.&lt;br /&gt;
&lt;br /&gt;
In the second example, the data can be compressed nicely, saving a byte overall (including compression overhead). Since this is the &amp;quot;correct&amp;quot; way to compress the data, it is using a 4-based VLI on the RLE Data: &amp;quot;'''''00'''''&amp;quot; means 4 bytes of output, &amp;quot;'''''01'''''&amp;quot; means 5 bytes, &amp;quot;'''''02'''''&amp;quot; means 6 bytes, etc.&lt;br /&gt;
&lt;br /&gt;
The third example shows how to compress a series of bytes that starts with repeating data, instead of non-repeating &amp;quot;raw data&amp;quot;. The first VLI of '''''00''''' means there is no raw data for output (this is required: compressed arrays always begin with the Raw Data, followed by RLE Data). The second VLI '''''04''''' is the length of the RLE Data; 8 bytes. Even if the non-compressed data was 4 bytes of &amp;quot;00&amp;quot;, the compressed array would still be only 3 bytes of total data, saving one byte. This helps explain the reasoning behind the 4-based VLI for RLE Data.&lt;br /&gt;
&lt;br /&gt;
====Object Data Type====&lt;br /&gt;
&lt;br /&gt;
The basic structure and data types shown so far are very powerful; your server can tell the client vast amounts of information, such as CPU architecture, memory maps, I/O maps, etc. with just a handful of arguments. However, grouping these arguments in a meaningful way may be difficult. You might be inclined to do some &amp;quot;mock&amp;quot; namespacing, like prefixing each CPU-related argument with &amp;quot;cpu_&amp;quot;. This is effective, but also slightly wasteful and error-prone.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;object&amp;quot; data type is designed to handle such situations. This data type allows an argument to be a container for other arguments. Its format looks like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:[...]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Where the set of ellipses denotes one or more &amp;quot;regular&amp;quot; arguments. Here is an example of what a &amp;quot;cpu&amp;quot; object might look like:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
(Note the white-space is for readability only; it is not meant to be transferred as part of the protocol data.)&lt;br /&gt;
&lt;br /&gt;
In this example, the &amp;quot;cpu&amp;quot; object contains two arguments: cpu.arch and cpu.name; both strings.&lt;br /&gt;
&lt;br /&gt;
But there are also times when you will want your server to send that same information for two [or more] CPU architectures on a single target. Some platforms may have multiple CPUs, each with its own individual set of resources (memory maps and the like), as well as shared resources between the CPUs. For this, the packet data structure needs a more advanced method of communicating these kinds of details.&lt;br /&gt;
&lt;br /&gt;
For this case, you can optionally create arrays of objects by including a comma (,) after the closing square bracket, followed by another series of arguments enclosed in their own square brackets, ''ad infinitum''. In other words, any leading object definitions without explicit names will be treated as additional array elements for the previously named object.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM7TDMI␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now our &amp;quot;cpu&amp;quot; object defines two CPUs: an ARM9 and ARM7, ready for Nintendo DS hacking. These arguments can be referenced as cpu[0].arch, cpu[0].name, cpu[1].arch, and cpu[1].name respectively.&lt;br /&gt;
&lt;br /&gt;
Objects can be arbitrarily complex, containing arrays of other objects. Here is an example of a simple memory map, containing Work RAM (read/write/execute) and ROM (read/execute) sections. The Work RAM section is broken into two distinct memory ranges. This is quite easily expressed:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;memory:[&lt;br /&gt;
:name:t=Work RAM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&amp;lt;br/&amp;gt;&lt;br /&gt;
:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RWX␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:name:t=ROM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RX␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comments===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Protocol Goals&amp;quot; have lead much of the motivation for developing this proposal. This presents what seems to be several very strange choices, at first glance. The choice of representing floating point numbers as a string of text seems extremely odd, until you consider that using the target-native floating point data format would make no sense when sending that data to a remote client (which is most likely running on a different architecture, and may have totally different native floating point formats). In order to express floating points with arbitrary precision in a data format-agnostic way, it is necessary to use a non-native format like text.&lt;br /&gt;
&lt;br /&gt;
Another oddity in this spec is the use of VLIs (variable-length integers) and their affect on the rest of the format. The main purpose for using VLIs is address widths. Some architectures can express their full address range within a single byte. Others require up to 8 bytes for a full 64-bit address range. Future architectures are by no means limited to 64-bit address widths. For this very reason, it is necessary to scale down as well as up. A VLI can express an address in as little as a single byte, or scale upward to arbitrarily large numbers. This makes VLIs perfect for addressing requirements among any architecture.&lt;br /&gt;
&lt;br /&gt;
VLIs present their own issues, however. For example, expressing a negative number as a VLI is nearly incomprehensible. Some might be inclined to reserve one bit within a VLI to indicate signedness, but that's another bit that cannot be used to minimize VLI overhead. The overhead is additional bytes required to represent a full number in a VLI system. For example, it is common for numbers 0 - 127 to be contained entirely within a single byte, including the overhead. But numbers between 128 - 255 require an additional byte to include more VLI &amp;quot;header&amp;quot; information (used to extend VLIs into arbitrarily long numbers). This is counter-intuitive, where a single byte itself can hold numbers between 0 - 255. Adding an additional sign bit reduces the range of VLIs by half: a single byte can only encode numbers between 0 - 63.&lt;br /&gt;
&lt;br /&gt;
The solution is to use a different data type specifically for expressing negative numbers. The VLI is encoded just like a positive number, but when interpreting the VLI, it must be converted to a negative number by either subtracting from zero (0 - ''n'') or multiplying by negative one (''n'' * -1). This is referred to as a &amp;quot;one's complement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In general, the efficiency of a VLI is very static. That means, a number using 0 - 7 bits of data (for example, the number &amp;quot;0&amp;quot; uses 0 bits of data, and the number &amp;quot;64&amp;quot; [binary: 100000] uses 6 bits) can be encoded into a single byte, a number using 8 - 14 bits can be encoded into 2 bytes, a number using 15 - 21 bits can be encoded into 3 bytes, etc. See http://www.dlugosz.com/ZIP2/VLI.html for more information on the kind of VLI I am considering for this proposal.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=988</id>
		<title>Scalable Remote Debugger Protocol</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=988"/>
				<updated>2010-01-13T03:00:59Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Protocol Packet Data Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently serving as a reference to kick-start development of the universal debugger protocol which will be used by the [[Universal Debugger Project]] and hopefully many, many other debuggers and debugger interfaces in the years to come.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
These references are listed in order of relevance; most relevant first.&lt;br /&gt;
&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc909.txt RFC-909: Loader Debugger Protocol]&lt;br /&gt;
# [http://sourceware.org/gdb/download/onlinedocs/gdb_33.html GDB Remote Serial Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc643.txt RFC-643: Network Debugging Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/ien/ien158.txt IEN-158: XNET Debugging Protocol]&lt;br /&gt;
# [http://www.xdebug.org/docs-dbgp.php DBGp: A common debugger protocol for languages and debugger UI communication]&lt;br /&gt;
&lt;br /&gt;
The relevancy I've determined for this list is due to interest in these specs, as well as potential generic uses and protocol extension.&lt;br /&gt;
&lt;br /&gt;
RFC-909 is so far the closest thing I have found which resembles the general idea I have for a &amp;quot;Universal Debugger Protocol&amp;quot;. It's composed as a simple binary packet, it's extensible, and it's designed to be stacked on top of existing transport protocols such as TCP/IP. I doubt this exact spec will fit all of our needs, but it is certainly a good start.&lt;br /&gt;
&lt;br /&gt;
GDB provides a fairly popular protocol. This one is designed for serial communications, so it will work well with small embedded devices. But it could be complicated to extend while retaining its GDB friendliness.&lt;br /&gt;
&lt;br /&gt;
RFC-643 and IEN-158 are interesting only because they show that some experimentation on the ideas of remote debugging have been employed in the past. Unfortunately, these specs were designed for a specific architecture, and are of little practical use for our purposes.&lt;br /&gt;
&lt;br /&gt;
DBGp shows what a modern remote debugging protocol can look like; including modern XML syntax. The downside to this is that low-level debuggers in small embedded devices are unlikely to parse XML at all.&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
&lt;br /&gt;
This section represents my ([[User:Parasyte|Parasyte]]) own personal opinions and ideas, and should not be taken as advocacy for standardization.&lt;br /&gt;
&lt;br /&gt;
One of the main goals of developing a &amp;quot;universal&amp;quot; protocol for debugging is that it must be usable everywhere; in small embedded devices, and some of the most powerful machines in the world. This kind of flexibility must be designed around multiple layers of abstraction. See [http://en.wikipedia.org/wiki/OSI_Model OSI Model] and [http://en.wikipedia.org/wiki/Internet_Protocol_Suite Internet Protocol Suite] for examples of abstraction layers used in communications technologies.&lt;br /&gt;
&lt;br /&gt;
At the lowest layer, you find the ''wire''; the physical means of transmitting information over distance. For our purposes, we should not limit ourselves to a single wire. Instead, we should allow the use of multiple wires, user-selectable, but never more than one at a time.&lt;br /&gt;
&lt;br /&gt;
The following layers get more and more generic and abstract, until you reach the highest layer which represents what the application sees and interacts with. This would be the &amp;quot;protocol&amp;quot; itself.&lt;br /&gt;
&lt;br /&gt;
So let's break these components down, hypothetically, and get into some details, ordered lowest layer first:&lt;br /&gt;
&lt;br /&gt;
# '''Physical layer''': Some examples of wires to support include LAN (Ethernet/WiFi), Wireless (Bluetooth), RS-232 (serial port, USB serial port), Inter-Process Communication (Domain Sockets? DBUS?)&lt;br /&gt;
# '''Transport layer''': Some examples of transport protocols include TCP/IP, UDP/IP (LAN, Domain Sockets), UART (RS-232), IPC-specific (DBUS)&lt;br /&gt;
# '''Application layer''': A library (or similar service, E.G. a daemon) to tie all transport layers into a single API that, to the application, looks like one simple interface to connect and send/receive data. The library/daemon will have to handle the transport-specific details behind-the-scenes.&lt;br /&gt;
&lt;br /&gt;
Thinking about this led to a conundrum; If we support multiple wires, we have to support multiple transport protocols which are compatible with those wires. And if we support multiple transport protocols, we have to know which one our target implements. To make the API as simple as possible, we must not force clients to choose from configurable options (for a bad example) that requires a large degree of changes for each different type of connection made. How do we simplify the API so that a user can just plain connect without doing any pre-setup work?&lt;br /&gt;
&lt;br /&gt;
Answer: The [http://en.wikipedia.org/wiki/URI_scheme URI scheme]. The unfortunate downside to this solution is that it is undesired to use URI schemes without registering them with IANA. However, an argument could be made that these schemes would not be used for general network/internet communication. A few popular examples of similarly non-networked schemes are the file: and about: URI schemes. (The exception here is that at least one physical layer (LAN) could be used for over-the-internet communication; but this has great benefits in its own right.)&lt;br /&gt;
&lt;br /&gt;
===Example URI Schemes===&lt;br /&gt;
&lt;br /&gt;
The following table represents some examples of how URI schemes could be used as debugger protocols:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp://192.168.1.20/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | TCP/IP to remote host 192.168.1.20 on a pre-defined default port&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+udp://192.168.1.20:9424/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UDP/IP to remote host 192.168.1.20 on port 9424&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+usb://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | USB (SRDP-compatible devices) on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+uart://localhost:3/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UART COM port 3 on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+dbus://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | DBUS IPC on localhost&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'srdp' prefix on these examples is to specify the 'Scalable Remote Debugger Protocol.' The + and suffix defines an additional layer (or protocol) below SRDP.&lt;br /&gt;
&lt;br /&gt;
The latter three examples look a bit odd with localhost being the destination, but this is necessary, since the localhost ''is'' the destination for hosting the UART RS-232 port, USB port, and IPC interface. Using non-loopback interfaces (IP addresses outside of the local machine) with these protocols should be undefined, unless there is evidence that connecting to RS-232/USB/IPC interfaces on other machines across a network is practical and plausible.&lt;br /&gt;
&lt;br /&gt;
===Simplified Configuration===&lt;br /&gt;
&lt;br /&gt;
These URI schemes give a very simple and elegant solution to the concerns they address. No longer will you be stuck with complicated configuration settings like the example below (upper left group box) ... and this is not an incredibly complex configuration dialog, as it is; instead, connecting to ANY low-level debugger in the world will be as simple as typing a URL.&lt;br /&gt;
&lt;br /&gt;
Example of what '''''not''''' to do:&lt;br /&gt;
&lt;br /&gt;
[[Image:Gscc_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Operation Groups===&lt;br /&gt;
&lt;br /&gt;
The protocol is defined as a set of usable &amp;quot;requests&amp;quot; (AKA &amp;quot;operations&amp;quot; or &amp;quot;commands&amp;quot;) requested by the client to the debugger, or vice-versa. Operations should be grouped according to a specific metric. The metric I've chosen is hardware (architecture) relationships. The table below shows an example of such groups (currently 6 in total) and example operations assigned to each group.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 1)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Diagnostics (Init, Shutdown, Ping/Pong, Reset, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 2)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | CPU handling (Get/set process states, register read/write, arbitrary code execution, general CPU control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 3)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Memory handling (read, write, address conversion, hardware I/O, cache control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 4)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Breakpoint handling (add, delete, edit, get, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 5)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Stream handling (stdin/stdout/stderr, debugger-specific messages, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 6)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Vendor-specific (custom command sets, should be discouraged unless absolutely necessary)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Proposal==&lt;br /&gt;
&lt;br /&gt;
This section defines a proposed specification which may be adopted as the &amp;quot;Scalable Remote Debugger Protocol&amp;quot;. It is considered a work in progress and is currently open for peer-review, meaning we are interested in receiving comments, criticisms, and suggestions.&lt;br /&gt;
&lt;br /&gt;
===Protocol Goals===&lt;br /&gt;
&lt;br /&gt;
Goals of the protocol include:&lt;br /&gt;
&lt;br /&gt;
# '''Client/server relationship''': Target (debuggee) acts as a server, quietly listening for any SRDP requests; User Interface acts as a client, making explicit requests to a listening server.&lt;br /&gt;
# '''Asynchronous requests''': A client must send requests without expecting an immediate response. A server accepting requests may not respond immediately to those requests.&lt;br /&gt;
# '''Scalable''': The data structure (format) used in the protocol must be adaptable to the future; The structure must be as forgiving and dynamic as possible, avoiding fixed contents (except where absolutely necessary) and allowing for [non-mission-critical] non-standard contents.&lt;br /&gt;
# '''Easy to implement''': Basic features of the protocol should be easy to implement from an API point-of-view, as well as having a small memory footprint; the protocol must be usable on small embedded machines with few resources.&lt;br /&gt;
# '''Robust''': Ambiguity should be kept to a minimum in all aspects of the protocol; every bit transferred should have a useful meaning.&lt;br /&gt;
# '''Easy to debug''': A debugger protocol that cannot itself be debugged (observed and verified to work as expected) is a failure in and of itself. For this reason, the protocol should be human-readable in its most basic form.&lt;br /&gt;
&lt;br /&gt;
===Underlying Protocols===&lt;br /&gt;
&lt;br /&gt;
There are no reservations on any underlying protocols (protocols used to move data from the client to the server, and back again -- SRDP is not one of these protocols). The only requirement is that they provide hand-shaking (transmission control), sequential ordering of packet data arrival, and data integrity checking. Some examples of suitable underlying protocols include [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/UDP/IP], and [http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART].&lt;br /&gt;
&lt;br /&gt;
The initial reference implementation will use TCP/IP for remote connections. For local-listening servers, the reference implementation will use UNIX Domain Sockets on UNIX-like operating systems, and Named Pipes on Windows.&lt;br /&gt;
&lt;br /&gt;
===Protocol Packet Data Structure===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;goals&amp;quot; section outlines the major features which formed the following data structure. Inspiration comes mainly from [http://en.wikipedia.org/wiki/JSON JSON], the JavaScript Object Notation. As JSON is a serialization [text format] of JavaScript objects, the SRDP data structure is a serialization of the data being transmitted.&lt;br /&gt;
&lt;br /&gt;
The structure also shares some inspiration from [http://en.wikipedia.org/wiki/Remote_procedure_call RPC]; An example is that your client may want to read work RAM from the target. The SRDP request for &amp;quot;read memory&amp;quot; is technically similar to remotely running a &amp;quot;read memory&amp;quot; function on the server, invoked by the client. For this reason, each SRDP packet contains one or more &amp;quot;arguments&amp;quot; which you could imagine are passed directly to a plain old function.&lt;br /&gt;
&lt;br /&gt;
Each packet is sent as a series of 8-bit bytes. Packets are broken down into a &amp;quot;request/response/alert&amp;quot; name (called a command), encapsulating a series of &amp;quot;arguments&amp;quot;. You can think of it like a C function call. The &amp;quot;info&amp;quot; command, for example, requests information about the target machine architecture; it requires no arguments. The info command looks like this, and is a complete and valid SRDP packet:&lt;br /&gt;
&lt;br /&gt;
  info()&lt;br /&gt;
&lt;br /&gt;
Each argument has a name (made of one or more characters: alpha-numeric, underscore (_), or hyphen (-). The argument name is followed by a colon (:) and then a single byte representing the data type of the argument, then an equals sign (=) and the argument's value. All arguments are separated with a comma (,).&lt;br /&gt;
&lt;br /&gt;
The argument syntax is similar to that of [http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]. In pseudo-form, it looks something like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:{type}={value}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Valid data types:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | {type}&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Name&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | n&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any positive integer, encoded as a [http://www.dlugosz.com/ZIP2/VLI.html VLI]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | s&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Signed Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any negative integer, encoded as a [http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement one's complement] VLI&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | f&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Floating Point Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any non-integer number, Infinity, or [http://en.wikipedia.org/wiki/NaN NaN], encoded as a null-terminated UTF-8 string, or null-terminated UTF-16 or UTF-32 string with BOM; To be decoded by [http://en.wikipedia.org/wiki/Scanf#Format_string_specifications sscanf]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | a&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob), preceded by a VLI to indicate the length of the array.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | c&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Compressed Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob) with [http://en.wikipedia.org/wiki/Run-length_encoding RLE] compression. See [[#Compressed Array Data Type]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | t&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Text&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Null-terminated UTF-8 string without [http://en.wikipedia.org/wiki/Byte-order_mark BOM], or null-terminated UTF-16 or UTF-32 string with BOM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some example arguments. (Please keep in mind that all of the argument names listed within this section are for demonstration purposes only, and are not recommended for reference purposes.)&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | msg:t=Hello, World!␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | num:n=□&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | pi:f=3.141592␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | ram_dump:a=□■■■■&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | my-compressed-data:c=□□■■■■□■□■■■&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
What the symbols mean:&lt;br /&gt;
&lt;br /&gt;
  ␀: Null-terminator&lt;br /&gt;
  □: VLI&lt;br /&gt;
  ■: Data byte&lt;br /&gt;
&lt;br /&gt;
====Compressed Array Data Type====&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; padding: 10px;&amp;quot; | '''''One suggestion is making this data-type optional, and changing this spec to use a standard library, like zlib. In this way, slow machines with few resources can adhere to the SRDP spec without wasting precious footprint space and computational power implementing such &amp;quot;heavy&amp;quot; libraries.&lt;br /&gt;
&lt;br /&gt;
Using a &amp;quot;heavy-weight&amp;quot; compression library will help achieve better compression ratios, but will add processing overhead. The added overhead may turn out to be an overall hindrance. For example, a memory editor might want to refresh a memory display as fast as possible (several times per second) within a small visible view-port window. This kind of editor will need to download the contents of memory within the visible range quickly. Using compression in a use-case like this is a good idea, but only if transferring the smaller packet can make up for the time required to compress and decompress the data.'''''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Compressed arrays are similar to the standard &amp;quot;Array&amp;quot; data type. The compressed array starts with a single VLI to represent the total data size of the value (e.g. the size of the compressed data, ''x''). The following data is a series of alternating raw data and RLE data.&lt;br /&gt;
&lt;br /&gt;
# '''Raw Data''': A VLI representing raw data size in bytes (''n''), followed by ''n'' bytes of actual data.&lt;br /&gt;
# '''RLE Data''': A VLI representing RLE data size in bytes (''n''), followed by a single byte to be repeated (''n'' + 4) times in the output.&lt;br /&gt;
&lt;br /&gt;
This series is repeated until there are no more bytes to be read from input (''x'' bytes of the argument value have been read).&lt;br /&gt;
&lt;br /&gt;
For the RLE compression to be useful (efficient) it must not be used for any less than 4 bytes (therefore, the VLI is said to be a &amp;quot;4-based&amp;quot; number). The number 4 is derived from the minimum overhead introduced by the serial alternation and VLIs; 1 VLI for RLE output length, 1 byte of RLE data, 1 VLI for raw data length.&lt;br /&gt;
&lt;br /&gt;
Thus, in order for the RLE to perform &amp;quot;compression&amp;quot;, the RLE output must be larger than the smallest sequence required to switch from raw data and back again. Some examples to illustrate, '''''bold-italic''''' bytes are for VLI &amp;quot;control sequences&amp;quot; (the data lengths specified above):&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 1'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 01&lt;br /&gt;
 &lt;br /&gt;
 Incorrectly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''&amp;lt;u&amp;gt;03&amp;lt;/u&amp;gt;''''' 00 '''''01''''' 01&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''08''''' 94 24 51 73 00 00 00 01&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 2'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''00''''' 00&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 3'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 00 00 00 00 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''00''''' '''''04''''' 00&lt;br /&gt;
&lt;br /&gt;
The reason the second line in example 1 above is &amp;quot;incorrectly&amp;quot; compressed is because the second VLI is expecting the length to be 0-based. If this was the case, you would be simply adding overhead to replace any bytes saved by the &amp;quot;compression&amp;quot;. For this reason, the &amp;quot;correct&amp;quot; way to compress the example is to use a single length of raw data. This example is non-compressible, and should not be sent as a compressed array data type.&lt;br /&gt;
&lt;br /&gt;
In the second example, the data can be compressed nicely, saving a byte overall (including compression overhead). Since this is the &amp;quot;correct&amp;quot; way to compress the data, it is using a 4-based VLI on the RLE Data: &amp;quot;'''''00'''''&amp;quot; means 4 bytes of output, &amp;quot;'''''01'''''&amp;quot; means 5 bytes, &amp;quot;'''''02'''''&amp;quot; means 6 bytes, etc.&lt;br /&gt;
&lt;br /&gt;
The third example shows how to compress a series of bytes that starts with repeating data, instead of non-repeating &amp;quot;raw data&amp;quot;. The first VLI of '''''00''''' means there is no raw data for output (this is required: compressed arrays always begin with the Raw Data, followed by RLE Data). The second VLI '''''04''''' is the length of the RLE Data; 8 bytes. Even if the non-compressed data was 4 bytes of &amp;quot;00&amp;quot;, the compressed array would still be only 3 bytes of total data, saving one byte. This helps explain the reasoning behind the 4-based VLI for RLE Data.&lt;br /&gt;
&lt;br /&gt;
====Object Data Type====&lt;br /&gt;
&lt;br /&gt;
The basic structure and data types shown so far are very powerful; your server can tell the client vast amounts of information, such as CPU architecture, memory maps, I/O maps, etc. with just a handful of arguments. However, grouping these arguments in a meaningful way may be difficult. You might be inclined to do some &amp;quot;mock&amp;quot; namespacing, like prefixing each CPU-related argument with &amp;quot;cpu_&amp;quot;. This is effective, but also slightly wasteful and error-prone.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;object&amp;quot; data type is designed to handle such situations. This data type allows an argument to be a container for other arguments. Its format looks like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:[...]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Where the set of ellipses denotes one or more &amp;quot;regular&amp;quot; arguments. Here is an example of what a &amp;quot;cpu&amp;quot; object might look like:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
(Note the white-space is for readability only; it is not meant to be transferred as part of the protocol data.)&lt;br /&gt;
&lt;br /&gt;
In this example, the &amp;quot;cpu&amp;quot; object contains two arguments: cpu.arch and cpu.name; both strings.&lt;br /&gt;
&lt;br /&gt;
But there are also times when you will want your server to send that same information for two [or more] CPU architectures on a single target. Some platforms may have multiple CPUs, each with its own individual set of resources (memory maps and the like), as well as shared resources between the CPUs. For this, the packet data structure needs a more advanced method of communicating these kinds of details.&lt;br /&gt;
&lt;br /&gt;
For this case, you can optionally create arrays of objects by including a comma (,) after the closing square bracket, followed by another series of arguments enclosed in their own square brackets, ''ad infinitum''. In other words, any leading object definitions without explicit names will be treated as additional array elements for the previously named object.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM7TDMI␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now our &amp;quot;cpu&amp;quot; object defines two CPUs: an ARM9 and ARM7, ready for Nintendo DS hacking. These arguments can be referenced as cpu[0].arch, cpu[0].name, cpu[1].arch, and cpu[1].name respectively.&lt;br /&gt;
&lt;br /&gt;
Objects can be arbitrarily complex, containing arrays of other objects. Here is an example of a simple memory map, containing Work RAM (read/write/execute) and ROM (read/execute) sections. The Work RAM section is broken into two distinct memory ranges. This is quite easily expressed:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;memory:[&lt;br /&gt;
:name:t=Work RAM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&amp;lt;br/&amp;gt;&lt;br /&gt;
:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RWX␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:name:t=ROM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RX␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comments===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Protocol Goals&amp;quot; have lead much of the motivation for developing this proposal. This presents what seems to be several very strange choices, at first glance. The choice of representing floating point numbers as a string of text seems extremely odd, until you consider that using the target-native floating point data format would make no sense when sending that data to a remote client (which is most likely running on a different architecture, and may have totally different native floating point formats). In order to express floating points with arbitrary precision in a data format-agnostic way, it is necessary to use a non-native format like text.&lt;br /&gt;
&lt;br /&gt;
Another oddity in this spec is the use of VLIs (variable-length integers) and their affect on the rest of the format. The main purpose for using VLIs is address widths. Some architectures can express their full address range within a single byte. Others require up to 8 bytes for a full 64-bit address range. Future architectures are by no means limited to 64-bit address widths. For this very reason, it is necessary to scale down as well as up. A VLI can express an address in as little as a single byte, or scale upward to arbitrarily large numbers. This makes VLIs perfect for addressing requirements among any architecture.&lt;br /&gt;
&lt;br /&gt;
VLIs present their own issues, however. For example, expressing a negative number as a VLI is nearly incomprehensible. Some might be inclined to reserve one bit within a VLI to indicate signedness, but that's another bit that cannot be used to minimize VLI overhead. The overhead is additional bytes required to represent a full number in a VLI system. For example, it is common for numbers 0 - 127 to be contained entirely within a single byte, including the overhead. But numbers between 128 - 255 require an additional byte to include more VLI &amp;quot;header&amp;quot; information (used to extend VLIs into arbitrarily long numbers). This is counter-intuitive, where a single byte itself can hold numbers between 0 - 255. Adding an additional sign bit reduces the range of VLIs by half: a single byte can only encode numbers between 0 - 63.&lt;br /&gt;
&lt;br /&gt;
The solution is to use a different data type specifically for expressing negative numbers. The VLI is encoded just like a positive number, but when interpreting the VLI, it must be converted to a negative number by either subtracting from zero (0 - ''n'') or multiplying by negative one (''n'' * -1). This is referred to as a &amp;quot;one's complement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In general, the efficiency of a VLI is very static. That means, a number using 0 - 7 bits of data (for example, the number &amp;quot;0&amp;quot; uses 0 bits of data, and the number &amp;quot;64&amp;quot; [binary: 100000] uses 6 bits) can be encoded into a single byte, a number using 8 - 14 bits can be encoded into 2 bytes, a number using 15 - 21 bits can be encoded into 3 bytes, etc. See http://www.dlugosz.com/ZIP2/VLI.html for more information on the kind of VLI I am considering for this proposal.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=987</id>
		<title>Scalable Remote Debugger Protocol</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=987"/>
				<updated>2010-01-13T02:55:05Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Protocol Packet Data Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently serving as a reference to kick-start development of the universal debugger protocol which will be used by the [[Universal Debugger Project]] and hopefully many, many other debuggers and debugger interfaces in the years to come.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
These references are listed in order of relevance; most relevant first.&lt;br /&gt;
&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc909.txt RFC-909: Loader Debugger Protocol]&lt;br /&gt;
# [http://sourceware.org/gdb/download/onlinedocs/gdb_33.html GDB Remote Serial Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc643.txt RFC-643: Network Debugging Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/ien/ien158.txt IEN-158: XNET Debugging Protocol]&lt;br /&gt;
# [http://www.xdebug.org/docs-dbgp.php DBGp: A common debugger protocol for languages and debugger UI communication]&lt;br /&gt;
&lt;br /&gt;
The relevancy I've determined for this list is due to interest in these specs, as well as potential generic uses and protocol extension.&lt;br /&gt;
&lt;br /&gt;
RFC-909 is so far the closest thing I have found which resembles the general idea I have for a &amp;quot;Universal Debugger Protocol&amp;quot;. It's composed as a simple binary packet, it's extensible, and it's designed to be stacked on top of existing transport protocols such as TCP/IP. I doubt this exact spec will fit all of our needs, but it is certainly a good start.&lt;br /&gt;
&lt;br /&gt;
GDB provides a fairly popular protocol. This one is designed for serial communications, so it will work well with small embedded devices. But it could be complicated to extend while retaining its GDB friendliness.&lt;br /&gt;
&lt;br /&gt;
RFC-643 and IEN-158 are interesting only because they show that some experimentation on the ideas of remote debugging have been employed in the past. Unfortunately, these specs were designed for a specific architecture, and are of little practical use for our purposes.&lt;br /&gt;
&lt;br /&gt;
DBGp shows what a modern remote debugging protocol can look like; including modern XML syntax. The downside to this is that low-level debuggers in small embedded devices are unlikely to parse XML at all.&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
&lt;br /&gt;
This section represents my ([[User:Parasyte|Parasyte]]) own personal opinions and ideas, and should not be taken as advocacy for standardization.&lt;br /&gt;
&lt;br /&gt;
One of the main goals of developing a &amp;quot;universal&amp;quot; protocol for debugging is that it must be usable everywhere; in small embedded devices, and some of the most powerful machines in the world. This kind of flexibility must be designed around multiple layers of abstraction. See [http://en.wikipedia.org/wiki/OSI_Model OSI Model] and [http://en.wikipedia.org/wiki/Internet_Protocol_Suite Internet Protocol Suite] for examples of abstraction layers used in communications technologies.&lt;br /&gt;
&lt;br /&gt;
At the lowest layer, you find the ''wire''; the physical means of transmitting information over distance. For our purposes, we should not limit ourselves to a single wire. Instead, we should allow the use of multiple wires, user-selectable, but never more than one at a time.&lt;br /&gt;
&lt;br /&gt;
The following layers get more and more generic and abstract, until you reach the highest layer which represents what the application sees and interacts with. This would be the &amp;quot;protocol&amp;quot; itself.&lt;br /&gt;
&lt;br /&gt;
So let's break these components down, hypothetically, and get into some details, ordered lowest layer first:&lt;br /&gt;
&lt;br /&gt;
# '''Physical layer''': Some examples of wires to support include LAN (Ethernet/WiFi), Wireless (Bluetooth), RS-232 (serial port, USB serial port), Inter-Process Communication (Domain Sockets? DBUS?)&lt;br /&gt;
# '''Transport layer''': Some examples of transport protocols include TCP/IP, UDP/IP (LAN, Domain Sockets), UART (RS-232), IPC-specific (DBUS)&lt;br /&gt;
# '''Application layer''': A library (or similar service, E.G. a daemon) to tie all transport layers into a single API that, to the application, looks like one simple interface to connect and send/receive data. The library/daemon will have to handle the transport-specific details behind-the-scenes.&lt;br /&gt;
&lt;br /&gt;
Thinking about this led to a conundrum; If we support multiple wires, we have to support multiple transport protocols which are compatible with those wires. And if we support multiple transport protocols, we have to know which one our target implements. To make the API as simple as possible, we must not force clients to choose from configurable options (for a bad example) that requires a large degree of changes for each different type of connection made. How do we simplify the API so that a user can just plain connect without doing any pre-setup work?&lt;br /&gt;
&lt;br /&gt;
Answer: The [http://en.wikipedia.org/wiki/URI_scheme URI scheme]. The unfortunate downside to this solution is that it is undesired to use URI schemes without registering them with IANA. However, an argument could be made that these schemes would not be used for general network/internet communication. A few popular examples of similarly non-networked schemes are the file: and about: URI schemes. (The exception here is that at least one physical layer (LAN) could be used for over-the-internet communication; but this has great benefits in its own right.)&lt;br /&gt;
&lt;br /&gt;
===Example URI Schemes===&lt;br /&gt;
&lt;br /&gt;
The following table represents some examples of how URI schemes could be used as debugger protocols:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp://192.168.1.20/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | TCP/IP to remote host 192.168.1.20 on a pre-defined default port&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+udp://192.168.1.20:9424/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UDP/IP to remote host 192.168.1.20 on port 9424&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+usb://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | USB (SRDP-compatible devices) on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+uart://localhost:3/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UART COM port 3 on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+dbus://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | DBUS IPC on localhost&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'srdp' prefix on these examples is to specify the 'Scalable Remote Debugger Protocol.' The + and suffix defines an additional layer (or protocol) below SRDP.&lt;br /&gt;
&lt;br /&gt;
The latter three examples look a bit odd with localhost being the destination, but this is necessary, since the localhost ''is'' the destination for hosting the UART RS-232 port, USB port, and IPC interface. Using non-loopback interfaces (IP addresses outside of the local machine) with these protocols should be undefined, unless there is evidence that connecting to RS-232/USB/IPC interfaces on other machines across a network is practical and plausible.&lt;br /&gt;
&lt;br /&gt;
===Simplified Configuration===&lt;br /&gt;
&lt;br /&gt;
These URI schemes give a very simple and elegant solution to the concerns they address. No longer will you be stuck with complicated configuration settings like the example below (upper left group box) ... and this is not an incredibly complex configuration dialog, as it is; instead, connecting to ANY low-level debugger in the world will be as simple as typing a URL.&lt;br /&gt;
&lt;br /&gt;
Example of what '''''not''''' to do:&lt;br /&gt;
&lt;br /&gt;
[[Image:Gscc_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Operation Groups===&lt;br /&gt;
&lt;br /&gt;
The protocol is defined as a set of usable &amp;quot;requests&amp;quot; (AKA &amp;quot;operations&amp;quot; or &amp;quot;commands&amp;quot;) requested by the client to the debugger, or vice-versa. Operations should be grouped according to a specific metric. The metric I've chosen is hardware (architecture) relationships. The table below shows an example of such groups (currently 6 in total) and example operations assigned to each group.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 1)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Diagnostics (Init, Shutdown, Ping/Pong, Reset, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 2)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | CPU handling (Get/set process states, register read/write, arbitrary code execution, general CPU control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 3)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Memory handling (read, write, address conversion, hardware I/O, cache control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 4)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Breakpoint handling (add, delete, edit, get, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 5)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Stream handling (stdin/stdout/stderr, debugger-specific messages, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 6)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Vendor-specific (custom command sets, should be discouraged unless absolutely necessary)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Proposal==&lt;br /&gt;
&lt;br /&gt;
This section defines a proposed specification which may be adopted as the &amp;quot;Scalable Remote Debugger Protocol&amp;quot;. It is considered a work in progress and is currently open for peer-review, meaning we are interested in receiving comments, criticisms, and suggestions.&lt;br /&gt;
&lt;br /&gt;
===Protocol Goals===&lt;br /&gt;
&lt;br /&gt;
Goals of the protocol include:&lt;br /&gt;
&lt;br /&gt;
# '''Client/server relationship''': Target (debuggee) acts as a server, quietly listening for any SRDP requests; User Interface acts as a client, making explicit requests to a listening server.&lt;br /&gt;
# '''Asynchronous requests''': A client must send requests without expecting an immediate response. A server accepting requests may not respond immediately to those requests.&lt;br /&gt;
# '''Scalable''': The data structure (format) used in the protocol must be adaptable to the future; The structure must be as forgiving and dynamic as possible, avoiding fixed contents (except where absolutely necessary) and allowing for [non-mission-critical] non-standard contents.&lt;br /&gt;
# '''Easy to implement''': Basic features of the protocol should be easy to implement from an API point-of-view, as well as having a small memory footprint; the protocol must be usable on small embedded machines with few resources.&lt;br /&gt;
# '''Robust''': Ambiguity should be kept to a minimum in all aspects of the protocol; every bit transferred should have a useful meaning.&lt;br /&gt;
# '''Easy to debug''': A debugger protocol that cannot itself be debugged (observed and verified to work as expected) is a failure in and of itself. For this reason, the protocol should be human-readable in its most basic form.&lt;br /&gt;
&lt;br /&gt;
===Underlying Protocols===&lt;br /&gt;
&lt;br /&gt;
There are no reservations on any underlying protocols (protocols used to move data from the client to the server, and back again -- SRDP is not one of these protocols). The only requirement is that they provide hand-shaking (transmission control), sequential ordering of packet data arrival, and data integrity checking. Some examples of suitable underlying protocols include [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/UDP/IP], and [http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART].&lt;br /&gt;
&lt;br /&gt;
The initial reference implementation will use TCP/IP for remote connections. For local-listening servers, the reference implementation will use UNIX Domain Sockets on UNIX-like operating systems, and Named Pipes on Windows.&lt;br /&gt;
&lt;br /&gt;
===Protocol Packet Data Structure===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;goals&amp;quot; section outlines the major features which formed the following data structure. Inspiration comes mainly from [http://en.wikipedia.org/wiki/JSON JSON], the JavaScript Object Notation. As JSON is a serialization [text format] of JavaScript objects, the SRDP data structure is a serialization of the data being transmitted.&lt;br /&gt;
&lt;br /&gt;
The structure also shares some inspiration from [http://en.wikipedia.org/wiki/Remote_procedure_call RPC]; An example is that your client may want to read work RAM from the target. The SRDP request for &amp;quot;read memory&amp;quot; is technically similar to remotely running a &amp;quot;read memory&amp;quot; function on the server, invoked by the client. For this reason, each SRDP packet contains one or more &amp;quot;arguments&amp;quot; which you could imagine are passed directly to a plain old function.&lt;br /&gt;
&lt;br /&gt;
Each packet is sent as a series of 8-bit bytes. Packets are broken down into a series of &amp;quot;arguments&amp;quot;. Each argument has a name (made of one or more characters: alpha-numeric, underscore (_), or hyphen (-). The argument name is followed by a colon (:) and then a single byte representing the data type of the argument, then an equals sign (=) and the argument's value. All arguments are separated with a comma (,).&lt;br /&gt;
&lt;br /&gt;
The argument syntax is similar to that of [http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]. In pseudo-form, it looks something like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:{type}={value}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Valid data types:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | {type}&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Name&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | n&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any positive integer, encoded as a [http://www.dlugosz.com/ZIP2/VLI.html VLI]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | s&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Signed Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any negative integer, encoded as a [http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement one's complement] VLI&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | f&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Floating Point Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any non-integer number, Infinity, or [http://en.wikipedia.org/wiki/NaN NaN], encoded as a null-terminated UTF-8 string, or null-terminated UTF-16 or UTF-32 string with BOM; To be decoded by [http://en.wikipedia.org/wiki/Scanf#Format_string_specifications sscanf]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | a&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob), preceded by a VLI to indicate the length of the array.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | c&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Compressed Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob) with [http://en.wikipedia.org/wiki/Run-length_encoding RLE] compression. See [[#Compressed Array Data Type]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | t&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Text&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Null-terminated UTF-8 string without [http://en.wikipedia.org/wiki/Byte-order_mark BOM], or null-terminated UTF-16 or UTF-32 string with BOM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some example arguments. (Please keep in mind that all of the argument names listed within this section are for demonstration purposes only, and are not recommended for reference purposes.)&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | msg:t=Hello, World!␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | num:n=□&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | pi:f=3.141592␀&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | ram_dump:a=□■■■■&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | my-compressed-data:c=□□■■■■□■□■■■&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
What the symbols mean:&lt;br /&gt;
&lt;br /&gt;
  ␀: Null-terminator&lt;br /&gt;
  □: VLI&lt;br /&gt;
  ■: Data byte&lt;br /&gt;
&lt;br /&gt;
====Compressed Array Data Type====&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; padding: 10px;&amp;quot; | '''''One suggestion is making this data-type optional, and changing this spec to use a standard library, like zlib. In this way, slow machines with few resources can adhere to the SRDP spec without wasting precious footprint space and computational power implementing such &amp;quot;heavy&amp;quot; libraries.&lt;br /&gt;
&lt;br /&gt;
Using a &amp;quot;heavy-weight&amp;quot; compression library will help achieve better compression ratios, but will add processing overhead. The added overhead may turn out to be an overall hindrance. For example, a memory editor might want to refresh a memory display as fast as possible (several times per second) within a small visible view-port window. This kind of editor will need to download the contents of memory within the visible range quickly. Using compression in a use-case like this is a good idea, but only if transferring the smaller packet can make up for the time required to compress and decompress the data.'''''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Compressed arrays are similar to the standard &amp;quot;Array&amp;quot; data type. The compressed array starts with a single VLI to represent the total data size of the value (e.g. the size of the compressed data, ''x''). The following data is a series of alternating raw data and RLE data.&lt;br /&gt;
&lt;br /&gt;
# '''Raw Data''': A VLI representing raw data size in bytes (''n''), followed by ''n'' bytes of actual data.&lt;br /&gt;
# '''RLE Data''': A VLI representing RLE data size in bytes (''n''), followed by a single byte to be repeated (''n'' + 4) times in the output.&lt;br /&gt;
&lt;br /&gt;
This series is repeated until there are no more bytes to be read from input (''x'' bytes of the argument value have been read).&lt;br /&gt;
&lt;br /&gt;
For the RLE compression to be useful (efficient) it must not be used for any less than 4 bytes (therefore, the VLI is said to be a &amp;quot;4-based&amp;quot; number). The number 4 is derived from the minimum overhead introduced by the serial alternation and VLIs; 1 VLI for RLE output length, 1 byte of RLE data, 1 VLI for raw data length.&lt;br /&gt;
&lt;br /&gt;
Thus, in order for the RLE to perform &amp;quot;compression&amp;quot;, the RLE output must be larger than the smallest sequence required to switch from raw data and back again. Some examples to illustrate, '''''bold-italic''''' bytes are for VLI &amp;quot;control sequences&amp;quot; (the data lengths specified above):&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 1'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 01&lt;br /&gt;
 &lt;br /&gt;
 Incorrectly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''&amp;lt;u&amp;gt;03&amp;lt;/u&amp;gt;''''' 00 '''''01''''' 01&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''08''''' 94 24 51 73 00 00 00 01&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 2'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''00''''' 00&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 3'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 00 00 00 00 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''00''''' '''''04''''' 00&lt;br /&gt;
&lt;br /&gt;
The reason the second line in example 1 above is &amp;quot;incorrectly&amp;quot; compressed is because the second VLI is expecting the length to be 0-based. If this was the case, you would be simply adding overhead to replace any bytes saved by the &amp;quot;compression&amp;quot;. For this reason, the &amp;quot;correct&amp;quot; way to compress the example is to use a single length of raw data. This example is non-compressible, and should not be sent as a compressed array data type.&lt;br /&gt;
&lt;br /&gt;
In the second example, the data can be compressed nicely, saving a byte overall (including compression overhead). Since this is the &amp;quot;correct&amp;quot; way to compress the data, it is using a 4-based VLI on the RLE Data: &amp;quot;'''''00'''''&amp;quot; means 4 bytes of output, &amp;quot;'''''01'''''&amp;quot; means 5 bytes, &amp;quot;'''''02'''''&amp;quot; means 6 bytes, etc.&lt;br /&gt;
&lt;br /&gt;
The third example shows how to compress a series of bytes that starts with repeating data, instead of non-repeating &amp;quot;raw data&amp;quot;. The first VLI of '''''00''''' means there is no raw data for output (this is required: compressed arrays always begin with the Raw Data, followed by RLE Data). The second VLI '''''04''''' is the length of the RLE Data; 8 bytes. Even if the non-compressed data was 4 bytes of &amp;quot;00&amp;quot;, the compressed array would still be only 3 bytes of total data, saving one byte. This helps explain the reasoning behind the 4-based VLI for RLE Data.&lt;br /&gt;
&lt;br /&gt;
====Object Data Type====&lt;br /&gt;
&lt;br /&gt;
The basic structure and data types shown so far are very powerful; your server can tell the client vast amounts of information, such as CPU architecture, memory maps, I/O maps, etc. with just a handful of arguments. However, grouping these arguments in a meaningful way may be difficult. You might be inclined to do some &amp;quot;mock&amp;quot; namespacing, like prefixing each CPU-related argument with &amp;quot;cpu_&amp;quot;. This is effective, but also slightly wasteful and error-prone.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;object&amp;quot; data type is designed to handle such situations. This data type allows an argument to be a container for other arguments. Its format looks like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:[...]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Where the set of ellipses denotes one or more &amp;quot;regular&amp;quot; arguments. Here is an example of what a &amp;quot;cpu&amp;quot; object might look like:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
(Note the white-space is for readability only; it is not meant to be transferred as part of the protocol data.)&lt;br /&gt;
&lt;br /&gt;
In this example, the &amp;quot;cpu&amp;quot; object contains two arguments: cpu.arch and cpu.name; both strings.&lt;br /&gt;
&lt;br /&gt;
But there are also times when you will want your server to send that same information for two [or more] CPU architectures on a single target. Some platforms may have multiple CPUs, each with its own individual set of resources (memory maps and the like), as well as shared resources between the CPUs. For this, the packet data structure needs a more advanced method of communicating these kinds of details.&lt;br /&gt;
&lt;br /&gt;
For this case, you can optionally create arrays of objects by including a comma (,) after the closing square bracket, followed by another series of arguments enclosed in their own square brackets, ''ad infinitum''. In other words, any leading object definitions without explicit names will be treated as additional array elements for the previously named object.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM946E-S␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:arch:t=ARM␀,&lt;br /&gt;
:name:t=ARM7TDMI␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now our &amp;quot;cpu&amp;quot; object defines two CPUs: an ARM9 and ARM7, ready for Nintendo DS hacking. These arguments can be referenced as cpu[0].arch, cpu[0].name, cpu[1].arch, and cpu[1].name respectively.&lt;br /&gt;
&lt;br /&gt;
Objects can be arbitrarily complex, containing arrays of other objects. Here is an example of a simple memory map, containing Work RAM (read/write/execute) and ROM (read/execute) sections. The Work RAM section is broken into two distinct memory ranges. This is quite easily expressed:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;memory:[&lt;br /&gt;
:name:t=Work RAM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&amp;lt;br/&amp;gt;&lt;br /&gt;
:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RWX␀&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:name:t=ROM␀,&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□,&lt;br /&gt;
::end:n=□&lt;br /&gt;
:],&lt;br /&gt;
:flags:t=RX␀&lt;br /&gt;
]&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comments===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Protocol Goals&amp;quot; have lead much of the motivation for developing this proposal. This presents what seems to be several very strange choices, at first glance. The choice of representing floating point numbers as a string of text seems extremely odd, until you consider that using the target-native floating point data format would make no sense when sending that data to a remote client (which is most likely running on a different architecture, and may have totally different native floating point formats). In order to express floating points with arbitrary precision in a data format-agnostic way, it is necessary to use a non-native format like text.&lt;br /&gt;
&lt;br /&gt;
Another oddity in this spec is the use of VLIs (variable-length integers) and their affect on the rest of the format. The main purpose for using VLIs is address widths. Some architectures can express their full address range within a single byte. Others require up to 8 bytes for a full 64-bit address range. Future architectures are by no means limited to 64-bit address widths. For this very reason, it is necessary to scale down as well as up. A VLI can express an address in as little as a single byte, or scale upward to arbitrarily large numbers. This makes VLIs perfect for addressing requirements among any architecture.&lt;br /&gt;
&lt;br /&gt;
VLIs present their own issues, however. For example, expressing a negative number as a VLI is nearly incomprehensible. Some might be inclined to reserve one bit within a VLI to indicate signedness, but that's another bit that cannot be used to minimize VLI overhead. The overhead is additional bytes required to represent a full number in a VLI system. For example, it is common for numbers 0 - 127 to be contained entirely within a single byte, including the overhead. But numbers between 128 - 255 require an additional byte to include more VLI &amp;quot;header&amp;quot; information (used to extend VLIs into arbitrarily long numbers). This is counter-intuitive, where a single byte itself can hold numbers between 0 - 255. Adding an additional sign bit reduces the range of VLIs by half: a single byte can only encode numbers between 0 - 63.&lt;br /&gt;
&lt;br /&gt;
The solution is to use a different data type specifically for expressing negative numbers. The VLI is encoded just like a positive number, but when interpreting the VLI, it must be converted to a negative number by either subtracting from zero (0 - ''n'') or multiplying by negative one (''n'' * -1). This is referred to as a &amp;quot;one's complement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In general, the efficiency of a VLI is very static. That means, a number using 0 - 7 bits of data (for example, the number &amp;quot;0&amp;quot; uses 0 bits of data, and the number &amp;quot;64&amp;quot; [binary: 100000] uses 6 bits) can be encoded into a single byte, a number using 8 - 14 bits can be encoded into 2 bytes, a number using 15 - 21 bits can be encoded into 3 bytes, etc. See http://www.dlugosz.com/ZIP2/VLI.html for more information on the kind of VLI I am considering for this proposal.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=986</id>
		<title>Scalable Remote Debugger Protocol</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=Scalable_Remote_Debugger_Protocol&amp;diff=986"/>
				<updated>2010-01-13T02:42:49Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Underlying Protocols */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is currently serving as a reference to kick-start development of the universal debugger protocol which will be used by the [[Universal Debugger Project]] and hopefully many, many other debuggers and debugger interfaces in the years to come.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
These references are listed in order of relevance; most relevant first.&lt;br /&gt;
&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc909.txt RFC-909: Loader Debugger Protocol]&lt;br /&gt;
# [http://sourceware.org/gdb/download/onlinedocs/gdb_33.html GDB Remote Serial Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/rfc643.txt RFC-643: Network Debugging Protocol]&lt;br /&gt;
# [ftp://ftp.rfc-editor.org/in-notes/ien/ien158.txt IEN-158: XNET Debugging Protocol]&lt;br /&gt;
# [http://www.xdebug.org/docs-dbgp.php DBGp: A common debugger protocol for languages and debugger UI communication]&lt;br /&gt;
&lt;br /&gt;
The relevancy I've determined for this list is due to interest in these specs, as well as potential generic uses and protocol extension.&lt;br /&gt;
&lt;br /&gt;
RFC-909 is so far the closest thing I have found which resembles the general idea I have for a &amp;quot;Universal Debugger Protocol&amp;quot;. It's composed as a simple binary packet, it's extensible, and it's designed to be stacked on top of existing transport protocols such as TCP/IP. I doubt this exact spec will fit all of our needs, but it is certainly a good start.&lt;br /&gt;
&lt;br /&gt;
GDB provides a fairly popular protocol. This one is designed for serial communications, so it will work well with small embedded devices. But it could be complicated to extend while retaining its GDB friendliness.&lt;br /&gt;
&lt;br /&gt;
RFC-643 and IEN-158 are interesting only because they show that some experimentation on the ideas of remote debugging have been employed in the past. Unfortunately, these specs were designed for a specific architecture, and are of little practical use for our purposes.&lt;br /&gt;
&lt;br /&gt;
DBGp shows what a modern remote debugging protocol can look like; including modern XML syntax. The downside to this is that low-level debuggers in small embedded devices are unlikely to parse XML at all.&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
&lt;br /&gt;
This section represents my ([[User:Parasyte|Parasyte]]) own personal opinions and ideas, and should not be taken as advocacy for standardization.&lt;br /&gt;
&lt;br /&gt;
One of the main goals of developing a &amp;quot;universal&amp;quot; protocol for debugging is that it must be usable everywhere; in small embedded devices, and some of the most powerful machines in the world. This kind of flexibility must be designed around multiple layers of abstraction. See [http://en.wikipedia.org/wiki/OSI_Model OSI Model] and [http://en.wikipedia.org/wiki/Internet_Protocol_Suite Internet Protocol Suite] for examples of abstraction layers used in communications technologies.&lt;br /&gt;
&lt;br /&gt;
At the lowest layer, you find the ''wire''; the physical means of transmitting information over distance. For our purposes, we should not limit ourselves to a single wire. Instead, we should allow the use of multiple wires, user-selectable, but never more than one at a time.&lt;br /&gt;
&lt;br /&gt;
The following layers get more and more generic and abstract, until you reach the highest layer which represents what the application sees and interacts with. This would be the &amp;quot;protocol&amp;quot; itself.&lt;br /&gt;
&lt;br /&gt;
So let's break these components down, hypothetically, and get into some details, ordered lowest layer first:&lt;br /&gt;
&lt;br /&gt;
# '''Physical layer''': Some examples of wires to support include LAN (Ethernet/WiFi), Wireless (Bluetooth), RS-232 (serial port, USB serial port), Inter-Process Communication (Domain Sockets? DBUS?)&lt;br /&gt;
# '''Transport layer''': Some examples of transport protocols include TCP/IP, UDP/IP (LAN, Domain Sockets), UART (RS-232), IPC-specific (DBUS)&lt;br /&gt;
# '''Application layer''': A library (or similar service, E.G. a daemon) to tie all transport layers into a single API that, to the application, looks like one simple interface to connect and send/receive data. The library/daemon will have to handle the transport-specific details behind-the-scenes.&lt;br /&gt;
&lt;br /&gt;
Thinking about this led to a conundrum; If we support multiple wires, we have to support multiple transport protocols which are compatible with those wires. And if we support multiple transport protocols, we have to know which one our target implements. To make the API as simple as possible, we must not force clients to choose from configurable options (for a bad example) that requires a large degree of changes for each different type of connection made. How do we simplify the API so that a user can just plain connect without doing any pre-setup work?&lt;br /&gt;
&lt;br /&gt;
Answer: The [http://en.wikipedia.org/wiki/URI_scheme URI scheme]. The unfortunate downside to this solution is that it is undesired to use URI schemes without registering them with IANA. However, an argument could be made that these schemes would not be used for general network/internet communication. A few popular examples of similarly non-networked schemes are the file: and about: URI schemes. (The exception here is that at least one physical layer (LAN) could be used for over-the-internet communication; but this has great benefits in its own right.)&lt;br /&gt;
&lt;br /&gt;
===Example URI Schemes===&lt;br /&gt;
&lt;br /&gt;
The following table represents some examples of how URI schemes could be used as debugger protocols:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp://192.168.1.20/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | TCP/IP to remote host 192.168.1.20 on a pre-defined default port&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+udp://192.168.1.20:9424/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UDP/IP to remote host 192.168.1.20 on port 9424&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+usb://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | USB (SRDP-compatible devices) on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+uart://localhost:3/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | UART COM port 3 on localhost&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;nowiki&amp;gt;srdp+dbus://localhost/&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | DBUS IPC on localhost&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'srdp' prefix on these examples is to specify the 'Scalable Remote Debugger Protocol.' The + and suffix defines an additional layer (or protocol) below SRDP.&lt;br /&gt;
&lt;br /&gt;
The latter three examples look a bit odd with localhost being the destination, but this is necessary, since the localhost ''is'' the destination for hosting the UART RS-232 port, USB port, and IPC interface. Using non-loopback interfaces (IP addresses outside of the local machine) with these protocols should be undefined, unless there is evidence that connecting to RS-232/USB/IPC interfaces on other machines across a network is practical and plausible.&lt;br /&gt;
&lt;br /&gt;
===Simplified Configuration===&lt;br /&gt;
&lt;br /&gt;
These URI schemes give a very simple and elegant solution to the concerns they address. No longer will you be stuck with complicated configuration settings like the example below (upper left group box) ... and this is not an incredibly complex configuration dialog, as it is; instead, connecting to ANY low-level debugger in the world will be as simple as typing a URL.&lt;br /&gt;
&lt;br /&gt;
Example of what '''''not''''' to do:&lt;br /&gt;
&lt;br /&gt;
[[Image:Gscc_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Operation Groups===&lt;br /&gt;
&lt;br /&gt;
The protocol is defined as a set of usable &amp;quot;requests&amp;quot; (AKA &amp;quot;operations&amp;quot; or &amp;quot;commands&amp;quot;) requested by the client to the debugger, or vice-versa. Operations should be grouped according to a specific metric. The metric I've chosen is hardware (architecture) relationships. The table below shows an example of such groups (currently 6 in total) and example operations assigned to each group.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 1)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Diagnostics (Init, Shutdown, Ping/Pong, Reset, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 2)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | CPU handling (Get/set process states, register read/write, arbitrary code execution, general CPU control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 3)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Memory handling (read, write, address conversion, hardware I/O, cache control, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 4)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Breakpoint handling (add, delete, edit, get, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 5)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Stream handling (stdin/stdout/stderr, debugger-specific messages, ...)&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | 6)&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Vendor-specific (custom command sets, should be discouraged unless absolutely necessary)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Proposal==&lt;br /&gt;
&lt;br /&gt;
This section defines a proposed specification which may be adopted as the &amp;quot;Scalable Remote Debugger Protocol&amp;quot;. It is considered a work in progress and is currently open for peer-review, meaning we are interested in receiving comments, criticisms, and suggestions.&lt;br /&gt;
&lt;br /&gt;
===Protocol Goals===&lt;br /&gt;
&lt;br /&gt;
Goals of the protocol include:&lt;br /&gt;
&lt;br /&gt;
# '''Client/server relationship''': Target (debuggee) acts as a server, quietly listening for any SRDP requests; User Interface acts as a client, making explicit requests to a listening server.&lt;br /&gt;
# '''Asynchronous requests''': A client must send requests without expecting an immediate response. A server accepting requests may not respond immediately to those requests.&lt;br /&gt;
# '''Scalable''': The data structure (format) used in the protocol must be adaptable to the future; The structure must be as forgiving and dynamic as possible, avoiding fixed contents (except where absolutely necessary) and allowing for [non-mission-critical] non-standard contents.&lt;br /&gt;
# '''Easy to implement''': Basic features of the protocol should be easy to implement from an API point-of-view, as well as having a small memory footprint; the protocol must be usable on small embedded machines with few resources.&lt;br /&gt;
# '''Robust''': Ambiguity should be kept to a minimum in all aspects of the protocol; every bit transferred should have a useful meaning.&lt;br /&gt;
# '''Easy to debug''': A debugger protocol that cannot itself be debugged (observed and verified to work as expected) is a failure in and of itself. For this reason, the protocol should be human-readable in its most basic form.&lt;br /&gt;
&lt;br /&gt;
===Underlying Protocols===&lt;br /&gt;
&lt;br /&gt;
There are no reservations on any underlying protocols (protocols used to move data from the client to the server, and back again -- SRDP is not one of these protocols). The only requirement is that they provide hand-shaking (transmission control), sequential ordering of packet data arrival, and data integrity checking. Some examples of suitable underlying protocols include [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/UDP/IP], and [http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART].&lt;br /&gt;
&lt;br /&gt;
The initial reference implementation will use TCP/IP for remote connections. For local-listening servers, the reference implementation will use UNIX Domain Sockets on UNIX-like operating systems, and Named Pipes on Windows.&lt;br /&gt;
&lt;br /&gt;
===Protocol Packet Data Structure===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;goals&amp;quot; section outlines the major features which formed the following data structure. Inspiration comes mainly from [http://en.wikipedia.org/wiki/JSON JSON], the JavaScript Object Notation. As JSON is a serialization [text format] of JavaScript objects, the SRDP data structure is a serialization of the data being transmitted.&lt;br /&gt;
&lt;br /&gt;
The structure also shares some inspiration from [http://en.wikipedia.org/wiki/Remote_procedure_call RPC]; An example is that your client may want to read work RAM from the target. The SRDP request for &amp;quot;read memory&amp;quot; is technically similar to remotely running a &amp;quot;read memory&amp;quot; function on the server, invoked by the client. For this reason, each SRDP packet contains one or more &amp;quot;arguments&amp;quot; which you could imagine are passed directly to a plain old function.&lt;br /&gt;
&lt;br /&gt;
Each packet is sent as a series of 8-bit bytes. Packets are broken down into a series of &amp;quot;arguments&amp;quot;. Each argument has a name (made of one or more characters: alpha-numeric, underscore (_), or hyphen (-). The argument name is followed by a colon (:) and then a single byte representing the data type of the argument, then an equals sign (=) and the argument's value. All arguments are &amp;quot;closed&amp;quot; with a semi-colon (;).&lt;br /&gt;
&lt;br /&gt;
The argument syntax is similar to that of [http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]. In pseudo-form, it looks something like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:{type}={value};&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Valid data types:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | {type}&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Name&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; background-color: #303030;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | n&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any positive integer, encoded as a [http://www.dlugosz.com/ZIP2/VLI.html VLI]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | s&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Signed Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any negative integer, encoded as a [http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement one's complement] VLI&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | f&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Floating Point Number&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Any non-integer number, Infinity, or [http://en.wikipedia.org/wiki/NaN NaN], encoded as a null-terminated UTF-8 string, or null-terminated UTF-16 or UTF-32 string with BOM; To be decoded by [http://en.wikipedia.org/wiki/Scanf#Format_string_specifications sscanf]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | a&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob), preceded by a VLI to indicate the length of the array.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | c&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Compressed Array&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Byte-array (binary blob) with [http://en.wikipedia.org/wiki/Run-length_encoding RLE] compression. See [[#Compressed Array Data Type]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | t&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Text&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | Null-terminated UTF-8 string without [http://en.wikipedia.org/wiki/Byte-order_mark BOM], or null-terminated UTF-16 or UTF-32 string with BOM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some example arguments. (Please keep in mind that all of the argument names listed within this section are for demonstration purposes only, and are not recommended for reference purposes.)&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | msg:t=Hello, World!␀;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | num:n=□;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | pi:f=3.141592␀;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | ram_dump:a=□■■■■;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | my-compressed-data:c=□□■■■■□■□■■■;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
What the symbols mean:&lt;br /&gt;
&lt;br /&gt;
  ␀: Null-terminator&lt;br /&gt;
  □: VLI&lt;br /&gt;
  ■: Data byte&lt;br /&gt;
&lt;br /&gt;
====Compressed Array Data Type====&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; padding: 10px;&amp;quot; | '''''One suggestion is making this data-type optional, and changing this spec to use a standard library, like zlib. In this way, slow machines with few resources can adhere to the SRDP spec without wasting precious footprint space and computational power implementing such &amp;quot;heavy&amp;quot; libraries.'''''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Compressed arrays are similar to the standard &amp;quot;Array&amp;quot; data type. The compressed array starts with a single VLI to represent the total data size of the value (e.g. the size of the compressed data, ''x''). The following data is a series of alternating raw data and RLE data.&lt;br /&gt;
&lt;br /&gt;
# '''Raw Data''': A VLI representing raw data size in bytes (''n''), followed by ''n'' bytes of actual data.&lt;br /&gt;
# '''RLE Data''': A VLI representing RLE data size in bytes (''n''), followed by a single byte to be repeated (''n'' + 4) times in the output.&lt;br /&gt;
&lt;br /&gt;
This series is repeated until there are no more bytes to be read from input (''x'' bytes of the argument value have been read).&lt;br /&gt;
&lt;br /&gt;
For the RLE compression to be useful (efficient) it must not be used for any less than 4 bytes (therefore, the VLI is said to be a &amp;quot;4-based&amp;quot; number). The number 4 is derived from the minimum overhead introduced by the serial alternation and VLIs; 1 VLI for RLE output length, 1 byte of RLE data, 1 VLI for raw data length.&lt;br /&gt;
&lt;br /&gt;
Thus, in order for the RLE to perform &amp;quot;compression&amp;quot;, the RLE output must be larger than the smallest sequence required to switch from raw data and back again. Some examples to illustrate, '''''bold-italic''''' bytes are for VLI &amp;quot;control sequences&amp;quot; (the data lengths specified above):&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 1'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 01&lt;br /&gt;
 &lt;br /&gt;
 Incorrectly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''&amp;lt;u&amp;gt;03&amp;lt;/u&amp;gt;''''' 00 '''''01''''' 01&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''08''''' 94 24 51 73 00 00 00 01&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 2'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 94 24 51 73 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''04''''' 94 24 51 73 '''''00''''' 00&lt;br /&gt;
&lt;br /&gt;
 '''EXAMPLE 3'''&lt;br /&gt;
 &lt;br /&gt;
 Non-compressed data:&lt;br /&gt;
 00 00 00 00 00 00 00 00&lt;br /&gt;
 &lt;br /&gt;
 Correctly compressed data:&lt;br /&gt;
 '''''00''''' '''''04''''' 00&lt;br /&gt;
&lt;br /&gt;
The reason the second line in example 1 above is &amp;quot;incorrectly&amp;quot; compressed is because the second VLI is expecting the length to be 0-based. If this was the case, you would be simply adding overhead to replace any bytes saved by the &amp;quot;compression&amp;quot;. For this reason, the &amp;quot;correct&amp;quot; way to compress the example is to use a single length of raw data. This example is non-compressible, and should not be sent as a compressed array data type.&lt;br /&gt;
&lt;br /&gt;
In the second example, the data can be compressed nicely, saving a byte overall (including compression overhead). Since this is the &amp;quot;correct&amp;quot; way to compress the data, it is using a 4-based VLI on the RLE Data: &amp;quot;'''''00'''''&amp;quot; means 4 bytes of output, &amp;quot;'''''01'''''&amp;quot; means 5 bytes, &amp;quot;'''''02'''''&amp;quot; means 6 bytes, etc.&lt;br /&gt;
&lt;br /&gt;
The third example shows how to compress a series of bytes that starts with repeating data, instead of non-repeating &amp;quot;raw data&amp;quot;. The first VLI of '''''00''''' means there is no raw data for output (this is required: compressed arrays always begin with the Raw Data, followed by RLE Data). The second VLI '''''04''''' is the length of the RLE Data; 8 bytes. Even if the non-compressed data was 4 bytes of &amp;quot;00&amp;quot;, the compressed array would still be only 3 bytes of total data, saving one byte. This helps explain the reasoning behind the 4-based VLI for RLE Data.&lt;br /&gt;
&lt;br /&gt;
====Object Data Type====&lt;br /&gt;
&lt;br /&gt;
The basic structure and data types shown so far are very powerful; your server can tell the client vast amounts of information, such as CPU architecture, memory maps, I/O maps, etc. with just a handful of arguments. However, grouping these arguments in a meaningful way may be difficult. You might be inclined to do some &amp;quot;mock&amp;quot; namespacing, like prefixing each CPU-related argument with &amp;quot;cpu_&amp;quot;. This is effective, but also slightly wasteful and error-prone.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;object&amp;quot; data type is designed to handle such situations. This data type allows an argument to be a container for other arguments. Its format looks like this:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | {name}:[...];&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Where the set of ellipses denotes one or more &amp;quot;regular&amp;quot; arguments. Here is an example of what a &amp;quot;cpu&amp;quot; object might look like:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀;&lt;br /&gt;
:name:t=ARM946E-S␀;&lt;br /&gt;
];&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
(Note the white-space is for readability only; it is not meant to be transferred as part of the protocol data.)&lt;br /&gt;
&lt;br /&gt;
In this example, the &amp;quot;cpu&amp;quot; object contains two arguments: cpu.arch and cpu.name; both strings.&lt;br /&gt;
&lt;br /&gt;
But there are also times when you will want your server to send that same information for two [or more] CPU architectures on a single target. Some platforms may have multiple CPUs, each with its own individual set of resources (memory maps and the like), as well as shared resources between the CPUs. For this, the packet data structure needs a more advanced method of communicating these kinds of details.&lt;br /&gt;
&lt;br /&gt;
For this case, you can optionally create arrays of objects by including a comma (,) after the closing square bracket, followed by another series of arguments enclosed in their own square brackets, ''ad infinitum''.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;cpu:[&lt;br /&gt;
:arch:t=ARM␀;&lt;br /&gt;
:name:t=ARM946E-S␀;&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:arch:t=ARM␀;&lt;br /&gt;
:name:t=ARM7TDMI␀;&lt;br /&gt;
];&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now our &amp;quot;cpu&amp;quot; object defines two CPUs: an ARM9 and ARM7, ready for Nintendo DS hacking. These arguments can be referenced as cpu[0].arch, cpu[0].name, cpu[1].arch, and cpu[1].name respectively.&lt;br /&gt;
&lt;br /&gt;
Objects can be arbitrarily complex, containing arrays of other objects. Here is an example of a simple memory map, containing Work RAM (read/write/execute) and ROM (read/execute) sections. The Work RAM section is broken into two distinct memory ranges. This is quite easily expressed:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;border-collapse: collapse; width: 100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000;&amp;quot; | &amp;lt;tt&amp;gt;memory:[&lt;br /&gt;
:name:t=Work RAM␀;&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□;&lt;br /&gt;
::end:n=□;&lt;br /&gt;
:],&amp;lt;br/&amp;gt;&lt;br /&gt;
:[&lt;br /&gt;
::start:n=□;&lt;br /&gt;
::end:n=□;&lt;br /&gt;
:];&lt;br /&gt;
:flags:t=RWX␀;&lt;br /&gt;
],&amp;lt;br/&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
:name:t=ROM␀;&lt;br /&gt;
:range:[&lt;br /&gt;
::start:n=□;&lt;br /&gt;
::end:n=□;&lt;br /&gt;
:];&lt;br /&gt;
:flags:t=RX␀;&lt;br /&gt;
];&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comments===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Protocol Goals&amp;quot; have lead much of the motivation for developing this proposal. This presents what seems to be several very strange choices, at first glance. The choice of representing floating point numbers as a string of text seems extremely odd, until you consider that using the target-native floating point data format would make no sense when sending that data to a remote client (which is most likely running on a different architecture, and may have totally different native floating point formats). In order to express floating points with arbitrary precision in a data format-agnostic way, it is necessary to use a non-native format like text.&lt;br /&gt;
&lt;br /&gt;
Another oddity in this spec is the use of VLIs (variable-length integers) and their affect on the rest of the format. The main purpose for using VLIs is address widths. Some architectures can express their full address range within a single byte. Others require up to 8 bytes for a full 64-bit address range. Future architectures are by no means limited to 64-bit address widths. For this very reason, it is necessary to scale down as well as up. A VLI can express an address in as little as a single byte, or scale upward to arbitrarily large numbers. This makes VLIs perfect for addressing requirements among any architecture.&lt;br /&gt;
&lt;br /&gt;
VLIs present their own issues, however. For example, expressing a negative number as a VLI is nearly incomprehensible. Some might be inclined to reserve one bit within a VLI to indicate signedness, but that's another bit that cannot be used to minimize VLI overhead. The overhead is additional bytes required to represent a full number in a VLI system. For example, it is common for numbers 0 - 127 to be contained entirely within a single byte, including the overhead. But numbers between 128 - 255 require an additional byte to include more VLI &amp;quot;header&amp;quot; information (used to extend VLIs into arbitrarily long numbers). This is counter-intuitive, where a single byte itself can hold numbers between 0 - 255. Adding an additional sign bit reduces the range of VLIs by half: a single byte can only encode numbers between 0 - 63.&lt;br /&gt;
&lt;br /&gt;
The solution is to use a different data type specifically for expressing negative numbers. The VLI is encoded just like a positive number, but when interpreting the VLI, it must be converted to a negative number by either subtracting from zero (0 - ''n'') or multiplying by negative one (''n'' * -1). This is referred to as a &amp;quot;one's complement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In general, the efficiency of a VLI is very static. That means, a number using 0 - 7 bits of data (for example, the number &amp;quot;0&amp;quot; uses 0 bits of data, and the number &amp;quot;64&amp;quot; [binary: 100000] uses 6 bits) can be encoded into a single byte, a number using 8 - 14 bits can be encoded into 2 bytes, a number using 15 - 21 bits can be encoded into 3 bytes, etc. See http://www.dlugosz.com/ZIP2/VLI.html for more information on the kind of VLI I am considering for this proposal.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer_Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=RLM&amp;diff=984</id>
		<title>RLM</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=RLM&amp;diff=984"/>
				<updated>2009-12-27T04:06:44Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Lunar Magic Protection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;RLM is a program designed to &amp;quot;unprotect&amp;quot; Super Mario World ROM hacks that were &amp;quot;protected&amp;quot; with the Lunar Magic level editor. RLM stands for &amp;quot;Recover Lunar Magic&amp;quot;. Also seen in the source code, &amp;quot;Rape Lunar Magic&amp;quot; was once considered.&lt;br /&gt;
&lt;br /&gt;
==Version History==&lt;br /&gt;
&lt;br /&gt;
v1.3 (12-26-09):&lt;br /&gt;
* Fixed yet another last-known-problem with (what I believe is) &amp;quot;Super ExGFX&amp;quot;.&lt;br /&gt;
* Support for drag-n-drop (see &amp;quot;Using RLM&amp;quot;).&lt;br /&gt;
* Readme cleanup.&lt;br /&gt;
&lt;br /&gt;
v1.2 (04-18-05):&lt;br /&gt;
* Fixed the last known problem with OverWorld decryption.&lt;br /&gt;
&lt;br /&gt;
v1.1 (01-16-05):&lt;br /&gt;
* Fixed a problem with OverWorld decryption.&lt;br /&gt;
* Changed copyright years from 2003-2004 to 2003-2005.&lt;br /&gt;
* Added a version number define to make version changes easier.&lt;br /&gt;
&lt;br /&gt;
v1.0 (01-13-05):&lt;br /&gt;
* Initial release!&lt;br /&gt;
&lt;br /&gt;
==Lunar Magic Protection==&lt;br /&gt;
&lt;br /&gt;
The protection scheme used by Lunar Magic is simple albeit effective against inexperienced hackers. When protecting a hack, the editor will write a few bytes into the SMC header as well as the SNES ROM header which it uses to signal to itself that the ROM is protected. Reversing these changes is enough to bypass the &amp;quot;Lunar Magic cannot open this ROM&amp;quot; message, but you will run into trouble when you open the edited stages.&lt;br /&gt;
&lt;br /&gt;
Almost everything that Lunar Magic edits will be encrypted with a simple XOR operation, when a hack is protected; unedited stages and objects will remain in their original, unencrypted state.&lt;br /&gt;
&lt;br /&gt;
The first thing encrypted is the stage pointers. To anyone looking in a hex editor, they appear to point to invalid stage data (because they do). Decrypting these pointers shows you were to find the valid &amp;quot;RATS&amp;quot; headers, as well as encrypted stage data. At this point, decrypting the stage data is enough to open the hack in Lunar Magic. However, the ROM will not work on an SNES or an emulator, due to an assembly hack in place which will try to decrypt the already-decrypted stage data. Reverting the assembly hack will make the ROM playable.&lt;br /&gt;
&lt;br /&gt;
Other edited objects in the ROM are also encrypted in a similar manner. The overworld is a particularly big example. I believe the &amp;quot;ExGFX&amp;quot; are also encrypted.&lt;br /&gt;
&lt;br /&gt;
==RLM Specifics==&lt;br /&gt;
&lt;br /&gt;
RLM contains code which allows it to handle LoROM and ExHiROM SNES ROMs in the SMC format. The main decryption loop, decryptLunar(), is a very simplified Super Mario World stage data parser. Most data blocks in this stage format are 3 bytes, but some are 4 or 5 bytes. RLM has to understand this concept (at the very least) in order to decrypt the stage data properly; Only the first two bytes of each block are encrypted.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
RLM is available under the terms of the [http://www.gnu.org/licenses/gpl.html GNU General Public License]. You can download the zip/gz/bz2 compressed source code from [http://hg.kodewerx.org/rlm kwhg] or if you have Mercurial, clone the source code repository with the following command:&lt;br /&gt;
&lt;br /&gt;
 hg clone http://hg.kodewerx.org/rlm&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
 $ ./rlm&lt;br /&gt;
 RLM (Recover Lunar Magic) - v1.3&lt;br /&gt;
 Copyright 2003-2009 Parasyte (parasyte@kodewerx.org)&lt;br /&gt;
 http://www.kodewerx.org/&lt;br /&gt;
 &lt;br /&gt;
 Usage: ./rlm &amp;lt;in-file.smc&amp;gt; [out-file.smc]&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;in-file.smc&amp;gt; is the name of the protected Super Mario World ROM, and [out-file.smc] is the file name that you want RLM to create with the unprotected data. Note that [out-file.smc] is optional; if not specified, it will create a new file with the extension of the input file name changed to &amp;quot;.unlocked.smc&amp;quot;. For example, &amp;quot;in-file.smc&amp;quot; becomes &amp;quot;in-file.unlocked.smc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=RLM&amp;diff=983</id>
		<title>RLM</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=RLM&amp;diff=983"/>
				<updated>2009-12-27T04:05:50Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;RLM is a program designed to &amp;quot;unprotect&amp;quot; Super Mario World ROM hacks that were &amp;quot;protected&amp;quot; with the Lunar Magic level editor. RLM stands for &amp;quot;Recover Lunar Magic&amp;quot;. Also seen in the source code, &amp;quot;Rape Lunar Magic&amp;quot; was once considered.&lt;br /&gt;
&lt;br /&gt;
==Lunar Magic Protection==&lt;br /&gt;
&lt;br /&gt;
The protection scheme used by Lunar Magic is simple albeit effective against inexperienced hackers. When protecting a hack, the editor will write a few bytes into the SMC header as well as the SNES ROM header which it uses to signal to itself that the ROM is protected. Reversing these changes is enough to bypass the &amp;quot;Lunar Magic cannot open this ROM&amp;quot; message, but you will run into trouble when you open the edited stages.&lt;br /&gt;
&lt;br /&gt;
Almost everything that Lunar Magic edits will be encrypted with a simple XOR operation, when a hack is protected; unedited stages and objects will remain in their original, unencrypted state.&lt;br /&gt;
&lt;br /&gt;
The first thing encrypted is the stage pointers. To anyone looking in a hex editor, they appear to point to invalid stage data (because they do). Decrypting these pointers shows you were to find the valid &amp;quot;RATS&amp;quot; headers, as well as encrypted stage data. At this point, decrypting the stage data is enough to open the hack in Lunar Magic. However, the ROM will not work on an SNES or an emulator, due to an assembly hack in place which will try to decrypt the already-decrypted stage data. Reverting the assembly hack will make the ROM playable.&lt;br /&gt;
&lt;br /&gt;
Other edited objects in the ROM are also encrypted in a similar manner. The overworld is a particularly big example. I believe the &amp;quot;ExGFX&amp;quot; are also encrypted.&lt;br /&gt;
&lt;br /&gt;
==RLM Specifics==&lt;br /&gt;
&lt;br /&gt;
RLM contains code which allows it to handle LoROM and ExHiROM SNES ROMs in the SMC format. The main decryption loop, decryptLunar(), is a very simplified Super Mario World stage data parser. Most data blocks in this stage format are 3 bytes, but some are 4 or 5 bytes. RLM has to understand this concept (at the very least) in order to decrypt the stage data properly; Only the first two bytes of each block are encrypted.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
RLM is available under the terms of the [http://www.gnu.org/licenses/gpl.html GNU General Public License]. You can download the zip/gz/bz2 compressed source code from [http://hg.kodewerx.org/rlm kwhg] or if you have Mercurial, clone the source code repository with the following command:&lt;br /&gt;
&lt;br /&gt;
 hg clone http://hg.kodewerx.org/rlm&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
 $ ./rlm&lt;br /&gt;
 RLM (Recover Lunar Magic) - v1.3&lt;br /&gt;
 Copyright 2003-2009 Parasyte (parasyte@kodewerx.org)&lt;br /&gt;
 http://www.kodewerx.org/&lt;br /&gt;
 &lt;br /&gt;
 Usage: ./rlm &amp;lt;in-file.smc&amp;gt; [out-file.smc]&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;in-file.smc&amp;gt; is the name of the protected Super Mario World ROM, and [out-file.smc] is the file name that you want RLM to create with the unprotected data. Note that [out-file.smc] is optional; if not specified, it will create a new file with the extension of the input file name changed to &amp;quot;.unlocked.smc&amp;quot;. For example, &amp;quot;in-file.smc&amp;quot; becomes &amp;quot;in-file.unlocked.smc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=RLM&amp;diff=982</id>
		<title>RLM</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=RLM&amp;diff=982"/>
				<updated>2009-12-27T04:05:23Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;RLM is a program designed to &amp;quot;unprotect&amp;quot; Super Mario World ROM hacks that were &amp;quot;protected&amp;quot; with the Lunar Magic level editor. RLM stands for &amp;quot;Recover Lunar Magic&amp;quot;. Also seen in the source code, &amp;quot;Rape Lunar Magic&amp;quot; was once considered.&lt;br /&gt;
&lt;br /&gt;
==Lunar Magic Protection==&lt;br /&gt;
&lt;br /&gt;
The protection scheme used by Lunar Magic is simple albeit effective against inexperienced hackers. When protecting a hack, the editor will write a few bytes into the SMC header as well as the SNES ROM header which it uses to signal to itself that the ROM is protected. Reversing these changes is enough to bypass the &amp;quot;Lunar Magic cannot open this ROM&amp;quot; message, but you will run into trouble when you open the edited stages.&lt;br /&gt;
&lt;br /&gt;
Almost everything that Lunar Magic edits will be encrypted with a simple XOR operation, when a hack is protected; unedited stages and objects will remain in their original, unencrypted state.&lt;br /&gt;
&lt;br /&gt;
The first thing encrypted is the stage pointers. To anyone looking in a hex editor, they appear to point to invalid stage data (because they do). Decrypting these pointers shows you were to find the valid &amp;quot;RATS&amp;quot; headers, as well as encrypted stage data. At this point, decrypting the stage data is enough to open the hack in Lunar Magic. However, the ROM will not work on an SNES or an emulator, due to an assembly hack in place which will try to decrypt the already-decrypted stage data. Reverting the assembly hack will make the ROM playable.&lt;br /&gt;
&lt;br /&gt;
Other edited objects in the ROM are also encrypted in a similar manner. The overworld is a particularly big example. I believe the &amp;quot;ExGFX&amp;quot; are also encrypted.&lt;br /&gt;
&lt;br /&gt;
==RLM Specifics==&lt;br /&gt;
&lt;br /&gt;
RLM contains code which allows it to handle LoROM and ExHiROM SNES ROMs in the SMC format. The main decryption loop, decryptLunar(), is a very simplified Super Mario World stage data parser. Most data blocks in this stage format are 3 bytes, but some are 4 or 5 bytes. RLM has to understand this concept (at the very least) in order to decrypt the stage data properly; Only the first two bytes of each block are encrypted.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
RLM is available under the terms of the [http://www.gnu.org/licenses/gpl.html GNU General Public License]. You can download the zip/gz/bz2 compressed source code from [http://hg.kodewerx.org/rlm kwhg] or if you have Mercurial, clone the source code repository with the following command:&lt;br /&gt;
&lt;br /&gt;
 hg clone http://hg.kodewerx.org/rlm&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
 $ ./rlm&lt;br /&gt;
 RLM (Recover Lunar Magic) - v1.3&lt;br /&gt;
 Copyright 2003-2005 Parasyte&lt;br /&gt;
 &lt;br /&gt;
 Usage: ./rlm &amp;lt;in-file.smc&amp;gt; [out-file.smc]&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;in-file.smc&amp;gt; is the name of the protected Super Mario World ROM, and [out-file.smc] is the file name that you want RLM to create with the unprotected data. Note that [out-file.smc] is optional; if not specified, it will create a new file with the extension of the input file name changed to &amp;quot;.unlocked.smc&amp;quot;. For example, &amp;quot;in-file.smc&amp;quot; becomes &amp;quot;in-file.unlocked.smc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	<entry>
		<id>https://www.kodewerx.org/w/index.php?title=RLM&amp;diff=981</id>
		<title>RLM</title>
		<link rel="alternate" type="text/html" href="https://www.kodewerx.org/w/index.php?title=RLM&amp;diff=981"/>
				<updated>2009-12-24T19:33:03Z</updated>
		
		<summary type="html">&lt;p&gt;Parasyte: /* Lunar Magic Protection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;RLM is a program designed to &amp;quot;unprotect&amp;quot; Super Mario World ROM hacks that were &amp;quot;protected&amp;quot; with the Lunar Magic level editor. RLM stands for &amp;quot;Recover Lunar Magic&amp;quot;. Also seen in the source code, &amp;quot;Rape Lunar Magic&amp;quot; was once considered.&lt;br /&gt;
&lt;br /&gt;
==Lunar Magic Protection==&lt;br /&gt;
&lt;br /&gt;
The protection scheme used by Lunar Magic is simple albeit effective against inexperienced hackers. When protecting a hack, the editor will write a few bytes into the SMC header as well as the SNES ROM header which it uses to signal to itself that the ROM is protected. Reversing these changes is enough to bypass the &amp;quot;Lunar Magic cannot open this ROM&amp;quot; message, but you will run into trouble when you open the edited stages.&lt;br /&gt;
&lt;br /&gt;
Almost everything that Lunar Magic edits will be encrypted with a simple XOR operation, when a hack is protected; unedited stages and objects will remain in their original, unencrypted state.&lt;br /&gt;
&lt;br /&gt;
The first thing encrypted is the stage pointers. To anyone looking in a hex editor, they appear to point to invalid stage data (because they do). Decrypting these pointers shows you were to find the valid &amp;quot;RATS&amp;quot; headers, as well as encrypted stage data. At this point, decrypting the stage data is enough to open the hack in Lunar Magic. However, the ROM will not work on an SNES or an emulator, due to an assembly hack in place which will try to decrypt the already-decrypted stage data. Reverting the assembly hack will make the ROM playable.&lt;br /&gt;
&lt;br /&gt;
Other edited objects in the ROM are also encrypted in a similar manner. The overworld is a particularly big example. I believe the &amp;quot;ExGFX&amp;quot; are also encrypted.&lt;br /&gt;
&lt;br /&gt;
==RLM Specifics==&lt;br /&gt;
&lt;br /&gt;
RLM contains code which allows it to handle LoROM and ExHiROM SNES ROMs in the SMC format. The main decryption loop, decryptLunar(), is a very simplified Super Mario World stage data parser. Most data blocks in this stage format are 3 bytes, but some are 4 or 5 bytes. RLM has to understand this concept (at the very least) in order to decrypt the stage data properly; Only the first two bytes of each block are encrypted.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
RLM is available under the terms of the [http://www.gnu.org/licenses/gpl.html GNU General Public License]. You can download the zip/gz/bz2 compressed source code from [http://hg.kodewerx.org/rlm kwhg] or if you have Mercurial, clone the source code repository with the following command:&lt;br /&gt;
&lt;br /&gt;
 hg clone http://hg.kodewerx.org/rlm&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
 $ ./rlm&lt;br /&gt;
 RLM (Recover Lunar Magic) - v1.2&lt;br /&gt;
 Copyright 2003-2005 Parasyte&lt;br /&gt;
 &lt;br /&gt;
 Usage: ./rlm &amp;lt;infile&amp;gt; &amp;lt;outfile&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;infile&amp;gt; is the name of the protected Super Mario World ROM, and &amp;lt;outfile&amp;gt; is the filename that you want RLM to create with the unprotected data.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer Documentation]]&lt;/div&gt;</summary>
		<author><name>Parasyte</name></author>	</entry>

	</feed>