CC65 compiler

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
dougeff
Posts: 2673
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: CC65 compiler

Post by dougeff » Wed Jun 20, 2018 10:30 am

Little outdated topic sorry but following nesdoug's tutorial and I cant it to compile correctly. Getting this error. I left the .asm file blank as I dont know what code to test because Im still learning. Tried a few examples at his site but get errors with the .asm also. Not sure why Im having such a issue compiling. Any help would be great. Thanks :)

Code:
ld65: Warning: NROM.cfg(76): Segment `HEADER' does not exist
ld65: Warning: nrom.cfg(76): Segment `STARTUP' does not exist
ld65: Warning: nrom.cfg(76): Segment `VECTORS' does not exist
ld65: Warning: nrom.cfg(76): Segment `CHARS' does not exist
ld65: Warning: nrom.cfg(76): Segment `ONCE' does not exist
Need more info. Windows or Linux?

Using a .bat file, make file, or manually typing commands into the terminal?

Which example code are you trying to compile?

None of my .cfg files are named NROM.cfg ... nor nrom.cfg. Where did you get that from?

Most of those segments are located in 'reset.s' which is almost the same as 'crt0.s' found in other people's source code. Are you sure that file is in the same folder?
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
DRW
Posts: 1930
Joined: Sat Sep 07, 2013 2:59 pm

Re: CC65 compiler

Post by DRW » Wed Jun 20, 2018 10:49 am

dude3585 wrote:Little outdated topic sorry but following nesdoug's tutorial and I cant it to compile correctly. Getting this error. I left the .asm file blank as I dont know what code to test because Im still learning. Tried a few examples at his site but get errors with the .asm also. Not sure why Im having such a issue compiling. Any help would be great. Thanks :)

Code: Select all

ld65: Warning: NROM.cfg(76): Segment `HEADER' does not exist
ld65: Warning: nrom.cfg(76): Segment `STARTUP' does not exist
ld65: Warning: nrom.cfg(76): Segment `VECTORS' does not exist
ld65: Warning: nrom.cfg(76): Segment `CHARS' does not exist
ld65: Warning: nrom.cfg(76): Segment `ONCE' does not exist
Well, obviously, you don't have any of these segments in your Assembly file, even though they're declared in your CFG file.
Which is no wonder if you are using a blank Assembly file.

This way the compiler thinks you have forgotten these segments and warns you about it.

Your code file needs stuff like:

Code: Select all

.segment "STARTUP"
    ; Startup code goes here.

.segment "VECTORS"
    .addr Nmi
    .addr Reset
    .addr 0
etc.


P.S.: It's just a warning, not an error. After compiling, you should still get an NES file with all zeroes out of it, don't you?
Available now: My game "City Trouble".
Sales website: https://megacatstudios.com/products/city-trouble
Gameplay: https://youtu.be/Eee0yurkIW4
Download website: http://www.denny-r-walter.de/city.htm

User avatar
rainwarrior
Posts: 7803
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: CC65 compiler

Post by rainwarrior » Wed Jun 20, 2018 11:12 am

The fix isn't to add those segments to your assembly file, though. That's just treating the symptoms rather than the problem. It might compile but the ROM is not going to run unless you fill those segments up with what they require.

The fix is to find and include the content that you're missing from whatever example you're working from that is supposed to fill in those segments for you already.

User avatar
DRW
Posts: 1930
Joined: Sat Sep 07, 2013 2:59 pm

Re: CC65 compiler

Post by DRW » Wed Jun 20, 2018 12:04 pm

Well, it looks like he's trying to compile a blank file, so I assume the actual code comes afterwards anyway and he's just trying to set up the system to get zero errors.
Available now: My game "City Trouble".
Sales website: https://megacatstudios.com/products/city-trouble
Gameplay: https://youtu.be/Eee0yurkIW4
Download website: http://www.denny-r-walter.de/city.htm

User avatar
rainwarrior
Posts: 7803
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: CC65 compiler

Post by rainwarrior » Wed Jun 20, 2018 1:34 pm

Sorry, yes you gave good information, I was merely clarifying that only doing that won't solve the problem, only hiding it.

User avatar
dude3585
Posts: 39
Joined: Mon Sep 05, 2016 3:33 pm
Location: US

Re: CC65 compiler

Post by dude3585 » Wed Jun 20, 2018 4:58 pm

