Esempio n. 1
0
bool emu_load_cart(const char *file_name) {
	FILE *f = fopen(file_name, "rb");
	if (f) {
		// Détermine la taille du fichier
		unsigned size = get_file_size(f);
		// Garde pour les sauvegardes d'état
		strcpy(emu_file_name, file_name);
		// Au moins un tableau couvrant la map 0000-7FFF...
		size = max(size, 0x8000);
		// Et multiple d'une page (arrondissement à la page supérieure)
		size = ((size + 0x3FFF) / 0x4000) * 0x4000;
		mem_rom = malloc(size);
		// La cartouche préparée, prépare le CPU
		cpu_init();
		lcd_init();
		sound_init();
		mem_init();
		// Charge le contenu
		fread(mem_rom, size, 1, f);
		fclose(f);
		// Démarrage
		mbc_init(size);
		load_sram();
		// Color-It
		ColorIt_init(file_name, mem_rom);
		return true;
	}
	return false;
}
Esempio n. 2
0
int rom_load(char * rpath)
{
	char tmp[PATH_MAX];
	int romsize, ramsize;

	strcpy(RomPath,rpath);

	strcpy(tmp, RomPath);
	*(strrchr(tmp,'/')+1) = 0;
	strcpy(setting2.lastpath, tmp);
	
	bTurbo = 0;
	

	gb_destroy();
	gb_init();
	
	// Žw’肵‚œƒtƒ@ƒCƒ‹‚ðƒ[ƒh‚·‚éB by ruka
	romsize = load_rom(RomPath);
	if (!romsize){
		renderer_set_msg("ROM Load Failed");
		return -1;
	}

	ramsize = load_sram(SramPath);
	
	if (!gb_load_rom(rom_image, romsize, sram_space, ramsize)){
		renderer_set_msg("ROM Load Failed");
		return -1;
	}

	if(org_gbtype==1)
		renderer_set_msg("ROM TYPE:GB");
	else if(org_gbtype==2)
		renderer_set_msg("ROM TYPE:SGB");
	else if(org_gbtype==3)
		renderer_set_msg("ROM TYPE:GBC");
	


	free_rewind_states();
	allocate_rewind_states();

	set_gb_type();
			
	return romsize;
}
Esempio n. 3
0
/**
 * @brief User entry point in driver/simulator ioctl routine.
 *
 * @param proceed -- if standard code execution should be proceed
 * @param sptr    -- statics table pointer
 * @param f       -- file pointer. Lynx/Linux specific.
 *                   See (sys/file.h) for Lynx and (linux/fs.h) for Linux.
 * @param lun     -- minor number (LUN)
 * @param com     -- ioctl number
 * @param arg     -- ioctl arguments
 *
 * It's up to user to set kernel-level errno (by means of @e pseterr call).
 * @e proceed parameter denotes if further standard actions should be proceed
 * after function returns. @b FALSE - means that user-desired operation done
 * all that user wants and there is no further necessaty to perfom any standard
 * operations that follow function call. @b TRUE - means that code that follows
 * function call will be executed.
 *
 * @return return value is the same as in entry point function\n
 *         OK     - if succeed.\n
 *         SYSERR - in case of failure.
 */
int CvorbUserIoctl(int *proceed, register CVORBStatics_t *sptr,
			 struct file *f, int lun, int com, char *arg)
{
	CVORBUserStatics_t *usp = sptr->usrst; /* user statistics table */
	ushort edp[3]; /* [select/get function] ioctl parameters
			  [0] -- module idx
			  [1] -- chan idx
			  [2] -- func idx */
	*proceed = FALSE;

