diff --git a/man/rgbasm.5 b/man/rgbasm.5 index 0e43886e..5a7df967 100644 --- a/man/rgbasm.5 +++ b/man/rgbasm.5 @@ -43,7 +43,9 @@ Labels tie a name to a specific location within a section (see below). .Pp Instructions are assembled into Game Boy opcodes. -Multiple instructions on one line can be separated by double colons +Multiple instructions on one line, as well as data directives (see +.Sx Defining constant data in ROM +below), can be separated by double colons .Ql :: . .Pp The available instructions are documented in diff --git a/src/asm/parser.y b/src/asm/parser.y index 09fcedb9..218c3efa 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -480,7 +480,7 @@ else: plain_directive: label - | label cpu_commands + | label data | label macro | label directive ; @@ -562,10 +562,6 @@ directive: | println | export | export_def - | db - | dw - | dl - | ds | section | rsreset | rsset @@ -889,56 +885,6 @@ endu: } ; -ds: - POP_DS uconst { - sect_Skip($2, true); - } - | POP_DS uconst COMMA ds_args trailing_comma { - sect_RelBytes($2, $4); - } - | POP_DS POP_ALIGN LBRACK align_spec RBRACK trailing_comma { - uint32_t n = sect_GetAlignBytes($4.alignment, $4.alignOfs); - sect_Skip(n, true); - sect_AlignPC($4.alignment, $4.alignOfs); - } - | POP_DS POP_ALIGN LBRACK align_spec RBRACK COMMA ds_args trailing_comma { - uint32_t n = sect_GetAlignBytes($4.alignment, $4.alignOfs); - sect_RelBytes(n, $7); - sect_AlignPC($4.alignment, $4.alignOfs); - } -; - -ds_args: - reloc_8bit { - $$.push_back(std::move($1)); - } - | ds_args COMMA reloc_8bit { - $$ = std::move($1); - $$.push_back(std::move($3)); - } -; - -db: - POP_DB { - sect_Skip(1, false); - } - | POP_DB constlist_8bit trailing_comma -; - -dw: - POP_DW { - sect_Skip(2, false); - } - | POP_DW constlist_16bit trailing_comma -; - -dl: - POP_DL { - sect_Skip(4, false); - } - | POP_DL constlist_32bit trailing_comma -; - def_equ: def_id POP_EQU iconst { $$ = std::move($1); @@ -1775,15 +1721,19 @@ sect_attrs: } ; -// CPU commands. +// CPU instructions and data declarations -cpu_commands: - cpu_command - | cpu_command DOUBLE_COLON cpu_commands +data: + datum + | datum DOUBLE_COLON data ; -cpu_command: - sm83_adc +datum: + db + | dw + | dl + | ds + | sm83_adc | sm83_add | sm83_and | sm83_bit @@ -1831,6 +1781,56 @@ cpu_command: | sm83_xor ; +ds: + POP_DS uconst { + sect_Skip($2, true); + } + | POP_DS uconst COMMA ds_args trailing_comma { + sect_RelBytes($2, $4); + } + | POP_DS POP_ALIGN LBRACK align_spec RBRACK trailing_comma { + uint32_t n = sect_GetAlignBytes($4.alignment, $4.alignOfs); + sect_Skip(n, true); + sect_AlignPC($4.alignment, $4.alignOfs); + } + | POP_DS POP_ALIGN LBRACK align_spec RBRACK COMMA ds_args trailing_comma { + uint32_t n = sect_GetAlignBytes($4.alignment, $4.alignOfs); + sect_RelBytes(n, $7); + sect_AlignPC($4.alignment, $4.alignOfs); + } +; + +ds_args: + reloc_8bit { + $$.push_back(std::move($1)); + } + | ds_args COMMA reloc_8bit { + $$ = std::move($1); + $$.push_back(std::move($3)); + } +; + +db: + POP_DB { + sect_Skip(1, false); + } + | POP_DB constlist_8bit trailing_comma +; + +dw: + POP_DW { + sect_Skip(2, false); + } + | POP_DW constlist_16bit trailing_comma +; + +dl: + POP_DL { + sect_Skip(4, false); + } + | POP_DL constlist_32bit trailing_comma +; + sm83_adc: SM83_ADC op_a_n { sect_ConstByte(0xCE); diff --git a/test/asm/multiple-instructions.asm b/test/asm/multiple-instructions.asm index 0a7afb07..3ef0b382 100644 --- a/test/asm/multiple-instructions.asm +++ b/test/asm/multiple-instructions.asm @@ -9,3 +9,5 @@ Label: nop :: call z, .local :: ld b, a Label2::jr Label2::ret .local2::call nz, .local2::ret + +Label3:: db 1, 2 :: dw 3, 4 :: dl 5, 6 :: ds 7, 8 :: ret diff --git a/test/asm/multiple-instructions.out.bin b/test/asm/multiple-instructions.out.bin index 643ee943..af9fda27 100644 Binary files a/test/asm/multiple-instructions.out.bin and b/test/asm/multiple-instructions.out.bin differ