Returning address of pixel...
Okay, this is my first graphic-based game. It's also my
first real program using pointers and FILE I/O functions.
So, if my question doesn't make any sense--don't make fun
of me. Please.
By the way, a lot of the stuff I'm trying to do won't even
be used in my game--I just keep trying various things so I
can become more 'comfortable' with these concepts.
I'm trying to make a 13h game. Right now, I'm
trying to make a function that returns the address of a
plotted-pixel. Here's my pixel-plotting function:
Code:
//Global
typedef unsigned char BYTE;
typedef unsigned short WORD;
BYTE *g_vgamemory = 0xA0000;
int PixelPlot(char color, int x, int y)
{
WORD offset = ( (y *320 + x) );
g_vgamemory[offset] = color;
return 0;
}
Anyway, I want to make a function that returns the address
of a pixel (as I've said). But I don't know where to start.
What return-type do I give the function? I mean, g_vgamemory
is a BYTE, but the offset is a WORD.
Would it be this...?
Code:
BYTE *get_pixel_add(int x, int y)
{
WORD offset = ( ((y *320 + x) );
return &g_vgamemory[offset];
}
Or this...?
Code:
WORD *get_pixel_add(int x, int y)
{
WORD offset = ( (y *320 + x) );
return &g_vgamemory[offset];
}
...g_vgamemory is of type BYTE. But I don't see how that
function could work since it only holds a value of 0-255,
and there's 64,000 possible places the pixel could be (??)
If I'm suppose to use the WORD function, would I need to
typecast g_vgamemory as a WORD? Please help. (Please explain
your answer too. I want to know how to do it, but more
importantly, I want to know why it works. :))
:confused: <- I love these little faces...
Thanks a lot.