aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-05-22 16:00:57 -0400
committerB. Watson <urchlay@slackware.uk>2024-05-22 16:00:57 -0400
commit7fc45e8ac37dde5026a8b6bc1e8190e69107f94a (patch)
tree1eaedb8a91d8e3ab66a2b0b71aba48352dce755f
parenta1144de8efebc414c33a0df9b8fccd758a242586 (diff)
downloadbw-atari8-tools-7fc45e8ac37dde5026a8b6bc1e8190e69107f94a.tar.gz
unprotbas: handle corner case where 129 vars are in the table.
-rw-r--r--unprotbas.135
-rw-r--r--unprotbas.c31
-rw-r--r--unprotbas.rst31
3 files changed, 65 insertions, 32 deletions
diff --git a/unprotbas.1 b/unprotbas.1
index 992bd28..b2e44f5 100644
--- a/unprotbas.1
+++ b/unprotbas.1
@@ -234,21 +234,38 @@ Load the unprotected program on the Atari and LIST it (or use \fBchkbas\fP to ge
listing), and edit \fBvarnames.txt\fP in a text editor.
.sp
As you figure out what each variable\(aqs purpose is, change its name
-in the text file. Don\(aqt delete any lines from the file, and don\(aqt
-add any. Don\(aqt get rid of the \fI$\fP or \fI(\fP at the end of any line. You
-may enter the names in lowercase (\fBunprotbas\fP will convert them to
-uppercase). Remember to follow the rules for BASIC variable names:
-only letters and numbers allowed, and the first character must be
-a letter. No duplicates of the same type are allowed (you can have
-\fIFOO\fP and \fIFOO$\fP, but not two numerics called \fIFOO\fP).
+in the text file. When editing the file:
+.INDENT 0.0
+.IP \(bu 2
+Don\(aqt add or delete any lines.
+.IP \(bu 2
+Don\(aqt get rid of the \fI$\fP or \fI(\fP at the end of any line.
+.IP \(bu 2
+You may enter the names in lowercase (\fBunprotbas\fP will convert them to uppercase).
+.IP \(bu 2
+Remember to follow the rules for BASIC variable names:
+The first character must be a letter, other characters must be a letter
+or a number, and only the last character can be \fI$\fP or \fI(\fP\&.
+.IP \(bu 2
+No duplicates of the same type are allowed (you can have \fIFOO\fP and \fIFOO$\fP,
+but not two numerics called \fIFOO\fP).
+.UNINDENT
.sp
When you\(aqre finished, re\-run \fBunprotbas\fP, this time with the \fB\-r\fP
-option. The unprotected program will use your variable names, rather
-than generating new ones.
+option. If all is well, the unprotected program will use your variable
+names, rather than generating new ones. If you broke the rules, you
+should get an informative error message explaining what and where the
+problem is.
.sp
This process can also be used for regular unprotected programs. Use
\fB\-n \-w\fP the first time, to save the existing variable names to
\fBvarnames.txt\fP rather than generating new ones.
+.SH NOTES
+.sp
+Atari BASIC has a limit of 128 variables in a program. It\(aqs actually
+possible for the variable name table (and the variable value table)
+to contain 129 variables, though the last one won\(aqt be usable in the
+program.
.SH COPYRIGHT
.sp
WTFPL. See \fI\%http://www.wtfpl.net/txt/copying/\fP for details.
diff --git a/unprotbas.c b/unprotbas.c
index 5ad483b..5748461 100644
--- a/unprotbas.c
+++ b/unprotbas.c
@@ -30,7 +30,7 @@ unsigned char data[65536];
/* for the -r option */
unsigned char varnames[65536];
-unsigned char *varmap[128];
+unsigned char *varmap[129];
int varmap_count;
/* BASIC 14-byte header values */
@@ -351,17 +351,10 @@ int rebuild_vntable(int write) {
}
/* there's supposed to be a null byte at the end of the table, unless
- all 128 table slots are used. */
- if(write) {
- if(varnum < 128) data[vp] = 0;
- /* fixup the VNTD pointer */
- /*
- vntd = vntp + (vp - vnstart);
- fprintf(stderr, "%04x\n", vntd);
- data[4] = vntd & 0xff;
- data[5] = vntd >> 8;
- */
- }
+ all 128 table slots are used... except really, there can be 129
+ entries, and there's always a null byte. */
+ if(write) data[vp] = 0;
+ size++;
return size;
}
@@ -439,7 +432,12 @@ void check_varname(const unsigned char *name, int line) {
c = name[i];
if(c >= 'A' && c <= 'Z') continue;
if(c >= '0' && c <= '9') continue;
- if(i == (len - 1) && ((c == '$') || (c == '('))) continue;
+ if(c == '$' || c == '(') {
+ if(i == (len - 1))
+ continue;
+ else
+ die_mapfile("invalid variable name: $ and ( only allowed at end", line);
+ }
die_mapfile("invalid character in variable name", line);
}
@@ -506,6 +504,7 @@ void read_var_map(void) {
fprintf(stderr, MAP_FILE ": too many variables (have %d, need %d).\n", count, vvcount);
exit(1);
}
+
#if 0
for(count = 0; varmap[count] != NULL; count++) {
fprintf(stderr, "\t%02d %s\n", count, varmap[count]);
@@ -520,6 +519,9 @@ void apply_var_map(void) {
int i, newp = 0;
unsigned char *v;
+ if(verbose)
+ fprintf(stderr, "using variable names from " MAP_FILE "\n");
+
for(i = 0; i < varmap_count; i++) {
v = varmap[i];
while(*v) {
@@ -529,7 +531,8 @@ void apply_var_map(void) {
new_vntable[newp - 1] |= 0x80;
}
- if(varmap_count < 128) new_vntable[newp++] = '\0';
+ /* if(varmap_count < 128) */
+ new_vntable[newp++] = '\0';
i = vvstart - vnstart;
adjust_vntable_size(i, newp);
diff --git a/unprotbas.rst b/unprotbas.rst
index 752acd7..6ba560c 100644
--- a/unprotbas.rst
+++ b/unprotbas.rst
@@ -206,20 +206,33 @@ Load the unprotected program on the Atari and LIST it (or use **chkbas** to get
listing), and edit **varnames.txt** in a text editor.
As you figure out what each variable's purpose is, change its name
-in the text file. Don't delete any lines from the file, and don't
-add any. Don't get rid of the *$* or *(* at the end of any line. You
-may enter the names in lowercase (**unprotbas** will convert them to
-uppercase). Remember to follow the rules for BASIC variable names:
-only letters and numbers allowed, and the first character must be
-a letter. No duplicates of the same type are allowed (you can have
-*FOO* and *FOO$*, but not two numerics called *FOO*).
+in the text file. When editing the file:
+
+- Don't add or delete any lines.
+- Don't get rid of the *$* or *(* at the end of any line.
+- You may enter the names in lowercase (**unprotbas** will convert them to uppercase).
+- Remember to follow the rules for BASIC variable names:
+ The first character must be a letter, other characters must be a letter
+ or a number, and only the last character can be *$* or *(*.
+- No duplicates of the same type are allowed (you can have *FOO* and *FOO$*,
+ but not two numerics called *FOO*).
When you're finished, re-run **unprotbas**, this time with the **-r**
-option. The unprotected program will use your variable names, rather
-than generating new ones.
+option. If all is well, the unprotected program will use your variable
+names, rather than generating new ones. If you broke the rules, you
+should get an informative error message explaining what and where the
+problem is.
This process can also be used for regular unprotected programs. Use
**-n -w** the first time, to save the existing variable names to
**varnames.txt** rather than generating new ones.
+NOTES
+=====
+
+Atari BASIC has a limit of 128 variables in a program. It's actually
+possible for the variable name table (and the variable value table)
+to contain 129 variables, though the last one won't be usable in the
+program.
+
.. include:: manftr.rst