Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Initialising an array of addresses
#1
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! Smile
Reply
#2
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...
Reply
#3
Ah, interesting! I'll give that a try, thanks boriel!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)