Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 256 color text mode hack #4764

Closed
2 tasks done
dxgldotorg opened this issue Jan 19, 2024 · 17 comments
Closed
2 tasks done

Support 256 color text mode hack #4764

dxgldotorg opened this issue Jan 19, 2024 · 17 comments

Comments

@dxgldotorg
Copy link

Is your feature request related to a problem? Please describe.

No response

What you want

As it currently stands, the hack used to make text mode run in 256 color mode doesn't seem to work; tried vgaonly mode to emulate IBM VGA.
Example: MegaZeux 2.69c the last 16-bit DOS version of the game creation system MegaZeux.
image
Screenshot shows a game that uses the game engine's "SMZX" mode which is not working as instead of vertical bars the graphics should be smooth colors.

Describe alternatives you've considered

No response

Additional information

MZX 2.69c is at https://www.digitalmzx.com/show.php?id=166 in case you need to test. The game used is SMZX Tetris at https://www.digitalmzx.com/show.php?id=1586 which you can confirm the correct colors playing it in the web player.

Have you checked that no similar feature request(s) exist?

  • I have searched and didn't find any similar feature request.

Code of Conduct & Contributing Guidelines

  • I agree to follow the code of conduct and the contributing guidelines.
@AliceLR
Copy link

AliceLR commented Jan 19, 2024

To more accurately explain what is supposed to be going on in VGA terms: for '90s Nvidia, ATi, and possibly some Cirrus Logic and C&T graphics adapters, enabling the mode 13h pixel doubling bit of the VGA mode control register while in 640x350 text mode would result in a 256-color 320x350 text mode with 4 colors per character. The 4 colors are indexed using the background and foreground colors as the high and low nibbles of the palette index.

For reference, here is how modern MZX enables this hack: https://github.com/AliceLR/megazeux/blob/88a20a39ac50e70eabd4925a6a1433ae0be0e127/arch/djgpp/render_ega.c#L98

static void ega_set_smzx(boolean is_ati)
{
  // Super MegaZeux mode:
  // In a nutshell, this sets bit 6 of the VGA Mode Control Register.
  // Bit 6 controls the pixel width - if 1, the pixel width is doubled,
  // creating one 8-bit pixel instead of two 4-bit pixels. HOWEVER,
  // normally, this is only done in Mode 13h.
  //
  // nVidia and some Cirrus Logic cards support this; ATI cards
  // also "support" it, but swap the order of joining the pixels
  // and require a weird horizontal pixel shift value - see below.
  outportb(0x3C0, 0x10);
  outportb(0x3C0, 0x4C);

  if(is_ati)
  {
    // set horizontal pixel shift to Undefined (0.5 pixels, in theory)
    outportb(0x3C0, 0x13);
    outportb(0x3C0, 0x01);
  }
}

I don't have any test programs for this ready since I wasn't prepared to request this yet, but in the old DOS versions of MegaZeux you could load the file PAL_ED.MZX, press "P" to open the palette editor, and press "X" to display the entire 256 color palette. It should show something that looks like this:

image

Instead, what DOSBox and DOSBox-X display is this:

image

@dxgldotorg
Copy link
Author

dxgldotorg commented Jan 19, 2024

I just tested on an old GeForce 6200 AGP card, and that card does SMZX mode correctly. Tested on 2.93 DJGPP build.

@joncampbell123
Copy link
Owner

Ew... very clever! Someone figured out how 256-color mode works and hacked text mode to fit within it! 👍

VGA 256-color mode is really just 4 bits shifted into an 8-bit register per dot clock, but that would make a strange unhelpful 640x200 256-color mode, so there is a bit to latch every other pixel so that you only see the completed 8-bit value and not the intermediate ones. This is also why it is impossible to do a 640x200 256-color tweakmode on standard VGA hardware.

@joncampbell123
Copy link
Owner

I have an old Pentium laptop with a Cirrus chipset (and 4KB bank switching to prove to naive DOS games jam developers that not all VESA BIOSes bank switch on multiples of 64KB even if the window itself is 64KB 😆), maybe this trick works there too.

@joncampbell123
Copy link
Owner

I can confirm:

A 486 laptop with a Paradise/Western Digital SVGA chipset doesn't work this way. You can set the bit and halve the resolution of text mode, but it doesn't allow this hack to work.

A Pentium laptop (Toshiba Satellite Pro) with a Chips & Tech chipset does appear to work in a way that allows this hack to work. Setting that bit halves the resolution and makes the text multicolored that suggest 256-color 4-bit shifting behavior.

@AliceLR
Copy link

AliceLR commented Jan 30, 2024

Do you have specifics on these laptop models/graphics? I've been trying to keep a list of every known model that's been tested so far so we have more data.

A 486 laptop with a Paradise/Western Digital SVGA chipset doesn't work this way. You can set the bit and halve the resolution of text mode, but it doesn't allow this hack to work.

This sounds a lot like what happens with my ThinkPad 560X's NeoMagic chipset. The left pixel always gets doubled and tweaking the horizontal pixel shift register doesn't help.

