It is currently Wed Sep 18, 2019 4:34 am

All times are UTC - 7 hours



Forum rules





Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Snes cc65
PostPosted: Sun Jan 27, 2019 6:37 pm 
Offline

Joined: Sun Jan 27, 2019 6:34 pm
Posts: 9
Hello,
I was wondering can anyone give me some advice or past experience on cc65 and SNES programming? I have a game that is developed in cc65 for NES and was asked to do it for SNES also with cc65. Searching the internet I found little to none information about cc65 and SNES programming. Also I was wondering is there any code examples?


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Sun Jan 27, 2019 7:37 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2562
Location: DIGDUG
We all decided that cc65, being a 6502 compiler, was inadequate for making a SNES game (65816 processor).

However, the assembler ca65, can assemble 65816 asm, and ironically would do fine.

calima has been working on a SNES game, and I'd be very interested in finding out what assembler/compiler they used.

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


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Sun Jan 27, 2019 7:48 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7582
Location: Canada
CC65 won't take advantage of any of the 16-bit features, but it will still compile working code for SNES. It's just slower than it could be, which was already true even on the 8-bit platforms.

So... I think it should still pretty usable. Probably even more usable than on NES, I think, since you've got more CPU to work with? I haven't yet had an opportunity to try, though. I may be unaware of some critical flaw, but the lack of 16-bit optimization doesn't seem like a dealbreaker to me.

The assembly side of it, ca65, works pretty good as far as I've tried it with that.

tepples wrote a "project template" example for SNES in ca65:
https://pineight.com/snes/


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Sun Jan 27, 2019 8:01 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2562
Location: DIGDUG
Well, accessing RAM, outside of the LowRAM, requires a long address to 7exxxx or 7fxxxx, which the compiler would never generate.

I suppose you could inline assembly a "push bank number" B ... (PHB) and use regular 16-bit addresses. I guess there could be workarounds.

And, I suppose you could force the direct page to be at 0000, and work like the NES zero page.

Maybe you could write a function in asm that could handle long JSR calls... but those require return long, so I don't know how you would handle that (cc65 would only generate code that end in RTS). I would be very nervous about writing code in one bank that calls a function in another bank.

(edited twice)

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


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Sun Jan 27, 2019 8:12 pm 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3724
Location: Indianapolis
I've been wondering about using cc65 with SNES also. As far as I know, no one has done that, so there aren't any SNES examples for cc65 specifically. I think just writing the SNES-specific parts in asm, cc65 should work just fine. The CPU is 1.5 to 2 times faster than NES, it couldn't be any worse than using it on NES. There should be examples using ca65, you would have to adapt those or write new ones that are similar to the NES library you currently use.


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Sun Jan 27, 2019 8:17 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 8559
Location: Seattle
dougeff wrote:
I suppose you could inline assembly a "push bank number" B ... (PHB) and use regular 16-bit addresses. I guess there could be workarounds.
Yeah, I think it'd be most straightforward to set it up such that B is always the $7F page, and only use explicit DMA loads to move things from ROM in other banks into RAM or the PPU as necessary...

Quote:
Maybe you could write a function in asm that could handle long JSR calls... but those require return long, so I don't know how you would handle that (cc65 would only generate code that end in RTS). I would be very nervous about writing code in one bank that calls a function in another bank.
Well, calima did already add explicit trampoline support to cc65, for inter-bank calls on (I think?) the NES. I don't see why they couldn't be made to work on the SNES.

Memblers wrote:
I've been wondering about using cc65 with SNES also. As far as I know, no one has done that
Thefox has said he's done it for "small tests", but I don't remember if he's released anything.

As thefox said there, at worst you can leave the "E" bit set on the 65816 core, and just stick with the constraints of 8K RAM and 32K ROM for the CPU. You could even put tile data in higher banks because the DMA registers require special handling anyway, and ignore the E bit.


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Sun Jan 27, 2019 11:45 pm 
Offline

Joined: Tue Feb 07, 2017 2:03 am
Posts: 757
If you are using C you don't care about pushing the machine or speed, so running the SNES in E mode at 3.58 mhz would be fine and a solid boost over the NES.

But if you want to get stuff pushing the SNES more you would probably be better of using a 65816 C port, of which OCRA /C is probably the best, or the WDC one.

Wasn't Sydney Hunter SNES written in C?


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Mon Jan 28, 2019 2:26 am 
Offline

Joined: Tue Oct 06, 2015 10:16 am
Posts: 966
I'm not sure about Sydney Hunter, but I believe it was tcc-816, like a few of Shiru's titles. Of SNES projects I was a part of, two are shipping and some are underway. Little Medusa SNES was cc65, running in RAM, emulating bankswitches with DMA like lidnariq described above. Fork Parker was an asm project (ca65). A project I'm currently writing runs on cc65 with a "one 32kb bank for code, one for rodata, with tile data stored elsewhere", and future projects will use the most flexible "trampoline in RAM" setup, letting cc65 access all lorom banks.

