Menu

Can arrays be dimensioned with a variable?

Help
2022-05-04
2022-05-05
  • stan cartwright

    stan cartwright - 2022-05-04

    I tried to code an area scroll routine for ili9341.
    It needs 2 arrays, size depends on width to scroll.
    I did get it down to 3 errors that the arrays not declared.
    scax=0:scay=0:sawid=55:saht=8
    dim tl1(sawid),tl2(sawid) as word

     
  • Anobium

    Anobium - 2022-05-04

    Declaration parameters must be a constant.

     
  • stan cartwright

    stan cartwright - 2022-05-04

    It seems so.
    scax=0:scay=0:sawid=55:saht=8
    dim tl1(55),tl2(55) as word
    works.
    I can't think of a simple workaround.
    The idea was scan a screen area using readpixel line at a time then swap them "rotated" 1 pixel.
    needs 2 arrays but only the width of the scroll area. Never mind, just define them the same.
    not tested it, just compiles.

     
  • stan cartwright

    stan cartwright - 2022-05-04

    I found alloc in help
    glcdprint (0,0,str(@my256bytebuffer),wh) prints 458829.
    This could be a solution. Reminds me of picaxe.
    This a 328p.

    I know.. check the data sheet. picaxe had only a few pics and who knows what ram was when no vars left to use but it was declared as peek/poke.. nostalgia.

    Does alloc work with avr? If the handling code was a sub it could be interesting.
    Is it worth me testing alloc with 328P? Any tips before I do please?
    What happens with <2K ram after vars dimmed? Is alloc ram the top end of ram before dimmed vars?
    Sorry so thick but new to me.
    cheers. dynamic storage seems interesting eg. for graphics

     

    Last edit: stan cartwright 2022-05-04
  • stan cartwright

    stan cartwright - 2022-05-04

    scax=0:scay=0:sawid=55:saht=8
    dim tl1 as alloc * sawid
    dim tl2 as alloc * sawid

    What is the memory value to be found in data sheets please?

     
  • stan cartwright

    stan cartwright - 2022-05-04

    Where do gcb vars go and where is safe ram please?

    do gcb vars start at ram start so ram top down is ok to use?

     

    Last edit: stan cartwright 2022-05-04
  • stan cartwright

    stan cartwright - 2022-05-04

    I don't think hex. Is decimal 2303- array size ok for the start in dim tl1 as alloc * sawid at start ?

     

    Last edit: stan cartwright 2022-05-04
  • Anobium

    Anobium - 2022-05-05

    The mega328p has the following. I got this info from the C:\GCstudio\GreatCowBasic\chipdata\mega328p.dat file.

    [Chipdata]
    RAM=2048
    ...
    MaxAddress=2304
    ...
    [FreeRAM]
    100:900

    Therefore, this chip as 2048 bytes of RAM from address 0x100 (start address of RAM) to x900 and therefore the MaxAddress of the RAM is 0d + 2048d + 0x100 - 1d = 2034d


    So, an array of 2303 is not possible as this greater then the RAM.
    Where do gcb vars go and where is safe ram please? In the range of 100:900
    And, before you ask... the lower 32 bytes are used by the compiler to support all the functions - so, whilst you could put a variable there... it will get overwritten.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.