CC65 compiler

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

vedita
Posts: 4
Joined: Fri Aug 18, 2017 5:18 am

CC65 compiler

Post by vedita »

Hello friends I am new here and am wanting to learn to program for Nes, I would like to know how the compiler CC65 installation that will install the rom, because every time I try to start programming for Nes I stop these compilers where I have no idea how to install and get him to do the Assembly of rom, if you can help me I would be grateful ... ....

If it's not too much trouble I'd like a video lesson teaching how to install because it would be much easier to understand, I thank you.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: CC65 compiler

Post by dougeff »

Are you having trouble "installing" the cc65 suite, or running the .exe files?

If the 2nd, describe the error message you get. Did a black box appear and disappear when you clicked on it?
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: CC65 compiler

Post by FrankenGraphics »

To set it up, you simply extract it to c:\cc65 (or wherever you want it).

in that folder, keep your projects in separate folders. My projects always begin with a _ so they will appear first when name-sorted.

In a project folder, you'll need a batch file (out of convenience) and a config file (out of necessity). The batch file can be as simple as it gets.

One of mine looks like this:

Code: Select all

ca65 -t nes -l list.lst -g src/dungeon.asm -o dungeon.o
ld65 -C src/dungeon.cfg dungeon.o -o dungeon.nes
pause
When running the batch file (in my case named _makefile.bat) ca65 -the assembler- will output an object file. ld65 -the linker- will take that object file and link it according to the config file into a playable rom (name its extention .nes for emulator recognition, .bin otherwise)

the config file is needed to tell the linker how to link objects. This differs from platform to platform (like apple II, c64, nes), and for the nes, the config will differ from mapper to mapper. The ld65 reference has useful tips on how to construct one, and dougeff recently made a whole bunch of tutorial templates. Note that they're made with using neslib in mind, so you can cut some parts out at will if you don't use neslib.

the ld65 and ca65 references will allso give you a full list of command line options to put in your batch file.
vedita
Posts: 4
Joined: Fri Aug 18, 2017 5:18 am

Re: CC65 compiler

Post by vedita »

dougeff wrote:Are you having trouble "installing" the cc65 suite, or running the .exe files?

If the 2nd, describe the error message you get. Did a black box appear and disappear when you clicked on it?
I don't know where to start, let me explain ... ....

Where I write the code?

How to turn this code into something executable on the emulator?

I need something very detailed, from how to install cc65 to time to transform the code into a rom do you understand?

I'm a beginner at this and I'm a little lost, I've always wanted to learn more unfortunately never get something very detailed, if they can help me I appreciate it.
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: CC65 compiler

Post by FrankenGraphics »

You can write the code in anything that can produce a text format file. Even microsoft notepad. But your code will be more readable in something like notepad++, keep track of line numbers in your code, notify you when there has been changes to opened files, etc etc... lots of useful perks.

Once you have your code (name it code.txt or main.asm or whatever, the extention doesn't matter - it's just for keeping apples from pears for your own convenience), you must use either the command line of your OS* or write a batch file which does the same for you. This is to make the cc65 suite produce a ROM for you.

Have you used the command prompt or made a batch file before?

*On windows 8.1 to 10, you can conveniently open the command prompt three ways
1) win key+r, "cmd.exe", enter key. This works regardless language/localization.
2) win key+x, c key
3) win key+x, a key (same but with administrative privileges)


As a side note, using asm6 is a lot simpler, because you can simply drag and drop your main code file to asm6.ex icon and it will produce a ROM. But you'll eventually need to learn the other stuff anyway.
vedita
Posts: 4
Joined: Fri Aug 18, 2017 5:18 am

Re: CC65 compiler

Post by vedita »

FrankenGraphics wrote:You can write the code in anything that can produce a text format file. Even microsoft notepad. But your code will be more readable in something like notepad++, keep track of line numbers in your code, notify you when there has been changes to opened files, etc etc... lots of useful perks.

Once you have your code (name it code.txt or main.asm or whatever, the extention doesn't matter - it's just for keeping apples from pears for your own convenience), you must use either the command line of your OS* or write a batch file which does the same for you. This is to make the cc65 suite produce a ROM for you.

Have you used the command prompt or made a batch file before?

*On windows 8.1 to 10, you can conveniently open the command prompt three ways
1) win key+r, "cmd.exe", enter key. This works regardless language/localization.
2) win key+x, c key
3) win key+x, a key (same but with administrative privileges)


As a side note, using asm6 is a lot simpler, because you can simply drag and drop your main code file to asm6.ex icon and it will produce a ROM. But you'll eventually need to learn the other stuff anyway.
If it wasn't too much to ask, I'd like you to make a video showing all the steps with the part that you create the rom, as I believe that a lot of people who want to learn this part, keeps "Nes that would not only help me as a lot of people too.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: CC65 compiler

Post by Pokun »

I haven't seen any video tutorials, but if you can read English, Dougef's blog seems to explain what you need to learn to make your first NES ROM in CC65, and more. And if assembly is fine instead of C, I recommend the Nerdy Nights tutorial. It does teach some bad things, but other than that it is a very good tutorial for beginners of NES and/or 6502. That's where I started.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: CC65 compiler

Post by dougeff »

Someone once asked me if I could demonstrate programming a NES game, like live in front of an audience. I laughed. Ok, if an audience is willing to watch me sit and type quietly for 12-14 hours, I could bang together a very simple Super Mario Bros style scroller.

