Ejemplo n.º 1
0
 def test_nop_sngl(self):
     tokens = lexical('NOP')
     self.assertEquals(1 , len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_IMPLIED', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xea])
Ejemplo n.º 2
0
 def test_org_fffa(self):
     tokens = lexical('.org $FFFA')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_DIRECTIVE', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_DIRECTIVE', ast[0]['type'])
     code = semantic(ast)
Ejemplo n.º 3
0
 def test_asm_compiler_scrolling_5(self):
     cart = Cartridge()
     cart.path = "fixtures/nesasm/scrolling/"
     f = open("fixtures/nesasm/scrolling/scrolling5.asm")
     code = f.read()
     f.close()
     tokens = lexical(code)
     ast = syntax(tokens)
     opcodes = semantic(ast, cart=cart)
Ejemplo n.º 4
0
 def test_rts_sngl(self):
     tokens = lexical("RTS")
     self.assertEquals(1, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_IMPLIED", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x60])
Ejemplo n.º 5
0
 def test_sei_sngl(self):
     tokens = list(lexical("SEI"))
     self.assertEquals(1, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_IMPLIED", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x78])
Ejemplo n.º 6
0
 def test_sed_sngl(self):
     tokens = list(lexical('SED'))
     self.assertEquals(1, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMPLIED', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xf8])
Ejemplo n.º 7
0
 def test_cli_sngl(self):
     tokens = list(lexical('CLI'))
     self.assertEquals(1, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMPLIED', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x58])
Ejemplo n.º 8
0
 def test_bank_0(self):
     tokens = lexical('.bank 0')
     self.assertEquals(2 , len(tokens))
     self.assertEquals('T_DIRECTIVE', tokens[0]['type'])
     self.assertEquals('T_DECIMAL_ARGUMENT', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_DIRECTIVE', ast[0]['type'])
     code = semantic(ast)
Ejemplo n.º 9
0
 def test_org_fffa(self):
     tokens = lexical('.org $FFFA')
     self.assertEquals(2 , len(tokens))
     self.assertEquals('T_DIRECTIVE', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_DIRECTIVE', ast[0]['type'])
     code = semantic(ast)
Ejemplo n.º 10
0
 def test_bank_0(self):
     tokens = lexical('.bank 0')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_DIRECTIVE', tokens[0]['type'])
     self.assertEquals('T_DECIMAL_ARGUMENT', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_DIRECTIVE', ast[0]['type'])
     code = semantic(ast)
Ejemplo n.º 11
0
 def test_bne_rel(self):
     tokens = lexical("BNE $10")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_ADDRESS", tokens[1]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_RELATIVE", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0xD0, 0x0E])
Ejemplo n.º 12
0
 def test_lsr_imm_with_binary(self):
     tokens = lexical("LSR #%00000100")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_BINARY_NUMBER", tokens[1]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_IMMEDIATE", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x4A, 0x04])
Ejemplo n.º 13
0
 def test_lsr_imm_with_decimal(self):
     tokens = lexical("LSR #10")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_DECIMAL_NUMBER", tokens[1]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_IMMEDIATE", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x4A, 0x0A])
Ejemplo n.º 14
0
 def test_lsr_acc(self):
     tokens = lexical("LSR A")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_ACCUMULATOR", tokens[1]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_ACCUMULATOR", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x4A])
Ejemplo n.º 15
0
 def test_bpl_rel(self):
     tokens = lexical('BPL $10')
     self.assertEquals(2 , len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_RELATIVE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x10, 0x0e])
Ejemplo n.º 16
0
 def test_sbc_imm(self):
     tokens = lexical("SBC #$10")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_HEX_NUMBER", tokens[1]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_IMMEDIATE", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0xE9, 0x10])
Ejemplo n.º 17
0
 def test_asl_imm(self):
     tokens = lexical('ASL #$10')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_HEX_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMMEDIATE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x0a, 0x10])
Ejemplo n.º 18
0
 def test_cmp_imm(self):
     tokens = list(lexical('CMP #$10'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_HEX_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMMEDIATE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xc9, 0x10])
Ejemplo n.º 19
0
 def test_lsr_acc(self):
     tokens = list(lexical('LSR A'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ACCUMULATOR', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ACCUMULATOR', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x4a])
Ejemplo n.º 20
0
 def test_ldy_imm_with_binary(self):
     tokens = list(lexical('LDY #%00000100'))
     self.assertEquals(2 , len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_BINARY_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_IMMEDIATE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xa0, 0x04])
