mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-23 08:32:39 +00:00
Implemented calloc()
This commit is contained in:
parent
57bbe42711
commit
57cdb8dab4
5
src/main/fragment/vwuz1=_deref_pbuz2.asm
Normal file
5
src/main/fragment/vwuz1=_deref_pbuz2.asm
Normal file
@ -0,0 +1,5 @@
|
||||
ldy #0
|
||||
lda ({z2}),y
|
||||
sta {z1}
|
||||
lda #0
|
||||
sta {z1}+1
|
4
src/main/fragment/vwuz1_le_0_then_la1.asm
Normal file
4
src/main/fragment/vwuz1_le_0_then_la1.asm
Normal file
@ -0,0 +1,4 @@
|
||||
lda {z1}
|
||||
beq {la1}
|
||||
lda {z1}+1
|
||||
beq {la1}
|
@ -1,5 +1,7 @@
|
||||
// Implementation of functions found int C stdlib.h / stdlib.c
|
||||
|
||||
import "string"
|
||||
|
||||
// Top of the heap used by malloc()
|
||||
unsigned char* HEAP_TOP = 0xa000;
|
||||
|
||||
@ -20,6 +22,15 @@ void free(void* ptr) {
|
||||
// TODO: So far no support for freeing stuff
|
||||
}
|
||||
|
||||
// Allocates memory and returns a pointer to it. Sets allocated memory to zero.
|
||||
// - nitems − This is the number of elements to be allocated.
|
||||
// - size − This is the size of elements.
|
||||
void *calloc(size_t nitems, size_t size) {
|
||||
void* mem = malloc(nitems*size);
|
||||
memset(mem, 0, nitems*size);
|
||||
return mem;
|
||||
}
|
||||
|
||||
// Searches an array of nitems unsigned words, the initial member of which is pointed to by base, for a member that matches the value key.
|
||||
// - key - The value to look for
|
||||
// - items - Pointer to the start of the array to search in
|
||||
|
@ -29,8 +29,9 @@ void* memmove( void* destination, void* source, size_t num ) {
|
||||
// Copies the character c (an unsigned char) to the first num characters of the object pointed to by the argument str.
|
||||
void *memset(void *str, char c, size_t num) {
|
||||
char* end = (char*)str + num;
|
||||
for(char* dst = str; dst!=end; dst++)
|
||||
*dst = c;
|
||||
if(num>0)
|
||||
for(char* dst = str; dst!=end; dst++)
|
||||
*dst = c;
|
||||
return str;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user