A better terminal handling
This commit is contained in:
@@ -733,14 +733,21 @@ void equi_main_loop() {
|
|||||||
ram.ibp = 65535U;
|
ram.ibp = 65535U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined __CC65__
|
||||||
|
struct termios tty_opts_raw, tty_opts_backup;
|
||||||
|
void restore_term() {
|
||||||
|
/* restore the terminal settings */
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_backup);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Equi VM entry point */
|
/* Equi VM entry point */
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
uchar instr, bc, modec, smode = 0;
|
uchar instr, bc, modec, smode = 0;
|
||||||
FILE *prog = stdin;
|
FILE *prog = stdin;
|
||||||
/* _attempt_ to disable buffering for char input/output */
|
/* _attempt_ to disable buffering for char input/output */
|
||||||
#if !defined __CC65__
|
#if !defined __CC65__
|
||||||
struct termios tty_opts_raw, tty_opts_backup;
|
atexit(&restore_term);
|
||||||
tcgetattr(STDIN_FILENO, &tty_opts_backup);
|
|
||||||
cfmakeraw(&tty_opts_raw);
|
cfmakeraw(&tty_opts_raw);
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw);
|
tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw);
|
||||||
#endif
|
#endif
|
||||||
@@ -764,7 +771,6 @@ int main(int argc, char* argv[]) {
|
|||||||
else if(argv[2][0] == 's') /* enter silent mode, don't print the banners and prompts */
|
else if(argv[2][0] == 's') /* enter silent mode, don't print the banners and prompts */
|
||||||
smode = 1;
|
smode = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start input buffering from the start of command buffer (-1 because we use prefix increment) */
|
/* Start input buffering from the start of command buffer (-1 because we use prefix increment) */
|
||||||
ram.ibp = 65535U;
|
ram.ibp = 65535U;
|
||||||
if(!ram.MM && !smode) { /* skip the terminal init and the greeting if in minification or silent mode */
|
if(!ram.MM && !smode) { /* skip the terminal init and the greeting if in minification or silent mode */
|
||||||
@@ -777,7 +783,6 @@ int main(int argc, char* argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
printf("Welcome to Equi v" EQUI_VER " by Luxferre, 2022" CRLF "System RAM: %d bytes" CRLF "Equi ready" CRLF CRLF "> ", (int) sizeof(ram));
|
printf("Welcome to Equi v" EQUI_VER " by Luxferre, 2022" CRLF "System RAM: %d bytes" CRLF "Equi ready" CRLF CRLF "> ", (int) sizeof(ram));
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1) { /* Now, we're in the command mode loop */
|
while(1) { /* Now, we're in the command mode loop */
|
||||||
instr = fgetc(prog); /* Fetch the next instruction from the keyboard/file */
|
instr = fgetc(prog); /* Fetch the next instruction from the keyboard/file */
|
||||||
if(instr == 0xFFU || instr == 0U || instr == 3U || instr == 4U) /* exit on zero byte or ctrl+C or ctrl+D */
|
if(instr == 0xFFU || instr == 0U || instr == 3U || instr == 4U) /* exit on zero byte or ctrl+C or ctrl+D */
|
||||||
@@ -839,10 +844,6 @@ int main(int argc, char* argv[]) {
|
|||||||
cputc(instr); /* echo it if not in silent mode */
|
cputc(instr); /* echo it if not in silent mode */
|
||||||
}
|
}
|
||||||
} /* command mode loop end */
|
} /* command mode loop end */
|
||||||
#ifndef __CC65__
|
|
||||||
/* restore the terminal settings */
|
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_backup);
|
|
||||||
#endif
|
|
||||||
fclose(prog); /* close the input file */
|
fclose(prog); /* close the input file */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user