Ejemplo n.º 21
0
 def test_ora_imm_with_binary(self):
     tokens = lexical('ORA #%00000100')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_BINARY_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMMEDIATE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x09, 0x04])
Ejemplo n.º 22
0
 def test_ora_imm_with_decimal(self):
     tokens = lexical('ORA #10')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_DECIMAL_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMMEDIATE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x09, 0x0a])
Ejemplo n.º 23
0
 def test_sty_zp(self):
     tokens = list(lexical('STY $00'))
     self.assertEquals(2 , len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_ZEROPAGE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x84, 0x00])
Ejemplo n.º 24
0
 def test_ora_zp(self):
     tokens = lexical('ORA $00')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ZEROPAGE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x05, 0x00])
Ejemplo n.º 25
0
 def test_ldy_abs(self):
     tokens = lexical('LDY $1234')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ABSOLUTE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xac, 0x34, 0x12])
Ejemplo n.º 26
0
 def test_beq_rel(self):
     tokens = lexical('BEQ $10')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_RELATIVE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xf0, 0x0e])
Ejemplo n.º 27
0
 def test_ldy_imm_with_decimal(self):
     tokens = list(lexical('LDY #10'))
     self.assertEquals(2 , len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_DECIMAL_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_IMMEDIATE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xa0, 0x0a])
Ejemplo n.º 28
0
 def test_bit_zp(self):
     tokens = lexical("BIT $00")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_ADDRESS", tokens[1]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_ZEROPAGE", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x24, 0x00])
Ejemplo n.º 29
0
 def test_ldy_abs(self):
     tokens = list(lexical('LDY $1234'))
     self.assertEquals(2 , len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_ABSOLUTE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xac, 0x34, 0x12])
Ejemplo n.º 30
0
 def test_lsr_acc(self):
     tokens = lexical('LSR A')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ACCUMULATOR', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ACCUMULATOR', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x4a])
