Esempio n. 1
0
extern "C" DLL_EXPORT void CDECL_CALL EmuMain(char *rom)
{
    int i;
    char *s;

    /* If we have special perms, drop them ASAP! */
    vid_preinit();

    init_exports();

    s = strdup(".");
    sys_sanitize(s);
    sys_initpath(s);

    for (i = 0; defaultconfig[i]; i++)
        rc_command(defaultconfig[i]);

    /* FIXME - make interface modules responsible for atexit() */
    atexit(shutdown);
    catch_signals();
    vid_init();
    pcm_init();

    rom = strdup(rom);
    sys_sanitize(rom);

    loader_init(rom);

    emu_reset();
    emu_run();
}
Esempio n. 2
0
int main(int argc, char **argv) {
  const char *appdir = fs_appdir();

  if (!fs_mkdir(appdir)) {
    LOG_FATAL("Failed to create app directory %s", appdir);
  }

  // load base options from config
  char config[PATH_MAX] = {0};
  snprintf(config, sizeof(config), "%s" PATH_SEPARATOR "config", appdir);
  options_read(config);

  // override options from the command line
  options_parse(&argc, &argv);

  if (OPTION_help) {
    options_print_help();
    return EXIT_SUCCESS;
  }

  if (!exception_handler_install()) {
    LOG_WARNING("Failed to initialize exception handler");
    return EXIT_FAILURE;
  }

  struct window *window = win_create();
  if (!window) {
    LOG_WARNING("Failed to initialize window");
    return EXIT_FAILURE;
  }

  const char *load = argc > 1 ? argv[1] : NULL;
  if (load && strstr(load, ".trace")) {
    struct tracer *tracer = tracer_create(window);
    tracer_run(tracer, load);
    tracer_destroy(tracer);
  } else {
    struct emu *emu = emu_create(window);
    emu_run(emu, load);
    emu_destroy(emu);
  }

  win_destroy(window);

  exception_handler_uninstall();

  // persist options for next run
  options_write(config);

  return EXIT_SUCCESS;
}
Esempio n. 3
0
static int gnuboy_main(const char *rom)
{
    rb->lcd_puts(0,0,"Init video");
    vid_init();
    rb->lcd_puts(0,1,"Init sound");
    pcm_init();
    rb->lcd_puts(0,2,"Loading rom");
    loader_init(rom);
    if(shut)
        return PLUGIN_ERROR;
    rb->lcd_puts(0,3,"Emu reset");
    emu_reset();
    rb->lcd_puts(0,4,"Emu run");
    rb->lcd_clear_display();
    rb->lcd_update();
    emu_run();

    /* never reached */
    return PLUGIN_OK;
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
	int i;
	char *opt, *arg, *cmd, *s, *rom = 0;

	/* Avoid initializing video if we don't have to */
	for (i = 1; i < argc; i++)
	{
		if (!strcmp(argv[i], "--help"))
			help(base(argv[0]));
		else if (!strcmp(argv[i], "--version"))
			version(base(argv[0]));
		else if (!strcmp(argv[i], "--copying"))
			copying();
		else if (!strcmp(argv[i], "--bind")) i += 2;
		else if (!strcmp(argv[i], "--source")) i++;
		else if (!strcmp(argv[i], "--showvars"))
		{
			show_exports();
			exit(0);
		}
		else if (argv[i][0] == '-' && argv[i][1] == '-');
		else if (argv[i][0] == '-' && argv[i][1]);
		else rom = argv[i];
	}
	
	if (!rom) usage(base(argv[0]));

	/* If we have special perms, drop them ASAP! */
	vid_preinit();

	init_exports();

	s = strdup(argv[0]);
	sys_sanitize(s);
	sys_initpath(s);

	for (i = 0; defaultconfig[i]; i++)
		rc_command(defaultconfig[i]);

	for (i = 1; i < argc; i++)
	{
		if (!strcmp(argv[i], "--bind"))
		{
			if (i + 2 >= argc) die("missing arguments to bind\n");
			cmd = malloc(strlen(argv[i+1]) + strlen(argv[i+2]) + 9);
			sprintf(cmd, "bind %s \"%s\"", argv[i+1], argv[i+2]);
			rc_command(cmd);
			free(cmd);
			i += 2;
		}
		else if (!strcmp(argv[i], "--source"))
		{
			if (i + 1 >= argc) die("missing argument to source\n");
			cmd = malloc(strlen(argv[i+1]) + 6);
			sprintf(cmd, "source %s", argv[++i]);
			rc_command(cmd);
			free(cmd);
		}
		else if (!strncmp(argv[i], "--no-", 5))
		{
			opt = strdup(argv[i]+5);
			while ((s = strchr(opt, '-'))) *s = '_';
			cmd = malloc(strlen(opt) + 7);
			sprintf(cmd, "set %s 0", opt);
			rc_command(cmd);
			free(cmd);
			free(opt);
		}
		else if (argv[i][0] == '-' && argv[i][1] == '-')
		{
			opt = strdup(argv[i]+2);
			if ((s = strchr(opt, '=')))
			{
				*s = 0;
				arg = s+1;
			}
			else arg = "1";
			while ((s = strchr(opt, '-'))) *s = '_';
			while ((s = strchr(arg, ','))) *s = ' ';
			
			cmd = malloc(strlen(opt) + strlen(arg) + 6);
			sprintf(cmd, "set %s %s", opt, arg);
			
			rc_command(cmd);
			free(cmd);
			free(opt);
		}
		/* short options not yet implemented */
		else if (argv[i][0] == '-' && argv[i][1]);
	}

	/* FIXME - make interface modules responsible for atexit() */
	atexit(shutdown);
	catch_signals();
	vid_init();
	pcm_init();

	rom = strdup(rom);
	sys_sanitize(rom);
	
	loader_init(rom);
	
	emu_reset();
	emu_run();

	/* never reached */
	return 0;
}
Esempio n. 5
0
File: main.c Progetto: cjbrowne/Emma
int main(int argc, char **argv)
{
  assert(HEAPSIZE < MAXSIZE_FILE); // otherwise config.h is screwed
	int i=0,rv=0;
  int first_byte=0,second_byte=0;
  FILE* infile = NULL;
	ramword_t *inputbuffer = NULL;
  stack_t* stack = NULL;
  ramaddr_t* heap = NULL;
  cpu_t* cpu = NULL;
	switch(argc)
	{
		case 0:
			printf("Unsuitable environment (argc==0)\n");
			rv = -1;
		case 1:
			printf("Usage: emma input\n");
			rv = -1;
		case 2:
			if((infile = fopen(argv[1],"r")) == NULL)
			{
				printf("[error] could not open input file, check permissions.\n");
				rv = -1;
			}
			break;
		default:
			printf("Usage: emma input\n");
			rv = -1;
	}
  // if we're successful, get on with the business of the day
  if(rv==0)
  {
    // initialize the CPU
    cpu = malloc(sizeof(cpu_t));
    if(cpu == NULL) return -1; // error
    memset(cpu,0,sizeof(cpu_t));
    if((inputbuffer = malloc(MAXSIZE_FILE * sizeof(*inputbuffer)))==NULL) return -1;
    stack = st_create(STACKSIZE);
    #ifdef EMMA_DEBUG
    fprintf(stderr,"HEAPSIZE: %d\n",HEAPSIZE);
    #endif
    heap = heap_init(HEAPSIZE);
    
    // read the file into memory (more complex than it first seemed)
    while(((first_byte = getc(infile)) != EOF)&&((second_byte = getc(infile)) != EOF)) {
      inputbuffer[i] = (first_byte<<8) | second_byte;
      i++;
      if(i>=MAXSIZE_FILE) break; // this fixes the cause of a segfault
    }
    
    #ifdef EMMA_DEBUG
    int j=0;
    printf("Loaded program: ");
    while(j<i)
    {
      printf("%.4X ",inputbuffer[j]);
      j++;
    }
    putchar('\n');
    #endif
    
    // warn about program truncation
    if(i > HEAPSIZE) 
    {
      #ifdef EMMA_DEBUG
      printf("Warning: input file \"%s\" has been truncated\n",argv[1]);
      #endif
      #ifdef FATAL_ERRORS
      rv = -1;
      #endif
    }
    
    // move the input buffer onto the heap at offset 0x0000, truncated to HEAPSIZE
    if(!heap_load(heap,inputbuffer,HEAPSIZE))
    {
      #ifdef EMMA_DEBUG
      printf("Error: heap loading failed\n");
      #endif
      #ifdef FATAL_ERRORS
      rv = -1;
      #endif
    }
    
    // the input buffer is no longer necessary, so we should free it
    free(inputbuffer);
    
    // set up the cpu with the stack and the heap
    cpu->stack = stack;
    cpu->pc = heap;
    
    if(rv==0)
    {
      // set the program running, return the state of the CPU at exit
      cpu = emu_run(cpu);
    }
    
    #ifdef EMMA_DEBUG
    if((cpu->flag_reg & FLAG_ERROR)!=0) // this if was previously backwards
    {
      printf("Program halted with error: %.2X\n",cpu->errno);
      core_dump(cpu);
    }
    #endif
    
    // shutdown safely (free any used memory)
    st_free(stack);
    heap_free(heap);
    free(cpu);
    fclose(infile);
  }
	return rv;
}
Esempio n. 6
0
int app_main(int argc,char** argv)
{
    char * rom;		
/*
		 to use the medios browser you have to define USE_MEDIOS_BROWSER. This completely changes the way the emu works, it mapps button_off
		 to exit the emulator and return to the browser, While exit in the emu ingame menu still completly exits.
		 Cj tell me if you want to do it this way and also let me know if it works for you?
*/

    int i;
    for(i=0;i<argc;i++) printf("%d:%s\n",i,argv[i]);

#ifdef USE_MEDIOS_BROWSER
	while(1)
	{
		osd_setEntirePalette(gui_pal,256);
		gfx_planeSetSize(BMAP1,LCD_WIDTH,LCD_HEIGHT,8);
		gfx_planeSetPos(BMAP1,X_OFFSET,Y_OFFSET);
		iniIcon();
		gfx_openGraphics();
		clearScreen(COLOR_WHITE);
		gfx_fontSet(STD6X9);
		if(argc<2) {
                   ini_file_browser();
		   rom=browse("/",1);
		}
                else {
                  rom = (char *)malloc(MAX_PATH);
                  strcpy(rom,argv[1]);
                }
		if (rom=='0')
		{
			cleanup();
			reload_firmware();
		}
		gfx_openGraphics();
		OSD_BITMAP1_ADDRESS = (int)gfx_planeGetBufferOffset(BMAP1);
		gfx_planeSetSize(BMAP1,160,144,8);
		gfx_planeSetPos(BMAP1,(LCD_WIDTH-OSD_BITMAP1_WIDTH) + X_OFFSET,(LCD_HEIGHT-OSD_BITMAP1_HEIGHT)/2 + Y_OFFSET);
		
		gfx_fillRect(0x00,0,0,160,144);
		
		gfx_fontSet(10);   

    vid_init();
    pcm_init();

    //rom = (char *)malloc(MAX_PATH);
    printf("Rom name : %s\n",rom);
    
    loader_init(rom);

    emu_reset();
    emu_run();
	} 
#endif
#ifndef USE_MEDIOS_BROWSER
		//this uses the avBoy browser and is the default
    gfx_openGraphics();
    OSD_BITMAP1_ADDRESS = (int)gfx_planeGetBufferOffset(BMAP1);
    gfx_planeSetSize(BMAP1,160,144,8);
		gfx_planeSetPos(BMAP1,(LCD_WIDTH-OSD_BITMAP1_WIDTH) + X_OFFSET,(LCD_HEIGHT-OSD_BITMAP1_HEIGHT)/2 + Y_OFFSET);
    
    gfx_fillRect(0x00,0,0,160,144);

    gfx_fontSet(10);   
    
    vid_init();
    pcm_init();
    
    rom = (char *)malloc(MAX_PATH);
    
    printf("argc = %d, argv = %x\n",argc,argv);

    if(argc<2) browser(rom);
    else strcpy(rom,argv[1]);
    
    //browser(rom);
    printf("Rom name : %s (%x,%x)\n",rom,rom,rom+MAX_PATH);

    loader_init(rom);

    emu_reset();
    emu_run();
#endif
    printf("before return\n");
    return 0;
}