Compare commits

...

2 Commits

Author SHA1 Message Date
Mathieu Maret
4c523bf956 libc: add a, bad, malloc 2023-03-21 22:41:17 +01:00
Mathieu Maret
1f844d6a35 keyboard: add alt modifier 2023-03-21 22:40:10 +01:00
3 changed files with 166 additions and 3 deletions

View File

@ -144,6 +144,135 @@ const char *scancode[128] = {
/* 126 */ 0, /* 126 */ 0,
/* 127 */ 0}; /* 127 */ 0};
const char *scancode_alt[128] = {
/* 0 */ 0,
/* 1 */ "\e",
/* 2 */ "1",
/* 3 */ "~",
/* 4 */ "#",
/* 5 */ "{",
/* 6 */ "[",
/* 7 */ "|",
/* 8 */ "`",
/* 9 */ "\\",
/* 10 */ "^",
/* 11 */ "@",
/* 12 */ "]",
/* 13 */ "}",
/* 14 */ "\b", /* Shift-Backspace */
/* 15 */ "\e[Z", /* Shift-Tab */
/* 16 */ "A",
/* 17 */ "Z",
/* 18 */ "E",
/* 19 */ "R",
/* 20 */ "T",
/* 21 */ "Y",
/* 22 */ "U",
/* 23 */ "I",
/* 24 */ "O",
/* 25 */ "P",
/* 26 */ "\"",
/* 27 */ "£",
/* 28 */ "\n",
/* 29 */ 0, /* left control */
/* 30 */ "Q",
/* 31 */ "S",
/* 32 */ "D",
/* 33 */ "F",
/* 34 */ "G",
/* 35 */ "H",
/* 36 */ "J",
/* 37 */ "K",
/* 38 */ "L",
/* 39 */ "M",
/* 40 */ "%",
/* 41 */ 0,
/* 42 */ 0,
/* 43 */ "µ",
/* 44 */ "W",
/* 45 */ "X",
/* 46 */ "C",
/* 47 */ "V",
/* 48 */ "B",
/* 49 */ "N",
/* 50 */ "?",
/* 51 */ ".",
/* 52 */ "/",
/* 53 */ "§",
/* 54 */ 0,
/* 55 */ 0,
/* 56 */ 0,
/* 57 */ 0,
/* 58 */ 0,
/* 59 */ "\eOP", /* Shift-F1 */
/* 60 */ "\eOQ", /* Shift-F2 */
/* 61 */ "\eOR", /* Shift-F3 */
/* 62 */ "\eOS", /* Shift-F4 */
/* 63 */ "\e[15;2~", /* Shift-F5 */
/* 64 */ "\e[17;2~", /* Shift-F6 */
/* 65 */ "\e[18;2~", /* Shift-F7 */
/* 66 */ "\e[19;2~", /* Shift-F8 */
/* 67 */ "\e[20:2~", /* Shift-F9 */
/* 68 */ "\e[21:2~", /* Shift-F10 */
/* 69 */ 0,
/* 70 */ 0,
/* 71 */ 0,
/* 72 */ 0,
/* 73 */ 0,
/* 74 */ 0,
/* 75 */ 0,
/* 76 */ 0,
/* 77 */ 0,
/* 78 */ 0,
/* 79 */ 0,
/* 80 */ 0,
/* 81 */ 0,
/* 82 */ 0,
/* 83 */ 0,
/* 84 */ 0,
/* 85 */ 0,
/* 86 */ ">",
/* 87 */ "\e[23;2~", /* Shift-F11 */
/* 88 */ "\e[24;2~", /* Shift-F12 */
/* 89 */ 0,
/* 90 */ 0,
/* 91 */ 0,
/* 92 */ 0,
/* 93 */ 0,
/* 94 */ 0,
/* 95 */ 0,
/* 96 */ 0,
/* 97 */ 0,
/* 98 */ 0,
/* 99 */ 0,
/* 100 */ 0,
/* 101 */ 0,
/* 102 */ 0,
/* 103 */ 0,
/* 104 */ 0,
/* 105 */ 0,
/* 106 */ 0,
/* 107 */ 0,
/* 108 */ 0,
/* 109 */ 0,
/* 110 */ 0,
/* 111 */ 0,
/* 112 */ 0,
/* 113 */ 0,
/* 114 */ 0,
/* 115 */ 0,
/* 116 */ 0,
/* 117 */ 0,
/* 118 */ 0,
/* 119 */ 0,
/* 120 */ 0,
/* 121 */ 0,
/* 122 */ 0,
/* 123 */ 0,
/* 124 */ 0,
/* 125 */ 0,
/* 126 */ 0,
/* 127 */ 0};
const char *scancode_shift[128] = { const char *scancode_shift[128] = {
/* 0 */ 0, /* 0 */ 0,
/* 1 */ "\e", /* 1 */ "\e",
@ -279,6 +408,7 @@ void keyboard_do_irq()
static int lshift = 0; static int lshift = 0;
static int rshift = 0; static int rshift = 0;
static int capslock = 0; static int capslock = 0;
static int alt = 0;
static int isExt = 0; static int isExt = 0;
unsigned char c = inb(KEYBOARD_DATA_PORT); unsigned char c = inb(KEYBOARD_DATA_PORT);
const char *key = NULL; const char *key = NULL;
@ -298,12 +428,17 @@ void keyboard_do_irq()
case 54: case 54:
rshift = 1; rshift = 1;
break; break;
case 56:
alt = 1;
break;
case 58: case 58:
capslock = 1 - capslock; capslock = 1 - capslock;
break; break;
default: default:
if ((lshift || rshift) ^ capslock) { if ((lshift || rshift) ^ capslock) {
key = scancode_shift[(int)c]; key = scancode_shift[(int)c];
} else if (alt) {
key = scancode_alt[(int)c];
} else { } else {
key = scancode[(int)c]; key = scancode[(int)c];
} }
@ -316,6 +451,10 @@ void keyboard_do_irq()
break; break;
case 54: case 54:
rshift = 0; rshift = 0;
break;
case 56:
alt = 0;
break;
} }
} }
} }

