9

The PC BIOS uses the INT 0x10, AH=0x00 function to change the video mode.

There's a big list of video modes available, but how can I be sure that the video mode I want to set is supported?

For example, the first 7 modes (0-6) seem to be supported for CGA cards (and successors such as EGA and VGA), while mode 7 is for MDA/Hercules. If I set mode 3 (80x25 text, 16-color) on a PC that only has MDA (a monochrome card), what will happen? I imagine simply changing the video mode using the BIOS won't damage hardware, but is there any way to tell if the call worked or not?

4 Answers 4

14

Indeed, in many sources, the int10h subfunction AH=0 to set video mode returns without any meaningful status.

One way, suggested by C&T BIOS programming guide, is to verify if the mode is set via Read Current Video State function, int10h with AH=0x0F.

It will return the current active mode among other things.

In more detail, the MDA and CGA cards have no BIOS of their own, so IBM 5150 motherbord BIOS has built-in support for them. And in fact you have to set with motherboard DIP switches which adapter you have (MDA or CGA, and if CGA, which default mode you want, 40x25 or 80x25).

The point is, if your switches is set to MDA, it gets stored into Equipment Flag bits, and when setting a new mode with Int 10h, the Equipment Flags are checked for display type.

If the Flags indicate your swiches are set to MDA, then, no matter what mode number you request, the mode 7 parameters will be set to the MDA card. So you can't set any other mode.

The IBM manuals say if you have both MDA and CGA, you still have to set the switches to MDA, so you can't select other modes through BIOS.

If you don't have an MDA, but only CGA card, BIOS initializes either mode 1 or 3 based on if the switches are set to 40x25 or 80x25. If you have MDA or both based on switches, video init code tries to select mode 0, but the mode set function always forces the mode to 7 in case of MDA present.

This leads to an interesting use case, if you have CGA and no MDA, what happens if you select mode 7? I think the BIOS tries to write the MDA mode register settings to the CGA card, as I see nothing preventing it.

Which means, a game cannot know through BIOS if it can set mode 7, so maybe best to check what is the current mode before trying to set any mode, and it seems having dual MDA/CGA card combo means the BIOS must either be tricked to CGA only mode via the Equpment Flags, or the game must detect and control the CGA card directly without the BIOS.

Having a later card such as EGA or VGA made this easier as you can just set a mode and it works, or detect the presence of EGA or VGA directly.

7
  • I'll note that the reason you had to select MDA if you had both was that the IBM Monochrome Monitor would fail (dramatically) if it was powered with no input video signal, and if the MDA mode switch was not set, the MDA card would not be initialized and would generate no video signals.
    – tsc_chazz
    Sep 18, 2023 at 16:54
  • @tsc_chazz The MDA monitor getting damaged without signal I don't believe. If there is something wrong in the system and it does not go to display init code, there are safety mechanisms that keep the HSYNC disabled after hardware reset until port 3D8h is written with bit to enable HSYNC drive. It would mean that the display would burn up and damage if you forgot to plug in the video cable, or forgot to turn on the computer before the display. Sure, I believe it will get damaged with incorrect HSYNC period, width or polarity, as HSYNC literally drives the flyback transformer almost directly.
    – Justme
    Sep 18, 2023 at 17:39
  • I speak from experience. The specific problem is not HSYNC but VSYNC; without a VSYNC signal the vertical yoke isolation capacitor overvolts and explodes. The original IBM MDA was shipped with a male-to-female IEEE power connector (later correction: a male IEEE connector on a short pigtail) that plugged into a switched socket on the back of the PC so that the monitor would only have power when the PC was live. I believe this design flaw may have been corrected in later displays but it was definitely there in the original.
    – tsc_chazz
    Sep 18, 2023 at 18:14
  • 1
    @tsc_chazz That's a new one, is there any reference to that? It is certainly possible; however the TDA1170 vertical deflection chip free-runs at slightly less than the 50 Hz VSYNC rate from the card, so a missing VSYNC should not do anything. It may be that it only breaks if the video is missing and the circuit is faulty that it fails to free-run.
    – Justme
    Sep 18, 2023 at 19:22
  • nothing I can point at right now, I can only speak of the systems I had to service and the repairs I did. And I was a bit of a hotshot in those days, had no service manuals... but it's easy to find a burst electrolytic even without manuals. And it was either two or three systems that had that failure happen to a monitor that was powered when the PC was off. Maybe there were different models of monochrome monitor, one which free-ran Vsync and one which didn't? That may have been the "later correction."
    – tsc_chazz
    Sep 18, 2023 at 19:33
