View Full Version : Passing values between arrays

28-09-2006, 07:12 PM
I need a little help with fpc4gba: I have a bug I'm not able to resolve by myself... look at this code:

program main;


gba_types, gba_video, gba_regs, gba_bg, gba_core;

sMap: array [0..4] of u16;
blockLayer: pu16;
value: u16;

blockLayer := MEMBGMAP(1); // This is like blocklayer: pu16 absolute $6004000;
SetMode(MODE_3 or BG2_ENABLE);

sMap[2] := 15;

{$ifndef USE_SWAP}
blockLayer[2] := sMap[2];
value := sMap[2];
blockLayer[2] := value;

if blockLayer[2] = 15 then
VideoBuffer[16000] := $001F; // Never reached if USE_SWAP is undefined

It should put a red pixel on the gba screen only if the value of sMap[2] is passed to blockLayer[2]. As you can see, it fails if I try to assign it directly from array to array, but works if I assign the value by passing it in another variable. :doh:

By checking the map file, I can see that in both cases sMap and blockLayer are created in the same memory region, that is readable and writeable ($3000000).
Any ideas? :think: :eh: :scratch:

28-09-2006, 08:51 PM
Can you post the assembler code? This smells like a codegenerator bug.

28-09-2006, 10:48 PM
I have pastebin-ed it here:
The compiler comes from the last trunk revision sources

29-09-2006, 06:30 AM
I think the problem is this:

108. .Lj16:
109. .long U_P$MAIN_SMAP+4
110. .Lj19:
111. .long U_P$MAIN_SMAP+4

.Lj16 correctly points to smap, but if I look at the code, .Lj19 should point to blocklayer, because the value is stored in a pointer loaded from .Lj19. I also don't know why the compiler decides to copy two bytes instead of 1 word.

29-09-2006, 11:24 AM
Therefore is this a codegenerator bug? I'm going mad to figure where is the wrong code :)

29-09-2006, 11:54 AM
Yes, it definately is a codegenerator bug.

29-09-2006, 12:05 PM
If you think it is useful, I could add this bug in mantis

29-09-2006, 12:16 PM
Yes, please do so, so we cannot forget about it.