1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-09 17:29:36 +00:00

Adds safety asserts.

This commit is contained in:
Thomas Harte 2020-03-30 21:39:31 -04:00
parent 6805acd74f
commit a491650c8b
2 changed files with 13 additions and 0 deletions

View File

@ -8,6 +8,8 @@
#include "../6502.hpp"
#include <cassert>
using namespace CPU::MOS6502;
const uint8_t CPU::MOS6502::JamOpcode = 0xf2;
@ -80,6 +82,7 @@ ProcessorBase::State ProcessorBase::get_state() {
state.execution_state.micro_program = int(micro_offset / list_length);
state.execution_state.micro_program_offset = int(micro_offset % list_length);
assert(&operations_[state.execution_state.micro_program][state.execution_state.micro_program_offset] == scheduled_program_counter_);
return state;
}

View File

@ -9,6 +9,7 @@
#ifndef Struct_hpp
#define Struct_hpp
#include <cassert>
#include <cstdarg>
#include <cstring>
#include <string>
@ -113,6 +114,15 @@ struct Serialisable {
template <typename Owner> class StructImpl: public Struct {
public:
#ifndef NDEBUG
StructImpl() {
// Protect against declarations that nominate the wrong Owner; this isn't
// a static assert because that wouldn't catch all invalid cases.
const auto owner = static_cast<Owner *>(this);
assert(owner != nullptr);
}
#endif
/*!
@returns the value of type @c Type that is loaded from the offset registered for the field @c name.
It is the caller's responsibility to provide an appropriate type of data.