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);
19 void Video_Setup(void)
24 giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
25 if( giTerminalFD == -1 )
27 fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno);
32 tmpInt = giScreenWidth;
33 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, &tmpInt );
34 if(tmpInt != giScreenWidth)
36 fprintf(stderr, "Warning: Selected width (%i) is invalid, clipped to %i\n",
37 giScreenWidth, tmpInt);
38 giScreenWidth = tmpInt;
42 tmpInt = giScreenHeight;
43 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, &tmpInt );
44 if(tmpInt != giScreenHeight)
46 fprintf(stderr, "Warning: Selected height (%i) is invalid, clipped to %i\n",
47 giScreenHeight, tmpInt);
48 giScreenHeight = tmpInt;
52 tmpInt = TERM_MODE_FB;
53 ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
55 // Force VT8 to be shown
56 ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
58 // Create local framebuffer (back buffer)
59 gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
60 memset32( gpScreenBuffer, 0x8888FF, giScreenWidth*giScreenHeight );
64 void Video_Update(void)
66 //seek(giTerminalFD, 0, SEEK_SET);
67 seek(giTerminalFD, 0, 1);
68 write(giTerminalFD, giScreenWidth*giScreenHeight*4, gpScreenBuffer);
71 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color)
73 uint32_t *buf = gpScreenBuffer + Y*giScreenWidth + X;
75 _SysDebug("Video_FillRect: (X=%i, Y=%i, W=%i, H=%i, Color=%08x)",
78 if(W < 0 || X < 0 || X >= giScreenWidth) return ;
79 if(X + W > giScreenWidth) W = giScreenWidth - X;
81 if(H < 0 || Y < 0 || Y >= giScreenHeight) return ;
82 if(Y + H > giScreenHeight) H = giScreenHeight - Y;
86 memset32( buf, Color, W );
91 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color)
93 Video_FillRect(X, Y, W, 1, Color);
94 Video_FillRect(X, Y+H-1, W, 1, Color);
95 Video_FillRect(X, Y, 1, H, Color);
96 Video_FillRect(X+W-1, Y, 1, H, Color);
100 * \brief Draw an image to the screen
101 * \todo Maybe have support for an offset in the image
103 void Video_DrawImage(short X, short Y, short W, short H, tImage *Image)
106 uint8_t *buf = (uint8_t *)(gpScreenBuffer + Y*giScreenWidth + X);
114 if( X >= giScreenWidth ) return ;
115 if( Y >= giScreenHeight ) return ;
117 // Wrap to image size
118 if( W > Image->Width ) W = Image->Width;
119 if( H > Image->Height ) H = Image->Height;
121 // Wrap to screen size
122 if( X + W > giScreenWidth ) W = giScreenWidth - X;
123 if( Y + H > giScreenHeight ) H = giScreenHeight - Y;
127 switch( Image->Format )
130 for( y = 0; y < H; y ++ )
132 int r, g, b, a; // New
133 int or, og, ob; // Original
134 for( x = 0; x < W; x ++ ) {
135 b = data[x*4+0]; g = data[x*4+1]; r = data[x*4+2]; a = data[x*4+3];
136 if( a == 0 ) continue; // 100% transparent
137 ob = buf[x*4+0]; og = buf[x*4+1]; or = buf[x*4+2];
141 // Transparent: Handled above
152 r = (or * (255-a) + r * a) / 255;
153 g = (og * (255-a) + g * a) / 255;
154 b = (ob * (255-a) + b * a) / 255;
157 buf[x*4+0] = b; buf[x*4+1] = g; buf[x*4+2] = r;
159 data += Image->Width * 4;
160 buf += giScreenWidth * 4;
166 for( y = 0; y < H; y ++ )
168 for( x = 0; x < W; x ++ ) {
169 buf[x*4+0] = data[x*3+2]; // Blue
170 buf[x*4+1] = data[x*3+1]; // Green
171 buf[x*4+2] = data[x*3+0]; // Red
174 buf += giScreenWidth * 4;