summaryrefslogtreecommitdiff
path: root/headers
diff options
context:
space:
mode:
authoralekseiplusplus <alekseijeaves@protonmail.com>2023-04-21 16:12:16 +1000
committeralekseiplusplus <alekseijeaves@protonmail.com>2023-04-21 16:12:16 +1000
commit83e8a4494741e6257b18267a58fe8ae342e3229f (patch)
tree001d5094f713118834e9a0fb5313df4cf40ecc7a /headers
parentae800796cdcce21c561bcbfbc96b29efe4d39a0b (diff)
changed dirs, now testing instructions.
Diffstat (limited to 'headers')
-rw-r--r--headers/6502.h (renamed from headers/applesystem.h)20
-rw-r--r--headers/addressing.h2
-rw-r--r--headers/apple.h6
-rw-r--r--headers/debug.h12
-rw-r--r--headers/include.h5
-rw-r--r--headers/instruction-table.h (renamed from headers/instruction-bin.h)25
-rw-r--r--headers/instructions-init.h (renamed from headers/instruction-init.h)27
-rw-r--r--headers/instructions.h23
8 files changed, 65 insertions, 55 deletions
diff --git a/headers/applesystem.h b/headers/6502.h
index 6b2f818..ea92479 100644
--- a/headers/applesystem.h
+++ b/headers/6502.h
@@ -1,5 +1,5 @@
-// applesystem.h
-// Core elements of the 6502 CPU, and flag manipulation.
+// 6502.h
+// Core elements of the 6502 CPU
typedef unsigned char byte;
typedef unsigned short address;
@@ -8,19 +8,19 @@ address PC = 0x0000;
byte Memory[4096]; // TO DO. Add expansion capability to memory.
// FLAGS
-const byte flag_N = 0x80; // Negative
-const byte flag_V = 0x40; // Overflow
-const byte flag_B = 0x10; // BRK command
-const byte flag_D = 0x08; // Decimal mode
-const byte flag_I = 0x04; // IRQ disable
-const byte flag_Z = 0x02; // Zero
-const byte flag_C = 0x01; // Carry
+#define flag_N 0x80 // Negative
+#define flag_V 0x40 // Overflow
+#define flag_B 0x10 // BRK command
+#define flag_D 0x08 // Decimal mode
+#define flag_I 0x04 // IRQ disable
+#define flag_Z 0x02 // Zero
+#define flag_C 0x01 // Carry
byte getFlag(byte flag) {
return ((P & flag) == flag) ? 1 : 0;
}
-void setFlag(byte flag, int x) { //OVERLOAD TO ACCEPT INT AS WELL
+void setFlag(byte flag, int x) {
if (x == 1){
if ((P & flag) == 0x0) P += flag;
}else if (x == 0){
diff --git a/headers/addressing.h b/headers/addressing.h
index d9d8e98..58df3f5 100644
--- a/headers/addressing.h
+++ b/headers/addressing.h
@@ -28,7 +28,7 @@ struct AddData{
typedef struct AddData AddData;
-#include"instruction-init.h"
+#include"instructions-init.h"
//Holds address of current instruction.
void* current_instruction;
diff --git a/headers/apple.h b/headers/apple.h
new file mode 100644
index 0000000..f5cac5c
--- /dev/null
+++ b/headers/apple.h
@@ -0,0 +1,6 @@
+#define MEMORY_SIZE 4096
+
+void AppleOn(){
+ //Memory = malloc(MEMORY_SIZE);
+ initInstructionTable();
+} \ No newline at end of file
diff --git a/headers/debug.h b/headers/debug.h
index bb6ba40..cb34dac 100644
--- a/headers/debug.h
+++ b/headers/debug.h
@@ -33,9 +33,11 @@ void dPageDump(short m){
// Dump CPU values
void dStatusDump(void){
- printf(" acc:\t%x\n X:\t%x\n Y:\t%x\nstack:\t%x\nflags:\t%x\n", acc, X, Y, S, P);
+printf("\
+..acc:\t%x\tcycles:\t%d\n\
+....X:\t%x\tlength:\t%d\n\
+....Y:\t%x\t...add:\t%x\n\
+stack:\t%x\t.value:\t%x\n\
+flags:\t%x\n\
+", acc, idata.cycles, X, idata.length, Y, idata.add, S, idata.value, P);
}
-
-void dIdataDump(void){
- printf("cycles:\t%d\nlength:\t%d\n add:\t%x\n value:\t%x\n", idata.cycles, idata.length, idata.add, idata.value);
-} \ No newline at end of file
diff --git a/headers/include.h b/headers/include.h
index e2578de..c4a2ef8 100644
--- a/headers/include.h
+++ b/headers/include.h
@@ -2,7 +2,8 @@
#include"stdint.h"
#include"stdlib.h"
#include"string.h"
-#include"applesystem.h"
+#include"6502.h"
#include"addressing.h"
#include"instructions.h"
-#include"instruction-bin.h" \ No newline at end of file
+#include"instruction-table.h"
+#include"apple.h" \ No newline at end of file
diff --git a/headers/instruction-bin.h b/headers/instruction-table.h
index 0127fd7..bb51adb 100644
--- a/headers/instruction-bin.h
+++ b/headers/instruction-table.h
@@ -1,3 +1,28 @@
+// instruction-table.h
+// Defines the instruction table, and the functions to access it.
+
+void* InstructionTable;
+void (*func)(Addressing, address);
+
+#define InstructionTableSize (256 * (sizeof(uintptr_t) + sizeof(Addressing)))
+
+uintptr_t* getInstructionTableFunction(int i){ //Segmentation fault is occurring here, likely in next one too
+ uintptr_t* r = (InstructionTable + (sizeof(uintptr_t)*i));
+ return r;
+}
+
+Addressing* getInstructionTableAddressing(int i){
+ Addressing* r = (InstructionTable + (sizeof(uintptr_t)*256) + (sizeof(Addressing)*i));
+ return r;
+}
+
+void callInstructionTable(int i, address val){
+ uintptr_t a = getInstructionTableFunction(i);
+ memcpy(&func, a, sizeof(uintptr_t));
+ Addressing* r = (InstructionTable + ((sizeof(uintptr_t)*256) + (sizeof(Addressing) * i)));
+ func(*r, val);
+}
+
void setInstructionTable(int i, uintptr_t p, Addressing r){
uintptr_t* p1 = (InstructionTable + (sizeof(uintptr_t)*i));
*p1 = p;
diff --git a/headers/instruction-init.h b/headers/instructions-init.h
index 68b9cf3..6fddec4 100644
--- a/headers/instruction-init.h
+++ b/headers/instructions-init.h
@@ -1,32 +1,5 @@
// instruction-init.h
// Initializes every instruction function prior to addressing.h so that function addresses are accessible
-// also defines the array used to refer to functions
-
-//InstructionTable
-void* InstructionTable;
-void (*func)(Addressing, address);
-
-#define InstructionTableSize (256 * (sizeof(uintptr_t) + sizeof(Addressing)))
-
-uintptr_t* getInstructionTableFunction(int i){ //Segmentation fault is occurring here, likely in next one too
- uintptr_t* r = (InstructionTable + (sizeof(uintptr_t)*i));
- return r;
-}
-
-Addressing* getInstructionTableAddressing(int i){
- Addressing* r = (InstructionTable + (sizeof(uintptr_t)*256) + (sizeof(Addressing)*i));
- return r;
-}
-
-void callInstructionTable(int i, address val){
- printf("Table:\t%x\n", InstructionTable);
- uintptr_t a = getInstructionTableFunction(i);
- printf("A Val:\t%x\n", a);
- //printf("Before:\t%x\n", func); func = a; printf("After:\t%x\n", func);
- printf("Before:\t%x\n", func); memcpy(&func, a, sizeof(uintptr_t)); printf("After:\t%x\n", func);
- Addressing* r = (InstructionTable + ((sizeof(uintptr_t)*256) + (sizeof(Addressing) * i)));
- func(*r, val); printf("Statement OK");
-}
// Load and Store Instructions
void fLDA(Addressing, address);
diff --git a/headers/instructions.h b/headers/instructions.h
index 96f5719..bdcd442 100644
--- a/headers/instructions.h
+++ b/headers/instructions.h
@@ -1,13 +1,16 @@
-// instruction.h
+// instructions.h
// Definition of all instruction functions, handling effect of instruction and flags.
-// array/map of pointers which all point
-// to the functions which the index corresponds to.
-// use that like a sort of map
+AddData idata;
-//Instruction Data
-AddData idata;
+/* TO DO
+
+!!!!!!!! CHECK THAT idata.value IS USED ACROSS ALL FUNCTIONS, NOT VAL !!!!!!!!!!!!!!
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Fix all functions before performing testing
+
+*/
// Load and Store Instructions
@@ -206,15 +209,15 @@ void fBIT(Addressing addr, address val){ idata = fAddress(addr, val);
// Shift and Rotate Instructions
void fASL(Addressing addr, address val){ idata = fAddress(addr, val);
- setFlag(flag_C, (val & 0x80));
- acc = (val << 1);
+ setFlag(flag_C, (idata.value & 0x80));
+ acc = (idata.value << 1);
setFlagN(acc);
setFlagZ(acc);
}
void fLSR(Addressing addr, address val){ idata = fAddress(addr, val);
- setFlag(flag_C, (val & 0x01));
- acc = (val >> 1);
+ setFlag(flag_C, (idata.value & 0x01));
+ acc = (idata.value >> 1);
setFlagN(acc);
setFlagZ(acc);
}