aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--unprotbas.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/unprotbas.c b/unprotbas.c
index bf8fc76..acfd528 100644
--- a/unprotbas.c
+++ b/unprotbas.c
@@ -15,7 +15,9 @@
or whatever), we "fix" that by making up new variable names.
*/
-#define STM_OFFSET 0xf2
+/* the difference between the VVTP and VNTP values in the file, and the
+ actual file positions of the variable names and values. */
+#define TBL_OFFSET 0xf2
/* minimum program size, for a program that has no variables and
only one line of code (the immediate line 32768, consisting only of
@@ -23,14 +25,22 @@
can't process. */
#define MIN_PROG_SIZE 21
-#define MAP_FILE "varnames.txt"
+/* maximum size of the program in memory. 64KB is actually way overkill. */
+#define BUFSIZE 65536
+
+/* maximum number of variables in the variable name and value tables. this
+ could be 128, but "ERROR- 4" still expands the tables. Entries >128
+ don't have tokens, can't be referred to in code, but we'll preserve
+ them anyway. */
+#define MAXVARS 256
/* entire file gets read into memory (for now) */
-unsigned char data[65536];
+unsigned char data[BUFSIZE];
/* for the -r option */
-unsigned char varnames[65536];
-unsigned char *varmap[256];
+#define MAP_FILE "varnames.txt"
+unsigned char varnames[BUFSIZE];
+unsigned char *varmap[MAXVARS];
int varmap_count;
/* BASIC 14-byte header values */
@@ -108,9 +118,9 @@ void read_header(void) {
stmtab = getword(8);
stmcur = getword(10);
starp = getword(12);
- codestart = stmtab - STM_OFFSET - (vntp - 256);
- vnstart = vntp - 256 + 14;
- vvstart = vvtp - 256 + 14;
+ codestart = stmtab - TBL_OFFSET - (vntp - 256);
+ vnstart = vntp - TBL_OFFSET;
+ vvstart = vvtp - TBL_OFFSET;
if(verbose) dump_header_vars();
}
@@ -294,6 +304,7 @@ void move_code(int offset) {
or letter+number or one-letter string/array names).
*/
+/* return true if the variable name table is OK */
int vntable_ok(void) {
int vp, bad;
@@ -355,8 +366,8 @@ int rebuild_vntable(int write) {
unsigned char type = data[vv] >> 6;
/* fprintf(stderr, "%04x: %04x, %d\n", vv, data[vv], type); */
- if(varnum == 256) {
- fprintf(stderr, "Warning: skipping variable numbers >=256 in value table.\n");
+ if(varnum == MAXVARS) {
+ fprintf(stderr, "Warning: skipping variable numbers >=%d in value table.\n", MAXVARS);
break;
}
@@ -396,7 +407,7 @@ 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... except really, there can be 129
+ 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++;
@@ -560,7 +571,7 @@ void read_var_map(void) {
}
void apply_var_map(void) {
- unsigned char new_vntable[65536];
+ unsigned char new_vntable[BUFSIZE];
int i, newp = 0;
unsigned char *v;