From a68295151788760d694ef136b00c773973aba772 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 12 May 2023 22:06:18 +0100 Subject: Add .ds directive --- README.md | 3 +++ game/main.asm | 3 +++ tr8as.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) 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 }, -- cgit v1.2.3