Jump to content
IGNORED

Excluding numbers


Recommended Posts

I would like to exclude a few numbers ($00, $30, $C0, and $F0) but this routine doesn't seem to be doing it. Is there an obvious reason why?

	 LDA	  Run
 CLC
 ADC	  #$20

 BEQ	  Pickups
 CMP	  #$30
 BEQ	  Pickups
 CMP	  #$C0
 BEQ	  Pickups
 CMP	  #$F0
 BEQ	  Pickups
 JMP	  Pickups_2
 

Pickups: 
 CLC	  
 ADC	  #$10

Pickups_2: 

 STA	  Run

Link to comment
Share on other sites

Is the code written to do what you want it to do though?

 

It's comparing after adding the initial #$20 value.

 

So, effectively, it is doing:

 

A=(A+32) AND 255

IF A=0 OR A=48 OR A=192 OR A=240 THEN A=A+16

RUN=A

 

So, if the initial value in A is $E0, $10, $A0 or $D0 - then A gets $30 added to it.

otherwise, it just gets $20 added.

Link to comment
Share on other sites

Is the code written to do what you want it to do though?

 

It's comparing after adding the initial #$20 value.

 

So, effectively, it is doing:

 

A=(A+32) AND 255

IF A=0 OR A=48 OR A=192 OR A=240 THEN A=A+16

RUN=A

 

So, if the initial value in A is $E0, $10, $A0 or $D0 - then A gets $30 added to it.

otherwise, it just gets $20 added.

Yes, that is exactly what I want it to do. I don't want any of those 4 numbers to end up in A.

 

Cybergoth, I did notice that $F0 + $10 = $0 so I changed the $10 to a $20 but it made no difference.

 

Would $F0 + $20 = $10?

Edited by accousticguitar
Link to comment
Share on other sites

Is the code written to do what you want it to do though?

 

It's comparing after adding the initial #$20 value.

 

So, effectively, it is doing:

 

A=(A+32) AND 255

IF A=0 OR A=48 OR A=192 OR A=240 THEN A=A+16

RUN=A

 

So, if the initial value in A is $E0, $10, $A0 or $D0 - then A gets $30 added to it.

otherwise, it just gets $20 added.

Yes, that is exactly what I want it to do. I don't want any of those 4 numbers to end up in A.

 

Cybergoth, I did notice that $F0 + $10 = $0 so I changed the $10 to a $20 but it made no difference.

 

Would $F0 + $20 = $10?

Yes, $F0+$20=$10.

 

Here's an idea: change the code like this:

	 LDA	  Run
Pickups
 CLC
 ADC	  #$20

 BEQ	  Pickups
 CMP	  #$30
 BEQ	  Pickups
 CMP	  #$C0
 BEQ	  Pickups
 CMP	  #$F0
 BEQ	  Pickups
 STA	  Run

Then you know that it should never get through unless it is one of the right numbers. The key change here is that you check the value after you modify it. Still want to watch out for endless loops, though - I don't know if it will fall into one or not.

 

Plus this version takes less code. :)

Link to comment
Share on other sites

Yes, but if you have subroutines or stack manipulation nested too deep, ram locations will begin to show signs of curruption (the stack builds itself downward). For example, 5 levels of nesting + a PHA would corrupt $F5.

 

Or, an index register could be using a bad value that causes it to store out of the intended range.

 

Search a z26 .log file for stores to $F5 to be sure.

Link to comment
Share on other sites

Upon further review, I was wrong. It is skipping over the BEQs like they are not even there. It is adding $20 to the accumulator and then storing it in Run without excluding the numbers at all. It does not appear to be different numbers in there like random numbers being put in. It appears to be adding $20 like clockwork and no more than that ever.

Edited by accousticguitar
Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...