diff options
author | B. Watson <urchlay@slackware.uk> | 2024-07-17 04:07:02 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-07-17 04:07:02 -0400 |
commit | 944b59a1e25f254694e5c58fddcb461d5a05a5a4 (patch) | |
tree | 460e589aece3c67bada0a7e52c83c134c1abc203 | |
parent | 18bfe53f6d36a30ed2867aced9999e8d91f57a5f (diff) | |
download | bw-atari8-tools-944b59a1e25f254694e5c58fddcb461d5a05a5a4.tar.gz |
listbas: print Turbo/BXL/BXE hex constants correctly (in hex!).
-rw-r--r-- | listbas.c | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -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) |