summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2020-03-15 19:20:15 -0400
committerRangi <remy.oukaour+rangi42@gmail.com>2020-03-15 19:20:15 -0400
commit8c24867c887a63488b7cd232dcf46931a0e3b5aa (patch)
treed243da95be7640bb2873af0afff61f35d5774f19
parentda356938fadf1569aa1b74ed4db61beda8147e3a (diff)
Optimize
-rw-r--r--Improve-the-event-initialization-system.md31
-rw-r--r--Optimizing-assembly-code.md4
2 files changed, 32 insertions, 3 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
+```
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md
index 24bea11..2b51bf1 100644
--- a/Optimizing-assembly-code.md
+++ b/Optimizing-assembly-code.md
@@ -310,9 +310,9 @@ But do:
```asm
; 7 bytes, 7 cycles
- add a, LOW(Address)
+ add LOW(Address)
ld l, a
- adc a, HIGH(Address)
+ adc HIGH(Address)
sub l
ld h, a
```