diff --git a/execute.go b/execute.go index 3ae67fe..2296930 100644 --- a/execute.go +++ b/execute.go @@ -150,6 +150,56 @@ func buildOpLoad(addressMode int, regDst int) opFunc { } } +func buildOpUpdateFlag(flag uint8, value bool) opFunc { + return func(s *state, line []uint8, opcode opcode) { + s.registers.updateFlag(flag, value) + } +} + +/* +TODO: + +ADC +SBC + +AND +ORA + +ASL +EOR +LSR + +BIT +CMP +CPX +CPY + +BRK + +BCC +BCS +BEQ +BMI +BPL +BVC +BVS + +JMP +JSR +RTI +RTS + +PHA +PHP +PLA +PLP + +STA +STX +STY + +*/ + var opcodes = [256]opcode{ 0x2A: opcode{"ROL", 1, 2, buildRotate(modeAccumulator, true)}, 0x26: opcode{"ROL", 2, 5, buildRotate(modeZeroPage, true)}, @@ -163,6 +213,15 @@ var opcodes = [256]opcode{ 0x6E: opcode{"ROR", 3, 6, buildRotate(modeAbsolute, false)}, 0x7E: opcode{"ROR", 3, 7, buildRotate(modeAbsoluteX, false)}, + 0x38: opcode{"SEC", 1, 2, buildOpUpdateFlag(flagC, true)}, + 0xF8: opcode{"SED", 1, 2, buildOpUpdateFlag(flagD, true)}, + 0x78: opcode{"SEI", 1, 2, buildOpUpdateFlag(flagI, true)}, + + 0x18: opcode{"CLC", 1, 2, buildOpUpdateFlag(flagC, false)}, + 0xD8: opcode{"CLD", 1, 2, buildOpUpdateFlag(flagD, false)}, + 0x58: opcode{"CLI", 1, 2, buildOpUpdateFlag(flagI, false)}, + 0xB8: opcode{"CLV", 1, 2, buildOpUpdateFlag(flagV, false)}, + 0xE6: opcode{"INC", 2, 5, buildOpIncDec(modeZeroPage, true)}, 0xF6: opcode{"INC", 2, 6, buildOpIncDec(modeZeroPageX, true)}, 0xEE: opcode{"INC", 3, 6, buildOpIncDec(modeAbsolute, true)}, diff --git a/execute_test.go b/execute_test.go index 1be46e4..5f082a0 100644 --- a/execute_test.go +++ b/execute_test.go @@ -168,5 +168,20 @@ func TestRotate(t *testing.T) { if !s.registers.getFlag(flagC) { t.Errorf("Error in ROR carry") } +} + +func TestClearSetFlag(t *testing.T) { + var s state + s.registers.setP(0x00) + + executeLine(&s, []uint8{0xF8}) + if !s.registers.getFlag(flagD) { + t.Errorf("Error in SED. %v", s.registers) + } + + executeLine(&s, []uint8{0xD8}) + if s.registers.getFlag(flagD) { + t.Errorf("Error in CLD. %v", s.registers) + } }