FAQ  •  Register  •  Login

Initialising an array of addresses

<<

LTee

Posts: 119

Joined: Tue Jul 07, 2009 2:54 pm

Post Wed Aug 10, 2011 11:25 am

Initialising an array of addresses

I was trying to keep a list of memory addresses (pointing to tile data) in an array to use as a cheap lookup table. I tried to do something like this:

  Code:
'data
Data:
asm
defb 0, 0, 191, 191, 191, 191, 191, 191, 0, 0, 253, 253, 253, 253, 253, 253
end asm

'array of addresses
dim tsAddress(TSMAXTILES) as uinteger => {@Data}


... which doesn't work, because @Data isn't a constant so I get an "Initializer expression is not constant" compiler error.

I could write and call a method which loads the array with the correct information on startup, but I just wanted to check that I wasn't missing an obvious trick which would allow me to avoid that? Thanks for any tips! :)
<<

boriel

Site Admin

Posts: 1158

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Aug 10, 2011 1:51 pm

Re: Initialising an array of addresses

You can't do it that way, but you can simply put those bytes in 16bit format:
  Code:
dim tsAddress(TSMAXTILES) as uinteger => {0 + 256 * 0, 191 + 256 * 191, 191 + 256 * 191, 191 + 256 * 191, 0 ...

or also
  Code:
dim tsAddress(TSMAXTILES) as uinteger => {0x0000, 0xBFBF, 0xBFBF, 0xBFBF, 0x0000, ...

Note, BFBF = 191, 191 etc...
<<

LTee

Posts: 119

Joined: Tue Jul 07, 2009 2:54 pm

Post Wed Aug 10, 2011 2:16 pm

Re: Initialising an array of addresses

Ah, interesting! I'll give that a try, thanks boriel!

Return to Help & Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO