summaryrefslogtreecommitdiff
path: root/src/cpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpu')
l---------src/cpu/.#addressing.c1
-rw-r--r--src/cpu/6502.c2
-rw-r--r--src/cpu/addressing.c11
-rw-r--r--src/cpu/addressing.h8
-rw-r--r--src/cpu/core.h2
-rw-r--r--src/cpu/instructions.c15
-rw-r--r--src/cpu/table.c18
-rw-r--r--src/cpu/table.h4
8 files changed, 33 insertions, 28 deletions
diff --git a/src/cpu/.#addressing.c b/src/cpu/.#addressing.c
new file mode 120000
index 0000000..e0e3e02
--- /dev/null
+++ b/src/cpu/.#addressing.c
@@ -0,0 +1 @@
+aleksei@arch-desktop.664:1701869620 \ No newline at end of file
diff --git a/src/cpu/6502.c b/src/cpu/6502.c
index e7c1669..595cd4e 100644
--- a/src/cpu/6502.c
+++ b/src/cpu/6502.c
@@ -36,7 +36,7 @@ void SetFlagN(byte x){
//Perform prior to any changes TODO: FIX THIS! WTF WERE YOU THINKING?
void SetFlagV(byte x, byte y){
address z = (address)x + (address)y;
- if (z > 0xFF)
+ if ((x & 0x80) != (y & 0x80))
SetFlag(flag_V, 1);
else
SetFlag(flag_V, 0);
diff --git a/src/cpu/addressing.c b/src/cpu/addressing.c
index e5625fa..60ec4f0 100644
--- a/src/cpu/addressing.c
+++ b/src/cpu/addressing.c
@@ -8,7 +8,7 @@
//Holds address of current instruction.
void* current_instruction;
-address fAddressGetAddress(Addressing mode, short x) {
+address fAddressGetAddress(Addressing mode, address x) {
switch(mode){
case eImplied:
case eRelative:
@@ -47,12 +47,11 @@ int fAddressGetLength(Addressing mode){
}
}
-byte fAddressGetValue(Addressing mode, short x, address addr) {
+byte fAddressGetValue(Addressing mode, address x, address addr) {
switch(mode){
case eImplied:
- case eIndirectAbsolute:
return 0;
- case eRelative: // TODO: MARKER FOR 3/12/2023
+ case eRelative:
case eImmediate:
return x;
case eAccumulator:
@@ -62,7 +61,7 @@ byte fAddressGetValue(Addressing mode, short x, address addr) {
}
}
-int fAddressGetCycles(Addressing mode, short x, address addr) {
+int fAddressGetCycles(Addressing mode, address x, address addr) {
int cycles;
//case &fADC: case &fAND: case &fBIT: case &fCMP: case &fCPX: case &fCPY: case &fEOR: case &fLDA:
@@ -170,7 +169,7 @@ int fAddressGetCycles(Addressing mode, short x, address addr) {
return cycles;
}
-AddData fAddress(Addressing mode, short x) {
+AddData fAddress(Addressing mode, address x) {
AddData ret;
ret.add = fAddressGetAddress (mode, x);
ret.value = fAddressGetValue (mode, x, ret.add);
diff --git a/src/cpu/addressing.h b/src/cpu/addressing.h
index e2c882e..790b912 100644
--- a/src/cpu/addressing.h
+++ b/src/cpu/addressing.h
@@ -12,8 +12,8 @@
// For a given addressing mode and opcode, return data about the instruction.
-AddData fAddress (Addressing mode, short x );
-address fAddressGetAddress (Addressing mode, short x );
+AddData fAddress (Addressing mode, address x );
+address fAddressGetAddress (Addressing mode, address x );
int fAddressGetLength (Addressing mode );
-byte fAddressGetValue (Addressing mode, short x, address addr);
-int fAddressGetCycles (Addressing mode, short x, address addr); \ No newline at end of file
+byte fAddressGetValue (Addressing mode, address x, address addr);
+int fAddressGetCycles (Addressing mode, address x, address addr);
diff --git a/src/cpu/core.h b/src/cpu/core.h
index 5a73818..4545cd5 100644
--- a/src/cpu/core.h
+++ b/src/cpu/core.h
@@ -15,7 +15,7 @@ extern byte P;
extern byte S;
extern address PC;
extern byte* Memory;
-extern const byte ROM[];
+extern byte ROM[];
enum Addressing
diff --git a/src/cpu/instructions.c b/src/cpu/instructions.c
index b4daf6e..1a94386 100644
--- a/src/cpu/instructions.c
+++ b/src/cpu/instructions.c
@@ -68,6 +68,7 @@ void fSBC(Addressing addr, address val){
SetFlag(flag_C, (buffer > acc) ? 1 : 0);
acc = buffer;
+
SetFlagN(acc);
SetFlagZ(acc);
}
@@ -135,7 +136,7 @@ void fEOR(Addressing addr, address val){
// Jump, Branch, Compare, and Test Bits
void fJMP(Addressing addr, address val){
- PC = idata.add - idata.length;
+ PC = idata.value - idata.length;
}
void fBCC(Addressing addr, address val){
@@ -189,9 +190,9 @@ void fCPY(Addressing addr, address val){
}
void fBIT(Addressing addr, address val){
- SetFlag(flag_N, (idata.value & flag_N) ? 1 : 0);
- SetFlag(flag_V, (idata.value & flag_V) ? 1 : 0);
- SetFlag(flag_Z, (idata.value & acc) ? 0 : 1);
+ SetFlag(flag_N, ((idata.value & flag_N) != 0) ? 1 : 0);
+ SetFlag(flag_V, ((idata.value & flag_V) != 0) ? 1 : 0);
+ SetFlag(flag_Z, ((idata.value & acc) == 0) ? 1 : 0);
}
// Shift and Rotate Instructions
@@ -321,14 +322,14 @@ void fPLP(Addressing addr, address val){
// Subroutine Instructions
void fJSR(Addressing addr, address val){
- SetStack((PC+3) >> 8);
- SetStack((PC+3) & 0x00FF);
+ SetStack ((PC+idata.length) >> 8);
+ SetStack(((PC+idata.length) & 0x00FF) - 1);
PC = idata.add;
PC -= idata.length;
}
void fRTS(Addressing addr, address val){
- PC = (address)(GetStack());
+ PC = (address)(GetStack()) + 1;
PC += ((address)(GetStack())) << 8;
PC -= idata.length;
}
diff --git a/src/cpu/table.c b/src/cpu/table.c
index 735ab80..4e60f58 100644
--- a/src/cpu/table.c
+++ b/src/cpu/table.c
@@ -17,24 +17,28 @@ Addressing* GetInstructionTableAddressing(int i){
return r;
}
-void CallInstructionTable(int i, address val){
- val = 0; // TODO: Let the initial value of val be redundant for now so as to not break anything, but fix later
+void CallInstructionTable(){
+ int val = 0;
// Setup to call the correct function.
+ int i = (address)GetMemory(PC);
uintptr_t a = GetInstructionTableFunction(i);
memcpy(&func, a, sizeof(uintptr_t));
// Find the correct addressing mode.
- Addressing* r = (InstructionTable + ((sizeof(uintptr_t)*256) + (sizeof(Addressing) * i)));
+ Addressing r = *(Addressing*)(InstructionTable + ((sizeof(uintptr_t)*256) + (sizeof(Addressing) * i)));
// Set val
- if (fAddressGetLength(*r) >= 2)
+ if (fAddressGetLength(r) >= 2)
val += (address)GetMemory(PC+1);
- if (fAddressGetLength(*r) == 3)
+ if (fAddressGetLength(r) == 3)
val += (address)GetMemory(PC+2) << 8;
+
// Set idata
- idata = fAddress(*r, val);
+ idata = fAddress(r, val);
// Perform function
- func(*r, val); // TODO: MARKER FOR 3/12/2023
+ func(r, val); // TODO: MARKER FOR 3/12/2023
+
+
PC += idata.length;
}
diff --git a/src/cpu/table.h b/src/cpu/table.h
index 18cac90..7406c9c 100644
--- a/src/cpu/table.h
+++ b/src/cpu/table.h
@@ -14,10 +14,10 @@ uintptr_t* GetInstructionTableFunction(int i);
Addressing* GetInstructionTableAddressing(int i);
-void CallInstructionTable(int i, address val);
+void CallInstructionTable();
// Sets an individual portion of an instruction set
void SetInstructionTable(int i, uintptr_t p, Addressing r);
// Initializes instruction table in memory.
-void InitInstructionTable(); \ No newline at end of file
+void InitInstructionTable();