tis100

Reimplementation of Zachtronics TIS-100 as a TUI game
git clone https://git.sinitax.com/sinitax/tis100
Log | Files | Refs | sfeed.txt

commit ee7820e1cfde69c16130a43c8b7e7df1724afb9e
parent ae4a7b241a033627ed136b2ef66922034cfbeae1
Author: Louis Burda <quent.burda@gmail.com>
Date:   Mon, 25 Dec 2023 03:28:35 +0100

Calculate steps needed by tick of last output event

Diffstat:
Mtis100.c | 7+++++++
Mtpu.c | 19++++++++++++++-----
Mtpu.h | 1+
3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/tis100.c b/tis100.c @@ -37,6 +37,7 @@ main(int argc, const char **argv) { struct tis_stats stats; bool idle, prev_idle; + int i; if (argc < 2) { fprintf(stderr, "Usage: tis100 FILE [IO..]\n"); @@ -52,6 +53,12 @@ main(int argc, const char **argv) prev_idle = idle; idle = !tis_step(&tis); } + + for (i = 0; i < TIS_MAX_IO_PORTS; i++) { + if (tis.out_ports[i] && tis.out_ports[i]->io_step > 0) { + } + } + tis.steps -= 1; /* remove last idle step */ if (tis.show_stats) { diff --git a/tpu.c b/tpu.c @@ -181,6 +181,7 @@ tpu_io_port_init(struct tpu_io_port *io_port, char c, enum tpu_port_dir dir, enum tpu_port_type type, int x, int y) { tpu_port_init(&io_port->port, NULL); + io_port->io_step = 0; io_port->type = type; io_port->file = NULL; io_port->dir = dir; @@ -673,7 +674,6 @@ tis_step(struct tis *tis) tis_communicate(tis); - running = false; for (i = 0; i < TPU_MAP_BUCKETS; i++) { link = tis->tpu_map.buckets[i]; for (; link; link = link->next) @@ -682,15 +682,15 @@ tis_step(struct tis *tis) for (i = 0; i < TPU_MAP_BUCKETS; i++) { link = tis->tpu_map.buckets[i]; - for (; link; link = link->next) { + for (; link; link = link->next) tpu_update(link->tpu); - running |= !link->tpu->idle; - } } + running = false; for (i = 0; i < TPU_MAP_BUCKETS; i++) { link = tis->tpu_map.buckets[i]; for (; link; link = link->next) { + running |= !link->tpu->idle; if (link->tpu->pc < link->tpu->inst_cnt) { link->tpu->steps += 1; if (link->tpu->idle) @@ -732,6 +732,7 @@ tis_communicate(struct tis *tis) die("communicate: invalid input '%s'", buf); io_port->port.out = val; io_port->port.writing = true; + io_port->io_step = tis->steps; break; } } @@ -745,6 +746,7 @@ tis_communicate(struct tis *tis) fprintf(io_port->file, "%i\n", io_port->port.in); io_port->port.reset_in = true; tpu_port_update(&io_port->port); + io_port->io_step = tis->steps; } } @@ -757,11 +759,18 @@ tis_gen_stats(struct tis *tis) size_t all_steps; int i; - stats.steps = tis->steps; + stats.steps = 0; stats.nodes = 0; stats.insts = 0; stats.idle = 0; + for (i = 0; i < TIS_MAX_IO_PORTS; i++) { + if (tis->out_ports[i] && tis->out_ports[i]->io_step > 0) { + stats.steps = MAX(stats.steps, tis->out_ports[i]->io_step + 1); + } + } + if (!stats.steps) stats.steps = tis->steps; + all_steps = 0; idle_steps = 0; for (i = 0; i < TPU_MAP_BUCKETS; i++) { diff --git a/tpu.h b/tpu.h @@ -115,6 +115,7 @@ struct tpu_io_port { struct tpu_port port; enum tpu_port_dir dir; enum tpu_port_type type; + size_t io_step; FILE *file; int x, y; char c;