icbrkr #1 Posted January 4, 2003 I'm working some more in 5200BAS (after a few month vacation from it) and I've got a question on how to program something... I'm trying to figure out how to do a simple IF X>Y routine, but I haven't been able to. In other words, when a level ends, I need to check Player 1's score and Player 2's score and whomever's is higher, they win. But it appears I can't do: A=SCORE1 Y=SCORE2 IF A>Y THEN GOSUB STUFF and by the examples on your website, it's not possible either. The only thing I can do is IF A>1 THEN GOSUB STUFF.. Any ideas how I can work around this? Brian Quote Share this post Link to post Share on other sites
calamari #2 Posted January 5, 2003 I'm trying to figure out how to do a simple IF X>Y routine, but I haven't been able to. In other words, when a level ends, I need to check Player 1's score and Player 2's score and whomever's is higher, they win. But it appears I can't do: A=SCORE1 Y=SCORE2 IF A>Y THEN GOSUB STUFF Any ideas how I can work around this? This is because the 6502 doesn't allow register,register compares (or adds, subtracts, etc, for that matter).. the only thing I can think of that allows reg-reg are transfers (copy/move).. like tya, tay, txa, etc, even then you cant do txy or tyx directly. You also can't do memory-memory compares. You can compare a register vs memory (of different kinds.. zeropage, x/y indexed, indirect, etc), or a register vs an immediate.. so as you found you can do: CMP #$01 ;does A=1? (reg vs immed) Which is isn't any good for this situation, I agree.. but you can also do: CMP $EE ;does A=the value at location $EE? (reg vs memory) The second way works well for what you are trying to do. Let's see it in 5200BAS code: A=SCORE1 IF A>SCORE2 THEN:GOSUB STUFF:END IF As a sidenote, you'll want to avoid > if possible (comparing with > and <= takes two instructions vs. one instruction for < and >=, see the IF entry in the Command Reference).. so I'd suggest this instead: A=SCORE2 IF A<SCORE1 THEN:GOSUB STUFF:END IF I'm assuming that you will have it call different subroutines depending on who wins, so the code might look like this: A=SCORE2 IF A<SCORE1 THEN GOSUB STUFF ELSE GOSUB STUFF2 END IF You could also use Y instead of A in the above code.. or X.. whatever you prefer. HTH, calamari Quote Share this post Link to post Share on other sites
icbrkr #3 Posted January 5, 2003 A=SCORE2 IF A<SCORE1 THEN:GOSUB STUFF:END IF I'm assuming that you will have it call different subroutines depending on who wins, so the code might look like this: A=SCORE2 IF A<SCORE1 THEN GOSUB STUFF ELSE GOSUB STUFF2 END IF You could also use Y instead of A in the above code.. or X.. whatever you prefer. HTH, calamari I didn't even realize it was possible to use another variable besides X, Y, and A in a comparison (IF A Brian Quote Share this post Link to post Share on other sites