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

This commit is contained in:
Luxferre
2022-08-23 21:06:48 +03:00
parent 1ce0c339ca
commit f560cc5cbd
+7 -15
View File
@@ -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 * 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 <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <termios.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; /* terminal I/O helper definitions */
struct termios tty_opts_backup, tty_opts_raw;
void restore_term() {tcsetattr(0, TCSANOW, &tty_opts_backup);} void restore_term() {tcsetattr(0, TCSANOW, &tty_opts_backup);}
int main(int argc, char* argv[]) { /* emulator entry point: nrj program.bin */ int main(int argc, char* argv[]) { /* emulator entry point: nrj program.bin */
if(argc > 1) { 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"); FILE *prog = fopen(argv[1], "rb");
if(prog) { /* load the program and prepare the terminal */ 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); fseek(prog, 0, SEEK_END);
int flen = ftell(prog); int flen = ftell(prog);
fseek(prog, 0, SEEK_SET); 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); cfmakeraw(&tty_opts_raw);
tcsetattr(0, TCSANOW, &tty_opts_raw); tcsetattr(0, TCSANOW, &tty_opts_raw);
nrj_run(mem, 3); /* now, start the engine */ nrj_run(mem, 3); /* now, start the engine */
return 0; /* return the successful status to the outer OS */
} }
else { } /* otherwise bail out with an error */
printf("NRJ%u: could not open the input file %s\r\n", (unsigned int) NRJWSIZE, argv[1]); printf("NRJ%u: no valid program binary specified\r\n", (unsigned int) NRJWSIZE);
return 1; return 1;
}
} else {
printf("NRJ%u: no binary specified\r\n", (unsigned int) NRJWSIZE);
return 1;
}
return 0;
} }