diff options
-rw-r--r-- | Improve-the-event-initialization-system.md | 31 | ||||
-rw-r--r-- | Optimizing-assembly-code.md | 4 |
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 ``` |