2 * Acess2 GUI (AxWin) Version 3
3 * - By John Hodge (thePowersGang)
10 #include <acess/devices/terminal.h>
12 #include "resources/cursor.h"
17 void Video_Setup(void);
18 void Video_SetCursorPos(short X, short Y);
19 void Video_Update(void);
20 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color);
21 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color);
26 uint32_t *gpScreenBuffer;
29 void Video_Setup(void)
34 giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
35 if( giTerminalFD == -1 )
37 fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno);
42 tmpInt = giScreenWidth;
43 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, &tmpInt );
44 if(tmpInt != giScreenWidth)
46 fprintf(stderr, "Warning: Selected width (%i) is invalid, clipped to %i\n",
47 giScreenWidth, tmpInt);
48 giScreenWidth = tmpInt;
52 tmpInt = giScreenHeight;
53 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, &tmpInt );
54 if(tmpInt != giScreenHeight)
56 fprintf(stderr, "Warning: Selected height (%i) is invalid, clipped to %i\n",
57 giScreenHeight, tmpInt);
58 giScreenHeight = tmpInt;
62 tmpInt = TERM_MODE_FB;
63 ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
65 // Force VT to be shown
66 ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
68 // Create local framebuffer (back buffer)
69 gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
71 // Set cursor position and bitmap
72 ioctl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap);
73 Video_SetCursorPos( giScreenWidth/2, giScreenHeight/2 );
76 void Video_Update(void)
78 _SysDebug("Video_Update - gpScreenBuffer[0] = 0x%x", gpScreenBuffer[0]);
79 seek(giTerminalFD, 0, 1);
80 write(giTerminalFD, gpScreenBuffer, giScreenWidth*giScreenHeight*4);
81 _SysDebug("Video_Update - Done");
84 void Video_SetCursorPos(short X, short Y)
90 pos.x = giVideo_CursorX = X;
91 pos.y = giVideo_CursorY = Y;
92 ioctl(giTerminalFD, TERM_IOCTL_GETSETCURSOR, &pos);
96 * \brief Blit an entire buffer to the screen
97 * \note Assumes Pitch = 4*W
99 void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H)
104 // _SysDebug("Video_Blit: (%p (%i, %i) %ix%i)", Source, DstX, DstY, W, H);
106 if( DstX >= giScreenWidth) return ;
107 if( DstY >= giScreenHeight) return ;
108 // TODO: Handle -ve X/Y by clipping
109 if( DstX < 0 || DstY < 0 ) return ;
110 // TODO: Handle out of bounds by clipping too
111 if( DstX + W > giScreenWidth ) return;
112 if( DstY + H > giScreenHeight )
113 H = giScreenWidth - DstY;
115 if( W <= 0 || H <= 0 ) return;
117 // _SysDebug(" Clipped to (%i, %i) %ix%i", DstX, DstY, W, H);
118 // _SysDebug(" Source[0] = 0x%x", Source[0]);
119 buf = gpScreenBuffer + DstY*giScreenWidth + DstX;
124 buf += giScreenWidth - W;