add simple puts function for testing

This commit is contained in:
Robert 2023-09-03 20:31:42 +02:00
parent 7adc0c7ce1
commit 3d25674623
4 changed files with 57 additions and 1 deletions

View file

@ -0,0 +1,7 @@
#ifndef _CLIPPER_STRING_H_
#define _CLIPPER_STRING_H_
void putch(char c);
void puts(const char* str);
#endif

View file

@ -10,6 +10,9 @@
# error "Please use an ix86-elf compiler"
#endif
#include "string.h"
void kmain(void) {
puts("Clipper has booted!\r\n");
return;
}

44
src/kernel/lib/string.c Normal file
View file

@ -0,0 +1,44 @@
#include "string.h"
#include <stdint.h>
static volatile char* video = (volatile char*)0xB8000;
static uint8_t cursor_x = 0, cursor_y = 0;
#define SCREEN_WIDTH 80
#define SCREEN_HEIGHT 25
static inline void advance_cursor(void) {
cursor_x++;
if (cursor_x >= SCREEN_WIDTH) {
cursor_x = 0;
cursor_y++;
if (cursor_y >= SCREEN_HEIGHT) {
cursor_y = 0;
}
}
}
static inline void linefeed(void) {
cursor_y++;
if (cursor_y >= SCREEN_HEIGHT) {
cursor_y = 0;
}
}
void putch(char c) {
switch(c) {
case '\r': cursor_x = 0; return;
case '\n': linefeed(); return;
}
video[cursor_y * (SCREEN_WIDTH * 2) + (cursor_x * 2)] = c;
advance_cursor();
}
void puts(const char* str) {
for (const char* c = str; *c != '\0'; c++) {
putch(*c);
}
}