This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added version/compatibility level info
- Loading branch information
Showing
4 changed files
with
266 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
/* | ||
* Part of tivars_lib | ||
* (C) 2015 Adrien 'Adriweb' Bertrand | ||
* https://github.com/adriweb/TIs_lib | ||
* License: MIT | ||
*/ | ||
|
||
namespace tivars; | ||
|
||
class TIVersion | ||
{ | ||
private $name = 'Unknown'; | ||
private $level = 99; | ||
private $sig = ''; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getLevel() | ||
{ | ||
return $this->level; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSig() | ||
{ | ||
return $this->sig; | ||
} | ||
|
||
|
||
/*** "Constructors" ***/ | ||
|
||
/** | ||
* @param int $level The version compatibliity level | ||
* @return TIVersion | ||
* @throws \Exception | ||
*/ | ||
public static function createFromLevel($level = -1) | ||
{ | ||
if (TIVersions::isValidLevel($level)) | ||
{ | ||
$instance = new self(); | ||
$instance->level = $level; | ||
$instance->sig = TIVersions::getSignatureFromLevel($level); | ||
$instance->name = TIVersions::getNameFromLevel($level); | ||
return $instance; | ||
} else { | ||
throw new \Exception("Invalid version ID"); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $name The version name | ||
* @return TIVersion | ||
* @throws \Exception | ||
*/ | ||
public static function createFromName($name = '') | ||
{ | ||
if (TIVersions::isValidName($name)) | ||
{ | ||
$instance = new self(); | ||
$instance->name = $name; | ||
$instance->level = TIVersions::getLevelFromName($name); | ||
$instance->sig = TIVersions::getSignatureFromName($name); | ||
return $instance; | ||
} else { | ||
throw new \Exception("Invalid version name"); | ||
} | ||
} | ||
|
||
/** | ||
* @param int $level The version compatibliity level | ||
* @return TIVersion | ||
* @throws \Exception | ||
*/ | ||
public static function createFromSignature($sig = '') | ||
{ | ||
if (TIVersions::isValidSignature($sig)) | ||
{ | ||
$instance = new self(); | ||
$instance->sig = $sig; | ||
$instance->level = TIVersions::getMinLevelFromSignature($sig); | ||
$instance->name = TIVersions::getDefaultNameFromSignature($sig); | ||
return $instance; | ||
} else { | ||
throw new \Exception("Invalid version signature"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
<?php | ||
/* | ||
* Part of tivars_lib | ||
* (C) 2015 Adrien 'Adriweb' Bertrand | ||
* https://github.com/adriweb/tivars_lib | ||
* License: MIT | ||
*/ | ||
|
||
namespace tivars; | ||
|
||
abstract class TIVersions | ||
{ | ||
const hasVersionField = 2; | ||
const hasFlash = 2; | ||
const hasColor = 4; | ||
|
||
private static $versions = []; | ||
|
||
/** | ||
* Make and insert the associative arrays for the version. | ||
* | ||
* @param int $level The [compatibility] level of this version | ||
* @param string $name The name of the calc using this version | ||
* @param string $sig The signature (magic bytes) used for this version | ||
*/ | ||
private static function insertVersion($level, $name, $sig) | ||
{ | ||
if (!isset(self::$versions[$name])) | ||
self::$versions[$name] = [ 'level' => $level, 'sig' => $sig ]; | ||
|
||
if (!isset(self::$versions[$level])) | ||
self::$versions[$level] = [ 'name' => $name, 'sig' => $sig ]; | ||
|
||
if (!isset(self::$versions[$sig])) | ||
self::$versions[$sig] = [ 'level' => $level, 'name' => $name ]; | ||
} | ||
|
||
// TODO : Research actual compatibility level/"versions" from libtifiles, and maybe even TI ? | ||
public static function initTIVersionsArray() | ||
{ | ||
self::insertVersion(99, 'Unknown', ''); | ||
|
||
self::insertVersion(0, '82', '**TI82**'); | ||
self::insertVersion(1, '83', '**TI83**'); | ||
self::insertVersion(2, '83+', '**TI83F*'); | ||
self::insertVersion(2, '82+', '**TI83F*'); | ||
self::insertVersion(3, '84+', '**TI83F*'); | ||
self::insertVersion(3, '82A', '**TI83F*'); | ||
self::insertVersion(4, '84+CSE', '**TI83F*'); | ||
self::insertVersion(5, '84+CE', '**TI83F*'); | ||
self::insertVersion(6, '83PCE', '**TI83F*'); | ||
} | ||
|
||
/** | ||
* @param int $level The version level | ||
* @return string The version name for that Level | ||
*/ | ||
public static function getNameFromLevel($level = 99) | ||
{ | ||
if ($level !== 99 && isset(self::$versions[$level])) | ||
{ | ||
return self::$versions[$level]['name']; | ||
} else { | ||
return 'Unknown'; | ||
} | ||
} | ||
|
||
/** | ||
* @param string $name The version name | ||
* @return int The version level for that name | ||
*/ | ||
public static function getLevelFromName($name = '') | ||
{ | ||
if ($name !== '' && isset(self::$versions[$name])) | ||
{ | ||
return self::$versions[$name]['level']; | ||
} else { | ||
return 99; | ||
} | ||
} | ||
|
||
/** | ||
* @param int $level The version level | ||
* @return string The signature for that Level | ||
*/ | ||
public static function getSignatureFromLevel($level = 99) | ||
{ | ||
if ($level !== 99 && isset(self::$versions[$level])) | ||
{ | ||
return self::$versions[$level]['sig']; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @return string The signature for that name | ||
*/ | ||
public static function getSignatureFromName($name = '') | ||
{ | ||
if ($name !== '' && isset(self::$versions[$name])) | ||
{ | ||
return self::$versions[$name]['sig']; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
|
||
/** | ||
* @param string $sig | ||
* @return string The default calc name whose file formats use that signature | ||
*/ | ||
public static function getDefaultNameFromSignature($sig = '') | ||
{ | ||
if ($sig !== '' && isset(self::$versions[$sig])) | ||
{ | ||
return self::$versions[$sig]['name']; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
|
||
/** | ||
* @param string $sig The signature | ||
* @return string The minimum compatibility level for that signaure | ||
*/ | ||
public static function getMinLevelFromSignature($sig = '') | ||
{ | ||
if ($sig !== '' && isset(self::$versions[$sig])) | ||
{ | ||
return self::$versions[$sig]['level']; | ||
} else { | ||
return 99; | ||
} | ||
} | ||
|
||
public static function isValidLevel($level = 99) | ||
{ | ||
return ($level >= 0 && is_int($level) && isset(self::$versions[$level])); | ||
} | ||
|
||
public static function isValidName($name = '') | ||
{ | ||
return ($name !== '' && isset(self::$versions[$name])); | ||
} | ||
|
||
public static function isValidSignature($sig = '') | ||
{ | ||
return ($sig !== '' && isset(self::$versions[$sig])); | ||
} | ||
} | ||
|
||
TIVersions::initTIVersionsArray(); |