static void
compegps_data_write(void)
{
	/* because of different file extensions we can only write one GPS data type at time */
	
	gbfprintf(fout, "G  WGS 84\n");
	gbfprintf(fout, "U  1\n");
	
	/* process options */
	
	target_index = 1;
	if (option_index != NULL)
		target_index = atoi(option_index);
		
	snlen = 0;
	if (global_opts.synthesize_shortnames != 0)
	{
		if (option_snlen != NULL)
			snlen = atoi(option_snlen);
		else
			snlen = SHORT_NAME_LENGTH;
		
		is_fatal((snlen < 1), MYNAME "Invalid length for generated shortnames!");
		
		setshort_whitespace_ok(sh, 0);
		setshort_length(sh, snlen);
	}
	
	radius = -1;
	if (option_radius != 0)
	{
	    radius = atof(option_radius);
	    is_fatal((radius <= 0.0), MYNAME "Invalid value for radius!");
	}
	
	if (option_icon != NULL)
	{
		if (*option_icon == '\0')
			option_icon = NULL;
		else if (case_ignore_strcmp(option_icon, "deficon") == 0)
			option_icon = NULL;
	}
	
	switch(global_opts.objective)
	{
		case wptdata:
			curr_index = target_index = 0;
			write_waypoints();
			break;
		case trkdata:
			write_track();
			break;
		case rtedata:
			write_route();
			break;
		case posndata:
			fatal(MYNAME ": Realtime positioning not supported.\n");
			break;
	}
}
Exemple #2
0
bool UnformatImage (const std::string &path, Range range)
{
	auto disk = std::make_shared<Disk>();
	if (!ReadImage(path, disk))
		return false;

	ValidateRange(range, MAX_TRACKS, MAX_SIDES, disk->cyls(), disk->heads());

	range.each([&] (const CylHead &cylhead) {
		if (!g_fAbort)
			disk->write_track(cylhead, Track());
	});

	return WriteImage(path, disk);
}
Exemple #3
0
bool CreateImage (const std::string &path, Range range)
{
	auto disk = std::make_shared<Disk>();

	// Start with legacy default formats, with automatic gap 3
	Format fmt = IsFileExt(path, "cpm") ? RegularFormat::ProDos : RegularFormat::MGT;
	fmt.gap3 = 0;

	// Allow everything about the format to be overridden, but check it
	fmt.Override(true);
	fmt.Validate();
	ValidateRange(range, MAX_TRACKS, MAX_SIDES);

	// Set the disk label, if supplied
	if (!opt.label.empty())
		disk->metadata["label"] = opt.label;

	// Extend or format the disk
	if (opt.noformat)
		disk->write_track(CylHead(range.cyl_end - 1, range.head_end - 1), Track());
	else
		disk->format(fmt);

	// Write to the output disk image
	WriteImage(path, disk);

	// Report the new disk parameters, unless it's already been displayed (raw)
	if (!IsFileExt(path, "raw"))
	{
		auto cyls = disk->cyls();
		auto heads = disk->heads();

		if (opt.noformat)
			util::cout << util::fmt("Created %2u cyl%s, %u head%s, unformatted.\n", cyls, (cyls == 1) ? "" : "s", heads, (heads == 1) ? "" : "s");
		else
		{
			util::cout << util::fmt("Created %2u cyl%s, %u head%s, %2u sector%s/track, %4u bytes/sector\n",
									cyls, (cyls == 1) ? "" : "s", heads, (heads == 1) ? "" : "s",
									fmt.sectors, (fmt.sectors == 1) ? "" : "s", fmt.sector_size());
		}
	}

	return true;
}
int main(int argc, char *argv[])
{
  int status;
  unsigned char *p;
  int k;

  TSTTITLE("TESTING WRITE MIDIFILE");
  TSTSECTION("Buffer write function");

  TSTGROUP("Buffer sizing");

  status = chk_evt_buf(16);
  TST("Room allocated", (status == 0 && (evt_buf_sz - evt_buf_wm) >= 1024));

  TSTGROUP("Buffer writing");
  p=evt_buf;
  b_write8(0xAB);
  b_write7(0xCD);
  
  #if 0
  b_write16(0xFEDA); /* 1111 1110 1101 1010*/
  b_write14(0xFEDA);
  b_write32(0xFEEDBAC0);
  #endif

  TST("Write  8 bits",(p[0] == 0xAB));
  TST("Write  7 bits",(p[1] == (0xCD & 0x7F)));
  #if 0
  TST("Write 16 bits",(p[2] == 0xFE && p[3] == 0xDA)); /*1111 1110 1101 1010*/
  TST("Write 14 bits",(p[4] == 0x7D && p[5] == 0x5A)); /*0111 1101 0101 1010*/
  TSTONFAIL("Bytes written: %02x %02x",p[4],p[5]);
  #endif

  TSTGROUP("Raw write track");
  h_writetrack = (t_writetrack) mywritetrack1;
  h_error = (t_error) mf_null_handler;

  status = write_track(1);
  TST("write_track() returned unsuccessfully",(status == 309));
  TSTONFAIL("return code: %d\n",status);
  midi_file = fopen("test_file.mid","wb");
  status = write_track(1);
  TST("write_track() returned successfully",(status == 0));
  fclose(midi_file);

  midi_file = fopen("test_file.mid","rb");
  TST("File reopened for read",(midi_file != NULL));

  if (midi_file) {
    /* Now, if everything went well the file should contain:
    *   MTrk 00 00 00 0C 00 90 3C 64 60 3E 64 83 60 FF 2F 00
    */
    TSTWRITE("#");
    p = "MTrk\0\0\0\x0C\0\x90\x3C\x64\x60\x3E\x64\x83\x60\xFF\x2F\0";
    for (k=0; k<20; k++) {
      if (p[k] != fgetc(midi_file)) break;
      TSTWRITE(" %02X",p[k]);
    }
    TSTWRITE("\n");
    TST("File written correctly",(k == 20));

    fclose(midi_file);
    midi_file = NULL;
  }

  h_writetrack = (t_writetrack) mywritetrack2;
  status = mf_write("test_file.mid",0,1,96);
  TST("mf_write succeeded",(status == 0));

  TSTDONE();

  if (midi_file) fclose(midi_file);

  return (0);
}
bool ti99_floppy_format::save(io_generic *io, floppy_image *image)
{
	int act_track_size = 0;

	UINT8 bitstream[500000/8];
	UINT8 trackdata[9216];   // max size

	int cellsizes[] = { 2000, 4000, 1000, 2000 };

	// Do we use double-stepping?
	// If our image was loaded into a 80-track drive, we will always write 80 tracks.
	int maxtrack, maxheads;
	image->get_maximal_geometry(maxtrack, maxheads);

	if (maxtrack > 80) maxtrack = 80;
	else
	{
		if (maxtrack > 35 && maxtrack < 80) maxtrack = 40;
		else maxtrack = 35;
	}

	int attempt = 0;
	int sector[36];
	int maxsect = 18;
	bool write = true;

	// We expect a bitstream of length 50000 for FM and 100000 for MFM
	for(int head=0; head < 2; head++)
	{
		int track = 0;
		while (track < maxtrack)
		{
			int cell_size = cellsizes[attempt];
			int encoding = get_encoding(cell_size);
			int track_size = get_track_size(cell_size, 36); // max number of sectors

			// Retrieve the cells from the flux sequence
			generate_bitstream_from_track(track, head, cell_size, bitstream, act_track_size, image);

			// Maybe the track has become longer due to moving splices
			if (act_track_size > 200000000/cell_size) act_track_size = 200000000/cell_size;

			int marks = decode_bitstream(bitstream, trackdata, sector, act_track_size, encoding, (encoding==floppy_image::FM)? 0xff:0x4e, track_size);

			if (track==0)
			{
				if (head==0)
				{
					// Find the highest sector in the track
					// This is only needed for the SDF format
					int i=35;
					while (i>=0 && sector[i]==-1) i--;

					if (i>18) maxsect = 36;
					else
					{
						if (i>16) maxsect = 18;
						else
						{
							if (i>9) maxsect = 16;
							else maxsect = 9;
						}
					}
					if (TRACE) osd_printf_info("ti99_dsk: Sectors/track: %d\n", maxsect);

					// We try different cell sizes until we find a fitting size.
					// If this fails, we fall back to a size of 2000 ns
					// The criterion for a successful decoding is that we find at least
					// 6 ID or data address marks on the track. It is highly unlikely
					// to find so many marks with a wrong cell size.
					if (marks < 6 && attempt < 4)
					{
						if (TRACE) osd_printf_verbose("ti99_dsk: Decoding with cell size %d failed.\n", cell_size);
						attempt++;
						write = false;
					}
					else write = true;
				}
				else
				{
					if (marks < 6)
					{
						if (min_heads()==1)
						{
							if (TRACE) osd_printf_info("ti99_dsk: We don't have a second side and the format allows for single-sided recording.\n");
							return true;
						}
						else
						{
							osd_printf_warning("ti99_dsk: No second side, but this format requires two-sided recording. Saving empty tracks.\n");
						}
					}
				}
			}

			if (write)
			{
				if (TRACE)
				{
					if (head == 0 && track == 0)
					{
						if (marks >=6) { if (TRACE) osd_printf_info("ti99_dsk: Decoding with cell size %d successful.\n", cell_size); }
						else osd_printf_info("ti99_dsk: No address marks found on track 0. Assuming MFM format.\n");
					}
				}
				// Save to the file
				write_track(io, trackdata, sector, track, head, maxsect, maxtrack, track_size);
				track++;
			}
		}
	}

	return true;
}