From a1fe7b51bd364c309f1f1a79e57653f0e67307d4 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 27 May 2024 15:55:42 -0400 Subject: unprotbas: fixline() commentary. --- unprotbas.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'unprotbas.c') diff --git a/unprotbas.c b/unprotbas.c index c59a33c..c458e9f 100644 --- a/unprotbas.c +++ b/unprotbas.c @@ -34,6 +34,9 @@ them anyway. */ #define MAXVARS 256 +/* tokenized colon (statement separator) */ +#define TOK_COLON 0x14 + /* entire file gets read into memory (for now) */ unsigned char data[BUFSIZE]; @@ -153,13 +156,17 @@ void set_header_vars(void) { 2 09 line length (or, offset to next line) [!] 3 06 offset to next statement *from the start of the line* 4 28 token for "?" - 5 14 token for : (end of statement) + 5 14 token for : (end of statement), we call it TOK_COLON 6 09 offset to next statement [!] 7 15 token for END 8 16 token for end-of-line [*] 9 ?? (line number of next statement) Note the values marked with [!] are equal. + The line length at offset 2 is what gets zeroed out by the + protection. To fix it, we follow the next-statement offsets. If + there's not a colon before the offset, replace the byte at + offset 2 with that statement's offset. [*] end-of-line is $16 *except* for REM and DATA, which are terminated with $9B instead. @@ -168,7 +175,7 @@ int fixline(int linepos) { /* +3 here to skip the line number + line length */ int offset = data[linepos + 3]; - while(data[linepos + offset - 1] == 0x14) + while(data[linepos + offset - 1] == TOK_COLON) offset = data[linepos + offset]; data[linepos + 2] = offset; -- cgit v1.2.3