示例#1
0
bool WizardStartPage::UpdateROMPathState(bool error) {
	TIFILE_t *tifile;
	bool ready = false;
	wxWindow *win = FindWindowById(wxID_FORWARD, GetParent());
	wxMessageDialog *dial;
	wxString path = m_filePicker1->GetPath();
	
	if (!path.IsEmpty()) {
		tifile = newimportvar(path.c_str(), TRUE);
		if (tifile == NULL || !((tifile->type == ROM_TYPE) || (tifile->type == SAV_TYPE))) {
			if (error) {
				dial = new wxMessageDialog(NULL, wxT("Invalid ROM image specified! Please select a valid ROM image, and try again."),
					wxT("Error loading ROM image"),
					wxOK | wxICON_ERROR);
				dial->ShowModal();
			}
			ready = false;
		} else {
			ready = true;
		}
		FreeTiFile(tifile);
	} else {
		ready = false;
	}
	
	win->Enable(ready);
	return ready;
}
示例#2
0
TIFILE_t* newimportvar(LPCTSTR filePath, BOOL only_check_header) {
	FILE *infile = NULL;
	TIFILE_t *tifile;
	
	TCHAR extension[5] = "";
	const TCHAR *pext = strrchr(filePath, '.');
	if (pext != NULL)
	{
#ifdef _WINDOWS
		StringCbCopy(extension, sizeof(extension), pext);
#else
		strcpy(extension, pext);
#endif
	}

	tifile = InitTiFile();
	if (tifile == NULL)
		return NULL;

	if (!_tcsicmp(extension, _T(".lab"))) {
		tifile->type = LABEL_TYPE;
		return tifile;
	}

	if (!_tcsicmp(extension, _T(".brk"))) {
		tifile->type = BREAKPOINT_TYPE;
		return tifile;
	}

#ifdef _WINDOWS
	if (!_tcsicmp(extension, _T(".tig")) || !_tcsicmp(extension, _T(".zip")) ) {
		tifile->type = ZIP_TYPE;
		if (!only_check_header)
			ImportZipFile(filePath, tifile);
		return tifile;
	}
#endif
#ifdef WINVER
	_tfopen_s(&infile, filePath, _T("rb"));
#else
	infile = fopen(filePath, "rb");
#endif
	if (infile == NULL) 
		return FreeTiFile(tifile);

	ReadTiFileHeader(infile, tifile);
	//the last part is to make sure we don't allow files that cant be imported but
	//assumed to be ROMs until we try to read data. Why? because we don't read the
	//size of the data till we import. Since importing a ROM is fast and I don't
	//care enough to fix and this was meant for speed checking files on drop its fine
	if (only_check_header && tifile->type != ROM_TYPE) {
		fclose(infile);
		return tifile;
	}

	tifile = ImportVarData(infile, tifile, 0);
	fclose(infile);
	return tifile;
}
示例#3
0
TIFILE_t* ImportROMFile(FILE *infile, TIFILE_t *tifile) {
	size_t size;
	int calc, i, tmp;

	fseek(infile, 0, SEEK_END);
	size = ftell(infile);
	fseek(infile, 0, SEEK_SET);

	if (size == 32 * 1024) calc = TI_81;
	else if (size == 128 * 1024) calc = TI_82;
	else if (size == 256 * 1024) calc = TI_83;
	else if ((size >= 510 * 1024) && (size <= (590 * 1024))) calc = TI_83P;
	else if ((size >= 1016 * 1024) && (size <= (1030 * 1024))) calc = TI_84P;
	else if ((size >= 2044 * 1024) && (size <= (2260 * 1024))) calc = TI_83PSE;
	else {
		puts("not a known rom");
		return FreeTiFile(tifile);
	}

	tifile->rom = (ROM_t *) malloc(sizeof(ROM_t));
	if (tifile->rom == NULL) {
		return FreeTiFile(tifile);
	}

	tifile->rom->data = (unsigned char *) malloc(size);
	if (tifile->rom->data == NULL)
		return FreeTiFile(tifile);

	for(i = 0; i < size && !feof(infile); i++) {
		tmp = fgetc(infile);
		if (tmp == EOF)
			return FreeTiFile(tifile);
		tifile->rom->data[i] = tmp;
	}
	tifile->rom->size		= (int)size;
	calc = FindRomVersion(calc, tifile->rom->version, tifile->rom->data, (int)size);
	tifile->model			= calc;

	return tifile;
}
示例#4
0
TIFILE_t* ImportVarData(FILE *infile, TIFILE_t *tifile, int varNumber) {
	switch (tifile->type) {
		case ROM_TYPE:
			return ImportROMFile(infile, tifile);
		case FLASH_TYPE:
			return ImportFlashFile(infile, tifile);
		case SAV_TYPE:
			tifile->save = ReadSave(infile);
			if (!tifile->save)
				return FreeTiFile(tifile);
			tifile->model = tifile->save->model;
			return tifile;
	}

	int i, tmp;
	unsigned short headersize;
	unsigned short length;
	unsigned char vartype, *ptr;

	if (varNumber == 0) {
		tmpread(infile);
		length2 = tmp;
		tmpread(infile);
		length2 += tmp << 8;
	}

	tmpread(infile);
	headersize = tmp;
	tmpread(infile);
	headersize += tmp << 8;

	tmpread(infile);
	length = tmp;
	tmpread(infile);
	length += tmp << 8;

	tmpread(infile);
	vartype = tmp;

	if ((tifile->model == TI_73 && vartype == 0x13) ||
		(tifile->model == TI_82 && vartype == 0x0F) ||
		(tifile->model == TI_85 && vartype == 0x1D)) {
		tifile->backup = (TIBACKUP_t *) malloc(sizeof(TIBACKUP_t));
		if (tifile->backup == NULL)
			return FreeTiFile(tifile);
		tifile->backup->headersize	= headersize;
		tifile->backup->length1		= length;
		tifile->backup->vartype		= vartype;
		return ImportBackup(infile, tifile);
	}

	if (length2 > length + 17 || tifile->type == GROUP_TYPE) {
		tifile->type = GROUP_TYPE;
		length2 -= 0x39;
	} else {
		tifile->type = VAR_TYPE;
	}

	tifile->var = (TIVAR_t *) malloc(sizeof(TIVAR_t));
	tifile->vars[varNumber] = tifile->var;
	if (tifile->var == NULL)
		return FreeTiFile(tifile);

	tifile->var->headersize		= headersize;
	tifile->var->length			= length;
	tifile->var->vartype		= vartype;
	ptr = tifile->var->name;
	for(i = 0; i < 8 && !feof(infile); i++) {
		tmpread(infile);
		ptr[i] = tmp;
	}

	if (tifile->model == TI_83P) {
		tmp = fgetc(infile);
		if (tmp == EOF) {
			fclose(infile);
			FreeTiFile(tifile);
			return NULL;
		}
		ptr[i++] = tmp;
		tmp = fgetc(infile);
		if (tmp == EOF)
			return FreeTiFile(tifile);
		ptr[i++] =tmp;
	} else {
		ptr[i++] = 0;
		ptr[i++] = 0;
	}
	tmp = fgetc(infile);
	if (tmp == EOF)
		return FreeTiFile(tifile);
	ptr[i++] = tmp;
	tmp = fgetc(infile);
	if (tmp == EOF)
		return FreeTiFile(tifile);
	ptr[i++] = tmp;

	tifile->var->data = (unsigned char *) malloc(tifile->var->length);
	if (tifile->var->data == NULL)
		return FreeTiFile(tifile);

	i = 0;
	if (tifile->model == TI_86)
		fgetc(infile);

	for(i = 0; i < tifile->var->length && !feof(infile); i++) {
		tmp = fgetc(infile);
		if (tmp == EOF)
			return FreeTiFile(tifile);
		tifile->var->data[i] = tmp;
	}

	if (tifile->type == GROUP_TYPE) {
		if (varNumber != 0)
			return tifile;
		while (tifile != NULL) {
			length2 -= tifile->var->length + tifile->var->headersize;
			if (length2 < 0)
				break;
			tifile = ImportVarData(infile, tifile, ++varNumber);
		}
	}

	tifile->chksum = (fgetc(infile) & 0xFF) + ((fgetc(infile) & 0xFF) << 8 );
	return tifile;
}
示例#5
0
void ReadTiFileHeader(FILE *infile, TIFILE_t *tifile) {
	char headerString[8];
	int i, tmp;

	fread(headerString, 1, 8, infile);
	rewind(infile);
	
	if (!_strnicmp(headerString, DETECT_STR, 8) ||
		!_strnicmp(headerString, DETECT_CMP_STR, 8)) {
		tifile->type = SAV_TYPE;
		return;
	}

	if (!_strnicmp(headerString, FLASH_HEADER, 8)) {
		tifile->type = FLASH_TYPE;
		tifile->flash = (TIFLASH_t*) malloc(sizeof(TIFLASH_t));
		ZeroMemory(tifile->flash, sizeof(TIFLASH_t));
		if (tifile->flash == NULL) {
			FreeTiFile(tifile);
			return;
		}

		unsigned char *ptr = (unsigned char *) tifile->flash;
		for(i = 0; i < TI_FLASH_HEADER_SIZE && !feof(infile); i++) {
			tmp = fgetc(infile);
			if (tmp == EOF) {
				_tprintf_s(_T("failed to get the whole header\n"));
				fclose(infile);
				FreeTiFile(tifile);
				return;
			}
			ptr[i] = tmp;
		}
		return;
	}

	/* It maybe a rom if it doesn't have the Standard header */
	if (_strnicmp(headerString, "**TI73**", 8) &&
		_strnicmp(headerString, "**TI82**", 8) &&
		_strnicmp(headerString, "**TI83**", 8) &&
		_strnicmp(headerString, "**TI83F*", 8) &&
		_strnicmp(headerString, "**TI85**", 8) &&
		_strnicmp(headerString, "**TI86**", 8)) {
		tifile->type = ROM_TYPE;
		return;
	}

	/* Import file Header */
	unsigned char *ptr = (unsigned char *) tifile;
	for(i = 0; i < TI_FILE_HEADER_SIZE && !feof(infile); i++) {
		tmp = fgetc(infile);
		if (tmp == EOF) {
			FreeTiFile(tifile);
			return;
		}
		ptr[i] = tmp;
	}

	if (!_strnicmp((char *) tifile->sig, "**TI73**", 8)) tifile->model = TI_73;
	else if (!_strnicmp((char *) tifile->sig, "**TI82**", 8)) tifile->model = TI_82;
	else if (!_strnicmp((char *) tifile->sig, "**TI83**", 8)) tifile->model = TI_83;
	else if (!_strnicmp((char *) tifile->sig, "**TI83F*", 8)) tifile->model = TI_83P;
	else if (!_strnicmp((char *) tifile->sig, "**TI85**", 8)) tifile->model = TI_85;
	else if (!_strnicmp((char *) tifile->sig, "**TI86**", 8)) tifile->model = TI_86;
	else {
		FreeTiFile(tifile);
		return;
	}
	return;
}
示例#6
0
TIFILE_t* ImportBackup(FILE *infile, TIFILE_t *tifile) {
	int i, tmp;
	tifile->backup->data1 = NULL;
	tifile->backup->data2 = NULL;
	tifile->backup->data3 = NULL;

	tmpread(infile);
	tifile->backup->length2 = tmp;
	tmpread(infile);
	tifile->backup->length2 += tmp << 8;

	tmpread(infile);
	tifile->backup->length3 = tmp;
	tmpread(infile);
	tifile->backup->length3 += tmp << 8;

	tmpread(infile);
	tifile->backup->address = tmp;
	tmpread(infile);
	tifile->backup->address += tmp << 8;

	tmpread(infile);
	tifile->backup->length1a = tmp;
	tmpread(infile);
	tifile->backup->length1a += tmp << 8;

	tifile->backup->data1 = (unsigned char *) malloc(tifile->backup->length1);
	if (tifile->backup->data1 == NULL)
		return FreeTiFile(tifile);
	for(i = 0; i < tifile->backup->length1 && !feof(infile); i++) {
		tmpread(infile);
		tifile->backup->data1[i] = tmp;
	}


	tmpread(infile);
	tifile->backup->length2a = tmp;
	tmpread(infile);
	tifile->backup->length2a += tmp << 8;

	tifile->backup->data2 = (unsigned char *) malloc(tifile->backup->length2);
	if (tifile->backup->data2 == NULL)
		return FreeTiFile(tifile);
	for(i = 0; i < tifile->backup->length2 && !feof(infile); i++) {
		tmpread(infile);
		tifile->backup->data2[i] =tmp;
	}

	tmpread(infile);
	tifile->backup->length3a = tmp;
	tmpread(infile);
	tifile->backup->length3a += tmp << 8;

	tifile->backup->data3 = (unsigned char *) malloc(tifile->backup->length3);
	if (tifile->backup->data3 == NULL)
		return FreeTiFile(tifile);
	for(i=0; i<tifile->backup->length3 && !feof(infile); i++) {
		tmpread(infile);
		tifile->backup->data3[i] = tmp;
	}

	tifile->chksum = (fgetc(infile) & 0xFF) + ((fgetc(infile) & 0xFF) << 8);

	tifile->type	= BACKUP_TYPE;
	return tifile;
}
示例#7
0
TIFILE_t* ImportFlashFile(FILE *infile, TIFILE_t *tifile) {
	int i;
	for(i = 0; i < 256; i++) {
		tifile->flash->pagesize[i]	= 0;
		tifile->flash->data[i]		= NULL;
	}

	INTELHEX_t record;
	int CurrentPage		= -1;
	int HighestAddress	=  0;
	int TotalSize		=  0;
	int TotalPages		=  0;
	int done			=  0;
	
	if (tifile->flash->type == FLASH_TYPE_OS) {
		// Find the first page, usually after the first line
		do {
			if (!ReadIntelHex(infile, &record)) {
				FreeTiFile(tifile);
				return NULL;
			}
		} while (record.Type != 0x02 || record.DataSize != 2);
		CurrentPage = ((record.Data[0] << 8) | record.Data[1]) & 0x7F;
		if (tifile->flash->data[CurrentPage] == 0) {
			tifile->flash->data[CurrentPage] = (unsigned char *) malloc(PAGE_SIZE);
			if (tifile->flash->data[CurrentPage] == NULL) {
				FreeTiFile(tifile);
				return NULL;
			}
			memset(tifile->flash->data[CurrentPage], 0, PAGE_SIZE);	//THIS IS IMPORTANT FOR LINKING, APPS FOR NOW
		}
		HighestAddress	=  0;
	}


	while (!feof( infile ) && !done) {
		ReadIntelHex(infile, &record);

		switch ( record.Type ) {
			case 00:
				if (CurrentPage > -1) {
					for(i = 0; (i < record.DataSize) && (((i + record.Address) & 0x3FFF) < PAGE_SIZE); i++) {
						tifile->flash->data[CurrentPage][(i + record.Address) & 0x3FFF] = record.Data[i];
					}
					if ( HighestAddress < i + record.Address ) HighestAddress = (int) (i + record.Address);
				}
				break;
			case 01:
				done = 1;
				if (CurrentPage == -1) {
					printf("invalid current page\n");
					FreeTiFile(tifile);
					return NULL;
				}
				TotalSize += (HighestAddress - PAGE_SIZE);
				tifile->flash->pagesize[CurrentPage] = (HighestAddress - PAGE_SIZE);
				tifile->flash->pages = TotalPages;
				break;
			case 02:
				if (CurrentPage > -1) {
					TotalSize += PAGE_SIZE;
					tifile->flash->pagesize[CurrentPage] = (HighestAddress - PAGE_SIZE);
				}
				TotalPages++;
				CurrentPage = ((record.Data[0] << 8) | record.Data[1]) & 0x7F;
				if (tifile->flash->data[CurrentPage] == 0) {
					tifile->flash->data[CurrentPage] = (unsigned char *) malloc(PAGE_SIZE);
					if (tifile->flash->data[CurrentPage] == NULL) {
						FreeTiFile(tifile);
						return NULL;
					}
					memset(tifile->flash->data[CurrentPage], 0, PAGE_SIZE);	//THIS IS IMPORTANT FOR LINKING, APPS FOR NOW
				}
				HighestAddress	=  0;
				break;
			default:
				printf("unknown record\n");
				FreeTiFile(tifile);
				return NULL;
		}
	}

	if (tifile->flash->device == 0x74) {
		tifile->model = TI_73;
	} else if (tifile->flash->device == 0x73) {
		tifile->model = TI_83P;
	} else {
		FreeTiFile(tifile);
		return NULL;
	}
	return tifile;
}
static LINK_ERR SendFile(const LPCALC lpCalc, LPCTSTR lpszFileName, SEND_FLAG Destination)
{
	TIFILE_t *var = importvar(lpszFileName, FALSE);

	BOOL exec_vio_backup = break_on_exe_violation;
	break_on_exe_violation = false;
	LINK_ERR result;
	if (var != NULL) {
		switch(var->type)
		{
		case GROUP_TYPE:
		case VAR_TYPE:
		case FLASH_TYPE:
			{
				if (lpCalc->cpu.pio.link == NULL) {
					result = LERR_MODEL;
					//81 for now
					break;
				}

				lpCalc->cpu.pio.link->vlink_size = var->length;
				lpCalc->cpu.pio.link->vlink_send = 0;
				BOOL running_backup = lpCalc->running;
				// if we just started running, calc_turn_on may be running
				while (lpCalc->fake_running) { }
				lpCalc->fake_running = TRUE;

				result = link_send_var(&lpCalc->cpu, var, (SEND_FLAG) Destination);
				if (var->type == FLASH_TYPE)
				{
					if (var->flash->type == FLASH_TYPE_OS) {
						calc_reset(lpCalc);
						//calc_turn_on(lpCalc);
					} else {
						// Rebuild the app list
						applist_t applist;
						state_build_applist(&lpCalc->cpu, &applist);

						u_int i;
						for (i = 0; i < applist.count; i++) {
							if (_tcsncmp((TCHAR *) var->flash->name, applist.apps[i].name, 8) == 0) {
								lpCalc->last_transferred_app = applist.apps[i];
								break;
							}
						}
					}
				}

				lpCalc->fake_running = FALSE;
				lpCalc->running = running_backup;
				break;
			}
		case BACKUP_TYPE:
			lpCalc->cpu.pio.link->vlink_size = var->length;
			lpCalc->cpu.pio.link->vlink_send = 0;
			result = link_send_backup(&lpCalc->cpu, var);
			break;
		case ZIP_TYPE: {
			WIN32_FIND_DATA FindFileData;
			HANDLE hFind;
			TCHAR path[MAX_PATH];
			TCHAR search[MAX_PATH];
			GetStorageString(path, sizeof(path));
			StringCbCat(path, sizeof(path), _T("Zip\\"));
			StringCbCopy(search, sizeof(search), path);
			StringCbCat(search, sizeof(search), _T("*"));
			hFind = FindFirstFile(search, &FindFileData);
			if (hFind == INVALID_HANDLE_VALUE) {
				result = LERR_FILE;
				break;
			} else if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
				TCHAR filename[MAX_PATH];
				StringCbCopy(filename, sizeof(filename), path);
				StringCbCat(filename, sizeof(filename), FindFileData.cFileName);
				SendFileToCalc(NULL, lpCalc, filename, FALSE, Destination);
				SendFileToCalc(NULL, lpCalc, filename, FALSE, Destination);
			}
			while (FindNextFile(hFind, &FindFileData)) {
				if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
					TCHAR filename[MAX_PATH];
					StringCbCopy(filename, sizeof(filename), path);
					StringCbCat(filename, sizeof(filename), FindFileData.cFileName);
					SendFileToCalc(NULL, lpCalc, filename, FALSE, Destination);
					DeleteFile(filename);
				}
			}
			FindClose(hFind);
			DeleteFile(path);
			result = LERR_SUCCESS;
			break;
		}
		case ROM_TYPE:
		case SAV_TYPE: {
			if (rom_load(lpCalc, lpszFileName) == TRUE) {
				result = LERR_SUCCESS;
			} else {
				result = LERR_LINK;
			}

			FreeTiFile(var);
			var = NULL;
			break;
		}
		case LABEL_TYPE: {
			VoidLabels(lpCalc);
			labels_app_load(lpCalc, lpszFileName);
			result = LERR_SUCCESS;
			break;
		}
		case BREAKPOINT_TYPE:
			break;
		}
		if (var) {
			FreeTiFile(var);
		}
		break_on_exe_violation = exec_vio_backup;
		return result;
	}
	else
	{
		break_on_exe_violation = exec_vio_backup;
		return LERR_FILE;
	}
}
示例#9
0
BOOL rom_load(LPCALC lpCalc, LPCTSTR FileName) {
	if (lpCalc == NULL) {
		return FALSE;
	}
	TIFILE_t* tifile = newimportvar(FileName, FALSE);
	if (tifile == NULL) {
		return FALSE;
	}

	lpCalc->speed = 100;
	if (lpCalc->active) {
		calc_slot_free(lpCalc);
	}
	lpCalc->model = tifile->model;

	if (tifile->type == SAV_TYPE) {
		lpCalc->active 	= TRUE;
		switch (tifile->model) {
			case TI_82:
			case TI_83: {
				int size;
				char *rom = GetRomOnly(tifile->save, &size);
				char VerString[64];
				FindRomVersion(	tifile->model, VerString, (unsigned char *) rom, size);
				calc_init_83(lpCalc, VerString);
				break;
			}
			case TI_73:
			case TI_83P:
				calc_init_83p(lpCalc);
				break;
			case TI_84PSE:
			case TI_83PSE:
				calc_init_83pse(lpCalc);
				break;
			case TI_84P:
				calc_init_84p(lpCalc);
				break;
			case TI_85:
			case TI_86:
				calc_init_86(lpCalc);
				break;
			default:
				FreeTiFile(tifile);
				return FALSE;
		}

		LoadSlot(tifile->save, lpCalc);
#ifdef WINVER
		StringCbCopy(lpCalc->rom_path, sizeof(lpCalc->rom_path), FileName);
#else
		_tcscpy_s(lpCalc->rom_path, FileName);
#endif
		FindRomVersion(tifile->model, lpCalc->rom_version, lpCalc->mem_c.flash, lpCalc->mem_c.flash_size);
	} else if (tifile->type == ROM_TYPE) {

		switch (tifile->model) {
			case TI_81:
				calc_init_81(lpCalc, tifile->rom->version);
				memcpy(	lpCalc->cpu.mem_c->flash,
						tifile->rom->data,
						(lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size);
				break;
			case TI_82:
			case TI_83:
				calc_init_83(lpCalc, tifile->rom->version);
				memcpy(	lpCalc->cpu.mem_c->flash,
						tifile->rom->data,
						(lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size);
				break;
			case TI_85:
			case TI_86:
				calc_init_86(lpCalc);
				memcpy(	lpCalc->cpu.mem_c->flash,
						tifile->rom->data,
						(lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size);
				break;
			case TI_73:
			case TI_83P:
				calc_init_83p(lpCalc);
				memcpy(	lpCalc->cpu.mem_c->flash,
						tifile->rom->data,
						(lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size);
				calc_erase_certificate(lpCalc->cpu.mem_c->flash,lpCalc->cpu.mem_c->flash_size);
				break;
			case TI_84P:
				calc_init_84p(lpCalc);
				memcpy(	lpCalc->cpu.mem_c->flash,
						tifile->rom->data,
						(lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size);
				calc_erase_certificate(lpCalc->cpu.mem_c->flash,lpCalc->cpu.mem_c->flash_size);
				break;
			case TI_84PSE:
			case TI_83PSE:
				calc_init_83pse(lpCalc);
				memcpy(	lpCalc->cpu.mem_c->flash,
						tifile->rom->data,
						(lpCalc->cpu.mem_c->flash_size<=tifile->rom->size)?lpCalc->cpu.mem_c->flash_size:tifile->rom->size);
				calc_erase_certificate(lpCalc->cpu.mem_c->flash,lpCalc->cpu.mem_c->flash_size);
				break;
			default:
				FreeTiFile(tifile);
				return FALSE;
		}

		lpCalc->active = TRUE;
		memcpy(lpCalc->rom_version, tifile->rom->version, sizeof(lpCalc->rom_version));
#ifdef WINVER
		StringCbCopy(lpCalc->rom_path, sizeof(lpCalc->rom_path), FileName);
#else
		_tcscpy_s(lpCalc->rom_path, FileName);
#endif
		

	} else {
		lpCalc = NULL;
		return FALSE;
	}
	if (lpCalc != NULL) {
		lpCalc->cpu.pio.model = lpCalc->model;
#ifdef WINVER
extern keyprog_t keygrps[256];
extern keyprog_t defaultkeys[256];
extern keyprog_t keysti86[256];
		if (lpCalc->model == TI_86 || lpCalc->model == TI_85) {
			memcpy(keygrps, keysti86, sizeof(keyprog_t) * 256);
		} else {
			memcpy(keygrps, defaultkeys, sizeof(keyprog_t) * 256);
		}
#endif
		if (lpCalc->model >= TI_73) {
			check_bootfree_and_update(lpCalc);
		}
		if (tifile->save == NULL) {
			calc_reset(lpCalc);
			if (lpCalc->auto_turn_on) {
				calc_turn_on(lpCalc);
			}
		}
	}

	FreeTiFile(tifile);
	return TRUE;
}