Example #1
0
/*Create a tile list based on texture. width must be divisible by tw , and height by th...*/
rdp_srec_texture_tile_list_t* rdp_srec_tilelist_create(rdp_srec_texture_t* texture,uint16_t tw,uint16_t th,uint16_t tx_offs,uint16_t ty_offs) {
	rdp_srec_texture_tile_list_t* srec_tl;

	
	if ((!texture) || (0 == tw) || (0 == th) || (texture->width < tw) || (texture->height < th)) { return NULL; }

	srec_tl = (rdp_srec_texture_tile_list_t*)malloc(sizeof(rdp_srec_texture_tile_list_t));
	if (!srec_tl) { return NULL; }

	srec_tl->texture = NULL; 
	srec_tl->tiles = 0;

	/*Estimate TC*/
	uint32_t twc,thc;

	twc = (((texture->width + tw) & (~(tw-1))) / tw) + 1;
	thc = (((texture->height + th) & (~(th-1))) / th) + 1;

	srec_tl->texture = (rdp_srec_texture_t**)malloc(sizeof(rdp_srec_texture_t**) * (twc * thc));
	if (!srec_tl->texture) { rdp_srec_tilelist_destroy(srec_tl); return NULL; }

	uint32_t i,j;
	for (i = 0,j = thc*twc;i < j;++i) { 
		srec_tl->texture[i] = NULL; 
	}

	data_cache_hit_writeback_invalidate(srec_tl,sizeof(rdp_srec_texture_tile_list_t));


	/*Make tiles*/
	uint16_t x,y;

	uint8_t* tdata = texture->data;
	for (y = 0;y < texture->height;y += th) {
		const uint32_t yb = ((uint32_t)y * (uint32_t)texture->width * (uint32_t)texture->bitdepth);
		for (x = 0;x < texture->width;x += tw) {
			srec_tl->texture[srec_tl->tiles] = 
			rdp_srec_tex_create_tilepart(&tdata[yb + ((uint32_t)x * (uint32_t)texture->bitdepth)],
			tw,th,texture->bitdepth,texture->format);
			if (!srec_tl->texture[srec_tl->tiles]) {
				rdp_srec_tilelist_destroy(srec_tl); 
				return NULL;
			}
			srec_tl->texture[srec_tl->tiles]->tilepart = ((uint32_t)(tx_offs+x) << 16) | (uint32_t)(ty_offs+y);
			data_cache_hit_writeback_invalidate(srec_tl->texture[srec_tl->tiles],sizeof(rdp_srec_texture_t));
			++srec_tl->tiles;
		}
	}

	data_cache_hit_writeback_invalidate(srec_tl,sizeof(rdp_srec_texture_tile_list_t));
	return srec_tl;
}
Example #2
0
rdp_srec_texture_t* rdp_srec_tex_create(uint16_t w,uint16_t h,uint16_t bpp,uint16_t format) {
	rdp_srec_texture_t* srec_texture;
	const uint32_t sz = (((w * h * bpp) + sizeof(rdp_srec_texture_t)) + (bpp << 1)) & (~((bpp << 1)-1));

	if ((0 == bpp) || (0 == w) || (0 == h)) { return NULL; }

	srec_texture = (rdp_srec_texture_t*)malloc(sz);
	if (!srec_texture) { return NULL; }

	srec_texture->width = w;
	srec_texture->height = h;
	srec_texture->bitdepth = bpp;
	srec_texture->format = format;
	srec_texture->tilepart = 0xffffffff;
	srec_texture->hslices = srec_texture->width >> 5;
	srec_texture->vslices = srec_texture->height >> 4;

	/*Make w/dw writes safe*/
	uint8_t* addr = ((void*)srec_texture) + sizeof(rdp_srec_texture_t); 
	if ((uint32_t)addr & (bpp-1)) {
		srec_texture->data = (void*)addr + (8 - ((uint32_t)addr & (bpp-1)));
	} else {
		srec_texture->data = (void*)addr;
	}

	data_cache_hit_writeback_invalidate(srec_texture,sizeof(rdp_srec_texture_t));
	return srec_texture;
}
Example #3
0
void rdp_srec_tex_convert(sprite_t* ldragon_sprite,rdp_srec_texture_t* srec_texture) {
	srec_texture->width = ldragon_sprite->width;
	srec_texture->height = ldragon_sprite->height;
	srec_texture->bitdepth = ldragon_sprite->bitdepth;
	srec_texture->format = ldragon_sprite->format;
	srec_texture->data = ldragon_sprite->data;
	srec_texture->hslices = ldragon_sprite->hslices;
	srec_texture->vslices = ldragon_sprite->vslices;
	srec_texture->tilepart = 0;
	data_cache_hit_writeback_invalidate(srec_texture,sizeof(rdp_srec_texture_t));
}
Example #4
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 #5
0
void read_ucode(void* start, unsigned long size)
{
    data_cache_hit_writeback_invalidate(start, size);

    disable_interrupts();
    __SP_DMA_wait();

    SP_regs->DRAM_addr = start;
    MEMORY_BARRIER();
    SP_regs->RSP_addr = (void*)SP_DMA_IMEM;
    MEMORY_BARRIER();
    SP_regs->rsp_write_length = size - 1;
    MEMORY_BARRIER();
    __SP_DMA_wait();
    data_cache_hit_invalidate(start, size);

    enable_interrupts();
    return;
}