aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-12 22:06:18 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-12 22:06:18 +0100
commita68295151788760d694ef136b00c773973aba772 (patch)
tree0c4272f1a69bb609a673eba29693aa8223a3b89e
parent9e4698a5212e3fccea30145ec41ee7ac822bcd0b (diff)
downloadtr8vm-a68295151788760d694ef136b00c773973aba772.tar.gz
tr8vm-a68295151788760d694ef136b00c773973aba772.zip
Add .ds directive
-rw-r--r--README.md3
-rw-r--r--game/main.asm3
-rw-r--r--tr8as.c49
3 files changed, 55 insertions, 0 deletions
diff --git a/README.md b/README.md
index 9c0f625..b00e1a9 100644
--- a/README.md
+++ b/README.md
@@ -294,6 +294,9 @@ and `>`for the high byte.
.dw imm [, imm]
Literal word (16-bit value).
+.ds count, imm
+Generates `count` bytes with value `imm`.
+
.equ id value
Define an ID assigning a constant value. When the id is used, it will be replaced with its value.
diff --git a/game/main.asm b/game/main.asm
index 4b9a81f..8373f37 100644
--- a/game/main.asm
+++ b/game/main.asm
@@ -267,6 +267,9 @@ player_coord:
.dw player_sprite
.dw player_update
+ ; 16 entities
+ .ds 112, 0
+
; end of list
.db ET_END
diff --git a/tr8as.c b/tr8as.c
index cfaa80b..0237683 100644
--- a/tr8as.c
+++ b/tr8as.c
@@ -770,6 +770,54 @@ static uint8_t parse_dw(As *as, char **c)
return 1;
}
+static uint8_t parse_ds(As *as, char **c)
+{
+ char word[MAX_ID + 1];
+ uint8_t wlen;
+ uint16_t count = 0xff, imm = 0xff;
+
+ /* .ds count, imm */
+
+ if (!next_word(as, c, word, &wlen))
+ return 0;
+
+ if (wlen == 0)
+ return error_l("Syntax error", &as->loc, "expected count");
+
+ if (!next_imm(as, word, &count))
+ return error_l("Syntax error", &as->loc, "expected count");
+
+ *c = skip_whitespace(*c);
+ if (**c != ',')
+ return error_l("Syntax error", &as->loc, "expected ,");
+ (*c)++;
+
+ if (!next_word(as, c, word, &wlen))
+ return 0;
+
+ if (wlen == 0)
+ return error_l("Syntax error", &as->loc, "expected immediate");
+
+ if (next_imm(as, word, &count))
+ {
+ if (imm > 0xff)
+ return error_l("Overflow in immediate", &as->loc, word);
+ }
+ else
+ return error_l("Syntax error", &as->loc, "expected immediate");
+
+ if (as->addr + count > UINT16_MAX)
+ return error_l("Memory overflow", &as->loc, "output is more than 65535 bytes");
+
+ for (uint16_t i = 0; i < count; i++)
+ as->out[as->addr++] = imm & 0xff;
+
+ if (as->addr > as->size)
+ as->size = as->addr;
+
+ return 1;
+}
+
static uint8_t parse_nop(As *as, char **c)
{
/* NOP */
@@ -1530,6 +1578,7 @@ static InstParse insts[] =
{ ".equ", parse_equ },
{ ".db", parse_db },
{ ".dw", parse_dw },
+ { ".ds", parse_ds },
{ "halt", parse_halt },
{ "push", parse_push },
{ "port", parse_port },