Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
hi!
i'm working on a little test game, and i'm wondering if relying on wait_vbl_done() is enough to get a constant update speed oy should i use a timer interrupt if i want my logic updated at a stable rate. I'm currently using no interrupts at all, and i use IF based timers. my code looks like this:
while(!0){
wait_vbl_done();
//all my functions
}
i started using wait_vbl_done() because i realized my game would run slower as i included more logic, and this does seem to fix this, but i'd like to know if i'm doing it wrong, or what would be the best approach.
thanks!
Offline
It should work as long as you don't turn the LCD off.
If you need 100% precision no matter what, timers are the way to go.
Last edited by l0k1 (2016-01-06 03:49:59)
Offline
Basically, no. If the LCD is turned off, then the vblank interrupt gets postponed.
The LY register at $FF44 is constantly incrementing from 0 to 153 while the LCD is on. VBlank happens when this hits 144, and lasts through 153, when the counter is reset to 0. If you turn off the LCD, this stops counting. When you turn the LCD back on, the counter resets to 0.
Say this counter is at 94 when you turn off the LCD. No vblank happened, and when you turn the LCD back on, it has to start counting from 0 again. So total time from vblank to vblank would be 94 + 143 cycles, plus however long it took your code to run when the LCD was off.
The timer, on the other hand, will increment at all times it is turned on, unless you explicitly stop it.
Usually relying on the vblank is okay, unless you need really high precision.
Edit:
You can make timer interrupts happen at a much faster rate than vblank, or moderately slower than vblank, or anywhere in between.
Last edited by l0k1 (2016-01-06 17:06:18)
Offline