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
void game_init(void)
{
	loader_init();
	if (load_next()) {
		frame_handler = frame_error;
		return;
	}
		
	enter_title(); // title in fact
}
Esempio n. 3
0
_EGLDriver *
_EGL_MAIN(const char *args)
{
   const struct egl_g3d_loader *loader;
   _EGLDriver *drv;

   loader = loader_init();
   drv = egl_g3d_create_driver(loader);
   if (!drv) {
      loader_fini();
      return NULL;
   }

   drv->Name = "Gallium";
   drv->Unload = egl_g3d_unload;

   return drv;
}
Esempio n. 4
0
int gbcLoadRom(const char *filename)
{
	char *p;

    if (!loader_init(filename))
		return 0;

	strcpy(sram_filename, filename);
	p = strrchr(sram_filename, '.');
	if (p)
		*p = '\0';
	strcat(sram_filename, ".sav");

	sram_save_counter = SRAM_SAVE_LOOPS;
	gbcLoadSRAM();

    emu_reset();
    return 1;
}
Esempio n. 5
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. 6
0
int background_init(char * engine,char * keyword,int filter)
{
	int i;
	unsigned int engine_num;

	for(i=0; i<MAX_IMG; i++) {
		bg[i] = NULL;
	}

	engine_num = ENG_DEVIANTART;
	if( engine ) {
		engine_num = engine[0] - '0';
		if( engine_num >= ENG_NUM ) {
			printd(DEBUG_ERROR,"Unknown engine: %s\n",engine);
			return RET_FAIL;
		}
	}
	loader = loader_init(engine_num,DEF_MAX_IMAGE,keyword,SIZE_LARGE,filter);

	return RET_OK;
}
Esempio n. 7
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. 8
0
/*
	ok, this is pman init stage two. we will execute this code, and then jump to the process 
	manager main processing loop.
	
	What we will do here, is setup the page pool. And initialize System services, along with structures.
	Notice, we are now task 0 on the system.
*/	
void pman_init_stage2()
{
	UINT32 linear, physical; 
	struct pm_thread *pmthr = NULL;
	struct pm_task *pmtsk = NULL;
	int i = 0;
    int init_size = 0;
    
	/* get rid of the init stuff */
	destroy_thread(INIT_THREAD_NUM);
	destroy_task(INIT_TASK_NUM);
	
	/*
	Open used ports
	*/
	for(i = 0; i <= 12; i++)
	{
		open_port(i, 3, PRIV_LEVEL_ONLY);
	}
	
	/* 
		Init stage 1 has placed bootinfo at PMAN_MULTIBOOTINFO_PHYS 
		before initializing the pool we need to know memory size
		and that information is there. So lets map it on our page table.
	*/
	linear = PMAN_MULTIBOOT_LINEAR + SARTORIS_PROCBASE_LINEAR;
  	physical = PMAN_MULTIBOOT_PHYS; 

	map_pages(PMAN_TASK, linear, physical, PMAN_MULTIBOOT_PAGES, PGATT_WRITE_ENA, 2);

	/* Reallocate init image */
	init_size = init_reloc();

    pman_print_set_color(0x7);
	pman_print("Mapping Malloc %i pages", PMAN_MALLOC_PAGES);
       
	/* Pagein remaining pages for kmalloc */
	linear = PMAN_MALLOC_LINEAR + SARTORIS_PROCBASE_LINEAR; // place after multiboot (this will invalidate the map src/dest linear address, 
                                                            // we cannot use that area anymore, but it's ok, we used it for init copy only.)
  	physical = PMAN_MALLOC_PHYS; 

	map_pages(PMAN_TASK, linear, physical, PMAN_MALLOC_PAGES, PGATT_WRITE_ENA, 2);

	pman_print("Initializing tasks/threads.");

    /* Show MMAP information */
	if(((struct multiboot_info*)PMAN_MULTIBOOT_LINEAR)->flags & MB_INFO_MMAP && ((struct multiboot_info*)PMAN_MULTIBOOT_LINEAR)->mmap_length > 0)
	{		 
		//Calculate multiboot mmap linear address.
		//Sartoris loader left MMAP just after multiboot info structure.
		
		((struct multiboot_info*)PMAN_MULTIBOOT_LINEAR)->mmap_addr = PMAN_MULTIBOOT_LINEAR + sizeof(struct multiboot_info);

		pman_print("Multiboot MMAP Size: %i ", ((struct multiboot_info*)PMAN_MULTIBOOT_LINEAR)->mmap_length);
		pman_print("Multiboot mmap linear address: %x", ((struct multiboot_info*)PMAN_MULTIBOOT_LINEAR)->mmap_addr);

		struct mmap_entry *entry = NULL;
		entry = (struct mmap_entry *)((struct multiboot_info*)PMAN_MULTIBOOT_LINEAR)->mmap_addr;

		int kk = 0, mmlen = ((struct multiboot_info*)PMAN_MULTIBOOT_LINEAR)->mmap_length / entry->size;
		for(kk = 0; kk < mmlen; kk++)
		{
			pman_print("Multiboot entry size: %i start: %x end: %x type: %i", entry->size, (UINT32)entry->start, (UINT32)entry->end, entry->type);		

			entry = (struct mmap_entry *)((UINT32)entry + entry->size);
		}
	}
	else
	{
		pman_print("No MMAP present.");
	}

    /* Initialize vmm subsystem */
	vmm_init((struct multiboot_info*)PMAN_MULTIBOOT_LINEAR, PMAN_INIT_RELOC_PHYS, PMAN_INIT_RELOC_PHYS + init_size);
	
    tsk_init();
	thr_init();

	/* Mark SCHED_THR as taken! */
	pmtsk = tsk_create(PMAN_TASK);
	pmtsk->state = TSK_NORMAL;

    pmthr = thr_create(SCHED_THR, pmtsk);
	pmthr->state = THR_INTHNDL;		// ehm... well... it IS an interrupt handler :D
	pmthr->task_id = PMAN_TASK;
	pmthr->state = THR_INTHNDL;	
    
	pman_print("Initializing allocator and interrupts.");
    /* Initialize kernel memory allocator */
	kmem_init(PMAN_MALLOC_LINEAR, PMAN_MALLOC_PAGES);
	
	/* get our own interrupt handlers, override microkernel defaults */
	int_init();
	
	/* Initialize Scheduler subsystem */
	sch_init();
    
	pman_print("InitFS2 Service loading...");
	
	/* Load System Services and init Loader */
	loader_init((ADDR)PHYSICAL2LINEAR(PMAN_INIT_RELOC_PHYS));

	//pman_print_clr(7);
	pman_print("Loading finished, return INIT image memory to POOL...");

	/* Put now unused Init-Fs pages onto vmm managed address space again. */
	vmm_add_mem((struct multiboot_info*)PMAN_MULTIBOOT_LINEAR
				,PHYSICAL2LINEAR(PMAN_INIT_RELOC_PHYS)
				,PHYSICAL2LINEAR(PMAN_INIT_RELOC_PHYS + init_size));
	
	pman_print("Signals Initialization...");

	/* Initialize global signals container */
	init_signals();

	pman_print("Commands Initialization...");

	/* Initialize Commands subsystem. */
	cmd_init();

	pman_print_set_color(12);
	pman_print("PMAN: Initialization step 2 completed.");

	/* Create Scheduler int handler */
	if(create_int_handler(32, SCHED_THR, FALSE, 0) < 0)
		pman_print_and_stop("Could not create Scheduler thread.");

	/* This is it, we are finished! */
	process_manager();
}
Esempio n. 9
0
int
main(int ac, char **av, char **ep)
{
	int rc;
	cpu_t *cpu;
	xec_guest_info_t guest_info;
	xec_mem_if_t *mem_if;
	xec_monitor_t *monitor;
	xec_us_syscall_if_t *us_syscall;
	m88k_uintptr_t stack_top;
	nix_env_t *env;
	bool debugging = false;

	aspace_lock();

	if (ac < 2) {
		fprintf(stderr, "usage: %s <executable> [args...]\n", *av);
		exit(EXIT_FAILURE);
	}

	/* Initialize xec, nix and loader. */
	xec_init();
	obsd41_init();
	loader_init();

	/* Create CPU */
	cpu = cpu_new(CPU_ARCH_M88K, CPU_FLAG_ENDIAN_BIG, 0);
	if (cpu == NULL) {
		fprintf(stderr, "error: failed initializing M88K architecture.\n");
		exit(EXIT_FAILURE);
	}

	/* Create XEC bridge mem-if */
	mem_if = run88_new_mem_if();

	/* Create the XEC US Syscall */
	us_syscall = obsd41_us_syscall_create(mem_if);
	if (us_syscall == NULL) {
		fprintf(stderr, "error: failed creating xec userspace syscall.\n");
		exit(EXIT_FAILURE);
	}

	/* Create NIX env */
	env = nix_env_create(mem_if);
	if (env == NULL) {
		fprintf(stderr, "error: failed creating nix environment.\n");
		exit(EXIT_FAILURE);
	}

	/* Load the executable */
	rc = loader_load(mem_if, av[1]);
	if (rc != LOADER_SUCCESS) {
		fprintf(stderr, "error: cannot load executable '%s', error=%d.\n", av[1], rc);
		exit(EXIT_FAILURE);
	}

	/* Setup arguments */
	g_uframe_log = xec_log_register("uframe");

#ifndef DEBUGGER
	xec_log_disable("nix");
	xec_log_disable("openbsd41");
	xec_log_disable("uframe");
	xec_log_disable(NULL);
#endif

	openbsd_m88k_setup_uframe(cpu, mem_if, ac - 1, av + 1, ep, &stack_top);

	/* Setup the CPU */
	cpu_set_flags_codegen(cpu, CPU_CODEGEN_OPTIMIZE|CPU_CODEGEN_TAG_LIMIT);
	cpu_set_flags_debug(cpu, CPU_DEBUG_NONE);
	//cpu_set_flags_debug(cpu, CPU_DEBUG_SINGLESTEP_BB);
	cpu_set_flags_hint(cpu, CPU_HINT_TRAP_RETURNS_TWICE);
	cpu_set_ram(cpu, RAM);

	/* Create XEC bridge monitor */
	guest_info.name = cpu->info.name;
	guest_info.endian = (cpu->info.common_flags & CPU_FLAG_ENDIAN_MASK)
		== CPU_FLAG_ENDIAN_BIG ? XEC_ENDIAN_BIG : XEC_ENDIAN_LITTLE;
	guest_info.byte_size = cpu->info.byte_size;
	guest_info.word_size = cpu->info.word_size;
	guest_info.page_size = cpu->info.default_page_size;
	monitor = xec_monitor_create(&guest_info, mem_if, cpu->rf.grf, NULL);
	if (monitor == NULL) {
		fprintf(stderr, "error: failed createc xec monitor.\n");
		exit(EXIT_FAILURE);
	}

	/* Setup registers for execution */
	PC = g_ahdr.entry;

	R[31] = stack_top; // Stack Pointer
	R[1]  = -1;        // Return Address

	cpu->code_start = g_ahdr.tstart;
	cpu->code_end   = g_ahdr.tstart + g_ahdr.tsize;
	cpu->code_entry = g_ahdr.entry;

	cpu_tag(cpu, cpu->code_entry);

	dump_state(RAM, (m88k_grf_t*)cpu->rf.grf);

#ifdef DEBUGGER
	debugging = true;
#else
	fprintf(stderr, "Translating..."); fflush(stderr);
	cpu_translate(cpu);
	fprintf(stderr, "done.\n");
#endif

	aspace_unlock();

	for (;;) {
		if (debugging) {
			rc = cpu_debugger(cpu, debug_function);
			if (rc < 0) {
				debugging = false;
				continue;
			}
		} else {
			rc = cpu_run(cpu, debug_function);
		}

		switch (rc) {
			case JIT_RETURN_NOERR: /* JIT code wants us to end execution */
				break;

			case JIT_RETURN_FUNCNOTFOUND:
#ifndef DEBUGGER
				fprintf(stderr, "%s: error: 0x%llX not found!\n", __func__, (unsigned long long)PC);
				fprintf(stderr, "Translating..."); fflush(stderr);
				cpu_tag(cpu, PC);
				cpu_flush(cpu);
				cpu_translate(cpu);
				fprintf(stderr, "done.\n");
#else
				dump_state(RAM, (m88k_grf_t*)cpu->rf.grf);

				if (PC == (uint32_t)(-1U))
					goto exit_loop;

				// bad :(
				fprintf(stderr, "%s: warning: 0x%llX not found!\n", __func__, (unsigned long long)PC);
				fprintf(stderr, "PC: ");
				for (size_t i = 0; i < 16; i++)
					fprintf(stderr, "%02X ", RAM[PC+i]);
				fprintf(stderr, "\n");
				exit(EXIT_FAILURE);
#endif
				break;

			case JIT_RETURN_TRAP:
//				printf("TRAP %u / %u!\n", TRAPNO, R[13]);
				if (TRAPNO == 0x80 && R[13] == 1) // exit
					goto exit_loop;

//				printf("BEFORE:\n");
//				dump_state(RAM, (m88k_grf_t*)cpu->rf.grf);
				xec_us_syscall_dispatch(us_syscall, monitor);
//				printf("AFTER:\n");
//				dump_state(RAM, (m88k_grf_t*)cpu->rf.grf);
				break;

			case JIT_RETURN_SINGLESTEP:
				break;

			default:
				fprintf(stderr, "unknown return code: %d\n", rc);
				goto exit_loop;
		}

		if (cpu->flags_debug & (CPU_DEBUG_SINGLESTEP | CPU_DEBUG_SINGLESTEP_BB))
			cpu_flush(cpu);
	}

exit_loop:
	cpu_free(cpu);

	fprintf(stderr, ">> run88 success\n");
	exit(EXIT_SUCCESS);
}
Esempio n. 10
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;
}