| Zeile 7: | Zeile 7: | ||
Da wir ja schon mit C++ arbeiten, wäre auch etwas OOP angebracht. Deshalb erstellen wir ein Klasse namens Video, die wir in einen Header stecken. Dadurch ist unsere kernel.cpp sehr übersichtlich: | Da wir ja schon mit C++ arbeiten, wäre auch etwas OOP angebracht. Deshalb erstellen wir ein Klasse namens Video, die wir in einen Header stecken. Dadurch ist unsere kernel.cpp sehr übersichtlich: | ||
<cpp> | <cpp> | ||
| − | #include "Video.h" | + | // Einbinden unseres Header |
| + | #include "Video.h" | ||
void main() { | void main() { | ||
| − | + | // Vordergrund schwarz, Hintergrund hellgrau | |
| − | + | screen.color(0x7000); | |
| − | + | ||
| + | // Bildschirm leeren | ||
| + | screen.clear(); | ||
| + | |||
| + | // Textausgabe | ||
| + | screen << "Willkommen im C++-TestKernel!"; | ||
} | } | ||
</cpp> | </cpp> | ||
| Zeile 26: | Zeile 32: | ||
class Video | class Video | ||
{ | { | ||
| − | + | public: | |
| − | + | // Konstruktor | |
| − | + | Video(); | |
| − | + | ||
| − | + | // Destruktor | |
| − | + | ~Video(); | |
| − | + | ||
| − | + | // Leeren des Bildschirms, die Größe beträgt 80x25 Zeichen | |
| − | + | void clear(); | |
| − | + | ||
| − | + | // Textausgabe | |
| − | + | Video& operator << (const char* s); | |
| + | |||
| + | // Ausgabe eines einzelnen Zeichens | ||
| + | void put(char c); | ||
| + | |||
| + | // Setzen der FG/BG-Farben | ||
| + | void color(int color); | ||
| + | |||
| + | private: | ||
| + | // Zeiger auf den Videospeicher | ||
| + | unsigned short* videomem; | ||
| + | |||
| + | // Y-Position der Textausgabe, je volle Zeile +80 | ||
| + | unsigned int off; | ||
| + | |||
| + | // X-Position der Textausgabe, ab Zeilenanfang | ||
| + | unsigned int pos; | ||
| + | |||
| + | // FB/BG-Farbe | ||
| + | unsigned int screen_color; | ||
}; | }; | ||
| − | + | // Globale Instanz der Video-Klasse, Definition in Video.cpp | |
| + | extern Video screen; | ||
#endif | #endif | ||
| Zeile 55: | Zeile 81: | ||
Video::Video(){ | Video::Video(){ | ||
| − | + | // Setzen der Farbe auf Hellgrau auf Schwarz | |
| − | + | screen_color = 0x0700; | |
| − | + | ||
| − | + | // Setzen der Textausgabe auf links oben. | |
| + | pos = 0; | ||
| + | off = 0; | ||
| + | |||
| + | // Startadresse des Videospeichers | ||
| + | videomem = (unsigned short*) 0xb8000; | ||
} | } | ||
| Zeile 65: | Zeile 96: | ||
void Video::clear(){ | void Video::clear(){ | ||
| − | + | // Füllen des Bildschirms mit Leerzeichen | |
| − | + | for(int i = 0;i < (80*25);i++) | |
| − | + | videomem[i] = (unsigned char)' ' | screen_color; | |
| − | + | ||
| − | + | // Zurücksetzen der Textausgabe nach links oben | |
| − | + | pos = 0; | |
| + | off = 0; | ||
} | } | ||
Video& Video::operator << (const char* s){ | Video& Video::operator << (const char* s){ | ||
| − | + | // Für jedes einzelne Zeichen wird put() aufgerufen | |
| − | + | while (*s != '\0') | |
| − | + | put(*s++); | |
| − | + | ||
| + | return *this; | ||
} | } | ||
void Video::put(char c){ | void Video::put(char c){ | ||
| − | + | // Wenn die Textausgabe den rechten... | |
| − | + | if(pos >= 80){ | |
| − | + | pos = 0; | |
| − | + | off += 80; | |
| − | + | } | |
| − | + | ||
| − | + | // ...oder den unteren Bildschirmrand erreicht, gibt es | |
| − | + | // einen Umbruch bzw. es wird aufgeräumt. | |
| − | + | if(off >= (80*25)) | |
| + | clear(); | ||
| + | |||
| + | // Setzen des Zeichens und der Farbe in den Videospeicher | ||
| + | videomem[off + pos] = (unsigned char)c | screen_color; | ||
| + | pos++; | ||
} | } | ||
void Video::color(int color){ | void Video::color(int color){ | ||
| − | + | screen_color = color; | |
} | } | ||
</cpp> | </cpp> | ||