feature (strings): implemented the noxos ascii extension

This commit is contained in:
antifallobst 2023-05-03 22:46:15 +02:00
parent fb66944b0e
commit be508dae9f
6 changed files with 99 additions and 28 deletions

View File

@ -3,32 +3,36 @@
#ifndef NOX_SCANCODES_H
#define NOX_SCANCODES_H
#define PS2_SCANCODE_SET_1_ESCAPE 0x01
#define PS2_SCANCODE_SET_1_BACKSPACE 0x0E
#define PS2_SCANCODE_SET_1_TABULATOR 0x0F
#define PS2_SCANCODE_SET_1_RETURN 0x1C
#define PS2_SCANCODE_SET_1_SHIFT_LEFT 0x2A
#define PS2_SCANCODE_SET_1_SHIFT_RIGHT 0x36
#define PS2_SCANCODE_SET_1_ALT_LEFT 0x38
#define PS2_SCANCODE_SET_1_SPACE 0x39
#define PS2_SCANCODE_SET_1_CAPSLOCK 0x3A
#define PS2_SCANCODE_SET_1_NUMLOCK 0x45
#define PS2_SCANCODE_SET_1_SCROLLLOCK 0x46
#define PS2_SCANCODE_SET_1_F1 0x3B
#define PS2_SCANCODE_SET_1_F2 0x3C
#define PS2_SCANCODE_SET_1_F3 0x3D
#define PS2_SCANCODE_SET_1_F4 0x3E
#define PS2_SCANCODE_SET_1_F5 0x3F
#define PS2_SCANCODE_SET_1_F6 0x40
#define PS2_SCANCODE_SET_1_F7 0x41
#define PS2_SCANCODE_SET_1_F8 0x42
#define PS2_SCANCODE_SET_1_F9 0x43
#define PS2_SCANCODE_SET_1_F10 0x44
#define PS2_SCANCODE_SET_1_F11 0x57
#define PS2_SCANCODE_SET_1_F12 0x58
#define PS2_SCANCODE_SET_1_ESCAPE 0x01
#define PS2_SCANCODE_SET_1_BACKSPACE 0x0E
#define PS2_SCANCODE_SET_1_TABULATOR 0x0F
#define PS2_SCANCODE_SET_1_RETURN 0x1C
#define PS2_SCANCODE_SET_1_SHIFT_LEFT 0x2A
#define PS2_SCANCODE_SET_1_SHIFT_RIGHT 0x36
#define PS2_SCANCODE_SET_1_ALT_LEFT 0x38
#define PS2_SCANCODE_SET_1_SPACE 0x39
#define PS2_SCANCODE_SET_1_CAPSLOCK 0x3A
#define PS2_SCANCODE_SET_1_NUMLOCK 0x45
#define PS2_SCANCODE_SET_1_SCROLLLOCK 0x46
#define PS2_SCANCODE_SET_1_F1 0x3B
#define PS2_SCANCODE_SET_1_F2 0x3C
#define PS2_SCANCODE_SET_1_F3 0x3D
#define PS2_SCANCODE_SET_1_F4 0x3E
#define PS2_SCANCODE_SET_1_F5 0x3F
#define PS2_SCANCODE_SET_1_F6 0x40
#define PS2_SCANCODE_SET_1_F7 0x41
#define PS2_SCANCODE_SET_1_F8 0x42
#define PS2_SCANCODE_SET_1_F9 0x43
#define PS2_SCANCODE_SET_1_F10 0x44
#define PS2_SCANCODE_SET_1_F11 0x57
#define PS2_SCANCODE_SET_1_F12 0x58
#define PS2_SCANCODE_SET_1_E0_CURSOR_UP 0x48
#define PS2_SCANCODE_SET_1_E0_CURSOR_LEFT 0x4B
#define PS2_SCANCODE_SET_1_E0_CURSOR_RIGHT 0x4D
#define PS2_SCANCODE_SET_1_E0_CURSOR_DOWN 0x50
#define PS2_SCANCODE_SET_1_RELEASE 0x80
#define PS2_SCANCODE_SET_1_MODIFIER 0xE0
#define PS2_SCANCODE_SET_1_RELEASE 0x80
#define PS2_SCANCODE_SET_1_MODIFIER 0xE0
#endif //NOX_SCANCODES_H

View File

