Page 1 of 2

Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Tue Feb 17, 2009 8:42 pm
by sweetgum
Before I move into developing my own kernel I'd like to experiment with drawing graphics... I've taken the following code off of the wiki and implemeneted a pointer to 0xA0000 in hopes of being able to draw a single red pixel using putpixel from the wiki.I cant seem to get this working, the following is my code.

Code: Select all

// main.c -- Defines the C-code kernel entry point, calls initialisation routines.
//           Made for JamesM's tutorials <www.jamesmolloy.co.uk>

static void putpixel(unsigned char* screen, int x,int y, int color)
{
    unsigned where=x*3+y*2400;
    screen[where]=color&255;         // BLUE
    screen[where+1]=(color>>8)&255;  // GREEN
    screen[where+2]=(color>>16)&255; // RED
}



int main(struct multiboot *mboot_ptr)
{
    char *sc = (char*)0xA0000;
	putpixel(sc, 0,0, 0xFF0000);
	
}
I've searched google the wiki and the forums for something about drawing basic graphics, but I've got no sufficient results. If someone could help me out I'd really appreciate it. This is booted with grub so the kernel is in protected mode.

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Tue Feb 17, 2009 9:22 pm
by piranha
Is it patched grub?
Do you have initialization for video mode?

Cause if it isn't, and you don't have any........wow.
Edit: It is on the wiki.

-JL

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Tue Feb 17, 2009 9:40 pm
by Troy Martin
A couple problems with your code/theory:
  • As piranha said, video mode probably isn't initialized.
  • Your code is for 24-bit colour depths only, which isn't supported in Virtual PC (probably only that single emulator though.)
Although the usage of the screen selector in putpixel() is a good plan for the future (think desktop switching, virtual terminals, etc.) =D>

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Tue Feb 17, 2009 10:02 pm
by sweetgum
piranha wrote:Is it patched grub?
Do you have initialization for video mode?

Cause if it isn't, and you don't have any........wow.
Edit: It is on the wiki.

-JL
Can you show me how to intialize video mode? Thats the entire source to main.c and its all thats running, so I don't have any such initialization. If you could show me where this information is on the wiki i'd really appreciate it :)

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Tue Feb 17, 2009 10:07 pm
by piranha
http://wiki.osdev.org/Bochs_VBE_extensions
http://wiki.osdev.org/Category:VGA
http://wiki.osdev.org/Drawing_In_Protected_Mode

Specifically the last link...

the way I do it is use patched grub, but you can also do it other ways...

-JL

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Tue Feb 17, 2009 10:45 pm
by sweetgum
piranha wrote:http://wiki.osdev.org/Bochs_VBE_extensions
http://wiki.osdev.org/Category:VGA
http://wiki.osdev.org/Drawing_In_Protected_Mode

Specifically the last link...

the way I do it is use patched grub, but you can also do it other ways...

-JL
So I figure with the patched grub my code will just display a red pixel right? Or am I missing something? Can you show me your drawpixel routine that you use with the patched grub?

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Wed Feb 18, 2009 2:23 am
by eddyb
sweetgum wrote:
piranha wrote:http://wiki.osdev.org/Bochs_VBE_extensions
http://wiki.osdev.org/Category:VGA
http://wiki.osdev.org/Drawing_In_Protected_Mode

Specifically the last link...

the way I do it is use patched grub, but you can also do it other ways...

-JL
So I figure with the patched grub my code will just display a red pixel right? Or am I missing something? Can you show me your drawpixel routine that you use with the patched grub?
patched grub sets the video mode for you, so it'll work

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Wed Feb 18, 2009 6:25 am
by Creature
What you're doing now is drawing a pixel to a non-existing screen. When GRUB passes command to your kernel (and you did not compile GRUB with VBE support and did not request it), you're in 80x25 text mode, meaning all you can do is text. Besides, even though I'm very fond of wanting to have graphics myself too and GRUB VBE seems like the easiest solution, building GRUB is a pain in the @$$, if you succeed, please do share it with us ;).

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Wed Feb 18, 2009 9:04 am
by neon
and GRUB VBE seems like the easiest solution,
Sometimes the easiest solution is not the best solution.

