Jump to content
Sign in to follow this  
icbrkr

Question for Calamari...

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...