static int plugin_main(void)
{
    int button, avg_peak, t_disp=0;
    int font_h, font_w;
    bool pulse __attribute__ ((unused)) = true; /* 'unused' resolves warnings */
    rb->lcd_getstringsize("A", &font_w, &font_h);
    starfield_init(&starfield);
    starfield_add_stars(&starfield, INIT_STARS);

#if LCD_DEPTH > 1
     rb->lcd_set_backdrop(NULL);
#endif
#ifdef HAVE_LCD_COLOR
    rb->lcd_set_background(LCD_BLACK);
    rb->lcd_set_foreground(LCD_WHITE);
#endif

    while (true)
    {
        rb->sleep(1);
        rb->lcd_clear_display();

#if ((CONFIG_CODEC == SWCODEC)  || !defined(SIMULATOR) && \
    ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)))

        /* This will make the stars pulse to the music */
        if(pulse){

            /* Get the peaks. ( Borrowed from vu_meter ) */
#if (CONFIG_CODEC == SWCODEC)
            int left_peak, right_peak;
            rb->mixer_channel_calculate_peaks(PCM_MIXER_CHAN_PLAYBACK,
                                              &left_peak, &right_peak);
#else
            int left_peak = rb->mas_codec_readreg(0xC);
            int right_peak = rb->mas_codec_readreg(0xD);
#endif
            /* Devide peak data by 4098 to bring the max
               value down from ~32k to 8 */
            left_peak  =    left_peak/0x1000;
            right_peak =    right_peak/0x1000;

            /* Make sure they dont stop */
            if(left_peak<0x1)
                left_peak     = 0x1;
            if(right_peak<0x1)
                right_peak    = 0x1;

            /* And make sure they dont go over 8 */
            if(left_peak>0x8)
                left_peak     = 0x8;
            if(right_peak>0x8)
                right_peak    = 0x8;

            /* We need the average of both chanels */
            avg_peak     = ( left_peak + right_peak )/2;

            /* Set the speed to the peak meter */
            starfield.z_move = avg_peak;

        } /* if pulse */
#else
        (void) avg_peak;
#endif
        starfield_move_and_draw(&starfield);

#ifdef HAVE_LCD_COLOR
        rb->lcd_set_foreground(LCD_WHITE);
#endif

        /* if a parameter is updated (by the user), we must print it */
        if (t_disp > 0)
        {
            --t_disp;
#ifdef HAVE_LCD_COLOR
            rb->lcd_set_foreground(LCD_WHITE);
#endif
            rb->lcd_putsxyf(0, LCD_HEIGHT-font_h, "star:%d speed:%d",
                           starfield.nb_stars, starfield.z_move);
        }
        rb->lcd_update();

        button = rb->button_get(false);
        switch(button)
        {
            case (STARFIELD_INCREASE_ZMOVE):
            case (STARFIELD_INCREASE_ZMOVE | BUTTON_REPEAT):
                ++(starfield.z_move);
                pulse=false;
                t_disp=MSG_DISP_TIME;
                break;
            case (STARFIELD_DECREASE_ZMOVE):
            case (STARFIELD_DECREASE_ZMOVE | BUTTON_REPEAT):
                --(starfield.z_move);
                pulse=false;
                t_disp=MSG_DISP_TIME;
                break;
            case(STARFIELD_INCREASE_NB_STARS):
            case(STARFIELD_INCREASE_NB_STARS | BUTTON_REPEAT):
                starfield_add_stars(&starfield, STARFIELD_INCREASE_STEP);
                t_disp=MSG_DISP_TIME;
                break;
            case(STARFIELD_DECREASE_NB_STARS):
            case(STARFIELD_DECREASE_NB_STARS | BUTTON_REPEAT):
                starfield_del_stars(&starfield, STARFIELD_INCREASE_STEP);
                t_disp=MSG_DISP_TIME;
                break;
#ifdef HAVE_LCD_COLOR
            case(STARFIELD_TOGGLE_COLOR):
                starfield.color=!starfield.color;
                break;
#endif
#ifdef STARFIELD_RC_QUIT
            case STARFIELD_RC_QUIT:
#endif
            case(STARFIELD_QUIT):
                return PLUGIN_OK;
                break;
            default:
                exit_on_usb(button);
                break;
        }
    }
}
예제 #2
0
int main()
{
    initGraphics();
    SceCtrlData pad, pad_old;
    sceCtrlReadBufferPositive(&pad_old, 1);
    
    starfield.nb_stars = 0;
    starfield.z_move = 1;
    starfield_add_stars(&starfield, 600);
    
    while(1) {
    	fillScreenRect(RGB(0, 0, 0), 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

      starfield_move_and_draw(&starfield);
	  Print(0,0,RGB(255, 255, 255),"StarField - Ported to the TIFF exploit by BlackSith");
	  Print(2,1,RGB(255, 255, 255),"Originally ported to the PSP by Karmon");
	  Print(0,30,RGB(255, 255, 255),"..Press Start to Exit..");

      //char str_buffer[40];
      if(t_disp > 0)
      {
         t_disp--;
         //sprintf(str_buffer, sizeof(str_buffer), "Stars:%d \nSpeed:%d", starfield.nb_stars, starfield.z_move);
         //print(3, SCREEN_HEIGHT-10, RGB(255, 255, 255), str_buffer);
      }

      /*if(frame == 0)
      {
         gettimeofday(&tv, NULL);
         start_fps = tv.tv_sec;
      }

      if(show_fps > 0)
      {
         gettimeofday(&tv, NULL);
         //snprintf(str_buffer, sizeof(str_buffer), "FPS: %ld", frame/(tv.tv_sec-start_fps+1));
         //printTextScreen(3, 3, str_buffer, RGB(255, 255, 255));
      }*/
      frame++;
    
      sceCtrlReadBufferPositive(&pad, 1);
      if(pad.Buttons != pad_old.Buttons){
      	pad_old = pad;
        if(pad.Buttons & PSP_CTRL_UP) {
          starfield.z_move++;
          t_disp = MSG_DISP_TIME;
      } else if(pad.Buttons & PSP_CTRL_DOWN) {
          starfield.z_move--;
          t_disp = MSG_DISP_TIME;
        }
        if(pad.Buttons & PSP_CTRL_RIGHT) {
          starfield_add_stars(&starfield, 100);
          t_disp=MSG_DISP_TIME;
      } else if(pad.Buttons & PSP_CTRL_LEFT) {
          starfield_del_stars(&starfield, 100);
          t_disp=MSG_DISP_TIME;
        }
        if(pad.Buttons & PSP_CTRL_CROSS) {
          if(show_fps > 0)
            show_fps--;
          else
            show_fps++;
			  }
			}
			flipScreen();
			sceDisplayWaitVblankStart();
		if(pad.Buttons & PSP_CTRL_START) { vshKernelExitVSHVSH(0); }
		}

    //sceKernelSleepThread();
    return(0);
}