6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 3:47 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: CA65 examples?
PostPosted: Wed Feb 27, 2013 5:32 pm 
Offline
User avatar

Joined: Wed Feb 13, 2013 1:38 pm
Posts: 589
Location: Michigan, USA
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


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65 examples?
PostPosted: Wed Feb 27, 2013 6:13 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Yes, I'd use any convenient text editor.
Here's how I use the assembler and linker:

Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65 examples?
PostPosted: Wed Feb 27, 2013 7:03 pm 
Offline
User avatar

Joined: Wed Feb 13, 2013 1:38 pm
Posts: 589
Location: Michigan, USA
Thank you, Ed...


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65 examples?
PostPosted: Thu Feb 28, 2013 12:49 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 679
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:
# 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.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65 examples?
PostPosted: Thu Feb 28, 2013 6:21 am 
Offline
User avatar

Joined: Wed Feb 13, 2013 1:38 pm
Posts: 589
Location: Michigan, USA
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)...


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65 examples?
PostPosted: Thu Feb 28, 2013 6:59 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 679
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:
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:
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.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: