From 82e506390d12a3ce30604e42af8cbccc448ad861 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 21 May 2023 22:44:06 +0100 Subject: Add .str directive --- tr8as.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tr8as.c') diff --git a/tr8as.c b/tr8as.c index 15143b7..64af41d 100644 --- a/tr8as.c +++ b/tr8as.c @@ -695,6 +695,37 @@ static uint8_t parse_equ(As *as, char **c) return new_define(as, id, value); } +static uint8_t parse_str(As *as, char **c) +{ + /* .str "string" */ + + *c = skip_whitespace(*c); + if (**c != '"') + return error_l("Syntax error", &as->loc, "expected \""); + (*c)++; + + while (**c && **c != '\"' && **c != '\n') + { + if (**c == '\\') + { + (*c)++; + if (**c != '\\' && **c != '"') + return error_l("Syntax error", &as->loc, "invalid escape sequence"); + } + + as->out[as->addr++] = **c; + if (as->addr > as->size) + as->size = as->addr; + (*c)++; + } + + if (**c != '"') + return error_l("Syntax error", &as->loc, "expected \""); + + return 1; +} + + static uint8_t parse_db(As *as, char **c) { char word[MAX_ID + 1]; @@ -1582,6 +1613,7 @@ static InstParse insts[] = { ".incbin", parse_incbin }, { ".org", parse_org }, { ".equ", parse_equ }, + { ".str", parse_str }, { ".db", parse_db }, { ".dw", parse_dw }, { ".ds", parse_ds }, -- cgit v1.2.3