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 */
|
/* 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
|
char* pos = (char*)(CGA_START + 2 * (x + y * 80)); // cast to char* to make writable
|
||||||
*pos = character;
|
*pos = character;
|
||||||
*(pos + 1) = attrib;
|
*(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 */
|
/* 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);
|
this->getpos(cursor_x, cursor_y);
|
||||||
|
|
||||||
for (unsigned short byte = 0; byte < n; ++byte) {
|
for (unsigned short byte = 0; byte < n; ++byte) {
|
||||||
|
|
||||||
char current = *(string + byte);
|
char current = *(string + byte);
|
||||||
if (current == '\n') {
|
if (current == '\n') {
|
||||||
// TODO: Screen bounds
|
|
||||||
cursor_x = 0;
|
cursor_x = 0;
|
||||||
cursor_y = cursor_y + 1;
|
cursor_y = cursor_y + 1;
|
||||||
|
|
||||||
|
if (cursor_y > 24) {
|
||||||
|
// Bottom of screen reached
|
||||||
|
this->scrollup();
|
||||||
|
cursor_y = cursor_y - 1;
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
} else if (current == '\0') {
|
} else if (current == '\0') {
|
||||||
|
// Don't need to run to end if null terminated
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->show(cursor_x, cursor_y, current, attrib);
|
this->show(cursor_x, cursor_y, current, attrib);
|
||||||
cursor_x = cursor_x + 1;
|
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);
|
this->setpos(cursor_x, cursor_y);
|
||||||
|
|
||||||
// TODO: automatic line breaking, automatic scrolling
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
void CGA_Stream::flush() {
|
void CGA_Stream::flush() {
|
||||||
print(buffer, pos, attribute(this->color_bg, this->color_fg, this->blink));
|
print(buffer, pos, attribute(this->color_bg, this->color_fg, this->blink));
|
||||||
|
|
||||||
|
// TODO: Should not be reset like this
|
||||||
// Flushing resets attributes
|
// Flushing resets attributes
|
||||||
this->blink = false;
|
this->blink = false;
|
||||||
this->color_bg = CGA::BLACK;
|
this->color_bg = CGA::BLACK;
|
||||||
|
|||||||
@ -57,6 +57,7 @@ void OutStream::fill_use_char() {
|
|||||||
this->fill_used++;
|
this->fill_used++;
|
||||||
}
|
}
|
||||||
void OutStream::flush() {
|
void OutStream::flush() {
|
||||||
|
// TODO: Should not be reset like this
|
||||||
// Flushing resets fixed width
|
// Flushing resets fixed width
|
||||||
this->base = 10;
|
this->base = 10;
|
||||||
this->fill_char = ' ';
|
this->fill_char = ' ';
|
||||||
|
|||||||
@ -14,6 +14,8 @@ void keyboard_demo() {
|
|||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
|
kout << "Keyboard Demo: " << endl;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
kout << kb.key_hit();
|
kout << kb.key_hit();
|
||||||
kout.flush();
|
kout.flush();
|
||||||
|
|||||||
@ -16,11 +16,9 @@ void text_demo() {
|
|||||||
kout << "Attribut (GREEN on WHITE): "
|
kout << "Attribut (GREEN on WHITE): "
|
||||||
<< bgc(CGA::WHITE) << fgc(CGA::GREEN) << "GREEN on WHITE" << endl
|
<< bgc(CGA::WHITE) << fgc(CGA::GREEN) << "GREEN on WHITE" << endl
|
||||||
<< "Attribut (WHITE on BLACK): "
|
<< "Attribut (WHITE on BLACK): "
|
||||||
<< bgc(CGA::BLACK) << fgc(CGA::WHITE) << "WHITE on BLACK" << endl
|
<< bgc(CGA::BLACK) << fgc(CGA::WHITE) << "WHITE on BLACK" << endl;
|
||||||
<< endl;
|
|
||||||
|
|
||||||
kout << "Test der Zahlenausgabefunktion:" << endl
|
kout << "Test der Zahlenausgabefunktion:" << endl
|
||||||
<< endl
|
|
||||||
<< "| dec | hex | bin |" << endl
|
<< "| dec | hex | bin |" << endl
|
||||||
<< "+-------+-------+-------+" << endl;
|
<< "+-------+-------+-------+" << endl;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user