Skip to content

Commit

Permalink
Fix some flash stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kg583 committed Dec 31, 2023
1 parent ce27135 commit 1ff33e6
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tivars/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


from io import BytesIO
from typing import ByteString, BinaryIO, Type
from typing import BinaryIO, Type
from warnings import warn

from .data import *
Expand Down Expand Up @@ -105,9 +105,9 @@ def set(cls, value: _T, **kwargs) -> bytes:

class TIFlashBlock(Dock):
"""
Parser for flash blocks
Parser for Intel blocks
The data section of a flash header is composed of blocks separated by newlines.
The data section of a flash header with ``binary_flag == $00`` is composed of blocks stored in the Intel format.
Each block contains some segment of data stored at an address, which may be relative or absolute.
"""

Expand Down Expand Up @@ -219,7 +219,7 @@ def checksum(self) -> int:

return int.from_bytes(self.raw.checksum, 'little')

@Loader[ByteString, BytesIO]
@Loader[bytes, bytearray, BytesIO]
def load_bytes(self, data: bytes | BytesIO):
"""
Loads a byte string or bytestream into this block
Expand Down Expand Up @@ -366,7 +366,7 @@ def __init__(self, init=None, *,
:param init: Values to initialize the header's data (defaults to ``None``)
:param magic: File magic at the start of the header (defaults to ``**TIFL**``)
:param revision: The header's revision number (defaults to ``0.0``)
:param binary_flag: Whether the header's data is stored in Intel format (defaults to ``True``)
:param binary_flag: Whether the header's data is stored in binary format (defaults to ``True``)
:param object_type: The header's object type (defaults to ``$88``)
:param date: The header's stored date as a tuple (dd, mm, yyyy) (defaults to null)
:param name: The name of the headers (defaults to ``UNNAMED``)
Expand Down Expand Up @@ -450,7 +450,7 @@ def name_length(self) -> int:

return int.from_bytes(self.raw.name_length, 'little')

@Section(8, String)
@Section(31, String)
def name(self) -> str:
"""
The name or basecode attached to the flash header
Expand Down Expand Up @@ -603,7 +603,7 @@ def filename(self, model: TIModel = TI_84PCE) -> str:

return f"{self.name}.{self.extension(model)}"

@Loader[ByteString, BytesIO]
@Loader[bytes, bytearray, BytesIO]
def load_bytes(self, data: bytes | BytesIO):
"""
Loads a byte string or bytestream into this header
Expand Down Expand Up @@ -632,15 +632,13 @@ def load_bytes(self, data: bytes | BytesIO):

# Read name
name_length = data.read(1)[0]
self.raw.name = data.read(8)
self.raw.name = data.read(31).rstrip(b'\x00')

if name_length != self.name_length:
warn(f"The header name length ({name_length}) doesn't match the length of the name "
f"(|{self.name}| = {self.name_length}).",
BytesWarning)

data.seek(23, 1)

# Read types
self.raw.devices = data.read(1)

Expand Down

0 comments on commit 1ff33e6

Please sign in to comment.