X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FDisplay%2FVESA%2Fmain.c;h=e30d64064f36e598b27cd1402310f912394fbc3c;hb=1c821df6e9a345c41e0b7e5b71544ec6defb7faf;hp=69292933d130ad73ae303222c13ce546e74176d0;hpb=7f07ccaa4d128305aed6f67f1f57a5c9276a895f;p=tpg%2Facess2.git diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index 69292933..e30d6406 100644 --- a/Modules/Display/VESA/main.c +++ b/Modules/Display/VESA/main.c @@ -2,7 +2,7 @@ * AcessOS 1 * Video BIOS Extensions (Vesa) Driver */ -#define DEBUG 1 +#define DEBUG 0 #define VERSION 0x100 #include @@ -15,6 +15,8 @@ // === CONSTANTS === #define FLAG_LFB 0x1 +#define VESA_DEFAULT_FRAMEBUFFER (KERNEL_BASE|0xA0000) +#define VESA_CURSOR_PERIOD 1000 // === PROTOTYPES === int Vesa_Install(char **Arguments); @@ -24,6 +26,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); @@ -37,14 +43,28 @@ tDevFS_Driver gVesa_DriverStruct = { }; tSpinlock glVesa_Lock; tVM8086 *gpVesa_BiosState; - int giVesaCurrentMode = -1; int giVesaDriverId = -1; -char *gVesaFramebuffer = (void*)0xC00A0000; +// --- Video Modes --- + int giVesaCurrentMode = 0; + int giVesaCurrentFormat = VIDEO_BUFFMT_TEXT; 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; @@ -66,11 +86,11 @@ 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; } - 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 @@ -82,7 +102,7 @@ int Vesa_Install(char **Arguments) gVesa_Modes[0].height = 25; gVesa_Modes[0].bpp = 12; gVesa_Modes[0].code = 0x3; - gVesa_Modes[0].flags = VIDEO_FLAG_TEXT; + gVesa_Modes[0].flags = 1; gVesa_Modes[0].fbSize = 80*25*2; gVesa_Modes[0].framebuffer = 0xB8000; @@ -108,12 +128,13 @@ int Vesa_Install(char **Arguments) 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", + 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 } @@ -131,7 +152,7 @@ int Vesa_Install(char **Arguments) Uint64 Vesa_Read(tVFS_Node *Node, Uint64 off, Uint64 len, void *buffer) { #if DEBUG >= 2 - LogF("Vesa_Read: () - NULL\n"); + Log("Vesa_Read: () - NULL\n"); #endif return 0; } @@ -151,34 +172,48 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) // Default Text mode if( giVesaCurrentMode == 0 ) { - Uint8 *fb = (Uint8 *)(KERNEL_BASE|0xB8000); - Uint32 *buf = Buffer; - if( Offset + Length > 25*80*8 ) { + 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; - for(; Length > 0; Length -= 8, fb += 2) + LOG("fb = %p", fb); + for(rem = Length; rem --; fb ++, chars++) { - if( *buf < 0x80 ) - *fb = *buf & 0x7F; + if( chars->Ch < 0x80 ) + *fb = chars->Ch & 0x7F; else *fb = 0x00; - buf ++; - fb[1] = 0; - fb[1] |= (*buf & 0x888) == 0x888 ? 0x8 : 0; - fb[1] |= (*buf & 0x700) > 0x300 ? 0x4 : 0; - fb[1] |= (*buf & 0x070) > 0x030 ? 0x2 : 0; - fb[1] |= (*buf & 0x007) > 0x003 ? 0x1 : 0; - fb[1] |= (*buf & 0x888000) == 0x888000 ? 0x80 : 0; - fb[1] |= (*buf & 0x700000) > 0x300000 ? 0x40 : 0; - fb[1] |= (*buf & 0x070000) > 0x030000 ? 0x20 : 0; - fb[1] |= (*buf & 0x007000) > 0x003000 ? 0x10 : 0; - buf ++; + *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 ) { @@ -186,14 +221,106 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) LEAVE('i', 0); return 0; } - if(gVesa_Modes[giVesaCurrentMode].fbSize < Offset+Length) + + // Text Mode + switch( giVesaCurrentFormat ) { - Log_Warning("VESA", "Vesa_Write - Framebuffer Overflow"); - LEAVE('i', 0); - return 0; - } + 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; - memcpy(gVesaFramebuffer + Offset, Buffer, Length); + 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; @@ -205,6 +332,8 @@ 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; @@ -220,17 +349,50 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) case VIDEO_IOCTL_MODEINFO: 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; + } + return ret; + + case VIDEO_IOCTL_SETCURSOR: // Set cursor position + 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(giVesaCursorTimer != -1) { + Time_RemoveTimer(giVesaCursorTimer); + giVesaCursorTimer = -1; + } + giVesaCursorX = -1; + giVesaCursorY = -1; + } + else { + // Log_Debug("VESA", "Updating timer %i?", giVesaCursorTimer); + if(giVesaCursorTimer == -1) + giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Node); + } + //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) -{ - #if DEBUG - LogF("Vesa_Int_SetMode: (mode=%i)\n", mode); - #endif +{ + Log_Log("VESA", "Setting mode to %i", mode); // Sanity Check values if(mode < 0 || mode > giVesaModeCount) return -1; @@ -238,6 +400,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; @@ -251,15 +416,17 @@ int Vesa_Int_SetMode(int mode) VM8086_Int(gpVesa_BiosState, 0x10); // Map Framebuffer - MM_UnmapHWPages((tVAddr)gVesaFramebuffer, giVesaPageCount); + if( (tVAddr)gpVesa_Framebuffer != VESA_DEFAULT_FRAMEBUFFER ) + MM_UnmapHWPages((tVAddr)gpVesa_Framebuffer, giVesaPageCount); giVesaPageCount = (gVesa_Modes[mode].fbSize + 0xFFF) >> 12; - gVesaFramebuffer = (void*)MM_MapHWPages(gVesa_Modes[mode].framebuffer, giVesaPageCount); + gpVesa_Framebuffer = (void*)MM_MapHWPages(gVesa_Modes[mode].framebuffer, giVesaPageCount); - LogF("Vesa", "Framebuffer (Phys) = 0x%x", gVesa_Modes[mode].framebuffer); - LogF("Vesa", "Framebuffer (Virt) = 0x%x", gVesaFramebuffer); + Log_Log("VESA", "Framebuffer (Phys) = 0x%x", gVesa_Modes[mode].framebuffer); + Log_Log("VESA", "Framebuffer (Virt) = 0x%x", gpVesa_Framebuffer); // Record Mode Set giVesaCurrentMode = mode; + gpVesaCurMode = &gVesa_Modes[giVesaCurrentMode]; RELEASE( &glVesa_Lock ); @@ -274,11 +441,6 @@ int Vesa_Int_FindMode(tVideo_IOCtl_Mode *data) ENTER("idata->width idata->height idata->bpp", data->width, data->height, data->bpp); - if(data->flags & VIDEO_FLAG_TEXT) { - LEAVE('i', 0); - return 0; - } - for(i=0;ibpp = 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 > 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; + + giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Arg); +} + +// ------------------------ +// --- 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; + } + } +}