comparison pytouhou/formats/ecl.py @ 43:7195aaf95f6e

Fix set_counter, and relative_jump(_ex)
author Thibaut Girka <thib@sitedethib.com>
date Thu, 18 Aug 2011 22:24:32 +0200
parents 1b0ca2fb89f9
children 25ca15f714ad
comparison
equal deleted inserted replaced
42:1b0ca2fb89f9 43:7195aaf95f6e
131 ecl = cls() 131 ecl = cls()
132 ecl.subs = [] 132 ecl.subs = []
133 ecl.main = [] 133 ecl.main = []
134 134
135 # Read subs 135 # Read subs
136 for offset in sub_offsets: 136 for sub_offset in sub_offsets:
137 file.seek(offset) 137 file.seek(sub_offset)
138 ecl.subs.append([]) 138 ecl.subs.append([])
139
140 instruction_offsets = []
141
139 while True: 142 while True:
143 instruction_offsets.append(file.tell() - sub_offset)
144
140 time, opcode = unpack('<IH', file.read(6)) 145 time, opcode = unpack('<IH', file.read(6))
141 if time == 0xffffffff or opcode == 0xffff: 146 if time == 0xffffffff or opcode == 0xffff:
142 break 147 break
143 size, rank_mask, param_mask = unpack('<HHH', file.read(6)) 148 size, rank_mask, param_mask = unpack('<HHH', file.read(6))
144 data = file.read(size - 12) 149 data = file.read(size - 12)
145 if opcode in cls._instructions: 150 if opcode in cls._instructions:
146 args = unpack('<%s' % cls._instructions[opcode][0], data) 151 args = unpack('<%s' % cls._instructions[opcode][0], data)
147 else: 152 else:
148 args = (data, ) 153 args = (data, )
149 print('Warning: unknown opcode %d' % opcode) #TODO 154 print('Warning: unknown opcode %d' % opcode) #TODO
155
150 ecl.subs[-1].append((time, opcode, rank_mask, param_mask, args)) 156 ecl.subs[-1].append((time, opcode, rank_mask, param_mask, args))
157
158
159 # Translate offsets to instruction pointers
160 for instr_offset, (i, instr) in zip(instruction_offsets, enumerate(ecl.subs[-1])):
161 time, opcode, rank_mask, param_mask, args = instr
162 if opcode == 2: # relative_jump
163 frame, relative_offset = args
164 args = frame, instruction_offsets.index(instr_offset + relative_offset)
165 elif opcode == 3: # relative_jump_ex
166 frame, relative_offset, counter_id = args
167 args = frame, instruction_offsets.index(instr_offset + relative_offset), counter_id
168 ecl.subs[-1][i] = time, opcode, rank_mask, param_mask, args
169
151 170
152 # Read main 171 # Read main
153 file.seek(main_offset) 172 file.seek(main_offset)
154 while True: 173 while True:
155 time, = unpack('<H', file.read(2)) 174 time, = unpack('<H', file.read(2))