Today, I will continue to read the code since yesterday. Because I have a class today, I have a little dizzy today, so not not do it well, now I can only write it by memory.
I saw articles about DMA:
For example, suppose I Wanded to Copy A 32 x 32 Character
Screen Map (IE $ 800 BYTES) from location $ 18000 in Rom Into
Location $ 0000 of vram. I Could Do this sale dma channel 0
WITH THE FOLLOWING CODE (A is 8-bits, X & Y Are 16-bits).
LDX.W # $ 0000; Set vram Pointer to $ 0000
StX $ 2116
LDA # $ 01; Control Value for "Normal" DMA
STA $ 4300
LDA # $ 18; DMA to $ 2118
STA $ 4301
LDX.W # $ 8000; Source Offset
StX $ 4302
LDA # $ 01; Source Bank
STA $ 4304
LDX.W # $ 0800; Number of Bytes
StX $ 4305
LDA # $ 01; Enable DMA Channel 0
STA $ 420B
If he is not just a example, that is, the code is correct, then the address in the ROM should be 1D204's $ 78-byte space loaded to $ 2118, and $ 2118 is Video Port Data, I put this space out, Since this DATA is directly output to Video Port Data, I suspect that the algorithm that may be used is the graphic processing mode described in this article:
Sprite Doc
-------------------------------------------------- ------------
If You Haven't Already Obtained "Yoshi Doc", Get IT and Read It Before you
Read this doc ....
Part I - The BitPlane Representation of A 16 Color 8x8 Pixel Tile
-------------------------------------------------- ---------------
Sprites Are Made of Tiles, in Particular 4-BitPlane Tiles, 4-BitPlane
Tiles, Means That The Tiles Are Made of 4-Bit Color Values, So this Means
That The Tiles Can Have A Maximum of 16 Colors.
In Many Graphics Formats, this Type of Data Would Be Stored As Follows
(Assuming a 8 pixel by 8 pixel tile)
$ 1 $ 0 $ 2 $ 8 $ 2 $ 4 $ 5
$ 2 $ 6 $ 1 $ F $ E $ 1
$ 1 $ 2 $ 2 $ 6 $ 7 $ 0
$ 1 $ 0 $ 2 $ 8 $ 2 $ 4 $ 5
$ 1 $ 0 $ 2 $ 8 $ 2 $ 4 $ 5
$ 1 $ 0 $ 2 $ 8 $ 2 $ 4 $ 5
$ 1 $ 0 $ 2 $ 8 $ 2 $ 4 $ 5
$ 1 $ 0 $ 2 $ 8 $ 2 $ 4 $ 5
WHERE Each HEX Number Repesents a Color, So Pixel (0) Would Be ColorNumber "1", And Pixel (4, 2) Would Be Color "6" .... this is
On The Super Nintendo .... for Reasons Having to do with the importation
Of The Graphics Engine, The Super Nintendo Represents ITS Image Data in
The "Bitplane" format, Assuming and 8 Pixel by 8 Pixel Tile with 16
Colors, this Data Would Have Four Bitplanes (0-3) of Monochrome, Binary
Image Data:
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 2
0 0 0 0 0 0 0 0 1 2 3
0 0 0 0 0 0 0 0 1 2 3
0 0 0 0 0 0 0 0 1 2 3
0 0 0 0 0 0 0 0 1 2 3
0 0 0 0 0 0 0 0 1 2 3
1 1 1 1 1 1 1 1 2 3
2 2 2 2 2 2 2 2 3
3 3 3 3 3 3 3 3
Four Monochrome 8x8 Pixel images stacked on top of each other. if you
WANTED Pixel (4, 2) To Have The Color "6" You Would Have to Put A "1" in
BitPlane One, And A "1" in Bitplane Two, with the bitplane Zero and Three
Having "0" 's. this is because the binary representation of "6" IS "0110".
Ok, So it is obviouslyly Possible to Store Each Monochrome BitPlane In 8
Bytes, Each Byte Repensenting a Row in the bitplane. so a single tile
Takes Up 32 Bytes (8 BYtes Per Row * 8 Rows * 4 Bitplanes) of memory.
Part II - The Way Tiles Are Stored in Vram for Sprite Data
-------------------------------------------------- -------
In vram you store a Tile 16 Bits At a Time As Follows:
<------- 2 Bytes at a time ------>
<- 1 Byte Wide -> <- 1 byte Wide->
[Plane 0, ROW 0] [Plane 1, Row 0]
[Plane 0, ROW 1] [Plane 1, ROW 1]
[Plane 0, ROW 2] [Plane 1, Row 2]
.
.
.
[Plane 0, ROW 7] [Plane 1, Row 7]
[Plane 2, ROW 0] [Plane 2, Row 0]
[Plane 2, Row 1] [Plane 2, ROW 1]
[Plane 2, Row 2] [Plane 2, Row 2] ..
.
.
[Plane 2, ROW 7] [Plane 2, Row 7]
The Super Nintendo Can Have Two Different Sizes of Sprite on The Screen
At One Time, You Can Choose from The Following Combinations:
[Value] [sprite size 0] [Sprite size 1]
000 8x8 Pixel 16x16 Pixel
001 8x8 Pixel 32x32 Pixel
010 8x8 Pixel 64x64 Pixel
011 16x16 Pixel 32x32 Pixel
100 16x16 Pixel 64x64 Pixel
101 32x32 Pixel 64x64 Pixel
IT is set in the Upper Three Bits of Address $ 2101 ... so to use 8x8 Pixel
Sprites, and 32x32 Pixel Sprites, You Would Load $ 2101 with the value
"001xxxxx" (where x is don't cre)
The Lower Five Bits of Address $ 2101 Are Also Very Important, Thase Bits
Tell the super nintendo where in vram your sprites are located. The
Lowest Three Bits Are The "name base", and the fours and fiffh bits are the
"name". The "name" Bits Specify THE Upper 4k Word of The Sprite Address,
And the "name base" Specfies the offset. so if put you tile data in vram
$ 0000 You Would Set these Bits All to Zero.
Suppose you want to have four 32 Pixel by 32 Pixel Sprites; Each Would Be
Composed of 16 Tiles, Each Tile Is Numbered, Tiles $ 0- $ 3F
[sprite 0]
0 1 2 3
4 5 6 7
8 9 A b
C d e f
.
.
[Sprite 3]
30 31 32 33
34 35 36 37
38 39 3A 3B
3C 3D 3E 3F
In Vram, Tied Tile, $ 0 THROUGH TILE $ 3F Would Be Store in An Interlaced
Fashion As Follows:
$ $ 1 $ $ 6 $ $ 6 $ 21 $ 23 $ 30 $ 31 $ 32 $ 33
With $ 6 $ 6 $ 7 $ 14 $ 26 $ 27 $ 34 $ 35 $ 36 $ 37
Do you see the pattern? You Must Store The First Row (Four Tiles) of Each
Sprite, and the the second row, the the third, etc .... if you were dealing with 8x8 sprites, you would have to store the first
Row of 16 Sprites, The Second Row of The 16 Sprites, etc ....
IF you were dealing with 16x16 sprites, you have to store the first row
Of 8 Sprites, Then the Second, THEN THIRD, ETC ...
WITH 64X64, YEP, You Guessed It, The First Row of Two Sprites, THEN THE
Second Row, ETC ....
Part III - Setting Up The Oam Table for your sprites
-------------------------------------------------- ---
For Each Sprite In The Sprite Table (Maximum of 128 Sprites, Numbered 0-127)
You Must Have Four Bytes of Information, The First Byte Is The Low 8 Bits of
The horizontal position of the sprite, The second byte is the value
Position of the sprite, the third byte is the "address" of the sprite ...
It is not the actual vram address, it is the Tile Number, That Is To Say,
The Physical Vram Address of The Sprite Can Be Obtained by The Following:
Multiply The Sprite "Address" by 32 (Because Each Tile IS 32 BYTES) and add it
To the Starting Vram Address That You Set in the $ 2101 register.
THIS TILE NUMBER POINTS to the First Tile in The Sprite ... The Snes Expects the
REST of TILES TO FOLLOW IN THE ORDER Described in The Previous Section ...
The next byte containes the 9th bit of the tile "address" and a few attributes
Bit 0 = 9th bit
Bit 1-3 = PALETTE NUMBER
Bit 4,5 = Playfield Priority
Bit 6 = Horizontal Flip
Bit 7 = Horizonal Flip
The Palette Number Is Not a 4 Bit Number, So Obviously, You Can Only Choose
Between 8 of the 16 Palettes .... if you set these bits to all 0, you will be
Selecting The Eigth Palette (Palette 7), IF you set the "001" it is the bound of palette etc ... it Was Trial and Error, And Some
BEFORE I FigureD this one Out :)
To set these bytes in the oam table, you must first setup the Oam "Address"
On The 16 Bit Register $ 2102 (And $ 2103). Again this is not a real address,
You Use the 7 Lowest Bits of this Address to Select Which Sprite you
Would Like to Set The Data for (Sprite 0 to Sprite 127)
You Can Write The Four Bytes Discussed Above To The Register $ 2104, ITS
Like The Color Register, Auto Incrementing ...
So ... What are all the other bits for ??? (The Remaining 9) Well, I know About
Only Two Others, The Highest Bit (Bit 15) IS A Sprite Priority Bit, IT IS
Basically the bit you set to "turn on" The Sprite, And Keep It Being RedRawn
On The Screen ... Its a little more tris, But Thats All I Know About ITS
Behavior. So when setup your table, (and periodically throughout the
SPRITES 'DISPLAY Lifecycle) You Must Set this Bit High .... (for any sprite being
Displayed
There is another small table (32 bytes) That You Must Load Into the Oam, There
Consist of two bits for every sprite, one of the bits being the 9th horizontal
Position bit, and the other is the size select bit (Remember We Can Pick from
Two Different Size Sprites On The Screen At Celetes The First Bit Is The THE FIREEN ATH
Most Significant Horizontal Location, and The Second Is The size Toggle
Bit ...
To Write this Table The Oam, You Must Set The 9th Bit of The "Address" in $ 2103
To one .... Then Write the bytes, again it is an auto incrementing register
Make Sure That You Have Enabled The Sprites To Be On A Particular Plane (See
The Yoshi Doc, on $ 212c .... and make sure that you have set your palettecorRectly (Remember Sprite Palette 0 Is The 8th Palette !!!)
It seems to be a bit more ... but the translation of the wolf group, although I think there is a lot of mistakes in his translation, there will be a lot of misunderstandings.
About OAM Even if Sprite, I infered from the following content, it should be what I want:
In block, after completing the operation of the DMA, the next thing is the setting of BG1 ~ BG4 (BG4 is not used in the battle screen of Fe4)
The horizontal and vertical offset of these BGs and the generally displayed in the game are completed, and it is a segment of the SPU, which should be hitting the sound. Then return to Joypad.