Since the text (and numbers for that matter) are in the background pattern table, I wrote my text "PLAYER SCORE:" as part of the background as well as the starting score of 00 next to it. So whenever the score increases would I have to rewrite the background all the way back up to the second 0 just to update it or is there as better way. For that matter, couldn't I just add the numbers to the sprite pattern table and overlay the new number?
Try setting the VRAM address to the byte right after the ':' in "PLAYER SCORE:" and then printing digits.
Like tepples said, you can overwrite small parts of the name tables with new data, just have the VRAM address point to exact location you want to change before writing the data. There is no need to redraw the whole screen or to patch the background with sprites.
Just make sure to do all your VRAM updates during VBlank and you should be fine.
Well time to make myself look stupid but here I go... how do I find the VRAM address.
67726e wrote:
how do I find the VRAM address.
The formula is: NT + (Y * 32) + X
NT: name table address ($2000, $2400, $2800 or $2C00);
Y: row (0 to 29);
X: column (0 to 31);
So, to update the tile at coordinates (8, 4) in the first name table you use address: $2000 + (4 * 32) + 8 = $2088.
Well I knew I might has well have added how do I write to VRAM along with how do ID the correct address. Anyway I figured out the VRAM address to be $2057
$2000 + (2 * 32) + 23
I just want to change the second zero in 00 to be a 1 to simulate a score. So when I go:
LDY #$0
STY $2056
The code took the liberty of 'rearranging' my background for me. I hate to ask even more questions but I did a search on writing to VRAM on the forum and couldn't find anything so what seems to be the problem?[/b]
If you have something in the name table you have obviously written stuff to the PPU before. You have to write the address to $2006 (first the high byte and then the low byte) and the data to $2007.
Code:
lda #$20
sta $2006
lda #$57
sta $2006
lda #TILE_ID
sta $2007
That's like, the very basics of NES programming. If you are just copying&pasting code and doesn't even know what I'm talking about I guess I can't help you.
Well I did try that and it pretty much just screwed up my entire background. It didn't work and just screwed up my background but I did figure out why. I needed to reset the value at $2006 to its original of $2000 and that solved it. (Hope that proves I don't just copy and paste
)
When you write to VRAM through $2006 and $2007, the background scroll position gets corrupted. All you need to do to fix it is write the X and Y coordinates to $2005.
I did manage to acquire to a fix by simply rewriting 2000 to $2006. I tested your method and it works fine as well. I did a little digging and I added my change tile code to the A button so whenever I pressed it with my fix, it glitched the background for as long as I held the button but did change the number (I wasn't able to detect this when I ran a simple change routine that operated once) and I detected no problems at all with what you told me. Thanks for the help with this one, I clearly needed it.