From 2e19f113bc68fd38f59d469b213d251ee50e314d Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 21 Apr 2010 22:19:09 +0800 Subject: [PATCH] Fixes to Vesa video driver and VTerm's mode setting - Known Bugs: Vesa seems to not like scrolling, it may be related to the update speed, but I doubt it, probably due to some limit in the size of the update (when doing a whole screen update) --- Kernel/Makefile.BuildNum | 2 +- Kernel/drv/vterm.c | 19 ++++++---- Modules/Display/VESA/main.c | 74 +++++++++++++++++++++---------------- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 1feb3bdc..6782fc24 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1960 +BUILD_NUM = 1974 diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index d0f450b6..1e244972 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -19,9 +19,9 @@ #define MAX_INPUT_CHARS32 64 #define MAX_INPUT_CHARS8 (MAX_INPUT_CHARS32*4) #define VT_SCROLLBACK 2 // 2 Screens of text -#define DEFAULT_OUTPUT "VGA" +//#define DEFAULT_OUTPUT "VGA" //#define DEFAULT_OUTPUT "BochsGA" -//#define DEFAULT_OUTPUT "Vesa" +#define DEFAULT_OUTPUT "Vesa" #define DEFAULT_INPUT "PS2Keyboard" #define DEFAULT_WIDTH 80 #define DEFAULT_HEIGHT 25 @@ -63,6 +63,8 @@ extern void Debug_SetKTerminal(char *File); // === PROTOTYPES === int VT_Install(char **Arguments); +void VT_InitOutput(void); +void VT_InitInput(void); char *VT_ReadDir(tVFS_Node *Node, int Pos); tVFS_Node *VT_FindDir(tVFS_Node *Node, char *Name); int VT_Root_IOCtl(tVFS_Node *Node, int Id, void *Data); @@ -190,6 +192,9 @@ int VT_Install(char **Arguments) // Add to DevFS DevFS_AddDevice( &gVT_DrvInfo ); + VT_InitOutput(); + VT_InitInput(); + // Set kernel output to VT0 Debug_SetKTerminal("/Devices/VTerm/0"); @@ -204,6 +209,9 @@ int VT_Install(char **Arguments) void VT_InitOutput() { giVT_OutputDevHandle = VFS_Open(gsVT_OutputDevice, VFS_OPENFLAG_WRITE); + if(giVT_InputDevHandle == -1) { + Log_Warning("VTerm", "Oh F**k, I can't open the video device '%s'", gsVT_OutputDevice); + } VT_SetTerminal( 0 ); VT_SetResolution(1, 640, 480); } @@ -463,12 +471,7 @@ void VT_SetResolution(int IsTextMode, int Width, int Height) giVT_RealHeight = mode.height; VFS_IOCtl( giVT_OutputDevHandle, VIDEO_IOCTL_GETSETMODE, &tmp ); - - - if(IsTextMode) - tmp = VIDEO_BUFFMT_TEXT; - else - tmp = VIDEO_BUFFMT_FRAMEBUFFER; + tmp = IsTextMode ? VIDEO_BUFFMT_TEXT : VIDEO_BUFFMT_FRAMEBUFFER; VFS_IOCtl( giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp ); } diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index 1d803fb5..f24b405d 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,7 @@ // === CONSTANTS === #define FLAG_LFB 0x1 +#define VESA_DEFAULT_FRAMEBUFFER (KERNEL_BASE|0xA0000) // === PROTOTYPES === int Vesa_Install(char **Arguments); @@ -40,7 +41,7 @@ tVM8086 *gpVesa_BiosState; int giVesaCurrentMode = 0; int giVesaCurrentFormat = VIDEO_BUFFMT_TEXT; int giVesaDriverId = -1; -char *gVesaFramebuffer = (void*)0xC00A0000; +char *gpVesa_Framebuffer = (void*)VESA_DEFAULT_FRAMEBUFFER; tVesa_Mode *gVesa_Modes; int giVesaModeCount = 0; int giVesaPageCount = 0; @@ -67,11 +68,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)\n", 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 @@ -115,7 +116,7 @@ int Vesa_Install(char **Arguments) 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 } @@ -157,21 +158,24 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) 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*sizeof(tVT_Char) ) { + if( Offset + Length > 25*80 ) { Log_Warning("VESA", "Vesa_Write - Framebuffer Overflow"); LEAVE('i', 0); return 0; } - fb += 2*(Offset/sizeof(tVT_Char)); + fb += 2*Offset; LOG("fb = %p", fb); - for(rem = Length / sizeof(tVT_Char); rem --; fb ++, chars++) + for(rem = Length; rem --; fb ++, chars++) { if( chars->Ch < 0x80 ) *fb = chars->Ch & 0x7F; @@ -189,7 +193,6 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) //LOG("%08x (%03x,%03x) = %04x", // chars->Ch, chars->BGCol, chars->FGCol, *fb); } - Length /= sizeof(tVT_Char); Length *= sizeof(tVT_Char); LEAVE('X', Length); return Length; @@ -207,27 +210,33 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) case VIDEO_BUFFMT_TEXT: { tVT_Char *chars = Buffer; - int pitch = gVesa_Modes[giVesaCurrentMode].width * giVT_CharWidth; + int pitch = gVesa_Modes[giVesaCurrentMode].width; + int widthInChars; int x, y; - Uint32 *dest; - int rem; + Uint32 *dest = (void*)gpVesa_Framebuffer; + int i; + Length /= sizeof(tVT_Char); Offset /= sizeof(tVT_Char); - dest = (void*)gVesaFramebuffer; + LOG("gVesa_Modes[%i].width = %i", giVesaCurrentMode, gVesa_Modes[giVesaCurrentMode].width); - x = (Offset % (gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth)) * giVT_CharWidth; - y = (Offset / (gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth)) * giVT_CharHeight; - LOG("(x,y) = (%i,%i)", x, y); + 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); // Sanity Check - if(y > gVesa_Modes[giVesaCurrentMode].height) { + if(y > gVesa_Modes[giVesaCurrentMode].height/giVT_CharHeight) { LEAVE('i', 0); return 0; } - dest += y * pitch; + dest += y * giVT_CharHeight * pitch; dest += x * giVT_CharWidth; - for( rem = Length / sizeof(tVT_Char); rem--; ) + + LOG("dest = %p", dest); + + for( i = 0; i < Length; i++ ) { VT_Font_Render( chars->Ch, @@ -239,21 +248,20 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) dest += giVT_CharWidth; chars ++; - x += giVT_CharWidth; + x ++; if( x >= pitch ) { x = 0; - y += giVT_CharHeight; + y ++ ; dest += pitch*(giVT_CharHeight-1); } } - Length /= sizeof(tVT_Char); Length *= sizeof(tVT_Char); } break; case VIDEO_BUFFMT_FRAMEBUFFER: { - Uint8 *destBuf = (Uint8*) ((Uint)gVesaFramebuffer + (Uint)Offset); + Uint8 *destBuf = (Uint8*) ((Uint)gpVesa_Framebuffer + (Uint)Offset); if(gVesa_Modes[giVesaCurrentMode].fbSize < Offset+Length) { @@ -305,7 +313,10 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) case VIDEO_IOCTL_SETBUFFORMAT: ret = giVesaCurrentFormat; - if(Data) giVesaCurrentFormat = *(int*)Data; + if(Data) { + Log_Log("VESA", "Buffer mode to %i", *(int*)Data); + giVesaCurrentFormat = *(int*)Data; + } return ret; case VIDEO_IOCTL_REQLFB: // Request Linear Framebuffer @@ -315,10 +326,8 @@ int Vesa_Ioctl(tVFS_Node *Node, int ID, void *Data) } int Vesa_Int_SetMode(int mode) -{ - #if DEBUG - Log("Vesa_Int_SetMode: (mode=%i)", mode); - #endif +{ + Log_Log("VESA", "Setting mode to %i", mode); // Sanity Check values if(mode < 0 || mode > giVesaModeCount) return -1; @@ -339,12 +348,13 @@ 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); - Log("Vesa", "Framebuffer (Phys) = 0x%x", gVesa_Modes[mode].framebuffer); - Log("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; -- 2.20.1