How to work with VGA video mod? How to encode pixels?

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
User avatar
mrjbom
Member
Member
Posts: 322
Joined: Sun Jul 21, 2019 7:34 am

How to work with VGA video mod? How to encode pixels?

Post by mrjbom »

Hey.
Based on this page, you can understand that the standard VGA BIOS memory includes VGA 320 * 200 with 256 colors. I have a question, how to use a particular mod? How to write in bit color?
Klakap
Member
Member
Posts: 297
Joined: Sat Mar 10, 2018 10:16 am

Re: How to work with VGA video mod? How to encode pixels?

Post by Klakap »

Little note at first, if you want use graphic mode and you want use BIOS, dont work with VGA, implement VESA, it contain all modes what you need. VGA is good if you want write driver for graphic card, because you can learn a lot about it.

How use particular mode? At first you must make a decision if you want start graphic mode from BIOS, or without BIOS. If you dont want use BIOS, complete code is in http://files.osdev.org/mirrors/geezer/o ... cs/modes.c .

Here is code for writing pixels:

Code: Select all

void write_vga_pixel(uint32_t line, uint32_t column, uint8_t color) {
    uint8_t *vga_memory = (uint8_t *) 0xA0000;
    uint32_t offset=0;

    offset=( (line*320) + column);

    vga_memory[offset]=color;
}
User avatar
mrjbom
Member
Member
Posts: 322
Joined: Sun Jul 21, 2019 7:34 am

Re: How to work with VGA video mod? How to encode pixels?

Post by mrjbom »

Klakap wrote:Little note at first, if you want use graphic mode and you want use BIOS, dont work with VGA, implement VESA, it contain all modes what you need. VGA is good if you want write driver for graphic card, because you can learn a lot about it.

How use particular mode? At first you must make a decision if you want start graphic mode from BIOS, or without BIOS. If you dont want use BIOS, complete code is in http://files.osdev.org/mirrors/geezer/o ... cs/modes.c .

Here is code for writing pixels:

Code: Select all

void write_vga_pixel(uint32_t line, uint32_t column, uint8_t color) {
    uint8_t *vga_memory = (uint8_t *) 0xA0000;
    uint32_t offset=0;

    offset=( (line*320) + column);

    vga_memory[offset]=color;
}
How to use it working in BIOS?
Klakap
Member
Member
Posts: 297
Joined: Sat Mar 10, 2018 10:16 am

Re: How to work with VGA video mod? How to encode pixels?

Post by Klakap »

You must be in real mode and use assembler:

Code: Select all

  mov ah, 0  ;BIOS VGA mode interrupt
  mov al, 0x13  ;320x200x8 bpp graphic mode
  int 0x10  ;call bios interrupt
And you are in graphic mode.
User avatar
mrjbom
Member
Member
Posts: 322
Joined: Sun Jul 21, 2019 7:34 am

Re: How to work with VGA video mod? How to encode pixels?

Post by mrjbom »

Klakap wrote:You must be in real mode and use assembler
As far as I know, GRUB loads my kernel into protected mode right away. Is that right? How do I then use 320x200x8bpp graphic mode?
GMorgan
Posts: 22
Joined: Sun Jul 14, 2019 4:27 pm

Re: How to work with VGA video mod? How to encode pixels?

Post by GMorgan »

You'd have to drop back to real mode. If you are using GRUB it can initialise the framebuffer for you.

Honestly all of the BIOS stuff is going away. You might be better off using UEFI if you plan to write your kernel in long mode.
Post Reply