NESASM -> ASM6

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

Moderator: Moderators

Post Reply
User avatar
Ypsilon
Posts: 11
Joined: Sun Mar 21, 2010 3:35 pm

NESASM -> ASM6

Post by Ypsilon »

Hello everyone.

I started a little time ago with NES programming, and I was using Nesasm. But I have discovered that it doesn't work properly, for example with .DB's (it doesn't initialize the variables with the value).

So I'm going to start using asm6, and I have to make some changes with my code. I've been learning at first with the GBAguy tutorial and everything seemed to work OK with nesasm, but then, when I try to compile with asm6, it tells me that the program counter is out of reach. I .orged the variables at $0000 and the code at $8000, so I guess it has something to do with that (maybe I can't work with variables which are that far in the code?)

Another thing that I think I'll have to change are the .ines directives. I have seen a post (ASM6 templates) that seem to solve that, but I need a solution for the variables thing :P

As I've read, it seems that the GBAguy tutorial is not very accurate, am I right? Could someone tell me why? As I've taken things from it, I am probably making a lot of things wrong.

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

Re: NESASM -> ASM6

Post by tepples »

Ypsilon wrote:As I've read, it seems that the GBAguy tutorial is not very accurate, am I right? Could someone tell me why?
See Myths#Old tutorials.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: NESASM -> ASM6

Post by tokumaru »

Ypsilon wrote:But I have discovered that it doesn't work properly, for example with .DB's (it doesn't initialize the variables with the value).
No assembler will initialize variables for you. They reserve the memory locations, but it's up to you to put something meaningful at those locations.
User avatar
Ypsilon
Posts: 11
Joined: Sun Mar 21, 2010 3:35 pm

Re: NESASM -> ASM6

Post by Ypsilon »

tokumaru wrote:
Ypsilon wrote:But I have discovered that it doesn't work properly, for example with .DB's (it doesn't initialize the variables with the value).
No assembler will initialize variables for you. They reserve the memory locations, but it's up to you to put something meaningful at those locations.
I'm talking about, for example:

sp1X .DB $50

Wouldn't that reserve a byte and initialize it with 50h?
User avatar
MottZilla
Posts: 2835
Joined: Wed Dec 06, 2006 8:18 pm

Post by MottZilla »

No. Unlike C and other languages you can't initialize variables, only declare them. To initialize them you must do that in your code. That's what he just said.
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

In fact that would work for machines where the code is run in RAM, such as the FDS, the C64, etc... Where the BIOS copy your code to RAM.

But not the NES, as variables are in (uninitialized) RAM and code in ROM (code can also be in RAM, but you'll have to initialize it yourself).
Useless, lumbering half-wits don't scare us.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

You can put initialized variables in the "DATA" segment, as long as your init code copies DATA from its load address to its run address. For example, the init code for C programs compiled with cc65 and linked with its platform support library does exactly this.

But then I tend not to use init code to initialize variables to anything but zero. A guideline published by the Free Software Foundation recommends the same thing for C programs:
In [url=http://www.gnu.org/prep/standards/html_node/Semantics.html#Semantics]GNU Coding Standards: Writing Robust Programs[/url], FSF wrote:When static storage is to be written in during program execution, use explicit C code to initialize it. Reserve C initialized declarations for data that will not be changed.
This guideline produces an "RODATA" segment with const declarations, an empty "DATA" segment, and a "BSS" (zeroed) segment for module- or function-scope variables.

When the player presses reset on an FDS, is anything reloaded?
User avatar
MottZilla
Posts: 2835
Joined: Wed Dec 06, 2006 8:18 pm

Post by MottZilla »

It depends on the game. Sometimes pressing reset causing the BIOS to restart entirely. Other times you will have the FDS program in control still after reset.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Either way, the DATA segment doesn't automatically get reloaded unless the user backs out to the FDS menu. The code/rodata/data/bss segment scheme used in cc65 and elsewhere is based on C and POSIX semantics, which to my knowledge don't have a "reset button" action.
User avatar
Ypsilon
Posts: 11
Joined: Sun Mar 21, 2010 3:35 pm

Post by Ypsilon »

Okey so, from what I think I have understood, you need to initialize all the variables from the code, even the constants. Am I right? :oops:
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Constants don't use any RAM, how would you initialize them? While variables are symbols that represent memory locations, constants are just symbols representing numbers that don't change, and such symbols can be created by the assembler just fine.

Constants are usually defined like this:

Code: Select all

MAX_LIVES = 9
And used like this:

Code: Select all

	;increment the number of lives if it didn't reach the maximum
	lda #MAX_LIVES
	cmp Lives
	beq Skip
	inc Lives
skip:
User avatar
Ypsilon
Posts: 11
Joined: Sun Mar 21, 2010 3:35 pm

Post by Ypsilon »

Ok! Thanks!!
Post Reply