Jump to content
IGNORED

Using Indirect Variable Arrays


mksmith

Recommended Posts

I'm looking at using Indirect Variable Arrays for level data pointers and the example on RandomTerrain doesn't compile. The error shown is Value in 'lda #mydataplo' must be <$100.

 

I want to setup about 30 levels of data which I want to use a pointer to access the data rather than using a huge if then... list. Can that be the intended use?

 

 

Link to comment
Share on other sites

I've never used the indirect arrays in 7800BASIC but I do that using assembly in my game (with thanks to RevEng for helping me with that).

 

This takes the contents of my 'checkMapTemp8' variable and uses it as an index into my list of pointers which are stored as two separate lists, one for the high byte of the address and one for the low byte of the address.

Each of my pointers actually points to the start of a 256 byte list and I use my 'titleScreenFloorOffsetTemp' variable as a second index into that list, so in the end I'm choosing a list, and then choosing a byte in that list which then gets stored in temp3.

 

I've added some extra comments to hopefully make it clearer what's happening if you're not familiar with assembly.

	asm
	ldx checkMapTemp8 ;load the value to use as an index
	lda voxelColourMapLowByte,x ;grab the low byte of the pointer
	sta temp7 ;store it somewhere in memory
	lda voxelColourMapHighByte,x ;grab the high byte of the pointer
	sta temp8 ;store it in the next byte of memory
	
	ldy titleScreenFloorOffsetTemp ;load the index into the chosen list
	lda (temp7),y ;load the chosen byte in the chosen list
	sta temp3 ;store the result in temp3
	
	jmp skipVoxelColourMapList ;jump over the data
voxelColourMapLowByte ;List of low bytes (#< will give you the low byte of an address)
	.byte #<ColourData0 ;0
	.byte #<ColourData1 ;1
	.byte #<ColourData2 ;0
	.byte #<ColourData3 ;1
voxelColourMapHighByte ;List of high bytes (#> will give you the high byte of an address)
	.byte #>ColourData0 ;0
	.byte #>ColourData1 ;1
	.byte #>ColourData2 ;0
	.byte #>ColourData3 ;1
skipVoxelColourMapList
end
Link to comment
Share on other sites

I'm looking at using Indirect Variable Arrays for level data pointers and the example on RandomTerrain doesn't compile. The error shown is Value in 'lda #mydataplo' must be <$100.

 

I want to setup about 30 levels of data which I want to use a pointer to access the data rather than using a huge if then... list. Can that be the intended use?

 

 

 

The lda instruction can only load 8 bits at a time, and your variable probably isn't in the zero page. You might be able to do math on the address though, if the assembler has macros such as HI8,LO8 or such. Whatever it is, it will almost certainly have to be supported as a relocatable record for the linker.

  • Like 1
Link to comment
Share on other sites

Somewhere along the way the example has got mangled. This should work...

 

   dim mempointer=a
   dim mempointerhi=b
   dim memindex=c
   rem ** each data statement you wish to point at should have a similar
   rem ** const statement.
   const mydataplo=#<mydata
   const mydataphi=#>mydata
   rem ** set the memory pointer to point to "mydata"
   mempointer=mydataplo
   mempointerhi=mydataphi
   rem ** an example of indirect variable array access
   if mempointer[[memindex]]=0 then goto drawelephant
   data mydata
   0,3,5,8
end
drawelephant
Link to comment
Share on other sites

Somewhere along the way the example has got mangled. This should work...

 

   dim mempointer=a
   dim mempointerhi=b
   dim memindex=c
   rem ** each data statement you wish to point at should have a similar
   rem ** const statement.
   const mydataplo=#<mydata
   const mydataphi=#>mydata
   rem ** set the memory pointer to point to "mydata"
   mempointer=mydataplo
   mempointerhi=mydataphi
   rem ** an example of indirect variable array access
   if mempointer[[memindex]]=0 then goto drawelephant
   data mydata
   0,3,5,8
end
drawelephant

 

Why are the constants important?

Would this not work?

 

mempointer = #<mydata

mempointerhi = #>mydata

Link to comment
Share on other sites

the "#" "<" and ">" value modifiers don't really belong to the language proper, they come from assembly language. So the parsing that happens during regular variable assignments doesn't work with them, but the const command doesn't do any parsing and passes them to the underlying assembly code intact.

  • Like 1
Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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...