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

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

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

Post by DocWaluigean »

This is the inside of the first "app" code of NES:

Code: Select all

  .inesprg 1   ; 1x 16KB PRG code
  .ineschr 1   ; 1x  8KB CHR data
  .inesmap 0   ; mapper 0 = NROM, no bank swapping
  .inesmir 1   ; background mirroring
  

;;;;;;;;;;;;;;;

    
  .bank 0
  .org $C000 
RESET:
  SEI          ; disable IRQs
  CLD          ; disable decimal mode
  LDX #$40
  STX $4017    ; disable APU frame IRQ
  LDX #$FF
  TXS          ; Set up stack
  INX          ; now X = 0
  STX $2000    ; disable NMI
  STX $2001    ; disable rendering
  STX $4010    ; disable DMC IRQs

vblankwait1:       ; First wait for vblank to make sure PPU is ready
  BIT $2002
  BPL vblankwait1

clrmem:
  LDA #$00
  STA $0000, x
  STA $0100, x
  STA $0200, x
  STA $0400, x
  STA $0500, x
  STA $0600, x
  STA $0700, x
  LDA #$FE
  STA $0300, x
  INX
  BNE clrmem
   
vblankwait2:      ; Second wait for vblank, PPU is ready after this
  BIT $2002
  BPL vblankwait2


  LDA #%10000000   ;intensify blues
  STA $2001

Forever:
  JMP Forever     ;jump back to Forever, infinite loop
  
 

NMI:
  RTI
 
;;;;;;;;;;;;;;  
  
  
  
  .bank 1
  .org $FFFA     ;first of the three vectors starts here
  .dw NMI        ;when an NMI happens (once per frame if enabled) the 
                   ;processor will jump to the label NMI:
  .dw RESET      ;when the processor first turns on or is reset, it will jump
                   ;to the label RESET:
  .dw 0          ;external interrupt IRQ is not used in this tutorial
  
  
;;;;;;;;;;;;;;  
  
  
  .bank 2
  .org $0000
  .incbin "mario.chr"   ;includes 8KB graphics file from SMB1
I honestly have NO idea how to set up a 100% code-ready blank where it shows nothing but gray screen. Like which code needs to be deleted before it's clean-ready. Like when you start up BASIC programming, and you see nothing on the coding screen? That kind, but for this 6502.

Let's try for me to read it:

The code sets up the .ines to prepare the CPU, PPU, but I still don't know how to use it yet. Can I change the number? inesmap 0 to inesmap 255?

I don't know what SEI and CLD is yet nor how to use:
SEI - Set Interrupt Disable
I = 1

Set the interrupt disable flag to one.
CLD - Clear Decimal Mode
D = 0

Sets the decimal mode flag to zero.
I know don't think too much, but still..

Code: Select all

  STX $2000    ; disable NMI
  STX $2001    ; disable rendering
  STX $4010    ; disable DMC IRQs
No idea, but PPU ports I'm guessing.

vblankwait1: ; First wait for vblank to make sure PPU is ready
BIT $2002
BPL vblankwait1
VBlank has to do with one-line rendering from top to bottom, right?

Code: Select all

clrmem:
  LDA #$00
  STA $0000, x
  STA $0100, x
  STA $0200, x
  STA $0400, x
  STA $0500, x
  STA $0600, x
  STA $0700, x
  LDA #$FE
  STA $0300, x
  INX
  BNE clrmem
Judging how I read it, I don't know anymore how to use the comma atm... It's clearing the memory to be used.

Code: Select all

vblankwait2:      ; Second wait for vblank, PPU is ready after this
  BIT $2002
  BPL vblankwait2
After this, THIS is where I start putting codes in whatever I want, right?

Code: Select all

 LDA #%10000000   ;intensify blues
  STA $2001

Forever:
  JMP Forever     ;jump back to Forever, infinite loop
Making color blue background of it?

Code: Select all

NMI:
  RTI
RTI - Return from Interrupt
The RTI instruction is used at the end of an interrupt processing routine. It pulls the processor flags from the stack followed by the program counter.
I don't know this opcode yet.

Code: Select all

  .bank 1
  .org $FFFA     ;first of the three vectors starts here
  .dw NMI        ;when an NMI happens (once per frame if enabled) the 
                   ;processor will jump to the label NMI:
  .dw RESET      ;when the processor first turns on or is reset, it will jump
                   ;to the label RESET:
  .dw 0          ;external interrupt IRQ is not used in this tutorial
Okay...?

Code: Select all

;;;;;;;;;;;;;;  
  
  
  .bank 2
  .org $0000
  .incbin "mario.chr"   ;includes 8KB graphics file from SMB1
I guess after .org $0000, I can code anything I want now, right? This part is inserting file "mario.chr" into the game.
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

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

Post by Garth »

DocWaluigean wrote: Sat Jun 13, 2020 12:13 pm I don't understand at first sight.

Code: Select all

        LDA foobar - Load number into A Register from "foobar" label.
