implement autoscrolling on screen borders
This commit is contained in:
@ -73,11 +73,14 @@ void CGA::show(int x, int y, char character, unsigned char attrib) {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
if (x > 80 || y > 25) {
|
||||
// Out of bounds
|
||||
return;
|
||||
}
|
||||
|
||||
char* pos = (char*)(CGA_START + 2 * (x + y * 80)); // cast to char* to make writable
|
||||
*pos = character;
|
||||
*(pos + 1) = attrib;
|
||||
|
||||
// TODO: screen border check
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@ -95,28 +98,44 @@ void CGA::print(char* string, int n, unsigned char attrib) {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
int cursor_x, cursor_y;
|
||||
int cursor_x, cursor_y; // Don't poll registers every stroke
|
||||
this->getpos(cursor_x, cursor_y);
|
||||
|
||||
for (unsigned short byte = 0; byte < n; ++byte) {
|
||||
|
||||
char current = *(string + byte);
|
||||
if (current == '\n') {
|
||||
// TODO: Screen bounds
|
||||
cursor_x = 0;
|
||||
cursor_y = cursor_y + 1;
|
||||
|
||||
if (cursor_y > 24) {
|
||||
// Bottom of screen reached
|
||||
this->scrollup();
|
||||
cursor_y = cursor_y - 1;
|
||||
}
|
||||
|
||||
continue;
|
||||
} else if (current == '\0') {
|
||||
// Don't need to run to end if null terminated
|
||||
break;
|
||||
}
|
||||
|
||||
this->show(cursor_x, cursor_y, current, attrib);
|
||||
cursor_x = cursor_x + 1;
|
||||
|
||||
if (cursor_x > 79) {
|
||||
// Right of screen reached
|
||||
cursor_x = 0;
|
||||
cursor_y = cursor_y + 1;
|
||||
|
||||
if (cursor_y > 24) {
|
||||
// Bottom of screen reached
|
||||
this->scrollup();
|
||||
cursor_y = cursor_y - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->setpos(cursor_x, cursor_y);
|
||||
|
||||
// TODO: automatic line breaking, automatic scrolling
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@ -175,5 +194,5 @@ unsigned char CGA::attribute(CGA::color bg, CGA::color fg, bool blink) {
|
||||
|
||||
return blink << 7 // B0000000
|
||||
| (bg & 0x7) << 4 // 0HHH0000
|
||||
| (fg & 0xF); // 0000VVVV
|
||||
| (fg & 0xF); // 0000VVVV
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
void CGA_Stream::flush() {
|
||||
print(buffer, pos, attribute(this->color_bg, this->color_fg, this->blink));
|
||||
|
||||
// TODO: Should not be reset like this
|
||||
// Flushing resets attributes
|
||||
this->blink = false;
|
||||
this->color_bg = CGA::BLACK;
|
||||
|
@ -57,6 +57,7 @@ void OutStream::fill_use_char() {
|
||||
this->fill_used++;
|
||||
}
|
||||
void OutStream::flush() {
|
||||
// TODO: Should not be reset like this
|
||||
// Flushing resets fixed width
|
||||
this->base = 10;
|
||||
this->fill_char = ' ';
|
||||
|
@ -14,6 +14,8 @@ void keyboard_demo() {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
kout << "Keyboard Demo: " << endl;
|
||||
|
||||
while (true) {
|
||||
kout << kb.key_hit();
|
||||
kout.flush();
|
||||
|
@ -16,11 +16,9 @@ void text_demo() {
|
||||
kout << "Attribut (GREEN on WHITE): "
|
||||
<< bgc(CGA::WHITE) << fgc(CGA::GREEN) << "GREEN on WHITE" << endl
|
||||
<< "Attribut (WHITE on BLACK): "
|
||||
<< bgc(CGA::BLACK) << fgc(CGA::WHITE) << "WHITE on BLACK" << endl
|
||||
<< endl;
|
||||
<< bgc(CGA::BLACK) << fgc(CGA::WHITE) << "WHITE on BLACK" << endl;
|
||||
|
||||
kout << "Test der Zahlenausgabefunktion:" << endl
|
||||
<< endl
|
||||
<< "| dec | hex | bin |" << endl
|
||||
<< "+-------+-------+-------+" << endl;
|
||||
|
||||
|
Reference in New Issue
Block a user