Beispiel #1
0
 def __init__(self):
   self.file_obj = valiant.ObjectFile()
   self.file_obj.magic1 = MAGIC_NUM % 100
   self.file_obj.magic2 = MAGIC_NUM / 100
   self.obj_body = self.file_obj.body
   self.buffer = None
   self.info = DataInfo()
   self.component_req = {}
Beispiel #2
0
 def _build_vobject(self, palette):
     obj = valiant.ObjectFile()
     obj.magic1 = MAGIC_NUM % 100
     obj.magic2 = MAGIC_NUM // 100
     obj.header.short_palette = True
     packet = obj.body.packets.add()
     packet.role = valiant.PALETTE
     binary = packet.binary
     binary.bin = bytes(self.pal.to_bytes())
     return obj
 def assertDowngrade(self, basename):
     future_file = os.path.join('testdata/', basename)
     fp = open(future_file, 'rb')
     content = fp.read()
     fp.close()
     obj = valiant.ObjectFile()
     obj.ParseFromString(content)
     downgraded_file = os.path.join(tempfile.mkdtemp(), basename)
     downgrade_to_deprecated_proto(obj)
     save_proto(obj, downgraded_file)
     deprecated_file = os.path.join('testdata/deprecated/', basename)
     self.assert_file_eq(downgraded_file, deprecated_file)
Beispiel #4
0
 def read_valiant(self, filename):
     import gen.valiant_pb2 as valiant
     fp = open(filename, 'rb')
     content = fp.read()
     fp.close()
     mem = ppu_memory.PpuMemory()
     mem.allocate_num_pages(2)
     obj_file = valiant.ObjectFile()
     obj_file.ParseFromString(content)
     binary_map = {}
     for packet in obj_file.body.packets:
         if packet.role == valiant.CHR:
             binary_map['chr'] = packet.binary
         if packet.role == valiant.NAMETABLE:
             binary_map['nametable'] = packet.binary
         if packet.role == valiant.ATTRIBUTE:
             binary_map['attribute'] = packet.binary
         if packet.role == valiant.PALETTE:
             binary_map['palette'] = packet.binary
     chr_bin = self._expand_binary(binary_map['chr'])
     nt_bin = self._expand_binary(binary_map['nametable'])
     at_bin = self._expand_binary(binary_map['attribute'])
     pal_bin = self._expand_binary(binary_map['palette'])
     # Parse chr data.
     mem.chr_set = chr_data.ChrBank.from_binary(bytes(bytearray(chr_bin)))
     # Parse nametable data.
     for y in range(30):
         for x in range(32):
             mem.gfx[0].nametable[y][x] = nt_bin[y * 32 + x]
     # Parse attributes data.
     for a in range(64):
         p0 = (at_bin[a] >> 0) & 0x03
         p1 = (at_bin[a] >> 2) & 0x03
         p2 = (at_bin[a] >> 4) & 0x03
         p3 = (at_bin[a] >> 6) & 0x03
         y = (a // 8) * 4
         x = (a % 8) * 4
         mem.gfx[0].colorization[y + 0][x + 0] = p0
         mem.gfx[0].colorization[y + 0][x + 2] = p1
         if y < (7 * 4):
             mem.gfx[0].colorization[y + 2][x + 0] = p2
             mem.gfx[0].colorization[y + 2][x + 2] = p3
     # Parse palette data.
     pal = palette.Palette()
     pal.set_bg_color(pal_bin[0])
     for i in range(4):
         p = []
         for j in range(4):
             p.append(pal_bin[i * 4 + j])
         pal.add(p)
     mem.palette_nt = pal
     return mem