diff options
author | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-03-15 19:20:15 -0400 |
---|---|---|
committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-03-15 19:20:15 -0400 |
commit | 8c24867c887a63488b7cd232dcf46931a0e3b5aa (patch) | |
tree | d243da95be7640bb2873af0afff61f35d5774f19 /Improve-the-event-initialization-system.md | |
parent | da356938fadf1569aa1b74ed4db61beda8147e3a (diff) |
Optimize
Diffstat (limited to 'Improve-the-event-initialization-system.md')
-rw-r--r-- | Improve-the-event-initialization-system.md | 31 |
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 +``` |