diff --git a/include/mos6502.enums.h b/include/mos6502.enums.h index 8209981..8d7a5c7 100644 --- a/include/mos6502.enums.h +++ b/include/mos6502.enums.h @@ -17,13 +17,13 @@ * 6th bit. */ enum status_flags { - CARRY = 1, - ZERO = 2, - INTERRUPT = 4, - DECIMAL = 8, - BREAK = 16, - OVERFLOW = 64, - NEGATIVE = 128, + MOS_CARRY = 1, + MOS_ZERO = 2, + MOS_INTERRUPT = 4, + MOS_DECIMAL = 8, + MOS_BREAK = 16, + MOS_OVERFLOW = 64, + MOS_NEGATIVE = 128, }; /* diff --git a/include/mos6502.h b/include/mos6502.h index 701ce1e..389bbb3 100644 --- a/include/mos6502.h +++ b/include/mos6502.h @@ -32,9 +32,9 @@ * therefore, the literal value we are adding, rather than a boolean * signifier. */ -#define CARRY_BIT() \ +#define MOS_CARRY_BIT() \ vm_8bit carry = 0; \ - if (cpu->P & CARRY) carry = 1 + if (cpu->P & MOS_CARRY) carry = 1 /* * A uniform way of declaring resolve functions for address modes, which diff --git a/src/mos6502.addr.c b/src/mos6502.addr.c index f849685..098bd97 100644 --- a/src/mos6502.addr.c +++ b/src/mos6502.addr.c @@ -141,7 +141,7 @@ DEFINE_ADDR(abs) DEFINE_ADDR(abx) { ADDR_HILO(cpu); - CARRY_BIT(); + MOS_CARRY_BIT(); EFF_ADDR(addr + cpu->X + carry); return vm_segment_get(cpu->memory, eff_addr); @@ -154,7 +154,7 @@ DEFINE_ADDR(abx) DEFINE_ADDR(aby) { ADDR_HILO(cpu); - CARRY_BIT(); + MOS_CARRY_BIT(); EFF_ADDR(addr + cpu->Y + carry); return vm_segment_get(cpu->memory, eff_addr); @@ -217,7 +217,7 @@ DEFINE_ADDR(idx) DEFINE_ADDR(idy) { ADDR_LO(cpu); - CARRY_BIT(); + MOS_CARRY_BIT(); EFF_ADDR(vm_segment_get(cpu->memory, addr) + cpu->Y + carry); return vm_segment_get(cpu->memory, eff_addr); diff --git a/src/mos6502.arith.c b/src/mos6502.arith.c index 3accbd9..b33f17f 100644 --- a/src/mos6502.arith.c +++ b/src/mos6502.arith.c @@ -15,10 +15,10 @@ */ DEFINE_INST(adc) { - CARRY_BIT(); + MOS_CARRY_BIT(); cpu->A += oper + carry; - mos6502_modify_status(cpu, NEGATIVE | OVERFLOW | CARRY | ZERO, cpu->A); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_OVERFLOW | MOS_CARRY | MOS_ZERO, cpu->A); } /* @@ -30,7 +30,7 @@ DEFINE_INST(adc) */ DEFINE_INST(cmp) { - mos6502_modify_status(cpu, ZERO | NEGATIVE | CARRY, cpu->A - oper); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE | MOS_CARRY, cpu->A - oper); } /* @@ -39,7 +39,7 @@ DEFINE_INST(cmp) */ DEFINE_INST(cpx) { - mos6502_modify_status(cpu, ZERO | NEGATIVE | CARRY, cpu->X - oper); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE | MOS_CARRY, cpu->X - oper); } /* @@ -48,7 +48,7 @@ DEFINE_INST(cpx) */ DEFINE_INST(cpy) { - mos6502_modify_status(cpu, ZERO | NEGATIVE | CARRY, cpu->Y - oper); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE | MOS_CARRY, cpu->Y - oper); } /* @@ -61,7 +61,7 @@ DEFINE_INST(dec) { if (cpu->last_addr) { vm_segment_set(cpu->memory, cpu->last_addr, oper - 1); - mos6502_modify_status(cpu, NEGATIVE | ZERO, oper - 1); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, oper - 1); } } @@ -71,7 +71,7 @@ DEFINE_INST(dec) DEFINE_INST(dex) { cpu->X--; - mos6502_modify_status(cpu, NEGATIVE | ZERO, cpu->X); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, cpu->X); } /* @@ -80,7 +80,7 @@ DEFINE_INST(dex) DEFINE_INST(dey) { cpu->Y--; - mos6502_modify_status(cpu, NEGATIVE | ZERO, cpu->Y); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, cpu->Y); } /* @@ -92,7 +92,7 @@ DEFINE_INST(inc) { if (cpu->last_addr) { vm_segment_set(cpu->memory, cpu->last_addr, oper + 1); - mos6502_modify_status(cpu, NEGATIVE | ZERO, oper + 1); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, oper + 1); } } @@ -102,7 +102,7 @@ DEFINE_INST(inc) DEFINE_INST(inx) { cpu->X++; - mos6502_modify_status(cpu, NEGATIVE | ZERO, cpu->X); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, cpu->X); } /* @@ -111,7 +111,7 @@ DEFINE_INST(inx) DEFINE_INST(iny) { cpu->Y++; - mos6502_modify_status(cpu, NEGATIVE | ZERO, cpu->Y); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, cpu->Y); } /* @@ -122,8 +122,8 @@ DEFINE_INST(iny) */ DEFINE_INST(sbc) { - CARRY_BIT(); + MOS_CARRY_BIT(); cpu->A = cpu->A - oper - carry; - mos6502_modify_status(cpu, NEGATIVE | OVERFLOW | CARRY | ZERO, cpu->A); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_OVERFLOW | MOS_CARRY | MOS_ZERO, cpu->A); } diff --git a/src/mos6502.bits.c b/src/mos6502.bits.c index 5b78e59..c73c59b 100644 --- a/src/mos6502.bits.c +++ b/src/mos6502.bits.c @@ -15,7 +15,7 @@ DEFINE_INST(and) { cpu->A &= oper; - mos6502_modify_status(cpu, NEGATIVE | ZERO, cpu->A); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, cpu->A); } /* @@ -31,9 +31,9 @@ DEFINE_INST(and) */ DEFINE_INST(asl) { - cpu->P &= ~CARRY; + cpu->P &= ~MOS_CARRY; if (oper & 0x80) { - cpu->P |= CARRY; + cpu->P |= MOS_CARRY; } oper <<= 1; @@ -44,7 +44,7 @@ DEFINE_INST(asl) cpu->A = oper; } - mos6502_modify_status(cpu, NEGATIVE | CARRY | ZERO, oper); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_CARRY | MOS_ZERO, oper); } /* @@ -54,20 +54,20 @@ DEFINE_INST(asl) */ DEFINE_INST(bit) { - cpu->P &= ~NEGATIVE; - if (oper & NEGATIVE) { - cpu->P |= NEGATIVE; + cpu->P &= ~MOS_NEGATIVE; + if (oper & MOS_NEGATIVE) { + cpu->P |= MOS_NEGATIVE; } - cpu->P &= ~OVERFLOW; - if (oper & OVERFLOW) { - cpu->P |= OVERFLOW; + cpu->P &= ~MOS_OVERFLOW; + if (oper & MOS_OVERFLOW) { + cpu->P |= MOS_OVERFLOW; } if (oper & cpu->A) { - cpu->P &= ~ZERO; + cpu->P &= ~MOS_ZERO; } else { - cpu->P |= ZERO; + cpu->P |= MOS_ZERO; } } @@ -78,7 +78,7 @@ DEFINE_INST(bit) DEFINE_INST(eor) { cpu->A ^= oper; - mos6502_modify_status(cpu, NEGATIVE | ZERO, cpu->A); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, cpu->A); } /* @@ -90,9 +90,9 @@ DEFINE_INST(eor) */ DEFINE_INST(lsr) { - cpu->P &= ~CARRY; + cpu->P &= ~MOS_CARRY; if (oper & 0x01) { - cpu->P |= CARRY; + cpu->P |= MOS_CARRY; } oper >>= 1; @@ -103,8 +103,8 @@ DEFINE_INST(lsr) cpu->A = oper; } - // NEGATIVE is intentionally not included here. - mos6502_modify_status(cpu, CARRY | ZERO, oper); + // MOS_NEGATIVE is intentionally not included here. + mos6502_modify_status(cpu, MOS_CARRY | MOS_ZERO, oper); } /* @@ -114,7 +114,7 @@ DEFINE_INST(lsr) DEFINE_INST(ora) { cpu->A |= oper; - mos6502_modify_status(cpu, NEGATIVE | ZERO, cpu->A); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, cpu->A); } /* @@ -124,7 +124,7 @@ DEFINE_INST(ora) */ DEFINE_INST(rol) { - CARRY_BIT(); + MOS_CARRY_BIT(); if (oper & 0x80) { carry = 1; @@ -142,7 +142,7 @@ DEFINE_INST(rol) cpu->A = oper; } - mos6502_modify_status(cpu, NEGATIVE | CARRY | ZERO, oper); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_CARRY | MOS_ZERO, oper); } /* @@ -151,7 +151,7 @@ DEFINE_INST(rol) */ DEFINE_INST(ror) { - CARRY_BIT(); + MOS_CARRY_BIT(); if (oper & 0x01) { carry = 1; @@ -169,5 +169,5 @@ DEFINE_INST(ror) cpu->A = oper; } - mos6502_modify_status(cpu, NEGATIVE | CARRY | ZERO, oper); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_CARRY | MOS_ZERO, oper); } diff --git a/src/mos6502.branch.c b/src/mos6502.branch.c index 8e93e83..80cdd3d 100644 --- a/src/mos6502.branch.c +++ b/src/mos6502.branch.c @@ -21,7 +21,7 @@ */ DEFINE_INST(bcc) { - JUMP_IF(~cpu->P & CARRY); + JUMP_IF(~cpu->P & MOS_CARRY); } /* @@ -29,7 +29,7 @@ DEFINE_INST(bcc) */ DEFINE_INST(bcs) { - JUMP_IF(cpu->P & CARRY); + JUMP_IF(cpu->P & MOS_CARRY); } /* @@ -38,7 +38,7 @@ DEFINE_INST(bcs) */ DEFINE_INST(beq) { - JUMP_IF(cpu->P & ZERO); + JUMP_IF(cpu->P & MOS_ZERO); } /* @@ -46,7 +46,7 @@ DEFINE_INST(beq) */ DEFINE_INST(bmi) { - JUMP_IF(cpu->P & NEGATIVE); + JUMP_IF(cpu->P & MOS_NEGATIVE); } /* @@ -55,7 +55,7 @@ DEFINE_INST(bmi) */ DEFINE_INST(bne) { - JUMP_IF(~cpu->P & ZERO); + JUMP_IF(~cpu->P & MOS_ZERO); } /* @@ -64,7 +64,7 @@ DEFINE_INST(bne) */ DEFINE_INST(bpl) { - JUMP_IF(~cpu->P & NEGATIVE); + JUMP_IF(~cpu->P & MOS_NEGATIVE); } /* @@ -72,7 +72,7 @@ DEFINE_INST(bpl) */ DEFINE_INST(bvc) { - JUMP_IF(~cpu->P & OVERFLOW); + JUMP_IF(~cpu->P & MOS_OVERFLOW); } /* @@ -80,5 +80,5 @@ DEFINE_INST(bvc) */ DEFINE_INST(bvs) { - JUMP_IF(cpu->P & OVERFLOW); + JUMP_IF(cpu->P & MOS_OVERFLOW); } diff --git a/src/mos6502.c b/src/mos6502.c index 0ccc102..1d7deb9 100644 --- a/src/mos6502.c +++ b/src/mos6502.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "log.h" #include "mos6502.h" @@ -252,31 +253,31 @@ mos6502_set_status(mos6502 *cpu, vm_8bit status) void mos6502_modify_status(mos6502 *cpu, vm_8bit status, vm_8bit oper) { - if (status & NEGATIVE) { - cpu->P &= ~NEGATIVE; + if (status & MOS_NEGATIVE) { + cpu->P &= ~MOS_NEGATIVE; if (oper & 0x80) { - cpu->P |= NEGATIVE; + cpu->P |= MOS_NEGATIVE; } } - if (status & OVERFLOW) { - cpu->P &= ~OVERFLOW; - if (oper & OVERFLOW) { - cpu->P |= OVERFLOW; + if (status & MOS_OVERFLOW) { + cpu->P &= ~MOS_OVERFLOW; + if (oper & MOS_OVERFLOW) { + cpu->P |= MOS_OVERFLOW; } } - if (status & CARRY) { - cpu->P &= ~CARRY; + if (status & MOS_CARRY) { + cpu->P &= ~MOS_CARRY; if (oper > 0) { - cpu->P |= CARRY; + cpu->P |= MOS_CARRY; } } - if (status & ZERO) { - cpu->P &= ~ZERO; + if (status & MOS_ZERO) { + cpu->P &= ~MOS_ZERO; if (oper == 0) { - cpu->P |= ZERO; + cpu->P |= MOS_ZERO; } } } @@ -352,7 +353,7 @@ void mos6502_execute(mos6502 *cpu, vm_8bit opcode) { vm_8bit operand; - //int cycles; + int cycles; mos6502_address_resolver resolver; mos6502_instruction_handler handler; @@ -380,9 +381,11 @@ mos6502_execute(mos6502 *cpu, vm_8bit opcode) // with the idea that certain instructions -- in certain address // modes -- were more expensive than others, and you want those // programs to feel faster or slower in relation to that. - //cycles = mos6502_cycles(cpu, opcode); + cycles = mos6502_cycles(cpu, opcode); - // FIXME: actually emulate the cycles + // FIXME: uh this probably isn't right, but I wanted to do + // something. + usleep(cycles * 100000); // Ok -- we're done! This wasn't so hard, was it? return; diff --git a/src/mos6502.exec.c b/src/mos6502.exec.c index fe20253..c751973 100644 --- a/src/mos6502.exec.c +++ b/src/mos6502.exec.c @@ -16,7 +16,7 @@ DEFINE_INST(brk) { mos6502_push_stack(cpu, cpu->PC); mos6502_push_stack(cpu, cpu->P); - cpu->P |= INTERRUPT; + cpu->P |= MOS_INTERRUPT; cpu->PC += 2; } diff --git a/src/mos6502.loadstor.c b/src/mos6502.loadstor.c index 6b13615..096af5b 100644 --- a/src/mos6502.loadstor.c +++ b/src/mos6502.loadstor.c @@ -14,7 +14,7 @@ */ DEFINE_INST(lda) { - mos6502_modify_status(cpu, ZERO | NEGATIVE, oper); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE, oper); cpu->A = oper; } @@ -23,7 +23,7 @@ DEFINE_INST(lda) */ DEFINE_INST(ldx) { - mos6502_modify_status(cpu, ZERO | NEGATIVE, oper); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE, oper); cpu->X = oper; } @@ -32,7 +32,7 @@ DEFINE_INST(ldx) */ DEFINE_INST(ldy) { - mos6502_modify_status(cpu, ZERO | NEGATIVE, oper); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE, oper); cpu->Y = oper; } @@ -58,7 +58,7 @@ DEFINE_INST(php) DEFINE_INST(pla) { cpu->A = mos6502_pop_stack(cpu); - mos6502_modify_status(cpu, NEGATIVE | ZERO, cpu->A); + mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, cpu->A); } /* @@ -100,7 +100,7 @@ DEFINE_INST(sty) */ DEFINE_INST(tax) { - mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->A); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE, cpu->A); cpu->X = cpu->A; } @@ -109,7 +109,7 @@ DEFINE_INST(tax) */ DEFINE_INST(tay) { - mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->A); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE, cpu->A); cpu->Y = cpu->A; } @@ -118,7 +118,7 @@ DEFINE_INST(tay) */ DEFINE_INST(tsx) { - mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->S); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE, cpu->S); cpu->X = cpu->S; } @@ -127,7 +127,7 @@ DEFINE_INST(tsx) */ DEFINE_INST(txa) { - mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->X); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE, cpu->X); cpu->A = cpu->X; } @@ -136,7 +136,7 @@ DEFINE_INST(txa) */ DEFINE_INST(txs) { - mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->X); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE, cpu->X); cpu->S = cpu->X; } @@ -145,6 +145,6 @@ DEFINE_INST(txs) */ DEFINE_INST(tya) { - mos6502_modify_status(cpu, ZERO | NEGATIVE, cpu->Y); + mos6502_modify_status(cpu, MOS_ZERO | MOS_NEGATIVE, cpu->Y); cpu->A = cpu->Y; } diff --git a/src/mos6502.stat.c b/src/mos6502.stat.c index 4718189..eb628d4 100644 --- a/src/mos6502.stat.c +++ b/src/mos6502.stat.c @@ -13,7 +13,7 @@ */ DEFINE_INST(clc) { - cpu->P &= ~CARRY; + cpu->P &= ~MOS_CARRY; } /* @@ -21,7 +21,7 @@ DEFINE_INST(clc) */ DEFINE_INST(cld) { - cpu->P &= ~DECIMAL; + cpu->P &= ~MOS_DECIMAL; } /* @@ -29,7 +29,7 @@ DEFINE_INST(cld) */ DEFINE_INST(cli) { - cpu->P &= ~INTERRUPT; + cpu->P &= ~MOS_INTERRUPT; } /* @@ -37,7 +37,7 @@ DEFINE_INST(cli) */ DEFINE_INST(clv) { - cpu->P &= ~OVERFLOW; + cpu->P &= ~MOS_OVERFLOW; } /* @@ -45,7 +45,7 @@ DEFINE_INST(clv) */ DEFINE_INST(sec) { - cpu->P |= CARRY; + cpu->P |= MOS_CARRY; } /* @@ -53,7 +53,7 @@ DEFINE_INST(sec) */ DEFINE_INST(sed) { - cpu->P |= DECIMAL; + cpu->P |= MOS_DECIMAL; } /* @@ -61,5 +61,5 @@ DEFINE_INST(sed) */ DEFINE_INST(sei) { - cpu->P |= INTERRUPT; + cpu->P |= MOS_INTERRUPT; } diff --git a/tests/mos6502.addr.c b/tests/mos6502.addr.c index 2fd03b8..30d7566 100644 --- a/tests/mos6502.addr.c +++ b/tests/mos6502.addr.c @@ -58,7 +58,7 @@ Test(mos6502_addr, addr_mode_abx_carry1) SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 1, 0x30); cpu->X = 3; - cpu->P = cpu->P | CARRY; + cpu->P = cpu->P | MOS_CARRY; cr_assert_eq(mos6502_resolve_abx(cpu), 111); } @@ -77,7 +77,7 @@ Test(mos6502_addr, addr_mode_aby_carry1) SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 1, 0x30); cpu->Y = 3; - cpu->P = cpu->P | CARRY; + cpu->P = cpu->P | MOS_CARRY; cr_assert_eq(mos6502_resolve_aby(cpu), 111); } diff --git a/tests/mos6502.arith.c b/tests/mos6502.arith.c index 052ded1..f1c3524 100644 --- a/tests/mos6502.arith.c +++ b/tests/mos6502.arith.c @@ -12,7 +12,7 @@ Test(mos6502_arith, adc) mos6502_handle_adc(cpu, 3); cr_assert_eq(cpu->A, 8); - cpu->P |= CARRY; + cpu->P |= MOS_CARRY; mos6502_handle_adc(cpu, 64); cr_assert_eq(cpu->A, 73); } @@ -21,39 +21,39 @@ Test(mos6502_arith, cmp) { cpu->A = 5; mos6502_handle_cmp(cpu, 3); - cr_assert_eq(cpu->P & CARRY, CARRY); - cr_assert_eq(cpu->P & NEGATIVE, 0); - cr_assert_eq(cpu->P & ZERO, 0); + cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY); + cr_assert_eq(cpu->P & MOS_NEGATIVE, 0); + cr_assert_eq(cpu->P & MOS_ZERO, 0); cpu->A = 3; mos6502_handle_cmp(cpu, 3); - cr_assert_eq(cpu->P & CARRY, 0); - cr_assert_eq(cpu->P & NEGATIVE, 0); - cr_assert_eq(cpu->P & ZERO, ZERO); + cr_assert_eq(cpu->P & MOS_CARRY, 0); + cr_assert_eq(cpu->P & MOS_NEGATIVE, 0); + cr_assert_eq(cpu->P & MOS_ZERO, MOS_ZERO); cpu->A = 192; mos6502_handle_cmp(cpu, 3); - cr_assert_eq(cpu->P & CARRY, CARRY); - cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); - cr_assert_eq(cpu->P & ZERO, 0); + cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY); + cr_assert_eq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE); + cr_assert_eq(cpu->P & MOS_ZERO, 0); } Test(mos6502_arith, cpx) { cpu->X = 5; mos6502_handle_cpx(cpu, 3); - cr_assert_eq(cpu->P & CARRY, CARRY); - cr_assert_eq(cpu->P & NEGATIVE, 0); - cr_assert_eq(cpu->P & ZERO, 0); + cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY); + cr_assert_eq(cpu->P & MOS_NEGATIVE, 0); + cr_assert_eq(cpu->P & MOS_ZERO, 0); } Test(mos6502_arith, cpy) { cpu->Y = 5; mos6502_handle_cpy(cpu, 3); - cr_assert_eq(cpu->P & CARRY, CARRY); - cr_assert_eq(cpu->P & NEGATIVE, 0); - cr_assert_eq(cpu->P & ZERO, 0); + cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY); + cr_assert_eq(cpu->P & MOS_NEGATIVE, 0); + cr_assert_eq(cpu->P & MOS_ZERO, 0); } Test(mos6502_arith, dec) @@ -115,7 +115,7 @@ Test(mos6502_arith, sbc) mos6502_handle_sbc(cpu, 3); cr_assert_eq(cpu->A, 2); - cpu->P |= CARRY; + cpu->P |= MOS_CARRY; cpu->A = 16; mos6502_handle_sbc(cpu, 8); cr_assert_eq(cpu->A, 7); diff --git a/tests/mos6502.bits.c b/tests/mos6502.bits.c index 4ae9295..baa977c 100644 --- a/tests/mos6502.bits.c +++ b/tests/mos6502.bits.c @@ -31,29 +31,29 @@ Test(mos6502_bits, bit) { cpu->A = 5; mos6502_handle_bit(cpu, 129); - cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); - cr_assert_eq(cpu->P & OVERFLOW, 0); - cr_assert_eq(cpu->P & ZERO, 0); + cr_assert_eq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE); + cr_assert_eq(cpu->P & MOS_OVERFLOW, 0); + cr_assert_eq(cpu->P & MOS_ZERO, 0); mos6502_handle_bit(cpu, 193); - cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); - cr_assert_eq(cpu->P & OVERFLOW, OVERFLOW); - cr_assert_eq(cpu->P & ZERO, 0); + cr_assert_eq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE); + cr_assert_eq(cpu->P & MOS_OVERFLOW, MOS_OVERFLOW); + cr_assert_eq(cpu->P & MOS_ZERO, 0); mos6502_handle_bit(cpu, 65); - cr_assert_eq(cpu->P & NEGATIVE, 0); - cr_assert_eq(cpu->P & OVERFLOW, OVERFLOW); - cr_assert_eq(cpu->P & ZERO, 0); + cr_assert_eq(cpu->P & MOS_NEGATIVE, 0); + cr_assert_eq(cpu->P & MOS_OVERFLOW, MOS_OVERFLOW); + cr_assert_eq(cpu->P & MOS_ZERO, 0); mos6502_handle_bit(cpu, 33); - cr_assert_eq(cpu->P & NEGATIVE, 0); - cr_assert_eq(cpu->P & OVERFLOW, 0); - cr_assert_eq(cpu->P & ZERO, 0); + cr_assert_eq(cpu->P & MOS_NEGATIVE, 0); + cr_assert_eq(cpu->P & MOS_OVERFLOW, 0); + cr_assert_eq(cpu->P & MOS_ZERO, 0); mos6502_handle_bit(cpu, 0); - cr_assert_eq(cpu->P & NEGATIVE, 0); - cr_assert_eq(cpu->P & OVERFLOW, 0); - cr_assert_eq(cpu->P & ZERO, ZERO); + cr_assert_eq(cpu->P & MOS_NEGATIVE, 0); + cr_assert_eq(cpu->P & MOS_OVERFLOW, 0); + cr_assert_eq(cpu->P & MOS_ZERO, MOS_ZERO); } Test(mos6502_bits, eor) @@ -71,12 +71,12 @@ Test(mos6502_bits, lsr) { mos6502_handle_lsr(cpu, 5); cr_assert_eq(cpu->A, 2); - cr_assert_eq(cpu->P & CARRY, CARRY); + cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY); cpu->last_addr = 123; mos6502_handle_lsr(cpu, 22); cr_assert_eq(vm_segment_get(cpu->memory, 123), 11); - cr_assert_eq(cpu->P & CARRY, CARRY); + cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY); } Test(mos6502_bits, ora) diff --git a/tests/mos6502.branch.c b/tests/mos6502.branch.c index caba64d..b97c55d 100644 --- a/tests/mos6502.branch.c +++ b/tests/mos6502.branch.c @@ -12,7 +12,7 @@ Test(mos6502_branch, bcc) mos6502_handle_bcc(cpu, 0); cr_assert_eq(cpu->PC, 123); - cpu->P |= CARRY; + cpu->P |= MOS_CARRY; cpu->last_addr = 125; mos6502_handle_bcc(cpu, 0); cr_assert_neq(cpu->PC, 125); @@ -24,7 +24,7 @@ Test(mos6502_branch, bcs) mos6502_handle_bcs(cpu, 0); cr_assert_neq(cpu->PC, 123); - cpu->P |= CARRY; + cpu->P |= MOS_CARRY; cpu->last_addr = 125; mos6502_handle_bcs(cpu, 0); cr_assert_eq(cpu->PC, 125); @@ -36,7 +36,7 @@ Test(mos6502_branch, beq) mos6502_handle_beq(cpu, 0); cr_assert_neq(cpu->PC, 123); - cpu->P |= ZERO; + cpu->P |= MOS_ZERO; cpu->last_addr = 125; mos6502_handle_beq(cpu, 0); cr_assert_eq(cpu->PC, 125); @@ -48,7 +48,7 @@ Test(mos6502_branch, bmi) mos6502_handle_bmi(cpu, 0); cr_assert_neq(cpu->PC, 123); - cpu->P |= NEGATIVE; + cpu->P |= MOS_NEGATIVE; cpu->last_addr = 125; mos6502_handle_bmi(cpu, 0); cr_assert_eq(cpu->PC, 125); @@ -60,7 +60,7 @@ Test(mos6502_branch, bne) mos6502_handle_bne(cpu, 0); cr_assert_eq(cpu->PC, 123); - cpu->P |= ZERO; + cpu->P |= MOS_ZERO; cpu->last_addr = 125; mos6502_handle_bne(cpu, 0); cr_assert_neq(cpu->PC, 125); @@ -72,7 +72,7 @@ Test(mos6502_branch, bpl) mos6502_handle_bpl(cpu, 0); cr_assert_eq(cpu->PC, 123); - cpu->P |= NEGATIVE; + cpu->P |= MOS_NEGATIVE; cpu->last_addr = 125; mos6502_handle_bpl(cpu, 0); cr_assert_neq(cpu->PC, 125); @@ -84,7 +84,7 @@ Test(mos6502_branch, bvc) mos6502_handle_bvc(cpu, 0); cr_assert_eq(cpu->PC, 123); - cpu->P |= OVERFLOW; + cpu->P |= MOS_OVERFLOW; cpu->last_addr = 125; mos6502_handle_bvc(cpu, 0); cr_assert_neq(cpu->PC, 125); @@ -96,7 +96,7 @@ Test(mos6502_branch, bvs) mos6502_handle_bvs(cpu, 0); cr_assert_neq(cpu->PC, 123); - cpu->P |= OVERFLOW; + cpu->P |= MOS_OVERFLOW; cpu->last_addr = 125; mos6502_handle_bvs(cpu, 0); cr_assert_eq(cpu->PC, 125); diff --git a/tests/mos6502.c b/tests/mos6502.c index 62417f6..12bb617 100644 --- a/tests/mos6502.c +++ b/tests/mos6502.c @@ -47,31 +47,31 @@ Test(mos6502, pop_stack) Test(mos6502, modify_status) { - mos6502_modify_status(cpu, NEGATIVE, 130); - cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); - mos6502_modify_status(cpu, NEGATIVE, 123); - cr_assert_neq(cpu->P & NEGATIVE, NEGATIVE); + mos6502_modify_status(cpu, MOS_NEGATIVE, 130); + cr_assert_eq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE); + mos6502_modify_status(cpu, MOS_NEGATIVE, 123); + cr_assert_neq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE); - mos6502_modify_status(cpu, OVERFLOW, 123); - cr_assert_eq(cpu->P & OVERFLOW, OVERFLOW); - mos6502_modify_status(cpu, OVERFLOW, 44); - cr_assert_neq(cpu->P & OVERFLOW, OVERFLOW); + mos6502_modify_status(cpu, MOS_OVERFLOW, 123); + cr_assert_eq(cpu->P & MOS_OVERFLOW, MOS_OVERFLOW); + mos6502_modify_status(cpu, MOS_OVERFLOW, 44); + cr_assert_neq(cpu->P & MOS_OVERFLOW, MOS_OVERFLOW); - mos6502_modify_status(cpu, CARRY, 23); - cr_assert_eq(cpu->P & CARRY, CARRY); - mos6502_modify_status(cpu, CARRY, 0); - cr_assert_neq(cpu->P & CARRY, CARRY); + mos6502_modify_status(cpu, MOS_CARRY, 23); + cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY); + mos6502_modify_status(cpu, MOS_CARRY, 0); + cr_assert_neq(cpu->P & MOS_CARRY, MOS_CARRY); - mos6502_modify_status(cpu, ZERO, 0); - cr_assert_eq(cpu->P & ZERO, ZERO); - mos6502_modify_status(cpu, ZERO, 1); - cr_assert_neq(cpu->P & ZERO, ZERO); + mos6502_modify_status(cpu, MOS_ZERO, 0); + cr_assert_eq(cpu->P & MOS_ZERO, MOS_ZERO); + mos6502_modify_status(cpu, MOS_ZERO, 1); + cr_assert_neq(cpu->P & MOS_ZERO, MOS_ZERO); } Test(mos6502, set_status) { - mos6502_set_status(cpu, BREAK | INTERRUPT | DECIMAL); - cr_assert_eq(cpu->P & (BREAK | INTERRUPT | DECIMAL), BREAK | INTERRUPT | DECIMAL); + mos6502_set_status(cpu, MOS_BREAK | MOS_INTERRUPT | MOS_DECIMAL); + cr_assert_eq(cpu->P & (MOS_BREAK | MOS_INTERRUPT | MOS_DECIMAL), MOS_BREAK | MOS_INTERRUPT | MOS_DECIMAL); } Test(mos6502, instruction) diff --git a/tests/mos6502.exec.c b/tests/mos6502.exec.c index b90417c..1cd56f0 100644 --- a/tests/mos6502.exec.c +++ b/tests/mos6502.exec.c @@ -13,7 +13,7 @@ Test(mos6502_exec, brk) cpu->PC = 123; mos6502_handle_brk(cpu, 0); cr_assert_eq(cpu->PC, 125); - cr_assert_eq(cpu->P & INTERRUPT, INTERRUPT); + cr_assert_eq(cpu->P & MOS_INTERRUPT, MOS_INTERRUPT); cr_assert_eq(mos6502_pop_stack(cpu), orig_P); cr_assert_eq(mos6502_pop_stack(cpu), 123); diff --git a/tests/mos6502.stat.c b/tests/mos6502.stat.c index ce51770..16ca2d5 100644 --- a/tests/mos6502.stat.c +++ b/tests/mos6502.stat.c @@ -8,49 +8,49 @@ TestSuite(mos6502_stat, .init = setup, .fini = teardown); Test(mos6502_stat, clc) { - cpu->P = CARRY | DECIMAL; + cpu->P = MOS_CARRY | MOS_DECIMAL; mos6502_handle_clc(cpu, 0); - cr_assert_eq(cpu->P & CARRY, 0); + cr_assert_eq(cpu->P & MOS_CARRY, 0); } Test(mos6502_stat, cld) { - cpu->P = DECIMAL | CARRY; + cpu->P = MOS_DECIMAL | MOS_CARRY; mos6502_handle_cld(cpu, 0); - cr_assert_eq(cpu->P & DECIMAL, 0); + cr_assert_eq(cpu->P & MOS_DECIMAL, 0); } Test(mos6502_stat, cli) { - cpu->P = CARRY | INTERRUPT; + cpu->P = MOS_CARRY | MOS_INTERRUPT; mos6502_handle_cli(cpu, 0); - cr_assert_eq(cpu->P & INTERRUPT, 0); + cr_assert_eq(cpu->P & MOS_INTERRUPT, 0); } Test(mos6502_stat, clv) { - cpu->P = CARRY | OVERFLOW; + cpu->P = MOS_CARRY | MOS_OVERFLOW; mos6502_handle_clv(cpu, 0); - cr_assert_eq(cpu->P & OVERFLOW, 0); + cr_assert_eq(cpu->P & MOS_OVERFLOW, 0); } Test(mos6502_stat, sec) { cpu->P = 0; mos6502_handle_sec(cpu, 0); - cr_assert_eq(cpu->P & CARRY, CARRY); + cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY); } Test(mos6502_stat, sed) { cpu->P = 0; mos6502_handle_sed(cpu, 0); - cr_assert_eq(cpu->P & DECIMAL, DECIMAL); + cr_assert_eq(cpu->P & MOS_DECIMAL, MOS_DECIMAL); } Test(mos6502_stat, sei) { cpu->P = 0; mos6502_handle_sei(cpu, 0); - cr_assert_eq(cpu->P & INTERRUPT, INTERRUPT); + cr_assert_eq(cpu->P & MOS_INTERRUPT, MOS_INTERRUPT); }