Monday, November 9, 2009

Sprite Field Coordinates

Since the Super Nintendo's OAM (object attribute memory) uses a 9-bit x and an 8-bit y screen coordinate, and the screen is 256x224 pixels big, you may think 16-bit field coordinates is the best approach since the top 8 bits will be what screen, and the bottom 8 bits will be what pixel of the screen, but there is a catch. You'd only be able to increment using whole numbers like 1 and 2 pixels per frame. If you need something inbetween like 1.5 pixels per frame you need decimal bits. If you do 16-bit whole numbers and 16-bit decimals such as this:

ssssssssttttpppp dddddddddddddddd
s: screen
t: tile
p: pixel
d: decimal

it will require 32-bit math which the 65816 isn't very good at. Thankfully there is a better way of doing this:

ssssttttppppdddd
s: screen
t: tile
p: pixel
d: decimal

This is not just optimistic because it uses 16-bit math which the 65816 IS good at. It also makes sprite-tile collision way easier. All you need to do is combine both top bytes of both x and y coordinates to calculate the correct tile number the sprite is overlapping.

Sunday, November 1, 2009

Why your Super Nintendo codes don't work sometimes

Beleive it or not you could be the best Super Nintendo programmer in history and not even know it. What makes a good Super Nintendo programmer is the ability to come up with ways around limitations. The only issue is there is bad documentation on issues such as interrupts and stacks which seem unimportant but can really glitch up your code if you don't set them up the correct way.

For the last few months I've been working on a MegaMan-like action game, but I've ran into a problem early on that took me a long time to fix. I was trying to program the AI/physics of the player sprite, but everything I did glitched out. I asked other people to tell me what I'm doing wrong, they asked me for my source code and I gave it to them. This was 3 weeks ago and they still never answered me. I've got it to work correctly before they were even able to answer me.

To solve the problem I had to keep tinkering with the interrupts and stack until I finally got it right. I doubt the people who are taking me so long to answer this problem actually know themselves, simply because you can search all you want but there isn't any good documents that deal with interrupts and stack enough for anyone to completely understand it.