How does Object_v_speed_lo work? [4.5]

jataka5000

New member
Hello,

I've been studying the doHandlePhysics script carefully, and I don't quite understand how Object_v_speed_lo and Object_v_speed_hi really work. I get the analogy of Object_v_speed_lo being like the minute hand and Object_v_speed_hi the hour hand, but I don't see anywhere in this script (or any other) where the math is actually being done to then calculate the speed. Is there a script somewhere which says that once Object_v_speed_lo goes beyond #$ff then Object_v_speed_hi increases by 1?

That's what I want to get at. Weird things happen if I just try to ignore updating the _lo or _hi... seems that we need both.


There is one strange piece of code that I cannot make sense of what happens in doHandlePhysics_Gravity under 'notJumpThruPlat:' --

Code:
LDA Object_v_speed_hi,x
CMP #MAX_FALL_SPEED
BNE notOverFallSpeed
; is at least max fall speed.
LDA #$00
STA Object_v_speed_lo,x
notOverFallSpeed:

JMP doneWithGravity

It seems like it is setting the minute hand to zero each time if the max speed has not been reached. I was expecting there to be a clause that says to skip updating the speed once the speed has reached the max value. But I don't see anything like that. This comparison (CMP #MAX_FALL_SPEED) actually shows up *after* the position and speed are updated, very strange.

I'm trying to dig into these details because I am wanting to do essentially the same thing but with the direction of gravity reversed. In ASM, turns out I need to deeply understand what's going on, there is no way to "put a minus sign" in there :)
 

jorotroid

Member
It's setting it to 0 if the the max speed has been reached. Meaning that Object_v_speed_lo is being kept at 0 so Object_v_speed_hi can never get any bigger. Maybe another way to look at it: the hi variables are what actually get used to calculate an object's position. The lo versions are used to calculated how fast the hi variables can change.

I'll make some comments for that code to try to clear it up:

Code:
LDA Object_v_speed_hi,x			; Gets the hi vertical speed of the object
CMP #MAX_FALL_SPEED			; Compares that speed to the MAX_FALL_SPEED constant
BNE notOverFallSpeed			; If the hi vertical speed and the max fall speed are not equal (so in this context, if Object_v_speed < MAX_FALL_SPEED), branch ahead to the notOverFallSpeed label
; is at least max fall speed.		; The hi vertical speed was equal to the max fall speed, so we
LDA #$00				; Load 0 int to the accumulator
STA Object_v_speed_lo,x			; And set the lo vertical speed to 0
notOverFallSpeed:			; Both branches will come back together here.

JMP doneWithGravity			; Jump to the doneWithGravity label.

I think they should have used BCC instead of BNE so it would have checked specifically for less than instead of not equal. With BNE if there is some other process that can change the Object_v_speed_hi, the object could go faster than the max speed and just keep on accelerating until the values loop over.
 
Top Bottom