Skip to content

Commit

Permalink
Added TI-TXT file format
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Zoppi <texzk@email.it>
  • Loading branch information
TexZK committed Feb 11, 2024
1 parent c3cd0db commit cda293e
Show file tree
Hide file tree
Showing 18 changed files with 1,534 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog

* Library rewritten from scratch (not backwards compatible).
* Added new object oriented API, hopefully more user friendly.
* Added *Texas Instruments TI-TXT* file format.
* Improved docs and examples.


0.3.1 (2024-01-23)
Expand Down
75 changes: 75 additions & 0 deletions docs/_autosummary/hexrec.formats.titxt.TiTxtFile.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
TiTxtFile
=========

.. currentmodule:: hexrec.formats.titxt

.. autoclass:: TiTxtFile
:members:
:inherited-members:
:private-members:
:special-members:




.. rubric:: Attributes

.. autosummary::

~TiTxtFile.DEFAULT_DATALEN
~TiTxtFile.FILE_EXT
~TiTxtFile.META_KEYS
~TiTxtFile.maxdatalen
~TiTxtFile.memory
~TiTxtFile.records






.. rubric:: Methods

.. autosummary::
:nosignatures:

~TiTxtFile.__init__
~TiTxtFile.append
~TiTxtFile.apply_records
~TiTxtFile.clear
~TiTxtFile.convert
~TiTxtFile.copy
~TiTxtFile.crop
~TiTxtFile.cut
~TiTxtFile.delete
~TiTxtFile.discard_memory
~TiTxtFile.discard_records
~TiTxtFile.extend
~TiTxtFile.fill
~TiTxtFile.find
~TiTxtFile.flood
~TiTxtFile.from_blocks
~TiTxtFile.from_bytes
~TiTxtFile.from_memory
~TiTxtFile.from_records
~TiTxtFile.get_address_max
~TiTxtFile.get_address_min
~TiTxtFile.get_holes
~TiTxtFile.get_meta
~TiTxtFile.get_spans
~TiTxtFile.index
~TiTxtFile.load
~TiTxtFile.merge
~TiTxtFile.parse
~TiTxtFile.print
~TiTxtFile.read
~TiTxtFile.save
~TiTxtFile.serialize
~TiTxtFile.set_meta
~TiTxtFile.shift
~TiTxtFile.split
~TiTxtFile.update_records
~TiTxtFile.validate_records
~TiTxtFile.view
~TiTxtFile.write

50 changes: 50 additions & 0 deletions docs/_autosummary/hexrec.formats.titxt.TiTxtRecord.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
TiTxtRecord
===========

.. currentmodule:: hexrec.formats.titxt

.. autoclass:: TiTxtRecord
:members:
:inherited-members:
:private-members:
:special-members:




.. rubric:: Attributes

.. autosummary::

~TiTxtRecord.EQUALITY_KEYS
~TiTxtRecord.LINE_REGEX
~TiTxtRecord.META_KEYS






.. rubric:: Methods

.. autosummary::
:nosignatures:

~TiTxtRecord.__init__
~TiTxtRecord.compute_checksum
~TiTxtRecord.compute_count
~TiTxtRecord.copy
~TiTxtRecord.create_address
~TiTxtRecord.create_data
~TiTxtRecord.create_eof
~TiTxtRecord.data_to_int
~TiTxtRecord.get_meta
~TiTxtRecord.parse
~TiTxtRecord.print
~TiTxtRecord.serialize
~TiTxtRecord.to_bytestr
~TiTxtRecord.to_tokens
~TiTxtRecord.update_checksum
~TiTxtRecord.update_count
~TiTxtRecord.validate

46 changes: 46 additions & 0 deletions docs/_autosummary/hexrec.formats.titxt.TiTxtTag.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
TiTxtTag
========

.. currentmodule:: hexrec.formats.titxt

.. autoclass:: TiTxtTag
:members:
:inherited-members:
:private-members:
:special-members:




.. rubric:: Attributes

.. autosummary::

~TiTxtTag.DATA
~TiTxtTag.ADDRESS
~TiTxtTag.EOF
~TiTxtTag.denominator
~TiTxtTag.imag
~TiTxtTag.numerator
~TiTxtTag.real






.. rubric:: Methods

.. autosummary::
:nosignatures:

~TiTxtTag.is_address
~TiTxtTag.is_eof
~TiTxtTag.__init__
~TiTxtTag.as_integer_ratio
~TiTxtTag.bit_count
~TiTxtTag.bit_length
~TiTxtTag.conjugate
~TiTxtTag.from_bytes
~TiTxtTag.to_bytes