@ -6,12 +6,35 @@
#include "stdtypes.h"
#include <stdarg.h>
#define STRING_EXT_SIZE(n) ((n) + 5)
typedef const char* string_t;
typedef enum {
STRING_EXT_CMD_CLEAR,
STRING_EXT_CMD_CURSOR_MOVE,
STRING_EXT_CMD_CURSOR_SET,
STRING_EXT_CMD_COLOR_SET,
STRING_EXT_CMD_COLOR_RESET,
STRING_EXT_CMD_RENDER_DISABLE,
STRING_EXT_CMD_RENDER_ENABLE,
STRING_EXT_CMD_KEYBOARD_ECHO
} string_ext_command_E;
typedef struct {
uint8_t shift_in;
uint16_t length;
uint8_t command;
uint8_t data;
// DATA BLOCKS
// SHIFT OUT
}__attribute__((packed)) string_ext_header_T;
uint32_t string_length (string_t string);
bool string_compare (string_t a, string_t b);
uint32_t string_find_next (string_t string, char chr);
uint32_t string_find_last (string_t string, char chr);
void string_add_ext_command (string_t string, string_ext_command_E command, int num_data, uint8_t data[]);
uint64_t variadic_format_size (string_t string, va_list args);
uint64_t format_size (string_t string, ...);

View File

@ -24,7 +24,7 @@ int read_command(char* command_buffer) {
}
}
command_buffer[pos] = '\0';
command_buffer[--pos] = '\0';
return pos;
}

Binary file not shown.

View File

@ -61,13 +61,44 @@ void ps2_keyboard_init() {
pic_unmask_irq(IRQ_KEYBOARD);
}
#include "utils/memory.h"
void ps2_keyboard_read() {
uint8_t scancode = ps2_controller_read_data();
char chr [2]; chr[1] = '\0';
char chr [8];
if (extended_key) {
extended_key = false;
return;
switch (scancode) {
case PS2_SCANCODE_SET_1_E0_CURSOR_LEFT: {
uint8_t data = 0;
string_add_ext_command(chr, STRING_EXT_CMD_CURSOR_MOVE, 1, &data);
chr[STRING_EXT_SIZE(1)+1] = '\0';
break;
}
case PS2_SCANCODE_SET_1_E0_CURSOR_RIGHT: {
uint8_t data = 1;
string_add_ext_command(chr, STRING_EXT_CMD_CURSOR_MOVE, 1, &data);
chr[STRING_EXT_SIZE(1)+1] = '\0';
break;
}
case PS2_SCANCODE_SET_1_E0_CURSOR_UP: {
uint8_t data = 2;
string_add_ext_command(chr, STRING_EXT_CMD_CURSOR_MOVE, 1, &data);
chr[STRING_EXT_SIZE(1)+1] = '\0';
break;
}
case PS2_SCANCODE_SET_1_E0_CURSOR_DOWN: {
uint8_t data = 3;
string_add_ext_command(chr, STRING_EXT_CMD_CURSOR_MOVE, 1, &data);
chr[STRING_EXT_SIZE(1)+1] = '\0';
break;
}
default: {
return;
}
}
memory_hexdump(chr, 8);
}
if (scancode == PS2_SCANCODE_SET_1_MODIFIER) {
@ -111,16 +142,19 @@ void ps2_keyboard_read() {
case PS2_SCANCODE_SET_1_BACKSPACE: {
chr[0] = '\b';
chr[1] = '\0';
break;
}
case PS2_SCANCODE_SET_1_SPACE: {
chr[0] = ' ';
chr[1] = '\0';
break;
}
case PS2_SCANCODE_SET_1_RETURN: {
chr[0] = '\n';
chr[1] = '\0';
break;
}
@ -137,6 +171,7 @@ void ps2_keyboard_read() {
if (string_is_char_lowercase(chr[0])) chr[0] -= 32;
else if (string_is_char_uppercase(chr[0])) chr[0] += 32;
}
chr[1] = '\0';
break;
}
}

View File

@ -42,6 +42,15 @@ uint32_t string_find_last(string_t string, char chr) {
return n;
}
void string_add_ext_command(string_t string, string_ext_command_E command, int num_data, uint8_t data[]) {
string_ext_header_T* header = (string_ext_header_T*)string;
header->shift_in = 0x0F;
header->length = num_data;
header->command = command;
memory_copy(data, &header->data, num_data);
*(&(&header->data)[num_data]) = 0x0E;
}
uint64_t variadic_format_size(string_t string, va_list args) {
const char* buffer_in = (const char*)string;