summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cpu/addressing.h2
-rw-r--r--src/cpu/instructions/definitions.h36
-rw-r--r--src/interpreter.c2
3 files changed, 30 insertions, 10 deletions
diff --git a/src/cpu/addressing.h b/src/cpu/addressing.h
index 0969025..29fa87c 100644
--- a/src/cpu/addressing.h
+++ b/src/cpu/addressing.h
@@ -33,6 +33,8 @@ typedef struct AddData{
//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:
diff --git a/src/cpu/instructions/definitions.h b/src/cpu/instructions/definitions.h
index 937ca10..98345c5 100644
--- a/src/cpu/instructions/definitions.h
+++ b/src/cpu/instructions/definitions.h
@@ -2,7 +2,8 @@
// Definition of all instruction functions, handling effect of instruction and flags.
AddData idata;
-
+#define GET_STACK getMemory(0x01FF - S)
+#define SET_STACK(z) setMemory(0x01FF - S, z)
/* TO DO
@@ -280,40 +281,50 @@ void fTXS(Addressing addr, address val){ idata = fAddress(addr, val);
}
void fPHA(Addressing addr, address val){ idata = fAddress(addr, val);
- setMemory(0x01FF-S, acc);
+ SET_STACK(acc);
S++;
}
void fPHP(Addressing addr, address val){ idata = fAddress(addr, val);
- setMemory(0x01FF-S, P);
+ SET_STACK(P);
S++;
}
void fPLA(Addressing addr, address val){ idata = fAddress(addr, val);
S--;
- acc = getMemory(0x01FF-S);
+ acc = GET_STACK;
}
void fPLP(Addressing addr, address val){ idata = fAddress(addr, val);
S--;
- P = getMemory(0x01FF-S);
+ P = GET_STACK;
}
// Subroutine Instructions
// NEED TO FINISH THESE
void fJSR(Addressing addr, address val){ idata = fAddress(addr, val);
- Memory[0x01FF-S] = (idata.add-1);
+ SET_STACK(((PC-1) & 0xFF00) >> 8);
+ S++;
+ SET_STACK((PC-1) & 0x00FF);
S++;
PC = idata.add;
}
void fRTS(Addressing addr, address val){ idata = fAddress(addr, val);
-
+ S--;
+ PC = (address)(GET_STACK + 1);
+ S--;
+ PC += ((address)(GET_STACK)) << 8;
}
void fRTI(Addressing addr, address val){ idata = fAddress(addr, val);
-
+ S--;
+ P = GET_STACK; //NEED TO FIX
+ S--;
+ PC = (address)(GET_STACK);
+ S--;
+ PC += (address)(GET_STACK << 8);
}
// Set/Reset Insutrctions
@@ -352,7 +363,14 @@ void fNOP(Addressing addr, address val){ idata = fAddress(addr, val);
}
void fBRK(Addressing addr, address val){ idata = fAddress(addr, val);
- flagSet(flag_B);
+ SET_STACK((((PC+2) & 0xFF00) >> 8));
+ S++;
+ SET_STACK((PC+2) & 0x00FF);
+ S++;
+ SET_STACK(P);
+ S++;
+ PC = (address)(getMemory(0xFFFE));
+ PC += ((address)(getMemory(0xFFFF)) << 8);
}
#ifdef ILLEGAL
diff --git a/src/interpreter.c b/src/interpreter.c
index 96c4617..a51ade1 100644
--- a/src/interpreter.c
+++ b/src/interpreter.c
@@ -106,7 +106,7 @@ int main(int argc, char *argv[]){
c += dCharToNum(getc(stdin));
address x = 0x0000;
char z = 0x00;
- for(int i = ((fAddressGetLength(*getInstructionTableAddressing(c)) * 2) - 2); i > 0; i--) {
+ for(int i = ((getInstructionLength(c) * 2) - 2); i > 0; i--) {
do {
z = getc(stdin);
} while (z == ' ' || z == '\t');