I was wondering how I could display more than 256 colors with the VGA color palette. correct me if I'm wrong, but the reason that you can't display more than 256 colors at once is because each byte in video memory corresponds to one pixel on the screen. But because each byte can only hold a number up to 255 (not including 0) you can't reference a color past 256 (the maximum number combinations). Assuming that this is correct, is there a way to extend the video memory so that each pixel uses 2 bytes (video memory size * 2) or one word of memory each? :icon_question:

Dani AI

Generated

Short answer: you cannot make a plain VGA 8‑bit mode show more than 256 simultaneous colors by “widening” video memory — that mode stores one byte per pixel which is an index into a 256‑entry palette, so the color depth is fixed by the mode. As pointed out, the practical path is to switch the card out of legacy VGA into a true‑color SVGA/VBE mode or to use software tricks (dithering, temporal palette swaps) to simulate more colors. (fr.wikipedia.org)

If you want to do this from DOS/real mode (the low‑level route you asked about), use the VESA BIOS Extensions (VBE). Basic workflow: call INT 10h AX=0x4F00 to get the controller info (it contains the mode list), call INT 10h AX=0x4F01 for each mode to inspect the ModeInfoBlock (look for BitsPerPixel and the linear‑framebuffer attribute), then call INT 10h AX=0x4F02 with BX = mode_number (OR the mode number with 0x4000 to request the linear framebuffer) to set a true‑color mode. That will give you 15/16/24/32 bpp modes when the card supports them. (wiki.osdev.org)

Example (outline, real code needs real buffers and checks):

; Get controller info
mov ax, 0x4F00
; ES:DI -> 512-byte VBE info buffer
int 0x10
; For each mode in buffer -> call:
mov ax, 0x4F01
mov cx, [mode_number]
; ES:DI -> 256-byte ModeInfoBlock
int 0x10

; To set a 32bpp linear mode (example)
mov ax, 0x4F02
mov bx, mode_number_or_0x4000  ; set LFB bit if supported
int 0x10

After you set a mode, ModeInfoBlock.PhysBasePtr gives a physical address for the LFB — in protected mode you must map that physical address into your virtual address space (DPMI / paging) before writing pixels. If a mode has no LFB you’ll have to use banked access per the ModeInfoBlock. Testing inside VirtualBox means you must query what modes the virtual card actually exposes (mode numbers differ by implementation). (wiki.osdev.org)

A final note: Mode‑X and other VGA planar hacks change memory layout and performance but do not increase the simultaneous color count beyond 256 — for true color use VBE/SVGA or a modern API/driver as suggested. (en.wikipedia.org)

Recommended Answers

All 9 Replies

> I was wondering how I could display more than 256 colors with the VGA color palette

You can not. It is a fundamental limitation of the VGA architecture. VGA may hold just that many colors at a time.

> the reason that you can't display more than 256 colors at once is because each byte in video memory corresponds to one pixel on the screen

The reason is that the VGA palette has 256 entries.

To achieve true color you must go beyond VGA modes.

>> To achieve true color you must go beyond VGA modes. <<

So how would I go beyond VGA modes?

I just found out that the newer way to display graphics is through DVI or HDMI, but I can't find a tutorial on how to program the DVI. So if anyone knows a tutorial or can tell me how that would be helpful.

A couple of (or a few) questions:

1. What video hardware (video board) are you using?
2. What kind of display?
3. How are you trying to program the display?

Modern cards are 24-bit or 32-bit color capable. There is a standard api interface that most all modern cards support called VESA. If you aren't using a card more than, say 15 or 20 years old, then they have VESA support, which will handle 24-32bit color pallets quite nicely. NO ONE uses VGA direct framebuffer I/O any more except possibly for raw console/BIOS output.

As for the display that I'm trying to program, I don't know since I am trying to get it to work in a virtual box. For VESA is that the only way to program for DVI?

DVI is just an interface. You really don't need to concern yourself with that. It is the video card (physical or virtual) that you need to communicate with. For VirtualBox, using VESA API's in the client would be appropriate, or normal system graphic API's, such as Qt, OpenGL, DX10, etc.

The video card is virtual, but I'm doing this in DOS so OpenGL and DirectX aren't really an option, I'm trying to do this as close to hardware level as possible.

Then the question nails down to what exactly is the virtual spec of that virtual card.

All cards are really different. They all support the lowest common hardware denominator (that is is VGA), and their drivers support the lowest common sofrware denominator (that is, DX/OGL standard). Programming registers of GeForce has absolutely nothing in common with programming registers of Radeon, or Larrabee, or Integrated Graphics, or whatever else.

So, how does your card operate?

Thanks, for your help, but I found a tutorial on how to program for VESA. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.