Example #1
0
static bool load_roms(unsigned rom_type, const char **rom_paths, size_t roms)
{
   size_t i;
   bool ret = true;

   if (roms == 0)
      return false;

   if (roms > MAX_ROMS)
      return false;

   void *rom_buf[MAX_ROMS] = {NULL};
   long rom_len[MAX_ROMS] = {0};
   struct retro_game_info info[MAX_ROMS] = {{NULL}};

   if (!g_extern.system.info.need_fullpath)
   {
      RARCH_LOG("Loading ROM file: %s.\n", rom_paths[0]);
      if ((rom_len[0] = read_rom_file(rom_paths[0], &rom_buf[0])) == -1)
      {
         RARCH_ERR("Could not read ROM file.\n");
         ret = false;
         goto end;
      }

      RARCH_LOG("ROM size: %u bytes.\n", (unsigned)rom_len[0]);
   }
   else
      RARCH_LOG("ROM loading skipped. Implementation will load it on its own.\n");

   info[0].path = rom_paths[0];
   info[0].data = rom_buf[0];
   info[0].size = rom_len[0];
   info[0].meta = NULL; // Not relevant at this moment.

   for (i = 1; i < roms; i++)
   {
      if (rom_paths[i] &&
            !g_extern.system.info.need_fullpath &&
            (rom_len[i] = read_file(rom_paths[i], &rom_buf[i])) == -1)
      {
         RARCH_ERR("Could not read ROM file: \"%s\".\n", rom_paths[i]);
         ret = false;
         goto end;
      }
      
      info[i].path = rom_paths[i];
      info[i].data = rom_buf[i];
      info[i].size = rom_len[i];
      info[i].meta = NULL;
   }

   if (rom_type == 0)
      ret = pretro_load_game(&info[0]);
   else
      ret = pretro_load_game_special(rom_type, info, roms);

   if (!ret)
      RARCH_ERR("Failed to load game.\n");

end:
   for (i = 0; i < MAX_ROMS; i++)
      free(rom_buf[i]);
   return ret;
}
Example #2
0
static w_err_t rom2_erase_all(w_media_s *media)
{
    wind_memset(g_rom2,0,ROM2_BLKSIZE);
    read_rom_file();
    return W_ERR_OK;
}
Example #3
0
static w_int32_t rom2_erase_blk(w_media_s *media,w_uint32_t addr,w_int32_t blkcnt)
{
    wind_memset(&g_rom2[addr],0,blkcnt * ROM2_BLKSIZE);
    read_rom_file();
    return blkcnt;
}
Example #4
0
static w_int32_t rom2_read_blk(w_media_s *media,w_uint32_t addr,w_uint8_t *data,w_int32_t blkcnt)
{
    read_rom_file();
    wind_memcpy(data,&g_rom2[addr],blkcnt * ROM2_BLKSIZE);
    return blkcnt;
}
Example #5
0
struct zfile *read_rom (struct romdata **prd)
{
	struct romdata *rd2 = *prd;
	struct romdata *rd = *prd;
	TCHAR *name;
	int id = rd->id;
	uae_u32 crc32;
	int size;
	uae_u8 *buf, *buf2;

