Hello, I'm back, still need assistences

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

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

Hello, I'm back, still need assistences

Post by DocWaluigean » Mon Jun 08, 2020 9:25 pm

*****FOR EARLY OF THIS THREAD: http://forums.nesdev.com/viewtopic.php?t=17454 *****

Hey. It's me from 2 years ago and I'm motivated to do NES stuff.

I want to apologize for not being here since the 2 years old thread. I got motivated to continue with the NES [and SNES if possible] programming, but first I need assistance in keeping the motivated feeling.

So what helped me start motivated was when I asked a friend if he want to play NES multiplayer and he said no, which is alright for me. So I downloaded MESEN, the best NES emulator on Earth, and played some homebrew games about it, and I'm starting to finally get motivated to get back into it. The only problem about it is I don't know when I'm going to lose motivation to do more NES stuff.

When I see certain games through PPU Viewer, I keep seeing potentials about games as good as Mario Adventure, Kirby's Adventure, Super Mario Bros. 3 Mix, and even more.

I also played the SNES games called VIP Mario 5, which has a very much beautiful art style, along with Janked Up Mario Party! and, hilariously, "Mario's Mystery Meat." Reason I put SNES in was because I heard SNES uses more than exact the same programming languages of NES!

But I need help in keeping motivated to learn program on NES and/or SNES if it means I get to do those.

I got a program called GameMaker Studio 2, but I still struggle in learning to make games, I have to use tutorials with those. What motivations can I find in learning to program NES/SNES right now?

https://www.youtube.com/watch?v=YBiCXcfZuoQ
https://www.youtube.com/watch?v=WytEp9tSYqI

The two videos I saw now shows how much love and effort were made into NES, and to certain people it's a waste of time when GameMaker Studio 2 and other video programs is better. Which I don't understand how did the creator have so much love for the NES homebrews. I need help maintaining and keeping the motivations, and better yet, grow motivations to do more NES homebrews.

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

Re: Hello, I'm back, still need assistences

Post by DocWaluigean » Mon Jun 08, 2020 9:29 pm

Although I tend to forgot about it, thankfully I wrote it all down:

-------------------------------------------------------
The limitations of 6502 CPU is 255. The HEX version is FF. The Binary version is 1111 1111 [or 11111111. Space in the middle helps a little?]

The number system in this style is wheels. It means if you go over 255, it will go back to 0.

6502 } 255 + 2 = 001.

It's the same thing in backwards. If you go below 0, it will go back to 255.

6502 } 3 - 5 = 254.

... 253, 254, 255, 0, 1, 2, ...
... 3, 2, 1, 0, 255, 254, 253, ...

Works either way.

The code line is always read from TOP to BOTTOM.

+++++++++++++++++++++++

Any number / digit / variable / value = N
The "lever", or on [1] and off [0] = B



HEX number written >>> #$NN

Normal Number / Immediate Decimals number written >>> #NN

Binary number written >>> %BBBBBBBB


Immediate Decimals Minimum Written = #N
Maximum usages Maximum Written = #NNN

-------------------------------------

The Address [The location, destination, and objective of the code] >>> $NNNN

$NN = $00NN

$NNN = $0NNN

$N = 000N

$NNNN = $NNNN

The zeros is not used, while N is.

++++++++++++++++++++++++++++

A label is a type of directive that makes it easier to go "back in time", or go directly to the label that's in the future OR the past of the codings using JMP/BEQ/BNE.

======EXAMPLES=====

cupcakes:
LDA $03

pancakes:
LDA $05

toilet:
LDA $FF
STA $FFFF


--

Think of something like a magical teleportation pod that said "@GOTO" with the name of the label in front of it. Except a little different.


***
A comment is a type of extremely simple code used to organize things. No matter how much you write in this, it will never be operated nor used inside the comment.

It's always a comment when it's after the [ ; ] symbol.

===EXAMPLES===

LDA $01 ; Yo man. Wanna go to a stag party?

LDX $02 ; Sounds dope, bruh! I hope I can bring some grasses in!

LDY $03 ; I happen to be a vegetarian! I'm so offended you mention grasses; my Dad was a tree trunk!

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

All the hilarious comments above will never be implemented into the code. So write whatever you want.

--------------------

