gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 01777708810b347f83994b9486bacd6009800b4c parent 2f8d3304c9f733229c04dcbda0936e655a215a2a Author: Phidias618 <126189685+Phidias618@users.noreply.github.com> Date: Thu, 7 May 2026 12:35:43 +0200 refactor memset() for the sm83 Diffstat:
| M | gbdk-lib/include/asm/sm83/string.h | 2 | +- |
| M | gbdk-lib/libc/asm/sm83/_memset.s | 61 | ++++++++++++++++++++++++++----------------------------------- |
2 files changed, 27 insertions(+), 36 deletions(-)
diff --git a/gbdk-lib/include/asm/sm83/string.h b/gbdk-lib/include/asm/sm83/string.h @@ -51,7 +51,7 @@ void *memmove (void *dest, const void *src, size_t n); @param c char value to fill with (truncated from int) @param n Number of bytes to fill */ -void *memset (void *s, int c, size_t n) OLDCALL PRESERVES_REGS(b, c); +void *memset (void *s, int c, size_t n); /** Reverses the characters in a string diff --git a/gbdk-lib/libc/asm/sm83/_memset.s b/gbdk-lib/libc/asm/sm83/_memset.s @@ -4,49 +4,40 @@ ; void *memset (void *s, int c, size_t n) _memset:: - lda hl,7(sp) - ld a,(hl-) - ld d, a - ld a,(hl-) - ld e, a - or d - jr z,6$ + ld a, c + + pop hl ; pop return address + pop bc ; pop n + push hl ; push return address - dec hl - ld a,(hl-) - push af - ld a,(hl-) - ld l,(hl) - ld h,a - pop af + ld h, d + ld l, e - srl d - rr e - jr nc,4$ - ld (hl+),a -4$: - srl d - rr e - jr nc,5$ + srl b + rr c + jr nc,0$ ld (hl+),a - ld (hl+),a -5$: - inc d - inc e - jr 2$ +0$: + srl b + inc b + rr c + + jr c,2$ + jr z,3$ 1$: + dec c ld (hl+),a ld (hl+),a +2$: ld (hl+),a ld (hl+),a -2$: - dec e jr nz,1$ - dec d +3$: + dec b jr nz,1$ -6$: - lda hl,2(sp) - ld a,(hl+) - ld e,a - ld d,(hl) + + ; return s in bc + ld b, d + ld c, e + ret
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.