Update MentOs code to the latest development version.
This commit is contained in:
+861
-850
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file fdc.c
|
||||
/// @brief Floppy driver controller handling.
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "fdc.h"
|
||||
|
||||
@@ -1,271 +1,275 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file keyboard.c
|
||||
/// @brief Keyboard handling.
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "keyboard.h"
|
||||
#include "isr.h"
|
||||
#include "video.h"
|
||||
#include "stdio.h"
|
||||
#include "keymap.h"
|
||||
#include "bitops.h"
|
||||
|
||||
#include "port_io.h"
|
||||
#include "pic8259.h"
|
||||
#include "keymap.h"
|
||||
#include "sys/bitops.h"
|
||||
#include "video.h"
|
||||
#include "debug.h"
|
||||
#include "ctype.h"
|
||||
#include "isr.h"
|
||||
#include "scheduler.h"
|
||||
|
||||
/// A macro from Ivan to update buffer indexes.
|
||||
#define STEP(x) (((x) == BUFSIZE - 1) ? 0 : (x + 1))
|
||||
#define STEP(x) (((x) == BUFSIZE - 1) ? 0 : ((x) + 1))
|
||||
|
||||
/// Circular Buffer where the pressed keys are stored.
|
||||
static int circular_buffer[BUFSIZE];
|
||||
|
||||
static int32_t circular_buffer[BUFSIZE] = { 0 };
|
||||
/// Index inside the buffer...
|
||||
static long buf_r = 0;
|
||||
|
||||
/// Index inside the buffer...
|
||||
static long buf_w = 0;
|
||||
|
||||
/// Tracks the state of the leds.
|
||||
static uint8_t ledstate = 0;
|
||||
|
||||
/// The shadow option is active.
|
||||
static bool_t shadow = false;
|
||||
|
||||
/// The shadow character.
|
||||
static char shadow_character = 0;
|
||||
|
||||
/// The flags concerning the keyboard.
|
||||
static uint32_t keyboard_flags = 0;
|
||||
static uint32_t kflags = 0;
|
||||
|
||||
/// Flag which identifies the left shift.
|
||||
#define KBD_LEFT_SHIFT 1
|
||||
#define KBD_LEFT_SHIFT (1 << 0) ///< Flag which identifies the left shift.
|
||||
#define KBD_RIGHT_SHIFT (1 << 1) ///< Flag which identifies the right shift.
|
||||
#define KBD_CAPS_LOCK (1 << 2) ///< Flag which identifies the caps lock.
|
||||
#define KBD_NUM_LOCK (1 << 3) ///< Flag which identifies the num lock.
|
||||
#define KBD_SCROLL_LOCK (1 << 4) ///< Flag which identifies the scroll lock.
|
||||
#define KBD_LEFT_CONTROL (1 << 5) ///< Flag which identifies the left control.
|
||||
#define KBD_RIGHT_CONTROL (1 << 6) ///< Flag which identifies the right control.
|
||||
#define KBD_LEFT_ALT (1 << 7) ///< Flag which identifies the left alt.
|
||||
#define KBD_RIGHT_ALT (1 << 8) ///< Flag which identifies the right alt.
|
||||
|
||||
/// Flag which identifies the right shift.
|
||||
#define KBD_RIGHT_SHIFT 2
|
||||
|
||||
/// Flag which identifies the caps lock.
|
||||
#define KBD_CAPS_LOCK 4
|
||||
|
||||
/// Flag which identifies the num lock.
|
||||
#define KBD_NUM_LOCK 8
|
||||
|
||||
/// Flag which identifies the scroll lock.
|
||||
#define KBD_SCROLL_LOCK 16
|
||||
|
||||
/// Flag which identifies the left control.
|
||||
#define KBD_LEFT_CONTROL 32
|
||||
|
||||
/// Flag which identifies the right control.
|
||||
#define KBD_RIGHT_CONTROL 64
|
||||
|
||||
static inline void push_character(char c)
|
||||
static inline void push_character(uint16_t c)
|
||||
{
|
||||
// Update buffer.
|
||||
if (STEP(buf_w) == buf_r) {
|
||||
buf_r = STEP(buf_r);
|
||||
}
|
||||
circular_buffer[buf_w] = c;
|
||||
buf_w = STEP(buf_w);
|
||||
// Update buffer.
|
||||
if (STEP(buf_w) == buf_r) {
|
||||
buf_r = STEP(buf_r);
|
||||
}
|
||||
|
||||
circular_buffer[buf_w] = c;
|
||||
|
||||
buf_w = STEP(buf_w);
|
||||
}
|
||||
|
||||
static inline int read_character()
|
||||
{
|
||||
char c = -1;
|
||||
if (buf_r != buf_w) {
|
||||
c = circular_buffer[buf_r];
|
||||
buf_r = STEP(buf_r);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void keyboard_install()
|
||||
{
|
||||
// Install the IRQ.
|
||||
irq_install_handler(IRQ_KEYBOARD, keyboard_isr, "keyboard");
|
||||
// Enable the IRQ.
|
||||
pic8259_irq_enable(IRQ_KEYBOARD);
|
||||
// Initialize the keymaps.
|
||||
init_keymaps();
|
||||
// Install the IRQ.
|
||||
irq_install_handler(IRQ_KEYBOARD, keyboard_isr, "keyboard");
|
||||
// Enable the IRQ.
|
||||
pic8259_irq_enable(IRQ_KEYBOARD);
|
||||
}
|
||||
|
||||
void keyboard_isr(pt_regs *r)
|
||||
void keyboard_isr(pt_regs *f)
|
||||
{
|
||||
(void)r;
|
||||
(void)f;
|
||||
|
||||
if (!(inportb(0x64) & 1)) {
|
||||
return;
|
||||
}
|
||||
if (!(inportb(0x64U) & 1U)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Take scancode from the port.
|
||||
uint32_t scancode = inportb(0x60);
|
||||
if (scancode == 0xE0) {
|
||||
scancode = (scancode << 8) | inportb(0x60);
|
||||
}
|
||||
// Take scancode from the port.
|
||||
uint32_t scancode = inportb(0x60);
|
||||
if (scancode == 0xE0) {
|
||||
scancode = (scancode << 8U) | inportb(0x60);
|
||||
}
|
||||
|
||||
// If the key has just been released.
|
||||
if (scancode & 0x80) {
|
||||
if (scancode == (KEY_LEFT_SHIFT | CODE_BREAK)) {
|
||||
clear_flag(&keyboard_flags, KBD_LEFT_SHIFT);
|
||||
} else if (scancode == (KEY_RIGHT_SHIFT | CODE_BREAK)) {
|
||||
clear_flag(&keyboard_flags, KBD_RIGHT_SHIFT);
|
||||
} else if (scancode == (KEY_LEFT_CONTROL | CODE_BREAK)) {
|
||||
clear_flag(&keyboard_flags, KBD_LEFT_CONTROL);
|
||||
} else if (scancode == (KEY_RIGHT_CONTROL | CODE_BREAK)) {
|
||||
clear_flag(&keyboard_flags, KBD_RIGHT_CONTROL);
|
||||
}
|
||||
} else {
|
||||
int32_t character = 0;
|
||||
// If the key has just been released.
|
||||
if (scancode & 0x80U) {
|
||||
if (scancode == (KEY_LEFT_SHIFT | CODE_BREAK)) {
|
||||
bitmask_clear_assign(kflags, KBD_LEFT_SHIFT);
|
||||
} else if (scancode == (KEY_RIGHT_SHIFT | CODE_BREAK)) {
|
||||
bitmask_clear_assign(kflags, KBD_RIGHT_SHIFT);
|
||||
} else if (scancode == (KEY_LEFT_CONTROL | CODE_BREAK)) {
|
||||
bitmask_clear_assign(kflags, KBD_LEFT_CONTROL);
|
||||
} else if (scancode == (KEY_RIGHT_CONTROL | CODE_BREAK)) {
|
||||
bitmask_clear_assign(kflags, KBD_RIGHT_CONTROL);
|
||||
} else if (scancode == (KEY_LEFT_ALT | CODE_BREAK)) {
|
||||
bitmask_clear_assign(kflags, KBD_LEFT_ALT);
|
||||
} else if (scancode == (KEY_RIGHT_ALT | CODE_BREAK)) {
|
||||
bitmask_clear_assign(kflags, KBD_RIGHT_ALT);
|
||||
}
|
||||
} else {
|
||||
int32_t character = 0;
|
||||
|
||||
// Parse the key.
|
||||
switch (scancode) {
|
||||
case KEY_LEFT_SHIFT:
|
||||
set_flag(&keyboard_flags, KBD_LEFT_SHIFT);
|
||||
break;
|
||||
case KEY_RIGHT_SHIFT:
|
||||
set_flag(&keyboard_flags, KBD_RIGHT_SHIFT);
|
||||
break;
|
||||
case KEY_LEFT_CONTROL:
|
||||
set_flag(&keyboard_flags, KBD_LEFT_CONTROL);
|
||||
break;
|
||||
case KEY_RIGHT_CONTROL:
|
||||
set_flag(&keyboard_flags, KBD_RIGHT_CONTROL);
|
||||
break;
|
||||
case KEY_CAPS_LOCK:
|
||||
keyboard_flags ^= KBD_CAPS_LOCK;
|
||||
keyboard_update_leds();
|
||||
break;
|
||||
case KEY_NUM_LOCK:
|
||||
keyboard_flags ^= KBD_NUM_LOCK;
|
||||
keyboard_update_leds();
|
||||
break;
|
||||
case KEY_SCROLL_LOCK:
|
||||
keyboard_flags ^= KBD_SCROLL_LOCK;
|
||||
keyboard_update_leds();
|
||||
break;
|
||||
case KEY_PAGE_UP:
|
||||
video_scroll_up();
|
||||
break;
|
||||
case KEY_PAGE_DOWN:
|
||||
video_scroll_down();
|
||||
break;
|
||||
case KEY_ESCAPE:
|
||||
break;
|
||||
case KEY_LEFT_ALT:
|
||||
break;
|
||||
case KEY_RIGHT_ALT:
|
||||
break;
|
||||
case KEY_BACKSPACE:
|
||||
push_character('\b');
|
||||
video_delete_last_character();
|
||||
video_set_cursor_auto();
|
||||
break;
|
||||
case KEY_KP_RETURN:
|
||||
case KEY_ENTER:
|
||||
push_character('\n');
|
||||
video_new_line();
|
||||
video_set_cursor_auto();
|
||||
pic8259_send_eoi(IRQ_KEYBOARD);
|
||||
break;
|
||||
case KEY_UP_ARROW:
|
||||
push_character('\033');
|
||||
push_character('[');
|
||||
push_character(72);
|
||||
break;
|
||||
case KEY_DOWN_ARROW:
|
||||
push_character('\033');
|
||||
push_character('[');
|
||||
push_character(80);
|
||||
break;
|
||||
case KEY_LEFT_ARROW:
|
||||
push_character('\033');
|
||||
push_character('[');
|
||||
push_character(75);
|
||||
break;
|
||||
case KEY_RIGHT_ARROW:
|
||||
push_character('\033');
|
||||
push_character('[');
|
||||
push_character(77);
|
||||
break;
|
||||
default:
|
||||
if (has_flag(keyboard_flags, KBD_NUM_LOCK)) {
|
||||
character = keymap_it.numlock[scancode];
|
||||
}
|
||||
if (character <= 0) {
|
||||
// Apply shift modifier.
|
||||
if (has_flag(keyboard_flags,
|
||||
(KBD_LEFT_SHIFT | KBD_RIGHT_SHIFT))) {
|
||||
character = keymap_it.shift[scancode];
|
||||
} else {
|
||||
character = keymap_it.base[scancode];
|
||||
}
|
||||
}
|
||||
if (character > 0) {
|
||||
// Apply caps lock modifier.
|
||||
if (has_flag(keyboard_flags, KBD_CAPS_LOCK)) {
|
||||
if (character >= 'a' && character <= 'z') {
|
||||
character += 'A' - 'a';
|
||||
} else if (character >= 'A' && character <= 'Z') {
|
||||
character += 'a' - 'A';
|
||||
}
|
||||
}
|
||||
if (!shadow) {
|
||||
video_putc(character);
|
||||
} else if (shadow_character != 0) {
|
||||
video_putc(shadow_character);
|
||||
}
|
||||
// Update buffer.
|
||||
push_character(character);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
pic8259_send_eoi(IRQ_KEYBOARD);
|
||||
// Parse the key.
|
||||
switch (scancode) {
|
||||
case KEY_LEFT_SHIFT:
|
||||
bitmask_set_assign(kflags, KBD_LEFT_SHIFT);
|
||||
break;
|
||||
case KEY_RIGHT_SHIFT:
|
||||
bitmask_set_assign(kflags, KBD_RIGHT_SHIFT);
|
||||
break;
|
||||
case KEY_LEFT_CONTROL:
|
||||
bitmask_set_assign(kflags, KBD_LEFT_CONTROL);
|
||||
break;
|
||||
case KEY_RIGHT_CONTROL:
|
||||
bitmask_set_assign(kflags, KBD_RIGHT_CONTROL);
|
||||
break;
|
||||
case KEY_CAPS_LOCK:
|
||||
bitmask_flip_assign(kflags, KBD_CAPS_LOCK);
|
||||
keyboard_update_leds();
|
||||
break;
|
||||
case KEY_NUM_LOCK:
|
||||
bitmask_flip_assign(kflags, KBD_NUM_LOCK);
|
||||
keyboard_update_leds();
|
||||
break;
|
||||
case KEY_SCROLL_LOCK:
|
||||
bitmask_flip_assign(kflags, KBD_SCROLL_LOCK);
|
||||
keyboard_update_leds();
|
||||
break;
|
||||
case KEY_PAGE_UP:
|
||||
video_shift_one_page_down();
|
||||
break;
|
||||
case KEY_PAGE_DOWN:
|
||||
video_shift_one_page_up();
|
||||
break;
|
||||
case KEY_ESCAPE:
|
||||
break;
|
||||
case KEY_LEFT_ALT:
|
||||
bitmask_set_assign(kflags, KBD_LEFT_ALT);
|
||||
push_character(scancode << 16u);
|
||||
break;
|
||||
case KEY_RIGHT_ALT:
|
||||
bitmask_set_assign(kflags, KBD_RIGHT_ALT);
|
||||
push_character(scancode << 16u);
|
||||
break;
|
||||
case KEY_BACKSPACE:
|
||||
push_character('\b');
|
||||
break;
|
||||
case KEY_DELETE:
|
||||
push_character(127);
|
||||
break;
|
||||
case KEY_KP_RETURN:
|
||||
case KEY_ENTER:
|
||||
push_character('\n');
|
||||
break;
|
||||
case KEY_UP_ARROW:
|
||||
push_character('\033');
|
||||
push_character('[');
|
||||
push_character('A');
|
||||
break;
|
||||
case KEY_DOWN_ARROW:
|
||||
push_character('\033');
|
||||
push_character('[');
|
||||
push_character('B');
|
||||
break;
|
||||
case KEY_RIGHT_ARROW:
|
||||
push_character('\033');
|
||||
push_character('[');
|
||||
push_character('C');
|
||||
break;
|
||||
case KEY_LEFT_ARROW:
|
||||
push_character('\033');
|
||||
push_character('[');
|
||||
push_character('D');
|
||||
break;
|
||||
case KEY_HOME:
|
||||
push_character('\033');
|
||||
push_character('[');
|
||||
push_character('H');
|
||||
break;
|
||||
case KEY_END:
|
||||
push_character('\033');
|
||||
push_character('[');
|
||||
push_character('F');
|
||||
break;
|
||||
default: {
|
||||
// Get the current keymap.
|
||||
const keymap_t *keymap = get_keymap();
|
||||
|
||||
if (bitmask_check(kflags, KBD_NUM_LOCK)) {
|
||||
character = keymap->numlock[scancode];
|
||||
}
|
||||
if ((character <= 0) && bitmask_check(kflags, KBD_RIGHT_ALT) && (bitmask_check(kflags, KBD_LEFT_SHIFT | KBD_RIGHT_SHIFT))) {
|
||||
if (scancode == KEY_LEFT_BRAKET) {
|
||||
character = '{';
|
||||
} else if (scancode == KEY_RIGHT_BRAKET) {
|
||||
character = '}';
|
||||
}
|
||||
}
|
||||
if ((character <= 0) && bitmask_check(kflags, KBD_RIGHT_ALT)) {
|
||||
if (scancode == KEY_LEFT_BRAKET) {
|
||||
character = '[';
|
||||
} else if (scancode == KEY_RIGHT_BRAKET) {
|
||||
character = ']';
|
||||
} else if (scancode == 0x27) {
|
||||
character = '@';
|
||||
} else if (scancode == 0x28) {
|
||||
character = '#';
|
||||
}
|
||||
}
|
||||
if ((character <= 0) && (bitmask_check(kflags, KBD_LEFT_SHIFT | KBD_RIGHT_SHIFT))) {
|
||||
character = keymap->shift[scancode];
|
||||
}
|
||||
if (character <= 0) {
|
||||
character = keymap->base[scancode];
|
||||
}
|
||||
// We have failed to retrieve the character.
|
||||
if (character <= 0) {
|
||||
break;
|
||||
}
|
||||
// Apply caps lock modifier.
|
||||
if (bitmask_check(kflags, KBD_CAPS_LOCK)) {
|
||||
if (character >= 'a' && character <= 'z') {
|
||||
character += 'A' - 'a';
|
||||
} else if (character >= 'A' && character <= 'Z') {
|
||||
character += 'a' - 'A';
|
||||
}
|
||||
}
|
||||
if (bitmask_check(kflags, KBD_LEFT_CONTROL | KBD_RIGHT_CONTROL)) {
|
||||
push_character('\033');
|
||||
push_character('^');
|
||||
character = toupper(character);
|
||||
|
||||
// Qui ci arrivi quando stai tenendo premuto ctrl+<carattere>.
|
||||
// Qui devi scatenare il SIGINT (ctrl+c).
|
||||
|
||||
// signal();
|
||||
}
|
||||
// Update buffer.
|
||||
push_character(character);
|
||||
}
|
||||
}
|
||||
}
|
||||
pic8259_send_eoi(IRQ_KEYBOARD);
|
||||
}
|
||||
|
||||
void keyboard_update_leds()
|
||||
{
|
||||
// Handle scroll_loc & num_loc & caps_loc.
|
||||
(keyboard_flags & KBD_SCROLL_LOCK) ? (ledstate |= 1) : (ledstate ^= 1);
|
||||
(keyboard_flags & KBD_NUM_LOCK) ? (ledstate |= 2) : (ledstate ^= 2);
|
||||
(keyboard_flags & KBD_CAPS_LOCK) ? (ledstate |= 4) : (ledstate ^= 4);
|
||||
// Handle scroll_loc & num_loc & caps_loc.
|
||||
bitmask_check(kflags, KBD_SCROLL_LOCK) ? (ledstate |= 1) : (ledstate ^= 1);
|
||||
bitmask_check(kflags, KBD_NUM_LOCK) ? (ledstate |= 2) : (ledstate ^= 2);
|
||||
bitmask_check(kflags, KBD_CAPS_LOCK) ? (ledstate |= 4) : (ledstate ^= 4);
|
||||
|
||||
// Write on the port.
|
||||
outportb(0x60, 0xED);
|
||||
outportb(0x60, ledstate);
|
||||
// Write on the port.
|
||||
outportb(0x60, 0xED);
|
||||
outportb(0x60, ledstate);
|
||||
}
|
||||
|
||||
void keyboard_enable()
|
||||
{
|
||||
outportb(0x60, 0xF4);
|
||||
outportb(0x60, 0xF4);
|
||||
}
|
||||
|
||||
void keyboard_disable()
|
||||
{
|
||||
outportb(0x60, 0xF5);
|
||||
outportb(0x60, 0xF5);
|
||||
}
|
||||
|
||||
int keyboard_getc(void)
|
||||
int keyboard_getc()
|
||||
{
|
||||
int c = -1;
|
||||
if (buf_r != buf_w) {
|
||||
c = circular_buffer[buf_r];
|
||||
buf_r = STEP(buf_r);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void keyboard_set_shadow(const bool_t value)
|
||||
{
|
||||
shadow = value;
|
||||
if (shadow == false) {
|
||||
shadow_character = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void keyboard_set_shadow_character(const char _shadow_character)
|
||||
{
|
||||
shadow_character = _shadow_character;
|
||||
}
|
||||
|
||||
bool_t keyboard_get_shadow()
|
||||
{
|
||||
return shadow;
|
||||
}
|
||||
|
||||
bool_t keyboard_is_ctrl_pressed()
|
||||
{
|
||||
return (bool_t)(keyboard_flags & (KBD_LEFT_CONTROL));
|
||||
}
|
||||
|
||||
bool_t keyboard_is_shifted()
|
||||
{
|
||||
return (bool_t)(keyboard_flags & (KBD_LEFT_SHIFT | KBD_RIGHT_SHIFT));
|
||||
return read_character();
|
||||
}
|
||||
|
||||
@@ -1,207 +1,284 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file keymap.c
|
||||
/// @brief Keymap for keyboard.
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "keymap.h"
|
||||
#include "string.h"
|
||||
|
||||
const keymap_t keymap_it = {
|
||||
.base = {
|
||||
[0] = -1,
|
||||
[KEY_ESCAPE] = 27,
|
||||
[KEY_ONE] = '1',
|
||||
[KEY_TWO] = '2',
|
||||
[KEY_THREE] = '3',
|
||||
[KEY_FOUR] = '4',
|
||||
[KEY_FIVE] = '5',
|
||||
[KEY_SIX] = '6',
|
||||
[KEY_SEVEN] = '7',
|
||||
[KEY_EIGHT] = '8',
|
||||
[KEY_NINE] = '9',
|
||||
[KEY_ZERO] = '0',
|
||||
[KEY_APOSTROPHE] = '\'',
|
||||
[KEY_I_ACC] = 141,
|
||||
[KEY_BACKSPACE] = '\b',
|
||||
[KEY_TAB] = '\t',
|
||||
[KEY_Q] = 'q',
|
||||
[KEY_W] = 'w',
|
||||
[KEY_E] = 'e',
|
||||
[KEY_R] = 'r',
|
||||
[KEY_T] = 't',
|
||||
[KEY_Y] = 'y',
|
||||
[KEY_U] = 'u',
|
||||
[KEY_I] = 'i',
|
||||
[KEY_O] = 'o',
|
||||
[KEY_P] = 'p',
|
||||
[KEY_LEFT_BRAKET] = 138,
|
||||
[KEY_RIGHT_BRAKET] = '+',
|
||||
[KEY_ENTER] = 13,
|
||||
[KEY_LEFT_CONTROL] = -1,
|
||||
[KEY_A] = 'a',
|
||||
[KEY_S] = 's',
|
||||
[KEY_D] = 'd',
|
||||
[KEY_F] = 'f',
|
||||
[KEY_G] = 'g',
|
||||
[KEY_H] = 'h',
|
||||
[KEY_J] = 'j',
|
||||
[KEY_K] = 'k',
|
||||
[KEY_L] = 'l',
|
||||
[KEY_SEMICOLON] = 149,
|
||||
[KEY_DOUBLE_QUOTES] = 133,
|
||||
[KEY_GRAVE] = '\\',
|
||||
[KEY_LEFT_SHIFT] = -1,
|
||||
[KEY_BACKSLASH] = 151,
|
||||
[KEY_Z] = 'z',
|
||||
[KEY_X] = 'x',
|
||||
[KEY_C] = 'c',
|
||||
[KEY_V] = 'v',
|
||||
[KEY_B] = 'b',
|
||||
[KEY_N] = 'n',
|
||||
[KEY_M] = 'm',
|
||||
[KEY_COMMA] = ',',
|
||||
[KEY_PERIOD] = '.',
|
||||
[KEY_MINUS] = '-',
|
||||
[KEY_RIGHT_SHIFT] = -1,
|
||||
[KEY_KP_MUL] = '*',
|
||||
[KEY_LEFT_ALT] = -1,
|
||||
[KEY_SPACE] = ' ',
|
||||
[KEY_CAPS_LOCK] = -1,
|
||||
[KEY_F1] = -1,
|
||||
[KEY_F2] = -1,
|
||||
[KEY_F3] = -1,
|
||||
[KEY_F4] = -1,
|
||||
[KEY_F5] = -1,
|
||||
[KEY_F6] = -1,
|
||||
[KEY_F7] = -1,
|
||||
[KEY_F8] = -1,
|
||||
[KEY_F9] = -1,
|
||||
[KEY_F10] = -1,
|
||||
[KEY_NUM_LOCK] = -1,
|
||||
[KEY_SCROLL_LOCK] = -1,
|
||||
[KEY_KP7] = -1,
|
||||
[KEY_KP8] = -1,
|
||||
[KEY_KP9] = -1,
|
||||
[KEY_KP_SUB] = '-',
|
||||
[KEY_KP4] = -1,
|
||||
[KEY_KP5] = -1,
|
||||
[KEY_KP6] = -1,
|
||||
[KEY_KP_ADD] = '+',
|
||||
[KEY_KP1] = -1,
|
||||
[KEY_KP2] = -1,
|
||||
[KEY_KP3] = -1,
|
||||
[KEY_KP0] = -1,
|
||||
[KEY_KP_DEC] = -1,
|
||||
[84] = -1,
|
||||
[85] = -1,
|
||||
[KEY_KP_LESS] = '<',
|
||||
[87] = -1,
|
||||
[88] = -1,
|
||||
[KEY_KP_DIV] = '/'
|
||||
},
|
||||
.shift = {
|
||||
[0] = -1,
|
||||
[KEY_ESCAPE] = -1,
|
||||
[KEY_ONE] = '!',
|
||||
[KEY_TWO] = '"',
|
||||
[KEY_THREE] = 156,
|
||||
[KEY_FOUR] = '$',
|
||||
[KEY_FIVE] = '%',
|
||||
[KEY_SIX] = '&',
|
||||
[KEY_SEVEN] = '/',
|
||||
[KEY_EIGHT] = '(',
|
||||
[KEY_NINE] = ')',
|
||||
[KEY_ZERO] = '=',
|
||||
[KEY_APOSTROPHE] = '?',
|
||||
[KEY_I_ACC] = '^',
|
||||
[KEY_BACKSPACE] = -1,
|
||||
[KEY_TAB] = -1,
|
||||
[KEY_Q] = 'Q',
|
||||
[KEY_W] = 'W',
|
||||
[KEY_E] = 'E',
|
||||
[KEY_R] = 'R',
|
||||
[KEY_T] = 'T',
|
||||
[KEY_Y] = 'Y',
|
||||
[KEY_U] = 'U',
|
||||
[KEY_I] = 'I',
|
||||
[KEY_O] = 'O',
|
||||
[KEY_P] = 'P',
|
||||
[KEY_LEFT_BRAKET] = 130,
|
||||
[KEY_RIGHT_BRAKET] = '*',
|
||||
[KEY_ENTER] = -1,
|
||||
[KEY_LEFT_CONTROL] = -1,
|
||||
[KEY_A] = 'A',
|
||||
[KEY_S] = 'S',
|
||||
[KEY_D] = 'D',
|
||||
[KEY_F] = 'F',
|
||||
[KEY_G] = 'G',
|
||||
[KEY_H] = 'H',
|
||||
[KEY_J] = 'J',
|
||||
[KEY_K] = 'K',
|
||||
[KEY_L] = 'L',
|
||||
[KEY_SEMICOLON] = 128,
|
||||
[KEY_DOUBLE_QUOTES] = 167,
|
||||
[KEY_GRAVE] = '|',
|
||||
[KEY_LEFT_SHIFT] = -1,
|
||||
[KEY_BACKSLASH] = -1,
|
||||
[KEY_Z] = 'Z',
|
||||
[KEY_X] = 'X',
|
||||
[KEY_C] = 'C',
|
||||
[KEY_V] = 'V',
|
||||
[KEY_B] = 'B',
|
||||
[KEY_N] = 'N',
|
||||
[KEY_M] = 'M',
|
||||
[KEY_COMMA] = ';',
|
||||
[KEY_PERIOD] = ':',
|
||||
[KEY_MINUS] = '_',
|
||||
[KEY_RIGHT_SHIFT] = -1,
|
||||
[KEY_KP_MUL] = '*',
|
||||
[KEY_LEFT_ALT] = -1,
|
||||
[KEY_SPACE] = ' ',
|
||||
[KEY_CAPS_LOCK] = -1,
|
||||
[KEY_F1] = -1,
|
||||
[KEY_F2] = -1,
|
||||
[KEY_F3] = -1,
|
||||
[KEY_F4] = -1,
|
||||
[KEY_F5] = -1,
|
||||
[KEY_F6] = -1,
|
||||
[KEY_F7] = -1,
|
||||
[KEY_F8] = -1,
|
||||
[KEY_F9] = -1,
|
||||
[KEY_F10] = -1,
|
||||
[KEY_NUM_LOCK] = -1,
|
||||
[KEY_SCROLL_LOCK] = -1,
|
||||
[KEY_KP7] = -1,
|
||||
[KEY_KP8] = -1,
|
||||
[KEY_KP9] = -1,
|
||||
[KEY_KP_SUB] = '-',
|
||||
[KEY_KP4] = -1,
|
||||
[KEY_KP5] = -1,
|
||||
[KEY_KP6] = -1,
|
||||
[KEY_KP_ADD] = '+',
|
||||
[KEY_KP1] = -1,
|
||||
[KEY_KP2] = -1,
|
||||
[KEY_KP3] = -1,
|
||||
[KEY_KP0] = -1,
|
||||
[KEY_KP_DEC] = -1,
|
||||
[84] = -1,
|
||||
[85] = -1,
|
||||
[KEY_KP_LESS] = '>',
|
||||
[87] = -1,
|
||||
[88] = -1,
|
||||
[KEY_KP_DIV] = '/'
|
||||
},
|
||||
.numlock = {
|
||||
[KEY_KP_DEC] = '.',
|
||||
[KEY_KP0] = '0',
|
||||
[KEY_KP1] = '1',
|
||||
[KEY_KP2] = '2',
|
||||
[KEY_KP3] = '3',
|
||||
[KEY_KP4] = '4',
|
||||
[KEY_KP5] = '5',
|
||||
[KEY_KP6] = '6',
|
||||
[KEY_KP7] = '7',
|
||||
[KEY_KP8] = '8',
|
||||
[KEY_KP9] = '9',
|
||||
},
|
||||
};
|
||||
/// Identifies the current keymap type.
|
||||
keymap_type_t keymap_type = KEYMAP_IT;
|
||||
/// Contains the different keymaps.
|
||||
keymap_t keymaps[KEYMAP_TYPE_MAX];
|
||||
|
||||
keymap_type_t get_keymap_type()
|
||||
{
|
||||
return keymap_type;
|
||||
}
|
||||
|
||||
void set_keymap_type(keymap_type_t type)
|
||||
{
|
||||
if (type != keymap_type)
|
||||
keymap_type = type;
|
||||
}
|
||||
|
||||
const keymap_t *get_keymap()
|
||||
{
|
||||
return &keymaps[keymap_type];
|
||||
}
|
||||
|
||||
void init_keymaps()
|
||||
{
|
||||
for (int i = 0; i < KEYMAP_TYPE_MAX; ++i)
|
||||
memset(&keymaps[i], -1, sizeof(keymap_t));
|
||||
|
||||
// == ITALIAN KEY MAPPING =================================================
|
||||
keymaps[KEYMAP_IT].base[KEY_ESCAPE] = 27;
|
||||
keymaps[KEYMAP_IT].base[KEY_ONE] = '1';
|
||||
keymaps[KEYMAP_IT].base[KEY_TWO] = '2';
|
||||
keymaps[KEYMAP_IT].base[KEY_THREE] = '3';
|
||||
keymaps[KEYMAP_IT].base[KEY_FOUR] = '4';
|
||||
keymaps[KEYMAP_IT].base[KEY_FIVE] = '5';
|
||||
keymaps[KEYMAP_IT].base[KEY_SIX] = '6';
|
||||
keymaps[KEYMAP_IT].base[KEY_SEVEN] = '7';
|
||||
keymaps[KEYMAP_IT].base[KEY_EIGHT] = '8';
|
||||
keymaps[KEYMAP_IT].base[KEY_NINE] = '9';
|
||||
keymaps[KEYMAP_IT].base[KEY_ZERO] = '0';
|
||||
keymaps[KEYMAP_IT].base[KEY_APOSTROPHE] = '\'';
|
||||
keymaps[KEYMAP_IT].base[KEY_I_ACC] = 141;
|
||||
keymaps[KEYMAP_IT].base[KEY_BACKSPACE] = '\b';
|
||||
keymaps[KEYMAP_IT].base[KEY_TAB] = '\t';
|
||||
keymaps[KEYMAP_IT].base[KEY_Q] = 'q';
|
||||
keymaps[KEYMAP_IT].base[KEY_W] = 'w';
|
||||
keymaps[KEYMAP_IT].base[KEY_E] = 'e';
|
||||
keymaps[KEYMAP_IT].base[KEY_R] = 'r';
|
||||
keymaps[KEYMAP_IT].base[KEY_T] = 't';
|
||||
keymaps[KEYMAP_IT].base[KEY_Y] = 'y';
|
||||
keymaps[KEYMAP_IT].base[KEY_U] = 'u';
|
||||
keymaps[KEYMAP_IT].base[KEY_I] = 'i';
|
||||
keymaps[KEYMAP_IT].base[KEY_O] = 'o';
|
||||
keymaps[KEYMAP_IT].base[KEY_P] = 'p';
|
||||
keymaps[KEYMAP_IT].base[KEY_LEFT_BRAKET] = 138;
|
||||
keymaps[KEYMAP_IT].base[KEY_RIGHT_BRAKET] = '+';
|
||||
keymaps[KEYMAP_IT].base[KEY_ENTER] = 13;
|
||||
keymaps[KEYMAP_IT].base[KEY_A] = 'a';
|
||||
keymaps[KEYMAP_IT].base[KEY_S] = 's';
|
||||
keymaps[KEYMAP_IT].base[KEY_D] = 'd';
|
||||
keymaps[KEYMAP_IT].base[KEY_F] = 'f';
|
||||
keymaps[KEYMAP_IT].base[KEY_G] = 'g';
|
||||
keymaps[KEYMAP_IT].base[KEY_H] = 'h';
|
||||
keymaps[KEYMAP_IT].base[KEY_J] = 'j';
|
||||
keymaps[KEYMAP_IT].base[KEY_K] = 'k';
|
||||
keymaps[KEYMAP_IT].base[KEY_L] = 'l';
|
||||
keymaps[KEYMAP_IT].base[KEY_SEMICOLON] = 149;
|
||||
keymaps[KEYMAP_IT].base[KEY_DOUBLE_QUOTES] = 133;
|
||||
keymaps[KEYMAP_IT].base[KEY_GRAVE] = '\\';
|
||||
keymaps[KEYMAP_IT].base[KEY_BACKSLASH] = 151;
|
||||
keymaps[KEYMAP_IT].base[KEY_Z] = 'z';
|
||||
keymaps[KEYMAP_IT].base[KEY_X] = 'x';
|
||||
keymaps[KEYMAP_IT].base[KEY_C] = 'c';
|
||||
keymaps[KEYMAP_IT].base[KEY_V] = 'v';
|
||||
keymaps[KEYMAP_IT].base[KEY_B] = 'b';
|
||||
keymaps[KEYMAP_IT].base[KEY_N] = 'n';
|
||||
keymaps[KEYMAP_IT].base[KEY_M] = 'm';
|
||||
keymaps[KEYMAP_IT].base[KEY_COMMA] = ',';
|
||||
keymaps[KEYMAP_IT].base[KEY_PERIOD] = '.';
|
||||
keymaps[KEYMAP_IT].base[KEY_MINUS] = '-';
|
||||
keymaps[KEYMAP_IT].base[KEY_KP_MUL] = '*';
|
||||
keymaps[KEYMAP_IT].base[KEY_SPACE] = ' ';
|
||||
keymaps[KEYMAP_IT].base[KEY_KP_SUB] = '-';
|
||||
keymaps[KEYMAP_IT].base[KEY_KP_ADD] = '+';
|
||||
keymaps[KEYMAP_IT].base[KEY_KP_LESS] = '<';
|
||||
keymaps[KEYMAP_IT].base[KEY_KP_DIV] = '/';
|
||||
|
||||
keymaps[KEYMAP_IT].shift[KEY_ONE] = '!';
|
||||
keymaps[KEYMAP_IT].shift[KEY_TWO] = '"';
|
||||
keymaps[KEYMAP_IT].shift[KEY_THREE] = 156;
|
||||
keymaps[KEYMAP_IT].shift[KEY_FOUR] = '$';
|
||||
keymaps[KEYMAP_IT].shift[KEY_FIVE] = '%';
|
||||
keymaps[KEYMAP_IT].shift[KEY_SIX] = '&';
|
||||
keymaps[KEYMAP_IT].shift[KEY_SEVEN] = '/';
|
||||
keymaps[KEYMAP_IT].shift[KEY_EIGHT] = '(';
|
||||
keymaps[KEYMAP_IT].shift[KEY_NINE] = ')';
|
||||
keymaps[KEYMAP_IT].shift[KEY_ZERO] = '=';
|
||||
keymaps[KEYMAP_IT].shift[KEY_APOSTROPHE] = '?';
|
||||
keymaps[KEYMAP_IT].shift[KEY_I_ACC] = '^';
|
||||
keymaps[KEYMAP_IT].shift[KEY_Q] = 'Q';
|
||||
keymaps[KEYMAP_IT].shift[KEY_W] = 'W';
|
||||
keymaps[KEYMAP_IT].shift[KEY_E] = 'E';
|
||||
keymaps[KEYMAP_IT].shift[KEY_R] = 'R';
|
||||
keymaps[KEYMAP_IT].shift[KEY_T] = 'T';
|
||||
keymaps[KEYMAP_IT].shift[KEY_Y] = 'Y';
|
||||
keymaps[KEYMAP_IT].shift[KEY_U] = 'U';
|
||||
keymaps[KEYMAP_IT].shift[KEY_I] = 'I';
|
||||
keymaps[KEYMAP_IT].shift[KEY_O] = 'O';
|
||||
keymaps[KEYMAP_IT].shift[KEY_P] = 'P';
|
||||
keymaps[KEYMAP_IT].shift[KEY_LEFT_BRAKET] = 130;
|
||||
keymaps[KEYMAP_IT].shift[KEY_RIGHT_BRAKET] = '*';
|
||||
keymaps[KEYMAP_IT].shift[KEY_A] = 'A';
|
||||
keymaps[KEYMAP_IT].shift[KEY_S] = 'S';
|
||||
keymaps[KEYMAP_IT].shift[KEY_D] = 'D';
|
||||
keymaps[KEYMAP_IT].shift[KEY_F] = 'F';
|
||||
keymaps[KEYMAP_IT].shift[KEY_G] = 'G';
|
||||
keymaps[KEYMAP_IT].shift[KEY_H] = 'H';
|
||||
keymaps[KEYMAP_IT].shift[KEY_J] = 'J';
|
||||
keymaps[KEYMAP_IT].shift[KEY_K] = 'K';
|
||||
keymaps[KEYMAP_IT].shift[KEY_L] = 'L';
|
||||
keymaps[KEYMAP_IT].shift[KEY_SEMICOLON] = 128;
|
||||
keymaps[KEYMAP_IT].shift[KEY_DOUBLE_QUOTES] = 167;
|
||||
keymaps[KEYMAP_IT].shift[KEY_GRAVE] = '|';
|
||||
keymaps[KEYMAP_IT].shift[KEY_Z] = 'Z';
|
||||
keymaps[KEYMAP_IT].shift[KEY_X] = 'X';
|
||||
keymaps[KEYMAP_IT].shift[KEY_C] = 'C';
|
||||
keymaps[KEYMAP_IT].shift[KEY_V] = 'V';
|
||||
keymaps[KEYMAP_IT].shift[KEY_B] = 'B';
|
||||
keymaps[KEYMAP_IT].shift[KEY_N] = 'N';
|
||||
keymaps[KEYMAP_IT].shift[KEY_M] = 'M';
|
||||
keymaps[KEYMAP_IT].shift[KEY_COMMA] = ';';
|
||||
keymaps[KEYMAP_IT].shift[KEY_PERIOD] = ':';
|
||||
keymaps[KEYMAP_IT].shift[KEY_MINUS] = '_';
|
||||
keymaps[KEYMAP_IT].shift[KEY_KP_MUL] = '*';
|
||||
keymaps[KEYMAP_IT].shift[KEY_SPACE] = ' ';
|
||||
keymaps[KEYMAP_IT].shift[KEY_KP_SUB] = '-';
|
||||
keymaps[KEYMAP_IT].shift[KEY_KP_ADD] = '+';
|
||||
keymaps[KEYMAP_IT].shift[KEY_KP_LESS] = '>';
|
||||
keymaps[KEYMAP_IT].shift[KEY_KP_DIV] = '/';
|
||||
|
||||
keymaps[KEYMAP_IT].numlock[KEY_KP_DEC] = '.';
|
||||
keymaps[KEYMAP_IT].numlock[KEY_KP0] = '0';
|
||||
keymaps[KEYMAP_IT].numlock[KEY_KP1] = '1';
|
||||
keymaps[KEYMAP_IT].numlock[KEY_KP2] = '2';
|
||||
keymaps[KEYMAP_IT].numlock[KEY_KP3] = '3';
|
||||
keymaps[KEYMAP_IT].numlock[KEY_KP4] = '4';
|
||||
keymaps[KEYMAP_IT].numlock[KEY_KP5] = '5';
|
||||
keymaps[KEYMAP_IT].numlock[KEY_KP6] = '6';
|
||||
keymaps[KEYMAP_IT].numlock[KEY_KP7] = '7';
|
||||
keymaps[KEYMAP_IT].numlock[KEY_KP8] = '8';
|
||||
keymaps[KEYMAP_IT].numlock[KEY_KP9] = '9';
|
||||
|
||||
// == US KEY MAPPING ======================================================
|
||||
|
||||
keymaps[KEYMAP_US].base[KEY_ESCAPE] = 27;
|
||||
keymaps[KEYMAP_US].base[KEY_ONE] = '1';
|
||||
keymaps[KEYMAP_US].base[KEY_TWO] = '2';
|
||||
keymaps[KEYMAP_US].base[KEY_THREE] = '3';
|
||||
keymaps[KEYMAP_US].base[KEY_FOUR] = '4';
|
||||
keymaps[KEYMAP_US].base[KEY_FIVE] = '5';
|
||||
keymaps[KEYMAP_US].base[KEY_SIX] = '6';
|
||||
keymaps[KEYMAP_US].base[KEY_SEVEN] = '7';
|
||||
keymaps[KEYMAP_US].base[KEY_EIGHT] = '8';
|
||||
keymaps[KEYMAP_US].base[KEY_NINE] = '9';
|
||||
keymaps[KEYMAP_US].base[KEY_ZERO] = '0';
|
||||
keymaps[KEYMAP_US].base[KEY_APOSTROPHE] = '-';
|
||||
keymaps[KEYMAP_US].base[KEY_I_ACC] = '=';
|
||||
keymaps[KEYMAP_US].base[KEY_BACKSPACE] = '\b';
|
||||
keymaps[KEYMAP_US].base[KEY_TAB] = '\t';
|
||||
keymaps[KEYMAP_US].base[KEY_Q] = 'q';
|
||||
keymaps[KEYMAP_US].base[KEY_W] = 'w';
|
||||
keymaps[KEYMAP_US].base[KEY_E] = 'e';
|
||||
keymaps[KEYMAP_US].base[KEY_R] = 'r';
|
||||
keymaps[KEYMAP_US].base[KEY_T] = 't';
|
||||
keymaps[KEYMAP_US].base[KEY_Y] = 'y';
|
||||
keymaps[KEYMAP_US].base[KEY_U] = 'u';
|
||||
keymaps[KEYMAP_US].base[KEY_I] = 'i';
|
||||
keymaps[KEYMAP_US].base[KEY_O] = 'o';
|
||||
keymaps[KEYMAP_US].base[KEY_P] = 'p';
|
||||
keymaps[KEYMAP_US].base[KEY_LEFT_BRAKET] = '[';
|
||||
keymaps[KEYMAP_US].base[KEY_RIGHT_BRAKET] = ']';
|
||||
keymaps[KEYMAP_US].base[KEY_ENTER] = 13;
|
||||
keymaps[KEYMAP_US].base[KEY_A] = 'a';
|
||||
keymaps[KEYMAP_US].base[KEY_S] = 's';
|
||||
keymaps[KEYMAP_US].base[KEY_D] = 'd';
|
||||
keymaps[KEYMAP_US].base[KEY_F] = 'f';
|
||||
keymaps[KEYMAP_US].base[KEY_G] = 'g';
|
||||
keymaps[KEYMAP_US].base[KEY_H] = 'h';
|
||||
keymaps[KEYMAP_US].base[KEY_J] = 'j';
|
||||
keymaps[KEYMAP_US].base[KEY_K] = 'k';
|
||||
keymaps[KEYMAP_US].base[KEY_L] = 'l';
|
||||
keymaps[KEYMAP_US].base[KEY_SEMICOLON] = ';';
|
||||
keymaps[KEYMAP_US].base[KEY_DOUBLE_QUOTES] = '\'';
|
||||
keymaps[KEYMAP_US].base[KEY_GRAVE] = '`';
|
||||
keymaps[KEYMAP_US].base[KEY_BACKSLASH] = '\\';
|
||||
keymaps[KEYMAP_US].base[KEY_Z] = 'z';
|
||||
keymaps[KEYMAP_US].base[KEY_X] = 'x';
|
||||
keymaps[KEYMAP_US].base[KEY_C] = 'c';
|
||||
keymaps[KEYMAP_US].base[KEY_V] = 'v';
|
||||
keymaps[KEYMAP_US].base[KEY_B] = 'b';
|
||||
keymaps[KEYMAP_US].base[KEY_N] = 'n';
|
||||
keymaps[KEYMAP_US].base[KEY_M] = 'm';
|
||||
keymaps[KEYMAP_US].base[KEY_COMMA] = ',';
|
||||
keymaps[KEYMAP_US].base[KEY_PERIOD] = '.';
|
||||
keymaps[KEYMAP_US].base[KEY_MINUS] = '/';
|
||||
keymaps[KEYMAP_US].base[KEY_KP_MUL] = '*';
|
||||
keymaps[KEYMAP_US].base[KEY_SPACE] = ' ';
|
||||
keymaps[KEYMAP_US].base[KEY_KP_SUB] = '-';
|
||||
keymaps[KEYMAP_US].base[KEY_KP_ADD] = '+';
|
||||
keymaps[KEYMAP_US].base[KEY_KP_LESS] = '<';
|
||||
keymaps[KEYMAP_US].base[KEY_KP_DIV] = '/';
|
||||
|
||||
keymaps[KEYMAP_US].shift[KEY_ONE] = '!';
|
||||
keymaps[KEYMAP_US].shift[KEY_TWO] = '@';
|
||||
keymaps[KEYMAP_US].shift[KEY_THREE] = '#';
|
||||
keymaps[KEYMAP_US].shift[KEY_FOUR] = '$';
|
||||
keymaps[KEYMAP_US].shift[KEY_FIVE] = '%';
|
||||
keymaps[KEYMAP_US].shift[KEY_SIX] = '^';
|
||||
keymaps[KEYMAP_US].shift[KEY_SEVEN] = '&';
|
||||
keymaps[KEYMAP_US].shift[KEY_EIGHT] = '*';
|
||||
keymaps[KEYMAP_US].shift[KEY_NINE] = '(';
|
||||
keymaps[KEYMAP_US].shift[KEY_ZERO] = ')';
|
||||
keymaps[KEYMAP_US].shift[KEY_APOSTROPHE] = '_';
|
||||
keymaps[KEYMAP_US].shift[KEY_I_ACC] = '+';
|
||||
keymaps[KEYMAP_US].shift[KEY_Q] = 'Q';
|
||||
keymaps[KEYMAP_US].shift[KEY_W] = 'W';
|
||||
keymaps[KEYMAP_US].shift[KEY_E] = 'E';
|
||||
keymaps[KEYMAP_US].shift[KEY_R] = 'R';
|
||||
keymaps[KEYMAP_US].shift[KEY_T] = 'T';
|
||||
keymaps[KEYMAP_US].shift[KEY_Y] = 'Y';
|
||||
keymaps[KEYMAP_US].shift[KEY_U] = 'U';
|
||||
keymaps[KEYMAP_US].shift[KEY_I] = 'I';
|
||||
keymaps[KEYMAP_US].shift[KEY_O] = 'O';
|
||||
keymaps[KEYMAP_US].shift[KEY_P] = 'P';
|
||||
keymaps[KEYMAP_US].shift[KEY_LEFT_BRAKET] = '{';
|
||||
keymaps[KEYMAP_US].shift[KEY_RIGHT_BRAKET] = '}';
|
||||
keymaps[KEYMAP_US].shift[KEY_A] = 'A';
|
||||
keymaps[KEYMAP_US].shift[KEY_S] = 'S';
|
||||
keymaps[KEYMAP_US].shift[KEY_D] = 'D';
|
||||
keymaps[KEYMAP_US].shift[KEY_F] = 'F';
|
||||
keymaps[KEYMAP_US].shift[KEY_G] = 'G';
|
||||
keymaps[KEYMAP_US].shift[KEY_H] = 'H';
|
||||
keymaps[KEYMAP_US].shift[KEY_J] = 'J';
|
||||
keymaps[KEYMAP_US].shift[KEY_K] = 'K';
|
||||
keymaps[KEYMAP_US].shift[KEY_L] = 'L';
|
||||
keymaps[KEYMAP_US].shift[KEY_SEMICOLON] = ':';
|
||||
keymaps[KEYMAP_US].shift[KEY_DOUBLE_QUOTES] = '"';
|
||||
keymaps[KEYMAP_US].shift[KEY_GRAVE] = '~';
|
||||
keymaps[KEYMAP_US].shift[KEY_Z] = 'Z';
|
||||
keymaps[KEYMAP_US].shift[KEY_X] = 'X';
|
||||
keymaps[KEYMAP_US].shift[KEY_C] = 'C';
|
||||
keymaps[KEYMAP_US].shift[KEY_V] = 'V';
|
||||
keymaps[KEYMAP_US].shift[KEY_B] = 'B';
|
||||
keymaps[KEYMAP_US].shift[KEY_N] = 'N';
|
||||
keymaps[KEYMAP_US].shift[KEY_M] = 'M';
|
||||
keymaps[KEYMAP_US].shift[KEY_COMMA] = '<';
|
||||
keymaps[KEYMAP_US].shift[KEY_PERIOD] = '>';
|
||||
keymaps[KEYMAP_US].shift[KEY_MINUS] = '?';
|
||||
keymaps[KEYMAP_US].shift[KEY_KP_MUL] = '*';
|
||||
keymaps[KEYMAP_US].shift[KEY_SPACE] = ' ';
|
||||
keymaps[KEYMAP_US].shift[KEY_KP_SUB] = '-';
|
||||
keymaps[KEYMAP_US].shift[KEY_KP_ADD] = '+';
|
||||
keymaps[KEYMAP_US].shift[KEY_KP_LESS] = '>';
|
||||
keymaps[KEYMAP_US].shift[KEY_KP_DIV] = '/';
|
||||
|
||||
keymaps[KEYMAP_US].numlock[KEY_KP_DEC] = '.';
|
||||
keymaps[KEYMAP_US].numlock[KEY_KP0] = '0';
|
||||
keymaps[KEYMAP_US].numlock[KEY_KP1] = '1';
|
||||
keymaps[KEYMAP_US].numlock[KEY_KP2] = '2';
|
||||
keymaps[KEYMAP_US].numlock[KEY_KP3] = '3';
|
||||
keymaps[KEYMAP_US].numlock[KEY_KP4] = '4';
|
||||
keymaps[KEYMAP_US].numlock[KEY_KP5] = '5';
|
||||
keymaps[KEYMAP_US].numlock[KEY_KP6] = '6';
|
||||
keymaps[KEYMAP_US].numlock[KEY_KP7] = '7';
|
||||
keymaps[KEYMAP_US].numlock[KEY_KP8] = '8';
|
||||
keymaps[KEYMAP_US].numlock[KEY_KP9] = '9';
|
||||
}
|
||||
+133
-128
@@ -1,11 +1,14 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file mouse.c
|
||||
/// @brief Driver for *PS2* Mouses.
|
||||
/// @copyright (c) 2019 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.is distributed under the MIT License.
|
||||
///// See LICENSE.md for details.
|
||||
/////! @cond Doxygen_Suppress
|
||||
|
||||
#include "mouse.h"
|
||||
#include "pic8259.h"
|
||||
#include "port_io.h"
|
||||
|
||||
static uint8_t mouse_cycle = 0;
|
||||
|
||||
@@ -17,159 +20,161 @@ static int32_t mouse_y = (600 / 2);
|
||||
|
||||
void mouse_install()
|
||||
{
|
||||
// Enable the auxiliary mouse device.
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x64, 0xA8);
|
||||
// Enable the auxiliary mouse device.
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x64, 0xA8);
|
||||
|
||||
// Enable the interrupts.
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x64, 0x20);
|
||||
mouse_waitcmd(0);
|
||||
uint8_t status_byte = (inportb(0x60) | 2);
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x64, 0x60);
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x60, status_byte);
|
||||
// Enable the interrupts.
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x64, 0x20);
|
||||
mouse_waitcmd(0);
|
||||
uint8_t status_byte = (inportb(0x60) | 2);
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x64, 0x60);
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x60, status_byte);
|
||||
|
||||
// Tell the mouse to use default settings.
|
||||
mouse_write(MOUSE_USE_DEFAULT_SETTINGS);
|
||||
// Acknowledge.
|
||||
mouse_read();
|
||||
// Tell the mouse to use default settings.
|
||||
mouse_write(MOUSE_USE_DEFAULT_SETTINGS);
|
||||
// Acknowledge.
|
||||
mouse_read();
|
||||
|
||||
// Setup the mouse handler.
|
||||
// pic8259_irq_install_handler(IRQ_MOUSE, mouse_isr);
|
||||
// Setup the mouse handler.
|
||||
// pic8259_irq_install_handler(IRQ_MOUSE, mouse_isr);
|
||||
|
||||
mouse_enable();
|
||||
mouse_enable();
|
||||
}
|
||||
|
||||
void mouse_enable()
|
||||
{
|
||||
// Enable the mouse interrupts.
|
||||
pic8259_irq_enable(IRQ_MOUSE);
|
||||
// Disable the mouse.
|
||||
mouse_write(MOUSE_ENABLE_PACKET);
|
||||
// Acknowledge.
|
||||
mouse_read();
|
||||
// Enable the mouse interrupts.
|
||||
pic8259_irq_enable(IRQ_MOUSE);
|
||||
// Disable the mouse.
|
||||
mouse_write(MOUSE_ENABLE_PACKET);
|
||||
// Acknowledge.
|
||||
mouse_read();
|
||||
}
|
||||
|
||||
void mouse_disable()
|
||||
{
|
||||
// Disable the mouse interrupts.
|
||||
pic8259_irq_disable(IRQ_MOUSE);
|
||||
// Disable the mouse.
|
||||
mouse_write(MOUSE_DISABLE_PACKET);
|
||||
// Acknowledge.
|
||||
mouse_read();
|
||||
// Disable the mouse interrupts.
|
||||
pic8259_irq_disable(IRQ_MOUSE);
|
||||
// Disable the mouse.
|
||||
mouse_write(MOUSE_DISABLE_PACKET);
|
||||
// Acknowledge.
|
||||
mouse_read();
|
||||
}
|
||||
|
||||
void mouse_waitcmd(unsigned char type)
|
||||
{
|
||||
register unsigned int _time_out = 100000;
|
||||
if (type == 0) {
|
||||
// DATA.
|
||||
while (_time_out--) {
|
||||
if ((inportb(0x64) & 1) == 1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
while (_time_out--) // SIGNALS
|
||||
{
|
||||
if ((inportb(0x64) & 2) == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
register unsigned int _time_out = 100000;
|
||||
if (type == 0) {
|
||||
// DATA.
|
||||
while (_time_out--) {
|
||||
if ((inportb(0x64) & 1) == 1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
while (_time_out--) // SIGNALS
|
||||
{
|
||||
if ((inportb(0x64) & 2) == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void mouse_write(unsigned char data)
|
||||
{
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x64, 0xD4);
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x60, data);
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x64, 0xD4);
|
||||
mouse_waitcmd(1);
|
||||
outportb(0x60, data);
|
||||
}
|
||||
|
||||
unsigned char mouse_read()
|
||||
{
|
||||
mouse_waitcmd(0);
|
||||
return inportb(0x60);
|
||||
mouse_waitcmd(0);
|
||||
return inportb(0x60);
|
||||
}
|
||||
|
||||
void mouse_isr(register_t *r)
|
||||
void mouse_isr(pt_regs *f)
|
||||
{
|
||||
(void)r;
|
||||
// Get the input bytes.
|
||||
mouse_bytes[mouse_cycle++] = (char)inportb(0x60);
|
||||
if (mouse_cycle == 3) {
|
||||
// Reset the mouse cycle.
|
||||
mouse_cycle = 0;
|
||||
// ----------------------------
|
||||
// Get the X coordinates.
|
||||
// ----------------------------
|
||||
if ((mouse_bytes[0] & 0x40) == 0) {
|
||||
// Bit number 4 of the first byte (value 0x10) indicates that
|
||||
// delta X (the 2nd byte) is a negative number, if it is set.
|
||||
if ((mouse_bytes[0] & 0x10) == 0) {
|
||||
mouse_x -= mouse_bytes[1];
|
||||
} else {
|
||||
mouse_x += mouse_bytes[1];
|
||||
}
|
||||
} else {
|
||||
// Overflow.
|
||||
mouse_x += mouse_bytes[1] / 2;
|
||||
}
|
||||
// ----------------------------
|
||||
// Get the Y coordinates.
|
||||
// ----------------------------
|
||||
if ((mouse_bytes[0] & 0x80) == 0) {
|
||||
// Bit number 5 of the first byte (value 0x20) indicates that
|
||||
// delta Y (the 3rd byte) is a negative number, if it is set.
|
||||
if ((mouse_bytes[0] & 0x20) == 0) {
|
||||
mouse_y -= mouse_bytes[2];
|
||||
} else {
|
||||
mouse_y += mouse_bytes[2];
|
||||
}
|
||||
} else {
|
||||
// Overflow.
|
||||
mouse_y -= mouse_bytes[2] / 2;
|
||||
}
|
||||
// ----------------------------
|
||||
// Apply cursor constraint (800x600).
|
||||
// ----------------------------
|
||||
if (mouse_x <= 0) {
|
||||
mouse_x = 0;
|
||||
} else if (mouse_x >= (800 - 16)) {
|
||||
mouse_x = 800 - 16;
|
||||
}
|
||||
if (mouse_y <= 0) {
|
||||
mouse_y = 0;
|
||||
} else if (mouse_y >= (600 - 24)) {
|
||||
mouse_y = 600 - 24;
|
||||
}
|
||||
// Print the position.
|
||||
// dbg_print("\rX: %d | Y: %d\n", mouse_x, mouse_y);
|
||||
(void)f;
|
||||
// Get the input bytes.
|
||||
mouse_bytes[mouse_cycle++] = (char)inportb(0x60);
|
||||
if (mouse_cycle == 3) {
|
||||
// Reset the mouse cycle.
|
||||
mouse_cycle = 0;
|
||||
// ----------------------------
|
||||
// Get the X coordinates.
|
||||
// ----------------------------
|
||||
if ((mouse_bytes[0] & 0x40) == 0) {
|
||||
// Bit number 4 of the first byte (value 0x10) indicates that
|
||||
// delta X (the 2nd byte) is a negative number, if it is set.
|
||||
if ((mouse_bytes[0] & 0x10) == 0) {
|
||||
mouse_x -= mouse_bytes[1];
|
||||
} else {
|
||||
mouse_x += mouse_bytes[1];
|
||||
}
|
||||
} else {
|
||||
// Overflow.
|
||||
mouse_x += mouse_bytes[1] / 2;
|
||||
}
|
||||
// ----------------------------
|
||||
// Get the Y coordinates.
|
||||
// ----------------------------
|
||||
if ((mouse_bytes[0] & 0x80) == 0) {
|
||||
// Bit number 5 of the first byte (value 0x20) indicates that
|
||||
// delta Y (the 3rd byte) is a negative number, if it is set.
|
||||
if ((mouse_bytes[0] & 0x20) == 0) {
|
||||
mouse_y -= mouse_bytes[2];
|
||||
} else {
|
||||
mouse_y += mouse_bytes[2];
|
||||
}
|
||||
} else {
|
||||
// Overflow.
|
||||
mouse_y -= mouse_bytes[2] / 2;
|
||||
}
|
||||
// ----------------------------
|
||||
// Apply cursor constraint (800x600).
|
||||
// ----------------------------
|
||||
if (mouse_x <= 0) {
|
||||
mouse_x = 0;
|
||||
} else if (mouse_x >= (800 - 16)) {
|
||||
mouse_x = 800 - 16;
|
||||
}
|
||||
if (mouse_y <= 0) {
|
||||
mouse_y = 0;
|
||||
} else if (mouse_y >= (600 - 24)) {
|
||||
mouse_y = 600 - 24;
|
||||
}
|
||||
// Print the position.
|
||||
// pr_default("\rX: %d | Y: %d\n", mouse_x, mouse_y);
|
||||
|
||||
// Move the cursor.
|
||||
// video_set_cursor(mouse_x, mouse_y);
|
||||
// Move the cursor.
|
||||
// video_set_cursor(mouse_x, mouse_y);
|
||||
|
||||
// Here a problem is detected, if the mouse moves
|
||||
// Pressed keys are detected.
|
||||
// Detecting keystrokes.
|
||||
// Center pressed.
|
||||
if ((mouse_bytes[0] & 0x04) == 0) {
|
||||
// dbg_print(LNG_MOUSE_MID);
|
||||
}
|
||||
// Right pressed.
|
||||
if ((mouse_bytes[0] & 0x02) == 0) {
|
||||
// dbg_print(LNG_MOUSE_RIGHT);
|
||||
}
|
||||
// Left pressed.
|
||||
if ((mouse_bytes[0] & 0x01) == 0) {
|
||||
// dbg_print(LNG_MOUSE_LEFT);
|
||||
}
|
||||
}
|
||||
pic8259_send_eoi(IRQ_MOUSE);
|
||||
// Here a problem is detected, if the mouse moves
|
||||
// Pressed keys are detected.
|
||||
// Detecting keystrokes.
|
||||
// Center pressed.
|
||||
if ((mouse_bytes[0] & 0x04) == 0) {
|
||||
// pr_default(LNG_MOUSE_MID);
|
||||
}
|
||||
// Right pressed.
|
||||
if ((mouse_bytes[0] & 0x02) == 0) {
|
||||
// pr_default(LNG_MOUSE_RIGHT);
|
||||
}
|
||||
// Left pressed.
|
||||
if ((mouse_bytes[0] & 0x01) == 0) {
|
||||
// pr_default(LNG_MOUSE_LEFT);
|
||||
}
|
||||
}
|
||||
pic8259_send_eoi(IRQ_MOUSE);
|
||||
}
|
||||
|
||||
///! @endcond
|
||||
@@ -0,0 +1,138 @@
|
||||
/// MentOS, The Mentoring Operating system project
|
||||
/// @file rtc.c
|
||||
/// @brief Real Time Clock (RTC) driver.
|
||||
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "rtc.h"
|
||||
|
||||
#include "pic8259.h"
|
||||
#include "string.h"
|
||||
#include "port_io.h"
|
||||
#include "kernel.h"
|
||||
#include "isr.h"
|
||||
|
||||
#define CMOS_ADDR 0x70 ///< Addess where we need to write the Address.
|
||||
#define CMOS_DATA 0x71 ///< Addess where we need to write the Data.
|
||||
|
||||
/// Current global time.
|
||||
tm_t global_time;
|
||||
/// Previous global time.
|
||||
tm_t previous_global_time;
|
||||
/// Data type is BCD.
|
||||
int is_bcd;
|
||||
|
||||
static inline unsigned int rtc_are_different(tm_t *t0, tm_t *t1)
|
||||
{
|
||||
if (t0->tm_sec != t1->tm_sec)
|
||||
return 1;
|
||||
if (t0->tm_min != t1->tm_min)
|
||||
return 1;
|
||||
if (t0->tm_hour != t1->tm_hour)
|
||||
return 1;
|
||||
if (t0->tm_mon != t1->tm_mon)
|
||||
return 1;
|
||||
if (t0->tm_year != t1->tm_year)
|
||||
return 1;
|
||||
if (t0->tm_wday != t1->tm_wday)
|
||||
return 1;
|
||||
if (t0->tm_mday != t1->tm_mday)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// @brief Check if rtc is updating time currently.
|
||||
static inline unsigned int is_updating_rtc()
|
||||
{
|
||||
outportb(CMOS_ADDR, 0x0A);
|
||||
uint32_t status = inportb(CMOS_DATA);
|
||||
return (status & 0x80U);
|
||||
}
|
||||
|
||||
static inline unsigned char read_register(unsigned char reg)
|
||||
{
|
||||
outportb(CMOS_ADDR, reg);
|
||||
return inportb(CMOS_DATA);
|
||||
}
|
||||
|
||||
static inline void write_register(unsigned char reg, unsigned char value)
|
||||
{
|
||||
outportb(CMOS_ADDR, reg);
|
||||
outportb(CMOS_DATA, value);
|
||||
}
|
||||
|
||||
static inline unsigned char bcd2bin(unsigned char bcd)
|
||||
{
|
||||
return ((bcd >> 4u) * 10) + (bcd & 0x0Fu);
|
||||
}
|
||||
|
||||
static inline void rtc_read_datetime()
|
||||
{
|
||||
if (read_register(0x0Cu) & 0x10u) {
|
||||
if (is_bcd) {
|
||||
global_time.tm_sec = bcd2bin(read_register(0x00));
|
||||
global_time.tm_min = bcd2bin(read_register(0x02));
|
||||
global_time.tm_hour = bcd2bin(read_register(0x04)) + 2;
|
||||
global_time.tm_mon = bcd2bin(read_register(0x08));
|
||||
global_time.tm_year = bcd2bin(read_register(0x09)) + 2000;
|
||||
global_time.tm_wday = bcd2bin(read_register(0x06));
|
||||
global_time.tm_mday = bcd2bin(read_register(0x07));
|
||||
} else {
|
||||
global_time.tm_sec = read_register(0x00);
|
||||
global_time.tm_min = read_register(0x02);
|
||||
global_time.tm_hour = read_register(0x04) + 2;
|
||||
global_time.tm_mon = read_register(0x08);
|
||||
global_time.tm_year = read_register(0x09) + 2000;
|
||||
global_time.tm_wday = read_register(0x06);
|
||||
global_time.tm_mday = read_register(0x07);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void rtc_handler_isr(pt_regs *f)
|
||||
{
|
||||
static unsigned int first_update = 1;
|
||||
// Wait until rtc is not updating.
|
||||
while (is_updating_rtc())
|
||||
;
|
||||
// Read the values.
|
||||
rtc_read_datetime();
|
||||
if (first_update) {
|
||||
do {
|
||||
// Save the previous global time.
|
||||
previous_global_time = global_time;
|
||||
// Wait until rtc is not updating.
|
||||
while (is_updating_rtc())
|
||||
;
|
||||
// Read the values.
|
||||
rtc_read_datetime();
|
||||
} while (!rtc_are_different(&previous_global_time, &global_time));
|
||||
first_update = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void gettime(tm_t *time)
|
||||
{
|
||||
// Copy the update time.
|
||||
memcpy(time, &global_time, sizeof(tm_t));
|
||||
}
|
||||
|
||||
void rtc_install(void)
|
||||
{
|
||||
unsigned char status;
|
||||
|
||||
status = read_register(0x0B);
|
||||
status |= 0x02u; // 24 hour clock
|
||||
status |= 0x10u; // update ended interrupts
|
||||
status &= ~0x20u; // no alarm interrupts
|
||||
status &= ~0x40u; // no periodic interrupt
|
||||
is_bcd = !(status & 0x04u); // check if data type is BCD
|
||||
write_register(0x0B, status);
|
||||
|
||||
read_register(0x0C);
|
||||
|
||||
// Install the IRQ.
|
||||
irq_install_handler(IRQ_REAL_TIME_CLOCK, rtc_handler_isr, "Real Time Clock (RTC)");
|
||||
// Enable the IRQ.
|
||||
pic8259_irq_enable(IRQ_REAL_TIME_CLOCK);
|
||||
}
|
||||
Reference in New Issue
Block a user