SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 29a3b18186c181399f4b99b9111ca9d8b5726886 parent f9b13c66b162766216d1c9b19f99ea38fb5625f3 Author: Lior Halphon <LIJI32@gmail.com> Date: Sun, 3 Jan 2021 16:52:18 +0200 Better camera noise on frontends without camera support Diffstat:
| M | Core/camera.c | 28 | ++++++++++++++-------------- |
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git 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; - - while ((signed *) data != &value + 1) { - hash ^= (*data << 8); - if (hash & 0x8000) { - hash ^= 0x8a00; - hash ^= *data; - } - data++; + uint32_t value = (x * 151 + y * 149) ^ noise_seed; + uint32_t hash = 0; + + 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)
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.