Page 1 of 1

Syntax Error: .ORG $7FF0

Posted: Tue May 16, 2017 9:38 pm
by opm_gamedev
So, I just began to program for the NES and am currently using xa65 on Raspberry Pi. My trouble, however, begins during assembly. Before I added the header, everything assemble just fine. But the newly generated file won't run in FCEUX, so I added the discount header seen in the source. Now, whenever I attempt to assemble my code it shoots me the following error :

Code: Select all

  .ORG $7FF0
Desktop/nes.s:line 1: 1000:Syntax error
  .org $8000
Desktop/nes.s:line 19: 1012:Syntax error
Break after 2 errors
The source code I am starting out with comes from the tutorial page:

Code: Select all

  .ORG $7FF0
header:
  .db "NES", $1a
  .db $00
  .db $00
  .db $02
  .db $00
  .db $00
  .db $00
  .db $00
  .db $00
  .db $00
  .db $00
  .db $00
  .db $00
  .db $00
  .db $00

  .org $8000
reset:
  lda #$01	; square 1
  sta $4015
  lda #$08	; period low
  sta $4002
  lda #$02	; period high
  sta $4003
  lda #$bf	; volume
  sta $4000
forever:
  jmp forever

Re: Syntax Error: .ORG $7FF0

Posted: Tue May 16, 2017 9:44 pm
by gauauu
Looking at the man page for xa65, it looks like it doesn't support the .org pseudo-op. You'll have to read the manual to figure out how to get your code to be located at a certain point. The .org pseudo-op tells the assembler where (at what memory address) to locate the next block of code. Different assemblers have different semantics for doing that, so a tutorial that works for one assembler won't work for another out of the box. (There's quite a bit of difference in 6502 assembly syntax, unlike some other languages that are more standardized.)

So you'll either have to study the manual for your assembler, or switch to a different assembler that better matches the tutorial code :-/

Re: Syntax Error: .ORG $7FF0

Posted: Tue May 16, 2017 10:03 pm
by tokumaru
It looks like xa65 doesn't have a direct replacement for .ORG, but you can change the value if the PC like this: * = $XXXX

Changing the PC afterwards won't cause any padding though, like .ORG would. Instead, you have to do the padding yourself, like this: .dsb $XXXX - *

Re: Syntax Error: .ORG $7FF0

Posted: Tue May 16, 2017 10:44 pm
by lidnariq
I wrote a bunch of trivial NES ROMs using XA65; debian even includes one (i.e. "apt-get source efp" - this is not mine)

Re: Syntax Error: .ORG $7FF0

Posted: Wed May 17, 2017 12:43 am
by Myask
tokumaru wrote:It looks like xa65 doesn't have a direct replacement for .ORG, but you can change the value if the PC like this: * = $XXXX

Changing the PC afterwards won't cause any padding though, like .ORG would. Instead, you have to do the padding yourself, like this: .dsb $XXXX - *
Does .dsb with 0 bytewidth throw an error?

Re: Syntax Error: .ORG $7FF0

Posted: Wed May 17, 2017 7:04 am
by tokumaru
I have no idea, but if you run into a case where you need a bytewidth of 0, just don't use the command at all.

Re: Syntax Error: .ORG $7FF0

Posted: Wed May 17, 2017 7:20 am
by tepples
Automating the decision to use or not use the command, depending on the size of preceding data, would look like the following (pseudocode, untested):

Code: Select all

.if * < $XXXX
  .dsb $XXXX - *
.endif
Not having studied xa65's error reporting commands, I don't know how to ensure failure if preceding data is too large. In ca65, one might use .assert.

Re: Syntax Error: .ORG $7FF0

Posted: Wed May 17, 2017 9:59 am
by opm_gamedev
lidnariq wrote:I wrote a bunch of trivial NES ROMs using XA65; debian even includes one (i.e. "apt-get source efp" - this is not mine)
That's very helpful, actually. That way I can see the proper pseudo-Ops. If only I wasn't at work, I am itching to check it out.
gauauu wrote: Looking at the man page for xa65, it looks like it doesn't support the .org pseudo-op. You'll have to read the manual to figure out how to get your code to be located at a certain point. The .org pseudo-op tells the assembler where (at what memory address) to locate the next block of code. Different assemblers have different semantics for doing that, so a tutorial that works for one assembler won't work for another out of the box. (There's quite a bit of difference in 6502 assembly syntax, unlike some other languages that are more standardized.)

