summaryrefslogtreecommitdiffstats
path: root/tis100-curses.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-12-25 01:46:55 +0100
committerLouis Burda <quent.burda@gmail.com>2023-12-25 01:46:55 +0100
commit5ff5bb25cc864e7fa06aa8fed0c4ec92e99f103a (patch)
tree646a3a56d5e9d831e81d64c48a2e39e594cf0685 /tis100-curses.c
parent70d48f0db2ff618436df7c8c52ead5a0701fd7ab (diff)
downloadtis100-5ff5bb25cc864e7fa06aa8fed0c4ec92e99f103a.tar.gz
tis100-5ff5bb25cc864e7fa06aa8fed0c4ec92e99f103a.zip
Make mode/state behaviour compatible with game
Diffstat (limited to 'tis100-curses.c')
-rw-r--r--tis100-curses.c88
1 files changed, 49 insertions, 39 deletions
diff --git a/tis100-curses.c b/tis100-curses.c
index 47b077e..2a34a0a 100644
--- a/tis100-curses.c
+++ b/tis100-curses.c
@@ -37,8 +37,8 @@ enum {
};
enum {
- COLOR_HEADING,
- COLOR_VAL
+ THEME_DEFAULT,
+ THEME_DISABLED
};
static const char *mode_repr[] = {
@@ -182,6 +182,7 @@ tui_draw_tpu(struct tpu *tpu)
int idle;
attr = (tpu_sel == tpu && input_mode == TPU_NAV) ? A_BOLD : 0;
+ attr |= tpu->disabled ? COLOR_PAIR(THEME_DISABLED) : COLOR_PAIR(THEME_DEFAULT);
sx = tpu_pos_x(tpu);
sy = tpu_pos_y(tpu);
@@ -189,7 +190,12 @@ tui_draw_tpu(struct tpu *tpu)
WACS_D_ULCORNER, WACS_D_URCORNER,
WACS_D_LLCORNER, WACS_D_LRCORNER);
- if (tpu->inst_cnt > 0) {
+ if (tpu->disabled) {
+ tui_draw_text(sx + 4, sy + 1 + 1, attr | A_REVERSE, " ");
+ tui_draw_text(sx + 4, sy + 1 + 3, attr | A_BOLD, "COMMUNICATION");
+ 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));
inst = start;
for (off = 0; off < TPU_INPUT_ROWS && inst < tpu->inst_cnt; ) {
@@ -219,98 +225,98 @@ tui_draw_tpu(struct tpu *tpu)
h = TPU_INFO_H;
tui_draw_box(x, y, w, h, attr,
WACS_D_TTEE, WACS_D_URCORNER, WACS_D_LTEE, WACS_D_RTEE);
- tui_draw_text(x + 2, y + 1, A_BOLD, "ACC");
- tui_draw_lit(x + 1, y + 2, 0, tpu->acc);
+ tui_draw_text(x + 2, y + 1, attr | A_BOLD, "ACC");
+ tui_draw_lit(x + 1, y + 2, attr, tpu->acc);
tui_draw_box(x, (y += TPU_INFO_H - 1), w, h, attr,
WACS_D_LTEE, WACS_D_RTEE, WACS_D_LTEE, WACS_D_RTEE);
- tui_draw_text(x + 2, y + 1, A_BOLD, "BAK");
- tui_draw_lit(x + 1, y + 2, 0, tpu->bak);
+ tui_draw_text(x + 2, y + 1, attr | A_BOLD, "BAK");
+ tui_draw_lit(x + 1, y + 2, attr, tpu->bak);
tui_draw_box(x, (y += TPU_INFO_H - 1), w, h, attr,
WACS_D_LTEE, WACS_D_RTEE, WACS_D_LTEE, WACS_D_RTEE);
- tui_draw_text(x + 2, y + 1, A_BOLD, "LST");
+ tui_draw_text(x + 2, y + 1, attr | A_BOLD, "LST");
if (tpu->last < 0) {
- tui_draw_text(x + 2, y + 2, 0, "N/A");
+ tui_draw_text(x + 2, y + 2, attr, "N/A");
} else {
- tui_draw_wch(x + 2, y + 2, 0,
+ tui_draw_wch(x + 2, y + 2, attr,
dir_to_arrow((enum tpu_port_dir) tpu->last));
- tui_draw_wch(x + 3, y + 2, 0,
+ tui_draw_wch(x + 3, y + 2, attr,
dir_to_arrow((enum tpu_port_dir) tpu->last));
- tui_draw_wch(x + 4, y + 2, 0,
+ tui_draw_wch(x + 4, y + 2, attr,
dir_to_arrow((enum tpu_port_dir) tpu->last));
}
tui_draw_box(x, (y += TPU_INFO_H - 1), w, h, attr,
WACS_D_LTEE, WACS_D_RTEE, WACS_D_LTEE, WACS_D_RTEE);
- tui_draw_text(x + 2, y + 1, A_BOLD, "MOD");
- tui_draw_text(x + 2, y + 2, 0, "%s", mode_repr[tpu->status]);
+ tui_draw_text(x + 2, y + 1, attr | A_BOLD, "MOD");
+ tui_draw_text(x + 2, y + 2, attr, "%s", mode_repr[tpu->mode]);
tui_draw_box(x, (y += TPU_INFO_H - 1), w, h, attr,
WACS_D_LTEE, WACS_D_RTEE, WACS_D_BTEE, WACS_D_RTEE);
- tui_draw_text(x + 2, y + 1, A_BOLD, "IDL");
+ tui_draw_text(x + 2, y + 1, attr | A_BOLD, "IDL");
if (tpu->steps > 0)
idle = (int) ((double) tpu->idle_steps * 100 / (double) tpu->steps);
else
- idle = 100;
- tui_draw_text(x + 2, y + 2, 0, "%03i", idle);
+ idle = 0;
+ tui_draw_text(x + 2, y + 2, attr, "%03i", idle);
tui_draw_box(x, (y += TPU_INFO_H - 1), w, 2, attr,
WACS_D_LTEE, WACS_D_RTEE, WACS_D_BTEE, WACS_D_LRCORNER);
if (tpu->ports[DIR_LEFT].attached) {
port = &tpu->ports[DIR_LEFT];
- if (port->in_set)
+ if (port->avail)
tui_draw_lit(sx - 4, sy + 6, A_BOLD, port->in);
if (port->type & PORT_IN)
tui_draw_wch(sx - 1, sy + 7,
- port->in_set ? A_BOLD : 0, WACS_RARROW);
+ port->avail ? A_BOLD : 0, WACS_RARROW);
if (port->type & PORT_OUT)
tui_draw_wch(sx - 1, sy + 8,
- port->out_set ? A_BOLD : 0, WACS_LARROW);
- if (port->out_set)
+ port->writing ? A_BOLD : 0, WACS_LARROW);
+ if (port->writing)
tui_draw_lit(sx - 4, sy + 10, A_BOLD, port->out);
}
if (tpu->ports[DIR_RIGHT].attached) {
port = &tpu->ports[DIR_RIGHT];
- if (port->out_set)
+ if (port->writing)
tui_draw_lit(sx + TPU_W, sy + 5, A_BOLD, port->out);
if (port->type & PORT_OUT)
tui_draw_wch(sx + TPU_W, sy + 7,
- port->out_set ? A_BOLD : 0, WACS_RARROW);
+ port->writing ? A_BOLD : 0, WACS_RARROW);
if (port->type & PORT_IN)
tui_draw_wch(sx + TPU_W, sy + 8,
- port->in_set ? A_BOLD : 0, WACS_LARROW);
- if (port->in_set)
+ port->avail ? A_BOLD : 0, WACS_LARROW);
+ if (port->avail)
tui_draw_lit(sx + TPU_W, sy + 9, A_BOLD, port->in);
}
if (tpu->ports[DIR_UP].attached) {
port = &tpu->ports[DIR_UP];
- if (port->out_set)
+ if (port->writing)
tui_draw_lit(sx + 8, sy - 1, A_BOLD, port->out);
if (port->type & PORT_OUT)
tui_draw_wch(sx + 13, sy - 1,
- port->out_set ? A_BOLD : 0, WACS_UARROW);
+ port->writing ? A_BOLD : 0, WACS_UARROW);
if (port->type & PORT_IN)
tui_draw_wch(sx + 15, sy - 1,
- port->in_set ? A_BOLD : 0, WACS_DARROW);
- if (port->in_set)
+ port->avail ? A_BOLD : 0, WACS_DARROW);
+ if (port->avail)
tui_draw_lit(sx + 16, sy - 1, A_BOLD, port->in);
}
if (tpu->ports[DIR_DOWN].attached) {
port = &tpu->ports[DIR_DOWN];
- if (port->in_set)
+ if (port->avail)
tui_draw_lit(sx + 8, sy + TPU_H, A_BOLD, port->in);
if (port->type & PORT_IN)
tui_draw_wch(sx + 13, sy + TPU_H,
- port->in_set ? A_BOLD : 0, WACS_UARROW);
+ port->avail ? A_BOLD : 0, WACS_UARROW);
if (port->type & PORT_OUT)
tui_draw_wch(sx + 15, sy + TPU_H,
- port->out_set ? A_BOLD : 0, WACS_DARROW);
- if (port->out_set)
+ port->writing ? A_BOLD : 0, WACS_DARROW);
+ if (port->writing)
tui_draw_lit(sx + 16, sy + TPU_H, A_BOLD, port->out);
}
}
@@ -404,7 +410,6 @@ handlekey(int key)
scrx += 4;
break;
case 's':
- tis_communicate(&tis);
tis_step(&tis);
break;
}
@@ -418,8 +423,8 @@ handlekey(int key)
case KEY_LEFT:
case KEY_RIGHT:
dir = key_to_dir(key);
- if (tpu_sel && tpu_sel->ports[dir].dst_tpu)
- tpu_sel = tpu_sel->ports[dir].dst_tpu;
+ if (tpu_sel && tpu_sel->ports[dir].dst_port->tpu)
+ tpu_sel = tpu_sel->ports[dir].dst_port->tpu;
tui_seek(tpu_sel, MID, MID);
break;
}
@@ -442,12 +447,14 @@ first_tpu(void)
static void
reset(int ifd, int argc, const char **argv, bool watch)
{
- tis_load(&tis, argv[1]);
- tis_load_io(&tis, argv + 2);
+ tis_deinit(&tis);
+ tis_init(&tis);
+ tis_load(&tis, argv);
- if (watch)
+ if (watch) {
if (inotify_add_watch(ifd, argv[1], IN_MODIFY) < 0)
die("inotify_add_watch '%s':", argv[1]);
+ }
tpu_sel = first_tpu();
}
@@ -474,6 +481,8 @@ main(int argc, const char **argv)
noecho();
keypad(stdscr, TRUE);
start_color();
+ init_pair(THEME_DEFAULT, COLOR_WHITE, COLOR_BLACK);
+ init_pair(THEME_DISABLED, COLOR_RED, COLOR_BLACK);
curs_set(0);
tui_resize();
timeout(TIMEOUT);
@@ -510,6 +519,7 @@ main(int argc, const char **argv)
case 'r':
reset(ifd, argc, argv, false);
break;
+ case 'q':
case KEY_CTRL('c'):
quit = true;
break;