From: David Given Date: Sun, 3 Jun 2018 13:09:01 +0000 (+0200) Subject: Set the terminal to raw nonblocking mode (so we don't need the shell script to X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=9bd0a020a129223a086a50ce799b558c13828273;p=ack.git Set the terminal to raw nonblocking mode (so we don't need the shell script to run the emulator). --- diff --git a/plat/pc86/emu/8086tiny.c b/plat/pc86/emu/8086tiny.c index a0eec055e..20c7c361c 100644 --- a/plat/pc86/emu/8086tiny.c +++ b/plat/pc86/emu/8086tiny.c @@ -5,14 +5,18 @@ // // This work is licensed under the MIT License. See included LICENSE.TXT. +#include +#include +#include #include #include #include -#include #ifndef _WIN32 #include #include +#include +#include #endif #ifndef NO_GRAPHICS @@ -259,9 +263,33 @@ void audio_callback(void *data, unsigned char *stream, int len) } #endif +static struct termios old_terminal_state; + +static void reset_terminal(void) +{ + tcsetattr(0, TCSAFLUSH, &old_terminal_state); +} + +static void set_raw_mode(void) +{ + struct termios state; + tcgetattr(0, &state); + old_terminal_state = state; + + state.c_lflag &= ~(ECHO | ICANON); + state.c_oflag &= ~(OPOST); + state.c_cc[VMIN] = 0; + state.c_cc[VTIME] = 0; + + tcsetattr(0, TCSAFLUSH, &state); + atexit(reset_terminal); +} + // Emulator entry point int main(int argc, char **argv) { + set_raw_mode(); + #ifndef NO_GRAPHICS // Initialise SDL SDL_Init(SDL_INIT_AUDIO);