forked from moizumi99/m99_riscv_emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenEmulation.cpp
61 lines (53 loc) · 1.07 KB
/
ScreenEmulation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Created by moiz on 8/29/20.
//
#include <ncurses.h>
#include "ScreenEmulation.h"
ScreenEmulation::ScreenEmulation() {
ScreenInit();
}
ScreenEmulation::~ScreenEmulation() {
ScreenExit();
}
void ScreenEmulation::ScreenInit() {
// ncurse initialization.
initscr();
// Capture key stroke without storing them to buffer.
// cbreak();
raw(); // raw() will make Ctrl-C captured. Test enough before using this.
noecho();
// Capture special keys.
keypad(stdscr, TRUE);
// Allow scrolling.
scrollok(stdscr, TRUE);
// Don't wait for key hit.
nodelay(stdscr, TRUE);
}
void ScreenEmulation::ScreenExit() {
endwin();
}
bool ScreenEmulation::CheckInput() {
if (++counter_ < kThreshold) {
return key_valid_;
} else {
counter_ = 0;
}
if (key_valid_) {
return key_valid_;
}
int c = getch();
if (c == ERR) {
return key_valid_;
}
key_value_ = c;
key_valid_ = true;
return true;
}
int ScreenEmulation::GetKeyValue() {
key_valid_ = false;
return key_value_;
}
void ScreenEmulation::putchar(int c) {
addch(c);
wrefresh(stdscr);
}