diff --git a/Octane/gbemu-part1.js b/Octane/gbemu-part1.js index 73ff9a3..ad618e9 100644 --- a/Octane/gbemu-part1.js +++ b/Octane/gbemu-part1.js @@ -39,7 +39,11 @@ function runGameboy() { GameBoyAudioNode.run(); } + var resultHash = gameboy.canvas.resultHash; + resetGlobalVariables(); + + return resultHash; } function tearDownGameboy() { @@ -56,7 +60,7 @@ var expectedGameboyStateStr = var GameBoyWindow = { }; -function GameBoyContext() { +function GameBoyContext(canvas) { this.createBuffer = function() { return new Buffer(); } @@ -69,20 +73,21 @@ function GameBoyContext() { this.putImageData = function (buffer, x, y) { var sum = 0; for (var i = 0; i < buffer.data.length; i++) { - sum += i * buffer.data[i]; - sum = sum % 1000; + sum ^= (i * buffer.data[i]) | 0; } + canvas.resultHash ^= sum; } this.drawImage = function () { } }; function GameBoyCanvas() { this.getContext = function() { - return new GameBoyContext(); + return new GameBoyContext(this); } this.width = 160; this.height = 144; this.style = { visibility: "visibile" }; + this.resultHash = 0x1a2b3c4f; } function cout(message, colorIndex) { diff --git a/Octane/gbemu-part2.js b/Octane/gbemu-part2.js index 1320cd0..30cf6e1 100644 --- a/Octane/gbemu-part2.js +++ b/Octane/gbemu-part2.js @@ -9782,7 +9782,15 @@ var gameboy_rom='r+BPyZiEZwA+AeBPySAobeEq6gAgKlYj5WJv6SRmZjjhKuXqACDJ/////////// setupGameboy(); class Benchmark { + EXPECTED_RESULT_HASH = 439041103; + runIteration() { - runGameboy(); + this.result = runGameboy(); + } + + validate() { + if (this.result != this.EXPECTED_RESULT_HASH) + throw new Error(`Got unexpected result hash ${this.result} instead of ${this.EXPECTED_RESULT_HASH}`) + } }