diff --git a/src/sys/graphics/main.C b/src/sys/graphics/main.C new file mode 100755 index 0000000..a4c82fd --- /dev/null +++ b/src/sys/graphics/main.C @@ -0,0 +1,18 @@ +#include "objgfx30.h" +#include + +int main() { + TMode_Rec Mode_Rec; + TVESA_Rec VESA_Rec; + TPixelFmt pixfmt; + TRGB rgb[256]; + TGfx0* buf=0; + buf = new TGfx0(); + // cout << sizeof(buf->pal) << endl; + // cout << sizeof(rgb) << endl; + pixfmt.BPP=8; + buf->create(400,400,&pixfmt); + cout << buf->getMaxX() << endl; + if (buf) delete buf; + return(0); +} diff --git a/src/sys/graphics/makefile b/src/sys/graphics/makefile new file mode 100755 index 0000000..95a910f --- /dev/null +++ b/src/sys/graphics/makefile @@ -0,0 +1,6 @@ +objgfx: main.o objgfx30.o + g++ -o objgfx main.o objgfx30.o +main.o: main.C + g++ -c main.C +objgfx30.o: objgfx30.C objgfx30.h + g++ -c objgfx30.C diff --git a/src/sys/graphics/objgfx30.C b/src/sys/graphics/objgfx30.C new file mode 100755 index 0000000..a617e7e --- /dev/null +++ b/src/sys/graphics/objgfx30.C @@ -0,0 +1,85 @@ +#include "objgfx30.h" +#include + +// TGfx0 constructor + +TGfx0::TGfx0() { + DataState = og_None; + Buffer = 0; + LineOfs = 0; + *pal = 0; + xRes = 0; + yRes = 0; + MaxX = 0; + MaxY = 0; + bSize = 0; + lSize = 0; + TransparentColor = 0; + BPP = 0; + RedShifter = 0; + GreenShifter = 0; + BlueShifter = 0; + RedFieldPosition = 0; + GreenFieldPosition = 0; + BlueFieldPosition = 0; + return; +} // TGfx0::TGfx0() + + +bool TGfx0::create(UInt32 _xRes, UInt32 _yRes, TPixelFmt* _pixformat) { + UInt32 yy; + if (DataState==og_Owner) { + if (Buffer) free(Buffer); + if (LineOfs) free(LineOfs); + if (*pal) free(*pal); + } // if datastate + BPP = _pixformat->BPP; + bSize=_xRes*_yRes*((BPP+7) >> 3); + Buffer = malloc(bSize); + if (!Buffer) return FALSE; + lSize = _yRes*sizeof(UInt32); + LineOfs = (UInt32*)malloc(lSize); + if (!LineOfs) return FALSE; + // allocate pal here + // *pal=malloc(sizeof( + MaxX=_xRes-1; + xRes=_xRes; + MaxY=_yRes-1; + LineOfs[0]=0; + for (yy=1; yy> 3); + DataState = og_Owner; + // For 8bpp modes the next part doesn't matter + RedFieldPosition=_pixformat->RedFieldPosition; + GreenFieldPosition=_pixformat->GreenFieldPosition; + BlueFieldPosition=_pixformat->BlueFieldPosition; + // The next part is only used by 15/16hpp + RedShifter=8-_pixformat->RedMaskSize; + GreenShifter=8-_pixformat->GreenMaskSize; + BlueShifter=8-_pixformat->BlueMaskSize; + Owner = this; + return TRUE; +} // TGfx0::create + +UInt32 TGfx0::getMaxX() { + return MaxX; +} // TGfx0::getMaxX + +UInt32 TGfx0::getMaxY() { + return MaxY; +} // TGfx0::getMaxY + +TGfx0::~TGfx0() { + if (DataState == og_Owner) { + if (*pal) free(pal); + if (Buffer) free(Buffer); + if (LineOfs) free(LineOfs); + } // if datastate + *pal=0; + LineOfs=0; + Buffer=0; + bSize=0; + lSize=0; + DataState = og_None; + return; +} // TGfx0::~TGfx0() diff --git a/src/sys/graphics/objgfx30.h b/src/sys/graphics/objgfx30.h new file mode 100755 index 0000000..d735484 --- /dev/null +++ b/src/sys/graphics/objgfx30.h @@ -0,0 +1,137 @@ +#ifndef OBJGFX30_H +#define OBJGFX30_H + +#define TRUE 1 +#define FALSE 0 +#define gm320x200x256 0x13 +#define gm640x480x256 0x101 +#define gm800x600x256 0x103 +#define gm1024x768x256 0x105 +#define gm1280x1024x256 0x107 + + /* 32768 color video mode constants */ +#define gm640x480x32k 0x110 +#define gm800x600x32k 0x113 +#define gm1024x768x32k 0x116 +#define gm1280x1024x32k 0x119 + + /* 65536 color video mode constants */ +#define gm640x480x64k 0x111 +#define gm800x600x64k 0x114 +#define gm1024x768x64k 0x117 +#define gm1280x1024x64k 0x11A + + /* 16.8 million color video mode constants */ +#define gm640x480x16m 0x112 +#define gm800x600x16m 0x115 +#define gm1024x768x16m 0x118 +#define gm1280x1024x16m 0x11B + +typedef signed char Int8; +typedef signed short int Int16; +typedef signed long Int32; + +typedef unsigned char UInt8; +typedef unsigned short int UInt16; +typedef unsigned long UInt32; + +enum og_DataState { og_None, og_Owner, og_Aliasing }; + +typedef struct { + UInt8 red; + UInt8 green; + UInt8 blue; + } TRGB; + +typedef struct { + UInt16 ModeAttributes; + UInt8 WindowAFlags; + UInt8 WindowBFlags; + UInt16 Granularity; + UInt16 WindowSize; + UInt16 WindowASeg; + UInt16 WindowBSeg; + void* BankSwitch; + UInt16 BytesPerLine; + UInt16 xRes, yRes; + UInt8 CharWidth; + UInt8 CharHeight; + UInt8 NumBitPlanes; + UInt8 BitsPerPixel; + UInt8 NumberOfBanks; + UInt8 MemoryModel; + UInt8 BankSize; + UInt8 NumOfImagePages; + UInt8 Reserved; + // Direct colour fields (required for Direct/6 and YUV/7 memory models + UInt8 RedMaskSize; + UInt8 RedFieldPosition; + UInt8 GreenMaskSize; + UInt8 GreenFieldPosition; + UInt8 BlueMaskSize; + UInt8 BlueFieldPosition; + UInt8 RsvdMaskSize; + UInt8 RsvdFieldPosition; + UInt8 DirectColourMode; + // VESA 2.0 specific fields + UInt32 PhysBasePtr; + void* OffScreenMemOffset; + UInt16 OffScreenMemSize; + UInt8 paddington[461]; + } TMode_Rec; + +typedef struct { + char VBESignature[4]; + UInt8 minVersion; + UInt8 majVersion; + char * OEMStringPtr; + UInt32 Capabilities; + UInt16* VideoModePtr; + UInt16 TotalMemory; + // VESA 2.0 specific fields + UInt16 OEMSoftwareRev; + char * OEMVendorNamePtr; + char * OEMProductNamePtr; + char * OEMProductRevPtr; + UInt8 paddington[474]; + } TVESA_Rec; + +typedef struct { + UInt8 BPP; + UInt8 RedFieldPosition; + UInt8 GreenFieldPosition; + UInt8 BlueFieldPosition; + UInt8 RedMaskSize; + UInt8 BlueMaskSize; + UInt8 GreenMaskSize; + } TPixelFmt; + +class TGfx0 { + public: + // owner + TGfx0* Owner; + void* Buffer; + UInt32* LineOfs; + TRGB* pal[256]; + UInt32 xRes, yRes; + UInt32 MaxX, MaxY; + UInt32 bSize; // buffer size (in bytes) + UInt32 lSize; // LineOfs size (in bytes) + UInt32 TransparentColor; + og_DataState DataState; + UInt8 BPP; // bits per pixel + UInt8 RedFieldPosition; + UInt8 GreenFieldPosition; + UInt8 BlueFieldPosition; + UInt8 RedShifter; + UInt8 GreenShifter; + UInt8 BlueShifter; + public: + TGfx0(); + bool create(UInt32, UInt32, TPixelFmt*); + UInt32 getMaxX(); + UInt32 getMaxY(); + ~TGfx0(); + }; // gfx0 + +#endif