mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Add ds cnt, byte syntax
As suggested by https://github.com/rednex/rgbds/issues/350#issuecomment-498030458 The order `count` then `byte` was decided after some discussion: - First argument consistent with single-arg syntax - Intuitive at least to some people other than myself - Consistent with other assemblers, at least ca65
This commit is contained in:
@@ -46,6 +46,7 @@ void out_AbsByteGroup(uint8_t const *s, int32_t length);
|
|||||||
void out_Skip(int32_t skip);
|
void out_Skip(int32_t skip);
|
||||||
void out_String(char const *s);
|
void out_String(char const *s);
|
||||||
void out_RelByte(struct Expression *expr);
|
void out_RelByte(struct Expression *expr);
|
||||||
|
void out_RelBytes(struct Expression *expr, int32_t n);
|
||||||
void out_RelWord(struct Expression *expr);
|
void out_RelWord(struct Expression *expr);
|
||||||
void out_RelLong(struct Expression *expr);
|
void out_RelLong(struct Expression *expr);
|
||||||
void out_PCRelByte(struct Expression *expr);
|
void out_PCRelByte(struct Expression *expr);
|
||||||
|
|||||||
@@ -884,6 +884,10 @@ ds : T_POP_DS uconst
|
|||||||
{
|
{
|
||||||
out_Skip($2);
|
out_Skip($2);
|
||||||
}
|
}
|
||||||
|
| T_POP_DS uconst comma reloc_8bit
|
||||||
|
{
|
||||||
|
out_RelBytes(&$4, $2);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
db : T_POP_DB constlist_8bit_entry comma constlist_8bit {
|
db : T_POP_DB constlist_8bit_entry comma constlist_8bit {
|
||||||
|
|||||||
@@ -799,6 +799,14 @@ Note that strings are not zero-terminated!
|
|||||||
DB 1,2,3,4,"This is a string"
|
DB 1,2,3,4,"This is a string"
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
|
.Ic DS
|
||||||
|
can also be used to fill a region of memory with some value.
|
||||||
|
The following produces 42 times the byte $FF:
|
||||||
|
.Pp
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
DS 42, $FF
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
Alternatively, you can use
|
Alternatively, you can use
|
||||||
.Ic DW
|
.Ic DW
|
||||||
to store a list of words (16-bit) or
|
to store a list of words (16-bit) or
|
||||||
|
|||||||
@@ -295,11 +295,7 @@ void out_String(char const *s)
|
|||||||
absByteBypassCheck(*s++);
|
absByteBypassCheck(*s++);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static void outputExpression(struct Expression const *expr)
|
||||||
* Output a relocatable byte. Checking will be done to see if it
|
|
||||||
* is an absolute value in disguise.
|
|
||||||
*/
|
|
||||||
void out_RelByte(struct Expression *expr)
|
|
||||||
{
|
{
|
||||||
if (!rpn_isKnown(expr)) {
|
if (!rpn_isKnown(expr)) {
|
||||||
out_CreatePatch(PATCHTYPE_BYTE, expr);
|
out_CreatePatch(PATCHTYPE_BYTE, expr);
|
||||||
@@ -307,6 +303,26 @@ void out_RelByte(struct Expression *expr)
|
|||||||
} else {
|
} else {
|
||||||
out_AbsByte(expr->nVal);
|
out_AbsByte(expr->nVal);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output a relocatable byte. Checking will be done to see if it
|
||||||
|
* is an absolute value in disguise.
|
||||||
|
*/
|
||||||
|
void out_RelByte(struct Expression *expr)
|
||||||
|
{
|
||||||
|
outputExpression(expr);
|
||||||
|
rpn_Free(expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output several copies of a relocatable byte. Checking will be done to see if
|
||||||
|
* it is an absolute value in disguise.
|
||||||
|
*/
|
||||||
|
void out_RelBytes(struct Expression *expr, int32_t n)
|
||||||
|
{
|
||||||
|
while (n--)
|
||||||
|
outputExpression(expr);
|
||||||
rpn_Free(expr);
|
rpn_Free(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
test/asm/ds-bad.asm
Normal file
4
test/asm/ds-bad.asm
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
SECTION "test", ROM0[0]
|
||||||
|
|
||||||
|
ds unknown, 0
|
||||||
|
ds 1, $100
|
||||||
5
test/asm/ds-bad.err
Normal file
5
test/asm/ds-bad.err
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
ERROR: ds-bad.asm(3):
|
||||||
|
Expected constant expression: 'unknown' is not constant at assembly time
|
||||||
|
warning: ds-bad.asm(4): [-Wtruncation]
|
||||||
|
Expression must be 8-bit
|
||||||
|
error: Assembly aborted (1 errors)!
|
||||||
0
test/asm/ds-bad.out
Normal file
0
test/asm/ds-bad.out
Normal file
8
test/asm/ds-byte.asm
Normal file
8
test/asm/ds-byte.asm
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
SECTION "test", ROM0[0]
|
||||||
|
|
||||||
|
Label:
|
||||||
|
ds 4, 42
|
||||||
|
.other
|
||||||
|
ds 5, .other - Label - 5 ; Expressions should work...
|
||||||
|
ds 60, .last - Label ; ...even if not constant
|
||||||
|
.last
|
||||||
0
test/asm/ds-byte.err
Normal file
0
test/asm/ds-byte.err
Normal file
0
test/asm/ds-byte.out
Normal file
0
test/asm/ds-byte.out
Normal file
1
test/asm/ds-byte.out.bin
Normal file
1
test/asm/ds-byte.out.bin
Normal file
@@ -0,0 +1 @@
|
|||||||
|
****<2A><><EFBFBD><EFBFBD><EFBFBD>EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
|
||||||
Reference in New Issue
Block a user