VgaAcRegisters[VgaAcIndex] = Data;
}
-static VOID VgaEnterGraphicsMode(UINT Width, UINT Height, UINT BitDepth)
+static BOOL VgaEnterGraphicsMode(PCOORD Resolution, UINT BitDepth)
{
DWORD i;
CONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo;
/* Fill the bitmap info header */
ZeroMemory(&BitmapInfo->bmiHeader, sizeof(BITMAPINFOHEADER));
BitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- BitmapInfo->bmiHeader.biWidth = Width;
- BitmapInfo->bmiHeader.biHeight = Height;
+ BitmapInfo->bmiHeader.biWidth = Resolution->X;
+ BitmapInfo->bmiHeader.biHeight = Resolution->Y;
BitmapInfo->bmiHeader.biBitCount = 8;
- BitmapInfo->bmiHeader.biPlanes = 1;
+ BitmapInfo->bmiHeader.biPlanes = 1;
BitmapInfo->bmiHeader.biCompression = BI_RGB;
- BitmapInfo->bmiHeader.biSizeImage = Width * Height * (BitDepth / 8);
+ BitmapInfo->bmiHeader.biSizeImage = Resolution->X * Resolution->Y
+ * (BitDepth / 8);
/* Fill the palette data */
for (i = 0; i < BitDepth; i++) PaletteIndex[i] = (WORD)i;
NULL,
CONSOLE_GRAPHICS_BUFFER,
&GraphicsBufferInfo);
+ if (GraphicsConsoleBuffer == INVALID_HANDLE_VALUE) return FALSE;
/* Save the framebuffer address and mutex */
ConsoleFramebuffer = GraphicsBufferInfo.lpBitMap;
/* Set the active buffer */
SetConsoleActiveScreenBuffer(GraphicsConsoleBuffer);
+
+ return TRUE;
}
-static VOID VgaLeaveGraphicsMode()
-{
+static VOID VgaLeaveGraphicsMode(VOID)
+{
/* Switch back to the text buffer */
SetConsoleActiveScreenBuffer(TextConsoleBuffer);
GraphicsConsoleBuffer = NULL;
}
+static BOOL VgaEnterTextMode(PCOORD Resolution)
+{
+ /* Resize the console */
+ SetConsoleScreenBufferSize(TextConsoleBuffer, *Resolution);
+
+ /* Allocate a framebuffer */
+ ConsoleFramebuffer = HeapAlloc(GetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ Resolution->X * Resolution->Y
+ * sizeof(CHAR_INFO));
+ if (ConsoleFramebuffer == NULL)
+ {
+ DisplayMessage(L"An unexpected error occurred!\n");
+ VdmRunning = FALSE;
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static VOID VgaLeaveTextMode(VOID)
+{
+ /* Free the old framebuffer */
+ HeapFree(GetProcessHeap(), 0, ConsoleFramebuffer);
+ ConsoleFramebuffer = NULL;
+}
+
static VOID VgaUpdateMode(VOID)
{
COORD Resolution = VgaGetDisplayResolution();
}
else
{
- /* Free the old framebuffer */
- HeapFree(GetProcessHeap(), 0, ConsoleFramebuffer);
- ConsoleFramebuffer = NULL;
+ /* Leave the current text mode */
+ VgaLeaveTextMode();
}
/* Check if the new mode is alphanumeric */
if (!(VgaGcRegisters[VGA_GC_MISC_REG] & VGA_GC_MISC_NOALPHA))
{
- /* Resize the console */
- SetConsoleScreenBufferSize(TextConsoleBuffer, Resolution);
-
- /* Allocate a framebuffer */
- ConsoleFramebuffer = HeapAlloc(GetProcessHeap(),
- HEAP_ZERO_MEMORY,
- sizeof(CHAR_INFO)
- * Resolution.X
- * Resolution.Y);
- if (ConsoleFramebuffer == NULL)
- {
- DisplayMessage(L"An unexpected error occurred!\n");
- VdmRunning = FALSE;
- return;
- }
+ /* Enter new text mode */
+ if (!VgaEnterTextMode(&Resolution)) return;
/* Set the text mode flag */
TextMode = TRUE;
else
{
/* Enter 8-bit graphics mode */
- VgaEnterGraphicsMode(Resolution.X, Resolution.Y, 8);
+ if (!VgaEnterGraphicsMode(&Resolution, 8)) return;
/* Clear the text mode flag */
TextMode = FALSE;
/* Perform a full update */
NeedsUpdate = TRUE;
- UpdateRectangle.Left = 0;
- UpdateRectangle.Top = 0;
- UpdateRectangle.Right = Resolution.X;
+ UpdateRectangle.Left = 0;
+ UpdateRectangle.Top = 0;
+ UpdateRectangle.Right = Resolution.X;
UpdateRectangle.Bottom = Resolution.Y;
}
VOID VgaReadMemory(DWORD Address, LPBYTE Buffer, DWORD Size)
{
DWORD i;
+ DWORD VideoAddress;
DPRINT("VgaReadMemory: Address 0x%08X, Size %lu\n",
Address,
/* Loop through each byte */
for (i = 0; i < Size; i++)
{
- DWORD VideoAddress = VgaTranslateReadAddress(Address + i);
+ VideoAddress = VgaTranslateReadAddress(Address + i);
/* Copy the value to the buffer */
Buffer[i] = VgaMemory[VideoAddress];
VOID VgaWriteMemory(DWORD Address, LPBYTE Buffer, DWORD Size)
{
DWORD i, j;
+ DWORD VideoAddress;
DPRINT("VgaWriteMemory: Address 0x%08X, Size %lu\n",
Address,
/* Loop through each byte */
for (i = 0; i < Size; i++)
{
- DWORD VideoAddress = VgaTranslateWriteAddress(Address + i);
+ VideoAddress = VgaTranslateWriteAddress(Address + i);
for (j = 0; j < VGA_NUM_BANKS; j++)
{
SMALL_RECT ScreenRect;
PCHAR_INFO CharBuffer;
DWORD Address = 0;
+ DWORD CurrentAddr;
/* Set the global handle */
TextConsoleBuffer = TextHandle;
ModeChanged = FALSE;
/* Get the data */
- Resolution = VgaGetDisplayResolution();
- CharBuffer = (PCHAR_INFO)ConsoleFramebuffer;
+ Resolution = VgaGetDisplayResolution();
+ CharBuffer = (PCHAR_INFO)ConsoleFramebuffer;
AddressSize = VgaGetAddressSize();
- ScreenRect.Left = ScreenRect.Top = 0;
- ScreenRect.Right = Resolution.X;
+ ScreenRect.Left = ScreenRect.Top = 0;
+ ScreenRect.Right = Resolution.X;
ScreenRect.Bottom = Resolution.Y;
ScanlineSize = (DWORD)VgaCrtcRegisters[VGA_CRTC_OFFSET_REG] * 2;
/* Read the data from the console into the framebuffer */
ReadConsoleOutputA(TextConsoleBuffer,
- ConsoleFramebuffer,
+ CharBuffer,
Resolution,
Origin,
&ScreenRect);
-
/* Loop through the scanlines */
for (i = 0; i < Resolution.Y; i++)
{
/* Loop through the characters */
for (j = 0; j < Resolution.X; j++)
{
- DWORD CurrentAddr = LOWORD((Address + j) * AddressSize);
+ CurrentAddr = LOWORD((Address + j) * AddressSize);
/* Store the character in plane 0 */
VgaMemory[CurrentAddr] = CharBuffer[i * Resolution.X + j].Char.AsciiChar;
}
/* EOF */
-