Issue when declaring functionpointer

29/01/2010

I have two functions:
void emptyFunction(int functionChoice)
{
}

void randomizeButtons(Button* array[], u8 items)
{
int counter;
for(counter=0; counter<items; counter++)
{
array[counter]->posX = 220*rand();
array[counter]->posY = 220*rand();

drawButton(array[counter]);
}
}

And two pointers to these functions:
void (*foo)(int);
foo = &emptyFunction;

void (*foo2)(Button*, u8);
foo2 = &randomizeButtons;

The second pointer though, gives a warning:
warning: assignment from incompatible pointer type

To solve this, for the second pointer only, I have to change the function declaration OR typecast to (void*).
So solution 1:
void (*foo2);

And solution 2:
foo2 = (void*) &randomizeButtons;

Very strange, because this isn’t needed for the first functionpointer, foo.

Advertisements

Minor UPDATE Single Pipe Builder

29/01/2010

Playing my (first) NDS game “Single Pipe Builder” on a real NDS works flawlessly. However, placing the ‘key rock’ can be difficult for most people (right handed). With this update you can use the shoulder buttons! Also, the filename now corresponds tot the name of the game.

The update is backwards compatible: the ‘A’ button still works.

Have fun!

Download singlePipeBuilder.zip


Replace thumbstick of your N64 controller

29/01/2010

It can be done cheap and by yourself!
http://www.nintendorepairshop.com/N64%20Controller%20Repair%20Thumbstick%20Replacement.htm

Nintendo Repair Shop


expected specifier-qualifier-list before ‘Button’

29/01/2010

What if you make a new struct, wich has a structmember that is a pointer to something that has the same type of the struct you are making?

For example:
typedef struct
{
char* text;
u8 posX;
u8 posY;
u8 width;
u8 height;
void* callback_function;
Button* array;
u8 itemsInArray;
} Button;

Now you will get the following error:  expected specifier-qualifier-list before ‘Button’
How to work around this?
Put struct in front of the structmember, and it will compile!

Working example:
ypedef struct
{
char* text;
u8 posX;
u8 posY;
u8 width;
u8 height;
void* callback_function;
struct Button* array;
u8 itemsInArray;
} Button;

Note:
The button-struct is not a very good struct itself, but it’s an example for this error.


Structs with function pointers with arguments

29/01/2010

Example: (complex, in principle only needed when you dive into C and are interested in pointers and void pointers)

http://cid-58814201e79976dd.skydrive.live.com/self.aspx/iepro/functionPointerExample.zip

This example has an example of making an array of objects (buttons) having as members function pointers.

These function pointers take arguments being  another member of the struct.

setting the pointers and its argument:

void setFunctionPointer_buttonView( void* myFunction, BUTTONVIEW* myButtonViewPtr, float myArgument ){
void (*foo)(float);
foo = myFunction;
((BUTTONVIEW*) myButtonViewPtr)->pushedButtonFunction = foo;
((BUTTONVIEW*) myButtonViewPtr)->argumentOfPushedButtonFunction = myArgument;
}

example of calling the function pointed at when clicked within the button:

void clickedWithinButton_buttonView( u8 clickPosX, u8 clickPosY, BUTTONVIEW* myButtonViewPtr ){

u8 positionX = myButtonViewPtr->posX;
u8 positionY = myButtonViewPtr->posY;
u8 _width = myButtonViewPtr->width;
u8 _height = myButtonViewPtr->height;

u8 left =   positionX;
u8 right =  positionX +  _width;
u8 up =   positionY;
u8 down =   positionY + _height;

if ( ((clickPosX > left) && (clickPosX < right)) && ((clickPosY > up) && (clickPosY < down)) ){
//playDrop() ;
void (*foo)(float);
foo = myButtonViewPtr->pushedButtonFunction;
float myANgle =  myButtonViewPtr->argumentOfPushedButtonFunction;
foo(myANgle);
}
}


Eclipse, (using nds plugin)

