How can code be run during hblank?
Does it require a specific mapper?
What type of code is typically run during hblank?
questions about hblank
Moderator: Moderators
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.
Re: questions about hblank
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.shawnleblanc wrote:How can code be run during hblank?
Does it require a specific mapper?
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.What type of code is typically run during hblank?
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.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.
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.