cc65 not compiling code

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
User avatar
SusiKette
Posts: 110
Joined: Fri Mar 16, 2018 1:52 pm
Location: Finland

cc65 not compiling code

Post by SusiKette » Sat Aug 10, 2019 12:58 am

According to a tutorial I've been looking at, you have to write something like this in a .bat file to get cc65 to compile code:

Code: Select all

ca65 test.asm -o test.o
ld65 test.o -o test.nes -t nes
However, when I try to compile, there is no output file nor any errors displayed. Well, there could be, but the command line closes before I can see if there are any. Does cc65 have a function similar to the "pause" function in NESASM3?

User avatar
Kasumi
Posts: 1292
Joined: Wed Apr 02, 2008 2:09 pm

Re: cc65 not compiling code

Post by Kasumi » Sat Aug 10, 2019 1:06 am

PAUSE is not a function of nesasm3, it's one of the windows command line. Adding PAUSE to any .bat, NES related or not will have the same effect.

Edit, because it was only implied, not directly stated: You can add PAUSE to this script too.

User avatar
koitsu
Posts: 4217
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: cc65 not compiling code

Post by koitsu » Sat Aug 10, 2019 1:33 am

Also, please fix your argument/flag order. It is a bad habit to simply "append stuff" to a command line; always follow usage syntax per help commands or documentation (and for ld65). There is no universal standard for parsing these arguments.

TL;DR: change your script to:

Code: Select all

ca65 -o test.o test.asm
ld65 -t nes -o test.nes test.o
Also, you probably don't want to use -t nes, but you'll find out why soon enough on your own.

User avatar
SusiKette
Posts: 110
Joined: Fri Mar 16, 2018 1:52 pm
Location: Finland

Re: cc65 not compiling code

Post by SusiKette » Sat Aug 10, 2019 3:39 am

Okay, so now that I can see the error messages it seems like the error I was getting was the chr file begin too big. But since the mapper I'm using allows that much chr I'm assuming that -t nes doesn't account for mappers. If I remove it, ld65 says that it is missing a memory configuration. I couldn't find much useful information on how to create one, so I might need some help here.

EDIT: I might be able to get the RAM and PRG parts correct, but I'm not sure how I should make the configuration for CHR

tepples
Posts: 21946
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: cc65 not compiling code

Post by tepples » Sat Aug 10, 2019 5:10 am

Which mapper, how big is PRG ROM, and how big is CHR ROM?

User avatar
koitsu
Posts: 4217
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: cc65 not compiling code

Post by koitsu » Sat Aug 10, 2019 5:13 am

Right now nothing accounts for mappers in assemblers/linkers other than NESASM. You get to manage all related parts of it yourself, both the code and the "organisation" of how it's used in the assembler/linker. ca65/ld65 makes this process a bit easier (particularly ld65) -- you may want to refer to some examples that Tepples has put together for some mappers, with an exclusive focus on PRG:

* https://github.com/pinobatch/snrom-template
* https://github.com/pinobatch/bnrom-template

You may also find the bank attribute on a MEMORY entry in your ld65 configuration useful when combined with the .bank directive in ca65 (not the same as .bankbyte!). It makes storing/retrieving the PRG or CHR bank number of a particular bank very easy. It is an easily overlooked feature given the formatting/layout of the documentation.

That said: you didn't disclose what mapper you're working with, but the above should give you the general idea. Also, if you are starting out with NES development, I suggest ignoring mappers entirely and just use mapper 0 / NROM to make your life easier for now -- worry about mappers later.

As for CHR: make separate MEMORY/SEGMENTs for each one, and then declare the segment in the assembly source along with an .incbin statement to reference the actual .chr files themselves. It's that easy. You may find this post of mine helpful, which was for MMC3.

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

Re: cc65 not compiling code

Post by dougeff » Sat Aug 10, 2019 12:08 pm

You need to make a configuration file .cfg.

Here's a basic example.

