No announcement yet.

Array Index mismatch when accessing from data / parameter.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Array Index mismatch when accessing from data / parameter.

    I have an array in data like so:

    word test_image
    0x9D32,0x23B9,0x78C4,0x01B3,0x9D32,0x002B,0x78C4,0x01B7,0x9D32,0x0027, ... ( ~841 length )
    I have a function with the signature:

    func RLE_Blit( var x, var y, var w, var h, var* img )
    I am passing the data into my function using the following:

    RLE_Blit( 0, 0, 480, 272, test_image );
    If I access the 'test_image' array directly in this function (bypassing the 'img' parameter) the function works properly, all indexes are what I expect them to be.
    If i access the array through the 'img' parameter I get very weird values for all indexes except '0, 8, 16, 24, 32 ... etc...' which are the correct values.

    I tried making the array a global variable but the program seemed to get to index ~240 and then go walkabout in memory, which seems independent of stack size.
    But that's unrelated, however it did output the correct values for the array before it went for a walk.

    I'm quite new to this so I might be doing something obviously wrong, but nothing I can see in the documentation seems to give me any clues.

    As a small example:

    img[0] == test_image[0]
    img[1] != test_image[1]
    img[8] == test_image[8]
    ​img[9] != test_image[9]
    I'm using Workshop v with Diablo16 PmmC v1.7.
    Unfortunately work makes it exceedingly hard to update to the latest version which is why these versions are a little old.

  • #2
    Can you use File, Zip project and attache your project here? or email it to mark at 4dsystems dot com dot au

    Why does 'work' make it hard to update?


    • #3
      I've emailed the project to the email provided.

      My work environment blocks all auto-updates from the 4D Environment and
      does not seem to like downloading the 4D software directly from the website.
      But I do have the option of downloading from home.


      • #4
        Thanks to Mark,
        I see that the array in the DATA tags is stored in FLASH memory which is byte addressed.

        When directly accessing the DATA array the compiler will use BYTE addressing to access its elements.
        But when the array is passed through as a function parameter the compiler assumes that the array has
        come from RAM which is WORD addressed.

        This is what caused the differences in array element values between the direct access and the parameter access.

        To fix this I add 2 to the index instead of 1 which will take me to the next word instead of the next byte.