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
|
// 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) == flag) ? 1 : 0;
}
void SetFlag(byte flag, int x) {
if (x == 1){
if ((P & flag) == 0x0) P += flag;
}else if (x == 0){
if ((P & flag) == flag) P -= flag;
}
else{
fprintf(stderr, "SetFlag() passed arg neither 0 or 1");
}
}
void flagSet(byte flag){
P |= flag;
}
void flagClear(byte flag){
P &= ~flag;
}
// Functions which perform reusable routines for finding if a specific flag should be set.
void SetFlagN(byte x){
/*if ((x & flag_N) == flag_N)
SetFlag(flag_N, 1);
else
SetFlag(flag_N, 0);*/
P = (x & flag_N) | (P & ~flag_N);
}
//Perform prior to any changes TODO: FIX THIS! WTF WERE YOU THINKING?
void SetFlagV(byte x, byte y){
address z = (address)x + (address)y;
if (z > 0xFF)
SetFlag(flag_V, 1);
else
SetFlag(flag_V, 0);
}
/*void SetFlagB(){ //WORK ON
SetFlag(flag_B, 1);
}*/
/*void SetFlagD(){
SetFlag(flag_D, 1);
}*/
/*void SetFlagI(){ //WORK ON
SetFlag(flag_Z, 1);
}*/
void SetFlagZ(int x){
if (x == 0)
SetFlag(flag_Z, 1);
else
SetFlag(flag_Z, 0);
}
/*void SetFlagC(){
SetFlag(flag_Z, 1);
}*/
/*byte GetMemory(address x){
return Memory[x];
}
void SetMemory(address x, byte y){
Memory[x] = y;
}*/
byte GetStack() {
S--;
return GetMemory(0x01FF - S);
}
void SetStack(byte x) {
SetMemory(0x01FF - S, x);
S++;
}
|