From 29a3b18186c181399f4b99b9111ca9d8b5726886 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 3 Jan 2021 16:52:18 +0200 Subject: [PATCH] Better camera noise on frontends without camera support --- Core/camera.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Core/camera.c b/Core/camera.c index bef8489..7751f18 100644 --- a/Core/camera.c +++ b/Core/camera.c @@ -1,26 +1,26 @@ #include "gb.h" -static signed noise_seed = 0; +static uint32_t noise_seed = 0; -/* This is not a complete emulation of the camera chip. Only the features used by the GameBoy Camera ROMs are supported. +/* This is not a complete emulation of the camera chip. Only the features used by the Game Boy Camera ROMs are supported. We also do not emulate the timing of the real cart, as it might be actually faster than the webcam. */ static uint8_t generate_noise(uint8_t x, uint8_t y) { - signed value = (x + y * 128 + noise_seed); - uint8_t *data = (uint8_t *) &value; - unsigned hash = 0; + uint32_t value = (x * 151 + y * 149) ^ noise_seed; + uint32_t hash = 0; - while ((signed *) data != &value + 1) { - hash ^= (*data << 8); - if (hash & 0x8000) { - hash ^= 0x8a00; - hash ^= *data; - } - data++; + while (value) { hash <<= 1; + if (hash & 0x100) { + hash ^= 0x101; + } + if (value & 0x80000000) { + hash ^= 0xA1; + } + value <<= 1; } - return (hash >> 8); + return hash; } static long get_processed_color(GB_gameboy_t *gb, uint8_t x, uint8_t y)