Exemplo n.º 1
0
void Init()
{
	fntMain = font_LoadFromFile( GetResource( "font.zfi" ) );

	texTiles = tex_LoadFromFile( GetResource( "tiles.png" ) );
	tex_SetFrameSize( &texTiles, 32, 32 );

	// RU: Инициализация тайлов размером 32x32. Параметр Count указывает на количество тайлов по X и Y. Массив Tiles содержит кадры для каждого тайла.
	// EN: Initialization of tiles with size 32x32. Parameter Count set amount of tiles on X and Y. Array Tiles contains frames for every tile.
	map.Size.W  = 32;
	map.Size.H  = 32;
	map.Count.X = 25;
	map.Count.Y = 19;
	map.Tiles = (int**)malloc( sizeof( int* ) * map.Count.X );
	// RU: Заполняем карту "травой", 19 кадр.
	// EN: Fill the map by "grass", 19 frame.
	for ( int i = 0; i < map.Count.X; i++ )
	{
		map.Tiles[ i ] = (int*)malloc( sizeof( int ) * map.Count.Y );
		for ( int j = 0; j < map.Count.Y; j++ )
			map.Tiles[ i ][ j ] = 19;
	}

	// RU: Загружаем карту из бинарного файла.
	// EN: Load map from binary file.
	zglTFile f;
	file_Open( &f, GetResource( "ground.map" ), FOM_OPENR );
	for ( int i = 0; i < map.Count.X; i++ )
		file_Read( f, &map.Tiles[ i ][ 0 ], map.Count.Y * sizeof( int ) );
	file_Close( &f );
}
Exemplo n.º 2
0
void Media_Tests(void)
{
	int i ;
	int j ;
	int k ;
	int l ;
	int m , handle ;
	unsigned char sector[512] ;
	gfx_Cls() ;
	putstr("Media Tests") ;
	printf("Media Tests\n") ;
	file_Unmount() ;    // just to test this and media_Init
	i = media_Init() ;
	if (i == 0)
	{
		printf("Please insert the uSD card") ;
		while (i = 0)
		{
			printf(".") ;
			i = media_Init() ;
		}
	}

	printf("First RAW sector=%d\n", rawbase) ;
	trymount() ;

	handle = file_Open("gfx2demo.gci", 'r') ;
	file_Seek(handle, 0x49, 0x5800) ;   // location of large unicorn file
	i = 128 * 128 * 13 * 2 + 8 ;     // size of large unicorn file
	l = (i / 512) + 1 ;
	// we assume here that the raw partition is big enough to write this, could
	k = rawbase ;
	m = 1 ;
	while (i != 0)
	{
		printf("Copying sector %d of %d\r", m, l) ;
		j = min(512, i) ;
		file_Read(sector, j, handle) ;
		media_SetSector(k >> 16, k & 0xFFFF) ;
		k++ ;
		media_WrSector(sector) ;
		i -= j ;
		m++ ;
	}
	file_Close(handle) ;
	media_SetSector(rawbase >> 16, rawbase & 0xFFFF) ;
	media_Image(0,0) ;
	media_SetSector(rawbase >> 16, rawbase & 0xFFFF) ;
	media_Video(0,128) ;

	media_SetSector(rawbase >> 16, rawbase & 0xFFFF) ;
	media_WriteByte(0x11) ;
	media_WriteWord(0x2233) ;
	media_Flush() ;            // should write 0xFF over the rest of the sector
	media_SetSector(rawbase >> 16, rawbase & 0xFFFF) ;
	printf("\n%2.2x %4.4x %4.4x\n",media_ReadByte(), media_ReadWord(), media_ReadWord());
}
Exemplo n.º 3
0
void FAT_Tests(void)
{
	int i ;
	int j ;
	int k , handle;
	WORD w1, w2 ;
	unsigned char wks[255] ;
	unsigned char bytes[20] ;
	datar data ;
	gfx_Cls() ;
	printf("FAT Tests\n") ;
	putstr("FAT Tests\n") ;
	printf("File Error= %d\n", file_Error()) ;
	printf("uSD has %d Files\n", file_Count("*.*")) ;
	file_Dir("*.dat") ;     // should this get returned!? FindFirst and next certainly should, both need to be manual as they need "to(buffer)"

	if (file_Exists(testdat))
		file_Erase(testdat) ;
	handle = file_Open(testdat, 'w') ;
	printf("Handle= %d\n",handle) ;
	// write some stuff to uSD
	file_PutC('a', handle) ;
	file_PutW(1234, handle) ;
	file_PutS("This is a Test", handle) ;
	file_Close(handle) ;

	handle = file_Open(testdat, 'r') ;
	printf("Handle= %d\n",handle) ;
	// read it back and dump to screen
	printf("%c\n",file_GetC(handle)) ;
	printf("%d\n",file_GetW(handle)) ;
	i = file_GetS(wks, 100, handle) ;
	printf("Length=%d, String=""%s""\n", i, wks) ;

	file_Rewind(handle) ;
	i = file_Read(bytes, 10, handle) ;
	printf("Bytes read= %d Data=", i) ;
	for (j = 0; j <= i-1; j++)
		printf("%2.2x ", bytes[j]) ;
	i = file_Tell(handle, &w1, &w2) ;
	printf("\nFile pointer= %d\n", (w1 << 16) + w2) ;
	i = file_Size(handle, &w1, &w2) ;
	printf("File size=%d\n", (w1 << 16) + w2) ;

	file_Close(handle) ;
	file_Erase(testdat) ;

	handle = file_Open(testdat, 'w') ;
	printf("Handle=%d\n",handle) ;
	for(i = 1; i <= 50; i++)
	{
		data.recnum = i ;
		k = i % 20 ;
		for (j = 0; j <= 4; j++)
		{
			data.values[j] = atoz[k+j] ;
			data.idx = atoz[rand() % 27] ;
		}
		file_Write(sizeof(data), &data, handle) ;
	}
	file_Close(handle) ;
	handle = file_Open(testdat, 'r') ;
	file_Index(handle, sizeof(data) >> 16, sizeof(data) & 0xFFFF, 5) ;
	i = file_Read(&data, sizeof(data), handle) ;
	printf("%d %c %c %c %c %c %c\n", data.recnum, data.values[0],data.values[1],data.values[2],data.values[3],data.values[4], data.idx) ;
	file_Seek(handle, 0, 10*sizeof(data)) ;
	i = file_Read(&data, sizeof(data), handle) ;
	printf("%d %c %c %c %c %c %c\n", data.recnum, data.values[0],data.values[1],data.values[2],data.values[3],data.values[4], data.idx) ;
	file_Close(handle) ;
	file_Erase(testdat) ;


	file_FindFirstRet("*.dat", wks) ;
	printf(wks) ;
	printf("\n") ;
	file_FindNextRet(wks) ;
	printf(wks) ;
	printf("\n") ;

	handle = file_Open(testdat, 'w') ;
	printf("Handle=%d\n",handle) ;
	i = sizeof(Image) ;
	k = 0 ;
	while (i != 0)
	{
		j = min(512, i) ;
		file_Write(j, &Image[k], handle) ;
		i -= j ;
		k += j ;
	}
	file_Close(handle) ;
	gfx_Cls() ;
	handle = file_Open(testdat, 'r') ;
	file_Image(0,0,handle) ;
	file_Close(handle) ;
	gfx_MoveTo(40,10) ;
	putstr("4D Logo") ;

	file_Erase(testdat) ;
	handle = file_Open(testdat, 'w') ;
	printf("Handle=%d", handle) ;
	file_ScreenCapture(0,0,100,32, handle) ;
	file_Close(handle) ;

	handle = file_Open(testdat, 'r') ;
	file_Image(0,40,handle) ;
	file_Rewind(handle) ;
	file_Image(0,80,handle) ;
	file_Rewind(handle) ;
	file_Image(0,120,handle) ;
	file_Close(handle) ;
	file_Erase(testdat) ;
}
Exemplo n.º 4
0
Shell_Object * CreatePicViewer(void) {
	Shell_Object * parent;
	uchar buf_head[8];
	uint32 length;
	uchar is_png;
	png_structp png_ptr;
	png_infop info_ptr;
	png_infop end_ptr;
	Heap_Manager * png_heap;
	Heap_Manager * pic_heap;
	void * temp_ptr;
	png_byte * row_pointers[480];
	efat_FileSystem * fs;
	efat_File * file;
	uint32 i, j;
	uchar r, g, b;
	uint16 * background;
	uint32 p_width, p_height, p_bdepth, p_ctype;
	init_sd_card(&_osc._fm_drives[0]);
	//Uart_Printf("sd driver initialized\n");
	fs = efat_Init(0, &_osc._fm_drives[0]);
	file = efat_Open("test.png", fs, "r");
	if(file == NULL) {
		Uart_Printf("file not found\n");
		return NULL;
	}
	Uart_Printf("file found\n");
	//efat_Read(512, myFile, (uchar *)buf);
	length = file_Read(8, file, buf_head);
	if(length != 8) {
		return NULL;
	}
	//memcmp("aaaa", buf_head, 3);
	is_png = !png_sig_cmp_2(buf_head, 0, 8);
	if(!is_png) {
		Uart_Printf("this is not a png file\n");
		return NULL;
	}
	Uart_Printf("this is png file\n");
	
	png_heap = m_create_heap(1024 * 2048);
	//usr_alloc(NULL, 20);
	Uart_Printf("create read struct\n");
	png_ptr = png_create_read_struct_3(PNG_LIBPNG_VER_STRING, 
	(void *)temp_ptr, png_user_error, png_user_warning,
	(void *)png_heap, usr_alloc, usr_release);
	if(png_ptr == NULL) {
		return NULL;
	}
	Uart_Printf("create info struct\n");
	info_ptr = png_create_info_struct_2(png_ptr);
	if(info_ptr == NULL) {
		png_heap = png_get_mem_ptr_2(png_ptr);
		//png_destroy_read_struct(&png_ptr, NULL, NULL);
		m_delete_heap(png_heap);
		return NULL;
	}
	end_ptr = png_create_info_struct_2(png_ptr);
	if(end_ptr == NULL) {
		png_heap = png_get_mem_ptr_2(png_ptr);
		//png_destroy_read_struct(&png_ptr, info_ptr, NULL);
		m_delete_heap(png_heap);
		return NULL;
	}
	Uart_Printf("info created\n");
	png_set_read_fn_2(png_ptr, file, usr_read_data);
	png_set_sig_bytes_2(png_ptr, 8);
	png_set_user_limits_2(png_ptr, 640, 480);
	//row_pointers = usr_alloc(png_ptr, png_ptr->height * sizeof(png_byte *));
	Uart_Printf("allocating rows pointer\n");
	/*for(i=0;i<png_ptr->height;i++) {
		row_pointers[i] = NULL;
	}*/
	for(i=0;i<320;i++) {
	    row_pointers[i] = usr_alloc(png_ptr, png_ptr->width * 4);
	    Uart_Printf("%d\n", row_pointers[i]);
	}
	//use high level interface
	Uart_Printf("use high level interface\n");
	png_read_png_2(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_ALPHA | PNG_TRANSFORM_SWAP_ENDIAN, NULL);
	Uart_Printf("png decoded\n");
	p_width = png_get_image_width_2(png_ptr, info_ptr);
	p_height = png_get_image_height_2(png_ptr, info_ptr); 
	p_bdepth = png_get_bit_depth_2(png_ptr, info_ptr);
	p_ctype = png_get_color_type_2(png_ptr, info_ptr);
	Uart_Printf("allocating background\n");
	//background = m_alloc(320 * 240 * sizeof(uint16));
	png_read_image_2(png_ptr, row_pointers);
	pic_heap = m_create_heap((320 * 240 * sizeof(uint16)) + 1024);
	background = m_heap_alloc(pic_heap, 320 * 240 * sizeof(uint16));
	(p_height > 320)?(p_height = 320):(p_height = p_height);
	(p_width > 240)?(p_width = 240):(p_width = p_width);
	Uart_Printf("rendering image\n");
	for(j=0;j<p_height;j++) {
		for(i=0;i<p_width;i++) {
			r = *(uchar *)((uint32)row_pointers[j] + (3 * i));
			g = *(uchar *)((uint32)row_pointers[j] + ((3 * i) + 1));
			b = *(uchar *)((uint32)row_pointers[j] + ((3 * i) + 2));
			r >>= 3;
			g >>= 2;
			b >>= 3;
			/*r = *(uchar *)((uint32)row_pointers[j] + i);
			b = r << 2;
			g = b << 2;*/
			background[(j * 240) + i] = (uint16)((r<<11)|(g<<5)|b); 
		}
	}
	//Uart_Printf("read image\n");
	//png_read_image_2(png_ptr, row_pointers);
	Uart_Printf("png decoding success\n");
	//m_alloc(2500);
	parent = CreateFrame("Viewer", background);
	/*Uart_Printf("cleaning up\n");
	for(i=0;i<320;i++) {
		//row_pointers[i] = usr_alloc(png_ptr, png_ptr->width * 4);
		usr_release(png_ptr, row_pointers[i]);
	}
	png_destroy_struct_3(png_ptr, usr_release, (void *)png_heap);*/
	return parent;
}