From 944b59a1e25f254694e5c58fddcb461d5a05a5a4 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 17 Jul 2024 04:07:02 -0400 Subject: listbas: print Turbo/BXL/BXE hex constants correctly (in hex!). --- listbas.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'listbas.c') diff --git a/listbas.c b/listbas.c index dac8253..33f6202 100644 --- a/listbas.c +++ b/listbas.c @@ -300,9 +300,17 @@ void color_off(void) { fputs(COLOR_OFF, outfh); } -void print_number(unsigned int pos) { +void print_number(unsigned int pos, int hex) { + double num = bcd2double(program + pos); if(color) color_on(color_const); - fprintf(outfh, "%G", bcd2double(program + pos)); + if(hex) { + if(num < 0 || num > 0xffff) { + fprintf(stderr, "%s: invalid Turbo/BXL/BXE hex const %lf at pos $%04x\n", self, num, pos); + } + fprintf(outfh, (num > 0xff ? "%04x" : "%02x"), (unsigned int)num); + } else { + fprintf(outfh, "%G", num); + } if(color) color_off(); } @@ -598,10 +606,10 @@ CALLBACK(print_op) { case OP_HEXCONST: if(color) color_on(color_op); outchr('$'); - if(color) color_off(); - /* fall thru */ + print_number(pos + 1, 1); + return; case OP_NUMCONST: - print_number(pos + 1); + print_number(pos + 1, 0); return; case OP_STRCONST: print_string(pos + 2, program[pos + 1]); @@ -815,7 +823,7 @@ void init_bas_dialect() { if(autodetect) detect_bas_dialect(); - if(bas_type == B_BXL || bas_type == B_BXE) + if(bas_type == B_TURBO || bas_type == B_BXL || bas_type == B_BXE) allow_hex_const = 1; if(bas_type == B_APLUS) -- cgit v1.2.3