Forum
Array of addresses - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: Array of addresses (/showthread.php?tid=274)



Array of addresses - britlion - 07-17-2010

I'm trying to make an array of sprite pointers.

The compiler doesn't seem to like

Code:
DIM Sprites(5) AS uInteger => {@sprite1,@sprite2,@sprite3,@sprite4,@sprite5,@sprite6}

And I'm not quite sure why. It reports the error: Initializer expression is not constant. - and I beg to differ. I thought @label WAS a constant?


Re: Array of addresses - boriel - 07-19-2010

britlion Wrote:I'm trying to make an array of sprite pointers.

The compiler doesn't seem to like

Code:
DIM Sprites(5) AS uInteger => {@sprite1,@sprite2,@sprite3,@sprite4,@sprite5,@sprite6}

And I'm not quite sure why. It reports the error: Initializer expression is not constant. - and I beg to differ. I thought @label WAS a constant?
The compiler does not currently support this. Sorry. It's constant, as you say, but hard to know in compiler-time. Think of how will you code this array in asm:
Code:
__Sprites:
...
...
Db _sprite1????
Even the assembler does not support this (yet). There should be a mechanism to make a DB/DW to contain an expression. I will have a look on it, but it will be for version 1.2.7 or newer. 1.2.6 needs to be closed. Only bitwise operations are still pending...


Re: Array of addresses - britlion - 07-20-2010

Understood.

I'm surprised that nobody has put this functionality to do this in standard assemblers for decades, though. I can't be the only person that thinks doing

Code:
for n=0 to frames
putsprite(spriteframes(n))
next n

Or something that's conceptually similar, is a cunning way to do sprite animations..

I suppose, since sprites are of a fixed size, people have always treated them as vectors and calculated the pointers from a base..