Folks above are correct on most points. cc65 cannot use 16-bit code or long addressing, but it generates correct code (unlike tcc-816), doesn't crash (unlike tcc-816), in general it works. I don't find the 8kb RAM limit that bad, anything you'd put in the larger 64kb RAM banks is likely map data, and map data you will access with asm anyway for performance.

cc65 will use more advanced instructions that it knows of, 65c02 and so on, (ptr) without ,y, stz to name some. So the code generated is better than on NES.

I added the cc65 trampoline support for MMC3 originally, and several shipping titles use it. Some on other mappers too (UNROM, etc). It can be used for SNES too, by putting the trampoline in the low 8kb RAM. All jumps and returns are 16-bit local to that RAM location, it switches banks using self-modifying code jumping to itself.

Nothing I've written runs in the E(mulation) mode. It's all native 816 mode, but 8-bit AXY when running C. Some asm functions use 16-bit internally. I can't share any code I'm afraid, it's all written under contract. I've described these things in some previous threads on this, search with my username and cc65.


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Mon Jan 28, 2019 3:07 am 
Offline

Joined: Sun Jan 27, 2019 6:34 pm
Posts: 9
Thank you all for your answers. It is my first time doing something on SNES so I'm not yet familiar with all of that terminology. I will sure do more research on what you all said.
I'm asked to do it in cc65 so I suppose that the speed is not something that concerns the one who game this project.


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Mon Jan 28, 2019 8:40 am 
Offline

Joined: Sat Apr 25, 2015 1:47 pm
Posts: 436
Location: FL
Oziphantom wrote:
running the SNES in E mode at 3.58 mhz

Running at 3.58 mHz requires running out of bank 80 or higher, which isn't possible in emulation mode unless you plan on literally never using interrupts (otherwise PBR will be destroyed as soon as an interrupt occurs).

Also, while it still doesn't involve C, I also definitely endorse libSFX for ca65 users, it's quite a useful collection of macros/tools to make pure assembly development a much smoother process.


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Mon Jan 28, 2019 12:55 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 4208
Location: A world gone mad
The short of it is that you shouldn't use cc65/ca65 for SNES/65816 work, unless you're planning on doing something "small-ish", and predominantly uses "8-bit everything" (I'm intentionally being vague/nebulous here to keep it simple). calima's post is a good example of how someone went to great extremes (read: many self-coded workarounds that aren't necessary if using a different assembler).

Whoever is instilling this assembler requirement on you is obviously unfamiliar with the limitations of cc65/ca65 on 65816. Shame on them. Show them this thread and maybe they'll relax their requirement and you can get some actual work done. :)


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Mon Jan 28, 2019 1:57 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7582
Location: Canada
koitsu wrote:
Whoever is instilling this assembler requirement on you is obviously unfamiliar with the limitations of cc65/ca65 on 65816. Shame on them. Show them this thread and maybe they'll relax their requirement and you can get some actual work done. :)

Nobody in this thread has anything to say about limitations of the ca65 assembler, only the C compiler. Perhaps you could be a little less vague about what it is you think is wrong with it?

As far as I've used it, I consider it a word-class assembler, 65816 mode included. I've seen you say that you don't like it for SNES more than once, but to my memory I've tried to ask and never managed to get you to state a specific problem you've had with it in that respect.

(The most recent example that comes to mind is this thread where you complained vaguely about how some assemblers do their addressing modes, and I asked you to clarify, but as far as I could tell in that thread ca65 actually does have the addressing behaviour you were advocating for.)

And if there is some other assembler you think is a better alternative, why did you not even say which one that is?? You just came here to say "ca65 sucks, bye"??


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Mon Jan 28, 2019 2:36 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21591
Location: NE Indiana, USA (NTSC)
Perhaps "a better assembler" is the assembler whose syntax a better C compiler, such as ORCA/C or WDC's, is capable of producing.

_________________
Pin Eight | Twitter | GitHub | Patreon


Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Mon Jan 28, 2019 2:37 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7582
Location: Canada
Tepples, could you please let koitsu speak for himself.

(To clarify: I want to know what koitsu thinks, not what tepples guesses koitsu thinks. If you do have experience with other C compilers that would be relevant to this conversation though, by all means please describe what you know.)


Last edited by rainwarrior on Mon Jan 28, 2019 4:30 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Snes cc65
PostPosted: Mon Jan 28, 2019 4:01 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2562
Location: DIGDUG
By the way, I think that the nesdev community should maybe improve the current SNES toolset. Among those could be a C library. I would use them, but I've been too busy to work on anything myself.

I keep expecting shiru to come swooping in on a rope and drop all the tools I need, and disappear again like Keyser Söze. (I bet you're thinking, Keyser Söze didn't swoop in on a rope, but, hey, you don't know his unwritten backstory... maybe he swoops on ropes in his free time, off screen)

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


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: nocash and 2 guests


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