If you are developing an addin repeated downloading to the rex takes time, and battery life and hiting the hard reset or flipping the battery hatch takes its toll on the hardware. Therefore it is much better to run your addin under an emulator.

Step 1 : Get an emulator.
Below is a screen shot of the DS2 emulator. Note the poor screen design requires a PC resolution of more than 1024*768 to operate - ruling out may laptops.


Once again what was available for the DS2 has been adapted for the Rex 6000. First Peter Kong improved the screen layout, and then Daniel Schmidt sucessfully changed it to work with an image of the Rex firmware. The result of this impressive work is shown below and you can download the latest version from Daniel's site.



Step 2 : Addin in an appropriate format
The emulators DO NOT RUN COMPILED ADDINS (.REX or .DS2).

There are two differences between the files the emulator runs and normal addin. Firstly the headers from the normal addin ie the Icon and the description fields must be removed. Secondly the binary file is represented in Motorola S record format. The file must be called addin1.out and placed in the same directory as the emulator.

If you are using a development kit, for example, the rexdk, it may automatically produce a file called "addin1.out" for you. If you have an existing compiled addin and you want to create an addin1.out file follow these steps.

Step 3 : Run the emulator Run the file "dsmain.exe" (same in both the dataslim and rex emulators) and then click the "run" button or press the spacebar.

You should see the firmware initiation sequence and have to calibrate the (virtual!) touchscreen. The DS2 emulator then begins addin execution. The Rex emulator shows the main menu, clicking "extras" begins execution.

Note that clicking "time sync" makes the emulator slow to close to true rex speed

Other emulator features
RUN  Loads firmware image, starts execution
PAUSE  Pause program execution
MEMORY  Shows the contents of memory
TRACE  Shows the trace window (see below)
SAVE  saves?
LOAD  loads?
LDPRG  Re-loads Addin code
RESET  Resets the emulator


Breakpoints here's an example of breakpoints:
Suppose the emulator is running your addin, and at some interesting point you press Pause. The Programcounter (PC) displays 8F15, and you'd like the emulator to stop here everytime it passes by. Bank1 points to (for example) 000F8000. Add the PC value to this value to get the breakpoint address of 00100F15. Enter this (8 digits) in the breakpoint textbox, and just to be sure move the focus away from the textbox eg by clicking another textbox. Each time the emulator gets to this address (even after pressing Run), it'll break here. Now you can step through and inspect calls, registers and what not. So if you want a breakpoint at $8000, just add the bank1 value your addin is running in to it.

Tracing: Declare DsTrace function in your code as follows:

static void DsTrace(char *s, ...)
{
    output8(0xfe, 0);
}

Open Trace window in Emulator pressing [TRACE] button.
In the code use
DsTrace to output debug info to Trace window.

void main(void)
{
  
int a;
  
a = 5;
    /* Output a=5 to Emulator TRACE Window */
  
DsTrace("a=%d \n", a);
}

Note: If you have DsTrace("bla-bla-bla"); - nothing appears. You have to put \n,
ie DsTrace("bla-bla-bla\n");

Also note above not tested on other than DSSDK (let me know if you've tried under rexdk)

Q How was the DS2 emulator turned into a rex emulator?
The Ds2 firmware is split up in 4 files. Those files are boot.out, emuemis.out, dataslim.out and fep9 out. Every file stores a different part of the firmware. Those files are "normal" motorola s-record files. The address space from 0x000000 to 0x007fff is stored in s1 records (2-byte address). The rest is stored in s2 records (3-byte address). The first 8K are stored in the boot.out file. From 0x002000 to 0x004fff the firmware is stored in emuemis.out.

0x005000 - 0x00bfff : Dataslim.out
0x00c000 - 0x04ffff : EmuEmis.out
0x050000 - 0x0bffff : Dataslim.out
0x0c0000 - 0x0fffff : Fep9.out

The addin1.out file is loaded into the first addin page. If you rebuild those files with the rex firmware, the rex firmware is correctly loaded and the emulator "boots" as a rex. With a little firmware modification the emulator directly jumps to the beginning of the first addin when tapping the extras button.