Subject: Re: [stella] one last 16 bit compare question From: KirkIsrael@xxxxxxxxxxxxx Date: 10 Mar 2004 05:19:15 0000 
> Be careful when comparing only the integer portion of a fixed point number > because the fractional portion is considered unsigned. > > int range > 2 2.000 to 2.996 > 1 1.000 to 1.996 > 0 0.000 to 0.996 > 1 0.004 to 1.000 > 2 1.004 to 2.000 > > So if you clip the integer value to +/ 2 your positive range will be higher > than your negative range. Here's the code I came up with too make sure the abs(speed) wasn't too big: BALL_MAX_POS_SPEED_HI = #1 BALL_MAX_NEG_SPEED_HI = #1 ;making sure ball speed isnt to extreme (abs(speed) not too big) LDA slowBallYSpeed+1 CMP #BALL_MAX_POS_SPEED_HI BMI BallSpeedLessThanMax LDA #BALL_MAX_POS_SPEED_HI BallSpeedLessThanMax CMP #BALL_MAX_NEG_SPEED_HI BPL BallSpeedGreaterThanMin LDA #BALL_MAX_NEG_SPEED_HI BallSpeedGreaterThanMin STA slowBallYSpeed+1 So basically I'm just looking at the high byte... against positive values, I can see the range is 0 < val <= 0000000111111111 but by just looking at the high byte for negative values, how much more or less negative can it be than positive? If its just a few bits I don't care, but I think it might be just under a whole byte worth an assymetry I don't like Maybe I should just do what I came up with for making sure abs(speed) wasn't too small...at my friend Ranjit's suggestion, if the speed is negative, I take it's negative to get a positive, and then do that compare (I use Y register as a boolean about whether the original value was negative, and then, if it's "too small", set it to the correct a bit small postive or a bit small negative value:: ;comparison to make sure speed ;isn't too slow; it's much easier to ;do comparisons w/ positive values, ;and also we know it's a small positive ;value, so once it's positive, if the ;hi byte is not zero, it MUST be big enough ;so we make a copy into temp, and then ;change the original if we see the guaranteed ;positive version is too small LDA slowBallYSpeed STA tempVar LDA slowBallYSpeed+1 STA tempVar+1 LDY #0 ; Y is boolean, 0 = postive LDA tempVar+1 BPL ThisAintNegativeSpeed LDY #1 ;remember that this is negative ;negate what's in temp sec lda #0 sbc tempVar sta tempVar lda #0 sbc tempVar+1 sta tempVar+1 ThisAintNegativeSpeed ;we know tempvar is 16 bit, positive value LDA tempVar+1 BNE DoneSeeingBallSpeedIsBigEnough LDA tempVar CMP #BALL_MIN_POS_SPEED_LO bcs DoneSeeingBallSpeedIsBigEnough tya BEQ ChangeBallSpeedToMinPositive ChangeBallSpeedToMinNegative LDA #BALL_MIN_NEG_SPEED_LO sta slowBallYSpeed LDA #BALL_MIN_NEG_SPEED_HI sta slowBallYSpeed+1 JMP DoneSeeingBallSpeedIsBigEnough ChangeBallSpeedToMinPositive LDA #BALL_MIN_POS_SPEED_LO sta slowBallYSpeed LDA #BALL_MIN_POS_SPEED_HI sta slowBallYSpeed+1 DoneSeeingBallSpeedIsBigEnough It's a little brutal, and uses two bytes of tempVar, but still, at least even *I* can understand it :)  KirkIsrael@xxxxxxxxxxxxx http://kisrael.com "Death smiles at us all. All a man can do is smile back." Gladiator  Archives (includes files) at http://www.biglist.com/lists/stella/archives/ Unsub & more at http://www.biglist.com/lists/stella/
Current Thread 


< Previous  Index  Next > 

Re: [stella] one last 16 bit compar, Eric Ball  Thread  [stella] not quote on topic: artsy , KirkIsrael 
Re: [stella] one last 16 bit compar, Eric Ball  Date  [stella] finalish joustpong feedbac, KirkIsrael 
Month 