⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console.cc

📁 一个mips虚拟机非常好代码,使用C++来编写的,希望大家多学学,
💻 CC
字号:
#include <unistd.h>#include <fcntl.h>#include <termios.h>#include "module.hh"#include "sulima.hh"#include <signal.h>static char *console_dev;static Console *console;static struct termios orig_termios;static bool restore_termios = false;static const int poll_interval = 0x10000;// Initialize the console subsystem.voidSulima::create_console_subsystem(){    // Link related variables.     define("console", console_dev);}voidSulima::enable_console(CPU *cpu){    struct termios termios;    sigset_t block_ttou;         sigemptyset (&block_ttou);    sigaddset (&block_ttou, SIGTTOU);    if ((console_dev == NULL) || (*console_dev == 0))	return;    console = dynamic_cast<Console *>(find_module(console_dev));    if (!console) {    	throw Error("\"%#s\" is not a Console module.", console_dev);    }        io_fd = STDIN_FILENO;    if (tcgetattr(io_fd, &orig_termios) != -1) {	termios = orig_termios;	termios.c_iflag &= ~(INLCR|ICRNL);	termios.c_lflag &= ~(ICANON|ECHO);	/*block SIGTTOU to enable using tcsetattr() from backgroud processes, RitaShen*/	sigprocmask (SIG_BLOCK, &block_ttou, NULL);	if (tcsetattr(io_fd, TCSANOW, &termios) != -1) 	    restore_termios = true;	/*recover SIGTTOU*/	sigprocmask (SIG_UNBLOCK, &block_ttou, NULL);    }        ioqueue->insert(this);}// Destroy the subsystem.voidSulima::destroy_console_subsystem(){    ioqueue->remove(this);    if (restore_termios)	tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios);}voidSulima::io_poll(){    unsigned char c;    int len;    len = read(io_fd, &c, 1);    if ((len > 0) && (console != NULL))	console->input((int)c);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -