コード例 #1
0
enum plugin_status plugin_start(const void* parameter)
{
    int action, i;
    struct jackpot game;
    (void)parameter;
    atexit(jackpot_exit);
    rb->srand(*rb->current_tick);
#ifdef HAVE_LCD_CHARCELLS
    patterns_init(rb->screens[SCREEN_MAIN]);
#endif /* HAVE_LCD_CHARCELLS */
    jackpot_init(&game);

    FOR_NB_SCREENS(i){
        rb->screens[i]->clear_display();
        jackpot_display_slot_machine(&game, rb->screens[i]);
    }
    /*Empty the event queue*/
    rb->button_clear_queue();
    while (true)
    {
        action = pluginlib_getaction(TIMEOUT_BLOCK,
                                plugin_contexts, ARRAYLEN(plugin_contexts));
        switch ( action )
        {
            case PLA_CANCEL:
                return PLUGIN_OK;
            case PLA_SELECT:
                jackpot_play_turn(&game);
                break;

            default:
                exit_on_usb(action);
                break;
        }
    }
    return PLUGIN_OK;
}
コード例 #2
0
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;
        }
    }
}
コード例 #3
0
ファイル: test_fps.c プロジェクト: 4nykey/rockbox
static void time_greyscale(void)
{
    char str[32];     /* text buffer */
    long time_start;  /* start tickcount */
    long time_end;    /* end tickcount */
    long time_1, time_2;
    int frames_1, frames_2;
    int fps, load;
    size_t gbuf_size;
    unsigned char *gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);

#if NUM_CORES > 1
    int i;
    for (i = 0; i < NUM_CORES; i++)
    {
        rb->snprintf(str, sizeof(str), "Greyscale (%s)",
                     (i > 0) ? "COP" : "CPU");
        log_text(str);
#else
    const int i = 0;
    log_text("Greyscale library");
    {
#endif

        if (!grey_init(gbuf, gbuf_size, (i > 0) ? GREY_ON_COP : 0,
                       LCD_WIDTH, LCD_HEIGHT, NULL))
        {
            log_text("greylib: out of memory.");
            return;
        }
        make_grey_rect(LCD_WIDTH, LCD_HEIGHT);

        /* Test 1 - greyscale overlay not yet enabled */
        frames_1 = 0;
        rb->sleep(0); /* sync to tick */
        time_start = *rb->current_tick;
        while((time_end = *rb->current_tick) - time_start < DURATION)
        {
            grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
            frames_1++;
        }
        time_1 = time_end - time_start;
    
        /* Test 2 - greyscale overlay enabled */
        grey_show(true);
        frames_2 = 0;
        rb->sleep(0); /* sync to tick */
        time_start = *rb->current_tick;
        while((time_end = *rb->current_tick) - time_start < DURATION)
        {
            grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
            frames_2++;
        }
        time_2 = time_end - time_start;

        grey_release();
        fps = calc_tenth_fps(frames_2, time_2);
        load = 100 - (100 * frames_2 * time_1) / (frames_1 * time_2);
        rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
        log_text(str);

        if (load > 0 && load < 100)
        {
            rb->snprintf(str, sizeof(str), "CPU load: %d%%", load);
            log_text(str);
        }
        else
            log_text("CPU load err (boost?)");
    }
}
#endif

void plugin_quit(void)
{
#ifdef HAVE_TOUCHSCREEN
    static struct touchbutton button[] = {{
            .action = ACTION_STD_OK,
            .title = "OK",
            /* .vp runtime initialized, rest false/NULL */
    }};
    struct viewport *vp = &button[0].vp;
    struct screen *lcd = rb->screens[SCREEN_MAIN];
    rb->viewport_set_defaults(vp, SCREEN_MAIN);
    const int border = 10;
    const int height = 50;

    lcd->set_viewport(vp);
    /* button matches the bottom center in the grid */
    vp->x = lcd->lcdwidth/3;
    vp->width = lcd->lcdwidth/3;
    vp->height = height;
    vp->y = lcd->lcdheight - height - border;

    touchbutton_draw(button, ARRAYLEN(button));
    lcd->update_viewport();
    if (rb->touchscreen_get_mode() == TOUCHSCREEN_POINT)
    {
        while(touchbutton_get(button, ARRAYLEN(button)) != ACTION_STD_OK);
    }
    else
#endif
        while (1)
        {
            int btn = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts,
                                                   ARRAYLEN(plugin_contexts));
            exit_on_usb(btn);
            if ((btn == FPS_QUIT) || (btn == FPS_QUIT2))
                break;
        }
}
コード例 #4
0
enum plugin_status plugin_start(const void* parameter)
{
    long lastbutton = BUTTON_NONE;
    int redraw = REDRAW_FULL;
    struct fractal_ops *ops = &mandelbrot_ops;

    (void)parameter;

#ifdef USEGSLIB
    /* get the remainder of the plugin buffer */
    gbuf = (unsigned char *)rb->plugin_get_buffer(&gbuf_size);

    /* initialize the greyscale buffer.*/
    if (!grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL))
    {
        rb->splash(HZ, "Couldn't init greyscale display");
        return PLUGIN_ERROR;
    }
    grey_show(true); /* switch on greyscale overlay */
#endif

    /* release greylib on exit */
    atexit(cleanup);
#if LCD_DEPTH > 1
    rb->lcd_set_backdrop(NULL);
#endif

    ops->init();

    /* main loop */
    while (true)
    {
        long button = BUTTON_NONE;

        if (redraw != REDRAW_NONE)
        {
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
            rb->cpu_boost(true);
#endif
            switch (redraw)
            {
                case REDRAW_FULL:
                    mylcd_ub_clear_display();
                    mylcd_ub_update();
                    /* fall-through */
                case REDRAW_FULL_OVERLAY:
                    rects_queue_init();
                    break;
                default:
                    break;
            }

            /* paint all rects */
            rects_calc_all(ops->calc, button_yield, (void *)&button);
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
            rb->cpu_boost(false);
#endif
            /* not interrupted by button press - screen is fully drawn */
            redraw = (button == BUTTON_NONE) ? REDRAW_NONE : REDRAW_PARTIAL;
        }

        if (button == BUTTON_NONE)
            button = rb->button_get(true);

        switch (button)
        {
#ifdef FRACTAL_RC_QUIT
        case FRACTAL_RC_QUIT:
#endif
        case FRACTAL_QUIT:
            return PLUGIN_OK;

        case FRACTAL_ZOOM_OUT:
#ifdef FRACTAL_ZOOM_OUT_PRE
            if (lastbutton != FRACTAL_ZOOM_OUT_PRE)
                break;
#endif
            if (!ops->zoom(-1))
                redraw = REDRAW_FULL;
            break;


        case FRACTAL_ZOOM_IN:
#ifdef FRACTAL_ZOOM_IN_PRE
            if (lastbutton != FRACTAL_ZOOM_IN_PRE)
                break;
#endif
#ifdef FRACTAL_ZOOM_IN2
        case FRACTAL_ZOOM_IN2:
#endif
            if (!ops->zoom(1))
                redraw = REDRAW_FULL;
            break;

        case FRACTAL_UP:
            ops->move(0, +1);
            mylcd_ub_scroll_down(LCD_SHIFT_Y);
            mylcd_ub_update();
            if (redraw != REDRAW_FULL)
                redraw = rects_move_down() ? REDRAW_FULL : REDRAW_PARTIAL;
            break;

        case FRACTAL_DOWN:
            ops->move(0, -1);
            mylcd_ub_scroll_up(LCD_SHIFT_Y);
            mylcd_ub_update();
            if (redraw != REDRAW_FULL)
                redraw = rects_move_up() ? REDRAW_FULL : REDRAW_PARTIAL;
            break;

        case FRACTAL_LEFT:
            ops->move(-1, 0);
            mylcd_ub_scroll_right(LCD_SHIFT_X);
            mylcd_ub_update();
            if (redraw != REDRAW_FULL)
                redraw = rects_move_right() ? REDRAW_FULL : REDRAW_PARTIAL;
            break;

        case FRACTAL_RIGHT:
            ops->move(+1, 0);
            mylcd_ub_scroll_left(LCD_SHIFT_X);
            mylcd_ub_update();
            if (redraw != REDRAW_FULL)
                redraw = rects_move_left() ? REDRAW_FULL : REDRAW_PARTIAL;
            break;

        case FRACTAL_PRECISION_DEC:
#ifdef FRACTAL_PRECISION_DEC_PRE
            if (lastbutton != FRACTAL_PRECISION_DEC_PRE)
                break;
#endif
            if (ops->precision(-1))
                redraw = REDRAW_FULL_OVERLAY;

            break;

        case FRACTAL_PRECISION_INC:
#ifdef FRACTAL_PRECISION_INC_PRE
            if (lastbutton != FRACTAL_PRECISION_INC_PRE)
                break;
#endif
            if (ops->precision(+1))
                redraw = REDRAW_FULL_OVERLAY;

            break;

        case FRACTAL_RESET:
            ops->init();
            redraw = REDRAW_FULL;
            break;

        default:
            exit_on_usb(button);
            break;
        }

        if (button != BUTTON_NONE)
            lastbutton = button;
    }
    return PLUGIN_OK;
}
コード例 #5
0
ファイル: text_viewer.c プロジェクト: ntj/rockbox
enum plugin_status plugin_start(const void* file)
{
    int button;
    int lastbutton = BUTTON_NONE;
    bool autoscroll = false;
    long old_tick;
    bool done = false;
    bool display_update = true;
    size_t size;
    unsigned char *plugin_buf;

