diff --git a/src/sys/graphics/main.cpp b/src/sys/graphics/main.cpp index ff9d76d..0764258 100755 --- a/src/sys/graphics/main.cpp +++ b/src/sys/graphics/main.cpp @@ -9,24 +9,21 @@ #include int main() { - TPixelFmt pixfmt; - UInt32 foo; +// UInt32 foo; + UInt8 r, g, b; + r=0; + g=0; + b=0; TGfx0* buf=0; TGfx0* buf2=0; buf = new TGfx0(); buf2 = new TGfx0(); - pixfmt.BPP=8; buf->create(400,400,(TPixelFmt *)&def_pixfmt_8bpp); buf2->create(400,400,(TPixelFmt *)&def_pixfmt_8bpp); - buf->flip(buf2); - buf->setRGBPalette(0,253,255,255); - buf->setRGBPalette(1,255,251,255); - buf->setRGBPalette(2,251,255,255); - buf->setRGBPalette(3,255,255,255); - buf->setRGBPalette(4,255,253,255); - buf->setRGBPalette(5,255,255,251); - foo=buf->RGB(255,255,255); - printf("%d\n",(int)foo); + buf->putpixel(10,10,69); + r=buf->getpixel(10,10); + printf("%d\n",r); if (buf) delete buf; + if (buf2) delete buf2; return(0); } diff --git a/src/sys/graphics/objgfx30.cpp b/src/sys/graphics/objgfx30.cpp index 589da97..f4cea3f 100755 --- a/src/sys/graphics/objgfx30.cpp +++ b/src/sys/graphics/objgfx30.cpp @@ -4,6 +4,7 @@ #include "objgfx30.h" #include +#include // TGfx0 constructor @@ -31,6 +32,12 @@ bool TGfx0::create(UInt32 _xRes, UInt32 _yRes,TPixelFmt* _pixformat) { + /* + * constructor TGfx0::create() + * Allocates memory for a buffer of size _xRes by _yRes with + * the pixel format defined in _pixformat. Allocates memory + * for pal and LineOfs. + */ UInt32 yy; if (DataState==og_Owner) { if (Buffer) free(Buffer); @@ -41,16 +48,13 @@ bSize=_xRes*_yRes*((BPP+7) >> 3); Buffer = malloc(bSize); if (!Buffer) return FALSE; + memset(Buffer,0,bSize); lSize = _yRes*sizeof(UInt32); LineOfs = (UInt32*)malloc(lSize); if (!LineOfs) return FALSE; pal = (TRGB*)malloc(256*sizeof(TRGB)); if (!pal) return FALSE; - for (yy = 0; yy<=256; yy++) { - pal[yy].red = 0; - pal[yy].green = 0; - pal[yy].blue = 0; - } // for + memset(pal,0,sizeof(TRGB)*256); MaxX=_xRes-1; xRes=_xRes; MaxY=_yRes-1; @@ -96,7 +100,7 @@ for (count=0; count<=yCount; count++) ; memcpy(((char*)Buffer+LineOfs[count]), // dest ((char*)SrcObject->Buffer+SrcObject->LineOfs[count]), // src - xCount); // len + xCount); // len } // else } // TGfx0::flip @@ -109,22 +113,103 @@ } // TGfx0::getMaxY UInt32 TGfx0::getpixel(UInt32 x, UInt32 y) { - return 0; + UInt32 result; + result = 42; + if ((!Buffer) || (!LineOfs)) return TransparentColor; + if ((x<0) || (x>MaxX) || (y<0) || y>MaxY) return TransparentColor; + switch (BPP) { + case 8: + asm( + " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx*4] + " add %%ecx, %%edi \n" // add edi, ecx + " movzbl (%%edi),%%eax \n" // edx,byte ptr [edi] + " mov %%eax, %4 \n" // mov result, eax + : + : "D" (Buffer), "S" (LineOfs), // %0, %1 + "c" (x), "b" (y), // %2, %3 + "m" (result) // %4 + ); + break; + } // switch + return result; } // TGfx0::getpixel void TGfx0::putpixel(UInt32 x, UInt32 y, UInt32 colour) { + if ((!Buffer) || (!LineOfs)) return; + if ((x<0) || (x>MaxX) || (y<0) || y>MaxY) return; + switch (BPP) { + case 8: + asm( + // { Calculate offset, prepare the pixel to be drawn } + " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] + " mov %4, %%eax \n" // mov eax, colour + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%al, (%%edi) \n" // mov [edi], al + : + : "D" (Buffer), "S" (LineOfs), // %0, %1 + "c" (x), "b" (y), // %2, %3 + "m" (colour) // %4 + ); + break; + case 15: + case 16: + asm( + // { Calculate offset, prepare the pixel to be drawn } + " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] + " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} + " mov %4, %%eax \n" // mov eax, colour + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], al + : + : "D" (Buffer), "S" (LineOfs), // %0, %1 + "c" (x), "b" (y), // %2, %3 + "m" (colour) // %4 + ); + break; + case 24: + asm( + " mov %3, %%ebx \n" // mov ebx, [y] + " mov %2, %%ecx \n" // mov ecx, [x] + // { Check horizontal visibility } + " mov %5, %%edx \n" // mov edx, maxY + " cmp %%edx, %%ebx \n" // cmp ebx, edx + " ja Exit \n" + // { Check vertical visibility } + " mov %4, %%edx \n" // mov edx, maxX + " mov %%edx, %%ecx \n" // cmp ecx, edx + " ja Exit \n" + // { Calculate offset, prepare the pixel to be drawn } + " mov %%edx, (%%esi,%%ebx,4) \n" // mov edx, [esi + ebx * 4] + " add %%edx, %%edx \n" // add edi, edx + " mov %6, %%eax \n" // mov eax, colour + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ecx, %%edi \n" // add ecx, ecx {adjust for pixel size} + " add %%ecx, %%edi \n" // add ecx, ecx {adjust for pixel size} + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], ax + " shr $16, %%eax \n" // shr eax, 16 + " mov %%al, 2(%%edi)\n" // mov [edi+2],al + "Exit: \n" + : + : "D" (Buffer), "S" (LineOfs), // %0, %1 + "m" (x), "m" (y), // %2, %3 + "m" (MaxX), "m" (MaxY), "m" (colour) // %4, %5, %6 + ); + } // switch return; } // TGfx0::putpixel UInt32 TGfx0::RGB(UInt8 red, UInt8 green, UInt8 blue) { UInt32 lastclr; - lastclr=1000; + lastclr=0; switch (BPP) { case 8: asm( - "movl $256,%%ecx \n" - "movl $769,%%ebx \n" - "xor %%eax,%%eax \n" + " movl $256,%%ecx \n" + " movl $256*3+1,%%ebx \n" + " xor %%eax,%%eax \n" "lop: \n" " pushl %%eax \n" " mov (%%esi),%%al \n" @@ -161,6 +246,70 @@ : "S" (pal), "m" (red), "m" (green), "m" (blue), "m" (lastclr) ); break; + case 15: + case 16: + asm( + " xor %%eax, %%eax \n" + " xor %%ebx, %%ebx \n" + " xor %%ecx, %%ecx \n" + " mov %0, %%al \n" // mov al, red + " mov %3, %%cl \n" // mov cl, RedShifter + " shr %%cl, %%al \n" // shr al, cl + " mov %4, %%cl \n" // mov cl, RedFieldPosition + " shl %%cl, %%eax \n" // shl eax, cl + " mov %%eax, %%ebx \n" // mov ebx, eax + " xor %%eax, %%eax \n" // xor eax, eax + " mov %1, %%al \n" // mov al, green + " mov %5, %%cl \n" // mov cl, GreenShifter + " shr %%cl, %%al \n" // shr al, cl + " mov %6, %%cl \n" // mov cl, GreenFieldPosition + " shl %%cl, %%eax \n" // shl eax, cl + " or %%eax, %%ebx \n" // or eax, ebx + " xor %%eax, %%eax \n" // xor eax, eax + " mov %2, %%al \n" // mov al, blue + " mov %7, %%cl \n" // mov cl, BlueShifter + " shr %%cl, %%al \n" // shr al, cl + " mov %8, %%cl \n" // mov cl, BlueFieldPosition + " shl %%cl, %%eax \n" // shl eax, cl + " or %%ebx, %%eax \n" // or eax, ebx + " mov %%eax, %9 \n" // mov lastclr, eax + : + : "m" (red), "m" (green), "m" (blue), // %0, %1, %2 + "m" (RedShifter), "m" (RedFieldPosition), // %3, %4 + "m" (GreenShifter), "m" (GreenFieldPosition), // %5, %6 + "m" (BlueShifter), "m" (BlueFieldPosition), // %7, %8 + "m" (lastclr) // %9 + ); + break; + case 24: + case 32: + asm( + " xor %%eax, %%eax \n" // xor eax, eax + " xor %%ebx, %%ebx \n" // xor ebx, ebx + " xor %%ecx, %%ecx \n" // xor ecx, ecx + + " mov %0, %%al \n" // mov al, red + " mov %3, %%cl \n" // mov cl, RedFieldPosition + " shl %%cl, %%eax \n" // shl eax, cl + " mov %%eax, %%ebx \n" // mov ebx, eax + " xor %%eax, %%eax \n" // xor eax, eax + " mov %1, %%al \n" // mov al, green + " mov %4, %%cl \n" // mov cl, GreenFieldPosition + " shl %%cl, %%eax \n" // shl eax, cl + " or %%eax, %%ebx \n" // or ebx, eax + " xor %%eax, %%eax \n" // xor eax, eax + " mov %2, %%al \n" // mov al, blue + " mov %5, %%cl \n" // mov cl, BlueFieldPosition + " shl %%cl, %%eax \n" // shl eax, cl + " or %%ebx, %%eax \n" // or eax, ebx + " mov %%eax, %6 \n" // mov lastclr, eax + : + : "m" (red), "m" (green), "m" (blue), // %0, %1, %2 + "m" (RedFieldPosition), // %3 + "m" (GreenFieldPosition), // %4 + "m" (BlueFieldPosition), // %5 + "m" (lastclr) // %6 + ); } // switch //asm("": "=a" (lastclr)); return lastclr; @@ -187,6 +336,9 @@ *red = ((colour >> RedFieldPosition) << RedShifter); *green = ((colour >> GreenFieldPosition) << GreenShifter); *blue = ((colour >> BlueFieldPosition) << BlueShifter); + if ((*red) && (RedShifter)) *red+=(1 << RedShifter)-1; + if ((*green) && (GreenShifter)) *green+=(1 << GreenShifter)-1; + if ((*blue) && (BlueShifter)) *blue+=(1 << BlueShifter)-1; break; case 24: case 32: diff --git a/src/sys/graphics/objgfx30.h b/src/sys/graphics/objgfx30.h index 3a4384d..403af6f 100755 --- a/src/sys/graphics/objgfx30.h +++ b/src/sys/graphics/objgfx30.h @@ -106,8 +106,8 @@ UInt8 GreenFieldPosition; UInt8 BlueFieldPosition; UInt8 RedMaskSize; - UInt8 BlueMaskSize; UInt8 GreenMaskSize; + UInt8 BlueMaskSize; } TPixelFmt; // Default pixel formats