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

User avatar
Banshaku
Posts: 2328
Joined: Tue Jun 24, 2008 8:38 pm
Location: Fukuoka, Japan
Contact:

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

Post by Banshaku » Sun Sep 30, 2018 8:15 pm

No problem ;) If you want to use 6502 asm only it's fine too. What I just meant is C could have been easier if you just want to make a game.

When you know enough 6502 you can try to use your 6502 with some C and that will be quite interesting to do! Knowing how 6502 and nes work is quite useful when you do C code so what you are learning is not wasted: it will be used later.

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

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

Post by DocWaluigean » Sun Sep 30, 2018 8:26 pm

Kasumi wrote:Help me help you. What specifically don't you understand about the concepts? Assume whenever I make a post, I feel I have already made it as simple and clear as I can.

So telling me the explanation is complicated is not really feedback I can use beyond trying to explain some different way which may not target the part you don't understand. If I reexplain addressing modes (which I've done in the the rest of the post), but your issue is with looping then no one has won. You've got to be specific about the issues you're having or I have to guess.

In the ,x addressing mode. X is treated as a number. The 16 bit address before the ,x (not the value stored in that address) is treated as a number. These two numbers are added together to get a new number. This new number is the address that gets used.

In LDA, the value from the new address is copied to A.
In STA, the value in A is stored to the new address.

Edit: To help you help me, with the descriptions above, look at the code examples. The behavior exactly matches. Which of the steps from which example gives you a result you do not fully understand? Walk through each step of what should happen. (X is added to the address. So the result in the example should be this.) And stop whenever your result following the steps is different than what I said the result should be. And then I'll try to explain that difference.

Edit2: Assuming the paintbrush error you described was in your last piece of code. Above the "TOPHAT1" label, you initialize X to 31. Then you use dex and bne in a loop together. This loops 31 times, because to get below the bne, X must be zero.

Above the "HATLOOP" label, you do not initialize X. This means it is still zero from after the TOPHAT1 loop. You still use dex and bne in a loop together. This loops 256 times, because to get below the bne, X must be zero.

It starts at 0. 1 is subtracted to get 255. 255 is not equal to zero, so it loops.
Then 254, etc.
-The Register limits added:

A : You CANNOT use Register A for absolute effect! [Only X and Y can do it.]
A : You CANNOT INCrement A directly!
A : ??????????

---

Code: Select all

lda #$0F
sta $0200
lda #$02
sta $0201
lda #$08
sta $0202

ldx #1
lda $0200,x;A now holds the value 2. $0200+X (which holds 1) is $0201. Inside $0201 is #$02
inx;Now X = 2
lda $0200,x;A now holds the value 8. $0200+X (which holds 2) is $0202. Inside $0201 is #$08

-The Absolute Effect [Or The "Compass-Comma" I made it up] is making certain codes that can potentially make it get treated like a file cabinet? The numbers in STA 200/1/2 is treated as a file cabinet, and when you did LDA 200,X which is 1, you "basically pull out the file cabinet box, and take the numbers that's stored into Address Code $0201, which is 2." And that result, Register A is now holding number 2?

-So yeah... it feels more of "Cabinet Comma" over "Compass-Comma" which is somewhat like go-to codings.. or the "Compass-Comma" is actually the BNE/BEQ...?

- I'm guessing I have to nickname each code name to make it easier. BNE would be, "Begone, No-Equations!" [Meaning if it's number zero, it will "GO TO" the labels needed or loop back to the beignning of code / beginning of where label is, otherwise if it's OTHER than zero, it will pass like a door.]

