Jump to content



0

2600 programming


3 replies to this topic

#1 karnov OFFLINE  

karnov

    Space Invader

  • 35 posts

Posted Mon Jun 14, 2004 8:12 PM

Hello,
In this code:

          ldx #0

          lda #0

Clear     sta 0,x

          inx

          bne Clear

Is this what is happening?:
1) load x with the number 0 (so now x=0)
2) load the accumulator with the number 0 (so now accumulator = 0)
3) assign this line in the program as the location known as "Clear"
4) store whats in the accumulator (0) into location x+0
5) increase x by 1 (so now x=1)
6) branch to the location known as "Clear" if the result of the previous
line is not 0 (therefore creating a loop)

First question: Is that a correct analysis of this code? (If i'm wrong please
correct me.)

Second question: How does this clear RAM and all TIA registers?

Thanks!

#2 Andrew Davie OFFLINE  

Andrew Davie

    Stargunner

  • 1,314 posts
  • Location:Tasmania

Posted Mon Jun 14, 2004 10:42 PM

karnov said:

Hello,  
 In this code:

          ldx #0

          lda #0

Clear     sta 0,x

          inx

          bne Clear

Is this what is happening?:
1) load x with the number 0 (so now x=0)
2) load the accumulator with the number 0 (so now accumulator = 0)
3) assign this line in the program as the location known as "Clear"
4) store whats in the accumulator (0) into location x+0  
5) increase x by 1 (so now x=1)
6) branch to the location known as "Clear" if the result of the previous
   line is not 0 (therefore creating a loop)

First question: Is that a correct analysis of this code? (If i'm wrong please
                    correct me.)

Second question: How does this clear RAM and all TIA registers?

Thanks!


Essentially correct. The branch is taken when the Z flag is non-zero (that's the meaning of the BNE op-code -- branch NOT equal to zero). X starts at 0, and it will take 256 increments before it is 0 again (and the Z flag is cleared). So this code will loop 256 times and clear 256 memory locations starting at 0.

Since the RAM starts at $80 (128 decimal) and the TIA registers are effectively at location 0 onwards, you end up clearing both 128 bytes of RAM, and stomping all over TIA registers (read-only and write-only and read-write) with 0, too. It doesn't really matter if you write 0 to read-only registers in the TIA -- the action is harmless.

So the above is a simple way to clear the machine to a known state. It is not, however, the most efficient way. I suggest you ask these sorts of questions in the Programming for Newbies forum!

Cheers
A

#3 karnov OFFLINE  

karnov

    Space Invader

  • 35 posts

Posted Tue Jun 15, 2004 10:35 PM

Thanks for the help Mr. Davie, I have found your tutorials very helpful. I will post the rest of my questions in the newbie section. Thanks again!

#4 Andrew Davie OFFLINE  

Andrew Davie

    Stargunner

  • 1,314 posts
  • Location:Tasmania

Posted Tue Jun 15, 2004 10:39 PM

karnov said:

Thanks for the help Mr. Davie, I have found your tutorials very helpful. I will post the rest of my questions in the newbie section. Thanks again!

No worries. Since you appear to be Russian, you might also enjoy my Museum of Soviet Calculators -- http://www.taswegian...COW/soviet.html




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users