mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-23 11:32:07 +00:00
Edit some documentation of unions and macros
This commit is contained in:
66
man/rgbasm.5
66
man/rgbasm.5
@@ -1688,39 +1688,50 @@ keyword.
|
|||||||
.Ic NEXTU
|
.Ic NEXTU
|
||||||
separates each block of allocations, and you may use it as many times within a union as necessary.
|
separates each block of allocations, and you may use it as many times within a union as necessary.
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
; Let's say PC = $C0DE here
|
; Let's say PC == $C0DE here
|
||||||
UNION
|
UNION
|
||||||
; Here, PC = $C0DE
|
; Here, PC == $C0DE
|
||||||
Name: ds 8
|
wName:: ds 10
|
||||||
; PC = $C0E6
|
; Now, PC == $C0E8
|
||||||
Nickname: ds 8
|
wNickname:: ds 10
|
||||||
; PC = $C0EE
|
; PC == $C0F2
|
||||||
NEXTU
|
NEXTU
|
||||||
; PC is back to $C0DE
|
; PC is back to $C0DE
|
||||||
Health: dw
|
wHealth:: dw
|
||||||
; PC = $C0E0
|
; PC == $C0E0
|
||||||
Something: ds 6
|
wLives:: db
|
||||||
; And so on
|
; PC == $C0E1
|
||||||
Lives: db
|
ds 7
|
||||||
NEXTU
|
; PC == $C0E8
|
||||||
VideoBuffer: ds 19
|
wBonus:: db
|
||||||
ENDU
|
; PC == $C0E9
|
||||||
|
NEXTU
|
||||||
|
; PC is back to $C0DE again
|
||||||
|
wVideoBuffer: ds 16
|
||||||
|
; PC == $C0EE
|
||||||
|
ENDU
|
||||||
|
; Afterward, PC == $C0F2
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
In the example above,
|
In the example above,
|
||||||
.Sq Name , Health , VideoBuffer
|
.Sq wName , wHealth ,
|
||||||
all have the same value, as do
|
|
||||||
.Sq Nickname
|
|
||||||
and
|
and
|
||||||
.Sq Lives .
|
.Sq wVideoBuffer
|
||||||
|
all have the same value; so do
|
||||||
|
.Sq wNickname
|
||||||
|
and
|
||||||
|
.Sq wBonus .
|
||||||
Thus, keep in mind that
|
Thus, keep in mind that
|
||||||
.Ql ld [Health], a
|
.Ql ld [wHealth], a
|
||||||
is identical to
|
assembles to the exact same thing as
|
||||||
.Ql ld [Name], a .
|
.Ql ld [wName], a .
|
||||||
.Pp
|
.Pp
|
||||||
The size of this union is 19 bytes, as this is the size of the largest block (the last one, containing
|
This whole union's total size is 20 bytes, the size of the largest block (the first one, containing
|
||||||
.Sq VideoBuffer ) .
|
.Sq wName
|
||||||
Nesting unions is possible, with each inner union's size being considered as described above.
|
and
|
||||||
|
.Sq wNickname ) .
|
||||||
|
.Pp
|
||||||
|
Unions may be nested, with each inner union's size being determined as above, and affecting its outer union like any other allocation.
|
||||||
.Pp
|
.Pp
|
||||||
Unions may be used in any section, but they may only contain space-allocating directives like
|
Unions may be used in any section, but they may only contain space-allocating directives like
|
||||||
.Ic DS
|
.Ic DS
|
||||||
@@ -1728,12 +1739,13 @@ Unions may be used in any section, but they may only contain space-allocating di
|
|||||||
.Sx Statically allocating space in RAM ) .
|
.Sx Statically allocating space in RAM ) .
|
||||||
.Sh THE MACRO LANGUAGE
|
.Sh THE MACRO LANGUAGE
|
||||||
.Ss Invoking macros
|
.Ss Invoking macros
|
||||||
You execute the macro by inserting its name.
|
A macro is invoked by writing its name at the beginning of a line, followed by any arguments.
|
||||||
.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
|
||||||
|
MyMacro 42 ;\ So will this
|
||||||
.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).
|
||||||
|
|||||||
Reference in New Issue
Block a user