"Foobar" is a silly name used in programming discussions where the identity is not particularly important, like of like saying "John Doe" for a hypothetical person. In the scenario I gave, "foobar" is the name of a variable in RAM. When the assembler encounters it, it will substitute-in the actual numerical address.
BEQ label1 - If Zero Flag is on, go to "label1".
[ ANY CODE ]
[ ANY CODE ]

label1: [ ANY CODE]
LDX #7 - Load number 7 into X Register.
LDA array1, X - Load numbers from "array1" label to Register A, and copy the "array1" number into Register X.
DEX - Decrement X Register
BPL label2 - If destination reached here while the Negative Flag is off, go to "label2"
Perhaps I did not make it obvious enough. In my earlier post, that second piece of code has label2, not label1, meaning they're two different things. Also, label2 is on the line after the LDX #7, and note that there's another line after the LDA array1,X, which is STA array2,X.
· The stack pointer, or S register, is a pointer to the next available location on the system stack, a special area
of memory for temporary data storage. In addition to being available to the user, the stack pointer and stack
are also used automatically every time a subroutine is called or an interrupt occurs to store return information.
· Finally, the program counter, or PC, is a pointer to the memory location of the instruction to be executed
next.
I don't know if Processor status is used in NES, and program counter in NES. But I do know Stack Pointer is in NES in anyway. So it's a Temporary Data Storage, and the way to use it is...???
The Processor-status register P is absolutely used in NES. As for the stack, I could point you to the first two pages of my 6502 treatise on stacks, the first one being just the very basics, at http://wilsonminesco.com/stacks/basics.html, and then the second one being about subroutine return addresses and nesting, at http://wilsonminesco.com/stacks/sub_ret.html . Leave the rest of the stacks treatise for after you have advanced a little further.
http://WilsonMinesCo.com/ lots of 6502 resources
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

Garth wrote: Sat Jun 13, 2020 2:38 pm
DocWaluigean wrote: Sat Jun 13, 2020 12:13 pm I don't understand at first sight.

Code: Select all

        LDA foobar - Load number into A Register from "foobar" label.
"Foobar" is a silly name used in programming discussions where the identity is not particularly important, like of like saying "John Doe" for a hypothetical person. In the scenario I gave, "foobar" is the name of a variable in RAM. When the assembler encounters it, it will substitute-in the actual numerical address.
BEQ label1 - If Zero Flag is on, go to "label1".
[ ANY CODE ]
[ ANY CODE ]

label1: [ ANY CODE]
LDX #7 - Load number 7 into X Register.
LDA array1, X - Load numbers from "array1" label to Register A, and copy the "array1" number into Register X.
DEX - Decrement X Register
BPL label2 - If destination reached here while the Negative Flag is off, go to "label2"
Perhaps I did not make it obvious enough. In my earlier post, that second piece of code has label2, not label1, meaning they're two different things. Also, label2 is on the line after the LDX #7, and note that there's another line after the LDA array1,X, which is STA array2,X.
· The stack pointer, or S register, is a pointer to the next available location on the system stack, a special area
of memory for temporary data storage. In addition to being available to the user, the stack pointer and stack
are also used automatically every time a subroutine is called or an interrupt occurs to store return information.
· Finally, the program counter, or PC, is a pointer to the memory location of the instruction to be executed
next.
I don't know if Processor status is used in NES, and program counter in NES. But I do know Stack Pointer is in NES in anyway. So it's a Temporary Data Storage, and the way to use it is...???
The Processor-status register P is absolutely used in NES. As for the stack, I could point you to the first two pages of my 6502 treatise on stacks, the first one being just the very basics, at http://wilsonminesco.com/stacks/basics.html, and then the second one being about subroutine return addresses and nesting, at http://wilsonminesco.com/stacks/sub_ret.html . Leave the rest of the stacks treatise for after you have advanced a little further.
So it's like first dimensional Arrays about Stack?
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

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

Post by Garth »

DocWaluigean wrote: Sat Jun 13, 2020 12:50 pm The Zero Flag: It turns on if the A, X, Y, or S Register has zero? It turns on if ONLY The A Register is turned on? Or if the destination of Address is holding zero right now?
Z=1 if the result of the last load, logic, or arithmetic operation is 0. Stores do not affect it, nor does it ever reflect the status of the stack pointer register S.
The Carry Flag: It turns on if ONLY the A Register got overflow [over 255] and revert back to zero, right? Or it can be also X, Y, and S? Or also the Address?
That's partly correct. C=1 if the result of an addition won't fit in 8 bits, so there's a carry into the 9th bit. It also tells what bit was shifted or rotated out the left end; for example 10000000 in binary, shifted left, will be 1 00000000, where the 1 is now in the carry bit. It also reflects whether a borrow happened in a subtraction; but there it's the inverse, meaning C=1 means a borrow did not happen. It's best not to use the word "overflow" though, because the overflow flag is separate and has a different function, as discussed earlier.
The Negative Flag: It turns on [or set] if the A Register got backward? Or it includes X, Y, and S? I don't know Stack Pointers yet. Does it include Address if the number stored is backward?
N=1 if the last load, logic, or arithmetic function resulted in the high bit set. For example, if X=0 and you DEcrement X (with the DEX instruction), the result if 11111111 in binary, the high bit being set.
LDA #$09 - Put HEX number 9 into A.
SBC #$0A - Subtract 10 [HEX number A] into Register A.

