PC compatible text modes

Discussion of development of software for any "obsolete" computer or video game system. See the WSdev wiki and ObscureDev wiki for more information on certain platforms.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

PC compatible text modes

Post by Bregalad »

How does text mode works on PC compatibles? How similar are those still done today on modern computers? How similar was it to, e.g. NES BG graphics?

The only information I found is that the orignal IMB PC had a fixed 80x25 character resolution and was monochrome by default. You could buy expensive extention carts to get colour and/or higher resolution graphics, but the PC was already natively handling colour internally. I think it has 16 colours (4 shades of gray and 12 full hues colours at 2 level of brightness). It seems to use a tile system which allows 256 tiles and a background and foreground color for each of them but the background can only be among the "dark" set of 8 colours. (The extra bit is used for blinking, which is very stupid since that effect could be done in software.)

As such each caracter is definied as a "word", 1 byte for attribute and 1 byte for character. But how does the program mantain compatibility if the terminal is larger than 80x25 ? Do they allow to modify tiles like NES does with CHR-RAM ? But if you don't know what is the size of the characters in the first place, how is it done ?

Is there somewhere a comprehensive list of graphic modes for PCs ? It seems I cannot find any. My understanding is that in bitmap modes, the first PCs could only draw CGA, and thus be less colorful than text mode where all 16 colours could be used anywhere, but I'm not even sure about that. Eventually, 16-colour, 256 colour and 65536 colour and 32k colour graphical mode became common.
User avatar
rainwarrior
Posts: 8735
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PC compatible text modes

Post by rainwarrior »

I believe it's basically a "CHR-RAM" kind of situation, and a lot of the setup of font modes was software driven. I think the "default" font sets were stored in a PC's BIOS and copied into video RAM when you change the mode via some BIOS routine (int 10h or something). There's more options as you progress from CGA to EGA to VGA, but I don't remember any of the details anymore. Everything that you speculated sounds correct to me, though.

Digging through some of my old DOS code, I found stuff that reads the 8x8 font from the BIOS (found at $FFA6E) and uses that as a convenient font set instead of having to generate one in my own program. I can't seem to find anything that attempts to change the font set, though I know I did it at some point.

You can bypass the BIOS routines, though, and mess with the hardware registers directly too. I don't know how common that was with CGA/EGA but it got really popular to do this with VGA (was especially useful for scrolling). So, in some cases it'd be hard to compile a standard list of available resolutions/modes, 'cause a lot of permutations of the settings have been attempted over the years!
User avatar
rainwarrior
Posts: 8735
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PC compatible text modes

Post by rainwarrior »

This article seems to have a lot of useful information:
https://en.wikipedia.org/wiki/VGA-compatible_text_mode
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: PC compatible text modes

Post by tepples »

MDA has CHR ROM. EGA and VGA have CHR RAM. I don't know about CGA.

Some pre-EGA video cards will cause snow on the video if VRAM is written outside blanking.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PC compatible text modes

Post by lidnariq »

Bregalad wrote:The only information I found is that the orignal IBM PC had a fixed 80x25 character resolution and was monochrome by default.
That's the MDA card. It was $300 when new.
You could buy expensive extension cards to get colour and/or higher resolution graphics, but the PC was already natively handling colour internally.
Those are: the CGA, the PGA PGC, and "no it wasn't".

