diff options
Diffstat (limited to 'listamsb.c')
-rw-r--r-- | listamsb.c | 30 |
1 files changed, 22 insertions, 8 deletions
@@ -550,21 +550,28 @@ int crunch_line(void) { /* only called during decrunching. only handles one-byte tokens (only has to). */ -void expand_token(unsigned char t, unsigned char *buf) { +void expand_token(int ext, unsigned char t, unsigned char *buf) { + const char *result; + if(t < 0x80) { buf[0] = t; buf[1] = 0; return; } - strcpy((char *)buf, std_tokens[t - MIN_STD_TOK]); + if(ext) + result = ext_tokens[t - MIN_EXT_TOK]; + else + result = std_tokens[t - MIN_STD_TOK]; + + strcpy((char *)buf, result); } /* only called during decrunching. the tokenizer in AMSB requires spaces to separate keywords and variables/numbers. "IF A THEN 100" really needs the spaces before and after the A, for example. */ -int need_space_between(unsigned char t1, unsigned char t2) { +int need_space_between(int ext1, int ext2, unsigned char t1, unsigned char t2) { unsigned char tok1[10], tok2[10]; unsigned char t1last, t2first; @@ -575,8 +582,8 @@ int need_space_between(unsigned char t1, unsigned char t2) { if(t1 > MAX_STD_TOK || t2 > MAX_STD_TOK) die("invalid token in program, can't decrunch"); - expand_token(t1, tok1); - expand_token(t2, tok2); + expand_token(ext1, t1, tok1); + expand_token(ext2, t2, tok2); t1last = tok1[strlen((char *)tok1) - 1]; /* "PRINT" => "T" */ t2first = tok2[0]; /* "PRINT" => "P" */ @@ -624,12 +631,19 @@ int decrunch_line(void) { } else if(byte == TOK_REM || byte == TOK_SQUOTE || byte == TOK_BANG) { in_comment = 1; } else if(byte == 0xff) { - /* extended/function tokens never need a space before/after them */ - code[codelen++] = byte; byte = read_prog_byte(); + if(need_space_between(0, 1, prev, byte)) + code[codelen++] = ' '; + code[codelen++] = 0xff; code[codelen++] = byte; + prev = byte; + /* XXX: this next bit assumes there will never be two + extended tokens in a row. I *think* this is true, but + I'm not 100% certain. */ byte = read_prog_byte(); - } else if(need_space_between(prev, byte)) { + if(need_space_between(1, 0, prev, byte)) + code[codelen++] = ' '; + } else if(need_space_between(0, 0, prev, byte)) { code[codelen++] = ' '; } } |