<s> from py65 . utils . addressing import AddressParser <EOL> class Disassembler : <EOL> def __init__ ( self , mpu , address_parser = None ) : <EOL> if address_parser is None : <EOL> address_parser = AddressParser ( ) <EOL> self . _mpu = mpu <EOL> self . _address_parser = address_parser <EOL> self . addrWidth = mpu . ADDR_WIDTH <EOL> self . byteWidth = mpu . BYTE_WIDTH <EOL> self . addrFmt = mpu . ADDR_FORMAT <EOL> self . byteFmt = mpu . BYTE_FORMAT <EOL> self . addrMask = mpu . addrMask <EOL> self . byteMask = mpu . byteMask <EOL> def instruction_at ( self , pc ) : <EOL> """<STR_LIT>""" <EOL> instruction = self . _mpu . ByteAt ( pc ) <EOL> disasm , addressing = self . _mpu . disassemble [ instruction ] <EOL> if addressing == '<STR_LIT>' : <EOL> disasm += '<STR_LIT>' <EOL> length = <NUM_LIT:1> <EOL> elif addressing == '<STR_LIT>' : <EOL> address = self . _mpu . WordAt ( pc + <NUM_LIT:1> ) <EOL> address_or_label = self . _address_parser . label_for ( <EOL> address , '<STR_LIT:$>' + self . addrFmt % address ) <EOL> disasm += '<STR_LIT:U+0020>' + address_or_label <EOL> length = <NUM_LIT:3> <EOL> elif addressing == '<STR_LIT>' : <EOL> address = self . _mpu . WordAt ( pc + <NUM_LIT:1> ) <EOL> address_or_label = self . _address_parser . label_for ( <EOL> address , '<STR_LIT:$>' + self . addrFmt % address ) <EOL> disasm += '<STR_LIT>' % address_or_label <EOL> length = <NUM_LIT:3> <EOL> elif addressing == '<STR_LIT>' : <EOL> address = self . _mpu . WordAt ( pc + <NUM_LIT:1> ) <EOL> address_or_label = self . _address_parser . label_for ( <EOL> address , '<STR_LIT:$>' + self . addrFmt % address ) <EOL> disasm += '<STR_LIT>' % address_or_label <EOL> length = <NUM_LIT:3> <EOL> elif addressing == '<STR_LIT>' : <EOL> byte = self . _mpu . ByteAt ( pc + <NUM_LIT:1> ) <EOL> disasm += '<STR_LIT>' + self . byteFmt % byte <EOL> length = <NUM_LIT:2> <EOL> elif addressing == '<STR_LIT>' : <EOL> length = <NUM_LIT:1> <EOL> elif addressing == '<STR_LIT>' : <EOL> address = self . _mpu . WordAt ( pc + <NUM_LIT:1> ) <EOL> address_or_label = self . _address_parser . label_for ( <EOL> address , '<STR_LIT:$>' + self . addrFmt % address ) <EOL> disasm += '<STR_LIT>' % address_or_label <EOL> length = <NUM_LIT:3> <EOL> elif addressing == '<STR_LIT>' : <EOL> zp_address = self . _mpu . ByteAt ( pc + <NUM_LIT:1> ) <EOL> address_or_label = self . _address_parser . label_for ( <EOL> zp_address , '<STR_LIT:$>' + self . byteFmt % zp_address ) <EOL> disasm += '<STR_LIT>' % address_or_label <EOL> length = <NUM_LIT:2> <EOL> elif addressing == '<STR_LIT>' : <EOL> zp_address = self . _mpu . ByteAt ( pc + <NUM_LIT:1> ) <EOL> address_or_label = self . _address_parser . label_for ( <EOL> zp_address , '<STR_LIT:$>' + self . byteFmt % zp_address ) <EOL> disasm += '<STR_LIT>' % address_or_label <EOL> length = <NUM_LIT:2> <EOL> elif addressing == '<STR_LIT>' : <EOL> address = self . _mpu . WordAt ( pc + <NUM_LIT:1> ) <EOL> address_or_label = self . _address_parser . label_for ( <EOL> address , '<STR_LIT:$>' + self . addrFmt % address ) <EOL> disasm += '<STR_LIT>' % address_or_label <EOL> length = <NUM_LIT:3> <EOL> elif addressing == '<STR_LIT>' : <EOL> opv = self . _mpu . ByteAt ( pc + <NUM_LIT:1> ) <EOL> targ = pc + <NUM_LIT:2> <EOL> if opv & ( <NUM_LIT:1> << ( self . byteWidth - <NUM_LIT:1> ) ) : <EOL> targ -= ( opv ^ self . byteMask ) + <NUM_LIT:1> <EOL> else : <EOL> targ += opv <EOL> targ &= self . addrMask <EOL> address_or_label = self . _address_parser . label_for ( <EOL> targ , '<STR_LIT:$>' + self . addrFmt % targ ) <EOL> disasm += '<STR_LIT:U+0020>' + address_or_label <EOL> length = <NUM_LIT:2> <EOL> elif addressing == '<STR_LIT>' : <EOL> zp_address = self . _mpu . ByteAt ( pc + <NUM_LIT:1> ) <EOL> address_or_label = self . _address_parser . label_for ( <EOL> zp_address , '<STR_LIT>' + self . byteFmt % zp_address + '<STR_LIT:)>' ) <EOL> disasm += '<STR_LIT>' % address_or_label <EOL> length = <NUM_LIT:2> <EOL> elif addressing == '<STR_LIT>' : <EOL> zp_address = self . _mpu . ByteAt ( pc + <NUM_LIT:1> ) <EOL> address_or_label = self . _address_parser . label_for ( <EOL> zp_address , '<STR_LIT:$>' + self . byteFmt % zp_address ) <EOL> disasm += '<STR_LIT>' % address_or_label <EOL> length = <NUM_LIT:2> <EOL> elif addressing == '<STR_LIT>' : <EOL> zp_address = self . _mpu . ByteAt ( pc + <NUM_LIT:1> ) <EOL> address_or_label = self . _address_parser . label_for ( <EOL> zp_address , '<STR_LIT:$>' + self . byteFmt % zp_address ) <EOL> disasm += '<STR_LIT>' % address_or_label <EOL> length = <NUM_LIT:2> <EOL> elif addressing == '<STR_LIT>' : <EOL> zp_address = self . _mpu . ByteAt ( pc + <NUM_LIT:1> ) <EOL> address_or_label = self . _address_parser . label_for ( <EOL> zp_address , '<STR_LIT:$>' + self . byteFmt % zp_address ) <EOL> disasm += '<STR_LIT>' % address_or_label <EOL> length = <NUM_LIT:2> <EOL> return ( length , disasm ) </s>
