summaryrefslogtreecommitdiffstats
path: root/sw/z80/libc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sw/z80/libc/include/stdint.h13
-rw-r--r--sw/z80/libc/include/stdlib.h7
-rw-r--r--sw/z80/libc/include/types.h60
-rw-r--r--sw/z80/libc/string.c20
4 files changed, 89 insertions, 11 deletions
diff --git a/sw/z80/libc/include/stdint.h b/sw/z80/libc/include/stdint.h
new file mode 100644
index 0000000..5e8caf3
--- /dev/null
+++ b/sw/z80/libc/include/stdint.h
@@ -0,0 +1,13 @@
+#ifndef __STDINT_H__
+#define __STDINT_H__
+
+typedef unsigned int uint;
+
+typedef char int8_t;
+typedef unsigned char uint8_t;
+typedef int int16_t;
+typedef unsigned int uint16_t;
+typedef long int int32_t;
+typedef unsigned long int uint32_t;
+
+#endif // __STDINT_H__ \ No newline at end of file
diff --git a/sw/z80/libc/include/stdlib.h b/sw/z80/libc/include/stdlib.h
new file mode 100644
index 0000000..c69f573
--- /dev/null
+++ b/sw/z80/libc/include/stdlib.h
@@ -0,0 +1,7 @@
+#ifndef __STDLIB_H__
+#define __STDLIB_H__
+
+#include "stdint.h"
+
+
+#endif // __STDLIB_H__ \ No newline at end of file
diff --git a/sw/z80/libc/include/types.h b/sw/z80/libc/include/types.h
new file mode 100644
index 0000000..a083bfe
--- /dev/null
+++ b/sw/z80/libc/include/types.h
@@ -0,0 +1,60 @@
+#ifndef __TYPES_H__
+#define __TYPES_H__
+
+/* only types from primitive types are defined in this file */
+
+typedef volatile unsigned char register_t;
+
+typedef unsigned int uint;
+
+typedef char int8_t;
+typedef unsigned char uint8_t;
+typedef int int16_t;
+typedef unsigned int uint16_t;
+typedef long int int32_t;
+typedef unsigned long int uint32_t;
+
+typedef uint16_t size_t;
+typedef int16_t ssize_t;
+
+typedef uint8_t pid_t;
+typedef uint16_t ino_t;
+
+typedef uint8_t dev_t;
+typedef uint32_t devsize_t;
+typedef uint8_t fd_t;
+typedef uint16_t blk_t;
+typedef uint8_t user_t;
+typedef struct {
+ uint8_t member[3];
+} uint24_t;
+
+typedef uint32_t fsize_t;
+
+typedef struct
+{
+ dev_t dev; // device id, global in the fs
+ ino_t inode; // inode id relative to the volume
+
+} inode_t;
+
+typedef struct time_s
+{
+ struct
+ {
+ uint minutes :6;
+ uint hour :5;
+
+ } time;
+
+ struct
+ {
+ uint day :5;
+ uint month :4;
+ uint year :12;
+
+ } date;
+
+} time_t;
+
+#endif
diff --git a/sw/z80/libc/string.c b/sw/z80/libc/string.c
index 9dd56cc..57b3a7f 100644
--- a/sw/z80/libc/string.c
+++ b/sw/z80/libc/string.c
@@ -1,11 +1,11 @@
#include "string.h"
-void * memset(void *dest, const int8_t src, size_t n) {
+void *memset(void *dest, const int8_t src, size_t n) {
- void *dp = dest;
+ char *dp = (char *) dest;
while (n--)
- *dp++ = src;
+ *(dp++) = src;
return dest;
}
@@ -22,16 +22,14 @@ void *memcpy(void *dest, void *src, size_t n)
return dest;
}
-int8_t memcmp(const void *s1, const void *s2, size_t n) {
-
- uint8_t u1, u2;
-
- for ( ; n--; s1++, s2++) {
+int8_t memcmp(void *s1, void *s2, size_t n)
+{
+ char *u1 = (char *) s1;
+ char *u2 = (char *) s2;
- u1 = *s1;
- u2 = *s2;
+ for ( ; n--; u1++, u2++) {
- if (u1 != u2)
+ if (*u1 != *u2)
return u1 - u2;
}