mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2025-01-16 02:32:52 +00:00
Changed start_addr to origin
This commit is contained in:
parent
caee2554f8
commit
ab05cb1ae1
@ -231,12 +231,12 @@ def assemble_segments(source_files, data_files, obj_files, run_addr=""):
|
||||
parser = find_diskimage(name)
|
||||
if parser and parser.image:
|
||||
for s in parser.segments:
|
||||
if s.start_addr > 0:
|
||||
if s.origin > 0:
|
||||
print("adding %s from %s" % (s, name))
|
||||
segments.add_segment(s.data, s.start_addr)
|
||||
segments.add_segment(s.data, s.origin)
|
||||
if options.verbose:
|
||||
for s in segments:
|
||||
print("%s - %04x)" % (str(s)[:-1], s.start_addr + len(s)))
|
||||
print("%s - %04x)" % (str(s)[:-1], s.origin + len(s)))
|
||||
if run_addr:
|
||||
try:
|
||||
run_addr = text_to_int(run_addr)
|
||||
|
@ -759,20 +759,20 @@ def get_xex(segments, run_addr=None):
|
||||
runad = False
|
||||
for s in segments:
|
||||
total += 4 + len(s)
|
||||
if s.start_addr == 0x2e0:
|
||||
if s.origin == 0x2e0:
|
||||
runad = True
|
||||
if not runad:
|
||||
words = np.empty([1], dtype='<u2')
|
||||
if run_addr:
|
||||
found = False
|
||||
for s in segments:
|
||||
if run_addr >= s.start_addr and run_addr < s.start_addr + len(s):
|
||||
if run_addr >= s.origin and run_addr < s.origin + len(s):
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
raise InvalidBinaryFile("Run address points outside data segments")
|
||||
else:
|
||||
run_addr = segments[0].start_addr
|
||||
run_addr = segments[0].origin
|
||||
words[0] = run_addr
|
||||
r = SegmentData(words.view(dtype=np.uint8))
|
||||
s = DefaultSegment(r, 0x2e0)
|
||||
@ -787,10 +787,10 @@ def get_xex(segments, run_addr=None):
|
||||
for s in segments_copy:
|
||||
# create new sub-segment inside new main segment that duplicates the
|
||||
# original segment's data/style
|
||||
new_s = DefaultSegment(rawdata[i:i+4+len(s)], s.start_addr)
|
||||
new_s = DefaultSegment(rawdata[i:i+4+len(s)], s.origin)
|
||||
words = new_s.data[0:4].view(dtype='<u2')
|
||||
words[0] = s.start_addr
|
||||
words[1] = s.start_addr + len(s) - 1
|
||||
words[0] = s.origin
|
||||
words[1] = s.origin + len(s) - 1
|
||||
new_s.style[0:4] = data_style
|
||||
new_s.data[4:4+len(s)] = s[:]
|
||||
new_s.style[4:4+len(s)] = s.style[:]
|
||||
|
@ -589,7 +589,7 @@ class Dos33DiskImage(DiskImageBase):
|
||||
addr = dirent.get_binary_start_address(self) - 4 # factor in 4 byte header
|
||||
else:
|
||||
addr = 0
|
||||
segment = ObjSegment(raw, 0, 0, start_addr=addr, name=name, verbose_name=verbose_name)
|
||||
segment = ObjSegment(raw, 0, 0, origin=addr, name=name, verbose_name=verbose_name)
|
||||
if addr > 0:
|
||||
style = segment.get_style_bits(data=True)
|
||||
segment.style[0:4] = style
|
||||
@ -605,14 +605,14 @@ class Dos33DiskImage(DiskImageBase):
|
||||
last = -1
|
||||
|
||||
for s in segments:
|
||||
origin = min(origin, s.start_addr)
|
||||
last = max(last, s.start_addr + len(s))
|
||||
origin = min(origin, s.origin)
|
||||
last = max(last, s.origin + len(s))
|
||||
if _xd: log.debug("contiguous bytes needed: %04x - %04x" % (origin, last))
|
||||
if run_addr and run_addr != origin:
|
||||
# check if run_addr points to some location that has data
|
||||
found = False
|
||||
for s in segments:
|
||||
if run_addr >= s.start_addr and run_addr < s.start_addr + len(s):
|
||||
if run_addr >= s.origin and run_addr < s.origin + len(s):
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
@ -620,7 +620,7 @@ class Dos33DiskImage(DiskImageBase):
|
||||
origin -= 3
|
||||
hi, lo = divmod(run_addr, 256)
|
||||
raw = SegmentData([0x4c, lo, hi])
|
||||
all_segments = [DefaultSegment(raw, start_addr=origin)]
|
||||
all_segments = [DefaultSegment(raw, origin=origin)]
|
||||
all_segments.extend(segments)
|
||||
else:
|
||||
all_segments = segments
|
||||
@ -630,8 +630,8 @@ class Dos33DiskImage(DiskImageBase):
|
||||
words[0] = origin
|
||||
words[1] = size
|
||||
for s in all_segments:
|
||||
index = s.start_addr - origin + 4
|
||||
print("setting data for $%04x - $%04x at index $%04x" % (s.start_addr, s.start_addr + len(s), index))
|
||||
index = s.origin - origin + 4
|
||||
print("setting data for $%04x - $%04x at index $%04x" % (s.origin, s.origin + len(s), index))
|
||||
image[index:index + len(s)] = s.data
|
||||
return image, 'B'
|
||||
|
||||
|
@ -82,7 +82,7 @@ class BSAVESaver(object):
|
||||
def encode_data(cls, segment, ui_control):
|
||||
data = segment.tobytes()
|
||||
header = np.empty(2, dtype="<u2")
|
||||
header[0] = segment.start_addr
|
||||
header[0] = segment.origin
|
||||
header[1] = len(data)
|
||||
print("binary data: %x bytes at %x" % (header[1], header[0]))
|
||||
return header.tobytes() + segment.tobytes()
|
||||
@ -102,6 +102,9 @@ class OrderWrapper(object):
|
||||
self.base = data.base # base array for numpy bounds determination
|
||||
self.order = byte_order
|
||||
|
||||
def __str__(self):
|
||||
return f"OrderWrapper at {hex(id(self))} count={len(self)} order={self.order} base: count={len(self.np_data)}"
|
||||
|
||||
def __len__(self):
|
||||
return np.alen(self.order)
|
||||
|
||||
@ -397,11 +400,11 @@ class DefaultSegment(object):
|
||||
savers = [SegmentSaver, BSAVESaver]
|
||||
can_resize_default = False
|
||||
|
||||
base_serializable_attributes = ['start_addr', 'error', 'name', 'verbose_name', 'page_size', 'map_width', 'uuid', 'can_resize']
|
||||
base_serializable_attributes = ['origin', 'error', 'name', 'verbose_name', 'page_size', 'map_width', 'uuid', 'can_resize']
|
||||
extra_serializable_attributes = []
|
||||
|
||||
def __init__(self, rawdata, start_addr=0, name="All", error=None, verbose_name=None, memory_map=None):
|
||||
self.start_addr = int(start_addr) # force python int to decouple from possibly being a numpy datatype
|
||||
def __init__(self, rawdata, origin=0, name="All", error=None, verbose_name=None, memory_map=None):
|
||||
self.origin = int(origin) # force python int to decouple from possibly being a numpy datatype
|
||||
self.set_raw(rawdata)
|
||||
self.error = error
|
||||
self.name = name
|
||||
@ -418,6 +421,8 @@ class DefaultSegment(object):
|
||||
self.can_resize = self.__class__.can_resize_default
|
||||
|
||||
def set_raw(self, rawdata):
|
||||
if type(rawdata) != SegmentData:
|
||||
log.warning(f"data not in SegmentData format {rawdata}, {type(rawdata)}")
|
||||
self.rawdata = rawdata
|
||||
self.update_raw_pointers()
|
||||
|
||||
@ -588,8 +593,8 @@ class DefaultSegment(object):
|
||||
self.set_style_ranges(e[slot], user=i)
|
||||
|
||||
def __str__(self):
|
||||
if self.start_addr > 0:
|
||||
origin = " @ %04x" % (self.start_addr)
|
||||
if self.origin > 0:
|
||||
origin = " @ %04x" % (self.origin)
|
||||
else:
|
||||
origin = ""
|
||||
s = "%s ($%x bytes%s)" % (self.name, len(self), origin)
|
||||
@ -637,7 +642,7 @@ class DefaultSegment(object):
|
||||
"""Get index into base array's raw data, given the address of a byte
|
||||
into this segment
|
||||
"""
|
||||
return self.get_raw_index(addr - self.start_addr)
|
||||
return self.get_raw_index(addr - self.origin)
|
||||
|
||||
def get_index_from_base_index(self, base_index):
|
||||
"""Get index into this array's data given the index into the base array
|
||||
@ -1042,7 +1047,7 @@ class DefaultSegment(object):
|
||||
return sorted([[k, v] for k, v in self.rawdata.extra.comments.items()])
|
||||
|
||||
def iter_comments_in_segment(self):
|
||||
start = self.start_addr
|
||||
start = self.origin
|
||||
start_index = self.get_raw_index(0)
|
||||
end_index = self.get_raw_index(len(self.rawdata))
|
||||
for k, v in self.rawdata.extra.comments.items():
|
||||
@ -1060,9 +1065,9 @@ class DefaultSegment(object):
|
||||
|
||||
def label(self, index, lower_case=True):
|
||||
if lower_case:
|
||||
return "%04x" % (index + self.start_addr)
|
||||
return "%04x" % (index + self.origin)
|
||||
else:
|
||||
return "%04X" % (index + self.start_addr)
|
||||
return "%04X" % (index + self.origin)
|
||||
|
||||
@property
|
||||
def search_copy(self):
|
||||
@ -1102,14 +1107,14 @@ class EmptySegment(DefaultSegment):
|
||||
class ObjSegment(DefaultSegment):
|
||||
extra_serializable_attributes = ['metadata_start', 'data_start']
|
||||
|
||||
def __init__(self, rawdata, metadata_start, data_start, start_addr, end_addr=0, name="", **kwargs):
|
||||
DefaultSegment.__init__(self, rawdata, start_addr, name, **kwargs)
|
||||
def __init__(self, rawdata, metadata_start, data_start, origin, end_addr=0, name="", **kwargs):
|
||||
DefaultSegment.__init__(self, rawdata, origin, name, **kwargs)
|
||||
self.metadata_start = int(metadata_start)
|
||||
self.data_start = int(data_start)
|
||||
|
||||
def __str__(self):
|
||||
count = len(self)
|
||||
s = "%s $%04x-$%04x ($%04x @ $%04x)" % (self.name, self.start_addr, self.start_addr + count, count, self.data_start)
|
||||
s = "%s $%04x-$%04x ($%04x @ $%04x)" % (self.name, self.origin, self.origin + count, count, self.data_start)
|
||||
if self.error:
|
||||
s += " " + self.error
|
||||
return s
|
||||
@ -1118,7 +1123,7 @@ class ObjSegment(DefaultSegment):
|
||||
def verbose_info(self):
|
||||
count = len(self)
|
||||
name = self.verbose_name or self.name
|
||||
s = "%s address range: $%04x-$%04x ($%04x bytes), file index of first byte: $%04x" % (name, self.start_addr, self.start_addr + count, count, self.data_start)
|
||||
s = "%s address range: $%04x-$%04x ($%04x bytes), file index of first byte: $%04x" % (name, self.origin, self.origin + count, count, self.data_start)
|
||||
if self.error:
|
||||
s += " error='%s'" % self.error
|
||||
return s
|
||||
@ -1225,11 +1230,11 @@ def interleave_segments(segments, num_bytes):
|
||||
|
||||
|
||||
class SegmentList(list):
|
||||
def add_segment(self, data, start_addr=0, name=None):
|
||||
last = start_addr + len(data)
|
||||
def add_segment(self, data, origin=0, name=None):
|
||||
last = origin + len(data)
|
||||
if name is None:
|
||||
name = "%04x - %04x, size=%04x" % (start_addr, last, len(data))
|
||||
name = "%04x - %04x, size=%04x" % (origin, last, len(data))
|
||||
rawdata = SegmentData(data)
|
||||
s = DefaultSegment(rawdata, start_addr, name)
|
||||
s = DefaultSegment(rawdata, origin, name)
|
||||
self.append(s)
|
||||
return s
|
||||
|
@ -69,14 +69,14 @@ class StandardDeliveryImage(DiskImageBase):
|
||||
raw = SegmentData(np.zeros([143360], dtype=np.uint8))
|
||||
dsk = cls(raw, create=True)
|
||||
if run_addr is None:
|
||||
run_addr = segments[0].start_addr
|
||||
run_addr = segments[0].origin
|
||||
|
||||
chunks = []
|
||||
|
||||
for s in segments:
|
||||
# find size in 256 byte chunks that start on a page boundary
|
||||
# since the loader only deals with page boundaries
|
||||
origin = s.start_addr
|
||||
origin = s.origin
|
||||
chunk_start, padding = divmod(origin, 256)
|
||||
if (chunk_start == 0x20 or chunk_start == 0x40) and padding == 1:
|
||||
show_hgr = False
|
||||
|
@ -15,7 +15,7 @@ from functools import reduce
|
||||
def get_indexed(segment, num, scale):
|
||||
indexes = np.arange(num) * scale
|
||||
raw = segment.rawdata.get_indexed(indexes)
|
||||
s = DefaultSegment(raw, segment.start_addr + indexes[0])
|
||||
s = DefaultSegment(raw, segment.origin + indexes[0])
|
||||
return s, indexes
|
||||
|
||||
class TestSegment1(object):
|
||||
@ -97,7 +97,7 @@ class TestIndexed(object):
|
||||
assert not sub.rawdata.is_indexed
|
||||
for i in range(len(sub)):
|
||||
ri = sub.get_raw_index(i)
|
||||
assert ri == sub.start_addr + i
|
||||
assert ri == sub.origin + i
|
||||
assert sub[i] == base[ri]
|
||||
start, end = sub.byte_bounds_offset()
|
||||
assert start == 512
|
||||
@ -116,7 +116,7 @@ class TestIndexed(object):
|
||||
for i in range(len(indexes)):
|
||||
ri = s.get_raw_index(i)
|
||||
print(ri, "base[ri]=%d" % base[ri], i, indexes[i], "s[i]=%d" % s[i])
|
||||
assert ri == sub.start_addr + indexes[i]
|
||||
assert ri == sub.origin + indexes[i]
|
||||
assert s[i] == base[ri]
|
||||
start, end = s.byte_bounds_offset()
|
||||
assert start == 0
|
||||
@ -126,7 +126,7 @@ class TestIndexed(object):
|
||||
s2, indexes2 = get_indexed(s, 64, 3)
|
||||
assert s2.rawdata.is_indexed
|
||||
for i in range(len(indexes2)):
|
||||
assert s2.get_raw_index(i) == sub.start_addr + indexes2[i] * 3
|
||||
assert s2.get_raw_index(i) == sub.origin + indexes2[i] * 3
|
||||
start, end = s.byte_bounds_offset()
|
||||
assert start == 0
|
||||
assert end == len(base)
|
||||
|
Loading…
x
Reference in New Issue
Block a user