From 79066f8628d742bfb22df23278c33efe738bceea Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 25 Jun 2019 22:18:11 -0400 Subject: [PATCH] Imports NOT tests, fixes NOT overflow and carry flags. --- .../Mac/Clock SignalTests/68000Tests.mm | 71 +++++++++++++++++++ .../Implementation/68000Implementation.hpp | 3 + 2 files changed, 74 insertions(+) diff --git a/OSBindings/Mac/Clock SignalTests/68000Tests.mm b/OSBindings/Mac/Clock SignalTests/68000Tests.mm index c6bacfb9b..dae8a29e5 100644 --- a/OSBindings/Mac/Clock SignalTests/68000Tests.mm +++ b/OSBindings/Mac/Clock SignalTests/68000Tests.mm @@ -3004,6 +3004,77 @@ class CPU::MC68000::ProcessorStorageTests { XCTAssertEqual(4, _machine->get_cycle_count()); } +// MARK: NOT + +- (void)testNOTb { + _machine->set_program({ + 0x4600 // NOT.B D0 + }); + auto state = _machine->get_processor_state(); + state.data[0] = 0x12345678; + + _machine->set_processor_state(state); + _machine->run_for_instructions(1); + + state = _machine->get_processor_state(); + XCTAssertEqual(state.data[0], 0x12345687); + XCTAssertEqual(state.status & Flag::ConditionCodes, Flag::Negative); + XCTAssertEqual(4, _machine->get_cycle_count()); +} + +- (void)testNOTw { + _machine->set_program({ + 0x4640 // NOT.w D0 + }); + auto state = _machine->get_processor_state(); + state.data[0] = 0x12340000; + state.status |= Flag::ConditionCodes; + + _machine->set_processor_state(state); + _machine->run_for_instructions(1); + + state = _machine->get_processor_state(); + XCTAssertEqual(state.data[0], 0x1234ffff); + XCTAssertEqual(state.status & Flag::ConditionCodes, Flag::Negative | Flag::Extend); + XCTAssertEqual(4, _machine->get_cycle_count()); +} + +- (void)testNOTl_Dn { + _machine->set_program({ + 0x4680 // NOT.l D0 + }); + auto state = _machine->get_processor_state(); + state.data[0] = 0xffffff00; + state.status |= Flag::ConditionCodes; + + _machine->set_processor_state(state); + _machine->run_for_instructions(1); + + state = _machine->get_processor_state(); + XCTAssertEqual(state.data[0], 0x000000ff); + XCTAssertEqual(state.status & Flag::ConditionCodes, Flag::Extend); + XCTAssertEqual(6, _machine->get_cycle_count()); +} + +- (void)testNOTl_XXXl { + _machine->set_program({ + 0x46b9, 0x0000, 0x3000 // NOT.L ($3000).L + }); + *_machine->ram_at(0x3000) = 0xf001; + *_machine->ram_at(0x3002) = 0x2311; + auto state = _machine->get_processor_state(); + state.status |= Flag::Extend; + + _machine->set_processor_state(state); + _machine->run_for_instructions(1); + + state = _machine->get_processor_state(); + XCTAssertEqual(*_machine->ram_at(0x3000), 0x0ffe); + XCTAssertEqual(*_machine->ram_at(0x3002), 0xdcee); + XCTAssertEqual(state.status & Flag::ConditionCodes, Flag::Extend); + XCTAssertEqual(28, _machine->get_cycle_count()); +} + // MARK: PEA - (void)testPEA_A1 { diff --git a/Processors/68000/Implementation/68000Implementation.hpp b/Processors/68000/Implementation/68000Implementation.hpp index 17eb114f1..b348a48c9 100644 --- a/Processors/68000/Implementation/68000Implementation.hpp +++ b/Processors/68000/Implementation/68000Implementation.hpp @@ -1468,18 +1468,21 @@ template void Proces active_program_->destination->halves.low.halves.low ^= 0xff; zero_result_ = active_program_->destination->halves.low.halves.low; negative_flag_ = zero_result_ & 0x80; + overflow_flag_ = carry_flag_ = 0; break; case Operation::NOTw: active_program_->destination->halves.low.full ^= 0xffff; zero_result_ = active_program_->destination->halves.low.full; negative_flag_ = zero_result_ & 0x8000; + overflow_flag_ = carry_flag_ = 0; break; case Operation::NOTl: active_program_->destination->full ^= 0xffffffff; zero_result_ = active_program_->destination->full; negative_flag_ = zero_result_ & 0x80000000; + overflow_flag_ = carry_flag_ = 0; break; #define sbcd() \