Made screen.h actually good

This commit is contained in:
2024-03-09 19:33:28 +01:00
parent e8ea9ebcc0
commit 71e80f73bb
6 changed files with 78 additions and 9 deletions
+4 -1
View File
@@ -3,6 +3,9 @@
void main() {
setupIdt();
print("kern.\n", 0x0f);
clear(0x0f);
print("kern.\n\n", 0x0f);
print("> ", 0x0e);
}
Binary file not shown.
+48 -5
View File
@@ -1,8 +1,15 @@
#include "screen.h"
#include "stdint.h"
unsigned int cursor = 0;
uint16_t cursor = 0;
void putc(char c, char attr) {
void putc(char c, uint8_t attr) {
if (c == '\n') {
uint16_t line = cursor - (cursor % COLS);
setCursorPos(line + COLS);
return;
}
int mem = VIDMEM + cursor * 2;
*(char*)(mem) = c;
*(char*)(mem+1) = attr;
@@ -10,12 +17,48 @@ void putc(char c, char attr) {
cursor++;
}
void print(char* s, char attr) {
int i = 0;
void print(char* s, uint8_t attr) {
char c = *s;
while (c != '\0') {
putc(c, attr);
c = *(s + ++i);
c = *(++s);
}
}
void putcAt(char c, uint8_t attr, uint8_t col, uint8_t row) {
uint16_t offset = calcOffset(col, row);
*(char*)(VIDMEM + offset * 2) = c;
*(char*)(VIDMEM + offset * 2 + 1) = attr;
}
void printAt(char* s, uint8_t attr, uint8_t col, uint8_t row) {
uint16_t offset = calcOffset(col, row);
char c = *s;
while (c != '\0') {
*(char*)(VIDMEM + offset * 2) = c;
*(char*)(VIDMEM + offset * 2 + 1) = attr;
c = *(++s);
offset++;
}
}
void clear(uint8_t attr) {
for (int i = 0; i < CHARS*2; i += 2) {
*(char*)(VIDMEM + i) = ' ';
*(char*)(VIDMEM + i + 1) = attr;
}
}
void setCursorPos(uint16_t offset) {
cursor = offset;
}
uint16_t getCursorPos() {
return cursor;
}
uint16_t calcOffset(uint8_t col, uint8_t row) {
return row * COLS + col;
}
+26 -3
View File
@@ -1,9 +1,32 @@
#ifndef SCREEN_H
#define SCREEN_H
#define VIDMEM 0xb8000
#include "stdint.h"
void putc(char c, char attr);
void print(char* s, char attr);
#define VIDMEM 0xb8000
#define CURSOR_HIGH 14
#define CURSOR_LOW 15
#define CTRLREG 0x3d4
#define DATAREG 0x3d5
// 80x25 VGA Text mode
#define ROWS 25
#define COLS 80
#define CHARS (ROWS*COLS)
#define CURSOR '_'
void putc(char c, uint8_t attr);
void print(char* s, uint8_t attr);
void putcAt(char c, uint8_t attr, uint8_t row, uint8_t col);
void printAt(char* s, uint8_t attr, uint8_t row, uint8_t col);
void clear(uint8_t attr);
void setCursorPos(uint16_t offset);
uint16_t getCursorPos();
uint16_t calcOffset(uint8_t row, uint8_t col);
void setCursorChar(char cursor);
char getCursorChar();
#endif
Binary file not shown.
Binary file not shown.