X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FDisplay%2FVESA%2Fmain.c;h=55083b043a808ed16f07775536beb6f6ffc12143;hb=8de6b4e1a2050289458d6489551eb61b6c1d3645;hp=9b3de8d193c53cc3cf0ac59787eadf1d2804eb91;hpb=3998cfbbadb005bf3ad52ea2538dc21f82864ddc;p=tpg%2Facess2.git diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index 9b3de8d1..55083b04 100644 --- a/Modules/Display/VESA/main.c +++ b/Modules/Display/VESA/main.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include @@ -16,7 +16,7 @@ // === CONSTANTS === #define FLAG_LFB 0x1 #define VESA_DEFAULT_FRAMEBUFFER (KERNEL_BASE|0xA0000) -#define BLINKING_CURSOR 0 +#define BLINKING_CURSOR 1 #if BLINKING_CURSOR # define VESA_CURSOR_PERIOD 1000 #endif @@ -25,14 +25,13 @@ int Vesa_Install(char **Arguments); Uint64 Vesa_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); - int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data); + int Vesa_IOCtl(tVFS_Node *Node, int ID, void *Data); int Vesa_Int_SetMode(int Mode); int Vesa_Int_FindMode(tVideo_IOCtl_Mode *data); int Vesa_Int_ModeInfo(tVideo_IOCtl_Mode *data); +void Vesa_int_HideCursor(void); +void Vesa_int_ShowCursor(void); 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); @@ -41,18 +40,18 @@ tDevFS_Driver gVesa_DriverStruct = { { .Read = Vesa_Read, .Write = Vesa_Write, - .IOCtl = Vesa_Ioctl + .IOCtl = Vesa_IOCtl } }; -tSpinlock glVesa_Lock; +tMutex glVesa_Lock; tVM8086 *gpVesa_BiosState; int giVesaDriverId = -1; // --- Video Modes --- int giVesaCurrentMode = 0; - int giVesaCurrentFormat = VIDEO_BUFFMT_TEXT; tVesa_Mode *gVesa_Modes; tVesa_Mode *gpVesaCurMode; int giVesaModeCount = 0; + int gbVesaModesChecked; // --- Framebuffer --- char *gpVesa_Framebuffer = (void*)VESA_DEFAULT_FRAMEBUFFER; int giVesaPageCount = 0; //!< Framebuffer size in pages @@ -60,27 +59,21 @@ char *gpVesa_Framebuffer = (void*)VESA_DEFAULT_FRAMEBUFFER; int giVesaCursorX = -1; int giVesaCursorY = -1; int giVesaCursorTimer = -1; // Invalid timer + int gbVesa_CursorVisible = 0; // --- 2D Video Stream Handlers --- -tDrvUtil_Video_2DHandlers gVesa_2DFunctions = { - NULL, - Vesa_2D_Fill, - Vesa_2D_Blit -}; +tDrvUtil_Video_BufInfo gVesa_BufInfo; // === CODE === int Vesa_Install(char **Arguments) { tVesa_CallInfo *info; tFarPtr infoPtr; - tVesa_CallModeInfo *modeinfo; - tFarPtr modeinfoPtr; Uint16 *modes; int i; // Allocate Info Block gpVesa_BiosState = VM8086_Init(); info = VM8086_Allocate(gpVesa_BiosState, 512, &infoPtr.seg, &infoPtr.ofs); - modeinfo = VM8086_Allocate(gpVesa_BiosState, 512, &modeinfoPtr.seg, &modeinfoPtr.ofs); // Set Requested Version memcpy(info->signature, "VBE2", 4); // Set Registers @@ -93,13 +86,15 @@ int Vesa_Install(char **Arguments) return MODULE_ERR_NOTNEEDED; } - Log_Debug("VESA", "info->VideoModes = %04x:%04x", info->VideoModes.seg, info->VideoModes.ofs); + //Log_Debug("VESA", "info->VideoModes = %04x:%04x", info->VideoModes.seg, info->VideoModes.ofs); modes = (Uint16 *) VM8086_GetPointer(gpVesa_BiosState, info->VideoModes.seg, info->VideoModes.ofs); // Read Modes for( giVesaModeCount = 0; modes[giVesaModeCount] != 0xFFFF; giVesaModeCount++ ); gVesa_Modes = (tVesa_Mode *)malloc( giVesaModeCount * sizeof(tVesa_Mode) ); + Log_Debug("VESA", "%i Modes", giVesaModeCount); + // Insert Text Mode gVesa_Modes[0].width = 80; gVesa_Modes[0].height = 25; @@ -112,36 +107,9 @@ int Vesa_Install(char **Arguments) for( i = 1; i < giVesaModeCount; i++ ) { gVesa_Modes[i].code = modes[i]; - // Get Mode info - gpVesa_BiosState->AX = 0x4F01; - gpVesa_BiosState->CX = gVesa_Modes[i].code; - gpVesa_BiosState->ES = modeinfoPtr.seg; - gpVesa_BiosState->DI = modeinfoPtr.ofs; - VM8086_Int(gpVesa_BiosState, 0x10); - - // Parse Info - gVesa_Modes[i].flags = 0; - if ( (modeinfo->attributes & 0x90) == 0x90 ) - { - gVesa_Modes[i].flags |= FLAG_LFB; - gVesa_Modes[i].framebuffer = modeinfo->physbase; - gVesa_Modes[i].fbSize = modeinfo->Xres*modeinfo->Yres*modeinfo->bpp/8; - } else { - gVesa_Modes[i].framebuffer = 0; - gVesa_Modes[i].fbSize = 0; - } - - gVesa_Modes[i].pitch = modeinfo->pitch; - gVesa_Modes[i].width = modeinfo->Xres; - gVesa_Modes[i].height = modeinfo->Yres; - gVesa_Modes[i].bpp = modeinfo->bpp; - - #if DEBUG - Log_Log("VESA", "0x%x - %ix%ix%i", - gVesa_Modes[i].code, gVesa_Modes[i].width, gVesa_Modes[i].height, gVesa_Modes[i].bpp); - #endif } - + +// VM8086_Deallocate( info ); // Install Device giVesaDriverId = DevFS_AddDevice( &gVesa_DriverStruct ); @@ -150,6 +118,53 @@ int Vesa_Install(char **Arguments) return MODULE_ERR_OK; } +void Vesa_int_FillModeList(void) +{ + if( !gbVesaModesChecked ) + { + int i; + tVesa_CallModeInfo *modeinfo; + tFarPtr modeinfoPtr; + + modeinfo = VM8086_Allocate(gpVesa_BiosState, 512, &modeinfoPtr.seg, &modeinfoPtr.ofs); + for( i = 1; i < giVesaModeCount; i ++ ) + { + // Get Mode info + gpVesa_BiosState->AX = 0x4F01; + gpVesa_BiosState->CX = gVesa_Modes[i].code; + gpVesa_BiosState->ES = modeinfoPtr.seg; + gpVesa_BiosState->DI = modeinfoPtr.ofs; + VM8086_Int(gpVesa_BiosState, 0x10); + + // Parse Info + gVesa_Modes[i].flags = 0; + if ( (modeinfo->attributes & 0x90) == 0x90 ) + { + gVesa_Modes[i].flags |= FLAG_LFB; + gVesa_Modes[i].framebuffer = modeinfo->physbase; + gVesa_Modes[i].fbSize = modeinfo->Yres*modeinfo->pitch; + } else { + gVesa_Modes[i].framebuffer = 0; + gVesa_Modes[i].fbSize = 0; + } + + gVesa_Modes[i].pitch = modeinfo->pitch; + gVesa_Modes[i].width = modeinfo->Xres; + gVesa_Modes[i].height = modeinfo->Yres; + gVesa_Modes[i].bpp = modeinfo->bpp; + + #if DEBUG + Log_Log("VESA", "0x%x - %ix%ix%i", + gVesa_Modes[i].code, gVesa_Modes[i].width, gVesa_Modes[i].height, gVesa_Modes[i].bpp); + #endif + } + +// VM8086_Deallocate( modeinfo ); + + gbVesaModesChecked = 1; + } +} + /* Read from the framebuffer */ Uint64 Vesa_Read(tVFS_Node *Node, Uint64 off, Uint64 len, void *buffer) @@ -165,184 +180,26 @@ Uint64 Vesa_Read(tVFS_Node *Node, Uint64 off, Uint64 len, void *buffer) */ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) { - ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer); - - if(Buffer == NULL) { - LEAVE('i', 0); - return 0; - } - - // Default Text mode - if( giVesaCurrentMode == 0 ) - { - Uint16 *fb = (Uint16*)(KERNEL_BASE|0xB8000); - tVT_Char *chars = Buffer; - int rem; - - Length /= sizeof(tVT_Char); - Offset /= sizeof(tVT_Char); - - if( giVesaCurrentFormat != VIDEO_BUFFMT_TEXT ) { - Log_Warning("VESA", "Vesa_Write - Mode 0 is not framebuffer"); - LEAVE('i', -1); - return -1; - } - - if( Offset + Length > 25*80 ) { - Log_Warning("VESA", "Vesa_Write - Framebuffer Overflow"); - LEAVE('i', 0); - return 0; - } - - fb += 2*Offset; - LOG("fb = %p", fb); - for(rem = Length; rem --; fb ++, chars++) - { - if( chars->Ch < 0x80 ) - *fb = chars->Ch & 0x7F; - else - *fb = 0x00; - - *fb |= (chars->FGCol & 0x888) == 0x888 ? 0x8 : 0; - *fb |= (chars->FGCol & 0x700) > 0x300 ? 0x4 : 0; - *fb |= (chars->FGCol & 0x070) > 0x030 ? 0x2 : 0; - *fb |= (chars->FGCol & 0x007) > 0x003 ? 0x1 : 0; - *fb |= (chars->BGCol & 0x888) == 0x888 ? 0x80 : 0; - *fb |= (chars->BGCol & 0x700) > 0x300 ? 0x40 : 0; - *fb |= (chars->BGCol & 0x070) > 0x030 ? 0x20 : 0; - *fb |= (chars->BGCol & 0x007) > 0x003 ? 0x10 : 0; - //LOG("%08x (%03x,%03x) = %04x", - // chars->Ch, chars->BGCol, chars->FGCol, *fb); - } - Length *= sizeof(tVT_Char); - LEAVE('X', Length); - return Length; - } - if( gVesa_Modes[giVesaCurrentMode].framebuffer == 0 ) { Log_Warning("VESA", "Vesa_Write - Non-LFB Modes not yet supported."); - LEAVE('i', 0); return 0; } - - // Text Mode - switch( giVesaCurrentFormat ) - { - case VIDEO_BUFFMT_TEXT: - { - tVT_Char *chars = Buffer; - int pitch = gVesa_Modes[giVesaCurrentMode].width; - 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; - - Length /= sizeof(tVT_Char); - Offset /= sizeof(tVT_Char); - - LOG("gVesa_Modes[%i].width = %i", giVesaCurrentMode, gVesa_Modes[giVesaCurrentMode].width); - x = Offset % widthInChars; - y = Offset / widthInChars; - LOG("(x,y) = (%i,%i) = [%i,%i]", x, y, x * giVT_CharWidth, y * giVT_CharHeight * pitch); - LOG("(w,h) = (%i,%i) = [%i,%i]", - (int)(Length % widthInChars), - (int)(Length / widthInChars), - (int)((Length % widthInChars) * giVT_CharWidth), - (int)((Length / widthInChars) * giVT_CharHeight * pitch) - ); - - // Sanity Check - if(y >= heightInChars) { - LEAVE('i', 0); - return 0; - } - - if( Offset + 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++ ) - { - VT_Font_Render( - chars->Ch, - dest + x*giVT_CharWidth, pitch, - VT_Colour12to24(chars->BGCol), - VT_Colour12to24(chars->FGCol) - ); - - chars ++; - x ++; - if( x >= widthInChars ) { - x = 0; - y ++; - dest += pitch*giVT_CharHeight; - } - } - Length *= sizeof(tVT_Char); - } - break; - - case VIDEO_BUFFMT_FRAMEBUFFER: - { - Uint8 *destBuf = (Uint8*) ((Uint)gpVesa_Framebuffer + (Uint)Offset); - - if(gVesa_Modes[giVesaCurrentMode].fbSize < Offset+Length) - { - Log_Warning("VESA", "Vesa_Write - Framebuffer Overflow"); - LEAVE('i', 0); - return 0; - } - - LOG("buffer = %p", Buffer); - LOG("Updating Framebuffer (%p to %p)", destBuf, destBuf + (Uint)Length); - - - // Copy to Frambuffer - memcpy(destBuf, Buffer, Length); - - 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; - } - - LEAVE('X', Length); - return Length; + + return DrvUtil_Video_WriteLFB(&gVesa_BufInfo, Offset, Length, Buffer); } +const char *csaVESA_IOCtls[] = {DRV_IOCTLNAMES, DRV_VIDEO_IOCTLNAMES, NULL}; /** - * \fn int Vesa_Ioctl(vfs_node *node, int id, void *data) * \brief Handle messages to the device */ -int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) +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; - case DRV_IOCTL_IDENT: memcpy("VESA", Data, 4); return 1; - case DRV_IOCTL_VERSION: return VERSION; - + BASE_IOCTLS(DRV_TYPE_VIDEO, "VESA", VERSION, csaVESA_IOCtls); + case VIDEO_IOCTL_GETSETMODE: if( !Data ) return giVesaCurrentMode; return Vesa_Int_SetMode( *(int*)Data ); @@ -353,48 +210,23 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) return Vesa_Int_ModeInfo((tVideo_IOCtl_Mode*)Data); case VIDEO_IOCTL_SETBUFFORMAT: - ret = giVesaCurrentFormat; - if(Data) { - //Log_Log("VESA", "Buffer mode to %i", *(int*)Data); - giVesaCurrentFormat = *(int*)Data; - } + Vesa_int_HideCursor(); + ret = gVesa_BufInfo.BufferFormat; + if(Data) gVesa_BufInfo.BufferFormat = *(int*)Data; + if(gVesa_BufInfo.BufferFormat == VIDEO_BUFFMT_TEXT) + DrvUtil_Video_SetCursor( &gVesa_BufInfo, &gDrvUtil_TextModeCursor ); + Vesa_int_ShowCursor(); return ret; case VIDEO_IOCTL_SETCURSOR: // Set cursor position - #if !BLINKING_CURSOR - if(giVesaCursorX > 0 && giVesaCursorY) - Vesa_FlipCursor(Node); - #endif + Vesa_int_HideCursor(); 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); + Vesa_int_ShowCursor(); return 0; - case VIDEO_IOCTL_REQLFB: // Request Linear Framebuffer + case VIDEO_IOCTL_SETCURSORBITMAP: + DrvUtil_Video_SetCursor( &gVesa_BufInfo, Data ); return 0; } return 0; @@ -404,24 +236,23 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) * \brief Updates the video mode */ int Vesa_Int_SetMode(int mode) -{ - Log_Log("VESA", "Setting mode to %i", mode); - +{ // Sanity Check values if(mode < 0 || mode > giVesaModeCount) return -1; - + // Check for fast return if(mode == giVesaCurrentMode) return 1; + Vesa_int_FillModeList(); + Time_RemoveTimer(giVesaCursorTimer); giVesaCursorTimer = -1; - LOCK( &glVesa_Lock ); + Mutex_Acquire( &glVesa_Lock ); gpVesa_BiosState->AX = 0x4F02; gpVesa_BiosState->BX = gVesa_Modes[mode].code; if(gVesa_Modes[mode].flags & FLAG_LFB) { - Log_Log("VESA", "Using LFB"); gpVesa_BiosState->BX |= 0x4000; // Bit 14 - Use LFB } @@ -434,15 +265,25 @@ int Vesa_Int_SetMode(int mode) giVesaPageCount = (gVesa_Modes[mode].fbSize + 0xFFF) >> 12; gpVesa_Framebuffer = (void*)MM_MapHWPages(gVesa_Modes[mode].framebuffer, giVesaPageCount); - Log_Log("VESA", "Framebuffer (Phys) = 0x%x", gVesa_Modes[mode].framebuffer); - Log_Log("VESA", "Framebuffer (Virt) = 0x%x", gpVesa_Framebuffer); + Log_Log("VESA", "Setting mode to %i (%ix%i %ibpp) %p[0x%x] maps %P", + mode, + gVesa_Modes[mode].width, gVesa_Modes[mode].height, + gVesa_Modes[mode].bpp, + gpVesa_Framebuffer, giVesaPageCount << 12, gVesa_Modes[mode].framebuffer + ); // Record Mode Set giVesaCurrentMode = mode; gpVesaCurMode = &gVesa_Modes[giVesaCurrentMode]; - RELEASE( &glVesa_Lock ); - + Mutex_Release( &glVesa_Lock ); + + gVesa_BufInfo.Framebuffer = gpVesa_Framebuffer; + gVesa_BufInfo.Pitch = gVesa_Modes[mode].pitch; + gVesa_BufInfo.Width = gVesa_Modes[mode].width; + gVesa_BufInfo.Height = gVesa_Modes[mode].height; + gVesa_BufInfo.Depth = gVesa_Modes[mode].bpp; + return 1; } @@ -453,24 +294,43 @@ int Vesa_Int_FindMode(tVideo_IOCtl_Mode *data) int factor, tmp; ENTER("idata->width idata->height idata->bpp", data->width, data->height, data->bpp); + + Vesa_int_FillModeList(); for(i=0;iwidth - && gVesa_Modes[i].height == data->height - && gVesa_Modes[i].bpp == data->bpp) + if(gVesa_Modes[i].width == data->width && gVesa_Modes[i].height == data->height) { - LOG("Perfect!"); - best = i; - break; + //if( (data->bpp == 32 || data->bpp == 24) + // && (gVesa_Modes[i].bpp == 32 || gVesa_Modes[i].bpp == 24) ) + if( data->bpp == gVesa_Modes[i].bpp ) + { + LOG("Perfect!"); + best = i; + break; + } } - tmp = gVesa_Modes[i].width * gVesa_Modes[i].height * gVesa_Modes[i].bpp; - tmp -= data->width * data->height * data->bpp; + tmp = gVesa_Modes[i].width * gVesa_Modes[i].height; + tmp -= data->width * data->height; tmp = tmp < 0 ? -tmp : tmp; - factor = tmp * 100 / (data->width * data->height * data->bpp); + factor = tmp * 1000 / (data->width * data->height); + + if( data->bpp == 8 && gVesa_Modes[i].bpp != 8 ) continue; + if( data->bpp == 16 && gVesa_Modes[i].bpp != 16 ) continue; + + if( (data->bpp == 32 || data->bpp == 24) + && (gVesa_Modes[i].bpp == 32 || gVesa_Modes[i].bpp == 24) ) + { + if( data->bpp == gVesa_Modes[i].bpp ) + factor /= 2; + } + else { + if( data->bpp != gVesa_Modes[i].bpp ) + continue ; + } LOG("factor = %i", factor); @@ -491,97 +351,67 @@ int Vesa_Int_FindMode(tVideo_IOCtl_Mode *data) int Vesa_Int_ModeInfo(tVideo_IOCtl_Mode *data) { if(data->id < 0 || data->id > giVesaModeCount) return -1; + + Vesa_int_FillModeList(); + data->width = gVesa_Modes[data->id].width; data->height = gVesa_Modes[data->id].height; 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) +void Vesa_int_HideCursor(void) { - 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 > gpVesaCurMode->fbSize/4) { - Debug("Cursor OOB (%i,%i)", x, y); + DrvUtil_Video_RemoveCursor( &gVesa_BufInfo ); + #if BLINKING_CURSOR + if(giVesaCursorTimer != -1) { + Time_RemoveTimer(giVesaCursorTimer); 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) +void Vesa_int_ShowCursor(void) { - int pitch = gpVesaCurMode->pitch/4; - Uint32 *buf = (Uint32*)gpVesa_Framebuffer + Y*pitch + X; - while( H -- ) { - memsetd(buf, Colour, W); - buf += pitch; + gbVesa_CursorVisible = (giVesaCursorX >= 0); + if(gVesa_BufInfo.BufferFormat == VIDEO_BUFFMT_TEXT) + { + DrvUtil_Video_DrawCursor( + &gVesa_BufInfo, + giVesaCursorX*giVT_CharWidth, + giVesaCursorY*giVT_CharHeight + ); + #if BLINKING_CURSOR + giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, NULL); + #endif } + else + DrvUtil_Video_DrawCursor( + &gVesa_BufInfo, + giVesaCursorX, + giVesaCursorY + ); } -void Vesa_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H) +/** + * \brief Swaps the text cursor on/off + */ +void Vesa_FlipCursor(void *Arg) { - 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; - } - } + if( gVesa_BufInfo.BufferFormat != VIDEO_BUFFMT_TEXT ) + return ; + + if( gbVesa_CursorVisible ) + DrvUtil_Video_RemoveCursor(&gVesa_BufInfo); + else + DrvUtil_Video_DrawCursor(&gVesa_BufInfo, + giVesaCursorX*giVT_CharWidth, + giVesaCursorY*giVT_CharHeight + ); + gbVesa_CursorVisible = !gbVesa_CursorVisible; + + #if BLINKING_CURSOR + giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Arg); + #endif } +