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
|
||||
|
@ -10,19 +10,19 @@
|
||||
#ifndef __CPU_include__
|
||||
#define __CPU_include__
|
||||
|
||||
|
||||
class CPU {
|
||||
|
||||
|
||||
private:
|
||||
CPU(const CPU ©); // Verhindere Kopieren
|
||||
CPU(const CPU& copy); // Verhindere Kopieren
|
||||
|
||||
public:
|
||||
CPU() {}
|
||||
|
||||
|
||||
// Time-Stamp-Counter auslesen
|
||||
inline unsigned long long int rdtsc() {
|
||||
unsigned long long int ret;
|
||||
asm volatile ( "rdtsc" : "=A"(ret) );
|
||||
unsigned long long int ret;
|
||||
asm volatile("rdtsc"
|
||||
: "=A"(ret));
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
@ -10,8 +10,6 @@
|
||||
|
||||
#include "kernel/Globals.h"
|
||||
|
||||
|
||||
CPU cpu; // CPU-spezifische Funktionen
|
||||
PCSPK pcspk; // PC-Lautsprecher
|
||||
CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
||||
|
||||
CPU cpu; // CPU-spezifische Funktionen
|
||||
PCSPK pcspk; // PC-Lautsprecher
|
||||
CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
||||
|
@ -10,12 +10,12 @@
|
||||
#ifndef __Globals_include__
|
||||
#define __Globals_include__
|
||||
|
||||
#include "kernel/CPU.h"
|
||||
#include "devices/PCSPK.h"
|
||||
#include "devices/CGA_Stream.h"
|
||||
#include "devices/PCSPK.h"
|
||||
#include "kernel/CPU.h"
|
||||
|
||||
extern CPU cpu; // CPU-spezifische Funktionen
|
||||
extern PCSPK pcspk; // PC-Lautsprecher
|
||||
extern CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
||||
extern CPU cpu; // CPU-spezifische Funktionen
|
||||
extern PCSPK pcspk; // PC-Lautsprecher
|
||||
extern CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
||||
|
||||
#endif
|
||||
|
@ -16,7 +16,6 @@
|
||||
#ifndef __IOport_include__
|
||||
#define __IOport_include__
|
||||
|
||||
|
||||
class IOport {
|
||||
// Kopieren erlaubt!
|
||||
|
||||
@ -25,50 +24,56 @@ class IOport {
|
||||
|
||||
public:
|
||||
// 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.
|
||||
void outb (unsigned char val) const {
|
||||
asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(address) );
|
||||
void outb(unsigned char val) const {
|
||||
asm volatile("outb %0, %1"
|
||||
:
|
||||
: "a"(val), "Nd"(address));
|
||||
}
|
||||
|
||||
// Wortweise Ausgabe eines Wertes ueber einen I/O-Port.
|
||||
void outw (unsigned short val) const {
|
||||
asm volatile ( "outw %0, %1" : : "a"(val), "Nd"(address) );
|
||||
void outw(unsigned short val) const {
|
||||
asm volatile("outw %0, %1"
|
||||
:
|
||||
: "a"(val), "Nd"(address));
|
||||
}
|
||||
|
||||
// 32-Bit Ausgabe eines Wertes ueber einen I/O-Port.
|
||||
void outdw (unsigned int val) const {
|
||||
asm volatile ( "outl %0, %1" : : "a"(val), "Nd"(address) );
|
||||
void outdw(unsigned int val) const {
|
||||
asm volatile("outl %0, %1"
|
||||
:
|
||||
: "a"(val), "Nd"(address));
|
||||
}
|
||||
|
||||
// Byteweises Einlesen eines Wertes ueber einen I/O-Port.
|
||||
unsigned char inb () const {
|
||||
unsigned char inb() const {
|
||||
unsigned char ret;
|
||||
|
||||
asm volatile ( "inb %1, %0"
|
||||
: "=a"(ret)
|
||||
: "Nd"(address) );
|
||||
asm volatile("inb %1, %0"
|
||||
: "=a"(ret)
|
||||
: "Nd"(address));
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Wortweises Einlesen eines Wertes ueber einen I/O-Port.
|
||||
unsigned short inw () const {
|
||||
unsigned short inw() const {
|
||||
unsigned short ret;
|
||||
|
||||
asm volatile ( "inw %1, %0"
|
||||
: "=a"(ret)
|
||||
: "Nd"(address) );
|
||||
asm volatile("inw %1, %0"
|
||||
: "=a"(ret)
|
||||
: "Nd"(address));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// 32-Bit Einlesen eines Wertes ueber einen I/O-Port.
|
||||
unsigned int indw () const {
|
||||
unsigned int indw() const {
|
||||
unsigned int ret;
|
||||
|
||||
asm volatile ( "inl %1, %0"
|
||||
: "=a"(ret)
|
||||
: "Nd"(address) );
|
||||
|
||||
asm volatile("inl %1, %0"
|
||||
: "=a"(ret)
|
||||
: "Nd"(address));
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
@ -11,11 +11,8 @@
|
||||
* 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)
|
||||
void int_disp (unsigned int slot) {
|
||||
void int_disp(unsigned int slot) {
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,11 @@
|
||||
#include "lib/OutStream.h"
|
||||
|
||||
// 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;
|
||||
return *this;
|
||||
}
|
||||
OutStream& OutStream::operator << (const fillc& c) {
|
||||
OutStream& OutStream::operator<<(const fillc& c) {
|
||||
this->fill_char = c.c;
|
||||
return *this;
|
||||
}
|
||||
@ -70,27 +70,27 @@ void OutStream::fill_use_char() {
|
||||
//
|
||||
// Zeichen und Zeichenketten in Stream ausgeben
|
||||
//
|
||||
OutStream& OutStream::operator << (char c) {
|
||||
OutStream& OutStream::operator<<(char c) {
|
||||
put(c);
|
||||
if (c != '\n') {
|
||||
// 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;
|
||||
}
|
||||
|
||||
// TODO: shouldn't this be printed as number?
|
||||
OutStream& OutStream::operator << (unsigned char c) {
|
||||
return *this << (char) c;
|
||||
OutStream& OutStream::operator<<(unsigned char c) {
|
||||
return *this << (char)c;
|
||||
}
|
||||
|
||||
OutStream& OutStream::operator << (char* string) {
|
||||
OutStream& OutStream::operator<<(char* string) {
|
||||
char* pos = string;
|
||||
while (*pos) {
|
||||
put (*pos);
|
||||
put(*pos);
|
||||
pos++;
|
||||
}
|
||||
this->fill_finalize(); // NOTE: I added this
|
||||
this->fill_finalize(); // NOTE: I added this
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -98,74 +98,75 @@ OutStream& OutStream::operator << (char* string) {
|
||||
// Ganzer Zahlen im Zahlensystem zur Basis base in Stream ausgeveb
|
||||
// Alle vorzeichenbehafteten Datentypen werden als long dargestellt,
|
||||
// Alle vorzeichenlosen als unsigned long.
|
||||
OutStream& OutStream::operator << (short ival) {
|
||||
return *this << (long) ival;
|
||||
OutStream& OutStream::operator<<(short ival) {
|
||||
return *this << (long)ival;
|
||||
}
|
||||
|
||||
OutStream& OutStream::operator << (unsigned short ival) {
|
||||
return *this << (unsigned long) ival;
|
||||
|
||||
OutStream& OutStream::operator<<(unsigned short ival) {
|
||||
return *this << (unsigned long)ival;
|
||||
}
|
||||
|
||||
OutStream& OutStream::operator << (int ival) {
|
||||
return *this << (long) ival;
|
||||
|
||||
OutStream& OutStream::operator<<(int ival) {
|
||||
return *this << (long)ival;
|
||||
}
|
||||
|
||||
OutStream& OutStream::operator << (unsigned int ival) {
|
||||
return *this << (unsigned long) ival;
|
||||
|
||||
OutStream& OutStream::operator<<(unsigned int ival) {
|
||||
return *this << (unsigned long)ival;
|
||||
}
|
||||
|
||||
// Darstellung eine vorzeichenbehafteten ganzen Zahl.
|
||||
OutStream& OutStream::operator << (long ival) {
|
||||
OutStream& OutStream::operator<<(long ival) {
|
||||
// Bei negativen Werten wird ein Minuszeichen ausgegeben.
|
||||
if (ival < 0) {
|
||||
put ('-');
|
||||
put('-');
|
||||
ival = -ival;
|
||||
}
|
||||
// Dann wird der Absolutwert als vorzeichenlose Zahl ausgegeben.
|
||||
return *this << (unsigned long) ival;
|
||||
return *this << (unsigned long)ival;
|
||||
}
|
||||
|
||||
// Darstellung einer vorzeichenlosen ganzen Zahl.
|
||||
OutStream& OutStream::operator << (unsigned long ival) {
|
||||
OutStream& OutStream::operator<<(unsigned long ival) {
|
||||
unsigned long div;
|
||||
char digit;
|
||||
|
||||
if (base == 8) {
|
||||
put ('0'); // oktale Zahlen erhalten eine fuehrende Null
|
||||
put('0'); // oktale Zahlen erhalten eine fuehrende Null
|
||||
} else if (base == 16) {
|
||||
put ('0'); // hexadezimale Zahlen ein "0x"
|
||||
put ('x');
|
||||
put('0'); // hexadezimale Zahlen ein "0x"
|
||||
put('x');
|
||||
}
|
||||
|
||||
// Bestimmung der groessten Potenz der gewaehlten Zahlenbasis, die
|
||||
// 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
|
||||
for (; div > 0; div /= (unsigned long) base) {
|
||||
for (; div > 0; div /= (unsigned long)base) {
|
||||
digit = ival / div;
|
||||
if (digit < 10) {
|
||||
put ('0' + digit);
|
||||
put('0' + digit);
|
||||
} else {
|
||||
put ('a' + digit - 10);
|
||||
put('a' + digit - 10);
|
||||
}
|
||||
ival %= div;
|
||||
}
|
||||
this->fill_finalize(); // NOTE: I added this
|
||||
this->fill_finalize(); // NOTE: I added this
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Darstellung eines Zeigers als hexadezimale ganze Zahl
|
||||
OutStream& OutStream::operator << (void* ptr) {
|
||||
OutStream& OutStream::operator<<(void* ptr) {
|
||||
int oldbase = base;
|
||||
base = 16;
|
||||
*this << (unsigned long) ptr;
|
||||
*this << (unsigned long)ptr;
|
||||
base = oldbase;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
// Aufruf einer Manipulatorfunktion
|
||||
OutStream& OutStream::operator << (OutStream& (*f) (OutStream&)) {
|
||||
OutStream& OutStream::operator<<(OutStream& (*f)(OutStream&)) {
|
||||
return f(*this);
|
||||
}
|
||||
|
||||
@ -180,33 +181,32 @@ OutStream& OutStream::operator << (OutStream& (*f) (OutStream&)) {
|
||||
// zu beeinflussen, z.B durch die Wahl des Zahlensystems.
|
||||
|
||||
// Fuege einen Zeilenumbruch in die Ausgabe ein.
|
||||
OutStream& endl (OutStream& os) {
|
||||
OutStream& endl(OutStream& os) {
|
||||
os << '\n';
|
||||
os.flush();
|
||||
return os;
|
||||
}
|
||||
|
||||
// Waehlt das binaere Zahlensystem aus.
|
||||
OutStream& bin (OutStream& os) {
|
||||
OutStream& bin(OutStream& os) {
|
||||
os.base = 2;
|
||||
return os;
|
||||
}
|
||||
|
||||
// Waehlt das oktale Zahlensystem aus.
|
||||
OutStream& oct (OutStream& os) {
|
||||
OutStream& oct(OutStream& os) {
|
||||
os.base = 8;
|
||||
return os;
|
||||
}
|
||||
|
||||
// Waehlt das dezimale Zahlensystem aus.
|
||||
OutStream& dec (OutStream& os) {
|
||||
OutStream& dec(OutStream& os) {
|
||||
os.base = 10;
|
||||
return os;
|
||||
}
|
||||
|
||||
// Waehlt das hexadezimale Zahlensystem aus.
|
||||
OutStream& hex (OutStream& os) {
|
||||
OutStream& hex(OutStream& os) {
|
||||
os.base = 16;
|
||||
return os;
|
||||
}
|
||||
|
||||
|
@ -30,76 +30,74 @@ class OutStream;
|
||||
// TODO: Should this only work for the next << ?
|
||||
class fillw {
|
||||
public:
|
||||
fillw(unsigned char w) : w(w) {};
|
||||
unsigned char w;
|
||||
fillw(unsigned char w) : w(w) {};
|
||||
unsigned char w;
|
||||
};
|
||||
|
||||
class fillc {
|
||||
public:
|
||||
fillc(char c) : c(c) {};
|
||||
char c;
|
||||
fillc(char c) : c(c) {};
|
||||
char c;
|
||||
};
|
||||
|
||||
|
||||
class OutStream : public StringBuffer {
|
||||
|
||||
private:
|
||||
OutStream(const OutStream ©); // Verhindere Kopieren
|
||||
OutStream(const OutStream& copy); // Verhindere Kopieren
|
||||
|
||||
// NOTE: I added this
|
||||
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_finalize(); // does the filling after text has been written to buffer
|
||||
// NOTE: I added this
|
||||
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_finalize(); // does the filling after text has been written to buffer
|
||||
|
||||
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
|
||||
unsigned char fill_width;
|
||||
char fill_char; // fill character for fixed width
|
||||
// NOTE: I added this
|
||||
unsigned char fill_width;
|
||||
char fill_char; // fill character for fixed width
|
||||
|
||||
OutStream () : StringBuffer () {
|
||||
base = 10; // initial Dezimalsystem
|
||||
fill_width = 0; // no fixed width
|
||||
fill_used = 0;
|
||||
fill_char = ' '; // fill with spaces
|
||||
}
|
||||
OutStream() : StringBuffer() {
|
||||
base = 10; // initial Dezimalsystem
|
||||
fill_width = 0; // no fixed width
|
||||
fill_used = 0;
|
||||
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
|
||||
void put(char c) override;
|
||||
// NOTE: I added this
|
||||
void put(char c) override;
|
||||
|
||||
// OPERATOR << : Umwandlung des angegebenen Datentypes in eine
|
||||
// Zeichenkette.
|
||||
// OPERATOR << : Umwandlung des angegebenen Datentypes in eine
|
||||
// Zeichenkette.
|
||||
|
||||
// Darstellung eines Zeichens (trivial)
|
||||
OutStream& operator << (char c);
|
||||
OutStream& operator << (unsigned char c);
|
||||
// Darstellung eines Zeichens (trivial)
|
||||
OutStream& operator<<(char c);
|
||||
OutStream& operator<<(unsigned char c);
|
||||
|
||||
// Darstellung einer nullterminierten Zeichenkette
|
||||
OutStream& operator << (char* string);
|
||||
// Darstellung einer nullterminierten Zeichenkette
|
||||
OutStream& operator<<(char* string);
|
||||
|
||||
// Darstellung ganzer Zahlen im Zahlensystem zur Basis base
|
||||
OutStream& operator << (short ival);
|
||||
OutStream& operator << (unsigned short ival);
|
||||
OutStream& operator << (int ival);
|
||||
OutStream& operator << (unsigned int ival);
|
||||
OutStream& operator << (long ival);
|
||||
OutStream& operator << (unsigned long ival);
|
||||
// Darstellung ganzer Zahlen im Zahlensystem zur Basis base
|
||||
OutStream& operator<<(short ival);
|
||||
OutStream& operator<<(unsigned short ival);
|
||||
OutStream& operator<<(int ival);
|
||||
OutStream& operator<<(unsigned int ival);
|
||||
OutStream& operator<<(long ival);
|
||||
OutStream& operator<<(unsigned long ival);
|
||||
|
||||
// Darstellung eines Zeigers als hexadezimale ganze Zahl
|
||||
OutStream& operator << (void* ptr);
|
||||
// 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, set fixed output width
|
||||
OutStream& operator<<(const fillw& w);
|
||||
OutStream& operator<<(const fillc& c);
|
||||
|
||||
// Aufruf einer Manipulatorfunktion
|
||||
OutStream& operator << (OutStream& (*f) (OutStream&));
|
||||
// Aufruf einer Manipulatorfunktion
|
||||
OutStream& operator<<(OutStream& (*f)(OutStream&));
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Manipulatorfunktionen
|
||||
//
|
||||
@ -111,18 +109,18 @@ public:
|
||||
// zu beeinflussen, z.B durch die Wahl des Zahlensystems.
|
||||
|
||||
// Zeilenumbruch in Ausgabe einfuegen.
|
||||
OutStream& endl (OutStream& os);
|
||||
OutStream& endl(OutStream& os);
|
||||
|
||||
// Waehle binaeres Zahlensystem aus.
|
||||
OutStream& bin (OutStream& os);
|
||||
OutStream& bin(OutStream& os);
|
||||
|
||||
// Waehle oktales Zahlensystem aus.
|
||||
OutStream& oct (OutStream& os);
|
||||
OutStream& oct(OutStream& os);
|
||||
|
||||
// Waehle dezimales Zahlensystem aus.
|
||||
OutStream& dec (OutStream& os);
|
||||
OutStream& dec(OutStream& os);
|
||||
|
||||
// Waehle hexadezimales Zahlensystem aus.
|
||||
OutStream& hex (OutStream& os);
|
||||
OutStream& hex(OutStream& os);
|
||||
|
||||
#endif
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
#include "lib/StringBuffer.h"
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: StringBuffer::put *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -29,10 +28,9 @@
|
||||
* Parameter: *
|
||||
* c: Einzufuegendes Zeichen. *
|
||||
*****************************************************************************/
|
||||
void StringBuffer::put (char c) {
|
||||
void StringBuffer::put(char c) {
|
||||
buffer[pos] = c;
|
||||
pos++;
|
||||
if (pos == sizeof (buffer))
|
||||
flush ();
|
||||
}
|
||||
|
||||
if (pos == sizeof(buffer))
|
||||
flush();
|
||||
}
|
||||
|
@ -19,9 +19,9 @@
|
||||
#define __StringBuffer_include__
|
||||
|
||||
class StringBuffer {
|
||||
|
||||
|
||||
private:
|
||||
StringBuffer(const StringBuffer ©); // Verhindere Kopieren
|
||||
StringBuffer(const StringBuffer& copy); // Verhindere Kopieren
|
||||
|
||||
// Alle Variablen und Methoden dieser Klasse sind "protected",
|
||||
// da die abgeleiteten Klassen einen direkten Zugriff auf den
|
||||
@ -34,15 +34,14 @@ protected:
|
||||
int pos;
|
||||
|
||||
// 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
|
||||
virtual void put (char c);
|
||||
virtual void put(char c);
|
||||
|
||||
// Methode zur Ausgabe des Pufferinhalts
|
||||
virtual void flush () = 0;
|
||||
|
||||
virtual void flush() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -11,9 +11,8 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "kernel/Globals.h"
|
||||
#include "user/TextDemo.h"
|
||||
#include "user/SoundDemo.h"
|
||||
|
||||
#include "user/TextDemo.h"
|
||||
|
||||
int main() {
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
@ -23,10 +22,10 @@ int main() {
|
||||
|
||||
// TODO: Startmeldung ausgeben
|
||||
|
||||
|
||||
text_demo();
|
||||
// sound_demo();
|
||||
|
||||
while (1);
|
||||
while (1)
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,8 @@
|
||||
#include "kernel/Globals.h"
|
||||
|
||||
void sound_demo() {
|
||||
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
pcspk.tetris();
|
||||
// pcspk.play(440, 1000);
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,6 @@
|
||||
#ifndef __SoundDemo_include__
|
||||
#define __SondDemo_include__
|
||||
|
||||
void sound_demo();
|
||||
void sound_demo();
|
||||
|
||||
#endif
|
||||
|
@ -10,11 +10,11 @@
|
||||
|
||||
#include "kernel/Globals.h"
|
||||
|
||||
|
||||
void text_demo() {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
kout << "Test der Zahlenausgabefunktion:" << endl << endl;
|
||||
kout << "Test der Zahlenausgabefunktion:" << endl;
|
||||
kout << endl;
|
||||
kout << "| dec | hex | bin |" << endl;
|
||||
kout << "+-------+-------+-------+" << endl;
|
||||
|
||||
|
@ -11,6 +11,6 @@
|
||||
#ifndef __TextDemo_include__
|
||||
#define __TextDemo_include__
|
||||
|
||||
void text_demo();
|
||||
void text_demo();
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user