package com.rox.emu.p6502;

import com.rox.emu.UnknownOpCodeException;
import com.rox.emu.p6502.op.AddressingMode;
import com.rox.emu.p6502.op.OpCode;
import org.junit.Test;

import static com.rox.emu.p6502.op.OpCode.OP_ADC_I;
import static com.rox.emu.p6502.op.OpCode.OP_SEC;
import static org.junit.Assert.*;

/**
 * # - Memory
 * $ - Value
 *
 *  #$V               - Immediate
 *  $V / $ VV         - Zero Page
 *  $V,X / $VV,X      - Zero Page[X]
 *  $V,Y / $VV,Y      - Zero Page[Y]
 *  $VVV / $VVVV      - Absolute
 *  $VVV,X / $VVVV,X  - Absolute[X]
 *  $VVV,Y / $VVVV,Y  - Absolute[Y]
 *  ($V,X) / ($VV,X)  - Indirect, X
 *  ($V),Y / ($VV),Y  - Indirect, Y
 *
 *  | $[ V_Z | V_ABS ] ]
 */
public class CompilerTest {
    @Test
    public void testImpliedInstruction(){
        for (OpCode opcode : OpCode.values()){
            if (opcode.getAddressingMode() == AddressingMode.IMPLIED){
                Compiler compiler = new Compiler(opcode.getOpCodeName());

                int[] bytes = compiler.getBytes();

                assertEquals("Wrong byte value for " + opcode.getOpCodeName() + "(" + opcode.getByteValue() + ")", opcode.getByteValue(), bytes[0]);
            }
        }
    }

    @Test
    public void testImmediateInstruction(){
        for (OpCode opcode : OpCode.values()){
            if (opcode.getAddressingMode() == AddressingMode.IMMEDIATE){
                Compiler compiler = new Compiler(opcode.getOpCodeName() + " " + "#$10");

                int[] bytes = compiler.getBytes();

                assertArrayEquals(new int[] {opcode.getByteValue(), 10}, bytes);
            }
        }

//        Compiler compiler = new Compiler(OP_ADC_I.getOpCodeName() + " " + "#$10");
//
//        int[] bytes = compiler.getBytes();
//
//        assertArrayEquals(new int[] {OP_ADC_I.getByteValue(), 10}, bytes);
    }

    @Test
    public void firstInvalidOpcode(){
        Compiler compiler = new Compiler("ROX");

        try {
            compiler.getBytes();
            fail("Exception expected, 'ROX' is an invalid OpCode");
        }catch(UnknownOpCodeException e){
            assertNotNull(e);
        }
    }
}

@@ -758,36 +758,37 @@
 pliedInstruction
+s
 ()%7B%0A
-
         for (OpC
@@ -1246,16 +1246,17 @@
 truction
+s
 ()%7B%0A    
@@ -1600,32 +1600,32 @@
 ;%0A            %7D%0A
+
         %7D%0A%0A//   
@@ -1621,222 +1621,8 @@
    %7D
-%0A%0A//        Compiler compiler = new Compiler(OP_ADC_I.getOpCodeName() + %22 %22 + %22#$10%22);%0A//%0A//        int%5B%5D bytes = compiler.getBytes();%0A//%0A//        assertArrayEquals(new int%5B%5D %7BOP_ADC_I.getByteValue(), 10%7D, bytes);
 %0A   

Test cleanup