Video in graphic mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
KuzinAlexandr
Posts: 1
Joined: Wed Oct 18, 2023 9:55 am
Libera.chat IRC: Alexandr

Video in graphic mode

Post by KuzinAlexandr »

Hello other forum users. I'm wondering how video memory can be used in graphics mode. In text it is used like this:

Code: Select all

char* videoptr = (char*)0xb8000;

void kmain()
{
    videoptr[0] = 'H';
    videoptr[1] = 0x07;
}
I heard that the address 0xA0000 is already used for the graphic mode

I would like to receive a code snippet for using the graphical mode.
Last edited by KuzinAlexandr on Wed Oct 25, 2023 11:50 am, edited 1 time in total.
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: Video in graphic mode

Post by Octocontrabass »

KuzinAlexandr wrote:I'm wondering how video memory can be used in graphics mode. In text it is used like this:
You can access video memory the same way in graphics mode. The specifics depend on which mode you're using.
KuzinAlexandr wrote:I heard that the address 0xA0000 is already used for the graphic mode
Standard VGA modes 0xD, 0xE, 0xF, 0x10, 0x11, 0x12, and 0x13 use address 0xA0000. Standard VGA modes 0x4, 0x5, and 0x6 use address 0xB8000. Non-standard modes can use other addresses.
Ultrasick
Posts: 1
Joined: Sat Dec 25, 2021 4:53 pm

Re: Video in graphic mode

Post by Ultrasick »

VGA has configuration registers. You can set the starting address of the framebuffer as you wish (within limits). The starting address can be set independent of whether you are in graphics or text mode.

When you use 16 colors per pixel, then writing a pixel is not so straight forward. You can only access 64 KB of the 256 KB. There is a configuration register where you tell the graphics circuit which of the four 64 KB parts should be accessible.

Those 4 parts (4x 64 KB) of the total memory (256 KB) are called "memory banks". Since you can only access 64 KB at any time you need to do bank switching (changing a value in a VGA configuration register).

A pixel is 4 bits in size (when using 16 colors). But every bit is stored in a different bank. So you store
[*] the bit 2^0 in bank 0
[*] the bit 2^1 in bank 1
[*] the bit 2^2 in bank 2 and
[*] the bit 2^3 in bank 3.

To sum it up and answer you question about a code snippet: You need at least a year of development time to write a proper VGA compatible driver. But I don't think that you can do it within a year.
Post Reply