Jump to content
jbs30000

Quick yes or no question on variable arrays

Recommended Posts

It's been a while since I've done this so I figured I'd better double check because my memory is crap.

 

If I go

dim MyArray=a

 

Then MyArray[0] is a and MyArray[1] is b, correct?

Share this post


Link to post
Share on other sites

It's been a while since I've done this so I figured I'd better double check because my memory is crap.

 

If I go

dim MyArray=a

 

Then MyArray[0] is a and MyArray[1] is b, correct?

Yes, that's right. The number in square brackets is the offset to the starting address, so an offset of 0 gives you the starting address (a). The assembly equivalent is

 

  ; MyArray[0]
  LDX 0
  LDA MyArray,X
  ; MyArray[1]
  LDX 1
  LDA MyArray,X

Michael

Share this post


Link to post
Share on other sites

I don't know for sure, but I thought arrays were read-only with bB:

If you dim an array to ROM, it will be a read-only array. But if you dim an array to RAM, it will be a read/write (variable) array.

 

Note that if you dim an array to expansion RAM that requires separate read and write addresses, you'll need to either dim the array twice-- once for writing, and once for reading-- or you'll need to modify the index as needed if the expansion RAM is small enough.

 

For example:

 

  rem dim a Superchip array for writing and reading
  dim w_MyArray=$F000
  dim r_MyArray=$F080
  w_MyArray[12]=rand
  w_MyArray[12]=r_MyArray[12]+1

  rem modify the index instead of dimming twice
  dim MyArray=$F000
  rem use index 0 to 127 for writing
  rem use index 128 to 255 for reading
  MyArray[12]=rand
  MyArray[12]=MyArray[140]+1

In the second example, note that 140=12+128, so it does the same thing as the first example (add 1 to the element with index 12). However, the second example/method is harder for the reader to understand, and it will work only for Superchip expansion RAM (since the Superchip has 128 bytes of RAM, so there are a total of 256 write and read addresses).

 

Michael

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...