]> git.sur5r.net Git - cc65/commitdiff
Replaced calloc by an assembler version
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 15 Nov 2001 21:53:00 +0000 (21:53 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 15 Nov 2001 21:53:00 +0000 (21:53 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1119 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/common/.cvsignore
libsrc/common/Makefile
libsrc/common/calloc.c [deleted file]
libsrc/common/calloc.s [new file with mode: 0644]

index 8cae4b2d93ead8451eb7bea69df6475bdc70cbd4..31181a27c0fba2453aaedbee8b1eee10373a1888 100644 (file)
@@ -5,7 +5,6 @@ _hextab.s
 _scanf.s
 abort.s
 bsearch.s
-calloc.s
 errormsg.s
 fclose.s
 fdopen.s
index 6723738f57f841770aa6c7fda32635e16e27e6f5..a548973854af6cbe1a931c088db5849173e15867 100644 (file)
@@ -17,7 +17,6 @@ C_OBJS =      _afailed.o      \
                _scanf.o        \
                abort.o         \
                bsearch.o       \
-               calloc.o        \
                errormsg.o      \
                fclose.o        \
                fdopen.o        \
@@ -59,6 +58,7 @@ S_OBJS =      _fdesc.o        \
                abs.o           \
                atexit.o        \
                atoi.o          \
+               calloc.o        \
                copydata.o      \
                cprintf.o       \
                errno.o         \
diff --git a/libsrc/common/calloc.c b/libsrc/common/calloc.c
deleted file mode 100644 (file)
index 70b9849..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * calloc.c
- *
- * Ullrich von Bassewitz, 06.06.1998
- */
-
-
-
-#include <stdlib.h>
-#include <string.h>
-
-
-
-void* calloc (size_t count, size_t size)
-{
-    void* mem;
-    size *= count;
-    if (mem = malloc (size)) {
-       memset (mem, 0, size);
-    }
-    return mem;
-}
-
-
-
diff --git a/libsrc/common/calloc.s b/libsrc/common/calloc.s
new file mode 100644 (file)
index 0000000..16d2175
--- /dev/null
@@ -0,0 +1,64 @@
+;
+; Ullrich von Bassewitz, 15.11.2001
+;
+; Allocate a block and zero it.
+;
+; void* __fastcall__ calloc (size_t count, size_t size);
+;
+
+       .export _calloc
+       .import _malloc, _memset
+       .import tosumulax, pushax, push0
+
+
+; -------------------------------------------------------------------------
+
+.proc  _calloc
+
+; We have the first argument in a/x and the second on the stack. Calling
+; tosumulax will give the product of both in a/x.
+
+       jsr     tosumulax
+
+; Save size for later
+
+       sta     Size
+       stx     Size+1
+
+; malloc() is a fastcall function, so we do already have the argument in
+; the right place
+
+        jsr    _malloc
+
+; Check for a NULL pointer
+
+       cpx     #0
+       bne     ClearBlock
+       cmp     #0
+       beq     ClearBlock
+
+; We have a NULL pointer, bail out
+
+       rts
+
+; No NULL pointer, clear the block. memset will return a pointer to the
+; block which is exactly what we want.
+
+ClearBlock:
+        jsr    pushax                  ; ptr
+       jsr     push0                   ; #0
+       lda     Size
+       ldx     Size+1                  ; Size
+       jmp     _memset
+
+.endproc
+
+; -------------------------------------------------------------------------
+; Data
+
+.bss
+
+Size:  .res    2
+
+
+