mirror of
https://github.com/gbdev/rgbds.git
synced 2026-01-22 16:31:51 +00:00
Implement [[ fragment literals ]] (#1614)
This feature is referred to as "code/data literals" in ASMotor, and simply as "literals" in some older assemblers like MIDAS for the PDP-10. RGBASM already had the "section fragments" feature for keeping disparate contents together when linked, so these worked naturally as "fragment literals".
This commit is contained in:
62
test/asm/fragment-literals.asm
Normal file
62
test/asm/fragment-literals.asm
Normal file
@@ -0,0 +1,62 @@
|
||||
SECTION "1", ROM0[0]
|
||||
|
||||
DEF VERSION EQU $11
|
||||
GetVersion::
|
||||
ld a, [ [[db VERSION]] ]
|
||||
ret
|
||||
|
||||
SECTION "2", ROM0, ALIGN[4]
|
||||
|
||||
MACRO text
|
||||
db \1, 0
|
||||
ENDM
|
||||
|
||||
MACRO text_pointer
|
||||
dw [[
|
||||
text \1
|
||||
]]
|
||||
ENDM
|
||||
|
||||
GetText::
|
||||
ld hl, [[
|
||||
dw [[ db "Alpha", 0 ]]
|
||||
dw [[
|
||||
text "Beta"
|
||||
]]
|
||||
text_pointer "Gamma"
|
||||
dw 0
|
||||
]]
|
||||
ld c, a
|
||||
ld b, 0
|
||||
add hl, bc
|
||||
add hl, bc
|
||||
ld a, [hli]
|
||||
ld h, [hl]
|
||||
ld l, a
|
||||
ret
|
||||
|
||||
SECTION "C", ROM0
|
||||
|
||||
Foo::
|
||||
call [[ jp [[ jp [[ ret ]] ]] ]]
|
||||
call [[
|
||||
Label::
|
||||
call GetVersion
|
||||
DEF MYTEXT EQU 3
|
||||
ld a, MYTEXT
|
||||
call GetText
|
||||
ld b, h
|
||||
ld c, l
|
||||
ret
|
||||
]]
|
||||
jp [[
|
||||
Bar:
|
||||
inc hl
|
||||
.loop
|
||||
nop
|
||||
: dec l
|
||||
jr nz, :-
|
||||
dec h
|
||||
jr nz, .loop
|
||||
ret
|
||||
]]
|
||||
Reference in New Issue
Block a user