+mksmith Posted July 25, 2019 Share Posted July 25, 2019 Hi, Been taking a little break this week from Arkanoid to recharge and wanted to test a theory I have with the code RevEng created for the brick layout... I'm looking to store a map grid area in memory (say 25*25 squares) and need to (based on the x and y of character position) determine what is stored at that memory location. dim mapTable = $2200 dim charX = a dim charB = b rem map area 25x25 (0-24) const mapWidth = 24 const mapHeight = 24 rem char position charX = 18 : charY = 22 rem get value at location offset=charX+(charY*mapWidth) : value = mapTable[offset] I'm getting stuck as the offset can obviously be >255. The question is what would be the most optimal way to calculate the offset in this situation? Assembly solution is acceptable. Quote Link to comment Share on other sites More sharing options...
+mksmith Posted July 27, 2019 Author Share Posted July 27, 2019 So I've been playing around today and not getting any progress - been looking to use pointers to lookup the column (Y) and then getting the offset from that (X): dim pointer = a.b dim mapTable = $2200 dim mapTableRow0 = mapTable dim mapTableRow1 = mapTableRow0 + #25 dim mapTableRow2 = mapTableRow1 + #25 dim mapTableRow3 = mapTableRow2 + #25 dim mapTableRow4 = mapTableRow3 + #25 dim mapTableRow5 = mapTableRow4 + #25 data mapTableLookupPointerLo <#mapTableRow0,<#mapTableRow1,<#mapTableRow2,<#mapTableRow3,<#mapTableRow4,<#mapTableRow5 end data mapTableLookupPointerHi >#mapTableRow0,>#mapTableRow1,>#mapTableRow2,>#mapTableRow3,>#mapTableRow4,>#mapTableRow5 end function getOffset rem temp1=x temp2=y pointer[0] = mapBlockTableLookupPointerLo[temp2] : pointer[1] = mapBlockTableLookupPointerHi[temp2] temp3 = pointer[[temp1]] return temp3 Not entirely sure if that could/should/would even work... Any suggestions on this? Quote Link to comment Share on other sites More sharing options...
swapd0 Posted July 27, 2019 Share Posted July 27, 2019 It must work, having an offset to each row it's a good solution. 1 Quote Link to comment Share on other sites More sharing options...
+SmittyB Posted July 27, 2019 Share Posted July 27, 2019 I've made a couple of adjustments, not sure if anything else might be needed. rem 'a.b' is used for fixed-point numbers, not sure if it will confuse other parts of 7800BASIC rem As long as the low and high bytes are contiguous in memory it will work dim pointer = a dim pointerHi = b dim mapTable = $2200 dim mapTableRow0 = mapTable dim mapTableRow1 = mapTableRow0 + #25 dim mapTableRow2 = mapTableRow1 + #25 dim mapTableRow3 = mapTableRow2 + #25 dim mapTableRow4 = mapTableRow3 + #25 dim mapTableRow5 = mapTableRow4 + #25 rem Swapped around the # and >/< symbols data mapTableLookupPointerLo #<mapTableRow0,#<mapTableRow1,#<mapTableRow2,#<mapTableRow3,#<mapTableRow4,#<mapTableRow5 end data mapTableLookupPointerHi #>mapTableRow0,#>mapTableRow1,#>mapTableRow2,#>mapTableRow3,#>mapTableRow4,#>mapTableRow5 end function getOffset rem temp1=x temp2=y rem Changed the names to match the data definitions pointer[0] = mapTableLookupPointerLo[temp2] : pointer[1] = mapTableLookupPointerHi[temp2] temp3 = pointer[[temp1]] return temp3 1 1 Quote Link to comment Share on other sites More sharing options...
+mksmith Posted July 27, 2019 Author Share Posted July 27, 2019 @SmittyB Hey thanks for taking a look! Hmmm... still not getting a result though... Quote Link to comment Share on other sites More sharing options...
+SmittyB Posted July 27, 2019 Share Posted July 27, 2019 One of the things I wasn't sure about was how you're dimming the rows by referencing the previous location + 25. I've not tried it myself so I can't say if it works or not 1 Quote Link to comment Share on other sites More sharing options...
+mksmith Posted July 27, 2019 Author Share Posted July 27, 2019 No probs ? Yeah not quite sure either - might try a few variations. Putting together a quick little test app. Quote Link to comment Share on other sites More sharing options...
+mksmith Posted July 27, 2019 Author Share Posted July 27, 2019 @SmittyB Actually it may be working... I'll get back to you! 2 Quote Link to comment Share on other sites More sharing options...
+mksmith Posted July 27, 2019 Author Share Posted July 27, 2019 Ok - this does appear to work! I built a separate example to what i'm working with and it's displaying the correct values! So to set the value use the following: pointer[0] = mapTableLookupPointerLo[Y] : pointer[1] = mapTableLookupPointerHi[Y] : pointer[[X]] = value Thanks @SmittyB ??? 1 Quote Link to comment Share on other sites More sharing options...
+SmittyB Posted July 27, 2019 Share Posted July 27, 2019 That should be fine for setting the values. Glad that it's working. 1 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.