Modifying a Nametable's tile before loading it into the PPU?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
Sanchezman
Posts: 14
Joined: Fri Jun 28, 2013 11:15 pm

Modifying a Nametable's tile before loading it into the PPU?

Post by Sanchezman »

So, I'm trying to make a subroutine that can modify a given tile in a given nametable before it loads into the PPU using ASM6.

The code I have is as follows (the .org is just so I can find the subroutine in the fceuxd's debugger):

Code: Select all


;*TODO: Implement a working version of this subroutine
.org $c500
switch_tile:
	lda nametableaddr_low
	clc
	adc tileswitch_low
	sta tileswitch_low
	lda nametableaddr_high
	adc tileswitch_high
	sta tileswitch_high
	lda newtile
	ldy #$2
	sta (tileswitch_low),y
rts
The most of the code works fine. In fact the only problem is at

Code: Select all

sta (tileswitch_low),y
While the debugger's disassembly shows that (tileswitch_low),y points to the correct address ($d1a9), the address is never actually written to. Going through both the hex editor and the RAM filter show that $d1a9 is unchanged from before.

Why is this so? Is is because I am trying to change a value in ROM? If so, how can I go about changing a nametable's tile?

Thanks for any and all help!
Why are they called urine cakes if you're NOT supposed to eat them?
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Re: Modifying a Nametable's tile before loading it into the

Post by 3gengames »

Are you trying to store in the ROM at the location in the ()'s? If so, you're using an addressing mode not even related. It should be either $(location/label) or $location/label,Y if it's an array. If that's not it, please explain more clearly how this code works.
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: Modifying a Nametable's tile before loading it into the

Post by thefox »

Sanchezman wrote:Why is this so? Is is because I am trying to change a value in ROM? If so, how can I go about changing a nametable's tile?
It's not called Read Only Memory for nothing. :) Indeed, you can't modify the values in ROM.

If you copy your nametable to (CPU) RAM, you can modify it to your hearts content before uploading it to PPU. Or you could copy it to PPU unmodified, and then modify it. It all depends on what you're trying to do exactly.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Modifying a Nametable's tile before loading it into the

Post by tepples »

There are two ways to build a nametable from parts.

You can copy things into RAM (at $0100-$01BF or $0200-$07FF), modify them there, and then copy them into video memory. Thwaite does this with 2-row chunks that make the hint area, house area, and score area, and Concentration Room does this with 4x4-tile areas around a card that's being turned over. And a lot of platformers do this with the area at the seam.

Or you can just turn off rendering, copy one item into video memory, and then copy another item into video memory on top of this. Nintendo games tend to do this with horizontal and vertical strips of tiles, and RBI Baseball does it with rectangles, as I discovered when reversing a subroutine to see what the heck it does.
User avatar
Sanchezman
Posts: 14
Joined: Fri Jun 28, 2013 11:15 pm

Re: Modifying a Nametable's tile before loading it into the

Post by Sanchezman »

tepples wrote: Or you can just turn off rendering, copy one item into video memory, and then copy another item into video memory on top of this.
So to do this, if I wanted to change, say, tile #85, if my current nametable is at $2800, I could write $2855 to the $2006 register, and make my change through the $2007 register?

**Edit**
Thanks for the advice, tepples. The code that I now have which works is:

Code: Select all

switch_tile:
	lda $2006
	lda ppuaddr_low
	clc
	adc tileswitch_low
	sta ppuaddr_low
	lda ppuaddr_high
	adc tileswitch_high
	sta $2006
	lda ppuaddr_low
	sta $2006
	lda newtile
	sta $2007
rts
Why are they called urine cakes if you're NOT supposed to eat them?
Post Reply