From c4a8131994a6ab13498d4932cd77129c2eda3f0d Mon Sep 17 00:00:00 2001 From: Rangi Date: Sat, 18 Dec 2021 17:49:51 -0500 Subject: Optimize --- Improve-the-event-initialization-system.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Improve-the-event-initialization-system.md b/Improve-the-event-initialization-system.md index c55e6ed..5b7da03 100644 --- a/Improve-the-event-initialization-system.md +++ b/Improve-the-event-initialization-system.md @@ -194,16 +194,20 @@ $ tools/free_space.py pokecrystal.map Free space: 455295/2097152 (21.71%) ``` -That's 72 more ROM bytes than before. It's not a whole lot, but every bit helps. You can eke out a few more by applying the tricks from the [assembly optimization tutorial](Optimizing-assembly-code) to `InitializeEvents`: it was written more for clarity than to save space. For example, all three `cp -1` can become `inc a` to save three bytes *and* run a little faster. Or you can optimize the entire `.sprites_loop` using the "[Add `a` to an address](Optimizing-assembly-code#add-a-to-an-address)" technique: +That's 72 more ROM bytes than before. It's not a whole lot, but every bit helps. + +You can eke out a few more by applying the tricks from the [assembly optimization tutorial](Optimizing-assembly-code) to `InitializeEvents`: it was written more for clarity than to save space. For example, all three `cp -1` can become `inc a` (the "[Compare `a` to 255](Optimizing-assembly-code#compare-a-to-255)" technique) to save three bytes *and* run a little faster. And you can optimize the entire `.sprites_loop` using the "[Add `a` to an address](Optimizing-assembly-code#add-a-to-an-address)" technique: ```diff .sprites_loop ld a, [hli] - ld e, a - ld d, 0 - cp -1 +- cp -1 ++ inc a ret z -+ add LOW(wVariableSprites) ++ ; subtract 1 to balance the previous 'inc' ++ add LOW(wVariableSprites) - 1 + ld e, a + adc HIGH(wVariableSprites) + sub e -- cgit v1.2.3