From 0c5e15b49dd8a8167dffc11a2fadecc74464bd33 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 11 Apr 2021 02:38:58 +0300 Subject: [PATCH] Correct emulation of count overflow in ATTR_CHR, fixes #372 --- Core/sgb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/sgb.c b/Core/sgb.c index c77b0db6..f22eb3e5 100644 --- a/Core/sgb.c +++ b/Core/sgb.c @@ -269,7 +269,8 @@ static void command_ready(GB_gameboy_t *gb) #endif uint8_t x = command->x; uint8_t y = command->y; - if (x >= 20 || y >= 18 || (count + 3) / 4 > sizeof(gb->sgb->command) - sizeof(*command) - 1) { + count = MIN(count, 20 * 18); + if (x >= 20 || y >= 18) { /* TODO: Verify with the SFC BIOS */ break; }