    old_tick = *rb->current_tick;

    if (!file)
        return PLUGIN_ERROR;

    /* get the plugin buffer */
    plugin_buf = rb->plugin_get_buffer(&size);

    if (!tv_init_action(&plugin_buf, &size)) {
        rb->splash(HZ, "Error initialize");
        return PLUGIN_ERROR;
    }

    if (!tv_load_file(file)) {
        rb->splash(HZ, "Error opening file");
        return PLUGIN_ERROR;
    }

    atexit(tv_exit);
    while (!done) {
#ifdef HAVE_LCD_BITMAP
        if (preferences->statusbar)
            rb->send_event(GUI_EVENT_ACTIONUPDATE, NULL);
#endif

        if (display_update)
            tv_draw();

        display_update = true;

        button = rb->button_get_w_tmo(HZ/10);

        switch (button) {
            case TV_MENU:
#ifdef TV_MENU2
            case TV_MENU2:
#endif
                {
                    unsigned res = tv_menu();

                    if (res != TV_MENU_RESULT_EXIT_MENU)
                    {
                        if (res == TV_MENU_RESULT_ATTACHED_USB)
                            return PLUGIN_USB_CONNECTED;
                        else if (res == TV_MENU_RESULT_ERROR)
                            return PLUGIN_ERROR;
                        else
                            done = true;
                    }
                }
                break;

            case TV_AUTOSCROLL:
#ifdef TV_AUTOSCROLL_PRE
                if (lastbutton != TV_AUTOSCROLL_PRE)
                    break;
#endif
                autoscroll = !autoscroll;
                break;

            case TV_SCROLL_UP:
            case TV_SCROLL_UP | BUTTON_REPEAT:
#ifdef TV_SCROLL_UP2
            case TV_SCROLL_UP2:
            case TV_SCROLL_UP2 | BUTTON_REPEAT:
#endif
                tv_scroll_up(TV_VERTICAL_SCROLL_PREFS);
                old_tick = *rb->current_tick;
                break;

            case TV_SCROLL_DOWN:
            case TV_SCROLL_DOWN | BUTTON_REPEAT:
#ifdef TV_PAGE_DOWN2
            case TV_SCROLL_DOWN2:
            case TV_SCROLL_DOWN2 | BUTTON_REPEAT:
#endif
                tv_scroll_down(TV_VERTICAL_SCROLL_PREFS);
                old_tick = *rb->current_tick;
                break;

            case TV_SCREEN_LEFT:
            case TV_SCREEN_LEFT | BUTTON_REPEAT:
                if (preferences->windows > 1)
                {
                    /* Screen left */
                    tv_scroll_left(TV_HORIZONTAL_SCROLL_PREFS);
                }
                else {   /* prefs->windows == 1 */
                    if (preferences->narrow_mode == NM_PAGE)
                    {
                        /* scroll to previous page */
                        tv_scroll_up(TV_VERTICAL_SCROLL_PAGE);
                    }
                    else
                    {
                        /* Top of file */
                        tv_top();
                    }
                }
                break;

            case TV_SCREEN_RIGHT:
            case TV_SCREEN_RIGHT | BUTTON_REPEAT:
                if (preferences->windows > 1)
                {
                    /* Screen right */
                    tv_scroll_right(TV_HORIZONTAL_SCROLL_PREFS);
                }
                else {   /* prefs->windows == 1 */
                    if (preferences->narrow_mode == NM_PAGE)
                    {
                        /* scroll to next page */
                        tv_scroll_down(TV_VERTICAL_SCROLL_PAGE);
                    }
                    else
                    {
                        /* Bottom of file */
                        tv_bottom();
                    }
                }
                break;

#ifdef TV_LINE_UP
            case TV_LINE_UP:
            case TV_LINE_UP | BUTTON_REPEAT:
                /* Scroll up one line */
                tv_scroll_up(TV_VERTICAL_SCROLL_LINE);
                old_tick = *rb->current_tick;
                break;

            case TV_LINE_DOWN:
            case TV_LINE_DOWN | BUTTON_REPEAT:
                /* Scroll down one line */
                tv_scroll_down(TV_VERTICAL_SCROLL_LINE);
                old_tick = *rb->current_tick;
                break;
#endif
#ifdef TV_COLUMN_LEFT
            case TV_COLUMN_LEFT:
            case TV_COLUMN_LEFT | BUTTON_REPEAT:
                /* Scroll left one column */
                tv_scroll_left(TV_HORIZONTAL_SCROLL_COLUMN);
                break;

            case TV_COLUMN_RIGHT:
            case TV_COLUMN_RIGHT | BUTTON_REPEAT:
                /* Scroll right one column */
                tv_scroll_right(TV_HORIZONTAL_SCROLL_COLUMN);
                break;
#endif

#ifdef TV_RC_QUIT
            case TV_RC_QUIT:
#endif
            case TV_QUIT:
#ifdef TV_QUIT2
            case TV_QUIT2:
#endif
                done = true;
                break;

            case TV_BOOKMARK:
                tv_add_or_remove_bookmark();
                break;

            default:
                exit_on_usb(button);
                display_update = false;
                break;
        }
        if (button != BUTTON_NONE)
        {
            lastbutton = button;
            rb->yield();
        }
        if (autoscroll)
        {
            if(old_tick <= *rb->current_tick - (110 - preferences->autoscroll_speed * 10))
            {
                tv_scroll_down(TV_VERTICAL_SCROLL_PREFS);
                old_tick = *rb->current_tick;
                display_update = true;
            }
        }
    }
    return PLUGIN_OK;
}
コード例 #6
0
/**********************************************************************
 * Plugin starts here
 **********************************************************************/
