summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralekseiplusplus <alekseijeaves@protonmail.com>2023-04-20 12:51:50 +1000
committeralekseiplusplus <alekseijeaves@protonmail.com>2023-04-20 12:51:50 +1000
commitc138759ebf4194a73364a79a9acc87f54dcc73bc (patch)
treebe113336c04e39954863a55e8a39e7c46a404f4e
parent10fedb851f6654874a644f4b158a4d9d404da14e (diff)
callIT() FINALLY WORKS
-rwxr-xr-xa.outbin30760 -> 30664 bytes
-rw-r--r--include.h1
-rw-r--r--instruction-init.h22
-rw-r--r--interpreter.c3
-rw-r--r--test.c28
5 files changed, 39 insertions, 15 deletions
diff --git a/a.out b/a.out
index 45940d6..502cb0b 100755
--- a/a.out
+++ b/a.out
Binary files differ
diff --git a/include.h b/include.h
index 047775f..4bffe1e 100644
--- a/include.h
+++ b/include.h
@@ -1,6 +1,7 @@
#include"stdio.h"
#include"stdint.h"
#include"stdlib.h"
+#include"string.h"
#include"applesystem.h"
#include"addressing.h"
#include"instruction.h" \ No newline at end of file
diff --git a/instruction-init.h b/instruction-init.h
index c2f85ed..adb5047 100644
--- a/instruction-init.h
+++ b/instruction-init.h
@@ -4,17 +4,19 @@
//InstructionTable
void* IT;
-
-
+void (*func)(Addressing, address);
void setIT(int i, uintptr_t p, Addressing r){
- uintptr_t* p1 = (IT + (i * sizeof(uintptr_t)));
+ uintptr_t* p1 = (IT + (sizeof(uintptr_t)*i));
*p1 = p;
- Addressing* r1 = (IT + ((sizeof(uintptr_t)*256)) + (i * sizeof(Addressing)));
+ Addressing* r1 = (IT + (sizeof(uintptr_t)*256) + (sizeof(Addressing)*i));
*r1 = r;
+
+ printf("DEBUG:\t%x\t%x -> %x\t%x -> %x\n", i, p1, *p1, r1, *r1);
}
+/*
uintptr_t getITFunction(int i){ //Segmentation fault is occurring here, likely in next one too
uintptr_t r = (IT + (sizeof(uintptr_t)*i));
return r;
@@ -24,13 +26,14 @@ Addressing getITAddressing(int i){
Addressing r = (IT + (sizeof(uintptr_t)*256) + (sizeof(Addressing)*i));
return r;
}
+*/
void callIT(int i, address val){
- void (*func)(Addressing, address);
- func = (IT + (sizeof(uintptr_t) * i));
- Addressing r = (IT + ((i * sizeof(Addressing)) + (sizeof(uintptr_t)*256)));
- func(r, val);
+ uintptr_t a = ((uintptr_t)IT + (sizeof(uintptr_t) * i));
+ memcpy(&func, a, sizeof(uintptr_t));
+ Addressing* r = (IT + ((sizeof(uintptr_t)*256) + (sizeof(Addressing) * i)));
+ func(*r, val);
}
@@ -104,7 +107,8 @@ void fSEI(Addressing, address);
void fNOP(Addressing, address);
void fBRK(Addressing, address);
-void initIT(){
+void initIT(){ //Change this to load a binary file which contains this same information.
+ //So will need to dump the contents of IT at some point.
IT = malloc(256 * (sizeof(uintptr_t) + sizeof(Addressing)));
// Load and Store Instructions
diff --git a/interpreter.c b/interpreter.c
index 4598d2f..6fea22e 100644
--- a/interpreter.c
+++ b/interpreter.c
@@ -13,6 +13,9 @@
int main(){
char c;
unsigned char a, b;
+
+ initIT();
+
while(1){
c = fgetc(stdin);
diff --git a/test.c b/test.c
index b8cecd6..1ae1aff 100644
--- a/test.c
+++ b/test.c
@@ -2,10 +2,26 @@
#include"debug.h"
int main(){
- fAddressGetLength(eAbsolute);
- printf("fAddressGetLength Success\n");
- getITFunction(0x00);
- printf("getITFunction Success\n");
- getITAddressing(0x00);
- printf("getITAddressing Success\n");
+ char c;
+ unsigned char a, b;
+
+ initIT();
+
+ //void (*func)(Addressing, address); printf("Statement OK");
+
+ printf("\n\n");
+
+ func = &fLDA;
+
+ dStatusDump();
+
+ //func(*(IT + ((sizeof(uintptr_t)*256)) + (0xA9 * sizeof(Addressing))), *(IT + ((sizeof(uintptr_t)*0xA9))));
+
+ callIT(0xA9, 0x01);
+
+ dStatusDump();
+
+ printf("%x\n", (IT + 31));
+
+ return 0;
} \ No newline at end of file