summaryrefslogtreecommitdiff
path: root/addressing.h
blob: 1a80466632d31f08a8f013746053e6ffcab46427 (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
#define FALSE	0
#define TRUE	1

enum Addressing {
	eImmediate,
	eAccumulator,
	eAbsolute,
	eAbsoluteIndexedX,
	eAbsoluteIndexedY,
	eZeroPage,
	eZeroPageIndexedX,
	eZeroPageIndexedY,
	eIndexedIndirect,
	eIndirectIndexed,
	eImplied,
	eIndirectAbsolute,
	eRelative
};

typedef int Addressing;

	/*
	*	Any addressing method which is single line commented out without definition
	*	implies that handling should be hard-coded in the switch case of the
	*	instruction from which it came.
	*/



struct AddData{
	int cycles;
	int length;
	byte value;
};

AddData fAddress(Addressing addr, short x) {
	AddData ret;
	switch(addr){
		case eImmediate:		ret.value = x;		break;
		case eAccumulator:		ret.value = acc;	break;

		case eAbsolute:			ret.value = Memory[x];			break;
		case eAbsoluteIndexedX:	ret.value = Memory[(x + X)];	break;
		case eAbsoluteIndexedY:	ret.value = Memory[(x + Y)];	break;

		case eZeroPage:			ret.value = Memory[(x & 0x00FF)];		break;
		case eZeroPageIndexedX:	ret.value = Memory[((x = X) & 0x00FF)];	break;
		case eZeroPageIndexedY:	ret.value = Memory[((x = Y) & 0x00FF)];	break;

		case eIndexedIndirect:	ret.value = Memory[((x + X) << 8) + ((x + X) + 1)];	break;
		case eIndirectIndexed:	ret.value = ((Memory[x] + Memory[(x+1 << 8)]) + Y);	break;

		//case eImplied: No reference
		//case eIndirectAbsolute: Only used in the JMP instruction
		//case eRelative: Only used in branch instructions
	}

	switch(addr){
		case eAbsolute: case eAbsoluteIndexedX: case eAbsoluteIndexedY:
			ret.length = 3;	break;
		case eAccumulator:
			ret.length = 1;	break;
		default:
			ret.length = 2;	break;
	}


	// FOR TIME, FIND THE PARTICULAR VALUE SET FOR THE FIRST TYPE,
	// APPLY RELATIVE MOVEMENT
	//  THEN LET THE FUNCTION WHICH CALLED fAddress HANDLE A NON-TYPICAL VALUE.

}