Shufflehound Posted December 4, 2013 Share Posted December 4, 2013 I'm going through some 2600 source code and I'm seeing tonnes of "lda"s and "sta"s. What do they mean? Even in "2600 Programming for Newbies" I can't really find an explanation. Very newbie question, but with so many of these in the code, it would be nice to know. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Wickeycolumbus Posted December 4, 2013 Share Posted December 4, 2013 LDA and STA are two very common 6502 instructions. LDA being LoaD Accumulator and STA STore Accumulator. LDA is used to load a new value into the accumulator from a variety of sources (immediate, memory, or indexed memory). STA allows you to store the contents of the accumulator to a memory location. The Accumulator is the main register of the 6502 and is used to perform many numerical operations. If you are interested in learning 6502 assembly, you should take a look at Machine Language for Beginners, it's a great read for anyone with programming experience, but minimal knowledge about processors. Chapter 6 has a summary of all the instructions, where you can look up others if you're curious. Quote Link to comment Share on other sites More sharing options...
Shufflehound Posted December 4, 2013 Author Share Posted December 4, 2013 Thank you very much! Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted December 4, 2013 Share Posted December 4, 2013 Here's a good list of links in case you need them in the future: randomterrain.com/atari-2600-memories-tutorial-andrew-davie-01.html#useful_links Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted December 4, 2013 Share Posted December 4, 2013 Also may be good for an overview http://www.dwheeler.com/6502/oneelkruns/asm1step.html Quote Link to comment Share on other sites More sharing options...
+nanochess Posted December 4, 2013 Share Posted December 4, 2013 The address that you use for LDA/STA also has a meaning if it access a peripheral. By example, in Atari VCS is very common STA WSYNC to wait for next video line. Quote Link to comment Share on other sites More sharing options...
Shufflehound Posted December 4, 2013 Author Share Posted December 4, 2013 Also, does anyone have any links on converting numbers to Atari hex? I'm asking because all hex converters I've come across have completely different hex results than what the Atari uses. For instance, in this tutorial code it says that "-1" is "#$F0" in assembly, but on the online converters it says it's "00 01" and that "F0" is "240". Mind confuzzled. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted December 5, 2013 Share Posted December 5, 2013 I use this when working with batari Basic: randomterrain.com/atari-2600-memories-batari-basic-tools-toys.html I don't know if you need something different when using assembly language. Quote Link to comment Share on other sites More sharing options...
+nanochess Posted December 5, 2013 Share Posted December 5, 2013 Also, does anyone have any links on converting numbers to Atari hex? I'm asking because all hex converters I've come across have completely different hex results than what the Atari uses. For instance, in this tutorial code it says that "-1" is "#$F0" in assembly, but on the online converters it says it's "00 01" and that "F0" is "240". Mind confuzzled. 6502 can handle only 8 bits of data. So zero is $00 and minus one is $FF, alternatively you can see it as 255 decimal. The point is that if you have a value of $03 and you add it $FF then you'll have $02 (3 plus -1 equals 2) because this trick Quote Link to comment Share on other sites More sharing options...
danwinslow Posted December 5, 2013 Share Posted December 5, 2013 (edited) Hex is hex, there's no 'atari' hex. Hex is four bits per character. Atari uses 8 bit bytes. Therefore, two hex characters make up one atari byte. 'Hex' stands for hexadecimal, meaning base 16, meaning numerals 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. So a hex number like $03 ( the dollar means its hex ) means a hex value of 0 followed by a hex value of 3. In binary, this would look like 0000 0011. A hex value of $A1 would look like this in binary : 1010 ( ie., decimal 10 or hex $A ) followed by 0001. Negative numbers are represented using two's complement ( you can google that ), so a -1 decimal looks like 1111 1111 binary, which looks like $FF in hex. All these expressions 'mean' the same bit pattern : -1,$FF,255,11111111 Edited December 5, 2013 by danwinslow Quote Link to comment Share on other sites More sharing options...
Shufflehound Posted December 5, 2013 Author Share Posted December 5, 2013 6502 can handle only 8 bits of data. So zero is $00 and minus one is $FF, alternatively you can see it as 255 decimal. The point is that if you have a value of $03 and you add it $FF then you'll have $02 (3 plus -1 equals 2) because this trick So how come "255" equals "-1" in this case? So, are you saying that there's a point where half way through the 6502's numbers there's a point where "128" is actually "-128"? Could it be seen as two 128s but the second version is minus numbers? So is $7F equal to 127, but $80 is equal to -128? Quote Link to comment Share on other sites More sharing options...
+nanochess Posted December 5, 2013 Share Posted December 5, 2013 So how come "255" equals "-1" in this case? So, are you saying that there's a point where half way through the 6502's numbers there's a point where "128" is actually "-128"? Could it be seen as two 128s but the second version is minus numbers? So is $7F equal to 127, but $80 is equal to -128? You're right with both interpretations, $81 is -127 or 129 depending on context. You choose if your program or some special variable of yours is using signed or unsigned numbers, the processor doesn't note the difference. It simplifies enormously programming matters specially when you start handling 16-bit numbers using two bytes, the lowest byte always is unsigned and the higher byte is signed or unsigned per your requirements. Quote Link to comment Share on other sites More sharing options...
Wickeycolumbus Posted December 5, 2013 Share Posted December 5, 2013 Everything just depends on how your program is set up to interpret different numbers. I've personally never used a negative number in any of my games. If you're interested in binary representations of negative numbers, look up sign magnitude notation and 2's complement. Of course, these binary representations can be converted to other bases, such as hex or decimal, so that explains why FF could be either 255 decimal or -1 decimal, which is it's 2's complement interpretation. Quote Link to comment Share on other sites More sharing options...
Shufflehound Posted December 5, 2013 Author Share Posted December 5, 2013 I realise how much I don't know. Do the signed and unsigned numbers have something to do with the A, X and Y? Do you tell the 6502 what number draws the line between being positive and negative? Quote Link to comment Share on other sites More sharing options...
Shufflehound Posted December 5, 2013 Author Share Posted December 5, 2013 Do the minus numbers have anything to do with the jargon "left nibble?" Quote Link to comment Share on other sites More sharing options...
+nanochess Posted December 5, 2013 Share Posted December 5, 2013 Don't worry at start of programming learning just think that all numbers are unsigned. Quote Link to comment Share on other sites More sharing options...
Shufflehound Posted December 5, 2013 Author Share Posted December 5, 2013 Ah, okay then. So, with out minus numbers, how can you move to the right using HMOVE? Quote Link to comment Share on other sites More sharing options...
danwinslow Posted December 5, 2013 Share Posted December 5, 2013 I realise how much I don't know. Do the signed and unsigned numbers have something to do with the A, X and Y? Do you tell the 6502 what number draws the line between being positive and negative? No, and No. In a way, there's no such thing as a negative number to the computer, its all just eight bits. 255 is the same as 11111111 is the same as $FF. You can interpret 11111111 as -1, depending on the context, but to the computer it's stil just 11111111. The numbers roll over at 255, since all eight bits are used. 255+1=0 ( but the carry flag gets set ). Quote Link to comment Share on other sites More sharing options...
+nanochess Posted December 5, 2013 Share Posted December 5, 2013 (edited) Ah, okay then. So, with out minus numbers, how can you move to the right using HMOVE? Use one of the commonly available routines, like this http://atariage.com/forums/topic/198465-i-want-to-keep-learning-a2600-programming-but-im-stuck/?do=findComment&comment=2529970 Note it uses negative numbers to calculate the final position, but you don't need to think about it at this point. Edited December 5, 2013 by nanochess 1 Quote Link to comment Share on other sites More sharing options...
Wickeycolumbus Posted December 5, 2013 Share Posted December 5, 2013 Ah, okay then. So, with out minus numbers, how can you move to the right using HMOVE? You wouldn't store say a -3 to HMOVE to reset it's position 3 clocks to the right, you'd store 11011111b (which is 223d, or DFh). This is covered in the Stella Programmer's Guide. Here is a link the table of values HMOVE interprets: http://www.alienbill.com/2600/101/docs/stella.html#HMOVE It's all about what the hardware or functions in your program that numbers are passed to interpret them as. Think of them as 256 values that could mean anything. 2 Quote Link to comment Share on other sites More sharing options...
Shufflehound Posted December 5, 2013 Author Share Posted December 5, 2013 Could I just put binary instead of hex wherever I like, then? Quite honestly I find binary easier to get my head round. I find the two's compliment hex thing very confusing. Quote Link to comment Share on other sites More sharing options...
Shufflehound Posted December 5, 2013 Author Share Posted December 5, 2013 You wouldn't store say a -3 to HMOVE to reset it's position 3 clocks to the right, you'd store 11011111b On the Programmer's Guide it says 1101. What do the extra 1111b mean? Is that just filling in for the byte? Quote Link to comment Share on other sites More sharing options...
+nanochess Posted December 5, 2013 Share Posted December 5, 2013 (edited) On the Programmer's Guide it says 1101. What do the extra 1111b mean? Is that just filling in for the byte? On the world of Atari's TIA, there are several bits in registers that aren't used, you can fill them with zeros or ones. The HMOVE registers use bits 7-4 and bits not used are 3-0, so you can use 11011111b or 11010000b as you like. Edited December 5, 2013 by nanochess Quote Link to comment Share on other sites More sharing options...
Wickeycolumbus Posted December 5, 2013 Share Posted December 5, 2013 (edited) On the Programmer's Guide it says 1101. What do the extra 1111b mean? Is that just filling in for the byte? The head of the table specifies bits D4-D7, which are the 4 most significant bits. The other 4 (D0-D3) can actually be anything, because the hardware ignores them. So storing 11010000 would do the same thing as 11010001 and 11010010, and so on. As long as D4-D7 are set as you want them, the others can contain any value. Edit: Ha, we keep posting at the same time Edited December 5, 2013 by Wickeycolumbus Quote Link to comment Share on other sites More sharing options...
+nanochess Posted December 5, 2013 Share Posted December 5, 2013 Edit: Ha, we keep posting at the same time Well, two advices are better than one I'll leave to go to dinner 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.