Exemplo n.º 1
0
int
main(int argc, char *argv[])
{
    int ch;
    cpu_t *cpu = init_cpu();
    char *sys_file;

    while ((ch = getopt(argc, argv, "df:")) != EOF) {
        switch (ch) {
            case 'd':
                cpu->debug = true;
                break;

            case 'f':
                sys_file = strdup(optarg);
                break;
        }
    }

    argc -= optind;
    argv += optind;

    init_disk(cpu->port0, "/tmp/disk0");

    load_cpu(cpu, sys_file);

    while (true)
        run_cpu(cpu);

    free_cpu(cpu);
    return 0;
}
Exemplo n.º 2
0
int main(int argc, char * argv[]) {
   
    cpu* local_cpu = create_cpu();

    // Load program:
    load_program(local_cpu->program, "C:\\Users\\Daniel\\Documents\\Projects\\snowbird\\programs\\div");
    
    // Run Program:
    run_cpu(local_cpu);
    
    free_cpu(local_cpu);
}
Exemplo n.º 3
0
void Ay_Core::end_frame( time_t* end )
{
	cpu.set_time( 0 );
	
	// Since detection of CPC mode will halve clock rate during the frame
	// and thus generate up to twice as much sound, we must generate half
	// as much until mode is known.
	if ( !(spectrum_mode | cpc_mode) )
		*end /= 2;
	
	while ( cpu.time() < *end )
	{
		run_cpu( min( *end, next_play ) );
		
		if ( cpu.time() >= next_play )
		{
			// next frame
			next_play += play_period;
			
			if ( cpu.r.iff1 )
			{
				// interrupt enabled
				
				if ( mem_.ram [cpu.r.pc] == 0x76 )
					cpu.r.pc++; // advance past HALT instruction
				
				cpu.r.iff1 = 0;
				cpu.r.iff2 = 0;
				
				mem_.ram [--cpu.r.sp] = byte (cpu.r.pc >> 8);
				mem_.ram [--cpu.r.sp] = byte (cpu.r.pc);
				
				// fixed interrupt
				cpu.r.pc = 0x38;
				cpu.adjust_time( 12 );
				
				if ( cpu.r.im == 2 )
				{
					// vectored interrupt
					addr_t addr = cpu.r.i * 0x100 + 0xFF;
					cpu.r.pc = mem_.ram [(addr + 1) & 0xFFFF] * 0x100 + mem_.ram [addr];
					cpu.adjust_time( 6 );
				}
			}
		}
	}
Exemplo n.º 4
0
int main(int argc, char* argv[]) {
  if (argc != 5) {
    printf("usage: cache-sim <set bits> <associativity> <block bits> <tracefile>\n");
    exit(1);
  }
  int sets   = atoi(argv[1]);
  int lines  = atoi(argv[2]);
  int blocks = atoi(argv[3]);
  char* file = argv[4];

  Cache* cache = make_cache(sets, lines, blocks);
  CPU*   cpu   = make_cpu(cache, file);

  run_cpu(cpu);

  delete_cpu(cpu);
  delete_cache(cache);
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
	printf("Begin\n");
	//Try and capture from a webcam
	CvCapture * capture = cvCaptureFromCAM(0);//CV_CAP_ANY);

	//If the capture failed, let the user know
	if(!capture){
		printf("Capture failed! %s\n", strerror(errno));
		return -1;
	}

	IplImage* img = cvQueryFrame(capture); 
	//cvCvtColor(img, img, CV_RGB2GRAY);
	int height,width,step,channels;
	unsigned char *data;
	int i,j,k;
	int key;

	// get the image data
	height    = img->height;
	width     = img->width;
	step      = img->widthStep;
	channels  = img->nChannels;
	data      = (unsigned char *)img->imageData;


	//Greyscaling code	
	IplImage *dest = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
	cvCvtColor(img, dest, CV_RGB2GRAY);
	
	printf("Starting the webcam feed\n");
	printf("Processing a %dx%d image with %d channels\n",height,width,channels); 

	wakeup();
	struct timeval start;
	struct timeval end;
	float elapsedtime;

	int op = 0;

	while (key != QUIT){	

		img = cvQueryFrame(capture);
		dest = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
		cvCvtColor(img, dest, CV_RGB2GRAY);
		
		data = (unsigned char *)dest->imageData;

		if(!img){
			break;
		}

		gettimeofday(&start, NULL);		
		
		if(op == 0)
			run_cpu(data, width, height, channels);
		else if(op == 1)
			run_gpu(data, width, height);
		else if(op == 2)
			run_gpu_op(data, width, height);
		else if(op == 3)
			run_gpu_shared_op(data, width, height);
		
		gettimeofday(&end, NULL);

		elapsedtime = (end.tv_sec - start.tv_sec) * 1000.0;
		elapsedtime += (end.tv_usec - start.tv_usec) / 1000.0;

		printf("FPS: %.2f\n", 1.0 / (elapsedtime / 100));

	
   		cvShowImage("mainWin", dest);
		key = cvWaitKey(1);

		switch(key) 
		{
			case OP:
				op = 1;
				break;
			case SH:
				op = 2;
				break;
			case OP_SHARED:
				op = 3;
				break;
			case UN:
				op = 0;
				break;
		}
	}



	//Do the computaiton here


	// release the image
	cvReleaseImage(&dest );
	return 0;

}
Exemplo n.º 6
0
int main(int argc, char **argv)
{
	int datasize = 10;
	int debug = 0;
	int usestdin = 0;
	int o;
	extern int optind;

	while ((o = getopt(argc, argv, "ds")) != -1) {
		switch (o) {
		case 'd':
			debug = 1;
			break;
		case 's':
			usestdin = 1;
			break;
		default:
			usage(argv[0]);
			exit(EXIT_SUCCESS);
		}
	}

	if (optind >= argc) {
		usage(argv[0]);
		exit(EXIT_SUCCESS);
	}
	char *input = argv[optind];

	FILE *f;
	struct stat st;
	if ((f = fopen(input, "rb")) == NULL) {
		perror(argv[0]);
		exit(EXIT_FAILURE);
	}
	if (fstat(fileno(f), &st) < 0) {
		perror(argv[0]);
		exit(EXIT_FAILURE);
	}

	uint8_t *code;
	if ((code = malloc(st.st_size)) == NULL) {
		perror(argv[0]);
		exit(EXIT_FAILURE);
	}
	if ((fread(code, 1, st.st_size, f)) != st.st_size) {
		fprintf(stderr, "%s: error reading input file\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	fclose(f);

	struct cpu *cpu = new_cpu(datasize);
	if (cpu == NULL) {
		fprintf(stderr, "error: can't create CPU\n");
		exit(EXIT_FAILURE);
	}

	cpu->debug = debug;
	cpu->exception = exception;
	if (usestdin) {
		cpu->inbox = stdinbox;
	} else {
		cpu->inbox = inbox;
	}
	cpu->outbox = outbox;

	if (load_code(cpu, code, st.st_size) < 0) {
		fprintf(stderr, "error: can't load code\n");
		exit(EXIT_FAILURE);
	}
	free(code);

	cpu->data[9] = 0;

	run_cpu(cpu);

	printf("Executed %d instructions\n", cpu->clock);
	
	exit(EXIT_SUCCESS);
}