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

[bug][OK in branch 1.32] A variable is assigned a wrong value by 1 (only under some circumstances) #58

Open
Fabrizio-Caruso opened this issue Oct 2, 2024 · 1 comment

Comments

@Fabrizio-Caruso
Copy link

The new changes in this repo have fixed some bugs but also introduced several new bugs that affect all my games except the smallest two. Here I only discuss a bug present in the Horde game:
game source code: https://github.com/Fabrizio-Caruso/CROSS-LIB/tree/master/src/games/horde
game description: https://github.com/Fabrizio-Caruso/CROSS-LIB/blob/master/docs/GAMES.md#horde

In particular I suspect that the code around this line is miscompiled:
https://github.com/Fabrizio-Caruso/CROSS-LIB/blob/master/src/games/horde/main.c#L2001

I use these options: -std=c99 -O2 -s -I./ -fno-builtin -fno-peephole2 -fno-function-cse

How to reproduce:
The bug is only visible when a double fire power-up is taken. In this case the right arrow is placed more to the right than it should be (see picture).
This bug disappears if a dummy print with the new_arrow_x variable is added. Maybe something must be polluting a register or a carry bit?
Using -O1 removes this bug but produces a worse one (level 1 cannot be completed).

image

I have attached the binaries.
build.zip

@mburkley
Copy link
Owner

mburkley commented Oct 6, 2024

There was an issue with byte subtraction whereby when subtracting a register from another value, the code was negating the register and then an add-byte. But negate is a 16-bit operation so depending on the contents of the lower byte, the result may or may not have been off by one. This has been fixed on the 1.32 branch.

@Fabrizio-Caruso Fabrizio-Caruso changed the title [bug] A variable is assigned a wrong value by 1 (only under some circumstances) [bug][OK in branch 1.32] A variable is assigned a wrong value by 1 (only under some circumstances) Oct 11, 2024
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

2 participants