Author Topic: SNES SDK Optimization  (Read 3647 times)

0 Members and 1 Guest are viewing this topic.

Offline AndiNo

  • Newbie
  • *
  • Posts: 17
  • NEO newbie
SNES SDK Optimization
« on: July 21, 2010, 05:47:14 PM »
Everything I heard up to now regarding C code on the SNES was something like "C for game logic, ASM for everything graphics/sound/etc related stuff". My question is: Is it possible that some of you ASM proficient guys (like mic_ for example) can rewrite the parts of C code in the SDK that are speed critical (like those DMA transfers etc of which I don't know anything) ? Or do you think there wouldn't be much difference in a game's speed that's written in C? From what I know the creator of the SDK rewrote such parts from ASM to C, however speed-wise this doesn't make sense to me.

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: SNES SDK Optimization
« Reply #2 on: July 21, 2010, 07:44:34 PM »
For initiating a DMA transfer it doesn't matter if you use C or asm since the setup time is so small relative to how long the DMA transfer will last.

Depending on how heavy your calculations are you can probably get away with doing most of the work in C. Do all the updates to buffers in RAM during the active display period, and DMA the buffers to VRAM when the next vblank occurs. Just avoid putting any C code in your vblank routine. At least anything but the simplest of things (like starting the DMA transfers). I'd recommend writing all loops that you know are going to be executed a lot of times in asm, because C code will almost certainly be at least twice as slow even after going through the optimizers.

For sound I don't think you've got much of an option. There are no C compilers for the SPC-700 that I know of, and even if there was it wouldn't make much sense to use it because of the limited amount of memory and processing power of the SPC. But you don't necessarily have to write your own sound driver. There are MOD/XM playback drivers available for example.

Offline AndiNo

  • Newbie
  • *
  • Posts: 17
  • NEO newbie
Re: SNES SDK Optimization
« Reply #3 on: July 21, 2010, 09:57:36 PM »
Thanks for your answers! However I'm not sure if that answers my question :)
So you think rewriting the given C code to ASM wouldn't be necessary or helpful? Are you referring to the snesc_vblank function in init.c?
Anyway, my idea was that writing a game in C could be sped up by rewriting specific parts of the SDK in ASM which could then be used by all games which use the SDK. I do not mean rewriting the GAME in ASM, only the speed critical parts of the SDK (at least that of which I think they are critical).

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: SNES SDK Optimization
« Reply #4 on: July 22, 2010, 12:23:35 AM »
Yeah, I was talking about snesc_vblank, although you can replace it with your own handler in snes_init.

Parts of the libraries that come with the SDK are already written in asm. Like memcpy, memset, strlen. You may want to avoid the standard multiply / division / modulo routines and use some that take advantage of the SNES's hardware multiplier/divider. I've got a couple of division / modulo routines here (C prototypes here).

Offline AndiNo

  • Newbie
  • *
  • Posts: 17
  • NEO newbie
Re: SNES SDK Optimization
« Reply #5 on: July 22, 2010, 12:30:35 AM »
Now THIS is what I was talking about! :) Do you have any idea how they compare to the standard operators? And do you plan to create any more of these replacements?

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: SNES SDK Optimization
« Reply #6 on: July 22, 2010, 01:05:15 AM »
No I haven't compared them. There isn't really that much more to do as far as math is concerned, unless you start messing with the DSP-1 chip, but I can't help you with that. Multiplication can be done similar to division, but uses registers $4202/$4203/$4216/$4217.

Offline AndiNo

  • Newbie
  • *
  • Posts: 17
  • NEO newbie
Re: SNES SDK Optimization
« Reply #7 on: July 22, 2010, 08:08:57 PM »
Well anyway, it's a start :)
Thanks for your help!