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.c | |
| parent | 0f06ef7127b669207fd8f09b88ecb660b38eb971 (diff) | |
| download | tis100-33995e119a16fbf13c51cf3a72a6cc52d70a75a8.tar.gz tis100-33995e119a16fbf13c51cf3a72a6cc52d70a75a8.zip | |
Add support for multiple input and output ports
Diffstat (limited to 'tis100.c')
| -rw-r--r-- | tis100.c | 51 |
1 files changed, 22 insertions, 29 deletions
@@ -11,55 +11,48 @@ #include <stdlib.h> static struct tis tis; -static FILE *tis_stdin = NULL; -static FILE *tis_stdout = NULL; int (*cleanup)(void) = NULL; -const char *progname = "tis-as"; +const char *progname = "tis100"; + +static bool +io_active(struct tis *tis) +{ + struct tpu_io_port *io_port; + int i; + + for (i = 0; i < TIS_MAX_IO_PORTS; i++) { + io_port = tis->in_ports[i]; + if (!io_port || !io_port->file) continue; + if (!feof(io_port->file) && io_port->port.attached + && io_port->port.dst_port->reading) + return true; + } + return false; +} int main(int argc, const char **argv) { bool idle, prev_idle; - if (argc < 2 || argc > 4) { - fprintf(stderr, "Usage: tis-as FILE [STDIN] [STDOUT]\n"); + if (argc < 2) { + fprintf(stderr, "Usage: tis100 FILE [IO..]\n"); exit(1); } - if (argc >= 3) { - tis_stdin = fopen(argv[2], "r"); - if (!tis_stdin) die("fopen '%s':", argv[2]); - } else { - tis_stdin = stdin; - } - setvbuf(tis_stdin, NULL, _IONBF, 0); - - if (argc >= 4) { - tis_stdout = fopen(argv[3], "w+"); - if (!tis_stdout) die("fopen '%s':", argv[3]); - } else { - tis_stdout = stdout; - } - setvbuf(tis_stdout, NULL, _IONBF, 0); - tis_init(&tis); tis_load(&tis, argv[1]); + tis_load_io(&tis, argv + 2); - tis.stdin_port.out = -1; idle = false; - while (!idle || !prev_idle || tis.stdin_port.attached - && tis.stdin_port.reading && !feof(tis_stdin)) { - tis_communicate(&tis, tis_stdin, tis_stdout); - + while (!idle || !prev_idle || io_active(&tis)) { + tis_communicate(&tis); prev_idle = idle; idle = !tis_step(&tis); } - fclose(tis_stdin); - fclose(tis_stdout); - tis_deinit(&tis); } |
