12

Due to my limited knowledge of retrocomputing and old CRT displays and graphics cards, I could be making some wrong assumptions in this question. For any wrong assumption you find in this question, I would request you to point it out to me so that I can improve my knowledge as I try to get an answer to this question.

I see from online articles that VGA had a screen resolution of 640x480. And I understand from recent video questions on this forum that we can switch to VGA mode 3 with instructions:

MOV AH, 0
MOV AL, 3
INT 0x10

But here is what I cannot understand. In video mode 3, there are 80x25 characters and each character uses 9x16 pixels. But 9x80 = 720 and 16x25 = 400. So 80x25 characters would need 720x400 resolution.

How does VGA manage to show 720x400 resolution text on a 640x480 display? Does it scale the pixel width down and scale the pixel height up? Like fit 720 pixels wide text somehow in the available 640 pixels wide display?

Scaling down 720 to 640 is a scale down ratio of 9:8, so every 9 pixels wide text needs to fit on 8 pixels of width on the disply? Wouldn't that lead to dropping 1 pixel in 9 pixels?

2
  • 1
    This is also why the stock UEFI font is 8×19; it’s just large enough to fit a 80×25 character grid in a 640×480 framebuffer while keeping padding to a minimum. Commented Jan 25, 2023 at 15:11
  • How they fit on a CRT (display) was poorly, because it's in VGA mode which is a given resolution. "From the monitor's side, there is no difference in input signal in a text mode and an All Points Addressable (APA) mode of the same size." en.wikipedia.org/wiki/VGA_text_mode
    – Mazura
    Commented Jan 28, 2023 at 3:18

5 Answers 5

21

How does VGA manage to show 720x400 resolution text on a 640x480 display?

This might be your basic misunderstanding here. Displays as used back then and what VGA was designed for, are not a fixed 640x480 device, but analogue CRT (Cathode-Ray Tube) monitors. Fixed size displays only became a common thing for desktop PC way later with the advent of fast, high resolution LCD screens (*1).

Number of pixel per line is thus only limited by output speed of the computer - and beam manipulation speed by the CRT. Likewise the number of lines. Due to the way of the receiver of a CRT is build, it will adapt. This is called synchronisation (syncing). A 15% higher pixel rate is quite within reason for next to all CRT.

So in a way, yes, the pixels were a bit smaller. Except this was not reached by dropping parts of them or calculation some intermediate values like it is today, but by literally making them smaller in width. Which the CRT would show faithfully (*2).

Later, when Super VGA came, Multisync CRT appeared. They were able to sync to quite wide rates from 320x240 to 1600x1200 resolutions, some even beyond that.


*1 - Well, Laptops and other special purpose devices had them first, but they were not driving the standards back then.

*2 - There are limits due the size of the colour mask, but again they will not become an influence at variations that small.

14
  • 1
    @Schezuk you wouldn’t use a 5153 for VGA... CGA was fixed 640×200 for text and high-res graphics. Commented Jan 25, 2023 at 12:50
  • 3
    @Schezuk A 5153 is a CGA screen, it can not sync to a 400 line picture - that's a bit out of it's spec (of visible 200 lines). But that's not due the CRT itself, which might be capable, but timing related electronics couldn't sync to the signal presented. Also, 5153 input is TTL level, not analogue like delivered by VGA, so the picture will at best be still colour distorted.
    – Raffzahn
    Commented Jan 25, 2023 at 12:57
  • 4
    @Schezuk the 8503 is a monochrome monitor so it doesn’t have discrete dots or a mask; the 8512 has a .41mm pitch on a 240mm display, so at most 585 distinct pixels, and the 8513 has a .28mm pitch on a 212mm display, so at most 757 distinct pixels. Thus the 8503 will always have a very clear picture, the 8512 will always be slightly blurry, the 8513 should produce a crisp image if adjusted properly. Commented Jan 25, 2023 at 14:27
  • 3
    @Schezuk: The beam is usually focused sufficiently loosely that parts of it will be spread out over adjacent rows of holes.
    – supercat
    Commented Jan 25, 2023 at 15:46
  • 3
    @Schezuk Y...No. The signal framing controls the beams vertical position. the horizontal is strictly due the time it takes to go left to right. It does not contain any pixel information that can be detected by the beam control. It's a continuous analogue signal. How many holes there are in a line depends on the screen resolution. How many pixel there are on the computers signal. If there are too many, it will be blurry. is there are less, it will be crisp clear. And yes, the beam will always as well hit the mask, so part of the signal is always hidden. That's why colour CRT are darker than B&W
    – Raffzahn
    Commented Jan 25, 2023 at 15:56
