Example #1
0
int
md_read_rom (const char *filename, unsigned short parport, int size)
{
  FILE *file;
  unsigned short int id;
  unsigned char buffer[0x100];
  int blocksleft, address = 0;
  time_t starttime;
  void (*read_block) (int, unsigned char *) = ttt_read_rom_w; // ttt_read_rom_b

  if ((file = fopen (filename, "wb")) == NULL)
    {
      fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename);
      exit (1);
    }
  ttt_init_io (parport);

  id = check_card ();
  if (id == 0)
    {
      fclose (file);
      remove (filename);
      exit (1);
    }

  if ((id == 0xb0d0 || id == 0x8916) && size > 32 * MBIT)
    size = 32 * MBIT;                           // Sharp or Intel 32 Mbit flash card
#if 0
  // size is set to 64 * MBIT "by default" (in ucon64_opts.c)
  else if (id == 0x8917 && size > 64 * MBIT)
    size = 64 * MBIT;                           // Intel 64 Mbit flash card
#endif

  printf ("Receive: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT);

  blocksleft = size >> 8;
  eep_reset ();
  ttt_rom_enable ();
  if (read_block == ttt_read_rom_w)
    ttt_set_ai_data (6, 0x94);          // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS
  starttime = time (NULL);
  while (blocksleft-- > 0)
    {
      read_block (address, buffer);             // 0x100 bytes read
      if (read_block == ttt_read_rom_b)
        ucon64_bswap16_n (buffer, 0x100);
      fwrite (buffer, 1, 0x100, file);
      address += 0x100;
      if ((address & 0x3fff) == 0)
        ucon64_gauge (starttime, address, size);
    }
  // original code doesn't call ttt_rom_disable() when byte-size function is
  //  used (ttt_read_rom_b() calls it)
  if (read_block == ttt_read_rom_w)
    ttt_rom_disable ();

  fclose (file);

  return 0;
}
Example #2
0
int
md_write_sram (const char *filename, unsigned short parport, int start_bank)
{
  FILE *file;
  unsigned char buffer[0x4000];
  int size, bytesread, bytessent = 0, address;
  time_t starttime;
  void (*write_block) (int *, unsigned char *) = write_ram_by_byte; // write_ram_by_page
  (void) write_ram_by_page;

  size = ucon64.file_size;
  if (start_bank == -1)
    address = 0;
  else
    {
      if (start_bank < 1 || start_bank > 4)
        {
          fputs ("ERROR: Bank must be a value 1 - 4\n", stderr);
          exit (1);
        }
      address = (start_bank - 1) * 32 * 1024;
    }

  if ((file = fopen (filename, "rb")) == NULL)
    {
      fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename);
      exit (1);
    }

  ttt_init_io (parport);
  printf ("Send: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT);

  if (check_card () == 0)
    {
      fclose (file);
      exit (1);
    }

  starttime = time (NULL);
  while ((bytesread = fread (buffer, 1, 0x4000, file)) != 0)
    {
      write_block (&address, buffer);
      bytessent += bytesread;
      ucon64_gauge (starttime, bytessent, size);
    }

  fclose (file);

  return 0;
}
Example #3
0
int
pce_read_rom (const char *filename, unsigned short parport, int size)
{
  FILE *file;
  unsigned char buffer[0x100];
  int blocksleft, address = 0;
  time_t starttime;
  void (*read_block) (int, unsigned char *) = ttt_read_rom_w; // ttt_read_rom_b

  if ((file = fopen (filename, "wb")) == NULL)
    {
      fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename);
      exit (1);
    }
  ttt_init_io (parport);

  printf ("Receive: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT);

  if (check_card () == 0)
    {
      fclose (file);
      remove (filename);
      exit (1);
    }

  blocksleft = size >> 8;
  eep_reset ();
  ttt_rom_enable ();
  if (read_block == ttt_read_rom_w)
    ttt_set_ai_data (6, 0x94);          // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS
  starttime = time (NULL);
  while (blocksleft-- > 0)
    {
      read_block (address, buffer);             // 0x100 bytes read
      fwrite (buffer, 1, 0x100, file);
      address += 0x100;
      if ((address & 0x3fff) == 0)
        ucon64_gauge (starttime, address, size);
    }
  // original code doesn't call ttt_rom_disable() when byte-size function is
  //  used (ttt_read_rom_b() calls it)
  if (read_block == ttt_read_rom_w)
    ttt_rom_disable ();

  fclose (file);

  return 0;
}
Example #4
0
int
md_read_sram (const char *filename, unsigned short parport, int start_bank)
/*
  The MD-PRO has 256 kB of SRAM. However, the SRAM dumps of all games that have
  been tested had each byte doubled. In order to make it possible to easily
  obtain the SRAM data for use in an emulator, or to send an emulator SRAM file
  to the MD-PRO, we remove the redundant data when receiving/dumping and double
  the data when sending.
  It could be that this approach causes trouble for some games. However, when
  looking at ToToTEK's own code in ttt_write_page_ram2() this seems unlikely
  (data is doubled in that function). Note that write_sram_by_byte() is a
  function written by us, and so does the doubling of data, but it doesn't mean
  it should work for all games.
*/
{
  FILE *file;
  unsigned char buffer[0x100];
  int blocksleft, address, bytesreceived = 0, size, i;
  time_t starttime;
  void (*read_block) (int, unsigned char *) = ttt_read_ram_b; // ttt_read_ram_w
  // This function does not seem to work if ttt_read_ram_w() is used, but see
  //  note below

  if (start_bank == -1)
    {
      address = 0;
      size = 128 * 1024;
    }
  else
    {
      if (start_bank < 1 || start_bank > 4)
        {
          fputs ("ERROR: Bank must be a value 1 - 4\n", stderr);
          exit (1);
        }
      address = (start_bank - 1) * 32 * 1024;
      size = 32 * 1024;
    }

  if ((file = fopen (filename, "wb")) == NULL)
    {
      fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename);
      exit (1);
    }

  ttt_init_io (parport);
  printf ("Receive: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT);

  if (check_card () == 0)
    {
      fclose (file);
      remove (filename);
      exit (1);
    }

  if (read_block == ttt_read_ram_w)
    {
//      address *= 2;
      ttt_ram_enable ();
#if 0
      // According to JohnDie, disabling this statement should make it possible
      //  to use ttt_read_ram_w().
      ttt_set_ai_data (6, 0x98);        // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS
#endif
    }
//  else
//    ttt_set_ai_data (6, 0x94);          // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS

  blocksleft = size >> 7;
  starttime = time (NULL);
  while (blocksleft-- > 0)
    {
      read_block (address, buffer);             // 0x100 bytes read
      for (i = 0; i < 0x80; i++)
        buffer[i] = buffer[2 * i];              // data is doubled => no problems with endianess
      fwrite (buffer, 1, 0x80, file);
      address += 0x100;
      bytesreceived += 0x80;
      if ((address & 0x3fff) == 0)
        ucon64_gauge (starttime, bytesreceived, size);
    }
  if (read_block == ttt_read_ram_w)
    ttt_ram_disable ();

  fclose (file);

  return 0;
}
Example #5
0
int
md_write_rom (const char *filename, unsigned short parport)
{
  FILE *file;
  unsigned char buffer[0x4000], game_table[32 * 0x20];
  int game_no, size, address = 0, bytesread, bytessent = 0, bytesleft = 0,
      multi_game;
  time_t starttime;
  void (*write_block) (int *, unsigned char *) = write_rom_by_page; // write_rom_by_byte
  (void) write_rom_by_byte;

  if ((file = fopen (filename, "rb")) == NULL)
    {
      fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename);
      exit (1);
    }
  ttt_init_io (parport);

  fseek (file, 0x83f4, SEEK_SET);
  buffer[0] = 0;
  fread (buffer, 1, 12, file);                  // it's OK to not verify if we can read
  // currently we ignore the version string (full string is "uCON64 2.0.2")
  multi_game = strncmp ((char *) buffer, "uCON64", 6) ? 0 : 1;

  if (multi_game)
    {
      fseek (file, 0x8000, SEEK_SET);
      bytesread = fread (game_table, 1, 32 * 0x20, file);
      if (bytesread != 32 * 0x20)
        {
          fputs ("ERROR: Could not read game table from file\n", stderr);
          fclose (file);
          return -1;
        }
    }

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

  md_id = check_card ();
  if (md_id == 0)
    {
      fclose (file);
      exit (1);
    }

  fseek (file, 0, SEEK_SET);

  starttime = time (NULL);
  if (!multi_game)
    bytesleft = size;                           // one file (no multi-game)
  eep_reset ();
  game_no = -1;
  do
    {
      if (game_no >= 0)                         // a game of a multi-game file
        bytesleft = game_table[game_no * 0x20 + 0x1d] * MBIT;
      else if (multi_game)
        bytesleft = MD_PRO_LOADER_SIZE;         // the loader

      while (bytesleft > 0 && (bytesread = fread (buffer, 1, 0x4000, file)) != 0)
        {
          ucon64_bswap16_n (buffer, 0x4000);
          if ((((address & 0xffff) == 0) && (md_id == 0xb0d0)) ||
              (((address & 0x1ffff) == 0) && (md_id == 0x8916 || md_id == 0x8917)))
            ttt_erase_block (address);
          write_block (&address, buffer);

          bytessent += bytesread;
          ucon64_gauge (starttime, bytessent, size);
          bytesleft -= bytesread;
        }
      // Games have to be aligned to (start at) a 2 Mbit boundary.
      address = (address + 2 * MBIT - 1) & ~(2 * MBIT - 1);
      game_no++;
    }
  while (multi_game ? (game_table[game_no * 0x20] && game_no < 31) : 0);

  fclose (file);

  return 0;
}
Example #6
0
int
pce_write_rom (const char *filename, unsigned short parport)
{
  FILE *file;
  unsigned char buffer[0x4000], game_table[32 * 0x20];
  int game_no, size, romsize = 0, startaddress, address = 0, bytesread,
      bytessent = 0, bytesleft, multi_game;
  time_t starttime;
  void (*write_block) (int *, unsigned char *) = write_rom_by_page; // write_rom_by_byte
  (void) write_rom_by_byte;

  if ((file = fopen (filename, "rb")) == NULL)
    {
      fprintf (stderr, ucon64_msg[OPEN_READ_ERROR], filename);
      exit (1);
    }
  ttt_init_io (parport);

  fseek (file, 0xb3f4, SEEK_SET);
  buffer[0] = 0;
  fread (buffer, 1, 12, file);                  // it's OK to not verify if we can read
  // currently we ignore the version string (full string is "uCON64 2.0.1")
  multi_game = strncmp ((char *) buffer, "uCON64", 6) ? 0 : 1;

  if (multi_game)
    {
      fseek (file, 0xb000, SEEK_SET);
      bytesread = fread (game_table, 1, 32 * 0x20, file);
      if (bytesread != 32 * 0x20)
        {
          fputs ("ERROR: Could not read game table from file\n", stderr);
          fclose (file);
          return -1;
        }
    }

  size = ucon64.file_size;
  // 4 Mbit games need the last 2 Mbit to be mirrored (so, they need 6 Mbit)
  if (multi_game)
    {
      game_no = 0;
      while (game_table[game_no * 0x20] && game_no < 31)
        {
          if (game_table[game_no * 0x20 + 0x1e] == 4)
            size += 2 * MBIT;
          game_no++;
        }
    }
  else
    {
      romsize = size;                           // one file (no multi-game)
      if (size == 4 * MBIT)
        size += 2 * MBIT;
    }
  printf ("Send: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT);

  if (check_card () == 0)
    {
      fclose (file);
      exit (1);
    }

  fseek (file, 0, SEEK_SET);

  starttime = time (NULL);
  eep_reset ();
  game_no = -1;
  do
    {
      if (game_no >= 0)                         // a game of a multi-game file
        romsize = game_table[game_no * 0x20 + 0x1e] * MBIT;
      else if (multi_game)
        romsize = PCE_PRO_LOADER_SIZE;          // the loader

      bytesleft = romsize;
      if (bytesleft == 4 * MBIT)
        bytesleft += 2 * MBIT;
      startaddress = address;

      while (bytesleft > 0 && (bytesread = fread (buffer, 1, 0x4000, file)) != 0)
        {
          if ((address & 0xffff) == 0)
            ttt_erase_block (address);
          write_block (&address, buffer);
          if ((romsize == 3 * MBIT) && (address - startaddress == 2 * MBIT))
            address += 2 * MBIT;
          else if ((romsize == 4 * MBIT) && (address - startaddress == 4 * MBIT))
            fseek (file, -2 * MBIT, SEEK_CUR);

          bytessent += bytesread;
          ucon64_gauge (starttime, bytessent, size);
          bytesleft -= bytesread;
        }
      // Games have to be aligned to a Mbit boundary.
      address = (address + MBIT - 1) & ~(MBIT - 1);
      game_no++;
    }
  while (multi_game ? (game_table[game_no * 0x20] && game_no < 31) : 0);

  fclose (file);

  return 0;
}
Example #7
0
qboolean
SNDDMA_Init (void)
{
	int         rc = 0, i;
	char       *err_msg = "";
	int         rate = -1, format = -1, bps, stereo = -1, frag_size;
	unsigned int mask;

	mask = snd_cards_mask ();
	if (!mask) {
		Con_Printf ("No sound cards detected\n");
		return 0;
	}
	if ((i = COM_CheckParm ("-sndcard")) != 0) {
		card = atoi (com_argv[i + 1]);
	}
	if ((i = COM_CheckParm ("-snddev")) != 0) {
		dev = atoi (com_argv[i + 1]);
	}
	if ((i = COM_CheckParm ("-sndbits")) != 0) {
		i = atoi (com_argv[i + 1]);
		if (i == 16) {
			format = SND_PCM_SFMT_S16_LE;
		} else if (i == 8) {
			format = SND_PCM_SFMT_U8;
		} else {
			Con_Printf ("Error: invalid sample bits: %d\n", i);
			return 0;
		}
	}
	if ((i = COM_CheckParm ("-sndspeed")) != 0) {
		rate = atoi (com_argv[i + 1]);
		if (rate != 44100 && rate != 22050 && rate != 11025) {
			Con_Printf ("Error: invalid sample rate: %d\n", rate);
			return 0;
		}
	}
	if ((i = COM_CheckParm ("-sndmono")) != 0) {
		stereo = 0;
	}
	if (card == -1) {
		for (card = 0; card < SND_CARDS; card++) {
			if (!(mask & (1 << card)))
				continue;
			rc = check_card (card);
			if (rc < 0)
				return 0;
			if (!rc)
				goto dev_openned;
		}
	} else {
		if (dev == -1) {
			rc = check_card (card);
			if (rc < 0)
				return 0;
			if (!rc)
				goto dev_openned;
		} else {
			if ((rc = snd_pcm_open (&pcm_handle, card, dev,
									SND_PCM_OPEN_PLAYBACK
									| SND_PCM_OPEN_NONBLOCK)) < 0) {
				Con_Printf ("Error: audio open error: %s\n", snd_strerror (rc));
				return 0;
			}
			goto dev_openned;
		}
	}
	Con_Printf ("Error: audio open error: %s\n", snd_strerror (rc));
	return 0;

  dev_openned:
	Con_Printf ("Using card %d, device %d.\n", card, dev);
	memset (&cinfo, 0, sizeof (cinfo));
	cinfo.channel = SND_PCM_CHANNEL_PLAYBACK;
	snd_pcm_channel_info (pcm_handle, &cinfo);
	Con_Printf ("%08x %08x %08x\n", cinfo.flags, cinfo.formats, cinfo.rates);
	if ((rate == -1 || rate == 44100) && cinfo.rates & SND_PCM_RATE_44100) {
		rate = 44100;
		frag_size = 512;				/* assuming stereo 8 bit */
	} else if ((rate == -1 || rate == 22050)
			   && cinfo.rates & SND_PCM_RATE_22050) {
		rate = 22050;
		frag_size = 256;				/* assuming stereo 8 bit */
	} else if ((rate == -1 || rate == 11025)
			   && cinfo.rates & SND_PCM_RATE_11025) {
		rate = 11025;
		frag_size = 128;				/* assuming stereo 8 bit */
	} else {
		Con_Printf ("ALSA: desired rates not supported\n");
		goto error_2;
	}
	if ((format == -1 || format == SND_PCM_SFMT_S16_LE)
		&& cinfo.formats & SND_PCM_FMT_S16_LE) {
		format = SND_PCM_SFMT_S16_LE;
		bps = 16;
		frag_size *= 2;
	} else if ((format == -1 || format == SND_PCM_SFMT_U8)
			   && cinfo.formats & SND_PCM_FMT_U8) {
		format = SND_PCM_SFMT_U8;
		bps = 8;
	} else {
		Con_Printf ("ALSA: desired formats not supported\n");
		goto error_2;
	}
	if (stereo && cinfo.max_voices >= 2) {
		stereo = 1;
	} else {
		stereo = 0;
		frag_size /= 2;
	}

//  err_msg="audio flush";
//  if ((rc=snd_pcm_channel_flush(pcm_handle, SND_PCM_CHANNEL_PLAYBACK))<0)
//      goto error;
	err_msg = "audio munmap";
	if ((rc = snd_pcm_munmap (pcm_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0)
		goto error;

	memset (&params, 0, sizeof (params));
	params.channel = SND_PCM_CHANNEL_PLAYBACK;
	params.mode = SND_PCM_MODE_BLOCK;
	params.format.interleave = 1;
	params.format.format = format;
	params.format.rate = rate;
	params.format.voices = stereo + 1;
	params.start_mode = SND_PCM_START_GO;
	params.stop_mode = SND_PCM_STOP_ROLLOVER;
	params.buf.block.frag_size = frag_size;
	params.buf.block.frags_min = 1;
	params.buf.block.frags_max = -1;
//  err_msg="audio flush";
//  if ((rc=snd_pcm_channel_flush(pcm_handle, SND_PCM_CHANNEL_PLAYBACK))<0)
//      goto error;
	err_msg = "audio params";
	if ((rc = snd_pcm_channel_params (pcm_handle, &params)) < 0)
		goto error;

	err_msg = "audio mmap";
	if (
		(rc =
		 snd_pcm_mmap (pcm_handle, SND_PCM_CHANNEL_PLAYBACK, &mmap_control,
					   (void **) &mmap_data)) < 0)
		goto error;
	err_msg = "audio prepare";
	if ((rc = snd_pcm_plugin_prepare (pcm_handle, SND_PCM_CHANNEL_PLAYBACK)) <
		0) goto error;

	memset (&setup, 0, sizeof (setup));
	setup.mode = SND_PCM_MODE_BLOCK;
	setup.channel = SND_PCM_CHANNEL_PLAYBACK;
	err_msg = "audio setup";
	if ((rc = snd_pcm_channel_setup (pcm_handle, &setup)) < 0)
		goto error;

	shm = &sn;
	memset ((dma_t *) shm, 0, sizeof (*shm));
	shm->splitbuffer = 0;
	shm->channels = setup.format.voices;
	shm->submission_chunk = 128;		// don't mix less than this #
	shm->samplepos = 0;					// in mono samples
	shm->samplebits = setup.format.format == SND_PCM_SFMT_S16_LE ? 16 : 8;
	shm->samples =
		setup.buf.block.frags * setup.buf.block.frag_size / (shm->samplebits / 8);	// mono 
																					// samples 
																					// in 
																					// buffer
	shm->speed = setup.format.rate;
	shm->buffer = (unsigned char *) mmap_data;
	Con_Printf ("%5d stereo\n", shm->channels - 1);
	Con_Printf ("%5d samples\n", shm->samples);
	Con_Printf ("%5d samplepos\n", shm->samplepos);
	Con_Printf ("%5d samplebits\n", shm->samplebits);
	Con_Printf ("%5d submission_chunk\n", shm->submission_chunk);
	Con_Printf ("%5d speed\n", shm->speed);
	Con_Printf ("0x%x dma buffer\n", (int) shm->buffer);
	Con_Printf ("%5d total_channels\n", total_channels);

	snd_inited = 1;
	return 1;
  error:
	Con_Printf ("Error: %s: %s\n", err_msg, snd_strerror (rc));
  error_2:
	snd_pcm_close (pcm_handle);
	return 0;
}
Example #8
0
int
smsgg_read_sram (const char *filename, unsigned short parport, int start_bank)
{
  FILE *file;
  unsigned char buffer[0x100];
  int blocksleft, address, size, bytesreceived = 0;
  time_t starttime;
  void (*read_block) (int, unsigned char *) = ttt_read_ram_b; // ttt_read_ram_w

  if (start_bank == -1)
    {
      address = 0;
      size = 128 * 1024;
    }
  else
    {
      if (start_bank < 1 || start_bank > 4)
        {
          fputs ("ERROR: Bank must be a value 1 - 4\n", stderr);
          exit (1);
        }
      address = (start_bank - 1) * 32 * 1024;
      size = 32 * 1024;
    }

  if ((file = fopen (filename, "wb")) == NULL)
    {
      fprintf (stderr, ucon64_msg[OPEN_WRITE_ERROR], filename);
      exit (1);
    }

  ttt_init_io (parport);
  printf ("Receive: %d Bytes (%.4f Mb)\n\n", size, (float) size / MBIT);

  if (check_card () == 0)
    {
      fclose (file);
      remove (filename);
      exit (1);
    }

  if (read_block == ttt_read_ram_w)
    {
      ttt_ram_enable ();
      ttt_set_ai_data (6, 0x98);        // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS
    }
//  else
//    ttt_set_ai_data (6, 0x94);          // rst=1, wei=0(dis.), rdi=0(dis.), inc mode, rom_CS

  blocksleft = size >> 8;
  starttime = time (NULL);
  while (blocksleft-- > 0)
    {
      read_block (address, buffer);             // 0x100 bytes read
      fwrite (buffer, 1, 0x100, file);
      address += 0x100;
      bytesreceived += 0x100;
      if ((address & 0x3fff) == 0)
        ucon64_gauge (starttime, bytesreceived, size);
    }
  if (read_block == ttt_read_ram_w)
    ttt_ram_disable ();

  fclose (file);

  return 0;
}