Page 1 of 1

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

Posted: Mon Jul 22, 2019 7:22 am
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?

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

Posted: Mon Jul 22, 2019 9:42 am
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;
}

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

Posted: Mon Jul 22, 2019 10:42 am
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?

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

Posted: Mon Jul 22, 2019 11:19 am
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.

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

Posted: Mon Jul 22, 2019 11:58 am
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?

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

Posted: Tue Jul 23, 2019 12:52 am
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.