コード例 #1
0
/*
 * WinMain - main windows entry point
 */
int PASCAL WinMain( HINSTANCE inst, HINSTANCE previnst, LPSTR cmd, int show)
{
    HINSTANCE           newinst;
    HANDLE              h;
    MSG                 msg;
    parm_data           parm;
    command_data        cmddat;
    char                FAR_PTR *cmdline;
    char                filename[_MAX_PATH];

    /*
     * are we the first? if so, winexec another one of ourselves
     * and then start sampling
     */
    if( !previnst ) {
        SharedMemory = NULL;
        StartWDebug386();
        if( !WDebug386 ) {
            WinMessage( "Could not find WDEBUG.386" );
            return( FALSE );
        }
        if( !MsgInit( inst ) ) fatal();
        cmddat.nCmdShow = SW_NORMAL;
        if( cmd == NULL || cmd[0] == 0 ) {
            if( !GetFileName( inst, show, filename ) ) {
                CloseShop();
                return( FALSE );
            }
            cmdline = filename;
        } else {
            cmddat.nCmdShow = SW_MINIMIZE;
            cmdline = cmd;
        }

        h = GlobalAlloc( GMEM_SHARE | GMEM_FIXED | GMEM_ZEROINIT, sizeof( shared_data ) );
        if( h == NULL ) {
            CloseShop();
            return( FALSE );
        }
        SharedMemory = MK_FP( h,0 );

        WaitForFirst = TRUE;    /* tell our counterpart to wait for
                               us before starting the timer */
        cmddat.always2= 2;
        parm.wEnvSeg = 0;
        parm.lpCmdLine = (char far *) "";
        parm.lpCmdShow = (void far *) &cmddat;
        parm.dwReserved = 0;
        newinst = LoadModule( "wsamplew.exe", (LPVOID) &parm );
        if( (UINT)newinst < 32 ) {
            WinMessage( MsgArray[MSG_SAMPLE_12-ERR_FIRST_MESSAGE] );
            CloseShop();
            return( FALSE );
        }
        /*
         * wait for our counterpart to initialize - if he fails,
         * then we must die too
         */
        do {
            GetIData( newinst, (void near *)&IsSecondOK, sizeof( IsSecondOK ) );
            MessageLoop();
        } while( !IsSecondOK );
        if( IsSecondOK == NOT_OK ) {
            WinMessage( MsgArray[MSG_SAMPLE_12-ERR_FIRST_MESSAGE] );
            CloseShop();
            return( FALSE );
        }

        /*
         * get data created by our counterpart
         */
        GetIData( newinst, &OutputWindow, sizeof( OutputWindow ) );
        GetIData( newinst, &MainWindowHandle, sizeof( MainWindowHandle ) );
        GetIData( newinst, &SampSave, sizeof( SampSave) );

        /*
         * start the sampler - our other half will be re-started
         * once we have loaded the task to be sampled.
         */
        sample_main( cmdline );
        CloseShop();
        SendMessage( MainWindowHandle, WM_CLOSE, 0, 0 );
        return( FALSE );

    } else {

        /*
         * we are the second instance (the guy who waits for
         * timer events and then tries to write the sample file)
         * init our windows stuff, then wait for the first instance
         * to start the samplee, set a timer, and go
         */
        PrevInstance = previnst;
        if( !MsgInit( inst ) ) fatal();
        if( !WindowsInit( inst, show ) ) {
            IsSecondOK = NOT_OK;
            return( FALSE );
        }
        IsSecondOK = A_OK;
        do {
            GetIData( previnst, (void near *)&WaitForFirst, sizeof( WaitForFirst ) );
            MessageLoop();
        } while( WaitForFirst );
        GetIData( previnst, (void near *) &Samples, sizeof( Samples ) );
        GetIData( previnst, &SharedMemory, sizeof( SharedMemory ) );
        KillTimer( MainWindowHandle, TIMER_ID );
        SetTimer( MainWindowHandle, TIMER_ID, 4500, 0L); /* 4.5 seconds */
    }

    /*
     * main message loop for the second instance
     */
    while( GetMessage( &msg, NULL, 0, 0 ) ) {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }
    return( FALSE );

} /* WinMain */
コード例 #2
0
ファイル: main.c プロジェクト: LedgerHQ/blue-sample-apps
__attribute__((section(".boot"))) int main(void) {
    // exit critical section
    __asm volatile("cpsie i");

    // ensure exception will work as planned
    os_boot();

    BEGIN_TRY {
        TRY {
            io_seproxyhal_init();

            G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_SET_TICKER_INTERVAL;
            G_io_seproxyhal_spi_buffer[1] = 0;
            G_io_seproxyhal_spi_buffer[2] = 2;
            G_io_seproxyhal_spi_buffer[3] = 0;
            G_io_seproxyhal_spi_buffer[4] =
                const_anti_align_0x1000[sizeof(const_anti_align_0x1000) - 1];
            io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 5);

            G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_SET_TICKER_INTERVAL;
            G_io_seproxyhal_spi_buffer[1] = 0;
            G_io_seproxyhal_spi_buffer[2] = 2;
            G_io_seproxyhal_spi_buffer[3] = 0;
            G_io_seproxyhal_spi_buffer[4] = 50;
            io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 5);

            // initialize the game panel, targets and player
            {
                unsigned int i;

                os_memset(&G_player, 0, sizeof(G_player));
                os_memset(G_shots, 0, sizeof(G_shots));
                os_memset(G_targets, 0, sizeof(G_targets));
                // consume events
                G_events = 0;
                // draw buttons only once ! to avoid flickering
                G_draw_buttons = 1;
                G_state_index = 0;

                G_player.x = 100;
                G_player.y = 200;
                G_player.velocity = PLAYER_VELOCITY;
                G_player.last_direction = 0;

                for (i = 0; i < TARGET_COUNT; i++) {
                    G_targets[i].x = 300 - (cx_rng_u8() % 100);
                    G_targets[i].y =
                        20 +
                        (cx_rng_u8() * 10 + G_player.y) % (SCREEN_HEIGHT - 20);
                    G_targets[i].alive = 1;
                }
            }

            // erase loader screen (once only)
            G_state = ERASE_SCREEN;
            io_seproxyhal_display(&erase_screen[0]);

            sample_main();
        }
        CATCH_OTHER(e) {
        }
        FINALLY {
        }
    }
    END_TRY;
}