karnov Posted June 15, 2004 Share Posted June 15, 2004 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! Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted June 15, 2004 Share Posted June 15, 2004 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 Quote Link to comment Share on other sites More sharing options...
karnov Posted June 16, 2004 Author Share Posted June 16, 2004 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! Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted June 16, 2004 Share Posted June 16, 2004 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.com/MOSCOW/soviet.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.