2 * Acess2 GUI (AxWin) Version 3
3 * - By John Hodge (thePowersGang)
10 #include <acess/devices/terminal.h>
12 #include "resources/cursor.h"
18 void Video_Setup(void);
19 void Video_SetCursorPos(short X, short Y);
20 void Video_Update(void);
21 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color);
22 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color);
27 uint32_t *gpScreenBuffer;
30 void Video_Setup(void)
35 giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
36 if( giTerminalFD == -1 )
38 fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno);
43 tmpInt = giScreenWidth;
44 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, &tmpInt );
45 if(tmpInt != giScreenWidth)
47 fprintf(stderr, "Warning: Selected width (%i) is invalid, clipped to %i\n",
48 giScreenWidth, tmpInt);
49 giScreenWidth = tmpInt;
53 tmpInt = giScreenHeight;
54 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, &tmpInt );
55 if(tmpInt != giScreenHeight)
57 fprintf(stderr, "Warning: Selected height (%i) is invalid, clipped to %i\n",
58 giScreenHeight, tmpInt);
59 giScreenHeight = tmpInt;
63 tmpInt = TERM_MODE_FB;
64 ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
66 // Force VT to be shown
67 ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
69 // Create local framebuffer (back buffer)
70 gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
72 // Set cursor position and bitmap
73 ioctl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap);
74 Video_SetCursorPos( giScreenWidth/2, giScreenHeight/2 );
77 void Video_Update(void)
79 _SysDebug("Video_Update - gpScreenBuffer[0] = 0x%x", gpScreenBuffer[0]);
80 seek(giTerminalFD, 0, 1);
81 write(giTerminalFD, gpScreenBuffer, giScreenWidth*giScreenHeight*4);
82 _SysDebug("Video_Update - Done");
85 void Video_SetCursorPos(short X, short Y)
91 pos.x = giVideo_CursorX = X;
92 pos.y = giVideo_CursorY = Y;
93 ioctl(giTerminalFD, TERM_IOCTL_GETSETCURSOR, &pos);
97 * \brief Blit an entire buffer to the screen
98 * \note Assumes Pitch = 4*W
100 void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H)
105 // _SysDebug("Video_Blit: (%p (%i, %i) %ix%i)", Source, DstX, DstY, W, H);
107 if( DstX >= giScreenWidth) return ;
108 if( DstY >= giScreenHeight) return ;
109 // TODO: Handle -ve X/Y by clipping
110 if( DstX < 0 || DstY < 0 ) return ;
111 // TODO: Handle out of bounds by clipping too
112 if( DstX + W > giScreenWidth ) return;
113 if( DstY + H > giScreenHeight )
114 H = giScreenWidth - DstY;
116 if( W <= 0 || H <= 0 ) return;
118 // _SysDebug(" Clipped to (%i, %i) %ix%i", DstX, DstY, W, H);
119 // _SysDebug(" Source[0] = 0x%x", Source[0]);
120 buf = gpScreenBuffer + DstY*giScreenWidth + DstX;
125 buf += giScreenWidth - W;
129 tColour Video_AlphaBlend(tColour _orig, tColour _new, uint8_t _alpha)
131 uint16_t ao,ro,go,bo;
132 uint16_t an,rn,gn,bn;
133 if( _alpha == 0 ) return _orig;
134 if( _alpha == 255 ) return _new;
136 ao = (_orig >> 24) & 0xFF;
137 ro = (_orig >> 16) & 0xFF;
138 go = (_orig >> 8) & 0xFF;
139 bo = (_orig >> 0) & 0xFF;
141 an = (_new >> 24) & 0xFF;
142 rn = (_new >> 16) & 0xFF;
143 gn = (_new >> 8) & 0xFF;
144 bn = (_new >> 0) & 0xFF;
146 if( _alpha == 0x80 ) {
153 ao = ao*(255-_alpha) + an*_alpha;
154 ro = ro*(255-_alpha) + rn*_alpha;
155 go = go*(255-_alpha) + gn*_alpha;
156 bo = bo*(255-_alpha) + bn*_alpha;
163 return (ao << 24) | (ro << 16) | (go << 8) | bo;