-BEQ would be, "Begone, Equated Quell!" [Meaning if it's any number that is not zero, it will "GO TO" to the labels needed or go back to the beginning of code / beginning of where label is. Otherwise, it will go through or pass like a door.]

The quell is, ironically, synonym of "contain" which is the best word for making it easier I guess. I'm also guessinf Equated is the same similar word of "Equations"???

=====

Way shorter, yes? And to briefly explain this one. Imagine you want to draw a 2 pixel line.
You'd load X with 1. After a single dex, there wouldn't be a branch and you've only drawn one pixel. So you draw the next one after the loop. If you had loaded X with 2, it would take two dex before the branches would stop. ETC.

Your assignment this time is to convert ALL horizontal lines in your old face code to loops like this.


Re-reading it again, Oooooh. Just horizontal [at least most-horizontal lines] line of the code, not the entire thing... I hope this doesn't demotivate me if I didn't understand it.

But you see what I mean about names with BNE and BEQ. [[Come to think of it, I'm finally starting to recognize BNE or BEQ since I made up names. Every teacher should know this for elementary school if they keep asking to teach programming at young ages..]]
Last edited by DocWaluigean on Sun Sep 30, 2018 9:03 pm, edited 2 times in total.

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

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

Post by DocWaluigean » Sun Sep 30, 2018 8:29 pm

Banshaku wrote:No problem ;) If you want to use 6502 asm only it's fine too. What I just meant is C could have been easier if you just want to make a game.

When you know enough 6502 you can try to use your 6502 with some C and that will be quite interesting to do! Knowing how 6502 and nes work is quite useful when you do C code so what you are learning is not wasted: it will be used later.
The C++/C#/C and 6502 hybrid would be the MOST amazing thing ever! ^^ But I don't know how yet sadly. Also, I seen far more than potentials to just use 6502 for games, so...yes?

If I want to make a game, I would use Game-Maker, Unreal / Unity, etc. And coding would be wayyy longer for me to learn C++ / C# / C if I'm going that road atm.

I don't know if I'm explaining right. It's a curse of mentalities. T-T But it would give insight if I know the differences of C / C++ / C# [Even though it's off-topic. but not sure how implemented and similarities it can be to put 6502 code languages into those.]

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

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

Post by DocWaluigean » Tue Oct 02, 2018 7:16 pm

I don't know why no responses on other things that could help give insights; a lot of teachers in the past is willing to answer different questions that could help out students more. Being there for students even most ridiculous questions [at least in topic] raises confidences, curiosity, and trust....

But nvm. Here.

Code: Select all

lda #$04
ldx #$1F
toplineloop:
sta $0200,x
dex
bne toplineloop
sta $0200

;===

sta $0220 ; Hat Vertically [Up/Down]
sta $023F
sta $0240
sta $025F
sta $0260
sta $027F
sta $0280
sta $029F
sta $02A0
sta $02BF
sta $02C0
sta $02DF
sta $02E0
sta $02FF
sta $0300
sta $031F
sta $0320
sta $033F
sta $0340
sta $035F
sta $0360
sta $037F
sta $0380
sta $039F

;==========

sta $03A0
sta $03A1
sta $03A2
sta $03A3
sta $03A4
sta $03A5
sta $03A6
sta $03BF
sta $03BE
sta $03BD
sta $03BC
sta $03BB
sta $03BA
sta $03B9

;=========

sta $0398
sta $0397
sta $0396
sta $0395
sta $0394
sta $0387
sta $0388
sta $0389
sta $038A
sta $038B

;=========

sta $0370
sta $0371
sta $0372
sta $0373
sta $036F
sta $036E
sta $036D
sta $036C

;========

ldx #$0D ; Eye Color Light Green Left
stx $038C
stx $03AC
stx $03CC
stx $03EC

ldy #$0E ; Eye Color Light Blue Right

sty $0393
sty $03B3
sty $03D3
sty $03F3

;========

lda #$01 ; Lip color White
sta $04AA
sta $04CB
sta $04CC
sta $04CD
sta $04CE
sta $04CF
sta $04D0
sta $04D1
sta $04D2
sta $04D3
sta $04D4
sta $04B5

;---
lda #$08

sta $03C0
sta $03DF
sta $03E0
sta $03FF
sta $0400
sta $041F
sta $0420
sta $043F
sta $0440
sta $045F
sta $0460
sta $047F
sta $0480
sta $049F
sta $04A0
sta $04BF
sta $04C0
sta $04DF
sta $04E0
sta $04FF
sta $0500
sta $051F
sta $0520
sta $053F
sta $0540
sta $055F
sta $0560
sta $057F
sta $0580
sta $059F
sta $05A0
sta $05BF
sta $05C0
sta $05DF



;***********************

LDX #$E0

bottomlineloop:
sta $05DF,x
dex
bne bottomlineloop
Here's the problem; I don't know how It supposed to work with the number from, "IF 0, GOTO LABEL" style. At this knowledge, there is no, "IF #==#, GOTO LABEL" style. When I tried the zero, it painted a lot of things until the X = 0. The only thing I got it good is on the last part of coding.

tepples
Posts: 21752
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

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

Post by tepples » Wed Oct 03, 2018 6:30 am

For "if # == #, go to label", use "if # - # == 0, go to label". This is what the cmp instruction is for: it performs a subtraction and sets NZC flags appropriately, but it doesn't write the full results back to A.


EDIT: I appear to have been mistaken about the V flag. Corrected.

unregistered
Posts: 1038
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

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

Post by unregistered » Wed Oct 03, 2018 10:12 am

Expanding tepples' cmp explanation:

Let's say you want to branch somewhere if Happy == 255. You might use:

Code: Select all

lda Happy
cmp #255
beq somewhere

...

somewhere:
Though, for me, it's usually much better to change that branch to "bne +" and place the code you want run directly afterward. That way the branch is taken unless Happy == 255 and so the strived for code only runs if Happy == 255 (and if you place the + after that code).

To make it crystal clear: cmp never affects a's value. It only does the subtraction and affects the NZC flags accordingly (at least those are the flags listed in the first edition of MOS Technology's Programming Manual's Appendix B... probably another mistake... why wouldn't cmp affect the V flag too? tepples is trustworthy :)). cmp can be used, followed by whatever branch you choose, and you can still use a's value following those instructions as if they weren't there. No need to take time and space afterward by loading the same value into the accumulator. :)

