aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--unprotbas.c11
1 files changed, 9 insertions, 2 deletions
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;