
 asm6502.txt
  An ANSI C 6502 assembler that recognizes "illegal" instructions

  Default CPU = 6510.

---- New in 2026.04.12:

 Added data overwrite warning.
 Added "main" proc keyword.
 Added big endian option for DCW/DCL.
 Correct order of operations (pemdas).
 Added support for .shl (<<) and .shr (>>).
 Added .paramtype().


==== Supported Directives

	.accu
		set accumulator operand size - only 8 supported
	.advance, org, orga
		set ORG position (orga = within same bank)
	alias <name> <value>
		define an equate
	align <size>
		positive value to align ORG
	.ascii
		raw text parameter(s)
	bank (set bank)
		index
	block, res, space
		define a block space (unfilled), adding to position
	byt, byte
		raw 8-bit integers (warning if outside [-$80,$FF])
	db, dcb, dc.b
		8-bit bytes and/or comma-separated string parameters
	checkpc <position>
		check to see if ORG is below this value
	default name=xxx
		define a default equate (no redefinition error)
	defchr
		make a CHR character - 8 hex codes (0-3 per digit)
	dw, dcw, dc.w, addr, .word
		raw 16-bit integers (warning if outside [-$8000,$FFFF])
	dcl, dc.l
		raw 32-bit integers
	end
		stops all further processing - no params
	endproc
		ends a procedure - no params
	equ
		define a label (preceding) as an equate
	fill
		fill bytes for length, optional value (default=0)
	incbin
		binary file name [SKIP (offset)] [READ (amount)]
	include
		text file name to process
	.index
		set indexed mode operand size - only 8 supported
	ineschr
		non-negative integer for CHR bank count (8KB ea.)
	inesmap
		iNES mapper index [0,511]
	inesmir
		iNES mirror (0=H, 1=V, 2=FourScore)
	inesprg
		iNES program bank count (16KB ea.)
	module
		start a module (affects labels) - name param
	opt
		set optimization option - off | on
	p02, p10
		set processor to 6502 or 6510 (low two digits)
	pad
		same as .fill, but to an explicit ORG
	.proc | main
		start a procedure (requires a name)
	processor <ID>
		set processor - 6502 | 6510
	pushseg, popseg
		save/restore current segment - no params
	segment <name> - also: bss, code, data, .text, zp, zeropage
		set segment, its position retained
	subroutine <name>
		start subroutine (similar to .proc)


==== Label Extensions

	xxx.lsb		- least significant byte (same as (xxx&$FF))
	xxx.msb		- most significant 16-bit byte (same as (xxx>>8&$FF))


==== Preprocessing Directives

	.define <name> <text>
		define a preprocessing ID - operates as text replacement
	.else
		if an .if expression ==0, parse this instead
	.elif <expr>
		if an .if expression ==0, try this expression instead
	.endif
		end of an .if's range of conditional parsing
	.error, .fail
		report an error (not supposed to come here)
	.if <expr>
		if expression !=0, parse, otherwise don't parse
	.ifdef <name>
		if preprocessing define name is listed, parse
	.ifndef <name>
		if preprocessing define name is not listed, parse
	.undef
		remove a preprocessing ID


==== Function Directives

	.paramtype
		returns 1 for number; 2 for text


==== Built-in Preprocessing Defines

	__DATE__	- calculated GMT date
	__FILE__	- current file path
	__LINE__	- current line index (unescaped start)
	__TIME__	- calculated GMT time
	__6510__	- 0 or 1 depending on generation setting


==== Not Supported

  .macro
  .func
  .localchar (local label leading character; '@' default)
  .shift - ???
  The 'a' ID is reserved for the A register.


==== Notes

 The assembler doesn't always work well with branches to labels on the next
line; if in doubt, add a line ending if branching to the next instruction.

 PALTEST and some other carts call for flat addressing (-L):
  "PALTEST.ASM -P32 -L -M1 -O"

 The NEStress assembly source (unknown credit) appears to be rather stale,
  2002-07-23 to the 2002-07-31 build.  The source file has text that shows
  a score of 9 instead of 11.  The .nes hangs in the IRQ routine.
  "-CTanks.CHR -P32 -L -M0 -R1 -O"

 FDSPic.asm is really 8KB (-P8 -M3 -O -CFDSPic.chr -R1).

 mmc5exram.nes has a 'text:' label, leading a dot requirement for '.text'.

 tvpassfail's tv.s contains code that expects segments to be reordered in
  a shared manner (CODE & RODATA are both ROM); RODATA will have to be set
  manually (to $C200).  The nes.ini file also calls for RODATA alignment;
  `.align $100` should be put after each `.segment "RODATA"`.
