diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-07-26 22:15:15 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-07-26 22:15:15 +0200 |
| commit | 33995e119a16fbf13c51cf3a72a6cc52d70a75a8 (patch) | |
| tree | 872cb861564b452468954639851635410d714697 /tis100-curses.c | |
| parent | 0f06ef7127b669207fd8f09b88ecb660b38eb971 (diff) | |
| download | tis100-33995e119a16fbf13c51cf3a72a6cc52d70a75a8.tar.gz tis100-33995e119a16fbf13c51cf3a72a6cc52d70a75a8.zip | |
Add support for multiple input and output ports
Diffstat (limited to 'tis100-curses.c')
| -rw-r--r-- | tis100-curses.c | 83 |
1 files changed, 28 insertions, 55 deletions
diff --git a/tis100-curses.c b/tis100-curses.c index f7f79c2..ff4bafd 100644 --- a/tis100-curses.c +++ b/tis100-curses.c @@ -52,8 +52,6 @@ static int scrw = 80; static int scrh = 40; static struct tis tis; -static FILE *tis_stdin = NULL; -static FILE *tis_stdout = NULL; static int show_reloaded = 0; @@ -62,7 +60,7 @@ static enum input_mode input_mode = MAIN; static struct tpu *tpu_sel = NULL; int (*cleanup)(void) = endwin; -const char *progname = "tis-curses"; +const char *progname = "tis100-curses"; static enum tpu_port_dir key_to_dir(int key) @@ -156,6 +154,16 @@ tui_draw_text(int x, int y, attr_t attr, const char *fmt, ...) } static void +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; + tui_draw_text(x, y, attr, "%.*s", 4, buf); +} + +static void tui_draw_wch(int x, int y, attr_t attr, const cchar_t *c) { attron(attr); @@ -213,12 +221,12 @@ tui_draw_tpu(struct tpu *tpu) 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_text(x + 1 + (tpu->acc >= 0), y + 2, 0, "%03i", tpu->acc); + tui_draw_lit(x + 1, y + 2, 0, 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_text(x + 1 + (tpu->bak >= 0), y + 2, 0, "%03i", tpu->bak); + tui_draw_lit(x + 1, y + 2, 0, 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); @@ -254,8 +262,7 @@ tui_draw_tpu(struct tpu *tpu) if (tpu->ports[DIR_LEFT].attached) { port = &tpu->ports[DIR_LEFT]; if (port->in_set) - tui_draw_text(sx - 3, sy + 6, - A_BOLD, "%03i", port->in); + 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); @@ -263,15 +270,13 @@ tui_draw_tpu(struct tpu *tpu) tui_draw_wch(sx - 1, sy + 8, port->out_set ? A_BOLD : 0, WACS_LARROW); if (port->out_set) - tui_draw_text(sx - 3, sy + 10, - A_BOLD, "%03i", port->out); + 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) - tui_draw_text(sx + TPU_W + 1, sy + 5, - A_BOLD, "%03i", port->out); + tui_draw_lit(sx + TPU_W, sy + 5, A_BOLD, port->out); if (port->type & PORT_OUT) tui_draw_wch(sx + TPU_W + 1, sy + 7, port->out_set ? A_BOLD : 0, WACS_RARROW); @@ -279,15 +284,13 @@ tui_draw_tpu(struct tpu *tpu) tui_draw_wch(sx + TPU_W + 1, sy + 8, port->in_set ? A_BOLD : 0, WACS_LARROW); if (port->in_set) - tui_draw_text(sx + TPU_W + 1, sy + 9, - A_BOLD, "%03i", port->in); + 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) - tui_draw_text(sx + 9, sy - 1, - A_BOLD, "%03i", port->out); + 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); @@ -295,15 +298,13 @@ tui_draw_tpu(struct tpu *tpu) tui_draw_wch(sx + 15, sy - 1, port->in_set ? A_BOLD : 0, WACS_DARROW); if (port->in_set) - tui_draw_text(sx + 17, sy - 1, - A_BOLD, "%03i", port->in); + 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) - tui_draw_text(sx + 9, sy + TPU_H, - A_BOLD, "%03i", port->in); + 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); @@ -311,8 +312,7 @@ tui_draw_tpu(struct tpu *tpu) tui_draw_wch(sx + 15, sy + TPU_H, port->out_set ? A_BOLD : 0, WACS_DARROW); if (port->out_set) - tui_draw_text(sx + 17, sy + TPU_H, - A_BOLD, "%03i", port->out); + tui_draw_lit(sx + 16, sy + TPU_H, A_BOLD, port->out); } } @@ -405,7 +405,7 @@ handlekey(int key) scrx += 4; break; case 's': - tis_communicate(&tis, tis_stdin, tis_stdout); + tis_communicate(&tis); tis_step(&tis); break; } @@ -441,37 +441,21 @@ first_tpu(void) } static void -reset(int ifd, int argc, char **argv, bool watch) +reset(int ifd, int argc, const char **argv, bool watch) { tis_load(&tis, argv[1]); + tis_load_io(&tis, argv + 2); if (watch) if (inotify_add_watch(ifd, argv[1], IN_MODIFY) < 0) die("inotify_add_watch '%s':", argv[1]); - if (argc >= 3) { - if (tis_stdin) fclose(tis_stdin); - tis_stdin = fopen(argv[2], "r"); - if (!tis_stdin) die("fopen '%s':", argv[2]); - } - - if (argc >= 4) { - if (tis_stdout) fclose(tis_stdout); - tis_stdout = fopen(argv[3], "w+"); - if (!tis_stdout) die("fopen '%s':", argv[3]); - } - - if (tis.stdin_port.attached) { - tpu_sel = tis.stdin_port.dst_tpu; - } else { - tpu_sel = first_tpu(); - } + tpu_sel = first_tpu(); tui_seek(NULL, MID, MID); - } int -main(int argc, char **argv) +main(int argc, const char **argv) { struct inotify_event event; ssize_t len; @@ -479,8 +463,8 @@ main(int argc, char **argv) int key; int ifd; - if (argc < 2 || argc > 4) { - fprintf(stderr, "Usage: tis-curses FILE [STDIN] [STDOUT]\n"); + if (argc < 2) { + fprintf(stderr, "Usage: tis100-curses FILE [IO..]\n"); exit(1); } @@ -525,14 +509,6 @@ main(int argc, char **argv) case 'h': tui_seek(NULL, MID, MID); break; - case 'i': - if (tis.stdin_port.attached) - tui_seek(tis.stdin_port.dst_tpu, MID, MID); - break; - case 'o': - if (tis.stdout_port.attached) - tui_seek(tis.stdout_port.dst_tpu, MID, MID); - break; case 'r': reset(ifd, argc, argv, false); break; @@ -549,8 +525,5 @@ main(int argc, char **argv) close(ifd); - if (tis_stdin) fclose(tis_stdin); - if (tis_stdout) fclose(tis_stdout); - endwin(); } |
