Page 1 of 1
NESASM -> ASM6
Posted: Mon Mar 22, 2010 7:17 am
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
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!
Re: NESASM -> ASM6
Posted: Mon Mar 22, 2010 7:34 am
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.
Re: NESASM -> ASM6
Posted: Mon Mar 22, 2010 9:27 am
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.
Re: NESASM -> ASM6
Posted: Mon Mar 22, 2010 10:10 am
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?
Posted: Mon Mar 22, 2010 10:25 am
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.
Posted: Mon Mar 22, 2010 10:28 am
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).
Posted: Mon Mar 22, 2010 10:53 am
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:
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?
Posted: Mon Mar 22, 2010 11:20 am
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.
Posted: Mon Mar 22, 2010 11:45 am
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.
Posted: Mon Mar 22, 2010 2:18 pm
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?

Posted: Mon Mar 22, 2010 2:38 pm
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:
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:
Posted: Mon Mar 22, 2010 3:07 pm
by Ypsilon
Ok! Thanks!!