Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix inc_lr and dec_lr overflow #454

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Core/sm83_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ static void inc_lr(GB_gameboy_t *gb, uint8_t opcode)
uint8_t value;
register_id = (opcode >> 4) + 1;

value = (gb->registers[register_id] & 0xFF) + 1;
value = (gb->registers[register_id] + 1) & 0xFF;
Copy link
Contributor

@jkotlinski jkotlinski Aug 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The & 0xff part is redundant, as the value is implicitly casted to uint8_t.

gb->registers[register_id] = (gb->registers[register_id] & 0xFF00) | value;

gb->af &= ~(GB_SUBTRACT_FLAG | GB_ZERO_FLAG | GB_HALF_CARRY_FLAG);
Expand All @@ -614,7 +614,7 @@ static void dec_lr(GB_gameboy_t *gb, uint8_t opcode)
uint8_t value;
register_id = (opcode >> 4) + 1;

value = (gb->registers[register_id] & 0xFF) - 1;
value = (gb->registers[register_id] - 1) & 0xFF;
gb->registers[register_id] = (gb->registers[register_id] & 0xFF00) | value;

gb->af &= ~(GB_ZERO_FLAG | GB_HALF_CARRY_FLAG);
Expand Down