X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FDisplay%2FVESA%2Fmain.c;h=703e708f8c043c45ee7e36df126e122c61dd48e1;hb=9eec1cc1efa9d3fabc1b040c194dbb1394f13533;hp=43b7147fbff9c8d9a3855e7a1726751393dc1910;hpb=b98fbd4e9c71447d81fc9bd643fb174c76346e0f;p=tpg%2Facess2.git diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index 43b7147f..703e708f 100644 --- a/Modules/Display/VESA/main.c +++ b/Modules/Display/VESA/main.c @@ -16,6 +16,7 @@ // === CONSTANTS === #define FLAG_LFB 0x1 #define VESA_DEFAULT_FRAMEBUFFER (KERNEL_BASE|0xA0000) +#define VESA_CURSOR_PERIOD 1000 // === PROTOTYPES === int Vesa_Install(char **Arguments); @@ -25,6 +26,7 @@ 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); @@ -41,20 +43,27 @@ 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; 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; @@ -240,7 +249,7 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) ); // Sanity Check - if(y > heightInChars) { + if(y >= heightInChars) { LEAVE('i', 0); return 0; } @@ -348,6 +357,22 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) return ret; case VIDEO_IOCTL_SETCURSOR: // Set cursor position + giVesaCursorX = ((tVideo_IOCtl_Pos*)Data)->x; + giVesaCursorY = ((tVideo_IOCtl_Pos*)Data)->y; + if( + giVesaCursorX < 0 || giVesaCursorY < 0 + || giVesaCursorX >= gVesa_Modes[giVesaCurrentMode].width + || giVesaCursorY >= gVesa_Modes[giVesaCurrentMode].height) + { + if(giVesaCursorTimer != -1) + Time_RemoveTimer(giVesaCursorTimer); + giVesaCursorX = -1; + giVesaCursorY = -1; + } + else { + if(giVesaCursorTimer == -1) + giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Node); + } return 0; case VIDEO_IOCTL_REQLFB: // Request Linear Framebuffer @@ -356,6 +381,9 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) return 0; } +/** + * \brief Updates the video mode + */ int Vesa_Int_SetMode(int mode) { Log_Log("VESA", "Setting mode to %i", mode); @@ -366,6 +394,8 @@ int Vesa_Int_SetMode(int mode) // Check for fast return if(mode == giVesaCurrentMode) return 1; + Time_RemoveTimer(giVesaCursorTimer); + LOCK( &glVesa_Lock ); gpVesa_BiosState->AX = 0x4F02; @@ -446,6 +476,26 @@ int Vesa_Int_ModeInfo(tVideo_IOCtl_Mode *data) 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 = gVesa_Modes[giVesaCurrentMode].pitch/4; + int x = giVesaCursorX*giVT_CharWidth; + int y = giVesaCursorY*giVT_CharHeight; + int i; + Uint32 *fb = (void*)gpVesa_Framebuffer; + + if(giVesaCursorX < 0 || giVesaCursorY < 0) return; + + for( i = 1; i < giVT_CharHeight-1; i++ ) + fb[(y+i)*pitch+x] = ~fb[(y+i)*pitch+x]; + + giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Arg); +} + // ------------------------ // --- 2D Accelleration --- // ------------------------ @@ -461,42 +511,44 @@ void Vesa_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colo void Vesa_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H) { - int scrnwidth = gVesa_Modes[giVesaCurrentMode].width; - int dst = DstY*scrnwidth + DstX; - int src = SrcY*scrnwidth + SrcX; + 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 > scrnwidth) - W = scrnwidth - SrcX; - if(DstX + W > scrnwidth) - W = scrnwidth - DstX; + 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*scrnwidth; - src += H*scrnwidth; + dst += H*scrnpitch; + src += H*scrnpitch; while( H -- ) { - dst -= scrnwidth; - src -= scrnwidth; + dst -= scrnpitch; + src -= scrnpitch; tmp = W; for( tmp = W; tmp --; ) { - *((Uint32*)gpVesa_Framebuffer + dst + tmp) = *((Uint32*)gpVesa_Framebuffer + src + tmp); + *(Uint32*)(gpVesa_Framebuffer + dst + tmp) = *(Uint32*)(gpVesa_Framebuffer + src + tmp); } } } else { // Normal copy is OK while( H -- ) { - memcpyd((Uint32*)gpVesa_Framebuffer + dst, (Uint32*)gpVesa_Framebuffer + src, W); - dst += scrnwidth; - src += scrnwidth; + memcpy((void*)gpVesa_Framebuffer + dst, (void*)gpVesa_Framebuffer + src, W*sizeof(Uint32)); + dst += scrnpitch; + src += scrnpitch; } } }