* AcessOS 1\r
* Video BIOS Extensions (Vesa) Driver\r
*/\r
-#define DEBUG 1\r
+#define DEBUG 0\r
#define VERSION 0x100\r
\r
#include <acess.h>\r
\r
// === CONSTANTS ===\r
#define FLAG_LFB 0x1\r
+#define VESA_DEFAULT_FRAMEBUFFER (KERNEL_BASE|0xA0000)\r
+#define BLINKING_CURSOR 0\r
+#if BLINKING_CURSOR\r
+# define VESA_CURSOR_PERIOD 1000\r
+#endif\r
\r
// === PROTOTYPES ===\r
int Vesa_Install(char **Arguments);\r
int Vesa_Int_SetMode(int Mode);\r
int Vesa_Int_FindMode(tVideo_IOCtl_Mode *data);\r
int Vesa_Int_ModeInfo(tVideo_IOCtl_Mode *data);\r
+void Vesa_FlipCursor(void *Arg);\r
+// --- 2D Acceleration Functions --\r
+void Vesa_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour);\r
+void Vesa_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H);\r
\r
// === GLOBALS ===\r
MODULE_DEFINE(0, VERSION, Vesa, Vesa_Install, NULL, "PCI", "VM8086", NULL);\r
};\r
tSpinlock glVesa_Lock;\r
tVM8086 *gpVesa_BiosState;\r
+ int giVesaDriverId = -1;\r
+// --- Video Modes ---\r
int giVesaCurrentMode = 0;\r
int giVesaCurrentFormat = VIDEO_BUFFMT_TEXT;\r
- int giVesaDriverId = -1;\r
-char *gVesaFramebuffer = (void*)0xC00A0000;\r
tVesa_Mode *gVesa_Modes;\r
+tVesa_Mode *gpVesaCurMode;\r
int giVesaModeCount = 0;\r
- int giVesaPageCount = 0;\r
+// --- Framebuffer ---\r
+char *gpVesa_Framebuffer = (void*)VESA_DEFAULT_FRAMEBUFFER;\r
+ int giVesaPageCount = 0; //!< Framebuffer size in pages\r
+// --- Cursor Control ---\r
+ int giVesaCursorX = -1;\r
+ int giVesaCursorY = -1;\r
+ int giVesaCursorTimer = -1; // Invalid timer\r
+// --- 2D Video Stream Handlers ---\r
+tDrvUtil_Video_2DHandlers gVesa_2DFunctions = {\r
+ NULL,\r
+ Vesa_2D_Fill,\r
+ Vesa_2D_Blit\r
+};\r
\r
-//CODE\r
+// === CODE ===\r
int Vesa_Install(char **Arguments)\r
{\r
tVesa_CallInfo *info;\r
// Call Interrupt\r
VM8086_Int(gpVesa_BiosState, 0x10);\r
if(gpVesa_BiosState->AX != 0x004F) {\r
- Log_Warning("Vesa", "Vesa_Install - VESA/VBE Unsupported (AX = 0x%x)\n", gpVesa_BiosState->AX);\r
+ Log_Warning("VESA", "Vesa_Install - VESA/VBE Unsupported (AX = 0x%x)", gpVesa_BiosState->AX);\r
return MODULE_ERR_NOTNEEDED;\r
}\r
\r
- Log_Debug("Vesa", "info->VideoModes = %04x:%04x", info->VideoModes.seg, info->VideoModes.ofs);\r
+ Log_Debug("VESA", "info->VideoModes = %04x:%04x", info->VideoModes.seg, info->VideoModes.ofs);\r
modes = (Uint16 *) VM8086_GetPointer(gpVesa_BiosState, info->VideoModes.seg, info->VideoModes.ofs);\r
\r
// Read Modes\r
gVesa_Modes[i].bpp = modeinfo->bpp;\r
\r
#if DEBUG\r
- Log_Log("Vesa", "0x%x - %ix%ix%i",\r
+ Log_Log("VESA", "0x%x - %ix%ix%i",\r
gVesa_Modes[i].code, gVesa_Modes[i].width, gVesa_Modes[i].height, gVesa_Modes[i].bpp);\r
#endif\r
}\r
Uint64 Vesa_Read(tVFS_Node *Node, Uint64 off, Uint64 len, void *buffer)\r
{\r
#if DEBUG >= 2\r
- LogF("Vesa_Read: () - NULL\n");\r
+ Log("Vesa_Read: () - NULL\n");\r
#endif\r
return 0;\r
}\r
tVT_Char *chars = Buffer;\r
int rem;\r
\r
+ Length /= sizeof(tVT_Char);\r
+ Offset /= sizeof(tVT_Char);\r
+ \r
if( giVesaCurrentFormat != VIDEO_BUFFMT_TEXT ) {\r
Log_Warning("VESA", "Vesa_Write - Mode 0 is not framebuffer");\r
LEAVE('i', -1);\r
return -1;\r
}\r
\r
- if( Offset + Length > 25*80*sizeof(tVT_Char) ) {\r
+ if( Offset + Length > 25*80 ) {\r
Log_Warning("VESA", "Vesa_Write - Framebuffer Overflow");\r
LEAVE('i', 0);\r
return 0;\r
}\r
\r
- fb += 2*(Offset/sizeof(tVT_Char));\r
+ fb += 2*Offset;\r
LOG("fb = %p", fb);\r
- for(rem = Length / sizeof(tVT_Char); rem --; fb ++, chars++)\r
+ for(rem = Length; rem --; fb ++, chars++)\r
{\r
if( chars->Ch < 0x80 )\r
*fb = chars->Ch & 0x7F;\r
//LOG("%08x (%03x,%03x) = %04x",\r
// chars->Ch, chars->BGCol, chars->FGCol, *fb);\r
}\r
- Length /= sizeof(tVT_Char);\r
Length *= sizeof(tVT_Char);\r
LEAVE('X', Length);\r
return Length;\r
case VIDEO_BUFFMT_TEXT:\r
{\r
tVT_Char *chars = Buffer;\r
- int pitch = gVesa_Modes[giVesaCurrentMode].width * giVT_CharWidth;\r
+ int pitch = gVesa_Modes[giVesaCurrentMode].width;\r
+ int widthInChars = gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth;\r
+ int heightInChars = gVesa_Modes[giVesaCurrentMode].height/giVT_CharHeight;\r
int x, y;\r
- Uint32 *dest;\r
- int rem;\r
+ Uint32 *dest = (void*)gpVesa_Framebuffer;\r
+ int i;\r
\r
+ Length /= sizeof(tVT_Char);\r
Offset /= sizeof(tVT_Char);\r
- dest = (void*)gVesaFramebuffer;\r
+ \r
LOG("gVesa_Modes[%i].width = %i", giVesaCurrentMode, gVesa_Modes[giVesaCurrentMode].width);\r
- x = (Offset % (gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth)) * giVT_CharWidth;\r
- y = (Offset / (gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth)) * giVT_CharHeight;\r
- LOG("(x,y) = (%i,%i)", x, y);\r
+ x = Offset % widthInChars;\r
+ y = Offset / widthInChars;\r
+ LOG("(x,y) = (%i,%i) = [%i,%i]", x, y, x * giVT_CharWidth, y * giVT_CharHeight * pitch);\r
+ LOG("(w,h) = (%i,%i) = [%i,%i]",\r
+ (int)(Length % widthInChars),\r
+ (int)(Length / widthInChars),\r
+ (int)((Length % widthInChars) * giVT_CharWidth),\r
+ (int)((Length / widthInChars) * giVT_CharHeight * pitch)\r
+ );\r
\r
// Sanity Check\r
- if(y > gVesa_Modes[giVesaCurrentMode].height) {\r
+ if( Offset > (Uint64)(heightInChars*widthInChars) ) {\r
+ LEAVE('i', 0);\r
+ return 0;\r
+ }\r
+ if(y >= heightInChars) {\r
LEAVE('i', 0);\r
return 0;\r
}\r
\r
- dest += y * pitch;\r
+ \r
+ if( (int)Offset + (int)Length > heightInChars*widthInChars ) {\r
+ Log_Debug("VESA", "%i + %i > %i*%i (%i)",\r
+ (int)Offset, (int)Length, heightInChars, widthInChars, heightInChars*widthInChars);\r
+ Length = heightInChars*widthInChars - Offset;\r
+ Log_Notice("VESA", "Clipping write size to %i characters", (int)Length);\r
+ }\r
+ \r
+ dest += y * giVT_CharHeight * pitch;\r
dest += x * giVT_CharWidth;\r
- for( rem = Length / sizeof(tVT_Char); rem--; )\r
+ \r
+ LOG("dest = %p", dest);\r
+ \r
+ for( i = 0; i < (int)Length; i++ )\r
{\r
VT_Font_Render(\r
chars->Ch,\r
- dest, pitch,\r
+ dest + x*giVT_CharWidth, pitch,\r
VT_Colour12to24(chars->BGCol),\r
VT_Colour12to24(chars->FGCol)\r
);\r
\r
- dest += giVT_CharWidth;\r
- \r
chars ++;\r
- x += giVT_CharWidth;\r
- if( x >= pitch ) {\r
+ x ++;\r
+ if( x >= widthInChars ) {\r
x = 0;\r
- y += giVT_CharHeight;\r
- dest += pitch*(giVT_CharHeight-1);\r
+ y ++;\r
+ dest += pitch*giVT_CharHeight;\r
}\r
}\r
- Length /= sizeof(tVT_Char);\r
Length *= sizeof(tVT_Char);\r
}\r
break;\r
\r
case VIDEO_BUFFMT_FRAMEBUFFER:\r
{\r
- Uint8 *destBuf = (Uint8*) ((Uint)gVesaFramebuffer + (Uint)Offset);\r
+ Uint8 *destBuf = (Uint8*) ((Uint)gpVesa_Framebuffer + (Uint)Offset);\r
\r
if(gVesa_Modes[giVesaCurrentMode].fbSize < Offset+Length)\r
{\r
LOG("BGA Framebuffer updated");\r
}\r
break;\r
+ \r
+ case VIDEO_BUFFMT_2DSTREAM:\r
+ Length = DrvUtil_Video_2DStream(\r
+ NULL, // Single framebuffer, so Ent is unused\r
+ Buffer, Length, &gVesa_2DFunctions, sizeof(gVesa_2DFunctions)\r
+ );\r
+ break;\r
+ \r
default:\r
LEAVE('i', -1);\r
return -1;\r
int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data)\r
{\r
int ret;\r
+ //Log_Debug("VESA", "Vesa_Ioctl: (Node=%p, ID=%i, Data=%p)", Node, ID, Data);\r
switch(ID)\r
{\r
case DRV_IOCTL_TYPE: return DRV_TYPE_VIDEO;\r
\r
case VIDEO_IOCTL_SETBUFFORMAT:\r
ret = giVesaCurrentFormat;\r
- if(Data) giVesaCurrentFormat = *(int*)Data;\r
+ if(Data) {\r
+ //Log_Log("VESA", "Buffer mode to %i", *(int*)Data);\r
+ giVesaCurrentFormat = *(int*)Data;\r
+ }\r
return ret;\r
\r
+ case VIDEO_IOCTL_SETCURSOR: // Set cursor position\r
+ #if !BLINKING_CURSOR\r
+ if(giVesaCursorX > 0 && giVesaCursorY)\r
+ Vesa_FlipCursor(Node);\r
+ #endif\r
+ giVesaCursorX = ((tVideo_IOCtl_Pos*)Data)->x;\r
+ giVesaCursorY = ((tVideo_IOCtl_Pos*)Data)->y;\r
+ //Log_Debug("VESA", "Cursor position (%i,%i)", giVesaCursorX, giVesaCursorY);\r
+ if(\r
+ giVesaCursorX < 0 || giVesaCursorY < 0\r
+ || giVesaCursorX >= gpVesaCurMode->width/giVT_CharWidth\r
+ || giVesaCursorY >= gpVesaCurMode->height/giVT_CharHeight)\r
+ {\r
+ #if BLINKING_CURSOR\r
+ if(giVesaCursorTimer != -1) {\r
+ Time_RemoveTimer(giVesaCursorTimer);\r
+ giVesaCursorTimer = -1;\r
+ }\r
+ #endif\r
+ giVesaCursorX = -1;\r
+ giVesaCursorY = -1;\r
+ }\r
+ else {\r
+ #if BLINKING_CURSOR\r
+ // Log_Debug("VESA", "Updating timer %i?", giVesaCursorTimer);\r
+ if(giVesaCursorTimer == -1)\r
+ giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Node);\r
+ #else\r
+ Vesa_FlipCursor(Node);\r
+ #endif\r
+ }\r
+ //Log_Debug("VESA", "Cursor position (%i,%i) Timer %i", giVesaCursorX, giVesaCursorY, giVesaCursorTimer);\r
+ return 0;\r
+ \r
case VIDEO_IOCTL_REQLFB: // Request Linear Framebuffer\r
return 0;\r
}\r
return 0;\r
}\r
\r
+/**\r
+ * \brief Updates the video mode\r
+ */\r
int Vesa_Int_SetMode(int mode)\r
-{ \r
- #if DEBUG\r
- LogF("Vesa_Int_SetMode: (mode=%i)\n", mode);\r
- #endif\r
+{\r
+ Log_Log("VESA", "Setting mode to %i", mode);\r
\r
// Sanity Check values\r
if(mode < 0 || mode > giVesaModeCount) return -1;\r
// Check for fast return\r
if(mode == giVesaCurrentMode) return 1;\r
\r
+ Time_RemoveTimer(giVesaCursorTimer);\r
+ giVesaCursorTimer = -1;\r
+ \r
LOCK( &glVesa_Lock );\r
\r
gpVesa_BiosState->AX = 0x4F02;\r
VM8086_Int(gpVesa_BiosState, 0x10);\r
\r
// Map Framebuffer\r
- MM_UnmapHWPages((tVAddr)gVesaFramebuffer, giVesaPageCount);\r
+ if( (tVAddr)gpVesa_Framebuffer != VESA_DEFAULT_FRAMEBUFFER )\r
+ MM_UnmapHWPages((tVAddr)gpVesa_Framebuffer, giVesaPageCount);\r
giVesaPageCount = (gVesa_Modes[mode].fbSize + 0xFFF) >> 12;\r
- gVesaFramebuffer = (void*)MM_MapHWPages(gVesa_Modes[mode].framebuffer, giVesaPageCount);\r
+ gpVesa_Framebuffer = (void*)MM_MapHWPages(gVesa_Modes[mode].framebuffer, giVesaPageCount);\r
\r
- LogF("Vesa", "Framebuffer (Phys) = 0x%x", gVesa_Modes[mode].framebuffer);\r
- LogF("Vesa", "Framebuffer (Virt) = 0x%x", gVesaFramebuffer);\r
+ Log_Log("VESA", "Framebuffer (Phys) = 0x%x", gVesa_Modes[mode].framebuffer);\r
+ Log_Log("VESA", "Framebuffer (Virt) = 0x%x", gpVesa_Framebuffer);\r
\r
// Record Mode Set\r
giVesaCurrentMode = mode;\r
+ gpVesaCurMode = &gVesa_Modes[giVesaCurrentMode];\r
\r
RELEASE( &glVesa_Lock );\r
\r
data->bpp = gVesa_Modes[data->id].bpp;\r
return 1;\r
}\r
+\r
+/**\r
+ * \brief Updates the state of the text cursor\r
+ * \note Just does a bitwise not on the cursor region\r
+ */\r
+void Vesa_FlipCursor(void *Arg)\r
+{\r
+ int pitch = gpVesaCurMode->pitch/4;\r
+ int x = giVesaCursorX*giVT_CharWidth;\r
+ int y = giVesaCursorY*giVT_CharHeight;\r
+ int i;\r
+ Uint32 *fb = (void*)gpVesa_Framebuffer;\r
+ \r
+ //Debug("Cursor flip");\r
+ \r
+ // Sanity 1\r
+ if(giVesaCursorX < 0 || giVesaCursorY < 0\r
+ || y*pitch + x + giVT_CharHeight*pitch > (int)gpVesaCurMode->fbSize/4) {\r
+ Debug("Cursor OOB (%i,%i)", x, y);\r
+ giVesaCursorTimer = -1;\r
+ return;\r
+ }\r
+ \r
+ // Draw cursor\r
+ fb += (y+1)*pitch + x;\r
+ for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch )\r
+ *fb = ~*fb;\r
+ \r
+ #if BLINKING_CURSOR\r
+ giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Arg);\r
+ #endif\r
+}\r
+\r
+// ------------------------\r
+// --- 2D Accelleration ---\r
+// ------------------------\r
+void Vesa_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour)\r
+{\r
+ int pitch = gpVesaCurMode->pitch/4;\r
+ Uint32 *buf = (Uint32*)gpVesa_Framebuffer + Y*pitch + X;\r
+ while( H -- ) {\r
+ memsetd(buf, Colour, W);\r
+ buf += pitch;\r
+ }\r
+}\r
+\r
+void Vesa_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H)\r
+{\r
+ int scrnpitch = gVesa_Modes[giVesaCurrentMode].pitch;\r
+ int dst = DstY*scrnpitch + DstX;\r
+ int src = SrcY*scrnpitch + SrcX;\r
+ int tmp;\r
+ \r
+ //Log("Vesa_2D_Blit: (Ent=%p, DstX=%i, DstY=%i, SrcX=%i, SrcY=%i, W=%i, H=%i)",\r
+ // Ent, DstX, DstY, SrcX, SrcY, W, H);\r
+ \r
+ if(SrcX + W > gVesa_Modes[giVesaCurrentMode].width)\r
+ W = gVesa_Modes[giVesaCurrentMode].width - SrcX;\r
+ if(DstX + W > gVesa_Modes[giVesaCurrentMode].width)\r
+ W = gVesa_Modes[giVesaCurrentMode].width - DstX;\r
+ if(SrcY + H > gVesa_Modes[giVesaCurrentMode].height)\r
+ H = gVesa_Modes[giVesaCurrentMode].height - SrcY;\r
+ if(DstY + H > gVesa_Modes[giVesaCurrentMode].height)\r
+ H = gVesa_Modes[giVesaCurrentMode].height - DstY;\r
+ \r
+ //Debug("W = %i, H = %i", W, H);\r
+ \r
+ if( dst > src ) {\r
+ // Reverse copy\r
+ dst += H*scrnpitch;\r
+ src += H*scrnpitch;\r
+ while( H -- ) {\r
+ dst -= scrnpitch;\r
+ src -= scrnpitch;\r
+ tmp = W;\r
+ for( tmp = W; tmp --; ) {\r
+ *(Uint32*)(gpVesa_Framebuffer + dst + tmp) = *(Uint32*)(gpVesa_Framebuffer + src + tmp);\r
+ }\r
+ }\r
+ }\r
+ else {\r
+ // Normal copy is OK\r
+ while( H -- ) {\r
+ memcpy((void*)gpVesa_Framebuffer + dst, (void*)gpVesa_Framebuffer + src, W*sizeof(Uint32));\r
+ dst += scrnpitch;\r
+ src += scrnpitch;\r
+ }\r
+ }\r
+}\r