ref: 38372c59edb070d2c0320d21c6cf898e118e3e26
dir: /doc/rgb0.htm/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>RGB? Fileformat</title> <link rel="stylesheet" type="text/css" href="./style.css"> </head> <body> <h1>The RGB ObjectFileFormats</h1> <h2>Table of Contents</h2> <ul> <li><a href="#background">Background</A> <li><a href="#filestructure">FileStructure</A> <li><a href="#rpn">Rpn Data</A> </ul> <h2 id="background">Background</h2> <p>I developed the RGB0 fileformat mainly because I needed a suitable dataformat to hold the output from <a href="asm.htm">xAsm</a> 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?</p> <p>The RGB1 fileformat saw the light of day with the V1.02 of the old RGBDS release because of the addition of fixed sections.</p> <p>The RGB2 fileformat emerged because I needed to add support for big endian CPUs.</p> <h2 id="filestructure">FileStructure</h2> <ul> <li><dfn>LONG</dfn> is a 32‐bit integer stored in little‐endian format (Intel) <li><dfn>BYTE</dfn> is an 8‐bit integer <li><dfn>STRING</dfn> is a 0‐terminated string of <b>BYTE</b> </ul> <p>Down to business...</p> <pre> ; 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 ;<b>NumberOfSymbols</b> 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 = WRAM0 ;1 = VRAM ;2 = ROMX ;3 = ROM0 ;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 ROMX sections. IF Type==ROMX || Type==ROM0 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</pre> <h2 id="rpn">Rpn Data</h2> <p>Expressions in the objectfile are stored as <abbr title="Reverse Polish Notation">RPN</abbr>. 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 expressions are stored as <b>BYTE</b>s with some bytes being special prefixes for integers and symbols.</p> <table> <caption>RPN Expressions</caption> <thead> <tr> <th scope="col">Byte value</th> <th scope="col">Meaning</th> </tr> </thead> <tr> <td>$00</td> <td>+ operator</td> </tr> <tr> <td>$01</td> <td>- operator</td> </tr> <tr> <td>$02</td> <td>* operator</td> </tr> <tr> <td>$03</td> <td>/ operator</td> </tr> <tr> <td>$04</td> <td>% operator</td> </tr> <tr> <td>$05</td> <td>unary -</td> </tr> <tr> <td>$06</td> <td>| operator</td> </tr> <tr> <td>$07</td> <td>& operator</td> </tr> <tr> <td>$08</td> <td>^ operator</td> </tr> <tr> <td>$09</td> <td>unary ~</td> </tr> <tr> <td>$0A</td> <td>&& comparison</td> </tr> <tr> <td>$0B</td> <td>|| comparison</td> </tr> <tr> <td>$0C</td> <td>unary !</td> </tr> <tr> <td>$0D</td> <td>== comparison</td> </tr> <tr> <td>$0E</td> <td>!= comparison</td> </tr> <tr> <td>$0F</td> <td>> comparison</td> </tr> <tr> <td>$10</td> <td>< comparison</td> </tr> <tr> <td>$11</td> <td>>= comparison</td> </tr> <tr> <td>$12</td> <td><= comparison</td> </tr> <tr> <td>$13</td> <td><< operator</td> </tr> <tr> <td>$14</td> <td>>> operator</td> </tr> <tr> <td>$15</td> <td>BANK() function for Gameboy, a symbol ID follows</td> </tr> <tr> <td>$16</td> <td>HRAMCheck for Gameboy, check if value is in HRAM and logically and it with 0xFF</td> </tr> <tr> <td>$17</td> <td>ZeroPageCheck for PC-Engine, check if value is in ZP (0x2000-0x20FF) and logically and it with 0xFF</td> </tr> <tr> <td>$18</td> <td>RangeCheck. LOW and HIGH signed LONGs follow. Checks a value to see if within the range [LOW;HIGH]. If not, generate an error. </td> </tr> <tr> <td>$80</td> <td>LONG integer follows</td> </tr> <tr> <td>$81</td> <td>Symbol ID follows</td> </tr> </table> <hr> <p>Last updated 18 July 1997 by <a href="mailto:[email protected]">Carsten Sorensen</a></p> </body> </html>