Ejemplo n.º 1
0
/**
 * tnsp_file_display:
 * @filename: a TI file.
 *
 * Determine file class and display internal content.
 *
 * Return value: an error code, 0 otherwise.
 **/
int tnsp_file_display(const char *filename)
{
	FileContent *content1;
	FlashContent *content3;
	int ret;

	if (tifiles_file_is_os(filename)) 
	{
		content3 = tifiles_content_create_flash(CALC_NSPIRE);
		ret = tnsp_file_read_flash(filename, content3);
		if (!ret)
		{
			tnsp_content_display_flash(content3);
			tifiles_content_delete_flash(content3);
		}
	}
	else if (tifiles_file_is_regular(filename)) 
	{
		content1 = tifiles_content_create_regular(CALC_NSPIRE);
		ret = tnsp_file_read_regular(filename, content1);
		if (!ret)
		{
			tifiles_file_display_regular(content1);
			tifiles_content_delete_regular(content1);
		}
	}
	else
	{
		tifiles_info("Unknown file type !");
		return ERR_BAD_FILE;
	}

	return ret;
}
Ejemplo n.º 2
0
/**
 * tnsp_file_display:
 * @filename: a TI file.
 *
 * Determine file class and display internal content.
 *
 * Return value: an error code, 0 otherwise.
 **/
int tnsp_file_display(const char *filename)
{
  FileContent *content1;
  FlashContent *content3;

  // the testing order is important: regular before backup (due to TI89/92+)
  if (tifiles_file_is_os(filename)) 
  {
	content3 = tifiles_content_create_flash(CALC_NSPIRE);
    tnsp_file_read_flash(filename, content3);
    tnsp_content_display_flash(content3);
    tifiles_content_delete_flash(content3);
  } 
  else if (tifiles_file_is_regular(filename)) 
  {
	content1 = tifiles_content_create_regular(CALC_TI92);
    tnsp_file_read_regular(filename, content1);
    tnsp_content_display_regular(content1);
    tifiles_content_delete_regular(content1);
  }
  else
  {
      tifiles_info("Unknown file type !");
      return ERR_BAD_FILE;
  }

  return 0;
}
Ejemplo n.º 3
0
/**
 * tifiles_file_test:
 * @filename: a filename as string.
 * @type: type to check
 * @target: hand-held model or CALC_NONE for no filtering
 *
 * Check whether #filename is a TI file of type #type useable on a #target model.
 * This function is a generic one which overwrap and extends the tifiles_file_is_* 
 * functions.
 *
 * This is a powerful function which allows checking of a specific file type for
 * a given target.
 *
 * Return value: a boolean value.
 **/
TIEXPORT2 int TICALL tifiles_file_test(const char *filename, FileClass type, CalcModel target)
{
	char *e = tifiles_fext_get(filename);

	if (!tifiles_file_is_ti(filename))
		return 0;

	if (!strcmp(e, ""))
		return 0;

	if(target > CALC_MAX)
	{
		tifiles_critical("tifiles_file_test: invalid target argument! This is a bug.");
		return 0;
	}

	if(type & TIFILE_SINGLE)
	{
		if(target && !g_ascii_strncasecmp(e, GROUP_FILE_EXT[target], 2))
			return !0;
		else
			return tifiles_file_is_single(filename);
	}
	
	if(type & TIFILE_GROUP)
	{
		if(target && !g_ascii_strcasecmp(e, GROUP_FILE_EXT[target]))
			return !0;
		else
			return tifiles_file_is_group(filename);
	}
	
	if(type & TIFILE_REGULAR)
	{
		return tifiles_file_test(filename, TIFILE_SINGLE, target) ||
				tifiles_file_test(filename, TIFILE_GROUP, target);
	}
	
	if(type & TIFILE_BACKUP)
	{
		if(target && !g_ascii_strcasecmp(e, BACKUP_FILE_EXT[target]))
			return !0;
		else
			return tifiles_file_is_backup(filename);
	}
	
	if(type & TIFILE_OS)
	{
		if(target && !g_ascii_strcasecmp(e, FLASH_OS_FILE_EXT[target]))
			return !0;
		else if(target && tifiles_file_is_tib(filename))
		{
			FILE *f;
			uint8_t data[16];

			f = g_fopen(filename, "rb");
			if(f == NULL)
				return 0;

			fread_n_chars(f, 16, (char *)data);
			fclose(f);

			switch(data[8])
			{
			case 1: if(target != CALC_TI92P) return 0;
			case 3: if(target != CALC_TI89)  return 0;
			case 8: if(target != CALC_V200)  return 0;
			case 9: if(target != CALC_TI89T) return 0;
			}

			return !0;
		}
		else
			return tifiles_file_is_os(filename);
	}
	
	if(type & TIFILE_APP)
	{
		if(target && !g_ascii_strcasecmp(e, FLASH_APP_FILE_EXT[target]))
			return !0;
		else
			return tifiles_file_is_app(filename);
	}
	
	if(type & TIFILE_FLASH)
	{
		return tifiles_file_test(filename, TIFILE_OS, target) ||
				tifiles_file_test(filename, TIFILE_APP, target);
	}
	
	if(type & TIFILE_TIGROUP)
	{
		if(target)
		{
			// No easy/light way for this part: we have to load the whole file 
			// and to parse the TigEntry structures.
			TigContent *content;
			int ret, ok=0;
			int k;

			if(!tifiles_file_has_tig_header(filename))
				return 0;

			content = tifiles_content_create_tigroup(CALC_NONE, 0);
			ret = tifiles_file_read_tigroup(filename, content);
			if(ret) return 0;

			for (k = 0; k < content->n_apps; k++)
			{
				TigEntry *te = content->app_entries[k];

				if(tifiles_calc_are_compat(te->content.regular->model, target))
					ok++;
			}

			for (k = 0; k < content->n_vars; k++)
			{
				TigEntry *te = content->var_entries[k];

				if(tifiles_calc_are_compat(te->content.regular->model, target))
					ok++;
			}

			tifiles_content_delete_tigroup(content);
			return ok;
		}
		else
			return tifiles_file_is_tigroup(filename);
	}

	return 0;
}
Ejemplo n.º 4
0
/**
 * tifiles_file_is_flash:
 * @filename: a filename as string.
 *
 * Check whether file is a FLASH file (os or app).
 *
 * Return value: a boolean value.
 **/