https://github.com/nesdoug/01_Hello/blo ... k_vert.cfg

And you need to separate your code into different "segments" to determine where it ends up. For example, you want to incbin. your CHR into a CHAR segment, and have that listed last in the memory definitions.
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
SusiKette
Posts: 110
Joined: Fri Mar 16, 2018 1:52 pm
Location: Finland

Re: cc65 not compiling code

Post by SusiKette » Sun Aug 11, 2019 8:59 pm

I managed to make a config that compiles, but there are still some segments in the examples that I don't know the use for. Mainly ONCE, HEAP and LOWCODE. Then there are a few that seem similar, but I'm not sure what's the difference. STARTUP vs. INIT and DATA vs. RODATA. Knowing the use for these might also clear some confusion around some of the attributes used.

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

Re: cc65 not compiling code

Post by rainwarrior » Sun Aug 11, 2019 9:15 pm

RODATA is Read Only data. Just stuff that goes into ROM that isn't code, e.g. a const array goes here.

DATA is read/write data. C variables go here. There's also additionally an initialization block in ROM that gets copied into DATA's RAM location at startup to fill them with their initial values.

HEAP is used for malloc/free, you probably don't need this.

STARTUP is used to contain the code that gets run immediately after power/reset.

I forget what ONCE, LOWCODE, and INIT are used for. To be honest a lot of these aren't super useful and can probably be omitted unless you want to use very specific features of cc65's included C libraries.


For my most recent NES C project, my CFG used only the essentials: dgolf.cfg

This was combined with a simplified version of cc65's C runtime startup, which basically just initializes DATA: dgolf.s:cc65_init


If we're not talking about C and you're just making an assembly program there's even less that's really required, and all the names are arbitrary. You can call segments whatever you want.

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

Re: cc65 not compiling code

Post by calima » Mon Aug 12, 2019 12:26 am

ONCE = INIT = library constructors for code run at startup, only once. For other platforms this is stuff like input and graphics drivers, not relevant for NES.
LOWCODE is support functions placed in a "common bank" on some atari platforms, to be always accessible. Not used on NES.

tepples
Posts: 21946
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: cc65 not compiling code

Post by tepples » Mon Aug 12, 2019 4:29 am

I've used the LOWCODE mechanism for small bits of code that I copy to RAM in order to use them with data scattered across multiple banks of a 32K bank switched ROM. See, for example, interbank_fetch.s in Action 53.

The ONCE/INIT sounds like it'd be good for code that needs to be in a certain part of PRG ROM, such as keeping MMC3's reset code above $E000.

User avatar
koitsu
Posts: 4217
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: cc65 not compiling code

Post by koitsu » Mon Aug 12, 2019 1:38 pm

OP is not using C (see their script). None of the segments being discussed matter. Their existence has already confused the OP because they are more intended for use alongside C. Rainwarrior's above post, last line, is all that's relevant.

User avatar
SusiKette
Posts: 110
Joined: Fri Mar 16, 2018 1:52 pm
Location: Finland

Re: cc65 not compiling code

Post by SusiKette » Tue Sep 03, 2019 11:50 am

Now I have managed to make some code. It compiles, but it doesn't work as expected. The PRG should be for now starting at $E000 to get it to the "fixed bank" of MMC3. The space before it should be filled since I specified so in the config. However, when running the ROM on FCEUX, the code doesn't appear in the debugger. There is some PRG data at $8000, but that doesn't seem like any code/data I've written in the assembly files. Since I don't know where the issue could be, I attached the entire project folder, so someone with more experience might be able to figure out why this happens.
Attachments
test.zip
(7.18 KiB) Downloaded 124 times

User avatar
Memblers
Site Admin
Posts: 3820
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: cc65 not compiling code

Post by Memblers » Tue Sep 03, 2019 5:56 pm

I found it, the PRG and CHR data are backwards in the .NES file. In config.cfg, MEMORY outputs header, CHR, PRG. The order should be header, PRG, CHR.

Post Reply