summaryrefslogtreecommitdiff
path: root/src/cpu/addressing.h
diff options
context:
space:
mode:
authoralekseiplusplus <alekseijeaves@protonmail.com>2023-07-27 11:36:01 +1000
committeralekseiplusplus <alekseijeaves@protonmail.com>2023-07-27 11:36:01 +1000
commit9a6188f821b11b69fff3d3a303dbfcce2e52e6f4 (patch)
treeb06aa0d876b19cca281cbc26db9086ab7241d6bd /src/cpu/addressing.h
parentb158eaeb489bce502198e844593b38a2f5f5b9ee (diff)
refactoring of src/cpu/
Diffstat (limited to 'src/cpu/addressing.h')
-rw-r--r--src/cpu/addressing.h188
1 files changed, 9 insertions, 179 deletions
diff --git a/src/cpu/addressing.h b/src/cpu/addressing.h
index 29fa87c..d0320b8 100644
--- a/src/cpu/addressing.h
+++ b/src/cpu/addressing.h
@@ -1,6 +1,11 @@
// addressing.h
// Contains definitions relevant to addressing, as well as fAddress() which returns time, length, value, and address for an instruction function call.
+#ifndef ADDRESSING_H
+#define ADDRESSING_H
+
+#include"core.h"
+
enum Addressing {
eImmediate,
eAccumulator,
@@ -26,190 +31,15 @@ typedef struct AddData{
byte value;
} AddData;
-//typedef struct AddData AddData;
-
-#include"instructions/init.h"
+#include"instructions.h"
//Holds address of current instruction.
void* current_instruction;
#define getInstructionLength(c) fAddressGetLength(*getInstructionTableAddressing(c))
-int fAddressGetLength(Addressing addr){
- switch(addr){
- case eAbsolute: case eAbsoluteIndexedX: case eAbsoluteIndexedY:
- return 3;
- case eAccumulator: case eImplied:
- return 1;
- default:
- return 2;
- }
-}
-
-AddData fAddress(Addressing addr, short x) {
- AddData ret;
-
- // ADDRESS
-
- switch(addr){
- case eImplied:
- case eIndirectAbsolute:
- case eRelative:
- case eImmediate:
- case eAccumulator:
- ret.add = 0x0000;
- 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 = ((getMemory(x+X+1))<<8) + (getMemory(x+X));
- break;
- case eIndirectIndexed:
- ret.add = ((getMemory(x+1))<<8) + (getMemory(x)) + Y;
- break;
- }
-
- // VALUE
-
- switch(addr){
- case eImplied:
- case eIndirectAbsolute:
- case eRelative:
- break;
-
- case eImmediate:
- ret.value = x;
- break;
-
- case eAccumulator:
- ret.value = acc;
- break;
-
- default:
- ret.value = getMemory(ret.add);
- }
-
- // LENGTH
-
- ret.length = fAddressGetLength(addr);
-
- // CYCLES
-
- //case &fADC: case &fAND: case &fBIT: case &fCMP: case &fCPX: case &fCPY: case &fEOR: case &fLDA:
- //case &fLDX: case &fLDY: case &fORA: case &fSBC: case &fSTX: case &fSTY:
-
- if ( current_instruction == &fADC || current_instruction == &fAND || current_instruction == &fBIT || current_instruction == &fCMP || current_instruction == &fCPX
- || current_instruction == &fCPY || current_instruction == &fEOR || current_instruction == &fLDA || current_instruction == &fLDX || current_instruction == &fLDY
- || current_instruction == &fORA || current_instruction == &fSBC || current_instruction == &fSTX || current_instruction == &fSTY ){
- switch(addr){
- case eImmediate:
- ret.cycles = 2; break;
- case eZeroPage:
- ret.cycles = 3; break;
- case eZeroPageIndexedX: case eAbsolute: case eAbsoluteIndexedX: case eAbsoluteIndexedY:
- ret.cycles = 4; break;
- case eIndexedIndirect:
- ret.cycles = 6; break;
- case eIndirectIndexed:
- ret.cycles = 5; break;
- }
- }
-
- //case &fASL: case &fDEC: case &fINC: case &fLSR: case &fROL: case &fROR:
- else if( current_instruction == &fASL || current_instruction == &fDEC || current_instruction == &fINC
- || current_instruction == &fLSR || current_instruction == &fROL || current_instruction == &fROR ){
- switch(addr){
- case eAccumulator:
- ret.cycles = 2; break;
- case eZeroPage:
- ret.cycles = 5; break;
- case eZeroPageIndexedX: case eAbsolute:
- ret.cycles = 6; break;
- case eAbsoluteIndexedX:
- ret.cycles = 7; break;
- }
- }
-
- //case &fSTA:
- else if (current_instruction == &fSTA){
- switch(addr){
- case eZeroPage:
- ret.cycles = 3; break;
- case eZeroPageIndexedX: case eAbsolute:
- ret.cycles = 4; break;
- case eAbsoluteIndexedX: case eAbsoluteIndexedY:
- ret.cycles = 5; break;
- case eIndexedIndirect: case eIndirectIndexed:
- ret.cycles = 6; break;
- }
- }
-
-
- //case &fBRK:
- else if (current_instruction == &fBRK){
- ret.cycles = 7;
- }
-
-
- //case &fRTI: case &fRTS: case &fJSR:
- else if (current_instruction == &fRTI || current_instruction == &fRTS || current_instruction == &fJSR){
- ret.cycles = 6;
- }
-
- //case &fJMP:
- else if (current_instruction == &fJMP){
- ret.cycles = 5;
- }
-
- //case &fPLA: case &fPLP:
- else if (current_instruction == &fPLA || current_instruction == &fPLP){
- ret.cycles = 4;
- }
-
- //case &fPHA: case &fPHP:
- else if (current_instruction == &fPHA || current_instruction == &fPHP){
- ret.cycles = 3;
- }
-
- else {
- ret.cycles = 2;
- }
-
-
- // Page Boundary
-
- //case &fADC: case &fSBC: case &fLDA: case &fLDX: case &fLDY: case &fEOR: case &fAND: case &fORA: case &fCMP:
- if ( current_instruction == &fADC || current_instruction == &fSBC || current_instruction == &fLDA || current_instruction == &fLDX || current_instruction == &fLDY
- || current_instruction == &fEOR || current_instruction == &fAND || current_instruction == &fORA || current_instruction == &fCMP ){
- switch(addr){
- case eAbsoluteIndexedX:
- if ((x & 0xFF00) != ((x + X) & 0xFF00)) ret.cycles++; break;
- case eAbsoluteIndexedY:
- if ((x & 0xFF00) != ((x + Y) & 0xFF00)) ret.cycles++; break;
- case eIndirectIndexed:
- if ((ret.add & 0xFF00) != (ret.add - Y & 0xFF00)) ret.cycles++; break;
- }
- }
+int fAddressGetLength(Addressing addr);
- return ret;
-}
+AddData fAddress(Addressing addr, short x);
+#endif \ No newline at end of file