I've written the larger part of an emulator for a 6502 CPU but my method of op-code decoding is giving me concern, mainly because of how long the method is getting but also because I need a variable for each code, I need to declare them three times and I've stuck them all in a very non-OO class.  I wouldn't mind some scathing critique.I've written it in a TDD fashion (in an effort to understand pure TDD) which has led to the simplest implementation with refactors only when necessary.  Even though I think this is probably the most efficient solution (making full use of the benefits of a switch statement), I'm thinking there's maybe a better way. Extract:-public void step() {    System.out.println(\n*** STEP >>>);    int accumulatorBeforeOperation = registers.getRegister(Registers.REG_ACCUMULATOR);    int opCode = nextProgramByte();    //Execute the opcode    System.out.println(Instruction:  + InstructionSet.getOpCodeName(opCode) + ...);    switch (opCode){        case InstructionSet.OP_ASL_A: {            int newFakeByte = registers.getRegister(Registers.REG_ACCUMULATOR) << 1;            setCarryFlagBasedOn(newFakeByte);            registers.setRegisterAndFlags(Registers.REG_ACCUMULATOR, newFakeByte);        }        break;        case InstructionSet.OP_ASL_Z: {            int location = nextProgramByte();            int newFakeByte = memory.getByte(location) << 1;            setCarryFlagBasedOn(newFakeByte);            registers.setFlagsBasedOn(newFakeByte);            memory.setByteAt(location, newFakeByte);        }        break;        ...        case InstructionSet.OP_DEY:            registers.decrementRegisterWithFlags(Registers.REG_Y_INDEX);            break;        case InstructionSet.OP_LDX_I:            registers.setRegisterAndFlags(Registers.REG_X_INDEX, nextProgramByte());            break;        case InstructionSet.OP_LDX_Z:            registers.setRegisterAndFlags(Registers.REG_X_INDEX, getByteOfMemoryAt(nextProgramByte()));            break;        ...        default:            throw new UnknownOpCodeException(Unknown 6502 OpCode: + opCode +  encountered., opCode);    }ThoughtsI've looked at storing op-codes as Enums but it means reading bytes (in Javas case this is int represented bytes) and writing conversion code from raw byte to Enum but that seems unnecessary for the small maintainability improvement.It seems excessive and not very OO to do it with a class per op-code.
Op-code decoding in an emulator
java;object oriented;virtual machine