Пример #1
0
int
ppf_set_fid (const char *ppf, const char *fidname)
{
    int fidsize, ppfsize, pos;
    char ppfname[FILENAME_MAX],
         fidbuf[MAX_ID_SIZE + 34 + 1] = "@BEGIN_FILE_ID.DIZ"; // +1 for string terminator

    strcpy (ppfname, ppf);
    ucon64_file_handler (ppfname, NULL, 0);
    fcopy (ppf, 0, fsizeof (ppf), ppfname, "wb"); // no copy if one file

    printf ("Adding FILE_ID.DIZ (%s)...\n", fidname);
    fidsize = ucon64_fread (fidbuf + 18, 0, MAX_ID_SIZE, fidname);
    memcpy (fidbuf + 18 + fidsize, "@END_FILE_ID.DIZ", 16);

    ppfsize = fsizeof (ppfname);
    pos = ucon64_find (ppfname, 0, ppfsize, "@BEGIN_FILE_ID.DIZ", 18,
                       MEMCMP2_CASE | UCON64_FIND_QUIET);
    if (pos == -1)
        pos = ppfsize;
    truncate (ppfname, pos);

    ucon64_fwrite (fidbuf, pos, fidsize + 18 + 16, ppfname, "r+b");
    pos += fidsize + 18 + 16;
#ifdef  WORDS_BIGENDIAN
    fidsize = bswap_32 (fidsize);                 // Write file size in little-endian format
#endif
    ucon64_fwrite (&fidsize, pos, 4, ppfname, "r+b");

    printf (ucon64_msg[WROTE], ppfname);
    return 0;
}
Пример #2
0
static int
lynx_b (st_rominfo_t *rominfo, int bank, const char *value)
{
  st_lnx_header_t header;
  short int *bankvar;
  char dest_name[FILENAME_MAX];

  if (!rominfo->buheader_len)
    {
      fprintf (stderr, "ERROR: This is no LNX file\n\n");
      return -1;
    }

  ucon64_fread (&header, 0, sizeof (st_lnx_header_t), ucon64.rom);

  bankvar = (bank == 0 ? &header.page_size_bank0 : &header.page_size_bank1);
  if ((atol (value) % 64) != 0 || (atol (value) > 512))
    *bankvar = 0;
  else
#ifdef  WORDS_BIGENDIAN
    *bankvar = bswap_16 (atol (value) * 4);
#else
    *bankvar = atol (value) * 4;
#endif

  strcpy (dest_name, ucon64.rom);
  ucon64_file_handler (dest_name, NULL, 0);
  fcopy (ucon64.rom, 0, ucon64.file_size, dest_name, "wb");
  ucon64_fwrite (&header, 0, sizeof (st_lnx_header_t), dest_name, "r+b");

  printf (ucon64_msg[WROTE], dest_name);
  return 0;
}
Пример #3
0
int
dc_parse (const char *templ_file)
{
    char ip[0x8000], dest_name[FILENAME_MAX];

    if (access (templ_file, F_OK) == -1)
    {
        int i = 0;

        printf ("Creating empty template file: \"%s\"\n", templ_file);

        for (i = 0; templ[i].name; i++)
            set_property (templ_file, templ[i].name, templ[i].def, templ[i].comment);

        printf (ucon64_msg[WROTE], templ_file);
    }

    if (parse_templ (templ_file, ip) == -1)
        return -1;

    update_crc (ip);

    strcpy (dest_name, "ip.bin");
    ucon64_file_handler (dest_name, NULL, 0);

    ucon64_fwrite (ip, 0, 0x8000, dest_name, "wb");

    printf (ucon64_msg[WROTE], dest_name);
    return 0;
}
Пример #4
0
int
lynx_n (st_rominfo_t *rominfo, const char *name)
{
  st_lnx_header_t header;
  char dest_name[FILENAME_MAX];

  if (!rominfo->buheader_len)
    {
      fprintf (stderr, "ERROR: This is no LNX file\n\n");
      return -1;
    }

  ucon64_fread (&header, 0, sizeof (st_lnx_header_t), ucon64.rom);

  memset (header.cartname, 0, sizeof (header.cartname));
  strncpy (header.cartname, name, sizeof (header.cartname));

  strcpy (dest_name, ucon64.rom);
  ucon64_file_handler (dest_name, NULL, 0);
  fcopy (ucon64.rom, 0, ucon64.file_size, dest_name, "wb");
  ucon64_fwrite (&header, 0, sizeof (st_lnx_header_t), dest_name, "r+b");

  printf (ucon64_msg[WROTE], dest_name);
  return 0;
}
Пример #5
0
int
pce_f (st_ucon64_nfo_t *rominfo)
/*
  Region protection codes are found in (American) TurboGrafx-16 games. It
  prevents those games from running on a PC-Engine. One search pattern seems
  sufficient to fix/crack all TG-16 games. In addition to that, the protection
  code appears to be always somewhere in the first 32 kB.
*/
{
  char src_name[FILENAME_MAX], dest_name[FILENAME_MAX], buffer[32 * 1024];
  int bytesread, n;

  puts ("Attempting to fix region protection code...");

  strcpy (src_name, ucon64.fname);
  strcpy (dest_name, ucon64.fname);
  ucon64_file_handler (dest_name, src_name, 0);
  fcopy (src_name, 0, ucon64.file_size, dest_name, "wb"); // no copy if one file

  if ((bytesread = ucon64_fread (buffer, rominfo->backup_header_len, 32 * 1024, src_name)) <= 0)
    return -1;

  // '!' == ASCII 33 (\x21), '*' == 42 (\x2a)
  if (rominfo->interleaved)
    n = change_mem (buffer, bytesread, "\x94\x02\x0f", 3, '*', '!', "\x01", 1, 0);
  else
    n = change_mem (buffer, bytesread, "\x29\x40\xf0", 3, '*', '!', "\x80", 1, 0);

  ucon64_fwrite (buffer, rominfo->backup_header_len, 32 * 1024, dest_name, "r+b");

  printf ("Found %d pattern%s\n", n, n != 1 ? "s" : "");
  printf (ucon64_msg[WROTE], dest_name);
  remove_temp_file ();
  return n;
}
Пример #6
0
int
pce_swap (st_ucon64_nfo_t *rominfo)
{
  char src_name[FILENAME_MAX], dest_name[FILENAME_MAX];
  unsigned char *rom_buffer;
  int size = ucon64.file_size - rominfo->backup_header_len;

  if ((rom_buffer = (unsigned char *) malloc (size)) == NULL)
    {
      fprintf (stderr, ucon64_msg[ROM_BUFFER_ERROR], size);
      return -1;
    }

  strcpy (src_name, ucon64.fname);
  strcpy (dest_name, ucon64.fname);
  ucon64_file_handler (dest_name, src_name, 0);

  if (rominfo->backup_header_len)                    // copy header (if present)
    fcopy (src_name, 0, rominfo->backup_header_len, dest_name, "wb");

  ucon64_fread (rom_buffer, rominfo->backup_header_len, size, src_name);
  swapbits (rom_buffer, size);
  ucon64_fwrite (rom_buffer, rominfo->backup_header_len, size, dest_name,
            rominfo->backup_header_len ? "ab" : "wb");
  free (rom_buffer);

  printf (ucon64_msg[WROTE], dest_name);
  remove_temp_file ();
  return 0;
}
Пример #7
0
// header format is specified in src/backup/ffe.h
int
pce_msg (st_ucon64_nfo_t *rominfo)
{
  char src_name[FILENAME_MAX], dest_name[FILENAME_MAX];
  unsigned char *rom_buffer = NULL;
  st_msg_header_t header;
  int size = ucon64.file_size - rominfo->backup_header_len;

  if (rominfo->interleaved)
    if ((rom_buffer = (unsigned char *) malloc (size)) == NULL)
      {
        fprintf (stderr, ucon64_msg[ROM_BUFFER_ERROR], size);
        return -1;
      }

  memset (&header, 0, MSG_HEADER_LEN);
  header.size = (unsigned char) (size / 8192);
  header.emulation = size == 3 * MBIT ? 1 : 0;
  header.id1 = 0xaa;
  header.id2 = 0xbb;
  header.type = 2;

  strcpy (src_name, ucon64.fname);
  strcpy (dest_name, ucon64.fname);
  set_suffix (dest_name, ".msg");
  ucon64_file_handler (dest_name, src_name, 0);

  ucon64_fwrite (&header, 0, MSG_HEADER_LEN, dest_name, "wb");
  if (rominfo->interleaved)
    {
      // Magic Super Griffin files should not be "interleaved"
      ucon64_fread (rom_buffer, rominfo->backup_header_len, size, src_name);
      swapbits (rom_buffer, size);
      ucon64_fwrite (rom_buffer, MSG_HEADER_LEN, size, dest_name, "ab");
      free (rom_buffer);
    }
  else
    fcopy (src_name, rominfo->backup_header_len, size, dest_name, "ab");

  printf (ucon64_msg[WROTE], dest_name);
  remove_temp_file ();
  return 0;
}
Пример #8
0
int
mccl_read (const char *filename, unsigned int parport)
{
  unsigned char buffer[0x1760], inbyte;
  char dest_name[FILENAME_MAX];
  int count = 0;
  time_t starttime;

  parport_print_info ();
  puts ("Resetting device");
  do
    {
      outportb (CONTROL, 0x24);
      while ((inportb (STATUS) & 0x20) == 0)
        ;
    }
  while ((inportw (DATA) & 0xf) != 4);
  outportb (CONTROL, 0x22);
  while ((inportb (STATUS) & 0x20) != 0)
    ;
  outportb (CONTROL, 0x26);

  printf ("Receive: %d Bytes (%.4f Mb)\n\n", 0x1760, (float) 0x1760 / MBIT);
  starttime = time (NULL);
  do
    {
      outportb (CONTROL, 0x26);
      while ((inportb (STATUS) & 0x20) == 0)
        ;
      inbyte = (unsigned char) (inportw (DATA) & 0xf);
      outportb (CONTROL, 0x22);
      while ((inportb (STATUS) & 0x20) != 0)
        ;
      outportb (CONTROL, 0x26);
      while ((inportb (STATUS) & 0x20) == 0)
        ;
      inbyte |= (unsigned char) ((inportw (DATA) & 0xf) << 4);
      outportb (CONTROL, 0x22);
      while ((inportb (STATUS) & 0x20) != 0)
        ;
      buffer[count++] = inbyte;
      if ((count & 0x1f) == 0)
        ucon64_gauge (starttime, count, 0x1760);
    }
  while (count < 0x1760);

  strcpy (dest_name, filename);
  ucon64_file_handler (dest_name, NULL, 0);
  ucon64_fwrite (buffer, 0, count, dest_name, "wb");
  printf (ucon64_msg[WROTE], dest_name);
  return 0;
}
Пример #9
0
int
ppf_set_desc (const char *ppf, const char *description)
{
    char desc[50], ppfname[FILENAME_MAX];

    strcpy (ppfname, ppf);
    memset (desc, ' ', 50);
    strncpy (desc, description, strlen (description));
    ucon64_file_handler (ppfname, NULL, 0);
    fcopy (ppf, 0, fsizeof (ppf), ppfname, "wb"); // no copy if one file
    ucon64_fwrite (desc, 6, 50, ppfname, "r+b");

    printf (ucon64_msg[WROTE], ppfname);
    return 0;
}
Пример #10
0
int
lynx_lnx (st_rominfo_t *rominfo)
{
  st_lnx_header_t header;
  char dest_name[FILENAME_MAX];
  int size = ucon64.file_size;

  if (rominfo->buheader_len != 0)
    {
      fprintf (stderr, "ERROR: This seems to already be an LNX file\n\n");
      return -1;
    }

  header.page_size_bank0 = size > 4 * MBIT ? 4 * MBIT / 256 : size / 256;
  header.page_size_bank1 = size > 4 * MBIT ? (size - (4 * MBIT)) / 256 : 0;
#ifdef  WORDS_BIGENDIAN
  header.page_size_bank0 = bswap_16 (header.page_size_bank0);
  header.page_size_bank1 = bswap_16 (header.page_size_bank1);
#endif

  memset (header.cartname, 0, sizeof (header.cartname));
  memset (header.manufname, 0, sizeof (header.manufname));
  memset (header.spare, 0, sizeof (header.spare));

#ifdef  WORDS_BIGENDIAN
  header.version = bswap_16 (1);
#else
  header.version = 1;
#endif

  memcpy (header.magic, "LYNX", 4);
  header.rotation = 0;
  strncpy (header.cartname, ucon64.rom, sizeof (header.cartname));
  strcpy (header.manufname, "Atari");

  strcpy (dest_name, ucon64.rom);
  set_suffix (dest_name, ".lnx");

  ucon64_file_handler (dest_name, NULL, 0);
  ucon64_fwrite (&header, 0, sizeof (st_lnx_header_t), dest_name, "wb");
  fcopy (ucon64.rom, 0, ucon64.file_size, dest_name, "ab");

  printf (ucon64_msg[WROTE], dest_name);
  return 0;
}
Пример #11
0
static int
lynx_rot (st_rominfo_t *rominfo, int rotation)
{
  st_lnx_header_t header;
  char dest_name[FILENAME_MAX];

  if (!rominfo->buheader_len)
    {
      fprintf (stderr, "ERROR: This is no LNX file\n\n");
      return -1;
    }

  ucon64_fread (&header, 0, sizeof (st_lnx_header_t), ucon64.rom);

  header.rotation = rotation;                   // header.rotation is an 8-bit field

  strcpy (dest_name, ucon64.rom);
  ucon64_file_handler (dest_name, NULL, 0);
  fcopy (ucon64.rom, 0, ucon64.file_size, dest_name, "wb");
  ucon64_fwrite (&header, 0, sizeof (st_lnx_header_t), dest_name, "r+b");

  printf (ucon64_msg[WROTE], dest_name);
  return 0;
}
Пример #12
0
// see src/backup/mgd.h for the file naming scheme
int
pce_mgd (st_ucon64_nfo_t *rominfo)
{
  char src_name[FILENAME_MAX], dest_name[FILENAME_MAX];
  unsigned char *rom_buffer = NULL;
  int size = ucon64.file_size - rominfo->backup_header_len;

  if (!rominfo->interleaved)
    if ((rom_buffer = (unsigned char *) malloc (size)) == NULL)
      {
        fprintf (stderr, ucon64_msg[ROM_BUFFER_ERROR], size);
        return -1;
      }

  strcpy (src_name, ucon64.fname);
  mgd_make_name (ucon64.fname, UCON64_PCE, size, dest_name);
  ucon64_file_handler (dest_name, src_name, OF_FORCE_BASENAME);

  // bit-swapping images for the MGD2 only makes sense for owners of a TG-16
  //  (American version of the PCE)
  if (!rominfo->interleaved)
    {
      ucon64_fread (rom_buffer, rominfo->backup_header_len, size, src_name);
      swapbits (rom_buffer, size);
      ucon64_fwrite (rom_buffer, 0, size, dest_name, "wb");
      free (rom_buffer);
    }
  else
    fcopy (src_name, rominfo->backup_header_len, size, dest_name, "wb");

  printf (ucon64_msg[WROTE], dest_name);
  remove_temp_file ();

  mgd_write_index_file ((char *) basename2 (dest_name), 1);
  return 0;
}