diff --git a/docs/rgbasm.5.html b/docs/rgbasm.5.html index d5f67a7f..2082a7be 100644 --- a/docs/rgbasm.5.html +++ b/docs/rgbasm.5.html @@ -49,10 +49,11 @@ All pseudo‐ops, mnemonics and registers (reserved keywords) are
There are two syntaxes for comments. In both cases, a comment ends at the end of the line. The most common one is: anything that follows a semicolon - ";" (that isn't inside a string) is a comment. There is another - format: anything that follows a "*" that is placed right at the - start of a line is a comment. The assembler removes all comments from the code - before doing anything else. + ‘;’ (that isn't inside a string) is a + comment. There is another format: anything that follows a + ‘*’ that is placed right at the start of + a line is a comment. The assembler removes all comments from the code before + doing anything else.
Sometimes lines can be too long and it may be necessary to split them. The syntax to do so is the following one: @@ -65,7 +66,7 @@ Sometimes lines can be too long and it may be necessary to split them. The
This works anywhere in the code except inside of strings. To split strings it is - needed to use STRCAT like this: + needed to use STRCAT() like this:
@@ -74,99 +75,140 @@ This works anywhere in the code except inside of strings. To split strings it is
 

Sections

+SECTION name, + type +
+SECTION name, + type, + options +
+SECTION name, + type[addr] +
+SECTION name, + type[addr], + options +
Before you can start writing code, you must define a section. This tells the assembler what kind of information follows and, if it is code, where to put it.
-
-
-    SECTION "CoolStuff",ROMX
-
-
+name is a string enclosed in double quotes and + can be a new name or the name of an existing section. All sections assembled + at the same time that have the same name and type are considered to be the + same section, and their code is put together in the object file generated by + the assembler. All other sections must have a unique name, even in different + source files, or the linker will treat it as an error.
-This switches to the section called "CoolStuff" (or creates it if it - doesn't already exist) and it defines it as a code section. All sections - assembled at the same time that have the same name, type, etc, are considered - to be the same one, and their code is put together in the object file - generated by the assembler. All other sections must have a unique name, even - in different source files, or the linker will treat it as an error. -
-Possible section types are as follows: +Possible section types are as follows:
 
 
-
ROM0
-
A ROM section. Mapped to memory at $0000–$3FFF (or - $0000-$7FFF if tiny ROM mode is enabled in - rgblink(1)).
+
ROM0
+
A ROM section. addr can + range from $0000–$3FFF (or $0000–$7FFF if tiny ROM mode is + enabled in rgblink(1)).
 
 
-
ROMX
-
A banked ROM section. Mapped to memory at - $4000–$7FFF. Valid banks range from 1 to 511. Not available if tiny - ROM mode is enabled in rgblink(1).
-
 
-
 
-
VRAM
-
A banked video RAM section. Mapped to memory at - $8000–$9FFF. Can only allocate memory, not fill it. Valid banks are - 0 and 1 but bank 1 isn't available if DMG mode is enabled in +
ROMX
+
A banked ROM section. addr + can range from $4000–$7FFF. bank + can range from 1 to 511. Not available if tiny ROM mode is enabled in rgblink(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 15.
+
VRAM
+
A banked video RAM section. + addr can range from $8000–$9FFF. + bank can be 0 or 1 but bank 1 is + unavailable if DMG mode is enabled in + rgblink(1). Memory in this section can only + be allocated with DS, not filled with + data.
 
 
-
WRAM0
-
A general-purpose RAM section. Mapped to memory at - $C000–$CFFF, or $C000-$DFFF if DMG mode is enabled in - rgblink(1). Can only allocate memory, not - fill it.
+
SRAM
+
A banked external (save) RAM section. + addr can range from $A000–$BFFF. + bank can range from 0 to 15. Memory in + this section can only be allocated with DS, + not filled with data.
 
 
-
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. Not available if DMG mode is enabled in +
WRAM0
+
A general-purpose RAM section. + addr can range from $C000–$CFFF, + or $C000–$DFFF if DMG mode is enabled in + rgblink(1). Memory in this section can only + be allocated with DS, not filled with + data.
+
 
+
 
+
WRAMX
+
A banked general-purpose RAM section. + addr can range from $D000–$DFFF. + bank can range from 1 to 7. Memory in + this section can only be allocated with DS, + not filled with data. Not available if DMG mode is enabled in rgblink(1).
 
 
-
OAM
-
An object attributes RAM section. Mapped to memory at - $FE00-$FE9F. Can only allocate memory, not fill it.
+
OAM
+
An object attributes RAM section. + addr can range from $FE00-$FE9F. Memory + in this section can only be allocated with + DS, not filled with data.
 
 
-
HRAM
-
A high RAM section. Mapped to memory at $FF80–$FFFE. - Can only allocate memory, not fill it. +
HRAM
+
A high RAM section. addr + can range from $FF80–$FFFE. Memory in this section can only be + allocated with DS, not filled with data.
- NOTE: If you use this method of allocating HRAM the assembler will NOT - choose the short addressing mode in the LD instructions - LD [$FF00+n8],A and - LD A,[$FF00+n8] 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 - LDH [$FF00+n8],A and + Note: If you use this method of allocating HRAM + the assembler will not choose the short + addressing mode in the LD instructions LD + [$FF00+n8],A and LD A,[$FF00+n8] because + the actual address calculation is done by the linker. If you find this + undesirable you can use RSSET, + RB, or RW + instead or use the LDH [$FF00+n8],A and LDH A,[$FF00+n8] syntax instead. This forces the assembler to emit the correct instruction and the linker to check if the value is in the correct range. This optimization can be disabled by passing the -L flag to - rgbasm as explained in rgbasm(1).
-A section is usually defined as a floating one, but the code can restrict where - the linker can place it. +options are comma separated and may include: +
+
 
+
 
+
BANK[bank]
+
Specify which bank for the + linker to place the section.
+
 
+
 
+
ALIGN[align]
+
Place the section at an address whose + align least‐significant bits are + zero. It is a syntax error to use this option with + addr.
+
-If a section is defined with no indications, it is a floating section. The - linker will decide where to place it in the final binary and it has no - obligation to follow any specific rules. The following example defines a - section that can be placed anywhere in any ROMX bank: +If [addr] is not specified, the section is + considered “floating”; the linker will automatically calculate + an appropriate address for the section. Similarly, if + BANK[bank] is + not specified, the linker will automatically find a bank with enough space. +
+Sections can also be placed by using a linkerscript file. The format is + described in rgblink(5). They allow the user to + place floating sections in the desired bank in the order specified in the + script. This is useful if the sections can't be placed at an address manually + because the size may change, but they have to be together. +
+Section examples:
@@ -174,8 +216,19 @@ If a section is defined with no indications, it is a floating section. The
 
-If it is needed, the following syntax can be used to fix the base address of the - section: +This switches to the section called “CoolStuff” (or creates it if + it doesn't already exist) and defines it as a code section. +
+The following example defines a section that can be placed anywhere in any ROMX + bank: +
+
+
+    SECTION "CoolStuff",ROMX
+
+
+
+If it is needed, the the base address of the section can be specified:
@@ -183,8 +236,7 @@ If it is needed, the following syntax can be used to fix the base address of the
 
-It won't, however, fix the bank number, which is left to the linker. If you also - want to specify the bank you can do: +An example with a fixed bank:
@@ -201,11 +253,7 @@ And if you only want to force the section into a certain bank, and not it's
 
-In addition, you can specify byte alignment for a section. This ensures that the - section starts at a memory address where the given number of least-significant - bits are 0. This can be used along with BANK, if - desired. However, if an alignment is specified, the base address must be left - unassigned. This can be useful when using DMA to copy data or when it is +Alignment examples: one use could be when using DMA to copy data or when it is needed to align the start of an array to 256 bytes to optimize the code that accesses it.
@@ -217,26 +265,23 @@ In addition, you can specify byte alignment for a section. This ensures that the
-HINT: If you think this is a lot of typing for doing a simple - ORG type thing you can quite easily write an +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 section name and determines correct section type etc as arguments for SECTION. -
+

Section + Stack

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 number of entries - in the stack is limited only by the amount of memory in your machine. + the interface to the section stack.
-Sections can also be placed by using a linkerscript file. The format is - described in rgblink(5). They allow the user to - place floating sections in the desired bank in the order specified in the - script. This is useful if the sections can't be placed at an address manually - because the size may change, but they have to be together. +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 + number of entries in the stack is limited only by the amount of memory in your + machine.

SYMBOLS

Symbols

RGBDS supports several types of symbols: @@ -254,7 +299,7 @@ RGBDS supports several types of symbols:
String equate (EQUS)
Give a frequently used string a name. Can also be used as - a mini-macro, like #define in C.
+ a mini-macro, like #define in C.
MACRO
A block of code or pseudo instructions that you invoke like any other mnemonic. You can give them arguments too.
@@ -370,18 +415,14 @@ str_SIZEOF = 259 There are four commands in the RS group of commands: - - + - - - @@ -425,7 +466,7 @@ str_SIZEOF = 259
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. + can think of it as the same as #define .
@@ -604,11 +645,10 @@ ENDM
     
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 the value of \2, - \2 will get the value in - \3 and so forth. + macros. Very useful in REPT-blocks. It will shift the arguments by one to + the left. \1 will get the value of + \2, \2 will get + the value in \3 and so forth.
This is the only way of accessing the value of arguments from 10 to 256. @@ -658,62 +698,52 @@ Note that string symbols that are part of a PURGE The following symbols are defined by the assembler:
Command Meaning
RSRESET Resets the _RS counter to zero.
- - - + + - - - - - - - - - @@ -729,55 +759,46 @@ The following symbols are defined by the assembler: - - - - - - - - -
Type Name Contents
EQU @ PC value
EQU _PI Fixed point π
SET _RS _RS Counter
EQU _NARG Number of arguments passed to macro
EQU __LINE__ The current line number
EQUS __FILE__ The current filename
EQUS __DATE__ Today's date
EQUS __TIME__ The current time
EQU __UTC_YEAR__ Today's year
EQU __UTC_MONTH__ Today's month number, 1-12
EQU __UTC_DAY__ Today's day of the month, 1-31
EQU __UTC_HOUR__ Current hour, 0-23
EQU __UTC_MINUTE__ Current minute, 0-59
EQU __UTC_SECOND__ Current second, 0-59
EQU __RGBDS_MAJOR__ Major version number of RGBDS.
EQU __RGBDS_MINOR__ Minor version number of RGBDS.
EQU __RGBDS_PATCH__ Patch version number of RGBDS.
@@ -1039,15 +1060,15 @@ A great number of operators you can use in expressions are available (listed in order of precedence): - - + - + @@ -1070,8 +1091,8 @@ A great number of operators you can use in expressions are available (listed in - + @@ -1096,7 +1117,7 @@ A great number of operators you can use in expressions are available (listed in - +
Operator Meaning
()( + ) Precedence override
Shift left/right
& - | ^& + | ^ Binary and/or/xor
Boolean and/or
!! Unary Boolean not
@@ -1127,57 +1148,90 @@ 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/yDIV(x, + y) + + x÷y + +
MUL(x,y)x*yMUL(x, + y) + + x×y + +
SIN(x)sin(x)SIN(x) + + sin(x) + +
COS(x)cos(x)COS(x) + + cos(x) + +
TAN(x)tan(x)TAN(x) + + tan(x) + +
ASIN(x)arcsin(x)ASIN(x) + + asin(x) + +
ACOS(x)arccos(x)ACOS(x) + + acos(x) + +
ATAN(x)arctan(x)ATAN(x) + + atan(x) + +
ATAN2(x,y)Angle between (x,y) and (1,0)ATAN2(x, + y)Angle between + + (x,y) + + and + + (1,0) + +
@@ -1203,8 +1257,7 @@ The most basic string expression is any number of characters contained in double there are a number of commands you can use within a string: - - + @@ -1258,7 +1311,7 @@ A funky feature is {symbol} withing a string. This
HINT: The {symbol} construct can also be used outside strings. The symbol's value is again inserted as a string. This is - just a short way of doing "{symbol}". + 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 @@ -1266,45 +1319,47 @@ Whenever the macro-language expects a string you can actually use a string used as part of an integer expression!
String
- - + - - - + - + - + - + - + - + - + @@ -1340,38 +1395,40 @@ CHARMAP "A", 128 There are a few other functions that do various useful things:
Name Operation
STRLEN(string)STRLEN(string) Returns the number of characters in string
STRCAT(str1,str2)STRCAT(str1, + str2) Appends str2 to str1.
STRCMP(str1,str2)STRCMP(str1, + str2) Returns negative if str1 is alphabetically lower than str2, zero if they match, positive if str1 is greater than str2.
STRIN(str1,str2)STRIN(str1, + str2) Returns the position of str2 in str1 or zero if it's not present (first character is position 1).
STRSUB(str,pos,len)STRSUB(str, + pos, + len) Returns a substring from str starting at pos (first character is position 1) and with len characters.
STRUPR(str)STRUPR(str) Converts all characters in str to capitals and returns the new string.
STRLWR(str)STRLWR(str) Converts all characters in str to lower case and returns the new string.
- - + - - - - + + - - + + - - + + - - + +
Name Operation
BANK(@/str/lbl)Returns a bank number. If the argument is the symbol - @, this function returns the bank of the - current section. If the argument is a string, it returns the bank of the - section that has that name. If the argument is a label, it returns the - bank number the label is in. For labels, as the linker has to resolve - this, it can't be used when the expression has to be constant.BANK(arg)Returns a bank number. If + arg is the symbol + @, this function returns the bank of the + current section. If arg is a string, it + returns the bank of the section that has that name. If + arg is a label, it returns the bank + number the label is in. For labels, as the linker has to resolve this, it + can't be used when the expression has to be constant.
DEF(label)Returns TRUE if label has been defined.DEF(label)Returns TRUE if label + has been defined.
HIGH(r16/cnst/lbl)Returns the top 8 bits of the operand if it is a label - or constant, or the top 8-bit register if it is a 16-bit register.HIGH(arg)Returns the top 8 bits of the operand if + arg is a label or constant, or the top + 8-bit register if it is a 16-bit register.
LOW(r16/cnst/lbl)Returns the bottom 8 bits of the operand if it is a - label or constant, or the bottom 8-bit register if it is a 16-bit register - (AF isn't a valid register for this function).LOW(arg)Returns the bottom 8 bits of the operand if + arg is a label or constant, or the bottom + 8-bit register if it is a 16-bit register (AF isn't a valid register for + this function).

MISCELLANEOUS

@@ -1404,180 +1461,6 @@ The options that OPT can modify are currently: b, 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. -

ALPHABETICAL - LIST OF KEYWORDS

-
-
@
-
-
__DATE__
-
-
__FILE__
-
-
__ISO_8601_LOCAL__
-
-
__ISO_8601_UTC__
-
-
__LINE__
-
-
__TIME__
-
-
__RGBDS_MAJOR__
-
-
__RGBDS_MINOR__
-
-
__RGBDS_PATCH__
-
-
__UTC_YEAR__
-
-
__UTC_MONTH__
-
-
__UTC_DAY__
-
-
__UTC_HOUR__
-
-
__UTC_MINUTE__
-
-
__UTC_SECOND__
-
-
_NARG
-
-
_PI
-
-
_RS
-
-
ACOS
-
-
ASIN
-
-
ATAN
-
-
ATAN2
-
-
BANK
-
-
CHARMAP
-
-
COS
-
-
DB
-
-
DEF
-
-
DIV
-
-
DL
-
-
DS
-
-
DW
-
-
ELIF
-
-
ELSE
-
-
ENDC
-
-
ENDM
-
-
ENDR
-
-
EQU
-
-
EQUS
-
-
EXPORT
-
-
FAIL
-
-
GLOBAL
-
-
HIGH
-
-
HRAM
-
-
IF
-
-
INCBIN
-
-
INCLUDE
-
-
LOW
-
-
MACRO
-
-
MUL
-
-
OPT
-
-
POPO
-
-
POPS
-
-
PRINTF
-
-
PRINTI
-
-
PRINTT
-
-
PRINTV
-
-
PURGE
-
-
PUSHO
-
-
PUSHS
-
-
REPT
-
-
RB
-
-
RL
-
-
ROM0
-
-
ROMX
-
-
RSRESET
-
-
RSSET
-
-
RW
-
-
SECTION
-
-
SET
-
-
SHIFT
-
-
SIN
-
-
SRAM
-
-
STRCAT
-
-
STRCMP
-
-
STRIN
-
-
STRLEN
-
-
STRLWR
-
-
STRSUB
-
-
STRUPR
-
-
TAN
-
-
VRAM
-
-
WRAM0
-
-
WRAMX
-
-
WARN
-
-

SEE ALSO

rgbasm(1), rgblink(1),