Scroll window and Objects

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Scroll window and Objects

Post by JoeGtake2 »

Hey all. So, I've got a completely unruly routine gauging objects' placement. It has been the most maddening thing, and the wonkiness and complexity of it is still yielding edge cases I can't account for. So I'm trying to dramatically simplify so at the very least, anomalies will be easier to find.

Essentially, right now I have a 32 column area. I have a 16 bit camera position, which I can compare to an object's 16 bit position to know whether or not to give the object a draw status. This generally works, but I get the occasional edge case where the draw state flips on when the object should be firmly in the opposite nametable (one less in the high byte tan the camera position).

I also attempted to trying things with turning an object's position into a value out of 32, for a direct comparison with the camera's column. After a lot of edge case scenarios, this gave me similar unexpected false writes.

What methods do you guys use for things like this? How would you keep objects within a camera view? The 16bit idea above would be the most logical, wouldn't it?
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Scroll window and Objects

Post by unregistered »

Hi, our game uses 16bit square metatiles and is set up with enough RAM set aside to store 32 columns. Also, our camera, like yours, is 16bit. The crucial explanation to my question about how to keep track of metatiles exists, from tepples, at the bottom of page 69 of this thread.

It was hard for me to understand :oops: , but I spent much time rereading tepples' post over and over and then experimenting with my code trying to grasp his valid_left and visible_left. There was an end to my struggles, thankfully, after being blessed with fully grasping and implementing everything he talked about. Hope his post can help you too; tepples is so wise. :)


edit: Sorry, you are talking about objects... um I still haven't solved the only edge case reading problem that I still have... but, so far, the simplest way of checking an object's collision, that I've found, is to do something like this (labels beginning with + work in asm6... +skip can be changed to whatever type of label you want :)):

Code: Select all

;if you are comparing two 16 bit values:
lda column+0
eor objectX+0
bne +skip
  lda column+1
  eor objectX+1
  bne +skip
    ;code to run if the two 16bit values are equal
+skip
eor works because that instruction never returns 0 unless all bits of both values are the same.
i.e.
0 xor 0 = 0
0 xor 1 = 1
1 xor 0 = 1
1 xor 1 = 0

Notice that the only results of 0 are when both bits are the same. :)


edit2: Sorry. Fixed misspellings from "lable" to "label". Also noticed that my code example didn't make any sense... why would we ever check object's location with camera's position... so those variable names have been updated so that it becomes helpful, I hope.

final edit: It doesn't make sense, to me, that the column should be 16bit... so I created two other variables columnLo and columnHi... and there are two translate functions that run depending on if the player is pressing left or right... each translate the column # to be drawn to columnLo and columnHi. They aren't posted here because they are very specific to our game. :)
Last edited by unregistered on Fri Oct 19, 2018 10:39 am, edited 2 times in total.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Scroll window and Objects

Post by Oziphantom »

You must get the two values into the same space, then its trivial, just beware the tri-state of < >= you might need to handle =. You need to be very diligent and 100% check to make sure that your start values and end values are either inclusive or exclusive and never mix it up.

There is no standard, there is no "this is the way it is done", there is no I'm doing this what am I doing wrong. It is 100% abstract and is what ever rules and maths you have come up with, we can't help you with anything specific unless we see ALL of your code, and I mean all of it. Typically when I stuff something like this up, I stuff up the easy part I assume is right and get all the hard maths correct. Due to spaces being collinear with each other, you can get the case where it is actually 100% wrong, but just so happens to look right 95% of the time.
Post Reply