commit 1b0379fbac944362053b74349c9d4518091b4492
parent cb4c12bfe94dcade7a058078986d43e0f441ee8d
Author: Luxferre <lux@ferre>
Date: Fri, 12 Aug 2022 12:52:45 +0300
implemented silent mode with s command line parameter
Diffstat:
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
@@ -135,7 +135,9 @@ See [FizzBuzz](examples/fizzbuzz.equi) for a more thorough example of how differ
Being a purely PC-oriented low-level runtime/programming environment, Equi has the reference implementation emulator/VM written in C (ANSI C89 standard), `equi.c`, compilable and runnable on all the systems supporting standard I/O. Note that, for portability reasons, this emulator:
+- accepts the programs from standard input only,
- only implements three ports for `P` instruction: 0 as an echo port (returns passed parameters as corresponding result values), 1 as a random port (returns two random values in the results in the range between the two parameter values) and 2 as a CRC16 calculation port for a given memory location and its length, for any other port value it outputs its parameters to the standard error stream and puts three 0x0000 values back onto the stack,
+- implements `s` command line parameter that runs the emulator in the silent mode without printing any welcome banners or interactive prompts,
- doesn't implement non-blocking key input (the `,` instruction is identical to blocking key input instruction `?`),
- sandboxes the `{` and `}` operations using the file with the name you supply on the compile time to the `PERSIST_FILE` constant. The file must already be created and accessible. If it doesn't exist, these operations will effectively do nothing except putting 0x0000 (success status) onto the stack.
diff --git a/equi.c b/equi.c
@@ -578,9 +578,11 @@ void equi_main_loop() {
/* Equi VM entry point */
int main(int argc, char* argv[]) {
- uchar instr, bc, mmode = 0;
+ uchar instr, bc, mmode = 0, smode = 0;
if(argc > 1 && argv[1][0] == 'm') /* enter minification mode, don't run the programs */
mmode = 1;
+ else if(argc > 1 && argv[1][0] == 's') /* enter silent mode, don't print the banners and prompts */
+ smode = 1;
/* _attempt_ to disable buffering for char input/output */
#if !defined __CC65__ && !defined __TINYC__
setvbuf(stdin, NULL, _IONBF, 0);
@@ -596,7 +598,7 @@ int main(int argc, char* argv[]) {
/* Start both execution and input buffering from the start of command buffer (-1 because we use prefix increment) */
ram.pc = ram.ibp = 65535U;
- if(!mmode) { /* skip the terminal init and the greeting if in minification mode */
+ if(!mmode && !smode) { /* skip the terminal init and the greeting if in minification or silent mode */
/* CC65-specific terminal init */
#ifdef __CC65__
clrscr();
@@ -638,15 +640,19 @@ int main(int argc, char* argv[]) {
break; /* and exit the command mode immediately */
} else {
/* if not in II or minification mode, process EOF or Q instruction: trigger interpreter loop */
- cputc(CR); /* echo CR */
- cputc(LF); /* echo LF */
+ if(!smode) {
+ cputc(CR); /* echo CR */
+ cputc(LF); /* echo LF */
+ }
ram.cmdbuf[++ram.ibp] = INS_QUIT; /* end program with INS_QUIT */
ram.IM = 1; /* set the mandatory interpretation mode flag */
equi_main_loop(); /* and run the interpreter loop */
- cputc(CR); /* echo CR */
- cputc(LF); /* echo LF */
- cputc('>');
- cputc(' ');
+ if(!smode) {
+ cputc(CR); /* echo CR */
+ cputc(LF); /* echo LF */
+ cputc('>');
+ cputc(' ');
+ }
}
} else { /* append the instruction/character to the command buffer if and only if it doesn't match the above criteria and we're not in II mode */
if(!ram.II)