Added XEX creator from a list of segments

This commit is contained in:
Rob McMullen 2016-05-05 17:14:23 -07:00
parent cfe6c775bb
commit eaca5e166a
3 changed files with 56 additions and 1 deletions

View File

@ -8,7 +8,7 @@ except ImportError:
raise RuntimeError("atrcopy %s requires numpy" % __version__)
from errors import *
from ataridos import AtariDosDiskImage, AtariDosFile
from ataridos import AtariDosDiskImage, AtariDosFile, get_xex
from diskimages import AtrHeader, BootDiskImage
from kboot import KBootImage, add_kboot_header
from segments import SegmentData, SegmentSaver, DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, user_bit_mask, match_bit_mask, comment_bit_mask, data_bit_mask, selected_bit_mask, diff_bit_mask, not_user_bit_mask

View File

@ -346,3 +346,24 @@ class AtariDosDiskImage(DiskImageBase):
except InvalidBinaryFile:
log.debug("%s not a binary file; skipping segment generation" % str(segment))
return segments_out
def get_xex(segments, runaddr):
total = 2
for s in segments:
total += 4 + len(s)
total += 6
bytes = np.zeros([total], dtype=np.uint8)
bytes[0:2] = 0xff # FFFF header
i = 2
for s in segments:
words = bytes[i:i+4].view(dtype='<u2')
words[0] = s.start_addr
words[1] = s.start_addr + len(s) - 1
i += 4
bytes[i:i + len(s)] = s[:]
i += len(s)
words = bytes[i:i+6].view(dtype='<u2')
words[0] = 0x2e0
words[1] = 0x2e1
words[2] = runaddr
return bytes

34
test/test_segment.py Normal file
View File

@ -0,0 +1,34 @@
import os
import numpy as np
from atrcopy import DefaultSegment, SegmentData, get_xex
class TestSegment1(object):
def setup(self):
self.segments = []
for i in range(8):
data = np.ones([1024], dtype=np.uint8) * i
r = SegmentData(data)
self.segments.append(DefaultSegment(r, i * 1024))
def test_xex(self):
items = [
[(0, 1, 2), 0],
]
for indexes, stuff in items:
s = [self.segments[i] for i in indexes]
bytes = get_xex(s, 0xbeef)
assert tuple(bytes[0:2]) == (0xff, 0xff)
# 2 bytes for the ffff
# 6 bytes for the last segment run address
# 4 bytes per segment for start, end address
size = reduce(lambda a, b:a + 4 + len(b), s, 0)
assert len(bytes) == 2 + 6 + size
if __name__ == "__main__":
t = TestSegment1()
t.setup()
t.test_xex()