+2008-12-26 Philipp Klaus Krause <pkk AT spth.de>
+ * device/lib/z80/Makefile.in,
+ device/lib/Makefile.in,
+ device/lib/z80/memmove.s: Implemented RFE #1914256
+
2008-12-26 Philipp Klaus Krause <pkk AT spth.de>
* src/z80/peeph-z80.def: fixed a bug in peephole 0zf
_strcspn.c _strlen.c _strncat.c _strncmp.c \
_strncpy.c _strpbrk.c _strrchr.c _strspn.c \
_strstr.c _strtok.c \
- _memcmp.c _memcpy.c _memmove.c _memset.c \
+ _memcmp.c _memcpy.c _memset.c \
_calloc.c _malloc.c _realloc.c _free.c \
printf_large.c sprintf.c vprintf.c puts.c gets.c \
assert.c time.c \
SCC = $(TOPDIR)/bin/sdcc -mz80
SAS = $(TOPDIR)/bin/as-z80
-OBJ = div.o mul.o putchar.o shift.o stubs.o crt0_rle.o heap.o fstubs.o
+OBJ = div.o mul.o putchar.o shift.o stubs.o crt0_rle.o heap.o fstubs.o memmove.o
LIB = z80.lib
CC = $(SCC)
--- /dev/null
+ .area _CODE
+
+ .globl _memmove
+
+; The Z80 has the ldir and lddr instructions, which are perfect for implementing memmove().
+
+_memmove:
+ push ix
+ ld ix,#0
+ add ix,sp
+ ld c, 8(ix)
+ ld b, 9(ix)
+ ld a, c
+ or a, b
+ jr Z, memmove_end
+ ld e, 4(ix)
+ ld d, 5(ix)
+ ld l, 6(ix)
+ ld h, 7(ix)
+ ld a, l
+ sbc hl, de ; or above cleared carry.
+ ld l, a
+ ld h, 7(ix)
+ jr NC, memmove_up
+memmove_down:
+ add hl, bc
+ dec hl
+ ld a, e
+ add a, c
+ ld e, a
+ ld a, d
+ adc a, b
+ ld d, a
+ dec de
+ lddr
+ jr memmove_end
+memmove_up:
+ ldir
+memmove_end:
+ ld l, 4(ix)
+ ld h, 5(ix)
+ pop ix
+ ret
+