holy SHIFT
This commit is contained in:
@@ -66,7 +66,19 @@ static void draw_char(char c, int px, int py, int fg, int bg)
|
||||
}
|
||||
}
|
||||
|
||||
static void putchar(char c)
|
||||
static void erase_char(int px, int py)
|
||||
{
|
||||
for (size_t y=0; y<FONT_HEIGHT; y++)
|
||||
{
|
||||
for (size_t x=0; x<8; x++)
|
||||
{
|
||||
// Black
|
||||
putpixel(px+x, py+y, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void putchar(char c)
|
||||
{
|
||||
if (c == '\n')
|
||||
{
|
||||
@@ -75,6 +87,17 @@ static void putchar(char c)
|
||||
return;
|
||||
}
|
||||
|
||||
// Improperly handled.
|
||||
// When we're on an empty line it should get to the upper line's last character
|
||||
if (c == '\b')
|
||||
{
|
||||
cursor.x--;
|
||||
int px = cursor.x * FONT_WIDTH;
|
||||
int py = cursor.y * FONT_HEIGHT;
|
||||
erase_char(px, py);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((cursor.x+1)*FONT_WIDTH >= framebuffer->width)
|
||||
{
|
||||
cursor.x = 0;
|
||||
@@ -87,7 +110,7 @@ static void putchar(char c)
|
||||
cursor.x++;
|
||||
}
|
||||
|
||||
// Overhead that could be avoided, right?
|
||||
// Overhead that could be avoided, right? (for printf)
|
||||
void _putchar(char character)
|
||||
{
|
||||
putchar(character);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
int term_init();
|
||||
void kputs(const char* str);
|
||||
void putchar(char c);
|
||||
|
||||
enum TermColors
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../io/printf.h"
|
||||
#include "ps2.h"
|
||||
#include <stdint.h>
|
||||
#include "../io/term.h"
|
||||
|
||||
// The key status bitfield will be used to see if ALT, CONTROL, or SHIFT is pressed
|
||||
uint8_t key_status = 0b00000000;
|
||||
@@ -156,50 +157,55 @@ void keyboard_handler()
|
||||
// Key release (bit 7 set)
|
||||
if (scancode & 0x80)
|
||||
{
|
||||
if (key_status & SHIFT_PRESSED)
|
||||
unsigned char code = scancode & 0x7F;
|
||||
switch (code)
|
||||
{
|
||||
serial_kputs("SHIFT was released!\n");
|
||||
key_status &= ~(1 << 0); // Unset SHIFT bit
|
||||
// Clear the corresponding bit if corresponding key is released
|
||||
case LEFT_SHIFT_PRESSED:
|
||||
case RIGHT_SHIFT_PRESSED:
|
||||
key_status &= ~SHIFT_PRESSED_BIT;
|
||||
break;
|
||||
case CTRL_PRESSED:
|
||||
key_status &= ~CTRL_PRESSED_BIT;
|
||||
break;
|
||||
case ALT_PRESSED:
|
||||
key_status &= ~ALT_PRESSED_BIT;
|
||||
break;
|
||||
}
|
||||
|
||||
if (key_status & ALT_PRESSED)
|
||||
{
|
||||
serial_kputs("ALT was released!\n");
|
||||
key_status &= ~(1 << 1); // Unset ALT bit
|
||||
}
|
||||
|
||||
if (key_status & CTRL_PRESSED)
|
||||
{
|
||||
serial_kputs("CTRL was released!\n");
|
||||
key_status &= ~(1 << 2); // Unset CTRL bit
|
||||
}
|
||||
// Send EOI
|
||||
outb(0x20, 0x20);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Key press
|
||||
unsigned char character;
|
||||
|
||||
switch (keymap[scancode])
|
||||
switch (scancode)
|
||||
{
|
||||
case SHIFT:
|
||||
serial_kputs("SHIFT ");
|
||||
key_status |= (1 << 0); // SHIFT bit
|
||||
// Set bits for corresponding special key press
|
||||
case LEFT_SHIFT_PRESSED:
|
||||
case RIGHT_SHIFT_PRESSED:
|
||||
key_status |= SHIFT_PRESSED_BIT;
|
||||
break;
|
||||
case ALT:
|
||||
serial_kputs("ALT ");
|
||||
key_status |= (1 << 1);
|
||||
case CTRL_PRESSED:
|
||||
key_status |= CTRL_PRESSED_BIT;
|
||||
break;
|
||||
case CTRL:
|
||||
serial_kputs("CTRL ");
|
||||
key_status |= (1 << 2);
|
||||
case ALT_PRESSED:
|
||||
key_status |= ALT_PRESSED_BIT;
|
||||
break;
|
||||
|
||||
default:
|
||||
character = (key_status & SHIFT_PRESSED) ? keymap_shifted[scancode] : keymap[scancode];
|
||||
printf("%c", character);
|
||||
break;
|
||||
{
|
||||
// Should we get a SHIFTED char or a regular one?
|
||||
unsigned char c = (key_status & SHIFT_PRESSED_BIT) ? keymap_shifted[scancode] : keymap[scancode];
|
||||
|
||||
if (c)
|
||||
{
|
||||
putchar(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Should we get a SHIFTED char or a regular one?
|
||||
serial_kputs("key pressed!\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
void keyboard_handler();
|
||||
|
||||
#define SHIFT_PRESSED 0b00000001
|
||||
#define ALT_PRESSED 0b00000010
|
||||
#define CTRL_PRESSED 0b00000100
|
||||
#define SHIFT_PRESSED_BIT 0b00000001
|
||||
#define ALT_PRESSED_BIT 0b00000010
|
||||
#define CTRL_PRESSED_BIT 0b00000100
|
||||
|
||||
enum SpecialKeys
|
||||
{
|
||||
@@ -14,6 +14,18 @@ enum SpecialKeys
|
||||
CTRL = 253
|
||||
};
|
||||
|
||||
enum SpecialScancodes
|
||||
{
|
||||
LEFT_SHIFT_PRESSED = 0x2A,
|
||||
LEFT_SHIFT_RELEASED = 0xAA,
|
||||
RIGHT_SHIFT_PRESSED = 0x36,
|
||||
RIGHT_SHIFT_RELEASED = 0xB6,
|
||||
CTRL_PRESSED = 0x1D,
|
||||
CTRL_RELEASED = 0x9D,
|
||||
ALT_PRESSED = 0x38,
|
||||
ALT_RELEASED = 0xB8
|
||||
};
|
||||
|
||||
enum KeyboardLayout
|
||||
{
|
||||
US,
|
||||
|
||||
Reference in New Issue
Block a user