uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 5e2bb92e4c1f4cd26e0828a3c9738f1f85104f50
parent 06b694d4061f0e7e78ad2efadd0d5b9525936c5b
Author: neauoire <aliceffekt@gmail.com>
Date:   Tue, 11 Jan 2022 15:13:12 -0800

Removed unistd from uxncli

Diffstat:
Msrc/uxncli.c | 84++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 43 insertions(+), 41 deletions(-)

diff --git a/src/uxncli.c b/src/uxncli.c @@ -1,6 +1,5 @@ #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include "uxn.h" @@ -89,8 +88,11 @@ static void run(Uxn *u) { Device *d = &u->dev[0]; - while((!d->dat[0xf]) && (read(0, &d->dat[0x2], 1) > 0)) - uxn_eval(u, GETVECTOR(d)); + while(!d->dat[0xf]) { + int c = fgetc(stdin); + if(c != EOF) + console_input(u, (Uint8)c); + } } static int @@ -106,50 +108,50 @@ load(Uxn *u, char *filepath) return 1; } -int -main(int argc, char **argv) +static int +start(Uxn *u) { - Uxn u; - int i, loaded = 0; - bank0 = (Uint8 *)calloc(0x10000, sizeof(Uint8)); bank1 = (Uint8 *)calloc(0x10000, sizeof(Uint8)); - if(!uxn_boot(&u, bank1, bank0 + PAGE_DEV, (Stack *)(bank0 + PAGE_WST), (Stack *)(bank0 + PAGE_RST))) + if(!uxn_boot(u, bank1, bank0 + PAGE_DEV, (Stack *)(bank0 + PAGE_WST), (Stack *)(bank0 + PAGE_RST))) return error("Boot", "Failed"); + /* system */ uxn_port(u, 0x0, system_dei, system_deo); + /* console */ uxn_port(u, 0x1, nil_dei, console_deo); + /* empty */ uxn_port(u, 0x2, nil_dei, nil_deo); + /* empty */ uxn_port(u, 0x3, nil_dei, nil_deo); + /* empty */ uxn_port(u, 0x4, nil_dei, nil_deo); + /* empty */ uxn_port(u, 0x5, nil_dei, nil_deo); + /* empty */ uxn_port(u, 0x6, nil_dei, nil_deo); + /* empty */ uxn_port(u, 0x7, nil_dei, nil_deo); + /* empty */ uxn_port(u, 0x8, nil_dei, nil_deo); + /* empty */ uxn_port(u, 0x9, nil_dei, nil_deo); + /* file */ uxn_port(u, 0xa, nil_dei, file_deo); + /* datetime */ uxn_port(u, 0xb, datetime_dei, nil_deo); + /* empty */ uxn_port(u, 0xc, nil_dei, nil_deo); + /* empty */ uxn_port(u, 0xd, nil_dei, nil_deo); + /* empty */ uxn_port(u, 0xe, nil_dei, nil_deo); + /* empty */ uxn_port(u, 0xf, nil_dei, nil_deo); + return 1; +} - /* system */ uxn_port(&u, 0x0, system_dei, system_deo); - /* console */ uxn_port(&u, 0x1, nil_dei, console_deo); - /* empty */ uxn_port(&u, 0x2, nil_dei, nil_deo); - /* empty */ uxn_port(&u, 0x3, nil_dei, nil_deo); - /* empty */ uxn_port(&u, 0x4, nil_dei, nil_deo); - /* empty */ uxn_port(&u, 0x5, nil_dei, nil_deo); - /* empty */ uxn_port(&u, 0x6, nil_dei, nil_deo); - /* empty */ uxn_port(&u, 0x7, nil_dei, nil_deo); - /* empty */ uxn_port(&u, 0x8, nil_dei, nil_deo); - /* empty */ uxn_port(&u, 0x9, nil_dei, nil_deo); - /* file */ uxn_port(&u, 0xa, nil_dei, file_deo); - /* datetime */ uxn_port(&u, 0xb, datetime_dei, nil_deo); - /* empty */ uxn_port(&u, 0xc, nil_dei, nil_deo); - /* empty */ uxn_port(&u, 0xd, nil_dei, nil_deo); - /* empty */ uxn_port(&u, 0xe, nil_dei, nil_deo); - /* empty */ uxn_port(&u, 0xf, nil_dei, nil_deo); - - for(i = 1; i < argc; i++) { - if(!loaded++) { - if(!load(&u, argv[i])) - return error("Load", "Failed"); - if(!uxn_eval(&u, PAGE_PROGRAM)) - return error("Init", "Failed"); - } else { - char *p = argv[i]; - while(*p) console_input(&u, *p++); - console_input(&u, '\n'); - } +int +main(int argc, char **argv) +{ + Uxn u; + int i; + if(argc < 2) + return error("Usage", "uxncli game.rom args"); + if(!start(&u)) + return error("Start", "Failed"); + if(!load(&u, argv[1])) + return error("Load", "Failed"); + if(!uxn_eval(&u, PAGE_PROGRAM)) + return error("Init", "Failed"); + for(i = 2; i < argc; i++) { + char *p = argv[i]; + while(*p) console_input(&u, *p++); + console_input(&u, '\n'); } - if(!loaded) - return error("Input", "Missing"); - run(&u); - return 0; }