From c138759ebf4194a73364a79a9acc87f54dcc73bc Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Thu, 20 Apr 2023 12:51:50 +1000 Subject: callIT() FINALLY WORKS --- a.out | Bin 30760 -> 30664 bytes include.h | 1 + instruction-init.h | 22 +++++++++++++--------- interpreter.c | 3 +++ test.c | 28 ++++++++++++++++++++++------ 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/a.out b/a.out index 45940d6..502cb0b 100755 Binary files a/a.out and b/a.out 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 -- cgit v1.2.3