RBJ (Redcode oBJect)

RBJ format belongs to XRK - Extra Redcode Kit, a complete Core Wars system for DOS by Marco Pontello. RBJ files contains an assembled binary version of a Redcode Warrior, usually written by the XRA - Extra Redcode Assembler. RBJ files also contains info about the warrior's author, name and version of the assembler used, date & time.

File structure overview
An RBJ file is composed of 3 sections: Header, Code, Tail

The Tail is represented by 1 byte used as a checksum. To verify the integrity of a RBJ file, simply compare this value to the calculated checksum of the first (filesize - 1) bytes (that is Header + Code).

Structure Descriptions
Int = 2 bytes in Little-endian format.

Header
The Header is 75 bytes long, and is composed as follow:

Pos Field           Len Data - 0  Version ID        1 Byte - decimal 1 Author           30 Chars 31 Made with        30 Chars 61 Serial Date&Time  8 FP64 69 Split Flag        1 Byte 70 Reserved          1 Byte 71 Program Len       2 Int 73 Start             2 Int

Code
The Code block is a sequence of (Program Len) blocks as follow:

Field          Len Data - 0  Command           1 Byte +1 Mode A / B        1 Byte +2 Operand A         2 Int +4 Operand B         2 Int

Tail
One Byte as a checksum:

Field          Len Data - 0  CheckByte         1 Byte -

Version ID
Decimal (Major ver. * 10 + Minor ver.) Ex: 12 = v1.2

Author
Warrior's programmer Name/Nick

Made with
Assembler used

Serial Date&Time
Floating Point value: Dec * 86400 = seconds from midnight / Int = days from some date

Split Flag
0 = No SPL opcode used (program doesn't split) !0 = Program may use SPL

Reserved
Not used

Program Len
Instructions count, length of the code block

Start
Point to the instruction where execution start

Command
0 DAT 1 MOV 2 ADD 3 SUB 4 JMP 5 JMZ 6 JMN 7 DJN 8 CMP 9 (not used) 10 SPL

Mode A / B
Field A = low nibble Field B = high nibble

0 "#" Immediate 1 "$" Direct 2 "@" Indirect 3 "<" Indirect autodecremented

Operand A & B
2 bytes signed integer

CheckByte
Here's how to calc the checksum byte (in BASIC-like pseudocode): Sum = 0 FOR i = 1 TO BufferLen STEP 1 Sum = Sum + BufferByte(i) NEXT i FOR i = 1 TO BufferLen STEP 2 Sum = Sum + BufferByte(i) NEXT i FOR i = 1 TO BufferLen STEP 3 Sum = Sum + BufferByte(i) NEXT i FOR i = 1 TO BufferLen STEP 4 Sum = Sum + BufferByte(i) NEXT i Sum = Sum AND 255