31 lines
596 B
C++
31 lines
596 B
C++
|
#include <intcode/Machine.hpp>
|
||
|
|
||
|
namespace intcode {
|
||
|
|
||
|
Machine::Machine() : rom_{}, ram_{}, pc_{0}, base_{0} {}
|
||
|
|
||
|
Machine::Machine(std::vector<ValueType> ram)
|
||
|
: rom_{ram}, ram_{}, pc_{0}, base_{0} {}
|
||
|
|
||
|
auto Machine::At(std::size_t i) -> ValueType & {
|
||
|
return i < rom_.size() ? rom_[i] : ram_[i];
|
||
|
}
|
||
|
|
||
|
auto Machine::Rel(std::size_t i) -> ValueType & {
|
||
|
return At(base_ + i);
|
||
|
}
|
||
|
|
||
|
auto Machine::Rebase(std::size_t offset) -> void {
|
||
|
base_ += offset;
|
||
|
}
|
||
|
|
||
|
auto Machine::Next() -> ValueType & {
|
||
|
return At(pc_++);
|
||
|
}
|
||
|
|
||
|
auto Machine::Goto(std::size_t address) -> void {
|
||
|
pc_ = address;
|
||
|
}
|
||
|
|
||
|
} // namespace
|