X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FDisplay%2FBochsGA%2Fbochsvbe.c;h=5508e3f4490dc2c17dc759d535a1e7e742d1bd83;hb=e6795eb552a6be88b7870dae14a958ab391bfae8;hp=1ed46ccb4979f314d091872684f25f3380abb278;hpb=54746c855c6e2fe42fde9f93b0ce3f41aeefc2e5;p=tpg%2Facess2.git diff --git a/Modules/Display/BochsGA/bochsvbe.c b/Modules/Display/BochsGA/bochsvbe.c index 1ed46ccb..5508e3f4 100644 --- a/Modules/Display/BochsGA/bochsvbe.c +++ b/Modules/Display/BochsGA/bochsvbe.c @@ -10,23 +10,19 @@ #include #include #include -#include +#include #define INT // === TYPES === -typedef struct { +typedef struct sBGA_Mode { Uint16 width; Uint16 height; Uint16 bpp; - Uint16 flags; Uint32 fbSize; -} t_bga_mode; +} tBGA_Mode; // === CONSTANTS === -enum eMode_Flags { - MODEFLAG_TEXT = 1 -}; #define BGA_LFB_MAXSIZE (1024*768*4) #define VBE_DISPI_BANK_ADDRESS 0xA0000 #define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000 @@ -79,17 +75,14 @@ tDevFS_Driver gBGA_DriverStruct = { } }; int giBGA_CurrentMode = -1; + int giBGA_BufferFormat = 0; tVideo_IOCtl_Pos gBGA_CursorPos = {-1,-1}; - int giBGA_DriverId = -1; Uint *gBGA_Framebuffer; -t_bga_mode gBGA_Modes[] = { - {}, - { 80,25, 12, MODEFLAG_TEXT, 80*25*8}, // 640 x 480 - {100,37, 12, MODEFLAG_TEXT, 100*37*8}, // 800 x 600 - {640,480,8, 0, 640*480}, - {640,480,32, 0, 640*480*4}, - {800,600,8, 0, 800*600}, - {800,600,32, 0, 800*600*4}, +const tBGA_Mode *gpBGA_CurrentMode; +const tBGA_Mode gBGA_Modes[] = { + {640,480,32, 640*480*4}, + {800,600,32, 800*600*4}, + {1024,768,32, 1024*768*4} }; #define BGA_MODE_COUNT (sizeof(gBGA_Modes)/sizeof(gBGA_Modes[0])) @@ -99,25 +92,25 @@ t_bga_mode gBGA_Modes[] = { */ int BGA_Install(char **Arguments) { - int bga_version = 0; + int version = 0; // Check BGA Version - bga_version = BGA_int_ReadRegister(VBE_DISPI_INDEX_ID); + version = BGA_int_ReadRegister(VBE_DISPI_INDEX_ID); + // NOTE: This driver was written for 0xB0C4, but they seem to be backwards compatable - if(bga_version < 0xB0C4 || bga_version > 0xB0C5) { - Warning("[BGA ] Bochs Adapter Version is not 0xB0C4 or 0xB0C5, instead 0x%x", bga_version); + if(version != 0xB0C0 && (version < 0xB0C4 || version > 0xB0C5)) { + Log_Warning("BGA", "Bochs Adapter Version is not 0xB0C4 or 0xB0C5, instead 0x%x", version); return MODULE_ERR_NOTNEEDED; } // Install Device - giBGA_DriverId = DevFS_AddDevice( &gBGA_DriverStruct ); - if(giBGA_DriverId == -1) { - Warning("[BGA ] Unable to register with DevFS, maybe already loaded?"); + if(DevFS_AddDevice( &gBGA_DriverStruct ) == -1) { + Log_Warning("BGA", "Unable to register with DevFS, maybe already loaded?"); return MODULE_ERR_MISC; } // Map Framebuffer to hardware address - gBGA_Framebuffer = (void *) MM_MapHWPage(VBE_DISPI_LFB_PHYSICAL_ADDRESS, 768); // 768 pages (3Mb) + gBGA_Framebuffer = (void *) MM_MapHWPages(VBE_DISPI_LFB_PHYSICAL_ADDRESS, 768); // 768 pages (3Mb) return MODULE_ERR_OK; } @@ -127,8 +120,8 @@ int BGA_Install(char **Arguments) */ void BGA_Uninstall() { - //DevFS_DelDevice( giBGA_DriverId ); - MM_UnmapHWPage( VBE_DISPI_LFB_PHYSICAL_ADDRESS, 768 ); + DevFS_DelDevice( &gBGA_DriverStruct ); + MM_UnmapHWPages( VBE_DISPI_LFB_PHYSICAL_ADDRESS, 768 ); } /** @@ -141,7 +134,7 @@ Uint64 BGA_Read(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer) if(giBGA_CurrentMode == -1) return -1; // Check Offset and Length against Framebuffer Size - if(off+len > gBGA_Modes[giBGA_CurrentMode].fbSize) + if(off+len > gpBGA_CurrentMode->fbSize) return -1; // Copy from Framebuffer @@ -159,64 +152,76 @@ Uint64 BGA_Write(tVFS_Node *node, Uint64 off, Uint64 len, void *Buffer) // Check Mode if(giBGA_CurrentMode == -1) { - LEAVE('i', -1); - return -1; - } - - // Check Input against Frambuffer Size - if(off + len > gBGA_Modes[giBGA_CurrentMode].fbSize) { - LEAVE('i', -1); - return -1; + Log_Notice("BGA", "Setting video mode to #0 (640x480x32)"); + BGA_int_UpdateMode(0); // Mode Zero is 640x480 } // Text Mode - if( gBGA_Modes[giBGA_CurrentMode].flags & MODEFLAG_TEXT ) + switch( giBGA_BufferFormat ) { + case VIDEO_BUFFMT_TEXT: + { tVT_Char *chars = Buffer; - int pitch = gBGA_Modes[giBGA_CurrentMode].width * giVT_CharWidth; - int x, y; + int x, y; // Characters/Rows + int widthInChars = gpBGA_CurrentMode->width/giVT_CharWidth; Uint32 *dest; off /= sizeof(tVT_Char); - dest = (void*)gBGA_Framebuffer; - x = (off % gBGA_Modes[giBGA_CurrentMode].width) * giVT_CharWidth; - y = (off / gBGA_Modes[giBGA_CurrentMode].width) * giVT_CharHeight; - dest += y * pitch; - dest += x * giVT_CharWidth; len /= sizeof(tVT_Char); + + x = (off % widthInChars); + y = (off / widthInChars); + + // Sanity Check + if(y > gpBGA_CurrentMode->height / giVT_CharHeight) { + LEAVE('i', 0); + return 0; + } + + dest = (Uint32 *)gBGA_Framebuffer; + dest += y * gpBGA_CurrentMode->width * giVT_CharHeight; while(len--) { VT_Font_Render( chars->Ch, - dest, pitch, + dest + x*giVT_CharWidth, 32, gpBGA_CurrentMode->width*4, VT_Colour12to24(chars->BGCol), VT_Colour12to24(chars->FGCol) ); - dest += giVT_CharWidth; - chars ++; - x += giVT_CharWidth; - if( x >= pitch ) { + x ++; + if( x >= widthInChars ) { x = 0; - y += giVT_CharHeight; - dest += pitch*(giVT_CharHeight-1); + y ++; // Why am I keeping track of this? + dest += gpBGA_CurrentMode->width*giVT_CharHeight; } } - } - else - { + } + break; + + case VIDEO_BUFFMT_FRAMEBUFFER: + { Uint8 *destBuf = (Uint8*) ((Uint)gBGA_Framebuffer + (Uint)off); - Log("buffer = %p", Buffer); - Log("Updating Framebuffer (%p to %p)", - destBuf, destBuf + (Uint)len); + if( off + len > gpBGA_CurrentMode->fbSize ) { + LEAVE('i', 0); + return 0; + } + + LOG("buffer = %p", Buffer); + LOG("Updating Framebuffer (%p to %p)", destBuf, destBuf + (Uint)len); // Copy to Frambuffer memcpy(destBuf, Buffer, len); - Log("BGA Framebuffer updated"); + LOG("BGA Framebuffer updated"); + } + break; + default: + LEAVE('i', -1); + return -1; } LEAVE('i', len); @@ -224,13 +229,13 @@ Uint64 BGA_Write(tVFS_Node *node, Uint64 off, Uint64 len, void *Buffer) } /** - * \fn INT int BGA_Ioctl(tVFS_Node *node, int ID, void *Data) + * \fn int BGA_Ioctl(tVFS_Node *Node, int ID, void *Data) * \brief Handle messages to the device */ -INT int BGA_Ioctl(tVFS_Node *node, int ID, void *Data) +int BGA_Ioctl(tVFS_Node *Node, int ID, void *Data) { int ret = -2; - ENTER("pNode iId pData", node, ID, Data); + ENTER("pNode iId pData", Node, ID, Data); switch(ID) { @@ -263,9 +268,10 @@ INT int BGA_Ioctl(tVFS_Node *node, int ID, void *Data) ret = BGA_int_ModeInfo((tVideo_IOCtl_Mode*)Data); break; - // Request Access to LFB - case VIDEO_IOCTL_REQLFB: - ret = BGA_int_MapFB( *(void**)Data ); + case VIDEO_IOCTL_SETBUFFORMAT: + ret = giBGA_BufferFormat; + if(Data) + giBGA_BufferFormat = *(int*)Data; break; case VIDEO_IOCTL_SETCURSOR: @@ -273,6 +279,11 @@ INT int BGA_Ioctl(tVFS_Node *node, int ID, void *Data) gBGA_CursorPos.y = ((tVideo_IOCtl_Pos*)Data)->y; break; + // Request Access to LFB +// case VIDEO_IOCTL_REQLFB: +// ret = BGA_int_MapFB( *(void**)Data ); +// break; + default: LEAVE('i', -2); return -2; @@ -293,14 +304,14 @@ void BGA_int_WriteRegister(Uint16 reg, Uint16 value) outw(VBE_DISPI_IOPORT_DATA, value); } -INT Uint16 BGA_int_ReadRegister(Uint16 reg) +Uint16 BGA_int_ReadRegister(Uint16 reg) { outw(VBE_DISPI_IOPORT_INDEX, reg); return inw(VBE_DISPI_IOPORT_DATA); } #if 0 -INT void BGA_int_SetBank(Uint16 bank) +void BGA_int_SetBank(Uint16 bank) { BGA_int_WriteRegister(VBE_DISPI_INDEX_BANK, bank); } @@ -310,15 +321,14 @@ INT void BGA_int_SetBank(Uint16 bank) * \fn void BGA_int_SetMode(Uint16 width, Uint16 height, Uint16 bpp) * \brief Sets the video mode from the dimensions and bpp given */ -void BGA_int_SetMode(Uint16 width, Uint16 height) +void BGA_int_SetMode(Uint16 Width, Uint16 Height) { - ENTER("iwidth iheight ibpp", width, height, bpp); + ENTER("iWidth iheight ibpp", Width, Height, bpp); BGA_int_WriteRegister(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_DISABLED); - BGA_int_WriteRegister(VBE_DISPI_INDEX_XRES, width); - BGA_int_WriteRegister(VBE_DISPI_INDEX_YRES, height); + BGA_int_WriteRegister(VBE_DISPI_INDEX_XRES, Width); + BGA_int_WriteRegister(VBE_DISPI_INDEX_YRES, Height); BGA_int_WriteRegister(VBE_DISPI_INDEX_BPP, 32); BGA_int_WriteRegister(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | VBE_DISPI_NOCLEARMEM | VBE_DISPI_LFB_ENABLED); - //BGA_int_WriteRegister(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | VBE_DISPI_NOCLEARMEM); LEAVE('-'); } @@ -331,17 +341,12 @@ int BGA_int_UpdateMode(int id) // Sanity Check if(id < 0 || id >= BGA_MODE_COUNT) return -1; - // Check if it is a text mode - if( gBGA_Modes[id].flags & MODEFLAG_TEXT ) - BGA_int_SetMode( - gBGA_Modes[id].width*giVT_CharWidth, - gBGA_Modes[id].height*giVT_CharHeight); - else // Graphics? - BGA_int_SetMode( - gBGA_Modes[id].width, - gBGA_Modes[id].height); + BGA_int_SetMode( + gBGA_Modes[id].width, + gBGA_Modes[id].height); giBGA_CurrentMode = id; + gpBGA_CurrentMode = &gBGA_Modes[id]; return id; } @@ -365,10 +370,6 @@ int BGA_int_FindMode(tVideo_IOCtl_Mode *info) LogF("Mode %i (%ix%ix%i), ", i, gBGA_Modes[i].width, gBGA_Modes[i].height, gBGA_Modes[i].bpp); #endif - // Check if this mode is the same type as what we want - if( !(gBGA_Modes[i].flags & MODEFLAG_TEXT) != !(info->flags & VIDEO_FLAG_TEXT) ) - continue; - // Ooh! A perfect match if(gBGA_Modes[i].width == info->width && gBGA_Modes[i].height == info->height @@ -403,10 +404,6 @@ int BGA_int_FindMode(tVideo_IOCtl_Mode *info) info->height = gBGA_Modes[best].height; info->bpp = gBGA_Modes[best].bpp; - info->flags = 0; - if(gBGA_Modes[best].flags & MODEFLAG_TEXT) - info->flags |= VIDEO_FLAG_TEXT; - return best; } @@ -427,10 +424,6 @@ int BGA_int_ModeInfo(tVideo_IOCtl_Mode *info) info->height = gBGA_Modes[info->id].height; info->bpp = gBGA_Modes[info->id].bpp; - info->flags = 0; - if(gBGA_Modes[info->id].flags & MODEFLAG_TEXT) - info->flags |= VIDEO_FLAG_TEXT; - return 1; } @@ -446,10 +439,10 @@ int BGA_int_MapFB(void *Dest) // Sanity Check if((Uint)Dest > 0xC0000000) return 0; - if(gBGA_Modes[giBGA_CurrentMode].bpp < 15) return 0; // Only non-pallete modes are supported + if(gpBGA_CurrentMode->bpp < 15) return 0; // Only non-pallete modes are supported // Count required pages - pages = (gBGA_Modes[giBGA_CurrentMode].fbSize + 0xFFF) >> 12; + pages = (gpBGA_CurrentMode->fbSize + 0xFFF) >> 12; // Check if there is space for( i = 0; i < pages; i++ )