Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
This is what my blank "template.c" document looks like, I just finished setting up pvsneslib, but I have a few more questions: Where should I start writing code in the document, what files does the program accept for audio, and how do I make sure I don't trip the restrictions of the SNES, such as color restrictions and background ?

Great that you got the whole thing set up, that's the first step!

If you never programmed in C, I really recommend you to read books / websites / video tutorial about how to code on the language as the next step :).

To answer your question, you can (and will) write code anywhere is the file (more or less). The gameplay code will most likely go after the "put code here" comment. But when you want to use a variable, you'll have to declare it first, so you'll most likely declare the variables after the "#include <snes.h>" file. 

If you trip on color restrictions or audio restrictions, you'll usually see it when running the game on emulator: nothing will show, or the color will be wrong, etc. (retro game development is usually quite scare when it comes to debugging tools :p)

Regarding input, PVSNESlib is quite nice as it accepts:

- BMP for graphics (be careful of the color palette, it needs to have 256 color palette BMP with only the first 16 or 4 colors defined depending on the graphics mode you'll use - usually it'll be 16).

- IT (Impulse tracker) for music and sound effects, if you use the "non-streaming" function. I recommend OpenMPT as a program to create those music and audio files (it's arguably the best "modern" tracker program available) https://openmpt.org/

- WAV for sound effects if you use the streaming functions (beware, it does work well only on NTSC, and it's quite complex to use - I recommend sticking to IT file for beginning)

You can open the source code of Keep SNES alive to see an example of that, the archive contains everything: code, images, sound, music, etc.

But as I said, you should really start by learning how to code in C first, else you'll have an hard time doing anything meaningful. You don't need to take a full course, but at least to learn the "basics" (using and typing variables, loops, creating functions, etc.)

Thanks for all the answers. I've got a few youtube videos about learning C bookmarked, and I've got a few apps for learning C downloaded. As far as programming goes, do I need to worry about messing with the other files (data.asm, hdr.asm, Makefile) or not?

You'll need to modify those file along the way when you'll want to include graphics or audio:

- Makefile: this file contains instructions on how to compile the game into a valid SNES rom. Depending on your project, you might have to modify it to include the name of the graphics files / audio file to include into your project.

- data.asm : this file list where all the data (graphics, audio, tilemaps, etc) are going to be stored in the ROM. Basically a SNES rom is a combination of several "slots" (or "banks") of 32kb. This file is used to define what data goes were, and will have to be modified each time you want to add a new asset into the rom.

- hdr.asm: this file is the "rom header". The only thing you'll need to modify in it, is the game title, all the other params are OK for most projects :)

Regarding Makefile, I suggest you to read tutorial / watch video about how to use them too, as it's a common topic in many programming projects :).

The other aspects are specific to the SNES and PVSNESLib, and you'll find more details about them in the Wiki:

https://github.com/alekmaul/pvsneslib/wiki/Sprites

Actually, once you're more familiar with C, I suggest you to follow the tutorial steps from the wiki:

https://github.com/alekmaul/pvsneslib/wiki/Introduction

You'll learn how to display text and sprites on screen.

Do "data.asm" is a bank of sorts that holds the assets, and "template.c " pulls/references those assets?

Yes. To do the link, you'll simply import the definitions from data.asm as "extern variables" in your C file.

For example, in my data.asm I have the lines:

spritesGFX:
.incbin "sprites16.pic"
spritesGFX_end:

(the "sprites16.pic" file being a BMP file converted to the SNES format by PVSNESLib)

Then, in my C file, in the variable declarations I use the line:

extern char spritesGFX, spritesGFX_end;

Now I can use those variables in my code: "spritesGFX" is the beginning of the graphical data, while "spritesGFX_end" is their end.

That way, I can load the graphical data from the ROM to the VRAM using the following line:

oamInitGfxSet(&spritesGFX, (&spritesGFX_end-&spritesGFX), &spritesPAL, (&spritesPAL_end-&spritesPAL), 0, 0x4000, OBJ_SIZE16);

The "&" in front of the variable name is meant to indicate that I don't need the variable value, but their address in memory (well, in that case in ROM), as we'll use the start/end address to load the data in VRAM (at least, that's how PVSNESLib works!)

All this code comes directly for the source code of Keeping SNES Alive btw.

(+1)

Thanks for the directions! I'll start working on a pong-clone over the next few days to get the hang of C.