From c150802bc351b221f380e295afe1239ad70de50b Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 17 Jul 2024 04:40:53 -0400 Subject: listbas: support all 256 variable names in Turbo BASIC. --- TODO | 1 - bas.c | 5 +++++ listbas.c | 56 ++++++++++++++++++++++++++++++++------------------------ 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/TODO b/TODO index cdeb1a4..d09cebe 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ for now: listbas: -- Turbo BASIC tokens for variables 128-255 not recognized. - A+/BXL/BXE indentation not supported at all. These may need library (xex.c) changes: diff --git a/bas.c b/bas.c index cf03f38..e5df296 100644 --- a/bas.c +++ b/bas.c @@ -394,6 +394,11 @@ void walk_code(unsigned int startlineno, unsigned int endlineno) { while(pos < end) { /* loop over operators */ tok = program[pos]; switch(tok) { + case 0: /* Turbo variables numbered >= $80 */ + CALL(on_exp_token); + /* on_exp_token callback better know what to do with $00! */ + pos += 2; + break; case OP_NUMCONST: CALL(on_exp_token); pos++; diff --git a/listbas.c b/listbas.c index 33f6202..11455e5 100644 --- a/listbas.c +++ b/listbas.c @@ -599,10 +599,42 @@ void op_color_on(unsigned char tok) { color_on(color_op); /* in case of bad token when bas_type == B_BASIC */ } +void print_varname(unsigned char varnum) { + int i, count; + unsigned char c; + + if(color) color_on(color_varnames); + + for(i = vnstart, count = 0; count < varnum; i++) { + if(program[i] & 0x80) count++; + if(i == codestart) { + fprintf(outfh, "(bad var tok $%02x)", varnum | 0x80); + return; + } + } + + do { + c = program[i++]; + if(color && c == ('(' | 0x80)) { + if(color) color_on(color_op); + } + outchr(c & 0x7f); + } while (c < 0x80); + if(color) color_off(); +} + CALLBACK(print_op) { const char *name; switch(tok) { + case 0: /* Turbo variables numbered >= $80 */ + if(bas_type == B_TURBO) { + print_varname(program[pos + 1] | 0x80); + return; + } else { + fprintf(stderr, "%s: got Turbo ext var tok at line %d, in non-Turbo program!\n", self, lineno); + } + break; case OP_HEXCONST: if(color) color_on(color_op); outchr('$'); @@ -633,30 +665,6 @@ CALLBACK(print_op) { if(color) color_off(); } -void print_varname(unsigned char varnum) { - int i, count; - unsigned char c; - - if(color) color_on(color_varnames); - - for(i = vnstart, count = 0; count < varnum; i++) { - if(program[i] & 0x80) count++; - if(i == codestart) { - fprintf(outfh, "(bad var tok $%02x)", varnum | 0x80); - return; - } - } - - do { - c = program[i++]; - if(color && c == ('(' | 0x80)) { - if(color) color_on(color_op); - } - outchr(c & 0x7f); - } while (c < 0x80); - if(color) color_off(); -} - /* for normal BASIC/A+/XL/XE variable tokens, $80-$FF. Turbo uses these, too, but it supports 256 variables, so it only uses $80-$FF for the first 128 vars. */ -- cgit v1.2.3