aboutsummaryrefslogtreecommitdiff
path: root/unprotbas.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-05-27 15:55:42 -0400
committerB. Watson <urchlay@slackware.uk>2024-05-27 15:55:42 -0400
commita1fe7b51bd364c309f1f1a79e57653f0e67307d4 (patch)
tree40e0d2babfbd255b269a9dabe7cdd62630561163 /unprotbas.c
parentebb5c5ebc85b7f5b3a0a80e8021a80b0aebcedf6 (diff)
downloadbw-atari8-tools-a1fe7b51bd364c309f1f1a79e57653f0e67307d4.tar.gz
unprotbas: fixline() commentary.
Diffstat (limited to 'unprotbas.c')
-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;