annotate pytouhou/formats/ecl.py @ 46:25ca15f714ad

Add/fix a few opcodes
author Thibaut Girka <thib@sitedethib.com>
date Mon, 22 Aug 2011 10:49:49 +0200
parents 7195aaf95f6e
children 811cefefb5c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
1 from struct import pack, unpack
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
2 from pytouhou.utils.helpers import read_string
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
3
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
4 from collections import namedtuple
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
5
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
6
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
7 class ECL(object):
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
8 _instructions = {0: ('', 'noop?'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
9 1: ('I', 'delete?'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
10 2: ('Ii', 'relative_jump'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
11 3: ('Iii', 'relative_jump_ex'),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
12 4: ('ii', 'set_int'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
13 5: ('if', 'set_float'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
14 6: ('ii', 'set_random_int'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
15 8: ('if', 'set_random_float'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
16 9: ('iff', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
17 10: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
18 13: ('iii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
19 14: ('iii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
20 15: ('iii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
21 16: ('iii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
22 17: ('iii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
23 18: ('i', None),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
24 20: ('iff', 'add'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
25 21: ('iff', 'sub'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
26 23: ('iff', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
27 25: ('iffff', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
28 26: ('i', None),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
29 27: ('ii', 'compare_ints'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
30 28: ('ff', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
31 29: ('ii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
32 30: ('ii', None),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
33 31: ('ii', 'relative_jump_if_equal'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
34 32: ('ii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
35 33: ('ii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
36 34: ('ii', None),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
37 35: ('iif', 'call'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
38 36: ('', 'return?'),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
39 39: ('iifii', 'call_if_equal'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
40 43: ('fff', 'set_position'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
41 45: ('ff', 'set_angle_and_speed'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
42 46: ('f', 'set_rotation_speed'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
43 47: ('f', 'set_speed'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
44 48: ('f', 'set_acceleration'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
45 49: ('ff', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
46 50: ('ff', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
47 51: ('ff', 'set_speed_towards_player'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
48 52: ('iff', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
49 56: ('iffi', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
50 57: ('ifff', 'move_to'),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
51 59: ('iffi', 'move_to2'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
52 61: ('i', 'stop_in'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
53 63: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
54 65: ('ffff', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
55 66: ('', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
56 67: ('hhiiffffi', 'set_bullet_attributes'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
57 68: ('hhiiffffi', 'set_bullet_attributes2'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
58 69: ('hhiiffffi', 'set_bullet_attributes3'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
59 70: ('hhiiffffi', 'set_bullet_attributes4'),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
60 71: ('hhiiffffi', 'set_bullet_attributes5'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
61 74: ('hhiiffffi', 'set_bullet_attributes6'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
62 75: ('hhiiffffi', 'set_bullet_attributes7'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
63 76: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
64 77: ('i', 'set_bullet_interval'),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
65 78: ('', 'delay_attack'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
66 79: ('', 'no_delay_attack'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
67 81: ('fff', 'set_bullet_launch_offset'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
68 82: ('iiiiffff', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
69 83: ('', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
70 84: ('i', None),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
71 85: ('hhffffffiiiiii', 'laser'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
72 86: ('hhffffffiiiiii', 'laser2'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
73 87: ('i', 'set_upcoming_id'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
74 88: ('if','alter_laser_angle'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
75 90: ('iiii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
76 92: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
77 #93: set_spellcard, a string is there
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
78 94: ('', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
79 95: ('ifffhhi', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
80 96: ('', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
81 97: ('i', 'set_anim'),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
82 98: ('hhhhhxx', 'set_multiple_anims'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
83 99: ('ii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
84 100: ('i', 'set_death_anim'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
85 101: ('i', 'set_boss_mode?'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
86 102: ('iffff', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
87 103: ('fff', 'set_enemy_hitbox'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
88 104: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
89 105: ('i', 'set_vulnerable'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
90 106: ('i', 'play_sound'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
91 107: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
92 108: ('i', 'set_death_callback?'),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
93 109: ('ii', 'memory_write_int'),
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
94 111: ('i', 'set_life'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
95 112: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
96 113: ('i', 'set_low_life_trigger'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
97 114: ('i', 'set_low_life_callback'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
98 115: ('i', 'set_timeout'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
99 116: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
100 117: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
101 118: ('iihh', None),
46
25ca15f714ad Add/fix a few opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
102 119: ('i', 'drop_bonus'),
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
103 120: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
104 121: ('ii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
105 122: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
106 123: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
107 124: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
108 125: ('', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
109 126: ('i', 'set_remaining_lives'),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
110 127: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
111 128: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
112 129: ('ii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
113 130: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
114 131: ('ffiiii', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
115 132: ('i', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
116 133: ('', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
117 134: ('', None),
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
118 135: ('i', None)} #TODO
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
119
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
120 def __init__(self):
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
121 self.main = []
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
122 self.subs = [[]]
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
123
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
124
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
125 @classmethod
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
126 def read(cls, file):
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
127 sub_count, main_offset = unpack('<II', file.read(8))
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
128 if file.read(8) != b'\x00\x00\x00\x00\x00\x00\x00\x00':
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
129 raise Exception #TODO
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
130 sub_offsets = unpack('<%s' % ('I' * sub_count), file.read(4 * sub_count))
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
131
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
132 ecl = cls()
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
133 ecl.subs = []
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
134 ecl.main = []
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
135
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
136 # Read subs
43
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
137 for sub_offset in sub_offsets:
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
138 file.seek(sub_offset)
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
139 ecl.subs.append([])
43
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
140
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
141 instruction_offsets = []
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
142
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
143 while True:
43
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
144 instruction_offsets.append(file.tell() - sub_offset)
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
145
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
146 time, opcode = unpack('<IH', file.read(6))
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
147 if time == 0xffffffff or opcode == 0xffff:
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
148 break
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
149 size, rank_mask, param_mask = unpack('<HHH', file.read(6))
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
150 data = file.read(size - 12)
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
151 if opcode in cls._instructions:
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
152 args = unpack('<%s' % cls._instructions[opcode][0], data)
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
153 else:
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
154 args = (data, )
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
155 print('Warning: unknown opcode %d' % opcode) #TODO
43
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
156
42
1b0ca2fb89f9 Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
157 ecl.subs[-1].append((time, opcode, rank_mask, param_mask, args))
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
158
43
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
159
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
160 # Translate offsets to instruction pointers
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
161 for instr_offset, (i, instr) in zip(instruction_offsets, enumerate(ecl.subs[-1])):
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
162 time, opcode, rank_mask, param_mask, args = instr
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
163 if opcode == 2: # relative_jump
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
164 frame, relative_offset = args
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
165 args = frame, instruction_offsets.index(instr_offset + relative_offset)
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
166 elif opcode == 3: # relative_jump_ex
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
167 frame, relative_offset, counter_id = args
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
168 args = frame, instruction_offsets.index(instr_offset + relative_offset), counter_id
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
169 ecl.subs[-1][i] = time, opcode, rank_mask, param_mask, args
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
170
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
171
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
172 # Read main
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
173 file.seek(main_offset)
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
174 while True:
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
175 time, = unpack('<H', file.read(2))
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
176 if time == 0xffff:
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
177 break
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
178 sub, instr_type, size = unpack('<HHH', file.read(6))
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
179 data = file.read(size - 8)
20
6ebf9539c077 Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents: 18
diff changeset
180 if instr_type in (0, 2, 4, 6): # Enemy spawn
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
181 args = unpack('<ffIhHHH', data)
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
182 else:
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
183 print('ECL: Warning: unknown opcode %d (%r)' % (instr_type, data)) #TODO
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
184 args = (data,)
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
185 ecl.main.append((time, sub, instr_type, args))
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
186
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
187 return ecl
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
188