Page 1 of 1

?'s about using ca65

Posted: Wed Nov 15, 2006 6:12 am
by mbrenaman
I'm having problems figuring some things out using ca65, and am looking for help.

My first question is, how do you compile a program with several source files without using one big .include list. Lot's of my files depend on others and if I tried to address each source file, I'll end up .include'd a source more the once.

My second question, how do you go about making code into modules for use with multiple projects. I use .include, but what about modules and these .import/.export commands.

I read the ca65 manual and well.... I think I need alittle more instruction then is provided to fully understand how to use these aspects.

Is there more documentation on the internet? Maybe example code?

Well, anyways. If you can help me out, thank you in advance.

Posted: Wed Nov 15, 2006 12:10 pm
by tepples
I can most easily explain .include and .global in terms of C headers. Do you know how header files in the C or C++ language work?

Posted: Wed Nov 15, 2006 12:13 pm
by mbrenaman
Yes. I know how header files work in C.

Posted: Wed Nov 15, 2006 4:34 pm
by tepples
Treat each CA65 .s file as you would a C .c file, and treat each CA65 .h file as you would a C .h file.

C foo.c:

Code: Select all

#include "sprites.h"
CA65 foo.s:

Code: Select all

.include "sprites.h"
C sprites.h:

Code: Select all

int drawChar(int x);
extern const char charFrames[256];
extern char curTurn;  // in "zeropage" segment
CA65 sprites.h:

Code: Select all

.import drawChar
.import charTable
.importzp curTurn
C sprites.c:

Code: Select all

int drawChar(int x) {
  // ...
}

const char charFrames[256] = {
  // ...
};

char curTurn;
CA65 sprites.s:

Code: Select all

.segment "CODE"
.export drawChar
drawChar:
  ; ...
  rts

.segment "RODATA"
.export charFrames
charFrames:
  .byt ;...

.segment "ZEROPAGE"
.exportzp curTurn
curTurn:
  .res 1

Posted: Thu Nov 16, 2006 6:12 am
by mbrenaman
Thank you tepples, I understand completly.

I have another question though. In "CA65 sprites.s", where you define the segment for the code for drawChar "CODE", is there a way to make the segment optional (to the project using it)?

I know I can use a constant symbol inplace of "CODE", but how would constants fit into the example you provided. I'm aware defined constants can't be .import'ed and .export'ed.