2 * Acess2 GUI (AxWin) Version 3
3 * - By John Hodge (thePowersGang)
10 #include <acess/devices/terminal.h>
12 #include "resources/cursor.h"
15 void Video_Setup(void);
16 void Video_SetCursorPos(short X, short Y);
17 void Video_Update(void);
18 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color);
19 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color);
26 void Video_Setup(void)
31 giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
32 if( giTerminalFD == -1 )
34 fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno);
39 tmpInt = giScreenWidth;
40 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, &tmpInt );
41 if(tmpInt != giScreenWidth)
43 fprintf(stderr, "Warning: Selected width (%i) is invalid, clipped to %i\n",
44 giScreenWidth, tmpInt);
45 giScreenWidth = tmpInt;
49 tmpInt = giScreenHeight;
50 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, &tmpInt );
51 if(tmpInt != giScreenHeight)
53 fprintf(stderr, "Warning: Selected height (%i) is invalid, clipped to %i\n",
54 giScreenHeight, tmpInt);
55 giScreenHeight = tmpInt;
59 tmpInt = TERM_MODE_FB;
60 ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
62 // Force VT to be shown
63 ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
65 // Create local framebuffer (back buffer)
66 gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
67 memset32( gpScreenBuffer, 0x8888FF, giScreenWidth*giScreenHeight );
69 // Set cursor position and bitmap
70 ioctl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap);
71 Video_SetCursorPos( giScreenWidth/2, giScreenHeight/2 );
76 void Video_Update(void)
78 //seek(giTerminalFD, 0, SEEK_SET);
79 seek(giTerminalFD, 0, 1);
80 write(giTerminalFD, gpScreenBuffer, giScreenWidth*giScreenHeight*4);
83 void Video_SetCursorPos(short X, short Y)
89 pos.x = giVideo_CursorX = X;
90 pos.y = giVideo_CursorY = Y;
91 ioctl(giTerminalFD, TERM_IOCTL_GETSETCURSOR, &pos);
94 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color)
96 uint32_t *buf = gpScreenBuffer + Y*giScreenWidth + X;
98 _SysDebug("Video_FillRect: (X=%i, Y=%i, W=%i, H=%i, Color=%08x)",
101 if(W < 0 || X < 0 || X >= giScreenWidth) return ;
102 if(X + W > giScreenWidth) W = giScreenWidth - X;
104 if(H < 0 || Y < 0 || Y >= giScreenHeight) return ;
105 if(Y + H > giScreenHeight) H = giScreenHeight - Y;
109 memset32( buf, Color, W );
110 buf += giScreenWidth;
114 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color)
116 Video_FillRect(X, Y, W, 1, Color);
117 Video_FillRect(X, Y+H-1, W, 1, Color);
118 Video_FillRect(X, Y, 1, H, Color);
119 Video_FillRect(X+W-1, Y, 1, H, Color);
123 * \brief Draw an image to the screen
124 * \todo Maybe have support for an offset in the image
126 void Video_DrawImage(short X, short Y, short W, short H, tImage *Image)
129 uint8_t *buf = (uint8_t *)(gpScreenBuffer + Y*giScreenWidth + X);
137 if( X >= giScreenWidth ) return ;
138 if( Y >= giScreenHeight ) return ;
140 // Wrap to image size
141 if( W > Image->Width ) W = Image->Width;
142 if( H > Image->Height ) H = Image->Height;
144 // Wrap to screen size
145 if( X + W > giScreenWidth ) W = giScreenWidth - X;
146 if( Y + H > giScreenHeight ) H = giScreenHeight - Y;
150 switch( Image->Format )
153 for( y = 0; y < H; y ++ )
155 int r, g, b, a; // New
156 int or, og, ob; // Original
157 for( x = 0; x < W; x ++ )
159 b = data[x*4+0]; g = data[x*4+1]; r = data[x*4+2]; a = data[x*4+3];
160 if( a == 0 ) continue; // 100% transparent
161 ob = buf[x*4+0]; og = buf[x*4+1]; or = buf[x*4+2];
165 // Transparent: Handled above
176 r = (or * (255-a) + r * a) / 255;
177 g = (og * (255-a) + g * a) / 255;
178 b = (ob * (255-a) + b * a) / 255;
181 buf[x*4+0] = b; buf[x*4+1] = g; buf[x*4+2] = r;
183 data += Image->Width * 4;
184 buf += giScreenWidth * 4;
190 for( y = 0; y < H; y ++ )
192 for( x = 0; x < W; x ++ )
194 buf[x*4+0] = data[x*3+2]; // Blue
195 buf[x*4+1] = data[x*3+1]; // Green
196 buf[x*4+2] = data[x*3+0]; // Red
199 buf += giScreenWidth * 4;
203 _SysDebug("ERROR: Unknown image format %i\n", Image->Format);