Reword some RGBASM docs

This commit is contained in:
Rangi42
2024-08-18 13:18:00 -04:00
committed by Sylvie
parent 731715ff36
commit b7290366cb

View File

@@ -603,6 +603,13 @@ Modifications to a character map take effect immediately from that point onward.
There are a few other functions that do things beyond numeric or string operations: There are a few other functions that do things beyond numeric or string operations:
.Bl -column "SECTION(symbol)" .Bl -column "SECTION(symbol)"
.It Sy Name Ta Sy Operation .It Sy Name Ta Sy Operation
.It Fn DEF symbol Ta Returns 1 if
.Ar symbol
has been defined, 0 otherwise.
String constants are not expanded within the parentheses.
.It Fn ISCONST arg Ta Returns 1 if Ar arg Ap s value is known by RGBASM (e.g. if it can be an argument to
.Ic IF ) ,
or 0 if only RGBLINK can compute its value.
.It Fn BANK arg Ta Returns a bank number. .It Fn BANK arg Ta Returns a bank number.
If If
.Ar arg .Ar arg
@@ -639,13 +646,6 @@ If
.Ar arg .Ar arg
is a section type keyword, it returns the starting address of that section type. is a section type keyword, it returns the starting address of that section type.
The result is not constant, since only RGBLINK can compute its value. The result is not constant, since only RGBLINK can compute its value.
.It Fn DEF symbol Ta Returns 1 if
.Ar symbol
has been defined, 0 otherwise.
String constants are not expanded within the parentheses.
.It Fn ISCONST arg Ta Returns 1 if Ar arg Ap s value is known by RGBASM (e.g. if it can be an argument to
.Ic IF ) ,
or 0 if only RGBLINK can compute its value.
.El .El
.Sh SECTIONS .Sh SECTIONS
Before you can start writing code, you must define a section. Before you can start writing code, you must define a section.
@@ -800,7 +800,7 @@ Section examples:
.Bl -item .Bl -item
.It .It
.Bd -literal -offset indent .Bd -literal -offset indent
SECTION "Cool Stuff",ROMX SECTION "Cool Stuff", ROMX
.Ed .Ed
This switches to the section called This switches to the section called
.Dq CoolStuff , .Dq CoolStuff ,
@@ -810,25 +810,25 @@ Code and data may follow.
.It .It
If it is needed, the the base address of the section can be specified: If it is needed, the the base address of the section can be specified:
.Bd -literal -offset indent .Bd -literal -offset indent
SECTION "Cool Stuff",ROMX[$4567] SECTION "Cool Stuff", ROMX[$4567]
.Ed .Ed
.It .It
An example with a fixed bank: An example with a fixed bank:
.Bd -literal -offset indent .Bd -literal -offset indent
SECTION "Cool Stuff",ROMX[$4567],BANK[3] SECTION "Cool Stuff", ROMX[$4567], BANK[3]
.Ed .Ed
.It .It
And if you want to force only the section's bank, and not its position within the bank, that's also possible: And if you want to force only the section's bank, and not its position within the bank, that's also possible:
.Bd -literal -offset indent .Bd -literal -offset indent
SECTION "Cool Stuff",ROMX,BANK[7] SECTION "Cool Stuff", ROMX, BANK[7]
.Ed .Ed
.It .It
Alignment examples: Alignment examples:
The first one could be useful for defining an OAM buffer to be DMA'd, since it must be aligned to 256 bytes. The first one could be useful for defining an OAM buffer to be DMA'd, since it must be aligned to 256 bytes.
The second could also be appropriate for GBC HDMA, or for an optimized copy code that requires alignment. The second could also be appropriate for GBC HDMA, or for an optimized copy code that requires alignment.
.Bd -literal -offset indent .Bd -literal -offset indent
SECTION "OAM Data",WRAM0,ALIGN[8] ;\ align to 256 bytes SECTION "OAM Data", WRAM0, ALIGN[8] ;\ align to 256 bytes
SECTION "VRAM Data",ROMX,BANK[2],ALIGN[4] ;\ align to 16 bytes SECTION "VRAM Data", ROMX, BANK[2], ALIGN[4] ;\ align to 16 bytes
.Ed .Ed
.El .El
.Pp .Pp
@@ -1275,16 +1275,18 @@ DEF str_SIZEOF EQU 259
.Ed .Ed
.Pp .Pp
There are five commands in the RS group of commands: There are five commands in the RS group of commands:
.Bl -column "RSSET constexpr" .Bl -column "DEF name RB constexpr"
.It Sy Command Ta Sy Meaning .It Sy Command Ta Sy Meaning
.It Ic RSRESET Ta Equivalent to Ql RSSET 0 . .It Ic RSRESET Ta Equivalent to Ql RSSET 0 .
.It Ic RSSET Ar constexpr Ta Sets the Ic _RS No counter to Ar constexpr . .It Ic RSSET Ar constexpr Ta Sets the Ic _RS No counter to Ar constexpr .
.It Ic RB Ar constexpr Ta Sets the preceding symbol to Ic _RS No and adds Ar constexpr No to Ic _RS . .It Ic DEF Ar name Ic RB Ar constexpr Ta Sets Ar name No to Ic _RS No and then adds Ar constexpr No to Ic _RS .
.It Ic RW Ar constexpr Ta Sets the preceding symbol to Ic _RS No and adds Ar constexpr No * 2 to Ic _RS . .It Ic DEF Ar name Ic RW Ar constexpr Ta Sets Ar name No to Ic _RS No and then adds Ar constexpr No * 2 to Ic _RS .
.It Ic RL Ar constexpr Ta Sets the preceding symbol to Ic _RS No and adds Ar constexpr No * 4 to Ic _RS . .It Ic DEF Ar name Ic RL Ar constexpr Ta Sets Ar name No to Ic _RS No and then adds Ar constexpr No * 4 to Ic _RS .
.El .El
.Pp .Pp
If the argument to If the
.Ar constexpr
argument to
.Ic RB , RW , .Ic RB , RW ,
or or
.Ic RL .Ic RL
@@ -1319,7 +1321,7 @@ and
will not expand string constants in their names. will not expand string constants in their names.
.Bd -literal -offset indent .Bd -literal -offset indent
DEF COUNTREG EQUS "[hl+]" DEF COUNTREG EQUS "[hl+]"
ld a,COUNTREG ld a, COUNTREG
DEF PLAYER_NAME EQUS "\e"John\e"" DEF PLAYER_NAME EQUS "\e"John\e""
db PLAYER_NAME db PLAYER_NAME
@@ -1327,7 +1329,7 @@ DEF PLAYER_NAME EQUS "\e"John\e""
.Pp .Pp
This will be interpreted as: This will be interpreted as:
.Bd -literal -offset indent .Bd -literal -offset indent
ld a,[hl+] ld a, [hl+]
db "John" db "John"
.Ed .Ed
.Pp .Pp
@@ -1391,8 +1393,8 @@ So this won't work:
MACRO outer MACRO outer
MACRO inner MACRO inner
PRINTLN "Hello!" PRINTLN "Hello!"
ENDM ENDM ; this actually ends the 'outer' macro...
ENDM ENDM ; ...and then this is a syntax error!
.Ed .Ed
.Pp .Pp
But this will: But this will:
@@ -1637,7 +1639,7 @@ You can also include only part of a file with
.Ic INCBIN . .Ic INCBIN .
The example below includes 256 bytes from data.bin, starting from byte 78. The example below includes 256 bytes from data.bin, starting from byte 78.
.Bd -literal -offset indent .Bd -literal -offset indent
INCBIN "data.bin",78,256 INCBIN "data.bin", 78, 256
.Ed .Ed
.Pp .Pp
The length argument is optional. The length argument is optional.
@@ -1696,10 +1698,10 @@ Unions may be used in any section, but they may only contain space-allocating di
.Ss Invoking macros .Ss Invoking macros
You execute the macro by inserting its name. You execute the macro by inserting its name.
.Bd -literal -offset indent .Bd -literal -offset indent
add a,b add a, b
ld sp,hl ld sp, hl
MyMacro ;\ This will be expanded MyMacro ;\ This will be expanded
sub a,87 sub a, 87
.Ed .Ed
.Pp .Pp
It's valid to call a macro from a macro (yes, even the same one). It's valid to call a macro from a macro (yes, even the same one).
@@ -1716,10 +1718,11 @@ it will insert the macro definition (the code enclosed in
Suppose your macro contains a loop. Suppose your macro contains a loop.
.Bd -literal -offset indent .Bd -literal -offset indent
MACRO LoopyMacro MACRO LoopyMacro
xor a,a xor a, a
\&.loop ld [hl+],a \&.loop
ld [hl+], a
dec c dec c
jr nz,.loop jr nz, .loop
ENDM ENDM
.Ed .Ed
.Pp .Pp
@@ -1734,10 +1737,11 @@ also works in
blocks. blocks.
.Bd -literal -offset indent .Bd -literal -offset indent
MACRO LoopyMacro MACRO LoopyMacro
xor a,a xor a, a
\&.loop\e@ ld [hl+],a \&.loop\e@
ld [hl+], a
dec c dec c
jr nz,.loop\e@ jr nz, .loop\e@
ENDM ENDM
.Ed .Ed
.Pp .Pp
@@ -1763,19 +1767,20 @@ through
being the first argument specified on the macro invocation. being the first argument specified on the macro invocation.
.Bd -literal -offset indent .Bd -literal -offset indent
MACRO LoopyMacro MACRO LoopyMacro
ld hl,\e1 ld hl, \e1
ld c,\e2 ld c, \e2
xor a,a xor a, a
\&.loop\e@ ld [hl+],a \&.loop\e@
ld [hl+], a
dec c dec c
jr nz,.loop\e@ jr nz, .loop\e@
ENDM ENDM
.Ed .Ed
.Pp .Pp
Now you can call the macro specifying two arguments, the first being the address and the second being a byte count. Now you can call the macro specifying two arguments, the first being the address and the second being a byte count.
The generated code will then reset all bytes in this range. The generated code will then reset all bytes in this range.
.Bd -literal -offset indent .Bd -literal -offset indent
LoopyMacro MyVars,54 LoopyMacro MyVars, 54
.Ed .Ed
.Pp .Pp
Arguments are passed as string constants, although there's no need to enclose them in quotes. Arguments are passed as string constants, although there's no need to enclose them in quotes.
@@ -1907,11 +1912,11 @@ and the matching
.Ic ENDR .Ic ENDR
will be repeated a number of times just as if you had done a copy/paste operation yourself. will be repeated a number of times just as if you had done a copy/paste operation yourself.
The following example will assemble The following example will assemble
.Ql add a,c .Ql add a, c
four times: four times:
.Bd -literal -offset indent .Bd -literal -offset indent
REPT 4 REPT 4
add a,c add a, c
ENDR ENDR
.Ed .Ed
.Pp .Pp
@@ -1952,16 +1957,16 @@ ENDR
.Pp .Pp
It acts just as if you had done: It acts just as if you had done:
.Bd -literal -offset indent .Bd -literal -offset indent
N = 0 DEF N = 0
dw N * N dw N * N
N = 1 DEF N = 1
dw N * N dw N * N
N = 2 DEF N = 2
dw N * N dw N * N
; ... ; ...
N = 255 DEF N = 255
dw N * N dw N * N
N = 256 DEF N = 256
.Ed .Ed
.Pp .Pp
You can customize the range of You can customize the range of