コード例 #1
0
ファイル: movingsprite_test.py プロジェクト: yxda/pyNES
 def __init__(self, testname):
     HexTestCase.__init__(self, testname)
     f = open('fixtures/movingsprite/movingsprite.asm')
     code = f.read()
     f.close()
     tokens = lexical(code)
     self.ast = syntax(tokens)
コード例 #2
0
ファイル: compiler_test.py プロジェクト: joskid/pyNES
    def test_compile_list(self):
        code = '''
            palette:
              .db $0F,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$0C,$0D,$0E,$0F
              .db $0F,$30,$31,$32,$33,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$0F
        '''
        tokens = lexical(code)
        ast = syntax(tokens)
        self.assertEquals(2, len(ast))

        self.assertEquals('S_DIRECTIVE', ast[0]['type'])
        self.assertEquals('.db', ast[0]['children'][0]['value'])
        self.assertEquals( 32, len(ast[0]['children']))
        palette1 = [0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
            0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
        for i in range(len(palette1)):
            h = '$%02X' % palette1[i]
            self.assertEquals(h, ast[0]['children'][i * 2 + 1]['value'])
            self.assertEquals('S_DIRECTIVE', ast[1]['type'])

        self.assertEquals('S_DIRECTIVE', ast[1]['type'])
        self.assertEquals('.db', ast[0]['children'][0]['value'])
        self.assertEquals( 32, len(ast[1]['children']))
        palette2 = [0x0f, 0x30, 0x31, 0x32, 0x33, 0x35, 0x36, 0x37, 0x38, 0x39,
            0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x0f]
        for i in range(len(palette2)):
            h = '$%02X' % palette2[i]
            self.assertEquals(h, ast[1]['children'][i * 2 + 1]['value'])
コード例 #3
0
ファイル: movingsprite_test.py プロジェクト: BmanisKing/Mine
 def __init__(self, testname):
     HexTestCase.__init__(self, testname)
     f = open('fixtures/movingsprite/movingsprite.asm')
     code = f.read()
     f.close()
     tokens = lexical(code)
     self.ast = syntax(tokens)
コード例 #4
0
ファイル: compiler_test.py プロジェクト: joskid/pyNES
    def test_several_lists_with_labels(self):
        code = '''
            .org $E000

            palette:
              .db $0F,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$0C,$0D,$0E,$0F
              .db $0F,$30,$31,$32,$33,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$0F

            sprites:
              .db $80, $00, $03, $80; Y pos, tile id, attributes, X pos
              '''

        tokens = lexical(code)
        ast = syntax(tokens)
        self.assertEquals(4, len(ast))
        self.assertEquals('S_DIRECTIVE', ast[0]['type'])
        self.assertEquals('.org', ast[0]['children'][0]['value'])
        self.assertEquals('S_DIRECTIVE', ast[1]['type'])
        self.assertEquals('.db', ast[1]['children'][0]['value'])
        self.assertEquals(['palette'], ast[1]['labels'])

        self.assertEquals('S_DIRECTIVE', ast[2]['type'])
        self.assertEquals('.db', ast[2]['children'][0]['value'])

        self.assertEquals('S_DIRECTIVE', ast[3]['type'])
        self.assertEquals('.db', ast[3]['children'][0]['value'])
        self.assertEquals(['sprites'], ast[3]['labels'])

        labels = get_labels(ast)
        expected = {'palette': 0xE000, 'sprites': 0xE000 + 32}

        self.assertEquals(expected, labels)
コード例 #5
0
 def test_org_fffa(self):
     tokens = list(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'])
コード例 #6
0
ファイル: scrolling_test.py プロジェクト: gabriel-ozeas/pyNES
 def test_ines_functions(self):
     example = """
         .inesprg 1   ; 1x 16KB PRG code
         .ineschr 1   ; 1x  8KB CHR data
         .inesmap 0   ; mapper 0 = NROM, no bank swapping
         .inesmir 1   ; VERT mirroring for HORIZ scrolling
         """
     tokens = lexical(example)
コード例 #7
0
ファイル: directive_test.py プロジェクト: BmanisKing/Mine
 def test_bank_0(self):
     tokens = list(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'])
コード例 #8
0
 def test_bank_0(self):
     tokens = list(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'])
コード例 #9
0
ファイル: directive_test.py プロジェクト: BmanisKing/Mine
 def test_org_fffa(self):
     tokens = list(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'])
コード例 #10
0
ファイル: guide_test.py プロジェクト: acs022/pyNES
    def test_example_5_14(self):
        example_5_14 = '''
        ; Example 5-14.  Simple 16-bit square root.
        ;
        ; Returns the 8-bit square root in $20 of the
        ; 16-bit number in $20 (low) and $21 (high). The
        ; remainder is in location $21.

        sqrt16: LDY #$01     ; lsby of first odd number = 1
                STY $22
                DEY
                STY $23      ; msby of first odd number (sqrt = 0)
        again:  SEC
                LDA $20      ; save remainder in X register
                TAX          ; subtract odd lo from integer lo
                SBC $22
                STA $20
                LDA $21      ; subtract odd hi from integer hi
                SBC $23
                STA $21      ; is subtract result negative?
                BCC nomore   ; no. increment square root
                INY
                LDA $22      ; calculate next odd number
                ADC #$01
                STA $22
                BCC again
                INC $23
                JMP again
        nomore: STY $20      ; all done, store square root
                STX $21      ; and remainder
                RTS
        '''
        tokens = lexical(example_5_14)
        self.assertEquals(74, len(tokens))
        
        self.assertEquals('T_ENDLINE', tokens[0]['type'])
        self.assertEquals('T_ENDLINE', tokens[1]['type'])
        self.assertEquals('T_ENDLINE', tokens[2]['type'])
        self.assertEquals('T_ENDLINE', tokens[3]['type'])
        self.assertEquals('T_ENDLINE', tokens[4]['type'])
        self.assertEquals('T_ENDLINE', tokens[5]['type'])
        self.assertEquals('T_ENDLINE', tokens[6]['type'])

        self.assertEquals('T_LABEL', tokens[7]['type'])
        self.assertEquals('T_INSTRUCTION', tokens[8]['type'])
        self.assertEquals('T_HEX_NUMBER', tokens[9]['type'])
        self.assertEquals('T_ENDLINE', tokens[10]['type'])

        self.assertEquals('T_INSTRUCTION', tokens[11]['type'])
        self.assertEquals('T_ADDRESS', tokens[12]['type'])
        self.assertEquals('T_ENDLINE', tokens[13]['type'])

        self.assertEquals('T_INSTRUCTION', tokens[14]['type'])
        self.assertEquals('T_ENDLINE', tokens[15]['type'])

        self.assertEquals('T_INSTRUCTION', tokens[16]['type'])
        self.assertEquals('T_ADDRESS', tokens[17]['type'])
        self.assertEquals('T_ENDLINE', tokens[18]['type'])
コード例 #11
0
    def test_example_5_14(self):
        example_5_14 = '''
        ; Example 5-14.  Simple 16-bit square root.
        ;
        ; Returns the 8-bit square root in $20 of the
        ; 16-bit number in $20 (low) and $21 (high). The
        ; remainder is in location $21.

        sqrt16: LDY #$01     ; lsby of first odd number = 1
                STY $22
                DEY
                STY $23      ; msby of first odd number (sqrt = 0)
        again:  SEC
                LDA $20      ; save remainder in X register
                TAX          ; subtract odd lo from integer lo
                SBC $22
                STA $20
                LDA $21      ; subtract odd hi from integer hi
                SBC $23
                STA $21      ; is subtract result negative?
                BCC nomore   ; no. increment square root
                INY
                LDA $22      ; calculate next odd number
                ADC #$01
                STA $22
                BCC again
                INC $23
                JMP again
        nomore: STY $20      ; all done, store square root
                STX $21      ; and remainder
                RTS
        '''
        tokens = list(lexical(example_5_14))
        self.assertEquals(74, len(tokens))

        self.assertEquals('T_ENDLINE', tokens[0]['type'])
        self.assertEquals('T_ENDLINE', tokens[1]['type'])
        self.assertEquals('T_ENDLINE', tokens[2]['type'])
        self.assertEquals('T_ENDLINE', tokens[3]['type'])
        self.assertEquals('T_ENDLINE', tokens[4]['type'])
        self.assertEquals('T_ENDLINE', tokens[5]['type'])
        self.assertEquals('T_ENDLINE', tokens[6]['type'])

        self.assertEquals('T_LABEL', tokens[7]['type'])
        self.assertEquals('T_INSTRUCTION', tokens[8]['type'])
        self.assertEquals('T_HEX_NUMBER', tokens[9]['type'])
        self.assertEquals('T_ENDLINE', tokens[10]['type'])

        self.assertEquals('T_INSTRUCTION', tokens[11]['type'])
        self.assertEquals('T_ADDRESS', tokens[12]['type'])
        self.assertEquals('T_ENDLINE', tokens[13]['type'])

        self.assertEquals('T_INSTRUCTION', tokens[14]['type'])
        self.assertEquals('T_ENDLINE', tokens[15]['type'])

        self.assertEquals('T_INSTRUCTION', tokens[16]['type'])
        self.assertEquals('T_ADDRESS', tokens[17]['type'])
        self.assertEquals('T_ENDLINE', tokens[18]['type'])
コード例 #12
0
ファイル: cli_test.py プロジェクト: yxda/pyNES
 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])
コード例 #13
0
ファイル: scrolling_test.py プロジェクト: gabriel-ozeas/pyNES
 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)
コード例 #14
0
ファイル: sed_test.py プロジェクト: BmanisKing/Mine
 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])
