diff --git a/part12-wgt/wgt.c b/part12-wgt/wgt.c index 4a648b6..826e50a 100644 --- a/part12-wgt/wgt.c +++ b/part12-wgt/wgt.c @@ -19,7 +19,6 @@ void *memset(void *dest, unsigned int val, unsigned len) return dest; } - void *memcpy(void *dest, const void *src, unsigned len) { unsigned int *d = dest; @@ -29,6 +28,22 @@ void *memcpy(void *dest, const void *src, unsigned len) return dest; } +void *memcpy_xray(void *dest, const void *src, unsigned len) +{ + unsigned int *d = dest; + const unsigned int *s = src; + while (len--) { + if (*s != 0) { + *d++ = *s++; + } else { + d++; + s++; + } + } + + return dest; +} + int abs(int i) { return i < 0 ? -i : i; diff --git a/part12-wgt/wgt.h b/part12-wgt/wgt.h index e241747..5534083 100644 --- a/part12-wgt/wgt.h +++ b/part12-wgt/wgt.h @@ -48,6 +48,7 @@ extern short bx,by,tx,ty; void *memset(void *dest, unsigned int val, unsigned len); void *memcpy(void *dest, const void *src, unsigned len); +void *memcpy_xray(void *dest, const void *src, unsigned len); int abs(int i); int strlen(const char *str); diff --git a/part12-wgt/wnpblock.c b/part12-wgt/wnpblock.c index b93d809..d40d4b5 100644 --- a/part12-wgt/wnpblock.c +++ b/part12-wgt/wnpblock.c @@ -3,7 +3,7 @@ // We should replace this with faster version (and xray needs to do the right thing - not sure memcpy is a good replacement) #define fastcopy memcpy -#define putxray memcpy +#define putxray memcpy_xray block wnewblock (short x, short y, short x2, short y2) {