40 changes: 40 additions & 0 deletions docs/_autosummary/hexrec.formats.titxt.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
titxt
=====

.. automodule:: hexrec.formats.titxt














.. rubric:: Classes

.. autosummary::
:toctree:
:template: custom-class-template.rst
:nosignatures:

TiTxtFile
TiTxtRecord
TiTxtTag












1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Contents
authors
changelog


Indices and tables
==================

Expand Down
1 change: 1 addition & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Reference
hexrec.formats.mos
hexrec.formats.raw
hexrec.formats.srec
hexrec.formats.titxt
hexrec.formats.xtek
hexrec.utils
hexrec.xxd
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sphinx >= 7
sphinx-click
sphinx-autodoc-typehints

bytesparse
bytesparse >= 0.0.8
colorama
furo
twine
Expand Down
3 changes: 2 additions & 1 deletion src/hexrec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
from .formats.mos import MosFile
from .formats.raw import RawFile
from .formats.srec import SrecFile
from .formats.titxt import TiTxtFile
from .formats.xtek import XtekFile
from .xxd import xxd


def _register_default_file_types():
# TODO: __doc__

defaults = {
# The most common formats come first
Expand All @@ -50,6 +50,7 @@ def _register_default_file_types():

# Least common
'asciihex': AsciiHexFile,
'titxt': TiTxtFile,
'xtek': XtekFile,
'mos': MosFile,

Expand Down
6 changes: 4 additions & 2 deletions src/hexrec/formats/asciihex.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def to_bytestr(

if self.tag == AsciiHexTag.ADDRESS:
count = self.count or 1
valstr = (b'$A%%0%dX%s' % (count, dollarend)) % (self.address & 0xFFFFFFFF)
mask = (1 << (4 * count)) - 1
valstr = (b'$A%%0%dX%s' % (count, dollarend)) % (self.address & mask)

elif self.tag == AsciiHexTag.CHECKSUM:
valstr = b'$S%04X%s' % ((self.checksum & 0xFFFF), dollarend)
Expand Down Expand Up @@ -397,7 +398,8 @@ def to_tokens(

if tag == tag.ADDRESS:
count = self.count or 1
addrstr = (b'$A%%0%dX%s' % (count, dollarend)) % (self.address & 0xFFFFFFFF)
mask = (1 << (4 * count)) - 1
addrstr = (b'$A%%0%dX%s' % (count, dollarend)) % (self.address & mask)

elif tag == tag.CHECKSUM:
chksstr = b'$S%04X%s' % ((self.checksum & 0xFFFF), dollarend)
Expand Down
7 changes: 1 addition & 6 deletions src/hexrec/formats/ihex.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def is_extension(self) -> bool:

def is_file_termination(self) -> bool:

return super().is_file_termination()
return self.is_eof()

def is_start(self) -> bool:
r"""Tells whether this is a Start Address record tag.
Expand All @@ -153,10 +153,6 @@ def is_start(self) -> bool:
return ((self == self.START_SEGMENT_ADDRESS) or
(self == self.START_LINEAR_ADDRESS))

def is_file_termination(self) -> bool:

return self.is_eof()


if not __TYPING_HAS_SELF: # pragma: no cover
del Self
Expand Down Expand Up @@ -774,7 +770,6 @@ def validate_records(
extension = 0

for index, record in enumerate(records):
record = _cast(IhexRecord, record)
record.validate()
tag = _cast(IhexTag, record.tag)

Expand Down
1 change: 0 additions & 1 deletion src/hexrec/formats/mos.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ def validate_records(
last_data_endex = 0

for index, record in enumerate(records):
record = _cast(MosRecord, record)
record.validate()
tag = _cast(MosTag, record.tag)

Expand Down
7 changes: 1 addition & 6 deletions src/hexrec/formats/srec.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def is_data(self) -> bool:

def is_file_termination(self) -> bool:

return super().is_file_termination()
return self.is_start()

def is_header(self) -> bool:
r"""Tells whether this is a header record tag.
Expand Down Expand Up @@ -415,10 +415,6 @@ def is_start(self) -> bool:
(self == self.START_24) or
(self == self.START_32))

def is_file_termination(self) -> bool:

return self.is_start()


SIZE_TO_ADDRESS_FORMAT: Mapping[int, bytes] = {
2: b'%04X',
Expand Down Expand Up @@ -1117,7 +1113,6 @@ def validate_records(
data_count = 0

for index, record in enumerate(records):
record = _cast(SrecRecord, record)
record.validate()
tag = _cast(SrecTag, record.tag)

Expand Down
Loading

0 comments on commit cda293e

Please sign in to comment.