tis100

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

commit 5adac1252fb065ecb3e308152f6b178b303d6189
parent 7d73b738a5703d5263a84dcbe3564e2267af6804
Author: Louis Burda <quent.burda@gmail.com>
Date:   Wed, 26 Jul 2023 07:34:49 +0200

Fix tpu source rendering and tpu location duplicates

Diffstat:
Masm.c | 4+++-
Mtest/test.asm | 2--
Mtis-curses.c | 18+++++++++++++-----
Mtpu.c | 4+++-
Mtpu.h | 2+-
5 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/asm.c b/asm.c @@ -337,7 +337,9 @@ tis_load(struct tis *tis, const char *filepath) tok_next_in(&tokenizer, TOK_YPOS, -1); tpu->y = atoi(tokenizer.tokstr + 1); tok_next_in(&tokenizer, TOK_NL, -1); - tpu_map_add(&tis->tpu_map, tpu); + if (!tpu_map_add(&tis->tpu_map, tpu)) + die("load: duplicate tpu location X%i Y%i", + tpu->x, tpu->y); break; case TOK_END: if (!tpu) goto disallowed; diff --git a/test/test.asm b/test/test.asm @@ -6,11 +6,9 @@ tpu X1 Y1 end tpu X2 Y1 -LABEL8: mov LEFT, ACC add 1 mov ACC, RIGHT - jmp LABEL8 end tpu X3 Y1 diff --git a/tis-curses.c b/tis-curses.c @@ -173,8 +173,9 @@ tui_draw_tpu(struct tpu *tpu) struct tpu_port *port; int sx, sy, x, y, w, h; int off, start, inst; + size_t len; + attr_t attr; int idle; - attr_t attr;; attr = (tpu_sel == tpu && input_mode == TPU_NAV) ? A_BOLD : 0; @@ -189,14 +190,21 @@ tui_draw_tpu(struct tpu *tpu) inst = start; for (off = 0; off < TPU_INPUT_ROWS && inst < tpu->inst_cnt; ) { if (tpu->label_map.labels[inst]) { - tui_draw_text(sx + 2, sy + 1 + off, A_DIM, - "%s:", tpu->label_map.labels[inst]); + len = strlen(tpu->label_map.labels[inst]); + if (len > TPU_INPUT_COLS - 1) { + tui_draw_text(sx + 2, sy + 1 + off, A_DIM, + "%.*s..:", TPU_INPUT_COLS - 3, + tpu->label_map.labels[inst]); + } else { + tui_draw_text(sx + 2, sy + 1 + off, A_DIM, + "%s:", tpu->label_map.labels[inst]); + } off++; } 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, linebuf); + inst == tpu->pc ? A_STANDOUT : 0, "%-*.*s", + TPU_INPUT_COLS, TPU_INPUT_COLS, linebuf); inst++; off++; } } diff --git a/tpu.c b/tpu.c @@ -580,18 +580,20 @@ tpu_map_link_pos(struct tpu_map *map, int x, int y) return link; } -void +bool tpu_map_add(struct tpu_map *map, struct tpu *tpu) { struct tpu_map_link **pos, *link; pos = tpu_map_link_pos(map, tpu->x, tpu->y); + if (*pos) return false; *pos = link = malloc(sizeof(struct tpu_map_link)); if (!link) die("malloc:"); link->tpu = tpu; link->x = tpu->x; link->y = tpu->y; link->next = NULL; + return true; } struct tpu * diff --git a/tpu.h b/tpu.h @@ -129,7 +129,7 @@ enum tpu_status tpu_step(struct tpu *tpu); void tpu_map_init(struct tpu_map *map); void tpu_map_deinit(struct tpu_map *map); -void tpu_map_add(struct tpu_map *map, struct tpu *tpu); +bool tpu_map_add(struct tpu_map *map, struct tpu *tpu); struct tpu *tpu_map_get(struct tpu_map *map, int x, int y); void tis_init(struct tis *tis);