6 #define VERSION ((0<<8)|10)
12 #include <api_drv_video.h>
16 int Video_Install(char **Arguments);
17 Uint64 Video_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
18 Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer);
19 int Video_IOCtl(tVFS_Node *Node, int ID, void *Data);
20 // --- 2D Acceleration Functions --
21 void Video_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour);
22 void Video_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H);
25 //MODULE_DEFINE(0, VERSION, NativeVideo, Video_Install, NULL, NULL);
26 tVFS_NodeType gVideo_NodeType = {
31 tDevFS_Driver gVideo_DriverStruct = {
33 {.Type = &gVideo_NodeType}
36 int giVideo_CurrentFormat;
37 // --- 2D Video Stream Handlers ---
38 tDrvUtil_Video_2DHandlers gVideo_2DFunctions = {
45 int Video_Install(char **Arguments)
48 giVideo_DriverID = DevFS_AddDevice( &gVideo_DriverStruct );
49 if(giVideo_DriverID == -1)
50 return MODULE_ERR_MISC;
56 * \brief Read from framebuffer (unimplemented)
58 Uint64 Video_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
64 * \brief Write to the framebuffer
66 Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer)
69 ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
76 switch( giVideo_CurrentFormat )
78 case VIDEO_BUFFMT_TEXT:
80 const tVT_Char *chars = Buffer;
81 // int pitch = giUI_Pitch;
82 int widthInChars = giUI_Width/giVT_CharWidth;
83 int heightInChars = giUI_Height/giVT_CharHeight;
85 Uint32 tmpBuf[giVT_CharHeight*giVT_CharWidth];
87 Length /= sizeof(tVT_Char);
88 Offset /= sizeof(tVT_Char);
90 x = Offset % widthInChars;
91 y = Offset / widthInChars;
94 if( Offset > (Uint64)(heightInChars*widthInChars) ) {
95 Log_Notice("Video", "Offset (%i) > %i*%i (%i)", Offset,
96 heightInChars, widthInChars, heightInChars*widthInChars);
100 if(y >= heightInChars) {
105 // Clip to screen size
106 if( (int)Offset + (int)Length > heightInChars*widthInChars ) {
107 Log_Debug("Video", "%i + %i > %i*%i (%i)",
108 (int)Offset, (int)Length, heightInChars, widthInChars, heightInChars*widthInChars);
109 Length = heightInChars*widthInChars - Offset;
110 Log_Notice("Video", "Clipping write size to %i characters", (int)Length);
113 // Log_Debug("Video", "(%i,%i) %i chars", x, y, (int)Length);
116 for( i = 0; i < (int)Length; i++ )
120 // Log_Debug("Video", "Render Char 0x%x in 0x%03x:%03x",
121 // chars->Ch, chars->FGCol, chars->BGCol);
122 memset(tmpBuf, 0xFF, giVT_CharWidth*giVT_CharHeight*4);
125 tmpBuf, 32, giVT_CharWidth*4,
126 VT_Colour12to24(chars->BGCol),
127 VT_Colour12to24(chars->FGCol)
130 x*giVT_CharWidth, y*giVT_CharHeight,
131 giVT_CharWidth, giVT_CharHeight,
138 x*giVT_CharWidth, y*giVT_CharHeight,
139 giVT_CharWidth, giVT_CharHeight,
140 VT_Colour12to24(chars->BGCol)
146 if( x >= widthInChars ) {
149 //dest += pitch*giVT_CharHeight;
152 Length *= sizeof(tVT_Char);
156 case VIDEO_BUFFMT_FRAMEBUFFER:
160 if(giUI_Pitch*giUI_Height < Offset+Length)
162 Log_Warning("Video", "Video_Write - Framebuffer Overflow");
167 LOG("buffer = %p", Buffer);
169 startX = Offset % giUI_Width;
170 startY = Offset / giUI_Width;
172 if( Length + startX < giUI_Width )
182 // First scanline (partial or full)
185 giUI_Width - startX, 1,
188 Length -= giUI_Width - startX;
189 Buffer += giUI_Width - startX;
192 for( i = 0; i < Length / giUI_Height; i ++ )
198 Buffer += giUI_Width;
201 // Final scanline (partial)
202 if( Length % giUI_Height )
206 Length % giUI_Height, 1,
213 case VIDEO_BUFFMT_2DSTREAM:
214 Length = DrvUtil_Video_2DStream(
215 NULL, // Single framebuffer, so Ent is unused
216 Buffer, Length, &gVideo_2DFunctions, sizeof(gVideo_2DFunctions)
225 // Tell the UI to blit
232 const char * csaVIDEO_IOCTLS[] = {DRV_IOCTLNAMES, DRV_VIDEO_IOCTLNAMES, NULL};
234 * \brief Handle messages to the device
236 int Video_IOCtl(tVFS_Node *Node, int ID, void *Data)
239 tVideo_IOCtl_Mode *mode = Data;
242 BASE_IOCTLS(DRV_TYPE_VIDEO, "NativeVideo", VERSION, csaVIDEO_IOCTLS);
244 // Video mode control
245 // - We cheat, and only have one mode
246 case VIDEO_IOCTL_GETSETMODE:
248 case VIDEO_IOCTL_FINDMODE:
249 case VIDEO_IOCTL_MODEINFO:
251 mode->width = giUI_Width;
252 mode->height = giUI_Height;
258 case VIDEO_IOCTL_SETBUFFORMAT:
259 ret = giVideo_CurrentFormat;
261 giVideo_CurrentFormat = *(int*)Data;
266 case VIDEO_IOCTL_SETCURSOR: // Set cursor position
268 if(giVideo_CursorX > 0)
269 Video_FlipCursor(Node);
271 giVideo_CursorX = ((tVideo_IOCtl_Pos*)Data)->x;
272 giVideo_CursorY = ((tVideo_IOCtl_Pos*)Data)->y;
273 if( giVideo_CursorX < 0 || giVesaCursorY < 0
274 || giVideo_CursorX >= gpVesaCurMode->width/giVT_CharWidth
275 || giVideo_CursorY >= gpVesaCurMode->height/giVT_CharHeight)
278 if(giVesaCursorTimer != -1) {
279 Time_RemoveTimer(giVesaCursorTimer);
280 giVesaCursorTimer = -1;
288 // Log_Debug("VESA", "Updating timer %i?", giVesaCursorTimer);
289 if(giVesaCursorTimer == -1)
290 giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Node);
292 Vesa_FlipCursor(Node);
295 //Log_Debug("VESA", "Cursor position (%i,%i) Timer %i", giVesaCursorX, giVesaCursorY, giVesaCursorTimer);
302 // --- 2D Acceleration Functions --
303 void Video_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour)
305 UI_FillBitmap(X, Y, W, H, Colour);
308 void Video_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H)
310 UI_BlitFramebuffer(DstX, DstY, SrcX, SrcY, W, H);