View File

@ -536,7 +536,7 @@ char readc()
return syscall0(SYSCALL_ID_READ); return syscall0(SYSCALL_ID_READ);
} }
char readcBlock() char getchar()
{ {
char c = 0; char c = 0;
do { do {
@ -549,7 +549,7 @@ int readline(char *buf, int size)
{ {
int i = 0; int i = 0;
for (; i < size - 1; i++) { for (; i < size - 1; i++) {
char key = readcBlock(); char key = getchar();
if (key == '\n') if (key == '\n')
break; break;
@ -570,3 +570,24 @@ void *brk(void *addr)
{ {
return (void *)syscall1(SYSCALL_ID_BRK, (unsigned int)addr); return (void *)syscall1(SYSCALL_ID_BRK, (unsigned int)addr);
} }
void *malloc(size_t size)
{
void *heapTop = 0;
static void *free = 0;
if (heapTop == 0) {
heapTop = brk(0);
free = heapTop;
} else {
heapTop = brk(0);
}
if (free + size > heapTop) {
if (brk(heapTop + size))
return NULL;
}
free += size;
return (free - size);
}

View File

@ -10,6 +10,8 @@
(((c) == ' ') || ((c) == '\t') || ((c) == '\f') || ((c) == '\n') || ((c) == '\r') || \ (((c) == ' ') || ((c) == '\t') || ((c) == '\f') || ((c) == '\n') || ((c) == '\r') || \
((c) == '\v')) ((c) == '\v'))
#define isprint(c) ((' ' <= (c)) && ((c) <= '~')) #define isprint(c) ((' ' <= (c)) && ((c) <= '~'))
#define EOF (-1)
int memcmp(const void *s1, const void *s2, size_t n); int memcmp(const void *s1, const void *s2, size_t n);
void *memcpy(void *dest, const void *src, size_t n); void *memcpy(void *dest, const void *src, size_t n);
@ -43,6 +45,7 @@ void _exit(int status);
void yolo(); void yolo();
int testSycall5(uint arg1, uint arg2, uint arg3, uint arg4, uint arg5); int testSycall5(uint arg1, uint arg2, uint arg3, uint arg4, uint arg5);
char readc(); char readc();
char readcBlock(); char getchar();
int readline(char *buf, int size); int readline(char *buf, int size);
void *brk(void *addr); void *brk(void *addr);
void *malloc(size_t size);