Need help with cursors please

Post Reply
Roroy
Posts: 17
Joined: Sat Sep 22, 2012 7:00 am

Need help with cursors please

Post by Roroy » Sat Sep 22, 2012 7:06 am

Hello,

I have been following this tutorial:

http://www.codemii.com/2008/08/31/tutorial-4-cursors/

And I can't quite understand one section of the code:

Code: Select all

void DrawHLine (int x1, int x2, int y, int color) {
    int i;
    y = 320 * y;
    x1 >>= 1;
    x2 >>= 1;
    for (i = x1; i <= x2; i++) {
        u32 *tmpfb = xfb;
        tmpfb[y+i] = color;
    }
}
Specifically the

u32 *tmpfb = xfb;
tmpfb[y=i] = color;

Am I right in assuming that a new variable named tmpfb is created?
What is the purpose of the asterisk?
What does xfb mean?
What is the purpose of the [y+1]?
What does the >>= symbol mean? I've never seen it in C/C++ Programs before...

Thanks in advance.

I appreciate any help given!

:D

mtheall
Posts: 210
Joined: Thu Feb 03, 2011 10:47 pm

Re: Need help with cursors please

Post by mtheall » Sat Sep 22, 2012 9:17 pm

Am I right in assuming that a new variable named tmpfb is created?
What is the purpose of the asterisk?
What does xfb mean?
What is the purpose of the [y+1]?
What does the >>= symbol mean? I've never seen it in C/C++ Programs before...
Yes, a new variable named tmpfb is created. The * indicates that it is a pointer. xfb is probably a global variable that was declared elsewhere. The [y+1] is an array dereferencer. Specifically, it is equivalent to "*(typeof(tmpfb))((int)tmpfb + (y+1)*sizeof(*tmpfb))". >>= is the bitwise shift + assignment combo operator.

If you don't know that a variable is being declared, you don't know what * is for, you don't know what [] means when applied to a pointer, you don't know what >>= is, then you need to be going through some C/C++ tutorials, not a Wii tutorial.

Roroy
Posts: 17
Joined: Sat Sep 22, 2012 7:00 am

Re: Need help with cursors please

Post by Roroy » Tue Sep 25, 2012 8:53 am

Took your advice and step by step, have been taking C++ Tutorials.
So hopefully will understand this better.

Found out where xfb was declared:

static void *xfb = NULL;

(At the very top of the example source code in Wii folder)

But I don't get what this line does...

mtheall
Posts: 210
Joined: Thu Feb 03, 2011 10:47 pm

Re: Need help with cursors please

Post by mtheall » Tue Sep 25, 2012 11:25 pm

Code: Select all

static void *xfb = NULL;
This line? It does the following things:

1. Declare a variable xfb
2. xfb is of type void* (a pointer to void, i.e. a pointer to generic/unknown type)
3. Assign the value NULL to xfb (NULL is ((void*)0) in GNU)
4. xfb is static (other translation units will never be able to see this variable, i.e. other c/cpp/h/hpp files)

relminator
Posts: 84
Joined: Sun Apr 11, 2010 10:43 am

Re: Need help with cursors please

Post by relminator » Thu Sep 27, 2012 6:46 am

Why are they still using software rendering on the Wii when we on the DS are doing HW accel?

User avatar
Izhido
Posts: 107
Joined: Fri Oct 19, 2007 10:57 pm
Location: Costa Rica
Contact:

Re: Need help with cursors please

Post by Izhido » Thu Sep 27, 2012 6:55 pm

Cause it's fun?

You should take a look at the beautiful things you can create when you have a crude, raw circle/arc drawing algorithm and a way to place pixels directly on-screen. Wonderful, wonderful GW-BASIC-over-DOS-programs memories...

(Oh. And slow pixel-filling algorithms too :) )

relminator
Posts: 84
Joined: Sun Apr 11, 2010 10:43 am

Re: Need help with cursors please

Post by relminator » Fri Sep 28, 2012 7:09 am

Izhido wrote:Cause it's fun?

You should take a look at the beautiful things you can create when you have a crude, raw circle/arc drawing algorithm and a way to place pixels directly on-screen. Wonderful, wonderful GW-BASIC-over-DOS-programs memories...

(Oh. And slow pixel-filling algorithms too :) )
Oh, trust me I do:
http://rel.phatcode.net/junk.php?id=119

Look at the bottom screens.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests