Plotting pixels directly in pmode

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
morpheus

Plotting pixels directly in pmode

Post by morpheus »

Hello everbody

I wanted to plot a pixel with the following function.

void plot_pixel(int x, int y, byte c)
{
byte* offset = (char*)0xA0000 + ((0x280 * x) + y);
*offset = c;
}

[0x280 means 640]

I work in 640*480*256 mode and in pmode.

but it doesn't work. Does anybody have an idea??
hartyl

RE:Plotting pixels directly in pmode

Post by hartyl »

it should still do - in pmode as well.
do you have a data-descriptor with base 0 (otherwise it won't work)?
how do you switch to that vga-mode?

greets, hartyl
morpheus

RE:Plotting pixels directly in pmode

Post by morpheus »

Yes my kernel lives in DPL0

I switch to this mode by switching to (un)real mode then do the mode switch via:

mov ax, 4f02h  ;
mov bx, 101h   ; 640*480*256
int 10h        ; call SVGA bios

then I switch back to pmode

The only thing is that I can't plot pixels :(
carbonBased

RE:Plotting pixels directly in pmode

Post by carbonBased »

First off, you do know that the video memory window at 0x000A0000 is only a 64k chunk, right?

640x480 == ~300kb

In other words, you wont be able to access the entire span of video memory using this mechanism alone (you'll also need to use video bank switching).

Since you're using VESA, you might want to check out my VESA tutorial (meant for DJGPP, but easily ported to any language/environment) at http://www.neuraldk.org/document.php?djgppGraphics

Cheers,
Jeff
hartyl

RE:Plotting pixels directly in pmode

Post by hartyl »

when you're using VESA it's best to use the LFB (linear frame buffer). you can get the base-address of the buffer via an "int 10h"-call & write to it like to good old 0xA0000.

greets, hartyl
Morpheus

RE:Plotting pixels directly in pmode

Post by Morpheus »

Thanks I didn't knew that until I discovered it while plotting pixels. No I'm going to find out the addr of the LFB.
Morpheus

RE:Plotting pixels directly in pmode

Post by Morpheus »

thanks Hartyl,

After trying to work with the LFB it worked for me :)

Thanks mate!!
carbonBased

RE:Plotting pixels directly in pmode

Post by carbonBased »

Just a quick note; the LFB is not supported on all graphics cards... at least not through VESA.

To support the widest variety of graphics cards, you should also consider writing drivers for VESA banked modes (using the real mode and pmode banking routines).

It's truely a pain, but it'll give you excellent coverage, and reduce the need for chipset specific drivers (which are even more a pain!) for a time.

Cheers,
Jeff
Morpheus

RE:Plotting pixels directly in pmode

Post by Morpheus »

Your right but I don't know how to do bankswitches in pmode. (without switching back to real mode). I know how to do it in real mode but how to this in pmode??

Greetz
carbonBased

RE:Plotting pixels directly in pmode

Post by carbonBased »

The link I previously gave (http://www.neuraldk.org/document.php?djgppGraphics) shows how to use the pmode banking routines.  VESA 2.0 defines a pointer (32-bit flat pointer) to both the LFB and protected mode banking routine.

Cheers,
Jeff
TheUbu

RE:Plotting pixels directly in pmode

Post by TheUbu »

Hey,

Plotting of pixels could be quite simple if you read up on VESA. All you have to do is build v86 functionality into your kernel(quite simple). Then write a little biosCall function which will utilize the v86 procedures to call the bios and init a VESA mode for you. Then get the VESA information about the LFB and have your VMM map that region of memory in. Once all that is complete just write to it and you will see things appear on the screen. I on the other hand just use the ubix graphics lib plotPixel to do that.


-Christopher
Post Reply