PDA

View Full Version : Passing values between arrays



Legolas
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;

{ $DEFINE USE_SWAP}

uses
gba_types, gba_video, gba_regs, gba_bg, gba_core;

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

begin
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];
{$else}
value := sMap[2];
blockLayer[2] := value;
{$endif}

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

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:

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

Legolas
28-09-2006, 10:48 PM
I have pastebin-ed it here:
http://www.hu.freepascal.org/fpcircbot/cgipastebin?msgid=121
The compiler comes from the last trunk revision sources

dmantione
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.

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

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

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

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