13

That's not how you designed your programs in the early days of the PC:

You rather decided for one (maybe two) video cards (typically CGA and/or Hercules Monochrome) and then looked up your documentation what modes these cards support - Then you decided for one mode that was available on the largest common subset of cards/monitors and developed your program for exactly this mode and wrote this onto your box for the game. Programs supporting more than one mode/card are actually pretty rare (that's why most of the early PC games support only CGA 320x200 on RGB monitors, and next to no programs exist supporting the same mode on composite), and if you did (Sierra did this with a number of their games when Tandy/PCjr video modes came up), you compiled a special version for this mode and put it on an extra disk in your box. In principle, you left it to the user to make sure the selected graphics mode fit the hardware by having them insert the disk with the proper version and only did marginal checks (for presence of the required video card, for example) if the user's decision was correct.

This only changed significantly when (Super)VGA cards became common that supported a multitude of resolutions/color depths, but there you had subfunction 1Bh to detect supported modes, and later VESA BIOS with even more support to check your hardware. But even most VGA games decided on one single mode and support for multiple resolutions was rather the exception than the rule.

8

BIOS has the ReturnFunctionalityStateInformation function 1Bh that can be used to retrieve a 20-bit bitmap of the supported video modes. You supply a far pointer to a 64-byte buffer that BIOS will fill with the Functionality State Information. The first item therein is a far pointer to the Static Functionality Information table that itself begins with 3 bytes that contain the 20-bit bitmap you can then inspect:

mov di, Buffer          ; ES:DI points at your 64-byte buffer
xor bx, bx              ; Implementation type = 0
mov ah, 1Bh             ; BIOS.ReturnFunctionalityStateInformation
int 10h                 ; -> AL
cmp al, 1Bh
jne NOK                 ; Call was invalid
; ES:DI now points at the 64-byte Functionality State Information table
lds si, [es:di]         ; Get pointer to the Static Information Table
; DS:SI now points at a 20-bit vector that indicates whether a certain video mode is supported

eg. To test if mode 12h (16-color 640x480) is supported:

test byte [si+2], 00000100b
jz   NOK            ; Not supported
mov  ax, 0012h      ; BIOS.SetVideoMode
int  10h
mov  ah, 0Fh        ; BIOS.GetVideoMode
int  10h            ; -> AL mode, AH columns, BH page
cmp  ax, 5012h
jne  NOK            ; Unexpected failure

From Richard F. Ferraro's PROGRAMMER'S GUIDE TO THE EGA AND VGA CARDS

The availability of the video modes is contained in three contiguous bytes of the static function table. The three bytes contain 20 bits. Each bit is associated with a display mode. A bit position within one of these three bytes that is set to a 1 indicates that the respective mode is supported on this video system.

4
  • 1
    Assuming such new video system like VGA, EGA, or MCGA, this work.
    – Justme
    Sep 17, 2023 at 18:44
  • Are you taking about Int 10h Function 1Bh? This is only available on PS2 VGA and later.
    – Raffzahn
    Sep 17, 2023 at 19:28
  • Who called it ReturnFunctionalityStateInformation? Sep 19, 2023 at 10:14
  • 2
    it is actually called "Return Functionality / State Information" ("This function returns functionality and state information in a provided memory buffer for the current adapter and mode") as per the Intel VGA BIOS OEM Reference Guide
    – dlatikay
    Sep 20, 2023 at 16:43
4

There's a big list of video modes available, but how can I be sure that the video mode I want to set is supported?

There is no easy way - unless you can determinate what kind of Card it is. For new hardware (past 1991) this can be done (in part) by using the VESA functions, starting with 4F00h to query environment information. Without that classic card probing may be used - like testing function 12h for EGA/VGA.

I imagine simply changing the video mode using the BIOS won't damage hardware

It should not. Original IBM BIOS does default all unknown modes to a value specific for that card. This can be seen, as Justme describes, by looking up the video mode selected via INT 10h Function 0Fh

but is there any way to tell if the call worked or not?

Using function 0Fh will do so with original BIOS and many compatible - although it's not guaranteed.

You must log in to answer this question.

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