Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bincopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,8 @@ def as_verilog_vmem(self):
def as_binary(self,
minimum_address=None,
maximum_address=None,
padding=None):
padding=None,
fill=True):
"""Return a byte string of all data within given address range.

`minimum_address` is the absolute minimum address of the
Expand All @@ -1534,6 +1535,9 @@ def as_binary(self,
bits, and so on. By default the padding is ``b'\\xff' *
word_size_bytes``.

`fill` fill the binary up to `maximum_address`. By default
this is True.

>>> binfile.as_binary()
bytearray(b'!F\\x016\\x01!G\\x016\\x00~\\xfe\\t\\xd2\\x19\\x01!F\\x01~\\x17\\xc2\\x00\\x01
\\xff_\\x16\\x00!H\\x01\\x19\\x19Ny#F#\\x96Wx#\\x9e\\xda?\\x01\\xb2\\xca?\\x01Vp+^q+r+s!
Expand Down Expand Up @@ -1580,7 +1584,8 @@ def as_binary(self,
data = data[:size]
length = len(data) // self.word_size_bytes
elif maximum_address >= current_maximum_address:
binary += padding * (maximum_address - current_maximum_address)
if fill:
binary += padding * (maximum_address - current_maximum_address)
break

binary += padding * (address - current_maximum_address)
Expand Down