tis100

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

commit 8ec5b039472f9fbe24f2eb1c5d8e66a7551a33fd
parent ee7820e1cfde69c16130a43c8b7e7df1724afb9e
Author: Louis Burda <quent.burda@gmail.com>
Date:   Mon, 25 Dec 2023 04:13:41 +0100

Fixup more behaviour - add dim idle indicator

Diffstat:
Mtis100-curses.c | 7+++----
Mtis100.c | 8--------
Mtpu.c | 21+++++++++++----------
3 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/tis100-curses.c b/tis100-curses.c @@ -157,8 +157,7 @@ tui_draw_lit(int x, int y, attr_t attr, int lit) { char buf[6]; - snprintf(buf, 5, "%03i", lit); - if (buf[0] != '-') x += 1; + snprintf(buf, 5, "% 04i", lit); tui_draw_text(x, y, attr, "%.*s", 4, buf); } @@ -213,8 +212,8 @@ tui_draw_tpu(struct tpu *tpu) } asm_print_inst(linebuf, sizeof(linebuf), &tpu->insts[inst]); tui_draw_text(sx + 2, sy + 1 + off, - inst == tpu->pc ? A_STANDOUT : 0, "%-*.*s", - TPU_INPUT_COLS, TPU_INPUT_COLS, linebuf); + inst == tpu->pc ? A_STANDOUT | (tpu->idle ? A_DIM : 0) : 0, + "%-*.*s", TPU_INPUT_COLS, TPU_INPUT_COLS, linebuf); inst++; off++; } } diff --git a/tis100.c b/tis100.c @@ -37,7 +37,6 @@ 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"); @@ -54,13 +53,6 @@ main(int argc, const char **argv) 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) { stats = tis_gen_stats(&tis); printf("=== stats ===\n"); diff --git a/tpu.c b/tpu.c @@ -205,7 +205,7 @@ tpu_init(struct tpu *tpu) tpu->disabled = false; tpu->mode = MODE_IDLE; - tpu->idle = true; + tpu->idle = false; tpu->x = 0; tpu->y = 0; @@ -565,6 +565,7 @@ tpu_step(struct tpu *tpu) if (tpu->pc >= tpu->inst_cnt) tpu->pc = 0; } else { tpu->mode = MODE_IDLE; + tpu->idle = true; } } @@ -672,20 +673,27 @@ tis_step(struct tis *tis) bool running; size_t i; - tis_communicate(tis); - for (i = 0; i < TPU_MAP_BUCKETS; i++) { link = tis->tpu_map.buckets[i]; for (; link; link = link->next) tpu_step(link->tpu); } + tis_communicate(tis); + for (i = 0; i < TPU_MAP_BUCKETS; i++) { link = tis->tpu_map.buckets[i]; for (; link; link = link->next) tpu_update(link->tpu); } + for (i = 0; i < TIS_MAX_IO_PORTS; i++) { + if (tis->in_ports[i]) + tpu_port_update(&tis->in_ports[i]->port); + if (tis->out_ports[i]) + tpu_port_update(&tis->out_ports[i]->port); + } + running = false; for (i = 0; i < TPU_MAP_BUCKETS; i++) { link = tis->tpu_map.buckets[i]; @@ -699,13 +707,6 @@ tis_step(struct tis *tis) } } - for (i = 0; i < TIS_MAX_IO_PORTS; i++) { - if (tis->in_ports[i]) - tpu_port_update(&tis->in_ports[i]->port); - if (tis->out_ports[i]) - tpu_port_update(&tis->out_ports[i]->port); - } - tis->steps += 1; return running;