summaryrefslogtreecommitdiff
path: root/instruction-init.h
blob: 12cdfa46023a96e47611272ce58f6495ac607a91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//	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* IT;
void (*func)(Addressing, address);

#define InstructionTableSize (256*(sizeof(uintptr_t) + sizeof(Addressing)))

/*
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;
}

Addressing getITAddressing(int i){
	Addressing r = (IT + (sizeof(uintptr_t)*256) + (sizeof(Addressing)*i));
	return r;
}
*/


void callIT(int i, address val){
	uintptr_t a = (IT + (sizeof(uintptr_t) * i));
	memcpy(&func, a, sizeof(uintptr_t));
	Addressing* r = (IT + ((sizeof(uintptr_t)*256) + (sizeof(Addressing) * i)));
	func(*r, val);
}

void initIT(){
	IT = malloc(InstructionTableSize);
	FILE* fs = fopen("instructions.bin", "r");

	/*if (fs == NULL){
		system("instruction-dump");
	}*/
	for(char* c = IT; c < (IT + InstructionTableSize); c++){ //NEED TO MAKE (IT + (256*(sizeof(uintptr_t) + sizeof(Addressing)))) a macro
		*c = fgetc(fs);
	} //Investigate whether doing word sized units would increase speed
	fclose(fs);
	//read in the instruction data binary
}



// Load and Store Instructions
void fLDA(Addressing, address);
void fLDX(Addressing, address);
void fLDY(Addressing, address);
void fSTA(Addressing, address);
void fSTX(Addressing, address);
void fSTY(Addressing, address);
// Arithmetic Instructions
void fADC(Addressing, address);
void fSBC(Addressing, address);
//Increment and Decrement Instructions
void fINC(Addressing, address);
void fINX(Addressing, address);
void fINY(Addressing, address);
void fDEC(Addressing, address);
void fDEX(Addressing, address);
void fDEY(Addressing, address);
// Logical Instructions
void fAND(Addressing, address);
void fORA(Addressing, address);
void fEOR(Addressing, address);
// Jump, Branch, Compare, and Test Bits
void fJMP(Addressing, address);
void fBCC(Addressing, address);
void fBCS(Addressing, address);
void fBEQ(Addressing, address);
void fBNE(Addressing, address);
void fBMI(Addressing, address);
void fBPL(Addressing, address);
void fBVS(Addressing, address);
void fBVC(Addressing, address);
void fCMP(Addressing, address);
void fCPX(Addressing, address);
void fCPY(Addressing, address);
void fBIT(Addressing, address);
// Shift and Rotate Instructions
void fASL(Addressing, address);
void fLSR(Addressing, address);
void fROL(Addressing, address);
void fROR(Addressing, address);
// Transfer Instructions
void fTAX(Addressing, address);
void fTAY(Addressing, address);
void fTXA(Addressing, address);
void fTYA(Addressing, address);
// Stack Instructions
void fTSX(Addressing, address);
void fTXS(Addressing, address);
void fPHA(Addressing, address);
void fPHP(Addressing, address);
void fPLA(Addressing, address);
void fPLP(Addressing, address);
// Subroutine Instructions
void fJSR(Addressing, address);
void fRTS(Addressing, address);
void fRTI(Addressing, address);
// Set/Reset Insutrctions
void fCLC(Addressing, address);
void fCLD(Addressing, address);
void fCLI(Addressing, address);
void fCLV(Addressing, address);
void fSEC(Addressing, address);
void fSED(Addressing, address);
void fSEI(Addressing, address);
// NOP/BRK Instructions
void fNOP(Addressing, address);
void fBRK(Addressing, address);