So you'll either have to study the manual for your assembler, or switch to a different assembler that better matches the tutorial code :-/
Good thing I am still fairly green when it comes to programming anything. I don't have any bad habits as of yet that I've become particularly attached to. It's just getting to where I can at least make something rudimentary happen at all. Unfortunately, there isn't an armhf port of any other assembler available on the Raspbian repositories, and I'm not quite comfortable compiling source. That being said, given the limitations, I'll definitely study the XA65 man pages a bit more. Thank you guys for all the good advice. It makes this journey that much less intimidating.

Re: Syntax Error: .ORG $7FF0

Posted: Wed May 17, 2017 10:24 am
by tepples
opm_gamedev wrote:I'm not quite comfortable compiling source.
I've tried to provide instructions here and here.

You mentioned using an operating system based on Debian. So do I. First install dependencies:

Code: Select all

sudo apt-get install build-essential python3-pil git
build-essential is GCC, Binutils, Make, and other parts required for building C or C++ programs from source.
python3-pil is Pillow (Python Imaging Library), which lets a PNG-to-CHR converter written in Python read the PNG image files you pass to it.
git is a version control system, used (among other things) to download source code with its full revision history.

Then build and install cc65, and tell me the first thing you don't understand:

Code: Select all

mkdir -p ~/develop
cd ~/develop
git clone https://github.com/cc65/cc65.git
cd cc65
make
make install prefix=~/.local
which cc65

Re: Syntax Error: .ORG $7FF0

Posted: Fri May 19, 2017 9:24 am
by opm_gamedev
tepples wrote: Then build and install cc65, and tell me the first thing you don't understand:
The first thing I don't understand at this point is: "where do I go from here?"
I entered the commands to execute both CC65 and CA65, with the CLI returning a message that neither command exists. Even after following the instructions to the letter.

I did take note as the CLI spit out file names during source compilation that among C files were a bunch of Assembler files. This caused concern. Even though I am running a Debian derivative, I am doing so on an ARMv8 CPU. So, if the source code I compiled was written for x86, I wouldn't be able to run the software. Hopefully, this is not the case. Especially, if CA65 is the more commonly used Assembler.

Re: Syntax Error: .ORG $7FF0

Posted: Fri May 19, 2017 9:39 am
by opm_gamedev
tokumaru wrote:It looks like xa65 doesn't have a direct replacement for .ORG, but you can change the value if the PC like this: * = $XXXX

Changing the PC afterwards won't cause any padding though, like .ORG would. Instead, you have to do the padding yourself, like this: .dsb $XXXX - *
Three Questions:
  • 1. So, I would write the code * = $XXXX exactly?
    2. How would I determine the proper padding size?
    3. Is this mandatory?

Re: Syntax Error: .ORG $7FF0

Posted: Fri May 19, 2017 9:43 am
by tepples
Now that cc65 is built and installed, you need to set your PATH to include executables installed for the current user.

The .bashrc file is a shell script that Bash runs when it starts. Among other things, it's used to set up the PATH, the list of folders where the shell looks for programs to run. By default, the shell doesn't include any folder in your home directory in this list, so you'll need to add it.

Code: Select all

mousepad ~/.bashrc
Put this at the bottom:

Code: Select all

if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi
Translated into English: "If a folder called .local/bin exists inside your home directory, add it to the PATH."

Then log out and back in, and make sure the change to the PATH took:

Code: Select all

which cc65
The which command is a quick way to search the PATH without actually running anything.
I did take note as the CLI spit out file names during source compilation that among C files were a bunch of Assembler files.
These are in 6502 assembly language, not x86, x86-64, or ARM assembly language. They make up part of the standard library that gets included in the executable when you build a program written in C.