Пример #1
0
/*
	Try to get some information on the ROM dump:
	- size
	- ROM base address
	- FLASH/EPROM
	- soft version
	- calc type
*/
int ti68k_get_img_infos(const char *filename, IMG_INFO *ri)
{
	FILE *f;

	// No filename, exits
	if(!strcmp(g_basename(filename), ""))
	   return ERR_CANT_OPEN;

	// Check file
	if(!ti68k_is_a_img_file(filename))
	{
		tiemu_warning("Images must have '.img' extension (%s).\n",
			filename);
		return ERR_CANT_OPEN;
	}
	
	// Open dest file
  	f = fopen(filename, "rb");
  	if(f == NULL)
    {
      	tiemu_warning("Unable to open this file: <%s>\n", filename);
      	return ERR_CANT_OPEN;
    }
    
    // Read header
    if (fread(ri, sizeof(IMG_INFO), 1, f) < 1)
    {
      tiemu_warning("Failed to read from file: <%s>\n", filename);
      fclose(f);
      return ERR_CANT_OPEN;
    }

    if(strcmp(ri->signature, IMG_SIGN) || ri->size > 4*MB)
    {
      tiemu_warning("Bad image: <%s>\n", filename);
      return ERR_INVALID_UPGRADE;
    }

    // Close file
    if (fclose(f))
    {
      tiemu_warning("Failed to close file: <%s>\n", filename);
      return ERR_CANT_OPEN;
    }
    
    return 0;
}
Пример #2
0
/*
    Returns the first found image
*/
int ti68k_find_image(const char *dirname, char **dst_name)
{
    GDir *dir;
	GError *error = NULL;
	G_CONST_RETURN gchar *dirent;
    int ret = 0;
    char *filename;
    
    if(dst_name != NULL)
	    *dst_name = NULL;

    // Search for *.img files and convert them
	dir = g_dir_open(dirname, 0, &error);
	if (dir == NULL) 
	{
		tiemu_warning(_("Opendir error"));
      	return ERR_CANT_OPEN_DIR;
	}

    filename = NULL;

    while ((dirent = g_dir_read_name(dir)) != NULL) 
	{
  		if (dirent[0] == '.') 
  			continue;

        if(!ti68k_is_a_img_file(dirent))
            continue;

        filename = g_strconcat(dirname, dirent, NULL);
        ret = !0;
        break;
    }

    g_dir_close(dir);

    if(dst_name != NULL)
        *dst_name = filename;

    return ret;
}
Пример #3
0
int fs_load_state(const char *filename)
{
	int err;

	g_free(params.sav_file);
    params.sav_file = g_strdup(filename);
    
    err = ti68k_state_load(params.sav_file);
	if(err == ERR_STATE_MATCH)
	{
		gchar *rf, *tf;
		int ret = msg_box2(_("Warning"), 
			_("The state image you are attempting to load does not match the current running image. Press OK if you want TiEmu to automatically load the corresponding image or Cancel to abort."));
		
		if(ret == BUTTON2)	//cancel
			return 0;

		ti68k_state_parse(filename, &rf, &tf);
		
		if(!ti68k_is_a_img_file(rf))
			return 0;

        // Set tib file and image
        g_free(params.tib_file);
		params.tib_file = tf;

		g_free(params.rom_file);
		params.rom_file = rf;

		// Restart engine by exiting the GTK loop
		while(gtk_events_pending()) gtk_main_iteration();
		gtk_main_quit();	
	}
	else
		handle_error();

	return 0;
}
Пример #4
0
/*
	Try to get some informations on the ROM dump:
	- size
	- ROM base address
	- FLASH/EPROM
	- soft version
	- calc type
*/
int ti68k_get_img_infos(const char *filename, IMG_INFO *ri)
{
	FILE *f;

	// No filename, exits
	if(!strcmp(g_basename(filename), ""))
	   return ERR_CANT_OPEN;

	// Check file
	if(!ti68k_is_a_img_file(filename))
	{
		fprintf(stderr, "Images must have '.img' extension (%s).\n",
			filename);
		return ERR_CANT_OPEN;
	}
	
	// Open dest file
  	f = fopen(filename, "rb");
  	if(f == NULL)
    {
      	fprintf(stderr, "Unable to open this file: <%s>\n", filename);
      	return ERR_CANT_OPEN;
    }
    
    // Read header
    fread(ri, sizeof(IMG_INFO), 1, f);
    if(strcmp(ri->signature, "TiEmu img v2.00"))
   	{
   		fprintf(stderr, "Bad image: <%s>\n", filename);
      	return ERR_INVALID_UPGRADE;
   	}
    
    // Close file
    fclose(f);
    
    return 0;
}
Пример #5
0
gint display_romversion_dbox(gboolean file_only)
{
    GladeXML *xml;
	GtkWidget *data;
    gint result;
    GtkListStore *store;
	
	xml = glade_xml_new
		(tilp_paths_build_glade("romversion-2.glade"), "romversion_dbox",
		 PACKAGE);
	if (!xml)
		g_error(_("%s: GUI loading failed!\n"), __FILE__);
	glade_xml_signal_autoconnect(xml);

    // display list box
	dbox = glade_xml_get_widget(xml, "romversion_dbox");
	gtk_dialog_set_alternative_button_order(GTK_DIALOG(dbox), GTK_RESPONSE_OK,
	                                        GTK_RESPONSE_CANCEL,-1);
    
    data = glade_xml_get_widget(xml, "clist1");
    store = clist_create(data);
	clist_populate(store);
    
	// run main box
	gtk_dialog_set_response_sensitive(GTK_DIALOG(dbox), GTK_RESPONSE_OK, FALSE);
	result = gtk_dialog_run(GTK_DIALOG(dbox));
	gtk_widget_destroy(dbox);

	switch (result) 
	{
		case GTK_RESPONSE_OK:
            if(chosen_file == NULL)
                break;

			if(!ti68k_is_a_img_file(chosen_file))
				break;

            // Remove previous tib file
            g_free(params.tib_file);
			params.tib_file = g_strconcat("", NULL);

            // Set new image
			g_free(params.rom_file);
			params.rom_file = g_strconcat(inst_paths.img_dir, chosen_file, NULL);
			g_free(chosen_file);
            chosen_file = NULL;

            if(file_only) return 0;

            // Restart engine by exiting the GTK loop
			g_free(params.sav_file);
			params.sav_file = g_strdup("");

			while(gtk_events_pending()) gtk_main_iteration();
			gtk_main_quit();	
		break;
		
		default:
            if(file_only) return -1;
		break;
	}

	return 0;
}
Пример #6
0
/*
  Scan the command line, extract arguments and init variables
*/
int scan_cmdline(int argc, char **argv)
{
	int cnt;
	char *p;
	char msg[80];

	int import = 0;
	char *rom = NULL;
	char *tib = NULL;
	char *sav = NULL;
	char *fn = NULL;

	//for(cnt = 0; cnt < argc; cnt++)
	//	fprintf(stdout, "%i: [%s]\n", cnt, argv[cnt]);
  
	/* Parses list of arguments */
	for(cnt=1; cnt<argc; cnt++) 
	{
		p = argv[cnt];

#ifdef __WIN32__
		if(!stricmp(p, "/RegServer") || !stricmp(p, "-RegServer")
		   || !stricmp(p, "--RegServer")) {
			char *p;
			ITypeLib *tlb;
			char szModule[512];
			wchar_t tlbname[512];
			HMODULE hModule = GetModuleHandle(NULL);
			DWORD dwResult = GetModuleFileName(hModule, szModule, sizeof(szModule));

			if (!dwResult) exit(1);
			p = szModule + strlen(szModule) - 4;

			if (stricmp(p,".exe")) exit(1);
			strcpy(++p,"tlb");
			mbstowcs(tlbname, szModule, strlen(szModule)+1);

			if (RegisterServer(&CLSID_TiEmuOLE,
			                   "TiEmu OLE Interface",
			                   "TiEmu.TiEmuOLE",
			                   "TiEmu.TiEmuOLE.1", NULL)
			    || LoadTypeLib(tlbname, &tlb))
				exit(1);
			else {
				if (RegisterTypeLib(tlb, tlbname, NULL)) {
					tlb->lpVtbl->Release(tlb);
					exit(1);
				} else {
					tlb->lpVtbl->Release(tlb);
					fprintf(stdout, "TiEmu OLE Interface successfully registered.");
					exit(0);
				}
			}
		}

		if(!stricmp(p, "/UnregServer") || !stricmp(p, "-UnregServer")
		   || !stricmp(p, "--UnregServer")) {
			if (UnregisterServer(&CLSID_TiEmuOLE, "TiEmu.TiEmuOLE",
			                     "TiEmu.TiEmuOLE.1")
			    || UnRegisterTypeLib(&LIBID_TiEmuOLELib, 1, 0, 0,
			                         SYS_WIN32))
				exit(1);
			else {
				fprintf(stdout, "TiEmu OLE Interface successfully unregistered.");
				exit(0);
			}
		}
		if(!stricmp(p, "/Embedding") || !stricmp(p, "-Embedding")
		   || !stricmp(p, "--Embedding")) {
			// VB runs it with this option.
			continue;
		}
#endif

		if(*p == '-') 
		{
			// a long option (like --help)
			p++;
		} else 
		{
			fn = g_strdup(p);
			// a filename
			//g_free(params.rom_file);
			//params.rom_file = g_strdup(p);
		}
		strcpy(msg, p);

		if(strexact(msg, "-import")) 
			import = !0;

		if(strstr(msg, "rom="))
			rom = g_strdup(msg + 4);

		if(strstr(msg, "tib="))
			tib = g_strdup(msg + 4);

		if(strstr(msg, "sav=")) 
			sav = g_strdup(msg + 4);

		if(strstr(msg, "send="))
			file_to_send = g_strdup(msg + 5);
	      
		if(strexact(msg, "-help") || strexact(msg, "h")) 
			help();

		if(strexact(msg, "-version") || strexact(msg, "v")) 
			exit(0);
	}

	/* */
	if(fn && ti68k_is_a_rom_file(fn))
		rom = fn;
	else if(fn && ti68k_is_a_tib_file(fn))
		tib = fn;
	else if(fn && ti68k_is_a_sav_file(fn))
		sav = fn;

	/* And process them */
	if(rom && ti68k_is_a_rom_file(rom))
	{
		gchar *dstname;

		int err = ti68k_convert_rom_to_image(rom, inst_paths.img_dir, &dstname);
		if(err) 
		{
			tiemu_err(err, NULL);
			exit(-1);
		}

		if(import)
			exit(0);

		g_free(params.rom_file);
		params.rom_file = dstname;
		g_free(params.sav_file);
		params.sav_file = g_strdup("");
	}

	if(tib && ti68k_is_a_tib_file(tib))
	{
		gchar *dstname;

		int err = ti68k_convert_tib_to_image(tib, inst_paths.img_dir, &dstname, -1);
		if(err) 
		{
			tiemu_err(err, NULL);
			exit(-1);
		}

		if(import)
			exit(0);

		g_free(params.rom_file);
		params.rom_file = dstname;
		g_free(params.sav_file);
		params.sav_file = g_strdup("");
	 }

	if(sav && !fn)						// for compatibility
	{
		g_free(params.sav_file);
		params.sav_file = g_strdup(sav);
	}

	if(sav && ti68k_is_a_sav_file(sav) && fn)
	{
		gchar *rf, *tf;

		ti68k_state_parse(sav, &rf, &tf);
		
		if(!ti68k_is_a_img_file(rf))
			return 0;

		g_free(params.rom_file);
		params.rom_file = rf;

        g_free(params.tib_file);
		params.tib_file = tf;

		g_free(params.sav_file);
		params.sav_file = g_strdup(sav);
	}

	return 0;
}
Пример #7
0
/*
  	Scan images in a given directory and write list into img_list.txt.
*/
int ti68k_scan_images(const char *dirname, const char *filename)
{
	FILE *file;
	IMG_INFO img;
	GDir *dir;
	GError *error = NULL;
	G_CONST_RETURN gchar *dirent;
	gchar *path, *str;
	int ret;
	struct stat f_info;
  	char *line[7];

  	tiemu_info(_("Scanning images/upgrades... "));

	// Create file (and overwrite)
	file = fopen(filename, "wt");
    if(file == NULL)
	{
	  	tiemu_warning(_("Unable to open this file: <%s>"), filename);
	  	return ERR_CANT_OPEN;
	} 	

  	// List all files available in the directory
	dir = g_dir_open(dirname, 0, &error);
	if (dir == NULL) 
	{
		tiemu_warning(_("Opendir error"));
      	return ERR_CANT_OPEN_DIR;
	}
  
	while ((dirent = g_dir_read_name(dir)) != NULL) 
	{
  		if (dirent[0] == '.') 
  			continue;
   
	  	path = g_strconcat(dirname, dirent, NULL);
	  	
		ret = stat(path, &f_info);
		if(ret == -1)
		{
			tiemu_warning(_("Can not stat: <%s>"), dirent);
	      	perror("stat: ");
		}
		else
		{
			if(ti68k_is_a_img_file(path))
			{
				memset(&img, 0, sizeof(IMG_INFO));
				ret = ti68k_get_img_infos(path, &img);
				if(ret)
				{
					tiemu_warning(_("Can not get ROM/update info: <%s>"), path);
					break;
				}
			}
            else
				continue;

			str = g_strdup_printf("%iKB", (int)(img.size >> 10));

		  	line[0] = (char *)dirent;
		  	line[1] = (char *)ti68k_calctype_to_string(img.calc_type);
	  		line[2] = img.version;
	  		line[3] = (char *)ti68k_romtype_to_string(img.flash);
	  		line[4] = str;
			line[5] = img.has_boot ? _("yes") : _("no");
			line[6] = (char *)ti68k_hwtype_to_string(img.hw_type);
	  
		  	fprintf(file, "%s,%s,%s,%s,%s,%s,%s\n", 
		  			line[0], line[1], line[2], 
		  			line[3], line[4], line[5], line[6]);
			g_free(str);
		}
	  	g_free(path);
    }      

	// Close
	g_dir_close(dir);
  
  	fclose(file);
  	tiemu_info(_("Done."));
  
  	return 0;
}
Пример #8
0
/*
	Try to get some information on the ROM dump:
	- size
	- ROM base address
	- FLASH/EPROM
	- soft version
	- calc type
*/
int ti68k_get_img_infos(const char *filename, IMG_INFO *ri)
{
	FILE *f;
	IMG_INFO32 ri32;
	IMG_INFO64 ri64;

	// No filename, exits
	if(!strcmp(g_basename(filename), ""))
	   return ERR_CANT_OPEN;

	// Check file
	if(!ti68k_is_a_img_file(filename))
	{
		tiemu_warning("Images must have '.img' extension (%s).\n",
			filename);
		return ERR_CANT_OPEN;
	}
	
	// Open dest file
  	f = fopen(filename, "rb");
  	if(f == NULL)
    {
      	tiemu_warning("Unable to open this file: <%s>\n", filename);
      	return ERR_CANT_OPEN;
    }
    
    // Read header
    if (fread(&ri32, sizeof(IMG_INFO32), 1, f) < 1)
    {
      tiemu_warning("Failed to read from file: <%s>\n", filename);
      fclose(f);
      return ERR_CANT_OPEN;
    }
    *ri = ri32;

	// below is patch from Lionel
    if(strcmp(ri->signature, IMG_SIGN) || ri->size > 4*MB || ri->calc_type > CALC_MAX
       || ri->header_size == 0 || ri->hw_type > 4 || ri->rom_base == 0)
    {
      // In addition to plain invalid files, this may happen if the image was
      // created on a 64-bit platform with TIEmu <= 3.03.
      // Try to read an IMG_INFO structure as it used to be written by those
      // 64-bit platforms.
      fseek(f, 0, SEEK_SET);
      if (fread(&ri64, sizeof(IMG_INFO64), 1, f) < 1)
      {
        tiemu_warning("Failed to read from file: <%s>\n", filename);
        fclose(f);
        return ERR_CANT_OPEN;
      }
      else {
        memcpy(ri->signature, &(ri64.signature), sizeof(ri64.signature));
        ri->revision = (int32_t)(ri64.revision);
        ri->header_size = (int32_t)(ri64.header_size);

        ri->calc_type = ri64.calc_type;
        memcpy(ri->version, &(ri64.version), sizeof(ri64.version));
        ri->flash = ri64.flash;
        ri->has_boot = ri64.has_boot;
        ri->size = (int32_t)(ri64.size);
        ri->hw_type = ri64.hw_type;
        ri->rom_base = ri64.rom_base;
          
        if(strcmp(ri->signature, IMG_SIGN) || ri->size > 4*MB || ri->calc_type > CALC_MAX
           || ri->header_size == 0 || ri->hw_type > 4 || ri->rom_base == 0)
        {
          // Nope, it still doesn't seem to be a TIEmu image.
          tiemu_warning("Bad image: <%s>\n", filename);
          return ERR_INVALID_UPGRADE;
        }
        else {
          tiemu_info("Found a reasonably valid 64-bit IMG_INFO in <%s>\n", filename);
        }
      }
    }

    // Close file
    if (fclose(f))
    {
      tiemu_warning("Failed to close file: <%s>\n", filename);
      return ERR_CANT_OPEN;
    }
    
    return 0;
}