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 );
70 // memset(gpScreenBufferi
71 // Video_FillRect(0, 0, giScreenWidth, giScreenHeight, 0x8080FF);
73 // Set cursor position and bitmap
74 ioctl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap);
75 Video_SetCursorPos( giScreenWidth/2, giScreenHeight/2 );
80 void Video_Update(void)
82 _SysDebug("Video_Update - gpScreenBuffer[0] = 0x%x", gpScreenBuffer[0]);
83 seek(giTerminalFD, 0, 1);
84 write(giTerminalFD, gpScreenBuffer, giScreenWidth*giScreenHeight*4);
85 _SysDebug("Video_Update - Done");
88 void Video_SetCursorPos(short X, short Y)
94 pos.x = giVideo_CursorX = X;
95 pos.y = giVideo_CursorY = Y;
96 ioctl(giTerminalFD, TERM_IOCTL_GETSETCURSOR, &pos);
100 * \brief Blit an entire buffer to the screen
101 * \note Assumes Pitch = 4*W
103 void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H)
108 // _SysDebug("Video_Blit: (%p (%i, %i) %ix%i)", Source, DstX, DstY, W, H);
110 if( DstX >= giScreenWidth) return ;
111 if( DstY >= giScreenHeight) return ;
112 // TODO: Handle -ve X/Y by clipping
113 if( DstX < 0 || DstY < 0 ) return ;
114 // TODO: Handle out of bounds by clipping too
115 if( DstX + W > giScreenWidth ) return;
116 if( DstY + H > giScreenHeight )
117 H = giScreenWidth - DstY;
119 if( W <= 0 || H <= 0 ) return;
121 // _SysDebug(" Clipped to (%i, %i) %ix%i", DstX, DstY, W, H);
122 // _SysDebug(" Source[0] = 0x%x", Source[0]);
123 buf = gpScreenBuffer + DstY*giScreenWidth + DstX;
128 buf += giScreenWidth - W;