Example #1
0
void main()
{
	int i = 0;
	int x;
	struct img_resource *r;
	
	volatile unsigned int *num_clock_cycles = 0x86000000;
	unsigned int **frame_start = 0x82000000;
	unsigned int *start = 0x00600000;
	
	int fat16_start;
	struct fat16_handle h;

	printf("Reading partition table... ");
	fat16_start = fat16_find_partition();
	if (fat16_start < 0)
	{
		puts("no FAT16 partition found!");
		return;
	}
	printf("found starting at sector %d.\r\n", fat16_start);
	
	printf("Opening FAT16 partition... ");
	if (fat16_open(&h, fat16_start) < 0)
	{
		puts("FAT16 boot sector read failed!");
		return;
	}
	puts("OK");

	
	*frame_start = start;
	r = img_load(&h, "LEFT_4  RES");
	
	printf("in main...\r\n");
	x = 0;
	accel_fill(start, 0x80808080, 640*480);
	while (1)
	{
		int y;
		if ((i % 64) == 0)
			printf("iters: %d, i %% 100 = %d, clock cycles: %d\r\n", i, ((unsigned int)i) % 100U, *num_clock_cycles);
		for (y = 0; y < 448; y += 64)
			accel_blit(start + y * 640 + x, r->pixels, r->w, r->h);
		x += 16;
		if (x == 512)
			x = 0;	
		i++;
	}
}
Example #2
0
//returns zero on failure
int fat16_init() {
	//read mbr sector
	fat16_read_mbr((uint16_t*)mbr);
	
	//read partition table
	memcpy(part_table, mbr+MBR_OFFSET_PART_TABLE,sizeof(partition_table)*4);
	selected_part = fat16_find_partition(part_table, TABLE_ENTRIES);

	if(selected_part==-1)
		return 0;
	
	//start of boot sector
	boot_start_lba = __SWAP32(part_table[selected_part].lba_offset);
	//read fat boot sector
	fat16_read_fat_boot(&fat_boot);
	
	//start of root dir
	root_dir_start_lba = (__SWAP16(fat_boot.reserved_sectors) + __SWAP16(fat_boot.fat_size_sectors) * fat_boot.number_of_fats) * __SWAP16(fat_boot.sector_size);
	root_dir_start_lba /= 512;
	root_dir_start_lba += boot_start_lba;

	//start of cluster data:
	data_start_lba = ((__SWAP16(fat_boot.reserved_sectors) 
							+ __SWAP16(fat_boot.fat_size_sectors) 
							* fat_boot.number_of_fats)
							* __SWAP16(fat_boot.sector_size));
	data_start_lba += __SWAP16(fat_boot.root_dir_entries)*0x20;
	data_start_lba /= 512;
	data_start_lba += boot_start_lba;
	
	//start of FAT data
	fat_start_lba = boot_start_lba+((__SWAP16(fat_boot.sector_size)*__SWAP16(fat_boot.reserved_sectors))/512);
	//read FAT
	fat = (uint16_t*) malloc(__SWAP16(fat_boot.fat_size_sectors)* __SWAP16(fat_boot.sector_size));
	fat16_read_fat(fat);

	cluster_size_bytes = __SWAP16(fat_boot.sector_size) * fat_boot.sectors_per_cluster;
	cluster_size_lba = cluster_size_bytes/512;
	return 1;
}