Hello, new here, and need best recommandations.

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

Re: Hello, new here, and need best recommandations.

Post by DocWaluigean »

tokumaru wrote:
DocWaluigean wrote:THIRD TIME! Third time is a lucky number time. I'm going to read it, and I'm going to pretend that you never wrote this, so I can get it out of my system.
Just wanted to make it clear that I wasn't trying to be rude or anything, I was just warning you to be careful with your expectations. Programming games isn't always fun, most of it is actually solving problems. If you don't find problem-solving fun, programming games will always feel like a chore to you.
Actually, that was a fun-sentences like if cartoony people were to say, "Welp! Third time's the charm!" It's more of "I'm starting to feel little more comfortable, I guess I should say it." attitude.

I'm sorry if I'm being the one whose rude though. It's, sadly, just who I am. Alongside I said earlier that it took me 5 years from beginning to learning all the way to last month to try to really learn 6502.

Also, I don't want to be view as, "This thug is up to something bad." this and other that. Obviously the internet is like the real world with illegal crimes and stuff. I'm not anything like those.
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Hello, new here, and need best recommandations.

Post by Kasumi »

-I'm guessing I'm right about the lesson on Branching is "The Program Counter is where are you in Address now."
This is correct. Or at least. It's correct that the program counter is where the CPU will next execute an instruction. You are not correct that that was the goal of the lesson. The Program Counter was taught only to make it easier to follow the real lesson, which was branching.
-When the Program Counter is going up, the Opcode goes up by 2, and the Address goes up by 3. When it's number/HEX/Decimals, it's only 2 code upward, in favor for the opcode, that's used in the Address code, and the number that's also used for the Address code. I'm guessing high-byte and low-byte doesn't count here.
This is not. Each instruction always has an opcode. This is one byte. Most instructions then have an operand of either 1 or 2 bytes. So if you are using an instruction that is dealing with an address (that isn't $0000-$00FF) it is three bytes. One byte for the opcode. Two bytes for the operand which is an address.

Some instructions are exactly one byte total (just the opcode), we just haven't covered any of those yet.
Way simpler: The CPU just "knows" how many bytes each instruction is. It will add the size in bytes of the current instruction to the PC and then the PC will have the address of the next instruction.
Edit:
Because the $12 represent the "street" of the code, while $34 represent the "house of the code. $12 might be CPU, PPU, RAM. And the $34 might be the lever or role/job for what they do FOR CPU, PPU, RAM.
This is actually a reasonably solid way to look at it. It is correct that the byte in $12's place usually does defines a "profession" (like construction), while the byte in $34's place usually chooses the role within that profession. (Flag Man, cement truck driver.) RAM isn't really delegated into jobs, though.
-Labels are a type of BIG box you can use for later codings.
They're actually more like the label you put ON the box. Labels don't really "store" anything. They just name things.

How you've commented the example isn't correct, but I'm going another way for now.

Everyone following this topic will probably think I'm crazy for even trying this example here, but I think it will actually help.

I will explain why I'm doing this upfront. I want to make it clear that everything is just bytes. That the 6502 CPU doesn't care that much about things. Most context is created to help the programmer.

Order is VERY IMPORTANT. Do these things step by step. If you do anything out of order, you will need to navigate to the page again and follow the steps again starting from 1.

1. Go to an easy6502 code box.
2. Erase what's in the box.
3. Type (but don't assemble) the following code.

Code: Select all

lda #$A2
sta $0600
This address should look familiar. It is the address of the first byte of the first instruction, if you recall.
4. Type 0600 next to Start: $
5. Check the checkbox next to "Monitor"
Your easy6502 box should now look like this:
Image
6. Click assemble
7. Check the checkbox next to "Debugger"
8. Click step.
9. Type out (in notepad or something, not easy6502) the values to the right of 0600: under the monitor checkbox. These are the bytes that the code (lda #$A2, sta $0600) became.
10. Click run.
11. Type out which values are in in A, X and Y underneath the bytes you typed out earlier.
12. In your document, type out the values to the right of 0600: under the monitor again. They've changed, but this should make sense. After all, you just stored a number there.
13. Click reset.
14. Click run.
15. Type out which values are in A, X, and Y underneath the bytes you typed out earlier.

What changed? Do you have a guess as to why this might be?
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

Re: Hello, new here, and need best recommandations.

Post by DocWaluigean »

Code: Select all

A=$00 X=$00 Y=$00
SP=$ff PC=$0600
NV-BDIZC
00110000

-
0600: a9 a2 8d 00 06 00 00 00 00 00 00 00 00 00 00 00 
0610: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0620: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0630: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0640: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0660: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0670: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

=====

run

=====

A=$00 X=$a2 Y=$00
SP=$ff PC=$0606
NV-BDIZC
10110000

-

0600: 00 a2 8d 00 06 00 00 00 00 00 00 00 00 00 00 00 
0610: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0620: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0630: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0640: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0660: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0670: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

=====

2nd run 

=====

A=$00 X=$00 Y=$00
SP=$ff PC=$0601
NV-BDIZC
00110000

-

0600: 00 a2 8d 00 06 00 00 00 00 00 00 00 00 00 00 00 
0610: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0620: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0630: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0640: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0660: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0670: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Hello, new here, and need best recommandations.

Post by Kasumi »

You only need the values immediately to the right of 0600. Not below. (i.e .not the 0610, 0620 etc columns which are all zero.)

Something tells me the steps weren't followed exactly. The PC would not be $0600 at any of the points where you were meant to note what A, X and Y were, so your first run's value seem to be after either reset or assemble, not after run or step.

Your second run's results are also not what I want to show. You need to start entirely over with the steps if any mistake is made during them.

Also important: You are getting the values from A, X and Y and the values to the right of $0600 at DIFFERENT times, this is why they are not together in the steps.

You have the state of A, X and Y (step 11) before the values to the right of 0600 (step 9)
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

Re: Hello, new here, and need best recommandations.

Post by DocWaluigean »

Kasumi wrote:You only need the values immediately to the right of 0600. Not below. (i.e .not the 0610, 0620 etc columns which are all zero.)

Something tells me the steps weren't followed exactly. The PC would not be $0600 at any of the points where you were meant to note what A, X and Y were, so your first run's value seem to be after either reset or assemble, not after run or step.

Your second run's results are also not what I want to show. You need to start entirely over with the steps if any mistake is made during them.

Also important: You are getting the values from A, X and Y and the values to the right of $0600 at DIFFERENT times, this is why they are not together in the steps.

You have the state of A, X and Y (step 11) before the values to the right of 0600 (step 9)
6. Click assemble

Code: Select all

0600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0610: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0620: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0630: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0640: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0660: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0670: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
Preprocessing ...
Indexing labels ...
Found 0 labels.
Assembling code ...
Code assembled successfully, 5 bytes.

A=$00 X=$00 Y=$00
SP=$ff PC=$0600
NV-BDIZC
00110000

=================

8. Click step.
9. Type out (in notepad or something, not easy6502) the values to the right of 0600: under the monitor checkbox. These are the bytes that the code (lda #$A2, sta $0600) became.


A=$a2 X=$00 Y=$00
SP=$ff PC=$0602
NV-BDIZC
10110000

Code: Select all

0600: a9 a2 8d 00 06 00 00 00 00 00 00 00 00 00 00 00 
0610: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0620: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0630: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0640: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0660: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0670: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
Preprocessing ...
Indexing labels ...
Found 0 labels.
Assembling code ...
Code assembled successfully, 5 bytes.

=====

10. Click run.

A=$00 X=$8d Y=$00
SP=$ff PC=$0604
NV-BDIZC
10110000

0600: a2 a2 8d 00 06 00 00 00 00 00 00 00 00 00 00 00
0610: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0620: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0630: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0640: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0660: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0670: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
06a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
06b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
06c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
06d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
06e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
06f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00


=====

13. Click reset.
14. Click run.


A=$a2 X=$00 Y=$00
SP=$ff PC=$0606
NV-BDIZC
10110000

Code: Select all

0600: a2 a2 8d 00 06 00 00 00 00 00 00 00 00 00 00 00 
0610: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0620: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0630: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0640: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0660: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0670: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
06f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
While re-reading it, I keep seeing missing info.

Instead of, "Below the box where you put the code, there's Monitor, Start, and Length. Type 0600 next to "Start: $"

It's "4. Type 0600 next to Start: $" .....

I'm really trying this time..
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Hello, new here, and need best recommandations.

Post by Kasumi »

It's true I could have been more specific about where to type 0600, but there is an image very shortly after that shows what it should look like when the steps are completed. Even if there were not, there is only one place with text that says "Start: $" and only one place you can type into next to it.

This has come up a bit, and I promise I'm not trying to pick on you. But sometimes the key to understanding something is very shortly after the part you don't understand. If you always stop immediately on the first confusing thing, you may end up stuck when the answer was actually really close. For things like steps, it's often helpful to read all the steps once before actually doing any of them.

We are still getting different results, which is also strange. I'm not going to have you do it again, but just out of curiosity what's your browser/OS?

Here's what I get for step 9:
0600: a9 a2 8d 00 06 00 00 00 00 00 00 00 00 00 00 00
I click run, and for step 11 I get:
A=$a2 X=$00 Y=$00
And for 12 I get:
0600: a2 a2 8d 00 06 00 00 00 00 00 00 00 00 00 00 00
I click reset, and run, and for step 15 I get:
A=$00 X=$a2 Y=$00

The only way I can get $8d into X is to reset and run multiple times instead of just once. But again, I won't have you do it again. These are my results. And the context for these results is the following. You assemble the program.

Code: Select all

lda #$A2
sta $0600
The program becomes these bytes starting at address $0600:

Code: Select all

0600: a9 a2 8d 00 06 00 00 00 00 00 00 00 00 00 00 00
Some of them should look familiar. For instance, the a2 is from the lda #$A2 in the code that was assembled. And the 00 and 06 are from the sta $0600 in the code that was assembled. (The bytes are "backwards", yes. That is simply how the 6502 CPU stores addresses.)
This means $a9 is the opcode for LDA #??.
Because lda #?? needs another byte for the value (which is its operand), this means the next byte will be used to fill in the ?s. The next byte is $A2. Altogether, that's lda #$A2. Exactly what was typed in.

The 6502 completes that instruction and is now at the next instruction. The byte following the last byte of the last instuction (which was $A2) is the opcode of the next instruction.
This means $8d is the opcode for STA $????.
Because sta $???? needs TWO bytes for the address (which is its operand), this means the next two bytes will be used to fill in the ?s. The next two bytes are $00 and $06. Since 6502 stores them flipped, if you flip them back you get $0600. Altogether, that's sta $0600. Exactly what was typed in.

After the program is run, you get these values in A, X and Y.

Code: Select all

A=$a2 X=$00 Y=$00
This should make sense, because there is an LDA #$A2 as the first instruction in the code. Now the bytes starting at address $0600 look like this:

Code: Select all

0600: a2 a2 8d 00 06 00 00 00 00 00 00 00 00 00 00 00
This should also make sense, because you stored $A2 to address $0600.

Then you click reset, which sends easy6502's CPU back to $0600. (Where the opcode for the first instruction should be.)
After the program is run, you get these values in A, X and Y:

Code: Select all

A=$00 X=$a2 Y=$00
What is different in A, X and Y from when the program was run the first time?
Thinking about the explanation above, why do you think it ends up different?
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

Re: Hello, new here, and need best recommandations.

Post by DocWaluigean »

I will try and read it fourth time...Again...

-Despite importance of this is very less, Program Counter allows you to to see where "you are now" on the location of the code.

-For HEX/Binary/number, it goes up by two. Because the opcode is stored into the assembly for the code to proceed, and the variables stored FOR/IN the opcode.

-For Address Code, it goes up by three. Because also the opcode is stored into the assembly for the code to proceed. BUT the Address has two separated numbers: high-byte and low-byte. the two separated numbers is two of three reasons for it to go up by three.

-Judging what you say about, "While writing and thinking about 6502 code, you basically never give any thought to the Program Counter. (Or at least, I don't!) It helps the CPU, but not you as the programmer that much." ---- This is less important for learning, but it's great to learn what this does. "I teach you about it now, so that you can better track the branching examples. Also, having learned it, you now know more than half of 6502 CPU's state!"

-BEQ/BNE is a new opcode I/you/we all will learn. It's a Lever-On-or-Off.

-BEQ: If the Zero Flag is turned on, while the code-line is onto BEQ, it will perform specific code upon it. OR it will go to the label of the code before returning here.
-If the Zero Flag is turned off, while the code-line is onto BEQ, it will be ignored and proceed like comment code.

-BNE is the polar opposite of BEQ. If Zero flag is OFF, while the code line is onto BNE, it will perform specific code, or go to label before returning here.
-If the Zero Flag is turned ON, while code line is onto BEQ, it will be ignored and proceed like comment code.

-Label is used to make re-using the code much faster and easier. And save a lot of spaces.

-----

? - Program Counter counts how many bytes you wasted. Potentially show you if you are wasting any memory to fit into NES or Mapper.

? - The High-Byte is $12. The Low-Byte is $34. The result is $1234.

X - The High-Byte and Low-Byte is not understood at this time for me.

========

I could see stern talk earlier. So I'm sorry if I was any rude to you. The Branching, at this time, is the hardest new lesson I had to see.

The best communication is to best understand each other.
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Hello, new here, and need best recommandations.

Post by Kasumi »

What you've written about beq/bne is still not quite correct. Ignore the branching post.

Read this post: https://forums.nesdev.com/viewtopic.php ... 45#p225445
And answer the questions at the bottom. Or ask questions about it.

Edit for the questions:
-Despite importance of this is very less, Program Counter allows you to to see where "you are now" on the location of the code.
This is correct.
-BEQ: If the Zero Flag is turned on, while the code-line is onto BEQ, it will perform specific code upon it. OR it will go to the label of the code before returning here.
-If the Zero Flag is turned off, while the code-line is onto BEQ, it will be ignored and proceed like comment code.
If the zero flag is turned on, while the code is on the line of the beq, it will go to the label next to it. There is no or. It also won't return.
If the zero flag is turned off, while the code is on the line of the beq, it will do nothing and proceed.

If the zero flag is turned on, it will do exactly one thing. If the zero flag is turned off, it will do exactly one thing. It can do one thing OR the other because the zero flag can be turned on OR turned off.

But given a turned on zero flag, it will always do one thing. And given a turned off zero flag, it will always do one thing.
-Label is used to make re-using the code much faster and easier. And save a lot of spaces.
It makes it easier to read/write code because you don't have to memorize numbered addresses, but it saves no space at all.
? - Program Counter counts how many bytes you wasted. Potentially show you if you are wasting any memory to fit into NES or Mapper.
No. Your other explanation was right. The explanation in the post was "The PC is the Program Counter. It keeps track of the address of the next instruction the CPU will execute." I'm not sure of a better way to make it clear.

The 6502 is very simple. I get the impression you've got it in your head that it can't be that simple, so you're trying to introduce new concepts to it. Basically everything related to 6502 does exactly one simple thing, keeps track of exactly one simple thing, or chooses between two simple things based on the state of one simple thing.
? - The High-Byte is $12. The Low-Byte is $34. The result is $1234.
This is correct. Given $1234, the high byte is $12 and the low byte is $34. The 6502 would store them "backwards" like $34 $12, but they still represent $1234.
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

Re: Hello, new here, and need best recommandations.

Post by DocWaluigean »

What is different in A, X and Y from when the program was run the first time?
Thinking about the explanation above, why do you think it ends up different?


My browser is Firefox atm.

Upon first running program:

A=$a2 X=$00 Y=$00
SP=$ff PC=$0606
NV-BDIZC
10110000

2nd time:

A=$00 X=$a2 Y=$00
SP=$ff PC=$0606
NV-BDIZC
10110000

3rd time [Press run 2 times]:

A=$00 X=$8d Y=$00
SP=$ff PC=$0604
NV-BDIZC
10110000

---
..........................I don't ever want this to be Bunnyboy nerdy nights all over again...............

The difference in running second time, is that upon reset, the tiny pieces of memories inside the CPU is still kept, and goes different ways because the memory from first run was partially kept, and then second memory..
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Hello, new here, and need best recommandations.

Post by Kasumi »

I'll ask a more specific question.

Why does this specific code do something different each time you run it? It can't be just that memory is kept around, because no other code you've written or tried would get a different result after running it again. What is it about this code that makes it get a different result?
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

Re: Hello, new here, and need best recommandations.

Post by DocWaluigean »

Kasumi wrote:I'll ask a more specific question.

Why does this specific code do something different each time you run it? It can't be just that memory is kept around, because no other code you've written or tried would get a different result after running it again. What is it about this code that makes it get a different result?
:cry: :roll:

When you run the first time, the code is stored into Address $0600.

0600: a2 a2 8d 00 06 00 00 00 00 00 00 00 00 00 00 00

When you run the second time, while this code above is in there, it will give the same value, but in X instead of A.

Is this lesson well thought out for difficult thinking or is it trying to "prove me if I have what it takes to be part of NESDev or kick me out" test???
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

Re: Hello, new here, and need best recommandations.

Post by DocWaluigean »

Is it because according to DISASSEMBLE on first time:

Address Hexdump Dissassembly
-------------------------------
$0600 a2 a2 LDX #$a2
$0602 8d 00 06 STA $0600

and on the second time:

Address Hexdump Dissassembly
-------------------------------
$0600 00 BRK
$0601 a2 8d LDX #$8d
$0603 00 BRK
$0604 06 00 ASL $00

There is an extra hidden code placed called BRK [Break Opcode], Load Data X, then ASL???

The BRK is a hidden opcode that appear out of nowhere when you reset the code?
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Hello, new here, and need best recommandations.

Post by Kasumi »

Bingo! Or, more or less bingo. That BRK doesn't come from nowhere, though.

So the first time you run it, it's actually an LDA #$?? opcode, not LDX #$??. It starts with
$A9 $A2. LDA #$A2
And this is why at the end A has $A2 in it.

Then it stores that to $A2 to $0600. And, remember, that's where the first instruction is! So we overwrite the opcode for LDA #$?? with the opcode for LDX #$??. (Which is $A2).

When we reset, it means the PC will start again at the instruction at $0600. But it just got changed!

So the second time you run it, it starts with:
$A2 $A2. LDX #$A2.
And this is why at the end of second run, X (instead of A) has $A2 in it.

But there's still an sta $0600 rather than stx $0600. On easy6502, A starts with $00 in it.

So once again, the first instruction gets changed to a different one. ($00). And when you reset, you get BRK. That's the part you noticed.

This was a long way to get to this point, I admit. But does this make sense? The 6502 can see the addresses from $0000 to $FFFF. It can attempt to read from, attempt to write to, or attempt to execute (run the opcode at) any of those addresses. You have learned 3 ways to attempt a read from an address. lda $????, ldx $???? and ldy $????. And you have learned 3 ways to attempt to write to an address. sta $????, stx $????, sty $????. And, if you understand the above, you understand how an address is "executed". That is, how it looks up the opcode at that address, and does the action associated with that opcode then arrives at (sets the PC to) the address of the next instruction.

It does not care what "type" of address it is in any of those cases. It doesn't care if it's RAM. It doesn't care if it's a register. It doesn't check if the write will even have an effect. (It will always ATTEMPT to write, but the value that was attempted to be written is not necessarily stored, depending on the address.) In this example, you wrote to an address "meant for" code, but the 6502 doesn't care what an address is"meant for". You can also read addresses "meant for" code, and you can execute addresses "meant for" variables. The 6502 does not care about what any given address is "meant for".

Does any of that not make sense? It is vitally important that especially the last two paragraphs make sense.

Edit: It was not meant to be purposefully difficult, though I do realize it IS/WAS difficult. I was running out of ways to make addresses clear which I still believe to be a large part of your confusion. The 6502 considers all addresses to be the same type of thing (with arguably two exceptions we'll cover later), regardless of whether its reading from, or writing to, or executing that address. They're different for the programmer, that's why a memory map exists. For the programmer. The 6502 itself is basically unconcerned by the memory map.

If we're all clear here, I'll test your knowledge of the PC/labels. And then we'll get back to branching.
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

Re: Hello, new here, and need best recommandations.

Post by DocWaluigean »

Kasumi wrote:Bingo! Or, more or less bingo. That BRK doesn't come from nowhere, though.

So the first time you run it, it's actually an LDA #$?? opcode, not LDX #$??. It starts with
$A9 $A2. LDA #$A2
And this is why at the end A has $A2 in it.

Then it stores that to $A2 to $0600. And, remember, that's where the first instruction is! So we overwrite the opcode for LDA #$?? with the opcode for LDX #$??. (Which is $A2).

When we reset, it means the PC will start again at the instruction at $0600. But it just got changed!

So the second time you run it, it starts with:
$A2 $A2. LDX #$A2.
And this is why at the end of second run, X (instead of A) has $A2 in it.

But there's still an sta $0600 rather than stx $0600. On easy6502, A starts with $00 in it.

So once again, the first instruction gets changed to a different one. ($00). And when you reset, you get BRK. That's the part you noticed.

This was a long way to get to this point, I admit. But does this make sense? The 6502 can see the addresses from $0000 to $FFFF. It can attempt to read from, attempt to write to, or attempt to execute (run the opcode at) any of those addresses. You have learned 3 ways to attempt a read from an address. lda $????, ldx $???? and ldy $????. And you have learned 3 ways to attempt to write to an address. sta $????, stx $????, sty $????. And, if you understand the above, you understand how an address is "executed". That is, how it looks up the opcode at that address, and does the action associated with that opcode then arrives at (sets the PC to) the address of the next instruction.

It does not care what "type" of address it is in any of those cases. It doesn't care if it's RAM. It doesn't care if it's a register. It doesn't check if the write will even have an effect. (It will always ATTEMPT to write, but the value that was attempted to be written is not necessarily stored, depending on the address.) In this example, you wrote to an address "meant for" code, but the 6502 doesn't care what an address is"meant for". You can also read addresses "meant for" code, and you can execute addresses "meant for" variables. The 6502 does not care about what any given address is "meant for".

Does any of that not make sense? It is vitally important that especially the last two paragraphs make sense.

Edit: It was not meant to be purposefully difficult, though I do realize it IS/WAS difficult. I was running out of ways to make addresses clear which I still believe to be a large part of your confusion. The 6502 considers all addresses to be the same type of thing (with arguably two exceptions we'll cover later), regardless of whether its reading from, or writing to, or executing that address. They're different for the programmer, that's why a memory map exists. For the programmer. The 6502 itself is basically unconcerned by the memory map.

If we're all clear here, I'll test your knowledge of the PC/labels. And then we'll get back to branching.
This information is literally illogical to me, I'm starting to feel really upset or really mad at myself since the Easy6502/Nerdy Night issues again..and I do not qualify to complain about this...
So the first time you run it, it's actually an LDA #$?? opcode, not LDX #$??. It starts with
$A9 $A2. LDA #$A2
And this is why at the end A has $A2 in it.
Okay, I understand that. Needs better wording on the last sentences though. "At the end, [the A Register] has $A2 in it."
Then it stores that to $A2 to $0600. And, remember, that's where the first instruction is! So we overwrite the opcode for LDA #$?? with the opcode for LDX #$??. (Which is $A2).

When we reset, it means the PC will start again at the instruction at $0600. But it just got changed!
What do you mean? or why? You didn't told me we had to re-write or replace LDA with LDX.
So the second time you run it, it starts with:
$A2 $A2. LDX #$A2.
And this is why at the end of second run, X (instead of A) has $A2 in it.

But there's still an sta $0600 rather than stx $0600. On easy6502, A starts with $00 in it.

So once again, the first instruction gets changed to a different one. ($00). And when you reset, you get BRK. That's the part you noticed.
There is a LOT of questions I'm literally missing. I don't see LDA turned into LDX alongside with BRK. Or you never told me I need to disassemble...
This was a long way to get to this point, I admit. But does this make sense? The 6502 can see the addresses from $0000 to $FFFF. It can attempt to read from, attempt to write to, or attempt to execute (run the opcode at) any of those addresses. You have learned 3 ways to attempt a read from an address. lda $????, ldx $???? and ldy $????. And you have learned 3 ways to attempt to write to an address. sta $????, stx $????, sty $????. And, if you understand the above, you understand how an address is "executed". That is, how it looks up the opcode at that address, and does the action associated with that opcode then arrives at (sets the PC to) the address of the next instruction.
No, it does not. Okay, $0000 - FFFF, I understand. and then read, write to, or excecute. Okay LDA/X/Y. But I'm still not understanding to your certain questions.

Edit: It was not meant to be purposefully difficult, though I do realize it IS/WAS difficult. I was running out of ways to make addresses clear which I still believe to be a large part of your confusion. The 6502 considers all addresses to be the same type of thing (with arguably two exceptions we'll cover later), regardless of whether its reading from, or writing to, or executing that address. They're different for the programmer, that's why a memory map exists. For the programmer. The 6502 itself is basically unconcerned by the memory map.

If we're all clear here, I'll test your knowledge of the PC/labels. And then we'll get back to branching.
Let's try do a drawing of examples of how Branching works. So I can get the idea if we're on the same page. I need one-by-one step for it...

Edit: I don't want to put emotions in here. But I am NOT and NEVER giving up. I am never going to wait another 5 years to learn the same program that I struggled 5 years ago just for confusion about A X Y Register.
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Hello, new here, and need best recommandations.

Post by Kasumi »

What do you mean? or why? You didn't told me we had to re-write or replace LDA with LDX.
I didn't tell you you had to replace LDA with LDX because you didn't have to do that. The code did it to itself.

I told you that in easy6502, your code starts at address $0600. This means the first opcode of the first instruction is at $0600. The code I gave you writes to $0600 which changes what the first instruction is. Does that make sense?
Or you never told me I need to disassemble...
You didn't need to disassemble, but I'm very glad you found that resource without me directing you to it. What I was hoping for is that you'd make the connection that since your code starts at $0600 and the program writes to $0600, that that might change the code. I left a bunch of hints about it in the post.

Anyway. Does it make sense now? Even if not, I guess I'm cool with it so long as you understand about how 6502 deals with addresses. Not every example is gonna land. If you wanna get back to branching, give me the address of all of these instructions, and tell me how you found those addresses. Edit: I guess I should say, assume the first one starts at $0600.

Code: Select all

lda #$00
sta $0201
tay
lda $0200
Knowing the purpose of the PC should help.
Post Reply