Tutorial 6: Button detection

In this Wii programming tutorial we will cover displaying an image as the mouse cursor and how to detect button clicking. You can grab the PDF of this tutorial here: codemii-tutorial-6.

Firstly download this tutorial6-image which will contain the required files to get us started. This zip file also contains the JPEG code required to display images which you should have learnt about in the last tutorial. Extract this zip file in C:\devkitPro\examples\gamecube and open up tutorial6.pnproj.

As you should recall, we displayed a cursor which we could control on the gamecube by using the following code:

int cursor_x = 300;
int cursor_y = 250;

while(1) {

	PAD_ScanPads();

	if (PAD_StickY(0) > 18) {
		cursor_y--;
	}
	if (PAD_StickY(0) < -18) {
		cursor_y++;
	}
	if (PAD_StickX(0) > 18) {
		cursor_x++;
	}
	if (PAD_StickX(0) < -18) {
		cursor_x--;
	}

	VIDEO_ClearFrameBuffer (rmode, xfb, COLOR_BLACK);

	DrawBox (cursor_x, cursor_y, cursor_x + 1, cursor_y + 1, COLOR_WHITE);

	VIDEO_WaitVSync();

}

So all that’s required for us to do is change DrawBox to use display_jpeg instead.

display_jpeg(about, cursor_x, cursor_y); 

Compile your source and there we have it; your cursor is now showing up as an image.

Detecting button clicking

In order to detect button clicking we have to know our button’s four co-ordinates; x1, x2, y1 and y2. The simplest way to figure this out is to just print the location of your cursor to the screen when you press A so you can see the x and y co-ordinates as when you are displaying an image it’s not the same as the x and y of the cursor. I know that there has to be a better way for doing this, but I’m just showing you what worked for me.

Put change display_jpeg back to DrawBox as we’ll need to find the x and y co-ordinates.

You can then add the following code to print out the x and y co-ordinates of the cursor:

u16 buttonsDown = PAD_ButtonsDown(0);

if( buttonsDown & PAD_BUTTON_A ) {
	printf("x = %i. y = %i\n", cursor_x, cursor_y);
	usleep(500000);
}

We have used printf before, which prints something to the screen but in this case we are using printf to print out two integers; x and y. The way the statement works is we say to printf that we will be passing an integer in the first argument which is denoted by %i. After we have finished the text to print (“ “), we pass the first argument; cursor_x which is an integer. Printf grabs this integer and displays it when it prints “x = 100”. You can print a double (%d), long (%l), characters (%c) and so on.

Usleep as the name suggests, makes the whole application pause for a specified amount of time. The argument usleep takes is a integer and is in microseconds. 500000 would be 500 milliseconds which is ½ of a second.

Before using usleep you need to include

#include <unistd.h>

in your headers. Unistd includes miscellaneous functions. If you didn’t include unistd, it would still compile but throw an error saying it can’t find the usleep function, but lucky for us it would still work.

So now if we compile and run our code (tutorial6-mouse-image), we can move the cursor around the about image. What we need to do is find the x, y co-ordinates of the top left and bottom right of the image. So if you were to go ahead and do this yourself you would find that they would roughly be 202, 120 (top left) and 254, 141 (bottom right).

We have our image’s co-ordinates and now all that’s left to do is produce code that will identify if our cursor is in our images co-ordinates. Something as found below works nicely:

if (cursor_x >= 202 && cursor_x <= 254 && cursor_y >= 120 && cursor_y <= 141) {
	printf("Button pressed\n");
}

