It is currently Sun Oct 22, 2017 3:06 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 89 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
PostPosted: Wed Feb 25, 2015 4:24 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 710
Location: New York, NY
tepples wrote:
  • If rendering is disabled, and the current VRAM address is $0000-$3EFF, the PPU will output the color at $3F00.
  • If rendering is disabled, and the current VRAM address is $3F00, the PPU will output the color at $3F00.
  • If rendering is disabled, and the current VRAM address is $3F01, the PPU will output the color at $3F01.
  • If rendering is disabled, and the current VRAM address is $3F02, the PPU will output the color at $3F02.
  • If rendering is disabled, and the current VRAM address is $3F03, the PPU will output the color at $3F03.

It stores a table of colors at $3F00-$3F1F and expects to be able to switch to the next color by reading one byte from or writing one byte to the VRAM data port, which advances the VRAM address by 1.


You are on to something here. I implemented that feature a while ago after reading about it in the wiki and after discovering some other games (or demos) depended on it.

As a test, I just modified the associated code to return white when that code executes:

Image

Image

So, those glitches are related. Maybe it is some sort of timing issue where the color is not updated at the right point.


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 4:36 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5730
Location: Canada
If you run it on a real machine, you can see a few more things about the palette state via the colours in the hblank/overscan at the sides of the image.

https://www.youtube.com/watch?v=BMpZznee74I


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 4:40 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 710
Location: New York, NY
rainwarrior wrote:
If you run it on a real machine, you can see a few more things about the palette state via the colours in the hblank/overscan at the sides of the image.

https://www.youtube.com/watch?v=BMpZznee74I


Woah!


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 4:59 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 710
Location: New York, NY
Interestingly, it positions sprite 0 toward the top-right of the screen and it relies on that hit to coordinate those lines in the middle of the screen. I wonder if it is doing very careful timing based off of that hit.


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 6:48 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3064
Location: Brazil
tepples wrote:
If rendering is disabled, and the current VRAM address is $0000-$3EFF, the PPU will output the color at $3F00.


My bad regarding "PPU address" instead of "VRAM address". :oops: :oops: :oops:


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 7:16 pm 
Offline
User avatar

Joined: Sat Jan 22, 2005 8:51 am
Posts: 427
Location: Chicago, IL
zeroone wrote:
Interestingly, it positions sprite 0 toward the top-right of the screen and it relies on that hit to coordinate those lines in the middle of the screen. I wonder if it is doing very careful timing based off of that hit.

The game spins waiting for that sprite 0 hit immediately before jumping to the $2004 read routine. There it loops 8 times, burning ~113 cycles/loop.

_________________
get nemulator
http://nemulator.com


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 8:02 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 710
Location: New York, NY
Quote:
The game spins waiting for that sprite 0 hit immediately before jumping to the $2004 read routine. There it loops 8 times, burning ~113 cycles/loop.


What is it waiting for? The HBlank?

As for timing, my emulator renders the text boxes in Marble Madness correctly and Battletoads runs without a problem. I don't know if I can make it more accurate than that.


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 8:06 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19115
Location: NE Indiana, USA (NTSC)
Apparently it's snooping on OAM bus as a way to synchronize its raster effects to horizontal blanking.


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 8:14 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 710
Location: New York, NY
tepples wrote:
Apparently it's snooping on OAM bus as a way to synchronize its raster effects to horizontal blanking.


It's not gaining/losing that many cycles from the snoop. And, why would it have to anyway? It should always be the same number of cycles after the sprite 0 hit to the edge.


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 8:27 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6294
Location: Seattle
Polling on $2002 reads induces up to a 6-cycle jitter. Eight scanlines of asking the PPU where it is and adding an extra cycle if necessary should just about be enough to get cycle-exact timing out. (Does it?)


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 8:42 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 710
Location: New York, NY
lidnariq wrote:
Polling on $2002 reads induces up to a 6-cycle jitter. Eight scanlines of asking the PPU where it is and adding an extra cycle if necessary should just about be enough to get cycle-exact timing out. (Does it?)


I think you mean $2004 and it seems to be doing all that polling on the same scanline (the sprite 0 hit scanline).


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 8:59 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10066
Location: Rio de Janeiro - Brazil
It's so weird that this game goes through all this trouble to pull off some stupid raster effects in menu screens that could have easily used timed code all the way, with the beginning of the frame and/or a sprite 0 hit as a reference point. But no, they decided to use an obscure/undocumented aspect of the console, that's not even guaranteed to work on all revisions (didn't OAM read back fail on some Famicom models?).


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 9:03 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19115
Location: NE Indiana, USA (NTSC)
Sprite 0 hit gets into a ~20-pixel-wide ballpark. Polling on $2004 over the next few lines allows correcting from that ballpark to an exact position plus or minus one pixel. This sort of precise alignment to the horizontal blank becomes especially important for mid-frame palette changes.

And to Codemasters and Color Dreams, everything was undocumented.


Top
 Profile  
 
PostPosted: Wed Feb 25, 2015 9:10 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6294
Location: Seattle
zeroone wrote:
I think you mean $2004 and it seems to be doing all that polling on the same scanline (the sprite 0 hit scanline).
I meant what I said, exactly as I said it.

It polls $2002, waiting for sprite 0 hit. That provides a 6-7 cycle/18-21 pixel jitter.

It then tests $2004 over eight successive scanlines, adjusting the PPU/CPU phase by one cycle (+1 pixel / -2 pixels) if necessary on each of those scanlines.


Last edited by lidnariq on Thu Feb 26, 2015 1:41 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Feb 26, 2015 1:39 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5730
Location: Canada
tokumaru wrote:
But no, they decided to use an obscure/undocumented aspect of the console, that's not even guaranteed to work on all revisions (didn't OAM read back fail on some Famicom models?).

They probably didn't have any official documentation at all to work from. A lot of unlicensed NES work was done on the basis of reverse engineering. The game was also never released on Famicom, so even if the technique would have failed on that, it wasn't relevant.

If it works, it works. The fact that it's annoying to emulate is our problem, not theirs. The emulated-NES platform didn't even exist then, they had no reason to make any concessions for it (even if they could predict the future and know that this technique would be tricky for us).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 89 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google Adsense [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group