This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Modifying $2005 and $2006 during HBLANK

Modifying $2005 and $2006 during HBLANK
by on (#41735)
I've been trying to figure out a way to hide scrolling glitches again, something that has already been discussed in topics such as this and this). I was trying to come up with a new method that didn't require IRQs or special mappers (i.e. NROM-friendly) and didn't require a lot of sprites (like Alfred Chicken or Felix the Cat do). I was also trying to avoid relying on obscure PPU behavior (such as $2004 reads), but something's gotta give.

The only obscure thing I need is to change the scrolling through $2005/$2006 in the middle of a frame, which isn't such an obscure trick, as it's already known for a long time. I decided to ask this in a new thread because this isn't necessarily related to scrolling glitches.

Anyway, does anyone know the protocol for safely resetting the scroll to any point in the name tables? I do understand Loopy's scrolling documents and know how to modify the registers, what I need to know is the correct time to modify them. Can that be done during HBLANK without the need for turning rendering off? Are there any problems regarding the two tiles that are fetched in the previous scanline (glitches)?

Also, if anyone can point me to a game that has done this and is proven to work on hardware without glitches, that'd be great. Thanks for the help.

If my idea is proven to work, I'll be sure to describe it here later.

by on (#41737)
You don't need to turn the rendering off. It might help to pre-load A,X,and Y with whatever values needed before hblank, if there's a lot to do.

First, I write the 113.666 cycle loop, then I put a delay before it starts, messing around with the start delay timing until it all lines up.

In the progam I'm working on now, here's part of the loop for writing the regs each scanline:
Code:
                  ldy #0
   scanline_loop:
                  lda scroll_table,y            ; 4    4
                  tax                           ; 2    6
                  lda vram_addr_hi,x            ; 4    10
                  sta $2006                     ; 4    14
                  stx $2005                     ; 4    18
                  lda #0                        ; 2    20
                  sta $2005                     ; 4    24
                  lda vram_addr_lo,x            ; 4    28
                  sta $2006                     ; 4    32

I can give you those tables if you want them.

I think Fantastic Adventures of Dizzy was one game that did a lot of mid-frame scroll writes in the intro. Either that, or another Dizzy game.

by on (#41738)
Memblers wrote:
You don't need to turn the rendering off.

That's great.

Quote:
It might help to pre-load A,X,and Y with whatever values needed before hblank, if there's a lot to do.

Yeah, I'd want the writes to take as little time as possible.

Quote:
First, I write the 113.666 cycle loop, then I put a delay before it starts, messing around with the start delay timing until it all lines up.

So you just shift things around until it works? Just out of curiosity, do you have any idea when in the scanline that first write to $2006 occurs? I'll understand if you don't, since you shifted it into place.

Quote:
I can give you those tables if you want them.

The idea of using tables for this is good. I already have means of finding the necessary values, but if you feel like sharing the table I'm sure it will be useful to someone.

Quote:
I think Fantastic Adventures of Dizzy was one game that did a lot of mid-frame scroll writes in the intro.

Thanks, I'm checking those games out.

by on (#41739)
tokumaru wrote:
So you just shift things around until it works? Just out of curiosity, do you have any idea when in the scanline that first write to $2006 occurs? I'll understand if you don't, since you shifted it into place.


I just checked it in Nintendulator, stepping through it is on 58, 58.333, and 58.667

Quote:
The idea of using tables for this is good. I already have means of finding the necessary values, but if you feel like sharing the table I'm sure it will be useful to someone.

Here are those:
http://www.parodius.com/~memblers/nes/vram_hi.bin
http://www.parodius.com/~memblers/nes/vram_lo.bin

In that code, scroll_table is in RAM and basically defines which scanline to draw for every line.

by on (#41741)
tokumaru wrote:
So you just shift things around until it works? Just out of curiosity, do you have any idea when in the scanline that first write to $2006 occurs? I'll understand if you don't, since you shifted it into place.

tokumaru, that's why you should give a quick look on emulation side. ;)
Quote:
; Writes to $2006 works at power up.
; Writes to $2006 are ignored before 29657.
; Writes to $2006 work at 29658.
; $2006 is $0000 at power if it's been off for 20 or more seconds,
$0001 if less, unchanged by reset.

More here:
http://nesdevwiki.org/wiki/Power-up_state_of_PPU

by on (#41745)
Fx3 wrote:
tokumaru, that's why you should give a quick look on emulation side. ;)

Hehehe! I get what you mean, but I really can't bother learning all those little details. That's the kind of thing I forget anyway when I don't constantly think of it.

Quote:
http://nesdevwiki.org/wiki/Power-up_state_of_PPU

I don't really care about the power-up state, since I just safely wait for 2 frames to go by before doing anything... this is all a game programmer has to know! =) What I'm aiming for here is manipulating the scroll as the screen renders.

by on (#41751)
Quote:
I don't really care about the power-up state, since I just safely wait for 2 frames to go by before doing anything... this is all a game programmer has to know! =) What I'm aiming for here is manipulating the scroll as the screen renders.

Well, you asked when in the scanline that first write to $2006 occurs. My bad, because you mentioned that custom code. :|

by on (#41760)
Well, it's fun I just wrote an article about that yesterday. It was meant to be used by both newbies and more advanced programmers, on the NES programming side (not on the emulation side). And the arcticle ended up *much longer* than what I exepted to write when starting it. I just give practical tips on to use $2005 and $2006, as well as "short" list of all possible changes during the frame (well, I wanted it to be short at least).

It's all here : http://jonathan.microclub.ch/NES_raster/index.html
Let me know if this is usefull (it should).

by on (#42608)
Bregalad wrote:

You know, you should add that to the wiki. It's not too technical and lets people know what's possible on the NES. I haven't checked the demos though.

by on (#48988)
Bregalad wrote:
Well, it's fun I just wrote an article about that yesterday. It was meant to be used by both newbies and more advanced programmers, on the NES programming side (not on the emulation side). And the arcticle ended up *much longer* than what I exepted to write when starting it. I just give practical tips on to use $2005 and $2006, as well as "short" list of all possible changes during the frame (well, I wanted it to be short at least).

It's all here : http://jonathan.microclub.ch/NES_raster/index.html
Let me know if this is usefull (it should).


Sorry to bump an old topic, but I had marked this page as being useful and it isn't loading for me now. Does anyone have a copy of its contents?

by on (#48990)
Hope this works.

http://74.125.93.132/search?q=cache:ypxNjjAJCzkJ:www.microclub.ch/~jmasur/NES_raster/index.html&cd=1&hl=en&ct=clnk&gl=us

by on (#48993)
And of course now it's coming up fine no problem. Guess I'll save the content this time.

by on (#48996)
Well I did a total backup this morning and it looks like they did some short maintenance on the server, but now it seems it's working again.

by on (#52758)
Bregalad: please define escient...

by on (#52762)
mmh.... where did you found that ?

by on (#52764)
Quote:
I consider knowing at what exact clock cycle a latch inside the NES change it's state is not meaningfull to game programmers, but knowing how to use such a behaviour to good escient is.


It is there and

Quote:
Unfoturnately, the CPU is much slower than the PPU, and the chance of using that to a good escient is slim.


there in the document.

by on (#52765)
Okay I've "fixed" that error. I guess a good escient was suppoed to be a good use, altough I didn't know that word didn't exist in english.

by on (#52802)
it's a decent word as long as someone knows to look it up in the French dictionnaire

by on (#52808)
I just know Escient as the company that spun off Gracenote, the CDDB company.