add attribute support, fg/bg in progress
This commit is contained in:
@ -117,7 +117,6 @@ void CGA::print(char* string, int n, unsigned char attrib) {
|
||||
this->setpos(cursor_x, cursor_y);
|
||||
|
||||
// TODO: automatic line breaking, automatic scrolling
|
||||
// TODO: printing doesn't work after first newline character
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@ -173,4 +172,8 @@ void CGA::clear() {
|
||||
unsigned char CGA::attribute(CGA::color bg, CGA::color fg, bool blink) {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
return blink << 7 // B0000000
|
||||
| (bg & 0x7) << 4 // 0HHH0000
|
||||
| (fg & 0xF); // 0000VVVV
|
||||
}
|
||||
|
@ -24,6 +24,17 @@
|
||||
* verwendet werden, um eine Ausgabe zu erzwingen. *
|
||||
*****************************************************************************/
|
||||
void CGA_Stream::flush() {
|
||||
print(buffer, pos);
|
||||
print(buffer, pos, attribute(this->color_bg, this->color_fg, this->blink));
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
// NOTE: I added this
|
||||
// TODO
|
||||
// CGA_Stream& CGA_Stream::operator<<(const fgc& fg) {
|
||||
// this->color_fg = fg.fg;
|
||||
// return *this;
|
||||
// }
|
||||
// CGA_Stream& CGA_Stream::operator<<(const bgc& bg) {
|
||||
// this->color_bg = bg.bg;
|
||||
// return *this;
|
||||
// }
|
||||
|
@ -18,16 +18,44 @@
|
||||
#include "devices/CGA.h"
|
||||
#include "lib/OutStream.h"
|
||||
|
||||
class CGA_Stream : public OutStream, public CGA {
|
||||
// NOTE: I added this
|
||||
class fgc {
|
||||
public:
|
||||
fgc() : fg(CGA::LIGHT_GREY) {};
|
||||
fgc(CGA::color fg) : fg(fg) {};
|
||||
CGA::color fg;
|
||||
};
|
||||
class bgc {
|
||||
public:
|
||||
bgc() : bg(CGA::BLACK) {};
|
||||
bgc(CGA::color bg) : bg(bg) {};
|
||||
CGA::color bg;
|
||||
};
|
||||
|
||||
class CGA_Stream : public OutStream, public CGA {
|
||||
private:
|
||||
CGA_Stream(CGA_Stream& copy); // Verhindere Kopieren
|
||||
|
||||
public:
|
||||
CGA_Stream() : OutStream(), CGA() { flush(); }
|
||||
CGA::color color_fg;
|
||||
CGA::color color_bg;
|
||||
bool blink;
|
||||
|
||||
CGA_Stream() : OutStream(), CGA() {
|
||||
color_fg = CGA::LIGHT_GREY;
|
||||
color_bg = CGA::BLACK;
|
||||
blink = false;
|
||||
|
||||
flush();
|
||||
}
|
||||
|
||||
// Methode zur Ausgabe des Pufferinhalts der Basisklasse StringBuffer.
|
||||
void flush() override;
|
||||
|
||||
// NOTE: I added this
|
||||
// TODO: Problem: Implementing this here breaks the << chaining
|
||||
// CGA_Stream& operator<<(const fgc&);
|
||||
// CGA_Stream& operator<<(const bgc&);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -24,18 +24,18 @@
|
||||
|
||||
#include "lib/StringBuffer.h"
|
||||
|
||||
// NOTE: I added this, stream manipulator with argument
|
||||
class OutStream;
|
||||
|
||||
// NOTE: I added this
|
||||
// TODO: I should probably put this inside some FormatStream or sth...
|
||||
// TODO: Should this only work for the next << ?
|
||||
class fillw {
|
||||
public:
|
||||
fillw() : w(0) {};
|
||||
fillw(unsigned char w) : w(w) {};
|
||||
unsigned char w;
|
||||
};
|
||||
|
||||
class fillc {
|
||||
public:
|
||||
fillc() : c(' ') {};
|
||||
fillc(char c) : c(c) {};
|
||||
char c;
|
||||
};
|
||||
@ -58,15 +58,16 @@ public:
|
||||
char fill_char; // fill character for fixed width
|
||||
|
||||
OutStream() : StringBuffer() {
|
||||
base = 10; // initial Dezimalsystem
|
||||
fill_width = 0; // no fixed width
|
||||
fill_used = 0;
|
||||
base = 10; // initial Dezimalsystem
|
||||
|
||||
fill_width = 0; // no fixed width
|
||||
fill_char = ' '; // fill with spaces
|
||||
fill_used = 0;
|
||||
}
|
||||
|
||||
void flush() override = 0; // weiterhin undefiniert aber public
|
||||
|
||||
// NOTE: I added this
|
||||
// NOTE: I added this, override put for fixed width
|
||||
void put(char c) override;
|
||||
|
||||
// OPERATOR << : Umwandlung des angegebenen Datentypes in eine
|
||||
@ -90,9 +91,9 @@ public:
|
||||
// Darstellung eines Zeigers als hexadezimale ganze Zahl
|
||||
OutStream& operator<<(void* ptr);
|
||||
|
||||
// NOTE: I added this, set fixed output width
|
||||
OutStream& operator<<(const fillw& w);
|
||||
OutStream& operator<<(const fillc& c);
|
||||
// NOTE: I added this
|
||||
OutStream& operator<<(const fillw&);
|
||||
OutStream& operator<<(const fillc&);
|
||||
|
||||
// Aufruf einer Manipulatorfunktion
|
||||
OutStream& operator<<(OutStream& (*f)(OutStream&));
|
||||
|
@ -13,16 +13,23 @@
|
||||
void text_demo() {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
kout << "Test der Zahlenausgabefunktion:" << endl;
|
||||
kout << endl;
|
||||
kout << "| dec | hex | bin |" << endl;
|
||||
kout << "+-------+-------+-------+" << endl;
|
||||
kout << "Attribut (GREEN on WHITE, blinking): "
|
||||
<< (unsigned short)kout.attribute(CGA::WHITE, CGA::GREEN, true) << endl
|
||||
<< "Attribut (WHITE on BLACK, no blink): "
|
||||
<< (unsigned short)kout.attribute(CGA::BLACK, CGA::WHITE, false) << endl
|
||||
<< endl;
|
||||
|
||||
kout << "Test der Zahlenausgabefunktion:" << endl
|
||||
<< endl
|
||||
<< "| dec | hex | bin |" << endl
|
||||
<< "+-------+-------+-------+" << endl;
|
||||
|
||||
// TODO: should fillw just work for the next << ?
|
||||
for (unsigned short num = 0; num < 17; ++num) {
|
||||
kout << fillw(0) << "| " << fillw(6) << dec << num;
|
||||
kout << fillw(0) << "| " << fillw(6) << hex << num;
|
||||
kout << fillw(0) << "| " << fillw(6) << bin << num;
|
||||
kout << fillw(0) << "|" << endl;
|
||||
kout << fillw(0) << "| " << fillw(6) << dec << num
|
||||
<< fillw(0) << "| " << fillw(6) << hex << num
|
||||
<< fillw(0) << "| " << fillw(6) << bin << num
|
||||
<< fillw(0) << "|" << endl;
|
||||
}
|
||||
|
||||
kout << endl;
|
||||
}
|
||||
|
Reference in New Issue
Block a user