コード例 #1
0
 def test_number_label_bin_offset(self):
     parser = AddressParser()
     parser.labels = {'foo': 0xC000}
     self.assertEqual(0xC003, parser.number('foo+%00000011'))
     self.assertEqual(0xBFFD, parser.number('foo-%00000011'))
     self.assertEqual(0xC003, parser.number('foo + %00000011'))
     self.assertEqual(0xBFFD, parser.number('foo - %00000011'))
コード例 #2
0
 def test_number_bad_label_with_offset(self):
     parser = AddressParser()
     try:
         parser.number('bad_label+3')
         self.fail()
     except KeyError as exc:
         self.assertEqual('Label not found: bad_label', exc.args[0])
コード例 #3
0
 def test_number_bad_label_syntax(self):
     parser = AddressParser()
     parser.labels = {'foo': 0xFFFF}
     try:
         parser.number('#$foo')
         self.fail()
     except KeyError as exc:
         self.assertEqual('Label not found: #$foo', exc.args[0])
コード例 #4
0
 def disassemble(self, bytes, pc=0, mpu=None):
     if mpu is None:
         mpu = MPU()
     address_parser = AddressParser()
     disasm = Disassembler(mpu, address_parser)
     mpu.memory[pc:len(bytes) - 81] = bytes
     return disasm.instruction_at(pc)
コード例 #5
0
 def test_number_label_offset_default_radix(self):
     parser = AddressParser()
     parser.labels = {'foo': 0xC000}
     parser.radix = 16
     self.assertEqual(0xC010, parser.number('foo+10'))
     self.assertEqual(0xBFF0, parser.number('foo-10'))
     self.assertEqual(0xC010, parser.number('foo + 10'))
     self.assertEqual(0xBFF0, parser.number('foo - 10'))
     parser.radix = 10
     self.assertEqual(0xC00A, parser.number('foo+10'))
     self.assertEqual(0xBFF6, parser.number('foo-10'))
     self.assertEqual(0xC00A, parser.number('foo + 10'))
     self.assertEqual(0xBFF6, parser.number('foo - 10'))
コード例 #6
0
    def __init__(self, mpu, address_parser=None):
        if address_parser is None:
            address_parser = AddressParser()

        self._mpu = mpu
        self._address_parser = address_parser

        self.addrWidth = mpu.ADDR_WIDTH
        self.byteWidth = mpu.BYTE_WIDTH
        self.addrFmt = mpu.ADDR_FORMAT
        self.byteFmt = mpu.BYTE_FORMAT
        self.addrMask = mpu.addrMask
        self.byteMask = mpu.byteMask
コード例 #7
0
    def __init__(self, mpu, address_parser=None):
        """ If a configured AddressParser is passed, symbolic addresses
        may be used in the assembly statements.
        """
        self._mpu = mpu

        if address_parser is None:
            address_parser = AddressParser()
        self._address_parser = address_parser

        self._addressing = []
        numchars = mpu.BYTE_WIDTH / 4  # 1 byte = 2 chars in hex
        for mode, format in self.Addressing:
            pat = "^" + re.escape(format) + "$"
            pat = pat.replace('00', '0{%d}' % numchars)
            pat = pat.replace('FF', '([0-9A-F]{%d})' % numchars)
            self._addressing.append([mode, re.compile(pat)])
コード例 #8
0
 def test_number_dec_literal(self):
     parser = AddressParser()
     self.assertEqual(49152, parser.number('+49152'))
コード例 #9
0
 def test_number_hex_literal(self):
     parser = AddressParser()
     self.assertEqual(49152, parser.number('$c000'))
コード例 #10
0
 def test_range_start_exceeds_end(self):
     parser = AddressParser(labels={})
     self.assertEqual((0xFFD2, 0xFFD4), parser.range('ffd4:ffd2'))
コード例 #11
0
 def test_number_constrains_address_at_maxwidth_24(self):
     parser = AddressParser()
     parser.maxwidth = 24
     parser.labels = {'foo': 0xFFFFFF}
     self.assertRaises(OverflowError, parser.number, 'foo+5')