	switch (com) {
	case CVORB_VHDL:
		return read_vhdl(usp, arg);
	case CVORB_PCB:
		return read_pcb(usp, arg);
	case CVORB_TEMP:
		return read_temp(usp, arg);
	case CVORB_MOD_CFG_RD:
		return read_mod_config_reg(usp, arg);
	case CVORB_MOD_CFG_WR:
		return write_mod_config_reg(usp, arg);
	case CVORB_CH_CFG_RD:
		return read_ch_config_reg(usp, arg);
	case CVORB_CH_CFG_WR:
		return write_ch_config_reg(usp, arg);
	case CVORB_MOD_STAT:
		return read_mod_stat(usp, arg);
	case CVORB_CH_STAT:
		return read_ch_stat(usp, arg);
	case CVORB_LOAD_SRAM:
		return load_sram(usp, arg);
	case CVORB_READ_SRAM:
		return read_sram(usp, arg);
	case CVORB_FEN: /* enable function in the function bitmask */
		return enable_function(usp, arg);
	case CVORB_FDIS: /* disable function in the function bitmask */
		return disable_function(usp, arg);
	case CVORB_FEN_RD: /* read Funciton Enable Mask */
		{
			uint m[2]; /* [0] -- bits[63-32]
				      [1] -- bits[31-0] */

			/* ioctl parameters */
			struct {
				ushort m; /* module idx */
				ushort c; /* channel idx */
				uint  *p; /* results goes here */
			} par;

			if (cdcm_copy_from_user(&par, arg, sizeof(par)))
				return SYSERR;

			m[0] = _rcr(par.m, par.c, FCT_EM_H);
			m[1] = _rcr(par.m, par.c, FCT_EM_L);
			return cdcm_copy_to_user(par.p, m, sizeof(m));
		}
	case CVORB_FEN_WR: /* write Function Enable Mask */
		return write_fem_regs(usp, arg);
	case CVORB_FUNC_SEL: /* select function to be played */
		if (cdcm_copy_from_user(&edp, arg, sizeof(edp)))
			return SYSERR;
		_wcr(edp[0], edp[1], FUNC_SEL, edp[2]);
		/* Should wait on Channel Status register bit[9] -- function
		   copy in progress, when data is copying into local SRAM. */
		while(_rcr(edp[0], edp[1], CH_STAT) & 1<<9)
			usec_sleep(1);
		return OK;
	case CVORB_FUNC_GET:	/* get currently selected function */
		if (cdcm_copy_from_user(&edp, arg, sizeof(edp)))
			return SYSERR;
		return _rcr(edp[0], edp[1], FUNC_SEL);
	case CVORB_WRSWP: /* action register.
			     Simulate front panel pulse inputs */
		return write_swp(usp, arg);
	case CVORB_RC_RD:
		return read_recurrent_cycles_reg(usp, arg);
	case CVORB_RC_WR:
		return write_recurrent_cycles_reg(usp, arg);
	case CVORB_DAC_ON:
		return dac_on(usp, arg);
	case CVORB_DAC_OFF:
		/* disable on-board clock generator */
		_wr(0, CLK_GEN_CNTL, AD9516_OFF);
		return OK;
	case AD9516_GET_PLL:
		return get_pll(usp, arg);
	case CVORB_WR_SAR:
		return write_sar(usp, arg);
	default:
		*proceed = TRUE; /* continue standard code execution */
	}

