#include "asm.h" #include "tpu.h" #include "util.h" #include #include #include #include #include #include #include static struct tis tis; static FILE *tis_stdin = NULL; static FILE *tis_stdout = NULL; int (*cleanup)(void) = NULL; const char *progname = "tis-as"; int main(int argc, const char **argv) { bool idle, prev_idle; int c; if (argc < 2 || argc > 4) { fprintf(stderr, "Usage: tis-as FILE [STDIN] [STDOUT]\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.stdin_port.out = -1; idle = false; while (!idle || !prev_idle || tis.stdin_port.reading && !feof(tis_stdin)) { if (tis.stdin_port.out < 0) { c = getc(tis_stdin); if (c >= 0) tis.stdin_port.out = c; } if (tis.stdout_port.in >= 0) { putc(tis.stdout_port.in, tis_stdout); tis.stdout_port.in = -1; } prev_idle = idle; idle = !tis_step(&tis); } fclose(tis_stdin); fclose(tis_stdout); tis_deinit(&tis); }