Follow-up from PR #211 (crypto.c sample port).
The transpiler currently only supports simple array index expressions where the index is a local variable or constant. Complex expressions like:
collision_top_left[(x >> 3) + ((y >> 3) << 4)]
fail with: Array element access requires the index to be a local variable or constant. Complex index expressions are not supported.
This pattern is common in NES games for tile map lookups. The C code equivalent is straightforward array indexing that the 6502 handles with indexed addressing modes.
Workaround
Compute the index into a temp variable first:
byte idx = (byte)((x >> 3) + ((y >> 3) << 4));
byte result = collision_top_left[idx];
Implementation
The HandleLdelemU1 method in IL2NESWriter.ArrayHandling.cs needs to handle more complex IL patterns before the ldelem.u1 instruction, such as shift/add/sub operations on the index.
Follow-up from PR #211 (crypto.c sample port).
The transpiler currently only supports simple array index expressions where the index is a local variable or constant. Complex expressions like:
fail with: Array element access requires the index to be a local variable or constant. Complex index expressions are not supported.
This pattern is common in NES games for tile map lookups. The C code equivalent is straightforward array indexing that the 6502 handles with indexed addressing modes.
Workaround
Compute the index into a temp variable first:
Implementation
The
HandleLdelemU1method inIL2NESWriter.ArrayHandling.csneeds to handle more complex IL patterns before theldelem.u1instruction, such as shift/add/sub operations on the index.