From 9fb1467ee53f458131f5f04b3c135afc48c6887f Mon Sep 17 00:00:00 2001 From: Clanmaster21 Date: Thu, 17 Oct 2019 01:39:38 +0100 Subject: [PATCH] cpHLDE and writeHLinDE improvements (#33) Pretty major improvements to both of these, cpHLDE is now 5 bytes shorter and between 9 and 12 cycles faster due to branching, and writeHLinDE is now 2 bytes shorter and 21 cycles faster. --- kernel/core.asm | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/kernel/core.asm b/kernel/core.asm index f23475a..a88cf2f 100644 --- a/kernel/core.asm +++ b/kernel/core.asm @@ -79,33 +79,22 @@ subHL: ; Compare HL with DE and sets Z and C in the same way as a regular cp X where ; HL is A and DE is X. -; A is preserved through some register hocus pocus: having cpHLDE destroying -; A bit me too many times. cpHLDE: - push bc - ld b, a ; preserve A - ld a, h - cp d - jr nz, .end ; if not equal, flags are correct - ld a, l - cp e - ; flags are correct -.end: - ; restore A but don't touch flags - ld a, b - pop bc + push hl + or a ;reset carry flag + sbc hl, de ;There is no 'sub hl, de', so we must use sbc + pop hl ret ; Write the contents of HL in (DE) +; de and hl are preserved, so no pushing/popping necessary writeHLinDE: - push af - ld a, l - ld (de), a - inc de - ld a, h - ld (de), a - dec de - pop af + ex de, hl + ld (hl), e + inc hl + ld (hl), d + dec hl + ex de, hl ret ; Call the method (IX) is a pointer to. In other words, call intoIX before