4.6 The basic4 Sample Program

The basic4 sample program utilizes the functions explained in this chapter to implement an application with a simple menu.

The program has two modes: the menu mode and the animation mode. The program runs in menu mode when the static variable IsMenuMode in the Draw function of graphic.c is set to 1. When this variable is set to 0, the program runs in animation mode.

Animation mode
This mode draws moving rectangles using the same rendering routine used in the basic3 program, with almost no modifications. However, you can also change the color of the rectangle when in menu mode. You can switch to menu mode by pressing the Start button.

Menu mode
This mode displays the menu for selecting a color for the rectangle displayed in animation mode. Choose between red, green and blue by pressing RIGHT/LEFT on the Control Pad. When you press the Start button, the mode switches to animation mode.

A variety of debug console functions are utilized to display the menu in this sample program, so if you want to see an example of actual usage of the debug console, we recommend you look through graphic.c. The basic4 sample program also contains a routine for Controller input. The process is not very difficult, so you should be able to comprehend things by reading the sample source. To learn more about the Controller, see the relevant chapter in the Device Tutorial. This chapter's sample program is written not only to draw rectangles, but also to display the debug console and the performance meter. Ultimately, it is the Draw function in graphic.c that instructs NuSystem to render these.

List 4-1 See basic4 "graphic.c"

  /* Activate a task for rendering a rectangle (no swap) */
                (s32)(glistp - glist) * sizeof(Gfx),

  /* Display the menu if in menu mode */

  /* Controller process */
  HandleController(&IsMenuMode, &RectColor);

  /* Display the performance meter */
  nuDebTaskPerfBar1(1, 210, NU_SC_SWAPBUFFER);

Important here is that the last argument in both nuGfxTaskStart and nuDebConDisp is NU_SC_NOSWAPBUFFER. If you do not suppress swapping with this argument, then the framebuffer will be swapped when the rendering of the rectangle or the debug console has been completed. As a result, when you call nuDebTaskPerfBar1, the performance meter will be displayed in a different framebuffer than the rectangle or the debug console.