def write_segment_list_entry(f, v): persistence.write_uint8(f, v[loaderlib.SI_TYPE]) if v[loaderlib.SI_FILE_OFFSET] == -1: persistence.write_uint32(f, 0xFFFFFFFF) # Unsigned, special value. else: persistence.write_uint32(f, v[loaderlib.SI_FILE_OFFSET]) persistence.write_uint32(f, v[loaderlib.SI_DATA_LENGTH]) persistence.write_uint32(f, v[loaderlib.SI_LENGTH]) persistence.write_uint32(f, v[loaderlib.SI_ADDRESS])
def write_SegmentBlock(f, block, pc_offset): if block.line_data is None: line_data_count = 0 else: line_data_count = len(block.line_data) s = struct.pack(SEGMENTBLOCK_PACK_FORMAT, block.segment_id, block.segment_offset, block.address, block.length, block.flags, block.line_count, line_data_count) f.write(s) if line_data_count > 0: if get_block_data_type(block) == DATA_TYPE_CODE: block_offset = 0 for i, (type_id, entry) in enumerate(block.line_data): persistence.write_uint8(f, type_id) if type_id == SLD_INSTRUCTION: if type(entry) is int: persistence.write_uint16(f, entry) # The length of this instruction is not stored, so we calculate it relative to the next one. j = i + 1 while j < len(block.line_data): next_type_id, next_entry = block.line_data[j] if next_type_id == SLD_INSTRUCTION: if type(next_entry) is int: block_offset = next_entry else: block_offset = next_entry.pc - pc_offset break j += 1 else: persistence.write_uint16(f, block_offset) block_offset += entry.num_bytes elif type_id == SLD_EQU_LOCATION_RELATIVE: persistence.write_uint32(f, entry) # block offset elif type_id in (SLD_COMMENT_TRAILING, SLD_COMMENT_FULL_LINE): persistence.write_string(f, entry) # string else: logger.error( "Trying to save a savefile, did not know how to handle entry of type_id: %d, entry value: %s", type_id, entry)
def write_SegmentBlock(f, block): if block.line_data is None: line_data_count = 0 else: line_data_count = len(block.line_data) s = struct.pack(SEGMENTBLOCK_PACK_FORMAT, block.segment_id, block.segment_offset, block.address, block.length, block.flags, block.line_count, line_data_count) f.write(s) if line_data_count > 0: if get_block_data_type(block) == DATA_TYPE_CODE: block_offset = 0 for i, (type_id, entry) in enumerate(block.line_data): persistence.write_uint8(f, type_id) if type_id == SLD_INSTRUCTION: if type(entry) is int: persistence.write_uint16(f, entry) # The length of this instruction is not stored, so we calculate it relative to the next one. j = i+1 while j < len(block.line_data): next_type_id, next_entry = block.line_data[j] if next_type_id == SLD_INSTRUCTION: if type(next_entry) is int: block_offset = next_entry else: block_offset = next_entry.pc-2 break j += 1 else: persistence.write_uint16(f, block_offset) block_offset += entry.num_bytes elif type_id == SLD_EQU_LOCATION_RELATIVE: persistence.write_uint32(f, entry) # block offset elif type_id in (SLD_COMMENT_TRAILING, SLD_COMMENT_FULL_LINE): persistence.write_string(f, entry) # string else: logger.error("Trying to save a savefile, did not know how to handle entry of type_id: %d, entry value: %s", type_id, entry)