📄 qsnesdoc.html
字号:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="David Piepgrass">
<META NAME="GENERATOR" CONTENT="Mozilla/4.03 [en] (Win95; I) [Netscape]">
<TITLE>SNES Graphics Information</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#A8F0FF" LINK="#003300" VLINK="#000099" ALINK="#990000">
<CENTER><FONT FACE="Comic Sans MS"><FONT SIZE=+2>Qwertie's SNES Documentation</FONT></FONT></CENTER>
<CENTER><FONT FACE="Comic Sans MS">Plus DMA</FONT></CENTER>
<CENTER><FONT FACE="Comic Sans MS">Revision 6 <FONT SIZE=-1>(2.1)</FONT></FONT></CENTER>
<P>I've almost reached a point where my doc is a total drop-in replacement
for Yoshi's v2.30 document, which hasn't been updated in years. It's
a shame that we emu authors have had to put up with that document and it
was no small task to write something better.
<P>This repeats most everything contained in Yoshi's doc, but expands on
it in much greater detail, in better and less ambiguous English.
Since it is in HTML, it's got plenty of cross-references. I, myself,
read this document when I can't remember something about the SNES.
It is designed as a sort of compromise, intended to be read by both SNES
developers and emulator authors.
<P>It used to cover only graphics, but now also covers DMA, HDMA, Indirect
HDMA, joypad registers (including the old-style reading method, which is
not covered by Yoshi's doc), and Windowing.
<P>Note: Unless otherwise stated, all 16-bit number values in this document
should be assumed to be in big-endian (is that what it's called?) format,
where the least significant byte occupies the lower memory location and
the high byte occupies the following memory location.
<P><FONT FACE="Arial,Helvetica"><FONT SIZE=+3>Table of Contents</FONT></FONT>
<P> 1. <A HREF="#Terminology">SNES Graphics Terminology</A>
<BR> 2. <A HREF="#PPUMemoryTypes">Types of PPU memory</A>
<BR> 3. <A HREF="#GraphicsOrganization">How basic SNES
graphics are organized in the PPU</A>
<BR> 3.1. <A HREF="#BGBasics">BG
Basics</A>
<BR> 3.2. <A HREF="#SpriteBasics">Sprite
Basics</A>
<BR> 4. <A HREF="#GraphicsFormat">The SNES graphics format</A>
<BR> 4.2 <A HREF="#Mode7GrFormat">Mode
7 Graphics Format</A>
<BR> 5. <A HREF="#RegisterReference">Register Reference</A>
<BR> 5.1 <A HREF="#RegOAM">OAM
Registers</A>
<BR> 5.2 <A HREF="#RegColor">Color
Registers</A>
<BR> 5.3 <A HREF="#RegVRAM">VRAM
Transfer Control Registers</A>
<BR> 5.4 <A HREF="#RegVideo">Video
Registers</A>
<BR> 5.5 <A HREF="#RegCounter">Counter/IRQ/VBL/NMI
registers</A>
<BR> 5.6 <A HREF="#RegWindows">Windowing
registers</A>
<BR> 5.7 <A HREF="RegJoypad">Joypad
registers</A>
<BR> 5.8 <A HREF="#RegDMA">DMA
Registers</A>
<BR> 6. <A HREF="#DMATransfers">DMA/HDMA tutorial and
reference</A>
<CENTER> </CENTER>
<CENTER><A NAME="Terminology"></A><FONT SIZE=+2>SNES Graphics Terminology</FONT></CENTER>
<UL>
<LI>
PPU: Picture processing unit. It is the thing that takes your SNES graphics
data and turns it into an image on the TV screen.</LI>
<LI>
VRAM: Video RAM. 64K of memory where tiles and tile maps are stored</LI>
<LI>
Registers: Memory-mapped I/O ports used for sending data and commands to
the PPU.</LI>
<LI>
OAM (also known as OBJ, object, or sprite info): Information about the
sprites on the screen, or the memory that contains this information. OAM
stands for "Object Attribute Memory".</LI>
<LI>
CG: Color palette data, or the memory that stores it. There are 256 palette
entries which contain the 15-bit absolute color levels.</LI>
<LI>
SC: Screen. Usually refers to the tile map for a BG, which is stored in
VRAM.</LI>
<LI>
BG: Background. There are up to 4 BGs, or "layers", of tiles that form
the basis of SNES graphics. These BGs can be scrolled, and a special type
of BG, in "Mode 7", can be scaled and rotated and stuff to look 3-D.
Sometimes the term "plane" (scrolling plane, as opposed to color plane)
is used (BG1=Plane 0, BG2=Plane 1, etc.)</LI>
<LI>
Sprites: Everybody knows what these are, come on. They are the little (well,
they can be up to 64x64 pixels on the SNES) graphics usually used for individual
moving objects in a game.</LI>
<LI>
Tile map (a.k.a. BG Matrix): A BG is made up of hundreds of tiles, which
are simply little graphics of a certain size (8x8, and 16x16 which is made
of 4 8x8 tiles) placed end-to-end. A tile map is a two-dimensional array
which contains a tile number and other properties for each square on the
BG. Note that, depending on the context, the word "tile" may refer to the
two-byte entry in the tile map, or else data for an 8x8 graphic character.</LI>
<LI>
Character: the graphic data (pixels) for a tile.</LI>
<LI>
Priority: Attribute that determines, or helps to determine, the order in
which BGs and sprites are drawn on the screen.</LI>
</UL>
<CENTER><A NAME="PPUMemoryTypes"></A><FONT SIZE=+2>Types of PPU Memory</FONT></CENTER>
<P>There are three memory areas where different kinds of graphics data
are stored, as well as the registers (located in the reserved 65816 address
space between $2000 and $5FFF) which set certain screen parameters.
<P>The main data area is the VRAM, a 64 KB memory space that can be accessed
with registers <A HREF="#Reg2115">$2115</A>, $<A HREF="#Reg2116">2116</A>,
$<A HREF="#Reg2118">2118</A>, and $<A HREF="#Reg2139">2139</A>. This
area is used for storing all the tiles used in your game, as well as the
tile maps.
<P>The second data area, the OAM, is used to store properties of the sprites.
It includes information about position, size, priority, etc. There can
be 128 objects maximum, and the memory is 544 bytes: the first 512 bytes
have four bytes of information per sprite, and the last 32 bytes have two
more bits of information. Two or more sprites can share the same
set of tiles.
<P>The third area is the CGRAM, where the palette data is stored. It is
512 bytes: two bytes, and fifteen bits, for each of the 256 on-screen colors.
There are five bits for each primary color (red, green, and blue).
<CENTER> </CENTER>
<CENTER><A NAME="GraphicsOrganization"></A><FONT SIZE=+3>The SNES PPU Graphics
Organization</FONT></CENTER>
<P><A NAME="BGBasics"></A><FONT SIZE=+1>Basics of BGs</FONT>
<P>In <A HREF="#PPUMemoryTypes">VRAM</A> there is a two-dimensional array
that is a <A HREF="#Terminology">map</A> of the tiles on the screen. Depending
on the setting of <A HREF="#Reg2107">registers $2107 to $210A</A>, this
map may be 32x32, 32x64, 64x32 or 64x64 tiles in size (see a note in the
register description about the format of maps larger than 32 tiles wide
or high). Each of the entries in this map contain the following data:
<PRE>High Low Legend-> c: Starting character (tile) number
vhopppcc cccccccc h: horizontal flip v: vertical flip
p: palette number o: priority bit</PRE>
The character number indexes into an "array of tiles" starting at a base
VRAM location selected by <A HREF="#Reg210B">registers $210B or $210C</A>.
The byte address in VRAM where the character data starts can be found using
the following calculation:
<BR> address_of_character = (base_location_bits <<
13) + (8 * color_depth * character_number);
<BR>This formula works in both 8x8 and <A HREF="#Reg2107">16x16 tile mode</A>.
For example, if base location 1 is selected, the color depth for the tile
map is 4 bits (16 colors), and character number 1 is selected, the address
will be (1<<13)+8*4*1 = 8224.
<BR>Note that the word address entered into the <A HREF="#Reg2116">VRAM
address register</A> will be half of that, or 4112.
<P>Except when using 256-color <A HREF="#Terminology">BGs</A>, the palette
bits determine what colors in the <A HREF="#Terminology">CGRAM</A> will
be mapped to the colors in the character. The number formed by the palette
bits is multiplied by the number of colors in the BG to get the starting
index in the color palette. For example, if palette 3 is selected in 16
color mode, the tile's colors will range from CG entries 48 to 63.
However, entry #48 will be unused since this is mapped from color 0, which
is always the 'transparent color'. Notice that, except in a 256-color
mode, it is not possible to select colors above 127. That's okay;
the sprites use these colors. Also, except in Mode 0 (see <A HREF="#Reg2105">register
$2105</A>), four color BGs may only use colors 1 to 31.
<P>The horizontal and vertical flip bits, if set to 1, will cause the characters
to be mirrored when shown on the screen, so that they are facing the opposite
direction. When in 16x16 tile mode, the entire tile is flipped (pixel 0
is swapped with pixel 15) rather than the individual 8x8 sub tiles being
flipped.
<P>The <A HREF="#Terminology">priority</A> bit has the effect of deciding
whether a given tile is 'on top of' or behind other BGs and sprites.
For more information on the drawing order, see bit 3 of <A HREF="#Reg2105">register
$2105</A>.
<P><A NAME="SpriteBasics"></A><FONT SIZE=+1>Basics of sprites</FONT>
<P>All SNES <A HREF="#Terminology">sprites</A> are 16 colors. The
SNES can have two sizes of sprites on the screen at once; the two sizes
are selected with bits 5-7 of <A HREF="#Reg2101">register $2101</A>.
The <A HREF="#Terminology">character data</A> for sprites is stored in
<A HREF="#PPUMemoryTypes">VRAM</A>, in the same format as <A HREF="#Terminology">BG</A>
tiles. Two or more sprites can share the same set of tiles.
When the sprites are larger than 8x8, they are arranged in columns, followed
by rows of 8x8 tiles. For example, a 32x32 sprite is stored like
this:
<PRE>Byte Offset 0 32 64 96 128 160 192 224 256 ... et cetera.
Tile Coord (0,0) (8,0) (16,0) (24,0) (0,8) (8,8) (16,8) (24,8) (0,16) ... and so on.</PRE>
Now that you've consumed the above information, realize that it is not
completely correct. The SNES has one more display quirk that is thrown
into the mix: all of the rows must be stored 16 tiles apart (i.e. 512 bytes,
or 256 words.) This means that, if there was one 32x32 sprite in
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -