Beispiel #1
0
int main(void)
{
    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize peripherals */
    display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
    console_init();
    controller_init();

    console_set_render_mode(RENDER_MANUAL);

    int testv = 0;
    int press = 0;
    uint8_t data[32];
    memset( data, 0, 32 );

    /* Main loop test */
    while(1) 
    {
        console_clear();

        /* To do initialize routines */
        controller_scan();

        struct controller_data keys = get_keys_down();

        for( int i = 0; i < 4; i++ )
        {
            if( keys.c[i].A )
            {
                rumble_start( i );
            }

            if( keys.c[i].B )
            {
                rumble_stop( i );
            }

            if( keys.c[i].Z )
            {
                press = read_mempak_address( i, 0x0000, data );
            }
        }

        int controllers = get_controllers_present();

        printf( "Controller 1 %spresent\n", (controllers & CONTROLLER_1_INSERTED) ? "" : "not " );
        printf( "Controller 2 %spresent\n", (controllers & CONTROLLER_2_INSERTED) ? "" : "not " );
        printf( "Controller 3 %spresent\n", (controllers & CONTROLLER_3_INSERTED) ? "" : "not " );
        printf( "Controller 4 %spresent\n", (controllers & CONTROLLER_4_INSERTED) ? "" : "not " );

        int accessories = get_accessories_present();

        printf( "Accessory 1 %spresent %s\n", (accessories & CONTROLLER_1_INSERTED) ? "" : "not ", 
                                              (accessories & CONTROLLER_1_INSERTED) ? format_type( identify_accessory( 0 ) ) : "" );
        printf( "Accessory 2 %spresent %s\n", (accessories & CONTROLLER_2_INSERTED) ? "" : "not ",
                                              (accessories & CONTROLLER_2_INSERTED) ? format_type( identify_accessory( 1 ) ) : "" );
        printf( "Accessory 3 %spresent %s\n", (accessories & CONTROLLER_3_INSERTED) ? "" : "not ",
                                              (accessories & CONTROLLER_3_INSERTED) ? format_type( identify_accessory( 2 ) ) : "" );
        printf( "Accessory 4 %spresent %s\n", (accessories & CONTROLLER_4_INSERTED) ? "" : "not ",
                                              (accessories & CONTROLLER_4_INSERTED) ? format_type( identify_accessory( 3 ) ) : "" );

        printf("\n%d\n\n", testv++ );

        for( int i = 0; i < 32; i++ )
        {
            printf( "%02X", data[i] );
        }

        printf( "\n\n" );
        printf( "Operation returned: %d\n", press );

        console_render();
    }
}
Beispiel #2
0
int main(void)
{
    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize peripherals */
    display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
    console_init();
    controller_init();

    console_set_render_mode(RENDER_MANUAL);

    /* Main loop test */
    while(1) 
    {
        console_clear();

        /* To do initialize routines */
        controller_scan();

        int controllers = get_controllers_present();

        if( controllers & CONTROLLER_1_INSERTED )
        {
            int accessories = get_accessories_present();

            if( (accessories & CONTROLLER_4_INSERTED) && identify_accessory( 3 ) == ACCESSORY_VRU )
            {
                uint8_t out[64];
                uint8_t in[64];

                // Initial sequence
                out[0] = 0x00;
                out[1] = 0x00;
                print_request( 2, out );
                execute_raw_command( 3, 0xB, 2, 3, out, in );
                print_result( 3, in );

                // LODS OF 0x0B
                out[0] = 0x1E;
                out[1] = 0x0C;
                print_request( 2, out );
                execute_raw_command( 3, 0xD, 2, 1, out, in );
                print_result( 1, in );

                out[0] = 0x6E;
                out[1] = 0x07;
                print_request( 2, out );
                execute_raw_command( 3, 0xD, 2, 1, out, in );
                print_result( 1, in );

                out[0] = 0x08;
                out[1] = 0x0E;
                print_request( 2, out );
                execute_raw_command( 3, 0xD, 2, 1, out, in );
                print_result( 1, in );

                out[0] = 0x56;
                out[1] = 0x18;
                print_request( 2, out );
                execute_raw_command( 3, 0xD, 2, 1, out, in );
                print_result( 1, in );

                out[0] = 0x03;
                out[1] = 0x0F;
                print_request( 2, out );
                execute_raw_command( 3, 0xD, 2, 1, out, in );
                print_result( 1, in );

                // Some C's and B's
                out[0] = 0x00;
                out[1] = 0x00;
                out[2] = 0x00;
                out[3] = 0x00;
                out[4] = 0x01;
                out[5] = 0x00;
                print_request( 6, out );
                execute_raw_command( 3, 0xC, 6, 1, out, in );
                print_result( 1, in );

                out[0] = 0x00;
                out[1] = 0x00;
                print_request( 2, out );
                execute_raw_command( 3, 0xB, 2, 3, out, in );
                print_result( 3, in );
                
                out[0] = 0x00;
                out[1] = 0x00;
                out[2] = 0x02;
                out[3] = 0x00;
                out[4] = 0x3B;
                out[5] = 0x00;
                print_request( 6, out );
                execute_raw_command( 3, 0xC, 6, 1, out, in );
                print_result( 1, in );

                out[0] = 0x00;
                out[1] = 0x00;
                print_request( 2, out );
                execute_raw_command( 3, 0xB, 2, 3, out, in );
                print_result( 3, in );

                // Give that A a try
                memset( out, 0, sizeof( out ) );
                print_request( 22, out );
                execute_raw_command( 3, 0xA, 22, 1, out, in );
                print_result( 1, in );

                memset( out, 0, sizeof( out ) );
                print_request( 22, out );
                execute_raw_command( 3, 0xA, 22, 1, out, in );
                print_result( 1, in );

                memset( out, 0, sizeof( out ) );
                out[14] = 0x03;
                out[18] = 0x12;
                out[20] = 0x08;
                print_request( 22, out );
                execute_raw_command( 3, 0xA, 22, 1, out, in );
                print_result( 1, in );

                // Render it!
                console_render();
                while(1){;}
            }
            else
            {
                printf( "Please insert a VRU into slot 4.\n" );
            }
        }
        else
        {
            printf( "Please insert a standard\ncontroller into slot 1.\n" );
        }

        console_render();
    }
}
Beispiel #3
0
int main(void)
{
    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize peripherals */
    console_init();
    controller_init();

    console_set_render_mode(RENDER_MANUAL);

    console_clear();

    printf( "Press A on a controller\n"
                    "to read that controller's\n"
                    "mempak.\n\n"
                    "Press B to format mempak.\n\n"
                    "Press Z to corrupt mempak.\n\n"
                    "Press L to copy mempak.\n\n"
                    "Press R to paste mempak." );
    
    console_render();

    /* Main loop test */
    while(1) 
    {
        /* To do initialize routines */
        controller_scan();

        struct controller_data keys = get_keys_down();

        for( int i = 0; i < 4; i++ )
        {
            if( keys.c[i].err == ERROR_NONE )
            {
                if( keys.c[i].A )
                {
                    console_clear();

                    /* Read accessories present, throwing away return.  If we don't do this, then
                       initialization routines in the identify_accessory() call will fail once we
                       remove and insert a new accessory while running */
                    struct controller_data output;
                    get_accessories_present( &output );

                    /* Make sure they don't have a rumble pak inserted instead */
                    switch( identify_accessory( i ) )
                    {
                        case ACCESSORY_NONE:
                            printf( "No accessory inserted!" );
                            break;
                        case ACCESSORY_MEMPAK:
                        {
                            int err;
                            if( (err = validate_mempak( i )) )
                            {
                                if( err == -3 )
                                {
                                    printf( "Mempak is not formatted!" );
                                }
                                else
                                {
                                    printf( "Mempak bad or removed during read!" );
                                }
                            }
                            else
                            {
                                for( int j = 0; j < 16; j++ )
                                {
                                    entry_structure_t entry;

                                    get_mempak_entry( i, j, &entry );

                                    if( entry.valid )
                                    {
                                        printf( "%s - %d blocks\n", entry.name, entry.blocks );
                                    }
                                    else
                                    {
                                        printf( "(EMPTY)\n" );
                                    }
                                }

                                printf( "\nFree space: %d blocks", get_mempak_free_space( i ) );
                            }

                            break;
                        }
                        case ACCESSORY_RUMBLEPAK:
                            printf( "Cannot read data off of rumblepak!" );
                            break;
                    }

                    console_render();
                }
                else if( keys.c[i].B )
                {
                    console_clear();

                    /* Make sure they don't have a rumble pak inserted instead */
                    switch( identify_accessory( i ) )
                    {
                        case ACCESSORY_NONE:
                            printf( "No accessory inserted!" );
                            break;
                        case ACCESSORY_MEMPAK:
                            if( format_mempak( i ) )
                            {
                                printf( "Error formatting mempak!" );
                            }
                            else
                            {
                                printf( "Memory card formatted!" );
                            }

                            break;
                        case ACCESSORY_RUMBLEPAK:
                            printf( "Cannot format rumblepak!" );
                            break;
                    }

                    console_render();
                }
                else if( keys.c[i].Z )
                {
                    console_clear();

                    /* Make sure they don't have a rumble pak inserted instead */
                    switch( identify_accessory( i ) )
                    {
                        case ACCESSORY_NONE:
                            printf( "No accessory inserted!" );
                            break;
                        case ACCESSORY_MEMPAK:
                        {
                            uint8_t sector[256];
                            int err = 0;

                            memset( sector, 0xFF, 256 );

                            err |= write_mempak_sector( i, 0, sector );
                            err |= write_mempak_sector( i, 1, sector );
                            err |= write_mempak_sector( i, 2, sector );
                            err |= write_mempak_sector( i, 3, sector );
                            err |= write_mempak_sector( i, 4, sector );

                            if( err )
                            {
                                printf( "Error corrupting data!" );
                            }
                            else
                            {
                                printf( "Data corrupted on memory card!" );
                            }

                            break;
                        }
                        case ACCESSORY_RUMBLEPAK:
                            printf( "Cannot erase data off of rumblepak!" );
                            break;
                    }

                    console_render();
                }
                else if( keys.c[i].L )
                {
                    console_clear();

                    /* Make sure they don't have a rumble pak inserted instead */
                    switch( identify_accessory( i ) )
                    {
                        case ACCESSORY_NONE:
                            printf( "No accessory inserted!" );
                            break;
                        case ACCESSORY_MEMPAK:
                        {
                            int err = 0;

                            for( int j = 0; j < 128; j++ )
                            {
                                err |= read_mempak_sector( i, j, &mempak_data[j * MEMPAK_BLOCK_SIZE]  );
                            }

                            if( err )
                            {
                                printf( "Error loading data!" );
                            }
                            else
                            {
                                printf( "Data loaded into RAM!" );
                            }

                            break;
                        }
                        case ACCESSORY_RUMBLEPAK:
                            printf( "Cannot erase data off of rumblepak!" );
                            break;
                    }

                    console_render();
                }
                else if( keys.c[i].R )
                {
                    console_clear();

                    /* Make sure they don't have a rumble pak inserted instead */
                    switch( identify_accessory( i ) )
                    {
                        case ACCESSORY_NONE:
                            printf( "No accessory inserted!" );
                            break;
                        case ACCESSORY_MEMPAK:
                        {
                            int err = 0;

                            for( int j = 0; j < 128; j++ )
                            {
                                err |= write_mempak_sector( i, j, &mempak_data[j * MEMPAK_BLOCK_SIZE]  );
                            }

                            if( err )
                            {
                                printf( "Error saving data!" );
                            }
                            else
                            {
                                printf( "Data saved into mempak!" );
                            }

                            break;
                        }
                        case ACCESSORY_RUMBLEPAK:
                            printf( "Cannot erase data off of rumblepak!" );
                            break;
                    }

                    console_render();
                }
            }
        }
    }
}