The CGA was not more expensive that the MDA when new, and the CGA and MDA were both launch peripherals. (However, the CGA 5153 monitor was not. Early CGA card users had to use the CGA's awkward composite video output)

PGA PGC was later and thousands of dollars more.
I think it has 16 colours (4 shades of gray and 12 full hues colours at 2 level of brightness).
See RGBI video.
(The extra bit is used for blinking, which is very stupid since that effect could be done in software.)
In practice, no, it couldn't. The original XT was just too slow for that to be practical.

Additionally, there is a toggle that disables that, so that you can get bright backgrounds.
CGA: port 3D8h & 0x20
MDA: port 3B8h & 0x20
EGA/VGA: port 3C0h function 10h & 0x8
How does the program maintain compatibility if the terminal is larger than 80x25 ?
The XT BIOS implemented routines that specifically stored the current width of the screen, and could be told to adjust to whatever the physical resolution was.

See also the software SVGATextMode
Do they allow to modify tiles like NES does with CHR-RAM ?
Only with the EGA and newer.
But if you don't know what is the size of the characters in the first place, how is it done ?
Characters are only ever 8 or 9 dots wide. There is a register that controls this, starting with the Hercules and EGA cards.

Characters can be anywhere from 1 to 64 scanlines tall. There is a register that controls that, too. (port 3C4h function 9)

Please see https://www-user.tu-chemnitz.de/~kzs/to ... ga/vga.txt
Is there somewhere a comprehensive list of graphic modes for PCs ?
Please look up Ralf Brown's interrupt list.

Interrupt 10h, function AH=0
rainwarrior wrote:Digging through some of my old DOS code, I found stuff that reads the 8x8 font from the BIOS (found at $FFA6E)
Interrupt 43h.
rainwarrior wrote: I can't seem to find anything that attempts to change the font set, though I know I did it at some point.
Interrupt 10h, AX=1100h.
I don't know how common [reprogramming the CGA's registers was] was with CGA/EGA but it got really popular to do this with VGA
It was very rare with CGA. As far as non-modern options go, it's basically just California Games (which used timed code to change between the CGA's red-green-yellow video mode and the cyan-magenta-white video mode)

Title screen: http://www.reenigne.org/blog/crtc-emulation-for-mess/
Footbag: http://www.mobygames.com/game/dos/calif ... otId,7722/
tepples wrote:I don't know about CGA.
CGA actually shares the same physical ROM for the character generator with the MDA card. One half holds the MDA font, the other half holds two variants (one rarely seen) for the CGA.
Last edited by lidnariq on Sun Aug 21, 2016 3:23 pm, edited 1 time in total.
Joe
Posts: 650
Joined: Mon Apr 01, 2013 11:17 pm

Re: PC compatible text modes

Post by Joe »

Bregalad wrote:How does text mode works on PC compatibles?
A portion of video RAM is used for character-attribute byte pairs. One byte selects the character from ROM (CGA, MDA) or video RAM (EGA, VGA). The other byte selects foreground and background color (up to 4 bits each), attributes like blinking and underline (where available/enabled), and even has one bit that can do double-duty as a color selection bit and as a 9th character selection bit, for up to 512 unique characters on the screen at a time at the expense of some flexibility in color choice (EGA, VGA).

Each character is displayed either 8 or 9 pixels wide, with the 9th column being either empty or a duplicate of the 8th column depending on character value and the configuration of the card. The screen is either 40 or 80 characters wide. Character height is programmable, but typical height values are 8 pixels, 14 pixels, and 16 pixels tall, and the character height is usually chosen to make the screen 25 characters tall.
Bregalad wrote:How similar are those still done today on modern computers?
Most modern video cards implement a pretty good VGA simulation in hardware (and maybe firmware). From a software perspective, a modern video card running in VGA mode is usually indistinguishable from an IBM VGA.
Bregalad wrote:How similar was it to, e.g. NES BG graphics?
Pretty similar. You have a grid of tiles and their attributes. In some ways it's more flexible (palette is set for each character instead of for groups of 4 characters), in other ways it's less flexible (only 2 colors per character).
Bregalad wrote:But how does the program mantain compatibility if the terminal is larger than 80x25 ?
Programs that used text mode as a terminal would usually interact through DOS or BIOS calls, which would mostly abstract away the difference. Programs that directly manipulate video RAM would have trouble if they made assumptions about the video card's current state. Programs that directly set a high-density text mode like that would be aware that the terminal is larger than normal and have no trouble.
Bregalad wrote:Do they allow to modify tiles like NES does with CHR-RAM ?
For CGA and MDA, no. For EGA and VGA, yes.
Bregalad wrote:But if you don't know what is the size of the characters in the first place, how is it done ?
Software that modifies the tiles in video RAM will usually also reprogram the video card to a known state, including tile size.
Bregalad wrote:Is there somewhere a comprehensive list of graphic modes for PCs ?
No. There is a list of BIOS video modes for PCs in RBIL, where modes 00h through 07h and 0Dh through 13h are the ones that could be most easily set, but games are likely to manually program the video card registers to set their own custom mode, and this doesn't even begin to cover SVGA and beyond.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: PC compatible text modes

Post by Bregalad »