	/* find parent node */
	for (;;) {
		if (rd2 == &roms[0])
			break;
		if (rd2[-1].id != id)
			break;
		rd2--;
	}
	*prd = rd2;
	size = rd2->size;
	crc32 = rd2->crc32;
	name = rd->name;
	buf = xmalloc (uae_u8, size * 2);
	memset (buf, 0xff, size * 2);
	if (!buf)
		return NULL;
	buf2 = buf + size;
	while (rd->id == id) {
		int i, j, add;
		int ok = 0;
		uae_u32 flags = rd->type;
		int odd = (flags & ROMTYPE_ODD) ? 1 : 0;

		add = 0;
		for (i = 0; i < 2; i++) {
			memset (buf, 0, size);
			if (!(flags & (ROMTYPE_EVEN | ROMTYPE_ODD))) {
				read_rom_file (buf, rd);
				if (flags & ROMTYPE_CD32) {
					memcpy (buf2, buf, size);
					mergecd32 (buf, buf2, size);
				}
				add = 1;
				i++;
			} else {
				int romsize = size / 2;
				if (i)
					odd = !odd;
				if (flags & ROMTYPE_8BIT) {
					read_rom_file (buf2, rd);
					if (flags & ROMTYPE_BYTESWAP)
						byteswap (buf2, romsize);
					if (flags & ROMTYPE_SCRAMBLED)
						descramble (rd, buf2, romsize, odd);
					for (j = 0; j < size; j += 2)
						buf[j + odd] = buf2[j / 2];
					read_rom_file (buf2, rd + 1);
					if (flags & ROMTYPE_BYTESWAP)
						byteswap (buf2, romsize);
					if (flags & ROMTYPE_SCRAMBLED)
						descramble (rd + 1, buf2, romsize, !odd);
					for (j = 0; j < size; j += 2)
						buf[j + (1 - odd)] = buf2[j / 2];
				} else {
					read_rom_file (buf2, rd);
					if (flags & ROMTYPE_BYTESWAP)
						byteswap (buf2, romsize);
					if (flags & ROMTYPE_SCRAMBLED)
						descramble (rd, buf2, romsize, odd);
					for (j = 0; j < size; j += 4) {
						buf[j + 2 * odd + 0] = buf2[j / 2 + 0];
						buf[j + 2 * odd + 1] = buf2[j / 2 + 1];
					}
					read_rom_file (buf2, rd + 1);
					if (flags & ROMTYPE_BYTESWAP)
						byteswap (buf2, romsize);
					if (flags & ROMTYPE_SCRAMBLED)
						descramble (rd + 1, buf2, romsize, !odd);
					for (j = 0; j < size; j += 4) {
						buf[j + 2 * (1 - odd) + 0] = buf2[j / 2 + 0];
						buf[j + 2 * (1 - odd) + 1] = buf2[j / 2 + 1];
					}
				}
				add = 2;
			}
			if (get_crc32 (buf, size) == crc32) {
				ok = 1;
			}
			if (!ok && (rd->type & ROMTYPE_AR)) {
				uae_u8 tmp[2];
				tmp[0] = buf[0];
				tmp[1] = buf[1];
				buf[0] = buf[1] = 0;
				if (get_crc32 (buf, size) == crc32)
					ok = 1;
				buf[0] = tmp[0];
				buf[1] = tmp[1];
			}
			if (!ok) {
				/* perhaps it is byteswapped without byteswap entry? */
				byteswap (buf, size);
				if (get_crc32 (buf, size) == crc32)
					ok = 1;
			}
			if (ok) {
				struct zfile *zf = zfile_fopen_empty (NULL, name, size);
				if (zf) {
					zfile_fwrite (buf, size, 1, zf);
					zfile_fseek (zf, 0, SEEK_SET);
				}
				xfree (buf);
				return zf;
			}
		}
		rd += add;

	}
	xfree (buf);
	return NULL;
}
Example #6
0
static bool load_roms(unsigned rom_type, const char **rom_paths, size_t roms)
{
   bool ret = true;

   if (roms == 0)
      return false;

   if (roms > MAX_ROMS)
      return false;

   void *rom_buf[MAX_ROMS] = {NULL};
   ssize_t rom_len[MAX_ROMS] = {0};
   struct retro_game_info info[MAX_ROMS] = {{NULL}};
   char *xml_buf = load_xml_map(g_extern.xml_name);

   FILE *rom_file = NULL;
   if (rom_paths[0])
   {
      RARCH_LOG("Loading ROM file: %s.\n", rom_paths[0]);
      rom_file = fopen(rom_paths[0], "rb");
   }

   if (!g_extern.system.info.need_fullpath)
   {
      if ((rom_len[0] = read_rom_file(rom_file, &rom_buf[0])) == -1)
      {
         RARCH_ERR("Could not read ROM file.\n");
         ret = false;
         goto end;
      }

      RARCH_LOG("ROM size: %u bytes.\n", (unsigned)rom_len[0]);
   }
   else
   {
      if (!rom_file)
      {
         RARCH_ERR("Implementation requires a full path to be set, cannot load ROM from stdin. Aborting ...\n");
         ret = false;
         goto end;
      }

      RARCH_LOG("ROM loading skipped. Implementation will load it on its own.\n");
   }

   info[0].path = rom_paths[0];
   info[0].data = rom_buf[0];
   info[0].size = rom_len[0];
   info[0].meta = xml_buf;

   for (size_t i = 1; i < roms; i++)
   {
      if (rom_paths[i] &&
            !g_extern.system.info.need_fullpath &&
            (rom_len[i] = read_file(rom_paths[i], &rom_buf[i])) == -1)
      {
         RARCH_ERR("Could not read ROM file: \"%s\".\n", rom_paths[i]);
         ret = false;
         goto end;
      }
      
      info[i].path = rom_paths[i];
      info[i].data = rom_buf[i];
      info[i].size = rom_len[i];
   }

   if (rom_type == 0)
      ret = pretro_load_game(&info[0]);
   else
      ret = pretro_load_game_special(rom_type, info, roms);

   if (!ret)
      RARCH_ERR("Failed to load game.\n");

end:
   for (unsigned i = 0; i < MAX_ROMS; i++)
      free(rom_buf[i]);
   free(xml_buf);
   if (rom_file)
      fclose(rom_file);

   return ret;
}