mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Added scrolling (finally)
This commit is contained in:
+2
-1
@@ -2,6 +2,7 @@
|
|||||||
#include "idt.h"
|
#include "idt.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
char* exceptionMessages[] = {
|
char* exceptionMessages[] = {
|
||||||
"Divide By Zero Error",
|
"Divide By Zero Error",
|
||||||
@@ -79,7 +80,7 @@ void faultHandler(struct regs* r) {
|
|||||||
|
|
||||||
if (r->errCode) {
|
if (r->errCode) {
|
||||||
print(": 0x", 0x04);
|
print(": 0x", 0x04);
|
||||||
printHex(r->errCode, 0x04);
|
print(itoa(r->errCode, 16), 0x04);
|
||||||
}
|
}
|
||||||
|
|
||||||
cli();
|
cli();
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void keyboardHandler() {
|
|||||||
|
|
||||||
char* read(char terminator, uint8_t attr) {
|
char* read(char terminator, uint8_t attr) {
|
||||||
bufferLen = 0;
|
bufferLen = 0;
|
||||||
echo = true;
|
echo = attr ? true : false;
|
||||||
echoAttr = attr;
|
echoAttr = attr;
|
||||||
|
|
||||||
while (buffer[bufferLen-1] != terminator && bufferLen < MAX_BUFFER_SIZE);
|
while (buffer[bufferLen-1] != terminator && bufferLen < MAX_BUFFER_SIZE);
|
||||||
|
|||||||
+24
-16
@@ -2,20 +2,38 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
uint16_t cursor = 0;
|
uint32_t cursor = 0;
|
||||||
|
|
||||||
void updateCursor() {
|
void updateCursor() {
|
||||||
|
// Move visual cursor position
|
||||||
outb(0x3d4, 0x0f); // Low byte
|
outb(0x3d4, 0x0f); // Low byte
|
||||||
outb(0x3d5, cursor & 0xff);
|
outb(0x3d5, cursor & 0xff);
|
||||||
outb(0x3d4, 0x0e); // High byte
|
outb(0x3d4, 0x0e); // High byte
|
||||||
outb(0x3d5, cursor >> 8);
|
outb(0x3d5, cursor >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scroll() {
|
||||||
|
if (cursor < COLS * ROWS) return;
|
||||||
|
|
||||||
|
for (int i = 1; i < ROWS; i++) {
|
||||||
|
memcopy((char*)(calcOffset(0, i)*2)+VIDMEM, (char*)(calcOffset(0, i-1)*2)+VIDMEM, COLS*2);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* lastRow = (char*)(calcOffset(0, ROWS-1)*2)+VIDMEM;
|
||||||
|
for (int i = 0; i < COLS*2; i += 2) {
|
||||||
|
lastRow[i] = '\0';
|
||||||
|
lastRow[i+1] = 0x0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor = calcOffset(0, ROWS-1);
|
||||||
|
}
|
||||||
|
|
||||||
void putc(char c, uint8_t attr) {
|
void putc(char c, uint8_t attr) {
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
uint16_t line = cursor - (cursor % COLS);
|
uint16_t line = cursor - (cursor % COLS);
|
||||||
setCursorPos(line + COLS);
|
setCursorPos(line + COLS);
|
||||||
|
scroll();
|
||||||
|
updateCursor();
|
||||||
return;
|
return;
|
||||||
} else if (c == '\b') {
|
} else if (c == '\b') {
|
||||||
cursor--;
|
cursor--;
|
||||||
@@ -32,6 +50,7 @@ void putc(char c, uint8_t attr) {
|
|||||||
|
|
||||||
cursor++;
|
cursor++;
|
||||||
|
|
||||||
|
scroll();
|
||||||
updateCursor();
|
updateCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +61,7 @@ void print(char* s, uint8_t attr) {
|
|||||||
c = *(++s);
|
c = *(++s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scroll();
|
||||||
updateCursor();
|
updateCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,28 +93,16 @@ void clear(uint8_t attr) {
|
|||||||
updateCursor();
|
updateCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setCursorPos(uint32_t offset) {
|
||||||
void printHex(uint8_t d, uint8_t attr) {
|
|
||||||
char hexDigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
|
||||||
uint8_t low = d & 0x0f;
|
|
||||||
uint8_t high = (d & 0xf0) >> 4;
|
|
||||||
|
|
||||||
putc(hexDigits[low], attr);
|
|
||||||
putc(hexDigits[high], attr);
|
|
||||||
|
|
||||||
updateCursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCursorPos(uint16_t offset) {
|
|
||||||
cursor = offset;
|
cursor = offset;
|
||||||
updateCursor();
|
updateCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getCursorPos() {
|
uint32_t getCursorPos() {
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t calcOffset(uint8_t col, uint8_t row) {
|
uint32_t calcOffset(uint8_t col, uint8_t row) {
|
||||||
return row * COLS + col;
|
return row * COLS + col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -21,9 +21,10 @@ void printAt(char* s, uint8_t attr, uint8_t row, uint8_t col);
|
|||||||
void clear(uint8_t attr);
|
void clear(uint8_t attr);
|
||||||
void printHex(uint8_t d, uint8_t attr);
|
void printHex(uint8_t d, uint8_t attr);
|
||||||
|
|
||||||
void setCursorPos(uint16_t offset);
|
void setCursorPos(uint32_t offset);
|
||||||
uint16_t getCursorPos();
|
uint32_t getCursorPos();
|
||||||
uint16_t calcOffset(uint8_t row, uint8_t col);
|
uint32_t calcOffset(uint8_t row, uint8_t col);
|
||||||
|
void scroll();
|
||||||
|
|
||||||
void enableCursor(uint8_t start, uint8_t end);
|
void enableCursor(uint8_t start, uint8_t end);
|
||||||
void disableCursor();
|
void disableCursor();
|
||||||
|
|||||||
Reference in New Issue
Block a user