enum plugin_status plugin_start(const void* parameter){
    int button;
    int last_second = -1;
    bool redraw=true;
    struct time time;
    struct counter counter;
    bool exit_clock = false;
    (void)parameter;
    atexit(cleanup);

#if LCD_DEPTH > 1
    rb->lcd_set_backdrop(NULL);
#endif

    load_settings();

    /* init xlcd functions */
    counter_init(&counter);
    clock_draw_set_colors();

    while(!exit_clock){
        clock_update_time(&time);

        if(!clock_settings.general.idle_poweroff)
            rb->reset_poweroff_timer();

        /*************************
         * Scan for button presses
         ************************/
        button =  pluginlib_getaction(HZ/10, plugin_contexts, PLA_ARRAY_COUNT);
        redraw=true;/* we'll set it to false afterwards if there was no action */
        switch (button){
            case ACTION_COUNTER_TOGGLE: /* start/stop counter */
                if(clock_settings.general.show_counter)
                    counter_toggle(&counter);
                break;

            case ACTION_COUNTER_RESET: /* reset counter */
                if(clock_settings.general.show_counter)
                    counter_reset(&counter);
                break;

            case ACTION_MODE_NEXT_REPEAT:
            case ACTION_MODE_NEXT:
                clock_settings.mode++;
                if(clock_settings.mode >= NB_CLOCK_MODES)
                    clock_settings.mode = 0;
                break;

            case ACTION_MODE_PREV_REPEAT:
            case ACTION_MODE_PREV:
                clock_settings.mode--;
                if(clock_settings.mode < 0)
                    clock_settings.mode = NB_CLOCK_MODES-1;
                break;
            case ACTION_SKIN_PREV_REPEAT:
            case ACTION_SKIN_PREV:
                clock_settings_skin_next(&clock_settings);
                break;
            case ACTION_SKIN_NEXT_REPEAT:
            case ACTION_SKIN_NEXT:
                clock_settings_skin_previous(&clock_settings);
                break;
            case ACTION_MENU:
                clock_draw_restore_colors();
                exit_clock=main_menu();
                break;
            default:
                exit_on_usb(button);
                if(time.second != last_second){
                    last_second=time.second;
                    redraw=true;
                }else
                    redraw=false;
                break;
        }

        if(redraw){
            clock_draw_set_colors();
            FOR_NB_SCREENS(i)
                clock_draw(rb->screens[i], &time, &counter);
            redraw=false;
        }
    }

