diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-07-26 17:59:43 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-07-26 17:59:43 +0200 |
| commit | ed666b4fd98ad168f735b814cf74e77ef5c52794 (patch) | |
| tree | 1a9e0f4920060f193d5add588503253a2635a19a /tis100.c | |
| parent | ce2b644f251d5b22dc2228a0ffc8479408c49c38 (diff) | |
| download | tis100-ed666b4fd98ad168f735b814cf74e77ef5c52794.tar.gz tis100-ed666b4fd98ad168f735b814cf74e77ef5c52794.zip | |
Fork tis256 to create version like game
Diffstat (limited to 'tis100.c')
| -rw-r--r-- | tis100.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tis100.c b/tis100.c new file mode 100644 index 0000000..1a14a64 --- /dev/null +++ b/tis100.c @@ -0,0 +1,74 @@ +#include "asm.h" +#include "tpu.h" +#include "util.h" + +#include <signal.h> +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include <stdint.h> +#include <stdbool.h> +#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"; + +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.attached + && tis.stdin_port.reading && !feof(tis_stdin)) { + if (tis.stdin_port.attached && tis.stdin_port.out < 0) { + c = getc(tis_stdin); + if (c >= 0) tis.stdin_port.out = c; + } + + if (tis.stdout_port.attached && 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); +} + |
