diff options
author | ExpoSeed <43502820+ExpoSeed@users.noreply.github.com> | 2021-01-06 17:14:24 -0600 |
---|---|---|
committer | ExpoSeed <43502820+ExpoSeed@users.noreply.github.com> | 2021-01-06 17:14:24 -0600 |
commit | 145191a4afe5e972196e350e0a65a5911e923965 (patch) | |
tree | 986119d9553000716d52646f10dbcc1c05dd10ec | |
parent | 201df908b16867064d55f74843b441482af95a29 (diff) |
Updated Improving the WaitForVBlank function (markdown)
-rw-r--r-- | Improving-the-WaitForVBlank-function.md | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Improving-the-WaitForVBlank-function.md b/Improving-the-WaitForVBlank-function.md index 4e74adb..0e7c4d8 100644 --- a/Improving-the-WaitForVBlank-function.md +++ b/Improving-the-WaitForVBlank-function.md @@ -1,10 +1,12 @@ The credits for this tutorial belong to **[DizzyEggg](https://github.com/dizzyeggg)**. -In both, Pokémon FireRed/LeafGreen and Pokémon Emerald, Game Freak modified the WaitForVBlank function present in Pokémon Ruby/Sapphire. +In both, Pokémon FireRed/LeafGreen and Pokémon Emerald, Game Freak modified the `WaitForVBlank` function present in Pokémon Ruby/Sapphire. -What this function normally does is to put the GBA's CPU in Sleep Mode each time a pixel has been drawn on the screen. While in that state, the CPU prioritizes saving its power over everything else. +`WaitForVBlank` is used for what is called [vsyncing](https://www.coranac.com/tonc/text/video.htm#sec-vsync1). In short, VBlank is a short period of time in between each refresh of the screen, and it is used to keep the game processes in sync with the GBA's screen. -By telling the CPU not to enter Sleep Mode, we make the GBA use its full power at all times. +In Emerald, Gamefreak used a `while` loop that kept on checking for VBlank over and over again. However, this approach is very wasteful. The `while` loop is not doing anything, so all it does is waste CPU cycles, and burning CPU cycles like this burns battery power. + +The correct way to vsync is to use a [software interrupt/BIOS call](https://www.coranac.com/tonc/text/swi.htm#sec-vsync2). In short, we put the CPU in low power mode while we wait for the next VBlank, and on the next VBlank the CPU comes back to life. The easiest way to do so, is by copying and pasting the function directly from Ruby and Sapphire, which means modifying the function like this: @@ -30,4 +32,4 @@ static void WaitForVBlank(void) } ``` -Save, build a ROM, and so the game will utilize the full power of the GBA's CPU in order to draw things on screen. The easiest way to notice this is while running the game on a GBA emulator with a FastForward feature implemented.
\ No newline at end of file +Save, build a ROM, and so the game will utilize the full power of the GBA's CPU in order to draw things on screen. The easiest way to notice this is while running the game on a GBA emulator with a FastForward feature implemented, where implementing this fix will give you a 100-150% increase in speed.
\ No newline at end of file |