    return PLUGIN_OK;
}
コード例 #7
0
int main(void)
{
    plasma_frequency = 1;
    int action, x, y;
    unsigned char p1,p2,p3,p4,t1,t2,t3,t4, z,z0;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
    long last_tick = *rb->current_tick;
    int delay;
    int cumulated_lag = 0;
#endif
#ifdef HAVE_LCD_COLOR
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
    unsigned char *ptr;
#else
    fb_data *ptr;
#endif
    int time=0;
#else
    unsigned char *ptr;
#endif

    /*Generate the neccesary pre calced stuff*/
    wave_table_generate();

#ifndef HAVE_LCD_COLOR
    shades_generate();  /* statically */

    /* get the remainder of the plugin buffer */
    gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);

    if (!grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL))
    {
        rb->splash(HZ, "Couldn't init greyscale display");
        return PLUGIN_ERROR;
    }
    /* switch on greyscale overlay */
    grey_show(true);
#endif
    atexit(cleanup);
    sp1 = 4;
    sp2 = 2;
    sp3 = 4;
    sp4 = 2;
    p1=p2=p3=p4=0;
    while (true)
    {
#ifdef HAVE_LCD_COLOR
        shades_generate(time++); /* dynamically */
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
        ptr = (unsigned char*)rb->lcd_framebuffer;
#else
        ptr = rb->lcd_framebuffer;
#endif

#else
        ptr = greybuffer;
#endif
        t1=p1;
        t2=p2;
        for(y = 0; y < LCD_HEIGHT; ++y)
        {
            t3=p3;
            t4=p4;
            z0 = wave_array[t1] + wave_array[t2];
            for(x = 0; x < LCD_WIDTH; ++x)
            {
                z = z0 + wave_array[t3] + wave_array[t4];
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
                *ptr++ = z;
#else
                *ptr++ = colours[z];
#endif
                t3+=1;
                t4+=2;
            }
            t1+=2;
            t2+=1;
            rb->yield();
        }
        p1+=sp1;
        p2-=sp2;
        p3+=sp3;
        p4-=sp4;
#ifdef HAVE_LCD_COLOR
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
        rb->lcd_blit_pal256(    (unsigned char*)rb->lcd_framebuffer,
                                0,0,0,0,LCD_WIDTH,LCD_HEIGHT);
#else
        rb->lcd_update();
#endif
#else
        grey_ub_gray_bitmap(greybuffer, 0, 0, LCD_WIDTH, LCD_HEIGHT);
#endif

#ifdef HAVE_ADJUSTABLE_CPU_FREQ
        delay = last_tick - *rb->current_tick + HZ/33;
        if (!boosted && delay < 0)
        {
            cumulated_lag -= delay;     /* proportional increase */
            if (cumulated_lag >= HZ)
                rb->cpu_boost(boosted = true);
        }
        else if (boosted && delay > 1)  /* account for jitter */
        {
            if (--cumulated_lag <= 0)   /* slow decrease */
                rb->cpu_boost(boosted = false);
        }
        last_tick = *rb->current_tick;
#endif
        action = pluginlib_getaction(0, plugin_contexts,
                        ARRAYLEN(plugin_contexts));

        switch(action)
        {
            case PLA_EXIT:
            case PLA_CANCEL:
                return PLUGIN_OK;
                break;

#ifdef HAVE_SCROLLWHEEL
            case PLA_SCROLL_FWD:
            case PLA_SCROLL_FWD_REPEAT:
#endif
            case PLA_UP:
            case PLA_UP_REPEAT:
                ++plasma_frequency;
                wave_table_generate();
                break;

#ifdef HAVE_SCROLLWHEEL
            case PLA_SCROLL_BACK:
            case PLA_SCROLL_BACK_REPEAT:
#endif
            case PLA_DOWN:
            case PLA_DOWN_REPEAT:
                if(plasma_frequency>1)
                {
                    --plasma_frequency;
                    wave_table_generate();
                }
                break;
#ifdef HAVE_LCD_COLOR
            case PLA_SELECT:
                redfactor=rb->rand()%4;
                greenfactor=rb->rand()%4;
                bluefactor=rb->rand()%4;
                redphase=rb->rand()%256;
                greenphase=rb->rand()%256;
                bluephase=rb->rand()%256;
                break;
#endif

            default:
                exit_on_usb(action);
                break;
        }
    }
}
コード例 #8
0
ファイル: nim.c プロジェクト: 4nykey/rockbox
/* this is the plugin entry point */
enum plugin_status plugin_start(const void* parameter)
{
    int y,z,button;
    int x,v,min;
    bool ok;
    bool go;
    atexit(nim_exit);

