diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-12-25 01:46:55 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-12-25 01:46:55 +0100 |
| commit | 5ff5bb25cc864e7fa06aa8fed0c4ec92e99f103a (patch) | |
| tree | 646a3a56d5e9d831e81d64c48a2e39e594cf0685 /asm.c | |
| parent | 70d48f0db2ff618436df7c8c52ead5a0701fd7ab (diff) | |
| download | tis100-5ff5bb25cc864e7fa06aa8fed0c4ec92e99f103a.tar.gz tis100-5ff5bb25cc864e7fa06aa8fed0c4ec92e99f103a.zip | |
Make mode/state behaviour compatible with game
Diffstat (limited to 'asm.c')
| -rw-r--r-- | asm.c | 40 |
1 files changed, 29 insertions, 11 deletions
@@ -250,6 +250,7 @@ tok_next(struct asm_tokenizer *tok) } else if (asm_is_lit(s)) { return TOK_LIT; } else if (*s == '#') { + tok->tokstr = tok->linebuf + tok->off; tok->off += strlen(tok->linebuf + tok->off); return TOK_COMMENT; } else if (len && strchr(TEXTALPH, *s) @@ -321,7 +322,7 @@ tpu_validate(struct tpu *tpu) } void -tis_load(struct tis *tis, const char *filepath) +tis_load_asm(struct tis *tis, const char *filepath) { struct tpu_io_port *io_port; struct asm_tokenizer tokenizer; @@ -338,9 +339,6 @@ tis_load(struct tis *tis, const char *filepath) size_t len; char c; - tis_deinit(tis); - tis_init(tis); - tokenizer.filepath = filepath; tokenizer.file = fopen(filepath, "r"); if (!tokenizer.file) die("load: fopen '%s':", filepath); @@ -452,6 +450,8 @@ tis_load(struct tis *tis, const char *filepath) tokenizer.lineno-1); break; case TOK_COMMENT: + if (tpu && !strcmp(tokenizer.tokstr, "DISABLED")) + tpu->disabled = true; tok_next_in(&tokenizer, TOK_NL, -1); break; case TOK_LABEL: @@ -459,7 +459,7 @@ tis_load(struct tis *tis, const char *filepath) die("load: line %lu, label too long", tokenizer.lineno); if (!label_map_add(&tpu->label_map, - tokenizer.tokstr, tpu->inst_cnt)) + tokenizer.tokstr, (int) tpu->inst_cnt)) die("load: line %lu, duplicate label (pos)", tokenizer.lineno); tpu->label_cnt += 1; @@ -491,11 +491,9 @@ tis_load(struct tis *tis, const char *filepath) dir_reprs[io_port->dir]); } port->attached = true; - port->dst_tpu = NULL; port->dst_port = &io_port->port; port->type = io_port->type; io_port->port.attached = true; - io_port->port.dst_tpu = link->tpu; io_port->port.dst_port = port; } } @@ -525,13 +523,35 @@ disallowed: } void -tis_load_io(struct tis *tis, const char **argv) +tis_load(struct tis *tis, const char **argv) { const char **arg; int n, i; char c; - for (arg = argv; *arg; arg++) { + if (!*argv) die("missing argv[0]"); + + for (arg = argv + 1; *arg; arg++) { + if (!strcmp(*arg, "-h") || !strcmp(*arg, "--help")) { + fprintf(stderr, "Usage: %s [-h] [-s] " + "[--in.X IN].. [--out.X OUT].. ASM\n", argv[0]); + } else if (!strcmp(*arg, "-s") || !strcmp(*arg, "--stats")) { + tis->show_stats = true; + } else if (sscanf(*arg, "--in.%c%n", &c, &n) == 1 && n == 6) { + /* after tis_load_asm.. */ + arg++; + } else if (sscanf(*arg, "--out.%c%n", &c, &n) == 1 && n == 7) { + /* after tis_load_asm.. */ + arg++; + } else { + if (tis->asm_init) + die("multiple asm files"); + tis_load_asm(tis, *arg); + tis->asm_init = true; + } + } + + for (arg = argv + 1; *arg; arg++) { if (sscanf(*arg, "--in.%c%n", &c, &n) == 1 && n == 6) { i = asm_port_char_to_index(c); if (!tis->in_ports[i]) @@ -548,8 +568,6 @@ tis_load_io(struct tis *tis, const char **argv) if (!tis->out_ports[i]->file) die("fopen '%s':", *arg); setvbuf(tis->out_ports[i]->file, NULL, _IONBF, 0); - } else { - die("parse: unknown cmdline option '%s'", *arg); } } } |
