Any way to access multiple const arrays within a function?

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
blackcattech
Posts: 113
Joined: Mon Jan 11, 2010 10:39 pm
Location: Chesterfield

Any way to access multiple const arrays within a function?

Post by blackcattech » Fri Jul 26, 2013 9:19 am

I'm writing some code for an OLED display and I'm struggling a bit to work out how to do something.

I have set up a series of const arrays holding several bitmaps that I need to display on the screen.

At the moment, the only ways I can see to access these in code is to either have a separate routine for each bitmap with the const array name hardcoded in, or to merge all the arrays in to one and find somewhere to store the offset.

Is there an alternative? I know you can use addressof to find the address of the first location of an array but I don't know how to access the actual data at a particular address.

As a thought, is it possible to do a const array of addressofs? If that makes sense... Set up your bitmaps then set up an array to point to the start of each one so you just pass an index and the routine can use the address stored as the starting point?

I'm sure Swordfish can use pointers but I can't find any explanation in the help files as to how to use them. Possibly I don't know what to search for to find the information I need.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Jul 26, 2013 12:12 pm

try something like this

Code: Select all

Device = 18F452
Clock =  20

Include "USART.bas"
Include "Convert.bas"

const arrayA() as byte = (1,2,3,4,5)
const ArrayB() as byte = (10,20)

sub Display(byrefconst array() as byte)
   dim index as byte
   for index = 0 to bound(array)
      USART.Write(DecToStr(array(index)),13,10)
   next
end sub

SetBaudrate(br19200)
Display(arrayA)
Display(arrayB)

Post Reply