diff options
author | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-04-07 02:35:46 +1000 |
---|---|---|
committer | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-04-07 02:35:46 +1000 |
commit | fbca225d25db812fe7823a8528dff17320cf1c53 (patch) | |
tree | f99d672c7245233814cd038fd683ef8bf4270961 /addressing.h | |
parent | 4b2952578ece47358960e29825443f77070a7457 (diff) |
commit so I can access it tomorrow.
Diffstat (limited to 'addressing.h')
-rw-r--r-- | addressing.h | 78 |
1 files changed, 60 insertions, 18 deletions
diff --git a/addressing.h b/addressing.h index 300dac5..9c57592 100644 --- a/addressing.h +++ b/addressing.h @@ -1,12 +1,15 @@ +// addressing.h +// Contains definitions relevant to addressing, as well as fAddress() which returns time, length, value, and address for an instruction function call. + enum Addressing { eImmediate, eAccumulator, - eAbsolute, - eAbsoluteIndexedX, - eAbsoluteIndexedY, eZeroPage, eZeroPageIndexedX, eZeroPageIndexedY, + eAbsolute, + eAbsoluteIndexedX, + eAbsoluteIndexedY, eIndexedIndirect, eIndirectIndexed, eImplied, @@ -22,30 +25,70 @@ void (*current_instruction)(Addressing, address); struct AddData{ int cycles; int length; + address add; byte value; }; AddData fAddress(Addressing addr, short x) { AddData ret; - // VALUE + // ADDRESS switch(addr){ - case eImmediate: ret.value = x; break; - case eAccumulator: ret.value = acc; break; + case eImplied: + case eIndirectAbsolute: + case eRelative: + break; + + case eAbsolute: + ret.add = x; + break; + case eAbsoluteIndexedX: + ret.add = (x + X); + break; + case eAbsoluteIndexedY: + ret.add = (x + Y); + break; + + case eZeroPage: + ret.add = (x & 0x00FF); + break; + case eZeroPageIndexedX: + ret.add = ((x + X) & 0x00FF); + break; + case eZeroPageIndexedY: + ret.add = ((x + Y) & 0x00FF); + break; + + case eIndexedIndirect: + ret.add = (((address)Memory[x+X+1])<<8) + (Memory[x+X]); + break; + case eIndirectIndexed: + ret.add = (((address)Memory[x+1])<<8) + (Memory[x]) + Y; + break; + } - case eAbsolute: ret.value = Memory[x]; break; - case eAbsoluteIndexedX: ret.value = Memory[(x + X)]; break; - case eAbsoluteIndexedY: ret.value = Memory[(x + Y)]; break; + // VALUE - case eZeroPage: ret.value = Memory[(x & 0x00FF)]; break; - case eZeroPageIndexedX: ret.value = Memory[((x + X) & 0x00FF)]; break; - case eZeroPageIndexedY: ret.value = Memory[((x + Y) & 0x00FF)]; break; + switch(addr){ + case eImplied: + case eIndirectAbsolute: + case eRelative: + break; + + case eImmediate: + ret.value = x; + break; - case eIndexedIndirect: ret.value = Memory[ (((address)Memory[x+X+1])<<8) + (Memory[x+X]) ]; break; - case eIndirectIndexed: ret.value = Memory[ (((address)Memory[x+1])<<8) + (Memory[x]) + Y ]; break; + case eAccumulator: + ret.value = acc; + break; + + default: + ret.value = Memory[ret.add] } + // LENGTH switch(addr){ @@ -122,7 +165,7 @@ AddData fAddress(Addressing addr, short x) { ret.cycles = 3; break; - default: //Any instruction which doesn't fit any of these conditions is probably an implied/relative mode instruction which costs 2 cycles + default: ret.cycles = 2; } @@ -133,9 +176,8 @@ AddData fAddress(Addressing addr, short x) { if ((x & 0xFFFC) != ((x + X) & 0xFFFC)) ret.cycles++; break; case eAbsoluteIndexedY: if ((x & 0xFFFC) != ((x + Y) & 0xFFFC)) ret.cycles++; break; - case eIndirectIndexed: //I am not 100% sure if this is the correct handling a page boundary cross with indirect indexed addressing. also its kinda ugly - if( (((((address)Memory[x+1])<<8) + (Memory[x]) + Y) & 0xFFFC) != - (((((address)Memory[x+1])<<8) + (Memory[x])) & 0xFFFC)) ret.cycles++; break; + case eIndirectIndexed: + if ((ret.add & 0xFFFC) != (ret.add - Y & 0xFFFC)) ret.cycles++; break; } } } |