-
Notifications
You must be signed in to change notification settings - Fork 1
/
console_input.c
153 lines (149 loc) · 5.13 KB
/
console_input.c
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// *** WARNING ***
// This file is generated by genconsole.rb
// Keep untouched or ruin the abstraction
#include <curses.h>
#include "console_internal.h"
#include "console_input.h"
void console_handle_input(console_ref self, int ch)
{
switch (self->mode) {
case CONSOLE_MODE_COMMAND:
switch (ch) {
// commit command: \n
case '\n':
console_command_commit(self);
break;
// back to normal mode: <ESC>
case 27:
console_command_backto_normal_mode(self);
break;
default:
console_command_command_edit(self, ch);
break;
}
break;
case CONSOLE_MODE_NORMAL:
switch (ch) {
// focus current PC:
case ' ':
console_command_cursor_reset(self, self->pc_phys, -self->middle_y);
console_command_cursor_set(self, self->middle_y);
break;
// set breakpoint on current cursor position: b
case 'b':
console_command_break_on_cursor(self);
break;
// quit the app: q
case 'q':
console_command_quit(self);
break;
// go to end: G
case 'G':
console_command_cursor_reset(self, 0, -self->view_height);
console_command_cursor_set(self, self->view_height - 1);
break;
// scroll page up: <CTRL> + u
case 0x1f & 'u':
console_command_cursor_scroll(self, -self->view_height / 2);
break;
// scroll page down: <CTRL> + d
case 0x1f & 'd':
console_command_cursor_scroll(self, self->view_height / 2);
break;
// scroll down: <CTRL> + e
case 0x1f & 'e':
console_command_cursor_scroll(self, 1);
break;
// scroll up: <CTRL> + y
case 0x1f & 'y':
console_command_cursor_scroll(self, -1);
break;
// cursor move down: j, '\n'
case 'j': // Fallthrough
case '\n': // Fallthrough
console_command_cursor_offset(self, 1);
break;
// cursor move up: k, '-'
case 'k': // Fallthrough
case '-': // Fallthrough
console_command_cursor_offset(self, -1);
break;
// memory scroll down: <KEY_DOWN>
case KEY_DOWN:
console_command_ram_offset(self, 1);
break;
// memory scroll up: <KEY_UP>
case KEY_UP:
console_command_ram_offset(self, -1);
break;
// memory page down: <KEY_NPAGE>
case KEY_NPAGE:
console_command_ram_offset(self, 16);
break;
// memory page up: <KEY_PPAGE>
case KEY_PPAGE:
console_command_ram_offset(self, -16);
break;
// memory reset offset: <KEY_HOME>, <KEY_END>
case KEY_HOME: // Fallthrough
case KEY_END: // Fallthrough
console_command_ram_set(self, 0);
break;
// step to next frame: +
case '+':
console_command_step_frame(self);
break;
// step to next scanline: >
case '>':
console_command_step_scanline(self);
break;
// step instruction: .
case '.':
console_command_step_instruction(self);
break;
// pause execution: p
case 'p':
console_command_pause(self);
break;
// enter jump mode: $, <NUM>, g
case '$': // Fallthrough
case '0': // Fallthrough
case '1': // Fallthrough
case '2': // Fallthrough
case '3': // Fallthrough
case '4': // Fallthrough
case '5': // Fallthrough
case '6': // Fallthrough
case '7': // Fallthrough
case '8': // Fallthrough
case '9': // Fallthrough
case 'g': // Fallthrough
console_command_enter_jump_mode(self, ch);
break;
// enter command mode: :
case ':':
console_command_enter_command_mode(self);
break;
}
break;
case CONSOLE_MODE_JUMP:
switch (ch) {
// offset jump: \n
case '\n':
console_command_jump_offset(self);
break;
// return to normal mode: <ESC>
case 27:
console_command_backto_normal_mode(self);
break;
// commit jump command: g
case 'g':
console_command_jump_commit(self);
break;
default:
console_command_jump_edit(self, ch);
break;
}
break;
}
}