Example #1
0
sqd_uint64
sre_ntoh64(sqd_uint64 net_int64)
{
#ifdef WORDS_BIGENDIAN
  return net_int64;
#else
  Byteswap((char *) &net_int64, 8);
  return net_int64;
#endif
}
Example #2
0
sqd_uint64
sre_hton64(sqd_uint64 host_int64)
{
#ifdef WORDS_BIGENDIAN
  return host_int64;
#else
  Byteswap((char *) &host_int64, 8);
  return host_int64;
#endif
}
Example #3
0
sqd_uint32
sre_hton32(sqd_uint32 hostlong)
{
#ifdef WORDS_BIGENDIAN
  return hostlong;
#else
  Byteswap((char *) &hostlong, 4);
  return hostlong;
#endif
}
Example #4
0
sqd_uint16
sre_hton16(sqd_uint16 hostshort)
{
#ifdef WORDS_BIGENDIAN
  return hostshort;
#else
  Byteswap((char *) &hostshort, 2);
  return hostshort;
#endif
}
Example #5
0
sqd_uint32
sre_ntoh32(sqd_uint32 netlong)
{
#ifdef WORDS_BIGENDIAN
  return netlong;
#else
  Byteswap((char *) &netlong, 4);
  return netlong;
#endif
}
Example #6
0
sqd_uint16
sre_ntoh16(sqd_uint16 netshort)
{
#ifdef WORDS_BIGENDIAN
  return netshort;
#else
  Byteswap((char *) &netshort, 2);
  return netshort;
#endif
}
Example #7
0
// nearly same as PicoCartLoad, but works with zipfiles
int CartLoadZip(const char *fname, unsigned char **prom, unsigned int *psize)
{
	unsigned char *rom=0;
	struct zipent* zipentry;
	int size;
	ZIP *zipfile = openzip(fname);

	if(!zipfile) return 1;

	// find first bin or smd
	while((zipentry = readzip(zipfile)) != 0)
	{
		char *ext;
		if(strlen(zipentry->name) < 5) continue;
		ext = zipentry->name+strlen(zipentry->name)-4;

		if(!strcasecmp(ext, ".bin") || !strcasecmp(ext, ".smd") || !strcasecmp(ext, ".gen")) break;
	}

	if(!zipentry) {
		closezip(zipfile);
		return 4; // no roms
	}

	size = zipentry->uncompressed_size;

	size=(size+3)&~3; // Round up to a multiple of 4

	// Allocate space for the rom plus padding
	rom=PicoCartAlloc(size);
	if (rom==NULL) { closezip(zipfile); return 2; }

	if(readuncompresszip(zipfile, zipentry, (char *)rom) != 0) {
		free(rom);
		rom = 0;
		closezip(zipfile);
		return 5; // unzip failed
	}

	closezip(zipfile);

	// Check for SMD:
	if ((size&0x3fff)==0x200) { DecodeSmd(rom,size); size-=0x200; } // Decode and byteswap SMD
	else Byteswap(rom,size); // Just byteswap

	if (prom)  *prom=rom;
	if (psize) *psize=size;

	return 0;
}
Example #8
0
int PicoCartLoad(FILE *f,unsigned char **prom,unsigned int *psize)
{
  unsigned char *rom=NULL; int size;
  if (f==NULL) return 1;

  fseek(f,0,SEEK_END); size=ftell(f); fseek(f,0,SEEK_SET);
  size=(size+3)&~3; // Round up to a multiple of 4

  // Allocate space for the rom plus padding
  rom=PicoCartAlloc(size);
  if (rom==NULL) return 1; // { fclose(f); return 1; }

  fread(rom,1,size,f); // Load up the rom
  // fclose(f); // this is confusing. From now on, caller should close it, because it opened this.

  // Check for SMD:
  if ((size&0x3fff)==0x200) { DecodeSmd(rom,size); size-=0x200; } // Decode and byteswap SMD
  else Byteswap(rom,size); // Just byteswap

  if (prom)  *prom=rom;
  if (psize) *psize=size;

  return 0;
}
Example #9
0
static void get_bios(void)
{
  u16 *ps;
  u32 *pl;
  int i;

  // M68K ROM
  if (p32x_bios_g != NULL) {
    elprintf(EL_STATUS|EL_32X, "32x: using supplied 68k BIOS");
    Byteswap(Pico32xMem->m68k_rom, p32x_bios_g, sizeof(Pico32xMem->m68k_rom));
  }
  else {
    // generate 68k ROM
    ps = (u16 *)Pico32xMem->m68k_rom;
    pl = (u32 *)ps;
    for (i = 1; i < 0xc0/4; i++)
      pl[i] = HWSWAP(0x880200 + (i - 1) * 6);

    // fill with nops
    for (i = 0xc0/2; i < 0x100/2; i++)
      ps[i] = 0x4e71;

#if 0
    ps[0xc0/2] = 0x46fc;
    ps[0xc2/2] = 0x2700; // move #0x2700,sr
    ps[0xfe/2] = 0x60fe; // jump to self
#else
    ps[0xfe/2] = 0x4e75; // rts
#endif
  }
  // fill remaining m68k_rom page with game ROM
  memcpy(Pico32xMem->m68k_rom_bank + sizeof(Pico32xMem->m68k_rom),
    Pico.rom + sizeof(Pico32xMem->m68k_rom),
    sizeof(Pico32xMem->m68k_rom_bank) - sizeof(Pico32xMem->m68k_rom));

  // MSH2
  if (p32x_bios_m != NULL) {
    elprintf(EL_STATUS|EL_32X, "32x: using supplied master SH2 BIOS");
    Byteswap(&Pico32xMem->sh2_rom_m, p32x_bios_m, sizeof(Pico32xMem->sh2_rom_m));
  }
  else {
    pl = (u32 *)&Pico32xMem->sh2_rom_m;

    // fill exception vector table to our trap address
    for (i = 0; i < 128; i++)
      pl[i] = HWSWAP(0x200);

    // start
    pl[0] = pl[2] = HWSWAP(0x204);
    // reset SP
    pl[1] = pl[3] = HWSWAP(0x6040000);

    // startup code
    memcpy(&Pico32xMem->sh2_rom_m.b[0x200], msh2_code, sizeof(msh2_code));
  }

  // SSH2
  if (p32x_bios_s != NULL) {
    elprintf(EL_STATUS|EL_32X, "32x: using supplied slave SH2 BIOS");
    Byteswap(&Pico32xMem->sh2_rom_s, p32x_bios_s, sizeof(Pico32xMem->sh2_rom_s));
  }
  else {
    pl = (u32 *)&Pico32xMem->sh2_rom_s;

    // fill exception vector table to our trap address
    for (i = 0; i < 128; i++)
      pl[i] = HWSWAP(0x200);

    // start
    pl[0] = pl[2] = HWSWAP(0x204);
    // reset SP
    pl[1] = pl[3] = HWSWAP(0x603f800);

    // startup code
    memcpy(&Pico32xMem->sh2_rom_s.b[0x200], ssh2_code, sizeof(ssh2_code));
  }
}