It is fine if you want to use VBE; but I dont recommend relying on the boot loader to set it.

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Wed Feb 18, 2009 11:40 am
by sweetgum
neon wrote:
and GRUB VBE seems like the easiest solution,
Sometimes the easiest solution is not the best solution.

It is fine if you want to use VBE; but I dont recommend relying on the boot loader to set it.
Hey neon, could you show me how to set the mode to VBE without grub? Just for learning purposes.

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Wed Feb 18, 2009 1:04 pm
by neon
Hey neon, could you show me how to set the mode to VBE without grub? Just for learning purposes.
Just use VBE via real mode. Just look for the VBE (or VESA) specifications..everything you need is in there. Or even Ralf Browns interrupt list, int 0x10. Scroll down until you get to the VESA / VBE interrupts. (I cant post a link right now.)

I do not want to show you an example because it may not be best for your systems design goals. I highley recommend looking at the different methods that you have before deciding what is best for your systems needs. i.e., VESA? VGA? VBE? GRUB?

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Wed Feb 18, 2009 2:38 pm
by Creature
The best solution is probably either switching back to real mode or VM86 mode (for which the first one will most likely give you issues with your 32-bits code and the second will need you to do JamesM's tuts almost entirely, as it requires multitasking). Though both aren't easy to do. I know graphics sounds fun, but you should try to get it out of your mind until you get some other parts of your OS, like multitasking and VM86. A GUI is one of the later things you should wonder about.

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Wed Feb 18, 2009 4:20 pm
by Combuster
There are about two easy routes for graphics in the kernel:

Easy:
1: Have the bootloader set graphics mode (ugly hack, but works)
2: Grab some VGA code and use that (limited resolution, but good to fit anywhere into your OS' five year plan since it is a starter for point 6 below)

Medium:
3: switching to real mode (make sure you get the switch right here, it needs quite a bit of magic)
4: V8086 mode (nice if you have it, but difficult to pull off for beginners, and might not fit your kernel design as it complicates things due to segment registers, and not working in long mode)

Difficult:
5: real mode emulator (works everywhere, but is a huge amount of work)

Expert:
6: write drivers for each card (be seeing you again in 25 years :twisted:)

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Wed Feb 18, 2009 5:48 pm
by Troy Martin
Combuster wrote:There are about two easy routes for graphics in the kernel:

Easy:
1: Have the bootloader set graphics mode (ugly hack, but works)
2: Grab some VGA code and use that (limited resolution, but good to fit anywhere into your OS' five year plan since it is a starter for point 6 below)

Medium:
3: switching to real mode (make sure you get the switch right here, it needs quite a bit of magic)
4: V8086 mode (nice if you have it, but difficult to pull off for beginners, and might not fit your kernel design as it complicates things due to segment registers, and not working in long mode)

Difficult:
5: real mode emulator (works everywhere, but is a huge amount of work)

Expert:
6: write drivers for each card (be seeing you again in 25 years :twisted:)
Adding another one to the list: a few old VGA cards (Realtek RTVGA, VEGA cards, C&T 64310, etc.) can support resolutions of up to 1024x768 using the standard VGA mode setting tool (AH=00h) but I don't think any new cards support said modes. Although that would be wicked b!tchin'!!!

Re: Drawing graphics, using JamesM Genesis kernel as a basis

Posted: Thu Feb 19, 2009 5:14 am
by Combuster
using the standard VGA mode setting tool (AH=00h)
If you use the bios anyway, you can just use VBE while you're at it, for the above list that doesn't make a difference.

If you care, you can get a 800x600x4 with basic VGA register programming (with a braindamaging 40Hz refresh rate as consequence)