Implement 8-bit wraparound for multiplies as well and handle empty memory in ircbotRun()

This commit is contained in:
Juhani Krekelä 2018-05-26 22:51:19 +03:00
parent 46f7854d13
commit cd00c3cded
1 changed files with 8 additions and 6 deletions

14
gir.js
View File

@ -705,8 +705,8 @@ function runVM(state, maxCycles = null) {
memory.set(index, 0);
}
let old = memory.get(index);
memory.set(index, old +
multiplier * change);
let value = old + multiplier * change;
memory.set(index, value & 0xff);
}
ip++;
@ -972,10 +972,12 @@ function ircbotRun(program, input, maxCycles = 400000) {
// Find min and max of the existant array indinces, since
// there is no good way to easily get them and we need them
// for the output
let min = Array.from(result.state.memory.keys()).reduce(
(x, y) => Math.min(x, y));
let max = Array.from(result.state.memory.keys()).reduce(
(x, y) => Math.max(x, y));
// Default to both being set to tapeHead, because that way
// even if there are no indices we can get values that
// the rest of the code can work with
let memoryIndices = Array.from(result.state.memory.keys());
let min = memoryIndices.reduce(Math.min, tapeHead);
let max = memoryIndices.reduce(Math.max, tapeHead);
// Get 15 cells of context on each side of tape head
// Exception is if max or min comes up before that, in which