Ejemplo n.º 31
0
 def test_inesmir(self):
     tokens = list(lexical('.inesmir 1'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_DIRECTIVE', tokens[0]['type'])
     self.assertEquals('T_DECIMAL_ARGUMENT', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_DIRECTIVE', ast[0]['type'])
     code = semantic(ast, True)
     # self.assertEquals(1, get_var('inesmir'))
     self.assertEquals(code[7], 1)
Ejemplo n.º 32
0
 def test_jmp_abs(self):
     tokens = lexical('JMP $1234')
     self.assertEquals(2 , len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     self.assertEquals('$1234', tokens[1]['value'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_ABSOLUTE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x4c, 0x34, 0x12])
Ejemplo n.º 33
0
 def test_jsr_abs(self):
     tokens = list(lexical('JSR $1234'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     self.assertEquals('$1234', tokens[1]['value'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ABSOLUTE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x20, 0x34, 0x12])
Ejemplo n.º 34
0
 def test_inesmir(self):
     tokens = lexical('.inesmir 1')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_DIRECTIVE', tokens[0]['type'])
     self.assertEquals('T_DECIMAL_ARGUMENT', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_DIRECTIVE', ast[0]['type'])
     code = semantic(ast, True)
     #self.assertEquals(1, get_var('inesmir'))
     self.assertEquals(code[7], 1)
Ejemplo n.º 35
0
 def test_bit_abs(self):
     tokens = lexical("BIT $1234")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_ADDRESS", tokens[1]["type"])
     self.assertEquals("$1234", tokens[1]["value"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_ABSOLUTE", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x2C, 0x34, 0x12])
Ejemplo n.º 36
0
 def test_db_3(self):
     tokens = lexical('.db $80, $00, $03, $80')
     self.assertEquals(8, len(tokens))
     self.assertEquals('T_DIRECTIVE', tokens[0]['type'])
     #self.assertEquals('T_HEX_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_DIRECTIVE', ast[0]['type'])
     code = semantic(ast)
     self.assertIsNotNone(code)
     expected = [0x80, 0x0, 0x03, 0x80]
     self.assertEquals(expected, code)
Ejemplo n.º 37
0
 def test_ldy_absx(self):
     tokens = list(lexical('LDY $1234,X'))
     self.assertEquals(4, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     self.assertEquals('T_SEPARATOR', tokens[2]['type'])
     self.assertEquals('T_REGISTER', tokens[3]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ABSOLUTE_X', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xbc, 0x34, 0x12])
Ejemplo n.º 38
0
 def test_lda_absx(self):
     tokens = lexical('LDA $1234,X')
     self.assertEquals(4 , len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     self.assertEquals('T_SEPARATOR', tokens[2]['type'])
     self.assertEquals('T_REGISTER', tokens[3]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_ABSOLUTE_X', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xbd, 0x34, 0x12])
Ejemplo n.º 39
0
 def test_db_3(self):
     tokens = list(lexical('.db $80, $00, $03, $80'))
     self.assertEquals(8, len(tokens))
     self.assertEquals('T_DIRECTIVE', tokens[0]['type'])
     # self.assertEquals('T_HEX_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_DIRECTIVE', ast[0]['type'])
     code = semantic(ast)
     self.assertIsNotNone(code)
     expected = [0x80, 0x0, 0x03, 0x80]
     self.assertEquals(expected, code)
Ejemplo n.º 40
0
    def test_asm_compiler(self):
        cart = Cartridge()
        cart.path = 'fixtures/movingsprite/'

        opcodes = semantic(self.ast, True, cart=cart)

        self.assertIsNotNone(opcodes)
        bin = ''.join([chr(opcode) for opcode in opcodes])
        f = open('fixtures/movingsprite/movingsprite.nes', 'rb')
        content = f.read()
        f.close()
        self.assertHexEquals(content, bin)
Ejemplo n.º 41
0
    def test_asm_compiler(self):
        cart = Cartridge()
        cart.path = 'fixtures/movingsprite/'

        opcodes = semantic(self.ast, True, cart=cart)

        self.assertIsNotNone(opcodes)
        bin = ''.join([chr(opcode) for opcode in opcodes])
        f = open('fixtures/movingsprite/movingsprite.nes', 'rb')
        content = f.read()
        f.close()
        self.assertHexEquals(content, bin)
Ejemplo n.º 42
0
 def test_inc_zpx(self):
     tokens = list(lexical("INC $10,X"))
     self.assertEquals(4, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_ADDRESS", tokens[1]["type"])
     self.assertEquals("T_SEPARATOR", tokens[2]["type"])
     self.assertEquals("T_REGISTER", tokens[3]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_ZEROPAGE_X", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0xF6, 0x10])
Ejemplo n.º 43
0
 def test_sbc_absy(self):
     tokens = lexical("SBC $1234,Y")
     self.assertEquals(4, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_ADDRESS", tokens[1]["type"])
     self.assertEquals("T_SEPARATOR", tokens[2]["type"])
     self.assertEquals("T_REGISTER", tokens[3]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_ABSOLUTE_Y", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0xF9, 0x34, 0x12])
Ejemplo n.º 44
0
 def test_stx_zpy(self):
     tokens = list(lexical('STX $10,Y'))
     self.assertEquals(4, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     self.assertEquals('T_SEPARATOR', tokens[2]['type'])
     self.assertEquals('T_REGISTER', tokens[3]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ZEROPAGE_Y', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x96, 0x10])
Ejemplo n.º 45
0
 def test_and_absy(self):
     tokens = list(lexical('AND $1234,Y'))
     self.assertEquals(4 , len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     self.assertEquals('T_SEPARATOR', tokens[2]['type'])
     self.assertEquals('T_REGISTER', tokens[3]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_ABSOLUTE_Y', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x39, 0x34, 0x12])
Ejemplo n.º 46
0
 def test_ora_zpx(self):
     tokens = lexical('ORA $10,X')
     self.assertEquals(4, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     self.assertEquals('T_SEPARATOR', tokens[2]['type'])
     self.assertEquals('T_REGISTER', tokens[3]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ZEROPAGE_X', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x15, 0x10])
Ejemplo n.º 47
0
 def test_ora_absy(self):
     tokens = lexical('ORA $1234,Y')
     self.assertEquals(4, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     self.assertEquals('T_SEPARATOR', tokens[2]['type'])
     self.assertEquals('T_REGISTER', tokens[3]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ABSOLUTE_Y', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x19, 0x34, 0x12])
Ejemplo n.º 48
0
 def test_ldy_zpx(self):
     tokens = list(lexical('LDY $10,X'))
     self.assertEquals(4 , len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     self.assertEquals('T_SEPARATOR', tokens[2]['type'])
     self.assertEquals('T_REGISTER', tokens[3]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_ZEROPAGE_X', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xb4, 0x10])
Ejemplo n.º 49
0
 def test_inc_absx(self):
     tokens = list(lexical("INC $1234,X"))
     self.assertEquals(4, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_ADDRESS", tokens[1]["type"])
     self.assertEquals("$1234", tokens[1]["value"])
     self.assertEquals("T_SEPARATOR", tokens[2]["type"])
     self.assertEquals("T_REGISTER", tokens[3]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_ABSOLUTE_X", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0xFE, 0x34, 0x12])
Ejemplo n.º 50
0
 def test_and_imm(self):
     '''
     Test the logical operation AND between $10(Decimal 16)
     and the content of the Accumulator
     '''
     tokens = lexical('AND #$10')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_HEX_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMMEDIATE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x29, 0x10])
Ejemplo n.º 51
0
 def test_and_imm_with_binary(self):
     '''
     Test the logical operation AND between #%00000100 (Decimal 4)
     and the content of the Accumulator
     '''
     tokens = lexical('AND #%00000100')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_BINARY_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMMEDIATE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x29, 0x04])
Ejemplo n.º 52
0
 def test_adc_imm_with_decimal(self):
     '''
     Test the arithmetic operation ADC between decimal 10
     and the content of the accumulator.
     '''
     tokens = list(lexical('ADC #10'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_DECIMAL_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMMEDIATE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x69, 0x0A])
Ejemplo n.º 53
0
 def test_and_zp(self):
     '''
     Test the logical operation AND between the content of
     accumulator and the content of zero page address $00
     '''
     tokens = lexical('AND $00')
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ZEROPAGE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x25, 0x00])
Ejemplo n.º 54
0
 def test_adc_imm_with_binary(self):
     '''
     Test the arithmetic operation ADC between binary %00000100
     (Decimal 4) and the content of the accumulator.
     '''
     tokens = list(lexical('ADC #%00000100'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_BINARY_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMMEDIATE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x69, 0x04])
Ejemplo n.º 55
0
 def test_adc_zp(self):
     '''
     Test the arithmetic operation ADC between the content of
     the accumulator and the content of the zero page address.
     '''
     tokens = list(lexical('ADC $00'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ZEROPAGE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x65, 0x00])
Ejemplo n.º 56
0
 def test_ora_indy(self):
     tokens = lexical('ORA ($20),Y')
     self.assertEquals(6, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_OPEN', tokens[1]['type'])
     self.assertEquals('T_ADDRESS', tokens[2]['type'])
     self.assertEquals('T_CLOSE', tokens[3]['type'])
     self.assertEquals('T_SEPARATOR', tokens[4]['type'])
     self.assertEquals('T_REGISTER', tokens[5]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_INDIRECT_Y', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x11, 0x20])
Ejemplo n.º 57
0
 def test_sta_absx(self):
     tokens = lexical('STA $1234,X')
     self.assertEquals(4 , len(tokens))
     token = tokens[0]
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     self.assertEquals('$1234', tokens[1]['value'])
     self.assertEquals('T_SEPARATOR', tokens[2]['type'])
     self.assertEquals('T_REGISTER', tokens[3]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_ABSOLUTE_X', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x9D, 0x34, 0x12])
Ejemplo n.º 58
0
    def test_jsr_abs(self):
        tokens = lexical('JSR $1234')
        self.assertEquals(2, len(tokens))
        self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
        self.assertEquals('T_ADDRESS', tokens[1]['type'])
        self.assertEquals('$1234', tokens[1]['value'])
        ast = syntax(tokens)
        self.assertEquals(1, len(ast))
        self.assertEquals('S_ABSOLUTE', ast[0]['type'])
        code = semantic(ast)
        self.assertEquals(code, [0x20, 0x34, 0x12])


#TODO: http://www.6502.buss.hk/6502-instruction-set/jmp says that there is a indirect
Ejemplo n.º 59
0
 def test_adc_abs(self):
     '''
     Test the arithmetic operation ADC between the content of
     the accumulator and the content located at address $1234.
     '''
     tokens = list(lexical('ADC $1234'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     self.assertEquals('$1234', tokens[1]['value'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ABSOLUTE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x6d, 0x34, 0x12])
Ejemplo n.º 60
0
 def test_eor_indx(self):
     tokens = list(lexical('EOR ($20,X)'))
     self.assertEquals(6, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_OPEN', tokens[1]['type'])
     self.assertEquals('T_ADDRESS', tokens[2]['type'])
     self.assertEquals('$20', tokens[2]['value'])
     self.assertEquals('T_SEPARATOR', tokens[3]['type'])
     self.assertEquals('T_REGISTER', tokens[4]['type'])
     self.assertEquals('T_CLOSE', tokens[5]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_INDIRECT_X', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x41, 0x20])