Skip to content

Commit 65b75d8

Browse files
committed
add canvas hashing
1 parent 901c95b commit 65b75d8

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Octane/gbemu-part1.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ function runGameboy() {
3939
GameBoyAudioNode.run();
4040
}
4141

42+
var resultHash = gameboy.canvas.resultHash;
43+
4244
resetGlobalVariables();
45+
46+
return resultHash;
4347
}
4448

4549
function tearDownGameboy() {
@@ -56,7 +60,8 @@ var expectedGameboyStateStr =
5660

5761
var GameBoyWindow = { };
5862

59-
function GameBoyContext() {
63+
function GameBoyContext(canvas) {
64+
6065
this.createBuffer = function() {
6166
return new Buffer();
6267
}
@@ -69,20 +74,21 @@ function GameBoyContext() {
6974
this.putImageData = function (buffer, x, y) {
7075
var sum = 0;
7176
for (var i = 0; i < buffer.data.length; i++) {
72-
sum += i * buffer.data[i];
73-
sum = sum % 1000;
77+
sum ^= (i * buffer.data[i]) | 0;
7478
}
79+
canvas.resultHash ^= sum;
7580
}
7681
this.drawImage = function () { }
7782
};
7883

7984
function GameBoyCanvas() {
8085
this.getContext = function() {
81-
return new GameBoyContext();
86+
return new GameBoyContext(this);
8287
}
8388
this.width = 160;
8489
this.height = 144;
8590
this.style = { visibility: "visibile" };
91+
this.resultHash = 0x1a2b3c4f;
8692
}
8793

8894
function cout(message, colorIndex) {

Octane/gbemu-part2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9783,6 +9783,6 @@ setupGameboy();
97839783

97849784
class Benchmark {
97859785
runIteration() {
9786-
runGameboy();
9786+
this.result = runGameboy();
97879787
}
97889788
}

0 commit comments

Comments
 (0)