-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflags.cpp
54 lines (49 loc) · 1.07 KB
/
flags.cpp
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
#include "system.h"
/*
* setter functions return true or false based on whether flag was set or not
*
* order of flags:
* Bit No. 7 6 5 4 3 2 1 0
S V B D I Z C
S = Sign = Negative
V = oVerflow
bit 5 is always set to one
B = break flag
D = decimal flag (not used in NES)
I = interrupt
Z = zero
C = carry
* https://wiki.nesdev.com/w/index.php/Status_flags
*/
bool setzeroflag(uint8_t compval, cpustate * cpu)
{
// if compval is 0, zero flag is set
if(compval == 0)
{
cpu->p |= (1 << 1);
return true;
}
else
{
cpu->p &= ~(1 << 1);
return false;
}
}
bool setnegflag(uint8_t compval, cpustate * cpu)
{
// if bit 7 of compval is on, negative flag is set
if(compval & 0x80)
{
cpu->p |= (1 << 7);
return true;
}
else
{
cpu->p &= ~(1 << 7);
return false;
}
}
bool getflag(cpustate * cpu, int bit)
{
return (cpu->p & (1 << bit)) == (1 << bit);
}