Hello, new here, and need best recommandations.

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

Moderator: Moderators

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

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

Post by DocWaluigean » 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: 22054
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: 1086
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: 205
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: 11866
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: 205
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: 11866
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: 205
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: 22054
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: 205
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: 22054
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: 205
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."

User avatar
tokumaru
Posts: 11866
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 5:13 pm

All numbers are signed and unsigned at the same time. That may sound confusing, but the great thing about 2's complement is that all binary operations are correct for signed and unsigned values. The only difference is how YOU interpret the results and make decisions based on them.

$FF is 255 unsigned, or -1 signed, both at the same time. If you subtract 2 from it, the result is correct either way:

$FF - $02 = $FD
Unsigned: 255 - 2 = 253
Signed: -1 - 2 = -3

The answer is correct either way. The CPU uses the carry flag to signal unsigned overflows/underflows, and the V flag to signal signed overflows/underflows. Depending on what you need the numbers for, you'll use one flag or the other (or the N flag, which's also useful after signed operations) to make decisions.

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

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

Post by DocWaluigean » Wed Oct 03, 2018 5:25 pm

tokumaru wrote:All numbers are signed and unsigned at the same time. That may sound confusing, but the great thing about 2's complement is that all binary operations are correct for signed and unsigned values. The only difference is how YOU interpret the results and make decisions based on them.

$FF is 255 unsigned, or -1 signed, both at the same time. If you subtract 2 from it, the result is correct either way:

$FF - $02 = $FD
Unsigned: 255 - 2 = 253
Signed: -1 - 2 = -3

The answer is correct either way. The CPU uses the carry flag to signal unsigned overflows/underflows, and the V flag to signal signed overflows/underflows. Depending on what you need the numbers for, you'll use one flag or the other (or the N flag, which's also useful after signed operations) to make decisions.

The answer on this one? Or the answer about what I wrote earlier before the questioned about signed/unsigned numbers?

So it's like a mirror-mirror style of positive and negative where...............

255 is positive [unsigned]

and 1 is negative [signed]

-

251 is positive [unsigned]

and 5 is negative [signed]

-

190 is positive [unsigned]

and 64 is negative [signed]

255
-65
---
190


?????

I would see the pattern if that's correct..? Which is why BCC and BCS / BPL and BMI exists?

tepples
Posts: 22054
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 5:28 pm

In two's complement, 0 through 127 ($00 through $7F) are positive, and 128 through 255 ($80 through $FF) are treated as negative. They represent -128 through -1. All the positive numbers have bit 7 clear (0), and all the negative numbers have bit 7 set (1). This is why BPL (branch if plus) jumps if the last result had bit 7 clear, and BPL (branch if minus) jumps if the last result had bit 7 set.

BCC and BCS are used if you're comparing two unsigned numbers, and BPL and BMI are used if you're comparing two signed numbers. You also use BPL in a loop that counts down to 0 and stops once the index has passed zero:

Code: Select all

  ldy #4
loop:
  ; Y will equal 4, then 3, then 2, then 1, then 0.
  ; Do something with Y each time (omitted).

  ; Now count down: 4 becomes 3, 3 becomes 2, ..., 0 becomes -1
  dey
  ; If Y hasn't become negative, stay in the loop
  bpl loop

Post Reply