tis100

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

commit c06c696a20fa8987bbb13da608153ccfc3cd55e7
parent 238ac5ab6c47bfe0c9cda1490f97f2d7f5d3eaf6
Author: Louis Burda <quent.burda@gmail.com>
Date:   Wed, 27 Dec 2023 13:42:10 +0100

Fixup idle calculation

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

diff --git a/tis100-curses.c b/tis100-curses.c @@ -213,7 +213,7 @@ tui_draw_tpu(struct tpu *tpu) } tui_draw_text(sx + 1 + offx, sy + 1 + offy, inst == tpu->pc ? A_STANDOUT | (tpu->idle ? A_DIM : 0) : 0, - "%-*.*s", TPU_MAX_COLS, TPU_MAX_COLS, rowbuf); + "%-*.*s", TPU_MAX_COLS - offx, TPU_MAX_COLS, rowbuf); inst += 1; offy += 1; offx = 0; diff --git a/tpu.c b/tpu.c @@ -770,7 +770,6 @@ tis_gen_stats(struct tis *tis) 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; @@ -784,7 +783,12 @@ tis_gen_stats(struct tis *tis) } } - stats.idle = (float) idle_steps / (float) all_steps; + if (!stats.steps) stats.steps = all_steps; + + if (all_steps == 0) + stats.idle = 0; + else + stats.idle = (float) idle_steps / (float) all_steps; return stats; }