We've just updated MediaWiki and its underlying software. If anything doesn't look or work quite right, please mention it to us. --RanAS

65c816

From SnesLab
Jump to: navigation, search

The 65c816 is a 16-bit capable CPU originally developed by the Western Design Center, as an extension to the 8-bit MOS 6502. The Super Nintendo Entertainment System uses a CPU called the 5A22, which is a customized 65c816 chip manufactured by Ricoh for use in the aforementioned Nintendo product. Other products using the 65c816 include the Apple IIgs.

Interestingly enough, the predecessor of the SNES, the NES, used a customized 6502 (called the 2A03) also manufactured by Ricoh.

Programming the 65c816

65c816 machine language is the native language of the 65c816 CPU. It can be translated to (disassembling) and from (assembling) 65c816 assembler language code (or ASM for short), which is the same thing as 65c816 machine language, but is represented using text instead of raw binary, in order to make it easier for people to understand.

Because the 65c816's instruction set is a superset of that of the 6502, a relatively common 8-bit processor back in the 80s, the 65c816 is also compatible with 6502 machine language, fully compatible in emulation mode. This was handy for developers wanting to port games from the NES (which used a custom 6502 chip) to the SNES, because the code itself would require few changes. Graphics, music, etc. would require more work to port over. What this means for hackers is that there is another whole library of code to pick from.

65c816 code in Super Mario World

The Super Mario World ROM, like that of all other SNES games, consists mostly of 65c816 code, that causes the game to work. Changing this code will change how the game works (or stop it from working). Changing the code can be done by editing the raw machine language with a hex editor (yuck!) or by using a patching assembler (a better choice). A patching assembler, such as xkas, overwrites game code with code of your own, that you put in a text file in 65c816 ASM format. Your code is translated into machine language that can be read and executed by the SNES's 65c816 processor, or an emulator.

Custom blocks, sprites and patches for Super Mario World hacks contain 65c816 code as well, but often in such a manner that the person using them does not need to know that the code is there, in much the same way knowledge of Super Mario World's internal design is not required to simply play the game.

Instruction set

65c816 ASM consists of approximately 91 mnemonics, where most of them has different addressing modes. The mnemonics are composed by a 3-letter 8-bit instruction sometimes along with an 8-bit/16-bit/24-bit parameter byte(s). Opcode WDM (#$42) is not used. There are 3 registers which get used along with the instructions: Register A, X and Y.

A full list of opcodes can be found on the 65c816 instructions article.

Tutorials

There are multiple tutorials out there for 65c816 ASM. There are some located at RHDN. There are also some at SMWCentral, submitted by various users. Please refer to the external links.

See Also