Skip to content

Commit

Permalink
minor thingies
Browse files Browse the repository at this point in the history
  • Loading branch information
oculometric committed May 6, 2024
1 parent dbbda73 commit 92f0b89
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 38 deletions.
37 changes: 37 additions & 0 deletions src/include/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@

#include <stdint.h>

#define K_ESC '\x1b'
#define K_LSHIFT '\x0e'
#define K_RSHIFT '\x0f'
#define K_LCTRL '\x11'
#define K_RCTRL '\x12'
#define K_LALT '\x13'
#define K_NSTAR '\x01'
#define K_NPLUS '\x02'
#define K_NMINUS '\x03'
#define K_NDOT '\x04'
#define K_CAPS '\x05'
#define K_SCROLL '\x06'
#define K_NUM '\x07'
#define K_N0 '\xb0'
#define K_N1 '\xb1'
#define K_N2 '\xb2'
#define K_N3 '\xb3'
#define K_N4 '\xb4'
#define K_N5 '\xb5'
#define K_N6 '\xb6'
#define K_N7 '\xb7'
#define K_N8 '\xb8'
#define K_N9 '\xb9'
#define K_F1 '\xba'
#define K_F2 '\xbb'
#define K_F3 '\xbc'
#define K_F4 '\xbd'
#define K_F5 '\xbe'
#define K_F6 '\xbf'
#define K_F7 '\xc0'
#define K_F8 '\xc1'
#define K_F9 '\xc2'
#define K_F10 '\xc3'
#define K_F11 '\xc4'
#define K_F12 '\xc5'

namespace nov
{
namespace keyboard
Expand Down Expand Up @@ -69,6 +105,7 @@ void keyboardInterruptCallback();
void assignPS2KeyboardController(PS2KeyboardController* controller);

KeyState decodeScancode(uint8_t scancode, ScancodeSet scs);
bool isAlphaNumeric(char c);

#define PS2_DATA_PORT 0x60

Expand Down
37 changes: 1 addition & 36 deletions src/include/scancodes.h
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
#pragma once

#include <stdint.h>

#define K_ESC '\x1b'
#define K_LSHIFT '\x0e'
#define K_RSHIFT '\x0f'
#define K_LCTRL '\x11'
#define K_RCTRL '\x12'
#define K_LALT '\x13'
#define K_NSTAR '\x01'
#define K_NPLUS '\x02'
#define K_NMINUS '\x03'
#define K_NDOT '\x04'
#define K_CAPS '\x05'
#define K_SCROLL '\x06'
#define K_NUM '\x07'
#define K_N0 '\xb0'
#define K_N1 '\xb1'
#define K_N2 '\xb2'
#define K_N3 '\xb3'
#define K_N4 '\xb4'
#define K_N5 '\xb5'
#define K_N6 '\xb6'
#define K_N7 '\xb7'
#define K_N8 '\xb8'
#define K_N9 '\xb9'
#define K_F1 '\xba'
#define K_F2 '\xbb'
#define K_F3 '\xbc'
#define K_F4 '\xbd'
#define K_F5 '\xbe'
#define K_F6 '\xbf'
#define K_F7 '\xc0'
#define K_F8 '\xc1'
#define K_F9 '\xc2'
#define K_F10 '\xc3'
#define K_F11 '\xc4'
#define K_F12 '\xc5'
#include <keyboard.h>

static const char scan_code_set_1_char[256]
{
Expand Down
1 change: 1 addition & 0 deletions src/include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class String

void resize(uint32_t new_capacity);
void clear();
void pop(uint32_t num = 1);

const char* constStr() const;

Expand Down
6 changes: 4 additions & 2 deletions src/kernel_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ extern "C" void main(boot::OSHintTable* os_hint_table)
keyboard::KeyState state = keyboard::decodeScancode(kb_byte, keyboard::ScancodeSet::SET_1);
if (state.is_down)
{
text_panel->text.append(state.key);
com_1 << "keyboard byte: " << (char)state.key << endl;
if (keyboard::isAlphaNumeric(state.key) || state.key == '\n')
text_panel->text.append(state.key);
if (state.key == '\b')
text_panel->text.pop();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ KeyState decodeScancode(uint8_t scancode, ScancodeSet scs)
return state;
}

bool isAlphaNumeric(char c)
{
if (c < ' ') return false;
if (c > '~') return false;
return true;
}

void PS2KeyboardController::queueInByte(uint8_t byte)
{
if (in_queue_end == in_queue_start - 1)
Expand Down
6 changes: 6 additions & 0 deletions src/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ void String::clear()
backing.clear();
}

void String::pop(uint32_t num)
{
if (!num) return;
for (uint32_t i = 0; i < num; i++) backing.pop();
}

uint32_t String::getLength() const
{
return backing.getLength();
Expand Down

0 comments on commit 92f0b89

Please sign in to comment.