;;; The A Register is now carrying HEX number FF, and the Negative Flag is turned on.
Right.
STA $0100 - Put HEX number FF into A. - At ANY point the code goes to here, the Negative Flag is turned on.
No; in this case, you're storing (STA $0100) means "STore Accumulator's contents in address $100," and store operations do not affect the status.
Does it affect with X, Y, and S Register also?
Load, increment, and decrement instructions on X and Y affect the status. The only direct access the programmer has to S is TXS and TSX; so it's kind of in a different category.
So it's like first dimensional Arrays about Stack?
Yes; what I showed was for two one-dimensional arrays. The stack was not involved in that loop I showed though. However, arrays of multiple dimensions can be handled, limited basically only to the amount of available memory.
http://WilsonMinesCo.com/ lots of 6502 resources
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

Garth wrote: Sat Jun 13, 2020 3:02 pm
DocWaluigean wrote: Sat Jun 13, 2020 12:50 pm The Zero Flag: It turns on if the A, X, Y, or S Register has zero? It turns on if ONLY The A Register is turned on? Or if the destination of Address is holding zero right now?
Z=1 if the result of the last load, logic, or arithmetic operation is 0. Stores do not affect it, nor does it ever reflect the status of the stack pointer register S.
The Carry Flag: It turns on if ONLY the A Register got overflow [over 255] and revert back to zero, right? Or it can be also X, Y, and S? Or also the Address?
That's partly correct. C=1 if the result of an addition won't fit in 8 bits, so there's a carry into the 9th bit. It also tells what bit was shifted or rotated out the left end; for example 10000000 in binary, shifted left, will be 1 00000000, where the 1 is now in the carry bit. It also reflects whether a borrow happened in a subtraction; but there it's the inverse, meaning C=1 means a borrow did not happen. It's best not to use the word "overflow" though, because the overflow flag is separate and has a different function, as discussed earlier.
The Negative Flag: It turns on [or set] if the A Register got backward? Or it includes X, Y, and S? I don't know Stack Pointers yet. Does it include Address if the number stored is backward?
N=1 if the last load, logic, or arithmetic function resulted in the high bit set. For example, if X=0 and you DEcrement X (with the DEX instruction), the result if 11111111 in binary, the high bit being set.
LDA #$09 - Put HEX number 9 into A.
SBC #$0A - Subtract 10 [HEX number A] into Register A.

;;; The A Register is now carrying HEX number FF, and the Negative Flag is turned on.
Right.
STA $0100 - Put HEX number FF into A. - At ANY point the code goes to here, the Negative Flag is turned on.
No; in this case, you're storing (STA $0100) means "STore Accumulator's contents in address $100," and store operations do not affect the status.
Does it affect with X, Y, and S Register also?
Load, increment, and decrement instructions on X and Y affect the status. The only direct access the programmer has to S is TXS and TSX; so it's kind of in a different category.
So it's like first dimensional Arrays about Stack?
Yes; what I showed was for two one-dimensional arrays. The stack was not involved in that loop I showed though. However, arrays of multiple dimensions can be handled, limited basically only to the amount of available memory.
So Zero Flag can turn on if the latest operation [A, X, Y, and S] is 0 right now? If X and Y is number 20 and 50, but A is 0, the Flag is on, and will remain on until A equals something other than 0?
That's partly correct. C=1 if the result of an addition won't fit in 8 bits, so there's a carry into the 9th bit. It also tells what bit was shifted or rotated out the left end; for example 10000000 in binary, shifted left, will be 1 00000000, where the 1 is now in the carry bit. It also reflects whether a borrow happened in a subtraction; but there it's the inverse, meaning C=1 means a borrow did not happen. It's best not to use the word "overflow" though, because the overflow flag is separate and has a different function, as discussed earlier.
I'm guessing it's a yes that it includes A, X, and Y [and S?] Registers.
N=1 if the last load, logic, or arithmetic function resulted in the high bit set. For example, if X=0 and you DEcrement X (with the DEX instruction), the result if 11111111 in binary, the high bit being set.
Can be turn on by A, X, Y [and S] Register?

Code: Select all

LDA #$09 - Put HEX number 9 into A.
SBC #$0A - Subtract 10 [HEX number A] into Register A.

;;; The A Register is now carrying HEX number FF, and the Negative Flag is turned on.
Right.
Okay, I'm wondering if it applies to X, Y, S, and PC Register too.
STA $0100 - Put HEX number FF into A. - At ANY point the code goes to here, the Negative Flag is turned on.
No; in this case, you're storing (STA $0100) means "STore Accumulator's contents in address $100," and store operations do not affect the status.
Is there any Flag that's affected by store operations?
Does it affect with X, Y, and S Register also?
Load, increment, and decrement instructions on X and Y affect the status. The only direct access the programmer has to S is TXS and TSX; so it's kind of in a different category.
Sorry for repeating questions so much. So all three Register (Usually A X and Y) affect the status? I can turn on 3 switches using 3 Registers? Which Registers can't turn on certain Flags? And I'm wondering the Stack Pointer as a different Register, as it's not part of 3 Registers.
So it's like first dimensional Arrays about Stack?
Yes; what I showed was for two one-dimensional arrays. The stack was not involved in that loop I showed though. However, arrays of multiple dimensions can be handled, limited basically only to the amount of available memory.
I see. Although I'm still new to this Stack Arrays stuff.
turboxray
Posts: 348
Joined: Thu Oct 31, 2019 12:56 am

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

Post by turboxray »

Garth wrote: Sat Jun 13, 2020 3:02 pm
DocWaluigean wrote: Sat Jun 13, 2020 12:50 pm The Zero Flag: It turns on if the A, X, Y, or S Register has zero? It turns on if ONLY The A Register is turned on? Or if the destination of Address is holding zero right now?
Z=1 if the result of the last load, logic, or arithmetic operation is 0. Stores do not affect it, nor does it ever reflect the status of the stack pointer register S.
It does reflect S when you do a TSX.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

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

Post by tokumaru »

There's no such thing as NESASM6 or NESASM7. there's an assembler called ASM6, but it's completely unrelated to NESASM. The problem with NESASM is that it's based on a PC Engine assembler, so it carries over some design choices that make sense for that platform but not for the NES. NESASM is still the most popular one among newbies though, as there are more tutorials/articles that use it.

As for CMP being a subtraction, that's true. Subtracting one number from another is the best way to compare them, and this is precisely how it's done in assembly. Think about it: if the result of a subtraction is 0, this means that the 2 numbers are equal! This is why the Z flag is used to determine equality (BEQ, BNE). And if they're not equal, the carry flag will tell you which one is larger.

On the 6502, the difference between CMP and SBC is that CMP doesn't use the carry flag (i.e. you can't borrow with CMP) and it doesn't keep the result (only the flags are affected).
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

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

Post by Garth »

DocWaluigean wrote: Sat Jun 13, 2020 3:38 pm So Zero Flag can turn on if the latest operation [A, X, Y, and S] is 0 right now? If X and Y is number 20 and 50, but A is 0, the Flag is on, and will remain on until A equals something other than 0?
If the latest operation was on X, Z will reflect the X result. If the latest operation was on Y, Z will reflect the Y result. If the latest operation wan on A, Z will reflect the A result.
That's partly correct. C=1 if the result of an addition won't fit in 8 bits, so there's a carry into the 9th bit. It also tells what bit was shifted or rotated out the left end; for example 10000000 in binary, shifted left, will be 1 00000000, where the 1 is now in the carry bit. It also reflects whether a borrow happened in a subtraction; but there it's the inverse, meaning C=1 means a borrow did not happen. It's best not to use the word "overflow" though, because the overflow flag is separate and has a different function, as discussed earlier.
I'm guessing it's a yes that it includes A, X, and Y [and S?] Registers.
You cannot rotate, shift, or add in the X & Y registers, nor S. You can compare X or Y with CPX or CPY, and that can affect the C flag. You cannot compare S though.
N=1 if the last load, logic, or arithmetic function resulted in the high bit set. For example, if X=0 and you DEcrement X (with the DEX instruction), the result if 11111111 in binary, the high bit being set.
Can be turn on by A, X, Y [and S] Register?
X and Y, yes; but not S. As turboxray pointed out, TSX affects N and Z. (Neither TSX nor TXS affect C though.)

Code: Select all

LDA #$09 - Put HEX number 9 into A.
SBC #$0A - Subtract 10 [HEX number A] into Register A.

;;; The A Register is now carrying HEX number FF, and the Negative Flag is turned on.
Right.
Okay, I'm wondering if it applies to X, Y, S, and PC Register too.
You cannot subtract from X, Y, S, or PC, only A.
Is there any Flag that's affected by store operations?
No.
Does it affect with X, Y, and S Register also?
Load, increment, and decrement instructions on X and Y affect the status. The only direct access the programmer has to S is TXS and TSX; so it's kind of in a different category.
Sorry for repeating questions so much. So all three Register (Usually A X and Y) affect the status?
It's the action on them that affects the status. For example, if you act on A, the status reflects that. Then if you act on X, the status is overwritten with that action. Then if you act on Y, the status is overwritten again. So status reflects the latest action, not necessarily the current state of any one register.
I can turn on 3 switches using 3 Registers? Which Registers can't turn on certain Flags? And I'm wondering the Stack Pointer as a different Register, as it's not part of 3 Registers.
Right. The stack pointer has a very specific purpose that's separate from what A, X, and Y are used for. As for switches, I'm not sure what you're asking.
http://WilsonMinesCo.com/ lots of 6502 resources
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

tokumaru wrote: Sat Jun 13, 2020 4:45 pm There's no such thing as NESASM6 or NESASM7. there's an assembler called ASM6, but it's completely unrelated to NESASM. The problem with NESASM is that it's based on a PC Engine assembler, so it carries over some design choices that make sense for that platform but not for the NES. NESASM is still the most popular one among newbies though, as there are more tutorials/articles that use it.

