Jump to content
IGNORED

Memory Map and accessing offset > 255


mksmith

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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

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