cc65 compiling

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

kennyp1369
Posts: 8
Joined: Fri Jun 08, 2018 6:48 pm

cc65 compiling

Post by kennyp1369 »

How do I compile an example c file to a .nes file using cc65 in the linux command line?
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: cc65 compiling

Post by tepples »

Which NES I/O library is the .c file designed to use? Shiru's neslib? The stdio console provided by cc65?
kennyp1369
Posts: 8
Joined: Fri Jun 08, 2018 6:48 pm

Re: cc65 compiling

Post by kennyp1369 »

Shiru's neslib. I have a folder in the cc65 directory with shiru's examples in it. I was trying to compile example1.c for nes.
There is a _compile.bat file in the folder bit I don't know what the commands are to compile in a linux environment.

I tried:
cl65 -t nes example1.c
and got:
bash: cl65: command not found
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: cc65 compiling

Post by dougeff »

There's a makefile here.

https://github.com/jmk/cc65-nes-examples?files=1

Looks like something like

cc65 -Oi example1.c --add-source
ca65 crt0.s
ca65 example1.s
ld65 -C nes.cfg -o example1.nes crt0.o example1.o runtime.lib

but if you are using a different version of cc65 than Shiru used when he made the runtime.lib, it will error. I think you can delete that from the line, I'm away from my computer at the moment, can't remember.

By the way, I'm 99% sure that "-t nes" does nothing useful.
nesdoug.com -- blog/tutorial on programming for the NES
kennyp1369
Posts: 8
Joined: Fri Jun 08, 2018 6:48 pm

Re: cc65 compiling

Post by kennyp1369 »

I get:
bash: cc65: command not found
when I try the first line.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: cc65 compiling

Post by dougeff »

I don't remember how to set paths on a linux machine. You will have to Google it.
nesdoug.com -- blog/tutorial on programming for the NES
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: cc65 compiling

Post by lidnariq »

dougeff wrote:By the way, I'm 99% sure that "-t nes" does nothing useful.
(wild tangent) Having now looked, apparently it's equivalent to -D__NES__=1
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: cc65 compiling

Post by dougeff »

retracted
nesdoug.com -- blog/tutorial on programming for the NES
kennyp1369
Posts: 8
Joined: Fri Jun 08, 2018 6:48 pm

Re: cc65 compiling

Post by kennyp1369 »

I made some great progress.

cc65 -Oi example1.c --add-source
ca65 crt0.s
ca65 example1.s

all worked after I set paths, but I got the error:
Error: nes.cfg(82): Attribute expected, got '__STACKSIZE__'
when I ran:
ld65 -C nes.cfg -o example1.nes crt0.o example1.o runtime.lib

I
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: cc65 compiling

Post by calima »

That's because Shiru's examples were made with a six years old cc65. They aren't compatible with the latest version, but with the 2.13 old one.
kennyp1369
Posts: 8
Joined: Fri Jun 08, 2018 6:48 pm

Re: cc65 compiling

Post by kennyp1369 »

Is there a fix to get it to compile? I'm trying to find reference example code that all compiles.


MEMORY {

    # First 28 bytes of the zero page are used by NES library


    ZP: start = $28, size = $d8, type = rw, define = yes;


    # INES Cartridge Header


    HEADER: start = $0, size = $10, file = %O ,fill = yes;


    # 2 16K ROM Banks

    # - startup

    # - code

    # - rodata

    # - data (load)


    PRG: start = $8000, size = $3f00, file = %O ,fill = yes, define = yes;


    # NROM256

    # PRG: start = $8000, size = $7f00, file = %O ,fill = yes, define = yes;


    # DPCM Samples at end of the ROM


    DMC: start = $7f00, size = $fa, file = %O, fill = yes;


    # NROM256

    # DMC: start = $ff00, size = $fa, file = %O, fill = yes;


    # Hardware Vectors at end of the ROM


    VECTORS: start = $7ffa, size = $6, file = %O, fill = yes;


    # NROM256

    # VECTORS: start = $fffa, size = $6, file = %O, fill = yes;


    # 1 8K CHR Bank


    CHR: start = $0000, size = $2000, file = %O, fill = yes;


    # standard 2K SRAM (-zeropage)

    # $0100 famitone, palette, cpu stack

    # $0200 oam buffer

    # $0300..$800 ca65 stack


    RAM: start = $0300, size = $0500, define = yes;


    # Use this definition instead if you going to use extra 8K RAM

    # RAM: start = $6000, size = $2000, define = yes;

}


SEGMENTS {

    HEADER: load = HEADER, type = ro;

    STARTUP: load = PRG, type = ro, define = yes;

    LOWCODE: load = PRG, type = ro, optional = yes;

    INIT: load = PRG, type = ro, define = yes, optional = yes;

    CODE: load = PRG, type = ro, define = yes;

    RODATA: load = PRG, type = ro, define = yes;

    DATA: load = PRG, run = RAM, type = rw, define = yes;

    VECTORS: load = VECTORS, type = rw;

    SAMPLES: load = DMC, type = rw;

    CHARS: load = CHR, type = rw;

    BSS: load = RAM, type = bss, define = yes;

    HEAP: load = RAM, type = bss, optional = yes;

    ZEROPAGE: load = ZP, type = zp;

}


FEATURES {

    CONDES: segment = INIT,

            type = constructor,

            label = __CONSTRUCTOR_TABLE__,

            count = __CONSTRUCTOR_COUNT__;

    CONDES: segment = RODATA,

            type = destructor,

            label = __DESTRUCTOR_TABLE__,

            count = __DESTRUCTOR_COUNT__;

    CONDES: type = interruptor,

            segment = RODATA,

            label = __INTERRUPTOR_TABLE__,

            count = __INTERRUPTOR_COUNT__;

}


SYMBOLS {

    __STACKSIZE__ = $0500; # 5 pages stack

}
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: cc65 compiling

Post by Banshaku »

I had to update the file since I took the examples and tried to compile them with the latest version and had issues like you. The stack line would look like this:

Code: Select all

    __STACKSIZE__ : type = weak, value = $0500; 
I included my current config file which is based on Shiru's examples. I commented out the features parts since I'm not using them.

I did make a make file that compile everything in your source folder. I may share it later if people are interested in it. For now I use a copy of the runtime to build the runtime.lib when necessary but would like to automate it late to take the files from cc65 directly.

If I can make it generic enough it could be useful for people that needs to build the runtime and build all their files in a src folder automatically.
Attachments
nrom_128_horz.cfg.zip
(999 Bytes) Downloaded 168 times
kennyp1369
Posts: 8
Joined: Fri Jun 08, 2018 6:48 pm

Re: cc65 compiling

Post by kennyp1369 »

I got a different error now that the nes.cfg file has been changed

ld65: Error: Wrong data version in `runtime.lib'
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: cc65 compiling

Post by lidnariq »

The runtime that was distributed with shiru's project is just an old version of cc65's nes.lib, with a few heavier functions removed. (see also)

You can safely use cc65's nes.lib instead.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: cc65 compiling

Post by dougeff »

This sequence of events is amazingly familiar, and reminds me of the famous "babel fish puzzle" from the infocom text adventure "Hitchhiker's Guide to the Galaxy". You see you try to get the babel fish out of the dispenser, only for it to fly through a hole. If you cover the hole, then the fish bounces into a grate in the floor. If you cover the grate, the babel fish lands, then a tiny robot comes and steals it away through a panel. If you then cover the panel...etc.

Each failed step was not apparent until you fixed the previous step of the puzzle. Also, you are required by the game to go through each failed step before solving the puzzle.
nesdoug.com -- blog/tutorial on programming for the NES
Post Reply