summaryrefslogtreecommitdiff
path: root/Improve-the-event-initialization-system.md
diff options
context:
space:
mode:
Diffstat (limited to 'Improve-the-event-initialization-system.md')
-rw-r--r--Improve-the-event-initialization-system.md31
1 files changed, 30 insertions, 1 deletions
diff --git a/Improve-the-event-initialization-system.md b/Improve-the-event-initialization-system.md
index 78f42dd..5b5f509 100644
--- a/Improve-the-event-initialization-system.md
+++ b/Improve-the-event-initialization-system.md
@@ -207,4 +207,33 @@ $ tools/free_space.awk 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.)
+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:
+
+```diff
+ .sprites_loop
+ ld a, [hli]
+- ld e, a
+- ld d, 0
+- cp -1
+- jr z, .sprites_done
+- ld a, [hli]
+- push hl
+- ld hl, wVariableSprites
+- add hl, de
+- ld [hl], a
+- pop hl
++ ld a, [hli]
++ cp -1
++ ret z
++ add LOW(wVariableSprites)
++ ld e, a
++ adc HIGH(wVariableSprites)
++ sub e
++ ld d, a
++ ld a, [hli]
++ ld [de], a
+ jr .sprites_loop
+-.sprites_done
+-
+- ret
+```