NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectBackground/Tiles & Sprites Movement  
Posted byAnonymous
Posted on1/3/02 2:55 PM
From IP65.80.88.160  



In the ROM that I am programming ( I am a beginner at programming these ROMs and all ), I can see no place where I have defined a pattern for the background, yet, it displays various tiles from my tileset all across the screen... How and where do I specify these tiles?

And on Sprites... how do I move one of two sprites with the push of a button? I know how to capture button presses, but, how do I change the X and Y values of a sprite?

Thanks,
Matt




SubjectRe: Background/Tiles & Sprites Movement new  
Posted byIndy
Posted on1/4/02 01:02 AM
From IP62.40.201.139  



First I recommend you to red the NesTech.txt (you can get it here: http://nesdev.parodius.com/ndox200.zip).

Background Tiles are defined in the nametable (the nametables are located in the VRAM from $2000 to $3000). The NES has 2 (independend) nametables - altough it has adressing space for 4 (so the 2 nametables are mirrored to the other 2 which makes 4). You specify the current nametable with the PPU control register 1 (which is in NES Memory @ memory location $2000). Then you have to write to this nametable (the numbers of your tiles) where one Byte in the nametable represents 1 tile. You can write to the VRAM with the help of 2 other registers:
The first register is the PPU Adressing register aka $2006. The first byte written to this register specifies the high part, the second byte the low part of a 16-bit adress (in the VRAM). You can now write to this adress in VRAM with register $2007 (write a value to $2007 and this one will be written to the VRAM location specified by the 16-bit adress). After each write to $2007 the adress is incremented (depending on $2000 content -> look in the nestech.txt) with 1 or 32.

Sprite RAM is accessed via 2 other registers - it works the same way as above - only that adresses are only 1 byte in size so you have to write only once to the adress register (you can look up the register in nestech.txt -):)). The format of the data in Sprite RAM is also descriped there.

I hope this helps a bit. Just read the document and you'll see that what i wrote will make sense -):D
If you still have questions - just ask

regards Martin




SubjectRe: Background/Tiles & Sprites Movement new  
Posted bymcmartin
Posted on1/4/02 08:55 AM
From IP204.216.188.80  



If you're moving a LOT of sprites, the DMA approach is better. The basic concept is to devote 256 bytes of memory just to your sprite data (which is the size of SPR-RAM, conveniently enough). Fiddle with that memory to your hearts content (following the conventions in NESTech.txt, as mentioned) and then write the high byte of your sprite memory to $4014.

As an example, in my tutor.nes file, the sprite data is kept in memory locations $0200-$02FF. I write a #$02 to $4014 and all the data is blasted into SPR-RAM.

--Michael




SubjectRe: Background/Tiles & Sprites Movement new  
Posted byAnonymous
Posted on1/5/02 2:02 PM
From IP65.80.88.160  



Thanks for all that info ( which I have already read and 99% comprehended ), but, that doesn't answer my original question... How do I MOVE my sprite once its up there?

Say I have two sprites up on the screen, how do I move the second one without affecting the first? How do I read the coordinates of the sprites, alter them, and write them back to the sprite data as to move them!?

Thanks for your trouble...
Matt





SubjectRe: Background/Tiles & Sprites Movement new  
Posted byIndy
Posted on1/5/02 3:57 PM
From IP62.40.201.139  



Well - I've never programmed a ROM for the Nes but the only way to move a sprite is to change it's x/y coordinate in the sprite ram. let's say your sprite ram looks like this:

first sprite second sprite
|$00|$01|$01|$00||$10|$02|$01|$10|

^here begins spram (adress 0)

These woud be 2 sprites - one at position 0/0 on screen, the sprite is tile #1. The other sprite would be displayed at position $10/$10 with tile #2. Now if you want to move sprite 0 to let's say $0/$20 you can write this code.

lda #$00
sta $2003 ; SPRam - Adress 0
lda #$20 ; load new y coordinate in A
sta $2004 ; write y coordinate to SPRam

now the sprite should be displayed at $0/$20 ... to let the sprite really move (i.e. see as it walks from 0 to $20) you'll have to move the sprite one pixel after another to $20 (i think you could to that easily by incrementing a counter each vblank and write that counter to the y coordinate).
I'm 99.9% sure that you can't read from SPRam (because register $2004 is write only) so you have to use own counters in the NES ram that keep track of the current coordinates of your sprites.

I hope this is a bit helpful and right - as i mentioned before i've never programmed a nes rom (but i looked at many sources -):))

regards Martin




SubjectRe: Background/Tiles & Sprites Movement new  
Posted bymcmartin
Posted on1/7/02 00:17 AM
From IP12.234.29.87  



Oh, sorry, misread your question.

That's actually a non-question, you see. You get sprite movement "for free." If you change where sprite 1's X location is without modifying the information for sprite 0, then when you next write to $4014, sprite 1's location will change and sprite 0's won't. Since with the $4014 approach you're keeping a copy of SPR-RAM in CPU-RAM, you can read sprite coordinates with a simple LDA from your copy in CPU-RAM.

The basic theory is to write once to $4014 every frame, and spend the rest of the frame computing the proper actions of the sprites.

If you understand what the registers do but not what to do with them I'd suggest my "NES 101" tutorial. It only deals with one sprite, but if you don't go and explicitly change a sprite's value, it stays in the same place.

--Michael




Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo