예제 #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 );
}
예제 #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());
}
예제 #3
0
파일: file.c 프로젝트: oleavitt/gem
FILEDATA *file_OpenMain(const char *fname)
{
	assert(include_level == 0);

	if((filestack->fp = SCN_FindFile(fname, READ,
		scn_source_paths, SCN_FINDFILE_CHK_CUR_FIRST)) != NULL)
	{
		strcpy(filestack->name, fname);
		filestack->line_num = 1;
	}
	else
	{
		logerror("Unable to open: %s", fname);
		file_Close();
		return NULL;
	}

	return filestack; /* &filestack[0] */
}
예제 #4
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) ;
}
예제 #5
0
파일: file.c 프로젝트: kuriel07/Yggdrasil
file_File * file_OpenStatus(uchar * path, fat_FileSystem * fs, uchar status) {
	uchar a = 0x00;
	uchar entry_found = 0;
	file_File * file;
	uint16 i, length, j = 0;
	uint16 c;
	uchar skip;
	uchar file_name[SIZE_MAX_LFN];
	uint32 cluster_no;
	cluster_no = fs->cluster_begin_lba;
	file = (file_File *)efat_malloc(sizeof(file_File));
	file->entry = (fat_DirEntry *)efat_malloc(sizeof(fat_DirEntry));
	file->status = status;
	file->entry->attrib |= FAT_ATTR_DIR;		//set current file to root directory
	i = 0;
	while(entry_found==0) {
		fopen_get_next_entry:
		length = util_DirNameCopy(file_name, path + i);
		if(length == 0) {
			if(file->entry->attrib & FAT_ATTR_DIR) {	//check if directory
				file_Close(file);
				return 0;						//return null if directory
			}
			return file;
		}
		i += length;
		if(file_name[0] != 0) {		//eat empty space ex: \\libraries\\.. --> libraries\\..
			while((skip = fat_GetDirEntry(j, cluster_no, file->entry, fs)) !=0 ) {
				j += skip;
				if(util_DirNameCompare(file_name, file->entry->lfn)) {
					if(file->entry->attrib & FAT_ATTR_DIR) {
						cluster_no = fat_GetDataCluster(file->entry->cluster, fs); 
					} else {
						file->data_cluster = fat_GetDataCluster(file->entry->cluster, fs);
						if(a & FILE_MODE_APPEND) {
							file->file_ptr = file->entry->size - 1;
						} else {
							file->file_ptr = 0;
						}
						(fat_FileSystem *)file->fs = fs;
						file->status |= FILE_OPENED;		//set status
						file->current_cluster = file->data_cluster;		//set current cluster to 1st cluster
						file->current_offset = 0;
						return file;						//asumsi tidak ada file didalam file ??
					}
					j = 0;
					goto fopen_get_next_entry;
				}
			}
			if(status & FILE_OPEN_CREATE) {		//check if creation allowed
				if(path[i - 1] == '\\') {		//is directory?
					//use dir create
					dir_Create(cluster_no, file_name, file->entry, fs);				//create directory
					cluster_no = fat_GetDataCluster(file->entry->cluster, fs);
					j = 0;
					goto fopen_get_next_entry;
				} else {						//then file
					file_Create(cluster_no, file_name, file, fs);
					file->data_cluster = fat_GetDataCluster(file->entry->cluster, fs);
					if(a & FILE_MODE_APPEND) {
						file->file_ptr = file->entry->size - 1;
					} else {
						file->file_ptr = 0;
					}
					(fat_FileSystem *)file->fs = fs;
					file->status |= FILE_OPENED;		//set status
					file->current_cluster = file->data_cluster;		//set current cluster to 1st cluster
					file->current_offset = 0;
					return file;
				}
			}
			//file/directory tidak ditemukan
			file_Close(file);
			return 0;
		}
	}
	file_Close(file);
	return 0;	//file not found
}