CA65 examples?

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
User avatar
Michael
Posts: 633
Joined: 13 Feb 2013
Location: Michigan, USA

CA65 examples?

Post by Michael »

Anyone come across a tutorial or examples for using the CA65 cross-assembler (on a Windows 7 laptop)? Do you use a text editor for your source and then feed it to the CA65 executable?

TIA... Regards, Mike
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: CA65 examples?

Post by BigEd »

Yes, I'd use any convenient text editor.
Here's how I use the assembler and linker:

Code: Select all

ca65 -l boot816.as -D BASE=0x8000
cl65 boot816.o --target none --start-addr 0x8000 -o boot816.bin
(From viewtopic.php?p=9534#p9534)

Cheers
Ed
User avatar
Michael
Posts: 633
Joined: 13 Feb 2013
Location: Michigan, USA

Re: CA65 examples?

Post by Michael »

Thank you, Ed...
White Flame
Posts: 704
Joined: 24 Jul 2012

Re: CA65 examples?

Post by White Flame »

Here's portions of the Makefile boilerplate I've grown over the years. It reports on the used size of segments and generates all the debug output. I use a proper src, obj, and bin subdirectory set as I often have other resources that have to go through the pipe.

Code: Select all

# Final output filename
BINFILE = editor.prg
CFGFILE = src/editor.cfg

obj/%.o: src/%.asm
	ca65 $< -g -o $@ -I src

clean:
	- mkdir -p obj
	- mkdir -p bin
	- rm -f obj/*
	- rm -f bin/*

all: clean obj/editor.o
	ld65 -Ln L -C $(CFGFILE) -m obj/map -o bin/$(BINFILE) $^
	@sed '1,/^$/ d' obj/map | sed -n '/Exports list/q;p'
I name the labels file simply "L", so from Vice's monitor I can type ll"L" quickly to load the labels, as there's no scriptable cmdline option for preloading label files.

Oftentimes I export labels with a double-underscore in them and add a grep + sort for them from the labels file after final compilation, to give some finer grained boundary reporting when memory is tight.

YMMV on the exact sed format, as I'm using a modified version of an older ca65/ld65, and I don't know what newer versions output. Same for cmdline switches, but I'd expect those to be pretty stable.
User avatar
Michael
Posts: 633
Joined: 13 Feb 2013
Location: Michigan, USA

Re: CA65 examples?

Post by Michael »

Gosh, I only understand about a quarter of that (way over my head).

After using only Integrated Development Environments (IDE) these last ten years I can't even remember how I used to create Apple ][ and 68HC11 programs. But, I don't seem to remember it being quite as involved as your description.

Thanks, Gentlemen... It looks like I may have a lot of work ahead of me (lol)...
White Flame
Posts: 704
Joined: 24 Jul 2012

Re: CA65 examples?

Post by White Flame »

If you want to use that blindly, there's just 3 things to configure.

Set BINFILE and CFGFILE at the top, then in the line

Code: Select all

all: clean obj/editor.o
list all the object files you want compiled together. For instance, if you have foo.asm and bar.asm in your src directory, the line would be

Code: Select all

all: clean obj/foo.o obj/bar.o
and it will compile and link those files together.

The basics of Makefiles are pretty simple. As far as all the crazy punctuation goes, I'm not an expert in that. I read the docs as needed to make them work in the general case, and it works across all the projects I have.

When I have small things that can fit in a single .asm file, I sometimes do grab a single-command assembler like xa. But it is good to have a proper ca65 project skeleton that you can do bigger, more flexible development in.


If you're just banging around with small stuff and aren't familiar with Makefiles and segment-based configuration, yeah you might want to go for something simpler than ca65. It takes a fair amount to set up, but it's the only thing I'd want to use for large projects. I simply run smaller projects through the same, since it's good future-proofing for scaling something up later.
Post Reply