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 »

tepples wrote:In two's complement, 0-127 are positive, and 128-255 are treated as negative. They represent -128 through -1.
.......

But that's single.. what about what tokumaru wrote about that they're signed and unsigned at same time?

So in Tokumaru part, it's a mirror of positive and negative of +255 and -1, and it can go down into +3 and -253.

And in your part, it's two parts where 0-127 is positive lever, and 128-255 is negative lever, also known as -1 and -128..?

[Obviously[[?]], zero is a positive number.]
tepples
Posts: 22705
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 »

The number $C0 can represent 192, or it can represent -64. The 6502 itself couldn't give a care. In practice, it depends on the context of the code around it. As an assembly language programmer, you are responsible for imbuing numbers with semantics, defining what each value means in context.

Zero is traditionally neither negative nor positive. But the BPL and BMI branches treat a zero result as nonnegative, as if it were positive. To treat zero differently from positive numbers proper, you'll need to use both a BNE or BEQ and a BPL or BMI. You'll need to do this, for example, to distinguish a stopped character from one moving to the right.
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

tepples wrote:The number $C0 can represent 192, or it can represent -64. The 6502 itself couldn't give a care. In practice, it depends on the context of the code around it. As an assembly language programmer, you are responsible for imbuing numbers with semantics, defining what each value means in context.

Zero is traditionally neither negative or positive. But the BPL and BMI branches treat a zero result as nonnegative, as if it were positive. To treat zero differently from positive numbers proper, you'll need to use both a BNE or BEQ and a BPL or BMI.
So there's an opcode where it let me define a numbers in favor for "Mirror-+" or "half -+" styles? Or what does 6502, in form if NES, support only?
tepples
Posts: 22705
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 »

If you write lda #<-10, ca65 will treat that as a two's complement number and translate it into lda #246.
  1. The # means that lda will load an immediate value, as opposed to reading from a memory address.
  2. The < means "keep the low byte". An assembler on a 32-bit platform, such as a PC, will internally process all values as 32-bit values. In 32-bit two's complement, -10 is $FFFFFFF6, and the < operator tells the assembler to cut the value down to 8-bit.
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

tepples wrote:If you write lda #<-10, ca65 will treat that as a two's complement number and translate it into lda #246.
  1. The # means that lda will load an immediate value, as opposed to reading from a memory address.
  2. The < means "keep the low byte". An assembler on a 32-bit platform, such as a PC, will internally process all values as 32-bit values. In 32-bit two's complement, -10 is $FFFFFFF6, and the < operator tells the assembler to cut the value down to 8-bit.
...ca65 is part of Colecovision that Unregistered is part of, or the 6502?..

I'm starting to get confused on how it works, with your answer and Tokumaru answer.
tepples
Posts: 22705
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 »

ca65 is a 6502 assembler. It has nothing to do with Coleco.
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

But what about the NESASM6 part? Or ca65 better choice?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

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

Post by tokumaru »

There's no "NESASM6"... There's NESASM and ASM6, two separate assemblers. NESASM and ASM6 are much more newbie friendly, but ca65 has more features than both combined. Because NESASM has some weird quirks, I usually suggest ASM6 to beginners.

Keep in mind that any of them can be used to make any kind of NES game, the difference is that ca65 has some features that make larger projects easier to manage, if you know how to use said features.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

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

Post by unregistered »

Note: I can't be part of Colecovision; I've never even touched a Colecovision. :lol:
DocWaluigean wrote:
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]

-
Note: we will deal with #255 as the hardware (the 6502) sees it... in binary: #11111111b
11111111 is positive [unsigned]

and 11111111 is negative [signed]

because, like tepples said, bit7 is set and so the "signed" way of using 11111111 makes that represent a negative number (-1).

You can experiment with Windows 10's Calculator to better understand signed and unsigned. Open Calculator, click the three horizontal lines in the upper left, click "Programmer's Mode". Click on the QWORD until it reads BYTE. Click on BIN. Type or click 11111111. Notice that the signed decimal value, next to DEC, reads -1. Now click BYTE again and it will goto QWORD. Then click the C to clear the calculator. Next type or click 11111111 again. Now the value next to DEC will read 255 (that's the unsigned version of #11111111b).

