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])
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)
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)
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])
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])
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])
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])
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)
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)
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)
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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)
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])
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])
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)
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])
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)
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])
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])
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)
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)
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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
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])
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])