forked from PoliEcho-holding-org/kern
Made screen.h actually good
This commit is contained in:
+4
-1
@@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
setupIdt();
|
setupIdt();
|
||||||
print("kern.\n", 0x0f);
|
clear(0x0f);
|
||||||
|
|
||||||
|
print("kern.\n\n", 0x0f);
|
||||||
|
print("> ", 0x0e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
+48
-5
@@ -1,8 +1,15 @@
|
|||||||
#include "screen.h"
|
#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;
|
int mem = VIDMEM + cursor * 2;
|
||||||
*(char*)(mem) = c;
|
*(char*)(mem) = c;
|
||||||
*(char*)(mem+1) = attr;
|
*(char*)(mem+1) = attr;
|
||||||
@@ -10,12 +17,48 @@ void putc(char c, char attr) {
|
|||||||
cursor++;
|
cursor++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print(char* s, char attr) {
|
void print(char* s, uint8_t attr) {
|
||||||
int i = 0;
|
|
||||||
char c = *s;
|
char c = *s;
|
||||||
while (c != '\0') {
|
while (c != '\0') {
|
||||||
putc(c, attr);
|
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
@@ -1,9 +1,32 @@
|
|||||||
#ifndef SCREEN_H
|
#ifndef SCREEN_H
|
||||||
#define SCREEN_H
|
#define SCREEN_H
|
||||||
|
|
||||||
#define VIDMEM 0xb8000
|
#include "stdint.h"
|
||||||
|
|
||||||
void putc(char c, char attr);
|
#define VIDMEM 0xb8000
|
||||||
void print(char* s, char attr);
|
#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
|
#endif
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user