1

reformat + static const ioports

This commit is contained in:
2022-07-24 16:54:51 +02:00
parent e1eac41853
commit 0d109727ac
11 changed files with 84 additions and 67 deletions

View File

@ -14,12 +14,15 @@
#include "devices/CGA.h"
#include "user/lib/Memory.h"
const IOport CGA::index_port(0x3d4);
const IOport CGA::data_port(0x3d5);
/*****************************************************************************
* Methode: CGA::setpos *
*---------------------------------------------------------------------------*
* Beschreibung: Setzen des Cursors in Spalte x und Zeile y. *
*****************************************************************************/
void CGA::setpos(const unsigned int x, const unsigned int y) {
void CGA::setpos(unsigned int x, unsigned int y) {
/* Hier muess Code eingefuegt werden */
@ -42,7 +45,7 @@ void CGA::setpos(const unsigned int x, const unsigned int y) {
* *
* Rückgabewerte: x und y *
*****************************************************************************/
void CGA::getpos(unsigned int& x, unsigned int& y) const {
void CGA::getpos(unsigned int& x, unsigned int& y) {
/* Hier muess Code eingefuegt werden */
@ -70,7 +73,7 @@ void CGA::getpos(unsigned int& x, unsigned int& y) const {
* character Das auszugebende Zeichen *
* attrib Attributbyte fuer das Zeichen *
*****************************************************************************/
void CGA::show(const unsigned int x, const unsigned int y, const char character, const unsigned char attrib) {
void CGA::show(unsigned int x, unsigned int y, char character, unsigned char attrib) {
/* Hier muess Code eingefuegt werden */
@ -95,7 +98,7 @@ void CGA::show(const unsigned int x, const unsigned int y, const char character,
* n Laenger der Zeichenkette *
* attrib Attributbyte fuer alle Zeichen der Zeichenkette *
*****************************************************************************/
void CGA::print(const char* string, const unsigned int n, const unsigned char attrib) {
void CGA::print(const char* string, unsigned int n, unsigned char attrib) const {
/* Hier muess Code eingefuegt werden */
@ -142,11 +145,11 @@ void CGA::print(const char* string, const unsigned int n, const unsigned char at
setpos(cursor_x, cursor_y);
}
void CGA::print(const bse::string& string, const unsigned int n, const unsigned char attrib) {
void CGA::print(const bse::string& string, const unsigned int n, const unsigned char attrib) const {
print((const char*)string, n, attrib);
}
void CGA::print(const bse::string& string, const unsigned char attrib) {
void CGA::print(const bse::string& string, const unsigned char attrib) const {
print((const char*)string, string.size(), attrib);
}
@ -157,7 +160,7 @@ void CGA::print(const bse::string& string, const unsigned char attrib) {
* Die neue Zeile am unteren Bildrand wird mit Leerzeichen *
* gefuellt. *
*****************************************************************************/
void CGA::scrollup() {
void CGA::scrollup() const {
/* Hier muss Code eingefuegt werden */
@ -195,7 +198,7 @@ void CGA::clear() {
* fg Foreground color *
* blink ywa/no *
*****************************************************************************/
unsigned char CGA::attribute(const CGA::color bg, const CGA::color fg, const bool blink) {
unsigned char CGA::attribute(CGA::color bg, CGA::color fg, bool blink) {
/* Hier muess Code eingefuegt werden */

View File

@ -20,20 +20,20 @@
class CGA {
private:
static const IOport index_port; // Auswahl eines Register der Grafikkarte
static const IOport data_port; // Lese-/Schreib-Zugriff auf Register der Grafikk.
public:
// Copy Konstrutkor unterbinden
CGA(const CGA& copy) = delete;
IOport index_port; // Auswahl eines Register der Grafikkarte
IOport data_port; // Lese-/Schreib-Zugriff auf Register der Grafikk.
public:
static const unsigned int CGA_START = 0xb8000U;
// Konstruktur mit Initialisierung der Ports
CGA() : index_port(0x3d4), data_port(0x3d5) {
CGA() {
this->setpos(0, 0);
}
static const unsigned int CGA_START = 0xb8000U;
// Konstanten fuer die moeglichen Farben im Attribut-Byte.
typedef enum {
BLACK,
@ -77,22 +77,22 @@ public:
};
// Setzen des Cursors in Spalte x und Zeile y.
void setpos(unsigned int x, unsigned int y);
static void setpos(unsigned int x, unsigned int y);
// Abfragen der Cursorpostion
void getpos(unsigned int& x, unsigned int& y) const;
static void getpos(unsigned int& x, unsigned int& y) ;
// Anzeige eines Zeichens mit Attribut an einer bestimmten Stelle
static void show(unsigned int x, unsigned int y, char character, unsigned char attrib = STD_ATTR);
// Anzeige mehrerer Zeichen ab der aktuellen Cursorposition
void print(const char* string, unsigned int n, unsigned char attrib = STD_ATTR);
void print(const bse::string& string, unsigned int n, unsigned char attrib = STD_ATTR);
void print(const bse::string& string, unsigned char attrib = STD_ATTR);
void print(const char* string, unsigned int n, unsigned char attrib = STD_ATTR) const;
void print(const bse::string& string, unsigned int n, unsigned char attrib = STD_ATTR) const;
void print(const bse::string& string, unsigned char attrib = STD_ATTR) const;
// Verschiebt den Bildschirminhalt um eine Zeile nach oben.
// Neue Zeile am unteren Bildrand mit Leerzeichen fuellen
virtual void scrollup();
virtual void scrollup() const;
// Lösche den Textbildschirm
virtual void clear();

View File

@ -11,9 +11,12 @@
#include "devices/Keyboard.h"
#include "kernel/Globals.h"
const IOport Keyboard::ctrl_port(0x64);
const IOport Keyboard::data_port(0x60);
/* Tabellen fuer ASCII-Codes (Klassenvariablen) intiialisieren */
unsigned char Keyboard::normal_tab[] = {
constexpr unsigned char Keyboard::normal_tab[] = {
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 225, 39, '\b',
0, 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', 129, '+', '\n',
0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 148, 132, '^', 0, '#',
@ -21,7 +24,7 @@ unsigned char Keyboard::normal_tab[] = {
'*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-',
0, 0, 0, '+', 0, 0, 0, 0, 0, 0, 0, '<', 0, 0};
unsigned char Keyboard::shift_tab[] = {
constexpr unsigned char Keyboard::shift_tab[] = {
0, 0, '!', '"', 21, '$', '%', '&', '/', '(', ')', '=', '?', 96, 0,
0, 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 154, '*', 0,
0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 153, 142, 248, 0, 39,
@ -29,7 +32,7 @@ unsigned char Keyboard::shift_tab[] = {
0, 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '>', 0, 0};
unsigned char Keyboard::alt_tab[] = {
constexpr unsigned char Keyboard::alt_tab[] = {
0, 0, 0, 253, 0, 0, 0, 0, '{', '[', ']', '}', '\\', 0, 0,
0, '@', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '~', 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -37,9 +40,10 @@ unsigned char Keyboard::alt_tab[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0};
unsigned char Keyboard::asc_num_tab[] = {
constexpr unsigned char Keyboard::asc_num_tab[] = {
'7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', ','};
unsigned char Keyboard::scan_num_tab[] = {
constexpr unsigned char Keyboard::scan_num_tab[] = {
8, 9, 10, 53, 5, 6, 7, 27, 2, 3, 4, 11, 51};
/*****************************************************************************
@ -220,7 +224,7 @@ void Keyboard::get_ascii_code() {
* schaltet und die Wiederholungsrate auf maximale *
* Geschwindigkeit eingestellt. *
*****************************************************************************/
Keyboard::Keyboard() : ctrl_port(0x64), data_port(0x60) {
Keyboard::Keyboard() {
// alle LEDs ausschalten (bei vielen PCs ist NumLock nach dem Booten an)
set_led(led::caps_lock, false);
set_led(led::scroll_lock, false);

View File

@ -17,16 +17,14 @@
class Keyboard : public ISR {
private:
Keyboard(const Keyboard& copy) = delete; // Verhindere Kopieren
unsigned char code; // Byte von Tastatur
unsigned char prefix; // Prefix von Tastatur
Key gather; // letzter dekodierter Key
char leds; // Zustand LEDs
// Benutzte Ports des Tastaturcontrollers
const IOport ctrl_port; // Status- (R) u. Steuerregister (W)
const IOport data_port; // Ausgabe- (R) u. Eingabepuffer (W)
static const IOport ctrl_port; // Status- (R) u. Steuerregister (W)
static const IOport data_port; // Ausgabe- (R) u. Eingabepuffer (W)
// Bits im Statusregister
enum { outb = 0x01,
@ -58,11 +56,11 @@ private:
prefix2 = 0xe1 };
// Klassenvariablen
static unsigned char normal_tab[];
static unsigned char shift_tab[];
static unsigned char alt_tab[];
static unsigned char asc_num_tab[];
static unsigned char scan_num_tab[];
static const unsigned char normal_tab[];
static const unsigned char shift_tab[];
static const unsigned char alt_tab[];
static const unsigned char asc_num_tab[];
static const unsigned char scan_num_tab[];
// Interpretiert die Make und Break-Codes der Tastatur.
bool key_decoded();
@ -74,6 +72,8 @@ private:
Key key_hit();
public:
Keyboard(const Keyboard& copy) = delete; // Verhindere Kopieren
unsigned int lastkey; // speichert den ASCII-Code der zuletzt gedrückten Taste
// Initialisierung der Tastatur.

View File

@ -15,6 +15,11 @@
#include "devices/PCSPK.h"
#include "kernel/Globals.h"
const IOport PCSPK::control(0x43);
const IOport PCSPK::data0(0x40);
const IOport PCSPK::data2(0x42);
const IOport PCSPK::ppi(0x61);
/*****************************************************************************
* Methode: PCSPK::play *
*---------------------------------------------------------------------------*

View File

@ -59,21 +59,20 @@
#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& copy); // Verhindere Kopieren
static const IOport control; // Steuerregister (write only)
static const IOport data0; // Zaehler-0 Datenregister (read/write)
static const IOport data2; // Zaehler-2 Datenregister
static const IOport ppi; // Status-Register des PPI
// Verzoegerung um X ms (in 1ms Schritten; Min. 1ms)
inline void delay(int time);
public:
PCSPK(const PCSPK& copy) = delete; // Verhindere Kopieren
// Konstruktor. Initialisieren der Ports.
PCSPK() : control(0x43), data0(0x40), data2(0x42), ppi(0x61) {}
PCSPK() {}
// Demo Sounds
void tetris();

View File

@ -12,6 +12,9 @@
#include "kernel/Globals.h"
#include "kernel/IOport.h"
const IOport PIT::control(0x43);
const IOport PIT::data0(0x40);
/*****************************************************************************
* Methode: PIT::interval *
*---------------------------------------------------------------------------*
@ -25,12 +28,10 @@ void PIT::interval(int us) {
/* hier muss Code eingefuegt werden */
IOport control(0x43);
control.outb(0x36); // Zähler 0 Mode 3
unsigned int cntStart = (1193180.0 / 1000000.0) * us; // 1.19Mhz PIT
IOport data0(0x40);
data0.outb(cntStart & 0xFF); // Zaehler-0 laden (Lobyte)
data0.outb(cntStart >> 8); // Zaehler-0 laden (Hibyte)
}
@ -47,7 +48,7 @@ void PIT::plugin() {
/* hier muss Code eingefuegt werden */
intdis.assign(IntDispatcher::timer, *this);
pic.allow(PIC::timer);
PIC::allow(PIC::timer);
}
/*****************************************************************************

View File

@ -12,32 +12,34 @@
#define __PIT_include__
#include "kernel/interrupts/ISR.h"
#include "kernel/IOport.h"
class PIT : public ISR {
private:
PIT(const PIT& copy) = delete; // Verhindere Kopieren
const static IOport control;
const static IOport data0;
enum { time_base = 838 }; /* ns */
int timer_interval;
char indicator[4] = {'|', '/', '-', '\\'};
const char indicator[4] = {'|', '/', '-', '\\'};
unsigned int indicator_pos = 0;
unsigned long last_indicator_refresh = 0;
public:
PIT(const PIT& copy) = delete; // Verhindere Kopieren
// Zeitgeber initialisieren.
PIT(int us) {
this->interval(us);
explicit PIT(int us) {
PIT::interval(us);
}
// Konfiguriertes Zeitintervall auslesen.
int interval() const {
return timer_interval;
}
int interval() const { return timer_interval; }
// Zeitintervall in Mikrosekunden, nachdem periodisch ein Interrupt
//erzeugt werden soll.
void interval(int us);
static void interval(int us);
// Aktivierung der Unterbrechungen fuer den Zeitgeber
void plugin();

View File

@ -17,14 +17,13 @@
#define __IOport_include__
class IOport {
// Kopieren erlaubt!
private:
// 16-Bit Adresse im I/O-Adressraum
unsigned short address;
const unsigned short address;
public:
// Konstruktor, speichert Port-Adresse
IOport(unsigned short a) : address(a) {};
explicit IOport(unsigned short a) : address(a) {};
// Byteweise Ausgabe eines Wertes ueber einen I/O-Port.
void outb(unsigned char val) const {

View File

@ -18,8 +18,8 @@
#include "kernel/interrupts/PIC.h"
#include "kernel/IOport.h"
static IOport IMR1(0x21); // interrupt mask register von PIC 1
static IOport IMR2(0xa1); // interrupt mask register von PIC 2
IOport const PIC::IMR1(0x21); // interrupt mask register von PIC 1
IOport const PIC::IMR2(0xa1); // interrupt mask register von PIC 2
/*****************************************************************************
* Methode: PIC::allow *

View File

@ -17,13 +17,17 @@
#ifndef __PIC_include__
#define __PIC_include__
class PIC {
#include "kernel/IOport.h"
class PIC {
private:
PIC(const PIC& copy) = delete; // Verhindere Kopieren
static const IOport IMR1; // interrupt mask register von PIC 1
static const IOport IMR2; // interrupt mask register von PIC 2
public:
PIC() {}
PIC(const PIC& copy) = delete; // Verhindere Kopieren
PIC() = default;
// IRQ-Nummern von Geraeten
enum {
@ -33,13 +37,13 @@ public:
};
// Freischalten der Weiterleitung eines IRQs durch den PIC an die CPU
void allow(int irq);
static void allow(int irq);
// Unterdruecken der Weiterleitung eines IRQs durch den PIC an die CPU
void forbid(int irq);
static void forbid(int irq);
// Abfragen, ob die Weiterleitung fuer einen bestimmten IRQ unterdrueckt ist
bool status(int interrupt_device);
static bool status(int interrupt_device);
};
#endif