cpx and cpy work exactly as cmp works; except, replace both "a"s in the preceeding paragraph with "x" or "y". :) edit: and, this is probably obvious, but also replace "the accumulator" with "index x" or "index y".

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

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

Post by DocWaluigean » Wed Oct 03, 2018 11:24 am

unregistered wrote:Expanding tepples' cmp explanation:

Let's say you want to branch somewhere if Happy == 255. You might use:

Code: Select all

lda Happy
cmp #255
beq somewhere

...

somewhere:
Though, for me, it's usually much better to change that branch to "bne +" and place the code you want run directly afterward. That way the branch is taken unless Happy == 255 and so the strived for code only runs if Happy == 255 (and if you place the + after that code).

To make it crystal clear: cmp never affects a's value. It only does the subtraction and affects the NZC flags accordingly (at least those are the flags listed in the first edition of MOS Technology's Programming Manual's Appendix B... probably another mistake... why wouldn't cmp affect the V flag too? tepples is trustworthy :)). cmp can be used, followed by whatever branch you choose, and you can still use a's value following those instructions as if they weren't there. No need to take time and space afterward by loading the same value into the accumulator. :)

cpx and cpy work exactly as cmp works; except, replace both "a"s in the preceeding paragraph with "x" or "y". :) edit: and, this is probably obvious, but also replace "the accumulator" with "index x" or "index y".
THIS looks interesting.

So CMP is used to make "N = 100" stuff? or it's used as "number-alternated" BEQ / BNE? I was about to write code examples, but I got confused a liittle.

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

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

Post by tokumaru » Wed Oct 03, 2018 11:49 am

CMP compares two values, modifying the CPU flags accordingly, and you can use that information to make decisions in you program (branch or not branch based on the state of the different flags).

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

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

Post by DocWaluigean » Wed Oct 03, 2018 1:09 pm

tokumaru wrote:CMP compares two values, modifying the CPU flags accordingly, and you can use that information to make decisions in you program (branch or not branch based on the state of the different flags).
I'm going to have to figure out ways to make drawings of it so it would be easier to understand....

So CMP is a flag-modifier code that "tricks" it into thinking it's a zero flag or N flag?

Code: Select all


[[[Happy == 255 ]]]

lda Happy
cmp #255
beq somewhere
So for this code examples, "Usually, BEQ means we don't allow any number BUT zero to pass through. Buuut since you have the CMP permission, you [255] may pass to the label 'somewhere'."

Is this correct?

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

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

Post by tokumaru » Wed Oct 03, 2018 1:16 pm

Sounds correct.

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

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

Post by DocWaluigean » Wed Oct 03, 2018 2:44 pm

tokumaru wrote:Sounds correct.
:shock: REALLY?! ...THAT SIMPLE ANSWER?!...

......??!

Anyway, so this gets the opposite if it were BNE, correct? or BNE is not compatible with CMP? What else is CMP not compatible or is compatible?

tepples
Posts: 21752
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

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