Is the Satellite Pro a 400 CDS or comparable, by any chance? I had an unknown model Satellite Pro circa 2004 most likely with a C&T chipset that supported this hack. I remember it having used the same pixel ordering as the Nvidia cards (the left pixel of each pair contributes the low nibble of the color, IIRC).

The ATi cards that support this—in addition to needing that horizontal shift setting—apparently also have the nibbles in the opposite order.

@joncampbell123
Copy link
Owner

joncampbell123 commented Jan 31, 2024

Do you have specifics on these laptop models/graphics? I've been trying to keep a list of every known model that's been tested so far so we have more data.

A 486 laptop with a Paradise/Western Digital SVGA chipset doesn't work this way. You can set the bit and halve the resolution of text mode, but it doesn't allow this hack to work.

This sounds a lot like what happens with my ThinkPad 560X's NeoMagic chipset. The left pixel always gets doubled and tweaking the horizontal pixel shift register doesn't help.

Is the Satellite Pro a 400 CDS or comparable, by any chance? I had an unknown model Satellite Pro circa 2004 most likely with a C&T chipset that supported this hack. I remember it having used the same pixel ordering as the Nvidia cards (the left pixel of each pair contributes the low nibble of the color, IIRC).

The ATi cards that support this—in addition to needing that horizontal shift setting—apparently also have the nibbles in the opposite order.

The Pentium laptop in question is a Toshiba Satellite Pro 465CDX (1997 era DOS/Windows 95 era laptop). It was a great laptop for it's time for both DOS gaming and Windows 95 OSR2 gaming. It came out right when Intel Pentium CPUs with MMX were appearing in laptops which was fun to play with from assembly language. Most Toshiba laptops of the time period including the Libretto use C&T chipsets.

The 486 laptop is a Compaq LTE Elite 450CX with a Paradise/Western Digital SVGA chipset. Seems to be about 1994-era. When I put a CF card in it I had to pick one 512MB or smaller for the BIOS to work with it.

@joncampbell123
Copy link
Owner

joncampbell123 commented Jan 31, 2024

If your Toshiba laptop was made 2000-ish or later it may have an Intel chipset instead of Chips & Tech because Intel acquired C&T around that time. https://en.wikipedia.org/wiki/Chips_and_Technologies

I have a Toshiba laptop I bought sometime around 2004 with an Intel graphics chipset (the 855GM) which runs perfectly fine with Linux and Windows XP.

@joncampbell123
Copy link
Owner

One thing that DOSBox-X has already implemented regarding this bit was the discovery some time ago that if you set up 320x200 256-color mode on VGA, and then switch OFF this bit, you get a strange 640x200 256-color mode because you get to see the intermediate "pixels" that result when the 8-bit value is halfway shifted out to shift the next pixel in. I suppose if you arrange the color palette just right you might exploit this odd tweakmode for high res 256-color graphics on standard VGA, but obviously not for gaming. While it seems to work on most chipsets I noticed Tseng ET4000 cards react in that case by just making it a 640x200 256-color mode with the 320x200 screen squeezed on the left side and the right side is just edge pixels repeated, but then again ET4000 cards have their own weird edge cases with standard VGA compatibility.

joncampbell123 added a commit that referenced this issue Feb 19, 2024
…ion is required to enable it since S3 chipsets are not listed as supporting the tweakmode
@joncampbell123
Copy link
Owner

How's this?

mzxrun_000

@AliceLR
Copy link

AliceLR commented Feb 19, 2024

How's this?

Looks great!

@joncampbell123
Copy link
Owner

Awesome. It's done.

@AliceLR
Copy link

AliceLR commented Feb 20, 2024

Not sure if hardware testing follow-up belongs in this issue, but so far I've received feedback from a MegaZeux user with a Compaq 4704 motherboard (onboard S3 Trio64V) that suggests this chip performs the same left pixel doubling as the NeoMagic MagicGraph128XD.

@joncampbell123
Copy link
Owner

Not sure if hardware testing follow-up belongs in this issue, but so far I've received feedback from a MegaZeux user with a Compaq 4704 motherboard (onboard S3 Trio64V) that suggests this chip performs the same left pixel doubling as the NeoMagic MagicGraph128XD.

So it does the same thing my 486 laptop with the Paradise/WD chipset does, and it only doubles pixels, instead of combining them into 8 bit pixels?

@AliceLR
Copy link

AliceLR commented Feb 20, 2024

So it does the same thing my 486 laptop with the Paradise/WD chipset does, and it only doubles pixels, instead of combining them into 8 bit pixels?

Yes, I think so. Here's a sample from PAL_ED.MZX that demonstrates the doubled pixels and 4-bit indexing:
image

edit: for good measure, here's the NeoMagic MagicGraph128XD showing the same behavior:
NeoMagic_MagicGraph128XD_PAL_ED

@joncampbell123
Copy link
Owner

Yeah, that's pixel doubling. If it's just doubled pixels and there's no colors between the colors, that's what it's doing.

@dxgldotorg
Copy link
Author

How's this?

Looks great!

Exactly like my ultra-janky MZX port I made back in the day (though I used automatic interpolation outside of the MZX runtime for SMZX Mode 1 until Mode 2 came out).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants