Index: dos/dem.c =================================================================== --- dos/dem.c (révision 62409) +++ dos/dem.c (copie de travail) @@ -20,6 +20,9 @@ #include "dem.h" #include "bop.h" +#include "bios/bios.h" +#include "hardware/vga.h" + /* Extra PSDK/NDK Headers */ #include @@ -117,7 +120,7 @@ STARTUPINFOA StartupInfo; PROCESS_INFORMATION ProcessInformation; - /* Remove return carriage character */ + /* NULL-terminate the command by removing the return carriage character */ while (*CmdPtr != '\r') CmdPtr++; *CmdPtr = '\0'; @@ -135,7 +138,8 @@ StartupInfo.cb = sizeof(StartupInfo); - DosPrintCharacter('\n'); + VgaRefreshDisplay(); + VgaDetachFromConsole(FALSE); Result = CreateProcessA(NULL, CommandLine, @@ -166,9 +170,11 @@ DPRINT1("Failed when launched command '%s'\n"); dwExitCode = GetLastError(); } - - DosPrintCharacter('\n'); + VgaAttachToConsole(); + VidBiosSyncCursorPosition(); + VgaRefreshDisplay(); + setAL((UCHAR)dwExitCode); break; Index: hardware/vga.c =================================================================== --- hardware/vga.c (révision 62409) +++ hardware/vga.c (copie de travail) @@ -189,6 +189,10 @@ static HANDLE EndEvent = NULL; static HANDLE AnotherEvent = NULL; +static CONSOLE_CURSOR_INFO OrgConsoleCursorInfo; +static CONSOLE_SCREEN_BUFFER_INFO OrgConsoleBufferInfo; + + /* * Text mode -- we always keep a valid text mode framebuffer * even if we are in graphics mode. This is needed in order to @@ -404,7 +408,7 @@ static inline DWORD VgaGetAddressSize(VOID); -static BOOL VgaAttachToConsole(PCOORD Resolution) +static BOOL VgaAttachToConsoleInternal(PCOORD Resolution) { BOOL Success; ULONG Length = 0; @@ -414,9 +418,11 @@ DWORD AddressSize, ScanlineSize; DWORD Address = 0; DWORD CurrentAddr; - SMALL_RECT ScreenRect; // ConRect; + SMALL_RECT ConRect; COORD Origin = { 0, 0 }; + WORD Offset; + ASSERT(TextFramebuffer == NULL); // ResetEvent(AnotherEvent); @@ -454,19 +460,36 @@ return FALSE; } - /* Copy console data into VGA memory */ + /* + * Resize the console + */ + ConRect.Left = 0; + ConRect.Top = ConsoleInfo.srWindow.Top; + ConRect.Right = ConRect.Left + Resolution->X - 1; + ConRect.Bottom = ConRect.Top + Resolution->Y - 1; + /* + * Use this trick to effectively resize the console buffer and window, + * because: + * - SetConsoleScreenBufferSize fails if the new console screen buffer size + * is smaller than the current console window size, and: + * - SetConsoleWindowInfo fails if the new console window size is larger + * than the current console screen buffer size. + */ + SetConsoleScreenBufferSize(TextConsoleBuffer, *Resolution); + SetConsoleWindowInfo(TextConsoleBuffer, TRUE, &ConRect); + SetConsoleScreenBufferSize(TextConsoleBuffer, *Resolution); + /* Update the saved console information */ + GetConsoleScreenBufferInfo(TextConsoleBuffer, &ConsoleInfo); + /* + * Copy console data into VGA memory + */ + /* Get the data */ AddressSize = VgaGetAddressSize(); - ScreenRect.Left = ScreenRect.Top = 0; - ScreenRect.Right = TextResolution.X; - ScreenRect.Bottom = TextResolution.Y; - - // ConRect.Left = 0; - // ConRect.Top = ConsoleSize->Y - BufferSize.Y; - // ConRect.Right = ConRect.Left + BufferSize.X - 1; - // ConRect.Bottom = ConRect.Top + BufferSize.Y - 1; - + ConRect.Left = ConRect.Top = 0; + ConRect.Right = TextResolution.X; + ConRect.Bottom = TextResolution.Y; ScanlineSize = (DWORD)VgaCrtcRegisters[VGA_CRTC_OFFSET_REG] * 2; /* Read the data from the console into the framebuffer... */ @@ -474,7 +497,7 @@ CharBuff, TextResolution, Origin, - &ScreenRect); // &ConRect); + &ConRect); /* ... and copy the framebuffer into the VGA memory */ @@ -497,11 +520,32 @@ Address += ScanlineSize; } + /* + * Update the cursor position in the VGA registers. + */ + Offset = ConsoleInfo.dwCursorPosition.Y * Resolution->X + + ConsoleInfo.dwCursorPosition.X; + DPRINT1("X = %d ; Y = %d\n", ConsoleInfo.dwCursorPosition.X, ConsoleInfo.dwCursorPosition.Y); + VgaCrtcRegisters[VGA_CRTC_CURSOR_LOC_LOW_REG] = LOBYTE(Offset); + VgaCrtcRegisters[VGA_CRTC_CURSOR_LOC_HIGH_REG] = HIBYTE(Offset); + CursorMoved = TRUE; + return TRUE; } -static VOID VgaDetachFromConsole(VOID) +BOOL VgaAttachToConsole(VOID) { + if (TextResolution.X == 0 || TextResolution.Y == 0) + DPRINT1("VgaAttachToConsole -- TextResolution uninitialized\n"); + + if (TextResolution.X == 0) TextResolution.X = 80; + if (TextResolution.Y == 0) TextResolution.Y = 25; + + return VgaAttachToConsoleInternal(&TextResolution); +} + +VOID VgaDetachFromConsole(BOOL ChangeMode) +{ ULONG dummyLength; PVOID dummyPtr; COORD dummySize = {0}; @@ -519,6 +563,29 @@ (PCHAR*)&dummyPtr); TextFramebuffer = NULL; + + if (!ChangeMode) + { + SMALL_RECT ConRect; + + /* Restore the old screen buffer */ + SetConsoleActiveScreenBuffer(TextConsoleBuffer); + + /* Restore the original console size */ + ConRect.Left = 0; + ConRect.Top = 0; + ConRect.Right = ConRect.Left + OrgConsoleBufferInfo.srWindow.Right - OrgConsoleBufferInfo.srWindow.Left; + ConRect.Bottom = ConRect.Top + OrgConsoleBufferInfo.srWindow.Bottom - OrgConsoleBufferInfo.srWindow.Top ; + /* + * See the following trick explanation in VgaAttachToConsoleInternal. + */ + SetConsoleScreenBufferSize(TextConsoleBuffer, OrgConsoleBufferInfo.dwSize); + SetConsoleWindowInfo(TextConsoleBuffer, TRUE, &ConRect); + SetConsoleScreenBufferSize(TextConsoleBuffer, OrgConsoleBufferInfo.dwSize); + + /* Restore the original cursor shape */ + SetConsoleCursorInfo(TextConsoleBuffer, &OrgConsoleCursorInfo); + } } static BOOL IsConsoleHandle(HANDLE hHandle) @@ -944,55 +1011,27 @@ static BOOL VgaEnterTextMode(PCOORD Resolution) { - SMALL_RECT ConRect; - DPRINT1("VgaEnterTextMode\n"); /* Switch to the text buffer */ SetConsoleActiveScreenBuffer(TextConsoleBuffer); - /* Resize the console */ - ConRect.Left = 0; - ConRect.Top = ConsoleInfo.srWindow.Top; - ConRect.Right = ConRect.Left + Resolution->X - 1; - ConRect.Bottom = ConRect.Top + Resolution->Y - 1; - /* - * Use this trick to effectively resize the console buffer and window, - * because: - * - SetConsoleScreenBufferSize fails if the new console screen buffer size - * is smaller than the current console window size, and: - * - SetConsoleWindowInfo fails if the new console window size is larger - * than the current console screen buffer size. - */ - SetConsoleScreenBufferSize(TextConsoleBuffer, *Resolution); - SetConsoleWindowInfo(TextConsoleBuffer, TRUE, &ConRect); - SetConsoleScreenBufferSize(TextConsoleBuffer, *Resolution); - /* Update the saved console information */ - GetConsoleScreenBufferInfo(TextConsoleBuffer, &ConsoleInfo); - - /* Adjust the text framebuffer if we changed resolution */ + /* Adjust the text framebuffer if we changed the resolution */ if (TextResolution.X != Resolution->X || TextResolution.Y != Resolution->Y) { - WORD Offset; + VgaDetachFromConsole(TRUE); - VgaDetachFromConsole(); - - /* VgaAttachToConsole sets TextResolution to the new resolution */ - if (!VgaAttachToConsole(Resolution)) + /* + * VgaAttachToConsoleInternal sets TextResolution to the + * new resolution and updates ConsoleInfo. + */ + if (!VgaAttachToConsoleInternal(Resolution)) { DisplayMessage(L"An unexpected error occurred!\n"); EmulatorTerminate(); return FALSE; } - - /* Update the cursor position in the registers */ - Offset = ConsoleInfo.dwCursorPosition.Y * Resolution->X + - ConsoleInfo.dwCursorPosition.X; - DPRINT1("X = %d ; Y = %d\n", ConsoleInfo.dwCursorPosition.X, ConsoleInfo.dwCursorPosition.Y); - VgaCrtcRegisters[VGA_CRTC_CURSOR_LOC_LOW_REG] = LOBYTE(Offset); - VgaCrtcRegisters[VGA_CRTC_CURSOR_LOC_HIGH_REG] = HIBYTE(Offset); - CursorMoved = TRUE; } /* The active framebuffer is now the text framebuffer */ @@ -1825,11 +1864,13 @@ if (!IsConsoleHandle(TextHandle)) return FALSE; TextConsoleBuffer = TextHandle; - /* Save the console information */ - if (!GetConsoleScreenBufferInfo(TextConsoleBuffer, &ConsoleInfo)) + /* Save the original cursor and console screen buffer information */ + if (!GetConsoleCursorInfo(TextConsoleBuffer, &OrgConsoleCursorInfo) || + !GetConsoleScreenBufferInfo(TextConsoleBuffer, &OrgConsoleBufferInfo)) { return FALSE; } + ConsoleInfo = OrgConsoleBufferInfo; /* Initialize the VGA palette and fail if it isn't successfully created */ if (!VgaInitializePalette()) return FALSE; @@ -1873,7 +1914,7 @@ VgaLeaveTextMode(); } - VgaDetachFromConsole(); + VgaDetachFromConsole(FALSE); CloseHandle(AnotherEvent); CloseHandle(EndEvent); Index: hardware/vga.h =================================================================== --- hardware/vga.h (révision 62409) +++ hardware/vga.h (copie de travail) @@ -250,6 +250,9 @@ /* FUNCTIONS ******************************************************************/ +BOOL VgaAttachToConsole(VOID); +VOID VgaDetachFromConsole(BOOL ChangeMode); + DWORD VgaGetVideoBaseAddress(VOID); DWORD VgaGetVideoLimitAddress(VOID); COORD VgaGetDisplayResolution(VOID); Index: ntvdm.c =================================================================== --- ntvdm.c (révision 62409) +++ ntvdm.c (copie de travail) @@ -32,8 +32,6 @@ static HANDLE ConsoleInput = INVALID_HANDLE_VALUE; static HANDLE ConsoleOutput = INVALID_HANDLE_VALUE; static DWORD OrgConsoleInputMode, OrgConsoleOutputMode; -static CONSOLE_CURSOR_INFO OrgConsoleCursorInfo; -static CONSOLE_SCREEN_BUFFER_INFO OrgConsoleBufferInfo; static HMENU hConsoleMenu = NULL; static INT VdmMenuPos = -1; @@ -318,16 +316,6 @@ return FALSE; } - /* Save the original cursor and console screen buffer information */ - if (!GetConsoleCursorInfo(ConsoleOutput, &OrgConsoleCursorInfo) || - !GetConsoleScreenBufferInfo(ConsoleOutput, &OrgConsoleBufferInfo)) - { - CloseHandle(ConsoleOutput); - CloseHandle(ConsoleInput); - wprintf(L"FATAL: Cannot save console cursor/screen-buffer info\n"); - return FALSE; - } - /* Initialize the UI */ ConsoleInitUI(); @@ -336,26 +324,6 @@ VOID ConsoleCleanup(VOID) { - SMALL_RECT ConRect; - - /* Restore the old screen buffer */ - SetConsoleActiveScreenBuffer(ConsoleOutput); - - /* Restore the original console size */ - ConRect.Left = 0; - ConRect.Top = 0; - ConRect.Right = ConRect.Left + OrgConsoleBufferInfo.srWindow.Right - OrgConsoleBufferInfo.srWindow.Left; - ConRect.Bottom = ConRect.Top + OrgConsoleBufferInfo.srWindow.Bottom - OrgConsoleBufferInfo.srWindow.Top ; - /* - * See the following trick explanation in vga.c:VgaEnterTextMode() . - */ - SetConsoleScreenBufferSize(ConsoleOutput, OrgConsoleBufferInfo.dwSize); - SetConsoleWindowInfo(ConsoleOutput, TRUE, &ConRect); - SetConsoleScreenBufferSize(ConsoleOutput, OrgConsoleBufferInfo.dwSize); - - /* Restore the original cursor shape */ - SetConsoleCursorInfo(ConsoleOutput, &OrgConsoleCursorInfo); - /* Restore the original input and output console modes */ SetConsoleMode(ConsoleOutput, OrgConsoleOutputMode); SetConsoleMode(ConsoleInput , OrgConsoleInputMode );