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);
44 tmpInt = TERM_MODE_FB;
45 ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
48 giScreenWidth = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, NULL );
49 giScreenHeight = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, NULL );
51 // Force VT to be shown
52 ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
54 // Create local framebuffer (back buffer)
55 gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
57 // Set cursor position and bitmap
58 ioctl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap);
59 Video_SetCursorPos( giScreenWidth/2, giScreenHeight/2 );
62 void Video_Update(void)
64 _SysDebug("Video_Update - gpScreenBuffer[0] = 0x%x", gpScreenBuffer[0]);
65 seek(giTerminalFD, 0, 1);
66 write(giTerminalFD, gpScreenBuffer, giScreenWidth*giScreenHeight*4);
67 _SysDebug("Video_Update - Done");
70 void Video_SetCursorPos(short X, short Y)
76 pos.x = giVideo_CursorX = X;
77 pos.y = giVideo_CursorY = Y;
78 ioctl(giTerminalFD, TERM_IOCTL_GETSETCURSOR, &pos);
82 * \brief Blit an entire buffer to the screen
83 * \note Assumes Pitch = 4*W
85 void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H)
90 // _SysDebug("Video_Blit: (%p (%i, %i) %ix%i)", Source, DstX, DstY, W, H);
92 if( DstX >= giScreenWidth) return ;
93 if( DstY >= giScreenHeight) return ;
94 // TODO: Handle -ve X/Y by clipping
95 if( DstX < 0 || DstY < 0 ) return ;
96 // TODO: Handle out of bounds by clipping too
97 if( DstX + W > giScreenWidth ) return;
98 if( DstY + H > giScreenHeight )
99 H = giScreenWidth - DstY;
101 if( W <= 0 || H <= 0 ) return;
103 // _SysDebug(" Clipped to (%i, %i) %ix%i", DstX, DstY, W, H);
104 // _SysDebug(" Source[0] = 0x%x", Source[0]);
105 buf = gpScreenBuffer + DstY*giScreenWidth + DstX;
110 buf += giScreenWidth - W;
114 tColour Video_AlphaBlend(tColour _orig, tColour _new, uint8_t _alpha)
116 uint16_t ao,ro,go,bo;
117 uint16_t an,rn,gn,bn;
118 if( _alpha == 0 ) return _orig;
119 if( _alpha == 255 ) return _new;
121 ao = (_orig >> 24) & 0xFF;
122 ro = (_orig >> 16) & 0xFF;
123 go = (_orig >> 8) & 0xFF;
124 bo = (_orig >> 0) & 0xFF;
126 an = (_new >> 24) & 0xFF;
127 rn = (_new >> 16) & 0xFF;
128 gn = (_new >> 8) & 0xFF;
129 bn = (_new >> 0) & 0xFF;
131 if( _alpha == 0x80 ) {
138 ao = ao*(255-_alpha) + an*_alpha;
139 ro = ro*(255-_alpha) + rn*_alpha;
140 go = go*(255-_alpha) + gn*_alpha;
141 bo = bo*(255-_alpha) + bn*_alpha;
148 return (ao << 24) | (ro << 16) | (go << 8) | bo;