Wow, what a mess. Those 3 letters accronyms are confusing. No wonder why backwards compatibility with old PC or DOS programs is so terrible.
Software that modifies the tiles in video RAM will usually also reprogram the video card to a known state, including tile size.
Oh, and what if the exact size we expect isn't available with a given video cart ?
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PC compatible text modes

Post by lidnariq »

The VGA was sufficiently constrained that there wasn't really such a concept.

At that point everyone had the same lowest common denominator:
31.5 kHz hsync
choice of 60 or 70 Hz vsync
choice of one of two pixel clocks: 28.3 MHz and 25.2 MHz
optional toggle to halve pixel clock
an optional toggle to doublescan
guaranteed minimum horizontal underscan of 80%; guaranteed minimum vertical underscan of 90%

In practice, this meant that the "tweak" modes were always 320, 360, 640, or 720 pixels wide, and 200, 240, 350, 400, or 480 scanlines tall. Hence the weird resolution of the Windows 95 animated startup and shutdown screens. (The 350 scanline-high mode was actually controlled by the monitor: the card would say "please stretch this extra vertically", even though the exact timing is identical to the 400-scanline mode)

There was a piece of software at the time called Tweak which let you explore this, as well as load the settings of your video card and "black box" away the pixel clock selection.

Reprogramming the video mode registers was relatively rare until the VGA card, so "tweaked" video modes for the CGA were basically limited to changing the character cell height — see http://8088mph.blogspot.com/2015/04/cga ... rated.html . Trixter has make a "authentic CGA calibration" program that implies that the amount of underscanning of a "real" CGA monitor should be enough to draw a just-barely-overscanned 720x240 pixels.

Starting with the EGA, people usually used the planar graphics mode instead of the tiled text mode; the only instance I remember of explicitly using the EGA text mode in clever ways is Megazeux ... and the only VGA game instance I can remember is Excelsior.



A lot of early VGA compatible cards used the explicitly reserved settings at register 3C2h & 0x0C to add two more clock selections, most often 36 MHz and 40 MHz, explicitly for the 800x600@56Hz graphics mode and something compatible with the VT100's 132x25 text mode.

Later video cards either added a large variety of physical clocks—I remember one card that could choose between 32 different frequencies. Even later we finally got good enough at making stable enough PLLs to allow almost-arbitrary pixel clocks.
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: PC compatible text modes

Post by Banshaku »

Reading all those messages make me feel nostalgic of the dos days :) I remember making text routine that would write at 0xB000 since it was faster than using the bios ones .

@Bregalad

If you want and old book about pc programming in french, Micro Application had "la bible du pc"'which I remember using a long time ago.
Joe
Posts: 650
Joined: Mon Apr 01, 2013 11:17 pm

Re: PC compatible text modes

Post by Joe »

Bregalad wrote:No wonder why backwards compatibility with old PC or DOS programs is so terrible.
Most compatibility issues for old PC software have nothing at all to do with the video card. VGA has good backwards compatibility with CGA, MDA, and EGA, and 99% of PC video cards are VGA-compatible.
Bregalad wrote:Oh, and what if the exact size we expect isn't available with a given video cart ?
That wasn't really an issue. Most software didn't try to use any features beyond the base set available with VGA (or CGA/MDA/EGA, if the software was developed with that in mind) so any VGA-compatible video card would work. If you could set a video mode on one VGA-compatible card, you could be certain it would work on other VGA-compatible cards.
User avatar
rainwarrior
Posts: 8735
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PC compatible text modes

Post by rainwarrior »

Bregalad wrote:Wow, what a mess. Those 3 letters accronyms are confusing. No wonder why backwards compatibility with old PC or DOS programs is so terrible.
Well, there was a straightforward progression from CGA to EGA to VGA (despite the "A" standing for a different word in VGA). Each backward compatible with the previous.

Each had a 320x200 low resolution mode commonly used in games. CGA with 2-bit colour (very limited palette), EGA 4-bit, and VGA 8-bit.

CGA text mode had 40x25 or 80x25 characters (8x8), either had the 16 colour scheme you're already familiar with. EGA added another 80x25 mode with 8x14 characters instead, which I think is the most commonly used one. EGA was also when the font set became customizable, apparently (though this remained somewhat rare to do, I think).

There's also an 80x43 text mode (8x8) in EGA. This came up less often, but was useful for things like map editors. I think this was an aesthetic influence for Dwarf Fortress.