21

CRTs don’t have a fixed pixel resolution; early CRTs have fixed timings (25.175 MHz and 28.322 MHz for VGA). VGA 80×25 text mode really does produce 400 lines of 720 pixels, as you determined, with a slightly-higher refresh rate than 640×480 mode (70Hz v. 60Hz). See OSDev’s page on video signals and timing for a good explanation of display timing in an analog world.

For LCDs and other displays with fixed pixel resolutions, usually on laptops, the VGA BIOS was adapted to take the limitations into account. On laptops, this normally meant that 9-pixel modes were ignored, and only 400 lines were displayed, with blank space at the top and bottom of the screen; so 80×25 text mode used 640×400 pixels on-screen. (VGA text modes can have their ninth column enabled or disabled; enabling the ninth column adds a blank column of pixels, except for a few graphics characters where it can duplicate the eighth column.)

I wrote a tool to better use laptop screens like this, 80x30; it sets up an 80×30 text mode using 640×480 pixels. This also works fine on CRTs.

8

They don't fit to 640 pixels as VGA text mode is not 640x480.

640x480 is simply the one of the modes, but not the only mode available. It just happens to be the highest and most commonly known format.

And the CRT display is analog, so it does not have discrete pixels anyway, it just shows whatever continuous analog signal comes from the video card. It does have discrete lines of video.

So the monitor shows all 720 pixels, plus borders.

VGA text mode has 9-bit character cells so text mode is 720x400 at 70 Hz, not 640x480 at 60 Hz.

Basically, a VGA monitor originally supported three modes. It can be set to scan at speed of 350, 400, or 480 visible lines per field of video.

In all modes, a fixed horizontal line rate of about 31.5 kHz is used.

The VGA adapter has two selectable pixel clocks; 25.175 MHz or 28.322 MHz.

The 25 MHz clock allows to fit 640 visible pixels on a scan line, and the 28 MHz clock allows to fit 720 visible pixels on a scan line.

These clocks are also used to provide 320 and 360 pixel wide modes (by halving the dot clock to double the dot width).

So the CRT does not know how many pixels there are per line, all it can do is scan the beams around based on the sync signals and drive the beam intensity as per the incoming analog video signal.

4

First of all, it’s worth remembering that an analogue video signal, which is what a VGA card generates, has no inherent horizontal resolution. The signal source generates a specific number of horizontal scanlines one below the other (which determines vertical resolution) at a specific refresh rate, which the monitor must be able to adapt to, but the level of detail on the horizontal axis is simply whatever the source manages to produce. A CRT monitor will not care. (LCDs on the other hand might, as they actually do try to recover the original framebuffer pixels to match them against their own pixel grid. But more on that later.) This is why some people would sometimes speak of ‘200-line’ or ‘400-line’ modes, and why the conventional notation for screen modes (e.g. ‘576i’ or ‘720p’) only mentions the vertical resolution (though for digital video it no longer really makes sense). It can be occasionally good to know when performing obscure video mode tricks.

Furthermore, though it’s conventionally called ‘the VGA resolution’, 640×480 is not the only resolution at which VGA is able to operate. In text mode, it generates a 400p analogue video signal at 70 Hz refresh rate. A VGA-compatible monitor has to be able to show 480 scanlines in graphics mode, so it surely should be able to display a mere 400 of them when in text mode. At least that was the case at the time.

Of course the VGA card in text mode does, in fact, generate the signal from the glyph bitmaps of the character mode font, which actually has an inherent horizontal resolution. The most common text mode renders an 80×25 grid of character cells at 9×16 pixels each, giving text mode an effective resolution of 720×400 pixels. And you are of course right to notice that 640 pixels are not enough to store a whole single scanline of that mode.

