Regarding observing the cycles, I changed my mind. At first, I didn’t attach any importance to it. After some more reading and getting a better understanding of the importance the cycles have, even in a simulation, I will will do some changes to the code.
To do this in a way that keeps the code flexible and maintable, I want to introduce an attribute for the opcode-methods. It will handle the cycles this opcode takes, the adressing mode and probably some more parameters. We’ll see.
C#
[AttributeUsage(AttributeTargets.Method)]
class OpcodeAttribute : Attribute {
public int Cycles { get; }
public string AddressingMode { get; }
public OpcodeAttribute(int cycles, string mode) {
Cycles = cycles;
AddressingMode = mode;
}
}
C#
[Opcode(2, "Immediate")]
public void Cmd_A9() {
// LDA #immediate
A = FetchByte();
SetFlags(A);
}
MethodInfo method = this.GetType().GetMethod("Cmd_" + opcode.ToString("X2"));
if (method != null) {
var attr = method.GetCustomAttribute<OpcodeAttribute>();
method.Invoke(this, null);
if (attr != null) {
CycleCount += attr.Cycles;
# use attr.AddressingMode to chose the mode for this opcode
}
}