    /* if you don't use the parameter, you can do like
       this to avoid the compiler warning about it */
    (void)parameter;

    /*Get the pattern handle*/
    h1=rb->lcd_get_locked_pattern();
    h2=rb->lcd_get_locked_pattern();
    hcry=rb->lcd_get_locked_pattern();
    hsmile=rb->lcd_get_locked_pattern();


    rb->splash(HZ, "NIM V1.2");
    rb->lcd_clear_display();

    /* Main loop */
    while (1)
    {
        /* Init */
        x=21;
        v=1;
        y=1;
        end=false;
        min=0;

        /*Empty the event queue*/
        rb->button_clear_queue();

        /* Game loop */
        while(end!=true)
        {
            do
            {
                ok=1;
                y=1;
                display_first_line(x);

                rb->lcd_putsf(0,1,"[%d..%d]?=%d",min,v,y);
                rb->lcd_update();

                go=false;
                while (!go)
                {
                    button = rb->button_get(true);
                    switch ( button )
                    {
                        case BUTTON_STOP|BUTTON_REL:
                            go = true;
                            return PLUGIN_OK;
                            break;

                        case BUTTON_PLAY|BUTTON_REL:
                            go=true;
                            break;

                        case BUTTON_LEFT|BUTTON_REL:
                            go=false;
                            if (y>min)
                                y--;
                            break;

                        case BUTTON_RIGHT|BUTTON_REL:
                            go=false;
                            if (y<v)
                                y++;
                            break;

                        default:
                            exit_on_usb(button);
                            break;
                    }
                    display_first_line(x);
                    rb->lcd_putsf(0,1,"[%d..%d]?=%d",min,v,y);
                    rb->lcd_update();
                }

                if ( (y==0) && (x<21))
                {
                    impossible();
                    ok=false;
                }
                else
                {
                    if (y!=0) /*If y=0 and x=21 jump to CPU code */
                    {
                        if ((y>v) || (y>x))
                        {
                            impossible();
                            ok=false;
                        }
                        if (y-x==0)
                            win();
                        else
                        {
                            v=y*2;
                            x-=y;
                        }
                    }
                }
            }
            while (ok==false);

            display_first_line(x);

            /*CPU*/
            if (x==1)
                lose();
            else
                if (x==2)
                    win();
            y=0;
            if (end==false)
            {
                for (z=v;z>=1;z--)
                {
                    if (x-z==1)
                        y=z;
                }
                if (y<=0)
                {
                    for(z=v;z>=1;z--)
                    {
                        if(x-(z*3)==2)
                            y=z;
                    }
                    if ((y==0) && (x>14))
                        y=v;
                    if (y==0)
                        y=1;
                }
                v=y*2;
                x-=y;
                rb->lcd_putsf(0,1,"I take=%d",y);
                rb->lcd_update();
                rb->sleep(HZ);
            }
            if ((x==1)&&(!end))
                win();
            min=1;
        }
    }
    return PLUGIN_OK;
}
コード例 #9
0
ファイル: greyscale.c プロジェクト: Rockbox/rockbox
/* this is only a demo of what the framework can do */
int main(void)
{
    int time;
    int x, y, i;
    int button, scroll_amount;
    bool black_border = false;

    static const unsigned char rockbox[] = {
    /* ...........................................
     * .####...###...###..#...#.####...###..#...#.
     * .#...#.#...#.#...#.#..#..#...#.#...#..#.#..
     * .####..#...#.#.....###...####..#...#...#...
     * .#..#..#...#.#...#.#..#..#...#.#...#..#.#..
     * .#...#..###...###..#...#.####...###..#...#.
     * ...........................................
     * 43 x 7 pixel, 1 bpp
     */
       0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22,
       0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E,
       0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14,
       0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08,
       0x14, 0x22, 0x00
    };
    
    static const unsigned char showing[] = {
    /* .......................................
     * ..####.#...#..###..#...#.#.#...#..####.
     * .#.....#...#.#...#.#...#.#.##..#.#.....
     * ..###..#####.#...#.#.#.#.#.#.#.#.#..##.
     * .....#.#...#.#...#.#.#.#.#.#..##.#...#.
     * .####..#...#..###...#.#..#.#...#..####.
     * .......................................
     * 39 x 7 pixel, 1 bpp
     */
       0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08,
       0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E,
       0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08,
       0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00
    };
    
    static const unsigned char grayscale_grey[] = {
    /* .......................................................
     * ..####.####...###..#...#..####..###...###..#.....#####.
     * .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#.....
     * .#..##.####..#####..#.#...###..#.....#####.#.....####..
     * .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#.....
     * ..####.#...#.#...#...#...####...###..#...#.#####.#####.
     * .......................................................
     * 55 x 7 pixel, 8 bpp
     */
       110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
       110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
       110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
       110,110,110,110,110,110,110,
       120,120, 20, 20, 20, 20,120,222,222,222,222,120,120,120, 24, 24,
        24,120,120,226,120,120,120,226,120,120, 28, 28, 28, 28,120,120,
       230,230,230,120,120,120, 32, 32, 32,120,120,234,120,120,120,120,
       120, 36, 36, 36, 36, 36,120,
       130, 20,130,130,130,130,130,222,130,130,130,222,130, 24,130,130,
       130, 24,130,226,130,130,130,226,130, 28,130,130,130,130,130,230,
       130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
       130, 36,130,130,130,130,130,
       140, 20,140,140, 20, 20,140,222,222,222,222,140,140, 24, 24, 24,
        24, 24,140,140,226,140,226,140,140,140, 28, 28, 28,140,140,230,
       140,140,140,140,140, 32, 32, 32, 32, 32,140,234,140,140,140,140,
       140, 36, 36, 36, 36,140,140,
       130, 20,130,130,130, 20,130,222,130,130,222,130,130, 24,130,130,
       130, 24,130,130,130,226,130,130,130,130,130,130,130, 28,130,230,
       130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
       130, 36,130,130,130,130,130,
       120,120, 20, 20, 20, 20,120,222,120,120,120,222,120, 24,120,120,
       120, 24,120,120,120,226,120,120,120, 28, 28, 28, 28,120,120,120,
       230,230,230,120,120, 32,120,120,120, 32,120,234,234,234,234,234,
       120, 36, 36, 36, 36, 36,120,
       110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
       110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
       110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
       110,110,110,110,110,110,110
    };

    /* Turn off backlight timeout */
    backlight_ignore_timeout();

    rb->lcd_setfont(FONT_SYSFIXED);   /* select default font */

    /* get the remainder of the plugin buffer */
    gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);

    /* initialize the greyscale buffer:
       Archos: 112 pixels wide, 7 rows (56 pixels) high.
       H1x0: 160 pixels wide, 30 rows (120 pixels) high. */
    if (!grey_init(gbuf, gbuf_size, GREY_BUFFERED|GREY_ON_COP,
                   LCD_WIDTH, GFX_HEIGHT, NULL))
    {
        rb->splash(HZ, "Not enough memory.");
        return PLUGIN_ERROR;
    }

    /* place greyscale overlay 1 row down */
    grey_set_position(0, 8);

    rb->lcd_puts(0, 0, "Shades: 129");
    rb->lcd_update();

