コード例 #1
0
ファイル: invaders.c プロジェクト: Godzil/EDL
int main(int argc,char**argv)
{
	double	atStart,now,remain;

	/// Initialize GLFW 
	glfwInit(); 

	// Open registers OpenGL window 
	if( !(windows[REGISTER_WINDOW]=glfwCreateWindow( REGISTER_WIDTH, REGISTER_HEIGHT, "cpu",NULL,NULL)) ) 
	{ 
		glfwTerminate(); 
		return 1; 
	} 

	glfwSetWindowPos(windows[REGISTER_WINDOW],600,740);

	glfwMakeContextCurrent(windows[REGISTER_WINDOW]);
	setupGL(REGISTER_WINDOW,REGISTER_WIDTH,REGISTER_HEIGHT);

	// Open timing OpenGL window 
	if( !(windows[TIMING_WINDOW]=glfwCreateWindow( TIMING_WIDTH, TIMING_HEIGHT, "timing",NULL,NULL)) ) 
	{ 
		glfwTerminate(); 
		return 1; 
	} 

	glfwSetWindowPos(windows[TIMING_WINDOW],600,300);

	glfwMakeContextCurrent(windows[TIMING_WINDOW]);
	setupGL(TIMING_WINDOW,TIMING_WIDTH,TIMING_HEIGHT);

	// Open invaders OpenGL window 
	if( !(windows[MAIN_WINDOW]=glfwCreateWindow( WIDTH, HEIGHT, "invaders",NULL,NULL)) ) 
	{ 
		glfwTerminate(); 
		return 1; 
	} 

	glfwSetWindowPos(windows[MAIN_WINDOW],300,300);
	
	glfwMakeContextCurrent(windows[MAIN_WINDOW]);
	setupGL(MAIN_WINDOW,WIDTH,HEIGHT);

	glfwSwapInterval(0);			// Disable VSYNC

	glfwSetKeyCallback(windows[MAIN_WINDOW],kbHandler);
	glfwSetScrollCallback(windows[TIMING_WINDOW],mwHandler);

	atStart=glfwGetTime();
	//////////////////

	if (InitialiseMemory())
		return -1;
	
	PinSetRESET(1);
	PIN_BUFFER_RESET=1;
	PinSetO1(1);			// Run with reset high for a few cycles to perform a full cpu reset
	PinSetO1(0);
	PinSetO2(1);
	PinSetO2(0);
	PinSetO1(1);
	PinSetO1(0);
	PinSetO2(1);
	PinSetO2(0);
	PinSetO1(1);
	PinSetO1(0);
	PinSetO2(1);
	PinSetO2(0);
	PinSetRESET(0);			// RESET CPU
	PIN_BUFFER_RESET=0;

	//dumpInstruction=100000;

	int stopTheClock=0;
	while (!glfwGetKey(windows[MAIN_WINDOW],GLFW_KEY_ESCAPE))
	{
		
		if (!stopTheClock)
		{
			masterClock++;
			if ((masterClock%4)==0)
				pixelClock++;

			if ((masterClock%10)==0)
			{
								// I8080 emulation works off positive edge trigger. So we need to supply the same sort of
								// clock.
				PIN_BUFFER_O2=0;
				PIN_BUFFER_O1=1;
				PinSetO1(1);		// Execute a cpu step
				if (bTimingEnabled)
					RecordPins();
				PIN_BUFFER_O1=0;
				PinSetO1(0);
				if (bTimingEnabled)
					RecordPins();
				PIN_BUFFER_O2=1;
				PinSetO2(1);
				if (bTimingEnabled)
					RecordPins();
				PIN_BUFFER_O2=0;
				PinSetO2(0);

				if (!MEM_Handler())
				{
					stopTheClock=1;
				}
				if (bTimingEnabled)
					RecordPins();

				PinSetINT(0);		// clear interrupt state
				PIN_BUFFER_INT=0;
				cpuClock++;
			}
			if (pixelClock==30432+10161)		// Based on 19968000 Mhz master clock + mame notes
			{
				NEXTINT=0xCF;
				PinSetINT(1);
				PIN_BUFFER_INT=1;
			}
			if (pixelClock==71008+10161)
			{
				NEXTINT=0xD7;
				PinSetINT(1);
				PIN_BUFFER_INT=1;
			}
		}
		if (pixelClock>=83200 || stopTheClock)
		{
			if (pixelClock>=83200)
				pixelClock=0;

			if (glfwWindowShouldClose(windows[TIMING_WINDOW]))
			{
				bTimingEnabled=0;
				glfwHideWindow(windows[TIMING_WINDOW]);
			}
			if (glfwWindowShouldClose(windows[REGISTER_WINDOW]))
			{
				bRegisterEnabled=0;
				glfwHideWindow(windows[REGISTER_WINDOW]);
			}

            		glfwMakeContextCurrent(windows[MAIN_WINDOW]);
			ShowScreen(MAIN_WINDOW,WIDTH,HEIGHT);
			glfwSwapBuffers(windows[MAIN_WINDOW]);
				
			if (bTimingEnabled)
			{
				glfwMakeContextCurrent(windows[TIMING_WINDOW]);
				DrawTiming(videoMemory[TIMING_WINDOW],TIMING_WIDTH);
				ShowScreen(TIMING_WINDOW,TIMING_WIDTH,TIMING_HEIGHT);
				glfwSwapBuffers(windows[TIMING_WINDOW]);
			}
			if (bRegisterEnabled)
			{
				glfwMakeContextCurrent(windows[REGISTER_WINDOW]);
				DrawRegister(videoMemory[REGISTER_WINDOW],REGISTER_WIDTH);
				ShowScreen(REGISTER_WINDOW,REGISTER_WIDTH,REGISTER_HEIGHT);
				glfwSwapBuffers(windows[REGISTER_WINDOW]);
			}
        
			glfwPollEvents();
			
			g_traceStep=0;
			if (CheckKey(GLFW_KEY_PAUSE))
			{
				g_instructionStep^=1;
				if (stopTheClock && !g_instructionStep)
					stopTheClock=0;
				ClearKey(GLFW_KEY_PAUSE);
			}
			if (stopTheClock && CheckKey('S'))
			{
				stopTheClock=0;
				ClearKey('S');
			}
			if (stopTheClock && CheckKey('T'))
			{
				stopTheClock=0;
				g_traceStep=1;
				ClearKey('T');
			}

			now=glfwGetTime();

			remain = now-atStart;

			while ((remain<0.02f))
			{
				now=glfwGetTime();

				remain = now-atStart;
			}
			atStart=glfwGetTime();
		}
	}
	
	return 0;

}
コード例 #2
0
ファイル: main.c プロジェクト: PAntoine/stuuffs
int 	main()
{
	unsigned int	failed_count = 0;
	unsigned int	count;
	void*			memory;
	char*			alloc[1000];

	memory = malloc(1 * 1024 * 1024);

	InitialiseMemory(memory,(1*1024*1024));

		if (!MemoryConsistancyCheck())
		{
			printf("after init\n");
			DumpMemoryTable();
			exit(1);
		}

	DumpMemoryTable();

	for (count=1;count < 1000; count++)
	{
		if ((alloc[count] = AllocateMemory(1024)) == NULL)
		{
			failed_count++;
		}
	}
		if (!MemoryConsistancyCheck())
		{
			DumpMemoryTable();
			exit(1);
		}


	printf("Failed to allocate %d requests\n",failed_count);

	MemoryConsistancyCheck();
	printf("free 200\n");
	FreeMemory(alloc[200]);
	MemoryConsistancyCheck();
	printf("free 202\n");
	FreeMemory(alloc[202]);
	MemoryConsistancyCheck();
	printf("free 201\n");
	FreeMemory(alloc[201]);
	MemoryConsistancyCheck();


	printf("before the next set deletes\n");
	for (count=1;count < 10 /*00 - failed_count*/; count++)
	{
		FreeMemory(alloc[count]);
		alloc[count] = NULL;
		printf("free %d\n",count);
		MemoryConsistancyCheck();
	}

	for (count=400;count > 300 /*00 - failed_count*/; count--)
	{
		FreeMemory(alloc[count]);
		alloc[count] = NULL;
	}

	if (!MemoryConsistancyCheck())
	{
		DumpMemoryTable();
		exit(1);
	}

	DumpMemoryTable();

	{
		int i;
	for (i=0,count=100;count<400;count += 17)
	{
		printf("[%d] count: %d\n",i++,count);
		if (AllocateMemory(count) == NULL)
		{
			printf("second round of allocations: size %d\n",count);
		}
	}
	DumpMemoryTable();
	}

	/* free them again */
	for (count=1;count < 1000 - failed_count; count++)
	{
		if (alloc[count] != NULL)
			FreeMemory(alloc[count]);

		if (!MemoryConsistancyCheck())
		{
			printf("count: %d\n",count);
			DumpMemoryTable();
			exit(1);
		}
	}

	DumpMemoryTable();

	DumpStatistics();
}