コード例 #12
0
ファイル: test_assembler.py プロジェクト: larsks/nice65
 def assemble(self, statement, pc=0000, mpu=None):
     if mpu is None:
         mpu = MPU()
     address_parser = AddressParser()
     assembler = Assembler(mpu, address_parser)
     return assembler.assemble(statement, pc)
コード例 #13
0
 def test_maxwidth_defaults_to_16_bits(self):
     parser = AddressParser()
     self.assertEqual(16, parser.maxwidth)
     self.assertEqual(0xFFFF, parser._maxaddr)
コード例 #14
0
 def test_number_label(self):
     parser = AddressParser()
     parser.labels = {'foo': 0xC000}
     self.assertEqual(0xC000, parser.number('foo'))
コード例 #15
0
 def test_range_one_number(self):
     parser = AddressParser(labels={})
     self.assertEqual((0xFFD2, 0xFFD2), parser.range('ffd2'))
コード例 #16
0
 def test_label_for_returns_alternate_default(self):
     parser = AddressParser(labels={})
     self.assertEqual('foo', parser.label_for(0xFFD2, 'foo'))
コード例 #17
0
 def test_label_for_returns_none_by_default(self):
     parser = AddressParser(labels={})
     self.assertEqual(None, parser.label_for(0xFFD2))
コード例 #18
0
 def test_label_for_returns_label(self):
     parser = AddressParser(labels={'chrout': 0xFFD2})
     self.assertEqual('chrout', parser.label_for(0xFFD2))
コード例 #19
0
 def test_adderss_for_returns_alternate_default(self):
     parser = AddressParser(labels={})
     self.assertEqual('foo', parser.address_for('chrout', 'foo'))
コード例 #20
0
 def test_address_for_returns_none_by_default(self):
     parser = AddressParser(labels={})
     self.assertEqual(None, parser.address_for('chrout'))
コード例 #21
0
 def test_address_for_returns_address(self):
     parser = AddressParser(labels={'chrout': 0xFFD2})
     self.assertEqual(0xFFD2, parser.address_for('chrout'))
コード例 #22
0
 def test_number_bin_literal(self):
     parser = AddressParser()
     self.assertEqual(129, parser.number('%10000001'))
コード例 #23
0
 def test_number_default_radix(self):
     parser = AddressParser()
     parser.radix = 10
     self.assertEqual(10, parser.number('10'))
     parser.radix = 16
     self.assertEqual(16, parser.number('10'))
コード例 #24
0
 def test_range_one_label(self):
     parser = AddressParser(labels={'chrout': 0xFFD2})
     self.assertEqual((0xFFD2, 0xFFD2), parser.range('chrout'))
コード例 #25
0
 def test_maxwidth_can_be_set_in_constructor(self):
     parser = AddressParser(maxwidth=24)
     self.assertEqual(24, parser.maxwidth)
     self.assertEqual(0xFFFFFF, parser._maxaddr)
コード例 #26
0
 def test_range_two_numbers(self):
     parser = AddressParser(labels={})
     self.assertEqual((0xFFD2, 0xFFD4), parser.range('ffd2:ffd4'))
コード例 #27
0
ファイル: test_assembler.py プロジェクト: larsks/nice65
 def test_ctor_uses_provided_mpu_and_address_parser(self):
     mpu = MPU()
     address_parser = AddressParser()
     asm = Assembler(mpu, address_parser)
     self.assertTrue(asm._mpu is mpu)
     self.assertTrue(asm._address_parser is address_parser)
コード例 #28
0
 def test_range_mixed(self):
     parser = AddressParser(labels={'chrout': 0xFFD2})
     self.assertEqual((0xFFD2, 0xFFD4), parser.range('chrout:ffd4'))
コード例 #29
0
 def test_maxwidth_setter(self):
     parser = AddressParser()
     parser.maxwidth = 24
     self.assertEqual(24, parser.maxwidth)
     self.assertEqual(0xFFFFFF, parser._maxaddr)
コード例 #30
0
 def test_number_constrains_address_at_zero_or_above(self):
     parser = AddressParser()
     self.assertRaises(OverflowError, parser.number, '-1')