It is currently Tue Nov 20, 2018 4:28 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: cc65 compiling
PostPosted: Fri Jun 08, 2018 6:51 pm 
Offline

Joined: Fri Jun 08, 2018 6:48 pm
Posts: 8
How do I compile an example c file to a .nes file using cc65 in the linux command line?


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Fri Jun 08, 2018 6:53 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20789
Location: NE Indiana, USA (NTSC)
Which NES I/O library is the .c file designed to use? Shiru's neslib? The stdio console provided by cc65?


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Fri Jun 08, 2018 7:26 pm 
Offline

Joined: Fri Jun 08, 2018 6:48 pm
Posts: 8
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


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Fri Jun 08, 2018 7:50 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2334
Location: DIGDUG
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


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Fri Jun 08, 2018 8:04 pm 
Offline

Joined: Fri Jun 08, 2018 6:48 pm
Posts: 8
I get:
bash: cc65: command not found
when I try the first line.


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Fri Jun 08, 2018 8:17 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2334
Location: DIGDUG
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


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Fri Jun 08, 2018 8:28 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 7723
Location: Seattle
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


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Fri Jun 08, 2018 8:57 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2334
Location: DIGDUG
retracted

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Fri Jun 08, 2018 9:17 pm 
Offline

Joined: Fri Jun 08, 2018 6:48 pm
Posts: 8
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


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Sat Jun 09, 2018 1:59 am 
Offline

Joined: Tue Oct 06, 2015 10:16 am
Posts: 820
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.


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Sat Jun 09, 2018 7:29 am 
Offline

Joined: Fri Jun 08, 2018 6:48 pm
Posts: 8
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

}


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Sat Jun 09, 2018 8:14 am 
Offline
User avatar

Joined: Tue Jun 24, 2008 8:38 pm
Posts: 2056
Location: Fukuoka, Japan
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:
    __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 61 times
Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Sat Jun 09, 2018 7:02 pm 
Offline

Joined: Fri Jun 08, 2018 6:48 pm
Posts: 8
I got a different error now that the nes.cfg file has been changed

ld65: Error: Wrong data version in `runtime.lib'


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Sat Jun 09, 2018 7:18 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 7723
Location: Seattle
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.


Top
 Profile  
 
 Post subject: Re: cc65 compiling
PostPosted: Sat Jun 09, 2018 8:15 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2334
Location: DIGDUG
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google [Bot] and 1 guest


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:  
Powered by phpBB® Forum Software © phpBB Group