questions about hblank

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
djcouchycouch
Posts: 97
Joined: Sat May 28, 2011 10:30 am

questions about hblank

Post by djcouchycouch »

How can code be run during hblank?

Does it require a specific mapper?

What type of code is typically run during hblank?
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

I don't think anything runs in HBlank, usually just scrolling changes to cleanly scroll to a status bar, like in SMB3, although they don't do it cleanly. No mapper is required, HBlank is a condition of the system, not a mapper.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

A mapper can help the program determine at what time the PPU's horizontal blanking (hblank) starts. MMC3, for instance, watches which addresses the PPU is reading, and when it sees a bunch of reads from $1000-$1FFF (second pattern table), it assumes the PPU is reading sprite patterns during hblank. For each burst of $1000-$1FFF reads, the MMC3 decreases a counter, and it asserts an IRQ once the counter drops below zero. But even without a mapper, there are still ways to determine where the PPU is rendering in order to make sure that your scroll split happens during hblank; most of these involve the sprite 0 hit flag in PPUSTATUS ($2002) and some carefully timed wait loops.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: questions about hblank

Post by tokumaru »

shawnleblanc wrote:How can code be run during hblank?

Does it require a specific mapper?
Mapper IRQs will help you get the time right, but sprite 0 hits and/or timed code can be used as well, so no mapper required.
What type of code is typically run during hblank?
HBlank time is really short (about 28 CPU cycles), so you can't really do much. What usually happens is that effects such as scroll changes, CHR bankswitches, color emphasis changes, and so on are timed to happen during HBlank in order to create a clean split.
User avatar
qbradq
Posts: 952
Joined: Wed Oct 15, 2008 11:50 am

Post by qbradq »

Rad Racer is a good example. It's mapper (MMC1) does not have IRQ support. I uses mid-hblank scroll changes to make the 3D road effect (I think). Not sure how this is accomplished though.
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

qbradq wrote:Rad Racer is a good example. It's mapper (MMC1) does not have IRQ support. I uses mid-hblank scroll changes to make the 3D road effect (I think). Not sure how this is accomplished though.
I've reverse engineered Rad Racer once and if I remember well it runs all game logic on the top of the screen (variable CPU cycle timing) then rely on a sprite zero hit on the start of the road.
Then the first part of the road (the one that bends up/down) is done with a chain $2006 writes, the lower part is just done with a chain of $2005 writes, and then the program just displays the status bar and wait for next VBlank.

Fortunately for them they were able to code the game so that the logic always ends before the road. This should have been harder to do than it sounds, as it would be terrible if the logic would take longer, and the program would "miss" the sprite zero hit.
Useless, lumbering half-wits don't scare us.
Post Reply