It is currently Sun Nov 19, 2017 11:08 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed Aug 09, 2017 11:31 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19233
Location: NE Indiana, USA (NTSC)
In this post, calima wrote:
I was also looking at getting on the Gameboy [...] there are plenty of z80 C compilers.

I too was thinking about getting into Game Boy, largely to illustrate a point to the FamiTracker user community about using a Game Boy connected to the NES through a controller to Game Link cable as expansion audio.

As of 2017, which C compilers target LR35902? A compiler targeting Z80 is fine if it offers a choice to emit code that doesn't use IX, IY, and other Z80 features left out of the Game Boy's LR35902? Aspects to consider in your recommendation:

  • Which are free software?
  • Of non-free compilers, which are made for both Windows and GNU/Linux?
  • Of non-free compilers, which are available without charge?
  • Of non-free compilers available without charge, which may be used to emit code that will be included in a product that will be sold?
  • Which are maintained? GBDK is 16 years old.
  • Which support the largest subset of C, including useful features introduced in C99?
  • How well do they optimize?


Top
 Profile  
 
PostPosted: Wed Aug 09, 2017 11:32 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6446
Location: UK (temporarily)
GBDK uses an ancient release of SDCC, which is still maintained and still can target the LR35902.


Top
 Profile  
 
PostPosted: Wed Aug 09, 2017 12:04 pm 
Offline

Joined: Sun Mar 27, 2011 10:49 am
Posts: 206
Location: NYC
Yes, SDCC is AFAIK the only real choice. A generic Z80 compiler wouldn't come close to working - the instruction sets are far too different. The GB "Z80" is much more like a souped-up 8080, although it's not source compatible (I can't tell - it might be binary compatible [1] [2]).

I know that there probably were a few commercial GB games written in C. Or at least GBC games (that's Game Boy Color games, not Game Boy C games :wink:) - compiler technology had improved, memory restrictions were less severe, and the GBC could run twice as fast. But honestly, the code SDCC generates is terrible. Generating decent code for the GBZ80 from C is a Herculean task, so I can't fault it for this, but I also can't see how you'd write anything more significant than a tech demo in it without dipping down into assembly an awful lot.


Top
 Profile  
 
PostPosted: Thu Aug 10, 2017 2:19 am 
Offline

Joined: Tue May 28, 2013 5:49 am
Posts: 867
Location: Sweden
I guess the GBZ80 is like a Z80 with an 8080 instruction set plus a Z80 RETI and a few unique ones (including the zero page like LDH) and using a Z80 syntax. RETI has moved to a different spot compared to the Z80, but some of the other new instructions appears to have taken the place of 8080 and Z80 instructions, so I guess it's not fully binary compatible with 8080 either.

GBDK is the only C-compiler I've seen, but I've never bothered with it.

If assembler is fine I'd recommend RGBDS. It was apparently used in commercial GBC games back in the day since it's supposedly more versatile then Nintendo's official one. And it has a fork that is still maintained. It has a powerful macro language but also the syntax may be considered a bit weird at times. It seems to be the far most common assembler for Game Boy, and BGB supports its syntax and debug files in its debugger. Plus it's much better than WLA.


Top
 Profile  
 
PostPosted: Thu Aug 10, 2017 4:15 am 
Offline

Joined: Fri Oct 16, 2015 1:14 pm
Posts: 11
SDCC is probably your best option. Beware that GBDK ships with an ancient version (~2002?) of SDCC,
but the mainline version of SDCC also supports GBZ80, so you can use that instead.
And even now, SDCC sometimes generates really stupid code and has some weird quirks.

There is also gbdk-n, which makes the gbdk libraries compatible to modern SDCC versions.
I don't know how complete this is, but had no issues so far for my small test roms.


Top
 Profile  
 
PostPosted: Thu Aug 10, 2017 5:53 am 
Offline

Joined: Sun Mar 27, 2011 10:49 am
Posts: 206
Location: NYC
Pokun wrote:
If assembler is fine I'd recommend RGBDS. It was apparently used in commercial GBC games back in the day since it's supposedly more versatile then Nintendo's official one. And it has a fork that is still maintained. It has a powerful macro language but also the syntax may be considered a bit weird at times. It seems to be the far most common assembler for Game Boy, and BGB supports its syntax and debug files in its debugger. Plus it's much better than WLA.

Agreed, RGBDS is what I use.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 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