From 9bd0a020a129223a086a50ce799b558c13828273 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 3 Jun 2018 15:09:01 +0200 Subject: [PATCH] Set the terminal to raw nonblocking mode (so we don't need the shell script to run the emulator). --- plat/pc86/emu/8086tiny.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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); -- 2.34.1