Register is simple number carrying system with fancy name that holds number, awaiting for commands to be replaced, or to placed.

The numbers never disappeared once assigned, or given a number, regardless. You always have to replace it to change the number/value/digit/variable.

With this, you can carry up to three numbers, maximum of 255 for each.

-----------

The limitations for each is:

A = You cannot increment, or fancy word of adding one, to the number stored into Register A directly. [INC/INX/INY] You have to do the INC to the Address that got the number from Register A to do that.

X/Y = You cannot transfer numbers from Register X and Y together. [TAX, TAY]
You can only transfer numbers from Y to A, and from X to A. But never X to Y and Y to X back again.

++++++++++++

LDA / LDX / LDY - "Load Data into A/X/Y Register"

You put any number into the register A, X, or Y.

===EXAMPLE1===

LDA #$0F

STA $0001

---

A = 15 [The F number for HEX.]

"Put_Number_From_A_Into" Address-0001

The Address $0001 is now carrying number 15.

===EXAMPLE2===

LDX #13

STA $0030

---

X = 13

Address = 0030

The Address $0030 is now carrying number 13.

===EXAMPLE3===

LDY %#00001010

STA $13

---

Y = 10 [The number from Binary]

Address = 0013.

The Address $0013 is now carrying number 10.

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

TAX / TAY = Transfer Register A to X. or. Transfer Register A to Y.

TXA / TXY = Same thing as above, but other way.

Despite the name, the TXA/TXY/TAX/TAY copies the number from one register to another. It never loses its number, just copy.

If there is no program written in A/X/Y, nor any number placed into any Register, than it will copy to targeted Register as zero.


===EXAMPLE1===

LDA #$10

TAX

---

Register A is carrying number 16, or 10 in HEX number.

Register A has "transfer", or COPY, number 15 into Register X.

Right now, Register A and Register X has number 15 ready to be placed or replaced.

===EXAMPLE 2===

TAY

LDX #18

LDA #$FF

---

Register A has no number inside it, so it always has zero as default. As such, Register Y is now carrying number 0.

Register X is now carrying number 18.

Register A is now carrying 255 [FF in HEX number, the maximum for 8-bit.]

For this code:

A = 255
X = 18
Y = 0

===EXAMPLE 3===

LDA $01

TAX

TAY

LDY $05

TYA

---


Register A is now carrying value inside number 1, the Address.

Register A is "copy and paste" value from number 1, the address, for Register X ::: X is now carrying value FROM number 1.

Register A is also "copy and paste" number 1 for Register Y. ::: Y is also carrying number 1.

Register Y is being given number 5 to carry [Carrying the value inside Address 5]. Because Y already has number 1, it get's replaced and now it's number 5. ::: Y is now carrying number 5.

Register Y is "copying and paste" [TYA] number 5 for A.

A was carrying number 1, but as A is holding number 5 now, it replaces number 1 with number 5. ::: A is now carrying number 5 instead.

As a result from this ----

A = 5

X = 1

Y = 5





--------------------------
--------------------------
--------------------------



Increment - The smarty word for addition by one.

Decrement - The smarty word for subtraction from one.


INC / INX / INY = Increment, or add one, to the Address / Register X / Register Y.


***NOTICE***

For other programs, you could do INC STEP 2, INC STEP 5, to increment by addition of 2, or 5, or any number. Same thing with decrement.
But for 6502 Assembly, you can only do increment / decrement by 1.

************

===EXAMPLE1===

LDX #20

INX

---

X is now carrying number 20.

Increment X. Meaning you add by 1 to the X Register.

X is now carrying number 21.

===EXAMPLE2===

LDA #$0D

STA $0010

INC $0010

---

Put number 13 [D in HEX number] into Register A.

Store number 13 from Register A into Address $0010

Increment Address $0010 by one. It does NOT mean $0011! It only increments/decrements INSIDE the Address that the Register stored!

Address $0010 is now carrying 14.

===EXAMPLE3===

LDY #02

DEY

DEY

DEY

DEY

STY $1000

---

Put number 2 into Register Y.

Decrement Register Y FOUR times according to the code.

2 - 1 = 1

1 - 1 = 0

0 - 1 = 255

255 - 1 = 254

