2 * Acess GUI (AxWin) Version 2
3 * By John Hodge (thePowersGang)
7 #include <acess/devices/terminal.h>
11 void Video_Setup(void);
12 void Video_Update(void);
13 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color);
14 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color);
21 void Video_Setup(void)
26 giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
27 if( giTerminalFD == -1 )
29 fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno);
34 tmpInt = giScreenWidth;
35 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, &tmpInt );
36 if(tmpInt != giScreenWidth)
38 fprintf(stderr, "Warning: Selected width (%i) is invalid, clipped to %i\n",
39 giScreenWidth, tmpInt);
40 giScreenWidth = tmpInt;
44 tmpInt = giScreenHeight;
45 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, &tmpInt );
46 if(tmpInt != giScreenHeight)
48 fprintf(stderr, "Warning: Selected height (%i) is invalid, clipped to %i\n",
49 giScreenHeight, tmpInt);
50 giScreenHeight = tmpInt;
54 tmpInt = TERM_MODE_FB;
55 ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
57 // Force VT8 to be shown
58 ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
60 // Create local framebuffer (back buffer)
61 gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
62 memset32( gpScreenBuffer, 0x8888FF, giScreenWidth*giScreenHeight );
66 void Video_Update(void)
68 //seek(giTerminalFD, 0, SEEK_SET);
69 seek(giTerminalFD, 0, 1);
70 write(giTerminalFD, gpScreenBuffer, giScreenWidth*giScreenHeight*4);
73 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color)
75 uint32_t *buf = gpScreenBuffer + Y*giScreenWidth + X;
77 _SysDebug("Video_FillRect: (X=%i, Y=%i, W=%i, H=%i, Color=%08x)",
80 if(W < 0 || X < 0 || X >= giScreenWidth) return ;
81 if(X + W > giScreenWidth) W = giScreenWidth - X;
83 if(H < 0 || Y < 0 || Y >= giScreenHeight) return ;
84 if(Y + H > giScreenHeight) H = giScreenHeight - Y;
88 memset32( buf, Color, W );
93 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color)
95 Video_FillRect(X, Y, W, 1, Color);
96 Video_FillRect(X, Y+H-1, W, 1, Color);
97 Video_FillRect(X, Y, 1, H, Color);
98 Video_FillRect(X+W-1, Y, 1, H, Color);
102 * \brief Draw an image to the screen
103 * \todo Maybe have support for an offset in the image
105 void Video_DrawImage(short X, short Y, short W, short H, tImage *Image)
108 uint8_t *buf = (uint8_t *)(gpScreenBuffer + Y*giScreenWidth + X);
116 if( X >= giScreenWidth ) return ;
117 if( Y >= giScreenHeight ) return ;
119 // Wrap to image size
120 if( W > Image->Width ) W = Image->Width;
121 if( H > Image->Height ) H = Image->Height;
123 // Wrap to screen size
124 if( X + W > giScreenWidth ) W = giScreenWidth - X;
125 if( Y + H > giScreenHeight ) H = giScreenHeight - Y;
129 switch( Image->Format )
132 for( y = 0; y < H; y ++ )
134 int r, g, b, a; // New
135 int or, og, ob; // Original
136 for( x = 0; x < W; x ++ )
138 b = data[x*4+0]; g = data[x*4+1]; r = data[x*4+2]; a = data[x*4+3];
139 if( a == 0 ) continue; // 100% transparent
140 ob = buf[x*4+0]; og = buf[x*4+1]; or = buf[x*4+2];
144 // Transparent: Handled above
155 r = (or * (255-a) + r * a) / 255;
156 g = (og * (255-a) + g * a) / 255;
157 b = (ob * (255-a) + b * a) / 255;
160 buf[x*4+0] = b; buf[x*4+1] = g; buf[x*4+2] = r;
162 data += Image->Width * 4;
163 buf += giScreenWidth * 4;
169 for( y = 0; y < H; y ++ )
171 for( x = 0; x < W; x ++ )
173 buf[x*4+0] = data[x*3+2]; // Blue
174 buf[x*4+1] = data[x*3+1]; // Green
175 buf[x*4+2] = data[x*3+0]; // Red
178 buf += giScreenWidth * 4;
182 _SysDebug("ERROR: Unknown image format %i\n", Image->Format);