summaryrefslogtreecommitdiff
path: root/CPU.c
diff options
context:
space:
mode:
authorleo <leo@azuminha.com>2024-03-18 21:21:20 -0300
committerleo <leo@azuminha.com>2024-03-18 21:21:20 -0300
commit1cffb789b5d258c3d6fced0fb949f068b1b23bae (patch)
tree069aa9dc20433c38893cc4354cab63d626415708 /CPU.c
parent21bb49029a4a30c80714a4b05193e1ba58117d5a (diff)
CLC
CLD CLI CLV CMP CPX CPY
Diffstat (limited to 'CPU.c')
-rw-r--r--CPU.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/CPU.c b/CPU.c
index b17b8db..a0fe581 100644
--- a/CPU.c
+++ b/CPU.c
@@ -194,6 +194,20 @@ void asl(struct CPU *cpu, enum adressing_mode mode){
update_zero_and_negative_flags(cpu, value);
}
+void compare(struct CPU *cpu, enum adressing_mode mode, uint8_t comp_val){
+ uint16_t addr = get_operand_address(cpu, mode);
+ uint8_t value = mem_read(cpu, addr);
+
+
+ if(comp_val >= value){
+ enable_flag(cpu, CARRY);
+ }else{
+ disable_flag(cpu, CARRY);
+ }
+
+ update_zero_and_negative_flags(cpu, (comp_val - value));
+}
+
void interpret(struct CPU *cpu){
while(1){
@@ -259,6 +273,27 @@ void interpret(struct CPU *cpu){
case BVS:
branch(cpu, test_flag(cpu, OVERFLOW));
break;
+ case CLC:
+ disable_flag(cpu, CARRY);
+ break;
+ case CLD:
+ disable_flag(cpu, DECIMAL_MODE);
+ break;
+ case CLI:
+ disable_flag(cpu, INTERRUPT_DISABLE);
+ break;
+ case CLV:
+ disable_flag(cpu, OVERFLOW);
+ break;
+ case CMP:
+ compare(cpu, OPCODE[opcode].mode, cpu->register_a);
+ break;
+ case CPX:
+ compare(cpu, OPCODE[opcode].mode, cpu->register_x);
+ break;
+ case CPY:
+ compare(cpu, OPCODE[opcode].mode, cpu->register_y);
+ break;
default:
break;
}
@@ -314,4 +349,4 @@ int main(){
load_and_run(&cpu_6, program_6);
assert(cpu_6.register_a == 0x55);
printf("PASSED\n");
-} \ No newline at end of file
+}