Windows 10's Calculator's Programmer's Mode always switches the decimal version (next to DEC) to signed when the left most bit of the value is set. Have to go... sorry.
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

tokumaru wrote:There's no "NESASM6"... There's NESASM and ASM6, two separate assemblers. NESASM and ASM6 are much more newbie friendly, but ca65 has more features than both combined. Because NESASM has some weird quirks, I usually suggest ASM6 to beginners.

Keep in mind that any of them can be used to make any kind of NES game, the difference is that ca65 has some features that make larger projects easier to manage, if you know how to use said features.
Ooooh. What features does ca65 have that ASM6 doesn't?
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

unregistered wrote:Note: I can't be part of Colecovision; I've never even touched a Colecovision. :lol:
DocWaluigean wrote:
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]

-
Note: we will deal with #255 as the hardware (the 6502) sees it... in binary: #11111111b
11111111 is positive [unsigned]

and 11111111 is negative [signed]

because, like tepples said, bit7 is set and so the "signed" way of using 11111111 makes that represent a negative number (-1).

You can experiment with Windows 10's Calculator to better understand signed and unsigned. Open Calculator, click the three horizontal lines in the upper left, click "Programmer's Mode". Click on the QWORD until it reads BYTE. Click on BIN. Type or click 11111111. Notice that the signed decimal value, next to DEC, reads -1. Now click BYTE again and it will goto QWORD. Then click the C to clear the calculator. Next type or click 11111111 again. Now the value next to DEC will read 255 (that's the unsigned version of #11111111b).

Windows 10's Calculator's Programmer's Mode always switches the decimal version (next to DEC) to signed when the left most bit of the value is set. Have to go... sorry.
It's alright.. I'm a little confused though.

So...

00000000 is unsigned

00100000 is unsigned

01000000 is signed

10000000 is signed

11000000 is signed

11010101 is signed

Is this what it means?...
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

I got to ask even extremely ridiculous question even if there's chance I got right or not so I can find and understand in the most simplest or elementary explanation even toddler can understand. Just a reminder if I said this before?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

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

Post by tokumaru »

DocWaluigean wrote:What features does ca65 have that ASM6 doesn't?
A more robust macro system that allows you to automate repetitive tasks, more advanced memory management that allows you to fill ROM and RAM non-linearly (i.e. source code organized by context), modular assembly (you can assemble parts of your program separately and combine them later), and so on.

Most of these are things you don't know you need when you're starting out, but as your programs grow more complex, you start to wish there were better ways to organize the source code and keep everything easy to maintain, and that's when you realize that ca65 can help you.
DocWaluigean
Posts: 205
Joined: Sun Jun 17, 2018 6:41 pm

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

Post by DocWaluigean »

tokumaru wrote:
DocWaluigean wrote:What features does ca65 have that ASM6 doesn't?
A more robust macro system that allows you to automate repetitive tasks, more advanced memory management that allows you to fill ROM and RAM non-linearly (i.e. source code organized by context), modular assembly (you can assemble parts of your program separately and combine them later), and so on.

Most of these are things you don't know you need when you're starting out, but as your programs grow more complex, you start to wish there were better ways to organize the source code and keep everything easy to maintain, and that's when you realize that ca65 can help you.
It sounds like something I'd do if I was in charge of NESMaker but for free.

Ah. But unfortunately it's all in CMD right?
tepples
Posts: 22705
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 »

The 8-bit value itself isn't signed or unsigned. The context is signed or unsigned, and the value has an interpretation within that context.

In an unsigned context:

%00000101 means 5
%11111011 means 251

The same 8-bit values in a signed context:

%00000101 means 5
%11111011 means -5

The context is distinguished implicitly by what instructions occur around them, such as what thresholds are used in CMP, which branch instructions, and the like. There's no "unsigned mode" or "signed mode" that you have to put the processor into, the way there are "8-bit mode" and "16-bit mode" on a different CPU.

If you need a mouse-driven front-end to ca65, as opposed to something that works from command prompts, batch files, and makefiles, you could try NESICIDE.
Post Reply