I'm having the most difficult time weeding out stray edge case nonsense with this L-R scrolling engine, so I thought I'd post up here rather than bash my head against the same thing over and over again for another night to get your guys' thoughts.
Obviously, you guys know that I'm a bit wrangled on method simply due to mutli-purpose, malleable nature of this engine. So bear with me.
Background collisions and column loads are working great. I have vertical mirroring, so I load current nametable at $2000, then the left half of the right nametable to the second nametable, right half of the left nametable to the second nametable. The midpoint of the second nametable is the seam. All good. I've got background scrolling working perfectly - attributes, collisions, nametables all acting just like they're supposed to - variable pads on each side of the scroll, autoscroll bits...a few particular "it must be this way" things I'd eventually like to address, but for right now, I'm having a hell of a time with objects, with something I felt would be fairly simple.
There is a columnTracker variable. It can be 0-31. This represents the camera-left column. Thus, columnTracker+24 is the seam. Cool. As the camera scrolls it updates the seam, and checks the screen info to see if objects should be loaded. This is fine.
Objects have a variable called Object_status. Bit 2 of Object_status determines if they are in the camera view or not (1 = active but out of view, 0 = in view). This is where all things break down.
This should be a fairly simple thing, but effectively, here's the logic I am trying to handle:
Hopefully that makes sense. The problem is, everything I try that seems to work out logically to check to see when columnTracker is in the second nametable ends up yielding bugs (things turning on when they shouldn't/off when they shouldn't).
Was hoping for some thoughts, advice, etc. What do you guys think the best method would be for determining in/out of camera here?
Thanks!
Obviously, you guys know that I'm a bit wrangled on method simply due to mutli-purpose, malleable nature of this engine. So bear with me.
Background collisions and column loads are working great. I have vertical mirroring, so I load current nametable at $2000, then the left half of the right nametable to the second nametable, right half of the left nametable to the second nametable. The midpoint of the second nametable is the seam. All good. I've got background scrolling working perfectly - attributes, collisions, nametables all acting just like they're supposed to - variable pads on each side of the scroll, autoscroll bits...a few particular "it must be this way" things I'd eventually like to address, but for right now, I'm having a hell of a time with objects, with something I felt would be fairly simple.
There is a columnTracker variable. It can be 0-31. This represents the camera-left column. Thus, columnTracker+24 is the seam. Cool. As the camera scrolls it updates the seam, and checks the screen info to see if objects should be loaded. This is fine.
Objects have a variable called Object_status. Bit 2 of Object_status determines if they are in the camera view or not (1 = active but out of view, 0 = in view). This is where all things break down.
This should be a fairly simple thing, but effectively, here's the logic I am trying to handle:
Code:
;; If inside the camera window, jump to "show this object"
;; If outside the camera window, jump to "hide this object"
LDA Object_x,x
LSR
LSR
LSR
LSR
STA temp ;; now, we know which one of 16 columns.
LDA Object_scroll,x
AND #%00000001
ASL
ASL
ASL
ASL
ORA temp
STA thisObjectColumnPosition
;;;;;;;; the scroll value acts as the high x byte. This puts it in place in byte 4, giving
;;;;;;;; the object its column evaluation
;;;;;;;============
;;;;;; For if the scroll is 0-15, this is fairly straight forward.
;;;;;; it would look like this:
LDA columnTracker
CMP thisObjectColumnPosition
BCC outsideOfCamera
;;;;;; still inside, check right edge.
LDA columnTracker
CLC
ADC #$10
AND #%00011111
CMP thisObjectColumnPosition
BCC outsideOfCamera
;;;;;; Passed the test, that means this is inside
;;;;;; Camera area.
JMP doInsideCamera
outsideOfCamera:
LDA Object_status,x
ORA #%00000100
STA Object_status,x
JMP done
doInsideCamera:
LDA Object_status,x
AND #%11111011
STA Object_status,x
done:
;; If outside the camera window, jump to "hide this object"
LDA Object_x,x
LSR
LSR
LSR
LSR
STA temp ;; now, we know which one of 16 columns.
LDA Object_scroll,x
AND #%00000001
ASL
ASL
ASL
ASL
ORA temp
STA thisObjectColumnPosition
;;;;;;;; the scroll value acts as the high x byte. This puts it in place in byte 4, giving
;;;;;;;; the object its column evaluation
;;;;;;;============
;;;;;; For if the scroll is 0-15, this is fairly straight forward.
;;;;;; it would look like this:
LDA columnTracker
CMP thisObjectColumnPosition
BCC outsideOfCamera
;;;;;; still inside, check right edge.
LDA columnTracker
CLC
ADC #$10
AND #%00011111
CMP thisObjectColumnPosition
BCC outsideOfCamera
;;;;;; Passed the test, that means this is inside
;;;;;; Camera area.
JMP doInsideCamera
outsideOfCamera:
LDA Object_status,x
ORA #%00000100
STA Object_status,x
JMP done
doInsideCamera:
LDA Object_status,x
AND #%11111011
STA Object_status,x
done:
Hopefully that makes sense. The problem is, everything I try that seems to work out logically to check to see when columnTracker is in the second nametable ends up yielding bugs (things turning on when they shouldn't/off when they shouldn't).
Was hoping for some thoughts, advice, etc. What do you guys think the best method would be for determining in/out of camera here?
Thanks!