summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLOuroboros <lunosouroboros@gmail.com>2021-01-06 19:49:52 -0300
committerLOuroboros <lunosouroboros@gmail.com>2021-01-06 19:49:52 -0300
commitc9e3c61438dd025a9eca2a264fb3619b18eb167a (patch)
treef7d89df86b87bf13f677f39e6f9fe6c7a7cf4c4c
parent9b483d05575cbdb2b5a6a49a4bb0d41bd9bd5e78 (diff)
Created Improving the WaitForVBlank function (markdown)
-rw-r--r--Improving-the-WaitForVBlank-function.md33
1 files changed, 33 insertions, 0 deletions
diff --git a/Improving-the-WaitForVBlank-function.md b/Improving-the-WaitForVBlank-function.md
new file mode 100644
index 0000000..4e74adb
--- /dev/null
+++ b/Improving-the-WaitForVBlank-function.md
@@ -0,0 +1,33 @@
+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.
+
+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.
+
+By telling the CPU not to enter Sleep Mode, we make the GBA use its full power at all times.
+
+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:
+
+```diff
+static void WaitForVBlank(void)
+{
+ gMain.intrCheck &= ~INTR_FLAG_VBLANK;
+- while (!(gMain.intrCheck & INTR_FLAG_VBLANK))
+- ;
++ VBlankIntrWait();
+}
+```
+
+Alternatively, we can do what the `VBlankIntrWait` function does in a more direct manner, which is unnoticeably faster.
+
+```diff
+static void WaitForVBlank(void)
+{
+ gMain.intrCheck &= ~INTR_FLAG_VBLANK;
+- while (!(gMain.intrCheck & INTR_FLAG_VBLANK))
+- ;
++ asm("swi 0x5");
+}
+```
+
+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