feature: add a few helpers fn (is...)

fix: print unprintable characters no longer occurs
This commit is contained in:
0x35c 2024-10-11 13:10:47 +02:00
parent 29b59c474d
commit 41786ea523
7 changed files with 45 additions and 15 deletions

View File

@ -1,18 +1,34 @@
#pragma once #pragma once
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
[[__maybe_unused__]] static const char *keymap[128] = { [[__maybe_unused__]] static const char *keymap[128] = {
[2] = "1!", [3] = "2@", [4] = "3#", [5] = "4$", [6] = "5%", [2] = "1!", [3] = "2@", [4] = "3#", [5] = "4$", [6] = "5%",
[7] = "6^", [8] = "7&", [9] = "8*", [10] = "9(", [11] = "0)", [7] = "6^", [8] = "7&", [9] = "8*", [10] = "9(", [11] = "0)",
[12] = "-_", [13] = "=+", [16] = "qQ", [17] = "wW", [18] = "eE", [12] = "-_", [13] = "=+", [14] = NULL, [15] = NULL, [16] = "qQ",
[19] = "rR", [20] = "tT", [21] = "yY", [22] = "uU", [23] = "iI", [17] = "wW", [18] = "eE", [19] = "rR", [20] = "tT", [21] = "yY",
[24] = "oO", [25] = "pP", [26] = "[{", [27] = "]}", [28] = "\n\n", [22] = "uU", [23] = "iI", [24] = "oO", [25] = "pP", [26] = "[{",
[30] = "aA", [31] = "sS", [32] = "dD", [33] = "fF", [34] = "gG", [27] = "]}", [28] = "\n\n", [30] = "aA", [31] = "sS", [32] = "dD",
[35] = "hH", [36] = "jJ", [37] = "kK", [38] = "lL", [39] = ";:", [33] = "fF", [34] = "gG", [35] = "hH", [36] = "jJ", [37] = "kK",
[40] = "'\"", [43] = "\\|", [44] = "zZ", [45] = "xX", [46] = "cC", [38] = "lL", [39] = ";:", [40] = "'\"", [41] = NULL, [42] = NULL,
[47] = "vV", [48] = "bB", [49] = "nN", [50] = "mM", [51] = ",<", [43] = "\\|", [44] = "zZ", [45] = "xX", [46] = "cC", [47] = "vV",
[52] = ".>", [53] = "/?", [57] = " ", [48] = "bB", [49] = "nN", [50] = "mM", [51] = ",<", [52] = ".>",
[53] = "/?", [54] = NULL, [55] = NULL, [56] = NULL, [57] = " ",
[58] = NULL, [59] = NULL, [60] = NULL, [61] = NULL, [62] = NULL,
[63] = NULL, [64] = NULL, [65] = NULL, [66] = NULL, [67] = NULL,
[68] = NULL, [69] = NULL, [70] = NULL, [71] = NULL, [72] = NULL,
[73] = NULL, [74] = NULL, [75] = NULL, [76] = NULL, [77] = NULL,
[78] = NULL, [79] = NULL, [80] = NULL, [81] = NULL, [82] = NULL,
[83] = NULL, [84] = NULL, [85] = NULL, [86] = NULL, [87] = NULL,
[88] = NULL, [89] = NULL, [90] = NULL, [91] = NULL, [92] = NULL,
[93] = NULL, [94] = NULL, [95] = NULL, [96] = NULL, [97] = NULL,
[98] = NULL, [99] = NULL, [100] = NULL, [101] = NULL, [102] = NULL,
[103] = NULL, [104] = NULL, [105] = NULL, [106] = NULL, [107] = NULL,
[108] = NULL, [109] = NULL, [110] = NULL, [111] = NULL, [112] = NULL,
[113] = NULL, [114] = NULL, [115] = NULL, [116] = NULL, [117] = NULL,
[118] = NULL, [119] = NULL, [120] = NULL, [121] = NULL, [122] = NULL,
[123] = NULL, [124] = NULL, [125] = NULL, [126] = NULL, [127] = NULL,
}; };
#define KEYBOARD_PORT 0x60 #define KEYBOARD_PORT 0x60
@ -104,4 +120,4 @@ struct key_event {
uint8_t scan_code; uint8_t scan_code;
}; };
struct key_event get_key(void); struct key_event get_key(void);

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
/* /*
int isalnum(int c);
int isalpha(int c);
int iscntrl(int c); int iscntrl(int c);
*/ */
int isdigit(int c); int isdigit(int c);
int isalpha(int c);
int isalnum(int c);
/* /*
int isgraph(int c); int isgraph(int c);
int islower(int c); int islower(int c);

View File

@ -0,0 +1,6 @@
#include "ctype.h"
int isalnum(int c)
{
return isalpha(c) || isdigit(c);
}

View File

@ -0,0 +1,4 @@
int isalpha(int c)
{
return ('Z' >= c && c >= 'A') || ('z' >= c && c >= 'a');
}

View File

@ -29,5 +29,8 @@ void kernel_main(void)
init_idt(); init_idt();
init_memory(); init_memory();
load_drivers(); load_drivers();
kprintf("I see no way to confuse an array of 256 seg:off pairs with a "
"complex 8*unknown quantity -byte descriptor table. -- Troy "
"Martin 03:50, 22 March 2009 (UTC)\n");
shell_init(); shell_init();
} }

View File

@ -2,7 +2,7 @@
#include "alloc.h" #include "alloc.h"
#include "commands.h" #include "commands.h"
#include "drivers.h" #include "ctype.h"
#include "kprintf.h" #include "kprintf.h"
#include "shell.h" #include "shell.h"
#include "string.h" #include "string.h"

View File

@ -20,7 +20,8 @@ struct key_event terminal_getkey(void)
scan_code == KEY_LEFT_SHIFT + 128) scan_code == KEY_LEFT_SHIFT + 128)
caps_mode = false; caps_mode = false;
if (scan_code < 128) { if (scan_code < 128) {
ev.c = keymap[scan_code][caps_mode]; if (keymap[scan_code])
ev.c = keymap[scan_code][caps_mode];
if (scan_code >= KEY_F1 && scan_code <= KEY_F10) if (scan_code >= KEY_F1 && scan_code <= KEY_F10)
terminal_set_screen(scan_code - KEY_F1); terminal_set_screen(scan_code - KEY_F1);
ev.scan_code = scan_code; ev.scan_code = scan_code;