Moved header files into their lib directory

This commit is contained in:
2024-10-10 09:48:54 +02:00
parent 8deefad48d
commit 6369c29773
36 changed files with 3 additions and 2 deletions
+15
View File
@@ -0,0 +1,15 @@
#ifndef COLOR_H
#define COLOR_H
#define BLACK 0x00000000 // 0
#define RED 0x00ff0000 // 1
#define GREEN 0x0000ff00 // 2
#define YELLOW 0x00ffff00 // 3
#define BLUE 0x000000ff // 4
#define MAGENTA 0x00ff00ff // 5
#define CYAN 0x0000ffff // 6
#define WHITE 0x00ffffff // 7
uint32_t codeToColor(uint8_t code);
#endif
+16
View File
@@ -0,0 +1,16 @@
#ifndef MATH_H
#define MATH_H
// Constants
#define PI 3.141592653589 // Should be good enough
#define E 2.718281828459
// Macros
#define abs(x) ( (x) > 0 ? (x) : -(x) )
#define sign(x) ( (x) == 0 ? 0 : ((x) < 0 ? -1 : 1 ) )
#define floor(x) ( (int)(x) ) // C floors floats when converting to ints
#define round(x) ( (int)((x) + 0.5) ) // Normal rounding
#define ceil(x) ( (int)((x) + 1) ) // Always rounds up
#endif
+10
View File
@@ -0,0 +1,10 @@
#ifndef STDARG_H
#define STDARG_H
typedef char* va_list;
#define va_start(ap, paramn) (void)((ap) = (char*)(&(paramn) + 1))
#define va_end(ap) (void)((ap) = 0)
#define va_arg(ap, type) (((type*)((ap) = ((ap) + sizeof(type))))[-1])
#endif
+8
View File
@@ -0,0 +1,8 @@
#ifndef BOOL_H
#define BOOL_H
#define bool _Bool
#define true 1
#define false 0
#endif
+9
View File
@@ -0,0 +1,9 @@
#ifndef STDDEF_H
#define STDDEF_H
#define NULL ((void*)0)
typedef unsigned int size_t;
typedef signed int ssize_t;
#endif
+20
View File
@@ -0,0 +1,20 @@
#ifndef STDINT_H
#define STDINT_H
#include <stddef.h>
// Signed ints
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long long int64_t;
// Unsigned ints
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
// TODO: floats
#endif
+41
View File
@@ -0,0 +1,41 @@
#ifndef STDIO_H
#define STDIO_H
#include <stddef.h>
// Nobody should have to interface with the internals of this structure
typedef struct _iobuf { // 24B
unsigned char* _ptr; // File buffer base
unsigned int _size; // Size of buffer
int _offset; // Offset into file
unsigned short _flag; // Open flags
int _file; // File descriptor
char __reserved[6];
} FILE;
// Standard file pointers
extern FILE* stdin;
extern FILE* stdout;
extern FILE* stderr;
/* File IO */
FILE* fopen(const char* filename, const char* mode);
int fclose(FILE* stream);
size_t fread(void* ptr, size_t size, size_t count, FILE* stream);
size_t fwrite(const void* ptr, size_t size, size_t count, FILE* stream);
int fseek(FILE* stream, long int origin, int offset);
long int ftell(FILE* stream);
/* Terminal IO */
int printf(const char* fmt, ...);
int sprintf(char* str, const char* fmt, ...);
int snprintf(char* str, size_t n, const char* fmt, ...);
int fprintf(FILE* stream, const char* fmt, ...);
void putc(char c);
char getc();
void print(const char* str);
void clear();
void reads(char* str);
#endif
+10
View File
@@ -0,0 +1,10 @@
#ifndef STDLIB_H
#define STDLIB_H
#include <stdint.h>
#include <syscall.h>
void* malloc(const uint32_t size);
void free(const void* ptr);
#endif
+23
View File
@@ -0,0 +1,23 @@
#ifndef STRING_H
#define STRING_H
#include <stdint.h>
void* memcpy(void* src, void* dst, uint32_t length);
void* memcpy32(void* src, void* dst, uint32_t length);
void* memset(void* dst, uint8_t value, uint32_t length);
char* itoa(uint32_t val, uint8_t base);
uint32_t atoi(const char* str);
int isSpace(char c);
char* strcpy(char* str1, const char* str2);
char* strncpy(char* str1, const char* str2, size_t n);
char* strcat(char* str1, const char* str2);
char* strncat(char* str1, const char* str2, size_t n);
char* strchr(const char* str, char c);
char* strrchr(const char* str, char c);
int strcmp(const char* str1, const char* str2);
int strncmp(const char* str1, const char* str2, size_t n);
uint32_t strlen(const char* str);
#endif
+38
View File
@@ -0,0 +1,38 @@
#ifndef SYSCALL_H
#define SYSCALL_H
#include <stddef.h>
#define MAX_SYSCALLS 9
typedef enum {
SYS_RESERVED,
SYS_SLEEP,
SYS_READ,
SYS_WRITE,
SYS_OPEN,
SYS_CLOSE,
SYS_MALLOC,
SYS_FREE,
SYS_SEEK,
} SYSCALL_NUMBERS;
typedef enum {
O_CREAT = 0x01, // Create if does not exist
O_RDONLY = 0x02, // Read only
O_WRONLY = 0x04, // Write only
O_RDWR = 0x08, // Read and write
O_APPEND = 0x10, // Always writes at the end (appends)
O_TRUNC = 0x20, // Truncate file size and position to 0 on Open
O_BIN = 0x40, // Read bytes, not text
} OFLAGS;
int syscall(int nr, int arg0, int arg1, int arg2);
/* Syscall wrappers */
int read(int fd, void* ptr, size_t count);
int write(int fd, const void* ptr, size_t count);
int open(const char* path, int oflag);
int close(int fd);
#endif
+8
View File
@@ -0,0 +1,8 @@
#ifndef TIME_H
#define TIME_H
#include <stdint.h>
void sleep(uint32_t ms);
#endif