Example #1
0
sprite_t *loadImage32DFS(char *fname) {
    int size, x, y, n, fd;
    u8 *tbuf;
    u32 *ibuf;
    sprite_t *sbuf;

    fd = dfs_open(fname);
    if (fd < 0)
        return 0;                       // couldn't open image

    size = dfs_size(fd);
    tbuf = malloc(size);
    if (!tbuf) {
        dfs_close(fd);
        return 0;                       // out of memory
    }

    dfs_read(tbuf, 1, size, fd);
    dfs_close(fd);

    ibuf = (u32*)stbi_load_from_memory(tbuf, size, &x, &y, &n, 4);
    free(tbuf);
    if (!ibuf)
        return 0;                       // couldn't decode image

    sbuf = (sprite_t*)malloc(sizeof(sprite_t) + x * y * 4);
    if (!sbuf) {
        stbi_image_free(ibuf);
        return 0;                       // out of memory
    }

    sbuf->width = x;
    sbuf->height = y;
    sbuf->bitdepth = 4;
    sbuf->format = 0;
    sbuf->hslices = x / 32;
    sbuf->vslices = y / 32;

   // color_t *src = (color_t*)ibuf;
    u32 *dst = (u32*)((u32)sbuf + sizeof(sprite_t));

    for (int j=0; j<y; j++)
        for (int i=0; i<x; i++)
            dst[i + j*x] = ibuf[i + j*x];

    /* Invalidate data associated with sprite in cache */
    data_cache_hit_writeback_invalidate( sbuf->data, sbuf->width * sbuf->height * sbuf->bitdepth );

    stbi_image_free(ibuf);
    return sbuf;
}
Example #2
0
File: cp.c Project: elopez/SO-I
int main(int argc, char **argv)
{
	if (argc < 3)
		return -1;
	if (dfs_connect("127.0.0.1") == -1)	// Conectarse al servidor
		return -1;
	FD src = dfs_open(argv[1]);	// Abrir el archivo origen
	dfs_rm(argv[2]);	// Borro el archivo por si existiera
	dfs_create(argv[2]);
	FD dst = dfs_open(argv[2]);	// Abrir destino
	char c;
	// Copiar el contenido
	while (dfs_read(src, 1, &c) != EOF) {
		dfs_write(dst, 1, &c);
	}
	// Cerrar archivos
	dfs_close(dst);
	dfs_close(src);
	// Cerrar conexion
	dfs_disconnect();
	return 0;
}
Example #3
0
File: cat.c Project: elopez/SO-I
int main(int argc, char **argv)
{
	FD src;
	int file = 1;
	char c[2];
	if (argc < 2)
		return -1;
	if (dfs_connect("127.0.0.1") == -1)	// Conectarse al servidor
		return -1;
	while (file < argc) {
		src = dfs_open(argv[file]);	// Abrir el archivo origen
		while (dfs_read(src, 1, c) != EOF) {
			putchar(*c);
		}
		dfs_close(src);
		file++;
	}
	printf("\n");
	// Cerrar archivos
	// Cerrar conexion
	dfs_disconnect();
	return 0;
}
Example #4
0
int main( int argc, char *argv[] )
{
    if( argc < 3 )
    {
        return -1;
    }

    if( argv[1][0] != '-' )
    {
        return -1;
    }

    switch( argv[1][1] )
    {
        case 'l':
        case 'L':
        {
            /* List files in DFS */
            FILE *fp = fopen( argv[2], "rb" );

            fseek( fp, 0, SEEK_END );
            int lSize = ftell( fp );
            fseek( fp, 0, SEEK_SET );
            
            void *filesystem = malloc( lSize );
            fread( filesystem, 1, lSize, fp );
            fclose( fp );

            dfs_init_pc( filesystem, 1 );

            list_dir( "/", 0 );

            free( filesystem );
            break;
        }
        case 'e':
        case 'E':
        {
            /* Extract file */
            FILE *fp = fopen( argv[2], "rb" );

            fseek( fp, 0, SEEK_END );
            int lSize = ftell( fp );
            fseek( fp, 0, SEEK_SET );
            
            void *filesystem = malloc( lSize );
            fread( filesystem, 1, lSize, fp );
            fclose( fp );

            dfs_init_pc( filesystem, 1 );
            
            int fl = dfs_open( argv[3] );
            uint8_t *data = malloc( dfs_size( fl ) );

            dfs_read( data, 1, dfs_size( fl ), fl );
            fwrite( data, 1, dfs_size( fl ), stdout );
            dfs_close( fl );

            free( filesystem );
            free( data );

            break;
        }
        case 's':
        case 'S':
        {
            /* Extract file with another file open (test multiple files) */
            FILE *fp = fopen( argv[2], "rb" );

            fseek( fp, 0, SEEK_END );
            int lSize = ftell( fp );
            fseek( fp, 0, SEEK_SET );
            
            void *filesystem = malloc( lSize );
            fread( filesystem, 1, lSize, fp );
            fclose( fp );

            dfs_init_pc( filesystem, 1 );

            int nu = dfs_open( argv[4] );
            uint32_t unused;
            dfs_read( &unused, 1, 4, nu );
            
            int fl = dfs_open( argv[3] );
            uint8_t *data = malloc( dfs_size( fl ) );

            dfs_read( data, 1, dfs_size( fl ), fl );
            fwrite( data, 1, dfs_size( fl ), stdout );
            dfs_close( fl );
            dfs_close( nu );

            free( filesystem );
            free( data );

            break;
        }
    }

    return 0;
}
Example #5
0
int main(void)
{
    int mode = 0;

    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize peripherals */
    display_init( RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
    dfs_init( DFS_DEFAULT_LOCATION );
    rdp_init();
    controller_init();
    timer_init();

    /* Read in single sprite */
    int fp = dfs_open("/mudkip.sprite");
    sprite_t *mudkip = malloc( dfs_size( fp ) );
    dfs_read( mudkip, 1, dfs_size( fp ), fp );
    dfs_close( fp );
    
    fp = dfs_open("/earthbound.sprite");
    sprite_t *earthbound = malloc( dfs_size( fp ) );
    dfs_read( earthbound, 1, dfs_size( fp ), fp );
    dfs_close( fp );

    fp = dfs_open("/plane.sprite");
    sprite_t *plane = malloc( dfs_size( fp ) );
    dfs_read( plane, 1, dfs_size( fp ), fp );
    dfs_close( fp );

    /* Kick off animation update timer to fire thirty times a second */
    new_timer(TIMER_TICKS(1000000 / 30), TF_CONTINUOUS, update_counter);

    /* Main loop test */
    while(1) 
    {
        static display_context_t disp = 0;

        /* Grab a render buffer */
        while( !(disp = display_lock()) );
       
        /*Fill the screen */
        graphics_fill_screen( disp, 0xFFFFFFFF );

        /* Set the text output color */
        graphics_set_color( 0x0, 0xFFFFFFFF );
    
        switch( mode )
        {
            case 0:
                /* Software spritemap test */
                graphics_draw_text( disp, 20, 20, "Software spritemap test" );

                /* Display a stationary sprite of adequate size to fit in TMEM */
                graphics_draw_sprite_trans( disp, 20, 50, plane );

                /* Display a stationary sprite to demonstrate backwards compatibility */
                graphics_draw_sprite_trans( disp, 50, 50, mudkip );

                /* Display walking NESS animation */
                graphics_draw_sprite_stride( disp, 20, 100, earthbound, ((animcounter / 15) & 1) ? 1: 0 );

                /* Display rotating NESS animation */
                graphics_draw_sprite_stride( disp, 50, 100, earthbound, ((animcounter / 8) & 0x7) * 2 );

                break;
            case 1:
            {
                /* Hardware spritemap test */
                graphics_draw_text( disp, 20, 20, "Hardware spritemap test" );

                /* Assure RDP is ready for new commands */
                rdp_sync( SYNC_PIPE );

                /* Remove any clipping windows */
                rdp_set_default_clipping();

                /* Enable sprite display instead of solid color fill */
                rdp_enable_texture_copy();

                /* Attach RDP to display */
                rdp_attach_display( disp );
                    
                /* Ensure the RDP is ready to receive sprites */
                rdp_sync( SYNC_PIPE );

                /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                rdp_load_texture( 0, 0, MIRROR_DISABLED, plane );
                
                /* Display a stationary sprite of adequate size to fit in TMEM */
                rdp_draw_sprite( 0, 20, 50 );

                /* Since the RDP is very very limited in texture memory, we will use the spritemap feature to display
                   all four pieces of this sprite individually in order to use the RDP at all */
                for( int i = 0; i < 4; i++ )
                {
                    /* Ensure the RDP is ready to receive sprites */
                    rdp_sync( SYNC_PIPE );

                    /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                    rdp_load_texture_stride( 0, 0, MIRROR_DISABLED, mudkip, i );
                
                    /* Display a stationary sprite to demonstrate backwards compatibility */
                    rdp_draw_sprite( 0, 50 + (20 * (i % 2)), 50 + (20 * (i / 2)) );
                }

                /* Ensure the RDP is ready to receive sprites */
                rdp_sync( SYNC_PIPE );

                /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                rdp_load_texture_stride( 0, 0, MIRROR_DISABLED, earthbound, ((animcounter / 15) & 1) ? 1: 0 );
                
                /* Display walking NESS animation */
                rdp_draw_sprite( 0, 20, 100 );

                /* Ensure the RDP is ready to receive sprites */
                rdp_sync( SYNC_PIPE );

                /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                rdp_load_texture_stride( 0, 0, MIRROR_DISABLED, earthbound, ((animcounter / 8) & 0x7) * 2 );
                
                /* Display rotating NESS animation */
                rdp_draw_sprite( 0, 50, 100 );

                /* Inform the RDP we are finished drawing and that any pending operations should be flushed */
                rdp_detach_display();

                break;
            }
        }

        /* Force backbuffer flip */
        display_show(disp);

        /* Do we need to switch video displays? */
        controller_scan();
        struct controller_data keys = get_keys_down();

        if( keys.c[0].A )
        {
            /* Lazy switching */
            mode = 1 - mode;
        }
    }
}