Page 1 of 1

CC65 syntax related question (not CA65)

Posted: Tue Jul 03, 2012 8:41 am
by albailey
I've coded for years in CA65 and after seeing some amazing work done using CC65, I've decided to try my hand at it.
However I have encountered some problems in trying to convert CA65 ASM syntax into something CC65 likes.

For now, my workaround has been to make ASM libraries and just call those any time I encounter a problem.

Here is a very simple example. I put some raw CHR data in BANK5, and I want to access it by address.

In CA65 I would do something like this (assuming all my linker settings are properly setup):

.segment "BANK5"
CHR_LABEL:
.incbin "chrtiles.bin"

and back in my main code, once I have bank switched I could get at it like this:
LDA #<CHR_LABEL
LDX #>CHR_LABEL


I have no clue how to do the same type of thing in CC65. Thats why I'm using ASM libraries and calling those instead.

What would be the CC65 equivalent for
".segment"
".incbin"
and getting the address/label for the chunk of data


Thanks
Al

Posted: Tue Jul 03, 2012 9:02 am
by thefox
So you're asking how to do the equivalent in C code?

There's no equivalent of .incbin in C, so if/when you need it it's better to do that in an asm module:
Asm:

Code: Select all

.export _foo
_foo:
  .incbin "whatever.bin"
Accessing it from C:

Code: Select all

// Using const here assuming foo is in ROM.
extern const unsigned char foo[];
// Do stuff with it:
unsigned char fifth_byte = foo[ 4 ];

To get the address simply use "foo" or "&foo[0]". Note that you need to prefix the name with an underscore when exporting it from the asm module.

Posted: Tue Jul 03, 2012 9:58 am
by albailey
Thanks.

Thats cleaner than how I was doing it.

I had been writing functions to return addresses, etc..

Al