summaryrefslogtreecommitdiff
path: root/src/cpu/6502.c
blob: 7ae3f16dfa3f9bdb1d18d1f2be830457926575f5 (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
//	6502.h
//	Main elements of the 6502 CPU

#include"6502.h"

byte acc, X, Y, P, S = 0x00;
address PC = 0x0000;
byte* Memory;


byte GetFlag(byte flag) {
	return (P & flag) ? 1 : 0;
}


void SetFlag(byte flag, int x) {
	P = (P & ~flag) | ((x != 0) ? flag : 0);
}


void SetFlag_N(byte x){
	P = (x & flag_N) | (P & ~flag_N);
}


void SetFlag_V(byte x, byte y){
	address z = (address)x + (address)y;
	if ((x & 0x80) != (y & 0x80))
		SetFlag(flag_V, 1);
	else
		SetFlag(flag_V, 0);
}


void SetFlag_Z(int x){
	if (x == 0)
		SetFlag(flag_Z, 1);
	else
		SetFlag(flag_Z, 0);
}


byte GetStack() {
	S--;
	return GetMemory(0x01FF - S);
}


void SetStack(byte x) {
	SetMemory(0x01FF - S, x);
	S++;
}