However, character cells are merely often 9 pixels wide, and the glyph bitmaps are never. The glyph bitmaps are actually 8×16, drawn inside character cells that could be either 9×16 or 8×16. The ninth column of pixels in a character cell, if present, is not encoded in the glyph bitmap, but is generated by the graphics adapter: either entirely blank or, if the character index is in the box-drawing character range [0xC0, 0xE0), by repeating the eighth column. The EGA and VGA have a specific register responsible for switching between width-9 and width-8 character cells: sequencer register 1, bit 0. Toggling it will switch the effective horizontal resolution in text mode between 720 and 640 pixels. And when the VGA card is in 640×480 graphical mode, the character cells (now a software-only concept implemented by the video interrupt services) are 8 pixels wide.

As a side note, video card firmware often tweaks the font slightly when width-9 character cells are in use, to take advantage of wider character spacing. Here’s a sample of fonts from the ‘VGA Text Mode Fonts’ collection:

Comparison of width-8 and width-9 text-mode fonts from video ROMs by IBM, InteGraphics, Intel, 3DLabs and Trident

Stephen Kitt’s answer also points out (which I am not going to restate in entirety) that on early laptops with 640×480 LCD screens, width-9 character cells were not supported at all. And from my superficial testing, it seems they are no longer supported on relatively modern laptops either (I tried it on a couple of laptops with Intel graphics, one from 2004, the other from 2010; no width-9 font variant was installed, and toggling the register bit had no effect).0 So these days, if text mode is used at all, the horizontal resolution will probably be 640 pixels after all.


0 Interestingly, the text mode font used by DOSBox contains glyphs optimised for width-9 cells, but DOSBox does not actually implement width-9 cells either. Ironically enough, QEMU, which doesn’t actually care all that much for accuracy of reproduction, does emulate width-9 character cells (though SeaVGABIOS seems not to include a separate width-8 font variant either).

2
  • 1
    Toggling the bit 0 of sequencer register to switch between 8/9 pixels wide characters may not work on the fly. The sequencer should be held in reset while changing the bit. In any case, if it did work, you would have to do other things as well, because the total line length is still set to 100 character clocks, so if you don't change pixel clock back to 25 MHz, the horizontal rate will be too high. Of course it is possible the registers are protected somehow so the laptop is able to show an image even if bits are changed weirdly.
    – Justme
    Commented Jan 27, 2023 at 20:53
  • @Justme Not that I have the hardware to test, but do you happen to know of a good code sample of how to manipulate that register correctly? Commented Jan 27, 2023 at 22:44
0

Well, for standard text mode (8x8), it uses maybe 640x400 or 640x200. For the other, yes, it does use 720x400. It all depends on the pixel clock. As long as you use 25.175 Mhz, you can only have 640 pixels across. You can only vary the horizontal resolution of a fixed mode. So if you want less, you can output everything multiple times or reduce the pixel clock. And if you want more, you can increase the pixel clock. As for vertical, you can lower that resolution by doubling (or tripling, or quadding) the lines.

The Gigatron TTL computer uses a 6.25 Mhz CPU and pixel clock. So that means the pixels are 4 times as wide. To keep the aspect ratio, it sends all 120 lines 4 times each. So it has the same horizontal and vertical frequencies as 640x480 mode, but only has 160x120 pixels.

3
  • The standard VGA text mode is 720x400, with 9x16 char cells. Not 8x8 char cells in 640x200 block. And in that case the video signal would still be double-scanned to 400 lines, as VGA has no 200-line format.
    – Justme
    Commented Jan 27, 2023 at 15:21
  • "To keep the aspect ratio, it sends all 160 lines 4 times each" -- I've never used a Gigatron, but IIRC in order to minimize components the display is generated directly (perhaps through a single 8-bit shift register?) by code running on the CPU via bit (or byte) banging, so presumably it could just as easily be used to generate a 160x480 display.
    – occipita
    Commented Jan 28, 2023 at 19:07
  • It stores 19,200 bytes in a raw bitmap format. It bit bangs the video & syncs using native instructions in ROM. It's a Harvard RISC architecture; all native instructions take 1 cycle. It sends the video data out of the Out port. It uses specialized instructions to do a logical mask on the memory as it reads it, sends it to the port, and increments the low memory index. The X register is a counter that increments independently of the ALU, allowing one to simultaneously mask off the upper 2 bits with a mask to use them as syncs. It can optionally skip 1-3 native lines for speed. Commented Feb 8, 2023 at 8:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .