diff --git a/tivars/types/complex.py b/tivars/types/complex.py index ff6f9f5..037e215 100644 --- a/tivars/types/complex.py +++ b/tivars/types/complex.py @@ -133,10 +133,10 @@ def __complex__(self): def __format__(self, format_spec: str) -> str: def make_imag(entry: 'RealEntry') -> str: match entry.type_id: - case 0x18 | 0x21: + case TIRealFraction.type_id | TIRealPiFraction.type_id: return format(entry, format_spec).replace("/", "i/") - case 0x1C: + case TIRealRadical.type_id: return f"{entry:{format_spec}} * i" case _: @@ -247,8 +247,8 @@ def imag_type(self) -> type['RealEntry']: def clear(self): super().clear() - self.real_subtype_id = 0x0C - self.imag_subtype_id = self._type_id if self._type_id is not None else 0x0C + self.real_subtype_id = TIComplex.type_id + self.imag_subtype_id = self._type_id if self._type_id is not None else TIComplex.type_id def components(self) -> (RealEntry, RealEntry): """ @@ -258,13 +258,11 @@ def components(self) -> (RealEntry, RealEntry): return self.real, self.imag def get_min_os(self, data: bytes = None) -> OsVersion: - data = data or self.data - - match max(data[0], data[9]): - case 0x0C: + match self.get_version(data): + case 0x00: return TI_83.OS() - case 0x1B: + case 0x0B: return TI_84P.OS("2.55") case _: @@ -274,10 +272,10 @@ def get_version(self, data: bytes = None) -> int: data = data or self.data match max(data[0], data[9]): - case 0x0C: + case TIComplex.type_id: return 0x00 - case 0x1B: + case TIComplexFraction.type_id: return 0x0B case _: @@ -326,7 +324,8 @@ def load_string(self, string: str): self.real = self.real_type(parts[0]) except (TypeError, ValueError): - for type_id in [0x00, 0x18, 0x1C, 0x20, 0x21]: + for type_id in [TIReal.type_id, TIRealFraction.type_id, TIRealRadical.type_id, + TIRealPi.type_id, TIRealPiFraction.type_id]: if type_id == self.real_subtype_id: continue diff --git a/tivars/types/group.py b/tivars/types/group.py index 467873c..e5e777d 100644 --- a/tivars/types/group.py +++ b/tivars/types/group.py @@ -10,7 +10,10 @@ from tivars.data import * from tivars.models import * from tivars.var import TIEntry, SizedEntry +from .appvar import * from .gdb import TIGraphedEquation +from .list import * +from .tokenized import * class TIGroup(SizedEntry, register=True): @@ -75,10 +78,10 @@ def group(entries: Sequence[TIEntry], *, name: str = "GROUP") -> 'TIGroup': vat[0] |= entry.raw.flags match entry.type_id: - case 0x05 | 0x06 | 0x15 | 0x17: + case TIProgram.type_id | TIProtectedProgram.type_id | TIAppVar.type_id | TIGroup.type_id: vat += bytearray([len(name), *name]) - case 0x01 | 0x0D: + case TIRealList.type_id | TIComplexList.type_id: vat += bytearray([len(name) + 1, *name, 0]) case _: @@ -113,7 +116,7 @@ def ungroup(self, data: bytes = None) -> list[TIEntry]: _, version = data.read(2) match type_id := type_byte[0] & 63: - case 0x05 | 0x06 | 0x15 | 0x17: + case TIProgram.type_id | TIProtectedProgram.type_id | TIAppVar.type_id | TIGroup.type_id: *_, page, length = data.read(4) if length > 8: @@ -122,7 +125,7 @@ def ungroup(self, data: bytes = None) -> list[TIEntry]: name = data.read(length) - case 0x01 | 0x0D: + case TIRealList.type_id | TIComplexList.type_id: *_, page, length = data.read(4) if length > 7: diff --git a/tivars/types/tokenized.py b/tivars/types/tokenized.py index 34cbcc5..517633d 100644 --- a/tivars/types/tokenized.py +++ b/tivars/types/tokenized.py @@ -303,7 +303,7 @@ def protect(self): Cast this program to a protected program """ - self.type_id = 0x06 + self.type_id = TIProtectedProgram.type_id self.coerce() def unprotect(self): @@ -311,7 +311,7 @@ def unprotect(self): Cast this program to an unprotected program """ - self.type_id = 0x05 + self.type_id = TIProgram.type_id self.coerce() @Loader[bytes, bytearray, BytesIO] @@ -359,13 +359,13 @@ def coerce(self): doors &= b"\xEF\x68" in self.data and self.data.index(b"\xEF\x68") > 0 match self.type_id, any(token in self.data for token in self.asm_tokens) | doors: - case 0x05, False: + case TIProgram.type_id, False: self.__class__ = TIProgram - case 0x05, True: + case TIProgram.type_id, True: self.__class__ = TIAsmProgram - case 0x06, False: + case TIProtectedProgram.type_id, False: self.__class__ = TIProtectedProgram - case 0x06, True: + case TIProtectedProgram.type_id, True: self.__class__ = TIProtectedAsmProgram