Place the above code in the if (buttonsDown & PAD_BUTTON_A) { statement and recompile your code (tutorial6-button-detection). Once you’ve run it with gcube, try pressing the A button (Q key) around the button and inside the button. You’ll see it works quite well and correctly detects when the button is pressed.

35 Responses to “Tutorial 6: Button detection”

  1. slash_trax says:

    I found your tutorials last Sunday and I have to say they are great. I haven’t been following them verbatim instead choosing to use them as sort of a guild to figure things out for myself. I started a new project, adding all of the elements from the different tutorials to it successfully.

    Is there a way to stack or layer elements so that you can have text on top of a JPEG image? Also can the JPEG tutorial be reworked for PNG files or is there a completely different way of adding them?

  2. teknecal says:

    I think you should just be able to display the text over the image by adding it after the display_jpeg function (or which ever function you use to show the jpeg).

    For PNG images it’s a little different and I have a not so pretty example here: http://www.codemii.com/display_png.zip

  3. harry says:

    thanks very much, again! :)
    I hope I’ll have a good idea for some homebrew software soon…

    I wonder if anyone is planning on releasing a “Wii Channel installer”. Something that can turn a Homebrew Channel Icon into a real Channel in the menu. Would be cool (for Sega, NES & SNES) but I guess it would need someone like bushing to create something like that.

  4. Ethan says:

    When I try to compile your file in display_png.zip it cannot find the include png/pngogc.h. Where can I find this include file?

    thanks for your tutorials,
    they are great,
    Ethan

  5. teknecal says:

    You can grab the png files here: http://www.codemii.com/libogc_png.zip. Extract it to C:\devkitPro\devkitPPC\powerpc-gekko

    I haven’t really looked into PNGs as I’m now just using GRRLib and I don’t have to think about it.

  6. DCelso says:

    How I can use the wii-mote ir instead of analog joystic in this example?
    And How I can use the nunchuck analog joystic in this example?
    Thanks.

  7. teknecal says:

    To use the Wiimote you can follow http://www.codemii.com/2008/08/31/tutorial-4-cursors/

    To use the nunchuck you can have a read of this http://forum.wiibrew.org/read.php?11,1334

  8. durdadan says:

    he he, sorry, you must hate seeing my post in all the topics

    i am getting this error

    > “make”
    main.c
    linking … tutorial6.elf
    c:/devkitPro/libogc/lib/wiilibwiiuse.a(dynamics.o): In function `calc_joystick_state’:
    dynamics.c:(.text.calc_joystick_state+0xa0): undefined reference to `atanf’
    dynamics.c:(.text.calc_joystick_state+0xf0): undefined reference to `sqrt’
    dynamics.c:(.text.calc_joystick_state+0×154): undefined reference to `atanf’
    c:/devkitPro/libogc/lib/wiilibwiiuse.a(dynamics.o): In function `calculate_orientation’:
    dynamics.c:(.text.calculate_orientation+0×230): undefined reference to `atan2f’
    dynamics.c:(.text.calculate_orientation+0×25c): undefined reference to `atan2f’
    c:/devkitPro/libogc/lib/wiilibwiiuse.a(ir.o): In function `calc_yaw’:
    ir.c:(.text.calc_yaw+0×28): undefined reference to `atanf’
    c:/devkitPro/libogc/lib/wiilibwiiuse.a(ir.o): In function `apply_ir_smoothing’:
    ir.c:(.text.apply_ir_smoothing+0×3c): undefined reference to `sqrtf’
    ir.c:(.text.apply_ir_smoothing+0xa4): undefined reference to `atan2f’
    ir.c:(.text.apply_ir_smoothing+0xac): undefined reference to `cosf’
    ir.c:(.text.apply_ir_smoothing+0xc8): undefined reference to `sinf’
    c:/devkitPro/libogc/lib/wiilibwiiuse.a(ir.o): In function `rotate_dots’:
    ir.c:(.text.rotate_dots+0xa0): undefined reference to `cos’
    ir.c:(.text.rotate_dots+0xb4): undefined reference to `sin’
    c:/devkitPro/libogc/lib/wiilibwiiuse.a(ir.o): In function `find_sensorbar’:
    ir.c:(.text.find_sensorbar+0×5d4): undefined reference to `atan2′
    ir.c:(.text.find_sensorbar+0×624): undefined reference to `atan2′
    ir.c:(.text.find_sensorbar+0×8d4): undefined reference to `atan2′
    c:/devkitPro/libogc/lib/wiilibbte.a(physbusif.o): In function `physbusif_output’:
    physbusif.c:(.text.physbusif_output+0×148): undefined reference to `USB_WriteBlkMsgAsync’
    physbusif.c:(.text.physbusif_output+0×184): undefined reference to `USB_WriteCtrlMsgAsync’
    c:/devkitPro/libogc/lib/wiilibbte.a(physbusif.o): In function `physbusif_shutdown’:
    physbusif.c:(.text.physbusif_shutdown+0×3c): undefined reference to `USB_CloseDeviceAsync’
    c:/devkitPro/libogc/lib/wiilibbte.a(physbusif.o): In function `__issue_intrread’:
    physbusif.c:(.text.__issue_intrread+0×9c): undefined reference to `USB_ReadIntrMsgAsync’
    c:/devkitPro/libogc/lib/wiilibbte.a(physbusif.o): In function `__issue_bulkread’:
    physbusif.c:(.text.__issue_bulkread+0×9c): undefined reference to `USB_ReadBlkMsgAsync’
    c:/devkitPro/libogc/lib/wiilibbte.a(physbusif.o): In function `physbusif_init’:
    physbusif.c:(.text.physbusif_init+0×58): undefined reference to `USB_Initialize’
    physbusif.c:(.text.physbusif_init+0×1a0): undefined reference to `USB_OpenDevice’
    physbusif.c:(.text.physbusif_init+0×1c8): undefined reference to `USB_OpenDevice’
    collect2: ld returned 1 exit status
    make[1]: *** [/c/devkitpro/examples/gamecube/tutorial6/tutorial6.elf] Error 1
    “make”: *** [build] Error 2

    > Process Exit Code: 2
    > Time Taken: 00:01

    all i did was add the IR movement, just like before.

    i didn’t add my button detection yet. and all my joystick movements are commented out.

    • durdadan says:

      i rewrote the code and got different errors, along the same lines

      > “make”
      main.c
      linking … tutorial6.elf
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(wpad.o): In function `WPAD_Shutdown’:
      wpad.c:(.text.WPAD_Shutdown+0xbc): undefined reference to `BTE_Shutdown’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(wpad.o): In function `WPAD_Init’:
      wpad.c:(.text.WPAD_Init+0×158): undefined reference to `BTE_Init’
      wpad.c:(.text.WPAD_Init+0×164): undefined reference to `BTE_InitCore’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(wpad.o): In function `__initcore_finished’:
      wpad.c:(.text.__initcore_finished+0×28): undefined reference to `BTE_ReadStoredLinkKey’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(wpad.o): In function `__readlinkkey_finished’:
      wpad.c:(.text.__readlinkkey_finished+0×20): undefined reference to `BTE_ApplyPatch’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(wpad.o): In function `__wpad_patch_finished’:
      wpad.c:(.text.__wpad_patch_finished+0×14): undefined reference to `BTE_InitSub’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(dynamics.o): In function `calc_joystick_state’:
      dynamics.c:(.text.calc_joystick_state+0xa0): undefined reference to `atanf’
      dynamics.c:(.text.calc_joystick_state+0xf0): undefined reference to `sqrt’
      dynamics.c:(.text.calc_joystick_state+0×154): undefined reference to `atanf’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(dynamics.o): In function `calculate_orientation’:
      dynamics.c:(.text.calculate_orientation+0×230): undefined reference to `atan2f’
      dynamics.c:(.text.calculate_orientation+0×25c): undefined reference to `atan2f’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(io_wii.o): In function `wiiuse_io_write’:
      io_wii.c:(.text.wiiuse_io_write+0×28): undefined reference to `bte_sendmessageasync’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(io_wii.o): In function `wiiuse_disconnect’:
      io_wii.c:(.text.wiiuse_disconnect+0×2c): undefined reference to `bte_disconnect’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(io_wii.o): In function `wiiuse_register’:
      io_wii.c:(.text.wiiuse_register+0×38): undefined reference to `bte_new’
      io_wii.c:(.text.wiiuse_register+0×4c): undefined reference to `bte_arg’
      io_wii.c:(.text.wiiuse_register+0×5c): undefined reference to `bte_received’
      io_wii.c:(.text.wiiuse_register+0×6c): undefined reference to `bte_disconnected’
      io_wii.c:(.text.wiiuse_register+0×80): undefined reference to `bte_registerdeviceasync’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(ir.o): In function `calc_yaw’:
      ir.c:(.text.calc_yaw+0×28): undefined reference to `atanf’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(ir.o): In function `apply_ir_smoothing’:
      ir.c:(.text.apply_ir_smoothing+0×3c): undefined reference to `sqrtf’
      ir.c:(.text.apply_ir_smoothing+0xa4): undefined reference to `atan2f’
      ir.c:(.text.apply_ir_smoothing+0xac): undefined reference to `cosf’
      ir.c:(.text.apply_ir_smoothing+0xc8): undefined reference to `sinf’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(ir.o): In function `rotate_dots’:
      ir.c:(.text.rotate_dots+0xa0): undefined reference to `cos’
      ir.c:(.text.rotate_dots+0xb4): undefined reference to `sin’
      c:/devkitPro/libogc/lib/wii\libwiiuse.a(ir.o): In function `find_sensorbar’:
      ir.c:(.text.find_sensorbar+0×5d4): undefined reference to `atan2′
      ir.c:(.text.find_sensorbar+0×624): undefined reference to `atan2′
      ir.c:(.text.find_sensorbar+0×8d4): undefined reference to `atan2′
      collect2: ld returned 1 exit status
      make[1]: *** [/c/devkitpro/examples/gamecube/tutorial6/tutorial6.elf] Error 1
      “make”: *** [build] Error 2

      > Process Exit Code: 2
      > Time Taken: 00:01

  9. Jacic says:

    I bet youre getting tired of me finding errors in your examples, Im sorry, I dont try! This was the error I got from an unchanged example(tutorial6-image)(the first one).

    > “make”
    main.c
    In file included from c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeg/jpgogc.h:12,
    from c:/devkitPro/examples/gamecube/tutorial6/source/main.c:7:
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:66: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘FAR’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:67: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:68: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:70: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JBLOCK’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:71: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘FAR’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:72: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:73: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:75: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘FAR’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:88: error: expected specifier-qualifier-list before ‘UINT16′
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:102: error: expected specifier-qualifier-list before ‘UINT8′
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:139: error: expected specifier-qualifier-list before ‘JDIMENSION’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:193: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:196: error: expected specifier-qualifier-list before ‘jpeg_saved_marker_ptr’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:279: error: expected specifier-qualifier-list before ‘JDIMENSION’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:420: error: expected specifier-qualifier-list before ‘JDIMENSION’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:645: error: expected specifier-qualifier-list before ‘JMETHOD’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:702: error: expected specifier-qualifier-list before ‘JMETHOD’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:714: error: expected specifier-qualifier-list before ‘JOCTET’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:726: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘*’ token
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:758: error: expected specifier-qualifier-list before ‘JMETHOD’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:809: error: expected declaration specifiers or ‘…’ before ‘jpeg_marker_parser_method’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:809: error: expected declaration specifiers or ‘…’ before ‘(‘ token
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h: In function ‘EXTERN’:
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:884: error: expected declaration specifiers before ‘jpeg_std_error’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:900: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:902: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:905: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:906: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:910: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:911: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:912: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:915: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:917: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:919: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:920: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:922: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:925: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:929: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:930: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:931: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:933: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:934: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:937: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:939: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:942: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:945: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:950: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:954: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:956: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:960: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:963: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:976: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:977: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:980: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:983: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:988: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:989: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:991: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:992: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:993: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:994: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1003: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1006: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1011: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1016: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1017: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1019: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1028: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1029: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1034: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1035: error: expected declaration specifiers before ‘EXTERN’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1038: error: expected declaration specifiers before ‘EXTERN’
    In file included from c:/devkitPro/examples/gamecube/tutorial6/source/main.c:7:
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeg/jpgogc.h:25: error: storage class specified for parameter ‘JPEGIMG’
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeg/jpgogc.h:27: error: expected ‘)’ before ‘*’ token
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:9: error: storage class specified for parameter ‘picdata’
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:10: error: storage class specified for parameter ‘piclength’
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:12: error: storage class specified for parameter ‘xfb’
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:13: error: storage class specified for parameter ‘rmode’
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:15: error: expected ‘)’ before ‘jpeg’
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:31: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{‘ token
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:49: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{‘ token
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:60: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{‘ token
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:69: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{‘ token
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:77: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{‘ token
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:121: error: expected declaration specifiers before ‘return’
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:122: error: expected declaration specifiers before ‘}’ token
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:122: error: old-style parameter declarations in prototyped function definition
    c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:884: error: parameter name omitted
    c:/devkitPro/examples/gamecube/tutorial6/source/main.c:122: error: expected ‘{‘ at end of input
    make[1]: *** [main.o] Error 1
    “make”: *** [build] Error 2

    > Process Exit Code: 2
    > Time Taken: 00:00

    I tried finding where it was missing, but with no success.

    • teknecal says:

      Seems like the same issue as last time it seems.

      c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-gekko/4.2.4/../../../../powerpc-gekko/include/jpeglib.h:1016:
      shows the jpeglib.h in the include folder when it should be in the jpeg folder.

      • Jacic says:

        Its better, but now theres this:

        > “make”
        main.c
        c:/devkitPro/examples/gamecube/tutorial6/source/main.c:121: error: expected identifier or ‘(‘ before ‘return’
        c:/devkitPro/examples/gamecube/tutorial6/source/main.c:122: error: expected identifier or ‘(‘ before ‘}’ token
        make[1]: *** [main.o] Error 1
        “make”: *** [build] Error 2

        > Process Exit Code: 2
        > Time Taken: 00:03

        • teknecal says:

          That’s weird. Maybe try changing return 0 to return 1 or removing return 0; all together?

          Also can you try removing various parts of the source, like the while(1) { loop, and try re-compiling, etc?

  10. Jacic says:

    I found the problem! The last ‘}’ in the main.c file shouldnt be there, and neither should “return 0;”. I removed those and it worked.

  11. IceWolf says:

    When I point at the screen and am pressing Button A, there is a wrong position output: “x = -2147892716 y = 1″.

    if (buttonsDown & WPAD_BUTTON_A) {
    printf(“x = %i y = %i\n”, ir.x, ir.y);
    usleep(500000);
    }

    –>
    warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘double’
    warning: format ‘%i’ expects type ‘int’, but argument 3 has type ‘double’
    warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘double’
    warning: format ‘%i’ expects type ‘int’, but argument 3 has type ‘double’

  12. Timptation says:

    There’s something wrong with the display_jpeg function. It doesn’t display the image in the correct place. I’m not sure about the reason for it (something to do with the size of the screen buffer attributes versus the resolution I assume), but it needs to do the same thing that the line drawing functions are, which is the “x >>= 1;” line sometime before the for loops.

  13. Cockmongler says:

    I’m pretty sure %d is decimal integer and %g is double.

  14. yohandris says:

    hey can you make a tutorial on how to display a png file. i looked at the example you showed slash_trax but i dont quite understand it.

    • teknecal says:

      Hi, I won’t do a tutorial on it (as it’s easier to use GRRLIB) but I will give a quick run down on it. If you’ve read the tutorial about displaying JPGs you should be fine.

      Reading though main.c:

      We have the normal variables like in jpg
      extern char toucan[];
      extern int toucanlength;

      Some variables for PNG
      /*** User defined types from pngogc ***/
      PNGWRAPPER png;
      PNG_MEMFILE *mf;

      /*** General ***/
      char *pic; /*** Picture buffer ***/
      int row, col;
      u32 *upic;

      We can skip the rest until this part which opens up the toucan file (shown by toucan.s) like in JPG
      mf = pngmem_fopen(toucan, toucanlength);
      if ( mf == NULL )
      {
      printf(“No memory file!\n”);
      while(1);
      }

      It then decodes the PNG with the following.
      if ( PNG_Decode(mf, &png) == PNGOGC_SUCCESS )
      {
      pic = (char *)malloc(png.height * png.width * 2);
      upic = (u32 *)pic;
      RGB24toYUY2(png.image, png.width, png.height, pic, png.width * 2);

      You can ignore that offset two lines (centring image).

      Then we come to the below which tells it where to draw the PNG file. If you put offset to 50, it will move it 50 pixels to the right, etc.
      int offsetx = 0;
      int offsety = 0;

      int i,j;
      for(i=0;i<=(png.width-(png.width/2)-1);i++)
      for(j=1;j<=png.height-2;j++)
      xfb[0][(i+offsetx)+320*(j+16+offsety)]=upic[i+(png.width-(png.width/2))*j];

      Then just clearing up the PNG memory.
      free(pic);
      PNG_Clear(&png);
      pngmem_fclose(mf);

      • yohandris says:

        ok i understand it now but i need the libraries

        • yohandris says:

          ohh wait i see were you put the link now.

          • yohandris says:

            ok i got a problem now. when i try to compile your display_png file it gives me this error

            > “make”
            main.c
            c:/Users/yohandris/Desktop/display_png/source/main.c: In function ‘main’:
            c:/Users/yohandris/Desktop/display_png/source/main.c:135: warning: assignment from incompatible pointer type
            c:/Users/yohandris/Desktop/display_png/source/main.c:142: warning: pointer targets in passing argument 1 of ‘RGB24toYUY2′ differ in signedness
            c:devkitprodevkitppcbin../lib/gcc/powerpc-eabi/4.4.2/../../../../powerpc-eabi/include/png/huffyuv.h:7: note: expected ‘char *’ but argument is of type ‘unsigned char *’
            c:/Users/yohandris/Desktop/display_png/source/main.c:188: warning: pointer targets in passing argument 2 of ‘YUY2toRGB24′ differ in signedness
            c:devkitprodevkitppcbin../lib/gcc/powerpc-eabi/4.4.2/../../../../powerpc-eabi/include/png/huffyuv.h:8: note: expected ‘u8 *’ but argument is of type ‘char *’
            Compiling … toucan.s
            linking … display_png.elf
            output … display_png.dol

            > Process Exit Code: 0
            > Time Taken: 00:02

            any ideas? also how do i use grrlib? i can’t find out how to install it

            • teknecal says:

              That’s all fine, probably has to do with the new compiler version that DevKitPPC uses (r17 to r19). It has actually compiled the dol and elf file. Run the dol with gcube and you’ll see it work.

              For GRRLIB install:
              First thing is to run that install.bat found in GRRLIB\GRRLIB\lib.
              Second thing is to open up CMD (Start -> Run, type cmd.exe), then navigate to the GRRLIB\GRRLIB\GRRLIB directory (e.g. cd GRRLIB\GRRLIB\GRRLIB) that contains a file called “Makefile”. Type in “make clean all install”, hit enter and it should be good to go.

              You should then take a look into some of the examples that’s included with GRRLIB, some are a bit complex so try to find the easy ones.

  15. yohandris says:

    Hello teknecal, how would you acces the wiimote’s accelerometer? Is their anyway to use the wii speak and the motion plus gyroscope?

    Also grrlib is working great for me and without any problems and it really made things easier. It took me a while to figure out that im suppososed to use raw2c on my images but im all good now. Maybe you should make a tutorial on it because the examples were a bit confusing and not exact and i had to trial and error what was rot, scale, position, and that i had to change the makefile to include the gfx folder.

    Do you think a tutorial on using internet access would be to complicated?

  16. yohandris says:

    ok thanks i got it from here

    • yohandris says:

      You added a extra WPAD_ in WPAD_WPAD_Accel(0, &accel);
      Just saying in case someone trys to use that.

Leave a Reply