Firstly, you need to set a graphics mode indeed.
I assume you're in protected mode, so you have to program VGA controllers to set a mode, like 640x480x4.
http://wiki.osdev.org/VGA_Resources has really great examples.
If you want to have SVGA, you have two options, use VBE or write native drivers.
VBE uses BIOS interrupt 0x10 function 0x4FXX, so it only works in real mode. Instead you can use PMID from VBE3, but it isn't supported very much, as it was an optional feature to implement in graphics cards.
If you want to use BIOS interrupts you have a few options.
Drop to real mode, do the interrupt and return back to protected mode. But it is an ugly solution, also you will need reprogram PICs.
Use Virtual 8086 mode. This is a bit hard to implement, and only works in protected mode, no long mode support.
wiki.osdev.org has neat two pages for it:
http://wiki.osdev.org/Virtual_8086_Mode and
http://wiki.osdev.org/Virtual_Monitor
Use an emulator like libx86emu to emulate BIOS code in protected mode, but redirect the port and memory input / outputs to real hardware, then the devices won't know the difference. This is the method I'm using, in this thread:
http://f.osdev.org/viewtopic.php?f=1&t=31388
After setting a graphics mode, you need to plot pixels on it.
VGA modes have indexed color system, if you want to change palette you can reprogram DAC.
If you set a planar mode like 640x480x4, your buffers are four bitmaps, for each bits of index. For example if you want to plot the first pixel with palette index 2:
-> Switch to first plane, set first bit on plane to 1.
-> Switch to second plane, set first bit on plane to 1.
-> Switch to third plane, set first bit on plane to 0.
-> Switch to fourth plane, set first bit on plane to 0.
0b0011 is 2, so first pixel with be palette index 2.
If you set a linear mode like 320x200x8 then everything is much easier.
You have a linear frame buffer, if you want to plot first pixel with palette index 210, just do:
Code: Select all
uint8_t* vgamem = (uint8_t*) 0xA0000;
vgamem[0] = 210;
If you set a VBE mode with LFB, you have to get the LFB address from mode info block, then you can plot pixels easily. And there is no indexed color mode in VBE.
If you set a mode like 800x600x24, and if you want to set first pixel with a RGB of 255,210,20:
Code: Select all
uint8_t* lfb = (uint8_t*) mode_info->lfb_address;
lfb[0] = 20; // (Blue)
lfb[1] = 210; // (Green)
lfb[2] = 255; // (Red)
is enough.
http://wiki.osdev.org/Drawing_In_Protected_Mode has neat "example codes" for plotting pixels, drawing rectangles etc.
Cheers.