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

Change in behaviour for jr @+constant #259

Closed
mattcurrie opened this issue Mar 28, 2018 · 10 comments
Closed

Change in behaviour for jr @+constant #259

mattcurrie opened this issue Mar 28, 2018 · 10 comments
Assignees

Comments

@mattcurrie
Copy link
Member

Source:

    jr @+$50

In 0.3.5 this is assembled as these bytes:

    $18 $4E

In 0.3.6 this is assembled as these bytes:

    $18 $4F

Is this an intentional change? I'm guessing its related to the "Allow JR between sections." change in 0.3.6.

@AntonioND
Copy link
Member

No, that's not intentional.

@AntonioND AntonioND self-assigned this Mar 28, 2018
@Sanqui
Copy link
Member

Sanqui commented Mar 28, 2018

Anecdotally, I also noticed that jr @ no longer caused the game to freeze.

@AntonioND
Copy link
Member

What game?

@Sanqui
Copy link
Member

Sanqui commented Mar 28, 2018

I was testing while writing homebrew. I thought it was my fault though and it wasn't critical so I just ignored it.

@AntonioND
Copy link
Member

AntonioND commented Mar 28, 2018

This is actually quite bad, it doesn't even work with constants. It only works when the result has to be calculated by the linker (labels, for example). In short, it works pretty much always, except when using @ or numeric constants.

I'll fix it and add it to the release notes of 0.3.6. I don't think that many people will be affected, though.

@mattcurrie
Copy link
Member Author

Thanks Antonio.

In my disassembler I generate these type of instructions when there is a jr to an address that was not disassembled as the start address of an instruction (so there isn't a label to jump to). I believe this is nearly always due to it disassembling some data bytes as code.

@AntonioND
Copy link
Member

AntonioND commented Mar 28, 2018

I've found a problem when fixing this.

ld bc,@
jp @
jr @

dw @

I can only fix one of the 2 groups with the current code, so I'll have to do some more serious modifications to it...

@obskyr
Copy link
Contributor

obskyr commented Mar 29, 2018

Perhaps while you're fixing this, you can allow jr to function with absolute addresses too?

While disassembling, I frequently find myself wanting to write placeholders like jr $0350, but that's currently not allowed. Instead of special-casing jr @+[...], how about simply having @+[...] expand to an absolute address and have jr handle those too?

@AntonioND
Copy link
Member

rgbasm doesn't evaluate @, it passes the reference to rgblink, and that's the one that actually evaluates it.

The problem is that @ is evaluated at the position of the patch. For a DW, the position is the same place where @ was in the source code. For any instruction, the @ has to evaluate to the byte of the instruction, but it evaluates to the position of the offset byte (or the immediate). That's why it is off by one, and why it only happens with @, while labels still work.

The crash with constants is another issue, and that is easy to fix.

@AntonioND
Copy link
Member

I've created a pull request that should take care of both problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants