Пример #1
0
int
msg_write_rom (const char *filename, unsigned short parport)
{
  FILE *file;
  unsigned char *buffer, emu_mode_select;
  int bytesread, bytessent = 0, size;
  time_t starttime;
  unsigned short blocksdone = 0;

  ffe_init_io (parport);

  if ((file = fopen (filename, "rb")) == NULL)
    {
      fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename);
      exit (1);
    }
  if ((buffer = (unsigned char *) malloc (BUFFERSIZE)) == NULL)
    {
      fprintf (stderr, ucon64_msg[FILE_BUFFER_ERROR], BUFFERSIZE);
      exit (1);
    }

  size = ucon64.file_size - MSG_HEADER_LEN;
  printf ("Send: %d Bytes (%.4f Mb)\n", size, (float) size / MBIT);

  fread (buffer, 1, MSG_HEADER_LEN, file);
  emu_mode_select = buffer[1];                  // this byte is needed later

  ffe_send_command0 (0xe008, 0);
  printf ("Press q to abort\n\n");

  starttime = time (NULL);
  while ((bytesread = fread (buffer, 1, BUFFERSIZE, file)) != 0)
    {
      ffe_send_command (5, blocksdone, 0);
      ffe_send_block (0x8000, buffer, (unsigned short) bytesread);
      blocksdone++;

      bytessent += bytesread;
      ucon64_gauge (starttime, bytessent, size);
      ffe_checkabort (2);
    }

  if (emu_mode_select & 1)
    ffe_send_command (4, 0xff00, 0);
  else
    ffe_send_command (4, 0xff03, 0);

  free (buffer);
  fclose (file);

  return 0;
}
Пример #2
0
int
smd_write_rom (const char *filename, unsigned int parport)
{
  FILE *file;
  unsigned char *buffer;
  int bytesread, bytessend, blocksdone = 0, fsize;
  time_t starttime;

  ffe_init_io (parport);

  if ((file = fopen (filename, "rb")) == NULL)
    {
      fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename);
      exit (1);
    }
  if ((buffer = (unsigned char *) malloc (BUFFERSIZE)) == NULL)
    {
      fprintf (stderr, ucon64_msg[FILE_BUFFER_ERROR], BUFFERSIZE);
      exit (1);
    }

  fsize = fsizeof (filename);
  printf ("Send: %d Bytes (%.4f Mb)\n", fsize, (float) fsize / MBIT);

  fread (buffer, 1, SMD_HEADER_LEN, file);
  ffe_send_block (0xdc00, buffer, SMD_HEADER_LEN); // send header
  bytessend = SMD_HEADER_LEN;

  ffe_send_command0 (0x2001, 0);

  printf ("Press q to abort\n\n");

  starttime = time (NULL);
  while ((bytesread = fread (buffer, 1, BUFFERSIZE, file)))
    {
      ffe_send_command (5, (unsigned short) blocksdone, 0);
      ffe_send_block (0x8000, buffer, bytesread);
      blocksdone++;

      bytessend += bytesread;
      ucon64_gauge (starttime, bytessend, fsize);
      ffe_checkabort (2);
    }

  // ROM dump > 128 16 KB blocks? (=16 Mb (=2 MB))
  ffe_send_command0 (0x2001, (unsigned char) (blocksdone > 0x80 ? 7 : 3));

  free (buffer);
  fclose (file);
  ffe_deinit_io ();

  return 0;
}
Пример #3
0
static void
set_header (unsigned char *buffer)
{
  unsigned short n;
  unsigned char m = 0, sizes[] = "\x10\x20\x30\x30\x40\x40\x60\x80";

  for (n = 0; n < 128; n++)
    {
      ffe_send_command (5, n, 0);
      buffer[n] = ffe_send_command1 (0xa0a0);
      wait2 (1);
      if (buffer[n] != 0xff)
        m = 1;
    }
  if (m == 0)
    {                                           // no cartridge in Magic Super Griffin
      buffer[0] = 0;
      return;
    }

  m = 0;
  if (!check (buffer, 0, 0x40, 0x20))
    m |= 2;
  if (check (buffer, 0, 0x20, 0x20))
    {
      if (!check (buffer, 0, 0x10, 0x10))
        m |= 1;
    }
  else
    {
      m |= 4;
      if (!check (buffer, 0x40, 0x60, 0x20))
        m |= 1;
    }

  memset (buffer, 0, MSG_HEADER_LEN);
  buffer[0] = sizes[m];
  if (buffer[0] == 0x30)
    buffer[1] = 1;
  buffer[8] = 0xaa;
  buffer[9] = 0xbb;
  buffer[10] = 2;
}
Пример #4
0
int
smd_read_rom (const char *filename, unsigned int parport)
{
  FILE *file;
  unsigned char *buffer, byte;
  int size, blocksdone = 0, blocksleft, bytesreceived = 0;
  time_t starttime;

  ffe_init_io (parport);

  if ((file = fopen (filename, "wb")) == NULL)
    {
      fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename);
      exit (1);
    }
  if ((buffer = (unsigned char *) malloc (BUFFERSIZE)) == NULL)
    {
      fprintf (stderr, ucon64_msg[FILE_BUFFER_ERROR], BUFFERSIZE);
      exit (1);
    }

  ffe_send_command (1, 0xdff1, 1);
  byte = ffe_receiveb ();
  if ((0x81 ^ byte) != ffe_receiveb ())
    printf ("received data is corrupt\n");

  blocksleft = 8 * byte;
  if (blocksleft == 0)
    {
      fprintf (stderr, "ERROR: There is no cartridge present in the Super Magic Drive\n");
      fclose (file);
      remove (filename);
      exit (1);
    }

  memset (buffer, 0, SMD_HEADER_LEN);
  buffer[0] = blocksleft;
  buffer[1] = 3;
  buffer[8] = 0xaa;
  buffer[9] = 0xbb;
  buffer[10] = 6;
  fwrite (buffer, 1, SMD_HEADER_LEN, file);     // write header

  size = blocksleft * 16384;                    // size in bytes for ucon64_gauge() below
  printf ("Receive: %d Bytes (%.4f Mb)\n", size, (float) size / MBIT);

  wait2 (32);
  ffe_send_command0 (0x2001, 0);

  printf ("Press q to abort\n\n");

  starttime = time (NULL);
  while (blocksleft > 0)
    {
      ffe_send_command (5, (unsigned short) blocksdone, 0);
      ffe_receive_block (0x4000, buffer, BUFFERSIZE);
      blocksdone++;
      blocksleft--;
      fwrite (buffer, 1, BUFFERSIZE, file);

      bytesreceived += BUFFERSIZE;
      ucon64_gauge (starttime, bytesreceived, size);
      ffe_checkabort (2);
    }

  free (buffer);
  fclose (file);
  ffe_deinit_io ();

  return 0;
}
Пример #5
0
int
msg_read_rom (const char *filename, unsigned short parport)
{
  FILE *file;
  unsigned char *buffer, blocksleft, emu_mode_select;
  int size, bytesreceived = 0;
  time_t starttime;
  unsigned short blocksdone = 0;

  ffe_init_io (parport);

  if ((file = fopen (filename, "wb")) == NULL)
    {
      fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename);
      exit (1);
    }
  if ((buffer = (unsigned char *) malloc (BUFFERSIZE)) == NULL)
    {
      fprintf (stderr, ucon64_msg[FILE_BUFFER_ERROR], BUFFERSIZE);
      exit (1);
    }

  set_header (buffer);
  if (buffer[0] == 0)
    {
      fprintf (stderr, "ERROR: There is no cartridge present in the Magic Super Griffin\n");
      fclose (file);
      remove (filename);
      exit (1);
    }
  blocksleft = buffer[0];
  size = buffer[0] * 8192;
  printf ("Receive: %d Bytes (%.4f Mb)\n", size, (float) size / MBIT);

  fwrite (buffer, 1, MSG_HEADER_LEN, file);     // write header
  emu_mode_select = buffer[1];

  ffe_send_command (5, 0, 0);
  ffe_send_command0 (0xbff0, 0);

  printf ("Press q to abort\n\n");

  starttime = time (NULL);
  while (blocksleft > 0)
    {
      ffe_send_command (5, blocksdone, 0);
      if (emu_mode_select && blocksdone >= 32)
        ffe_send_command (5, blocksdone + 32, 0);
      ffe_receive_block (0xa000, buffer, BUFFERSIZE);
      // vgs aborts if the checksum doesn't match the data, we let the user decide
      blocksleft--;
      blocksdone++;
      fwrite (buffer, 1, BUFFERSIZE, file);

      bytesreceived += BUFFERSIZE;
      ucon64_gauge (starttime, bytesreceived, size);
      ffe_checkabort (2);
    }

  free (buffer);
  fclose (file);

  return 0;
}