forked from PoliEcho-holding-org/kern
Continuing terminal I/O
- Made stdio.h work - Moved printFiletable back into kernel.c - TODO: Add stdio.h to all files that should use it (probably next commmit) - Added some more global addresses. There's a memory layout, but i'm not using it - Got cursor to be drawn - Calc program now gets user input
This commit is contained in:
+33
-2
@@ -11,8 +11,39 @@ void print(const char* s) {
|
||||
write(STDOUT, s, strlen(s));
|
||||
}
|
||||
|
||||
void read(char* s) {
|
||||
print("\x1b[1M[ ERROR: Read() Syscall not found! ]\n");
|
||||
void putc(char c) {
|
||||
static char _c; // We need to pass in a static address. Idk why
|
||||
_c = c;
|
||||
write(STDOUT, &_c, 1);
|
||||
}
|
||||
|
||||
char getc() {
|
||||
char* character = (char*)0x3000;
|
||||
*character = '\0';
|
||||
while (*character == '\0') { __asm__ volatile ("hlt"); }
|
||||
return *character;
|
||||
}
|
||||
|
||||
// Reads until a newline
|
||||
// TODO: Use Read() Syscall
|
||||
void read(char* buffer) {
|
||||
char c;
|
||||
uint8_t len = 0;
|
||||
|
||||
while ((c = getc()) != '\n') {
|
||||
if (c == '\b') {
|
||||
if (len < 1) continue; // Can we backspace?
|
||||
len--;
|
||||
putc(c);
|
||||
} else {
|
||||
buffer[len++] = c;
|
||||
putc(c);
|
||||
}
|
||||
}
|
||||
|
||||
buffer[len++] = c; // Add newline
|
||||
putc(c);
|
||||
buffer[len] = '\0'; // Null terminate
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user