As for CMP being a subtraction, that's true. Subtracting one number from another is the best way to compare them, and this is precisely how it's done in assembly. Think about it: if the result of a subtraction is 0, this means that the 2 numbers are equal! This is why the Z flag is used to determine equality (BEQ, BNE). And if they're not equal, the carry flag will tell you which one is larger.

On the 6502, the difference between CMP and SBC is that CMP doesn't use the carry flag (i.e. you can't borrow with CMP) and it doesn't keep the result (only the flags are affected).
I was wondering about the best of the best tool to use for NES making 2020 right now. ASM6? I know about YY-CHR and Mesen for emulator, but I wonder what else.

CMP must be the MOST difficult opcode for me to understand! First, it compares the code, then using it alters the usages for BEQ and BNE and others, and NOW it can subtract one number to another number!?
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

Garth wrote: Sat Jun 13, 2020 4:59 pm
DocWaluigean wrote: Sat Jun 13, 2020 3:38 pm So Zero Flag can turn on if the latest operation [A, X, Y, and S] is 0 right now? If X and Y is number 20 and 50, but A is 0, the Flag is on, and will remain on until A equals something other than 0?
If the latest operation was on X, Z will reflect the X result. If the latest operation was on Y, Z will reflect the Y result. If the latest operation wan on A, Z will reflect the A result.
That's partly correct. C=1 if the result of an addition won't fit in 8 bits, so there's a carry into the 9th bit. It also tells what bit was shifted or rotated out the left end; for example 10000000 in binary, shifted left, will be 1 00000000, where the 1 is now in the carry bit. It also reflects whether a borrow happened in a subtraction; but there it's the inverse, meaning C=1 means a borrow did not happen. It's best not to use the word "overflow" though, because the overflow flag is separate and has a different function, as discussed earlier.
I'm guessing it's a yes that it includes A, X, and Y [and S?] Registers.
You cannot rotate, shift, or add in the X & Y registers, nor S. You can compare X or Y with CPX or CPY, and that can affect the C flag. You cannot compare S though.
N=1 if the last load, logic, or arithmetic function resulted in the high bit set. For example, if X=0 and you DEcrement X (with the DEX instruction), the result if 11111111 in binary, the high bit being set.
Can be turn on by A, X, Y [and S] Register?
X and Y, yes; but not S. As turboxray pointed out, TSX affects N and Z. (Neither TSX nor TXS affect C though.)

Code: Select all

LDA #$09 - Put HEX number 9 into A.
SBC #$0A - Subtract 10 [HEX number A] into Register A.

;;; The A Register is now carrying HEX number FF, and the Negative Flag is turned on.
Right.
Okay, I'm wondering if it applies to X, Y, S, and PC Register too.
You cannot subtract from X, Y, S, or PC, only A.
Is there any Flag that's affected by store operations?
No.
Does it affect with X, Y, and S Register also?
Load, increment, and decrement instructions on X and Y affect the status. The only direct access the programmer has to S is TXS and TSX; so it's kind of in a different category.
Sorry for repeating questions so much. So all three Register (Usually A X and Y) affect the status?
It's the action on them that affects the status. For example, if you act on A, the status reflects that. Then if you act on X, the status is overwritten with that action. Then if you act on Y, the status is overwritten again. So status reflects the latest action, not necessarily the current state of any one register.
I can turn on 3 switches using 3 Registers? Which Registers can't turn on certain Flags? And I'm wondering the Stack Pointer as a different Register, as it's not part of 3 Registers.
Right. The stack pointer has a very specific purpose that's separate from what A, X, and Y are used for. As for switches, I'm not sure what you're asking.
===================
DocWaluigean wrote: ↑Sat Jun 13, 2020 5:38 pm
So Zero Flag can turn on if the latest operation [A, X, Y, and S] is 0 right now? If X and Y is number 20 and 50, but A is 0, the Flag is on, and will remain on until A equals something other than 0?
If the latest operation was on X, Z will reflect the X result. If the latest operation was on Y, Z will reflect the Y result. If the latest operation wan on A, Z will reflect the A result.
Oooooh, I get it. It will reflect mostly on the LATEST operations of most recent usages of Registers.
That's partly correct. C=1 if the result of an addition won't fit in 8 bits, so there's a carry into the 9th bit. It also tells what bit was shifted or rotated out the left end; for example 10000000 in binary, shifted left, will be 1 00000000, where the 1 is now in the carry bit. It also reflects whether a borrow happened in a subtraction; but there it's the inverse, meaning C=1 means a borrow did not happen. It's best not to use the word "overflow" though, because the overflow flag is separate and has a different function, as discussed earlier.
I'm guessing it's a yes that it includes A, X, and Y [and S?] Registers.
You cannot rotate, shift, or add in the X & Y registers, nor S. You can compare X or Y with CPX or CPY, and that can affect the C flag. You cannot compare S though.
This one, I'm a little confused... I'm thinking the X and Y Register will NOT be affected by Overflow Flag?
N=1 if the last load, logic, or arithmetic function resulted in the high bit set. For example, if X=0 and you DEcrement X (with the DEX instruction), the result if 11111111 in binary, the high bit being set.
Can be turn on by A, X, Y [and S] Register?
X and Y, yes; but not S. As turboxray pointed out, TSX affects N and Z. (Neither TSX nor TXS affect C though.)
Okay, A, X, and Y can turn on the Negative Flag. But NOT S nor PC.
LDA #$09 - Put HEX number 9 into A.
SBC #$0A - Subtract 10 [HEX number A] into Register A.