That's the most common stuff, I think. There's other modes and obscure details every level of this puzzle, and a bunch of other variations on graphics cards (MDA, Hercules, MCGA, etc.) but these were the most popular targets. Games mostly used the 320x200 modes for a long time. I don't think using the text modes with custom font for tiled graphics was ever very common, mostly it was just used "as intended" for text.
zzo38
Posts: 1096
Joined: Mon Feb 07, 2011 12:46 pm

Re: PC compatible text modes

Post by zzo38 »

I have schematics for PC CGA. In text mode you can have 80x25 tiles or 40x25 tiles, each tile with two colours selected from sixteen; if the mode register specifies flashing text enabled then you can have only eight background colours because one bit is instead used for making the text to flash. Patterns are taken from ROM, and a jumper can be used to select between two sets of patterns. The patterns for MDPA are stored in the same ROM as CGA (apparently this is so that they do not need to make two separate ROMs). Timing and some other stuff (tile height, tiles per scanline, cursor position, etc) done by the 6845 CRTC chip, which outputs the address and then the other logic in the circuit is used to read two bytes from video memory, using the address from CRTC is doubled and then the low bit of the actual address is clear for the character byte and is set for the colour byte (the low 4-bits for foreground, high 4-bits for background).
(Free Hero Mesh - FOSS puzzle game engine)
User avatar
Myask
Posts: 965
Joined: Sat Jul 12, 2014 3:04 pm

Re: PC compatible text modes

Post by Myask »

rainwarrior wrote:text modes with custom font for tiled graphics was ever very common, mostly it was just used "as intended" for text.
Do you mean like MZX and ZZT, or like the "Macrocom Method"?
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PC compatible text modes

Post by lidnariq »

I think you lost a negation?

Anyway, there were lots of games that used text mode for games that weren't just textual. Kroz, ZZT, all of the roguelikes ...

I just can't think of anything contemporary other than Macrocom's and Round42 that used the shortened characters for graphics (but do note the modern Magiduck).

... much like I can only think of Megazeux and Excelsior for games that reprogrammed the font ... oh, wait, I did encounter these ones recently.
User avatar
rainwarrior
Posts: 8735
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PC compatible text modes

Post by rainwarrior »

Myask wrote:
rainwarrior wrote:I don't think using the text modes with custom font for tiled graphics was ever very common, mostly it was just used "as intended" for text.
Do you mean like MZX and ZZT, or like the "Macrocom Method"?
Nope, I'd never used Megazeux, or heard of Macrocom. Maybe tile replacement was more common than I thought? It really didn't come up much for me, though. Enough that I knew it existed, but not enough that I could remember any examples of it.

There were lots of games that used the default font tiles to make graphics for games, I didn't mean to sound like I was excluding those with the words "as intended". (The NIBBLES.BAS game which came with MS-DOS, BBS door games like Legend of the Red Dragon often had "ASCII art", lidnariq mentioned roguelikes and there's a lot of those.)

What I meant was that I could think of very few games that replaced tiles to make custom graphics, the way you would normally do on the NES (where there isn't a default set, and games are the primary focus of the platform). Most of them stuck with the default font set, some standard text mode, and the 16 colours (2 per tile) available since CGA.

It seems like the MSX had a text mode that did often get used that way for games (e.g. MSX R-Type), and I've wondered if the ZX colour artifacts are also due to it being based on a similar text mode hardware implementation, but I don't know too much about either of those systems, so I could be mistaken. I thought this was what Bregalad was getting at, though, the similarity between the NES tile capabilities and text modes of computers that were contemporary to it.


I think part of why is just that once you get to EGA, it only really helps you to use text mode if your game is very rigidly made of a grid of tiles (like Megazeux seems to be), or is mostly text anyway. Like, it's really convenient and you can probably update large parts of your screen efficiently, as opposed to software rendering tiles in a bitmapped screen mode. It's a huge disadvantage, of course, as soon as you want things moving smoothly between the tiles, since you don't have a "sprite" layer or anything like that to mix with it. By the time you got to VGA, software rendering wasn't really such a problem anymore anyway, so if you were going text, maybe you were into the ASCII aesthetic already?


The Macrocrom method is a bit curious. Yet another CGA abuse trick, I guess. There seems to be a lot of interesting obscure tricks to do with CGA.
Post Reply