X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FDisplay%2FVESA%2Fmain.c;h=55083b043a808ed16f07775536beb6f6ffc12143;hb=8de6b4e1a2050289458d6489551eb61b6c1d3645;hp=02689ea2cdadb816d933c5ae0893711f25b920fd;hpb=cc8b3e3a6e84370a5b1e1109c17a08dcbc82d3b9;p=tpg%2Facess2.git diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index 02689ea2..55083b04 100644 --- a/Modules/Display/VESA/main.c +++ b/Modules/Display/VESA/main.c @@ -29,10 +29,9 @@ 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_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); @@ -52,6 +51,7 @@ tVM8086 *gpVesa_BiosState; 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 @@ -59,12 +59,8 @@ 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 === @@ -72,15 +68,12 @@ 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 @@ -114,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->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( info ); // Install Device giVesaDriverId = DevFS_AddDevice( &gVesa_DriverStruct ); @@ -152,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) @@ -197,42 +210,23 @@ int Vesa_IOCtl(tVFS_Node *Node, int ID, void *Data) return Vesa_Int_ModeInfo((tVideo_IOCtl_Mode*)Data); case VIDEO_IOCTL_SETBUFFORMAT: + 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) - 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_SETCURSORBITMAP: + DrvUtil_Video_SetCursor( &gVesa_BufInfo, Data ); return 0; } return 0; @@ -246,15 +240,11 @@ int Vesa_Int_SetMode(int mode) // Sanity Check values if(mode < 0 || mode > giVesaModeCount) return -1; - Log_Log("VESA", "Setting mode to %i (%ix%i %ibpp)", - mode, - gVesa_Modes[mode].width, gVesa_Modes[mode].height, - gVesa_Modes[mode].bpp - ); - // Check for fast return if(mode == giVesaCurrentMode) return 1; + Vesa_int_FillModeList(); + Time_RemoveTimer(giVesaCursorTimer); giVesaCursorTimer = -1; @@ -263,7 +253,6 @@ int Vesa_Int_SetMode(int mode) 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 } @@ -276,8 +265,12 @@ 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, (Virt) = 0x%x, Size = 0x%x", - gVesa_Modes[mode].framebuffer, gpVesa_Framebuffer, giVesaPageCount << 12); + 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; @@ -301,6 +294,8 @@ 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;iid < 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; - int bytes_per_px = (gpVesaCurMode->bpp + 7) / 8; - int x = giVesaCursorX*giVT_CharWidth; - int y = giVesaCursorY*giVT_CharHeight; - int i; - Uint8 *fb = (void*)gpVesa_Framebuffer; - - //Debug("Cursor flip"); - - // Sanity check - if(giVesaCursorX < 0 || giVesaCursorY < 0 - || y*pitch + x + (giVT_CharHeight-1)*pitch > (int)gpVesaCurMode->fbSize) { - Log_Notice("VESA", "Cursor OOB (%i,%i)", x, y); - giVesaCursorTimer = -1; - return; - } - - // Draw cursor - fb += (y+1)*pitch + x*bytes_per_px; - - switch(bytes_per_px) - { - case 1: - for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) - *fb = ~*fb; - break; - case 2: - for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) { - fb[0] = ~fb[0]; - fb[1] = ~fb[1]; - } - break; - case 3: - for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) { - fb[0] = ~fb[0]; - fb[1] = ~fb[1]; - fb[2] = ~fb[2]; - } - break; - case 4: - for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) { - fb[0] = ~fb[0]; - fb[1] = ~fb[1]; - fb[2] = ~fb[2]; - fb[3] = ~fb[3]; - } - break; - default: - Log_Error("VESA", "Vesa_FlipCursor - Bug Report, unknown bytes_per_px (%i)", bytes_per_px); + DrvUtil_Video_RemoveCursor( &gVesa_BufInfo ); + #if BLINKING_CURSOR + if(giVesaCursorTimer != -1) { + Time_RemoveTimer(giVesaCursorTimer); giVesaCursorTimer = -1; - return ; } - - #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) { - // TODO: Handle non-32bit modes - 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 = gpVesaCurMode->pitch; - int bytes_per_px = (gpVesaCurMode->bpp + 7) / 8; - 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 > gpVesaCurMode->width) - W = gpVesaCurMode->width - SrcX; - if(DstX + W > gpVesaCurMode->width) - W = gpVesaCurMode->width - DstX; - if(SrcY + H > gpVesaCurMode->height) - H = gpVesaCurMode->height - SrcY; - if(DstY + H > gpVesaCurMode->height) - H = gpVesaCurMode->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*bytes_per_px; - for( tmp = W; tmp --; ) { - *(Uint8*)(gpVesa_Framebuffer + dst + tmp) = *(Uint8*)(gpVesa_Framebuffer + src + tmp); - } - } - } - else { - // Normal copy is OK - while( H -- ) { - memcpy((void*)gpVesa_Framebuffer + dst, (void*)gpVesa_Framebuffer + src, W*bytes_per_px); - dst += scrnpitch; - src += scrnpitch; - } - } - //Log("Vesa_2D_Blit: RETURN"); + 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 } +