Post by tepples » Wed Oct 03, 2018 3:25 pm

Consider the following instructions:

Code: Select all

lda firstVar
cmp secondVar
b?? somewhereElse
The cmp instruction sets up the flags such that the following instructions (which replace b?? above) do the following:

For bcc (branch if carry clear): Jump if the value at address firstVar is less than the value at secondVar as an unsigned number
For bcs (branch if carry set): Jump if the value at address firstVar is greater than or equal to the value at secondVar as an unsigned number
For bne (branch if not equal): Jump if the value at address firstVar is not equal to the value at secondVar
For beq (branch if not equal): Jump if the value at address firstVar is not equal to the value at secondVar
For bpl (branch if plus): Jump if the value at address firstVar is greater than or equal to the value at secondVar as a signed number
For bmi (branch if minus): Jump if the value at address firstVar is less than the value at secondVar as a signed number

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

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

Post by DocWaluigean » Wed Oct 03, 2018 3:39 pm

tepples wrote:Consider the following instructions:

Code: Select all

lda firstVar
cmp secondVar
b?? somewhereElse
The cmp instruction sets up the flags such that the following instructions (which replace b?? above) do the following:

For bcc (branch if carry clear): Jump if the value at address firstVar is less than the value at secondVar as an unsigned number
For bcs (branch if carry set): Jump if the value at address firstVar is greater than or equal to the value at secondVar as an unsigned number
For bne (branch if not equal): Jump if the value at address firstVar is not equal to the value at secondVar
For beq (branch if not equal): Jump if the value at address firstVar is not equal to the value at secondVar
For bpl (branch if plus): Jump if the value at address firstVar is greater than or equal to the value at secondVar as a signed number
For bmi (branch if minus): Jump if the value at address firstVar is less than the value at secondVar as a signed number
So... :?: :

BCC : V1 < V2 = teleport / GOTO
BCS : V1 >= V2 = teleport / GOTO
BNE : V1 != V2 = teleport / GOTO
BEQ : V1 == V2 = teleport / GOTO
BPL : V1 >= V2 = teleport / GOTO
BMI : V1 < Vs = teleport / GOTO

and WITHOUT using CMP:

BCC: ?????
BCS: ?????
BNE: 0 = teleport / GOTO : 1-255 = Passage / IGNORE [A wall on numbers, a door on zero.]
BEQ: 1-255 = teleport / GOTO : 0 = Passage / IGNORE [A door on numbers, a wall on zero.]
BPL: ?????
BMI: ????? ;[Hilariously, absolutely nothing to do with weight and obese measurement.]

I also noticed a "signed" number... don't you mean "a selected number that's RIGHT NOW being used in Register A / X / Y, or just A." ?

[I strangely didn't get replied if I am right about the one above or not...]
Last edited by DocWaluigean on Wed Oct 03, 2018 4:37 pm, edited 1 time in total.

tepples
Posts: 21752
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

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

Post by tepples » Wed Oct 03, 2018 3:52 pm

"Signed" means "a number that can be either positive or negative, when interpreted in two's complement".

Two's complement is a way of representing negative numbers by adding 256 ($100). For example, 255 ($FF) means -1, 254 ($FE) means -2, 253 ($FD) means -3, etc. This works because addition and subtraction in the 6502 are modulo 256. To represent -4, you use 252 ($FC) which is 256 - 4. Then 252 plus 5 equals 257 which in turn equals 1, which is -4 plus 5.

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

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

Post by DocWaluigean » Wed Oct 03, 2018 4:28 pm

tepples wrote:"Signed" means "a number that can be either positive or negative, when interpreted in two's complement".

Two's complement is a way of representing negative numbers by adding 256 ($100). For example, 255 ($FF) means -1, 254 ($FE) means -2, 253 ($FD) means -3, etc. This works because addition and subtraction in the 6502 are modulo 256. To represent -4, you use 252 ($FC) which is 256 - 4. Then 252 plus 5 equals 257 which in turn equals 1, which is -4 plus 5.
So this has to do with the N flag, the one Kasumi mentioned?

So how do I make it signed...?

EDIT: This looks very annoying for people who is tired of my questions... I understood, but... without questions, we'd be more less mindful on things than before if everyone asked so many questions.

I know I repeated what I said before. "The worst questions is question that's never asked."

Post Reply