From 3cb042a49dbdb302e409c6ec54e16f3dfe11f462 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 21 Apr 2019 22:08:18 -0400 Subject: [PATCH] Corrects the carry and extend flags for various long-word operations. --- Machines/Electron/Electron.cpp | 1 + .../Mac/Clock SignalTests/EmuTOSTests.mm | 8 +++--- OSBindings/Mac/Clock SignalTests/QLTests.mm | 8 +++--- .../Implementation/68000Implementation.hpp | 28 +++++++------------ 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 75269411a..383793397 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -62,6 +62,7 @@ class ConcreteMachine: set_clock_rate(2000000); speaker_.set_input_rate(2000000 / SoundGenerator::clock_rate_divider); + speaker_.set_high_frequency_cutoff(7000); std::vector rom_names = {"basic.rom", "os.rom"}; if(target.has_adfs) { diff --git a/OSBindings/Mac/Clock SignalTests/EmuTOSTests.mm b/OSBindings/Mac/Clock SignalTests/EmuTOSTests.mm index a88cd0d53..09a30863f 100644 --- a/OSBindings/Mac/Clock SignalTests/EmuTOSTests.mm +++ b/OSBindings/Mac/Clock SignalTests/EmuTOSTests.mm @@ -72,20 +72,20 @@ class EmuTOS: public CPU::MC68000::BusHandler { case Microcycle::SelectWord | Microcycle::Read: cycle.value->full = is_peripheral ? peripheral_result : base[word_address]; - if(!(cycle.operation & Microcycle::IsProgram)) printf("[word r %08x -> %04x] ", *cycle.address, cycle.value->full); +// if(!(cycle.operation & Microcycle::IsProgram)) printf("[word r %08x -> %04x] ", *cycle.address, cycle.value->full); break; case Microcycle::SelectByte | Microcycle::Read: cycle.value->halves.low = (is_peripheral ? peripheral_result : base[word_address]) >> cycle.byte_shift(); - if(!(cycle.operation & Microcycle::IsProgram)) printf("[byte r %08x -> %02x] ", *cycle.address, cycle.value->halves.low); +// if(!(cycle.operation & Microcycle::IsProgram)) printf("[byte r %08x -> %02x] ", *cycle.address, cycle.value->halves.low); break; case Microcycle::SelectWord: assert(!(is_rom && !is_peripheral)); - if(!(cycle.operation & Microcycle::IsProgram)) printf("[word w %04x -> %08x] ", cycle.value->full, *cycle.address); +// if(!(cycle.operation & Microcycle::IsProgram)) printf("[word w %04x -> %08x] ", cycle.value->full, *cycle.address); base[word_address] = cycle.value->full; break; case Microcycle::SelectByte: assert(!(is_rom && !is_peripheral)); - if(!(cycle.operation & Microcycle::IsProgram)) printf("[byte w %02x -> %08x] ", cycle.value->halves.low, *cycle.address); +// if(!(cycle.operation & Microcycle::IsProgram)) printf("[byte w %02x -> %08x] ", cycle.value->halves.low, *cycle.address); base[word_address] = (cycle.value->halves.low << cycle.byte_shift()) | (base[word_address] & (0xffff ^ cycle.byte_mask())); break; } diff --git a/OSBindings/Mac/Clock SignalTests/QLTests.mm b/OSBindings/Mac/Clock SignalTests/QLTests.mm index 1e14e326d..196d2b90f 100644 --- a/OSBindings/Mac/Clock SignalTests/QLTests.mm +++ b/OSBindings/Mac/Clock SignalTests/QLTests.mm @@ -71,20 +71,20 @@ class QL: public CPU::MC68000::BusHandler { case Microcycle::SelectWord | Microcycle::Read: cycle.value->full = is_peripheral ? peripheral_result : base[word_address]; - if(!(cycle.operation & Microcycle::IsProgram)) printf("\n[%08x -> %04x]\t", *cycle.address, cycle.value->full); + if(!(cycle.operation & Microcycle::IsProgram)) printf("[%08x -> %04x] ", *cycle.address, cycle.value->full); break; case Microcycle::SelectByte | Microcycle::Read: cycle.value->halves.low = (is_peripheral ? peripheral_result : base[word_address]) >> cycle.byte_shift(); - if(!(cycle.operation & Microcycle::IsProgram)) printf("\n[%08x -> %02x]\t", *cycle.address, cycle.value->halves.low); + if(!(cycle.operation & Microcycle::IsProgram)) printf("[%08x -> %02x] ", *cycle.address, cycle.value->halves.low); break; case Microcycle::SelectWord: assert(!(is_rom && !is_peripheral)); - if(!(cycle.operation & Microcycle::IsProgram)) printf("\n{%04x -> %08x}\t", cycle.value->full, *cycle.address); + if(!(cycle.operation & Microcycle::IsProgram)) printf("{%04x -> %08x} ", cycle.value->full, *cycle.address); if(!is_peripheral) base[word_address] = cycle.value->full; break; case Microcycle::SelectByte: assert(!(is_rom && !is_peripheral)); - if(!(cycle.operation & Microcycle::IsProgram)) printf("\n{%02x -> %08x}\t", cycle.value->halves.low, *cycle.address); + if(!(cycle.operation & Microcycle::IsProgram)) printf("{%02x -> %08x} ", cycle.value->halves.low, *cycle.address); if(!is_peripheral) base[word_address] = (cycle.value->halves.low << cycle.byte_shift()) | (base[word_address] & (0xffff ^ cycle.byte_mask())); break; } diff --git a/Processors/68000/Implementation/68000Implementation.hpp b/Processors/68000/Implementation/68000Implementation.hpp index 5ee846a65..af444ab49 100644 --- a/Processors/68000/Implementation/68000Implementation.hpp +++ b/Processors/68000/Implementation/68000Implementation.hpp @@ -52,30 +52,22 @@ template void Processor: // no instruction was ongoing. Either way, do a standard instruction operation. // TODO: unless an interrupt is pending, or the trap flag is set. -// if(program_counter_.full >= 0x250 && program_counter_.full <= 0x25e) { -// std::cout << std::setfill('0'); -// std::cout << (extend_flag_ ? 'x' : '-') << (negative_flag_ ? 'n' : '-') << (zero_result_ ? '-' : 'z'); -// std::cout << (overflow_flag_ ? 'v' : '-') << (carry_flag_ ? 'c' : '-') << '\t'; -// for(int c = 0; c < 8; ++ c) std::cout << "d" << c << ":" << std::setw(8) << data_[c].full << " "; -// for(int c = 0; c < 8; ++ c) std::cout << "a" << c << ":" << std::setw(8) << address_[c].full << " "; -// } static bool should_log = false; - should_log |= program_counter_.full >= 0x4F54 && program_counter_.full <= 0x4F84; - if(should_log) { - std::cout << "d0:" << std::setw(8) << std::setfill('0') << data_[0].full << " "; - std::cout << "d1:" << std::setw(8) << std::setfill('0') << data_[1].full << " "; - std::cout << "d2:" << std::setw(8) << std::setfill('0') << data_[2].full << " "; -// std::cout << "a5:" << std::setw(8) << std::setfill('0') << address_[5].full << " "; -// std::cout << "a6:" << std::setw(8) << std::setfill('0') << address_[6].full << " "; - std::cout << "a7:" << std::setw(8) << std::setfill('0') << address_[7].full << " "; +// should_log |= program_counter_.full >= 0x4F54 && program_counter_.full <= 0x4F84; +// if(should_log) { + std::cout << std::setfill('0'); + std::cout << (extend_flag_ ? 'x' : '-') << (negative_flag_ ? 'n' : '-') << (zero_result_ ? '-' : 'z'); + std::cout << (overflow_flag_ ? 'v' : '-') << (carry_flag_ ? 'c' : '-') << '\t'; + for(int c = 0; c < 8; ++ c) std::cout << "d" << c << ":" << std::setw(8) << data_[c].full << " "; + for(int c = 0; c < 8; ++ c) std::cout << "a" << c << ":" << std::setw(8) << address_[c].full << " "; if(is_supervisor_) { std::cout << "usp:" << std::setw(8) << std::setfill('0') << stack_pointers_[0].full << " "; } else { std::cout << "ssp:" << std::setw(8) << std::setfill('0') << stack_pointers_[1].full << " "; } std::cout << '\n'; - } +// } decoded_instruction_ = prefetch_queue_.halves.high.full; if(!instructions[decoded_instruction_].micro_operations) { @@ -157,7 +149,7 @@ template void Processor: #define addsubl(a, b, dest, op, overflow) \ const auto source = a; \ const auto destination = b; \ - const uint64_t result = op(destination, source); \ + const uint64_t result = op(uint64_t(destination), uint64_t(source)); \ \ zero_result_ = dest = uint32_t(result); \ extend_flag_ = carry_flag_ = result >> 32; \ @@ -420,7 +412,7 @@ template void Processor: case Operation::CMPl: { const uint32_t source = active_program_->source->full; const uint32_t destination = active_program_->destination->full; - const uint64_t result = destination - source; + const uint64_t result = uint64_t(destination) - uint64_t(source); zero_result_ = uint32_t(result); carry_flag_ = result >> 32;