add simple puts function for testing
This commit is contained in:
parent
7adc0c7ce1
commit
3d25674623
4
Makefile
4
Makefile
|
@ -5,6 +5,8 @@ SRC_DIR=src
|
||||||
BUILD_DIR=build
|
BUILD_DIR=build
|
||||||
ISO_DIR=$(BUILD_DIR)/iso
|
ISO_DIR=$(BUILD_DIR)/iso
|
||||||
|
|
||||||
|
INCLUDE_DIR=$(SRC_DIR)/kernel/include
|
||||||
|
|
||||||
KERNEL_ASM := $(shell find $(SRC_DIR)/kernel -name "*.asm")
|
KERNEL_ASM := $(shell find $(SRC_DIR)/kernel -name "*.asm")
|
||||||
KERNEL_C := $(shell find $(SRC_DIR)/kernel -name "*.c")
|
KERNEL_C := $(shell find $(SRC_DIR)/kernel -name "*.c")
|
||||||
|
|
||||||
|
@ -31,7 +33,7 @@ $(BUILD_DIR)/%.asm.o: $(SRC_DIR)/%.asm
|
||||||
|
|
||||||
$(BUILD_DIR)/%.c.o: $(SRC_DIR)/%.c
|
$(BUILD_DIR)/%.c.o: $(SRC_DIR)/%.c
|
||||||
@mkdir -p "$(@D)"
|
@mkdir -p "$(@D)"
|
||||||
$(CC) -c $< -o $@ -std=gnu99 -ffreestanding -O2 -Wall -Wextra
|
$(CC) -c $< -o $@ -I$(INCLUDE_DIR) -std=gnu99 -ffreestanding -O2 -Wall -Wextra
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(BUILD_DIR)/*
|
rm -rf $(BUILD_DIR)/*
|
||||||
|
|
7
src/kernel/include/string.h
Normal file
7
src/kernel/include/string.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef _CLIPPER_STRING_H_
|
||||||
|
#define _CLIPPER_STRING_H_
|
||||||
|
|
||||||
|
void putch(char c);
|
||||||
|
void puts(const char* str);
|
||||||
|
|
||||||
|
#endif
|
|
@ -10,6 +10,9 @@
|
||||||
# error "Please use an ix86-elf compiler"
|
# error "Please use an ix86-elf compiler"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
void kmain(void) {
|
void kmain(void) {
|
||||||
|
puts("Clipper has booted!\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
44
src/kernel/lib/string.c
Normal file
44
src/kernel/lib/string.c
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue