Results 1 to 8 of 8

Thread: Passing values between arrays

  1. #1

    Passing values between arrays

    I need a little help with fpc4gba: I have a bug I'm not able to resolve by myself... look at this code:

    [pascal]
    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.
    [/pascal]
    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:
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  2. #2

    Passing values between arrays

    Can you post the assembler code? This smells like a codegenerator bug.

  3. #3

    Passing values between arrays

    I have pastebin-ed it here:
    http://www.hu.freepascal.org/fpcircb...ebin?msgid=121
    The compiler comes from the last trunk revision sources
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  4. #4

    Passing values between arrays

    I think the problem is this:

    Code:
    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.

  5. #5

    Passing values between arrays

    Therefore is this a codegenerator bug? I'm going mad to figure where is the wrong code
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  6. #6

    Passing values between arrays

    Yes, it definately is a codegenerator bug.

  7. #7

    Passing values between arrays

    If you think it is useful, I could add this bug in mantis
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  8. #8

    Passing values between arrays

    Yes, please do so, so we cannot forget about it.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •