diff --git a/src/main/fragment/mos6502-common/_deref_qvoz1_eq_pvoc1_then_la1.asm b/src/main/fragment/mos6502-common/_deref_qvoz1_eq_pvoc1_then_la1.asm new file mode 100644 index 000000000..c59b6b7d5 --- /dev/null +++ b/src/main/fragment/mos6502-common/_deref_qvoz1_eq_pvoc1_then_la1.asm @@ -0,0 +1,9 @@ +ldy #0 +lda ({z1}),y +cmp #<{c1} +bne !+ +iny +lda ({z1}),y +cmp #>{c1} +beq {la1} +!: \ No newline at end of file diff --git a/src/main/kc/include/string.h b/src/main/kc/include/string.h index d69c3f283..ec2f98e37 100644 --- a/src/main/kc/include/string.h +++ b/src/main/kc/include/string.h @@ -19,6 +19,14 @@ void *memset(void *str, char c, size_t num); /// Copies the C string pointed by source into the array pointed by destination, including the terminating null character (and stopping at that point). char* strcpy( char* destination, char* source ); +/// Copies up to n characters from the string pointed to, by src to dest. +/// In a case where the length of src is less than that of n, the remainder of dest will be padded with null bytes. +/// @param dst − This is the pointer to the destination array where the content is to be copied. +/// @param src − This is the string to be copied. +/// @param n − The number of characters to be copied from source. +/// @return The destination +char *strncpy(char *dst, const char *src, size_t n); + /// Computes the length of the string str up to but not including the terminating null character. size_t strlen(char *str); diff --git a/src/main/kc/lib/string.c b/src/main/kc/lib/string.c index 39b959d8c..cdfd7c47c 100644 --- a/src/main/kc/lib/string.c +++ b/src/main/kc/lib/string.c @@ -46,6 +46,21 @@ char* strcpy( char* destination, char* source ) { return destination; } +/// Copies up to n characters from the string pointed to, by src to dst. +/// In a case where the length of src is less than that of n, the remainder of dst will be padded with null bytes. +/// @param dst − This is the pointer to the destination array where the content is to be copied. +/// @param src − This is the string to be copied. +/// @param n − The number of characters to be copied from source. +/// @return The destination +char *strncpy(char *dst, const char *src, size_t n) { + for(size_t i = 0;i<n;i++) { + char c = *src; + if(c) src++; + *dst++ = c; + } + return dst; +} + // Converts a string to uppercase. char * strupr(char *str) { char * src = str;