initial reformat, still has misformats
This commit is contained in:
@ -13,13 +13,12 @@
|
||||
*****************************************************************************/
|
||||
#include "devices/CGA.h"
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: CGA::setpos *
|
||||
*---------------------------------------------------------------------------*
|
||||
* 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 */
|
||||
|
||||
@ -28,15 +27,13 @@ void CGA::setpos (int x, int y) {
|
||||
unsigned char cursor_low = pos & 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);
|
||||
|
||||
index_port.outb(0xE); // Cursor(high)
|
||||
index_port.outb(0xE); // Cursor(high)
|
||||
data_port.outb(cursor_high);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: CGA::getpos *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -44,26 +41,23 @@ void CGA::setpos (int x, int 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 */
|
||||
|
||||
index_port.outb(0xF); // Cursor(low)
|
||||
index_port.outb(0xF); // Cursor(low)
|
||||
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 short cursor =
|
||||
(cursor_low & 0xFF)
|
||||
| ((cursor_high << 8) & 0xFF00);
|
||||
(cursor_low & 0xFF) | ((cursor_high << 8) & 0xFF00);
|
||||
|
||||
x = cursor % 80;
|
||||
y = (int)(cursor / 80);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: CGA::show *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -75,19 +69,17 @@ void CGA::getpos (int &x, int &y) {
|
||||
* character Das auszugebende 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 */
|
||||
|
||||
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 + 1) = attrib;
|
||||
|
||||
// TODO: screen border check
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: CGA::print *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -99,7 +91,7 @@ void CGA::show (int x, int y, char character, unsigned char attrib) {
|
||||
* n Laenger 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 */
|
||||
|
||||
@ -126,10 +118,8 @@ void CGA::print (char* string, int n, unsigned char attrib) {
|
||||
|
||||
// TODO: automatic line breaking, automatic scrolling
|
||||
// TODO: printing doesn't work after first newline character
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* 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 *
|
||||
* gefuellt. *
|
||||
*****************************************************************************/
|
||||
void CGA::scrollup () {
|
||||
void CGA::scrollup() {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
@ -150,16 +140,14 @@ void CGA::scrollup () {
|
||||
for (unsigned short byte = 2 * 80 * 24; byte < 2 * 80 * 25; ++byte) {
|
||||
*((char*)(CGA_START + byte)) = '\0';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: CGA::clear *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Lösche den Textbildschirm. *
|
||||
*****************************************************************************/
|
||||
void CGA::clear () {
|
||||
void CGA::clear() {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
@ -168,10 +156,8 @@ void CGA::clear () {
|
||||
}
|
||||
|
||||
this->setpos(0, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: CGA::attribute *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -184,8 +170,7 @@ void CGA::clear () {
|
||||
* fg Foreground color *
|
||||
* 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 */
|
||||
|
||||
}
|
||||
|
||||
@ -17,60 +17,73 @@
|
||||
#include "kernel/IOport.h"
|
||||
|
||||
class CGA {
|
||||
|
||||
|
||||
private:
|
||||
IOport index_port; // Auswahl eines Register der Grafikkarte
|
||||
IOport data_port; // Lese-/Schreib-Zugriff auf Register der Grafikk.
|
||||
|
||||
IOport index_port; // Auswahl eines Register der Grafikkarte
|
||||
IOport data_port; // Lese-/Schreib-Zugriff auf Register der Grafikk.
|
||||
|
||||
// Copy Konstrutkor unterbinden
|
||||
CGA(const CGA ©);
|
||||
|
||||
CGA(const CGA& copy);
|
||||
|
||||
public:
|
||||
const char *CGA_START; // Startadresse des Buldschirmspeichers
|
||||
|
||||
const char* CGA_START; // Startadresse des Buldschirmspeichers
|
||||
|
||||
// Konstruktur mit Initialisierung der Ports
|
||||
CGA () : index_port (0x3d4), data_port (0x3d5) {
|
||||
CGA() : index_port(0x3d4), data_port(0x3d5) {
|
||||
CGA_START = (const char*)0xb8000;
|
||||
|
||||
// NOTE: I added this
|
||||
this->setpos(0, 0);
|
||||
}
|
||||
|
||||
|
||||
// Konstanten fuer die moeglichen Farben im Attribut-Byte.
|
||||
typedef enum {
|
||||
BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHT_GREY,
|
||||
DARK_GREY, LIGHT_BLUE, LIGHT_GREEN, LIGHT_CYAN, LIGHT_RED,
|
||||
LIGHT_MAGENTA, YELLOW, WHITE
|
||||
BLACK,
|
||||
BLUE,
|
||||
GREEN,
|
||||
CYAN,
|
||||
RED,
|
||||
MAGENTA,
|
||||
BROWN,
|
||||
LIGHT_GREY,
|
||||
DARK_GREY,
|
||||
LIGHT_BLUE,
|
||||
LIGHT_GREEN,
|
||||
LIGHT_CYAN,
|
||||
LIGHT_RED,
|
||||
LIGHT_MAGENTA,
|
||||
YELLOW,
|
||||
WHITE
|
||||
} color;
|
||||
|
||||
|
||||
// Standardzeichenfarbe
|
||||
enum { STD_ATTR = BLACK << 4 | LIGHT_GREY };
|
||||
|
||||
|
||||
// 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.
|
||||
void setpos (int x, int y);
|
||||
|
||||
void setpos(int x, int y);
|
||||
|
||||
// Abfragen der Cursorpostion
|
||||
void getpos (int& x, int& y);
|
||||
|
||||
void getpos(int& x, int& y);
|
||||
|
||||
// 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
|
||||
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.
|
||||
// Neue Zeile am unteren Bildrand mit Leerzeichen fuellen
|
||||
void scrollup ();
|
||||
|
||||
void scrollup();
|
||||
|
||||
// Lösche den Textbildschirm
|
||||
void clear ();
|
||||
|
||||
void clear();
|
||||
|
||||
// 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
|
||||
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
|
||||
#include "devices/CGA_Stream.h"
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: CGA_Stream::flush *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -24,8 +23,7 @@
|
||||
* sobald der Puffer voll ist, kann aber auch explizit *
|
||||
* verwendet werden, um eine Ausgabe zu erzwingen. *
|
||||
*****************************************************************************/
|
||||
void CGA_Stream::flush () {
|
||||
print (buffer, pos);
|
||||
void CGA_Stream::flush() {
|
||||
print(buffer, pos);
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -21,13 +21,13 @@
|
||||
class CGA_Stream : public OutStream, public CGA {
|
||||
|
||||
private:
|
||||
CGA_Stream(CGA_Stream ©); // Verhindere Kopieren
|
||||
CGA_Stream(CGA_Stream& copy); // Verhindere Kopieren
|
||||
|
||||
public:
|
||||
CGA_Stream () : OutStream(), CGA() { flush(); }
|
||||
CGA_Stream() : OutStream(), CGA() { flush(); }
|
||||
|
||||
// Methode zur Ausgabe des Pufferinhalts der Basisklasse StringBuffer.
|
||||
void flush () override;
|
||||
void flush() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
#include "devices/PCSPK.h"
|
||||
#include "kernel/Globals.h"
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: PCSPK::play *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -24,42 +23,39 @@
|
||||
* Rückgabewerte: f: Frequenz des Tons *
|
||||
* 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 cntStart = 1193180 / freq;
|
||||
int cntStart = 1193180 / freq;
|
||||
int status;
|
||||
|
||||
|
||||
|
||||
// Zaehler laden
|
||||
control.outb (0xB6); // Zaehler-2 konfigurieren
|
||||
data2.outb (cntStart%256); // Zaehler-2 laden (Lobyte)
|
||||
data2.outb (cntStart/256); // Zaehler-2 laden (Hibyte)
|
||||
control.outb(0xB6); // Zaehler-2 konfigurieren
|
||||
data2.outb(cntStart % 256); // Zaehler-2 laden (Lobyte)
|
||||
data2.outb(cntStart / 256); // Zaehler-2 laden (Hibyte)
|
||||
|
||||
// Lautsprecher einschalten
|
||||
status = (int)ppi.inb (); // Status-Register des PPI auslesen
|
||||
ppi.outb ( status|3 ); // Lautpsrecher Einschalten
|
||||
status = (int)ppi.inb(); // Status-Register des PPI auslesen
|
||||
ppi.outb(status | 3); // Lautpsrecher Einschalten
|
||||
|
||||
// Pause
|
||||
delay(len);
|
||||
|
||||
// Lautsprecher ausschalten
|
||||
off ();
|
||||
}
|
||||
|
||||
// Lautsprecher ausschalten
|
||||
off();
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: PCSPK::off *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Lautsprecher ausschalten. *
|
||||
*****************************************************************************/
|
||||
void PCSPK::off () {
|
||||
void PCSPK::off() {
|
||||
int status;
|
||||
|
||||
status = (int)ppi.inb (); // Status-Register des PPI auslesen
|
||||
ppi.outb ( (status>>2)<<2 ); // Lautsprecher ausschalten
|
||||
status = (int)ppi.inb(); // Status-Register des PPI auslesen
|
||||
ppi.outb((status >> 2) << 2); // Lautsprecher ausschalten
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: PCSPK::readCounter *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -71,13 +67,12 @@ void PCSPK::off () {
|
||||
inline unsigned int PCSPK::readCounter() {
|
||||
unsigned char lo, hi;
|
||||
|
||||
control.outb (0x0); // Latch Command
|
||||
lo = data0.inb (); // Lobyte des Counters auslesen
|
||||
hi = data0.inb (); // Hibyte des Counters auslesen
|
||||
control.outb(0x0); // Latch Command
|
||||
lo = data0.inb(); // Lobyte des Counters auslesen
|
||||
hi = data0.inb(); // Hibyte des Counters auslesen
|
||||
return (hi << 8) | lo;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: PCSPK::delay *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -85,44 +80,41 @@ inline unsigned int PCSPK::readCounter() {
|
||||
* *
|
||||
* Parameter: time (delay in ms) *
|
||||
*****************************************************************************/
|
||||
inline void PCSPK::delay (int time) {
|
||||
inline void PCSPK::delay(int time) {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
// 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
|
||||
// 00110010 => 0x32: Counter0, LoByte/HiByte, Mode1, Binary
|
||||
// 00110100 => 0x34: Counter0, LoByte/HiByte, Mode2, Binary
|
||||
// 00110110 => 0x36: Counter0, LoByte/HiByte, Mode3, Binary
|
||||
control.outb(0x34); // Zaehler-0 konfigurieren
|
||||
data0.outb(cntStart & 0xFF); // Zaehler-0 laden (Lobyte)
|
||||
data0.outb(cntStart >> 8); // Zaehler-0 laden (Hibyte)
|
||||
control.outb(0x34); // Zaehler-0 konfigurieren
|
||||
data0.outb(cntStart & 0xFF); // Zaehler-0 laden (Lobyte)
|
||||
data0.outb(cntStart >> 8); // Zaehler-0 laden (Hibyte)
|
||||
|
||||
int initial_count, current_count;
|
||||
for (int i = 0; i < time; ++i) {
|
||||
initial_count = readCounter();
|
||||
while(1) {
|
||||
while (1) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: PCSPK::tetris *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Tetris Sound, Kévin Rapaille, August 2013 *
|
||||
* https://gist.github.com/XeeX/6220067 *
|
||||
*****************************************************************************/
|
||||
void PCSPK::tetris () {
|
||||
void PCSPK::tetris() {
|
||||
play(658, 125);
|
||||
play(1320, 500);
|
||||
play(990, 250);
|
||||
@ -238,10 +230,9 @@ void PCSPK::tetris () {
|
||||
play(660, 500);
|
||||
play(880, 1000);
|
||||
play(838, 2000);
|
||||
off ();
|
||||
off();
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: PCSPK::tetris *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -881,5 +872,5 @@ void PCSPK::aerodynamic() {
|
||||
play(880.0, 122);
|
||||
play(1108.7, 122);
|
||||
play(880.0, 122);
|
||||
off ();
|
||||
off();
|
||||
}
|
||||
|
||||
@ -18,77 +18,75 @@
|
||||
#include "kernel/IOport.h"
|
||||
|
||||
// Note, Frequenz
|
||||
#define C0 130.81
|
||||
#define C0X 138.59
|
||||
#define D0 146.83
|
||||
#define D0X 155.56
|
||||
#define E0 164.81
|
||||
#define F0 174.61
|
||||
#define F0X 185.00
|
||||
#define G0 196.00
|
||||
#define G0X 207.65
|
||||
#define A0 220.00
|
||||
#define A0X 233.08
|
||||
#define B0 246.94
|
||||
#define C0 130.81
|
||||
#define C0X 138.59
|
||||
#define D0 146.83
|
||||
#define D0X 155.56
|
||||
#define E0 164.81
|
||||
#define F0 174.61
|
||||
#define F0X 185.00
|
||||
#define G0 196.00
|
||||
#define G0X 207.65
|
||||
#define A0 220.00
|
||||
#define A0X 233.08
|
||||
#define B0 246.94
|
||||
|
||||
#define C1 261.63
|
||||
#define C1X 277.18
|
||||
#define D1 293.66
|
||||
#define D1X 311.13
|
||||
#define E1 329.63
|
||||
#define F1 349.23
|
||||
#define F1X 369.99
|
||||
#define G1 391.00
|
||||
#define G1X 415.30
|
||||
#define A1 440.00
|
||||
#define A1X 466.16
|
||||
#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 C1 261.63
|
||||
#define C1X 277.18
|
||||
#define D1 293.66
|
||||
#define D1X 311.13
|
||||
#define E1 329.63
|
||||
#define F1 349.23
|
||||
#define F1X 369.99
|
||||
#define G1 391.00
|
||||
#define G1X 415.30
|
||||
#define A1 440.00
|
||||
#define A1X 466.16
|
||||
#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
|
||||
|
||||
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)
|
||||
inline void delay (int time);
|
||||
|
||||
inline void delay(int time);
|
||||
|
||||
// Zaehler von PIT Channel 0 auslesen (wird fuer delay benoetigt)
|
||||
inline unsigned int readCounter ();
|
||||
inline unsigned int readCounter();
|
||||
|
||||
public:
|
||||
|
||||
// Konstruktor. Initialisieren der Ports.
|
||||
PCSPK () : control(0x43), data0(0x40), data2(0x42), ppi(0x61) {}
|
||||
|
||||
PCSPK() : control(0x43), data0(0x40), data2(0x42), ppi(0x61) {}
|
||||
|
||||
// Demo Sounds
|
||||
void tetris ();
|
||||
void aerodynamic ();
|
||||
void tetris();
|
||||
void aerodynamic();
|
||||
|
||||
// Ton abspielen
|
||||
void play (float f, int len);
|
||||
|
||||
void play(float f, int len);
|
||||
|
||||
// Lautsprecher ausschalten
|
||||
void off ();
|
||||
void off();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user