CC65 syntax related question (not CA65)

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
Posts: 177
Joined: Thu Jul 13, 2006 3:15 pm

CC65 syntax related question (not CA65)

Post by albailey » Tue Jul 03, 2012 8:41 am

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"
.incbin "chrtiles.bin"

and back in my main code, once I have bank switched I could get at it like this:

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
and getting the address/label for the chunk of data


User avatar
Posts: 3141
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland

Post by thefox » Tue Jul 03, 2012 9:02 am

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:

Code: Select all

.export _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.

Posts: 177
Joined: Thu Jul 13, 2006 3:15 pm

Post by albailey » Tue Jul 03, 2012 9:58 am


Thats cleaner than how I was doing it.

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


Post Reply