コード例 #15
0
ファイル: directive_test.py プロジェクト: joskid/pyNES
 def test_org_c000(self):
     tokens = lexical('.org $C000')
     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)
コード例 #16
0
ファイル: rts_test.py プロジェクト: ickybodclay/pyNES
 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])
コード例 #17
0
ファイル: directive_test.py プロジェクト: acs022/pyNES
 def test_org_c000(self):
     tokens = lexical('.org $C000')
     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)
コード例 #18
0
ファイル: sei_test.py プロジェクト: BmanisKing/Mine
 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])
コード例 #19
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])
コード例 #20
0
ファイル: lsr_test.py プロジェクト: ickybodclay/pyNES
 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])
コード例 #21
0
ファイル: beq_test.py プロジェクト: joskid/pyNES
 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])
コード例 #22
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])
コード例 #23
0
ファイル: lsr_test.py プロジェクト: ickybodclay/pyNES
 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])
コード例 #24
0
ファイル: bne_test.py プロジェクト: ickybodclay/pyNES
 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])
コード例 #25
0
ファイル: bpl_test.py プロジェクト: acs022/pyNES
 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])
コード例 #26
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])
コード例 #27
0
ファイル: lsr_test.py プロジェクト: ickybodclay/pyNES
 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])
コード例 #28
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])
コード例 #29
0
ファイル: sty_test.py プロジェクト: ebennaga/pyNES
 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])
コード例 #30
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])
コード例 #31
0
ファイル: bit_test.py プロジェクト: ickybodclay/pyNES
 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])
コード例 #32
0
ファイル: ldy_test.py プロジェクト: ebennaga/pyNES
 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])
コード例 #33
0
ファイル: lsr_test.py プロジェクト: BmanisKing/Mine
 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])
コード例 #34
0
ファイル: sbc_test.py プロジェクト: ickybodclay/pyNES
 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])
コード例 #35
0
ファイル: ldy_test.py プロジェクト: ebennaga/pyNES
 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])
コード例 #36
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])
コード例 #37
0
ファイル: cmp_test.py プロジェクト: BmanisKing/Mine
 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])
コード例 #38
0
ファイル: lsr_test.py プロジェクト: joskid/pyNES
 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])
コード例 #39
0
ファイル: ldy_test.py プロジェクト: ebennaga/pyNES
 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])
コード例 #40
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])
コード例 #41
0
ファイル: directive_test.py プロジェクト: joskid/pyNES
 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)
コード例 #42
0
ファイル: bit_test.py プロジェクト: ickybodclay/pyNES
 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])
コード例 #43
0
ファイル: directive_test.py プロジェクト: BmanisKing/Mine
 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)
コード例 #44
0
ファイル: jmp_test.py プロジェクト: acs022/pyNES
 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])
コード例 #45
0
ファイル: and_test.py プロジェクト: ebennaga/pyNES
 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])
コード例 #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])
コード例 #47
0
ファイル: ldy_test.py プロジェクト: yxda/pyNES
 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])
コード例 #48
0
ファイル: stx_test.py プロジェクト: yxda/pyNES
 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])
コード例 #49
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])
コード例 #50
0
ファイル: directive_test.py プロジェクト: joskid/pyNES
 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)
コード例 #51
0
ファイル: ldy_test.py プロジェクト: ebennaga/pyNES
 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])
コード例 #52
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])
コード例 #53
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
コード例 #54
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])
コード例 #55
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])
コード例 #56
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])
コード例 #57
0
ファイル: compiler_test.py プロジェクト: joskid/pyNES
 def test_compile_decimal(self):
     code = '''
         LDA #128
         STA $0203
     '''
     tokens = lexical(code)
     self.assertEquals(7, len(tokens))
     self.assertEquals('T_ENDLINE', tokens[0]['type'])
     self.assertEquals('T_INSTRUCTION', tokens[1]['type'])
     self.assertEquals('T_DECIMAL_NUMBER', tokens[2]['type'])
     self.assertEquals('T_ENDLINE', tokens[3]['type'])
     self.assertEquals('T_INSTRUCTION', tokens[4]['type'])
     self.assertEquals('T_ADDRESS', tokens[5]['type'])
     self.assertEquals('T_ENDLINE', tokens[6]['type'])
コード例 #58
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])