 Robot Warfare 1
 RW0 bytecode description
 Version 2.1

 Alexander A. Shabarshin [Chabarchine] (shaos@mail.ru)
 http://robots.shaos.ru

 November 1998 - September 2002


 Header:
 -------

0x0000: 0x00..0x02 // Version (0 for 1.*, 1 for 1.99, 2 for 2.*)
0x0001: 2 bytes // CheckSum (sum of bytes from 0x0005 to end)
0x0003: 2 bytes // Offset to bytecode entry point (in bytes)
0x0005: 1 byte  // Length of the robot name (strlen)
0x0006: N bytes // Robot name
0x????: 0x00    // Terminal character for robot name
0x????: 2 bytes // Number of variables (plus arrays length)
0x????: 2 bytes // Code length in bytes (beginning from start point)
0x????: 3 bytes // Robot color (R,G,B)
0x????: 4 bytes // Equipments on the FRONT,RIGHT,BACK,LEFT (0-empty,1-eye,2-gun)
0x????: 1 byte  // Image flag (0x00-image is absent, 0x20-image is present)
// if image present, then next 32 bytes describe the robot image (2pix/byte)
0x????: N bytes // Author nickname
0x????: 0x00    // Terminal character for author nickname
0x????: ?? ...  // Reserved for additional data
// after that follows bytecode 
START: // Entry point

 Bytecode:
 -----------------------------------------------------------------
 B - byte (1 byte)
 W - word (2 bytes - low byte + high byte)
 M - variable or constant (3-5 bytes):
     0x00 W - signed integer (-32K..+32K)
     0x01 W - variable in W cell (array[constant] is compiled to it too)
     0x02 W1 W2 - array element (W1-begin of array, W2-variables with offset)
 Registers are variables (0x01 0x?? 0xFF) with the addresses:
 0xFF00 - X // register for relative X value
 0xFF01 - Y // register for relative Y value
 0xFF02 - D // register for distance value
 0xFF03 - N // register for object value
 0xFF04 - K // register for additional value
 0xFF05 - R // register for random value
 0xFF06 - T // register for timer value
 0xFF07 - E // register for our energy value
 0xFF08 - M // register for our missiles number
 0xFF09 - I // register for order number of robot
 0xFF0A - A // A-register for read/write
 0xFF0B - B // B-register for read/write
 0xFF0C - C // C-register for read/write
 0xFF0D - P // register for command pointer
 0xFF0E - L // register for last value of big expression
 0xFF0F - S // register for stack length

 labW - label with address W
 *    - old commands - supported by interpreter only
 -    - free time commands during interpretation
-----------------------------------------------------------------

 0x01 W1 W2        // DEF arr[len]  (W1-offset to array start, W2-len)
 0x02 W1 W2 W3 ... // DEF arr[len]={list}  (W3-number of words)

*0x10 W M1 M2 // IF M1<M2 : labW
*0x11 W M1 M2 // IF M1>M2 : labW
*0x12 W M1 M2 // IF M1<=M2 : labW
*0x13 W M1 M2 // IF M1>=M2 : labW
*0x14 W M1 M2 // IF M1==M2 : labW
*0x15 W M1 M2 // IF M1!=M2 : labW

-0x20 M1 M2 // M1=M2
*0x21 M1 M2 // M1=-M2
*0x22 M1 M2 M3 // M1=M2+M3
*0x23 M1 M2 M3 // M1=M2-M3
*0x24 M1 M2 M3 // M1=M2/M3
*0x25 M1 M2 M3 // M1=M2*M3
*0x26 M1 M2 M3 // M1=M2%M3
*0x27 M1 M2 M3 // M1=M2&M3 - binary AND
*0x28 M1 M2 M3 // M1=M2|M3 - binary OR
*0x29 M1 M2 M3 // M1=M2^M3 - binary XOR
*0x2A M1 M2 // M1=~M2 - binary NOT

