private int GetAddress(AddressModes addressMode, int SignatureBytes, RegisterBankNumber Bank) { int addr = 0; int ptr = 0; switch (addressMode) { // The address will not be used in Immediate or Implied mode, but case AddressModes.Immediate: return(ADDRESS_IMMEDIATE); case AddressModes.Implied: return(ADDRESS_IMPLIED); case AddressModes.Absolute: return(Bank.GetLongAddress(SignatureBytes)); case AddressModes.AbsoluteLong: return(SignatureBytes); case AddressModes.AbsoluteIndexedWithX: return(Bank.GetLongAddress(SignatureBytes + cpu.X.Value)); case AddressModes.AbsoluteLongIndexedWithX: return(SignatureBytes + cpu.X.Value); case AddressModes.AbsoluteIndexedWithY: return(SignatureBytes + cpu.Y.Value); case AddressModes.AbsoluteLongIndexedWithY: return(Bank.GetLongAddress(SignatureBytes + cpu.X.Value)); case AddressModes.DirectPage: return(cpu.DirectPage.GetLongAddress(SignatureBytes)); case AddressModes.DirectPageIndexedWithX: return(cpu.DirectPage.GetLongAddress(SignatureBytes + cpu.X.Value)); case AddressModes.DirectPageIndexedWithY: return(cpu.DirectPage.GetLongAddress(SignatureBytes + cpu.Y.Value)); case AddressModes.DirectPageIndexedIndirectWithX: addr = cpu.DirectPage.GetLongAddress(SignatureBytes) + cpu.X.Value; ptr = cpu.Memory.ReadWord(addr); return(cpu.ProgramBank.GetLongAddress(ptr)); case AddressModes.DirectPageIndirect: addr = cpu.DirectPage.GetLongAddress(SignatureBytes); ptr = cpu.Memory.ReadWord(addr); return(cpu.ProgramBank.GetLongAddress(ptr)); case AddressModes.DirectPageIndirectIndexedWithY: addr = cpu.DirectPage.GetLongAddress(SignatureBytes); ptr = cpu.Memory.ReadWord(addr) + cpu.Y.Value; return(cpu.ProgramBank.GetLongAddress(ptr)); case AddressModes.DirectPageIndirectLong: addr = cpu.DirectPage.GetLongAddress(SignatureBytes); ptr = cpu.Memory.ReadLong(addr); return(ptr); case AddressModes.DirectPageIndirectLongIndexedWithY: addr = cpu.DirectPage.GetLongAddress(SignatureBytes); ptr = cpu.Memory.ReadLong(addr) + cpu.Y.Value; return(cpu.ProgramBank.GetLongAddress(ptr)); case AddressModes.ProgramCounterRelative: ptr = MakeSignedByte((byte)SignatureBytes); addr = cpu.PC.Value + ptr; return(addr); case AddressModes.ProgramCounterRelativeLong: ptr = MakeSignedInt((UInt16)SignatureBytes); addr = cpu.PC.Value + ptr; return(addr); case AddressModes.StackImplied: //case AddressModes.StackAbsolute: return(0); case AddressModes.StackDirectPageIndirect: return(cpu.DirectPage.GetLongAddress(SignatureBytes)); case AddressModes.StackRelative: return(cpu.Stack.Value + SignatureBytes); case AddressModes.StackRelativeIndirectIndexedWithY: return(cpu.Stack.Value + SignatureBytes + cpu.Y.Value); case AddressModes.StackProgramCounterRelativeLong: return(SignatureBytes); // Jump and JSR indirect references vectors located in Bank 0 case AddressModes.JmpAbsoluteIndirect: addr = SignatureBytes; ptr = cpu.Memory.ReadWord(addr); return(cpu.ProgramBank.GetLongAddress(ptr)); case AddressModes.JmpAbsoluteIndirectLong: addr = SignatureBytes; ptr = cpu.Memory.ReadLong(addr); return(ptr); case AddressModes.JmpAbsoluteIndexedIndirectWithX: addr = SignatureBytes + cpu.X.Value; ptr = cpu.Memory.ReadWord(addr); return(cpu.ProgramBank.GetLongAddress(ptr)); case AddressModes.Accumulator: return(0); default: throw new NotImplementedException("GetAddress() Address mode not implemented: " + addressMode.ToString()); } }