Files
kern/include/c/stdio.h
T
Tom-on 74c38342d7 Made memory/addresses.h more organised
Also didn't need to add stdio.h to any files so that's good!
2024-05-28 17:43:07 +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*)0x2100;
*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