Skip to content

Commit

Permalink
fix branch distance calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
randomdude999 committed Jan 23, 2024
1 parent 5353837 commit 5e17f3b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/asar/arch-65816.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ void branch(insn_context& ctx) {
if(pass == 2) {
num = getnum(parsed.arg);
if(foundlabel) {
int64_t delta = num - (snespos + width + 1);
// cast delta to signed 16-bit, this makes it possible to handle bank-border-wrapping automatically
int16_t delta = num - (snespos + width + 1);
if((num & ~0xffff) != (snespos & ~0xffff)) {
// todo: should throw error "can't branch to different bank"
asar_throw_error(2, error_type_block, error_id_relative_branch_out_of_bounds, dec(delta).data());
Expand Down

0 comments on commit 5e17f3b

Please sign in to comment.