The joke being, of course, it takes way too much time to do even a simple game. It would be painfully boring to watch.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: CC65 compiler

Post by FrankenGraphics »

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.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: CC65 compiler

Post by Pokun »

dougeff wrote:Someone once asked me if I could demonstrate programming a NES game, like live in front of an audience. I laughed. Ok, if an audience is willing to watch me sit and type quietly for 12-14 hours, I could bang together a very simple Super Mario Bros style scroller.

The joke being, of course, it takes way too much time to do even a simple game. It would be painfully boring to watch.
Yeah some things are best explained by showing, and programming isn't one of them. Video tutorials are slow, if you loose concentration for an instance or try to fast-forward a little, you easily miss what the teacher is doing and won't be able to follow anymore, you are forced to rewind and watch the part again. Another bad thing is if you quit in the middle of the video it's a pain to find where you where last time, or if you need to review an old part of the tutorial you have to search in the video search-bar, it's almost impossible to get to a point where the context makes sense without watching it all over again. Also you can't glean through the video like with text when searching it.
Everything takes like ten times the time than learning from text and pictures that you can study in your own pace. Certain parts of a tutorial might be better shown in short video clips, but definitely not punching code.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: CC65 compiler

Post by DRW »

Before you try to program for the NES, you should learn about basic computer-related things, like the command line prompt because it looks like you don't know about it yet.

Also, you should research what a compiler is and what it does.

And I don't understand why you insist on getting a video tutorial. If you want to become a programmer, you should be able to gather information in text form. Not everything will be presented to you in the form of a video.

But in the moment, this point is moot anyway. You won't get very far with NES programming if you seriously have to ask for a video tutorial on setting up a simple compiler from a zip file. That's like trying to write a novel without even being able to read.
Even if you follow the instructions that the other users listed for you, you will most likely be stuck by the next step. And the next step afterwards. And so on.

Before bothering with NES programming at all, it's mandatory that you have basic computer knowledge. For a start, research what the windows command line prompt is and what a compiler is used for.

Also, for starting programming, you should use something different than the NES. The NES is very specific.
Since you don't even seem to know how to program at all (otherwise you wouldn't ask where to enter the source code), I'd suggest to start with a C, C++ or C# tutorial for Windows (at least the first few chapters) where you write simple text-based applications, so that you first learn about the concept of programming before you get to the highly hardware-specific NES.

Please don't let this discourage you. But I think if somebody wants to start with something, he should start at the beginning. Programming the NES is advanced stuff. Don't do this unless you know what a Win32 console application is and you can create one yourself from a source code file.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: CC65 compiler

Post by tepples »

This list of articles should help bring you up to speed on basic computer science concepts.

@DRW
Should someone really have to download and install multiple gigabytes of Visual Studio just to prove he can create a Windows console app? I can see how it'd be helpful if someone wants to program the NES in C, not so much assembly language, as all my asset conversion tools are in Python. I know MinGW (GCC for Windows) exists, but not being a regular user of MinGW, I can't walk you through installing it.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: CC65 compiler

Post by DRW »

tepples wrote:Should someone really have to download and install multiple gigabytes of Visual Studio just to prove he can create a Windows console app?
It's not about "proving" anything, it's a help for him. If he prefers to start with a highly specific console like the NES, despite not even knowing what the Windows console is, it's his decision, but I doubt that he'll get very far.

And you don't need to install a whole Visual Studio. There is Code::Blocks. Or he can use Turbo C++ 1.01 which was released as freeware by Borland.
tepples wrote:I can see how it'd be helpful if someone wants to program the NES in C, not so much assembly language
The programming language is secondary in this case (unless he actually plans to use the C compiler of cc65). It's about getting a grip of how programming works in general since he asked stuff like "Where do I enter the code?" I could also have said that he should get QBasic for a start, but I hate the BASIC programming language, that's why I suggested C-like languages.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: CC65 compiler

Post by Garth »

DRW wrote:I could also have said that he should get QBasic for a start, but I hate the BASIC programming language, that's why I suggested C-like languages.
I would allow for the different way different brains think. I've used several different versions of BASIC, from toy (Timex Sinclair ZX-81, IIRC) to professional instrumentation BASICs (from Hewlett-Packard); and although I'm not crazy about BASIC, it was much easier for me than C. I cannot get my brain around C. To me, it's an absolute disaster of a language that never should have hit the streets. I do great at Forth and RPN though, and at assembly (particularly if I can use macros to raise the level of the language a lot). A friend said, "You have an RPN brain."
http://WilsonMinesCo.com/ lots of 6502 resources
niconii
Posts: 219
Joined: Sun Mar 27, 2016 7:56 pm

Re: CC65 compiler

Post by niconii »

There really isn't one "beginning" when it comes to programming. I've seen people start with something like assembly and work their way up, start with something very abstract like Haskell and work their way down... There's many ways to do it.

In general, I don't think saying "instead of doing this thing you're interested in, you have to do all this other stuff you're not interested in first" tends to work very well. All they really need to know here is how to get started; I imagine they don't because tutorials tend to assume some level of familiarity with the command line already and thus don't cover the subject, but it's honestly pretty orthogonal to the subject of NES programming itself. They might have an easier time once they're actually dealing with things documented by the wiki, so I don't think it's worthwhile to assume they'll be stuck by everything.

(It's also worth noting that not being familiar with the command line does not immediately imply never having programmed before. A number of languages have IDEs or built-in editors; Python is one notable example.)
Post Reply