示例#1
0
    def test_extra(self):
        s = self.segment
        s.set_comment([[4, 5]], "test1")
        s.set_comment([[40, 50]], "test2")
        s.set_style_ranges([[2, 100]], comment=True)
        s.set_style_ranges([[200, 299]], data=True)
        for i in range(1, 4):
            for j in range(1, 4):
                # create some with overlapping regions, some without
                r = [500 * j, 500 * j + 200 * i + 200]
                s.set_style_ranges([r], user=i)
                s.set_user_data([r], i, i * 10 + j)
        r = [100, 200]
        s.set_style_ranges([r], user=4)
        s.set_user_data([r], 4, 99)
        r = [3100, 3200]
        s.set_style_ranges([r], user=4)
        s.set_user_data([r], 4, 99)

        out = dict()
        s.serialize_session(out)
        print("saved", out)

        data = np.ones([4000], dtype=np.uint8)
        r = SegmentData(data)
        s2 = DefaultSegment(r, 0)
        s2.restore_session(out)
        out2 = dict()
        s2.serialize_session(out2)
        print("loaded", out2)
        assert out == out2
示例#2
0
 def test_short_segment(self):
     bytes = [0xff, 0xff, 0x00, 0x60, 0xff, 0x60, 1, 2]
     rawdata = SegmentData(bytes)
     image = AtariDosFile(rawdata)
     image.parse_segments()
     assert len(image.segments) == 1
     assert len(image.segments[0]) == 2
示例#3
0
 def test_typical_rom_sizes(self, k_size):
     data = self.get_rom(k_size)
     rawdata = SegmentData(data)
     rom_image = RomImage(rawdata)
     rom_image.strict_check()
     rom_image.parse_segments()
     assert len(rom_image.segments) == 1
     assert len(rom_image.segments[0]) == k_size * 1024
示例#4
0
    def test_bad(self):
        k_size = 32

        # check for error because invalid data in cart image itself
        data = self.get_cart(k_size, 1337)
        rawdata = SegmentData(data)
        with pytest.raises(errors.InvalidDiskImage):
            image = AtariCartImage(rawdata, 1337)
        with pytest.raises(errors.InvalidDiskImage):
            image = AtariCartImage(rawdata, 12)

        # check for error with valid cart image, but invalid cart type supplied
        # to the image parser
        data = self.get_cart(k_size, 12)
        rawdata = SegmentData(data)
        with pytest.raises(errors.InvalidDiskImage):
            image = AtariCartImage(rawdata, 1337)
示例#5
0
 def test_unbanked(self, k_size, cart_type):
     data = self.get_cart(k_size, cart_type)
     rawdata = SegmentData(data)
     image = AtariCartImage(rawdata, cart_type)
     image.parse_segments()
     assert len(image.segments) == 2
     assert len(image.segments[0]) == 16
     assert len(image.segments[1]) == k_size * 1024
示例#6
0
 def test_banked(self, k_size, main_size, banked_size, cart_type):
     data = self.get_cart(k_size, cart_type)
     rawdata = SegmentData(data)
     image = AtariCartImage(rawdata, cart_type)
     image.parse_segments()
     assert len(image.segments) == 1 + 1 + (k_size - main_size) //banked_size
     assert len(image.segments[0]) == 16
     assert len(image.segments[1]) == main_size * 1024
     assert len(image.segments[2]) == banked_size * 1024
示例#7
0
 def check_size(self, data):
     xex_size = len(data)
     bytes = add_xexboot_header(data)
     #        rawdata = SegmentData(bytes)
     #        size = len(rawdata)
     #        atr = KBootImage(rawdata)
     #        newatr = atr.as_new_format("ATR")
     image_size = len(bytes)
     bytes = add_atr_header(bytes)
     rawdata = SegmentData(bytes)
     newatr = KBootImage(rawdata)
     image = newatr.bytes
     print(image[0:16])
     paragraphs = image_size // 16
     print(newatr.header, paragraphs)
     assert int(image[2:4].view(dtype='<u2')) == paragraphs
     assert int(image[16 + 9:16 + 9 + 2].view('<u2')) == xex_size
     return image
示例#8
0
 def test_conversion_to_atari_cart(self, cart):
     cart_type = cart[0]
     name = cart[1]
     k_size = cart[2]
     if "Bounty" in name:
         return
     data = self.get_rom(k_size)
     rawdata = SegmentData(data)
     rom_image = RomImage(rawdata)
     rom_image.strict_check()
     rom_image.parse_segments()
     new_cart_image = AtariCartImage(rawdata, cart_type)
     new_cart_image.relaxed_check()
     new_cart_image.parse_segments()
     assert new_cart_image.header.valid
     s = new_cart_image.create_emulator_boot_segment()
     assert len(s) == len(rawdata) + new_cart_image.header.nominal_length
     assert s[0:4].tobytes() == b'CART'
     assert s[4:8].view(dtype=">u4") == cart_type
示例#9
0
 def test_segment(self):
     bytes = np.asarray([0xff, 0xff, 0x00, 0x60, 0x01, 0x60, 1, 2],
                        dtype=np.uint8)
     rawdata = SegmentData(bytes)
     container = XexContainerSegment(rawdata, 0)
     image = AtariDosFile(container.rawdata)
     image.parse_segments()
     print(image.segments)
     assert len(image.segments) == 1
     assert len(image.segments[0]) == 2
     assert np.all(image.segments[0] == bytes[6:8])
     container.resize(16)
     for s in image.segments:
         s.replace_data(container)
     new_segment = DefaultSegment(rawdata[8:16])
     new_segment[:] = 99
     assert np.all(image.segments[0] == bytes[6:8])
     print(new_segment[:])
     assert np.all(new_segment[:] == 99)
示例#10
0
 def test_invalid_rom_sizes(self, k_size):
     data = np.zeros((k_size * 1024) + 17, dtype=np.uint8)
     rawdata = SegmentData(data)
     with pytest.raises(errors.InvalidDiskImage):
         rom_image = RomImage(rawdata)
示例#11
0
 def setup(self):
     data = np.ones([4000], dtype=np.uint8)
     r = SegmentData(data)
     self.segment = DefaultSegment(r, 0)
示例#12
0
 def test_err_segment(self):
     bytes = [0xff, 0xff, 0x00, 0x60, 0x00, 0x00, 1, 2]
     rawdata = SegmentData(bytes)
     image = AtariDosFile(rawdata)
     with pytest.raises(errors.InvalidBinaryFile):
         image.parse_segments()
示例#13
0
 def setup(self):
     rawdata = SegmentData(self.sample_data.copy())
     self.image = self.diskimage_type(rawdata)