-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.c~
153 lines (113 loc) · 3.4 KB
/
scan.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
#include "utils.h"
#include <unistd.h>
#include <fcntl.h>
#define MAX_SCANCODES 128
#define MAX_MNEMONICS 16
#define BUFFER_SIZE 128
#define DEBUG 1
static char scancodes_lower[MAX_SCANCODES];
static char scancodes_upper[MAX_SCANCODES];
static char mnemonics[MAX_MNEMONICS][BUFFER_SIZE];
int shift = 0;
int ctrl = 0;
int alt = 0;
int MAX_SCANCODES_C = MAX_SCANCODES;
int SHIFT_DOWN = 200;
int SHIFT_UP = 300;
int CTRL_DOWN = 201;
int CTRL_UP = 301;
int ALT_DOWN = 202;
int ALT_UP = 302;
/*
Deklaracije za nizove i tabele ovde
tabelu za prevodjenje scancodeova i tabelu
za cuvanje mnemonika cuvati kao staticke
varijable unutar ovog fajla i ucitavati
ih uz pomoc funkcije load_config
*/
void load_config(const char *scancodes_filename, const char *mnemonic_filename)
{
load_scancodes(scancodes_filename);
load_mnemonic(mnemonic_filename);
}
int process_scancode(int scancode, char *buffer)
{
if(0){
printstr("Processing scancode ");
char tmp_buff[BUFFER_SIZE];
int len = itoa(scancode,tmp_buff);
printstr(tmp_buff)
newline();
}
int result;
__asm__ __volatile__(
// ===== special codes =====
//check shift down
"cmp (SHIFT_DOWN), %%eax;"
"je SHIFT_DOWN_HANDLE;"
//check shift up
"cmp (SHIFT_UP), %%eax;"
"je SHIFT_UP_HANDLE;"
//check ctrl down
"cmp (CTRL_DOWN), %%eax;"
"je CTRL_DOWN_HANDLE;"
//check ctrl up
"cmp (CTRL_UP), %%eax;"
"je CTRL_UP_HANDLE;"
//check alt down
"cmp (ALT_DOWN), %%eax;"
"je ALT_DOWN_HANDLE;"
//check alt up
"cmp (ALT_UP), %%eax;"
"je ALT_UP_HANDLE;"
// ===== end special codes =====
// ===== standard chars =====
"cmp (MAX_SCANCODES_C), %%eax;"
"jle STANDARD_CHAR_HANDLE;"
// ===== end standard chars =====
"jmp EXIT;"
// ===== handlers =====
// shift down
"SHIFT_DOWN_HANDLE:;"
"movl $1, (shift);"
"jmp EXIT;"
// shift up
"SHIFT_UP_HANDLE:;"
"movl $0, (shift);"
"jmp EXIT;"
// ctrl down
"CTRL_DOWN_HANDLE:;"
"movl $1, (ctrl);"
"jmp EXIT;"
// ctrl up
"CTRL_UP_HANDLE:;"
"movl $0, (ctrl);"
"jmp EXIT;"
// alt down
"ALT_DOWN_HANDLE:;"
"movl $1, (alt);"
"jmp EXIT;"
// alt up
"ALT_UP_HANDLE:;"
"movl $0, (alt);"
"jmp EXIT;"
// standard chars
"STANDARD_CHAR_HANDLE:;"
"leal (scancodes_lower), %%ebx;"
"jmp EXIT;"
// ===== end handlers =====
//done
"EXIT:;"
: "=b" (result)
: "a" (scancode), "b" (buffer)
: "%ecx","memory"
);
/*
Your code goes here!
Remember, only inline assembly.
Good luck!
*/
vardump(strlen(buffer));
printstr("\n");
return result;
}