initial reformat, still has misformats
This commit is contained in:
@ -13,13 +13,12 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#include "devices/CGA.h"
|
#include "devices/CGA.h"
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: CGA::setpos *
|
* Methode: CGA::setpos *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* 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(int x, int y) {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
@ -28,15 +27,13 @@ void CGA::setpos (int x, int y) {
|
|||||||
unsigned char cursor_low = pos & 0xFF;
|
unsigned char cursor_low = pos & 0xFF;
|
||||||
unsigned char cursor_high = (pos >> 8) & 0xFF;
|
unsigned char cursor_high = (pos >> 8) & 0xFF;
|
||||||
|
|
||||||
index_port.outb(0xF); // Cursor(low)
|
index_port.outb(0xF); // Cursor(low)
|
||||||
data_port.outb(cursor_low);
|
data_port.outb(cursor_low);
|
||||||
|
|
||||||
index_port.outb(0xE); // Cursor(high)
|
index_port.outb(0xE); // Cursor(high)
|
||||||
data_port.outb(cursor_high);
|
data_port.outb(cursor_high);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: CGA::getpos *
|
* Methode: CGA::getpos *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
@ -44,26 +41,23 @@ void CGA::setpos (int x, int y) {
|
|||||||
* *
|
* *
|
||||||
* Rückgabewerte: x und y *
|
* Rückgabewerte: x und y *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void CGA::getpos (int &x, int &y) {
|
void CGA::getpos(int& x, int& y) {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
index_port.outb(0xF); // Cursor(low)
|
index_port.outb(0xF); // Cursor(low)
|
||||||
unsigned char cursor_low = data_port.inb();
|
unsigned char cursor_low = data_port.inb();
|
||||||
|
|
||||||
index_port.outb(0xE); // Cursor(high)
|
index_port.outb(0xE); // Cursor(high)
|
||||||
unsigned char cursor_high = data_port.inb();
|
unsigned char cursor_high = data_port.inb();
|
||||||
|
|
||||||
unsigned short cursor =
|
unsigned short cursor =
|
||||||
(cursor_low & 0xFF)
|
(cursor_low & 0xFF) | ((cursor_high << 8) & 0xFF00);
|
||||||
| ((cursor_high << 8) & 0xFF00);
|
|
||||||
|
|
||||||
x = cursor % 80;
|
x = cursor % 80;
|
||||||
y = (int)(cursor / 80);
|
y = (int)(cursor / 80);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: CGA::show *
|
* Methode: CGA::show *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
@ -75,19 +69,17 @@ void CGA::getpos (int &x, int &y) {
|
|||||||
* 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(int x, int y, char character, unsigned char attrib) {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
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
|
// TODO: screen border check
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: CGA::print *
|
* Methode: CGA::print *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
@ -99,7 +91,7 @@ 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, int n, unsigned char attrib) {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
@ -126,10 +118,8 @@ void CGA::print (char* string, int n, unsigned char attrib) {
|
|||||||
|
|
||||||
// TODO: automatic line breaking, automatic scrolling
|
// TODO: automatic line breaking, automatic scrolling
|
||||||
// TODO: printing doesn't work after first newline character
|
// TODO: printing doesn't work after first newline character
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: CGA::scrollup *
|
* Methode: CGA::scrollup *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
@ -137,7 +127,7 @@ void CGA::print (char* string, int n, unsigned char attrib) {
|
|||||||
* Die neue Zeile am unteren Bildrand wird mit Leerzeichen *
|
* Die neue Zeile am unteren Bildrand wird mit Leerzeichen *
|
||||||
* gefuellt. *
|
* gefuellt. *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void CGA::scrollup () {
|
void CGA::scrollup() {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
@ -150,16 +140,14 @@ void CGA::scrollup () {
|
|||||||
for (unsigned short byte = 2 * 80 * 24; byte < 2 * 80 * 25; ++byte) {
|
for (unsigned short byte = 2 * 80 * 24; byte < 2 * 80 * 25; ++byte) {
|
||||||
*((char*)(CGA_START + byte)) = '\0';
|
*((char*)(CGA_START + byte)) = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: CGA::clear *
|
* Methode: CGA::clear *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* Beschreibung: Lösche den Textbildschirm. *
|
* Beschreibung: Lösche den Textbildschirm. *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void CGA::clear () {
|
void CGA::clear() {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
@ -168,10 +156,8 @@ void CGA::clear () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->setpos(0, 0);
|
this->setpos(0, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: CGA::attribute *
|
* Methode: CGA::attribute *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
@ -184,8 +170,7 @@ void CGA::clear () {
|
|||||||
* fg Foreground color *
|
* fg Foreground color *
|
||||||
* blink ywa/no *
|
* blink ywa/no *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
unsigned char CGA::attribute (CGA::color bg, CGA::color fg, bool blink) {
|
unsigned char CGA::attribute(CGA::color bg, CGA::color fg, bool blink) {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,60 +17,73 @@
|
|||||||
#include "kernel/IOport.h"
|
#include "kernel/IOport.h"
|
||||||
|
|
||||||
class CGA {
|
class CGA {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IOport index_port; // Auswahl eines Register der Grafikkarte
|
IOport index_port; // Auswahl eines Register der Grafikkarte
|
||||||
IOport data_port; // Lese-/Schreib-Zugriff auf Register der Grafikk.
|
IOport data_port; // Lese-/Schreib-Zugriff auf Register der Grafikk.
|
||||||
|
|
||||||
// Copy Konstrutkor unterbinden
|
// Copy Konstrutkor unterbinden
|
||||||
CGA(const CGA ©);
|
CGA(const CGA& copy);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const char *CGA_START; // Startadresse des Buldschirmspeichers
|
const char* CGA_START; // Startadresse des Buldschirmspeichers
|
||||||
|
|
||||||
// Konstruktur mit Initialisierung der Ports
|
// Konstruktur mit Initialisierung der Ports
|
||||||
CGA () : index_port (0x3d4), data_port (0x3d5) {
|
CGA() : index_port(0x3d4), data_port(0x3d5) {
|
||||||
CGA_START = (const char*)0xb8000;
|
CGA_START = (const char*)0xb8000;
|
||||||
|
|
||||||
// NOTE: I added this
|
// NOTE: I added this
|
||||||
this->setpos(0, 0);
|
this->setpos(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Konstanten fuer die moeglichen Farben im Attribut-Byte.
|
// Konstanten fuer die moeglichen Farben im Attribut-Byte.
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHT_GREY,
|
BLACK,
|
||||||
DARK_GREY, LIGHT_BLUE, LIGHT_GREEN, LIGHT_CYAN, LIGHT_RED,
|
BLUE,
|
||||||
LIGHT_MAGENTA, YELLOW, WHITE
|
GREEN,
|
||||||
|
CYAN,
|
||||||
|
RED,
|
||||||
|
MAGENTA,
|
||||||
|
BROWN,
|
||||||
|
LIGHT_GREY,
|
||||||
|
DARK_GREY,
|
||||||
|
LIGHT_BLUE,
|
||||||
|
LIGHT_GREEN,
|
||||||
|
LIGHT_CYAN,
|
||||||
|
LIGHT_RED,
|
||||||
|
LIGHT_MAGENTA,
|
||||||
|
YELLOW,
|
||||||
|
WHITE
|
||||||
} color;
|
} color;
|
||||||
|
|
||||||
// Standardzeichenfarbe
|
// Standardzeichenfarbe
|
||||||
enum { STD_ATTR = BLACK << 4 | LIGHT_GREY };
|
enum { STD_ATTR = BLACK << 4 | LIGHT_GREY };
|
||||||
|
|
||||||
// Groesse des Bildschirms (25 Zeilen, 80 Spalten)
|
// Groesse des Bildschirms (25 Zeilen, 80 Spalten)
|
||||||
enum { ROWS = 25, COLUMNS = 80 };
|
enum { ROWS = 25,
|
||||||
|
COLUMNS = 80 };
|
||||||
|
|
||||||
// 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(int x, int y);
|
||||||
|
|
||||||
// Abfragen der Cursorpostion
|
// Abfragen der Cursorpostion
|
||||||
void getpos (int& x, int& y);
|
void getpos(int& x, int& y);
|
||||||
|
|
||||||
// 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);
|
void show(int x, int y, char character, unsigned char attrib = STD_ATTR);
|
||||||
|
|
||||||
// Anzeige mehrerer Zeichen ab der aktuellen Cursorposition
|
// Anzeige mehrerer Zeichen ab der aktuellen Cursorposition
|
||||||
void print (char* string, int n, unsigned char attrib = STD_ATTR);
|
void print(char* string, 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
|
||||||
void scrollup ();
|
void scrollup();
|
||||||
|
|
||||||
// Lösche den Textbildschirm
|
// Lösche den Textbildschirm
|
||||||
void clear ();
|
void clear();
|
||||||
|
|
||||||
// Hilfsfunktion zur Erzeugung eines Attribut-Bytes
|
// Hilfsfunktion zur Erzeugung eines Attribut-Bytes
|
||||||
unsigned char attribute (CGA::color bg, CGA::color fg, bool blink);
|
unsigned char attribute(CGA::color bg, CGA::color fg, bool blink);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
#include "devices/CGA_Stream.h"
|
#include "devices/CGA_Stream.h"
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: CGA_Stream::flush *
|
* Methode: CGA_Stream::flush *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
@ -24,8 +23,7 @@
|
|||||||
* sobald der Puffer voll ist, kann aber auch explizit *
|
* sobald der Puffer voll ist, kann aber auch explizit *
|
||||||
* verwendet werden, um eine Ausgabe zu erzwingen. *
|
* verwendet werden, um eine Ausgabe zu erzwingen. *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void CGA_Stream::flush () {
|
void CGA_Stream::flush() {
|
||||||
print (buffer, pos);
|
print(buffer, pos);
|
||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,13 +21,13 @@
|
|||||||
class CGA_Stream : public OutStream, public CGA {
|
class CGA_Stream : public OutStream, public CGA {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CGA_Stream(CGA_Stream ©); // Verhindere Kopieren
|
CGA_Stream(CGA_Stream& copy); // Verhindere Kopieren
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CGA_Stream () : OutStream(), CGA() { flush(); }
|
CGA_Stream() : OutStream(), CGA() { flush(); }
|
||||||
|
|
||||||
// Methode zur Ausgabe des Pufferinhalts der Basisklasse StringBuffer.
|
// Methode zur Ausgabe des Pufferinhalts der Basisklasse StringBuffer.
|
||||||
void flush () override;
|
void flush() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
#include "devices/PCSPK.h"
|
#include "devices/PCSPK.h"
|
||||||
#include "kernel/Globals.h"
|
#include "kernel/Globals.h"
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: PCSPK::play *
|
* Methode: PCSPK::play *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
@ -24,42 +23,39 @@
|
|||||||
* Rückgabewerte: f: Frequenz des Tons *
|
* Rückgabewerte: f: Frequenz des Tons *
|
||||||
* len: Laenge des Tons in ms *
|
* len: Laenge des Tons in ms *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void PCSPK::play (float f, int len) {
|
void PCSPK::play(float f, int len) {
|
||||||
int freq = (int)f;
|
int freq = (int)f;
|
||||||
int cntStart = 1193180 / freq;
|
int cntStart = 1193180 / freq;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
|
||||||
// Zaehler laden
|
// Zaehler laden
|
||||||
control.outb (0xB6); // Zaehler-2 konfigurieren
|
control.outb(0xB6); // Zaehler-2 konfigurieren
|
||||||
data2.outb (cntStart%256); // Zaehler-2 laden (Lobyte)
|
data2.outb(cntStart % 256); // Zaehler-2 laden (Lobyte)
|
||||||
data2.outb (cntStart/256); // Zaehler-2 laden (Hibyte)
|
data2.outb(cntStart / 256); // Zaehler-2 laden (Hibyte)
|
||||||
|
|
||||||
// Lautsprecher einschalten
|
// Lautsprecher einschalten
|
||||||
status = (int)ppi.inb (); // Status-Register des PPI auslesen
|
status = (int)ppi.inb(); // Status-Register des PPI auslesen
|
||||||
ppi.outb ( status|3 ); // Lautpsrecher Einschalten
|
ppi.outb(status | 3); // Lautpsrecher Einschalten
|
||||||
|
|
||||||
// Pause
|
// Pause
|
||||||
delay(len);
|
delay(len);
|
||||||
|
|
||||||
// Lautsprecher ausschalten
|
|
||||||
off ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Lautsprecher ausschalten
|
||||||
|
off();
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: PCSPK::off *
|
* Methode: PCSPK::off *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* Beschreibung: Lautsprecher ausschalten. *
|
* Beschreibung: Lautsprecher ausschalten. *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void PCSPK::off () {
|
void PCSPK::off() {
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
status = (int)ppi.inb (); // Status-Register des PPI auslesen
|
status = (int)ppi.inb(); // Status-Register des PPI auslesen
|
||||||
ppi.outb ( (status>>2)<<2 ); // Lautsprecher ausschalten
|
ppi.outb((status >> 2) << 2); // Lautsprecher ausschalten
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: PCSPK::readCounter *
|
* Methode: PCSPK::readCounter *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
@ -71,13 +67,12 @@ void PCSPK::off () {
|
|||||||
inline unsigned int PCSPK::readCounter() {
|
inline unsigned int PCSPK::readCounter() {
|
||||||
unsigned char lo, hi;
|
unsigned char lo, hi;
|
||||||
|
|
||||||
control.outb (0x0); // Latch Command
|
control.outb(0x0); // Latch Command
|
||||||
lo = data0.inb (); // Lobyte des Counters auslesen
|
lo = data0.inb(); // Lobyte des Counters auslesen
|
||||||
hi = data0.inb (); // Hibyte des Counters auslesen
|
hi = data0.inb(); // Hibyte des Counters auslesen
|
||||||
return (hi << 8) | lo;
|
return (hi << 8) | lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: PCSPK::delay *
|
* Methode: PCSPK::delay *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
@ -85,44 +80,41 @@ inline unsigned int PCSPK::readCounter() {
|
|||||||
* *
|
* *
|
||||||
* Parameter: time (delay in ms) *
|
* Parameter: time (delay in ms) *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
inline void PCSPK::delay (int time) {
|
inline void PCSPK::delay(int time) {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
// 1.19 MHz => 1s for full countdown
|
// 1.19 MHz => 1s for full countdown
|
||||||
unsigned short cntStart = 1193180 / 1000; // 1s / 1000 = 1ms countdown
|
unsigned short cntStart = 1193180 / 1000; // 1s / 1000 = 1ms countdown
|
||||||
|
|
||||||
// 00110000 => 0x30: Counter0, LoByte/HiByte, Mode0, Binary
|
// 00110000 => 0x30: Counter0, LoByte/HiByte, Mode0, Binary
|
||||||
// 00110010 => 0x32: Counter0, LoByte/HiByte, Mode1, Binary
|
// 00110010 => 0x32: Counter0, LoByte/HiByte, Mode1, Binary
|
||||||
// 00110100 => 0x34: Counter0, LoByte/HiByte, Mode2, Binary
|
// 00110100 => 0x34: Counter0, LoByte/HiByte, Mode2, Binary
|
||||||
// 00110110 => 0x36: Counter0, LoByte/HiByte, Mode3, Binary
|
// 00110110 => 0x36: Counter0, LoByte/HiByte, Mode3, Binary
|
||||||
control.outb(0x34); // Zaehler-0 konfigurieren
|
control.outb(0x34); // Zaehler-0 konfigurieren
|
||||||
data0.outb(cntStart & 0xFF); // Zaehler-0 laden (Lobyte)
|
data0.outb(cntStart & 0xFF); // Zaehler-0 laden (Lobyte)
|
||||||
data0.outb(cntStart >> 8); // Zaehler-0 laden (Hibyte)
|
data0.outb(cntStart >> 8); // Zaehler-0 laden (Hibyte)
|
||||||
|
|
||||||
int initial_count, current_count;
|
int initial_count, current_count;
|
||||||
for (int i = 0; i < time; ++i) {
|
for (int i = 0; i < time; ++i) {
|
||||||
initial_count = readCounter();
|
initial_count = readCounter();
|
||||||
while(1) {
|
while (1) {
|
||||||
current_count = readCounter();
|
current_count = readCounter();
|
||||||
|
|
||||||
if (current_count > initial_count) break; // The counter has already been reset
|
if (current_count > initial_count) break; // The counter has already been reset
|
||||||
|
|
||||||
initial_count = current_count;
|
initial_count = current_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: PCSPK::tetris *
|
* Methode: PCSPK::tetris *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* Beschreibung: Tetris Sound, Kévin Rapaille, August 2013 *
|
* Beschreibung: Tetris Sound, Kévin Rapaille, August 2013 *
|
||||||
* https://gist.github.com/XeeX/6220067 *
|
* https://gist.github.com/XeeX/6220067 *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void PCSPK::tetris () {
|
void PCSPK::tetris() {
|
||||||
play(658, 125);
|
play(658, 125);
|
||||||
play(1320, 500);
|
play(1320, 500);
|
||||||
play(990, 250);
|
play(990, 250);
|
||||||
@ -238,10 +230,9 @@ void PCSPK::tetris () {
|
|||||||
play(660, 500);
|
play(660, 500);
|
||||||
play(880, 1000);
|
play(880, 1000);
|
||||||
play(838, 2000);
|
play(838, 2000);
|
||||||
off ();
|
off();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: PCSPK::tetris *
|
* Methode: PCSPK::tetris *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
@ -881,5 +872,5 @@ void PCSPK::aerodynamic() {
|
|||||||
play(880.0, 122);
|
play(880.0, 122);
|
||||||
play(1108.7, 122);
|
play(1108.7, 122);
|
||||||
play(880.0, 122);
|
play(880.0, 122);
|
||||||
off ();
|
off();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,77 +18,75 @@
|
|||||||
#include "kernel/IOport.h"
|
#include "kernel/IOport.h"
|
||||||
|
|
||||||
// Note, Frequenz
|
// Note, Frequenz
|
||||||
#define C0 130.81
|
#define C0 130.81
|
||||||
#define C0X 138.59
|
#define C0X 138.59
|
||||||
#define D0 146.83
|
#define D0 146.83
|
||||||
#define D0X 155.56
|
#define D0X 155.56
|
||||||
#define E0 164.81
|
#define E0 164.81
|
||||||
#define F0 174.61
|
#define F0 174.61
|
||||||
#define F0X 185.00
|
#define F0X 185.00
|
||||||
#define G0 196.00
|
#define G0 196.00
|
||||||
#define G0X 207.65
|
#define G0X 207.65
|
||||||
#define A0 220.00
|
#define A0 220.00
|
||||||
#define A0X 233.08
|
#define A0X 233.08
|
||||||
#define B0 246.94
|
#define B0 246.94
|
||||||
|
|
||||||
#define C1 261.63
|
#define C1 261.63
|
||||||
#define C1X 277.18
|
#define C1X 277.18
|
||||||
#define D1 293.66
|
#define D1 293.66
|
||||||
#define D1X 311.13
|
#define D1X 311.13
|
||||||
#define E1 329.63
|
#define E1 329.63
|
||||||
#define F1 349.23
|
#define F1 349.23
|
||||||
#define F1X 369.99
|
#define F1X 369.99
|
||||||
#define G1 391.00
|
#define G1 391.00
|
||||||
#define G1X 415.30
|
#define G1X 415.30
|
||||||
#define A1 440.00
|
#define A1 440.00
|
||||||
#define A1X 466.16
|
#define A1X 466.16
|
||||||
#define B1 493.88
|
#define B1 493.88
|
||||||
|
|
||||||
#define C2 523.25
|
|
||||||
#define C2X 554.37
|
|
||||||
#define D2 587.33
|
|
||||||
#define D2X 622.25
|
|
||||||
#define E2 659.26
|
|
||||||
#define F2 698.46
|
|
||||||
#define F2X 739.99
|
|
||||||
#define G2 783.99
|
|
||||||
#define G2X 830.61
|
|
||||||
#define A2 880.00
|
|
||||||
#define A2X 923.33
|
|
||||||
#define B2 987.77
|
|
||||||
#define C3 1046.50
|
|
||||||
|
|
||||||
|
#define C2 523.25
|
||||||
|
#define C2X 554.37
|
||||||
|
#define D2 587.33
|
||||||
|
#define D2X 622.25
|
||||||
|
#define E2 659.26
|
||||||
|
#define F2 698.46
|
||||||
|
#define F2X 739.99
|
||||||
|
#define G2 783.99
|
||||||
|
#define G2X 830.61
|
||||||
|
#define A2 880.00
|
||||||
|
#define A2X 923.33
|
||||||
|
#define B2 987.77
|
||||||
|
#define C3 1046.50
|
||||||
|
|
||||||
class PCSPK {
|
class PCSPK {
|
||||||
|
|
||||||
private:
|
|
||||||
IOport control; // Steuerregister (write only)
|
|
||||||
IOport data0; // Zaehler-0 Datenregister (read/write)
|
|
||||||
IOport data2; // Zaehler-2 Datenregister
|
|
||||||
IOport ppi; // Status-Register des PPI
|
|
||||||
|
|
||||||
PCSPK (const PCSPK ©); // Verhindere Kopieren
|
private:
|
||||||
|
IOport control; // Steuerregister (write only)
|
||||||
|
IOport data0; // Zaehler-0 Datenregister (read/write)
|
||||||
|
IOport data2; // Zaehler-2 Datenregister
|
||||||
|
IOport ppi; // Status-Register des PPI
|
||||||
|
|
||||||
|
PCSPK(const PCSPK& copy); // Verhindere Kopieren
|
||||||
|
|
||||||
// Verzoegerung um X ms (in 1ms Schritten; Min. 1ms)
|
// Verzoegerung um X ms (in 1ms Schritten; Min. 1ms)
|
||||||
inline void delay (int time);
|
inline void delay(int time);
|
||||||
|
|
||||||
// Zaehler von PIT Channel 0 auslesen (wird fuer delay benoetigt)
|
// Zaehler von PIT Channel 0 auslesen (wird fuer delay benoetigt)
|
||||||
inline unsigned int readCounter ();
|
inline unsigned int readCounter();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Konstruktor. Initialisieren der Ports.
|
// Konstruktor. Initialisieren der Ports.
|
||||||
PCSPK () : control(0x43), data0(0x40), data2(0x42), ppi(0x61) {}
|
PCSPK() : control(0x43), data0(0x40), data2(0x42), ppi(0x61) {}
|
||||||
|
|
||||||
// Demo Sounds
|
// Demo Sounds
|
||||||
void tetris ();
|
void tetris();
|
||||||
void aerodynamic ();
|
void aerodynamic();
|
||||||
|
|
||||||
// Ton abspielen
|
// Ton abspielen
|
||||||
void play (float f, int len);
|
void play(float f, int len);
|
||||||
|
|
||||||
// Lautsprecher ausschalten
|
// Lautsprecher ausschalten
|
||||||
void off ();
|
void off();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -10,19 +10,19 @@
|
|||||||
#ifndef __CPU_include__
|
#ifndef __CPU_include__
|
||||||
#define __CPU_include__
|
#define __CPU_include__
|
||||||
|
|
||||||
|
|
||||||
class CPU {
|
class CPU {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CPU(const CPU ©); // Verhindere Kopieren
|
CPU(const CPU& copy); // Verhindere Kopieren
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CPU() {}
|
CPU() {}
|
||||||
|
|
||||||
// Time-Stamp-Counter auslesen
|
// Time-Stamp-Counter auslesen
|
||||||
inline unsigned long long int rdtsc() {
|
inline unsigned long long int rdtsc() {
|
||||||
unsigned long long int ret;
|
unsigned long long int ret;
|
||||||
asm volatile ( "rdtsc" : "=A"(ret) );
|
asm volatile("rdtsc"
|
||||||
|
: "=A"(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -10,8 +10,6 @@
|
|||||||
|
|
||||||
#include "kernel/Globals.h"
|
#include "kernel/Globals.h"
|
||||||
|
|
||||||
|
CPU cpu; // CPU-spezifische Funktionen
|
||||||
CPU cpu; // CPU-spezifische Funktionen
|
PCSPK pcspk; // PC-Lautsprecher
|
||||||
PCSPK pcspk; // PC-Lautsprecher
|
CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
||||||
CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
|
||||||
|
|
||||||
|
|||||||
@ -10,12 +10,12 @@
|
|||||||
#ifndef __Globals_include__
|
#ifndef __Globals_include__
|
||||||
#define __Globals_include__
|
#define __Globals_include__
|
||||||
|
|
||||||
#include "kernel/CPU.h"
|
|
||||||
#include "devices/PCSPK.h"
|
|
||||||
#include "devices/CGA_Stream.h"
|
#include "devices/CGA_Stream.h"
|
||||||
|
#include "devices/PCSPK.h"
|
||||||
|
#include "kernel/CPU.h"
|
||||||
|
|
||||||
extern CPU cpu; // CPU-spezifische Funktionen
|
extern CPU cpu; // CPU-spezifische Funktionen
|
||||||
extern PCSPK pcspk; // PC-Lautsprecher
|
extern PCSPK pcspk; // PC-Lautsprecher
|
||||||
extern CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
extern CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -16,7 +16,6 @@
|
|||||||
#ifndef __IOport_include__
|
#ifndef __IOport_include__
|
||||||
#define __IOport_include__
|
#define __IOport_include__
|
||||||
|
|
||||||
|
|
||||||
class IOport {
|
class IOport {
|
||||||
// Kopieren erlaubt!
|
// Kopieren erlaubt!
|
||||||
|
|
||||||
@ -25,50 +24,56 @@ class IOport {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Konstruktor, speichert Port-Adresse
|
// Konstruktor, speichert Port-Adresse
|
||||||
IOport (unsigned short a) : address (a) { };
|
IOport(unsigned short a) : address(a) {};
|
||||||
|
|
||||||
// Byteweise Ausgabe eines Wertes ueber einen I/O-Port.
|
// Byteweise Ausgabe eines Wertes ueber einen I/O-Port.
|
||||||
void outb (unsigned char val) const {
|
void outb(unsigned char val) const {
|
||||||
asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(address) );
|
asm volatile("outb %0, %1"
|
||||||
|
:
|
||||||
|
: "a"(val), "Nd"(address));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wortweise Ausgabe eines Wertes ueber einen I/O-Port.
|
// Wortweise Ausgabe eines Wertes ueber einen I/O-Port.
|
||||||
void outw (unsigned short val) const {
|
void outw(unsigned short val) const {
|
||||||
asm volatile ( "outw %0, %1" : : "a"(val), "Nd"(address) );
|
asm volatile("outw %0, %1"
|
||||||
|
:
|
||||||
|
: "a"(val), "Nd"(address));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 32-Bit Ausgabe eines Wertes ueber einen I/O-Port.
|
// 32-Bit Ausgabe eines Wertes ueber einen I/O-Port.
|
||||||
void outdw (unsigned int val) const {
|
void outdw(unsigned int val) const {
|
||||||
asm volatile ( "outl %0, %1" : : "a"(val), "Nd"(address) );
|
asm volatile("outl %0, %1"
|
||||||
|
:
|
||||||
|
: "a"(val), "Nd"(address));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Byteweises Einlesen eines Wertes ueber einen I/O-Port.
|
// Byteweises Einlesen eines Wertes ueber einen I/O-Port.
|
||||||
unsigned char inb () const {
|
unsigned char inb() const {
|
||||||
unsigned char ret;
|
unsigned char ret;
|
||||||
|
|
||||||
asm volatile ( "inb %1, %0"
|
asm volatile("inb %1, %0"
|
||||||
: "=a"(ret)
|
: "=a"(ret)
|
||||||
: "Nd"(address) );
|
: "Nd"(address));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wortweises Einlesen eines Wertes ueber einen I/O-Port.
|
// Wortweises Einlesen eines Wertes ueber einen I/O-Port.
|
||||||
unsigned short inw () const {
|
unsigned short inw() const {
|
||||||
unsigned short ret;
|
unsigned short ret;
|
||||||
|
|
||||||
asm volatile ( "inw %1, %0"
|
asm volatile("inw %1, %0"
|
||||||
: "=a"(ret)
|
: "=a"(ret)
|
||||||
: "Nd"(address) );
|
: "Nd"(address));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 32-Bit Einlesen eines Wertes ueber einen I/O-Port.
|
// 32-Bit Einlesen eines Wertes ueber einen I/O-Port.
|
||||||
unsigned int indw () const {
|
unsigned int indw() const {
|
||||||
unsigned int ret;
|
unsigned int ret;
|
||||||
|
|
||||||
asm volatile ( "inl %1, %0"
|
asm volatile("inl %1, %0"
|
||||||
: "=a"(ret)
|
: "=a"(ret)
|
||||||
: "Nd"(address) );
|
: "Nd"(address));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -11,11 +11,8 @@
|
|||||||
* Autor: Michael Schoettner, 30.7.16 *
|
* Autor: Michael Schoettner, 30.7.16 *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
extern "C" void int_disp(unsigned int slot);
|
||||||
extern "C" void int_disp (unsigned int slot);
|
|
||||||
|
|
||||||
|
|
||||||
// Low-Level Interrupt-Behandlung. (Die Funktion wird spaeter noch erweitert)
|
// Low-Level Interrupt-Behandlung. (Die Funktion wird spaeter noch erweitert)
|
||||||
void int_disp (unsigned int slot) {
|
void int_disp(unsigned int slot) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,11 +23,11 @@
|
|||||||
#include "lib/OutStream.h"
|
#include "lib/OutStream.h"
|
||||||
|
|
||||||
// NOTE: I added this, stream manipulators with arg
|
// NOTE: I added this, stream manipulators with arg
|
||||||
OutStream& OutStream::operator << (const fillw& w) {
|
OutStream& OutStream::operator<<(const fillw& w) {
|
||||||
this->fill_width = w.w;
|
this->fill_width = w.w;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
OutStream& OutStream::operator << (const fillc& c) {
|
OutStream& OutStream::operator<<(const fillc& c) {
|
||||||
this->fill_char = c.c;
|
this->fill_char = c.c;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -70,27 +70,27 @@ void OutStream::fill_use_char() {
|
|||||||
//
|
//
|
||||||
// Zeichen und Zeichenketten in Stream ausgeben
|
// Zeichen und Zeichenketten in Stream ausgeben
|
||||||
//
|
//
|
||||||
OutStream& OutStream::operator << (char c) {
|
OutStream& OutStream::operator<<(char c) {
|
||||||
put(c);
|
put(c);
|
||||||
if (c != '\n') {
|
if (c != '\n') {
|
||||||
// endl() doesn't has access to StringBuffer::put(), so ignore \n here
|
// endl() doesn't has access to StringBuffer::put(), so ignore \n here
|
||||||
this->fill_finalize(); // NOTE: I added this
|
this->fill_finalize(); // NOTE: I added this
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: shouldn't this be printed as number?
|
// TODO: shouldn't this be printed as number?
|
||||||
OutStream& OutStream::operator << (unsigned char c) {
|
OutStream& OutStream::operator<<(unsigned char c) {
|
||||||
return *this << (char) c;
|
return *this << (char)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutStream& OutStream::operator << (char* string) {
|
OutStream& OutStream::operator<<(char* string) {
|
||||||
char* pos = string;
|
char* pos = string;
|
||||||
while (*pos) {
|
while (*pos) {
|
||||||
put (*pos);
|
put(*pos);
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
this->fill_finalize(); // NOTE: I added this
|
this->fill_finalize(); // NOTE: I added this
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,74 +98,75 @@ OutStream& OutStream::operator << (char* string) {
|
|||||||
// Ganzer Zahlen im Zahlensystem zur Basis base in Stream ausgeveb
|
// Ganzer Zahlen im Zahlensystem zur Basis base in Stream ausgeveb
|
||||||
// Alle vorzeichenbehafteten Datentypen werden als long dargestellt,
|
// Alle vorzeichenbehafteten Datentypen werden als long dargestellt,
|
||||||
// Alle vorzeichenlosen als unsigned long.
|
// Alle vorzeichenlosen als unsigned long.
|
||||||
OutStream& OutStream::operator << (short ival) {
|
OutStream& OutStream::operator<<(short ival) {
|
||||||
return *this << (long) ival;
|
return *this << (long)ival;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutStream& OutStream::operator << (unsigned short ival) {
|
OutStream& OutStream::operator<<(unsigned short ival) {
|
||||||
return *this << (unsigned long) ival;
|
return *this << (unsigned long)ival;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutStream& OutStream::operator << (int ival) {
|
OutStream& OutStream::operator<<(int ival) {
|
||||||
return *this << (long) ival;
|
return *this << (long)ival;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutStream& OutStream::operator << (unsigned int ival) {
|
OutStream& OutStream::operator<<(unsigned int ival) {
|
||||||
return *this << (unsigned long) ival;
|
return *this << (unsigned long)ival;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Darstellung eine vorzeichenbehafteten ganzen Zahl.
|
// Darstellung eine vorzeichenbehafteten ganzen Zahl.
|
||||||
OutStream& OutStream::operator << (long ival) {
|
OutStream& OutStream::operator<<(long ival) {
|
||||||
// Bei negativen Werten wird ein Minuszeichen ausgegeben.
|
// Bei negativen Werten wird ein Minuszeichen ausgegeben.
|
||||||
if (ival < 0) {
|
if (ival < 0) {
|
||||||
put ('-');
|
put('-');
|
||||||
ival = -ival;
|
ival = -ival;
|
||||||
}
|
}
|
||||||
// Dann wird der Absolutwert als vorzeichenlose Zahl ausgegeben.
|
// Dann wird der Absolutwert als vorzeichenlose Zahl ausgegeben.
|
||||||
return *this << (unsigned long) ival;
|
return *this << (unsigned long)ival;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Darstellung einer vorzeichenlosen ganzen Zahl.
|
// Darstellung einer vorzeichenlosen ganzen Zahl.
|
||||||
OutStream& OutStream::operator << (unsigned long ival) {
|
OutStream& OutStream::operator<<(unsigned long ival) {
|
||||||
unsigned long div;
|
unsigned long div;
|
||||||
char digit;
|
char digit;
|
||||||
|
|
||||||
if (base == 8) {
|
if (base == 8) {
|
||||||
put ('0'); // oktale Zahlen erhalten eine fuehrende Null
|
put('0'); // oktale Zahlen erhalten eine fuehrende Null
|
||||||
} else if (base == 16) {
|
} else if (base == 16) {
|
||||||
put ('0'); // hexadezimale Zahlen ein "0x"
|
put('0'); // hexadezimale Zahlen ein "0x"
|
||||||
put ('x');
|
put('x');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bestimmung der groessten Potenz der gewaehlten Zahlenbasis, die
|
// Bestimmung der groessten Potenz der gewaehlten Zahlenbasis, die
|
||||||
// noch kleiner als die darzustellende Zahl ist.
|
// noch kleiner als die darzustellende Zahl ist.
|
||||||
for (div = 1; ival/div >= (unsigned long) base; div *= base);
|
for (div = 1; ival / div >= (unsigned long)base; div *= base)
|
||||||
|
;
|
||||||
|
|
||||||
// ziffernweise Ausgabe der Zahl
|
// ziffernweise Ausgabe der Zahl
|
||||||
for (; div > 0; div /= (unsigned long) base) {
|
for (; div > 0; div /= (unsigned long)base) {
|
||||||
digit = ival / div;
|
digit = ival / div;
|
||||||
if (digit < 10) {
|
if (digit < 10) {
|
||||||
put ('0' + digit);
|
put('0' + digit);
|
||||||
} else {
|
} else {
|
||||||
put ('a' + digit - 10);
|
put('a' + digit - 10);
|
||||||
}
|
}
|
||||||
ival %= div;
|
ival %= div;
|
||||||
}
|
}
|
||||||
this->fill_finalize(); // NOTE: I added this
|
this->fill_finalize(); // NOTE: I added this
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Darstellung eines Zeigers als hexadezimale ganze Zahl
|
// Darstellung eines Zeigers als hexadezimale ganze Zahl
|
||||||
OutStream& OutStream::operator << (void* ptr) {
|
OutStream& OutStream::operator<<(void* ptr) {
|
||||||
int oldbase = base;
|
int oldbase = base;
|
||||||
base = 16;
|
base = 16;
|
||||||
*this << (unsigned long) ptr;
|
*this << (unsigned long)ptr;
|
||||||
base = oldbase;
|
base = oldbase;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aufruf einer Manipulatorfunktion
|
// Aufruf einer Manipulatorfunktion
|
||||||
OutStream& OutStream::operator << (OutStream& (*f) (OutStream&)) {
|
OutStream& OutStream::operator<<(OutStream& (*f)(OutStream&)) {
|
||||||
return f(*this);
|
return f(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,33 +181,32 @@ OutStream& OutStream::operator << (OutStream& (*f) (OutStream&)) {
|
|||||||
// zu beeinflussen, z.B durch die Wahl des Zahlensystems.
|
// zu beeinflussen, z.B durch die Wahl des Zahlensystems.
|
||||||
|
|
||||||
// Fuege einen Zeilenumbruch in die Ausgabe ein.
|
// Fuege einen Zeilenumbruch in die Ausgabe ein.
|
||||||
OutStream& endl (OutStream& os) {
|
OutStream& endl(OutStream& os) {
|
||||||
os << '\n';
|
os << '\n';
|
||||||
os.flush();
|
os.flush();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Waehlt das binaere Zahlensystem aus.
|
// Waehlt das binaere Zahlensystem aus.
|
||||||
OutStream& bin (OutStream& os) {
|
OutStream& bin(OutStream& os) {
|
||||||
os.base = 2;
|
os.base = 2;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Waehlt das oktale Zahlensystem aus.
|
// Waehlt das oktale Zahlensystem aus.
|
||||||
OutStream& oct (OutStream& os) {
|
OutStream& oct(OutStream& os) {
|
||||||
os.base = 8;
|
os.base = 8;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Waehlt das dezimale Zahlensystem aus.
|
// Waehlt das dezimale Zahlensystem aus.
|
||||||
OutStream& dec (OutStream& os) {
|
OutStream& dec(OutStream& os) {
|
||||||
os.base = 10;
|
os.base = 10;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Waehlt das hexadezimale Zahlensystem aus.
|
// Waehlt das hexadezimale Zahlensystem aus.
|
||||||
OutStream& hex (OutStream& os) {
|
OutStream& hex(OutStream& os) {
|
||||||
os.base = 16;
|
os.base = 16;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,76 +30,74 @@ class OutStream;
|
|||||||
// TODO: Should this only work for the next << ?
|
// TODO: Should this only work for the next << ?
|
||||||
class fillw {
|
class fillw {
|
||||||
public:
|
public:
|
||||||
fillw(unsigned char w) : w(w) {};
|
fillw(unsigned char w) : w(w) {};
|
||||||
unsigned char w;
|
unsigned char w;
|
||||||
};
|
};
|
||||||
|
|
||||||
class fillc {
|
class fillc {
|
||||||
public:
|
public:
|
||||||
fillc(char c) : c(c) {};
|
fillc(char c) : c(c) {};
|
||||||
char c;
|
char c;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class OutStream : public StringBuffer {
|
class OutStream : public StringBuffer {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OutStream(const OutStream ©); // Verhindere Kopieren
|
OutStream(const OutStream& copy); // Verhindere Kopieren
|
||||||
|
|
||||||
// NOTE: I added this
|
// NOTE: I added this
|
||||||
unsigned char fill_used; // indicates how many characters are already used by the text internally
|
unsigned char fill_used; // indicates how many characters are already used by the text internally
|
||||||
void fill_use_char(); // recognizes that one char from the print width has been used up
|
void fill_use_char(); // recognizes that one char from the print width has been used up
|
||||||
void fill_finalize(); // does the filling after text has been written to buffer
|
void fill_finalize(); // does the filling after text has been written to buffer
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int base; // Basis des Zahlensystems: z.B. 2, 8, 10 oder 16
|
int base; // Basis des Zahlensystems: z.B. 2, 8, 10 oder 16
|
||||||
|
|
||||||
// NOTE: I added this
|
// NOTE: I added this
|
||||||
unsigned char fill_width;
|
unsigned char fill_width;
|
||||||
char fill_char; // fill character for fixed width
|
char fill_char; // fill character for fixed width
|
||||||
|
|
||||||
OutStream () : StringBuffer () {
|
OutStream() : StringBuffer() {
|
||||||
base = 10; // initial Dezimalsystem
|
base = 10; // initial Dezimalsystem
|
||||||
fill_width = 0; // no fixed width
|
fill_width = 0; // no fixed width
|
||||||
fill_used = 0;
|
fill_used = 0;
|
||||||
fill_char = ' '; // fill with spaces
|
fill_char = ' '; // fill with spaces
|
||||||
}
|
}
|
||||||
|
|
||||||
void flush() override = 0; // weiterhin undefiniert aber public
|
void flush() override = 0; // weiterhin undefiniert aber public
|
||||||
|
|
||||||
// NOTE: I added this
|
// NOTE: I added this
|
||||||
void put(char c) override;
|
void put(char c) override;
|
||||||
|
|
||||||
// OPERATOR << : Umwandlung des angegebenen Datentypes in eine
|
// OPERATOR << : Umwandlung des angegebenen Datentypes in eine
|
||||||
// Zeichenkette.
|
// Zeichenkette.
|
||||||
|
|
||||||
// Darstellung eines Zeichens (trivial)
|
// Darstellung eines Zeichens (trivial)
|
||||||
OutStream& operator << (char c);
|
OutStream& operator<<(char c);
|
||||||
OutStream& operator << (unsigned char c);
|
OutStream& operator<<(unsigned char c);
|
||||||
|
|
||||||
// Darstellung einer nullterminierten Zeichenkette
|
// Darstellung einer nullterminierten Zeichenkette
|
||||||
OutStream& operator << (char* string);
|
OutStream& operator<<(char* string);
|
||||||
|
|
||||||
// Darstellung ganzer Zahlen im Zahlensystem zur Basis base
|
// Darstellung ganzer Zahlen im Zahlensystem zur Basis base
|
||||||
OutStream& operator << (short ival);
|
OutStream& operator<<(short ival);
|
||||||
OutStream& operator << (unsigned short ival);
|
OutStream& operator<<(unsigned short ival);
|
||||||
OutStream& operator << (int ival);
|
OutStream& operator<<(int ival);
|
||||||
OutStream& operator << (unsigned int ival);
|
OutStream& operator<<(unsigned int ival);
|
||||||
OutStream& operator << (long ival);
|
OutStream& operator<<(long ival);
|
||||||
OutStream& operator << (unsigned long ival);
|
OutStream& operator<<(unsigned long ival);
|
||||||
|
|
||||||
// Darstellung eines Zeigers als hexadezimale ganze Zahl
|
// Darstellung eines Zeigers als hexadezimale ganze Zahl
|
||||||
OutStream& operator << (void* ptr);
|
OutStream& operator<<(void* ptr);
|
||||||
|
|
||||||
// NOTE: I added this, set fixed output width
|
// NOTE: I added this, set fixed output width
|
||||||
OutStream &operator << (const fillw &w);
|
OutStream& operator<<(const fillw& w);
|
||||||
OutStream &operator << (const fillc &c);
|
OutStream& operator<<(const fillc& c);
|
||||||
|
|
||||||
// Aufruf einer Manipulatorfunktion
|
// Aufruf einer Manipulatorfunktion
|
||||||
OutStream& operator << (OutStream& (*f) (OutStream&));
|
OutStream& operator<<(OutStream& (*f)(OutStream&));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Manipulatorfunktionen
|
// Manipulatorfunktionen
|
||||||
//
|
//
|
||||||
@ -111,18 +109,18 @@ public:
|
|||||||
// zu beeinflussen, z.B durch die Wahl des Zahlensystems.
|
// zu beeinflussen, z.B durch die Wahl des Zahlensystems.
|
||||||
|
|
||||||
// Zeilenumbruch in Ausgabe einfuegen.
|
// Zeilenumbruch in Ausgabe einfuegen.
|
||||||
OutStream& endl (OutStream& os);
|
OutStream& endl(OutStream& os);
|
||||||
|
|
||||||
// Waehle binaeres Zahlensystem aus.
|
// Waehle binaeres Zahlensystem aus.
|
||||||
OutStream& bin (OutStream& os);
|
OutStream& bin(OutStream& os);
|
||||||
|
|
||||||
// Waehle oktales Zahlensystem aus.
|
// Waehle oktales Zahlensystem aus.
|
||||||
OutStream& oct (OutStream& os);
|
OutStream& oct(OutStream& os);
|
||||||
|
|
||||||
// Waehle dezimales Zahlensystem aus.
|
// Waehle dezimales Zahlensystem aus.
|
||||||
OutStream& dec (OutStream& os);
|
OutStream& dec(OutStream& os);
|
||||||
|
|
||||||
// Waehle hexadezimales Zahlensystem aus.
|
// Waehle hexadezimales Zahlensystem aus.
|
||||||
OutStream& hex (OutStream& os);
|
OutStream& hex(OutStream& os);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include "lib/StringBuffer.h"
|
#include "lib/StringBuffer.h"
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: StringBuffer::put *
|
* Methode: StringBuffer::put *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
@ -29,10 +28,9 @@
|
|||||||
* Parameter: *
|
* Parameter: *
|
||||||
* c: Einzufuegendes Zeichen. *
|
* c: Einzufuegendes Zeichen. *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void StringBuffer::put (char c) {
|
void StringBuffer::put(char c) {
|
||||||
buffer[pos] = c;
|
buffer[pos] = c;
|
||||||
pos++;
|
pos++;
|
||||||
if (pos == sizeof (buffer))
|
if (pos == sizeof(buffer))
|
||||||
flush ();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,9 +19,9 @@
|
|||||||
#define __StringBuffer_include__
|
#define __StringBuffer_include__
|
||||||
|
|
||||||
class StringBuffer {
|
class StringBuffer {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StringBuffer(const StringBuffer ©); // Verhindere Kopieren
|
StringBuffer(const StringBuffer& copy); // Verhindere Kopieren
|
||||||
|
|
||||||
// Alle Variablen und Methoden dieser Klasse sind "protected",
|
// Alle Variablen und Methoden dieser Klasse sind "protected",
|
||||||
// da die abgeleiteten Klassen einen direkten Zugriff auf den
|
// da die abgeleiteten Klassen einen direkten Zugriff auf den
|
||||||
@ -34,15 +34,14 @@ protected:
|
|||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
// StringBuffer: Im Konstruktor wird der Puffer als leer markiert.
|
// StringBuffer: Im Konstruktor wird der Puffer als leer markiert.
|
||||||
StringBuffer () : pos(0) {}
|
StringBuffer() : pos(0) {}
|
||||||
|
|
||||||
// NOTE: I changed this
|
// NOTE: I changed this
|
||||||
// Fuegt ein Zeichen in den Puffer ein. Wenn der Puffer
|
// Fuegt ein Zeichen in den Puffer ein. Wenn der Puffer
|
||||||
virtual void put (char c);
|
virtual void put(char c);
|
||||||
|
|
||||||
// Methode zur Ausgabe des Pufferinhalts
|
// Methode zur Ausgabe des Pufferinhalts
|
||||||
virtual void flush () = 0;
|
virtual void flush() = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -11,9 +11,8 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "kernel/Globals.h"
|
#include "kernel/Globals.h"
|
||||||
#include "user/TextDemo.h"
|
|
||||||
#include "user/SoundDemo.h"
|
#include "user/SoundDemo.h"
|
||||||
|
#include "user/TextDemo.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
@ -23,10 +22,10 @@ int main() {
|
|||||||
|
|
||||||
// TODO: Startmeldung ausgeben
|
// TODO: Startmeldung ausgeben
|
||||||
|
|
||||||
|
|
||||||
text_demo();
|
text_demo();
|
||||||
// sound_demo();
|
// sound_demo();
|
||||||
|
|
||||||
while (1);
|
while (1)
|
||||||
|
;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,9 +11,8 @@
|
|||||||
#include "kernel/Globals.h"
|
#include "kernel/Globals.h"
|
||||||
|
|
||||||
void sound_demo() {
|
void sound_demo() {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
pcspk.tetris();
|
pcspk.tetris();
|
||||||
// pcspk.play(440, 1000);
|
// pcspk.play(440, 1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,6 @@
|
|||||||
#ifndef __SoundDemo_include__
|
#ifndef __SoundDemo_include__
|
||||||
#define __SondDemo_include__
|
#define __SondDemo_include__
|
||||||
|
|
||||||
void sound_demo();
|
void sound_demo();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -10,11 +10,11 @@
|
|||||||
|
|
||||||
#include "kernel/Globals.h"
|
#include "kernel/Globals.h"
|
||||||
|
|
||||||
|
|
||||||
void text_demo() {
|
void text_demo() {
|
||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
kout << "Test der Zahlenausgabefunktion:" << endl << endl;
|
kout << "Test der Zahlenausgabefunktion:" << endl;
|
||||||
|
kout << endl;
|
||||||
kout << "| dec | hex | bin |" << endl;
|
kout << "| dec | hex | bin |" << endl;
|
||||||
kout << "+-------+-------+-------+" << endl;
|
kout << "+-------+-------+-------+" << endl;
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,6 @@
|
|||||||
#ifndef __TextDemo_include__
|
#ifndef __TextDemo_include__
|
||||||
#define __TextDemo_include__
|
#define __TextDemo_include__
|
||||||
|
|
||||||
void text_demo();
|
void text_demo();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user