From 43be150dc6e84f6f6eeb071cd3cdb7fc21125d60 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 30 Oct 2018 11:41:24 +0100 Subject: Move sw to sw-old and hw to hw-altium, add kicad files --- sw-old/z80/libc/include/stdint.h | 13 +++++++++ sw-old/z80/libc/include/stdio.h | 11 ++++++++ sw-old/z80/libc/include/stdlib.h | 7 +++++ sw-old/z80/libc/include/string.h | 12 ++++++++ sw-old/z80/libc/include/sysio.h | 55 ++++++++++++++++++++++++++++++++++++ sw-old/z80/libc/include/types.h | 60 ++++++++++++++++++++++++++++++++++++++++ sw-old/z80/libc/stdio.c | 12 ++++++++ sw-old/z80/libc/string.c | 37 +++++++++++++++++++++++++ 8 files changed, 207 insertions(+) create mode 100644 sw-old/z80/libc/include/stdint.h create mode 100644 sw-old/z80/libc/include/stdio.h create mode 100644 sw-old/z80/libc/include/stdlib.h create mode 100644 sw-old/z80/libc/include/string.h create mode 100644 sw-old/z80/libc/include/sysio.h create mode 100644 sw-old/z80/libc/include/types.h create mode 100644 sw-old/z80/libc/stdio.c create mode 100644 sw-old/z80/libc/string.c (limited to 'sw-old/z80/libc') diff --git a/sw-old/z80/libc/include/stdint.h b/sw-old/z80/libc/include/stdint.h new file mode 100644 index 0000000..5e8caf3 --- /dev/null +++ b/sw-old/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-old/z80/libc/include/stdio.h b/sw-old/z80/libc/include/stdio.h new file mode 100644 index 0000000..b31cdfd --- /dev/null +++ b/sw-old/z80/libc/include/stdio.h @@ -0,0 +1,11 @@ +#ifndef __STDIO_H__ +#define __STDIO_H__ + +#include "types.h" + +extern uint8_t *stdout, stderr; + +void putc(char ch, uint8_t *buffer); +int printf(const char *fmt, ...); + +#endif diff --git a/sw-old/z80/libc/include/stdlib.h b/sw-old/z80/libc/include/stdlib.h new file mode 100644 index 0000000..c69f573 --- /dev/null +++ b/sw-old/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-old/z80/libc/include/string.h b/sw-old/z80/libc/include/string.h new file mode 100644 index 0000000..9c002e3 --- /dev/null +++ b/sw-old/z80/libc/include/string.h @@ -0,0 +1,12 @@ +#ifndef __STRING_H__ +#define __STRING_H__ + +#include "types.h" + +void * memset(void *dest, const int8_t src, size_t n); + +void *memcpy(void *dest, const void *src, size_t n); + +int8_t memcmp(const void *s1, const void *s2, size_t n); + +#endif diff --git a/sw-old/z80/libc/include/sysio.h b/sw-old/z80/libc/include/sysio.h new file mode 100644 index 0000000..5d1f5ae --- /dev/null +++ b/sw-old/z80/libc/include/sysio.h @@ -0,0 +1,55 @@ +#ifndef __SYSIO_H__ +#define __SYSIO_H__ + +#include "types.h" + +/* +* Memory management +*/ + +void * malloc(uint16_t size); +uint16_t malloc_size(void * address); +void free(void * address); + +/* +* File management +*/ + +#define F_WRITE "w" +#define F_READ "r" +#define F_BIN_WRITE "wb" +#define F_BIN_READ "rb" + +#define F_READ_CODE 0x0 +#define F_WRITE_CODE 0x1 +#define F_BIN_READ_CODE 0x2 +#define F_BIN_WRITE_CODE 0x3 + +#define F_PERM_READ 0x0 +#define F_PERM_WRITE 0x1 +#define F_PERM_RW 0x2 + +struct file { + + const char * path; + unsigned int mode:4; + unsigned int permission:4; +}; + +#define FILE struct file + +FILE * fopen(const char * path, const char * mode); +uint8_t fclose(FILE * file); + +// TODO: other functions + +/* +* Processes management +*/ + +#define PID uint16_t + +void exit(); // exit this program +void interrupt(PID) + +#endif \ No newline at end of file diff --git a/sw-old/z80/libc/include/types.h b/sw-old/z80/libc/include/types.h new file mode 100644 index 0000000..a083bfe --- /dev/null +++ b/sw-old/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-old/z80/libc/stdio.c b/sw-old/z80/libc/stdio.c new file mode 100644 index 0000000..c2548d6 --- /dev/null +++ b/sw-old/z80/libc/stdio.c @@ -0,0 +1,12 @@ +#include "stdio.h" + +void putc(char ch, uint8_t *buffer) +{ + *buffer = ch; + *(++buffer) = '\0'; +} + + +int printf(const char *fmt, ...) +{ +} diff --git a/sw-old/z80/libc/string.c b/sw-old/z80/libc/string.c new file mode 100644 index 0000000..57b3a7f --- /dev/null +++ b/sw-old/z80/libc/string.c @@ -0,0 +1,37 @@ +#include "string.h" + +void *memset(void *dest, const int8_t src, size_t n) { + + char *dp = (char *) dest; + + while (n--) + *(dp++) = src; + + return dest; +} + +void *memcpy(void *dest, void *src, size_t n) +{ + char *dp = dest; + char *sp = src; + + while (n--) { + *dp++ = *sp++; + } + + return dest; +} + +int8_t memcmp(void *s1, void *s2, size_t n) +{ + char *u1 = (char *) s1; + char *u2 = (char *) s2; + + for ( ; n--; u1++, u2++) { + + if (*u1 != *u2) + return u1 - u2; + } + + return 0; +} \ No newline at end of file -- cgit v1.2.1