#ifdef HAVE_ADJUSTABLE_CPU_FREQ
    rb->cpu_boost(true);
#endif
    grey_show(true);          /* switch on greyscale overlay */

    time = *rb->current_tick; /* start time measurement */

    grey_set_background(150);
    grey_clear_display();     /* fill everything with grey 150 */

    /* draw a dark grey line star background */
    grey_set_foreground(80);
    for (y = 0; y < GFX_HEIGHT; y += 8)                   /* horizontal part */
    {
        grey_drawline(0, y, (LCD_WIDTH-1), (GFX_HEIGHT-1) - y); /*grey lines */
    }
    for (x = 10; x <= LCD_WIDTH; x += 10)                    /* vertical part */
    {
        grey_drawline(x, 0, (LCD_WIDTH-1) - x, (GFX_HEIGHT-1)); /*grey lines */
    }

    grey_set_foreground(0);
    grey_drawrect(0, 0, LCD_WIDTH, GFX_HEIGHT);   /* black border */

    /* draw grey tones */
    for (i = 0; i < GFX_GREYTONE_WIDTH; i++)
    {
        x = ((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2) + i;
        grey_set_foreground(GFX_GREYTONE_STEP * i);
        /* vertical lines */
        grey_vline(x, (GFX_HEIGHT/8), (GFX_HEIGHT-GFX_HEIGHT/8-1));
    }

    grey_set_drawmode(DRMODE_COMPLEMENT);
    /* invert rectangle (lower half) */
    grey_fillrect((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2, (GFX_HEIGHT/2+1),
                  GFX_GREYTONE_WIDTH, (GFX_HEIGHT/2-GFX_HEIGHT/8-1));
    /* invert a line */
    grey_hline((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2,
               (LCD_WIDTH+GFX_GREYTONE_WIDTH)/2, (GFX_HEIGHT/2-1));

    /* show bitmaps (1 bit and 8 bit) */
    /* opaque */
    grey_set_drawinfo(DRMODE_SOLID, 255, 100);
    grey_mono_bitmap(rockbox,
                     MAX((LCD_WIDTH/2-47), ((LCD_WIDTH-GFX_GREYTONE_WIDTH)/2)),
                     (5*GFX_HEIGHT/16-4), 43, 7);
    /* transparent */
    grey_set_drawinfo(DRMODE_FG, 0, 100);
    grey_mono_bitmap(showing, (LCD_WIDTH/2+4) , (5*GFX_HEIGHT/16-4), 39, 7);
    /* greyscale */
    grey_gray_bitmap(grayscale_grey, ((LCD_WIDTH-55)/2), (11*GFX_HEIGHT/16-4),
                     55, 7);

    grey_update();

    time = *rb->current_tick - time;  /* end time measurement */

    rb->lcd_putsf(0, 0, "Shades: 129, %d.%02ds", time / 100, time % 100);
    grey_deferred_lcd_update();       /* schedule an lcd_update() */
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
    rb->cpu_boost(false);
#endif

    /* drawing is now finished, play around with scrolling 
     * until you press OFF or connect USB
     */
    grey_set_background(255);
    while (true)
    {
        scroll_amount = 1;

        button = rb->button_get(true);

        exit_on_usb(button);

        if (button & GREYSCALE_SHIFT)
        {
            if (!black_border)
            {
                grey_set_background(0);
                black_border = true;
            }
        }
        else
        {
            if (black_border)
            {
                grey_set_background(255);
                black_border = false;
            }
        }

        if (button & BUTTON_REPEAT)
            scroll_amount = 4;

        switch (button & ~(GREYSCALE_SHIFT | BUTTON_REPEAT))
        {
            case GREYSCALE_LEFT:

                grey_scroll_left(scroll_amount);  /* scroll left */
                grey_update();
                break;

            case GREYSCALE_RIGHT:

                grey_scroll_right(scroll_amount); /* scroll right */
                grey_update();
                break;

            case GREYSCALE_UP:

                grey_scroll_up(scroll_amount);    /* scroll up */
                grey_update();
                break;

            case GREYSCALE_DOWN:

                grey_scroll_down(scroll_amount);  /* scroll down */
                grey_update();
                break;
#ifdef GREYSCALE_RC_OFF
            case GREYSCALE_RC_OFF:
#endif
            case GREYSCALE_OFF:
                return PLUGIN_OK;
        }
    }
}