Skip to content

Commit

Permalink
Work around BGB going back in time
Browse files Browse the repository at this point in the history
BGB has a rather minor bug regardling its linking capabilities causing
the connection to end prematurely.
  • Loading branch information
mid-kid committed Jan 15, 2022
1 parent 106fc1c commit 98f8ed7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ void bgb_loop_timestamp(void *user, uint32_t t)
{
// Update the timestamp sent by the emulator
struct mobile_user *mobile = (struct mobile_user *)user;

// Attempt to detect the clock going back in time
// This is probably a BGB bug, caused by enabling some options, such as
// the "break on ld d,d" option.
if (((mobile->bgb_clock - t) & 0x7FFFFFFF) < 0x100) {
fprintf(stderr, "[BUG] Emulator went back in time? "
"old: 0x%08X; new: 0x%08X\n", mobile->bgb_clock, t);
return;
}

mobile->bgb_clock = t;
bgb_loop_action(mobile);
}
Expand Down

0 comments on commit 98f8ed7

Please sign in to comment.