cleanup cga
This commit is contained in:
@ -19,7 +19,7 @@
|
|||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* Beschreibung: Setzen des Cursors in Spalte x und Zeile y. *
|
* Beschreibung: Setzen des Cursors in Spalte x und Zeile y. *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void CGA::setpos(int x, int y) {
|
void CGA::setpos(unsigned int x, unsigned int y) {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ void CGA::setpos(int x, int y) {
|
|||||||
* *
|
* *
|
||||||
* Rückgabewerte: x und y *
|
* Rückgabewerte: x und y *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void CGA::getpos(int& x, int& y) const {
|
void CGA::getpos(unsigned int& x, unsigned int& y) const {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ void CGA::getpos(int& x, int& y) const {
|
|||||||
* character Das auszugebende Zeichen *
|
* character Das auszugebende Zeichen *
|
||||||
* attrib Attributbyte fuer das Zeichen *
|
* attrib Attributbyte fuer das Zeichen *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void CGA::show(int x, int y, char character, unsigned char attrib) {
|
void CGA::show(unsigned int x, unsigned int y, char character, unsigned char attrib) {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ void CGA::show(int x, int y, char character, unsigned char attrib) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cga_char_t* pos = (cga_char_t*)CGA_START + x + y * COLUMNS;
|
cga_char_t* pos = reinterpret_cast<cga_char_t*>(CGA_START) + x + y * COLUMNS;
|
||||||
pos->cga_char = character;
|
pos->cga_char = character;
|
||||||
pos->cga_attribute = attrib;
|
pos->cga_attribute = attrib;
|
||||||
}
|
}
|
||||||
@ -95,12 +95,13 @@ void CGA::show(int x, int y, char character, unsigned char attrib) {
|
|||||||
* n Laenger der Zeichenkette *
|
* n Laenger der Zeichenkette *
|
||||||
* attrib Attributbyte fuer alle Zeichen der Zeichenkette *
|
* attrib Attributbyte fuer alle Zeichen der Zeichenkette *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void CGA::print(char* string, int n, unsigned char attrib) {
|
void CGA::print(char* string, unsigned int n, unsigned char attrib) {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
int cursor_x, cursor_y; // Don't poll registers every stroke
|
unsigned int cursor_x = 0;
|
||||||
this->getpos(cursor_x, cursor_y);
|
unsigned int cursor_y = 0; // Don't poll registers every stroke
|
||||||
|
getpos(cursor_x, cursor_y);
|
||||||
|
|
||||||
for (int byte = 0; byte < n; ++byte) {
|
for (int byte = 0; byte < n; ++byte) {
|
||||||
char current = *(string + byte);
|
char current = *(string + byte);
|
||||||
@ -110,7 +111,7 @@ void CGA::print(char* string, int n, unsigned char attrib) {
|
|||||||
|
|
||||||
if (cursor_y >= ROWS) {
|
if (cursor_y >= ROWS) {
|
||||||
// Bottom of screen reached
|
// Bottom of screen reached
|
||||||
this->scrollup();
|
scrollup();
|
||||||
cursor_y = cursor_y - 1;
|
cursor_y = cursor_y - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +123,7 @@ void CGA::print(char* string, int n, unsigned char attrib) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->show(cursor_x, cursor_y, current, attrib);
|
show(cursor_x, cursor_y, current, attrib);
|
||||||
cursor_x = cursor_x + 1;
|
cursor_x = cursor_x + 1;
|
||||||
|
|
||||||
if (cursor_x >= COLUMNS) {
|
if (cursor_x >= COLUMNS) {
|
||||||
@ -132,13 +133,13 @@ void CGA::print(char* string, int n, unsigned char attrib) {
|
|||||||
|
|
||||||
if (cursor_y >= ROWS) {
|
if (cursor_y >= ROWS) {
|
||||||
// Bottom of screen reached
|
// Bottom of screen reached
|
||||||
this->scrollup();
|
scrollup();
|
||||||
cursor_y = cursor_y - 1;
|
cursor_y = cursor_y - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->setpos(cursor_x, cursor_y);
|
setpos(cursor_x, cursor_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -153,10 +154,12 @@ void CGA::scrollup() {
|
|||||||
/* Hier muss Code eingefuegt werden */
|
/* Hier muss Code eingefuegt werden */
|
||||||
|
|
||||||
// Move up
|
// Move up
|
||||||
bse::memcpy<cga_line_t>((cga_line_t*)CGA_START, (cga_line_t*)CGA_START + 1, ROWS - 1);
|
bse::memcpy<cga_line_t>(reinterpret_cast<cga_line_t*>(CGA_START),
|
||||||
|
reinterpret_cast<cga_line_t*>(CGA_START) + 1,
|
||||||
|
ROWS - 1);
|
||||||
|
|
||||||
// Clear last line
|
// Clear last line
|
||||||
bse::zero<cga_line_t>((cga_line_t*)CGA_START + ROWS - 1);
|
bse::zero<cga_line_t>(reinterpret_cast<cga_line_t*>(CGA_START) + ROWS - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -168,8 +171,8 @@ void CGA::clear() {
|
|||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
bse::zero<cga_page_t>((cga_page_t*)CGA_START);
|
bse::zero<cga_page_t>(reinterpret_cast<cga_page_t*>(CGA_START));
|
||||||
this->setpos(0, 0);
|
setpos(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
|||||||
@ -15,23 +15,21 @@
|
|||||||
#define __CGA_include__
|
#define __CGA_include__
|
||||||
|
|
||||||
#include "kernel/IOport.h"
|
#include "kernel/IOport.h"
|
||||||
|
#include "user/lib/Array.h"
|
||||||
|
|
||||||
class CGA {
|
class CGA {
|
||||||
private:
|
private:
|
||||||
IOport index_port; // Auswahl eines Register der Grafikkarte
|
|
||||||
IOport data_port; // Lese-/Schreib-Zugriff auf Register der Grafikk.
|
|
||||||
|
|
||||||
// Copy Konstrutkor unterbinden
|
// Copy Konstrutkor unterbinden
|
||||||
CGA(const CGA& copy) = delete;
|
CGA(const CGA& copy) = delete;
|
||||||
|
|
||||||
|
IOport index_port; // Auswahl eines Register der Grafikkarte
|
||||||
|
IOport data_port; // Lese-/Schreib-Zugriff auf Register der Grafikk.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// NOTE: I change CGA_START to this const because I think the address should be constant and macro-like,
|
|
||||||
// not the data at this address (we want that data to change).
|
|
||||||
static const unsigned int CGA_START = 0xb8000U;
|
static const unsigned int CGA_START = 0xb8000U;
|
||||||
|
|
||||||
// Konstruktur mit Initialisierung der Ports
|
// Konstruktur mit Initialisierung der Ports
|
||||||
CGA() : index_port(0x3d4), data_port(0x3d5) {
|
CGA() : index_port(0x3d4), data_port(0x3d5) {
|
||||||
// NOTE: I added this
|
|
||||||
this->setpos(0, 0);
|
this->setpos(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,29 +60,32 @@ public:
|
|||||||
enum { ROWS = 25,
|
enum { ROWS = 25,
|
||||||
COLUMNS = 80 };
|
COLUMNS = 80 };
|
||||||
|
|
||||||
// NOTE: I added this
|
// Easier access to memory (also easier copying of lines/pages etc)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char cga_char;
|
char cga_char;
|
||||||
unsigned char cga_attribute;
|
unsigned char cga_attribute;
|
||||||
} cga_char_t;
|
} cga_char_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
cga_char_t cga_line[COLUMNS];
|
// Can use these arrays since they don't have memory overhead (except for the methods that are elsewhere)
|
||||||
|
bse::array<cga_char_t, COLUMNS> cga_line;
|
||||||
} cga_line_t;
|
} cga_line_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
cga_line_t cga_page[ROWS];
|
bse::array<cga_line_t, ROWS> cga_page;
|
||||||
} cga_page_t;
|
} cga_page_t;
|
||||||
|
|
||||||
// Setzen des Cursors in Spalte x und Zeile y.
|
// Setzen des Cursors in Spalte x und Zeile y.
|
||||||
void setpos(int x, int y);
|
void setpos(unsigned int x, unsigned int y);
|
||||||
|
|
||||||
// Abfragen der Cursorpostion
|
// Abfragen der Cursorpostion
|
||||||
void getpos(int& x, int& y) const;
|
void getpos(unsigned int& x, unsigned int& y) const;
|
||||||
|
|
||||||
// Anzeige eines Zeichens mit Attribut an einer bestimmten Stelle
|
// Anzeige eines Zeichens mit Attribut an einer bestimmten Stelle
|
||||||
void show(int x, int y, char character, unsigned char attrib = STD_ATTR);
|
static void show(unsigned int x, unsigned int y, char character, unsigned char attrib = STD_ATTR);
|
||||||
|
|
||||||
// Anzeige mehrerer Zeichen ab der aktuellen Cursorposition
|
// Anzeige mehrerer Zeichen ab der aktuellen Cursorposition
|
||||||
virtual void print(char* string, int n, unsigned char attrib = STD_ATTR);
|
virtual void print(char* string, unsigned int n, unsigned char attrib = STD_ATTR);
|
||||||
|
|
||||||
// Verschiebt den Bildschirminhalt um eine Zeile nach oben.
|
// Verschiebt den Bildschirminhalt um eine Zeile nach oben.
|
||||||
// Neue Zeile am unteren Bildrand mit Leerzeichen fuellen
|
// Neue Zeile am unteren Bildrand mit Leerzeichen fuellen
|
||||||
|
|||||||
@ -76,7 +76,7 @@ void PIT::trigger() {
|
|||||||
// Indicator
|
// Indicator
|
||||||
if (systime - this->last_indicator_refresh >= 10) {
|
if (systime - this->last_indicator_refresh >= 10) {
|
||||||
this->indicator_pos = (this->indicator_pos + 1) % 4;
|
this->indicator_pos = (this->indicator_pos + 1) % 4;
|
||||||
kout.show(79, 0, this->indicator[this->indicator_pos]);
|
CGA::show(79, 0, this->indicator[this->indicator_pos]);
|
||||||
this->last_indicator_refresh = systime;
|
this->last_indicator_refresh = systime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user