C compilers for 65816

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
JustClaire
Posts: 18
Joined: 27 Feb 2020

C compilers for 65816

Post by JustClaire »

Hello

This is the topic that have probably been touched 1000 times before, but here i am, bringing it up again.

What good C compilers for 816 are there? To be good it needs to work(obviously) and produce efficient enough code(after all we dont have gigabytes of memory space to work with).

I've heard that the WDC compiler is not the best option and also have seen some other compilers that have been either abandoned or dont support 816 fully and/or are heavily targeted towards a specific 6502 system(c64, apple2, nes, etc.) so i am pretty confused what are currently the best options for compilers.

EDIT:
Just to clarify, by "heavily targeted" i meant when a compiler supports 6502 with all the popular target platforms and some (sometimes semi-working) support for 816 on the side
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: C compilers for 65816

Post by BigEd »

I've a feeling that WDC's offering might be the best option, by being the only one. But it would be good to hear that this is not so.

The '02 is, it seems, not a great match(*) for C. It feels like it should be that the '816 is a better match, but then I'm not an expert on compilers. I have found that the '816 is quite a peculiar beast and takes a bit of getting used to, and I would think it could only be well-targeted by someone who had got to know it quite well.

Perhaps the SNES and the IIGS are the places to look?

(*) Not a terrible match either: the few HP calculators built on 6502-like micros were, I believe, written in C, and were successful enough. If the output of the compiler is good enough, it doesn't matter too much that it's not as good as hand-crafted code. It might help also if the C in question is written with sympathy for the machine it will execute on.
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

Re: C compilers for 65816

Post by BitWise »

WDC's 816 compiler generates OK code and unlike the 65C02 compiler does not crash when encountering an error.

The free copy doesn't include the assembler source for the startup module but you can get the code you need from this project.

https://github.com/andrew-jacobs/w65c816sxb-cdemo.

Try to avoid using stdio.h functions if you want a small program.
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
User avatar
drogon
Posts: 1671
Joined: 14 Feb 2018
Location: Scotland
Contact:

Re: C compilers for 65816

Post by drogon »

BitWise wrote:
WDC's 816 compiler generates OK code and unlike the 65C02 compiler does not crash when encountering an error.

The free copy doesn't include the assembler source for the startup module but you can get the code you need from this project.

https://github.com/andrew-jacobs/w65c816sxb-cdemo.

Try to avoid using stdio.h functions if you want a small program.
Although I've now completely moved away from C on the '816 there is a small task I'm looking at where C may be better than the BCPL I'm currently using, but the question I have is; Does it provide some sort of loader to help move code segments into the correct banks before program startup, or is this what the startup module is for?

Thanks,

-Gordon
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

Re: C compilers for 65816

Post by BitWise »

drogon wrote:
BitWise wrote:
WDC's 816 compiler generates OK code and unlike the 65C02 compiler does not crash when encountering an error.

The free copy doesn't include the assembler source for the startup module but you can get the code you need from this project.

https://github.com/andrew-jacobs/w65c816sxb-cdemo.

Try to avoid using stdio.h functions if you want a small program.
Although I've now completely moved away from C on the '816 there is a small task I'm looking at where C may be better than the BCPL I'm currently using, but the question I have is; Does it provide some sort of loader to help move code segments into the correct banks before program startup, or is this what the startup module is for?

Thanks,

-Gordon
I've not tried it but the linker supports building a image that contains relocatable code/data that is built for a different area (-C18000,8000 => link as if at $01:8000 but place at $00:8000 -- same for data with -Dxxxx,yyyy). You'd have to a write a custom startup module to use the addresses provided by the linker (during linking) to create a lda #/ldx #/ldy #/mvn code sequence that relocates code and the same for initialised data.
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
Post Reply