-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
48 lines (37 loc) · 901 Bytes
/
main.c
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
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
typedef struct {
uint8_t A;
uint8_t Y;
uint8_t X;
uint8_t PCH;
uint8_t PCL;
uint8_t S;
uint8_t P;
} Cpu_state;
// Set bit (0-7) in registry
void set_bit(uint8_t *reg, int shift){
*reg = *reg | (0x01 << shift); // OR (bitwise)
}
// Unset bit (0-7) in registry
void unset_bit(uint8_t *reg, int shift){
*reg = *reg ^ (0x01 << shift); // XOR (bitwise)
// could also be done as AND reg (NOT (0x01 << shift))
}
// Get bit (0-7) from registry
bool get_bit(uint8_t *reg, int shift) {
return *reg & (0x01 << shift); // AND (bitwise)
}
int main() {
uint8_t reg = 0xdf; //1101 1111
set_bit(®, 5);
bool active = get_bit(®, 5);
printf("Active 5: %d\n", active);
active = get_bit(®, 4);
printf("Active 4: %d\n", active);
unset_bit(®, 5);
active = get_bit(®, 5);
printf("Active 5: %d\n", active);
return 0;
}