diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-21 22:44:06 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-21 22:44:06 +0100 |
commit | 82e506390d12a3ce30604e42af8cbccc448ad861 (patch) | |
tree | ee6da5aeb4b5f10267850072caf856efff0d7b80 | |
parent | 6909a1a5f7e2eeb15d451af99072774593321158 (diff) | |
download | tr8vm-82e506390d12a3ce30604e42af8cbccc448ad861.tar.gz tr8vm-82e506390d12a3ce30604e42af8cbccc448ad861.zip |
Add .str directive
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | tr8as.c | 32 |
2 files changed, 35 insertions, 0 deletions
@@ -294,6 +294,9 @@ and `>`for the high byte. **.dw imm [, imm]** Literal word (16-bit value). +**.str "string"** +Include the string as literal bytes. Use `\"` to escape a quote and `\\` to escape de backslash. The string is not zero ended, use `.db` to add a zero if needed. + **.ds count, imm** Generates `count` bytes with value `imm`. @@ -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 }, |