6 #define VERSION ((0<<8)|10)
12 #include <api_drv_video.h>
16 int Video_Install(char **Arguments);
17 size_t Video_Read(tVFS_Node *Node, Uint64 Offset, size_t Length, void *Buffer);
18 size_t Video_Write(tVFS_Node *Node, Uint64 Offset, size_t 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 size_t Video_Read(tVFS_Node *Node, Uint64 Offset, size_t Length, void *Buffer)
64 * \brief Write to the framebuffer
66 size_t Video_Write(tVFS_Node *Node, Uint64 Offset, size_t 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);
170 startX = Offset % giUI_Width;
171 startY = Offset / giUI_Width;
174 if( startX + Length < giUI_Width )
182 else if( startX == 0 )
184 int lines = Length / giUI_Width;
185 int rem = Length % giUI_Width;
186 UI_BlitBitmap(0, startY, giUI_Width, lines, Buffer);
188 UI_BlitBitmap(0, startY + lines, rem, 1, (Uint32*)Buffer + lines*giUI_Width);
193 // First scanline (partial or full)
196 giUI_Width - startX, 1,
199 Length -= giUI_Width - startX;
200 Buffer += giUI_Width - startX;
203 for( i = 0; i < Length / giUI_Height; i ++ )
209 Buffer += giUI_Width;
212 // Final scanline (partial)
213 if( Length % giUI_Height )
217 Length % giUI_Height, 1,
224 case VIDEO_BUFFMT_2DSTREAM:
225 Length = DrvUtil_Video_2DStream(
226 NULL, // Single framebuffer, so Ent is unused
227 Buffer, Length, &gVideo_2DFunctions, sizeof(gVideo_2DFunctions)
236 // Tell the UI to blit
243 const char * csaVIDEO_IOCTLS[] = {DRV_IOCTLNAMES, DRV_VIDEO_IOCTLNAMES, NULL};
245 * \brief Handle messages to the device
247 int Video_IOCtl(tVFS_Node *Node, int ID, void *Data)
250 tVideo_IOCtl_Mode *mode = Data;
253 BASE_IOCTLS(DRV_TYPE_VIDEO, "NativeVideo", VERSION, csaVIDEO_IOCTLS);
255 // Video mode control
256 // - We cheat, and only have one mode
257 case VIDEO_IOCTL_GETSETMODE:
259 case VIDEO_IOCTL_FINDMODE:
260 case VIDEO_IOCTL_MODEINFO:
262 mode->width = giUI_Width;
263 mode->height = giUI_Height;
269 case VIDEO_IOCTL_SETBUFFORMAT:
270 ret = giVideo_CurrentFormat;
272 giVideo_CurrentFormat = *(int*)Data;
277 case VIDEO_IOCTL_SETCURSOR: // Set cursor position
279 if(giVideo_CursorX > 0)
280 Video_FlipCursor(Node);
282 giVideo_CursorX = ((tVideo_IOCtl_Pos*)Data)->x;
283 giVideo_CursorY = ((tVideo_IOCtl_Pos*)Data)->y;
284 if( giVideo_CursorX < 0 || giVesaCursorY < 0
285 || giVideo_CursorX >= gpVesaCurMode->width/giVT_CharWidth
286 || giVideo_CursorY >= gpVesaCurMode->height/giVT_CharHeight)
289 if(giVesaCursorTimer != -1) {
290 Time_RemoveTimer(giVesaCursorTimer);
291 giVesaCursorTimer = -1;
299 // Log_Debug("VESA", "Updating timer %i?", giVesaCursorTimer);
300 if(giVesaCursorTimer == -1)
301 giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Node);
303 Vesa_FlipCursor(Node);
306 //Log_Debug("VESA", "Cursor position (%i,%i) Timer %i", giVesaCursorX, giVesaCursorY, giVesaCursorTimer);
313 // --- 2D Acceleration Functions --
314 void Video_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour)
316 UI_FillBitmap(X, Y, W, H, Colour);
319 void Video_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H)
321 UI_BlitFramebuffer(DstX, DstY, SrcX, SrcY, W, H);