	return OK;
}
int genesis_init() {
    static int bfirstRun = true;

    if (bfirstRun) {
        FirstRun();
        bfirstRun = false;
    }

    /* set default config */
    error_init();
    set_config_defaults();

    /* Load ROM file */
    cart.rom = (unsigned char*) malloc(10 * 1024 * 1024);
    memset(cart.rom, 0, 10 * 1024 * 1024);
    //
    //if (!load_rom("uda:/sonic.smd")) {
    if (!load_rom(romname)) {
        char buf[1024];
        sprintf(buf, "Error loading file `%s'.", romname);
        ErrorPrompt(buf);
        free(cart.rom);
        return 1;
    }

    // now running
    running = 1;
    // not exit
    gen_exit = 0;

    SYSInputReset();

    /* load BIOS */
    memset(bios_rom, 0, sizeof (bios_rom));
    FILE *f = fopen(OS_ROM, "rb");
    if (f != NULL) {
        fread(&bios_rom, 0x800, 1, f);
        fclose(f);
        int i;
        for (i = 0; i < 0x800; i += 2) {
            uint8 temp = bios_rom[i];
            bios_rom[i] = bios_rom[i + 1];
            bios_rom[i + 1] = temp;
        }
        config.tmss |= 2;
    }

    /* initialize Genesis virtual system */
    memset(&bitmap, 0, sizeof (t_bitmap));
//    bitmap.width = g_pTexture->width;
//    bitmap.height = g_pTexture->height;
//    bitmap.pitch = g_pTexture->wpitch;

    bitmap.width = 1024;
    bitmap.height = 576;
    bitmap.pitch = bitmap.width * 4;
    
    bitmap.data = screen;
    bitmap.viewport.changed = 3;

    //config.overscan = 0; // disabled


    /* initialize emulation */
    printf("audio_init\r\n");
    audio_init(SOUND_FREQUENCY, vdp_pal ? 50.0 : 60.0);
    printf("system_init\r\n");
    system_init();

    printf("sramname\r\n");
    /* load SRAM */
    if (gensettings.saves & SAVES_SRAM) {
        load_sram(sramname);
    }
    
    
    /* user cfg */
    SetGenConfig();


    /* reset emulation */
    system_reset();

    /* run 1 frame */
    system_frame(0);

    if (gensettings.saves & SAVES_STATES) {
        load_state(statename);
    }

    return 0;
}
Esempio n. 5
0
File: main.c Progetto: rtobar/imanes
int main(int args, char *argv[]) {

	char *save_file;
	ines_file *nes_rom;

	/* Print NOW everything :D */
#ifdef _MSC_VER
	setvbuf(stdout,NULL,_IONBF,0);
	setvbuf(stderr,NULL,_IONBF,0);
#else
	setbuf(stdout,NULL);
	setbuf(stderr,NULL);
#endif

	/* i18n stuff */
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	/* Parse command line options */
	initialize_configuration();
	switch ( parse_options(args, argv) ) {
		case -1:
			usage(stderr,argv);
			exit(EXIT_FAILURE);
		case 0:
			exit(EXIT_SUCCESS);
		default:
			break;
	}

	load_user_configuration();

	/* Initialize static data */
	initialize_palette();
	initialize_instruction_set();
	initialize_playback();
	initialize_apu();
	initialize_cpu();
	initialize_ppu();
	initialize_clock();
	initialize_pads();

	/* Read the ines file and get all the ROM/VROM */
	config.rom_file = argv[optind];
	nes_rom = check_ines_file(config.rom_file);
	map_rom_memory(nes_rom);
	save_file = load_sram(config.rom_file);

	/* Init the graphics engine */
	init_screen();
	init_gui();

	/* Main execution loop */
	main_loop();

	/* After finishing the emulation, save the SRAM if necessary */
	save_sram(save_file);
	free(save_file);

	/* Free all the used resources */
	mapper->end_mapper();
	end_screen();
	end_gui();
	end_ppu();
	end_cpu();
	end_apu();
	end_playback();
	free_ines_file(nes_rom);

	return 0;
}
Esempio n. 6
0
uint32_t load_rom(uint8_t* filename, uint32_t base_addr, uint8_t flags) {
  UINT bytes_read;
  DWORD filesize;
  UINT count=0;
  tick_t ticksstart, ticks_total=0;
  ticksstart=getticks();
  printf("%s\n", filename);
  file_open(filename, FA_READ);
  if(file_res) {
    uart_putc('?');
    uart_putc(0x30+file_res);
    return 0;
  }
  filesize = file_handle.fsize;
  smc_id(&romprops);
  file_close();
  /* reconfigure FPGA if necessary */
  if(romprops.fpga_conf) {
    printf("reconfigure FPGA with %s...\n", romprops.fpga_conf);
    fpga_pgm((uint8_t*)romprops.fpga_conf);
  }
  set_mcu_addr(base_addr + romprops.load_address);
  file_open(filename, FA_READ);
  ff_sd_offload=1;
  sd_offload_tgt=0;
  f_lseek(&file_handle, romprops.offset);
  for(;;) {
    ff_sd_offload=1;
    sd_offload_tgt=0;
    bytes_read = file_read();
    if (file_res || !bytes_read) break;
    if(!(count++ % 512)) {
      uart_putc('.');
    }
  }
  file_close();
  set_mapper(romprops.mapper_id);
  printf("rom header map: %02x; mapper id: %d\n", romprops.header.map, romprops.mapper_id);
  ticks_total=getticks()-ticksstart;
  printf("%u ticks total\n", ticks_total);
  if(romprops.mapper_id==3) {
    printf("BSX Flash cart image\n");
    printf("attempting to load BSX BIOS /sd2snes/bsxbios.bin...\n");
    load_sram_offload((uint8_t*)"/sd2snes/bsxbios.bin", 0x800000);
    printf("attempting to load BS data file /sd2snes/bsxpage.bin...\n");
    load_sram_offload((uint8_t*)"/sd2snes/bsxpage.bin", 0x900000);
    printf("Type: %02x\n", romprops.header.destcode);
    set_bsx_regs(0xc0, 0x3f);
    uint16_t rombase;
    if(romprops.header.ramsize & 1) {
      rombase = romprops.load_address + 0xff00;
//      set_bsx_regs(0x36, 0xc9);
    } else {
      rombase = romprops.load_address + 0x7f00;
//      set_bsx_regs(0x34, 0xcb);
    }
    sram_writebyte(0x33, rombase+0xda);
    sram_writebyte(0x00, rombase+0xd4);
    sram_writebyte(0xfc, rombase+0xd5);
    set_fpga_time(0x0220110301180530LL);
  }
  if(romprops.has_dspx || romprops.has_cx4) {
    printf("DSPx game. Loading firmware image %s...\n", romprops.dsp_fw);
    load_dspx(romprops.dsp_fw, romprops.fpga_features);
    /* fallback to DSP1B firmware if DSP1.bin is not present */
    if(file_res && romprops.dsp_fw == DSPFW_1) {
      load_dspx(DSPFW_1B, romprops.fpga_features);
    }
    if(file_res) {
      snes_menu_errmsg(MENU_ERR_NODSP, (void*)romprops.dsp_fw);
    }
  }
  uint32_t rammask;
  uint32_t rommask;

  while(filesize > (romprops.romsize_bytes + romprops.offset)) {
    romprops.romsize_bytes <<= 1;
  }

  if(romprops.header.ramsize == 0) {
    rammask = 0;
  } else {
    rammask = romprops.ramsize_bytes - 1;
  }
  rommask = romprops.romsize_bytes - 1;
  printf("ramsize=%x rammask=%lx\nromsize=%x rommask=%lx\n", romprops.header.ramsize, rammask, romprops.header.romsize, rommask);
  set_saveram_mask(rammask);
  set_rom_mask(rommask);
  readled(0);
  if(flags & LOADROM_WITH_SRAM) {
    if(romprops.ramsize_bytes) {
      sram_memset(SRAM_SAVE_ADDR, romprops.ramsize_bytes, 0);
      strcpy(strrchr((char*)filename, (int)'.'), ".srm");
      printf("SRM file: %s\n", filename);
      load_sram(filename, SRAM_SAVE_ADDR);
      saveram_crc_old = calc_sram_crc(SRAM_SAVE_ADDR, romprops.ramsize_bytes);
    } else {
      printf("No SRAM\n");
    }
  }

  printf("check MSU...");
  if(msu1_check(filename)) {
    romprops.fpga_features |= FEAT_MSU1;
    romprops.has_msu1 = 1;
  } else {
    romprops.has_msu1 = 0;
  }
  printf("done\n");

  romprops.fpga_features |= FEAT_SRTC;
  romprops.fpga_features |= FEAT_213F;

  fpga_set_213f(romprops.region);
  fpga_set_features(romprops.fpga_features);

  if(flags & LOADROM_WITH_RESET) {
    fpga_dspx_reset(1);
    snes_reset_pulse();
    fpga_dspx_reset(0);
  }

  return (uint32_t)filesize;
}
Esempio n. 7
0
File: cli.c Progetto: Godzil/sd2snes
static void cmd_loadraw(void) {
  uint32_t address = parse_unsigned(0,16777216,16);
  load_sram((uint8_t*)curchar, address);
}