Example #1
0
/**
 * Decide when to scroll and scroll when decided to.
 */
void ScrollProcess(CORO_PARAM, const void *) {
	// COROUTINE
	CORO_BEGIN_CONTEXT;
	CORO_END_CONTEXT(_ctx);

	CORO_BEGIN_CODE(_ctx);

	// In Tinsel v2, scenes may play movies, so the background may not always
	// already be initialized like it is in v1
	while (!GetBgObject())
		CORO_SLEEP(1);

	g_ImageH = BgHeight();		// Dimensions
	g_ImageW = BgWidth();		//  of this scene.

	// Give up if there'll be no purpose in this process
	if (g_ImageW == SCREEN_WIDTH  &&  g_ImageH == SCREEN_HEIGHT)
		CORO_KILL_SELF();

	if (!TinselV2) {
		g_LeftScroll = g_DownScroll = 0;		// No iterations outstanding
		g_oldx = g_oldy = 0;
		g_scrollPixelsX = g_scrollPixelsY = SCROLLPIXELS;
	}

	if (!g_scrollActor)
		g_scrollActor = GetLeadId();

	g_pScrollMover = GetMover(g_scrollActor);

	while (1) {
		MonitorScroll();		// Set scroll requirement

		if (g_LeftScroll || g_DownScroll)	// Scroll if required
			ScrollImage();

		CORO_SLEEP(1);		// allow re-scheduling
	}

	CORO_END_CODE;
}
//*****************************************************************************
//
// This function is the display "task" that is called periodically by the
// Scheduler from the application main processing loop.
// This function displays a cycle of several messages on the display.
//
// Odd values are used for timeouts for some of the displayed messaged.  For
// example a message may be shown for 5.3 seconds.  This is done to keep the
// changes on the display out of sync with the LED blinking which occurs
// once per second.
//
//*****************************************************************************
void
DisplayTask(void *pvParam)
{
    static unsigned long ulState = 0;
    static unsigned long ulLastTick = 0;
    static unsigned long ulTimeout = 0;

    //
    // Check to see if the timeout has expired and it is time to change the
    // display.
    //
    if(SchedulerElapsedTicksGet(ulLastTick) > ulTimeout)
    {
        //
        // Save the current tick value to use for comparison next time through
        //
        ulLastTick = SchedulerTickCountGet();

        //
        // Switch based on the display task state
        //
        switch(ulState)
        {
            //
            // In this state, the scrolling TI logo is initialized, and the
            // state changed to next state.  A short timeout is used so that
            // the scrolling image will start next time through this task.
            //
            case 0:
            {
                ScrollImage(g_pucTILogo, sizeof(g_pucTILogo) / 2);
                ulTimeout = 1;
                ulState = 1;
                break;
            }

            //
            // In this state the TI logo is scrolled across the screen with
            // a scroll rate of this task period (each time this task is
            // called by the scheduler it advances the scroll by one pixel
            // column).
            //
            case 1:
            {
                if(ScrollImage(g_pucTILogo, 0))
                {
                    //
                    // If the scrolling is done, then advance the state and
                    // set the timeout for 1.3 seconds (next state will start
                    // in 1.3 seconds).
                    //
                    ulTimeout = 130;
                    ulState = 2;
                }
                break;
            }

            //
            // This state shows the text "STELLARIS" on the display for 5.3
            // seconds.
            //
            case 2:
            {
                Display96x16x1StringDraw("STELLARIS", 21, 0);
                ulTimeout = 530;
                ulState = 3;
                break;
            }

            //
            // This state clears the screen for 1.3 seconds.
            //
            case 3:
            {
                Display96x16x1Clear();
                ulTimeout = 130;
                ulState = 4;
                break;
            }

            //
            // This state shows "EVALBOT" for 5.3 seconds.
            //
            case 4:
            {
                Display96x16x1StringDraw("EVALBOT", 27, 0);
                ulTimeout = 530;
                ulState = 5;
                break;
            }

            //
            // This state clears the screen for 1.3 seconds.
            //
            case 5:
            {
                Display96x16x1Clear();
                ulTimeout = 130;
                ulState = 0;
                break;
            }

            //
            // The default state should not occur, but if it does, then reset
            // back to the beginning state.
            //
            default:
            {
                ulTimeout = 130;
                ulState = 0;
                break;
            }
        }
    }
}