diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..66f7e10a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+rgbasm
+rgblink
+rgbfix
+rgbgfx
+*.o
+*.exe
+*.html
diff --git a/GNUmakefile b/GNUmakefile
new file mode 100644
index 00000000..9650e67f
--- /dev/null
+++ b/GNUmakefile
@@ -0,0 +1,6 @@
+# GNU Make 3.x doesn't support the "!=" shell syntax, so here's an alternative
+
+PKG_CONFIG = pkg-config
+PNGFLAGS = $(shell ${PKG_CONFIG} --cflags libpng)
+
+include Makefile
diff --git a/LICENSE b/LICENSE
index 8304b668..a8d669a3 100644
--- a/LICENSE
+++ b/LICENSE
@@ -18,6 +18,12 @@ released under the following license:
rgbfix was rewritten from scratch by Anthony J. Bentley, and is released
under the ISC license; see the source file for the text of the license.
+rgbgfx was written by stag019, and is released under the ISC license.
+
+The UTF-8 decoder in src/asm/charmap.c was written by Björn Höhrmann and is
+released under the MIT license. The remainder of charmap.c was written by
+stag019, and is released under the ISC license.
+
extern/err.c is derived from the Musl C library, http://www.musl-libc.org,
and is released under the MIT license.
diff --git a/Makefile b/Makefile
index b84a311e..5f3be4aa 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
-.POSIX:
-
+PKG_CONFIG = pkg-config
WARNFLAGS = -Wall -Werror=implicit
-REALCFLAGS = ${CFLAGS} ${WARNFLAGS} -Iinclude -g \
+PNGFLAGS != ${PKG_CONFIG} --cflags libpng
+REALCFLAGS = ${CFLAGS} ${WARNFLAGS} ${PNGFLAGS} -Iinclude -g \
-std=c99 -D_POSIX_C_SOURCE=200809L
# User-defined variables
@@ -42,13 +42,20 @@ rgbfix_obj = \
src/fix/main.o \
src/extern/err.o
-all: rgbasm rgblink rgbfix
+rgbgfx_obj = \
+ src/gfx/gb.o \
+ src/gfx/main.o \
+ src/gfx/makepng.o \
+ src/extern/err.o
+
+all: rgbasm rgblink rgbfix rgbgfx
clean:
$Qrm -rf rgbds.html
$Qrm -rf rgbasm rgbasm.exe ${rgbasm_obj} rgbasm.html
$Qrm -rf rgblink rgblink.exe ${rgblink_obj} rgblink.html
$Qrm -rf rgbfix rgbfix.exe ${rgbfix_obj} rgbfix.html
+ $Qrm -rf rgbgfx rgbgfx.exe ${rgbgfx_obj} rgbgfx.html
$Qrm -rf src/asm/asmy.c src/asm/asmy.h
install: all
@@ -56,11 +63,13 @@ install: all
$Qinstall -s -m 555 rgbasm ${BINPREFIX}/rgbasm
$Qinstall -s -m 555 rgbfix ${BINPREFIX}/rgbfix
$Qinstall -s -m 555 rgblink ${BINPREFIX}/rgblink
+ $Qinstall -s -m 555 rgbgfx ${BINPREFIX}/rgbgfx
$Qmkdir -p ${MANPREFIX}/man1 ${MANPREFIX}/man7
$Qinstall -m 444 src/rgbds.7 ${MANPREFIX}/man7/rgbds.7
$Qinstall -m 444 src/asm/rgbasm.1 ${MANPREFIX}/man1/rgbasm.1
$Qinstall -m 444 src/fix/rgbfix.1 ${MANPREFIX}/man1/rgbfix.1
$Qinstall -m 444 src/link/rgblink.1 ${MANPREFIX}/man1/rgblink.1
+ $Qinstall -m 444 src/gfx/rgbgfx.1 ${MANPREFIX}/man1/rgbgfx.1
rgbasm: ${rgbasm_obj}
$Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm
@@ -71,6 +80,9 @@ rgblink: ${rgblink_obj}
rgbfix: ${rgbfix_obj}
$Q${CC} ${REALCFLAGS} -o $@ ${rgbfix_obj}
+rgbgfx: ${rgbgfx_obj}
+ $Q${CC} ${REALCFLAGS} -o $@ ${rgbgfx_obj} `${PKG_CONFIG} --libs libpng`
+
.y.c:
$Q${YACC} -d ${YFLAGS} -o $@ $<
@@ -91,6 +103,7 @@ mingw:
$Qmv rgbasm rgbasm.exe
$Qmv rgblink rgblink.exe
$Qmv rgbfix rgbfix.exe
+ $Qmv rgbgfx rgbgfx.exe
# Below is a target for the project maintainer to easily create web manuals.
# It relies on mandoc: http://mdocml.bsd.lv
@@ -105,3 +118,5 @@ wwwman:
rgbfix.html
$Qmandoc ${MANDOC} src/link/rgblink.1 | sed s/OpenBSD/General/ > \
rgblink.html
+ $Qmandoc ${MANDOC} src/gfx/rgbgfx.1 | sed s/OpenBSD/General/ > \
+ rgbgfx.html
diff --git a/README b/README.md
similarity index 51%
rename from README
rename to README.md
index 9917c619..304cefce 100644
--- a/README
+++ b/README.md
@@ -1,6 +1,4 @@
-----------------
- RGBDS README
-----------------
+# RGBDS
RGBDS (Rednex Game Boy Development System) is a free assembler/linker package
for the Game Boy and Game Boy Color. It consists of:
@@ -8,50 +6,64 @@ for the Game Boy and Game Boy Color. It consists of:
- rgbasm (assembler)
- rgblink (linker)
- rgbfix (checksum/header fixer)
+ - rgbgfx (PNG‐to‐Game Boy graphics converter)
rgbds-linux is a fork of the original RGBDS which aims to make the programs
more like other UNIX tools.
- Installing RGBDS (UNIX)
-=========================
+## Installing RGBDS (UNIX)
+
+RGBDS requires libpng and pkg-config to be installed.
+
+On Mac OS X, install them with [Homebrew](http://brew.sh/). On other Unixes,
+use the built-in package manager.
+
+You can test if they're installed by running `pkg-config --cflags libpng`:
+if the output is a path, then you're good, and if it outputs an error then
+you need to install them via a package manager.
To build the programs on a UNIX or UNIX-like system, just run in your terminal:
- make
+```sh
+make
+```
Then to install the compiled programs and manual pages, run (with appropriate
privileges):
- make install
+```sh
+make install
+```
After installation, you can read the manuals with the man(1) command. E.g.,
- man 1 rgbasm
-
+```sh
+man 1 rgbasm
+```
Note: the variables described below can affect installation behavior when given
on the make command line. For example, to install rgbds in your home directory
instead of systemwide, run the following:
- mkdir -p $HOME/{bin,man/man1,man/man7}
- make install PREFIX=$HOME
+```sh
+mkdir -p $HOME/{bin,man/man1,man/man7}
+make install PREFIX=$HOME
+```
+`PREFIX`: Location where RGBDS will be installed. Defaults to /usr/local.
-PREFIX: Location where RGBDS will be installed. Defaults to /usr/local.
-
-BINPREFIX: Location where the RGBDS programs will be installed. Defaults
+`BINPREFIX`: Location where the RGBDS programs will be installed. Defaults
to ${PREFIX}/bin.
-MANPREFIX: Location where the RGBDS man pages will be installed. Defaults
+`MANPREFIX`: Location where the RGBDS man pages will be installed. Defaults
to ${PREFIX}/man.
-Q: Whether to quiet the build or not. To make the build more verbose, clear
+`Q`: Whether to quiet the build or not. To make the build more verbose, clear
this variable. Defaults to @.
- Installing RGBDS (Windows)
-============================
+## Installing RGBDS (Windows)
Windows builds are available here: https://github.com/bentley/rgbds/releases
diff --git a/doc/asm.htm b/doc/asm.htm
deleted file mode 100644
index 735dc01e..00000000
--- a/doc/asm.htm
+++ /dev/null
@@ -1,129 +0,0 @@
-
-
-
DB defines a list of bytes that will be stored in the final image. Ideal for tables and text.
-
DB 1,2,3,4,"This is a string"
-
Alternatively you can use DW to store a list of words. Strings are not allowed as arguments to DW.
-
You can also use DB and DW without arguments. This works exactly like “DS 1” and “DS 2” respectively. Consequently DB and DW can be used in a WRAM0/WRAMX/HRAM/VRAM/SRAM section.
DS allocates a number of bytes. The content is undefined. This is the preferred method of allocationg space in a RAM section. You can however also use DB and DW without any arguments.
EQUates are constant symbols. They can for example be used for things such as bit-definitions of hardware-registers.
-
DONUT_ISGOOD EQU $01
-DONUT_ISBAD EQU $02
-
Note that a colon (:) following the label-name is not allowed. EQUates can be exported and imported. They don't change their value during the link process.
EQUS is used to define string-symbols. Wherever the assembler meets a string symbol its name is replaced with its value. If you are familiar with C you can think of it as the same as #define.
-
COUNTREG EQUS "[hl+]"
-
- ld a,COUNTREG
-
(Note that : following the label-name is not allowed.)
-
This will be interpreted as:
-
ld a,[hl+]
-
String-symbols can also be used to define small one-line macros:
-
PUSHA EQUS "push af\npush bc\npush de\npush hl\n"
-
Note that a colon (:) following the label-name is not allowed. String equates can't be exported or imported.
Importing and exporting of symbols is a feature that is very useful when your project spans many source-files and for example you need to jump to a routine defined in another file.
-
-
Import/export commands
-
-
-
Command
-
Meaning
-
-
-
-
IMPORT (or XREF) label[,label,...]
-
This instructs the assembler to define label as if it were present
- in the current file but leave the address calculation to the linker.
-
-
-
EXPORT (or XDEF) label[,label,...]
-
The assembler will make label accessible to other files during the link process.
-
-
-
GLOBAL label[,label,...]
-
If label is defined during the assembly it will be exported, if not it will be imported. Handy (very!) for include-files.
Fixed point constants are basically normal 32-bit constants where the upper 16 bits are used for the integer part and the lower 16 bits are used for the fraction (65536ths). This means that you can use them in normal integer expression and indeed some integer operators like plus and minus don't care whether the operands are integer or fixed-point. You can easily convert a fixed-point number to an integer by shifting it right 16 bits. It follows that you can convert an integer to a fixed-point number by shifting it left.
-
Some things are different for fixed-point math though. Which is why you have the following functions to use:
-
-
-
-
-
Name
-
Operation
-
-
-
-
DIV(x,y)
-
x/y
-
-
-
MUL(x,y)
-
x*y
-
-
-
SIN(x)
-
sin(x)
-
-
-
COS(x)
-
cos(x)
-
-
-
TAN(x)
-
tan(x)
-
-
-
ASIN(x)
-
sin-1(x)
-
-
-
ACOS(x)
-
cos-1(x)
-
-
-
ATAN(x)
-
tan-1(x)
-
-
-
ATAN2(x,y)
-
(x,y) angle
-
-
-
These functions are extremely useful for automatic generation of various tables. A circle has 65536.0 degrees. Sine values are between [-1.0;1.0]
-
; --
-; -- Generate a 256 byte sine table with values between 0 and 128
-; --
-ANGLE SET 0.0
- REPT 256
- DB (MUL(64.0,SIN(ANGLE))+64.0)>>16
-ANGLE SET ANGLE+256.0
- ENDR
The last one, Gameboy graphics, is quite interesting and useful. The values are actually pixel values and it converts the “chunky” data to “planar” data as used in the Gameboy.
-
DW `01012323
-
Admittedly an expression with just a single number is quite boring. To spice things up a bit there’s a few operators you can use to perform calculations between numbers.
-
Operators
-
A great number of operators you can use in expressions are available (listed in order of precedence):
-
-
Operators
-
-
-
Operator
-
Meaning
-
-
-
-
( )
-
Precedence override
-
-
-
FUNC()
-
Functioncall
-
-
-
~ + -
-
Unary not/plus/minus
-
-
-
* / %
-
Multiply/divide/modulo
-
-
-
<< >>
-
Shift left/right
-
-
-
& | ^
-
Binary and/or/xor
-
-
-
+ -
-
Add/subtract
-
-
-
!= == <= >= < >
-
Boolean comparison
-
-
-
&& ||
-
Boolean and/or
-
-
-
!
-
Unary Boolean not
-
-
-
-
The result of the boolean operators is zero if when FALSE and non-zero when TRUE. Thus it is legal to use an integer as the condition for IF blocks. You can use symbols instead of numbers in your expression if you wish.
-
-
An expression is said to be constant when it doesn't change its value during linking. This basically means that you can't use labels in those expressions. The instructions in the macro-language all require expressions that are constant.
The most basic string expression is any number of characters contained in double quotes ("for instance"). As in C the escape character is \ and there is a number of commands you can use within a string:
-
-
Escape characters:
-
-
-
Character sequence
-
Meaning
-
Notes
-
-
-
-
\\
-
Backslash
-
-
-
-
\"
-
Double-quote
-
-
-
-
\{
-
Curly bracket left
-
-
-
-
\}
-
Curly bracket right
-
-
-
-
\n
-
Newline ($0A)
-
-
-
-
\t
-
Tab ($09)
-
-
-
-
\1-\9
-
Macroargument
-
Only in macros
-
-
-
\@
-
Labelname suffix
-
Only in macros and repts
-
-
-
-
A funky feature is {symbol} withing a string. This will examine the type of the symbol and insert its value accordingly. If symbol is a string symbol the symbols value is simply copied. If it's a numeric symbol the value is converted to hexadecimal notation and inserted as a string.
-
HINT: The {symbol} construct can also be used outside strings. The symbols value is again inserted as a string. This is just a short way of doing "{symbol}".
-
Whenever the macro-language expects a string you can actually use a string expression. This consists of one or more of these function. Yes, you can nest them. Note that some of these functions actually return an integer and can be used as part of an integer expression!
-
-
String functions:
-
-
-
Name
-
Operation
-
-
-
-
STRLEN(stringexpr)
-
Returns the number of characters in string
-
-
-
STRCAT(stringexpr1,stringexpr2)
-
Appends stringexpr2 to stringexpr1.
-
-
-
STRCMP(stringexpr1,stringexpr2)
-
Returns negative if stringexpr1 is alphabetically less than stringexpr2 Zero if they match Positive if greater than
-
-
-
STRIN(haystack,needle)
-
Returns needles position within haystack or zero if it's not present
-
-
-
STRSUB(stringexpr,pos,count)
-
Returns a substring of stringexpr starting at pos (first character is position 1) and with count characters
-
-
-
STRUPR(stringexpr)
-
Converts all characters in string to capitals and returns the new string
-
-
-
STRLWR(string)
-
Converts all characters in string to lower case and returns the new string
FAIL and WARN can be used to terminate the assembling process if you wish to do so. This is especially useful for macros that get an invalid argument. FAIL and WARN take a string as the only argument and they will print this string out as a normal error with a linenumber.
-
FAIL stops assembling immediately while WARN continues after printing the errormessage.
The HRAM section was 128 bytes long instead of 127. potentially thrashing the interrupt enable register if you filled the HRAM.
-
The BANK() function, when used on a symbol defined in the current sourcefile, returned the wrong bank ID. (reported by Harry P. Mulder)
-
The BANK() function didn't check whether the argument was a properly defined symbol. (reported by Harry P. Mulder)
-
Completely new lexical analyser module. This fixed several linenumber bugs and other macro/if/rept related bugs. Also fixed a bug which made it possible to have equated symbols with the same name as a reserved keyword (if you get a "parse error" with this release on some of your sources, this is probably what is going on)
Sometimes the first line of a file wouldn't assemble correctly. Reported by Jeff Frohwein.
-
Unrolling multiline string symbols left the linecounter in a sorry state. Jeff Frohwein again.
-
DB and DW can now (officially ;-) be used in BSS/HRAM/VRAM sections without any arguments to reserve a byte or a word respectively. Reported/suggested/inspired by Mr. Frohwein.
-
The character # can now be used as part of a symbol name. Jeff....
-
The RS counter "_RS" is now defined from the very start of the assembly process instead of after the first RSSET or RSRESET.
-
Bug fixed: You couldn't use \0-\9 and \@ in {} constructs
-
PURGE pseudo-op added. Purges a symbol from the symboltable and memory. Use with extreme caution! Inspired by Harry P. Mulder
-
MACRO parameter passing method changed drastically. Read (and re-read) the manual for details. Suggested by Harry P. Mulder.
-
-
-
-
1.05
-
20 July 1997
-
RGBDS fixes:
- RGBAsm supports the LDD and LDI syntax plus [HLD] and [HLI]. LDH is
- synonymous with LDIO.
- General fixes:
-There was a bug in the macro parameter passing. Any whitespace after the
-last parameter would be appended to the last parameter. Reported by Jeff Frohwein.
-A section stack has been implemented. Look up POPS and PUSHS. Jeff Frohweins doing again.
-OPT command added for defining and changing some options while assembling.
-You can now define which characters are used for the Gameboy graphics
-integer (`) using the commandline or the new OPT command. Cool idea by (surprise surprise) Jeff Frohwein.
-Also, an option stack has been added. Look up POPO and PUSHO in the
-manual.
-Fixed yet another line number bug reported by Jeff Frohwein (when will this guy leave me alone? ;)
-
-
-
1.06
-
22 July 1997
-
General fixes:
-The lamest typo bug of all time has been fixed. RGBAsm would output a word defined with DW as 4 bytes instead of 2. Jeff Frohwein reported this.
-The first line of an included file didn't assemble correctly.
--b option added for setting the characters used for binary constants.
-
-
-
-
1.08
-
21 September 1997
-
General fixes:
-A crash occured if you tried to use a macro symbol in an expression.
-(Jeff Frohwein)
-You couldn't use STRCMP, STRLEN and STRIN in relocatable expressions. (Harry
-P. Mulder)
-Relocatable symbols are no longer allowed as arguments to the DEF function.
-Bug fixed in the assembler where it would sometimes write out too many bytes
-for HRAM section definitions.
-
-
-
-
1.08
-
02 July 1999
-
- Feature:
-
- DQ directive added for defining 32-bit data constants. See operation of DW & DB.
-
-
-
-
-
1.08
-
05 July 1999
-
- Feature:
-
- Allow only a part of a binary file to be included instead of the whole thing.
-
-
-
-
-
1.08
-
10 June 1999
-
- Feature:
-
- Added output of file dependency information for each file included/assembled. Enabled with a command line option.
-
-
- Feature:
-
- Added ability to output error information in either RGBDS or Microsoft Developer Studio format.
-
-
-
-
-
1.08
-
?? ???? 1999
-
- Feature:
-
- Added pseudo-instructions to handle NE (not equal), EQ (equal), and LT (less than) on JR/JP/CALL instructions
-
-
-
-
-
1.08
-
?? ???? 1999
-
- Feature:
-
- Added STRTRIM, STRLTRIM, STRRTRIM directives to allow trimming of white space from strings in macro arguments.
-
-
-
-
-
1.08
-
?? ???? 1999
-
- Bug Fix:
-
- When an "unknown symbol" error was reported during the link phase the undefined symbol was not given.
-
-
-
-
-
1.08
-
?? ???? 1999
-
- Bug Fix:
-
- Declaring a symbol as GLOBAL in a header file and then referencing it in code but never defining it would crash the linker.
-
-
-
-
-
1.09
-
08 February 2000
-
- Feature:
-
- Can now use a command line option to set the number format between a slightly tweaked Motorola/RGBDS format and Zilog.
-
- Hex numbers can now be represented as $FF or FFh.
-
- Octal as &77 or 77o.
-
- Binary as %10010110 or 10010110b.
-
- Gameboy graphics numbers as `1001 or 1001g.
-
- Decimal numbers remain unchanged.
-
-
You probably have some graphics you’d like to include. Use INCBIN to include a raw binary file as it is. If the file isn’t found in the current directory the include-path list will be searched.
-
INCBIN "titlepic.bin"
-INCBIN "sprites\\hero.bin"
-
You can also include only part of a file with INCBIN. The example below includes 256 bytes from data.bin starting from position 78.
Use INCLUDE to process another assembler-file and then return to the current file when done. If the file isn't found in the current directory the include-path list will be searched. You may nest INCLUDE calls infinitely (or until you run out of memory whichever comes first).
One of the assembler’s main tasks is to keep track of addresses for you so you dor’t have to remember obscure numbers but can make do with a meaningful name, a label.
-
This can be done in a number of ways:
-
GlobalLabel
-AnotherGlobal:
-.locallabel
-.yet_a_local:
-ThisWillBeExported:: ;note the two colons
-
This is very similar to other assemblers. Local labels are only accessible within the scope they are defined. A scope starts after a global label and ends at the next global label. You may or may not have seen the :: feature before. It declares a normal global label but does an EXPORT at the same time.
-
Labels will normally change their value during the link process and are thus not constant.
One of the best features of an assembler is the ability to write macros for it. Macros also provide a method of passing arguments to them and they can then react to the input using IF-constructs.
-
MyMacro: MACRO
- ld a,80
- call MyFunc
- ENDM
-
The above example is a very simple macro. You execute the macro by typing its name.
-
add a,b
- ld sp,hl
- MyMacro ;This will be expanded
- sub a,87
-
When the assembler meets MyMacro it will insert the macrodefinition (the text enclosed in MACRO/ENDM).
-
Suppose your macro contains a loop.
-
LoopyMacro: MACRO
- xor a,a
-.loop ld [hl+],a
- dec c
- jr nz,.loop
- ENDM
-
This is fine. That is, if you only use the macro once per scope. To get around this problem there is a special label string equate called \@ that you can append to your labels and it will then expand to a unique string.
-
\@ also works in REPT-blocks should you have any loops there.
-
LoopyMacro: MACRO
- xor a,a
-.loop\@ ld [hl+],a
- dec c
- jr nz,.loop\@
- ENDM
-
Arguments
-
I’d like LoopyMacro a lot better if I didn’t have to pre-load the registers with values and then call it. What I’d like is the ability to pass it arguments and it then loaded the registers itself.
-
And I can do that. In macros you can get the arguments by using the special macro string equates \1 through \9, \1 being the first argument specified on the calling of the macro.
-
LoopyMacro: MACRO
- ld hl,\1
- ld c,\2
- xor a,a
-.loop\@ ld [hl+],a
- dec c
- jr nz,.loop\@
- ENDM
-
Now I can call the macro specifying two arguments. The first being the address and the second being a bytecount. The macro will then reset all bytes in this range.
-
LoopyMacro MyVars,54
-
You can specify up to nine arguments when calling a macro. Arguments are passed as string equates. There’s no need to enclose them in quotes. Parameter passing has changed a bit since v1.03 in that an expression will not be evaluated first but passed directly. This means that it’s probably a very good idea to use brackets around \1–\9 if you perform further calculations on them. For instance if you pass 1+2 as the first argument and then do PRINTV \1*2
-you will get the value 5 on screen and not 6 as you might have expected.
-
Note that a colon (:) following the macro-name is required. Macros can't be exported or imported. It's valid to call a macro from a macro (yes, even the same one).
POPO and PUSHO provide the interface to the option stack. PUSHO will push the current set of options on the option stack. POPO can then later be used to restore them. Useful if you want to change some options in an include file and you don't want to destroy the options set by the program that included your file. The stacks number of entries is limited only by the amount of memory in your machine.
POPS and PUSHS provide the interface to the section stack. PUSHS will push the current section context on the section stack. POPS can then later be used to restore it. Useful for defining sections in included files when you don't want to destroy the section context for the program that included your file. The stacks number of entries is limited only by the amount of memory in your machine.
These three instructions type text and values to stdout. Useful for debugging macros or wherever you may feel the need to tell yourself some important information.
-
PRINTT "I'm the greatest programmer in the whole wide world\n"
-PRINTV (2+3)/5
-PRINTF MUL(3.14,3987.0)
-
-
PRINTT prints out a string
-
PRINTV prints out an integer value or, as in the example, the result of a calculation. Unsurprisingly you can also print out a constant symbols value
The PURGE command allows you to completely remove a symbol from the symbol table as if it had never existed. USE WITH EXTREME CAUTION!!! I can’t stress this enough but you seriously need to know what you are doing. DON’T purge symbol that you use in expressions the linker needs to calculate. In fact, it’s probably not even safe to purge anything other than string symbols and macros.
-
Kamikaze EQUS "I don't want to live anymore"
-AOLer EQUS "Me too"
- PURGE Kamikaze,AOLer
-
Note that string symbols that are part of a PURGE command WILL NOT BE EXPANDED as the ONLY exception to this rule.
Suppose you’re feeling lazy and you want to unroll a time consuming loop. REPT is here for that purpose. Everything between REPT and ENDR will be repeated a number of times just as if you done a copy/paste operation yourself
-
REPT 4
-add a,c
-ENDR
-
This will assemble add a,c four times.
-
You can also use REPT to generate tables on the fly:
-
; --
-; -- Generate a 256 byte sine table with values between 0 and 128
-; --
-ANGLE SET 0.0
- REPT 256
- DB (MUL(64.0,SIN(ANGLE))+64.0)>>16
-ANGLE SET ANGLE+256.0
- ENDR
-
REPT is also very useful in recursive macros and as in macros you can also use the special label operator \@. REPT-blocks can be nested.
Sets the preceding symbol to _RS and adds constexpr to _RS
-
-
-
RW constexpr
-
Sets the preceding symbol to _RS and adds constexpr*2 to _RS
-
-
-
Note that a colon (:) following the symbol-name is not allowed. RS symbols can be exported and imported. They don't change their value during the link process.
Before you can start writing code you must define a section. This tells the assembler what kind of data follows and if it is code where to put it.
-
SECTION "CoolStuff",ROMX
-
This switches to the section called "CoolStuff" (or creates it if it doesn't already exits) and it defines it as a code section. All sections within a sourcefile must be identified by a unique name.
-
-
Possible section types are as follows:
-
-
-
ROM0
-
A ROM section. Mapped to memory at $0000–$3fff.
-
-
ROMX
-
A banked ROM section. Mapped to memory at $4000–$7fff. Valid banks range from 1 to 511.
-
-
VRAM
-
A banked video RAM section. Mapped to memory at $8000–$9fff. Can only allocate memory, not fill it. Valid banks range from 0 to 1.
-
-
SRAM
-
A banked external (save) RAM section. Mapped to memory at $a000–$bfff. Can only allocate memory, not fill it. Valid banks range from 0 to 3.
-
-
WRAM0
-
A general-purpose RAM section. Mapped to memory at $c000–$cfff. Can only allocate memory, not fill it.
-
-
WRAMX
-
A banked general-purpose RAM section. Mapped to memory at $d000–$dfff. Can only allocate memory, not fill it. Valid banks range from 1 to 7.
-
-
HRAM
-
A high RAM section. Mapped to memory at $ff80–$fffe. Can only allocate memory, not fill it. NOTE WELL: if you use this method of allocating HRAM the assembler will NOT choose the short addressingmode in the LD instruction because the actual address calculation is done by the linker! If you find this undesirable you can use RSSET/RB/RW instead or use the LDIO mnemonic. The address calculation is then done by the assembler.
-
-
-
The following deprecated section names are aliases for some of the above sections:
-
-
-
HOME
-
Alias for ROM0.
-
-
CODE
-
DATA
-
Alias for ROMX.
-
-
BSS
-
Alias for WRAM0.
-
-
-
Due to quite a lot of emails requesting an ORG directive you can now add an address to the sectiontype for the Gameboy:
-
SECTION "CoolStuff",ROM0[$1234]
-
This will force the section to address $1234. This also works with the other sectiontypes. For ROMX sections the linker will then place the section in any bank at the address you specify. If you also want to specify the bank you can do:
-
SECTION "CoolStuff",ROMX[$4567],BANK[3]
-
And if you only want to force the section into a certain bank, and not it's position within the bank, that's also possible:
-
SECTION "CoolStuff",ROMX,BANK[7]
-
HINT: If you think this is a lot of typing for doing a simple ORG type thing you can quite easily write an intelligent macro (called ORG for example) that uses \@ for the sectionname and determines correct sectiontype etc as arguments for SECTION
SETs are like EQUates also constant symbols in the sense that their values are defined during the assembly process. These symbols are normally used in macros.
-
KINKYCOUNT SET 2
-KINKYCOUNT SET DONUT_ISGOOD+KINKYCOUNT
-
Note that a colon (:) following the label-name is not allowed. SETs can be exported and imported but the result is undefined and might change in a later release. Alternatively you can use = as a synonym for SET.
SHIFT is a special command only available in macros. Very useful in REPT-blocks. It will "shift" the arguments by one "to the left". \1 will get \2's value, \2 will get \3's value and so forth.
The full GB-Z80 instruction-set is implemented with a few modifications to the original Zilog syntax. This is due to a Bison problem but in my opinion the syntax is better than the original one.
-
Instructions
-
-
ADC
-
ADD
-
AND
-
BIT
-
CALL
-
CCF
-
CP
-
CPL
-
DAA
-
DEC
-
DI
-
EI
-
EX
-
HALT
-
INC
-
JP
-
JR
-
LD
-
LDD
-
LDI
-
LDH/LDIO (see note below)
-
NOP
-
OR
-
POP
-
PUSH
-
RES
-
RET
-
RETI
-
RL
-
RLA
-
RLC
-
RLCA
-
RR
-
RRA
-
RRC
-
RRCA
-
RST
-
SBC
-
SCF
-
SET
-
SLA
-
SRA
-
SRL
-
STOP
-
SUB
-
SWAP
-
XOR
-
-
Note that you can use both
-
OR A,B
- OR B
-
Addressingmodes
-
Indirect addressing has been changed to [ ] instead of ( ):
-
-
A
-
B
-
C
-
D
-
E
-
H
-
L
-
AF
-
BC
-
DE
-
HL
-
SP
-
[BC]
-
[DE]
-
[HL]
-
[HL-]/[HLI]
-
[HL+]/[HLD]
-
[SP]
-
n8 (8 bit expression)
-
n16 (16 bit expression)
-
n3 (3 bit CONSTANT expression)
-
[n16]/[$FF00+n8]
-
[$FF00+C]/[C]
-
-
The assembler will intelligently decide between [n16] and [$FF00+n8] in the LD instruction. Note however that if you use any constant symbols in the expression they had better be defined before the instruction or your symbol-table may become mangled. Also worth noting is that it will only ever select the short $FF00 mode when you use constant symbols. NOT if you use symbols defined in a HRAM section. As this defies the whole point of implementing the HRAM sectiontype I've added the LDIO mnemonic. It works like the LD instruction but it will ALWAYS generate the $FF00+ form and it will also automatically logically AND the expression with $FF if it is relocatable. Which is what you want. Trust me ;)
Options are preceded by a hyphen (-) and go as follows:
-
oobjectfile : Write an object-file for xLink
- ipath : Add an extra include-path
- h : Short help text
- e(l|b) : Change endianness (CAUTION!)
- gASCI : Change the four characters used for Gameboy graphics
- constants (default is 0123)
- bAS : Change the two characters used for binary constants
- (default is 01)
- zHX : Set the byte value (hex format) used for uninitialised data (default is ? for random)
-
The ASMotor package (xAsm, xLink, RGBFix, examples and documentation) is freeware and distributed as is. The author retains his copyright and right to modify the specifications and operation of the software without notice.
-
In other words this means I encourage you to…
-
-
use it for whatever purpose even professional work without me charging you a penny
-
copy it to another person (wholly or in part, though I’m sure he’d appreciate the whole package) in
-whatever form you find suitable
-
mass-distribute the ASMotor package if it is complete (xAsm, xLink, RGBFix and documentation).
-
contact me if you have any problems
-
-
This also means you can’t…
-
-
blame me for loss of profit, data, sleep, food or other nasty things through the use or distribution of ASMotor. If
-you choose to use ASMotor you do so at your own risk.
-
expect me to be able to help you should you have a problem related or not to ASMotor.
-
RGBFix can now also truncate the ROM-images to a valid size.
-
RGBAsm supports the LDD and LDI syntax plus [HLD] and [HLI]. LDH is synonymous with LDIO.
-
Example filenames have been changed to adhere to Jeff Frohweins proposed standard.
-
-
General fixes:
-
-
RGBLink knows about big and little endian. Plus it can do range checking on intermediate results in an expression. This is necessary to support
-different types of CPUs.
-
RGBLink didn’t know about the special PC symbol “@” so if you used it more than once per sourcefile in an expression the linker had to resolve, things would go horribly wrong.
-
There was a bug in the macro parameter passing. Any whitespace after the last parameter would be appended to the last parameter. Reported by Jeff Frohwein.
-
A section stack has been implemented. Look up POPS and PUSHS in the
-manual. Jeff Frohwein’s doing again.
-
OPT command added for defining and changing some options while assembling.
-
You can now define which characters are used for the Gameboy graphics integer (`) using the commandline or the new OPT command. Cool idea by (surprise surprise) Jeff Frohwein.
-
Also, an option stack has been added. Look up POPO and PUSHO in the manual.
-
Fixed yet another line number bug reported by Jeff Frohwein (when will this guy leave me alone? ;)
-
-
-
-
1.02
-
22 July 1997
-
General fixes:
-
-
The lamest typo bug of all time has been fixed. RGBAsm would output a word defined with DW as 4 bytes instead of 2. Jeff Frohwein reported this.
-
The first line of an included file didn’t assemble correctly.
-
-b option added for setting the characters used for binary constants.
-
-
-
-
-
1.10
-
21 Sep 1997
-
General fixes:
-
-
The assembler would crash if you tried to use a macro symbol in an expression. (Jeff Frohwein)
-
You couldn’t use STRCMP, STRLEN and STRIN in relocatable expressions. (Harry P. Mulder)
-
Relocatable symbols are no longer allowed as arguments to the DEF function.
-
Finally! A librarian and smart linking has been added.
-
Bug fixed in the assembler where it would sometimes write out too many bytes for HRAM section definitions.
-
-z options (set fill value used for uninitialised data) added to the
-assembler and linker.
-
The assembler will now read in any type of ASCII file on any type of OS.
-
First ASMotor release. Supports big-endian CPUs as well. Usage changed to allow for different output fileformats
-
-
-
1.05
-
20 July 1997
-
-
-
We can now do range checking on intermediate results in an expression. This is necessary to support different types of CPUs.
-
RGBLink DIDN’T know about the special PC symbol "@" so if you used it more than once per sourcefile in an expression the linker had to resolve, things would go horribly wrong.
-
-
-
-
1.06
-
21 September 1997
-
Smart linking and library support added
-
Program renamed to xLink
-
-
-
-
Usage
-
xlink [options] linkfile
-
Options are preceded by a hyphen (-) and go as follows:
-
h : Short help text
- mmapfile : Write a mapfile
- t : Output target:
- tg : Gameboy ROM image (default)
- ts : Gameboy Small mode (32kB) ROM image
- tp : Psion2 relocatable module
- zHX : Set the byte value (hex format) used for uninitialised data (default is ? for random)
-
-
The Linkfile
-
A linkfile is used to tell xLink which objects to include and what the outputname should be. It is in plain ASCII-format.
-
If you use libraries they will only be included if one of the objects actually reference them. This works on a SECTION level and not on a module level. This means that when you write libraries you can put each subroutine in its own SECTION so only the relevant bits are included.
-
Operation for Gameboy (-tg)
-
Sections created with ROM0 in the assembler are placed in the GB bank #0 (the fixed bank $0000-$3FFF) in the order they are loaded from the objectfiles specified in the linkfile. So you want the first file in the linkfile to contain your header. ROMX sections are placed in any bank other than #0. This means you have absolutely no control over which sections goes where. This insures minimal slack (unused bytes) at the end of each bank in the image.
-
Currently the linker doesn't calculate the GB checksums.
-You must use RGBFix to do this.
-
-
Operation for Gameboy small mode (-ts)
-
Small mode forces all ROMX sections to be of type ROM0 and increases the ROM0 section size from 16kB to 32kB. This also means that ROM0/ROMX sections are written to the final image in the order you have specified on the command line.
-
Currently the linker doesn't calculate the GB checksums. You must use RGBFix to do this.
-
-
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 = 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
-
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 expressions 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.
-