aboutsummaryrefslogtreecommitdiff
path: root/bas2aplus.c
diff options
context:
space:
mode:
Diffstat (limited to 'bas2aplus.c')
-rw-r--r--bas2aplus.c91
1 files changed, 62 insertions, 29 deletions
diff --git a/bas2aplus.c b/bas2aplus.c
index d7768cd..ee71130 100644
--- a/bas2aplus.c
+++ b/bas2aplus.c
@@ -9,11 +9,10 @@
#undef DUMP_TABLES
-#ifdef DUMP_TABLES
#include "tokens.c"
#include "aplus_tokens.c"
#include "bxl_tokens.c"
-#endif
+#include "bxe_tokens.c"
/* there are a few more BXL commands past 0x55, but they have no
A+ equivalents. */
@@ -66,10 +65,11 @@ unsigned char cmd_table[] = {
...though BUMP( and FIND( do have A+ equivalents (they just need
a left paren inserted after) */
unsigned char op_table[] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 0x0e, /* convert BXL hex const to decimal */
- 0, 0, 0, 0,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* not used: 0x00-0x07 */
+ 0xff, 0xff, 0xff, 0xff, 0xff, /* not used: 0x08-0x0c */
+ 0x0e, /* convert BXL hex const to decimal */
+ 0x0e, 0x0f, /* numeric and string consts are the same */
+ 0xff, 0xff, /* these 2 not used: 0x10-0x11 */
/* these are the same, 0x12-0x1b */
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
@@ -171,39 +171,72 @@ void parse_args(int argc, char **argv) {
die("Only one input and one output file allowed.");
}
-CALLBACK(conv_cmd) {
- if(tok > LAST_BXL_CMD) {
- fprintf(stderr, "%s: Invalid cmd token %02x at line %d, pos %04x, skipping.\n",
- self, tok, lineno, pos);
- return;
+const char *get_tok_name(unsigned char tok, int is_cmd) {
+ if(is_cmd) {
+ if(tok <= last_command) {
+ return commands[tok];
+ } else if(tok == 0x5a) {
+ return "BASIC XL LOCAL/EXIT/PROCEDURE/CALL/SORTUP/SORTDOWN";
+ } else if(tok == 0x59 || (tok > 0x5a && tok < 0x65)) {
+ return bxe_cmds[tok - 0x57];
+ } else if(tok > last_command && tok <= 0x58) {
+ return bxl_cmds[tok - 0x38];
+ } else {
+ return "(maybe Turbo BASIC?)";
+ }
+ } else {
+ if(tok < 0x12) return "";
+ if(tok <= last_operator) {
+ return operators[tok];
+ } else if(tok <= 0x68) {
+ return bxl_ops[tok - 0x55];
+ } else {
+ return "(maybe Turbo BASIC?)";
+ }
}
+}
- program[pos] = cmd_table[tok];
- if(verbose)
- fprintf(stderr, "cmd tok %02x converted to %02x at line %d, pos %04x\n", tok, program[pos], lineno, pos);
+void unsupported_msg(unsigned char tok, int lineno, int is_cmd) {
+ fprintf(stderr, "%s: Invalid %s \"%s\" (%02x) at line %d, not converted.\n",
+ self, is_cmd ? "command" : "operator", get_tok_name(tok, is_cmd), tok, lineno);
}
-CALLBACK(conv_op) {
- unsigned char newtok;
+int is_supported_cmd(unsigned char tok, int lineno) {
+ if(tok > LAST_BXL_CMD) {
+ unsupported_msg(tok, lineno, 1);
+ return 0;
+ }
+ return 1;
+}
- if(tok < 0x12 && tok != OP_HEXCONST) return;
+int is_supported_op(unsigned char tok, int lineno) {
+ if(tok > LAST_BXL_OP || op_table[tok] == 0xff) {
+ unsupported_msg(tok, lineno, 0);
+ return 0;
+ }
+ return 1;
+}
- if(tok > LAST_BXL_OP) {
- fprintf(stderr, "%s: Invalid op token %02x at line %d, pos %04x, skipping.\n",
- self, tok, lineno, pos);
+CALLBACK(conv_cmd) {
+ if(!is_supported_cmd(tok, lineno))
return;
- }
- newtok = op_table[tok];
- if(newtok == 0xff) {
- fprintf(stderr, "%s: BXL op token %02x at line %d, pos %04x, has no A+ equivalent, skipping.\n",
- self, tok, lineno, pos);
+ program[pos] = cmd_table[tok];
+
+ if(verbose && tok != program[pos])
+ fprintf(stderr, "cmd tok \"%s\" ($%02x) converted to $%02x at line %d, pos $%04x\n",
+ get_tok_name(tok, 1), tok, program[pos], lineno, pos);
+}
+
+CALLBACK(conv_op) {
+ if(!is_supported_op(tok, lineno))
return;
- }
- program[pos] = newtok;
- if(verbose)
- fprintf(stderr, "op tok %02x converted to %02x at line %d, pos %04x\n", tok, program[pos], lineno, pos);
+ program[pos] = op_table[tok];
+
+ if(verbose && tok != program[pos])
+ fprintf(stderr, "op tok \"%s\" ($%02x) converted to $%02x at line %d, pos $%04x\n",
+ get_tok_name(tok, 0), tok, program[pos], lineno, pos);
}
int main(int argc, char **argv) {