diff --git a/src/sys/graphics/main.cpp b/src/sys/graphics/main.cpp index 1219323..fafe393 100755 --- a/src/sys/graphics/main.cpp +++ b/src/sys/graphics/main.cpp @@ -21,11 +21,15 @@ buf = new TGfx0(); buf2 = new TGfx0(); font = new TDPFont(buf); - buf->create(400,400,(TPixelFmt *)&def_pixfmt_16bpp); - buf2->create(400,400,(TPixelFmt *)&def_pixfmt_15bpp); + buf->create(400,400,(TPixelFmt *)&def_pixfmt_24bpp); +// buf2->create(400,400,(TPixelFmt *)&def_pixfmt_15bpp); + buf2->alias(buf,3,3,8,8); + buf2->putPixel(0,0,1); + buf2->putPixel(buf2->getMaxX(),buf2->getMaxY(),1); + buf2->clear(1); result = font->Load("PACMAN.DPF"); font->SetColor(1); - font->PutText(0,0,"HelloWorld"); + font->PutText(0,0," loWorld"); for (r=0; r<=15; r++) { for (g=0; g<=79; g++) if (buf->getPixel(g,r)) printf("*"); else printf(" "); diff --git a/src/sys/graphics/objgfx30.cpp b/src/sys/graphics/objgfx30.cpp index 4a8e428..b094b4c 100755 --- a/src/sys/graphics/objgfx30.cpp +++ b/src/sys/graphics/objgfx30.cpp @@ -5,6 +5,7 @@ #include "objgfx30.h" #include #include +#include #include // TGfx0 constructor @@ -30,8 +31,206 @@ return; } // TGfx0::TGfx0() +bool +TGfx0::alias(TGfx0* SrcObject, UInt32 x1, UInt32 y1, UInt32 x2, UInt32 y2) { + UInt32 tmp; + printf("in alias\n"); + if (DataState==og_Owner) return FALSE; -bool TGfx0::create(UInt32 _xRes, UInt32 _yRes,TPixelFmt* _pixformat) { + if (x2Buffer)+x1*((SrcObject->BPP+7) >> 3)); + LineOfs=((UInt32 *)SrcObject->LineOfs)+y1; + pal = SrcObject->pal; + xRes = SrcObject->xRes; + yRes = SrcObject->yRes; + MaxX = (x2-x1); + MaxY = (y2-y1); + bSize = 0; + lSize = 0; + TransparentColor = SrcObject->TransparentColor; + DataState = og_Aliasing; + BPP = SrcObject->BPP; + // For 8bpp modes the next part doesn't matter + RedFieldPosition = SrcObject->RedFieldPosition; + GreenFieldPosition = SrcObject->GreenFieldPosition; + BlueFieldPosition = SrcObject->BlueFieldPosition; + // The next part is only used by 15/16bpp + RedShifter = SrcObject->RedShifter; + GreenShifter = SrcObject->GreenShifter; + BlueShifter = SrcObject->BlueShifter; + return TRUE; +} // TGfx0::alias + +void +TGfx0::arc(UInt32 x_center, UInt32 y_center, UInt32 radius, + UInt32 s_angle, UInt32 e_angle, UInt32 colour) { +} // TGfx0::arc + +void +TGfx0::bar(Int32 x1, Int32 y1, Int32 x2, Int32 y2, UInt32 colour) { + Int32 yy; + Int32 tmp; + + if (x2(Int32)MaxY)) return; + if (y1<0) y1=0; + if (y2>(Int32)MaxY) y2=MaxY; + for (yy=y1; yy<=y2; yy++) + horizLine(x1,x2,yy,colour); +} // TGfx0::bar + +void +TGfx0::circle(Int32 x_center, Int32 y_center, UInt32 radius, UInt32 colour) { + +} // TGfx0::circle + +void +TGfx0::clear(UInt32 colour) { + UInt32 height; + if ((Buffer==NULL) || (LineOfs==NULL)) return; + asm("cld\n"); + switch (BPP) { + case 8: + asm( + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%edx \n" // inc edx (MaxY) + " inc %%ebx \n" // inc ebx (MaxX) + " sub %%edx, %%esi \n" // sub esi, edx + " mov %%al, %%ah \n" // mov ah, al + " mov %%ax, %%cx \n" // mov cx, ax + " shl $16, %%eax \n" // shl eax, 16 + " mov %%cx, %%ax \n" // mov ax, cx + "loop8: \n" + " push %%edx \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " and $3, %%edx \n" // and edx, 3 + " shr $2, %%ecx \n" // shr ecx, 2 + " rep \n" + " stosl \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " rep \n" + " stosb \n" + " pop %%edx \n" + " add %%esi, %%edi \n" // add edi, esi + " dec %%ebx \n" + " jnz loop8 \n" + : + : "D" (Buffer), "S" (LineOfs), // %0, %1 + "a" (colour), "b" (MaxY), // %2, %3 + "c" (xRes), "d" (MaxX) // %4, %5 + ); + break; + case 15: + case 16: + asm( + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%edx \n" // inc edx (MaxX) + " inc %%ebx \n" // inc ebx (MaxY) + " sub %%edx, %%esi \n" // sub esi, edx + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " mov %%ax, %%cx \n" // mov cx, ax + " shl $16, %%eax \n" // shl eax, 16 + " mov %%cx, %%ax \n" // mov ax, cx + "loop16: \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " shr $1, %%ecx \n" // shr ecx, 1 + " rep \n" + " stosl \n" + " jnc noc16 \n" + " stosw \n" + "noc16: \n" + " add %%esi, %%edi \n" // add edi, esi + " dec %%ebx \n" + " jnz loop16 \n" + : + : "D" (Buffer), "S" (LineOfs), // %0, %1 + "a" (colour), "b" (MaxY), // %2, %3 + "c" (xRes), "d" (MaxX) // %4, %5 + ); + break; + case 24: + asm( + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%edx \n" // inc edx (MaxX) + " inc %%ebx \n" // inc ebx (MaxY) + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " mov %%ebx, %6 \n" // mov height, ebx + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " mov %%eax, %%ebx \n" // mov ebx, eax + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " shr $16, %%ebx \n" // shr ebx, 16 + "oloop24: \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + "iloop24: \n" + " mov %%ax,(%%edi) \n" // mov [edi],ax + " movb %%bl,2(%%edi) \n" // mov [edi+2],bl + " add $3, %%edi \n" // add edi, 3 + " dec %%ecx \n" // dec ecx + " jnz iloop24 \n" + " add %%esi, %%edi \n" // add edi, esi + " decl %6 \n" // dec height + " jnz oloop24 \n" + : + : "D" (Buffer), "S" (LineOfs), // %0, %1 + "a" (colour), "b" (MaxY), // %2, %3 + "c" (xRes), "d" (MaxX), // %4, %5 + "g" (height) // %6 + ); + break; + case 32: + asm( + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%ebx \n" // inc ebx (MaxX) + " inc %%edx \n" // inc edx (MaxY) + " mov %%ebx, %%ecx \n" // mov ecx, ebx + " shl $2, %%ecx \n" // shl ecx, 2 + " sub %%ecx, %%esi \n" // sub esi, ecx // adjust for pix size + "loop32: \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " rep \n" + " stosl \n" + " add %%esi, %%edi \n" // add edi, esi + " dec %%ebx \n" + " jnz loop32 \n" + : + : "D" (Buffer), "S" (LineOfs), // %0, %1 + "a" (colour), "b" (MaxY), // %2, %3 + "c" (xRes), "d" (MaxX) // %4, %5 + ); + } +} // TGfx0::clear + +void +TGfx0::clone(TGfx0* SrcObject) { + +} // TGfx0::clone + +bool +TGfx0::create(UInt32 _xRes, UInt32 _yRes,TPixelFmt* _pixformat) { /* * constructor TGfx0::create() * Allocates memory for a buffer of size _xRes by _yRes with @@ -75,12 +274,13 @@ return TRUE; } // TGfx0::create -void TGfx0::copy(TGfx0* SrcObject) { +void +TGfx0::copy(TGfx0* SrcObject) { UInt32 count, xCount, yCount; UInt32 xx, yy; UInt8 r, g, b; - if (!Buffer) return; - if (!SrcObject->Buffer) return; + if (Buffer==NULL) return; + if (SrcObject->Buffer==NULL) return; xCount = SrcObject->MaxX+1; if (xCount>MaxX+1) xCount=MaxX; yCount = SrcObject->MaxY+1; @@ -104,18 +304,21 @@ } // else } // TGfx0::copy -UInt32 TGfx0::getMaxX(void) { +UInt32 +TGfx0::getMaxX(void) { return MaxX; } // TGfx0::getMaxX -UInt32 TGfx0::getMaxY(void) { +UInt32 +TGfx0::getMaxY(void) { return MaxY; } // TGfx0::getMaxY -UInt32 TGfx0::getPixel(UInt32 x, UInt32 y) { +UInt32 +TGfx0::getPixel(UInt32 x, UInt32 y) { UInt32 result; result = 42; - if ((!Buffer) || (!LineOfs)) return TransparentColor; + if ((Buffer==NULL) || (LineOfs==NULL)) return TransparentColor; if ((x<0) || (x>MaxX) || (y<0) || y>MaxY) return TransparentColor; switch (BPP) { case 8: @@ -168,7 +371,7 @@ " shl $2, %%ecx \n" // shl ecx, 2 {adjust for pixel size} " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx*4] " add %%ecx, %%edi \n" // add edi, ecx - " mov (%%edi),%%eax \n" // edx,word ptr [edi] + " mov (%%edi),%%eax \n" // eax,word ptr [edi] " mov %%eax, %4 \n" // mov result, eax : : "D" (Buffer), "S" (LineOfs), // %0, %1 @@ -179,8 +382,14 @@ return result; } // TGfx0::getPixel -void TGfx0::putPixel(UInt32 x, UInt32 y, UInt32 colour) { - if ((!Buffer) || (!LineOfs)) return; +void +TGfx0::horizLine(Int32 x1, Int32 x2, Int32 y, UInt32 colour) { + +} // TGfx0::horizLine + +void +TGfx0::putPixel(UInt32 x, UInt32 y, UInt32 colour) { + if ((Buffer==NULL) || (LineOfs==NULL)) return; if ((x<0) || (x>MaxX) || (y<0) || y>MaxY) return; switch (BPP) { case 8: @@ -247,7 +456,8 @@ return; } // TGfx0::putPixel -UInt32 TGfx0::RGB(UInt8 red, UInt8 green, UInt8 blue) { +UInt32 +TGfx0::RGB(UInt8 red, UInt8 green, UInt8 blue) { UInt32 lastclr; lastclr=0; switch (BPP) { @@ -361,7 +571,8 @@ return lastclr; } // TGfx0::RGB -void TGfx0::setRGBPalette(UInt8 colour, UInt8 red, UInt8 green, UInt8 blue) { +void +TGfx0::setRGBPalette(UInt8 colour, UInt8 red, UInt8 green, UInt8 blue) { if (!pal) return; pal[colour].red = red; pal[colour].green = green; @@ -369,7 +580,8 @@ return; } // TGfx0::setRGBPalette -void TGfx0::unpackRGB(UInt32 colour, UInt8* red, UInt8* green, UInt8* blue) { +void +TGfx0::unpackRGB(UInt32 colour, UInt8* red, UInt8* green, UInt8* blue) { switch (BPP) { case 8: if (!pal) { @@ -408,15 +620,15 @@ TGfx0::~TGfx0(void) { if (DataState == og_Owner) { - if (pal) free(pal); - if (Buffer) free(Buffer); - if (LineOfs) free(LineOfs); + if (pal!=NULL) free(pal); + if (Buffer!=NULL) free(Buffer); + if (LineOfs!=NULL) free(LineOfs); } // if datastate - pal=0; - LineOfs=0; - Buffer=0; - bSize=0; - lSize=0; + pal = NULL; + LineOfs= NULL; + Buffer = NULL; + bSize = 0; + lSize = 0; DataState = og_None; return; } // TGfx0::~TGfx0() diff --git a/src/sys/graphics/objgfx30.h b/src/sys/graphics/objgfx30.h index 309c2d2..f5815be 100755 --- a/src/sys/graphics/objgfx30.h +++ b/src/sys/graphics/objgfx30.h @@ -145,11 +145,19 @@ UInt8 BlueShifter; public: TGfx0(void); - bool create(UInt32, UInt32,TPixelFmt*); + bool alias(TGfx0*, UInt32, UInt32, UInt32, UInt32); + void arc(UInt32, UInt32, UInt32, UInt32, UInt32, UInt32); + void bar(Int32, Int32, Int32, Int32, UInt32); + // void bSpline + void circle(Int32, Int32, UInt32, UInt32); + bool create(UInt32, UInt32, TPixelFmt*); + void clear(UInt32); + void clone(TGfx0*); void copy(TGfx0*); UInt32 getMaxX(void); UInt32 getMaxY(void); UInt32 getPixel(UInt32, UInt32); + void horizLine(Int32, Int32, Int32, UInt32); void putPixel(UInt32, UInt32, UInt32); UInt32 RGB(UInt8, UInt8, UInt8); void setRGBPalette(UInt8, UInt8, UInt8, UInt8); @@ -157,4 +165,5 @@ ~TGfx0(void); }; // gfx0 + #endif