The RGB ObjectFileFormats


Table of Contents




Background

I developed the RGB0 fileformat mainly because I needed a suitable dataformat to hold the output from xAsm that was powerful to accomodate all the features I needed and also would make it easy for me to add new ones. The reason for documenting it is so people can write converters between it and other formats. Perhaps even develop other compilers for it?

The RGB1 fileformat saw the light of day with the V1.02 of the old RGBDS release because of the addition of fixed sections.
The RGB2 fileformat emerged because I needed to add support for big endian CPUs.



FileStructure

LONG is a 32-bit integer stored in little-endian format (Intel)
BYTE is an 8-bit integer
STRING is a 0 terminated string of BYTE

Down to business...

    ; There's a header...

      

    BYTE    ID[4]                      ;"RGB0", "RGB1", "RGB2"

    LONG    NumberOfSymbols            ;The number of symbols used in this file

    LONG    NumberOfSections           ;The number of sections used in this file

      

    ; Now for some symbols

      

    REPT    NumberOfSymbols            ;NumberOfSymbols symboldefs follow

        STRING  Name                   ;The name of this symbol

        BYTE    Type                   ;0 = LOCAL symbol only used in this file

                                       ;1 = IMPORT this symbol from elsewhere


                                       ;2 = EXPORT this symbol to other objects

        IF      Type != 1

            LONG    SectionID          ;The section number in which this symbol

                                       ;is defined.  If -1 this symbol is an EQUate

            LONG Value                 ;The symbols value. If SectionID!=-1 it's the

                                       ;offset into that section

        ENDC

    ENDR

      

    ; And I'll be... Sections!

      

    REPT NumberOfSections

        LONG    Size                   ;Size in bytes of this section

        BYTE    Type                   ;0 = BSS

                                       ;1 = VRAM

                                       ;2 = CODE

                                       ;3 = HOME

                                       ;4 = HRAM

        LONG    Org                    ;Only present in RGB1. Address to fix this

                                       ;section at. -1 if the linker should

                                       ;decide (normal operation)

        LONG    Bank                   ;Only present in RGB1. Bank to load this

                                       ;section into. -1 if the linker should

                                       ;decide (normal operation). This field is

                                       ;only valid for CODE sections.

        IF      Type==CODE || Type==HOME

            BYTE Data[Size]

            LONG NumberOfPatches

               

            ; These types of sections may have patches

               

            REPT NumberOfPatches

                STRING    SourceFile   ;The name of the sourcefile (for

                                       ;printing an errormessage)

                LONG Line              ;The line of the sourcefile

                LONG Offset            ;Offset into the section where patch

                                       ;should be applied

                BYTE Type              ;0 = BYTE patch

                                       ;1 = little endian WORD patch

                                       ;2 = little endianLONG patch

                                       ;3 = big endian WORD patch (RGB2 and later)

                                       ;4 = big endianLONG patch (RGB2 and later)

                LONG RPNSize

                BYTE RPN[RPNSize]      ;RPN definition below

            ENDR

        ENDC

    ENDR



Rpn Data

Expressions in the objectfile are stored as RPN. This is an expression of the form "2 5 +". This will first push the value "2" to the stack. Then "5". The "+" operator pops two arguments from the stack, adds them, and then pushes the result on the stack, effectively replacing the two top arguments with their sum. In the RGB format RPN expression are stored as BYTEs with some bytes being special prefixes for integers and symbols.

RPN Expressions
Byte value Meaning
$00 + operator
$01 - operator
$02 * operator
$03 / operator
$04 % operator
$05 unary -
$06 | operator
$07 & operator
$08 ^ operator
$09 unary ~
$0A && comparison
$0B || comparison
$0C unary !
$0D == comparison
$0E != comparison
$0F > comparison
$10 < comparison
$11 >= comparison
$12 <= comparison
$13 << operator
$14 >> operator
$15 BANK() function for Gameboy, a symbol ID follows
$16 HRAMCheck for Gameboy, check if value is in HRAM and logically and it with 0xFF
$17 ZeroPageCheck for PC-Engine, check if value is in ZP (0x2000-0x20FF) and logically and it with 0xFF
$18 RangeCheck. LOW and HIGH signed LONGs follow. Checks a value to see if within the range [LOW;HIGH]. If not, generate an error.
$80 LONG integer follows
$81 Symbol ID follows


Last updated 18 July 1997 by Carsten Sorensen