;;; The A Register is now carrying HEX number FF, and the Negative Flag is turned on.
Right.
Okay, I'm wondering if it applies to X, Y, S, and PC Register too.
You cannot subtract from X, Y, S, or PC, only A.
Okay, ONLY Register A can use ADC and SBC, got it.
Is there any Flag that's affected by store operations?
No.
Very, very, very good to know, so I'll try to keep that in mind.
Does it affect with X, Y, and S Register also?
Load, increment, and decrement instructions on X and Y affect the status. The only direct access the programmer has to S is TXS and TSX; so it's kind of in a different category.
Sorry for repeating questions so much. So all three Register (Usually A X and Y) affect the status?
It's the action on them that affects the status. For example, if you act on A, the status reflects that. Then if you act on X, the status is overwritten with that action. Then if you act on Y, the status is overwritten again. So status reflects the latest action, not necessarily the current state of any one register.
This one brings me interesting questions. Let's say that Register A has Carry Flag turn on, Register X has Negative Flag turn on, and Register Y has Zero Flag turn on. Through most recent operations, will the flag turn off and on many times when I use certain Registers?

-I use the Register A. The Carry Flag is turned on.
-Then I use Register X, which has Negative Flag turned on.
[Either Carry Flag is also turn on because Register A is still carrying number? Or if it turns off because I'm using Register X right now.]
-Then I use the Register A.
[Does the Negative Flag still remains on at this point? Or NOW it turns off the Negative Flag but it turns ON the Carry Flag?]
Then I used the Register Y, which has Zero Flag turn on.
[Does it turns off both the Negative Flag and Carry Flag, but NOW turns on the Zero Flag?]
Then I used the Register X Flag.
[Does it turn off the Zero Flag, and turns off the Carry Flag, but NOW turns on the Negative Flag?]

[[[Selected Flags will be constantly turning on and off many times?]]]

OR

-Register A
-Register X
[Carry Flag is turned on, and Negative Flag is turned on, because A and X is now active.]
-Register A
[Still both turn on]
Register Y
[Zero Flag is now turned on, as Register Y is now actively holding number zero.]
Register X
Register A
Register X
Register Y
Register A...
[Doesn't matter...]

[[[All three Flags will be turning on as they're all active anyway?]]]
I can turn on 3 switches using 3 Registers? Which Registers can't turn on certain Flags? And I'm wondering the Stack Pointer as a different Register, as it's not part of 3 Registers.
Right. The stack pointer has a very specific purpose that's separate from what A, X, and Y are used for. As for switches, I'm not sure what you're asking.
I mean Flags when I said switches. Like I can turn on all Carry Flags using 3 Registers.

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

I'm writing something really big about what I learned.
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

So let's see what I or anyone learned so far when I copy and paste informations:
=================================================================================================================================

-------------------------------------------------------
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.

+++++++++++++++++++++++
The letters meaning in this:
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

JMP cupcakes

--

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!

STA $0420 ; Stag Party
STX $0421 ; Outside Party
STY $0422 ; Musical Drumming Party

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

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.

STA / STX / STY - "Store [or actually, "copy and paste"] Data into the Address"

Even after putting numbers in the Address, the number is still being carried by A/X/Y Register!

===EXAMPLE1===

LDA #$0F ; Load HEX number 0F [15] into Register A.

STA $0001 ; Store HEX number 0F [15] into Address $0001.
Register A is still carrying HEX number 0F [15], So both Address $0001 and Register A has number 15 / HEX number 0F!

---

A = 15 [The F number for HEX.]

"Put_Number_From_A_Into" Address-0001

The Address $0001 is now carrying number 15. Register A is also carrying number 15.

===EXAMPLE2===

LDX #13

STA $0030

---

X = 13

Address = 0030

The Address $0030 is now carrying number 13. Register X is also still carrying number 13.

===EXAMPLE3===

LDY %#00001010

STA $13

---

Y = 10 [The number from Binary]

Address = 0013.

The Address $0013 is now carrying number 10. Register Y is also 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

---
According to that examples:

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!!!!!!!!

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

ADC = ADd with Carry

ADC let's you add numbers directly into Register A.

VERY simple!

----
Example:

LDA #$08 - Load HEX number 8 [8 lol] into Register A.
ADC #$08 - Add HEX number 8 into Register A. Register A. is now carrying HEX number 10 [16].
STA $0200 - Store HEX number 10 [16] from Register A into Address $0200. Register A is still holding HEX number 10.

BOTH Register A and Address $0200 is carrying HEX number 10 [normal number 16.]
----

SBC = SuBtract with Carry

SBC is polar opposite of ADC.

SBC let's you subtract numbers directly from Register A.

ALSO VERY simple!

----
Example:

LDA #129 - Load number 129 into Register A.
SBC #28 - Subtract 129 from Register A with 28. Now Register A is holding number 101.
DEC - Decrement Register A. Now Register A is holding number 100.
STA $0255 - Store number 100 from Register A directly into Address $0255. Now both Address $0255 and Register A is carrying number 100.
----



Carry Flag - A flag that turns on when numbers being carried by A/X/Y Register went over 255. [Also called Overflow in terms of going over 255.]
Also known as C-Flag.

In this time, ways to turn on Carry Flag is through usages of ADC opcodes onto Register A to equal higher than 255.

*There's many way to say this. Turn on and turn off, to me, is most preferrable to say. In this programming, Set may means "Turn On", and Clear may means "Turn Off".*

CLC = Clear Carry Flag

CLC Clears Carry Flag. Turns Carry Flag to zero.

SEC = Set Carry Flag

SEC Sets Carry Flag. In other words, "Turn On the Carry Flag" by turning Carry Flag to one.

---

BCS = Branch if Carry Set
BCC = Branch if Carry Clear

BCS and BCC is special opcodes that relies on Carry Flag.

BCS - If the Carry Flag is on as the destination reaches BCS, it will jump to selected label or Address.
BCC = If the Carry Flag is OFF as the destination reaches BCC, it will jump to selected label or Address.

---
EXAMPLE:

Icecream: - Label of Icecream.
LDA $#F0 - Load HEX number F0 [240] into Register A.
INC - Increment Register A by one. Now Register A has HEX number F1 [241].

BCC Icecream - This opcode checks if the Carry Flag is on or off. Since the Carry Flag is off, it will now jump to the label Icecream. As it also gets incremented by one again [F2, F3, F4...]. Right until it reaches 255, it incremented into 256, which is now back to 0 because it overflows. NOW the Carry Flag turns on as Register A contains number 0 from increments. As it reaches this destination where Carry Flag is on, it will IGNORE this code and proceed.

eating: - Label.
STA $1000 - Store number ZERO from Register A directly into Address $1000. Now both Register A and Address $1000 has number zero.

[[TO BE EDITED]]
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

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

Post by tokumaru »

DocWaluigean wrote: Sat Jun 13, 2020 5:08 pmI was wondering about the best of the best tool to use for NES making 2020 right now. ASM6?
This ia a subjective matter, there's no absolute best assembler. They all have pros and cons that affect different people differently. For absolute beginners, definitely NESASM or ASM6 (there's more online material for NESASM though).
I know about YY-CHR and Mesen for emulator, but I wonder what else.
Graphics editing is also subjective. I personally prefer to work on "real" graphics editors (Photoshop, Gimp, or even Paint), which are less restricted than traditional tile editors, and then convert the graphics to the format the NES uses.

As for emulators, you definitely want to go for accuracy and debugging features. Currently, Mesen is the one that offers the best in both areas, but others like Nintendulator and FCEUX also have their merits.
CMP must be the MOST difficult opcode for me to understand!
It's literally just a SBC that doesn't use the carry and doesn't save the result. If anything, it's a simplified SBC.
First, it compares the code[/quotes]
And in assembly, "compare" actually means subtract. This is not just on the 6502 either, every other CPU architecture I'm aware of does comparisons with subtractions.

I'm gonna say this one more time: be careful with how you word things. Nobody here uses the expression "the code" when talking about numbers. I know it may be hard for you to adapt to how other people do things, but if you keep using names nobody else uses, it will make communication harder, and imprint the wrong terms even deeper in your brain. Please try to learn the terms that people actually use, it will make the learning process easier for you.
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

tokumaru wrote: Sat Jun 13, 2020 5:38 pm
DocWaluigean wrote: Sat Jun 13, 2020 5:08 pmI was wondering about the best of the best tool to use for NES making 2020 right now. ASM6?
This ia a subjective matter, there's no absolute best assembler. They all have pros and cons that affect different people differently. For absolute beginners, definitely NESASM or ASM6 (there's more online material for NESASM though).
I know about YY-CHR and Mesen for emulator, but I wonder what else.
Graphics editing is also subjective. I personally prefer to work on "real" graphics editors (Photoshop, Gimp, or even Paint), which are less restricted than traditional tile editors, and then convert the graphics to the format the NES uses.

As for emulators, you definitely want to go for accuracy and debugging features. Currently, Mesen is the one that offers the best in both areas, but others like Nintendulator and FCEUX also have their merits.
CMP must be the MOST difficult opcode for me to understand!
It's literally just a SBC that doesn't use the carry and doesn't save the result. If anything, it's a simplified SBC.
First, it compares the code[/quotes]
And in assembly, "compare" actually means subtract. This is not just on the 6502 either, every other CPU architecture I'm aware of does comparisons with subtractions.

I'm gonna say this one more time: be careful with how you word things. Nobody here uses the expression "the code" when talking about numbers. I know it may be hard for you to adapt to how other people do things, but if you keep using names nobody else uses, it will make communication harder, and imprint the wrong terms even deeper in your brain. Please try to learn the terms that people actually use, it will make the learning process easier for you.
I see. I'm wondering which is more recently released, the ASM6 or NESASM?
---

I use Aseprite for it!

I wonder what merits Nintendulator and FCEUX has?
---
Really? I wish to ask to explain, but I don't want to be bothersome, so I don't know how freedom is "The stupidest question is question unanswered.".
---
Alright... Which terms does NESDev or the programmers of 6502 actually uses, and how do I use it in a sentences?
More importantly, if I were to make a "fun book" about what I [or we] learn about 6502 Assembly to make NES programming easier, how would I able to make anyone, possibly children, understand more easily with programming languages so they won't go through rough times like I had years ago?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

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

Post by tokumaru »

DocWaluigean wrote: Sat Jun 13, 2020 5:55 pmI see. I'm wondering which is more recently released, the ASM6 or NESASM?
I think both have received little fixes over the years, but neither has been updated recently. "Newer" doesn't necessarily mean "better", though.
I wonder what merits Nintendulator and FCEUX has?
Nintendulator aims for accuracy, and has a few debugging features. FCEUX is one of the least accurate emulators around, but it's very lightweight and has easy to use debugging features. Mesen also aims for accuracy, and has the best debugging features of all NES emulators, but they're not as easy to use, and a more powerful computer is needed to use most features smoothly.
Alright... Which terms does NESDev or the programmers of 6502 actually uses, and how do I use it in a sentences?
In this case you can simply say SBC/CMP subtracts a number from another, but if you want to get technical, numbers are specified as operands in instructions. For example: in the instruction SBC #14, SBC is the operator (it performs an operation) and #14 is the operand (it's an argument needed by the operator).
More importantly, if I were to make a "fun book" about what I [or we] learn about 6502 Assembly to make NES programming easier, how would I able to make anyone, possibly children, understand more easily with programming languages so they won't go through rough times like I had years ago?
If I knew how to teach hard subjects the easy way I'd probably be making money off of that. I honestly don't think you can dumb down these technical subjects to a point where everyone can understand them and still provide enough information for people to actually produce something. I mean, there's nothing wrong with a children's book or TV show dumbing down the inner workings of video games (like Beakman's World did it, for example) to give kids a notion of how they work, but I don't think you can convey enough technical information to actually have kids *make* a video game. I mean, just the concept of binary numbers alone is incredibly complex for little humans who're still learning to add and subtract in decimal! If you can't understand bits, you can't code in assembly. Even most adults will be surprised and confused at the idea that you count in bases other than 10.
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

tokumaru wrote: Sat Jun 13, 2020 6:58 pm
DocWaluigean wrote: Sat Jun 13, 2020 5:55 pmI see. I'm wondering which is more recently released, the ASM6 or NESASM?
I think both have received little fixes over the years, but neither has been updated recently. "Newer" doesn't necessarily mean "better", though.
I wonder what merits Nintendulator and FCEUX has?
Nintendulator aims for accuracy, and has a few debugging features. FCEUX is one of the least accurate emulators around, but it's very lightweight and has easy to use debugging features. Mesen also aims for accuracy, and has the best debugging features of all NES emulators, but they're not as easy to use, and a more powerful computer is needed to use most features smoothly.
Alright... Which terms does NESDev or the programmers of 6502 actually uses, and how do I use it in a sentences?
In this case you can simply say SBC/CMP subtracts a number from another, but if you want to get technical, numbers are specified as operands in instructions. For example: in the instruction SBC #14, SBC is the operator (it performs an operation) and #14 is the operand (it's an argument needed by the operator).
More importantly, if I were to make a "fun book" about what I [or we] learn about 6502 Assembly to make NES programming easier, how would I able to make anyone, possibly children, understand more easily with programming languages so they won't go through rough times like I had years ago?
If I knew how to teach hard subjects the easy way I'd probably be making money off of that. I honestly don't think you can dumb down these technical subjects to a point where everyone can understand them and still provide enough information for people to actually produce something. I mean, there's nothing wrong with a children's book or TV show dumbing down the inner workings of video games (like Beakman's World did it, for example) to give kids a notion of how they work, but I don't think you can convey enough technical information to actually have kids *make* a video game. I mean, just the concept of binary numbers alone is incredibly complex for little humans who're still learning to add and subtract in decimal! If you can't understand bits, you can't code in assembly. Even most adults will be surprised and confused at the idea that you count in bases other than 10.
I see. I'll try the ASM6?
----
MESEN might be best suitable if it means getting use of all the features that FCEUX and Nintendulator lacks.
----
In this case you can simply say SBC/CMP subtracts a number from another, but if you want to get technical, numbers are specified as operands in instructions. For example: in the instruction SBC #14, SBC is the operator (it performs an operation) and #14 is the operand (it's an argument needed by the operator).
Oooh. Might be little challenging to remember it. "Operator Code" as "Opcode". But not sure about operand meaning.
the quantity on which an operation is to be done. Isn't that what Value means? Or Variable? Like "Find the Value in Equations"? Value tricks me many times.
----
Somewhat true, but children are actually more smarter than what average adult thinks about them. It just needs to make it fun to learn how decimals work and pictures to help.
Post Reply