Changed default font to Termius 8x16 (old font is still there)

This commit is contained in:
2024-05-02 13:10:40 +02:00
parent 12de6c5b74
commit 8664855d81
6 changed files with 1588 additions and 27 deletions
+13 -9
View File
@@ -8,17 +8,16 @@ CFLAGS = -ffreestanding -m32 -Iinclude -Wall -Wextra
SRC = ./src SRC = ./src
BUILD = ./build BUILD = ./build
C_FILES = calc C_FILES = calc
FONTS = testfont term16n
.PHONY: os clean run .PHONY: os clean run
# Main compilation target # Main compilation target
os: $(BUILD) bootloader kernel $(C_FILES) filesystem os: $(BUILD) filesystem
@echo "\nDone!\n" @echo "\nDone!\n"
# Filesystem # Filesystem
filesystem: filesystem: $(BUILD)/boot.bin $(BUILD)/kernel.bin $(C_FILES) $(FONTS)
@echo "Assembling $(SRC)/testfont.asm..."
@$(AS) -fbin -o $(BUILD)/testfont.bin $(SRC)/testfont.asm
@echo "Building filesystem..." @echo "Building filesystem..."
@$(AS) -fbin -o $(BUILD)/filetable.bin $(SRC)/filetable.asm @$(AS) -fbin -o $(BUILD)/filetable.bin $(SRC)/filetable.asm
@dd if=/dev/zero of=kern.iso bs=512 count=2880 status=none @dd if=/dev/zero of=kern.iso bs=512 count=2880 status=none
@@ -26,16 +25,17 @@ filesystem:
@dd if=$(BUILD)/boot.bin of=kern.iso bs=512 seek=0 conv=notrunc status=none @dd if=$(BUILD)/boot.bin of=kern.iso bs=512 seek=0 conv=notrunc status=none
@dd if=$(BUILD)/filetable.bin of=kern.iso bs=512 seek=5 conv=notrunc status=none @dd if=$(BUILD)/filetable.bin of=kern.iso bs=512 seek=5 conv=notrunc status=none
@dd if=$(BUILD)/kernel.bin of=kern.iso bs=512 seek=6 conv=notrunc status=none @dd if=$(BUILD)/kernel.bin of=kern.iso bs=512 seek=6 conv=notrunc status=none
@dd if=$(BUILD)/testfont.bin of=kern.iso bs=512 seek=36 conv=notrunc status=none @dd if=$(BUILD)/term16n.bin of=kern.iso bs=512 seek=36 conv=notrunc status=none
@dd if=$(SRC)/fs/test.txt of=kern.iso bs=512 seek=40 conv=notrunc status=none @dd if=$(BUILD)/testfont.bin of=kern.iso bs=512 seek=40 conv=notrunc status=none
@dd if=$(BUILD)/calc.bin of=kern.iso bs=512 seek=41 conv=notrunc status=none @dd if=$(SRC)/fs/test.txt of=kern.iso bs=512 seek=44 conv=notrunc status=none
@dd if=$(BUILD)/calc.bin of=kern.iso bs=512 seek=45 conv=notrunc status=none
$(BUILD): $(BUILD):
@[ -d $(BUILD) ] || mkdir $(BUILD) @[ -d $(BUILD) ] || mkdir $(BUILD)
@rm -rf $(BUILD)/* @rm -rf $(BUILD)/*
# Bootloader: This target is responsible for creating boot.bin # Bootloader: This target is responsible for creating boot.bin
bootloader: $(BUILD)/boot.bin: $(SRC)/stage1.asm $(SRC)/stage2.asm
@echo "Assembling $(SRC)/stage1.asm..." @echo "Assembling $(SRC)/stage1.asm..."
@$(AS) -fbin -o $(BUILD)/stage1.bin $(SRC)/stage1.asm @$(AS) -fbin -o $(BUILD)/stage1.bin $(SRC)/stage1.asm
@echo "Assembling $(SRC)/stage2.asm..." @echo "Assembling $(SRC)/stage2.asm..."
@@ -43,7 +43,7 @@ bootloader:
@cat $(BUILD)/stage1.bin $(BUILD)/stage2.bin > $(BUILD)/boot.bin @cat $(BUILD)/stage1.bin $(BUILD)/stage2.bin > $(BUILD)/boot.bin
# Kernel: This target is responsible for creating kernel.bin # Kernel: This target is responsible for creating kernel.bin
kernel: $(SRC)/kernel.c $(SRC)/entry.asm $(BUILD)/kernel.bin: $(SRC)/kernel.c $(SRC)/entry.asm
@echo "Assembling $(SRC)/entry.asm..." @echo "Assembling $(SRC)/entry.asm..."
@$(AS) -felf32 -o $(BUILD)/entry.o $(SRC)/entry.asm @$(AS) -felf32 -o $(BUILD)/entry.o $(SRC)/entry.asm
@echo "Compiling $(SRC)/kernel.c..." @echo "Compiling $(SRC)/kernel.c..."
@@ -57,6 +57,10 @@ $(C_FILES):
@$(LD) -T$(SRC)/$@.ld --oformat binary -o $(BUILD)/$@.bin $(BUILD)/$@.o @$(LD) -T$(SRC)/$@.ld --oformat binary -o $(BUILD)/$@.bin $(BUILD)/$@.o
@rm $(BUILD)/$@.o @rm $(BUILD)/$@.o
$(FONTS):
@echo "Assembling $(SRC)/fonts/$@.asm..."
@$(AS) -fbin -o $(BUILD)/$@.bin $(SRC)/fonts/$@.asm
# Run QEMU # Run QEMU
run: run:
qemu-system-x86_64 -drive format=raw,file="./kern.iso",index=0,media=disk -m 256M -accel tcg qemu-system-x86_64 -drive format=raw,file="./kern.iso",index=0,media=disk -m 256M -accel tcg
+10 -8
View File
@@ -6,8 +6,6 @@
#define MODE_INFO_BLOCK 0x9000 #define MODE_INFO_BLOCK 0x9000
#define BG_COLOR 0x00010b17 #define BG_COLOR 0x00010b17
#define FG_COLOR 0x00ebddf4 #define FG_COLOR 0x00ebddf4
#define CHAR_WIDTH 8
#define CHAR_HEIGHT 16
typedef struct modeInfoBlock_s { typedef struct modeInfoBlock_s {
// Required by all VBE revisions // Required by all VBE revisions
@@ -96,13 +94,15 @@ uint32_t convertColor(uint32_t color) {
void putcAt(unsigned char c, uint32_t x, uint32_t y) { void putcAt(unsigned char c, uint32_t x, uint32_t y) {
uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr; uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr;
uint8_t bytesPerPx = (gfxMode->bpp+1) / 8; uint8_t bytesPerPx = (gfxMode->bpp+1) / 8;
uint32_t offset = (gfxMode->xRes * y * CHAR_HEIGHT + x * CHAR_WIDTH) * bytesPerPx; uint8_t charWidth = *(font);
uint8_t charHeight = *(font + 1);
uint32_t offset = (gfxMode->xRes * y * charHeight + x * charWidth) * bytesPerPx;
char* bitmap = &font[((c % 128) - 1) * 16]; char* bitmap = &font[((c % 128) - 1) * charHeight];
for (uint8_t i = 0; i < CHAR_HEIGHT; i++) { // Rows for (uint8_t i = 0; i < charHeight; i++) { // Rows
char bitmapRow = bitmap[i]; char bitmapRow = bitmap[i];
for (uint8_t j = 0; j < CHAR_WIDTH * bytesPerPx; ++j) { // Cols for (uint8_t j = 0; j < charHeight * bytesPerPx; ++j) { // Cols
uint32_t color = convertColor((bitmapRow & 0x80) ? fgColor : bgColor); uint32_t color = convertColor((bitmapRow & 0x80) ? fgColor : bgColor);
uint8_t byte = j % bytesPerPx; uint8_t byte = j % bytesPerPx;
vidmem[offset + j] = (uint8_t)(color >> (8 * byte)); vidmem[offset + j] = (uint8_t)(color >> (8 * byte));
@@ -124,6 +124,8 @@ void printAt(const char* str, uint32_t x, uint32_t y) {
} }
void putc(char c) { void putc(char c) {
uint8_t charWidth = *(font);
if (c == '\n') { if (c == '\n') {
putcAt(' ', cursor.x, cursor.y); // Make sure we don't leave an extra cursor putcAt(' ', cursor.x, cursor.y); // Make sure we don't leave an extra cursor
cursor.y++; cursor.y++;
@@ -132,7 +134,7 @@ void putc(char c) {
putcAt(' ', cursor.x, cursor.y); // Make sure we don't leave an extra cursor putcAt(' ', cursor.x, cursor.y); // Make sure we don't leave an extra cursor
if (cursor.x == 0) { if (cursor.x == 0) {
cursor.x = gfxMode->xRes / CHAR_WIDTH - 1; // Subtract one so we don't overflow to the line start cursor.x = gfxMode->xRes / charWidth - 1; // Subtract one so we don't overflow to the line start
cursor.y--; // y could be 0 cursor.y--; // y could be 0
} else { } else {
cursor.x--; cursor.x--;
@@ -143,7 +145,7 @@ void putc(char c) {
putcAt(c, cursor.x, cursor.y); putcAt(c, cursor.x, cursor.y);
cursor.x++; cursor.x++;
if (cursor.x >= gfxMode->xRes / CHAR_WIDTH) { if (cursor.x >= gfxMode->xRes / charWidth) {
cursor.y++; // TODO: Scrolling cursor.y++; // TODO: Scrolling
cursor.x = 0; cursor.x = 0;
} }
+4 -3
View File
@@ -13,9 +13,10 @@ filetable:
db "boot",0,0,0,0,0,0, "bin",0,0,5 db "boot",0,0,0,0,0,0, "bin",0,0,5
db "filetable",0, "tab",0,5,1 db "filetable",0, "tab",0,5,1
db "kernel",0,0,0,0, "bin",0,6,30 db "kernel",0,0,0,0, "bin",0,6,30
db "testfont",0,0, "fnt",0,36,4 db "term16n",0,0,0, "fnt",0,36,4
db "test",0,0,0,0,0,0, "txt",0,40,1 db "testfont",0,0, "fnt",0,40,4
db "calc",0,0,0,0,0,0, "bin",0,41,2 db "test",0,0,0,0,0,0, "txt",0,44,1
db "calc",0,0,0,0,0,0, "bin",0,45,2
times 512-($-$$) db 0 times 512-($-$$) db 0
File diff suppressed because it is too large Load Diff
+9 -2
View File
@@ -5,8 +5,15 @@
;;; 8*16*128 = 2048B (2kB) ;;; 8*16*128 = 2048B (2kB)
;;; Takes up 4 sectors ;;; Takes up 4 sectors
;;; ;;;
;; 0-31
times 31*16 db 0 ;;; Font header - 16 Bytes
charWidth: db 8
charHeight: db 16
reserved: times 14 db 0
;;; Bitmap data
;; 1-31 Non printable characters (0 - NULL is in the header, and we can't print it anyway)
times 30*16 db 0
;; Space ' ' or '_' - starts at ascii 32/20h ;; Space ' ' or '_' - starts at ascii 32/20h
db 00000000b,\ db 00000000b,\
00000000b,\ 00000000b,\
+3 -3
View File
@@ -372,9 +372,9 @@ DATA_SEG equ GDT.dataDescriptor - GDT.start
;; VBE Stuff ;; VBE Stuff
;; !! IF YOU WANT TO SELECT ANY VALUE IN THE SETUP, SET THESE TO ZERO !! ;; !! IF YOU WANT TO SELECT ANY VALUE IN THE SETUP, SET THESE TO ZERO !!
width: dw 0 width: dw 1920
height: dw 0 height: dw 1080
bpp: db 0 bpp: db 32
offset: dw 0 offset: dw 0
_segment: dw 0 ; segment is a keyword _segment: dw 0 ; segment is a keyword