*0x30 W // GOTO labW
*0x31 W // CALL labW
-0x33 // RET
 0x34 // STEP
 0x35 // LEFT
 0x36 // RIGHT
 0x37 string 0x00 // SAY "string and/or &var"
*0x38 M // PRINT var
 0x3A M // ACT var (FRONT=0,RIGHT=1,BACK=2,LEFT=3)
 0x3B   // SPY
 0x3C M // RADAR var
 0x3F 0x00 B // DUMP B (Dump variables in the B columns)

 0x40 B ...  // var=expr (B bytes)
-0x41 M1 M2  // IFY var1 var2
-0x42 M1 M2  // IFN var1 var2
-0x43 M      // GOTO var
-0x44 M      // CALL var

*0x51 W ... 0x00 // TEST "wildcard" label
 0x52 ... 0x00   // TEST "wildcard" // result in L register

 0x60 M // SHOT avar // copy 16 registers values to [avar] 
 0x61 M1 M2 // SEND var1 var2 // send code var1 to robot var2
 0x62 M // RECV avar // receive code and save it to [avar]
-0x63   // POP
 0x64 M1 M2 // PIXEL varx vary
 0x65 M1 M2 // FILL vardx vardy // from last PIXEL with COLOR
 0x66 ... 00 // TEXT "string" // from last PIXEL with COLOR
 0x67 M // PLANE varn // set current plane for drawing (0 - default)
 0x68 M // COLOR varn // set current color
 0x69 M1 M2 // SELECT varx vary
 0x6A M1 M2 // SET var_plane [var_side] // default var_side=0
 0x70 M1 M2 // COPYP avar1 avar2 // copy packet [avar2] to [avar1]
 0x71 M1 M2 // SENDP avar var // send packet [avar] to robot var
 0x72 M // RECVP avar // receive packet and save it to [avar]
 0x7F M // COMMAND var // high-level command

 0xFF // END - end of bytecode


 Expressions
 -----------

 expr uses var,label,(,),?:,+,-,*,/,%,&,|,^,~,!,&&,||,=,==,>,<,>=,<=,!=,<<,>>

 0x80 // &&  A,B -> A&&B
 0x81 // ||  A,B -> A||B
 0x90 // ==  A,B -> A==B
 0x91 // !=  A,B -> A!=B
 0x92 // >   A,B -> A>B
 0x93 // <   A,B -> A<B
 0x94 // >=  A,B -> A>=B
 0x95 // <=  A,B -> A<=B
 0xA0 // +   A,B -> A+B
 0xA1 // -   A,B -> A-B
 0xB0 // *   A,B -> A*B
 0xB1 // /   A,B -> A/B
 0xB2 // %   A,B -> A%B
 0xC0 // &   A,B -> A&B
 0xC1 // |   A,B -> A|B
 0xC2 // ^   A,B -> A^B
 0xD0 // >>  A,B -> A>>B
 0xD1 // <<  A,B -> A<<B
 0xE0 // -   A -> -A (negative)
 0xE1 // ~   A -> ~A (bit inverse)
 0xE2 // !   A -> !A (logic NOT)
 0xF0 // ?:         A,B,C -> A?B:C
 0xF1 // DUP        A -> A,A
 0xF2 // ROL        A,B -> B,A
 0xF3 // LOAD       A -> mem[A]
 0xF4 // SAVE       A,B -> .  (mem[A]=B)
 0xF5 W // PUSH W   . -> W
 0xF6 // []         A,B -> A[B]


 Debug info
 ----------

 Debug info is added to end of RW0 code using option -d in RW1C v2.1.x.
 After code compiler writes zero-terminated word "DEBUG" and
 list of source files in form zero-terminated names. Two zero 
 bytes identify end of list. Then we have list of variables:

 ? bytes - NAME,0
 2 bytes - size of variable in words
 2 bytes - index of variable

 Then we have a number of 5-bytes structures:

 1 byte - index of source file
 2 bytes - number of line in the source file
 2 bytes - address in code

 End of structures is FF byte.
