From f3d3e588fdf2db1478be85d41b0b5a0049235732 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 17 May 2022 16:51:26 -0400 Subject: [PATCH] Add enough of state to [sort-of] pass the first test. i.e. until the processor overruns, as it is permitted to do, and can't handle the second instruction. --- .../Implementation/68000Mk2Implementation.hpp | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp index 9e214ba53..6978a09e7 100644 --- a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp +++ b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp @@ -306,8 +306,8 @@ void Processor CPU::MC68000Mk2::State Processor::get_state() { - return CPU::MC68000Mk2::State(); + CPU::MC68000Mk2::State state; + + // This isn't true, but will ensure that both stack_pointers_ have their proper values. + did_update_status(); + + for(int c = 0; c < 7; c++) { + state.registers.data[c] = registers_[c].l; + state.registers.address[c] = registers_[c + 8].l; + } + state.registers.data[7] = registers_[7].l; + + state.registers.program_counter = program_counter_.l; + state.registers.status = status_.status(); + state.registers.user_stack_pointer = stack_pointers_[0].l; + state.registers.supervisor_stack_pointer = stack_pointers_[1].l; + + return state; } template -void Processor::set_state(const CPU::MC68000Mk2::State &) { +void Processor::set_state(const CPU::MC68000Mk2::State &state) { + // Copy registers and the program counter. + for(int c = 0; c < 7; c++) { + registers_[c].l = state.registers.data[c]; + registers_[c + 8].l = state.registers.address[c]; + } + registers_[7].l = state.registers.data[7]; + program_counter_.l = state.registers.program_counter; + + // Set status first in order to get the proper is-supervisor flag in place. + status_.set_status(state.registers.status); + + // Update stack pointers, being careful to copy the right one. + stack_pointers_[0].l = state.registers.user_stack_pointer; + stack_pointers_[1].l = state.registers.supervisor_stack_pointer; + registers_[15] = stack_pointers_[is_supervisor_]; + + // Ensure the local is-supervisor flag is updated. + did_update_status(); }