puppydrum64
puppydrum64

Reputation: 1688

How does the default mouse cursor in MS-DOS work without erasing whatever is underneath it?

My understanding of VGA graphics may be flawed, but it seems to have only one layer of graphics, yet the mouse cursor in MS-DOS (or at least DOSBox) appears to be independent of the graphics beneath, much like a "sprite layer" on most video game consoles of the time. Yet DOSBox's VGA mode appears to be a one-layer bitmap screen. Is the mouse on a separate layer that only it can occupy? Furthermore, is there a way for VGA to output hardware sprites?

Upvotes: 4

Views: 536

Answers (2)

Marco Sacchi
Marco Sacchi

Reputation: 982

What mouse drivers generally do (at least from what I've seen in the 90s, on real hardware) is:

  • for text modes:
    • swap the background color with the text color of the cell where the cursor is positioned;
    • reserve four glyphs out of the 256 available, forming a 2x2 cell box, to draw a pointer the size of a text cell via software, mixing the cursor graphics with the four characters behind it. The four glyphs are then set by calculating the position of the cells where the pointer should appear, without changing the character attributes;
  • for graphic modes:
    • save the portion of the screen behind the cursor, draw the cursor, restore the saved buffer, save the new portion, draw the cursor in the new position, and so on
    • draw the cursor by XORing the pixel values, XORring again to restore the background, draw the cursor by XORing the pixels in the new position, and so on

In text modes a cell in video memory is defined by 2 bytes: one contains the character, the other the attributes for that character (https://en.wikipedia.org/wiki/VGA_text_mode#Text_buffer).

XORing in graphic modes, with indexed colors, is possible because the palettes are arranged to obtain a high contrast, at least for the first 16 colors, inherited from EGA. When, instead, the mode allows to directly specify the intensity of the RGB channels, XORing is sufficient for the cursor to have excellent contrast.

Mouse pointer management also depends on the type of application. Typically for video games, which often use a linear framebuffer, everything is managed by software, while the mouse driver only provides the pointer coordinates. Sometimes only the delta of movement received from the driver was used because at high resolutions there was no other way to obtain precise positioning and smooth movement.

As for DOSBox, it emulates a CGA/EGA/[S]VGA card (so it never accesses the hardware's native registers), and its behavior does not change whether it is in window or full screen. When it receives focus, the native cursor of the system it runs on disappears, and only the emulated one remains visible.

Upvotes: 0

Some name
Some name

Reputation: 62

As far as I know VGA has no hardware support for a mouse cursor or sprites. With the introduction of XGA sprites became available. But VGA only supports a text cursor but no graphical cursor.

So my guess is that the mouse driver reads the 16x16 pixels (or whatever the size of the mouse pointer is) and then stores it somewhere. Then it can draw the mouse pointer into the frame buffer. When the pointer is moved a bit to the left (for example) then the driver can restore the original 16x16 pixels in the frame buffer. Then it reads 16x16 pixels from the new location and then draws the pointer again.

As long as DOS Box is in windowed mode (means not in full screen) it doesn't access the VGA registers anyway but draws on a canvas provided by the operating system. So DOS Box can use hardware sprites even if VGA doesn't support it. Because in this situation VGA is not used at all.

Upvotes: 0

Related Questions