TIEXPORT2 int TICALL tifiles_file_is_flash(const char *filename)
{
  return tifiles_file_is_os(filename) || tifiles_file_is_app(filename);
}
Ejemplo n.º 5
0
int ti68k_is_a_tib_file(const char *filename)
{
	return tifiles_file_is_os(filename);
}
Ejemplo n.º 6
0
/*
  Get some information on the FLASH upgrade:
  - size
  - ROM base address
  - os version
  - calc type
*/
int ti68k_get_tib_infos(const char *filename, IMG_INFO *tib, int preload)
{
	FlashContent *content;
	FlashContent *ptr;
	int nheaders = 0;
	int i;

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

	// Check valid file
	if(!tifiles_file_is_ti(filename))
		return ERR_NOT_TI_FILE;
		
	if(!tifiles_file_is_os(filename))
		return ERR_INVALID_UPGRADE;

	// Load file
	content = tifiles_content_create_flash(CALC_TI89);
	if(tifiles_file_read_flash(filename, content) != 0)
        return ERR_INVALID_UPGRADE;
	
	// count headers
  	for (ptr = content; ptr != NULL; ptr = ptr->next)
    	nheaders++;
  	
  	// keep the last one (data)
  	for (i = 0, ptr = content; i < nheaders - 1; i++)
    	ptr = ptr->next;
    	
  	// Load TIB into memory and relocate at SPP
	if(tib->data == NULL)
  		tib->data = malloc(SPP + ptr->data_length + 4);
	if(tib->data == NULL)
		return ERR_MALLOC;

    memset(tib->data + SPP, 0xff, ptr->data_length);
  	memcpy(tib->data + SPP, ptr->data_part, ptr->data_length);
  	
  	// Update current rom infos
    tib->rom_base = tib->data[BO+5 + SPP] & 0xf0;

	// libtifiles can't distinguish TI89/TI89t and 92+/V200. We need to look.
	switch(ptr->device_type & 0xff)
	{
		case DEVICE_TYPE_89:    // can be a Titanium, too
            switch(tib->rom_base & 0xff)
            {
            case 0x20: tib->calc_type = TI89;  break;
            case 0x80: tib->calc_type = TI89t; break;
            default: return ERR_INVALID_UPGRADE;
            }
		break;
		case DEVICE_TYPE_92P:
            switch(tib->rom_base & 0xff)
            {
            case 0x20: tib->calc_type = V200;  break;
            case 0x40: tib->calc_type = TI92p; break;
            default: return ERR_INVALID_UPGRADE;
            }
		break;
		default:
			tiemu_info("TIB problem: %02x!\n", 0xff & ptr->device_type);
			return ERR_INVALID_UPGRADE;
		break;
	}
    
  	tib->flash = FLASH_ROM;
  	tib->has_boot = 0;
  	tib->size = ptr->data_length + SPP;

  	get_rom_version(tib->data, tib->size, tib->version);
  	
  	tifiles_content_delete_flash(content);
	if(!preload)
		free(tib->data);

  	return 0;
}