예제 #1
0
/*
 * Main function.
 * Loops through the command-line interpreter until ready to play.
 * XXX implement argv
 */
int
main(int argc, char *argv[])
{

	while (1) {
		if (argc==1)
			gboy_init_interp(); // call the command-line interface
		else {
			argc=1;
			if ( (rom_fd=open(argv[1], O_RDWR)) == -1) {
				write(1, argv[1], strnlen(argv[1], 255));
				perror(" couldn't be opened.\nopen()");
			}
			else {
				printf("File %s opened\n", argv[1]);
			}
		}
		while (1) {
			/*
			 * start_vm() returns when the file opened doesn't represent
			 * a valid Game Boy ROM, or when the user chooses to change
			 * the ROM.
			 */
			if ((start_vm(rom_fd))==-1)
				printf("File not a gb binary\n\n");
			close(rom_fd);
			rom_fd=0;
			break;
		}
	}

	/* execution never gets here; the program exits through a callback function */
	return 0;
}
예제 #2
0
파일: main.c 프로젝트: agripin/corewar
int		main(int ac, char **av)
{
  unsigned char	board[MEM_SIZE];
  t_vm		*vm;
  t_dlist	*list;
  t_dlist	*list_s;

  if (ac < 2)
    return (0);
  list = NULL;
  list_s = NULL;
  list = new_list(list);
  list_s = new_list(list_s);
  init_board(board);
  vm = NULL;
  vm = new_vm(vm);
  fill_list(list, av);
  check_debug(list, vm);
  syntax(list);
  find_dump(list, vm);
  find_champ(list, vm, board, 0);
  id_champ(vm);
  champ_id_reg(vm);
  init_alive(vm);
  start_vm(vm, board);
  winning(vm);
  return (0);
}
예제 #3
0
void setUp(void)
{
    actual_state = Create_assert_cpu_image_t();
    expected_state = Create_assert_cpu_image_t();

    actual_mem = Create_assert_memory_map_t();
    expected_mem = Create_assert_memory_map_t();

    rom_file = fopen("/home/schambda/Projects/gameboy/projects/background_string/background_string.gb", "rb");
    TEST_ASSERT_NOT_NULL_MESSAGE(rom_file, "Unable to open ROM file");
    start_vm();
}
예제 #4
0
int main()
{
    char rom_path[PATH_MAX];

    printf("\nRealBoy %s\n", "0.2.2");

    sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);

    vita2d_init();
    vita2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));

    while (1) {
        strcpy(current_dir, "ux0:");

        int ret = file_choose(
                      current_dir,
                      rom_path,
                      "Choose a GB/GB Color/Super GB ROM:",
                      supported_ext
                  );

        if (ret == -1)
            break;

        if ( (rom_file = fopen(rom_path, "r")) == NULL) {
            printf("\nError opening %s\n", rom_path);
            continue;
        }

        file_path = strndup(rom_path, 256);

        if (rom_file != NULL)	{
            init_conf();
            int ret_val; // value returned from emulation
            /* Start Virtual Machine */
            ret_val = start_vm();
            /* Error returned if file not valid */
            if (ret_val == -1) {
                printf("File %s not a gb binary\n\n", rom_path);
            }
        }

        free(file_path);
    }

    vita2d_fini();

    sceKernelExitProcess(0);
    return 0;
}
예제 #5
0
파일: lily.c 프로젝트: pexcn/Lily
int main(int argc, char *argv[])
{
	int c;
	int is_default_name = true;
	int has_obj_name = false;
	char fn_in[100];
	char fn_out[100];
	char temp_name[100];
//	printf("%d",sizeof(OpCode));
	
	if(!find_source_file(argc,argv,fn_in)){
		fprintf(stderr,"no input file\n");
	}
	
	while((c=getopt(argc,argv,"xVvHhS:s:o:")) != -1){
        
		switch (c) {
        	case 'S':
        	case 's':
        		strcpy(temp_name,fn_in);
        		str_find_replace(temp_name,'.','\0');
        		strcat(temp_name,".s");
        		strcpy(fn_out,temp_name);
        		gen_op_code = true;
        		goto end;
        		break;
        	case 'x':
        		break;
            case 'o':
            	if(!file_name_vaild(optarg,'o')){
        			fprintf(stderr,"input file name is invaild\n");
        			return 0;
        		}
        		strcpy(fn_out,optarg);
        		is_default_name = false;
            	break;
        	case 'V':
        	case 'v':
        		version();
             	break;
            case 'H':
            case 'h':
            	help();
            	break;
        	default:
            	break;
        }
    }
    
end:
	input_stream = fopen(fn_in,"r+");
	
	if(gen_op_code){
		output_stream = fopen(fn_out,"w+");
		compile();
	}else{
		if(is_default_name){
			//str_find_replace(fn_in,'.','\0');	
        	//strcat(fn_in,".out");
        	//use fn_in to write file
        	output_stream = fopen("a.out","w+");
        	
		}else{
			output_stream = fopen(fn_out,"w+");
		}
		compile();
		process_struct_code();
		//write_binary_struct_code();
		init_vm();
		start_vm();
		
	}
    
	return 0;
}
예제 #6
0
파일: main.c 프로젝트: darksoul42/bitrig
int
vmmaction(struct parse_result *res)
{
	struct sockaddr_un	 sun;
	struct imsg		 imsg;
	int			 done = 0;
	int			 n;
	int			 ret, action;

	if (ctl_sock == -1) {
		if ((ctl_sock = socket(AF_UNIX,
		    SOCK_STREAM|SOCK_CLOEXEC, 0)) == -1)
			err(1, "socket");

		bzero(&sun, sizeof(sun));
		sun.sun_family = AF_UNIX;
		strlcpy(sun.sun_path, socket_name, sizeof(sun.sun_path));

		if (connect(ctl_sock,
		    (struct sockaddr *)&sun, sizeof(sun)) == -1)
			err(1, "connect: %s", socket_name);

		if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL)
			err(1, "malloc");
		imsg_init(ibuf, ctl_sock);
	}

	switch (res->action) {
	case CMD_START:
		/* XXX validation should be done in start_vm() */
		if (res->size < 1)
			errx(1, "specified memory size too small");
		if (res->path == NULL)
			errx(1, "no kernel specified");
		if (res->ndisks > VMM_MAX_DISKS_PER_VM)
			errx(1, "too many disks");
		else if (res->ndisks == 0)
			warnx("starting without disks");
		if (res->nifs == -1)
			res->nifs = 0;
		if (res->nifs == 0)
			warnx("starting without network interfaces");

		ret = start_vm(res->name, res->size, res->nifs,
		    res->ndisks, res->disks, res->path);
		if (ret) {
			errno = ret;
			err(1, "start VM operation failed");
		}
		break;
	case CMD_STOP:
		terminate_vm(res->id, res->name);
		break;
	case CMD_STATUS:
		get_info_vm(res->id, res->name, 0);
		break;
	case CMD_CONSOLE:
		get_info_vm(res->id, res->name, 1);
		break;
	case CMD_RELOAD:
		imsg_compose(ibuf, IMSG_VMDOP_RELOAD, 0, 0, -1,
		    res->path, res->path == NULL ? 0 : strlen(res->path) + 1);
		done = 1;
		break;
	case CMD_LOAD:
		imsg_compose(ibuf, IMSG_VMDOP_LOAD, 0, 0, -1,
		    res->path, res->path == NULL ? 0 : strlen(res->path) + 1);
		done = 1;
		break;
	case CMD_CREATE:
	case NONE:
		break;
	}

	action = res->action;
	parse_free(res);

	while (ibuf->w.queued)
		if (msgbuf_write(&ibuf->w) <= 0 && errno != EAGAIN)
			err(1, "write error");

	while (!done) {
		if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN)
			errx(1, "imsg_read error");
		if (n == 0)
			errx(1, "pipe closed");

		while (!done) {
			if ((n = imsg_get(ibuf, &imsg)) == -1)
				errx(1, "imsg_get error");
			if (n == 0)
				break;

			if (imsg.hdr.type == IMSG_CTL_FAIL) {
				if (IMSG_DATA_SIZE(&imsg) == sizeof(ret)) {
					memcpy(&ret, imsg.data, sizeof(ret));
					errno = ret;
					warn("command failed");
				} else {
					warnx("command failed");
				}
				done = 1;
				break;
			}

			ret = 0;
			switch (action) {
			case CMD_START:
				done = start_vm_complete(&imsg, &ret,
				    tty_autoconnect);
				break;
			case CMD_STOP:
				done = terminate_vm_complete(&imsg, &ret);
				break;
			case CMD_CONSOLE:
			case CMD_STATUS:
				done = add_info(&imsg, &ret);
				break;
			default:
				done = 1;
				break;
			}

			imsg_free(&imsg);
		}
	}

	return (0);
}