nrj-oisc

NOR and Reference Jump OISC platform
git clone git://git.luxferre.top/nrj-oisc.git
Log | Files | Refs | README

commit f560cc5cbdcc96a162049e546be89d90cec5264d
parent 1ce0c339caac58fabba11b8a8e5ff4b7915faf81
Author: Luxferre <lux@ferre>
Date:   Tue, 23 Aug 2022 21:06:48 +0300

Perfection is attained not when there's nothing to add but when there's nothing to take away

Diffstat:
Mnrj.c | 24++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/nrj.c b/nrj.c @@ -1,8 +1,6 @@ -/* - * NRJ (NOR and Reference Jump) OISC ANSI C emulator +/* NRJ (NOR and Reference Jump) OISC ANSI C emulator * Created by Luxferre, 2022, public domain - * Build with: cc -Os -std=c89 -o nrj nrj.c - */ + * Build with: cc -Os -std=c89 -o nrj nrj.c */ #include <stdlib.h> #include <stdio.h> #include <termios.h> @@ -49,15 +47,14 @@ void nrj_run(NRJWORD *mem, NRJWORD pc) { /* Main NRJ engine - just 12 lines of C } } -/* terminal helper definitions */ -struct termios tty_opts_backup, tty_opts_raw; +struct termios tty_opts_backup, tty_opts_raw; /* terminal I/O helper definitions */ void restore_term() {tcsetattr(0, TCSANOW, &tty_opts_backup);} int main(int argc, char* argv[]) { /* emulator entry point: nrj program.bin */ if(argc > 1) { - NRJWORD mem[NRJSIZE]; /* NRJ memory: word 0 - input, 1 - output, 2 - I/O context, 3 - program start */ FILE *prog = fopen(argv[1], "rb"); if(prog) { /* load the program and prepare the terminal */ + NRJWORD mem[NRJSIZE]; /* NRJ memory: word 0 - input, 1 - output, 2 - I/O context, 3 - program start */ fseek(prog, 0, SEEK_END); int flen = ftell(prog); fseek(prog, 0, SEEK_SET); @@ -68,14 +65,9 @@ int main(int argc, char* argv[]) { /* emulator entry point: nrj program.bin */ cfmakeraw(&tty_opts_raw); tcsetattr(0, TCSANOW, &tty_opts_raw); nrj_run(mem, 3); /* now, start the engine */ + return 0; /* return the successful status to the outer OS */ } - else { - printf("NRJ%u: could not open the input file %s\r\n", (unsigned int) NRJWSIZE, argv[1]); - return 1; - } - } else { - printf("NRJ%u: no binary specified\r\n", (unsigned int) NRJWSIZE); - return 1; - } - return 0; + } /* otherwise bail out with an error */ + printf("NRJ%u: no valid program binary specified\r\n", (unsigned int) NRJWSIZE); + return 1; }