Terminal: Bringing back the console graphics screen-buffers?

Created on 31 Aug 2018  路  7Comments  路  Source: microsoft/terminal

How hard would it be to bring back the console graphics screen-buffers functionality to conhost, which previously existed in Windows <= 2003 and was used by NTVDM to display the output of graphics DOS applications while being run in windowed mode? (see e.g. https://virtuallyfun.com/wordpress/2009/08/08/softpc-%e2%80%93at-version-3/ ) (hint: done using CreateConsoleScreenBuffer with special parameters.)

This feature could also be useful for those other applications (e.g. some Far-Manager plugins) that attempt through convoluted hacks (aka. giving the illusion) to display graphics contents (e.g. thumbnails of image files) in the console window.
Or for these 3rd-party emulators (DOS, etc...) that can start from the command-line, but are currently forced to create a separate window when starting a graphics app.

Area-Output Area-Server Issue-Feature Product-Conhost

Most helpful comment

@HBelusca we all await your pull request with much interest ;)

All 7 comments

I would reckon it'd be nearly impossible - I think all of the NTVDM code was torn out a long time ago, and there's pretty much no demand to add it back.

I was wondering whether this feature couldn't be used also as the underlying thing to emulate (in WSL) the /dev/video0 or /dev/fb0 devices.

(Besides, note that in principle this function doesn't require the existence of NTVDM: a shared memory section between conhost and the app that requests via the CreateConsoleScreenBuffer() the graphics SB, whose characteristics are passed through the last parameter, and the shared mutex to synchronize write/reads (for conhost to render the image), should be sufficient 馃槂 )

@HBelusca we all await your pull request with much interest ;)

LOL my pull request? This would imply I work in the Console team at Microsoft and have access to their code for writing such an implementation... Sadly I don't work at all there! xDD

It's still there, it just has a bug that needs to be fixed.
ConHostV1.dll!CreateConsoleBitmap (second NtMapViewOFSection doesn't have its buffer Ptr initialized to 0). My loader fixes this for instance:

https://github.com/leecher1337/ntvdmx64/blob/master/ntvdmpatch/src/ldntvdm/ldntvdm/ldntvdm.c

Also ensure that you use Console V1 so that it is supported:

https://github.com/leecher1337/ntvdmx64/blob/master/ntvdmpatch/release/reg/conhost.reg

Would be glad if Microsoft finally fixes this bug which is there since Windows 7.
Share conhost sourcecode and you get a pull request :-P

In order to happily work with it, you also need to fix SetconsolePalette calls (also described in source above).

Here is a more detailled information about the bug and how to fix it properly:

NTSTATUS CreateScreenBuffer(...)
{
    ...
    ScreenInfo = HeapAlloc(pConHeap,MAKE_TAG( SCREEN_TAG ),sizeof(SCREEN_INFORMATION));
    if (ScreenInfo == NULL) return STATUS_NO_MEMORY;
    ...
    if ((ScreenInfo->Flags = Flags) & CONSOLE_TEXTMODE_BUFFER) {
    ...
    } else {
        Status = CreateConsoleBitmap(GraphBufInfo, ScreenInfo);
        ...
    }
    ...
}

In

CreateConsoleBitmap(...)
{
   ...
    // There it is OK:
    ScreenInfo->BufferInfo.GraphicsInfo.BitMap = 0;
    Status = NtMapViewOfSection(ScreenInfo->BufferInfo.GraphicsInfo.hSection,
                                NtCurrentProcess(),
                                &ScreenInfo->BufferInfo.GraphicsInfo.BitMap,
                                0L,
                                GraphicsInfo->lpBitMapInfo->bmiHeader.biSizeImage,
                                NULL,
                                &ViewSize,
                                ViewUnmap,
                                0L,
                                PAGE_READWRITE
                               );
...
    ViewSize = GraphicsInfo->lpBitMapInfo->bmiHeader.biSizeImage;
// BUGBUG        OH NOES! YOU FORGOT THIS LINE:
ScreenInfo->BufferInfo.GraphicsInfo.ClientBitMap = 0;
// ^^ To fix, add this line here! ^^
    Status = NtMapViewOfSection(ScreenInfo->BufferInfo.GraphicsInfo.hSection,
                                CONSOLE_CLIENTPROCESSHANDLE(),
                                &ScreenInfo->BufferInfo.GraphicsInfo.ClientBitMap,
                                0L,
                                GraphicsInfo->lpBitMapInfo->bmiHeader.biSizeImage,
                                NULL,
                                &ViewSize,
                                ViewUnmap,
                                0L,
                                PAGE_READWRITE
                               );

}

oising commented on Oct 17, 2018
@HBelusca we all await your pull request with much interest ;)

Ok now I can really actually submit a pull request!!

Was this page helpful?
0 / 5 - 0 ratings