Thanks for quick reply! I followed this.On Win10 64bit. Notepad ++.
Followed this pretty much exactly but was confused by a few things. For the .cfg file Ive tried a few differnt nrom files that were at your site. In the CFG.zip. For the .asm I tried copy and pasting all the code here https://nesdoug.com/2015/11/17/3-our-first-program/.
I also made exceptions for PATH environment variables.


Update: I havnt made path exceptions in Windows for ld65. If that is needed?
Also that is correct I did try blank .asm and also code from Doug''s first program page. Basically tried blanka dn not blank to just get a .nes file compiled even if it wont run. Ill take a look at the reset.s file. That could be the missing code I need to take a look at.
FrankenGraphics wrote:Won't record a movie, but this is my best attempt at a complete walkthrough.

1) Download the latest cc65 suite from here: https://cc65.github.io/cc65/getting-started.html
2) Extract it to c:\cc65
3) In c:\cc65, create a new folder. Name it "_MyFirstProject"
4) Open that folder. And open notepad. Write this:

Code: Select all

ca65 -t nes -l mylist.lst src/mycode.asm -o myobjectfile.o
ld65 -C src/NROM.cfg myobjectfile.o -o mynesrom.nes
Pause
And save it as "_makefile.bat" in the project folder you just created. We'll get to what that did in a bit. For now, let's do a couple more things:
5) Within your project folder, create a new one called src. This is where we'll keep sourcecode and assets and configs. Open it.
6) Download dougeff's config zip and place one of the configs in it named something with "nrom" there. It doesn't matter which one at this point, but rename it to NROM.cfg for the sake of this walkthrough.
7) Make a new text file, let's call it mycode.asm.
8) Write some lines of code in it (since we're using dougeffs configs, a tip is following the same tutorials) and save.
9) So, with all that done, let's try it. Double click your batch file to make it run ca65 and ld65.
You should now have a NES binary file called mynesrom.nes. Congratulations!

Allright, let's get back to what the batch file did.

The batch file (.bat) is a way of automating using the command line tool, which you otherwise would use each time you'd assemble source code into a binary file (what one might offhandedly call a ROM, after the .rom file extension), using ca65*. We're not there yet, though, just preparing.

Let me step through what that batch file will do once you run it (you'll eventually do so by double clicking on it)
First line:
ca65 | this tells windows to run ca65; the assembler. Windows should know where it's at, so we don't need to specify the whole path.
-t nes | this is our first "command line option" - optional instructions which tells ca65 what to do. -t sets the target platform to nes. This isn't necessary to specify, but is handy: the right processor is chosen and so we will get notified if we try to use opcodes it can't accept. There's more to it if you'd program for, say, the commodore 64, but let's not get into that.
-l mylist.lst | this tells ca65 to create a listing of its output. It's not necessary either, but viewing the .lst file in a text or code editor might reveal things when you're analysing your resulting program and its machine language strings can be used for finding stuff in a hex editor. We won't get deeper into that now either.
src/mycode.asm | this will tell the assembler what file to assemble. The src\ part indicates that we have a folder named src in which the code should be.
-o myobjectfile.o | This tells ca65 that the assembled output file (called an object file) will be named myobjectfile.o - if we don't include it, it will default to the filename of your source code file but have the extension .o instead of what your source had.

Allright, so with that line run, the assember has made an object file. It's now the job of the linker to link together object files. Since we only have one for now, the linker will simply take that object file and output it as a nes file. But we need to instruct it to do so, of course. So here's line two:

ld65 | This will start the linker. Let's tell it what to do.
-C src/NROM.cfg | Use the config file named NROM.cfg
myobjectfile.o | Convert this object file according to specs found in NROM.cfg
-o mynesrom.nes | into an output we name mynesrom.nes.

Line three:
Pause | This is so the command prompt window doesn't close after execution. This way we can review what it had to say - were there any warnings, errors, or did we succeed? The pause is entirely optional, but is handy.

DONE!
You now know how to make .nes files using batch files and the cc65 suite. If you instead want to use the command line, you simply use the win-r hotkey, write "cmd.exe", hit enter, and then enter the same lines you wrote in the batch files (not "pause". that one is redundant here).

*ca65 and ld65 are two tools in the cc65 toolchain. ca is the assembler, ld is the linker. Both are needed to make a nes rom using assembly language.

Post Reply