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

View File

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

View File

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

View File

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

View File

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