Files
kern/include/c/stdio.h
T
Tom-on ff07696dc6 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
2024-05-28 17:08:49 +02:00

50 lines
951 B
C

#ifndef STDIO_H
#define STDIO_H
#include <syscall.h>
#include <string.h>
// TODO: Make a proper file descriptor table
#define STDOUT 1
void print(const char* s) {
write(STDOUT, s, strlen(s));
}
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