2 * Acess2 GUI (AxWin) Version 3
3 * - By John Hodge (thePowersGang)
10 #include <acess/devices/terminal.h>
12 #include "resources/cursor.h"
19 void Video_Setup(void);
20 void Video_SetCursorPos(short X, short Y);
21 void Video_Update(void);
22 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color);
23 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color);
28 uint32_t *gpScreenBuffer;
29 int giVideo_FirstDirtyLine;
30 int giVideo_LastDirtyLine;
33 void Video_Setup(void)
38 giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
39 if( giTerminalFD == -1 )
41 fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno);
47 tmpInt = TERM_MODE_FB;
48 ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
51 giScreenWidth = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, NULL );
52 giScreenHeight = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, NULL );
54 giVideo_LastDirtyLine = giScreenHeight;
56 // Force VT to be shown
57 ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
59 // Create local framebuffer (back buffer)
60 gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
62 // Set cursor position and bitmap
63 ioctl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap);
64 Video_SetCursorPos( giScreenWidth/2, giScreenHeight/2 );
67 void Video_Update(void)
69 int ofs = giVideo_FirstDirtyLine*giScreenWidth;
70 int size = (giVideo_LastDirtyLine-giVideo_FirstDirtyLine)*giScreenWidth;
72 if( giVideo_LastDirtyLine == 0 ) return;
74 _SysDebug("Video_Update - Updating lines %i to %i (0x%x+0x%x px)",
75 giVideo_FirstDirtyLine, giVideo_LastDirtyLine, ofs, size);
76 seek(giTerminalFD, ofs*4, 1);
77 write(giTerminalFD, gpScreenBuffer+ofs, size*4);
78 _SysDebug("Video_Update - Done");
79 giVideo_FirstDirtyLine = 0;
80 giVideo_LastDirtyLine = 0;
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);
95 * \brief Blit an entire buffer to the screen
96 * \note Assumes Pitch = 4*W
98 void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H)
102 if( DstX >= giScreenWidth) return ;
103 if( DstY >= giScreenHeight) return ;
104 // TODO: Handle -ve X/Y by clipping
105 if( DstX < 0 || DstY < 0 ) return ;
106 // TODO: Handle out of bounds by clipping too
107 if( DstX + W > giScreenWidth ) return;
108 if( DstY + H > giScreenHeight )
109 H = giScreenWidth - DstY;
111 if( W <= 0 || H <= 0 ) return;
113 if( DstX < giVideo_FirstDirtyLine )
114 giVideo_FirstDirtyLine = DstY;
115 if( DstY + H > giVideo_LastDirtyLine )
116 giVideo_LastDirtyLine = DstY + H;
118 buf = gpScreenBuffer + DstY*giScreenWidth + DstX;
119 if(W != giScreenWidth)
123 memcpy(buf, Source, W*4);
125 buf += giScreenWidth;
130 memcpy(buf, Source, giScreenWidth*H*4);
134 tColour Video_AlphaBlend(tColour _orig, tColour _new, uint8_t _alpha)
136 uint16_t ao,ro,go,bo;
137 uint16_t an,rn,gn,bn;
138 if( _alpha == 0 ) return _orig;
139 if( _alpha == 255 ) return _new;
141 ao = (_orig >> 24) & 0xFF;
142 ro = (_orig >> 16) & 0xFF;
143 go = (_orig >> 8) & 0xFF;
144 bo = (_orig >> 0) & 0xFF;
146 an = (_new >> 24) & 0xFF;
147 rn = (_new >> 16) & 0xFF;
148 gn = (_new >> 8) & 0xFF;
149 bn = (_new >> 0) & 0xFF;
151 if( _alpha == 0x80 ) {
158 ao = ao*(255-_alpha) + an*_alpha;
159 ro = ro*(255-_alpha) + rn*_alpha;
160 go = go*(255-_alpha) + gn*_alpha;
161 bo = bo*(255-_alpha) + bn*_alpha;
168 return (ao << 24) | (ro << 16) | (go << 8) | bo;