Thursday, March 30, 2006

SNES Frog Feast near complete

I finally wrestled the lcc816/cc65 compiler combination to the ground, and got Frog Feast working on the SNES. The only thing left to add is sound playback, and getting it on a cartridge!

Getting it to play correctly on a 256 pixel screen (vs. 320 for the other versions) wasn't a major problem. The player cannot miss the lily pad on outer edges, but this doesn't change the game much.

The SNES version isn't able to use the same game logic source code as the other versions, due to the fixes and optimizations needed for the SNES and the compiler.

I had to reorganize a lot of the functions so that they access VRAM right after the VBlank. This is a bigger problem on the SNES compared to any other system.

Here are the fixes needed to get it working with the compiler correctly:

The lcc816 compiler doesn't pass function correctly between C functions. This is mostly due to a missing macro which isn't supported under ca65 (due to it's more limited macro language compared to xa/ja). So, I had to set up global variable for parameter passing. Assembly language routines work find, because they pull the values relative to the stack pointer.

Many additions were made to the SED script to convert from xa/ja to ca65.
The compiler calls functions with a jsr, instead of a jsl.
All of the prologue/epilogue calls and setting the __caller variable are removed. The lda #xxxx part of this is still there, because I couldn't get SED to remove both lines.

The RSH and LSH macros were fixed. They didn't do multi shifts in the converted version.

I converted the jgte, jgteu, etc macros from ja to ca65. mreg and mreg2 are set as zeropage locations.

Some of the math functions from the runtime library were also put into the routines section.

The compiler complains when trying to get the 16 bit value of a 24 bit address. This was fixed in the compiler to generate (address&$FFFF)

Code such as Frogs[Loop].x generates a call to muli32, which is very slow. This was replaced with FrogPtr->x. FrogPtr is set to &Frogs[0], for example;

C continue and switch statements do not appear to work correctly. The switch statement was replaced with a set of if..else if.. lines. A function containing a continue statement had to be broken into two seperate functions (one for each frog), and the loop eliminated. The continue is replaced with a return.

The code was updated to a 2004 version from the lcc816 version. I'm not sure if this fixed anything.

Constant data tables have to be done in assembly (using .dcb), since all arrays are put into the DATA segment, which is discarded by the linker script.

The size of the mreg and mreg2 variables were mis-set to 2 instead of 4. This caused a lot of problems, but cannot be blamed on the compiler.

Most of the time and effort has been spent figuring out the compiler issues. But, it's definately rewarding to see it working correctly on the real system.

I will be releasing the compiler and related stuff once everything is done.

8 Comments:

At 1:20 AM, Blogger zach morgan said...

If you release the source to the snes version, it'll be the first FOSS snes game ever completed, afaik. I'd appreciate that a lot.

By the way, blogger made me sign up for a blog before I could post this.

 
At 10:51 PM, Blogger Charles said...

I will be releasing the source, once it's done.

 
At 8:15 AM, Blogger HenkZ said...

Hi, I'm currently doing some research into how to make a small SNES application (=game), and run it (on actual hardware). Will those cartridges run on an unmodified system ? From Europe ? If so, where did you buy those cartridges and their contents ? I can't call myself a SNES programmer until I get my game running on actual hardware.
To promote SNES development, I intend to buy "Frog Feast".

 
At 4:08 PM, Blogger MIPS said...

Nice work. It's a huge impediment when you have to wrestle with the tools. Congrats and thumbs up.

I used the excellent Zardoz compiler in the past and it appears that it is now the official WDC 65816 compiler. It has great memory model options and access to stack parameters (locals and autos) via fast dpage addressing.

Check it out on the WDC, crippled version is available free. Too bad it is expensive to buy.

 
At 1:57 PM, Blogger Charles said...

The WDC free version is very limited. I was hoping they would make it easy to use for SNES development.

 
At 1:59 PM, Blogger Charles said...

The game is written for NTSC, so that may cause a problem, but the cartridge will work on any SNES.

The cartridge is just a regular SNES game, with the rom replaced with an eprom containing Frog Feast.

 
At 6:56 AM, Blogger Björn said...

Hi Charles,

I would like to contact you by email sence I would like to start an Eclipse project for making SNES games...

My email is: bornemix * gmail.com , please drop me a line!

 
At 6:22 AM, Blogger Ed said...

Hi Charles: it looks like you got the SNES version out and have moved on to other platforms. Any chance you could release your latest lcc816? That would be great (even if it's incomplete)!

 

Post a Comment

<< Home