// addressing.h #include "addressing.h" address fAddressGetAddress(Addressing mode, address x) { switch(mode) { case eImplied: case eRelative: case eImmediate: case eAccumulator: return 0x0000; case eAbsolute: return x; case eIndirectAbsolute: return (((address)GetMemory(x+1)) << 8) + (address)GetMemory(x); case eAbsoluteIndexedX: return x + X; case eAbsoluteIndexedY: return x + Y; case eZeroPage: return x & 0x00FF; case eZeroPageIndexedX: return ((x + X) & 0x00FF); case eZeroPageIndexedY: return ((x + Y) & 0x00FF); case eIndexedIndirect: return (((address)(GetMemory(x+X+1))) << 8) + (address)(GetMemory(x+X)); case eIndirectIndexed: return ((address)(GetMemory(x+1)) << 8) + ((address)(GetMemory(x))) + ((address)Y); } } int fAddressGetLength(Addressing mode) { switch(mode) { case eAbsolute: case eAbsoluteIndexedX: case eAbsoluteIndexedY: case eIndirectAbsolute: return 3; case eAccumulator: case eImplied: return 1; default: return 2; } } byte fAddressGetValue(Addressing mode, address x, address addr) { switch(mode) { case eImplied: return 0; case eRelative: case eImmediate: return x; case eAccumulator: return acc; default: return GetMemory(addr); } } struct State fAddress(Addressing mode, address x) { struct State ret; ret.address = fAddressGetAddress (mode, x); ret.value = fAddressGetValue (mode, x, ret.address); ret.length = fAddressGetLength (mode); return ret; }