Free NES assembler

0. Contents

This is the documentation of nescom-1.1.5.1.
   1. Purpose
      1.1. History
   2. Linker
   3. Supported syntax
      3.1. Mnemonics
      3.2. Addressing modes
      3.3. Operand size control
      3.4. Expression evaluation
      3.5. Segments
      3.6. Comments
      3.7. Command separation
      3.8. Code pointer relocation
      3.9. Branch labels
      3.10. Preprocessor
      3.11. Object file format
      3.12. IPS output support
      3.13. Linkage selection
   4. Changelog
   5. Known bugs
   6. Copying
   7. Requirements
   8. Downloading

1. Purpose

This program reads symbolic 6502/RP2A03/RP2A07 machine code and compiles (assembles) it into a relocatable object file or into an IPS patch.

The produced object file is binary-compatible with those made with XA65.

1.1. History

This program was born when Bisqwit needed to have something for NES that is already accomplished for SNES by snescom.

2. Linker

This package also contains a linker.

The linker can also be used to convert IPS patches into binary files (an empty space is assumed to be the original file), with the following command: neslink input.ips -o result.bin -f raw

3. Supported syntax

3.1. Mnemonics

The following mnemonics are supported:

adc, and, asl, bcc, bcs, beq, bit, bmi, bne, bpl, brk, bvc, bvs, clc, cld, cli, clv, cmp, cpx, cpy, dec, dex, dey, eor, inc, inx, iny, jmp, jsr, lda, ldx, ldy, lsr, nop, ora, pha, php, pla, plp, rol, ror, rti, rts, sbc, sec, sed, sei, sta, stx, sty, tax, tay, tsx, txa, txs, tya

3.2. Addressing modes

All the standard addressing modes of the 6502 cpu are supported.

Syntax:
Name Examples Functionally equivalent to (not nescom syntax, provided for illustration only)
Implied: nop; clc
Immediate: lda #value etc a = value
Short relative: bcc end
Direct: lda $12 a = ram[$0012]
Direct indexed: lda $12,x
lda $12,y
a = ram[$0012 + x]
a = ram[$0012 + y]
Direct indexed indirect: lda ($12,x) a = ram[ramw[$0012 + x]]
Direct indirect indexed: lda ($12),y a = ram[ramw[$0012] + y]
Absolute: lda $1234 a = ram[$1234]
Absolute indexed: lda $1234,x
lda $1234,y
a = ram[$1234 + x]
a = ram[$1234 + y]
Absolute indirect: lda ($1234) a = ram[ramw[$1234]]
Note: "ram" and "ramw" in the table refer to generic address space access (RAM, I/O ports, ROM etc). "ramw" means 16-bit read access, but the meaning of "ram" depends on the context. It can be a read, write or a jump target, depending on instruction.

3.3. Operand size control

There are several operand prefixes that can be used to force a certain operand size/type.

3.4. Expression evaluation

Expressions are supported. These are valid code:

3.5. Segments

Code, labels and data can be generated to four segments: text, data, zero and bss.
Use .text, .data, .zero and .bss respectively to select the segment.
However, only the contents of text and data segments are saved into the o65 file. Labels are saved in all segments.

3.6. Comments

Comments begin with a semicolon (;) and end with a newline.
A colon is allowed to appear in comment.

3.7. Command separation

Commands are separated by newlines and colons (:).

3.8. Code pointer relocation

You can use a command like *= $F200 to change where the code goes by default.
With IPS this is especially useful.
You can change the code pointer as many times as you wish, but unless you're generating an IPS file, all code must be a continuous block.

3.9. Branch labels

The label - can be defined for local branches backward and + for branches forward.

3.10. Preprocessor

nescom uses GCC as a preprocessor.
You can use #ifdef, #ifndef, #define, #if, #endif and #include like in any C program. (See bugs)

3.11. Object file format

nescom produces relocatable object files (O65), non-relocatable patch files (IPS), or raw files.
The O65 file format has been documented by André Fachat for the XA65 project.

3.12. IPS output support

This version of nescom allows you to create IPS files.
This IPS format has been extended to allow you to specify global symbols and externs to be patched later.
In the generated format:

3.13. Linkage selection

By default, O65 objects are linked to any free location in the ROM.
IPS files are linked to predefined locations.

With the .link statement, you can change that.

.link page $3F declares that this object should be placed into page $3F.

.link group 1 declares that this object should be placed to the same page together with all other objects that want to be linked in group 1. This is useful when you want to ensure that certain tables or routines go to the same page, even if they are not in the same compilation unit.
The actual page is determined during link time, and you can get the page by using 24-bit (@) or segment reference (^) to a symbol from those modules.

This is not completely ready for NES yet.

4. Changelog

Nov 20 2005; 0.0.0 import from snescom-1.5.0.1.
Nov 29 2005; 0.1.0 bugfixes, now it's functional.
Dec 16 2005; 0.2.0 support for deeper "++" and "--" labels. Also support for .nop statement.
Jun 20 2006; 1.0.0 raw output file format support in nescom. Also using boost::smart_ptr.
Jul 26 2006; 1.1.0 has now a linker, and an example program.
Jul 27 2006; 1.1.1 adds some consistency to ROM and NES address space conversions.
Sep 21 2006; 1.1.2 adds clever_disasm and some documentation changes.
Oct 9 2006; 1.1.3 fixes a crash & memory leak bug.
May 13 2007; 1.1.3.1 fixes a bug regarding comments in #included files.
Oct 27 2007; 1.1.4 added some new features in clever-disasm, and example ini files.

5. Known bugs

6. Copying

nescom has been written by Joel Yliluoma, a.k.a. Bisqwit,
and is distributed under the terms of the General Public License (GPL).

If you happen to see this program useful for you, I'd appreciate if you tell me :) Perhaps it would motivate me to enhance the program.

7. Requirements

nescom uses GCC as a slave in the preprocessing phase. Therefore, gcc must be installed and found in the PATH when running nescom.

8. Downloading

The official home page of nescom is at http://iki.fi/bisqwit/source/nescom.html.
Check there for new versions.

Generated from progdesc.php (last updated: Wed, 30 Dec 2009 14:48:07 +0200)
with docmaker.php (last updated: Wed, 30 Dec 2009 14:48:07 +0200)
at Sun, 22 Aug 2010 04:46:41 +0300