(note: this is happening with #9913, don't know if it's still so after that since I can't switch to #9984 atm for the others known problems)
offset calculation for an array smaller than 256 bytes is wrong - the problem disappear just making the array bigger:
unsigned char gameMap[208];
void someFunction (void) {
int tx,ty;
if (gameMap[ty*13+tx] & 0x01)
doSomething()
}
generates:
ld de, #_gameMap+0
ld c, -6 (ix)
ld l, c
add hl, hl
add hl, bc
add hl, hl
add hl, hl
add hl, bc
ld c, -8 (ix)
ld a, l
add a, c
ld c, a
ld l, c
ld a, c
rla
sbc a, a
ld h, a
add hl,de
ld -11 (ix), l
ld -10 (ix), h
ld l,-11 (ix)
ld h,-10 (ix)
ld a, (hl)
ld -12 (ix), a
bit 0, -12 (ix)
jp NZ,00398$
jp 00137$
IMHO it seems that the problem is that B and H aren't zeroed before the multiplication by 13.
If I just make the array bigger, the generated code becomes
;main.c:467: if (gameMap[ty*MAP_X+tx] & BLOCK) {
ld bc, #_gameMap+0
ld e,-6 (ix)
ld d,-5 (ix)
ld l, e
ld h, d
add hl, hl
add hl, de
add hl, hl
add hl, hl
add hl, de
ld e,-8 (ix)
ld d,-7 (ix)
add hl, de
add hl,bc
ld -11 (ix), l
ld -10 (ix), h
ld l,-11 (ix)
ld h,-10 (ix)
ld a, (hl)
ld -12 (ix), a
bit 0, -12 (ix)
jp NZ,00398$
jp 00137$
and works as expected.
Let me know if you need any other detail.
Also reported in [#2632]
Related
Bugs:
#2632Last edit: Maarten Brock 2017-10-17
wow, didn't see that :| it's definately that very same problem.
This bug has been fixed a while ago.
Philipp