X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FDisplay%2FVESA%2Fmain.c;h=ff9e514969ca3468b21bd5cbdacd458a3c0b294e;hb=320aba7c7d009697ba5e51ac684722b56d696bea;hp=e625c57705118e6bfd980ca3fffe6c5decf04daa;hpb=144175640d070e26aa6a661a3a0014fa69e604dd;p=tpg%2Facess2.git diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index e625c577..ff9e5149 100644 --- a/Modules/Display/VESA/main.c +++ b/Modules/Display/VESA/main.c @@ -16,6 +16,10 @@ // === CONSTANTS === #define FLAG_LFB 0x1 #define VESA_DEFAULT_FRAMEBUFFER (KERNEL_BASE|0xA0000) +#define BLINKING_CURSOR 1 +#if BLINKING_CURSOR +# define VESA_CURSOR_PERIOD 1000 +#endif // === PROTOTYPES === int Vesa_Install(char **Arguments); @@ -25,6 +29,10 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); int Vesa_Int_SetMode(int Mode); int Vesa_Int_FindMode(tVideo_IOCtl_Mode *data); int Vesa_Int_ModeInfo(tVideo_IOCtl_Mode *data); +void Vesa_FlipCursor(void *Arg); +// --- 2D Acceleration Functions -- +void Vesa_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour); +void Vesa_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H); // === GLOBALS === MODULE_DEFINE(0, VERSION, Vesa, Vesa_Install, NULL, "PCI", "VM8086", NULL); @@ -38,15 +46,28 @@ tDevFS_Driver gVesa_DriverStruct = { }; tSpinlock glVesa_Lock; tVM8086 *gpVesa_BiosState; + int giVesaDriverId = -1; +// --- Video Modes --- int giVesaCurrentMode = 0; int giVesaCurrentFormat = VIDEO_BUFFMT_TEXT; - int giVesaDriverId = -1; -char *gpVesa_Framebuffer = (void*)VESA_DEFAULT_FRAMEBUFFER; tVesa_Mode *gVesa_Modes; +tVesa_Mode *gpVesaCurMode; int giVesaModeCount = 0; - int giVesaPageCount = 0; +// --- Framebuffer --- +char *gpVesa_Framebuffer = (void*)VESA_DEFAULT_FRAMEBUFFER; + int giVesaPageCount = 0; //!< Framebuffer size in pages +// --- Cursor Control --- + int giVesaCursorX = -1; + int giVesaCursorY = -1; + int giVesaCursorTimer = -1; // Invalid timer +// --- 2D Video Stream Handlers --- +tDrvUtil_Video_2DHandlers gVesa_2DFunctions = { + NULL, + Vesa_2D_Fill, + Vesa_2D_Blit +}; -//CODE +// === CODE === int Vesa_Install(char **Arguments) { tVesa_CallInfo *info; @@ -68,7 +89,7 @@ int Vesa_Install(char **Arguments) // Call Interrupt VM8086_Int(gpVesa_BiosState, 0x10); if(gpVesa_BiosState->AX != 0x004F) { - Log_Warning("VESA", "Vesa_Install - VESA/VBE Unsupported (AX = 0x%x)\n", gpVesa_BiosState->AX); + Log_Warning("VESA", "Vesa_Install - VESA/VBE Unsupported (AX = 0x%x)", gpVesa_BiosState->AX); return MODULE_ERR_NOTNEEDED; } @@ -211,7 +232,8 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) { tVT_Char *chars = Buffer; int pitch = gVesa_Modes[giVesaCurrentMode].width; - int widthInChars; + int widthInChars = gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth; + int heightInChars = gVesa_Modes[giVesaCurrentMode].height/giVT_CharHeight; int x, y; Uint32 *dest = (void*)gpVesa_Framebuffer; int i; @@ -220,7 +242,6 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) Offset /= sizeof(tVT_Char); LOG("gVesa_Modes[%i].width = %i", giVesaCurrentMode, gVesa_Modes[giVesaCurrentMode].width); - widthInChars = gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth; x = Offset % widthInChars; y = Offset / widthInChars; LOG("(x,y) = (%i,%i) = [%i,%i]", x, y, x * giVT_CharWidth, y * giVT_CharHeight * pitch); @@ -232,17 +253,29 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) ); // Sanity Check - if(y > gVesa_Modes[giVesaCurrentMode].height/giVT_CharHeight) { + if( Offset > (Uint64)(heightInChars*widthInChars) ) { + LEAVE('i', 0); + return 0; + } + if(y >= heightInChars) { LEAVE('i', 0); return 0; } + + if( (int)Offset + (int)Length > heightInChars*widthInChars ) { + Log_Debug("VESA", "%i + %i > %i*%i (%i)", + (int)Offset, (int)Length, heightInChars, widthInChars, heightInChars*widthInChars); + Length = heightInChars*widthInChars - Offset; + Log_Notice("VESA", "Clipping write size to %i characters", (int)Length); + } + dest += y * giVT_CharHeight * pitch; dest += x * giVT_CharWidth; LOG("dest = %p", dest); - for( i = 0; i < Length; i++ ) + for( i = 0; i < (int)Length; i++ ) { VT_Font_Render( chars->Ch, @@ -251,7 +284,6 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) VT_Colour12to24(chars->FGCol) ); - chars ++; x ++; if( x >= widthInChars ) { @@ -285,6 +317,14 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) LOG("BGA Framebuffer updated"); } break; + + case VIDEO_BUFFMT_2DSTREAM: + Length = DrvUtil_Video_2DStream( + NULL, // Single framebuffer, so Ent is unused + Buffer, Length, &gVesa_2DFunctions, sizeof(gVesa_2DFunctions) + ); + break; + default: LEAVE('i', -1); return -1; @@ -301,6 +341,7 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) { int ret; + //Log_Debug("VESA", "Vesa_Ioctl: (Node=%p, ID=%i, Data=%p)", Node, ID, Data); switch(ID) { case DRV_IOCTL_TYPE: return DRV_TYPE_VIDEO; @@ -319,17 +360,54 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) case VIDEO_IOCTL_SETBUFFORMAT: ret = giVesaCurrentFormat; if(Data) { - Log_Log("VESA", "Buffer mode to %i", *(int*)Data); + //Log_Log("VESA", "Buffer mode to %i", *(int*)Data); giVesaCurrentFormat = *(int*)Data; } return ret; + case VIDEO_IOCTL_SETCURSOR: // Set cursor position + #if !BLINKING_CURSOR + if(giVesaCursorX > 0) + Vesa_FlipCursor(Node); + #endif + giVesaCursorX = ((tVideo_IOCtl_Pos*)Data)->x; + giVesaCursorY = ((tVideo_IOCtl_Pos*)Data)->y; + //Log_Debug("VESA", "Cursor position (%i,%i)", giVesaCursorX, giVesaCursorY); + if( + giVesaCursorX < 0 || giVesaCursorY < 0 + || giVesaCursorX >= gpVesaCurMode->width/giVT_CharWidth + || giVesaCursorY >= gpVesaCurMode->height/giVT_CharHeight) + { + #if BLINKING_CURSOR + if(giVesaCursorTimer != -1) { + Time_RemoveTimer(giVesaCursorTimer); + giVesaCursorTimer = -1; + } + #endif + giVesaCursorX = -1; + giVesaCursorY = -1; + } + else { + #if BLINKING_CURSOR + // Log_Debug("VESA", "Updating timer %i?", giVesaCursorTimer); + if(giVesaCursorTimer == -1) + giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Node); + #else + Vesa_FlipCursor(Node); + #endif + } + //Log_Debug("VESA", "Cursor position (%i,%i) Timer %i", giVesaCursorX, giVesaCursorY, giVesaCursorTimer); + return 0; + case VIDEO_IOCTL_REQLFB: // Request Linear Framebuffer return 0; } return 0; } +/** + * \brief Updates the video mode + */ int Vesa_Int_SetMode(int mode) { Log_Log("VESA", "Setting mode to %i", mode); @@ -340,6 +418,9 @@ int Vesa_Int_SetMode(int mode) // Check for fast return if(mode == giVesaCurrentMode) return 1; + Time_RemoveTimer(giVesaCursorTimer); + giVesaCursorTimer = -1; + LOCK( &glVesa_Lock ); gpVesa_BiosState->AX = 0x4F02; @@ -363,6 +444,7 @@ int Vesa_Int_SetMode(int mode) // Record Mode Set giVesaCurrentMode = mode; + gpVesaCurMode = &gVesa_Modes[giVesaCurrentMode]; RELEASE( &glVesa_Lock ); @@ -419,3 +501,92 @@ int Vesa_Int_ModeInfo(tVideo_IOCtl_Mode *data) data->bpp = gVesa_Modes[data->id].bpp; return 1; } + +/** + * \brief Updates the state of the text cursor + * \note Just does a bitwise not on the cursor region + */ +void Vesa_FlipCursor(void *Arg) +{ + int pitch = gpVesaCurMode->pitch/4; + int x = giVesaCursorX*giVT_CharWidth; + int y = giVesaCursorY*giVT_CharHeight; + int i; + Uint32 *fb = (void*)gpVesa_Framebuffer; + + //Debug("Cursor flip"); + + // Sanity 1 + if(giVesaCursorX < 0 || giVesaCursorY < 0 + || y*pitch + x + giVT_CharHeight*pitch > (int)gpVesaCurMode->fbSize/4) { + Debug("Cursor OOB (%i,%i)", x, y); + giVesaCursorTimer = -1; + return; + } + + // Draw cursor + fb += (y+1)*pitch + x; + for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) + *fb = ~*fb; + + #if BLINKING_CURSOR + giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Arg); + #endif +} + +// ------------------------ +// --- 2D Accelleration --- +// ------------------------ +void Vesa_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour) +{ + int pitch = gpVesaCurMode->pitch/4; + Uint32 *buf = (Uint32*)gpVesa_Framebuffer + Y*pitch + X; + while( H -- ) { + memsetd(buf, Colour, W); + buf += pitch; + } +} + +void Vesa_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H) +{ + int scrnpitch = gVesa_Modes[giVesaCurrentMode].pitch; + int dst = DstY*scrnpitch + DstX; + int src = SrcY*scrnpitch + SrcX; + int tmp; + + //Log("Vesa_2D_Blit: (Ent=%p, DstX=%i, DstY=%i, SrcX=%i, SrcY=%i, W=%i, H=%i)", + // Ent, DstX, DstY, SrcX, SrcY, W, H); + + if(SrcX + W > gVesa_Modes[giVesaCurrentMode].width) + W = gVesa_Modes[giVesaCurrentMode].width - SrcX; + if(DstX + W > gVesa_Modes[giVesaCurrentMode].width) + W = gVesa_Modes[giVesaCurrentMode].width - DstX; + if(SrcY + H > gVesa_Modes[giVesaCurrentMode].height) + H = gVesa_Modes[giVesaCurrentMode].height - SrcY; + if(DstY + H > gVesa_Modes[giVesaCurrentMode].height) + H = gVesa_Modes[giVesaCurrentMode].height - DstY; + + //Debug("W = %i, H = %i", W, H); + + if( dst > src ) { + // Reverse copy + dst += H*scrnpitch; + src += H*scrnpitch; + while( H -- ) { + dst -= scrnpitch; + src -= scrnpitch; + tmp = W; + for( tmp = W; tmp --; ) { + *(Uint32*)(gpVesa_Framebuffer + dst + tmp) = *(Uint32*)(gpVesa_Framebuffer + src + tmp); + } + } + } + else { + // Normal copy is OK + while( H -- ) { + memcpy((void*)gpVesa_Framebuffer + dst, (void*)gpVesa_Framebuffer + src, W*sizeof(Uint32)); + dst += scrnpitch; + src += scrnpitch; + } + } +}