From 479a64dca67fae62583b9bf06d1cb2a33d60bc95 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 2 Oct 2016 23:36:20 +0300 Subject: [PATCH] Dither using a pattern, closer to actual GameBoy Camera --- Core/camera.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/Core/camera.c b/Core/camera.c index 4812c89..db8eb2f 100644 --- a/Core/camera.c +++ b/Core/camera.c @@ -1,22 +1,5 @@ #include "camera.h" -static int8_t dither_random(uint8_t x, uint8_t y) -{ - static bool once = false; - static int8_t random[128*112]; - if (!once) { - unsigned int r = 0x1337c0de; - for (int i = 0; i < sizeof(random); i++) { - random[i] = r % 85 - 42; - r += 11; - r *= 25214903917; - } - once = true; - } - - return random[x + y * 128]; -} - uint8_t GB_camera_read_image(GB_gameboy_t *gb, uint16_t addr) { uint8_t tile_x = addr / 0x10 % 0x10; @@ -31,8 +14,8 @@ uint8_t GB_camera_read_image(GB_gameboy_t *gb, uint16_t addr) int color = gb->camera_get_pixel_callback? gb->camera_get_pixel_callback(gb, x,y) ^ 0xFF : (rand() & 0xFF); - /* Dither using a deterministic random */ - color += dither_random(x, y); + /* Dither using a pattern */ + color += ((x + y) & 1? 21 : -21) >> (y & 1); if (color > 255) { color = 255; }