def parse(self):

        done = False
        while not done:
            cmd = rom[self.address]
            class_ = self.get_command_class(cmd)(address=self.address)
            asm = class_.to_asm()

            # label jumps/calls
            for key, param in class_.param_types.items():
                if param['class'] == PointerLabelParam:
                    label_address = class_.params[key].parsed_address
                    label = '%s_branch_%x' % (self.base_label, label_address)
                    label_def = '%s: ; %x' % (label, label_address)
                    label_asm = (label_address, label_def, label_address)
                    if label_asm not in self.used_labels:
                        self.labels += [label_asm]
                    asm = asm.replace('$%x' % get_local_address(label_address),
                                      label)

            self.output += [(self.address, '\t' + asm,
                             self.address + class_.size)]
            self.address += class_.size

            done = class_.end
            # infinite loops are enders
            if class_.macro_name == 'anim_loop':
                if class_.params[0].byte == 0:
                    done = True

        # last_address comment
        self.output += [(self.address, '; %x\n' % self.address, self.address)]

        # parse any other branches too
        self.labels = list(set(self.labels))
        for address, asm, last_address in self.labels:
            if not (self.start_address <= address < self.address) and (
                    address, asm, last_address) not in self.used_labels:
                self.used_labels += [(address, asm, last_address)]
                sub = BattleAnim(address=address,
                                 base_label=self.base_label,
                                 label=asm.split(':')[0],
                                 used_labels=self.used_labels,
                                 macros=self.macros)
                self.output += sub.output
                self.labels += sub.labels

        self.output = list(set(self.output))
        self.labels = list(set(self.labels))
	def parse(self):

		done = False
		while not done:
			cmd = rom[self.address]
			class_ = self.get_command_class(cmd)(address=self.address)
			asm = class_.to_asm()

			# label jumps/calls
			for key, param in class_.param_types.items():
				if param['class'] == PointerLabelParam:
					label_address = class_.params[key].parsed_address
					label = '%s_branch_%x' % (self.base_label, label_address)
					label_def = '%s: ; %x' % (label, label_address)
					label_asm = (label_address, label_def, label_address)
					if label_asm not in self.used_labels:
						self.labels += [label_asm]
					asm = asm.replace('$%x' % get_local_address(label_address), label)

			self.output += [(self.address, '\t' + asm, self.address + class_.size)]
			self.address += class_.size

			done = class_.end
			# infinite loops are enders
			if class_.macro_name == 'anim_loop':
				if class_.params[0].byte == 0:
					done = True

		# last_address comment
		self.output += [(self.address, '; %x\n' % self.address, self.address)]

		# parse any other branches too
		self.labels = list(set(self.labels))
		for address, asm, last_address in self.labels:
			if not (self.start_address <= address < self.address) and (address, asm, last_address) not in self.used_labels:
				self.used_labels += [(address, asm, last_address)]
				sub = BattleAnim(
					address=address,
					base_label=self.base_label,
					label=asm.split(':')[0],
					used_labels=self.used_labels,
					macros=self.macros
				)
				self.output += sub.output
				self.labels += sub.labels

		self.output = list(set(self.output))
		self.labels = list(set(self.labels))
	def parse(self):
		noise = False
		done = False
		while not done:
			cmd = rom[self.address]

			class_ = self.get_sound_class(cmd)(address=self.address, channel=self.channel)

			# notetype loses the intensity param on channel 4
			if class_.macro_name == 'notetype':
				if self.channel in [4, 8]:
					class_.size -= 1
					del class_.params[class_.size - 1]

			# togglenoise only has a param when toggled on
			elif class_.macro_name in ['togglenoise', 'sfxtogglenoise']:
				if noise:
					class_.size -= 1
					del class_.params[class_.size - 1]
				noise = not noise

			elif class_.macro_name == 'togglesfx':
				self.sfx = not self.sfx

			asm = class_.to_asm()

			# label any jumps or calls
			for key, param in class_.param_types.items():
				if param['class'] == PointerLabelParam:
					label_address = class_.params[key].parsed_address
					label = '%s_branch_%x' % (
						self.base_label,
						label_address
					)
					self.labels += [generate_label_asm(label, label_address)]
					asm = asm.replace(
						'$%x' % (get_local_address(label_address)),
						label
					)

			self.output += [(self.address, '\t' + asm, self.address + class_.size)]
			self.address += class_.size

			done = class_.end
			# infinite loops are enders
			if class_.macro_name == 'loopchannel':
				if class_.params[0].byte == 0:
					done = True

			# dumb safety checks
			if (
				self.address >= len(rom) or
				self.address / 0x4000 != self.start_address / 0x4000
			) and not done:
				done = True
				raise Exception, self.label + ': reached the end of the bank without finishing!'

		self.output += [(self.address, '; %x\n' % self.address, self.address)]

		# parse any other branches too
		self.labels = list(set(self.labels))
		for address, asm, last_address in self.labels:
			if (
				address >= self.address
				and (address, asm, last_address) not in self.used_labels
			):

				self.used_labels += [(address, asm, last_address)]
				sub = Channel(
					address=address,
					channel=self.channel,
					base_label=self.base_label,
					label=asm.split(':')[0],
					used_labels=self.used_labels,
					sfx=self.sfx,
				)
				self.output += sub.output
				self.labels += sub.labels
Beispiel #4
0
    def parse(self):
        noise = False
        done = False
        while not done:
            cmd = rom[self.address]

            class_ = self.get_sound_class(cmd)(address=self.address,
                                               channel=self.channel)

            # notetype loses the intensity param on channel 4
            if class_.macro_name == 'notetype':
                if self.channel in [4, 8]:
                    class_.size -= 1
                    del class_.params[class_.size - 1]

            # togglenoise only has a param when toggled on
            elif class_.macro_name in ['togglenoise', 'sfxtogglenoise']:
                if noise:
                    class_.size -= 1
                    del class_.params[class_.size - 1]
                noise = not noise

            elif class_.macro_name == 'togglesfx':
                self.sfx = not self.sfx

            asm = class_.to_asm()

            # label any jumps or calls
            for key, param in class_.param_types.items():
                if param['class'] == PointerLabelParam:
                    label_address = class_.params[key].parsed_address
                    label = '%s_branch_%x' % (self.base_label, label_address)
                    self.labels += [generate_label_asm(label, label_address)]
                    asm = asm.replace(
                        '$%x' % (get_local_address(label_address)), label)

            self.output += [(self.address, '\t' + asm,
                             self.address + class_.size)]
            self.address += class_.size

            done = class_.end
            # infinite loops are enders
            if class_.macro_name == 'loopchannel':
                if class_.params[0].byte == 0:
                    done = True

            # dumb safety checks
            if (self.address >= len(rom) or self.address / 0x4000 !=
                    self.start_address / 0x4000) and not done:
                done = True
                raise Exception, self.label + ': reached the end of the bank without finishing!'

        self.output += [(self.address, '; %x\n' % self.address, self.address)]

        # parse any other branches too
        self.labels = list(set(self.labels))
        for address, asm, last_address in self.labels:
            if (address >= self.address
                    and (address, asm, last_address) not in self.used_labels):

                self.used_labels += [(address, asm, last_address)]
                sub = Channel(
                    address=address,
                    channel=self.channel,
                    base_label=self.base_label,
                    label=asm.split(':')[0],
                    used_labels=self.used_labels,
                    sfx=self.sfx,
                )
                self.output += sub.output
                self.labels += sub.labels