Page 1 of 1

General Purpose Registers and Where to Find Them

Posted: Mon Dec 26, 2016 8:04 pm
by cleverName
Hey guys, I'm somewhat new to SNES assembly language. I've been reading through the articles on superfamicom and most of it is making pretty decent sense, at least as much as it should after a week or so of studying it. Anyway, I'm attempting to write some simple game logic but for whatever reason I seem to be stuck on finding open registers I can use. It seems like everything is being used by something like OAM or DMA.

My question is how am I supposed to find registers I can store any values I need to remember? Do I just pick registers and see if it screws anything up? I saw some of the memory maps on superfamicom but they don't make a whole lot of sense to me.

Sorry to bother you guys with such a simple question haha. Thanks in advance

Re: General Purpose Registers and Where to Find Them

Posted: Mon Dec 26, 2016 8:32 pm
by tepples
Memory at $7E0000-$7FFFFF is free for your use. Additionally, $7E0000-$7E1FFF is mirrored into $0000-$1FFF of banks $00 through $3F and $80 through $BF, so that you can use it as direct page and stack.

Have you programmed for any other 65816-based platform, such as the Apple IIGS?

Re: General Purpose Registers and Where to Find Them

Posted: Mon Dec 26, 2016 8:41 pm
by cleverName
Oh gotcha, thanks! Sadly no... This is actually the only project I've ever attempted for any kind of assembly language. I've read that 65816 isn't the best place to start, but I find it interesting so I'm trying my hand at it.

Re: General Purpose Registers and Where to Find Them

Posted: Mon Dec 26, 2016 9:20 pm
by dougeff
open registers I can use. It seems like everything is being used by something like OAM or DMA.
Just so you are clear...'registers' at $2100-421f are hardware registers and not processor registers.

65816 has 3 ...16-bit registers, called A,X,Y. Only A can do math and bit shifts/ AND/OR. Therefore, I only consider A to be the general purpose register.

X and Y are typically used for indexing an array, or dereferencing a pointer, or counting loops. They can also be used for finding variables pushed onto the stack with stack relative addressing.

Like tepples said, use the direct page as temporary holders of values. (Or perhaps the stack).

Re: General Purpose Registers and Where to Find Them

Posted: Tue Dec 27, 2016 1:17 pm
by qwertymodo
Yeah, there really aren't any GPR's, at least not like what you'd see on other architectures. You have the accumulator, the two index registers, and that's pretty much it. It's designed with external memory in mind, which is why you'll see so many instructions with several different addressing variants for operands. Typically the reason for using GPR's is for faster operation, and you can achieve that result using direct-page memory as others have mentioned. A lot of games will use bytes $00-0F in the direct page as local scratchpad, much the same as you would typically use GPR's on other architectures like MIPS (the s/t registers there are a godsend...). Check the superfamicom wiki opcode page, they list the cycle count for all of the opcodes, which should help you figure out how to set up your code to use the faster addressing modes.

Re: General Purpose Registers and Where to Find Them

Posted: Tue Dec 27, 2016 9:12 pm
by Memblers
If it helps too, you can find tons of docs, tutorials, simulators, and books for 6502 because that CPU was everywhere. The 65816 is 100% backwards-compatible with the 6502. So that could be a useful way to start out with the basics.

Re: General Purpose Registers and Where to Find Them

Posted: Wed Dec 28, 2016 12:52 am
by 93143
There are a few differences between the 65816 in emulation mode and the 6502. This includes a couple of bugfixes, but the main difference is that the 6502's unimplemented opcodes (which did unintended but occasionally useful stuff) are now in use as 65816 opcodes and thus do totally different things.

It is claimed that
Eyes and Lichty (1986) wrote:All existing 6502 software can be run by the new processor
but this seems to be weighted with the implication that a 6502 program using illegal opcodes isn't really a 6502 program...

Re: General Purpose Registers and Where to Find Them

Posted: Wed Dec 28, 2016 3:59 am
by koitsu
65816 emulation mode operates more like 65c02 than 6502. OP: do not get hung up on this part of the thread conversation.