OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:26 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 35 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: VGA programming problems
PostPosted: Thu Sep 17, 2020 9:14 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
I did a search on my archives, and I've found this code (see attachment). It sets VGA modes without using the BIOS.

Just for the records, the only standard resolution with 256 colors on VGA is 320x200. There's a trick to use 320x240, but that's all. The reason is because there's no more video RAM to handle larger resolutions. 640x480 and 800x600 are 16 colors only to fit into 64k. (320 * 200 * 8 bit = 64k, and the standard 80x25 text mode is 9*80x16*25 = 720x400 pixels)

To support higher resolutions with 256 colors, you'll need SVGA. There you can only access 64k at once too, but you have a so called "bank" function which selects a window on a larger video RAM (meaning you can access different segments at 0xA0000 depending which bank is used). Unfortunately the banking function is manufacturer specific and not standardized as the other VGA registers.

For higher resolutions and packed pixels (hicolor or truecolor), you'll need VESA which is not VGA. VESA is only standardized at BIOS int interface level, so either you write a native video card driver or you need to use the BIOS. This mode uses so called linear framebuffer, which is not mapped at 0xA0000, therefore it's not limited to 64k. The buffer is contiguous, and can be arbitrary large.

Cheers,
bzt


Attachments:
vgamodes.c [62.36 KiB]
Downloaded 92 times
Top
 Profile  
 
 Post subject: Re: VGA programming problems
PostPosted: Thu Sep 17, 2020 3:37 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
bzt wrote:
No, of course you don't need to change the palette controller. What you need to change is the mode.

Changing the mode involves changing the palette controller. Disassemble any VGA option ROM and see for yourself.

bzt wrote:
For VGA you can have either a mode with 16 colors, or with 256 colors, no other options exists

Correct. When did I say the 64-color palette was a limitation of the hardware? The palette controller is simply programmed to output only 64 unique colors. In 16-color modes, the attribute controller can only select 16 of the palette controller's 256 entries.

bzt wrote:
(there's no such thing as 64 color mode, and BIOS was never programmed to produce 64 EGA colors.

Video modes set using the VGA ROM are designed to be register-compatible with EGA, if the mode existed on EGA. EGA allows you to select 16 out of a total of 64 colors via the attribute controller. In order for that to work on VGA, the VGA ROM must program the palette controller to produce the 64 EGA colors. Disassemble any VGA option ROM and see for yourself.

Minus zero degrees has a few VGA ROMs if you're not sure where to look.


Top
 Profile  
 
 Post subject: Re: VGA programming problems
PostPosted: Fri Sep 18, 2020 8:26 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
Octocontrabass wrote:
Changing the mode involves changing the palette controller.
Nope, the code I've attached to my previous post changes modes but it does not touch any DAC registers. It even has a comment on the top, "To do: do something with 16- and 256-color palettes?"
Octocontrabass wrote:
Video modes set using the VGA ROM are designed to be register-compatible with EGA
No, they weren't. The modes were designed to use the same buffer layout, but not registers. (And FYI while EGA had two buffers for two monitors, VGA had only one buffer for a single monitor). The EGA palette registers had 2 bits per color channels, while VGA had 6 bits, so it cannot be register-compatible. Converting EGA channel values to VGA channel values requires SHL 4. See IBM EGA specification, page 12 section Registers.
Octocontrabass wrote:
In order for that to work on VGA, the VGA ROM must program the palette controller to produce the 64 EGA colors.
Where did you get that "must produce the 64 EGA colors" thing? Would you mind sharing a link with us? By default, the first 16 (and only 16, not 64) VGA palette entries are configured to match the default 16 EGA colors. End of story.
Octocontrabass wrote:
Disassemble any VGA option ROM and see for yourself.
Believe it or not, I actually did disassemble many video ROMs back in the day. Mostly SVGA ROMs, to reverse engineer their banking routine and additional register set. I wrote an SVGA assembly library for DOS with native drivers, years before VESA got widespread. Later I rewrote that library with VESA, and I've posted a screenshot of that rewrite on this forum (huh, that post was 8 years ago, and the rewrite was in 1998).

But please, this conversation is going nowhere, and it definitely does not help the OP. No matter how many times you write "64 EGA colors", that won't make it true.

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: VGA programming problems
PostPosted: Fri Sep 18, 2020 1:59 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
bzt wrote:
(And FYI while EGA had two buffers for two monitors, VGA had only one buffer for a single monitor).

Where did you hear this? Last I checked, EGA can only drive one monitor at a time. It is possible to install a CGA or MDA to attach a second monitor, but VGA supports that too. (I've even seen one PCI chipset that routes MDA I/O independently from the other VGA-related I/O to allow installing a PCI VGA alongside an ISA MDA, although I don't know how well it works.)

bzt wrote:
The EGA palette registers had 2 bits per color channels, while VGA had 6 bits, so it cannot be register-compatible. Converting EGA channel values to VGA channel values requires SHL 4. See IBM EGA specification, page 12 section Registers.

Those are the attribute controller palette registers, which are the same for both EGA and VGA. VGA also has a second set of palette registers in the DAC, which converts the indices programmed into the attribute controller's palette into colors. The VGA attribute controller's palette is compatible with EGA only when the DAC palette is programmed to produce EGA colors.

bzt wrote:
Where did you get that "must produce the 64 EGA colors" thing? Would you mind sharing a link with us? By default, the first 16 (and only 16, not 64) VGA palette entries are configured to match the default 16 EGA colors. End of story.

Here's a link. Look at the "Color Paging with the Color Select Register" section.


Top
 Profile  
 
 Post subject: Re: VGA programming problems
PostPosted: Fri Sep 18, 2020 2:10 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
To settle this, from Wikipedia:
Wikipedia wrote:
EGA produces a display of up to 16 colors (using a fixed palette, or one selected from a gamut of 64 colors, depending on mode) at several resolutions up to 640×350 pixels, as well as two monochrome modes at higher resolutions. EGA cards include a ROM to extend the system BIOS for additional graphics functions, and a custom CRT controller (CRTC).]

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 35 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 57 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group