Exemplo n.º 1
0
void Init(struct Gamestate* state)
{
	EnableDebugOutput(DEBUG_USART);
	printf("Init\r\n");

	InitializeLEDs();

	SetLEDs(0x01);
	SetLEDs(0x07);

#ifdef ACCELEROMETER
/*	InitializeAccelerometer();
	printf("Init Accelerometer: %s\r\n", PingAccelerometer() > 0 ? "OKAY" : "FAILED");
	CalibrateAccelerometer();*/
#endif

	for(int i=0;i<NumberOfStars;i++)
	{
		stars[i].x=GetRandomInteger()%360;
		stars[i].y=(GetRandomInteger()%200);

		int z=sqrti((NumberOfStars-1-i)*NumberOfStars)*1000/NumberOfStars;
		stars[i].dy=1;//6000*1200/(z+200);

		stars[i].f=(6-(z*7)/1000)+(GetRandomInteger()%6)*7;
	}
}
Exemplo n.º 2
0
int main()
{
	// Do some basic initialization tasks
	InitializeSystem();

	// Initialize pins for LEDs
	InitializeLEDs();

	// Enable printf via trace macrocell (get output with 'make trace')
	EnableDebugOutput(DEBUG_ITM);
	//printf("step\n %d");
	//Turn on all LEDs
	_Bool isOn = 0;
	int val = 1 | 2 | 4 | 8;
	while (1) {
		if (isOn == 0) {
			val = (val<<1) | (val<0);
			SetLEDs(val);
			isOn = 1;
		} else {
			SetLEDs(0 | 0 | 0 | 0);
			isOn = 0;
			iprintf("test\r\n");
		}
		Delay( 10 );
	}
}
Exemplo n.º 3
0
int main()
{
	// Do some basic initialization tasks
	InitializeSystem();

	EnableDebugOutput(DEBUG_ITM);

	// Enable clock for GPIOA and GPIOC peripheral
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

	// Set Pin modes for PA8 (SCL)
	GPIO_Init(GPIOA, &(GPIO_InitTypeDef){
		.GPIO_Speed = GPIO_Speed_2MHz,
		.GPIO_Mode = GPIO_Mode_AF,		//Not OUT, but AF = Alternate Function
		.GPIO_OType = GPIO_OType_OD,
		.GPIO_PuPd = GPIO_PuPd_NOPULL,	//External pullups, so none here
		.GPIO_Pin = GPIO_Pin_8
	});
Exemplo n.º 4
0
int main()
{
	RCC_ClocksTypeDef RCC_Clocks;
	RCC_GetClocksFreq(&RCC_Clocks);

	SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

	InitializeLEDs();
	InitializeUserInterface();
	InitializeRandom();
	InitializeRumble();

	//Clear framebuffers
	memset(ADDR_FRAMEBUFFER1, 0x00, 320*200);
	memset(ADDR_FRAMEBUFFER2, 0x00, 320*200);

	//Create drawing surfaces
	InitializeBitmap(&frame1,320,200,320,ADDR_FRAMEBUFFER1);
	InitializeBitmap(&frame2,320,200,320,ADDR_FRAMEBUFFER2);

	//Switch on VGA
	IntializeVGAScreenMode320x200(ADDR_FRAMEBUFFER1);

	if(!TheGame) {
		EnableDebugOutput(DEBUG_USART);
		fprintf(stderr, "PANIC: Game structure pointer is NULL\r\n");
		return -1;
	}

	if(TheGame->currentState)
		TheGame->currentState->Init(NULL);

	if(!TheGame->currentState->Update || !TheGame->currentState->Draw) {
		fprintf(stderr, "PANIC: Update and/or Draw function pointer is NULL\r\n");
		return -1;
	}

	Gamestate *currentState = TheGame->currentState;

	while(1)
	{
		oldTime = currentTime;
		currentTime = SysTickCounter;
		if (currentState != TheGame->currentState)
		{
			Gamestate *newState = TheGame->currentState;
			if (!newState->initialized) {
				newState->Init(currentState);
				newState->initialized = true;
			}
			if (newState->OnEnter)
				newState->OnEnter(currentState);
			currentState = newState;
		}

		//Swap Buffers
		if(frame&1) { drawingSurface=&frame2; SetFrameBuffer(ADDR_FRAMEBUFFER1); }
		else { drawingSurface=&frame1; SetFrameBuffer(ADDR_FRAMEBUFFER2); }

		//Update and draw
		currentState->Update(currentTime - oldTime);
		currentState->Draw(drawingSurface);

		frame++;

		if (currentState != TheGame->currentState &&
			TheGame->currentState->OnLeave)
		{
			currentState->OnLeave(currentState);
		}
		//VSync
		WaitVBL();
	}
}
Exemplo n.º 5
0
void Init(struct Gamestate* state)
{
	EnableDebugOutput(DEBUG_USART);
	printf("Init controller test\r\n");
	setFont(fontblack8);
}
Exemplo n.º 6
0
void Init(struct Gamestate* state)
{
	EnableDebugOutput(DEBUG_USART);
	printf("Init\r\n");
	setFont(fontblack8);

	InitializeFilesystem();

	//Open a file
	FILE* file = fopen("0:TESTFILE", "w+");
	if(!file) {
		perror("fopen()");
		goto fs_err;
	}
	printf("opened file: %x\r\n", (uint32_t)file);

	//Write to file
	const char* writecontent = "This is a test";
	int res = fwrite(writecontent, 1, strlen(writecontent), file);
	if(!res) {
		if(ferror(file))
			printf("Error occured\r\n");
		perror("fwrite()");
		goto fs_err;
	}
	printf("wrote file: %x\r\n", res);

	//Seek to start
	res = fseek(file, 0, SEEK_SET);
	if(res == -1) {
		perror("fseek()");
		goto fs_err;
	}
	printf("seeked file: %x\r\n", res);

	//Read file
	char readcontent[256];
	res = fread(readcontent, 1, 255, file);
	if(!res) {
		if(ferror(file))
			printf("Error occured\r\n");
		if(feof(file))
			printf("EOF occured\r\n");
		perror("fread()");
		goto fs_err;
	}
	readcontent[res] = '\0';
	printf("read file: %x\r\n", res);
	printf("content: %s\r\n", readcontent);

fs_err:
	//Close file
	res = fclose(file);
	if(res != 0) {
		perror("fclose()");
		goto fs_err;
	}
	printf("closed file: %x\r\n", res);

	DeinitializeFilesystem();
}
Exemplo n.º 7
0
void Init(struct Gamestate* state)
{
	EnableDebugOutput(DEBUG_USART);
	printf("Init State\r\n");
}