22/01/2010

Using Eclipse as an IDE. (For now on MACOS.)

Download Eclips, version C/C++

you can configure Eclipse to make nds files.

http://tekninjadiaries.blogspot.com/2008/01/setting-up-eclipse-for-nintendo-ds.html

(but this link does not give all information)

Issue: Eclipse does not see the header files ???

Solution: carefully configuring the project properties

(a little bit different for MACOS and XP)

Here for MACOS:

Create a makefile project, using MACOSX GCC

Then project properties — right click on project in Project Explorer —: (follow the pictures)

uncheck Generate makefile automatically

add DEVKITPRO and DEVKITARM manually finding the location in /opt/devkitpro/…

make sure MACOSX GCC is selected

in path and symbols we have a range of tabs to take care of…

these includes are shown in the Project Explorer in the Includes folder, which is not the folder with your header files, this is an extra folder

The source file is made and you have to copy your source files in this folder, which has a green dot on it.

output location for the .nds file

the makefile must be added by hand, and the content copied in it. (I used the makefile from a Programmers NotePad project

make sure this is shown in the Project Explorer, sometimes there is a Default ARM& folder, which is blocking path’s…so shift around until you have this configuration. The include folder has the header files. This folder is also added using Eclipse new folder, than the header files added.

To refresh do clean… under tab project of Eclipse. There will be automatic rebuilding.

My console said:

**** Build of configuration Default for project testingWhileItRains ****

make
main.c
arm-eabi-gcc -MMD -MP -MF /Users/contrechoc/Documents/workspace/testingWhileItRains/build/main.d -g -Wall -O2 -march=armv5te -mtune=arm946e-s -fomit-frame-pointer -ffast-math -mthumb -mthumb-interwork -I/Users/contrechoc/Documents/workspace/testingWhileItRains/include -I/Users/contrechoc/Documents/workspace/testingWhileItRains/build -I/opt/devkitpro/libnds/include -I/opt/devkitpro/libnds/include -I/Users/contrechoc/Documents/workspace/testingWhileItRains/build -DARM9 -c /Users/contrechoc/Documents/workspace/testingWhileItRains/source/main.c -o main.o
/Users/contrechoc/Documents/workspace/testingWhileItRains/source/main.c: In function ‘main’:
/Users/contrechoc/Documents/workspace/testingWhileItRains/source/main.c:88: warning: ‘touchReadXY’ is deprecated (declared at /opt/devkitpro/libnds/include/nds/arm9/input.h:94)
/Users/contrechoc/Documents/workspace/testingWhileItRains/source/main.c:21: warning: unused variable ‘test’
linking testingWhileItRains.elf
built … testingWhileItRains.arm9

Nintendo DS rom tool 1.41 – May  1 2009
by Rafael Vuijk, Dave Murphy, Alexei Karpenko
built … testingWhileItRains.nds

(after a few houres of trying to get running with Eclipse….)

—-

Eclipse with C/C++ is called CDT for Windows.

http://snipah.com/

apparently you can also use a prepared nds configuration: (Eclipse->Help->Install New Software-> add website)

This is for Windows (?) I’ll try this on the XP…

The problem with WIndows is the C compiler MINGW or CYGWIN. These have to cooperate with ECLIPSE and that is somehow not easy(?).

help installing the nds plugin for Eclipse:

http://marketplace.eclipse.org/updatesite/help?url=http://dev.snipah.com/nds/updater

well, tried everything for the moment with Eclipse on XP…..:-(((

Programmer’s Notepad works without a flaw, and without any complaining: we’ll stick to Programmers NotePad!


Print debug info on top screen

22/01/2010

If you want to easily print debug info with iprintf on the top screen of your nds, copy and paste the following code right above where you want to begin debugging:

videoSetMode(MODE_0_2D);
PrintConsole topScreen;
consoleInit(&topScreen, 3,BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true);
consoleSelect(&topScreen);
iprintf(“\n\n\tHello DS dev’rs\n”);