+mksmith Posted May 22, 2019 Share Posted May 22, 2019 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? Quote Link to comment Share on other sites More sharing options...
+SmittyB Posted May 22, 2019 Share Posted May 22, 2019 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 Quote Link to comment Share on other sites More sharing options...
+mksmith Posted May 23, 2019 Author Share Posted May 23, 2019 Thanks again for your help SmittyB. I'll see what I can come up with! Quote Link to comment Share on other sites More sharing options...
ChildOfCv Posted May 23, 2019 Share Posted May 23, 2019 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. 1 Quote Link to comment Share on other sites More sharing options...
RevEng Posted May 23, 2019 Share Posted May 23, 2019 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 Quote Link to comment Share on other sites More sharing options...
+mksmith Posted May 23, 2019 Author Share Posted May 23, 2019 Awesome - Thanks RevEnv! Ah should have noted the pointers from some 2600 stuff I previously worked on. Quote Link to comment Share on other sites More sharing options...
Lillapojkenpåön Posted May 25, 2019 Share Posted May 25, 2019 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 Quote Link to comment Share on other sites More sharing options...
RevEng Posted May 25, 2019 Share Posted May 25, 2019 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. 1 Quote Link to comment Share on other sites More sharing options...
+mksmith Posted May 25, 2019 Author Share Posted May 25, 2019 Code works well in practice! 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.