1
This commit is contained in:
churl
2022-06-17 15:37:39 +02:00
parent d29dc064cb
commit 59f5b5eacc
5 changed files with 179 additions and 180 deletions

View File

@ -15,12 +15,10 @@
#include "devices/LFBgraphics.h" #include "devices/LFBgraphics.h"
#include "kernel/Globals.h" #include "kernel/Globals.h"
/* Hilfsfunktionen */ /* Hilfsfunktionen */
void swap(unsigned int *a, unsigned int *b); void swap(unsigned int* a, unsigned int* b);
int abs(int a); int abs(int a);
/***************************************************************************** /*****************************************************************************
* Methode: LFBgraphics::drawMonoBitmap * * Methode: LFBgraphics::drawMonoBitmap *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -38,21 +36,21 @@ int abs(int a);
* mit cpi2fnt (AmigaOS) erzeugt wurden. Das Format erklaert* * mit cpi2fnt (AmigaOS) erzeugt wurden. Das Format erklaert*
* sich in den C-Dateien in fonts/ von selbst. * * sich in den C-Dateien in fonts/ von selbst. *
*****************************************************************************/ *****************************************************************************/
inline void LFBgraphics::drawMonoBitmap( unsigned int x, unsigned int y, inline void LFBgraphics::drawMonoBitmap(unsigned int x, unsigned int y,
unsigned int width, unsigned int width,
unsigned int height, unsigned int height,
unsigned char* bitmap, unsigned char* bitmap,
unsigned int color) { unsigned int color) {
// Breite in Bytes // Breite in Bytes
unsigned short width_byte = width/8 + ((width%8 != 0) ? 1 : 0); unsigned short width_byte = width / 8 + ((width % 8 != 0) ? 1 : 0);
for(unsigned int yoff=0; yoff<height; ++yoff) { for (unsigned int yoff = 0; yoff < height; ++yoff) {
int xpos=x; int xpos = x;
int ypos=y+yoff; int ypos = y + yoff;
for(unsigned int xb=0; xb < width_byte; ++xb) { for (unsigned int xb = 0; xb < width_byte; ++xb) {
for( int src=7; src>=0; --src) { for (int src = 7; src >= 0; --src) {
if ((1 << src) & *bitmap) { if ((1 << src) & *bitmap) {
drawPixel(xpos, ypos, color); drawPixel(xpos, ypos, color);
} }
xpos++; xpos++;
} }
@ -61,7 +59,6 @@ inline void LFBgraphics::drawMonoBitmap( unsigned int x, unsigned int y,
} }
} }
/***************************************************************************** /*****************************************************************************
* Methode: LFBgraphics::drawString * * Methode: LFBgraphics::drawString *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -74,18 +71,15 @@ inline void LFBgraphics::drawMonoBitmap( unsigned int x, unsigned int y,
* Beschreibung: Gibt eine Zeichenkette mit gewaehlter Schrift an der * * Beschreibung: Gibt eine Zeichenkette mit gewaehlter Schrift an der *
* Position x,y aus. * * Position x,y aus. *
*****************************************************************************/ *****************************************************************************/
void LFBgraphics::drawString(Font &fnt, unsigned int x, unsigned int y, void LFBgraphics::drawString(Font& fnt, unsigned int x, unsigned int y,
unsigned int col, char* str, unsigned int len) { unsigned int col, char* str, unsigned int len) {
unsigned int i; for (unsigned int i = 0; i < len; ++i) {
drawMonoBitmap(x, y, fnt.get_char_width(), fnt.get_char_height(),
for(i = 0; i < len; ++i) { fnt.getChar(*(str + i)), col);
drawMonoBitmap(x, y, fnt.get_char_width(), fnt.get_char_height(),
fnt.getChar( *(str+i) ), col);
x += fnt.get_char_width(); x += fnt.get_char_width();
} }
} }
/***************************************************************************** /*****************************************************************************
* Methode: LFBgraphics::drawPixel * * Methode: LFBgraphics::drawPixel *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -94,136 +88,150 @@ void LFBgraphics::drawString(Font &fnt, unsigned int x, unsigned int y,
* * * *
* Beschreibung: Zeichnen eines Pixels. * * Beschreibung: Zeichnen eines Pixels. *
*****************************************************************************/ *****************************************************************************/
void LFBgraphics::drawPixel(unsigned int x, unsigned int y,unsigned int col) { void LFBgraphics::drawPixel(unsigned int x, unsigned int y, unsigned int col) {
unsigned char *ptr = (unsigned char *) lfb; unsigned char* ptr = (unsigned char*)lfb;
if (hfb == 0 || lfb == 0) return ;
if (mode == 0) ptr = (unsigned char *) hfb; if (hfb == 0 || lfb == 0) {
// Pixel ausserhalb des sichtbaren Bereichs?
if (x<0 || x>=xres || y<0 || y>yres)
return; return;
}
if (mode == 0) ptr = (unsigned char*)hfb;
// Pixel ausserhalb des sichtbaren Bereichs?
if (x < 0 || x >= xres || y < 0 || y > yres) {
return;
}
// Adresse des Pixels berechnen und Inhalt schreiben // Adresse des Pixels berechnen und Inhalt schreiben
switch (bpp) { switch (bpp) {
case 8: case 8:
ptr += (x+y*xres); ptr += (x + y * xres);
*ptr = col; *ptr = col;
return; return;
case 15: case 15:
case 16: case 16:
ptr += (2*x+2*y*xres); ptr += (2 * x + 2 * y * xres);
*ptr = col; *ptr = col;
return; return;
case 24: case 24:
ptr += (3*x+3*y*xres); ptr += (3 * x + 3 * y * xres);
*ptr = (col & 0xFF); ptr++; *ptr = (col & 0xFF);
*ptr = ((col>>8) & 0xFF); ptr++; ptr++;
*ptr = ((col>>16) & 0xFF); ptr++; *ptr = ((col >> 8) & 0xFF);
return; ptr++;
case 32: *ptr = ((col >> 16) & 0xFF);
ptr += (4*x+4*y*xres); ptr++;
*ptr = (col & 0xFF); ptr++; return;
*ptr = ((col>>8) & 0xFF); ptr++; case 32:
*ptr = ((col>>16) & 0xFF); ptr++; ptr += (4 * x + 4 * y * xres);
return; *ptr = (col & 0xFF);
ptr++;
*ptr = ((col >> 8) & 0xFF);
ptr++;
*ptr = ((col >> 16) & 0xFF);
ptr++;
return;
} }
} }
/***************************************************************************** /*****************************************************************************
* Methode: LFBgraphics::clear * * Methode: LFBgraphics::clear *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Bildschirm loeschen. * * Beschreibung: Bildschirm loeschen. *
*****************************************************************************/ *****************************************************************************/
void LFBgraphics::clear() { void LFBgraphics::clear() {
unsigned int *ptr = (unsigned int *)lfb; unsigned int* ptr = (unsigned int*)lfb;
unsigned int i; unsigned int i;
if (hfb == 0 || lfb == 0) {
if (hfb == 0 || lfb == 0) return ; return;
}
if (mode == 0) {
ptr = (unsigned int*)hfb;
}
if (mode == 0) ptr = (unsigned int *) hfb;
switch (bpp) { switch (bpp) {
case 8: case 8:
for (i=0; i < ((xres/4)*yres); i++) for (i = 0; i < ((xres / 4) * yres); i++) {
*(ptr++) = 0; *(ptr++) = 0;
return; }
case 15: return;
case 16: case 15:
for (i=0; i < (2*(xres/4)*yres); i++) case 16:
*(ptr++) = 0; for (i = 0; i < (2 * (xres / 4) * yres); i++) {
return; *(ptr++) = 0;
case 24: }
for (i=0; i < (3*(xres/4)*yres); i++) return;
*(ptr++) = 0; case 24:
return; for (i = 0; i < (3 * (xres / 4) * yres); i++) {
case 32: *(ptr++) = 0;
for (i=0; i < (4*(xres/4)*yres); i++) }
*(ptr++) = 0; return;
return; case 32:
for (i = 0; i < (4 * (xres / 4) * yres); i++) {
*(ptr++) = 0;
}
return;
} }
} }
/***************************************************************************** /*****************************************************************************
* Methode: LFBgraphics::setDrawingBuff * * Methode: LFBgraphics::setDrawingBuff *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Stellt ein, ob in den sichtbaren Puffer gezeichnet wird. * * Beschreibung: Stellt ein, ob in den sichtbaren Puffer gezeichnet wird. *
*****************************************************************************/ *****************************************************************************/
void LFBgraphics::setDrawingBuff(int v) void LFBgraphics::setDrawingBuff(int v) {
{ mode = v;
mode = v;
} }
/***************************************************************************** /*****************************************************************************
* Methode: LFBgraphics::copyHiddenToVisible * * Methode: LFBgraphics::copyHiddenToVisible *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Kopiert den versteckten Puffer in den sichtbaren LFB. * * Beschreibung: Kopiert den versteckten Puffer in den sichtbaren LFB. *
*****************************************************************************/ *****************************************************************************/
void LFBgraphics::copyHiddenToVisible() { void LFBgraphics::copyHiddenToVisible() {
unsigned int *sptr = (unsigned int *)hfb; unsigned int* sptr = (unsigned int*)hfb;
unsigned int *dptr = (unsigned int *)lfb; unsigned int* dptr = (unsigned int*)lfb;
unsigned int i; unsigned int i;
if (hfb == 0 || lfb == 0) return ; if (hfb == 0 || lfb == 0) return;
switch (bpp) { switch (bpp) {
case 8: case 8:
for (i=0; i < ((xres/4)*yres); i++) for (i = 0; i < ((xres / 4) * yres); i++) {
*(dptr++) = *(sptr++); *(dptr++) = *(sptr++);
return; }
case 15: return;
case 16: case 15:
for (i=0; i < (2*(xres/4)*yres); i++) case 16:
*(dptr++) = *(sptr++); for (i = 0; i < (2 * (xres / 4) * yres); i++) {
return; *(dptr++) = *(sptr++);
case 24: }
for (i=0; i < (3*(xres/4)*yres); i++) return;
*(dptr++) = *(sptr++); case 24:
return; for (i = 0; i < (3 * (xres / 4) * yres); i++) {
case 32: *(dptr++) = *(sptr++);
for (i=0; i < (4*(xres/4)*yres); i++) }
*(dptr++) = *(sptr++); return;
return; case 32:
for (i = 0; i < (4 * (xres / 4) * yres); i++) {
*(dptr++) = *(sptr++);
}
return;
} }
} }
void swap(unsigned int* a, unsigned int* b) {
int h = *a;
*a = *b;
void swap(unsigned int *a, unsigned int *b) { *b = h;
int h;
h = *a;
*a = *b;
*b = h;
} }
int abs(int a) { int abs(int a) {
if (a<0) return -a; if (a < 0) {
return a; return -a;
}
return a;
} }

View File

@ -17,44 +17,42 @@
#include "devices/fonts/Fonts.h" #include "devices/fonts/Fonts.h"
// Hilfsfunktionen um Farbwerte fuer einen Pixel zu erzeugen // Hilfsfunktionen um Farbwerte fuer einen Pixel zu erzeugen
#define RGB_24(r,g,b) (unsigned int) ((r << 16) + (g << 8) + b ) #define RGB_24(r, g, b) (unsigned int)((r << 16) + (g << 8) + b)
#define BUFFER_INVISIBLE 0 #define BUFFER_INVISIBLE 0
#define BUFFER_VISIBLE 1 #define BUFFER_VISIBLE 1
class LFBgraphics { class LFBgraphics {
private: private:
LFBgraphics (const LFBgraphics &copy); // Verhindere Kopieren LFBgraphics(const LFBgraphics& copy) = delete; // Verhindere Kopieren
// Hilfsfunktion fuer drawString // Hilfsfunktion fuer drawString
void drawMonoBitmap ( unsigned int x, unsigned int y, void drawMonoBitmap(unsigned int x, unsigned int y,
unsigned int width, unsigned int height, unsigned int width, unsigned int height,
unsigned char* bitmap, unsigned int col); unsigned char* bitmap, unsigned int col);
public: public:
unsigned int xres, yres; // Aufloesung in Pixel unsigned int xres, yres; // Aufloesung in Pixel
unsigned int bpp; // Farbtiefe (Bits per Pixel) unsigned int bpp; // Farbtiefe (Bits per Pixel)
unsigned int lfb; // Adresse des Linearen Framebuffers unsigned int lfb; // Adresse des Linearen Framebuffers
unsigned int hfb; // Adresse des versteckten Buffers (optional, fuer Animationen) unsigned int hfb; // Adresse des versteckten Buffers (optional, fuer Animationen)
unsigned int mode; // Zeichnen im sichtbaren = 1 oder unsichtbaren = 0 Puffer unsigned int mode; // Zeichnen im sichtbaren = 1 oder unsichtbaren = 0 Puffer
LFBgraphics () { mode = BUFFER_VISIBLE; }; LFBgraphics() : mode(BUFFER_VISIBLE) {};
void clear (); void clear();
void drawPixel ( unsigned int x, unsigned int y, unsigned int col); void drawPixel(unsigned int x, unsigned int y, unsigned int col);
void drawString (Font &fnt, unsigned int x, unsigned int y, void drawString(Font& fnt, unsigned int x, unsigned int y,
unsigned int col, char* str, unsigned int len); unsigned int col, char* str, unsigned int len);
// stellt ein, ob in den sichtbaren Puffer gezeichnet wird // stellt ein, ob in den sichtbaren Puffer gezeichnet wird
void setDrawingBuff( int v); void setDrawingBuff(int v);
// kopiert 'hfb' nach 'lfb' // kopiert 'hfb' nach 'lfb'
void copyHiddenToVisible(); void copyHiddenToVisible();
}; };
#endif #endif

View File

@ -13,6 +13,7 @@
#include "kernel/Globals.h" #include "kernel/Globals.h"
#include "user/CoopThreadDemo.h" #include "user/CoopThreadDemo.h"
#include "user/HelloWorldThread.h" #include "user/HelloWorldThread.h"
#include "user/VBEdemo.h"
int main() { int main() {
kout.clear(); kout.clear();
@ -25,7 +26,7 @@ int main() {
// Startmeldung // Startmeldung
if constexpr (!DEBUG) { if constexpr (!DEBUG) {
kout << "HHUos 0.6\n" kout << "HHUos 0.7\n"
<< "=========\n" << "=========\n"
<< "Unterstuetzte Funktionen:\n" << "Unterstuetzte Funktionen:\n"
<< " - Bildschirmausgaben\n" << " - Bildschirmausgaben\n"
@ -34,6 +35,7 @@ int main() {
<< " - Einfache Heap verwaltung\n" << " - Einfache Heap verwaltung\n"
<< " - Tastatureingaben per Interrupt\n" << " - Tastatureingaben per Interrupt\n"
<< " - Kooperative Threads\n" << " - Kooperative Threads\n"
<< " - VESA Graphics Mode\n"
<< endl; << endl;
} }
@ -54,7 +56,9 @@ int main() {
// Threads anlegen // Threads anlegen
// scheduler.ready(new HelloWorldThread()); // scheduler.ready(new HelloWorldThread());
scheduler.ready(new CoopThreadDemo()); // scheduler.ready(new CoopThreadDemo());
scheduler.ready(new VBEdemo());
// Scheduler starten (schedule() erzeugt den Idle-Thread) // Scheduler starten (schedule() erzeugt den Idle-Thread)
scheduler.schedule(); scheduler.schedule();

View File

@ -8,26 +8,22 @@
* Autor: Michael Schoettner, HHU, 26.12.2016 * * Autor: Michael Schoettner, HHU, 26.12.2016 *
*****************************************************************************/ *****************************************************************************/
#include "kernel/Globals.h"
#include "user/VBEdemo.h" #include "user/VBEdemo.h"
#include "devices/fonts/Fonts.h" #include "devices/fonts/Fonts.h"
#include "kernel/Globals.h"
// Bitmap // Bitmap
#include "bmp_hhu.cc" #include "bmp_hhu.cc"
/***************************************************************************** /*****************************************************************************
* Methode: VBEdemo::linInterPol1D * * Methode: VBEdemo::linInterPol1D *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Farbwert in einer Dimension interpoliert berechnen. * * Beschreibung: Farbwert in einer Dimension interpoliert berechnen. *
*****************************************************************************/ *****************************************************************************/
int VBEdemo::linInterPol1D(int x, int xr, int l, int r) { int VBEdemo::linInterPol1D(int x, int xr, int l, int r) {
return ((((l>>16)*(xr-x)+(r>>16)*x)/xr)<<16) return ((((l >> 16) * (xr - x) + (r >> 16) * x) / xr) << 16) | (((((l >> 8) & 0xFF) * (xr - x) + ((r >> 8) & 0xFF) * x) / xr) << 8) | (((l & 0xFF) * (xr - x) + (r & 0xFF) * x) / xr);
|(((((l>>8)&0xFF)*(xr-x)+((r>>8)&0xFF)*x)/xr)<<8)
|(((l&0xFF)*(xr-x)+(r&0xFF)*x)/xr);
} }
/***************************************************************************** /*****************************************************************************
* Methode: VBEdemo::linInterPol2D * * Methode: VBEdemo::linInterPol2D *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -36,70 +32,65 @@ int VBEdemo::linInterPol1D(int x, int xr, int l, int r) {
int VBEdemo::linInterPol2D(int x, int y, int lt, int rt, int lb, int rb) { int VBEdemo::linInterPol2D(int x, int y, int lt, int rt, int lb, int rb) {
return linInterPol1D(y, vesa.yres, return linInterPol1D(y, vesa.yres,
linInterPol1D(x, vesa.xres, lt, rt), linInterPol1D(x, vesa.xres, lt, rt),
linInterPol1D(x, vesa.xres, lb, rb) ); linInterPol1D(x, vesa.xres, lb, rb));
} }
/***************************************************************************** /*****************************************************************************
* Methode: VBEdemo::drawColors * * Methode: VBEdemo::drawColors *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Pixel-Demo. * * Beschreibung: Pixel-Demo. *
*****************************************************************************/ *****************************************************************************/
void VBEdemo::drawColors () { void VBEdemo::drawColors() {
int x_res=640, y_res=480; int x_res = 640;
int y_res = 480;
for (int y=0; y<y_res; y++) {
for (int x=0; x<x_res; x++) { for (int y = 0; y < y_res; y++) {
for (int x = 0; x < x_res; x++) {
vesa.drawPixel(x, y, linInterPol2D(x, y, 0x0000FF, 0x00FF00, 0xFF0000, 0xFFFF00)); vesa.drawPixel(x, y, linInterPol2D(x, y, 0x0000FF, 0x00FF00, 0xFF0000, 0xFFFF00));
} }
} }
} }
/***************************************************************************** /*****************************************************************************
* Methode: VBEdemo::drawBitmap * * Methode: VBEdemo::drawBitmap *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Bitmap aus GIMP ausgeben. * * Beschreibung: Bitmap aus GIMP ausgeben. *
*****************************************************************************/ *****************************************************************************/
void VBEdemo::drawBitmap () { void VBEdemo::drawBitmap() {
unsigned int sprite_height = hhu.height; unsigned int sprite_height = hhu.height;
unsigned int sprite_width = hhu.width; unsigned int sprite_width = hhu.width;
unsigned int sprite_bpp = hhu.bytes_per_pixel; unsigned int sprite_bpp = hhu.bytes_per_pixel;
unsigned char *sprite_pixel = (unsigned char*)hhu.pixel_data; unsigned char* sprite_pixel = (unsigned char*)hhu.pixel_data;
/* Hier muss Code eingefuegt werden */ /* Hier muss Code eingefuegt werden */
} }
/***************************************************************************** /*****************************************************************************
* Methode: VBEdemo::drawFonts * * Methode: VBEdemo::drawFonts *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Fonts ausgeben. * * Beschreibung: Fonts ausgeben. *
*****************************************************************************/ *****************************************************************************/
void VBEdemo::drawFonts () { void VBEdemo::drawFonts() {
/* Hier muss Code eingefuegt werden */ /* Hier muss Code eingefuegt werden */
} }
/***************************************************************************** /*****************************************************************************
* Methode: VBEdemo::run * * Methode: VBEdemo::run *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Der Anwendungsthread erzeugt drei Threads die Zaehler * * Beschreibung: Der Anwendungsthread erzeugt drei Threads die Zaehler *
* ausgeben und terminiert sich selbst. * * ausgeben und terminiert sich selbst. *
*****************************************************************************/ *****************************************************************************/
void VBEdemo::run () { void VBEdemo::run() {
// In den Grafikmodus schalten (32-Bit Farbtiefe) // In den Grafikmodus schalten (32-Bit Farbtiefe)
vesa.initGraphicMode(MODE_640_480_24BITS); vesa.initGraphicMode(MODE_640_480_24BITS);
vesa.setDrawingBuff(BUFFER_VISIBLE); vesa.setDrawingBuff(BUFFER_VISIBLE);
drawColors(); drawColors();
/* Hier muss Code eingefuegt werden */ /* Hier muss Code eingefuegt werden */
// selbst terminieren // selbst terminieren
scheduler.exit (); scheduler.exit();
} }

View File

@ -10,34 +10,32 @@
#ifndef __VBEdemo_include__ #ifndef __VBEdemo_include__
#define __VBEdemo_include__ #define __VBEdemo_include__
#include "kernel/threads/Thread.h" #include "kernel/threads/Thread.h"
class VBEdemo : public Thread { class VBEdemo : public Thread {
private: private:
VBEdemo (const VBEdemo &copy); // Verhindere Kopieren VBEdemo(const VBEdemo& copy) = delete; // Verhindere Kopieren
// Hilfsfunktionen fuer drawColors() // Hilfsfunktionen fuer drawColors()
int linInterPol1D (int x, int xr, int l, int r); int linInterPol1D(int x, int xr, int l, int r);
int linInterPol2D (int x, int y, int lt, int rt, int lb, int rb); int linInterPol2D(int x, int y, int lt, int rt, int lb, int rb);
public: public:
// Gib dem Anwendungsthread einen Stack. // Gib dem Anwendungsthread einen Stack.
VBEdemo () : Thread () { } VBEdemo() {}
// Thread-Startmethode // Thread-Startmethode
void run (); void run() override;
// Farbraum ausgeben // Farbraum ausgeben
void drawColors (); void drawColors();
// Bitmap aus GIMP ausgeben // Bitmap aus GIMP ausgeben
void drawBitmap (); void drawBitmap();
// Fonts ausgeben // Fonts ausgeben
void drawFonts (); void drawFonts();
}; };
#endif #endif