Drawing graphics, using JamesM Genesis kernel as a basis

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.
sweetgum
Member
Member
Posts: 37
Joined: Thu Sep 18, 2008 11:17 pm

Drawing graphics, using JamesM Genesis kernel as a basis

Post 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.
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

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

Post 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
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

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

Post 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>
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
sweetgum
Member
Member
Posts: 37
Joined: Thu Sep 18, 2008 11:17 pm

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

Post 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 :)
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

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

Post 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
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
sweetgum
Member
Member
Posts: 37
Joined: Thu Sep 18, 2008 11:17 pm

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

Post 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?
eddyb
Member
Member
Posts: 248
Joined: Fri Aug 01, 2008 7:52 am

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

Post 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
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

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

Post 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 ;).
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

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

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
sweetgum
Member
Member
Posts: 37
Joined: Thu Sep 18, 2008 11:17 pm

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

Post 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.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

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

Post 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?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

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

Post 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.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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:)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

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

Post 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'!!!
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply