summaryrefslogtreecommitdiffstats
path: root/tis100-curses.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-12-25 16:49:51 +0100
committerLouis Burda <quent.burda@gmail.com>2023-12-25 16:49:51 +0100
commit238ac5ab6c47bfe0c9cda1490f97f2d7f5d3eaf6 (patch)
tree8bc0450c20060c262743ee986854741531a19f68 /tis100-curses.c
parent8ec5b039472f9fbe24f2eb1c5d8e66a7551a33fd (diff)
downloadtis100-238ac5ab6c47bfe0c9cda1490f97f2d7f5d3eaf6.tar.gz
tis100-238ac5ab6c47bfe0c9cda1490f97f2d7f5d3eaf6.zip
Add support for prefix labels
Diffstat (limited to 'tis100-curses.c')
-rw-r--r--tis100-curses.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/tis100-curses.c b/tis100-curses.c
index 313aa44..c45f367 100644
--- a/tis100-curses.c
+++ b/tis100-curses.c
@@ -18,12 +18,10 @@
#define KEY_ESC 0x1b
#define KEY_CTRL(c) ((c) & ~0x60)
-#define TPU_INPUT_ROWS 15
-#define TPU_INPUT_COLS 19
#define TPU_INFO_W 7
#define TPU_INFO_H 4
-#define TPU_W (1 + TPU_INPUT_COLS + TPU_INFO_W)
-#define TPU_H (1 + TPU_INPUT_ROWS + 1)
+#define TPU_W (1 + TPU_MAX_COLS + TPU_INFO_W)
+#define TPU_H (1 + TPU_MAX_ROWS + 1)
#define TIMEOUT 50
@@ -172,10 +170,11 @@ tui_draw_wch(int x, int y, attr_t attr, const cchar_t *c)
static void
tui_draw_tpu(struct tpu *tpu)
{
- char linebuf[TPU_INPUT_COLS + 1];
+ char rowbuf[TPU_MAX_COLS + 1];
struct tpu_port *port;
int sx, sy, x, y, w, h;
- int off, start, inst;
+ int offx, offy, start, inst;
+ struct label *label;
size_t len;
attr_t attr;
int idle;
@@ -195,26 +194,29 @@ tui_draw_tpu(struct tpu *tpu)
tui_draw_text(sx + 4, sy + 1 + 4, attr | A_BOLD, " FAILURE ");
tui_draw_text(sx + 4, sy + 1 + 6, attr | A_REVERSE, " ");
} else if (tpu->inst_cnt > 0) {
- start = MAX(0, MIN(tpu->pc - 4, (int) tpu->inst_cnt - TPU_INPUT_ROWS));
+ start = MAX(0, MIN(tpu->pc - 4, (int) tpu->inst_cnt - TPU_MAX_ROWS));
inst = start;
- for (off = 0; off < TPU_INPUT_ROWS && inst < tpu->inst_cnt; ) {
- if (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]);
+ for (offy = 0; offy < TPU_MAX_ROWS && inst < tpu->inst_cnt; ) {
+ asm_print_inst(rowbuf, sizeof(rowbuf), &tpu->insts[inst]);
+ label = &tpu->label_map.labels[inst];
+ if (label->str) {
+ len = strlen(label->str);
+ tui_draw_text(sx + 1 + offx, sy + 1 + offy,
+ A_DIM, "%s:", label->str);
+ if (label->prefix) {
+ offx += (int) strlen(label->str) + 1;
+ if (offx + 1 + (int) strlen(rowbuf) <= TPU_MAX_COLS)
+ offx += 1;
} else {
- tui_draw_text(sx + 2, sy + 1 + off, A_DIM,
- "%s:", tpu->label_map.labels[inst]);
+ offy += 1;
}
- off++;
}
- asm_print_inst(linebuf, sizeof(linebuf), &tpu->insts[inst]);
- tui_draw_text(sx + 2, sy + 1 + off,
+ tui_draw_text(sx + 1 + offx, sy + 1 + offy,
inst == tpu->pc ? A_STANDOUT | (tpu->idle ? A_DIM : 0) : 0,
- "%-*.*s", TPU_INPUT_COLS, TPU_INPUT_COLS, linebuf);
- inst++; off++;
+ "%-*.*s", TPU_MAX_COLS, TPU_MAX_COLS, rowbuf);
+ inst += 1;
+ offy += 1;
+ offx = 0;
}
}