I am assuming you are familiar with hex and binary.
A page of RAM is 256 bytes. $XX00-$XXFF.
On the NES, XX can be 00-07.
There is no need to load a picture. (at least not with the basic setup you will start with.) All the graphics you will use are just always there if you incbin'd the file as described in the tutorial.
Storing a number to location $4014 causes the PPU to copy a page of RAM to the PPU which will then display sprites using that information without any more of your input. The page of RAM that is copied is determined by the number written to $4014. You also must set the low byte where the transfer starts with $2003. This is usually #$00.
Code: Select all
lda #$00
sta $2003 ; set the low byte (00) of the RAM address
lda #$02;
sta $4014;$0200-$02FF is copied.
lda #$07
sta $4014;$0700-$07FF is copied.
The page of RAM you want to use for sprites is up to you. (It's not wise to use $00 or $01, though.)
Note that the write to $4014 should happen in your NMI interrupt code. (If you don't know what this is, ask and I'll explain that)
You will also want to enable rendering by writing the values you want to $2000 and $2001.
See here for what the bits of each register do.
Would start NMIs (you generally want them enabled if you want graphics), and set the tiles used for the background to the second half of your CHR-ROM. You can see how by looking at how the set bits correspond to the information in the wiki.
Will start displaying sprites and the background.
There are 64 sprites. So each sprite uses 4 bytes.
Let's say you're using page 2.
Byte 0 is the sprite's y position. So writing #$10 to $0200 would set one of the 64 sprite's y position to #$10. Writing #$20 to $0204 would set the next sprite's y position to #$20. Etc.
Byte 1 is the sprite's tile. Whatever byte you write here is the tile graphic the sprite will use. $0201 refers to one sprite. $0205 refers to the next. etc. To know which tile to write, load your rom in FCEUX and go to debug, PPU Viewer. Mouse over the graphic you want, and it will give you its tile number.
Byte 2 ($0202, $0206 etc) is broken down like this:
Code: Select all
76543210
||||||||
||||||++- Palette (4 to 7) of sprite
|||+++--- Unimplemented
||+------ Priority (0: in front of background; 1: behind background)
|+------- Flip sprite horizontally
+-------- Flip sprite vertically
But you can just write #$00 there for now.
Byte 3 ($0203, $0207) is the sprite's X position.
So to make a sprite appear, write its X and Y positions to the RAM in the page you have chosen for sprites. Then write its tile number.
The sprite will be drawn automatically next time the NMI interrupt happens. To move it, load its location, adc (or subtract) the number of pixels you want it to move by, and then store it's location.
Like that.