[The math is wrong, but it's right ONLY in 6502 CPU programming!]

Store number 254 from Register Y into Address $1000.

Now Address $1000 is holding number 254.






--------------------------
--------------------------
--------------------------






JMP = Jump.

This code will jump to any labels.

VERY simple, but can also be effective. An empty label will also work.

===EXAMPLES===

LDX $01

letsdoitagain:

INX

JMP letsdoitagain

---

Register X is now carrying number 1.

The label "letsdoitagain" is made.

Increment, or add 1, to Register X. Now carrying 2.

JMMP, [Jump] to the label letsdoitagain. Or in other words, "Go directly to the label named, "letsdoitagain" !!!"

You are now on the label "letsdoitagain".

Increment Register X, now carrying 3.

Jump to, or go to, the label "letsdoitagain".

IT NEVER ENDS!!!!!!!!
Last edited by DocWaluigean on Mon Jun 08, 2020 10:37 pm, edited 1 time in total.

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

Re: Hello, I'm back, still need assistences

Post by DocWaluigean » Mon Jun 08, 2020 9:56 pm

So I need to look back past on where I left off or have to start over in learning opcodes.
But right now, I want to show you that in some way, I could repay kindness with my artworks that I made. I could be helpful in designing any tiles or sprites for any NES makers.
Platform-Dummy 1.png
Platform-Dummy 1.png (2.74 KiB) Viewed 1956 times
My tile platforms.png
My tile platforms.png (8.45 KiB) Viewed 1956 times

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

Re: Hello, I'm back, still need assistences

Post by DocWaluigean » Mon Jun 08, 2020 10:09 pm

And this one, I made using GameMaker Studio 2, I made the BreakOut with [possibly?] NES sprites and NES sounds. Except the winning theme, that is not NES like. Space to start, R to change directions for cost of 1/3 score, left goes left and right goes right.
DocWaluigean's Breakout.zip
(2.56 MiB) Downloaded 38 times
So with this, I guess it kind of proves that I understand the basics of typical programming?

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

Re: Hello, I'm back, still need assistences

Post by DocWaluigean » Mon Jun 08, 2020 10:49 pm

So here are the opcodes I think I understand:

Register: An easy way of saying "A machine whose job is to carry or create number for next opcodes that needs it."
A X and Y stuff

---

LDA Load numbers into Register A.
LDX Load numbers into Register X.
LDY Load numbers into Register Y.
TAX Transfer numbers from Register A into Register X.
TAY Transfer numbers from Register A into Register Y.
TXA Transfer numbers from Register X into Register A.
TXY Transfer numbers from Register X into Register Y.

INC Increment Register A. [Fancy way of "increasing numbers by ONE inside Register A. Only one, not zero nor higher than one.]
INX Increment Register X.
INY Increment Register Y.
DEC Decrement Register A. [Another fancy way of saying "decrease numbers by ONE inside Register A. Not zero, not two. Only ONE.]
DEX Decrement Register X.
DEY Decrement Register Y.

JMP Jump to... [Jump to the name of the label or address specified. Pretty much same as, "GOTO" command.]

Re-read the previous post from 2 years ago. I'm guessing "CLC" is used to "Erase all the number the Register A, X, and Y is carrying."?

User avatar
Gilbert
Posts: 399
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong
Contact:

Re: Hello, I'm back, still need assistences

Post by Gilbert » Tue Jun 09, 2020 2:03 am

DocWaluigean wrote:
Mon Jun 08, 2020 10:49 pm
Re-read the previous post from 2 years ago. I'm guessing "CLC" is used to "Erase all the number the Register A, X, and Y is carrying."?
No. The CLC (Clear Carry) clears the Carry flag. The "Carry" here means the number carried to the next place when doing arithmetic operations such as addition and multiplication.
For example, in denary arithmetic used in daily life, say we have 5 + 8 = 13, where the addition of two one digit numbers yields a two digit number. In this case, it is not enough to express the result in one single digit, so a '1' is carried over to the tens place. This '1' is called a carry.
In a 6502 CPU, apart from the registers A, X and Y, there are flags (each either have the value of 0 or 1, or for it to be easier to understand, either 'off' or 'on', or 'no' or 'yes') to record the state after some operations.
For example, when we add two 8-bit numbers together with ADC, if the result is too large to be expressed with just 8-bit, the carry flag becomes 1/on/yes. If we further add two numbers with ADC, say 1 + 2, the result will become 4, not 3, as there is a '1' carried to this addition. This is useful for doing say 16-bit arithmetic with a 8-bit CPU.

Sometimes you just do a fresh addition and do not want to have any carry added into the result. In this case you use CLC to clear (i.e. turn this flag 0) the carry flag before the addition to ensure your calculation will not be affected by some previous operations that may change the carry flag.

There is also a SEC command to SEt the Carry flag to 1 (this is most useful in doing subtraction).

There are other flags in the CPU that could be affected by different operations, such as Overflow, Negative, etc. and these flags are important in branching operations (think operations like "if (a < 0) then blah blah" in other programming languages) so you need to read more about them if you seriously want to write assembly codes.

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

Re: Hello, I'm back, still need assistences

Post by DocWaluigean » Tue Jun 09, 2020 1:02 pm

Gilbert wrote:
Tue Jun 09, 2020 2:03 am
DocWaluigean wrote:
Mon Jun 08, 2020 10:49 pm
Re-read the previous post from 2 years ago. I'm guessing "CLC" is used to "Erase all the number the Register A, X, and Y is carrying."?
No. The CLC (Clear Carry) clears the Carry flag. The "Carry" here means the number carried to the next place when doing arithmetic operations such as addition and multiplication.
For example, in denary arithmetic used in daily life, say we have 5 + 8 = 13, where the addition of two one digit numbers yields a two digit number. In this case, it is not enough to express the result in one single digit, so a '1' is carried over to the tens place. This '1' is called a carry.
In a 6502 CPU, apart from the registers A, X and Y, there are flags (each either have the value of 0 or 1, or for it to be easier to understand, either 'off' or 'on', or 'no' or 'yes') to record the state after some operations.
For example, when we add two 8-bit numbers together with ADC, if the result is too large to be expressed with just 8-bit, the carry flag becomes 1/on/yes. If we further add two numbers with ADC, say 1 + 2, the result will become 4, not 3, as there is a '1' carried to this addition. This is useful for doing say 16-bit arithmetic with a 8-bit CPU.

Sometimes you just do a fresh addition and do not want to have any carry added into the result. In this case you use CLC to clear (i.e. turn this flag 0) the carry flag before the addition to ensure your calculation will not be affected by some previous operations that may change the carry flag.

There is also a SEC command to SEt the Carry flag to 1 (this is most useful in doing subtraction).

There are other flags in the CPU that could be affected by different operations, such as Overflow, Negative, etc. and these flags are important in branching operations (think operations like "if (a < 0) then blah blah" in other programming languages) so you need to read more about them if you seriously want to write assembly codes.
Can you use this as an example? I don't understand about it.

User avatar
tokumaru
Posts: 11866
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Hello, I'm back, still need assistences

Post by tokumaru » Tue Jun 09, 2020 3:41 pm

When you're doing an addition on paper, say, 24 + 38, you do it like this:

Code: Select all

 24
+38
---

4 + 8 equals 12, which doesn't fit in one digit. What do you do? You carry one over to the next place:

Code: Select all

 1
 24
+38
---
  2
Then you add the 3 digits in the second column to find the final digit in the ten's place:

Code: Select all

 1
 24
+38
---
 62
We only have 10 unique symbols to represent numbers (digits 0 to 9), but that doesn't mean we have to stop counting just because we're out of digits: we can simply carry one to the next place and keep going.

With the 6502 it's the same thing. Since it's an 8-bit CPU, it only knows 256 different "symbols" (0 to 255), but that doesn't mean we need to stop counting at 255: we can carry one to the next byte and keep going. However, since each 6502 instruction only handles one byte at a time, it needs a temporary place to hold that "1" that's bring carried over, so that a future instruction can add it to the bytes of the next "column". This temporary place is the carry flag.

Some CPUs have an "ADD" instruction in addition to the "ADC", but the 6502 only has "ADC", so you need the "CLC" to make sure that nothing from a previous operation is being carried over to the current one whenever you start a new addition.

Subtractions work in reverse: the carry flag actually works as a "borrow" value, that you put in place (using "SEC") just in case the subtraction that follows needs to borrow it. For example, 11 - 23. 23 is larger than 11, so you shouldn't be able to do that subtraction, but since the carry is set, the CPU acts as if you were subtracting 23 from 267 (just like a one in the next place is worth 10 in decimal, a one in the next byte is worth 256, and 256 + 11 is 267), so it does the subtraction and you get 244 as the result. But since you did use the carry bit, it's now clear, and that will cause the next subtraction (i.e. the one that handles the next column) to subtract one extra unit, accounting for that one that you had to borrow before.

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

Re: Hello, I'm back, still need assistences

Post by DocWaluigean » Tue Jun 09, 2020 6:22 pm

tokumaru wrote:
Tue Jun 09, 2020 3:41 pm
When you're doing an addition on paper, say, 24 + 38, you do it like this:

Code: Select all

 24
+38
---

4 + 8 equals 12, which doesn't fit in one digit. What do you do? You carry one over to the next place:

Code: Select all

 1
 24
+38
---
  2
Then you add the 3 digits in the second column to find the final digit in the ten's place:

Code: Select all

 1
 24
+38
---
 62
We only have 10 unique symbols to represent numbers (digits 0 to 9), but that doesn't mean we have to stop counting just because we're out of digits: we can simply carry one to the next place and keep going.

With the 6502 it's the same thing. Since it's an 8-bit CPU, it only knows 256 different "symbols" (0 to 255), but that doesn't mean we need to stop counting at 255: we can carry one to the next byte and keep going. However, since each 6502 instruction only handles one byte at a time, it needs a temporary place to hold that "1" that's bring carried over, so that a future instruction can add it to the bytes of the next "column". This temporary place is the carry flag.

Some CPUs have an "ADD" instruction in addition to the "ADC", but the 6502 only has "ADC", so you need the "CLC" to make sure that nothing from a previous operation is being carried over to the current one whenever you start a new addition.

Subtractions work in reverse: the carry flag actually works as a "borrow" value, that you put in place (using "SEC") just in case the subtraction that follows needs to borrow it. For example, 11 - 23. 23 is larger than 11, so you shouldn't be able to do that subtraction, but since the carry is set, the CPU acts as if you were subtracting 23 from 267 (just like a one in the next place is worth 10 in decimal, a one in the next byte is worth 256, and 256 + 11 is 267), so it does the subtraction and you get 244 as the result. But since you did use the carry bit, it's now clear, and that will cause the next subtraction (i.e. the one that handles the next column) to subtract one extra unit, accounting for that one that you had to borrow before.
This sounds very amazing, with the "Carry the number" as a tool for programming. But I don't see how it's used in practice yet.

LDA #0010

ADC #0090

STA #0100...

This is wrong, but I'm trying to figure it out.

User avatar
tokumaru
Posts: 11866
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Hello, I'm back, still need assistences

Post by tokumaru » Tue Jun 09, 2020 6:48 pm

Code: Select all

  ;prevent previous operations from interfering with this one
  clc
  
  ;add two numbers
  lda #$82
  adc #$95
  
  ;$82 + $95 = $117, which is more than $ff, the maximum value a byte can hold, so this addition will set the carry flag
  
  ;the accumulator contains the lower 8 bits of the result ($17), which we can save
  sta result
  
  ;if we're working with 16-bit numbers, we can keep going and add the next "column" of bytes
  lda #$20
  adc #$4b
  
  ;$20 + $4b = $6b, but since the carry flag is set, it's also added to the accumulator, resulting in $6c
  ;since $6c fits in a byte just fine, the carry flag is now clear
  
  ;save this new result right next to the previous one in memory
  sta result+1
With this we have successfully added $2082 to $4b95, achieving the result $6c17. In decimal, that's 8322 + 19349 = 27671. With this simple workaround, we can make an 8-bit CPU process 16-bit numbers.

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

Re: Hello, I'm back, still need assistences

Post by DocWaluigean » Tue Jun 09, 2020 9:43 pm

tokumaru wrote:
Tue Jun 09, 2020 6:48 pm

Code: Select all

  ;prevent previous operations from interfering with this one
  clc
  
  ;add two numbers
  lda #$82
  adc #$95
  
  ;$82 + $95 = $117, which is more than $ff, the maximum value a byte can hold, so this addition will set the carry flag
  
  ;the accumulator contains the lower 8 bits of the result ($17), which we can save
  sta result
  
  ;if we're working with 16-bit numbers, we can keep going and add the next "column" of bytes
  lda #$20
  adc #$4b
  
  ;$20 + $4b = $6b, but since the carry flag is set, it's also added to the accumulator, resulting in $6c
  ;since $6c fits in a byte just fine, the carry flag is now clear
  
  ;save this new result right next to the previous one in memory
  sta result+1
With this we have successfully added $2082 to $4b95, achieving the result $6c17. In decimal, that's 8322 + 19349 = 27671. With this simple workaround, we can make an 8-bit CPU process 16-bit numbers.

So you're saying CLC is an opcode which converts the next 2 addresses from typical numbers as Address in ASM into number additions of arithmetic ?

Like

----

CLC

LDA #20

ADC #44

STA N64

This would result in number 64 stored into the Address that's named, or "labelled" N64?

This is new about ADC. "ADd with Carry"?... I need more examples. Can you use smaller numbers please?

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

Re: Hello, I'm back, still need assistences

Post by DocWaluigean » Tue Jun 09, 2020 9:52 pm

Re-Reading Tokumaru:

-ADC adds new numbers OUT OF THIN AIR into ONE PREVIOUS LINE OF CODE [?]

STA Result.... ? So it's now $117 into the Address labelled Result, which is standardly impossible for NES to handle this code normally?...

LDA [HEX] #$20 = Create number 32 [#$20] out of thin air.

ADC #$4B = ADD the HEX number 4B directly into the previous code, which is LDA #$20. The A Register is now carrying #$6B.

" but since the carry flag is set, it's also added to the accumulator, resulting in $6c" This, what do you mean.
"since $6c fits in a byte just fine, the carry flag is now clear" ALSO this, what do you mean.

Is the Carry Flag just a simple "Zero and One" only? Or...Is it ALWAYS carrying number 1 in MOST RECENT USING code if the Carry Flag got "turn on"?

User avatar
tokumaru
Posts: 11866
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Hello, I'm back, still need assistences

Post by tokumaru » Tue Jun 09, 2020 10:14 pm

DocWaluigean wrote:
Tue Jun 09, 2020 9:52 pm
-ADC adds new numbers OUT OF THIN AIR into ONE PREVIOUS LINE OF CODE [?]
Yes, I picked numbers out of thin air just to demonstrate how ADC and the carry flag work. In a real program it would be pointless to add constant numbers together like that.
STA Result.... ? So it's now $117 into the Address labelled Result
No, only $17 got stored into the address labeled result. The top $1 went to the carry flag.
" but since the carry flag is set, it's also added to the accumulator, resulting in $6c" This, what do you mean.
"ADC" means "add with carry". This instruction always adds two numbers, PLUs the carry flag. Since the carry flag was one, the final result was $6c ($20 + $4b + 1) instead of $6b.
"since $6c fits in a byte just fine, the carry flag is now clear" ALSO this, what do you mean.
The result of this addition didn't cross the $ff boundary ($6c is less than 256!), so the carry was not set after this operation.
Is the Carry Flag just a simple "Zero and One" only?
Yes. By definition, flags are either set or clear (i.e. 0 or 1). That's OK though, because there's no way that any 2 8-bit numbers will cause more than 1 to be carried over! The largest 8-bit number is $ff (255), and $ff + $ff = $1fe. See? Even with the largest numbers, only the number 1 can ever be carried over to the next "column". This is also true in decimal, where 9 + 9 is 18, so there's no way that an addition will ever cause more than 1 to be carried over.
Or...Is it ALWAYS carrying number 1 in MOST RECENT USING code if the Carry Flag got "turn on"?
In this case, the carry flag is changed every time you use an ADC instruction, and it will always indicate whether the result of each addition was larger than $ff. Several other instructions affect the carry flag too, each in their own way. You really have to consult which instructions affect which flags and how in order to know how to use the CPU flags. After a while you memorize this.

User avatar
Gilbert
Posts: 399
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong
Contact:

Re: Hello, I'm back, still need assistences

Post by Gilbert » Tue Jun 09, 2020 10:24 pm

My advice is to read some of the tutorials about programming in 6502 assembly to improve your understanding on the subject, such as those available from 6502.org.

Also, have a reference to the instructions ready at all time (such as this one linked to by the NESDEV wiki) so you may look up the details on the behaviour of each instruction when in doubt. In particular, such reference will usually list out what registers/flags will affect an instruction and what registers/flags that instruction will affect.

Edit: Didn't notice Tokumaru linked to the same reference, so, yeah.

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

Re: Hello, I'm back, still need assistences

Post by DocWaluigean » Tue Jun 09, 2020 10:30 pm

tokumaru wrote:
Tue Jun 09, 2020 10:14 pm
DocWaluigean wrote:
Tue Jun 09, 2020 9:52 pm
-ADC adds new numbers OUT OF THIN AIR into ONE PREVIOUS LINE OF CODE [?]
Yes, I picked numbers out of thin air just to demonstrate how ADC and the carry flag work. In a real program it would be pointless to add constant numbers together like that.
STA Result.... ? So it's now $117 into the Address labelled Result
No, only $17 got stored into the address labeled result. The top $1 went to the carry flag.
" but since the carry flag is set, it's also added to the accumulator, resulting in $6c" This, what do you mean.
"ADC" means "add with carry". This instruction always adds two numbers, PLUs the carry flag. Since the carry flag was one, the final result was $6c ($20 + $4b + 1) instead of $6b.
"since $6c fits in a byte just fine, the carry flag is now clear" ALSO this, what do you mean.
The result of this addition didn't cross the $ff boundary ($6c is less than 256!), so the carry was not set after this operation.
Is the Carry Flag just a simple "Zero and One" only?
Yes. By definition, flags are either set or clear (i.e. 0 or 1). That's OK though, because there's no way that any 2 8-bit numbers will cause more than 1 to be carried over! The largest 8-bit number is $ff (255), and $ff + $ff = $1fe. See? Even with the largest numbers, only the number 1 can ever be carried over to the next "column". This is also true in decimal, where 9 + 9 is 18, so there's no way that an addition will ever cause more than 1 to be carried over.
Or...Is it ALWAYS carrying number 1 in MOST RECENT USING code if the Carry Flag got "turn on"?
In this case, the carry flag is changed every time you use an ADC instruction, and it will always indicate whether the result of each addition was larger than $ff. Several other instructions affect the carry flag too, each in their own way. You really have to consult which instructions affect which flags and how in order to know how to use the CPU flags. After a while you memorize this.
So ADC is REALLY just an adding new numbers into the code? Or it also adds new number into the code **PLUS ONE**? Depending if the "Carry Flag is on or off?" I need to be specific in small details when I could use ADC even if the Carry Flag is on or off. What is the limit to using ADC beside higher than $FF?

So if the top $1 went to the carry flag, do you mean $100? or $001? Only the last two digits of the number [in HEX way] gets stored into the Address "Result"?

"This instruction always adds two numbers, PLUs the carry flag." So that also includes ZERO, which is adding nothing.

So what happens if it DID cross the $FF boundary if you said it's possible to make an 8-bit CPU process 16-bit numbers? Isn't that the point to cross the boundary?

This sounds REALLY powerful for the 6502, but I still don't get this part.

So in order to use Carry Flag, I have to use the ADC first?

-----------

Gilbert wrote:
Tue Jun 09, 2020 10:24 pm
My advice is to read some of the tutorials about programming in 6502 assembly to improve your understanding on the subject, such as those available from 6502.org.

Also, have a reference to the instructions ready at all time (such as this one linked to by the NESDEV wiki) so you may look up the details on the behaviour of each instruction when in doubt. In particular, such reference will usually list out what registers/flags will affect an instruction and what registers/flags that instruction will affect.

Edit: Didn't notice Tokumaru linked to the same reference, so, yeah.
There's a reason why I'm asking so many questions here. I can't understand well with explanations on books, on Easy6502, and famously Nerdy Nights. It's been two years since I learn what A X and Y Register is for, and I understand fully on those stuff. I'm not like anyone or you who could understand each sentences and details so well. If I do this by myself, I will always be lost on whatever I'm doing.

EDIT: Also, if you read the whole thing http://forums.nesdev.com/viewtopic.php?t=17454 You'd understand where I am right now.

Post Reply