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, 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 tDevFS_Driver gVideo_DriverStruct = {
35 int giVideo_CurrentFormat;
36 // --- 2D Video Stream Handlers ---
37 tDrvUtil_Video_2DHandlers gVideo_2DFunctions = {
44 int Video_Install(char **Arguments)
47 giVideo_DriverID = DevFS_AddDevice( &gVideo_DriverStruct );
48 if(giVideo_DriverID == -1)
49 return MODULE_ERR_MISC;
55 * \brief Read from framebuffer (unimplemented)
57 Uint64 Video_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
63 * \brief Write to the framebuffer
65 Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
68 ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
75 switch( giVideo_CurrentFormat )
77 case VIDEO_BUFFMT_TEXT:
79 tVT_Char *chars = Buffer;
80 // int pitch = giUI_Pitch;
81 int widthInChars = giUI_Width/giVT_CharWidth;
82 int heightInChars = giUI_Height/giVT_CharHeight;
84 Uint32 tmpBuf[giVT_CharHeight*giVT_CharWidth];
86 Length /= sizeof(tVT_Char);
87 Offset /= sizeof(tVT_Char);
89 x = Offset % widthInChars;
90 y = Offset / widthInChars;
93 if( Offset > (Uint64)(heightInChars*widthInChars) ) {
94 Log_Notice("Video", "Offset (%i) > %i*%i (%i)", Offset,
95 heightInChars, widthInChars, heightInChars*widthInChars);
99 if(y >= heightInChars) {
104 // Clip to screen size
105 if( (int)Offset + (int)Length > heightInChars*widthInChars ) {
106 Log_Debug("Video", "%i + %i > %i*%i (%i)",
107 (int)Offset, (int)Length, heightInChars, widthInChars, heightInChars*widthInChars);
108 Length = heightInChars*widthInChars - Offset;
109 Log_Notice("Video", "Clipping write size to %i characters", (int)Length);
112 // Log_Debug("Video", "(%i,%i) %i chars", x, y, (int)Length);
115 for( i = 0; i < (int)Length; i++ )
119 // Log_Debug("Video", "Render Char 0x%x in 0x%03x:%03x",
120 // chars->Ch, chars->FGCol, chars->BGCol);
121 memset(tmpBuf, 0xFF, giVT_CharWidth*giVT_CharHeight*4);
124 tmpBuf, 32, giVT_CharWidth*4,
125 VT_Colour12to24(chars->BGCol),
126 VT_Colour12to24(chars->FGCol)
129 x*giVT_CharWidth, y*giVT_CharHeight,
130 giVT_CharWidth, giVT_CharHeight,
137 x*giVT_CharWidth, y*giVT_CharHeight,
138 giVT_CharWidth, giVT_CharHeight,
139 VT_Colour12to24(chars->BGCol)
145 if( x >= widthInChars ) {
148 //dest += pitch*giVT_CharHeight;
151 Length *= sizeof(tVT_Char);
155 case VIDEO_BUFFMT_FRAMEBUFFER:
159 if(giUI_Pitch*giUI_Height < Offset+Length)
161 Log_Warning("Video", "Video_Write - Framebuffer Overflow");
166 LOG("buffer = %p", Buffer);
168 startX = Offset % giUI_Width;
169 startY = Offset / giUI_Width;
171 if( Length + startX < giUI_Width )
181 // First scanline (partial or full)
184 giUI_Width - startX, 1,
187 Length -= giUI_Width - startX;
188 Buffer += giUI_Width - startX;
191 for( i = 0; i < Length / giUI_Height; i ++ )
197 Buffer += giUI_Width;
200 // Final scanline (partial)
201 if( Length % giUI_Height )
205 Length % giUI_Height, 1,
212 case VIDEO_BUFFMT_2DSTREAM:
213 Length = DrvUtil_Video_2DStream(
214 NULL, // Single framebuffer, so Ent is unused
215 Buffer, Length, &gVideo_2DFunctions, sizeof(gVideo_2DFunctions)
224 // Tell the UI to blit
231 const char * csaVIDEO_IOCTLS[] = {DRV_IOCTLNAMES, DRV_VIDEO_IOCTLNAMES, NULL};
233 * \brief Handle messages to the device
235 int Video_IOCtl(tVFS_Node *Node, int ID, void *Data)
238 tVideo_IOCtl_Mode *mode = Data;
241 BASE_IOCTLS(DRV_TYPE_VIDEO, "NativeVideo", VERSION, csaVIDEO_IOCTLS);
243 // Video mode control
244 // - We cheat, and only have one mode
245 case VIDEO_IOCTL_GETSETMODE:
247 case VIDEO_IOCTL_FINDMODE:
248 case VIDEO_IOCTL_MODEINFO:
250 mode->width = giUI_Width;
251 mode->height = giUI_Height;
257 case VIDEO_IOCTL_SETBUFFORMAT:
258 ret = giVideo_CurrentFormat;
260 giVideo_CurrentFormat = *(int*)Data;
265 case VIDEO_IOCTL_SETCURSOR: // Set cursor position
267 if(giVideo_CursorX > 0)
268 Video_FlipCursor(Node);
270 giVideo_CursorX = ((tVideo_IOCtl_Pos*)Data)->x;
271 giVideo_CursorY = ((tVideo_IOCtl_Pos*)Data)->y;
272 if( giVideo_CursorX < 0 || giVesaCursorY < 0
273 || giVideo_CursorX >= gpVesaCurMode->width/giVT_CharWidth
274 || giVideo_CursorY >= gpVesaCurMode->height/giVT_CharHeight)
277 if(giVesaCursorTimer != -1) {
278 Time_RemoveTimer(giVesaCursorTimer);
279 giVesaCursorTimer = -1;
287 // Log_Debug("VESA", "Updating timer %i?", giVesaCursorTimer);
288 if(giVesaCursorTimer == -1)
289 giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Node);
291 Vesa_FlipCursor(Node);
294 //Log_Debug("VESA", "Cursor position (%i,%i) Timer %i", giVesaCursorX, giVesaCursorY, giVesaCursorTimer);
301 // --- 2D Acceleration Functions --
302 void Video_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour)
304 UI_FillBitmap(X, Y, W, H, Colour);
307 void Video_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H)
309 UI_BlitFramebuffer(DstX, DstY, SrcX, SrcY, W, H);